Merge branch 'main' into amber

This commit is contained in:
greenart7c3
2023-08-28 07:06:52 -03:00
committed by GitHub
61 changed files with 1096 additions and 681 deletions
@@ -72,7 +72,7 @@ open class Event(
override fun firstTaggedUser() = tags.firstOrNull { it.size > 1 && it[0] == "p" }?.let { it[1] }
override fun firstTaggedEvent() = tags.firstOrNull { it.size > 1 && it[0] == "e" }?.let { it[1] }
override fun firstTaggedUrl() = tags.firstOrNull { it.size > 1 && it[0] == "r" }?.let { it[1] }
override fun firstTaggedAddress() = tags.firstOrNull { it.size > 1 && it[0] == "r" }?.let {
override fun firstTaggedAddress() = tags.firstOrNull { it.size > 1 && it[0] == "a" }?.let {
val aTagValue = it[1]
val relay = it.getOrNull(2)
@@ -218,7 +218,7 @@ open class Event(
return try {
hasCorrectIDHash() && hasVerifedSignature()
} catch (e: Exception) {
Log.e("Event", "Event $id does not have a valid signature: ${toJson()}", e)
Log.w("Event", "Event $id does not have a valid signature: ${toJson()}", e)
false
}
}
@@ -50,5 +50,18 @@ class StatusEvent(
val sig = CryptoUtils.sign(id, privateKey)
return StatusEvent(id.toHexKey(), pubKey, createdAt, tags, newStatus, sig.toHexKey())
}
fun clear(
event: StatusEvent,
privateKey: ByteArray,
createdAt: Long = TimeUtils.now()
): StatusEvent {
val msg = ""
val tags = event.tags.filter { it.size > 1 && it[0] == "d" }
val pubKey = event.pubKey()
val id = generateId(pubKey, createdAt, kind, tags, msg)
val sig = CryptoUtils.sign(id, privateKey)
return StatusEvent(id.toHexKey(), pubKey, createdAt, tags, msg, sig.toHexKey())
}
}
}