#1551·chatbot

Replace custom UUID v4 helper with native crypto.randomUUID()

Author: FizzybrewCreated Sep 9, 2026Updated Sep 9, 2026

Problem

The current generateUUID() helper manually constructs UUID v4 values using Math.random().

Modern JavaScript runtimes provide a native Web Crypto API method, crypto.randomUUID(), which generates cryptographically secure UUID v4 values. The custom implementation is therefore unnecessary and provides weaker randomness than the native API.

Solution

Replace the custom implementation with the native crypto.randomUUID() API while keeping the existing generateUUID() helper and its current call sites unchanged.

typescript
export function generateUUID(): string {
  return crypto.randomUUID();
}

This keeps the existing abstraction in place while delegating UUID generation to the platform-provided cryptographically secure implementation.