Speeds up id calculations for Amber's Intent call.

Only assembles an id if necessary.
pull/835/head
Vitor Pamplona 2024-04-12 11:01:32 -04:00
rodzic 2342da114d
commit 32b9b6c37a
1 zmienionych plików z 22 dodań i 19 usunięć

Wyświetl plik

@ -246,13 +246,11 @@ class ExternalSignerLauncher(
columnName: String = "signature",
onReady: (String) -> Unit,
) {
val result =
getDataFromResolver(
SignerType.SIGN_EVENT,
arrayOf(event.toJson(), event.pubKey()),
columnName,
)
result.fold(
getDataFromResolver(
SignerType.SIGN_EVENT,
arrayOf(event.toJson(), event.pubKey()),
columnName,
).fold(
onFailure = { },
onSuccess = {
if (it == null) {
@ -286,7 +284,7 @@ class ExternalSignerLauncher(
): kotlin.Result<String?> {
val localData =
if (signerType !== SignerType.GET_PUBLIC_KEY) {
data.toList().plus(npub).toTypedArray()
arrayOf(*data, npub)
} else {
data
}
@ -326,15 +324,24 @@ class ExternalSignerLauncher(
return kotlin.Result.success(null)
}
fun hashCodeFields(
str1: String,
str2: String,
onReady: (String) -> Unit,
): Int {
var result = str1.hashCode()
result = 31 * result + str2.hashCode()
result = 31 * result + onReady.hashCode()
return result
}
fun decrypt(
encryptedContent: String,
pubKey: HexKey,
signerType: SignerType = SignerType.NIP04_DECRYPT,
onReady: (String) -> Unit,
) {
val id = (encryptedContent + pubKey + onReady.toString()).hashCode().toString()
val result = getDataFromResolver(signerType, arrayOf(encryptedContent, pubKey))
result.fold(
getDataFromResolver(signerType, arrayOf(encryptedContent, pubKey)).fold(
onFailure = { },
onSuccess = {
if (it == null) {
@ -342,7 +349,7 @@ class ExternalSignerLauncher(
encryptedContent,
signerType,
pubKey,
id,
hashCodeFields(encryptedContent, pubKey, onReady).toString(),
onReady,
)
} else {
@ -358,9 +365,7 @@ class ExternalSignerLauncher(
signerType: SignerType = SignerType.NIP04_ENCRYPT,
onReady: (String) -> Unit,
) {
val id = (decryptedContent + pubKey + onReady.toString()).hashCode().toString()
val result = getDataFromResolver(signerType, arrayOf(decryptedContent, pubKey))
result.fold(
getDataFromResolver(signerType, arrayOf(decryptedContent, pubKey)).fold(
onFailure = { },
onSuccess = {
if (it == null) {
@ -368,7 +373,7 @@ class ExternalSignerLauncher(
decryptedContent,
signerType,
pubKey,
id,
hashCodeFields(decryptedContent, pubKey, onReady).toString(),
onReady,
)
} else {
@ -382,9 +387,7 @@ class ExternalSignerLauncher(
event: LnZapRequestEvent,
onReady: (String) -> Unit,
) {
val result =
getDataFromResolver(SignerType.DECRYPT_ZAP_EVENT, arrayOf(event.toJson(), event.pubKey))
result.fold(
getDataFromResolver(SignerType.DECRYPT_ZAP_EVENT, arrayOf(event.toJson(), event.pubKey)).fold(
onFailure = { },
onSuccess = {
if (it == null) {