mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-12-26 10:06:45 +00:00
keystore importing
This commit is contained in:
parent
294649de66
commit
ed056bc49f
4 changed files with 65 additions and 5 deletions
|
@ -1,6 +1,8 @@
|
||||||
package com.sparrowwallet.drongo.protocol;
|
package com.sparrowwallet.drongo.protocol;
|
||||||
|
|
||||||
|
import com.sparrowwallet.drongo.KeyDerivation;
|
||||||
import com.sparrowwallet.drongo.address.*;
|
import com.sparrowwallet.drongo.address.*;
|
||||||
|
import com.sparrowwallet.drongo.crypto.ChildNumber;
|
||||||
import com.sparrowwallet.drongo.crypto.ECKey;
|
import com.sparrowwallet.drongo.crypto.ECKey;
|
||||||
import com.sparrowwallet.drongo.policy.PolicyType;
|
import com.sparrowwallet.drongo.policy.PolicyType;
|
||||||
|
|
||||||
|
@ -381,19 +383,30 @@ public enum ScriptType {
|
||||||
};
|
};
|
||||||
|
|
||||||
private final String name;
|
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.name = name;
|
||||||
this.defaultDerivation = defaultDerivation;
|
this.defaultDerivationPath = defaultDerivationPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDefaultDerivation() {
|
public String getDefaultDerivationPath() {
|
||||||
return defaultDerivation;
|
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();
|
public abstract List<PolicyType> getAllowedPolicyTypes();
|
||||||
|
|
|
@ -8,6 +8,8 @@ public class Keystore {
|
||||||
public static final String DEFAULT_LABEL = "Keystore 1";
|
public static final String DEFAULT_LABEL = "Keystore 1";
|
||||||
|
|
||||||
private String label;
|
private String label;
|
||||||
|
private KeystoreSource source = KeystoreSource.SW_WATCH;
|
||||||
|
private WalletModel walletModel = WalletModel.SPARROW;
|
||||||
private KeyDerivation keyDerivation;
|
private KeyDerivation keyDerivation;
|
||||||
private ExtendedPublicKey extendedPublicKey;
|
private ExtendedPublicKey extendedPublicKey;
|
||||||
|
|
||||||
|
@ -31,6 +33,22 @@ public class Keystore {
|
||||||
this.label = label;
|
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() {
|
public KeyDerivation getKeyDerivation() {
|
||||||
return keyDerivation;
|
return keyDerivation;
|
||||||
}
|
}
|
||||||
|
@ -60,6 +78,8 @@ public class Keystore {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: If source is SW_SEED, check seed field is filled
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package com.sparrowwallet.drongo.wallet;
|
||||||
|
|
||||||
|
public enum KeystoreSource {
|
||||||
|
HW_USB, HW_AIRGAPPED, SW_SEED, SW_WATCH;
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue