Exemple #1
0
def test_TestTransactionSignInputs():
    handle = utils.makeEmptyTransaction()
    # Panics if txns already signed
    sig = skycoin.cipher_Sig()
    assert skycoin.SKY_coin_Transaction_PushSignature(handle, sig) == skycoin.SKY_OK
    secKeys = []
    secKeys.append(skycoin.cipher_SecKey())
    # Panics if not enough keys
    handle = utils.makeEmptyTransaction()
    ux, s = utils.makeUxOutWithSecret()
    h = skycoin.cipher_SHA256()
    assert skycoin.SKY_coin_UxOut_Hash(ux, h) == skycoin.SKY_OK
    err, _ = skycoin.SKY_coin_Transaction_PushInput(handle, h)
    assert err == skycoin.SKY_OK
    ux2, s2 = utils.makeUxOutWithSecret()
    assert skycoin.SKY_coin_UxOut_Hash(ux2, h) == skycoin.SKY_OK
    err, _ = skycoin.SKY_coin_Transaction_PushInput(handle, h)
    assert err == skycoin.SKY_OK
    assert skycoin.SKY_coin_Transaction_PushOutput(
        handle, utils.makeAddress(), 40, 80) == skycoin.SKY_OK
    err, count = skycoin.SKY_coin_Transaction_GetSignaturesCount(handle)
    assert err == skycoin.SKY_OK
    assert count == 0
    # Valid signing
    assert skycoin.SKY_coin_Transaction_HashInner(handle, h) == skycoin.SKY_OK
    secKeys = []
    secKeys.append(s)
    secKeys.append(s2)
    assert skycoin.SKY_coin_Transaction_SignInputs(
        handle, secKeys) == skycoin.SKY_OK
    err, count = skycoin.SKY_coin_Transaction_GetSignaturesCount(handle)
    assert err == skycoin.SKY_OK
    assert count == 2
    h2 = skycoin.cipher_SHA256()
    assert skycoin.SKY_coin_Transaction_HashInner(
        handle, h2) == skycoin.SKY_OK
    assert h == h2
    p = skycoin.cipher_PubKey()
    assert skycoin.SKY_cipher_PubKeyFromSecKey(s, p) == skycoin.SKY_OK
    a = skycoin.cipher__Address()
    a2 = skycoin.cipher__Address()
    assert skycoin.SKY_cipher_AddressFromPubKey(p, a) == skycoin.SKY_OK
    assert skycoin.SKY_cipher_PubKeyFromSecKey(s2, p) == skycoin.SKY_OK
    assert skycoin.SKY_cipher_AddressFromPubKey(p, a2) == skycoin.SKY_OK
    sha1 = skycoin.cipher_SHA256()
    sha2 = skycoin.cipher_SHA256()
    txin0 = skycoin.cipher_SHA256()
    txin1 = skycoin.cipher_SHA256()
    assert skycoin.SKY_coin_Transaction_GetInputAt(
        handle, 0, txin0) == skycoin.SKY_OK
    assert skycoin.SKY_coin_Transaction_GetInputAt(
        handle, 1, txin1) == skycoin.SKY_OK
    assert skycoin.SKY_cipher_AddSHA256(h, txin0, sha1) == skycoin.SKY_OK
    assert skycoin.SKY_cipher_AddSHA256(h, txin1, sha2) == skycoin.SKY_OK
    txsig0 = skycoin.cipher_Sig()
    txsig1 = skycoin.cipher_Sig()
    assert skycoin.SKY_coin_Transaction_GetSignatureAt(
        handle, 0, txsig0) == skycoin.SKY_OK
    assert skycoin.SKY_coin_Transaction_GetSignatureAt(
        handle, 1, txsig1) == skycoin.SKY_OK
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
Exemple #3
0
def test_TestBitcoinWIF():
    wips = [
        b"KwntMbt59tTsj8xqpqYqRRWufyjGunvhSyeMo3NTYpFYzZbXJ5Hp",
        b"L4ezQvyC6QoBhxB4GVs9fAPhUKtbaXYUn8YTqoeXwbevQq4U92vN",
        b"KydbzBtk6uc7M6dXwEgTEH2sphZxSPbmDSz6kUUHi4eUpSQuhEbq"
    ]

    publics = [
        b"034f355bdcb7cc0af728ef3cceb9615d90684bb5b2ca5f859ab0f0b704075871aa",
        b"02ed83704c95d829046f1ac27806211132102c34e9ac7ffa1b71110658e5b9d1bd",
        b"032596957532fc37e40486b910802ff45eeaa924548c0e1c080ef804e523ec3ed3"
    ]

    address = [
        b"1Q1pE5vPGEEMqRcVRMbtBK842Y6Pzo6nK9",
        b"1NKRhS7iYUGTaAfaR5z8BueAJesqaTyc4a",
        b"19ck9VKC6KjGxR9LJg4DNMRc45qFrJguvV"
    ]

    for p in range(len(wips)):
        secret_key = skycoin.cipher_SecKey()
        public_key = skycoin.cipher_PubKey()
        err = skycoin.skycoin.SKY_cipher_SecKeyFromBitcoinWalletImportFormat(
            wips[p], secret_key)
        assert err == skycoin.SKY_OK
        skycoin.SKY_cipher_PubKeyFromSecKey(secret_key, public_key)
        _, public_key_hex = skycoin.SKY_cipher_PubKey_Hex(public_key)
        assert public_key_hex == publics[p]
        bitcoin_addr = skycoin.cipher__BitcoinAddress()
        skycoin.SKY_cipher_BitcoinAddressFromPubKey(public_key, bitcoin_addr)
        bitcoin_addr_str = skycoin.skycoin.SKY_cipher_BitcoinAddress_String(
            bitcoin_addr)
        assert bitcoin_addr_str == address[p]
