mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-27 23:46:23 +02:00
add support for nip94
This commit is contained in:
@@ -902,9 +902,41 @@ class Account(
|
|||||||
return LocalCache.notes[signedEvent.id]
|
return LocalCache.notes[signedEvent.id]
|
||||||
}
|
}
|
||||||
|
|
||||||
fun sendHeader(headerInfo: FileHeader, relayList: List<Relay>? = null): Note? {
|
private fun sendHeader(signedEvent: FileHeaderEvent, relayList: List<Relay>? = null): Note? {
|
||||||
if (!isWriteable()) return null
|
Client.send(signedEvent, relayList = relayList)
|
||||||
|
LocalCache.consume(signedEvent, null)
|
||||||
|
|
||||||
|
return LocalCache.notes[signedEvent.id]
|
||||||
|
}
|
||||||
|
|
||||||
|
fun sendHeader(headerInfo: FileHeader, relayList: List<Relay>? = null): Note? {
|
||||||
|
if (!isWriteable() && !loginWithAmber) return null
|
||||||
|
|
||||||
|
if (loginWithAmber) {
|
||||||
|
val unsignedEvent = FileHeaderEvent.create(
|
||||||
|
url = headerInfo.url,
|
||||||
|
mimeType = headerInfo.mimeType,
|
||||||
|
hash = headerInfo.hash,
|
||||||
|
size = headerInfo.size.toString(),
|
||||||
|
dimensions = headerInfo.dim,
|
||||||
|
blurhash = headerInfo.blurHash,
|
||||||
|
description = headerInfo.description,
|
||||||
|
sensitiveContent = headerInfo.sensitiveContent,
|
||||||
|
keyPair = keyPair
|
||||||
|
)
|
||||||
|
AmberUtils.openAmber(unsignedEvent)
|
||||||
|
if (AmberUtils.content.isBlank()) return null
|
||||||
|
val signedEvent = FileHeaderEvent(
|
||||||
|
unsignedEvent.id,
|
||||||
|
unsignedEvent.pubKey,
|
||||||
|
unsignedEvent.createdAt,
|
||||||
|
unsignedEvent.tags,
|
||||||
|
unsignedEvent.content,
|
||||||
|
AmberUtils.content
|
||||||
|
)
|
||||||
|
|
||||||
|
return sendHeader(signedEvent, relayList = relayList)
|
||||||
|
} else {
|
||||||
val signedEvent = FileHeaderEvent.create(
|
val signedEvent = FileHeaderEvent.create(
|
||||||
url = headerInfo.url,
|
url = headerInfo.url,
|
||||||
mimeType = headerInfo.mimeType,
|
mimeType = headerInfo.mimeType,
|
||||||
@@ -914,13 +946,11 @@ class Account(
|
|||||||
blurhash = headerInfo.blurHash,
|
blurhash = headerInfo.blurHash,
|
||||||
description = headerInfo.description,
|
description = headerInfo.description,
|
||||||
sensitiveContent = headerInfo.sensitiveContent,
|
sensitiveContent = headerInfo.sensitiveContent,
|
||||||
privateKey = keyPair.privKey!!
|
keyPair = keyPair
|
||||||
)
|
)
|
||||||
|
|
||||||
Client.send(signedEvent, relayList = relayList)
|
return sendHeader(signedEvent, relayList = relayList)
|
||||||
LocalCache.consume(signedEvent, null)
|
}
|
||||||
|
|
||||||
return LocalCache.notes[signedEvent.id]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun sendPost(
|
fun sendPost(
|
||||||
|
@@ -4,6 +4,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||||
import com.vitorpamplona.quartz.encoders.toHexKey
|
import com.vitorpamplona.quartz.encoders.toHexKey
|
||||||
import com.vitorpamplona.quartz.crypto.CryptoUtils
|
import com.vitorpamplona.quartz.crypto.CryptoUtils
|
||||||
|
import com.vitorpamplona.quartz.crypto.KeyPair
|
||||||
import com.vitorpamplona.quartz.encoders.HexKey
|
import com.vitorpamplona.quartz.encoders.HexKey
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@@ -53,7 +54,7 @@ class FileHeaderEvent(
|
|||||||
torrentInfoHash: String? = null,
|
torrentInfoHash: String? = null,
|
||||||
encryptionKey: AESGCM? = null,
|
encryptionKey: AESGCM? = null,
|
||||||
sensitiveContent: Boolean? = null,
|
sensitiveContent: Boolean? = null,
|
||||||
privateKey: ByteArray,
|
keyPair: KeyPair,
|
||||||
createdAt: Long = TimeUtils.now()
|
createdAt: Long = TimeUtils.now()
|
||||||
): FileHeaderEvent {
|
): FileHeaderEvent {
|
||||||
val tags = listOfNotNull(
|
val tags = listOfNotNull(
|
||||||
@@ -76,10 +77,10 @@ class FileHeaderEvent(
|
|||||||
)
|
)
|
||||||
|
|
||||||
val content = description ?: ""
|
val content = description ?: ""
|
||||||
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
val pubKey = keyPair.pubKey.toHexKey()
|
||||||
val id = generateId(pubKey, createdAt, kind, tags, content)
|
val id = generateId(pubKey, createdAt, kind, tags, content)
|
||||||
val sig = CryptoUtils.sign(id, privateKey)
|
val sig = if (keyPair.privKey == null) null else CryptoUtils.sign(id, keyPair.privKey)
|
||||||
return FileHeaderEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig.toHexKey())
|
return FileHeaderEvent(id.toHexKey(), pubKey, createdAt, tags, content, sig?.toHexKey() ?: "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user