address.py (1029B)
1 # external imports 2 import sha3 3 from hexathon import ( 4 strip_0x, 5 uniform, 6 ) 7 from funga.eth.encoding import ( 8 is_address, 9 is_checksum_address, 10 to_checksum_address, 11 ) 12 13 to_checksum = to_checksum_address 14 15 16 class AddressChecksum: 17 """Address checksummer implementation. 18 19 Primarily for use with chainlib.cli.wallet.Wallet 20 """ 21 22 @classmethod 23 def valid(cls, v): 24 """Check if address is a valid checksum address 25 26 :param v: Address value, in hex 27 :type v: str 28 :rtype: bool 29 :returns: True if valid checksum 30 """ 31 return is_checksum_address(v) 32 33 34 @classmethod 35 def sum(cls, v): 36 """Create checksum from address 37 38 :param v: Address value, in hex 39 :type v: str 40 :raises ValueError: Invalid address 41 :rtype: str 42 :returns: Checksum address 43 """ 44 return to_checksum_address(v) 45 46 47 def is_same_address(a, b): 48 return uniform(strip_0x(a)) == uniform(strip_0x(b))