/** * Zod validation schemas and helpers for NEAR types. * * @remarks * These schemas power runtime validation for account IDs, public/private keys, * amounts, and gas while keeping the developer-facing API ergonomic via * helpers like {@link validateAccountId} and {@link normalizeAmount}. */ import { z } from "zod"; import { type AmountInput } from "./amount.js"; import { type GasInput } from "./gas.js"; /** * Schema for validating NEAR account IDs. * * Rules: * - Length: 2-64 characters * - Characters: lowercase alphanumeric, hyphens, underscores, and dots * - Pattern: subdomain-like structure (e.g., alice.near, contract.mainnet) */ export declare const AccountIdSchema: z.ZodString; export type AccountId = z.infer; /** * Schema for validating NEAR public keys. * * Supports: * - Ed25519: "ed25519:..." (base58 encoded) * - Secp256k1: "secp256k1:..." (base58 encoded) * - ML-DSA-65: "ml-dsa-65:..." (full key) and "ml-dsa-65-hash:..." (view handle) */ export declare const PublicKeySchema: z.ZodString; export type PublicKeyString = z.infer; /** * Type-safe private key string using template literal types. * * Provides compile-time type safety for private keys. * Supports ed25519, secp256k1, and ml-dsa-65 (post-quantum) keys. * * @example * ```typescript * const key: PrivateKey = 'ed25519:...' // ✅ Valid * const key: PrivateKey = 'secp256k1:...' // ✅ Valid * const key: PrivateKey = 'ml-dsa-65:...' // ✅ Valid (post-quantum) * const key: PrivateKey = 'alice.near' // ❌ Type error at compile time * * // Function signature ensures type safety * function signWith(key: PrivateKey) { ... } * signWith('ed25519:abc') // ✅ Valid * signWith('secp256k1:abc') // ✅ Valid * signWith('ml-dsa-65:abc') // ✅ Valid * signWith('alice.near') // ❌ Type error * ``` */ export type PrivateKey = `ed25519:${string}` | `secp256k1:${string}` | `ml-dsa-65:${string}`; /** * Schema for validating NEAR private keys. * * Supports: * - Ed25519: "ed25519:..." (base58 encoded, 64 bytes) * - Secp256k1: "secp256k1:..." (base58 encoded, 32 or 96 bytes) * - ML-DSA-65: "ml-dsa-65:..." (base58 encoded; either a 32-byte seed, as this * library serializes generated keys, or the 4032-byte raw expanded secret key * as written by nearcore / near-cli credentials) */ export declare const PrivateKeySchema: z.ZodString; export type PrivateKeyString = z.infer; /** * Schema for NEAR amounts with explicit units. * * Accepts: * - String with unit: "10 NEAR", "1000000 yocto" * - Created via Amount.NEAR(10) or Amount.yocto(1000000n) * - Raw bigint: 1000000n (treated as yoctoNEAR) * * Rejects bare numbers to prevent unit confusion. * Normalizes to yoctoNEAR string. */ export declare const AmountSchema: z.ZodPipe, z.ZodTransform>; /** * Compile-time-safe amount type for NEAR values. * * This is a template-literal type that only permits: * - `"10 NEAR"`, `"1.5 NEAR"` style strings * - `"1000 yocto"` style strings * - Raw bigint values treated as yoctoNEAR */ export type Amount = AmountInput; /** * Schema for gas amounts. * * Accepts: * - String with unit: "30 Tgas", Gas.Tgas(30) * - Raw gas number strings for advanced use * * Normalizes to raw gas string. */ export declare const GasSchema: z.ZodPipe>; export type Gas = GasInput; /** * Validate account ID (throws on invalid). */ export declare function validateAccountId(accountId: string): string; /** * Check if account ID is valid (boolean). */ export declare function isValidAccountId(accountId: string): boolean; /** * Validate public key (throws on invalid). */ export declare function validatePublicKey(key: string): string; /** * Check if public key is valid (boolean). */ export declare function isValidPublicKey(key: string): boolean; /** * Validate private key (throws on invalid). */ export declare function validatePrivateKey(key: string): string; /** * Check if private key is valid (boolean). */ export declare function isPrivateKey(key: string): boolean; /** * Normalize amount to yoctoNEAR string. */ export declare function normalizeAmount(amount: Amount): string; /** * Normalize gas to gas string. */ export declare function normalizeGas(gas: Gas): string; //# sourceMappingURL=validation.d.ts.map