Ejemplo n.º 1
0
def test_TestNewPubKey():
    public_key = skycoin.cipher_PubKey()
    _, data = skycoin.SKY_cipher_RandByte(31)
    assert skycoin.SKY_cipher_NewPubKey(
        data, public_key) == skycoin.SKY_ErrInvalidLengthPubKey
    _, data = skycoin.SKY_cipher_RandByte(32)
    assert skycoin.SKY_cipher_NewPubKey(
        data, public_key) == skycoin.SKY_ErrInvalidLengthPubKey
    _, data = skycoin.SKY_cipher_RandByte(34)
    assert skycoin.SKY_cipher_NewPubKey(
        data, public_key) == skycoin.SKY_ErrInvalidLengthPubKey
    _, data = skycoin.SKY_cipher_RandByte(0)
    assert skycoin.SKY_cipher_NewPubKey(
        data, public_key) == skycoin.SKY_ErrInvalidLengthPubKey
    _, data = skycoin.SKY_cipher_RandByte(100)
    assert skycoin.SKY_cipher_NewPubKey(
        data, public_key) == skycoin.SKY_ErrInvalidLengthPubKey
    _, data = skycoin.SKY_cipher_RandByte(33)
    assert skycoin.SKY_cipher_NewPubKey(
        data, public_key) == skycoin.SKY_ErrInvalidPubKey

    pubkey = skycoin.cipher_PubKey()
    seckey = skycoin.cipher_SecKey()
    err = skycoin.SKY_cipher_GenerateKeyPair(pubkey, seckey)
    assert err == skycoin.SKY_OK
    ptemp = pubkey.toStr()
    pubkey2 = skycoin.cipher_PubKey()
    err = skycoin.SKY_cipher_NewPubKey(ptemp, pubkey2)
    assert err == skycoin.SKY_OK
    assert pubkey == pubkey2
Ejemplo n.º 2
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
Ejemplo n.º 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]
Ejemplo n.º 4
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
Ejemplo n.º 5
0
def test_TestPubKeyFromHex():
    p1 = skycoin.cipher_PubKey()
    # Invalid hex
    err = skycoin.SKY_cipher_PubKeyFromHex(b"", p1)
    assert err == skycoin.SKY_ErrInvalidLengthPubKey
    err = skycoin.SKY_cipher_PubKeyFromHex(b"cascs", p1)
    assert err == skycoin.SKY_ErrInvalidPubKey
Ejemplo n.º 6
0
def test_TestAddressFromBytes():
    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)
    address_2 = skycoin.cipher__Address()
    _, byte = skycoin.SKY_cipher_Address_Bytes(address)
    err = skycoin.SKY_cipher_AddressFromBytes(byte, address_2)
    assert err == skycoin.SKY_OK
    assert address == address_2
    # Invalid number of bytes
    __ = skycoin.cipher__Address()
    err = skycoin.SKY_cipher_AddressFromBytes(byte[:len(byte) - 2], __)
    assert err == skycoin.SKY_ErrAddressInvalidLength
    # Invalid checksum
    byte_array = bytearray(byte)
    byte_array[-1] = 1
    byte_new = bytes(byte_array)
    err = skycoin.SKY_cipher_AddressFromBytes(byte_new, __)
    assert err == skycoin.SKY_ErrAddressInvalidChecksum
    address.Version = 2
    _, b = skycoin.SKY_cipher_Address_Bytes(address)
    err = skycoin.SKY_cipher_AddressFromBytes(b, __)
    assert err == skycoin.SKY_ErrAddressInvalidVersion
Ejemplo n.º 7
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
Ejemplo n.º 8
0
def test_TestPubKeyFromSig():
    public_key = skycoin.cipher_PubKey()
    secret_key = skycoin.cipher_SecKey()
    skycoin.SKY_cipher_GenerateKeyPair(public_key, secret_key)
    sha_sum = skycoin.cipher_SHA256()
    _, data = skycoin.SKY_cipher_RandByte(256)
    skycoin.SKY_cipher_SumSHA256(data, sha_sum)
    sig_1 = skycoin.cipher_Sig()
    skycoin.SKY_cipher_SignHash(sha_sum, secret_key, sig_1)
    public_key_2 = skycoin.cipher_PubKey()
    assert skycoin.SKY_cipher_PubKeyFromSig(sig_1, sha_sum,
                                            public_key_2) == skycoin.SKY_OK
    assert public_key == public_key_2
    sig_2 = skycoin.cipher_Sig()
    assert skycoin.SKY_cipher_PubKeyFromSig(
        sig_2, sha_sum,
        public_key_2) == skycoin.SKY_ErrInvalidSigPubKeyRecovery
Ejemplo n.º 9
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
Ejemplo n.º 10
0
def test_TestSecKeyTest():
    public_key = skycoin.cipher_PubKey()
    secret_key = skycoin.cipher_SecKey()
    secret_key_2 = skycoin.cipher_SecKey()
    skycoin.SKY_cipher_GenerateKeyPair(public_key, secret_key)
    value = skycoin.skycoin.SKY_cipher_CheckSecKey(secret_key)
    assert value == skycoin.SKY_OK
    value = skycoin.skycoin.SKY_cipher_CheckSecKey(secret_key_2)
    assert value == skycoin.SKY_ErrInvalidSecKyVerification
Ejemplo n.º 11
0
def create_wallet():
    """
    Create the wallet in blockchain
    """

    # generate CSRF token
    CSRF_token = app.lykke_session.get(
        form_url(app_config.SKYCOIN_NODE_URL, "/api/v1/csrf")).json()

    if not CSRF_token or "csrf_token" not in CSRF_token:
        return {"status": 500, "error": "Unknown server error"}

    # generate new seed
    new_seed = app.lykke_session.get(form_url(
        app_config.SKYCOIN_NODE_URL, "/api/v1/wallet/newSeed?entropy=128"),
                                     headers={
                                         'X-CSRF-Token':
                                         CSRF_token['csrf_token']
                                     }).json()

    if not new_seed or "seed" not in new_seed:
        return {"status": 500, "error": "Unknown server error"}

    # create the wallet from seed
    resp = app.lykke_session.post(
        form_url(app_config.SKYCOIN_NODE_URL, "/api/v1/wallet/create"), {
            "seed": new_seed["seed"],
            "label": "wallet123",
            "scan": "5"
        },
        headers={'X-CSRF-Token': CSRF_token['csrf_token']})

    if not resp:
        return {"status": 500, "error": "Unknown server error"}

    if resp.status_code != 200:
        return {"status": 500, "error": "Unknown server error"}

    new_wallet = resp.json()

    if not new_wallet or "entries" not in new_wallet:
        return {"status": 500, "error": "Unknown server error"}

    seed = new_seed['seed']
    pubkey = skycoin.cipher_PubKey()
    seckey = skycoin.cipher_SecKey()
    error = skycoin.SKY_cipher_GenerateDeterministicKeyPair(
        seed.encode(), pubkey, seckey)
    if error != 0:
        return {"status": 500, "error": "Unknown server error"}

    return {
        "privateKey":
        binascii.hexlify(bytearray(seckey.toStr())).decode('ascii'),
        "publicAddress": new_wallet["entries"][0]["address"],
        "addressContext": new_wallet['meta']['filename']
    }
Ejemplo n.º 12
0
def makeKeysAndAddress():
    ppubkey = skycoin.cipher_PubKey()
    pseckey = skycoin.cipher_SecKey()
    err = skycoin.SKY_cipher_GenerateKeyPair(ppubkey, pseckey)
    assert err == skycoin.SKY_OK
    paddress = skycoin.cipher__Address()
    err = skycoin.SKY_cipher_AddressFromPubKey(ppubkey, paddress)
    assert err == skycoin.SKY_OK
    return err, ppubkey, pseckey, paddress
Ejemplo n.º 13
0
def test_TestAddressNull():
    address = skycoin.cipher__Address()
    _error, isNull = skycoin.SKY_cipher_Address_Null(address)
    assert _error == skycoin.SKY_OK
    assert isNull == 1
    public_key = skycoin.cipher_PubKey()
    secret_key = skycoin.cipher_SecKey()
    skycoin.SKY_cipher_GenerateKeyPair(public_key, secret_key)
    skycoin.SKY_cipher_AddressFromPubKey(public_key, address)
    assert address is not None
Ejemplo n.º 14
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
Ejemplo n.º 15
0
def test_TestAddressVerify():
    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)
    # Valid pubkey+address
    err = skycoin.SKY_cipher_Address_Verify(address, public_key)
    assert err == skycoin.SKY_OK
    # Invalid pubkey
    public_key_temp = skycoin.cipher_PubKey()
    err = skycoin.SKY_cipher_Address_Verify(address, public_key_temp)
    assert err == skycoin.SKY_ErrAddressInvalidPubKey
    skycoin.SKY_cipher_GenerateKeyPair(public_key_temp, secret_key)
    err = skycoin.SKY_cipher_Address_Verify(address, public_key_temp)
    assert err == skycoin.SKY_ErrAddressInvalidPubKey
    #  Bad version
    address.Version = 0x01
    err = skycoin.SKY_cipher_Address_Verify(address, public_key)
    assert err == skycoin.SKY_ErrAddressInvalidVersion
Ejemplo n.º 16
0
def test_TestPubKeyVerify():
    # Random bytes should not be valid, most of the time
    failed = False
    for _ in range(10):
        public_key = skycoin.cipher_PubKey()
        _, data = skycoin.SKY_cipher_RandByte(33)
        skycoin.SKY_cipher_NewPubKey(data, public_key)
        if skycoin.SKY_cipher_PubKey_Verify(public_key) is not None:
            failed = True
            break
    assert failed is True
Ejemplo n.º 17
0
def test_TestPubKeyHex():
    p, sk = utils.makecipher_PubKeyAndcipher_SecKey()
    err, s3 = skycoin.SKY_cipher_PubKey_Hex(p)
    assert err == skycoin.SKY_OK
    p2 = skycoin.cipher_PubKey()
    err = skycoin.SKY_cipher_PubKeyFromHex(s3, p2)
    assert err == skycoin.SKY_OK
    assert p == p2
    err, s4 = skycoin.SKY_cipher_PubKey_Hex(p2)
    assert err == skycoin.SKY_OK
    assert s3 == s4
Ejemplo n.º 18
0
def test_TestSecKeyHashTest():
    public_key = skycoin.cipher_PubKey()
    secret_key = skycoin.cipher_SecKey()
    secret_key_2 = skycoin.cipher_SecKey()
    skycoin.SKY_cipher_GenerateKeyPair(public_key, secret_key)
    sha_sum_1 = skycoin.cipher_SHA256()
    _, data = skycoin.SKY_cipher_RandByte(256)
    skycoin.SKY_cipher_SumSHA256(data, sha_sum_1)
    value = skycoin.skycoin.SKY_cipher_CheckSecKeyHash(secret_key, sha_sum_1)
    assert value == skycoin.SKY_OK
    value = skycoin.skycoin.SKY_cipher_CheckSecKeyHash(secret_key_2, sha_sum_1)
    assert value == skycoin.SKY_ErrInvalidSecKyVerification
Ejemplo n.º 19
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
Ejemplo n.º 20
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
Ejemplo n.º 21
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
Ejemplo n.º 22
0
def test_TestAddressRoundtrip():
    public_key = skycoin.cipher_PubKey()
    secret_key = skycoin.cipher_SecKey()
    skycoin.SKY_cipher_GenerateKeyPair(public_key, secret_key)
    address = skycoin.cipher__Address()
    address_2 = skycoin.cipher__Address()
    skycoin.SKY_cipher_AddressFromPubKey(public_key, address)
    _, byte = skycoin.skycoin.SKY_cipher_Address_Bytes(address)
    err = skycoin.skycoin.SKY_cipher_AddressFromBytes(byte, address_2)
    assert err == skycoin.SKY_OK
    assert address == address_2
    _, addres_str = skycoin.SKY_cipher_Address_String(address)
    _, addres_2_str = skycoin.SKY_cipher_Address_String(address_2)
    assert addres_2_str == addres_str
Ejemplo n.º 23
0
def test_TestGenerateDeterministicKeyPair():
    # deterministic key pairs are useless as is because we can't
    # generate pair n+1, only pair 0
    public_key = skycoin.cipher_PubKey()
    secret_key = skycoin.cipher_SecKey()
    _, seed = skycoin.SKY_cipher_RandByte(32)
    skycoin.SKY_cipher_GenerateDeterministicKeyPair(seed, public_key,
                                                    secret_key)
    assert skycoin.SKY_cipher_PubKey_Verify(public_key) == skycoin.SKY_OK
    assert skycoin.SKY_cipher_SecKey_Verify(secret_key) == skycoin.SKY_OK
    skycoin.SKY_cipher_GenerateDeterministicKeyPair(seed, public_key,
                                                    secret_key)
    assert skycoin.SKY_cipher_PubKey_Verify(public_key) == skycoin.SKY_OK
    assert skycoin.SKY_cipher_SecKey_Verify(secret_key) == skycoin.SKY_OK
Ejemplo n.º 24
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
Ejemplo n.º 25
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
Ejemplo n.º 26
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
Ejemplo n.º 27
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
Ejemplo n.º 28
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
Ejemplo n.º 29
0
def makeUxBodyWithSecret():
    p = skycoin.cipher_PubKey()
    s = skycoin.cipher_SecKey()
    assert skycoin.SKY_cipher_GenerateKeyPair(p, s) == skycoin.SKY_OK
    uxb = skycoin.coin__UxBody()
    err, b = skycoin.SKY_cipher_RandByte(128)
    assert err == skycoin.SKY_OK
    h = skycoin.cipher_SHA256()
    assert skycoin.SKY_cipher_SumSHA256(b, h) == skycoin.SKY_OK
    assert h.assignTo(uxb.SrcTransaction) == None
    a = skycoin.cipher__Address()
    assert skycoin.SKY_cipher_AddressFromPubKey(p, a) == skycoin.SKY_OK
    uxb.Address = a
    uxb.Coins = int(1e6)
    uxb.Hours = int(100)
    return uxb, s
Ejemplo n.º 30
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