2021-08-21 09:27:40 +02:00
|
|
|
# external imports
|
2021-06-28 07:48:36 +02:00
|
|
|
import sha3
|
|
|
|
from hexathon import (
|
|
|
|
strip_0x,
|
|
|
|
uniform,
|
|
|
|
)
|
2021-10-18 14:23:54 +02:00
|
|
|
from funga.eth.encoding import (
|
2021-06-28 07:48:36 +02:00
|
|
|
is_address,
|
|
|
|
is_checksum_address,
|
|
|
|
to_checksum_address,
|
|
|
|
)
|
|
|
|
|
|
|
|
to_checksum = to_checksum_address
|
2021-08-21 09:27:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
class AddressChecksum:
|
|
|
|
"""Address checksummer implementation.
|
|
|
|
|
|
|
|
Primarily for use with chainlib.cli.wallet.Wallet
|
|
|
|
"""
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def valid(cls, v):
|
|
|
|
"""Check if address is a valid checksum address
|
|
|
|
|
|
|
|
:param v: Address value, in hex
|
|
|
|
:type v: str
|
|
|
|
:rtype: bool
|
|
|
|
:returns: True if valid checksum
|
|
|
|
"""
|
|
|
|
return is_checksum_address(v)
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def sum(cls, v):
|
|
|
|
"""Create checksum from address
|
|
|
|
|
|
|
|
:param v: Address value, in hex
|
|
|
|
:type v: str
|
|
|
|
:raises ValueError: Invalid address
|
|
|
|
:rtype: str
|
|
|
|
:returns: Checksum address
|
|
|
|
"""
|
|
|
|
return to_checksum_address(v)
|
2021-10-18 12:49:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
def is_same_address(a, b):
|
|
|
|
return uniform(strip_0x(a)) == uniform(strip_0x(b))
|