import { NetworkId } from '@midnight-ntwrk/midnight-js-network-id'; import { Buffer } from 'buffer'; import { ContractAddress } from '@midnight-ntwrk/midnight-js-protocol/compact-runtime'; /** * Asserts that the given value is non-nullable. * * @param value The value to test for nullability. * @param message The error message to use if an error is thrown. * * @throws Error If the value is nullable. */ declare function assertDefined(value: A | null | undefined, message?: string): asserts value is NonNullable; /** * Asserts that the given value is null or undefined. * * @param value The value to test for nullability. * @param message The error message to use if an error is thrown. * * @throws Error If the value is not undefined or null */ declare function assertUndefined(value: A | null | undefined, message?: string): asserts value is undefined | null; declare const ttlOneHour: () => Date; /** * The result of parsing a string as a hex-encoded string. */ type ParsedHexString = { /** A flag indicating if the hex-string has a `'0x'` prefix. */ readonly hasPrefix: boolean; /** The captured sequence of _whole_ bytes found in the source string. */ readonly byteChars: string; /** The remaining characters of incomplete bytes and/or the non hexadecimal characters found * in the source string. */ readonly incompleteChars: string; }; /** * Parses a string as a hex-encoded string. * * @param source The source string to parse. * @returns A {@link ParsedHexString} describing the parsed elements of `source`. * * @example * parseHex('Hello') => * { * hasPrefix: false, * incompleteChars: 'Hello' * } * * @example * parseHex('ab12e') => * { * hasPrefix: false, * byteChars: 'ab12' * incompleteChars: 'e' * } * * @example * parseHex('0xab12') => * { * hasPrefix: true, * byteChars: 'ab12' * incompleteChars: '' * } */ declare const parseHex: (source: string) => ParsedHexString; /** * Converts a byte string into a hex string. * * @param bytes The byte string to encode. */ declare const toHex: (bytes: Uint8Array) => string; /** * Converts a hex string into a byte string. * * @param str The hex string to decode. */ declare const fromHex: (str: string) => Buffer; /** * Determines if a string represents a hex-encoded sequence of bytes. * * @param source The source string. * @param byteLen An optional number of bytes that `source` should represent. If not specified * then any number of bytes can be represented by `source`. * @returns `true` if the `source` string is parsable as a hex-string, of non-zero length, and * of the optional byte length of `byteLen`; otherwise `false`. */ declare const isHex: (source: string, byteLen?: number) => boolean; /** * Asserts that a string represents a hex-encoded sequence of bytes. * * @param source The source string. * @param byteLen An optional number of bytes that `source` should represent. If not specified * then any number of bytes can be represented by `source`. * * @throws `Error` * `byteLen` is \<= zero. Valid hex-strings will be required to have at least one byte. * @throws `TypeError` * `source` is not a hex-encoded string because it: * - is empty, * - contains invalid or incomplete characters, or * - does not represent `byteLen` bytes. */ declare function assertIsHex(source: string, byteLen?: number): asserts source is NonNullable; /** * Parses a coin public key (in Bech32m format or hex) into a hex formatted string. * * @param possibleBech32 The input string, which can be a Bech32m-encoded coin public key or a hex string. * @param zswapNetworkId The network ID used for decoding the Bech32m formatted string. * @returns The hex string representation of the coin public key. * * @throws `Error` * If the input string is not a valid hex string or a valid Bech32m-encoded coin public key. */ declare const parseCoinPublicKeyToHex: (possibleBech32: string, zswapNetworkId: NetworkId) => string; /** * Parses an encryption public key (in Bech32m or hex format) into a hex formatted string. * * @param possibleBech32 The input string, which can be a Bech32m-encoded encryption public key or a hex string. * @param zswapNetworkId The network ID used for decoding the Bech32m formatted string. * @returns The hex string representation of the encryption public key. * * @throws `Error` * If the input string is not a valid hex string or a valid Bech32m-encoded encryption public key. */ declare const parseEncPublicKeyToHex: (possibleBech32: string, zswapNetworkId: NetworkId) => string; declare const MIN_PASSWORD_LENGTH = 16; declare const MIN_CHARACTER_CLASSES = 3; declare const MAX_CONSECUTIVE_REPEATED = 3; declare const MIN_SEQUENTIAL_LENGTH = 4; /** * Reason categories for password validation failures. */ type PasswordValidationFailure = 'missing' | 'too_short' | 'insufficient_classes' | 'repeated_characters' | 'sequential_pattern'; /** * Thrown when a password does not satisfy the strength policy applied to * private storage and export/import operations. */ declare class PasswordValidationError extends Error { readonly reason: PasswordValidationFailure; constructor(message: string, reason: PasswordValidationFailure); } /** * Shared password strength policy for private storage and export/import operations. * Throws {@link PasswordValidationError} on the first violated rule. */ declare const validatePassword: (password: string) => void; declare const MAX_SAFE_NAME_LENGTH = 255; /** * Asserts that `name` is safe to use as a single path segment or URL path * component. Rejects traversal payloads (`.`, `..`, separators), URL-encoded * characters, null bytes, whitespace, empty strings, and names longer than * {@link MAX_SAFE_NAME_LENGTH}. * * @param name The value to validate. * @param label Human-readable name of the parameter (for error messages). * @throws Error if `name` fails validation. */ declare function assertSafeName(name: string, label: string): void; /** * Asserts that `version` is a valid SemVer-style version string of the shape * `MAJOR.MINOR.PATCH` with an optional pre-release suffix * (`-[A-Za-z0-9._-]+`). Build metadata (`+...`) is intentionally not * supported because compactc releases do not use it. * * @param version The version string to validate. * @param label Human-readable name of the parameter (for error messages). * @throws Error if `version` is not SemVer-shaped. */ declare function assertSemVer(version: string, label: string): void; /** * Emits a `console.warn` when `url` uses an unencrypted scheme (`http:` or `ws:`) * targeting a non-loopback host. No-op for encrypted schemes (`https:`, `wss:`), * other schemes, and unparseable input. * * Intended to be called once at provider-factory construction time so * misconfigured remote endpoints surface immediately rather than after sensitive * payloads are transmitted in clear text. As a diagnostic helper it never throws — * an unparseable URL will produce errors through other channels (the protocol * checks at every call site already throw `InvalidProtocolSchemeError`), and * crashing the factory from a warning helper would be worse than silence. * * @param url An absolute URL string to inspect (e.g. `https://indexer.example/graphql`). * @param label Human-readable label used in the warning (e.g. "indexer query URL"). */ declare function warnIfInsecureRemoteUrl(url: string, label: string): void; /** * Asserts that a string represents a hex-encoded contract address. * * @param contractAddress The source string. * * @throws `TypeError` * `contractAddress` is not a correctly formatted {@link ContractAddress}. * * @internal */ declare function assertIsContractAddress(contractAddress: string): asserts contractAddress is ContractAddress; export { MAX_CONSECUTIVE_REPEATED, MAX_SAFE_NAME_LENGTH, MIN_CHARACTER_CLASSES, MIN_PASSWORD_LENGTH, MIN_SEQUENTIAL_LENGTH, PasswordValidationError, assertDefined, assertIsContractAddress, assertIsHex, assertSafeName, assertSemVer, assertUndefined, fromHex, isHex, parseCoinPublicKeyToHex, parseEncPublicKeyToHex, parseHex, toHex, ttlOneHour, validatePassword, warnIfInsecureRemoteUrl }; export type { ParsedHexString, PasswordValidationFailure };