UNPKG

@lifi/compose-spec

Version:

Public wire-format types and schemas for Compose flows

33 lines (27 loc) • 1.84 kB
// Shared string patterns and bounds for the compose wire format. // Zero-dependency leaf so both the Effect-schema side (`flowSchema.ts`, // `continuation.ts`, `descriptor.ts`) and the standalone Zod mirror // (`zodSchemas.ts`) consume one source of truth without importing across // layers. compose-spec is the wire-format leaf and may not import `@lifi/utils` // (enforced by `scripts/check-compose-boundaries.mjs`), so the equivalents of // `makeHexStringRegex(32, { lowercase: true })` and `MaxUint256` are inlined // here. // A `0x`-prefixed, exactly-32-byte, STRICTLY lowercase hex string. Validated // strictly — deliberately overriding compose-spec's lenient `0x`-prefix-only // convention for address fields. These hashes (`validationProgramHash`, // `paramsHash`) are machine-generated (ethers `keccak256` emits lowercase) and // never hand-typed, so strictness costs nothing; leniency would admit two // serializations of one hash (mixed case) and truncated values, both of which // poison determinism and the byte-identity fixture discipline. A zero hash // `0x00…00` (64 zeros) remains valid under the strict rule. export const BYTES32_LOWER_HEX = /^0x[0-9a-f]{64}$/; // A `0x`-prefixed 20-byte EVM address, hex digits in either case (EIP-55 // checksums are mixed-case); the prefix itself must be lowercase. export const EVM_ADDRESS_HEX = /^0x[0-9a-fA-F]{40}$/; // A decimal integer string with no sign, fraction, exponent or hex prefix. export const DECIMAL_UINT = /^[0-9]+$/; // eslint-disable-next-line @lifi/prefer-utils-constants -- see the header: compose-spec may not import @lifi/utils export const MAX_UINT256 = 2n ** 256n - 1n; // The largest epoch-millisecond magnitude a JS `Date` holds (ECMA-262 // §21.4.1.1); an expiry outside it has no ISO-8601 form to register. export const MAX_DATE_MS = 8.64e15;