[ad_1]
I write a easy taproot-based script in bitcoinjs, like:
<pk1> OP_CHECKSIG <pk2> OP_CHECKSIGADD <pk3> OP_CHECKSIGADD OP_2 OP_EQUAL
It needs to be a 3-2 threshold account, that require 2 signature. Nonetheless, it truly required 3 signature, if we solely signal it with 2 keypair, it is going to happen:
Operation not legitimate with the present stack dimension
So how do I capable of spend this taproot deal with, with solely 2 legitimate keypair?
Right here is the code used to formulate the deal with and spend:
const leafKeys = [];
const leafPubkeys = [];
const leafKeys_WIF = [];
for (let i = 0; i < num; i++)
const leafKey = ECPair.makeRandom( community );
leafKeys.push(leafKey);
leafPubkeys.push(toXOnly(leafKey.publicKey).toString('hex'));
leafKeys_WIF.push(leafKey.toWIF())
// It returns the script that I wrote earlier than
const leafScript = asm_builder(leafPubkeys, threshold);
const scriptTree: Taptree =
output: leafScript,
;
const redeem =
output: leafScript,
redeemVersion: LEAF_VERSION_TAPSCRIPT,
;
const p2tr = bitcoin.funds.p2tr(
internalPubkey: toXOnly(keypair.publicKey),
scriptTree,
redeem,
community: choose_network(`regtest`),
);
console.log(`Ready until UTXO is detected at this Tackle: $p2tr.deal with!`)
let temp_trans = await pushTrans(p2tr.deal with!)
console.log("the brand new txid is:", temp_trans)
const utxo = await getUTXOfromTx(temp_trans, p2tr.deal with!)
let psbt_origin: string = build_psbt(redeem, [utxo], p2tr.deal with, "bcrt1q5hk8re6mar775fxnwwfwse4ql9vtpn6x558g0w", "regtest", p2tr, amt, price)
let psbt_ = ''
for (var i = 0; i < threshold; i++)
psbt_ = sign_psbt(psbt_origin, leafKeys_WIF[i], "regtest")
psbt_origin = psbt_
const txhex = await pay_psbt_hex(psbt_origin, num - threshold, "regtest")
[ad_2]
Supply hyperlink
Leave a Reply