fix: use old approach of using sha256 for generating d tag
All checks were successful
Open PR on Staging / audit_and_check (pull_request) Successful in 44s

This commit is contained in:
daniyal 2024-08-22 16:11:20 +05:00
parent 73a5d42fcf
commit 49c1714962
5 changed files with 3 additions and 54 deletions

View File

@ -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_USER_APP_DATA = 'UPDATE_USER_APP_DATA'
export const UPDATE_PROCESSED_GIFT_WRAPS = 'UPDATE_PROCESSED_GIFT_WRAPS' export const UPDATE_PROCESSED_GIFT_WRAPS = 'UPDATE_PROCESSED_GIFT_WRAPS'
export const SET_D_TAG_FOR_APP_DATA = 'SET_D_TAG_FOR_APP_DATA'

View File

@ -1,10 +1,6 @@
import { UserAppData } from '../../types' import { UserAppData } from '../../types'
import * as ActionTypes from '../actionTypes' import * as ActionTypes from '../actionTypes'
import { import { UpdateProcessedGiftWraps, UpdateUserAppData } from './types'
SetDTagForAppData,
UpdateProcessedGiftWraps,
UpdateUserAppData
} from './types'
export const updateUserAppData = (payload: UserAppData): UpdateUserAppData => ({ export const updateUserAppData = (payload: UserAppData): UpdateUserAppData => ({
type: ActionTypes.UPDATE_USER_APP_DATA, type: ActionTypes.UPDATE_USER_APP_DATA,
@ -17,8 +13,3 @@ export const updateProcessedGiftWraps = (
type: ActionTypes.UPDATE_PROCESSED_GIFT_WRAPS, type: ActionTypes.UPDATE_PROCESSED_GIFT_WRAPS,
payload payload
}) })
export const setDTagForAppData = (payload: string): SetDTagForAppData => ({
type: ActionTypes.SET_D_TAG_FOR_APP_DATA,
payload
})

View File

@ -24,12 +24,6 @@ const reducer = (
processedGiftWraps: action.payload processedGiftWraps: action.payload
} }
case ActionTypes.SET_D_TAG_FOR_APP_DATA:
return {
...state,
dTag: action.payload
}
case ActionTypes.RESTORE_STATE: case ActionTypes.RESTORE_STATE:
return action.payload.userAppData || null return action.payload.userAppData || null

View File

@ -12,13 +12,7 @@ export interface UpdateProcessedGiftWraps {
payload: string[] payload: string[]
} }
export interface SetDTagForAppData {
type: typeof ActionTypes.SET_D_TAG_FOR_APP_DATA
payload: string
}
export type UserAppDataDispatchTypes = export type UserAppDataDispatchTypes =
| UpdateUserAppData | UpdateUserAppData
| UpdateProcessedGiftWraps | UpdateProcessedGiftWraps
| SetDTagForAppData
| RestoreState | RestoreState

View File

@ -24,7 +24,6 @@ import {
relayController relayController
} from '../controllers' } from '../controllers'
import { import {
setDTagForAppData,
updateProcessedGiftWraps, updateProcessedGiftWraps,
updateUserAppData as updateUserAppDataAction updateUserAppData as updateUserAppDataAction
} from '../store/actions' } from '../store/actions'
@ -35,6 +34,7 @@ import { Meta, SignedEvent, UserAppData } from '../types'
import { getDefaultRelayMap } from './relays' import { getDefaultRelayMap } from './relays'
import { parseJson, removeLeadingSlash } from './string' import { parseJson, removeLeadingSlash } from './string'
import { timeout } from './utils' import { timeout } from './utils'
import { getHash } from './hash'
/** /**
* Generates a `d` tag for userAppData * Generates a `d` tag for userAppData
@ -49,36 +49,7 @@ const getDTagForUserAppData = async (): Promise<string | null> => {
) )
} }
let dTag = store.getState().userAppData?.dTag return getHash(`938_${pubkey}`)
// 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
} }
/** /**