import * as Errors from './Errors.js'; import * as engine from './internal/engine.js'; export type { Bls, Ecdh, Ecdsa, Eddsa, Engine, Hash, HashState, Keystore, MlDsa, Mnemonic, } from './internal/engine.js'; /** * Resolves and installs crypto implementations. * * Slots resolve in parallel, then use {@link ox#Engine.set} merge semantics: * omitted slots and primitives preserve existing overrides. If a slot rejects * or validation fails, the installed engine is unchanged. * * @example * ```ts twoslash * import { Engine } from 'ox' * import { Hash } from 'ox/wasm' * * await Engine.install({ * Hash: Hash.engine() * }) * ``` * * @param value - Engine slots or promises for engine slots. * @returns The resolved engine that was installed. */ export declare function install(value: value & install.Exact): Promise>; export declare namespace install { /** Rejects slot and primitive names outside the engine contract. */ type Exact = { [key in keyof value]: key extends keyof engine.Engine ? [NonNullable>] extends [never] ? unknown : Exclude>, keyof NonNullable> extends never ? unknown : never : never; }; /** Engine whose slots can be resolved asynchronously. */ type Value = { [key in keyof engine.Engine]?: engine.Engine[key] | PromiseLike; }; /** Resolves the supplied slots while preserving their precise shape. */ type ReturnType = { [key in keyof value]: Awaited; }; /** Error thrown while installing an engine. */ type ErrorType = set.ErrorType | Errors.GlobalErrorType; } /** * Installs crypto implementations, replacing the `@noble/*` implementations ox * uses by default. * * Slots and their functions are optional. Omissions preserve earlier * overrides, or use Ox's default when none exists. Calls merge, so a later * engine can override one primitive. * * Call this once, during application startup, before any crypto call. ox * resolves the engine at call time, so values computed beforehand used whatever * implementation was installed then. * * @example * ```ts twoslash * import { Engine, Hash } from 'ox' * * Engine.set({ * Hash: { keccak256: () => new Uint8Array(32) } * }) * * Hash.keccak256('0xdeadbeef') * // @log: '0x0000000000000000000000000000000000000000000000000000000000000000' * ``` * * @param value - Engine to install. */ export declare function set(value: engine.Engine): void; export declare namespace set { type ErrorType = InvalidSlotValueError | UnknownPrimitiveError | UnknownSlotError | Errors.GlobalErrorType; } /** * Returns the installed engine. * * Only overrides are returned -- slots left on ox's defaults are absent, so an * empty object means ox is entirely on its default implementations. * * @example * ```ts twoslash * import { Engine } from 'ox' * * Engine.get() * // @log: {} * ``` * * @returns The installed engine. */ export declare function get(): engine.Engine; export declare namespace get { type ErrorType = Errors.GlobalErrorType; } /** * Restores ox's default implementations. * * @example * ```ts twoslash * import { Engine } from 'ox' * * Engine.reset('Hash') * Engine.reset() * ``` * * @param slot - Slot to reset. Resets every slot when omitted. */ export declare function reset(slot?: keyof engine.Engine): void; export declare namespace reset { type ErrorType = UnknownSlotError | Errors.GlobalErrorType; } /** * Runs a function with an engine installed, then restores the previous engine. * * Only safe for synchronous functions: the engine is process-wide for the * duration of the call, so concurrent asynchronous work would observe it too. * Passing a function that returns a promise throws * {@link ox#Engine.AsyncScopeError}. * * @example * ```ts twoslash * import { Engine, Hash } from 'ox' * * const hash = Engine.with( * { Hash: { keccak256: () => new Uint8Array(32) } }, * () => Hash.keccak256('0xdeadbeef') * ) * // @log: '0x0000000000000000000000000000000000000000000000000000000000000000' * ``` * * @param value - Engine to install for the duration of the call. * @param fn - Synchronous function to run. * @returns The return value of `fn`. */ declare function with_(value: engine.Engine, fn: () => returnType): returnType; export { with_ as with }; declare namespace with_ { type ErrorType = AsyncScopeError | set.ErrorType | get.ErrorType | Errors.GlobalErrorType; } /** Thrown when an engine slot is not an object or `undefined`. */ export declare class InvalidSlotValueError extends Errors.BaseError { readonly name = "Engine.InvalidSlotValueError"; constructor(slot: string); } /** Thrown when an unrecognized engine slot is supplied. */ export declare class UnknownSlotError extends Errors.BaseError { readonly name = "Engine.UnknownSlotError"; constructor(slot: string); } /** Thrown when a slot is given an unrecognized primitive name. */ export declare class UnknownPrimitiveError extends Errors.BaseError { readonly name = "Engine.UnknownPrimitiveError"; constructor(slot: string, primitive: string); } /** Thrown when {@link ox#Engine.with} is given an asynchronous function. */ export declare class AsyncScopeError extends Errors.BaseError { readonly name = "Engine.AsyncScopeError"; constructor(); } //# sourceMappingURL=Engine.d.ts.map