Skip to content

Commit a3dde5c

Browse files
authored
feat: script to get multisig xpub from seed easily (#520)
1 parent 1d1c899 commit a3dde5c

File tree

3 files changed

+60
-3
lines changed

3 files changed

+60
-3
lines changed

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ else
6565
node dist-scripts/get_xpub_from_seed.js $(seed)
6666
endif
6767

68+
# Internal target to run multisig_xpub_from_seed command.
69+
.PHONY: .run_multisig_xpub_from_seed
70+
.run_multisig_xpub_from_seed:
71+
ifeq ($(seed),)
72+
@echo "Usage: make multisig_xpub_from_seed seed=YOUR_SEED"
73+
else
74+
node dist-scripts/get_multisig_xpub_from_seed.js $(seed)
75+
endif
76+
6877
# Command: generate words
6978
.PHONY: words
7079
words: .script-build-dirs .run_words .script-clean-dirs
@@ -76,3 +85,7 @@ create_hsm_key: .script-build-dirs .run_create_hsm_key .script-clean-dirs
7685
# Command: Derive xPub from seed
7786
.PHONY: xpub_from_seed
7887
xpub_from_seed: .script-build-dirs .run_xpub_from_seed .script-clean-dirs
88+
89+
# Command: Derive multisig xPub from seed
90+
.PHONY: multisig_xpub_from_seed
91+
multisig_xpub_from_seed: .script-build-dirs .run_multisig_xpub_from_seed .script-clean-dirs

docs/multisig-wallets.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,35 @@ The order of the pubkeys is not important.
4444

4545
## Collect pubkeys
4646

47-
Configure your wallet normally and use the `/multisig-pubkey` to get your pubkey.
47+
There are two ways for getting the pubkey.
48+
49+
1. Configure your wallet normally and use the `/multisig-pubkey` to get your pubkey.
50+
2. Use the `make multisig_xpub_from_seed` command to generate the pubkey.
51+
4852
This public key will be shared among all participants and will be used in the configuration file in the pubkeys array.
49-
You don't need to start the wallet yet.
5053

5154
### POST /multisig-pubkey
5255

56+
You don't need to start the wallet before sending this request, just have the seedKey configured in your configuration file.
57+
5358
Parameters:
5459

5560
`seedKey`: Parameter to define which seed (from the object seeds in the config file) will be used to generate the pubkey.
5661
`passphrase`: Optional parameter to generate the pubkey with a passphrase. If not sent we use empty string. Should be the same when starting the wallet later.
5762

58-
5963
```bash
6064
$ curl -X POST --data-urlencode "passphrase=123" --data "seedKey=default" http://localhost:8000/multisig-pubkey
6165
{"success":true,"xpubkey":"xpub..."}
6266
```
6367

68+
### make multisig_xpub_from_seed
69+
70+
Just run the command, passing the seed key as argument. This method does not support passphrase yet, use the previous method if you need it.
71+
72+
```bash
73+
make multisig_xpub_from_seed seed='<seed words>'
74+
```
75+
6476
## Start a MultiSig Wallet
6577

6678
Same as the start on [README.md](./README.md), but include the parameter `"multisig": true` to the request body.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Copyright (c) Hathor Labs and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import hathorLib from '@hathor/wallet-lib';
9+
10+
function main() {
11+
/**
12+
* argv contains the cli arguments that made this script run, including the interpreter
13+
* and script filename so to get the actual seed passed via cli we need to remove the
14+
* other arguments.
15+
* argv = ["babel-node", "get_xpub_from_seed.js", "word0", ..., "wordLast"];
16+
* We need to remove the first 2 and join the other arguments into a single string
17+
* separated by spaces
18+
*/
19+
const seed = process.argv.slice(2).join(' ');
20+
const xpubkey = hathorLib.walletUtils.getMultiSigXPubFromWords(seed);
21+
22+
// Print the xpubkey
23+
console.log(xpubkey);
24+
}
25+
26+
try {
27+
main();
28+
process.exit(0);
29+
} catch (err) {
30+
console.error(err);
31+
process.exit(1);
32+
}

0 commit comments

Comments
 (0)