hyper-multisig-cli 1.1.3 → 1.3.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 +7 -3
- package/bin.js +44 -14
- package/package.json +3 -4
package/README.md
CHANGED
|
@@ -42,7 +42,7 @@ Take note of your public key.
|
|
|
42
42
|
|
|
43
43
|
We just create a dummy source core for this example:
|
|
44
44
|
|
|
45
|
-
```
|
|
45
|
+
```js
|
|
46
46
|
import Corestore from 'corestore'
|
|
47
47
|
import Hyperswarm from 'hyperswarm'
|
|
48
48
|
|
|
@@ -55,7 +55,9 @@ await core.ready()
|
|
|
55
55
|
for (let i = core.length; i < desiredLength; i++) await core.append(`Block-${i}`)
|
|
56
56
|
|
|
57
57
|
const swarm = new Hyperswarm()
|
|
58
|
-
swarm.on('connection', (conn) => {
|
|
58
|
+
swarm.on('connection', (conn) => {
|
|
59
|
+
store.replicate(conn)
|
|
60
|
+
})
|
|
59
61
|
swarm.join(core.discoveryKey)
|
|
60
62
|
console.log(`Swarming key ${core.id} (length ${core.length})`)
|
|
61
63
|
```
|
|
@@ -80,6 +82,8 @@ Note that the key of the multisig hypercore is fully determined by the public ke
|
|
|
80
82
|
|
|
81
83
|
It is possible to switch to a different `srcKey`.
|
|
82
84
|
|
|
85
|
+
The config supports an optional `multisigKey` field. Set this to the multisig key corresponding to your config (the key returned by the `link`command). This can be useful for searching configs based on their multisigKey.
|
|
86
|
+
|
|
83
87
|
### Create Signing Request
|
|
84
88
|
|
|
85
89
|
```shell
|
|
@@ -164,7 +168,7 @@ Waiting for remote seeders to pick up the changes...
|
|
|
164
168
|
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.
|
|
165
169
|
```
|
|
166
170
|
|
|
167
|
-
Do as the logs instruct, and add your target key to 2 or more seeders. For this example,
|
|
171
|
+
Do as the logs instruct, and add your target key to 2 or more seeders. For this example, simply run 2 more seeder scripts like above, but this time for the target key.
|
|
168
172
|
|
|
169
173
|
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.
|
|
170
174
|
|
package/bin.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
const Corestore = require('corestore')
|
|
3
|
+
const process = require('process')
|
|
3
4
|
const fs = require('fs').promises
|
|
4
5
|
const goodbye = require('graceful-goodbye')
|
|
5
6
|
const Multisig = require('hyper-multisig')
|
|
@@ -13,7 +14,7 @@ const z32 = require('z32')
|
|
|
13
14
|
const DEFAULT_CONFIG_PATH = './multisig.json'
|
|
14
15
|
const DEFAULT_STORAGE_PATH = './storage'
|
|
15
16
|
|
|
16
|
-
const cmdLink = command('link', description('Create multisig key'), link)
|
|
17
|
+
const cmdLink = command('link', description('Create multisig key'), wrapErrHandler(link))
|
|
17
18
|
|
|
18
19
|
const cmdRequest = command(
|
|
19
20
|
'request',
|
|
@@ -21,7 +22,7 @@ const cmdRequest = command(
|
|
|
21
22
|
flag('--force', 'Skip sanity checks'),
|
|
22
23
|
flag('--peer-update-timeout <ms>', 'Peer update timeout in ms'),
|
|
23
24
|
arg('<length>', 'Core length to request'),
|
|
24
|
-
request
|
|
25
|
+
wrapErrHandler(request)
|
|
25
26
|
)
|
|
26
27
|
|
|
27
28
|
const cmdVerify = command(
|
|
@@ -34,7 +35,7 @@ const cmdVerify = command(
|
|
|
34
35
|
flag('--peer-update-timeout <ms>', 'Peer update timeout in ms'),
|
|
35
36
|
arg('request', 'Signing request'),
|
|
36
37
|
rest('[...responses]', 'Signing responses'),
|
|
37
|
-
verify
|
|
38
|
+
wrapErrHandler(verify)
|
|
38
39
|
)
|
|
39
40
|
|
|
40
41
|
const cmdCommit = command(
|
|
@@ -48,7 +49,7 @@ const cmdCommit = command(
|
|
|
48
49
|
flag('--peer-update-timeout <ms>', 'Peer update timeout in ms'),
|
|
49
50
|
arg('request', 'Signing request'),
|
|
50
51
|
rest('[...responses]', 'Signing responses'),
|
|
51
|
-
commit
|
|
52
|
+
wrapErrHandler(commit)
|
|
52
53
|
)
|
|
53
54
|
|
|
54
55
|
const cmd = command(
|
|
@@ -86,7 +87,8 @@ async function request() {
|
|
|
86
87
|
.requestCore(publicKeys, namespace, srcCore, length, {
|
|
87
88
|
force,
|
|
88
89
|
peerUpdateTimeout: peerUpdateTimeout,
|
|
89
|
-
quorum
|
|
90
|
+
quorum,
|
|
91
|
+
legacy: true // legacy requests compat with hypercore-sign v3
|
|
90
92
|
})
|
|
91
93
|
.done()
|
|
92
94
|
request = res.request
|
|
@@ -95,7 +97,8 @@ async function request() {
|
|
|
95
97
|
const req = await multisig.requestDrive(publicKeys, namespace, srcDrive, length, {
|
|
96
98
|
force,
|
|
97
99
|
peerUpdateTimeout: peerUpdateTimeout,
|
|
98
|
-
quorum
|
|
100
|
+
quorum,
|
|
101
|
+
legacy: true // legacy requests compat with hypercore-sign v3
|
|
99
102
|
})
|
|
100
103
|
|
|
101
104
|
req.on('getting-src-blobs', () => {
|
|
@@ -273,21 +276,36 @@ async function loadConfig(configPath, opts = {}) {
|
|
|
273
276
|
namespace,
|
|
274
277
|
srcKey,
|
|
275
278
|
bootstrap,
|
|
276
|
-
quorum = null
|
|
279
|
+
quorum = null,
|
|
280
|
+
multisigKey = null
|
|
277
281
|
} = JSON.parse(await fs.readFile(configPath, 'utf-8'))
|
|
278
282
|
|
|
279
283
|
const { srcKeyRequired = true } = opts
|
|
280
284
|
|
|
281
|
-
if (
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
) {
|
|
287
|
-
throw new Error(
|
|
285
|
+
if (!(type === 'core' || type === 'drive')) {
|
|
286
|
+
throw new Error(`type must be either core or drive. Saw '${type}'`)
|
|
287
|
+
}
|
|
288
|
+
if (!namespace) throw new Error('namespace must be set')
|
|
289
|
+
if (!publicKeys?.length) throw new Error('publicKeys must be set and include at least 1 key')
|
|
290
|
+
for (let i = 0; i < publicKeys.length; i++) {
|
|
291
|
+
if (!idEnc.isValid(publicKeys[i])) throw new Error(`invalid publicKey ${i}: '${publicKeys[i]}'`)
|
|
288
292
|
}
|
|
289
293
|
|
|
294
|
+
if (srcKeyRequired && !srcKey) throw new Error('srcKey must be set')
|
|
295
|
+
if (srcKey && !idEnc.isValid(srcKey)) throw new Error(`invalid srcKey: '${srcKey}'`)
|
|
296
|
+
|
|
290
297
|
if (bootstrap) console.info(`Using non-default bootstrap`)
|
|
298
|
+
|
|
299
|
+
if (multisigKey) {
|
|
300
|
+
const calculatedKey = idEnc.normalize(Multisig.getCoreKey(publicKeys, namespace, { quorum }))
|
|
301
|
+
const passedInKey = idEnc.normalize(multisigKey)
|
|
302
|
+
if (passedInKey !== calculatedKey) {
|
|
303
|
+
throw new Error(
|
|
304
|
+
`multisigKey does not correspond to the key generated from the config (expected ${calculatedKey})`
|
|
305
|
+
)
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
291
309
|
return { type, publicKeys, namespace, srcKey, bootstrap, quorum }
|
|
292
310
|
}
|
|
293
311
|
|
|
@@ -310,4 +328,16 @@ async function replication(storage, bootstrap) {
|
|
|
310
328
|
return { store, swarm }
|
|
311
329
|
}
|
|
312
330
|
|
|
331
|
+
function wrapErrHandler(func) {
|
|
332
|
+
const res = async () => {
|
|
333
|
+
try {
|
|
334
|
+
await func()
|
|
335
|
+
} catch (e) {
|
|
336
|
+
console.error(e)
|
|
337
|
+
process.exit(1)
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return res
|
|
341
|
+
}
|
|
342
|
+
|
|
313
343
|
cmd.parse()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hyper-multisig-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "CLI of hyper-multisig",
|
|
5
5
|
"main": "bin.js",
|
|
6
6
|
"bin": {
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"bare-fs": "^4.5.4",
|
|
22
22
|
"corestore": "^7.8.0",
|
|
23
23
|
"graceful-goodbye": "^1.3.3",
|
|
24
|
-
"hyper-multisig": "^1.0
|
|
24
|
+
"hyper-multisig": "^2.1.0",
|
|
25
25
|
"hypercore-id-encoding": "^1.3.0",
|
|
26
|
-
"hypercore-signing-request": "^
|
|
26
|
+
"hypercore-signing-request": "^5.0.1",
|
|
27
27
|
"hyperdrive": "^13.2.1",
|
|
28
28
|
"hyperswarm": "^4.16.0",
|
|
29
29
|
"paparam": "^1.10.0",
|
|
@@ -35,7 +35,6 @@
|
|
|
35
35
|
"bare-process": "^4.2.2",
|
|
36
36
|
"bare-subprocess": "^5.2.2",
|
|
37
37
|
"brittle": "^3.19.1",
|
|
38
|
-
"compact-encoding": "^2.18.0",
|
|
39
38
|
"hypercore-crypto": "^3.6.1",
|
|
40
39
|
"hypercore-sign": "^4.0.1",
|
|
41
40
|
"hyperdht": "^6.29.0",
|