/** * JSON Canonicalization Scheme (JCS) per RFC 8785. * * This module provides deterministic JSON serialization to ensure * consistent signatures regardless of JSON serialization variations. * * RFC 8785 Rules: * 1. Objects: keys sorted by UTF-16 code unit values (lexicographic for ASCII) * 2. Arrays: elements in original order * 3. Strings: UTF-8 with minimal escape sequences * 4. Numbers: no leading zeros, no trailing zeros after decimal * 5. No whitespace between tokens */ import { BelticError } from '../errors/base.js'; /** * Error during JSON canonicalization. */ export declare class CanonicalizationError extends BelticError { constructor(message: string, details?: Record); } /** * Canonicalize JSON data per RFC 8785. * * This function produces a deterministic JSON representation that * will always produce the same bytes for semantically equivalent data. * * @param data - JavaScript value to canonicalize (object, array, string, number, boolean, null) * @returns Canonical UTF-8 bytes as Uint8Array * @throws CanonicalizationError if data cannot be canonicalized (e.g., NaN, Infinity) * * @example * ```typescript * canonicalize({ b: 1, a: 2 }) * // Returns Uint8Array for '{"a":2,"b":1}' * * canonicalize([1, 2, 3]) * // Returns Uint8Array for '[1,2,3]' * ``` */ export declare function canonicalize(data: unknown): Uint8Array; /** * Canonicalize JSON data to a string. * * @param data - JavaScript value to canonicalize * @returns Canonical JSON string */ export declare function canonicalizeToString(data: unknown): string; /** * Compute hash of canonicalized JSON. * * @param data - Data to hash * @param algorithm - Hash algorithm (sha256, sha384, sha512) * @returns Hash digest bytes as Uint8Array * * @example * ```typescript * const hash = await computeCanonicalHash({ hello: 'world' }); * ``` */ export declare function computeCanonicalHash(data: unknown, algorithm?: 'SHA-256' | 'SHA-384' | 'SHA-512'): Promise; /** * Compute base64url-encoded hash of canonicalized JSON. * * @param data - Data to hash * @param algorithm - Hash algorithm (SHA-256, SHA-384, SHA-512) * @returns Base64url-encoded hash string */ export declare function computeCanonicalHashB64(data: unknown, algorithm?: 'SHA-256' | 'SHA-384' | 'SHA-512'): Promise; /** * Verify that data matches expected canonical hash. * * @param data - Data to verify * @param expectedHash - Expected base64url-encoded hash * @param algorithm - Hash algorithm used * @returns True if hash matches, false otherwise */ export declare function verifyCanonicalHash(data: unknown, expectedHash: string, algorithm?: 'SHA-256' | 'SHA-384' | 'SHA-512'): Promise; //# sourceMappingURL=canonicalize.d.ts.map