send the logged in npub to amber

This commit is contained in:
greenart7c3
2023-09-15 21:35:32 -03:00
parent 614dbab1fd
commit 9a648d7e84
8 changed files with 152 additions and 304 deletions
@@ -11,12 +11,12 @@ import com.vitorpamplona.amethyst.OptOutFromFilters
import com.vitorpamplona.amethyst.service.AmberUtils import com.vitorpamplona.amethyst.service.AmberUtils
import com.vitorpamplona.amethyst.service.FileHeader import com.vitorpamplona.amethyst.service.FileHeader
import com.vitorpamplona.amethyst.service.NostrLnZapPaymentResponseDataSource import com.vitorpamplona.amethyst.service.NostrLnZapPaymentResponseDataSource
import com.vitorpamplona.amethyst.service.SignerType
import com.vitorpamplona.amethyst.service.relays.Client import com.vitorpamplona.amethyst.service.relays.Client
import com.vitorpamplona.amethyst.service.relays.Constants import com.vitorpamplona.amethyst.service.relays.Constants
import com.vitorpamplona.amethyst.service.relays.FeedType import com.vitorpamplona.amethyst.service.relays.FeedType
import com.vitorpamplona.amethyst.service.relays.Relay import com.vitorpamplona.amethyst.service.relays.Relay
import com.vitorpamplona.amethyst.service.relays.RelayPool import com.vitorpamplona.amethyst.service.relays.RelayPool
import com.vitorpamplona.amethyst.ui.actions.SignerType
import com.vitorpamplona.amethyst.ui.components.BundledUpdate import com.vitorpamplona.amethyst.ui.components.BundledUpdate
import com.vitorpamplona.amethyst.ui.note.combineWith import com.vitorpamplona.amethyst.ui.note.combineWith
import com.vitorpamplona.quartz.crypto.CryptoUtils import com.vitorpamplona.quartz.crypto.CryptoUtils
@@ -25,6 +25,7 @@ import com.vitorpamplona.quartz.encoders.ATag
import com.vitorpamplona.quartz.encoders.HexKey import com.vitorpamplona.quartz.encoders.HexKey
import com.vitorpamplona.quartz.encoders.hexToByteArray import com.vitorpamplona.quartz.encoders.hexToByteArray
import com.vitorpamplona.quartz.encoders.toHexKey import com.vitorpamplona.quartz.encoders.toHexKey
import com.vitorpamplona.quartz.encoders.toNpub
import com.vitorpamplona.quartz.events.* import com.vitorpamplona.quartz.events.*
import kotlinx.collections.immutable.ImmutableSet import kotlinx.collections.immutable.ImmutableSet
import kotlinx.collections.immutable.persistentSetOf import kotlinx.collections.immutable.persistentSetOf
@@ -117,7 +118,8 @@ class Account(
AmberUtils.decryptBlockList( AmberUtils.decryptBlockList(
content, content,
keyPair.pubKey.toHexKey(), keyPair.pubKey.toHexKey(),
blockList.id() blockList.id(),
keyPair.pubKey.toNpub()
) )
blockList.decryptedContent = AmberUtils.cachedDecryptedContent[blockList.id] blockList.decryptedContent = AmberUtils.cachedDecryptedContent[blockList.id]
live.invalidateData() live.invalidateData()
@@ -220,7 +222,7 @@ class Account(
) )
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.openAmber(event) AmberUtils.openAmber(event, keyPair.pubKey.toNpub())
val content = AmberUtils.content[event.id] ?: "" val content = AmberUtils.content[event.id] ?: ""
if (content.isBlank()) { if (content.isBlank()) {
return return
@@ -242,7 +244,7 @@ class Account(
) )
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.openAmber(event) AmberUtils.openAmber(event, keyPair.pubKey.toNpub())
val content = AmberUtils.content[event.id] val content = AmberUtils.content[event.id]
if (content.isBlank()) { if (content.isBlank()) {
return return
@@ -314,7 +316,7 @@ class Account(
keyPair keyPair
) )
AmberUtils.openAmber(senderReaction) AmberUtils.openAmber(senderReaction, keyPair.pubKey.toNpub())
val reactionContent = AmberUtils.content[event.id] val reactionContent = AmberUtils.content[event.id]
if (reactionContent.isBlank()) return if (reactionContent.isBlank()) return
senderReaction = ReactionEvent.create(senderReaction, reactionContent) senderReaction = ReactionEvent.create(senderReaction, reactionContent)
@@ -322,7 +324,7 @@ class Account(
val giftWraps = users.plus(senderPublicKey).map { val giftWraps = users.plus(senderPublicKey).map {
val gossip = Gossip.create(senderReaction) val gossip = Gossip.create(senderReaction)
val content = Gossip.toJson(gossip) val content = Gossip.toJson(gossip)
AmberUtils.encrypt(content, it, gossip.id!!, SignerType.NIP44_ENCRYPT) AmberUtils.encrypt(content, it, gossip.id!!, keyPair.pubKey.toNpub(), SignerType.NIP44_ENCRYPT)
val encryptedContent = AmberUtils.content[gossip.id] val encryptedContent = AmberUtils.content[gossip.id]
if (encryptedContent.isBlank()) return if (encryptedContent.isBlank()) return
@@ -330,7 +332,7 @@ class Account(
encryptedContent = encryptedContent, encryptedContent = encryptedContent,
pubKey = senderPublicKey pubKey = senderPublicKey
) )
AmberUtils.openAmber(sealedEvent) AmberUtils.openAmber(sealedEvent, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[sealedEvent.id] ?: "" val eventContent = AmberUtils.content[sealedEvent.id] ?: ""
if (eventContent.isBlank()) return if (eventContent.isBlank()) return
sealedEvent = SealedGossipEvent.create(sealedEvent, eventContent) sealedEvent = SealedGossipEvent.create(sealedEvent, eventContent)
@@ -367,7 +369,7 @@ class Account(
keyPair keyPair
) )
AmberUtils.openAmber(senderReaction) AmberUtils.openAmber(senderReaction, keyPair.pubKey.toNpub())
val reactionContent = AmberUtils.content[senderReaction.id] ?: "" val reactionContent = AmberUtils.content[senderReaction.id] ?: ""
if (reactionContent.isBlank()) return if (reactionContent.isBlank()) return
senderReaction = ReactionEvent.create(senderReaction, reactionContent) senderReaction = ReactionEvent.create(senderReaction, reactionContent)
@@ -376,7 +378,7 @@ class Account(
newUsers.forEach { newUsers.forEach {
val gossip = Gossip.create(senderReaction) val gossip = Gossip.create(senderReaction)
val content = Gossip.toJson(gossip) val content = Gossip.toJson(gossip)
AmberUtils.encrypt(content, it, gossip.id!!, SignerType.NIP44_ENCRYPT) AmberUtils.encrypt(content, it, gossip.id!!, keyPair.pubKey.toNpub(), SignerType.NIP44_ENCRYPT)
val encryptedContent = AmberUtils.content[gossip.id] val encryptedContent = AmberUtils.content[gossip.id]
if (encryptedContent.isBlank()) return if (encryptedContent.isBlank()) return
@@ -384,7 +386,7 @@ class Account(
encryptedContent = encryptedContent, encryptedContent = encryptedContent,
pubKey = senderPublicKey pubKey = senderPublicKey
) )
AmberUtils.openAmber(sealedEvent) AmberUtils.openAmber(sealedEvent, keyPair.pubKey.toNpub())
val sealedContent = AmberUtils.content[sealedEvent.id] ?: "" val sealedContent = AmberUtils.content[sealedEvent.id] ?: ""
if (sealedContent.isBlank()) return if (sealedContent.isBlank()) return
sealedEvent = SealedGossipEvent.create(sealedEvent, sealedContent) sealedEvent = SealedGossipEvent.create(sealedEvent, sealedContent)
@@ -415,7 +417,7 @@ class Account(
note.event?.let { note.event?.let {
val event = ReactionEvent.create(emojiUrl, it, keyPair) val event = ReactionEvent.create(emojiUrl, it, keyPair)
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.signEvent(event) AmberUtils.signEvent(event, keyPair.pubKey.toNpub())
} else { } else {
Client.send(event) Client.send(event)
LocalCache.consume(event) LocalCache.consume(event)
@@ -429,7 +431,7 @@ class Account(
note.event?.let { note.event?.let {
val event = ReactionEvent.create(reaction, it, keyPair) val event = ReactionEvent.create(reaction, it, keyPair)
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.signEvent(event) AmberUtils.signEvent(event, keyPair.pubKey.toNpub())
} else { } else {
Client.send(event) Client.send(event)
LocalCache.consume(event) LocalCache.consume(event)
@@ -462,7 +464,7 @@ class Account(
pollOption, pollOption,
message message
) )
AmberUtils.openAmber(unsignedEvent) AmberUtils.openAmber(unsignedEvent, keyPair.pubKey.toNpub())
val content = AmberUtils.content[unsignedEvent.id] ?: "" val content = AmberUtils.content[unsignedEvent.id] ?: ""
if (content.isBlank()) return null if (content.isBlank()) return null
@@ -481,7 +483,7 @@ class Account(
pollOption, pollOption,
message message
) )
AmberUtils.openAmber(unsignedEvent) AmberUtils.openAmber(unsignedEvent, keyPair.pubKey.toNpub())
val content = AmberUtils.content[unsignedEvent.id] ?: "" val content = AmberUtils.content[unsignedEvent.id] ?: ""
if (content.isBlank()) return null if (content.isBlank()) return null
@@ -531,7 +533,7 @@ class Account(
if (privKey != null) return zapResponseEvent.response(privKey, pubKey) if (privKey != null) return zapResponseEvent.response(privKey, pubKey)
AmberUtils.decrypt(zapResponseEvent.content, pubKey.toHexKey(), zapResponseEvent.id) AmberUtils.decrypt(zapResponseEvent.content, pubKey.toHexKey(), zapResponseEvent.id, keyPair.pubKey.toNpub())
val decryptedContent = AmberUtils.content[zapResponseEvent.id] ?: "" val decryptedContent = AmberUtils.content[zapResponseEvent.id] ?: ""
if (decryptedContent.isBlank()) return null if (decryptedContent.isBlank()) return null
return zapResponseEvent.response(decryptedContent) return zapResponseEvent.response(decryptedContent)
@@ -604,7 +606,7 @@ class Account(
note.event?.let { note.event?.let {
var event = ReactionEvent.createWarning(it, keyPair) var event = ReactionEvent.createWarning(it, keyPair)
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.openAmber(event) AmberUtils.openAmber(event, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[event.id] ?: "" val eventContent = AmberUtils.content[event.id] ?: ""
if (eventContent.isBlank()) return if (eventContent.isBlank()) return
event = ReactionEvent( event = ReactionEvent(
@@ -623,7 +625,7 @@ class Account(
note.event?.let { note.event?.let {
var event = ReportEvent.create(it, type, keyPair, content = content) var event = ReportEvent.create(it, type, keyPair, content = content)
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.openAmber(event) AmberUtils.openAmber(event, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[event.id] ?: "" val eventContent = AmberUtils.content[event.id] ?: ""
if (eventContent.isBlank()) return if (eventContent.isBlank()) return
event = ReportEvent( event = ReportEvent(
@@ -650,7 +652,7 @@ class Account(
var event = ReportEvent.create(user.pubkeyHex, type, keyPair) var event = ReportEvent.create(user.pubkeyHex, type, keyPair)
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.openAmber(event) AmberUtils.openAmber(event, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[event.id] ?: "" val eventContent = AmberUtils.content[event.id] ?: ""
if (eventContent.isBlank()) return if (eventContent.isBlank()) return
event = ReportEvent( event = ReportEvent(
@@ -678,7 +680,7 @@ class Account(
if (myNotes.isNotEmpty()) { if (myNotes.isNotEmpty()) {
val event = DeletionEvent.create(myNotes, keyPair) val event = DeletionEvent.create(myNotes, keyPair)
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.signEvent(event) AmberUtils.signEvent(event, keyPair.pubKey.toNpub())
} else { } else {
Client.send(event) Client.send(event)
LocalCache.consume(event) LocalCache.consume(event)
@@ -691,7 +693,7 @@ class Account(
var event = HTTPAuthorizationEvent.create(url, method, body, keyPair) var event = HTTPAuthorizationEvent.create(url, method, body, keyPair)
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.openAmber(event) AmberUtils.openAmber(event, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[event.id] ?: "" val eventContent = AmberUtils.content[event.id] ?: ""
if (eventContent.isBlank()) { if (eventContent.isBlank()) {
return null return null
@@ -713,7 +715,7 @@ class Account(
if (it.kind() == 1) { if (it.kind() == 1) {
val event = RepostEvent.create(it, keyPair) val event = RepostEvent.create(it, keyPair)
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.signEvent(event) AmberUtils.signEvent(event, keyPair.pubKey.toNpub())
} else { } else {
Client.send(event) Client.send(event)
LocalCache.consume(event) LocalCache.consume(event)
@@ -721,7 +723,7 @@ class Account(
} else { } else {
val event = GenericRepostEvent.create(it, keyPair) val event = GenericRepostEvent.create(it, keyPair)
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.signEvent(event) AmberUtils.signEvent(event, keyPair.pubKey.toNpub())
} else { } else {
Client.send(event) Client.send(event)
LocalCache.consume(event) LocalCache.consume(event)
@@ -756,7 +758,7 @@ class Account(
it, it,
keyPair keyPair
) )
AmberUtils.openAmber(unsignedEvent) AmberUtils.openAmber(unsignedEvent, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[unsignedEvent.id] ?: "" val eventContent = AmberUtils.content[unsignedEvent.id] ?: ""
returningContactList = if (eventContent.isBlank()) { returningContactList = if (eventContent.isBlank()) {
latestContactList latestContactList
@@ -805,7 +807,7 @@ class Account(
} }
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.openAmber(event) AmberUtils.openAmber(event, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[event.id] ?: "" val eventContent = AmberUtils.content[event.id] ?: ""
if (eventContent.isBlank()) { if (eventContent.isBlank()) {
return return
@@ -837,7 +839,7 @@ class Account(
} }
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.openAmber(event) AmberUtils.openAmber(event, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[event.id] ?: "" val eventContent = AmberUtils.content[event.id] ?: ""
if (eventContent.isBlank()) { if (eventContent.isBlank()) {
return return
@@ -870,7 +872,7 @@ class Account(
} }
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.openAmber(event) AmberUtils.openAmber(event, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[event.id] ?: "" val eventContent = AmberUtils.content[event.id] ?: ""
if (eventContent.isBlank()) { if (eventContent.isBlank()) {
return return
@@ -906,7 +908,7 @@ class Account(
} }
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.openAmber(event) AmberUtils.openAmber(event, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[event.id] ?: "" val eventContent = AmberUtils.content[event.id] ?: ""
if (eventContent.isBlank()) { if (eventContent.isBlank()) {
return return
@@ -942,7 +944,7 @@ class Account(
} }
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.openAmber(event) AmberUtils.openAmber(event, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[event.id] ?: "" val eventContent = AmberUtils.content[event.id] ?: ""
if (eventContent.isBlank()) { if (eventContent.isBlank()) {
return return
@@ -967,7 +969,7 @@ class Account(
) )
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.openAmber(event) AmberUtils.openAmber(event, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[event.id] ?: "" val eventContent = AmberUtils.content[event.id] ?: ""
if (eventContent.isBlank()) { if (eventContent.isBlank()) {
return return
@@ -993,7 +995,7 @@ class Account(
) )
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.openAmber(event) AmberUtils.openAmber(event, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[event.id] ?: "" val eventContent = AmberUtils.content[event.id] ?: ""
if (eventContent.isBlank()) { if (eventContent.isBlank()) {
return return
@@ -1019,7 +1021,7 @@ class Account(
) )
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.openAmber(event) AmberUtils.openAmber(event, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[event.id] ?: "" val eventContent = AmberUtils.content[event.id] ?: ""
if (eventContent.isBlank()) { if (eventContent.isBlank()) {
return return
@@ -1045,7 +1047,7 @@ class Account(
) )
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.openAmber(event) AmberUtils.openAmber(event, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[event.id] ?: "" val eventContent = AmberUtils.content[event.id] ?: ""
if (eventContent.isBlank()) { if (eventContent.isBlank()) {
return return
@@ -1071,7 +1073,7 @@ class Account(
) )
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.openAmber(event) AmberUtils.openAmber(event, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[event.id] ?: "" val eventContent = AmberUtils.content[event.id] ?: ""
if (eventContent.isBlank()) { if (eventContent.isBlank()) {
return return
@@ -1094,7 +1096,7 @@ class Account(
pubKey = keyPair.pubKey.toHexKey() pubKey = keyPair.pubKey.toHexKey()
) )
AmberUtils.openAmber(unsignedData) AmberUtils.openAmber(unsignedData, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[unsignedData.id] ?: "" val eventContent = AmberUtils.content[unsignedData.id] ?: ""
if (eventContent.isBlank()) return null if (eventContent.isBlank()) return null
val data = FileStorageEvent( val data = FileStorageEvent(
@@ -1118,7 +1120,7 @@ class Account(
pubKey = keyPair.pubKey.toHexKey() pubKey = keyPair.pubKey.toHexKey()
) )
AmberUtils.openAmber(unsignedEvent) AmberUtils.openAmber(unsignedEvent, keyPair.pubKey.toNpub())
val unsignedEventContent = AmberUtils.content[unsignedEvent.id] ?: "" val unsignedEventContent = AmberUtils.content[unsignedEvent.id] ?: ""
if (unsignedEventContent.isBlank()) return null if (unsignedEventContent.isBlank()) return null
val signedEvent = FileStorageHeaderEvent( val signedEvent = FileStorageHeaderEvent(
@@ -1188,7 +1190,7 @@ class Account(
sensitiveContent = headerInfo.sensitiveContent, sensitiveContent = headerInfo.sensitiveContent,
keyPair = keyPair keyPair = keyPair
) )
AmberUtils.openAmber(unsignedEvent) AmberUtils.openAmber(unsignedEvent, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[unsignedEvent.id] ?: "" val eventContent = AmberUtils.content[unsignedEvent.id] ?: ""
if (eventContent.isBlank()) return null if (eventContent.isBlank()) return null
val signedEvent = FileHeaderEvent( val signedEvent = FileHeaderEvent(
@@ -1255,7 +1257,7 @@ class Account(
) )
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.openAmber(signedEvent) AmberUtils.openAmber(signedEvent, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[signedEvent.id] ?: "" val eventContent = AmberUtils.content[signedEvent.id] ?: ""
if (eventContent.isBlank()) { if (eventContent.isBlank()) {
return return
@@ -1325,7 +1327,7 @@ class Account(
// println("Sending new PollNoteEvent: %s".format(signedEvent.toJson())) // println("Sending new PollNoteEvent: %s".format(signedEvent.toJson()))
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.openAmber(signedEvent) AmberUtils.openAmber(signedEvent, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[signedEvent.id] ?: "" val eventContent = AmberUtils.content[signedEvent.id] ?: ""
if (eventContent.isBlank()) { if (eventContent.isBlank()) {
return return
@@ -1377,7 +1379,7 @@ class Account(
) )
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.openAmber(signedEvent) AmberUtils.openAmber(signedEvent, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[signedEvent.id] ?: "" val eventContent = AmberUtils.content[signedEvent.id] ?: ""
if (eventContent.isBlank()) { if (eventContent.isBlank()) {
return return
@@ -1418,7 +1420,7 @@ class Account(
) )
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.openAmber(signedEvent) AmberUtils.openAmber(signedEvent, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[signedEvent.id] ?: "" val eventContent = AmberUtils.content[signedEvent.id] ?: ""
if (eventContent.isBlank()) { if (eventContent.isBlank()) {
return return
@@ -1451,7 +1453,7 @@ class Account(
var localMessage = message var localMessage = message
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.encrypt(localMessage, toUser, "encrypt") AmberUtils.encrypt(localMessage, toUser, "encrypt", keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content["encrypt"] ?: "" val eventContent = AmberUtils.content["encrypt"] ?: ""
if (eventContent.isBlank()) return if (eventContent.isBlank()) return
localMessage = eventContent localMessage = eventContent
@@ -1473,7 +1475,7 @@ class Account(
) )
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.openAmber(signedEvent) AmberUtils.openAmber(signedEvent, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[signedEvent.id] ?: "" val eventContent = AmberUtils.content[signedEvent.id] ?: ""
if (eventContent.isBlank()) { if (eventContent.isBlank()) {
return return
@@ -1515,7 +1517,7 @@ class Account(
geohash = geohash geohash = geohash
) )
AmberUtils.openAmber(chatMessageEvent) AmberUtils.openAmber(chatMessageEvent, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[chatMessageEvent.id] ?: "" val eventContent = AmberUtils.content[chatMessageEvent.id] ?: ""
if (eventContent.isBlank()) return if (eventContent.isBlank()) return
chatMessageEvent = ChatMessageEvent.create(chatMessageEvent, eventContent) chatMessageEvent = ChatMessageEvent.create(chatMessageEvent, eventContent)
@@ -1523,14 +1525,14 @@ class Account(
toUsers.plus(senderPublicKey).toSet().forEach { toUsers.plus(senderPublicKey).toSet().forEach {
val gossip = Gossip.create(chatMessageEvent) val gossip = Gossip.create(chatMessageEvent)
val content = Gossip.toJson(gossip) val content = Gossip.toJson(gossip)
AmberUtils.encrypt(content, it, gossip.id!!, SignerType.NIP44_ENCRYPT) AmberUtils.encrypt(content, it, gossip.id!!, keyPair.pubKey.toNpub(), SignerType.NIP44_ENCRYPT)
val gossipContent = AmberUtils.content[gossip.id] ?: "" val gossipContent = AmberUtils.content[gossip.id] ?: ""
if (gossipContent.isNotBlank()) { if (gossipContent.isNotBlank()) {
var sealedEvent = SealedGossipEvent.create( var sealedEvent = SealedGossipEvent.create(
encryptedContent = gossipContent, encryptedContent = gossipContent,
pubKey = senderPublicKey pubKey = senderPublicKey
) )
AmberUtils.openAmber(sealedEvent) AmberUtils.openAmber(sealedEvent, keyPair.pubKey.toNpub())
val sealedEventContent = AmberUtils.content[sealedEvent.id] ?: "" val sealedEventContent = AmberUtils.content[sealedEvent.id] ?: ""
if (sealedEventContent.isBlank()) return if (sealedEventContent.isBlank()) return
sealedEvent = SealedGossipEvent.create(sealedEvent, sealedEventContent) sealedEvent = SealedGossipEvent.create(sealedEvent, sealedEventContent)
@@ -1567,12 +1569,12 @@ class Account(
// Only keep in cache the GiftWrap for the account. // Only keep in cache the GiftWrap for the account.
if (it.recipientPubKey() == keyPair.pubKey.toHexKey()) { if (it.recipientPubKey() == keyPair.pubKey.toHexKey()) {
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.decrypt(it.content, it.pubKey, it.id, SignerType.NIP44_DECRYPT) AmberUtils.decrypt(it.content, it.pubKey, it.id, keyPair.pubKey.toNpub(), SignerType.NIP44_DECRYPT)
val decryptedContent = AmberUtils.cachedDecryptedContent[it.id] ?: "" val decryptedContent = AmberUtils.cachedDecryptedContent[it.id] ?: ""
if (decryptedContent.isEmpty()) return if (decryptedContent.isEmpty()) return
it.cachedGift(keyPair.pubKey, decryptedContent)?.let { cached -> it.cachedGift(keyPair.pubKey, decryptedContent)?.let { cached ->
if (cached is SealedGossipEvent) { if (cached is SealedGossipEvent) {
AmberUtils.decrypt(cached.content, cached.pubKey, cached.id, SignerType.NIP44_DECRYPT) AmberUtils.decrypt(cached.content, cached.pubKey, cached.id, keyPair.pubKey.toNpub(), SignerType.NIP44_DECRYPT)
val localDecryptedContent = AmberUtils.cachedDecryptedContent[cached.id] ?: "" val localDecryptedContent = AmberUtils.cachedDecryptedContent[cached.id] ?: ""
if (localDecryptedContent.isEmpty()) return if (localDecryptedContent.isEmpty()) return
cached.cachedGossip(keyPair.pubKey, localDecryptedContent)?.let { gossip -> cached.cachedGossip(keyPair.pubKey, localDecryptedContent)?.let { gossip ->
@@ -1614,7 +1616,7 @@ class Account(
) )
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.openAmber(event) AmberUtils.openAmber(event, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[event.id] ?: "" val eventContent = AmberUtils.content[event.id] ?: ""
if (eventContent.isBlank()) { if (eventContent.isBlank()) {
return return
@@ -1636,7 +1638,7 @@ class Account(
var event = StatusEvent.update(oldEvent, newStatus, keyPair) var event = StatusEvent.update(oldEvent, newStatus, keyPair)
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.openAmber(event) AmberUtils.openAmber(event, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[event.id] ?: "" val eventContent = AmberUtils.content[event.id] ?: ""
if (eventContent.isBlank()) { if (eventContent.isBlank()) {
return return
@@ -1652,7 +1654,7 @@ class Account(
var event = StatusEvent.create(newStatus, "general", expiration = null, keyPair) var event = StatusEvent.create(newStatus, "general", expiration = null, keyPair)
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.openAmber(event) AmberUtils.openAmber(event, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[event.id] ?: "" val eventContent = AmberUtils.content[event.id] ?: ""
if (eventContent.isBlank()) { if (eventContent.isBlank()) {
return return
@@ -1669,7 +1671,7 @@ class Account(
var event = StatusEvent.clear(oldEvent, keyPair) var event = StatusEvent.clear(oldEvent, keyPair)
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.openAmber(event) AmberUtils.openAmber(event, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[event.id] ?: "" val eventContent = AmberUtils.content[event.id] ?: ""
if (eventContent.isBlank()) { if (eventContent.isBlank()) {
return return
@@ -1681,7 +1683,7 @@ class Account(
var event2 = DeletionEvent.create(listOf(event.id), keyPair) var event2 = DeletionEvent.create(listOf(event.id), keyPair)
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.openAmber(event2) AmberUtils.openAmber(event2, keyPair.pubKey.toNpub())
val event2Content = AmberUtils.content[event2.id] ?: "" val event2Content = AmberUtils.content[event2.id] ?: ""
if (event2Content.isBlank()) { if (event2Content.isBlank()) {
return return
@@ -1706,7 +1708,7 @@ class Account(
) )
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.openAmber(event) AmberUtils.openAmber(event, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[event.id] ?: "" val eventContent = AmberUtils.content[event.id] ?: ""
if (eventContent.isBlank()) { if (eventContent.isBlank()) {
return return
@@ -1743,7 +1745,7 @@ class Account(
} }
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.openAmber(event) AmberUtils.openAmber(event, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[event.id] ?: "" val eventContent = AmberUtils.content[event.id] ?: ""
if (eventContent.isBlank()) { if (eventContent.isBlank()) {
return return
@@ -1782,7 +1784,7 @@ class Account(
} }
val msg = Event.mapper.writeValueAsString(privTags) val msg = Event.mapper.writeValueAsString(privTags)
AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey(), "encrypt") AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey(), "encrypt", keyPair.pubKey.toNpub())
val encryptedContent = AmberUtils.content["encrypt"] ?: "" val encryptedContent = AmberUtils.content["encrypt"] ?: ""
AmberUtils.content.remove("encrypt") AmberUtils.content.remove("encrypt")
if (encryptedContent.isBlank()) { if (encryptedContent.isBlank()) {
@@ -1800,7 +1802,7 @@ class Account(
keyPair.pubKey.toHexKey() keyPair.pubKey.toHexKey()
) )
AmberUtils.openAmber(event) AmberUtils.openAmber(event, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[event.id] ?: "" val eventContent = AmberUtils.content[event.id] ?: ""
if (eventContent.isBlank()) { if (eventContent.isBlank()) {
return return
@@ -1838,7 +1840,7 @@ class Account(
} }
val msg = Event.mapper.writeValueAsString(privTags) val msg = Event.mapper.writeValueAsString(privTags)
AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey(), "encrypt") AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey(), "encrypt", keyPair.pubKey.toNpub())
val encryptedContent = AmberUtils.content["encrypt"] ?: "" val encryptedContent = AmberUtils.content["encrypt"] ?: ""
AmberUtils.content.remove("encrypt") AmberUtils.content.remove("encrypt")
if (encryptedContent.isBlank()) { if (encryptedContent.isBlank()) {
@@ -1856,7 +1858,7 @@ class Account(
keyPair.pubKey.toHexKey() keyPair.pubKey.toHexKey()
) )
AmberUtils.openAmber(event) AmberUtils.openAmber(event, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[event.id] ?: "" val eventContent = AmberUtils.content[event.id] ?: ""
if (eventContent.isBlank()) { if (eventContent.isBlank()) {
return return
@@ -1924,7 +1926,7 @@ class Account(
} }
val msg = Event.mapper.writeValueAsString(privTags) val msg = Event.mapper.writeValueAsString(privTags)
AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey(), "encrypt") AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey(), "encrypt", keyPair.pubKey.toNpub())
val encryptedContent = AmberUtils.content["encrypt"] ?: "" val encryptedContent = AmberUtils.content["encrypt"] ?: ""
AmberUtils.content.remove("encrypt") AmberUtils.content.remove("encrypt")
if (encryptedContent.isBlank()) { if (encryptedContent.isBlank()) {
@@ -1950,7 +1952,7 @@ class Account(
keyPair.pubKey.toHexKey() keyPair.pubKey.toHexKey()
) )
} }
AmberUtils.openAmber(event) AmberUtils.openAmber(event, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[event.id] ?: "" val eventContent = AmberUtils.content[event.id] ?: ""
if (eventContent.isBlank()) { if (eventContent.isBlank()) {
return return
@@ -2040,7 +2042,7 @@ class Account(
var event = RelayAuthEvent.create(relay.url, challenge, keyPair.pubKey.toHexKey(), keyPair.privKey) var event = RelayAuthEvent.create(relay.url, challenge, keyPair.pubKey.toHexKey(), keyPair.privKey)
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.openAmber(event) AmberUtils.openAmber(event, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[event.id] ?: "" val eventContent = AmberUtils.content[event.id] ?: ""
if (eventContent.isBlank()) { if (eventContent.isBlank()) {
return null return null
@@ -2108,7 +2110,7 @@ class Account(
} }
val msg = Event.mapper.writeValueAsString(privTags) val msg = Event.mapper.writeValueAsString(privTags)
AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey(), "encrypt") AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey(), "encrypt", keyPair.pubKey.toNpub())
val encryptedContent = AmberUtils.content["encrypt"] ?: "" val encryptedContent = AmberUtils.content["encrypt"] ?: ""
AmberUtils.content.remove("encrypt") AmberUtils.content.remove("encrypt")
if (encryptedContent.isBlank()) { if (encryptedContent.isBlank()) {
@@ -2135,7 +2137,7 @@ class Account(
) )
} }
AmberUtils.openAmber(event) AmberUtils.openAmber(event, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[event.id] ?: "" val eventContent = AmberUtils.content[event.id] ?: ""
if (eventContent.isBlank()) { if (eventContent.isBlank()) {
return return
@@ -2213,7 +2215,7 @@ class Account(
val privateTags = listOf(listOf("p", pubkeyHex)) val privateTags = listOf(listOf("p", pubkeyHex))
val msg = Event.mapper.writeValueAsString(privateTags) val msg = Event.mapper.writeValueAsString(privateTags)
AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey(), "encrypt") AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey(), "encrypt", keyPair.pubKey.toNpub())
val encryptedContent = AmberUtils.content["encrypted"] ?: "" val encryptedContent = AmberUtils.content["encrypted"] ?: ""
AmberUtils.content.remove("encrypted") AmberUtils.content.remove("encrypted")
if (encryptedContent.isBlank()) return if (encryptedContent.isBlank()) return
@@ -2221,7 +2223,7 @@ class Account(
} else { } else {
var decryptedContent = AmberUtils.cachedDecryptedContent[id] var decryptedContent = AmberUtils.cachedDecryptedContent[id]
if (decryptedContent == null) { if (decryptedContent == null) {
AmberUtils.decrypt(blockList.content, keyPair.pubKey.toHexKey(), id) AmberUtils.decrypt(blockList.content, keyPair.pubKey.toHexKey(), id, keyPair.pubKey.toNpub())
val content = AmberUtils.content[id] ?: "" val content = AmberUtils.content[id] ?: ""
if (content.isBlank()) return if (content.isBlank()) return
decryptedContent = content decryptedContent = content
@@ -2229,7 +2231,7 @@ class Account(
val privateTags = blockList.privateTagsOrEmpty(decryptedContent).plus(element = listOf("p", pubkeyHex)) val privateTags = blockList.privateTagsOrEmpty(decryptedContent).plus(element = listOf("p", pubkeyHex))
val msg = Event.mapper.writeValueAsString(privateTags) val msg = Event.mapper.writeValueAsString(privateTags)
AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey(), id) AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey(), id, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[id] ?: "" val eventContent = AmberUtils.content[id] ?: ""
if (eventContent.isBlank()) return if (eventContent.isBlank()) return
eventContent eventContent
@@ -2253,7 +2255,7 @@ class Account(
) )
} }
AmberUtils.openAmber(event) AmberUtils.openAmber(event, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[event.id] ?: "" val eventContent = AmberUtils.content[event.id] ?: ""
if (eventContent.isBlank()) return if (eventContent.isBlank()) return
event = PeopleListEvent( event = PeopleListEvent(
@@ -2302,21 +2304,21 @@ class Account(
val privateTags = listOf(listOf("p", pubkeyHex)) val privateTags = listOf(listOf("p", pubkeyHex))
val msg = Event.mapper.writeValueAsString(privateTags) val msg = Event.mapper.writeValueAsString(privateTags)
AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey(), blockList.id) AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey(), blockList.id, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[blockList.id] ?: "" val eventContent = AmberUtils.content[blockList.id] ?: ""
if (eventContent.isBlank()) return if (eventContent.isBlank()) return
eventContent eventContent
} else { } else {
var decryptedContent = AmberUtils.cachedDecryptedContent[blockList.id] var decryptedContent = AmberUtils.cachedDecryptedContent[blockList.id]
if (decryptedContent == null) { if (decryptedContent == null) {
AmberUtils.decrypt(blockList.content, keyPair.pubKey.toHexKey(), blockList.id) AmberUtils.decrypt(blockList.content, keyPair.pubKey.toHexKey(), blockList.id, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[blockList.id] ?: "" val eventContent = AmberUtils.content[blockList.id] ?: ""
if (eventContent.isBlank()) return if (eventContent.isBlank()) return
decryptedContent = eventContent decryptedContent = eventContent
} }
val privateTags = blockList.privateTagsOrEmpty(decryptedContent).minus(element = listOf("p", pubkeyHex)) val privateTags = blockList.privateTagsOrEmpty(decryptedContent).minus(element = listOf("p", pubkeyHex))
val msg = Event.mapper.writeValueAsString(privateTags) val msg = Event.mapper.writeValueAsString(privateTags)
AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey(), blockList.id) AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey(), blockList.id, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[blockList.id] ?: "" val eventContent = AmberUtils.content[blockList.id] ?: ""
if (eventContent.isBlank()) return if (eventContent.isBlank()) return
eventContent eventContent
@@ -2330,7 +2332,7 @@ class Account(
encryptedContent encryptedContent
) )
AmberUtils.openAmber(event) AmberUtils.openAmber(event, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[event.id] ?: "" val eventContent = AmberUtils.content[event.id] ?: ""
if (eventContent.isBlank()) return if (eventContent.isBlank()) return
event = PeopleListEvent.create(event, eventContent) event = PeopleListEvent.create(event, eventContent)
@@ -2545,7 +2547,7 @@ class Account(
keyPair = keyPair keyPair = keyPair
) )
if (loginWithAmber) { if (loginWithAmber) {
AmberUtils.openAmber(event) AmberUtils.openAmber(event, keyPair.pubKey.toNpub())
val eventContent = AmberUtils.content[event.id] ?: "" val eventContent = AmberUtils.content[event.id] ?: ""
if (eventContent.isBlank()) return if (eventContent.isBlank()) return
event = ChannelMetadataEvent.create(event, eventContent) event = ChannelMetadataEvent.create(event, eventContent)
@@ -2563,7 +2565,7 @@ class Account(
if (loginWithAmber) { if (loginWithAmber) {
var decryptedContent = AmberUtils.cachedDecryptedContent[event.id] var decryptedContent = AmberUtils.cachedDecryptedContent[event.id]
if (decryptedContent == null) { if (decryptedContent == null) {
AmberUtils.decrypt(event.content, event.pubKey, event.id, SignerType.NIP44_DECRYPT) AmberUtils.decrypt(event.content, event.pubKey, event.id, keyPair.pubKey.toNpub(), SignerType.NIP44_DECRYPT)
} }
decryptedContent = AmberUtils.cachedDecryptedContent[event.id] ?: "" decryptedContent = AmberUtils.cachedDecryptedContent[event.id] ?: ""
if (decryptedContent.isEmpty()) return null if (decryptedContent.isEmpty()) return null
@@ -2579,7 +2581,7 @@ class Account(
if (loginWithAmber) { if (loginWithAmber) {
var decryptedContent = AmberUtils.cachedDecryptedContent[event.id] var decryptedContent = AmberUtils.cachedDecryptedContent[event.id]
if (decryptedContent == null) { if (decryptedContent == null) {
AmberUtils.decrypt(event.content, event.pubKey, event.id, SignerType.NIP44_DECRYPT) AmberUtils.decrypt(event.content, event.pubKey, event.id, keyPair.pubKey.toNpub(), SignerType.NIP44_DECRYPT)
} }
decryptedContent = AmberUtils.cachedDecryptedContent[event.id] ?: "" decryptedContent = AmberUtils.cachedDecryptedContent[event.id] ?: ""
if (decryptedContent.isEmpty()) return null if (decryptedContent.isEmpty()) return null
@@ -2609,7 +2611,8 @@ class Account(
AmberUtils.decryptDM( AmberUtils.decryptDM(
event.content, event.content,
event.talkingWith(userProfile().pubkeyHex), event.talkingWith(userProfile().pubkeyHex),
event.id event.id,
keyPair.pubKey.toNpub()
) )
AmberUtils.cachedDecryptedContent[event.id] AmberUtils.cachedDecryptedContent[event.id]
} else { } else {
@@ -2638,7 +2641,7 @@ class Account(
null null
} }
} }
AmberUtils.decryptZapEvent(event) AmberUtils.decryptZapEvent(event, keyPair.pubKey.toNpub())
return null return null
} }
@@ -13,7 +13,6 @@ import com.vitorpamplona.amethyst.model.Account
import com.vitorpamplona.amethyst.model.LocalCache import com.vitorpamplona.amethyst.model.LocalCache
import com.vitorpamplona.amethyst.service.relays.Client import com.vitorpamplona.amethyst.service.relays.Client
import com.vitorpamplona.amethyst.ui.MainActivity import com.vitorpamplona.amethyst.ui.MainActivity
import com.vitorpamplona.amethyst.ui.actions.SignerType
import com.vitorpamplona.quartz.encoders.HexKey import com.vitorpamplona.quartz.encoders.HexKey
import com.vitorpamplona.quartz.encoders.toHexKey import com.vitorpamplona.quartz.encoders.toHexKey
import com.vitorpamplona.quartz.events.Event import com.vitorpamplona.quartz.events.Event
@@ -24,6 +23,16 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
enum class SignerType {
SIGN_EVENT,
NIP04_ENCRYPT,
NIP04_DECRYPT,
NIP44_ENCRYPT,
NIP44_DECRYPT,
GET_PUBLIC_KEY,
DECRYPT_ZAP_EVENT
}
object AmberUtils { object AmberUtils {
val content = LruCache<String, String>(10) val content = LruCache<String, String>(10)
var isActivityRunning: Boolean = false var isActivityRunning: Boolean = false
@@ -128,7 +137,8 @@ object AmberUtils {
type: SignerType, type: SignerType,
intentResult: ActivityResultLauncher<Intent>, intentResult: ActivityResultLauncher<Intent>,
pubKey: HexKey, pubKey: HexKey,
id: String id: String,
currentUserNpub: HexKey
) { ) {
ServiceManager.shouldPauseService = false ServiceManager.shouldPauseService = false
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("nostrsigner:$data")) val intent = Intent(Intent.ACTION_VIEW, Uri.parse("nostrsigner:$data"))
@@ -144,14 +154,15 @@ object AmberUtils {
intent.putExtra("type", signerType) intent.putExtra("type", signerType)
intent.putExtra("pubKey", pubKey) intent.putExtra("pubKey", pubKey)
intent.putExtra("id", id) intent.putExtra("id", id)
intent.`package` = "com.greenart7c3.nostrsigner" intent.putExtra("current_user", currentUserNpub)
intent.`package` = "com.greenart7c3.nostrsigner.debug"
intentResult.launch(intent) intentResult.launch(intent)
} }
fun openAmber(event: EventInterface) { fun openAmber(event: EventInterface, currentUserNpub: HexKey) {
checkNotInMainThread() checkNotInMainThread()
val result = getDataFromResolver(SignerType.SIGN_EVENT, arrayOf(event.toJson(), event.pubKey())) val result = getDataFromResolver(SignerType.SIGN_EVENT, arrayOf(event.toJson(), event.pubKey()), currentUserNpub)
if (result !== null) { if (result !== null) {
content.put(event.id(), result) content.put(event.id(), result)
return return
@@ -164,14 +175,15 @@ object AmberUtils {
SignerType.SIGN_EVENT, SignerType.SIGN_EVENT,
activityResultLauncher, activityResultLauncher,
"", "",
event.id() event.id(),
currentUserNpub
) )
while (isActivityRunning) { while (isActivityRunning) {
Thread.sleep(100) Thread.sleep(100)
} }
} }
fun signEvent(event: EventInterface) { fun signEvent(event: EventInterface, currentUserNpub: HexKey) {
checkNotInMainThread() checkNotInMainThread()
ServiceManager.shouldPauseService = false ServiceManager.shouldPauseService = false
isActivityRunning = true isActivityRunning = true
@@ -180,12 +192,13 @@ object AmberUtils {
SignerType.SIGN_EVENT, SignerType.SIGN_EVENT,
signEventResultLauncher, signEventResultLauncher,
account.keyPair.pubKey.toHexKey(), account.keyPair.pubKey.toHexKey(),
event.id() event.id(),
currentUserNpub
) )
} }
fun decryptBlockList(encryptedContent: String, pubKey: HexKey, id: String, signerType: SignerType = SignerType.NIP04_DECRYPT) { fun decryptBlockList(encryptedContent: String, pubKey: HexKey, id: String, currentUserNpub: HexKey, signerType: SignerType = SignerType.NIP04_DECRYPT) {
val result = getDataFromResolver(signerType, arrayOf(encryptedContent, pubKey)) val result = getDataFromResolver(signerType, arrayOf(encryptedContent, pubKey), currentUserNpub)
if (result !== null) { if (result !== null) {
content.put(id, result) content.put(id, result)
cachedDecryptedContent[id] = result cachedDecryptedContent[id] = result
@@ -197,14 +210,16 @@ object AmberUtils {
signerType, signerType,
blockListResultLauncher, blockListResultLauncher,
pubKey, pubKey,
id id,
currentUserNpub
) )
} }
fun getDataFromResolver(signerType: SignerType, data: Array<out String>, columnName: String = "signature"): String? { fun getDataFromResolver(signerType: SignerType, data: Array<out String>, currentUserNpub: HexKey, columnName: String = "signature"): String? {
val localData = data.toList().plus(currentUserNpub).toTypedArray()
Amethyst.instance.contentResolver.query( Amethyst.instance.contentResolver.query(
Uri.parse("content://com.greenart7c3.nostrsigner.$signerType"), Uri.parse("content://com.greenart7c3.nostrsigner.$signerType"),
data, localData,
null, null,
null, null,
null null
@@ -219,8 +234,8 @@ object AmberUtils {
return null return null
} }
fun decrypt(encryptedContent: String, pubKey: HexKey, id: String, signerType: SignerType = SignerType.NIP04_DECRYPT) { fun decrypt(encryptedContent: String, pubKey: HexKey, id: String, currentUserNpub: HexKey, signerType: SignerType = SignerType.NIP04_DECRYPT) {
val result = getDataFromResolver(signerType, arrayOf(encryptedContent, pubKey)) val result = getDataFromResolver(signerType, arrayOf(encryptedContent, pubKey), currentUserNpub)
if (result !== null) { if (result !== null) {
content.put(id, result) content.put(id, result)
cachedDecryptedContent[id] = result cachedDecryptedContent[id] = result
@@ -233,15 +248,16 @@ object AmberUtils {
signerType, signerType,
decryptResultLauncher, decryptResultLauncher,
pubKey, pubKey,
id id,
currentUserNpub
) )
while (isActivityRunning) { while (isActivityRunning) {
// do nothing // do nothing
} }
} }
fun decryptDM(encryptedContent: String, pubKey: HexKey, id: String, signerType: SignerType = SignerType.NIP04_DECRYPT) { fun decryptDM(encryptedContent: String, pubKey: HexKey, id: String, currentUserNpub: HexKey, signerType: SignerType = SignerType.NIP04_DECRYPT) {
val result = getDataFromResolver(signerType, arrayOf(encryptedContent, pubKey)) val result = getDataFromResolver(signerType, arrayOf(encryptedContent, pubKey), currentUserNpub)
if (result !== null) { if (result !== null) {
content.put(id, result) content.put(id, result)
cachedDecryptedContent[id] = result cachedDecryptedContent[id] = result
@@ -252,12 +268,13 @@ object AmberUtils {
signerType, signerType,
decryptResultLauncher, decryptResultLauncher,
pubKey, pubKey,
id id,
currentUserNpub
) )
} }
fun decryptBookmark(encryptedContent: String, pubKey: HexKey, id: String, signerType: SignerType = SignerType.NIP04_DECRYPT) { fun decryptBookmark(encryptedContent: String, pubKey: HexKey, id: String, currentUserNpub: HexKey, signerType: SignerType = SignerType.NIP04_DECRYPT) {
val result = getDataFromResolver(signerType, arrayOf(encryptedContent, pubKey)) val result = getDataFromResolver(signerType, arrayOf(encryptedContent, pubKey), currentUserNpub)
if (result !== null) { if (result !== null) {
content.put(id, result) content.put(id, result)
cachedDecryptedContent[id] = result cachedDecryptedContent[id] = result
@@ -268,12 +285,13 @@ object AmberUtils {
signerType, signerType,
decryptResultLauncher, decryptResultLauncher,
pubKey, pubKey,
id id,
currentUserNpub
) )
} }
fun encrypt(decryptedContent: String, pubKey: HexKey, id: String, signerType: SignerType = SignerType.NIP04_ENCRYPT) { fun encrypt(decryptedContent: String, pubKey: HexKey, id: String, currentUserNpub: HexKey, signerType: SignerType = SignerType.NIP04_ENCRYPT) {
val result = getDataFromResolver(signerType, arrayOf(decryptedContent, pubKey)) val result = getDataFromResolver(signerType, arrayOf(decryptedContent, pubKey), currentUserNpub)
if (result !== null) { if (result !== null) {
content.put(id, result) content.put(id, result)
return return
@@ -285,15 +303,16 @@ object AmberUtils {
signerType, signerType,
activityResultLauncher, activityResultLauncher,
pubKey, pubKey,
id id,
currentUserNpub
) )
while (isActivityRunning) { while (isActivityRunning) {
Thread.sleep(100) Thread.sleep(100)
} }
} }
fun decryptZapEvent(event: LnZapRequestEvent) { fun decryptZapEvent(event: LnZapRequestEvent, currentUserNpub: HexKey) {
val result = getDataFromResolver(SignerType.DECRYPT_ZAP_EVENT, arrayOf(event.toJson())) val result = getDataFromResolver(SignerType.DECRYPT_ZAP_EVENT, arrayOf(event.toJson()), currentUserNpub)
if (result !== null) { if (result !== null) {
content.put(event.id, result) content.put(event.id, result)
cachedDecryptedContent[event.id] = result cachedDecryptedContent[event.id] = result
@@ -304,7 +323,8 @@ object AmberUtils {
SignerType.DECRYPT_ZAP_EVENT, SignerType.DECRYPT_ZAP_EVENT,
decryptResultLauncher, decryptResultLauncher,
event.pubKey, event.pubKey,
event.id event.id,
currentUserNpub
) )
} }
} }
@@ -8,8 +8,8 @@ import com.vitorpamplona.amethyst.service.relays.EOSEAccount
import com.vitorpamplona.amethyst.service.relays.JsonFilter import com.vitorpamplona.amethyst.service.relays.JsonFilter
import com.vitorpamplona.amethyst.service.relays.Relay import com.vitorpamplona.amethyst.service.relays.Relay
import com.vitorpamplona.amethyst.service.relays.TypedFilter import com.vitorpamplona.amethyst.service.relays.TypedFilter
import com.vitorpamplona.amethyst.ui.actions.SignerType
import com.vitorpamplona.quartz.encoders.toHexKey import com.vitorpamplona.quartz.encoders.toHexKey
import com.vitorpamplona.quartz.encoders.toNpub
import com.vitorpamplona.quartz.events.AdvertisedRelayListEvent import com.vitorpamplona.quartz.events.AdvertisedRelayListEvent
import com.vitorpamplona.quartz.events.BadgeAwardEvent import com.vitorpamplona.quartz.events.BadgeAwardEvent
import com.vitorpamplona.quartz.events.BadgeProfilesEvent import com.vitorpamplona.quartz.events.BadgeProfilesEvent
@@ -162,6 +162,7 @@ object NostrAccountDataSource : NostrDataSource("AccountData") {
event.content, event.content,
event.pubKey, event.pubKey,
event.id, event.id,
account.keyPair.pubKey.toNpub(),
SignerType.NIP44_DECRYPT SignerType.NIP44_DECRYPT
) )
cached = AmberUtils.cachedDecryptedContent[event.id] ?: "" cached = AmberUtils.cachedDecryptedContent[event.id] ?: ""
@@ -185,6 +186,7 @@ object NostrAccountDataSource : NostrDataSource("AccountData") {
event.content, event.content,
event.pubKey, event.pubKey,
event.id, event.id,
account.keyPair.pubKey.toNpub(),
SignerType.NIP44_DECRYPT SignerType.NIP44_DECRYPT
) )
cached = AmberUtils.cachedDecryptedContent[event.id] ?: "" cached = AmberUtils.cachedDecryptedContent[event.id] ?: ""
@@ -222,7 +224,7 @@ object NostrAccountDataSource : NostrDataSource("AccountData") {
if (this::account.isInitialized) { if (this::account.isInitialized) {
if (account.loginWithAmber) { if (account.loginWithAmber) {
val event = RelayAuthEvent.create(relay.url, challenge, account.keyPair.pubKey.toHexKey(), account.keyPair.privKey) val event = RelayAuthEvent.create(relay.url, challenge, account.keyPair.pubKey.toHexKey(), account.keyPair.privKey)
val result = AmberUtils.getDataFromResolver(SignerType.SIGN_EVENT, arrayOf(event.toJson()), "event") val result = AmberUtils.getDataFromResolver(SignerType.SIGN_EVENT, arrayOf(event.toJson(), account.keyPair.pubKey.toNpub()), account.keyPair.pubKey.toNpub(), "event")
if (result !== null) { if (result !== null) {
val signedEvent = Event.fromJson(result) val signedEvent = Event.fromJson(result)
Client.send( Client.send(
@@ -231,7 +233,7 @@ object NostrAccountDataSource : NostrDataSource("AccountData") {
) )
return return
} }
AmberUtils.signEvent(event) AmberUtils.signEvent(event, account.keyPair.pubKey.toNpub())
} else { } else {
val event = account.createAuthEvent(relay, challenge) val event = account.createAuthEvent(relay, challenge)
if (event != null) { if (event != null) {
@@ -8,11 +8,12 @@ import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.model.Account import com.vitorpamplona.amethyst.model.Account
import com.vitorpamplona.amethyst.model.LocalCache import com.vitorpamplona.amethyst.model.LocalCache
import com.vitorpamplona.amethyst.service.AmberUtils import com.vitorpamplona.amethyst.service.AmberUtils
import com.vitorpamplona.amethyst.service.SignerType
import com.vitorpamplona.amethyst.service.notifications.NotificationUtils.sendDMNotification import com.vitorpamplona.amethyst.service.notifications.NotificationUtils.sendDMNotification
import com.vitorpamplona.amethyst.service.notifications.NotificationUtils.sendZapNotification import com.vitorpamplona.amethyst.service.notifications.NotificationUtils.sendZapNotification
import com.vitorpamplona.amethyst.ui.actions.SignerType
import com.vitorpamplona.amethyst.ui.note.showAmount import com.vitorpamplona.amethyst.ui.note.showAmount
import com.vitorpamplona.quartz.encoders.toHexKey import com.vitorpamplona.quartz.encoders.toHexKey
import com.vitorpamplona.quartz.encoders.toNpub
import com.vitorpamplona.quartz.events.ChatMessageEvent import com.vitorpamplona.quartz.events.ChatMessageEvent
import com.vitorpamplona.quartz.events.ChatroomKey import com.vitorpamplona.quartz.events.ChatroomKey
import com.vitorpamplona.quartz.events.Event import com.vitorpamplona.quartz.events.Event
@@ -49,6 +50,7 @@ class EventNotificationConsumer(private val applicationContext: Context) {
pushWrappedEvent.content, pushWrappedEvent.content,
pushWrappedEvent.pubKey, pushWrappedEvent.pubKey,
pushWrappedEvent.id, pushWrappedEvent.id,
account.keyPair.pubKey.toNpub(),
SignerType.NIP44_DECRYPT SignerType.NIP44_DECRYPT
) )
cached = AmberUtils.cachedDecryptedContent[pushWrappedEvent.id] ?: "" cached = AmberUtils.cachedDecryptedContent[pushWrappedEvent.id] ?: ""
@@ -106,6 +108,7 @@ class EventNotificationConsumer(private val applicationContext: Context) {
event.content, event.content,
event.pubKey, event.pubKey,
event.id, event.id,
account.keyPair.pubKey.toNpub(),
SignerType.NIP44_DECRYPT SignerType.NIP44_DECRYPT
) )
cached = AmberUtils.cachedDecryptedContent[event.id] ?: "" cached = AmberUtils.cachedDecryptedContent[event.id] ?: ""
@@ -132,6 +135,7 @@ class EventNotificationConsumer(private val applicationContext: Context) {
event.content, event.content,
event.pubKey, event.pubKey,
event.id, event.id,
account.keyPair.pubKey.toNpub(),
SignerType.NIP44_DECRYPT SignerType.NIP44_DECRYPT
) )
cached = AmberUtils.cachedDecryptedContent[event.id] ?: "" cached = AmberUtils.cachedDecryptedContent[event.id] ?: ""
@@ -1,189 +0,0 @@
package com.vitorpamplona.amethyst.ui.actions
import android.app.Activity.RESULT_OK
import android.widget.Toast
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Button
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
import androidx.compose.material.OutlinedTextField
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.ContentPaste
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.ServiceManager
import com.vitorpamplona.amethyst.service.AmberUtils
import com.vitorpamplona.amethyst.ui.theme.ButtonBorder
import com.vitorpamplona.amethyst.ui.theme.DoubleVertSpacer
import com.vitorpamplona.quartz.encoders.HexKey
import com.vitorpamplona.quartz.events.Event
import kotlinx.coroutines.launch
enum class SignerType {
SIGN_EVENT,
NIP04_ENCRYPT,
NIP04_DECRYPT,
NIP44_ENCRYPT,
NIP44_DECRYPT,
GET_PUBLIC_KEY,
DECRYPT_ZAP_EVENT
}
@Composable
fun SignerDialog(
onClose: () -> Unit,
onPost: (content: String) -> Unit,
data: String,
type: SignerType = SignerType.SIGN_EVENT,
pubKey: HexKey = ""
) {
var signature by remember { mutableStateOf("") }
val scope = rememberCoroutineScope()
val context = LocalContext.current
val intentResult = rememberLauncherForActivityResult(
contract = ActivityResultContracts.StartActivityForResult(),
onResult = {
if (it.resultCode != RESULT_OK) {
scope.launch {
Toast.makeText(
context,
"Sign request rejected",
Toast.LENGTH_SHORT
).show()
}
return@rememberLauncherForActivityResult
}
signature = it.data?.getStringExtra("signature") ?: ""
if (type != SignerType.SIGN_EVENT) {
onPost(
signature
)
}
ServiceManager.shouldPauseService = true
}
)
LaunchedEffect(Unit) {
AmberUtils.openAmber(data, type, intentResult, pubKey, "")
}
Dialog(
onDismissRequest = { onClose() },
properties = DialogProperties(
usePlatformDefaultWidth = false,
dismissOnClickOutside = false,
decorFitsSystemWindows = false
)
) {
Surface(
modifier = Modifier
.fillMaxWidth()
.fillMaxHeight()
) {
Column(
Modifier
.fillMaxWidth()
.fillMaxHeight()
.padding(start = 10.dp, end = 10.dp, top = 10.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
CloseButton(
onPress = {
onClose()
}
)
PostButton(
onPost = {
if (type == SignerType.SIGN_EVENT) {
val event = Event.fromJson(data)
val signedEvent = Event(
event.id(),
event.pubKey(),
event.createdAt(),
event.kind(),
event.tags(),
event.content(),
signature
)
if (!signedEvent.hasValidSignature()) {
scope.launch {
Toast.makeText(
context,
"Invalid signature",
Toast.LENGTH_SHORT
).show()
}
return@PostButton
}
onPost(signedEvent.toJson())
} else {
onPost(signature)
}
},
isActive = true
)
}
Spacer(modifier = DoubleVertSpacer)
OutlinedTextField(
modifier = Modifier.fillMaxWidth(),
value = signature,
onValueChange = {
signature = it
},
placeholder = { Text("Signature (hex)") },
trailingIcon = {
Row {
IconButton(
onClick = { }
) {
Icon(
imageVector = Icons.Outlined.ContentPaste,
contentDescription = stringResource(R.string.paste_from_clipboard)
)
}
}
}
)
Button(
shape = ButtonBorder,
onClick = { AmberUtils.openAmber(data, type, intentResult, pubKey, "") }
) {
Text("Open Amber")
}
}
}
}
}
@@ -5,6 +5,7 @@ import com.vitorpamplona.amethyst.model.LocalCache
import com.vitorpamplona.amethyst.model.Note import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.service.AmberUtils import com.vitorpamplona.amethyst.service.AmberUtils
import com.vitorpamplona.quartz.encoders.toHexKey import com.vitorpamplona.quartz.encoders.toHexKey
import com.vitorpamplona.quartz.encoders.toNpub
object BookmarkPrivateFeedFilter : FeedFilter<Note>() { object BookmarkPrivateFeedFilter : FeedFilter<Note>() {
lateinit var account: Account lateinit var account: Account
@@ -24,7 +25,8 @@ object BookmarkPrivateFeedFilter : FeedFilter<Note>() {
AmberUtils.decryptBookmark( AmberUtils.decryptBookmark(
bookmarks.content, bookmarks.content,
account.keyPair.pubKey.toHexKey(), account.keyPair.pubKey.toHexKey(),
id id,
account.keyPair.pubKey.toNpub()
) )
} else { } else {
bookmarks.decryptedContent = decryptedContent bookmarks.decryptedContent = decryptedContent
@@ -50,6 +50,7 @@ import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.screen.loggedIn.ReportNoteDialog import com.vitorpamplona.amethyst.ui.screen.loggedIn.ReportNoteDialog
import com.vitorpamplona.quartz.encoders.HexKey import com.vitorpamplona.quartz.encoders.HexKey
import com.vitorpamplona.quartz.encoders.toHexKey import com.vitorpamplona.quartz.encoders.toHexKey
import com.vitorpamplona.quartz.encoders.toNpub
import kotlinx.collections.immutable.ImmutableSet import kotlinx.collections.immutable.ImmutableSet
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@@ -457,7 +458,8 @@ fun NoteDropDownMenu(note: Note, popupExpanded: MutableState<Boolean>, accountVi
AmberUtils.decrypt( AmberUtils.decrypt(
bookmarks?.content ?: "", bookmarks?.content ?: "",
accountViewModel.account.keyPair.pubKey.toHexKey(), accountViewModel.account.keyPair.pubKey.toHexKey(),
bookmarks?.id ?: "" bookmarks?.id ?: "",
accountViewModel.account.keyPair.pubKey.toNpub()
) )
bookmarks?.decryptedContent = AmberUtils.cachedDecryptedContent[bookmarks?.id ?: ""] ?: "" bookmarks?.decryptedContent = AmberUtils.cachedDecryptedContent[bookmarks?.id ?: ""] ?: ""
accountViewModel.removePrivateBookmark(note, bookmarks?.decryptedContent ?: "") accountViewModel.removePrivateBookmark(note, bookmarks?.decryptedContent ?: "")
@@ -479,7 +481,8 @@ fun NoteDropDownMenu(note: Note, popupExpanded: MutableState<Boolean>, accountVi
AmberUtils.decrypt( AmberUtils.decrypt(
bookmarks?.content ?: "", bookmarks?.content ?: "",
accountViewModel.account.keyPair.pubKey.toHexKey(), accountViewModel.account.keyPair.pubKey.toHexKey(),
bookmarks?.id ?: "" bookmarks?.id ?: "",
accountViewModel.account.keyPair.pubKey.toNpub()
) )
bookmarks?.decryptedContent = AmberUtils.cachedDecryptedContent[bookmarks?.id ?: ""] ?: "" bookmarks?.decryptedContent = AmberUtils.cachedDecryptedContent[bookmarks?.id ?: ""] ?: ""
accountViewModel.addPrivateBookmark(note, bookmarks?.decryptedContent ?: "") accountViewModel.addPrivateBookmark(note, bookmarks?.decryptedContent ?: "")
@@ -502,7 +505,8 @@ fun NoteDropDownMenu(note: Note, popupExpanded: MutableState<Boolean>, accountVi
AmberUtils.decrypt( AmberUtils.decrypt(
bookmarks?.content ?: "", bookmarks?.content ?: "",
accountViewModel.account.keyPair.pubKey.toHexKey(), accountViewModel.account.keyPair.pubKey.toHexKey(),
bookmarks?.id ?: "" bookmarks?.id ?: "",
accountViewModel.account.keyPair.pubKey.toNpub()
) )
bookmarks?.decryptedContent = AmberUtils.cachedDecryptedContent[bookmarks?.id ?: ""] ?: "" bookmarks?.decryptedContent = AmberUtils.cachedDecryptedContent[bookmarks?.id ?: ""] ?: ""
accountViewModel.removePublicBookmark( accountViewModel.removePublicBookmark(
@@ -527,7 +531,8 @@ fun NoteDropDownMenu(note: Note, popupExpanded: MutableState<Boolean>, accountVi
AmberUtils.decrypt( AmberUtils.decrypt(
bookmarks?.content ?: "", bookmarks?.content ?: "",
accountViewModel.account.keyPair.pubKey.toHexKey(), accountViewModel.account.keyPair.pubKey.toHexKey(),
bookmarks?.id ?: "" bookmarks?.id ?: "",
accountViewModel.account.keyPair.pubKey.toNpub()
) )
bookmarks?.decryptedContent = AmberUtils.cachedDecryptedContent[bookmarks?.id ?: ""] ?: "" bookmarks?.decryptedContent = AmberUtils.cachedDecryptedContent[bookmarks?.id ?: ""] ?: ""
accountViewModel.addPublicBookmark( accountViewModel.addPublicBookmark(
@@ -44,7 +44,7 @@ import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.ServiceManager import com.vitorpamplona.amethyst.ServiceManager
import com.vitorpamplona.amethyst.service.AmberUtils import com.vitorpamplona.amethyst.service.AmberUtils
import com.vitorpamplona.amethyst.service.PackageUtils import com.vitorpamplona.amethyst.service.PackageUtils
import com.vitorpamplona.amethyst.ui.actions.SignerType import com.vitorpamplona.amethyst.service.SignerType
import com.vitorpamplona.amethyst.ui.qrcode.SimpleQrCodeScanner import com.vitorpamplona.amethyst.ui.qrcode.SimpleQrCodeScanner
import com.vitorpamplona.amethyst.ui.screen.AccountStateViewModel import com.vitorpamplona.amethyst.ui.screen.AccountStateViewModel
import com.vitorpamplona.amethyst.ui.screen.loggedIn.ConnectOrbotDialog import com.vitorpamplona.amethyst.ui.screen.loggedIn.ConnectOrbotDialog
@@ -121,6 +121,7 @@ fun LoginPage(
SignerType.GET_PUBLIC_KEY, SignerType.GET_PUBLIC_KEY,
activity, activity,
"", "",
"",
"" ""
) )
} }
@@ -357,7 +358,7 @@ fun LoginPage(
Box(modifier = Modifier.padding(40.dp, 40.dp, 40.dp, 0.dp)) { Box(modifier = Modifier.padding(40.dp, 40.dp, 40.dp, 0.dp)) {
Button( Button(
onClick = { onClick = {
val result = AmberUtils.getDataFromResolver(SignerType.GET_PUBLIC_KEY, arrayOf("login")) val result = AmberUtils.getDataFromResolver(SignerType.GET_PUBLIC_KEY, arrayOf("login"), "")
if (result == null) { if (result == null) {
loginWithAmber = true loginWithAmber = true
return@Button return@Button