mirror of
https://github.com/minibits-cash/minibits_wallet.git
synced 2026-10-05 11:18:24 +00:00
Replace getWalletProfileByNip05 api by alternatives
This commit is contained in:
@@ -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"))
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user