hypercore-storage 2.3.0 → 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 +36 -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
|
|
|
@@ -956,7 +986,10 @@ class CorestoreStorage {
|
|
|
956
986
|
}
|
|
957
987
|
|
|
958
988
|
// not allowed to throw validation errors as its a shared tx!
|
|
959
|
-
async _create(
|
|
989
|
+
async _create(
|
|
990
|
+
view,
|
|
991
|
+
{ key, manifest, keyPair, encryptionKey, discoveryKey, alias, userData, core: ptrs }
|
|
992
|
+
) {
|
|
960
993
|
const rx = new CorestoreRX(this.db, view)
|
|
961
994
|
const tx = new CorestoreTX(view)
|
|
962
995
|
|
|
@@ -971,8 +1004,8 @@ class CorestoreStorage {
|
|
|
971
1004
|
if (head === null) head = initStoreHead()
|
|
972
1005
|
if (head.defaultDiscoveryKey === null) head.defaultDiscoveryKey = discoveryKey
|
|
973
1006
|
|
|
974
|
-
const corePointer = head.allocated.cores++
|
|
975
|
-
const dataPointer = head.allocated.datas++
|
|
1007
|
+
const corePointer = ptrs ? ptrs.corePointer : head.allocated.cores++
|
|
1008
|
+
const dataPointer = ptrs ? ptrs.dataPointer : head.allocated.datas++
|
|
976
1009
|
|
|
977
1010
|
core = { version: VERSION, corePointer, dataPointer, alias }
|
|
978
1011
|
|