Remove more logs

This commit is contained in:
Your Name
2025-11-14 14:40:05 -04:00
parent cb4f4b2a3c
commit 58d9b4386e
3 changed files with 95 additions and 151 deletions

View File

@@ -8,7 +8,7 @@
* Two-file architecture: * Two-file architecture:
* 1. Load nostr.bundle.js (official nostr-tools bundle) * 1. Load nostr.bundle.js (official nostr-tools bundle)
* 2. Load nostr-lite.js (this file - NOSTR_LOGIN_LITE library with CSS-only themes) * 2. Load nostr-lite.js (this file - NOSTR_LOGIN_LITE library with CSS-only themes)
* Generated on: 2025-11-14T18:31:40.699Z * Generated on: 2025-11-14T18:40:05.334Z
*/ */
// Verify dependencies are loaded // Verify dependencies are loaded
@@ -436,7 +436,7 @@ class Modal {
modalContent.appendChild(modalHeader); modalContent.appendChild(modalHeader);
// Add version element in bottom-right corner aligned with modal body // Add version element in bottom-right corner aligned with modal body
const versionElement = document.createElement('div'); const versionElement = document.createElement('div');
versionElement.textContent = 'v0.1.11'; versionElement.textContent = 'v0.1.12';
versionElement.style.cssText = ` versionElement.style.cssText = `
position: absolute; position: absolute;
bottom: 8px; bottom: 8px;
@@ -2898,7 +2898,7 @@ class NostrLite {
} }
async init(options = {}) { async init(options = {}) {
console.log('NOSTR_LOGIN_LITE: Initializing with options:', options); // console.log('NOSTR_LOGIN_LITE: Initializing with options:', options);
this.options = { this.options = {
theme: 'default', theme: 'default',
@@ -2946,12 +2946,12 @@ class NostrLite {
// Create modal during init (matching original git architecture) // Create modal during init (matching original git architecture)
this.modal = new Modal(this.options); this.modal = new Modal(this.options);
console.log('NOSTR_LOGIN_LITE: Modal created during init'); // console.log('NOSTR_LOGIN_LITE: Modal created during init');
// Initialize floating tab if enabled // Initialize floating tab if enabled
if (this.options.floatingTab.enabled) { if (this.options.floatingTab.enabled) {
this.floatingTab = new FloatingTab(this.modal, this.options.floatingTab); this.floatingTab = new FloatingTab(this.modal, this.options.floatingTab);
console.log('NOSTR_LOGIN_LITE: Floating tab initialized'); // console.log('NOSTR_LOGIN_LITE: Floating tab initialized');
} }
// Attempt to restore authentication state if persistence is enabled (AFTER facade is ready) // Attempt to restore authentication state if persistence is enabled (AFTER facade is ready)
@@ -2963,7 +2963,7 @@ class NostrLite {
} }
this.initialized = true; this.initialized = true;
console.log('NOSTR_LOGIN_LITE: Initialization complete'); // console.log('NOSTR_LOGIN_LITE: Initialization complete');
return this; return this;
} }
@@ -3098,7 +3098,7 @@ class NostrLite {
} }
launch(startScreen = 'login') { launch(startScreen = 'login') {
console.log('NOSTR_LOGIN_LITE: Launching with screen:', startScreen); // console.log('NOSTR_LOGIN_LITE: Launching with screen:', startScreen);
if (this.modal) { if (this.modal) {
this.modal.open({ startScreen }); this.modal.open({ startScreen });
@@ -3110,18 +3110,14 @@ class NostrLite {
// Attempt to restore authentication state // Attempt to restore authentication state
async _attemptAuthRestore() { async _attemptAuthRestore() {
try { try {
console.log('🔍 NOSTR_LOGIN_LITE: === _attemptAuthRestore START ===');
console.log('🔍 NOSTR_LOGIN_LITE: hasExtension:', this.hasExtension);
console.log('🔍 NOSTR_LOGIN_LITE: facadeInstalled:', this.facadeInstalled);
console.log('🔍 NOSTR_LOGIN_LITE: window.nostr:', window.nostr?.constructor?.name);
if (this.hasExtension) { if (this.hasExtension) {
// EXTENSION MODE: Use custom extension persistence logic // EXTENSION MODE: Use custom extension persistence logic
console.log('🔍 NOSTR_LOGIN_LITE: Extension mode - using extension-specific restore');
const restoredAuth = await this._attemptExtensionRestore(); const restoredAuth = await this._attemptExtensionRestore();
if (restoredAuth) { if (restoredAuth) {
console.log('🔍 NOSTR_LOGIN_LITE: ✅ Extension auth restored successfully!');
return restoredAuth; return restoredAuth;
} else { } else {
console.log('🔍 NOSTR_LOGIN_LITE: ❌ Extension auth could not be restored'); console.log('🔍 NOSTR_LOGIN_LITE: ❌ Extension auth could not be restored');
@@ -3133,14 +3129,11 @@ class NostrLite {
const restoredAuth = await window.nostr.restoreAuthState(); const restoredAuth = await window.nostr.restoreAuthState();
if (restoredAuth) { if (restoredAuth) {
console.log('🔍 NOSTR_LOGIN_LITE: ✅ Facade auth restored successfully!');
console.log('🔍 NOSTR_LOGIN_LITE: Method:', restoredAuth.method);
console.log('🔍 NOSTR_LOGIN_LITE: Pubkey:', restoredAuth.pubkey);
// CRITICAL FIX: Activate facade resilience system for non-extension methods // CRITICAL FIX: Activate facade resilience system for non-extension methods
// Extensions like nos2x can override our facade after page refresh // Extensions like nos2x can override our facade after page refresh
if (restoredAuth.method === 'local' || restoredAuth.method === 'nip46') { if (restoredAuth.method === 'local' || restoredAuth.method === 'nip46') {
console.log('🔍 NOSTR_LOGIN_LITE: 🛡️ Activating facade resilience system for page refresh');
this._activateResilienceProtection(restoredAuth.method); this._activateResilienceProtection(restoredAuth.method);
} }
@@ -3272,7 +3265,7 @@ class NostrLite {
// Show prompt for NIP-46 reconnection // Show prompt for NIP-46 reconnection
_showReconnectionPrompt(authData) { _showReconnectionPrompt(authData) {
console.log('NOSTR_LOGIN_LITE: Showing reconnection prompt for NIP-46');
// Dispatch event that UI can listen to // Dispatch event that UI can listen to
if (typeof window !== 'undefined') { if (typeof window !== 'undefined') {
@@ -3417,8 +3410,7 @@ class AuthManager {
// Save authentication state using unified plaintext approach // Save authentication state using unified plaintext approach
async saveAuthState(authData) { async saveAuthState(authData) {
try { try {
// console.log('🔐 AuthManager: Saving auth state with plaintext storage');
console.warn('🔐 SECURITY: Private key will be stored unencrypted for maximum usability');
const authState = { const authState = {
method: authData.method, method: authData.method,
@@ -3434,15 +3426,14 @@ class AuthManager {
hasGetPublicKey: typeof authData.extension?.getPublicKey === 'function', hasGetPublicKey: typeof authData.extension?.getPublicKey === 'function',
hasSignEvent: typeof authData.extension?.signEvent === 'function' hasSignEvent: typeof authData.extension?.signEvent === 'function'
}; };
// console.log('🔐 AuthManager: Extension method - storing verification data only');
break; break;
case 'local': case 'local':
// UNIFIED PLAINTEXT: Store secret key directly for maximum compatibility // UNIFIED PLAINTEXT: Store secret key directly for maximum compatibility
if (authData.secret) { if (authData.secret) {
authState.secret = authData.secret; authState.secret = authData.secret;
// console.log('🔐 AuthManager: Local method - storing secret key in plaintext');
console.warn('🔐 SECURITY: Secret key stored unencrypted for developer convenience');
} }
break; break;
@@ -3454,7 +3445,7 @@ class AuthManager {
relays: authData.signer.relays, relays: authData.signer.relays,
// Don't store secret - user will need to reconnect // Don't store secret - user will need to reconnect
}; };
// console.log('🔐 AuthManager: NIP-46 method - storing connection parameters');
} }
break; break;
@@ -3480,11 +3471,10 @@ class AuthManager {
// Restore authentication state on page load // Restore authentication state on page load
async restoreAuthState() { async restoreAuthState() {
try { try {
console.log('🔍 AuthManager: === restoreAuthState START ===');
console.log('🔍 AuthManager: storageKey:', this.storageKey);
const stored = this.storage.getItem(this.storageKey); const stored = this.storage.getItem(this.storageKey);
console.log('🔍 AuthManager: Storage raw value:', stored);
if (!stored) { if (!stored) {
console.log('🔍 AuthManager: ❌ No stored auth state found'); console.log('🔍 AuthManager: ❌ No stored auth state found');
@@ -3492,10 +3482,7 @@ class AuthManager {
} }
const authState = JSON.parse(stored); const authState = JSON.parse(stored);
console.log('🔍 AuthManager: ✅ Parsed stored auth state:', authState);
console.log('🔍 AuthManager: Method:', authState.method);
console.log('🔍 AuthManager: Timestamp:', authState.timestamp);
console.log('🔍 AuthManager: Age (ms):', Date.now() - authState.timestamp);
// Check if stored state is too old (24 hours for most methods, 1 hour for extensions) // Check if stored state is too old (24 hours for most methods, 1 hour for extensions)
const maxAge = authState.method === 'extension' ? 60 * 60 * 1000 : 24 * 60 * 60 * 1000; const maxAge = authState.method === 'extension' ? 60 * 60 * 1000 : 24 * 60 * 60 * 1000;
@@ -3507,27 +3494,26 @@ class AuthManager {
return null; return null;
} }
console.log('🔍 AuthManager: ✅ Auth state not expired, attempting restore for method:', authState.method);
let result; let result;
switch (authState.method) { switch (authState.method) {
case 'extension': case 'extension':
console.log('🔍 AuthManager: Calling _restoreExtensionAuth...');
result = await this._restoreExtensionAuth(authState); result = await this._restoreExtensionAuth(authState);
break; break;
case 'local': case 'local':
console.log('🔍 AuthManager: Calling _restoreLocalAuth...');
result = await this._restoreLocalAuth(authState); result = await this._restoreLocalAuth(authState);
break; break;
case 'nip46': case 'nip46':
console.log('🔍 AuthManager: Calling _restoreNip46Auth...');
result = await this._restoreNip46Auth(authState); result = await this._restoreNip46Auth(authState);
break; break;
case 'readonly': case 'readonly':
console.log('🔍 AuthManager: Calling _restoreReadonlyAuth...');
result = await this._restoreReadonlyAuth(authState); result = await this._restoreReadonlyAuth(authState);
break; break;
@@ -3536,8 +3522,6 @@ class AuthManager {
return null; return null;
} }
console.log('🔍 AuthManager: Restore method result:', result);
console.log('🔍 AuthManager: === restoreAuthState END ===');
return result; return result;
} catch (error) { } catch (error) {
@@ -3563,19 +3547,14 @@ class AuthManager {
return null; return null;
} }
console.log('🔍 AuthManager: ✅ Extension found:', extension.constructor?.name);
try { try {
// Verify extension still works and has same pubkey // Verify extension still works and has same pubkey
const currentPubkey = await extension.getPublicKey(); const currentPubkey = await extension.getPublicKey();
if (currentPubkey !== authState.pubkey) {
console.log('🔍 AuthManager: ❌ Extension pubkey changed, not restoring');
console.log('🔍 AuthManager: Expected:', authState.pubkey);
console.log('🔍 AuthManager: Got:', currentPubkey);
return null;
}
console.log('🔍 AuthManager: ✅ Extension auth restored successfully');
return { return {
method: 'extension', method: 'extension',
pubkey: authState.pubkey, pubkey: authState.pubkey,
@@ -3583,16 +3562,14 @@ class AuthManager {
}; };
} catch (error) { } catch (error) {
console.log('🔍 AuthManager: ❌ Extension verification failed:', error);
return null; return null;
} }
} }
// Smart extension waiting system - polls multiple locations for extensions // Smart extension waiting system - polls multiple locations for extensions
async _waitForExtension(authState, maxWaitMs = 3000) { async _waitForExtension(authState, maxWaitMs = 3000) {
console.log('🔍 AuthManager: === _waitForExtension START ===');
console.log('🔍 AuthManager: maxWaitMs:', maxWaitMs);
console.log('🔍 AuthManager: Looking for extension with constructor:', authState.extensionVerification?.constructor);
const startTime = Date.now(); const startTime = Date.now();
const pollInterval = 100; // Check every 100ms const pollInterval = 100; // Check every 100ms
@@ -3610,13 +3587,13 @@ class AuthManager {
]; ];
while (Date.now() - startTime < maxWaitMs) { while (Date.now() - startTime < maxWaitMs) {
console.log('🔍 AuthManager: Polling for extensions... (elapsed:', Date.now() - startTime, 'ms)');
// If our facade is currently installed and blocking, temporarily remove it // If our facade is currently installed and blocking, temporarily remove it
let facadeRemoved = false; let facadeRemoved = false;
let originalNostr = null; let originalNostr = null;
if (window.nostr?.constructor?.name === 'WindowNostr') { if (window.nostr?.constructor?.name === 'WindowNostr') {
console.log('🔍 AuthManager: Temporarily removing our facade to check for real extensions');
originalNostr = window.nostr; originalNostr = window.nostr;
window.nostr = window.nostr.existingNostr || undefined; window.nostr = window.nostr.existingNostr || undefined;
facadeRemoved = true; facadeRemoved = true;
@@ -3627,21 +3604,21 @@ class AuthManager {
for (const location of extensionLocations) { for (const location of extensionLocations) {
try { try {
const extension = location.getter(); const extension = location.getter();
console.log('🔍 AuthManager: Checking', location.path, ':', !!extension, extension?.constructor?.name);
if (this._isValidExtensionForRestore(extension, authState)) { if (this._isValidExtensionForRestore(extension, authState)) {
console.log('🔍 AuthManager: ✅ Found matching extension at', location.path);
// Restore facade if we removed it // Restore facade if we removed it
if (facadeRemoved && originalNostr) { if (facadeRemoved && originalNostr) {
console.log('🔍 AuthManager: Restoring facade after finding extension');
window.nostr = originalNostr; window.nostr = originalNostr;
} }
return extension; return extension;
} }
} catch (error) { } catch (error) {
console.log('🔍 AuthManager: Error checking', location.path, ':', error.message);
} }
} }
@@ -3702,31 +3679,27 @@ class AuthManager {
} }
} }
console.log('🔍 AuthManager: ✅ Extension validation passed for:', constructorName);
return true; return true;
} }
async _restoreLocalAuth(authState) { async _restoreLocalAuth(authState) {
// console.log('🔐 AuthManager: === _restoreLocalAuth (Unified Plaintext) ===');
// Check for legacy encrypted format first
if (authState.encrypted) { if (authState.encrypted) {
// console.log('🔐 AuthManager: Detected LEGACY encrypted format - migrating to plaintext');
console.warn('🔐 SECURITY: Converting from encrypted to plaintext storage for compatibility');
// Try to decrypt legacy format // Try to decrypt legacy format
const sessionPassword = sessionStorage.getItem('nostr_session_key'); const sessionPassword = sessionStorage.getItem('nostr_session_key');
if (!sessionPassword) { if (!sessionPassword) {
// console.log('🔐 AuthManager: Legacy session password not found - user must re-login');
return null; return null;
} }
try { try {
console.warn('🔐 AuthManager: Legacy encryption system no longer supported - user must re-login');
this.clearAuthState(); // Clear legacy format this.clearAuthState(); // Clear legacy format
return null; return null;
} catch (error) { } catch (error) {
console.error('🔐 AuthManager: Legacy decryption failed:', error);
this.clearAuthState(); // Clear corrupted legacy format this.clearAuthState(); // Clear corrupted legacy format
return null; return null;
} }
@@ -3734,12 +3707,11 @@ class AuthManager {
// NEW UNIFIED PLAINTEXT FORMAT // NEW UNIFIED PLAINTEXT FORMAT
if (!authState.secret) { if (!authState.secret) {
// console.log('🔐 AuthManager: No secret found in plaintext format');
return null; return null;
} }
// console.log('🔐 AuthManager: ✅ Local auth restored from plaintext storage');
console.warn('🔐 SECURITY: Secret key was stored unencrypted');
return { return {
method: 'local', method: 'local',
@@ -3750,14 +3722,14 @@ class AuthManager {
async _restoreNip46Auth(authState) { async _restoreNip46Auth(authState) {
if (!authState.nip46) { if (!authState.nip46) {
// console.log('🔐 AuthManager: No NIP-46 data found');
return null; return null;
} }
// For NIP-46, we can't automatically restore the connection // For NIP-46, we can't automatically restore the connection
// because it requires the user to re-authenticate with the remote signer // because it requires the user to re-authenticate with the remote signer
// Instead, we return the connection parameters so the UI can prompt for reconnection // Instead, we return the connection parameters so the UI can prompt for reconnection
// console.log('🔐 AuthManager: NIP-46 connection data found, requires user reconnection');
return { return {
method: 'nip46', method: 'nip46',
pubkey: authState.pubkey, pubkey: authState.pubkey,
@@ -3767,7 +3739,7 @@ class AuthManager {
} }
async _restoreReadonlyAuth(authState) { async _restoreReadonlyAuth(authState) {
// console.log('🔐 AuthManager: Read-only auth restored successfully');
return { return {
method: 'readonly', method: 'readonly',
pubkey: authState.pubkey pubkey: authState.pubkey
@@ -3779,7 +3751,7 @@ class AuthManager {
this.storage.removeItem(this.storageKey); this.storage.removeItem(this.storageKey);
sessionStorage.removeItem('nostr_session_key'); // Clear legacy session key sessionStorage.removeItem('nostr_session_key'); // Clear legacy session key
this.currentAuthState = null; this.currentAuthState = null;
// console.log('🔐 AuthManager: Auth state cleared from unified storage');
} }
// Check if we have valid stored auth // Check if we have valid stored auth
@@ -3822,8 +3794,8 @@ function getGlobalAuthManager() {
// **UNIFIED GLOBAL FUNCTION**: Set authentication state (works for all methods) // **UNIFIED GLOBAL FUNCTION**: Set authentication state (works for all methods)
function setAuthState(authData, options = {}) { function setAuthState(authData, options = {}) {
try { try {
// console.log('🌐 setAuthState: Setting global auth state for method:', authData.method);
console.warn('🔐 SECURITY: Using unified plaintext storage for maximum compatibility');
// Store in memory // Store in memory
globalAuthState = authData; globalAuthState = authData;
@@ -3832,7 +3804,7 @@ function setAuthState(authData, options = {}) {
const authManager = new AuthManager(options); const authManager = new AuthManager(options);
authManager.saveAuthState(authData); authManager.saveAuthState(authData);
// console.log('🌐 setAuthState: Auth state saved successfully');
} catch (error) { } catch (error) {
console.error('🌐 setAuthState: Failed to save auth state:', error); console.error('🌐 setAuthState: Failed to save auth state:', error);
throw error; throw error;

View File

@@ -1 +1 @@
0.1.11 0.1.12

View File

@@ -887,7 +887,7 @@ class NostrLite {
} }
async init(options = {}) { async init(options = {}) {
console.log('NOSTR_LOGIN_LITE: Initializing with options:', options); // console.log('NOSTR_LOGIN_LITE: Initializing with options:', options);
this.options = { this.options = {
theme: 'default', theme: 'default',
@@ -935,12 +935,12 @@ class NostrLite {
// Create modal during init (matching original git architecture) // Create modal during init (matching original git architecture)
this.modal = new Modal(this.options); this.modal = new Modal(this.options);
console.log('NOSTR_LOGIN_LITE: Modal created during init'); // console.log('NOSTR_LOGIN_LITE: Modal created during init');
// Initialize floating tab if enabled // Initialize floating tab if enabled
if (this.options.floatingTab.enabled) { if (this.options.floatingTab.enabled) {
this.floatingTab = new FloatingTab(this.modal, this.options.floatingTab); this.floatingTab = new FloatingTab(this.modal, this.options.floatingTab);
console.log('NOSTR_LOGIN_LITE: Floating tab initialized'); // console.log('NOSTR_LOGIN_LITE: Floating tab initialized');
} }
// Attempt to restore authentication state if persistence is enabled (AFTER facade is ready) // Attempt to restore authentication state if persistence is enabled (AFTER facade is ready)
@@ -952,7 +952,7 @@ class NostrLite {
} }
this.initialized = true; this.initialized = true;
console.log('NOSTR_LOGIN_LITE: Initialization complete'); // console.log('NOSTR_LOGIN_LITE: Initialization complete');
return this; return this;
} }
@@ -1087,7 +1087,7 @@ class NostrLite {
} }
launch(startScreen = 'login') { launch(startScreen = 'login') {
console.log('NOSTR_LOGIN_LITE: Launching with screen:', startScreen); // console.log('NOSTR_LOGIN_LITE: Launching with screen:', startScreen);
if (this.modal) { if (this.modal) {
this.modal.open({ startScreen }); this.modal.open({ startScreen });
@@ -1099,18 +1099,14 @@ class NostrLite {
// Attempt to restore authentication state // Attempt to restore authentication state
async _attemptAuthRestore() { async _attemptAuthRestore() {
try { try {
console.log('🔍 NOSTR_LOGIN_LITE: === _attemptAuthRestore START ===');
console.log('🔍 NOSTR_LOGIN_LITE: hasExtension:', this.hasExtension);
console.log('🔍 NOSTR_LOGIN_LITE: facadeInstalled:', this.facadeInstalled);
console.log('🔍 NOSTR_LOGIN_LITE: window.nostr:', window.nostr?.constructor?.name);
if (this.hasExtension) { if (this.hasExtension) {
// EXTENSION MODE: Use custom extension persistence logic // EXTENSION MODE: Use custom extension persistence logic
console.log('🔍 NOSTR_LOGIN_LITE: Extension mode - using extension-specific restore');
const restoredAuth = await this._attemptExtensionRestore(); const restoredAuth = await this._attemptExtensionRestore();
if (restoredAuth) { if (restoredAuth) {
console.log('🔍 NOSTR_LOGIN_LITE: ✅ Extension auth restored successfully!');
return restoredAuth; return restoredAuth;
} else { } else {
console.log('🔍 NOSTR_LOGIN_LITE: ❌ Extension auth could not be restored'); console.log('🔍 NOSTR_LOGIN_LITE: ❌ Extension auth could not be restored');
@@ -1122,14 +1118,11 @@ class NostrLite {
const restoredAuth = await window.nostr.restoreAuthState(); const restoredAuth = await window.nostr.restoreAuthState();
if (restoredAuth) { if (restoredAuth) {
console.log('🔍 NOSTR_LOGIN_LITE: ✅ Facade auth restored successfully!');
console.log('🔍 NOSTR_LOGIN_LITE: Method:', restoredAuth.method);
console.log('🔍 NOSTR_LOGIN_LITE: Pubkey:', restoredAuth.pubkey);
// CRITICAL FIX: Activate facade resilience system for non-extension methods // CRITICAL FIX: Activate facade resilience system for non-extension methods
// Extensions like nos2x can override our facade after page refresh // Extensions like nos2x can override our facade after page refresh
if (restoredAuth.method === 'local' || restoredAuth.method === 'nip46') { if (restoredAuth.method === 'local' || restoredAuth.method === 'nip46') {
console.log('🔍 NOSTR_LOGIN_LITE: 🛡️ Activating facade resilience system for page refresh');
this._activateResilienceProtection(restoredAuth.method); this._activateResilienceProtection(restoredAuth.method);
} }
@@ -1261,7 +1254,7 @@ class NostrLite {
// Show prompt for NIP-46 reconnection // Show prompt for NIP-46 reconnection
_showReconnectionPrompt(authData) { _showReconnectionPrompt(authData) {
console.log('NOSTR_LOGIN_LITE: Showing reconnection prompt for NIP-46');
// Dispatch event that UI can listen to // Dispatch event that UI can listen to
if (typeof window !== 'undefined') { if (typeof window !== 'undefined') {
@@ -1406,8 +1399,7 @@ class AuthManager {
// Save authentication state using unified plaintext approach // Save authentication state using unified plaintext approach
async saveAuthState(authData) { async saveAuthState(authData) {
try { try {
// console.log('🔐 AuthManager: Saving auth state with plaintext storage');
console.warn('🔐 SECURITY: Private key will be stored unencrypted for maximum usability');
const authState = { const authState = {
method: authData.method, method: authData.method,
@@ -1423,15 +1415,14 @@ class AuthManager {
hasGetPublicKey: typeof authData.extension?.getPublicKey === 'function', hasGetPublicKey: typeof authData.extension?.getPublicKey === 'function',
hasSignEvent: typeof authData.extension?.signEvent === 'function' hasSignEvent: typeof authData.extension?.signEvent === 'function'
}; };
// console.log('🔐 AuthManager: Extension method - storing verification data only');
break; break;
case 'local': case 'local':
// UNIFIED PLAINTEXT: Store secret key directly for maximum compatibility // UNIFIED PLAINTEXT: Store secret key directly for maximum compatibility
if (authData.secret) { if (authData.secret) {
authState.secret = authData.secret; authState.secret = authData.secret;
// console.log('🔐 AuthManager: Local method - storing secret key in plaintext');
console.warn('🔐 SECURITY: Secret key stored unencrypted for developer convenience');
} }
break; break;
@@ -1443,7 +1434,7 @@ class AuthManager {
relays: authData.signer.relays, relays: authData.signer.relays,
// Don't store secret - user will need to reconnect // Don't store secret - user will need to reconnect
}; };
// console.log('🔐 AuthManager: NIP-46 method - storing connection parameters');
} }
break; break;
@@ -1469,11 +1460,10 @@ class AuthManager {
// Restore authentication state on page load // Restore authentication state on page load
async restoreAuthState() { async restoreAuthState() {
try { try {
console.log('🔍 AuthManager: === restoreAuthState START ===');
console.log('🔍 AuthManager: storageKey:', this.storageKey);
const stored = this.storage.getItem(this.storageKey); const stored = this.storage.getItem(this.storageKey);
console.log('🔍 AuthManager: Storage raw value:', stored);
if (!stored) { if (!stored) {
console.log('🔍 AuthManager: ❌ No stored auth state found'); console.log('🔍 AuthManager: ❌ No stored auth state found');
@@ -1481,10 +1471,7 @@ class AuthManager {
} }
const authState = JSON.parse(stored); const authState = JSON.parse(stored);
console.log('🔍 AuthManager: ✅ Parsed stored auth state:', authState);
console.log('🔍 AuthManager: Method:', authState.method);
console.log('🔍 AuthManager: Timestamp:', authState.timestamp);
console.log('🔍 AuthManager: Age (ms):', Date.now() - authState.timestamp);
// Check if stored state is too old (24 hours for most methods, 1 hour for extensions) // Check if stored state is too old (24 hours for most methods, 1 hour for extensions)
const maxAge = authState.method === 'extension' ? 60 * 60 * 1000 : 24 * 60 * 60 * 1000; const maxAge = authState.method === 'extension' ? 60 * 60 * 1000 : 24 * 60 * 60 * 1000;
@@ -1496,27 +1483,26 @@ class AuthManager {
return null; return null;
} }
console.log('🔍 AuthManager: ✅ Auth state not expired, attempting restore for method:', authState.method);
let result; let result;
switch (authState.method) { switch (authState.method) {
case 'extension': case 'extension':
console.log('🔍 AuthManager: Calling _restoreExtensionAuth...');
result = await this._restoreExtensionAuth(authState); result = await this._restoreExtensionAuth(authState);
break; break;
case 'local': case 'local':
console.log('🔍 AuthManager: Calling _restoreLocalAuth...');
result = await this._restoreLocalAuth(authState); result = await this._restoreLocalAuth(authState);
break; break;
case 'nip46': case 'nip46':
console.log('🔍 AuthManager: Calling _restoreNip46Auth...');
result = await this._restoreNip46Auth(authState); result = await this._restoreNip46Auth(authState);
break; break;
case 'readonly': case 'readonly':
console.log('🔍 AuthManager: Calling _restoreReadonlyAuth...');
result = await this._restoreReadonlyAuth(authState); result = await this._restoreReadonlyAuth(authState);
break; break;
@@ -1525,8 +1511,6 @@ class AuthManager {
return null; return null;
} }
console.log('🔍 AuthManager: Restore method result:', result);
console.log('🔍 AuthManager: === restoreAuthState END ===');
return result; return result;
} catch (error) { } catch (error) {
@@ -1552,19 +1536,14 @@ class AuthManager {
return null; return null;
} }
console.log('🔍 AuthManager: ✅ Extension found:', extension.constructor?.name);
try { try {
// Verify extension still works and has same pubkey // Verify extension still works and has same pubkey
const currentPubkey = await extension.getPublicKey(); const currentPubkey = await extension.getPublicKey();
if (currentPubkey !== authState.pubkey) {
console.log('🔍 AuthManager: ❌ Extension pubkey changed, not restoring');
console.log('🔍 AuthManager: Expected:', authState.pubkey);
console.log('🔍 AuthManager: Got:', currentPubkey);
return null;
}
console.log('🔍 AuthManager: ✅ Extension auth restored successfully');
return { return {
method: 'extension', method: 'extension',
pubkey: authState.pubkey, pubkey: authState.pubkey,
@@ -1572,16 +1551,14 @@ class AuthManager {
}; };
} catch (error) { } catch (error) {
console.log('🔍 AuthManager: ❌ Extension verification failed:', error);
return null; return null;
} }
} }
// Smart extension waiting system - polls multiple locations for extensions // Smart extension waiting system - polls multiple locations for extensions
async _waitForExtension(authState, maxWaitMs = 3000) { async _waitForExtension(authState, maxWaitMs = 3000) {
console.log('🔍 AuthManager: === _waitForExtension START ===');
console.log('🔍 AuthManager: maxWaitMs:', maxWaitMs);
console.log('🔍 AuthManager: Looking for extension with constructor:', authState.extensionVerification?.constructor);
const startTime = Date.now(); const startTime = Date.now();
const pollInterval = 100; // Check every 100ms const pollInterval = 100; // Check every 100ms
@@ -1599,13 +1576,13 @@ class AuthManager {
]; ];
while (Date.now() - startTime < maxWaitMs) { while (Date.now() - startTime < maxWaitMs) {
console.log('🔍 AuthManager: Polling for extensions... (elapsed:', Date.now() - startTime, 'ms)');
// If our facade is currently installed and blocking, temporarily remove it // If our facade is currently installed and blocking, temporarily remove it
let facadeRemoved = false; let facadeRemoved = false;
let originalNostr = null; let originalNostr = null;
if (window.nostr?.constructor?.name === 'WindowNostr') { if (window.nostr?.constructor?.name === 'WindowNostr') {
console.log('🔍 AuthManager: Temporarily removing our facade to check for real extensions');
originalNostr = window.nostr; originalNostr = window.nostr;
window.nostr = window.nostr.existingNostr || undefined; window.nostr = window.nostr.existingNostr || undefined;
facadeRemoved = true; facadeRemoved = true;
@@ -1616,21 +1593,21 @@ class AuthManager {
for (const location of extensionLocations) { for (const location of extensionLocations) {
try { try {
const extension = location.getter(); const extension = location.getter();
console.log('🔍 AuthManager: Checking', location.path, ':', !!extension, extension?.constructor?.name);
if (this._isValidExtensionForRestore(extension, authState)) { if (this._isValidExtensionForRestore(extension, authState)) {
console.log('🔍 AuthManager: ✅ Found matching extension at', location.path);
// Restore facade if we removed it // Restore facade if we removed it
if (facadeRemoved && originalNostr) { if (facadeRemoved && originalNostr) {
console.log('🔍 AuthManager: Restoring facade after finding extension');
window.nostr = originalNostr; window.nostr = originalNostr;
} }
return extension; return extension;
} }
} catch (error) { } catch (error) {
console.log('🔍 AuthManager: Error checking', location.path, ':', error.message);
} }
} }
@@ -1691,31 +1668,27 @@ class AuthManager {
} }
} }
console.log('🔍 AuthManager: ✅ Extension validation passed for:', constructorName);
return true; return true;
} }
async _restoreLocalAuth(authState) { async _restoreLocalAuth(authState) {
// console.log('🔐 AuthManager: === _restoreLocalAuth (Unified Plaintext) ===');
// Check for legacy encrypted format first
if (authState.encrypted) { if (authState.encrypted) {
// console.log('🔐 AuthManager: Detected LEGACY encrypted format - migrating to plaintext');
console.warn('🔐 SECURITY: Converting from encrypted to plaintext storage for compatibility');
// Try to decrypt legacy format // Try to decrypt legacy format
const sessionPassword = sessionStorage.getItem('nostr_session_key'); const sessionPassword = sessionStorage.getItem('nostr_session_key');
if (!sessionPassword) { if (!sessionPassword) {
// console.log('🔐 AuthManager: Legacy session password not found - user must re-login');
return null; return null;
} }
try { try {
console.warn('🔐 AuthManager: Legacy encryption system no longer supported - user must re-login');
this.clearAuthState(); // Clear legacy format this.clearAuthState(); // Clear legacy format
return null; return null;
} catch (error) { } catch (error) {
console.error('🔐 AuthManager: Legacy decryption failed:', error);
this.clearAuthState(); // Clear corrupted legacy format this.clearAuthState(); // Clear corrupted legacy format
return null; return null;
} }
@@ -1723,12 +1696,11 @@ class AuthManager {
// NEW UNIFIED PLAINTEXT FORMAT // NEW UNIFIED PLAINTEXT FORMAT
if (!authState.secret) { if (!authState.secret) {
// console.log('🔐 AuthManager: No secret found in plaintext format');
return null; return null;
} }
// console.log('🔐 AuthManager: ✅ Local auth restored from plaintext storage');
console.warn('🔐 SECURITY: Secret key was stored unencrypted');
return { return {
method: 'local', method: 'local',
@@ -1739,14 +1711,14 @@ class AuthManager {
async _restoreNip46Auth(authState) { async _restoreNip46Auth(authState) {
if (!authState.nip46) { if (!authState.nip46) {
// console.log('🔐 AuthManager: No NIP-46 data found');
return null; return null;
} }
// For NIP-46, we can't automatically restore the connection // For NIP-46, we can't automatically restore the connection
// because it requires the user to re-authenticate with the remote signer // because it requires the user to re-authenticate with the remote signer
// Instead, we return the connection parameters so the UI can prompt for reconnection // Instead, we return the connection parameters so the UI can prompt for reconnection
// console.log('🔐 AuthManager: NIP-46 connection data found, requires user reconnection');
return { return {
method: 'nip46', method: 'nip46',
pubkey: authState.pubkey, pubkey: authState.pubkey,
@@ -1756,7 +1728,7 @@ class AuthManager {
} }
async _restoreReadonlyAuth(authState) { async _restoreReadonlyAuth(authState) {
// console.log('🔐 AuthManager: Read-only auth restored successfully');
return { return {
method: 'readonly', method: 'readonly',
pubkey: authState.pubkey pubkey: authState.pubkey
@@ -1768,7 +1740,7 @@ class AuthManager {
this.storage.removeItem(this.storageKey); this.storage.removeItem(this.storageKey);
sessionStorage.removeItem('nostr_session_key'); // Clear legacy session key sessionStorage.removeItem('nostr_session_key'); // Clear legacy session key
this.currentAuthState = null; this.currentAuthState = null;
// console.log('🔐 AuthManager: Auth state cleared from unified storage');
} }
// Check if we have valid stored auth // Check if we have valid stored auth
@@ -1811,8 +1783,8 @@ function getGlobalAuthManager() {
// **UNIFIED GLOBAL FUNCTION**: Set authentication state (works for all methods) // **UNIFIED GLOBAL FUNCTION**: Set authentication state (works for all methods)
function setAuthState(authData, options = {}) { function setAuthState(authData, options = {}) {
try { try {
// console.log('🌐 setAuthState: Setting global auth state for method:', authData.method);
console.warn('🔐 SECURITY: Using unified plaintext storage for maximum compatibility');
// Store in memory // Store in memory
globalAuthState = authData; globalAuthState = authData;
@@ -1821,7 +1793,7 @@ function setAuthState(authData, options = {}) {
const authManager = new AuthManager(options); const authManager = new AuthManager(options);
authManager.saveAuthState(authData); authManager.saveAuthState(authData);
// console.log('🌐 setAuthState: Auth state saved successfully');
} catch (error) { } catch (error) {
console.error('🌐 setAuthState: Failed to save auth state:', error); console.error('🌐 setAuthState: Failed to save auth state:', error);
throw error; throw error;