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

webassembly

parent 975a0146
This source diff could not be displayed because it is too large. You can view the blob instead.
(async function () {
if (!WebAssembly.instantiateStreaming) {
WebAssembly.instantiateStreaming = async (resp, importObject) => {
const source = await (await resp).arrayBuffer();
return await WebAssembly.instantiate(source, importObject);
};
}
const schemes = await fetch("schemes.zip");
const schemesBuffer = await schemes.arrayBuffer();
const Buffer = BrowserFS.BFSRequire("buffer").Buffer;
BrowserFS.configure(
{
fs: "OverlayFS",
options: {
readable: {
fs: "MountableFileSystem",
options: {
"/irma_configuration": {
fs: "ZipFS",
options: {
zipData: Buffer.from(schemesBuffer),
},
},
},
},
writable: {
fs: "InMemory",
},
},
},
async (e) => {
if (e) throw e;
console.log("BrowserFS configured.");
const go = new Go();
const result = await WebAssembly.instantiateStreaming(
fetch("main_opt.wasm"),
go.importObject
);
go.run(result.instance).catch((e) => console.error(err));
}
);
})();
const zip = (a, b) => a.map((k, i) => [k, b[i]]);
//to test library integration was succesful
console.log(blockhashjs);
//post to verification backend
browser.runtime.onMessage.addListener(function(msg, sender, sendResponse){
......@@ -8,6 +6,8 @@ browser.runtime.onMessage.addListener(function(msg, sender, sendResponse){
if(msg.command == "verify"){
if(!verifySignature){return;}//function not ready yet
let keys = msg.signatures.map(entry=> entry[0]);
var values = msg.signatures.map(entry=>entry[1]);
let envelopes = msg.signatures.map(entry=>entry[2]);
......@@ -36,14 +36,16 @@ browser.runtime.onMessage.addListener(function(msg, sender, sendResponse){
//now verify all signatures (with the hashes in place of the message for image fragments)
Promise.all(values.map(signature =>
fetch('http://localhost:3000/verify', { method: 'POST', headers: {
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/json'
}, body: signature })
.then(resp => resp.text())
// fetch('http://localhost:3000/verify', { method: 'POST', headers: {
// 'Accept': 'application/json, text/plain, */*',
// 'Content-Type': 'application/json'
// }, body: signature })
verifySignature(JSON.parse(signature))
.then(resp => JSON.stringify(resp))
)).then(responses => {
handleValidationResults(msg, responses, keys, values, envelopes, tab_id);
}).catch(function(err) {
console.log(err);
browser.browserAction.setIcon({
tabId: tab_id, path: "icons/pop_certificate_server_error-48.png"
});
......@@ -67,6 +69,7 @@ function getBlockhash(url){
};
function handleValidationResults(msg, responses, keys, values, envelopes, tab_id){
console.log(responses);
//if all responses are VALID we show a green check mark
const valid = responses.every(function (response) {
return JSON.parse(response)["status"] == 'VALID';
......@@ -109,6 +112,10 @@ function handleValidationResults(msg, responses, keys, values, envelopes, tab_id
//toggle provenance view for current tab
function toggleProvenanceView(active_tab) {
//to see if function is available, works cool!
//console.log(verifySignature);
console.log("in toggle for tab " + active_tab.id);
let key1 = "pop_state_" + active_tab.id;
let key2 = "pop_toggle_" + active_tab.id;
......
......@@ -23,7 +23,7 @@
"run_at": "document_idle"
}],
"background": {
"scripts": ["zlib.js","blockhash.js","local_backend.js"]
"scripts": ["browserfs.min.js","wasm_exec.js","irmavf.js","zlib.js","blockhash.js","local_backend.js"]
},
"web_accessible_resources": ["icons/clippy.svg"]
"web_accessible_resources": ["main_opt.wasm","schemes.zip","icons/clippy.svg"]
}
This diff is collapsed.
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