hypercore 10.33.1 → 10.33.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.
Files changed (2) hide show
  1. package/index.js +12 -3
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -20,6 +20,7 @@ const Batch = require('./lib/batch')
20
20
  const { manifestHash, defaultSignerManifest, createManifest, isCompat, sign } = require('./lib/verifier')
21
21
  const { ReadStream, WriteStream, ByteStream } = require('./lib/streams')
22
22
  const {
23
+ ASSERTION,
23
24
  BAD_ARGUMENT,
24
25
  SESSION_CLOSED,
25
26
  SESSION_NOT_WRITABLE,
@@ -825,6 +826,7 @@ module.exports = class Hypercore extends EventEmitter {
825
826
 
826
827
  async seek (bytes, opts) {
827
828
  if (this.opened === false) await this.opening
829
+ if (!isValidIndex(bytes)) throw ASSERTION('seek is invalid')
828
830
 
829
831
  const tree = (opts && opts.tree) || this.core.tree
830
832
  const s = tree.seek(bytes, this.padding)
@@ -847,10 +849,9 @@ module.exports = class Hypercore extends EventEmitter {
847
849
 
848
850
  async has (start, end = start + 1) {
849
851
  if (this.opened === false) await this.opening
852
+ if (!isValidIndex(start) || !isValidIndex(end)) throw ASSERTION('has range is invalid')
850
853
 
851
- const length = end - start
852
- if (length <= 0) return false
853
- if (length === 1) return this.core.bitfield.get(start)
854
+ if (end === start + 1) return this.core.bitfield.get(start)
854
855
 
855
856
  const i = this.core.bitfield.firstUnset(start)
856
857
  return i === -1 || i >= end
@@ -858,6 +859,7 @@ module.exports = class Hypercore extends EventEmitter {
858
859
 
859
860
  async get (index, opts) {
860
861
  if (this.opened === false) await this.opening
862
+ if (!isValidIndex(index)) throw ASSERTION('block index is invalid')
861
863
 
862
864
  this.tracer.trace('get', { index })
863
865
 
@@ -891,6 +893,8 @@ module.exports = class Hypercore extends EventEmitter {
891
893
  end = start + 1
892
894
  }
893
895
 
896
+ if (!isValidIndex(start) || !isValidIndex(end)) throw ASSERTION('clear range is invalid')
897
+
894
898
  const cleared = (opts && opts.diff) ? { blocks: 0 } : null
895
899
 
896
900
  if (start >= end) return cleared
@@ -923,6 +927,7 @@ module.exports = class Hypercore extends EventEmitter {
923
927
  const activeRequests = (opts && opts.activeRequests) || this.activeRequests
924
928
 
925
929
  const req = this.replicator.addBlock(activeRequests, index)
930
+ req.snapshot = index < this.length
926
931
 
927
932
  const timeout = opts && opts.timeout !== undefined ? opts.timeout : this.timeout
928
933
  if (timeout) req.context.setTimeout(req, timeout)
@@ -1156,3 +1161,7 @@ function ensureEncryption (core, opts) {
1156
1161
  function createCache (cache) {
1157
1162
  return cache === true ? new Xache({ maxSize: 65536, maxAge: 0 }) : (cache || null)
1158
1163
  }
1164
+
1165
+ function isValidIndex (index) {
1166
+ return index === 0 || index > 0
1167
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "10.33.1",
3
+ "version": "10.33.3",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -50,7 +50,7 @@
50
50
  "fast-fifo": "^1.3.0",
51
51
  "flat-tree": "^1.9.0",
52
52
  "hypercore-crypto": "^3.2.1",
53
- "hypercore-errors": "^1.1.1",
53
+ "hypercore-errors": "^1.2.0",
54
54
  "hypercore-id-encoding": "^1.2.0",
55
55
  "hypertrace": "^1.2.1",
56
56
  "is-options": "^1.0.1",