feat: use nip04 for encryption and decryption of userData to store on blossom server #162
@ -18,4 +18,3 @@ export const SET_RELAY_MAP_UPDATED = 'SET_RELAY_MAP_UPDATED'
|
||||
|
||||
export const UPDATE_USER_APP_DATA = 'UPDATE_USER_APP_DATA'
|
||||
export const UPDATE_PROCESSED_GIFT_WRAPS = 'UPDATE_PROCESSED_GIFT_WRAPS'
|
||||
export const SET_D_TAG_FOR_APP_DATA = 'SET_D_TAG_FOR_APP_DATA'
|
||||
|
@ -1,10 +1,6 @@
|
||||
import { UserAppData } from '../../types'
|
||||
import * as ActionTypes from '../actionTypes'
|
||||
import {
|
||||
SetDTagForAppData,
|
||||
UpdateProcessedGiftWraps,
|
||||
UpdateUserAppData
|
||||
} from './types'
|
||||
import { UpdateProcessedGiftWraps, UpdateUserAppData } from './types'
|
||||
|
||||
export const updateUserAppData = (payload: UserAppData): UpdateUserAppData => ({
|
||||
type: ActionTypes.UPDATE_USER_APP_DATA,
|
||||
@ -17,8 +13,3 @@ export const updateProcessedGiftWraps = (
|
||||
type: ActionTypes.UPDATE_PROCESSED_GIFT_WRAPS,
|
||||
payload
|
||||
})
|
||||
|
||||
export const setDTagForAppData = (payload: string): SetDTagForAppData => ({
|
||||
type: ActionTypes.SET_D_TAG_FOR_APP_DATA,
|
||||
payload
|
||||
})
|
||||
|
@ -24,12 +24,6 @@ const reducer = (
|
||||
processedGiftWraps: action.payload
|
||||
}
|
||||
|
||||
case ActionTypes.SET_D_TAG_FOR_APP_DATA:
|
||||
return {
|
||||
...state,
|
||||
dTag: action.payload
|
||||
}
|
||||
|
||||
case ActionTypes.RESTORE_STATE:
|
||||
return action.payload.userAppData || null
|
||||
|
||||
|
@ -12,13 +12,7 @@ export interface UpdateProcessedGiftWraps {
|
||||
payload: string[]
|
||||
}
|
||||
|
||||
export interface SetDTagForAppData {
|
||||
type: typeof ActionTypes.SET_D_TAG_FOR_APP_DATA
|
||||
payload: string
|
||||
}
|
||||
|
||||
export type UserAppDataDispatchTypes =
|
||||
| UpdateUserAppData
|
||||
| UpdateProcessedGiftWraps
|
||||
| SetDTagForAppData
|
||||
| RestoreState
|
||||
|
@ -24,7 +24,6 @@ import {
|
||||
relayController
|
||||
} from '../controllers'
|
||||
import {
|
||||
setDTagForAppData,
|
||||
updateProcessedGiftWraps,
|
||||
updateUserAppData as updateUserAppDataAction
|
||||
} from '../store/actions'
|
||||
@ -35,6 +34,7 @@ import { Meta, SignedEvent, UserAppData } from '../types'
|
||||
import { getDefaultRelayMap } from './relays'
|
||||
import { parseJson, removeLeadingSlash } from './string'
|
||||
import { timeout } from './utils'
|
||||
import { getHash } from './hash'
|
||||
|
||||
/**
|
||||
* Generates a `d` tag for userAppData
|
||||
@ -49,36 +49,7 @@ const getDTagForUserAppData = async (): Promise<string | null> => {
|
||||
)
|
||||
}
|
||||
|
||||
let dTag = store.getState().userAppData?.dTag
|
||||
|
||||
// if dTag is found in redux store then just return that
|
||||
if (dTag) return dTag
|
||||
|
||||
// dTag not found is redux store. Generate it.
|
||||
const unsignedEvent: UnsignedEvent = {
|
||||
kind: kinds.ShortTextNote,
|
||||
pubkey: pubkey,
|
||||
created_at: 0,
|
||||
tags: [],
|
||||
content: `938_${pubkey}`
|
||||
}
|
||||
|
||||
const nostrController = NostrController.getInstance()
|
||||
const signedEvent = await nostrController
|
||||
.signEvent(unsignedEvent)
|
||||
.catch((err) => {
|
||||
console.error('Failed to sign event for dTag', err)
|
||||
toast.error(err.message || err)
|
||||
return null
|
||||
})
|
||||
if (!signedEvent) return null
|
||||
|
||||
dTag = signedEvent.sig
|
||||
|
||||
// save dTag in redux store
|
||||
store.dispatch(setDTagForAppData(dTag))
|
||||
|
||||
return dTag
|
||||
return getHash(`938_${pubkey}`)
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user