Merge pull request #641 from greenart7c3/double_encryption_fix

fix double encryption on nip04 using amber
This commit is contained in:
Vitor Pamplona
2023-10-11 15:25:20 -04:00
committed by GitHub
@@ -156,11 +156,7 @@ 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) {
content.put(event.id(), result)
return
}
ServiceManager.shouldPauseService = false ServiceManager.shouldPauseService = false
isActivityRunning = true isActivityRunning = true
openSigner( openSigner(
@@ -173,15 +169,14 @@ object ExternalSignerUtils {
while (isActivityRunning) { while (isActivityRunning) {
Thread.sleep(100) Thread.sleep(100)
} }
} else {
content.put(event.id(), result)
}
} }
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) {
content.put(id, result)
cachedDecryptedContent[id] = result
return
}
isActivityRunning = true isActivityRunning = true
openSigner( openSigner(
encryptedContent, encryptedContent,
@@ -190,6 +185,10 @@ object ExternalSignerUtils {
pubKey, pubKey,
id id
) )
} else {
content.put(id, result)
cachedDecryptedContent[id] = result
}
} }
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,7 +205,9 @@ object ExternalSignerUtils {
null, null,
null null
).use { ).use {
if (it !== null) { if (it == null) {
return null
}
if (it.moveToFirst()) { if (it.moveToFirst()) {
val index = it.getColumnIndex(columnName) val index = it.getColumnIndex(columnName)
if (index < 0) { if (index < 0) {
@@ -216,18 +217,12 @@ object ExternalSignerUtils {
return it.getString(index) return it.getString(index)
} }
} }
}
return null return null
} }
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) {
content.put(id, result)
cachedDecryptedContent[id] = result
return
}
isActivityRunning = true isActivityRunning = true
openSigner( openSigner(
encryptedContent, encryptedContent,
@@ -239,15 +234,15 @@ object ExternalSignerUtils {
while (isActivityRunning) { while (isActivityRunning) {
// do nothing // do nothing
} }
} else {
content.put(id, result)
cachedDecryptedContent[id] = result
}
} }
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) {
content.put(id, result)
cachedDecryptedContent[id] = result
return
}
openSigner( openSigner(
encryptedContent, encryptedContent,
signerType, signerType,
@@ -255,15 +250,15 @@ object ExternalSignerUtils {
pubKey, pubKey,
id id
) )
} else {
content.put(id, result)
cachedDecryptedContent[id] = result
}
} }
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) {
content.put(id, result)
cachedDecryptedContent[id] = result
return
}
openSigner( openSigner(
encryptedContent, encryptedContent,
signerType, signerType,
@@ -271,17 +266,17 @@ object ExternalSignerUtils {
pubKey, pubKey,
id id
) )
} else {
content.put(id, result)
cachedDecryptedContent[id] = result
}
} }
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) {
content.put(id, result)
return
}
isActivityRunning = true isActivityRunning = true
openSigner( openSigner(
decryptedContent, decryptedContent,
@@ -293,15 +288,14 @@ object ExternalSignerUtils {
while (isActivityRunning) { while (isActivityRunning) {
Thread.sleep(100) Thread.sleep(100)
} }
} else {
content.put(id, result)
}
} }
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) {
content.put(event.id, result)
cachedDecryptedContent[event.id] = result
return
}
openSigner( openSigner(
event.toJson(), event.toJson(),
SignerType.DECRYPT_ZAP_EVENT, SignerType.DECRYPT_ZAP_EVENT,
@@ -309,5 +303,9 @@ object ExternalSignerUtils {
event.pubKey, event.pubKey,
event.id event.id
) )
} else {
content.put(event.id, result)
cachedDecryptedContent[event.id] = result
}
} }
} }