Replace getWalletProfileByNip05 api by alternatives

This commit is contained in:
minibits-cash
2026-02-28 21:48:25 +01:00
parent 34c2086519
commit 13a27e9abe
3 changed files with 21 additions and 47 deletions
+3 -2
View File
@@ -4,7 +4,7 @@ import {Text as RNText, TextStyle, View, ViewStyle, TextInput, ScrollView } from
import {colors, spacing, typography, useThemeColor} from '../../theme' import {colors, spacing, typography, useThemeColor} from '../../theme'
import {BottomModal, Button, Card, ErrorModal, Icon, InfoModal, ListItem, Loading, Screen, Text} from '../../components' import {BottomModal, Button, Card, ErrorModal, Icon, InfoModal, ListItem, Loading, Screen, Text} from '../../components'
import {useStores} from '../../models' import {useStores} from '../../models'
import { MinibitsClient} from '../../services' import { MinibitsClient, NostrClient} from '../../services'
import AppError, { Err } from '../../utils/AppError' import AppError, { Err } from '../../utils/AppError'
import {log} from '../../services/logService' import {log} from '../../services/logService'
import { TransactionStatus } from '../../models/Transaction' import { TransactionStatus } from '../../models/Transaction'
@@ -160,7 +160,8 @@ export const OwnName = observer(function (props: {pubkey: string}) {
} }
try { try {
const profileExists = await MinibitsClient.getWalletProfileByNip05(ownName + MINIBITS_NIP05_DOMAIN) //const profileExists = await MinibitsClient.getWalletProfileByNip05(ownName + MINIBITS_NIP05_DOMAIN)
const profileExists = await NostrClient.getNip05Record(ownName + MINIBITS_NIP05_DOMAIN) // throws if not found
if(profileExists) { if(profileExists) {
setInfo(translate("contactsScreen_ownName_profileExists")) setInfo(translate("contactsScreen_ownName_profileExists"))
+17 -40
View File
@@ -93,53 +93,30 @@ export const PrivateContacts = observer(function (props: {
try { try {
let newContact: Contact | undefined = undefined let newContact: Contact | undefined = undefined
let nostrProfile: NostrProfile | undefined = undefined
if (isExternalDomain) { if (isExternalDomain) {
// validate and get profile data from nip05 server + relays // validate and get profile data from nip05 server + relays
nostrProfile = await NostrClient.getNormalizedNostrProfile(newContactName, relaysStore.allPublicUrls) as NostrProfile
const profile = await NostrClient.getNormalizedNostrProfile(newContactName, relaysStore.allPublicUrls) as NostrProfile
log.trace('[saveNewContact]', 'Server profile', profile)
const {pubkey, npub, name, picture, nip05, lud16} = profile
newContact = {
type: ContactType.PRIVATE,
pubkey,
npub,
name,
picture,
nip05,
lud16,
isExternalDomain,
} as Contact
} else { } else {
// do it with single api call for minibts.cash profiles // replaced insecure getWalletProfileByNip05 call
const profileRecord = await MinibitsClient.getWalletProfileByNip05(newContactName + MINIBITS_NIP05_DOMAIN) nostrProfile = await NostrClient.getNormalizedNostrProfile(newContactName, NostrClient.getMinibitsRelays()) as NostrProfile
}
if(!profileRecord) { log.trace('[saveNewContact]', 'Nostr profile', nostrProfile)
warningMessage(translate("contactsScreen_privateContacts_profileNotFound", {
name: newContactName + MINIBITS_NIP05_DOMAIN
}))
setIsLoading(false)
return
}
const npub = NostrClient.getNpubkey(profileRecord.pubkey) const {pubkey, npub, name, picture, nip05, lud16} = nostrProfile
const {pubkey, nip05, name, avatar: picture} = profileRecord
newContact = { newContact = {
type: ContactType.PRIVATE, type: ContactType.PRIVATE,
pubkey, pubkey,
npub, npub,
nip05, name,
lud16: nip05, // minibits addresses are both nostr and lightning addresses picture,
name, nip05,
picture, lud16,
isExternalDomain isExternalDomain,
} as Contact } as Contact
}
contactsStore.addContact(newContact) contactsStore.addContact(newContact)
+1 -5
View File
@@ -2494,11 +2494,7 @@ const handleReceivedEventTask = async function (encryptedEvent: NostrEvent): Pro
&& userSettingsStore.isReceiveOnlyFromContactsOn === false && userSettingsStore.isReceiveOnlyFromContactsOn === false
) { ) {
const serverProfile = await MinibitsClient.getWalletProfileByNip05(sentFrom) const serverProfile = await MinibitsClient.getWalletProfile(sentFromPubkey)
if(serverProfile.pubkey !== sentFromPubkey) {
throw new AppError(Err.UNAUTHORIZED_ERROR, 'Sender pubkey does not match the one on the Minibits server.', {sentFrom, sentFromPubkey, serverProfile})
}
log.info('[handleReceivedEventTask]', 'Event sent from Minibits server user, adding to contacts...', {sentFrom, sentFromPubkey}) log.info('[handleReceivedEventTask]', 'Event sent from Minibits server user, adding to contacts...', {sentFrom, sentFromPubkey})