(pubkey: Buffer, network: bitcoin.Network)
| 3 | |
| 4 | // Generate a regular NOTE locking script |
| 5 | export function generateP2TRNoteInfo(pubkey: Buffer, network: bitcoin.Network) { |
| 6 | const xOnlyPubkey = toXOnly(pubkey); |
| 7 | |
| 8 | // Construct a regular NOTE locking script |
| 9 | const note_script = bitcoin.script.fromASM(buildNoteScript(xOnlyPubkey)); |
| 10 | |
| 11 | const p2pk_script_asm = `${xOnlyPubkey.toString("hex")} OP_CHECKSIG`; |
| 12 | const p2pk_script = bitcoin.script.fromASM(p2pk_script_asm); |
| 13 | |
| 14 | const scriptTree: Taptree = [ |
| 15 | { |
| 16 | output: note_script, |
| 17 | }, |
| 18 | { |
| 19 | output: p2pk_script, |
| 20 | }, |
| 21 | ]; |
| 22 | const script_p2tr = bitcoin.payments.p2tr({ |
| 23 | internalPubkey: xOnlyPubkey, |
| 24 | scriptTree, |
| 25 | network, |
| 26 | }); |
| 27 | |
| 28 | const note_redeem = { |
| 29 | output: note_script, |
| 30 | redeemVersion: 192, |
| 31 | }; |
| 32 | const p2pk_redeem = { |
| 33 | output: p2pk_script, |
| 34 | redeemVersion: 192, |
| 35 | }; |
| 36 | |
| 37 | const p2pk_p2tr = bitcoin.payments.p2tr({ |
| 38 | internalPubkey: xOnlyPubkey, |
| 39 | scriptTree, |
| 40 | redeem: p2pk_redeem, |
| 41 | network, |
| 42 | }); |
| 43 | |
| 44 | const note_p2tr = bitcoin.payments.p2tr({ |
| 45 | internalPubkey: xOnlyPubkey, |
| 46 | scriptTree, |
| 47 | redeem: note_redeem, |
| 48 | network, |
| 49 | }); |
| 50 | |
| 51 | return { |
| 52 | scriptP2TR: script_p2tr, |
| 53 | noteP2TR: note_p2tr, |
| 54 | p2pkP2TR: p2pk_p2tr, |
| 55 | noteRedeem: note_redeem, |
| 56 | p2pkRedeem: p2pk_redeem, |
| 57 | }; |
| 58 | } |
| 59 | |
| 60 | // Generate a Taproot transaction that packs all data into the redemption script |
| 61 | export function generateP2TRCommitDataInfo( |
no test coverage detected