|
|
|
@@ -330,7 +330,7 @@ class Modal {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_handleOptionClick(type) {
|
|
|
|
_handleOptionClick(type) {
|
|
|
|
console.log('Selected login type:', type);
|
|
|
|
// console.log('Selected login type:', type);
|
|
|
|
|
|
|
|
|
|
|
|
// Handle different login types
|
|
|
|
// Handle different login types
|
|
|
|
switch (type) {
|
|
|
|
switch (type) {
|
|
|
|
@@ -362,16 +362,16 @@ class Modal {
|
|
|
|
// Check if NostrLite instance has a preserved extension (real extension detected at init)
|
|
|
|
// Check if NostrLite instance has a preserved extension (real extension detected at init)
|
|
|
|
if (window.NOSTR_LOGIN_LITE?._instance?.preservedExtension) {
|
|
|
|
if (window.NOSTR_LOGIN_LITE?._instance?.preservedExtension) {
|
|
|
|
extension = window.NOSTR_LOGIN_LITE._instance.preservedExtension;
|
|
|
|
extension = window.NOSTR_LOGIN_LITE._instance.preservedExtension;
|
|
|
|
console.log('Modal: Using preserved extension:', extension.constructor?.name);
|
|
|
|
// console.log('Modal: Using preserved extension:', extension.constructor?.name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Otherwise check current window.nostr
|
|
|
|
// Otherwise check current window.nostr
|
|
|
|
else if (window.nostr && this._isRealExtension(window.nostr)) {
|
|
|
|
else if (window.nostr && this._isRealExtension(window.nostr)) {
|
|
|
|
extension = window.nostr;
|
|
|
|
extension = window.nostr;
|
|
|
|
console.log('Modal: Using current window.nostr extension:', extension.constructor?.name);
|
|
|
|
// console.log('Modal: Using current window.nostr extension:', extension.constructor?.name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!extension) {
|
|
|
|
if (!extension) {
|
|
|
|
console.log('Modal: No extension detected yet, waiting for deferred detection...');
|
|
|
|
// console.log('Modal: No extension detected yet, waiting for deferred detection...');
|
|
|
|
|
|
|
|
|
|
|
|
// DEFERRED EXTENSION CHECK: Extensions like nos2x might load after our library
|
|
|
|
// DEFERRED EXTENSION CHECK: Extensions like nos2x might load after our library
|
|
|
|
let attempts = 0;
|
|
|
|
let attempts = 0;
|
|
|
|
@@ -382,24 +382,24 @@ class Modal {
|
|
|
|
// Check again for preserved extension (might be set by deferred detection)
|
|
|
|
// Check again for preserved extension (might be set by deferred detection)
|
|
|
|
if (window.NOSTR_LOGIN_LITE?._instance?.preservedExtension) {
|
|
|
|
if (window.NOSTR_LOGIN_LITE?._instance?.preservedExtension) {
|
|
|
|
extension = window.NOSTR_LOGIN_LITE._instance.preservedExtension;
|
|
|
|
extension = window.NOSTR_LOGIN_LITE._instance.preservedExtension;
|
|
|
|
console.log('Modal: Found preserved extension after waiting:', extension.constructor?.name);
|
|
|
|
// console.log('Modal: Found preserved extension after waiting:', extension.constructor?.name);
|
|
|
|
this._tryExtensionLogin(extension);
|
|
|
|
this._tryExtensionLogin(extension);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Check current window.nostr again
|
|
|
|
// Check current window.nostr again
|
|
|
|
if (window.nostr && this._isRealExtension(window.nostr)) {
|
|
|
|
if (window.nostr && this._isRealExtension(window.nostr)) {
|
|
|
|
extension = window.nostr;
|
|
|
|
extension = window.nostr;
|
|
|
|
console.log('Modal: Found extension at window.nostr after waiting:', extension.constructor?.name);
|
|
|
|
// console.log('Modal: Found extension at window.nostr after waiting:', extension.constructor?.name);
|
|
|
|
this._tryExtensionLogin(extension);
|
|
|
|
this._tryExtensionLogin(extension);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Keep trying or give up
|
|
|
|
// Keep trying or give up
|
|
|
|
if (attempts < maxAttempts) {
|
|
|
|
if (attempts < maxAttempts) {
|
|
|
|
setTimeout(checkForExtension, 200);
|
|
|
|
setTimeout(checkForExtension, 200);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
console.log('Modal: No browser extension found after waiting 2 seconds');
|
|
|
|
// console.log('Modal: No browser extension found after waiting 2 seconds');
|
|
|
|
this._showExtensionRequired();
|
|
|
|
this._showExtensionRequired();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
@@ -410,7 +410,7 @@ class Modal {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Use the single detected extension directly - no choice UI
|
|
|
|
// Use the single detected extension directly - no choice UI
|
|
|
|
console.log('Modal: Single extension mode - using extension directly');
|
|
|
|
// console.log('Modal: Single extension mode - using extension directly');
|
|
|
|
this._tryExtensionLogin(extension);
|
|
|
|
this._tryExtensionLogin(extension);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -434,9 +434,9 @@ class Modal {
|
|
|
|
for (const location of locations) {
|
|
|
|
for (const location of locations) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const obj = location.getter();
|
|
|
|
const obj = location.getter();
|
|
|
|
|
|
|
|
|
|
|
|
console.log(`Modal: Checking ${location.name}:`, !!obj, obj?.constructor?.name);
|
|
|
|
// console.log(`Modal: Checking ${location.name}:`, !!obj, obj?.constructor?.name);
|
|
|
|
|
|
|
|
|
|
|
|
if (obj && this._isRealExtension(obj) && !seenExtensions.has(obj)) {
|
|
|
|
if (obj && this._isRealExtension(obj) && !seenExtensions.has(obj)) {
|
|
|
|
extensions.push({
|
|
|
|
extensions.push({
|
|
|
|
name: location.name,
|
|
|
|
name: location.name,
|
|
|
|
@@ -445,26 +445,26 @@ class Modal {
|
|
|
|
extension: obj
|
|
|
|
extension: obj
|
|
|
|
});
|
|
|
|
});
|
|
|
|
seenExtensions.add(obj);
|
|
|
|
seenExtensions.add(obj);
|
|
|
|
console.log(`Modal: ✓ Detected extension at ${location.name} (${obj.constructor?.name})`);
|
|
|
|
// console.log(`Modal: ✓ Detected extension at ${location.name} (${obj.constructor?.name})`);
|
|
|
|
} else if (obj) {
|
|
|
|
} else if (obj) {
|
|
|
|
console.log(`Modal: ✗ Filtered out ${location.name} (${obj.constructor?.name})`);
|
|
|
|
// console.log(`Modal: ✗ Filtered out ${location.name} (${obj.constructor?.name})`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
|
// Location doesn't exist or can't be accessed
|
|
|
|
// Location doesn't exist or can't be accessed
|
|
|
|
console.log(`Modal: ${location.name} not accessible:`, e.message);
|
|
|
|
// console.log(`Modal: ${location.name} not accessible:`, e.message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Also check window.nostr but be extra careful to avoid our library
|
|
|
|
// Also check window.nostr but be extra careful to avoid our library
|
|
|
|
console.log('Modal: Checking window.nostr:', !!window.nostr, window.nostr?.constructor?.name);
|
|
|
|
// console.log('Modal: Checking window.nostr:', !!window.nostr, window.nostr?.constructor?.name);
|
|
|
|
|
|
|
|
|
|
|
|
if (window.nostr) {
|
|
|
|
if (window.nostr) {
|
|
|
|
// Check if window.nostr is our WindowNostr facade with a preserved extension
|
|
|
|
// Check if window.nostr is our WindowNostr facade with a preserved extension
|
|
|
|
if (window.nostr.constructor?.name === 'WindowNostr' && window.nostr.existingNostr) {
|
|
|
|
if (window.nostr.constructor?.name === 'WindowNostr' && window.nostr.existingNostr) {
|
|
|
|
console.log('Modal: Found WindowNostr facade, checking existingNostr for preserved extension');
|
|
|
|
// console.log('Modal: Found WindowNostr facade, checking existingNostr for preserved extension');
|
|
|
|
const preservedExtension = window.nostr.existingNostr;
|
|
|
|
const preservedExtension = window.nostr.existingNostr;
|
|
|
|
console.log('Modal: Preserved extension:', !!preservedExtension, preservedExtension?.constructor?.name);
|
|
|
|
// console.log('Modal: Preserved extension:', !!preservedExtension, preservedExtension?.constructor?.name);
|
|
|
|
|
|
|
|
|
|
|
|
if (preservedExtension && this._isRealExtension(preservedExtension) && !seenExtensions.has(preservedExtension)) {
|
|
|
|
if (preservedExtension && this._isRealExtension(preservedExtension) && !seenExtensions.has(preservedExtension)) {
|
|
|
|
extensions.push({
|
|
|
|
extensions.push({
|
|
|
|
name: 'window.nostr.existingNostr',
|
|
|
|
name: 'window.nostr.existingNostr',
|
|
|
|
@@ -473,7 +473,7 @@ class Modal {
|
|
|
|
extension: preservedExtension
|
|
|
|
extension: preservedExtension
|
|
|
|
});
|
|
|
|
});
|
|
|
|
seenExtensions.add(preservedExtension);
|
|
|
|
seenExtensions.add(preservedExtension);
|
|
|
|
console.log(`Modal: ✓ Detected preserved extension: ${preservedExtension.constructor?.name}`);
|
|
|
|
// console.log(`Modal: ✓ Detected preserved extension: ${preservedExtension.constructor?.name}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Check if window.nostr is directly a real extension (not our facade)
|
|
|
|
// Check if window.nostr is directly a real extension (not our facade)
|
|
|
|
@@ -485,9 +485,9 @@ class Modal {
|
|
|
|
extension: window.nostr
|
|
|
|
extension: window.nostr
|
|
|
|
});
|
|
|
|
});
|
|
|
|
seenExtensions.add(window.nostr);
|
|
|
|
seenExtensions.add(window.nostr);
|
|
|
|
console.log(`Modal: ✓ Detected extension at window.nostr: ${window.nostr.constructor?.name}`);
|
|
|
|
// console.log(`Modal: ✓ Detected extension at window.nostr: ${window.nostr.constructor?.name}`);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
console.log(`Modal: ✗ Filtered out window.nostr (${window.nostr.constructor?.name}) - not a real extension`);
|
|
|
|
// console.log(`Modal: ✗ Filtered out window.nostr (${window.nostr.constructor?.name}) - not a real extension`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -495,27 +495,27 @@ class Modal {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_isRealExtension(obj) {
|
|
|
|
_isRealExtension(obj) {
|
|
|
|
console.log(`Modal: EXTENSIVE DEBUG - _isRealExtension called with:`, obj);
|
|
|
|
// console.log(`Modal: EXTENSIVE DEBUG - _isRealExtension called with:`, obj);
|
|
|
|
console.log(`Modal: Object type: ${typeof obj}`);
|
|
|
|
// console.log(`Modal: Object type: ${typeof obj}`);
|
|
|
|
console.log(`Modal: Object truthy: ${!!obj}`);
|
|
|
|
// console.log(`Modal: Object truthy: ${!!obj}`);
|
|
|
|
|
|
|
|
|
|
|
|
if (!obj || typeof obj !== 'object') {
|
|
|
|
if (!obj || typeof obj !== 'object') {
|
|
|
|
console.log(`Modal: REJECT - Not an object`);
|
|
|
|
// console.log(`Modal: REJECT - Not an object`);
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
console.log(`Modal: getPublicKey type: ${typeof obj.getPublicKey}`);
|
|
|
|
// console.log(`Modal: getPublicKey type: ${typeof obj.getPublicKey}`);
|
|
|
|
console.log(`Modal: signEvent type: ${typeof obj.signEvent}`);
|
|
|
|
// console.log(`Modal: signEvent type: ${typeof obj.signEvent}`);
|
|
|
|
|
|
|
|
|
|
|
|
// Must have required Nostr methods
|
|
|
|
// Must have required Nostr methods
|
|
|
|
if (typeof obj.getPublicKey !== 'function' || typeof obj.signEvent !== 'function') {
|
|
|
|
if (typeof obj.getPublicKey !== 'function' || typeof obj.signEvent !== 'function') {
|
|
|
|
console.log(`Modal: REJECT - Missing required methods`);
|
|
|
|
// console.log(`Modal: REJECT - Missing required methods`);
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Exclude NostrTools library object
|
|
|
|
// Exclude NostrTools library object
|
|
|
|
if (obj === window.NostrTools) {
|
|
|
|
if (obj === window.NostrTools) {
|
|
|
|
console.log(`Modal: REJECT - Is NostrTools object`);
|
|
|
|
// console.log(`Modal: REJECT - Is NostrTools object`);
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -523,10 +523,10 @@ class Modal {
|
|
|
|
// This is the key fix - match the comprehensive test's successful detection logic
|
|
|
|
// This is the key fix - match the comprehensive test's successful detection logic
|
|
|
|
const constructorName = obj.constructor?.name;
|
|
|
|
const constructorName = obj.constructor?.name;
|
|
|
|
const objectKeys = Object.keys(obj);
|
|
|
|
const objectKeys = Object.keys(obj);
|
|
|
|
|
|
|
|
|
|
|
|
console.log(`Modal: Constructor name: "${constructorName}"`);
|
|
|
|
// console.log(`Modal: Constructor name: "${constructorName}"`);
|
|
|
|
console.log(`Modal: Object keys: [${objectKeys.join(', ')}]`);
|
|
|
|
// console.log(`Modal: Object keys: [${objectKeys.join(', ')}]`);
|
|
|
|
|
|
|
|
|
|
|
|
// COMPREHENSIVE TEST LOGIC - Accept anything with required methods that's not our specific library classes
|
|
|
|
// COMPREHENSIVE TEST LOGIC - Accept anything with required methods that's not our specific library classes
|
|
|
|
const isRealExtension = (
|
|
|
|
const isRealExtension = (
|
|
|
|
typeof obj.getPublicKey === 'function' &&
|
|
|
|
typeof obj.getPublicKey === 'function' &&
|
|
|
|
@@ -534,14 +534,14 @@ class Modal {
|
|
|
|
constructorName !== 'WindowNostr' && // Our library class
|
|
|
|
constructorName !== 'WindowNostr' && // Our library class
|
|
|
|
constructorName !== 'NostrLite' // Our main class
|
|
|
|
constructorName !== 'NostrLite' // Our main class
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
console.log(`Modal: Using comprehensive test logic:`);
|
|
|
|
// console.log(`Modal: Using comprehensive test logic:`);
|
|
|
|
console.log(` Has getPublicKey: ${typeof obj.getPublicKey === 'function'}`);
|
|
|
|
// console.log(` Has getPublicKey: ${typeof obj.getPublicKey === 'function'}`);
|
|
|
|
console.log(` Has signEvent: ${typeof obj.signEvent === 'function'}`);
|
|
|
|
// console.log(` Has signEvent: ${typeof obj.signEvent === 'function'}`);
|
|
|
|
console.log(` Not WindowNostr: ${constructorName !== 'WindowNostr'}`);
|
|
|
|
// console.log(` Not WindowNostr: ${constructorName !== 'WindowNostr'}`);
|
|
|
|
console.log(` Not NostrLite: ${constructorName !== 'NostrLite'}`);
|
|
|
|
// console.log(` Not NostrLite: ${constructorName !== 'NostrLite'}`);
|
|
|
|
console.log(` Constructor: "${constructorName}"`);
|
|
|
|
// console.log(` Constructor: "${constructorName}"`);
|
|
|
|
|
|
|
|
|
|
|
|
// Additional debugging for comparison
|
|
|
|
// Additional debugging for comparison
|
|
|
|
const extensionPropChecks = {
|
|
|
|
const extensionPropChecks = {
|
|
|
|
_isEnabled: !!obj._isEnabled,
|
|
|
|
_isEnabled: !!obj._isEnabled,
|
|
|
|
@@ -555,27 +555,27 @@ class Modal {
|
|
|
|
version: !!obj.version,
|
|
|
|
version: !!obj.version,
|
|
|
|
description: !!obj.description
|
|
|
|
description: !!obj.description
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
console.log(`Modal: Extension property analysis:`, extensionPropChecks);
|
|
|
|
// console.log(`Modal: Extension property analysis:`, extensionPropChecks);
|
|
|
|
|
|
|
|
|
|
|
|
const hasExtensionProps = !!(
|
|
|
|
const hasExtensionProps = !!(
|
|
|
|
obj._isEnabled || obj.enabled || obj.kind ||
|
|
|
|
obj._isEnabled || obj.enabled || obj.kind ||
|
|
|
|
obj._eventEmitter || obj._scope || obj._requests || obj._pubkey ||
|
|
|
|
obj._eventEmitter || obj._scope || obj._requests || obj._pubkey ||
|
|
|
|
obj.name || obj.version || obj.description
|
|
|
|
obj.name || obj.version || obj.description
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
const underscoreKeys = objectKeys.filter(key => key.startsWith('_'));
|
|
|
|
const underscoreKeys = objectKeys.filter(key => key.startsWith('_'));
|
|
|
|
const hexToUint8Keys = objectKeys.filter(key => key.startsWith('_hex'));
|
|
|
|
const hexToUint8Keys = objectKeys.filter(key => key.startsWith('_hex'));
|
|
|
|
console.log(`Modal: Underscore keys: [${underscoreKeys.join(', ')}]`);
|
|
|
|
// console.log(`Modal: Underscore keys: [${underscoreKeys.join(', ')}]`);
|
|
|
|
console.log(`Modal: _hex* keys: [${hexToUint8Keys.join(', ')}]`);
|
|
|
|
// console.log(`Modal: _hex* keys: [${hexToUint8Keys.join(', ')}]`);
|
|
|
|
|
|
|
|
|
|
|
|
console.log(`Modal: Additional analysis:`);
|
|
|
|
// console.log(`Modal: Additional analysis:`);
|
|
|
|
console.log(` hasExtensionProps: ${hasExtensionProps}`);
|
|
|
|
// console.log(` hasExtensionProps: ${hasExtensionProps}`);
|
|
|
|
console.log(` hasLibraryMethod (_hexToUint8Array): ${objectKeys.includes('_hexToUint8Array')}`);
|
|
|
|
// console.log(` hasLibraryMethod (_hexToUint8Array): ${objectKeys.includes('_hexToUint8Array')}`);
|
|
|
|
|
|
|
|
|
|
|
|
console.log(`Modal: COMPREHENSIVE TEST LOGIC RESULT: ${isRealExtension ? 'ACCEPT' : 'REJECT'}`);
|
|
|
|
// console.log(`Modal: COMPREHENSIVE TEST LOGIC RESULT: ${isRealExtension ? 'ACCEPT' : 'REJECT'}`);
|
|
|
|
console.log(`Modal: FINAL DECISION for ${constructorName}: ${isRealExtension ? 'ACCEPT' : 'REJECT'}`);
|
|
|
|
// console.log(`Modal: FINAL DECISION for ${constructorName}: ${isRealExtension ? 'ACCEPT' : 'REJECT'}`);
|
|
|
|
|
|
|
|
|
|
|
|
return isRealExtension;
|
|
|
|
return isRealExtension;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -687,7 +687,7 @@ class Modal {
|
|
|
|
// Get pubkey from extension
|
|
|
|
// Get pubkey from extension
|
|
|
|
const pubkey = await extensionObj.getPublicKey();
|
|
|
|
const pubkey = await extensionObj.getPublicKey();
|
|
|
|
console.log('Extension provided pubkey:', pubkey);
|
|
|
|
console.log('Extension provided pubkey:', pubkey);
|
|
|
|
|
|
|
|
|
|
|
|
// Set extension method with the extension object
|
|
|
|
// Set extension method with the extension object
|
|
|
|
this._setAuthMethod('extension', { pubkey, extension: extensionObj });
|
|
|
|
this._setAuthMethod('extension', { pubkey, extension: extensionObj });
|
|
|
|
|
|
|
|
|
|
|
|
@@ -828,8 +828,8 @@ class Modal {
|
|
|
|
textarea.oninput();
|
|
|
|
textarea.oninput();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
console.log('Generated new local secret key (nsec format)');
|
|
|
|
// console.log('Generated new local secret key (nsec format)');
|
|
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Failed to generate local key:', error);
|
|
|
|
console.error('Failed to generate local key:', error);
|
|
|
|
formatHint.textContent = '❌ Failed to generate key - NostrTools not available';
|
|
|
|
formatHint.textContent = '❌ Failed to generate key - NostrTools not available';
|
|
|
|
@@ -1131,69 +1131,79 @@ class Modal {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_setAuthMethod(method, options = {}) {
|
|
|
|
_setAuthMethod(method, options = {}) {
|
|
|
|
// SINGLE-EXTENSION ARCHITECTURE: Handle method switching
|
|
|
|
// console.log('Modal: _setAuthMethod called with:', method, options);
|
|
|
|
console.log('Modal: _setAuthMethod called with:', method, options);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// CRITICAL: Never install facade for extension methods - leave window.nostr as the extension
|
|
|
|
// CRITICAL: Never install facade for extension methods - leave window.nostr as the extension
|
|
|
|
if (method === 'extension') {
|
|
|
|
if (method === 'extension') {
|
|
|
|
console.log('Modal: Extension method - NOT installing facade, leaving window.nostr as extension');
|
|
|
|
// console.log('Modal: Extension method - NOT installing facade, leaving window.nostr as extension');
|
|
|
|
|
|
|
|
|
|
|
|
// Save extension authentication state using global setAuthState function
|
|
|
|
// Save extension authentication state using global setAuthState function
|
|
|
|
if (typeof window.setAuthState === 'function') {
|
|
|
|
if (typeof window.setAuthState === 'function') {
|
|
|
|
console.log('Modal: Saving extension auth state to storage');
|
|
|
|
// console.log('Modal: Saving extension auth state to storage');
|
|
|
|
window.setAuthState({ method, ...options }, { isolateSession: this.options?.isolateSession });
|
|
|
|
window.setAuthState({ method, ...options }, { isolateSession: this.options?.isolateSession });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Emit auth method selection directly for extension
|
|
|
|
// Emit auth method selection directly for extension
|
|
|
|
const event = new CustomEvent('nlMethodSelected', {
|
|
|
|
const event = new CustomEvent('nlMethodSelected', {
|
|
|
|
detail: { method, ...options }
|
|
|
|
detail: { method, ...options }
|
|
|
|
});
|
|
|
|
});
|
|
|
|
window.dispatchEvent(event);
|
|
|
|
window.dispatchEvent(event);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.close();
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// FOR NON-EXTENSION METHODS: Force-install facade with resilience
|
|
|
|
|
|
|
|
// console.log('Modal: Non-extension method - FORCE-INSTALLING facade with resilience:', method);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Store the current extension if any (for potential restoration later)
|
|
|
|
|
|
|
|
const currentExtension = (window.nostr?.constructor?.name !== 'WindowNostr') ? window.nostr : null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Get NostrLite instance for facade operations
|
|
|
|
|
|
|
|
const nostrLiteInstance = window.NOSTR_LOGIN_LITE?._instance;
|
|
|
|
|
|
|
|
if (!nostrLiteInstance || typeof nostrLiteInstance._installFacade !== 'function') {
|
|
|
|
|
|
|
|
console.error('Modal: Cannot access NostrLite instance or _installFacade method');
|
|
|
|
|
|
|
|
// Fallback: emit event anyway
|
|
|
|
|
|
|
|
const event = new CustomEvent('nlMethodSelected', {
|
|
|
|
|
|
|
|
detail: { method, ...options }
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
window.dispatchEvent(event);
|
|
|
|
this.close();
|
|
|
|
this.close();
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// For non-extension methods, we need to ensure WindowNostr facade is available
|
|
|
|
// IMMEDIATE FACADE INSTALLATION
|
|
|
|
console.log('Modal: Non-extension method detected:', method);
|
|
|
|
// console.log('Modal: Installing WindowNostr facade immediately for method:', method);
|
|
|
|
|
|
|
|
const preservedExtension = nostrLiteInstance.preservedExtension || currentExtension;
|
|
|
|
|
|
|
|
nostrLiteInstance._installFacade(preservedExtension, true);
|
|
|
|
|
|
|
|
// console.log('Modal: WindowNostr facade force-installed, current window.nostr:', window.nostr?.constructor?.name);
|
|
|
|
|
|
|
|
|
|
|
|
// Check if we have a preserved extension but no WindowNostr facade installed
|
|
|
|
// DELAYED FACADE RESILIENCE - Reinstall after extension override attempts
|
|
|
|
const hasPreservedExtension = !!window.NOSTR_LOGIN_LITE?._instance?.preservedExtension;
|
|
|
|
const forceReinstallFacade = () => {
|
|
|
|
const hasWindowNostrFacade = window.nostr?.constructor?.name === 'WindowNostr';
|
|
|
|
console.log('Modal: RESILIENCE CHECK - Current window.nostr after delay:', window.nostr?.constructor?.name);
|
|
|
|
|
|
|
|
|
|
|
|
console.log('Modal: Method switching check:');
|
|
|
|
|
|
|
|
console.log(' method:', method);
|
|
|
|
|
|
|
|
console.log(' hasPreservedExtension:', hasPreservedExtension);
|
|
|
|
|
|
|
|
console.log(' hasWindowNostrFacade:', hasWindowNostrFacade);
|
|
|
|
|
|
|
|
console.log(' current window.nostr constructor:', window.nostr?.constructor?.name);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If we have a preserved extension but no facade, install facade for method switching
|
|
|
|
|
|
|
|
if (hasPreservedExtension && !hasWindowNostrFacade) {
|
|
|
|
|
|
|
|
console.log('Modal: Installing WindowNostr facade for method switching (non-extension authentication)');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Get the NostrLite instance and install facade with preserved extension
|
|
|
|
// If facade was overridden by extension, reinstall it
|
|
|
|
const nostrLiteInstance = window.NOSTR_LOGIN_LITE?._instance;
|
|
|
|
if (window.nostr?.constructor?.name !== 'WindowNostr') {
|
|
|
|
if (nostrLiteInstance && typeof nostrLiteInstance._installFacade === 'function') {
|
|
|
|
console.log('Modal: FACADE OVERRIDDEN! Force-reinstalling WindowNostr facade for user choice:', method);
|
|
|
|
const preservedExtension = nostrLiteInstance.preservedExtension;
|
|
|
|
nostrLiteInstance._installFacade(preservedExtension, true);
|
|
|
|
console.log('Modal: Installing facade with preserved extension:', preservedExtension?.constructor?.name);
|
|
|
|
console.log('Modal: Resilient facade force-reinstall complete, window.nostr:', window.nostr?.constructor?.name);
|
|
|
|
|
|
|
|
|
|
|
|
nostrLiteInstance._installFacade(preservedExtension);
|
|
|
|
// Schedule another check in case of persistent extension override
|
|
|
|
console.log('Modal: WindowNostr facade installed for method switching');
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
|
|
if (window.nostr?.constructor?.name !== 'WindowNostr') {
|
|
|
|
|
|
|
|
console.log('Modal: PERSISTENT OVERRIDE! Final facade force-reinstall for method:', method);
|
|
|
|
|
|
|
|
nostrLiteInstance._installFacade(preservedExtension, true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, 1000);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
console.error('Modal: Cannot access NostrLite instance or _installFacade method');
|
|
|
|
console.log('Modal: Facade persistence verified - no override detected');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// If no extension at all, ensure facade is installed for local/NIP-46/readonly methods
|
|
|
|
// Schedule resilience checks at multiple intervals
|
|
|
|
else if (!hasPreservedExtension && !hasWindowNostrFacade) {
|
|
|
|
// setTimeout(forceReinstallFacade, 100); // Quick check
|
|
|
|
console.log('Modal: Installing WindowNostr facade for non-extension methods (no extension detected)');
|
|
|
|
// setTimeout(forceReinstallFacade, 500); // Main check
|
|
|
|
|
|
|
|
// setTimeout(forceReinstallFacade, 1500); // Final check
|
|
|
|
const nostrLiteInstance = window.NOSTR_LOGIN_LITE?._instance;
|
|
|
|
|
|
|
|
if (nostrLiteInstance && typeof nostrLiteInstance._installFacade === 'function') {
|
|
|
|
|
|
|
|
nostrLiteInstance._installFacade();
|
|
|
|
|
|
|
|
console.log('Modal: WindowNostr facade installed for non-extension methods');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Emit auth method selection
|
|
|
|
// Emit auth method selection
|
|
|
|
const event = new CustomEvent('nlMethodSelected', {
|
|
|
|
const event = new CustomEvent('nlMethodSelected', {
|
|
|
|
@@ -1380,7 +1390,7 @@ class Modal {
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
console.log('Bunker key validation failed:', error.message);
|
|
|
|
// console.log('Bunker key validation failed:', error.message);
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -1433,7 +1443,7 @@ class Modal {
|
|
|
|
|
|
|
|
|
|
|
|
async _performNip46Connect(bunkerPubkey) {
|
|
|
|
async _performNip46Connect(bunkerPubkey) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
console.log('Starting NIP-46 connection to bunker:', bunkerPubkey);
|
|
|
|
// console.log('Starting NIP-46 connection to bunker:', bunkerPubkey);
|
|
|
|
|
|
|
|
|
|
|
|
// Check if nostr-tools NIP-46 is available
|
|
|
|
// Check if nostr-tools NIP-46 is available
|
|
|
|
if (!window.NostrTools?.nip46) {
|
|
|
|
if (!window.NostrTools?.nip46) {
|
|
|
|
@@ -1441,41 +1451,41 @@ class Modal {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Use nostr-tools to parse bunker input - this handles all formats correctly
|
|
|
|
// Use nostr-tools to parse bunker input - this handles all formats correctly
|
|
|
|
console.log('Parsing bunker input with nostr-tools...');
|
|
|
|
// console.log('Parsing bunker input with nostr-tools...');
|
|
|
|
const bunkerPointer = await window.NostrTools.nip46.parseBunkerInput(bunkerPubkey);
|
|
|
|
const bunkerPointer = await window.NostrTools.nip46.parseBunkerInput(bunkerPubkey);
|
|
|
|
|
|
|
|
|
|
|
|
if (!bunkerPointer) {
|
|
|
|
if (!bunkerPointer) {
|
|
|
|
throw new Error('Unable to parse bunker connection string or resolve NIP-05 identifier');
|
|
|
|
throw new Error('Unable to parse bunker connection string or resolve NIP-05 identifier');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
console.log('Parsed bunker pointer:', bunkerPointer);
|
|
|
|
// console.log('Parsed bunker pointer:', bunkerPointer);
|
|
|
|
|
|
|
|
|
|
|
|
// Create local client keypair for this session
|
|
|
|
// Create local client keypair for this session
|
|
|
|
const localSecretKey = window.NostrTools.generateSecretKey();
|
|
|
|
const localSecretKey = window.NostrTools.generateSecretKey();
|
|
|
|
console.log('Generated local client keypair for NIP-46 session');
|
|
|
|
// console.log('Generated local client keypair for NIP-46 session');
|
|
|
|
|
|
|
|
|
|
|
|
// Use nostr-tools BunkerSigner factory method (not constructor - it's private)
|
|
|
|
// Use nostr-tools BunkerSigner factory method (not constructor - it's private)
|
|
|
|
console.log('Creating nip46 BunkerSigner...');
|
|
|
|
// console.log('Creating nip46 BunkerSigner...');
|
|
|
|
const signer = window.NostrTools.nip46.BunkerSigner.fromBunker(localSecretKey, bunkerPointer, {
|
|
|
|
const signer = window.NostrTools.nip46.BunkerSigner.fromBunker(localSecretKey, bunkerPointer, {
|
|
|
|
onauth: (url) => {
|
|
|
|
onauth: (url) => {
|
|
|
|
console.log('Received auth URL from bunker:', url);
|
|
|
|
// console.log('Received auth URL from bunker:', url);
|
|
|
|
// Open auth URL in popup or redirect
|
|
|
|
// Open auth URL in popup or redirect
|
|
|
|
window.open(url, '_blank', 'width=600,height=800');
|
|
|
|
window.open(url, '_blank', 'width=600,height=800');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
console.log('NIP-46 BunkerSigner created successfully');
|
|
|
|
// console.log('NIP-46 BunkerSigner created successfully');
|
|
|
|
|
|
|
|
|
|
|
|
// Skip ping test - NIP-46 works through relays, not direct connection
|
|
|
|
// Skip ping test - NIP-46 works through relays, not direct connection
|
|
|
|
// Try to connect directly (this may trigger auth flow)
|
|
|
|
// Try to connect directly (this may trigger auth flow)
|
|
|
|
console.log('Attempting NIP-46 connect...');
|
|
|
|
// console.log('Attempting NIP-46 connect...');
|
|
|
|
await signer.connect();
|
|
|
|
await signer.connect();
|
|
|
|
console.log('NIP-46 connect successful');
|
|
|
|
// console.log('NIP-46 connect successful');
|
|
|
|
|
|
|
|
|
|
|
|
// Get the user's public key from the bunker
|
|
|
|
// Get the user's public key from the bunker
|
|
|
|
console.log('Getting public key from bunker...');
|
|
|
|
// console.log('Getting public key from bunker...');
|
|
|
|
const userPubkey = await signer.getPublicKey();
|
|
|
|
const userPubkey = await signer.getPublicKey();
|
|
|
|
console.log('NIP-46 user public key:', userPubkey);
|
|
|
|
// console.log('NIP-46 user public key:', userPubkey);
|
|
|
|
|
|
|
|
|
|
|
|
// Store the NIP-46 authentication info
|
|
|
|
// Store the NIP-46 authentication info
|
|
|
|
const nip46Info = {
|
|
|
|
const nip46Info = {
|
|
|
|
@@ -1489,7 +1499,7 @@ class Modal {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
console.log('NOSTR_LOGIN_LITE NIP-46 connection established successfully!');
|
|
|
|
// console.log('NOSTR_LOGIN_LITE NIP-46 connection established successfully!');
|
|
|
|
|
|
|
|
|
|
|
|
// Set as current auth method
|
|
|
|
// Set as current auth method
|
|
|
|
this._setAuthMethod('nip46', nip46Info);
|
|
|
|
this._setAuthMethod('nip46', nip46Info);
|
|
|
|
@@ -1662,8 +1672,8 @@ class Modal {
|
|
|
|
textarea.oninput();
|
|
|
|
textarea.oninput();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
console.log('Generated new seed phrase:', mnemonic.split(/\s+/).length, 'words');
|
|
|
|
// console.log('Generated new seed phrase:', mnemonic.split(/\s+/).length, 'words');
|
|
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Failed to generate seed phrase:', error);
|
|
|
|
console.error('Failed to generate seed phrase:', error);
|
|
|
|
formatHint.textContent = '❌ Failed to generate seed phrase - NIP-06 not available';
|
|
|
|
formatHint.textContent = '❌ Failed to generate seed phrase - NIP-06 not available';
|
|
|
|
@@ -1680,7 +1690,7 @@ class Modal {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const words = mnemonic.trim().split(/\s+/);
|
|
|
|
const words = mnemonic.trim().split(/\s+/);
|
|
|
|
|
|
|
|
|
|
|
|
// Must be 12 or 24 words
|
|
|
|
// Must be 12 or 24 words
|
|
|
|
if (words.length !== 12 && words.length !== 24) {
|
|
|
|
if (words.length !== 12 && words.length !== 24) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
@@ -1690,7 +1700,7 @@ class Modal {
|
|
|
|
window.NostrTools.nip06.privateKeyFromSeedWords(mnemonic, '', 0);
|
|
|
|
window.NostrTools.nip06.privateKeyFromSeedWords(mnemonic, '', 0);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
console.log('Mnemonic validation failed:', error.message);
|
|
|
|
// console.log('Mnemonic validation failed:', error.message);
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -1732,7 +1742,7 @@ class Modal {
|
|
|
|
throw new Error('Failed to derive any accounts from seed phrase');
|
|
|
|
throw new Error('Failed to derive any accounts from seed phrase');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
console.log(`Successfully derived ${accounts.length} accounts from seed phrase`);
|
|
|
|
// console.log(`Successfully derived ${accounts.length} accounts from seed phrase`);
|
|
|
|
this._showAccountSelection(accounts);
|
|
|
|
this._showAccountSelection(accounts);
|
|
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
@@ -1828,8 +1838,8 @@ class Modal {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_selectAccount(account) {
|
|
|
|
_selectAccount(account) {
|
|
|
|
console.log('Selected account:', account.index, account.npub);
|
|
|
|
// console.log('Selected account:', account.index, account.npub);
|
|
|
|
|
|
|
|
|
|
|
|
// Use the same auth method as local keys, but with seedphrase identifier
|
|
|
|
// Use the same auth method as local keys, but with seedphrase identifier
|
|
|
|
this._setAuthMethod('local', {
|
|
|
|
this._setAuthMethod('local', {
|
|
|
|
secret: account.nsec,
|
|
|
|
secret: account.nsec,
|