Remove `Buffer` from `decrypt*`

This commit is contained in:
Franck Royer 2022-05-19 16:22:04 +10:00
parent 181ba489be
commit 76777744f0
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
1 changed files with 10 additions and 11 deletions

View File

@ -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/). * 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 * @internal
*/ */
export async function decryptAsymmetric( export async function decryptAsymmetric(
payload: Uint8Array | Buffer, payload: Uint8Array,
privKey: Uint8Array | Buffer privKey: Uint8Array
): Promise<Uint8Array> { ): Promise<Uint8Array> {
return ecies.decrypt(Buffer.from(privKey), Buffer.from(payload)); return ecies.decrypt(privKey, payload);
} }
/** /**
@ -167,15 +167,14 @@ export async function encryptSymmetric(
* @internal * @internal
*/ */
export async function decryptSymmetric( export async function decryptSymmetric(
payload: Uint8Array | Buffer, payload: Uint8Array,
key: Uint8Array | Buffer | string key: Uint8Array | string
): Promise<Uint8Array> { ): Promise<Uint8Array> {
const data = Buffer.from(payload); const ivStart = payload.length - symmetric.IvSize;
const ivStart = data.length - symmetric.IvSize; const cipher = payload.slice(0, ivStart);
const cipher = data.slice(0, ivStart); const iv = payload.slice(ivStart);
const iv = data.slice(ivStart);
return symmetric.decrypt(iv, Buffer.from(hexToBytes(key)), cipher); return symmetric.decrypt(iv, hexToBytes(key), cipher);
} }
/** /**