Skip to content

Instantly share code, notes, and snippets.

Created April 19, 2018 02:01
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Example #1 for "How to make a user friendly Ethereum dApp"
contract EthedIn {
// Digest describing the data the user signs.
// Needs to match what is passed to Metamask.
bytes32 public constant delegationHash =
keccak256("string Action", "address Address");
// Create account for a user using the signature they provided
// * Only approved transaction delegators are allowed to call this
// * _sender should be the address included in the signature as well
// as the address that would be submitting this transaction
// if it were not delegated
function createAccountFor(
bytes _delegationSig,
address _sender
) public onlyTxDelegator {
// Recreate the digest the user signed
bytes32 _delegationDigest =
keccak256(delegationHash, keccak256("Create Account", _sender));
// Recover the signer from the digest.
address _signer = recoverSigner(_delegationDigest, _delegationSig);
// Check that it matches the claimed sender
require(_sender == _signer);
// Call the actual create account function
// Actually create the account
function createAccountForUser(address _address) private { /* ... */ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment