hyper-multisig-cli 1.3.0 → 1.5.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.
Files changed (3) hide show
  1. package/README.md +12 -0
  2. package/bin.js +119 -10
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -173,3 +173,15 @@ Do as the logs instruct, and add your target key to 2 or more seeders. For this
173
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.
174
174
 
175
175
  Note: for any future updates to your multisig core, remove the `first-commit` flag.
176
+
177
+ ## Recovering From Incompletely Seeded Commit (Advanced)
178
+
179
+ If the committer's process ends prematurely, after committing but before the commit got fully seeded, the multisig drive ends up in an incomplete state: the swarm knows its length has been updated, but does not have all new blocks.
180
+
181
+ Re-committing will trigger a 'TARGET_CORE_NOT_FULLY_SEEDED' error, which needs to be skipped for this recovery. But no other checks should be skipped.
182
+
183
+ Use the `--skip-target-well-seeded` flag to re-commit the drive. Note: re-committing is also possible from another machine.
184
+
185
+ ```
186
+ hyper-multisig commit --skip-target-well-seeded ...
187
+ ```
package/bin.js CHANGED
@@ -13,6 +13,7 @@ const z32 = require('z32')
13
13
 
14
14
  const DEFAULT_CONFIG_PATH = './multisig.json'
15
15
  const DEFAULT_STORAGE_PATH = './storage'
16
+ const DEFAULT_SEED_LOG_INTERVAL = 15000
16
17
 
17
18
  const cmdLink = command('link', description('Create multisig key'), wrapErrHandler(link))
18
19
 
@@ -41,10 +42,12 @@ const cmdVerify = command(
41
42
  const cmdCommit = command(
42
43
  'commit',
43
44
  description('Commit multisig'),
45
+ flag('--swarm-client-only', 'Swarm in client mode only'),
44
46
  flag(
45
47
  '--first-commit',
46
48
  'Set when this is the first commit to the multisig target, so it skips those checks'
47
49
  ),
50
+ flag('--skip-target-well-seeded', 'Skip checking multisig target is well seeded'),
48
51
  flag('--force-dangerous', 'Advanced option, it might break the core on misuse'),
49
52
  flag('--peer-update-timeout <ms>', 'Peer update timeout in ms'),
50
53
  arg('request', 'Signing request'),
@@ -52,6 +55,15 @@ const cmdCommit = command(
52
55
  wrapErrHandler(commit)
53
56
  )
54
57
 
58
+ const cmdSeed = command(
59
+ 'seed',
60
+ description('Seed both the source and multisig cores/drives'),
61
+ flag('--log-interval <logInterval>', 'Interval in ms to log replication status').default(
62
+ DEFAULT_SEED_LOG_INTERVAL
63
+ ),
64
+ wrapErrHandler(seed)
65
+ )
66
+
55
67
  const cmd = command(
56
68
  'multisig',
57
69
  flag('--config|-c <config>', `Config file path (default to ${DEFAULT_CONFIG_PATH})`),
@@ -60,6 +72,7 @@ const cmd = command(
60
72
  cmdRequest,
61
73
  cmdVerify,
62
74
  cmdCommit,
75
+ cmdSeed,
63
76
  () => console.log(cmd.help())
64
77
  )
65
78
 
@@ -154,7 +167,7 @@ async function verify() {
154
167
  quorum
155
168
  })
156
169
  }
157
- setupProgressLogs(runner, type, firstCommit)
170
+ setupProgressLogs(runner, type, firstCommit, true)
158
171
 
159
172
  const res = await runner.done()
160
173
 
@@ -167,7 +180,9 @@ async function verify() {
167
180
  async function commit() {
168
181
  const request = cmdCommit.args.request
169
182
  const responses = cmdCommit.rest || []
170
- const { firstCommit, forceDangerous, peerUpdateTimeout } = cmdCommit.flags
183
+ const { swarmClientOnly, firstCommit, skipTargetWellSeeded, forceDangerous, peerUpdateTimeout } =
184
+ cmdCommit.flags
185
+
171
186
  if (!request || !responses?.length) throw new Error('Invalid command')
172
187
 
173
188
  console.info(`Committing request ${request}`)
@@ -180,7 +195,9 @@ async function commit() {
180
195
  if (type === 'core') {
181
196
  const srcCore = store.get({ key: idEnc.decode(srcKey) })
182
197
  runner = multisig.commitCore(publicKeys, namespace, srcCore, request, responses, {
198
+ swarmAsServer: !swarmClientOnly,
183
199
  skipTargetChecks: firstCommit,
200
+ skipTargetWellSeeded,
184
201
  force: forceDangerous,
185
202
  peerUpdateTimeout: peerUpdateTimeout,
186
203
  quorum
@@ -188,13 +205,15 @@ async function commit() {
188
205
  } else {
189
206
  const srcDrive = new Hyperdrive(store, idEnc.decode(srcKey))
190
207
  runner = multisig.commitDrive(publicKeys, namespace, srcDrive, request, responses, {
208
+ swarmAsServer: !swarmClientOnly,
191
209
  skipTargetChecks: firstCommit,
210
+ skipTargetWellSeeded,
192
211
  force: forceDangerous,
193
212
  peerUpdateTimeout: peerUpdateTimeout,
194
213
  quorum
195
214
  })
196
215
  }
197
- setupProgressLogs(runner, type, firstCommit)
216
+ setupProgressLogs(runner, type, firstCommit, false)
198
217
 
199
218
  const res = await runner.done()
200
219
 
@@ -203,17 +222,104 @@ async function commit() {
203
222
  console.info(`${type} key: ${destKey}`)
204
223
  }
205
224
 
206
- function setupProgressLogs(req, name, firstCommit) {
225
+ async function seed() {
226
+ const logInterval = cmdSeed.flags.logInterval
227
+ ? +cmdSeed.flags.logInterval
228
+ : DEFAULT_SEED_LOG_INTERVAL
229
+ const { type, publicKeys, namespace, srcKey, multisigKey, quorum, store, swarm } = await setup()
230
+
231
+ const multisig = new Multisig(store, swarm)
232
+ console.log('\nPreparing to seed ~ Press Ctrl+C to exit\n')
233
+
234
+ const allCores = []
235
+
236
+ if (type === 'core') {
237
+ const srcCore = store.get({ key: idEnc.decode(srcKey) })
238
+ await srcCore.ready()
239
+ swarm.join(srcCore.discoveryKey)
240
+ srcCore.download({ start: 0, end: -1 })
241
+
242
+ let tgtCore
243
+ if (multisigKey) {
244
+ tgtCore = store.get({ key: idEnc.decode(multisigKey) })
245
+ await tgtCore.ready()
246
+ } else {
247
+ const res = await multisig.createCore(publicKeys, namespace, { quorum })
248
+ tgtCore = res.core
249
+ }
250
+ swarm.join(tgtCore.discoveryKey)
251
+ tgtCore.download({ start: 0, end: -1 })
252
+
253
+ allCores.push({ core: srcCore, label: 'Source' }, { core: tgtCore, label: 'Multisig' })
254
+ } else {
255
+ const srcDrive = new Hyperdrive(store, idEnc.decode(srcKey))
256
+ await srcDrive.ready()
257
+ swarm.join(srcDrive.discoveryKey)
258
+ srcDrive.db.core.download({ start: 0, end: -1 })
259
+ await srcDrive.getBlobs()
260
+ srcDrive.blobs.core.download({ start: 0, end: -1 })
261
+
262
+ let tgtCore
263
+ let tgtBlobsCore
264
+ if (multisigKey) {
265
+ const tgtDrive = new Hyperdrive(store, idEnc.decode(multisigKey))
266
+ await tgtDrive.ready()
267
+ tgtCore = tgtDrive.db.core
268
+ await tgtDrive.getBlobs()
269
+ tgtBlobsCore = tgtDrive.blobs.core
270
+ } else {
271
+ const res = await multisig.createDrive(publicKeys, namespace, { quorum })
272
+ tgtCore = res.core
273
+ tgtBlobsCore = res.blobsCore
274
+ await tgtBlobsCore.ready()
275
+ }
276
+ swarm.join(tgtCore.discoveryKey)
277
+ tgtCore.download({ start: 0, end: -1 })
278
+ tgtBlobsCore.download({ start: 0, end: -1 })
279
+
280
+ allCores.push(
281
+ { core: srcDrive.db.core, label: 'Source DB' },
282
+ { core: srcDrive.blobs.core, label: 'Source Blobs' },
283
+ { core: tgtCore, label: 'Multisig DB' },
284
+ { core: tgtBlobsCore, label: 'Multisig Blobs' }
285
+ )
286
+ }
287
+
288
+ for (const { core, label } of allCores) {
289
+ console.log(`${label} core:`)
290
+ console.log(` key: ${idEnc.normalize(core.key)}`)
291
+ console.log(` keyHex: ${core.key.toString('hex')}`)
292
+ console.log(` length: ${core.length}`)
293
+ console.log(` treeHash: ${idEnc.normalize(await core.treeHash())}\n`)
294
+ }
295
+
296
+ const interval = setInterval(() => {
297
+ allCores.forEach(({ core, label }) => {
298
+ const peers = core.peers.length
299
+ let fullyDownloadedPeers = 0
300
+ for (const p of core.peers) {
301
+ if (p.remoteContiguousLength >= core.length) fullyDownloadedPeers++
302
+ }
303
+ console.log(
304
+ `${label} core: ${peers} peers, ${fullyDownloadedPeers} fully downloaded, length: ${core.length}`
305
+ )
306
+ })
307
+ console.log()
308
+ }, logInterval)
309
+ goodbye(() => clearInterval(interval))
310
+ }
311
+
312
+ function setupProgressLogs(req, name, firstCommit, dryRun) {
207
313
  req.on('verify-committable-start', (srcKey, tgtKey) => {
208
314
  console.log(
209
- `Verifying the ${name} is safe to commit (source ${idEnc.normalize(srcKey)} to multisig target ${idEnc.normalize(tgtKey)})`
315
+ `Verifying the ${name} is safe to commit: source ${idEnc.normalize(srcKey)} (hex: ${srcKey.toString('hex')}) to multisig target ${idEnc.normalize(tgtKey)} (hex: ${tgtKey.toString('hex')})`
210
316
  )
211
317
  })
212
318
  req.on('commit-start', () => {
213
- console.log(`Committing the ${name}...`)
319
+ console.log(dryRun ? `Dry run the ${name} commit` : `Committing the ${name}...`)
214
320
  })
215
321
  req.on('verify-committed-start', (key) => {
216
- console.log(`Committed the ${name} (key ${idEnc.normalize(key)})`)
322
+ console.log(`Committed the ${name}, key ${idEnc.normalize(key)} (hex: ${key.toString('hex')})`)
217
323
  console.log('Waiting for remote seeders to pick up the changes...')
218
324
  if (firstCommit) {
219
325
  console.log(
@@ -228,8 +334,10 @@ function printRequest(request) {
228
334
  const reqStr = z32.encode(request)
229
335
  const reqMsg = {
230
336
  key: runner.id,
337
+ keyHex: runner.key.toString('hex'),
231
338
  length: runner.length,
232
- treeHash: idEnc.normalize(runner.treeHash)
339
+ treeHash: idEnc.normalize(runner.treeHash),
340
+ treeHashHex: runner.treeHash.toString('hex')
233
341
  }
234
342
  console.log('Request:', JSON.stringify(reqMsg, null, 2))
235
343
  console.log('To sign, run:', `\nhypercore-sign ${reqStr}`)
@@ -297,11 +405,12 @@ async function loadConfig(configPath, opts = {}) {
297
405
  if (bootstrap) console.info(`Using non-default bootstrap`)
298
406
 
299
407
  if (multisigKey) {
300
- const calculatedKey = idEnc.normalize(Multisig.getCoreKey(publicKeys, namespace, { quorum }))
408
+ const calculatedKeyBuffer = Multisig.getCoreKey(publicKeys, namespace, { quorum })
409
+ const calculatedKey = idEnc.normalize(calculatedKeyBuffer)
301
410
  const passedInKey = idEnc.normalize(multisigKey)
302
411
  if (passedInKey !== calculatedKey) {
303
412
  throw new Error(
304
- `multisigKey does not correspond to the key generated from the config (expected ${calculatedKey})`
413
+ `multisigKey does not correspond to the key generated from the config, expected ${calculatedKey} (hex: ${calculatedKeyBuffer.toString('hex')})`
305
414
  )
306
415
  }
307
416
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hyper-multisig-cli",
3
- "version": "1.3.0",
3
+ "version": "1.5.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": "^2.1.0",
24
+ "hyper-multisig": "^2.3.0",
25
25
  "hypercore-id-encoding": "^1.3.0",
26
26
  "hypercore-signing-request": "^5.0.1",
27
27
  "hyperdrive": "^13.2.1",
@@ -36,7 +36,7 @@
36
36
  "bare-subprocess": "^5.2.2",
37
37
  "brittle": "^3.19.1",
38
38
  "hypercore-crypto": "^3.6.1",
39
- "hypercore-sign": "^4.0.1",
39
+ "hypercore-sign-lib": "^1.1.0",
40
40
  "hyperdht": "^6.29.0",
41
41
  "lunte": "^1.6.0",
42
42
  "newline-decoder": "^1.0.2",