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