]> git.codecow.com Git - libnemo.git/commitdiff
Remove crypto destructuring and reference the full object property path.
authorChris Duncan <chris@zoso.dev>
Thu, 3 Jul 2025 17:15:54 +0000 (10:15 -0700)
committerChris Duncan <chris@zoso.dev>
Thu, 3 Jul 2025 17:15:54 +0000 (10:15 -0700)
src/lib/workers/safe.ts

index 9d891c0d9dec64c4a6f1f08dda3a4f6a76f8e97e..04c696ba702cad3698a5220eb41c2fd25d0f6485 100644 (file)
@@ -20,7 +20,6 @@ type SafeOutput = {
        result: any
 }
 
-const { subtle } = globalThis.crypto
 const ERR_MSG = 'Failed to store item in Safe'
 
 /**
@@ -100,7 +99,7 @@ export class Safe extends WorkerInterface {
        static async overwrite (name: string, password: Uint8Array, data: any): Promise<boolean> {
                let passkey: CryptoKey
                try {
-                       passkey = await subtle.importKey('raw', password, 'PBKDF2', false, ['deriveBits', 'deriveKey'])
+                       passkey = await crypto.subtle.importKey('raw', password, 'PBKDF2', false, ['deriveBits', 'deriveKey'])
                } catch {
                        throw new Error(ERR_MSG)
                } finally {
@@ -126,8 +125,8 @@ export class Safe extends WorkerInterface {
                                name: 'AES-GCM',
                                length: 256
                        }
-                       passkey = await subtle.deriveKey(derivationAlgorithm, passkey, derivedKeyType, false, ['encrypt'])
-                       const encrypted = await subtle.encrypt({ name: 'AES-GCM', iv: iv.buffer }, passkey, utf8.toBytes(data))
+                       passkey = await crypto.subtle.deriveKey(derivationAlgorithm, passkey, derivedKeyType, false, ['encrypt'])
+                       const encrypted = await crypto.subtle.encrypt({ name: 'AES-GCM', iv: iv.buffer }, passkey, utf8.toBytes(data))
                        const record = {
                                encrypted: buffer.toHex(encrypted),
                                iv: iv.hex
@@ -146,7 +145,7 @@ export class Safe extends WorkerInterface {
        static async get (name: string, password: Uint8Array): Promise<any> {
                let passkey: CryptoKey
                try {
-                       passkey = await subtle.importKey('raw', password, 'PBKDF2', false, ['deriveBits', 'deriveKey'])
+                       passkey = await crypto.subtle.importKey('raw', password, 'PBKDF2', false, ['deriveBits', 'deriveKey'])
                } catch {
                        return null
                } finally {
@@ -180,8 +179,8 @@ export class Safe extends WorkerInterface {
                                name: 'AES-GCM',
                                length: 256
                        }
-                       passkey = await subtle.deriveKey(derivationAlgorithm, passkey, derivedKeyType, false, ['decrypt'])
-                       const decrypted = await subtle.decrypt({ name: 'AES-GCM', iv: iv.buffer }, passkey, encrypted)
+                       passkey = await crypto.subtle.deriveKey(derivationAlgorithm, passkey, derivedKeyType, false, ['decrypt'])
+                       const decrypted = await crypto.subtle.decrypt({ name: 'AES-GCM', iv: iv.buffer }, passkey, encrypted)
                        const decoded = buffer.toUtf8(decrypted)
                        const data = JSON.parse(decoded)
                        this.destroy(name)