import { Hex } from "viem"; import type { Checksum } from "../types/checksum.js"; import type { InteroperableAddress, InteroperableAddressBinary, InteroperableAddressText } from "../types/interopAddress.js"; type EncodeFormat = "hex" | "bytes"; export type FormatResult = T extends "hex" ? Hex : T extends "bytes" ? Uint8Array : Hex | Uint8Array; /** * Parses an interoperable address from its EIP-7930 byte/hex representation. * * @param value - The binary address as Uint8Array or Hex string * @param opts - Decoding options * @param opts.representation - Representation to return: "binary" or "text" (defaults to "text") * @returns InteroperableAddress with the specified representation * @example * ```ts * // Get text representation (default) * const textAddr = decodeAddress("0x00010000010114d8da6bf26964af9d7eed9e03e53415D37aa96045"); * * // Get binary representation * const binaryAddr = decodeAddress("0x00010000010114d8da6bf26964af9d7eed9e03e53415D37aa96045", { representation: "binary" }); * ``` */ export declare function decodeAddress(value: Uint8Array | Hex, opts: { representation: "binary"; }): InteroperableAddressBinary; export declare function decodeAddress(value: Uint8Array | Hex, opts?: { representation?: "text"; }): InteroperableAddressText; /** * Serializes an `InteroperableAddress` into the EIP-7930 byte layout. * * Accepts either binary or text representation and converts internally if needed. * * Layout (big-endian): * - version: 2 bytes * - chainType: 2 bytes * - chainReferenceLength: 1 byte * - chainReference: N bytes * - addressLength: 1 byte * - address: M bytes * * @param addr - The interoperable address (binary or text representation) * @param opts - Encoding options * @param opts.format - Output format: "hex" or "bytes" * @returns The encoded address in the specified format * @example * ```ts * // Encode text representation * const hex = encodeAddress({ version: 1, chainType: "eip155", chainReference: "1", address: "0x..." }, { format: "hex" }); * * // Encode binary representation * const hex2 = encodeAddress(binaryAddr, { format: "hex" }); * ``` */ export declare const encodeAddress: (addr: InteroperableAddress, opts?: { format?: T; }) => FormatResult; /** * Converts a text representation to a binary representation. * * @param addr - InteroperableAddress with text representation * @returns InteroperableAddress with binary representation * @throws {InvalidInteroperableAddress} If the address is invalid * @example * ```ts * const textAddr = { * version: 1, * chainType: "eip155", * chainReference: "1", * address: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045" * }; * const binaryAddr = toBinaryRepresentation(textAddr); * ``` */ export declare function toBinaryRepresentation(addr: InteroperableAddress): InteroperableAddressBinary; /** * Converts a binary representation to a text representation. * * @param addr - InteroperableAddress with binary representation * @returns InteroperableAddress with text representation * @throws {UnsupportedChainType} If the chain type is not supported * @example * ```ts * const binaryAddr = decodeAddress("0x00010000010114d8da6bf26964af9d7eed9e03e53415D37aa96045", { representation: "binary" }); * const textAddr = toTextRepresentation(binaryAddr); * ``` */ export declare function toTextRepresentation(addr: InteroperableAddress): InteroperableAddressText; /** * Calculates a checksum for an `InteroperableAddress` as per ERC-7930. * * Accepts either binary or text representation and converts internally if needed. * * Implementation: * - Encode to hex using the canonical binary layout * - Hash the concatenation of: ChainType + ChainReferenceLength + ChainReference + AddressLength + Address * (Version field is excluded - slice(6) removes "0x" prefix + version (2 bytes = 4 hex chars)) * - Compute keccak256 hash * - Take the first 4 bytes (8 hex characters) of the hash * - Return as uppercase hexadecimal string (RFC 4648 Base 16 Alphabet [0-9A-F]) * * The checksum is validated through ChecksumSchema.safeParse(), which returns a result. * If validation fails, we throw a specific error. Since we generate the checksum from * a hash, it will always be valid, but we validate for type safety. * * @param addr - The interoperable address (binary or text representation) * @returns The calculated checksum (8-character uppercase hex string) * @throws {Error} If the calculated checksum string doesn't match the schema (should never happen) */ export declare const calculateChecksum: (addr: InteroperableAddress) => Checksum; /** * Validates an InteroperableAddress structure using the zod schema. * * This ensures the address conforms to EIP-7930 requirements: * - Valid version * - ChainType is valid (Uint8Array for binary, "eip155" | "solana" for text) * - ChainReference is valid (Uint8Array for binary, string for text, if present) * - Address is valid (Uint8Array for binary, string for text, if present) * * The schema normalizes chainType.binary by padding/trimming to exactly 2 bytes via transform. * * @param interopAddress - The interoperable address to validate (binary or text representation) * @returns The validated interoperable address * @throws {InvalidInteroperableAddress} If the address doesn't match the schema */ export declare const validateInteroperableAddress: (interopAddress: InteroperableAddress) => InteroperableAddress; /** * Validates the checksum of an InteroperableAddress against its calculated checksum. * * Accepts either binary or text representation and converts internally if needed. * * @param interopAddress - The interoperable address to validate (binary or text representation) * @param checksum - The checksum to validate against * @param options - Validation options * @param options.isENSName - Whether the address is an ENS name (affects error type) * @throws {InvalidChecksum} If the checksum is invalid for a raw address * @throws {ChecksumMismatchWarning} If the checksum is invalid for an ENS name */ export interface ValidateChecksumOptions { isENSName?: boolean; } export declare const validateChecksum: (interopAddress: InteroperableAddress, checksum: Checksum, options?: ValidateChecksumOptions) => void; export {}; //# sourceMappingURL=index.d.ts.map