コード例 #1
0
def test_TestECDHonce():
    secret_key_1 = skycoin.cipher_SecKey()
    public_key_1 = skycoin.cipher_PubKey()
    secret_key_2 = skycoin.cipher_SecKey()
    public_key_2 = skycoin.cipher_PubKey()
    skycoin.SKY_cipher_GenerateKeyPair(public_key_1, secret_key_1)
    skycoin.SKY_cipher_GenerateKeyPair(public_key_2, secret_key_2)
    _, data_1 = skycoin.SKY_cipher_ECDH(public_key_2, secret_key_1)
    _, data_2 = skycoin.SKY_cipher_ECDH(public_key_1, secret_key_2)
    assert data_1 == data_2
コード例 #2
0
def test_TestSecKeyVerify():
    # Empty secret key should not be valid
    secret_key = skycoin.cipher_SecKey()
    public_key = skycoin.cipher_PubKey()
    assert skycoin.SKY_cipher_SecKey_Verify(secret_key) is not None
    # Generated sec key should be valid
    skycoin.SKY_cipher_GenerateKeyPair(public_key, secret_key)
    assert skycoin.SKY_cipher_PubKey_Verify(public_key) == skycoin.SKY_OK
コード例 #3
0
def test_TestBitcoinAddressNull():
    a = skycoin.cipher__BitcoinAddress()
    err = skycoin.SKY_cipher_BitcoinAddress_Null(a)
    assert err == 1
    p = skycoin.cipher_PubKey()
    s = skycoin.cipher_SecKey()
    err = skycoin.SKY_cipher_GenerateKeyPair(p, s)
    assert err == skycoin.SKY_OK
    skycoin.SKY_cipher_BitcoinAddressFromPubKey(p, a)
    err = skycoin.SKY_cipher_BitcoinAddress_Null(a)
    assert err == 0
コード例 #4
0
def test_TestSignHash():
    public_key = skycoin.cipher_PubKey()
    secret_key = skycoin.cipher_SecKey()
    addres = skycoin.cipher__Address()
    sha_sum = skycoin.cipher_SHA256()
    sig_1 = skycoin.cipher_Sig()
    sig_2 = skycoin.cipher_Sig()
    skycoin.SKY_cipher_GenerateKeyPair(public_key, secret_key)
    skycoin.SKY_cipher_AddressFromPubKey(public_key, addres)
    _, data = skycoin.SKY_cipher_RandByte(256)
    skycoin.SKY_cipher_SumSHA256(data, sha_sum)
    skycoin.SKY_cipher_SignHash(sha_sum, secret_key, sig_1)
    assert sig_1 != sig_2
コード例 #5
0
def test_TestBitcoinAddressVerify():
    p = skycoin.cipher_PubKey()
    s = skycoin.cipher_SecKey()
    err = skycoin.SKY_cipher_GenerateKeyPair(p, s)
    assert err == skycoin.SKY_OK
    a = skycoin.cipher__BitcoinAddress()
    skycoin.SKY_cipher_BitcoinAddressFromPubKey(p, a)
    # Valid pubkey+address
    err = skycoin.SKY_cipher_BitcoinAddress_Verify(a, p)
    assert err == skycoin.SKY_OK
    # Invalid pubkey
    p = skycoin.cipher_PubKey()
    err = skycoin.SKY_cipher_BitcoinAddress_Verify(a, p)
    assert err == skycoin.SKY_ErrAddressInvalidPubKey
    p2 = skycoin.cipher_PubKey()
    err = skycoin.SKY_cipher_GenerateKeyPair(p2, s)
    err = skycoin.SKY_cipher_BitcoinAddress_Verify(a, p2)
    assert err == skycoin.SKY_ErrAddressInvalidPubKey
    # Bad version
    a.Version = 0x01
    err = skycoin.SKY_cipher_BitcoinAddress_Verify(a, p2)
    assert err == skycoin.SKY_ErrAddressInvalidVersion
