Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const txHex = params.txHex || (params.halfSigned && params.halfSigned.txHex);
if (!txHex) {
throw new Error('missing required param txHex or halfSigned.txHex');
}
let tx;
try {
const txToHex = Buffer.from(txHex, 'base64');
const decodedTx = Encoding.decode(txToHex);
// if we are a signed msig tx, the structure actually has the { msig, txn } as the root object
// if we are not signed, the decoded tx is the txn - refer to partialSignTxn and MultiSig constructor
// in algosdk for more information
const txnForDecoding = decodedTx.txn || decodedTx;
tx = Multisig.MultiSigTransaction.from_obj_for_encoding(txnForDecoding);
} catch (ex) {
throw new Error('txHex needs to be a valid tx encoded as base64 string');
}
const id = tx.txID();
const fee = { fee: tx.fee };
const outputAmount = tx.amount || 0;
const outputs: { amount: number; address: string }[] = [];
if (tx.to) {
outputs.push({
amount: outputAmount,
address: Address.encode(new Uint8Array(tx.to.publicKey)),
});
}