/*! micro-key-producer - MIT License (c) 2024 Paul Miller (paulmillr.com) */ /** * Utilities. * @module */ import { randomBytes as nobleRandomBytes } from '@noble/hashes/utils.js'; import { type TArg } from '@scure/base'; import * as P from 'micro-packed'; export type { TArg, TRet } from '@scure/base'; /** * Secure random byte generator re-exported from `@noble/hashes/utils`. * @param bytesLength - Number of random bytes to return. * @returns Fresh random bytes. * @example * Generate fresh entropy before deriving one of the deterministic key formats. * ```ts * import { randomBytes } from 'micro-key-producer/utils.js'; * randomBytes(32); * ``` */ export declare const randomBytes: typeof nobleRandomBytes; /** * Asserts something is a string. * @param value - Value to validate. * @param title - Label included in thrown errors. * @returns The validated string. * @throws On wrong argument types. {@link TypeError} * @example * Validate a label string. * * ```ts * astring('example', 'label'); * ``` */ export declare function astring(value: unknown, title?: string): string; /** * Deep-freeze an exported object graph. * @param obj - Value to freeze. * @returns The same value after freezing reachable objects. * @example * Freeze a lookup table before exporting it. * ```ts * import { deepFreeze } from 'micro-key-producer/utils.js'; * deepFreeze({ name: 'value' }); * ``` */ export declare function deepFreeze(obj: T): T; /** * Composes two coders: `encode` runs inner then outer, `decode` runs them in reverse. * Replaces `utils.chain` removed from `@scure/base` 2.3. * @param inner - Coder applied first on encode. * @param outer - Coder applied second on encode. * @returns Combined coder. * @example * Chain a fixed-width integer coder with base64url. * ```ts * import { base64urlnopad } from '@scure/base'; * import { chainCoders } from 'micro-key-producer/utils.js'; * chainCoders(numCoder, base64urlnopad); * ``` */ export declare function chainCoders(inner: { encode: (from: F) => M; decode: (to: M) => F; }, outer: { encode: (from: M) => T; decode: (to: T) => M; }): { encode: (from: F) => T; decode: (to: T) => F; }; /** * base36: lowercase alphanumeric, big-endian positional (multibase `k` payload, * used by e.g. IPNS/CIDv1). Leading zero bytes map to leading `0` digits. * Re-exported from `@scure/base` for compatibility; was vendored before 2.4.0 * shipped it. * @example * Encode an IPNS multicodec key payload. * ```ts * import { base36 } from 'micro-key-producer/utils.js'; * base36.decode(base36.encode(new Uint8Array([0, 1, 2]))); * ``` */ export { base36 } from '@scure/base'; /** * Base64-armored values are commonly used in cryptographic applications, such as PGP and SSH. * @param name - The name of the armored value. * @param lineLen - Maximum line length for the armored value (e.g., 64 for GPG, 70 for SSH). * @param inner - Inner CoderType for the value. * @param checksum - Optional checksum function. * @returns Coder representing the base64-armored value. * @throws On wrong argument types. {@link TypeError} * @throws On invalid armor names or line lengths. {@link RangeError} * @example * Wrap a packed coder in an ASCII armor envelope. * ```ts * import * as P from 'micro-packed'; * import { base64armor } from 'micro-key-producer/utils.js'; * base64armor('MESSAGE', 64, P.string(null)).encode('hello'); * ``` */ export declare function base64armor(name: string, lineLen: number, inner: P.CoderType, checksum?: TArg<(data: Uint8Array) => Uint8Array>): P.Coder;