Support encrypt, decrypt & verify + add dark theme + better error handling & UI enhancements

This commit is contained in:
zaelgohary
2025-05-28 09:49:23 +03:00
parent 5bc205b2f7
commit 37764e3861
7 changed files with 1893 additions and 548 deletions

View File

@@ -202,33 +202,6 @@ function debugString(val) {
// TODO we could test for more things here, like `Set`s and `Map`s.
return className;
}
/**
* Initialize the scripting environment (must be called before run_rhai)
*/
export function init_rhai_env() {
wasm.init_rhai_env();
}
function takeFromExternrefTable0(idx) {
const value = wasm.__wbindgen_export_2.get(idx);
wasm.__externref_table_dealloc(idx);
return value;
}
/**
* Securely run a Rhai script in the extension context (must be called only after user approval)
* @param {string} script
* @returns {any}
*/
export function run_rhai(script) {
const ptr0 = passStringToWasm0(script, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
const ret = wasm.run_rhai(ptr0, len0);
if (ret[2]) {
throw takeFromExternrefTable0(ret[1]);
}
return takeFromExternrefTable0(ret[0]);
}
/**
* Create and unlock a new keyspace with the given name and password
* @param {string} keyspace
@@ -266,6 +239,11 @@ export function lock_session() {
wasm.lock_session();
}
function takeFromExternrefTable0(idx) {
const value = wasm.__wbindgen_export_2.get(idx);
wasm.__externref_table_dealloc(idx);
return value;
}
/**
* Get metadata of the currently selected keypair
* @returns {any}
@@ -356,20 +334,81 @@ export function sign(message) {
return ret;
}
/**
* Verify a signature with the current session's selected keypair
* @param {Uint8Array} message
* @param {string} signature
* @returns {Promise<any>}
*/
export function verify(message, signature) {
const ptr0 = passArray8ToWasm0(message, wasm.__wbindgen_malloc);
const len0 = WASM_VECTOR_LEN;
const ptr1 = passStringToWasm0(signature, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len1 = WASM_VECTOR_LEN;
const ret = wasm.verify(ptr0, len0, ptr1, len1);
return ret;
}
/**
* Encrypt data using the current session's keyspace symmetric cipher
* @param {Uint8Array} data
* @returns {Promise<any>}
*/
export function encrypt_data(data) {
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
const len0 = WASM_VECTOR_LEN;
const ret = wasm.encrypt_data(ptr0, len0);
return ret;
}
/**
* Decrypt data using the current session's keyspace symmetric cipher
* @param {Uint8Array} encrypted
* @returns {Promise<any>}
*/
export function decrypt_data(encrypted) {
const ptr0 = passArray8ToWasm0(encrypted, wasm.__wbindgen_malloc);
const len0 = WASM_VECTOR_LEN;
const ret = wasm.decrypt_data(ptr0, len0);
return ret;
}
/**
* Initialize the scripting environment (must be called before run_rhai)
*/
export function init_rhai_env() {
wasm.init_rhai_env();
}
/**
* Securely run a Rhai script in the extension context (must be called only after user approval)
* @param {string} script
* @returns {any}
*/
export function run_rhai(script) {
const ptr0 = passStringToWasm0(script, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
const ret = wasm.run_rhai(ptr0, len0);
if (ret[2]) {
throw takeFromExternrefTable0(ret[1]);
}
return takeFromExternrefTable0(ret[0]);
}
function __wbg_adapter_32(arg0, arg1, arg2) {
wasm.closure89_externref_shim(arg0, arg1, arg2);
wasm.closure121_externref_shim(arg0, arg1, arg2);
}
function __wbg_adapter_35(arg0, arg1, arg2) {
wasm.closure133_externref_shim(arg0, arg1, arg2);
wasm.closure150_externref_shim(arg0, arg1, arg2);
}
function __wbg_adapter_38(arg0, arg1, arg2) {
wasm.closure188_externref_shim(arg0, arg1, arg2);
wasm.closure227_externref_shim(arg0, arg1, arg2);
}
function __wbg_adapter_135(arg0, arg1, arg2, arg3) {
wasm.closure1847_externref_shim(arg0, arg1, arg2, arg3);
function __wbg_adapter_138(arg0, arg1, arg2, arg3) {
wasm.closure1879_externref_shim(arg0, arg1, arg2, arg3);
}
const __wbindgen_enum_IdbTransactionMode = ["readonly", "readwrite", "versionchange", "readwriteflush", "cleanup"];
@@ -519,7 +558,7 @@ function __wbg_get_imports() {
const a = state0.a;
state0.a = 0;
try {
return __wbg_adapter_135(a, state0.b, arg0, arg1);
return __wbg_adapter_138(a, state0.b, arg0, arg1);
} finally {
state0.a = a;
}
@@ -673,16 +712,16 @@ function __wbg_get_imports() {
const ret = false;
return ret;
};
imports.wbg.__wbindgen_closure_wrapper288 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 90, __wbg_adapter_32);
imports.wbg.__wbindgen_closure_wrapper378 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 122, __wbg_adapter_32);
return ret;
};
imports.wbg.__wbindgen_closure_wrapper518 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 134, __wbg_adapter_35);
imports.wbg.__wbindgen_closure_wrapper549 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 151, __wbg_adapter_35);
return ret;
};
imports.wbg.__wbindgen_closure_wrapper776 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 189, __wbg_adapter_38);
imports.wbg.__wbindgen_closure_wrapper857 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 228, __wbg_adapter_38);
return ret;
};
imports.wbg.__wbindgen_debug_string = function(arg0, arg1) {