2020-11-10 17:00:00 +00:00
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2021-08-02 19:17:49 +01:00
|
|
|
/* eslint-disable */
|
|
|
|
|
2020-11-10 17:00:00 +00:00
|
|
|
importScripts('/static/static/wasm/wasm_exec.js')
|
|
|
|
|
|
|
|
if (!WebAssembly.instantiate) {
|
|
|
|
self.postMessage(new Error('web assembly is not supported'));
|
|
|
|
}
|
|
|
|
|
2021-10-06 17:35:33 +01:00
|
|
|
self.onmessage = async function (event) {
|
2020-11-17 20:22:14 +00:00
|
|
|
const data = event.data;
|
2020-11-16 20:06:41 +00:00
|
|
|
let result;
|
2020-11-18 20:12:59 +00:00
|
|
|
let apiKey;
|
2020-11-17 20:22:14 +00:00
|
|
|
switch (data.type) {
|
2021-10-06 17:35:33 +01:00
|
|
|
case 'Setup':
|
|
|
|
try {
|
|
|
|
const go = new Go();
|
|
|
|
const response = await fetch('/static/static/wasm/access.wasm')
|
|
|
|
const buffer = await response.arrayBuffer();
|
|
|
|
const module = await WebAssembly.compile(buffer);
|
|
|
|
const instance = await WebAssembly.instantiate(module, go.importObject);
|
|
|
|
|
|
|
|
go.run(instance)
|
|
|
|
|
|
|
|
self.postMessage('configured');
|
|
|
|
} catch (e) {
|
|
|
|
self.postMessage(new Error(e.message))
|
|
|
|
}
|
|
|
|
|
2022-02-14 20:06:35 +00:00
|
|
|
break;
|
|
|
|
case 'DeriveAndEncryptRootKey':
|
|
|
|
{
|
|
|
|
const passphrase = data.passphrase;
|
|
|
|
const projectID = data.projectID;
|
|
|
|
const aesKey = data.aesKey;
|
|
|
|
|
|
|
|
result = self.deriveAndEncryptRootKey(passphrase, projectID, aesKey);
|
|
|
|
self.postMessage(result);
|
|
|
|
}
|
2021-10-06 17:35:33 +01:00
|
|
|
break;
|
2020-11-10 17:00:00 +00:00
|
|
|
case 'GenerateAccess':
|
2020-11-18 20:12:59 +00:00
|
|
|
apiKey = data.apiKey;
|
|
|
|
const passphrase = data.passphrase;
|
|
|
|
const projectID = data.projectID;
|
2020-12-23 04:24:37 +00:00
|
|
|
const nodeURL = data.satelliteNodeURL;
|
2020-11-18 20:12:59 +00:00
|
|
|
|
|
|
|
result = self.generateAccessGrant(nodeURL, apiKey, passphrase, projectID);
|
2020-11-16 20:06:41 +00:00
|
|
|
|
|
|
|
self.postMessage(result);
|
|
|
|
break;
|
2021-03-25 22:57:25 +00:00
|
|
|
case 'SetPermission': // fallthrough
|
|
|
|
case 'RestrictGrant':
|
2020-11-17 20:22:14 +00:00
|
|
|
const isDownload = data.isDownload;
|
|
|
|
const isUpload = data.isUpload;
|
|
|
|
const isList = data.isList;
|
|
|
|
const isDelete = data.isDelete;
|
2020-11-24 20:51:36 +00:00
|
|
|
const notBefore = data.notBefore;
|
|
|
|
const notAfter = data.notAfter;
|
2020-11-17 20:22:14 +00:00
|
|
|
|
|
|
|
let permission = self.newPermission().value;
|
|
|
|
|
|
|
|
permission.AllowDownload = isDownload;
|
|
|
|
permission.AllowUpload = isUpload;
|
|
|
|
permission.AllowDelete = isDelete;
|
|
|
|
permission.AllowList = isList;
|
2021-04-28 13:47:35 +01:00
|
|
|
|
|
|
|
if (notBefore) permission.NotBefore = notBefore;
|
|
|
|
if (notAfter) permission.NotAfter = notAfter;
|
2020-11-17 20:22:14 +00:00
|
|
|
|
2021-03-23 20:50:34 +00:00
|
|
|
if (data.type === "SetPermission") {
|
2021-03-25 22:57:25 +00:00
|
|
|
const buckets = data.buckets;
|
|
|
|
apiKey = data.apiKey;
|
|
|
|
result = self.setAPIKeyPermission(apiKey, buckets, permission);
|
|
|
|
} else {
|
|
|
|
const paths = data.paths;
|
|
|
|
const accessGrant = data.grant;
|
|
|
|
result = self.restrictGrant(accessGrant, paths, permission);
|
|
|
|
}
|
2020-11-10 17:00:00 +00:00
|
|
|
|
|
|
|
self.postMessage(result);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
self.postMessage(new Error('provided message event type is not supported'));
|
|
|
|
}
|
|
|
|
};
|