Wasm.ts overview
The Argon2 kernel: @thomasfosterau/argon2’s WebAssembly (WASM_BASE64), compiled once at module scope and called through its C ABI. workerd forbids compiling wasm inside a request, so never move new WebAssembly.Module into a function. verify reads the costs from the stored string.
Exports Grouped by Category
utils
KernelCosts (interface)
Argon2id cost parameters handed to the kernel.
Signature
export interface KernelCosts {
readonly memoryCost: number
readonly timeCost: number
readonly parallelism: number
}
KernelError (class)
The kernel could not run: it "rejected" the costs or salt (hash returned -1), or it "trapped" (an allocation failure aborts the Rust side). The hasher wraps it in a HashingError.
Signature
declare class KernelError
hashArgon2id
Derive an argon2id (v=19, 32-byte digest) PHC string for password and salt. Fails when the kernel rejects the parameters or salt, or traps.
Signature
declare const hashArgon2id: (
password: string,
salt: Uint8Array,
costs: KernelCosts
) => Result.Result<string, KernelError>
verifyArgon2
Recompute a stored PHC string for password. "unverifiable" means the kernel could not recompute it (costs, salt or digest outside the crate’s bounds, or malformed encoding). Fails only on a trap.
Signature
declare const verifyArgon2: (password: string, stored: string) => Result.Result<Verdict, KernelError>