Exemple #4
0
def test_TestBitcoinAddress3():
    secret_key = skycoin.cipher_SecKey()
    err = skycoin.SKY_cipher_SecKeyFromHex(b'47f7616ea6f9b923076625b4488115de1ef1187f760e65f89eb6f4f7ff04b012', secret_key)
    assert err == skycoin.SKY_OK
    public_key = skycoin.cipher_PubKey()
    skycoin.SKY_cipher_PubKeyFromSecKey(secret_key, public_key)
    public_key_str = b'032596957532fc37e40486b910802ff45eeaa924548c0e1c080ef804e523ec3ed3'
    _, public_key_hex = skycoin.SKY_cipher_PubKey_Hex(public_key)
    assert public_key_hex == public_key_str
    bitcoin_srt = b'19ck9VKC6KjGxR9LJg4DNMRc45qFrJguvV'
    bitcoin_addr = skycoin.cipher__BitcoinAddress()
    skycoin.SKY_cipher_BitcoinAddressFromPubKey(public_key, bitcoin_addr)
    bitcoin_addr_str = skycoin.skycoin.SKY_cipher_BitcoinAddress_String(bitcoin_addr)
    assert bitcoin_srt == bitcoin_addr_str
Exemple #5
0
def test_TestBitcoinAddress2():
    secret_key = skycoin.cipher_SecKey()
    err = skycoin.SKY_cipher_SecKeyFromHex(b'dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd', secret_key)
    assert err == skycoin.SKY_OK
    public_key = skycoin.cipher_PubKey()
    skycoin.SKY_cipher_PubKeyFromSecKey(secret_key, public_key)
    public_key_str = b'02ed83704c95d829046f1ac27806211132102c34e9ac7ffa1b71110658e5b9d1bd'
    _, public_key_hex = skycoin.SKY_cipher_PubKey_Hex(public_key)
    assert public_key_hex == public_key_str
    bitcoin_srt = b'1NKRhS7iYUGTaAfaR5z8BueAJesqaTyc4a'
    bitcoin_addr = skycoin.cipher__BitcoinAddress()
    skycoin.SKY_cipher_BitcoinAddressFromPubKey(public_key, bitcoin_addr)
    bitcoin_addr_str = skycoin.skycoin.SKY_cipher_BitcoinAddress_String(bitcoin_addr)
    assert bitcoin_srt == bitcoin_addr_str
Exemple #6
0
def ValidateSeedData(SeedTestData=None, InputTestData=None):
    err, keys = skycoin.SKY_cipher_GenerateDeterministicKeyPairs(
        SeedTestData.Seed, len(SeedTestData.Keys))
    assert err == skycoin.SKY_OK
    if len(SeedTestData.Keys) != len(keys):
        return skycoin.SKY_ERROR
    for i, s in enumerate(keys):
        secret_Key_null = skycoin.cipher_SecKey()
        if s == secret_Key_null:
            return skycoin.SKY_ErrInvalidSecKey
        if (SeedTestData.Keys[i].Secret).decode() != binascii.hexlify(
                bytearray(s.toStr())).decode('ascii'):
            assert err == skycoin.SKY_ERROR
        p = skycoin.cipher_PubKey()
        p_null = skycoin.cipher_PubKey()
        err = skycoin.SKY_cipher_PubKeyFromSecKey(s, p)
        if p == p_null:
            return skycoin.SKY_ErrInvalidPubKey
        if (SeedTestData.Keys[i].Public).decode() != binascii.hexlify(
                bytearray(p.toStr())).decode('ascii'):
            return skycoin.SKY_ErrInvalidPubKey
        addr1 = skycoin.cipher__Address()
        addr_null = skycoin.cipher__Address()
        err = skycoin.SKY_cipher_AddressFromPubKey(p, addr1)
        assert err == skycoin.SKY_OK
        if addr1 == addr_null:
            return skycoin.SKY_ErrAddressInvalidPubKey
        if not (SeedTestData.Keys[i].Address == addr1):
            return skycoin.SKY_ErrAddressInvalidChecksum
        addr2 = skycoin.cipher__Address()
        err = skycoin.SKY_cipher_AddressFromSecKey(s, addr2)
        assert err == skycoin.SKY_OK
        if not (addr1 == addr2):
            return skycoin.SKY_ErrAddressInvalidChecksum

        if InputTestData == None and SeedTestData.Keys[i].Signatures != 0:
            return skycoin.SKY_ERROR

        if InputTestData != None:
            if len(SeedTestData.Keys[i].Signatures) != len(InputTestData):
                return skycoin.SKY_ERROR

            for j in range(len(InputTestData)):
                sig = SeedTestData.Keys[i].Signatures[j]
                sig_null = skycoin.cipher_Sig()
                if sig == sig_null:
                    return skycoin.SKY_ERROR

                err = skycoin.SKY_cipher_VerifySignedHash(
                    sig, InputTestData[j])
                if err != skycoin.SKY_OK:
                    return skycoin.SKY_ERROR

                p2 = skycoin.cipher_PubKey()
                err = skycoin.SKY_cipher_PubKeyFromSig(sig, InputTestData[j],
                                                       p2)
                if err != skycoin.SKY_OK:
                    return skycoin.SKY_ERROR
                if not (p == p2):
                    return 1
                    return skycoin.SKY_ERROR

                sig2 = skycoin.cipher_Sig()
                skycoin.SKY_cipher_SignHash(InputTestData[j], s, sig2)
                if sig2 == sig_null:
                    return skycoin.SKY_ERROR
    return skycoin.SKY_OK