MCPcopy Create free account
hub / github.com/NoteProtocol/NoteWallet / generateP2TRNoteInfoV1

Function generateP2TRNoteInfoV1

src/btc/btc-note.ts:121–176  ·  view source on GitHub ↗
(
  pubkey: Buffer,
  network: bitcoin.Network
)

Source from the content-addressed store, hash-verified

119}
120
121export function generateP2TRNoteInfoV1(
122 pubkey: Buffer,
123 network: bitcoin.Network
124) {
125 const xOnlyPubkey = toXOnly(pubkey);
126
127 const note_script = bitcoin.script.fromASM(buildNoteScript(xOnlyPubkey));
128
129 const p2pk_script_asm = `${pubkey.toString("hex")} OP_CHECKSIG`;
130 const p2pk_script = bitcoin.script.fromASM(p2pk_script_asm);
131
132 const scriptTree: Taptree = [
133 {
134 output: note_script,
135 },
136 {
137 output: p2pk_script,
138 },
139 ];
140 const script_p2tr = bitcoin.payments.p2tr({
141 internalPubkey: xOnlyPubkey,
142 scriptTree,
143 network,
144 });
145
146 const note_redeem = {
147 output: note_script,
148 redeemVersion: 192,
149 };
150 const p2pk_redeem = {
151 output: p2pk_script,
152 redeemVersion: 192,
153 };
154
155 const p2pk_p2tr = bitcoin.payments.p2tr({
156 internalPubkey: xOnlyPubkey,
157 scriptTree,
158 redeem: p2pk_redeem,
159 network,
160 });
161
162 const note_p2tr = bitcoin.payments.p2tr({
163 internalPubkey: xOnlyPubkey,
164 scriptTree,
165 redeem: note_redeem,
166 network,
167 });
168
169 return {
170 scriptP2TR: script_p2tr,
171 noteP2TR: note_p2tr,
172 p2pkP2TR: p2pk_p2tr,
173 noteRedeem: note_redeem,
174 p2pkRedeem: p2pk_redeem,
175 };
176}

Callers 2

createP2TRNotePsbtV1Function · 0.90

Calls 2

toXOnlyFunction · 0.90
buildNoteScriptFunction · 0.90

Tested by

no test coverage detected