def test_TestSecKeyFromHex(): sk = skycoin.cipher_SecKey() # Invalid hex err = skycoin.SKY_cipher_SecKeyFromHex(b"", sk) assert err == skycoin.SKY_ErrInvalidLengthSecKey err = skycoin.SKY_cipher_SecKeyFromHex(b"cascs", sk) assert err == skycoin.SKY_ErrInvalidSecKey # INvalid hex length err, b = skycoin.SKY_cipher_RandByte(32) p = skycoin.cipher_SecKey() err = skycoin.SKY_cipher_NewSecKey(b, p) assert err == skycoin.SKY_OK
def sign_hash(hashHex, seckeyHex): seckey = skycoin.cipher_Sig() error = skycoin.SKY_cipher_SecKeyFromHex(seckeyHex.encode(), seckey) if error != 0: return make_response( jsonify(build_error('Invalid Input Format', error_codes.badFormat)), 400) sha256 = skycoin.cipher_SHA256() error = skycoin.SKY_cipher_SHA256FromHex(hashHex.encode(), sha256) if error != 0: return make_response( jsonify(build_error('Invalid Input Format', error_codes.badFormat)), 400) signedHash = skycoin.cipher__Sig() error = skycoin.SKY_cipher_SignHash(hash, seckey, signedHash) if error != 0: return make_response( jsonify(build_error('Unknown Server Error', error_codes.unknown)), 500) error, signedHashHex = SKY_cipher_Sig_Hex(signedHash) if error != 0: return make_response( jsonify(build_error('Unknown Server Error', error_codes.unknown)), 500) retvalue = {"signedTransaction": signedHashHex} return jsonify(retvalue)
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
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