From a791dddb64701510b5408d8ed92c3bedda44dfc0 Mon Sep 17 00:00:00 2001 From: Moul <moul@moul.re> Date: Sat, 17 Oct 2020 12:28:24 +0200 Subject: [PATCH] [mod] #176: Get rid of base58 code --- silkaj/crypto_tools.py | 57 ------------------------------------------ 1 file changed, 57 deletions(-) diff --git a/silkaj/crypto_tools.py b/silkaj/crypto_tools.py index 88ce3fea..89a80576 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 -- GitLab