mirror of
https://github.com/greenart7c3/Amber.git
synced 2026-10-05 19:08:23 +00:00
remove keypair from account
This commit is contained in:
@@ -19,6 +19,7 @@ import com.vitorpamplona.quartz.crypto.KeyPair
|
||||
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
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -195,7 +196,7 @@ object LocalPreferences {
|
||||
}
|
||||
|
||||
private fun setCurrentAccount(context: Context, account: Account) {
|
||||
val npub = account.keyPair.pubKey.toNpub()
|
||||
val npub = account.signer.keyPair.pubKey.toNpub()
|
||||
updateCurrentAccount(context, npub)
|
||||
addAccount(context, npub)
|
||||
}
|
||||
@@ -281,10 +282,10 @@ object LocalPreferences {
|
||||
}
|
||||
|
||||
fun saveToEncryptedStorage(context: Context, account: Account) {
|
||||
val prefs = encryptedPreferences(context = context, account.keyPair.pubKey.toNpub())
|
||||
val prefs = encryptedPreferences(context = context, account.signer.keyPair.pubKey.toNpub())
|
||||
prefs.edit().apply {
|
||||
account.keyPair.privKey.let { putString(PrefKeys.NOSTR_PRIVKEY, it?.toHexKey()) }
|
||||
account.keyPair.pubKey.let { putString(PrefKeys.NOSTR_PUBKEY, it.toHexKey()) }
|
||||
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)
|
||||
putInt(PrefKeys.PROXY_PORT, account.proxyPort)
|
||||
putString(PrefKeys.ACCOUNT_NAME, account.name)
|
||||
@@ -411,7 +412,7 @@ object LocalPreferences {
|
||||
HttpClientManager.setDefaultProxyOnPort(proxyPort)
|
||||
val account =
|
||||
Account(
|
||||
keyPair = KeyPair(privKey = privKey?.hexToByteArray(), pubKey = pubKey.hexToByteArray()),
|
||||
signer = NostrSignerInternal(KeyPair(privKey = privKey?.hexToByteArray(), pubKey = pubKey.hexToByteArray())),
|
||||
name = name,
|
||||
useProxy = useProxy,
|
||||
proxyPort = proxyPort,
|
||||
|
||||
@@ -57,7 +57,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.keyPair.pubKey.toNpub())
|
||||
val database = NostrSigner.getInstance().getDatabase(account.signer.keyPair.pubKey.toNpub())
|
||||
val signPolicy = database.applicationDao().getSignPolicy(sortOrder ?: packageName)
|
||||
val permission =
|
||||
database
|
||||
@@ -86,7 +86,7 @@ class SignerProvider : ContentProvider() {
|
||||
return cursor
|
||||
}
|
||||
|
||||
val result = CryptoUtils.signString(message, account.keyPair.privKey!!).toHexKey()
|
||||
val result = CryptoUtils.signString(message, account.signer.keyPair.privKey!!).toHexKey()
|
||||
database.applicationDao().addHistory(
|
||||
HistoryEntity(
|
||||
0,
|
||||
@@ -117,7 +117,7 @@ class SignerProvider : ContentProvider() {
|
||||
return null
|
||||
}
|
||||
|
||||
val database = NostrSigner.getInstance().getDatabase(account.keyPair.pubKey.toNpub())
|
||||
val database = NostrSigner.getInstance().getDatabase(account.signer.keyPair.pubKey.toNpub())
|
||||
var permission =
|
||||
database
|
||||
.applicationDao()
|
||||
@@ -223,7 +223,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.keyPair.pubKey.toNpub())
|
||||
val database = NostrSigner.getInstance().getDatabase(account.signer.keyPair.pubKey.toNpub())
|
||||
var permission =
|
||||
database
|
||||
.applicationDao()
|
||||
@@ -314,7 +314,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.keyPair.pubKey.toNpub())
|
||||
val database = NostrSigner.getInstance().getDatabase(account.signer.keyPair.pubKey.toNpub())
|
||||
val permission =
|
||||
database
|
||||
.applicationDao()
|
||||
@@ -357,7 +357,8 @@ class SignerProvider : ContentProvider() {
|
||||
)
|
||||
|
||||
val cursor = MatrixCursor(arrayOf("signature", "result"))
|
||||
cursor.addRow(arrayOf<Any>(account.keyPair.pubKey.toNpub(), account.keyPair.pubKey.toNpub()))
|
||||
val npub = account.signer.keyPair.pubKey.toNpub()
|
||||
cursor.addRow(arrayOf<Any>(npub, npub))
|
||||
return cursor
|
||||
}
|
||||
|
||||
|
||||
@@ -3,14 +3,12 @@ package com.greenart7c3.nostrsigner.models
|
||||
import androidx.compose.runtime.Immutable
|
||||
import androidx.compose.runtime.Stable
|
||||
import androidx.lifecycle.LiveData
|
||||
import com.vitorpamplona.quartz.crypto.KeyPair
|
||||
import com.vitorpamplona.quartz.events.RelayAuthEvent
|
||||
import com.vitorpamplona.quartz.signers.NostrSignerInternal
|
||||
|
||||
@Stable
|
||||
class Account(
|
||||
val keyPair: KeyPair,
|
||||
val signer: NostrSignerInternal = NostrSignerInternal(keyPair),
|
||||
val signer: NostrSignerInternal,
|
||||
var name: String,
|
||||
var useProxy: Boolean,
|
||||
var proxyPort: Int,
|
||||
|
||||
@@ -34,28 +34,28 @@ object AmberUtils {
|
||||
SignerType.NIP04_DECRYPT -> {
|
||||
CryptoUtils.decryptNIP04(
|
||||
data,
|
||||
account.keyPair.privKey!!,
|
||||
account.signer.keyPair.privKey!!,
|
||||
Hex.decode(pubKey),
|
||||
)
|
||||
}
|
||||
SignerType.NIP04_ENCRYPT -> {
|
||||
CryptoUtils.encryptNIP04(
|
||||
data,
|
||||
account.keyPair.privKey!!,
|
||||
account.signer.keyPair.privKey!!,
|
||||
Hex.decode(pubKey),
|
||||
)
|
||||
}
|
||||
SignerType.NIP44_ENCRYPT -> {
|
||||
CryptoUtils.encryptNIP44(
|
||||
data,
|
||||
account.keyPair.privKey!!,
|
||||
account.signer.keyPair.privKey!!,
|
||||
pubKey.hexToByteArray(),
|
||||
).encodePayload()
|
||||
}
|
||||
else -> {
|
||||
CryptoUtils.decryptNIP44(
|
||||
data,
|
||||
account.keyPair.privKey!!,
|
||||
account.signer.keyPair.privKey!!,
|
||||
pubKey.hexToByteArray(),
|
||||
)
|
||||
}
|
||||
@@ -68,12 +68,12 @@ object AmberUtils {
|
||||
): String? {
|
||||
val event = Event.fromJson(data) as LnZapRequestEvent
|
||||
|
||||
val loggedInPrivateKey = account.keyPair.privKey
|
||||
val loggedInPrivateKey = account.signer.keyPair.privKey
|
||||
|
||||
return if (event.isPrivateZap()) {
|
||||
val recipientPK = event.zappedAuthor().firstOrNull()
|
||||
val recipientPost = event.zappedPost().firstOrNull()
|
||||
if (recipientPK == account.keyPair.pubKey.toHexKey()) {
|
||||
if (recipientPK == account.signer.keyPair.pubKey.toHexKey()) {
|
||||
// if the receiver is logged in, these are the params.
|
||||
val pubkeyToUse = event.pubKey
|
||||
|
||||
|
||||
@@ -146,14 +146,14 @@ class EventNotificationConsumer(private val applicationContext: Context) {
|
||||
Log.d("bunker", request)
|
||||
}
|
||||
|
||||
val dao = NostrSigner.getInstance().getDatabase(acc.keyPair.pubKey.toNpub()).applicationDao()
|
||||
val dao = NostrSigner.getInstance().getDatabase(acc.signer.keyPair.pubKey.toNpub()).applicationDao()
|
||||
val notification = dao.getNotification(event.id)
|
||||
if (notification != null) return
|
||||
dao.insertNotification(NotificationEntity(0, event.id(), event.createdAt))
|
||||
|
||||
val bunkerRequest = BunkerRequest.mapper.readValue(request, BunkerRequest::class.java)
|
||||
bunkerRequest.localKey = event.pubKey
|
||||
bunkerRequest.currentAccount = acc.keyPair.pubKey.toNpub()
|
||||
bunkerRequest.currentAccount = acc.signer.keyPair.pubKey.toNpub()
|
||||
bunkerRequest.encryptionType = encryptionType
|
||||
|
||||
val type = IntentUtils.getTypeFromBunker(bunkerRequest)
|
||||
@@ -171,7 +171,7 @@ class EventNotificationConsumer(private val applicationContext: Context) {
|
||||
""
|
||||
}
|
||||
|
||||
val database = NostrSigner.getInstance().getDatabase(acc.keyPair.pubKey.toNpub())
|
||||
val database = NostrSigner.getInstance().getDatabase(acc.signer.keyPair.pubKey.toNpub())
|
||||
|
||||
val permission = database.applicationDao().getByKey(bunkerRequest.localKey)
|
||||
if (permission != null && permission.application.isConnected && type == SignerType.CONNECT) {
|
||||
@@ -245,7 +245,7 @@ class EventNotificationConsumer(private val applicationContext: Context) {
|
||||
val cursor =
|
||||
applicationContext.contentResolver.query(
|
||||
Uri.parse("content://${BuildConfig.APPLICATION_ID}.$type"),
|
||||
arrayOf(data, pubKey, acc.keyPair.pubKey.toNpub()),
|
||||
arrayOf(data, pubKey, acc.signer.keyPair.pubKey.toNpub()),
|
||||
"1",
|
||||
null,
|
||||
bunkerRequest.localKey,
|
||||
|
||||
@@ -173,7 +173,7 @@ object IntentUtils {
|
||||
SignerType.SIGN_EVENT -> {
|
||||
val unsignedEvent = getUnsignedEvent(localData, account)
|
||||
var localAccount = account
|
||||
if (unsignedEvent.pubKey != account.keyPair.pubKey.toHexKey()) {
|
||||
if (unsignedEvent.pubKey != account.signer.keyPair.pubKey.toHexKey()) {
|
||||
LocalPreferences.loadFromEncryptedStorage(context, Hex.decode(unsignedEvent.pubKey).toNpub())?.let {
|
||||
localAccount = it
|
||||
}
|
||||
@@ -543,7 +543,7 @@ object IntentUtils {
|
||||
SignerType.GET_PUBLIC_KEY -> {
|
||||
onReady(
|
||||
IntentData(
|
||||
account.keyPair.pubKey.toNpub(),
|
||||
account.signer.keyPair.pubKey.toNpub(),
|
||||
"",
|
||||
type,
|
||||
pubKey,
|
||||
@@ -638,7 +638,7 @@ object IntentUtils {
|
||||
SignerType.SIGN_EVENT -> {
|
||||
val unsignedEvent = getUnsignedEvent(data, account)
|
||||
var localAccount = account
|
||||
if (unsignedEvent.pubKey != account.keyPair.pubKey.toHexKey()) {
|
||||
if (unsignedEvent.pubKey != account.signer.keyPair.pubKey.toHexKey()) {
|
||||
LocalPreferences.loadFromEncryptedStorage(context, Hex.decode(unsignedEvent.pubKey).toNpub())?.let {
|
||||
localAccount = it
|
||||
}
|
||||
@@ -892,7 +892,7 @@ object IntentUtils {
|
||||
pubKey,
|
||||
relays.ifEmpty { NostrSigner.getInstance().getSavedRelays().toList() },
|
||||
"",
|
||||
account.keyPair.pubKey.toNpub(),
|
||||
account.signer.keyPair.pubKey.toNpub(),
|
||||
EncryptionType.NIP04,
|
||||
),
|
||||
route,
|
||||
@@ -902,7 +902,7 @@ object IntentUtils {
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
Log.e("nostrconnect", e.message, e)
|
||||
NostrSigner.getInstance().getDatabase(account.keyPair.pubKey.toNpub()).applicationDao().insertLog(
|
||||
NostrSigner.getInstance().getDatabase(account.signer.keyPair.pubKey.toNpub()).applicationDao().insertLog(
|
||||
LogEntity(
|
||||
0,
|
||||
"nostrconnect",
|
||||
@@ -972,7 +972,7 @@ object IntentUtils {
|
||||
): Event {
|
||||
val event = AmberEvent.fromJson(data)
|
||||
if (event.pubKey.isEmpty()) {
|
||||
event.pubKey = account.keyPair.pubKey.toHexKey()
|
||||
event.pubKey = account.signer.keyPair.pubKey.toHexKey()
|
||||
}
|
||||
if (event.id.isEmpty()) {
|
||||
event.id =
|
||||
|
||||
@@ -173,7 +173,7 @@ object NotificationDataSource : NostrDataSource("AccountData") {
|
||||
|
||||
val pubKeys =
|
||||
accounts.mapNotNull {
|
||||
LocalPreferences.loadFromEncryptedStorage(NostrSigner.getInstance(), it.npub)?.keyPair?.pubKey?.toHexKey()
|
||||
LocalPreferences.loadFromEncryptedStorage(NostrSigner.getInstance(), it.npub)?.signer?.keyPair?.pubKey?.toHexKey()
|
||||
}
|
||||
|
||||
val eoses =
|
||||
|
||||
@@ -105,8 +105,8 @@ class RegisterAccounts(
|
||||
if (acc != null) {
|
||||
val permissions =
|
||||
NostrSigner.getInstance().getDatabase(
|
||||
acc.keyPair.pubKey.toNpub(),
|
||||
).applicationDao().getAll(acc.keyPair.pubKey.toHexKey())
|
||||
acc.signer.keyPair.pubKey.toNpub(),
|
||||
).applicationDao().getAll(acc.signer.keyPair.pubKey.toHexKey())
|
||||
permissions.forEach { permission ->
|
||||
permission.relays.forEach { relay ->
|
||||
if (isSupportedUrl(relay.url)) {
|
||||
|
||||
@@ -140,7 +140,7 @@ fun AccountScreen(
|
||||
listOf(intentData)
|
||||
}
|
||||
}.mapNotNull { it }
|
||||
val database = NostrSigner.getInstance().getDatabase(state.account.keyPair.pubKey.toNpub())
|
||||
val database = NostrSigner.getInstance().getDatabase(state.account.signer.keyPair.pubKey.toNpub())
|
||||
val localRoute = mutableStateOf(newIntents.firstNotNullOfOrNull { it.route } ?: state.route)
|
||||
|
||||
SideEffect {
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.greenart7c3.nostrsigner.models.Account
|
||||
import com.vitorpamplona.quartz.crypto.CryptoUtils
|
||||
import com.vitorpamplona.quartz.crypto.KeyPair
|
||||
import com.vitorpamplona.quartz.encoders.bechToBytes
|
||||
import com.vitorpamplona.quartz.signers.NostrSignerInternal
|
||||
import fr.acinq.secp256k1.Hex
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -119,7 +120,7 @@ class AccountStateViewModel(npub: String?) : ViewModel() {
|
||||
CryptoUtils.decryptNIP49(key, password)
|
||||
?: throw Exception("Could not decrypt key with provided password")
|
||||
Account(
|
||||
KeyPair(Hex.decode(newKey)),
|
||||
signer = NostrSignerInternal(KeyPair(Hex.decode(newKey))),
|
||||
name = "",
|
||||
useProxy = false,
|
||||
proxyPort = 0,
|
||||
@@ -130,7 +131,7 @@ class AccountStateViewModel(npub: String?) : ViewModel() {
|
||||
)
|
||||
} else if (key.startsWith("nsec")) {
|
||||
Account(
|
||||
KeyPair(privKey = key.bechToBytes()),
|
||||
signer = NostrSignerInternal(KeyPair(privKey = key.bechToBytes())),
|
||||
name = "",
|
||||
useProxy = false,
|
||||
proxyPort = 0,
|
||||
@@ -142,7 +143,7 @@ class AccountStateViewModel(npub: String?) : ViewModel() {
|
||||
} else if (key.contains(" ") && CryptoUtils.isValidMnemonic(key)) {
|
||||
val keyPair = KeyPair(privKey = CryptoUtils.privateKeyFromMnemonic(key))
|
||||
Account(
|
||||
keyPair,
|
||||
signer = NostrSignerInternal(keyPair),
|
||||
name = "",
|
||||
useProxy = false,
|
||||
proxyPort = 0,
|
||||
@@ -153,7 +154,7 @@ class AccountStateViewModel(npub: String?) : ViewModel() {
|
||||
)
|
||||
} else {
|
||||
Account(
|
||||
KeyPair(Hex.decode(key)),
|
||||
signer = NostrSignerInternal(KeyPair(Hex.decode(key))),
|
||||
name = "",
|
||||
useProxy = false,
|
||||
proxyPort = 0,
|
||||
@@ -163,7 +164,7 @@ class AccountStateViewModel(npub: String?) : ViewModel() {
|
||||
seedWords = emptySet(),
|
||||
)
|
||||
}
|
||||
return account.keyPair.privKey != null
|
||||
return account.signer.keyPair.privKey != null
|
||||
} catch (e: Exception) {
|
||||
return false
|
||||
}
|
||||
@@ -183,7 +184,7 @@ class AccountStateViewModel(npub: String?) : ViewModel() {
|
||||
CryptoUtils.decryptNIP49(key, password)
|
||||
?: throw Exception("Could not decrypt key with provided password")
|
||||
Account(
|
||||
KeyPair(Hex.decode(newKey)),
|
||||
signer = NostrSignerInternal(KeyPair(Hex.decode(newKey))),
|
||||
name = "",
|
||||
useProxy = useProxy,
|
||||
proxyPort = proxyPort,
|
||||
@@ -194,7 +195,7 @@ class AccountStateViewModel(npub: String?) : ViewModel() {
|
||||
)
|
||||
} else if (key.startsWith("nsec")) {
|
||||
Account(
|
||||
KeyPair(privKey = key.bechToBytes()),
|
||||
signer = NostrSignerInternal(KeyPair(privKey = key.bechToBytes())),
|
||||
name = "",
|
||||
useProxy = useProxy,
|
||||
proxyPort = proxyPort,
|
||||
@@ -206,7 +207,7 @@ class AccountStateViewModel(npub: String?) : ViewModel() {
|
||||
} else if (key.contains(" ") && CryptoUtils.isValidMnemonic(key)) {
|
||||
val keyPair = KeyPair(privKey = CryptoUtils.privateKeyFromMnemonic(key))
|
||||
Account(
|
||||
keyPair,
|
||||
signer = NostrSignerInternal(keyPair),
|
||||
name = "",
|
||||
useProxy = useProxy,
|
||||
proxyPort = proxyPort,
|
||||
@@ -217,7 +218,7 @@ class AccountStateViewModel(npub: String?) : ViewModel() {
|
||||
)
|
||||
} else {
|
||||
Account(
|
||||
KeyPair(Hex.decode(key)),
|
||||
signer = NostrSignerInternal(KeyPair(Hex.decode(key))),
|
||||
name = "",
|
||||
useProxy = useProxy,
|
||||
proxyPort = proxyPort,
|
||||
@@ -241,7 +242,7 @@ class AccountStateViewModel(npub: String?) : ViewModel() {
|
||||
val key = seedWords.joinToString(separator = " ") { it }
|
||||
val keyPair = KeyPair(privKey = CryptoUtils.privateKeyFromMnemonic(key))
|
||||
val account = Account(
|
||||
keyPair,
|
||||
NostrSignerInternal(keyPair),
|
||||
name = "",
|
||||
useProxy = useProxy,
|
||||
proxyPort = proxyPort,
|
||||
|
||||
@@ -90,7 +90,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.keyPair.pubKey.toHexKey()}?$relayString$secret")
|
||||
mutableStateOf("bunker://${account.signer.keyPair.pubKey.toHexKey()}?$relayString$secret")
|
||||
}
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
@@ -100,7 +100,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.keyPair.pubKey.toHexKey()}?$relays$localSecret"
|
||||
bunkerUri = "bunker://${account.signer.keyPair.pubKey.toHexKey()}?$relays$localSecret"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ fun LogsScreen(
|
||||
modifier = modifier
|
||||
.fillMaxSize(),
|
||||
) {
|
||||
val logsFlow = NostrSigner.getInstance().getDatabase(account.keyPair.pubKey.toNpub()).applicationDao().getLogs()
|
||||
val logsFlow = NostrSigner.getInstance().getDatabase(account.signer.keyPair.pubKey.toNpub()).applicationDao().getLogs()
|
||||
val logs = logsFlow.collectAsStateWithLifecycle(initialValue = emptyList())
|
||||
|
||||
LazyColumn(
|
||||
@@ -99,7 +99,7 @@ fun LogsScreen(
|
||||
modifier = Modifier.padding(top = 8.dp),
|
||||
onClick = {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
NostrSigner.getInstance().getDatabase(account.keyPair.pubKey.toNpub()).applicationDao().clearLogs()
|
||||
NostrSigner.getInstance().getDatabase(account.signer.keyPair.pubKey.toNpub()).applicationDao().clearLogs()
|
||||
}
|
||||
},
|
||||
content = {
|
||||
|
||||
@@ -154,7 +154,7 @@ fun sendResult(
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
account.keyPair.pubKey.toHexKey(),
|
||||
account.signer.keyPair.pubKey.toHexKey(),
|
||||
true,
|
||||
intentData.bunkerRequest?.secret ?: "",
|
||||
intentData.bunkerRequest?.secret != null,
|
||||
@@ -592,7 +592,7 @@ fun MainScreen(
|
||||
it.route,
|
||||
modifier = Modifier.border(
|
||||
2.dp,
|
||||
Color.fromHex(account.keyPair.pubKey.toHexKey().slice(0..5)),
|
||||
Color.fromHex(account.signer.keyPair.pubKey.toHexKey().slice(0..5)),
|
||||
CircleShape,
|
||||
),
|
||||
)
|
||||
|
||||
@@ -44,7 +44,7 @@ fun NewApplicationScreen(
|
||||
intent.data = Uri.parse(it)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
context.getAppCompatActivity()?.startActivity(intent)
|
||||
accountStateViewModel.switchUser(account.keyPair.pubKey.toNpub(), Route.IncomingRequest.route)
|
||||
accountStateViewModel.switchUser(account.signer.keyPair.pubKey.toNpub(), Route.IncomingRequest.route)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -83,7 +83,7 @@ fun NewApplicationScreen(
|
||||
intent.data = Uri.parse(it.text)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
context.getAppCompatActivity()?.startActivity(intent)
|
||||
accountStateViewModel.switchUser(account.keyPair.pubKey.toNpub(), Route.IncomingRequest.route)
|
||||
accountStateViewModel.switchUser(account.signer.keyPair.pubKey.toNpub(), Route.IncomingRequest.route)
|
||||
}
|
||||
},
|
||||
content = {
|
||||
|
||||
@@ -227,7 +227,7 @@ fun NewNsecBunkerScreen(
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
account.keyPair.pubKey.toHexKey(),
|
||||
account.signer.keyPair.pubKey.toHexKey(),
|
||||
false,
|
||||
secret.value,
|
||||
true,
|
||||
@@ -273,7 +273,7 @@ fun NewNsecBunkerCreatedScreen(
|
||||
} else {
|
||||
val relays = application.relays.joinToString(separator = "&") { "relay=${it.url}" }
|
||||
val localSecret = "&secret=${application.secret}"
|
||||
val bunkerUri = "bunker://${account.keyPair.pubKey.toHexKey()}?$relays$localSecret"
|
||||
val bunkerUri = "bunker://${account.signer.keyPair.pubKey.toHexKey()}?$relays$localSecret"
|
||||
|
||||
Column(
|
||||
modifier = modifier
|
||||
|
||||
@@ -44,7 +44,7 @@ fun PermissionsScreen(
|
||||
) {
|
||||
val lifecycleEvent = rememberLifecycleEvent()
|
||||
val context = LocalContext.current
|
||||
val localAccount = LocalPreferences.loadFromEncryptedStorage(context, account.keyPair.pubKey.toNpub())!!
|
||||
val localAccount = LocalPreferences.loadFromEncryptedStorage(context, account.signer.keyPair.pubKey.toNpub())!!
|
||||
val applications =
|
||||
remember {
|
||||
mutableListOf<ApplicationEntity>()
|
||||
@@ -55,7 +55,7 @@ fun PermissionsScreen(
|
||||
LaunchedEffect(lifecycleEvent) {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
applications.clear()
|
||||
applications.addAll(database.applicationDao().getAll(localAccount.keyPair.pubKey.toHexKey()))
|
||||
applications.addAll(database.applicationDao().getAll(localAccount.signer.keyPair.pubKey.toHexKey()))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ fun SettingsScreen(
|
||||
},
|
||||
onConfirm = {
|
||||
logoutDialog = false
|
||||
accountStateViewModel.logOff(account.keyPair.pubKey.toNpub())
|
||||
accountStateViewModel.logOff(account.signer.keyPair.pubKey.toNpub())
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -292,7 +292,7 @@ private fun NSecQrButton(account: Account) {
|
||||
|
||||
if (showDialog) {
|
||||
QrCodeDialog(
|
||||
content = account.keyPair.privKey!!.toNsec(),
|
||||
content = account.signer.keyPair.privKey!!.toNsec(),
|
||||
) {
|
||||
showDialog = false
|
||||
}
|
||||
@@ -424,7 +424,7 @@ private fun copyNSec(
|
||||
account: Account,
|
||||
clipboardManager: ClipboardManager,
|
||||
) {
|
||||
account.keyPair.privKey?.let {
|
||||
account.signer.keyPair.privKey?.let {
|
||||
clipboardManager.setText(AnnotatedString(it.toNsec()))
|
||||
scope.launch {
|
||||
Toast.makeText(
|
||||
@@ -496,7 +496,7 @@ private fun EncryptNSecQRButton(
|
||||
|
||||
if (showDialog) {
|
||||
QrCodeDialog(
|
||||
content = CryptoUtils.encryptNIP49(account.keyPair.privKey!!.toHexKey(), password.value.text),
|
||||
content = CryptoUtils.encryptNIP49(account.signer.keyPair.privKey!!.toHexKey(), password.value.text),
|
||||
) {
|
||||
showDialog = false
|
||||
}
|
||||
@@ -554,7 +554,7 @@ private fun encryptCopyNSec(
|
||||
.show()
|
||||
}
|
||||
} else {
|
||||
account.keyPair.privKey?.let {
|
||||
account.signer.keyPair.privKey?.let {
|
||||
try {
|
||||
val key = CryptoUtils.encryptNIP49(it.toHexKey(), password.value.text)
|
||||
clipboardManager.setText(AnnotatedString(key))
|
||||
|
||||
@@ -122,7 +122,7 @@ fun AccountsBottomSheet(
|
||||
LocalPreferences.setAccountName(context, currentNpub, it)
|
||||
showNameDialog = false
|
||||
currentNpub = ""
|
||||
accountStateViewModel.switchUser(account.keyPair.pubKey.toNpub(), Route.Settings.route)
|
||||
accountStateViewModel.switchUser(account.signer.keyPair.pubKey.toNpub(), Route.Settings.route)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -40,8 +40,8 @@ fun LogoutButton(
|
||||
scope.launch(Dispatchers.IO) {
|
||||
val account = LocalPreferences.loadFromEncryptedStorage(context, acc.npub)
|
||||
account?.let {
|
||||
val database = NostrSigner.getInstance().getDatabase(account.keyPair.pubKey.toNpub())
|
||||
val permissions = database.applicationDao().getAll(it.keyPair.pubKey.toHexKey())
|
||||
val database = NostrSigner.getInstance().getDatabase(account.signer.keyPair.pubKey.toNpub())
|
||||
val permissions = database.applicationDao().getAll(it.signer.keyPair.pubKey.toHexKey())
|
||||
permissions.forEach { app ->
|
||||
database.applicationDao().delete(app)
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ fun ActiveMarker(
|
||||
) {
|
||||
val isCurrentUser by remember(account) {
|
||||
derivedStateOf {
|
||||
account.keyPair.pubKey.toNpub() == acc.npub
|
||||
account.signer.keyPair.pubKey.toNpub() == acc.npub
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -357,7 +357,7 @@ fun MultiEventHomeScreen(
|
||||
|
||||
val key = intentData.bunkerRequest?.localKey ?: packageName ?: continue
|
||||
|
||||
val database = NostrSigner.getInstance().getDatabase(localAccount.keyPair.pubKey.toNpub())
|
||||
val database = NostrSigner.getInstance().getDatabase(localAccount.signer.keyPair.pubKey.toNpub())
|
||||
|
||||
val application =
|
||||
database
|
||||
@@ -370,7 +370,7 @@ fun MultiEventHomeScreen(
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
localAccount.keyPair.pubKey.toHexKey(),
|
||||
localAccount.signer.keyPair.pubKey.toHexKey(),
|
||||
true,
|
||||
intentData.bunkerRequest?.secret ?: "",
|
||||
intentData.bunkerRequest?.secret != null,
|
||||
@@ -468,7 +468,7 @@ fun MultiEventHomeScreen(
|
||||
),
|
||||
)
|
||||
|
||||
val signedMessage = CryptoUtils.signString(intentData.data, localAccount.keyPair.privKey!!).toHexKey()
|
||||
val signedMessage = CryptoUtils.signString(intentData.data, localAccount.signer.keyPair.privKey!!).toHexKey()
|
||||
|
||||
if (intentData.bunkerRequest != null) {
|
||||
IntentUtils.sendBunkerResponse(
|
||||
@@ -601,7 +601,7 @@ fun ListItem(
|
||||
localAccount = LocalPreferences.loadFromEncryptedStorage(
|
||||
context,
|
||||
intentData.currentAccount,
|
||||
)?.keyPair?.pubKey?.toNpub()?.toShortenHex() ?: ""
|
||||
)?.signer?.keyPair?.pubKey?.toNpub()?.toShortenHex() ?: ""
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -105,9 +105,9 @@ fun SingleEventHomeScreen(
|
||||
if (intentData.type == SignerType.CONNECT) {
|
||||
"ack"
|
||||
} else if (intentData.bunkerRequest != null) {
|
||||
account.keyPair.pubKey.toHexKey()
|
||||
account.signer.keyPair.pubKey.toHexKey()
|
||||
} else {
|
||||
account.keyPair.pubKey.toNpub()
|
||||
account.signer.keyPair.pubKey.toNpub()
|
||||
}
|
||||
coroutineScope.launch {
|
||||
sendResult(
|
||||
@@ -184,7 +184,7 @@ fun SingleEventHomeScreen(
|
||||
intentData.type,
|
||||
{
|
||||
coroutineScope.launch(Dispatchers.IO) {
|
||||
val result = CryptoUtils.signString(intentData.data, account.keyPair.privKey!!).toHexKey()
|
||||
val result = CryptoUtils.signString(intentData.data, account.signer.keyPair.privKey!!).toHexKey()
|
||||
|
||||
sendResult(
|
||||
context,
|
||||
@@ -220,7 +220,7 @@ fun SingleEventHomeScreen(
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
account.keyPair.pubKey.toHexKey(),
|
||||
account.signer.keyPair.pubKey.toHexKey(),
|
||||
true,
|
||||
intentData.bunkerRequest?.secret ?: "",
|
||||
intentData.bunkerRequest?.secret != null,
|
||||
@@ -357,7 +357,7 @@ fun SingleEventHomeScreen(
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
account.keyPair.pubKey.toHexKey(),
|
||||
account.signer.keyPair.pubKey.toHexKey(),
|
||||
true,
|
||||
intentData.bunkerRequest?.secret ?: "",
|
||||
intentData.bunkerRequest?.secret != null,
|
||||
@@ -460,7 +460,7 @@ fun SingleEventHomeScreen(
|
||||
event.toJson(),
|
||||
intentData.type,
|
||||
{
|
||||
if (event.pubKey != account.keyPair.pubKey.toHexKey() && !isPrivateEvent(event.kind, event.tags)) {
|
||||
if (event.pubKey != account.signer.keyPair.pubKey.toHexKey() && !isPrivateEvent(event.kind, event.tags)) {
|
||||
coroutineScope.launch {
|
||||
Toast.makeText(
|
||||
context,
|
||||
@@ -517,7 +517,7 @@ fun SingleEventHomeScreen(
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
account.keyPair.pubKey.toHexKey(),
|
||||
account.signer.keyPair.pubKey.toHexKey(),
|
||||
true,
|
||||
intentData.bunkerRequest?.secret ?: "",
|
||||
intentData.bunkerRequest?.secret != null,
|
||||
|
||||
Reference in New Issue
Block a user