UNPKG

@webbuf/fixedbuf

Version:

Fixed-sized buffers optimized with Rust/WASM for the web, node.js, deno, and bun.

49 lines (48 loc) 2.1 kB
import { WebBuf, type Base32Options } from "@webbuf/webbuf"; export declare class FixedBuf<N extends number> { _buf: WebBuf; _size: N; constructor(size: N, buf: WebBuf); get buf(): WebBuf; static fromBuf<N extends number>(size: N, buf: WebBuf): FixedBuf<N>; static alloc<N extends number>(size: N, fill?: number): FixedBuf<N>; static fromHex<N extends number>(size: N, hex: string): FixedBuf<N>; toHex(): string; static fromBase64(size: number, base64: string): FixedBuf<number>; toBase64(): string; /** * Encode this buffer as a base32 string. * * @param options - Options for encoding * @param options.alphabet - The alphabet to use (default: "Crockford") * @param options.padding - Whether to use padding for Rfc4648* alphabets (default: true) * @returns The base32 encoded string */ toBase32(options?: Base32Options): string; /** * Create a FixedBuf from a base32 encoded string. * * @param size - The expected size of the decoded buffer * @param str - The base32 encoded string * @param options - Options for decoding * @param options.alphabet - The alphabet to use (default: "Crockford") * @param options.padding - Whether the string uses padding for Rfc4648* alphabets (default: true) * @returns The decoded FixedBuf */ static fromBase32<N extends number>(size: N, str: string, options?: Base32Options): FixedBuf<N>; static fromRandom<N extends number>(size: N): FixedBuf<N>; clone(): FixedBuf<N>; toReverse(): FixedBuf<N>; /** * Securely wipe the buffer by filling it with zeros. * * Call this method before releasing references to buffers containing * sensitive data (keys, passwords, etc.) to minimize the window where * sensitive data remains in memory. * * Note: This is a best-effort security measure. JavaScript's JIT compiler * may optimize away the write if it detects the buffer isn't read afterward, * and copies of the data may exist elsewhere in memory. */ wipe(): void; }