()
| 5 | * Does NOT rely on crypto.randomUUID() which is unavailable in RN. |
| 6 | */ |
| 7 | export function generateId(): string { |
| 8 | const bytes = new Uint8Array(16); |
| 9 | crypto.getRandomValues(bytes); |
| 10 | // Set version 4 (0100) in byte 6 |
| 11 | bytes[6] = (bytes[6] & 0x0f) | 0x40; |
| 12 | // Set variant 10xx in byte 8 |
| 13 | bytes[8] = (bytes[8] & 0x3f) | 0x80; |
| 14 | |
| 15 | const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join(""); |
| 16 | return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`; |
| 17 | } |
no test coverage detected