mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-12-25 17:46:44 +00:00
use locale-insensitive lowercase and uppercase functions
This commit is contained in:
parent
8a6d2da5c9
commit
ca833fbf68
10 changed files with 33 additions and 21 deletions
|
@ -5,6 +5,7 @@ import com.sparrowwallet.drongo.crypto.ChildNumber;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class KeyDerivation {
|
||||
private final String masterFingerprint;
|
||||
|
@ -16,7 +17,7 @@ public class KeyDerivation {
|
|||
}
|
||||
|
||||
public KeyDerivation(String masterFingerprint, String derivationPath) {
|
||||
this.masterFingerprint = masterFingerprint == null ? null : masterFingerprint.toLowerCase();
|
||||
this.masterFingerprint = masterFingerprint == null ? null : masterFingerprint.toLowerCase(Locale.ROOT);
|
||||
this.derivationPath = derivationPath;
|
||||
this.derivation = parsePath(derivationPath);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.sparrowwallet.drongo;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public enum Network {
|
||||
MAINNET("mainnet", 0, "1", 5, "3", "bc", ExtendedKey.Header.xprv, ExtendedKey.Header.xpub, 128, 8332),
|
||||
TESTNET("testnet", 111, "mn", 196, "2", "tb", ExtendedKey.Header.tprv, ExtendedKey.Header.tpub, 239, 18332),
|
||||
|
@ -39,7 +41,7 @@ public enum Network {
|
|||
}
|
||||
|
||||
public String toDisplayString() {
|
||||
return name.substring(0, 1).toUpperCase() + name.substring(1);
|
||||
return name.substring(0, 1).toUpperCase(Locale.ROOT) + name.substring(1);
|
||||
}
|
||||
|
||||
public int getP2PKHAddressHeader() {
|
||||
|
|
|
@ -2,6 +2,8 @@ package com.sparrowwallet.drongo;
|
|||
|
||||
import ch.qos.logback.core.PropertyDefinerBase;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class PropertyDefiner extends PropertyDefinerBase {
|
||||
private String application;
|
||||
|
||||
|
@ -11,15 +13,15 @@ public class PropertyDefiner extends PropertyDefinerBase {
|
|||
|
||||
@Override
|
||||
public String getPropertyValue() {
|
||||
if(System.getProperty(application.toLowerCase() + ".home") != null) {
|
||||
return System.getProperty(application.toLowerCase() + ".home");
|
||||
if(System.getProperty(application.toLowerCase(Locale.ROOT) + ".home") != null) {
|
||||
return System.getProperty(application.toLowerCase(Locale.ROOT) + ".home");
|
||||
}
|
||||
|
||||
return isWindows() ? System.getenv("APPDATA") + "/" + application.substring(0, 1).toUpperCase() + application.substring(1).toLowerCase() : System.getProperty("user.home") + "/." + application.toLowerCase();
|
||||
return isWindows() ? System.getenv("APPDATA") + "/" + application.substring(0, 1).toUpperCase(Locale.ROOT) + application.substring(1).toLowerCase(Locale.ROOT) : System.getProperty("user.home") + "/." + application.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
private boolean isWindows() {
|
||||
String osName = System.getProperty("os.name");
|
||||
return (osName != null && osName.toLowerCase().startsWith("windows"));
|
||||
return (osName != null && osName.toLowerCase(Locale.ROOT).startsWith("windows"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.sparrowwallet.drongo.protocol.Script;
|
|||
import com.sparrowwallet.drongo.protocol.ScriptType;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
public abstract class Address {
|
||||
protected final byte[] data;
|
||||
|
@ -106,7 +107,7 @@ public abstract class Address {
|
|||
}
|
||||
}
|
||||
|
||||
if(address.toLowerCase().startsWith(network.getBech32AddressHRP())) {
|
||||
if(address.toLowerCase(Locale.ROOT).startsWith(network.getBech32AddressHRP())) {
|
||||
try {
|
||||
Bech32.Bech32Data data = Bech32.decode(address);
|
||||
if(data.hrp.equals(network.getBech32AddressHRP())) {
|
||||
|
|
|
@ -1288,7 +1288,7 @@ public enum ScriptType {
|
|||
scriptTypes.sort((o1, o2) -> o2.getDescriptor().length() - o1.getDescriptor().length());
|
||||
|
||||
for(ScriptType scriptType : scriptTypes) {
|
||||
if(descriptor.toLowerCase().startsWith(scriptType.getDescriptor())) {
|
||||
if(descriptor.toLowerCase(Locale.ROOT).startsWith(scriptType.getDescriptor())) {
|
||||
return scriptType;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -154,7 +154,7 @@ public class BitcoinURI {
|
|||
if(sepIndex == 0) {
|
||||
throw new BitcoinURIParseException("Malformed Bitcoin URI - empty name '" + nameValuePairToken + "'");
|
||||
}
|
||||
final String nameToken = nameValuePairToken.substring(0, sepIndex).toLowerCase(Locale.ENGLISH);
|
||||
final String nameToken = nameValuePairToken.substring(0, sepIndex).toLowerCase(Locale.ROOT);
|
||||
final String valueToken = nameValuePairToken.substring(sepIndex + 1);
|
||||
|
||||
// Parse the amount.
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package com.sparrowwallet.drongo.wallet;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
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, GORDIAN_SEED_TOOL, JADE, LEDGER_NANO_S_PLUS;
|
||||
|
||||
public static WalletModel getModel(String model) {
|
||||
return valueOf(model.toUpperCase());
|
||||
return valueOf(model.toUpperCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
|
@ -44,7 +46,7 @@ public enum WalletModel {
|
|||
return "seedtool";
|
||||
}
|
||||
|
||||
return this.toString().toLowerCase();
|
||||
return this.toString().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
public boolean alwaysIncludeNonWitnessUtxo() {
|
||||
|
@ -74,7 +76,7 @@ public enum WalletModel {
|
|||
}
|
||||
|
||||
public String toDisplayString() {
|
||||
String line = this.toString().toLowerCase();
|
||||
String line = this.toString().toLowerCase(Locale.ROOT);
|
||||
String[] words = line.split("_");
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for(String word : words) {
|
||||
|
|
|
@ -10,6 +10,7 @@ import org.junit.Test;
|
|||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
|
@ -484,9 +485,9 @@ public class TransactionTest {
|
|||
@Test
|
||||
public void signBip340() {
|
||||
ECKey privKey = ECKey.fromPrivate(Utils.hexToBytes("0000000000000000000000000000000000000000000000000000000000000003"));
|
||||
Assert.assertEquals("F9308A019258C31049344F85F89D5229B531C845836F99B08601F113BCE036F9", Utils.bytesToHex(privKey.getPubKeyXCoord()).toUpperCase());
|
||||
Assert.assertEquals("F9308A019258C31049344F85F89D5229B531C845836F99B08601F113BCE036F9", Utils.bytesToHex(privKey.getPubKeyXCoord()).toUpperCase(Locale.ROOT));
|
||||
SchnorrSignature sig = privKey.signSchnorr(Sha256Hash.ZERO_HASH);
|
||||
Assert.assertEquals("E907831F80848D1069A5371B402410364BDF1C5F8307B0084C55F1CE2DCA821525F66A4A85EA8B71E482A74F382D2CE5EBEEE8FDB2172F477DF4900D310536C0", Utils.bytesToHex(sig.encode()).toUpperCase());
|
||||
Assert.assertEquals("E907831F80848D1069A5371B402410364BDF1C5F8307B0084C55F1CE2DCA821525F66A4A85EA8B71E482A74F382D2CE5EBEEE8FDB2172F477DF4900D310536C0", Utils.bytesToHex(sig.encode()).toUpperCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -3,13 +3,15 @@ package com.sparrowwallet.drongo.uri;
|
|||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class BitcoinUriTest {
|
||||
@Test
|
||||
public void testSamourai() throws BitcoinURIParseException {
|
||||
String uri = "bitcoin:BC1QT4NRM47695YWDG9N30N68JARMXRJNKFMR36994?amount=0,001";
|
||||
BitcoinURI bitcoinURI = new BitcoinURI(uri);
|
||||
|
||||
Assert.assertEquals("BC1QT4NRM47695YWDG9N30N68JARMXRJNKFMR36994".toLowerCase(), bitcoinURI.getAddress().toString());
|
||||
Assert.assertEquals("BC1QT4NRM47695YWDG9N30N68JARMXRJNKFMR36994".toLowerCase(Locale.ROOT), bitcoinURI.getAddress().toString());
|
||||
Assert.assertEquals(Long.valueOf(100000), bitcoinURI.getAmount());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import org.junit.Assert;
|
|||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class PolicyTest {
|
||||
@Test
|
||||
|
@ -16,27 +17,27 @@ public class PolicyTest {
|
|||
Keystore keystore3 = new Keystore("Keystore 3");
|
||||
|
||||
Policy policy = Policy.getPolicy(PolicyType.SINGLE, ScriptType.P2PKH, List.of(keystore1), 1);
|
||||
Assert.assertEquals("pkh(keystore1)", policy.getMiniscript().toString().toLowerCase());
|
||||
Assert.assertEquals("pkh(keystore1)", policy.getMiniscript().toString().toLowerCase(Locale.ROOT));
|
||||
Assert.assertEquals(1, policy.getNumSignaturesRequired());
|
||||
|
||||
Policy policy2 = Policy.getPolicy(PolicyType.SINGLE, ScriptType.P2SH_P2WPKH, List.of(keystore1), 1);
|
||||
Assert.assertEquals("sh(wpkh(keystore1))", policy2.getMiniscript().toString().toLowerCase());
|
||||
Assert.assertEquals("sh(wpkh(keystore1))", policy2.getMiniscript().toString().toLowerCase(Locale.ROOT));
|
||||
Assert.assertEquals(1, policy2.getNumSignaturesRequired());
|
||||
|
||||
Policy policy3 = Policy.getPolicy(PolicyType.SINGLE, ScriptType.P2WPKH, List.of(keystore1), 1);
|
||||
Assert.assertEquals("wpkh(keystore1)", policy3.getMiniscript().toString().toLowerCase());
|
||||
Assert.assertEquals("wpkh(keystore1)", policy3.getMiniscript().toString().toLowerCase(Locale.ROOT));
|
||||
Assert.assertEquals(1, policy3.getNumSignaturesRequired());
|
||||
|
||||
Policy policy4 = Policy.getPolicy(PolicyType.MULTI, ScriptType.P2SH, List.of(keystore1, keystore2, keystore3), 2);
|
||||
Assert.assertEquals("sh(sortedmulti(2,keystore1,keystore2,keystore3))", policy4.getMiniscript().toString().toLowerCase());
|
||||
Assert.assertEquals("sh(sortedmulti(2,keystore1,keystore2,keystore3))", policy4.getMiniscript().toString().toLowerCase(Locale.ROOT));
|
||||
Assert.assertEquals(2, policy4.getNumSignaturesRequired());
|
||||
|
||||
Policy policy5 = Policy.getPolicy(PolicyType.MULTI, ScriptType.P2SH_P2WSH, List.of(keystore1, keystore2, keystore3), 2);
|
||||
Assert.assertEquals("sh(wsh(sortedmulti(2,keystore1,keystore2,keystore3)))", policy5.getMiniscript().toString().toLowerCase());
|
||||
Assert.assertEquals("sh(wsh(sortedmulti(2,keystore1,keystore2,keystore3)))", policy5.getMiniscript().toString().toLowerCase(Locale.ROOT));
|
||||
Assert.assertEquals(2, policy5.getNumSignaturesRequired());
|
||||
|
||||
Policy policy6 = Policy.getPolicy(PolicyType.MULTI, ScriptType.P2WSH, List.of(keystore1, keystore2, keystore3), 2);
|
||||
Assert.assertEquals("wsh(sortedmulti(2,keystore1,keystore2,keystore3))", policy6.getMiniscript().toString().toLowerCase());
|
||||
Assert.assertEquals("wsh(sortedmulti(2,keystore1,keystore2,keystore3))", policy6.getMiniscript().toString().toLowerCase(Locale.ROOT));
|
||||
Assert.assertEquals(2, policy6.getNumSignaturesRequired());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue