0

Goal (not asking XY question):

  • send ETH to an address
  • web3.js script monitoring it and acting upon transaction
  • if msg.value > 0.1 ether then...
  • ...encrypt a file with the public key of the msg.sender and publish to IPFS
  • only the original ETH sender (they have private key) can decrypt the file

Looking at the question: How are ethereum addresses generated?

  1. Start with the public key (128 characters / 64 bytes)

  2. Take the Keccak-256 hash of the public key. You should now have a string that is 64 characters / 32 bytes. (note: SHA3-256 eventually became the standard, but Ethereum uses Keccak)

  3. Take the last 40 characters / 20 bytes of this public key (Keccak-256). Or, in other words, drop the first 24 characters / 12 bytes. These 40 characters / 20 bytes are the address. When prefixed with 0x it becomes 42 characters long.

Public key to address is a one-way function, so how can we design the system to accomplish the goal?

1 Answer 1

4

Since you have a message (the transaction that send ether) and a signature (the signature of the transaction) you can recover the public key associated.

For example using this answer Get public key of any ethereum account, you can recover the public key given a message hash and the signature.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.