Reset crypto_vault_extension to clean state before SigSocket implementation
This commit is contained in:
		| @@ -5,7 +5,6 @@ let keepAliveInterval = null; | ||||
| let sessionTimeoutDuration = 15; // Default 15 seconds | ||||
| let sessionTimeoutId = null; // Background timer | ||||
| let popupPort = null; // Track popup connection | ||||
| let sigSocketService = null; // SigSocket service instance | ||||
|  | ||||
| // Utility function to convert Uint8Array to hex | ||||
| function toHex(uint8Array) { | ||||
| @@ -139,9 +138,6 @@ async function restoreSession() { | ||||
| // Import WASM module functions | ||||
| import init, * as wasmFunctions from './wasm/wasm_app.js'; | ||||
|  | ||||
| // Import SigSocket service | ||||
| import SigSocketService from './background/sigsocket.js'; | ||||
|  | ||||
| // Initialize WASM module | ||||
| async function initVault() { | ||||
|   try { | ||||
| @@ -155,9 +151,6 @@ async function initVault() { | ||||
|     vault = wasmFunctions; | ||||
|     isInitialized = true; | ||||
|  | ||||
|     // Initialize SigSocket service | ||||
|     await initSigSocketService(); | ||||
|  | ||||
|     // Try to restore previous session | ||||
|     await restoreSession(); | ||||
|  | ||||
| @@ -168,17 +161,6 @@ async function initVault() { | ||||
|   } | ||||
| } | ||||
|  | ||||
| // Initialize SigSocket service | ||||
| async function initSigSocketService() { | ||||
|   try { | ||||
|     sigSocketService = new SigSocketService(); | ||||
|     await sigSocketService.initialize(vault); | ||||
|     console.log('SigSocket service initialized'); | ||||
|   } catch (error) { | ||||
|     console.error('Failed to initialize SigSocket service:', error); | ||||
|   } | ||||
| } | ||||
|  | ||||
|  | ||||
| // Consolidated message handlers | ||||
| const messageHandlers = { | ||||
| @@ -190,16 +172,6 @@ const messageHandlers = { | ||||
|   initSession: async (request) => { | ||||
|     await vault.init_session(request.keyspace, request.password); | ||||
|     await sessionManager.save(request.keyspace); | ||||
|  | ||||
|     // Auto-connect to SigSocket server when session is initialized (only if not already connected) | ||||
|     if (sigSocketService && !sigSocketService.isConnected) { | ||||
|       console.log(`Attempting to connect to SigSocket for keyspace: ${request.keyspace}`); | ||||
|       const connected = await sigSocketService.connectToServer(request.keyspace); | ||||
|       console.log(`SigSocket connection result: ${connected}`); | ||||
|     } else if (sigSocketService && sigSocketService.isConnected) { | ||||
|       console.log('SigSocket already connected, skipping connection attempt'); | ||||
|     } | ||||
|  | ||||
|     return { success: true }; | ||||
|   }, | ||||
|  | ||||
| @@ -289,52 +261,6 @@ const messageHandlers = { | ||||
|     await chrome.storage.local.set({ sessionTimeout: request.timeout }); | ||||
|     resetSessionTimeout(); // Restart with new duration | ||||
|     return { success: true }; | ||||
|   }, | ||||
|  | ||||
|   // SigSocket message handlers | ||||
|   connectSigSocket: async (request) => { | ||||
|     if (!sigSocketService) { | ||||
|       return { success: false, error: 'SigSocket service not available' }; | ||||
|     } | ||||
|     const connected = await sigSocketService.connectToServer(request.workspaceId); | ||||
|     return { success: connected }; | ||||
|   }, | ||||
|  | ||||
|   getPendingRequests: () => { | ||||
|     if (!sigSocketService) { | ||||
|       return { success: false, error: 'SigSocket service not available' }; | ||||
|     } | ||||
|     return { success: true, requests: sigSocketService.getPendingRequests() }; | ||||
|   }, | ||||
|  | ||||
|   keypaceUnlocked: async () => { | ||||
|     if (sigSocketService) { | ||||
|       await sigSocketService.onKeypaceUnlocked(); | ||||
|     } | ||||
|     return { success: true }; | ||||
|   }, | ||||
|  | ||||
|   approveSignRequest: async (request) => { | ||||
|     if (!sigSocketService) { | ||||
|       return { success: false, error: 'SigSocket service not available' }; | ||||
|     } | ||||
|     const approved = await sigSocketService.approveSignRequest(request.requestId); | ||||
|     return { success: approved }; | ||||
|   }, | ||||
|  | ||||
|   rejectSignRequest: async (request) => { | ||||
|     if (!sigSocketService) { | ||||
|       return { success: false, error: 'SigSocket service not available' }; | ||||
|     } | ||||
|     const rejected = await sigSocketService.rejectSignRequest(request.requestId, request.reason); | ||||
|     return { success: rejected }; | ||||
|   }, | ||||
|  | ||||
|   getSigSocketStatus: () => { | ||||
|     if (!sigSocketService) { | ||||
|       return { success: false, error: 'SigSocket service not available' }; | ||||
|     } | ||||
|     return { success: true, status: sigSocketService.getStatus() }; | ||||
|   } | ||||
| }; | ||||
|  | ||||
| @@ -376,11 +302,6 @@ chrome.runtime.onConnect.addListener((port) => { | ||||
|     // Track popup connection | ||||
|     popupPort = port; | ||||
|  | ||||
|     // Set popup port in SigSocket service | ||||
|     if (sigSocketService) { | ||||
|       sigSocketService.setPopupPort(port); | ||||
|     } | ||||
|  | ||||
|     // If we have an active session, ensure keep-alive is running | ||||
|     if (currentSession) { | ||||
|       startKeepAlive(); | ||||
| @@ -389,9 +310,6 @@ chrome.runtime.onConnect.addListener((port) => { | ||||
|     port.onDisconnect.addListener(() => { | ||||
|       // Popup closed, clear reference and stop keep-alive | ||||
|       popupPort = null; | ||||
|       if (sigSocketService) { | ||||
|         sigSocketService.setPopupPort(null); | ||||
|       } | ||||
|       stopKeepAlive(); | ||||
|     }); | ||||
|   } | ||||
|   | ||||
| @@ -6,8 +6,7 @@ | ||||
|  | ||||
|   "permissions": [ | ||||
|     "storage", | ||||
|     "activeTab", | ||||
|     "notifications" | ||||
|     "activeTab" | ||||
|   ], | ||||
|  | ||||
|   "icons": { | ||||
|   | ||||
| @@ -27,10 +27,6 @@ | ||||
|                 <span>seconds</span> | ||||
|               </div> | ||||
|             </div> | ||||
|             <div class="settings-item"> | ||||
|               <label for="sigSocketUrlInput">SigSocket Server</label> | ||||
|               <input type="text" id="sigSocketUrlInput" placeholder="ws://localhost:8080/ws" value="ws://localhost:8080/ws"> | ||||
|             </div> | ||||
|           </div> | ||||
|         </div> | ||||
|         <button id="themeToggle" class="btn-icon-only" title="Switch to dark mode"> | ||||
| @@ -193,11 +189,6 @@ | ||||
|           </div> | ||||
|         </div> | ||||
|       </div> | ||||
|  | ||||
|       <!-- Sign Request Manager --> | ||||
|       <div id="signRequestContainer"> | ||||
|         <!-- Sign request manager will be rendered here --> | ||||
|       </div> | ||||
|     </section> | ||||
|  | ||||
|  | ||||
| @@ -207,7 +198,6 @@ | ||||
|  | ||||
|   <!-- Enhanced JavaScript modules --> | ||||
|   <script src="js/errorHandler.js"></script> | ||||
|   <script src="popup/components/SignRequestManager.js"></script> | ||||
|   <script src="popup.js"></script> | ||||
| </body> | ||||
| </html> | ||||
| @@ -129,7 +129,6 @@ const elements = { | ||||
|   settingsToggle: document.getElementById('settingsToggle'), | ||||
|   settingsDropdown: document.getElementById('settingsDropdown'), | ||||
|   timeoutInput: document.getElementById('timeoutInput'), | ||||
|   sigSocketUrlInput: document.getElementById('sigSocketUrlInput'), | ||||
|  | ||||
|   // Keypair management elements | ||||
|   toggleAddKeypairBtn: document.getElementById('toggleAddKeypairBtn'), | ||||
| @@ -168,7 +167,6 @@ let currentKeyspace = null; | ||||
| let selectedKeypairId = null; | ||||
| let backgroundPort = null; | ||||
| let sessionTimeoutDuration = 15; // Default 15 seconds | ||||
| let signRequestManager = null; // Sign request manager instance | ||||
|  | ||||
| // Session timeout management | ||||
| function handleError(error, context, shouldShowToast = true) { | ||||
| @@ -200,14 +198,11 @@ function validateInput(value, fieldName, options = {}) { | ||||
|   return true; | ||||
| } | ||||
| async function loadTimeoutSetting() { | ||||
|   const result = await chrome.storage.local.get(['sessionTimeout', 'sigSocketUrl']); | ||||
|   const result = await chrome.storage.local.get(['sessionTimeout']); | ||||
|   sessionTimeoutDuration = result.sessionTimeout || 15; | ||||
|   if (elements.timeoutInput) { | ||||
|     elements.timeoutInput.value = sessionTimeoutDuration; | ||||
|   } | ||||
|   if (elements.sigSocketUrlInput) { | ||||
|     elements.sigSocketUrlInput.value = result.sigSocketUrl || 'ws://localhost:8080/ws'; | ||||
|   } | ||||
| } | ||||
|  | ||||
| async function checkSessionTimeout() { | ||||
| @@ -312,39 +307,6 @@ function connectToBackground() { | ||||
|  | ||||
|       // Show timeout notification | ||||
|       showToast(message.message, 'info'); | ||||
|  | ||||
|       // Update sign request manager | ||||
|       if (signRequestManager) { | ||||
|         signRequestManager.updateState({ isKeypaceUnlocked: false }); | ||||
|       } | ||||
|     } else if (message.type === 'KEYSPACE_UNLOCKED') { | ||||
|       // Handle keyspace unlock from SigSocket service | ||||
|       console.log('Popup received KEYSPACE_UNLOCKED message:', message); | ||||
|       if (signRequestManager) { | ||||
|         console.log('Updating SignRequestManager state with keypaceMatches:', message.keypaceMatches); | ||||
|         signRequestManager.updateState({ | ||||
|           isKeypaceUnlocked: true, | ||||
|           keypaceMatches: message.keypaceMatches, | ||||
|           pendingRequests: message.pendingRequests | ||||
|         }); | ||||
|         console.log('SignRequestManager state updated'); | ||||
|       } else { | ||||
|         console.log('No SignRequestManager available to update'); | ||||
|       } | ||||
|     } else if (message.type === 'NEW_SIGN_REQUEST') { | ||||
|       // Handle new sign request when keyspace is already unlocked | ||||
|       console.log('Popup received NEW_SIGN_REQUEST message:', message); | ||||
|       if (signRequestManager) { | ||||
|         console.log('Updating SignRequestManager with new request, keypaceMatches:', message.keypaceMatches); | ||||
|         // Only update if we have a valid keyspace match, otherwise requests array will be empty for security | ||||
|         signRequestManager.updateState({ | ||||
|           keypaceMatches: message.keypaceMatches, | ||||
|           pendingRequests: message.pendingRequests | ||||
|         }); | ||||
|         console.log(`SignRequestManager updated with new request: ${message.pendingRequests.length} requests visible`); | ||||
|       } else { | ||||
|         console.log('No SignRequestManager available to update with new request'); | ||||
|       } | ||||
|     } | ||||
|   }); | ||||
|  | ||||
| @@ -353,22 +315,6 @@ function connectToBackground() { | ||||
|   }); | ||||
| } | ||||
|  | ||||
| // Initialize Sign Request Manager | ||||
| async function initializeSignRequestManager() { | ||||
|   try { | ||||
|     const container = document.getElementById('signRequestContainer'); | ||||
|     if (container && window.SignRequestManager) { | ||||
|       signRequestManager = new window.SignRequestManager(); | ||||
|       await signRequestManager.initialize(container); | ||||
|       console.log('Sign Request Manager initialized'); | ||||
|     } else { | ||||
|       console.warn('SignRequestManager not available or container not found'); | ||||
|     } | ||||
|   } catch (error) { | ||||
|     console.error('Failed to initialize Sign Request Manager:', error); | ||||
|   } | ||||
| } | ||||
|  | ||||
| // Initialize | ||||
| document.addEventListener('DOMContentLoaded', async function() { | ||||
|   // Initialize theme first | ||||
| @@ -386,9 +332,6 @@ document.addEventListener('DOMContentLoaded', async function() { | ||||
|   // Connect to background script for keep-alive | ||||
|   connectToBackground(); | ||||
|  | ||||
|   // Initialize Sign Request Manager | ||||
|   await initializeSignRequestManager(); | ||||
|  | ||||
|   // Consolidated event listeners | ||||
|   const eventMap = { | ||||
|     createKeyspaceBtn: createKeyspace, | ||||
| @@ -433,18 +376,6 @@ document.addEventListener('DOMContentLoaded', async function() { | ||||
|     } | ||||
|   }); | ||||
|  | ||||
|   // SigSocket URL setting event listener | ||||
|   elements.sigSocketUrlInput?.addEventListener('change', async (e) => { | ||||
|     const url = e.target.value.trim(); | ||||
|     if (url) { | ||||
|       await chrome.storage.local.set({ sigSocketUrl: url }); | ||||
|       // Update the SigSocket service with new URL if it exists | ||||
|       if (signRequestManager && signRequestManager.sigSocketService) { | ||||
|         signRequestManager.sigSocketService.defaultServerUrl = url; | ||||
|       } | ||||
|     } | ||||
|   }); | ||||
|  | ||||
|   // Activity detection - reset timeout on any interaction | ||||
|   document.addEventListener('click', (e) => { | ||||
|     resetSessionTimeout(); | ||||
| @@ -713,12 +644,6 @@ async function login() { | ||||
|           clearVaultState(); | ||||
|           await loadKeypairs(); | ||||
|  | ||||
|           // Notify sign request manager about keyspace unlock | ||||
|           if (signRequestManager) { | ||||
|             signRequestManager.updateState({ isKeypaceUnlocked: true }); | ||||
|             await signRequestManager.refresh(); | ||||
|           } | ||||
|  | ||||
|           return response; | ||||
|         } else { | ||||
|           throw new Error(getResponseError(response, 'login')); | ||||
| @@ -748,11 +673,6 @@ async function lockSession() { | ||||
|     elements.passwordInput.value = ''; | ||||
|     clearVaultState(); | ||||
|  | ||||
|     // Update sign request manager | ||||
|     if (signRequestManager) { | ||||
|       signRequestManager.updateState({ isKeypaceUnlocked: false }); | ||||
|     } | ||||
|  | ||||
|     showToast('Session locked', 'info'); | ||||
|   } catch (error) { | ||||
|     showToast('Error: ' + error.message, 'error'); | ||||
|   | ||||
| @@ -1069,195 +1069,4 @@ input::placeholder, textarea::placeholder { | ||||
| .verification-icon svg { | ||||
|   width: 20px; | ||||
|   height: 20px; | ||||
| } | ||||
|  | ||||
| /* Sign Request Manager Styles */ | ||||
| .sign-request-manager { | ||||
|   margin-top: 16px; | ||||
|   padding: 16px; | ||||
|   background: var(--bg-secondary); | ||||
|   border-radius: 8px; | ||||
|   border: 1px solid var(--border-color); | ||||
| } | ||||
|  | ||||
| .connection-status { | ||||
|   display: flex; | ||||
|   align-items: center; | ||||
|   gap: 8px; | ||||
|   margin-bottom: 12px; | ||||
|   font-size: 12px; | ||||
|   font-weight: 500; | ||||
| } | ||||
|  | ||||
| .status-indicator { | ||||
|   width: 8px; | ||||
|   height: 8px; | ||||
|   border-radius: 50%; | ||||
|   background: #ef4444; | ||||
| } | ||||
|  | ||||
| .connection-status.connected .status-indicator { | ||||
|   background: #10b981; | ||||
| } | ||||
|  | ||||
| .no-requests { | ||||
|   text-align: center; | ||||
|   padding: 20px; | ||||
|   color: var(--text-secondary); | ||||
| } | ||||
|  | ||||
| .unlock-prompt, .keyspace-mismatch { | ||||
|   text-align: center; | ||||
|   padding: 20px; | ||||
| } | ||||
|  | ||||
| .unlock-prompt h3, .keyspace-mismatch h3 { | ||||
|   margin: 0 0 12px 0; | ||||
|   font-size: 16px; | ||||
|   color: var(--text-primary); | ||||
| } | ||||
|  | ||||
| .unlock-prompt p, .keyspace-mismatch p { | ||||
|   margin: 8px 0; | ||||
|   color: var(--text-secondary); | ||||
|   font-size: 14px; | ||||
| } | ||||
|  | ||||
| .hint { | ||||
|   font-style: italic; | ||||
|   font-size: 12px !important; | ||||
|   color: var(--text-tertiary) !important; | ||||
| } | ||||
|  | ||||
| .requests-header { | ||||
|   margin-bottom: 12px; | ||||
| } | ||||
|  | ||||
| .requests-header h3 { | ||||
|   margin: 0; | ||||
|   font-size: 16px; | ||||
|   color: var(--text-primary); | ||||
| } | ||||
|  | ||||
| .requests-list { | ||||
|   display: flex; | ||||
|   flex-direction: column; | ||||
|   gap: 12px; | ||||
| } | ||||
|  | ||||
| .sign-request-card { | ||||
|   background: var(--bg-primary); | ||||
|   border: 1px solid var(--border-color); | ||||
|   border-radius: 6px; | ||||
|   padding: 12px; | ||||
| } | ||||
|  | ||||
| .request-header { | ||||
|   display: flex; | ||||
|   justify-content: space-between; | ||||
|   align-items: center; | ||||
|   margin-bottom: 8px; | ||||
| } | ||||
|  | ||||
| .request-id { | ||||
|   font-family: monospace; | ||||
|   font-size: 12px; | ||||
|   color: var(--text-secondary); | ||||
|   font-weight: 500; | ||||
| } | ||||
|  | ||||
| .request-time { | ||||
|   font-size: 11px; | ||||
|   color: var(--text-tertiary); | ||||
| } | ||||
|  | ||||
| .request-message { | ||||
|   margin-bottom: 12px; | ||||
| } | ||||
|  | ||||
| .request-message label { | ||||
|   display: block; | ||||
|   font-size: 12px; | ||||
|   font-weight: 500; | ||||
|   color: var(--text-secondary); | ||||
|   margin-bottom: 4px; | ||||
| } | ||||
|  | ||||
| .message-content { | ||||
|   background: var(--bg-secondary); | ||||
|   border: 1px solid var(--border-color); | ||||
|   border-radius: 4px; | ||||
|   padding: 8px; | ||||
|   position: relative; | ||||
| } | ||||
|  | ||||
| .message-preview { | ||||
|   font-family: monospace; | ||||
|   font-size: 11px; | ||||
|   color: var(--text-primary); | ||||
|   word-break: break-all; | ||||
|   line-height: 1.4; | ||||
|   max-height: 60px; | ||||
|   overflow: hidden; | ||||
| } | ||||
|  | ||||
| .message-content.expanded .message-preview { | ||||
|   max-height: none; | ||||
| } | ||||
|  | ||||
| .expand-message { | ||||
|   position: absolute; | ||||
|   top: 4px; | ||||
|   right: 4px; | ||||
|   background: var(--accent-color); | ||||
|   color: white; | ||||
|   border: none; | ||||
|   border-radius: 3px; | ||||
|   padding: 2px 6px; | ||||
|   font-size: 10px; | ||||
|   cursor: pointer; | ||||
|   transition: background-color 0.2s; | ||||
| } | ||||
|  | ||||
| .expand-message:hover { | ||||
|   background: var(--accent-hover); | ||||
| } | ||||
|  | ||||
| .request-actions { | ||||
|   display: flex; | ||||
|   gap: 8px; | ||||
|   justify-content: flex-end; | ||||
| } | ||||
|  | ||||
| .btn-approve, .btn-reject { | ||||
|   padding: 6px 12px; | ||||
|   border: none; | ||||
|   border-radius: 4px; | ||||
|   font-size: 12px; | ||||
|   font-weight: 500; | ||||
|   cursor: pointer; | ||||
|   transition: all 0.2s; | ||||
| } | ||||
|  | ||||
| .btn-approve { | ||||
|   background: #10b981; | ||||
|   color: white; | ||||
| } | ||||
|  | ||||
| .btn-approve:hover:not(:disabled) { | ||||
|   background: #059669; | ||||
| } | ||||
|  | ||||
| .btn-reject { | ||||
|   background: #ef4444; | ||||
|   color: white; | ||||
| } | ||||
|  | ||||
| .btn-reject:hover:not(:disabled) { | ||||
|   background: #dc2626; | ||||
| } | ||||
|  | ||||
| .btn-approve:disabled, .btn-reject:disabled { | ||||
|   opacity: 0.6; | ||||
|   cursor: not-allowed; | ||||
| } | ||||
| @@ -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} | ||||
| @@ -299,42 +277,6 @@ export function is_unlocked() { | ||||
|     return ret !== 0; | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * Get the default public key for a workspace (keyspace) | ||||
|  * This returns the public key of the first keypair in the keyspace | ||||
|  * @param {string} workspace_id | ||||
|  * @returns {Promise<any>} | ||||
|  */ | ||||
| export function get_workspace_default_public_key(workspace_id) { | ||||
|     const ptr0 = passStringToWasm0(workspace_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||||
|     const len0 = WASM_VECTOR_LEN; | ||||
|     const ret = wasm.get_workspace_default_public_key(ptr0, len0); | ||||
|     return ret; | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * Get the current unlocked public key as hex string | ||||
|  * @returns {string} | ||||
|  */ | ||||
| export function get_current_unlocked_public_key() { | ||||
|     let deferred2_0; | ||||
|     let deferred2_1; | ||||
|     try { | ||||
|         const ret = wasm.get_current_unlocked_public_key(); | ||||
|         var ptr1 = ret[0]; | ||||
|         var len1 = ret[1]; | ||||
|         if (ret[3]) { | ||||
|             ptr1 = 0; len1 = 0; | ||||
|             throw takeFromExternrefTable0(ret[2]); | ||||
|         } | ||||
|         deferred2_0 = ptr1; | ||||
|         deferred2_1 = len1; | ||||
|         return getStringFromWasm0(ptr1, len1); | ||||
|     } finally { | ||||
|         wasm.__wbindgen_free(deferred2_0, deferred2_1, 1); | ||||
|     } | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * Get all keypairs from the current session | ||||
|  * Returns an array of keypair objects with id, type, and metadata | ||||
| @@ -381,7 +323,7 @@ function passArray8ToWasm0(arg, malloc) { | ||||
|     return ptr; | ||||
| } | ||||
| /** | ||||
|  * Sign message with current session (requires selected keypair) | ||||
|  * Sign message with current session | ||||
|  * @param {Uint8Array} message | ||||
|  * @returns {Promise<any>} | ||||
|  */ | ||||
| @@ -392,41 +334,6 @@ export function sign(message) { | ||||
|     return ret; | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * Get the current keyspace name | ||||
|  * @returns {string} | ||||
|  */ | ||||
| export function get_current_keyspace_name() { | ||||
|     let deferred2_0; | ||||
|     let deferred2_1; | ||||
|     try { | ||||
|         const ret = wasm.get_current_keyspace_name(); | ||||
|         var ptr1 = ret[0]; | ||||
|         var len1 = ret[1]; | ||||
|         if (ret[3]) { | ||||
|             ptr1 = 0; len1 = 0; | ||||
|             throw takeFromExternrefTable0(ret[2]); | ||||
|         } | ||||
|         deferred2_0 = ptr1; | ||||
|         deferred2_1 = len1; | ||||
|         return getStringFromWasm0(ptr1, len1); | ||||
|     } finally { | ||||
|         wasm.__wbindgen_free(deferred2_0, deferred2_1, 1); | ||||
|     } | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * Sign message with default keypair (first keypair in keyspace) without changing session state | ||||
|  * @param {Uint8Array} message | ||||
|  * @returns {Promise<any>} | ||||
|  */ | ||||
| export function sign_with_default_keypair(message) { | ||||
|     const ptr0 = passArray8ToWasm0(message, wasm.__wbindgen_malloc); | ||||
|     const len0 = WASM_VECTOR_LEN; | ||||
|     const ret = wasm.sign_with_default_keypair(ptr0, len0); | ||||
|     return ret; | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * Verify a signature with the current session's selected keypair | ||||
|  * @param {Uint8Array} message | ||||
| @@ -466,162 +373,46 @@ export function decrypt_data(encrypted) { | ||||
|     return ret; | ||||
| } | ||||
|  | ||||
| function __wbg_adapter_34(arg0, arg1, arg2) { | ||||
|     wasm.closure135_externref_shim(arg0, arg1, arg2); | ||||
| /** | ||||
|  * Initialize the scripting environment (must be called before run_rhai) | ||||
|  */ | ||||
| export function init_rhai_env() { | ||||
|     wasm.init_rhai_env(); | ||||
| } | ||||
|  | ||||
| function __wbg_adapter_39(arg0, arg1) { | ||||
|     wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__ha4436a3f79fb1a0f(arg0, arg1); | ||||
| /** | ||||
|  * 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_44(arg0, arg1, arg2) { | ||||
|     wasm.closure199_externref_shim(arg0, arg1, arg2); | ||||
| function __wbg_adapter_32(arg0, arg1, arg2) { | ||||
|     wasm.closure121_externref_shim(arg0, arg1, arg2); | ||||
| } | ||||
|  | ||||
| function __wbg_adapter_49(arg0, arg1) { | ||||
|     wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hf148c54a4a246cea(arg0, arg1); | ||||
| function __wbg_adapter_35(arg0, arg1, arg2) { | ||||
|     wasm.closure150_externref_shim(arg0, arg1, arg2); | ||||
| } | ||||
|  | ||||
| function __wbg_adapter_52(arg0, arg1, arg2) { | ||||
|     wasm.closure264_externref_shim(arg0, arg1, arg2); | ||||
| function __wbg_adapter_38(arg0, arg1, arg2) { | ||||
|     wasm.closure227_externref_shim(arg0, arg1, arg2); | ||||
| } | ||||
|  | ||||
| function __wbg_adapter_55(arg0, arg1, arg2) { | ||||
|     wasm.closure349_externref_shim(arg0, arg1, arg2); | ||||
| function __wbg_adapter_138(arg0, arg1, arg2, arg3) { | ||||
|     wasm.closure1879_externref_shim(arg0, arg1, arg2, arg3); | ||||
| } | ||||
|  | ||||
| function __wbg_adapter_195(arg0, arg1, arg2, arg3) { | ||||
|     wasm.closure2004_externref_shim(arg0, arg1, arg2, arg3); | ||||
| } | ||||
|  | ||||
| const __wbindgen_enum_BinaryType = ["blob", "arraybuffer"]; | ||||
|  | ||||
| const __wbindgen_enum_IdbTransactionMode = ["readonly", "readwrite", "versionchange", "readwriteflush", "cleanup"]; | ||||
|  | ||||
| const SigSocketConnectionFinalization = (typeof FinalizationRegistry === 'undefined') | ||||
|     ? { register: () => {}, unregister: () => {} } | ||||
|     : new FinalizationRegistry(ptr => wasm.__wbg_sigsocketconnection_free(ptr >>> 0, 1)); | ||||
| /** | ||||
|  * WASM-bindgen wrapper for SigSocket client | ||||
|  * | ||||
|  * This provides a clean JavaScript API for the browser extension to: | ||||
|  * - Connect to SigSocket servers | ||||
|  * - Send responses to sign requests | ||||
|  * - Manage connection state | ||||
|  */ | ||||
| export class SigSocketConnection { | ||||
|  | ||||
|     __destroy_into_raw() { | ||||
|         const ptr = this.__wbg_ptr; | ||||
|         this.__wbg_ptr = 0; | ||||
|         SigSocketConnectionFinalization.unregister(this); | ||||
|         return ptr; | ||||
|     } | ||||
|  | ||||
|     free() { | ||||
|         const ptr = this.__destroy_into_raw(); | ||||
|         wasm.__wbg_sigsocketconnection_free(ptr, 0); | ||||
|     } | ||||
|     /** | ||||
|      * Create a new SigSocket connection | ||||
|      */ | ||||
|     constructor() { | ||||
|         const ret = wasm.sigsocketconnection_new(); | ||||
|         this.__wbg_ptr = ret >>> 0; | ||||
|         SigSocketConnectionFinalization.register(this, this.__wbg_ptr, this); | ||||
|         return this; | ||||
|     } | ||||
|     /** | ||||
|      * Connect to a SigSocket server | ||||
|      * | ||||
|      * # Arguments | ||||
|      * * `server_url` - WebSocket server URL (e.g., "ws://localhost:8080/ws") | ||||
|      * * `public_key_hex` - Client's public key as hex string | ||||
|      * | ||||
|      * # Returns | ||||
|      * * `Ok(())` - Successfully connected | ||||
|      * * `Err(error)` - Connection failed | ||||
|      * @param {string} server_url | ||||
|      * @param {string} public_key_hex | ||||
|      * @returns {Promise<void>} | ||||
|      */ | ||||
|     connect(server_url, public_key_hex) { | ||||
|         const ptr0 = passStringToWasm0(server_url, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||||
|         const len0 = WASM_VECTOR_LEN; | ||||
|         const ptr1 = passStringToWasm0(public_key_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||||
|         const len1 = WASM_VECTOR_LEN; | ||||
|         const ret = wasm.sigsocketconnection_connect(this.__wbg_ptr, ptr0, len0, ptr1, len1); | ||||
|         return ret; | ||||
|     } | ||||
|     /** | ||||
|      * Send a response to a sign request | ||||
|      * | ||||
|      * This should be called by the extension after the user has approved | ||||
|      * a sign request and the message has been signed. | ||||
|      * | ||||
|      * # Arguments | ||||
|      * * `request_id` - ID of the original request | ||||
|      * * `message_base64` - Original message (base64-encoded) | ||||
|      * * `signature_hex` - Signature as hex string | ||||
|      * | ||||
|      * # Returns | ||||
|      * * `Ok(())` - Response sent successfully | ||||
|      * * `Err(error)` - Failed to send response | ||||
|      * @param {string} request_id | ||||
|      * @param {string} message_base64 | ||||
|      * @param {string} signature_hex | ||||
|      * @returns {Promise<void>} | ||||
|      */ | ||||
|     send_response(request_id, message_base64, signature_hex) { | ||||
|         const ptr0 = passStringToWasm0(request_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||||
|         const len0 = WASM_VECTOR_LEN; | ||||
|         const ptr1 = passStringToWasm0(message_base64, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||||
|         const len1 = WASM_VECTOR_LEN; | ||||
|         const ptr2 = passStringToWasm0(signature_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||||
|         const len2 = WASM_VECTOR_LEN; | ||||
|         const ret = wasm.sigsocketconnection_send_response(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2); | ||||
|         return ret; | ||||
|     } | ||||
|     /** | ||||
|      * Send a rejection for a sign request | ||||
|      * | ||||
|      * This should be called when the user rejects a sign request. | ||||
|      * | ||||
|      * # Arguments | ||||
|      * * `request_id` - ID of the request to reject | ||||
|      * * `reason` - Reason for rejection (optional) | ||||
|      * | ||||
|      * # Returns | ||||
|      * * `Ok(())` - Rejection sent successfully | ||||
|      * * `Err(error)` - Failed to send rejection | ||||
|      * @param {string} request_id | ||||
|      * @param {string} reason | ||||
|      * @returns {Promise<void>} | ||||
|      */ | ||||
|     send_rejection(request_id, reason) { | ||||
|         const ptr0 = passStringToWasm0(request_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||||
|         const len0 = WASM_VECTOR_LEN; | ||||
|         const ptr1 = passStringToWasm0(reason, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||||
|         const len1 = WASM_VECTOR_LEN; | ||||
|         const ret = wasm.sigsocketconnection_send_rejection(this.__wbg_ptr, ptr0, len0, ptr1, len1); | ||||
|         return ret; | ||||
|     } | ||||
|     /** | ||||
|      * Disconnect from the SigSocket server | ||||
|      */ | ||||
|     disconnect() { | ||||
|         wasm.sigsocketconnection_disconnect(this.__wbg_ptr); | ||||
|     } | ||||
|     /** | ||||
|      * Check if connected to the server | ||||
|      * @returns {boolean} | ||||
|      */ | ||||
|     is_connected() { | ||||
|         const ret = wasm.sigsocketconnection_is_connected(this.__wbg_ptr); | ||||
|         return ret !== 0; | ||||
|     } | ||||
| } | ||||
|  | ||||
| async function __wbg_load(module, imports) { | ||||
|     if (typeof Response === 'function' && module instanceof Response) { | ||||
|         if (typeof WebAssembly.instantiateStreaming === 'function') { | ||||
| @@ -676,10 +467,6 @@ function __wbg_get_imports() { | ||||
|         const ret = arg0.crypto; | ||||
|         return ret; | ||||
|     }; | ||||
|     imports.wbg.__wbg_data_432d9c3df2630942 = function(arg0) { | ||||
|         const ret = arg0.data; | ||||
|         return ret; | ||||
|     }; | ||||
|     imports.wbg.__wbg_error_524f506f44df1645 = function(arg0) { | ||||
|         console.error(arg0); | ||||
|     }; | ||||
| @@ -752,23 +539,10 @@ function __wbg_get_imports() { | ||||
|         const ret = result; | ||||
|         return ret; | ||||
|     }; | ||||
|     imports.wbg.__wbg_instanceof_Window_def73ea0955fc569 = function(arg0) { | ||||
|         let result; | ||||
|         try { | ||||
|             result = arg0 instanceof Window; | ||||
|         } catch (_) { | ||||
|             result = false; | ||||
|         } | ||||
|         const ret = result; | ||||
|         return ret; | ||||
|     }; | ||||
|     imports.wbg.__wbg_length_52b6c4580c5ec934 = function(arg0) { | ||||
|         const ret = arg0.length; | ||||
|         return ret; | ||||
|     }; | ||||
|     imports.wbg.__wbg_log_c222819a41e063d3 = function(arg0) { | ||||
|         console.log(arg0); | ||||
|     }; | ||||
|     imports.wbg.__wbg_msCrypto_a61aeb35a24c1329 = function(arg0) { | ||||
|         const ret = arg0.msCrypto; | ||||
|         return ret; | ||||
| @@ -784,7 +558,7 @@ function __wbg_get_imports() { | ||||
|                 const a = state0.a; | ||||
|                 state0.a = 0; | ||||
|                 try { | ||||
|                     return __wbg_adapter_195(a, state0.b, arg0, arg1); | ||||
|                     return __wbg_adapter_138(a, state0.b, arg0, arg1); | ||||
|                 } finally { | ||||
|                     state0.a = a; | ||||
|                 } | ||||
| @@ -803,10 +577,6 @@ function __wbg_get_imports() { | ||||
|         const ret = new Array(); | ||||
|         return ret; | ||||
|     }; | ||||
|     imports.wbg.__wbg_new_92c54fc74574ef55 = function() { return handleError(function (arg0, arg1) { | ||||
|         const ret = new WebSocket(getStringFromWasm0(arg0, arg1)); | ||||
|         return ret; | ||||
|     }, arguments) }; | ||||
|     imports.wbg.__wbg_new_a12002a7f91c75be = function(arg0) { | ||||
|         const ret = new Uint8Array(arg0); | ||||
|         return ret; | ||||
| @@ -839,12 +609,6 @@ function __wbg_get_imports() { | ||||
|         const ret = arg0.objectStore(getStringFromWasm0(arg1, arg2)); | ||||
|         return ret; | ||||
|     }, arguments) }; | ||||
|     imports.wbg.__wbg_onConnectionStateChanged_b0dc098522afadba = function(arg0) { | ||||
|         onConnectionStateChanged(arg0 !== 0); | ||||
|     }; | ||||
|     imports.wbg.__wbg_onSignRequestReceived_93232ba7a0919705 = function(arg0, arg1, arg2, arg3) { | ||||
|         onSignRequestReceived(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3)); | ||||
|     }; | ||||
|     imports.wbg.__wbg_open_88b1390d99a7c691 = function() { return handleError(function (arg0, arg1, arg2) { | ||||
|         const ret = arg0.open(getStringFromWasm0(arg1, arg2)); | ||||
|         return ret; | ||||
| @@ -879,10 +643,6 @@ function __wbg_get_imports() { | ||||
|     imports.wbg.__wbg_randomFillSync_ac0988aba3254290 = function() { return handleError(function (arg0, arg1) { | ||||
|         arg0.randomFillSync(arg1); | ||||
|     }, arguments) }; | ||||
|     imports.wbg.__wbg_readyState_7ef6e63c349899ed = function(arg0) { | ||||
|         const ret = arg0.readyState; | ||||
|         return ret; | ||||
|     }; | ||||
|     imports.wbg.__wbg_require_60cc747a6bc5215a = function() { return handleError(function () { | ||||
|         const ret = module.require; | ||||
|         return ret; | ||||
| @@ -895,34 +655,12 @@ function __wbg_get_imports() { | ||||
|         const ret = arg0.result; | ||||
|         return ret; | ||||
|     }, arguments) }; | ||||
|     imports.wbg.__wbg_send_0293179ba074ffb4 = function() { return handleError(function (arg0, arg1, arg2) { | ||||
|         arg0.send(getStringFromWasm0(arg1, arg2)); | ||||
|     }, arguments) }; | ||||
|     imports.wbg.__wbg_setTimeout_f2fe5af8e3debeb3 = function() { return handleError(function (arg0, arg1, arg2) { | ||||
|         const ret = arg0.setTimeout(arg1, arg2); | ||||
|         return ret; | ||||
|     }, arguments) }; | ||||
|     imports.wbg.__wbg_set_65595bdd868b3009 = function(arg0, arg1, arg2) { | ||||
|         arg0.set(arg1, arg2 >>> 0); | ||||
|     }; | ||||
|     imports.wbg.__wbg_setbinaryType_92fa1ffd873b327c = function(arg0, arg1) { | ||||
|         arg0.binaryType = __wbindgen_enum_BinaryType[arg1]; | ||||
|     }; | ||||
|     imports.wbg.__wbg_setonclose_14fc475a49d488fc = function(arg0, arg1) { | ||||
|         arg0.onclose = arg1; | ||||
|     }; | ||||
|     imports.wbg.__wbg_setonerror_8639efe354b947cd = function(arg0, arg1) { | ||||
|         arg0.onerror = arg1; | ||||
|     }; | ||||
|     imports.wbg.__wbg_setonerror_d7e3056cc6e56085 = function(arg0, arg1) { | ||||
|         arg0.onerror = arg1; | ||||
|     }; | ||||
|     imports.wbg.__wbg_setonmessage_6eccab530a8fb4c7 = function(arg0, arg1) { | ||||
|         arg0.onmessage = arg1; | ||||
|     }; | ||||
|     imports.wbg.__wbg_setonopen_2da654e1f39745d5 = function(arg0, arg1) { | ||||
|         arg0.onopen = arg1; | ||||
|     }; | ||||
|     imports.wbg.__wbg_setonsuccess_afa464ee777a396d = function(arg0, arg1) { | ||||
|         arg0.onsuccess = arg1; | ||||
|     }; | ||||
| @@ -957,10 +695,6 @@ function __wbg_get_imports() { | ||||
|         const ret = arg0.then(arg1); | ||||
|         return ret; | ||||
|     }; | ||||
|     imports.wbg.__wbg_then_48b406749878a531 = function(arg0, arg1, arg2) { | ||||
|         const ret = arg0.then(arg1, arg2); | ||||
|         return ret; | ||||
|     }; | ||||
|     imports.wbg.__wbg_transaction_d6d07c3c9963c49e = function() { return handleError(function (arg0, arg1, arg2) { | ||||
|         const ret = arg0.transaction(arg1, __wbindgen_enum_IdbTransactionMode[arg2]); | ||||
|         return ret; | ||||
| @@ -969,9 +703,6 @@ function __wbg_get_imports() { | ||||
|         const ret = arg0.versions; | ||||
|         return ret; | ||||
|     }; | ||||
|     imports.wbg.__wbg_warn_4ca3906c248c47c4 = function(arg0) { | ||||
|         console.warn(arg0); | ||||
|     }; | ||||
|     imports.wbg.__wbindgen_cb_drop = function(arg0) { | ||||
|         const obj = arg0.original; | ||||
|         if (obj.cnt-- == 1) { | ||||
| @@ -981,40 +712,16 @@ function __wbg_get_imports() { | ||||
|         const ret = false; | ||||
|         return ret; | ||||
|     }; | ||||
|     imports.wbg.__wbindgen_closure_wrapper1181 = function(arg0, arg1, arg2) { | ||||
|         const ret = makeMutClosure(arg0, arg1, 350, __wbg_adapter_55); | ||||
|     imports.wbg.__wbindgen_closure_wrapper378 = function(arg0, arg1, arg2) { | ||||
|         const ret = makeMutClosure(arg0, arg1, 122, __wbg_adapter_32); | ||||
|         return ret; | ||||
|     }; | ||||
|     imports.wbg.__wbindgen_closure_wrapper335 = function(arg0, arg1, arg2) { | ||||
|         const ret = makeMutClosure(arg0, arg1, 133, __wbg_adapter_34); | ||||
|     imports.wbg.__wbindgen_closure_wrapper549 = function(arg0, arg1, arg2) { | ||||
|         const ret = makeMutClosure(arg0, arg1, 151, __wbg_adapter_35); | ||||
|         return ret; | ||||
|     }; | ||||
|     imports.wbg.__wbindgen_closure_wrapper336 = function(arg0, arg1, arg2) { | ||||
|         const ret = makeMutClosure(arg0, arg1, 133, __wbg_adapter_34); | ||||
|         return ret; | ||||
|     }; | ||||
|     imports.wbg.__wbindgen_closure_wrapper337 = function(arg0, arg1, arg2) { | ||||
|         const ret = makeMutClosure(arg0, arg1, 133, __wbg_adapter_39); | ||||
|         return ret; | ||||
|     }; | ||||
|     imports.wbg.__wbindgen_closure_wrapper340 = function(arg0, arg1, arg2) { | ||||
|         const ret = makeMutClosure(arg0, arg1, 133, __wbg_adapter_34); | ||||
|         return ret; | ||||
|     }; | ||||
|     imports.wbg.__wbindgen_closure_wrapper657 = function(arg0, arg1, arg2) { | ||||
|         const ret = makeMutClosure(arg0, arg1, 200, __wbg_adapter_44); | ||||
|         return ret; | ||||
|     }; | ||||
|     imports.wbg.__wbindgen_closure_wrapper658 = function(arg0, arg1, arg2) { | ||||
|         const ret = makeMutClosure(arg0, arg1, 200, __wbg_adapter_44); | ||||
|         return ret; | ||||
|     }; | ||||
|     imports.wbg.__wbindgen_closure_wrapper661 = function(arg0, arg1, arg2) { | ||||
|         const ret = makeMutClosure(arg0, arg1, 200, __wbg_adapter_49); | ||||
|         return ret; | ||||
|     }; | ||||
|     imports.wbg.__wbindgen_closure_wrapper876 = function(arg0, arg1, arg2) { | ||||
|         const ret = makeMutClosure(arg0, arg1, 265, __wbg_adapter_52); | ||||
|     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) { | ||||
| @@ -1071,14 +778,6 @@ function __wbg_get_imports() { | ||||
|         const ret = wasm.memory; | ||||
|         return ret; | ||||
|     }; | ||||
|     imports.wbg.__wbindgen_string_get = function(arg0, arg1) { | ||||
|         const obj = arg1; | ||||
|         const ret = typeof(obj) === 'string' ? obj : undefined; | ||||
|         var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||||
|         var len1 = WASM_VECTOR_LEN; | ||||
|         getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); | ||||
|         getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); | ||||
|     }; | ||||
|     imports.wbg.__wbindgen_string_new = function(arg0, arg1) { | ||||
|         const ret = getStringFromWasm0(arg0, arg1); | ||||
|         return ret; | ||||
|   | ||||
										
											Binary file not shown.
										
									
								
							
		Reference in New Issue
	
	Block a user