( msgpackEncodedData: Buffer, pubkey: Buffer, network: bitcoin.Network )
| 59 | |
| 60 | // Generate a Taproot transaction that packs all data into the redemption script |
| 61 | export function generateP2TRCommitDataInfo( |
| 62 | msgpackEncodedData: Buffer, |
| 63 | pubkey: Buffer, |
| 64 | network: bitcoin.Network |
| 65 | ) { |
| 66 | const xOnlyPubkey = toXOnly(pubkey); |
| 67 | |
| 68 | const note_script = bitcoin.script.fromASM( |
| 69 | buildDataScript(msgpackEncodedData, xOnlyPubkey) |
| 70 | ); |
| 71 | |
| 72 | const p2pk_script_asm = `${xOnlyPubkey.toString("hex")} OP_CHECKSIG`; |
| 73 | const p2pk_script = bitcoin.script.fromASM(p2pk_script_asm); |
| 74 | |
| 75 | const scriptTree: Taptree = [ |
| 76 | { |
| 77 | output: note_script, |
| 78 | }, |
| 79 | { |
| 80 | output: p2pk_script, |
| 81 | }, |
| 82 | ]; |
| 83 | const script_p2tr = bitcoin.payments.p2tr({ |
| 84 | internalPubkey: xOnlyPubkey, |
| 85 | scriptTree, |
| 86 | network, |
| 87 | }); |
| 88 | |
| 89 | const note_redeem = { |
| 90 | output: note_script, |
| 91 | redeemVersion: 192, |
| 92 | }; |
| 93 | const p2pk_redeem = { |
| 94 | output: p2pk_script, |
| 95 | redeemVersion: 192, |
| 96 | }; |
| 97 | |
| 98 | const p2pk_p2tr = bitcoin.payments.p2tr({ |
| 99 | internalPubkey: xOnlyPubkey, |
| 100 | scriptTree, |
| 101 | redeem: p2pk_redeem, |
| 102 | network, |
| 103 | }); |
| 104 | |
| 105 | const note_p2tr = bitcoin.payments.p2tr({ |
| 106 | internalPubkey: xOnlyPubkey, |
| 107 | scriptTree, |
| 108 | redeem: note_redeem, |
| 109 | network, |
| 110 | }); |
| 111 | |
| 112 | return { |
| 113 | scriptP2TR: script_p2tr, |
| 114 | noteP2TR: note_p2tr, |
| 115 | p2pkP2TR: p2pk_p2tr, |
| 116 | noteRedeem: note_redeem, |
| 117 | p2pkRedeem: p2pk_redeem, |
| 118 | }; |
no test coverage detected