コード例 #6
0
def test_TestPubKeyFromSecKey():
    public_key = skycoin.cipher_PubKey()
    secret_key = skycoin.cipher_SecKey()
    skycoin.SKY_cipher_GenerateKeyPair(public_key, secret_key)
    public_key_2 = skycoin.cipher_PubKey()
    skycoin.SKY_cipher_PubKeyFromSecKey(secret_key, public_key_2)
    assert public_key == public_key_2
    secret_key_2 = skycoin.cipher_SecKey()
    assert skycoin.SKY_cipher_PubKeyFromSecKey(
        secret_key_2, public_key) == skycoin.SKY_ErrPubKeyFromNullSecKey
    _, data = skycoin.SKY_cipher_RandByte(99)
    assert skycoin.SKY_cipher_NewSecKey(
        data, secret_key) == skycoin.SKY_ErrInvalidLengthSecKey
    _, data = skycoin.SKY_cipher_RandByte(31)
    assert skycoin.SKY_cipher_NewSecKey(
        data, secret_key) == skycoin.SKY_ErrInvalidLengthSecKey
コード例 #7
0
def test_TestBitcoinWIPRoundTrio():
    public_key = skycoin.cipher_PubKey()
    secret_key_1 = skycoin.cipher_SecKey()
    secret_key_2 = skycoin.cipher_SecKey()
    skycoin.SKY_cipher_GenerateKeyPair(public_key, secret_key_1)
    wip_1 = skycoin.skycoin.SKY_cipher_BitcoinWalletImportFormatFromSeckey(
        secret_key_1)
    err = skycoin.skycoin.SKY_cipher_SecKeyFromBitcoinWalletImportFormat(
        wip_1, secret_key_2)
    assert err == skycoin.SKY_OK
    wip_2 = skycoin.skycoin.SKY_cipher_BitcoinWalletImportFormatFromSeckey(
        secret_key_2)
    _, secret_key_1_hex = skycoin.SKY_cipher_SecKey_Hex(secret_key_1)
    _, secret_key_2_hex = skycoin.SKY_cipher_SecKey_Hex(secret_key_2)
    assert secret_key_1_hex == secret_key_2_hex
    assert wip_1 == wip_2
コード例 #8
0
def test_TestDecodeBase58BitcoinAddress():
    public_key = skycoin.cipher_PubKey()
    secret_key = skycoin.cipher_SecKey()
    skycoin.SKY_cipher_GenerateKeyPair(public_key, secret_key)
    address = skycoin.cipher__BitcoinAddress()
    skycoin.SKY_cipher_BitcoinAddressFromPubKey(public_key, address)
    err = skycoin.SKY_cipher_BitcoinAddress_Verify(address, public_key)
    assert err == skycoin.SKY_OK
    address_2 = skycoin.cipher__BitcoinAddress()
    err = skycoin.SKY_cipher_DecodeBase58BitcoinAddress(b'""', address_2)
    assert err == skycoin.SKY_ERROR
    err = skycoin.SKY_cipher_DecodeBase58BitcoinAddress(b'"cascs"', address_2)
    assert err == skycoin.SKY_ERROR
    byte = skycoin.SKY_cipher_BitcoinAddress_Bytes(address)
    _, h = skycoin.SKY_base58_Hex2Base58(byte[:int(len(byte) / 2)])
    err = skycoin.SKY_cipher_DecodeBase58BitcoinAddress(h, address_2)
    assert err == skycoin.SKY_ErrAddressInvalidLength
    _, h = skycoin.SKY_base58_Hex2Base58(byte)
    err = skycoin.SKY_cipher_DecodeBase58BitcoinAddress(h, address_2)
    assert err == skycoin.SKY_OK
    assert address == address_2
    addres_str = skycoin.SKY_cipher_BitcoinAddress_String(address)
    err = skycoin.SKY_cipher_DecodeBase58BitcoinAddress(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_DecodeBase58BitcoinAddress(
        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_DecodeBase58BitcoinAddress(
        addres_2_str, address_2)
    assert err == skycoin.SKY_ERROR
    #  trailing whitespace is invalid
    addres_2_str = b'a_str + " "'
    err = skycoin.SKY_cipher_DecodeBase58BitcoinAddress(
        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_DecodeBase58BitcoinAddress(
        addres_2_str, address_2)
    assert err == skycoin.SKY_ERROR