kopia lustrzana https://github.com/vitorpamplona/amethyst
Speeds up id calculations for Amber's Intent call.
Only assembles an id if necessary.pull/835/head
rodzic
2342da114d
commit
32b9b6c37a
|
@ -246,13 +246,11 @@ class ExternalSignerLauncher(
|
||||||
columnName: String = "signature",
|
columnName: String = "signature",
|
||||||
onReady: (String) -> Unit,
|
onReady: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
val result =
|
getDataFromResolver(
|
||||||
getDataFromResolver(
|
SignerType.SIGN_EVENT,
|
||||||
SignerType.SIGN_EVENT,
|
arrayOf(event.toJson(), event.pubKey()),
|
||||||
arrayOf(event.toJson(), event.pubKey()),
|
columnName,
|
||||||
columnName,
|
).fold(
|
||||||
)
|
|
||||||
result.fold(
|
|
||||||
onFailure = { },
|
onFailure = { },
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
if (it == null) {
|
if (it == null) {
|
||||||
|
@ -286,7 +284,7 @@ class ExternalSignerLauncher(
|
||||||
): kotlin.Result<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()
|
arrayOf(*data, npub)
|
||||||
} else {
|
} else {
|
||||||
data
|
data
|
||||||
}
|
}
|
||||||
|
@ -326,15 +324,24 @@ class ExternalSignerLauncher(
|
||||||
return kotlin.Result.success(null)
|
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(
|
fun decrypt(
|
||||||
encryptedContent: String,
|
encryptedContent: String,
|
||||||
pubKey: HexKey,
|
pubKey: HexKey,
|
||||||
signerType: SignerType = SignerType.NIP04_DECRYPT,
|
signerType: SignerType = SignerType.NIP04_DECRYPT,
|
||||||
onReady: (String) -> Unit,
|
onReady: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
val id = (encryptedContent + pubKey + onReady.toString()).hashCode().toString()
|
getDataFromResolver(signerType, arrayOf(encryptedContent, pubKey)).fold(
|
||||||
val result = getDataFromResolver(signerType, arrayOf(encryptedContent, pubKey))
|
|
||||||
result.fold(
|
|
||||||
onFailure = { },
|
onFailure = { },
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
if (it == null) {
|
if (it == null) {
|
||||||
|
@ -342,7 +349,7 @@ class ExternalSignerLauncher(
|
||||||
encryptedContent,
|
encryptedContent,
|
||||||
signerType,
|
signerType,
|
||||||
pubKey,
|
pubKey,
|
||||||
id,
|
hashCodeFields(encryptedContent, pubKey, onReady).toString(),
|
||||||
onReady,
|
onReady,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
@ -358,9 +365,7 @@ class ExternalSignerLauncher(
|
||||||
signerType: SignerType = SignerType.NIP04_ENCRYPT,
|
signerType: SignerType = SignerType.NIP04_ENCRYPT,
|
||||||
onReady: (String) -> Unit,
|
onReady: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
val id = (decryptedContent + pubKey + onReady.toString()).hashCode().toString()
|
getDataFromResolver(signerType, arrayOf(decryptedContent, pubKey)).fold(
|
||||||
val result = getDataFromResolver(signerType, arrayOf(decryptedContent, pubKey))
|
|
||||||
result.fold(
|
|
||||||
onFailure = { },
|
onFailure = { },
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
if (it == null) {
|
if (it == null) {
|
||||||
|
@ -368,7 +373,7 @@ class ExternalSignerLauncher(
|
||||||
decryptedContent,
|
decryptedContent,
|
||||||
signerType,
|
signerType,
|
||||||
pubKey,
|
pubKey,
|
||||||
id,
|
hashCodeFields(decryptedContent, pubKey, onReady).toString(),
|
||||||
onReady,
|
onReady,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
@ -382,9 +387,7 @@ class ExternalSignerLauncher(
|
||||||
event: LnZapRequestEvent,
|
event: LnZapRequestEvent,
|
||||||
onReady: (String) -> Unit,
|
onReady: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
val result =
|
getDataFromResolver(SignerType.DECRYPT_ZAP_EVENT, arrayOf(event.toJson(), event.pubKey)).fold(
|
||||||
getDataFromResolver(SignerType.DECRYPT_ZAP_EVENT, arrayOf(event.toJson(), event.pubKey))
|
|
||||||
result.fold(
|
|
||||||
onFailure = { },
|
onFailure = { },
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
if (it == null) {
|
if (it == null) {
|
||||||
|
|
Ładowanie…
Reference in New Issue