-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFEVM f4 to 0x address converter
33 lines (25 loc) · 1.01 KB
/
FEVM f4 to 0x address converter
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
import base64
def add_base32_padding(encoded_text):
padding_needed = 8 - (len(encoded_text) % 8)
return encoded_text + '=' * padding_needed
def remove_f4_prefix(encoded_text):
prefix = "f410f"
if encoded_text.startswith(prefix):
return encoded_text[len(prefix):]
else:
return None
sample_f4_address = "f410f67hkuxnhgbnyonq7tw3kgaf5nv2mm5gsqrl67mq"
def convert_address_f4_0X(encoded_text):
if encoded_text is not None and len(encoded_text) == len(sample_f4_address):
encoded_text = remove_f4_prefix(encoded_text)
encoded_text_with_padding = add_base32_padding(encoded_text.upper())
decoded_bytes = base64.b32decode(encoded_text_with_padding)
# Discard the last 4 bytes
decoded_bytes = decoded_bytes[:-4]
hex_string = decoded_bytes.hex()
print(hex_string)
return hex_string
else:
print("Incorrect f4 address format")
#Example operation
convert_address_f4_0X("f410f67hkuxnhgbnyonq7tw3kgaf5nv2mm5gsqrl67mq")