From 4a49c162cf40c0c036642836c1caa1c825c3ecf6 Mon Sep 17 00:00:00 2001 From: Michele Esposito <34438276+mikesposito@users.noreply.github.com> Date: Tue, 11 Jul 2023 18:08:42 +0200 Subject: [PATCH] Update src/hex.ts Co-authored-by: Mark Stacey --- src/hex.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/hex.ts b/src/hex.ts index 238dfd70c..869f2d926 100644 --- a/src/hex.ts +++ b/src/hex.ts @@ -91,11 +91,15 @@ export function getChecksumAddress(address: Hex) { const unPrefixedHash = remove0x(bytesToHex(keccak256(unPrefixed))); return `0x${unPrefixed .split('') - .map((character, nibbleIndex) => - parseInt(unPrefixedHash[nibbleIndex] as string, 16) > 7 + .map((character, nibbleIndex) => { + const hashCharacter = unPrefixedHash[nibbleIndex]; + if (!hashCharacter) { + throw new Error('Hash shorter than address'); + } + return parseInt(hashCharacter, 16) > 7 ? character.toUpperCase() - : character, - ) + : character; + }) .join('')}`; }