hypercore-storage 2.0.3 → 2.0.4
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/package.json +1 -1
- package/spec/hyperschema/index.js +122 -81
package/package.json
CHANGED
|
@@ -2,24 +2,26 @@
|
|
|
2
2
|
// Schema Version: 1
|
|
3
3
|
/* eslint-disable camelcase */
|
|
4
4
|
/* eslint-disable quotes */
|
|
5
|
+
/* eslint-disable space-before-function-paren */
|
|
5
6
|
|
|
6
|
-
const VERSION = 1
|
|
7
7
|
const { c } = require('hyperschema/runtime')
|
|
8
8
|
|
|
9
|
+
const VERSION = 1
|
|
10
|
+
|
|
9
11
|
// eslint-disable-next-line no-unused-vars
|
|
10
12
|
let version = VERSION
|
|
11
13
|
|
|
12
14
|
// @corestore/allocated
|
|
13
15
|
const encoding0 = {
|
|
14
|
-
preencode
|
|
16
|
+
preencode(state, m) {
|
|
15
17
|
c.uint.preencode(state, m.cores)
|
|
16
18
|
c.uint.preencode(state, m.datas)
|
|
17
19
|
},
|
|
18
|
-
encode
|
|
20
|
+
encode(state, m) {
|
|
19
21
|
c.uint.encode(state, m.cores)
|
|
20
22
|
c.uint.encode(state, m.datas)
|
|
21
23
|
},
|
|
22
|
-
decode
|
|
24
|
+
decode(state) {
|
|
23
25
|
const r0 = c.uint.decode(state)
|
|
24
26
|
const r1 = c.uint.decode(state)
|
|
25
27
|
|
|
@@ -32,7 +34,7 @@ const encoding0 = {
|
|
|
32
34
|
|
|
33
35
|
// @corestore/head
|
|
34
36
|
const encoding1 = {
|
|
35
|
-
preencode
|
|
37
|
+
preencode(state, m) {
|
|
36
38
|
c.uint.preencode(state, m.version)
|
|
37
39
|
state.end++ // max flag is 4 so always one byte
|
|
38
40
|
|
|
@@ -40,7 +42,7 @@ const encoding1 = {
|
|
|
40
42
|
if (m.seed) c.fixed32.preencode(state, m.seed)
|
|
41
43
|
if (m.defaultDiscoveryKey) c.fixed32.preencode(state, m.defaultDiscoveryKey)
|
|
42
44
|
},
|
|
43
|
-
encode
|
|
45
|
+
encode(state, m) {
|
|
44
46
|
const flags =
|
|
45
47
|
(m.allocated ? 1 : 0) |
|
|
46
48
|
(m.seed ? 2 : 0) |
|
|
@@ -53,7 +55,7 @@ const encoding1 = {
|
|
|
53
55
|
if (m.seed) c.fixed32.encode(state, m.seed)
|
|
54
56
|
if (m.defaultDiscoveryKey) c.fixed32.encode(state, m.defaultDiscoveryKey)
|
|
55
57
|
},
|
|
56
|
-
decode
|
|
58
|
+
decode(state) {
|
|
57
59
|
const r0 = c.uint.decode(state)
|
|
58
60
|
const flags = c.uint.decode(state)
|
|
59
61
|
|
|
@@ -68,15 +70,15 @@ const encoding1 = {
|
|
|
68
70
|
|
|
69
71
|
// @corestore/alias
|
|
70
72
|
const encoding2 = {
|
|
71
|
-
preencode
|
|
73
|
+
preencode(state, m) {
|
|
72
74
|
c.string.preencode(state, m.name)
|
|
73
75
|
c.fixed32.preencode(state, m.namespace)
|
|
74
76
|
},
|
|
75
|
-
encode
|
|
77
|
+
encode(state, m) {
|
|
76
78
|
c.string.encode(state, m.name)
|
|
77
79
|
c.fixed32.encode(state, m.namespace)
|
|
78
80
|
},
|
|
79
|
-
decode
|
|
81
|
+
decode(state) {
|
|
80
82
|
const r0 = c.string.decode(state)
|
|
81
83
|
const r1 = c.fixed32.decode(state)
|
|
82
84
|
|
|
@@ -89,7 +91,7 @@ const encoding2 = {
|
|
|
89
91
|
|
|
90
92
|
// @corestore/core
|
|
91
93
|
const encoding3 = {
|
|
92
|
-
preencode
|
|
94
|
+
preencode(state, m) {
|
|
93
95
|
c.uint.preencode(state, m.version)
|
|
94
96
|
c.uint.preencode(state, m.corePointer)
|
|
95
97
|
c.uint.preencode(state, m.dataPointer)
|
|
@@ -97,7 +99,7 @@ const encoding3 = {
|
|
|
97
99
|
|
|
98
100
|
if (m.alias) encoding2.preencode(state, m.alias)
|
|
99
101
|
},
|
|
100
|
-
encode
|
|
102
|
+
encode(state, m) {
|
|
101
103
|
const flags = m.alias ? 1 : 0
|
|
102
104
|
|
|
103
105
|
c.uint.encode(state, m.version)
|
|
@@ -107,7 +109,7 @@ const encoding3 = {
|
|
|
107
109
|
|
|
108
110
|
if (m.alias) encoding2.encode(state, m.alias)
|
|
109
111
|
},
|
|
110
|
-
decode
|
|
112
|
+
decode(state) {
|
|
111
113
|
const r0 = c.uint.decode(state)
|
|
112
114
|
const r1 = c.uint.decode(state)
|
|
113
115
|
const r2 = c.uint.decode(state)
|
|
@@ -136,12 +138,14 @@ const encoding4 = {
|
|
|
136
138
|
case 'blake2b':
|
|
137
139
|
c.uint.encode(state, 0)
|
|
138
140
|
break
|
|
139
|
-
default:
|
|
141
|
+
default:
|
|
142
|
+
throw new Error('Unknown enum')
|
|
140
143
|
}
|
|
141
144
|
},
|
|
142
145
|
decode (state) {
|
|
143
146
|
switch (c.uint.decode(state)) {
|
|
144
|
-
case 0:
|
|
147
|
+
case 0:
|
|
148
|
+
return 'blake2b'
|
|
145
149
|
default: return null
|
|
146
150
|
}
|
|
147
151
|
}
|
|
@@ -161,12 +165,14 @@ const encoding5 = {
|
|
|
161
165
|
case 'ed25519':
|
|
162
166
|
c.uint.encode(state, 0)
|
|
163
167
|
break
|
|
164
|
-
default:
|
|
168
|
+
default:
|
|
169
|
+
throw new Error('Unknown enum')
|
|
165
170
|
}
|
|
166
171
|
},
|
|
167
172
|
decode (state) {
|
|
168
173
|
switch (c.uint.decode(state)) {
|
|
169
|
-
case 0:
|
|
174
|
+
case 0:
|
|
175
|
+
return 'ed25519'
|
|
170
176
|
default: return null
|
|
171
177
|
}
|
|
172
178
|
}
|
|
@@ -174,17 +180,17 @@ const encoding5 = {
|
|
|
174
180
|
|
|
175
181
|
// @core/tree-node
|
|
176
182
|
const encoding6 = {
|
|
177
|
-
preencode
|
|
183
|
+
preencode(state, m) {
|
|
178
184
|
c.uint.preencode(state, m.index)
|
|
179
185
|
c.uint.preencode(state, m.size)
|
|
180
186
|
c.fixed32.preencode(state, m.hash)
|
|
181
187
|
},
|
|
182
|
-
encode
|
|
188
|
+
encode(state, m) {
|
|
183
189
|
c.uint.encode(state, m.index)
|
|
184
190
|
c.uint.encode(state, m.size)
|
|
185
191
|
c.fixed32.encode(state, m.hash)
|
|
186
192
|
},
|
|
187
|
-
decode
|
|
193
|
+
decode(state) {
|
|
188
194
|
const r0 = c.uint.decode(state)
|
|
189
195
|
const r1 = c.uint.decode(state)
|
|
190
196
|
const r2 = c.fixed32.decode(state)
|
|
@@ -199,17 +205,17 @@ const encoding6 = {
|
|
|
199
205
|
|
|
200
206
|
// @core/signer
|
|
201
207
|
const encoding7 = {
|
|
202
|
-
preencode
|
|
208
|
+
preencode(state, m) {
|
|
203
209
|
encoding5.preencode(state, m.signature)
|
|
204
210
|
c.fixed32.preencode(state, m.namespace)
|
|
205
211
|
c.fixed32.preencode(state, m.publicKey)
|
|
206
212
|
},
|
|
207
|
-
encode
|
|
213
|
+
encode(state, m) {
|
|
208
214
|
encoding5.encode(state, m.signature)
|
|
209
215
|
c.fixed32.encode(state, m.namespace)
|
|
210
216
|
c.fixed32.encode(state, m.publicKey)
|
|
211
217
|
},
|
|
212
|
-
decode
|
|
218
|
+
decode(state) {
|
|
213
219
|
const r0 = encoding5.decode(state)
|
|
214
220
|
const r1 = c.fixed32.decode(state)
|
|
215
221
|
const r2 = c.fixed32.decode(state)
|
|
@@ -224,15 +230,15 @@ const encoding7 = {
|
|
|
224
230
|
|
|
225
231
|
// @core/prologue
|
|
226
232
|
const encoding8 = {
|
|
227
|
-
preencode
|
|
233
|
+
preencode(state, m) {
|
|
228
234
|
c.fixed32.preencode(state, m.hash)
|
|
229
235
|
c.uint.preencode(state, m.length)
|
|
230
236
|
},
|
|
231
|
-
encode
|
|
237
|
+
encode(state, m) {
|
|
232
238
|
c.fixed32.encode(state, m.hash)
|
|
233
239
|
c.uint.encode(state, m.length)
|
|
234
240
|
},
|
|
235
|
-
decode
|
|
241
|
+
decode(state) {
|
|
236
242
|
const r0 = c.fixed32.decode(state)
|
|
237
243
|
const r1 = c.uint.decode(state)
|
|
238
244
|
|
|
@@ -250,7 +256,7 @@ const encoding9_6 = c.array(c.fixed32)
|
|
|
250
256
|
|
|
251
257
|
// @core/manifest
|
|
252
258
|
const encoding9 = {
|
|
253
|
-
preencode
|
|
259
|
+
preencode(state, m) {
|
|
254
260
|
c.uint.preencode(state, m.version)
|
|
255
261
|
state.end++ // max flag is 8 so always one byte
|
|
256
262
|
encoding4.preencode(state, m.hash)
|
|
@@ -261,7 +267,7 @@ const encoding9 = {
|
|
|
261
267
|
if (m.linked) encoding9_6.preencode(state, m.linked)
|
|
262
268
|
if (m.userData) c.buffer.preencode(state, m.userData)
|
|
263
269
|
},
|
|
264
|
-
encode
|
|
270
|
+
encode(state, m) {
|
|
265
271
|
const flags =
|
|
266
272
|
(m.allowPatch ? 1 : 0) |
|
|
267
273
|
(m.prologue ? 2 : 0) |
|
|
@@ -278,7 +284,7 @@ const encoding9 = {
|
|
|
278
284
|
if (m.linked) encoding9_6.encode(state, m.linked)
|
|
279
285
|
if (m.userData) c.buffer.encode(state, m.userData)
|
|
280
286
|
},
|
|
281
|
-
decode
|
|
287
|
+
decode(state) {
|
|
282
288
|
const r0 = c.uint.decode(state)
|
|
283
289
|
const flags = c.uint.decode(state)
|
|
284
290
|
|
|
@@ -297,15 +303,15 @@ const encoding9 = {
|
|
|
297
303
|
|
|
298
304
|
// @core/keyPair
|
|
299
305
|
const encoding10 = {
|
|
300
|
-
preencode
|
|
306
|
+
preencode(state, m) {
|
|
301
307
|
c.buffer.preencode(state, m.publicKey)
|
|
302
308
|
c.buffer.preencode(state, m.secretKey)
|
|
303
309
|
},
|
|
304
|
-
encode
|
|
310
|
+
encode(state, m) {
|
|
305
311
|
c.buffer.encode(state, m.publicKey)
|
|
306
312
|
c.buffer.encode(state, m.secretKey)
|
|
307
313
|
},
|
|
308
|
-
decode
|
|
314
|
+
decode(state) {
|
|
309
315
|
const r0 = c.buffer.decode(state)
|
|
310
316
|
const r1 = c.buffer.decode(state)
|
|
311
317
|
|
|
@@ -321,7 +327,7 @@ const encoding11_2 = c.frame(encoding9)
|
|
|
321
327
|
|
|
322
328
|
// @core/auth
|
|
323
329
|
const encoding11 = {
|
|
324
|
-
preencode
|
|
330
|
+
preencode(state, m) {
|
|
325
331
|
c.fixed32.preencode(state, m.key)
|
|
326
332
|
c.fixed32.preencode(state, m.discoveryKey)
|
|
327
333
|
state.end++ // max flag is 4 so always one byte
|
|
@@ -330,7 +336,7 @@ const encoding11 = {
|
|
|
330
336
|
if (m.keyPair) encoding10.preencode(state, m.keyPair)
|
|
331
337
|
if (m.encryptionKey) c.buffer.preencode(state, m.encryptionKey)
|
|
332
338
|
},
|
|
333
|
-
encode
|
|
339
|
+
encode(state, m) {
|
|
334
340
|
const flags =
|
|
335
341
|
(m.manifest ? 1 : 0) |
|
|
336
342
|
(m.keyPair ? 2 : 0) |
|
|
@@ -344,7 +350,7 @@ const encoding11 = {
|
|
|
344
350
|
if (m.keyPair) encoding10.encode(state, m.keyPair)
|
|
345
351
|
if (m.encryptionKey) c.buffer.encode(state, m.encryptionKey)
|
|
346
352
|
},
|
|
347
|
-
decode
|
|
353
|
+
decode(state) {
|
|
348
354
|
const r0 = c.fixed32.decode(state)
|
|
349
355
|
const r1 = c.fixed32.decode(state)
|
|
350
356
|
const flags = c.uint.decode(state)
|
|
@@ -361,19 +367,19 @@ const encoding11 = {
|
|
|
361
367
|
|
|
362
368
|
// @core/head
|
|
363
369
|
const encoding12 = {
|
|
364
|
-
preencode
|
|
370
|
+
preencode(state, m) {
|
|
365
371
|
c.uint.preencode(state, m.fork)
|
|
366
372
|
c.uint.preencode(state, m.length)
|
|
367
373
|
c.fixed32.preencode(state, m.rootHash)
|
|
368
374
|
c.buffer.preencode(state, m.signature)
|
|
369
375
|
},
|
|
370
|
-
encode
|
|
376
|
+
encode(state, m) {
|
|
371
377
|
c.uint.encode(state, m.fork)
|
|
372
378
|
c.uint.encode(state, m.length)
|
|
373
379
|
c.fixed32.encode(state, m.rootHash)
|
|
374
380
|
c.buffer.encode(state, m.signature)
|
|
375
381
|
},
|
|
376
|
-
decode
|
|
382
|
+
decode(state) {
|
|
377
383
|
const r0 = c.uint.decode(state)
|
|
378
384
|
const r1 = c.uint.decode(state)
|
|
379
385
|
const r2 = c.fixed32.decode(state)
|
|
@@ -390,38 +396,43 @@ const encoding12 = {
|
|
|
390
396
|
|
|
391
397
|
// @core/hints
|
|
392
398
|
const encoding13 = {
|
|
393
|
-
preencode
|
|
394
|
-
state.end++ // max flag is
|
|
399
|
+
preencode(state, m) {
|
|
400
|
+
state.end++ // max flag is 2 so always one byte
|
|
395
401
|
|
|
396
402
|
if (m.contiguousLength) c.uint.preencode(state, m.contiguousLength)
|
|
403
|
+
if (m.remoteContiguousLength) c.uint.preencode(state, m.remoteContiguousLength)
|
|
397
404
|
},
|
|
398
|
-
encode
|
|
399
|
-
const flags =
|
|
405
|
+
encode(state, m) {
|
|
406
|
+
const flags =
|
|
407
|
+
(m.contiguousLength ? 1 : 0) |
|
|
408
|
+
(m.remoteContiguousLength ? 2 : 0)
|
|
400
409
|
|
|
401
410
|
c.uint.encode(state, flags)
|
|
402
411
|
|
|
403
412
|
if (m.contiguousLength) c.uint.encode(state, m.contiguousLength)
|
|
413
|
+
if (m.remoteContiguousLength) c.uint.encode(state, m.remoteContiguousLength)
|
|
404
414
|
},
|
|
405
|
-
decode
|
|
415
|
+
decode(state) {
|
|
406
416
|
const flags = c.uint.decode(state)
|
|
407
417
|
|
|
408
418
|
return {
|
|
409
|
-
contiguousLength: (flags & 1) !== 0 ? c.uint.decode(state) : 0
|
|
419
|
+
contiguousLength: (flags & 1) !== 0 ? c.uint.decode(state) : 0,
|
|
420
|
+
remoteContiguousLength: (flags & 2) !== 0 ? c.uint.decode(state) : 0
|
|
410
421
|
}
|
|
411
422
|
}
|
|
412
423
|
}
|
|
413
424
|
|
|
414
425
|
// @core/session
|
|
415
426
|
const encoding14 = {
|
|
416
|
-
preencode
|
|
427
|
+
preencode(state, m) {
|
|
417
428
|
c.string.preencode(state, m.name)
|
|
418
429
|
c.uint.preencode(state, m.dataPointer)
|
|
419
430
|
},
|
|
420
|
-
encode
|
|
431
|
+
encode(state, m) {
|
|
421
432
|
c.string.encode(state, m.name)
|
|
422
433
|
c.uint.encode(state, m.dataPointer)
|
|
423
434
|
},
|
|
424
|
-
decode
|
|
435
|
+
decode(state) {
|
|
425
436
|
const r0 = c.string.decode(state)
|
|
426
437
|
const r1 = c.uint.decode(state)
|
|
427
438
|
|
|
@@ -437,15 +448,15 @@ const encoding15 = c.array(encoding14)
|
|
|
437
448
|
|
|
438
449
|
// @core/dependency
|
|
439
450
|
const encoding16 = {
|
|
440
|
-
preencode
|
|
451
|
+
preencode(state, m) {
|
|
441
452
|
c.uint.preencode(state, m.dataPointer)
|
|
442
453
|
c.uint.preencode(state, m.length)
|
|
443
454
|
},
|
|
444
|
-
encode
|
|
455
|
+
encode(state, m) {
|
|
445
456
|
c.uint.encode(state, m.dataPointer)
|
|
446
457
|
c.uint.encode(state, m.length)
|
|
447
458
|
},
|
|
448
|
-
decode
|
|
459
|
+
decode(state) {
|
|
449
460
|
const r0 = c.uint.decode(state)
|
|
450
461
|
const r1 = c.uint.decode(state)
|
|
451
462
|
|
|
@@ -456,63 +467,84 @@ const encoding16 = {
|
|
|
456
467
|
}
|
|
457
468
|
}
|
|
458
469
|
|
|
459
|
-
function setVersion
|
|
470
|
+
function setVersion(v) {
|
|
460
471
|
version = v
|
|
461
472
|
}
|
|
462
473
|
|
|
463
|
-
function encode
|
|
474
|
+
function encode(name, value, v = VERSION) {
|
|
464
475
|
version = v
|
|
465
476
|
return c.encode(getEncoding(name), value)
|
|
466
477
|
}
|
|
467
478
|
|
|
468
|
-
function decode
|
|
479
|
+
function decode(name, buffer, v = VERSION) {
|
|
469
480
|
version = v
|
|
470
481
|
return c.decode(getEncoding(name), buffer)
|
|
471
482
|
}
|
|
472
483
|
|
|
473
|
-
function getEnum
|
|
484
|
+
function getEnum(name) {
|
|
474
485
|
switch (name) {
|
|
475
|
-
case '@core/hashes':
|
|
476
|
-
|
|
477
|
-
|
|
486
|
+
case '@core/hashes':
|
|
487
|
+
return encoding4_enum
|
|
488
|
+
case '@core/signatures':
|
|
489
|
+
return encoding5_enum
|
|
490
|
+
default:
|
|
491
|
+
throw new Error('Enum not found ' + name)
|
|
478
492
|
}
|
|
479
493
|
}
|
|
480
494
|
|
|
481
|
-
function getEncoding
|
|
495
|
+
function getEncoding(name) {
|
|
482
496
|
switch (name) {
|
|
483
|
-
case '@corestore/allocated':
|
|
484
|
-
|
|
485
|
-
case '@corestore/
|
|
486
|
-
|
|
487
|
-
case '@
|
|
488
|
-
|
|
489
|
-
case '@core
|
|
490
|
-
|
|
491
|
-
case '@core/
|
|
492
|
-
|
|
493
|
-
case '@core/
|
|
494
|
-
|
|
495
|
-
case '@core/
|
|
496
|
-
|
|
497
|
-
case '@core/
|
|
498
|
-
|
|
499
|
-
case '@core/
|
|
500
|
-
|
|
497
|
+
case '@corestore/allocated':
|
|
498
|
+
return encoding0
|
|
499
|
+
case '@corestore/head':
|
|
500
|
+
return encoding1
|
|
501
|
+
case '@corestore/alias':
|
|
502
|
+
return encoding2
|
|
503
|
+
case '@corestore/core':
|
|
504
|
+
return encoding3
|
|
505
|
+
case '@core/hashes':
|
|
506
|
+
return encoding4
|
|
507
|
+
case '@core/signatures':
|
|
508
|
+
return encoding5
|
|
509
|
+
case '@core/tree-node':
|
|
510
|
+
return encoding6
|
|
511
|
+
case '@core/signer':
|
|
512
|
+
return encoding7
|
|
513
|
+
case '@core/prologue':
|
|
514
|
+
return encoding8
|
|
515
|
+
case '@core/manifest':
|
|
516
|
+
return encoding9
|
|
517
|
+
case '@core/keyPair':
|
|
518
|
+
return encoding10
|
|
519
|
+
case '@core/auth':
|
|
520
|
+
return encoding11
|
|
521
|
+
case '@core/head':
|
|
522
|
+
return encoding12
|
|
523
|
+
case '@core/hints':
|
|
524
|
+
return encoding13
|
|
525
|
+
case '@core/session':
|
|
526
|
+
return encoding14
|
|
527
|
+
case '@core/sessions':
|
|
528
|
+
return encoding15
|
|
529
|
+
case '@core/dependency':
|
|
530
|
+
return encoding16
|
|
531
|
+
default:
|
|
532
|
+
throw new Error('Encoder not found ' + name)
|
|
501
533
|
}
|
|
502
534
|
}
|
|
503
535
|
|
|
504
|
-
function getStruct
|
|
536
|
+
function getStruct(name, v = VERSION) {
|
|
505
537
|
const enc = getEncoding(name)
|
|
506
538
|
return {
|
|
507
|
-
preencode
|
|
539
|
+
preencode(state, m) {
|
|
508
540
|
version = v
|
|
509
541
|
enc.preencode(state, m)
|
|
510
542
|
},
|
|
511
|
-
encode
|
|
543
|
+
encode(state, m) {
|
|
512
544
|
version = v
|
|
513
545
|
enc.encode(state, m)
|
|
514
546
|
},
|
|
515
|
-
decode
|
|
547
|
+
decode(state) {
|
|
516
548
|
version = v
|
|
517
549
|
return enc.decode(state)
|
|
518
550
|
}
|
|
@@ -521,4 +553,13 @@ function getStruct (name, v = VERSION) {
|
|
|
521
553
|
|
|
522
554
|
const resolveStruct = getStruct // compat
|
|
523
555
|
|
|
524
|
-
module.exports = {
|
|
556
|
+
module.exports = {
|
|
557
|
+
resolveStruct,
|
|
558
|
+
getStruct,
|
|
559
|
+
getEnum,
|
|
560
|
+
getEncoding,
|
|
561
|
+
encode,
|
|
562
|
+
decode,
|
|
563
|
+
setVersion,
|
|
564
|
+
version
|
|
565
|
+
}
|