import { StoredAuditEntry } from "./types.js"; import { AuditDb } from "./audit-db.js"; //#region src/audit/merkle.d.ts /** RFC 6962 leaf hash: `SHA-256(0x00 || leaf-bytes)`. */ declare function leafHash(entry: StoredAuditEntry): Buffer; /** * RFC 6962 §2.1 Merkle Tree Hash over ordered leaf hashes. The empty * tree hashes to `SHA-256()` per the RFC. */ declare function merkleTreeHash(leaves: ReadonlyArray): Buffer; /** * Tree head of the audit log at a given size: the anchor unit for * checkpointing and proofs. * * @stable */ interface AuditTreeHead { /** Number of leaves (audit entries) covered. */ readonly size: number; /** Hex Merkle root (`SHA-256`, RFC 6962). */ readonly rootHash: string; /** `seq` of the newest covered entry (`0` for the empty log). */ readonly lastSeq: number; } /** * Compute the current (or historical, via `toSeq`) Merkle tree head of * the audit log. * * @stable */ declare function computeAuditTreeHead(db: AuditDb, opts?: { readonly toSeq?: number; }): Promise; /** * Inclusion proof that the entry at `seq` is covered by `head`. * * @stable */ interface AuditInclusionProof { readonly seq: number; /** 0-based leaf index within the tree of `treeSize` leaves. */ readonly leafIndex: number; readonly treeSize: number; /** Bottom-up audit path, hex node hashes. */ readonly path: ReadonlyArray; } /** * Produce an RFC-6962 inclusion proof for the entry at `seq` against * the head of size `head.size`. Throws when the entry is not covered. * * @stable */ declare function proveAuditInclusion(db: AuditDb, seq: number, head: AuditTreeHead): Promise; /** * Verify an inclusion proof (RFC 6962 §2.1.1 verification algorithm) - * pure; needs only the entry, the proof, and the trusted head. * * @stable */ declare function verifyAuditInclusion(entry: StoredAuditEntry, proof: AuditInclusionProof, head: AuditTreeHead): boolean; /** * Produce an RFC-6962 consistency proof that the log at `older.size` * is a prefix of the log at `newer.size`. * * @stable */ declare function proveAuditConsistency(db: AuditDb, older: AuditTreeHead, newer: AuditTreeHead): Promise>; /** * Verify a consistency proof between two heads (RFC 6962 §2.1.2). A * `true` result means `newer` is an append-only extension of `older` - * nothing covered by `older` was rewritten, reordered, or truncated. * * @stable */ declare function verifyAuditConsistency(older: AuditTreeHead, newer: AuditTreeHead, proof: ReadonlyArray): boolean; /** * Ed25519-signed audit checkpoint (a signed tree head). Persist it * anywhere outside the writer's reach (a different host, an object * store, a ticket) - any later rewrite of the covered prefix fails the * consistency proof against it. * * @stable */ interface SignedAuditCheckpoint { readonly head: AuditTreeHead; /** Stable id of the signing writer (operator / CI / host). */ readonly writerId: string; /** ISO-8601 signing time. */ readonly signedAt: string; /** base64url Ed25519 signature over the canonical checkpoint body. */ readonly signature: string; /** PEM (SPKI) public key - carried for convenience; pin it separately. */ readonly publicKeyPem: string; } /** * Generate an Ed25519 keypair for audit-checkpoint signing (PEM SPKI / * PKCS8). Convenience for operators without existing key material. * * @stable */ declare function generateAuditSigningKeyPair(): { readonly publicKeyPem: string; readonly privateKeyPem: string; }; /** * Compute and sign the current tree head. * * @stable */ declare function signAuditCheckpoint(db: AuditDb, opts: { readonly privateKeyPem: string; readonly writerId: string; /** Override the wall clock - used by tests. */ readonly now?: () => number; }): Promise; /** * Verify a signed checkpoint's Ed25519 signature against a pinned * public key (pure - no database access). * * @stable */ declare function verifyAuditCheckpointSignature(checkpoint: SignedAuditCheckpoint, publicKeyPem: string): boolean; /** * Full anchored verification: the checkpoint's signature is valid * against the pinned key AND the current log is an append-only * extension of the checkpointed head (consistency proof computed and * verified over the live database). * * @stable */ declare function verifyAuditAgainstCheckpoint(db: AuditDb, checkpoint: SignedAuditCheckpoint, opts: { readonly publicKeyPem: string; }): Promise<{ readonly ok: true; readonly current: AuditTreeHead; } | { readonly ok: false; readonly reason: 'bad-signature' | 'inconsistent-log'; readonly current?: AuditTreeHead; }>; //#endregion export { AuditInclusionProof, AuditTreeHead, SignedAuditCheckpoint, computeAuditTreeHead, generateAuditSigningKeyPair, leafHash, merkleTreeHash, proveAuditConsistency, proveAuditInclusion, signAuditCheckpoint, verifyAuditAgainstCheckpoint, verifyAuditCheckpointSignature, verifyAuditConsistency, verifyAuditInclusion }; //# sourceMappingURL=merkle.d.ts.map