def test_hello_world(self): self.assertEqual(base58._encode(b'hello world'), b'StV1DL6CwTryKyV') self.assertEqual(base58._decode(b'StV1DL6CwTryKyV'), b'hello world') self.assertEqual(base58._decode(base58._encode(b'hello world')), b'hello world') self.assertEqual(base58._encode(base58._decode(b'StV1DL6CwTryKyV')), b'StV1DL6CwTryKyV')
def test_trailing_zeros(self): self.assertEqual(base58._encode(b'\x00\x00hello world'), b'11StV1DL6CwTryKyV') self.assertEqual(base58._decode(b'11StV1DL6CwTryKyV'), b'\x00\x00hello world') self.assertEqual(base58._decode(base58._encode(b'\0\0hello world')), b'\x00\x00hello world') self.assertEqual(base58._encode(base58._decode(b'11StV1DL6CwTryKyV')), b'11StV1DL6CwTryKyV')
print("\n*** [7] Base58 encoding") wif = base58._encode(checksummed_payload) print(wif) assert wif == b'KwdMAjGmerYanjeui5SHS7JkmpZvVipYvB2LJGU1ZxJwYvP98617', "failure" assert base58.encode( payload ) == b'KwdMAjGmerYanjeui5SHS7JkmpZvVipYvB2LJGU1ZxJwYvP98617', "failure" print("\n****** WIF to private key ******") print("\n*** [1] Base58 WIF") print(wif) compressed = len(wif) - 51 print("compressed" if (compressed == 1) else "uncompressed") print("\n*** [2] Base58 decoding") checksummed_payload = base58._decode(wif) print(checksummed_payload.hex()) print("\n*** [3] Extended key (checksum verified)") payload, checksum = checksummed_payload[:-4], checksummed_payload[-4:] verified = (sha256(sha256(payload).digest()).digest()[:4] == checksum) print(payload.hex() + " (" + ("true" if verified else "false") + ")") print(base58.decode(wif).hex()) print("\n*** [4] Private key") p2 = payload[1:-1].hex() if compressed else payload[1:].hex() assert int(p2, 16) == q, "failure" print(p2)
def test_empty(self): self.assertEqual(base58._encode(b''), b'') self.assertEqual(base58._decode(b''), b'') self.assertEqual(base58._decode(base58._encode(b'')), b'') self.assertEqual(base58._encode(base58._decode(b'')), b'')