fmt
This commit is contained in:
+8
-3
@@ -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<Uint8Ar
|
||||
|
||||
return new Uint8Array(buffer)
|
||||
}
|
||||
export async function ecdh(privkey: CryptoKey, pubkey: CryptoKey, usage: DHusage, context?: string): Promise<CryptoKey | null> {
|
||||
export async function ecdh(
|
||||
privkey: CryptoKey,
|
||||
pubkey: CryptoKey,
|
||||
usage: DHusage,
|
||||
context?: string
|
||||
): Promise<CryptoKey | null> {
|
||||
log.trace('ecdh')
|
||||
|
||||
let seed_bits: ArrayBuffer;
|
||||
let seed_bits: ArrayBuffer
|
||||
try {
|
||||
seed_bits = await crypto.subtle.deriveBits(
|
||||
{
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ export default class PrivateBox {
|
||||
|
||||
public static async gen(extractable: boolean = true): Promise<CryptoKeyPair> {
|
||||
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<PrivateBox | null> {
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ export default class PrivateWrap {
|
||||
|
||||
public static async gen(extractable: boolean = true): Promise<CryptoKeyPair> {
|
||||
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<PrivateWrap | null> {
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ export default class PwdBox {
|
||||
private static async derive(pwd: string, salt: Uint8Array, context?: string): Promise<CryptoKey | null> {
|
||||
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<PwdBox | null> {
|
||||
|
||||
+1
-1
@@ -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(
|
||||
{
|
||||
|
||||
+1
-1
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user