Skip to content

Commit 6f1e7ea

Browse files
committed
feat: add taproot check for signInputAsync()
1 parent b4d7760 commit 6f1e7ea

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/psbt.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,24 @@ class Psbt {
585585
this.__CACHE,
586586
sighashTypes,
587587
);
588+
const scriptType = this.getInputType(inputIndex);
589+
if (scriptType === 'taproot') {
590+
if (!keyPair.signSchnorr) {
591+
throw new Error(
592+
`Need Schnorr Signer to sign taproot input #${inputIndex}.`,
593+
);
594+
}
595+
return Promise.resolve(keyPair.signSchnorr(hash)).then(signature => {
596+
const partialSig = [
597+
{
598+
pubkey: keyPair.publicKey,
599+
signature,
600+
},
601+
];
602+
// must be changed to use the `updateInput()` public API
603+
this.data.inputs[inputIndex].partialSig = partialSig;
604+
});
605+
}
588606
return Promise.resolve(keyPair.sign(hash)).then(signature => {
589607
const partialSig = [
590608
{

ts_src/psbt.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,26 @@ export class Psbt {
706706
sighashTypes,
707707
);
708708

709+
const scriptType = this.getInputType(inputIndex);
710+
711+
if (scriptType === 'taproot') {
712+
if (!keyPair.signSchnorr) {
713+
throw new Error(
714+
`Need Schnorr Signer to sign taproot input #${inputIndex}.`,
715+
);
716+
}
717+
return Promise.resolve(keyPair.signSchnorr(hash)).then(signature => {
718+
const partialSig = [
719+
{
720+
pubkey: keyPair.publicKey,
721+
signature,
722+
},
723+
];
724+
// must be changed to use the `updateInput()` public API
725+
this.data.inputs[inputIndex].partialSig = partialSig;
726+
});
727+
}
728+
709729
return Promise.resolve(keyPair.sign(hash)).then(signature => {
710730
const partialSig = [
711731
{

0 commit comments

Comments
 (0)