mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-12-27 02:26:44 +00:00
complete wallet validation
This commit is contained in:
parent
f6414a4475
commit
6b1f7d0174
2 changed files with 18 additions and 5 deletions
|
@ -109,7 +109,11 @@ public class Keystore {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(keyDerivation.getDerivationPath() == null || !KeyDerivation.isValid(keyDerivation.getDerivationPath())) {
|
if(label.isEmpty() || label.replace(" ", "").length() > 16) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(keyDerivation.getDerivationPath() == null || keyDerivation.getDerivationPath().isEmpty() || !KeyDerivation.isValid(keyDerivation.getDerivationPath())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,10 +7,7 @@ import com.sparrowwallet.drongo.policy.PolicyType;
|
||||||
import com.sparrowwallet.drongo.protocol.ScriptType;
|
import com.sparrowwallet.drongo.protocol.ScriptType;
|
||||||
import org.bouncycastle.crypto.params.KeyParameter;
|
import org.bouncycastle.crypto.params.KeyParameter;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class Wallet {
|
public class Wallet {
|
||||||
|
|
||||||
|
@ -99,6 +96,10 @@ public class Wallet {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(containsDuplicateKeystoreLabels()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
for(Keystore keystore : keystores) {
|
for(Keystore keystore : keystores) {
|
||||||
if(!keystore.isValid()) {
|
if(!keystore.isValid()) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -119,6 +120,14 @@ public class Wallet {
|
||||||
return Arrays.stream(ScriptType.values()).anyMatch(scriptType -> !scriptType.equals(this.scriptType) && scriptType.getAccount(derivationPath) > -1);
|
return Arrays.stream(ScriptType.values()).anyMatch(scriptType -> !scriptType.equals(this.scriptType) && scriptType.getAccount(derivationPath) > -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean containsDuplicateKeystoreLabels() {
|
||||||
|
if(keystores.size() <= 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return !keystores.stream().map(Keystore::getLabel).allMatch(new HashSet<>()::add);
|
||||||
|
}
|
||||||
|
|
||||||
public Wallet copy() {
|
public Wallet copy() {
|
||||||
Wallet copy = new Wallet(name);
|
Wallet copy = new Wallet(name);
|
||||||
copy.setPolicyType(policyType);
|
copy.setPolicyType(policyType);
|
||||||
|
|
Loading…
Reference in a new issue