mirror of
https://github.com/greenart7c3/Amber.git
synced 2026-10-06 03:18:23 +00:00
check if pubkey of the event is empty and fill pubkey and event id
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user