Migrate to the new quartz format

This commit is contained in:
greenart7c3
2025-03-19 17:13:29 -03:00
parent bb49014c7e
commit e577877728
26 changed files with 155 additions and 152 deletions
@@ -12,13 +12,12 @@ import com.greenart7c3.nostrsigner.okhttp.HttpClientManager
import com.greenart7c3.nostrsigner.ui.parseBiometricsTimeType
import com.vitorpamplona.ammolite.relays.COMMON_FEED_TYPES
import com.vitorpamplona.ammolite.relays.RelaySetupInfo
import com.vitorpamplona.quartz.crypto.CryptoUtils
import com.vitorpamplona.quartz.crypto.KeyPair
import com.vitorpamplona.quartz.encoders.HexKey
import com.vitorpamplona.quartz.encoders.hexToByteArray
import com.vitorpamplona.quartz.encoders.toHexKey
import com.vitorpamplona.quartz.signers.NostrSignerInternal
import fr.acinq.secp256k1.jni.BuildConfig
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerInternal
import com.vitorpamplona.quartz.nip49PrivKeyEnc.Nip49
import java.io.File
// Release mode (!BuildConfig.DEBUG) always uses encrypted preferences
@@ -369,7 +368,7 @@ object LocalPreferences {
password: String,
) {
val context = NostrSigner.getInstance()
val ncryptsec = CryptoUtils.nip49.encrypt(privateKeyHex, password)
val ncryptsec = Nip49().encrypt(privateKeyHex, password)
encryptedPreferences(context, npub).edit {
apply {
putString(PrefKeys.NCRYPT_SEC, ncryptsec)
@@ -1,6 +1,5 @@
package com.greenart7c3.nostrsigner
import android.app.Activity
import android.content.Intent
import android.net.ConnectivityManager
import android.os.Bundle
@@ -46,7 +45,7 @@ import com.greenart7c3.nostrsigner.ui.BiometricsTimeType
import com.greenart7c3.nostrsigner.ui.components.RandomPinInput
import com.greenart7c3.nostrsigner.ui.navigation.Route
import com.greenart7c3.nostrsigner.ui.theme.NostrSignerTheme
import com.vitorpamplona.quartz.encoders.toNpub
import com.vitorpamplona.quartz.nip19Bech32.toNpub
import fr.acinq.secp256k1.Hex
import java.time.Duration
import java.time.Instant
@@ -97,7 +96,7 @@ class MainActivity : AppCompatActivity() {
var showPinDialog by remember { mutableStateOf(false) }
val keyguardLauncher =
rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) { result: ActivityResult ->
if (result.resultCode == Activity.RESULT_OK) {
if (result.resultCode == RESULT_OK) {
isAuthenticated = true
}
}
@@ -3,8 +3,8 @@ package com.greenart7c3.nostrsigner
import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.util.Log
import androidx.core.net.toUri
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.navigation.NavHostController
@@ -12,7 +12,7 @@ import com.greenart7c3.nostrsigner.models.IntentData
import com.greenart7c3.nostrsigner.service.BunkerRequestUtils
import com.greenart7c3.nostrsigner.service.IntentUtils
import com.greenart7c3.nostrsigner.ui.navigation.Route
import com.vitorpamplona.quartz.encoders.toNpub
import com.vitorpamplona.quartz.nip19Bech32.toNpub
import fr.acinq.secp256k1.Hex
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
@@ -96,7 +96,7 @@ class MainViewModel(val context: Context) : ViewModel() {
requests.forEach {
val contentIntent =
Intent(NostrSigner.getInstance(), MainActivity::class.java).apply {
data = Uri.parse("nostrsigner:")
data = "nostrsigner:".toUri()
}
contentIntent.putExtra("bunker", it.toJson())
contentIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
@@ -28,9 +28,9 @@ import com.vitorpamplona.ammolite.relays.RelaySetupInfo
import com.vitorpamplona.ammolite.relays.RelaySetupInfoToConnect
import com.vitorpamplona.ammolite.relays.TypedFilter
import com.vitorpamplona.ammolite.relays.filters.SincePerRelayFilter
import com.vitorpamplona.quartz.events.Event
import com.vitorpamplona.quartz.events.EventInterface
import com.vitorpamplona.quartz.events.MetadataEvent
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.metadata.MetadataEvent
import com.vitorpamplona.quartz.nip01Core.relay.RelayState
import com.vitorpamplona.quartz.utils.TimeUtils
import java.util.UUID
import java.util.concurrent.ConcurrentHashMap
@@ -43,7 +43,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
class NostrSigner : Application() {
val client: NostrClient = NostrClient(OkHttpWebSocket.Builder())
val client: NostrClient = NostrClient(OkHttpWebSocket.BuilderFactory())
val applicationIOScope = CoroutineScope(Dispatchers.IO + SupervisorJob())
private var databases = ConcurrentHashMap<String, AppDatabase>()
lateinit var settings: AmberSettings
@@ -185,7 +185,7 @@ class NostrSigner : Application() {
Log.d("NostrSigner", "Checking if relays are connected")
client.getAll().forEach { relay ->
if (!relay.isConnected()) {
relay.connectAndRun {
relay.connectAndRunAfterSync {
val builder = OneTimeWorkRequest.Builder(RelayDisconnectService::class.java)
val inputData = Data.Builder()
inputData.putString("relay", relay.url)
@@ -267,7 +267,7 @@ class NostrSigner : Application() {
read = it.read,
write = it.write,
activeTypes = it.feedTypes,
socketBuilder = OkHttpWebSocket.Builder(),
socketBuilderFactory = OkHttpWebSocket.BuilderFactory(),
forceProxy = account.useProxy,
subs = MutableSubscriptionManager(),
)
@@ -275,8 +275,8 @@ class NostrSigner : Application() {
relays.forEach {
it.register(listener)
it.connectAndRun { relay ->
relay.sendFilter(
it.connectAndRunAfterSync {
it.sendFilter(
UUID.randomUUID().toString().substring(0, 4),
filters = listOf(
TypedFilter(
@@ -319,8 +319,8 @@ class RelayListener(
Log.d("RelayListener", "Received auth challenge $challenge from relay ${relay.url}")
}
override fun onBeforeSend(relay: Relay, event: EventInterface) {
Log.d("RelayListener", "Sending event ${event.id()} to relay ${relay.url}")
override fun onBeforeSend(relay: Relay, event: Event) {
Log.d("RelayListener", "Sending event ${event.id} to relay ${relay.url}")
}
override fun onError(relay: Relay, subscriptionId: String, error: Error) {
@@ -332,11 +332,15 @@ class RelayListener(
onReceiveEvent(relay, subscriptionId, event)
}
override fun onEOSE(relay: Relay, subscriptionId: String) {
Log.d("RelayListener", "Received EOSE from subscription $subscriptionId")
}
override fun onNotify(relay: Relay, description: String) {
Log.d("RelayListener", "Received notify $description from relay ${relay.url}")
}
override fun onRelayStateChange(relay: Relay, type: Relay.StateType, channel: String?) {
override fun onRelayStateChange(relay: Relay, type: RelayState) {
Log.d("RelayListener", "Relay ${relay.url} state changed to $type")
}
@@ -357,8 +361,8 @@ class RelayListener2(
Log.d("RelayListener", "Received auth challenge $challenge from relay ${relay.url}")
}
override fun onBeforeSend(relay: Relay, event: EventInterface) {
Log.d("RelayListener", "Sending event ${event.id()} to relay ${relay.url}")
override fun onBeforeSend(relay: Relay, event: Event) {
Log.d("RelayListener", "Sending event ${event.id} to relay ${relay.url}")
}
override fun onError(error: Error, subscriptionId: String, relay: Relay) {
@@ -374,7 +378,7 @@ class RelayListener2(
Log.d("RelayListener", "Received notify $description from relay ${relay.url}")
}
override fun onRelayStateChange(type: Relay.StateType, relay: Relay, subscriptionId: String?) {
override fun onRelayStateChange(type: RelayState, relay: Relay) {
Log.d("RelayListener", "Relay ${relay.url} state changed to $type")
}
@@ -12,10 +12,10 @@ import com.greenart7c3.nostrsigner.models.SignerType
import com.greenart7c3.nostrsigner.models.kindToNip
import com.greenart7c3.nostrsigner.service.AmberUtils
import com.greenart7c3.nostrsigner.service.IntentUtils
import com.vitorpamplona.quartz.crypto.CryptoUtils
import com.vitorpamplona.quartz.encoders.toHexKey
import com.vitorpamplona.quartz.events.Event
import com.vitorpamplona.quartz.events.LnZapRequestEvent
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import com.vitorpamplona.quartz.nip55AndroidSigner.signString
import com.vitorpamplona.quartz.nip57Zaps.LnZapRequestEvent
import com.vitorpamplona.quartz.utils.TimeUtils
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@@ -94,7 +94,7 @@ class SignerProvider : ContentProvider() {
return cursor
}
val result = CryptoUtils.signString(message, account.signer.keyPair.privKey!!).toHexKey()
val result = signString(message, account.signer.keyPair.privKey!!).toHexKey()
scope.launch {
database.applicationDao().addHistory(
HistoryEntity(
@@ -3,11 +3,11 @@ package com.greenart7c3.nostrsigner.models
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.Stable
import androidx.lifecycle.LiveData
import com.vitorpamplona.quartz.encoders.HexKey
import com.vitorpamplona.quartz.encoders.toHexKey
import com.vitorpamplona.quartz.encoders.toNpub
import com.vitorpamplona.quartz.events.RelayAuthEvent
import com.vitorpamplona.quartz.signers.NostrSignerInternal
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerInternal
import com.vitorpamplona.quartz.nip19Bech32.toNpub
import com.vitorpamplona.quartz.nip42RelayAuth.RelayAuthEvent
@Stable
class Account(
@@ -1,8 +1,8 @@
package com.greenart7c3.nostrsigner.models
import androidx.compose.runtime.MutableState
import com.vitorpamplona.quartz.encoders.HexKey
import com.vitorpamplona.quartz.events.Event
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.HexKey
data class IntentData(
val data: String,
@@ -21,8 +21,8 @@
package com.greenart7c3.nostrsigner.okhttp
import android.util.Log
import com.vitorpamplona.quartz.crypto.nip17.AESGCM
import com.vitorpamplona.quartz.crypto.nip17.NostrCipher
import com.vitorpamplona.quartz.nip17Dm.files.encryption.AESGCM
import com.vitorpamplona.quartz.nip17Dm.files.encryption.NostrCipher
import okhttp3.Interceptor
import okhttp3.Response
import okhttp3.ResponseBody.Companion.toResponseBody
@@ -21,7 +21,7 @@
package com.greenart7c3.nostrsigner.okhttp
import android.util.LruCache
import com.vitorpamplona.quartz.crypto.nip17.NostrCipher
import com.vitorpamplona.quartz.nip17Dm.files.encryption.NostrCipher
/**
* Neigther ExoPlayer, nor Coil support passing key and nonce to the Interceptor via
@@ -20,21 +20,22 @@
*/
package com.greenart7c3.nostrsigner.okhttp
import com.vitorpamplona.ammolite.sockets.WebSocket
import com.vitorpamplona.ammolite.sockets.WebSocketListener
import com.vitorpamplona.ammolite.sockets.WebsocketBuilder
import com.vitorpamplona.quartz.nip01Core.relay.sockets.WebSocket
import com.vitorpamplona.quartz.nip01Core.relay.sockets.WebSocketListener
import com.vitorpamplona.quartz.nip01Core.relay.sockets.WebsocketBuilder
import com.vitorpamplona.quartz.nip01Core.relay.sockets.WebsocketBuilderFactory
import okhttp3.Request
import okhttp3.Response
class OkHttpWebSocket(
val url: String,
private val forceProxy: Boolean,
val forceProxy: Boolean,
val out: WebSocketListener,
) : WebSocket {
private val listener = OkHttpWebsocketListener()
private var socket: okhttp3.WebSocket? = null
private fun buildRequest() = Request.Builder().url(url.trim()).build()
fun buildRequest() = Request.Builder().url(url.trim()).build()
override fun connect() {
socket = HttpClientManager.getHttpClient(forceProxy).newWebSocket(buildRequest(), listener)
@@ -46,7 +47,7 @@ class OkHttpWebSocket(
response: Response,
) = out.onOpen(
response.receivedResponseAtMillis - response.sentRequestAtMillis,
response.headers["Sec-WebSocket-Extensions"]?.contains("permessage-deflate") ?: false,
response.headers.get("Sec-WebSocket-Extensions")?.contains("permessage-deflate") ?: false,
)
override fun onMessage(
@@ -73,14 +74,19 @@ class OkHttpWebSocket(
) = out.onFailure(t, response?.message)
}
class Builder : WebsocketBuilder {
class Builder(
val forceProxy: Boolean,
) : WebsocketBuilder {
override fun build(
url: String,
forceProxy: Boolean,
out: WebSocketListener,
) = OkHttpWebSocket(url, forceProxy, out)
}
class BuilderFactory : WebsocketBuilderFactory {
override fun build(forceProxy: Boolean) = Builder(forceProxy)
}
override fun cancel() {
socket?.cancel()
}
@@ -8,8 +8,8 @@ import com.greenart7c3.nostrsigner.database.LogEntity
import com.greenart7c3.nostrsigner.ui.AccountStateViewModel
import com.vitorpamplona.ammolite.relays.NostrClient
import com.vitorpamplona.ammolite.relays.Relay
import com.vitorpamplona.quartz.events.Event
import com.vitorpamplona.quartz.events.EventInterface
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.relay.RelayState
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
@@ -53,7 +53,7 @@ class AmberClientListener(
}
}
override fun onBeforeSend(relay: Relay, event: EventInterface) {
override fun onBeforeSend(relay: Relay, event: Event) {
scope.launch {
LocalPreferences.currentAccount(context)?.let { account ->
NostrSigner.getInstance().getDatabase(account).applicationDao().insertLog(
@@ -61,7 +61,7 @@ class AmberClientListener(
id = 0,
url = relay.url,
type = "onBeforeSend",
message = "Sending event ${event.id()}",
message = "Sending event ${event.id}",
time = System.currentTimeMillis(),
),
)
@@ -139,7 +139,7 @@ class AmberClientListener(
id = 0,
url = relay.url,
type = "onEvent",
message = "Received event ${event.id()} from subscription $subscriptionId afterEOSE: $afterEOSE",
message = "Received event ${event.id} from subscription $subscriptionId afterEOSE: $afterEOSE",
time = System.currentTimeMillis(),
),
)
@@ -163,7 +163,7 @@ class AmberClientListener(
}
}
override fun onRelayStateChange(type: Relay.StateType, relay: Relay, subscriptionId: String?) {
override fun onRelayStateChange(type: RelayState, relay: Relay) {
scope.launch {
LocalPreferences.currentAccount(context)?.let { account ->
NostrSigner.getInstance().getDatabase(account).applicationDao().insertLog(
@@ -13,12 +13,15 @@ import com.greenart7c3.nostrsigner.models.SignerType
import com.greenart7c3.nostrsigner.models.kindToNip
import com.greenart7c3.nostrsigner.ui.IntentResultType
import com.vitorpamplona.ammolite.relays.RelaySetupInfo
import com.vitorpamplona.quartz.crypto.CryptoUtils
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.LnZapRequestEvent
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import com.vitorpamplona.quartz.nip01Core.crypto.Nip01
import com.vitorpamplona.quartz.nip04Dm.crypto.Nip04
import com.vitorpamplona.quartz.nip44Encryption.Nip44
import com.vitorpamplona.quartz.nip57Zaps.LnZapRequestEvent
import com.vitorpamplona.quartz.nip57Zaps.PrivateZapEncryption
import fr.acinq.secp256k1.Hex
object AmberUtils {
@@ -33,28 +36,28 @@ object AmberUtils {
decryptZapEvent(data, account)
}
SignerType.NIP04_DECRYPT -> {
CryptoUtils.decryptNIP04(
Nip04.decrypt(
data,
account.signer.keyPair.privKey!!,
Hex.decode(pubKey),
)
}
SignerType.NIP04_ENCRYPT -> {
CryptoUtils.encryptNIP04(
Nip04.encrypt(
data,
account.signer.keyPair.privKey!!,
Hex.decode(pubKey),
)
}
SignerType.NIP44_ENCRYPT -> {
CryptoUtils.encryptNIP44(
Nip44.encrypt(
data,
account.signer.keyPair.privKey!!,
pubKey.hexToByteArray(),
).encodePayload()
}
else -> {
CryptoUtils.decryptNIP44(
Nip44.decrypt(
data,
account.signer.keyPair.privKey!!,
pubKey.hexToByteArray(),
@@ -83,13 +86,13 @@ object AmberUtils {
// if the sender is logged in, these are the params
val altPrivateKeyToUse =
if (recipientPost != null) {
LnZapRequestEvent.createEncryptionPrivateKey(
PrivateZapEncryption.createEncryptionPrivateKey(
loggedInPrivateKey!!.toHexKey(),
recipientPost,
event.createdAt,
)
} else if (recipientPK != null) {
LnZapRequestEvent.createEncryptionPrivateKey(
PrivateZapEncryption.createEncryptionPrivateKey(
loggedInPrivateKey!!.toHexKey(),
recipientPK,
event.createdAt,
@@ -100,7 +103,7 @@ object AmberUtils {
try {
if (altPrivateKeyToUse != null && recipientPK != null) {
val altPubKeyFromPrivate = CryptoUtils.pubkeyCreate(altPrivateKeyToUse).toHexKey()
val altPubKeyFromPrivate = Nip01.pubKeyCreate(altPrivateKeyToUse).toHexKey()
if (altPubKeyFromPrivate == event.pubKey) {
val result = event.getPrivateZapEvent(altPrivateKeyToUse, recipientPK)
@@ -22,7 +22,7 @@ import com.greenart7c3.nostrsigner.relays.AmberListenerSingleton
import com.greenart7c3.nostrsigner.service.IntentUtils.getUnsignedEvent
import com.greenart7c3.nostrsigner.service.model.AmberEvent
import com.vitorpamplona.ammolite.relays.RelaySetupInfo
import com.vitorpamplona.quartz.events.Event
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.utils.TimeUtils
import java.util.concurrent.ConcurrentHashMap
import kotlinx.coroutines.channels.Channel
@@ -46,10 +46,10 @@ import com.greenart7c3.nostrsigner.service.model.AmberEvent
import com.vitorpamplona.ammolite.relays.COMMON_FEED_TYPES
import com.vitorpamplona.ammolite.relays.Relay
import com.vitorpamplona.ammolite.relays.RelaySetupInfo
import com.vitorpamplona.quartz.crypto.nip04.Nip04
import com.vitorpamplona.quartz.encoders.Hex
import com.vitorpamplona.quartz.encoders.toNpub
import com.vitorpamplona.quartz.events.Event
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.tags.people.taggedUsers
import com.vitorpamplona.quartz.nip01Core.verify
import com.vitorpamplona.quartz.nip04Dm.crypto.EncryptedInfo
import com.vitorpamplona.quartz.utils.TimeUtils
import kotlinx.coroutines.launch
@@ -82,21 +82,17 @@ class EventNotificationConsumer(private val applicationContext: Context) {
saveLog("notifications disabled")
return
}
if (event.kind() != 24133) {
if (event.kind != 24133) {
saveLog("Not a bunker request")
return
}
if (!event.hasCorrectIDHash()) {
saveLog("Invalid id hash")
return
}
if (!event.hasVerifiedSignature()) {
saveLog("Invalid signature")
if (!event.verify()) {
saveLog("Invalid id hash or signature")
return
}
val taggedKey = event.taggedUsers().firstOrNull() ?: return
LocalPreferences.loadFromEncryptedStorage(applicationContext, Hex.decode(taggedKey).toNpub())?.let { acc ->
LocalPreferences.loadFromEncryptedStorage(applicationContext, taggedKey.toNPub())?.let { acc ->
notify(event, acc, relay)
}
}
@@ -121,7 +117,7 @@ class EventNotificationConsumer(private val applicationContext: Context) {
)
}
if (Nip04.isNIP04(event.content)) {
if (EncryptedInfo.isNIP04(event.content)) {
acc.signer.nip04Decrypt(event.content, event.pubKey) {
NostrSigner.getInstance().applicationIOScope.launch {
notify(event, acc, it, EncryptionType.NIP04, relay)
@@ -147,7 +143,7 @@ class EventNotificationConsumer(private val applicationContext: Context) {
val dao = NostrSigner.getInstance().getDatabase(acc.npub).applicationDao()
val notification = dao.getNotification(event.id)
if (notification != null) return
dao.insertNotification(NotificationEntity(0, event.id(), event.createdAt))
dao.insertNotification(NotificationEntity(0, event.id, event.createdAt))
dao.insertLog(
LogEntity(
@@ -29,9 +29,9 @@ import com.greenart7c3.nostrsigner.models.ReturnType
import com.greenart7c3.nostrsigner.models.SignerType
import com.greenart7c3.nostrsigner.models.containsNip
import com.greenart7c3.nostrsigner.service.model.AmberEvent
import com.vitorpamplona.quartz.encoders.toHexKey
import com.vitorpamplona.quartz.encoders.toNpub
import com.vitorpamplona.quartz.events.Event
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher
import com.vitorpamplona.quartz.nip19Bech32.toNpub
import fr.acinq.secp256k1.Hex
import java.net.URLDecoder
import kotlinx.coroutines.launch
@@ -316,7 +316,7 @@ object IntentUtils {
val data =
try {
decodeData(intent.data?.toString() ?: "", packageName == null, packageName == null)
} catch (e: Exception) {
} catch (_: Exception) {
intent.data?.toString()?.replace("nostrsigner:", "") ?: ""
}
@@ -496,7 +496,7 @@ object IntentUtils {
}
return try {
Hex.decode(key).toNpub()
} catch (e: Exception) {
} catch (_: Exception) {
null
}
}
@@ -562,13 +562,13 @@ object IntentUtils {
}
if (event.id.isEmpty()) {
event.id =
Event.generateId(
EventHasher.hashId(
event.pubKey,
event.createdAt,
event.kind,
event.tags,
event.content,
).toHexKey()
)
}
return AmberEvent.toEvent(event)
@@ -23,7 +23,7 @@ package com.greenart7c3.nostrsigner.service
import android.util.Log
import com.greenart7c3.nostrsigner.checkNotInMainThread
import com.greenart7c3.nostrsigner.okhttp.HttpClientManager
import com.vitorpamplona.quartz.encoders.Nip11RelayInformation
import com.vitorpamplona.quartz.nip11RelayInfo.Nip11RelayInformation
import java.io.IOException
import kotlinx.coroutines.CancellationException
import okhttp3.Call
@@ -33,8 +33,9 @@ import com.vitorpamplona.ammolite.relays.Relay
import com.vitorpamplona.ammolite.relays.TypedFilter
import com.vitorpamplona.ammolite.relays.filters.EOSETime
import com.vitorpamplona.ammolite.relays.filters.SincePerRelayFilter
import com.vitorpamplona.quartz.encoders.toHexKey
import com.vitorpamplona.quartz.events.Event
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import com.vitorpamplona.quartz.nip01Core.relay.RelayState
import com.vitorpamplona.quartz.utils.TimeUtils
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@@ -60,7 +61,7 @@ object NotificationDataSource : NostrDataSource(NostrSigner.getInstance().client
id = 0,
url = relay.url,
type = "onEvent",
message = "Received event ${event.id()} from subscription $subscriptionId afterEOSE: $afterEOSE",
message = "Received event ${event.id} from subscription $subscriptionId afterEOSE: $afterEOSE",
time = System.currentTimeMillis(),
),
)
@@ -68,11 +69,7 @@ object NotificationDataSource : NostrDataSource(NostrSigner.getInstance().client
}
}
override fun onRelayStateChange(
type: Relay.StateType,
relay: Relay,
subscriptionId: String?,
) {
override fun onRelayStateChange(type: RelayState, relay: Relay) {
Log.d("NotificationDataSource", "onRelayStateChange: $type")
AmberRelayStats.updateNotification()
scope.launch {
@@ -11,8 +11,8 @@ import com.google.gson.JsonObject
import com.google.gson.JsonSerializationContext
import com.google.gson.JsonSerializer
import com.google.gson.annotations.SerializedName
import com.vitorpamplona.quartz.encoders.HexKey
import com.vitorpamplona.quartz.events.Event
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.utils.TimeUtils
import java.lang.reflect.Type
@@ -7,10 +7,11 @@ import androidx.lifecycle.viewModelScope
import com.greenart7c3.nostrsigner.LocalPreferences
import com.greenart7c3.nostrsigner.NostrSigner
import com.greenart7c3.nostrsigner.models.Account
import com.vitorpamplona.quartz.crypto.CryptoUtils
import com.vitorpamplona.quartz.crypto.KeyPair
import com.vitorpamplona.quartz.encoders.bechToBytes
import com.vitorpamplona.quartz.signers.NostrSignerInternal
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerInternal
import com.vitorpamplona.quartz.nip06KeyDerivation.Nip06
import com.vitorpamplona.quartz.nip19Bech32.bech32.bechToBytes
import com.vitorpamplona.quartz.nip49PrivKeyEnc.Nip49
import fr.acinq.secp256k1.Hex
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.BufferOverflow
@@ -130,9 +131,8 @@ class AccountStateViewModel(npub: String?) : ViewModel() {
try {
val account =
if (key.startsWith("ncryptsec")) {
val newKey =
CryptoUtils.decryptNIP49(key, password)
?: throw Exception("Could not decrypt key with provided password")
val newKey = Nip49().decrypt(key, password)
Account(
signer = NostrSignerInternal(KeyPair(Hex.decode(newKey))),
name = "",
@@ -154,8 +154,8 @@ class AccountStateViewModel(npub: String?) : ViewModel() {
signPolicy = 0,
seedWords = emptySet(),
)
} else if (key.contains(" ") && CryptoUtils.isValidMnemonic(key)) {
val keyPair = KeyPair(privKey = CryptoUtils.privateKeyFromMnemonic(key))
} else if (key.contains(" ") && Nip06().isValidMnemonic(key)) {
val keyPair = KeyPair(privKey = Nip06().privateKeyFromMnemonic(key))
Account(
signer = NostrSignerInternal(keyPair),
name = "",
@@ -179,7 +179,7 @@ class AccountStateViewModel(npub: String?) : ViewModel() {
)
}
return account.signer.keyPair.privKey != null
} catch (e: Exception) {
} catch (_: Exception) {
return false
}
}
@@ -194,9 +194,7 @@ class AccountStateViewModel(npub: String?) : ViewModel() {
) {
val account =
if (key.startsWith("ncryptsec")) {
val newKey =
CryptoUtils.decryptNIP49(key, password)
?: throw Exception("Could not decrypt key with provided password")
val newKey = Nip49().decrypt(key, password)
Account(
signer = NostrSignerInternal(KeyPair(Hex.decode(newKey))),
name = "",
@@ -218,8 +216,8 @@ class AccountStateViewModel(npub: String?) : ViewModel() {
signPolicy = signPolicy,
seedWords = emptySet(),
)
} else if (key.contains(" ") && CryptoUtils.isValidMnemonic(key)) {
val keyPair = KeyPair(privKey = CryptoUtils.privateKeyFromMnemonic(key))
} else if (key.contains(" ") && Nip06().isValidMnemonic(key)) {
val keyPair = KeyPair(privKey = Nip06().privateKeyFromMnemonic(key))
Account(
signer = NostrSignerInternal(keyPair),
name = "",
@@ -255,7 +253,7 @@ class AccountStateViewModel(npub: String?) : ViewModel() {
name: String,
) {
val key = seedWords.joinToString(separator = " ") { it }
val keyPair = KeyPair(privKey = CryptoUtils.privateKeyFromMnemonic(key))
val keyPair = KeyPair(privKey = Nip06().privateKeyFromMnemonic(key))
val account = Account(
NostrSignerInternal(keyPair),
name = name,
@@ -108,12 +108,13 @@ import com.halilibo.richtext.commonmark.CommonmarkAstNodeParser
import com.halilibo.richtext.commonmark.MarkdownParseOptions
import com.halilibo.richtext.markdown.BasicMarkdown
import com.halilibo.richtext.ui.material3.RichText
import com.vitorpamplona.quartz.crypto.CryptoUtils
import com.vitorpamplona.quartz.crypto.CryptoUtils.random
import com.vitorpamplona.quartz.crypto.KeyPair
import com.vitorpamplona.quartz.crypto.nip06.Bip39Mnemonics
import com.vitorpamplona.quartz.encoders.toHexKey
import com.vitorpamplona.quartz.encoders.toNpub
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
import com.vitorpamplona.quartz.nip06KeyDerivation.Bip39Mnemonics
import com.vitorpamplona.quartz.nip06KeyDerivation.Nip06
import com.vitorpamplona.quartz.nip19Bech32.toNpub
import com.vitorpamplona.quartz.nip49PrivKeyEnc.Nip49
import com.vitorpamplona.quartz.utils.RandomInstance
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@@ -291,7 +292,7 @@ fun SignUpPage(
storageHelper.onFolderSelected = { _, folder ->
scope.launch(Dispatchers.IO) {
loading = true
val ncryptsec = CryptoUtils.nip49.encrypt(keyPair.privKey!!.toHexKey(), password.text)
val ncryptsec = Nip49().encrypt(keyPair.privKey!!.toHexKey(), password.text)
val ncryptsecFile = folder.makeFile(
context,
mimeType = "application/text",
@@ -312,9 +313,9 @@ fun SignUpPage(
launch(Dispatchers.IO) {
loading = true
while (seedWords.size < 12) {
val entropy = random(16)
val entropy = RandomInstance.bytes(16)
seedWords = Bip39Mnemonics.toMnemonics(entropy).toSet()
keyPair = KeyPair(privKey = CryptoUtils.privateKeyFromMnemonic(seedWords.joinToString(" ")))
keyPair = KeyPair(privKey = Nip06().privateKeyFromMnemonic(seedWords.joinToString(" ")))
}
loading = false
}
@@ -76,9 +76,9 @@ import com.halilibo.richtext.markdown.BasicMarkdown
import com.halilibo.richtext.ui.RichTextStyle
import com.halilibo.richtext.ui.material3.RichText
import com.halilibo.richtext.ui.resolveDefaults
import com.vitorpamplona.quartz.crypto.CryptoUtils
import com.vitorpamplona.quartz.encoders.toHexKey
import com.vitorpamplona.quartz.encoders.toNsec
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import com.vitorpamplona.quartz.nip19Bech32.toNsec
import com.vitorpamplona.quartz.nip49PrivKeyEnc.Nip49
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
@@ -481,7 +481,7 @@ private fun EncryptNSecQRButton(
if (showDialog) {
QrCodeDialog(
content = CryptoUtils.encryptNIP49(account.signer.keyPair.privKey!!.toHexKey(), password.value.text),
content = Nip49().encrypt(account.signer.keyPair.privKey!!.toHexKey(), password.value.text),
) {
showDialog = false
}
@@ -537,7 +537,7 @@ private fun encryptCopyNSec(
} else {
account.signer.keyPair.privKey?.let {
try {
val key = CryptoUtils.encryptNIP49(it.toHexKey(), password.value.text)
val key = Nip49().encrypt(it.toHexKey(), password.value.text)
clipboardManager.setText(AnnotatedString(key))
scope.launch {
Toast.makeText(
@@ -63,11 +63,11 @@ import com.vitorpamplona.ammolite.relays.RelaySetupInfoToConnect
import com.vitorpamplona.ammolite.relays.RelayStats
import com.vitorpamplona.ammolite.relays.TypedFilter
import com.vitorpamplona.ammolite.relays.filters.SincePerRelayFilter
import com.vitorpamplona.quartz.crypto.KeyPair
import com.vitorpamplona.quartz.encoders.RelayUrlFormatter
import com.vitorpamplona.quartz.encoders.toHexKey
import com.vitorpamplona.quartz.events.Event
import com.vitorpamplona.quartz.signers.NostrSignerInternal
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerInternal
import com.vitorpamplona.quartz.nip65RelayList.RelayUrlFormatter
import com.vitorpamplona.quartz.utils.TimeUtils
import java.util.Base64
import java.util.UUID
@@ -340,7 +340,7 @@ suspend fun onAddRelay(
event?.let { signedEvent ->
AmberListenerSingleton.setListener(context, accountStateViewModel)
val socket = OkHttpWebSocket.Builder()
val socket = OkHttpWebSocket.BuilderFactory()
val client = NostrClient(
socket,
)
@@ -36,8 +36,8 @@ import com.greenart7c3.nostrsigner.models.Permission
import com.greenart7c3.nostrsigner.models.SignerType
import com.greenart7c3.nostrsigner.service.model.AmberEvent
import com.greenart7c3.nostrsigner.ui.verticalScrollbar
import com.vitorpamplona.quartz.events.ContactListEvent
import com.vitorpamplona.quartz.events.Event
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip02FollowList.ContactListEvent
@Composable
fun EventData(
@@ -70,9 +70,9 @@ import com.greenart7c3.nostrsigner.ui.Result
import com.greenart7c3.nostrsigner.ui.navigation.Route
import com.greenart7c3.nostrsigner.ui.theme.orange
import com.greenart7c3.nostrsigner.ui.verticalScrollbar
import com.vitorpamplona.quartz.crypto.CryptoUtils
import com.vitorpamplona.quartz.encoders.toHexKey
import com.vitorpamplona.quartz.events.LnZapRequestEvent
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import com.vitorpamplona.quartz.nip55AndroidSigner.signString
import com.vitorpamplona.quartz.nip57Zaps.LnZapRequestEvent
import com.vitorpamplona.quartz.utils.TimeUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@@ -329,7 +329,7 @@ fun MultiEventHomeScreen(
),
)
val signedMessage = CryptoUtils.signString(intentData.data, thisAccount.signer.keyPair.privKey!!).toHexKey()
val signedMessage = signString(intentData.data, thisAccount.signer.keyPair.privKey!!).toHexKey()
if (intentData.bunkerRequest != null) {
val localIntentData = intentData.copy()
@@ -38,11 +38,11 @@ import com.greenart7c3.nostrsigner.service.getAppCompatActivity
import com.greenart7c3.nostrsigner.service.toShortenHex
import com.greenart7c3.nostrsigner.ui.IntentResultType
import com.greenart7c3.nostrsigner.ui.sendResult
import com.vitorpamplona.quartz.crypto.CryptoUtils
import com.vitorpamplona.quartz.encoders.bechToBytes
import com.vitorpamplona.quartz.encoders.toHexKey
import com.vitorpamplona.quartz.encoders.toNpub
import com.vitorpamplona.quartz.events.LnZapRequestEvent
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import com.vitorpamplona.quartz.nip19Bech32.bech32.bechToBytes
import com.vitorpamplona.quartz.nip19Bech32.toNpub
import com.vitorpamplona.quartz.nip55AndroidSigner.signString
import com.vitorpamplona.quartz.nip57Zaps.LnZapRequestEvent
import com.vitorpamplona.quartz.utils.TimeUtils
import fr.acinq.secp256k1.Hex
import kotlinx.coroutines.Dispatchers
@@ -199,7 +199,7 @@ fun SingleEventHomeScreen(
intentData.type,
{
NostrSigner.getInstance().applicationIOScope.launch(Dispatchers.IO) {
val result = CryptoUtils.signString(intentData.data, account.signer.keyPair.privKey!!).toHexKey()
val result = signString(intentData.data, account.signer.keyPair.privKey!!).toHexKey()
sendResult(
context,
+1 -1
View File
@@ -13,7 +13,7 @@ lifecycle_version = "2.8.7"
material3 = "1.3.1"
mockk = "1.13.16"
nav_version = "2.8.8"
quartz = "879f70fcbb"
quartz = "6fd5f36ff5"
compose_ui = "1.7.8"
richtextUi = "077a2cde64"
roomKtx = "2.6.1"