kopia lustrzana https://github.com/vitorpamplona/amethyst
decrypt LnZapRequestEvent
rodzic
7ff6f16df0
commit
a773be12c4
|
@ -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? {
|
||||
val event = note.event
|
||||
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()) {
|
||||
val recipientPK = event.zappedAuthor().firstOrNull()
|
||||
val recipientPost = event.zappedPost().firstOrNull()
|
||||
|
||||
if (recipientPK == userProfile().pubkeyHex) {
|
||||
// if the receiver is logged in, these are the params.
|
||||
val privateKeyToUse = loggedInPrivateKey
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.vitorpamplona.amethyst.ServiceManager
|
|||
import com.vitorpamplona.amethyst.ui.actions.SignerType
|
||||
import com.vitorpamplona.quartz.encoders.HexKey
|
||||
import com.vitorpamplona.quartz.events.EventInterface
|
||||
import com.vitorpamplona.quartz.events.LnZapRequestEvent
|
||||
|
||||
object AmberUtils {
|
||||
var content: String = ""
|
||||
|
@ -29,6 +30,7 @@ object AmberUtils {
|
|||
SignerType.NIP44_ENCRYPT -> "nip44_encrypt"
|
||||
SignerType.NIP44_DECRYPT -> "nip44_decrypt"
|
||||
SignerType.GET_PUBLIC_KEY -> "get_public_key"
|
||||
SignerType.DECRYPT_ZAP_EVENT -> "decrypt_zap_event"
|
||||
}
|
||||
intent.putExtra("type", signerType)
|
||||
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,
|
||||
NIP44_ENCRYPT,
|
||||
NIP44_DECRYPT,
|
||||
GET_PUBLIC_KEY
|
||||
GET_PUBLIC_KEY,
|
||||
DECRYPT_ZAP_EVENT
|
||||
}
|
||||
|
||||
@Composable
|
||||
|
|
|
@ -361,6 +361,9 @@ class AccountViewModel(val account: Account) : ViewModel() {
|
|||
}
|
||||
|
||||
fun decrypt(note: Note): String? {
|
||||
if (loggedInWithAmber()) {
|
||||
return account.decryptContentWithAmber(note)
|
||||
}
|
||||
return account.decryptContent(note)
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue