PSBT Bugfix for multiple of same pubkey in p2ms
This commit is contained in:
parent
29e319525f
commit
e10324f850
3 changed files with 66 additions and 8 deletions
ts_src
|
@ -747,16 +747,32 @@ function canFinalize(
|
|||
return hasSigs(1, input.partialSig);
|
||||
case 'multisig':
|
||||
const p2ms = payments.p2ms({ output: script });
|
||||
return hasSigs(p2ms.m!, input.partialSig);
|
||||
return hasSigs(p2ms.m!, input.partialSig, p2ms.pubkeys);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function hasSigs(neededSigs: number, partialSig?: any[]): boolean {
|
||||
function hasSigs(
|
||||
neededSigs: number,
|
||||
partialSig?: any[],
|
||||
pubkeys?: Buffer[],
|
||||
): boolean {
|
||||
if (!partialSig) return false;
|
||||
if (partialSig.length > neededSigs) throw new Error('Too many signatures');
|
||||
return partialSig.length === neededSigs;
|
||||
let sigs: any;
|
||||
if (pubkeys) {
|
||||
sigs = pubkeys
|
||||
.map(pkey => {
|
||||
const pubkey = ecPairFromPublicKey(pkey, { compressed: true })
|
||||
.publicKey;
|
||||
return partialSig.filter(pSig => pSig.pubkey.equals(pubkey))[0];
|
||||
})
|
||||
.filter(v => !!v);
|
||||
} else {
|
||||
sigs = partialSig;
|
||||
}
|
||||
if (sigs.length > neededSigs) throw new Error('Too many signatures');
|
||||
return sigs.length === neededSigs;
|
||||
}
|
||||
|
||||
function isFinalized(input: PsbtInput): boolean {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue