hypercore-storage 1.8.3 → 1.8.5

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 CHANGED
@@ -6,6 +6,8 @@ const View = require('./lib/view.js')
6
6
  const VERSION = 1
7
7
  const COLUMN_FAMILY = 'corestore'
8
8
 
9
+ const { store, core } = require('./lib/keys.js')
10
+
9
11
  const {
10
12
  CorestoreRX,
11
13
  CorestoreTX,
@@ -369,6 +371,38 @@ class CorestoreStorage {
369
371
  return this.db.ready()
370
372
  }
371
373
 
374
+ async deleteCore (ptr) {
375
+ const rx = new CoreRX(ptr, this.db, EMPTY)
376
+
377
+ const authPromise = rx.getAuth()
378
+ const sessionsPromise = rx.getSessions()
379
+
380
+ rx.tryFlush()
381
+
382
+ const auth = await authPromise
383
+ const sessions = await sessionsPromise
384
+
385
+ // no core stored here
386
+ if (!auth) return
387
+
388
+ const tx = this.db.write({ autoDestroy: true })
389
+
390
+ tx.tryDelete(store.core(auth.discoveryKey))
391
+
392
+ // clear core
393
+ const start = core.core(ptr.corePointer)
394
+ const end = core.core(ptr.corePointer + 1)
395
+ tx.tryDeleteRange(start, end)
396
+
397
+ for (const { dataPointer } of sessions) {
398
+ const start = core.data(dataPointer)
399
+ const end = core.data(dataPointer + 1)
400
+ tx.tryDeleteRange(start, end)
401
+ }
402
+
403
+ return tx.flush()
404
+ }
405
+
372
406
  static isCoreStorage (db) {
373
407
  return isCorestoreStorage(db)
374
408
  }
package/lib/keys.js CHANGED
@@ -113,6 +113,22 @@ store.discoveryKey = function (buffer) {
113
113
  return c.fixed32.decode(state)
114
114
  }
115
115
 
116
+ core.core = function (ptr) {
117
+ const state = alloc()
118
+ const start = state.start
119
+ UINT.encode(state, TL_CORE)
120
+ UINT.encode(state, ptr)
121
+ return state.buffer.subarray(start, state.start)
122
+ }
123
+
124
+ core.data = function (ptr) {
125
+ const state = alloc()
126
+ const start = state.start
127
+ UINT.encode(state, TL_DATA)
128
+ UINT.encode(state, ptr)
129
+ return state.buffer.subarray(start, state.start)
130
+ }
131
+
116
132
  core.auth = function (ptr) {
117
133
  const state = alloc()
118
134
  const start = state.start
@@ -433,6 +433,7 @@ async function core (core, { version, dryRun = true, gc = true }) {
433
433
 
434
434
  for (const index of allBits(bitfield)) {
435
435
  if (headerBits.get(index) === false) continue
436
+ if (index >= head.length) continue
436
437
 
437
438
  setBitInPage(index)
438
439
 
@@ -451,6 +452,7 @@ async function core (core, { version, dryRun = true, gc = true }) {
451
452
 
452
453
  for (const [index, bit] of headerBits) {
453
454
  if (!bit) continue
455
+ if (index >= head.length) continue
454
456
 
455
457
  setBitInPage(index)
456
458
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore-storage",
3
- "version": "1.8.3",
3
+ "version": "1.8.5",
4
4
  "main": "index.js",
5
5
  "files": [
6
6
  "index.js",