keystore importing

This commit is contained in:
Craig Raw 2020-04-29 12:03:09 +02:00
parent 294649de66
commit ed056bc49f
4 changed files with 65 additions and 5 deletions

View file

@ -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<ChildNumber> getDefaultDerivation() {
return KeyDerivation.parsePath(defaultDerivationPath);
}
public List<ChildNumber> getDefaultDerivation(int account) {
List<ChildNumber> copy = new ArrayList<>(KeyDerivation.parsePath(defaultDerivationPath));
ChildNumber accountChildNumber = new ChildNumber(account, true);
copy.set(2, accountChildNumber);
return Collections.unmodifiableList(copy);
}
public abstract List<PolicyType> getAllowedPolicyTypes();

View file

@ -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;
}

View file

@ -0,0 +1,5 @@
package com.sparrowwallet.drongo.wallet;
public enum KeystoreSource {
HW_USB, HW_AIRGAPPED, SW_SEED, SW_WATCH;
}

View file

@ -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();
}
}