diff --git a/packages/idb-cache/src/encryptionTasks.ts b/packages/idb-cache/src/encryptionTasks.ts index 26890a9..3359647 100644 --- a/packages/idb-cache/src/encryptionTasks.ts +++ b/packages/idb-cache/src/encryptionTasks.ts @@ -6,7 +6,6 @@ import { DecryptionError, IDBCacheError, } from "./errors"; -import { generateUUIDv1 } from "./utils"; /** * Encrypts a chunk of data using the worker. @@ -22,7 +21,7 @@ export async function encryptChunk( value: string, pendingRequests: Map> ): Promise { - const requestId = generateUUIDv1(); + const requestId = crypto.randomUUID(); try { const encrypted = await sendMessageToWorker<"encrypt">( port, @@ -66,7 +65,7 @@ export async function decryptChunk( ciphertext: ArrayBuffer, pendingRequests: Map> ): Promise { - const requestId = generateUUIDv1(); + const requestId = crypto.randomUUID(); try { const decrypted = await sendMessageToWorker<"decrypt">( port, diff --git a/packages/idb-cache/src/utils.ts b/packages/idb-cache/src/utils.ts index 03d4e21..3fc67dd 100644 --- a/packages/idb-cache/src/utils.ts +++ b/packages/idb-cache/src/utils.ts @@ -7,31 +7,6 @@ import { } from "idb"; import type { IDBCacheSchema, STORE } from "./types"; -/** - * Generates a UUID v1-like string. - * @returns A UUID v1-like string. - */ -export function generateUUIDv1(): string { - const now = Date.now(); - - const timeLow = (now & 0xffffffff).toString(16).padStart(8, "0"); - const timeMid = ((now / 0x100000000) & 0xffff).toString(16).padStart(4, "0"); - const timeHiAndVersion = (((now / 0x1000000000000) & 0x0fff) | 0x1000) - .toString(16) - .padStart(4, "0"); - - const clockSeq = (Math.floor(Math.random() * 0x3fff) | 0x8000) - .toString(16) - .padStart(4, "0"); - - const node = crypto.getRandomValues(new Uint8Array(6)); - const nodeHex = Array.from(node) - .map((b) => b.toString(16).padStart(2, "0")) - .join(""); - - return `${timeLow}-${timeMid}-${timeHiAndVersion}-${clockSeq}-${nodeHex}`; -} - const uuidCache = new Map(); /**