hyper-multisig-cli 0.0.1 → 0.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 +80 -23
- package/package.json +2 -2
package/bin.js
CHANGED
|
@@ -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'),
|
|
@@ -93,18 +107,20 @@ async function requestCore() {
|
|
|
93
107
|
const { publicKeys, namespace, srcKey, quorum, store, swarm } = await setup()
|
|
94
108
|
const srcCore = store.get({ key: idEnc.decode(srcKey) })
|
|
95
109
|
const multisig = new Multisig(store, swarm)
|
|
96
|
-
const res = await multisig
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
110
|
+
const res = await multisig
|
|
111
|
+
.requestCore(publicKeys, namespace, srcCore, length, {
|
|
112
|
+
force,
|
|
113
|
+
peerUpdateTimeout: peerUpdateTimeout,
|
|
114
|
+
quorum
|
|
115
|
+
})
|
|
116
|
+
.done()
|
|
101
117
|
|
|
102
118
|
printRequest(res.request)
|
|
103
119
|
goodbye.exit()
|
|
104
120
|
}
|
|
105
121
|
|
|
106
122
|
async function verifyCore() {
|
|
107
|
-
const { peerUpdateTimeout } = cmdVerifyCore.flags
|
|
123
|
+
const { firstCommit, peerUpdateTimeout } = cmdVerifyCore.flags
|
|
108
124
|
const request = cmdVerifyCore.args.request
|
|
109
125
|
const responses = cmdVerifyCore.rest || []
|
|
110
126
|
if (!request) throw new Error('Invalid command')
|
|
@@ -115,14 +131,18 @@ async function verifyCore() {
|
|
|
115
131
|
const { publicKeys, namespace, srcKey, quorum, store, swarm } = await setup()
|
|
116
132
|
const srcCore = store.get({ key: idEnc.decode(srcKey) })
|
|
117
133
|
const multisig = new Multisig(store, swarm)
|
|
118
|
-
const
|
|
134
|
+
const runner = multisig.commitCore(publicKeys, namespace, srcCore, request, responses, {
|
|
119
135
|
dryRun: true,
|
|
136
|
+
skipTargetChecks: firstCommit,
|
|
120
137
|
peerUpdateTimeout: peerUpdateTimeout,
|
|
121
138
|
quorum
|
|
122
139
|
})
|
|
140
|
+
setupProgressLogs(runner, 'core', firstCommit)
|
|
141
|
+
|
|
142
|
+
const res = await runner.done()
|
|
123
143
|
|
|
124
144
|
printCommit(res.manifest, res.quorum, res.result, true)
|
|
125
|
-
console.info(`Core key: ${res.result.destCore.key}`)
|
|
145
|
+
console.info(`Core key: ${res.result.destCore.key} is safe to commit`)
|
|
126
146
|
goodbye.exit()
|
|
127
147
|
}
|
|
128
148
|
|
|
@@ -138,13 +158,16 @@ async function commitCore() {
|
|
|
138
158
|
const { publicKeys, namespace, srcKey, quorum, store, swarm } = await setup()
|
|
139
159
|
const srcCore = store.get({ key: idEnc.decode(srcKey) })
|
|
140
160
|
const multisig = new Multisig(store, swarm)
|
|
141
|
-
const
|
|
161
|
+
const runner = multisig.commitCore(publicKeys, namespace, srcCore, request, responses, {
|
|
142
162
|
skipTargetChecks: firstCommit,
|
|
143
163
|
force: forceDangerous,
|
|
144
164
|
peerUpdateTimeout: peerUpdateTimeout,
|
|
145
165
|
quorum
|
|
146
166
|
})
|
|
147
167
|
|
|
168
|
+
setupProgressLogs(runner, 'core', firstCommit)
|
|
169
|
+
const res = await runner.done()
|
|
170
|
+
|
|
148
171
|
printCommit(res.manifest, res.quorum, res.result)
|
|
149
172
|
console.info(`Core key: ${res.result.destCore.key}`)
|
|
150
173
|
}
|
|
@@ -157,18 +180,20 @@ async function requestDrive() {
|
|
|
157
180
|
const { publicKeys, namespace, srcKey, quorum, store, swarm } = await setup()
|
|
158
181
|
const srcDrive = new Hyperdrive(store, idEnc.decode(srcKey))
|
|
159
182
|
const multisig = new Multisig(store, swarm)
|
|
160
|
-
const res = await multisig
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
183
|
+
const res = await multisig
|
|
184
|
+
.requestDrive(publicKeys, namespace, srcDrive, length, {
|
|
185
|
+
force,
|
|
186
|
+
peerUpdateTimeout: peerUpdateTimeout,
|
|
187
|
+
quorum
|
|
188
|
+
})
|
|
189
|
+
.done()
|
|
165
190
|
|
|
166
191
|
printRequest(res.request)
|
|
167
192
|
goodbye.exit()
|
|
168
193
|
}
|
|
169
194
|
|
|
170
195
|
async function verifyDrive() {
|
|
171
|
-
const { peerUpdateTimeout } =
|
|
196
|
+
const { firstCommit, peerUpdateTimeout } = cmdVerifyDrive.flags
|
|
172
197
|
const request = cmdVerifyDrive.args.request
|
|
173
198
|
const responses = cmdVerifyDrive.rest || []
|
|
174
199
|
if (!request) throw new Error('Invalid command')
|
|
@@ -178,14 +203,19 @@ async function verifyDrive() {
|
|
|
178
203
|
const { publicKeys, namespace, srcKey, quorum, store, swarm } = await setup()
|
|
179
204
|
const srcDrive = new Hyperdrive(store, idEnc.decode(srcKey))
|
|
180
205
|
const multisig = new Multisig(store, swarm)
|
|
181
|
-
const
|
|
206
|
+
const runner = multisig.commitDrive(publicKeys, namespace, srcDrive, request, responses, {
|
|
182
207
|
dryRun: true,
|
|
208
|
+
skipTargetChecks: firstCommit,
|
|
183
209
|
peerUpdateTimeout: peerUpdateTimeout,
|
|
184
210
|
quorum
|
|
185
211
|
})
|
|
186
212
|
|
|
213
|
+
setupProgressLogs(runner, 'drive', firstCommit)
|
|
214
|
+
|
|
215
|
+
const res = await runner.done()
|
|
216
|
+
|
|
187
217
|
printCommit(res.manifest, res.quorum, res.result, true)
|
|
188
|
-
console.info(`Drive key: ${res.result.db.destCore.key}`)
|
|
218
|
+
console.info(`Drive key: ${res.result.db.destCore.key} is safe to commit`)
|
|
189
219
|
goodbye.exit()
|
|
190
220
|
}
|
|
191
221
|
|
|
@@ -201,28 +231,55 @@ async function commitDrive() {
|
|
|
201
231
|
const { publicKeys, namespace, srcKey, quorum, store, swarm } = await setup()
|
|
202
232
|
const srcDrive = new Hyperdrive(store, idEnc.decode(srcKey))
|
|
203
233
|
const multisig = new Multisig(store, swarm)
|
|
204
|
-
const
|
|
234
|
+
const runner = multisig.commitDrive(publicKeys, namespace, srcDrive, request, responses, {
|
|
205
235
|
skipTargetChecks: firstCommit,
|
|
206
236
|
force: forceDangerous,
|
|
207
237
|
peerUpdateTimeout: peerUpdateTimeout,
|
|
208
238
|
quorum
|
|
209
239
|
})
|
|
240
|
+
setupProgressLogs(runner, 'drive', firstCommit)
|
|
241
|
+
|
|
242
|
+
const res = await runner.done()
|
|
210
243
|
|
|
211
244
|
printCommit(res.manifest, res.quorum, res.result)
|
|
212
245
|
console.info(`Drive key: ${res.result.db.destCore.key}`)
|
|
213
246
|
}
|
|
214
247
|
|
|
248
|
+
function setupProgressLogs(req, name, firstCommit) {
|
|
249
|
+
req.on('verify-committable-start', (srcKey, tgtKey) => {
|
|
250
|
+
console.log(
|
|
251
|
+
`Verifying the ${name} is safe to commit (source ${idEnc.normalize(srcKey)} to multisig target ${idEnc.normalize(tgtKey)})`
|
|
252
|
+
)
|
|
253
|
+
})
|
|
254
|
+
req.on('commit-start', () => {
|
|
255
|
+
console.log(`Committing the ${name}...`)
|
|
256
|
+
})
|
|
257
|
+
req.on('verify-committed-start', (key) => {
|
|
258
|
+
console.log(`Committed the ${name} (key ${idEnc.normalize(key)})`)
|
|
259
|
+
console.log('Waiting for remote seeders to pick up the changes...')
|
|
260
|
+
if (firstCommit) {
|
|
261
|
+
console.log(
|
|
262
|
+
'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.'
|
|
263
|
+
)
|
|
264
|
+
}
|
|
265
|
+
})
|
|
266
|
+
}
|
|
267
|
+
|
|
215
268
|
function printRequest(request) {
|
|
216
|
-
const
|
|
269
|
+
const runner = SignRequest.decode(request)
|
|
217
270
|
const reqStr = z32.encode(request)
|
|
218
|
-
const reqMsg = {
|
|
271
|
+
const reqMsg = {
|
|
272
|
+
key: runner.id,
|
|
273
|
+
length: runner.length,
|
|
274
|
+
treeHash: idEnc.normalize(runner.treeHash)
|
|
275
|
+
}
|
|
219
276
|
console.log('Request:', JSON.stringify(reqMsg, null, 2))
|
|
220
277
|
console.log('To sign, run:', `\nhypercore-sign ${reqStr}`)
|
|
221
278
|
}
|
|
222
279
|
|
|
223
280
|
function printCommit(manifest, quorum, result, dryRun) {
|
|
224
281
|
if (dryRun) {
|
|
225
|
-
console.log(`\nQuorum ${quorum} / ${manifest.quorum}`)
|
|
282
|
+
console.log(`\nQuorum: ${quorum} / ${manifest.quorum}`)
|
|
226
283
|
console.log('\nReview batch to commit:', JSON.stringify(result, null, 2))
|
|
227
284
|
} else {
|
|
228
285
|
console.log('\nCommitted:', JSON.stringify(result, null, 2))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hyper-multisig-cli",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
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": "^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",
|