Skip to content
Open
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
19 changes: 12 additions & 7 deletions lib/audit.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
const auditCore = require('hypercore-audit')

module.exports = async function * audit (store, { dryRun = false } = {}) {
for await (const { discoveryKey } of store.storage.createCoreStream()) {
const core = store.get({ discoveryKey, active: false })
await core.ready()
const storage = await store.storage.resume(discoveryKey)

const rx = storage.read()
const authPromise = rx.getAuth()
rx.tryFlush()

yield { discoveryKey, key: core.key, audit: await core.core.audit({ dryRun }) }
const auth = await authPromise

try {
await core.close()
} catch {
// ignore if failed, we are auditing...
yield {
discoveryKey,
key: auth ? auth.key : null,
audit: await auditCore(storage, { dryRun })
}
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"dependencies": {
"b4a": "^1.6.7",
"hypercore": "^11.0.0",
"hypercore-audit": "^1.0.0",
"hypercore-crypto": "^3.4.2",
"hypercore-errors": "^1.4.0",
"hypercore-id-encoding": "^1.3.0",
Expand Down