hypercore 11.16.1 → 11.17.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/README.md +31 -29
- package/index.js +212 -127
- package/lib/audit.js +18 -7
- package/lib/bit-interlude.js +17 -7
- package/lib/bitfield.js +73 -53
- package/lib/caps.js +5 -1
- package/lib/copy-prologue.js +14 -10
- package/lib/core.js +113 -59
- package/lib/default-encryption.js +14 -28
- package/lib/download.js +10 -10
- package/lib/fully-remote-proof.js +3 -3
- package/lib/hotswap-queue.js +5 -5
- package/lib/info.js +4 -4
- package/lib/merkle-tree.js +143 -104
- package/lib/messages.js +163 -143
- package/lib/multisig.js +19 -12
- package/lib/mutex.js +9 -7
- package/lib/receiver-queue.js +6 -6
- package/lib/remote-bitfield.js +30 -32
- package/lib/replicator.js +383 -265
- package/lib/session-state.js +112 -75
- package/lib/streams.js +16 -16
- package/lib/verifier.js +69 -43
- package/package.json +5 -3
package/lib/messages.js
CHANGED
|
@@ -12,10 +12,10 @@ const MANIFEST_LINKED = 0b00000100
|
|
|
12
12
|
const MANIFEST_USER_DATA = 0b00001000
|
|
13
13
|
|
|
14
14
|
const hashes = {
|
|
15
|
-
preencode
|
|
15
|
+
preencode(state, m) {
|
|
16
16
|
state.end++ // small uint
|
|
17
17
|
},
|
|
18
|
-
encode
|
|
18
|
+
encode(state, m) {
|
|
19
19
|
if (m === 'blake2b') {
|
|
20
20
|
c.uint.encode(state, 0)
|
|
21
21
|
return
|
|
@@ -23,7 +23,7 @@ const hashes = {
|
|
|
23
23
|
|
|
24
24
|
throw new Error('Unknown hash: ' + m)
|
|
25
25
|
},
|
|
26
|
-
decode
|
|
26
|
+
decode(state) {
|
|
27
27
|
const n = c.uint.decode(state)
|
|
28
28
|
if (n === 0) return 'blake2b'
|
|
29
29
|
throw new Error('Unknown hash id: ' + n)
|
|
@@ -31,10 +31,10 @@ const hashes = {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
const signatures = {
|
|
34
|
-
preencode
|
|
34
|
+
preencode(state, m) {
|
|
35
35
|
state.end++ // small uint
|
|
36
36
|
},
|
|
37
|
-
encode
|
|
37
|
+
encode(state, m) {
|
|
38
38
|
if (m === 'ed25519') {
|
|
39
39
|
c.uint.encode(state, 0)
|
|
40
40
|
return
|
|
@@ -42,7 +42,7 @@ const signatures = {
|
|
|
42
42
|
|
|
43
43
|
throw new Error('Unknown signature: ' + m)
|
|
44
44
|
},
|
|
45
|
-
decode
|
|
45
|
+
decode(state) {
|
|
46
46
|
const n = c.uint.decode(state)
|
|
47
47
|
if (n === 0) return 'ed25519'
|
|
48
48
|
throw new Error('Unknown signature id: ' + n)
|
|
@@ -50,17 +50,17 @@ const signatures = {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
const signer = {
|
|
53
|
-
preencode
|
|
53
|
+
preencode(state, m) {
|
|
54
54
|
signatures.preencode(state, m.signature)
|
|
55
55
|
c.fixed32.preencode(state, m.namespace)
|
|
56
56
|
c.fixed32.preencode(state, m.publicKey)
|
|
57
57
|
},
|
|
58
|
-
encode
|
|
58
|
+
encode(state, m) {
|
|
59
59
|
signatures.encode(state, m.signature)
|
|
60
60
|
c.fixed32.encode(state, m.namespace)
|
|
61
61
|
c.fixed32.encode(state, m.publicKey)
|
|
62
62
|
},
|
|
63
|
-
decode
|
|
63
|
+
decode(state) {
|
|
64
64
|
return {
|
|
65
65
|
signature: signatures.decode(state),
|
|
66
66
|
namespace: c.fixed32.decode(state),
|
|
@@ -72,15 +72,15 @@ const signer = {
|
|
|
72
72
|
const signerArray = c.array(signer)
|
|
73
73
|
|
|
74
74
|
const prologue = {
|
|
75
|
-
preencode
|
|
75
|
+
preencode(state, p) {
|
|
76
76
|
c.fixed32.preencode(state, p.hash)
|
|
77
77
|
c.uint.preencode(state, p.length)
|
|
78
78
|
},
|
|
79
|
-
encode
|
|
79
|
+
encode(state, p) {
|
|
80
80
|
c.fixed32.encode(state, p.hash)
|
|
81
81
|
c.uint.encode(state, p.length)
|
|
82
82
|
},
|
|
83
|
-
decode
|
|
83
|
+
decode(state) {
|
|
84
84
|
return {
|
|
85
85
|
hash: c.fixed32.decode(state),
|
|
86
86
|
length: c.uint.decode(state)
|
|
@@ -89,7 +89,7 @@ const prologue = {
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
const manifestv0 = {
|
|
92
|
-
preencode
|
|
92
|
+
preencode(state, m) {
|
|
93
93
|
hashes.preencode(state, m.hash)
|
|
94
94
|
state.end++ // type
|
|
95
95
|
|
|
@@ -106,7 +106,7 @@ const manifestv0 = {
|
|
|
106
106
|
signerArray.preencode(state, m.signers)
|
|
107
107
|
}
|
|
108
108
|
},
|
|
109
|
-
encode
|
|
109
|
+
encode(state, m) {
|
|
110
110
|
hashes.encode(state, m.hash)
|
|
111
111
|
|
|
112
112
|
if (m.prologue && m.signers.length === 0) {
|
|
@@ -125,7 +125,7 @@ const manifestv0 = {
|
|
|
125
125
|
signerArray.encode(state, m.signers)
|
|
126
126
|
}
|
|
127
127
|
},
|
|
128
|
-
decode
|
|
128
|
+
decode(state) {
|
|
129
129
|
const hash = hashes.decode(state)
|
|
130
130
|
const type = c.uint.decode(state)
|
|
131
131
|
|
|
@@ -177,8 +177,8 @@ const manifestv0 = {
|
|
|
177
177
|
|
|
178
178
|
const fixed32Array = c.array(c.fixed32)
|
|
179
179
|
|
|
180
|
-
const manifest = exports.manifest = {
|
|
181
|
-
preencode
|
|
180
|
+
const manifest = (exports.manifest = {
|
|
181
|
+
preencode(state, m) {
|
|
182
182
|
state.end++ // version
|
|
183
183
|
|
|
184
184
|
if (m.version === 0) return manifestv0.preencode(state, m)
|
|
@@ -193,7 +193,7 @@ const manifest = exports.manifest = {
|
|
|
193
193
|
if (m.linked) fixed32Array.preencode(state, m.linked)
|
|
194
194
|
if (m.userData) c.buffer.preencode(state, m.userData)
|
|
195
195
|
},
|
|
196
|
-
encode
|
|
196
|
+
encode(state, m) {
|
|
197
197
|
c.uint.encode(state, m.version)
|
|
198
198
|
|
|
199
199
|
if (m.version === 0) return manifestv0.encode(state, m)
|
|
@@ -214,7 +214,7 @@ const manifest = exports.manifest = {
|
|
|
214
214
|
if (m.linked) fixed32Array.encode(state, m.linked)
|
|
215
215
|
if (m.userData) c.buffer.encode(state, m.userData)
|
|
216
216
|
},
|
|
217
|
-
decode
|
|
217
|
+
decode(state) {
|
|
218
218
|
const version = c.uint.decode(state)
|
|
219
219
|
|
|
220
220
|
if (version === 0) return manifestv0.decode(state)
|
|
@@ -241,20 +241,20 @@ const manifest = exports.manifest = {
|
|
|
241
241
|
userData: hasUserData ? c.buffer.decode(state) : null
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
|
-
}
|
|
244
|
+
})
|
|
245
245
|
|
|
246
246
|
const node = {
|
|
247
|
-
preencode
|
|
247
|
+
preencode(state, n) {
|
|
248
248
|
c.uint.preencode(state, n.index)
|
|
249
249
|
c.uint.preencode(state, n.size)
|
|
250
250
|
c.fixed32.preencode(state, n.hash)
|
|
251
251
|
},
|
|
252
|
-
encode
|
|
252
|
+
encode(state, n) {
|
|
253
253
|
c.uint.encode(state, n.index)
|
|
254
254
|
c.uint.encode(state, n.size)
|
|
255
255
|
c.fixed32.encode(state, n.hash)
|
|
256
256
|
},
|
|
257
|
-
decode
|
|
257
|
+
decode(state) {
|
|
258
258
|
return {
|
|
259
259
|
index: c.uint.decode(state),
|
|
260
260
|
size: c.uint.decode(state),
|
|
@@ -265,18 +265,18 @@ const node = {
|
|
|
265
265
|
|
|
266
266
|
const nodeArray = c.array(node)
|
|
267
267
|
|
|
268
|
-
const wire = exports.wire = {}
|
|
268
|
+
const wire = (exports.wire = {})
|
|
269
269
|
|
|
270
270
|
wire.handshake = {
|
|
271
|
-
preencode
|
|
271
|
+
preencode(state, m) {
|
|
272
272
|
c.uint.preencode(state, 1)
|
|
273
273
|
c.fixed32.preencode(state, m.capability)
|
|
274
274
|
},
|
|
275
|
-
encode
|
|
275
|
+
encode(state, m) {
|
|
276
276
|
c.uint.encode(state, m.seeks ? 1 : 0)
|
|
277
277
|
c.fixed32.encode(state, m.capability)
|
|
278
278
|
},
|
|
279
|
-
decode
|
|
279
|
+
decode(state) {
|
|
280
280
|
const flags = c.uint.decode(state)
|
|
281
281
|
return {
|
|
282
282
|
seeks: (flags & 1) !== 0,
|
|
@@ -286,15 +286,15 @@ wire.handshake = {
|
|
|
286
286
|
}
|
|
287
287
|
|
|
288
288
|
const requestBlock = {
|
|
289
|
-
preencode
|
|
289
|
+
preencode(state, b) {
|
|
290
290
|
c.uint.preencode(state, b.index)
|
|
291
291
|
c.uint.preencode(state, b.nodes)
|
|
292
292
|
},
|
|
293
|
-
encode
|
|
293
|
+
encode(state, b) {
|
|
294
294
|
c.uint.encode(state, b.index)
|
|
295
295
|
c.uint.encode(state, b.nodes)
|
|
296
296
|
},
|
|
297
|
-
decode
|
|
297
|
+
decode(state) {
|
|
298
298
|
return {
|
|
299
299
|
index: c.uint.decode(state),
|
|
300
300
|
nodes: c.uint.decode(state)
|
|
@@ -303,15 +303,15 @@ const requestBlock = {
|
|
|
303
303
|
}
|
|
304
304
|
|
|
305
305
|
const requestSeek = {
|
|
306
|
-
preencode
|
|
306
|
+
preencode(state, s) {
|
|
307
307
|
c.uint.preencode(state, s.bytes)
|
|
308
308
|
c.uint.preencode(state, s.padding)
|
|
309
309
|
},
|
|
310
|
-
encode
|
|
310
|
+
encode(state, s) {
|
|
311
311
|
c.uint.encode(state, s.bytes)
|
|
312
312
|
c.uint.encode(state, s.padding)
|
|
313
313
|
},
|
|
314
|
-
decode
|
|
314
|
+
decode(state) {
|
|
315
315
|
return {
|
|
316
316
|
bytes: c.uint.decode(state),
|
|
317
317
|
padding: c.uint.decode(state)
|
|
@@ -320,15 +320,15 @@ const requestSeek = {
|
|
|
320
320
|
}
|
|
321
321
|
|
|
322
322
|
const requestUpgrade = {
|
|
323
|
-
preencode
|
|
323
|
+
preencode(state, u) {
|
|
324
324
|
c.uint.preencode(state, u.start)
|
|
325
325
|
c.uint.preencode(state, u.length)
|
|
326
326
|
},
|
|
327
|
-
encode
|
|
327
|
+
encode(state, u) {
|
|
328
328
|
c.uint.encode(state, u.start)
|
|
329
329
|
c.uint.encode(state, u.length)
|
|
330
330
|
},
|
|
331
|
-
decode
|
|
331
|
+
decode(state) {
|
|
332
332
|
return {
|
|
333
333
|
start: c.uint.decode(state),
|
|
334
334
|
length: c.uint.decode(state)
|
|
@@ -337,7 +337,7 @@ const requestUpgrade = {
|
|
|
337
337
|
}
|
|
338
338
|
|
|
339
339
|
wire.request = {
|
|
340
|
-
preencode
|
|
340
|
+
preencode(state, m) {
|
|
341
341
|
state.end++ // flags
|
|
342
342
|
c.uint.preencode(state, m.id)
|
|
343
343
|
c.uint.preencode(state, m.fork)
|
|
@@ -348,8 +348,14 @@ wire.request = {
|
|
|
348
348
|
if (m.upgrade) requestUpgrade.preencode(state, m.upgrade)
|
|
349
349
|
if (m.priority) c.uint.preencode(state, m.priority)
|
|
350
350
|
},
|
|
351
|
-
encode
|
|
352
|
-
const flags =
|
|
351
|
+
encode(state, m) {
|
|
352
|
+
const flags =
|
|
353
|
+
(m.block ? 1 : 0) |
|
|
354
|
+
(m.hash ? 2 : 0) |
|
|
355
|
+
(m.seek ? 4 : 0) |
|
|
356
|
+
(m.upgrade ? 8 : 0) |
|
|
357
|
+
(m.manifest ? 16 : 0) |
|
|
358
|
+
(m.priority ? 32 : 0)
|
|
353
359
|
|
|
354
360
|
c.uint.encode(state, flags)
|
|
355
361
|
c.uint.encode(state, m.id)
|
|
@@ -361,7 +367,7 @@ wire.request = {
|
|
|
361
367
|
if (m.upgrade) requestUpgrade.encode(state, m.upgrade)
|
|
362
368
|
if (m.priority) c.uint.encode(state, m.priority)
|
|
363
369
|
},
|
|
364
|
-
decode
|
|
370
|
+
decode(state) {
|
|
365
371
|
const flags = c.uint.decode(state)
|
|
366
372
|
|
|
367
373
|
return {
|
|
@@ -378,13 +384,13 @@ wire.request = {
|
|
|
378
384
|
}
|
|
379
385
|
|
|
380
386
|
wire.cancel = {
|
|
381
|
-
preencode
|
|
387
|
+
preencode(state, m) {
|
|
382
388
|
c.uint.preencode(state, m.request)
|
|
383
389
|
},
|
|
384
|
-
encode
|
|
390
|
+
encode(state, m) {
|
|
385
391
|
c.uint.encode(state, m.request)
|
|
386
392
|
},
|
|
387
|
-
decode
|
|
393
|
+
decode(state, m) {
|
|
388
394
|
return {
|
|
389
395
|
request: c.uint.decode(state)
|
|
390
396
|
}
|
|
@@ -392,21 +398,21 @@ wire.cancel = {
|
|
|
392
398
|
}
|
|
393
399
|
|
|
394
400
|
const dataUpgrade = {
|
|
395
|
-
preencode
|
|
401
|
+
preencode(state, u) {
|
|
396
402
|
c.uint.preencode(state, u.start)
|
|
397
403
|
c.uint.preencode(state, u.length)
|
|
398
404
|
nodeArray.preencode(state, u.nodes)
|
|
399
405
|
nodeArray.preencode(state, u.additionalNodes)
|
|
400
406
|
c.buffer.preencode(state, u.signature)
|
|
401
407
|
},
|
|
402
|
-
encode
|
|
408
|
+
encode(state, u) {
|
|
403
409
|
c.uint.encode(state, u.start)
|
|
404
410
|
c.uint.encode(state, u.length)
|
|
405
411
|
nodeArray.encode(state, u.nodes)
|
|
406
412
|
nodeArray.encode(state, u.additionalNodes)
|
|
407
413
|
c.buffer.encode(state, u.signature)
|
|
408
414
|
},
|
|
409
|
-
decode
|
|
415
|
+
decode(state) {
|
|
410
416
|
return {
|
|
411
417
|
start: c.uint.decode(state),
|
|
412
418
|
length: c.uint.decode(state),
|
|
@@ -418,15 +424,15 @@ const dataUpgrade = {
|
|
|
418
424
|
}
|
|
419
425
|
|
|
420
426
|
const dataSeek = {
|
|
421
|
-
preencode
|
|
427
|
+
preencode(state, s) {
|
|
422
428
|
c.uint.preencode(state, s.bytes)
|
|
423
429
|
nodeArray.preencode(state, s.nodes)
|
|
424
430
|
},
|
|
425
|
-
encode
|
|
431
|
+
encode(state, s) {
|
|
426
432
|
c.uint.encode(state, s.bytes)
|
|
427
433
|
nodeArray.encode(state, s.nodes)
|
|
428
434
|
},
|
|
429
|
-
decode
|
|
435
|
+
decode(state) {
|
|
430
436
|
return {
|
|
431
437
|
bytes: c.uint.decode(state),
|
|
432
438
|
nodes: nodeArray.decode(state)
|
|
@@ -435,17 +441,17 @@ const dataSeek = {
|
|
|
435
441
|
}
|
|
436
442
|
|
|
437
443
|
const dataBlock = {
|
|
438
|
-
preencode
|
|
444
|
+
preencode(state, b) {
|
|
439
445
|
c.uint.preencode(state, b.index)
|
|
440
446
|
c.buffer.preencode(state, b.value)
|
|
441
447
|
nodeArray.preencode(state, b.nodes)
|
|
442
448
|
},
|
|
443
|
-
encode
|
|
449
|
+
encode(state, b) {
|
|
444
450
|
c.uint.encode(state, b.index)
|
|
445
451
|
c.buffer.encode(state, b.value)
|
|
446
452
|
nodeArray.encode(state, b.nodes)
|
|
447
453
|
},
|
|
448
|
-
decode
|
|
454
|
+
decode(state) {
|
|
449
455
|
return {
|
|
450
456
|
index: c.uint.decode(state),
|
|
451
457
|
value: c.buffer.decode(state) || EMPTY,
|
|
@@ -455,15 +461,15 @@ const dataBlock = {
|
|
|
455
461
|
}
|
|
456
462
|
|
|
457
463
|
const dataHash = {
|
|
458
|
-
preencode
|
|
464
|
+
preencode(state, b) {
|
|
459
465
|
c.uint.preencode(state, b.index)
|
|
460
466
|
nodeArray.preencode(state, b.nodes)
|
|
461
467
|
},
|
|
462
|
-
encode
|
|
468
|
+
encode(state, b) {
|
|
463
469
|
c.uint.encode(state, b.index)
|
|
464
470
|
nodeArray.encode(state, b.nodes)
|
|
465
471
|
},
|
|
466
|
-
decode
|
|
472
|
+
decode(state) {
|
|
467
473
|
return {
|
|
468
474
|
index: c.uint.decode(state),
|
|
469
475
|
nodes: nodeArray.decode(state)
|
|
@@ -472,7 +478,7 @@ const dataHash = {
|
|
|
472
478
|
}
|
|
473
479
|
|
|
474
480
|
wire.data = {
|
|
475
|
-
preencode
|
|
481
|
+
preencode(state, m) {
|
|
476
482
|
state.end++ // flags
|
|
477
483
|
c.uint.preencode(state, m.request)
|
|
478
484
|
c.uint.preencode(state, m.fork)
|
|
@@ -483,8 +489,13 @@ wire.data = {
|
|
|
483
489
|
if (m.upgrade) dataUpgrade.preencode(state, m.upgrade)
|
|
484
490
|
if (m.manifest) manifest.preencode(state, m.manifest)
|
|
485
491
|
},
|
|
486
|
-
encode
|
|
487
|
-
const flags =
|
|
492
|
+
encode(state, m) {
|
|
493
|
+
const flags =
|
|
494
|
+
(m.block ? 1 : 0) |
|
|
495
|
+
(m.hash ? 2 : 0) |
|
|
496
|
+
(m.seek ? 4 : 0) |
|
|
497
|
+
(m.upgrade ? 8 : 0) |
|
|
498
|
+
(m.manifest ? 16 : 0)
|
|
488
499
|
|
|
489
500
|
c.uint.encode(state, flags)
|
|
490
501
|
c.uint.encode(state, m.request)
|
|
@@ -496,7 +507,7 @@ wire.data = {
|
|
|
496
507
|
if (m.upgrade) dataUpgrade.encode(state, m.upgrade)
|
|
497
508
|
if (m.manifest) manifest.encode(state, m.manifest)
|
|
498
509
|
},
|
|
499
|
-
decode
|
|
510
|
+
decode(state) {
|
|
500
511
|
const flags = c.uint.decode(state)
|
|
501
512
|
|
|
502
513
|
return {
|
|
@@ -512,17 +523,17 @@ wire.data = {
|
|
|
512
523
|
}
|
|
513
524
|
|
|
514
525
|
wire.noData = {
|
|
515
|
-
preencode
|
|
526
|
+
preencode(state, m) {
|
|
516
527
|
c.uint.preencode(state, m.request)
|
|
517
528
|
c.uint.preencode(state, m.reason ? 1 : 0)
|
|
518
529
|
if (m.reason) c.uint.preencode(state, m.reason)
|
|
519
530
|
},
|
|
520
|
-
encode
|
|
531
|
+
encode(state, m) {
|
|
521
532
|
c.uint.encode(state, m.request)
|
|
522
533
|
c.uint.encode(state, m.reason ? 1 : 0)
|
|
523
534
|
if (m.reason) c.uint.encode(state, m.reason)
|
|
524
535
|
},
|
|
525
|
-
decode
|
|
536
|
+
decode(state, m) {
|
|
526
537
|
const request = c.uint.decode(state)
|
|
527
538
|
const flags = state.start < state.end ? c.uint.decode(state) : 0
|
|
528
539
|
return {
|
|
@@ -533,15 +544,15 @@ wire.noData = {
|
|
|
533
544
|
}
|
|
534
545
|
|
|
535
546
|
wire.want = {
|
|
536
|
-
preencode
|
|
547
|
+
preencode(state, m) {
|
|
537
548
|
c.uint.preencode(state, m.start)
|
|
538
549
|
c.uint.preencode(state, m.length)
|
|
539
550
|
},
|
|
540
|
-
encode
|
|
551
|
+
encode(state, m) {
|
|
541
552
|
c.uint.encode(state, m.start)
|
|
542
553
|
c.uint.encode(state, m.length)
|
|
543
554
|
},
|
|
544
|
-
decode
|
|
555
|
+
decode(state) {
|
|
545
556
|
return {
|
|
546
557
|
start: c.uint.decode(state),
|
|
547
558
|
length: c.uint.decode(state)
|
|
@@ -550,15 +561,15 @@ wire.want = {
|
|
|
550
561
|
}
|
|
551
562
|
|
|
552
563
|
wire.unwant = {
|
|
553
|
-
preencode
|
|
564
|
+
preencode(state, m) {
|
|
554
565
|
c.uint.preencode(state, m.start)
|
|
555
566
|
c.uint.preencode(state, m.length)
|
|
556
567
|
},
|
|
557
|
-
encode
|
|
568
|
+
encode(state, m) {
|
|
558
569
|
c.uint.encode(state, m.start)
|
|
559
570
|
c.uint.encode(state, m.length)
|
|
560
571
|
},
|
|
561
|
-
decode
|
|
572
|
+
decode(state, m) {
|
|
562
573
|
return {
|
|
563
574
|
start: c.uint.decode(state),
|
|
564
575
|
length: c.uint.decode(state)
|
|
@@ -567,17 +578,17 @@ wire.unwant = {
|
|
|
567
578
|
}
|
|
568
579
|
|
|
569
580
|
wire.range = {
|
|
570
|
-
preencode
|
|
581
|
+
preencode(state, m) {
|
|
571
582
|
state.end++ // flags
|
|
572
583
|
c.uint.preencode(state, m.start)
|
|
573
584
|
if (m.length !== 1) c.uint.preencode(state, m.length)
|
|
574
585
|
},
|
|
575
|
-
encode
|
|
586
|
+
encode(state, m) {
|
|
576
587
|
c.uint.encode(state, (m.drop ? 1 : 0) | (m.length === 1 ? 2 : 0))
|
|
577
588
|
c.uint.encode(state, m.start)
|
|
578
589
|
if (m.length !== 1) c.uint.encode(state, m.length)
|
|
579
590
|
},
|
|
580
|
-
decode
|
|
591
|
+
decode(state) {
|
|
581
592
|
const flags = c.uint.decode(state)
|
|
582
593
|
|
|
583
594
|
return {
|
|
@@ -589,15 +600,15 @@ wire.range = {
|
|
|
589
600
|
}
|
|
590
601
|
|
|
591
602
|
wire.bitfield = {
|
|
592
|
-
preencode
|
|
603
|
+
preencode(state, m) {
|
|
593
604
|
c.uint.preencode(state, m.start)
|
|
594
605
|
c.uint32array.preencode(state, m.bitfield)
|
|
595
606
|
},
|
|
596
|
-
encode
|
|
607
|
+
encode(state, m) {
|
|
597
608
|
c.uint.encode(state, m.start)
|
|
598
609
|
c.uint32array.encode(state, m.bitfield)
|
|
599
610
|
},
|
|
600
|
-
decode
|
|
611
|
+
decode(state, m) {
|
|
601
612
|
return {
|
|
602
613
|
start: c.uint.decode(state),
|
|
603
614
|
bitfield: c.uint32array.decode(state)
|
|
@@ -606,19 +617,25 @@ wire.bitfield = {
|
|
|
606
617
|
}
|
|
607
618
|
|
|
608
619
|
wire.sync = {
|
|
609
|
-
preencode
|
|
620
|
+
preencode(state, m) {
|
|
610
621
|
state.end++ // flags
|
|
611
622
|
c.uint.preencode(state, m.fork)
|
|
612
623
|
c.uint.preencode(state, m.length)
|
|
613
624
|
c.uint.preencode(state, m.remoteLength)
|
|
614
625
|
},
|
|
615
|
-
encode
|
|
616
|
-
c.uint.encode(
|
|
626
|
+
encode(state, m) {
|
|
627
|
+
c.uint.encode(
|
|
628
|
+
state,
|
|
629
|
+
(m.canUpgrade ? 1 : 0) |
|
|
630
|
+
(m.uploading ? 2 : 0) |
|
|
631
|
+
(m.downloading ? 4 : 0) |
|
|
632
|
+
(m.hasManifest ? 8 : 0)
|
|
633
|
+
)
|
|
617
634
|
c.uint.encode(state, m.fork)
|
|
618
635
|
c.uint.encode(state, m.length)
|
|
619
636
|
c.uint.encode(state, m.remoteLength)
|
|
620
637
|
},
|
|
621
|
-
decode
|
|
638
|
+
decode(state) {
|
|
622
639
|
const flags = c.uint.decode(state)
|
|
623
640
|
|
|
624
641
|
return {
|
|
@@ -634,17 +651,17 @@ wire.sync = {
|
|
|
634
651
|
}
|
|
635
652
|
|
|
636
653
|
wire.reorgHint = {
|
|
637
|
-
preencode
|
|
654
|
+
preencode(state, m) {
|
|
638
655
|
c.uint.preencode(state, m.from)
|
|
639
656
|
c.uint.preencode(state, m.to)
|
|
640
657
|
c.uint.preencode(state, m.ancestors)
|
|
641
658
|
},
|
|
642
|
-
encode
|
|
659
|
+
encode(state, m) {
|
|
643
660
|
c.uint.encode(state, m.from)
|
|
644
661
|
c.uint.encode(state, m.to)
|
|
645
662
|
c.uint.encode(state, m.ancestors)
|
|
646
663
|
},
|
|
647
|
-
decode
|
|
664
|
+
decode(state) {
|
|
648
665
|
return {
|
|
649
666
|
from: c.uint.encode(state),
|
|
650
667
|
to: c.uint.encode(state),
|
|
@@ -654,15 +671,15 @@ wire.reorgHint = {
|
|
|
654
671
|
}
|
|
655
672
|
|
|
656
673
|
wire.extension = {
|
|
657
|
-
preencode
|
|
674
|
+
preencode(state, m) {
|
|
658
675
|
c.string.preencode(state, m.name)
|
|
659
676
|
c.raw.preencode(state, m.message)
|
|
660
677
|
},
|
|
661
|
-
encode
|
|
678
|
+
encode(state, m) {
|
|
662
679
|
c.string.encode(state, m.name)
|
|
663
680
|
c.raw.encode(state, m.message)
|
|
664
681
|
},
|
|
665
|
-
decode
|
|
682
|
+
decode(state) {
|
|
666
683
|
return {
|
|
667
684
|
name: c.string.decode(state),
|
|
668
685
|
message: c.raw.decode(state)
|
|
@@ -671,15 +688,15 @@ wire.extension = {
|
|
|
671
688
|
}
|
|
672
689
|
|
|
673
690
|
const keyValue = {
|
|
674
|
-
preencode
|
|
691
|
+
preencode(state, p) {
|
|
675
692
|
c.string.preencode(state, p.key)
|
|
676
693
|
c.buffer.preencode(state, p.value)
|
|
677
694
|
},
|
|
678
|
-
encode
|
|
695
|
+
encode(state, p) {
|
|
679
696
|
c.string.encode(state, p.key)
|
|
680
697
|
c.buffer.encode(state, p.value)
|
|
681
698
|
},
|
|
682
|
-
decode
|
|
699
|
+
decode(state) {
|
|
683
700
|
return {
|
|
684
701
|
key: c.string.decode(state),
|
|
685
702
|
value: c.buffer.decode(state)
|
|
@@ -688,19 +705,19 @@ const keyValue = {
|
|
|
688
705
|
}
|
|
689
706
|
|
|
690
707
|
const treeUpgrade = {
|
|
691
|
-
preencode
|
|
708
|
+
preencode(state, u) {
|
|
692
709
|
c.uint.preencode(state, u.fork)
|
|
693
710
|
c.uint.preencode(state, u.ancestors)
|
|
694
711
|
c.uint.preencode(state, u.length)
|
|
695
712
|
c.buffer.preencode(state, u.signature)
|
|
696
713
|
},
|
|
697
|
-
encode
|
|
714
|
+
encode(state, u) {
|
|
698
715
|
c.uint.encode(state, u.fork)
|
|
699
716
|
c.uint.encode(state, u.ancestors)
|
|
700
717
|
c.uint.encode(state, u.length)
|
|
701
718
|
c.buffer.encode(state, u.signature)
|
|
702
719
|
},
|
|
703
|
-
decode
|
|
720
|
+
decode(state) {
|
|
704
721
|
return {
|
|
705
722
|
fork: c.uint.decode(state),
|
|
706
723
|
ancestors: c.uint.decode(state),
|
|
@@ -710,18 +727,19 @@ const treeUpgrade = {
|
|
|
710
727
|
}
|
|
711
728
|
}
|
|
712
729
|
|
|
713
|
-
const bitfieldUpdate = {
|
|
714
|
-
|
|
730
|
+
const bitfieldUpdate = {
|
|
731
|
+
// TODO: can maybe be folded into a HAVE later on with the most recent spec
|
|
732
|
+
preencode(state, b) {
|
|
715
733
|
state.end++ // flags
|
|
716
734
|
c.uint.preencode(state, b.start)
|
|
717
735
|
c.uint.preencode(state, b.length)
|
|
718
736
|
},
|
|
719
|
-
encode
|
|
737
|
+
encode(state, b) {
|
|
720
738
|
state.buffer[state.start++] = b.drop ? 1 : 0
|
|
721
739
|
c.uint.encode(state, b.start)
|
|
722
740
|
c.uint.encode(state, b.length)
|
|
723
741
|
},
|
|
724
|
-
decode
|
|
742
|
+
decode(state) {
|
|
725
743
|
const flags = c.uint.decode(state)
|
|
726
744
|
return {
|
|
727
745
|
drop: (flags & 1) !== 0,
|
|
@@ -731,17 +749,17 @@ const bitfieldUpdate = { // TODO: can maybe be folded into a HAVE later on with
|
|
|
731
749
|
}
|
|
732
750
|
}
|
|
733
751
|
|
|
734
|
-
const oplog = exports.oplog = {}
|
|
752
|
+
const oplog = (exports.oplog = {})
|
|
735
753
|
|
|
736
754
|
oplog.entry = {
|
|
737
|
-
preencode
|
|
755
|
+
preencode(state, m) {
|
|
738
756
|
state.end++ // flags
|
|
739
757
|
if (m.userData) keyValue.preencode(state, m.userData)
|
|
740
758
|
if (m.treeNodes) nodeArray.preencode(state, m.treeNodes)
|
|
741
759
|
if (m.treeUpgrade) treeUpgrade.preencode(state, m.treeUpgrade)
|
|
742
760
|
if (m.bitfield) bitfieldUpdate.preencode(state, m.bitfield)
|
|
743
761
|
},
|
|
744
|
-
encode
|
|
762
|
+
encode(state, m) {
|
|
745
763
|
const s = state.start++
|
|
746
764
|
let flags = 0
|
|
747
765
|
|
|
@@ -764,7 +782,7 @@ oplog.entry = {
|
|
|
764
782
|
|
|
765
783
|
state.buffer[s] = flags
|
|
766
784
|
},
|
|
767
|
-
decode
|
|
785
|
+
decode(state) {
|
|
768
786
|
const flags = c.uint.decode(state)
|
|
769
787
|
return {
|
|
770
788
|
userData: (flags & 1) !== 0 ? keyValue.decode(state) : null,
|
|
@@ -776,15 +794,15 @@ oplog.entry = {
|
|
|
776
794
|
}
|
|
777
795
|
|
|
778
796
|
const keyPair = {
|
|
779
|
-
preencode
|
|
797
|
+
preencode(state, kp) {
|
|
780
798
|
c.buffer.preencode(state, kp.publicKey)
|
|
781
799
|
c.buffer.preencode(state, kp.secretKey)
|
|
782
800
|
},
|
|
783
|
-
encode
|
|
801
|
+
encode(state, kp) {
|
|
784
802
|
c.buffer.encode(state, kp.publicKey)
|
|
785
803
|
c.buffer.encode(state, kp.secretKey)
|
|
786
804
|
},
|
|
787
|
-
decode
|
|
805
|
+
decode(state) {
|
|
788
806
|
return {
|
|
789
807
|
publicKey: c.buffer.decode(state),
|
|
790
808
|
secretKey: c.buffer.decode(state)
|
|
@@ -793,17 +811,17 @@ const keyPair = {
|
|
|
793
811
|
}
|
|
794
812
|
|
|
795
813
|
const reorgHint = {
|
|
796
|
-
preencode
|
|
814
|
+
preencode(state, r) {
|
|
797
815
|
c.uint.preencode(state, r.from)
|
|
798
816
|
c.uint.preencode(state, r.to)
|
|
799
817
|
c.uint.preencode(state, r.ancestors)
|
|
800
818
|
},
|
|
801
|
-
encode
|
|
819
|
+
encode(state, r) {
|
|
802
820
|
c.uint.encode(state, r.from)
|
|
803
821
|
c.uint.encode(state, r.to)
|
|
804
822
|
c.uint.encode(state, r.ancestors)
|
|
805
823
|
},
|
|
806
|
-
decode
|
|
824
|
+
decode(state) {
|
|
807
825
|
return {
|
|
808
826
|
from: c.uint.decode(state),
|
|
809
827
|
to: c.uint.decode(state),
|
|
@@ -815,15 +833,15 @@ const reorgHint = {
|
|
|
815
833
|
const reorgHintArray = c.array(reorgHint)
|
|
816
834
|
|
|
817
835
|
const hints = {
|
|
818
|
-
preencode
|
|
836
|
+
preencode(state, h) {
|
|
819
837
|
reorgHintArray.preencode(state, h.reorgs)
|
|
820
838
|
c.uint.preencode(state, h.contiguousLength)
|
|
821
839
|
},
|
|
822
|
-
encode
|
|
840
|
+
encode(state, h) {
|
|
823
841
|
reorgHintArray.encode(state, h.reorgs)
|
|
824
842
|
c.uint.encode(state, h.contiguousLength)
|
|
825
843
|
},
|
|
826
|
-
decode
|
|
844
|
+
decode(state) {
|
|
827
845
|
return {
|
|
828
846
|
reorgs: reorgHintArray.decode(state),
|
|
829
847
|
contiguousLength: state.start < state.end ? c.uint.decode(state) : 0
|
|
@@ -832,19 +850,19 @@ const hints = {
|
|
|
832
850
|
}
|
|
833
851
|
|
|
834
852
|
const treeHeader = {
|
|
835
|
-
preencode
|
|
853
|
+
preencode(state, t) {
|
|
836
854
|
c.uint.preencode(state, t.fork)
|
|
837
855
|
c.uint.preencode(state, t.length)
|
|
838
856
|
c.buffer.preencode(state, t.rootHash)
|
|
839
857
|
c.buffer.preencode(state, t.signature)
|
|
840
858
|
},
|
|
841
|
-
encode
|
|
859
|
+
encode(state, t) {
|
|
842
860
|
c.uint.encode(state, t.fork)
|
|
843
861
|
c.uint.encode(state, t.length)
|
|
844
862
|
c.buffer.encode(state, t.rootHash)
|
|
845
863
|
c.buffer.encode(state, t.signature)
|
|
846
864
|
},
|
|
847
|
-
decode
|
|
865
|
+
decode(state) {
|
|
848
866
|
return {
|
|
849
867
|
fork: c.uint.decode(state),
|
|
850
868
|
length: c.uint.decode(state),
|
|
@@ -855,17 +873,17 @@ const treeHeader = {
|
|
|
855
873
|
}
|
|
856
874
|
|
|
857
875
|
const types = {
|
|
858
|
-
preencode
|
|
876
|
+
preencode(state, t) {
|
|
859
877
|
c.string.preencode(state, t.tree)
|
|
860
878
|
c.string.preencode(state, t.bitfield)
|
|
861
879
|
c.string.preencode(state, t.signer)
|
|
862
880
|
},
|
|
863
|
-
encode
|
|
881
|
+
encode(state, t) {
|
|
864
882
|
c.string.encode(state, t.tree)
|
|
865
883
|
c.string.encode(state, t.bitfield)
|
|
866
884
|
c.string.encode(state, t.signer)
|
|
867
885
|
},
|
|
868
|
-
decode
|
|
886
|
+
decode(state) {
|
|
869
887
|
return {
|
|
870
888
|
tree: c.string.decode(state),
|
|
871
889
|
bitfield: c.string.decode(state),
|
|
@@ -875,15 +893,15 @@ const types = {
|
|
|
875
893
|
}
|
|
876
894
|
|
|
877
895
|
const externalHeader = {
|
|
878
|
-
preencode
|
|
896
|
+
preencode(state, m) {
|
|
879
897
|
c.uint.preencode(state, m.start)
|
|
880
898
|
c.uint.preencode(state, m.length)
|
|
881
899
|
},
|
|
882
|
-
encode
|
|
900
|
+
encode(state, m) {
|
|
883
901
|
c.uint.encode(state, m.start)
|
|
884
902
|
c.uint.encode(state, m.length)
|
|
885
903
|
},
|
|
886
|
-
decode
|
|
904
|
+
decode(state) {
|
|
887
905
|
return {
|
|
888
906
|
start: c.uint.decode(state),
|
|
889
907
|
length: c.uint.decode(state)
|
|
@@ -894,7 +912,7 @@ const externalHeader = {
|
|
|
894
912
|
const keyValueArray = c.array(keyValue)
|
|
895
913
|
|
|
896
914
|
oplog.header = {
|
|
897
|
-
preencode
|
|
915
|
+
preencode(state, h) {
|
|
898
916
|
state.end += 2 // version + flags
|
|
899
917
|
if (h.external) {
|
|
900
918
|
externalHeader.preencode(state, h.external)
|
|
@@ -907,7 +925,7 @@ oplog.header = {
|
|
|
907
925
|
treeHeader.preencode(state, h.tree)
|
|
908
926
|
hints.preencode(state, h.hints)
|
|
909
927
|
},
|
|
910
|
-
encode
|
|
928
|
+
encode(state, h) {
|
|
911
929
|
c.uint.encode(state, 1)
|
|
912
930
|
if (h.external) {
|
|
913
931
|
c.uint.encode(state, 1) // ONLY set the first big for clarity
|
|
@@ -922,7 +940,7 @@ oplog.header = {
|
|
|
922
940
|
treeHeader.encode(state, h.tree)
|
|
923
941
|
hints.encode(state, h.hints)
|
|
924
942
|
},
|
|
925
|
-
decode
|
|
943
|
+
decode(state) {
|
|
926
944
|
const version = c.uint.decode(state)
|
|
927
945
|
|
|
928
946
|
if (version > 1) {
|
|
@@ -946,11 +964,13 @@ oplog.header = {
|
|
|
946
964
|
hash: old.types.tree,
|
|
947
965
|
allowPatch: false,
|
|
948
966
|
quorum: 1,
|
|
949
|
-
signers: [
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
967
|
+
signers: [
|
|
968
|
+
{
|
|
969
|
+
signature: old.types.signer,
|
|
970
|
+
namespace: DEFAULT_NAMESPACE,
|
|
971
|
+
publicKey: old.signer.publicKey
|
|
972
|
+
}
|
|
973
|
+
],
|
|
954
974
|
prologue: null,
|
|
955
975
|
linked: null,
|
|
956
976
|
userData: null
|
|
@@ -991,17 +1011,17 @@ oplog.header = {
|
|
|
991
1011
|
const uintArray = c.array(c.uint)
|
|
992
1012
|
|
|
993
1013
|
const multisigInput = {
|
|
994
|
-
preencode
|
|
1014
|
+
preencode(state, inp) {
|
|
995
1015
|
c.uint.preencode(state, inp.signer)
|
|
996
1016
|
c.fixed64.preencode(state, inp.signature)
|
|
997
1017
|
c.uint.preencode(state, inp.patch)
|
|
998
1018
|
},
|
|
999
|
-
encode
|
|
1019
|
+
encode(state, inp) {
|
|
1000
1020
|
c.uint.encode(state, inp.signer)
|
|
1001
1021
|
c.fixed64.encode(state, inp.signature)
|
|
1002
1022
|
c.uint.encode(state, inp.patch)
|
|
1003
1023
|
},
|
|
1004
|
-
decode
|
|
1024
|
+
decode(state) {
|
|
1005
1025
|
return {
|
|
1006
1026
|
signer: c.uint.decode(state),
|
|
1007
1027
|
signature: c.fixed64.decode(state),
|
|
@@ -1011,17 +1031,17 @@ const multisigInput = {
|
|
|
1011
1031
|
}
|
|
1012
1032
|
|
|
1013
1033
|
const patchEncodingv0 = {
|
|
1014
|
-
preencode
|
|
1034
|
+
preencode(state, n) {
|
|
1015
1035
|
c.uint.preencode(state, n.start)
|
|
1016
1036
|
c.uint.preencode(state, n.length)
|
|
1017
1037
|
uintArray.preencode(state, n.nodes)
|
|
1018
1038
|
},
|
|
1019
|
-
encode
|
|
1039
|
+
encode(state, n) {
|
|
1020
1040
|
c.uint.encode(state, n.start)
|
|
1021
1041
|
c.uint.encode(state, n.length)
|
|
1022
1042
|
uintArray.encode(state, n.nodes)
|
|
1023
1043
|
},
|
|
1024
|
-
decode
|
|
1044
|
+
decode(state) {
|
|
1025
1045
|
return {
|
|
1026
1046
|
start: c.uint.decode(state),
|
|
1027
1047
|
length: c.uint.decode(state),
|
|
@@ -1031,24 +1051,24 @@ const patchEncodingv0 = {
|
|
|
1031
1051
|
}
|
|
1032
1052
|
|
|
1033
1053
|
const multisigInputv0 = {
|
|
1034
|
-
preencode
|
|
1054
|
+
preencode(state, n) {
|
|
1035
1055
|
state.end++
|
|
1036
1056
|
c.uint.preencode(state, n.signer)
|
|
1037
1057
|
c.fixed64.preencode(state, n.signature)
|
|
1038
1058
|
if (n.patch) patchEncodingv0.preencode(state, n.patch)
|
|
1039
1059
|
},
|
|
1040
|
-
encode
|
|
1060
|
+
encode(state, n) {
|
|
1041
1061
|
c.uint.encode(state, n.patch ? 1 : 0)
|
|
1042
1062
|
c.uint.encode(state, n.signer)
|
|
1043
1063
|
c.fixed64.encode(state, n.signature)
|
|
1044
1064
|
if (n.patch) patchEncodingv0.encode(state, n.patch)
|
|
1045
1065
|
},
|
|
1046
|
-
decode
|
|
1066
|
+
decode(state) {
|
|
1047
1067
|
const flags = c.uint.decode(state)
|
|
1048
1068
|
return {
|
|
1049
1069
|
signer: c.uint.decode(state),
|
|
1050
1070
|
signature: c.fixed64.decode(state),
|
|
1051
|
-
patch:
|
|
1071
|
+
patch: flags & 1 ? patchEncodingv0.decode(state) : null
|
|
1052
1072
|
}
|
|
1053
1073
|
}
|
|
1054
1074
|
}
|
|
@@ -1057,17 +1077,17 @@ const multisigInputArrayv0 = c.array(multisigInputv0)
|
|
|
1057
1077
|
const multisigInputArray = c.array(multisigInput)
|
|
1058
1078
|
|
|
1059
1079
|
const compactNode = {
|
|
1060
|
-
preencode
|
|
1080
|
+
preencode(state, n) {
|
|
1061
1081
|
c.uint.preencode(state, n.index)
|
|
1062
1082
|
c.uint.preencode(state, n.size)
|
|
1063
1083
|
c.fixed32.preencode(state, n.hash)
|
|
1064
1084
|
},
|
|
1065
|
-
encode
|
|
1085
|
+
encode(state, n) {
|
|
1066
1086
|
c.uint.encode(state, n.index)
|
|
1067
1087
|
c.uint.encode(state, n.size)
|
|
1068
1088
|
c.fixed32.encode(state, n.hash)
|
|
1069
1089
|
},
|
|
1070
|
-
decode
|
|
1090
|
+
decode(state) {
|
|
1071
1091
|
return {
|
|
1072
1092
|
index: c.uint.decode(state),
|
|
1073
1093
|
size: c.uint.decode(state),
|
|
@@ -1079,15 +1099,15 @@ const compactNode = {
|
|
|
1079
1099
|
const compactNodeArray = c.array(compactNode)
|
|
1080
1100
|
|
|
1081
1101
|
exports.multiSignaturev0 = {
|
|
1082
|
-
preencode
|
|
1102
|
+
preencode(state, s) {
|
|
1083
1103
|
multisigInputArrayv0.preencode(state, s.proofs)
|
|
1084
1104
|
compactNodeArray.preencode(state, s.patch)
|
|
1085
1105
|
},
|
|
1086
|
-
encode
|
|
1106
|
+
encode(state, s) {
|
|
1087
1107
|
multisigInputArrayv0.encode(state, s.proofs)
|
|
1088
1108
|
compactNodeArray.encode(state, s.patch)
|
|
1089
1109
|
},
|
|
1090
|
-
decode
|
|
1110
|
+
decode(state) {
|
|
1091
1111
|
return {
|
|
1092
1112
|
proofs: multisigInputArrayv0.decode(state),
|
|
1093
1113
|
patch: compactNodeArray.decode(state)
|
|
@@ -1096,15 +1116,15 @@ exports.multiSignaturev0 = {
|
|
|
1096
1116
|
}
|
|
1097
1117
|
|
|
1098
1118
|
exports.multiSignature = {
|
|
1099
|
-
preencode
|
|
1119
|
+
preencode(state, s) {
|
|
1100
1120
|
multisigInputArray.preencode(state, s.proofs)
|
|
1101
1121
|
compactNodeArray.preencode(state, s.patch)
|
|
1102
1122
|
},
|
|
1103
|
-
encode
|
|
1123
|
+
encode(state, s) {
|
|
1104
1124
|
multisigInputArray.encode(state, s.proofs)
|
|
1105
1125
|
compactNodeArray.encode(state, s.patch)
|
|
1106
1126
|
},
|
|
1107
|
-
decode
|
|
1127
|
+
decode(state) {
|
|
1108
1128
|
return {
|
|
1109
1129
|
proofs: multisigInputArray.decode(state),
|
|
1110
1130
|
patch: compactNodeArray.decode(state)
|