fix double encryption on nip04

This commit is contained in:
greenart7c3
2023-10-11 15:14:10 -03:00
parent dd2e590475
commit 173245d900
@@ -156,40 +156,39 @@ object ExternalSignerUtils {
checkNotInMainThread() checkNotInMainThread()
val result = getDataFromResolver(SignerType.SIGN_EVENT, arrayOf(event.toJson(), event.pubKey()), columnName) val result = getDataFromResolver(SignerType.SIGN_EVENT, arrayOf(event.toJson(), event.pubKey()), columnName)
if (result !== null) { if (result == null) {
ServiceManager.shouldPauseService = false
isActivityRunning = true
openSigner(
event.toJson(),
SignerType.SIGN_EVENT,
activityResultLauncher,
"",
event.id()
)
while (isActivityRunning) {
Thread.sleep(100)
}
} else {
content.put(event.id(), result) content.put(event.id(), result)
return
}
ServiceManager.shouldPauseService = false
isActivityRunning = true
openSigner(
event.toJson(),
SignerType.SIGN_EVENT,
activityResultLauncher,
"",
event.id()
)
while (isActivityRunning) {
Thread.sleep(100)
} }
} }
fun decryptBlockList(encryptedContent: String, pubKey: HexKey, id: String, signerType: SignerType = SignerType.NIP04_DECRYPT) { fun decryptBlockList(encryptedContent: String, pubKey: HexKey, id: String, signerType: SignerType = SignerType.NIP04_DECRYPT) {
val result = getDataFromResolver(signerType, arrayOf(encryptedContent, pubKey)) val result = getDataFromResolver(signerType, arrayOf(encryptedContent, pubKey))
if (result !== null) { if (result == null) {
isActivityRunning = true
openSigner(
encryptedContent,
signerType,
blockListResultLauncher,
pubKey,
id
)
} else {
content.put(id, result) content.put(id, result)
cachedDecryptedContent[id] = result cachedDecryptedContent[id] = result
return
} }
isActivityRunning = true
openSigner(
encryptedContent,
signerType,
blockListResultLauncher,
pubKey,
id
)
} }
fun getDataFromResolver(signerType: SignerType, data: Array<out String>, columnName: String = "signature"): String? { fun getDataFromResolver(signerType: SignerType, data: Array<out String>, columnName: String = "signature"): String? {
@@ -206,15 +205,16 @@ object ExternalSignerUtils {
null, null,
null null
).use { ).use {
if (it !== null) { if (it == null) {
if (it.moveToFirst()) { return null
val index = it.getColumnIndex(columnName) }
if (index < 0) { if (it.moveToFirst()) {
Log.d("getDataFromResolver", "column '$columnName' not found") val index = it.getColumnIndex(columnName)
return null if (index < 0) {
} Log.d("getDataFromResolver", "column '$columnName' not found")
return it.getString(index) return null
} }
return it.getString(index)
} }
} }
return null return null
@@ -222,92 +222,90 @@ object ExternalSignerUtils {
fun decrypt(encryptedContent: String, pubKey: HexKey, id: String, signerType: SignerType = SignerType.NIP04_DECRYPT) { fun decrypt(encryptedContent: String, pubKey: HexKey, id: String, signerType: SignerType = SignerType.NIP04_DECRYPT) {
val result = getDataFromResolver(signerType, arrayOf(encryptedContent, pubKey)) val result = getDataFromResolver(signerType, arrayOf(encryptedContent, pubKey))
if (result !== null) { if (result == null) {
isActivityRunning = true
openSigner(
encryptedContent,
signerType,
decryptResultLauncher,
pubKey,
id
)
while (isActivityRunning) {
// do nothing
}
} else {
content.put(id, result) content.put(id, result)
cachedDecryptedContent[id] = result cachedDecryptedContent[id] = result
return
}
isActivityRunning = true
openSigner(
encryptedContent,
signerType,
decryptResultLauncher,
pubKey,
id
)
while (isActivityRunning) {
// do nothing
} }
} }
fun decryptDM(encryptedContent: String, pubKey: HexKey, id: String, signerType: SignerType = SignerType.NIP04_DECRYPT) { fun decryptDM(encryptedContent: String, pubKey: HexKey, id: String, signerType: SignerType = SignerType.NIP04_DECRYPT) {
val result = getDataFromResolver(signerType, arrayOf(encryptedContent, pubKey)) val result = getDataFromResolver(signerType, arrayOf(encryptedContent, pubKey))
if (result !== null) { if (result == null) {
openSigner(
encryptedContent,
signerType,
decryptResultLauncher,
pubKey,
id
)
} else {
content.put(id, result) content.put(id, result)
cachedDecryptedContent[id] = result cachedDecryptedContent[id] = result
return
} }
openSigner(
encryptedContent,
signerType,
decryptResultLauncher,
pubKey,
id
)
} }
fun decryptBookmark(encryptedContent: String, pubKey: HexKey, id: String, signerType: SignerType = SignerType.NIP04_DECRYPT) { fun decryptBookmark(encryptedContent: String, pubKey: HexKey, id: String, signerType: SignerType = SignerType.NIP04_DECRYPT) {
val result = getDataFromResolver(signerType, arrayOf(encryptedContent, pubKey)) val result = getDataFromResolver(signerType, arrayOf(encryptedContent, pubKey))
if (result !== null) { if (result == null) {
openSigner(
encryptedContent,
signerType,
decryptResultLauncher,
pubKey,
id
)
} else {
content.put(id, result) content.put(id, result)
cachedDecryptedContent[id] = result cachedDecryptedContent[id] = result
return
} }
openSigner(
encryptedContent,
signerType,
decryptResultLauncher,
pubKey,
id
)
} }
fun encrypt(decryptedContent: String, pubKey: HexKey, id: String, signerType: SignerType = SignerType.NIP04_ENCRYPT) { fun encrypt(decryptedContent: String, pubKey: HexKey, id: String, signerType: SignerType = SignerType.NIP04_ENCRYPT) {
content.remove(id) content.remove(id)
cachedDecryptedContent.remove(id) cachedDecryptedContent.remove(id)
val result = getDataFromResolver(signerType, arrayOf(decryptedContent, pubKey)) val result = getDataFromResolver(signerType, arrayOf(decryptedContent, pubKey))
if (result !== null) { if (result == null) {
isActivityRunning = true
openSigner(
decryptedContent,
signerType,
activityResultLauncher,
pubKey,
id
)
while (isActivityRunning) {
Thread.sleep(100)
}
} else {
content.put(id, result) content.put(id, result)
return
}
isActivityRunning = true
openSigner(
decryptedContent,
signerType,
activityResultLauncher,
pubKey,
id
)
while (isActivityRunning) {
Thread.sleep(100)
} }
} }
fun decryptZapEvent(event: LnZapRequestEvent) { fun decryptZapEvent(event: LnZapRequestEvent) {
val result = getDataFromResolver(SignerType.DECRYPT_ZAP_EVENT, arrayOf(event.toJson(), event.pubKey)) val result = getDataFromResolver(SignerType.DECRYPT_ZAP_EVENT, arrayOf(event.toJson(), event.pubKey))
if (result !== null) { if (result == null) {
openSigner(
event.toJson(),
SignerType.DECRYPT_ZAP_EVENT,
decryptResultLauncher,
event.pubKey,
event.id
)
} else {
content.put(event.id, result) content.put(event.id, result)
cachedDecryptedContent[event.id] = result cachedDecryptedContent[event.id] = result
return
} }
openSigner(
event.toJson(),
SignerType.DECRYPT_ZAP_EVENT,
decryptResultLauncher,
event.pubKey,
event.id
)
} }
} }