diff --git a/src/psbt.js b/src/psbt.js index fa4ba9f..cf1edca 100644 --- a/src/psbt.js +++ b/src/psbt.js @@ -19,16 +19,22 @@ class Psbt extends bip174_1.Psbt { ); if (!script) return false; const scriptType = classifyScript(script); - // TODO: for each type + const hasSigs = (neededSigs, partialSig) => { + if (!partialSig) return false; + if (partialSig.length > neededSigs) + throw new Error('Too many signatures'); + return partialSig.length === neededSigs; + }; switch (scriptType) { case 'pubkey': - return false; + return hasSigs(1, input.partialSig); case 'pubkeyhash': - return false; + return hasSigs(1, input.partialSig); case 'multisig': - return false; + const p2ms = payments.p2ms({ output: script }); + return hasSigs(p2ms.m, input.partialSig); case 'witnesspubkeyhash': - return false; + return hasSigs(1, input.partialSig); default: return false; } diff --git a/ts_src/psbt.ts b/ts_src/psbt.ts index 63cc318..b1190aa 100644 --- a/ts_src/psbt.ts +++ b/ts_src/psbt.ts @@ -22,16 +22,24 @@ export class Psbt extends PsbtBase { ); if (!script) return false; const scriptType = classifyScript(script); - // TODO: for each type + + const hasSigs = (neededSigs: number, partialSig?: any[]): boolean => { + if (!partialSig) return false; + if (partialSig.length > neededSigs) + throw new Error('Too many signatures'); + return partialSig.length === neededSigs; + }; + switch (scriptType) { case 'pubkey': - return false; + return hasSigs(1, input.partialSig); case 'pubkeyhash': - return false; + return hasSigs(1, input.partialSig); case 'multisig': - return false; + const p2ms = payments.p2ms({ output: script }); + return hasSigs(p2ms.m!, input.partialSig); case 'witnesspubkeyhash': - return false; + return hasSigs(1, input.partialSig); default: return false; }