Merge pull request #1465 from greenart7c3/main

When using intents check if it's rejected
This commit is contained in:
Vitor Pamplona
2025-09-08 13:25:19 -04:00
committed by GitHub
10 changed files with 27 additions and 0 deletions

View File

@@ -34,6 +34,9 @@ class DecryptZapResponse {
)
fun parse(intent: IntentResult): SignerResult.RequestAddressed<ZapEventDecryptionResult> {
if (intent.rejected) {
return SignerResult.RequestAddressed.ManuallyRejected()
}
val eventJson = intent.result
return if (!eventJson.isNullOrBlank()) {
if (eventJson.startsWith("{")) {

View File

@@ -33,6 +33,9 @@ class DeriveKeyResponse {
)
fun parse(intent: IntentResult): SignerResult.RequestAddressed<DerivationResult> {
if (intent.rejected) {
return SignerResult.RequestAddressed.ManuallyRejected()
}
val newPrivateKey = intent.result
return if (newPrivateKey != null) {
SignerResult.RequestAddressed.Successful(DerivationResult(newPrivateKey))

View File

@@ -32,6 +32,9 @@ class Nip04DecryptResponse {
)
fun parse(intent: IntentResult): SignerResult.RequestAddressed<DecryptionResult> {
if (intent.rejected) {
return SignerResult.RequestAddressed.ManuallyRejected()
}
val plaintext = intent.result
return if (plaintext != null) {
SignerResult.RequestAddressed.Successful(DecryptionResult(plaintext))

View File

@@ -32,6 +32,10 @@ class Nip04EncryptResponse {
)
fun parse(intent: IntentResult): SignerResult.RequestAddressed<EncryptionResult> {
if (intent.rejected) {
return SignerResult.RequestAddressed.ManuallyRejected()
}
val ciphertext = intent.result
return if (ciphertext != null) {
SignerResult.RequestAddressed.Successful(EncryptionResult(ciphertext))

View File

@@ -32,6 +32,9 @@ class Nip44DecryptResponse {
)
fun parse(intent: IntentResult): SignerResult.RequestAddressed<DecryptionResult> {
if (intent.rejected) {
return SignerResult.RequestAddressed.ManuallyRejected()
}
val plaintext = intent.result
return if (plaintext != null) {
SignerResult.RequestAddressed.Successful(DecryptionResult(plaintext))

View File

@@ -32,6 +32,9 @@ class Nip44EncryptResponse {
)
fun parse(intent: IntentResult): SignerResult.RequestAddressed<EncryptionResult> {
if (intent.rejected) {
return SignerResult.RequestAddressed.ManuallyRejected()
}
val ciphertext = intent.result
return if (ciphertext != null) {
SignerResult.RequestAddressed.Successful(EncryptionResult(ciphertext))

View File

@@ -39,6 +39,10 @@ class SignResponse {
intent: IntentResult,
unsignedEvent: Event,
): SignerResult.RequestAddressed<SignResult> {
if (intent.rejected) {
return SignerResult.RequestAddressed.ManuallyRejected()
}
val eventJson = intent.event
return if (eventJson != null) {
if (eventJson.startsWith("{")) {

View File

@@ -29,6 +29,7 @@ data class IntentResult(
val result: String? = null,
val event: String? = null,
val id: String? = null,
val rejected: Boolean = false,
) {
fun toJson(): String = JsonMapper.mapper.writeValueAsString(this)
@@ -48,6 +49,7 @@ data class IntentResult(
result = data.getStringExtra("result"),
event = data.getStringExtra("event"),
`package` = data.getStringExtra("package"),
rejected = data.extras?.containsKey("rejected") == true,
)
fun fromJson(json: String): IntentResult = JsonMapper.mapper.readValue<IntentResult>(json)

View File

@@ -36,6 +36,7 @@ class IntentResultJsonDeserializer : StdDeserializer<IntentResult>(IntentResult:
result = jsonObject.get("result")?.asText()?.intern(),
event = jsonObject.get("event")?.asText()?.intern(),
id = jsonObject.get("id")?.asText()?.intern(),
rejected = jsonObject.get("rejected")?.asBoolean() ?: false,
)
}
}

View File

@@ -35,6 +35,7 @@ class IntentResultJsonSerializer : StdSerializer<IntentResult>(IntentResult::cla
result.result?.let { gen.writeStringField("result", it) }
result.event?.let { gen.writeStringField("event", it) }
result.id?.let { gen.writeStringField("id", it) }
result.rejected.let { gen.writeBooleanField("rejected", it) }
gen.writeEndObject()
}
}