mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-11-02 18:26:43 +00:00
testnet support followup changes
This commit is contained in:
parent
747bfa915f
commit
b877e94cd0
4 changed files with 42 additions and 3 deletions
|
@ -84,4 +84,9 @@ public enum Network {
|
|||
private static boolean isTest() {
|
||||
return System.getProperty("org.gradle.test.worker") != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.sparrowwallet.drongo.protocol;
|
||||
|
||||
import com.sparrowwallet.drongo.KeyDerivation;
|
||||
import com.sparrowwallet.drongo.Network;
|
||||
import com.sparrowwallet.drongo.Utils;
|
||||
import com.sparrowwallet.drongo.address.*;
|
||||
import com.sparrowwallet.drongo.crypto.ChildNumber;
|
||||
|
@ -988,15 +989,15 @@ public enum ScriptType {
|
|||
}
|
||||
|
||||
public String getDefaultDerivationPath() {
|
||||
return defaultDerivationPath;
|
||||
return Network.get() != Network.MAINNET ? defaultDerivationPath.replace("/0'/0'", "/1'/0'") : defaultDerivationPath;
|
||||
}
|
||||
|
||||
public List<ChildNumber> getDefaultDerivation() {
|
||||
return KeyDerivation.parsePath(defaultDerivationPath);
|
||||
return KeyDerivation.parsePath(getDefaultDerivationPath());
|
||||
}
|
||||
|
||||
public List<ChildNumber> getDefaultDerivation(int account) {
|
||||
List<ChildNumber> copy = new ArrayList<>(KeyDerivation.parsePath(defaultDerivationPath));
|
||||
List<ChildNumber> copy = new ArrayList<>(KeyDerivation.parsePath(getDefaultDerivationPath()));
|
||||
ChildNumber accountChildNumber = new ChildNumber(account, true);
|
||||
copy.set(2, accountChildNumber);
|
||||
return Collections.unmodifiableList(copy);
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.sparrowwallet.drongo.wallet;
|
|||
|
||||
import com.sparrowwallet.drongo.BitcoinUnit;
|
||||
import com.sparrowwallet.drongo.KeyPurpose;
|
||||
import com.sparrowwallet.drongo.Network;
|
||||
import com.sparrowwallet.drongo.address.Address;
|
||||
import com.sparrowwallet.drongo.crypto.ECKey;
|
||||
import com.sparrowwallet.drongo.crypto.Key;
|
||||
|
@ -21,6 +22,7 @@ public class Wallet {
|
|||
public static final int DEFAULT_LOOKAHEAD = 20;
|
||||
|
||||
private String name;
|
||||
private Network network = Network.get();
|
||||
private PolicyType policyType;
|
||||
private ScriptType scriptType;
|
||||
private Policy defaultPolicy;
|
||||
|
@ -53,6 +55,14 @@ public class Wallet {
|
|||
this.name = name;
|
||||
}
|
||||
|
||||
public Network getNetwork() {
|
||||
return network;
|
||||
}
|
||||
|
||||
public void setNetwork(Network network) {
|
||||
this.network = network;
|
||||
}
|
||||
|
||||
public PolicyType getPolicyType() {
|
||||
return policyType;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
package com.sparrowwallet.drongo.wallet;
|
||||
|
||||
import com.sparrowwallet.drongo.ExtendedKey;
|
||||
import com.sparrowwallet.drongo.KeyDerivation;
|
||||
import com.sparrowwallet.drongo.KeyPurpose;
|
||||
import com.sparrowwallet.drongo.Utils;
|
||||
import com.sparrowwallet.drongo.crypto.Argon2KeyDeriver;
|
||||
import com.sparrowwallet.drongo.crypto.ChildNumber;
|
||||
import com.sparrowwallet.drongo.crypto.Key;
|
||||
import com.sparrowwallet.drongo.crypto.KeyDeriver;
|
||||
import com.sparrowwallet.drongo.policy.Policy;
|
||||
|
@ -10,6 +14,8 @@ import com.sparrowwallet.drongo.protocol.ScriptType;
|
|||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class WalletTest {
|
||||
@Test
|
||||
public void encryptTest() throws MnemonicException {
|
||||
|
@ -206,4 +212,21 @@ public class WalletTest {
|
|||
Assert.assertEquals("bc1q20e4vm656h5lvmngz9ztz6hjzftvh39yzngqhuqzk8qzj7tqnzaqgclrwc", wallet.getAddress(KeyPurpose.RECEIVE, 0).toString());
|
||||
Assert.assertEquals("bc1q2epdx7dplwaas2jucfrzmxm8350rqh68hs6vqreysku80ye44mfqla85f2", wallet.getAddress(KeyPurpose.CHANGE, 1).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHighDerivationPath() {
|
||||
Wallet wallet = new Wallet();
|
||||
wallet.setPolicyType(PolicyType.SINGLE);
|
||||
wallet.setScriptType(ScriptType.P2WPKH);
|
||||
Keystore keystore = new Keystore();
|
||||
keystore.setKeyDerivation(new KeyDerivation("ffffffff", "m/84'/0'/2147483646'"));
|
||||
ExtendedKey extendedKey = ExtendedKey.fromDescriptor("ypub6WxQGZTrBdeYSD6ZnSxopCGnuS7dhbqc72S3sbjdFjxf8eBR3EJDB3iDMhny2tKogZnpaJcjoHC6zF5Cz1jSMrFFR1wrqfA1MFsWP3ACotd");
|
||||
keystore.setExtendedPublicKey(extendedKey);
|
||||
wallet.getKeystores().add(keystore);
|
||||
|
||||
List<ChildNumber> derivation = List.of(keystore.getExtendedPublicKey().getKeyChildNumber(), new ChildNumber(0));
|
||||
Assert.assertEquals("027ecc656f4b91b92881b6f07cf876cd2e42b20df7acc4df54fc3315fbb2d13e1c", Utils.bytesToHex(extendedKey.getKey(derivation).getPubKey()));
|
||||
|
||||
Assert.assertEquals("bc1qarzeu6ncapyvjzdeayjq8vnzp6uvcn4eaeuuqq", wallet.getAddress(KeyPurpose.RECEIVE, 0).toString());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue