/** * Byte and encoding helpers built exclusively on web-standard APIs. * * The SDK has to import and run unchanged on Node, in browsers, and in Edge * runtimes (Vercel Edge, Cloudflare Workers). Edge runtimes provide no Node * builtins and no `Buffer`, so nothing in the SDK's module graph may reach for * either — see the `check:edge` script, which fails the build if one creeps * back in. * * Everything here is available on Node >= 18 (the SDK's engine floor), in * every modern browser, and on both Edge runtimes: `globalThis.crypto`, * `btoa`/`atob`, and `TextEncoder`/`TextDecoder`. */ /** * Fill `length` bytes with cryptographically secure randomness. * * @throws If the host exposes no Web Crypto implementation. */ export declare function randomBytes(length: number): Uint8Array; /** Hex-encode bytes. Replaces `Buffer.from(bytes).toString("hex")`. */ export declare function toHex(bytes: Uint8Array): string; /** Base64-encode bytes. Replaces `Buffer.from(bytes).toString("base64")`. */ export declare function toBase64(bytes: Uint8Array): string; /** Decode a base64 string to bytes. Replaces `Buffer.from(b64, "base64")`. */ export declare function fromBase64(base64: string): Uint8Array; /** * Coerce the binary shapes callers pass as `contents` into a `Uint8Array`, * matching what `Buffer.from(value)` used to accept (minus the string * overload, which callers handle separately because it is not binary). * * @throws If `value` is not a recognized binary shape. */ export declare function toBytes(value: unknown): Uint8Array; /** * View a typed array's bytes without copying, honoring its offset and length * (`.buffer` alone can be larger than the view). */ export declare function viewBytes(view: ArrayBufferView): Uint8Array; /** UTF-8 decode bytes. Replaces `buffer.toString("utf8")`. */ export declare function decodeUtf8(bytes: Uint8Array): string; /** * Hex-encoded SHA-256 of `data`, via Web Crypto. * * Async because `crypto.subtle.digest` is; Node's synchronous `createHash` * has no Edge equivalent. * * @throws If the host exposes no Web Crypto `subtle` implementation. */ export declare function sha256Hex(data: Uint8Array): Promise;