hypercore 11.18.0 → 11.18.2
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 +11 -2
- package/lib/fully-remote-proof.js +1 -3
- package/lib/read-batch.js +10 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -977,9 +977,18 @@ class Hypercore extends EventEmitter {
|
|
|
977
977
|
async proof(opts) {
|
|
978
978
|
if (this.opened === false) await this.opening
|
|
979
979
|
const rx = this.state.storage.read()
|
|
980
|
-
const
|
|
980
|
+
const proofPromise = MerkleTree.proof(this.state, rx, opts)
|
|
981
|
+
const blockPromise = opts && opts.block ? rx.getBlock(opts.block.index) : null
|
|
981
982
|
rx.tryFlush()
|
|
982
|
-
|
|
983
|
+
const [proof, block] = await Promise.all([proofPromise, blockPromise])
|
|
984
|
+
const settled = await proof.settle()
|
|
985
|
+
if (block) settled.block.value = block
|
|
986
|
+
return settled
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
async applyProof(proof, from) {
|
|
990
|
+
if (this.opened === false) await this.opening
|
|
991
|
+
return this.core.verify(proof, from)
|
|
983
992
|
}
|
|
984
993
|
|
|
985
994
|
async verifyFullyRemote(proof) {
|
|
@@ -101,13 +101,11 @@ async function verify(storage, buffer, { referrer = null } = {}) {
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
async function proof(sender, { index, block = null } = {}) {
|
|
104
|
-
const
|
|
104
|
+
const proof = await sender.proof({
|
|
105
105
|
block: block ? { index, nodes: 0 } : null,
|
|
106
106
|
upgrade: { start: 0, length: sender.length }
|
|
107
107
|
})
|
|
108
108
|
|
|
109
|
-
const proof = await treeProof.settle()
|
|
110
|
-
|
|
111
109
|
if (block) proof.block.value = block
|
|
112
110
|
proof.manifest = sender.core.header.manifest
|
|
113
111
|
|