Files
bare-operating-system/packages/bare-os-booter/lib/bare-os-audit-chain.js
T
Raven Scott 8f2e3cceb0 Move editable kernel bulk from kernel/init-main.js to kernel/lib/init/
(staged as /lib/init/init-main.js); point bundle-kernel-init and verify
scripts at the new path.

Wire curl, wget, openssl, ssh-keygen, and tar through coreutils and
booter host delegates with booter-side CLI helpers; refresh related
bins, bare manifest, shell completion, and man DB (kernel + seeder).

Add booter support modules for ACL evaluation, audit chain, secret
handles, peer admission, replication priority, process table, swarm
lifecycle, boot-graph proc, metrics, monotonic time, protomux alias
registry, and swarm peer policy; extend extension resolver, VFS,
swarm connection managers, IPC, identity-account, and initd.

Harden bare-os-bare-libs build on esbuild failure; add verify scripts
for extension manifest schema and runtime incomplete markers; extend
ctx API typings, gen-ctx-client-stub, and verify-ctx-dts.

Update boot hook fragment, bundled init.js, handbook and reference
docs (incl. kernel security and VFS path classes).
2026-04-04 17:51:47 -04:00

57 lines
1.2 KiB
JavaScript

/**
* Tamper-evident in-session audit chain (hash-linked NDJSON rows; no persistence unless host appends).
*/
import bareCrypto from 'bare-crypto'
const { createHash } = bareCrypto
/** @type {string | null} */
let chainHeadHex = null
let seq = 0
function hexU8(u8) {
let s = ''
for (let i = 0; i < u8.length; i++) s += u8[i].toString(16).padStart(2, '0')
return s
}
/**
* @param {Record<string, unknown>} entry
* @returns {{ seq: number, entryHash: string, prevHash: string | null }}
*/
export function bareOsAuditAppend(entry) {
seq++
const prev = chainHeadHex
const payload = JSON.stringify({
seq,
ts: Date.now(),
prev: prev,
...entry
})
const h = createHash('sha256')
h.update(prev || '')
h.update('\n')
h.update(payload)
const digest = h.digest()
const u8 = digest instanceof Uint8Array ? digest : new Uint8Array(digest)
chainHeadHex = hexU8(u8)
return { seq, entryHash: chainHeadHex, prevHash: prev }
}
export function bareOsAuditChainHead() {
return chainHeadHex
}
export function bareOsAuditChainLength() {
return seq
}
export function bareOsAuditChainSnapshot() {
return {
schema: 1,
length: seq,
headHex: chainHeadHex,
atMs: Date.now()
}
}