From e83f71f10e25d28050ad057f2a5e0c345dd97591 Mon Sep 17 00:00:00 2001 From: "Andreas C. Osowski" Date: Tue, 24 Oct 2017 07:56:04 +0200 Subject: [PATCH] Fixes #44: non-default security level signing --- src/main/java/jota/utils/IotaAPIUtils.java | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/java/jota/utils/IotaAPIUtils.java b/src/main/java/jota/utils/IotaAPIUtils.java index ae2ea2a..6ab7830 100644 --- a/src/main/java/jota/utils/IotaAPIUtils.java +++ b/src/main/java/jota/utils/IotaAPIUtils.java @@ -96,21 +96,19 @@ public class IotaAPIUtils { // Because the signature is > 2187 trytes, we need to // find the second transaction to add the remainder of the signature - for (int k = 0; k < bundle.getTransactions().size(); k++) { - // Same address as well as value = 0 (as we already spent the input) - if (bundle.getTransactions().get(k).getAddress().equals(thisAddress) && bundle.getTransactions().get(k).getValue() == 0) { - // Use the second 6562 trits - int[] secondFragment = Arrays.copyOfRange(key, 6561, 6561 * 2); + // Same address as well as value = 0 (as we already spent the input) + if (bundle.getTransactions().get(i + j).getAddress().equals(thisAddress) && bundle.getTransactions().get(i + j).getValue() == 0) { + // Use the second 6562 trits + int[] secondFragment = Arrays.copyOfRange(key, 6561 * j, 6561 * (j + 1)); - // The second 27 to 54 trytes of the bundle hash - int[] secondBundleFragment = Arrays.copyOfRange(normalizedBundleHash, 27, 27 * 2); + // The second 27 to 54 trytes of the bundle hash + int[] secondBundleFragment = Arrays.copyOfRange(normalizedBundleHash, 27 * j, 27 * (j + 1)); - // Calculate the new signature - int[] secondSignedFragment = new Signing(curl).signatureFragment(secondBundleFragment, secondFragment); + // Calculate the new signature + int[] secondSignedFragment = new Signing(curl).signatureFragment(secondBundleFragment, secondFragment); - // Convert signature to trytes and assign it again to this bundle entry - bundle.getTransactions().get(k).setSignatureFragments(Converter.trytes(secondSignedFragment)); - } + // Convert signature to trytes and assign it again to this bundle entry + bundle.getTransactions().get(i+j).setSignatureFragments(Converter.trytes(secondSignedFragment)); } } }