Skip to content

Commit

Permalink
Merge branch 'main' into rocksdb
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed Nov 26, 2024
2 parents 9250a35 + 7ceb790 commit 83a5fe8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
6 changes: 6 additions & 0 deletions lib/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const flat = require('flat-tree')
const c = require('compact-encoding')
const b4a = require('b4a')

const empty = b4a.alloc(32)

// this is optimised for speed over mem atm
// can be tweaked in the future

Expand Down Expand Up @@ -33,6 +35,8 @@ module.exports = async function auditCore (core, update) {
const leftNode = getNode(left)
const rightNode = getNode(right)

if (!rightNode && !leftNode) continue

stack.push(leftNode, rightNode)

if (valid[node.index]) {
Expand Down Expand Up @@ -89,9 +93,11 @@ module.exports = async function auditCore (core, update) {
return corrections

function getNode (index) {
if (index * 40 + 40 > tree.byteLength) return null
const state = { start: index * 40, end: index * 40 + 40, buffer: tree }
const size = c.uint64.decode(state)
const hash = c.fixed32.decode(state)
if (size === 0 && hash.equals(empty)) return null
return { index, size, hash }
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hypercore",
"version": "10.38.0",
"version": "10.38.1",
"description": "Hypercore is a secure, distributed append-only log",
"main": "index.js",
"scripts": {
Expand Down
8 changes: 4 additions & 4 deletions test/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ test('create verifier - multi signer', async function (t) {
const asig = crypto.sign(batch.signable(verifier.manifestHash), a.secretKey)
const bsig = crypto.sign(batch.signable(verifier.manifestHash), b.secretKey)

const signature = assemble([{ signer: 0, signature: asig }, { signer: 1, signature: bsig }])
const badSignature = assemble([{ signer: 0, signature: asig }, { signer: 1, signature: asig }])
const secondBadSignature = assemble([{ signer: 0, signature: asig }, { signer: 0, signature: asig }])
const thirdBadSignature = assemble([{ signer: 0, signature: asig }])
const signature = assemble([{ signer: 0, signature: asig, patch: 0 }, { signer: 1, signature: bsig, patch: 0 }])
const badSignature = assemble([{ signer: 0, signature: asig, patch: 0 }, { signer: 1, signature: asig, patch: 0 }])
const secondBadSignature = assemble([{ signer: 0, signature: asig, patch: 0 }, { signer: 0, signature: asig, patch: 0 }])
const thirdBadSignature = assemble([{ signer: 0, signature: asig, patch: 0 }])

t.ok(verifier.verify(batch, signature))
t.absent(verifier.verify(batch, badSignature))
Expand Down

0 comments on commit 83a5fe8

Please sign in to comment.