//#region src/keyformat/key-format.d.ts /** * Key formatting utilities for IAVL storage. * * Provides a fixed-width lexicographically sortable byte key format. * Based on Go IAVL keyformat/key_format.go */ /** * Provides a fixed-width lexicographically sortable byte key format. * * Create a byte key format based on a single byte prefix and fixed width key segments * each of whose length is specified by the corresponding element of layout. * * For example, to store keys that could index some objects by a version number and * their SHA256 hash using the form: 'c' then you * would define the KeyFormat with: * * ```typescript * const keyFormat = new KeyFormat('c'.charCodeAt(0), 8, 32); * ``` * * Then you can create a key with: * ```typescript * function ObjectKey(version: bigint, objectBytes: Uint8Array): Uint8Array { * const hasher = sha256(objectBytes); * return keyFormat.key(version, hasher); * } * ``` * * If the last term of the layout is 0 it is unbounded, and will accept any length. */ declare class KeyFormat { private readonly prefix; private readonly layout; private readonly length; private readonly unbounded; /** * Creates a new key format. * @param prefix - Single byte prefix for the key format * @param layout - Array of segment lengths. Last element can be 0 for unbounded. * @throws If any element except the last is 0 */ constructor(prefix: number, ...layout: number[]); /** * Format the byte segments into the key format. * @param segments - Byte arrays to format * @returns Formatted key * @throws If segment lengths do not match layout */ keyBytes(...segments: Uint8Array[]): Uint8Array; /** * Format the args passed into the key format. * @param args - Arguments to format (number, bigint, or Uint8Array) * @returns Formatted key * @throws If arguments don't match layout */ key(...args: (number | bigint | Uint8Array)[]): Uint8Array; /** * Reads out the bytes associated with each segment of the key format from key. * @param key - Key to scan * @returns Array of byte segments */ scanBytes(key: Uint8Array): Uint8Array[]; /** * Extracts the segments into values. * @param key - Key to scan * @param types - Array of types to extract ('bigint', 'uint32', 'int32', 'bytes') * @returns Array of extracted values */ scan(key: Uint8Array, types: Array<"bigint" | "uint32" | "int32" | "bytes">): Array; /** * Get the total length of the key format. */ getLength(): number; /** * Get the prefix as a string. */ getPrefix(): string; /** * Format a value into bytes. */ private format; /** * Format a bigint as big-endian bytes (8 bytes for compatibility). */ private formatBigInt; /** * Format a uint32 as big-endian bytes. */ private formatUint32; } /** * Fast prefix formatter for simple prefix-based keys. * Used for node keys and other simple formats. */ declare class FastPrefixFormatter { private readonly prefix; private readonly length; constructor(prefix: number, length: number); /** * Create a key with the prefix and value. */ key(value: Uint8Array): Uint8Array; /** * Extract the value from a prefixed key. */ scan(key: Uint8Array): Uint8Array; } /** * Key format for node storage: s */ declare const nodeKeyFormat: FastPrefixFormatter; /** * Key format for fast nodes: f */ declare const fastKeyFormat: KeyFormat; /** * Key format for metadata: m */ declare const metadataKeyFormat: KeyFormat; /** * Legacy key format for nodes: n */ declare const legacyNodeKeyFormat: FastPrefixFormatter; /** * Legacy key format for orphans: o */ declare const legacyOrphanKeyFormat: KeyFormat; /** * Legacy key format for roots: r */ declare const legacyRootKeyFormat: KeyFormat; /** * Create a node key from version and nonce. */ declare function formatNodeKey(version: bigint, nonce: number): Uint8Array; /** * Extract version and nonce from a node key. */ declare function parseNodeKey(key: Uint8Array): { version: bigint; nonce: number; }; //#endregion export { FastPrefixFormatter, KeyFormat, fastKeyFormat, formatNodeKey, legacyNodeKeyFormat, legacyOrphanKeyFormat, legacyRootKeyFormat, metadataKeyFormat, nodeKeyFormat, parseNodeKey }; //# sourceMappingURL=key-format.d.cts.map