hyper-multisig-cli 1.0.1 → 1.1.1
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 +57 -13
- package/package.json +2 -2
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,19 +56,25 @@ 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
|
|
65
75
|
if (!length) throw new Error('Invalid command')
|
|
66
76
|
|
|
67
77
|
const { type, publicKeys, namespace, srcKey, quorum, store, swarm } = await setup()
|
|
68
|
-
|
|
69
78
|
const multisig = new Multisig(store, swarm)
|
|
70
79
|
|
|
71
80
|
let request
|
|
@@ -81,13 +90,29 @@ async function request() {
|
|
|
81
90
|
request = res.request
|
|
82
91
|
} else {
|
|
83
92
|
const srcDrive = new Hyperdrive(store, idEnc.decode(srcKey))
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
93
|
+
const req = await multisig.requestDrive(publicKeys, namespace, srcDrive, length, {
|
|
94
|
+
force,
|
|
95
|
+
peerUpdateTimeout: peerUpdateTimeout,
|
|
96
|
+
quorum
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
req.on('getting-src-blobs', () => {
|
|
100
|
+
console.log('Getting the source blobs...')
|
|
101
|
+
})
|
|
102
|
+
req.on('verify-db-requestable-start', () => {
|
|
103
|
+
console.log('Verifying the db core is requestable....')
|
|
104
|
+
})
|
|
105
|
+
req.on('getting-blobs-length', () => {
|
|
106
|
+
console.log('Getting the blobs length (this can take a while)...')
|
|
107
|
+
})
|
|
108
|
+
req.on('verify-blobs-requestable-start', () => {
|
|
109
|
+
console.log('Verifying the blobs core is requestable...')
|
|
110
|
+
})
|
|
111
|
+
req.on('creating-drive', () => {
|
|
112
|
+
console.log('Creating the drive...')
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
const res = await req.done()
|
|
91
116
|
request = res.request
|
|
92
117
|
}
|
|
93
118
|
printRequest(request)
|
|
@@ -215,19 +240,31 @@ function printCommit(manifest, quorum, result, dryRun) {
|
|
|
215
240
|
}
|
|
216
241
|
}
|
|
217
242
|
|
|
218
|
-
async function setup() {
|
|
243
|
+
async function setup(opts = {}) {
|
|
219
244
|
const configPath = cmd.flags.config || DEFAULT_CONFIG_PATH
|
|
220
245
|
const storage = cmd.flags.storage || DEFAULT_STORAGE_PATH
|
|
221
246
|
|
|
222
|
-
const {
|
|
223
|
-
|
|
247
|
+
const { withReplication = true } = opts
|
|
248
|
+
|
|
249
|
+
const { type, publicKeys, namespace, srcKey, bootstrap, quorum } = await loadConfig(
|
|
250
|
+
configPath,
|
|
251
|
+
opts
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
let store, swarm
|
|
255
|
+
if (withReplication) {
|
|
256
|
+
const res = await replication(storage, bootstrap)
|
|
257
|
+
store = res.store
|
|
258
|
+
swarm = res.swarm
|
|
259
|
+
}
|
|
260
|
+
|
|
224
261
|
return { type, publicKeys, namespace, srcKey, quorum, store, swarm }
|
|
225
262
|
}
|
|
226
263
|
|
|
227
264
|
/**
|
|
228
265
|
* @type {function(): Promise<{ publicKeys: string[], namespace: string, srcKey: string }>}
|
|
229
266
|
*/
|
|
230
|
-
async function loadConfig(configPath) {
|
|
267
|
+
async function loadConfig(configPath, opts = {}) {
|
|
231
268
|
const {
|
|
232
269
|
type,
|
|
233
270
|
publicKeys,
|
|
@@ -237,7 +274,14 @@ async function loadConfig(configPath) {
|
|
|
237
274
|
quorum = null
|
|
238
275
|
} = JSON.parse(await fs.readFile(configPath, 'utf-8'))
|
|
239
276
|
|
|
240
|
-
|
|
277
|
+
const { srcKeyRequired = true } = opts
|
|
278
|
+
|
|
279
|
+
if (
|
|
280
|
+
!(type === 'core' || type === 'drive') ||
|
|
281
|
+
!publicKeys?.length ||
|
|
282
|
+
!namespace ||
|
|
283
|
+
(srcKeyRequired && !srcKey)
|
|
284
|
+
) {
|
|
241
285
|
throw new Error('Invalid config file')
|
|
242
286
|
}
|
|
243
287
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hyper-multisig-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "CLI of hyper-multisig",
|
|
5
5
|
"main": "bin.js",
|
|
6
6
|
"bin": {
|
|
@@ -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": "^1.0.
|
|
24
|
+
"hyper-multisig": "^1.0.1",
|
|
25
25
|
"hypercore-id-encoding": "^1.3.0",
|
|
26
26
|
"hypercore-signing-request": "^4.0.2",
|
|
27
27
|
"hyperdrive": "^13.2.1",
|