Unverified Commit bbd03e03 authored by TDevD's avatar TDevD Committed by GitHub
Browse files

Merge pull request #6 from Samourai-Wallet/develop

build 004
parents 33852ab5 2058bafb
......@@ -18,6 +18,7 @@ package org.bitcoinj.wallet;
import org.bitcoinj.core.*;
import org.bitcoinj.script.Script;
import org.bitcoinj.script.ScriptException;
import com.google.common.collect.Lists;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......
......@@ -235,9 +235,14 @@ public class MarriedKeyChain extends DeterministicKeyChain {
@Override
protected void formatAddresses(boolean includePrivateKeys, NetworkParameters params, StringBuilder builder2) {
for (DeterministicKeyChain followingChain : followingKeyChains)
builder2.append("Following chain: ").append(followingChain.getWatchingKey().serializePubB58(params))
for (DeterministicKeyChain followingChain : followingKeyChains) {
builder2.append("Following chain: ").append(followingChain.getWatchingKey().serializePubB58(params, 44))
.append('\n');
builder2.append("Following chain: ").append(followingChain.getWatchingKey().serializePubB58(params, 49))
.append('\n');
builder2.append("Following chain: ").append(followingChain.getWatchingKey().serializePubB58(params, 84))
.append('\n');
}
builder2.append('\n');
for (RedeemData redeemData : marriedKeysRedeemData.values())
formatScript(ScriptBuilder.createP2SHOutputScript(redeemData.redeemScript), builder2, params);
......
......@@ -40,7 +40,6 @@ import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.Peer;
import org.bitcoinj.core.PeerFilterProvider;
import org.bitcoinj.core.PeerGroup;
import org.bitcoinj.core.ScriptException;
import org.bitcoinj.core.Sha256Hash;
import org.bitcoinj.core.StoredBlock;
import org.bitcoinj.core.Transaction;
......
......@@ -22,6 +22,7 @@ import org.bitcoinj.core.TransactionConfidence.ConfidenceType;
import org.bitcoinj.crypto.KeyCrypter;
import org.bitcoinj.crypto.KeyCrypterScrypt;
import org.bitcoinj.script.Script;
import org.bitcoinj.script.ScriptException;
import org.bitcoinj.signers.LocalTransactionSigner;
import org.bitcoinj.signers.TransactionSigner;
import org.bitcoinj.utils.ExchangeRate;
......
......@@ -22,6 +22,7 @@ import org.bitcoinj.core.Transaction.SigHash;
import org.bitcoinj.crypto.TransactionSignature;
import org.bitcoinj.script.Script;
import org.bitcoinj.script.ScriptBuilder;
import org.bitcoinj.script.ScriptException;
import com.google.common.base.Preconditions;
import javax.annotation.Nullable;
......
......@@ -25,6 +25,9 @@ import org.bouncycastle.crypto.params.*;
import static org.bitcoinj.core.Utils.*;
import static org.junit.Assert.*;
import java.util.List;
import java.util.ArrayList;
/**
* This test is adapted from Armory's BIP 32 tests.
*/
......@@ -198,6 +201,52 @@ public class ChildKeyDerivationTest {
priv58 = key1.serializePrivB58(params);
assertEquals("tpubD6NzVbkrYhZ4WuxgZMdpw1Hvi7MKg6YDjDMXVohmZCFfF17hXBPYpc56rCY1KXFMovN29ik37nZimQseiykRTBTJTZJmjENyv2k3R12BJ1M", pub58);
assertEquals("tprv8ZgxMBicQKsPdSvtfhyEXbdp95qPWmMK9ukkDHfU8vTGQWrvtnZxe7TEg48Ui7HMsZKMj7CcQRg8YF1ydtFPZBxha5oLa3qeN3iwpYhHPVZ", priv58);
{
List<String> words = new ArrayList<String>();
words.add("dwarf");
words.add("cheese");
words.add("material");
words.add("blind");
words.add("rain");
words.add("elder");
words.add("train");
words.add("tribe");
words.add("deposit");
words.add("exist");
words.add("better");
words.add("organ");
byte[] hd_seed = MnemonicCode.toSeed(words, "test");
key1 = HDKeyDerivation.createMasterPrivateKey(hd_seed);
// BIP49
DeterministicKey key2 = HDKeyDerivation.deriveChildKey(key1, 49|ChildNumber.HARDENED_BIT);
DeterministicKey key3 = HDKeyDerivation.deriveChildKey(key2, ChildNumber.HARDENED_BIT);
int childnum = 0|ChildNumber.HARDENED_BIT;
DeterministicKey aKey = HDKeyDerivation.deriveChildKey(key3, childnum);
params = MainNetParams.get();
pub58 = aKey.serializePubB58(params, 49);
priv58 = aKey.serializePrivB58(params, 49);
assertEquals("ypub6WoG7B3T2iNt3gcVb8QEDZwpYwetWWBVBeJP5p1SoGy39Cp37TdvBTMCbjq2tURJR1G5A45VxbP6pCR9qrkD62KTKcshjo4AjJQMuKzXxbi", pub58);
assertEquals("yprvAHouhfWZCLpaqCY2V6sDrS15zupQ73TdpRNnHRbqEwS4GQUtZvKfdf2ikVWTfWnsLYUX6WYXiA7yk1akiQkL7Rr1aBx4S4r7RnZ7XgmRqSZ", priv58);
params = TestNet3Params.get();
pub58 = aKey.serializePubB58(params, 49);
priv58 = aKey.serializePrivB58(params, 49);
assertEquals("upub5DUCtWMnRzCxeVr2FhFjPDZos556k2DVXCDVxERuHFTWvoZ86pyfhCieWuzgtqocnSnrA9hG7wxuH3xty569u5b3rG61Q9nDeQ9nM42hj5v", pub58);
assertEquals("uprv8zUrUzptbcefS1mZ9fij25d5K3EcLZVe9yHu9r2HiuvY41DyZHfR9QQAffg7ftBBhz1J6cAHsWhnCs8Vqd6GvV7c6qAN6RaALtJXyNr5kLL", priv58);
// BIP84
key2 = HDKeyDerivation.deriveChildKey(key1, 84|ChildNumber.HARDENED_BIT);
key3 = HDKeyDerivation.deriveChildKey(key2, ChildNumber.HARDENED_BIT);
aKey = HDKeyDerivation.deriveChildKey(key3, childnum);
params = MainNetParams.get();
pub58 = aKey.serializePubB58(params, 84);
priv58 = aKey.serializePrivB58(params, 84);
assertEquals("zpub6rBun332vrUEDbUL4Yzfung4UasiNVA3qY7S6wNdrUudTynXPoqGRuTpt68n1xAbD9yd1GyjRBb3gmM7WqMCDqzuzBdVpAamjG4PjdGP5EK", pub58);
assertEquals("zprvAdCZNXW96Uuw17PrxXTfYejKvZ3Dy2SCUKBqJYy2J9NebBTNrGX1t79M2qZERzDamBhxonb1fhCZjhd3TixyCpa44L3ZC34ZFbQnFDrqaS5", priv58);
params = TestNet3Params.get();
pub58 = aKey.serializePubB58(params, 84);
priv58 = aKey.serializePrivB58(params, 84);
assertEquals("vpub5YrrZNMNL8JJpQhrj7rB5SJ3niHvc1C4B62YyMo6LTQ7FaXcPBB1weqGoGJS2KYuabWQ1NbVaYAr9ctre3h92uGWWpqoUXJpeMopBPEUYgu", pub58);
assertEquals("vprv9KsW9rpUVkk1bvdPd6KAiJMKEgTSCYUCos6xAyPUn7s8NnCTqdrmPrWnx1itSMbu8dEjotCmq3nNCZAnawJv1sqeayFrrPncAhACgsaiiWg", priv58);
}
}
@Test
......@@ -212,8 +261,8 @@ public class ChildKeyDerivationTest {
{
final String pub58 = key1.serializePubB58(params);
final String priv58 = key1.serializePrivB58(params);
final byte[] pub = key1.serializePublic(params);
final byte[] priv = key1.serializePrivate(params);
final byte[] pub = key1.serializePublic(params, 44);
final byte[] priv = key1.serializePrivate(params, 44);
assertEquals("xpub661MyMwAqRbcF7mq7Aejj5xZNzFfgi3ABamE9FedDHVmViSzSxYTgAQGcATDo2J821q7Y9EAagjg5EP3L7uBZk11PxZU3hikL59dexfLkz3", pub58);
assertEquals("xprv9s21ZrQH143K2dhN197jMx1ppxRBHFKJpMqdLsF1ewxncv7quRED8N5nksxphju3W7naj1arF56L5PUEWfuSk8h73Sb2uh7bSwyXNrjzhAZ", priv58);
assertArrayEquals(new byte[]{4, -120, -78, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 57, -68, 93, -104, -97, 31, -105, -18, 109, 112, 104, 45, -77, -77, 18, 85, -29, -120, 86, -113, 26, 48, -18, -79, -110, -6, -27, 87, 86, 24, 124, 99, 3, 96, -33, -14, 67, -19, -47, 16, 76, -49, -11, -30, -123, 7, 56, 101, 91, 74, 125, -127, 61, 42, -103, 90, -93, 66, -36, 2, -126, -107, 30, 24, -111}, pub);
......@@ -230,8 +279,8 @@ public class ChildKeyDerivationTest {
{
final String pub58 = key2.serializePubB58(params);
final String priv58 = key2.serializePrivB58(params);
final byte[] pub = key2.serializePublic(params);
final byte[] priv = key2.serializePrivate(params);
final byte[] pub = key2.serializePublic(params, 44);
final byte[] priv = key2.serializePrivate(params, 44);
assertEquals(DeterministicKey.deserializeB58(key1, priv58, params), key2);
assertEquals(DeterministicKey.deserializeB58(key1, pub58, params).getPubKeyPoint(), key2.getPubKeyPoint());
assertEquals(DeterministicKey.deserialize(params, priv, key1), key2);
......@@ -247,9 +296,9 @@ public class ChildKeyDerivationTest {
DeterministicKey key3 = HDKeyDerivation.deriveChildKey(key2, ChildNumber.ZERO_HARDENED);
DeterministicKey key4 = HDKeyDerivation.deriveChildKey(key3, ChildNumber.ZERO_HARDENED);
assertEquals(key4.getPath().size(), 3);
assertEquals(DeterministicKey.deserialize(params, key4.serializePrivate(params), key3).getPath().size(), 3);
assertEquals(DeterministicKey.deserialize(params, key4.serializePrivate(params), null).getPath().size(), 1);
assertEquals(DeterministicKey.deserialize(params, key4.serializePrivate(params)).getPath().size(), 1);
assertEquals(DeterministicKey.deserialize(params, key4.serializePrivate(params, 44), key3).getPath().size(), 3);
assertEquals(DeterministicKey.deserialize(params, key4.serializePrivate(params, 44), null).getPath().size(), 1);
assertEquals(DeterministicKey.deserialize(params, key4.serializePrivate(params, 44)).getPath().size(), 1);
}
/** Reserializing a deserialized key should yield the original input */
......
......@@ -120,7 +120,7 @@ public class PaymentSessionTest {
}
fail("Expected exception due to expired PaymentRequest");
}
/*
@Test
public void testPkiVerification() throws Exception {
InputStream in = getClass().getResourceAsStream("pki_test.bitcoinpaymentrequest");
......@@ -130,7 +130,7 @@ public class PaymentSessionTest {
assertEquals("www.bitcoincore.org", pkiData.displayName);
assertEquals("The USERTRUST Network, Salt Lake City, US", pkiData.rootAuthorityName);
}
*/
@Test(expected = PaymentProtocolException.InvalidNetwork.class)
public void testWrongNetwork() throws Exception {
// Create a PaymentRequest and make sure the correct values are parsed by the PaymentSession.
......
......@@ -21,7 +21,7 @@
<groupId>org.bitcoinj</groupId>
<artifactId>bitcoinj-parent</artifactId>
<version>0.15-Segwit-Samourai-001</version>
<version>0.15-Segwit-Samourai-004</version>
<packaging>pom</packaging>
<modules>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment