hyper-multisig-cli 1.3.0 → 1.4.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 (2) hide show
  1. package/bin.js +104 -4
  2. package/package.json +2 -2
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
 
@@ -52,6 +53,15 @@ const cmdCommit = command(
52
53
  wrapErrHandler(commit)
53
54
  )
54
55
 
56
+ const cmdSeed = command(
57
+ 'seed',
58
+ description('Seed both the source and multisig cores/drives'),
59
+ flag('--log-interval <logInterval>', 'Interval in ms to log replication status').default(
60
+ DEFAULT_SEED_LOG_INTERVAL
61
+ ),
62
+ wrapErrHandler(seed)
63
+ )
64
+
55
65
  const cmd = command(
56
66
  'multisig',
57
67
  flag('--config|-c <config>', `Config file path (default to ${DEFAULT_CONFIG_PATH})`),
@@ -60,6 +70,7 @@ const cmd = command(
60
70
  cmdRequest,
61
71
  cmdVerify,
62
72
  cmdCommit,
73
+ cmdSeed,
63
74
  () => console.log(cmd.help())
64
75
  )
65
76
 
@@ -203,17 +214,104 @@ async function commit() {
203
214
  console.info(`${type} key: ${destKey}`)
204
215
  }
205
216
 
217
+ async function seed() {
218
+ const logInterval = cmdSeed.flags.logInterval
219
+ ? +cmdSeed.flags.logInterval
220
+ : DEFAULT_SEED_LOG_INTERVAL
221
+ const { type, publicKeys, namespace, srcKey, multisigKey, quorum, store, swarm } = await setup()
222
+
223
+ const multisig = new Multisig(store, swarm)
224
+ console.log('\nPreparing to seed ~ Press Ctrl+C to exit\n')
225
+
226
+ const allCores = []
227
+
228
+ if (type === 'core') {
229
+ const srcCore = store.get({ key: idEnc.decode(srcKey) })
230
+ await srcCore.ready()
231
+ swarm.join(srcCore.discoveryKey)
232
+ srcCore.download({ start: 0, end: -1 })
233
+
234
+ let tgtCore
235
+ if (multisigKey) {
236
+ tgtCore = store.get({ key: idEnc.decode(multisigKey) })
237
+ await tgtCore.ready()
238
+ } else {
239
+ const res = await multisig.createCore(publicKeys, namespace, { quorum })
240
+ tgtCore = res.core
241
+ }
242
+ swarm.join(tgtCore.discoveryKey)
243
+ tgtCore.download({ start: 0, end: -1 })
244
+
245
+ allCores.push({ core: srcCore, label: 'Source' }, { core: tgtCore, label: 'Multisig' })
246
+ } else {
247
+ const srcDrive = new Hyperdrive(store, idEnc.decode(srcKey))
248
+ await srcDrive.ready()
249
+ swarm.join(srcDrive.discoveryKey)
250
+ srcDrive.db.core.download({ start: 0, end: -1 })
251
+ await srcDrive.getBlobs()
252
+ srcDrive.blobs.core.download({ start: 0, end: -1 })
253
+
254
+ let tgtCore
255
+ let tgtBlobsCore
256
+ if (multisigKey) {
257
+ const tgtDrive = new Hyperdrive(store, idEnc.decode(multisigKey))
258
+ await tgtDrive.ready()
259
+ tgtCore = tgtDrive.db.core
260
+ await tgtDrive.getBlobs()
261
+ tgtBlobsCore = tgtDrive.blobs.core
262
+ } else {
263
+ const res = await multisig.createDrive(publicKeys, namespace, { quorum })
264
+ tgtCore = res.core
265
+ tgtBlobsCore = res.blobsCore
266
+ await tgtBlobsCore.ready()
267
+ }
268
+ swarm.join(tgtCore.discoveryKey)
269
+ tgtCore.download({ start: 0, end: -1 })
270
+ tgtBlobsCore.download({ start: 0, end: -1 })
271
+
272
+ allCores.push(
273
+ { core: srcDrive.db.core, label: 'Source DB' },
274
+ { core: srcDrive.blobs.core, label: 'Source Blobs' },
275
+ { core: tgtCore, label: 'Multisig DB' },
276
+ { core: tgtBlobsCore, label: 'Multisig Blobs' }
277
+ )
278
+ }
279
+
280
+ for (const { core, label } of allCores) {
281
+ console.log(`${label} core:`)
282
+ console.log(` key: ${idEnc.normalize(core.key)}`)
283
+ console.log(` keyHex: ${core.key.toString('hex')}`)
284
+ console.log(` length: ${core.length}`)
285
+ console.log(` treeHash: ${idEnc.normalize(await core.treeHash())}\n`)
286
+ }
287
+
288
+ const interval = setInterval(() => {
289
+ allCores.forEach(({ core, label }) => {
290
+ const peers = core.peers.length
291
+ let fullyDownloadedPeers = 0
292
+ for (const p of core.peers) {
293
+ if (p.remoteContiguousLength >= core.length) fullyDownloadedPeers++
294
+ }
295
+ console.log(
296
+ `${label} core: ${peers} peers, ${fullyDownloadedPeers} fully downloaded, length: ${core.length}`
297
+ )
298
+ })
299
+ console.log()
300
+ }, logInterval)
301
+ goodbye(() => clearInterval(interval))
302
+ }
303
+
206
304
  function setupProgressLogs(req, name, firstCommit) {
207
305
  req.on('verify-committable-start', (srcKey, tgtKey) => {
208
306
  console.log(
209
- `Verifying the ${name} is safe to commit (source ${idEnc.normalize(srcKey)} to multisig target ${idEnc.normalize(tgtKey)})`
307
+ `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
308
  )
211
309
  })
212
310
  req.on('commit-start', () => {
213
311
  console.log(`Committing the ${name}...`)
214
312
  })
215
313
  req.on('verify-committed-start', (key) => {
216
- console.log(`Committed the ${name} (key ${idEnc.normalize(key)})`)
314
+ console.log(`Committed the ${name}, key ${idEnc.normalize(key)} (hex: ${key.toString('hex')})`)
217
315
  console.log('Waiting for remote seeders to pick up the changes...')
218
316
  if (firstCommit) {
219
317
  console.log(
@@ -228,6 +326,7 @@ function printRequest(request) {
228
326
  const reqStr = z32.encode(request)
229
327
  const reqMsg = {
230
328
  key: runner.id,
329
+ keyHex: runner.key.toString('hex'),
231
330
  length: runner.length,
232
331
  treeHash: idEnc.normalize(runner.treeHash)
233
332
  }
@@ -297,11 +396,12 @@ async function loadConfig(configPath, opts = {}) {
297
396
  if (bootstrap) console.info(`Using non-default bootstrap`)
298
397
 
299
398
  if (multisigKey) {
300
- const calculatedKey = idEnc.normalize(Multisig.getCoreKey(publicKeys, namespace, { quorum }))
399
+ const calculatedKeyBuffer = Multisig.getCoreKey(publicKeys, namespace, { quorum })
400
+ const calculatedKey = idEnc.normalize(calculatedKeyBuffer)
301
401
  const passedInKey = idEnc.normalize(multisigKey)
302
402
  if (passedInKey !== calculatedKey) {
303
403
  throw new Error(
304
- `multisigKey does not correspond to the key generated from the config (expected ${calculatedKey})`
404
+ `multisigKey does not correspond to the key generated from the config, expected ${calculatedKey} (hex: ${calculatedKeyBuffer.toString('hex')})`
305
405
  )
306
406
  }
307
407
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hyper-multisig-cli",
3
- "version": "1.3.0",
3
+ "version": "1.4.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.2.1",
25
25
  "hypercore-id-encoding": "^1.3.0",
26
26
  "hypercore-signing-request": "^5.0.1",
27
27
  "hyperdrive": "^13.2.1",