hypercore 11.40.2 → 11.40.3

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.
@@ -72,7 +72,14 @@ async function verify(storage, buffer, { referrer = null } = {}) {
72
72
 
73
73
  if (!auth.manifest || !auth.manifest.signers.length) return null
74
74
 
75
- const batch = await MerkleTree.verifyFullyRemote(new SlimSession(core, auth, head, roots), proof)
75
+ let batch = null
76
+ try {
77
+ batch = MerkleTree.verifyFullyRemote(new SlimSession(core, auth, head, roots), proof)
78
+ } catch (err) {
79
+ if (err.code !== 'INVALID_PROOF') throw err
80
+ return null
81
+ }
82
+
76
83
  const publicKey = auth.manifest.signers[0].publicKey
77
84
 
78
85
  let signable = null
@@ -825,6 +825,8 @@ class MerkleTree {
825
825
  }
826
826
  }
827
827
 
828
+ if (unverified) throw INVALID_PROOF('Proof not covered by the upgrade')
829
+
828
830
  return batch
829
831
  }
830
832
 
@@ -1154,7 +1156,7 @@ async function seekFromHead(session, head, bytes, padding) {
1154
1156
 
1155
1157
  for (let i = 0; i < roots.length; i++) {
1156
1158
  const root = roots[i]
1157
- const node = await getTreeNodeFromStorage(session.storage, root)
1159
+ const node = await getTreeNodeFromStorageOrError(session.storage, root)
1158
1160
  const size = getUnpaddedSize(node, padding, null)
1159
1161
 
1160
1162
  if (bytes === size) return root
@@ -34,7 +34,7 @@ module.exports = class ReceiverQueue {
34
34
  }
35
35
 
36
36
  _processRequest(req) {
37
- if (req.block || req.hash || req.seek || req.upgrade || req.manifest) {
37
+ if (this.requests.get(req.id) === req) {
38
38
  this.requests.delete(req.id)
39
39
  this.length--
40
40
  return req
package/lib/replicator.js CHANGED
@@ -1386,7 +1386,7 @@ class Peer {
1386
1386
  return
1387
1387
  }
1388
1388
 
1389
- const rem = start & (RemoteBitfield.BITS_PER_SEGMENT - 1)
1389
+ const rem = start & (RemoteBitfield.BITS_PER_PAGE - 1)
1390
1390
  if (rem > 0) {
1391
1391
  start -= rem
1392
1392
  length += rem
@@ -1401,7 +1401,7 @@ class Peer {
1401
1401
  this.missingBlocks.insert(start, remote.bitfield)
1402
1402
  }
1403
1403
 
1404
- start += RemoteBitfield.BITS_PER_SEGMENT
1404
+ start += RemoteBitfield.BITS_PER_PAGE
1405
1405
  }
1406
1406
 
1407
1407
  this._clearLocalRange(fixedStart, length)
@@ -1596,7 +1596,7 @@ class Peer {
1596
1596
 
1597
1597
  for (let i = 0; i < len; i++) {
1598
1598
  let index = off + i
1599
- if (index > s.seeker.end) index -= len
1599
+ if (index >= s.seeker.end) index -= len
1600
1600
 
1601
1601
  if (this._remoteHasBlock(index) === false) continue
1602
1602
  if (this.core.bitfield.get(index) === true) continue
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "11.40.2",
3
+ "version": "11.40.3",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {