Commit 956fb1df authored by taco@waag.org's avatar taco@waag.org
Browse files

added blockhash to signing example

parent 17a60288
This diff is collapsed.
......@@ -7,8 +7,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="UTF-8">
<script type="text/javascript" src="irma.js"></script>
<script type="text/javascript" src="blockhash.js"></script>
<script type="text/javascript" src="pop.js"></script>
<style>
html, body {
margin: 10px 0;
......@@ -30,9 +30,16 @@
</head>
<body>
<h3>sign text</h3>
<textarea id="message" rows="5" cols="80">Replace this with your <b>own</b> text!</textarea>
<button id="start-popup">Sign message</button>
<textarea id="result" rows="5" cols="80"></textarea>
<h3>sign image</h3>
<textarea id="imageurl" rows="5" cols="80">https://snotolf.waag.org/waag/sites/waag/files/2021-03/29031756258_3d2cb5e695_b.jpeg</textarea>
<button id="start-popup-image">Sign image hash</button>
<textarea id="result-image" rows="5" cols="80"></textarea>
</body>
<script type="text/javascript">
......@@ -57,6 +64,37 @@
console.error("Couldn't do what you asked 😢", error);
})
};
//sign the hash of an image
document.getElementById('start-popup-image').onclick = () => {
//1. calculate hash using pop library function
let url = document.getElementById("imageurl").value;
//NB a CORS error can be thrown,
//make sure the url that points to the image is on a server that serves correct CORS headers
pop_imagehash(url,function(err,hash){
if(hash){
document.getElementById("imageurl").value = hash;
//2. sign the hash
pop_sign("https://pop.waag.org",
"pbdf.sidn-pbdf.email.email",
hash)
.then( result =>{
//3. show the result
document.getElementById("result-image").value = result;
}).catch(error => {
if (error === 'Aborted') {
console.log('We closed it ourselves, so no problem 😅');
return;
}
console.error("Couldn't do what you asked 😢", error);
});
} else {
document.getElementById("imageurl").value = err;
}
})
};
</script>
</html>
......@@ -7,6 +7,12 @@ function pop_normalize(raw){
return text;
}
//perform perceptual image hash on url specified in image, specify callback with signature (err,hash)
function pop_imagehash(url,callback){
var blockhash = blockhashjs.blockhash;
return blockhash(url,16,2,callback);
}
//calls irma server specified in url
//to sign the message, using the (disclosed) attribute name
function pop_sign(url, attribute, message){
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment