当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript bitgo-utxo-lib.HDNode类代码示例

本文整理汇总了TypeScript中bitgo-utxo-lib.HDNode的典型用法代码示例。如果您正苦于以下问题:TypeScript HDNode类的具体用法?TypeScript HDNode怎么用?TypeScript HDNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了HDNode类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: co

    return co(function *initiateRecovery() {
      const keys = [];
      const userKey = params.userKey; // Box A
      let backupKey = params.backupKey; // Box B
      const bitgoXpub = params.bitgoKey; // Box C
      const destinationAddress = params.recoveryDestination;
      const passphrase = params.walletPassphrase;

      const isKrsRecovery = backupKey.startsWith('xpub') && !userKey.startsWith('xpub');
      const isUnsignedSweep = backupKey.startsWith('xpub') && userKey.startsWith('xpub');

      if (isKrsRecovery && _.isUndefined(config.krsProviders[params.krsProvider])) {
        throw new Error('unknown key recovery service provider');
      }

      const validatePassphraseKey = function(userKey, passphrase): Promise<HDNode> {
        try {
          if (!userKey.startsWith('xprv') && !isUnsignedSweep) {
            userKey = sjcl.decrypt(passphrase, userKey);
          }
          const userHDNode = HDNode.fromBase58(userKey);
          return Promise.resolve(userHDNode);
        } catch (e) {
          throw new Error('Failed to decrypt user key with passcode - try again!');
        }
      };

      const key = yield validatePassphraseKey(userKey, passphrase);

      keys.push(key);

      // Validate the backup key
      try {
        if (!backupKey.startsWith('xprv') && !isKrsRecovery && !isUnsignedSweep) {
          backupKey = sjcl.decrypt(passphrase, backupKey);
        }
        const backupHDNode = HDNode.fromBase58(backupKey);
        keys.push(backupHDNode);
      } catch (e) {
        throw new Error('Failed to decrypt backup key with passcode - try again!');
      }
      try {
        const bitgoHDNode = HDNode.fromBase58(bitgoXpub);
        keys.push(bitgoHDNode);
      } catch (e) {
        if (this.getFamily() !== 'xrp') {
          // in XRP recoveries, the BitGo xpub is optional
          throw new Error('Failed to parse bitgo xpub!');
        }
      }
      // Validate the destination address
      if (!this.isValidAddress(destinationAddress)) {
        throw new Error('Invalid destination address!');
      }

      return keys;
    }).call(this);
开发者ID:BitGo,项目名称:BitGoJS,代码行数:57,代码来源:xrp.ts

示例2: isValidPub

 /**
  * Return boolean indicating whether input is valid public key for the coin.
  *
  * @param {String} pub the pub to be checked
  * @returns {Boolean} is it valid?
  */
 isValidPub(pub) {
   try {
     bitGoUtxoLib.HDNode.fromBase58(pub);
     return true;
   } catch (e) {
     return false;
   }
 }
开发者ID:BitGo,项目名称:BitGoJS,代码行数:14,代码来源:ofc.ts

示例3: isValidPub

 /**
  * Return boolean indicating whether input is valid public key for the coin.
  *
  * @param {String} pub the pub to be checked
  * @returns {Boolean} is it valid?
  */
 public isValidPub(pub: string): boolean {
   try {
     HDNode.fromBase58(pub);
     return true;
   } catch (e) {
     return false;
   }
 }
开发者ID:BitGo,项目名称:BitGoJS,代码行数:14,代码来源:xrp.ts

示例4: function

 const validatePassphraseKey = function(userKey, passphrase): Promise<HDNode> {
   try {
     if (!userKey.startsWith('xprv') && !isUnsignedSweep) {
       userKey = sjcl.decrypt(passphrase, userKey);
     }
     const userHDNode = HDNode.fromBase58(userKey);
     return Promise.resolve(userHDNode);
   } catch (e) {
     throw new Error('Failed to decrypt user key with passcode - try again!');
   }
 };
开发者ID:BitGo,项目名称:BitGoJS,代码行数:11,代码来源:xrp.ts

示例5: before

  before(co(function *() {
    tx = '0xf86c82015285012a05f200825208945208d8e80c6d1aef9be37b4bd19a9cf75ed93dc886b5e620f480008026a00e13f9e0e11337b2b0227e3412211d3625e43f1083fda399cc361dd4bf89083ba06c801a761e0aa3bc8db0ac2568d575b0fb306a1f04f4d5ba82ba3cc0ea0a83bd';
    txid = '0x0ac669c5fef8294443c75a31e32c44b97bbc9e43a18ea8beabcc2a3b45eb6ffa';
    bitgoKeyXprv = 'xprv9s21ZrQH143K3tpWBHWe31sLoXNRQ9AvRYJgitkKxQ4ATFQMwvr7hHNqYRUnS7PsjzB7aK1VxqHLuNQjj1sckJ2Jwo2qxmsvejwECSpFMfC';
    const bitgoPrvBuffer = bitGoUtxoLib.HDNode.fromBase58(bitgoKeyXprv).getKey().getPrivateKeyBuffer();
    bitgoSignature = '0xaa' + secp256k1.sign(Buffer.from(txid.slice(2), 'hex'), bitgoPrvBuffer).signature.toString('hex');

    bitgo = new TestV2BitGo({ env: 'test' });
    bitgo.initializeTestVars();
    bgUrl = common.Environments[bitgo.getEnv()].uri;
    const coin = bitgo.coin('teth');
    ethWallet = coin.newWalletObject({ keys: ['user', 'backup', 'bitgo'] });
  }));
开发者ID:BitGo,项目名称:BitGoJS,代码行数:13,代码来源:ethWallet.ts

