hyper-multisig-cli 1.0.1 → 1.1.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/bin.js +34 -5
- package/package.json +1 -1
package/bin.js
CHANGED
|
@@ -3,6 +3,7 @@ const Corestore = require('corestore')
|
|
|
3
3
|
const fs = require('fs').promises
|
|
4
4
|
const goodbye = require('graceful-goodbye')
|
|
5
5
|
const Multisig = require('hyper-multisig')
|
|
6
|
+
const MultisigUtil = require('hyper-multisig/lib/util')
|
|
6
7
|
const idEnc = require('hypercore-id-encoding')
|
|
7
8
|
const SignRequest = require('hypercore-signing-request')
|
|
8
9
|
const Hyperdrive = require('hyperdrive')
|
|
@@ -13,6 +14,8 @@ const z32 = require('z32')
|
|
|
13
14
|
const DEFAULT_CONFIG_PATH = './multisig.json'
|
|
14
15
|
const DEFAULT_STORAGE_PATH = './storage'
|
|
15
16
|
|
|
17
|
+
const cmdLink = command('link', description('Create multisig key'), link)
|
|
18
|
+
|
|
16
19
|
const cmdRequest = command(
|
|
17
20
|
'request',
|
|
18
21
|
description('Create signing request'),
|
|
@@ -53,12 +56,19 @@ const cmd = command(
|
|
|
53
56
|
'multisig',
|
|
54
57
|
flag('--config|-c <config>', `Config file path (default to ${DEFAULT_CONFIG_PATH})`),
|
|
55
58
|
flag('--storage|-s <storage>', `Storage path (default to ${DEFAULT_STORAGE_PATH})`),
|
|
59
|
+
cmdLink,
|
|
56
60
|
cmdRequest,
|
|
57
61
|
cmdVerify,
|
|
58
62
|
cmdCommit,
|
|
59
63
|
() => console.log(cmd.help())
|
|
60
64
|
)
|
|
61
65
|
|
|
66
|
+
async function link() {
|
|
67
|
+
const { publicKeys, namespace } = await setup({ withReplication: false, srcKeyRequired: false })
|
|
68
|
+
const key = MultisigUtil.getCoreKey(publicKeys, namespace)
|
|
69
|
+
console.info(`pear://${idEnc.normalize(key)}`)
|
|
70
|
+
}
|
|
71
|
+
|
|
62
72
|
async function request() {
|
|
63
73
|
const length = +cmdRequest.args.length
|
|
64
74
|
const { force, peerUpdateTimeout } = cmdRequest.flags
|
|
@@ -215,19 +225,31 @@ function printCommit(manifest, quorum, result, dryRun) {
|
|
|
215
225
|
}
|
|
216
226
|
}
|
|
217
227
|
|
|
218
|
-
async function setup() {
|
|
228
|
+
async function setup(opts = {}) {
|
|
219
229
|
const configPath = cmd.flags.config || DEFAULT_CONFIG_PATH
|
|
220
230
|
const storage = cmd.flags.storage || DEFAULT_STORAGE_PATH
|
|
221
231
|
|
|
222
|
-
const {
|
|
223
|
-
|
|
232
|
+
const { withReplication = true } = opts
|
|
233
|
+
|
|
234
|
+
const { type, publicKeys, namespace, srcKey, bootstrap, quorum } = await loadConfig(
|
|
235
|
+
configPath,
|
|
236
|
+
opts
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
let store, swarm
|
|
240
|
+
if (withReplication) {
|
|
241
|
+
const res = await replication(storage, bootstrap)
|
|
242
|
+
store = res.store
|
|
243
|
+
swarm = res.swarm
|
|
244
|
+
}
|
|
245
|
+
|
|
224
246
|
return { type, publicKeys, namespace, srcKey, quorum, store, swarm }
|
|
225
247
|
}
|
|
226
248
|
|
|
227
249
|
/**
|
|
228
250
|
* @type {function(): Promise<{ publicKeys: string[], namespace: string, srcKey: string }>}
|
|
229
251
|
*/
|
|
230
|
-
async function loadConfig(configPath) {
|
|
252
|
+
async function loadConfig(configPath, opts = {}) {
|
|
231
253
|
const {
|
|
232
254
|
type,
|
|
233
255
|
publicKeys,
|
|
@@ -237,7 +259,14 @@ async function loadConfig(configPath) {
|
|
|
237
259
|
quorum = null
|
|
238
260
|
} = JSON.parse(await fs.readFile(configPath, 'utf-8'))
|
|
239
261
|
|
|
240
|
-
|
|
262
|
+
const { srcKeyRequired = true } = opts
|
|
263
|
+
|
|
264
|
+
if (
|
|
265
|
+
!(type === 'core' || type === 'drive') ||
|
|
266
|
+
!publicKeys?.length ||
|
|
267
|
+
!namespace ||
|
|
268
|
+
(srcKeyRequired && !srcKey)
|
|
269
|
+
) {
|
|
241
270
|
throw new Error('Invalid config file')
|
|
242
271
|
}
|
|
243
272
|
|