Log out user if extension's pubkey and auth's pubkey are different #295

Merged
b merged 6 commits from 290-user-ext-log-missmatch into staging 2025-01-02 09:44:28 +00:00
Showing only changes of commit c96a7fac4f - Show all commits

View File

@ -363,11 +363,21 @@ export const createWrap = (unsignedEvent: UnsignedEvent, receiver: string) => {
* @returns The user application data or null if an error occurs or no data is found. * @returns The user application data or null if an error occurs or no data is found.
*/ */
export const getUsersAppData = async (): Promise<UserAppData | null> => { export const getUsersAppData = async (): Promise<UserAppData | null> => {
// Get an instance of the NostrController
const nostrController = NostrController.getInstance()
// Initialize an array to hold relay URLs // Initialize an array to hold relay URLs
const relays: string[] = [] const relays: string[] = []
// Retrieve the user's public key and relay map from the Redux store // Retrieve the user's public key and relay map from the Redux store
const usersPubkey = store.getState().auth.usersPubkey! const usersPubkey = store.getState().auth.usersPubkey!
// Decryption can fail down in the code if extension options changed
// Forcefully log out the user if we detect missmatch between pubkeys
if (usersPubkey !== (await nostrController.capturePublicKey())) {
return null
}
const relayMap = store.getState().relays?.map const relayMap = store.getState().relays?.map
// Check if relayMap is undefined in the Redux store // Check if relayMap is undefined in the Redux store
@ -448,9 +458,6 @@ export const getUsersAppData = async (): Promise<UserAppData | null> => {
} }
} }
// Get an instance of the NostrController
const nostrController = NostrController.getInstance()
// Decrypt the encrypted content // Decrypt the encrypted content
const decrypted = await nostrController const decrypted = await nostrController
.nip04Decrypt(usersPubkey, encryptedContent) .nip04Decrypt(usersPubkey, encryptedContent)