import type { AtribRecord } from './types.js'; /** * The session_checkpoint event_type URI (§1.2.10, D139). Pre-promotion the * log encodes entries with this URI under the `0xFF` extension byte * (§2.3.1); the signed bytes carry the URI either way, so records are * byte-identical across the promotion. */ export declare const SESSION_CHECKPOINT_EVENT_TYPE_URI = "https://atrib.dev/v1/types/session_checkpoint"; /** * The byte the promotion ADR allocates for session_checkpoint log entries * (skipping 0x07, which stays D073's design-level `handoff` reservation). * NOT allocated yet: do not encode entries under this byte until the D036 * promotion lands. Exposed so verifiers and tests can pin the §1.2.10 * byte/URI duality. */ export declare const SESSION_CHECKPOINT_PROMOTED_EVENT_TYPE_BYTE = 8; /** * §1.2.2 content_id derivation input for origin-less cognitive producers: * pseudo-origin `atrib`, tool_name `session_checkpoint`. Pinned by the * conformance corpus. */ export declare const SESSION_CHECKPOINT_CONTENT_ID_ORIGIN = "atrib"; /** * The §1.2.10 checkpoint object. All fields REQUIRED except * `prior_checkpoint` (present iff `first_index > 0`) and `retroactive` * (present-only-when-true; the `true` literal type makes * `retroactive: false` unrepresentable, mirroring the absence-not-null * contract — presence changes the JCS canonical form and the signature). */ export interface SessionCheckpoint { /** Index of the first leaf newly covered by this interval. */ first_index: number; /** Record hash of the immediately preceding checkpoint on this context. */ prior_checkpoint?: string; /** Present-only-when-true attested-backfill flag (§1.2.10.3). */ retroactive?: true; /** RFC 6962 Merkle Tree Hash over leaves 0..tree_size-1, `"sha256:"+hex`. */ session_root: string; /** Number of leaves committed; ≥ 1. */ tree_size: number; } /** A session_checkpoint record: an ordinary AtribRecord plus the checkpoint body. */ export type SessionCheckpointRecord = AtribRecord & { checkpoint: SessionCheckpoint; }; /** * Derive the §1.2.2 content_id for a session_checkpoint record. * Origin-less cognitive producers use the pseudo-origin `"atrib"`, giving * the input `"atrib:session_checkpoint"` (corpus-pinned). Producers with a * service origin pass their normalized origin, mirroring directory_anchor. */ export declare function sessionCheckpointContentId(origin?: string): string; /** * Decode an ordered list of `"sha256:<64-hex>"` record-hash refs into the * raw 32-byte leaf values the session tree is built over (§1.2.10.1 leaf * rule). Throws on any malformed ref. */ export declare function sessionLeavesFromRefs(refs: readonly string[]): Uint8Array[]; /** * Compute the §1.2.10.1 session root over an ordered 32-byte record-hash * list. Reuses the §2.3.2 RFC 6962 helpers verbatim (leaf preimages here * are the raw 32-byte hashes; log entries have 90-byte preimages, so * cross-tree confusion is structurally impossible). Returns the * `"sha256:" + 64-hex` form carried in `checkpoint.session_root`. * * Throws on an empty list (empty checkpoints prohibited) or any non-32-byte * leaf (a tree over the UTF-8 display strings MUST NOT match). */ export declare function computeSessionRoot(recordHashes: readonly Uint8Array[]): string; /** * D099 local content commitment for a checkpoint record: * `args_hash = sha256(JCS({"leaves": [...ordered "sha256:" refs...]}))`. * The flat leaf list itself stays in `_local.content.leaves` in the mirror; * any party handed the list can replay both this commitment and the root. */ export declare function sessionCheckpointArgsHash(leafRefs: readonly string[]): string; export interface BuildCheckpointBodyOptions { /** Ordered raw 32-byte record hashes of every covered leaf (0..tree_size-1). */ recordHashes: readonly Uint8Array[]; /** Index of the first leaf newly covered by this interval. */ firstIndex: number; /** * Record hash of the immediately preceding checkpoint on this context. * MUST be present iff `firstIndex > 0` (§1.2.10). */ priorCheckpoint?: string | undefined; /** * Attested-backfill flag. Only `true` is representable in the body; * `false`/`undefined` produce the canonical absent form (absence-not-null). */ retroactive?: boolean | undefined; } /** * Build a structurally valid §1.2.10 checkpoint object. Throws on any * violation of the validator rules (the emit-pipeline wrapper catches and * degrades per §5.8). `retroactive` is included only when strictly `true`. */ export declare function buildCheckpointBody(opts: BuildCheckpointBodyOptions): SessionCheckpoint; export interface BuildSessionCheckpointRecordOptions { /** Producer public key, base64url (the same key that will sign). */ creatorKey: string; /** 32-hex session anchor the checkpoint commits over. */ contextId: string; /** * chain_root resolved through the normal D067 precedence * (`resolveChainRoot` / `inheritChainContext` — never reimplemented here). */ chainRoot: string; /** Structurally valid checkpoint body (see buildCheckpointBody). */ checkpoint: SessionCheckpoint; /** Record timestamp; defaults to Date.now(). */ timestamp?: number | undefined; /** * Ordered `"sha256:"` refs of the covered leaves. Used for the D099 * default `args_hash` and self-checked against the checkpoint body * (length == tree_size, recomputed root == session_root). */ leafRefs?: readonly string[] | undefined; /** Explicit §8.3 args_hash override; required when leafRefs are omitted. */ argsHash?: string | undefined; /** §1.2.2 content_id origin; defaults to the `atrib` pseudo-origin. */ contentIdOrigin?: string | undefined; /** * Optional §1.2.5 informed_by refs (e.g. the prior checkpoint hash, per * the §1.2.10.4 MAY). Sorted lexicographically before assembly. */ informedBy?: readonly string[] | undefined; } /** * Assemble the unsigned session_checkpoint record (signature: '') ready for * the existing signing owner (`signRecord`). This function does NOT sign — * there is exactly one signing path and it is not here. * * JCS slotting: `checkpoint` sorts between `chain_root` and `content_id`; * object-literal order is irrelevant because signing canonicalizes. */ export declare function buildSessionCheckpointRecord(opts: BuildSessionCheckpointRecordOptions): SessionCheckpointRecord; /** * Generate the inclusion proof for the session leaf at `index`. Delegates to * the §2.3.2/§2.7 helper (`computeInclusionProof`), which hashes each raw * leaf with the 0x00 domain prefix internally. Throws on empty trees, * out-of-range indexes, or non-32-byte leaves. */ export declare function sessionInclusionProof(index: number, recordHashes: readonly Uint8Array[]): Uint8Array[]; export interface VerifySessionInclusionOptions { /** 0-based leaf index the proof claims. */ index: number; /** The checkpoint's tree_size. */ treeSize: number; /** Raw 32-byte record hash of the leaf, or its `"sha256:"` ref. */ recordHash: Uint8Array | string; /** Sibling hashes, leaf to root. */ proof: readonly Uint8Array[]; /** The checkpoint's session_root (`"sha256:"+hex`). */ sessionRoot: string; } /** * Verify an inclusion proof of a record hash against a session_root. * Never throws; malformed input returns false. */ export declare function verifySessionInclusion(opts: VerifySessionInclusionOptions): boolean; /** * Generate the RFC 6962 §2.1.2 consistency proof * `PROOF(firstTreeSize, D[recordHashes])` from a prior checkpoint's tree * size to the current full leaf list. Subtree roots come from the same * §2.3.2 `computeRoot` helper the session root uses. Throws when * `firstTreeSize` is out of range or leaves are malformed. */ export declare function sessionConsistencyProof(firstTreeSize: number, recordHashes: readonly Uint8Array[]): Uint8Array[]; export interface VerifySessionConsistencyOptions { /** The prior checkpoint's tree_size. */ firstTreeSize: number; /** The later checkpoint's tree_size. */ secondTreeSize: number; /** The prior checkpoint's session_root (`"sha256:"+hex`). */ firstRoot: string; /** The later checkpoint's session_root (`"sha256:"+hex`). */ secondRoot: string; /** RFC 6962 §2.1.2 consistency proof nodes. */ proof: readonly Uint8Array[]; } /** * RFC 6962 §2.1.4.2 consistency-proof verification: proves the later tree * is an append-only extension of the earlier one. Never throws; malformed * input returns false. */ export declare function verifySessionConsistency(opts: VerifySessionConsistencyOptions): boolean; /** * Equivocation evidence per §1.2.10.2: two signed checkpoints from the same * creator_key on the same context claiming the same prior (or overlapping * ranges) with provably inconsistent roots. The pair itself is the * evidence; both signatures are genuine. */ export interface SessionCheckpointEquivocationEvidence { creator_key: string; context_id: string; reason: 'divergent-roots-same-claim' | 'append-only-violation'; prior_checkpoint?: string; first_record_hash: string; second_record_hash: string; first: { session_root: string; tree_size: number; first_index: number; }; second: { session_root: string; tree_size: number; first_index: number; }; } /** * Detect the direct §1.2.10.2 equivocation pair: same creator_key, same * context_id, same prior_checkpoint claim (or overlapping covered ranges) * with the same tree_size but divergent session_root values. Pairs with * different tree sizes need leaf material to prove divergence — use * `checkConsecutiveSessionCheckpoints` with `secondLeaves` for those. * Returns undefined when the pair is not (provably) equivocating. */ export declare function detectSessionCheckpointEquivocation(a: SessionCheckpointRecord, b: SessionCheckpointRecord): SessionCheckpointEquivocationEvidence | undefined; export interface CheckConsecutiveSessionCheckpointsOptions { /** * Ordered raw 32-byte leaves of the SECOND checkpoint's tree. When * supplied, the consistency proof is generated and verified from them. */ secondLeaves?: readonly Uint8Array[] | undefined; /** Pre-generated §2.1.2 consistency proof (used when secondLeaves absent). */ consistencyProof?: readonly Uint8Array[] | undefined; } export interface ConsecutiveSessionCheckpointCheck { /** second.prior_checkpoint equals the first checkpoint's record hash. */ priorCheckpointMatches: boolean; /** second.first_index equals first.tree_size. */ firstIndexMatchesPriorTreeSize: boolean; /** * RFC 6962 §2.1.4.2 result; undefined when neither leaves nor a proof * were supplied (linkage-only check). */ consistencyProofVerifies: boolean | undefined; /** All checkable §1.2.10.2 constraints hold. */ consistent: boolean; /** Populated when linked claims carry provably divergent roots. */ equivocation?: SessionCheckpointEquivocationEvidence; } /** * Check the §1.2.10.2 consecutive-checkpoint contract for K_i → K_{i+1}: * prior_checkpoint linkage, first_index continuation, and (when leaf or * proof material is available) the RFC 6962 append-only consistency proof. * A linked pair whose proof fails is surfaced as equivocation evidence * against the creator_key. Never throws; malformed material degrades to * `consistencyProofVerifies: false`. */ export declare function checkConsecutiveSessionCheckpoints(first: SessionCheckpointRecord, second: SessionCheckpointRecord, opts?: CheckConsecutiveSessionCheckpointsOptions): ConsecutiveSessionCheckpointCheck; //# sourceMappingURL=session-checkpoint.d.ts.map