Python eth_utils.decode_hex() Examples
The following are 30
code examples of eth_utils.decode_hex().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
eth_utils
, or try the search function
.
Example #1
Source File: initializer.py From trinity with MIT License | 6 votes |
def create_keypair_and_mock_withdraw_credentials( config: Eth2Config, key_set: Sequence[Dict[str, Any]] ) -> Tuple[Tuple[BLSPubkey, ...], Tuple[int, ...], Tuple[Hash32, ...]]: """ NOTE: this function mixes the parsing of keying material with the generation of derived values. Prefer other functions in this module that do the derivation directly. """ pubkeys: Tuple[BLSPubkey, ...] = () privkeys: Tuple[int, ...] = () withdrawal_credentials: Tuple[Hash32, ...] = () for key_pair in key_set: pubkey = BLSPubkey(decode_hex(key_pair["pubkey"])) privkey = int.from_bytes(decode_hex(key_pair["privkey"]), "big") withdrawal_credential = Hash32( config.BLS_WITHDRAWAL_PREFIX + hash_eth2(pubkey)[1:] ) pubkeys += (pubkey,) privkeys += (privkey,) withdrawal_credentials += (withdrawal_credential,) return (pubkeys, privkeys, withdrawal_credentials)
Example #2
Source File: configs.py From trinity with MIT License | 6 votes |
def _decoder( # NOTE: mypy incorrectly thinks `Field` is a generic type data: Dict[str, EncodedConfigTypes], fields: Collection[Field], # type: ignore ) -> Iterable[Tuple[str, ConfigTypes]]: # NOTE: this code is unwieldly but it satisfies `mypy` for field in fields: if field.type is Gwei: yield field.name, Gwei(cast(int, data[field.name])) elif field.type is Slot: yield field.name, Slot(cast(int, data[field.name])) elif field.type is Epoch: yield field.name, Epoch(cast(int, data[field.name])) elif field.type is Second: yield field.name, Second(cast(int, data[field.name])) elif field.type is bytes: yield field.name, decode_hex(cast(str, data[field.name])) else: yield field.name, int(data[field.name])
Example #3
Source File: test_sync.py From trinity with MIT License | 6 votes |
def test_beam_syncer_with_checkpoint( request, event_loop, event_bus, chaindb_fresh, chaindb_churner): checkpoint = Checkpoint( block_hash=decode_hex('0x5b8d32e4aebda3da7bdf2f0588cb42256e2ed0c268efec71b38278df8488a263'), score=55, ) await test_beam_syncer_loads_recent_state_root( request, event_loop, event_bus, chaindb_fresh, chaindb_churner, beam_to_block=66, checkpoint=checkpoint, )
Example #4
Source File: builder.py From trinity with MIT License | 6 votes |
def _delete_storage_twice(chain, contract_addr, nonce): # invoke function shuffle the storage, with a width of 64 # delete_twice(uint256) func_id = decode_hex("0x622ff59a") # width is how many different storage slots might be deletable width = b'\x40' # join call with parameters and pad: method_invocation = func_id + width.rjust(32, b'\0') tx = chain.create_unsigned_transaction( nonce=nonce, gas_price=1235, gas=123458, to=contract_addr, value=0, data=method_invocation, ) _, _, computation = chain.apply_transaction(tx.as_signed_transaction(FUNDED_ACCT)) computation.raise_if_error()
Example #5
Source File: builder.py From trinity with MIT License | 6 votes |
def churn_storage_once(chain, contract_addr, nonce): # invoke function shuffle the storage, with a width of 64 # shuffle(uint256) func_id = decode_hex("0xef6537b5") # width is how many different storage slots to fill before wrapping width = b'\x40' # join call with parameters and pad: method_invocation = func_id + width.rjust(32, b'\0') tx = chain.create_unsigned_transaction( nonce=nonce, gas_price=1234, gas=300000, to=contract_addr, value=0, data=method_invocation, ) _, _, computation = chain.apply_transaction(tx.as_signed_transaction(FUNDED_ACCT)) computation.raise_if_error()
Example #6
Source File: yaml_test_execution.py From py-ssz with MIT License | 6 votes |
def execute_invalid_ssz_test(test_case, sedes): if "value" in test_case and "ssz" in test_case: raise ValueError("Test case for invalid inputs contains both value and ssz") if "value" in test_case: value = from_formatted_dict(test_case["value"], sedes, CustomCodec) try: ssz.encode(value, sedes) except SSZException: pass else: raise FailedTestCase("Serializing invalid value did not yield an exception") elif "ssz" in test_case: serial = decode_hex(test_case["ssz"]) try: ssz.decode(serial, sedes) except SSZException: pass else: raise FailedTestCase("Deserializing invalid SSZ did not yield an exception") else: raise ValueError("Test case for invalid inputs contains neither value nor ssz")
Example #7
Source File: yaml_test_execution.py From py-ssz with MIT License | 6 votes |
def execute_valid_ssz_test(test_case, sedes): value = from_formatted_dict(test_case["value"], sedes, CustomCodec) serial = decode_hex(test_case["ssz"]) try: decoded = ssz.decode(serial, sedes) except SSZException: raise FailedTestCase("Deserializing valid SSZ failed") else: if decoded != value: raise FailedTestCase(f"Deserializing SSZ returned wrong result {decoded}") try: encoded = ssz.encode(value, sedes) except SSZException: raise FailedTestCase("Serializing valid value failed") else: if encoded != serial: raise FailedTestCase(f"Serializing value retunred wrong result {encoded}")
Example #8
Source File: test_handlers.py From raiden-services with MIT License | 6 votes |
def test_mr_with_unknown_signatures(context: Context): """ The signatures are valid but don't belong to the participants. """ context = setup_state_with_closed_channel(context) def assert_mr_is_ignored(mr): context.database.upsert_monitor_request(mr) event = ActionMonitoringTriggeredEvent( token_network_address=DEFAULT_TOKEN_NETWORK_ADDRESS, channel_identifier=DEFAULT_CHANNEL_IDENTIFIER, non_closing_participant=DEFAULT_PARTICIPANT2, ) action_monitoring_triggered_event_handler(event, context) assert not context.monitoring_service_contract.functions.monitor.called assert_mr_is_ignored( create_signed_monitor_request(closing_privkey=PrivateKey(decode_hex(get_random_privkey()))) ) assert_mr_is_ignored( create_signed_monitor_request( nonclosing_privkey=PrivateKey(decode_hex(get_random_privkey())) ) )
Example #9
Source File: test_sync.py From trinity with MIT License | 5 votes |
def test_beam_syncer_with_checkpoint_too_close_to_tip( caplog, request, event_loop, event_bus, chaindb_fresh, chaindb_churner): checkpoint = Checkpoint( block_hash=decode_hex('0x814aca8a5855f216fee0f627945f70b3c019ae2c8b3aeb528ea7049ed83cfc82'), score=645, ) caplog.set_level(logging.INFO) try: await test_beam_syncer_loads_recent_state_root( request, event_loop, event_bus, chaindb_fresh, chaindb_churner, beam_to_block=66, checkpoint=checkpoint, ) except asyncio.TimeoutError: # Beam syncer timing out and printing an info to the user is the expected behavior. # Our checkpoint is right before the tip and the chain doesn't advance forward. assert "Checkpoint is too near" in caplog.text
Example #10
Source File: validator.py From trinity with MIT License | 5 votes |
def _get_validator_duties(context: Context, request: Request) -> Response: if not isinstance(request, dict): return () if "validator_pubkeys" not in request: return () public_keys = tuple(map(decode_hex, request["validator_pubkeys"].split(","))) epoch = Epoch(int(request["epoch"])) duties = context.get_validator_duties(public_keys, epoch) return tuple(map(_marshal_duty, duties))
Example #11
Source File: test_ecies.py From pyquarkchain with MIT License | 5 votes |
def test_decrypt_known_good_handshake(): # Data taken from https://gist.github.com/fjl/3a78780d17c755d22df2 privkey = keys.PrivateKey( decode_hex("c45f950382d542169ea207959ee0220ec1491755abe405cd7498d6b16adb6df8") ) auth_ciphertext = decode_hex( "04a0274c5951e32132e7f088c9bdfdc76c9d91f0dc6078e848f8e3361193dbdc43b94351ea3d89e4ff33ddcefbc80070498824857f499656c4f79bbd97b6c51a514251d69fd1785ef8764bd1d262a883f780964cce6a14ff206daf1206aa073a2d35ce2697ebf3514225bef186631b2fd2316a4b7bcdefec8d75a1025ba2c5404a34e7795e1dd4bc01c6113ece07b0df13b69d3ba654a36e35e69ff9d482d88d2f0228e7d96fe11dccbb465a1831c7d4ad3a026924b182fc2bdfe016a6944312021da5cc459713b13b86a686cf34d6fe6615020e4acf26bf0d5b7579ba813e7723eb95b3cef9942f01a58bd61baee7c9bdd438956b426a4ffe238e61746a8c93d5e10680617c82e48d706ac4953f5e1c4c4f7d013c87d34a06626f498f34576dc017fdd3d581e83cfd26cf125b6d2bda1f1d56" ) # noqa: E501 auth_plaintext = decode_hex( "884c36f7ae6b406637c1f61b2f57e1d2cab813d24c6559aaf843c3f48962f32f46662c066d39669b7b2e3ba14781477417600e7728399278b1b5d801a519aa570034fdb5419558137e0d44cd13d319afe5629eeccb47fd9dfe55cc6089426e46cc762dd8a0636e07a54b31169eba0c7a20a1ac1ef68596f1f283b5c676bae4064abfcce24799d09f67e392632d3ffdc12e3d6430dcb0ea19c318343ffa7aae74d4cd26fecb93657d1cd9e9eaf4f8be720b56dd1d39f190c4e1c6b7ec66f077bb1100" ) # noqa: E501 decrypted = ecies.decrypt(auth_ciphertext, privkey) assert auth_plaintext == decrypted
Example #12
Source File: test_discovery.py From pyquarkchain with MIT License | 5 votes |
def test_v5_handlers(monkeypatch): # Ensure we dispatch v5 messages to the appropriate handlers. # These are hex-encoded messages sent by geth over the wire, obtained via wireshark using the # ethereum dissectors (https://github.com/ConsenSys/ethereum-dissectors). qkc_hex = "qkc1 topic discovery".encode().hex() v5_handlers = dict( recv_topic_register=qkc_hex + "4b1f9f999e3cf283e42270742eb3b52b1c0b63ede116ea58632517ffccc7516c794f6fc20f199b3a3a887f3e961b453bb9213eebad4581aaf9b2a60da7e5ba7b0106e2da954c455332406434653536373430663837366165663883666f6f8204d283666f6f", # noqa: E501 recv_pong_v5=qkc_hex + "6cb538da9382c022cc6d9b860b7cc7660718c731e1e6331de86a7cabfba8f01c061b5d6c09dd84de1d6c653536bb8ad31fb140d55d317dfaea5225a6907f49450102f855cb84a5a587f2827660827660a0b484b40a3712766dbbe8498f110bab968a543f9d0d57ec4cfa3b38b32ef2f237831f5ca3a0bd1ea218eaf7cddc6b068a414ae08876315f92bd134e214d5f3961d1a3e8e35b4ec13c", # noqa: E501 recv_ping_v5=qkc_hex + "c26911f1d2a320f17fa683397028e6cc7ebe114623e28e933d870634aa6050f45960679170192ec0f133dbc3f4e627eef468dbdb48bf4a7848412938da21be8a0001f84104d79000000000000000000000000000000000827660827660cb84b0201d9282848b82848b845b7e5593d6954c4553324064346535363734306638373661656638", # noqa: E501 recv_find_nodehash=qkc_hex + "58dc895847c5d2cc9ab6f722f25b9ff1b9c188af6ff7ed7c716a3cde2e93f3ec1e2b897acb1a33aa1d345c72ea34912287b21480c80ef99241d4bd9fd53711ee0105e6a038f7bb96e94bcd39866baa56038367ad6145de1ee8f4a8b0993ebdf8883a0ad8845b7e5593", # noqa: E501 recv_topic_query=qkc_hex + "308621f1ed59a67613da52da3f84bac3d927d0dc1650b27552b10a0a823fb2133cebf3680f68bf88457bb0c07787031357430985d03afa1af0574e8ef0eab7fc0007d7954c455332406434653536373430663837366165663880", # noqa: E501 recv_topic_nodes=qkc_hex + "e33166b59d20f206f0df2502be59186cb971c76ee91dba94ea9b1bbeb1308a5f4efbdf945ead9ba89d7c2c55d5d841dacdef69a455c98e1a5415e489508afa450008f87ea0cff0456ecbf2e6b0a40bc6541bd209c60ced192509470b405c256a17443674b3f85bf8599000000000000000000000ffff904c1f9c82765f82765fb840e7d624c642b86d3d48cea3e395305345c3a0226fc4c2dfdfbeb94cb6891e5e72b4467c69684ac14b072d2e4fa9c7a731cc1fdf0283abe41186d00b4c879f80ed", # noqa: E501 recv_neighbours_v5=qkc_hex + "8f6671ae9611c82c9cb04538aeed13a8b4e8eb8ad0d0dbba4b161ded52b195846c6086a0d42eef44cfcc0b793a0b9420613727958a8956139c127810b94d4e830004f90174f9016cf8599000000000000000000000ffff59401a22826597826597b840d723e264da67820fb0cedb0d03d5d975cc82bffdadd2879f3e5fa58b5525de5fdd0b90002bba44ac9232247dfbccb2a730e5ea98201bab1f1fe72422aa58143ff8599000000000000000000000ffffae6c601a82765f82765fb840779f19056e0a0486c3f6838896a931bf920cd8f551f664022a50690d4cca4730b50a97058aac11a5aa0cc55db6f9207e12a9cd389269f414a98e5b6a2f6c9f89f8599000000000000000000000ffff287603df827663827663b84085c85d7143ae8bb96924f2b54f1b3e70d8c4d367af305325d30a61385a432f247d2c75c45c6b4a60335060d072d7f5b35dd1d4c45f76941f62a4f83b6e75daaff8599000000000000000000000ffff0d4231b0820419820419b8407b46cc366b6cbaec088a7d15688a2c12bb8ba4cf7ee8e01b22ab534829f9ff13f7cc4130f10a4021f7d77e9b9c80a9777f5ddc035efb130fe3b6786434367973845b7e5569", # noqa: E501 ) proto = get_discovery_protocol() addr = random_address() for handler, msg in v5_handlers.items(): mock_handler = MockHandler() monkeypatch.setattr(proto, handler, mock_handler) proto.datagram_received(decode_hex(msg), (addr.ip, addr.udp_port)) assert mock_handler.called
Example #13
Source File: bls.py From trinity with MIT License | 5 votes |
def get_input_verify(test_case: Dict[str, Any]) -> SignatureData: return { "pubkey": BLSPubkey(decode_hex(test_case["input"]["pubkey"])), "message": decode_hex(test_case["input"]["message"]), "signature": BLSSignature(decode_hex(test_case["input"]["signature"])), }
Example #14
Source File: kademlia.py From pyquarkchain with MIT License | 5 votes |
def from_uri(cls, uri: str) -> "Node": parsed = urlparse.urlparse(uri) pubkey = keys.PublicKey(decode_hex(parsed.username)) return cls(pubkey, Address(parsed.hostname, parsed.port))
Example #15
Source File: initializer.py From trinity with MIT License | 5 votes |
def load_genesis_key_map( encoded_key_map: Tuple[Dict[str, Any]], public_key_codec: Callable[[str], BLSPubkey] = lambda key: BLSPubkey( decode_hex(key) ), private_key_codec: Callable[[str], int] = _decode_private_key_from_hex, ) -> Iterable[Tuple[BLSPubkey, int]]: for key_pair in encoded_key_map: public_key = public_key_codec(key_pair["public_key"]) private_key = private_key_codec(key_pair["private_key"]) yield public_key, private_key
Example #16
Source File: initializer.py From trinity with MIT License | 5 votes |
def _decode_private_key_from_hex(encoded_private_key: str) -> int: return int.from_bytes(decode_hex(encoded_private_key), "little")
Example #17
Source File: bls.py From trinity with MIT License | 5 votes |
def get_output_bls_signature(test_case: Dict[str, Any]) -> BLSSignature: output = test_case["output"] if output: return BLSSignature(decode_hex(test_case["output"])) else: return BLSSignature(b"\x00")
Example #18
Source File: bls.py From trinity with MIT License | 5 votes |
def get_input_sign(test_case: Dict[str, Any]) -> Dict[str, Union[int, bytes]]: return { "privkey": int.from_bytes(decode_hex(test_case["input"]["privkey"]), "big"), "message": decode_hex(test_case["input"]["message"]), }
Example #19
Source File: bls.py From trinity with MIT License | 5 votes |
def get_input_fast_aggregate_verify(test_case: Dict[str, Any]) -> Dict[str, Any]: pubkeys = tuple( BLSPubkey(decode_hex(item)) for item in test_case["input"]["pubkeys"] ) return { "pubkeys": pubkeys, "message": decode_hex(test_case["input"]["message"]), "signature": BLSSignature(decode_hex(test_case["input"]["signature"])), }
Example #20
Source File: builder.py From trinity with MIT License | 5 votes |
def _delete_nymph(chain, contract_addr, nonce): # invoke function shuffle the storage, with a width of 64 # poof() func_id = decode_hex("0x5969aa84") tx = chain.create_unsigned_transaction( nonce=nonce, gas_price=1235, gas=123459, to=contract_addr, value=0, data=func_id, ) _, _, computation = chain.apply_transaction(tx.as_signed_transaction(FUNDED_ACCT)) computation.raise_if_error()
Example #21
Source File: test_ecies.py From pyquarkchain with MIT License | 5 votes |
def test_ecdh(privkey_hex, pubkey_hex, ecdh_expected): privkey = keys.PrivateKey(decode_hex(privkey_hex)) pubkey = keys.PublicKey(decode_hex(pubkey_hex)) assert ecdh_expected == encode_hex(ecies.ecdh_agree(privkey, pubkey)) # FIXME: Document those values; this test was lifted from pydevp2p: # https://github.com/ethereum/pydevp2p/blob/e1ef07a782b9369d18a8441c3b9bcf12456e0608/devp2p/tests/test_ecies.py#L31
Example #22
Source File: test_ecies.py From pyquarkchain with MIT License | 5 votes |
def test_kdf(): input_ = decode_hex( "0x961c065873443014e0371f1ed656c586c6730bf927415757f389d92acf8268df" ) expected_key = decode_hex( "0x4050c52e6d9c08755e5a818ac66fabe478b825b1836fd5efc4d44e40d04dabcc" ) key = ecies.kdf(input_) assert key == expected_key
Example #23
Source File: builder.py From trinity with MIT License | 5 votes |
def deploy_storage_churn_contract(chain, nonce=0): deploy_tx = chain.create_unsigned_transaction( nonce=nonce, gas_price=1234, gas=3000000, to=b'', value=0, data=decode_hex("608060405234801561001057600080fd5b50600160008080815260200190815260200160002081905550610336806100386000396000f3fe608060405234801561001057600080fd5b506004361061004c5760003560e01c80634903b0d114610051578063622ff59a14610093578063adbd8315146100c1578063ef6537b5146100ef575b600080fd5b61007d6004803603602081101561006757600080fd5b810190808035906020019092919050505061011d565b6040518082815260200191505060405180910390f35b6100bf600480360360208110156100a957600080fd5b8101908080359060200190929190505050610135565b005b6100ed600480360360208110156100d757600080fd5b810190808035906020019092919050505061020e565b005b61011b6004803603602081101561010557600080fd5b8101908080359060200190929190505050610265565b005b60006020528060005260406000206000915090505481565b3073ffffffffffffffffffffffffffffffffffffffff1663adbd8315826040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b15801561018857600080fd5b505af115801561019c573d6000803e3d6000fd5b505050503073ffffffffffffffffffffffffffffffffffffffff1663adbd8315826040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b1580156101f357600080fd5b505af1158015610207573d6000803e3d6000fd5b5050505050565b60008090505b81811015610260576000806000838152602001908152602001600020541115610253576000808281526020019081526020016000206000905550610262565b8080600101915050610214565b505b50565b60008090505b818110156102e457600160008083815260200190815260200160002054036000806001840181526020019081526020016000205414156102d757600080828152602001908152602001600020546000806001840181526020019081526020016000208190555050610307565b808060010191505061026b565b506001600080808152602001908152602001600020600082825401925050819055505b5056fea165627a7a72305820dba28f294357644493dce42aff2ea2bf5f72e20dcb00a6ed4094dd313bf8f5220029"), # noqa: E501 ) chain.apply_transaction(deploy_tx.as_signed_transaction(FUNDED_ACCT)) chain.mine_block() return generate_contract_address(FUNDED_ACCT.public_key.to_canonical_address(), nonce)
Example #24
Source File: component.py From trinity with MIT License | 5 votes |
def get_local_private_key(boot_info: BootInfo) -> PrivateKey: if boot_info.args.discovery_private_key: local_private_key_bytes = decode_hex(boot_info.args.discovery_private_key) return PrivateKey(local_private_key_bytes) else: return boot_info.trinity_config.nodekey
Example #25
Source File: validator_api.py From trinity with MIT License | 5 votes |
def _get_block_proposal(self, request: web.Request) -> web.Response: slot = Slot(int(request.query["slot"])) randao_reveal = BLSSignature( decode_hex(request.query["randao_reveal"]).ljust(96, b"\x00") ) block = BeaconBlock.create( slot=slot, body=BeaconBlockBody.create(randao_reveal=randao_reveal) ) return web.json_response(to_formatted_dict(block))
Example #26
Source File: validator_api.py From trinity with MIT License | 5 votes |
def _get_validator_duties(self, request: web.Request) -> web.Response: public_keys = tuple( map(decode_hex, request.query["validator_pubkeys"].split(",")) ) # epoch = Epoch(request.query["epoch"]) duties = tuple( { "validator_pubkey": encode_hex(public_key), "attestation_slot": 2222, "attestation_shard": 22, "block_proposal_slot": 90, } for public_key in public_keys ) return web.json_response(duties)
Example #27
Source File: beacon.py From trinity with MIT License | 5 votes |
def state(self, request: web.Request) -> Dict[str, Any]: if 'slot' in request.query: slot = Slot(int(request.query['slot'])) state = self.chain.get_state_by_slot(slot) elif 'root' in request.query: root = cast(Root, decode_hex(request.query['root'])) state = self.chain.get_state_by_root(root) else: raise APIServerError(f"Wrong querystring: {request.query}") return to_formatted_dict(state)
Example #28
Source File: beacon.py From trinity with MIT License | 5 votes |
def block(self, request: web.Request) -> Dict[str, Any]: if 'slot' in request.query: slot = Slot(int(request.query['slot'])) block = self.chain.get_canonical_block_by_slot(slot) elif 'root' in request.query: root = cast(Root, decode_hex(request.query['root'])) block = self.chain.get_block_by_root(root) return to_formatted_dict(block, sedes=BeaconBlock)
Example #29
Source File: sloader.py From shadowlands with MIT License | 5 votes |
def register_package(self, checksum, url): fn = self.functions.registerPackage(decode_hex(checksum.strip()), url.strip()) return fn
Example #30
Source File: key_store.py From trinity with MIT License | 5 votes |
def _load_key_file(self, key_file: Path) -> Tuple[BLSPubkey, BLSPrivateKey, str]: with open(key_file) as key_file_handle: keyfile_json = json.load(key_file_handle) public_key = BLSPubkey(decode_hex(keyfile_json["public_key"])) password = self._password_provider(public_key) try: private_key = eth_keyfile.decode_keyfile_json(keyfile_json, password) except ValueError: self.logger.error( "password was incorrect for public key %s", encode_hex(public_key) ) raise return (public_key, private_key, keyfile_json["id"])