kopia lustrzana https://github.com/vitorpamplona/amethyst
add support for always rejected permissions from external signer
rodzic
ac8f0e8600
commit
13d9c1ab10
|
@ -252,33 +252,38 @@ class ExternalSignerLauncher(
|
||||||
arrayOf(event.toJson(), event.pubKey()),
|
arrayOf(event.toJson(), event.pubKey()),
|
||||||
columnName,
|
columnName,
|
||||||
)
|
)
|
||||||
if (result == null) {
|
result.fold(
|
||||||
openSignerApp(
|
onFailure = { },
|
||||||
event.toJson(),
|
onSuccess = {
|
||||||
SignerType.SIGN_EVENT,
|
if (it == null) {
|
||||||
"",
|
openSignerApp(
|
||||||
event.id(),
|
event.toJson(),
|
||||||
onReady,
|
SignerType.SIGN_EVENT,
|
||||||
)
|
"",
|
||||||
} else {
|
event.id(),
|
||||||
onReady(result)
|
onReady,
|
||||||
}
|
)
|
||||||
|
} else {
|
||||||
|
onReady(it)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getDataFromResolver(
|
private fun getDataFromResolver(
|
||||||
signerType: SignerType,
|
signerType: SignerType,
|
||||||
data: Array<out String>,
|
data: Array<out String>,
|
||||||
columnName: String = "signature",
|
columnName: String = "signature",
|
||||||
): String? {
|
): kotlin.Result<String?> {
|
||||||
return getDataFromResolver(signerType, data, columnName, contentResolver)
|
return getDataFromResolver(signerType, data, columnName, contentResolver)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getDataFromResolver(
|
private fun getDataFromResolver(
|
||||||
signerType: SignerType,
|
signerType: SignerType,
|
||||||
data: Array<out String>,
|
data: Array<out String>,
|
||||||
columnName: String = "signature",
|
columnName: String = "signature",
|
||||||
contentResolver: (() -> ContentResolver)? = null,
|
contentResolver: (() -> ContentResolver)? = null,
|
||||||
): String? {
|
): kotlin.Result<String?> {
|
||||||
val localData =
|
val localData =
|
||||||
if (signerType !== SignerType.GET_PUBLIC_KEY) {
|
if (signerType !== SignerType.GET_PUBLIC_KEY) {
|
||||||
data.toList().plus(npub).toTypedArray()
|
data.toList().plus(npub).toTypedArray()
|
||||||
|
@ -292,29 +297,33 @@ class ExternalSignerLauncher(
|
||||||
?.query(
|
?.query(
|
||||||
Uri.parse("content://$signerPackageName.$signerType"),
|
Uri.parse("content://$signerPackageName.$signerType"),
|
||||||
localData,
|
localData,
|
||||||
null,
|
"1",
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
)
|
)
|
||||||
.use {
|
.use {
|
||||||
if (it == null) {
|
if (it == null) {
|
||||||
return null
|
return kotlin.Result.success(null)
|
||||||
}
|
}
|
||||||
if (it.moveToFirst()) {
|
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)
|
val index = it.getColumnIndex(columnName)
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
Log.d("getDataFromResolver", "column '$columnName' not found")
|
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) {
|
} catch (e: Exception) {
|
||||||
Log.e("ExternalSignerLauncher", "Failed to query the Signer app in the background")
|
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(
|
fun decrypt(
|
||||||
|
@ -325,17 +334,22 @@ class ExternalSignerLauncher(
|
||||||
) {
|
) {
|
||||||
val id = (encryptedContent + pubKey + onReady.toString()).hashCode().toString()
|
val id = (encryptedContent + pubKey + onReady.toString()).hashCode().toString()
|
||||||
val result = getDataFromResolver(signerType, arrayOf(encryptedContent, pubKey))
|
val result = getDataFromResolver(signerType, arrayOf(encryptedContent, pubKey))
|
||||||
if (result == null) {
|
result.fold(
|
||||||
openSignerApp(
|
onFailure = { },
|
||||||
encryptedContent,
|
onSuccess = {
|
||||||
signerType,
|
if (it == null) {
|
||||||
pubKey,
|
openSignerApp(
|
||||||
id,
|
encryptedContent,
|
||||||
onReady,
|
signerType,
|
||||||
)
|
pubKey,
|
||||||
} else {
|
id,
|
||||||
onReady(result)
|
onReady,
|
||||||
}
|
)
|
||||||
|
} else {
|
||||||
|
onReady(it)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun encrypt(
|
fun encrypt(
|
||||||
|
@ -346,17 +360,22 @@ class ExternalSignerLauncher(
|
||||||
) {
|
) {
|
||||||
val id = (decryptedContent + pubKey + onReady.toString()).hashCode().toString()
|
val id = (decryptedContent + pubKey + onReady.toString()).hashCode().toString()
|
||||||
val result = getDataFromResolver(signerType, arrayOf(decryptedContent, pubKey))
|
val result = getDataFromResolver(signerType, arrayOf(decryptedContent, pubKey))
|
||||||
if (result == null) {
|
result.fold(
|
||||||
openSignerApp(
|
onFailure = { },
|
||||||
decryptedContent,
|
onSuccess = {
|
||||||
signerType,
|
if (it == null) {
|
||||||
pubKey,
|
openSignerApp(
|
||||||
id,
|
decryptedContent,
|
||||||
onReady,
|
signerType,
|
||||||
)
|
pubKey,
|
||||||
} else {
|
id,
|
||||||
onReady(result)
|
onReady,
|
||||||
}
|
)
|
||||||
|
} else {
|
||||||
|
onReady(it)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun decryptZapEvent(
|
fun decryptZapEvent(
|
||||||
|
@ -365,16 +384,21 @@ class ExternalSignerLauncher(
|
||||||
) {
|
) {
|
||||||
val result =
|
val result =
|
||||||
getDataFromResolver(SignerType.DECRYPT_ZAP_EVENT, arrayOf(event.toJson(), event.pubKey))
|
getDataFromResolver(SignerType.DECRYPT_ZAP_EVENT, arrayOf(event.toJson(), event.pubKey))
|
||||||
if (result == null) {
|
result.fold(
|
||||||
openSignerApp(
|
onFailure = { },
|
||||||
event.toJson(),
|
onSuccess = {
|
||||||
SignerType.DECRYPT_ZAP_EVENT,
|
if (it == null) {
|
||||||
event.pubKey,
|
openSignerApp(
|
||||||
event.id,
|
event.toJson(),
|
||||||
onReady,
|
SignerType.DECRYPT_ZAP_EVENT,
|
||||||
)
|
event.pubKey,
|
||||||
} else {
|
event.id,
|
||||||
onReady(result)
|
onReady,
|
||||||
}
|
)
|
||||||
|
} else {
|
||||||
|
onReady(it)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue