staging #223
@ -1,7 +1,6 @@
|
|||||||
import { EventTemplate, UnsignedEvent } from 'nostr-tools'
|
import { EventTemplate, UnsignedEvent } from 'nostr-tools'
|
||||||
import { WindowNostr } from 'nostr-tools/nip07'
|
import { WindowNostr } from 'nostr-tools/nip07'
|
||||||
import { EventEmitter } from 'tseep'
|
import { EventEmitter } from 'tseep'
|
||||||
import { AuthState } from '../store/auth/types'
|
|
||||||
import store from '../store/store'
|
import store from '../store/store'
|
||||||
import { SignedEvent } from '../types'
|
import { SignedEvent } from '../types'
|
||||||
import { LoginMethodContext } from '../services/LoginMethodStrategy/loginMethodContext'
|
import { LoginMethodContext } from '../services/LoginMethodStrategy/loginMethodContext'
|
||||||
@ -37,7 +36,7 @@ export class NostrController extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
nip44Encrypt = async (receiver: string, content: string) => {
|
nip44Encrypt = async (receiver: string, content: string) => {
|
||||||
// Retrieve the current login method from the application's redux state.
|
// 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)
|
const context = new LoginMethodContext(loginMethod)
|
||||||
|
|
||||||
// Handle encryption when the login method is via an extension.
|
// 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) => {
|
nip44Decrypt = async (sender: string, content: string) => {
|
||||||
// Retrieve the current login method from the application's redux state.
|
// 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)
|
const context = new LoginMethodContext(loginMethod)
|
||||||
|
|
||||||
// Handle decryption
|
// Handle decryption
|
||||||
@ -70,14 +69,14 @@ export class NostrController extends EventEmitter {
|
|||||||
signEvent = async (
|
signEvent = async (
|
||||||
event: UnsignedEvent | EventTemplate
|
event: UnsignedEvent | EventTemplate
|
||||||
): Promise<SignedEvent> => {
|
): Promise<SignedEvent> => {
|
||||||
const loginMethod = (store.getState().auth as AuthState).loginMethod
|
const loginMethod = store.getState().auth.loginMethod
|
||||||
const context = new LoginMethodContext(loginMethod)
|
const context = new LoginMethodContext(loginMethod)
|
||||||
|
|
||||||
return await context.signEvent(event)
|
return await context.signEvent(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
nip04Encrypt = async (receiver: string, content: string): Promise<string> => {
|
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)
|
const context = new LoginMethodContext(loginMethod)
|
||||||
|
|
||||||
return await context.nip04Encrypt(receiver, content)
|
return await context.nip04Encrypt(receiver, content)
|
||||||
@ -91,7 +90,7 @@ export class NostrController extends EventEmitter {
|
|||||||
* @returns A promise that resolves to the decrypted content.
|
* @returns A promise that resolves to the decrypted content.
|
||||||
*/
|
*/
|
||||||
nip04Decrypt = async (sender: string, content: string): Promise<string> => {
|
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)
|
const context = new LoginMethodContext(loginMethod)
|
||||||
|
|
||||||
return await context.nip04Decrypt(sender, content)
|
return await context.nip04Decrypt(sender, content)
|
||||||
|
@ -18,7 +18,6 @@ import { toast } from 'react-toastify'
|
|||||||
import { verifyEvent } from 'nostr-tools'
|
import { verifyEvent } from 'nostr-tools'
|
||||||
import { Event } from 'nostr-tools'
|
import { Event } from 'nostr-tools'
|
||||||
import store from '../store/store'
|
import store from '../store/store'
|
||||||
import { AuthState } from '../store/auth/types'
|
|
||||||
import { NostrController } from '../controllers'
|
import { NostrController } from '../controllers'
|
||||||
import { MetaParseError } from '../types/errors/MetaParseError'
|
import { MetaParseError } from '../types/errors/MetaParseError'
|
||||||
|
|
||||||
@ -143,7 +142,7 @@ export const useSigitMeta = (meta: Meta): FlatMeta => {
|
|||||||
if (meta.keys) {
|
if (meta.keys) {
|
||||||
const { sender, keys } = meta.keys
|
const { sender, keys } = meta.keys
|
||||||
// Retrieve the user's public key from the state
|
// 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)
|
const usersNpub = hexToNpub(usersPubkey)
|
||||||
|
|
||||||
// Check if the user's public key is in the keys object
|
// Check if the user's public key is in the keys object
|
||||||
|
@ -8,7 +8,7 @@ import {
|
|||||||
} from 'nostr-tools'
|
} from 'nostr-tools'
|
||||||
import { SignedEvent } from '../../types'
|
import { SignedEvent } from '../../types'
|
||||||
import store from '../../store/store'
|
import store from '../../store/store'
|
||||||
import { AuthState, LoginMethod } from '../../store/auth/types'
|
import { LoginMethod } from '../../store/auth/types'
|
||||||
import { LoginMethodStrategy } from './loginMethodStrategy'
|
import { LoginMethodStrategy } from './loginMethodStrategy'
|
||||||
import { verifySignedEvent } from '../../utils/nostr'
|
import { verifySignedEvent } from '../../utils/nostr'
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ import { verifySignedEvent } from '../../utils/nostr'
|
|||||||
*/
|
*/
|
||||||
export class PrivateKeyStrategy extends LoginMethodStrategy {
|
export class PrivateKeyStrategy extends LoginMethodStrategy {
|
||||||
async nip04Encrypt(receiver: string, content: string): Promise<string> {
|
async nip04Encrypt(receiver: string, content: string): Promise<string> {
|
||||||
const keys = (store.getState().auth as AuthState).keyPair
|
const keys = store.getState().auth.keyPair
|
||||||
|
|
||||||
if (!keys) {
|
if (!keys) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@ -36,7 +36,7 @@ export class PrivateKeyStrategy extends LoginMethodStrategy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async nip04Decrypt(sender: string, content: string): Promise<string> {
|
async nip04Decrypt(sender: string, content: string): Promise<string> {
|
||||||
const keys = (store.getState().auth as AuthState).keyPair
|
const keys = store.getState().auth.keyPair
|
||||||
|
|
||||||
if (!keys) {
|
if (!keys) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@ -52,7 +52,7 @@ export class PrivateKeyStrategy extends LoginMethodStrategy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async nip44Encrypt(receiver: string, content: string): Promise<string> {
|
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.
|
// Check if the private and public key pair is available.
|
||||||
if (!keys) {
|
if (!keys) {
|
||||||
@ -78,7 +78,7 @@ export class PrivateKeyStrategy extends LoginMethodStrategy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async nip44Decrypt(sender: string, content: string): Promise<string> {
|
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.
|
// Check if the private and public key pair is available.
|
||||||
if (!keys) {
|
if (!keys) {
|
||||||
@ -104,7 +104,7 @@ export class PrivateKeyStrategy extends LoginMethodStrategy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async signEvent(event: UnsignedEvent | EventTemplate): Promise<SignedEvent> {
|
async signEvent(event: UnsignedEvent | EventTemplate): Promise<SignedEvent> {
|
||||||
const keys = (store.getState().auth as AuthState).keyPair
|
const keys = store.getState().auth.keyPair
|
||||||
|
|
||||||
if (!keys) {
|
if (!keys) {
|
||||||
return Promise.reject(
|
return Promise.reject(
|
||||||
|
@ -10,7 +10,6 @@ import {
|
|||||||
} from 'nostr-tools'
|
} from 'nostr-tools'
|
||||||
import { toast } from 'react-toastify'
|
import { toast } from 'react-toastify'
|
||||||
import { NostrController } from '../controllers'
|
import { NostrController } from '../controllers'
|
||||||
import { AuthState } from '../store/auth/types'
|
|
||||||
import store from '../store/store'
|
import store from '../store/store'
|
||||||
import { CreateSignatureEventContent, Meta } from '../types'
|
import { CreateSignatureEventContent, Meta } from '../types'
|
||||||
import { hexToNpub, unixNow } from './nostr'
|
import { hexToNpub, unixNow } from './nostr'
|
||||||
@ -232,7 +231,7 @@ export const extractZipUrlAndEncryptionKey = async (meta: Meta) => {
|
|||||||
const zipUrl = createSignatureContent.zipUrl
|
const zipUrl = createSignatureContent.zipUrl
|
||||||
|
|
||||||
// Retrieve the user's public key from the state
|
// 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)
|
const usersNpub = hexToNpub(usersPubkey)
|
||||||
|
|
||||||
// Return null if the metadata does not contain keys
|
// Return null if the metadata does not contain keys
|
||||||
|
@ -27,8 +27,7 @@ import {
|
|||||||
updateProcessedGiftWraps,
|
updateProcessedGiftWraps,
|
||||||
updateUserAppData as updateUserAppDataAction
|
updateUserAppData as updateUserAppDataAction
|
||||||
} from '../store/actions'
|
} from '../store/actions'
|
||||||
import { AuthState, Keys } from '../store/auth/types'
|
import { Keys } from '../store/auth/types'
|
||||||
import { RelaysState } from '../store/relays/types'
|
|
||||||
import store from '../store/store'
|
import store from '../store/store'
|
||||||
import { Meta, ProfileMetadata, SignedEvent, UserAppData } from '../types'
|
import { Meta, ProfileMetadata, SignedEvent, UserAppData } from '../types'
|
||||||
import { getDefaultRelayMap } from './relays'
|
import { getDefaultRelayMap } from './relays'
|
||||||
@ -41,7 +40,7 @@ import { SIGIT_BLOSSOM } from './const.ts'
|
|||||||
* Generates a `d` tag for userAppData
|
* Generates a `d` tag for userAppData
|
||||||
*/
|
*/
|
||||||
const getDTagForUserAppData = async (): Promise<string | null> => {
|
const getDTagForUserAppData = async (): Promise<string | null> => {
|
||||||
const isLoggedIn = store.getState().auth?.loggedIn
|
const isLoggedIn = store.getState().auth.loggedIn
|
||||||
const pubkey = store.getState().auth?.usersPubkey
|
const pubkey = store.getState().auth?.usersPubkey
|
||||||
|
|
||||||
if (!isLoggedIn || !pubkey) {
|
if (!isLoggedIn || !pubkey) {
|
||||||
@ -360,7 +359,7 @@ export const getUsersAppData = async (): Promise<UserAppData | null> => {
|
|||||||
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 as AuthState).usersPubkey!
|
const usersPubkey = store.getState().auth.usersPubkey!
|
||||||
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
|
||||||
@ -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
|
// encrypt content for storing in kind 30078 event
|
||||||
const nostrController = NostrController.getInstance()
|
const nostrController = NostrController.getInstance()
|
||||||
@ -619,8 +618,7 @@ export const updateUsersAppData = async (meta: Meta) => {
|
|||||||
|
|
||||||
if (!signedEvent) return null
|
if (!signedEvent) return null
|
||||||
|
|
||||||
const relayMap =
|
const relayMap = store.getState().relays.map || getDefaultRelayMap()
|
||||||
(store.getState().relays as RelaysState).map || getDefaultRelayMap()
|
|
||||||
const writeRelays = Object.keys(relayMap).filter((key) => relayMap[key].write)
|
const writeRelays = Object.keys(relayMap).filter((key) => relayMap[key].write)
|
||||||
|
|
||||||
const publishResult = await Promise.race([
|
const publishResult = await Promise.race([
|
||||||
@ -878,8 +876,8 @@ export const subscribeForSigits = async (pubkey: string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const processReceivedEvent = async (event: Event, difficulty: number = 5) => {
|
const processReceivedEvent = async (event: Event, difficulty: number = 5) => {
|
||||||
const processedEvents = (store.getState().userAppData as UserAppData)
|
const processedEvents = store.getState().userAppData?.processedGiftWraps || []
|
||||||
.processedGiftWraps
|
|
||||||
if (processedEvents.includes(event.id)) return
|
if (processedEvents.includes(event.id)) return
|
||||||
|
|
||||||
store.dispatch(updateProcessedGiftWraps([...processedEvents, event.id]))
|
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) => {
|
export const sendNotification = async (receiver: string, meta: Meta) => {
|
||||||
// Retrieve the user's public key from the state
|
// 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
|
// Create an unsigned event object with the provided metadata
|
||||||
const unsignedEvent: UnsignedEvent = {
|
const unsignedEvent: UnsignedEvent = {
|
||||||
|
Loading…
Reference in New Issue
Block a user