hyper-multisig-cli 0.0.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +129 -17
- package/README.md.orig +169 -0
- package/bin.js +84 -24
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|

|
|
2
2
|
|
|
3
|
-
# Hyper Multisig
|
|
3
|
+
# Hyper Multisig CLI
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
CLI to safely create, verify and commit multisig signing requests for hypercores and hyperdrives.
|
|
6
|
+
|
|
7
|
+
Includes sanity checks to avoid common mistakes and risky releases, like detecting conflicts and ensuring all cores are fully seeded by other peers before committing.
|
|
8
|
+
|
|
9
|
+
Uses [hyper-multisig](https://github.com/holepunchto/hyper-multisig) under the hood.
|
|
7
10
|
|
|
8
11
|
## Installation
|
|
9
12
|
|
|
@@ -18,36 +21,145 @@ hyper-multisig --help
|
|
|
18
21
|
hyper-multisig-bare --help
|
|
19
22
|
```
|
|
20
23
|
|
|
21
|
-
|
|
24
|
+
## Example
|
|
25
|
+
|
|
26
|
+
This example sets up a multisig hypercore with 1 signer and a quorum of 1, so it can be run by a single person. A more standard setup is 3 signers with a quorum of 2.
|
|
27
|
+
|
|
28
|
+
### Create Signing Key
|
|
29
|
+
|
|
30
|
+
First use [hypercore-sign](https://github.com/holepunchto/hypercore-sign) to create your signing key:
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
npm i -g hypercore-sign
|
|
34
|
+
hypercore-sign-generate-keys
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Take note of your public key.
|
|
38
|
+
|
|
39
|
+
### Create Source Core
|
|
40
|
+
|
|
41
|
+
We just create a dummy source core for this example:
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
import Corestore from 'corestore'
|
|
45
|
+
import Hyperswarm from 'hyperswarm'
|
|
46
|
+
|
|
47
|
+
const desiredLength = 3
|
|
22
48
|
|
|
23
|
-
|
|
49
|
+
const store = new Corestore('temp-example-store')
|
|
50
|
+
const core = store.get({ name: 'source-core' })
|
|
51
|
+
await core.ready()
|
|
24
52
|
|
|
25
|
-
|
|
53
|
+
for (let i = core.length; i < desiredLength; i++) await core.append(`Block-${i}`)
|
|
54
|
+
|
|
55
|
+
const swarm = new Hyperswarm()
|
|
56
|
+
swarm.on('connection', (conn) => { store.replicate(conn) })
|
|
57
|
+
swarm.join(core.discoveryKey)
|
|
58
|
+
console.log(`Swarming key ${core.id} (length ${core.length})`)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Keep this process running, because we will need to download this hypercore to be able to create and commit the signing request.
|
|
62
|
+
|
|
63
|
+
### Create Config
|
|
64
|
+
|
|
65
|
+
Create `multisig.json` in your current directory
|
|
26
66
|
|
|
27
67
|
```json
|
|
28
68
|
{
|
|
29
|
-
"publicKeys": ["
|
|
30
|
-
"namespace": "
|
|
31
|
-
"srcKey": "
|
|
69
|
+
"publicKeys": ["paste-here-the-key-generated-by-hypercore-sign-generate-keys"],
|
|
70
|
+
"namespace": "dummy-test-core",
|
|
71
|
+
"srcKey": "paste-here-the-key-of-your-source-core"
|
|
32
72
|
}
|
|
33
73
|
```
|
|
34
74
|
|
|
35
|
-
|
|
75
|
+
Note that the key of the multisig hypercore is fully determined by the public keys and namespace. This means you can never use the same namespace with the same signers.
|
|
76
|
+
|
|
77
|
+
It is possible to switch to a different `srcKey`.
|
|
78
|
+
|
|
79
|
+
### Create Signing Request
|
|
36
80
|
|
|
37
81
|
```shell
|
|
38
|
-
hyper-multisig request-core
|
|
82
|
+
hyper-multisig request-core 3 --first-commit
|
|
39
83
|
```
|
|
40
84
|
|
|
41
|
-
|
|
85
|
+
You should see an error that the source core is not well seeded. It errors because committing any requests in this situation is dangerous.
|
|
42
86
|
|
|
43
|
-
|
|
87
|
+
Fix it by running this script in another terminal window, filling in the correct source key:
|
|
44
88
|
|
|
45
|
-
```shell
|
|
46
|
-
hyper-multisig verify-core <request> <response1> <response2>
|
|
47
89
|
```
|
|
90
|
+
import Corestore from 'corestore'
|
|
91
|
+
import Hyperswarm from 'hyperswarm'
|
|
92
|
+
import IdEnc from 'hypercore-id-encoding'
|
|
93
|
+
|
|
94
|
+
const stringKey = '' // use the key of your source core
|
|
95
|
+
|
|
96
|
+
const store = new Corestore('temp-example-seeder-store-${Math.random}')
|
|
97
|
+
const key = IdEnc.decode(stringKey)
|
|
98
|
+
const core = store.get({ key })
|
|
99
|
+
await core.ready()
|
|
100
|
+
|
|
101
|
+
const swarm = new Hyperswarm()
|
|
102
|
+
swarm.on('connection', (conn) => { store.replicate(conn) })
|
|
103
|
+
swarm.join(core.discoveryKey)
|
|
104
|
+
console.log(`Swarming key ${core.id}`)
|
|
105
|
+
|
|
106
|
+
core.download({ start: 0, end: -1 })
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Note: in practice you would use a seeder service, like a [blind-peer](https://github.com/holepunchto/blind-peer), to ensure your source core is well seeded. Having two seeder processes running locally is not safe (if your computer is turned off, the core is no longer available).
|
|
48
110
|
|
|
49
|
-
|
|
111
|
+
Now rerun the command:
|
|
50
112
|
|
|
51
113
|
```shell
|
|
52
|
-
hyper-multisig
|
|
114
|
+
hyper-multisig request-core 3 --first-commit
|
|
53
115
|
```
|
|
116
|
+
|
|
117
|
+
Take note of the signing request. It looks like this:
|
|
118
|
+
|
|
119
|
+
```
|
|
120
|
+
hypercore-sign yebob...
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Sign Request
|
|
124
|
+
|
|
125
|
+
Run the hypercore-sign command, and take note of the result. It looks like
|
|
126
|
+
|
|
127
|
+
```
|
|
128
|
+
Reply with:
|
|
129
|
+
|
|
130
|
+
yeqmm...
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Verify Request
|
|
134
|
+
|
|
135
|
+
```
|
|
136
|
+
hyper-multisig verify-core --first-commit <the signing request> <your signing response>
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
You should see the confirmation that the core is safe to commit.
|
|
140
|
+
|
|
141
|
+
### Commit Request
|
|
142
|
+
|
|
143
|
+
Run the same command as above, but replace 'verify-core' with 'commit-core'.
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
hyper-multisig commit-core --first-commit <the signing request> <your signing response>
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
You should see logs like
|
|
150
|
+
|
|
151
|
+
```
|
|
152
|
+
Verifying the core is safe to commit (source <source key> to multisig target <target key>)
|
|
153
|
+
Opened connection
|
|
154
|
+
Opened connection
|
|
155
|
+
Committing the core...
|
|
156
|
+
Committed the core (key <target key>)
|
|
157
|
+
Waiting for remote seeders to pick up the changes...
|
|
158
|
+
Please add this key to the seeders now. The logs here will notify you when it is picked up by them. Do not shut down until that happens.
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Do as the logs instruct, and add your target key to 2 or more seeders. For this example, simple run 2 more seeder scripts like above, but this time for the target key.
|
|
162
|
+
|
|
163
|
+
Once the program detects at least 2 seeders have fully downloaded the multisig drive, it will inform you it is done. Shut down with ctrl-c.
|
|
164
|
+
|
|
165
|
+
Note: for any future updates to your multisig core, remove the `first-commit` flag.
|
package/README.md.orig
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
# Hyper Multisig CLI
|
|
4
|
+
|
|
5
|
+
CLI to safely create, verify and commit multisig signing requests for hypercores and hyperdrives.
|
|
6
|
+
|
|
7
|
+
Includes sanity checks to avoid common mistakes and risky releases, like detecting conflicts and ensuring all cores are fully seeded by other peers before committing.
|
|
8
|
+
|
|
9
|
+
Uses [hyper-multisig](https://github.com/holepunchto/hyper-multisig) under the hood.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```shell
|
|
14
|
+
npm i -g hyper-multisig-cli@latest
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```shell
|
|
20
|
+
hyper-multisig --help
|
|
21
|
+
hyper-multisig-bare --help
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Example
|
|
25
|
+
|
|
26
|
+
This example sets up a multisig hypercore with 1 signer and a quorum of 1, so it can be run by a single person. A more standard setup is 3 signers with a quorum of 2.
|
|
27
|
+
|
|
28
|
+
<<<<<<< HEAD
|
|
29
|
+
### Create Signing Key
|
|
30
|
+
|
|
31
|
+
First use [hypercore-sign](https://github.com/holepunchto/hypercore-sign) to create your signing key:
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
npm i -g hypercore-sign
|
|
35
|
+
hypercore-sign-generate-keys
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Take note of your public key.
|
|
39
|
+
|
|
40
|
+
### Create Source Core
|
|
41
|
+
|
|
42
|
+
We just create a dummy source core for this example:
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
import Corestore from 'corestore'
|
|
46
|
+
import Hyperswarm from 'hyperswarm'
|
|
47
|
+
|
|
48
|
+
const desiredLength = 3
|
|
49
|
+
|
|
50
|
+
const store = new Corestore('temp-example-store')
|
|
51
|
+
const core = store.get({ name: 'source-core' })
|
|
52
|
+
await core.ready()
|
|
53
|
+
|
|
54
|
+
for (let i = core.length; i < desiredLength; i++) await core.append(`Block-${i}`)
|
|
55
|
+
|
|
56
|
+
const swarm = new Hyperswarm()
|
|
57
|
+
swarm.on('connection', (conn) => { store.replicate(conn) })
|
|
58
|
+
swarm.join(core.discoveryKey)
|
|
59
|
+
console.log(`Swarming key ${core.id} (length ${core.length})`)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Keep this process running, because we will need to download this hypercore to be able to create and commit the signing request.
|
|
63
|
+
|
|
64
|
+
### Create Config
|
|
65
|
+
|
|
66
|
+
Create `config.json` in your current directory
|
|
67
|
+
=======
|
|
68
|
+
Create `multisig.json`
|
|
69
|
+
>>>>>>> 0db29072a521ab91feb6cb973355c7954b3346a5
|
|
70
|
+
|
|
71
|
+
```json
|
|
72
|
+
{
|
|
73
|
+
"publicKeys": ["paste-here-the-key-generated-by-hypercore-sign-generate-keys"],
|
|
74
|
+
"namespace": "dummy-test-core",
|
|
75
|
+
"srcKey": "paste-here-the-key-of-your-source-core"
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Note that the key of the multisig hypercore is fully determined by the public keys and namespace. This means you can never use the same namespace with the same signers.
|
|
80
|
+
|
|
81
|
+
It is possible to switch to a different `srcKey`.
|
|
82
|
+
|
|
83
|
+
### Create Signing Request
|
|
84
|
+
|
|
85
|
+
```shell
|
|
86
|
+
hyper-multisig request-core 3 --first-commit
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
You should see an error that the source core is not well seeded. It errors because committing any requests in this situation is dangerous.
|
|
90
|
+
|
|
91
|
+
Fix it by running this script in another terminal window, filling in the correct source key:
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
import Corestore from 'corestore'
|
|
95
|
+
import Hyperswarm from 'hyperswarm'
|
|
96
|
+
import IdEnc from 'hypercore-id-encoding'
|
|
97
|
+
|
|
98
|
+
const stringKey = '' // use the key of your source core
|
|
99
|
+
|
|
100
|
+
const store = new Corestore('temp-example-seeder-store-${Math.random}')
|
|
101
|
+
const key = IdEnc.decode(stringKey)
|
|
102
|
+
const core = store.get({ key })
|
|
103
|
+
await core.ready()
|
|
104
|
+
|
|
105
|
+
const swarm = new Hyperswarm()
|
|
106
|
+
swarm.on('connection', (conn) => { store.replicate(conn) })
|
|
107
|
+
swarm.join(core.discoveryKey)
|
|
108
|
+
console.log(`Swarming key ${core.id}`)
|
|
109
|
+
|
|
110
|
+
core.download({ start: 0, end: -1 })
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Note: in practice you would use a seeder service, like a [blind-peer](https://github.com/holepunchto/blind-peer), to ensure your source core is well seeded. Having two seeder processes running locally is not safe (if your computer is turned off, the core is no longer available).
|
|
114
|
+
|
|
115
|
+
Now rerun the command:
|
|
116
|
+
|
|
117
|
+
```shell
|
|
118
|
+
hyper-multisig request-core 3 --first-commit
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Take note of the signing request. It looks like this:
|
|
122
|
+
|
|
123
|
+
```
|
|
124
|
+
hypercore-sign yebob...
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Sign Request
|
|
128
|
+
|
|
129
|
+
Run the hypercore-sign command, and take note of the result. It looks like
|
|
130
|
+
|
|
131
|
+
```
|
|
132
|
+
Reply with:
|
|
133
|
+
|
|
134
|
+
yeqmm...
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Verify Request
|
|
138
|
+
|
|
139
|
+
```
|
|
140
|
+
hyper-multisig verify-core --first-commit <the signing request> <your signing response>
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
You should see the confirmation that the core is safe to commit.
|
|
144
|
+
|
|
145
|
+
### Commit Request
|
|
146
|
+
|
|
147
|
+
Run the same command as above, but replace 'verify-core' with 'commit-core'.
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
hyper-multisig commit-core --first-commit <the signing request> <your signing response>
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
You should see logs like
|
|
154
|
+
|
|
155
|
+
```
|
|
156
|
+
Verifying the core is safe to commit (source <source key> to multisig target <target key>)
|
|
157
|
+
Opened connection
|
|
158
|
+
Opened connection
|
|
159
|
+
Committing the core...
|
|
160
|
+
Committed the core (key <target key>)
|
|
161
|
+
Waiting for remote seeders to pick up the changes...
|
|
162
|
+
Please add this key to the seeders now. The logs here will notify you when it is picked up by them. Do not shut down until that happens.
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Do as the logs instruct, and add your target key to 2 or more seeders. For this example, simple run 2 more seeder scripts like above, but this time for the target key.
|
|
166
|
+
|
|
167
|
+
Once the program detects at least 2 seeders have fully downloaded the multisig drive, it will inform you it is done. Shut down with ctrl-c.
|
|
168
|
+
|
|
169
|
+
Note: for any future updates to your multisig core, remove the `first-commit` flag.
|
package/bin.js
CHANGED
|
@@ -10,7 +10,7 @@ const Hyperswarm = require('hyperswarm')
|
|
|
10
10
|
const { command, flag, arg, rest, description } = require('paparam')
|
|
11
11
|
const z32 = require('z32')
|
|
12
12
|
|
|
13
|
-
const DEFAULT_CONFIG_PATH = './
|
|
13
|
+
const DEFAULT_CONFIG_PATH = './multisig.json'
|
|
14
14
|
const DEFAULT_STORAGE_PATH = './storage'
|
|
15
15
|
|
|
16
16
|
const cmdRequestCore = command(
|
|
@@ -25,6 +25,10 @@ const cmdRequestCore = command(
|
|
|
25
25
|
const cmdVerifyCore = command(
|
|
26
26
|
'verify-core',
|
|
27
27
|
description('Verify multisig'),
|
|
28
|
+
flag(
|
|
29
|
+
'--first-commit',
|
|
30
|
+
'Set when this is the first commit to the multisig target, so it skips those checks'
|
|
31
|
+
),
|
|
28
32
|
flag('--peer-update-timeout <ms>', 'Peer update timeout in ms'),
|
|
29
33
|
arg('request', 'Signing request'),
|
|
30
34
|
rest('[...responses]', 'Signing responses'),
|
|
@@ -34,7 +38,10 @@ const cmdVerifyCore = command(
|
|
|
34
38
|
const cmdCommitCore = command(
|
|
35
39
|
'commit-core',
|
|
36
40
|
description('Commit multisig'),
|
|
37
|
-
flag(
|
|
41
|
+
flag(
|
|
42
|
+
'--first-commit',
|
|
43
|
+
'Set when this is the first commit to the multisig target, so it skips those checks'
|
|
44
|
+
),
|
|
38
45
|
flag('--force-dangerous', 'Advanced option, it might break the core on misuse'),
|
|
39
46
|
flag('--peer-update-timeout <ms>', 'Peer update timeout in ms'),
|
|
40
47
|
arg('request', 'Signing request'),
|
|
@@ -54,6 +61,10 @@ const cmdRequestDrive = command(
|
|
|
54
61
|
const cmdVerifyDrive = command(
|
|
55
62
|
'verify-drive',
|
|
56
63
|
description('Verify multisig'),
|
|
64
|
+
flag(
|
|
65
|
+
'--first-commit',
|
|
66
|
+
'Set when this is the first commit to the multisig target, so it skips those checks'
|
|
67
|
+
),
|
|
57
68
|
flag('--peer-update-timeout <ms>', 'Peer update timeout in ms'),
|
|
58
69
|
arg('request', 'Signing request'),
|
|
59
70
|
rest('[...responses]', 'Signing responses'),
|
|
@@ -63,7 +74,10 @@ const cmdVerifyDrive = command(
|
|
|
63
74
|
const cmdCommitDrive = command(
|
|
64
75
|
'commit-drive',
|
|
65
76
|
description('Commit multisig'),
|
|
66
|
-
flag(
|
|
77
|
+
flag(
|
|
78
|
+
'--first-commit',
|
|
79
|
+
'Set when this is the first commit to the multisig target, so it skips those checks'
|
|
80
|
+
),
|
|
67
81
|
flag('--force-dangerous', 'Advanced option, it might break the drive on misuse'),
|
|
68
82
|
flag('--peer-update-timeout <ms>', 'Peer update timeout in ms'),
|
|
69
83
|
arg('request', 'Signing request'),
|
|
@@ -92,19 +106,24 @@ async function requestCore() {
|
|
|
92
106
|
|
|
93
107
|
const { publicKeys, namespace, srcKey, quorum, store, swarm } = await setup()
|
|
94
108
|
const srcCore = store.get({ key: idEnc.decode(srcKey) })
|
|
109
|
+
|
|
110
|
+
console.info(`Creating a signing request for hypercore ${srcCore.id} at length ${length}...`)
|
|
111
|
+
console.info('Please ensure this hypercore is seeded') // TODO: reactively based on error instead of always logging
|
|
95
112
|
const multisig = new Multisig(store, swarm)
|
|
96
|
-
const res = await multisig
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
113
|
+
const res = await multisig
|
|
114
|
+
.requestCore(publicKeys, namespace, srcCore, length, {
|
|
115
|
+
force,
|
|
116
|
+
peerUpdateTimeout: peerUpdateTimeout,
|
|
117
|
+
quorum
|
|
118
|
+
})
|
|
119
|
+
.done()
|
|
101
120
|
|
|
102
121
|
printRequest(res.request)
|
|
103
122
|
goodbye.exit()
|
|
104
123
|
}
|
|
105
124
|
|
|
106
125
|
async function verifyCore() {
|
|
107
|
-
const { peerUpdateTimeout } = cmdVerifyCore.flags
|
|
126
|
+
const { firstCommit, peerUpdateTimeout } = cmdVerifyCore.flags
|
|
108
127
|
const request = cmdVerifyCore.args.request
|
|
109
128
|
const responses = cmdVerifyCore.rest || []
|
|
110
129
|
if (!request) throw new Error('Invalid command')
|
|
@@ -115,14 +134,18 @@ async function verifyCore() {
|
|
|
115
134
|
const { publicKeys, namespace, srcKey, quorum, store, swarm } = await setup()
|
|
116
135
|
const srcCore = store.get({ key: idEnc.decode(srcKey) })
|
|
117
136
|
const multisig = new Multisig(store, swarm)
|
|
118
|
-
const
|
|
137
|
+
const runner = multisig.commitCore(publicKeys, namespace, srcCore, request, responses, {
|
|
119
138
|
dryRun: true,
|
|
139
|
+
skipTargetChecks: firstCommit,
|
|
120
140
|
peerUpdateTimeout: peerUpdateTimeout,
|
|
121
141
|
quorum
|
|
122
142
|
})
|
|
143
|
+
setupProgressLogs(runner, 'core', firstCommit)
|
|
144
|
+
|
|
145
|
+
const res = await runner.done()
|
|
123
146
|
|
|
124
147
|
printCommit(res.manifest, res.quorum, res.result, true)
|
|
125
|
-
console.info(`Core key: ${res.result.destCore.key}`)
|
|
148
|
+
console.info(`Core key: ${res.result.destCore.key} is safe to commit`)
|
|
126
149
|
goodbye.exit()
|
|
127
150
|
}
|
|
128
151
|
|
|
@@ -138,13 +161,16 @@ async function commitCore() {
|
|
|
138
161
|
const { publicKeys, namespace, srcKey, quorum, store, swarm } = await setup()
|
|
139
162
|
const srcCore = store.get({ key: idEnc.decode(srcKey) })
|
|
140
163
|
const multisig = new Multisig(store, swarm)
|
|
141
|
-
const
|
|
164
|
+
const runner = multisig.commitCore(publicKeys, namespace, srcCore, request, responses, {
|
|
142
165
|
skipTargetChecks: firstCommit,
|
|
143
166
|
force: forceDangerous,
|
|
144
167
|
peerUpdateTimeout: peerUpdateTimeout,
|
|
145
168
|
quorum
|
|
146
169
|
})
|
|
147
170
|
|
|
171
|
+
setupProgressLogs(runner, 'core', firstCommit)
|
|
172
|
+
const res = await runner.done()
|
|
173
|
+
|
|
148
174
|
printCommit(res.manifest, res.quorum, res.result)
|
|
149
175
|
console.info(`Core key: ${res.result.destCore.key}`)
|
|
150
176
|
}
|
|
@@ -157,18 +183,20 @@ async function requestDrive() {
|
|
|
157
183
|
const { publicKeys, namespace, srcKey, quorum, store, swarm } = await setup()
|
|
158
184
|
const srcDrive = new Hyperdrive(store, idEnc.decode(srcKey))
|
|
159
185
|
const multisig = new Multisig(store, swarm)
|
|
160
|
-
const res = await multisig
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
186
|
+
const res = await multisig
|
|
187
|
+
.requestDrive(publicKeys, namespace, srcDrive, length, {
|
|
188
|
+
force,
|
|
189
|
+
peerUpdateTimeout: peerUpdateTimeout,
|
|
190
|
+
quorum
|
|
191
|
+
})
|
|
192
|
+
.done()
|
|
165
193
|
|
|
166
194
|
printRequest(res.request)
|
|
167
195
|
goodbye.exit()
|
|
168
196
|
}
|
|
169
197
|
|
|
170
198
|
async function verifyDrive() {
|
|
171
|
-
const { peerUpdateTimeout } =
|
|
199
|
+
const { firstCommit, peerUpdateTimeout } = cmdVerifyDrive.flags
|
|
172
200
|
const request = cmdVerifyDrive.args.request
|
|
173
201
|
const responses = cmdVerifyDrive.rest || []
|
|
174
202
|
if (!request) throw new Error('Invalid command')
|
|
@@ -178,14 +206,19 @@ async function verifyDrive() {
|
|
|
178
206
|
const { publicKeys, namespace, srcKey, quorum, store, swarm } = await setup()
|
|
179
207
|
const srcDrive = new Hyperdrive(store, idEnc.decode(srcKey))
|
|
180
208
|
const multisig = new Multisig(store, swarm)
|
|
181
|
-
const
|
|
209
|
+
const runner = multisig.commitDrive(publicKeys, namespace, srcDrive, request, responses, {
|
|
182
210
|
dryRun: true,
|
|
211
|
+
skipTargetChecks: firstCommit,
|
|
183
212
|
peerUpdateTimeout: peerUpdateTimeout,
|
|
184
213
|
quorum
|
|
185
214
|
})
|
|
186
215
|
|
|
216
|
+
setupProgressLogs(runner, 'drive', firstCommit)
|
|
217
|
+
|
|
218
|
+
const res = await runner.done()
|
|
219
|
+
|
|
187
220
|
printCommit(res.manifest, res.quorum, res.result, true)
|
|
188
|
-
console.info(`Drive key: ${res.result.db.destCore.key}`)
|
|
221
|
+
console.info(`Drive key: ${res.result.db.destCore.key} is safe to commit`)
|
|
189
222
|
goodbye.exit()
|
|
190
223
|
}
|
|
191
224
|
|
|
@@ -201,28 +234,55 @@ async function commitDrive() {
|
|
|
201
234
|
const { publicKeys, namespace, srcKey, quorum, store, swarm } = await setup()
|
|
202
235
|
const srcDrive = new Hyperdrive(store, idEnc.decode(srcKey))
|
|
203
236
|
const multisig = new Multisig(store, swarm)
|
|
204
|
-
const
|
|
237
|
+
const runner = multisig.commitDrive(publicKeys, namespace, srcDrive, request, responses, {
|
|
205
238
|
skipTargetChecks: firstCommit,
|
|
206
239
|
force: forceDangerous,
|
|
207
240
|
peerUpdateTimeout: peerUpdateTimeout,
|
|
208
241
|
quorum
|
|
209
242
|
})
|
|
243
|
+
setupProgressLogs(runner, 'drive', firstCommit)
|
|
244
|
+
|
|
245
|
+
const res = await runner.done()
|
|
210
246
|
|
|
211
247
|
printCommit(res.manifest, res.quorum, res.result)
|
|
212
248
|
console.info(`Drive key: ${res.result.db.destCore.key}`)
|
|
213
249
|
}
|
|
214
250
|
|
|
251
|
+
function setupProgressLogs(req, name, firstCommit) {
|
|
252
|
+
req.on('verify-committable-start', (srcKey, tgtKey) => {
|
|
253
|
+
console.log(
|
|
254
|
+
`Verifying the ${name} is safe to commit (source ${idEnc.normalize(srcKey)} to multisig target ${idEnc.normalize(tgtKey)})`
|
|
255
|
+
)
|
|
256
|
+
})
|
|
257
|
+
req.on('commit-start', () => {
|
|
258
|
+
console.log(`Committing the ${name}...`)
|
|
259
|
+
})
|
|
260
|
+
req.on('verify-committed-start', (key) => {
|
|
261
|
+
console.log(`Committed the ${name} (key ${idEnc.normalize(key)})`)
|
|
262
|
+
console.log('Waiting for remote seeders to pick up the changes...')
|
|
263
|
+
if (firstCommit) {
|
|
264
|
+
console.log(
|
|
265
|
+
'Please add this key to the seeders now. The logs here will notify you when it is picked up by them. Do not shut down until that happens.'
|
|
266
|
+
)
|
|
267
|
+
}
|
|
268
|
+
})
|
|
269
|
+
}
|
|
270
|
+
|
|
215
271
|
function printRequest(request) {
|
|
216
|
-
const
|
|
272
|
+
const runner = SignRequest.decode(request)
|
|
217
273
|
const reqStr = z32.encode(request)
|
|
218
|
-
const reqMsg = {
|
|
274
|
+
const reqMsg = {
|
|
275
|
+
key: runner.id,
|
|
276
|
+
length: runner.length,
|
|
277
|
+
treeHash: idEnc.normalize(runner.treeHash)
|
|
278
|
+
}
|
|
219
279
|
console.log('Request:', JSON.stringify(reqMsg, null, 2))
|
|
220
280
|
console.log('To sign, run:', `\nhypercore-sign ${reqStr}`)
|
|
221
281
|
}
|
|
222
282
|
|
|
223
283
|
function printCommit(manifest, quorum, result, dryRun) {
|
|
224
284
|
if (dryRun) {
|
|
225
|
-
console.log(`\nQuorum ${quorum} / ${manifest.quorum}`)
|
|
285
|
+
console.log(`\nQuorum: ${quorum} / ${manifest.quorum}`)
|
|
226
286
|
console.log('\nReview batch to commit:', JSON.stringify(result, null, 2))
|
|
227
287
|
} else {
|
|
228
288
|
console.log('\nCommitted:', JSON.stringify(result, null, 2))
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hyper-multisig-cli",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "CLI of hyper-multisig",
|
|
5
5
|
"main": "bin.js",
|
|
6
6
|
"bin": {
|
|
7
|
-
"hyper-multisig": "
|
|
8
|
-
"hyper-multisig-bare": "
|
|
7
|
+
"hyper-multisig": "bin.js",
|
|
8
|
+
"hyper-multisig-bare": "bin-bare.js"
|
|
9
9
|
},
|
|
10
10
|
"files": [
|
|
11
11
|
"bin-bare.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"bare-fs": "^4.5.4",
|
|
22
22
|
"corestore": "^7.8.0",
|
|
23
23
|
"graceful-goodbye": "^1.3.3",
|
|
24
|
-
"hyper-multisig": "^0.
|
|
24
|
+
"hyper-multisig": "^0.1.2",
|
|
25
25
|
"hypercore-id-encoding": "^1.3.0",
|
|
26
26
|
"hypercore-signing-request": "^4.0.2",
|
|
27
27
|
"hyperdrive": "^13.2.1",
|