def test_generate_key_pair_signature_and_verify(self): private_key_file_path = join_with_root(private_key_file) password_path = join_with_root(private_key_password_file) with open(password_path) as f: password = f.read() print(password) new_pri_key, pub_key = ECCipher.load_key_pair(private_key_file_path, password) sample = b"qZaQ6S" print("gen prikey:", new_pri_key) self.assertIsNotNone(new_pri_key) new_signature = ECCipher.create_signature(new_pri_key, sample) print("new_signature is:", new_signature) self.assertIsNotNone(new_signature) # pub_key = ECCipher.create_public_key(new_pub_key) is_valid_sign = ECCipher.verify_sign(pub_key, new_signature, sample) print("is valid new_signature:", is_valid_sign) self.assertTrue(is_valid_sign)
def test_load_key_pair_from_private_key_and_verify_signature(self): private_key_file_path = join_with_root(private_key_file) password_path = join_with_root(private_key_password_file) with open(password_path) as f: password = f.read() print(password) pri_key, pub_key = ECCipher.load_key_pair(private_key_file_path, password) # ---------- sign and verify ------------ data = "testdata" new_signature = ECCipher.create_signature(pri_key, data) print("new_signature is:" + new_signature.hex()) is_valid_sign = verify_geth_signature(pub_key, new_signature, data) print("is valid new_signature:" + str(is_valid_sign)) self.assertTrue(is_valid_sign, "should be success") is_valid_sign = verify_geth_signature(pub_key, new_signature, data + "error") print("is valid new_signature:" + str(is_valid_sign)) self.assertFalse(is_valid_sign, "should be failed")
def mockup_product(self): private_key = ECCipher.create_private_key(self.account.privateKey) public_key = ECCipher.create_public_key_from_private_key(private_key) public_key = ECCipher.serialize_public_key(public_key) price = randint(1, 10000) * 0.01 return { 'description': 'stress testing description', 'signature': '304502201b31544ff65ebbfff3743a0b2536388e1f6cf2533de4bbf0ffab57d762f54d50022100a8101face8c6a6d2f0e01a9a01ea49d80598c880872db9e3c1e9eb27a23a2554', 'cover_image': 'upload_images/20181127072441_13.png', 'end_date': '2018-12-04T15:24:41.664517Z', 'msg_hash': 'dRFWYcWC9TKujDo7mLiUCq00MthHezzkyncAGIdaEos=', 'id': 53, 'start_date': '2018-11-27T15:24:41.664517Z', 'ptype': 'file', 'seq': 0, 'owner_address': public_key, 'tags': 'stress testing tags', 'price': price, 'title': 'stress testing product', 'category': 'stress testing category', 'status': 0, 'created': '2018-11-27T07:24:41.715315Z' }
def buyer_place_order(self, product, proxy): buyer_rsa_pubkey = self.rsa_public_key desc_hash = Encoder.str_to_base64_byte(product['msg_hash']) public_key = ECCipher.create_public_key( Encoder.hex_to_bytes(product['owner_address'])) seller_addr = w3.toChecksumAddress( ECCipher.get_address_from_public_key(public_key)) proxy = w3.toChecksumAddress(proxy) product = OrderInfo(desc_hash=desc_hash, buyer_rsa_pubkey=buyer_rsa_pubkey, seller=seller_addr, proxy=proxy, secondary_proxy=proxy, proxy_value=100, value=product['price'], time_allowed=3600 * 24) w3.personal.unlockAccount(self.account.address, _passphrase) order_id = self.buyer_agent.place_order(product) # w3.personal.lockAccount(self.account.address) # return -1 if failure return order_id
def derive_proxy_data(msg): msg = unpackb(msg, raw=False) public_key = ECCipher.create_public_key(msg['public_key']) data = msg['data'] signature = msg['signature'] valid = ECCipher.verify_sign(public_key, signature, data) if valid: return data
def sign_message_verify(sign_message): try: public_key = ECCipher.create_public_key(sign_message.public_key) valid = ECCipher.verify_sign(public_key, sign_message.signature, sign_message.data) except: return False else: return valid
def sign_proxy_data(data): public_key = _proxy_account.public_key private_key = _proxy_account.private_key signature = ECCipher.create_signature(private_key, data) msg = { 'data': data, 'public_key': ECCipher.serialize_public_key(public_key), 'signature': signature } return packb(msg, use_bin_type=True)
def test_load_key(self): pri_k, pub_k = ECCipher.load_key_pair(self.private_key_file_path, self.password) self.assertIsNotNone(pri_k) self.assertIsNotNone(pub_k) pri_key = ECCipher.load_private_key(self.private_key_file_path, self.password) self.assertIsNotNone(pri_key) msg = 'test123' sig = ECCipher.create_signature(pri_key, msg) print('sig:', sig) self.assertIsNotNone(sig) create_pub_key = ECCipher.create_public_key_from_private_key(pri_key) self.assertIsNotNone(create_pub_key) load_pub_key = ECCipher.load_public_key(self.private_key_file_path, self.password) self.assertIsNotNone(load_pub_key) v1 = ECCipher.verify_sign(load_pub_key, sig, msg) self.assertTrue(v1) v2 = ECCipher.verify_sign(create_pub_key, sig, msg) self.assertTrue(v2) addr = ECCipher.get_address_from_public_key(load_pub_key) print(addr) self.assertIsNotNone(addr)
def __init__(self, wallet): self.wallet = wallet self.account = self.wallet.accounts.default_account self.public_key = ECCipher.serialize_public_key(self.account.public_key) self.url = config.market.market_url_test self.token = '' self.nonce = ''
def seller_send_request_stream(self, order_info): logger.debug("seller send request to proxy ...") order_id = list(order_info.keys())[0] new_order_info = order_info[order_id] market_hash = new_order_info[0] seller_addr = eth_addr_to_string(new_order_info[3]) buyer_addr = eth_addr_to_string(new_order_info[2]) buyer_rsa_public_key = new_order_info[1] proxy_id = eth_addr_to_string(new_order_info[4]) session = get_session() raw_aes_key = session.query(FileInfo.aes_key) \ .filter(FileInfo.market_hash == Encoder.bytes_to_base64_str(market_hash)) \ .all()[0][0] logger.debug("start to encrypt aes key with buyer rsa public key") logger.debug("raw aes key: %s", raw_aes_key) logger.debug("buyer rsa public key: %s", buyer_rsa_public_key) encrypted_aes_key = load_der_public_key( buyer_rsa_public_key, backend=default_backend()).encrypt( raw_aes_key, padding.OAEP(mgf=padding.MGF1(algorithm=hashes.SHA256()), algorithm=hashes.SHA256(), label=None)) logger.debug("encrypted aes key: %s", encrypted_aes_key) logger.debug("order info got generated") message = Message() seller_data = message.seller_data message.type = Message.SELLER_DATA seller_data.order_id = order_id seller_data.order_type = 'stream' seller_data.seller_addr = seller_addr seller_data.buyer_addr = buyer_addr seller_data.market_hash = Encoder.bytes_to_base64_str(market_hash) seller_data.AES_key = encrypted_aes_key storage = seller_data.storage storage_type = session.query(FileInfo.remote_type) \ .filter(FileInfo.market_hash == Encoder.bytes_to_base64_str(market_hash)) \ .all()[0][0] remote_uri = session.query(FileInfo.remote_uri) \ .filter(FileInfo.market_hash == Encoder.bytes_to_base64_str(market_hash)) \ .all()[0][0] storage.type = storage_type storage.path = remote_uri sign_message = SignMessage() sign_message.public_key = self.wallet.market_client.public_key sign_message.data = message.SerializeToString() sign_message.signature = ECCipher.create_signature( self.wallet.market_client.account.private_key, sign_message.data) try: error, AES_key, urls = yield start_proxy_request( sign_message, proxy_id) if error: logger.error(error) else: logger.debug(AES_key) logger.debug(urls) event.emit(events.SELLER_DELIVERY, order_id) except Exception as e: logger.error(e)
def login(self, username=None): header = {'Content-Type': 'application/json'} data = {'public_key': self.public_key, 'username': username} resp = yield treq.post(url=self.url + 'account/v1/login/', headers=header, json=data, persistent=False) confirm_info = yield treq.json_content(resp) logger.debug("login response: %s", confirm_info) self.nonce = confirm_info['message'] logger.debug('nonce: %s', self.nonce) signature = ECCipher.create_signature(self.account.private_key, self.nonce) header_confirm = {'Content-Type': 'application/json'} data_confirm = { 'public_key': self.public_key, 'code': Encoder.bytes_to_hex(signature) } resp = yield treq.post(self.url + 'account/v1/confirm/', headers=header_confirm, json=data_confirm, persistent=False) confirm_info = yield treq.json_content(resp) self.token = confirm_info['message'] return confirm_info['status']
def __init__(self, wallet, account=None): self.wallet = wallet self.account = account or self.wallet.accounts.default_account self.public_key = ECCipher.serialize_public_key( self.account.public_key) if self.account else None self.url = config.market.market_url + '/' self.token = '' self.nonce = ''
def sign_buyer_message(message): sign_message = SignMessage() sign_message.public_key = buyer_public_key sign_message.data = message.SerializeToString() sign_message.signature = ECCipher.create_signature(buyer_private_key, sign_message.data) return sign_message
def proxy_claim_relay(self): proxy_trans = ProxyTrans(default_web3, config.chain.core_contract) private_key_file_path = join_with_root(config.wallet.private_key_file) password_path = join_with_root(config.wallet.private_key_password_file) with open(password_path) as f: password = f.read() priv_key, pub_key = ECCipher.geth_load_key_pair_from_private_key( private_key_file_path, password) priv_key_bytes = Encoder.str_to_base64_byte(priv_key) digest = hashes.Hash(hashes.SHA256(), backend=default_backend()) digest.update( ECCipher.generate_signature(priv_key_bytes, to_bytes(self.trade.order_id), password)) deliver_hash = digest.finalize() tx_hash = proxy_trans.claim_relay(self.trade.order_id, deliver_hash) return tx_hash
def buyer_send_request(self, order_info): logger.debug("buyer send request to proxy ...") order_id = list(order_info.keys())[0] new_order_info = order_info[order_id] seller_addr = eth_addr_to_string(new_order_info[3]) buyer_addr = eth_addr_to_string(new_order_info[2]) proxy_id = eth_addr_to_string(new_order_info[4]) message = Message() buyer_data = message.buyer_data message.type = Message.BUYER_DATA buyer_data.order_id = order_id buyer_data.order_type = 'file' buyer_data.seller_addr = seller_addr buyer_data.buyer_addr = buyer_addr buyer_data.market_hash = Encoder.bytes_to_base64_str(new_order_info[0]) sign_message = SignMessage() sign_message.public_key = self.wallet.market_client.public_key sign_message.data = message.SerializeToString() sign_message.signature = ECCipher.create_signature( self.wallet.market_client.account.private_key, sign_message.data) error, AES_key, urls = yield start_proxy_request( sign_message, proxy_id) def update_buyer_db(file_uri, file_path): market_hash = Encoder.bytes_to_base64_str(new_order_info[0]) file_uuid = file_uri.split('/')[3] session = get_session() session.query(BuyerFileInfo).filter( BuyerFileInfo.order_id == order_id).update( { BuyerFileInfo.market_hash: market_hash, BuyerFileInfo.is_downloaded: True, BuyerFileInfo.file_uuid: file_uuid, BuyerFileInfo.path: file_path, BuyerFileInfo.size: os.path.getsize(file_path) }, synchronize_session=False) session.commit() if error: logger.error(error) else: file_name = urls[0].split('/')[3] file_dir = join_with_rc(config.wallet.download_dir) # create if not exists os.makedirs(file_dir, exist_ok=True) file_path = os.path.join(file_dir, file_name) yield download_proxy_file(urls[0], file_path) logger.debug("downloaded file path: %s", file_path) decrypted_file = decrypt_file_aes(file_path, AES_key) logger.debug('Decrypted file path: %s', str(decrypted_file)) update_buyer_db(urls[0], decrypted_file) logger.debug("file has been downloaded") logger.debug("put order into confirmed queue, order id: %s", order_id) event.emit(events.BUYER_RECEIVE, order_id)
def exec_(): account = import_account(self.file.file, self.password.value) self.username.account = account def cb(status): self.imported.emit(status) public_key = ECCipher.serialize_public_key(account.public_key) wallet.market_client.isRegistered(public_key).addCallbacks(cb)
def __login(account=None): if account is None: wallet.accounts.set_default_account(1) account = wallet.accounts.default_account public_key = ECCipher.serialize_public_key(account.public_key) addr = utils.get_address_from_public_key_object(public_key) addr = web3.toChecksumAddress(addr) app.addr = addr if isinstance(account.key_passphrase, str): app.pwd = account.key_passphrase else: app.pwd = account.key_passphrase.decode() wallet.market_client.account = account wallet.market_client.public_key = ECCipher.serialize_public_key( wallet.market_client.account.public_key) wallet.market_client.login(app.username).addCallbacks( lambda _: event.emit(events.LOGIN_COMPLETED)) wallet.init() initialize_system() app.router.redirectTo('market_page')
def add_comment_by_hash(self, market_hash, comment=""): comment_address = ECCipher.get_address_from_public_key(self.account.public_key) logger.debug(comment_address) header = {"MARKET-KEY": self.public_key, "MARKET-TOKEN": self.token, 'Content-Type': 'application/json'} data = {'public_key': self.public_key, 'market_hash': market_hash, 'content': comment} url = utils.build_url(self.url + "comment/v1/comment/add/", {'market_hash': market_hash}) resp = yield treq.post(url, headers=header, json=data, persistent=False) comment_info = yield treq.json_content(resp) logger.debug('upload file info to market confirm: %s', comment_info) return comment_info['status']
def publish_product(self, selected_id, title, ptype, description, price, tags, start_date, end_date, category=None, cover_image=None): logger.debug("start publish product") header = {'Content-Type': 'multipart/form-data'} # 'application/json'} header['MARKET-KEY'] = self.public_key header['MARKET-TOKEN'] = self.token logger.debug('header token: %s', self.token) data = { 'owner_address': self.public_key, 'title': title, 'ptype': ptype, 'description': description, 'price': price, 'tags': tags, 'start_date': start_date, 'end_date': end_date, 'category': category } signature_source = str( self.public_key) + str(title) + str(ptype) + str( description) + str(price) + MarketClient.str_to_timestamp( start_date) + MarketClient.str_to_timestamp(end_date) signature = ECCipher.create_signature(self.account.private_key, signature_source) data['signature'] = Encoder.bytes_to_hex(signature) logger.debug("signature: %s", data['signature']) try: url = self.url + 'product/v1/allproducts/' resp = yield treq.post( url, files=dict(cover_image=open(cover_image, 'rb')), headers=header, data=data, persistent=False) confirm_info = yield treq.json_content(resp) logger.debug('market_hash: %s', confirm_info['data']['market_hash']) market_hash = confirm_info['data']['market_hash'] except Exception as e: logger.exception(e) if ptype == 'file' or ptype == 'stream': publish_file_update(market_hash, selected_id) return market_hash
def __generate_nonce_signature_and_get_token(self, header, nonce, pub_key_str, pri_key): url = '%s/account/v1/confirm/' % HOST print("nonce:%s" % nonce) nonce_signature = ECCipher.create_signature(pri_key, nonce) payload = {"public_key": pub_key_str, "code": Encoder.bytes_to_hex(nonce_signature)} confirm_resp = requests.post(url, headers=header, json=payload) print("response:%s" , confirm_resp.text) self.assertEqual(confirm_resp.status_code, 200) parsed_json = json.loads(confirm_resp.text) self.assertEqual(parsed_json['status'], 1) token = parsed_json['message'] print("token:%s" % token) return token
def test_server_chain(): os.chdir(root_dir) server_web3 = chain.default_web3 # chain.utils.deploy_contract(config.chain.core_contract) buyertrans = BuyerAgent(server_web3, config.chain.core_contract) print(server_web3.eth.defaultAccount) # desc_hash_base64 = 'AQkKqDxtNIRJ+1V82J5lP2/fRj/zbJ+2n0GzUF52Wsc=' # desc_hash = Encoder.str_to_base64_byte(desc_hash_base64) # public_key = RSACipher.load_public_key() # print('pubkey ' + str(len(public_key))) # order_info = OrderInfo( # desc_hash=desc_hash, # buyer_rsa_pubkey=public_key, # seller=buyertrans.web3.eth.defaultAccount, # proxy=buyertrans.web3.eth.defaultAccount, # secondary_proxy=buyertrans.web3.eth.defaultAccount, # proxy_value=10, # value=20, # time_allowed=100 # ) # test_server_id = buyertrans.place_order(order_info) # print(test_server_id) # buyertrans.withdraw_order(test_server_id) # print(buyertrans.query_order(test_server_id)) order_num = buyertrans.get_order_num() print(order_num) latest_order_info = buyertrans.query_order(order_num - 1) private_key_file_path = join_with_root(config.wallet.private_key_file) password_path = join_with_root(config.wallet.private_key_password_file) with open(password_path) as f: password = f.read() priv_key, pub_key = ECCipher.load_key_pair_from_private_key( private_key_file_path, password) pub_key_bytes = Encoder.str_to_base64_byte(pub_key) pub_key_loaded = load_der_public_key(pub_key_bytes, backend=default_backend()) # print(Encoder.str_to_base64_byte(pub_key)) # print(len(Encoder.str_to_base64_byte(pub_key))) # print(pub_key_bytes_to_addr(Encoder.str_to_base64_byte(pub_key))) # print(len(pub_key_bytes_to_addr(Encoder.str_to_base64_byte(pub_key)))) print(get_addr_from_public_key(pub_key_loaded)) print(to_bytes(hexstr=latest_order_info[2])) print(len(to_bytes(hexstr=latest_order_info[2])))
def buyer_send_request_stream(self, order_info): logger.debug("buyer send request to proxy ...") order_id = list(order_info.keys())[0] new_order_info = order_info[order_id] seller_addr = eth_addr_to_string(new_order_info[3]) buyer_addr = eth_addr_to_string(new_order_info[2]) proxy_id = eth_addr_to_string(new_order_info[4]) message = Message() buyer_data = message.buyer_data message.type = Message.BUYER_DATA buyer_data.order_id = order_id buyer_data.order_type = 'stream' buyer_data.seller_addr = seller_addr buyer_data.buyer_addr = buyer_addr buyer_data.market_hash = Encoder.bytes_to_base64_str(new_order_info[0]) sign_message = SignMessage() sign_message.public_key = self.wallet.market_client.public_key sign_message.data = message.SerializeToString() sign_message.signature = ECCipher.create_signature( self.wallet.market_client.account.private_key, sign_message.data) error, AES_key, urls = yield start_proxy_request( sign_message, proxy_id) def update_buyer_db(stream_id): session = get_session() session.query(BuyerFileInfo).filter( BuyerFileInfo.order_id == order_id).update( { BuyerFileInfo.is_downloaded: True, BuyerFileInfo.path: stream_id, }, synchronize_session=False) session.commit() if error: logger.error(error) else: update_buyer_db(json.dumps(urls)) logger.debug("Stream data has been geted") event.emit(events.BUYER_RECEIVE, order_id)
def setUp(self): private_key_file_path1 = join_with_root(private_key_file1) private_key_file_path2 = join_with_root(private_key_file2) password_path = join_with_root(private_key_password_file) with open(password_path) as f: password = f.read() self.pri_key, self.pub_key = ECCipher.load_key_pair(private_key_file_path1, password) self.pri_key_2, self.pub_key_2 = ECCipher.load_key_pair(private_key_file_path2, password) self.pub_key_string = ECCipher.serialize_public_key(self.pub_key) self.pub_key_string2 = ECCipher.serialize_public_key(self.pub_key_2) self.address = ECCipher.get_address_from_public_key(self.pub_key) self.address_2 = ECCipher.get_address_from_public_key(self.pub_key_2)
def send_buyer_message(self, order): global kad_port message = Message() buyer_data = message.buyer_data message.type = Message.BUYER_DATA buyer_data.order_id = order['order_id'] buyer_data.order_type = order['order_type'] buyer_data.seller_addr = order['seller'] buyer_data.buyer_addr = order['buyer'] buyer_data.market_hash = order['market_hash'] sign_message = SignMessage() sign_message.public_key = self.public_key sign_message.data = message.SerializeToString() sign_message.signature = ECCipher.create_signature( self.private_key, sign_message.data ) kad_port += 1 proxy_id = order['proxy'] error, AES_key, urls = yield start_proxy_request(sign_message, proxy_id, kad_port) if error: print(error) else: print(urls) if order['order_type'] == 'file': file_name = urls[0].split('/')[3] file_dir = join_with_rc(config.wallet.download_dir) # create if not exists os.makedirs(file_dir, exist_ok=True) file_path = os.path.join(file_dir, file_name) yield download_proxy_file(urls[0], file_path)
def login(): path = os.path.expanduser('~/.cpchain') if not os.path.exists(path): os.mkdir(path) with shelve.open(os.path.join(path, 'account')) as file: key_path = file.get('key_path') key_passphrase = file.get('key_passphrase') try: app.timing(logger, 'Data Init') if key_path and key_passphrase: if isinstance(key_passphrase, str): account = Account(key_path, key_passphrase.encode()) else: account = Account(key_path, key_passphrase) public_key = ECCipher.serialize_public_key(account.public_key) # Init market client account wallet.market_client.account = account wallet.market_client.public_key = public_key app.timing(logger, 'Account Prepare') addr = utils.get_address_from_public_key_object(public_key) addr = web3.toChecksumAddress(addr) logger.info(addr) app.addr = addr if isinstance(key_passphrase, str): app.pwd = key_passphrase else: app.pwd = key_passphrase.decode() wallet.market_client.query_username(app) __unlock() app.timing(logger, 'Unlock') enterPDash(account) return except Exception as e: logger.error(e) logger.debug('Init') wnd = LoginWindow(reactor) wnd.show() wallet.set_main_wnd(wnd)
def __generate_nonce_signature_and_get_token(self, header, nonce, pub_key_str, pri_key): url = reverse('confirm') print("nonce:%s" % nonce) nonce_signature = ECCipher.create_signature(pri_key, nonce) payload = { "public_key": pub_key_str, "code": Encoder.bytes_to_hex(nonce_signature) } # self.client.head(header) confirm_resp = self.client.post(url, data=payload, format='json', **header) self.assertEqual(confirm_resp.status_code, 200) resp = confirm_resp.content.decode("utf-8") print("response:%s" % resp) parsed_json = json.loads(resp) self.assertEqual(parsed_json['status'], 1) token = parsed_json['message'] print("token:%s" % token) return token
def send_seller_message(self, order): global kad_port message = Message() seller_data = message.seller_data message.type = Message.SELLER_DATA seller_data.order_id = order['order_id'] seller_data.order_type = order['order_type'] seller_data.seller_addr = order['seller'] seller_data.buyer_addr = order['buyer'] seller_data.market_hash = order['market_hash'] seller_data.AES_key = order['AES_key'] storage = seller_data.storage storage.type = order['storage_type'] storage.path = order['storage_path'] sign_message = SignMessage() sign_message.public_key = self.public_key sign_message.data = message.SerializeToString() sign_message.signature = ECCipher.create_signature( self.private_key, sign_message.data ) kad_port += 1 proxy_id = order['proxy'] error, AES_key, urls = yield start_proxy_request(sign_message, proxy_id, kad_port) if error: print(error) else: print(urls)
def publish_product(self, selected_id, title, description, price, tags, start_date, end_date, file_md5, size): logger.debug("start publish product") header = {'Content-Type': 'application/json'} header['MARKET-KEY'] = self.public_key header['MARKET-TOKEN'] = self.token logger.debug('header token: %s', self.token) data = {'owner_address': self.public_key, 'title': title, 'description': description, 'price': price, 'tags': tags, 'start_date': start_date, 'end_date': end_date, 'file_md5': file_md5, 'size': size} signature_source = str(self.public_key) + str(title) + str(description) + str( price) + MarketClient.str_to_timestamp(start_date) + MarketClient.str_to_timestamp(end_date) + str(file_md5) signature = ECCipher.create_signature(self.account.private_key, signature_source) data['signature'] = Encoder.bytes_to_hex(signature) logger.debug("signature: %s", data['signature']) resp = yield treq.post(self.url + 'product/v1/product/publish/', headers=header, json=data, persistent=False) confirm_info = yield treq.json_content(resp) print(confirm_info) logger.debug('market_hash: %s', confirm_info['data']['market_hash']) market_hash = confirm_info['data']['market_hash'] publish_file_update(market_hash, selected_id) return market_hash
def buyer_request(): message = Message() buyer_data = message.buyer_data message.type = Message.BUYER_DATA buyer_data.order_id = order_id buyer_data.order_type = order_type buyer_data.seller_addr = seller_addr buyer_data.buyer_addr = buyer_addr buyer_data.market_hash = 'MARKET_HASH' sign_message = SignMessage() sign_message.public_key = buyer_public_key sign_message.data = message.SerializeToString() sign_message.signature = ECCipher.create_signature(buyer_private_key, sign_message.data) proxy_list = yield pick_proxy() proxy_id = proxy_list[0] # should be selected by UI from proxy list if proxy_id: error, AES_key, urls = yield start_proxy_request( sign_message, proxy_id) if error: print(error) else: print(AES_key) print(urls) file_name = urls[0].split('/')[3] file_dir = join_with_rc(config.wallet.download_dir) # create if not exists os.makedirs(file_dir, exist_ok=True) file_path = os.path.join(file_dir, file_name) yield download_proxy_file(urls[0], file_path)
"ciphertext": "b47aed1b93acaa270d14f3dce9084cb073e67dbe687340f75845817d4668e6fe", "cipher": "aes-128-ctr" } } keystore = '/tmp/keystore' with open(keystore, 'w') as f: f.write(json.dumps(encrypted_key)) buyer_account = Account(keystore, b'passwd') seller_account = Account(keystore, b'passwd') buyer_private_key = buyer_account.private_key #object type buyer_public_key = ECCipher.serialize_public_key( buyer_account.public_key) # string type buyer_addr = ECCipher.get_address_from_public_key( buyer_account.public_key) #string type seller_private_key = seller_account.private_key seller_public_key = ECCipher.serialize_public_key( seller_account.public_key) #string type seller_addr = ECCipher.get_address_from_public_key( seller_account.public_key) #string type order_id = 1 order_type = 'file' def fake_seller_message(): message = Message()