1 | import { u8aToHex } from '@polkadot/util';
|
2 | import { keccakAsU8a } from '../keccak/index.js';
|
3 | function isInvalidChar(char, byte) {
|
4 | return char !== (byte > 7
|
5 | ? char.toUpperCase()
|
6 | : char.toLowerCase());
|
7 | }
|
8 | export function isEthereumChecksum(_address) {
|
9 | const address = _address.replace('0x', '');
|
10 | const hash = u8aToHex(keccakAsU8a(address.toLowerCase()), -1, false);
|
11 | for (let i = 0; i < 40; i++) {
|
12 | if (isInvalidChar(address[i], parseInt(hash[i], 16))) {
|
13 | return false;
|
14 | }
|
15 | }
|
16 | return true;
|
17 | }
|