From faa451453238e7655a3c98c55a4bb4da771c8c60 Mon Sep 17 00:00:00 2001 From: Oren Date: Wed, 29 Nov 2023 21:52:51 +0200 Subject: [PATCH] fix: `hexToBuffer` bug (#6098) * Fix `hexToBuffer` bug Related to this "documented behavior" quirk of `Buffer.from`: https://github.com/nodejs/node/issues/21242 * Fix lint * Implement in multiple lines --- packages/prover/src/utils/conversion.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/prover/src/utils/conversion.ts b/packages/prover/src/utils/conversion.ts index 1f143baf1bda..c809de5c4555 100644 --- a/packages/prover/src/utils/conversion.ts +++ b/packages/prover/src/utils/conversion.ts @@ -23,7 +23,8 @@ export function bufferToHex(buffer: Buffer | Uint8Array): string { } export function hexToBuffer(val: string): Buffer { - return Buffer.from(val.replace("0x", ""), "hex"); + const hexWithEvenLength = val.length % 2 ? `0${val}` : val; + return Buffer.from(hexWithEvenLength.replace("0x", ""), "hex"); } export function padLeft(v: T, length: number): T {