|
1 | 1 | package jota.utils; |
2 | 2 |
|
3 | 3 | import jota.dto.response.GetBundleResponse; |
| 4 | +import jota.model.Bundle; |
| 5 | +import jota.model.Input; |
4 | 6 | import org.apache.commons.lang3.NotImplementedException; |
5 | 7 | import org.slf4j.Logger; |
6 | 8 | import org.slf4j.LoggerFactory; |
7 | 9 |
|
| 10 | +import java.util.List; |
| 11 | + |
8 | 12 | /** |
9 | 13 | * Client Side computation service |
10 | 14 | * |
@@ -39,5 +43,72 @@ public static String newAddress(String seed, int index, boolean checksum) { |
39 | 43 | public static GetBundleResponse getBundle(final String transaction) { |
40 | 44 | throw new NotImplementedException("Not yet implemented"); |
41 | 45 | } |
| 46 | + |
| 47 | + /* |
| 48 | + public static List<String> signInputsAndReturn(String seed, List<Input> inputs, Bundle bundle, |
| 49 | + List<String> signatureFragments) { |
| 50 | + bundle.finalize(); |
| 51 | + bundle.addTrytes(signatureFragments); |
| 52 | +
|
| 53 | + // SIGNING OF INPUTS |
| 54 | + // |
| 55 | + // Here we do the actual signing of the inputs |
| 56 | + // Iterate over all bundle transactions, find the inputs |
| 57 | + // Get the corresponding private key and calculate the signatureFragment |
| 58 | + for (int i = 0; i < bundle.getTransactions().size(); i++) { |
| 59 | + if (Long.parseLong(bundle.getTransactions().get(i).getValue()) < 0) { |
| 60 | + String thisAddress = bundle.getTransactions().get(i).getAddress(); |
| 61 | +
|
| 62 | + // Get the corresponding keyIndex of the address |
| 63 | + int keyIndex = 0; |
| 64 | + for (int k = 0; k < inputs.size(); k++) { |
| 65 | + if (inputs.get(k).getAddress().equals(thisAddress)) { |
| 66 | + keyIndex = inputs.get(k).getKeyIndex(); |
| 67 | + break; |
| 68 | + } |
| 69 | + } |
| 70 | +
|
| 71 | + String bundleHash = bundle.getTransactions().get(i).getBundle(); |
| 72 | +
|
| 73 | + // Get corresponding private key of address |
| 74 | + int[] key = Signing.key(Converter.trits(seed), keyIndex, 2); |
| 75 | +
|
| 76 | + // First 6561 trits for the firstFragment |
| 77 | + var firstFragment = key.Take(6561); |
| 78 | +
|
| 79 | + // Get the normalized bundle hash |
| 80 | + String normalizedBundleHash = bundle.normalizedBundle(bundleHash); |
| 81 | + /* |
| 82 | + // First bundle fragment uses 27 trytes |
| 83 | + var firstBundleFragment = normalizedBundleHash(27); |
| 84 | +
|
| 85 | + // Calculate the new signatureFragment with the first bundle fragment |
| 86 | + var firstSignedFragment = Signing.signatureFragment(firstBundleFragment, firstFragment); |
| 87 | +
|
| 88 | + // Convert signature to trytes and assign the new signatureFragment |
| 89 | + bundle.Transactions[i].signatureMessageFragment = Converter.trytes(firstSignedFragment); |
| 90 | +
|
| 91 | + // Because the signature is > 2187 trytes, we need to |
| 92 | + // find the second transaction to add the remainder of the signature |
| 93 | + for (var j = 0; j < bundle.Transactions.Count; j++) |
| 94 | + { |
| 95 | + // Same address as well as value = 0 (as we already spent the input) |
| 96 | + if (bundle.Transactions[j].Address == thisAddress && bundle.Transactions[j].Value == 0) |
| 97 | + { |
| 98 | + // Use the second 6562 trits |
| 99 | + var secondFragment = key.Skip(6561).Take(6561); |
| 100 | +
|
| 101 | + // The second 27 to 54 trytes of the bundle hash |
| 102 | + var secondBundleFragment = normalizedBundleHash.slice(27, 27*2); |
| 103 | +
|
| 104 | + // Calculate the new signature |
| 105 | + var secondSignedFragment = Signing.signatureFragment(secondBundleFragment, secondFragment); |
| 106 | +
|
| 107 | + // Convert signature to trytes and assign it again to this bundle entry |
| 108 | + bundle.Transactions[j].signatureMessageFragment = Converter.trytes(secondSignedFragment); |
| 109 | + } |
| 110 | + }*/ |
| 111 | + // } |
| 112 | + // } |
42 | 113 | } |
43 | 114 |
|
0 commit comments