Fix some lints

This commit is contained in:
greenart7c3
2025-02-21 09:54:36 -03:00
parent 4b848a9d21
commit b91ccf551c
17 changed files with 40 additions and 178 deletions
@@ -256,11 +256,6 @@ fun nipToLocalizedString(context: Context, permission: Permission, shouldReturnE
data class KindNip(val kind: IntRange, val nip: String)
fun Int.kindToNipUrl(): String? =
kindsByNip.firstOrNull { it.kind.contains(this) }?.let {
return if (it.nip.startsWith("http")) it.nip else "https://github.com/nostr-protocol/nips/blob/master/${it.nip}.md"
}
fun Int.containsNip(): Boolean = kindsByNip.any {
val nip = if (this < 10) {
this.toString().padStart(2, '0')
@@ -272,9 +267,6 @@ fun Int.containsNip(): Boolean = kindsByNip.any {
fun Int.kindToNip(): String? = kindsByNip.firstOrNull { it.kind.contains(this) }?.nip
fun Int.nipToUrl(): String? = kindsByNip.firstOrNull { it.nip.toIntOrNull() == this }
?.nip?.let { nip -> if (nip.startsWith("http")) nip else "https://github.com/nostr-protocol/nips/blob/master/$nip.md" }
val kindsByNip = listOf(
KindNip(0..2, "01"),
KindNip(3..3, "02"),
@@ -28,7 +28,7 @@ import okhttp3.Response
import okhttp3.ResponseBody.Companion.toResponseBody
class EncryptedBlobInterceptor(
val cache: EncryptionKeyCache,
private val cache: EncryptionKeyCache,
) : Interceptor {
fun Response.decrypt(cipher: NostrCipher): Response {
val body = peekBody(Long.MAX_VALUE)
@@ -37,7 +37,7 @@ class EncryptedBlobInterceptor(
return newBuilder().body(newBody).build()
}
fun Response.decryptOrNull(cipher: NostrCipher): Response? =
private fun Response.decryptOrNull(cipher: NostrCipher): Response? =
try {
decrypt(cipher)
} catch (e: Exception) {
@@ -30,7 +30,7 @@ import com.vitorpamplona.quartz.crypto.nip17.NostrCipher
* This class serves as a key cache to decrypt the body of HTTP calls that need it.
*/
class EncryptionKeyCache {
val cache = LruCache<String, NostrCipher>(100)
private val cache = LruCache<String, NostrCipher>(100)
fun add(
url: String?,
@@ -21,8 +21,6 @@
package com.greenart7c3.nostrsigner.okhttp
import android.util.Log
import com.vitorpamplona.amethyst.service.okhttp.LoggingInterceptor
import com.vitorpamplona.quartz.crypto.nip17.NostrCipher
import java.net.InetSocketAddress
import java.net.Proxy
import java.time.Duration
@@ -48,7 +46,7 @@ object HttpClientManager {
private val cache = EncryptionKeyCache()
fun setDefaultProxy(proxy: Proxy?) {
private fun setDefaultProxy(proxy: Proxy?) {
if (currentProxy != proxy) {
Log.d("HttpClient", "Changing proxy to: ${proxy != null}")
currentProxy = proxy
@@ -58,8 +56,6 @@ object HttpClientManager {
}
}
fun getCurrentProxy(): Proxy? = currentProxy
fun setDefaultTimeout(timeout: Duration) {
Log.d("HttpClient", "Changing timeout to: $timeout")
if (defaultTimeout.seconds != timeout.seconds) {
@@ -98,13 +94,6 @@ object HttpClientManager {
.build()
}
fun getCurrentProxyPort(useProxy: Boolean): Int? =
if (useProxy) {
(currentProxy?.address() as? InetSocketAddress)?.port
} else {
null
}
fun getHttpClient(useProxy: Boolean): OkHttpClient =
if (useProxy) {
if (defaultHttpClient == null) {
@@ -121,9 +110,4 @@ object HttpClientManager {
fun setDefaultProxyOnPort(port: Int) {
setDefaultProxy(Proxy(Proxy.Type.SOCKS, InetSocketAddress("127.0.0.1", port)))
}
fun addCipherToCache(
url: String,
cipher: NostrCipher,
) = cache.add(url, cipher)
}
@@ -18,7 +18,7 @@
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.vitorpamplona.amethyst.service.okhttp
package com.greenart7c3.nostrsigner.okhttp
import android.util.Log
import java.net.InetSocketAddress
@@ -28,13 +28,13 @@ import okhttp3.Response
class OkHttpWebSocket(
val url: String,
val forceProxy: Boolean,
private val forceProxy: Boolean,
val out: WebSocketListener,
) : WebSocket {
private val listener = OkHttpWebsocketListener()
private var socket: okhttp3.WebSocket? = null
fun buildRequest() = Request.Builder().url(url.trim()).build()
private fun buildRequest() = Request.Builder().url(url.trim()).build()
override fun connect() {
socket = HttpClientManager.getHttpClient(forceProxy).newWebSocket(buildRequest(), listener)
@@ -46,7 +46,7 @@ class OkHttpWebSocket(
response: Response,
) = out.onOpen(
response.receivedResponseAtMillis - response.sentRequestAtMillis,
response.headers.get("Sec-WebSocket-Extensions")?.contains("permessage-deflate") ?: false,
response.headers["Sec-WebSocket-Extensions"]?.contains("permessage-deflate") ?: false,
)
override fun onMessage(
@@ -14,13 +14,6 @@ import androidx.biometric.BiometricPrompt
import com.greenart7c3.nostrsigner.R
object Biometrics {
fun isFingerprintAvailable(context: Context): Boolean {
val fragmentContext = context.getAppCompatActivity()!!
val keyguardManager =
fragmentContext.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
return keyguardManager.isDeviceSecure
}
fun authenticate(
title: String,
context: Context,
@@ -1,39 +0,0 @@
/**
* Copyright (c) 2024 Vitor Pamplona
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.greenart7c3.nostrsigner.service
import android.annotation.SuppressLint
import android.content.Context
object PackageUtils {
@SuppressLint("QueryPermissionsNeeded")
private fun isPackageInstalled(
context: Context,
): Boolean {
return context.packageManager.getInstalledApplications(0).find { info ->
info.packageName == "org.torproject.android"
} != null
}
fun isOrbotInstalled(context: Context): Boolean {
return isPackageInstalled(context)
}
}
@@ -24,7 +24,6 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
@@ -270,7 +270,7 @@ class AccountStateViewModel(npub: String?) : ViewModel() {
startUI(account, null)
}
fun startUI(
private fun startUI(
account: Account,
route: String?,
) {
@@ -1,28 +0,0 @@
package com.greenart7c3.nostrsigner.ui
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.compose.LocalLifecycleOwner
@Composable
fun rememberLifecycleEvent(lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current): Lifecycle.Event {
var state by remember { mutableStateOf(Lifecycle.Event.ON_ANY) }
DisposableEffect(lifecycleOwner) {
val observer =
LifecycleEventObserver { _, event ->
state = event
}
lifecycleOwner.lifecycle.addObserver(observer)
onDispose {
lifecycleOwner.lifecycle.removeObserver(observer)
}
}
return state
}
@@ -12,8 +12,6 @@ import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
@@ -1,7 +1,6 @@
package com.greenart7c3.nostrsigner.ui
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
@@ -33,10 +33,8 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.SpanStyle
@@ -180,7 +180,7 @@ fun MultiEventHomeScreen(
onRemoveIntentData(intents, IntentResultType.REMOVE)
for (intentData in intents) {
val localAccount =
val thisAccount =
if (intentData.currentAccount.isNotBlank()) {
LocalPreferences.loadFromEncryptedStorage(
context,
@@ -190,25 +190,25 @@ fun MultiEventHomeScreen(
accountParam
} ?: continue
val key = intentData.bunkerRequest?.localKey ?: packageName ?: continue
val localKey = intentData.bunkerRequest?.localKey ?: packageName ?: continue
val database = NostrSigner.getInstance().getDatabase(localAccount.signer.keyPair.pubKey.toNpub())
val savedApplication = database.applicationDao().getByKey(key)
val database = NostrSigner.getInstance().getDatabase(thisAccount.signer.keyPair.pubKey.toNpub())
val savedApplication = database.applicationDao().getByKey(localKey)
val application =
savedApplication ?: ApplicationWithPermissions(
application = ApplicationEntity(
key,
localKey,
"",
listOf(),
"",
"",
"",
localAccount.signer.keyPair.pubKey.toHexKey(),
thisAccount.signer.keyPair.pubKey.toHexKey(),
true,
intentData.bunkerRequest?.secret ?: "",
intentData.bunkerRequest?.secret != null,
localAccount.signPolicy,
thisAccount.signPolicy,
intentData.bunkerRequest?.closeApplication ?: true,
),
permissions = mutableListOf(),
@@ -224,7 +224,7 @@ fun MultiEventHomeScreen(
if (intentData.rememberMyChoice.value && intentData.checked.value) {
AmberUtils.acceptOrRejectPermission(
application,
key,
localKey,
intentData,
localEvent.kind,
intentData.rememberMyChoice.value,
@@ -237,7 +237,7 @@ fun MultiEventHomeScreen(
database.applicationDao().addHistory(
HistoryEntity(
0,
key,
localKey,
intentData.type.toString(),
localEvent.kind,
TimeUtils.now(),
@@ -252,7 +252,7 @@ fun MultiEventHomeScreen(
if (intentData.checked.value) {
BunkerRequestUtils.sendBunkerResponse(
context,
localAccount,
thisAccount,
intentData.bunkerRequest,
BunkerResponse(intentData.bunkerRequest.id, localEvent.toJson(), null),
application.application.relays,
@@ -266,7 +266,7 @@ fun MultiEventHomeScreen(
} else {
AmberUtils.sendBunkerError(
intentData,
localAccount,
thisAccount,
intentData.bunkerRequest,
relays = application.application.relays,
context = context,
@@ -307,7 +307,7 @@ fun MultiEventHomeScreen(
if (intentData.rememberMyChoice.value && intentData.checked.value) {
AmberUtils.acceptOrRejectPermission(
application,
key,
localKey,
intentData,
null,
intentData.rememberMyChoice.value,
@@ -319,7 +319,7 @@ fun MultiEventHomeScreen(
database.applicationDao().addHistory(
HistoryEntity(
0,
key,
localKey,
intentData.type.toString(),
null,
TimeUtils.now(),
@@ -327,7 +327,7 @@ fun MultiEventHomeScreen(
),
)
val signedMessage = CryptoUtils.signString(intentData.data, localAccount.signer.keyPair.privKey!!).toHexKey()
val signedMessage = CryptoUtils.signString(intentData.data, thisAccount.signer.keyPair.privKey!!).toHexKey()
if (intentData.bunkerRequest != null) {
val localIntentData = intentData.copy()
@@ -336,7 +336,7 @@ fun MultiEventHomeScreen(
if (intentData.checked.value) {
BunkerRequestUtils.sendBunkerResponse(
context,
localAccount,
thisAccount,
intentData.bunkerRequest,
BunkerResponse(intentData.bunkerRequest.id, signedMessage, null),
application.application.relays,
@@ -350,7 +350,7 @@ fun MultiEventHomeScreen(
} else {
AmberUtils.sendBunkerError(
intentData,
localAccount,
thisAccount,
intentData.bunkerRequest,
relays = application.application.relays,
context = context,
@@ -378,7 +378,7 @@ fun MultiEventHomeScreen(
database.applicationDao().addHistory(
HistoryEntity(
0,
key,
localKey,
intentData.type.toString(),
null,
TimeUtils.now(),
@@ -392,7 +392,7 @@ fun MultiEventHomeScreen(
if (intentData.checked.value) {
BunkerRequestUtils.sendBunkerResponse(
context,
localAccount,
thisAccount,
intentData.bunkerRequest,
BunkerResponse(intentData.bunkerRequest.id, "", null),
application.application.relays,
@@ -406,7 +406,7 @@ fun MultiEventHomeScreen(
} else {
AmberUtils.sendBunkerError(
intentData,
localAccount,
thisAccount,
intentData.bunkerRequest,
relays = application.application.relays,
context = context,
@@ -432,7 +432,7 @@ fun MultiEventHomeScreen(
if (intentData.rememberMyChoice.value && intentData.checked.value) {
AmberUtils.acceptOrRejectPermission(
application,
key,
localKey,
intentData,
null,
intentData.rememberMyChoice.value,
@@ -445,7 +445,7 @@ fun MultiEventHomeScreen(
database.applicationDao().addHistory(
HistoryEntity(
0,
key,
localKey,
intentData.type.toString(),
null,
TimeUtils.now(),
@@ -461,7 +461,7 @@ fun MultiEventHomeScreen(
if (intentData.checked.value) {
BunkerRequestUtils.sendBunkerResponse(
context,
localAccount,
thisAccount,
intentData.bunkerRequest,
BunkerResponse(intentData.bunkerRequest.id, signature, null),
application.application.relays,
@@ -475,7 +475,7 @@ fun MultiEventHomeScreen(
} else {
AmberUtils.sendBunkerError(
intentData,
localAccount,
thisAccount,
intentData.bunkerRequest,
relays = application.application.relays,
context = context,
@@ -526,7 +526,7 @@ fun MultiEventHomeScreen(
BunkerRequestUtils.clearRequests()
onRemoveIntentData(intents, IntentResultType.REMOVE)
for (intentData in intents) {
val localAccount =
val thisAccount =
if (intentData.currentAccount.isNotBlank()) {
LocalPreferences.loadFromEncryptedStorage(
context,
@@ -536,26 +536,26 @@ fun MultiEventHomeScreen(
accountParam
} ?: continue
val key = intentData.bunkerRequest?.localKey ?: packageName ?: continue
val localKey = intentData.bunkerRequest?.localKey ?: packageName ?: continue
val database = NostrSigner.getInstance().getDatabase(localAccount.signer.keyPair.pubKey.toNpub())
val database = NostrSigner.getInstance().getDatabase(thisAccount.signer.keyPair.pubKey.toNpub())
val application =
database
.applicationDao()
.getByKey(key) ?: ApplicationWithPermissions(
.getByKey(localKey) ?: ApplicationWithPermissions(
application = ApplicationEntity(
key,
localKey,
"",
listOf(),
"",
"",
"",
localAccount.signer.keyPair.pubKey.toHexKey(),
thisAccount.signer.keyPair.pubKey.toHexKey(),
true,
intentData.bunkerRequest?.secret ?: "",
intentData.bunkerRequest?.secret != null,
localAccount.signPolicy,
thisAccount.signPolicy,
intentData.bunkerRequest?.closeApplication ?: true,
),
permissions = mutableListOf(),
@@ -564,7 +564,7 @@ fun MultiEventHomeScreen(
if (intentData.rememberMyChoice.value && intentData.checked.value) {
AmberUtils.acceptOrRejectPermission(
application,
key,
localKey,
intentData,
null,
false,
@@ -1,33 +0,0 @@
package com.greenart7c3.nostrsigner.ui.components
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.greenart7c3.nostrsigner.R
import com.greenart7c3.nostrsigner.ui.theme.ButtonBorder
@Composable
fun PostButton(
modifier: Modifier = Modifier,
isActive: Boolean,
onPost: () -> Unit = {},
) {
Button(
enabled = isActive,
modifier = modifier,
onClick = {
if (isActive) {
onPost()
}
},
shape = ButtonBorder,
contentPadding = PaddingValues(0.dp),
) {
Text(text = stringResource(R.string.save), color = Color.White)
}
}
@@ -36,7 +36,6 @@ val primaryColor = Color(0xFFFFCA62)
val primaryVariant = Color(0xFFC8541A)
val secondaryColor = Color(0xFFFFCA62)
val orange = Color(0xFFFF6B00)
val defaultPadding = 35.dp
val RichTextDefaults = RichTextStyle().resolveDefaults()
private val DarkColorPalette =