/** * Branded types for improved type safety. * * Branded types (also known as nominal or opaque types) allow TypeScript * to distinguish between values that have the same underlying type but * different semantic meanings. * * @remarks * All hex-based types require lowercase `0x` prefix. Uppercase `0X` is * intentionally rejected for consistency with EIP-55 and viem conventions. * * @example * ```typescript * const address: EvmAddress = toEvmAddress("0x1234..."); * const hex: HexString = toHexString("0xabcd..."); * * // These are not interchangeable even though both are strings * function requiresAddress(addr: EvmAddress) { ... } * requiresAddress(hex); // Type error! * ``` */ declare const __brand: unique symbol; /** * Creates a branded type from a base type. * The brand is purely a compile-time construct and has no runtime overhead. */ export type Brand = T & { readonly [__brand]: B; }; /** * EVM address (20 bytes, hex-encoded with 0x prefix). * Example: "0x1234567890123456789012345678901234567890" */ export type EvmAddress = Brand<`0x${string}`, "EvmAddress">; /** * Generic hex-encoded string with 0x prefix. * Used for raw bytes, transaction data, etc. * * @remarks Named HexString to avoid conflict with viem's Hex type. */ export type HexString = Brand<`0x${string}`, "HexString">; /** * ZK circuit field element (32 bytes, hex-encoded with 0x prefix). * Used in zero-knowledge proof operations. * Example: "0x0000000000000000000000000000000000000000000000000000000000000001" */ export type FieldElement = Brand<`0x${string}`, "FieldElement">; /** * Blockchain chain identifier. * Must be a positive integer. * Examples: 1n (Ethereum mainnet), 137n (Polygon), 42161n (Arbitrum) */ export type ChainId = Brand; /** * Merkle tree leaf index. * Must be a non-negative integer. */ export type LeafIndex = Brand; /** * Block number on an EVM chain. * Must be a non-negative integer. */ export type BlockNumber = Brand; /** * Checks if a string is a valid Ethereum address format. */ export declare function isEvmAddress(value: string): value is EvmAddress; /** * Checks if a string is a valid hex string with 0x prefix. */ export declare function isHexString(value: string): value is HexString; /** * Checks if a string is a valid 32-byte field element. */ export declare function isFieldElement(value: string): value is FieldElement; /** * Checks if a value is a valid chain ID (positive bigint). * Accepts `unknown` for runtime validation of external input. */ export declare function isChainId(value: unknown): value is ChainId; /** * Checks if a value is a valid leaf index (non-negative bigint). * Accepts `unknown` for runtime validation of external input. */ export declare function isLeafIndex(value: unknown): value is LeafIndex; /** * Checks if a value is a valid block number (non-negative bigint). * Accepts `unknown` for runtime validation of external input. */ export declare function isBlockNumber(value: unknown): value is BlockNumber; /** * Casts a string to EvmAddress type. * Use when you know the string is a valid address (e.g., from trusted source). * * @throws Error if the value is not a valid address format */ export declare function toEvmAddress(value: string): EvmAddress; /** * Casts a string to HexString type. * * @throws Error if the value is not a valid hex format */ export declare function toHexString(value: string): HexString; /** * Casts a string to FieldElement type. * * @throws Error if the value is not a valid field element format */ export declare function toFieldElement(value: string): FieldElement; /** * Casts a bigint to ChainId type. * * @throws Error if the value is not positive */ export declare function toChainId(value: bigint): ChainId; /** * Casts a bigint to LeafIndex type. * * @throws Error if the value is negative */ export declare function toLeafIndex(value: bigint): LeafIndex; /** * Casts a bigint to BlockNumber type. * * @throws Error if the value is negative */ export declare function toBlockNumber(value: bigint): BlockNumber; /** * Casts a string to EvmAddress type without validation. * Use only when validation has already been performed or for performance-critical paths. */ export declare function asEvmAddress(value: `0x${string}`): EvmAddress; /** * Casts a string to HexString type without validation. */ export declare function asHexString(value: `0x${string}`): HexString; /** * Casts a string to FieldElement type without validation. */ export declare function asFieldElement(value: `0x${string}`): FieldElement; /** * Casts a bigint to ChainId type without validation. */ export declare function asChainId(value: bigint): ChainId; /** * Casts a bigint to LeafIndex type without validation. */ export declare function asLeafIndex(value: bigint): LeafIndex; /** * Casts a bigint to BlockNumber type without validation. */ export declare function asBlockNumber(value: bigint): BlockNumber; export {}; //# sourceMappingURL=branded.d.ts.map