Skip to content

Commit

Permalink
fix decryption for web apps
Browse files Browse the repository at this point in the history
  • Loading branch information
greenart7c3 committed Dec 6, 2023
1 parent f73188f commit 1834931
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class MainActivity : AppCompatActivity() {
super.onNewIntent(intent)
if (intent == null) return

val intentData = IntentUtils.getIntentData(intent) ?: return
val intentData = IntentUtils.getIntentData(intent, callingPackage) ?: return
val list = mutableListOf(intentData)
if (mainViewModel.intents.value == null) {
mainViewModel.intents.value = mutableListOf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import com.vitorpamplona.quartz.events.Event
import java.net.URLDecoder

object IntentUtils {
fun getIntentData(intent: Intent): IntentData? {
fun getIntentData(intent: Intent, packageName: String?): IntentData? {
if (intent.data != null) {
val type = when (intent.extras?.getString("type")) {
"sign_event" -> SignerType.SIGN_EVENT
Expand All @@ -31,11 +31,10 @@ object IntentUtils {
}

val data = try {
when (type) {
SignerType.NIP44_ENCRYPT, SignerType.NIP04_DECRYPT, SignerType.NIP44_DECRYPT, SignerType.NIP04_ENCRYPT -> {
intent.data?.toString()?.replace("nostrsigner:", "") ?: ""
}
else -> URLDecoder.decode(intent.data?.toString()?.replace("+", "%2b") ?: "", "utf-8").replace("nostrsigner:", "")
if (packageName == null) {
URLDecoder.decode(intent.data?.toString()?.replace("+", "%2b") ?: "", "utf-8").replace("nostrsigner:", "")
} else {
intent.data?.toString()?.replace("nostrsigner:", "") ?: ""
}
} catch (e: Exception) {
intent.data?.toString()?.replace("nostrsigner:", "") ?: ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fun AccountScreen(
LoginPage(accountStateViewModel)
}
is AccountState.LoggedIn -> {
val intentData = IntentUtils.getIntentData(intent)
val intentData = IntentUtils.getIntentData(intent, packageName)
if (intentData != null) {
if (intents.none { item -> item.id == intentData.id }) {
intents.add(intentData)
Expand Down
16 changes: 11 additions & 5 deletions app/src/main/java/com/greenart7c3/nostrsigner/ui/MainScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,15 @@ import com.greenart7c3.nostrsigner.ui.actions.AccountsBottomSheet
import com.greenart7c3.nostrsigner.ui.navigation.Route
import com.greenart7c3.nostrsigner.ui.theme.ButtonBorder
import com.vitorpamplona.quartz.encoders.toNpub
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import java.io.ByteArrayOutputStream
import java.util.Base64
import java.util.zip.GZIPOutputStream

@OptIn(DelicateCoroutinesApi::class)
fun sendResult(
context: Context,
packageName: String?,
Expand Down Expand Up @@ -155,11 +159,13 @@ fun sendResult(

clipboardManager.setText(AnnotatedString(result))

Toast.makeText(
context,
message,
Toast.LENGTH_SHORT
).show()
GlobalScope.launch(Dispatchers.Main) {
Toast.makeText(
context,
message,
Toast.LENGTH_SHORT
).show()
}
}
activity?.finish()
}
Expand Down

0 comments on commit 1834931

Please sign in to comment.