Remove most usages of tohexkey and tonpub

This commit is contained in:
greenart7c3
2025-03-17 14:56:48 -03:00
parent 3bd91ddca0
commit bcd1055eff
25 changed files with 217 additions and 201 deletions
+3
View File
@@ -66,6 +66,9 @@
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewParameterProviderOnFirstParameter" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewPickerAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
@@ -5,6 +5,7 @@ import android.content.Context
import android.content.SharedPreferences
import android.util.LruCache
import androidx.compose.runtime.Immutable
import androidx.core.content.edit
import com.greenart7c3.nostrsigner.models.Account
import com.greenart7c3.nostrsigner.models.AmberSettings
import com.greenart7c3.nostrsigner.okhttp.HttpClientManager
@@ -16,7 +17,6 @@ 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.encoders.toNpub
import com.vitorpamplona.quartz.signers.NostrSignerInternal
import fr.acinq.secp256k1.jni.BuildConfig
import java.io.File
@@ -87,9 +87,11 @@ object LocalPreferences {
if (currentAccount != npub) {
currentAccount = npub
encryptedPreferences(context).edit().apply {
encryptedPreferences(context).edit {
apply {
putString(PrefKeys.CURRENT_ACCOUNT, npub)
}.apply()
}
}
}
}
@@ -101,14 +103,17 @@ object LocalPreferences {
}
fun updateShouldShowRationale(context: Context, value: Boolean) {
encryptedPreferences(context).edit().apply {
encryptedPreferences(context).edit {
apply {
putBoolean(PrefKeys.RATIONALE, value)
}.apply()
}
}
}
fun saveSettingsToEncryptedStorage(settings: AmberSettings) {
val context = NostrSigner.getInstance()
encryptedPreferences(context).edit().apply {
encryptedPreferences(context).edit {
apply {
remove(PrefKeys.ENDPOINT)
remove(PrefKeys.PUSH_SERVER_MESSAGE)
putStringSet(PrefKeys.DEFAULT_RELAYS, settings.defaultRelays.map { it.url }.toSet())
@@ -117,7 +122,8 @@ object LocalPreferences {
putBoolean(PrefKeys.USE_AUTH, settings.useAuth)
putInt(PrefKeys.BIOMETRICS_TYPE, settings.biometricsTimeType.screenCode)
putBoolean(PrefKeys.USE_PIN, settings.usePin)
}.apply()
}
}
}
fun getLastCheck(context: Context, npub: String): Long {
@@ -125,9 +131,11 @@ object LocalPreferences {
}
fun setLastCheck(context: Context, npub: String, time: Long) {
encryptedPreferences(context, npub).edit().apply {
encryptedPreferences(context, npub).edit {
apply {
putLong(PrefKeys.LAST_CHECK, time)
}.apply()
}
}
}
fun getLastMetadataUpdate(context: Context, npub: String): Long {
@@ -135,9 +143,11 @@ object LocalPreferences {
}
fun setLastMetadataUpdate(context: Context, npub: String, time: Long) {
encryptedPreferences(context, npub).edit().apply {
encryptedPreferences(context, npub).edit {
apply {
putLong(PrefKeys.LAST_METADATA_UPDATE, time)
}.apply()
}
}
}
fun loadPinFromEncryptedStorage(): String? {
@@ -152,24 +162,28 @@ object LocalPreferences {
fun saveProfileUrlToEncryptedStorage(profileUrl: String?, npub: String) {
val context = NostrSigner.getInstance()
encryptedPreferences(context, npub).edit().apply {
encryptedPreferences(context, npub).edit {
apply {
if (profileUrl == null) {
remove(PrefKeys.PROFILE_URL)
} else {
putString(PrefKeys.PROFILE_URL, profileUrl)
}
}.apply()
}
}
}
fun savePinToEncryptedStorage(pin: String?) {
val context = NostrSigner.getInstance()
encryptedPreferences(context).edit().apply {
encryptedPreferences(context).edit {
apply {
if (pin == null) {
remove(PrefKeys.PIN)
} else {
putString(PrefKeys.PIN, pin)
}
}.apply()
}
}
}
suspend fun loadSettingsFromEncryptedStorage(): AmberSettings {
@@ -208,9 +222,11 @@ object LocalPreferences {
if (savedAccounts != accounts) {
savedAccounts = accounts
encryptedPreferences(context).edit().apply {
encryptedPreferences(context).edit {
apply {
putString(PrefKeys.SAVED_ACCOUNTS, accounts.joinToString(COMMA).ifBlank { null })
}.apply()
}
}
}
}
@@ -227,9 +243,8 @@ object LocalPreferences {
}
private fun setCurrentAccount(context: Context, account: Account) {
val npub = account.signer.keyPair.pubKey.toNpub()
updateCurrentAccount(context, npub)
addAccount(context, npub)
updateCurrentAccount(context, account.npub)
addAccount(context, account.npub)
}
fun switchToAccount(context: Context, npub: String) {
@@ -286,13 +301,13 @@ object LocalPreferences {
fun updatePrefsForLogout(npub: String, context: Context): Boolean {
accountCache.remove(npub)
val userPrefs = encryptedPreferences(context, npub)
userPrefs.edit().clear().commit()
userPrefs.edit(commit = true) { clear() }
removeAccount(context, npub)
deleteUserPreferenceFile(context, npub)
if (savedAccounts(context).isEmpty()) {
val appPrefs = encryptedPreferences(context)
appPrefs.edit().clear().commit()
appPrefs.edit(commit = true) { clear() }
return true
} else if (currentAccount(context) == npub) {
updateCurrentAccount(context, savedAccounts(context).elementAt(0))
@@ -307,8 +322,9 @@ object LocalPreferences {
}
fun saveToEncryptedStorage(context: Context, account: Account) {
val prefs = encryptedPreferences(context = context, account.signer.keyPair.pubKey.toNpub())
prefs.edit().apply {
val prefs = encryptedPreferences(context = context, account.npub)
prefs.edit {
apply {
account.signer.keyPair.privKey.let { putString(PrefKeys.NOSTR_PRIVKEY, it?.toHexKey()) }
account.signer.keyPair.pubKey.let { putString(PrefKeys.NOSTR_PUBKEY, it.toHexKey()) }
putBoolean(PrefKeys.USE_PROXY, account.useProxy)
@@ -318,7 +334,8 @@ object LocalPreferences {
putBoolean(PrefKeys.ALLOW_NEW_CONNECTIONS, account.allowNewConnections)
putInt(PrefKeys.SIGN_POLICY, account.signPolicy)
putString(PrefKeys.SEED_WORDS2, account.seedWords.joinToString(separator = " ") { it })
}.apply()
}
}
}
fun loadFromEncryptedStorage(context: Context): Account? {
@@ -330,9 +347,11 @@ object LocalPreferences {
npub: String,
value: String,
) {
encryptedPreferences(context, npub).edit().apply {
encryptedPreferences(context, npub).edit {
apply {
putString(PrefKeys.ACCOUNT_NAME, value)
}.apply()
}
}
accountCache.get(npub)?.let {
it.name = value
}
@@ -351,9 +370,11 @@ object LocalPreferences {
) {
val context = NostrSigner.getInstance()
val ncryptsec = CryptoUtils.nip49.encrypt(privateKeyHex, password)
encryptedPreferences(context, npub).edit().apply {
encryptedPreferences(context, npub).edit {
apply {
putString(PrefKeys.NCRYPT_SEC, ncryptsec)
}.apply()
}
}
}
fun updateProxy(
@@ -362,10 +383,12 @@ object LocalPreferences {
port: Int,
) {
val npub = currentAccount(context) ?: return
encryptedPreferences(context, npub).edit().apply {
encryptedPreferences(context, npub).edit {
apply {
putBoolean(PrefKeys.USE_PROXY, useProxy)
putInt(PrefKeys.PROXY_PORT, port)
}.apply()
}
}
accountCache.get(npub)?.let {
it.useProxy = useProxy
it.proxyPort = port
@@ -381,9 +404,11 @@ object LocalPreferences {
val pubKey = getString(PrefKeys.NOSTR_PUBKEY, null) ?: return null
val privKey = getString(PrefKeys.NOSTR_PRIVKEY, null)
this.edit().apply {
this.edit {
apply {
remove(PrefKeys.REMEMBER_APPS)
}.apply()
}
}
val name = getString(PrefKeys.ACCOUNT_NAME, "") ?: ""
val useProxy = getBoolean(PrefKeys.USE_PROXY, false)
val proxyPort = getInt(PrefKeys.PROXY_PORT, 9050)
@@ -28,8 +28,6 @@ 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.encoders.toHexKey
import com.vitorpamplona.quartz.encoders.toNpub
import com.vitorpamplona.quartz.events.Event
import com.vitorpamplona.quartz.events.EventInterface
import com.vitorpamplona.quartz.events.MetadataEvent
@@ -146,7 +144,7 @@ class NostrSigner : Application() {
val savedRelays = getSavedRelays() + newRelays
val useProxy = LocalPreferences.allSavedAccounts(this).any {
LocalPreferences.loadFromEncryptedStorage(this, it.npub)?.useProxy ?: false
LocalPreferences.loadFromEncryptedStorage(this, it.npub)?.useProxy == true
}
if (shouldReconnect) {
@@ -236,13 +234,13 @@ class NostrSigner : Application() {
.build()
}
val lastMetaData = LocalPreferences.getLastMetadataUpdate(this, account.signer.keyPair.pubKey.toNpub())
val lastCheck = LocalPreferences.getLastCheck(this, account.signer.keyPair.pubKey.toNpub())
val lastMetaData = LocalPreferences.getLastMetadataUpdate(this, account.npub)
val lastCheck = LocalPreferences.getLastCheck(this, account.npub)
val oneDayAgo = TimeUtils.oneDayAgo()
val fifteenMinutesAgo = TimeUtils.fifteenMinutesAgo()
if ((lastMetaData == 0L || oneDayAgo > lastMetaData) && (lastCheck == 0L || fifteenMinutesAgo > lastCheck)) {
Log.d("NostrSigner", "Fetching profile data for ${account.signer.keyPair.pubKey.toNpub()}")
LocalPreferences.setLastCheck(this, account.signer.keyPair.pubKey.toNpub(), TimeUtils.now())
Log.d("NostrSigner", "Fetching profile data for ${account.npub}")
LocalPreferences.setLastCheck(this, account.npub, TimeUtils.now())
val listener = RelayListener(
account = account,
onReceiveEvent = { _, _, event ->
@@ -254,8 +252,8 @@ class NostrSigner : Application() {
}
metadata.profilePicture()?.let { url ->
LocalPreferences.saveProfileUrlToEncryptedStorage(url, account.signer.keyPair.pubKey.toNpub())
LocalPreferences.setLastMetadataUpdate(this, account.signer.keyPair.pubKey.toNpub(), TimeUtils.now())
LocalPreferences.saveProfileUrlToEncryptedStorage(url, account.npub)
LocalPreferences.setLastMetadataUpdate(this, account.npub, TimeUtils.now())
onPictureFound(url)
}
}
@@ -285,7 +283,7 @@ class NostrSigner : Application() {
types = COMMON_FEED_TYPES,
filter = SincePerRelayFilter(
kinds = listOf(MetadataEvent.KIND),
authors = listOf(account.signer.keyPair.pubKey.toHexKey()),
authors = listOf(account.hexKey),
limit = 1,
),
),
@@ -294,8 +292,8 @@ class NostrSigner : Application() {
}
}
} else {
Log.d("NostrSigner", "Using cached profile data for ${account.signer.keyPair.pubKey.toNpub()}")
LocalPreferences.loadProfileUrlFromEncryptedStorage(account.signer.keyPair.pubKey.toNpub())?.let {
Log.d("NostrSigner", "Using cached profile data for ${account.npub}")
LocalPreferences.loadProfileUrlFromEncryptedStorage(account.npub)?.let {
onPictureFound(it)
return
}
@@ -14,7 +14,6 @@ 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.encoders.toNpub
import com.vitorpamplona.quartz.events.Event
import com.vitorpamplona.quartz.events.LnZapRequestEvent
import com.vitorpamplona.quartz.utils.TimeUtils
@@ -64,7 +63,7 @@ class SignerProvider : ContentProvider() {
val npub = IntentUtils.parsePubKey(projection[2]) ?: return null
if (!LocalPreferences.containsAccount(context!!, npub)) return null
val account = LocalPreferences.loadFromEncryptedStorage(context!!, npub) ?: return null
val database = NostrSigner.getInstance().getDatabase(account.signer.keyPair.pubKey.toNpub())
val database = NostrSigner.getInstance().getDatabase(account.npub)
val signPolicy = database.applicationDao().getSignPolicy(sortOrder ?: packageName)
val permission =
database
@@ -128,7 +127,7 @@ class SignerProvider : ContentProvider() {
return null
}
val database = NostrSigner.getInstance().getDatabase(account.signer.keyPair.pubKey.toNpub())
val database = NostrSigner.getInstance().getDatabase(account.npub)
var permission =
database
.applicationDao()
@@ -240,7 +239,7 @@ class SignerProvider : ContentProvider() {
val stringType = uri.toString().replace("content://$appId.", "")
val pubkey = projection[1]
val account = LocalPreferences.loadFromEncryptedStorage(context!!, npub) ?: return null
val database = NostrSigner.getInstance().getDatabase(account.signer.keyPair.pubKey.toNpub())
val database = NostrSigner.getInstance().getDatabase(account.npub)
var permission =
database
.applicationDao()
@@ -346,7 +345,7 @@ class SignerProvider : ContentProvider() {
"content://$appId.GET_PUBLIC_KEY" -> {
val packageName = callingPackage ?: return null
val account = LocalPreferences.loadFromEncryptedStorage(context!!) ?: return null
val database = NostrSigner.getInstance().getDatabase(account.signer.keyPair.pubKey.toNpub())
val database = NostrSigner.getInstance().getDatabase(account.npub)
val permission =
database
.applicationDao()
@@ -393,7 +392,7 @@ class SignerProvider : ContentProvider() {
}
val cursor = MatrixCursor(arrayOf("signature", "result"))
val result = if (sortOrder == null) account.signer.keyPair.pubKey.toNpub() else account.signer.keyPair.pubKey.toHexKey()
val result = if (sortOrder == null) account.npub else account.hexKey
cursor.addRow(arrayOf<Any>(result, result))
return cursor
}
@@ -3,6 +3,9 @@ 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
@@ -18,6 +21,8 @@ class Account(
var seedWords: Set<String>,
) {
val saveable: AccountLiveData = AccountLiveData(this)
val hexKey: HexKey = signer.keyPair.pubKey.toHexKey()
val npub: String = signer.keyPair.pubKey.toNpub()
fun createAuthEvent(
relayUrl: String,
@@ -74,7 +74,7 @@ object AmberUtils {
return if (event.isPrivateZap()) {
val recipientPK = event.zappedAuthor().firstOrNull()
val recipientPost = event.zappedPost().firstOrNull()
if (recipientPK == account.signer.keyPair.pubKey.toHexKey()) {
if (recipientPK == account.hexKey) {
// if the receiver is logged in, these are the params.
val pubkeyToUse = event.pubKey
@@ -22,7 +22,6 @@ 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.encoders.toNpub
import com.vitorpamplona.quartz.events.Event
import com.vitorpamplona.quartz.utils.TimeUtils
import java.util.concurrent.ConcurrentHashMap
@@ -65,7 +64,7 @@ object BunkerRequestUtils {
onDone(true)
onLoading(false)
NostrSigner.getInstance().applicationIOScope.launch {
NostrSigner.getInstance().getDatabase(account.signer.keyPair.pubKey.toNpub()).applicationDao().insertLog(
NostrSigner.getInstance().getDatabase(account.npub).applicationDao().insertLog(
LogEntity(
id = 0,
url = bunkerRequest.localKey,
@@ -92,7 +91,7 @@ object BunkerRequestUtils {
NostrSigner.getInstance().applicationIOScope.launch {
relays.forEach { relay ->
NostrSigner.getInstance().getDatabase(account.signer.keyPair.pubKey.toNpub()).applicationDao().insertLog(
NostrSigner.getInstance().getDatabase(account.npub).applicationDao().insertLog(
LogEntity(
id = 0,
url = relay.url,
@@ -323,7 +322,7 @@ object BunkerRequestUtils {
) ?: "Could not decrypt the message"
} catch (e: Exception) {
NostrSigner.getInstance().applicationIOScope.launch {
val database = NostrSigner.getInstance().getDatabase(account.signer.keyPair.pubKey.toNpub())
val database = NostrSigner.getInstance().getDatabase(account.npub)
database.applicationDao().insertLog(
LogEntity(
0,
@@ -362,7 +361,7 @@ object BunkerRequestUtils {
SignerType.GET_PUBLIC_KEY -> {
onReady(
IntentData(
account.signer.keyPair.pubKey.toNpub(),
account.npub,
"",
type,
pubKey,
@@ -22,11 +22,11 @@ package com.greenart7c3.nostrsigner.service
import android.app.NotificationManager
import android.content.Context
import android.net.Uri
import android.util.Log
import androidx.compose.ui.text.intl.Locale
import androidx.compose.ui.text.toLowerCase
import androidx.core.content.ContextCompat
import androidx.core.net.toUri
import com.greenart7c3.nostrsigner.BuildConfig
import com.greenart7c3.nostrsigner.LocalPreferences
import com.greenart7c3.nostrsigner.NostrSigner
@@ -60,7 +60,7 @@ class EventNotificationConsumer(private val applicationContext: Context) {
val accounts = LocalPreferences.allSavedAccounts(applicationContext)
accounts.forEach {
LocalPreferences.loadFromEncryptedStorage(applicationContext, it.npub)?.let { acc ->
val dao = NostrSigner.getInstance().getDatabase(acc.signer.keyPair.pubKey.toNpub()).applicationDao()
val dao = NostrSigner.getInstance().getDatabase(acc.npub).applicationDao()
dao.insertLog(
LogEntity(
0,
@@ -108,7 +108,7 @@ class EventNotificationConsumer(private val applicationContext: Context) {
) {
if (event.content.isEmpty()) return
val dao = NostrSigner.getInstance().getDatabase(acc.signer.keyPair.pubKey.toNpub()).applicationDao()
val dao = NostrSigner.getInstance().getDatabase(acc.npub).applicationDao()
NostrSigner.getInstance().applicationIOScope.launch {
dao.insertLog(
LogEntity(
@@ -144,7 +144,7 @@ class EventNotificationConsumer(private val applicationContext: Context) {
relay: Relay,
) {
val responseRelay = listOf(RelaySetupInfo(relay.url, read = true, write = true, feedTypes = COMMON_FEED_TYPES))
val dao = NostrSigner.getInstance().getDatabase(acc.signer.keyPair.pubKey.toNpub()).applicationDao()
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))
@@ -161,7 +161,7 @@ class EventNotificationConsumer(private val applicationContext: Context) {
val bunkerRequest = BunkerRequest.mapper.readValue(request, BunkerRequest::class.java)
bunkerRequest.localKey = event.pubKey
bunkerRequest.currentAccount = acc.signer.keyPair.pubKey.toNpub()
bunkerRequest.currentAccount = acc.npub
bunkerRequest.encryptionType = encryptionType
val type = BunkerRequestUtils.getTypeFromBunker(bunkerRequest)
@@ -179,7 +179,7 @@ class EventNotificationConsumer(private val applicationContext: Context) {
""
}
val database = NostrSigner.getInstance().getDatabase(acc.signer.keyPair.pubKey.toNpub())
val database = NostrSigner.getInstance().getDatabase(acc.npub)
val permission = database.applicationDao().getByKey(bunkerRequest.localKey)
if (permission != null && ((permission.application.secret != permission.application.key && permission.application.useSecret) || permission.application.isConnected) && type == SignerType.CONNECT) {
@@ -270,8 +270,8 @@ class EventNotificationConsumer(private val applicationContext: Context) {
val cursor =
applicationContext.contentResolver.query(
Uri.parse("content://${BuildConfig.APPLICATION_ID}.$type"),
arrayOf(data, pubKey, acc.signer.keyPair.pubKey.toNpub()),
"content://${BuildConfig.APPLICATION_ID}.$type".toUri(),
arrayOf(data, pubKey, acc.npub),
"1",
null,
bunkerRequest.localKey,
@@ -2,11 +2,11 @@ package com.greenart7c3.nostrsigner.service
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.provider.Browser
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.text.intl.Locale
import androidx.compose.ui.text.toLowerCase
import androidx.core.net.toUri
import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.databind.DeserializationContext
import com.fasterxml.jackson.databind.DeserializationFeature
@@ -159,7 +159,7 @@ object IntentUtils {
SignerType.SIGN_EVENT -> {
val unsignedEvent = getUnsignedEvent(localData, account)
var localAccount = account
if (unsignedEvent.pubKey != account.signer.keyPair.pubKey.toHexKey()) {
if (unsignedEvent.pubKey != account.hexKey) {
LocalPreferences.loadFromEncryptedStorage(context, Hex.decode(unsignedEvent.pubKey).toNpub())?.let {
localAccount = it
}
@@ -203,7 +203,7 @@ object IntentUtils {
) ?: "Could not decrypt the message"
} catch (e: Exception) {
NostrSigner.getInstance().applicationIOScope.launch {
val database = NostrSigner.getInstance().getDatabase(account.signer.keyPair.pubKey.toNpub())
val database = NostrSigner.getInstance().getDatabase(account.npub)
database.applicationDao().insertLog(
LogEntity(
0,
@@ -321,7 +321,7 @@ object IntentUtils {
}
val callbackUrl = intent.extras?.getString("callbackUrl") ?: ""
var name = if (callbackUrl.isNotBlank()) Uri.parse(callbackUrl).host ?: "" else ""
var name = if (callbackUrl.isNotBlank()) callbackUrl.toUri().host ?: "" else ""
if (name.isBlank()) {
name = intent.extras?.getString("appName") ?: ""
}
@@ -342,7 +342,7 @@ object IntentUtils {
SignerType.SIGN_EVENT -> {
val unsignedEvent = getUnsignedEvent(data, account)
var localAccount = account
if (unsignedEvent.pubKey != account.signer.keyPair.pubKey.toHexKey()) {
if (unsignedEvent.pubKey != account.hexKey) {
LocalPreferences.loadFromEncryptedStorage(context, Hex.decode(unsignedEvent.pubKey).toNpub())?.let {
localAccount = it
}
@@ -356,7 +356,7 @@ object IntentUtils {
) {
var npub = intent.getStringExtra("current_user")
if (npub != null) {
npub = parsePubKey(npub!!)
npub = parsePubKey(npub)
}
onReady(
@@ -392,7 +392,7 @@ object IntentUtils {
) ?: "Could not decrypt the message"
} catch (e: Exception) {
NostrSigner.getInstance().applicationIOScope.launch {
val database = NostrSigner.getInstance().getDatabase(account.signer.keyPair.pubKey.toNpub())
val database = NostrSigner.getInstance().getDatabase(account.npub)
database.applicationDao().insertLog(
LogEntity(
0,
@@ -408,7 +408,7 @@ object IntentUtils {
var npub = intent.getStringExtra("current_user")
if (npub != null) {
npub = parsePubKey(npub!!)
npub = parsePubKey(npub)
}
onReady(
@@ -435,7 +435,7 @@ object IntentUtils {
SignerType.GET_PUBLIC_KEY -> {
var npub = intent.getStringExtra("current_user")
if (npub != null) {
npub = parsePubKey(npub!!)
npub = parsePubKey(npub)
}
onReady(
@@ -462,7 +462,7 @@ object IntentUtils {
SignerType.SIGN_MESSAGE -> {
var npub = intent.getStringExtra("current_user")
if (npub != null) {
npub = parsePubKey(npub!!)
npub = parsePubKey(npub)
}
onReady(
@@ -558,7 +558,7 @@ object IntentUtils {
): Event {
val event = AmberEvent.fromJson(data)
if (event.pubKey.isEmpty()) {
event.pubKey = account.signer.keyPair.pubKey.toHexKey()
event.pubKey = account.hexKey
}
if (event.id.isEmpty()) {
event.id =
@@ -16,7 +16,6 @@ import com.greenart7c3.nostrsigner.models.SignerType
import com.greenart7c3.nostrsigner.models.containsNip
import com.vitorpamplona.ammolite.relays.COMMON_FEED_TYPES
import com.vitorpamplona.ammolite.relays.RelaySetupInfo
import com.vitorpamplona.quartz.encoders.toNpub
import java.util.UUID
import kotlinx.coroutines.launch
@@ -135,7 +134,7 @@ object NostrConnectUtils {
pubKey,
relays.ifEmpty { NostrSigner.getInstance().getSavedRelays().toList() },
"",
account.signer.keyPair.pubKey.toNpub(),
account.npub,
EncryptionType.NIP04,
nostrConnectSecret,
intent.getBooleanExtra("closeApplication", true),
@@ -148,7 +147,7 @@ object NostrConnectUtils {
} catch (e: Exception) {
Log.e("nostrconnect", e.message, e)
NostrSigner.getInstance().applicationIOScope.launch {
NostrSigner.getInstance().getDatabase(account.signer.keyPair.pubKey.toNpub()).applicationDao().insertLog(
NostrSigner.getInstance().getDatabase(account.npub).applicationDao().insertLog(
LogEntity(
0,
"nostrconnect",
@@ -39,7 +39,6 @@ import com.greenart7c3.nostrsigner.R
import com.greenart7c3.nostrsigner.models.IntentData
import com.greenart7c3.nostrsigner.relays.AmberListenerSingleton
import com.greenart7c3.nostrsigner.service.IntentUtils
import com.vitorpamplona.quartz.encoders.toNpub
import kotlinx.coroutines.flow.MutableStateFlow
@SuppressLint("StateFlowValueCalledInComposition", "UnrememberedMutableState")
@@ -81,7 +80,7 @@ fun AccountScreen(
}
}
val database = NostrSigner.getInstance().getDatabase(state.account.signer.keyPair.pubKey.toNpub())
val database = NostrSigner.getInstance().getDatabase(state.account.npub)
val localRoute = mutableStateOf(intents.firstNotNullOfOrNull { it.route } ?: state.route)
AmberListenerSingleton.accountStateViewModel = accountStateViewModel
@@ -54,7 +54,6 @@ import com.greenart7c3.nostrsigner.models.Permission
import com.greenart7c3.nostrsigner.ui.actions.RemoveAllPermissionsDialog
import com.greenart7c3.nostrsigner.ui.components.AmberButton
import com.greenart7c3.nostrsigner.ui.theme.orange
import com.vitorpamplona.quartz.encoders.toHexKey
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@@ -85,7 +84,7 @@ fun EditPermission(
val secret = if (checked) "&secret=${applicationData.secret}" else ""
var bunkerUri by remember {
val relayString = NostrSigner.getInstance().settings.defaultRelays.joinToString(separator = "&") { "relay=${it.url}" }
mutableStateOf("bunker://${account.signer.keyPair.pubKey.toHexKey()}?$relayString$secret")
mutableStateOf("bunker://${account.hexKey}?$relayString$secret")
}
LaunchedEffect(Unit) {
@@ -95,7 +94,7 @@ fun EditPermission(
checked = applicationData.useSecret
val relays = applicationData.relays.joinToString(separator = "&") { "relay=${it.url}" }
val localSecret = if (checked) "&secret=${applicationData.secret}" else ""
bunkerUri = "bunker://${account.signer.keyPair.pubKey.toHexKey()}?$relays$localSecret"
bunkerUri = "bunker://${account.hexKey}?$relays$localSecret"
}
}
@@ -19,7 +19,6 @@ import com.greenart7c3.nostrsigner.R
import com.greenart7c3.nostrsigner.models.Account
import com.greenart7c3.nostrsigner.ui.components.AmberButton
import com.greenart7c3.nostrsigner.ui.navigation.Route
import com.vitorpamplona.quartz.encoders.toNpub
@Composable
fun EditProfileScreen(
@@ -50,7 +49,7 @@ fun EditProfileScreen(
modifier = Modifier.padding(vertical = 40.dp),
onClick = {
LocalPreferences.setAccountName(context, npub, textFieldvalue.text)
accountStateViewModel.switchUser(account.signer.keyPair.pubKey.toNpub(), Route.Settings.route)
accountStateViewModel.switchUser(account.npub, Route.Settings.route)
},
text = stringResource(R.string.save),
)
@@ -27,7 +27,6 @@ import com.greenart7c3.nostrsigner.R
import com.greenart7c3.nostrsigner.models.Account
import com.greenart7c3.nostrsigner.models.TimeUtils
import com.greenart7c3.nostrsigner.ui.components.AmberButton
import com.vitorpamplona.quartz.encoders.toNpub
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@@ -37,7 +36,7 @@ fun LogsScreen(
account: Account,
) {
val scope = rememberCoroutineScope()
val logsFlow = NostrSigner.getInstance().getDatabase(account.signer.keyPair.pubKey.toNpub()).applicationDao().getLogs()
val logsFlow = NostrSigner.getInstance().getDatabase(account.npub).applicationDao().getLogs()
val logs = logsFlow.collectAsStateWithLifecycle(initialValue = emptyList())
val state = rememberLazyListState()
@@ -52,7 +51,7 @@ fun LogsScreen(
modifier = Modifier.padding(bottom = 8.dp),
onClick = {
scope.launch(Dispatchers.IO) {
NostrSigner.getInstance().getDatabase(account.signer.keyPair.pubKey.toNpub()).applicationDao().clearLogs()
NostrSigner.getInstance().getDatabase(account.npub).applicationDao().clearLogs()
}
},
text = stringResource(R.string.clear_logs),
@@ -115,7 +115,6 @@ import com.greenart7c3.nostrsigner.ui.actions.RelayLogScreen
import com.greenart7c3.nostrsigner.ui.components.IconRow
import com.greenart7c3.nostrsigner.ui.navigation.Route
import com.greenart7c3.nostrsigner.ui.navigation.routes
import com.vitorpamplona.quartz.encoders.toHexKey
import com.vitorpamplona.quartz.utils.TimeUtils
import java.io.ByteArrayOutputStream
import java.util.Base64
@@ -188,7 +187,7 @@ fun sendResult(
"",
"",
"",
account.signer.keyPair.pubKey.toHexKey(),
account.hexKey,
true,
intentData.bunkerRequest?.secret ?: "",
intentData.bunkerRequest?.secret != null,
@@ -701,7 +700,7 @@ fun MainScreen(
it.route,
modifier = Modifier.border(
2.dp,
Color.fromHex(account.signer.keyPair.pubKey.toHexKey().slice(0..5)),
Color.fromHex(account.hexKey.slice(0..5)),
CircleShape,
),
)
@@ -1,7 +1,6 @@
package com.greenart7c3.nostrsigner.ui
import android.content.Intent
import android.net.Uri
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
@@ -16,13 +15,13 @@ import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.core.net.toUri
import androidx.navigation.NavController
import com.greenart7c3.nostrsigner.R
import com.greenart7c3.nostrsigner.models.Account
import com.greenart7c3.nostrsigner.service.getAppCompatActivity
import com.greenart7c3.nostrsigner.ui.components.AmberButton
import com.greenart7c3.nostrsigner.ui.navigation.Route
import com.vitorpamplona.quartz.encoders.toNpub
@Composable
fun NewApplicationScreen(
@@ -40,12 +39,12 @@ fun NewApplicationScreen(
dialogOpen = false
if (!it.isNullOrEmpty()) {
val intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse(it)
intent.data = it.toUri()
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP)
intent.putExtra("closeApplication", false)
intent.`package` = context.packageName
context.getAppCompatActivity()?.startActivity(intent)
accountStateViewModel.switchUser(account.signer.keyPair.pubKey.toNpub(), Route.IncomingRequest.route)
accountStateViewModel.switchUser(account.npub, Route.IncomingRequest.route)
}
}
}
@@ -87,11 +86,11 @@ fun NewApplicationScreen(
}
val intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse(clipboardText.text)
intent.data = clipboardText.text.toUri()
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP)
intent.`package` = context.packageName
context.getAppCompatActivity()?.startActivity(intent)
accountStateViewModel.switchUser(account.signer.keyPair.pubKey.toNpub(), Route.IncomingRequest.route)
accountStateViewModel.switchUser(account.npub, Route.IncomingRequest.route)
},
text = stringResource(R.string.paste_from_clipboard),
)
@@ -52,7 +52,6 @@ import com.greenart7c3.nostrsigner.service.NotificationDataSource
import com.greenart7c3.nostrsigner.ui.actions.onAddRelay
import com.greenart7c3.nostrsigner.ui.components.AmberButton
import com.vitorpamplona.ammolite.relays.RelaySetupInfo
import com.vitorpamplona.quartz.encoders.toHexKey
import java.util.UUID
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
@@ -233,7 +232,7 @@ fun NewNsecBunkerScreen(
"",
"",
"",
account.signer.keyPair.pubKey.toHexKey(),
account.hexKey,
false,
secret.value,
true,
@@ -280,7 +279,7 @@ fun NewNsecBunkerCreatedScreen(
} else {
val relays = application.relays.joinToString(separator = "&") { "relay=${it.url}" }
val localSecret = "&secret=${application.secret}"
val bunkerUri = "bunker://${account.signer.keyPair.pubKey.toHexKey()}?$relays$localSecret"
val bunkerUri = "bunker://${account.hexKey}?$relays$localSecret"
LaunchedEffect(Unit) {
NostrSigner.getInstance().applicationIOScope.launch(Dispatchers.IO) {
@@ -32,7 +32,6 @@ import com.greenart7c3.nostrsigner.database.AppDatabase
import com.greenart7c3.nostrsigner.models.Account
import com.greenart7c3.nostrsigner.models.TimeUtils
import com.greenart7c3.nostrsigner.service.toShortenHex
import com.vitorpamplona.quartz.encoders.toHexKey
@Composable
fun PermissionsScreen(
@@ -41,7 +40,7 @@ fun PermissionsScreen(
navController: NavController,
database: AppDatabase,
) {
val applications = database.applicationDao().getAllFlow(account.signer.keyPair.pubKey.toHexKey()).collectAsStateWithLifecycle(emptyList())
val applications = database.applicationDao().getAllFlow(account.hexKey).collectAsStateWithLifecycle(emptyList())
Column(
modifier,
@@ -62,7 +62,6 @@ import com.greenart7c3.nostrsigner.ui.components.IconRow
import com.greenart7c3.nostrsigner.ui.components.TextSpinner
import com.greenart7c3.nostrsigner.ui.components.TitleExplainer
import com.greenart7c3.nostrsigner.ui.navigation.Route
import com.vitorpamplona.quartz.encoders.toNpub
import com.vitorpamplona.quartz.utils.TimeUtils
import com.vitorpamplona.quartz.utils.TimeUtils.ONE_WEEK
import java.text.DecimalFormat
@@ -92,7 +91,7 @@ fun SettingsScreen(
LaunchedEffect(Unit) {
isLoading = true
launch(Dispatchers.IO) {
val dbFile = context.getDatabasePath("amber_db_${account.signer.keyPair.pubKey.toNpub()}")
val dbFile = context.getDatabasePath("amber_db_${account.npub}")
val df = DecimalFormat("#.###")
sizeInMBFormatted = df.format(dbFile.length() / (1024.0 * 1024.0))
isLoading = false
@@ -106,7 +105,7 @@ fun SettingsScreen(
},
onConfirm = {
logoutDialog = false
accountStateViewModel.logOff(account.signer.keyPair.pubKey.toNpub())
accountStateViewModel.logOff(account.npub)
},
)
}
@@ -319,7 +318,7 @@ fun SettingsScreen(
logs = database.applicationDao().getOldLog(oneWeek)
}
}
val dbFile = context.getDatabasePath("amber_db_${account.signer.keyPair.pubKey.toNpub()}")
val dbFile = context.getDatabasePath("amber_db_${account.npub}")
val df = DecimalFormat("#.###")
sizeInMBFormatted = df.format(dbFile.length() / (1024.0 * 1024.0))
status = ""
@@ -329,7 +328,7 @@ fun SettingsScreen(
isLoading = false
if (e is CancellationException) throw e
Log.e("NostrSigner", "Error deleting old log entries", e)
val dbFile = context.getDatabasePath("amber_db_${account.signer.keyPair.pubKey.toNpub()}")
val dbFile = context.getDatabasePath("amber_db_${account.npub}")
val df = DecimalFormat("#.###")
sizeInMBFormatted = df.format(dbFile.length() / (1024.0 * 1024.0))
status = ""
@@ -18,8 +18,6 @@ import com.greenart7c3.nostrsigner.LocalPreferences
import com.greenart7c3.nostrsigner.NostrSigner
import com.greenart7c3.nostrsigner.R
import com.greenart7c3.nostrsigner.ui.AccountStateViewModel
import com.vitorpamplona.quartz.encoders.toHexKey
import com.vitorpamplona.quartz.encoders.toNpub
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@@ -40,8 +38,8 @@ fun LogoutButton(
scope.launch(Dispatchers.IO) {
val account = LocalPreferences.loadFromEncryptedStorage(context, acc.npub)
account?.let {
val database = NostrSigner.getInstance().getDatabase(account.signer.keyPair.pubKey.toNpub())
val permissions = database.applicationDao().getAll(it.signer.keyPair.pubKey.toHexKey())
val database = NostrSigner.getInstance().getDatabase(it.npub)
val permissions = database.applicationDao().getAll(it.hexKey)
permissions.forEach { app ->
database.applicationDao().delete(app)
}
@@ -12,7 +12,6 @@ import androidx.compose.ui.res.stringResource
import com.greenart7c3.nostrsigner.AccountInfo
import com.greenart7c3.nostrsigner.R
import com.greenart7c3.nostrsigner.models.Account
import com.vitorpamplona.quartz.encoders.toNpub
@Composable
fun ActiveMarker(
@@ -21,7 +20,7 @@ fun ActiveMarker(
) {
val isCurrentUser by remember(account) {
derivedStateOf {
account.signer.keyPair.pubKey.toNpub() == acc.npub
account.npub == acc.npub
}
}
@@ -16,6 +16,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.key
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
@@ -94,6 +95,7 @@ fun EventData(
val content = if (event.kind == 22242) AmberEvent.relay(event) else event.content
if (content.isNotBlank()) {
key("event-data-card") {
Card(
modifier = Modifier
.fillMaxWidth(),
@@ -133,6 +135,7 @@ fun EventData(
}
}
}
}
RawJsonButton(
onCLick = {
@@ -61,8 +61,6 @@ import com.greenart7c3.nostrsigner.service.toShortenHex
import com.greenart7c3.nostrsigner.ui.fromHex
import com.greenart7c3.nostrsigner.ui.navigation.Route
import com.greenart7c3.nostrsigner.ui.verticalScrollbar
import com.vitorpamplona.quartz.encoders.toHexKey
import com.vitorpamplona.quartz.encoders.toNpub
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@@ -105,7 +103,7 @@ fun ProfilePicture(account: Account) {
modifier = Modifier
.border(
2.dp,
Color.fromHex(account.signer.keyPair.pubKey.toHexKey().slice(0..5)),
Color.fromHex(account.hexKey.slice(0..5)),
CircleShape,
)
.height(120.dp)
@@ -113,7 +111,7 @@ fun ProfilePicture(account: Account) {
)
}
Text(
account.name.ifBlank { account.signer.keyPair.pubKey.toNpub().toShortenHex() },
account.name.ifBlank { account.npub.toShortenHex() },
fontWeight = FontWeight.Bold,
fontSize = 18.sp,
textAlign = TextAlign.Center,
@@ -72,7 +72,6 @@ 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.encoders.toNpub
import com.vitorpamplona.quartz.events.LnZapRequestEvent
import com.vitorpamplona.quartz.utils.TimeUtils
import kotlinx.coroutines.Dispatchers
@@ -110,7 +109,7 @@ fun MultiEventHomeScreen(
localAccount = LocalPreferences.loadFromEncryptedStorage(
context,
intents.firstOrNull()?.currentAccount ?: "",
)?.signer?.keyPair?.pubKey?.toNpub()?.toShortenHex() ?: ""
)?.npub?.toShortenHex() ?: ""
}
}
@@ -195,7 +194,7 @@ fun MultiEventHomeScreen(
val localKey = intentData.bunkerRequest?.localKey ?: packageName ?: continue
val database = NostrSigner.getInstance().getDatabase(thisAccount.signer.keyPair.pubKey.toNpub())
val database = NostrSigner.getInstance().getDatabase(thisAccount.npub)
val savedApplication = database.applicationDao().getByKey(localKey)
val application =
@@ -207,7 +206,7 @@ fun MultiEventHomeScreen(
"",
"",
"",
thisAccount.signer.keyPair.pubKey.toHexKey(),
thisAccount.hexKey,
true,
intentData.bunkerRequest?.secret ?: "",
intentData.bunkerRequest?.secret != null,
@@ -541,7 +540,7 @@ fun MultiEventHomeScreen(
val localKey = intentData.bunkerRequest?.localKey ?: packageName ?: continue
val database = NostrSigner.getInstance().getDatabase(thisAccount.signer.keyPair.pubKey.toNpub())
val database = NostrSigner.getInstance().getDatabase(thisAccount.npub)
val application =
database
@@ -554,7 +553,7 @@ fun MultiEventHomeScreen(
"",
"",
"",
thisAccount.signer.keyPair.pubKey.toHexKey(),
thisAccount.hexKey,
true,
intentData.bunkerRequest?.secret ?: "",
intentData.bunkerRequest?.secret != null,
@@ -111,11 +111,11 @@ fun SingleEventHomeScreen(
if (intentData.type == SignerType.CONNECT) {
intentData.bunkerRequest!!.nostrConnectSecret.ifBlank { "ack" }
} else if (intentData.bunkerRequest != null) {
account.signer.keyPair.pubKey.toHexKey()
account.hexKey
} else if (packageName == null) {
account.signer.keyPair.pubKey.toHexKey()
account.hexKey
} else {
account.signer.keyPair.pubKey.toNpub()
account.npub
}
sendResult(
@@ -238,7 +238,7 @@ fun SingleEventHomeScreen(
"",
"",
"",
account.signer.keyPair.pubKey.toHexKey(),
account.hexKey,
true,
intentData.bunkerRequest?.secret ?: "",
intentData.bunkerRequest?.secret != null,
@@ -383,7 +383,7 @@ fun SingleEventHomeScreen(
"",
"",
"",
account.signer.keyPair.pubKey.toHexKey(),
account.hexKey,
true,
intentData.bunkerRequest?.secret ?: "",
intentData.bunkerRequest?.secret != null,
@@ -495,7 +495,7 @@ fun SingleEventHomeScreen(
event.toJson(),
intentData.type,
{
if (event.pubKey != account.signer.keyPair.pubKey.toHexKey() && !isPrivateEvent(event.kind, event.tags)) {
if (event.pubKey != account.hexKey && !isPrivateEvent(event.kind, event.tags)) {
coroutineScope.launch {
Toast.makeText(
context,
@@ -556,7 +556,7 @@ fun SingleEventHomeScreen(
"",
"",
"",
account.signer.keyPair.pubKey.toHexKey(),
account.hexKey,
true,
intentData.bunkerRequest?.secret ?: "",
intentData.bunkerRequest?.secret != null,