1import { reduce } from 'lodash';
2import { isAddress, keccak256 } from 'web3-utils';
3import { pubToAddress } from 'ethereumjs-util';
4import { ETH_ZERO_ADDR, ETH_ZERO_ADDR_SHORT } from 'lib/constants';
6export const stripHexPrefix = (hex: string) => {
7 return hex.startsWith('0x') ? hex.slice(2) : hex;
10export const addHexPrefix = (hex: string) => {
11 return hex.startsWith('0x') ? hex : `0x${hex}`;
14export const isValidAddress = (a: string) => '0x0' === a || isAddress(a);
16export const abbreviateAddress = (address: string) =>
17 `${address.slice(0, 6)}…${address.slice(-4)}`;
19export const isZeroAddress = (a: string) =>
20 a === ETH_ZERO_ADDR || a === ETH_ZERO_ADDR_SHORT;
22export const toChecksumAddress = (address: string) => {
23 const addr = stripHexPrefix(address).toLowerCase();
24 const hash = keccak256(addr).toString('hex');
29 parseInt(hash[idx], 16) >= 8 ? acc + char.toUpperCase() : acc + char,
34export const eqAddr = (addr0: string, addr1: string) =>
37 : toChecksumAddress(addr0) === toChecksumAddress(addr1);
39export const publicToAddress = (publicKey: Buffer): string => {
40 return '0x' + pubToAddress(Buffer.from(publicKey), true).toString('hex');
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list