feat: implement browser extension UI with WebAssembly integration
This commit is contained in:
88
extension/popup/debug_rhai.js
Normal file
88
extension/popup/debug_rhai.js
Normal file
@@ -0,0 +1,88 @@
|
||||
/**
|
||||
* Debug helper for WebAssembly Vault with Rhai scripts
|
||||
*/
|
||||
|
||||
// Helper to try various Rhai scripts for debugging
|
||||
export const RHAI_SCRIPTS = {
|
||||
// Check if there's an active session
|
||||
CHECK_SESSION: `
|
||||
let has_session = false;
|
||||
let current_keyspace = "";
|
||||
|
||||
// Try to access functions expected to exist in the vault namespace
|
||||
if (isdef(vault) && isdef(vault::has_active_session)) {
|
||||
has_session = vault::has_active_session();
|
||||
if (has_session && isdef(vault::get_current_keyspace)) {
|
||||
current_keyspace = vault::get_current_keyspace();
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
"has_session": has_session,
|
||||
"keyspace": current_keyspace,
|
||||
"available_functions": [
|
||||
isdef(vault::list_keypairs) ? "list_keypairs" : null,
|
||||
isdef(vault::add_keypair) ? "add_keypair" : null,
|
||||
isdef(vault::has_active_session) ? "has_active_session" : null,
|
||||
isdef(vault::get_current_keyspace) ? "get_current_keyspace" : null
|
||||
]
|
||||
}
|
||||
`,
|
||||
|
||||
// Explicitly get keypairs for the current keyspace using session data
|
||||
LIST_KEYPAIRS: `
|
||||
let result = {"error": "Not initialized"};
|
||||
|
||||
if (isdef(vault) && isdef(vault::has_active_session) && vault::has_active_session()) {
|
||||
let keyspace = vault::get_current_keyspace();
|
||||
|
||||
// Try to list the keypairs from the current session
|
||||
if (isdef(vault::get_keypairs_from_session)) {
|
||||
result = {
|
||||
"keyspace": keyspace,
|
||||
"keypairs": vault::get_keypairs_from_session()
|
||||
};
|
||||
} else {
|
||||
result = {
|
||||
"error": "vault::get_keypairs_from_session is not defined",
|
||||
"keyspace": keyspace
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
result
|
||||
`,
|
||||
|
||||
// Use Rhai to inspect the Vault storage directly (for advanced debugging)
|
||||
INSPECT_VAULT_STORAGE: `
|
||||
let result = {"error": "Not accessible"};
|
||||
|
||||
if (isdef(vault) && isdef(vault::inspect_storage)) {
|
||||
result = vault::inspect_storage();
|
||||
}
|
||||
|
||||
result
|
||||
`
|
||||
};
|
||||
|
||||
// Run all debug scripts and collect results
|
||||
export async function runDiagnostics(wasmModule) {
|
||||
if (!wasmModule || !wasmModule.run_rhai) {
|
||||
throw new Error('WebAssembly module not loaded or run_rhai not available');
|
||||
}
|
||||
|
||||
const results = {};
|
||||
|
||||
for (const [name, script] of Object.entries(RHAI_SCRIPTS)) {
|
||||
try {
|
||||
console.log(`Running Rhai diagnostic script: ${name}`);
|
||||
results[name] = await wasmModule.run_rhai(script);
|
||||
console.log(`Result from ${name}:`, results[name]);
|
||||
} catch (error) {
|
||||
console.error(`Error running script ${name}:`, error);
|
||||
results[name] = { error: error.toString() };
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
Reference in New Issue
Block a user