Skip to content

Commit

Permalink
fix: hexToBuffer bug (#6098)
Browse files Browse the repository at this point in the history
* Fix `hexToBuffer` bug

Related to this "documented behavior" quirk of `Buffer.from`:
nodejs/node#21242

* Fix lint

* Implement in multiple lines
  • Loading branch information
orenyomtov authored Nov 29, 2023
1 parent 248b64c commit faa4514
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/prover/src/utils/conversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends Buffer | Uint8Array>(v: T, length: number): T {
Expand Down

0 comments on commit faa4514

Please sign in to comment.