Skip to content

Commit

Permalink
Update src/hex.ts
Browse files Browse the repository at this point in the history
Co-authored-by: Mark Stacey <markjstacey@gmail.com>
  • Loading branch information
mikesposito and Gudahtt authored Jul 11, 2023
1 parent 38444a9 commit 4a49c16
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/hex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('')}`;
}

Expand Down

0 comments on commit 4a49c16

Please sign in to comment.