Finish canFinalize

This commit is contained in:
junderw 2019-07-02 15:18:00 +09:00
parent f28e9cef71
commit 4644e9d2eb
No known key found for this signature in database
GPG key ID: B256185D3A971908
2 changed files with 24 additions and 10 deletions

View file

@ -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;
}

View file

@ -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;
}