Skip to content

Commit 3af7c11

Browse files
committed
feat: use BIP371 fields for taproot inputs
- does not cover `TapBip32Derivation` - does not cover taproot outputs
1 parent 9d4fdcd commit 3af7c11

File tree

15 files changed

+1939
-639
lines changed

15 files changed

+1939
-639
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
],
5151
"dependencies": {
5252
"bech32": "^2.0.0",
53-
"bip174": "^2.0.1",
53+
"bip174": "^2.1.0",
5454
"bs58check": "^2.1.2",
5555
"create-hash": "^1.1.0",
5656
"ripemd160": "^2.0.2",

src/psbt.d.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,34 @@ export declare class Psbt {
8080
getFeeRate(): number;
8181
getFee(): number;
8282
finalizeAllInputs(): this;
83-
finalizeInput(inputIndex: number, finalScriptsFunc?: FinalScriptsFunc): this;
83+
finalizeInput(inputIndex: number, finalScriptsFunc?: FinalScriptsFunc | FinalTaprootScriptsFunc): this;
84+
finalizeTaprootInput(inputIndex: number, tapLeafHashToFinalize?: Buffer, finalScriptsFunc?: FinalTaprootScriptsFunc): this;
85+
private _finalizeInput;
86+
private _finalizeTaprootInput;
8487
getInputType(inputIndex: number): AllScriptType;
8588
inputHasPubkey(inputIndex: number, pubkey: Buffer): boolean;
8689
inputHasHDKey(inputIndex: number, root: HDSigner): boolean;
8790
outputHasPubkey(outputIndex: number, pubkey: Buffer): boolean;
8891
outputHasHDKey(outputIndex: number, root: HDSigner): boolean;
8992
validateSignaturesOfAllInputs(validator: ValidateSigFunction): boolean;
9093
validateSignaturesOfInput(inputIndex: number, validator: ValidateSigFunction, pubkey?: Buffer): boolean;
94+
private _validateSignaturesOfInput;
95+
private validateSignaturesOfTaprootInput;
9196
signAllInputsHD(hdKeyPair: HDSigner, sighashTypes?: number[]): this;
9297
signAllInputsHDAsync(hdKeyPair: HDSigner | HDSignerAsync, sighashTypes?: number[]): Promise<void>;
9398
signInputHD(inputIndex: number, hdKeyPair: HDSigner, sighashTypes?: number[]): this;
9499
signInputHDAsync(inputIndex: number, hdKeyPair: HDSigner | HDSignerAsync, sighashTypes?: number[]): Promise<void>;
95100
signAllInputs(keyPair: Signer, sighashTypes?: number[]): this;
96101
signAllInputsAsync(keyPair: Signer | SignerAsync, sighashTypes?: number[]): Promise<void>;
97102
signInput(inputIndex: number, keyPair: Signer, sighashTypes?: number[]): this;
103+
signTaprootInput(inputIndex: number, keyPair: Signer, tapLeafHashToSign?: Buffer, sighashTypes?: number[]): this;
104+
private _signInput;
105+
private _signTaprootInput;
98106
signInputAsync(inputIndex: number, keyPair: Signer | SignerAsync, sighashTypes?: number[]): Promise<void>;
107+
signTaprootInputAsync(inputIndex: number, keyPair: Signer | SignerAsync, tapLeafHash?: Buffer, sighashTypes?: number[]): Promise<void>;
108+
private _signInputAsync;
109+
private _signTaprootInputAsync;
110+
private checkTaprootHashesForSig;
99111
toBuffer(): Buffer;
100112
toHex(): string;
101113
toBase64(): string;
@@ -143,15 +155,13 @@ export interface HDSigner extends HDSignerBase {
143155
* Return a 64 byte signature (32 byte r and 32 byte s in that order)
144156
*/
145157
sign(hash: Buffer): Buffer;
146-
signSchnorr?(hash: Buffer): Buffer;
147158
}
148159
/**
149160
* Same as above but with async sign method
150161
*/
151162
export interface HDSignerAsync extends HDSignerBase {
152163
derivePath(path: string): HDSignerAsync;
153164
sign(hash: Buffer): Promise<Buffer>;
154-
signSchnorr?(hash: Buffer): Promise<Buffer>;
155165
}
156166
export interface Signer {
157167
publicKey: Buffer;
@@ -177,11 +187,15 @@ declare type FinalScriptsFunc = (inputIndex: number, // Which input is it?
177187
input: PsbtInput, // The PSBT input contents
178188
script: Buffer, // The "meaningful" locking script Buffer (redeemScript for P2SH etc.)
179189
isSegwit: boolean, // Is it segwit?
180-
isTapscript: boolean, // Is taproot script path?
181190
isP2SH: boolean, // Is it P2SH?
182191
isP2WSH: boolean) => {
183192
finalScriptSig: Buffer | undefined;
184-
finalScriptWitness: Buffer | Buffer[] | undefined;
193+
finalScriptWitness: Buffer | undefined;
194+
};
195+
declare type FinalTaprootScriptsFunc = (inputIndex: number, // Which input is it?
196+
input: PsbtInput, // The PSBT input contents
197+
tapLeafHashToFinalize?: Buffer) => {
198+
finalScriptWitness: Buffer | undefined;
185199
};
186-
declare type AllScriptType = 'witnesspubkeyhash' | 'pubkeyhash' | 'multisig' | 'pubkey' | 'taproot' | 'nonstandard' | 'p2sh-witnesspubkeyhash' | 'p2sh-pubkeyhash' | 'p2sh-multisig' | 'p2sh-pubkey' | 'p2sh-nonstandard' | 'p2wsh-pubkeyhash' | 'p2wsh-multisig' | 'p2wsh-pubkey' | 'p2wsh-nonstandard' | 'p2sh-p2wsh-pubkeyhash' | 'p2sh-p2wsh-multisig' | 'p2sh-p2wsh-pubkey' | 'p2sh-p2wsh-nonstandard' | 'p2tr-pubkey' | 'p2tr-nonstandard';
200+
declare type AllScriptType = 'witnesspubkeyhash' | 'pubkeyhash' | 'multisig' | 'pubkey' | 'nonstandard' | 'p2sh-witnesspubkeyhash' | 'p2sh-pubkeyhash' | 'p2sh-multisig' | 'p2sh-pubkey' | 'p2sh-nonstandard' | 'p2wsh-pubkeyhash' | 'p2wsh-multisig' | 'p2wsh-pubkey' | 'p2wsh-nonstandard' | 'p2sh-p2wsh-pubkeyhash' | 'p2sh-p2wsh-multisig' | 'p2sh-p2wsh-pubkey' | 'p2sh-p2wsh-nonstandard';
187201
export {};

0 commit comments

Comments
 (0)