global.crypto
The platform's CSPRNG, with getRandomValues and randomUUID; no SubtleCrypto.
Usage
Generate a unique identifier.
// Generate a unique identifier.
const sessionId = crypto.randomUUID(); // '3b241101-e2bb-4255-8caf-4136c566a962'
const nonce = Array.from(crypto.getRandomValues(new Uint8Array(16)), (byte) =>
byte.toString(16).padStart(2, '0'),
).join('');
await fetch('https://api.example.com/sessions', {
method: 'POST',
body: JSON.stringify({ sessionId, nonce }),
});Properties and methods 2
| Name | Type | Required | Description |
|---|---|---|---|
getRandomValues | <T extends ArrayBufferView>(array: T) => T | Yes | — |
randomUUID | () => string | Yes | — |
getRandomValues — method signatures
Signatures
<T extends ArrayBufferView>(array: T): TType parameters
| Name | Constraint | Default |
|---|---|---|
T | ArrayBufferView<ArrayBufferLike> | — |
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
array | T | Yes | — |
Returns
T
randomUUID — method signatures
Signatures
(): stringParameters
No parameters.
Returns
string
Generated from the public TypeScript declarations: signatures, props and defaults come from the checked source, descriptions from its JSDoc. No defaults are invented.