How to use the bitcore-lib.HDPrivateKey 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 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 {
github bitpay / bitcore-wallet-client / lib / api.js View on Github external
API.signTxp = function(txp, derivedXPrivKey) {
  //Derive proper key to sign, for each input
  var privs = [];
  var derived = {};

  var xpriv = new Bitcore.HDPrivateKey(derivedXPrivKey);

  _.each(txp.inputs, function(i) {
    $.checkState(i.path, "Input derivation path not available (signing transaction)")
    if (!derived[i.path]) {
      derived[i.path] = xpriv.deriveChild(i.path).privateKey;
      privs.push(derived[i.path]);
    }
  });

  var t = Utils.buildTx(txp);

  var signatures = _.map(privs, function(priv, i) { 
    return t.getSignatures(priv);
  });

  signatures = _.map(_.sortBy(_.flatten(signatures), 'inputIndex'), function(s) {
github bitpay / bitcore / packages / bitcore-client / src / providers / address-provider / eth / index.ts View on Github external
derivePrivateKey(network, xPriv, addressIndex, isChange) {
    const xpriv = new BitcoreLib.HDPrivateKey(xPriv, network);
    const changeNum = isChange ? 1 : 0;
    const path = `m/${changeNum}/${addressIndex}`;
    const derivedPrivKey = xpriv.derive(path);
    const privKey = derivedPrivKey.privateKey.toString('hex');
    const pubKeyObj = derivedPrivKey.publicKey;
    const pubKey = pubKeyObj.toString('hex');
    const pubKeyBuffer = pubKeyObj.toBuffer();
    const address = this.addressFromPublicKeyBuffer(pubKeyBuffer);
    return { address, privKey, pubKey };
  }
}
github bitpay / bitcore-mnemonic / packages / bitcore-wallet-client / lib / api.js View on Github external
API.prototype.addAccess = function(opts, cb) {
  $.checkState(this.credentials && this.credentials.canSign());

  opts = opts || {};

  var reqPrivKey = new Bitcore.PrivateKey(opts.generateNewKey ? null : this.credentials.requestPrivKey);
  var requestPubKey = reqPrivKey.toPublicKey().toString();

  var xPriv = new Bitcore.HDPrivateKey(this.credentials.xPrivKey)
    .deriveChild(this.credentials.getBaseAddressDerivationPath());
  var sig = Utils.signRequestPubKey(requestPubKey, xPriv);
  var copayerId = this.credentials.copayerId;

  var encCopayerName = opts.name ? Utils.encryptMessage(opts.name, this.credentials.sharedEncryptingKey) : null;

  var opts = {
    copayerId: copayerId,
    requestPubKey: requestPubKey,
    signature: sig,
    name: encCopayerName,
    restrictions: opts.restrictions,
  };

  this._doPutRequest('/v1/copayers/' + copayerId + '/', opts, function(err, res) {
    if (err) return cb(err);
github bitpay / bitcore-mnemonic / packages / bitcore-wallet-client / lib / credentials.js View on Github external
Credentials.create = function(coin, network) {
  _checkCoin(coin);
  _checkNetwork(coin, network);

  var x = new Credentials();

  x.coin = coin;
  x.network = network;
  x.xPrivKey = (new Bitcore.HDPrivateKey(network)).toString();
  x.compliantDerivation = true;
  x._expand();
  return x;
};
github bitpay / bitcore-mnemonic / packages / bitcore-wallet-client / lib / api.js View on Github external
API.signTxp = function(txp, derivedXPrivKey) {
  //Derive proper key to sign, for each input
  var privs = [];
  var derived = {};

  var xpriv = new Bitcore.HDPrivateKey(derivedXPrivKey);

  _.each(txp.inputs, function(i) {
    $.checkState(i.path, "Input derivation path not available (signing transaction)")
    if (!derived[i.path]) {
      derived[i.path] = xpriv.deriveChild(i.path).privateKey;
      privs.push(derived[i.path]);
    }
  });

  var t = Utils.buildTx(txp);

  var signatures = _.map(privs, function(priv, i) { 
    return t.getSignatures(priv);
  });

  signatures = _.map(_.sortBy(_.flatten(signatures), 'inputIndex'), function(s) {
github bitpay / bitcore-mnemonic / packages / 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 / copay-recovery / js / services.js View on Github external
function deriveOne(xpriv, path, compliant) {
        var hdPrivateKey = bitcore.HDPrivateKey(xpriv);
        var xPrivKey = compliant ? hdPrivateKey.deriveChild(path) : hdPrivateKey.deriveNonCompliantChild(path);
        return xPrivKey;
      };
github bitpay / bitcore / packages / crypto-wallet-core / src / derivation / eth / index.ts View on Github external
derivePrivateKey(network, xPriv, addressIndex, isChange) {
    const xpriv = new BitcoreLib.HDPrivateKey(xPriv, network);
    const changeNum = isChange ? 1 : 0;
    const path = `m/${changeNum}/${addressIndex}`;
    const derivedPrivKey = xpriv.derive(path);
    const privKey = derivedPrivKey.privateKey.toString('hex');
    const pubKeyObj = derivedPrivKey.publicKey;
    const pubKey = pubKeyObj.toString('hex');
    const pubKeyBuffer = pubKeyObj.toBuffer();
    const address = this.addressFromPublicKeyBuffer(pubKeyBuffer);
    return { address, privKey, pubKey };
  }
}
github iost-official / keychain-manager / lib / private-keychain.js View on Github external
constructor(privateKeychainString) {
        if (privateKeychainString) {
            this.hdKeychain = new HDPrivateKey(privateKeychainString)
        } else {
            this.hdKeychain = new HDPrivateKey()
        }
    }