@hyperlane-xyz/sdk
Version:
The official SDK for the Hyperlane Network
44 lines • 2.41 kB
TypeScript
/**
* The types defined here are the source of truth for chain metadata.
* ANY CHANGES HERE NEED TO BE REFLECTED IN HYPERLANE-BASE CONFIG PARSING.
*/
import { z } from 'zod';
/**
* Creates a forward-compatible Zod schema for enums that normalizes unknown values.
*
* When registry is updated with new enum values, older SDK versions will parse
* the unknown value as the specified `unknownValue` instead of failing entirely.
*
* This enables:
* - Old SDK + New Registry: Works - unknown values become `Unknown` variant
* - New SDK + Old Registry: Works - known values parse normally
* - TypeScript exhaustiveness checking forces explicit handling of unknown cases
*
* @param enumObj - The enum or const object to validate against
* @param unknownValue - The value to use for unknown/new enum variants
* @returns A Zod schema that accepts any string but normalizes unknown values
*
* @example
* ```ts
* const zProtocolType = forwardCompatibleEnum(ProtocolType, ProtocolType.Unknown);
* zProtocolType.parse('ethereum'); // => ProtocolType.Ethereum
* zProtocolType.parse('newprotocol'); // => ProtocolType.Unknown
* ```
*/
export declare function forwardCompatibleEnum<T extends Record<string, string>>(enumObj: T, unknownValue: T[keyof T]): z.ZodEffects<z.ZodUnion<[z.ZodNativeEnum<T>, z.ZodString]>, T[keyof T]>;
/** Zod uint schema */
export declare const ZUint: z.ZodNumber;
/** Zod NonZeroUint schema */
export declare const ZNzUint: z.ZodNumber;
/** Zod unsigned Wei schema which accepts either a string number or a literal number */
export declare const ZUWei: z.ZodUnion<[z.ZodNumber, z.ZodString]>;
/** Zod 128, 160, 256, or 512 bit hex-defined hash with a 0x prefix for hex and no prefix for base58 */
export declare const ZHash: z.ZodString;
/** Zod ChainName schema */
export declare const ZChainName: z.ZodString;
export declare const ZBigNumberish: z.ZodEffects<z.ZodUnion<[z.ZodUnion<[z.ZodBigInt, z.ZodNumber]>, z.ZodString]>, bigint, string | number | bigint>;
/** Zod BPS (basis points) schema — accepts number or decimal string, transforms to number.
* Supports fractional values (e.g., 1.5 bps). */
export declare const ZBps: z.ZodEffects<z.ZodEffects<z.ZodUnion<[z.ZodNumber, z.ZodString]>, number, string | number>, number, string | number>;
export declare const ZBytes32String: z.ZodEffects<z.ZodString, string, string>;
//# sourceMappingURL=customZodTypes.d.ts.map