Created
June 6, 2019 17:39
-
-
Save rpaskin/a3a79eb0620b5f704433c56c31b75c91 to your computer and use it in GitHub Desktop.
We can use the following code on Opera Android to get a file, hash it, then sign the hash with the local Ethereum Account
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Test Opera</title> | |
<script src="//cdn.jsdelivr.net/gh/ethereum/[email protected]/dist/web3.min.js" type="text/javascript"></script> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/js-sha3/0.8.0/sha3.min.js" type="text/javascript"></script> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/zepto/1.2.0/zepto.min.js" type="text/javascript" charset="utf-8"></script> | |
<script type="text/javascript"> | |
const web3 = new Web3(ethereum); | |
const storage = window.localStorage; | |
var myAccount; | |
</script> | |
</head> | |
<body> | |
<form action="submit" method="get" accept-charset="utf-8" onsubmit="return false;"> | |
<input type="text" id="myAccount" name="myAccount" value="" placeholder="myAccount"> | |
<input type="text" id="signed" name="signed" value="" placeholder="signed package"> | |
<input type="file" onchange="hashFile(this)" id="my_document" multipe=false class="inputfile"> | |
</form> | |
<script type="text/javascript"> | |
$( document ).ready(function() { | |
web3.eth.getAccounts().then((accounts) => { myAccount = accounts[0]; $("#myAccount").val(myAccount); }); | |
}); | |
function hashFile(el) { | |
var fr = new FileReader(); | |
fr.onload = function (ev) { | |
var data = ev.srcElement.result; | |
web3.eth.personal.sign(keccak256(data), myAccount, (err, signed) => { | |
console.log(31, err, signed); | |
$("#signed").val(signed); | |
}); | |
}; | |
fr.readAsArrayBuffer(el.files[0]); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment