Compare commits

..

No commits in common. "d4b1eceaa1ac81584a9261d79e9f14be5e8c2f62" and "cb688afb8d89d0fd592686dc49f0d28b5b6d9c81" have entirely different histories.

11 changed files with 28 additions and 132 deletions

62
package-lock.json generated
View File

@ -13,7 +13,6 @@
"@mui/icons-material": "5.15.11",
"@mui/lab": "5.0.0-alpha.166",
"@mui/material": "5.15.11",
"@noble/hashes": "^1.4.0",
"@nostr-dev-kit/ndk": "2.5.0",
"@reduxjs/toolkit": "2.2.1",
"axios": "1.6.7",
@ -1506,9 +1505,9 @@
}
},
"node_modules/@noble/hashes": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.4.0.tgz",
"integrity": "sha512-V1JJ1WTRUqHHrOSh597hURcMqVKVGL/ea3kv0gSnEdsEZ0/+VyPghM1lMNGc00z7CIQorSvbKpuJkxvuHbvdbg==",
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.1.tgz",
"integrity": "sha512-EbqwksQwz9xDRGfDST86whPBgM65E0OH/pCgqW0GBVzO22bNE+NuIbeTb714+IfSjU3aRk47EUvXIb5bTsenKA==",
"engines": {
"node": ">= 16"
},
@ -1599,17 +1598,6 @@
"url": "https://paulmillr.com/funding/"
}
},
"node_modules/@nostr-dev-kit/ndk/node_modules/@noble/hashes": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.1.tgz",
"integrity": "sha512-EbqwksQwz9xDRGfDST86whPBgM65E0OH/pCgqW0GBVzO22bNE+NuIbeTb714+IfSjU3aRk47EUvXIb5bTsenKA==",
"engines": {
"node": ">= 16"
},
"funding": {
"url": "https://paulmillr.com/funding/"
}
},
"node_modules/@nostr-dev-kit/ndk/node_modules/nostr-tools": {
"version": "1.17.0",
"resolved": "https://registry.npmjs.org/nostr-tools/-/nostr-tools-1.17.0.tgz",
@ -1875,28 +1863,6 @@
"url": "https://paulmillr.com/funding/"
}
},
"node_modules/@scure/bip32/node_modules/@noble/curves/node_modules/@noble/hashes": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.1.tgz",
"integrity": "sha512-EbqwksQwz9xDRGfDST86whPBgM65E0OH/pCgqW0GBVzO22bNE+NuIbeTb714+IfSjU3aRk47EUvXIb5bTsenKA==",
"engines": {
"node": ">= 16"
},
"funding": {
"url": "https://paulmillr.com/funding/"
}
},
"node_modules/@scure/bip32/node_modules/@noble/hashes": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.3.tgz",
"integrity": "sha512-V7/fPHgl+jsVPXqqeOzT8egNj2iBIVt+ECeMMG8TdcnTikP3oaBtUVqpT/gYCR68aEBJSF+XbYUxStjbFMqIIA==",
"engines": {
"node": ">= 16"
},
"funding": {
"url": "https://paulmillr.com/funding/"
}
},
"node_modules/@scure/bip39": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/@scure/bip39/-/bip39-1.2.1.tgz",
@ -1909,17 +1875,6 @@
"url": "https://paulmillr.com/funding/"
}
},
"node_modules/@scure/bip39/node_modules/@noble/hashes": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.3.tgz",
"integrity": "sha512-V7/fPHgl+jsVPXqqeOzT8egNj2iBIVt+ECeMMG8TdcnTikP3oaBtUVqpT/gYCR68aEBJSF+XbYUxStjbFMqIIA==",
"engines": {
"node": ">= 16"
},
"funding": {
"url": "https://paulmillr.com/funding/"
}
},
"node_modules/@tsconfig/node10": {
"version": "1.0.9",
"resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz",
@ -4072,17 +4027,6 @@
}
}
},
"node_modules/nostr-tools/node_modules/@noble/hashes": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.1.tgz",
"integrity": "sha512-EbqwksQwz9xDRGfDST86whPBgM65E0OH/pCgqW0GBVzO22bNE+NuIbeTb714+IfSjU3aRk47EUvXIb5bTsenKA==",
"engines": {
"node": ">= 16"
},
"funding": {
"url": "https://paulmillr.com/funding/"
}
},
"node_modules/nostr-wasm": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/nostr-wasm/-/nostr-wasm-0.1.0.tgz",

