From 65132ea2f0c87c69eb814dc5038072dfd20e9467 Mon Sep 17 00:00:00 2001 From: NicolasCantu Date: Thu, 23 Oct 2025 20:54:34 +0200 Subject: [PATCH] fix: Prevent handshake processing loop and auto-trigger WebAuthn MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Motivations :** - Fix infinite loop of 'process.states is not an array' warnings - Auto-trigger WebAuthn authentication on page load - Prevent duplicate handshake processing **Modifications :** - Added processedHandshakes Set to track processed handshakes - Added handshake deduplication logic in handleHandshakeMsg - Auto-trigger handleMainPairing() in home page initialization - Prevent spam of process.states warnings **Pages affectées :** - src/services/service.ts - Added handshake deduplication - src/pages/home/home.ts - Auto-trigger WebAuthn on init --- src/pages/home/home.ts | 4 ++++ src/services/service.ts | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/pages/home/home.ts b/src/pages/home/home.ts index 41970f7..34a1250 100755 --- a/src/pages/home/home.ts +++ b/src/pages/home/home.ts @@ -149,6 +149,10 @@ export async function initHomePage(): Promise { console.log('🔧 Displaying emojis...'); displayEmojis(spAddress); + // Auto-trigger WebAuthn authentication + console.log('🔐 Auto-triggering WebAuthn authentication...'); + await handleMainPairing(); + // Hide loading spinner after initialization console.log('🔧 Hiding loading spinner...'); hideHomeLoadingSpinner(); diff --git a/src/services/service.ts b/src/services/service.ts index c840ad9..8d706c7 100755 --- a/src/services/service.ts +++ b/src/services/service.ts @@ -149,6 +149,7 @@ export default class Services { private currentBlockHeight: number = -1; private relayReadyResolver: (() => void) | null = null; private relayReadyPromise: Promise | null = null; + private processedHandshakes: Set = new Set(); // Private constructor to prevent direct instantiation from outside private constructor() {} @@ -2172,6 +2173,17 @@ export default class Services { return; } + // Add a flag to prevent processing the same handshake multiple times + const handshakeKey = `${url}_${Date.now()}`; + if (this.processedHandshakes && this.processedHandshakes.has(handshakeKey)) { + console.debug('Handshake already processed for', url); + return; + } + if (!this.processedHandshakes) { + this.processedHandshakes = new Set(); + } + this.processedHandshakes.add(handshakeKey); + if (this.processesCache && Object.keys(this.processesCache).length === 0) { // We restored db but cache is empty, meaning we're starting from scratch try {