decrypt LnZapRequestEvent
This commit is contained in:
@@ -2523,14 +2523,40 @@ class Account(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun decryptContentWithAmber(note: Note): String? = with(Dispatchers.IO) {
|
||||||
|
val event = note.event
|
||||||
|
return when (event) {
|
||||||
|
is PrivateDmEvent -> {
|
||||||
|
AmberUtils.decrypt(event.content, event.talkingWith(userProfile().pubkeyHex), event.id)
|
||||||
|
AmberUtils.cachedDecryptedContent[event.id]
|
||||||
|
}
|
||||||
|
is LnZapRequestEvent -> {
|
||||||
|
decryptZapContentAuthor(note)?.content()
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
event?.content()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun decryptZapContentAuthor(note: Note): Event? {
|
fun decryptZapContentAuthor(note: Note): Event? {
|
||||||
val event = note.event
|
val event = note.event
|
||||||
val loggedInPrivateKey = keyPair.privKey
|
val loggedInPrivateKey = keyPair.privKey
|
||||||
|
|
||||||
|
if (loginWithAmber && event is LnZapRequestEvent && event.isPrivateZap()) {
|
||||||
|
val decryptedContent = AmberUtils.cachedDecryptedContent[event.id]
|
||||||
|
if (decryptedContent != null) {
|
||||||
|
return Event.fromJson(decryptedContent)
|
||||||
|
}
|
||||||
|
AmberUtils.decryptZapEvent(event)
|
||||||
|
if (AmberUtils.content.isBlank()) return null
|
||||||
|
AmberUtils.cachedDecryptedContent[event.id] = AmberUtils.content
|
||||||
|
return Event.fromJson(AmberUtils.content)
|
||||||
|
}
|
||||||
|
|
||||||
return if (event is LnZapRequestEvent && loggedInPrivateKey != null && event.isPrivateZap()) {
|
return if (event is LnZapRequestEvent && loggedInPrivateKey != null && event.isPrivateZap()) {
|
||||||
val recipientPK = event.zappedAuthor().firstOrNull()
|
val recipientPK = event.zappedAuthor().firstOrNull()
|
||||||
val recipientPost = event.zappedPost().firstOrNull()
|
val recipientPost = event.zappedPost().firstOrNull()
|
||||||
|
|
||||||
if (recipientPK == userProfile().pubkeyHex) {
|
if (recipientPK == userProfile().pubkeyHex) {
|
||||||
// if the receiver is logged in, these are the params.
|
// if the receiver is logged in, these are the params.
|
||||||
val privateKeyToUse = loggedInPrivateKey
|
val privateKeyToUse = loggedInPrivateKey
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import com.vitorpamplona.amethyst.ServiceManager
|
|||||||
import com.vitorpamplona.amethyst.ui.actions.SignerType
|
import com.vitorpamplona.amethyst.ui.actions.SignerType
|
||||||
import com.vitorpamplona.quartz.encoders.HexKey
|
import com.vitorpamplona.quartz.encoders.HexKey
|
||||||
import com.vitorpamplona.quartz.events.EventInterface
|
import com.vitorpamplona.quartz.events.EventInterface
|
||||||
|
import com.vitorpamplona.quartz.events.LnZapRequestEvent
|
||||||
|
|
||||||
object AmberUtils {
|
object AmberUtils {
|
||||||
var content: String = ""
|
var content: String = ""
|
||||||
@@ -29,6 +30,7 @@ object AmberUtils {
|
|||||||
SignerType.NIP44_ENCRYPT -> "nip44_encrypt"
|
SignerType.NIP44_ENCRYPT -> "nip44_encrypt"
|
||||||
SignerType.NIP44_DECRYPT -> "nip44_decrypt"
|
SignerType.NIP44_DECRYPT -> "nip44_decrypt"
|
||||||
SignerType.GET_PUBLIC_KEY -> "get_public_key"
|
SignerType.GET_PUBLIC_KEY -> "get_public_key"
|
||||||
|
SignerType.DECRYPT_ZAP_EVENT -> "decrypt_zap_event"
|
||||||
}
|
}
|
||||||
intent.putExtra("type", signerType)
|
intent.putExtra("type", signerType)
|
||||||
intent.putExtra("pubKey", pubKey)
|
intent.putExtra("pubKey", pubKey)
|
||||||
@@ -101,4 +103,20 @@ object AmberUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun decryptZapEvent(event: LnZapRequestEvent) {
|
||||||
|
if (content.isBlank()) {
|
||||||
|
isActivityRunning = true
|
||||||
|
openAmber(
|
||||||
|
event.toJson(),
|
||||||
|
SignerType.DECRYPT_ZAP_EVENT,
|
||||||
|
IntentUtils.activityResultLauncher,
|
||||||
|
event.pubKey,
|
||||||
|
event.id
|
||||||
|
)
|
||||||
|
while (isActivityRunning) {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,8 @@ enum class SignerType {
|
|||||||
NIP04_DECRYPT,
|
NIP04_DECRYPT,
|
||||||
NIP44_ENCRYPT,
|
NIP44_ENCRYPT,
|
||||||
NIP44_DECRYPT,
|
NIP44_DECRYPT,
|
||||||
GET_PUBLIC_KEY
|
GET_PUBLIC_KEY,
|
||||||
|
DECRYPT_ZAP_EVENT
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
|||||||
@@ -361,6 +361,9 @@ class AccountViewModel(val account: Account) : ViewModel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun decrypt(note: Note): String? {
|
fun decrypt(note: Note): String? {
|
||||||
|
if (loggedInWithAmber()) {
|
||||||
|
return account.decryptContentWithAmber(note)
|
||||||
|
}
|
||||||
return account.decryptContent(note)
|
return account.decryptContent(note)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user