refactor: leverage native crypto.randomUUID() for UUID generation#433
Open
Nithin0620 wants to merge 2 commits into
Open
refactor: leverage native crypto.randomUUID() for UUID generation#433Nithin0620 wants to merge 2 commits into
Nithin0620 wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Description
Problem:
The existing
randomUUID()implementation always generates UUIDs using a custom algorithm, even in environments where the native Web Crypto API provides a built-incrypto.randomUUID()method. This misses an opportunity to use a standardized, well-tested, and potentially more secure UUID generation mechanism.Solution:
Updated the
randomUUID()function to first check whetherglobalThis.crypto.randomUUID()is available. When supported, the function now delegates UUID generation to the native implementation. For environments where the API is unavailable, the existing UUID generation logic is preserved as a fallback to maintain backward compatibility.Benefits of this approach:
Testing Plan
Unit Tests:
Summary of passed npm test results:
npm run test:unitlocally.Manual End-to-End (E2E) Tests:
Verified that compiling the workspaces via
npm run buildsucceeds without any TypeScript diagnostic errorsChecklist
Additional context
This change is backward compatible and does not alter the public API. It simply prioritizes the native Web Crypto UUID generation API when available while preserving the existing custom implementation as a fallback.