diff --git a/silkaj/crypto_tools.py b/silkaj/crypto_tools.py index 88ce3fea20a009074ef3685e9eaa5dd4fc4590c8..89a8057603f1a1f31c3b19a1cb970c48cde2e673 100644 --- a/silkaj/crypto_tools.py +++ b/silkaj/crypto_tools.py @@ -82,60 +82,3 @@ def gen_checksum(pubkey): pubkey_byte = base58.b58decode(pubkey) hash = hashlib.sha256(hashlib.sha256(pubkey_byte).digest()).digest() return base58.b58encode(hash)[:3].decode("utf-8") - - -b58_digits = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" - - -def b58_encode(b): - - # Convert big-endian bytes to integer - n = int("0x0" + encoding.HexEncoder.encode(b).decode("utf8"), 16) - - # Divide that integer into base58 - res = [] - while n > 0: - n, r = divmod(n, 58) - res.append(b58_digits[r]) - res = "".join(res[::-1]) - - # Encode leading zeros as base58 zeros - czero = 0 - pad = 0 - for c in b: - if c == czero: - pad += 1 - else: - break - return b58_digits[0] * pad + res - - -def b58_decode(s): - if not s: - return b"" - - # Convert the string to an integer - n = 0 - for c in s: - n *= 58 - if c not in b58_digits: - raise InvalidBase58Error( - "Character %r is not a " + "valid base58 character" % c - ) - digit = b58_digits.index(c) - n += digit - - # Convert the integer to bytes - h = "%x" % n - if len(h) % 2: - h = "0" + h - res = encoding.HexEncoder.decode(h.encode("utf8")) - - # Add padding back. - pad = 0 - for c in s[:-1]: - if c == b58_digits[0]: - pad += 1 - else: - break - return b"\x00" * pad + res