Skip to content

Commit b30cb6e

Browse files
committed
Use crypto.randomUUID
1 parent e154c57 commit b30cb6e

File tree

2 files changed

+2
-28
lines changed

2 files changed

+2
-28
lines changed

packages/idb-cache/src/encryptionTasks.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
DecryptionError,
77
IDBCacheError,
88
} from "./errors";
9-
import { generateUUIDv1 } from "./utils";
109

1110
/**
1211
* Encrypts a chunk of data using the worker.
@@ -22,7 +21,7 @@ export async function encryptChunk(
2221
value: string,
2322
pendingRequests: Map<string, ExtendedPendingRequest<EncryptedChunk>>
2423
): Promise<EncryptedChunk> {
25-
const requestId = generateUUIDv1();
24+
const requestId = crypto.randomUUID();
2625
try {
2726
const encrypted = await sendMessageToWorker<"encrypt">(
2827
port,
@@ -66,7 +65,7 @@ export async function decryptChunk(
6665
ciphertext: ArrayBuffer,
6766
pendingRequests: Map<string, ExtendedPendingRequest<string>>
6867
): Promise<string> {
69-
const requestId = generateUUIDv1();
68+
const requestId = crypto.randomUUID();
7069
try {
7170
const decrypted = await sendMessageToWorker<"decrypt">(
7271
port,

packages/idb-cache/src/utils.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,6 @@ import {
77
} from "idb";
88
import type { IDBCacheSchema, STORE } from "./types";
99

10-
/**
11-
* Generates a UUID v1-like string.
12-
* @returns A UUID v1-like string.
13-
*/
14-
export function generateUUIDv1(): string {
15-
const now = Date.now();
16-
17-
const timeLow = (now & 0xffffffff).toString(16).padStart(8, "0");
18-
const timeMid = ((now / 0x100000000) & 0xffff).toString(16).padStart(4, "0");
19-
const timeHiAndVersion = (((now / 0x1000000000000) & 0x0fff) | 0x1000)
20-
.toString(16)
21-
.padStart(4, "0");
22-
23-
const clockSeq = (Math.floor(Math.random() * 0x3fff) | 0x8000)
24-
.toString(16)
25-
.padStart(4, "0");
26-
27-
const node = crypto.getRandomValues(new Uint8Array(6));
28-
const nodeHex = Array.from(node)
29-
.map((b) => b.toString(16).padStart(2, "0"))
30-
.join("");
31-
32-
return `${timeLow}-${timeMid}-${timeHiAndVersion}-${clockSeq}-${nodeHex}`;
33-
}
34-
3510
const uuidCache = new Map<string, string>();
3611

3712
/**

0 commit comments

Comments
 (0)