/** * Hash-chain primitives for the ForgeOS Trust Ledger. * * Binary-compatible with the Python ledger.py implementation. * * Chain hash formula (matches Python _compute_chain_hash): * chain_hash = SHA-256("{seq}:{prev_hash}:{payload_hash}:{timestamp}") * * Payload hash formula (matches Python _sha256_dict): * payload_hash = SHA-256(JSON.stringify(payload, sortedKeys)) * where JSON uses ensure_ascii=false equivalent (UTF-8) and sort_keys=True. * * The genesis sentinel is "GENESIS" (matches Python GENESIS_SENTINEL), * NOT a zero-filled hex string. */ /** Genesis sentinel value — used as prev_hash for the first entry. */ export declare const GENESIS_SENTINEL = "GENESIS"; /** Schema version constant matching the Python implementation. */ export declare const SCHEMA_VERSION = "1.0"; /** Valid entry types — must match Python ENTRY_TYPES (§5.3 of architecture spec). */ export declare const ENTRY_TYPES: Set; /** * Compute the chain hash for a ledger entry. * * Formula: SHA-256("{seq}:{prev_hash}:{payload_hash}:{timestamp}") * * This exactly replicates Python's: * material = f"{seq}:{prev_hash}:{payload_hash}:{timestamp}" * return hashlib.sha256(material.encode("utf-8")).hexdigest() * * @param seq - Zero-based integer sequence number of the entry. * @param prevHash - chain_hash of the previous entry, or GENESIS_SENTINEL for seq 0. * @param payloadHash - SHA-256 hex digest of the payload dict. * @param timestamp - ISO 8601 UTC timestamp string. * @returns 64-character hex SHA-256 digest. */ export declare function computeChainHash(seq: number, prevHash: string, payloadHash: string, timestamp: string): string; /** * Compute the payload hash for a ledger entry. * * Replicates Python's _sha256_dict: * canonical = json.dumps(d, ensure_ascii=False, sort_keys=True) * return hashlib.sha256(canonical.encode("utf-8")).hexdigest() * * Keys are sorted recursively at the top level only (matching Python's * sort_keys=True which sorts only the top-level dict keys in standard * json.dumps — nested dicts are sorted too since Python json.dumps * sort_keys=True applies recursively). * * IMPORTANT: JSON.stringify with a replacer that sorts keys at every * level is required for full binary compatibility with Python's * json.dumps(..., sort_keys=True) which sorts ALL nested dict keys. * * @param payload - The payload dict to hash. * @returns 64-character hex SHA-256 digest. */ export declare function computePayloadHash(payload: Record): string; /** * JSON serialization matching Python's json.dumps(d, ensure_ascii=False, sort_keys=True). * * CRITICAL compatibility requirement: * Python's json.dumps uses ": " (space after colon) and ", " (space after comma) * as default separators. JavaScript's JSON.stringify uses ":" and "," (no spaces). * For binary hash compatibility, we must reproduce Python's exact output. * * Python also sorts ALL dict keys recursively (sort_keys=True applies at every * nesting level). JavaScript's JSON.stringify does not sort keys. * * Python's ensure_ascii=False means non-ASCII chars pass through unescaped. * JavaScript's JSON.stringify also does not escape non-ASCII chars by default. * * This function produces output IDENTICAL to Python's json.dumps with those * settings, enabling cross-language hash chain verification. * * @param value - Value to stringify. * @returns JSON string matching Python's json.dumps output exactly. */ export declare function sortedJsonStringify(value: unknown): string; /** * Serialize value to JSON matching Python's json.dumps(ensure_ascii=False, sort_keys=True). * * Uses ": " after colons and ", " after commas — exactly Python's default separators. * Sorts all object keys recursively. Does not escape non-ASCII characters. */ export declare function pythonJsonDumps(value: unknown): string; //# sourceMappingURL=chain.d.ts.map