示例6: generateKeyPair

 /**
  * Generate secp256k1 key pair
  *
  * @param seed
  * @returns {Object} object with generated pub and prv
  */
 generateKeyPair(seed) {
   if (!seed) {
     // An extended private key has both a normal 256 bit private key and a 256
     // bit chain code, both of which must be random. 512 bits is therefore the
     // maximum entropy and gives us maximum security against cracking.
     seed = crypto.randomBytes(512 / 8);
   }
   const extendedKey = bitGoUtxoLib.HDNode.fromSeedBuffer(seed);
   const xpub = extendedKey.neutered().toBase58();
   return {
     pub: xpub,
     prv: extendedKey.toBase58()
   };
 }
开发者ID:BitGo,项目名称:BitGoJS,代码行数:20,代码来源:ofc.ts

示例7: it

  it('should create and sign a trade payload', co(function *() {
    const xprv = 'xprv9s21ZrQH143K2MUz7uPUBVzdmvJQE6fPEQCkR3mypPbZgijPqfmGH7pjijdjeJx3oCoxPWVbjC4VYHzgN6wqEfYnnbNjK7jm2CkrvWrvkbR';
    const xpub = 'xpub661MyMwAqRbcEqZTDvvUYdwNKx8tdZPEbd8MDSBbNj8YZX4YPD5Wpv9Da2YzLC8ZNRhundXP7mVhhu9WdJChzZJFGLQD7tyY1KGfmjuBvcX';

    const msScope = nock(microservicesUri)
    .post('/api/trade/v1/payload')
    .reply(200, {
      payload: JSON.stringify({
        walletId: 'walletId',
        currency: 'tbtc',
        amount: '100000000',
        otherParties: ['test_counter_party_1'],
        nonce: Date.now()
      })
    });
    const platformScope = nock(bgUrl)
    .get('/api/v2/ofc/key/keyid')
    .reply(200, {
      pub: xpub,
      encryptedPrv: bitgo.encrypt({ input: xprv, password: TestV2BitGo.OFC_TEST_PASSWORD })
    });

    const { payload, signature } = yield trading.signTradePayload({
      currency: 'tbtc',
      amount: '100000000',
      otherParties: ['test_counterparty_1'],
      walletPassphrase: TestV2BitGo.OFC_TEST_PASSWORD
    });

    should.exist(payload);
    // The payload should be a valid JSON object
    // NOTE: we shouldn't do any more validation than this, as the schema is subject to change often
    (() => { JSON.parse(payload); }).should.not.throw();

    should.exist(signature);
    // signature should be a hex string
    signature.should.match(/^[0-9a-f]+$/);

    const address = HDNode.fromBase58(xpub).getAddress();

    bitcoinMessage.verify(payload, address, Buffer.from(signature, 'hex')).should.be.True();

    msScope.isDone().should.be.True();
    platformScope.isDone().should.be.True();
  }));
开发者ID:BitGo,项目名称:BitGoJS,代码行数:45,代码来源:trading.ts

示例8: it

    it('should fail if the HSM signature signed the wrong HSM commitment digest', co(function *() {
      let error = undefined;
      const badTxid = '0xb4b3827a529c9166786e796528017889ac5027255b65b3fa2a3d3ad91244a12b';
      const badTxidBuffer = Buffer.from(badTxid.slice(2), 'hex');
      const xprvNode = bitGoUtxoLib.HDNode.fromBase58(bitgoKeyXprv);

      const badSignature = '0xaa' + secp256k1.sign(badTxidBuffer, xprvNode.getKey().getPrivateKeyBuffer()).signature.toString('hex');
      const badPrebuild = JSON.parse(JSON.stringify(prebuild));
      badPrebuild.signature = badSignature;

      nockBitGoKey();
      try {
        yield ethWallet.baseCoin.validateHopPrebuild(ethWallet, badPrebuild, buildParams);
      } catch (e) {
        error = e.message;
      }
      should.exist(error);
      error.should.containEql("Hop txid signature invalid");
    }));
开发者ID:BitGo,项目名称:BitGoJS,代码行数:19,代码来源:ethWallet.ts

示例9: signTransaction

  /**
   * Assemble keychain and half-sign prebuilt transaction
   * @param params
   * - txPrebuild
   * - prv
   * @returns {{txHex}}
   */
  public signTransaction({ txPrebuild, prv }: SignTransactionOptions): HalfSignedTransaction {
    if (_.isUndefined(txPrebuild) || !_.isObject(txPrebuild)) {
      if (!_.isUndefined(txPrebuild) && !_.isObject(txPrebuild)) {
        throw new Error(`txPrebuild must be an object, got type ${typeof txPrebuild}`);
      }
      throw new Error('missing txPrebuild parameter');
    }

    if (_.isUndefined(prv) || !_.isString(prv)) {
      if (!_.isUndefined(prv) && !_.isString(prv)) {
        throw new Error(`prv must be a string, got type ${typeof prv}`);
      }
      throw new Error('missing prv parameter to sign transaction');
    }

    const userKey = HDNode.fromBase58(prv).getKey();
    const userPrivateKey: Buffer = userKey.getPrivateKeyBuffer();
    const userAddress = rippleKeypairs.deriveAddress(userKey.getPublicKeyBuffer().toString('hex'));

    const rippleLib = ripple();
    const halfSigned = rippleLib.signWithPrivateKey(txPrebuild.txHex, userPrivateKey.toString('hex'), { signAs: userAddress });
    return { halfSigned: { txHex: halfSigned.signedTransaction } };
  }
开发者ID:BitGo,项目名称:BitGoJS,代码行数:30,代码来源:xrp.ts


注:本文中的bitgo-utxo-lib.HDNode类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。