mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-06-25 19:00:51 +02:00
Merge pull request #744 from greenart7c3/reject_permission_amber
add support for always rejected permissions from external signer
This commit is contained in:
commit
db12ff0532
@ -252,7 +252,10 @@ class ExternalSignerLauncher(
|
||||
arrayOf(event.toJson(), event.pubKey()),
|
||||
columnName,
|
||||
)
|
||||
if (result == null) {
|
||||
result.fold(
|
||||
onFailure = { },
|
||||
onSuccess = {
|
||||
if (it == null) {
|
||||
openSignerApp(
|
||||
event.toJson(),
|
||||
SignerType.SIGN_EVENT,
|
||||
@ -261,24 +264,26 @@ class ExternalSignerLauncher(
|
||||
onReady,
|
||||
)
|
||||
} else {
|
||||
onReady(result)
|
||||
onReady(it)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fun getDataFromResolver(
|
||||
private fun getDataFromResolver(
|
||||
signerType: SignerType,
|
||||
data: Array<out String>,
|
||||
columnName: String = "signature",
|
||||
): String? {
|
||||
): kotlin.Result<String?> {
|
||||
return getDataFromResolver(signerType, data, columnName, contentResolver)
|
||||
}
|
||||
|
||||
fun getDataFromResolver(
|
||||
private fun getDataFromResolver(
|
||||
signerType: SignerType,
|
||||
data: Array<out String>,
|
||||
columnName: String = "signature",
|
||||
contentResolver: (() -> ContentResolver)? = null,
|
||||
): String? {
|
||||
): kotlin.Result<String?> {
|
||||
val localData =
|
||||
if (signerType !== SignerType.GET_PUBLIC_KEY) {
|
||||
data.toList().plus(npub).toTypedArray()
|
||||
@ -292,29 +297,33 @@ class ExternalSignerLauncher(
|
||||
?.query(
|
||||
Uri.parse("content://$signerPackageName.$signerType"),
|
||||
localData,
|
||||
null,
|
||||
"1",
|
||||
null,
|
||||
null,
|
||||
)
|
||||
.use {
|
||||
if (it == null) {
|
||||
return null
|
||||
return kotlin.Result.success(null)
|
||||
}
|
||||
if (it.moveToFirst()) {
|
||||
if (it.getColumnIndex("rejected") > -1) {
|
||||
Log.d("getDataFromResolver", "Permission denied")
|
||||
return kotlin.Result.failure(Exception("Permission denied"))
|
||||
}
|
||||
val index = it.getColumnIndex(columnName)
|
||||
if (index < 0) {
|
||||
Log.d("getDataFromResolver", "column '$columnName' not found")
|
||||
return null
|
||||
return kotlin.Result.success(null)
|
||||
}
|
||||
return it.getString(index)
|
||||
return kotlin.Result.success(it.getString(index))
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e("ExternalSignerLauncher", "Failed to query the Signer app in the background")
|
||||
return null
|
||||
return kotlin.Result.success(null)
|
||||
}
|
||||
|
||||
return null
|
||||
return kotlin.Result.success(null)
|
||||
}
|
||||
|
||||
fun decrypt(
|
||||
@ -325,7 +334,10 @@ class ExternalSignerLauncher(
|
||||
) {
|
||||
val id = (encryptedContent + pubKey + onReady.toString()).hashCode().toString()
|
||||
val result = getDataFromResolver(signerType, arrayOf(encryptedContent, pubKey))
|
||||
if (result == null) {
|
||||
result.fold(
|
||||
onFailure = { },
|
||||
onSuccess = {
|
||||
if (it == null) {
|
||||
openSignerApp(
|
||||
encryptedContent,
|
||||
signerType,
|
||||
@ -334,8 +346,10 @@ class ExternalSignerLauncher(
|
||||
onReady,
|
||||
)
|
||||
} else {
|
||||
onReady(result)
|
||||
onReady(it)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fun encrypt(
|
||||
@ -346,7 +360,10 @@ class ExternalSignerLauncher(
|
||||
) {
|
||||
val id = (decryptedContent + pubKey + onReady.toString()).hashCode().toString()
|
||||
val result = getDataFromResolver(signerType, arrayOf(decryptedContent, pubKey))
|
||||
if (result == null) {
|
||||
result.fold(
|
||||
onFailure = { },
|
||||
onSuccess = {
|
||||
if (it == null) {
|
||||
openSignerApp(
|
||||
decryptedContent,
|
||||
signerType,
|
||||
@ -355,8 +372,10 @@ class ExternalSignerLauncher(
|
||||
onReady,
|
||||
)
|
||||
} else {
|
||||
onReady(result)
|
||||
onReady(it)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fun decryptZapEvent(
|
||||
@ -365,7 +384,10 @@ class ExternalSignerLauncher(
|
||||
) {
|
||||
val result =
|
||||
getDataFromResolver(SignerType.DECRYPT_ZAP_EVENT, arrayOf(event.toJson(), event.pubKey))
|
||||
if (result == null) {
|
||||
result.fold(
|
||||
onFailure = { },
|
||||
onSuccess = {
|
||||
if (it == null) {
|
||||
openSignerApp(
|
||||
event.toJson(),
|
||||
SignerType.DECRYPT_ZAP_EVENT,
|
||||
@ -374,7 +396,9 @@ class ExternalSignerLauncher(
|
||||
onReady,
|
||||
)
|
||||
} else {
|
||||
onReady(result)
|
||||
}
|
||||
onReady(it)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user