@polkadot/util-crypto#keccakAsHex TypeScript Examples
The following examples show how to use
@polkadot/util-crypto#keccakAsHex.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: util.ts From crust-apps with Apache License 2.0 | 7 votes |
// converts an Ethereum address to a checksum representation
export function addrToChecksum (_address: string): string {
const address = _address.toLowerCase();
const hash = keccakAsHex(address.substr(2)).substr(2);
let result = '0x';
for (let n = 0; n < 40; n++) {
result = `${result}${
parseInt(hash[n], 16) > 7
? address[n + 2].toUpperCase()
: address[n + 2]
}`;
}
return result;
}
Example #2
Source File: util.ts From crust-apps with Apache License 2.0 | 6 votes |
// convert a give public key to an Ethereum address (the last 20 bytes of an _exapnded_ key keccack)
export function publicToAddr (publicKey: Uint8Array): string {
return addrToChecksum(`0x${keccakAsHex(publicKey).slice(-40)}`);
}