def test_trailing_zeros() -> None:
    assert _b58encode(b"\x00\x00hello world") == b"11StV1DL6CwTryKyV"
    assert _b58decode(b"11StV1DL6CwTryKyV") == b"\x00\x00hello world"
    assert _b58decode(_b58encode(b"\x00\x00hello world")) == b"\x00\x00hello world"
    assert _b58encode(_b58decode(b"11StV1DL6CwTryKyV")) == b"11StV1DL6CwTryKyV"

    assert b58decode(b58encode(b"\x00\x00hello world"), 13) == b"\x00\x00hello world"
예제 #2
0
 def test_hello_world(self):
     self.assertEqual(_b58encode(b'hello world'), b'StV1DL6CwTryKyV')
     self.assertEqual(_b58decode(b'StV1DL6CwTryKyV', None), b'hello world')
     self.assertEqual(_b58decode(_b58encode(b'hello world'), None),
                      b'hello world')
     self.assertEqual(_b58encode(_b58decode(b'StV1DL6CwTryKyV', None)),
                      b'StV1DL6CwTryKyV')
예제 #3
0
 def test_hello_world(self):
     self.assertEqual(_b58encode(b"hello world"), b"StV1DL6CwTryKyV")
     self.assertEqual(_b58decode(b"StV1DL6CwTryKyV"), b"hello world")
     self.assertEqual(_b58decode(_b58encode(b"hello world")),
                      b"hello world")
     self.assertEqual(_b58encode(_b58decode(b"StV1DL6CwTryKyV")),
                      b"StV1DL6CwTryKyV")
def test_hello_world() -> None:
    assert _b58encode(b"hello world") == b"StV1DL6CwTryKyV"
    assert _b58decode(b"StV1DL6CwTryKyV") == b"hello world"
    assert _b58decode(_b58encode(b"hello world")) == b"hello world"
    assert _b58encode(_b58decode(b"StV1DL6CwTryKyV")) == b"StV1DL6CwTryKyV"

    assert b58decode(b58encode(b"hello world"), 11) == b"hello world"
예제 #5
0
 def test_trailing_zeros(self):
     self.assertEqual(_b58encode(b'\x00\x00hello world'),
                      b'11StV1DL6CwTryKyV')
     self.assertEqual(_b58decode(b'11StV1DL6CwTryKyV', None),
                      b'\x00\x00hello world')
     self.assertEqual(_b58decode(_b58encode(b'\0\0hello world'), None),
                      b'\x00\x00hello world')
     self.assertEqual(_b58encode(_b58decode(b'11StV1DL6CwTryKyV', None)),
                      b'11StV1DL6CwTryKyV')
예제 #6
0
 def test_trailing_zeros(self):
     self.assertEqual(_b58encode(b"\x00\x00hello world"),
                      b"11StV1DL6CwTryKyV")
     self.assertEqual(_b58decode(b"11StV1DL6CwTryKyV"),
                      b"\x00\x00hello world")
     self.assertEqual(_b58decode(_b58encode(b"\0\0hello world")),
                      b"\x00\x00hello world")
     self.assertEqual(_b58encode(_b58decode(b"11StV1DL6CwTryKyV")),
                      b"11StV1DL6CwTryKyV")
def test_exceptions() -> None:

    encoded = b58encode(b"hello world")
    b58decode(encoded, 11)

    wrong_length = len(encoded) - 1
    with pytest.raises(BTClibValueError, match="invalid decoded size: "):
        b58decode(encoded, wrong_length)

    invalid_checksum = encoded[:-4] + b"1111"
    with pytest.raises(BTClibValueError, match="invalid checksum: "):
        b58decode(invalid_checksum, 4)

    err_msg = "'ascii' codec can't encode character "
    with pytest.raises(UnicodeEncodeError, match=err_msg):
        b58decode("hèllo world")

    err_msg = "not enough bytes for checksum, invalid base58 decoded size: "
    with pytest.raises(BTClibValueError, match=err_msg):
        b58decode(_b58encode(b"123"))
예제 #8
0
def test_exceptions() -> None:

    with pytest.raises(TypeError,
                       match="object supporting the buffer API required"):
        b58encode(3)  # type: ignore

    encoded = b58encode(b"hello world")
    b58decode(encoded, 11)

    wrong_length = len(encoded) - 1
    with pytest.raises(ValueError, match="invalid decoded size: "):
        b58decode(encoded, wrong_length)

    invalidChecksum = encoded[:-4] + b"1111"
    with pytest.raises(ValueError, match="invalid checksum: "):
        b58decode(invalidChecksum, 4)

    with pytest.raises(ValueError,
                       match="'ascii' codec can't encode character "):
        b58decode("hèllo world")

    err_msg = "not enough bytes for checksum, invalid base58 decoded size: "
    with pytest.raises(ValueError, match=err_msg):
        b58decode(_b58encode(b"123"))
예제 #9
0
h1 = sha256(payload).digest()
print(h1.hex())

print("\n*** [4] SHA-256 hashing of the SHA-256:")
h2 = sha256(h1).digest()
print(h2.hex())

print("\n*** [5] First 4 bytes of the double SHA-256 used as checksum:")
print(h2[:4].hex())

print("\n*** [6] checksum added at the end of the payload:")
checksummed_payload = payload + h2[:4]
print(checksummed_payload.hex())

print("\n*** [7] Base58 encoding")
wif = base58._b58encode(checksummed_payload)
print(wif)
assert wif == b"5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ"
wif = base58.b58encode(payload)
assert wif == b"5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ"

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._b58decode(wif)
print(checksummed_payload.hex())
예제 #10
0
def test_empty():
    assert _b58encode(b"") == b""
    assert _b58decode(_b58encode(b"")) == b""
예제 #11
0
 def test_empty(self):
     self.assertEqual(_b58encode(b''), b'')
     self.assertEqual(_b58decode(_b58encode(b''), None), b'')
def test_empty() -> None:
    assert _b58encode(b"") == b""
    assert _b58decode(_b58encode(b"")) == b""

    assert b58decode(b58encode(b""), 0) == b""
예제 #13
0
h3 = hashlib.sha256(vh160).digest()
print(h3.hex())

print("\n** [6] SHA-256 hashing of the result of the previous SHA-256 hash:")
h4 = hashlib.sha256(h3).digest()
print(h4.hex())

print("\n** [7] First 4 bytes of the second SHA-256 used as checksum:")
print(h4[:4].hex())

print("\n** [8] checksum added at the end of extended RIPEMD-160 hash:")
addr = vh160 + h4[:4]
print(addr.hex())

print("\n** [9] Base58 encoded address from uncompressed PubKey")
address = base58._b58encode(addr)
print(address)
assert address == b"16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM"
assert base58.b58encode(vh160) == b"16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM"

print("\n** steps [5]-[9] are also known as Base58Check b58encode")


def pubkey_bytes_from_prvkey(prvkey, compressed=True):
    PubKey = mult(prvkey)
    if compressed:
        prefix = b"\x02" if (PubKey[1] % 2 == 0) else b"\x03"
        return prefix + PubKey[0].to_bytes(32, byteorder="big")
    else:
        prefix = b"\x04"
        return (prefix + PubKey[0].to_bytes(32, byteorder="big") +
예제 #14
0
 def test_empty(self):
     self.assertEqual(_b58encode(b""), b"")
     self.assertEqual(_b58decode(_b58encode(b"")), b"")