6664a129b0
WHAT: all needed methods added to webworker WHY: to generate correct access grant Change-Id: I700f24840d5bbe1515dbafa7f4e71e505205f903
43 lines
1.3 KiB
JavaScript
43 lines
1.3 KiB
JavaScript
// Copyright (C) 2020 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
importScripts('/static/static/wasm/wasm_exec.js')
|
|
|
|
if (!WebAssembly.instantiate) {
|
|
self.postMessage(new Error('web assembly is not supported'));
|
|
}
|
|
|
|
const go = new Go();
|
|
const instantiateStreaming = WebAssembly.instantiateStreaming || async function (resp, importObject) {
|
|
const response = await resp;
|
|
const source = await response.arrayBuffer();
|
|
|
|
return await WebAssembly.instantiate(source, importObject);
|
|
};
|
|
const response = fetch('/static/static/wasm/access.wasm');
|
|
instantiateStreaming(response, go.importObject).then(result => go.run(result.instance)).catch(err => self.postMessage(new Error(err.message)));
|
|
|
|
self.onmessage = function (event) {
|
|
const type = event.data.type;
|
|
let result;
|
|
switch (type) {
|
|
case 'GenerateAccess':
|
|
result = self.generateAccessGrant();
|
|
|
|
self.postMessage(result);
|
|
break;
|
|
case 'NewPermission':
|
|
result = self.newPermission();
|
|
|
|
self.postMessage(result);
|
|
break;
|
|
case 'SetPermission':
|
|
result = self.setAPIKeyPermission();
|
|
|
|
self.postMessage(result);
|
|
break;
|
|
default:
|
|
self.postMessage(new Error('provided message event type is not supported'));
|
|
}
|
|
};
|