def test_btsprivkey(self): self.assertEqual([ format( PrivateKey( "5HqUkGuo62BfcJU5vNhTXKJRXuUi9QSE6jp8C3uBJ2BVHtB8WSd"). address, "ONE"), format( PrivateKey( "5JWcdkhL3w4RkVPcZMdJsjos22yB5cSkPExerktvKnRNZR5gx1S"). address, "ONE"), format( PrivateKey( "5HvVz6XMx84aC5KaaBbwYrRLvWE46cH6zVnv4827SBPLorg76oq"). address, "ONE"), format( PrivateKey( "5Jete5oFNjjk3aUMkKuxgAXsp7ZyhgJbYNiNjHLvq5xzXkiqw7R"). address, "ONE"), format( PrivateKey( "5KDT58ksNsVKjYShG4Ls5ZtredybSxzmKec8juj7CojZj6LPRF7"). address, "ONE") ], [ "ONEFN9r6VYzBK8EKtMewfNbfiGCr56pHDBFi", "ONEdXrrTXimLb6TEt3nHnePwFmBT6Cck112", "ONEJQUAt4gz4civ8gSs5srTK4r82F7HvpChk", "ONEFPXXHXXGbyTBwdKoJaAPXRnhFNtTRS4EL", "ONE3qXyZnjJneeAddgNDYNYXbF7ARZrRv5dr", ])
def test_loading_encrypted_key(self): PrivateKey( "42c08720c6d0ce2ab2d7c7398d9e2aad3724dbe3588008676081a15d62e0bcb8") with self.assertRaises(Exception): PrivateKey( '6PRQdSDAjq41FVc58T1gykbihNPQeUCMWj8KW9uoeDKd1ZdZ6MbShYPhvS')
def test_btcprivkey(self): self.assertEqual([format(PrivateKey("5HvVz6XMx84aC5KaaBbwYrRLvWE46cH6zVnv4827SBPLorg76oq").bitcoin.address, "BTC"), format(PrivateKey("5Jete5oFNjjk3aUMkKuxgAXsp7ZyhgJbYNiNjHLvq5xzXkiqw7R").bitcoin.address, "BTC"), format(PrivateKey("5KDT58ksNsVKjYShG4Ls5ZtredybSxzmKec8juj7CojZj6LPRF7").bitcoin.address, "BTC"), ], ["1G7qw8FiVfHEFrSt3tDi6YgfAdrDrEM44Z", "12c7KAAZfpREaQZuvjC5EhpoN6si9vekqK", "1Gu5191CVHmaoU3Zz3prept87jjnpFDrXL", ])
def test_btsprivkey(self): self.assertEqual([format(PrivateKey("5HqUkGuo62BfcJU5vNhTXKJRXuUi9QSE6jp8C3uBJ2BVHtB8WSd").address, "BTS"), format(PrivateKey("5JWcdkhL3w4RkVPcZMdJsjos22yB5cSkPExerktvKnRNZR5gx1S").address, "BTS"), format(PrivateKey("5HvVz6XMx84aC5KaaBbwYrRLvWE46cH6zVnv4827SBPLorg76oq").address, "BTS"), format(PrivateKey("5Jete5oFNjjk3aUMkKuxgAXsp7ZyhgJbYNiNjHLvq5xzXkiqw7R").address, "BTS"), format(PrivateKey("5KDT58ksNsVKjYShG4Ls5ZtredybSxzmKec8juj7CojZj6LPRF7").address, "BTS") ], [ 'BTSGu2U7Q3rmkCUCkQH2SToLMjEVUr86GrpA', 'BTS9YgTfC8EfkgDG7DoRXJpMVKRougo64Lop', 'BTSBXqRucGm7nRkk6jm7BNspTJTWRtNcx7k5', 'BTS5tTDDR6M3mkcyVv16edsw8dGUyNQZrvKU', 'BTS8G9ATJbJewVjTgTGmLGLNe1uP5XDWzaKX'])
def test_memo(self): from_priv = "5KNK3bejeP3PtQ1Q9EagBmGacYFCZ3qigRAZDbfqcdjDWWmZSMm" to_priv = "5K2JRPe1iRwD2He5DyDRtHs3Z1wpom3YXguFxEd57kNTHhQuZ2k" for msg in [ "foobar", "just a donation", "1124safafASFasc", ]: nonce = str(random.getrandbits(64)) memo = Memo.encode_memo(PrivateKey(from_priv), PrivateKey(to_priv).pubkey, nonce, msg) plain = Memo.decode_memo(PrivateKey(to_priv), memo) self.assertEqual(msg, plain)
def test_call_update(self): s = { 'fee': { 'amount': 100, 'asset_id': '1.3.0' }, 'delta_debt': { 'amount': 10000, 'asset_id': '1.3.22' }, 'delta_collateral': { 'amount': 100000000, 'asset_id': '1.3.0' }, 'funding_account': '1.2.29', 'extensions': [] } ops = [transactions.Operation(transactions.Call_order_update(**s))] tx = transactions.Signed_Transaction(ref_block_num=ref_block_num, ref_block_prefix=ref_block_prefix, expiration=expiration, operations=ops) tx = tx.sign([wif], chain=prefix) tx.verify([PrivateKey(wif).pubkey], "BTS") txWire = hexlify(bytes(tx)).decode("ascii") compare = "f68585abf4dce7c8045701036400000000000000001d00e1f50500000000001027000000000000160000011f2627efb5c5144440e06ff567f1a09928d699ac6f5122653cd7173362a1ae20205952c874ed14ccec050be1c86c1a300811763ef3b481e562e0933c09b40e31fb" self.assertEqual(compare[:-130], txWire[:-130])
def test_limit_order_create(self): s = { "fee": { "amount": 100, "asset_id": "1.3.0" }, "seller": "1.2.29", "amount_to_sell": { "amount": 100000, "asset_id": "1.3.0" }, "min_to_receive": { "amount": 10000, "asset_id": "1.3.105" }, "expiration": "2016-05-18T09:22:05", "fill_or_kill": False, "extensions": [] } ops = [transactions.Operation(transactions.Limit_order_create(**s))] tx = transactions.Signed_Transaction(ref_block_num=ref_block_num, ref_block_prefix=ref_block_prefix, expiration=expiration, operations=ops) tx = tx.sign([wif], chain=prefix) tx.verify([PrivateKey(wif).pubkey], "BTS") txWire = hexlify(bytes(tx)).decode("ascii") compare = "f68585abf4dce7c8045701016400000000000000001da086010000000000001027000000000000693d343c57000000011f75cbfd49ae8d9b04af76cc0a7de8b6e30b71167db7fe8e2197ef9d858df1877043493bc24ffdaaffe592357831c978fd8a296b913979f106debe940d60d77b50" self.assertEqual(compare[:-130], txWire[:-130])
def test_override_transfer(self): s = { "fee": { "amount": 0, "asset_id": "1.3.0" }, "issuer": "1.2.29", "from": "1.2.104", "to": "1.2.29", "amount": { "amount": 100000, "asset_id": "1.3.105" }, "extensions": [] } op = transactions.Override_transfer(**s) ops = [transactions.Operation(op)] tx = transactions.Signed_Transaction(ref_block_num=ref_block_num, ref_block_prefix=ref_block_prefix, expiration=expiration, operations=ops) tx = tx.sign([wif], chain=prefix) tx.verify([PrivateKey(wif).pubkey], "BTS") txWire = hexlify(bytes(tx)).decode("ascii") compare = "f68585abf4dce7c8045701260000000000000000001d681da08601000000000069000000012030cc81722c3e67442d2f59deba188f6079c8ba2d8318a642e6a70a125655515f20e2bd3adb2ea886cdbc7f6590c7f8c80818d9176d9085c176c736686ab6c9fd" self.assertEqual(compare[:-130], txWire[:-130])
def compareNewWire(self): # def test_online(self): # self.maxDiff = None from grapheneapi.grapheneapi import GrapheneAPI rpc = GrapheneAPI("localhost", 8092) tx = rpc.create_account("xeroc", "fsafaasf", "", False) pprint(tx) compare = rpc.serialize_transaction(tx) ref_block_num = tx["ref_block_num"] ref_block_prefix = tx["ref_block_prefix"] expiration = tx["expiration"] ops = [ transactions.Operation( transactions.Account_create(**tx["operations"][0][1])) ] tx = transactions.Signed_Transaction(ref_block_num=ref_block_num, ref_block_prefix=ref_block_prefix, expiration=expiration, operations=ops) tx = tx.sign([wif], chain=prefix) tx.verify([PrivateKey(wif).pubkey], "BTS") txWire = hexlify(bytes(tx)).decode("ascii") print("\n") print(txWire[:-130]) print(compare[:-130])
def getPublicKeys(self): pub = [] for key in self.keys: try: pub.append(format(PrivateKey(key).pubkey, "BTS")) except: continue return pub
def login(self, account, wifkey): try: self.wif = wifkey pKey = PrivateKey(wifkey) except: raise InvalidWifKey p = bytes(pKey) pub_key = format(pKey.pubkey, 'BTS') auth_data = { "account": account, "site": 'btsbots.com', "time": time.time() } message = json.dumps(auth_data, sort_keys=True).encode('utf-8') digest = hashlib.sha256(message).digest() i = 0 ndata = secp256k1.ffi.new("const int *ndata") ndata[0] = 0 while True: ndata[0] += 1 privkey = secp256k1.PrivateKey(p, raw=True) sig = secp256k1.ffi.new('secp256k1_ecdsa_recoverable_signature *') signed = secp256k1.lib.secp256k1_ecdsa_sign_recoverable( privkey.ctx, sig, digest, privkey.private_key, secp256k1.ffi.NULL, ndata) assert signed == 1 signature, i = privkey.ecdsa_recoverable_serialize(sig) if _is_canonical(signature): i += 4 # compressed i += 27 # compact break # pack signature # sigstr = struct.pack("<B", i) sigstr += signature login_data = { "user": account, "pubkey": pub_key, "verify": { "data": json.dumps(auth_data, sort_keys=True), "signature": hexlify(sigstr).decode('ascii') } } def logged_in(error, data): if error: print(error) # raise LoginFailed else: self.account = account self.ddp_client.subscribe('price') self.ddp_client.subscribe('login_order', params=[account]) self.ddp_client.subscribe('login_balance', params=[account]) self.ddp_client._login(login_data, logged_in)
def addPrivateKey(self, wif): try: pub = format(PrivateKey(wif).pubkey, "BTS") except: print("Invalid Private Key Format. Please use WIF!") return self.keys.append(wif) self.keys = list(set(self.keys)) self._storeWallet() return pub
def test_Adress(self): address1 = format(PrivateKey("5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3").address, "ONE") address2 = format(PublicKey("ONE6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", prefix="ONE").address, "ONE") tempAddress = format(Address("BTSFN9r6VYzBK8EKtMewfNbfiGCr56pHDBFi", prefix="BTS"), "BTS") tempAddress = format(Address("ONEFAbAx7yuxt725qSZvfwWqkdCwp9ZnUama", prefix="ONE"), "ONE") result = address2 == tempAddress ret = 0
def test_Privatekey(self): self.assertEqual([ str( PrivateKey( "5HvVz6XMx84aC5KaaBbwYrRLvWE46cH6zVnv4827SBPLorg76oq")), str( PrivateKey( "5Jete5oFNjjk3aUMkKuxgAXsp7ZyhgJbYNiNjHLvq5xzXkiqw7R")), str( PrivateKey( "5KDT58ksNsVKjYShG4Ls5ZtredybSxzmKec8juj7CojZj6LPRF7")), repr( PrivateKey( "5HvVz6XMx84aC5KaaBbwYrRLvWE46cH6zVnv4827SBPLorg76oq")), repr( PrivateKey( "5Jete5oFNjjk3aUMkKuxgAXsp7ZyhgJbYNiNjHLvq5xzXkiqw7R")), repr( PrivateKey( "5KDT58ksNsVKjYShG4Ls5ZtredybSxzmKec8juj7CojZj6LPRF7")), ], [ "5HvVz6XMx84aC5KaaBbwYrRLvWE46cH6zVnv4827SBPLorg76oq", "5Jete5oFNjjk3aUMkKuxgAXsp7ZyhgJbYNiNjHLvq5xzXkiqw7R", "5KDT58ksNsVKjYShG4Ls5ZtredybSxzmKec8juj7CojZj6LPRF7", '0e1bfc9024d1f55a7855dc690e45b2e089d2d825a4671a3c3c7e4ea4e74ec00e', '6e5cc4653d46e690c709ed9e0570a2c75a286ad7c1bc69a648aae6855d919d3e', 'b84abd64d66ee1dd614230ebbe9d9c6d66d78d93927c395196666762e9ad69d8' ])
def test_encrypt(self): self.assertEqual([ format( encrypt( PrivateKey( "5HqUkGuo62BfcJU5vNhTXKJRXuUi9QSE6jp8C3uBJ2BVHtB8WSd"), "TestingOneTwoThree"), "encwif"), format( encrypt( PrivateKey( "5KN7MzqK5wt2TP1fQCYyHBtDrXdJuXbUzm4A9rKAteGu3Qi5CVR"), "TestingOneTwoThree"), "encwif"), format( encrypt( PrivateKey( "5HtasZ6ofTHP6HCwTqTkLDuLQisYPah7aUnSKfC7h4hMUVw2gi5"), "Satoshi"), "encwif") ], [ "6PRN5mjUTtud6fUXbJXezfn6oABoSr6GSLjMbrGXRZxSUcxThxsUW8epQi", "6PRVWUbkzzsbcVac2qwfssoUJAN1Xhrg6bNk8J7Nzm5H7kxEbn2Nh2ZoGg", "6PRNFFkZc2NZ6dJqFfhRoFNMR9Lnyj7dYGrzdgXXVMXcxoKTePPX1dWByq" ])
def test_create_account(self): s = { "fee": { "amount": 1467634, "asset_id": "1.3.0" }, "registrar": "1.2.33", "referrer": "1.2.27", "referrer_percent": 3, "name": "foobar-f124", "owner": { "weight_threshold": 1, "account_auths": [], 'key_auths': [['BTS6pbVDAjRFiw6fkiKYCrkz7PFeL7XNAfefrsREwg8MKpJ9VYV9x', 1], ['BTS6zLNtyFVToBsBZDsgMhgjpwysYVbsQD6YhP3kRkQhANUB4w7Qp', 1]], "address_auths": [] }, "active": { "weight_threshold": 1, "account_auths": [], 'key_auths': [['BTS6pbVDAjRFiw6fkiKYCrkz7PFeL7XNAfefrsREwg8MKpJ9VYV9x', 1], ['BTS6zLNtyFVToBsBZDsgMhgjpwysYVbsQD6YhP3kRkQhANUB4w7Qp', 1], ['BTS8CemMDjdUWSV5wKotEimhK6c4dY7p2PdzC2qM1HpAP8aLtZfE7', 1]], "address_auths": [] }, "options": { "memo_key": "BTS5TPTziKkLexhVKsQKtSpo4bAv5RnB8oXcG4sMHEwCcTf3r7dqE", "voting_account": "1.2.5", "num_witness": 0, "num_committee": 0, "votes": [], "extensions": [] }, "extensions": {} } op = transactions.Account_create(**s) ops = [transactions.Operation(op)] tx = transactions.Signed_Transaction(ref_block_num=ref_block_num, ref_block_prefix=ref_block_prefix, expiration=expiration, operations=ops) tx = tx.sign([wif], chain=prefix) tx.verify([PrivateKey(wif).pubkey], "BTS") txWire = hexlify(bytes(tx)).decode("ascii") compare = "f68585abf4dce7c804570105f26416000000000000211b03000b666f6f6261722d6631323401000000000202fe8cc11cc8251de6977636b55c1ab8a9d12b0b26154ac78e56e7c4257d8bcf6901000314aa202c9158990b3ec51a1aa49b2ab5d300c97b391df3beb34bb74f3c62699e01000001000000000303b453f46013fdbccb90b09ba169c388c34d84454a3b9fbec68d5a7819a734fca0010002fe8cc11cc8251de6977636b55c1ab8a9d12b0b26154ac78e56e7c4257d8bcf6901000314aa202c9158990b3ec51a1aa49b2ab5d300c97b391df3beb34bb74f3c62699e010000024ab336b4b14ba6d881675d1c782912783c43dbbe31693aa710ac1896bd7c3d61050000000000000000011f61ad276120bc3f1892962bfff7db5e8ce04d5adec9309c80529e3a978a4fa1073225a6d56929e34c9d2a563e67a8f4a227e4fadb4a3bb6ec91bfdf4e57b80efd" self.assertEqual(compare[:-130], txWire[:-130])
def get_keys(self, account, password): keys = {"login": account, "password": password, "private": {}, "public": {}} for role in self.roles: b = bytes(account + role + password, 'utf8') s = hashlib.sha256(b).digest() k = hexlify(s).decode('ascii') #b58 = Base58(k) #wif = format(b58, "WIF") #print(role, wif) pk = PrivateKey(wif = k, prefix = self.prefix) keys["private"][role] = str(pk) keys["public"][role] = str(pk.pubkey) return(keys)
def test_proposal_update(self): s = { 'fee_paying_account': "1.2.1", 'proposal': "1.10.90", 'active_approvals_to_add': ["1.2.5"], "fee": transactions.Asset(amount=12512, asset_id="1.3.0"), } op = transactions.Proposal_update(**s) ops = [transactions.Operation(op)] tx = transactions.Signed_Transaction(ref_block_num=ref_block_num, ref_block_prefix=ref_block_prefix, expiration=expiration, operations=ops) tx = tx.sign([wif], chain=prefix) tx.verify([PrivateKey(wif).pubkey], "BTS") txWire = hexlify(bytes(tx)).decode("ascii") compare = "f68585abf4dce7c804570117e03000000000000000015a01050000000000000001203255378db6dc19443e74421c954ad7fdcf23f4ea45fe4fe5a1b078a0f94fb529594819c9799d68efa5cfb5b271a9333a2f516ca4fb5093226275f48a42d9e8cf" self.assertEqual(compare[:-130], txWire[:-130])
def decrypt(encrypted_privkey, passphrase): """BIP0038 non-ec-multiply decryption. Returns WIF privkey. :param Base58 encrypted_privkey: Private key :param str passphrase: UTF-8 encoded passphrase for decryption :return: BIP0038 non-ec-multiply decrypted key :rtype: Base58 :raises SaltException: if checksum verification failed (e.g. wrong password) """ d = unhexlify(base58decode(encrypted_privkey)) d = d[2:] # remove trailing 0x01 and 0x42 flagbyte = d[0:1] # get flag byte d = d[1:] # get payload assert flagbyte == b'\xc0', "Flagbyte has to be 0xc0" salt = d[0:4] d = d[4:-4] if SCRYPT_MODULE == "scrypt": key = scrypt.hash(passphrase, salt, 16384, 8, 8) elif SCRYPT_MODULE == "pylibscrypt": key = scrypt.scrypt(bytes(passphrase, "utf-8"), salt, 16384, 8, 8) else: raise ValueError("No scrypt module loaded") derivedhalf1 = key[0:32] derivedhalf2 = key[32:64] encryptedhalf1 = d[0:16] encryptedhalf2 = d[16:32] aes = AES.new(derivedhalf2) decryptedhalf2 = aes.decrypt(encryptedhalf2) decryptedhalf1 = aes.decrypt(encryptedhalf1) privraw = decryptedhalf1 + decryptedhalf2 privraw = ('%064x' % (int(hexlify(privraw), 16) ^ int(hexlify(derivedhalf1), 16))) wif = Base58(privraw) """ Verify Salt """ privkey = PrivateKey(format(wif, "wif")) addr = format(privkey.uncompressed.address, "BTC") a = bytes(addr, 'ascii') saltverify = hashlib.sha256(hashlib.sha256(a).digest()).digest()[0:4] if saltverify != salt : raise SaltException('checksum verification failed! Password may be incorrect.') return wif
def test_limit_order_cancel(self): s = { "fee": { "amount": 0, "asset_id": "1.3.0" }, "fee_paying_account": "1.2.104", "order": "1.7.51840", "extensions": [] } ops = [transactions.Operation(transactions.Limit_order_cancel(**s))] tx = transactions.Signed_Transaction(ref_block_num=ref_block_num, ref_block_prefix=ref_block_prefix, expiration=expiration, operations=ops) tx = tx.sign([wif], chain=prefix) tx.verify([PrivateKey(wif).pubkey], "BTS") txWire = hexlify(bytes(tx)).decode("ascii") compare = "f68585abf4dce7c804570102000000000000000000688095030000011f3fb754814f3910c1a8845486b86057d2b4588ae559b4c3810828c0d4cbec0e5b23517937cd7e0cc5ee8999d0777af7fe56d3c4b2e587421bfb7400d4efdae97a" self.assertEqual(compare[:-130], txWire[:-130])
def test_Transfer(self): pub = format(account.PrivateKey(wif).pubkey, prefix) from_account_id = "1.2.0" to_account_id = "1.2.1" amount = 1000000 asset_id = "1.3.4" message = "abcdefgABCDEFG0123456789" nonce = "5862723643998573708" fee = transactions.Asset(amount=0, asset_id="1.3.0") amount = transactions.Asset(amount=int(amount), asset_id=asset_id) encrypted_memo = memo.encode_memo( account.PrivateKey(wif), account.PublicKey(pub, prefix=prefix), nonce, message) memoStruct = { "from": pub, "to": pub, "nonce": nonce, "message": encrypted_memo, "chain": prefix } memoObj = transactions.Memo(**memoStruct) transferStruct = { "fee": fee, "from": from_account_id, "to": to_account_id, "amount": amount, "memo": memoObj } transfer = transactions.Transfer(**transferStruct) ops = [transactions.Operation(transfer)] tx = transactions.Signed_Transaction(ref_block_num=ref_block_num, ref_block_prefix=ref_block_prefix, expiration=expiration, operations=ops) tx = tx.sign([wif], chain=prefix) tx.verify([PrivateKey(wif).pubkey], "BTS") txWire = hexlify(bytes(tx)).decode("ascii") compare = "f68585abf4dce7c804570100000000000000000000000140420f0000000000040102c0ded2bc1f1305fb0faac5e6c03ee3a1924234985427b6167ca569d13df435cf02c0ded2bc1f1305fb0faac5e6c03ee3a1924234985427b6167ca569d13df435cf8c94d19817945c5120fa5b6e83079a878e499e2e52a76a7739e9de40986a8e3bd8a68ce316cee50b210000011f39e3fa7071b795491e3b6851d61e7c959be92cc7deb5d8491cf1c3c8c99a1eb44553c348fb8f5001a78b18233ac66727e32fc776d48e92d9639d64f68e641948" self.assertEqual(compare[:-130], txWire[:-130])
def test_fee_pool(self): s = { "fee": { "amount": 10001, "asset_id": "1.3.0" }, "from_account": "1.2.282", "asset_id": "1.3.32", "amount": 15557238, "extensions": [] } op = transactions.Asset_fund_fee_pool(**s) ops = [transactions.Operation(op)] tx = transactions.Signed_Transaction(ref_block_num=ref_block_num, ref_block_prefix=ref_block_prefix, expiration=expiration, operations=ops) tx = tx.sign([wif], chain=prefix) tx.verify([PrivateKey(wif).pubkey], "BTS") txWire = hexlify(bytes(tx)).decode("ascii") compare = "f68585abf4dce7c8045701101127000000000000009a02207662ed00000000000000011f39f7dc7745076c9c7e612d40c68ee92d3f4b2696b1838037ce2a35ac259883ba6c6c49d91ad05a7e78d80bb83482c273dbbc911587487bf468b85fb4f537da3d" self.assertEqual(compare[:-130], txWire[:-130])
def test_pricefeed(self): feed = transactions.PriceFeed( **{ "settlement_price": transactions.Price( base=transactions.Asset(amount=214211, asset_id="1.3.0"), quote=transactions.Asset(amount=1241, asset_id="1.3.14"), ), "core_exchange_rate": transactions.Price( base=transactions.Asset(amount=1241, asset_id="1.3.0"), quote=transactions.Asset(amount=6231, asset_id="1.3.14"), ), "maximum_short_squeeze_ratio": 1100, "maintenance_collateral_ratio": 1750, }) pFeed = transactions.Asset_publish_feed(fee=transactions.Asset( amount=100, asset_id="1.3.0"), publisher="1.2.0", asset_id="1.3.3", feed=feed) ops = [transactions.Operation(pFeed)] tx = transactions.Signed_Transaction(ref_block_num=ref_block_num, ref_block_prefix=ref_block_prefix, expiration=expiration, operations=ops) tx = tx.sign([wif], chain=prefix) tx.verify([PrivateKey(wif).pubkey], "BTS") txWire = hexlify(bytes(tx)).decode("ascii") compare = "f68585abf4dce7c8045701136400000000000000000003c34403000000000000d9040000000000000ed6064c04d9040000000000000057180000000000000e0000012009e13f9066fedc3c8c1eb2ac33b15dc67ecebf708890d0f8ab62ec8283d1636002315a189f1f5aa8497b41b8e6bb7c4dc66044510fae25d8f6aebb02c7cdef10" self.assertEqual(compare[:-130], txWire[:-130])
def test_encrypt(self): for memo in test_cases: enc = encode_memo(PrivateKey(memo["wif"]), PublicKey(memo["to"], prefix="GPH"), memo["nonce"], memo["plain"]) self.assertEqual(memo["message"], enc)
def getPrivateKeyForPublicKey(self, pub): for key in self.keys: if format(PrivateKey(key).pubkey, "BTS") == pub: return (key)
def removePrivateKeyFromPublicKey(self, pub): for key in self.keys: if format(PrivateKey(key).pubkey, "BTS") == pub: self.keys.remove(key) self._storeWallet()
def get_public(self, wif): pk = PrivateKey(wif, prefix=self.prefix) return (str(pk.pubkey))
def compareConstructedTX(self): # def test_online(self): # self.maxDiff = None op = transactions.Account_create( **{ "fee": { "amount": 1467634, "asset_id": "1.3.0" }, "registrar": "1.2.33", "referrer": "1.2.27", "referrer_percent": 3, "name": "foobar-f124", "owner": { "weight_threshold": 1, "account_auths": [], "key_auths": [[ "BTS5TPTziKkLexhVKsQKtSpo4bAv5RnB8oXcG4sMHEwCcTf3r7dqE", 1 ]], "address_auths": [] }, "active": { "weight_threshold": 1, "account_auths": [], "key_auths": [[ "BTS5TPTziKkLexhVKsQKtSpo4bAv5RnB8oXcG4sMHEwCcTf3r7dqE", 1 ]], "address_auths": [] }, "options": { "memo_key": "BTS5TPTziKkLexhVKsQKtSpo4bAv5RnB8oXcG4sMHEwCcTf3r7dqE", "voting_account": "1.2.5", "num_witness": 26, "num_committee": 8, "votes": [ "1:22", "1:23", "1:24", "1:25", "1:26", "1:27", "1:28", "1:30", "1:31", "1:32", "1:34", "1:35", "1:36", "1:37", "1:38", "1:40", "1:41", "1:44", "1:45", "1:49", "1:51", "1:56", "1:60", "0:76", "0:84", "0:87", "0:88", "0:91", "0:141", "1:143", "0:147", "2:148", "2:150", "1:165", "1:166", "2:171", "0:173", "2:179" ], "extensions": [] }, "extensions": {} }) ops = [transactions.Operation(op)] tx = transactions.Signed_Transaction(ref_block_num=ref_block_num, ref_block_prefix=ref_block_prefix, expiration=expiration, operations=ops) tx = tx.sign([wif], chain=prefix) tx.verify([PrivateKey(wif).pubkey], "BTS") txWire = hexlify(bytes(tx)).decode("ascii") pprint(transactions.JsonObj(tx)) from grapheneapi.grapheneapi import GrapheneAPI rpc = GrapheneAPI("localhost", 8092) compare = rpc.serialize_transaction(transactions.JsonObj(tx)) print(compare[:-130]) print(txWire[:-130]) print(txWire[:-130] == compare[:-130]) self.assertEqual(compare[:-130], txWire[:-130])
def is_key(self, wif, gls): pk = PrivateKey(wif, prefix=self.prefix) if str(pk.pubkey) == gls: return True return False
def test_shared_secret(self): for s in test_shared_secrets: priv = PrivateKey(s[0]) pub = PublicKey(s[1], prefix="GPH") shared_secret = get_shared_secret(priv, pub) self.assertEqual(s[2], shared_secret)