hypercore 11.0.34 → 11.0.36
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 +4 -2
- package/lib/session-state.js +3 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -364,8 +364,10 @@ class Hypercore extends EventEmitter {
|
|
|
364
364
|
if (state) state.unref() // ref'ed above in setup session
|
|
365
365
|
}
|
|
366
366
|
|
|
367
|
-
if (this.state && checkout !== -1
|
|
368
|
-
|
|
367
|
+
if (this.state && checkout !== -1) {
|
|
368
|
+
if (!opts.name && !opts.atom) throw ASSERTION('Checkouts must be named or atomized')
|
|
369
|
+
if (checkout > this.state.length) throw ASSERTION('Invalid checkout ' + checkout + ' for ' + opts.name + ', length is ' + this.state.length)
|
|
370
|
+
if (checkout < this.state.length) await this.state.truncate(checkout, this.fork)
|
|
369
371
|
}
|
|
370
372
|
|
|
371
373
|
if (this.state === null) {
|
package/lib/session-state.js
CHANGED
|
@@ -367,6 +367,9 @@ module.exports = class SessionState {
|
|
|
367
367
|
if (this.prologue && length < this.prologue.length) {
|
|
368
368
|
throw INVALID_OPERATION('Truncation breaks prologue')
|
|
369
369
|
}
|
|
370
|
+
if (length > this.length) {
|
|
371
|
+
throw INVALID_OPERATION('Not a truncation, ' + length + ' must be less or equal to ' + this.length)
|
|
372
|
+
}
|
|
370
373
|
|
|
371
374
|
const batch = this.createTreeBatch()
|
|
372
375
|
await MerkleTree.truncate(this, length, batch, fork)
|