Always use nip 44 for sending bunker requests

This commit is contained in:
greenart7c3
2025-06-27 07:08:14 -03:00
parent 41724adc0e
commit bb20ac8c6a
4 changed files with 16 additions and 63 deletions
@@ -28,7 +28,6 @@ data class AmberBunkerRequest(
val localKey: String,
val relays: List<RelaySetupInfo>,
val currentAccount: String,
val encryptionType: EncryptionType,
val nostrConnectSecret: String,
val closeApplication: Boolean,
val name: String,
@@ -52,13 +51,6 @@ data class AmberBunkerRequest(
)
fun fromJson(jsonObject: JsonNode): AmberBunkerRequest {
val encryptionTypeString = jsonObject.get("encryptionType")?.asText()?.intern() ?: ""
val encryptionType = when (encryptionTypeString) {
"NIP44" -> EncryptionType.NIP44
"NIP04" -> EncryptionType.NIP04
else -> EncryptionType.NIP04
}
return AmberBunkerRequest(
request = EventMapper.mapper.readValue(jsonObject.get("request").asText().intern()),
localKey = jsonObject.get("localKey")?.asText()?.intern() ?: "",
@@ -68,7 +60,6 @@ data class AmberBunkerRequest(
RelaySetupInfo(relayUrl, read = true, write = true, feedTypes = COMMON_FEED_TYPES)
} ?: Amber.instance.getSavedRelays().toList(),
currentAccount = jsonObject.get("currentAccount")?.asText()?.intern() ?: "",
encryptionType = encryptionType,
nostrConnectSecret = jsonObject.get("nostrConnectSecret")?.asText()?.intern() ?: "",
closeApplication = jsonObject.get("closeApplication")?.asBoolean() != false,
name = jsonObject.get("name")?.asText()?.intern() ?: "",
@@ -103,7 +94,6 @@ data class AmberBunkerRequest(
}
gen.writeEndArray()
gen.writeStringField("currentAccount", value.currentAccount)
gen.writeStringField("encryptionType", value.encryptionType.toString())
gen.writeStringField("nostrConnectSecret", value.nostrConnectSecret)
gen.writeBooleanField("closeApplication", value.closeApplication)
gen.writeStringField("name", value.name)
@@ -11,7 +11,6 @@ import com.greenart7c3.nostrsigner.database.HistoryEntity2
import com.greenart7c3.nostrsigner.database.LogEntity
import com.greenart7c3.nostrsigner.models.Account
import com.greenart7c3.nostrsigner.models.AmberBunkerRequest
import com.greenart7c3.nostrsigner.models.EncryptionType
import com.greenart7c3.nostrsigner.models.Permission
import com.greenart7c3.nostrsigner.models.SignerType
import com.greenart7c3.nostrsigner.relays.AmberListenerSingleton
@@ -111,39 +110,19 @@ object BunkerRequestUtils {
}
}
when (bunkerRequest.encryptionType) {
EncryptionType.NIP04 -> {
account.signer.nip04Encrypt(
EventMapper.mapper.writeValueAsString(bunkerResponse),
bunkerRequest.localKey,
) { encryptedContent ->
sendBunkerResponse(
bunkerRequest = bunkerRequest,
account = account,
localKey = bunkerRequest.localKey,
encryptedContent = encryptedContent,
relays = relays.ifEmpty { Amber.instance.getSavedRelays().toList() },
onLoading = onLoading,
onDone = onDone,
)
}
}
EncryptionType.NIP44 -> {
account.signer.nip44Encrypt(
EventMapper.mapper.writeValueAsString(bunkerResponse),
bunkerRequest.localKey,
) { encryptedContent ->
sendBunkerResponse(
bunkerRequest = bunkerRequest,
account = account,
localKey = bunkerRequest.localKey,
encryptedContent = encryptedContent,
relays = relays.ifEmpty { Amber.instance.getSavedRelays().toList() },
onLoading = onLoading,
onDone = onDone,
)
}
}
account.signer.nip44Encrypt(
EventMapper.mapper.writeValueAsString(bunkerResponse),
bunkerRequest.localKey,
) { encryptedContent ->
sendBunkerResponse(
bunkerRequest = bunkerRequest,
account = account,
localKey = bunkerRequest.localKey,
encryptedContent = encryptedContent,
relays = relays.ifEmpty { Amber.instance.getSavedRelays().toList() },
onLoading = onLoading,
onDone = onDone,
)
}
}
@@ -37,7 +37,6 @@ import com.greenart7c3.nostrsigner.database.LogEntity
import com.greenart7c3.nostrsigner.database.NotificationEntity
import com.greenart7c3.nostrsigner.models.Account
import com.greenart7c3.nostrsigner.models.AmberBunkerRequest
import com.greenart7c3.nostrsigner.models.EncryptionType
import com.greenart7c3.nostrsigner.models.Permission
import com.greenart7c3.nostrsigner.models.SignerType
import com.greenart7c3.nostrsigner.service.NotificationUtils.sendNotification
@@ -49,7 +48,6 @@ import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.jackson.EventMapper
import com.vitorpamplona.quartz.nip01Core.tags.people.taggedUsers
import com.vitorpamplona.quartz.nip01Core.verify
import com.vitorpamplona.quartz.nip04Dm.crypto.EncryptedInfo
import com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequest
import com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestConnect
import com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestNip04Decrypt
@@ -127,19 +125,9 @@ class EventNotificationConsumer(private val applicationContext: Context) {
)
}
if (EncryptedInfo.isNIP04(event.content)) {
Log.d(Amber.TAG, "isNIP04: true")
acc.signer.nip04Decrypt(event.content, event.pubKey) {
Amber.instance.applicationIOScope.launch {
notify(event, acc, it, EncryptionType.NIP04, relay)
}
}
} else {
Log.d(Amber.TAG, "isNIP04: false")
acc.signer.nip44Decrypt(event.content, event.pubKey) {
Amber.instance.applicationIOScope.launch {
notify(event, acc, it, EncryptionType.NIP44, relay)
}
acc.signer.decrypt(event.content, event.pubKey) {
Amber.instance.applicationIOScope.launch {
notify(event, acc, it, relay)
}
}
}
@@ -148,7 +136,6 @@ class EventNotificationConsumer(private val applicationContext: Context) {
event: Event,
acc: Account,
request: String,
encryptionType: EncryptionType,
relay: Relay,
) {
val responseRelay = listOf(RelaySetupInfo(relay.url, read = true, write = true, feedTypes = COMMON_FEED_TYPES))
@@ -215,7 +202,6 @@ class EventNotificationConsumer(private val applicationContext: Context) {
localKey = event.pubKey,
relays = responseRelay,
currentAccount = acc.hexKey,
encryptionType = encryptionType,
nostrConnectSecret = "",
closeApplication = true,
name = "",
@@ -7,7 +7,6 @@ import com.greenart7c3.nostrsigner.database.LogEntity
import com.greenart7c3.nostrsigner.models.Account
import com.greenart7c3.nostrsigner.models.AmberBunkerRequest
import com.greenart7c3.nostrsigner.models.BunkerMetadata
import com.greenart7c3.nostrsigner.models.EncryptionType
import com.greenart7c3.nostrsigner.models.Permission
import com.greenart7c3.nostrsigner.models.containsNip
import com.vitorpamplona.ammolite.relays.COMMON_FEED_TYPES
@@ -121,7 +120,6 @@ object NostrConnectUtils {
localKey = pubKey,
relays = relays.ifEmpty { Amber.instance.getSavedRelays().toList() },
currentAccount = account.hexKey,
encryptionType = EncryptionType.NIP04,
nostrConnectSecret = nostrConnectSecret,
closeApplication = intent.getBooleanExtra("closeApplication", true),
name = name,