def test_serialize_private_key(self): hex_private_key = "523c5fcf74823831756f0bcb3634234f10b3beb1c05595058534577752ad2d9f" hex_public_key = "03036c12be3726eb283d078dff481175e96224f0b0c632c7a37e10eb40fe6be889" base58_addr = "ANH5bHrrt111XwNEnuPZj6u95Dd6u7G4D6" wif = b'KyyZpJYXRfW8CXxH2B6FRq5AJsyTH7PjPACgBht4xRjstz4mxkeJ' account = Account(hex_private_key, SignatureScheme.SHA256withECDSA) hex_serialize_private_key = account.serialize_private_key().hex() self.assertEqual(hex_private_key, hex_serialize_private_key) self.assertEqual(account.serialize_public_key().hex(), hex_public_key) self.assertEqual(account.export_wif(), wif) self.assertEqual(account.get_address_base58(), base58_addr)
import base64 import unittest from ontology.utils import util from ontology.account.account import Account from ontology.wallet.wallet import WalletData from ontology.wallet.account import AccountData from ontology.crypto.signature_scheme import SignatureScheme from ontology.common.address import Address private_key = "8b6bb2bebb27f3e2c24cc8a3febb413c1ef98bd2481e2292ada6d90f9a5f5ec9" if __name__ == '__main__': account = Account(private_key) publickey = account.serialize_public_key() wif = account.export_wif() privatekey = account.get_privatekey_from_wif(wif) print("public key is ", publickey, type(publickey)) print("private key is ", privatekey) print("...", account.serialize_private_key()) address = Address(publickey) addr = address.b58decode() print("address is ", addr)
def test_export_wif(self): private_key = '523c5fcf74823831756f0bcb3634234f10b3beb1c05595058534577752ad2d9f' account = Account(private_key, SignatureScheme.SHA256withECDSA) wif = 'KyyZpJYXRfW8CXxH2B6FRq5AJsyTH7PjPACgBht4xRjstz4mxkeJ' self.assertEqual(wif, account.export_wif())
def test_get_private_key_from_wif(self): hex_private_key = utils.get_random_bytes(32).hex() acct = Account(hex_private_key) wif = acct.export_wif() import_key = Account.get_private_key_from_wif(wif) self.assertEqual(hex_private_key, import_key.hex())