Browse Source

Finish canFinalize

psbt
junderw 6 years ago
parent
commit
4644e9d2eb
No known key found for this signature in database GPG Key ID: B256185D3A971908
  1. 16
      src/psbt.js
  2. 18
      ts_src/psbt.ts

16
src/psbt.js

@ -19,16 +19,22 @@ class Psbt extends bip174_1.Psbt {
); );
if (!script) return false; if (!script) return false;
const scriptType = classifyScript(script); 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) { switch (scriptType) {
case 'pubkey': case 'pubkey':
return false; return hasSigs(1, input.partialSig);
case 'pubkeyhash': case 'pubkeyhash':
return false; return hasSigs(1, input.partialSig);
case 'multisig': case 'multisig':
return false; const p2ms = payments.p2ms({ output: script });
return hasSigs(p2ms.m, input.partialSig);
case 'witnesspubkeyhash': case 'witnesspubkeyhash':
return false; return hasSigs(1, input.partialSig);
default: default:
return false; return false;
} }

18
ts_src/psbt.ts

@ -22,16 +22,24 @@ export class Psbt extends PsbtBase {
); );
if (!script) return false; if (!script) return false;
const scriptType = classifyScript(script); 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) { switch (scriptType) {
case 'pubkey': case 'pubkey':
return false; return hasSigs(1, input.partialSig);
case 'pubkeyhash': case 'pubkeyhash':
return false; return hasSigs(1, input.partialSig);
case 'multisig': case 'multisig':
return false; const p2ms = payments.p2ms({ output: script });
return hasSigs(p2ms.m!, input.partialSig);
case 'witnesspubkeyhash': case 'witnesspubkeyhash':
return false; return hasSigs(1, input.partialSig);
default: default:
return false; return false;
} }

Loading…
Cancel
Save