mirror of
https://github.com/greenart7c3/Amber.git
synced 2026-10-06 03:18:23 +00:00
change event to amberevent to avoid conflits with quartz
This commit is contained in:
@@ -7,6 +7,7 @@ import android.database.MatrixCursor
|
||||
import android.net.Uri
|
||||
import com.greenart7c3.nostrsigner.models.SignerType
|
||||
import com.greenart7c3.nostrsigner.service.AmberUtils
|
||||
import com.greenart7c3.nostrsigner.service.model.AmberEvent
|
||||
import com.vitorpamplona.quartz.encoders.toNpub
|
||||
import com.vitorpamplona.quartz.events.Event
|
||||
import com.vitorpamplona.quartz.events.LnZapRequestEvent
|
||||
@@ -57,7 +58,7 @@ class SignerProvider : ContentProvider() {
|
||||
}
|
||||
|
||||
val signedEvent = AmberUtils.getSignedEvent(
|
||||
com.greenart7c3.nostrsigner.service.model.Event.fromJson(json),
|
||||
AmberEvent.fromJson(json),
|
||||
account.keyPair.privKey
|
||||
)
|
||||
val cursor = MatrixCursor(arrayOf("signature", "event"))
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.greenart7c3.nostrsigner.service
|
||||
import android.util.Log
|
||||
import com.greenart7c3.nostrsigner.models.Account
|
||||
import com.greenart7c3.nostrsigner.models.SignerType
|
||||
import com.greenart7c3.nostrsigner.service.model.Event
|
||||
import com.greenart7c3.nostrsigner.service.model.AmberEvent
|
||||
import com.vitorpamplona.quartz.crypto.CryptoUtils
|
||||
import com.vitorpamplona.quartz.crypto.Nip44Version
|
||||
import com.vitorpamplona.quartz.crypto.decodeNIP44
|
||||
@@ -12,6 +12,7 @@ import com.vitorpamplona.quartz.encoders.Bech32
|
||||
import com.vitorpamplona.quartz.encoders.HexKey
|
||||
import com.vitorpamplona.quartz.encoders.hexToByteArray
|
||||
import com.vitorpamplona.quartz.encoders.toHexKey
|
||||
import com.vitorpamplona.quartz.events.Event
|
||||
import com.vitorpamplona.quartz.events.LnZapPrivateEvent
|
||||
import com.vitorpamplona.quartz.events.LnZapRequestEvent
|
||||
import fr.acinq.secp256k1.Hex
|
||||
@@ -22,10 +23,10 @@ import javax.crypto.spec.IvParameterSpec
|
||||
import javax.crypto.spec.SecretKeySpec
|
||||
|
||||
object AmberUtils {
|
||||
fun getSignedEvent(unsignedEvent: Event, privateKey: ByteArray): Event {
|
||||
fun getSignedEvent(unsignedEvent: AmberEvent, privateKey: ByteArray): AmberEvent {
|
||||
val id = unsignedEvent.id.hexToByteArray()
|
||||
val sig = CryptoUtils.sign(id, privateKey).toHexKey()
|
||||
return Event(
|
||||
return AmberEvent(
|
||||
unsignedEvent.id,
|
||||
unsignedEvent.pubKey,
|
||||
unsignedEvent.createdAt,
|
||||
@@ -55,7 +56,7 @@ object AmberUtils {
|
||||
privkey = encryptionPrivateKey // sign event with generated privkey
|
||||
val pubKey = CryptoUtils.pubkeyCreate(encryptionPrivateKey).toHexKey() // updated event with according pubkey
|
||||
|
||||
val id = Event.generateId(
|
||||
val id = AmberEvent.generateId(
|
||||
pubKey,
|
||||
localEvent.createdAt,
|
||||
LnZapRequestEvent.kind,
|
||||
@@ -131,7 +132,7 @@ object AmberUtils {
|
||||
}
|
||||
}
|
||||
private fun decryptZapEvent(data: String, account: Account): String? {
|
||||
val event = com.vitorpamplona.quartz.events.Event.fromJson(data) as LnZapRequestEvent
|
||||
val event = Event.fromJson(data) as LnZapRequestEvent
|
||||
|
||||
val loggedInPrivateKey = account.keyPair.privKey
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import android.content.Intent
|
||||
import android.net.Uri
|
||||
import com.greenart7c3.nostrsigner.models.IntentData
|
||||
import com.greenart7c3.nostrsigner.models.SignerType
|
||||
import com.greenart7c3.nostrsigner.service.model.Event
|
||||
import com.greenart7c3.nostrsigner.service.model.AmberEvent
|
||||
import java.net.URLDecoder
|
||||
|
||||
object IntentUtils {
|
||||
@@ -41,10 +41,10 @@ object IntentUtils {
|
||||
}
|
||||
return null
|
||||
}
|
||||
fun getIntent(data: String, keyPair: KeyPair): Event {
|
||||
var event = Event.fromJson(data)
|
||||
fun getIntent(data: String, keyPair: KeyPair): AmberEvent {
|
||||
var event = AmberEvent.fromJson(data)
|
||||
if (event.pubKey.isEmpty()) {
|
||||
event = Event.setPubKeyIfEmpty(event, keyPair)
|
||||
event = AmberEvent.setPubKeyIfEmpty(event, keyPair)
|
||||
}
|
||||
return event
|
||||
}
|
||||
|
||||
+15
-15
@@ -27,7 +27,7 @@ import java.math.BigDecimal
|
||||
import java.util.*
|
||||
|
||||
@Immutable
|
||||
open class Event(
|
||||
open class AmberEvent(
|
||||
val id: HexKey,
|
||||
@SerializedName("pubkey") val pubKey: HexKey,
|
||||
@SerializedName("created_at") val createdAt: Long,
|
||||
@@ -35,7 +35,7 @@ open class Event(
|
||||
val tags: List<List<String>>,
|
||||
val content: String,
|
||||
val sig: HexKey
|
||||
) : EventInterface {
|
||||
) : AmberEventInterface {
|
||||
override fun id(): HexKey = id
|
||||
|
||||
override fun pubKey(): HexKey = pubKey
|
||||
@@ -228,14 +228,14 @@ open class Event(
|
||||
return CryptoUtils.sha256(rawEventJson.toByteArray()).toHexKey()
|
||||
}
|
||||
|
||||
private class EventDeserializer : JsonDeserializer<Event> {
|
||||
private class EventDeserializer : JsonDeserializer<AmberEvent> {
|
||||
override fun deserialize(
|
||||
json: JsonElement,
|
||||
typeOfT: Type?,
|
||||
context: JsonDeserializationContext?
|
||||
): Event {
|
||||
): AmberEvent {
|
||||
val jsonObject = json.asJsonObject
|
||||
return Event(
|
||||
return AmberEvent(
|
||||
id = jsonObject.get("id")?.asString ?: "",
|
||||
pubKey = jsonObject.get("pubkey")?.asString ?: "",
|
||||
createdAt = jsonObject.get("created_at")?.asLong ?: TimeUtils.now(),
|
||||
@@ -249,9 +249,9 @@ open class Event(
|
||||
}
|
||||
}
|
||||
|
||||
private class EventSerializer : JsonSerializer<Event> {
|
||||
private class EventSerializer : JsonSerializer<AmberEvent> {
|
||||
override fun serialize(
|
||||
src: Event,
|
||||
src: AmberEvent,
|
||||
typeOfSrc: Type?,
|
||||
context: JsonSerializationContext?
|
||||
): JsonElement {
|
||||
@@ -405,17 +405,17 @@ open class Event(
|
||||
companion object {
|
||||
val gson: Gson = GsonBuilder()
|
||||
.disableHtmlEscaping()
|
||||
.registerTypeAdapter(Event::class.java, EventSerializer())
|
||||
.registerTypeAdapter(Event::class.java, EventDeserializer())
|
||||
.registerTypeAdapter(AmberEvent::class.java, EventSerializer())
|
||||
.registerTypeAdapter(AmberEvent::class.java, EventDeserializer())
|
||||
.registerTypeAdapter(ByteArray::class.java, ByteArraySerializer())
|
||||
.registerTypeAdapter(ByteArray::class.java, ByteArrayDeserializer())
|
||||
.registerTypeAdapter(Response::class.java, ResponseDeserializer())
|
||||
.registerTypeAdapter(Request::class.java, RequestDeserializer())
|
||||
.create()
|
||||
|
||||
fun fromJson(json: String): Event = gson.fromJson(json, Event::class.java).getRefinedEvent()
|
||||
fun fromJson(json: String): AmberEvent = gson.fromJson(json, AmberEvent::class.java).getRefinedEvent()
|
||||
|
||||
fun Event.getRefinedEvent(): Event = when (kind) {
|
||||
fun AmberEvent.getRefinedEvent(): AmberEvent = when (kind) {
|
||||
else -> this
|
||||
}
|
||||
|
||||
@@ -440,22 +440,22 @@ open class Event(
|
||||
return CryptoUtils.sha256(rawEventJson.toByteArray())
|
||||
}
|
||||
|
||||
fun setPubKeyIfEmpty(event: Event, keyPair: KeyPair): Event {
|
||||
fun setPubKeyIfEmpty(event: AmberEvent, keyPair: KeyPair): AmberEvent {
|
||||
if (event.pubKey.isEmpty()) {
|
||||
val pubKey = keyPair.pubKey.toHexKey()
|
||||
val id = generateId(pubKey, event.createdAt, event.kind, event.tags, event.content)
|
||||
val signature = CryptoUtils.sign(id, keyPair.privKey).toHexKey()
|
||||
return Event(id.toHexKey(), pubKey, event.createdAt, event.kind, event.tags, event.content, signature)
|
||||
return AmberEvent(id.toHexKey(), pubKey, event.createdAt, event.kind, event.tags, event.content, signature)
|
||||
}
|
||||
|
||||
return event
|
||||
}
|
||||
|
||||
fun create(privateKey: ByteArray, kind: Int, tags: List<List<String>> = emptyList(), content: String = "", createdAt: Long = TimeUtils.now()): Event {
|
||||
fun create(privateKey: ByteArray, kind: Int, tags: List<List<String>> = emptyList(), content: String = "", createdAt: Long = TimeUtils.now()): AmberEvent {
|
||||
val pubKey = CryptoUtils.pubkeyCreate(privateKey).toHexKey()
|
||||
val id = generateId(pubKey, createdAt, kind, tags, content)
|
||||
val sig = CryptoUtils.sign(id, privateKey).toHexKey()
|
||||
return Event(id.toHexKey(), pubKey, createdAt, kind, tags, content, sig)
|
||||
return AmberEvent(id.toHexKey(), pubKey, createdAt, kind, tags, content, sig)
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -7,7 +7,7 @@ import com.vitorpamplona.quartz.events.EmojiUrl
|
||||
import java.math.BigDecimal
|
||||
|
||||
@Immutable
|
||||
interface EventInterface {
|
||||
interface AmberEventInterface {
|
||||
fun id(): HexKey
|
||||
|
||||
fun pubKey(): HexKey
|
||||
@@ -26,7 +26,7 @@ import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.greenart7c3.nostrsigner.R
|
||||
import com.greenart7c3.nostrsigner.models.TimeUtils
|
||||
import com.greenart7c3.nostrsigner.service.model.Event
|
||||
import com.greenart7c3.nostrsigner.service.model.AmberEvent
|
||||
import com.greenart7c3.nostrsigner.service.toShortenHex
|
||||
|
||||
@Composable
|
||||
@@ -35,7 +35,7 @@ fun EventData(
|
||||
remember: MutableState<Boolean>,
|
||||
packageName: String?,
|
||||
appName: String,
|
||||
event: Event,
|
||||
event: AmberEvent,
|
||||
rawJson: String,
|
||||
onAccept: () -> Unit,
|
||||
onReject: () -> Unit
|
||||
|
||||
@@ -10,7 +10,7 @@ import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import com.greenart7c3.nostrsigner.models.TimeUtils
|
||||
import com.greenart7c3.nostrsigner.service.model.Event
|
||||
import com.greenart7c3.nostrsigner.service.model.AmberEvent
|
||||
import com.greenart7c3.nostrsigner.ui.components.EventData
|
||||
import com.greenart7c3.nostrsigner.ui.theme.NostrSignerTheme
|
||||
|
||||
@@ -18,7 +18,7 @@ import com.greenart7c3.nostrsigner.ui.theme.NostrSignerTheme
|
||||
@Preview(device = "id:Nexus S")
|
||||
@Composable
|
||||
fun EventDataPreview() {
|
||||
val event = Event("123", "7579076d9aff0a4cfdefa7e2045f2486c7e5d8bc63bfc6b45397233e1bbfcb19", TimeUtils.now(), 1, listOf(), "This is a test 123 123 123 123 123 123", "")
|
||||
val event = AmberEvent("123", "7579076d9aff0a4cfdefa7e2045f2486c7e5d8bc63bfc6b45397233e1bbfcb19", TimeUtils.now(), 1, listOf(), "This is a test 123 123 123 123 123 123", "")
|
||||
val data = event.toJson()
|
||||
val remember = remember { mutableStateOf(false) }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user