mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-29 04:52:31 +02:00
Completing Intent writing implementation
This commit is contained in:
@@ -20,7 +20,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.vitorpamplona.quartz.nip55AndroidSigner.api.foreground.intents.responses
|
package com.vitorpamplona.quartz.nip55AndroidSigner.api.foreground.intents.responses
|
||||||
|
|
||||||
import android.content.Intent
|
|
||||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||||
import com.vitorpamplona.quartz.nip55AndroidSigner.api.SignerResult
|
import com.vitorpamplona.quartz.nip55AndroidSigner.api.SignerResult
|
||||||
import com.vitorpamplona.quartz.nip55AndroidSigner.api.ZapEventDecryptionResult
|
import com.vitorpamplona.quartz.nip55AndroidSigner.api.ZapEventDecryptionResult
|
||||||
@@ -29,11 +28,10 @@ import com.vitorpamplona.quartz.nip57Zaps.LnZapPrivateEvent
|
|||||||
|
|
||||||
class DecryptZapResponse {
|
class DecryptZapResponse {
|
||||||
companion object {
|
companion object {
|
||||||
fun assemble(event: LnZapPrivateEvent): Intent {
|
fun assemble(event: LnZapPrivateEvent): IntentResult =
|
||||||
val intent = Intent()
|
IntentResult(
|
||||||
intent.putExtra("result", event.toJson())
|
result = event.toJson(),
|
||||||
return intent
|
)
|
||||||
}
|
|
||||||
|
|
||||||
fun parse(intent: IntentResult): SignerResult.RequestAddressed<ZapEventDecryptionResult> {
|
fun parse(intent: IntentResult): SignerResult.RequestAddressed<ZapEventDecryptionResult> {
|
||||||
val eventJson = intent.result
|
val eventJson = intent.result
|
||||||
|
@@ -20,12 +20,18 @@
|
|||||||
*/
|
*/
|
||||||
package com.vitorpamplona.quartz.nip55AndroidSigner.api.foreground.intents.responses
|
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.DerivationResult
|
||||||
import com.vitorpamplona.quartz.nip55AndroidSigner.api.SignerResult
|
import com.vitorpamplona.quartz.nip55AndroidSigner.api.SignerResult
|
||||||
import com.vitorpamplona.quartz.nip55AndroidSigner.api.foreground.intents.results.IntentResult
|
import com.vitorpamplona.quartz.nip55AndroidSigner.api.foreground.intents.results.IntentResult
|
||||||
|
|
||||||
class DeriveKeyResponse {
|
class DeriveKeyResponse {
|
||||||
companion object {
|
companion object {
|
||||||
|
fun assemble(newPrivateKey: HexKey): IntentResult =
|
||||||
|
IntentResult(
|
||||||
|
result = newPrivateKey,
|
||||||
|
)
|
||||||
|
|
||||||
fun parse(intent: IntentResult): SignerResult.RequestAddressed<DerivationResult> {
|
fun parse(intent: IntentResult): SignerResult.RequestAddressed<DerivationResult> {
|
||||||
val newPrivateKey = intent.result
|
val newPrivateKey = intent.result
|
||||||
return if (newPrivateKey != null) {
|
return if (newPrivateKey != null) {
|
||||||
|
@@ -20,12 +20,22 @@
|
|||||||
*/
|
*/
|
||||||
package com.vitorpamplona.quartz.nip55AndroidSigner.api.foreground.intents.responses
|
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.PubKeyResult
|
||||||
import com.vitorpamplona.quartz.nip55AndroidSigner.api.SignerResult
|
import com.vitorpamplona.quartz.nip55AndroidSigner.api.SignerResult
|
||||||
import com.vitorpamplona.quartz.nip55AndroidSigner.api.foreground.intents.results.IntentResult
|
import com.vitorpamplona.quartz.nip55AndroidSigner.api.foreground.intents.results.IntentResult
|
||||||
|
|
||||||
class LoginResponse {
|
class LoginResponse {
|
||||||
companion object {
|
companion object {
|
||||||
|
fun assemble(
|
||||||
|
pubkey: HexKey,
|
||||||
|
packageName: String,
|
||||||
|
): IntentResult =
|
||||||
|
IntentResult(
|
||||||
|
result = pubkey,
|
||||||
|
`package` = packageName,
|
||||||
|
)
|
||||||
|
|
||||||
fun parse(intent: IntentResult): SignerResult.RequestAddressed<PubKeyResult> {
|
fun parse(intent: IntentResult): SignerResult.RequestAddressed<PubKeyResult> {
|
||||||
val pubkey = intent.result
|
val pubkey = intent.result
|
||||||
val packageName = intent.`package`
|
val packageName = intent.`package`
|
||||||
|
@@ -26,10 +26,15 @@ import com.vitorpamplona.quartz.nip55AndroidSigner.api.foreground.intents.result
|
|||||||
|
|
||||||
class Nip04DecryptResponse {
|
class Nip04DecryptResponse {
|
||||||
companion object {
|
companion object {
|
||||||
|
fun assemble(plaintext: String): IntentResult =
|
||||||
|
IntentResult(
|
||||||
|
result = plaintext,
|
||||||
|
)
|
||||||
|
|
||||||
fun parse(intent: IntentResult): SignerResult.RequestAddressed<DecryptionResult> {
|
fun parse(intent: IntentResult): SignerResult.RequestAddressed<DecryptionResult> {
|
||||||
val ciphertext = intent.result
|
val plaintext = intent.result
|
||||||
return if (ciphertext != null) {
|
return if (plaintext != null) {
|
||||||
SignerResult.RequestAddressed.Successful(DecryptionResult(ciphertext))
|
SignerResult.RequestAddressed.Successful(DecryptionResult(plaintext))
|
||||||
} else {
|
} else {
|
||||||
SignerResult.RequestAddressed.ReceivedButCouldNotPerform()
|
SignerResult.RequestAddressed.ReceivedButCouldNotPerform()
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,11 @@ import com.vitorpamplona.quartz.nip55AndroidSigner.api.foreground.intents.result
|
|||||||
|
|
||||||
class Nip04EncryptResponse {
|
class Nip04EncryptResponse {
|
||||||
companion object {
|
companion object {
|
||||||
|
fun assemble(ciphertext: String): IntentResult =
|
||||||
|
IntentResult(
|
||||||
|
result = ciphertext,
|
||||||
|
)
|
||||||
|
|
||||||
fun parse(intent: IntentResult): SignerResult.RequestAddressed<EncryptionResult> {
|
fun parse(intent: IntentResult): SignerResult.RequestAddressed<EncryptionResult> {
|
||||||
val ciphertext = intent.result
|
val ciphertext = intent.result
|
||||||
return if (ciphertext != null) {
|
return if (ciphertext != null) {
|
||||||
|
@@ -26,10 +26,15 @@ import com.vitorpamplona.quartz.nip55AndroidSigner.api.foreground.intents.result
|
|||||||
|
|
||||||
class Nip44DecryptResponse {
|
class Nip44DecryptResponse {
|
||||||
companion object {
|
companion object {
|
||||||
|
fun assemble(plaintext: String): IntentResult =
|
||||||
|
IntentResult(
|
||||||
|
result = plaintext,
|
||||||
|
)
|
||||||
|
|
||||||
fun parse(intent: IntentResult): SignerResult.RequestAddressed<DecryptionResult> {
|
fun parse(intent: IntentResult): SignerResult.RequestAddressed<DecryptionResult> {
|
||||||
val ciphertext = intent.result
|
val plaintext = intent.result
|
||||||
return if (ciphertext != null) {
|
return if (plaintext != null) {
|
||||||
SignerResult.RequestAddressed.Successful(DecryptionResult(ciphertext))
|
SignerResult.RequestAddressed.Successful(DecryptionResult(plaintext))
|
||||||
} else {
|
} else {
|
||||||
SignerResult.RequestAddressed.ReceivedButCouldNotPerform()
|
SignerResult.RequestAddressed.ReceivedButCouldNotPerform()
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,11 @@ import com.vitorpamplona.quartz.nip55AndroidSigner.api.foreground.intents.result
|
|||||||
|
|
||||||
class Nip44EncryptResponse {
|
class Nip44EncryptResponse {
|
||||||
companion object {
|
companion object {
|
||||||
|
fun assemble(ciphertext: String): IntentResult =
|
||||||
|
IntentResult(
|
||||||
|
result = ciphertext,
|
||||||
|
)
|
||||||
|
|
||||||
fun parse(intent: IntentResult): SignerResult.RequestAddressed<EncryptionResult> {
|
fun parse(intent: IntentResult): SignerResult.RequestAddressed<EncryptionResult> {
|
||||||
val ciphertext = intent.result
|
val ciphertext = intent.result
|
||||||
return if (ciphertext != null) {
|
return if (ciphertext != null) {
|
||||||
|
@@ -29,6 +29,12 @@ import com.vitorpamplona.quartz.nip55AndroidSigner.api.foreground.intents.result
|
|||||||
|
|
||||||
class SignResponse {
|
class SignResponse {
|
||||||
companion object {
|
companion object {
|
||||||
|
fun assemble(event: Event): IntentResult =
|
||||||
|
IntentResult(
|
||||||
|
event = event.toJson(),
|
||||||
|
result = event.sig,
|
||||||
|
)
|
||||||
|
|
||||||
fun parse(
|
fun parse(
|
||||||
intent: IntentResult,
|
intent: IntentResult,
|
||||||
unsignedEvent: Event,
|
unsignedEvent: Event,
|
||||||
|
@@ -24,11 +24,11 @@ import android.content.Intent
|
|||||||
import com.fasterxml.jackson.module.kotlin.readValue
|
import com.fasterxml.jackson.module.kotlin.readValue
|
||||||
import com.vitorpamplona.quartz.nip01Core.jackson.JsonMapper
|
import com.vitorpamplona.quartz.nip01Core.jackson.JsonMapper
|
||||||
|
|
||||||
class IntentResult(
|
data class IntentResult(
|
||||||
val `package`: String?,
|
val `package`: String? = null,
|
||||||
val result: String?,
|
val result: String? = null,
|
||||||
val event: String?,
|
val event: String? = null,
|
||||||
val id: String?,
|
val id: String? = null,
|
||||||
) {
|
) {
|
||||||
fun toJson(): String = JsonMapper.mapper.writeValueAsString(this)
|
fun toJson(): String = JsonMapper.mapper.writeValueAsString(this)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user