How to use the bitcore.HDPrivateKey function in bitcore

To help you get started, we’ve selected a few bitcore 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 iost-official / keychain-manager / lib / keychain-generator.js View on Github external
function KeychainGenerator(keyString) {
    if (keyString) {
        this.rootKeychain = new HDPrivateKey(keyString)
    } else {
        this.rootKeychain = new HDPrivateKey()
    }
}
github bitpay / bitcore / lib / client / api.js View on Github external
API.prototype._getSignaturesFor = function(txp, wcd) {

  //Derive proper key to sign, for each input
  var privs = [],
    derived = {};

  var network = new Bitcore.Address(txp.toAddress).network.name;
  var xpriv = new Bitcore.HDPrivateKey(wcd.xPrivKey, network);

  _.each(txp.inputs, function(i) {
    if (!derived[i.path]) {
      derived[i.path] = xpriv.derive(i.path).privateKey;
      privs.push(derived[i.path]);
    }
  });

  var t = new Bitcore.Transaction();

  _.each(txp.inputs, function(i) {
    t.from(i, i.publicKeys, txp.requiredSignatures);
  });

  t.to(txp.toAddress, txp.amount)
    .change(txp.changeAddress.address);
github bitpay / bitcore / lib / client / credentials.js View on Github external
Credentials.create = function(network) {
  var x = new Credentials();

  x.network = network;
  x.xPrivKey = (new Bitcore.HDPrivateKey(network)).toString();
  x._expand();
  return x;
};
github bitpay / bitcore-wallet-service / lib / clilib.js View on Github external
function _createXPrivKey() {
  return new Bitcore.HDPrivateKey().toString();
};
github bitpay / bitcore / lib / client / api.js View on Github external
function _initWcd(network) {
  $.checkArgument(network);
  var xPrivKey = new Bitcore.HDPrivateKey(network);
  var xPubKey = (new Bitcore.HDPublicKey(xPrivKey)).toString();
  var roPrivKey = xPrivKey.derive('m/1/0').privateKey;
  var rwPrivKey = xPrivKey.derive('m/1/1').privateKey;
  var copayerId = WalletUtils.xPubToCopayerId(xPubKey);


  return {
    copayerId: copayerId,
    xPrivKey: xPrivKey.toString(),
    publicKeyRing: [xPubKey],
    network: network,
    roPrivKey: roPrivKey.toWIF(),
    rwPrivKey: rwPrivKey.toWIF(),
  };
};
github iost-official / keychain-manager / lib / keychain-generator.js View on Github external
function KeychainGenerator(keyString) {
    if (keyString) {
        this.rootKeychain = new HDPrivateKey(keyString)
    } else {
        this.rootKeychain = new HDPrivateKey()
    }
}
github bitpay / bitcore / lib / client / api.js View on Github external
this.storage.load(function(err, wcd) {
    if (wcd)
      return cb('Storage already contains a wallet');

    wcd = {};

    var inData = JSON.parse(str);
    var i = 0;

    _.each(WALLET_CRITICAL_DATA.concat(WALLET_EXTRA_DATA), function(k) {
      wcd[k] = inData[i++];
    });

    if (wcd.xPrivKey) {
      var xpriv = new Bitcore.HDPrivateKey(wcd.xPrivKey);
      var xPubKey = new Bitcore.HDPublicKey(xpriv).toString();
      wcd.publicKeyRing.unshift(xPubKey);
      wcd.copayerId = WalletUtils.xPubToCopayerId(xPubKey);
      wcd.roPrivKey = xpriv.derive('m/1/0').privateKey.toWIF();
      wcd.rwPrivKey = xpriv.derive('m/1/1').privateKey.toWIF();
    }

    if (!wcd.publicKeyRing)
      return cb('Invalid source wallet');

    wcd.network = wcd.publicKeyRing[0].substr(0, 4) == 'tpub' ? 'testnet' : 'livenet';

    self.save(wcd, function(err) {
      return cb(err, WalletUtils.accessFromData(wcd));
    });
  });