From 13c94112d42195da812bde645326a9692dfc22a6 Mon Sep 17 00:00:00 2001 From: greenart7c3 Date: Sat, 16 Sep 2023 07:56:14 -0300 Subject: [PATCH] fix private zaps --- .../vitorpamplona/amethyst/model/Account.kt | 153 +++++++++--------- .../amethyst/service/AmberUtils.kt | 71 ++++---- .../service/NostrAccountDataSource.kt | 6 +- .../EventNotificationConsumer.kt | 4 - .../ui/dal/BookmarkPrivateFeedFilter.kt | 4 +- .../amethyst/ui/note/UserProfilePicture.kt | 13 +- .../ui/screen/loggedOff/LoginScreen.kt | 1 - 7 files changed, 117 insertions(+), 135 deletions(-) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/model/Account.kt b/app/src/main/java/com/vitorpamplona/amethyst/model/Account.kt index dbb6b8270..770b2c71d 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/model/Account.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/model/Account.kt @@ -25,7 +25,6 @@ import com.vitorpamplona.quartz.encoders.ATag import com.vitorpamplona.quartz.encoders.HexKey import com.vitorpamplona.quartz.encoders.hexToByteArray import com.vitorpamplona.quartz.encoders.toHexKey -import com.vitorpamplona.quartz.encoders.toNpub import com.vitorpamplona.quartz.events.* import kotlinx.collections.immutable.ImmutableSet import kotlinx.collections.immutable.persistentSetOf @@ -118,8 +117,7 @@ class Account( AmberUtils.decryptBlockList( content, keyPair.pubKey.toHexKey(), - blockList.id(), - keyPair.pubKey.toNpub() + blockList.id() ) blockList.decryptedContent = AmberUtils.cachedDecryptedContent[blockList.id] live.invalidateData() @@ -222,7 +220,7 @@ class Account( ) if (loginWithAmber) { - AmberUtils.openAmber(event, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(event) val content = AmberUtils.content[event.id] ?: "" if (content.isBlank()) { return @@ -244,7 +242,7 @@ class Account( ) if (loginWithAmber) { - AmberUtils.openAmber(event, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(event) val content = AmberUtils.content[event.id] if (content.isBlank()) { return @@ -316,7 +314,7 @@ class Account( keyPair ) - AmberUtils.openAmber(senderReaction, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(senderReaction) val reactionContent = AmberUtils.content[event.id] if (reactionContent.isBlank()) return senderReaction = ReactionEvent.create(senderReaction, reactionContent) @@ -324,7 +322,7 @@ class Account( val giftWraps = users.plus(senderPublicKey).map { val gossip = Gossip.create(senderReaction) val content = Gossip.toJson(gossip) - AmberUtils.encrypt(content, it, gossip.id!!, keyPair.pubKey.toNpub(), SignerType.NIP44_ENCRYPT) + AmberUtils.encrypt(content, it, gossip.id!!, SignerType.NIP44_ENCRYPT) val encryptedContent = AmberUtils.content[gossip.id] if (encryptedContent.isBlank()) return @@ -332,7 +330,7 @@ class Account( encryptedContent = encryptedContent, pubKey = senderPublicKey ) - AmberUtils.openAmber(sealedEvent, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(sealedEvent) val eventContent = AmberUtils.content[sealedEvent.id] ?: "" if (eventContent.isBlank()) return sealedEvent = SealedGossipEvent.create(sealedEvent, eventContent) @@ -369,7 +367,7 @@ class Account( keyPair ) - AmberUtils.openAmber(senderReaction, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(senderReaction) val reactionContent = AmberUtils.content[senderReaction.id] ?: "" if (reactionContent.isBlank()) return senderReaction = ReactionEvent.create(senderReaction, reactionContent) @@ -378,7 +376,7 @@ class Account( newUsers.forEach { val gossip = Gossip.create(senderReaction) val content = Gossip.toJson(gossip) - AmberUtils.encrypt(content, it, gossip.id!!, keyPair.pubKey.toNpub(), SignerType.NIP44_ENCRYPT) + AmberUtils.encrypt(content, it, gossip.id!!, SignerType.NIP44_ENCRYPT) val encryptedContent = AmberUtils.content[gossip.id] if (encryptedContent.isBlank()) return @@ -386,7 +384,7 @@ class Account( encryptedContent = encryptedContent, pubKey = senderPublicKey ) - AmberUtils.openAmber(sealedEvent, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(sealedEvent) val sealedContent = AmberUtils.content[sealedEvent.id] ?: "" if (sealedContent.isBlank()) return sealedEvent = SealedGossipEvent.create(sealedEvent, sealedContent) @@ -417,7 +415,7 @@ class Account( note.event?.let { val event = ReactionEvent.create(emojiUrl, it, keyPair) if (loginWithAmber) { - AmberUtils.signEvent(event, keyPair.pubKey.toNpub()) + AmberUtils.signEvent(event) } else { Client.send(event) LocalCache.consume(event) @@ -431,7 +429,7 @@ class Account( note.event?.let { val event = ReactionEvent.create(reaction, it, keyPair) if (loginWithAmber) { - AmberUtils.signEvent(event, keyPair.pubKey.toNpub()) + AmberUtils.signEvent(event) } else { Client.send(event) LocalCache.consume(event) @@ -464,7 +462,7 @@ class Account( pollOption, message ) - AmberUtils.openAmber(unsignedEvent, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(unsignedEvent) val content = AmberUtils.content[unsignedEvent.id] ?: "" if (content.isBlank()) return null @@ -483,7 +481,7 @@ class Account( pollOption, message ) - AmberUtils.openAmber(unsignedEvent, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(unsignedEvent, "event") val content = AmberUtils.content[unsignedEvent.id] ?: "" if (content.isBlank()) return null @@ -533,7 +531,7 @@ class Account( if (privKey != null) return zapResponseEvent.response(privKey, pubKey) - AmberUtils.decrypt(zapResponseEvent.content, pubKey.toHexKey(), zapResponseEvent.id, keyPair.pubKey.toNpub()) + AmberUtils.decrypt(zapResponseEvent.content, pubKey.toHexKey(), zapResponseEvent.id) val decryptedContent = AmberUtils.content[zapResponseEvent.id] ?: "" if (decryptedContent.isBlank()) return null return zapResponseEvent.response(decryptedContent) @@ -606,7 +604,7 @@ class Account( note.event?.let { var event = ReactionEvent.createWarning(it, keyPair) if (loginWithAmber) { - AmberUtils.openAmber(event, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(event) val eventContent = AmberUtils.content[event.id] ?: "" if (eventContent.isBlank()) return event = ReactionEvent( @@ -625,7 +623,7 @@ class Account( note.event?.let { var event = ReportEvent.create(it, type, keyPair, content = content) if (loginWithAmber) { - AmberUtils.openAmber(event, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(event) val eventContent = AmberUtils.content[event.id] ?: "" if (eventContent.isBlank()) return event = ReportEvent( @@ -652,7 +650,7 @@ class Account( var event = ReportEvent.create(user.pubkeyHex, type, keyPair) if (loginWithAmber) { - AmberUtils.openAmber(event, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(event) val eventContent = AmberUtils.content[event.id] ?: "" if (eventContent.isBlank()) return event = ReportEvent( @@ -680,7 +678,7 @@ class Account( if (myNotes.isNotEmpty()) { val event = DeletionEvent.create(myNotes, keyPair) if (loginWithAmber) { - AmberUtils.signEvent(event, keyPair.pubKey.toNpub()) + AmberUtils.signEvent(event) } else { Client.send(event) LocalCache.consume(event) @@ -693,7 +691,7 @@ class Account( var event = HTTPAuthorizationEvent.create(url, method, body, keyPair) if (loginWithAmber) { - AmberUtils.openAmber(event, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(event) val eventContent = AmberUtils.content[event.id] ?: "" if (eventContent.isBlank()) { return null @@ -715,7 +713,7 @@ class Account( if (it.kind() == 1) { val event = RepostEvent.create(it, keyPair) if (loginWithAmber) { - AmberUtils.signEvent(event, keyPair.pubKey.toNpub()) + AmberUtils.signEvent(event) } else { Client.send(event) LocalCache.consume(event) @@ -723,7 +721,7 @@ class Account( } else { val event = GenericRepostEvent.create(it, keyPair) if (loginWithAmber) { - AmberUtils.signEvent(event, keyPair.pubKey.toNpub()) + AmberUtils.signEvent(event) } else { Client.send(event) LocalCache.consume(event) @@ -758,7 +756,7 @@ class Account( it, keyPair ) - AmberUtils.openAmber(unsignedEvent, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(unsignedEvent) val eventContent = AmberUtils.content[unsignedEvent.id] ?: "" returningContactList = if (eventContent.isBlank()) { latestContactList @@ -807,7 +805,7 @@ class Account( } if (loginWithAmber) { - AmberUtils.openAmber(event, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(event) val eventContent = AmberUtils.content[event.id] ?: "" if (eventContent.isBlank()) { return @@ -839,7 +837,7 @@ class Account( } if (loginWithAmber) { - AmberUtils.openAmber(event, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(event) val eventContent = AmberUtils.content[event.id] ?: "" if (eventContent.isBlank()) { return @@ -872,7 +870,7 @@ class Account( } if (loginWithAmber) { - AmberUtils.openAmber(event, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(event) val eventContent = AmberUtils.content[event.id] ?: "" if (eventContent.isBlank()) { return @@ -908,7 +906,7 @@ class Account( } if (loginWithAmber) { - AmberUtils.openAmber(event, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(event) val eventContent = AmberUtils.content[event.id] ?: "" if (eventContent.isBlank()) { return @@ -944,7 +942,7 @@ class Account( } if (loginWithAmber) { - AmberUtils.openAmber(event, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(event) val eventContent = AmberUtils.content[event.id] ?: "" if (eventContent.isBlank()) { return @@ -969,7 +967,7 @@ class Account( ) if (loginWithAmber) { - AmberUtils.openAmber(event, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(event) val eventContent = AmberUtils.content[event.id] ?: "" if (eventContent.isBlank()) { return @@ -995,7 +993,7 @@ class Account( ) if (loginWithAmber) { - AmberUtils.openAmber(event, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(event) val eventContent = AmberUtils.content[event.id] ?: "" if (eventContent.isBlank()) { return @@ -1021,7 +1019,7 @@ class Account( ) if (loginWithAmber) { - AmberUtils.openAmber(event, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(event) val eventContent = AmberUtils.content[event.id] ?: "" if (eventContent.isBlank()) { return @@ -1047,7 +1045,7 @@ class Account( ) if (loginWithAmber) { - AmberUtils.openAmber(event, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(event) val eventContent = AmberUtils.content[event.id] ?: "" if (eventContent.isBlank()) { return @@ -1073,7 +1071,7 @@ class Account( ) if (loginWithAmber) { - AmberUtils.openAmber(event, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(event) val eventContent = AmberUtils.content[event.id] ?: "" if (eventContent.isBlank()) { return @@ -1096,7 +1094,7 @@ class Account( pubKey = keyPair.pubKey.toHexKey() ) - AmberUtils.openAmber(unsignedData, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(unsignedData) val eventContent = AmberUtils.content[unsignedData.id] ?: "" if (eventContent.isBlank()) return null val data = FileStorageEvent( @@ -1120,7 +1118,7 @@ class Account( pubKey = keyPair.pubKey.toHexKey() ) - AmberUtils.openAmber(unsignedEvent, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(unsignedEvent) val unsignedEventContent = AmberUtils.content[unsignedEvent.id] ?: "" if (unsignedEventContent.isBlank()) return null val signedEvent = FileStorageHeaderEvent( @@ -1190,7 +1188,7 @@ class Account( sensitiveContent = headerInfo.sensitiveContent, keyPair = keyPair ) - AmberUtils.openAmber(unsignedEvent, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(unsignedEvent) val eventContent = AmberUtils.content[unsignedEvent.id] ?: "" if (eventContent.isBlank()) return null val signedEvent = FileHeaderEvent( @@ -1257,7 +1255,7 @@ class Account( ) if (loginWithAmber) { - AmberUtils.openAmber(signedEvent, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(signedEvent) val eventContent = AmberUtils.content[signedEvent.id] ?: "" if (eventContent.isBlank()) { return @@ -1327,7 +1325,7 @@ class Account( // println("Sending new PollNoteEvent: %s".format(signedEvent.toJson())) if (loginWithAmber) { - AmberUtils.openAmber(signedEvent, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(signedEvent) val eventContent = AmberUtils.content[signedEvent.id] ?: "" if (eventContent.isBlank()) { return @@ -1379,7 +1377,7 @@ class Account( ) if (loginWithAmber) { - AmberUtils.openAmber(signedEvent, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(signedEvent) val eventContent = AmberUtils.content[signedEvent.id] ?: "" if (eventContent.isBlank()) { return @@ -1420,7 +1418,7 @@ class Account( ) if (loginWithAmber) { - AmberUtils.openAmber(signedEvent, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(signedEvent) val eventContent = AmberUtils.content[signedEvent.id] ?: "" if (eventContent.isBlank()) { return @@ -1453,7 +1451,7 @@ class Account( var localMessage = message if (loginWithAmber) { - AmberUtils.encrypt(localMessage, toUser, "encrypt", keyPair.pubKey.toNpub()) + AmberUtils.encrypt(localMessage, toUser, "encrypt") val eventContent = AmberUtils.content["encrypt"] ?: "" if (eventContent.isBlank()) return localMessage = eventContent @@ -1475,7 +1473,7 @@ class Account( ) if (loginWithAmber) { - AmberUtils.openAmber(signedEvent, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(signedEvent) val eventContent = AmberUtils.content[signedEvent.id] ?: "" if (eventContent.isBlank()) { return @@ -1517,7 +1515,7 @@ class Account( geohash = geohash ) - AmberUtils.openAmber(chatMessageEvent, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(chatMessageEvent) val eventContent = AmberUtils.content[chatMessageEvent.id] ?: "" if (eventContent.isBlank()) return chatMessageEvent = ChatMessageEvent.create(chatMessageEvent, eventContent) @@ -1525,14 +1523,14 @@ class Account( toUsers.plus(senderPublicKey).toSet().forEach { val gossip = Gossip.create(chatMessageEvent) val content = Gossip.toJson(gossip) - AmberUtils.encrypt(content, it, gossip.id!!, keyPair.pubKey.toNpub(), SignerType.NIP44_ENCRYPT) + AmberUtils.encrypt(content, it, gossip.id!!, SignerType.NIP44_ENCRYPT) val gossipContent = AmberUtils.content[gossip.id] ?: "" if (gossipContent.isNotBlank()) { var sealedEvent = SealedGossipEvent.create( encryptedContent = gossipContent, pubKey = senderPublicKey ) - AmberUtils.openAmber(sealedEvent, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(sealedEvent) val sealedEventContent = AmberUtils.content[sealedEvent.id] ?: "" if (sealedEventContent.isBlank()) return sealedEvent = SealedGossipEvent.create(sealedEvent, sealedEventContent) @@ -1569,12 +1567,12 @@ class Account( // Only keep in cache the GiftWrap for the account. if (it.recipientPubKey() == keyPair.pubKey.toHexKey()) { if (loginWithAmber) { - AmberUtils.decrypt(it.content, it.pubKey, it.id, keyPair.pubKey.toNpub(), SignerType.NIP44_DECRYPT) + AmberUtils.decrypt(it.content, it.pubKey, it.id, SignerType.NIP44_DECRYPT) val decryptedContent = AmberUtils.cachedDecryptedContent[it.id] ?: "" if (decryptedContent.isEmpty()) return it.cachedGift(keyPair.pubKey, decryptedContent)?.let { cached -> if (cached is SealedGossipEvent) { - AmberUtils.decrypt(cached.content, cached.pubKey, cached.id, keyPair.pubKey.toNpub(), SignerType.NIP44_DECRYPT) + AmberUtils.decrypt(cached.content, cached.pubKey, cached.id, SignerType.NIP44_DECRYPT) val localDecryptedContent = AmberUtils.cachedDecryptedContent[cached.id] ?: "" if (localDecryptedContent.isEmpty()) return cached.cachedGossip(keyPair.pubKey, localDecryptedContent)?.let { gossip -> @@ -1616,7 +1614,7 @@ class Account( ) if (loginWithAmber) { - AmberUtils.openAmber(event, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(event) val eventContent = AmberUtils.content[event.id] ?: "" if (eventContent.isBlank()) { return @@ -1638,7 +1636,7 @@ class Account( var event = StatusEvent.update(oldEvent, newStatus, keyPair) if (loginWithAmber) { - AmberUtils.openAmber(event, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(event) val eventContent = AmberUtils.content[event.id] ?: "" if (eventContent.isBlank()) { return @@ -1654,7 +1652,7 @@ class Account( var event = StatusEvent.create(newStatus, "general", expiration = null, keyPair) if (loginWithAmber) { - AmberUtils.openAmber(event, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(event) val eventContent = AmberUtils.content[event.id] ?: "" if (eventContent.isBlank()) { return @@ -1671,7 +1669,7 @@ class Account( var event = StatusEvent.clear(oldEvent, keyPair) if (loginWithAmber) { - AmberUtils.openAmber(event, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(event) val eventContent = AmberUtils.content[event.id] ?: "" if (eventContent.isBlank()) { return @@ -1683,7 +1681,7 @@ class Account( var event2 = DeletionEvent.create(listOf(event.id), keyPair) if (loginWithAmber) { - AmberUtils.openAmber(event2, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(event2) val event2Content = AmberUtils.content[event2.id] ?: "" if (event2Content.isBlank()) { return @@ -1708,7 +1706,7 @@ class Account( ) if (loginWithAmber) { - AmberUtils.openAmber(event, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(event) val eventContent = AmberUtils.content[event.id] ?: "" if (eventContent.isBlank()) { return @@ -1745,7 +1743,7 @@ class Account( } if (loginWithAmber) { - AmberUtils.openAmber(event, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(event) val eventContent = AmberUtils.content[event.id] ?: "" if (eventContent.isBlank()) { return @@ -1784,7 +1782,7 @@ class Account( } val msg = Event.mapper.writeValueAsString(privTags) - AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey(), "encrypt", keyPair.pubKey.toNpub()) + AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey(), "encrypt") val encryptedContent = AmberUtils.content["encrypt"] ?: "" AmberUtils.content.remove("encrypt") if (encryptedContent.isBlank()) { @@ -1802,7 +1800,7 @@ class Account( keyPair.pubKey.toHexKey() ) - AmberUtils.openAmber(event, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(event) val eventContent = AmberUtils.content[event.id] ?: "" if (eventContent.isBlank()) { return @@ -1840,7 +1838,7 @@ class Account( } val msg = Event.mapper.writeValueAsString(privTags) - AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey(), "encrypt", keyPair.pubKey.toNpub()) + AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey(), "encrypt") val encryptedContent = AmberUtils.content["encrypt"] ?: "" AmberUtils.content.remove("encrypt") if (encryptedContent.isBlank()) { @@ -1858,7 +1856,7 @@ class Account( keyPair.pubKey.toHexKey() ) - AmberUtils.openAmber(event, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(event) val eventContent = AmberUtils.content[event.id] ?: "" if (eventContent.isBlank()) { return @@ -1926,7 +1924,7 @@ class Account( } val msg = Event.mapper.writeValueAsString(privTags) - AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey(), "encrypt", keyPair.pubKey.toNpub()) + AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey(), "encrypt") val encryptedContent = AmberUtils.content["encrypt"] ?: "" AmberUtils.content.remove("encrypt") if (encryptedContent.isBlank()) { @@ -1952,7 +1950,7 @@ class Account( keyPair.pubKey.toHexKey() ) } - AmberUtils.openAmber(event, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(event) val eventContent = AmberUtils.content[event.id] ?: "" if (eventContent.isBlank()) { return @@ -2042,7 +2040,7 @@ class Account( var event = RelayAuthEvent.create(relay.url, challenge, keyPair.pubKey.toHexKey(), keyPair.privKey) if (loginWithAmber) { - AmberUtils.openAmber(event, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(event) val eventContent = AmberUtils.content[event.id] ?: "" if (eventContent.isBlank()) { return null @@ -2110,7 +2108,7 @@ class Account( } val msg = Event.mapper.writeValueAsString(privTags) - AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey(), "encrypt", keyPair.pubKey.toNpub()) + AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey(), "encrypt") val encryptedContent = AmberUtils.content["encrypt"] ?: "" AmberUtils.content.remove("encrypt") if (encryptedContent.isBlank()) { @@ -2137,7 +2135,7 @@ class Account( ) } - AmberUtils.openAmber(event, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(event) val eventContent = AmberUtils.content[event.id] ?: "" if (eventContent.isBlank()) { return @@ -2215,7 +2213,7 @@ class Account( val privateTags = listOf(listOf("p", pubkeyHex)) val msg = Event.mapper.writeValueAsString(privateTags) - AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey(), "encrypt", keyPair.pubKey.toNpub()) + AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey(), "encrypt") val encryptedContent = AmberUtils.content["encrypted"] ?: "" AmberUtils.content.remove("encrypted") if (encryptedContent.isBlank()) return @@ -2223,7 +2221,7 @@ class Account( } else { var decryptedContent = AmberUtils.cachedDecryptedContent[id] if (decryptedContent == null) { - AmberUtils.decrypt(blockList.content, keyPair.pubKey.toHexKey(), id, keyPair.pubKey.toNpub()) + AmberUtils.decrypt(blockList.content, keyPair.pubKey.toHexKey(), id) val content = AmberUtils.content[id] ?: "" if (content.isBlank()) return decryptedContent = content @@ -2231,7 +2229,7 @@ class Account( val privateTags = blockList.privateTagsOrEmpty(decryptedContent).plus(element = listOf("p", pubkeyHex)) val msg = Event.mapper.writeValueAsString(privateTags) - AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey(), id, keyPair.pubKey.toNpub()) + AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey(), id) val eventContent = AmberUtils.content[id] ?: "" if (eventContent.isBlank()) return eventContent @@ -2255,7 +2253,7 @@ class Account( ) } - AmberUtils.openAmber(event, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(event) val eventContent = AmberUtils.content[event.id] ?: "" if (eventContent.isBlank()) return event = PeopleListEvent( @@ -2304,21 +2302,21 @@ class Account( val privateTags = listOf(listOf("p", pubkeyHex)) val msg = Event.mapper.writeValueAsString(privateTags) - AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey(), blockList.id, keyPair.pubKey.toNpub()) + AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey(), blockList.id) val eventContent = AmberUtils.content[blockList.id] ?: "" if (eventContent.isBlank()) return eventContent } else { var decryptedContent = AmberUtils.cachedDecryptedContent[blockList.id] if (decryptedContent == null) { - AmberUtils.decrypt(blockList.content, keyPair.pubKey.toHexKey(), blockList.id, keyPair.pubKey.toNpub()) + AmberUtils.decrypt(blockList.content, keyPair.pubKey.toHexKey(), blockList.id) val eventContent = AmberUtils.content[blockList.id] ?: "" if (eventContent.isBlank()) return decryptedContent = eventContent } val privateTags = blockList.privateTagsOrEmpty(decryptedContent).minus(element = listOf("p", pubkeyHex)) val msg = Event.mapper.writeValueAsString(privateTags) - AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey(), blockList.id, keyPair.pubKey.toNpub()) + AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey(), blockList.id) val eventContent = AmberUtils.content[blockList.id] ?: "" if (eventContent.isBlank()) return eventContent @@ -2332,7 +2330,7 @@ class Account( encryptedContent ) - AmberUtils.openAmber(event, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(event) val eventContent = AmberUtils.content[event.id] ?: "" if (eventContent.isBlank()) return event = PeopleListEvent.create(event, eventContent) @@ -2547,7 +2545,7 @@ class Account( keyPair = keyPair ) if (loginWithAmber) { - AmberUtils.openAmber(event, keyPair.pubKey.toNpub()) + AmberUtils.openAmber(event) val eventContent = AmberUtils.content[event.id] ?: "" if (eventContent.isBlank()) return event = ChannelMetadataEvent.create(event, eventContent) @@ -2565,7 +2563,7 @@ class Account( if (loginWithAmber) { var decryptedContent = AmberUtils.cachedDecryptedContent[event.id] if (decryptedContent == null) { - AmberUtils.decrypt(event.content, event.pubKey, event.id, keyPair.pubKey.toNpub(), SignerType.NIP44_DECRYPT) + AmberUtils.decrypt(event.content, event.pubKey, event.id, SignerType.NIP44_DECRYPT) } decryptedContent = AmberUtils.cachedDecryptedContent[event.id] ?: "" if (decryptedContent.isEmpty()) return null @@ -2581,7 +2579,7 @@ class Account( if (loginWithAmber) { var decryptedContent = AmberUtils.cachedDecryptedContent[event.id] if (decryptedContent == null) { - AmberUtils.decrypt(event.content, event.pubKey, event.id, keyPair.pubKey.toNpub(), SignerType.NIP44_DECRYPT) + AmberUtils.decrypt(event.content, event.pubKey, event.id, SignerType.NIP44_DECRYPT) } decryptedContent = AmberUtils.cachedDecryptedContent[event.id] ?: "" if (decryptedContent.isEmpty()) return null @@ -2611,8 +2609,7 @@ class Account( AmberUtils.decryptDM( event.content, event.talkingWith(userProfile().pubkeyHex), - event.id, - keyPair.pubKey.toNpub() + event.id ) AmberUtils.cachedDecryptedContent[event.id] } else { @@ -2641,7 +2638,7 @@ class Account( null } } - AmberUtils.decryptZapEvent(event, keyPair.pubKey.toNpub()) + AmberUtils.decryptZapEvent(event) return null } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/service/AmberUtils.kt b/app/src/main/java/com/vitorpamplona/amethyst/service/AmberUtils.kt index 7960a682f..8ab310c2f 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/service/AmberUtils.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/service/AmberUtils.kt @@ -15,6 +15,7 @@ import com.vitorpamplona.amethyst.service.relays.Client import com.vitorpamplona.amethyst.ui.MainActivity import com.vitorpamplona.quartz.encoders.HexKey import com.vitorpamplona.quartz.encoders.toHexKey +import com.vitorpamplona.quartz.encoders.toNpub import com.vitorpamplona.quartz.events.Event import com.vitorpamplona.quartz.events.EventInterface import com.vitorpamplona.quartz.events.LnZapRequestEvent @@ -137,8 +138,7 @@ object AmberUtils { type: SignerType, intentResult: ActivityResultLauncher, pubKey: HexKey, - id: String, - currentUserNpub: HexKey + id: String ) { ServiceManager.shouldPauseService = false val intent = Intent(Intent.ACTION_VIEW, Uri.parse("nostrsigner:$data")) @@ -154,15 +154,17 @@ object AmberUtils { intent.putExtra("type", signerType) intent.putExtra("pubKey", pubKey) intent.putExtra("id", id) - intent.putExtra("current_user", currentUserNpub) + if (type !== SignerType.GET_PUBLIC_KEY) { + intent.putExtra("current_user", account.keyPair.pubKey.toNpub()) + } intent.`package` = "com.greenart7c3.nostrsigner" intentResult.launch(intent) } - fun openAmber(event: EventInterface, currentUserNpub: HexKey) { + fun openAmber(event: EventInterface, columnName: String = "signature") { checkNotInMainThread() - val result = getDataFromResolver(SignerType.SIGN_EVENT, arrayOf(event.toJson(), event.pubKey()), currentUserNpub) + val result = getDataFromResolver(SignerType.SIGN_EVENT, arrayOf(event.toJson(), event.pubKey()), columnName) if (result !== null) { content.put(event.id(), result) return @@ -175,15 +177,14 @@ object AmberUtils { SignerType.SIGN_EVENT, activityResultLauncher, "", - event.id(), - currentUserNpub + event.id() ) while (isActivityRunning) { Thread.sleep(100) } } - fun signEvent(event: EventInterface, currentUserNpub: HexKey) { + fun signEvent(event: EventInterface) { checkNotInMainThread() ServiceManager.shouldPauseService = false isActivityRunning = true @@ -192,13 +193,12 @@ object AmberUtils { SignerType.SIGN_EVENT, signEventResultLauncher, account.keyPair.pubKey.toHexKey(), - event.id(), - currentUserNpub + event.id() ) } - fun decryptBlockList(encryptedContent: String, pubKey: HexKey, id: String, currentUserNpub: HexKey, signerType: SignerType = SignerType.NIP04_DECRYPT) { - val result = getDataFromResolver(signerType, arrayOf(encryptedContent, pubKey), currentUserNpub) + fun decryptBlockList(encryptedContent: String, pubKey: HexKey, id: String, signerType: SignerType = SignerType.NIP04_DECRYPT) { + val result = getDataFromResolver(signerType, arrayOf(encryptedContent, pubKey)) if (result !== null) { content.put(id, result) cachedDecryptedContent[id] = result @@ -210,13 +210,17 @@ object AmberUtils { signerType, blockListResultLauncher, pubKey, - id, - currentUserNpub + id ) } - fun getDataFromResolver(signerType: SignerType, data: Array, currentUserNpub: HexKey, columnName: String = "signature"): String? { - val localData = data.toList().plus(currentUserNpub).toTypedArray() + fun getDataFromResolver(signerType: SignerType, data: Array, columnName: String = "signature"): String? { + val localData = if (signerType !== SignerType.GET_PUBLIC_KEY) { + data.toList().plus(account.keyPair.pubKey.toNpub()).toTypedArray() + } else { + data + } + Amethyst.instance.contentResolver.query( Uri.parse("content://com.greenart7c3.nostrsigner.$signerType"), localData, @@ -234,8 +238,8 @@ object AmberUtils { return null } - fun decrypt(encryptedContent: String, pubKey: HexKey, id: String, currentUserNpub: HexKey, signerType: SignerType = SignerType.NIP04_DECRYPT) { - val result = getDataFromResolver(signerType, arrayOf(encryptedContent, pubKey), currentUserNpub) + fun decrypt(encryptedContent: String, pubKey: HexKey, id: String, signerType: SignerType = SignerType.NIP04_DECRYPT) { + val result = getDataFromResolver(signerType, arrayOf(encryptedContent, pubKey)) if (result !== null) { content.put(id, result) cachedDecryptedContent[id] = result @@ -248,16 +252,15 @@ object AmberUtils { signerType, decryptResultLauncher, pubKey, - id, - currentUserNpub + id ) while (isActivityRunning) { // do nothing } } - fun decryptDM(encryptedContent: String, pubKey: HexKey, id: String, currentUserNpub: HexKey, signerType: SignerType = SignerType.NIP04_DECRYPT) { - val result = getDataFromResolver(signerType, arrayOf(encryptedContent, pubKey), currentUserNpub) + fun decryptDM(encryptedContent: String, pubKey: HexKey, id: String, signerType: SignerType = SignerType.NIP04_DECRYPT) { + val result = getDataFromResolver(signerType, arrayOf(encryptedContent, pubKey)) if (result !== null) { content.put(id, result) cachedDecryptedContent[id] = result @@ -268,13 +271,12 @@ object AmberUtils { signerType, decryptResultLauncher, pubKey, - id, - currentUserNpub + id ) } - fun decryptBookmark(encryptedContent: String, pubKey: HexKey, id: String, currentUserNpub: HexKey, signerType: SignerType = SignerType.NIP04_DECRYPT) { - val result = getDataFromResolver(signerType, arrayOf(encryptedContent, pubKey), currentUserNpub) + fun decryptBookmark(encryptedContent: String, pubKey: HexKey, id: String, signerType: SignerType = SignerType.NIP04_DECRYPT) { + val result = getDataFromResolver(signerType, arrayOf(encryptedContent, pubKey)) if (result !== null) { content.put(id, result) cachedDecryptedContent[id] = result @@ -285,13 +287,12 @@ object AmberUtils { signerType, decryptResultLauncher, pubKey, - id, - currentUserNpub + id ) } - fun encrypt(decryptedContent: String, pubKey: HexKey, id: String, currentUserNpub: HexKey, signerType: SignerType = SignerType.NIP04_ENCRYPT) { - val result = getDataFromResolver(signerType, arrayOf(decryptedContent, pubKey), currentUserNpub) + fun encrypt(decryptedContent: String, pubKey: HexKey, id: String, signerType: SignerType = SignerType.NIP04_ENCRYPT) { + val result = getDataFromResolver(signerType, arrayOf(decryptedContent, pubKey)) if (result !== null) { content.put(id, result) return @@ -303,16 +304,15 @@ object AmberUtils { signerType, activityResultLauncher, pubKey, - id, - currentUserNpub + id ) while (isActivityRunning) { Thread.sleep(100) } } - fun decryptZapEvent(event: LnZapRequestEvent, currentUserNpub: HexKey) { - val result = getDataFromResolver(SignerType.DECRYPT_ZAP_EVENT, arrayOf(event.toJson()), currentUserNpub) + fun decryptZapEvent(event: LnZapRequestEvent) { + val result = getDataFromResolver(SignerType.DECRYPT_ZAP_EVENT, arrayOf(event.toJson(), event.pubKey)) if (result !== null) { content.put(event.id, result) cachedDecryptedContent[event.id] = result @@ -323,8 +323,7 @@ object AmberUtils { SignerType.DECRYPT_ZAP_EVENT, decryptResultLauncher, event.pubKey, - event.id, - currentUserNpub + event.id ) } } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/service/NostrAccountDataSource.kt b/app/src/main/java/com/vitorpamplona/amethyst/service/NostrAccountDataSource.kt index 47e94eb16..777cc1871 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/service/NostrAccountDataSource.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/service/NostrAccountDataSource.kt @@ -162,7 +162,6 @@ object NostrAccountDataSource : NostrDataSource("AccountData") { event.content, event.pubKey, event.id, - account.keyPair.pubKey.toNpub(), SignerType.NIP44_DECRYPT ) cached = AmberUtils.cachedDecryptedContent[event.id] ?: "" @@ -186,7 +185,6 @@ object NostrAccountDataSource : NostrDataSource("AccountData") { event.content, event.pubKey, event.id, - account.keyPair.pubKey.toNpub(), SignerType.NIP44_DECRYPT ) cached = AmberUtils.cachedDecryptedContent[event.id] ?: "" @@ -224,7 +222,7 @@ object NostrAccountDataSource : NostrDataSource("AccountData") { if (this::account.isInitialized) { if (account.loginWithAmber) { val event = RelayAuthEvent.create(relay.url, challenge, account.keyPair.pubKey.toHexKey(), account.keyPair.privKey) - val result = AmberUtils.getDataFromResolver(SignerType.SIGN_EVENT, arrayOf(event.toJson(), account.keyPair.pubKey.toNpub()), account.keyPair.pubKey.toNpub(), "event") + val result = AmberUtils.getDataFromResolver(SignerType.SIGN_EVENT, arrayOf(event.toJson(), account.keyPair.pubKey.toNpub()), "event") if (result !== null) { val signedEvent = Event.fromJson(result) Client.send( @@ -233,7 +231,7 @@ object NostrAccountDataSource : NostrDataSource("AccountData") { ) return } - AmberUtils.signEvent(event, account.keyPair.pubKey.toNpub()) + AmberUtils.signEvent(event) } else { val event = account.createAuthEvent(relay, challenge) if (event != null) { diff --git a/app/src/main/java/com/vitorpamplona/amethyst/service/notifications/EventNotificationConsumer.kt b/app/src/main/java/com/vitorpamplona/amethyst/service/notifications/EventNotificationConsumer.kt index 25439bb40..9b5936a2c 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/service/notifications/EventNotificationConsumer.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/service/notifications/EventNotificationConsumer.kt @@ -13,7 +13,6 @@ import com.vitorpamplona.amethyst.service.notifications.NotificationUtils.sendDM import com.vitorpamplona.amethyst.service.notifications.NotificationUtils.sendZapNotification import com.vitorpamplona.amethyst.ui.note.showAmount import com.vitorpamplona.quartz.encoders.toHexKey -import com.vitorpamplona.quartz.encoders.toNpub import com.vitorpamplona.quartz.events.ChatMessageEvent import com.vitorpamplona.quartz.events.ChatroomKey import com.vitorpamplona.quartz.events.Event @@ -50,7 +49,6 @@ class EventNotificationConsumer(private val applicationContext: Context) { pushWrappedEvent.content, pushWrappedEvent.pubKey, pushWrappedEvent.id, - account.keyPair.pubKey.toNpub(), SignerType.NIP44_DECRYPT ) cached = AmberUtils.cachedDecryptedContent[pushWrappedEvent.id] ?: "" @@ -108,7 +106,6 @@ class EventNotificationConsumer(private val applicationContext: Context) { event.content, event.pubKey, event.id, - account.keyPair.pubKey.toNpub(), SignerType.NIP44_DECRYPT ) cached = AmberUtils.cachedDecryptedContent[event.id] ?: "" @@ -135,7 +132,6 @@ class EventNotificationConsumer(private val applicationContext: Context) { event.content, event.pubKey, event.id, - account.keyPair.pubKey.toNpub(), SignerType.NIP44_DECRYPT ) cached = AmberUtils.cachedDecryptedContent[event.id] ?: "" diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/dal/BookmarkPrivateFeedFilter.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/dal/BookmarkPrivateFeedFilter.kt index b177142fb..940dccb55 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/dal/BookmarkPrivateFeedFilter.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/dal/BookmarkPrivateFeedFilter.kt @@ -5,7 +5,6 @@ import com.vitorpamplona.amethyst.model.LocalCache import com.vitorpamplona.amethyst.model.Note import com.vitorpamplona.amethyst.service.AmberUtils import com.vitorpamplona.quartz.encoders.toHexKey -import com.vitorpamplona.quartz.encoders.toNpub object BookmarkPrivateFeedFilter : FeedFilter() { lateinit var account: Account @@ -25,8 +24,7 @@ object BookmarkPrivateFeedFilter : FeedFilter() { AmberUtils.decryptBookmark( bookmarks.content, account.keyPair.pubKey.toHexKey(), - id, - account.keyPair.pubKey.toNpub() + id ) } else { bookmarks.decryptedContent = decryptedContent diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/UserProfilePicture.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/UserProfilePicture.kt index 3100af03d..5c414a283 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/UserProfilePicture.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/UserProfilePicture.kt @@ -50,7 +50,6 @@ import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.ReportNoteDialog import com.vitorpamplona.quartz.encoders.HexKey import com.vitorpamplona.quartz.encoders.toHexKey -import com.vitorpamplona.quartz.encoders.toNpub import kotlinx.collections.immutable.ImmutableSet import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -458,8 +457,7 @@ fun NoteDropDownMenu(note: Note, popupExpanded: MutableState, accountVi AmberUtils.decrypt( bookmarks?.content ?: "", accountViewModel.account.keyPair.pubKey.toHexKey(), - bookmarks?.id ?: "", - accountViewModel.account.keyPair.pubKey.toNpub() + bookmarks?.id ?: "" ) bookmarks?.decryptedContent = AmberUtils.cachedDecryptedContent[bookmarks?.id ?: ""] ?: "" accountViewModel.removePrivateBookmark(note, bookmarks?.decryptedContent ?: "") @@ -481,8 +479,7 @@ fun NoteDropDownMenu(note: Note, popupExpanded: MutableState, accountVi AmberUtils.decrypt( bookmarks?.content ?: "", accountViewModel.account.keyPair.pubKey.toHexKey(), - bookmarks?.id ?: "", - accountViewModel.account.keyPair.pubKey.toNpub() + bookmarks?.id ?: "" ) bookmarks?.decryptedContent = AmberUtils.cachedDecryptedContent[bookmarks?.id ?: ""] ?: "" accountViewModel.addPrivateBookmark(note, bookmarks?.decryptedContent ?: "") @@ -505,8 +502,7 @@ fun NoteDropDownMenu(note: Note, popupExpanded: MutableState, accountVi AmberUtils.decrypt( bookmarks?.content ?: "", accountViewModel.account.keyPair.pubKey.toHexKey(), - bookmarks?.id ?: "", - accountViewModel.account.keyPair.pubKey.toNpub() + bookmarks?.id ?: "" ) bookmarks?.decryptedContent = AmberUtils.cachedDecryptedContent[bookmarks?.id ?: ""] ?: "" accountViewModel.removePublicBookmark( @@ -531,8 +527,7 @@ fun NoteDropDownMenu(note: Note, popupExpanded: MutableState, accountVi AmberUtils.decrypt( bookmarks?.content ?: "", accountViewModel.account.keyPair.pubKey.toHexKey(), - bookmarks?.id ?: "", - accountViewModel.account.keyPair.pubKey.toNpub() + bookmarks?.id ?: "" ) bookmarks?.decryptedContent = AmberUtils.cachedDecryptedContent[bookmarks?.id ?: ""] ?: "" accountViewModel.addPublicBookmark( diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedOff/LoginScreen.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedOff/LoginScreen.kt index a0bb39eec..8614e56fc 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedOff/LoginScreen.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedOff/LoginScreen.kt @@ -121,7 +121,6 @@ fun LoginPage( SignerType.GET_PUBLIC_KEY, activity, "", - "", "" ) }