From c7e11a7c01bf9b417a8b1fb03a0a752166409439 Mon Sep 17 00:00:00 2001 From: padreug Date: Sat, 6 Sep 2025 23:52:30 +0200 Subject: [PATCH] Enhance market DM decryption process with improved authentication checks - Introduced checks for both injected auth service and global auth composable to retrieve user private and public keys. - Enhanced logging to provide clearer feedback on authentication status during DM decryption attempts. - Improved error handling for cases where user keys are unavailable, ensuring better user guidance. These changes strengthen the authentication flow and improve the reliability of market-related direct messages. --- src/modules/market/composables/useMarket.ts | 22 ++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/modules/market/composables/useMarket.ts b/src/modules/market/composables/useMarket.ts index 78b2937..b9cce29 100644 --- a/src/modules/market/composables/useMarket.ts +++ b/src/modules/market/composables/useMarket.ts @@ -5,6 +5,7 @@ import { config } from '@/lib/config' import { nostrmarketService } from '../services/nostrmarketService' import { nip04 } from 'nostr-tools' import { useAsyncOperation } from '@/core/composables/useAsyncOperation' +import { auth } from '@/composables/useAuth' // Nostr event kinds for market functionality const MARKET_EVENT_KINDS = { @@ -384,14 +385,29 @@ export function useMarket() { try { console.log('🔔 Received order-related DM:', event.id, 'from:', event.pubkey.slice(0, 8)) - const userPrivkey = authService.user.value?.prvkey + // Check both injected auth service AND global auth composable + const hasAuthService = authService.user.value?.prvkey + const hasGlobalAuth = auth.currentUser.value?.prvkey - if (!userPrivkey) { + const userPrivkey = hasAuthService ? authService.user.value.prvkey : auth.currentUser.value?.prvkey + const userPubkey = hasAuthService ? authService.user.value.pubkey : auth.currentUser.value?.pubkey + + if (!userPrivkey || !userPubkey) { console.warn('Cannot decrypt DM: no user private key available', { - authServicePrivkey: !!authService.user.value?.prvkey + hasAuthService: !!hasAuthService, + hasGlobalAuth: !!hasGlobalAuth, + authServicePrivkey: !!authService.user.value?.prvkey, + globalAuthPrivkey: !!auth.currentUser.value?.prvkey }) return } + + console.log('🔐 Market DM decryption auth check:', { + hasAuthService: !!hasAuthService, + hasGlobalAuth: !!hasGlobalAuth, + usingAuthService: !!hasAuthService, + userPubkey: userPubkey.substring(0, 10) + '...' + }) console.log('🔓 Attempting to decrypt DM with private key available')