mirror of
https://github.com/gosticks/iota.lib.java.git
synced 2025-10-16 11:45:37 +00:00
fixed getnewaddress
This commit is contained in:
parent
a77cadb290
commit
80ef2dcf7e
@ -15,8 +15,7 @@ public class Checksum {
|
||||
public static String removeChecksum(String addressWithChecksum) {
|
||||
if (isAddressWithChecksum(addressWithChecksum)) {
|
||||
return getAddress(addressWithChecksum);
|
||||
}
|
||||
throw new RuntimeException("Invalid address: " + addressWithChecksum);
|
||||
} else return "";
|
||||
}
|
||||
|
||||
private static String getAddress(String addressWithChecksum) {
|
||||
|
||||
@ -18,8 +18,13 @@ public class IotaAPIUtils {
|
||||
public static GetNewAddressResponse getNewAddress(final String seed, final int index) {
|
||||
|
||||
final int[] key = Signing.key(Converter.trits(seed), index, 2);
|
||||
System.out.println("Length = "+ key.length );
|
||||
final int[] digests = Signing.digests(key);
|
||||
System.out.println("Length = "+ digests.length );
|
||||
|
||||
final int[] addressTrits = Signing.address(digests);
|
||||
System.out.println("Length = "+ addressTrits.length );
|
||||
|
||||
final String address = Converter.trytes(addressTrits);
|
||||
|
||||
return GetNewAddressResponse.create(address);
|
||||
|
||||
@ -21,8 +21,10 @@ public class Signing {
|
||||
}
|
||||
|
||||
Curl curl = new Curl();
|
||||
//curl.absorb(subseed, state);
|
||||
//curl.squeeze(subseed, state);
|
||||
curl.reset();
|
||||
curl.absorb(subseed, 0, subseed.length);
|
||||
curl.squeeze(subseed, 0, subseed.length);
|
||||
curl.reset();
|
||||
curl.absorb(subseed, 0, subseed.length);
|
||||
|
||||
List<Integer> key = new ArrayList<>();
|
||||
@ -33,7 +35,7 @@ public class Signing {
|
||||
|
||||
for (int i = 0; i < 27; i++) {
|
||||
|
||||
curl.squeeze(buffer, 0, buffer.length);
|
||||
curl.squeeze(buffer, offset, buffer.length);
|
||||
for (int j = 0; j < 243; j++) {
|
||||
key.add(buffer[j]);
|
||||
}
|
||||
@ -54,8 +56,8 @@ public class Signing {
|
||||
public static int[] digests(int[] key) {
|
||||
final Curl curl = new Curl();
|
||||
|
||||
int[] digests = new int[key.length];
|
||||
int[] buffer = new int[key.length];
|
||||
int[] digests = new int[(int) Math.floor(key.length / 6561) * 243];
|
||||
int[] buffer = new int[243];
|
||||
|
||||
for (int i = 0; i < Math.floor(key.length / 6561); i++) {
|
||||
int[] keyFragment = Arrays.copyOfRange(key, i * 6561, (i + 1) * 6561);
|
||||
@ -64,7 +66,7 @@ public class Signing {
|
||||
|
||||
buffer = Arrays.copyOfRange(keyFragment, j * 243, (j + 1) * 243);
|
||||
for (int k = 0; k < 26; k++) {
|
||||
|
||||
curl.reset();
|
||||
curl.absorb(buffer, 0, buffer.length);
|
||||
curl.squeeze(buffer, 0, buffer.length);
|
||||
}
|
||||
@ -74,6 +76,7 @@ public class Signing {
|
||||
}
|
||||
}
|
||||
|
||||
curl.reset();
|
||||
curl.absorb(keyFragment, 0, keyFragment.length);
|
||||
curl.squeeze(buffer, 0, buffer.length);
|
||||
|
||||
@ -86,7 +89,8 @@ public class Signing {
|
||||
|
||||
public static int[] address(int[] digests) {
|
||||
final Curl curl = new Curl();
|
||||
int[] address = new int[digests.length];
|
||||
int[] address = new int[243];
|
||||
curl.reset();
|
||||
curl.absorb(digests, 0, digests.length);
|
||||
curl.squeeze(address, 0, address.length);
|
||||
return address;
|
||||
|
||||
20
src/test/java/jota/AddressGenerationTest.java
Normal file
20
src/test/java/jota/AddressGenerationTest.java
Normal file
@ -0,0 +1,20 @@
|
||||
package jota;
|
||||
|
||||
import jota.utils.IotaAPIUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by Adrian on 02.12.2016.
|
||||
*/
|
||||
public class AddressGenerationTest {
|
||||
private static String TEST_SEED = "ZEB99QTOMYDSKIFCXTLTVSWQFKO9CRKQKMRDR9HWVOVSGZMWPFQIMSCXXWUULHD9MZKMFJZAYZHZYA9VZ";
|
||||
private static String FIRST_ADDRESS = "LCZXWAQUHBXST9IEPPMJICTWLKJA9HVASXWDIRCVNM9TUAGZY9SRRJLZMZQIZKBAESXXNABFATUAYQYYW";
|
||||
|
||||
@Test
|
||||
public void shouldAddChecksum() {
|
||||
assertEquals(IotaAPIUtils.getNewAddress(TEST_SEED,0),FIRST_ADDRESS);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
package jota;
|
||||
|
||||
import jota.utils.Checksum;
|
||||
import jota.utils.InputValidator;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@ -10,8 +11,9 @@ import static org.junit.Assert.assertEquals;
|
||||
*/
|
||||
public class ChecksumTest {
|
||||
|
||||
private static final String TEST_ADDRESS_WITHOUT_CHECKSUM = "PNGMCSNRCTRHCHPXYTPKEJYPCOWKOMRXZFHH9N9VDIKMNVAZCMIYRHVJIAZARZTUETJVFDMBEBIQE9QTH";
|
||||
private static final String TEST_ADDRESS_WITH_CHECKSUM = "PNGMCSNRCTRHCHPXYTPKEJYPCOWKOMRXZFHH9N9VDIKMNVAZCMIYRHVJIAZARZTUETJVFDMBEBIQE9QTHBFWDAOEFA";
|
||||
private static final String TEST_ADDRESS_WITHOUT_CHECKSUM = "RVORZ9SIIP9RCYMREUIXXVPQIPHVCNPQ9HZWYKFWYWZRE9JQKG9REPKIASHUUECPSQO9JT9XNMVKWYGVA";
|
||||
private static final String TEST_ADDRESS_WITH_CHECKSUM = "RVORZ9SIIP9RCYMREUIXXVPQIPHVCNPQ9HZWYKFWYWZRE9JQKG9REPKIASHUUECPSQO9JT9XNMVKWYGVAFOXM9MUBX";
|
||||
|
||||
@Test
|
||||
public void shouldAddChecksum() {
|
||||
assertEquals(Checksum.addChecksum(TEST_ADDRESS_WITHOUT_CHECKSUM), TEST_ADDRESS_WITH_CHECKSUM);
|
||||
@ -21,9 +23,4 @@ public class ChecksumTest {
|
||||
public void shouldRemoveChecksum() {
|
||||
assertEquals(Checksum.removeChecksum(TEST_ADDRESS_WITH_CHECKSUM), TEST_ADDRESS_WITHOUT_CHECKSUM);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldIsValidChecksum() {
|
||||
assertEquals(Checksum.isValidChecksum(TEST_ADDRESS_WITH_CHECKSUM), true);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user