mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-11-02 18:26:43 +00:00
handle zero length derivation paths
This commit is contained in:
parent
04576bddff
commit
eb07a7ffa3
2 changed files with 15 additions and 5 deletions
|
@ -341,7 +341,7 @@ public class DeterministicSeed implements EncryptableItem {
|
|||
}
|
||||
|
||||
public enum Type {
|
||||
BIP39() {
|
||||
BIP39("Mnemonic Words (BIP39)") {
|
||||
public byte[] getEntropyBytes(List<String> mnemonicCode) throws MnemonicException {
|
||||
return Bip39MnemonicCode.INSTANCE.toEntropy(mnemonicCode);
|
||||
}
|
||||
|
@ -354,7 +354,7 @@ public class DeterministicSeed implements EncryptableItem {
|
|||
return Bip39MnemonicCode.toSeed(mnemonicCode, passphrase);
|
||||
}
|
||||
},
|
||||
ELECTRUM() {
|
||||
ELECTRUM("Mnemonic Words (Electrum Seed Version System)") {
|
||||
public byte[] getEntropyBytes(List<String> mnemonicCode) throws MnemonicException {
|
||||
throw new MnemonicException("Electrum seeds do not provide entropy bytes");
|
||||
}
|
||||
|
@ -368,6 +368,16 @@ public class DeterministicSeed implements EncryptableItem {
|
|||
}
|
||||
};
|
||||
|
||||
Type(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
private final String name;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public abstract byte[] getEntropyBytes(List<String> mnemonicCode) throws MnemonicException;
|
||||
|
||||
public abstract void check(List<String> mnemonicCode) throws MnemonicException;
|
||||
|
|
|
@ -101,7 +101,7 @@ public class Keystore {
|
|||
public ExtendedKey getExtendedPrivateKey() throws MnemonicException {
|
||||
List<ChildNumber> derivation = getKeyDerivation().getDerivation();
|
||||
DeterministicKey derivedKey = getExtendedMasterPrivateKey().getKey(derivation);
|
||||
ExtendedKey xprv = new ExtendedKey(derivedKey, derivedKey.getParentFingerprint(), derivation.get(derivation.size() - 1));
|
||||
ExtendedKey xprv = new ExtendedKey(derivedKey, derivedKey.getParentFingerprint(), derivation.isEmpty() ? ChildNumber.ZERO : derivation.get(derivation.size() - 1));
|
||||
//Recreate from xprv string to reset path to single ChildNumber at the derived depth
|
||||
return ExtendedKey.fromDescriptor(xprv.toString());
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ public class Keystore {
|
|||
List<ChildNumber> derivation = getKeyDerivation().getDerivation();
|
||||
DeterministicKey derivedKey = getExtendedMasterPrivateKey().getKey(derivation);
|
||||
DeterministicKey derivedKeyPublicOnly = derivedKey.dropPrivateBytes().dropParent();
|
||||
ExtendedKey xpub = new ExtendedKey(derivedKeyPublicOnly, derivedKey.getParentFingerprint(), derivation.get(derivation.size() - 1));
|
||||
ExtendedKey xpub = new ExtendedKey(derivedKeyPublicOnly, derivedKey.getParentFingerprint(), derivation.isEmpty() ? ChildNumber.ZERO : derivation.get(derivation.size() - 1));
|
||||
if(!xpub.equals(getExtendedPublicKey())) {
|
||||
return false;
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ public class Keystore {
|
|||
String masterFingerprint = Utils.bytesToHex(xprv.getKey().getFingerprint());
|
||||
DeterministicKey derivedKey = xprv.getKey(derivation);
|
||||
DeterministicKey derivedKeyPublicOnly = derivedKey.dropPrivateBytes().dropParent();
|
||||
ExtendedKey xpub = new ExtendedKey(derivedKeyPublicOnly, derivedKey.getParentFingerprint(), derivation.get(derivation.size() - 1));
|
||||
ExtendedKey xpub = new ExtendedKey(derivedKeyPublicOnly, derivedKey.getParentFingerprint(), derivation.isEmpty() ? ChildNumber.ZERO : derivation.get(derivation.size() - 1));
|
||||
|
||||
keystore.setLabel(seed.getType().name());
|
||||
keystore.setSource(KeystoreSource.SW_SEED);
|
||||
|
|
Loading…
Reference in a new issue