Skip to content

Instantly share code, notes, and snippets.

@backus
Created April 19, 2018 02:01
Show Gist options
  • Save backus/55b874940fe46f1e9847ff1b763d0424 to your computer and use it in GitHub Desktop.
Save backus/55b874940fe46f1e9847ff1b763d0424 to your computer and use it in GitHub Desktop.
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
createAccountForUser(_sender);
}
// 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