staging #223

Merged
b merged 28 commits from staging into main 2024-10-09 13:50:23 +00:00
5 changed files with 21 additions and 26 deletions
Showing only changes of commit f09d9b2378 - Show all commits

View File

@ -1,7 +1,6 @@
import { EventTemplate, UnsignedEvent } from 'nostr-tools'
import { WindowNostr } from 'nostr-tools/nip07'
import { EventEmitter } from 'tseep'
import { AuthState } from '../store/auth/types'
import store from '../store/store'
import { SignedEvent } from '../types'
import { LoginMethodContext } from '../services/LoginMethodStrategy/loginMethodContext'
@ -37,7 +36,7 @@ export class NostrController extends EventEmitter {
*/
nip44Encrypt = async (receiver: string, content: string) => {
// Retrieve the current login method from the application's redux state.
const loginMethod = (store.getState().auth as AuthState).loginMethod
const loginMethod = store.getState().auth.loginMethod
const context = new LoginMethodContext(loginMethod)
// Handle encryption when the login method is via an extension.
@ -54,7 +53,7 @@ export class NostrController extends EventEmitter {
*/
nip44Decrypt = async (sender: string, content: string) => {
// Retrieve the current login method from the application's redux state.
const loginMethod = (store.getState().auth as AuthState).loginMethod
const loginMethod = store.getState().auth.loginMethod
const context = new LoginMethodContext(loginMethod)
// Handle decryption
@ -70,14 +69,14 @@ export class NostrController extends EventEmitter {
signEvent = async (
event: UnsignedEvent | EventTemplate
): Promise<SignedEvent> => {
const loginMethod = (store.getState().auth as AuthState).loginMethod
const loginMethod = store.getState().auth.loginMethod
const context = new LoginMethodContext(loginMethod)
return await context.signEvent(event)
}
nip04Encrypt = async (receiver: string, content: string): Promise<string> => {
const loginMethod = (store.getState().auth as AuthState).loginMethod
const loginMethod = store.getState().auth.loginMethod
const context = new LoginMethodContext(loginMethod)
return await context.nip04Encrypt(receiver, content)
@ -91,7 +90,7 @@ export class NostrController extends EventEmitter {
* @returns A promise that resolves to the decrypted content.
*/
nip04Decrypt = async (sender: string, content: string): Promise<string> => {
const loginMethod = (store.getState().auth as AuthState).loginMethod
const loginMethod = store.getState().auth.loginMethod
const context = new LoginMethodContext(loginMethod)
return await context.nip04Decrypt(sender, content)

View File

@ -18,7 +18,6 @@ import { toast } from 'react-toastify'
import { verifyEvent } from 'nostr-tools'
import { Event } from 'nostr-tools'
import store from '../store/store'
import { AuthState } from '../store/auth/types'
import { NostrController } from '../controllers'
import { MetaParseError } from '../types/errors/MetaParseError'
@ -143,7 +142,7 @@ export const useSigitMeta = (meta: Meta): FlatMeta => {
if (meta.keys) {
const { sender, keys } = meta.keys
// Retrieve the user's public key from the state
const usersPubkey = (store.getState().auth as AuthState).usersPubkey!
const usersPubkey = store.getState().auth.usersPubkey!
const usersNpub = hexToNpub(usersPubkey)
// Check if the user's public key is in the keys object

View File

@ -8,7 +8,7 @@ import {
} from 'nostr-tools'
import { SignedEvent } from '../../types'
import store from '../../store/store'
import { AuthState, LoginMethod } from '../../store/auth/types'
import { LoginMethod } from '../../store/auth/types'
import { LoginMethodStrategy } from './loginMethodStrategy'
import { verifySignedEvent } from '../../utils/nostr'
@ -20,7 +20,7 @@ import { verifySignedEvent } from '../../utils/nostr'
*/
export class PrivateKeyStrategy extends LoginMethodStrategy {
async nip04Encrypt(receiver: string, content: string): Promise<string> {
const keys = (store.getState().auth as AuthState).keyPair
const keys = store.getState().auth.keyPair
if (!keys) {
throw new Error(
@ -36,7 +36,7 @@ export class PrivateKeyStrategy extends LoginMethodStrategy {
}
async nip04Decrypt(sender: string, content: string): Promise<string> {
const keys = (store.getState().auth as AuthState).keyPair
const keys = store.getState().auth.keyPair
if (!keys) {
throw new Error(
@ -52,7 +52,7 @@ export class PrivateKeyStrategy extends LoginMethodStrategy {
}
async nip44Encrypt(receiver: string, content: string): Promise<string> {
const keys = (store.getState().auth as AuthState).keyPair
const keys = store.getState().auth.keyPair
// Check if the private and public key pair is available.
if (!keys) {
@ -78,7 +78,7 @@ export class PrivateKeyStrategy extends LoginMethodStrategy {
}
async nip44Decrypt(sender: string, content: string): Promise<string> {
const keys = (store.getState().auth as AuthState).keyPair
const keys = store.getState().auth.keyPair
// Check if the private and public key pair is available.
if (!keys) {
@ -104,7 +104,7 @@ export class PrivateKeyStrategy extends LoginMethodStrategy {
}
async signEvent(event: UnsignedEvent | EventTemplate): Promise<SignedEvent> {
const keys = (store.getState().auth as AuthState).keyPair
const keys = store.getState().auth.keyPair
if (!keys) {
return Promise.reject(

View File

@ -10,7 +10,6 @@ import {
} from 'nostr-tools'
import { toast } from 'react-toastify'
import { NostrController } from '../controllers'
import { AuthState } from '../store/auth/types'
import store from '../store/store'
import { CreateSignatureEventContent, Meta } from '../types'
import { hexToNpub, unixNow } from './nostr'
@ -232,7 +231,7 @@ export const extractZipUrlAndEncryptionKey = async (meta: Meta) => {
const zipUrl = createSignatureContent.zipUrl
// Retrieve the user's public key from the state
const usersPubkey = (store.getState().auth as AuthState).usersPubkey!
const usersPubkey = store.getState().auth.usersPubkey!
const usersNpub = hexToNpub(usersPubkey)
// Return null if the metadata does not contain keys

View File

@ -27,8 +27,7 @@ import {
updateProcessedGiftWraps,
updateUserAppData as updateUserAppDataAction
} from '../store/actions'
import { AuthState, Keys } from '../store/auth/types'
import { RelaysState } from '../store/relays/types'
import { Keys } from '../store/auth/types'
import store from '../store/store'
import { Meta, ProfileMetadata, SignedEvent, UserAppData } from '../types'
import { getDefaultRelayMap } from './relays'
@ -41,7 +40,7 @@ import { SIGIT_BLOSSOM } from './const.ts'
* Generates a `d` tag for userAppData
*/
const getDTagForUserAppData = async (): Promise<string | null> => {
const isLoggedIn = store.getState().auth?.loggedIn
const isLoggedIn = store.getState().auth.loggedIn
const pubkey = store.getState().auth?.usersPubkey
if (!isLoggedIn || !pubkey) {
@ -360,7 +359,7 @@ export const getUsersAppData = async (): Promise<UserAppData | null> => {
const relays: string[] = []
// Retrieve the user's public key and relay map from the Redux store
const usersPubkey = (store.getState().auth as AuthState).usersPubkey!
const usersPubkey = store.getState().auth.usersPubkey!
const relayMap = store.getState().relays?.map
// Check if relayMap is undefined in the Redux store
@ -572,7 +571,7 @@ export const updateUsersAppData = async (meta: Meta) => {
})
}
const usersPubkey = (store.getState().auth as AuthState).usersPubkey!
const usersPubkey = store.getState().auth.usersPubkey!
// encrypt content for storing in kind 30078 event
const nostrController = NostrController.getInstance()
@ -619,8 +618,7 @@ export const updateUsersAppData = async (meta: Meta) => {
if (!signedEvent) return null
const relayMap =
(store.getState().relays as RelaysState).map || getDefaultRelayMap()
const relayMap = store.getState().relays.map || getDefaultRelayMap()
const writeRelays = Object.keys(relayMap).filter((key) => relayMap[key].write)
const publishResult = await Promise.race([
@ -878,8 +876,8 @@ export const subscribeForSigits = async (pubkey: string) => {
}
const processReceivedEvent = async (event: Event, difficulty: number = 5) => {
const processedEvents = (store.getState().userAppData as UserAppData)
.processedGiftWraps
const processedEvents = store.getState().userAppData?.processedGiftWraps || []
if (processedEvents.includes(event.id)) return
store.dispatch(updateProcessedGiftWraps([...processedEvents, event.id]))
@ -930,7 +928,7 @@ const processReceivedEvent = async (event: Event, difficulty: number = 5) => {
*/
export const sendNotification = async (receiver: string, meta: Meta) => {
// Retrieve the user's public key from the state
const usersPubkey = (store.getState().auth as AuthState).usersPubkey!
const usersPubkey = store.getState().auth.usersPubkey!
// Create an unsigned event object with the provided metadata
const unsignedEvent: UnsignedEvent = {