From 3b0ec7ce714284abb73c626f1e3bc4a500e58e97 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Fri, 16 Aug 2024 16:06:15 +0530 Subject: [PATCH] Use --- web/packages/base/crypto/libsodium.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/web/packages/base/crypto/libsodium.ts b/web/packages/base/crypto/libsodium.ts index 033d017914..b5c1a1a63f 100644 --- a/web/packages/base/crypto/libsodium.ts +++ b/web/packages/base/crypto/libsodium.ts @@ -15,6 +15,7 @@ import type { DecryptBlobBytes, EncryptBytes, EncryptedBlobBytes, + EncryptedBoxBytes, } from "./types"; /** @@ -203,7 +204,10 @@ export async function fromHex(input: string) { * * 3. Box returns a "nonce", while Blob returns a "header". */ -const encryptBox = async ({ data, keyB64 }: EncryptBytes) => { +const encryptBox = async ({ + data, + keyB64, +}: EncryptBytes): Promise => { await sodium.ready; const nonce = sodium.randombytes_buf(sodium.crypto_secretbox_NONCEBYTES); const encryptedData = sodium.crypto_secretbox_easy( @@ -211,10 +215,7 @@ const encryptBox = async ({ data, keyB64 }: EncryptBytes) => { nonce, await fromB64(keyB64), ); - return { - encryptedData, - nonce, - }; + return { encryptedData, nonceB64: await toB64(nonce) }; }; /** @@ -440,7 +441,7 @@ export async function encryptToB64(data: string, keyB64: string) { return { encryptedData: await toB64(encrypted.encryptedData), key: keyB64, - nonce: await toB64(encrypted.nonce), + nonce: encrypted.nonceB64, } as B64EncryptionResult; }