await promises in place

This commit is contained in:
2024-09-10 00:32:25 +02:00
parent 9de49c228d
commit 7e858b3556
9 changed files with 31 additions and 38 deletions
+7 -14
View File
@@ -12,16 +12,9 @@ export default class PrivateBox {
private readonly box: SecretBox
) {}
public static gen(extractable: boolean = true): Promise<CryptoKeyPair> {
public static async gen(extractable: boolean = true): Promise<CryptoKeyPair> {
log.trace('generate keypair')
log.trace('Extractable :', extractable)
try {
return crypto.subtle.generateKey(consts.ECDH, extractable, ['deriveKey']) as Promise<CryptoKeyPair>
} catch (e) {
log.warn('Failed to generate a key')
log.debug('Error :', e)
throw e
}
return await crypto.subtle.generateKey(consts.ECDH, extractable, ['deriveKey']) as CryptoKeyPair
}
public static async encrypt(data: Uint8Array, pubkey: CryptoKey): Promise<PrivateBox> {
@@ -34,7 +27,7 @@ export default class PrivateBox {
public async decrypt(privkey: CryptoKey): Promise<Uint8Array | null> {
log.trace('decrypt')
const key = await ecdh(privkey, this.pubkey, DHusage.box)
return this.box.decrypt(key)
return await this.box.decrypt(key)
}
public async toString(): Promise<string> {
@@ -57,10 +50,10 @@ export default class PrivateBox {
return new PrivateBox(pubkey, box)
}
public static pubkey_toString(pubkey: CryptoKey): Promise<string> {
return misc.pubkey_toString(pubkey)
public static async pubkey_toString(pubkey: CryptoKey): Promise<string> {
return await misc.pubkey_toString(pubkey)
}
public static pubkey_fromString(pubkey: string): Promise<CryptoKey | null> {
return misc.pubkey_fromString(pubkey, misc.Usage.ecdh)
public static async pubkey_fromString(pubkey: string): Promise<CryptoKey | null> {
return await misc.pubkey_fromString(pubkey, misc.Usage.ecdh)
}
}