Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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',
}
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) {
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');
}
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;
compressedPubToHexAddress(pub: string): string {
const byteArrayAddr = bitgoAccountLib.Trx.Utils.getByteArrayFromHexAddress(pub);
const rawAddress = bitgoAccountLib.Trx.Utils.getRawAddressFromPubKey(byteArrayAddr);
return bitgoAccountLib.Trx.Utils.getHexAddressFromByteArray(rawAddress);
}