diff --git a/src/main/java/com/sparrowwallet/drongo/protocol/ScriptType.java b/src/main/java/com/sparrowwallet/drongo/protocol/ScriptType.java index cc9a30b..21dc8dc 100644 --- a/src/main/java/com/sparrowwallet/drongo/protocol/ScriptType.java +++ b/src/main/java/com/sparrowwallet/drongo/protocol/ScriptType.java @@ -1,6 +1,8 @@ package com.sparrowwallet.drongo.protocol; +import com.sparrowwallet.drongo.KeyDerivation; import com.sparrowwallet.drongo.address.*; +import com.sparrowwallet.drongo.crypto.ChildNumber; import com.sparrowwallet.drongo.crypto.ECKey; import com.sparrowwallet.drongo.policy.PolicyType; @@ -381,19 +383,30 @@ public enum ScriptType { }; private final String name; - private final String defaultDerivation; + private final String defaultDerivationPath; - ScriptType(String name, String defaultDerivation) { + ScriptType(String name, String defaultDerivationPath) { this.name = name; - this.defaultDerivation = defaultDerivation; + this.defaultDerivationPath = defaultDerivationPath; } public String getName() { return name; } - public String getDefaultDerivation() { - return defaultDerivation; + public String getDefaultDerivationPath() { + return defaultDerivationPath; + } + + public List getDefaultDerivation() { + return KeyDerivation.parsePath(defaultDerivationPath); + } + + public List getDefaultDerivation(int account) { + List copy = new ArrayList<>(KeyDerivation.parsePath(defaultDerivationPath)); + ChildNumber accountChildNumber = new ChildNumber(account, true); + copy.set(2, accountChildNumber); + return Collections.unmodifiableList(copy); } public abstract List getAllowedPolicyTypes(); diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/Keystore.java b/src/main/java/com/sparrowwallet/drongo/wallet/Keystore.java index 30d913c..c2abf60 100644 --- a/src/main/java/com/sparrowwallet/drongo/wallet/Keystore.java +++ b/src/main/java/com/sparrowwallet/drongo/wallet/Keystore.java @@ -8,6 +8,8 @@ public class Keystore { public static final String DEFAULT_LABEL = "Keystore 1"; private String label; + private KeystoreSource source = KeystoreSource.SW_WATCH; + private WalletModel walletModel = WalletModel.SPARROW; private KeyDerivation keyDerivation; private ExtendedPublicKey extendedPublicKey; @@ -31,6 +33,22 @@ public class Keystore { this.label = label; } + public KeystoreSource getSource() { + return source; + } + + public void setSource(KeystoreSource source) { + this.source = source; + } + + public WalletModel getWalletModel() { + return walletModel; + } + + public void setWalletModel(WalletModel walletModel) { + this.walletModel = walletModel; + } + public KeyDerivation getKeyDerivation() { return keyDerivation; } @@ -60,6 +78,8 @@ public class Keystore { return false; } + //TODO: If source is SW_SEED, check seed field is filled + return true; } diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/KeystoreSource.java b/src/main/java/com/sparrowwallet/drongo/wallet/KeystoreSource.java new file mode 100644 index 0000000..acf8c44 --- /dev/null +++ b/src/main/java/com/sparrowwallet/drongo/wallet/KeystoreSource.java @@ -0,0 +1,5 @@ +package com.sparrowwallet.drongo.wallet; + +public enum KeystoreSource { + HW_USB, HW_AIRGAPPED, SW_SEED, SW_WATCH; +} diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/WalletModel.java b/src/main/java/com/sparrowwallet/drongo/wallet/WalletModel.java new file mode 100644 index 0000000..0517149 --- /dev/null +++ b/src/main/java/com/sparrowwallet/drongo/wallet/WalletModel.java @@ -0,0 +1,22 @@ +package com.sparrowwallet.drongo.wallet; + +public enum WalletModel { + SPARROW, BITCOIN_CORE, ELECTRUM, TREZOR_1, TREZOR_T, COLDCARD, LEDGER, DIGITALBITBOX, KEEPKEY; + + public static WalletModel getModel(String model) { + return valueOf(model.toUpperCase()); + } + + public String toDisplayString() { + String line = this.toString().toLowerCase(); + String[] words = line.split("_"); + StringBuilder builder = new StringBuilder(); + for(String word : words) { + builder.append(Character.toUpperCase(word.charAt(0))); + builder.append(word.substring(1)); + builder.append(" "); + } + + return builder.toString().trim(); + } +}