import type { ContextItem, ContextChannel } from './types.js'; /** Leaf pre-image domain tag. */ export declare const LEAF_TAG = "CPA:v0.1:leaf\n"; /** Internal-node domain tag. */ export declare const NODE_TAG = "CPA:v0.1:node\n"; /** Signing / cpa_ref domain tag (used only for cpa_ref). */ export declare const SIGN_TAG = "CPA:v0.1:sign\n"; declare function utf8(s: string): Uint8Array; /** * The leaf pre-image: EXACTLY these four fields. content and trust_tier * are EXCLUDED so the root is identical whether or not content is later * disclosed. JCS sorts keys, so field order here is irrelevant. */ export interface LeafPreimage { byte_len: number; channel: ContextChannel; content_ref: string; ctx_id: string; } /** Extract the canonical leaf pre-image from a context item. */ export declare function leafPreimage(leaf: ContextItem): LeafPreimage; /** leaf_hash = sha256( utf8(LEAF_TAG) || utf8(canonicalizeJCS(preimage)) ) * Returns the raw 32-byte digest. */ export declare function leafHash(leaf: ContextItem): Uint8Array; /** Write-boundary twin of leafHash(). * * Emits the same bytes as leafHash() for every value it accepts. The only difference * is that an integer-valued number outside the interoperable IEEE 754 range is * refused instead of serialized. Use at signing and new-write boundaries ONLY: * leafHash() stays unrestricted so an artifact signed before this rule keeps * verifying. */ export declare function leafHashForWrite(leaf: ContextItem): Uint8Array; /** node_hash = sha256( utf8(NODE_TAG) || left32 || right32 ) over RAW * 32-byte digests. Returns the raw 32-byte digest. */ export declare function nodeHash(left: Uint8Array, right: Uint8Array): Uint8Array; export declare function buildPartitionRootBytes(leaves: ContextItem[]): Uint8Array; /** Write-boundary twin of buildPartitionRootBytes(). * * Reaches a canonicalizer only indirectly, through leafHash, so a call-site census * over canonicalizer usage cannot see it. Use when BUILDING a CPA; the recompute path * in verify.ts keeps calling buildPartitionRootBytes() so a CPA signed before this * rule still verifies. */ export declare function buildPartitionRootBytesForWrite(leaves: ContextItem[]): Uint8Array; /** Hex convenience wrapper around buildPartitionRootBytes. */ export declare function buildPartitionRoot(leaves: ContextItem[]): string; /** * Build the top root (raw 32-byte digest) over present partition roots. * Input is the ordered list of RAW 32-byte partition_root digests, taken * in CHANNEL_ORDER by the caller. Same NODE_TAG odd-promotion rule. * - Zero partitions => EMPTY sentinel: sha256( utf8(NODE_TAG) || * utf8("EMPTY") ). * - One partition => root = that partition_root. */ export declare function buildTopRootBytes(partitionRootsInChannelOrder: Uint8Array[]): Uint8Array; /** Hex convenience wrapper around buildTopRootBytes. */ export declare function buildTopRoot(partitionRootsInChannelOrder: string[]): string; /** The frozen empty-tree top root, as 64-hex. Signable sentinel. */ export declare function emptyTreeRoot(): string; export declare function bytesToHex(bytes: Uint8Array): string; export declare function hexToBytes(hex: string): Uint8Array; export { utf8 as utf8Bytes }; /** One audit step: the sibling digest (64-hex) and which side it sits on. * side === 'left' => fold as node_hash(sibling, acc) * side === 'right' => fold as node_hash(acc, sibling) */ export interface InclusionStep { sibling: string; side: 'left' | 'right'; } /** An inclusion proof for one leaf, identified by its ctx_id. The path is * ordered bottom-up (leaf level first). */ export interface InclusionProof { ctx_id: string; path: InclusionStep[]; } export declare function buildInclusionProof(leaves: ContextItem[], ctx_id: string): InclusionProof; /** Write-boundary twin of buildInclusionProof(). * * Reaches a canonicalizer only indirectly, through leafHash, so a call-site census over * canonicalizer usage cannot see it. Use when BUILDING a CPA; verifyInclusionProof keeps * calling leafHash() unrestricted so a proof emitted before this rule still checks. */ export declare function buildInclusionProofForWrite(leaves: ContextItem[], ctx_id: string): InclusionProof; /** * Verify an inclusion proof: recompute leaf_hash(leaf), fold the path with * node_hash respecting each step's side, and compare the hex result to * partition_root. Returns false on any structural problem or mismatch * (fail-closed; never throws on malformed proof material). */ export declare function verifyInclusionProof(leaf: ContextItem, proof: InclusionProof, partition_root: string): boolean; //# sourceMappingURL=merkle.d.ts.map