diff --git a/lib/core.js b/lib/core.js index 0a6b7fab..74624340 100644 --- a/lib/core.js +++ b/lib/core.js @@ -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') @@ -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') } @@ -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 } diff --git a/lib/merkle-tree.js b/lib/merkle-tree.js index e04ac993..21900f53 100644 --- a/lib/merkle-tree.js +++ b/lib/merkle-tree.js @@ -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) @@ -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()) @@ -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) } @@ -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) } @@ -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 } @@ -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) } } @@ -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() }) })