hypercore-storage 2.9.0 → 3.0.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.
@@ -0,0 +1,14 @@
1
+ function headLegacyMap(m) {
2
+ return {
3
+ version: 2, // version bumped from 1
4
+ cores: m.allocated.cores,
5
+ datas: m.allocated.datas,
6
+ groups: 0,
7
+ seed: m.seed,
8
+ defaultDiscoveryKey: m.defaultDiscoveryKey
9
+ }
10
+ }
11
+
12
+ module.exports = {
13
+ headLegacyMap
14
+ }
@@ -1,12 +1,13 @@
1
1
  // This file is autogenerated by the hyperschema compiler
2
- // Schema Version: 1
2
+ // Schema Version: 2
3
3
  /* eslint-disable camelcase */
4
4
  /* eslint-disable quotes */
5
5
  /* eslint-disable space-before-function-paren */
6
6
 
7
7
  const { c } = require('hyperschema/runtime')
8
+ const external0 = require('../../external.js')
8
9
 
9
- const VERSION = 1
10
+ const VERSION = 2
10
11
 
11
12
  // eslint-disable-next-line no-unused-vars
12
13
  let version = VERSION
@@ -32,10 +33,9 @@ const encoding0 = {
32
33
  }
33
34
  }
34
35
 
35
- // @corestore/head
36
+ // @corestore/head-v1
36
37
  const encoding1 = {
37
38
  preencode(state, m) {
38
- c.uint.preencode(state, m.version)
39
39
  state.end++ // max flag is 4 so always one byte
40
40
 
41
41
  if (m.allocated) encoding0.preencode(state, m.allocated)
@@ -45,7 +45,6 @@ const encoding1 = {
45
45
  encode(state, m) {
46
46
  const flags = (m.allocated ? 1 : 0) | (m.seed ? 2 : 0) | (m.defaultDiscoveryKey ? 4 : 0)
47
47
 
48
- c.uint.encode(state, m.version)
49
48
  c.uint.encode(state, flags)
50
49
 
51
50
  if (m.allocated) encoding0.encode(state, m.allocated)
@@ -53,11 +52,11 @@ const encoding1 = {
53
52
  if (m.defaultDiscoveryKey) c.fixed32.encode(state, m.defaultDiscoveryKey)
54
53
  },
55
54
  decode(state) {
56
- const r0 = c.uint.decode(state)
55
+ const v = c.uint.decode(state)
57
56
  const flags = c.uint.decode(state)
58
57
 
59
58
  return {
60
- version: r0,
59
+ version: v,
61
60
  allocated: (flags & 1) !== 0 ? encoding0.decode(state) : null,
62
61
  seed: (flags & 2) !== 0 ? c.fixed32.decode(state) : null,
63
62
  defaultDiscoveryKey: (flags & 4) !== 0 ? c.fixed32.decode(state) : null
@@ -65,8 +64,99 @@ const encoding1 = {
65
64
  }
66
65
  }
67
66
 
68
- // @corestore/alias
67
+ // @corestore/head-v2
69
68
  const encoding2 = {
69
+ preencode(state, m) {
70
+ c.uint.preencode(state, m.cores)
71
+ c.uint.preencode(state, m.datas)
72
+ c.uint.preencode(state, m.groups)
73
+ state.end++ // max flag is 2 so always one byte
74
+
75
+ if (m.seed) c.fixed32.preencode(state, m.seed)
76
+ if (m.defaultDiscoveryKey) c.fixed32.preencode(state, m.defaultDiscoveryKey)
77
+ },
78
+ encode(state, m) {
79
+ const flags = (m.seed ? 1 : 0) | (m.defaultDiscoveryKey ? 2 : 0)
80
+
81
+ c.uint.encode(state, m.cores)
82
+ c.uint.encode(state, m.datas)
83
+ c.uint.encode(state, m.groups)
84
+ c.uint.encode(state, flags)
85
+
86
+ if (m.seed) c.fixed32.encode(state, m.seed)
87
+ if (m.defaultDiscoveryKey) c.fixed32.encode(state, m.defaultDiscoveryKey)
88
+ },
89
+ decode(state) {
90
+ const v = c.uint.decode(state)
91
+ const r0 = c.uint.decode(state)
92
+ const r1 = c.uint.decode(state)
93
+ const r2 = c.uint.decode(state)
94
+ const flags = c.uint.decode(state)
95
+
96
+ return {
97
+ version: v,
98
+ cores: r0,
99
+ datas: r1,
100
+ groups: r2,
101
+ seed: (flags & 1) !== 0 ? c.fixed32.decode(state) : null,
102
+ defaultDiscoveryKey: (flags & 2) !== 0 ? c.fixed32.decode(state) : null
103
+ }
104
+ }
105
+ }
106
+
107
+ // @corestore/head
108
+ const encoding3 = {
109
+ preencode(state, m) {
110
+ c.uint.preencode(state, m.version)
111
+ switch (m.version) {
112
+ case 0:
113
+ case 1:
114
+ encoding1.preencode(state, m)
115
+ break
116
+ case 2:
117
+ encoding2.preencode(state, m)
118
+ break
119
+ default:
120
+ throw new Error('Unsupported version')
121
+ }
122
+ },
123
+ encode(state, m) {
124
+ c.uint.encode(state, m.version)
125
+ switch (m.version) {
126
+ case 0:
127
+ case 1:
128
+ encoding1.encode(state, m)
129
+ break
130
+ case 2:
131
+ encoding2.encode(state, m)
132
+ break
133
+ default:
134
+ throw new Error('Unsupported version')
135
+ }
136
+ },
137
+ decode(state) {
138
+ const start = state.start
139
+ const v = c.uint.decode(state)
140
+ state.start = start
141
+ switch (v) {
142
+ case 0:
143
+ case 1: {
144
+ const decoded = encoding1.decode(state)
145
+ const map = external0.headLegacyMap
146
+ return map(decoded)
147
+ }
148
+ case 2: {
149
+ const decoded = encoding2.decode(state)
150
+ return decoded
151
+ }
152
+ default:
153
+ throw new Error('Unsupported version')
154
+ }
155
+ }
156
+ }
157
+
158
+ // @corestore/alias
159
+ const encoding4 = {
70
160
  preencode(state, m) {
71
161
  c.string.preencode(state, m.name)
72
162
  c.fixed32.preencode(state, m.namespace)
@@ -87,14 +177,14 @@ const encoding2 = {
87
177
  }
88
178
 
89
179
  // @corestore/core
90
- const encoding3 = {
180
+ const encoding5 = {
91
181
  preencode(state, m) {
92
182
  c.uint.preencode(state, m.version)
93
183
  c.uint.preencode(state, m.corePointer)
94
184
  c.uint.preencode(state, m.dataPointer)
95
185
  state.end++ // max flag is 1 so always one byte
96
186
 
97
- if (m.alias) encoding2.preencode(state, m.alias)
187
+ if (m.alias) encoding4.preencode(state, m.alias)
98
188
  },
99
189
  encode(state, m) {
100
190
  const flags = m.alias ? 1 : 0
@@ -104,7 +194,7 @@ const encoding3 = {
104
194
  c.uint.encode(state, m.dataPointer)
105
195
  c.uint.encode(state, flags)
106
196
 
107
- if (m.alias) encoding2.encode(state, m.alias)
197
+ if (m.alias) encoding4.encode(state, m.alias)
108
198
  },
109
199
  decode(state) {
110
200
  const r0 = c.uint.decode(state)
@@ -116,21 +206,21 @@ const encoding3 = {
116
206
  version: r0,
117
207
  corePointer: r1,
118
208
  dataPointer: r2,
119
- alias: (flags & 1) !== 0 ? encoding2.decode(state) : null
209
+ alias: (flags & 1) !== 0 ? encoding4.decode(state) : null
120
210
  }
121
211
  }
122
212
  }
123
213
 
124
- const encoding4_enum = {
214
+ const encoding6_enum = {
125
215
  blake2b: 'blake2b'
126
216
  }
127
217
 
128
218
  // @core/hashes enum
129
- const encoding4 = {
130
- preencode (state, m) {
219
+ const encoding6 = {
220
+ preencode(state, m) {
131
221
  state.end++ // max enum is 0 so always one byte
132
222
  },
133
- encode (state, m) {
223
+ encode(state, m) {
134
224
  switch (m) {
135
225
  case 'blake2b':
136
226
  c.uint.encode(state, 0)
@@ -139,25 +229,26 @@ const encoding4 = {
139
229
  throw new Error('Unknown enum')
140
230
  }
141
231
  },
142
- decode (state) {
232
+ decode(state) {
143
233
  switch (c.uint.decode(state)) {
144
234
  case 0:
145
235
  return 'blake2b'
146
- default: return null
236
+ default:
237
+ return null
147
238
  }
148
239
  }
149
240
  }
150
241
 
151
- const encoding5_enum = {
242
+ const encoding7_enum = {
152
243
  ed25519: 'ed25519'
153
244
  }
154
245
 
155
246
  // @core/signatures enum
156
- const encoding5 = {
157
- preencode (state, m) {
247
+ const encoding7 = {
248
+ preencode(state, m) {
158
249
  state.end++ // max enum is 0 so always one byte
159
250
  },
160
- encode (state, m) {
251
+ encode(state, m) {
161
252
  switch (m) {
162
253
  case 'ed25519':
163
254
  c.uint.encode(state, 0)
@@ -166,17 +257,18 @@ const encoding5 = {
166
257
  throw new Error('Unknown enum')
167
258
  }
168
259
  },
169
- decode (state) {
260
+ decode(state) {
170
261
  switch (c.uint.decode(state)) {
171
262
  case 0:
172
263
  return 'ed25519'
173
- default: return null
264
+ default:
265
+ return null
174
266
  }
175
267
  }
176
268
  }
177
269
 
178
270
  // @core/tree-node
179
- const encoding6 = {
271
+ const encoding8 = {
180
272
  preencode(state, m) {
181
273
  c.uint.preencode(state, m.index)
182
274
  c.uint.preencode(state, m.size)
@@ -201,19 +293,19 @@ const encoding6 = {
201
293
  }
202
294
 
203
295
  // @core/signer
204
- const encoding7 = {
296
+ const encoding9 = {
205
297
  preencode(state, m) {
206
- encoding5.preencode(state, m.signature)
298
+ encoding7.preencode(state, m.signature)
207
299
  c.fixed32.preencode(state, m.namespace)
208
300
  c.fixed32.preencode(state, m.publicKey)
209
301
  },
210
302
  encode(state, m) {
211
- encoding5.encode(state, m.signature)
303
+ encoding7.encode(state, m.signature)
212
304
  c.fixed32.encode(state, m.namespace)
213
305
  c.fixed32.encode(state, m.publicKey)
214
306
  },
215
307
  decode(state) {
216
- const r0 = encoding5.decode(state)
308
+ const r0 = encoding7.decode(state)
217
309
  const r1 = c.fixed32.decode(state)
218
310
  const r2 = c.fixed32.decode(state)
219
311
 
@@ -226,7 +318,7 @@ const encoding7 = {
226
318
  }
227
319
 
228
320
  // @core/prologue
229
- const encoding8 = {
321
+ const encoding10 = {
230
322
  preencode(state, m) {
231
323
  c.fixed32.preencode(state, m.hash)
232
324
  c.uint.preencode(state, m.length)
@@ -247,21 +339,21 @@ const encoding8 = {
247
339
  }
248
340
 
249
341
  // @core/manifest.signers
250
- const encoding9_4 = c.array(encoding7)
342
+ const encoding11_4 = c.array(encoding9)
251
343
  // @core/manifest.linked
252
- const encoding9_6 = c.array(c.fixed32)
344
+ const encoding11_6 = c.array(c.fixed32)
253
345
 
254
346
  // @core/manifest
255
- const encoding9 = {
347
+ const encoding11 = {
256
348
  preencode(state, m) {
257
349
  c.uint.preencode(state, m.version)
258
350
  state.end++ // max flag is 8 so always one byte
259
- encoding4.preencode(state, m.hash)
351
+ encoding6.preencode(state, m.hash)
260
352
  c.uint.preencode(state, m.quorum)
261
- encoding9_4.preencode(state, m.signers)
353
+ encoding11_4.preencode(state, m.signers)
262
354
 
263
- if (m.prologue) encoding8.preencode(state, m.prologue)
264
- if (m.linked) encoding9_6.preencode(state, m.linked)
355
+ if (m.prologue) encoding10.preencode(state, m.prologue)
356
+ if (m.linked) encoding11_6.preencode(state, m.linked)
265
357
  if (m.userData) c.buffer.preencode(state, m.userData)
266
358
  },
267
359
  encode(state, m) {
@@ -270,12 +362,12 @@ const encoding9 = {
270
362
 
271
363
  c.uint.encode(state, m.version)
272
364
  c.uint.encode(state, flags)
273
- encoding4.encode(state, m.hash)
365
+ encoding6.encode(state, m.hash)
274
366
  c.uint.encode(state, m.quorum)
275
- encoding9_4.encode(state, m.signers)
367
+ encoding11_4.encode(state, m.signers)
276
368
 
277
- if (m.prologue) encoding8.encode(state, m.prologue)
278
- if (m.linked) encoding9_6.encode(state, m.linked)
369
+ if (m.prologue) encoding10.encode(state, m.prologue)
370
+ if (m.linked) encoding11_6.encode(state, m.linked)
279
371
  if (m.userData) c.buffer.encode(state, m.userData)
280
372
  },
281
373
  decode(state) {
@@ -284,19 +376,19 @@ const encoding9 = {
284
376
 
285
377
  return {
286
378
  version: r0,
287
- hash: encoding4.decode(state),
379
+ hash: encoding6.decode(state),
288
380
  quorum: c.uint.decode(state),
289
381
  allowPatch: (flags & 1) !== 0,
290
- signers: encoding9_4.decode(state),
291
- prologue: (flags & 2) !== 0 ? encoding8.decode(state) : null,
292
- linked: (flags & 4) !== 0 ? encoding9_6.decode(state) : null,
382
+ signers: encoding11_4.decode(state),
383
+ prologue: (flags & 2) !== 0 ? encoding10.decode(state) : null,
384
+ linked: (flags & 4) !== 0 ? encoding11_6.decode(state) : null,
293
385
  userData: (flags & 8) !== 0 ? c.buffer.decode(state) : null
294
386
  }
295
387
  }
296
388
  }
297
389
 
298
390
  // @core/keyPair
299
- const encoding10 = {
391
+ const encoding12 = {
300
392
  preencode(state, m) {
301
393
  c.buffer.preencode(state, m.publicKey)
302
394
  c.optionalBuffer.preencode(state, m.secretKey)
@@ -316,18 +408,44 @@ const encoding10 = {
316
408
  }
317
409
  }
318
410
 
411
+ // @core/group
412
+ const encoding13 = {
413
+ preencode(state, m) {
414
+ state.end++ // max flag is 2 so always one byte
415
+
416
+ if (m.key) c.fixed32.preencode(state, m.key)
417
+ if (m.pointer) c.uint.preencode(state, m.pointer)
418
+ },
419
+ encode(state, m) {
420
+ const flags = (m.key ? 1 : 0) | (m.pointer ? 2 : 0)
421
+
422
+ c.uint.encode(state, flags)
423
+
424
+ if (m.key) c.fixed32.encode(state, m.key)
425
+ if (m.pointer) c.uint.encode(state, m.pointer)
426
+ },
427
+ decode(state) {
428
+ const flags = c.uint.decode(state)
429
+
430
+ return {
431
+ key: (flags & 1) !== 0 ? c.fixed32.decode(state) : null,
432
+ pointer: (flags & 2) !== 0 ? c.uint.decode(state) : 0
433
+ }
434
+ }
435
+ }
436
+
319
437
  // @core/auth.manifest
320
- const encoding11_2 = c.frame(encoding9)
438
+ const encoding14_2 = c.frame(encoding11)
321
439
 
322
440
  // @core/auth
323
- const encoding11 = {
441
+ const encoding14 = {
324
442
  preencode(state, m) {
325
443
  c.fixed32.preencode(state, m.key)
326
444
  c.fixed32.preencode(state, m.discoveryKey)
327
445
  state.end++ // max flag is 4 so always one byte
328
446
 
329
- if (m.manifest) encoding11_2.preencode(state, m.manifest)
330
- if (m.keyPair) encoding10.preencode(state, m.keyPair)
447
+ if (m.manifest) encoding14_2.preencode(state, m.manifest)
448
+ if (m.keyPair) encoding12.preencode(state, m.keyPair)
331
449
  if (m.encryptionKey) c.buffer.preencode(state, m.encryptionKey)
332
450
  },
333
451
  encode(state, m) {
@@ -337,8 +455,8 @@ const encoding11 = {
337
455
  c.fixed32.encode(state, m.discoveryKey)
338
456
  c.uint.encode(state, flags)
339
457
 
340
- if (m.manifest) encoding11_2.encode(state, m.manifest)
341
- if (m.keyPair) encoding10.encode(state, m.keyPair)
458
+ if (m.manifest) encoding14_2.encode(state, m.manifest)
459
+ if (m.keyPair) encoding12.encode(state, m.keyPair)
342
460
  if (m.encryptionKey) c.buffer.encode(state, m.encryptionKey)
343
461
  },
344
462
  decode(state) {
@@ -349,44 +467,54 @@ const encoding11 = {
349
467
  return {
350
468
  key: r0,
351
469
  discoveryKey: r1,
352
- manifest: (flags & 1) !== 0 ? encoding11_2.decode(state) : null,
353
- keyPair: (flags & 2) !== 0 ? encoding10.decode(state) : null,
470
+ manifest: (flags & 1) !== 0 ? encoding14_2.decode(state) : null,
471
+ keyPair: (flags & 2) !== 0 ? encoding12.decode(state) : null,
354
472
  encryptionKey: (flags & 4) !== 0 ? c.buffer.decode(state) : null
355
473
  }
356
474
  }
357
475
  }
358
476
 
359
477
  // @core/head
360
- const encoding12 = {
478
+ const encoding15 = {
361
479
  preencode(state, m) {
362
480
  c.uint.preencode(state, m.fork)
363
481
  c.uint.preencode(state, m.length)
364
482
  c.fixed32.preencode(state, m.rootHash)
365
483
  c.optionalBuffer.preencode(state, m.signature)
484
+ state.end++ // max flag is 1 so always one byte
485
+
486
+ if (version >= 2 && m.timestamp) c.uint64.preencode(state, m.timestamp)
366
487
  },
367
488
  encode(state, m) {
489
+ const flags = version >= 2 && m.timestamp ? 1 : 0
490
+
368
491
  c.uint.encode(state, m.fork)
369
492
  c.uint.encode(state, m.length)
370
493
  c.fixed32.encode(state, m.rootHash)
371
494
  c.optionalBuffer.encode(state, m.signature)
495
+ c.uint.encode(state, flags)
496
+
497
+ if (version >= 2 && m.timestamp) c.uint64.encode(state, m.timestamp)
372
498
  },
373
499
  decode(state) {
374
500
  const r0 = c.uint.decode(state)
375
501
  const r1 = c.uint.decode(state)
376
502
  const r2 = c.fixed32.decode(state)
377
503
  const r3 = c.optionalBuffer.decode(state)
504
+ const flags = state.start < state.end ? c.uint.decode(state) : 0
378
505
 
379
506
  return {
380
507
  fork: r0,
381
508
  length: r1,
382
509
  rootHash: r2,
383
- signature: r3
510
+ signature: r3,
511
+ timestamp: version >= 2 && (flags & 1) !== 0 ? c.uint64.decode(state) : 0
384
512
  }
385
513
  }
386
514
  }
387
515
 
388
516
  // @core/hints
389
- const encoding13 = {
517
+ const encoding16 = {
390
518
  preencode(state, m) {
391
519
  state.end++ // max flag is 4 so always one byte
392
520
 
@@ -416,7 +544,7 @@ const encoding13 = {
416
544
  }
417
545
 
418
546
  // @core/session
419
- const encoding14 = {
547
+ const encoding17 = {
420
548
  preencode(state, m) {
421
549
  c.string.preencode(state, m.name)
422
550
  c.uint.preencode(state, m.dataPointer)
@@ -437,10 +565,10 @@ const encoding14 = {
437
565
  }
438
566
 
439
567
  // @core/sessions
440
- const encoding15 = c.array(encoding14)
568
+ const encoding18 = c.array(encoding17)
441
569
 
442
570
  // @core/dependency
443
- const encoding16 = {
571
+ const encoding19 = {
444
572
  preencode(state, m) {
445
573
  c.uint.preencode(state, m.dataPointer)
446
574
  c.uint.preencode(state, m.length)
@@ -477,9 +605,9 @@ function decode(name, buffer, v = VERSION) {
477
605
  function getEnum(name) {
478
606
  switch (name) {
479
607
  case '@core/hashes':
480
- return encoding4_enum
608
+ return encoding6_enum
481
609
  case '@core/signatures':
482
- return encoding5_enum
610
+ return encoding7_enum
483
611
  default:
484
612
  throw new Error('Enum not found ' + name)
485
613
  }
@@ -489,38 +617,44 @@ function getEncoding(name) {
489
617
  switch (name) {
490
618
  case '@corestore/allocated':
491
619
  return encoding0
492
- case '@corestore/head':
620
+ case '@corestore/head-v1':
493
621
  return encoding1
494
- case '@corestore/alias':
622
+ case '@corestore/head-v2':
495
623
  return encoding2
496
- case '@corestore/core':
624
+ case '@corestore/head':
497
625
  return encoding3
498
- case '@core/hashes':
626
+ case '@corestore/alias':
499
627
  return encoding4
500
- case '@core/signatures':
628
+ case '@corestore/core':
501
629
  return encoding5
502
- case '@core/tree-node':
630
+ case '@core/hashes':
503
631
  return encoding6
504
- case '@core/signer':
632
+ case '@core/signatures':
505
633
  return encoding7
506
- case '@core/prologue':
634
+ case '@core/tree-node':
507
635
  return encoding8
508
- case '@core/manifest':
636
+ case '@core/signer':
509
637
  return encoding9
510
- case '@core/keyPair':
638
+ case '@core/prologue':
511
639
  return encoding10
512
- case '@core/auth':
640
+ case '@core/manifest':
513
641
  return encoding11
514
- case '@core/head':
642
+ case '@core/keyPair':
515
643
  return encoding12
516
- case '@core/hints':
644
+ case '@core/group':
517
645
  return encoding13
518
- case '@core/session':
646
+ case '@core/auth':
519
647
  return encoding14
520
- case '@core/sessions':
648
+ case '@core/head':
521
649
  return encoding15
522
- case '@core/dependency':
650
+ case '@core/hints':
523
651
  return encoding16
652
+ case '@core/session':
653
+ return encoding17
654
+ case '@core/sessions':
655
+ return encoding18
656
+ case '@core/dependency':
657
+ return encoding19
524
658
  default:
525
659
  throw new Error('Encoder not found ' + name)
526
660
  }