From 29b630f6bf38876ffb33c3de9818cd740117563c Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Mon, 29 May 2023 17:20:43 +0200 Subject: [PATCH] update to hummingbird v1.6.7 to support pair path components and unique part progress indicator --- build.gradle | 2 +- .../sparrow/control/QRScanDialog.java | 14 ++++++++++---- .../sparrow/wallet/SettingsController.java | 4 +++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 97bb41d6..c2d32629 100644 --- a/build.gradle +++ b/build.gradle @@ -89,7 +89,7 @@ dependencies { implementation('com.github.arteam:simple-json-rpc-server:1.3') { exclude group: 'org.slf4j' } - implementation('com.sparrowwallet:hummingbird:1.6.4') + implementation('com.sparrowwallet:hummingbird:1.6.7') implementation('co.nstant.in:cbor:0.9') implementation("com.nativelibs4java:bridj${targetName}:0.7-20140918-3") { exclude group: 'com.google.android.tools', module: 'dx' diff --git a/src/main/java/com/sparrowwallet/sparrow/control/QRScanDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/QRScanDialog.java index ec871b25..f6b9cf82 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/QRScanDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/QRScanDialog.java @@ -25,6 +25,8 @@ import com.sparrowwallet.hummingbird.registry.*; import com.sparrowwallet.hummingbird.ResultType; import com.sparrowwallet.hummingbird.UR; import com.sparrowwallet.hummingbird.URDecoder; +import com.sparrowwallet.hummingbird.registry.pathcomponent.IndexPathComponent; +import com.sparrowwallet.hummingbird.registry.pathcomponent.PathComponent; import com.sparrowwallet.sparrow.AppServices; import com.sparrowwallet.sparrow.glyphfont.FontAwesome5; import com.sparrowwallet.sparrow.io.Config; @@ -208,6 +210,7 @@ public class QRScanDialog extends Dialog { URDecoder.Result urResult = decoder.getResult(); if(urResult.type == ResultType.SUCCESS) { result = extractResultFromUR(urResult.ur); + Platform.runLater(() -> setResult(result)); } else { result = new Result(new URException(urResult.error)); } @@ -479,7 +482,9 @@ public class QRScanDialog extends Dialog { if(cryptoHDKey.getOrigin() != null) { if(!cryptoHDKey.getOrigin().getComponents().isEmpty()) { PathComponent lastComponent = cryptoHDKey.getOrigin().getComponents().get(cryptoHDKey.getOrigin().getComponents().size() - 1); - lastChild = new ChildNumber(lastComponent.getIndex(), lastComponent.isHardened()); + if(lastComponent instanceof IndexPathComponent indexPathComponent) { + lastChild = new ChildNumber(indexPathComponent.getIndex(), indexPathComponent.isHardened()); + } depth = cryptoHDKey.getOrigin().getComponents().size(); } if(cryptoHDKey.getParentFingerprint() != null) { @@ -555,11 +560,12 @@ public class QRScanDialog extends Dialog { private KeyDerivation getKeyDerivation(CryptoKeypath cryptoKeypath) { if(cryptoKeypath != null) { - if(cryptoKeypath.getComponents().stream().anyMatch(PathComponent::isWildcard)) { - throw new IllegalArgumentException("Wildcard derivation paths are not supported"); + if(!cryptoKeypath.getComponents().stream().allMatch(pathComponent -> pathComponent instanceof IndexPathComponent)) { + throw new IllegalArgumentException("Only indexed derivation path components are supported"); } - List path = cryptoKeypath.getComponents().stream().map(comp -> new ChildNumber(comp.getIndex(), comp.isHardened())).collect(Collectors.toList()); + List path = cryptoKeypath.getComponents().stream().map(comp -> (IndexPathComponent)comp) + .map(comp -> new ChildNumber(comp.getIndex(), comp.isHardened())).collect(Collectors.toList()); return new KeyDerivation(Utils.bytesToHex(cryptoKeypath.getSourceFingerprint()), KeyDerivation.writePath(path)); } diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java index 9103c1bb..b058810e 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java @@ -9,6 +9,8 @@ import com.sparrowwallet.drongo.protocol.ScriptType; import com.sparrowwallet.drongo.wallet.*; import com.sparrowwallet.hummingbird.UR; import com.sparrowwallet.hummingbird.registry.*; +import com.sparrowwallet.hummingbird.registry.pathcomponent.IndexPathComponent; +import com.sparrowwallet.hummingbird.registry.pathcomponent.PathComponent; import com.sparrowwallet.sparrow.AppServices; import com.sparrowwallet.sparrow.EventManager; import com.sparrowwallet.sparrow.control.*; @@ -389,7 +391,7 @@ public class SettingsController extends WalletFormController implements Initiali private CryptoHDKey getCryptoHDKey(Keystore keystore) { ExtendedKey extendedKey = keystore.getExtendedPublicKey(); CryptoCoinInfo cryptoCoinInfo = new CryptoCoinInfo(CryptoCoinInfo.Type.BITCOIN.ordinal(), Network.get() == Network.MAINNET ? CryptoCoinInfo.Network.MAINNET.ordinal() : CryptoCoinInfo.Network.TESTNET.ordinal()); - List pathComponents = keystore.getKeyDerivation().getDerivation().stream().map(cNum -> new PathComponent(cNum.num(), cNum.isHardened())).collect(Collectors.toList()); + List pathComponents = keystore.getKeyDerivation().getDerivation().stream().map(cNum -> new IndexPathComponent(cNum.num(), cNum.isHardened())).collect(Collectors.toList()); CryptoKeypath cryptoKeypath = new CryptoKeypath(pathComponents, Utils.hexToBytes(keystore.getKeyDerivation().getMasterFingerprint()), pathComponents.size()); return new CryptoHDKey(false, extendedKey.getKey().getPubKey(), extendedKey.getKey().getChainCode(), cryptoCoinInfo, cryptoKeypath, null, extendedKey.getParentFingerprint()); }