Completing Intent writing implementation

This commit is contained in:
Vitor Pamplona
2025-07-22 10:54:24 -04:00
parent e6b5d51cda
commit a3ec4d4260
9 changed files with 57 additions and 17 deletions

View File

@@ -20,7 +20,6 @@
*/
package com.vitorpamplona.quartz.nip55AndroidSigner.api.foreground.intents.responses
import android.content.Intent
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip55AndroidSigner.api.SignerResult
import com.vitorpamplona.quartz.nip55AndroidSigner.api.ZapEventDecryptionResult
@@ -29,11 +28,10 @@ import com.vitorpamplona.quartz.nip57Zaps.LnZapPrivateEvent
class DecryptZapResponse {
companion object {
fun assemble(event: LnZapPrivateEvent): Intent {
val intent = Intent()
intent.putExtra("result", event.toJson())
return intent
}
fun assemble(event: LnZapPrivateEvent): IntentResult =
IntentResult(
result = event.toJson(),
)
fun parse(intent: IntentResult): SignerResult.RequestAddressed<ZapEventDecryptionResult> {
val eventJson = intent.result

View File

@@ -20,12 +20,18 @@
*/
package com.vitorpamplona.quartz.nip55AndroidSigner.api.foreground.intents.responses
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip55AndroidSigner.api.DerivationResult
import com.vitorpamplona.quartz.nip55AndroidSigner.api.SignerResult
import com.vitorpamplona.quartz.nip55AndroidSigner.api.foreground.intents.results.IntentResult
class DeriveKeyResponse {
companion object {
fun assemble(newPrivateKey: HexKey): IntentResult =
IntentResult(
result = newPrivateKey,
)
fun parse(intent: IntentResult): SignerResult.RequestAddressed<DerivationResult> {
val newPrivateKey = intent.result
return if (newPrivateKey != null) {

View File

@@ -20,12 +20,22 @@
*/
package com.vitorpamplona.quartz.nip55AndroidSigner.api.foreground.intents.responses
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip55AndroidSigner.api.PubKeyResult
import com.vitorpamplona.quartz.nip55AndroidSigner.api.SignerResult
import com.vitorpamplona.quartz.nip55AndroidSigner.api.foreground.intents.results.IntentResult
class LoginResponse {
companion object {
fun assemble(
pubkey: HexKey,
packageName: String,
): IntentResult =
IntentResult(
result = pubkey,
`package` = packageName,
)
fun parse(intent: IntentResult): SignerResult.RequestAddressed<PubKeyResult> {
val pubkey = intent.result
val packageName = intent.`package`

View File

@@ -26,10 +26,15 @@ import com.vitorpamplona.quartz.nip55AndroidSigner.api.foreground.intents.result
class Nip04DecryptResponse {
companion object {
fun assemble(plaintext: String): IntentResult =
IntentResult(
result = plaintext,
)
fun parse(intent: IntentResult): SignerResult.RequestAddressed<DecryptionResult> {
val ciphertext = intent.result
return if (ciphertext != null) {
SignerResult.RequestAddressed.Successful(DecryptionResult(ciphertext))
val plaintext = intent.result
return if (plaintext != null) {
SignerResult.RequestAddressed.Successful(DecryptionResult(plaintext))
} else {
SignerResult.RequestAddressed.ReceivedButCouldNotPerform()
}

View File

@@ -26,6 +26,11 @@ import com.vitorpamplona.quartz.nip55AndroidSigner.api.foreground.intents.result
class Nip04EncryptResponse {
companion object {
fun assemble(ciphertext: String): IntentResult =
IntentResult(
result = ciphertext,
)
fun parse(intent: IntentResult): SignerResult.RequestAddressed<EncryptionResult> {
val ciphertext = intent.result
return if (ciphertext != null) {

View File

@@ -26,10 +26,15 @@ import com.vitorpamplona.quartz.nip55AndroidSigner.api.foreground.intents.result
class Nip44DecryptResponse {
companion object {
fun assemble(plaintext: String): IntentResult =
IntentResult(
result = plaintext,
)
fun parse(intent: IntentResult): SignerResult.RequestAddressed<DecryptionResult> {
val ciphertext = intent.result
return if (ciphertext != null) {
SignerResult.RequestAddressed.Successful(DecryptionResult(ciphertext))
val plaintext = intent.result
return if (plaintext != null) {
SignerResult.RequestAddressed.Successful(DecryptionResult(plaintext))
} else {
SignerResult.RequestAddressed.ReceivedButCouldNotPerform()
}

View File

@@ -26,6 +26,11 @@ import com.vitorpamplona.quartz.nip55AndroidSigner.api.foreground.intents.result
class Nip44EncryptResponse {
companion object {
fun assemble(ciphertext: String): IntentResult =
IntentResult(
result = ciphertext,
)
fun parse(intent: IntentResult): SignerResult.RequestAddressed<EncryptionResult> {
val ciphertext = intent.result
return if (ciphertext != null) {

View File

@@ -29,6 +29,12 @@ import com.vitorpamplona.quartz.nip55AndroidSigner.api.foreground.intents.result
class SignResponse {
companion object {
fun assemble(event: Event): IntentResult =
IntentResult(
event = event.toJson(),
result = event.sig,
)
fun parse(
intent: IntentResult,
unsignedEvent: Event,

View File

@@ -24,11 +24,11 @@ import android.content.Intent
import com.fasterxml.jackson.module.kotlin.readValue
import com.vitorpamplona.quartz.nip01Core.jackson.JsonMapper
class IntentResult(
val `package`: String?,
val result: String?,
val event: String?,
val id: String?,
data class IntentResult(
val `package`: String? = null,
val result: String? = null,
val event: String? = null,
val id: String? = null,
) {
fun toJson(): String = JsonMapper.mapper.writeValueAsString(this)