def submit_request(account, sub=0, aud=0, exp=0, nbf=0, iat=0, wait=False): log.out.debug("submit_request: \"Using contract at {}\"".format( authority_contract.address)) # setting header alg = w3.toBytes(text="RS256") typ = w3.toBytes(text="JWT") aud = w3.toBytes(text=aud) # hashing request id try: request_id_bytes = w3.soliditySha3(['address', 'bytes32'], [account, aud]) except web3.exceptions.InvalidAddress as e: log.out.warning( "\033[91mPlease make sure your address has a valid EIP cheksum. Test on etherscan.io and correct in ressources/user_info.json\033[0m" ) exit() # casting those filthy bytes to an human-readable hexstr request_id = w3.toHex(request_id_bytes) request_id = request_id[0:20] # Proof that this works #log.out.debug(w3.toBytes(hexstr=request_id)) #log.out.debug(request_id_bytes) # submit to blockchain txn_hash = authority_contract.functions.addPermissionRequest( request_id, alg, typ, aud).transact({'from': account}) # wait for tx_receipt, could be disabled if (wait): timer = 50 tx_receipt = None log.out.info( "Transaction sent, waiting for mining: max. {} seconds".format( timer)) while (tx_receipt is None and timer > 0): tx_receipt = w3.eth.getTransactionReceipt(txn_hash) time.sleep(1) timer -= 1 if tx_receipt is not None: log.out.info( "\033[92mTransaction with request id {} mined!\033[0m".format( request_id)) return request_id
def sign_apphash(apphash): sedes = CountableList(List([rlp.sedes.binary, rlp.sedes.big_endian_int, rlp.sedes.big_endian_int, rlp.sedes.binary, rlp.sedes.binary])) decoded = rlp.decode(bytes.fromhex(apphash), sedes) for i in decoded: data = list(i) data[2] = bool(data[2]) msg_hash = w3.soliditySha3(['bytes32', 'uint256', 'bool', 'bytes', 'bytes'], data).hex()[2:] signed = utils.ecsign(bytes.fromhex(msg_hash), operator_normalize_key) tx = '1{0:0{1}X}{2:0{3}X}{4:0{5}X}{6:X}'.format(signed[1], 64, signed[2], 64, signed[0], 2, data[1]) requests.get('http://localhost:26657/broadcast_tx_async?tx="{}"'.format(tx))
def hashOrder(sellTokenAdress, sellTokenAmount, buyTokenAdress, buyTokenAmount, expiry, nonce, contractAdress): hashTypes = [ 'address', 'uint128', 'address', 'uint128', 'uint32', 'uint64', 'address' ] hashData = [ w3.toChecksumAddress(sellTokenAdress), sellTokenAmount, w3.toChecksumAddress(buyTokenAdress), buyTokenAmount, expiry, nonce, w3.toChecksumAddress(contractAdress) ] orderHash = w3.soliditySha3(hashTypes, hashData) return Web3.toHex(orderHash)
def getKeccak256(_nonce, _bid): result = w3.soliditySha3(['uint256', 'uint256'], [_nonce, _bid]) return result.hex()
if not taskid: raise ValueError('Missing TASKID') if not w3.isAddress(worker): raise ValueError('Invalid worker address') worker = w3.toChecksumAddress(worker) print("Genrating result and consensus.iexec in /iexec ...") shutil.copy("/app/result.txt", "/iexec/result.txt") shutil.copy("/app/result.txt", "/iexec/consensus.iexec") with open(keyfile) as f: private = f.read().splitlines()[0] digest = "0x" + fileChecksum("/iexec/consensus.iexec", "sha256") # hexstring hash = w3.soliditySha3(['bytes32', 'bytes32'], [taskid, digest]) seal = w3.soliditySha3(['address', 'bytes32', 'bytes32'], [worker, taskid, digest]) contrib = w3.soliditySha3(['bytes32', 'bytes32'], [hash, seal]) message = w3.soliditySha3(['bytes'], [b'\x19Ethereum Signed Message:\n32' + contrib]) signature = w3.eth.account.signHash(message, private) with open("/iexec/enclaveSig.iexec", 'w') as f: json.dump( { 'digest': digest, 'hash': w3.toHex(hash), 'seal': w3.toHex(seal), 'sign': { 'v': signature.v,
def hash(self): if self.prev_block != 0: ret = w3.sha3(rlp.encode(self, UnsignedTransaction)) else: ret = w3.soliditySha3(['uint64'], [self.uid]) return ret
def hashMessage(types, msg): msgHash = w3.soliditySha3(types, msg) return Web3.toHex(msgHash)