From a3f114bacc11805d9b245a1e1dcaa6d586f2a8d4 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Thu, 14 May 2026 06:54:01 -0700 Subject: [PATCH] Throw if hex input is an odd number of characters. --- src/lib/nano25519.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib/nano25519.ts b/src/lib/nano25519.ts index c9d6fca..5654d22 100644 --- a/src/lib/nano25519.ts +++ b/src/lib/nano25519.ts @@ -152,7 +152,10 @@ const nano25519_init = (bytes: number[]): { derive: typeof derive, sign: typeof if (typeof value === 'string') { const regex = RegExp(`^[A-Fa-f0-9]{${byteLengthMin << 1},${byteLengthMax << 1}}$`) if (!regex.test(value)) { - throw new TypeError(`Invalid ${name} ${value}`) + throw new TypeError(`Invalid hexadecimal characters in ${name} ${value}`) + } + if (value.length & 1) { + throw new TypeError(`Invalid hexadecimal length for ${name} ${value}`) } value = new Uint8Array(value.match(/[A-Fa-f0-9]{2}/g)?.map(b => parseInt(b, 16)) || []) } -- 2.47.3