mirror of
https://github.com/pezkuwichain/pezkuwi-common.git
synced 2026-04-28 01:38:05 +00:00
21 lines
696 B
JavaScript
21 lines
696 B
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.isEthereumChecksum = isEthereumChecksum;
|
|
const util_1 = require("@pezkuwi/util");
|
|
const index_js_1 = require("../keccak/index.js");
|
|
function isInvalidChar(char, byte) {
|
|
return char !== (byte > 7
|
|
? char.toUpperCase()
|
|
: char.toLowerCase());
|
|
}
|
|
function isEthereumChecksum(_address) {
|
|
const address = _address.replace('0x', '');
|
|
const hash = (0, util_1.u8aToHex)((0, index_js_1.keccakAsU8a)(address.toLowerCase()), -1, false);
|
|
for (let i = 0; i < 40; i++) {
|
|
if (isInvalidChar(address[i], parseInt(hash[i], 16))) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|