hypercore-storage 2.2.1 → 2.4.0
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 +37 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -343,6 +343,36 @@ class HypercoreStorage {
|
|
|
343
343
|
return this.atomize(atom)
|
|
344
344
|
}
|
|
345
345
|
|
|
346
|
+
async createStaticCore() {
|
|
347
|
+
const rx = this.read()
|
|
348
|
+
|
|
349
|
+
const headPromise = rx.getHead()
|
|
350
|
+
const authPromise = rx.getAuth()
|
|
351
|
+
|
|
352
|
+
rx.tryFlush()
|
|
353
|
+
|
|
354
|
+
const [head, auth] = await Promise.all([headPromise, authPromise])
|
|
355
|
+
if (!head || head.length === 0) throw new Error('Must have data')
|
|
356
|
+
|
|
357
|
+
const prologue = {
|
|
358
|
+
length: head.length,
|
|
359
|
+
hash: head.rootHash
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
const manifest = {
|
|
363
|
+
version: 1,
|
|
364
|
+
hash: auth.manifest.hash,
|
|
365
|
+
quorum: 0,
|
|
366
|
+
signers: [],
|
|
367
|
+
prologue
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
return {
|
|
371
|
+
manifest,
|
|
372
|
+
core: { ...this.core, dependencies: this.core.dependencies.slice() }
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
346
376
|
_addDependency(dep) {
|
|
347
377
|
const deps = []
|
|
348
378
|
|
|
@@ -449,6 +479,7 @@ class CorestoreStorage {
|
|
|
449
479
|
const corestoreFile = path.join(this.path, 'CORESTORE')
|
|
450
480
|
|
|
451
481
|
this.deviceFile = new DeviceFile(corestoreFile, {
|
|
482
|
+
lock: true,
|
|
452
483
|
wait: this.wait,
|
|
453
484
|
data: { id: this.id }
|
|
454
485
|
})
|
|
@@ -955,7 +986,10 @@ class CorestoreStorage {
|
|
|
955
986
|
}
|
|
956
987
|
|
|
957
988
|
// not allowed to throw validation errors as its a shared tx!
|
|
958
|
-
async _create(
|
|
989
|
+
async _create(
|
|
990
|
+
view,
|
|
991
|
+
{ key, manifest, keyPair, encryptionKey, discoveryKey, alias, userData, core: ptrs }
|
|
992
|
+
) {
|
|
959
993
|
const rx = new CorestoreRX(this.db, view)
|
|
960
994
|
const tx = new CorestoreTX(view)
|
|
961
995
|
|
|
@@ -970,8 +1004,8 @@ class CorestoreStorage {
|
|
|
970
1004
|
if (head === null) head = initStoreHead()
|
|
971
1005
|
if (head.defaultDiscoveryKey === null) head.defaultDiscoveryKey = discoveryKey
|
|
972
1006
|
|
|
973
|
-
const corePointer = head.allocated.cores++
|
|
974
|
-
const dataPointer = head.allocated.datas++
|
|
1007
|
+
const corePointer = ptrs ? ptrs.corePointer : head.allocated.cores++
|
|
1008
|
+
const dataPointer = ptrs ? ptrs.dataPointer : head.allocated.datas++
|
|
975
1009
|
|
|
976
1010
|
core = { version: VERSION, corePointer, dataPointer, alias }
|
|
977
1011
|
|