Skip to content

Commit

Permalink
TST: add caravan ms test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Overtorment committed Oct 20, 2022
1 parent ffc68e2 commit fa8589f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
3 changes: 1 addition & 2 deletions class/wallets/multisig-hd-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,7 @@ export class MultisigHDWallet extends AbstractHDElectrumWallet {

for (const pk of json.extendedPublicKeys) {
const path = this.constructor.isPathValid(json.bip32Path) ? json.bip32Path : "m/1'";
// wtf, where caravan stores fingerprints..?
this.addCosigner(pk.xpub, '00000000', path);
this.addCosigner(pk.xpub, pk.xfp ?? '00000000', path);
}
}

Expand Down
30 changes: 30 additions & 0 deletions tests/unit/fixtures/caravan-multisig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "Vault #1",
"addressType": "P2WSH",
"network": "mainnet",
"quorum": {
"requiredSigners": 2,
"totalSigners": 3
},
"startingAddressIndex": 0,
"extendedPublicKeys": [
{
"name": "io",
"xpub": "xpub6EJoguJn6okK6ymxkU53BZgjf4kqrL19uvTwqVnPRaV8qYvx1RhGtyKZxLhzY4YLCYtvB6DsGk1uR3GFBMvwgc5qz19WAxm2nSXZcoyNftY",
"bip32Path": "m/48'/0'/0'/2'",
"xfp": "A3909080"
},
{
"name": "bluewater",
"xpub": "xpub6FL52qF9cn2nL7T8gv6gStR8GcezKF4LgY53VLbi5sqRjc4PpBuYFp3nfep884hkuF9dC7KZ11mkthE1NVzbX98QmoJQqBFxQbHnpJ5vQKB",
"bip32Path": "m/48'/0'/0'/2'",
"xfp": "7AB71DF0"
},
{
"name": "Unknown",
"xpub": "xpub6ERjK6ubp5p7UUByXGadKvHcqEUMxvWPr7DkzqHz7GnnZEqdR9ffE3Y1DffYqRjJzeGWL1st1qH4kEaZCzjVnJoZ2PJUcnThi48D71zd6sJ",
"bip32Path": "Unknown",
"xfp": "F11B9FF2"
}
]
}
16 changes: 12 additions & 4 deletions tests/unit/multisig-hd-wallet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2125,15 +2125,23 @@ describe('multisig-cosigner', () => {

it('can parse files from sparrow wallet', () => {
const secrets = [
JSON.stringify(require('./fixtures/fromsparrow-electrum.json')),
require('fs').readFileSync('./tests/unit/fixtures/fromsparrow-coldcard.txt', 'ascii'),
JSON.stringify(require('./fixtures/fromsparrow-specter.json')),
[JSON.stringify(require('./fixtures/fromsparrow-electrum.json')), false],
[require('fs').readFileSync('./tests/unit/fixtures/fromsparrow-coldcard.txt', 'ascii'), true],
[JSON.stringify(require('./fixtures/fromsparrow-specter.json')), true],
[JSON.stringify(require('./fixtures/caravan-multisig.json')), true],
];

for (const s of secrets) {
for (const [s, verifyFingerprints] of secrets) {
const w = new MultisigHDWallet();
w.setSecret(s);

if (verifyFingerprints) {
assert.strictEqual(w.getFingerprint(1), 'A3909080');
assert.strictEqual(w.getFingerprint(2), '7AB71DF0');
assert.strictEqual(w.getFingerprint(3), 'F11B9FF2');
}

assert.ok(w.isNativeSegwit());
assert.strictEqual(w._getExternalAddressByIndex(0), 'bc1qtysquqsjqjfqvhd6l2h470hdgwhcahs4nq2ca49cyxftwjnjt9ssh8emel');
}
});
Expand Down

0 comments on commit fa8589f

Please sign in to comment.