hypercore 10.33.1 → 10.33.2
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/index.js +11 -3
- 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
|
-
|
|
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
|
|
@@ -1156,3 +1160,7 @@ function ensureEncryption (core, opts) {
|
|
|
1156
1160
|
function createCache (cache) {
|
|
1157
1161
|
return cache === true ? new Xache({ maxSize: 65536, maxAge: 0 }) : (cache || null)
|
|
1158
1162
|
}
|
|
1163
|
+
|
|
1164
|
+
function isValidIndex (index) {
|
|
1165
|
+
return index === 0 || index > 0
|
|
1166
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hypercore",
|
|
3
|
-
"version": "10.33.
|
|
3
|
+
"version": "10.33.2",
|
|
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.
|
|
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",
|