diff --git a/src/kdf.ts b/src/kdf.ts index 51cac13..1ae5fbe 100644 --- a/src/kdf.ts +++ b/src/kdf.ts @@ -23,7 +23,7 @@ export async function hkdf(key: Uint8Array, usage: Usage, context?: string): Pro return null } - let material: CryptoKey; + let material: CryptoKey try { material = await crypto.subtle.importKey('raw', key, 'HKDF', false, ['deriveKey']) } catch (e) { @@ -112,10 +112,15 @@ export async function pbkdf(salt: Uint8Array, password: string): Promise { +export async function ecdh( + privkey: CryptoKey, + pubkey: CryptoKey, + usage: DHusage, + context?: string +): Promise { log.trace('ecdh') - let seed_bits: ArrayBuffer; + let seed_bits: ArrayBuffer try { seed_bits = await crypto.subtle.deriveBits( { diff --git a/src/private-box.ts b/src/private-box.ts index 218c9f0..7cb34cf 100644 --- a/src/private-box.ts +++ b/src/private-box.ts @@ -14,7 +14,7 @@ export default class PrivateBox { public static async gen(extractable: boolean = true): Promise { log.trace('generate keypair') - return await crypto.subtle.generateKey(consts.ECDH, extractable, ['deriveBits']) as CryptoKeyPair + return await crypto.subtle.generateKey(consts.ECDH, extractable, ['deriveBits']) } public static async encrypt(data: Uint8Array, pubkey: CryptoKey, context?: string): Promise { diff --git a/src/private-wrap.ts b/src/private-wrap.ts index 5f2a926..893680e 100644 --- a/src/private-wrap.ts +++ b/src/private-wrap.ts @@ -14,7 +14,7 @@ export default class PrivateWrap { public static async gen(extractable: boolean = true): Promise { log.trace('generate keypair') - return await crypto.subtle.generateKey(consts.ECDH, extractable, ['deriveBits']) as CryptoKeyPair + return (await crypto.subtle.generateKey(consts.ECDH, extractable, ['deriveBits'])) as CryptoKeyPair } public static async wrap(data: CryptoKey, pubkey: CryptoKey, context?: string): Promise { diff --git a/src/pwd-box.ts b/src/pwd-box.ts index 5849a9f..6cf9a9a 100644 --- a/src/pwd-box.ts +++ b/src/pwd-box.ts @@ -14,7 +14,7 @@ export default class PwdBox { private static async derive(pwd: string, salt: Uint8Array, context?: string): Promise { const k = await pbkdf(salt, pwd) if (k === null) return null - return await hkdf(k, Usage.box, context) as CryptoKey + return (await hkdf(k, Usage.box, context)) as CryptoKey } public static async encrypt(data: Uint8Array, pwd: string, context?: string): Promise { diff --git a/src/secret-box.ts b/src/secret-box.ts index 60762a9..83d5be2 100644 --- a/src/secret-box.ts +++ b/src/secret-box.ts @@ -27,7 +27,7 @@ export default class SecretBox { const iv = crypto.getRandomValues(new Uint8Array(12)) - let cipher: ArrayBuffer; + let cipher: ArrayBuffer try { cipher = await crypto.subtle.encrypt( { diff --git a/src/secret-wrap.ts b/src/secret-wrap.ts index 2aa2e93..cf17a6f 100644 --- a/src/secret-wrap.ts +++ b/src/secret-wrap.ts @@ -45,7 +45,7 @@ export default class SecretWrap { const iv = crypto.getRandomValues(new Uint8Array(12)) - let box: ArrayBuffer; + let box: ArrayBuffer try { box = await crypto.subtle.wrapKey(format, data, key, {name: consts.ENCRYPTION, iv}) } catch (e) {