check if pubkey of the event is empty and fill pubkey and event id

This commit is contained in:
greenart7c3
2023-08-04 15:09:22 -03:00
parent 1affaa3d7c
commit 1ddaaf598b
2 changed files with 13 additions and 2 deletions
@@ -296,6 +296,15 @@ open class Event(
return CryptoUtils.sha256(rawEventJson.toByteArray())
}
fun setPubKeyIfEmpty(event: Event, pubKey: HexKey): Event {
if (event.pubKey.isEmpty()) {
val id = generateId(pubKey, event.createdAt, event.kind, event.tags, event.content)
return Event(id.toHexKey(), pubKey, event.createdAt, event.kind, event.tags, event.content, "")
}
return event
}
fun create(privateKey: ByteArray, kind: Int, tags: List<List<String>> = emptyList(), content: String = "", createdAt: Long = TimeUtils.now()): Event {
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
val id = generateId(pubKey, createdAt, kind, tags, content)
@@ -116,7 +116,9 @@ fun MainScreen(account: Account, accountStateViewModel: AccountStateViewModel, j
return@EventData
}
if (event.value!!.pubKey != account.keyPair.pubKey.toHexKey()) {
val localEvent = Event.setPubKeyIfEmpty(event.value!!, account.keyPair.pubKey.toHexKey())
if (localEvent.pubKey != account.keyPair.pubKey.toHexKey()) {
coroutineScope.launch {
Toast.makeText(
context,
@@ -127,7 +129,7 @@ fun MainScreen(account: Account, accountStateViewModel: AccountStateViewModel, j
return@EventData
}
val id = event.value!!.id.hexToByteArray()
val id = localEvent.id.hexToByteArray()
val sig = CryptoUtils.sign(id, account.keyPair.privKey!!).toHexKey()
clipboardManager.setText(AnnotatedString(sig))