Last active
May 22, 2023 06:47
-
-
Save ochaloup/58ceee3ed436766ba7c444bf3fbc8545 to your computer and use it in GitHub Desktop.
Python script to a binary uint8 array (decimal numbers) to base58 formatted string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!~/.pyenv/shims/python3 | |
# Usage: | |
# tobase58.py [3,0,0,0] | |
# Output: | |
# 5Sxr3 | |
import base58 | |
import sys | |
import json | |
if len(sys.argv) != 2: | |
print(f"Expecting one argument of json array listing uint items. The argument was not provided. Arguments: {sys.argv}") | |
exit(1) | |
json_string = sys.argv[1] | |
json_string = json_string.strip() | |
if not json_string.startswith("["): | |
print(f"Expecting the provided argument is a json array and starts with '[', but it is: {json_string}") | |
exit(2) | |
json_data = json.loads(json_string) | |
byte_array = bytearray(json_data) | |
print(base58.b58encode(byte_array).decode('utf-8')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment