How to use the bitcoinjs-lib.ECPair.fromWIF function in bitcoinjs-lib

To help you get started, we’ve selected a few bitcoinjs-lib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alexbosworth / ln-service / test / macros / chain_send_transaction.js View on Github external
if (!args.spend_transaction_id) {
    throw new Error('ExpectedOutpointTxIdToSpend');
  }

  if (args.spend_vout === undefined) {
    throw new Error('ExpectedOutpointVoutToSpend');
  }

  if (!args.tokens) {
    throw new Error('ExpectedTokenCountToSend');
  }

  const network = networks[defaultNetwork];

  const keyPair = ECPair.fromWIF(args.private_key, network);
  const outputScript = toOutputScript(args.destination, network);
  const tx = new Transaction();

  const outpointHash = Buffer.from(args.spend_transaction_id, 'hex').reverse();

  tx.addInput(outpointHash, args.spend_vout);

  try {
    tx.addOutput(outputScript, (args.tokens - (args.fee || 0)));
  } catch (err) {
    throw new Error('ErrorAddingOutputToSendOnChainTransaction');
  }

  const sigHashAll = parseInt(SIGHASH_ALL, hexBase);

  [keyPair].forEach((signingKey, vin) => {
github blockstack-packages / blockstack-keychains-js / src / unitTests.es6 View on Github external
test('PrivateKeychain', function(t) {
    t.plan(18)

    let privateKeychain = new PrivateKeychain()
    t.ok(privateKeychain instanceof PrivateKeychain, 'PrivateKeychain should have been created')

    let privateKeychain2 = new PrivateKeychain('5Kd3NBUAdUnhyzenEwVLy9pBKxSwXvE9FMPyR4UKZvpe6E3AgLr')
    t.ok(privateKeychain2, 'PrivateKeychain should have been created')

    let privateKeychain3 = new PrivateKeychain(new ECPair.fromWIF('5Kd3NBUAdUnhyzenEwVLy9pBKxSwXvE9FMPyR4UKZvpe6E3AgLr'))
    t.ok(privateKeychain3, 'PrivateKeychain should have been created')

    t.equal(privateKeychain2.privateKey('hex'), privateKeychain3.privateKey('hex'), 'Private keys should be equal')

    t.ok(privateKeychain.privateKey(), 'Private key should have been created')
    t.ok(privateKeychain.wif(), 'Private key WIF should have been created')
    
    let publicKeychain = privateKeychain.publicKeychain()
    t.ok(publicKeychain instanceof PublicKeychain, 'Public Keychain should have been created')

    let message = 'Hello, World!'
    let signature = privateKeychain.sign(message)
    t.ok(signature, 'Signature should have been created')

    let messageVerified = publicKeychain.verify(message, signature)
    t.ok(messageVerified, 'Message should have been verified')
github pillarwallet / pillarwallet / src / services / bitcoin.js View on Github external
export const importKeyPair = (s: string, networkName?: string): ECPair => ECPair.fromWIF(s, selectNetwork(networkName));
github blockstack-packages / blockstack-keychains-js / src / keychain.es6 View on Github external
constructor(privateKey) {
    if (!privateKey) {
      this.ecPair = new ECPair.makeRandom({ rng: getEntropy })
    } else {
      if (privateKey instanceof ECPair) {
        this.ecPair = privateKey
      } else if (isWIF(privateKey)) {
        this.ecPair = new ECPair.fromWIF(privateKey)
      } else {
        this.ecPair = new ECPair(privateKey, null, {})
      }
    }
  }