rename gordian seed tool, support retrieving a keystore from an output descriptor more generally

This commit is contained in:
Craig Raw 2022-01-04 10:33:47 +02:00
parent c1f6a1245e
commit 083288061f
3 changed files with 28 additions and 3 deletions

View file

@ -38,6 +38,10 @@ public enum Network {
return name; return name;
} }
public String toDisplayString() {
return name.substring(0, 1).toUpperCase() + name.substring(1);
}
public int getP2PKHAddressHeader() { public int getP2PKHAddressHeader() {
return p2pkhAddressHeader; return p2pkhAddressHeader;
} }

View file

@ -254,6 +254,27 @@ public class OutputDescriptor {
return wallet; return wallet;
} }
public Wallet toKeystoreWallet(String masterFingerprint) {
Wallet wallet = new Wallet();
if(isMultisig()) {
throw new IllegalStateException("Multisig output descriptors are unsupported.");
}
ExtendedKey extendedKey = getSingletonExtendedPublicKey();
if(masterFingerprint == null) {
masterFingerprint = getKeyDerivation(extendedKey).getMasterFingerprint();
}
wallet.setScriptType(getScriptType());
Keystore keystore = new Keystore();
keystore.setKeyDerivation(new KeyDerivation(masterFingerprint, KeyDerivation.writePath(getKeyDerivation(extendedKey).getDerivation())));
keystore.setExtendedPublicKey(extendedKey);
wallet.getKeystores().add(keystore);
wallet.setDefaultPolicy(Policy.getPolicy(isCosigner() ? PolicyType.MULTI : PolicyType.SINGLE, wallet.getScriptType(), wallet.getKeystores(), 1));
return wallet;
}
public static OutputDescriptor getOutputDescriptor(Wallet wallet) { public static OutputDescriptor getOutputDescriptor(Wallet wallet) {
return getOutputDescriptor(wallet, null); return getOutputDescriptor(wallet, null);
} }

View file

@ -1,7 +1,7 @@
package com.sparrowwallet.drongo.wallet; package com.sparrowwallet.drongo.wallet;
public enum WalletModel { public enum WalletModel {
SEED, SPARROW, BITCOIN_CORE, ELECTRUM, TREZOR_1, TREZOR_T, COLDCARD, LEDGER_NANO_S, LEDGER_NANO_X, DIGITALBITBOX_01, KEEPKEY, SPECTER_DESKTOP, COBO_VAULT, BITBOX_02, SPECTER_DIY, PASSPORT, BLUE_WALLET, KEYSTONE, SEEDSIGNER, CARAVAN, SEED_TOOL; SEED, SPARROW, BITCOIN_CORE, ELECTRUM, TREZOR_1, TREZOR_T, COLDCARD, LEDGER_NANO_S, LEDGER_NANO_X, DIGITALBITBOX_01, KEEPKEY, SPECTER_DESKTOP, COBO_VAULT, BITBOX_02, SPECTER_DIY, PASSPORT, BLUE_WALLET, KEYSTONE, SEEDSIGNER, CARAVAN, GORDIAN_SEED_TOOL;
public static WalletModel getModel(String model) { public static WalletModel getModel(String model) {
return valueOf(model.toUpperCase()); return valueOf(model.toUpperCase());
@ -40,7 +40,7 @@ public enum WalletModel {
return "bluewallet"; return "bluewallet";
} }
if(this == SEED_TOOL) { if(this == GORDIAN_SEED_TOOL) {
return "seedtool"; return "seedtool";
} }
@ -48,7 +48,7 @@ public enum WalletModel {
} }
public boolean alwaysIncludeNonWitnessUtxo() { public boolean alwaysIncludeNonWitnessUtxo() {
if(this == COLDCARD || this == COBO_VAULT || this == PASSPORT || this == KEYSTONE || this == SEED_TOOL) { if(this == COLDCARD || this == COBO_VAULT || this == PASSPORT || this == KEYSTONE || this == GORDIAN_SEED_TOOL) {
return false; return false;
} }