diff --git a/src/screens/Contacts/OwnName.tsx b/src/screens/Contacts/OwnName.tsx index daaa5333..267b094a 100644 --- a/src/screens/Contacts/OwnName.tsx +++ b/src/screens/Contacts/OwnName.tsx @@ -4,7 +4,7 @@ import {Text as RNText, TextStyle, View, ViewStyle, TextInput, ScrollView } from import {colors, spacing, typography, useThemeColor} from '../../theme' import {BottomModal, Button, Card, ErrorModal, Icon, InfoModal, ListItem, Loading, Screen, Text} from '../../components' import {useStores} from '../../models' -import { MinibitsClient} from '../../services' +import { MinibitsClient, NostrClient} from '../../services' import AppError, { Err } from '../../utils/AppError' import {log} from '../../services/logService' import { TransactionStatus } from '../../models/Transaction' @@ -160,7 +160,8 @@ export const OwnName = observer(function (props: {pubkey: string}) { } 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) { setInfo(translate("contactsScreen_ownName_profileExists")) diff --git a/src/screens/Contacts/PrivateContacts.tsx b/src/screens/Contacts/PrivateContacts.tsx index 223b8b87..350444b6 100644 --- a/src/screens/Contacts/PrivateContacts.tsx +++ b/src/screens/Contacts/PrivateContacts.tsx @@ -93,53 +93,30 @@ export const PrivateContacts = observer(function (props: { try { let newContact: Contact | undefined = undefined + let nostrProfile: NostrProfile | undefined = undefined if (isExternalDomain) { // validate and get profile data from nip05 server + relays - - 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 - + nostrProfile = await NostrClient.getNormalizedNostrProfile(newContactName, relaysStore.allPublicUrls) as NostrProfile } else { - // do it with single api call for minibts.cash profiles - const profileRecord = await MinibitsClient.getWalletProfileByNip05(newContactName + MINIBITS_NIP05_DOMAIN) + // replaced insecure getWalletProfileByNip05 call + nostrProfile = await NostrClient.getNormalizedNostrProfile(newContactName, NostrClient.getMinibitsRelays()) as NostrProfile + } - if(!profileRecord) { - warningMessage(translate("contactsScreen_privateContacts_profileNotFound", { - name: newContactName + MINIBITS_NIP05_DOMAIN - })) - setIsLoading(false) - return - } + log.trace('[saveNewContact]', 'Nostr profile', nostrProfile) - const npub = NostrClient.getNpubkey(profileRecord.pubkey) - const {pubkey, nip05, name, avatar: picture} = profileRecord + const {pubkey, npub, name, picture, nip05, lud16} = nostrProfile - newContact = { - type: ContactType.PRIVATE, - pubkey, - npub, - nip05, - lud16: nip05, // minibits addresses are both nostr and lightning addresses - name, - picture, - isExternalDomain - } as Contact - } + newContact = { + type: ContactType.PRIVATE, + pubkey, + npub, + name, + picture, + nip05, + lud16, + isExternalDomain, + } as Contact contactsStore.addContact(newContact) diff --git a/src/services/walletService.ts b/src/services/walletService.ts index c9096aa3..f8e9529c 100644 --- a/src/services/walletService.ts +++ b/src/services/walletService.ts @@ -2494,11 +2494,7 @@ const handleReceivedEventTask = async function (encryptedEvent: NostrEvent): Pro && userSettingsStore.isReceiveOnlyFromContactsOn === false ) { - const serverProfile = await MinibitsClient.getWalletProfileByNip05(sentFrom) - - if(serverProfile.pubkey !== sentFromPubkey) { - throw new AppError(Err.UNAUTHORIZED_ERROR, 'Sender pubkey does not match the one on the Minibits server.', {sentFrom, sentFromPubkey, serverProfile}) - } + const serverProfile = await MinibitsClient.getWalletProfile(sentFromPubkey) log.info('[handleReceivedEventTask]', 'Event sent from Minibits server user, adding to contacts...', {sentFrom, sentFromPubkey})