Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
for (var i = 0; i < outputs.length; i++) {
txTmp.addOutput(outputs[i].address, outputs[i].amountSats.toNumber());
}
for (var j = 0; j < inputs.length; j++) {
txTmp.addInput(inputs[j].txid, inputs[j].index)
}
let txToSign = txTmp.buildIncomplete();
const txHex = txToSign.toHex()
const addressType = multisigAddressType(inputs[0].multisig); // TODO: multiple inputs?
const segwit = addressType == MULTISIG_ADDRESS_TYPES.P2SH_P2WSH || addressType == MULTISIG_ADDRESS_TYPES.P2WSH
let splitTx = await ledgerbtc.splitTransaction(txHex, segwit);
let outputScriptHex = await ledgerbtc.serializeTransactionOutputs(splitTx).toString('hex');
const ledgerIns = inputs.map(input => ledgerInput(ledgerbtc, input));
// BIP32 PATH
let ledger_bip32_path = path.split("/").slice(1).join("/");
let ledgerKeySets = Array(inputs.length).fill(ledger_bip32_path); //array[bip32]
// SIGN
let signatures = await ledgerbtc.signP2SHTransaction(
ledgerIns,
ledgerKeySets,
outputScriptHex
}
}
/**
* Retrieve Trezor format for network constant
* @param {string} network - bitcoin network
* @private
* @returns {string} Trezor format of bitcoin network
*/
function coin(network) {
return (network === NETWORKS.MAINNET ? "Bitcoin" : "Testnet");
}
const addressScriptTypes = {
[MULTISIG_ADDRESS_TYPES.P2WSH]: 'SPENDWITNESS',
[MULTISIG_ADDRESS_TYPES.P2SH]: 'SPENDMULTISIG',
[MULTISIG_ADDRESS_TYPES.P2SH_P2WSH]: 'SPENDP2SHWITNESS',
}
function trezorInput(input, bip32Path) {
const requiredSigners = multisigRequiredSigners(input.multisig);
const addressType = multisigAddressType(input.multisig)
const spendType = addressScriptTypes[addressType]
return {
script_type: spendType,
multisig: {
m: requiredSigners,
pubkeys: multisigPublicKeys(input.multisig).map((publicKey) => trezorPublicKey(publicKey)),
signatures: Array(requiredSigners).fill(''),
},
prev_hash: input.txid,
prev_index: input.index,