Skip to content

Instantly share code, notes, and snippets.

@maheshmurthy
Last active April 15, 2018 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maheshmurthy/553ed55c6401cdaa4b2c63ee9d16edac to your computer and use it in GitHub Desktop.
Save maheshmurthy/553ed55c6401cdaa4b2c63ee9d16edac to your computer and use it in GitHub Desktop.
Ethereum Voting Dapp sign and verify
window.voteForCandidate = function(candidate) {
let candidateName = $("#candidate").val();
let msgParams = [
{
type: 'string', // Any valid solidity type
name: 'Message', // Any string label you want
value: 'Vote for ' + candidateName // The value to sign
}
]
var from = web3.eth.accounts[0]
var params = [msgParams, from]
var method = 'eth_signTypedData'
console.log("Hash is ");
console.log(sigUtil.typedSignatureHash(msgParams));
// Invoke the eth_signTypedData function and pass in the message and account address.
web3.currentProvider.sendAsync({
method,
params,
from,
}, function (err, result) {
if (err) return console.dir(err)
if (result.error) {
alert(result.error.message)
}
if (result.error) return console.error(result)
$("#msg").html("User intends to vote for " + candidateName + ". Any one can now submit the vote to the blockchain on behalf of this user. Copy the values");
$("#vote-for").html("Candidate: " + candidateName);
$("#addr").html("Address: " + from);
$("#signature").html("Signature: " + result.result);
console.log('PERSONAL SIGNED:' + JSON.stringify(result.result))
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment