def get(self, request, format=None): safe_funder_public_key = Account.privateKeyToAccount(settings.SAFE_FUNDER_PRIVATE_KEY).address \ if settings.SAFE_FUNDER_PRIVATE_KEY else None safe_sender_public_key = Account.privateKeyToAccount(settings.SAFE_TX_SENDER_PRIVATE_KEY).address \ if settings.SAFE_TX_SENDER_PRIVATE_KEY else None content = { 'name': 'Safe Relay Service', 'version': __version__, 'api_version': self.request.version, 'https_detected': self.request.is_secure(), 'settings': { 'ETHEREUM_NODE_URL': settings.ETHEREUM_NODE_URL, 'ETHEREUM_TRACING_NODE_URL': settings.ETHEREUM_TRACING_NODE_URL, 'ETH_HASH_PREFIX ': settings.ETH_HASH_PREFIX, 'FIXED_GAS_PRICE': settings.FIXED_GAS_PRICE, 'GAS_STATION_NUMBER_BLOCKS': settings.GAS_STATION_NUMBER_BLOCKS, 'NOTIFICATION_SERVICE_PASS': bool(settings.NOTIFICATION_SERVICE_PASS), 'NOTIFICATION_SERVICE_URI': settings.NOTIFICATION_SERVICE_URI, 'SAFE_ACCOUNTS_BALANCE_WARNING': settings.SAFE_ACCOUNTS_BALANCE_WARNING, 'SAFE_CHECK_DEPLOYER_FUNDED_DELAY': settings.SAFE_CHECK_DEPLOYER_FUNDED_DELAY, 'SAFE_CHECK_DEPLOYER_FUNDED_RETRIES': settings.SAFE_CHECK_DEPLOYER_FUNDED_RETRIES, 'SAFE_CONTRACT_ADDRESS': settings.SAFE_CONTRACT_ADDRESS, 'SAFE_DEFAULT_CALLBACK_HANDLER': settings.SAFE_DEFAULT_CALLBACK_HANDLER, 'SAFE_FIXED_CREATION_COST': settings.SAFE_FIXED_CREATION_COST, 'SAFE_FUNDER_MAX_ETH': settings.SAFE_FUNDER_MAX_ETH, 'SAFE_FUNDER_PUBLIC_KEY': safe_funder_public_key, 'SAFE_FUNDING_CONFIRMATIONS': settings.SAFE_FUNDING_CONFIRMATIONS, 'SAFE_PROXY_FACTORY_ADDRESS': settings.SAFE_PROXY_FACTORY_ADDRESS, 'SAFE_PROXY_FACTORY_V1_0_0_ADDRESS': settings.SAFE_PROXY_FACTORY_V1_0_0_ADDRESS, 'SAFE_TX_NOT_MINED_ALERT_MINUTES': settings.SAFE_TX_NOT_MINED_ALERT_MINUTES, 'SAFE_TX_SENDER_PUBLIC_KEY': safe_sender_public_key, 'SAFE_V0_0_1_CONTRACT_ADDRESS': settings.SAFE_V0_0_1_CONTRACT_ADDRESS, 'SAFE_V1_0_0_CONTRACT_ADDRESS': settings.SAFE_V1_0_0_CONTRACT_ADDRESS, 'SAFE_VALID_CONTRACT_ADDRESSES': settings.SAFE_VALID_CONTRACT_ADDRESSES, } } return Response(content)
def sign_create_deposit(deposit_params, private_key): """ Function to sign the deposit parameters required by the Switcheo API. Execution of this function is as follows:: sign_create_deposit(deposit_params=signable_params, private_key=eth_private_key) The expected return result for this function is as follows:: { 'blockchain': 'eth', 'asset_id': 'ETH', 'amount': '10000000000000000', 'timestamp': 1542089346249, 'contract_hash': '0x607af5164d95bd293dbe2b994c7d8aef6bec03bf', 'address': '0x32c46323b51c977814e05ef5e258ee4da0e4c3c3', 'signature': 'd4b8491d6514bff28b9f2caa440f51a93f31d....' } :param deposit_params: Parameters needed to deposit to the Switcheo API and signed in this function. :type deposit_params: dict :param private_key: The Ethereum private key to sign the deposit parameters. :type private_key: str :return: Dictionary of signed message to send to the Switcheo API. """ hash_message = defunct_hash_message(text=stringify_message(deposit_params)) hex_message = binascii.hexlify(hash_message).decode() signed_message = binascii.hexlify(Account.signHash(hex_message, private_key=private_key)['signature']).decode() create_params = deposit_params.copy() create_params['address'] = to_normalized_address(Account.privateKeyToAccount(private_key=private_key).address) create_params['signature'] = signed_message return create_params
def sign_create_withdrawal(withdrawal_params, private_key): """ Function to create a withdrawal from the Switcheo Smart Contract. Execution of this function is as follows:: sign_create_withdrawal(withdrawal_params=signable_params, private_key=eth_private_key) The expected return result for this function is as follows:: { 'blockchain': 'eth', 'asset_id': 'ETH', 'amount': '10000000000000000', 'timestamp': 1542090476102, 'contract_hash': '0x607af5164d95bd293dbe2b994c7d8aef6bec03bf', 'address': '0x32c46323b51c977814e05ef5e258ee4da0e4c3c3', 'signature': '375ddce62e5b3676d5e94ebb9f9a8af5963b....' } :param withdrawal_params: The parameters to be signed and create a withdraw from Switcheo. :type withdrawal_params: dict :param private_key: The Ethereum private key to sign the deposit parameters. :type private_key: str :return: Dictionary of the signed transaction to initiate the withdrawal of ETH via the Switcheo API. """ hash_message = defunct_hash_message(text=stringify_message(withdrawal_params)) hex_message = binascii.hexlify(hash_message).decode() signed_message = binascii.hexlify(Account.signHash(hex_message, private_key=private_key)['signature']).decode() create_params = withdrawal_params.copy() create_params['address'] = to_normalized_address(Account.privateKeyToAccount(private_key=private_key).address) create_params['signature'] = signed_message return create_params
def sign_create_cancellation(cancellation_params, private_key): """ Function to sign the parameters required to create a cancellation request from the Switcheo Exchange. Execution of this function is as follows:: sign_create_cancellation(cancellation_params=signable_params, private_key=eth_private_key) The expected return result for this function is as follows:: { 'order_id': '3125550a-04f9-4475-808b-42b5f89d6693', 'timestamp': 1542088842108, 'address': '0x32c46323b51c977814e05ef5e258ee4da0e4c3c3', 'signature': 'dac70ca711bcfbeefbdead2158ef8b15fab1a1....' } :param cancellation_params: Dictionary with Order ID and timestamp to sign for creating the cancellation. :type cancellation_params: dict :param private_key: The Ethereum private key to sign the deposit parameters. :type private_key: str :return: Dictionary of signed message to send to the Switcheo API. """ hash_message = defunct_hash_message(text=stringify_message(cancellation_params)) hex_message = binascii.hexlify(hash_message).decode() signed_message = binascii.hexlify(Account.signHash(hex_message, private_key=private_key)['signature']).decode() create_params = cancellation_params.copy() create_params['address'] = to_normalized_address(Account.privateKeyToAccount(private_key=private_key).address) create_params['signature'] = signed_message return create_params
def sign(safe, multi): """Sign transation of a Safe. This will sign a given transaction hash and return the signature. """ transaction_hash = click.prompt('Please enter transaction hash') transaction_hash = codecs.decode(transaction_hash, 'hex_codec') choice = click.prompt('What would you like to use for signing?\n(1) Private key\n(2) Account mnemonic\n(3) Safe mnemonic (Yields 2 signatures)\n', type=int) loops = 1 if not multi else safe.get_threshold() account_info = [] while loops > 0: if choice == 1: private_key = click.prompt('Please enter private key (Input hidden)', hide_input=True) address = Account.privateKeyToAccount(private_key).address account_info.append((private_key, address)) elif choice == 2: mnemonic = click.prompt('Please enter account mnemonic (Input hidden)', hide_input=True) account_info.append(get_account_info_from_mnemonic(mnemonic)) else: mnemonic = click.prompt('Please enter Safe mnemonic (Input hidden)', hide_input=True) account_info.append(get_account_info_from_mnemonic(mnemonic, index=0)) account_info.append(get_account_info_from_mnemonic(mnemonic, index=1)) for i, info in enumerate(account_info): loops -= 1 private_key = info[0] address = info[1] v, r, s = ecsign(transaction_hash, codecs.decode(private_key, 'hex_codec')) signature = {'v': v, 'r': r, 's': s} click.echo('Signature {} ({}):\n\n{}'.format(i, address, json.dumps(signature)))
def __init__(self, keyfile, keyfile_password_file=None, password=None): self.web3 = Web3() self.__keyfile = keyfile self.__keyfile_password_file = keyfile_password_file self.__password = password self.__localAccount = Account.privateKeyToAccount(self.__get_private_key_from_keyfile())
def _node_address_and_key(cls): node_address = os.getenv('NODE_ADDRESS') private_key = os.getenv('NODE_PRIVATE_KEY') key_filename = os.getenv('KEY_FILENAME') if key_filename is not None: encrypted_key = cls._read_key_file(key_filename) password = getpass.getpass( 'Input password to decrypt the node key: ') private_key = web3.eth.Account.decrypt(encrypted_key, password) node_address = Account.privateKeyToAccount(private_key).address if node_address is None: raise Exception('Node address is not defined') node_address = web3.Web3.toChecksumAddress(node_address) return node_address, private_key
def sign_create_order(order_params, private_key): """ Function to sign the create order parameters and send to the Switcheo API. Execution of this function is as follows:: sign_create_order(order_params=signable_params, private_key=eth_private_key) The expected return result for this function is as follows:: { 'blockchain': 'eth', 'pair': 'JRC_ETH', 'side': 'buy', 'price': '0.00000003', 'want_amount': '3350000000000000000000000', 'use_native_tokens': False, 'order_type': 'limit', 'timestamp': 1542089785915, 'contract_hash': '0x607af5164d95bd293dbe2b994c7d8aef6bec03bf', 'signature': '536306a2f2aee499ffd6584027029ee585293b3686....', 'address': '0x32c46323b51c977814e05ef5e258ee4da0e4c3c3' } :param order_params: Parameters to create an order to be submitted to the Switcheo Order Book. :type order_params: dict :param private_key: The Ethereum private key to sign the deposit parameters. :type private_key: str :return: Dictionary of signed message to send to the Switcheo API. """ hash_message = defunct_hash_message(text=stringify_message(order_params)) hex_message = binascii.hexlify(hash_message).decode() create_params = order_params.copy() signed_message = binascii.hexlify( Account.signHash(hex_message, private_key=private_key)['signature']).decode() create_params['signature'] = signed_message create_params['address'] = to_normalized_address( Account.privateKeyToAccount(private_key=private_key).address) return create_params
def get_json_data(filename): with open(filename) as file: return json.load(file) private_key = get_json_data(ACCOUNT_FILE)['account'] network_data = get_json_data(NETWORK_FILE) rpc_url = network_data['rpcUrl'] gas_price_url = network_data['gasPriceUrl'] w3 = Web3(HTTPProvider(rpc_url)) account = Account.privateKeyToAccount(private_key) def create_parser(): parser = argparse.ArgumentParser( description='Solution to registrar assignment') parser.add_argument('--deploy', required=False, action='store_true', help='Deploy a contract') parser.add_argument('--add', type=str, required=False, metavar='JSON',
from eth_account.account import Account from web3 import Web3, HTTPProvider from web3._utils.transactions import wait_for_transaction_receipt from web3.method import Method from web3.middleware import construct_sign_and_send_raw_middleware from web3.types import Wei from web3_flashbots import flashbot # test miner account faucet = Account.privateKeyToAccount( "0x133be114715e5fe528a1b8adf36792160601a2d63ab59d1fd454275b31328791") dummy_receiver = "0x1111111111111111111111111112144211111112" user = Account.create("test") if __name__ == '__main__': # instantiate Web3 as usual w3 = Web3(HTTPProvider("http://localhost:8545")) w3.middleware_onion.add(construct_sign_and_send_raw_middleware(faucet)) # inject the new data flashbot(w3, flashbots_key_id="5", flashbots_secret="2", flashbots_url="http://localhost:8545") # faucet funds the user assert w3.eth.getBalance(user.address) == 0 tx = w3.eth.sendTransaction({ "from": faucet.address, "to": user.address, "value": w3.toWei("1.1", "ether"),
from PIL import Image from web3.auto import w3 from web3.iban import Iban # Fully pretend a laptop is firefly # - show address qrcode at startup # - receive blecast of message to sign # - show sig:r/ and sig:s/ qrcodes after signing (assume sig:v is 27?) bus = dbus.SystemBus() device_uuids = defaultdict(set) #eth_account = Account.privateKeyToAccount(os.urandom(32)) eth_account = Account.privateKeyToAccount( bytes.fromhex( 'cf53d57f0d9cdcd2ab0aadf227b5c99bead260195e862cba5c8e782f4d0619d1')) firefly_key = "29231d6f2761547092e6a81664fd0eb7" # unsigned to signed def sbyte(n): return int.from_bytes(n.to_bytes(1, byteorder="big", signed=False), byteorder="big", signed=True) def decrypt(b): obj = Cipher(algorithms.AES(bytes.fromhex(firefly_key)),