How to use the bitcore-lib.HDPublicKey function in bitcore-lib

To help you get started, we’ve selected a few bitcore-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 ringringringring / trustnote-wallet / angular-bitcore-wallet-client / bitcore-wallet-client / lib / credentials.js View on Github external
$.checkState(this.xPrivKey || (this.xPubKey && this.entropySource));

    var network = Credentials._getNetworkFromExtendedKey(this.xPrivKey || this.xPubKey);
    if (this.network) {
        $.checkState(this.network == network);
    } else {
        this.network = network;
    }

    if (this.xPrivKey) {
        console.log('_expand path: ' + this.getBaseAddressDerivationPath());
        var xPrivKey = new Bitcore.HDPrivateKey.fromString(this.xPrivKey);

        // this extra derivation is not to share a non hardened xPubKey to the server.
        var addressDerivation = xPrivKey.derive(this.getBaseAddressDerivationPath());
        this.xPubKey = (new Bitcore.HDPublicKey(addressDerivation)).toString();
        console.log('_expand xPubKey: ' + this.xPubKey);
    } else {
    }


    this.publicKeyRing = [{
        xPubKey: this.xPubKey,
    }];
};
github byteball / obyte-gui-wallet / angular-bitcore-wallet-client / bitcore-wallet-client / lib / credentials.js View on Github external
$.checkState(this.xPrivKey || (this.xPubKey && this.entropySource));

  var network = Credentials._getNetworkFromExtendedKey(this.xPrivKey || this.xPubKey);
  if (this.network) {
    $.checkState(this.network == network);
  } else {
    this.network = network;
  }

  if (this.xPrivKey) {
	console.log('_expand path: '+this.getBaseAddressDerivationPath());
    var xPrivKey = new Bitcore.HDPrivateKey.fromString(this.xPrivKey);

    // this extra derivation is not to share a non hardened xPubKey to the server.
    var addressDerivation = xPrivKey.derive(this.getBaseAddressDerivationPath());
    this.xPubKey = (new Bitcore.HDPublicKey(addressDerivation)).toString();
	console.log('_expand xPubKey: '+this.xPubKey);
  } else {
  }



  this.publicKeyRing = [{
    xPubKey: this.xPubKey,
  }];
};
github bitpay / bitcore-wallet-client / lib / credentials.js View on Github external
var pkr = _.map(w.publicKeyRing.copayersExtPubKeys, function(xPubStr) {

    var isMe = xPubStr === credentials.xPubKey;
    var requestDerivation;

    if (isMe) {
      var path = Constants.PATHS.REQUEST_KEY;
      requestDerivation = (new Bitcore.HDPrivateKey(credentials.xPrivKey))
        .derive(path).hdPublicKey;
    } else {
      // this 
      var path = Constants.PATHS.REQUEST_KEY_AUTH;
      requestDerivation = (new Bitcore.HDPublicKey(xPubStr)).derive(path);
    }

    // Grab Copayer Name
    var hd = new Bitcore.HDPublicKey(xPubStr).derive('m/2147483646/0/0');
    var pubKey = hd.publicKey.toString('hex');
    var copayerName = w.publicKeyRing.nicknameFor[pubKey];
    if (isMe) {
      credentials.copayerName = copayerName;
    }

    return {
      xPubKey: xPubStr,
      requestPubKey: requestDerivation.publicKey.toString(),
      copayerName: copayerName,
    };
  });
