@@ -27,6 +27,11 @@ import { p2tr } from '../payments';
2727
2828import { signatureBlocksAction } from './psbtutils' ;
2929
30+ /**
31+ * Converts a public key to an X-only public key.
32+ * @param pubKey The public key to convert.
33+ * @returns The X-only public key.
34+ */
3035export const toXOnly = ( pubKey : Buffer ) =>
3136 pubKey . length === 32 ? pubKey : pubKey . slice ( 1 , 33 ) ;
3237
@@ -61,6 +66,12 @@ export function tapScriptFinalizer(
6166 }
6267}
6368
69+ /**
70+ * Serializes a taproot signature.
71+ * @param sig The signature to serialize.
72+ * @param sighashType The sighash type. Optional.
73+ * @returns The serialized taproot signature.
74+ */
6475export function serializeTaprootSignature (
6576 sig : Buffer ,
6677 sighashType ?: number ,
@@ -72,6 +83,11 @@ export function serializeTaprootSignature(
7283 return Buffer . concat ( [ sig , sighashTypeByte ] ) ;
7384}
7485
86+ /**
87+ * Checks if a PSBT input is a taproot input.
88+ * @param input The PSBT input to check.
89+ * @returns True if the input is a taproot input, false otherwise.
90+ */
7591export function isTaprootInput ( input : PsbtInput ) : boolean {
7692 return (
7793 input &&
@@ -85,6 +101,12 @@ export function isTaprootInput(input: PsbtInput): boolean {
85101 ) ;
86102}
87103
104+ /**
105+ * Checks if a PSBT output is a taproot output.
106+ * @param output The PSBT output to check.
107+ * @param script The script to check. Optional.
108+ * @returns True if the output is a taproot output, false otherwise.
109+ */
88110export function isTaprootOutput ( output : PsbtOutput , script ?: Buffer ) : boolean {
89111 return (
90112 output &&
@@ -97,6 +119,13 @@ export function isTaprootOutput(output: PsbtOutput, script?: Buffer): boolean {
97119 ) ;
98120}
99121
122+ /**
123+ * Checks the taproot input fields for consistency.
124+ * @param inputData The original input data.
125+ * @param newInputData The new input data.
126+ * @param action The action being performed.
127+ * @throws Throws an error if the input fields are inconsistent.
128+ */
100129export function checkTaprootInputFields (
101130 inputData : PsbtInput ,
102131 newInputData : PsbtInput ,
@@ -106,6 +135,13 @@ export function checkTaprootInputFields(
106135 checkIfTapLeafInTree ( inputData , newInputData , action ) ;
107136}
108137
138+ /**
139+ * Checks the taproot output fields for consistency.
140+ * @param outputData The original output data.
141+ * @param newOutputData The new output data.
142+ * @param action The action being performed.
143+ * @throws Throws an error if the output fields are inconsistent.
144+ */
109145export function checkTaprootOutputFields (
110146 outputData : PsbtOutput ,
111147 newOutputData : PsbtOutput ,
0 commit comments