support for nip95
This commit is contained in:
@@ -112,7 +112,7 @@ class Account(
|
||||
val content = blockList?.content ?: ""
|
||||
if (content.isEmpty()) return@launch
|
||||
AmberUtils.content = ""
|
||||
AmberUtils.decryptBookmark(
|
||||
AmberUtils.decrypt(
|
||||
content,
|
||||
keyPair.pubKey.toHexKey()
|
||||
)
|
||||
@@ -823,31 +823,75 @@ class Account(
|
||||
}
|
||||
|
||||
fun createNip95(byteArray: ByteArray, headerInfo: FileHeader): Pair<FileStorageEvent, FileStorageHeaderEvent>? {
|
||||
if (!isWriteable()) return null
|
||||
if (!isWriteable() && !loginWithAmber) return null
|
||||
|
||||
val data = FileStorageEvent.create(
|
||||
mimeType = headerInfo.mimeType ?: "",
|
||||
data = byteArray,
|
||||
privateKey = keyPair.privKey!!
|
||||
)
|
||||
if (loginWithAmber) {
|
||||
val unsignedData = FileStorageEvent.create(
|
||||
mimeType = headerInfo.mimeType ?: "",
|
||||
data = byteArray,
|
||||
pubKey = keyPair.pubKey.toHexKey()
|
||||
)
|
||||
|
||||
val signedEvent = FileStorageHeaderEvent.create(
|
||||
data,
|
||||
mimeType = headerInfo.mimeType,
|
||||
hash = headerInfo.hash,
|
||||
size = headerInfo.size.toString(),
|
||||
dimensions = headerInfo.dim,
|
||||
blurhash = headerInfo.blurHash,
|
||||
description = headerInfo.description,
|
||||
sensitiveContent = headerInfo.sensitiveContent,
|
||||
privateKey = keyPair.privKey!!
|
||||
)
|
||||
AmberUtils.openAmber(unsignedData)
|
||||
if (AmberUtils.content.isBlank()) return null
|
||||
val data = FileStorageEvent(
|
||||
unsignedData.id,
|
||||
unsignedData.pubKey,
|
||||
unsignedData.createdAt,
|
||||
unsignedData.tags,
|
||||
unsignedData.content,
|
||||
AmberUtils.content
|
||||
)
|
||||
|
||||
return Pair(data, signedEvent)
|
||||
val unsignedEvent = FileStorageHeaderEvent.create(
|
||||
data,
|
||||
mimeType = headerInfo.mimeType,
|
||||
hash = headerInfo.hash,
|
||||
size = headerInfo.size.toString(),
|
||||
dimensions = headerInfo.dim,
|
||||
blurhash = headerInfo.blurHash,
|
||||
description = headerInfo.description,
|
||||
sensitiveContent = headerInfo.sensitiveContent,
|
||||
pubKey = keyPair.pubKey.toHexKey()
|
||||
)
|
||||
|
||||
AmberUtils.openAmber(unsignedEvent)
|
||||
if (AmberUtils.content.isBlank()) return null
|
||||
val signedEvent = FileStorageHeaderEvent(
|
||||
unsignedEvent.id,
|
||||
unsignedEvent.pubKey,
|
||||
unsignedEvent.createdAt,
|
||||
unsignedEvent.tags,
|
||||
unsignedEvent.content,
|
||||
AmberUtils.content
|
||||
)
|
||||
|
||||
return Pair(data, signedEvent)
|
||||
} else {
|
||||
val data = FileStorageEvent.create(
|
||||
mimeType = headerInfo.mimeType ?: "",
|
||||
data = byteArray,
|
||||
privateKey = keyPair.privKey!!
|
||||
)
|
||||
|
||||
val signedEvent = FileStorageHeaderEvent.create(
|
||||
data,
|
||||
mimeType = headerInfo.mimeType,
|
||||
hash = headerInfo.hash,
|
||||
size = headerInfo.size.toString(),
|
||||
dimensions = headerInfo.dim,
|
||||
blurhash = headerInfo.blurHash,
|
||||
description = headerInfo.description,
|
||||
sensitiveContent = headerInfo.sensitiveContent,
|
||||
privateKey = keyPair.privKey!!
|
||||
)
|
||||
|
||||
return Pair(data, signedEvent)
|
||||
}
|
||||
}
|
||||
|
||||
fun sendNip95(data: FileStorageEvent, signedEvent: FileStorageHeaderEvent, relayList: List<Relay>? = null): Note? {
|
||||
if (!isWriteable()) return null
|
||||
if (!isWriteable() && !loginWithAmber) return null
|
||||
|
||||
Client.send(data, relayList = relayList)
|
||||
LocalCache.consume(data, null)
|
||||
@@ -1312,7 +1356,7 @@ class Account(
|
||||
}
|
||||
val msg = Event.mapper.writeValueAsString(privTags)
|
||||
|
||||
AmberUtils.encryptBookmark(msg, keyPair.pubKey.toHexKey())
|
||||
AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey())
|
||||
|
||||
if (AmberUtils.content.isBlank()) {
|
||||
return null
|
||||
@@ -1357,7 +1401,7 @@ class Account(
|
||||
}
|
||||
val msg = Event.mapper.writeValueAsString(privTags)
|
||||
|
||||
AmberUtils.encryptBookmark(msg, keyPair.pubKey.toHexKey())
|
||||
AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey())
|
||||
|
||||
if (AmberUtils.content.isBlank()) {
|
||||
return null
|
||||
@@ -1432,7 +1476,7 @@ class Account(
|
||||
}
|
||||
val msg = Event.mapper.writeValueAsString(privTags)
|
||||
|
||||
AmberUtils.encryptBookmark(msg, keyPair.pubKey.toHexKey())
|
||||
AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey())
|
||||
|
||||
if (AmberUtils.content.isBlank()) {
|
||||
return null
|
||||
@@ -1597,7 +1641,7 @@ class Account(
|
||||
}
|
||||
val msg = Event.mapper.writeValueAsString(privTags)
|
||||
|
||||
AmberUtils.encryptBookmark(msg, keyPair.pubKey.toHexKey())
|
||||
AmberUtils.encrypt(msg, keyPair.pubKey.toHexKey())
|
||||
|
||||
if (AmberUtils.content.isBlank()) {
|
||||
return null
|
||||
|
||||
@@ -6,6 +6,7 @@ import androidx.activity.result.ActivityResultLauncher
|
||||
import com.vitorpamplona.amethyst.ServiceManager
|
||||
import com.vitorpamplona.amethyst.ui.actions.SignerType
|
||||
import com.vitorpamplona.quartz.encoders.HexKey
|
||||
import com.vitorpamplona.quartz.events.EventInterface
|
||||
|
||||
object AmberUtils {
|
||||
var content: String = ""
|
||||
@@ -33,7 +34,20 @@ object AmberUtils {
|
||||
intentResult.launch(intent)
|
||||
}
|
||||
|
||||
fun decryptBookmark(encryptedContent: String, pubKey: HexKey) {
|
||||
fun openAmber(event: EventInterface) {
|
||||
isActivityRunning = true
|
||||
openAmber(
|
||||
event.toJson(),
|
||||
SignerType.SIGN_EVENT,
|
||||
IntentUtils.decryptActivityResultLauncher,
|
||||
""
|
||||
)
|
||||
while (isActivityRunning) {
|
||||
Thread.sleep(250)
|
||||
}
|
||||
}
|
||||
|
||||
fun decrypt(encryptedContent: String, pubKey: HexKey) {
|
||||
if (content.isBlank()) {
|
||||
isActivityRunning = true
|
||||
openAmber(
|
||||
@@ -48,7 +62,7 @@ object AmberUtils {
|
||||
}
|
||||
}
|
||||
|
||||
fun encryptBookmark(decryptedContent: String, pubKey: HexKey) {
|
||||
fun encrypt(decryptedContent: String, pubKey: HexKey) {
|
||||
if (content.isBlank()) {
|
||||
isActivityRunning = true
|
||||
openAmber(
|
||||
|
||||
@@ -285,7 +285,14 @@ open class NewPostViewModel() : ViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
fun upload(galleryUri: Uri, description: String, sensitiveContent: Boolean, server: ServersAvailable, context: Context, relayList: List<Relay>? = null) {
|
||||
fun upload(
|
||||
galleryUri: Uri,
|
||||
description: String,
|
||||
sensitiveContent: Boolean,
|
||||
server: ServersAvailable,
|
||||
context: Context,
|
||||
relayList: List<Relay>? = null
|
||||
) {
|
||||
isUploadingImage = true
|
||||
contentToAddUrl = null
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ object BookmarkPrivateFeedFilter : FeedFilter<Note>() {
|
||||
|
||||
if (account.loginWithAmber) {
|
||||
if (AmberUtils.content.isBlank()) {
|
||||
AmberUtils.decryptBookmark(bookmarks?.content ?: "", account.keyPair.pubKey.toHexKey())
|
||||
AmberUtils.decrypt(bookmarks?.content ?: "", account.keyPair.pubKey.toHexKey())
|
||||
bookmarks?.decryptedContent = AmberUtils.content
|
||||
}
|
||||
|
||||
|
||||
@@ -481,7 +481,7 @@ fun NoteDropDownMenu(note: Note, popupExpanded: MutableState<Boolean>, accountVi
|
||||
scope.launch(Dispatchers.IO) {
|
||||
if (accountViewModel.loggedInWithAmber()) {
|
||||
val bookmarks = accountViewModel.userProfile().latestBookmarkList
|
||||
AmberUtils.decryptBookmark(
|
||||
AmberUtils.decrypt(
|
||||
bookmarks?.content ?: "",
|
||||
accountViewModel.account.keyPair.pubKey.toHexKey()
|
||||
)
|
||||
@@ -503,7 +503,7 @@ fun NoteDropDownMenu(note: Note, popupExpanded: MutableState<Boolean>, accountVi
|
||||
scope.launch(Dispatchers.IO) {
|
||||
if (accountViewModel.loggedInWithAmber()) {
|
||||
val bookmarks = accountViewModel.userProfile().latestBookmarkList
|
||||
AmberUtils.decryptBookmark(
|
||||
AmberUtils.decrypt(
|
||||
bookmarks?.content ?: "",
|
||||
accountViewModel.account.keyPair.pubKey.toHexKey()
|
||||
)
|
||||
@@ -526,7 +526,7 @@ fun NoteDropDownMenu(note: Note, popupExpanded: MutableState<Boolean>, accountVi
|
||||
scope.launch(Dispatchers.IO) {
|
||||
if (accountViewModel.loggedInWithAmber()) {
|
||||
val bookmarks = accountViewModel.userProfile().latestBookmarkList
|
||||
AmberUtils.decryptBookmark(
|
||||
AmberUtils.decrypt(
|
||||
bookmarks?.content ?: "",
|
||||
accountViewModel.account.keyPair.pubKey.toHexKey()
|
||||
)
|
||||
@@ -551,7 +551,7 @@ fun NoteDropDownMenu(note: Note, popupExpanded: MutableState<Boolean>, accountVi
|
||||
scope.launch(Dispatchers.IO) {
|
||||
if (accountViewModel.loggedInWithAmber()) {
|
||||
val bookmarks = accountViewModel.userProfile().latestBookmarkList
|
||||
AmberUtils.decryptBookmark(
|
||||
AmberUtils.decrypt(
|
||||
bookmarks?.content ?: "",
|
||||
accountViewModel.account.keyPair.pubKey.toHexKey()
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user