move special EC parser and key handling to testapp
This commit is contained in:
parent
6b50ca4921
commit
765b452f7d
|
@ -1,4 +1,5 @@
|
|||
eclipse.preferences.version=1
|
||||
encoding//src/main/java=UTF-8
|
||||
encoding//src/main/resources=UTF-8
|
||||
encoding//src/test/java=UTF-8
|
||||
encoding/<project>=UTF-8
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
@ -106,6 +106,15 @@
|
|||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- Unit tests plugin, to skip runing test add -Dmaven.test.skip -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<runOrder>alphabetical</runOrder>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
|
|
|
@ -6,7 +6,7 @@ import java.util.NoSuchElementException;
|
|||
import org.tcpid.opretj.OPRETTransaction;
|
||||
|
||||
public class MasterVerifyKey extends VerifyKey {
|
||||
private final LinkedList<VerifyKey> subkeys = new LinkedList<>();
|
||||
private final LinkedList<MasterVerifyKey> subkeys = new LinkedList<>();
|
||||
|
||||
public MasterVerifyKey(final byte[] key) {
|
||||
super(key);
|
||||
|
@ -16,11 +16,11 @@ public class MasterVerifyKey extends VerifyKey {
|
|||
subkeys.clear();
|
||||
}
|
||||
|
||||
public VerifyKey getValidSubKey() {
|
||||
public MasterVerifyKey getValidSubKey() {
|
||||
return subkeys.getFirst();
|
||||
}
|
||||
|
||||
public void revokeSubKey(final VerifyKey key) {
|
||||
public void revokeSubKey(final MasterVerifyKey key) {
|
||||
final int i = subkeys.indexOf(key);
|
||||
|
||||
if (i == -1) {
|
||||
|
@ -31,7 +31,7 @@ public class MasterVerifyKey extends VerifyKey {
|
|||
subkeys.remove(i);
|
||||
}
|
||||
|
||||
public void setFirstValidSubKey(final VerifyKey key, final OPRETTransaction t1, final OPRETTransaction t2) {
|
||||
public void setFirstValidSubKey(final MasterVerifyKey key, final OPRETTransaction t1, final OPRETTransaction t2) {
|
||||
if (!subkeys.isEmpty()) {
|
||||
throw new IndexOutOfBoundsException("Subkey list is not empty");
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ public class MasterVerifyKey extends VerifyKey {
|
|||
subkeys.addLast(key);
|
||||
}
|
||||
|
||||
public void setNextValidSubKey(final VerifyKey after, final VerifyKey key) {
|
||||
public void setNextValidSubKey(final MasterVerifyKey after, final MasterVerifyKey key) {
|
||||
final VerifyKey l = subkeys.getLast();
|
||||
if (!l.equals(after)) {
|
||||
throw new NoSuchElementException("No such after key, or not last in list");
|
|
@ -22,7 +22,6 @@ import org.libsodium.jni.crypto.Hash;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.tcpid.key.MasterSigningKey;
|
||||
import org.tcpid.opretj.OPRETECParser;
|
||||
import org.tcpid.opretj.OPRETWallet;
|
||||
import org.tcpid.opretj.OPRETWalletAppKit;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.tcpid.opretj;
|
||||
package org.tcpid.opretj.testapp;
|
||||
|
||||
import org.tcpid.key.MasterVerifyKey;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.tcpid.opretj;
|
||||
package org.tcpid.opretj.testapp;
|
||||
|
||||
import static org.bitcoinj.script.ScriptOpCodes.OP_RETURN;
|
||||
import static org.libsodium.jni.NaCl.sodium;
|
||||
|
@ -32,6 +32,8 @@ import org.tcpid.key.MasterSigningKey;
|
|||
import org.tcpid.key.MasterVerifyKey;
|
||||
import org.tcpid.key.SigningKey;
|
||||
import org.tcpid.key.VerifyKey;
|
||||
import org.tcpid.opretj.OPRETBaseHandler;
|
||||
import org.tcpid.opretj.OPRETTransaction;
|
||||
|
||||
import com.google.common.primitives.Bytes;
|
||||
|
||||
|
@ -163,6 +165,85 @@ public class OPRETECParser extends OPRETBaseHandler {
|
|||
return true;
|
||||
}
|
||||
|
||||
private boolean handleAnnounce(final OPRETTransaction selfTx,
|
||||
final Map<List<Byte>, List<OPRETTransaction>> selfTransHashMap,
|
||||
final Map<List<Byte>, List<OPRETTransaction>> otherTransHashMap, final boolean isT1) {
|
||||
|
||||
final byte[] selfData = Bytes.toArray(selfTx.opretData.get(1));
|
||||
if (((selfData.length < 48) || (selfData.length > 64))) {
|
||||
logger.debug("invalid chunk1 size = {}", selfData.length);
|
||||
return false;
|
||||
}
|
||||
|
||||
final List<Byte> pkhash = selfTx.opretData.get(2);
|
||||
if ((pkhash.size() != 12)) {
|
||||
logger.debug("chunk 2 size != 12 but {} ", pkhash.size());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!verifyKeys.containsKey(pkhash)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (otherTransHashMap.containsKey(pkhash)) {
|
||||
for (final OPRETTransaction otherTx : otherTransHashMap.get(pkhash)) {
|
||||
final byte[] otherData = Bytes.toArray(otherTx.opretData.get(1));
|
||||
final byte[] cipher = isT1
|
||||
? Bytes.concat(Arrays.copyOfRange(selfData, 0, 48), Arrays.copyOfRange(otherData, 0, 48))
|
||||
: Bytes.concat(Arrays.copyOfRange(otherData, 0, 48), Arrays.copyOfRange(selfData, 0, 48));
|
||||
final BigInteger selfNonce = (selfData.length == 48) ? BigInteger.ZERO
|
||||
: new BigInteger(1, Arrays.copyOfRange(selfData, 48, selfData.length));
|
||||
final BigInteger otherNonce = (otherData.length == 48) ? BigInteger.ZERO
|
||||
: new BigInteger(1, Arrays.copyOfRange(otherData, 48, otherData.length));
|
||||
|
||||
final BigInteger nonce = isT1 ? selfNonce.shiftLeft(16 * 8).or(otherNonce)
|
||||
: otherNonce.shiftLeft(16 * 8).or(selfNonce);
|
||||
|
||||
byte[] noncebytes = Util.prependZeros(32, nonce.toByteArray());
|
||||
noncebytes = Arrays.copyOfRange(noncebytes, noncebytes.length - 32, noncebytes.length);
|
||||
|
||||
for (final MasterVerifyKey k : verifyKeys.get(pkhash)) {
|
||||
byte[] sharedkey, xornonce;
|
||||
sharedkey = HASH.sha256(HASH.sha256(Bytes.concat(k.toBytes(), noncebytes)));
|
||||
xornonce = Arrays.copyOfRange(HASH.sha256(Bytes.concat(sharedkey, noncebytes)), 0, 24);
|
||||
logger.debug("checking key {}", Encoder.HEX.encode(k.toBytes()));
|
||||
logger.debug("noncebytes {}", Encoder.HEX.encode(noncebytes));
|
||||
logger.debug("noncebytes len {}", noncebytes.length);
|
||||
logger.debug("xornonce {}", Encoder.HEX.encode(xornonce));
|
||||
logger.debug("sharedkey {}", Encoder.HEX.encode(sharedkey));
|
||||
sodium();
|
||||
final byte[] msg = Util.zeros(96);
|
||||
Sodium.crypto_stream_xsalsa20_xor(msg, cipher, 96, xornonce, sharedkey);
|
||||
final byte[] vk = Arrays.copyOfRange(msg, 0, 32);
|
||||
final byte[] sig = Arrays.copyOfRange(msg, 32, 96);
|
||||
try {
|
||||
logger.debug("Checking sig {} with key {}", Encoder.HEX.encode(sig), Encoder.HEX.encode(vk));
|
||||
k.verify(vk, sig);
|
||||
} catch (final RuntimeException e) {
|
||||
logger.debug("sig does not match");
|
||||
continue;
|
||||
}
|
||||
logger.debug("sig matches");
|
||||
|
||||
k.setFirstValidSubKey(new MasterVerifyKey(vk), selfTx, otherTx);
|
||||
otherTransHashMap.get(pkhash).remove(otherTx);
|
||||
if (otherTransHashMap.get(pkhash).isEmpty()) {
|
||||
otherTransHashMap.remove(pkhash);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// no matching transaction found, save for later
|
||||
if (!selfTransHashMap.containsKey(pkhash)) {
|
||||
selfTransHashMap.put(pkhash, new ArrayList<OPRETTransaction>());
|
||||
}
|
||||
selfTransHashMap.get(pkhash).add(selfTx);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean handleEC0F(final OPRETTransaction t) {
|
||||
final byte[] sig = Bytes.toArray(t.opretData.get(1));
|
||||
if ((sig.length != 64)) {
|
||||
|
@ -247,163 +328,13 @@ public class OPRETECParser extends OPRETBaseHandler {
|
|||
}
|
||||
|
||||
private boolean handleECA1(final OPRETTransaction t1) {
|
||||
// FIXME: refactor with handleECA2
|
||||
|
||||
logger.debug("handleECA1");
|
||||
final byte[] data1 = Bytes.toArray(t1.opretData.get(1));
|
||||
if (((data1.length < 48) || (data1.length > 64))) {
|
||||
logger.debug("invalid chunk1 size = {}", data1.length);
|
||||
return false;
|
||||
}
|
||||
|
||||
final List<Byte> pkhash = t1.opretData.get(2);
|
||||
if ((pkhash.size() != 12)) {
|
||||
logger.debug("chunk 2 size != 12 but {} ", pkhash.size());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!verifyKeys.containsKey(pkhash)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (transA2HashMap.containsKey(pkhash)) {
|
||||
for (final OPRETTransaction t2 : transA2HashMap.get(pkhash)) {
|
||||
final byte[] data2 = Bytes.toArray(t2.opretData.get(1));
|
||||
final byte[] cipher = Bytes.concat(Arrays.copyOfRange(data1, 0, 48), Arrays.copyOfRange(data2, 0, 48));
|
||||
BigInteger nonce1 = BigInteger.ZERO;
|
||||
BigInteger nonce2 = BigInteger.ZERO;
|
||||
if (data1.length > 48) {
|
||||
nonce1 = new BigInteger(1, Arrays.copyOfRange(data1, 48, data1.length));
|
||||
logger.debug("nonce1 {}", Encoder.HEX.encode(nonce1.toByteArray()));
|
||||
logger.debug("nonce1shift {}", Encoder.HEX.encode(nonce1.shiftLeft(16 * 8).toByteArray()));
|
||||
}
|
||||
if (data2.length > 48) {
|
||||
nonce2 = new BigInteger(1, Arrays.copyOfRange(data2, 48, data2.length));
|
||||
logger.debug("nonce2 {}", Encoder.HEX.encode(nonce2.toByteArray()));
|
||||
}
|
||||
|
||||
final BigInteger nonce = nonce1.shiftLeft(16 * 8).or(nonce2);
|
||||
logger.debug("nonceshift {}", Encoder.HEX.encode(nonce.toByteArray()));
|
||||
|
||||
byte[] noncebytes = Util.prependZeros(32, nonce.toByteArray());
|
||||
noncebytes = Arrays.copyOfRange(noncebytes, noncebytes.length - 32, noncebytes.length);
|
||||
|
||||
for (final MasterVerifyKey k : verifyKeys.get(pkhash)) {
|
||||
byte[] sharedkey, xornonce;
|
||||
sharedkey = HASH.sha256(HASH.sha256(Bytes.concat(k.toBytes(), noncebytes)));
|
||||
xornonce = Arrays.copyOfRange(HASH.sha256(Bytes.concat(sharedkey, noncebytes)), 0, 24);
|
||||
logger.debug("checking key {}", Encoder.HEX.encode(k.toBytes()));
|
||||
logger.debug("noncebytes {}", Encoder.HEX.encode(noncebytes));
|
||||
logger.debug("noncebytes len {}", noncebytes.length);
|
||||
logger.debug("xornonce {}", Encoder.HEX.encode(xornonce));
|
||||
logger.debug("sharedkey {}", Encoder.HEX.encode(sharedkey));
|
||||
sodium();
|
||||
final byte[] msg = Util.zeros(96);
|
||||
Sodium.crypto_stream_xsalsa20_xor(msg, cipher, 96, xornonce, sharedkey);
|
||||
final byte[] vk = Arrays.copyOfRange(msg, 0, 32);
|
||||
final byte[] sig = Arrays.copyOfRange(msg, 32, 96);
|
||||
try {
|
||||
logger.debug("Checking sig {} with key {}", Encoder.HEX.encode(sig), Encoder.HEX.encode(vk));
|
||||
k.verify(vk, sig);
|
||||
} catch (final RuntimeException e) {
|
||||
logger.debug("sig does not match");
|
||||
continue;
|
||||
}
|
||||
logger.debug("sig matches");
|
||||
|
||||
k.setFirstValidSubKey(new MasterVerifyKey(vk), t1, t2);
|
||||
transA2HashMap.get(pkhash).remove(t2);
|
||||
if (transA2HashMap.get(pkhash).isEmpty()) {
|
||||
transA2HashMap.remove(pkhash);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!transA1HashMap.containsKey(pkhash)) {
|
||||
transA1HashMap.put(pkhash, new ArrayList<OPRETTransaction>());
|
||||
}
|
||||
transA1HashMap.get(pkhash).add(t1);
|
||||
|
||||
return false;
|
||||
return handleAnnounce(t1, transA1HashMap, transA2HashMap, true);
|
||||
}
|
||||
|
||||
private boolean handleECA2(final OPRETTransaction t2) {
|
||||
// FIXME: refactor with handleECA1
|
||||
logger.debug("handleECA2");
|
||||
final byte[] data2 = Bytes.toArray(t2.opretData.get(1));
|
||||
if (((data2.length < 48) || (data2.length > 64))) {
|
||||
logger.debug("invalid chunk1 size = {}", data2.length);
|
||||
return false;
|
||||
}
|
||||
|
||||
final List<Byte> pkhash = t2.opretData.get(2);
|
||||
if ((pkhash.size() != 12)) {
|
||||
logger.debug("chunk 2 size != 12 but {} ", pkhash.size());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!verifyKeys.containsKey(pkhash)) {
|
||||
logger.debug("pkash not in hashmap");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (transA1HashMap.containsKey(pkhash)) {
|
||||
for (final OPRETTransaction t1 : transA1HashMap.get(pkhash)) {
|
||||
final byte[] data1 = Bytes.toArray(t1.opretData.get(1));
|
||||
final byte[] cipher = Bytes.concat(Arrays.copyOfRange(data1, 0, 48), Arrays.copyOfRange(data2, 0, 48));
|
||||
BigInteger nonce1 = BigInteger.ZERO;
|
||||
BigInteger nonce2 = BigInteger.ZERO;
|
||||
if (data1.length > 48) {
|
||||
nonce1 = new BigInteger(1, Arrays.copyOfRange(data1, 48, data1.length));
|
||||
}
|
||||
if (data2.length > 48) {
|
||||
nonce2 = new BigInteger(1, Arrays.copyOfRange(data2, 48, data2.length));
|
||||
}
|
||||
|
||||
final BigInteger nonce = nonce1.shiftLeft(16 * 8).or(nonce2);
|
||||
byte[] noncebytes = Util.prependZeros(32, nonce.toByteArray());
|
||||
noncebytes = Arrays.copyOfRange(noncebytes, noncebytes.length - 32, noncebytes.length);
|
||||
|
||||
for (final MasterVerifyKey k : verifyKeys.get(pkhash)) {
|
||||
byte[] sharedkey, xornonce;
|
||||
logger.debug("checking key {}", Encoder.HEX.encode(k.toBytes()));
|
||||
logger.debug("noncebytes {}", Encoder.HEX.encode(noncebytes));
|
||||
logger.debug("noncebytes len {}", noncebytes.length);
|
||||
sharedkey = HASH.sha256(HASH.sha256(Bytes.concat(k.toBytes(), noncebytes)));
|
||||
xornonce = Arrays.copyOfRange(HASH.sha256(Bytes.concat(sharedkey, noncebytes)), 0, 24);
|
||||
logger.debug("xornonce {}", Encoder.HEX.encode(xornonce));
|
||||
logger.debug("sharedkey {}", Encoder.HEX.encode(sharedkey));
|
||||
|
||||
sodium();
|
||||
final byte[] msg = Util.zeros(96);
|
||||
Sodium.crypto_stream_xsalsa20_xor(msg, cipher, 96, xornonce, sharedkey);
|
||||
final byte[] vk = Arrays.copyOfRange(msg, 0, 32);
|
||||
final byte[] sig = Arrays.copyOfRange(msg, 32, 96);
|
||||
try {
|
||||
logger.debug("Checking sig {} with key {}", Encoder.HEX.encode(sig), Encoder.HEX.encode(vk));
|
||||
k.verify(vk, sig);
|
||||
} catch (final RuntimeException e) {
|
||||
logger.debug("sig does not match");
|
||||
continue;
|
||||
}
|
||||
|
||||
logger.debug("sig matches");
|
||||
k.setFirstValidSubKey(new MasterVerifyKey(vk), t1, t2);
|
||||
transA1HashMap.get(pkhash).remove(t1);
|
||||
if (transA1HashMap.get(pkhash).isEmpty()) {
|
||||
transA1HashMap.remove(pkhash);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!transA2HashMap.containsKey(pkhash)) {
|
||||
transA2HashMap.put(pkhash, new ArrayList<OPRETTransaction>());
|
||||
}
|
||||
transA2HashMap.get(pkhash).add(t2);
|
||||
logger.debug("nothing in A1 HashMap");
|
||||
return false;
|
||||
return handleAnnounce(t2, transA2HashMap, transA1HashMap, false);
|
||||
}
|
||||
|
||||
private boolean handleECA3(final OPRETTransaction t) {
|
||||
|
@ -416,7 +347,8 @@ public class OPRETECParser extends OPRETBaseHandler {
|
|||
return false;
|
||||
}
|
||||
|
||||
protected boolean handleTransaction(final OPRETTransaction t) {
|
||||
@Override
|
||||
public boolean pushTransaction(final OPRETTransaction t) {
|
||||
logger.debug("checking {}", t.opretData);
|
||||
|
||||
if ((t.opretData.size() != 2) && (t.opretData.size() != 3) && (t.opretData.size() != 4)) {
|
||||
|
@ -464,11 +396,6 @@ public class OPRETECParser extends OPRETBaseHandler {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pushTransaction(final OPRETTransaction t) {
|
||||
handleTransaction(t);
|
||||
}
|
||||
|
||||
private void queueOnOPRETId(final MasterVerifyKey k) {
|
||||
// TODO Auto-generated method stub
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
<logger name="org.bitcoinj.core.AbstractBlockChain" level="error" />
|
||||
<logger name="org.bitcoinj.core.PeerSocketHandler" level="error" />
|
||||
<logger name="org.bitcoinj.net.ConnectionHandler" level="error" />
|
||||
<logger name="org.tcpid.opretj.OPRETECParser" level="debug" />
|
||||
<logger name="org.tcpid.opretj.testapp.OPRETECParser" level="debug" />
|
||||
<!--
|
||||
<logger name="eckey.OPRETSimpleLogger" level="debug" />
|
||||
<logger name="eckey.OPRETSimpleParser" level="debug" />
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.tcpid.opretj;
|
||||
package org.tcpid.opretj.testapp;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
@ -67,8 +67,9 @@ public class TestCrypto {
|
|||
@Test
|
||||
public void testSignEnc() {
|
||||
final MasterSigningKey msk = new MasterSigningKey(HASH.sha256("TESTSEED".getBytes()));
|
||||
final MasterVerifyKey subkey = msk.getSubKey(1L).getMasterVerifyKey();
|
||||
final MasterVerifyKey vk = msk.getMasterVerifyKey();
|
||||
byte[] sig = msk.sign(vk.toBytes());
|
||||
byte[] sig = msk.sign(subkey.toBytes());
|
||||
|
||||
logger.debug("using key {}", Encoder.HEX.encode(vk.toBytes()));
|
||||
final byte[] noncebytes = Util.zeros(32);
|
||||
|
@ -78,7 +79,7 @@ public class TestCrypto {
|
|||
logger.debug("sharedkey {}", Encoder.HEX.encode(sharedkey));
|
||||
|
||||
final byte[] cipher = Util.zeros(96);
|
||||
byte[] msg = Bytes.concat(vk.toBytes(), sig);
|
||||
byte[] msg = Bytes.concat(subkey.toBytes(), sig);
|
||||
assertEquals(96, msg.length);
|
||||
|
||||
sodium();
|
||||
|
@ -93,7 +94,7 @@ public class TestCrypto {
|
|||
sig = Arrays.copyOfRange(msg, 32, 96);
|
||||
logger.debug("vkb : {}", Encoder.HEX.encode(vkb));
|
||||
assertTrue("Verification of signature failed.", vk.verify(vkb, sig));
|
||||
assertArrayEquals(vk.toBytes(), vkb);
|
||||
assertArrayEquals(subkey.toBytes(), vkb);
|
||||
}
|
||||
|
||||
@Test
|
|
@ -1,8 +1,9 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.tcpid.opretj;
|
||||
package org.tcpid.opretj.testapp;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
@ -16,6 +17,8 @@ import org.libsodium.jni.encoders.Encoder;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.tcpid.key.MasterVerifyKey;
|
||||
import org.tcpid.opretj.OPRETTransaction;
|
||||
import org.tcpid.opretj.testapp.OPRETECParser;
|
||||
|
||||
import com.google.common.primitives.Bytes;
|
||||
|
||||
|
@ -24,14 +27,14 @@ public class TestECA1 {
|
|||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.tcpid.opretj.OPRETECParser#pushTransaction(org.tcpid.opretj.OPRETTransaction)}.
|
||||
* {@link org.tcpid.opretj.testapp.OPRETECParser#pushTransaction(org.tcpid.opretj.OPRETTransaction)}.
|
||||
*/
|
||||
@Test
|
||||
public void testPushTransaction() {
|
||||
logger.debug("testPushTransaction");
|
||||
|
||||
final byte[] cipher = Encoder.HEX.decode(
|
||||
"bed9e277c3fde807eecb2100e2a4c9ec1067891b9f021e3bfbc599a3676048598e7c9801d94d9765cb965e64cfb9f493d7ae332bc85affb8bb0337b6835c51d156005db43ab8ea9b988632bfadcaee7dabf08709be248f5354d59a98e53f0cda");
|
||||
"a15b671a9890a6bd0b6ed9a50193a15283001ccd72e106198b32242a906c300e263fc31dbfdaad66c40fc9796db3a464ab4313a06bbcd88fc1d503110016114c1da8bdf6e58a82be18d33c1baa96e1a9fe9c6f939b6838b30972be2de53f12d0");
|
||||
final byte[] vkb = Encoder.HEX.decode("fb2e360caf811b3aaf534d0458c2a2ca3e1f213b244a6f83af1ab50eddacdd8c");
|
||||
final MasterVerifyKey mvk = new MasterVerifyKey(vkb);
|
||||
|
||||
|
@ -66,36 +69,39 @@ public class TestECA1 {
|
|||
|
||||
parser.addVerifyKey(mvk, 0);
|
||||
|
||||
assertFalse(parser.handleTransaction(t2));
|
||||
assertFalse(parser.handleTransaction(t3));
|
||||
assertFalse(parser.handleTransaction(t4));
|
||||
assertTrue(parser.handleTransaction(t1));
|
||||
assertFalse(parser.pushTransaction(t2));
|
||||
assertFalse(parser.pushTransaction(t3));
|
||||
assertFalse(parser.pushTransaction(t4));
|
||||
assertTrue(parser.pushTransaction(t1));
|
||||
|
||||
mvk.clearSubKeys();
|
||||
|
||||
assertFalse(parser.handleTransaction(t1));
|
||||
assertFalse(parser.handleTransaction(t3));
|
||||
assertFalse(parser.handleTransaction(t4));
|
||||
assertTrue(parser.handleTransaction(t2));
|
||||
assertFalse(parser.pushTransaction(t1));
|
||||
assertFalse(parser.pushTransaction(t3));
|
||||
assertFalse(parser.pushTransaction(t4));
|
||||
assertTrue(parser.pushTransaction(t2));
|
||||
|
||||
mvk.clearSubKeys();
|
||||
|
||||
assertFalse(parser.handleTransaction(t1));
|
||||
assertFalse(parser.handleTransaction(t4));
|
||||
assertFalse(parser.handleTransaction(t3));
|
||||
assertTrue(parser.handleTransaction(t2));
|
||||
assertFalse(parser.pushTransaction(t1));
|
||||
assertFalse(parser.pushTransaction(t4));
|
||||
assertFalse(parser.pushTransaction(t3));
|
||||
assertTrue(parser.pushTransaction(t2));
|
||||
|
||||
mvk.clearSubKeys();
|
||||
|
||||
assertFalse(parser.handleTransaction(t2));
|
||||
assertFalse(parser.handleTransaction(t4));
|
||||
assertFalse(parser.handleTransaction(t3));
|
||||
assertTrue(parser.handleTransaction(t1));
|
||||
assertFalse(parser.pushTransaction(t2));
|
||||
assertFalse(parser.pushTransaction(t4));
|
||||
assertFalse(parser.pushTransaction(t3));
|
||||
assertTrue(parser.pushTransaction(t1));
|
||||
final MasterVerifyKey subkey = mvk.getValidSubKey();
|
||||
assertArrayEquals(subkey.toBytes(),
|
||||
Encoder.HEX.decode("e4acb361f4ec55804af6b5a1bbf5ca74ad78b4edc9a977a1dfed08872aa0a5db"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.tcpid.opretj.OPRETECParser#pushTransaction(org.tcpid.opretj.OPRETTransaction)}.
|
||||
* {@link org.tcpid.opretj.testapp.OPRETECParser#pushTransaction(org.tcpid.opretj.OPRETTransaction)}.
|
||||
*/
|
||||
@Test
|
||||
public void testPushTransactionWithNonce() {
|
||||
|
@ -125,22 +131,25 @@ public class TestECA1 {
|
|||
|
||||
parser.addVerifyKey(mvk, 0);
|
||||
|
||||
assertFalse(parser.handleTransaction(t2));
|
||||
assertTrue(parser.handleTransaction(t1));
|
||||
assertFalse(parser.pushTransaction(t2));
|
||||
assertTrue(parser.pushTransaction(t1));
|
||||
|
||||
mvk.clearSubKeys();
|
||||
|
||||
assertFalse(parser.handleTransaction(t1));
|
||||
assertTrue(parser.handleTransaction(t2));
|
||||
assertFalse(parser.pushTransaction(t1));
|
||||
assertTrue(parser.pushTransaction(t2));
|
||||
|
||||
mvk.clearSubKeys();
|
||||
|
||||
assertFalse(parser.handleTransaction(t1));
|
||||
assertTrue(parser.handleTransaction(t2));
|
||||
assertFalse(parser.pushTransaction(t1));
|
||||
assertTrue(parser.pushTransaction(t2));
|
||||
|
||||
mvk.clearSubKeys();
|
||||
|
||||
assertFalse(parser.handleTransaction(t2));
|
||||
assertTrue(parser.handleTransaction(t1));
|
||||
assertFalse(parser.pushTransaction(t2));
|
||||
assertTrue(parser.pushTransaction(t1));
|
||||
final MasterVerifyKey subkey = mvk.getValidSubKey();
|
||||
assertArrayEquals(subkey.toBytes(),
|
||||
Encoder.HEX.decode("fb2e360caf811b3aaf534d0458c2a2ca3e1f213b244a6f83af1ab50eddacdd8c"));
|
||||
}
|
||||
}
|
|
@ -1,4 +1,3 @@
|
|||
eclipse.preferences.version=1
|
||||
encoding//src/main/java=UTF-8
|
||||
encoding//src/test/java=UTF-8
|
||||
encoding/<project>=UTF-8
|
||||
|
|
|
@ -18,7 +18,7 @@ public interface OPRETHandlerInterface {
|
|||
|
||||
// void removeOPRET(byte[] magic);
|
||||
|
||||
void pushTransaction(OPRETTransaction t);
|
||||
boolean pushTransaction(OPRETTransaction t);
|
||||
|
||||
boolean removeOPRETChangeEventListener(OPRETChangeEventListener listener);
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ public class OPRETSimpleLogger extends OPRETBaseHandler {
|
|||
private static final Logger logger = LoggerFactory.getLogger(OPRETSimpleLogger.class);
|
||||
|
||||
@Override
|
||||
public void pushTransaction(final OPRETTransaction t) {
|
||||
public boolean pushTransaction(final OPRETTransaction t) {
|
||||
final StringBuilder buf = new StringBuilder();
|
||||
|
||||
for (final List<Byte> d : t.opretData) {
|
||||
|
@ -21,6 +21,7 @@ public class OPRETSimpleLogger extends OPRETBaseHandler {
|
|||
}
|
||||
|
||||
logger.info("Received in Block: {}\nTX: {}\nData: {}", t.blockHash, t.txHash, buf);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue