Renames Persona to KeyPair and Utils to CryptoUtils
This commit is contained in:
@@ -16,7 +16,7 @@ import com.vitorpamplona.amethyst.model.hexToByteArray
|
|||||||
import com.vitorpamplona.amethyst.model.parseConnectivityType
|
import com.vitorpamplona.amethyst.model.parseConnectivityType
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.HttpClient
|
import com.vitorpamplona.amethyst.service.HttpClient
|
||||||
import com.vitorpamplona.amethyst.service.Persona
|
import com.vitorpamplona.amethyst.service.KeyPair
|
||||||
import com.vitorpamplona.amethyst.service.model.ContactListEvent
|
import com.vitorpamplona.amethyst.service.model.ContactListEvent
|
||||||
import com.vitorpamplona.amethyst.service.model.Event
|
import com.vitorpamplona.amethyst.service.model.Event
|
||||||
import com.vitorpamplona.amethyst.service.model.Event.Companion.getRefinedEvent
|
import com.vitorpamplona.amethyst.service.model.Event.Companion.getRefinedEvent
|
||||||
@@ -211,8 +211,8 @@ object LocalPreferences {
|
|||||||
fun saveToEncryptedStorage(account: Account) {
|
fun saveToEncryptedStorage(account: Account) {
|
||||||
val prefs = encryptedPreferences(account.userProfile().pubkeyNpub())
|
val prefs = encryptedPreferences(account.userProfile().pubkeyNpub())
|
||||||
prefs.edit().apply {
|
prefs.edit().apply {
|
||||||
account.loggedIn.privKey?.let { putString(PrefKeys.NOSTR_PRIVKEY, it.toHexKey()) }
|
account.keyPair.privKey?.let { putString(PrefKeys.NOSTR_PRIVKEY, it.toHexKey()) }
|
||||||
account.loggedIn.pubKey.let { putString(PrefKeys.NOSTR_PUBKEY, it.toHexKey()) }
|
account.keyPair.pubKey.let { putString(PrefKeys.NOSTR_PUBKEY, it.toHexKey()) }
|
||||||
putStringSet(PrefKeys.FOLLOWING_CHANNELS, account.followingChannels)
|
putStringSet(PrefKeys.FOLLOWING_CHANNELS, account.followingChannels)
|
||||||
putStringSet(PrefKeys.FOLLOWING_COMMUNITIES, account.followingCommunities)
|
putStringSet(PrefKeys.FOLLOWING_COMMUNITIES, account.followingCommunities)
|
||||||
putStringSet(PrefKeys.HIDDEN_USERS, account.hiddenUsers)
|
putStringSet(PrefKeys.HIDDEN_USERS, account.hiddenUsers)
|
||||||
@@ -412,7 +412,7 @@ object LocalPreferences {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val a = Account(
|
val a = Account(
|
||||||
loggedIn = Persona(privKey = privKey?.hexToByteArray(), pubKey = pubKey.hexToByteArray()),
|
keyPair = KeyPair(privKey = privKey?.hexToByteArray(), pubKey = pubKey.hexToByteArray()),
|
||||||
followingChannels = followingChannels,
|
followingChannels = followingChannels,
|
||||||
followingCommunities = followingCommunities,
|
followingCommunities = followingCommunities,
|
||||||
hiddenUsers = hiddenUsers,
|
hiddenUsers = hiddenUsers,
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ import androidx.core.os.ConfigurationCompat
|
|||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import androidx.lifecycle.distinctUntilChanged
|
import androidx.lifecycle.distinctUntilChanged
|
||||||
import com.vitorpamplona.amethyst.OptOutFromFilters
|
import com.vitorpamplona.amethyst.OptOutFromFilters
|
||||||
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
import com.vitorpamplona.amethyst.service.FileHeader
|
import com.vitorpamplona.amethyst.service.FileHeader
|
||||||
|
import com.vitorpamplona.amethyst.service.KeyPair
|
||||||
import com.vitorpamplona.amethyst.service.NostrLnZapPaymentResponseDataSource
|
import com.vitorpamplona.amethyst.service.NostrLnZapPaymentResponseDataSource
|
||||||
import com.vitorpamplona.amethyst.service.Persona
|
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
|
||||||
import com.vitorpamplona.amethyst.service.model.*
|
import com.vitorpamplona.amethyst.service.model.*
|
||||||
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
|
||||||
@@ -53,7 +53,7 @@ val KIND3_FOLLOWS = " All Follows "
|
|||||||
@OptIn(DelicateCoroutinesApi::class)
|
@OptIn(DelicateCoroutinesApi::class)
|
||||||
@Stable
|
@Stable
|
||||||
class Account(
|
class Account(
|
||||||
val loggedIn: Persona,
|
val keyPair: KeyPair,
|
||||||
|
|
||||||
var followingChannels: Set<String> = DefaultChannels, // deprecated
|
var followingChannels: Set<String> = DefaultChannels, // deprecated
|
||||||
var followingCommunities: Set<String> = setOf(), // deprecated
|
var followingCommunities: Set<String> = setOf(), // deprecated
|
||||||
@@ -99,7 +99,7 @@ class Account(
|
|||||||
)
|
)
|
||||||
|
|
||||||
val liveHiddenUsers: LiveData<LiveHiddenUsers> = live.combineWith(getBlockListNote().live().metadata) { localLive, liveMuteListEvent ->
|
val liveHiddenUsers: LiveData<LiveHiddenUsers> = live.combineWith(getBlockListNote().live().metadata) { localLive, liveMuteListEvent ->
|
||||||
val liveBlockedUsers = (liveMuteListEvent?.note?.event as? PeopleListEvent)?.publicAndPrivateUsers(loggedIn.privKey)
|
val liveBlockedUsers = (liveMuteListEvent?.note?.event as? PeopleListEvent)?.publicAndPrivateUsers(keyPair.privKey)
|
||||||
LiveHiddenUsers(
|
LiveHiddenUsers(
|
||||||
hiddenUsers = liveBlockedUsers ?: persistentSetOf(),
|
hiddenUsers = liveBlockedUsers ?: persistentSetOf(),
|
||||||
spammers = localLive?.account?.transientHiddenUsers ?: persistentSetOf(),
|
spammers = localLive?.account?.transientHiddenUsers ?: persistentSetOf(),
|
||||||
@@ -146,14 +146,14 @@ class Account(
|
|||||||
|
|
||||||
fun userProfile(): User {
|
fun userProfile(): User {
|
||||||
return userProfileCache ?: run {
|
return userProfileCache ?: run {
|
||||||
val myUser: User = LocalCache.getOrCreateUser(loggedIn.pubKey.toHexKey())
|
val myUser: User = LocalCache.getOrCreateUser(keyPair.pubKey.toHexKey())
|
||||||
userProfileCache = myUser
|
userProfileCache = myUser
|
||||||
myUser
|
myUser
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isWriteable(): Boolean {
|
fun isWriteable(): Boolean {
|
||||||
return loggedIn.privKey != null
|
return keyPair.privKey != null
|
||||||
}
|
}
|
||||||
|
|
||||||
fun sendNewRelayList(relays: Map<String, ContactListEvent.ReadWrite>) {
|
fun sendNewRelayList(relays: Map<String, ContactListEvent.ReadWrite>) {
|
||||||
@@ -165,7 +165,7 @@ class Account(
|
|||||||
val event = ContactListEvent.updateRelayList(
|
val event = ContactListEvent.updateRelayList(
|
||||||
earlierVersion = contactList,
|
earlierVersion = contactList,
|
||||||
relayUse = relays,
|
relayUse = relays,
|
||||||
privateKey = loggedIn.privKey!!
|
privateKey = keyPair.privKey!!
|
||||||
)
|
)
|
||||||
|
|
||||||
Client.send(event)
|
Client.send(event)
|
||||||
@@ -177,7 +177,7 @@ class Account(
|
|||||||
followCommunities = listOf(),
|
followCommunities = listOf(),
|
||||||
followEvents = DefaultChannels.toList(),
|
followEvents = DefaultChannels.toList(),
|
||||||
relayUse = relays,
|
relayUse = relays,
|
||||||
privateKey = loggedIn.privKey!!
|
privateKey = keyPair.privKey!!
|
||||||
)
|
)
|
||||||
|
|
||||||
// Keep this local to avoid erasing a good contact list.
|
// Keep this local to avoid erasing a good contact list.
|
||||||
@@ -189,8 +189,8 @@ class Account(
|
|||||||
fun sendNewUserMetadata(toString: String, identities: List<IdentityClaim>) {
|
fun sendNewUserMetadata(toString: String, identities: List<IdentityClaim>) {
|
||||||
if (!isWriteable()) return
|
if (!isWriteable()) return
|
||||||
|
|
||||||
loggedIn.privKey?.let {
|
keyPair.privKey?.let {
|
||||||
val event = MetadataEvent.create(toString, identities, loggedIn.privKey!!)
|
val event = MetadataEvent.create(toString, identities, keyPair.privKey!!)
|
||||||
Client.send(event)
|
Client.send(event)
|
||||||
LocalCache.consume(event)
|
LocalCache.consume(event)
|
||||||
}
|
}
|
||||||
@@ -224,7 +224,7 @@ class Account(
|
|||||||
val emojiUrl = EmojiUrl.decode(reaction)
|
val emojiUrl = EmojiUrl.decode(reaction)
|
||||||
if (emojiUrl != null) {
|
if (emojiUrl != null) {
|
||||||
note.event?.let {
|
note.event?.let {
|
||||||
val event = ReactionEvent.create(emojiUrl, it, loggedIn.privKey!!)
|
val event = ReactionEvent.create(emojiUrl, it, keyPair.privKey!!)
|
||||||
Client.send(event)
|
Client.send(event)
|
||||||
LocalCache.consume(event)
|
LocalCache.consume(event)
|
||||||
}
|
}
|
||||||
@@ -234,7 +234,7 @@ class Account(
|
|||||||
}
|
}
|
||||||
|
|
||||||
note.event?.let {
|
note.event?.let {
|
||||||
val event = ReactionEvent.create(reaction, it, loggedIn.privKey!!)
|
val event = ReactionEvent.create(reaction, it, keyPair.privKey!!)
|
||||||
Client.send(event)
|
Client.send(event)
|
||||||
LocalCache.consume(event)
|
LocalCache.consume(event)
|
||||||
}
|
}
|
||||||
@@ -248,7 +248,7 @@ class Account(
|
|||||||
event,
|
event,
|
||||||
userProfile().latestContactList?.relays()?.keys?.ifEmpty { null }
|
userProfile().latestContactList?.relays()?.keys?.ifEmpty { null }
|
||||||
?: localRelays.map { it.url }.toSet(),
|
?: localRelays.map { it.url }.toSet(),
|
||||||
loggedIn.privKey!!,
|
keyPair.privKey!!,
|
||||||
pollOption,
|
pollOption,
|
||||||
message,
|
message,
|
||||||
zapType
|
zapType
|
||||||
@@ -262,18 +262,18 @@ class Account(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun isNIP47Author(pubkeyHex: String?): Boolean {
|
fun isNIP47Author(pubkeyHex: String?): Boolean {
|
||||||
val privKey = zapPaymentRequest?.secret?.hexToByteArray() ?: loggedIn.privKey
|
val privKey = zapPaymentRequest?.secret?.hexToByteArray() ?: keyPair.privKey
|
||||||
|
|
||||||
if (privKey == null) return false
|
if (privKey == null) return false
|
||||||
|
|
||||||
val pubKey = Utils.pubkeyCreate(privKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privKey).toHexKey()
|
||||||
return (pubKey == pubkeyHex)
|
return (pubKey == pubkeyHex)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun decryptZapPaymentResponseEvent(zapResponseEvent: LnZapPaymentResponseEvent): Response? {
|
fun decryptZapPaymentResponseEvent(zapResponseEvent: LnZapPaymentResponseEvent): Response? {
|
||||||
val myNip47 = zapPaymentRequest ?: return null
|
val myNip47 = zapPaymentRequest ?: return null
|
||||||
|
|
||||||
val privKey = myNip47.secret?.hexToByteArray() ?: loggedIn.privKey
|
val privKey = myNip47.secret?.hexToByteArray() ?: keyPair.privKey
|
||||||
val pubKey = myNip47.pubKeyHex.hexToByteArray()
|
val pubKey = myNip47.pubKeyHex.hexToByteArray()
|
||||||
|
|
||||||
if (privKey == null) return null
|
if (privKey == null) return null
|
||||||
@@ -286,7 +286,7 @@ class Account(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun calculateZappedAmount(zappedNote: Note?): BigDecimal {
|
fun calculateZappedAmount(zappedNote: Note?): BigDecimal {
|
||||||
val privKey = zapPaymentRequest?.secret?.hexToByteArray() ?: loggedIn.privKey
|
val privKey = zapPaymentRequest?.secret?.hexToByteArray() ?: keyPair.privKey
|
||||||
val pubKey = zapPaymentRequest?.pubKeyHex?.hexToByteArray()
|
val pubKey = zapPaymentRequest?.pubKeyHex?.hexToByteArray()
|
||||||
return zappedNote?.zappedAmount(privKey, pubKey) ?: BigDecimal.ZERO
|
return zappedNote?.zappedAmount(privKey, pubKey) ?: BigDecimal.ZERO
|
||||||
}
|
}
|
||||||
@@ -295,13 +295,13 @@ class Account(
|
|||||||
if (!isWriteable()) return
|
if (!isWriteable()) return
|
||||||
|
|
||||||
zapPaymentRequest?.let { nip47 ->
|
zapPaymentRequest?.let { nip47 ->
|
||||||
val event = LnZapPaymentRequestEvent.create(bolt11, nip47.pubKeyHex, nip47.secret?.hexToByteArray() ?: loggedIn.privKey!!)
|
val event = LnZapPaymentRequestEvent.create(bolt11, nip47.pubKeyHex, nip47.secret?.hexToByteArray() ?: keyPair.privKey!!)
|
||||||
|
|
||||||
val wcListener = NostrLnZapPaymentResponseDataSource(
|
val wcListener = NostrLnZapPaymentResponseDataSource(
|
||||||
fromServiceHex = nip47.pubKeyHex,
|
fromServiceHex = nip47.pubKeyHex,
|
||||||
toUserHex = event.pubKey,
|
toUserHex = event.pubKey,
|
||||||
replyingToHex = event.id,
|
replyingToHex = event.id,
|
||||||
authSigningKey = nip47.secret?.hexToByteArray() ?: loggedIn.privKey!!
|
authSigningKey = nip47.secret?.hexToByteArray() ?: keyPair.privKey!!
|
||||||
)
|
)
|
||||||
wcListener.start()
|
wcListener.start()
|
||||||
|
|
||||||
@@ -329,7 +329,7 @@ class Account(
|
|||||||
return LnZapRequestEvent.create(
|
return LnZapRequestEvent.create(
|
||||||
userPubKeyHex,
|
userPubKeyHex,
|
||||||
userProfile().latestContactList?.relays()?.keys?.ifEmpty { null } ?: localRelays.map { it.url }.toSet(),
|
userProfile().latestContactList?.relays()?.keys?.ifEmpty { null } ?: localRelays.map { it.url }.toSet(),
|
||||||
loggedIn.privKey!!,
|
keyPair.privKey!!,
|
||||||
message,
|
message,
|
||||||
zapType
|
zapType
|
||||||
)
|
)
|
||||||
@@ -344,13 +344,13 @@ class Account(
|
|||||||
}
|
}
|
||||||
|
|
||||||
note.event?.let {
|
note.event?.let {
|
||||||
val event = ReactionEvent.createWarning(it, loggedIn.privKey!!)
|
val event = ReactionEvent.createWarning(it, keyPair.privKey!!)
|
||||||
Client.send(event)
|
Client.send(event)
|
||||||
LocalCache.consume(event)
|
LocalCache.consume(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
note.event?.let {
|
note.event?.let {
|
||||||
val event = ReportEvent.create(it, type, loggedIn.privKey!!, content = content)
|
val event = ReportEvent.create(it, type, keyPair.privKey!!, content = content)
|
||||||
Client.send(event)
|
Client.send(event)
|
||||||
LocalCache.consume(event, null)
|
LocalCache.consume(event, null)
|
||||||
}
|
}
|
||||||
@@ -364,7 +364,7 @@ class Account(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val event = ReportEvent.create(user.pubkeyHex, type, loggedIn.privKey!!)
|
val event = ReportEvent.create(user.pubkeyHex, type, keyPair.privKey!!)
|
||||||
Client.send(event)
|
Client.send(event)
|
||||||
LocalCache.consume(event, null)
|
LocalCache.consume(event, null)
|
||||||
}
|
}
|
||||||
@@ -379,7 +379,7 @@ class Account(
|
|||||||
val myNotes = notes.filter { it.author == userProfile() }.map { it.idHex }
|
val myNotes = notes.filter { it.author == userProfile() }.map { it.idHex }
|
||||||
|
|
||||||
if (myNotes.isNotEmpty()) {
|
if (myNotes.isNotEmpty()) {
|
||||||
val event = DeletionEvent.create(myNotes, loggedIn.privKey!!)
|
val event = DeletionEvent.create(myNotes, keyPair.privKey!!)
|
||||||
Client.send(event)
|
Client.send(event)
|
||||||
LocalCache.consume(event)
|
LocalCache.consume(event)
|
||||||
}
|
}
|
||||||
@@ -388,7 +388,7 @@ class Account(
|
|||||||
fun createHTTPAuthorization(url: String, method: String, body: String? = null): HTTPAuthorizationEvent? {
|
fun createHTTPAuthorization(url: String, method: String, body: String? = null): HTTPAuthorizationEvent? {
|
||||||
if (!isWriteable()) return null
|
if (!isWriteable()) return null
|
||||||
|
|
||||||
return HTTPAuthorizationEvent.create(url, method, body, loggedIn.privKey!!)
|
return HTTPAuthorizationEvent.create(url, method, body, keyPair.privKey!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun boost(note: Note) {
|
fun boost(note: Note) {
|
||||||
@@ -401,11 +401,11 @@ class Account(
|
|||||||
|
|
||||||
note.event?.let {
|
note.event?.let {
|
||||||
if (it.kind() == 1) {
|
if (it.kind() == 1) {
|
||||||
val event = RepostEvent.create(it, loggedIn.privKey!!)
|
val event = RepostEvent.create(it, keyPair.privKey!!)
|
||||||
Client.send(event)
|
Client.send(event)
|
||||||
LocalCache.consume(event)
|
LocalCache.consume(event)
|
||||||
} else {
|
} else {
|
||||||
val event = GenericRepostEvent.create(it, loggedIn.privKey!!)
|
val event = GenericRepostEvent.create(it, keyPair.privKey!!)
|
||||||
Client.send(event)
|
Client.send(event)
|
||||||
LocalCache.consume(event)
|
LocalCache.consume(event)
|
||||||
}
|
}
|
||||||
@@ -426,7 +426,7 @@ class Account(
|
|||||||
if (followingCommunities.isNotEmpty()) {
|
if (followingCommunities.isNotEmpty()) {
|
||||||
followingCommunities.forEach {
|
followingCommunities.forEach {
|
||||||
ATag.parse(it, null)?.let {
|
ATag.parse(it, null)?.let {
|
||||||
returningContactList = ContactListEvent.followAddressableEvent(returningContactList, it, loggedIn.privKey!!)
|
returningContactList = ContactListEvent.followAddressableEvent(returningContactList, it, keyPair.privKey!!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
followingCommunities = emptySet()
|
followingCommunities = emptySet()
|
||||||
@@ -434,7 +434,7 @@ class Account(
|
|||||||
|
|
||||||
if (followingChannels.isNotEmpty()) {
|
if (followingChannels.isNotEmpty()) {
|
||||||
followingChannels.forEach {
|
followingChannels.forEach {
|
||||||
returningContactList = ContactListEvent.followEvent(returningContactList, it, loggedIn.privKey!!)
|
returningContactList = ContactListEvent.followEvent(returningContactList, it, keyPair.privKey!!)
|
||||||
}
|
}
|
||||||
followingChannels = emptySet()
|
followingChannels = emptySet()
|
||||||
}
|
}
|
||||||
@@ -448,7 +448,7 @@ class Account(
|
|||||||
val contactList = migrateCommunitiesAndChannelsIfNeeded(userProfile().latestContactList)
|
val contactList = migrateCommunitiesAndChannelsIfNeeded(userProfile().latestContactList)
|
||||||
|
|
||||||
val event = if (contactList != null) {
|
val event = if (contactList != null) {
|
||||||
ContactListEvent.followUser(contactList, user.pubkeyHex, loggedIn.privKey!!)
|
ContactListEvent.followUser(contactList, user.pubkeyHex, keyPair.privKey!!)
|
||||||
} else {
|
} else {
|
||||||
ContactListEvent.createFromScratch(
|
ContactListEvent.createFromScratch(
|
||||||
followUsers = listOf(Contact(user.pubkeyHex, null)),
|
followUsers = listOf(Contact(user.pubkeyHex, null)),
|
||||||
@@ -456,7 +456,7 @@ class Account(
|
|||||||
followCommunities = emptyList(),
|
followCommunities = emptyList(),
|
||||||
followEvents = DefaultChannels.toList(),
|
followEvents = DefaultChannels.toList(),
|
||||||
relayUse = Constants.defaultRelays.associate { it.url to ContactListEvent.ReadWrite(it.read, it.write) },
|
relayUse = Constants.defaultRelays.associate { it.url to ContactListEvent.ReadWrite(it.read, it.write) },
|
||||||
privateKey = loggedIn.privKey!!
|
privateKey = keyPair.privKey!!
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -470,7 +470,7 @@ class Account(
|
|||||||
val contactList = migrateCommunitiesAndChannelsIfNeeded(userProfile().latestContactList)
|
val contactList = migrateCommunitiesAndChannelsIfNeeded(userProfile().latestContactList)
|
||||||
|
|
||||||
val event = if (contactList != null) {
|
val event = if (contactList != null) {
|
||||||
ContactListEvent.followEvent(contactList, channel.idHex, loggedIn.privKey!!)
|
ContactListEvent.followEvent(contactList, channel.idHex, keyPair.privKey!!)
|
||||||
} else {
|
} else {
|
||||||
ContactListEvent.createFromScratch(
|
ContactListEvent.createFromScratch(
|
||||||
followUsers = emptyList(),
|
followUsers = emptyList(),
|
||||||
@@ -478,7 +478,7 @@ class Account(
|
|||||||
followCommunities = emptyList(),
|
followCommunities = emptyList(),
|
||||||
followEvents = DefaultChannels.toList().plus(channel.idHex),
|
followEvents = DefaultChannels.toList().plus(channel.idHex),
|
||||||
relayUse = Constants.defaultRelays.associate { it.url to ContactListEvent.ReadWrite(it.read, it.write) },
|
relayUse = Constants.defaultRelays.associate { it.url to ContactListEvent.ReadWrite(it.read, it.write) },
|
||||||
privateKey = loggedIn.privKey!!
|
privateKey = keyPair.privKey!!
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -492,7 +492,7 @@ class Account(
|
|||||||
val contactList = migrateCommunitiesAndChannelsIfNeeded(userProfile().latestContactList)
|
val contactList = migrateCommunitiesAndChannelsIfNeeded(userProfile().latestContactList)
|
||||||
|
|
||||||
val event = if (contactList != null) {
|
val event = if (contactList != null) {
|
||||||
ContactListEvent.followAddressableEvent(contactList, community.address, loggedIn.privKey!!)
|
ContactListEvent.followAddressableEvent(contactList, community.address, keyPair.privKey!!)
|
||||||
} else {
|
} else {
|
||||||
val relays = Constants.defaultRelays.associate { it.url to ContactListEvent.ReadWrite(it.read, it.write) }
|
val relays = Constants.defaultRelays.associate { it.url to ContactListEvent.ReadWrite(it.read, it.write) }
|
||||||
ContactListEvent.createFromScratch(
|
ContactListEvent.createFromScratch(
|
||||||
@@ -501,7 +501,7 @@ class Account(
|
|||||||
followCommunities = listOf(community.address),
|
followCommunities = listOf(community.address),
|
||||||
followEvents = DefaultChannels.toList(),
|
followEvents = DefaultChannels.toList(),
|
||||||
relayUse = relays,
|
relayUse = relays,
|
||||||
privateKey = loggedIn.privKey!!
|
privateKey = keyPair.privKey!!
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -518,7 +518,7 @@ class Account(
|
|||||||
ContactListEvent.followHashtag(
|
ContactListEvent.followHashtag(
|
||||||
contactList,
|
contactList,
|
||||||
tag,
|
tag,
|
||||||
loggedIn.privKey!!
|
keyPair.privKey!!
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
ContactListEvent.createFromScratch(
|
ContactListEvent.createFromScratch(
|
||||||
@@ -527,7 +527,7 @@ class Account(
|
|||||||
followCommunities = emptyList(),
|
followCommunities = emptyList(),
|
||||||
followEvents = DefaultChannels.toList(),
|
followEvents = DefaultChannels.toList(),
|
||||||
relayUse = Constants.defaultRelays.associate { it.url to ContactListEvent.ReadWrite(it.read, it.write) },
|
relayUse = Constants.defaultRelays.associate { it.url to ContactListEvent.ReadWrite(it.read, it.write) },
|
||||||
privateKey = loggedIn.privKey!!
|
privateKey = keyPair.privKey!!
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -544,7 +544,7 @@ class Account(
|
|||||||
val event = ContactListEvent.unfollowUser(
|
val event = ContactListEvent.unfollowUser(
|
||||||
contactList,
|
contactList,
|
||||||
user.pubkeyHex,
|
user.pubkeyHex,
|
||||||
loggedIn.privKey!!
|
keyPair.privKey!!
|
||||||
)
|
)
|
||||||
|
|
||||||
Client.send(event)
|
Client.send(event)
|
||||||
@@ -561,7 +561,7 @@ class Account(
|
|||||||
val event = ContactListEvent.unfollowHashtag(
|
val event = ContactListEvent.unfollowHashtag(
|
||||||
contactList,
|
contactList,
|
||||||
tag,
|
tag,
|
||||||
loggedIn.privKey!!
|
keyPair.privKey!!
|
||||||
)
|
)
|
||||||
|
|
||||||
Client.send(event)
|
Client.send(event)
|
||||||
@@ -578,7 +578,7 @@ class Account(
|
|||||||
val event = ContactListEvent.unfollowEvent(
|
val event = ContactListEvent.unfollowEvent(
|
||||||
contactList,
|
contactList,
|
||||||
channel.idHex,
|
channel.idHex,
|
||||||
loggedIn.privKey!!
|
keyPair.privKey!!
|
||||||
)
|
)
|
||||||
|
|
||||||
Client.send(event)
|
Client.send(event)
|
||||||
@@ -595,7 +595,7 @@ class Account(
|
|||||||
val event = ContactListEvent.unfollowAddressableEvent(
|
val event = ContactListEvent.unfollowAddressableEvent(
|
||||||
contactList,
|
contactList,
|
||||||
community.address,
|
community.address,
|
||||||
loggedIn.privKey!!
|
keyPair.privKey!!
|
||||||
)
|
)
|
||||||
|
|
||||||
Client.send(event)
|
Client.send(event)
|
||||||
@@ -609,7 +609,7 @@ class Account(
|
|||||||
val data = FileStorageEvent.create(
|
val data = FileStorageEvent.create(
|
||||||
mimeType = headerInfo.mimeType ?: "",
|
mimeType = headerInfo.mimeType ?: "",
|
||||||
data = byteArray,
|
data = byteArray,
|
||||||
privateKey = loggedIn.privKey!!
|
privateKey = keyPair.privKey!!
|
||||||
)
|
)
|
||||||
|
|
||||||
val signedEvent = FileStorageHeaderEvent.create(
|
val signedEvent = FileStorageHeaderEvent.create(
|
||||||
@@ -621,7 +621,7 @@ class Account(
|
|||||||
blurhash = headerInfo.blurHash,
|
blurhash = headerInfo.blurHash,
|
||||||
description = headerInfo.description,
|
description = headerInfo.description,
|
||||||
sensitiveContent = headerInfo.sensitiveContent,
|
sensitiveContent = headerInfo.sensitiveContent,
|
||||||
privateKey = loggedIn.privKey!!
|
privateKey = keyPair.privKey!!
|
||||||
)
|
)
|
||||||
|
|
||||||
return Pair(data, signedEvent)
|
return Pair(data, signedEvent)
|
||||||
@@ -651,7 +651,7 @@ class Account(
|
|||||||
blurhash = headerInfo.blurHash,
|
blurhash = headerInfo.blurHash,
|
||||||
description = headerInfo.description,
|
description = headerInfo.description,
|
||||||
sensitiveContent = headerInfo.sensitiveContent,
|
sensitiveContent = headerInfo.sensitiveContent,
|
||||||
privateKey = loggedIn.privKey!!
|
privateKey = keyPair.privKey!!
|
||||||
)
|
)
|
||||||
|
|
||||||
Client.send(signedEvent, relayList = relayList)
|
Client.send(signedEvent, relayList = relayList)
|
||||||
@@ -691,7 +691,7 @@ class Account(
|
|||||||
replyingTo = replyingTo,
|
replyingTo = replyingTo,
|
||||||
root = root,
|
root = root,
|
||||||
directMentions = directMentions,
|
directMentions = directMentions,
|
||||||
privateKey = loggedIn.privKey!!
|
privateKey = keyPair.privKey!!
|
||||||
)
|
)
|
||||||
|
|
||||||
Client.send(signedEvent, relayList = relayList)
|
Client.send(signedEvent, relayList = relayList)
|
||||||
@@ -723,7 +723,7 @@ class Account(
|
|||||||
replyTos = repliesToHex,
|
replyTos = repliesToHex,
|
||||||
mentions = mentionsHex,
|
mentions = mentionsHex,
|
||||||
addresses = addresses,
|
addresses = addresses,
|
||||||
privateKey = loggedIn.privKey!!,
|
privateKey = keyPair.privKey!!,
|
||||||
pollOptions = pollOptions,
|
pollOptions = pollOptions,
|
||||||
valueMaximum = valueMaximum,
|
valueMaximum = valueMaximum,
|
||||||
valueMinimum = valueMinimum,
|
valueMinimum = valueMinimum,
|
||||||
@@ -753,7 +753,7 @@ class Account(
|
|||||||
zapReceiver = zapReceiver,
|
zapReceiver = zapReceiver,
|
||||||
markAsSensitive = wantsToMarkAsSensitive,
|
markAsSensitive = wantsToMarkAsSensitive,
|
||||||
zapRaiserAmount = zapRaiserAmount,
|
zapRaiserAmount = zapRaiserAmount,
|
||||||
privateKey = loggedIn.privKey!!
|
privateKey = keyPair.privKey!!
|
||||||
)
|
)
|
||||||
Client.send(signedEvent)
|
Client.send(signedEvent)
|
||||||
LocalCache.consume(signedEvent, null)
|
LocalCache.consume(signedEvent, null)
|
||||||
@@ -774,7 +774,7 @@ class Account(
|
|||||||
zapReceiver = zapReceiver,
|
zapReceiver = zapReceiver,
|
||||||
markAsSensitive = wantsToMarkAsSensitive,
|
markAsSensitive = wantsToMarkAsSensitive,
|
||||||
zapRaiserAmount = zapRaiserAmount,
|
zapRaiserAmount = zapRaiserAmount,
|
||||||
privateKey = loggedIn.privKey!!
|
privateKey = keyPair.privKey!!
|
||||||
)
|
)
|
||||||
Client.send(signedEvent)
|
Client.send(signedEvent)
|
||||||
LocalCache.consume(signedEvent, null)
|
LocalCache.consume(signedEvent, null)
|
||||||
@@ -795,7 +795,7 @@ class Account(
|
|||||||
zapReceiver = zapReceiver,
|
zapReceiver = zapReceiver,
|
||||||
markAsSensitive = wantsToMarkAsSensitive,
|
markAsSensitive = wantsToMarkAsSensitive,
|
||||||
zapRaiserAmount = zapRaiserAmount,
|
zapRaiserAmount = zapRaiserAmount,
|
||||||
privateKey = loggedIn.privKey!!,
|
privateKey = keyPair.privKey!!,
|
||||||
advertiseNip18 = false
|
advertiseNip18 = false
|
||||||
)
|
)
|
||||||
Client.send(signedEvent)
|
Client.send(signedEvent)
|
||||||
@@ -813,7 +813,7 @@ class Account(
|
|||||||
|
|
||||||
val event = ChannelCreateEvent.create(
|
val event = ChannelCreateEvent.create(
|
||||||
channelInfo = metadata,
|
channelInfo = metadata,
|
||||||
privateKey = loggedIn.privKey!!
|
privateKey = keyPair.privKey!!
|
||||||
)
|
)
|
||||||
|
|
||||||
Client.send(event)
|
Client.send(event)
|
||||||
@@ -834,7 +834,7 @@ class Account(
|
|||||||
|
|
||||||
val event = EmojiPackSelectionEvent.create(
|
val event = EmojiPackSelectionEvent.create(
|
||||||
noteEvent.taggedAddresses().filter { it != emojiListEvent.address() },
|
noteEvent.taggedAddresses().filter { it != emojiListEvent.address() },
|
||||||
loggedIn.privKey!!
|
keyPair.privKey!!
|
||||||
)
|
)
|
||||||
|
|
||||||
Client.send(event)
|
Client.send(event)
|
||||||
@@ -849,7 +849,7 @@ class Account(
|
|||||||
val event = if (usersEmojiList.event == null) {
|
val event = if (usersEmojiList.event == null) {
|
||||||
EmojiPackSelectionEvent.create(
|
EmojiPackSelectionEvent.create(
|
||||||
listOf(emojiListEvent.address()),
|
listOf(emojiListEvent.address()),
|
||||||
loggedIn.privKey!!
|
keyPair.privKey!!
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
val noteEvent = usersEmojiList.event
|
val noteEvent = usersEmojiList.event
|
||||||
@@ -861,7 +861,7 @@ class Account(
|
|||||||
|
|
||||||
EmojiPackSelectionEvent.create(
|
EmojiPackSelectionEvent.create(
|
||||||
noteEvent.taggedAddresses().plus(emojiListEvent.address()),
|
noteEvent.taggedAddresses().plus(emojiListEvent.address()),
|
||||||
loggedIn.privKey!!
|
keyPair.privKey!!
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -881,11 +881,11 @@ class Account(
|
|||||||
bookmarks?.taggedUsers() ?: emptyList(),
|
bookmarks?.taggedUsers() ?: emptyList(),
|
||||||
bookmarks?.taggedAddresses() ?: emptyList(),
|
bookmarks?.taggedAddresses() ?: emptyList(),
|
||||||
|
|
||||||
bookmarks?.privateTaggedEvents(privKey = loggedIn.privKey!!) ?: emptyList(),
|
bookmarks?.privateTaggedEvents(privKey = keyPair.privKey!!) ?: emptyList(),
|
||||||
bookmarks?.privateTaggedUsers(privKey = loggedIn.privKey!!) ?: emptyList(),
|
bookmarks?.privateTaggedUsers(privKey = keyPair.privKey!!) ?: emptyList(),
|
||||||
bookmarks?.privateTaggedAddresses(privKey = loggedIn.privKey!!)?.plus(note.address) ?: listOf(note.address),
|
bookmarks?.privateTaggedAddresses(privKey = keyPair.privKey!!)?.plus(note.address) ?: listOf(note.address),
|
||||||
|
|
||||||
loggedIn.privKey!!
|
keyPair.privKey!!
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
BookmarkListEvent.create(
|
BookmarkListEvent.create(
|
||||||
@@ -894,11 +894,11 @@ class Account(
|
|||||||
bookmarks?.taggedUsers() ?: emptyList(),
|
bookmarks?.taggedUsers() ?: emptyList(),
|
||||||
bookmarks?.taggedAddresses() ?: emptyList(),
|
bookmarks?.taggedAddresses() ?: emptyList(),
|
||||||
|
|
||||||
bookmarks?.privateTaggedEvents(privKey = loggedIn.privKey!!)?.plus(note.idHex) ?: listOf(note.idHex),
|
bookmarks?.privateTaggedEvents(privKey = keyPair.privKey!!)?.plus(note.idHex) ?: listOf(note.idHex),
|
||||||
bookmarks?.privateTaggedUsers(privKey = loggedIn.privKey!!) ?: emptyList(),
|
bookmarks?.privateTaggedUsers(privKey = keyPair.privKey!!) ?: emptyList(),
|
||||||
bookmarks?.privateTaggedAddresses(privKey = loggedIn.privKey!!) ?: emptyList(),
|
bookmarks?.privateTaggedAddresses(privKey = keyPair.privKey!!) ?: emptyList(),
|
||||||
|
|
||||||
loggedIn.privKey!!
|
keyPair.privKey!!
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -918,11 +918,11 @@ class Account(
|
|||||||
bookmarks?.taggedUsers() ?: emptyList(),
|
bookmarks?.taggedUsers() ?: emptyList(),
|
||||||
bookmarks?.taggedAddresses()?.plus(note.address) ?: listOf(note.address),
|
bookmarks?.taggedAddresses()?.plus(note.address) ?: listOf(note.address),
|
||||||
|
|
||||||
bookmarks?.privateTaggedEvents(privKey = loggedIn.privKey!!) ?: emptyList(),
|
bookmarks?.privateTaggedEvents(privKey = keyPair.privKey!!) ?: emptyList(),
|
||||||
bookmarks?.privateTaggedUsers(privKey = loggedIn.privKey!!) ?: emptyList(),
|
bookmarks?.privateTaggedUsers(privKey = keyPair.privKey!!) ?: emptyList(),
|
||||||
bookmarks?.privateTaggedAddresses(privKey = loggedIn.privKey!!) ?: emptyList(),
|
bookmarks?.privateTaggedAddresses(privKey = keyPair.privKey!!) ?: emptyList(),
|
||||||
|
|
||||||
loggedIn.privKey!!
|
keyPair.privKey!!
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
BookmarkListEvent.create(
|
BookmarkListEvent.create(
|
||||||
@@ -931,11 +931,11 @@ class Account(
|
|||||||
bookmarks?.taggedUsers() ?: emptyList(),
|
bookmarks?.taggedUsers() ?: emptyList(),
|
||||||
bookmarks?.taggedAddresses() ?: emptyList(),
|
bookmarks?.taggedAddresses() ?: emptyList(),
|
||||||
|
|
||||||
bookmarks?.privateTaggedEvents(privKey = loggedIn.privKey!!) ?: emptyList(),
|
bookmarks?.privateTaggedEvents(privKey = keyPair.privKey!!) ?: emptyList(),
|
||||||
bookmarks?.privateTaggedUsers(privKey = loggedIn.privKey!!) ?: emptyList(),
|
bookmarks?.privateTaggedUsers(privKey = keyPair.privKey!!) ?: emptyList(),
|
||||||
bookmarks?.privateTaggedAddresses(privKey = loggedIn.privKey!!) ?: emptyList(),
|
bookmarks?.privateTaggedAddresses(privKey = keyPair.privKey!!) ?: emptyList(),
|
||||||
|
|
||||||
loggedIn.privKey!!
|
keyPair.privKey!!
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -955,11 +955,11 @@ class Account(
|
|||||||
bookmarks?.taggedUsers() ?: emptyList(),
|
bookmarks?.taggedUsers() ?: emptyList(),
|
||||||
bookmarks?.taggedAddresses() ?: emptyList(),
|
bookmarks?.taggedAddresses() ?: emptyList(),
|
||||||
|
|
||||||
bookmarks?.privateTaggedEvents(privKey = loggedIn.privKey!!) ?: emptyList(),
|
bookmarks?.privateTaggedEvents(privKey = keyPair.privKey!!) ?: emptyList(),
|
||||||
bookmarks?.privateTaggedUsers(privKey = loggedIn.privKey!!) ?: emptyList(),
|
bookmarks?.privateTaggedUsers(privKey = keyPair.privKey!!) ?: emptyList(),
|
||||||
bookmarks?.privateTaggedAddresses(privKey = loggedIn.privKey!!)?.minus(note.address) ?: listOf(),
|
bookmarks?.privateTaggedAddresses(privKey = keyPair.privKey!!)?.minus(note.address) ?: listOf(),
|
||||||
|
|
||||||
loggedIn.privKey!!
|
keyPair.privKey!!
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
BookmarkListEvent.create(
|
BookmarkListEvent.create(
|
||||||
@@ -968,11 +968,11 @@ class Account(
|
|||||||
bookmarks?.taggedUsers() ?: emptyList(),
|
bookmarks?.taggedUsers() ?: emptyList(),
|
||||||
bookmarks?.taggedAddresses() ?: emptyList(),
|
bookmarks?.taggedAddresses() ?: emptyList(),
|
||||||
|
|
||||||
bookmarks?.privateTaggedEvents(privKey = loggedIn.privKey!!)?.minus(note.idHex) ?: listOf(),
|
bookmarks?.privateTaggedEvents(privKey = keyPair.privKey!!)?.minus(note.idHex) ?: listOf(),
|
||||||
bookmarks?.privateTaggedUsers(privKey = loggedIn.privKey!!) ?: emptyList(),
|
bookmarks?.privateTaggedUsers(privKey = keyPair.privKey!!) ?: emptyList(),
|
||||||
bookmarks?.privateTaggedAddresses(privKey = loggedIn.privKey!!) ?: emptyList(),
|
bookmarks?.privateTaggedAddresses(privKey = keyPair.privKey!!) ?: emptyList(),
|
||||||
|
|
||||||
loggedIn.privKey!!
|
keyPair.privKey!!
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -983,7 +983,7 @@ class Account(
|
|||||||
fun createAuthEvent(relay: Relay, challenge: String): RelayAuthEvent? {
|
fun createAuthEvent(relay: Relay, challenge: String): RelayAuthEvent? {
|
||||||
if (!isWriteable()) return null
|
if (!isWriteable()) return null
|
||||||
|
|
||||||
return RelayAuthEvent.create(relay.url, challenge, loggedIn.privKey!!)
|
return RelayAuthEvent.create(relay.url, challenge, keyPair.privKey!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun removePublicBookmark(note: Note) {
|
fun removePublicBookmark(note: Note) {
|
||||||
@@ -998,11 +998,11 @@ class Account(
|
|||||||
bookmarks?.taggedUsers() ?: emptyList(),
|
bookmarks?.taggedUsers() ?: emptyList(),
|
||||||
bookmarks?.taggedAddresses()?.minus(note.address),
|
bookmarks?.taggedAddresses()?.minus(note.address),
|
||||||
|
|
||||||
bookmarks?.privateTaggedEvents(privKey = loggedIn.privKey!!) ?: emptyList(),
|
bookmarks?.privateTaggedEvents(privKey = keyPair.privKey!!) ?: emptyList(),
|
||||||
bookmarks?.privateTaggedUsers(privKey = loggedIn.privKey!!) ?: emptyList(),
|
bookmarks?.privateTaggedUsers(privKey = keyPair.privKey!!) ?: emptyList(),
|
||||||
bookmarks?.privateTaggedAddresses(privKey = loggedIn.privKey!!) ?: emptyList(),
|
bookmarks?.privateTaggedAddresses(privKey = keyPair.privKey!!) ?: emptyList(),
|
||||||
|
|
||||||
loggedIn.privKey!!
|
keyPair.privKey!!
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
BookmarkListEvent.create(
|
BookmarkListEvent.create(
|
||||||
@@ -1011,11 +1011,11 @@ class Account(
|
|||||||
bookmarks?.taggedUsers() ?: emptyList(),
|
bookmarks?.taggedUsers() ?: emptyList(),
|
||||||
bookmarks?.taggedAddresses() ?: emptyList(),
|
bookmarks?.taggedAddresses() ?: emptyList(),
|
||||||
|
|
||||||
bookmarks?.privateTaggedEvents(privKey = loggedIn.privKey!!) ?: emptyList(),
|
bookmarks?.privateTaggedEvents(privKey = keyPair.privKey!!) ?: emptyList(),
|
||||||
bookmarks?.privateTaggedUsers(privKey = loggedIn.privKey!!) ?: emptyList(),
|
bookmarks?.privateTaggedUsers(privKey = keyPair.privKey!!) ?: emptyList(),
|
||||||
bookmarks?.privateTaggedAddresses(privKey = loggedIn.privKey!!) ?: emptyList(),
|
bookmarks?.privateTaggedAddresses(privKey = keyPair.privKey!!) ?: emptyList(),
|
||||||
|
|
||||||
loggedIn.privKey!!
|
keyPair.privKey!!
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1027,10 +1027,10 @@ class Account(
|
|||||||
if (!isWriteable()) return false
|
if (!isWriteable()) return false
|
||||||
|
|
||||||
if (note is AddressableNote) {
|
if (note is AddressableNote) {
|
||||||
return userProfile().latestBookmarkList?.privateTaggedAddresses(loggedIn.privKey!!)
|
return userProfile().latestBookmarkList?.privateTaggedAddresses(keyPair.privKey!!)
|
||||||
?.contains(note.address) == true
|
?.contains(note.address) == true
|
||||||
} else {
|
} else {
|
||||||
return userProfile().latestBookmarkList?.privateTaggedEvents(loggedIn.privKey!!)
|
return userProfile().latestBookmarkList?.privateTaggedEvents(keyPair.privKey!!)
|
||||||
?.contains(note.idHex) == true
|
?.contains(note.idHex) == true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1060,7 +1060,7 @@ class Account(
|
|||||||
var returningList: PeopleListEvent = latestList
|
var returningList: PeopleListEvent = latestList
|
||||||
|
|
||||||
if (hiddenUsers.isNotEmpty()) {
|
if (hiddenUsers.isNotEmpty()) {
|
||||||
returningList = PeopleListEvent.addUsers(returningList, hiddenUsers.toList(), true, loggedIn.privKey!!)
|
returningList = PeopleListEvent.addUsers(returningList, hiddenUsers.toList(), true, keyPair.privKey!!)
|
||||||
hiddenUsers = emptySet()
|
hiddenUsers = emptySet()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1075,14 +1075,14 @@ class Account(
|
|||||||
earlierVersion = blockList,
|
earlierVersion = blockList,
|
||||||
pubKeyHex = pubkeyHex,
|
pubKeyHex = pubkeyHex,
|
||||||
isPrivate = true,
|
isPrivate = true,
|
||||||
privateKey = loggedIn.privKey!!
|
privateKey = keyPair.privKey!!
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
PeopleListEvent.createListWithUser(
|
PeopleListEvent.createListWithUser(
|
||||||
name = PeopleListEvent.blockList,
|
name = PeopleListEvent.blockList,
|
||||||
pubKeyHex = pubkeyHex,
|
pubKeyHex = pubkeyHex,
|
||||||
isPrivate = true,
|
isPrivate = true,
|
||||||
privateKey = loggedIn.privKey!!
|
privateKey = keyPair.privKey!!
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1101,7 +1101,7 @@ class Account(
|
|||||||
earlierVersion = blockList,
|
earlierVersion = blockList,
|
||||||
pubKeyHex = pubkeyHex,
|
pubKeyHex = pubkeyHex,
|
||||||
isPrivate = true,
|
isPrivate = true,
|
||||||
privateKey = loggedIn.privKey!!
|
privateKey = keyPair.privKey!!
|
||||||
)
|
)
|
||||||
|
|
||||||
Client.send(event)
|
Client.send(event)
|
||||||
@@ -1171,7 +1171,7 @@ class Account(
|
|||||||
if (listName == GLOBAL_FOLLOWS) return null
|
if (listName == GLOBAL_FOLLOWS) return null
|
||||||
if (listName == KIND3_FOLLOWS) return userProfile().cachedFollowingKeySet()
|
if (listName == KIND3_FOLLOWS) return userProfile().cachedFollowingKeySet()
|
||||||
|
|
||||||
val privKey = loggedIn.privKey
|
val privKey = keyPair.privKey
|
||||||
|
|
||||||
return if (listName != null) {
|
return if (listName != null) {
|
||||||
val aTag = ATag(PeopleListEvent.kind, userProfile().pubkeyHex, listName, null).toTag()
|
val aTag = ATag(PeopleListEvent.kind, userProfile().pubkeyHex, listName, null).toTag()
|
||||||
@@ -1195,7 +1195,7 @@ class Account(
|
|||||||
if (listName == GLOBAL_FOLLOWS) return null
|
if (listName == GLOBAL_FOLLOWS) return null
|
||||||
if (listName == KIND3_FOLLOWS) return userProfile().cachedFollowingTagSet()
|
if (listName == KIND3_FOLLOWS) return userProfile().cachedFollowingTagSet()
|
||||||
|
|
||||||
val privKey = loggedIn.privKey
|
val privKey = keyPair.privKey
|
||||||
|
|
||||||
return if (listName != null) {
|
return if (listName != null) {
|
||||||
val aTag = ATag(PeopleListEvent.kind, userProfile().pubkeyHex, listName, null).toTag()
|
val aTag = ATag(PeopleListEvent.kind, userProfile().pubkeyHex, listName, null).toTag()
|
||||||
@@ -1219,7 +1219,7 @@ class Account(
|
|||||||
if (listName == GLOBAL_FOLLOWS) return null
|
if (listName == GLOBAL_FOLLOWS) return null
|
||||||
if (listName == KIND3_FOLLOWS) return userProfile().cachedFollowingCommunitiesSet()
|
if (listName == KIND3_FOLLOWS) return userProfile().cachedFollowingCommunitiesSet()
|
||||||
|
|
||||||
val privKey = loggedIn.privKey
|
val privKey = keyPair.privKey
|
||||||
|
|
||||||
return if (listName != null) {
|
return if (listName != null) {
|
||||||
val aTag = ATag(PeopleListEvent.kind, userProfile().pubkeyHex, listName, null).toTag()
|
val aTag = ATag(PeopleListEvent.kind, userProfile().pubkeyHex, listName, null).toTag()
|
||||||
@@ -1256,7 +1256,7 @@ class Account(
|
|||||||
val event = ChannelMetadataEvent.create(
|
val event = ChannelMetadataEvent.create(
|
||||||
newChannelInfo = metadata,
|
newChannelInfo = metadata,
|
||||||
originalChannelIdHex = channel.idHex,
|
originalChannelIdHex = channel.idHex,
|
||||||
privateKey = loggedIn.privKey!!
|
privateKey = keyPair.privKey!!
|
||||||
)
|
)
|
||||||
|
|
||||||
Client.send(event)
|
Client.send(event)
|
||||||
@@ -1267,9 +1267,9 @@ class Account(
|
|||||||
|
|
||||||
fun decryptContent(note: Note): String? {
|
fun decryptContent(note: Note): String? {
|
||||||
val event = note.event
|
val event = note.event
|
||||||
return if (event is PrivateDmEvent && loggedIn.privKey != null) {
|
return if (event is PrivateDmEvent && keyPair.privKey != null) {
|
||||||
event.plainContent(loggedIn.privKey!!, event.talkingWith(userProfile().pubkeyHex).hexToByteArray())
|
event.plainContent(keyPair.privKey!!, event.talkingWith(userProfile().pubkeyHex).hexToByteArray())
|
||||||
} else if (event is LnZapRequestEvent && loggedIn.privKey != null) {
|
} else if (event is LnZapRequestEvent && keyPair.privKey != null) {
|
||||||
decryptZapContentAuthor(note)?.content()
|
decryptZapContentAuthor(note)?.content()
|
||||||
} else {
|
} else {
|
||||||
event?.content()
|
event?.content()
|
||||||
@@ -1278,7 +1278,7 @@ class Account(
|
|||||||
|
|
||||||
fun decryptZapContentAuthor(note: Note): Event? {
|
fun decryptZapContentAuthor(note: Note): Event? {
|
||||||
val event = note.event
|
val event = note.event
|
||||||
val loggedInPrivateKey = loggedIn.privKey
|
val loggedInPrivateKey = keyPair.privKey
|
||||||
|
|
||||||
return if (event is LnZapRequestEvent && loggedInPrivateKey != null && event.isPrivateZap()) {
|
return if (event is LnZapRequestEvent && loggedInPrivateKey != null && event.isPrivateZap()) {
|
||||||
val recipientPK = event.zappedAuthor().firstOrNull()
|
val recipientPK = event.zappedAuthor().firstOrNull()
|
||||||
@@ -1311,7 +1311,7 @@ class Account(
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (altPrivateKeyToUse != null && altPubkeyToUse != null) {
|
if (altPrivateKeyToUse != null && altPubkeyToUse != null) {
|
||||||
val altPubKeyFromPrivate = Utils.pubkeyCreate(altPrivateKeyToUse).toHexKey()
|
val altPubKeyFromPrivate = CryptoUtils.pubkeyCreate(altPrivateKeyToUse).toHexKey()
|
||||||
|
|
||||||
if (altPubKeyFromPrivate == event.pubKey) {
|
if (altPubKeyFromPrivate == event.pubKey) {
|
||||||
val result = event.getPrivateZapEvent(altPrivateKeyToUse, altPubkeyToUse)
|
val result = event.getPrivateZapEvent(altPrivateKeyToUse, altPubkeyToUse)
|
||||||
@@ -1413,7 +1413,7 @@ class Account(
|
|||||||
fun isHidden(userHex: String): Boolean {
|
fun isHidden(userHex: String): Boolean {
|
||||||
val blockList = getBlockList()
|
val blockList = getBlockList()
|
||||||
|
|
||||||
return (blockList?.publicAndPrivateUsers(loggedIn.privKey)?.contains(userHex) ?: false) || userHex in transientHiddenUsers
|
return (blockList?.publicAndPrivateUsers(keyPair.privKey)?.contains(userHex) ?: false) || userHex in transientHiddenUsers
|
||||||
}
|
}
|
||||||
|
|
||||||
fun followingKeySet(): Set<HexKey> {
|
fun followingKeySet(): Set<HexKey> {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.vitorpamplona.amethyst.model
|
package com.vitorpamplona.amethyst.model
|
||||||
|
|
||||||
import com.vitorpamplona.amethyst.service.Bech32
|
import com.vitorpamplona.amethyst.service.Bech32
|
||||||
import com.vitorpamplona.amethyst.service.Persona
|
import com.vitorpamplona.amethyst.service.KeyPair
|
||||||
import com.vitorpamplona.amethyst.service.bechToBytes
|
import com.vitorpamplona.amethyst.service.bechToBytes
|
||||||
import com.vitorpamplona.amethyst.service.nip19.Nip19
|
import com.vitorpamplona.amethyst.service.nip19.Nip19
|
||||||
import com.vitorpamplona.amethyst.service.toNpub
|
import com.vitorpamplona.amethyst.service.toNpub
|
||||||
@@ -41,7 +41,7 @@ fun decodePublicKey(key: String): ByteArray {
|
|||||||
val pubKeyParsed = parsed?.hex?.hexToByteArray()
|
val pubKeyParsed = parsed?.hex?.hexToByteArray()
|
||||||
|
|
||||||
return if (key.startsWith("nsec")) {
|
return if (key.startsWith("nsec")) {
|
||||||
Persona(privKey = key.bechToBytes()).pubKey
|
KeyPair(privKey = key.bechToBytes()).pubKey
|
||||||
} else if (pubKeyParsed != null) {
|
} else if (pubKeyParsed != null) {
|
||||||
pubKeyParsed
|
pubKeyParsed
|
||||||
} else {
|
} else {
|
||||||
@@ -55,7 +55,7 @@ fun decodePublicKeyAsHexOrNull(key: String): HexKey? {
|
|||||||
val pubKeyParsed = parsed?.hex
|
val pubKeyParsed = parsed?.hex
|
||||||
|
|
||||||
if (key.startsWith("nsec")) {
|
if (key.startsWith("nsec")) {
|
||||||
Persona(privKey = key.bechToBytes()).pubKey.toHexKey()
|
KeyPair(privKey = key.bechToBytes()).pubKey.toHexKey()
|
||||||
} else if (pubKeyParsed != null) {
|
} else if (pubKeyParsed != null) {
|
||||||
pubKeyParsed
|
pubKeyParsed
|
||||||
} else {
|
} else {
|
||||||
@@ -86,7 +86,7 @@ fun parseDirtyWordForKey(mightBeAKey: String): DirtyKeyInfo? {
|
|||||||
|
|
||||||
if (key.startsWith("nsec1", true)) {
|
if (key.startsWith("nsec1", true)) {
|
||||||
// Converts to npub
|
// Converts to npub
|
||||||
val pubkey = Nip19.uriToRoute(Persona(privKey = keyB32.bechToBytes()).pubKey.toNpub()) ?: return null
|
val pubkey = Nip19.uriToRoute(KeyPair(privKey = keyB32.bechToBytes()).pubKey.toNpub()) ?: return null
|
||||||
|
|
||||||
return DirtyKeyInfo(pubkey, restOfWord)
|
return DirtyKeyInfo(pubkey, restOfWord)
|
||||||
} else if (key.startsWith("npub1", true)) {
|
} else if (key.startsWith("npub1", true)) {
|
||||||
|
|||||||
+1
-1
@@ -9,7 +9,7 @@ import javax.crypto.Cipher
|
|||||||
import javax.crypto.spec.IvParameterSpec
|
import javax.crypto.spec.IvParameterSpec
|
||||||
import javax.crypto.spec.SecretKeySpec
|
import javax.crypto.spec.SecretKeySpec
|
||||||
|
|
||||||
object Utils {
|
object CryptoUtils {
|
||||||
private val sha256: MessageDigest = MessageDigest.getInstance("SHA-256")
|
private val sha256: MessageDigest = MessageDigest.getInstance("SHA-256")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
+5
-5
@@ -2,7 +2,7 @@ package com.vitorpamplona.amethyst.service
|
|||||||
|
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
|
|
||||||
class Persona(
|
class KeyPair(
|
||||||
privKey: ByteArray? = null,
|
privKey: ByteArray? = null,
|
||||||
pubKey: ByteArray? = null
|
pubKey: ByteArray? = null
|
||||||
) {
|
) {
|
||||||
@@ -13,8 +13,8 @@ class Persona(
|
|||||||
if (privKey == null) {
|
if (privKey == null) {
|
||||||
if (pubKey == null) {
|
if (pubKey == null) {
|
||||||
// create new, random keys
|
// create new, random keys
|
||||||
this.privKey = Utils.privkeyCreate()
|
this.privKey = CryptoUtils.privkeyCreate()
|
||||||
this.pubKey = Utils.pubkeyCreate(this.privKey)
|
this.pubKey = CryptoUtils.pubkeyCreate(this.privKey)
|
||||||
} else {
|
} else {
|
||||||
// this is a read-only account
|
// this is a read-only account
|
||||||
check(pubKey.size == 32)
|
check(pubKey.size == 32)
|
||||||
@@ -24,11 +24,11 @@ class Persona(
|
|||||||
} else {
|
} else {
|
||||||
// as private key is provided, ignore the public key and set keys according to private key
|
// as private key is provided, ignore the public key and set keys according to private key
|
||||||
this.privKey = privKey
|
this.privKey = privKey
|
||||||
this.pubKey = Utils.pubkeyCreate(privKey)
|
this.pubKey = CryptoUtils.pubkeyCreate(privKey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return "Persona(privateKey=${privKey?.toHexKey()}, publicKey=${pubKey.toHexKey()}"
|
return "KeyPair(privateKey=${privKey?.toHexKey()}, publicKey=${pubKey.toHexKey()}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
class AudioTrackEvent(
|
class AudioTrackEvent(
|
||||||
@@ -52,9 +52,9 @@ class AudioTrackEvent(
|
|||||||
subject?.let { listOf(SUBJECT, it) }
|
subject?.let { listOf(SUBJECT, it) }
|
||||||
)
|
)
|
||||||
|
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, "")
|
val id = generateId(pubKey, createdAt, kind, tags, "")
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return AudioTrackEvent(id.toHexKey(), pubKey, createdAt, tags, "", sig.toHexKey())
|
return AudioTrackEvent(id.toHexKey(), pubKey, createdAt, tags, "", sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
class BookmarkListEvent(
|
class BookmarkListEvent(
|
||||||
@@ -32,7 +32,7 @@ class BookmarkListEvent(
|
|||||||
privateKey: ByteArray,
|
privateKey: ByteArray,
|
||||||
createdAt: Long = TimeUtils.now()
|
createdAt: Long = TimeUtils.now()
|
||||||
): BookmarkListEvent {
|
): BookmarkListEvent {
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey)
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey)
|
||||||
val content = createPrivateTags(privEvents, privUsers, privAddresses, privateKey, pubKey)
|
val content = createPrivateTags(privEvents, privUsers, privAddresses, privateKey, pubKey)
|
||||||
|
|
||||||
val tags = mutableListOf<List<String>>()
|
val tags = mutableListOf<List<String>>()
|
||||||
@@ -49,7 +49,7 @@ class BookmarkListEvent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val id = generateId(pubKey.toHexKey(), createdAt, kind, tags, content)
|
val id = generateId(pubKey.toHexKey(), createdAt, kind, tags, content)
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return BookmarkListEvent(id.toHexKey(), pubKey.toHexKey(), createdAt, tags, content, sig.toHexKey())
|
return BookmarkListEvent(id.toHexKey(), pubKey.toHexKey(), createdAt, tags, content, sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
class ChannelCreateEvent(
|
class ChannelCreateEvent(
|
||||||
@@ -38,10 +38,10 @@ class ChannelCreateEvent(
|
|||||||
""
|
""
|
||||||
}
|
}
|
||||||
|
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
val tags = emptyList<List<String>>()
|
val tags = emptyList<List<String>>()
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, content)
|
val id = generateId(pubKey, createdAt, kind, tags, content)
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return ChannelCreateEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
return ChannelCreateEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -4,7 +4,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
class ChannelHideMessageEvent(
|
class ChannelHideMessageEvent(
|
||||||
@@ -27,14 +27,14 @@ class ChannelHideMessageEvent(
|
|||||||
const val kind = 43
|
const val kind = 43
|
||||||
|
|
||||||
fun create(reason: String, messagesToHide: List<String>?, privateKey: ByteArray, createdAt: Long = TimeUtils.now()): ChannelHideMessageEvent {
|
fun create(reason: String, messagesToHide: List<String>?, privateKey: ByteArray, createdAt: Long = TimeUtils.now()): ChannelHideMessageEvent {
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
val tags =
|
val tags =
|
||||||
messagesToHide?.map {
|
messagesToHide?.map {
|
||||||
listOf("e", it)
|
listOf("e", it)
|
||||||
} ?: emptyList()
|
} ?: emptyList()
|
||||||
|
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, reason)
|
val id = generateId(pubKey, createdAt, kind, tags, reason)
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return ChannelHideMessageEvent(id.toHexKey(), pubKey, createdAt, tags, reason, sig.toHexKey())
|
return ChannelHideMessageEvent(id.toHexKey(), pubKey, createdAt, tags, reason, sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
class ChannelMessageEvent(
|
class ChannelMessageEvent(
|
||||||
@@ -39,7 +39,7 @@ class ChannelMessageEvent(
|
|||||||
zapRaiserAmount: Long?
|
zapRaiserAmount: Long?
|
||||||
): ChannelMessageEvent {
|
): ChannelMessageEvent {
|
||||||
val content = message
|
val content = message
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
val tags = mutableListOf(
|
val tags = mutableListOf(
|
||||||
listOf("e", channel, "", "root")
|
listOf("e", channel, "", "root")
|
||||||
)
|
)
|
||||||
@@ -60,7 +60,7 @@ class ChannelMessageEvent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, content)
|
val id = generateId(pubKey, createdAt, kind, tags, content)
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return ChannelMessageEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
return ChannelMessageEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
class ChannelMetadataEvent(
|
class ChannelMetadataEvent(
|
||||||
@@ -37,10 +37,10 @@ class ChannelMetadataEvent(
|
|||||||
""
|
""
|
||||||
}
|
}
|
||||||
|
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
val tags = listOf(listOf("e", originalChannelIdHex, "", "root"))
|
val tags = listOf(listOf("e", originalChannelIdHex, "", "root"))
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, content)
|
val id = generateId(pubKey, createdAt, kind, tags, content)
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return ChannelMetadataEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
return ChannelMetadataEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
class ChannelMuteUserEvent(
|
class ChannelMuteUserEvent(
|
||||||
@@ -28,14 +28,14 @@ class ChannelMuteUserEvent(
|
|||||||
|
|
||||||
fun create(reason: String, usersToMute: List<String>?, privateKey: ByteArray, createdAt: Long = TimeUtils.now()): ChannelMuteUserEvent {
|
fun create(reason: String, usersToMute: List<String>?, privateKey: ByteArray, createdAt: Long = TimeUtils.now()): ChannelMuteUserEvent {
|
||||||
val content = reason
|
val content = reason
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
val tags =
|
val tags =
|
||||||
usersToMute?.map {
|
usersToMute?.map {
|
||||||
listOf("p", it)
|
listOf("p", it)
|
||||||
} ?: emptyList()
|
} ?: emptyList()
|
||||||
|
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, content)
|
val id = generateId(pubKey, createdAt, kind, tags, content)
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return ChannelMuteUserEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
return ChannelMuteUserEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
class ClassifiedsEvent(
|
class ClassifiedsEvent(
|
||||||
@@ -66,9 +66,9 @@ class ClassifiedsEvent(
|
|||||||
publishedAt?.let { tags.add(listOf("publishedAt", it.toString())) }
|
publishedAt?.let { tags.add(listOf("publishedAt", it.toString())) }
|
||||||
title?.let { tags.add(listOf("title", it)) }
|
title?.let { tags.add(listOf("title", it)) }
|
||||||
|
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, "")
|
val id = generateId(pubKey, createdAt, kind, tags, "")
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return ClassifiedsEvent(id.toHexKey(), pubKey, createdAt, tags, "", sig.toHexKey())
|
return ClassifiedsEvent(id.toHexKey(), pubKey, createdAt, tags, "", sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -4,7 +4,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
class CommunityDefinitionEvent(
|
class CommunityDefinitionEvent(
|
||||||
@@ -33,9 +33,9 @@ class CommunityDefinitionEvent(
|
|||||||
createdAt: Long = TimeUtils.now()
|
createdAt: Long = TimeUtils.now()
|
||||||
): CommunityDefinitionEvent {
|
): CommunityDefinitionEvent {
|
||||||
val tags = mutableListOf<List<String>>()
|
val tags = mutableListOf<List<String>>()
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, "")
|
val id = generateId(pubKey, createdAt, kind, tags, "")
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return CommunityDefinitionEvent(id.toHexKey(), pubKey, createdAt, tags, "", sig.toHexKey())
|
return CommunityDefinitionEvent(id.toHexKey(), pubKey, createdAt, tags, "", sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -5,7 +5,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
import com.vitorpamplona.amethyst.service.relays.Client
|
import com.vitorpamplona.amethyst.service.relays.Client
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@@ -53,10 +53,10 @@ class CommunityPostApprovalEvent(
|
|||||||
val replyToAuthor = listOf("p", approvedPost.pubKey())
|
val replyToAuthor = listOf("p", approvedPost.pubKey())
|
||||||
val kind = listOf("k", "${approvedPost.kind()}")
|
val kind = listOf("k", "${approvedPost.kind()}")
|
||||||
|
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
val tags: List<List<String>> = listOf(communities, replyToPost, replyToAuthor, kind)
|
val tags: List<List<String>> = listOf(communities, replyToPost, replyToAuthor, kind)
|
||||||
val id = generateId(pubKey, createdAt, GenericRepostEvent.kind, tags, content)
|
val id = generateId(pubKey, createdAt, GenericRepostEvent.kind, tags, content)
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return GenericRepostEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
return GenericRepostEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import com.vitorpamplona.amethyst.model.HexKey
|
|||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.decodePublicKey
|
import com.vitorpamplona.amethyst.model.decodePublicKey
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
data class Contact(val pubKeyHex: String, val relayUri: String?)
|
data class Contact(val pubKeyHex: String, val relayUri: String?)
|
||||||
@@ -224,9 +224,9 @@ class ContactListEvent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun create(content: String, tags: List<List<String>>, privateKey: ByteArray, createdAt: Long = TimeUtils.now()): ContactListEvent {
|
fun create(content: String, tags: List<List<String>>, privateKey: ByteArray, createdAt: Long = TimeUtils.now()): ContactListEvent {
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, content)
|
val id = generateId(pubKey, createdAt, kind, tags, content)
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return ContactListEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
return ContactListEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
class DeletionEvent(
|
class DeletionEvent(
|
||||||
@@ -22,10 +22,10 @@ class DeletionEvent(
|
|||||||
|
|
||||||
fun create(deleteEvents: List<String>, privateKey: ByteArray, createdAt: Long = TimeUtils.now()): DeletionEvent {
|
fun create(deleteEvents: List<String>, privateKey: ByteArray, createdAt: Long = TimeUtils.now()): DeletionEvent {
|
||||||
val content = ""
|
val content = ""
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
val tags = deleteEvents.map { listOf("e", it) }
|
val tags = deleteEvents.map { listOf("e", it) }
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, content)
|
val id = generateId(pubKey, createdAt, kind, tags, content)
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return DeletionEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
return DeletionEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
class EmojiPackEvent(
|
class EmojiPackEvent(
|
||||||
@@ -25,13 +25,13 @@ class EmojiPackEvent(
|
|||||||
createdAt: Long = TimeUtils.now()
|
createdAt: Long = TimeUtils.now()
|
||||||
): EmojiPackEvent {
|
): EmojiPackEvent {
|
||||||
val content = ""
|
val content = ""
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey)
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey)
|
||||||
|
|
||||||
val tags = mutableListOf<List<String>>()
|
val tags = mutableListOf<List<String>>()
|
||||||
tags.add(listOf("d", name))
|
tags.add(listOf("d", name))
|
||||||
|
|
||||||
val id = generateId(pubKey.toHexKey(), createdAt, kind, tags, content)
|
val id = generateId(pubKey.toHexKey(), createdAt, kind, tags, content)
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return EmojiPackEvent(id.toHexKey(), pubKey.toHexKey(), createdAt, tags, content, sig.toHexKey())
|
return EmojiPackEvent(id.toHexKey(), pubKey.toHexKey(), createdAt, tags, content, sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -4,7 +4,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
class EmojiPackSelectionEvent(
|
class EmojiPackSelectionEvent(
|
||||||
@@ -28,7 +28,7 @@ class EmojiPackSelectionEvent(
|
|||||||
createdAt: Long = TimeUtils.now()
|
createdAt: Long = TimeUtils.now()
|
||||||
): EmojiPackSelectionEvent {
|
): EmojiPackSelectionEvent {
|
||||||
val msg = ""
|
val msg = ""
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
val tags = mutableListOf<List<String>>()
|
val tags = mutableListOf<List<String>>()
|
||||||
|
|
||||||
listOfEmojiPacks?.forEach {
|
listOfEmojiPacks?.forEach {
|
||||||
@@ -36,7 +36,7 @@ class EmojiPackSelectionEvent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, msg)
|
val id = generateId(pubKey, createdAt, kind, tags, msg)
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return EmojiPackSelectionEvent(id.toHexKey(), pubKey, createdAt, tags, msg, sig.toHexKey())
|
return EmojiPackSelectionEvent(id.toHexKey(), pubKey, createdAt, tags, msg, sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import com.google.gson.annotations.SerializedName
|
|||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
import com.vitorpamplona.amethyst.service.nip19.Nip19
|
import com.vitorpamplona.amethyst.service.nip19.Nip19
|
||||||
import fr.acinq.secp256k1.Hex
|
import fr.acinq.secp256k1.Hex
|
||||||
import fr.acinq.secp256k1.Secp256k1
|
import fr.acinq.secp256k1.Secp256k1
|
||||||
@@ -340,9 +340,9 @@ open class Event(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun create(privateKey: ByteArray, kind: Int, tags: List<List<String>> = emptyList(), content: String = "", createdAt: Long = TimeUtils.now()): Event {
|
fun create(privateKey: ByteArray, kind: Int, tags: List<List<String>> = emptyList(), content: String = "", createdAt: Long = TimeUtils.now()): Event {
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
val id = Companion.generateId(pubKey, createdAt, kind, tags, content)
|
val id = Companion.generateId(pubKey, createdAt, kind, tags, content)
|
||||||
val sig = Utils.sign(id, privateKey).toHexKey()
|
val sig = CryptoUtils.sign(id, privateKey).toHexKey()
|
||||||
return Event(id.toHexKey(), pubKey, createdAt, kind, tags, content, sig)
|
return Event(id.toHexKey(), pubKey, createdAt, kind, tags, content, sig)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
class FileHeaderEvent(
|
class FileHeaderEvent(
|
||||||
@@ -74,9 +74,9 @@ class FileHeaderEvent(
|
|||||||
)
|
)
|
||||||
|
|
||||||
val content = description ?: ""
|
val content = description ?: ""
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, content)
|
val id = generateId(pubKey, createdAt, kind, tags, content)
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return FileHeaderEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
return FileHeaderEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
import java.util.Base64
|
import java.util.Base64
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@@ -51,9 +51,9 @@ class FileStorageEvent(
|
|||||||
)
|
)
|
||||||
|
|
||||||
val content = encode(data)
|
val content = encode(data)
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, content)
|
val id = generateId(pubKey, createdAt, kind, tags, content)
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return FileStorageEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
return FileStorageEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -4,7 +4,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
class FileStorageHeaderEvent(
|
class FileStorageHeaderEvent(
|
||||||
@@ -74,9 +74,9 @@ class FileStorageHeaderEvent(
|
|||||||
)
|
)
|
||||||
|
|
||||||
val content = description ?: ""
|
val content = description ?: ""
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, content)
|
val id = generateId(pubKey, createdAt, kind, tags, content)
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return FileStorageHeaderEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
return FileStorageHeaderEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.google.gson.reflect.TypeToken
|
import com.google.gson.reflect.TypeToken
|
||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.hexToByteArray
|
import com.vitorpamplona.amethyst.model.hexToByteArray
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
abstract class GeneralListEvent(
|
abstract class GeneralListEvent(
|
||||||
@@ -28,9 +28,9 @@ abstract class GeneralListEvent(
|
|||||||
if (content.isBlank()) return null
|
if (content.isBlank()) return null
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
val sharedSecret = Utils.getSharedSecret(privKey, pubKey.hexToByteArray())
|
val sharedSecret = CryptoUtils.getSharedSecret(privKey, pubKey.hexToByteArray())
|
||||||
|
|
||||||
return Utils.decrypt(content, sharedSecret)
|
return CryptoUtils.decrypt(content, sharedSecret)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.w("GeneralList", "Error decrypting the message ${e.message} for ${dTag()}")
|
Log.w("GeneralList", "Error decrypting the message ${e.message} for ${dTag()}")
|
||||||
null
|
null
|
||||||
@@ -90,7 +90,7 @@ abstract class GeneralListEvent(
|
|||||||
}
|
}
|
||||||
val msg = gson.toJson(privTags)
|
val msg = gson.toJson(privTags)
|
||||||
|
|
||||||
return Utils.encrypt(
|
return CryptoUtils.encrypt(
|
||||||
msg,
|
msg,
|
||||||
privateKey,
|
privateKey,
|
||||||
pubKey
|
pubKey
|
||||||
@@ -101,10 +101,10 @@ abstract class GeneralListEvent(
|
|||||||
privateTags: List<List<String>>? = null,
|
privateTags: List<List<String>>? = null,
|
||||||
privateKey: ByteArray
|
privateKey: ByteArray
|
||||||
): String {
|
): String {
|
||||||
return Utils.encrypt(
|
return CryptoUtils.encrypt(
|
||||||
msg = gson.toJson(privateTags),
|
msg = gson.toJson(privateTags),
|
||||||
privateKey = privateKey,
|
privateKey = privateKey,
|
||||||
pubKey = Utils.pubkeyCreate(privateKey)
|
pubKey = CryptoUtils.pubkeyCreate(privateKey)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
import com.vitorpamplona.amethyst.service.relays.Client
|
import com.vitorpamplona.amethyst.service.relays.Client
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@@ -35,7 +35,7 @@ class GenericRepostEvent(
|
|||||||
val replyToPost = listOf("e", boostedPost.id())
|
val replyToPost = listOf("e", boostedPost.id())
|
||||||
val replyToAuthor = listOf("p", boostedPost.pubKey())
|
val replyToAuthor = listOf("p", boostedPost.pubKey())
|
||||||
|
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
var tags: List<List<String>> = listOf(replyToPost, replyToAuthor)
|
var tags: List<List<String>> = listOf(replyToPost, replyToAuthor)
|
||||||
|
|
||||||
if (boostedPost is AddressableEvent) {
|
if (boostedPost is AddressableEvent) {
|
||||||
@@ -45,7 +45,7 @@ class GenericRepostEvent(
|
|||||||
tags = tags + listOf(listOf("k", "${boostedPost.kind()}"))
|
tags = tags + listOf(listOf("k", "${boostedPost.kind()}"))
|
||||||
|
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, content)
|
val id = generateId(pubKey, createdAt, kind, tags, content)
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return GenericRepostEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
return GenericRepostEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -4,7 +4,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
import java.security.MessageDigest
|
import java.security.MessageDigest
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@@ -40,9 +40,9 @@ class HTTPAuthorizationEvent(
|
|||||||
listOf("payload", hash)
|
listOf("payload", hash)
|
||||||
)
|
)
|
||||||
|
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, "")
|
val id = generateId(pubKey, createdAt, kind, tags, "")
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return HTTPAuthorizationEvent(id.toHexKey(), pubKey, createdAt, tags, "", sig.toHexKey())
|
return HTTPAuthorizationEvent(id.toHexKey(), pubKey, createdAt, tags, "", sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
class HighlightEvent(
|
class HighlightEvent(
|
||||||
@@ -30,10 +30,10 @@ class HighlightEvent(
|
|||||||
privateKey: ByteArray,
|
privateKey: ByteArray,
|
||||||
createdAt: Long = TimeUtils.now()
|
createdAt: Long = TimeUtils.now()
|
||||||
): PollNoteEvent {
|
): PollNoteEvent {
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
val tags = mutableListOf<List<String>>()
|
val tags = mutableListOf<List<String>>()
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, msg)
|
val id = generateId(pubKey, createdAt, kind, tags, msg)
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return PollNoteEvent(id.toHexKey(), pubKey, createdAt, tags, msg, sig.toHexKey())
|
return PollNoteEvent(id.toHexKey(), pubKey, createdAt, tags, msg, sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -4,7 +4,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
class LiveActivitiesChatMessageEvent(
|
class LiveActivitiesChatMessageEvent(
|
||||||
@@ -54,7 +54,7 @@ class LiveActivitiesChatMessageEvent(
|
|||||||
zapRaiserAmount: Long?
|
zapRaiserAmount: Long?
|
||||||
): LiveActivitiesChatMessageEvent {
|
): LiveActivitiesChatMessageEvent {
|
||||||
val content = message
|
val content = message
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
val tags = mutableListOf(
|
val tags = mutableListOf(
|
||||||
listOf("a", activity.toTag(), "", "root")
|
listOf("a", activity.toTag(), "", "root")
|
||||||
)
|
)
|
||||||
@@ -75,7 +75,7 @@ class LiveActivitiesChatMessageEvent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, content)
|
val id = generateId(pubKey, createdAt, kind, tags, content)
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return LiveActivitiesChatMessageEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
return LiveActivitiesChatMessageEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
class LiveActivitiesEvent(
|
class LiveActivitiesEvent(
|
||||||
@@ -51,9 +51,9 @@ class LiveActivitiesEvent(
|
|||||||
createdAt: Long = TimeUtils.now()
|
createdAt: Long = TimeUtils.now()
|
||||||
): LiveActivitiesEvent {
|
): LiveActivitiesEvent {
|
||||||
val tags = mutableListOf<List<String>>()
|
val tags = mutableListOf<List<String>>()
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, "")
|
val id = generateId(pubKey, createdAt, kind, tags, "")
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return LiveActivitiesEvent(id.toHexKey(), pubKey, createdAt, tags, "", sig.toHexKey())
|
return LiveActivitiesEvent(id.toHexKey(), pubKey, createdAt, tags, "", sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -10,7 +10,7 @@ import com.vitorpamplona.amethyst.model.HexKey
|
|||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.hexToByteArray
|
import com.vitorpamplona.amethyst.model.hexToByteArray
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
import java.lang.reflect.Type
|
import java.lang.reflect.Type
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@@ -35,9 +35,9 @@ class LnZapPaymentRequestEvent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
val sharedSecret = Utils.getSharedSecret(privKey, pubkey)
|
val sharedSecret = CryptoUtils.getSharedSecret(privKey, pubkey)
|
||||||
|
|
||||||
val jsonText = Utils.decrypt(content, sharedSecret)
|
val jsonText = CryptoUtils.decrypt(content, sharedSecret)
|
||||||
|
|
||||||
val payInvoiceMethod = gson.fromJson(jsonText, Request::class.java)
|
val payInvoiceMethod = gson.fromJson(jsonText, Request::class.java)
|
||||||
|
|
||||||
@@ -59,10 +59,10 @@ class LnZapPaymentRequestEvent(
|
|||||||
privateKey: ByteArray,
|
privateKey: ByteArray,
|
||||||
createdAt: Long = TimeUtils.now()
|
createdAt: Long = TimeUtils.now()
|
||||||
): LnZapPaymentRequestEvent {
|
): LnZapPaymentRequestEvent {
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey)
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey)
|
||||||
val serializedRequest = gson.toJson(PayInvoiceMethod.create(lnInvoice))
|
val serializedRequest = gson.toJson(PayInvoiceMethod.create(lnInvoice))
|
||||||
|
|
||||||
val content = Utils.encrypt(
|
val content = CryptoUtils.encrypt(
|
||||||
serializedRequest,
|
serializedRequest,
|
||||||
privateKey,
|
privateKey,
|
||||||
walletServicePubkey.hexToByteArray()
|
walletServicePubkey.hexToByteArray()
|
||||||
@@ -72,7 +72,7 @@ class LnZapPaymentRequestEvent(
|
|||||||
tags.add(listOf("p", walletServicePubkey))
|
tags.add(listOf("p", walletServicePubkey))
|
||||||
|
|
||||||
val id = generateId(pubKey.toHexKey(), createdAt, kind, tags, content)
|
val id = generateId(pubKey.toHexKey(), createdAt, kind, tags, content)
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return LnZapPaymentRequestEvent(id.toHexKey(), pubKey.toHexKey(), createdAt, tags, content, sig.toHexKey())
|
return LnZapPaymentRequestEvent(id.toHexKey(), pubKey.toHexKey(), createdAt, tags, content, sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -8,7 +8,7 @@ import com.google.gson.JsonElement
|
|||||||
import com.google.gson.JsonParseException
|
import com.google.gson.JsonParseException
|
||||||
import com.google.gson.annotations.SerializedName
|
import com.google.gson.annotations.SerializedName
|
||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
import java.lang.reflect.Type
|
import java.lang.reflect.Type
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@@ -30,9 +30,9 @@ class LnZapPaymentResponseEvent(
|
|||||||
|
|
||||||
private fun decrypt(privKey: ByteArray, pubKey: ByteArray): String? {
|
private fun decrypt(privKey: ByteArray, pubKey: ByteArray): String? {
|
||||||
return try {
|
return try {
|
||||||
val sharedSecret = Utils.getSharedSecret(privKey, pubKey)
|
val sharedSecret = CryptoUtils.getSharedSecret(privKey, pubKey)
|
||||||
|
|
||||||
val retVal = Utils.decrypt(content, sharedSecret)
|
val retVal = CryptoUtils.decrypt(content, sharedSecret)
|
||||||
|
|
||||||
if (retVal.startsWith(PrivateDmEvent.nip18Advertisement)) {
|
if (retVal.startsWith(PrivateDmEvent.nip18Advertisement)) {
|
||||||
retVal.substring(16)
|
retVal.substring(16)
|
||||||
|
|||||||
@@ -3,11 +3,10 @@ package com.vitorpamplona.amethyst.service.model
|
|||||||
import androidx.compose.runtime.Immutable
|
import androidx.compose.runtime.Immutable
|
||||||
import com.vitorpamplona.amethyst.model.*
|
import com.vitorpamplona.amethyst.model.*
|
||||||
import com.vitorpamplona.amethyst.service.Bech32
|
import com.vitorpamplona.amethyst.service.Bech32
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
import java.nio.charset.Charset
|
import java.nio.charset.Charset
|
||||||
import java.security.MessageDigest
|
import java.security.MessageDigest
|
||||||
import java.security.SecureRandom
|
import java.security.SecureRandom
|
||||||
import java.util.*
|
|
||||||
import javax.crypto.BadPaddingException
|
import javax.crypto.BadPaddingException
|
||||||
import javax.crypto.Cipher
|
import javax.crypto.Cipher
|
||||||
import javax.crypto.spec.IvParameterSpec
|
import javax.crypto.spec.IvParameterSpec
|
||||||
@@ -68,7 +67,7 @@ class LnZapRequestEvent(
|
|||||||
): LnZapRequestEvent {
|
): LnZapRequestEvent {
|
||||||
var content = message
|
var content = message
|
||||||
var privkey = privateKey
|
var privkey = privateKey
|
||||||
var pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
var pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
var tags = listOf(
|
var tags = listOf(
|
||||||
listOf("e", originalNote.id()),
|
listOf("e", originalNote.id()),
|
||||||
listOf("p", originalNote.pubKey()),
|
listOf("p", originalNote.pubKey()),
|
||||||
@@ -82,8 +81,8 @@ class LnZapRequestEvent(
|
|||||||
}
|
}
|
||||||
if (zapType == LnZapEvent.ZapType.ANONYMOUS) {
|
if (zapType == LnZapEvent.ZapType.ANONYMOUS) {
|
||||||
tags = tags + listOf(listOf("anon", ""))
|
tags = tags + listOf(listOf("anon", ""))
|
||||||
privkey = Utils.privkeyCreate()
|
privkey = CryptoUtils.privkeyCreate()
|
||||||
pubKey = Utils.pubkeyCreate(privkey).toHexKey()
|
pubKey = CryptoUtils.pubkeyCreate(privkey).toHexKey()
|
||||||
} else if (zapType == LnZapEvent.ZapType.PRIVATE) {
|
} else if (zapType == LnZapEvent.ZapType.PRIVATE) {
|
||||||
var encryptionPrivateKey = createEncryptionPrivateKey(privateKey.toHexKey(), originalNote.id(), createdAt)
|
var encryptionPrivateKey = createEncryptionPrivateKey(privateKey.toHexKey(), originalNote.id(), createdAt)
|
||||||
var noteJson = (create(privkey, 9733, listOf(tags[0], tags[1]), message)).toJson()
|
var noteJson = (create(privkey, 9733, listOf(tags[0], tags[1]), message)).toJson()
|
||||||
@@ -91,10 +90,10 @@ class LnZapRequestEvent(
|
|||||||
tags = tags + listOf(listOf("anon", encryptedContent))
|
tags = tags + listOf(listOf("anon", encryptedContent))
|
||||||
content = "" // make sure public content is empty, as the content is encrypted
|
content = "" // make sure public content is empty, as the content is encrypted
|
||||||
privkey = encryptionPrivateKey // sign event with generated privkey
|
privkey = encryptionPrivateKey // sign event with generated privkey
|
||||||
pubKey = Utils.pubkeyCreate(encryptionPrivateKey).toHexKey() // updated event with according pubkey
|
pubKey = CryptoUtils.pubkeyCreate(encryptionPrivateKey).toHexKey() // updated event with according pubkey
|
||||||
}
|
}
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, content)
|
val id = generateId(pubKey, createdAt, kind, tags, content)
|
||||||
val sig = Utils.sign(id, privkey)
|
val sig = CryptoUtils.sign(id, privkey)
|
||||||
return LnZapRequestEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
return LnZapRequestEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,14 +107,14 @@ class LnZapRequestEvent(
|
|||||||
): LnZapRequestEvent {
|
): LnZapRequestEvent {
|
||||||
var content = message
|
var content = message
|
||||||
var privkey = privateKey
|
var privkey = privateKey
|
||||||
var pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
var pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
var tags = listOf(
|
var tags = listOf(
|
||||||
listOf("p", userHex),
|
listOf("p", userHex),
|
||||||
listOf("relays") + relays
|
listOf("relays") + relays
|
||||||
)
|
)
|
||||||
if (zapType == LnZapEvent.ZapType.ANONYMOUS) {
|
if (zapType == LnZapEvent.ZapType.ANONYMOUS) {
|
||||||
privkey = Utils.privkeyCreate()
|
privkey = CryptoUtils.privkeyCreate()
|
||||||
pubKey = Utils.pubkeyCreate(privkey).toHexKey()
|
pubKey = CryptoUtils.pubkeyCreate(privkey).toHexKey()
|
||||||
tags = tags + listOf(listOf("anon", ""))
|
tags = tags + listOf(listOf("anon", ""))
|
||||||
} else if (zapType == LnZapEvent.ZapType.PRIVATE) {
|
} else if (zapType == LnZapEvent.ZapType.PRIVATE) {
|
||||||
var encryptionPrivateKey = createEncryptionPrivateKey(privateKey.toHexKey(), userHex, createdAt)
|
var encryptionPrivateKey = createEncryptionPrivateKey(privateKey.toHexKey(), userHex, createdAt)
|
||||||
@@ -124,10 +123,10 @@ class LnZapRequestEvent(
|
|||||||
tags = tags + listOf(listOf("anon", encryptedContent))
|
tags = tags + listOf(listOf("anon", encryptedContent))
|
||||||
content = ""
|
content = ""
|
||||||
privkey = encryptionPrivateKey
|
privkey = encryptionPrivateKey
|
||||||
pubKey = Utils.pubkeyCreate(encryptionPrivateKey).toHexKey()
|
pubKey = CryptoUtils.pubkeyCreate(encryptionPrivateKey).toHexKey()
|
||||||
}
|
}
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, content)
|
val id = generateId(pubKey, createdAt, kind, tags, content)
|
||||||
val sig = Utils.sign(id, privkey)
|
val sig = CryptoUtils.sign(id, privkey)
|
||||||
return LnZapRequestEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
return LnZapRequestEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,7 +137,7 @@ class LnZapRequestEvent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun encryptPrivateZapMessage(msg: String, privkey: ByteArray, pubkey: ByteArray): String {
|
private fun encryptPrivateZapMessage(msg: String, privkey: ByteArray, pubkey: ByteArray): String {
|
||||||
var sharedSecret = Utils.getSharedSecret(privkey, pubkey)
|
var sharedSecret = CryptoUtils.getSharedSecret(privkey, pubkey)
|
||||||
val iv = ByteArray(16)
|
val iv = ByteArray(16)
|
||||||
SecureRandom().nextBytes(iv)
|
SecureRandom().nextBytes(iv)
|
||||||
|
|
||||||
@@ -157,7 +156,7 @@ class LnZapRequestEvent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun decryptPrivateZapMessage(msg: String, privkey: ByteArray, pubkey: ByteArray): String {
|
private fun decryptPrivateZapMessage(msg: String, privkey: ByteArray, pubkey: ByteArray): String {
|
||||||
var sharedSecret = Utils.getSharedSecret(privkey, pubkey)
|
var sharedSecret = CryptoUtils.getSharedSecret(privkey, pubkey)
|
||||||
if (sharedSecret.size != 16 && sharedSecret.size != 32) {
|
if (sharedSecret.size != 16 && sharedSecret.size != 32) {
|
||||||
throw IllegalArgumentException("Invalid shared secret size")
|
throw IllegalArgumentException("Invalid shared secret size")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
class LongTextNoteEvent(
|
class LongTextNoteEvent(
|
||||||
@@ -33,7 +33,7 @@ class LongTextNoteEvent(
|
|||||||
const val kind = 30023
|
const val kind = 30023
|
||||||
|
|
||||||
fun create(msg: String, replyTos: List<String>?, mentions: List<String>?, privateKey: ByteArray, createdAt: Long = TimeUtils.now()): LongTextNoteEvent {
|
fun create(msg: String, replyTos: List<String>?, mentions: List<String>?, privateKey: ByteArray, createdAt: Long = TimeUtils.now()): LongTextNoteEvent {
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
val tags = mutableListOf<List<String>>()
|
val tags = mutableListOf<List<String>>()
|
||||||
replyTos?.forEach {
|
replyTos?.forEach {
|
||||||
tags.add(listOf("e", it))
|
tags.add(listOf("e", it))
|
||||||
@@ -42,7 +42,7 @@ class LongTextNoteEvent(
|
|||||||
tags.add(listOf("p", it))
|
tags.add(listOf("p", it))
|
||||||
}
|
}
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, msg)
|
val id = generateId(pubKey, createdAt, kind, tags, msg)
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return LongTextNoteEvent(id.toHexKey(), pubKey, createdAt, tags, msg, sig.toHexKey())
|
return LongTextNoteEvent(id.toHexKey(), pubKey, createdAt, tags, msg, sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import com.vitorpamplona.amethyst.model.HexKey
|
|||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.UserMetadata
|
import com.vitorpamplona.amethyst.model.UserMetadata
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
import java.io.ByteArrayInputStream
|
import java.io.ByteArrayInputStream
|
||||||
|
|
||||||
@Stable
|
@Stable
|
||||||
@@ -172,7 +172,7 @@ class MetadataEvent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun create(contactMetaData: String, identities: List<IdentityClaim>, privateKey: ByteArray, createdAt: Long = TimeUtils.now()): MetadataEvent {
|
fun create(contactMetaData: String, identities: List<IdentityClaim>, privateKey: ByteArray, createdAt: Long = TimeUtils.now()): MetadataEvent {
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
val tags = mutableListOf<List<String>>()
|
val tags = mutableListOf<List<String>>()
|
||||||
|
|
||||||
identities.forEach {
|
identities.forEach {
|
||||||
@@ -180,7 +180,7 @@ class MetadataEvent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, contactMetaData)
|
val id = generateId(pubKey, createdAt, kind, tags, contactMetaData)
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return MetadataEvent(id.toHexKey(), pubKey, createdAt, tags, contactMetaData, sig.toHexKey())
|
return MetadataEvent(id.toHexKey(), pubKey, createdAt, tags, contactMetaData, sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import com.vitorpamplona.amethyst.model.HexKey
|
|||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.hexToByteArray
|
import com.vitorpamplona.amethyst.model.hexToByteArray
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
class MuteListEvent(
|
class MuteListEvent(
|
||||||
@@ -23,9 +23,9 @@ class MuteListEvent(
|
|||||||
|
|
||||||
fun plainContent(privKey: ByteArray): String? {
|
fun plainContent(privKey: ByteArray): String? {
|
||||||
return try {
|
return try {
|
||||||
val sharedSecret = Utils.getSharedSecret(privKey, pubKey.hexToByteArray())
|
val sharedSecret = CryptoUtils.getSharedSecret(privKey, pubKey.hexToByteArray())
|
||||||
|
|
||||||
return Utils.decrypt(content, sharedSecret)
|
return CryptoUtils.decrypt(content, sharedSecret)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.w("BookmarkList", "Error decrypting the message ${e.message}")
|
Log.w("BookmarkList", "Error decrypting the message ${e.message}")
|
||||||
null
|
null
|
||||||
@@ -73,7 +73,7 @@ class MuteListEvent(
|
|||||||
privateKey: ByteArray,
|
privateKey: ByteArray,
|
||||||
createdAt: Long = TimeUtils.now()
|
createdAt: Long = TimeUtils.now()
|
||||||
): MuteListEvent {
|
): MuteListEvent {
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey)
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey)
|
||||||
|
|
||||||
val privTags = mutableListOf<List<String>>()
|
val privTags = mutableListOf<List<String>>()
|
||||||
privEvents?.forEach {
|
privEvents?.forEach {
|
||||||
@@ -87,7 +87,7 @@ class MuteListEvent(
|
|||||||
}
|
}
|
||||||
val msg = gson.toJson(privTags)
|
val msg = gson.toJson(privTags)
|
||||||
|
|
||||||
val content = Utils.encrypt(
|
val content = CryptoUtils.encrypt(
|
||||||
msg,
|
msg,
|
||||||
privateKey,
|
privateKey,
|
||||||
pubKey
|
pubKey
|
||||||
@@ -105,7 +105,7 @@ class MuteListEvent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val id = generateId(pubKey.toHexKey(), createdAt, kind, tags, content)
|
val id = generateId(pubKey.toHexKey(), createdAt, kind, tags, content)
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return MuteListEvent(id.toHexKey(), pubKey.toHexKey(), createdAt, tags, content, sig.toHexKey())
|
return MuteListEvent(id.toHexKey(), pubKey.toHexKey(), createdAt, tags, content, sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
class NNSEvent(
|
class NNSEvent(
|
||||||
@@ -31,9 +31,9 @@ class NNSEvent(
|
|||||||
createdAt: Long = TimeUtils.now()
|
createdAt: Long = TimeUtils.now()
|
||||||
): NNSEvent {
|
): NNSEvent {
|
||||||
val tags = mutableListOf<List<String>>()
|
val tags = mutableListOf<List<String>>()
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, "")
|
val id = generateId(pubKey, createdAt, kind, tags, "")
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return NNSEvent(id.toHexKey(), pubKey, createdAt, tags, "", sig.toHexKey())
|
return NNSEvent(id.toHexKey(), pubKey, createdAt, tags, "", sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
import kotlinx.collections.immutable.ImmutableSet
|
import kotlinx.collections.immutable.ImmutableSet
|
||||||
import kotlinx.collections.immutable.persistentSetOf
|
import kotlinx.collections.immutable.persistentSetOf
|
||||||
import kotlinx.collections.immutable.toImmutableSet
|
import kotlinx.collections.immutable.toImmutableSet
|
||||||
@@ -141,9 +141,9 @@ class PeopleListEvent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun create(content: String, tags: List<List<String>>, privateKey: ByteArray, createdAt: Long = TimeUtils.now()): PeopleListEvent {
|
fun create(content: String, tags: List<List<String>>, privateKey: ByteArray, createdAt: Long = TimeUtils.now()): PeopleListEvent {
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, content)
|
val id = generateId(pubKey, createdAt, kind, tags, content)
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return PeopleListEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
return PeopleListEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
class PinListEvent(
|
class PinListEvent(
|
||||||
@@ -34,9 +34,9 @@ class PinListEvent(
|
|||||||
tags.add(listOf("pin", it))
|
tags.add(listOf("pin", it))
|
||||||
}
|
}
|
||||||
|
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, "")
|
val id = generateId(pubKey, createdAt, kind, tags, "")
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return PinListEvent(id.toHexKey(), pubKey, createdAt, tags, "", sig.toHexKey())
|
return PinListEvent(id.toHexKey(), pubKey, createdAt, tags, "", sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
|
|
||||||
const val POLL_OPTION = "poll_option"
|
const val POLL_OPTION = "poll_option"
|
||||||
const val VALUE_MAXIMUM = "value_maximum"
|
const val VALUE_MAXIMUM = "value_maximum"
|
||||||
@@ -55,7 +55,7 @@ class PollNoteEvent(
|
|||||||
markAsSensitive: Boolean,
|
markAsSensitive: Boolean,
|
||||||
zapRaiserAmount: Long?
|
zapRaiserAmount: Long?
|
||||||
): PollNoteEvent {
|
): PollNoteEvent {
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
val tags = mutableListOf<List<String>>()
|
val tags = mutableListOf<List<String>>()
|
||||||
replyTos?.forEach {
|
replyTos?.forEach {
|
||||||
tags.add(listOf("e", it))
|
tags.add(listOf("e", it))
|
||||||
@@ -85,7 +85,7 @@ class PollNoteEvent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, msg)
|
val id = generateId(pubKey, createdAt, kind, tags, msg)
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return PollNoteEvent(id.toHexKey(), pubKey, createdAt, tags, msg, sig.toHexKey())
|
return PollNoteEvent(id.toHexKey(), pubKey, createdAt, tags, msg, sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
import com.vitorpamplona.amethyst.service.HexValidator
|
import com.vitorpamplona.amethyst.service.HexValidator
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
|
||||||
import fr.acinq.secp256k1.Hex
|
import fr.acinq.secp256k1.Hex
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@@ -55,9 +55,9 @@ class PrivateDmEvent(
|
|||||||
|
|
||||||
fun plainContent(privKey: ByteArray, pubKey: ByteArray): String? {
|
fun plainContent(privKey: ByteArray, pubKey: ByteArray): String? {
|
||||||
return try {
|
return try {
|
||||||
val sharedSecret = Utils.getSharedSecret(privKey, pubKey)
|
val sharedSecret = CryptoUtils.getSharedSecret(privKey, pubKey)
|
||||||
|
|
||||||
val retVal = Utils.decrypt(content, sharedSecret)
|
val retVal = CryptoUtils.decrypt(content, sharedSecret)
|
||||||
|
|
||||||
if (retVal.startsWith(nip18Advertisement)) {
|
if (retVal.startsWith(nip18Advertisement)) {
|
||||||
retVal.substring(16)
|
retVal.substring(16)
|
||||||
@@ -88,12 +88,12 @@ class PrivateDmEvent(
|
|||||||
markAsSensitive: Boolean,
|
markAsSensitive: Boolean,
|
||||||
zapRaiserAmount: Long?
|
zapRaiserAmount: Long?
|
||||||
): PrivateDmEvent {
|
): PrivateDmEvent {
|
||||||
val content = Utils.encrypt(
|
val content = CryptoUtils.encrypt(
|
||||||
if (advertiseNip18) { nip18Advertisement } else { "" } + msg,
|
if (advertiseNip18) { nip18Advertisement } else { "" } + msg,
|
||||||
privateKey,
|
privateKey,
|
||||||
recipientPubKey
|
recipientPubKey
|
||||||
)
|
)
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
val tags = mutableListOf<List<String>>()
|
val tags = mutableListOf<List<String>>()
|
||||||
publishedRecipientPubKey?.let {
|
publishedRecipientPubKey?.let {
|
||||||
tags.add(listOf("p", publishedRecipientPubKey.toHexKey()))
|
tags.add(listOf("p", publishedRecipientPubKey.toHexKey()))
|
||||||
@@ -114,7 +114,7 @@ class PrivateDmEvent(
|
|||||||
tags.add(listOf("zapraiser", "$it"))
|
tags.add(listOf("zapraiser", "$it"))
|
||||||
}
|
}
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, content)
|
val id = generateId(pubKey, createdAt, kind, tags, content)
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return PrivateDmEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
return PrivateDmEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
class ReactionEvent(
|
class ReactionEvent(
|
||||||
@@ -31,7 +31,7 @@ class ReactionEvent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun create(content: String, originalNote: EventInterface, privateKey: ByteArray, createdAt: Long = TimeUtils.now()): ReactionEvent {
|
fun create(content: String, originalNote: EventInterface, privateKey: ByteArray, createdAt: Long = TimeUtils.now()): ReactionEvent {
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
|
|
||||||
var tags = listOf(listOf("e", originalNote.id()), listOf("p", originalNote.pubKey()))
|
var tags = listOf(listOf("e", originalNote.id()), listOf("p", originalNote.pubKey()))
|
||||||
if (originalNote is AddressableEvent) {
|
if (originalNote is AddressableEvent) {
|
||||||
@@ -39,13 +39,13 @@ class ReactionEvent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, content)
|
val id = generateId(pubKey, createdAt, kind, tags, content)
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return ReactionEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
return ReactionEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun create(emojiUrl: EmojiUrl, originalNote: EventInterface, privateKey: ByteArray, createdAt: Long = TimeUtils.now()): ReactionEvent {
|
fun create(emojiUrl: EmojiUrl, originalNote: EventInterface, privateKey: ByteArray, createdAt: Long = TimeUtils.now()): ReactionEvent {
|
||||||
val content = ":${emojiUrl.code}:"
|
val content = ":${emojiUrl.code}:"
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
|
|
||||||
var tags = listOf(
|
var tags = listOf(
|
||||||
listOf("e", originalNote.id()),
|
listOf("e", originalNote.id()),
|
||||||
@@ -58,7 +58,7 @@ class ReactionEvent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, content)
|
val id = generateId(pubKey, createdAt, kind, tags, content)
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return ReactionEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
return ReactionEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
import java.net.URI
|
import java.net.URI
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@@ -29,10 +29,10 @@ class RecommendRelayEvent(
|
|||||||
|
|
||||||
fun create(relay: URI, privateKey: ByteArray, createdAt: Long = TimeUtils.now()): RecommendRelayEvent {
|
fun create(relay: URI, privateKey: ByteArray, createdAt: Long = TimeUtils.now()): RecommendRelayEvent {
|
||||||
val content = relay.toString()
|
val content = relay.toString()
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
val tags = listOf<List<String>>()
|
val tags = listOf<List<String>>()
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, content)
|
val id = generateId(pubKey, createdAt, kind, tags, content)
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return RecommendRelayEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
return RecommendRelayEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
class RelayAuthEvent(
|
class RelayAuthEvent(
|
||||||
@@ -23,13 +23,13 @@ class RelayAuthEvent(
|
|||||||
|
|
||||||
fun create(relay: String, challenge: String, privateKey: ByteArray, createdAt: Long = TimeUtils.now()): RelayAuthEvent {
|
fun create(relay: String, challenge: String, privateKey: ByteArray, createdAt: Long = TimeUtils.now()): RelayAuthEvent {
|
||||||
val content = ""
|
val content = ""
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
val tags = listOf(
|
val tags = listOf(
|
||||||
listOf("relay", relay),
|
listOf("relay", relay),
|
||||||
listOf("challenge", challenge)
|
listOf("challenge", challenge)
|
||||||
)
|
)
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, content)
|
val id = generateId(pubKey, createdAt, kind, tags, content)
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return RelayAuthEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
return RelayAuthEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
class RelaySetEvent(
|
class RelaySetEvent(
|
||||||
@@ -35,9 +35,9 @@ class RelaySetEvent(
|
|||||||
tags.add(listOf("r", it))
|
tags.add(listOf("r", it))
|
||||||
}
|
}
|
||||||
|
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, "")
|
val id = generateId(pubKey, createdAt, kind, tags, "")
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return RelaySetEvent(id.toHexKey(), pubKey, createdAt, tags, "", sig.toHexKey())
|
return RelaySetEvent(id.toHexKey(), pubKey, createdAt, tags, "", sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
data class ReportedKey(val key: String, val reportType: ReportEvent.ReportType)
|
data class ReportedKey(val key: String, val reportType: ReportEvent.ReportType)
|
||||||
@@ -63,7 +63,7 @@ class ReportEvent(
|
|||||||
val reportPostTag = listOf("e", reportedPost.id(), type.name.lowercase())
|
val reportPostTag = listOf("e", reportedPost.id(), type.name.lowercase())
|
||||||
val reportAuthorTag = listOf("p", reportedPost.pubKey(), type.name.lowercase())
|
val reportAuthorTag = listOf("p", reportedPost.pubKey(), type.name.lowercase())
|
||||||
|
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
var tags: List<List<String>> = listOf(reportPostTag, reportAuthorTag)
|
var tags: List<List<String>> = listOf(reportPostTag, reportAuthorTag)
|
||||||
|
|
||||||
if (reportedPost is AddressableEvent) {
|
if (reportedPost is AddressableEvent) {
|
||||||
@@ -71,7 +71,7 @@ class ReportEvent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, content)
|
val id = generateId(pubKey, createdAt, kind, tags, content)
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return ReportEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
return ReportEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,10 +80,10 @@ class ReportEvent(
|
|||||||
|
|
||||||
val reportAuthorTag = listOf("p", reportedUser, type.name.lowercase())
|
val reportAuthorTag = listOf("p", reportedUser, type.name.lowercase())
|
||||||
|
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
val tags: List<List<String>> = listOf(reportAuthorTag)
|
val tags: List<List<String>> = listOf(reportAuthorTag)
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, content)
|
val id = generateId(pubKey, createdAt, kind, tags, content)
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return ReportEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
return ReportEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
import com.vitorpamplona.amethyst.service.relays.Client
|
import com.vitorpamplona.amethyst.service.relays.Client
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@@ -35,7 +35,7 @@ class RepostEvent(
|
|||||||
val replyToPost = listOf("e", boostedPost.id())
|
val replyToPost = listOf("e", boostedPost.id())
|
||||||
val replyToAuthor = listOf("p", boostedPost.pubKey())
|
val replyToAuthor = listOf("p", boostedPost.pubKey())
|
||||||
|
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
var tags: List<List<String>> = listOf(replyToPost, replyToAuthor)
|
var tags: List<List<String>> = listOf(replyToPost, replyToAuthor)
|
||||||
|
|
||||||
if (boostedPost is AddressableEvent) {
|
if (boostedPost is AddressableEvent) {
|
||||||
@@ -43,7 +43,7 @@ class RepostEvent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, content)
|
val id = generateId(pubKey, createdAt, kind, tags, content)
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return RepostEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
return RepostEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import com.linkedin.urls.detection.UrlDetectorOptions
|
|||||||
import com.vitorpamplona.amethyst.model.HexKey
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.TimeUtils
|
import com.vitorpamplona.amethyst.model.TimeUtils
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
import com.vitorpamplona.amethyst.service.Utils
|
import com.vitorpamplona.amethyst.service.CryptoUtils
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.findHashtags
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.findHashtags
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@@ -42,7 +42,7 @@ class TextNoteEvent(
|
|||||||
privateKey: ByteArray,
|
privateKey: ByteArray,
|
||||||
createdAt: Long = TimeUtils.now()
|
createdAt: Long = TimeUtils.now()
|
||||||
): TextNoteEvent {
|
): TextNoteEvent {
|
||||||
val pubKey = Utils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||||
val tags = mutableListOf<List<String>>()
|
val tags = mutableListOf<List<String>>()
|
||||||
replyTos?.forEach {
|
replyTos?.forEach {
|
||||||
if (it == replyingTo) {
|
if (it == replyingTo) {
|
||||||
@@ -95,7 +95,7 @@ class TextNoteEvent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, msg)
|
val id = generateId(pubKey, createdAt, kind, tags, msg)
|
||||||
val sig = Utils.sign(id, privateKey)
|
val sig = CryptoUtils.sign(id, privateKey)
|
||||||
return TextNoteEvent(id.toHexKey(), pubKey, createdAt, tags, msg, sig.toHexKey())
|
return TextNoteEvent(id.toHexKey(), pubKey, createdAt, tags, msg, sig.toHexKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ object BookmarkPrivateFeedFilter : FeedFilter<Note>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun feed(): List<Note> {
|
override fun feed(): List<Note> {
|
||||||
val privKey = account.loggedIn.privKey ?: return emptyList()
|
val privKey = account.keyPair.privKey ?: return emptyList()
|
||||||
|
|
||||||
val bookmarks = account.userProfile().latestBookmarkList
|
val bookmarks = account.userProfile().latestBookmarkList
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class HiddenAccountsFeedFilter(val account: Account) : FeedFilter<User>() {
|
|||||||
|
|
||||||
override fun feed(): List<User> {
|
override fun feed(): List<User> {
|
||||||
return account.getBlockList()
|
return account.getBlockList()
|
||||||
?.publicAndPrivateUsers(account.loggedIn.privKey)
|
?.publicAndPrivateUsers(account.keyPair.privKey)
|
||||||
?.map { LocalCache.getOrCreateUser(it) }
|
?.map { LocalCache.getOrCreateUser(it) }
|
||||||
?: emptyList()
|
?: emptyList()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import com.vitorpamplona.amethyst.ServiceManager
|
|||||||
import com.vitorpamplona.amethyst.model.Account
|
import com.vitorpamplona.amethyst.model.Account
|
||||||
import com.vitorpamplona.amethyst.model.hexToByteArray
|
import com.vitorpamplona.amethyst.model.hexToByteArray
|
||||||
import com.vitorpamplona.amethyst.service.HttpClient
|
import com.vitorpamplona.amethyst.service.HttpClient
|
||||||
import com.vitorpamplona.amethyst.service.Persona
|
import com.vitorpamplona.amethyst.service.KeyPair
|
||||||
import com.vitorpamplona.amethyst.service.bechToBytes
|
import com.vitorpamplona.amethyst.service.bechToBytes
|
||||||
import com.vitorpamplona.amethyst.service.nip19.Nip19
|
import com.vitorpamplona.amethyst.service.nip19.Nip19
|
||||||
import fr.acinq.secp256k1.Hex
|
import fr.acinq.secp256k1.Hex
|
||||||
@@ -53,14 +53,14 @@ class AccountStateViewModel(val context: Context) : ViewModel() {
|
|||||||
|
|
||||||
val account =
|
val account =
|
||||||
if (key.startsWith("nsec")) {
|
if (key.startsWith("nsec")) {
|
||||||
Account(Persona(privKey = key.bechToBytes()), proxy = proxy, proxyPort = proxyPort)
|
Account(KeyPair(privKey = key.bechToBytes()), proxy = proxy, proxyPort = proxyPort)
|
||||||
} else if (pubKeyParsed != null) {
|
} else if (pubKeyParsed != null) {
|
||||||
Account(Persona(pubKey = pubKeyParsed), proxy = proxy, proxyPort = proxyPort)
|
Account(KeyPair(pubKey = pubKeyParsed), proxy = proxy, proxyPort = proxyPort)
|
||||||
} else if (pattern.matcher(key).matches()) {
|
} else if (pattern.matcher(key).matches()) {
|
||||||
// Evaluate NIP-5
|
// Evaluate NIP-5
|
||||||
Account(Persona(), proxy = proxy, proxyPort = proxyPort)
|
Account(KeyPair(), proxy = proxy, proxyPort = proxyPort)
|
||||||
} else {
|
} else {
|
||||||
Account(Persona(Hex.decode(key)), proxy = proxy, proxyPort = proxyPort)
|
Account(KeyPair(Hex.decode(key)), proxy = proxy, proxyPort = proxyPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalPreferences.updatePrefsForLogin(account)
|
LocalPreferences.updatePrefsForLogin(account)
|
||||||
@@ -75,7 +75,7 @@ class AccountStateViewModel(val context: Context) : ViewModel() {
|
|||||||
|
|
||||||
fun newKey(useProxy: Boolean, proxyPort: Int) {
|
fun newKey(useProxy: Boolean, proxyPort: Int) {
|
||||||
val proxy = HttpClient.initProxy(useProxy, "127.0.0.1", proxyPort)
|
val proxy = HttpClient.initProxy(useProxy, "127.0.0.1", proxyPort)
|
||||||
val account = Account(Persona(), proxy = proxy, proxyPort = proxyPort)
|
val account = Account(KeyPair(), proxy = proxy, proxyPort = proxyPort)
|
||||||
// saves to local preferences
|
// saves to local preferences
|
||||||
LocalPreferences.updatePrefsForLogin(account)
|
LocalPreferences.updatePrefsForLogin(account)
|
||||||
startUI(account)
|
startUI(account)
|
||||||
@@ -83,7 +83,7 @@ class AccountStateViewModel(val context: Context) : ViewModel() {
|
|||||||
|
|
||||||
@OptIn(DelicateCoroutinesApi::class)
|
@OptIn(DelicateCoroutinesApi::class)
|
||||||
fun startUI(account: Account) {
|
fun startUI(account: Account) {
|
||||||
if (account.loggedIn.privKey != null) {
|
if (account.keyPair.privKey != null) {
|
||||||
_accountContent.update { AccountState.LoggedIn(account) }
|
_accountContent.update { AccountState.LoggedIn(account) }
|
||||||
} else {
|
} else {
|
||||||
_accountContent.update { AccountState.LoggedInViewOnly(account) }
|
_accountContent.update { AccountState.LoggedInViewOnly(account) }
|
||||||
|
|||||||
+1
-1
@@ -157,7 +157,7 @@ private fun copyNSec(
|
|||||||
account: Account,
|
account: Account,
|
||||||
clipboardManager: ClipboardManager
|
clipboardManager: ClipboardManager
|
||||||
) {
|
) {
|
||||||
account.loggedIn.privKey?.let {
|
account.keyPair.privKey?.let {
|
||||||
clipboardManager.setText(AnnotatedString(it.toNsec()))
|
clipboardManager.setText(AnnotatedString(it.toNsec()))
|
||||||
scope.launch {
|
scope.launch {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
|
|||||||
Reference in New Issue
Block a user