REF: speedup multisig creation (closes #2097)

This commit is contained in:
Overtorment 2020-11-13 18:22:48 +00:00
parent 04838a17b9
commit 89ac4f0f72
3 changed files with 11 additions and 3 deletions

View file

@ -189,9 +189,9 @@ export class MultisigHDWallet extends AbstractHDElectrumWallet {
}
}
} else {
// mnemonics. lets derive fingerprint
// mnemonics. lets derive fingerprint (if it wasnt provided)
if (!bip39.validateMnemonic(key)) throw new Error('Not a valid mnemonic phrase');
fingerprint = MultisigHDWallet.seedToFingerprint(key);
fingerprint = fingerprint || MultisigHDWallet.seedToFingerprint(key);
}
if (fingerprint && this._cosignersFingerprints.indexOf(fingerprint.toUpperCase()) !== -1 && fingerprint !== '00000000') {

View file

@ -154,7 +154,8 @@ const WalletsAddMultisigStep2 = () => {
throw new Error('This should never happen');
}
for (const cc of cosigners) {
w.addCosigner(cc[0], cc[1], cc[2]);
const fp = cc[1] || getFpCacheForMnemonics(cc[0]);
w.addCosigner(cc[0], fp, cc[2]);
}
w.setLabel('Multisig Vault');
await w.fetchBalance();

View file

@ -711,6 +711,13 @@ describe('multisig-wallet (native segwit)', () => {
assert.strictEqual(w.getCosignerForFingerprint(fp1cobo), Zpub1);
assert.strictEqual(w.getCosignerForFingerprint(fp2coldcard), process.env.MNEMONICS_COLDCARD);
assert.strictEqual(w.howManySignaturesCanWeMake(), 1);
// now, provide fp with mnemonics and expect that wallet wont recalculate fp, and will use provided
w = new MultisigHDWallet();
w.addCosigner(process.env.MNEMONICS_COLDCARD, 'DEADBABE');
w.addCosigner(process.env.MNEMONICS_COBO);
assert.strictEqual(w.getFingerprint(1), 'DEADBABE');
assert.strictEqual(w.getCosignerForFingerprint('DEADBABE'), process.env.MNEMONICS_COLDCARD);
});
it('basic operations work for 2-of-3', async () => {