corestore 7.6.1 → 7.7.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 +44 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -457,6 +457,50 @@ class Corestore extends ReadyResource {
|
|
|
457
457
|
}
|
|
458
458
|
}
|
|
459
459
|
|
|
460
|
+
async staticify(core, opts) {
|
|
461
|
+
if (!this.opened) await this.ready()
|
|
462
|
+
if (!core.opened) await core.ready()
|
|
463
|
+
|
|
464
|
+
const rx = core.state.storage.read()
|
|
465
|
+
|
|
466
|
+
const headPromise = rx.getHead()
|
|
467
|
+
const authPromise = rx.getAuth()
|
|
468
|
+
|
|
469
|
+
rx.tryFlush()
|
|
470
|
+
|
|
471
|
+
const [head, auth] = await Promise.all([headPromise, authPromise])
|
|
472
|
+
if (!head || head.length === 0) throw new Error('Core must have data')
|
|
473
|
+
|
|
474
|
+
const prologue = {
|
|
475
|
+
length: head.length,
|
|
476
|
+
hash: head.rootHash
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
const manifest = {
|
|
480
|
+
version: 1,
|
|
481
|
+
hash: auth.manifest.hash,
|
|
482
|
+
quorum: 0,
|
|
483
|
+
signers: [],
|
|
484
|
+
prologue
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
const c = {
|
|
488
|
+
key: null,
|
|
489
|
+
discoveryKey: null,
|
|
490
|
+
manifest,
|
|
491
|
+
core: core.state.storage.core
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
c.key = Hypercore.key(c.manifest)
|
|
495
|
+
c.discoveryKey = Hypercore.discoveryKey(c.key)
|
|
496
|
+
|
|
497
|
+
await this.storage.createCore(c)
|
|
498
|
+
|
|
499
|
+
const staticCore = this.get({ ...opts, key: c.key })
|
|
500
|
+
await staticCore.ready()
|
|
501
|
+
return staticCore
|
|
502
|
+
}
|
|
503
|
+
|
|
460
504
|
get(opts) {
|
|
461
505
|
this._maybeClosed()
|
|
462
506
|
|