mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-03-26 17:52:29 +01:00
Speeds up id calculations for Amber's Intent call.
Only assembles an id if necessary.
This commit is contained in:
parent
2342da114d
commit
32b9b6c37a
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user