Created
April 19, 2018 02:01
-
-
Save backus/55b874940fe46f1e9847ff1b763d0424 to your computer and use it in GitHub Desktop.
Example #1 for "How to make a user friendly Ethereum dApp"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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