From 76777744f0adbd4ceece9098d0ae6ad31653e139 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Thu, 19 May 2022 16:22:04 +1000 Subject: [PATCH] Remove `Buffer` from `decrypt*` --- src/lib/waku_message/version_1.ts | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/lib/waku_message/version_1.ts b/src/lib/waku_message/version_1.ts index 6407b2a00d..05c6a2a929 100644 --- a/src/lib/waku_message/version_1.ts +++ b/src/lib/waku_message/version_1.ts @@ -126,15 +126,15 @@ export async function encryptAsymmetric( /** * Proceed with Asymmetric decryption of the data as per [26/WAKU-PAYLOAD](https://rfc.vac.dev/spec/26/). - * The return data is expect to be flags | payload-length | payload | [signature]. + * The returned data is expected to be `flags | payload-length | payload | [signature]`. * * @internal */ export async function decryptAsymmetric( - payload: Uint8Array | Buffer, - privKey: Uint8Array | Buffer + payload: Uint8Array, + privKey: Uint8Array ): Promise { - return ecies.decrypt(Buffer.from(privKey), Buffer.from(payload)); + return ecies.decrypt(privKey, payload); } /** @@ -167,15 +167,14 @@ export async function encryptSymmetric( * @internal */ export async function decryptSymmetric( - payload: Uint8Array | Buffer, - key: Uint8Array | Buffer | string + payload: Uint8Array, + key: Uint8Array | string ): Promise { - const data = Buffer.from(payload); - const ivStart = data.length - symmetric.IvSize; - const cipher = data.slice(0, ivStart); - const iv = data.slice(ivStart); + const ivStart = payload.length - symmetric.IvSize; + const cipher = payload.slice(0, ivStart); + const iv = payload.slice(ivStart); - return symmetric.decrypt(iv, Buffer.from(hexToBytes(key)), cipher); + return symmetric.decrypt(iv, hexToBytes(key), cipher); } /**