Skip to content
This repository was archived by the owner on Dec 28, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/core.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const hypercoreCrypto = require('hypercore-crypto')
const b4a = require('b4a')
const Oplog = require('./oplog')
const Mutex = require('./mutex')
const MerkleTree = require('./merkle-tree')
Expand Down Expand Up @@ -90,7 +91,7 @@ module.exports = class Core {
await oplog.flush(header)
}

if (opts.keyPair && !header.signer.publicKey.equals(opts.keyPair.publicKey)) {
if (opts.keyPair && !b4a.equals(header.signer.publicKey, opts.keyPair.publicKey)) {
throw new Error('Another hypercore is stored here')
}

Expand Down Expand Up @@ -176,7 +177,7 @@ module.exports = class Core {

for (const u of this.header.userData) {
if (u.key !== key) continue
if (value && u.value.equals(value)) return
if (value && b4a.equals(u.value, value)) return
empty = false
break
}
Expand Down
14 changes: 7 additions & 7 deletions lib/merkle-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class ReorgBatch extends MerkleTreeBatch {
const nodes = []
const root = verifyBlock(proof, this.tree.crypto, nodes)

if (root === null || !root.hash.equals(this.diff.hash)) return false
if (root === null || !b4a.equals(root.hash, this.diff.hash)) return false

this.nodes.push(...nodes)
return this._update(nodes)
Expand All @@ -233,7 +233,7 @@ class ReorgBatch extends MerkleTreeBatch {
if (!left) break

const existing = await this.tree.get(left.index, false)
if (!existing || !existing.hash.equals(left.hash)) {
if (!existing || !b4a.equals(existing.hash, left.hash)) {
diff = left
} else {
diff = n.get(ite.sibling())
Expand Down Expand Up @@ -355,7 +355,7 @@ module.exports = class MerkleTree {
}

addNode (node) {
if (node.size === 0 && node.hash.equals(BLANK_HASH)) node = blankNode(node.index)
if (node.size === 0 && b4a.equals(node.hash, BLANK_HASH)) node = blankNode(node.index)
this.unflushed.set(node.index, node)
}

Expand Down Expand Up @@ -383,7 +383,7 @@ module.exports = class MerkleTree {
const indexes = flat.fullRoots(2 * length)
const roots = new Array(indexes.length)

for (var i = 0; i < indexes.length; i++) {
for (let i = 0; i < indexes.length; i++) {
roots[i] = this.get(indexes[i], true)
}

Expand Down Expand Up @@ -545,7 +545,7 @@ module.exports = class MerkleTree {

for (const root of batch.roots) {
const existing = await this.get(root.index, false)
if (existing && existing.hash.equals(root.hash)) continue
if (existing && b4a.equals(existing.hash, root.hash)) continue
batch._updateDiffRoot(root)
break
}
Expand Down Expand Up @@ -573,7 +573,7 @@ module.exports = class MerkleTree {

if (unverified) {
const verified = await this.get(unverified.index)
if (!verified.hash.equals(unverified.hash)) {
if (!b4a.equals(verified.hash, unverified.hash)) {
throw new Error('Invalid checksum at node ' + unverified.index)
}
}
Expand Down Expand Up @@ -718,7 +718,7 @@ module.exports = class MerkleTree {
await new Promise((resolve, reject) => {
storage.read(0, OLD_TREE.length, (err, buf) => {
if (err) return resolve()
if (buf.equals(OLD_TREE)) return reject(new Error('Storage contains an incompatible merkle tree'))
if (b4a.equals(buf, OLD_TREE)) return reject(new Error('Storage contains an incompatible merkle tree'))
resolve()
})
})
Expand Down