How to use the @polkadot/util-crypto.keccakAsHex function in @polkadot/util-crypto

To help you get started, we’ve selected a few @polkadot/util-crypto examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github polkadot-js / apps / packages / app-claims / src / util.ts View on Github external
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;
}
github polkadot-js / apps / packages / app-claims / src / util.ts View on Github external
export function publicToAddr (publicKey: Uint8Array): string {
  return addrToChecksum(`0x${keccakAsHex(publicKey).slice(-40)}`);
}