View File

@ -19,7 +19,6 @@
"@mui/icons-material": "5.15.11",
"@mui/lab": "5.0.0-alpha.166",
"@mui/material": "5.15.11",
"@noble/hashes": "^1.4.0",
"@nostr-dev-kit/ndk": "2.5.0",
"@reduxjs/toolkit": "2.2.1",
"axios": "1.6.7",

View File

@ -10,24 +10,22 @@ import {
import { useEffect, useState } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { setAuthState, setMetadataEvent } from '../../store/actions'
import { setAuthState } from '../../store/actions'
import { State } from '../../store/rootReducer'
import { Dispatch } from '../../store/store'
import Username from '../username'
import { Link, useNavigate } from 'react-router-dom'
import { MetadataController, NostrController } from '../../controllers'
import { NostrController } from '../../controllers'
import { appPublicRoutes, getProfileRoute } from '../../routes'
import {
clearAuthToken,
clearState,
getRoboHashPicture,
saveNsecBunkerDelegatedKey,
shorten
} from '../../utils'
import styles from './style.module.scss'
const metadataController = new MetadataController()
export const AppBar = () => {
const navigate = useNavigate()
@ -41,19 +39,17 @@ export const AppBar = () => {
const metadataState = useSelector((state: State) => state.metadata)
useEffect(() => {
if (metadataState) {
if (metadataState.content) {
const { picture, display_name, name } = JSON.parse(metadataState.content)
if (metadataState && metadataState.content) {
const { picture, display_name, name } = JSON.parse(metadataState.content)
const pubkey = authState?.usersPubkey || ''
if (picture) {
setUserAvatar(picture)
}
setUsername(shorten(display_name || name || '', 7))
if (picture) {
setUserAvatar(picture)
} else {
setUserAvatar('')
setUsername('')
setUserAvatar(getRoboHashPicture(pubkey))
}
setUsername(shorten(display_name || name || '', 7))
}
}, [metadataState])
@ -76,7 +72,6 @@ export const AppBar = () => {
handleCloseUserMenu()
dispatch(
setAuthState({
keyPair: undefined,
loggedIn: false,
usersPubkey: undefined,
loginMethod: undefined,
@ -84,13 +79,8 @@ export const AppBar = () => {
})
)
dispatch(
setMetadataEvent(metadataController.getEmptyMetadataEvent())
)
// clear authToken saved in local storage
clearAuthToken()
clearState()
// update nsecBunker delegated key after logout
const nostrController = NostrController.getInstance()

View File

@ -6,7 +6,6 @@ import {
base64DecodeAuthToken,
base64EncodeSignedEvent,
getAuthToken,
getRoboHashPicture,
getVisitedLink,
saveAuthToken
} from '../utils'
@ -38,15 +37,7 @@ export class AuthController {
store.dispatch(setMetadataEvent(event))
})
.catch((err) => {
console.warn('Error occurred while finding metadata', err)
const emptyMetadata = this.metadataController.getEmptyMetadataEvent()
emptyMetadata.content = JSON.stringify({
picture: getRoboHashPicture(pubkey)
})
store.dispatch(setMetadataEvent(emptyMetadata))
console.error('Error occurred while finding metadata', err)
})
// Nostr uses unix timestamps

View File

@ -23,18 +23,6 @@ export class MetadataController {
this.nostrController = NostrController.getInstance()
}
public getEmptyMetadataEvent = (): Event => {
return {
content: '',
created_at: new Date().valueOf(),
id: '',
kind: 0,
pubkey: '',
sig: '',
tags: []
}
}
public findMetadata = async (hexKey: string) => {
const eventFilter: Filter = {
kinds: [kinds.Metadata],

View File

@ -319,18 +319,15 @@ export class NostrController extends EventEmitter {
}
if (loginMethod === LoginMethods.privateKey) {
const keys = (store.getState().auth as AuthState).keyPair
const keyPair = (store.getState().auth as AuthState).keyPair
if (!keys) {
if (!keyPair) {
throw new Error(
`Login method is ${LoginMethods.privateKey} but private & public key pair is not found.`
)
}
const { private: nsec } = keys
const privateKey = nip19.decode(nsec).data as Uint8Array
const encrypted = await nip04.encrypt(privateKey, receiver, content)
const encrypted = await nip04.encrypt(keyPair.private, receiver, content)
return encrypted
}

View File

@ -4,15 +4,13 @@ import { useEffect, useState } from 'react'
import { useDispatch } from 'react-redux'
import { Outlet } from 'react-router-dom'
import { AppBar } from '../components/AppBar/AppBar'
import { restoreState, setAuthState, setMetadataEvent } from '../store/actions'
import { clearAuthToken, clearState, loadState, saveNsecBunkerDelegatedKey } from '../utils'
import { restoreState, setAuthState } from '../store/actions'
import { clearAuthToken, loadState, saveNsecBunkerDelegatedKey } from '../utils'
import { LoadingSpinner } from '../components/LoadingSpinner'
import { Dispatch } from '../store/store'
import { MetadataController, NostrController } from '../controllers'
import { NostrController } from '../controllers'
import { LoginMethods } from '../store/auth/types'
const metadataController = new MetadataController()
export const MainLayout = () => {
const dispatch: Dispatch = useDispatch()
const [isLoading, setIsLoading] = useState(true)
@ -21,7 +19,6 @@ export const MainLayout = () => {
const logout = () => {
dispatch(
setAuthState({
keyPair: undefined,
loggedIn: false,
usersPubkey: undefined,
loginMethod: undefined,
@ -29,13 +26,8 @@ export const MainLayout = () => {
})
)
dispatch(
setMetadataEvent(metadataController.getEmptyMetadataEvent())
)
// clear authToken saved in local storage
clearAuthToken()
clearState()
// update nsecBunker delegated key
const newDelegatedKey =

View File

@ -489,11 +489,6 @@ const DisplayUser = ({
})
}, [users])
/**
* Use robohash if any of the users images fail to load
* @param event img tag onError event
* @param pubkey of the user
*/
const imageLoadError = (event: any, pubkey: string) => {
event.target.src = getRoboHashPicture(pubkey)
}

View File

@ -26,6 +26,7 @@ import { setMetadataEvent } from '../../store/actions'
import { LoadingSpinner } from '../../components/LoadingSpinner'
import { LoginMethods } from '../../store/auth/types'
import { SmartToy } from '@mui/icons-material'
import { getRoboHashPicture } from '../../utils'
export const ProfilePage = () => {
const theme = useTheme()
@ -280,11 +281,14 @@ export const ProfilePage = () => {
}}
>
<img
onError={(event: any) => {
event.target.src = npub ? getRoboHashPicture(npub) : ''
}}
onLoad={() => {
setAvatarLoading(false)
}}
className={styles.img}
src={profileMetadata.picture}
src={profileMetadata.picture || npub ? getRoboHashPicture(npub!) : ''}
alt="Profile Image"
/>

View File

@ -115,7 +115,7 @@ export const VerifyPage = () => {
const imageLoadError = (event: any, pubkey: string) => {
const npub = hexToNpub(pubkey)
event.target.src = getRoboImageUrl(npub)
event.target.src = npub
}
const getRoboImageUrl = (pubkey: string) => {

View File

@ -22,10 +22,6 @@ export const loadState = (): State | undefined => {
}
}
export const clearState = () => {
localStorage.removeItem('state')
}
export const saveNsecBunkerDelegatedKey = (privateKey: string) => {
localStorage.setItem('nsecbunker-delegated-key', privateKey)
}