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