/** * Chain Agnostic Improvement Proposal (CAIP) identifier grammar: CAIP-2 chain ids, * CAIP-10 account ids, CAIP-19 asset ids. * * These identifiers name the chain, account, and asset a receipt refers to in a * chain-agnostic way. When such an identifier is folded into a canonicalised, * content-addressed record (see ./canonicalize.js), it becomes part of the preimage: * two verifiers must agree on its exact bytes or their hashes diverge and the record * stops recomputing. So the identifier is not merely valid or not, it must be * BYTE-CANONICAL. The strict require* forms are the pre-hash gate an offline verifier * uses to refuse a non-canonical identifier before it reaches the digest. * * Anchor discipline (cross-language note): these validators anchor with ^ and $ and * are compiled WITHOUT the multiline (m) flag. In JavaScript, $ without m matches only * the end of input, so "eip155:1\n" is correctly rejected. This differs from Python, * whose $ also matches just before a trailing \n; the Python sibling therefore anchors * with \A and \Z instead. Same grammar, byte-identical accept/reject set, arrived at by * language-appropriate anchors. A validator matrix that missed this would let some * implementations accept a trailing-newline identifier that others reject. * * Grammar (verbatim from CAIP-2/10/19, ChainAgnostic/CAIPs): * chain_id = namespace ":" reference namespace [-a-z0-9]{3,8} reference [-_a-zA-Z0-9]{1,32} * account_id = chain_id ":" address address [-.%a-zA-Z0-9]{1,128} * asset_type = chain_id "/" ns ":" ref asset ns [-a-z0-9]{3,8} asset ref [-.%a-zA-Z0-9]{1,128} * asset_id = asset_type "/" token_id token_id [-.%a-zA-Z0-9]{1,78} * * Licensed under Apache 2.0. */ /** Raised by the require* gates when an identifier is not byte-canonical CAIP. */ export declare class CaipError extends Error { constructor(message: string); } /** True iff `s` is a byte-canonical CAIP-2 chain id. */ export declare function isCaip2(s: unknown): boolean; /** True iff `s` is a byte-canonical CAIP-10 account id. */ export declare function isCaip10(s: unknown): boolean; /** True iff `s` is a byte-canonical CAIP-19 asset type or asset id. */ export declare function isCaip19(s: unknown): boolean; /** * Return `s` unchanged if it is a canonical CAIP-2, else throw {@link CaipError}. * The pre-hash gate: call it on any chain id before it is folded into a canonicalised * record, so a non-canonical identifier fails closed rather than silently producing a * non-reproducible digest. */ export declare function requireCaip2(s: unknown): string; /** Return `s` if it is a canonical CAIP-10 account id, else throw {@link CaipError}. */ export declare function requireCaip10(s: unknown): string; /** Return `s` if it is a canonical CAIP-19 asset type or id, else throw {@link CaipError}. */ export declare function requireCaip19(s: unknown): string; /** * Build the CAIP-19 asset type for a chain's native coin via the slip44 namespace. * `caip19Slip44("eip155:1", 60)` -> `"eip155:1/slip44:60"`. The chain id is gated with * {@link requireCaip2} and the result with {@link requireCaip19}, so the output is * guaranteed byte-canonical. */ export declare function caip19Slip44(chainCaip2: string, coinType: number): string; /** * Build the CAIP-10 account id for `address` on `chainCaip2`. * `caip10Of("eip155:1", "0xab..")` -> `"eip155:1:0xab.."`. The chain id is gated with * {@link requireCaip2} and the result with {@link requireCaip10}. Throws {@link CaipError} * when the address is not a canonical CAIP-10 account address. */ export declare function caip10Of(chainCaip2: string, address: string): string; export declare const REGISTERED_NAMESPACES: ReadonlySet; /** The set of CAIP-2 namespaces registered in ChainAgnostic/namespaces (vendored). */ export declare function registeredNamespaces(): ReadonlySet; /** True iff `ns` is a registered CAIP-2 namespace (e.g. "eip155", "avax", "swift"). */ export declare function isRegisteredNamespace(ns: unknown): boolean; /** True iff `s` is a canonical CAIP-2 AND its namespace is registered. */ export declare function isRegisteredCaip2(s: unknown): boolean; /** True iff `s` is a canonical CAIP-10 AND its chain namespace is registered. */ export declare function isRegisteredCaip10(s: unknown): boolean; /** True iff `s` is a canonical CAIP-19 AND its chain namespace is registered. */ export declare function isRegisteredCaip19(s: unknown): boolean; /** Return `s` if it is a canonical CAIP-2 on a registered namespace, else throw. */ export declare function requireRegisteredCaip2(s: unknown): string; /** Return `s` if it is a canonical CAIP-10 on a registered namespace, else throw. */ export declare function requireRegisteredCaip10(s: unknown): string; /** Return `s` if it is a canonical CAIP-19 on a registered namespace, else throw. */ export declare function requireRegisteredCaip19(s: unknown): string; /** Namespaces for which a per-reference format rule is enforced by the is_valid_* tier. */ export declare const REFERENCE_FORMAT_NAMESPACES: ReadonlySet; /** True iff `s` is a canonical CAIP-2 on a registered namespace whose reference is also * well-formed for that namespace (strictest tier; e.g. rejects "eip155:abc"). */ export declare function isValidCaip2(s: unknown): boolean; /** CAIP-10 whose chain is registered and whose chain reference matches its namespace format. */ export declare function isValidCaip10(s: unknown): boolean; /** CAIP-19 whose chain is registered and whose chain reference matches its namespace format. */ export declare function isValidCaip19(s: unknown): boolean; /** Return `s` if it is a valid CAIP-2 (registered namespace + conformant reference), else throw. */ export declare function requireValidCaip2(s: unknown): string; /** Return `s` if it is a valid CAIP-10, else throw. */ export declare function requireValidCaip10(s: unknown): string; /** Return `s` if it is a valid CAIP-19, else throw. */ export declare function requireValidCaip19(s: unknown): string; //# sourceMappingURL=caip.d.ts.map