Skip to content

Commit f4b5982

Browse files
committed
docs: add Taproot related method annotations
1 parent 8d9775c commit f4b5982

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

ts_src/psbt/bip371.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ import { p2tr } from '../payments';
2727

2828
import { 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+
*/
3035
export 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+
*/
6475
export 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+
*/
7591
export 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+
*/
88110
export 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+
*/
100129
export 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+
*/
109145
export function checkTaprootOutputFields(
110146
outputData: PsbtOutput,
111147
newOutputData: PsbtOutput,

0 commit comments

Comments
 (0)