From dcc539107762589d13cf87bee4f493f9ef048c3f Mon Sep 17 00:00:00 2001 From: greenart7c3 Date: Wed, 29 Oct 2025 16:08:43 -0300 Subject: [PATCH] New interface for encryption/decryption events --- .../nostrsigner/models/EncryptedDataKind.kt | 15 ++ .../nostrsigner/models/IntentData.kt | 2 +- .../nostrsigner/models/Permission.kt | 1 + .../nostrsigner/service/IntentUtils.kt | 64 ++++++++- .../nostrsigner/service/model/AmberEvent.kt | 9 +- .../nostrsigner/ui/SeeDetailsScreen.kt | 4 +- .../ui/components/EncryptDecryptData.kt | 127 +++++++++-------- .../components/IntentSingleEventHomeScreen.kt | 7 +- .../ui/components/MultiEventHomeScreen.kt | 132 ++++++++++++++++-- app/src/main/res/values/strings.xml | 15 ++ 10 files changed, 297 insertions(+), 79 deletions(-) create mode 100644 app/src/main/java/com/greenart7c3/nostrsigner/models/EncryptedDataKind.kt diff --git a/app/src/main/java/com/greenart7c3/nostrsigner/models/EncryptedDataKind.kt b/app/src/main/java/com/greenart7c3/nostrsigner/models/EncryptedDataKind.kt new file mode 100644 index 00000000..052befba --- /dev/null +++ b/app/src/main/java/com/greenart7c3/nostrsigner/models/EncryptedDataKind.kt @@ -0,0 +1,15 @@ +package com.greenart7c3.nostrsigner.models + +import com.greenart7c3.nostrsigner.service.model.AmberEvent + +interface EncryptedDataKind { + val result: String +} + +class ClearTextEncryptedDataKind(val text: String, override val result: String) : EncryptedDataKind + +class TagArrayEncryptedDataKind(val tagArray: Array>, override val result: String) : EncryptedDataKind + +class EventEncryptedDataKind(val event: AmberEvent, override val result: String) : EncryptedDataKind + +class PrivateZapEncryptedDataKind(override val result: String) : EncryptedDataKind diff --git a/app/src/main/java/com/greenart7c3/nostrsigner/models/IntentData.kt b/app/src/main/java/com/greenart7c3/nostrsigner/models/IntentData.kt index b994f0ef..f953bf62 100644 --- a/app/src/main/java/com/greenart7c3/nostrsigner/models/IntentData.kt +++ b/app/src/main/java/com/greenart7c3/nostrsigner/models/IntentData.kt @@ -20,7 +20,7 @@ data class IntentData( val rememberType: MutableState, val route: String?, val event: Event?, - val encryptedData: String?, + val encryptedData: EncryptedDataKind?, val isNostrConnectURI: Boolean = false, val unsignedEventKey: HexKey = "", ) diff --git a/app/src/main/java/com/greenart7c3/nostrsigner/models/Permission.kt b/app/src/main/java/com/greenart7c3/nostrsigner/models/Permission.kt index 5ba8a95a..12c1281f 100644 --- a/app/src/main/java/com/greenart7c3/nostrsigner/models/Permission.kt +++ b/app/src/main/java/com/greenart7c3/nostrsigner/models/Permission.kt @@ -101,6 +101,7 @@ data class Permission( 11 -> context.getString(R.string.event_kind_11) 12 -> context.getString(R.string.event_kind_12) 13 -> context.getString(R.string.event_kind_13) + 14 -> context.getString(R.string.event_kind_14) 16 -> context.getString(R.string.event_kind_16) 17 -> context.getString(R.string.event_kind_17) 20 -> context.getString(R.string.event_kind_20) diff --git a/app/src/main/java/com/greenart7c3/nostrsigner/service/IntentUtils.kt b/app/src/main/java/com/greenart7c3/nostrsigner/service/IntentUtils.kt index ed85fd76..c0444ed8 100644 --- a/app/src/main/java/com/greenart7c3/nostrsigner/service/IntentUtils.kt +++ b/app/src/main/java/com/greenart7c3/nostrsigner/service/IntentUtils.kt @@ -25,17 +25,22 @@ import com.greenart7c3.nostrsigner.database.HistoryEntity import com.greenart7c3.nostrsigner.database.LogEntity import com.greenart7c3.nostrsigner.models.Account import com.greenart7c3.nostrsigner.models.AmberBunkerRequest +import com.greenart7c3.nostrsigner.models.ClearTextEncryptedDataKind import com.greenart7c3.nostrsigner.models.CompressionType +import com.greenart7c3.nostrsigner.models.EventEncryptedDataKind import com.greenart7c3.nostrsigner.models.IntentData import com.greenart7c3.nostrsigner.models.IntentResultType import com.greenart7c3.nostrsigner.models.Permission +import com.greenart7c3.nostrsigner.models.PrivateZapEncryptedDataKind import com.greenart7c3.nostrsigner.models.ReturnType import com.greenart7c3.nostrsigner.models.SignerType +import com.greenart7c3.nostrsigner.models.TagArrayEncryptedDataKind import com.greenart7c3.nostrsigner.models.containsNip import com.greenart7c3.nostrsigner.service.model.AmberEvent import com.greenart7c3.nostrsigner.ui.RememberType import com.vitorpamplona.quartz.nip01Core.core.Event import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher +import com.vitorpamplona.quartz.nip01Core.jackson.JacksonMapper import com.vitorpamplona.quartz.nip19Bech32.toNpub import com.vitorpamplona.quartz.utils.Hex import com.vitorpamplona.quartz.utils.TimeUtils @@ -190,6 +195,32 @@ object IntentUtils { "Could not decrypt the message" } + val encryptedDataKind = when (type) { + else -> { + if (type.name.contains("ENCRYPT")) { + if (localData.startsWith("{")) { + val event = AmberEvent.fromJson(localData) + EventEncryptedDataKind(event, result) + } else if (localData.startsWith("[")) { + val tagArray = JacksonMapper.fromJsonToTagArray(localData) + TagArrayEncryptedDataKind(tagArray, result) + } else { + ClearTextEncryptedDataKind(localData, result) + } + } else { + if (result.startsWith("{")) { + val event = AmberEvent.fromJson(result) + EventEncryptedDataKind(event, result) + } else if (result.startsWith("[")) { + val tagArray = JacksonMapper.fromJsonToTagArray(result) + TagArrayEncryptedDataKind(tagArray, result) + } else { + ClearTextEncryptedDataKind(localData, result) + } + } + } + } + IntentData( data = localData, name = appName, @@ -205,7 +236,7 @@ object IntentUtils { rememberType = mutableStateOf(RememberType.NEVER), route = route, event = null, - encryptedData = result, + encryptedData = encryptedDataKind, ) } SignerType.GET_PUBLIC_KEY -> { @@ -378,6 +409,35 @@ object IntentUtils { npub = parsePubKey(npub) } + val encryptedDataKind = when (type) { + SignerType.DECRYPT_ZAP_EVENT -> { + PrivateZapEncryptedDataKind(result) + } + else -> { + if (type.name.contains("ENCRYPT")) { + if (data.startsWith("{")) { + val event = AmberEvent.fromJson(data) + EventEncryptedDataKind(event, result) + } else if (data.startsWith("[")) { + val tagArray = JacksonMapper.fromJsonToTagArray(data) + TagArrayEncryptedDataKind(tagArray, result) + } else { + ClearTextEncryptedDataKind(data, result) + } + } else { + if (result.startsWith("{")) { + val event = AmberEvent.fromJson(result) + EventEncryptedDataKind(event, result) + } else if (result.startsWith("[")) { + val tagArray = JacksonMapper.fromJsonToTagArray(result) + TagArrayEncryptedDataKind(tagArray, result) + } else { + ClearTextEncryptedDataKind(data, result) + } + } + } + } + IntentData( data = data, name = name, @@ -393,7 +453,7 @@ object IntentUtils { rememberType = mutableStateOf(RememberType.NEVER), route = route, event = null, - encryptedData = result, + encryptedData = encryptedDataKind, ) } SignerType.GET_PUBLIC_KEY -> { diff --git a/app/src/main/java/com/greenart7c3/nostrsigner/service/model/AmberEvent.kt b/app/src/main/java/com/greenart7c3/nostrsigner/service/model/AmberEvent.kt index af1c6ac0..f8382939 100644 --- a/app/src/main/java/com/greenart7c3/nostrsigner/service/model/AmberEvent.kt +++ b/app/src/main/java/com/greenart7c3/nostrsigner/service/model/AmberEvent.kt @@ -17,6 +17,7 @@ import com.vitorpamplona.quartz.nip01Core.core.Event import com.vitorpamplona.quartz.nip01Core.core.HexKey import com.vitorpamplona.quartz.nip01Core.jackson.JacksonMapper import com.vitorpamplona.quartz.nip01Core.jackson.toTypedArray +import com.vitorpamplona.quartz.nip02FollowList.tags.ContactTag import com.vitorpamplona.quartz.utils.TimeUtils @Immutable @@ -60,7 +61,7 @@ open class AmberEvent( companion object { fun fromJson(jsonObject: JsonNode): AmberEvent = AmberEvent( - id = jsonObject.get("id")?.asText()?.intern() ?: "", + id = jsonObject.get("id")?.asText() ?: "", pubKey = jsonObject.get("pubkey")?.asText()?.intern() ?: "", createdAt = jsonObject.get("created_at")?.asLong() ?: TimeUtils.now(), kind = jsonObject.get("kind").asInt(), @@ -73,6 +74,12 @@ open class AmberEvent( } } + fun relay(): String { + return tags.filter { it.size > 1 && it[0] == "relay" }.map { it[1] }.first() + } + + fun verifiedFollowKeySet(): Set = tags.mapNotNullTo(HashSet(), ContactTag::parseValidKey) + companion object { val mapper: ObjectMapper = jacksonObjectMapper() diff --git a/app/src/main/java/com/greenart7c3/nostrsigner/ui/SeeDetailsScreen.kt b/app/src/main/java/com/greenart7c3/nostrsigner/ui/SeeDetailsScreen.kt index ee04153b..d916fde5 100644 --- a/app/src/main/java/com/greenart7c3/nostrsigner/ui/SeeDetailsScreen.kt +++ b/app/src/main/java/com/greenart7c3/nostrsigner/ui/SeeDetailsScreen.kt @@ -26,6 +26,8 @@ import androidx.compose.ui.text.intl.Locale import androidx.compose.ui.text.toLowerCase import androidx.compose.ui.unit.dp import com.greenart7c3.nostrsigner.R +import com.greenart7c3.nostrsigner.models.ClearTextEncryptedDataKind +import com.greenart7c3.nostrsigner.models.EventEncryptedDataKind import com.greenart7c3.nostrsigner.models.Permission import com.greenart7c3.nostrsigner.models.SignerType import com.greenart7c3.nostrsigner.service.BunkerRequestUtils @@ -122,7 +124,7 @@ fun SeeDetailsScreen( val event = intent.event!! if (event.kind == 22242) AmberEvent.relay(event) else event.content } else { - intent.encryptedData ?: intent.data + if (type.name.contains("ENCRYPT") && intent.encryptedData is ClearTextEncryptedDataKind) intent.encryptedData.text else if (intent.encryptedData is EventEncryptedDataKind) intent.encryptedData.event.content else intent.encryptedData?.result ?: "" } Text( diff --git a/app/src/main/java/com/greenart7c3/nostrsigner/ui/components/EncryptDecryptData.kt b/app/src/main/java/com/greenart7c3/nostrsigner/ui/components/EncryptDecryptData.kt index 9905059c..5d9eaec6 100644 --- a/app/src/main/java/com/greenart7c3/nostrsigner/ui/components/EncryptDecryptData.kt +++ b/app/src/main/java/com/greenart7c3/nostrsigner/ui/components/EncryptDecryptData.kt @@ -23,24 +23,32 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.SpanStyle import androidx.compose.ui.text.buildAnnotatedString +import androidx.compose.ui.text.capitalize import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.intl.Locale import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.withStyle import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import com.greenart7c3.nostrsigner.Amber import com.greenart7c3.nostrsigner.R import com.greenart7c3.nostrsigner.models.Account +import com.greenart7c3.nostrsigner.models.ClearTextEncryptedDataKind +import com.greenart7c3.nostrsigner.models.EncryptedDataKind +import com.greenart7c3.nostrsigner.models.EventEncryptedDataKind +import com.greenart7c3.nostrsigner.models.Permission import com.greenart7c3.nostrsigner.models.SignerType +import com.greenart7c3.nostrsigner.models.TagArrayEncryptedDataKind import com.greenart7c3.nostrsigner.ui.RememberType +import com.vitorpamplona.quartz.nip02FollowList.ContactListEvent import kotlinx.coroutines.launch @Composable fun EncryptDecryptData( account: Account, modifier: Modifier, - content: String, - encryptedData: String, + encryptedData: EncryptedDataKind?, shouldRunOnAccept: Boolean?, packageName: String?, applicationName: String?, @@ -49,12 +57,6 @@ fun EncryptDecryptData( onAccept: (RememberType) -> Unit, onReject: (RememberType) -> Unit, ) { - var showMore by androidx.compose.runtime.remember { - mutableStateOf(false) - } - val clipboardManager = LocalClipboard.current - val coroutineScope = rememberCoroutineScope() - val context = LocalContext.current var rememberType by remember { mutableStateOf(RememberType.NEVER) } @@ -64,16 +66,6 @@ fun EncryptDecryptData( ) { ProfilePicture(account) - val message = - when (type) { - SignerType.NIP44_ENCRYPT -> stringResource(R.string.encrypt_nip44) - SignerType.NIP04_ENCRYPT -> stringResource(R.string.encrypt_nip04) - SignerType.NIP44_DECRYPT -> stringResource(R.string.decrypt_nip44) - SignerType.NIP04_DECRYPT -> stringResource(R.string.decrypt_nip04) - SignerType.DECRYPT_ZAP_EVENT -> stringResource(R.string.decrypt_zap_event) - else -> stringResource(R.string.encrypt_decrypt) - } - packageName?.let { Text( modifier = Modifier @@ -91,26 +83,68 @@ fun EncryptDecryptData( withStyle(style = SpanStyle(fontWeight = FontWeight.Bold)) { append(applicationName ?: appName) } - append(" requests $message") + + if (type.name.contains("ENCRYPT")) { + when (encryptedData) { + is EventEncryptedDataKind -> { + val permission = Permission("sign_event", encryptedData.event.kind) + append(stringResource(R.string.wants_to_encrypt_with, permission.toLocalizedString(Amber.instance), type.name.split("_").first())) + } + + is TagArrayEncryptedDataKind -> { + append(stringResource(R.string.wants_to_encrypt_this_list_of_tags_with, type.name.split("_").first())) + } + + else -> append(stringResource(R.string.wants_to_encrypt_this_text_with, type.name.split("_").first())) + } + } else { + when (encryptedData) { + is EventEncryptedDataKind -> { + val permission = Permission("sign_event", encryptedData.event.kind) + append(stringResource(R.string.wants_to_read_from_encrypted_content, permission.toLocalizedString(Amber.instance), type.name.split("_").first())) + } + + is TagArrayEncryptedDataKind -> { + append(stringResource(R.string.wants_to_read_this_list_of_tags_from_encrypted_content, type.name.split("_").first())) + } + + else -> append(stringResource(R.string.wants_to_read_this_text_from_encrypted_content, type.name.split("_").first())) + } + } }, fontSize = 18.sp, ) Spacer(Modifier.size(4.dp)) - if (!type.toString().contains("DECRYPT")) { - Card( - modifier = Modifier - .fillMaxWidth(), - ) { - Column(Modifier.padding(6.dp)) { - Text( - "Event content", - fontWeight = FontWeight.Bold, - ) + Card( + modifier = Modifier + .fillMaxWidth(), + ) { + Column(Modifier.padding(6.dp)) { + Text( + stringResource(R.string.content).capitalize(Locale.current), + fontWeight = FontWeight.Bold, + ) + + if (encryptedData is EventEncryptedDataKind) { + val content = if (encryptedData.event.kind == 22242) encryptedData.event.relay() else encryptedData.event.content + if (encryptedData.event.kind == ContactListEvent.KIND) { + ContactListDetail( + title = stringResource(R.string.following), + text = "${encryptedData.event.verifiedFollowKeySet().size}", + ) + } else { + Text( + content, + modifier = Modifier + .fillMaxWidth() + .padding(top = 8.dp), + ) + } + } else { + val content = if (type.name.contains("ENCRYPT") && encryptedData is ClearTextEncryptedDataKind) encryptedData.text else encryptedData?.result ?: "" Text( content, - maxLines = 1, - overflow = TextOverflow.Ellipsis, modifier = Modifier .fillMaxWidth() .padding(top = 8.dp), @@ -118,37 +152,8 @@ fun EncryptDecryptData( } } } - RawJsonButton( - onCLick = { - showMore = !showMore - }, - if (!showMore) stringResource(R.string.show_details) else stringResource(R.string.hide_details), - ) - if (showMore) { - RawJson( - content, - encryptedData, - Modifier.height(200.dp), - stringResource(R.string.encrypted_decrypted_data), - type, - ) { - coroutineScope.launch { - clipboardManager.setClipEntry( - ClipEntry( - ClipData.newPlainText("", encryptedData), - ), - ) - Toast.makeText( - context, - context.getString(R.string.data_copied_to_the_clipboard), - Toast.LENGTH_SHORT, - ).show() - } - } - } else { - Spacer(modifier = Modifier.weight(1f)) - } + Spacer(modifier = Modifier.weight(1f)) RememberMyChoice( shouldRunOnAccept, diff --git a/app/src/main/java/com/greenart7c3/nostrsigner/ui/components/IntentSingleEventHomeScreen.kt b/app/src/main/java/com/greenart7c3/nostrsigner/ui/components/IntentSingleEventHomeScreen.kt index df70b6aa..b40473f0 100644 --- a/app/src/main/java/com/greenart7c3/nostrsigner/ui/components/IntentSingleEventHomeScreen.kt +++ b/app/src/main/java/com/greenart7c3/nostrsigner/ui/components/IntentSingleEventHomeScreen.kt @@ -188,8 +188,7 @@ fun IntentSingleEventHomeScreen( EncryptDecryptData( account = account, modifier = modifier, - content = intentData.data, - encryptedData = intentData.encryptedData ?: "", + encryptedData = intentData.encryptedData, shouldRunOnAccept = acceptOrReject, packageName = packageName, applicationName = applicationName, @@ -197,10 +196,10 @@ fun IntentSingleEventHomeScreen( type = intentData.type, onAccept = { val result = - if (intentData.encryptedData == "Could not decrypt the message" && (intentData.type == SignerType.DECRYPT_ZAP_EVENT)) { + if (intentData.encryptedData?.result == "Could not decrypt the message" && (intentData.type == SignerType.DECRYPT_ZAP_EVENT)) { "" } else { - intentData.encryptedData ?: "" + intentData.encryptedData?.result ?: "" } IntentUtils.sendResult( diff --git a/app/src/main/java/com/greenart7c3/nostrsigner/ui/components/MultiEventHomeScreen.kt b/app/src/main/java/com/greenart7c3/nostrsigner/ui/components/MultiEventHomeScreen.kt index 5f31d438..fe7ce4f2 100644 --- a/app/src/main/java/com/greenart7c3/nostrsigner/ui/components/MultiEventHomeScreen.kt +++ b/app/src/main/java/com/greenart7c3/nostrsigner/ui/components/MultiEventHomeScreen.kt @@ -48,10 +48,14 @@ import com.greenart7c3.nostrsigner.database.ApplicationWithPermissions import com.greenart7c3.nostrsigner.database.HistoryEntity import com.greenart7c3.nostrsigner.models.Account import com.greenart7c3.nostrsigner.models.AmberBunkerRequest +import com.greenart7c3.nostrsigner.models.ClearTextEncryptedDataKind +import com.greenart7c3.nostrsigner.models.EventEncryptedDataKind import com.greenart7c3.nostrsigner.models.IntentData import com.greenart7c3.nostrsigner.models.IntentResultType import com.greenart7c3.nostrsigner.models.Permission +import com.greenart7c3.nostrsigner.models.PrivateZapEncryptedDataKind import com.greenart7c3.nostrsigner.models.SignerType +import com.greenart7c3.nostrsigner.models.TagArrayEncryptedDataKind import com.greenart7c3.nostrsigner.service.AmberUtils import com.greenart7c3.nostrsigner.service.ApplicationNameCache import com.greenart7c3.nostrsigner.service.BunkerRequestUtils @@ -116,14 +120,41 @@ fun IntentMultiEventHomeScreen( onLoading: (Boolean) -> Unit, ) { val context = LocalContext.current - val grouped = intents.groupBy { it.type }.filter { it.key != SignerType.SIGN_EVENT } - val grouped2 = intents.filter { it.type == SignerType.SIGN_EVENT }.groupBy { it.event?.kind } - val acceptEventsGroup1 = grouped.map { + val groupedEventEncryptedData = intents.filter { it.encryptedData is EventEncryptedDataKind }.groupBy { it.type } + val groupedTextEncryptedData = intents.filter { it.encryptedData is ClearTextEncryptedDataKind }.groupBy { it.type } + val groupedTagArrayEncryptedData = intents.filter { it.encryptedData is TagArrayEncryptedDataKind }.groupBy { it.type } + val groupedPrivateZapEncryptedDataKind = intents.filter { it.encryptedData is PrivateZapEncryptedDataKind }.groupBy { it.type } + val groupedOthers = intents.filter { it.encryptedData == null && it.type != SignerType.SIGN_EVENT }.groupBy { it.type } + val groupedEvents = intents.filter { it.type == SignerType.SIGN_EVENT }.groupBy { it.event?.kind } + val acceptedGroupedEventEncryptedData = groupedEventEncryptedData.map { remember { mutableStateOf(true) } } - val acceptEventsGroup2 = grouped2.map { + val acceptedGroupedTextEncryptedData = groupedTextEncryptedData.map { + remember { + mutableStateOf(true) + } + } + val acceptedGroupedTagArrayEncryptedData = groupedTagArrayEncryptedData.map { + remember { + mutableStateOf(true) + } + } + + val acceptedGroupedPrivateZapEncryptedDataKind = groupedPrivateZapEncryptedDataKind.map { + remember { + mutableStateOf(true) + } + } + + val acceptEventsGroupOthers = groupedOthers.map { + remember { + mutableStateOf(true) + } + } + + val acceptEventsGroup2 = groupedEvents.map { remember { mutableStateOf(true) } @@ -153,10 +184,10 @@ fun IntentMultiEventHomeScreen( .padding(bottom = 20.dp), ) - grouped.toList().forEachIndexed { index, it -> + groupedEventEncryptedData.toList().forEachIndexed { index, it -> PermissionCard( context = context, - acceptEventsGroup = acceptEventsGroup1, + acceptEventsGroup = acceptedGroupedEventEncryptedData, index = index, item = it, onDetailsClick = { @@ -166,7 +197,59 @@ fun IntentMultiEventHomeScreen( }, ) } - grouped2.toList().forEachIndexed { index, it -> + groupedTextEncryptedData.toList().forEachIndexed { index, it -> + PermissionCard( + context = context, + acceptEventsGroup = acceptedGroupedTextEncryptedData, + index = index, + item = it, + onDetailsClick = { + MultiEventScreenIntents.intents = it + MultiEventScreenIntents.appName = appName + navController.navigate(Route.SeeDetails.route) + }, + ) + } + groupedTagArrayEncryptedData.toList().forEachIndexed { index, it -> + PermissionCard( + context = context, + acceptEventsGroup = acceptedGroupedTagArrayEncryptedData, + index = index, + item = it, + onDetailsClick = { + MultiEventScreenIntents.intents = it + MultiEventScreenIntents.appName = appName + navController.navigate(Route.SeeDetails.route) + }, + ) + } + groupedPrivateZapEncryptedDataKind.toList().forEachIndexed { index, it -> + PermissionCard( + context = context, + acceptEventsGroup = acceptedGroupedPrivateZapEncryptedDataKind, + index = index, + item = it, + onDetailsClick = { + MultiEventScreenIntents.intents = it + MultiEventScreenIntents.appName = appName + navController.navigate(Route.SeeDetails.route) + }, + ) + } + groupedOthers.toList().forEachIndexed { index, it -> + PermissionCard( + context = context, + acceptEventsGroup = acceptEventsGroupOthers, + index = index, + item = it, + onDetailsClick = { + MultiEventScreenIntents.intents = it + MultiEventScreenIntents.appName = appName + navController.navigate(Route.SeeDetails.route) + }, + ) + } + groupedEvents.toList().forEachIndexed { index, it -> PermissionCard( context = context, acceptEventsGroup = acceptEventsGroup2, @@ -373,7 +456,7 @@ fun IntentMultiEventHomeScreen( thisAccount.npub, ) - val signature = intentData.encryptedData ?: continue + val signature = intentData.encryptedData?.result ?: continue if (intentData.checked.value) { results.add( Result( @@ -1004,7 +1087,38 @@ fun PermissionCard( val message = if (first == SignerType.CONNECT) { stringResource(R.string.connect) } else { - permission.toLocalizedString(context) + val encryptedData = item.second.first().encryptedData + if (first.toString().contains("ENCRYPT")) { + when (encryptedData) { + is EventEncryptedDataKind -> { + val permission = Permission("sign_event", encryptedData.event.kind) + stringResource(R.string.encrypt_with, permission.toLocalizedString(context), first.toString().split("_").first()) + } + + is TagArrayEncryptedDataKind -> { + stringResource(R.string.encrypt_this_list_of_tags_with, first.toString().split("_").first()) + } + + else -> stringResource(R.string.encrypt_this_text_with, first.toString().split("_").first()) + } + } else { + if (first.toString().contains("DECRYPT")) { + when (encryptedData) { + is EventEncryptedDataKind -> { + val permission = Permission("sign_event", encryptedData.event.kind) + stringResource(R.string.read_from_encrypted_content, permission.toLocalizedString(context), first.toString().split("_").first()) + } + + is TagArrayEncryptedDataKind -> { + stringResource(R.string.read_this_list_of_tags_from_encrypted_content, first.toString().split("_").first()) + } + + else -> stringResource(R.string.read_this_text_from_encrypted_content, first.toString().split("_").first()) + } + } else { + permission.toLocalizedString(context) + } + } } Text( diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7d9627f5..f9bfb1f8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -579,4 +579,19 @@ Would you like to send the recent crash report to Amber in a DM? No personal information will be shared Would you like to copy the crash report to your clipboard and open a Client to send it to Amber? Send it + Event content + Direct Message + " wants to encrypt %1$s with %2$s" + " wants to encrypt this list of tags with %1$s" + " wants to encrypt this text with %1$s" + " wants to read %1$s from %2$s encrypted content" + " wants to read this list of tags from %1$s encrypted content" + " wants to read this text from %1$s encrypted content" + + Encrypt %1$s with %2$s + Encrypt this list of tags with %1$s + Encrypt this text with %1$s + Read %1$s from %2$s encrypted content + Read this list of tags from %1$s encrypted content + Read this text from %1$s encrypted content