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


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

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


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

示例1: it

    it('should verify full signatures correctly', () => {
      const txHex = '01000000000101ad26ff8d387cb1aff967fc76fd96c8036a5ad2f1e9aa5214bc07b019ec63b1830100000023220020c4138370d5d77d8d3ccf3dc7561d0232bc743b8d1c16074881b91556e296a9f8ffffffff0200e1f5050000000017a9144b422c82fef274b72106572af74097773b7dd56587180fe0110000000017a914139de7a47eb613076c790aaaee21d8bbe28942ab870400483045022100a8ae2918d0589bfad341f2d46499c118542537ce22f5cc199d96fc949bdd445302206f56289185e6f5d81a5531632c4985847af1df20f4a078f2290e331411f35f6c01483045022100b4b6c9e7b300f5362d82a69730983eea9de575106747fd424e179499fb78a74602206546801fb3f0f1fcc090003906020575d7b27c851e7fbea3b917480793180bb00169522102b4f2c26870cdd4fd6d93ac0fd89f536beaed2a4c59daeea318f7355d1b3420932102363a336031faf1506ee79c7939a44e3259b35fa25bd5ea7bcf0ce5359d8792c32103d18ae6a34e70400b303ea95cccca3e33a648f63624a52b306e2aedc6a4cfd63753ae00000000';
      const tx = bitcoin.Transaction.fromHex(txHex);
      const areSignaturesValid = basecoin.verifySignature(tx, 0, prebuild.txInfo.unspents[0].value);
      areSignaturesValid.should.equal(true);

      const isFirstSignatureValid = basecoin.verifySignature(tx, 0, prebuild.txInfo.unspents[0].value, { signatureIndex: 0 });
      const isSecondSignatureValid = basecoin.verifySignature(tx, 0, prebuild.txInfo.unspents[0].value, { signatureIndex: 1 });
      isFirstSignatureValid.should.equal(true);
      isSecondSignatureValid.should.equal(true);

      const userNode = prova.HDNode.fromBase58(userKeychain.pub);
      const backupNode = prova.HDNode.fromBase58(backupKeychain.pub);
      const bitgoNode = prova.HDNode.fromBase58(bitgoKeychain.pub);
      const derivationPath = `m/0/0/${prebuild.txInfo.unspents[0].chain}/${prebuild.txInfo.unspents[0].index}`;
      const userHex = userNode.hdPath().deriveKey(derivationPath).getPublicKeyBuffer().toString('hex');
      const backupHex = backupNode.hdPath().deriveKey(derivationPath).getPublicKeyBuffer().toString('hex');
      const bitgoHex = bitgoNode.hdPath().deriveKey(derivationPath).getPublicKeyBuffer().toString('hex');

      const isUserSignatureValid = basecoin.verifySignature(tx, 0, prebuild.txInfo.unspents[0].value, { publicKey: userHex });
      const isBackupSignatureValid = basecoin.verifySignature(tx, 0, prebuild.txInfo.unspents[0].value, { publicKey: backupHex });
      const isBitgoSignatureValid = basecoin.verifySignature(tx, 0, prebuild.txInfo.unspents[0].value, { publicKey: bitgoHex });
      isUserSignatureValid.should.equal(true);
      isBackupSignatureValid.should.equal(true);
      isBitgoSignatureValid.should.equal(false);
    });
开发者ID:BitGo,项目名称:BitGoJS,代码行数:26,代码来源:ltc.ts

示例2: it

 it('should construct a recovery transaction with segwit unspents', co(function *() {
   const { params, expectedTxHex } = fixtures.recoverBtcSegwitFixtures();
   recoveryNocks.nockBtcSegwitRecovery();
   const tx = yield coin.recover(params);
   const transaction = utxoLib.Transaction.fromHex(tx.transactionHex);
   transaction.ins.length.should.equal(2);
   transaction.outs.length.should.equal(1);
   transaction.outs[0].value.should.equal(57112);
   tx.transactionHex.should.equal(expectedTxHex);
 }));
开发者ID:BitGo,项目名称:BitGoJS,代码行数:10,代码来源:abstractUtxoCoin.ts

