def test_create_identity_from_prikey(self):
     wm = WalletManager()
     wm.open_wallet("./test6.json")
     ide = wm.create_identity_from_prikey(
         "ide", "1",
         util.hex_to_bytes(
             "75de8489fcb2dcaf2ef3cd607feffde18789de7da129b5e97c81e001793cb7cf"
         ))
     print(ide)
 def test_create_account_from_prikey(self):
     wm = WalletManager()
     wm.open_wallet("/Users/zhaoxavi/test.txt")
     account = wm.create_account_from_prikey(
         "myaccount", "1",
         util.hex_to_bytes(
             "75de8489fcb2dcaf2ef3cd607feffde18789de7da129b5e97c81e001793cb7cf"
         ))
     wm.save()
     print(account)
Beispiel #3
0
 def test_export_gcm_encrypted_private_key(self):
     private_key = "75de8489fcb2dcaf2ef3cd607feffde18789de7da129b5e97c81e001793cb7cf"
     account = Account(util.hex_to_bytes(private_key),
                       SignatureScheme.SHA256withECDSA)
     salt = util.get_random_bytes(16)
     enc_private_key = account.export_gcm_encrypted_private_key("1", salt, 16384)
     import_private_key = account.get_gcm_decoded_private_key(enc_private_key, "1", account.get_address_base58(),
                                                              salt,
                                                              16384,
                                                              SignatureScheme.SHA256withECDSA)
     self.assertEqual(import_private_key.hex(), private_key)
Beispiel #4
0
 def test_serialize_private_key(self):
     hex_private_key = "523c5fcf74823831756f0bcb3634234f10b3beb1c05595058534577752ad2d9f"
     hex_public_key = "03036c12be3726eb283d078dff481175e96224f0b0c632c7a37e10eb40fe6be889"
     base58_addr = "ANH5bHrrt111XwNEnuPZj6u95Dd6u7G4D6"
     wif = b'KyyZpJYXRfW8CXxH2B6FRq5AJsyTH7PjPACgBht4xRjstz4mxkeJ'
     account = Account(util.hex_to_bytes(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)
Beispiel #5
0
    def test_export_identity_qrcode(self):
        wm = WalletManager()
        pwd = "1"
        identity = wm.create_identity_from_prikey("sss", pwd, util.hex_to_bytes("75de8489fcb2dcaf2ef3cd607feffde18789de7da129b5e97c81e001793cb7cf"))
        # account = wm.create_random_account("sss2", pwd)
        wqr = WalletQR()
        d = wqr.export_identity_qrcode(wm.wallet_file, identity)

        dstr = json.dumps(d, default=lambda obj: obj.__dict__, sort_keys=True, indent=4)

        privatekey = wqr.get_prikey_from_qrcode(dstr, pwd)
        print(privatekey.hex())
Beispiel #6
0
    def test_deserialize_from(self):
        tx_hex = "00d14b09645bf401000000000000204e0000000000004756c9dd829b2142883adbe1ae4f8689a1f673e97100c66b14dfa5e7" \
                 "b46640490f7fd2fcd82fe986e7e3f14a696a7cc814d2c124dd088190f709b684e0bc676d70c41b37766a7cc8516a7cc86c51" \
                 "c1087472616e736665721400000000000000000000000000000000000000010068164f6e746f6c6f67792e4e61746976652e" \
                 "496e766f6b65000242410113141b59b1a62dc3837da026bbd8d541529632377ab7749d4150b71b97ea39798220f15fa039d8" \
                 "521608a6db5ef582cbc6b007106ae86d30344986adb906af7d232103036c12be3726eb283d078dff481175e96224f0b0c632" \
                 "c7a37e10eb40fe6be889ac844101ceda8a7a51cf2ee0094f25bf422b12c0be0e40d6c27d4ef8d9d7fb853645881b9b9dfa20" \
                 "f377bcd2139e36f654812fdc15f8c98bd163548a04322e59ff52a9ff410186372e64013a6455c06f4aa65b5301c85c68fe77" \
                 "df8e6a5096041aa2baa7ff6bf99be09811ce5855ca11cc750c8ee561361a28ca9a41acbaa042d93c2a62f39769522103036c" \
                 "12be3726eb283d078dff481175e96224f0b0c632c7a37e10eb40fe6be88921020f9ce29ede5f0e271b67e61b2480dccc98c3" \
                 "aabad095c604ef9ab1d92a475c0a21035384561673e76c7e3003e705e4aa7aee67714c8b68d62dd1fb3221f48c5d3da053ae"

        tx = Transaction.deserialize_from(util.hex_to_bytes(tx_hex))
        self.assertGreaterEqual(tx.gas_limit, 0)
        self.assertGreaterEqual(tx.gas_price, 0)
        self.assertGreaterEqual(tx.nonce, 0)
Beispiel #7
0
 def test_generate_signature(self):
     raw_hex_data = "523c5fcf74823831756f0bcb3634234f10b3beb1c05595058534577752ad2d9f"
     account = Account(util.hex_to_bytes(raw_hex_data),
                       SignatureScheme.SHA256withECDSA)
     data = account.generate_signature(bytes("test".encode()), SignatureScheme.SHA256withECDSA)
Beispiel #8
0
def address_from_hex_string(s: str) -> bytearray:
    hx = util.hex_to_bytes(s)
    return address_parse_from_bytes(util.to_array_reverse(hx))