Created
March 13, 2017 19:35
-
-
Save AlwaysBCoding/be7d7c3f2d57bfc472ff89d2686d8e27 to your computer and use it in GitHub Desktop.
Ethereum Ðapp Development - Video 19 | Implementing an Authentication Scheme
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
<h1>Example Text</h1> | |
<script> | |
var message = "DecypherTV"; | |
var userEthereumClient; | |
window.addEventListener("load", function() { | |
userEthereumClient = window.web3; | |
}) | |
document.querySelector("h1").addEventListener("click", function(event) { | |
userEthereumClient.eth.sign(userEthereumClient.eth.coinbase, window.web3.sha3(message), function(error, data) { | |
var signedAuthMessage = data; | |
document.cookie = "signedAuthMessage=" + signedAuthMessage; | |
}) | |
}) | |
// Require EthUtil NPM Module | |
var sigDecoded = EthUtil.fromRPCSig(signedAuthMessage); | |
var recoveredPub = EthUtil.ecrecover(window.web3.sha3(message), sigDecoded.v, sigDecoded.r, sigDecoded.s); | |
var recoveredAddress = EthUtil.pubToAddress(recoveredPub).toString("hex"); | |
// Authentication Logic (user is logged in?) | |
userEthereumClient.eth.coinbase === recoveredAddress; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment