hyper-multisig-cli 1.2.0 → 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 +2 -0
- package/bin.js +40 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -82,6 +82,8 @@ Note that the key of the multisig hypercore is fully determined by the public ke
|
|
|
82
82
|
|
|
83
83
|
It is possible to switch to a different `srcKey`.
|
|
84
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
|
+
|
|
85
87
|
### Create Signing Request
|
|
86
88
|
|
|
87
89
|
```shell
|
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(
|
|
@@ -275,21 +276,36 @@ async function loadConfig(configPath, opts = {}) {
|
|
|
275
276
|
namespace,
|
|
276
277
|
srcKey,
|
|
277
278
|
bootstrap,
|
|
278
|
-
quorum = null
|
|
279
|
+
quorum = null,
|
|
280
|
+
multisigKey = null
|
|
279
281
|
} = JSON.parse(await fs.readFile(configPath, 'utf-8'))
|
|
280
282
|
|
|
281
283
|
const { srcKeyRequired = true } = opts
|
|
282
284
|
|
|
283
|
-
if (
|
|
284
|
-
|
|
285
|
-
!publicKeys?.length ||
|
|
286
|
-
!namespace ||
|
|
287
|
-
(srcKeyRequired && !srcKey)
|
|
288
|
-
) {
|
|
289
|
-
throw new Error('Invalid config file')
|
|
285
|
+
if (!(type === 'core' || type === 'drive')) {
|
|
286
|
+
throw new Error(`type must be either core or drive. Saw '${type}'`)
|
|
290
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]}'`)
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (srcKeyRequired && !srcKey) throw new Error('srcKey must be set')
|
|
295
|
+
if (srcKey && !idEnc.isValid(srcKey)) throw new Error(`invalid srcKey: '${srcKey}'`)
|
|
291
296
|
|
|
292
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
|
+
|
|
293
309
|
return { type, publicKeys, namespace, srcKey, bootstrap, quorum }
|
|
294
310
|
}
|
|
295
311
|
|
|
@@ -312,4 +328,16 @@ async function replication(storage, bootstrap) {
|
|
|
312
328
|
return { store, swarm }
|
|
313
329
|
}
|
|
314
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
|
+
|
|
315
343
|
cmd.parse()
|