File tree Expand file tree Collapse file tree 2 files changed +2
-28
lines changed
Expand file tree Collapse file tree 2 files changed +2
-28
lines changed Original file line number Diff line number Diff line change 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 ,
Original file line number Diff line number Diff line change @@ -7,31 +7,6 @@ import {
77} from "idb" ;
88import 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-
3510const uuidCache = new Map < string , string > ( ) ;
3611
3712/**
You can’t perform that action at this time.
0 commit comments