mirror of
https://github.com/greenart7c3/Amber.git
synced 2026-10-05 19:08:23 +00:00
secret is optional now
This commit is contained in:
@@ -2,11 +2,11 @@
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 1,
|
||||
"identityHash": "5651f3201d3521ce45fda80b053e6722",
|
||||
"identityHash": "3267256afb5b9a388fb15f267466e995",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "application",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`key` TEXT NOT NULL, `name` TEXT NOT NULL, `relays` TEXT NOT NULL, `url` TEXT NOT NULL, `icon` TEXT NOT NULL, `description` TEXT NOT NULL, `pubKey` TEXT NOT NULL, `isConnected` INTEGER NOT NULL, `secret` TEXT NOT NULL, PRIMARY KEY(`key`))",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`key` TEXT NOT NULL, `name` TEXT NOT NULL, `relays` TEXT NOT NULL, `url` TEXT NOT NULL, `icon` TEXT NOT NULL, `description` TEXT NOT NULL, `pubKey` TEXT NOT NULL, `isConnected` INTEGER NOT NULL, `secret` TEXT NOT NULL, `useSecret` INTEGER NOT NULL, PRIMARY KEY(`key`))",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "key",
|
||||
@@ -61,6 +61,12 @@
|
||||
"columnName": "secret",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "useSecret",
|
||||
"columnName": "useSecret",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
@@ -172,7 +178,7 @@
|
||||
"views": [],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '5651f3201d3521ce45fda80b053e6722')"
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '3267256afb5b9a388fb15f267466e995')"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -238,7 +238,8 @@ object LocalPreferences {
|
||||
"",
|
||||
pubKey,
|
||||
true,
|
||||
""
|
||||
"",
|
||||
false
|
||||
)
|
||||
)
|
||||
database.applicationDao().insertPermissions(
|
||||
|
||||
@@ -32,7 +32,8 @@ data class ApplicationEntity(
|
||||
val description: String,
|
||||
val pubKey: String,
|
||||
var isConnected: Boolean,
|
||||
val secret: String
|
||||
val secret: String,
|
||||
val useSecret: Boolean
|
||||
)
|
||||
|
||||
data class ApplicationWithPermissions(
|
||||
|
||||
@@ -16,6 +16,9 @@ class nostrsigner : Application() {
|
||||
}
|
||||
|
||||
fun getDatabase(npub: String): AppDatabase {
|
||||
if (!databases.containsKey(npub)) {
|
||||
databases[npub] = AppDatabase.getDatabase(this, npub)
|
||||
}
|
||||
return databases[npub]!!
|
||||
}
|
||||
|
||||
|
||||
@@ -148,7 +148,8 @@ object AmberUtils {
|
||||
"",
|
||||
account.keyPair.pubKey.toHexKey(),
|
||||
true,
|
||||
intentData.bunkerRequest?.secret ?: ""
|
||||
intentData.bunkerRequest?.secret ?: "",
|
||||
intentData.bunkerRequest?.secret != null
|
||||
),
|
||||
permissions = mutableListOf()
|
||||
)
|
||||
|
||||
+20
-11
@@ -220,17 +220,26 @@ class EventNotificationConsumer(private val applicationContext: Context) {
|
||||
} catch (_: Exception) {
|
||||
""
|
||||
}
|
||||
bunkerRequest.secret = secret
|
||||
applicationWithSecret = database.applicationDao().getBySecret(secret)
|
||||
if (applicationWithSecret == null || secret.isBlank()) {
|
||||
IntentUtils.sendBunkerResponse(
|
||||
acc,
|
||||
bunkerRequest.localKey,
|
||||
BunkerResponse(bunkerRequest.id, "", "invalid secret"),
|
||||
relays,
|
||||
onLoading = { }
|
||||
) { }
|
||||
return@nip04Decrypt
|
||||
// TODO: make secret not optional when more applications start using it
|
||||
if (secret.isNotBlank()) {
|
||||
bunkerRequest.secret = secret
|
||||
applicationWithSecret = database.applicationDao().getBySecret(secret)
|
||||
if (applicationWithSecret == null || secret.isBlank()) {
|
||||
IntentUtils.sendBunkerResponse(
|
||||
acc,
|
||||
bunkerRequest.localKey,
|
||||
BunkerResponse(bunkerRequest.id, "", "invalid secret"),
|
||||
relays,
|
||||
onLoading = { }
|
||||
) { }
|
||||
return@nip04Decrypt
|
||||
}
|
||||
} else {
|
||||
applicationWithSecret = database.applicationDao().getAllApplications().firstOrNull { localApp ->
|
||||
!localApp.application.useSecret
|
||||
}
|
||||
|
||||
bunkerRequest.secret = applicationWithSecret?.application?.secret ?: ""
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
@@ -77,7 +78,7 @@ fun EditPermission(
|
||||
mutableStateListOf<ApplicationPermissionsEntity>()
|
||||
}
|
||||
var applicationData by remember {
|
||||
mutableStateOf(ApplicationEntity(selectedPackage, "", emptyList(), "", "", "", "", true, ""))
|
||||
mutableStateOf(ApplicationEntity(selectedPackage, "", emptyList(), "", "", "", "", true, "", false))
|
||||
}
|
||||
var textFieldvalue by remember(applicationData.name) {
|
||||
mutableStateOf(TextFieldValue(applicationData.name))
|
||||
@@ -85,10 +86,17 @@ fun EditPermission(
|
||||
var wantsToDelete by remember { mutableStateOf(false) }
|
||||
val scope = rememberCoroutineScope()
|
||||
|
||||
var checked by remember {
|
||||
mutableStateOf(applicationData.useSecret)
|
||||
}
|
||||
val secret = if (checked) "&secret=${applicationData.secret}" else ""
|
||||
val bunkerUri = "bunker://${account.keyPair.pubKey.toHexKey()}?relay=wss://relay.nsec.app$secret"
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
permissions.addAll(database.applicationDao().getAllByKey(selectedPackage).sortedBy { "${it.type}-${it.kind}" })
|
||||
applicationData = database.applicationDao().getByKey(selectedPackage)!!.application
|
||||
checked = applicationData.useSecret
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +123,6 @@ fun EditPermission(
|
||||
mutableStateOf(false)
|
||||
}
|
||||
|
||||
val bunkerUri = "bunker://${account.keyPair.pubKey.toHexKey()}?relay=wss://relay.nsec.app&secret=${applicationData.secret}"
|
||||
if (showDialog) {
|
||||
QrCodeDialog(
|
||||
content = bunkerUri
|
||||
@@ -167,6 +174,27 @@ fun EditPermission(
|
||||
Icon(Icons.Default.QrCode, stringResource(R.string.show_qr_code))
|
||||
}
|
||||
}
|
||||
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 8.dp)
|
||||
.clickable {
|
||||
checked = !checked
|
||||
}
|
||||
) {
|
||||
Text(
|
||||
modifier = Modifier.weight(1f),
|
||||
text = "Use secret to connect to the application"
|
||||
)
|
||||
Switch(
|
||||
checked = checked,
|
||||
onCheckedChange = {
|
||||
checked = !checked
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
OutlinedTextField(
|
||||
modifier = Modifier
|
||||
|
||||
@@ -154,7 +154,8 @@ fun sendResult(
|
||||
"",
|
||||
account.keyPair.pubKey.toHexKey(),
|
||||
true,
|
||||
intentData.bunkerRequest?.secret ?: ""
|
||||
intentData.bunkerRequest?.secret ?: "",
|
||||
intentData.bunkerRequest?.secret != null
|
||||
),
|
||||
permissions = mutableListOf()
|
||||
)
|
||||
@@ -538,13 +539,14 @@ fun MainScreen(
|
||||
"",
|
||||
account.keyPair.pubKey.toHexKey(),
|
||||
false,
|
||||
secret
|
||||
secret,
|
||||
false
|
||||
)
|
||||
|
||||
database.applicationDao().insertApplication(
|
||||
application
|
||||
)
|
||||
val bunkerUrl = "bunker://${account.keyPair.pubKey.toHexKey()}?relay=wss://relay.nsec.app&secret=${application.secret}"
|
||||
val bunkerUrl = "bunker://${account.keyPair.pubKey.toHexKey()}?relay=wss://relay.nsec.app"
|
||||
clipboardManager.setText(AnnotatedString(bunkerUrl))
|
||||
scope.launch(Dispatchers.Main) {
|
||||
navController.popBackStack()
|
||||
|
||||
Reference in New Issue
Block a user