use of com.sparrowwallet.drongo.wallet.Keystore in project sparrow by sparrowwallet.
the class CaravanMultisig method exportWallet.
@Override
public void exportWallet(Wallet wallet, OutputStream outputStream) throws ExportException {
if (!wallet.isValid()) {
throw new ExportException("Cannot export an incomplete wallet");
}
if (!wallet.getPolicyType().equals(PolicyType.MULTI)) {
throw new ExportException(getName() + " import requires a multisig wallet");
}
try {
CaravanFile cf = new CaravanFile();
cf.name = wallet.getFullName();
cf.addressType = wallet.getScriptType().toString().replace('-', '_');
cf.network = Network.get().getName();
cf.client = new Client();
Quorum quorum = new Quorum();
quorum.requiredSigners = wallet.getDefaultPolicy().getNumSignaturesRequired();
quorum.totalSigners = wallet.getKeystores().size();
cf.quorum = quorum;
cf.extendedPublicKeys = new ArrayList<>();
for (Keystore keystore : wallet.getKeystores()) {
ExtPublicKey extKey = new ExtPublicKey();
extKey.name = keystore.getLabel();
extKey.bip32Path = keystore.getKeyDerivation().getDerivationPath();
extKey.xpub = keystore.getExtendedPublicKey().toString();
extKey.xfp = keystore.getKeyDerivation().getMasterFingerprint();
extKey.method = keystore.getWalletModel().getType();
cf.extendedPublicKeys.add(extKey);
}
Gson gson = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
String json = gson.toJson(cf);
outputStream.write(json.getBytes(StandardCharsets.UTF_8));
outputStream.flush();
} catch (Exception e) {
log.error("Error exporting " + getName() + " wallet", e);
throw new ExportException("Error exporting " + getName() + " wallet", e);
}
}
use of com.sparrowwallet.drongo.wallet.Keystore in project sparrow by sparrowwallet.
the class KeystoneMultisig method importWallet.
@Override
public Wallet importWallet(InputStream inputStream, String password) throws ImportException {
Wallet wallet = super.importWallet(inputStream, password);
for (Keystore keystore : wallet.getKeystores()) {
keystore.setLabel(keystore.getLabel().replace("Coldcard", "Keystone"));
keystore.setWalletModel(WalletModel.KEYSTONE);
}
return wallet;
}
Aggregations