示例3: co

    return co(function *verifyRecoveryTransaction() {
      const decodedTx = yield request.post(this.recoveryBlockchainExplorerUrl(`/decodetx`))
      .send({ hex: txInfo.transactionHex })
      .result();

      const transactionDetails = decodedTx.transaction;

      const tx = bitcoin.Transaction.fromHex(txInfo.transactionHex, this.network);
      if (transactionDetails.TxId !== tx.getId()) {
        console.log(transactionDetails.TxId);
        console.log(tx.getId());
        throw new Error('inconsistent recovery transaction id');
      }

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

示例4: it

    it('should verify a signed transaction', co(function *() {
      const unspent = prebuild.txInfo.unspents[0];
      const signedTransaction = bitcoin.Transaction.fromHex(signedTxHex);
      const areSignaturesValid = basecoin.verifySignature(signedTransaction, 0, unspent.value);
      areSignaturesValid.should.equal(true);

      // mangle first signature
      const sigScript = bitcoin.script.decompile(signedTransaction.ins[0].script);
      sigScript.length.should.equal(5);
      const firstSignature = sigScript[1];
      const secondSignature = sigScript[2];
      firstSignature.length.should.equal(71);
      secondSignature.length.should.equal(71);

      // mangle random byte of first signature (modifying too much could make the sig script become misclassified)
      firstSignature[10] = 54;
      sigScript[1] = firstSignature;
      signedTransaction.ins[0].script = bitcoin.script.compile(sigScript);

      const areMangledSignaturesValid = basecoin.verifySignature(signedTransaction, 0, unspent.value);
      areMangledSignaturesValid.should.equal(false);

      const isFirstSignatureValid = basecoin.verifySignature(signedTransaction, 0, unspent.value, { signatureIndex: 0 });
      isFirstSignatureValid.should.equal(false);

      // the second signature remains unmodifed and should still be valid
      const isSecondSignatureValid = basecoin.verifySignature(signedTransaction, 0, unspent.value, { signatureIndex: 1 });
      isSecondSignatureValid.should.equal(true);

      const isPublicKeySignatureValid = basecoin.verifySignature(signedTransaction, 0, unspent.value, { publicKey: '0266824ac31b6a9d6568c3f7ced9aee1c720cd85994dd41d43dc63b0977195729e' });
      isPublicKeySignatureValid.should.equal(true);

      const isSignatureMappedPublicKeySignatureValid = basecoin.verifySignature(signedTransaction, 0, unspent.value, { publicKey: '0266824ac31b6a9d6568c3f7ced9aee1c720cd85994dd41d43dc63b0977195729e', signatureIndex: 1 });
      isSignatureMappedPublicKeySignatureValid.should.equal(true);

      const isMismappedPublicKeySignatureValid = basecoin.verifySignature(signedTransaction, 0, unspent.value, { publicKey: '0266824ac31b6a9d6568c3f7ced9aee1c720cd85994dd41d43dc63b0977195729e', signatureIndex: 0 });
      isMismappedPublicKeySignatureValid.should.equal(false);
    }));
开发者ID:BitGo,项目名称:BitGoJS,代码行数:38,代码来源:wallet.ts

示例5: it

      it('should create local prebuild', co(function *() {
        const fundingAddress = 't2CgWUKFKRaKzPXQF2cooNFtVZR1gTM8xxM';
        const fundingRedeemScript = '522103dc94182103c93690c2bca3fe013c19c956b940645b11b0a752e0e56b156bf4e22103b5f4aa0348bf339400ed7e16c6e960a4a46a1ea4c4cbe21abf6d0403161dc4f22103706ff6b11a8d9e3d63a455788d5d96738929ca642f1f3d8f9acedb689e759f3753ae';

        const receiveAddress = 't2HPJLxLLXLbKkfQngpwhZCGKAhHuqyqPk4';
        const unspent = {
          id: '8047839532dcfec617661120e1baa0e3b9135662ac8e1f97561e500d430dccb1:0',
          address: fundingAddress,
          value: 300000000,
          valueString: '300000000',
          blockHeight: 999999999,
          date: '2018-05-20T01:44:13.713Z'
        };
        const [txHash, vout] = unspent.id.split(':');

        const txb = new bitGoUtxoLib.TransactionBuilder(testCoin.network);
        txb.addInput(txHash, parseInt(vout, 16), 0xffffffff);
        txb.addOutput(receiveAddress, unspent.value - 50000);

        const tx = txb.buildIncomplete();
        tx.coin = coin.type;
        tx.overwintered = 1;
        tx.versionGroupId = 0x03C48270;

        const prebuild = {
          txHex: tx.toHex(),
          txInfo: {
            unspents: [
              {
                chain: 1,
                index: 113,
                redeemScript: fundingRedeemScript,
                value: 300000000
              }
            ]
          }
        };

        const wallet = new Wallet(bitgo, testCoin, {});
        const halfSigned = yield wallet.signTransaction({
          txPrebuild: prebuild,
          prv: keychains[0].prv
        });
        const halfSignedTx = bitGoUtxoLib.Transaction.fromHex(halfSigned.txHex, testCoin.network);
        halfSignedTx.network.coin.should.equal('zec');
        halfSignedTx.version.should.equal(bitGoUtxoLib.Transaction.ZCASH_SAPLING_VERSION);
        halfSignedTx.versionGroupId.should.equal(2301567109);
        halfSignedTx.overwintered.should.equal(1);
        halfSignedTx.expiryHeight.should.equal(0);
        halfSigned.txHex.should.equal('0400008085202f8901b1cc0d430d501e56971f8eac625613b9e3a0bae120116617c6fedc329583478000000000b600473044022034c624b44051fd6d3cf665b6117a614c683c918f9b6087d65d7043479bb60c3402205eef0d7032c98902c56a4337c4de7feba44704786fa9d4968af1699e1eede5b80100004c69522103dc94182103c93690c2bca3fe013c19c956b940645b11b0a752e0e56b156bf4e22103b5f4aa0348bf339400ed7e16c6e960a4a46a1ea4c4cbe21abf6d0403161dc4f22103706ff6b11a8d9e3d63a455788d5d96738929ca642f1f3d8f9acedb689e759f3753aeffffffff01b0dfe0110000000017a91476dce7beb23d0e0d53edf5895716d4c80dce60938700000000000000000000000000000000000000');

        const halfSignedPrebuild = _.extend({}, prebuild, halfSigned);
        const fullySigned = yield wallet.signTransaction({
          txPrebuild: halfSignedPrebuild,
          prv: keychains[2].prv,
          isLastSignature: true
        });
        const fullySignedTx = bitGoUtxoLib.Transaction.fromHex(fullySigned.txHex, testCoin.network);
        fullySignedTx.network.coin.should.equal('zec');
        fullySignedTx.version.should.equal(bitGoUtxoLib.Transaction.ZCASH_SAPLING_VERSION);
        fullySignedTx.versionGroupId.should.equal(2301567109);
        fullySignedTx.overwintered.should.equal(1);
        fullySignedTx.expiryHeight.should.equal(0);
        fullySignedTx.getId().should.equal('d16b14e8312661ca7570f587b102610c35e97e87c0668349ea216f9b0173864d');

        fullySigned.txHex.should.equal('0400008085202f8901b1cc0d430d501e56971f8eac625613b9e3a0bae120116617c6fedc329583478000000000fc00473044022034c624b44051fd6d3cf665b6117a614c683c918f9b6087d65d7043479bb60c3402205eef0d7032c98902c56a4337c4de7feba44704786fa9d4968af1699e1eede5b801473044022052df70f6e0e40082382cea9ce4f76347c436f92f56523ca9a2198a45de5145fa0220782f43b17d9013c9a611a027ab139f45c45a0f0e942525aa3e6e63796df1918f014c69522103dc94182103c93690c2bca3fe013c19c956b940645b11b0a752e0e56b156bf4e22103b5f4aa0348bf339400ed7e16c6e960a4a46a1ea4c4cbe21abf6d0403161dc4f22103706ff6b11a8d9e3d63a455788d5d96738929ca642f1f3d8f9acedb689e759f3753aeffffffff01b0dfe0110000000017a91476dce7beb23d0e0d53edf5895716d4c80dce60938700000000000000000000000000000000000000');
      }));
开发者ID:BitGo,项目名称:BitGoJS,代码行数:67,代码来源:zec.ts


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