hypercore 10.37.13 → 10.37.15
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/lib/core.js +12 -1
- package/lib/merkle-tree.js +5 -5
- package/lib/replicator.js +3 -0
- package/lib/verifier.js +6 -3
- package/package.json +2 -2
package/lib/core.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const hypercoreCrypto = require('hypercore-crypto')
|
|
2
2
|
const b4a = require('b4a')
|
|
3
|
+
const unslab = require('unslab')
|
|
3
4
|
const Oplog = require('./oplog')
|
|
4
5
|
const BigHeader = require('./big-header')
|
|
5
6
|
const Mutex = require('./mutex')
|
|
@@ -125,6 +126,11 @@ module.exports = class Core {
|
|
|
125
126
|
header = await bigHeader.load(header.external)
|
|
126
127
|
}
|
|
127
128
|
|
|
129
|
+
// unslab the long lived buffers to avoid keeping the slab alive
|
|
130
|
+
header.key = unslab(header.key)
|
|
131
|
+
header.tree.rootHash = unslab(header.tree.rootHash)
|
|
132
|
+
header.tree.signature = unslab(header.tree.signature)
|
|
133
|
+
|
|
128
134
|
if (opts.manifest) {
|
|
129
135
|
// if we provide a manifest and no key, verify that the stored key is the same
|
|
130
136
|
if (!opts.key && !Verifier.isValidManifest(header.key, Verifier.createManifest(opts.manifest))) {
|
|
@@ -163,6 +169,9 @@ module.exports = class Core {
|
|
|
163
169
|
while (bitfield.get(header.hints.contiguousLength)) header.hints.contiguousLength++
|
|
164
170
|
}
|
|
165
171
|
|
|
172
|
+
// to unslab
|
|
173
|
+
if (header.manifest) header.manifest = Verifier.createManifest(header.manifest)
|
|
174
|
+
|
|
166
175
|
const verifier = header.manifest ? new Verifier(header.key, header.manifest, { crypto, legacy }) : null
|
|
167
176
|
|
|
168
177
|
for (const e of entries) {
|
|
@@ -184,7 +193,7 @@ module.exports = class Core {
|
|
|
184
193
|
if (e.treeUpgrade) {
|
|
185
194
|
const batch = await tree.truncate(e.treeUpgrade.length, e.treeUpgrade.fork)
|
|
186
195
|
batch.ancestors = e.treeUpgrade.ancestors
|
|
187
|
-
batch.signature = e.treeUpgrade.signature
|
|
196
|
+
batch.signature = unslab(e.treeUpgrade.signature)
|
|
188
197
|
addReorgHint(header.hints.reorgs, tree, batch)
|
|
189
198
|
batch.commit()
|
|
190
199
|
|
|
@@ -697,6 +706,8 @@ module.exports = class Core {
|
|
|
697
706
|
}
|
|
698
707
|
}
|
|
699
708
|
|
|
709
|
+
manifest = Verifier.createManifest(manifest) // To unslab
|
|
710
|
+
|
|
700
711
|
const verifier = this.verifier || new Verifier(this.header.key, manifest, { crypto: this.crypto, legacy: this._legacy })
|
|
701
712
|
|
|
702
713
|
if (!verifier.verify(batch, batch.signature)) {
|
package/lib/merkle-tree.js
CHANGED
|
@@ -138,7 +138,7 @@ class MerkleTreeBatch {
|
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
hash () {
|
|
141
|
-
if (this.hashCached === null) this.hashCached = this.tree.crypto.tree(this.roots)
|
|
141
|
+
if (this.hashCached === null) this.hashCached = unslab(this.tree.crypto.tree(this.roots))
|
|
142
142
|
return this.hashCached
|
|
143
143
|
}
|
|
144
144
|
|
|
@@ -260,7 +260,7 @@ class MerkleTreeBatch {
|
|
|
260
260
|
this.tree.length = this.length
|
|
261
261
|
this.tree.byteLength = this.byteLength
|
|
262
262
|
this.tree.fork = this.fork
|
|
263
|
-
this.tree.signature = this.signature
|
|
263
|
+
this.tree.signature = this.signature
|
|
264
264
|
}
|
|
265
265
|
|
|
266
266
|
seek (bytes, padding) {
|
|
@@ -430,7 +430,7 @@ module.exports = class MerkleTree {
|
|
|
430
430
|
this.roots = roots
|
|
431
431
|
this.length = roots.length ? totalSpan(roots) / 2 : 0
|
|
432
432
|
this.byteLength = totalSize(roots)
|
|
433
|
-
this.signature = signature
|
|
433
|
+
this.signature = signature
|
|
434
434
|
this.prologue = prologue
|
|
435
435
|
|
|
436
436
|
this.storage = storage
|
|
@@ -471,7 +471,7 @@ module.exports = class MerkleTree {
|
|
|
471
471
|
}
|
|
472
472
|
|
|
473
473
|
hash () {
|
|
474
|
-
return this.crypto.tree(this.roots)
|
|
474
|
+
return unslab(this.crypto.tree(this.roots))
|
|
475
475
|
}
|
|
476
476
|
|
|
477
477
|
signable (namespace) {
|
|
@@ -982,7 +982,7 @@ function verifyUpgrade ({ fork, upgrade }, blockRoot, batch) {
|
|
|
982
982
|
ite.sibling()
|
|
983
983
|
}
|
|
984
984
|
|
|
985
|
-
batch.signature = upgrade.signature
|
|
985
|
+
batch.signature = unslab(upgrade.signature)
|
|
986
986
|
batch.fork = fork
|
|
987
987
|
|
|
988
988
|
return q.extra === null
|
package/lib/replicator.js
CHANGED
|
@@ -1108,6 +1108,8 @@ class Peer {
|
|
|
1108
1108
|
if (h.inflight.length > 0) continue
|
|
1109
1109
|
|
|
1110
1110
|
const req = this._makeRequest(false, h.priority, index + 1)
|
|
1111
|
+
if (req === null) continue
|
|
1112
|
+
|
|
1111
1113
|
const nodes = flatTree.depth(s.seeker.start + s.seeker.end - 1)
|
|
1112
1114
|
|
|
1113
1115
|
req.hash = { index: 2 * index, nodes }
|
|
@@ -1299,6 +1301,7 @@ class Peer {
|
|
|
1299
1301
|
if (this._remoteHasBlock(index) === false) continue
|
|
1300
1302
|
|
|
1301
1303
|
const req = this._makeRequest(false, 0, 0)
|
|
1304
|
+
if (req === null) continue
|
|
1302
1305
|
|
|
1303
1306
|
req.hash = { index: 2 * index, nodes: f.batch.want.nodes }
|
|
1304
1307
|
|
package/lib/verifier.js
CHANGED
|
@@ -3,6 +3,7 @@ const b4a = require('b4a')
|
|
|
3
3
|
const c = require('compact-encoding')
|
|
4
4
|
const flat = require('flat-tree')
|
|
5
5
|
const { BAD_ARGUMENT } = require('hypercore-errors')
|
|
6
|
+
const unslab = require('unslab')
|
|
6
7
|
|
|
7
8
|
const m = require('./messages')
|
|
8
9
|
const multisig = require('./multisig')
|
|
@@ -201,7 +202,9 @@ module.exports = class Verifier {
|
|
|
201
202
|
if (!(b4a.isBuffer(inp.prologue.hash) && inp.prologue.hash.byteLength === 32) || !(inp.prologue.length >= 0)) {
|
|
202
203
|
throw BAD_ARGUMENT('Invalid prologue')
|
|
203
204
|
}
|
|
205
|
+
|
|
204
206
|
manifest.prologue = inp.prologue
|
|
207
|
+
manifest.prologue.hash = unslab(manifest.prologue.hash)
|
|
205
208
|
}
|
|
206
209
|
|
|
207
210
|
return manifest
|
|
@@ -237,7 +240,7 @@ function defaultQuorum (man) {
|
|
|
237
240
|
}
|
|
238
241
|
|
|
239
242
|
function generateUpgrade (patch, start, length) {
|
|
240
|
-
const upgrade = { start, length, nodes: null, additionalNodes: [] }
|
|
243
|
+
const upgrade = { start, length, nodes: null, additionalNodes: [], signature: null }
|
|
241
244
|
|
|
242
245
|
const from = start * 2
|
|
243
246
|
const to = from + length * 2
|
|
@@ -274,8 +277,8 @@ function parseSigner (signer) {
|
|
|
274
277
|
validateSigner(signer)
|
|
275
278
|
return {
|
|
276
279
|
signature: 'ed25519',
|
|
277
|
-
namespace: signer.namespace || caps.DEFAULT_NAMESPACE,
|
|
278
|
-
publicKey: signer.publicKey
|
|
280
|
+
namespace: unslab(signer.namespace || caps.DEFAULT_NAMESPACE),
|
|
281
|
+
publicKey: unslab(signer.publicKey)
|
|
279
282
|
}
|
|
280
283
|
}
|
|
281
284
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hypercore",
|
|
3
|
-
"version": "10.37.
|
|
3
|
+
"version": "10.37.15",
|
|
4
4
|
"description": "Hypercore is a secure, distributed append-only log",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"safety-catch": "^1.0.1",
|
|
62
62
|
"sodium-universal": "^4.0.0",
|
|
63
63
|
"streamx": "^2.12.4",
|
|
64
|
-
"unslab": "^1.
|
|
64
|
+
"unslab": "^1.3.0",
|
|
65
65
|
"xache": "^1.1.0",
|
|
66
66
|
"z32": "^1.0.0"
|
|
67
67
|
},
|