How to use @bitgo/account-lib - 5 common examples

To help you get started, we’ve selected a few @bitgo/account-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 BitGo / BitGoJS / modules / core / src / v2 / coins / trx.ts View on Github external
return co(function*() {
      const txHex = params.txHex || (params.halfSigned && params.halfSigned.txHex);
      if (!txHex || !params.feeInfo) {
        throw new Error('missing explain tx parameters');
      }
      const coinName = this.getChain();
      const txBuilder = new bitgoAccountLib.TransactionBuilder({ coinName });
      txBuilder.from(txHex);
      const tx = txBuilder.build();
      const outputs = [
        {
          amount: tx.destinations[0].value.toString(),
          address: tx.destinations[0].address, // Should turn it into a readable format, aka base58
        },
      ];

      const displayOrder = [
        'id',
        'outputAmount',
        'changeAmount',
        'outputs',
        'changeOutputs',
        'fee',
github BitGo / BitGoJS / modules / core / src / v2 / coins / trx.ts View on Github external
}
      const recoveryAmountMinusFees = recoveryAmount - MINIMUM_TRON_MSIG_TRANSACTION_FEE;
      const buildTx = yield self.getBuildTransaction(recoveryAddressHex, bitgoHexAddr, recoveryAmountMinusFees);

      const keyHexAddresses = [
        self.compressedPubToHexAddress(self.xpubToCompressedPub(userXPub)),
        self.compressedPubToHexAddress(self.xpubToCompressedPub(backupXPub)),
        bitgoHexAddr,
      ];

      // run checks to ensure this is a valid tx - permissions match our signer keys
      self.checkPermissions(account.owner_permission.keys, keyHexAddresses);
      self.checkPermissions(account.active_permission[0].keys, keyHexAddresses);

      // construct our tx
      const txBuilder = new bitgoAccountLib.TransactionBuilder({ coinName: this.getChain() });
      txBuilder.from(buildTx);

      // this tx should be enough to drop into a node
      if (isUnsignedSweep) {
        return {
          tx: txBuilder.build().toJson(),
          recoveryAmount: recoveryAmountMinusFees,
        };
      }

      const userPrv = self.xprvToCompressedPrv(userXPrv);

      txBuilder.sign({ key: userPrv });

      // krs recoveries don't get signed
      if (!isKrsRecovery) {
github BitGo / BitGoJS / modules / core / src / v2 / coins / trx.ts View on Github external
signMessage(key: KeyPair, message: string | Buffer): Buffer {
    const toSign = this.toHexString(message);

    let prv = key.prv;
    if (this.isValidXprv(prv)) {
      prv = HDNode.fromBase58(prv)
        .getKey()
        .getPrivateKeyBuffer();
    }

    let sig = bitgoAccountLib.Trx.Utils.signString(toSign, prv, true);

    // remove the preceding 0x
    sig = sig.replace(/^0x/, '');

    return Buffer.from(sig, 'hex');
  }
github BitGo / BitGoJS / modules / core / src / v2 / coins / trx.ts View on Github external
signTransaction(params: TronSignTransactionOptions): SignedTransaction {
    const coinName = this.getChain();
    const txBuilder = new bitgoAccountLib.TransactionBuilder({ coinName });
    txBuilder.from(params.txPrebuild.txHex);

    let key = params.prv;
    if (this.isValidXprv(params.prv)) {
      key = HDNode.fromBase58(params.prv)
        .getKey()
        .getPrivateKeyBuffer();
    }

    txBuilder.sign({ key });
    const transaction = txBuilder.build();
    const response = {
      txHex: JSON.stringify(transaction.toJson()),
    };
    if (transaction.toJson().signature.length >= 2) {
      return response;
github BitGo / BitGoJS / modules / core / src / v2 / coins / trx.ts View on Github external
compressedPubToHexAddress(pub: string): string {
    const byteArrayAddr = bitgoAccountLib.Trx.Utils.getByteArrayFromHexAddress(pub);
    const rawAddress = bitgoAccountLib.Trx.Utils.getRawAddressFromPubKey(byteArrayAddr);
    return bitgoAccountLib.Trx.Utils.getHexAddressFromByteArray(rawAddress);
  }

@bitgo/account-lib

BitGo's account library functions

Apache-2.0
Latest version published 3 days ago

Package Health Score

78 / 100
Full package analysis

Similar packages