|
|
|
@ -6,9 +6,10 @@ import { getNIP07Signer, signEventWithNIP07, getPublicKeyWithNIP07 } from '../au |
|
|
|
import { signEventWithNsec, getPublicKeyFromNsec } from '../auth/nsec-signer.js'; |
|
|
|
import { signEventWithNsec, getPublicKeyFromNsec } from '../auth/nsec-signer.js'; |
|
|
|
import { |
|
|
|
import { |
|
|
|
signEventWithAnonymous, |
|
|
|
signEventWithAnonymous, |
|
|
|
generateAnonymousKey |
|
|
|
generateAnonymousKey, |
|
|
|
|
|
|
|
getStoredAnonymousKey |
|
|
|
} from '../auth/anonymous-signer.js'; |
|
|
|
} from '../auth/anonymous-signer.js'; |
|
|
|
import { decryptPrivateKey } from '../security/key-management.js'; |
|
|
|
import { decryptPrivateKey, encryptPrivateKey } from '../security/key-management.js'; |
|
|
|
import { sessionManager, type AuthMethod } from '../auth/session-manager.js'; |
|
|
|
import { sessionManager, type AuthMethod } from '../auth/session-manager.js'; |
|
|
|
import { fetchRelayLists, fetchProfile } from '../user-data.js'; |
|
|
|
import { fetchRelayLists, fetchProfile } from '../user-data.js'; |
|
|
|
import { nostrClient } from './nostr-client.js'; |
|
|
|
import { nostrClient } from './nostr-client.js'; |
|
|
|
@ -158,13 +159,11 @@ export async function authenticateWithNsec( |
|
|
|
throw new Error('Stored nsec key not found'); |
|
|
|
throw new Error('Stored nsec key not found'); |
|
|
|
} |
|
|
|
} |
|
|
|
// Verify the decrypted nsec matches the expected pubkey
|
|
|
|
// Verify the decrypted nsec matches the expected pubkey
|
|
|
|
const { getPublicKeyFromNsec } = await import('../auth/nsec-signer.js'); |
|
|
|
|
|
|
|
const derivedPubkey = await getPublicKeyFromNsec(decryptedNsec); |
|
|
|
const derivedPubkey = await getPublicKeyFromNsec(decryptedNsec); |
|
|
|
if (derivedPubkey !== pubkey) { |
|
|
|
if (derivedPubkey !== pubkey) { |
|
|
|
throw new Error('Stored nsec key does not match the expected pubkey - key may be corrupted'); |
|
|
|
throw new Error('Stored nsec key does not match the expected pubkey - key may be corrupted'); |
|
|
|
} |
|
|
|
} |
|
|
|
// Encrypt to ncryptsec format for signing
|
|
|
|
// Encrypt to ncryptsec format for signing
|
|
|
|
const { encryptPrivateKey } = await import('../security/key-management.js'); |
|
|
|
|
|
|
|
const ncryptsec = await encryptPrivateKey(decryptedNsec, session.password); |
|
|
|
const ncryptsec = await encryptPrivateKey(decryptedNsec, session.password); |
|
|
|
return signEventWithNsec(event, ncryptsec, session.password); |
|
|
|
return signEventWithNsec(event, ncryptsec, session.password); |
|
|
|
} catch (error) { |
|
|
|
} catch (error) { |
|
|
|
@ -201,7 +200,6 @@ export async function authenticateWithStoredAnonymous( |
|
|
|
password: string |
|
|
|
password: string |
|
|
|
): Promise<string> { |
|
|
|
): Promise<string> { |
|
|
|
// Verify the key exists and password is correct by trying to decrypt
|
|
|
|
// Verify the key exists and password is correct by trying to decrypt
|
|
|
|
const { getStoredAnonymousKey } = await import('../auth/anonymous-signer.js'); |
|
|
|
|
|
|
|
const decryptedNsec = await getStoredAnonymousKey(pubkey, password); |
|
|
|
const decryptedNsec = await getStoredAnonymousKey(pubkey, password); |
|
|
|
if (!decryptedNsec) { |
|
|
|
if (!decryptedNsec) { |
|
|
|
throw new Error('Invalid password or key not found'); |
|
|
|
throw new Error('Invalid password or key not found'); |
|
|
|
|