Files
suaveplan/packages/security-stack/crypto/crypto-utils/src/zeroize/zeroize.ts
2026-05-27 23:47:53 +01:00

14 lines
569 B
TypeScript

/**
* Overwrite `buf` in-place with zero bytes.
*
* JavaScript cannot guarantee the garbage collector has not already relocated
* or copied the underlying memory, so this is a best-effort operation. Its
* purpose is to minimise the time window during which sensitive bytes
* (secret keys, plaintext, derived material) remain readable on the heap
* after they are no longer needed. Combine with aggressive buffer
* scoping — allocate inside a function, zeroize, return nothing sensitive.
*/
export function zeroize(buf: Uint8Array): void {
buf.fill(0);
}