(length: number)
| 46 | } |
| 47 | |
| 48 | function randomBase32(length: number): string { |
| 49 | const bytes = new Uint8Array(length); |
| 50 | if (globalThis.crypto?.getRandomValues) { |
| 51 | globalThis.crypto.getRandomValues(bytes); |
| 52 | } else { |
| 53 | for (let i = 0; i < bytes.length; i++) { |
| 54 | bytes[i] = Math.floor(Math.random() * 256); |
| 55 | } |
| 56 | } |
| 57 | return Array.from(bytes, (byte) => ULID_ALPHABET[byte % 32]).join(''); |
| 58 | } |
| 59 | |
| 60 | function createRequestId(): string { |
| 61 | return `${encodeBase32(Date.now(), 10)}${randomBase32(16)}`; |