mirror of
https://github.com/sparrowwallet/hummingbird.git
synced 2024-11-02 18:46:45 +00:00
support minimum java 8 language level
This commit is contained in:
parent
ee01cfcbf5
commit
0c28c6b431
7 changed files with 33 additions and 27 deletions
|
@ -83,23 +83,21 @@ public class LegacyURDecoder {
|
||||||
String[] components = fragment.split("/");
|
String[] components = fragment.split("/");
|
||||||
|
|
||||||
switch(components.length) {
|
switch(components.length) {
|
||||||
case 2 -> {
|
case 2:
|
||||||
return new UR(components[0].substring(UR.UR_PREFIX.length() + 1), BC32.decode(components[1]));
|
return new UR(components[0].substring(UR.UR_PREFIX.length() + 1), BC32.decode(components[1]));
|
||||||
}
|
case 3:
|
||||||
case 3 -> {
|
|
||||||
String digest = components[1];
|
String digest = components[1];
|
||||||
String data = components[2];
|
String data = components[2];
|
||||||
checkDigest(data, digest);
|
checkDigest(data, digest);
|
||||||
return new UR(components[0].substring(UR.UR_PREFIX.length() + 1), BC32.decode(data));
|
return new UR(components[0].substring(UR.UR_PREFIX.length() + 1), BC32.decode(data));
|
||||||
}
|
case 4:
|
||||||
case 4 -> {
|
|
||||||
checkAndGetSequence(components[1]);
|
checkAndGetSequence(components[1]);
|
||||||
String digest = components[2];
|
String seqDigest = components[2];
|
||||||
String data = components[3];
|
String seqData = components[3];
|
||||||
checkDigest(digest, fragment);
|
checkDigest(seqDigest, fragment);
|
||||||
return new UR(components[0].substring(UR.UR_PREFIX.length() + 1), BC32.decode(data));
|
return new UR(components[0].substring(UR.UR_PREFIX.length() + 1), BC32.decode(seqData));
|
||||||
}
|
default:
|
||||||
default -> throw new IllegalArgumentException("Invalid number of fragments: expected 2 / 3 / 4 but got " + components.length);
|
throw new IllegalArgumentException("Invalid number of fragments: expected 2 / 3 / 4 but got " + components.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -266,7 +266,9 @@ public class FountainDecoder {
|
||||||
|
|
||||||
static byte[] joinFragments(List<byte[]> fragments, int messageLen) {
|
static byte[] joinFragments(List<byte[]> fragments, int messageLen) {
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
fragments.forEach(baos::writeBytes);
|
for(byte[] fragment : fragments) {
|
||||||
|
baos.write(fragment, 0, fragment.length);
|
||||||
|
}
|
||||||
byte[] message = baos.toByteArray();
|
byte[] message = baos.toByteArray();
|
||||||
|
|
||||||
byte[] unpaddedMessage = new byte[messageLen];
|
byte[] unpaddedMessage = new byte[messageLen];
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.sparrowwallet.hummingbird.fountain;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
@ -15,7 +16,7 @@ public class FountainUtils {
|
||||||
// others. This means that if you only generate the first `seqLen` parts,
|
// others. This means that if you only generate the first `seqLen` parts,
|
||||||
// then you have all the parts you need to decode the message.
|
// then you have all the parts you need to decode the message.
|
||||||
if(seqNum <= seqLen) {
|
if(seqNum <= seqLen) {
|
||||||
return List.of((int)seqNum - 1);
|
return Collections.singletonList((int)seqNum - 1);
|
||||||
} else {
|
} else {
|
||||||
ByteBuffer buffer = ByteBuffer.allocate(Integer.BYTES * 2);
|
ByteBuffer buffer = ByteBuffer.allocate(Integer.BYTES * 2);
|
||||||
buffer.putInt((int)(seqNum));
|
buffer.putInt((int)(seqNum));
|
||||||
|
|
|
@ -24,7 +24,7 @@ public class FountainCodesTest {
|
||||||
@Test
|
@Test
|
||||||
public void testRandomSampler() {
|
public void testRandomSampler() {
|
||||||
RandomXoshiro256StarStar rng = new RandomXoshiro256StarStar("Wolf");
|
RandomXoshiro256StarStar rng = new RandomXoshiro256StarStar("Wolf");
|
||||||
RandomSampler randomSampler = new RandomSampler(List.of(1d, 2d, 4d, 8d));
|
RandomSampler randomSampler = new RandomSampler(Arrays.asList(1d, 2d, 4d, 8d));
|
||||||
int[] numbers = IntStream.range(0, 500).map(i -> randomSampler.next(rng)).toArray();
|
int[] numbers = IntStream.range(0, 500).map(i -> randomSampler.next(rng)).toArray();
|
||||||
int[] expectedNumbers = new int[] {3, 3, 3, 3, 3, 3, 3, 0, 2, 3, 3, 3, 3, 1, 2, 2, 1, 3, 3, 2, 3, 3, 1, 1, 2, 1, 1, 3, 1, 3, 1, 2, 0, 2, 1, 0, 3, 3, 3, 1, 3, 3, 3, 3, 1, 3, 2, 3, 2, 2, 3, 3, 3, 3, 2, 3, 3, 0, 3, 3, 3, 3, 1, 2, 3, 3, 2, 2, 2, 1, 2, 2, 1, 2, 3, 1, 3, 0, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, 1, 3, 3, 2, 0, 2, 2, 3, 1, 1, 2, 3, 2, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 2, 3, 1, 2, 1, 1, 3, 1, 3, 2, 2, 3, 3, 3, 1, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, 2, 3, 3, 1, 2, 3, 3, 1, 3, 2, 3, 3, 3, 2, 3, 1, 3, 0, 3, 2, 1, 1, 3, 1, 3, 2, 3, 3, 3, 3, 2, 0, 3, 3, 1, 3, 0, 2, 1, 3, 3, 1, 1, 3, 1, 2, 3, 3, 3, 0, 2, 3, 2, 0, 1, 3, 3, 3, 2, 2, 2, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 2, 3, 3, 2, 0, 2, 3, 3, 3, 3, 2, 1, 1, 1, 2, 1, 3, 3, 3, 2, 2, 3, 3, 1, 2, 3, 0, 3, 2, 3, 3, 3, 3, 0, 2, 2, 3, 2, 2, 3, 3, 3, 3, 1, 3, 2, 3, 3, 3, 3, 3, 2, 2, 3, 1, 3, 0, 2, 1, 3, 3, 3, 3, 3, 3,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, 3, 3, 3, 2, 3, 1, 2, 3, 2, 1, 1, 3, 3, 2, 3, 3, 2, 3, 3, 0, 0, 1, 3, 3, 2, 3, 3, 3, 3, 1, 3, 3, 0, 3, 2, 3, 3, 1, 3, 3, 3, 3, 3, 3, 3, 0, 3, 3, 2};
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ public class FountainCodesTest {
|
||||||
RandomXoshiro256StarStar rng = new RandomXoshiro256StarStar("Wolf");
|
RandomXoshiro256StarStar rng = new RandomXoshiro256StarStar("Wolf");
|
||||||
List<Integer> numbers = IntStream.range(1, 11).boxed().collect(Collectors.toList());
|
List<Integer> numbers = IntStream.range(1, 11).boxed().collect(Collectors.toList());
|
||||||
numbers = FountainUtils.shuffled(numbers, rng);
|
numbers = FountainUtils.shuffled(numbers, rng);
|
||||||
List<Integer> expectedNumbers = List.of(6, 4, 9, 3, 10, 5, 7, 8, 1, 2);
|
List<Integer> expectedNumbers = Arrays.asList(6, 4, 9, 3, 10, 5, 7, 8, 1, 2);
|
||||||
|
|
||||||
Assert.assertEquals(expectedNumbers, numbers);
|
Assert.assertEquals(expectedNumbers, numbers);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,8 @@ import com.sparrowwallet.hummingbird.UREncoder;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CryptoAccountTest {
|
public class CryptoAccountTest {
|
||||||
|
@ -21,7 +23,7 @@ public class CryptoAccountTest {
|
||||||
Assert.assertEquals("37b5eed4", TestUtils.bytesToHex(cryptoAccount.getMasterFingerprint()));
|
Assert.assertEquals("37b5eed4", TestUtils.bytesToHex(cryptoAccount.getMasterFingerprint()));
|
||||||
|
|
||||||
CryptoOutput cryptoOutput1 = cryptoAccount.getOutputDescriptors().get(0);
|
CryptoOutput cryptoOutput1 = cryptoAccount.getOutputDescriptors().get(0);
|
||||||
Assert.assertEquals(List.of(ScriptExpression.PUBLIC_KEY_HASH), cryptoOutput1.getScriptExpressions());
|
Assert.assertEquals(Collections.singletonList(ScriptExpression.PUBLIC_KEY_HASH), cryptoOutput1.getScriptExpressions());
|
||||||
Assert.assertEquals("03eb3e2863911826374de86c231a4b76f0b89dfa174afb78d7f478199884d9dd32", TestUtils.bytesToHex(cryptoOutput1.getHdKey().getKey()));
|
Assert.assertEquals("03eb3e2863911826374de86c231a4b76f0b89dfa174afb78d7f478199884d9dd32", TestUtils.bytesToHex(cryptoOutput1.getHdKey().getKey()));
|
||||||
Assert.assertEquals("6456a5df2db0f6d9af72b2a1af4b25f45200ed6fcc29c3440b311d4796b70b5b", TestUtils.bytesToHex(cryptoOutput1.getHdKey().getChainCode()));
|
Assert.assertEquals("6456a5df2db0f6d9af72b2a1af4b25f45200ed6fcc29c3440b311d4796b70b5b", TestUtils.bytesToHex(cryptoOutput1.getHdKey().getChainCode()));
|
||||||
Assert.assertEquals("44'/0'/0'", cryptoOutput1.getHdKey().getOrigin().getPath());
|
Assert.assertEquals("44'/0'/0'", cryptoOutput1.getHdKey().getOrigin().getPath());
|
||||||
|
@ -29,7 +31,7 @@ public class CryptoAccountTest {
|
||||||
Assert.assertNull(cryptoOutput1.getHdKey().getChildren());
|
Assert.assertNull(cryptoOutput1.getHdKey().getChildren());
|
||||||
|
|
||||||
CryptoOutput cryptoOutput2 = cryptoAccount.getOutputDescriptors().get(1);
|
CryptoOutput cryptoOutput2 = cryptoAccount.getOutputDescriptors().get(1);
|
||||||
Assert.assertEquals(List.of(ScriptExpression.SCRIPT_HASH, ScriptExpression.WITNESS_PUBLIC_KEY_HASH), cryptoOutput2.getScriptExpressions());
|
Assert.assertEquals(Arrays.asList(ScriptExpression.SCRIPT_HASH, ScriptExpression.WITNESS_PUBLIC_KEY_HASH), cryptoOutput2.getScriptExpressions());
|
||||||
Assert.assertEquals("02c7e4823730f6ee2cf864e2c352060a88e60b51a84e89e4c8c75ec22590ad6b69", TestUtils.bytesToHex(cryptoOutput2.getHdKey().getKey()));
|
Assert.assertEquals("02c7e4823730f6ee2cf864e2c352060a88e60b51a84e89e4c8c75ec22590ad6b69", TestUtils.bytesToHex(cryptoOutput2.getHdKey().getKey()));
|
||||||
Assert.assertEquals("9d2f86043276f9251a4a4f577166a5abeb16b6ec61e226b5b8fa11038bfda42d", TestUtils.bytesToHex(cryptoOutput2.getHdKey().getChainCode()));
|
Assert.assertEquals("9d2f86043276f9251a4a4f577166a5abeb16b6ec61e226b5b8fa11038bfda42d", TestUtils.bytesToHex(cryptoOutput2.getHdKey().getChainCode()));
|
||||||
Assert.assertEquals("49'/0'/0'", cryptoOutput2.getHdKey().getOrigin().getPath());
|
Assert.assertEquals("49'/0'/0'", cryptoOutput2.getHdKey().getOrigin().getPath());
|
||||||
|
@ -37,7 +39,7 @@ public class CryptoAccountTest {
|
||||||
Assert.assertNull(cryptoOutput2.getHdKey().getChildren());
|
Assert.assertNull(cryptoOutput2.getHdKey().getChildren());
|
||||||
|
|
||||||
CryptoOutput cryptoOutput3 = cryptoAccount.getOutputDescriptors().get(2);
|
CryptoOutput cryptoOutput3 = cryptoAccount.getOutputDescriptors().get(2);
|
||||||
Assert.assertEquals(List.of(ScriptExpression.WITNESS_PUBLIC_KEY_HASH), cryptoOutput3.getScriptExpressions());
|
Assert.assertEquals(Collections.singletonList(ScriptExpression.WITNESS_PUBLIC_KEY_HASH), cryptoOutput3.getScriptExpressions());
|
||||||
Assert.assertEquals("03fd433450b6924b4f7efdd5d1ed017d364be95ab2b592dc8bddb3b00c1c24f63f", TestUtils.bytesToHex(cryptoOutput3.getHdKey().getKey()));
|
Assert.assertEquals("03fd433450b6924b4f7efdd5d1ed017d364be95ab2b592dc8bddb3b00c1c24f63f", TestUtils.bytesToHex(cryptoOutput3.getHdKey().getKey()));
|
||||||
Assert.assertEquals("72ede7334d5acf91c6fda622c205199c595a31f9218ed30792d301d5ee9e3a88", TestUtils.bytesToHex(cryptoOutput3.getHdKey().getChainCode()));
|
Assert.assertEquals("72ede7334d5acf91c6fda622c205199c595a31f9218ed30792d301d5ee9e3a88", TestUtils.bytesToHex(cryptoOutput3.getHdKey().getChainCode()));
|
||||||
Assert.assertEquals("84'/0'/0'", cryptoOutput3.getHdKey().getOrigin().getPath());
|
Assert.assertEquals("84'/0'/0'", cryptoOutput3.getHdKey().getOrigin().getPath());
|
||||||
|
@ -45,7 +47,7 @@ public class CryptoAccountTest {
|
||||||
Assert.assertNull(cryptoOutput3.getHdKey().getChildren());
|
Assert.assertNull(cryptoOutput3.getHdKey().getChildren());
|
||||||
|
|
||||||
CryptoOutput cryptoOutput4 = cryptoAccount.getOutputDescriptors().get(3);
|
CryptoOutput cryptoOutput4 = cryptoAccount.getOutputDescriptors().get(3);
|
||||||
Assert.assertEquals(List.of(ScriptExpression.SCRIPT_HASH), cryptoOutput4.getScriptExpressions());
|
Assert.assertEquals(Collections.singletonList(ScriptExpression.SCRIPT_HASH), cryptoOutput4.getScriptExpressions());
|
||||||
Assert.assertEquals("035ccd58b63a2cdc23d0812710603592e7457573211880cb59b1ef012e168e059a", TestUtils.bytesToHex(cryptoOutput4.getHdKey().getKey()));
|
Assert.assertEquals("035ccd58b63a2cdc23d0812710603592e7457573211880cb59b1ef012e168e059a", TestUtils.bytesToHex(cryptoOutput4.getHdKey().getKey()));
|
||||||
Assert.assertEquals("88d3299b448f87215d96b0c226235afc027f9e7dc700284f3e912a34daeb1a23", TestUtils.bytesToHex(cryptoOutput4.getHdKey().getChainCode()));
|
Assert.assertEquals("88d3299b448f87215d96b0c226235afc027f9e7dc700284f3e912a34daeb1a23", TestUtils.bytesToHex(cryptoOutput4.getHdKey().getChainCode()));
|
||||||
Assert.assertEquals("45'", cryptoOutput4.getHdKey().getOrigin().getPath());
|
Assert.assertEquals("45'", cryptoOutput4.getHdKey().getOrigin().getPath());
|
||||||
|
@ -53,7 +55,7 @@ public class CryptoAccountTest {
|
||||||
Assert.assertNull(cryptoOutput4.getHdKey().getChildren());
|
Assert.assertNull(cryptoOutput4.getHdKey().getChildren());
|
||||||
|
|
||||||
CryptoOutput cryptoOutput5 = cryptoAccount.getOutputDescriptors().get(4);
|
CryptoOutput cryptoOutput5 = cryptoAccount.getOutputDescriptors().get(4);
|
||||||
Assert.assertEquals(List.of(ScriptExpression.SCRIPT_HASH, ScriptExpression.WITNESS_SCRIPT_HASH), cryptoOutput5.getScriptExpressions());
|
Assert.assertEquals(Arrays.asList(ScriptExpression.SCRIPT_HASH, ScriptExpression.WITNESS_SCRIPT_HASH), cryptoOutput5.getScriptExpressions());
|
||||||
Assert.assertEquals("032c78ebfcabdac6d735a0820ef8732f2821b4fb84cd5d6b26526938f90c050711", TestUtils.bytesToHex(cryptoOutput5.getHdKey().getKey()));
|
Assert.assertEquals("032c78ebfcabdac6d735a0820ef8732f2821b4fb84cd5d6b26526938f90c050711", TestUtils.bytesToHex(cryptoOutput5.getHdKey().getKey()));
|
||||||
Assert.assertEquals("7953efe16a73e5d3f9f2d4c6e49bd88e22093bbd85be5a7e862a4b98a16e0ab6", TestUtils.bytesToHex(cryptoOutput5.getHdKey().getChainCode()));
|
Assert.assertEquals("7953efe16a73e5d3f9f2d4c6e49bd88e22093bbd85be5a7e862a4b98a16e0ab6", TestUtils.bytesToHex(cryptoOutput5.getHdKey().getChainCode()));
|
||||||
Assert.assertEquals("48'/0'/0'/1'", cryptoOutput5.getHdKey().getOrigin().getPath());
|
Assert.assertEquals("48'/0'/0'/1'", cryptoOutput5.getHdKey().getOrigin().getPath());
|
||||||
|
@ -61,7 +63,7 @@ public class CryptoAccountTest {
|
||||||
Assert.assertNull(cryptoOutput5.getHdKey().getChildren());
|
Assert.assertNull(cryptoOutput5.getHdKey().getChildren());
|
||||||
|
|
||||||
CryptoOutput cryptoOutput6 = cryptoAccount.getOutputDescriptors().get(5);
|
CryptoOutput cryptoOutput6 = cryptoAccount.getOutputDescriptors().get(5);
|
||||||
Assert.assertEquals(List.of(ScriptExpression.WITNESS_SCRIPT_HASH), cryptoOutput6.getScriptExpressions());
|
Assert.assertEquals(Collections.singletonList(ScriptExpression.WITNESS_SCRIPT_HASH), cryptoOutput6.getScriptExpressions());
|
||||||
Assert.assertEquals("0260563ee80c26844621b06b74070baf0e23fb76ce439d0237e87502ebbd3ca346", TestUtils.bytesToHex(cryptoOutput6.getHdKey().getKey()));
|
Assert.assertEquals("0260563ee80c26844621b06b74070baf0e23fb76ce439d0237e87502ebbd3ca346", TestUtils.bytesToHex(cryptoOutput6.getHdKey().getKey()));
|
||||||
Assert.assertEquals("2fa0e41c9dc43dc4518659bfcef935ba8101b57dbc0812805dd983bc1d34b813", TestUtils.bytesToHex(cryptoOutput6.getHdKey().getChainCode()));
|
Assert.assertEquals("2fa0e41c9dc43dc4518659bfcef935ba8101b57dbc0812805dd983bc1d34b813", TestUtils.bytesToHex(cryptoOutput6.getHdKey().getChainCode()));
|
||||||
Assert.assertEquals("48'/0'/0'/2'", cryptoOutput6.getHdKey().getOrigin().getPath());
|
Assert.assertEquals("48'/0'/0'/2'", cryptoOutput6.getHdKey().getOrigin().getPath());
|
||||||
|
|
|
@ -7,6 +7,7 @@ import com.sparrowwallet.hummingbird.TestUtils;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CryptoBip39Test {
|
public class CryptoBip39Test {
|
||||||
|
@ -16,7 +17,7 @@ public class CryptoBip39Test {
|
||||||
byte[] data = TestUtils.hexToBytes(hex);
|
byte[] data = TestUtils.hexToBytes(hex);
|
||||||
List<DataItem> items = CborDecoder.decode(data);
|
List<DataItem> items = CborDecoder.decode(data);
|
||||||
CryptoBip39 cryptoSeed = CryptoBip39.fromCbor(items.get(0));
|
CryptoBip39 cryptoSeed = CryptoBip39.fromCbor(items.get(0));
|
||||||
Assert.assertEquals(List.of("shield", "group", "erode", "awake", "lock", "sausage", "cash", "glare", "wave", "crew", "flame", "glove"), cryptoSeed.getWords());
|
Assert.assertEquals(Arrays.asList("shield", "group", "erode", "awake", "lock", "sausage", "cash", "glare", "wave", "crew", "flame", "glove"), cryptoSeed.getWords());
|
||||||
Assert.assertEquals("en", cryptoSeed.getLanguage());
|
Assert.assertEquals("en", cryptoSeed.getLanguage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,8 @@ import com.sparrowwallet.hummingbird.TestUtils;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CryptoOutputTest {
|
public class CryptoOutputTest {
|
||||||
|
@ -16,7 +18,7 @@ public class CryptoOutputTest {
|
||||||
byte[] data = TestUtils.hexToBytes(hex);
|
byte[] data = TestUtils.hexToBytes(hex);
|
||||||
List<DataItem> items = CborDecoder.decode(data);
|
List<DataItem> items = CborDecoder.decode(data);
|
||||||
CryptoOutput cryptoOutput = CryptoOutput.fromCbor(items.get(0));
|
CryptoOutput cryptoOutput = CryptoOutput.fromCbor(items.get(0));
|
||||||
Assert.assertEquals(List.of(ScriptExpression.PUBLIC_KEY_HASH), cryptoOutput.getScriptExpressions());
|
Assert.assertEquals(Collections.singletonList(ScriptExpression.PUBLIC_KEY_HASH), cryptoOutput.getScriptExpressions());
|
||||||
Assert.assertEquals("02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5", TestUtils.bytesToHex(cryptoOutput.getEcKey().getData()));
|
Assert.assertEquals("02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5", TestUtils.bytesToHex(cryptoOutput.getEcKey().getData()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +28,7 @@ public class CryptoOutputTest {
|
||||||
byte[] data = TestUtils.hexToBytes(hex);
|
byte[] data = TestUtils.hexToBytes(hex);
|
||||||
List<DataItem> items = CborDecoder.decode(data);
|
List<DataItem> items = CborDecoder.decode(data);
|
||||||
CryptoOutput cryptoOutput = CryptoOutput.fromCbor(items.get(0));
|
CryptoOutput cryptoOutput = CryptoOutput.fromCbor(items.get(0));
|
||||||
Assert.assertEquals(List.of(ScriptExpression.SCRIPT_HASH, ScriptExpression.WITNESS_PUBLIC_KEY_HASH), cryptoOutput.getScriptExpressions());
|
Assert.assertEquals(Arrays.asList(ScriptExpression.SCRIPT_HASH, ScriptExpression.WITNESS_PUBLIC_KEY_HASH), cryptoOutput.getScriptExpressions());
|
||||||
Assert.assertEquals("03fff97bd5755eeea420453a14355235d382f6472f8568a18b2f057a1460297556", TestUtils.bytesToHex(cryptoOutput.getEcKey().getData()));
|
Assert.assertEquals("03fff97bd5755eeea420453a14355235d382f6472f8568a18b2f057a1460297556", TestUtils.bytesToHex(cryptoOutput.getEcKey().getData()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +38,7 @@ public class CryptoOutputTest {
|
||||||
byte[] data = TestUtils.hexToBytes(hex);
|
byte[] data = TestUtils.hexToBytes(hex);
|
||||||
List<DataItem> items = CborDecoder.decode(data);
|
List<DataItem> items = CborDecoder.decode(data);
|
||||||
CryptoOutput cryptoOutput = CryptoOutput.fromCbor(items.get(0));
|
CryptoOutput cryptoOutput = CryptoOutput.fromCbor(items.get(0));
|
||||||
Assert.assertEquals(List.of(ScriptExpression.SCRIPT_HASH, ScriptExpression.MULTISIG), cryptoOutput.getScriptExpressions());
|
Assert.assertEquals(Arrays.asList(ScriptExpression.SCRIPT_HASH, ScriptExpression.MULTISIG), cryptoOutput.getScriptExpressions());
|
||||||
Assert.assertNull(cryptoOutput.getHdKey());
|
Assert.assertNull(cryptoOutput.getHdKey());
|
||||||
Assert.assertEquals(2, cryptoOutput.getMultiKey().getThreshold());
|
Assert.assertEquals(2, cryptoOutput.getMultiKey().getThreshold());
|
||||||
|
|
||||||
|
@ -53,7 +55,7 @@ public class CryptoOutputTest {
|
||||||
byte[] data = TestUtils.hexToBytes(hex);
|
byte[] data = TestUtils.hexToBytes(hex);
|
||||||
List<DataItem> items = CborDecoder.decode(data);
|
List<DataItem> items = CborDecoder.decode(data);
|
||||||
CryptoOutput cryptoOutput = CryptoOutput.fromCbor(items.get(0));
|
CryptoOutput cryptoOutput = CryptoOutput.fromCbor(items.get(0));
|
||||||
Assert.assertEquals(List.of(ScriptExpression.PUBLIC_KEY_HASH), cryptoOutput.getScriptExpressions());
|
Assert.assertEquals(Collections.singletonList(ScriptExpression.PUBLIC_KEY_HASH), cryptoOutput.getScriptExpressions());
|
||||||
Assert.assertEquals("02d2b36900396c9282fa14628566582f206a5dd0bcc8d5e892611806cafb0301f0", TestUtils.bytesToHex(cryptoOutput.getHdKey().getKey()));
|
Assert.assertEquals("02d2b36900396c9282fa14628566582f206a5dd0bcc8d5e892611806cafb0301f0", TestUtils.bytesToHex(cryptoOutput.getHdKey().getKey()));
|
||||||
Assert.assertEquals("637807030d55d01f9a0cb3a7839515d796bd07706386a6eddf06cc29a65a0e29", TestUtils.bytesToHex(cryptoOutput.getHdKey().getChainCode()));
|
Assert.assertEquals("637807030d55d01f9a0cb3a7839515d796bd07706386a6eddf06cc29a65a0e29", TestUtils.bytesToHex(cryptoOutput.getHdKey().getChainCode()));
|
||||||
Assert.assertEquals("44'/0'/0'", cryptoOutput.getHdKey().getOrigin().getPath());
|
Assert.assertEquals("44'/0'/0'", cryptoOutput.getHdKey().getOrigin().getPath());
|
||||||
|
@ -69,7 +71,7 @@ public class CryptoOutputTest {
|
||||||
byte[] data = TestUtils.hexToBytes(hex);
|
byte[] data = TestUtils.hexToBytes(hex);
|
||||||
List<DataItem> items = CborDecoder.decode(data);
|
List<DataItem> items = CborDecoder.decode(data);
|
||||||
CryptoOutput cryptoOutput = CryptoOutput.fromCbor(items.get(0));
|
CryptoOutput cryptoOutput = CryptoOutput.fromCbor(items.get(0));
|
||||||
Assert.assertEquals(List.of(ScriptExpression.WITNESS_SCRIPT_HASH, ScriptExpression.MULTISIG), cryptoOutput.getScriptExpressions());
|
Assert.assertEquals(Arrays.asList(ScriptExpression.WITNESS_SCRIPT_HASH, ScriptExpression.MULTISIG), cryptoOutput.getScriptExpressions());
|
||||||
Assert.assertNull(cryptoOutput.getHdKey());
|
Assert.assertNull(cryptoOutput.getHdKey());
|
||||||
Assert.assertEquals(1, cryptoOutput.getMultiKey().getThreshold());
|
Assert.assertEquals(1, cryptoOutput.getMultiKey().getThreshold());
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue