def upload_data(self, plaintext, storage): """ Upload data to the selected storage Args: plaintext (str): plaintext storage (str): storage layer e.g. ipfs, arweave, skynet, etc. Returns: label, data_source_public_key, hash_key (bytes, bytes, str): tuple containing policy label, data source public key and hash_key """ label, data_source_public_key, data = self.encrypt_data( plaintext=plaintext) if storage == "ipfs": hash_key = self.ipfs.add_bytes(data) elif storage == "arweave": transaction = arweave.Transaction(self.arweave_wallet, data=data) transaction.sign() transaction.send() hash_key = transaction.id elif storage == "skynet": file_name = '/tmp/{}.txt'.format( random.randint(100000000000, 999999999999)) file = open(file_name, 'wb') file.write(data) file.close() skynet_client = skynet.SkynetClient() hash_key = skynet_client.upload_file(file_name) else: raise ValueError("invalid storage layer") return label, data_source_public_key, hash_key
def post_genesis_transaction(): transaction = arweave.Transaction(wallet) transaction.add_tag(name="App-Name", value="ArVerifyDev") transaction.add_tag(name="Type", value="Genesis") transaction.add_tag(name="Fee", value=f"{FEE:.12f}") transaction.add_tag(name="Domain", value=str(DOMAIN)) transaction.sign() transaction.send() return transaction.id
def store_on_arweave(verified_address: str) -> str: # check if address has been verified before auth_nodes = ["s-hGrOFm1YysWGC3wXkNaFVpyrjdinVpRKiVnhbo2so"] transaction_id = get_verification_id(verified_address, auth_nodes) # if the address hasn't been verified yet, create a transaction if not transaction_id: # store verification on Arweave transaction = arweave.Transaction(wallet) transaction.add_tag(name="App-Name", value="ArVerifyDev") transaction.add_tag(name="Type", value="Verification") transaction.add_tag(name="Method", value="Google") transaction.add_tag(name="Address", value=verified_address) transaction.sign() _fee = transaction.get_price() transaction.send() return transaction.id else: return transaction_id
def send_to_arweave(verified_address: str, fee: float) -> arweave.Transaction: # store verification on chain transaction = arweave.Transaction(wallet) transaction.add_tag(name="App-Name", value="ArVerifyDev") transaction.add_tag(name="Type", value="Verification") transaction.add_tag(name="Method", value="Google") transaction.add_tag(name="Address", value=verified_address) transaction.sign() _fee = transaction.get_price() transaction.send() # tip member of DAO # fee -= _fee # print("_fee", _fee) # print("fee", fee) # to_address = select_from_contract() # tip_transaction = arweave.Transaction(wallet, quantity=fee, to=to_address) # tip_transaction.add_tag(name="AppName", value="ArVerifyDev") # tip_transaction.sign() # tip_transaction.send() return transaction
def fetch_data(self, shareable_code, storage): """ Fetch data from the selected storage and decrypt it Args: shareable_code (str): shareable code storage (str): storage layer e.g. ipfs, arweave, skynet, etc. Returns: retrieved_plaintexts (list): list of str """ meta_data = json.loads( base64.b64decode(shareable_code.encode('utf-8')).decode('utf-8')) data_source_public_key = meta_data['data_source_public_key'] hash_key = meta_data['hash'] if storage == "ipfs": data = self.ipfs.cat(hash_key) elif storage == "arweave": transaction = arweave.Transaction(self.arweave_wallet, id=hash_key) transaction.get_data() data = transaction.data if data == b'': raise ValueError( "Transaction not found. Wait for some more time") elif storage == "skynet": file_name = '/tmp/{}.txt'.format( random.randint(100000000000, 999999999999)) skynet_client = skynet.SkynetClient() skynet_client.download_file(file_name, hash_key) file = open(file_name, 'rb') data = file.read() file.close() else: raise ValueError("invalid storage layer") data_source_public_key = bytes.fromhex(data_source_public_key) policy_info = meta_data["policy_info"] return self.decrypt_data(data_source_public_key=data_source_public_key, data=data, policy_info=policy_info)
def upload_txt(self, tags, wallet_path, file_path): """ :param path: :param jwk: :return: """ wallet = arweave.Wallet(wallet_path) # reading .txt content with open(file_path) as txt: content = txt.read() txt.close() tx_obj = arweave.Transaction(wallet, data=content) tx_obj.add_tag('Content Type', 'text/plain') for tag, value in tags.items(): tx_obj.add_tag(tag, value) tx_obj.sign() tx_obj.send() return tx_obj.id