( privateKey: ECPairInterface, notePayload: NotePayload, noteUtxos: IUtxo[], payUtxos: IUtxo[], toAddresses: ISendToAddress[], change: string, network: bitcoin.Network, fee: number = 1000, locktime?: number )
| 68 | * in Partially Signed Bitcoin Transaction (PSBT) format. |
| 69 | */ |
| 70 | export function createP2TRNotePsbt( |
| 71 | privateKey: ECPairInterface, |
| 72 | notePayload: NotePayload, |
| 73 | noteUtxos: IUtxo[], |
| 74 | payUtxos: IUtxo[], |
| 75 | toAddresses: ISendToAddress[], |
| 76 | change: string, |
| 77 | network: bitcoin.Network, |
| 78 | fee: number = 1000, |
| 79 | locktime?: number |
| 80 | ) { |
| 81 | const psbt = new bitcoin.Psbt({network}); |
| 82 | psbt.setVersion(2); |
| 83 | psbt.setLocktime(locktime ?? 0); |
| 84 | |
| 85 | const p2note = generateP2TRNoteInfo(privateKey.publicKey, network); |
| 86 | const tapLeafNoteScript = createTapLeafScript( |
| 87 | p2note.noteRedeem, |
| 88 | p2note.noteP2TR |
| 89 | ); |
| 90 | const tapLeafP2PKScript = createTapLeafScript( |
| 91 | p2note.p2pkRedeem, |
| 92 | p2note.p2pkP2TR |
| 93 | ); |
| 94 | |
| 95 | let totalInput = 0; |
| 96 | |
| 97 | // Add NOTE input |
| 98 | totalInput += addNoteInput( |
| 99 | psbt, |
| 100 | noteUtxos[0]!, |
| 101 | p2note.noteP2TR, |
| 102 | tapLeafNoteScript |
| 103 | ); |
| 104 | |
| 105 | // Add other note inputs |
| 106 | for (let i = 1; i < noteUtxos.length; i++) { |
| 107 | totalInput += addNoteInput( |
| 108 | psbt, |
| 109 | noteUtxos[i]!, |
| 110 | p2note.p2pkP2TR, |
| 111 | tapLeafP2PKScript |
| 112 | ); |
| 113 | } |
| 114 | |
| 115 | // Add pay inputs |
| 116 | totalInput += addPsbtPayUtxos(privateKey, psbt, payUtxos, network); |
| 117 | |
| 118 | // Add outputs |
| 119 | const totalOutput = addOutputs(psbt, toAddresses); |
| 120 | |
| 121 | // Add change output |
| 122 | addChangeOutput(psbt, totalInput, totalOutput, fee, change); |
| 123 | |
| 124 | // Sign inputs |
| 125 | signInputs(psbt, noteUtxos, payUtxos, privateKey, network); |
| 126 | |
| 127 | // Finalize inputs |
no test coverage detected