-
Notifications
You must be signed in to change notification settings - Fork 0
/
address.py
40 lines (29 loc) · 1.09 KB
/
address.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from hashing import blake2b_hash
def proof_sender(public_key, sender):
if make_address(public_key) == sender:
return True
def validate_address(address: str, checksum_size: str = 2):
if address[-4:] == make_checksum(address[: -checksum_size * 2]):
return True
elif address == "burn":
return True
else:
return False
def make_checksum(public_key: str, checksum_size: int = 2) -> str:
checksum = blake2b_hash(data=public_key, size=checksum_size)
return checksum
def make_address(
public_key: str,
address_length: int = 42,
checksum_size: int = 2,
prefix: str = "ndo",
) -> str:
address_no_checksum = f"{prefix}{public_key[:address_length]}"
address = f"{address_no_checksum}{make_checksum(address_no_checksum, checksum_size=checksum_size)}"
return address
if __name__ == "__main__":
public_key = "96381e3725f85cfe0ab8de17623957b4565ca9b04d37b903075f2723600c21e3"
print(make_address(public_key))
print(
validate_address(make_address(public_key, address_length=42, checksum_size=2))
)