Пример #1
0
def test_TestAddressString():
    public_key = skycoin.cipher_PubKey()
    secret_key = skycoin.cipher_SecKey()
    skycoin.SKY_cipher_GenerateKeyPair(public_key, secret_key)
    address = skycoin.cipher__Address()
    skycoin.SKY_cipher_AddressFromPubKey(public_key, address)
    _, addres_str = skycoin.SKY_cipher_Address_String(address)
    address_2 = skycoin.cipher__Address()
    err = skycoin.SKY_cipher_DecodeBase58Address(addres_str, address_2)
    assert err == skycoin.SKY_OK
    assert address == address_2
    _, addres_2_str = skycoin.SKY_cipher_Address_String(address_2)
    addres_3 = skycoin.cipher__Address()
    err = skycoin.SKY_cipher_DecodeBase58Address(addres_2_str, addres_3)
    assert err == skycoin.SKY_OK
    assert address_2 == addres_3
Пример #2
0
def test_cipherAddress():
	address = skycoin.cipher__Address()
	error = skycoin.SKY_cipher_DecodeBase58Address("2GgFvqoyk9RjwVzj8tqfcXVXB4orBwoc9qv", address)
	assert error == 0
	error, bytes = skycoin.SKY_cipher_Address_BitcoinBytes(address)
	assert error == 0
	assert len( bytes ) > 0
	address2 = skycoin.cipher__Address()
	error = skycoin.SKY_cipher_BitcoinAddressFromBytes( bytes, address2 )
	assert error == 0
	assert address.isEqual(address2)
Пример #3
0
def test_TestPubKeyToAddress():
    public_key = skycoin.cipher_PubKey()
    secret_key = skycoin.cipher_SecKey()
    skycoin.SKY_cipher_GenerateKeyPair(public_key, secret_key)
    addres = skycoin.cipher__Address()
    skycoin.SKY_cipher_AddressFromPubKey(public_key, addres)
    # func (self Address) Verify(key PubKey) error
    assert skycoin.SKY_cipher_Address_Verify(addres,
                                             public_key) == skycoin.SKY_OK
    # func DecodeBase58Address(addr string) (Address, error)
    _, addres_str = skycoin.SKY_cipher_Address_String(addres)
    assert skycoin.SKY_cipher_DecodeBase58Address(addres_str,
                                                  addres) == skycoin.SKY_OK
Пример #4
0
def address_valid(address):
    """
    Check if an address is valid
    A SKY address uses an alphanumeric base58 encoding, without 0, O, I or l.
    Important note: the last four bytes are a checksum check. They are the
    first four bytes of a double SHA-256 digest of the previous 21 bytes
    Read the first twenty-one bytes, compute the checksum, and
    check that it corresponds to the last four bytes.
    """
    addressObj = skycoin.cipher__Address()
    error = skycoin.SKY_cipher_DecodeBase58Address(address.encode(),
                                                   addressObj)
    return jsonify({"isValid": error == 0})
Пример #5
0
def test_TestDecodeBase58Address():
    public_key = skycoin.cipher_PubKey()
    secret_key = skycoin.cipher_SecKey()
    skycoin.SKY_cipher_GenerateKeyPair(public_key, secret_key)
    address = skycoin.cipher__Address()
    skycoin.SKY_cipher_AddressFromPubKey(public_key, address)
    err = skycoin.SKY_cipher_Address_Verify(address, public_key)
    assert err == skycoin.SKY_OK
    address_2 = skycoin.cipher__Address()
    err = skycoin.SKY_cipher_DecodeBase58Address(b'""', address_2)
    assert err == skycoin.SKY_ERROR
    err = skycoin.SKY_cipher_DecodeBase58Address(b'"cascs"', address_2)
    assert err == skycoin.SKY_ERROR
    _, byte = skycoin.SKY_cipher_Address_Bytes(address)
    _, h = skycoin.SKY_base58_Hex2Base58(byte[:int(len(byte) / 2)])
    err = skycoin.SKY_cipher_DecodeBase58Address(h, address_2)
    assert err == skycoin.SKY_ErrAddressInvalidLength
    _, h = skycoin.SKY_base58_Hex2Base58(byte)
    err = skycoin.SKY_cipher_DecodeBase58Address(h, address_2)
    assert err == skycoin.SKY_OK
    assert address == address_2
    _, addres_str = skycoin.SKY_cipher_Address_String(address)
    err = skycoin.SKY_cipher_DecodeBase58Address(addres_str, address_2)
    assert err == skycoin.SKY_OK
    assert address == address_2
    #  preceding whitespace is invalid
    addres_2_str = b'" " + a_str'
    err = skycoin.SKY_cipher_DecodeBase58Address(addres_2_str, address_2)
    assert err == skycoin.SKY_ERROR
    #  preceding zeroes are invalid
    addres_2_str = b'"000" + a_str'
    err = skycoin.SKY_cipher_DecodeBase58Address(addres_2_str, address_2)
    assert err == skycoin.SKY_ERROR
    #  trailing whitespace is invalid
    addres_2_str = b'a_str + " "'
    err = skycoin.SKY_cipher_DecodeBase58Address(addres_2_str, address_2)
    assert err == skycoin.SKY_ERROR
    # trailing zeroes are invalid
    addres_2_str = b'a_str + "000"'
    err = skycoin.SKY_cipher_DecodeBase58Address(addres_2_str, address_2)
    assert err == skycoin.SKY_ERROR
Пример #6
0
def test_TestAddressBulk():
    for _ in range(1024):
        public_key = skycoin.cipher_PubKey()
        secret_key = skycoin.cipher_SecKey()
        addres_1 = skycoin.cipher__Address()
        address_2 = skycoin.cipher__Address()
        _, data = skycoin.SKY_cipher_RandByte(32)
        skycoin.SKY_cipher_GenerateDeterministicKeyPair(
            data, public_key, secret_key)
        skycoin.SKY_cipher_AddressFromPubKey(public_key, addres_1)
        err = skycoin.SKY_cipher_Address_Verify(addres_1, public_key)
        assert err == skycoin.SKY_OK
        _, addres_str = skycoin.SKY_cipher_Address_String(addres_1)
        err = skycoin.SKY_cipher_DecodeBase58Address(addres_str, address_2)
        assert err == skycoin.SKY_OK
        assert addres_1 == address_2
Пример #7
0
def KeysTestDataFromJSON(KeysTestDataJSON):
    address = skycoin.cipher__Address()
    err = skycoin.SKY_cipher_DecodeBase58Address(
        KeysTestDataJSON["address"].encode(), address)
    if err != skycoin.SKY_OK:
        return skycoin.SKY_ERROR, None
    err, hex_str = skycoin.SKY_base58_String2Hex(
        KeysTestDataJSON["secret"].encode())
    assert err == skycoin.SKY_OK
    secret_key = skycoin.cipher_SecKey()
    err = skycoin.SKY_cipher_NewSecKey(hex_str, secret_key)
    assert err == skycoin.SKY_OK

    err, secret_key_hex = skycoin.SKY_cipher_SecKey_Hex(secret_key)
    if err != skycoin.SKY_OK:
        return skycoin.SKY_ERROR, None

    err, hex_str = skycoin.SKY_base58_String2Hex(
        KeysTestDataJSON["public"].encode())
    assert err == skycoin.SKY_OK
    public_key = skycoin.cipher_PubKey()
    err = skycoin.SKY_cipher_NewPubKey(hex_str, public_key)
    assert err == skycoin.SKY_OK

    err, public_key_hex = skycoin.SKY_cipher_PubKey_Hex(public_key)
    if err != skycoin.SKY_OK:
        return skycoin.SKY_ERROR, None

    r = KeysTestData()
    r.Address = address
    r.Public = public_key_hex
    r.Secret = secret_key_hex
    r.Signatures = 0
    if KeysTestDataJSON.get("signatures") == None:
        return skycoin.SKY_OK, r
    sigs = []
    if len(KeysTestDataJSON["signatures"]) >= 0:
        for s in KeysTestDataJSON["signatures"]:
            sig_fromHex = skycoin.cipher_Sig()
            err = skycoin.SKY_cipher_SigFromHex(s.encode(), sig_fromHex)
            assert err == skycoin.SKY_OK
            sigs.append(sig_fromHex)
            assert err == skycoin.SKY_OK
    r.Signatures = sigs
    return skycoin.SKY_OK, r
Пример #8
0
def test_GenerateKeyPairs():
	error, data = skycoin.SKY_cipher_RandByte(32)
	assert error == 0
	pubkey = skycoin.cipher_PubKey()
	seckey = skycoin.cipher_SecKey()
	error = skycoin.SKY_cipher_GenerateDeterministicKeyPair(data, pubkey, seckey)
	assert error == 0
	address = skycoin.cipher__Address()
	error = skycoin.SKY_cipher_AddressFromPubKey(pubkey, address)
	assert error == 0
	error = skycoin.SKY_cipher_Address_Verify(address, pubkey)
	assert error == 0
	error, address_string = skycoin.SKY_cipher_Address_String( address )
	assert error == 0
	address2 = skycoin.cipher__Address()
	error = skycoin.SKY_cipher_DecodeBase58Address( address_string, address2 )
	assert error == 0
	assert address.isEqual(address2)