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
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
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