Add support for secret when using nostrconnect

This commit is contained in:
greenart7c3
2024-11-13 15:47:11 -03:00
parent e7c21fbedd
commit dcd88245d9
4 changed files with 15 additions and 3 deletions
@@ -24,6 +24,7 @@ data class BunkerRequest(
var secret: String,
var currentAccount: String,
var encryptionType: EncryptionType,
var nostrConnectSecret: String,
) {
fun toJson(): String {
return mapper.writeValueAsString(this)
@@ -92,6 +93,7 @@ data class BunkerRequest(
secret = jsonObject.get("secret")?.asText()?.intern() ?: "",
currentAccount = jsonObject.get("currentAccount")?.asText()?.intern() ?: "",
encryptionType = encryptionType,
nostrConnectSecret = jsonObject.get("nostrConnectSecret")?.asText()?.intern() ?: "",
)
}
@@ -127,6 +129,7 @@ data class BunkerRequest(
gen.writeStringField("secret", value.secret)
gen.writeStringField("currentAccount", value.currentAccount)
gen.writeStringField("encryptionType", value.encryptionType.toString())
gen.writeStringField("nostrConnectSecret", value.nostrConnectSecret)
gen.writeEndObject()
}
}
@@ -132,7 +132,7 @@ class EventNotificationConsumer(private val applicationContext: Context) {
applicationContext,
acc,
bunkerRequest,
BunkerResponse(bunkerRequest.id, "ack", null),
BunkerResponse(bunkerRequest.id, bunkerRequest.nostrConnectSecret.ifBlank { "ack" }, null),
permission.application.relays,
onLoading = {},
onDone = {},
@@ -248,7 +248,10 @@ class EventNotificationConsumer(private val applicationContext: Context) {
onDone = { },
)
} else {
val index = localCursor.getColumnIndex("event")
var index = localCursor.getColumnIndex("event")
if (index == -1) {
index = localCursor.getColumnIndex("result")
}
val result = localCursor.getString(index)
IntentUtils.sendBunkerResponse(
@@ -799,6 +799,7 @@ object IntentUtils {
val parsedData = URLDecoder.decode(split.drop(1).joinToString { it }.replace("+", "%2b"), "utf-8")
val splitParsedData = parsedData.split("&")
val permissions = mutableListOf<Permission>()
var nostrConnectSecret = ""
splitParsedData.forEach {
val internalSplit = it.split("=")
val paramName = internalSplit.first()
@@ -816,6 +817,10 @@ object IntentUtils {
name = json
}
if (paramName == "secret") {
nostrConnectSecret = json
}
if (paramName == "perms") {
if (json.isNotEmpty()) {
val splitPerms = json.split(",")
@@ -891,6 +896,7 @@ object IntentUtils {
"",
account.signer.keyPair.pubKey.toNpub(),
EncryptionType.NIP04,
nostrConnectSecret,
),
route,
null,
@@ -105,7 +105,7 @@ fun SingleEventHomeScreen(
{ permissions, signPolicy ->
val sig =
if (intentData.type == SignerType.CONNECT) {
"ack"
intentData.bunkerRequest!!.nostrConnectSecret.ifBlank { "ack" }
} else if (intentData.bunkerRequest != null) {
account.signer.keyPair.pubKey.toHexKey()
} else {