Finish canFinalize
This commit is contained in:
parent
f28e9cef71
commit
4644e9d2eb
2 changed files with 24 additions and 10 deletions
16
src/psbt.js
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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…
Add table
Reference in a new issue