From 0555a9a92b2d1a411979fcba974a9e273953b3c6 Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Sat, 21 Jan 2023 09:34:04 -0700 Subject: [PATCH 1/3] fix: add check for 0x in hex string --- packages/core/src/common/encoding-hex.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/core/src/common/encoding-hex.ts b/packages/core/src/common/encoding-hex.ts index 92967d51..165db325 100644 --- a/packages/core/src/common/encoding-hex.ts +++ b/packages/core/src/common/encoding-hex.ts @@ -10,6 +10,7 @@ for (let n = 0; n <= 0xff; ++n) { export function hexToBytes(hex: string): Uint8Array { if (typeof hex !== 'string') throw new TypeError('hexToBytes: expected string, got ' + typeof hex); + if (hex.startsWith('0x')) hex = hex.slice(2); if (hex.length % 2) throw new Error(`hexToBytes: received invalid unpadded hex, got: ${hex.length}`); const array = new Uint8Array(hex.length / 2); From 542d22c8af29daf94a25cf2094cb3c087b6a18d2 Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Sat, 21 Jan 2023 09:36:16 -0700 Subject: [PATCH 2/3] fix: modify to use existing cleanHex() function --- packages/core/src/common/encoding-hex.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/common/encoding-hex.ts b/packages/core/src/common/encoding-hex.ts index 165db325..5f285ca0 100644 --- a/packages/core/src/common/encoding-hex.ts +++ b/packages/core/src/common/encoding-hex.ts @@ -10,7 +10,7 @@ for (let n = 0; n <= 0xff; ++n) { export function hexToBytes(hex: string): Uint8Array { if (typeof hex !== 'string') throw new TypeError('hexToBytes: expected string, got ' + typeof hex); - if (hex.startsWith('0x')) hex = hex.slice(2); + if (hex.startsWith('0x')) hex = cleanHex(hex); if (hex.length % 2) throw new Error(`hexToBytes: received invalid unpadded hex, got: ${hex.length}`); const array = new Uint8Array(hex.length / 2); From a41c890b674209357513b54169130728c316438f Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 12 Apr 2023 08:24:07 -0500 Subject: [PATCH 3/3] Create sixty-ravens-swim.md --- .changeset/sixty-ravens-swim.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/sixty-ravens-swim.md diff --git a/.changeset/sixty-ravens-swim.md b/.changeset/sixty-ravens-swim.md new file mode 100644 index 00000000..f527751b --- /dev/null +++ b/.changeset/sixty-ravens-swim.md @@ -0,0 +1,5 @@ +--- +"micro-stacks": patch +--- + +Add check for `0x` in hex string