1

I have the below, trying to derive the Ethereum Address from public key (working) using keccak and to_checksum_address on eth_util, but doesn't match up with derivation on iancoleman.io or miguelmota.com


        # Derive the public key from the BIP32 extended key (working ✅)
        public_key_bytes = binascii.unhexlify(bip32_extended_key.PublicKey().hex())
    # Compute the Keccak-256 hash of the public key
    public_key_hash = keccak(public_key_bytes)

    # Take the last 20 bytes of the public key hash (the Ethereum address)
    address_bytes = public_key_hash[-20:]

    # Convert the address bytes to a hex string
    address_hex = address_bytes.hex()

    # Convert the hex address to a checksummed Ethereum address
    EthereumAddress = to_checksum_address('0x' + address_hex)

    if EthereumAddress == target_address:
        print("Seed phrase:", seed_phrase)
        print("Address:", target_address)
        print("Target address reached!")
        exit()
    else:
        print("Public key: ", public_key_bytes.hex())
        print("Ethereum address: ", EthereumAddress)

mull
  • 21
  • 4
  • I'd check the intermediate steps for some possible issues with mixing hex string with raw bytes and/or reversing the byte order. – Ismael Apr 20 '23 at 04:54
  • thank you @Ismael, seems you've already answered this 6 years ago here (https://ethereum.stackexchange.com/questions/29476/generating-an-address-from-a-public-key#comment31429_29480) hugely appreciated.

    In the process of attempting to cleanly deriving the public key in uncompressed format..

    – mull Apr 20 '23 at 10:03
  • Giving up on this for now, can't seem to find a way to derive an uncompressed public key from extended key needing 65 bytes instead of 33..'0x' instead of eg '02'.. – mull Apr 20 '23 at 13:35

0 Answers0