github bitpay / bitcore-wallet-service / test / integration / helpers.js View on Github external
_.each(_.range(n), function(c) {
    var xpriv = new Bitcore.HDPrivateKey();
    var xpub = Bitcore.HDPublicKey(xpriv);

    var xpriv_45H = xpriv.derive(45, true);
    var xpub_45H = Bitcore.HDPublicKey(xpriv_45H);
    var id45 = Copayer._xPubToCopayerId(xpub_45H.toString());

    var xpriv_44H_0H_0H = xpriv.derive(44, true).derive(0, true).derive(0, true);
    var xpub_44H_0H_0H = Bitcore.HDPublicKey(xpriv_44H_0H_0H);
    var id44 = Copayer._xPubToCopayerId(xpub_44H_0H_0H.toString());

    var xpriv_1H = xpriv.derive(1, true);
    var xpub_1H = Bitcore.HDPublicKey(xpriv_1H);
    var priv = xpriv_1H.derive(0).privateKey;
    var pub = xpub_1H.derive(0).publicKey;

    console.log('{id44: ', "'" + id44 + "',");
    console.log('id45: ', "'" + id45 + "',");
    console.log('xPrivKey: ', "'" + xpriv.toString() + "',");
    console.log('xPubKey: ', "'" + xpub.toString() + "',");
    console.log('xPrivKey_45H: ', "'" + xpriv_45H.toString() + "',");
github bitpay / bitcore / test / utils.js View on Github external
it('should fail to check a request pub key with wrong key', function() {
      var reqPubKey = '02c2c1c6e75cfc50235ff4a2eb848385c2871b8c94e285ee82eaced1dcd5dd568e';
      var xPrivKey = new Bitcore.HDPrivateKey();
      var xPubKey = new Bitcore.HDPublicKey(xPrivKey);
      var sig = Utils.signRequestPubKey(reqPubKey, xPrivKey);

      var xPrivKey2 = new Bitcore.HDPrivateKey();
      var xPubKey2 = new Bitcore.HDPublicKey(xPrivKey2);
      var valid = Utils.verifyRequestPubKey(reqPubKey, sig, xPubKey2);
      valid.should.be.equal(false);
    });
  });
github intervalue / intervalue-lightnode-2.0-testnet / src / js / controllers / recoveryFromSeed.js View on Github external
function setCurrentWallet() {
                xPubKey = Bitcore.HDPublicKey(self.xPrivKey.derive("m/44'/0'/" + currentWalletIndex + "'"));
                checkAndAddCurrentAddresses(0);
            }
github bitpay / bitcore-node / src / routes / wallet.ts View on Github external
const verifyRequestSignature = (params: VerificationPayload): boolean => {
  const { message, pubKey, signature } = params;
  const pub = new bitcoreLib.HDPublicKey(pubKey)
    .deriveChild('m/2')
    .publicKey.toBuffer();
  const messageHash = bitcoreLib.crypto.Hash.sha256sha256(Buffer.from(message));
  if (typeof signature === 'string') {
    return secp256k1.verify(messageHash, Buffer.from(signature, 'hex'), pub);
  } else {
    throw new Error('Signature must exist');
  }
};
github byteball / obyte-gui-wallet / src / js / controllers / recoveryFromSeed.js View on Github external
function setCurrentWallet() {
				xPubKey = Bitcore.HDPublicKey(self.xPrivKey.derive("m/44'/0'/" + currentWalletIndex + "'"));
				checkAndAddCurrentAddresses(0);
			}
github bitpay / bitcore-wallet-client / lib / api.js View on Github external
function testLiveKeys() {
    var words;
    try {
      words = c.getMnemonic();
    } catch (ex) {}

    var xpriv;
    if (words && (!c.mnemonicHasPassphrase || opts.passphrase)) {
      var m = new Mnemonic(words);
      xpriv = m.toHDPrivateKey(opts.passphrase, c.network);
    }
    if (!xpriv) {
      xpriv = new Bitcore.HDPrivateKey(c.xPrivKey);
    }
    xpriv = xpriv.deriveChild(c.getBaseAddressDerivationPath());
    var xpub = new Bitcore.HDPublicKey(c.xPubKey);

    return testMessageSigning(xpriv, xpub);
  };
github bitpay / bitcore / packages / bitcore-wallet-service / src / lib / server.ts View on Github external
opts,
      ['walletId', 'name', 'xPubKey', 'requestPubKey', 'copayerSignature'],
      cb
    )
  )
    return;

  if (_.isEmpty(opts.name)) return cb(new ClientError('Invalid copayer name'));

  opts.coin = opts.coin || Defaults.COIN;
  if (!Utils.checkValueInCollection(opts.coin, Constants.COINS))
    return cb(new ClientError('Invalid coin'));

  var xPubKey;
  try {
    xPubKey = Bitcore.HDPublicKey(opts.xPubKey);
  } catch (ex) {
    return cb(new ClientError('Invalid extended public key'));
  }
  if (_.isUndefined(xPubKey.network)) {
    return cb(new ClientError('Invalid extended public key'));
  }

  opts.supportBIP44AndP2PKH = _.isBoolean(opts.supportBIP44AndP2PKH)
    ? opts.supportBIP44AndP2PKH
    : true;

  self.walletId = opts.walletId;
  self._runLocked(cb, function(cb) {
    self.storage.fetchWallet(opts.walletId, function(err, wallet) {
      if (err) return cb(err);
      if (!wallet) return cb(Errors.WALLET_NOT_FOUND);