* EIP-55 mixed-case checksum address encoding. * Computes the checksum in-place using keccak256 of the lowercase hex address.
(address: string)
| 20 | * Computes the checksum in-place using keccak256 of the lowercase hex address. |
| 21 | */ |
| 22 | function toChecksumAddress(address: string): string { |
| 23 | const { createHash } = require('crypto') as typeof import('crypto') |
| 24 | const addr = address.toLowerCase().replace('0x', '') |
| 25 | const hash = createHash('sha3-256').update(addr).digest('hex') |
| 26 | let checksummed = '0x' |
| 27 | for (let i = 0; i < addr.length; i++) { |
| 28 | checksummed += |
| 29 | parseInt(hash[i], 16) >= 8 ? addr[i].toUpperCase() : addr[i] |
| 30 | } |
| 31 | return checksummed |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Derives an Ethereum address from a private key using secp256k1. |