createScriptWitness function
Implementation
Uint8List createScriptWitness({
required BTCRawTransaction tx,
required int i,
required ElectrumOutput output,
required UTXONetworkType networkType,
required BIP32 node,
}) {
final hashType = networkType.sighash.all;
final prevScriptPubKey = output.scriptPubKey.lockingScript;
assert(output.scriptPubKey.isSegwit);
final sigHash = tx.bip143sigHash(
index: i,
prevScriptPubKey: prevScriptPubKey,
output: output,
hashType: hashType,
);
final sig = signInput(bip32: node, sigHash: sigHash);
final scriptSig = encodeSignature(sig, hashType);
final pubkey = node.publicKey;
return [
0x02,
scriptSig.length,
...scriptSig,
pubkey.length,
...pubkey,
].toUint8List;
}