mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-12-27 02:26:44 +00:00
minor bip39 fixes
This commit is contained in:
parent
d394c25a3c
commit
be0c4d1176
3 changed files with 17 additions and 3 deletions
|
@ -11,7 +11,7 @@ import java.text.Normalizer;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class Bip39Calculator {
|
public class Bip39Calculator {
|
||||||
private Map<String, Integer> wordlistIndex;
|
private static Map<String, Integer> wordlistIndex;
|
||||||
|
|
||||||
public byte[] getSeed(List<String> mnemonicWords, String passphrase) {
|
public byte[] getSeed(List<String> mnemonicWords, String passphrase) {
|
||||||
loadWordlistIndex();
|
loadWordlistIndex();
|
||||||
|
@ -85,7 +85,7 @@ public class Bip39Calculator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadWordlistIndex() {
|
private synchronized void loadWordlistIndex() {
|
||||||
if(wordlistIndex == null) {
|
if(wordlistIndex == null) {
|
||||||
wordlistIndex = new HashMap<>();
|
wordlistIndex = new HashMap<>();
|
||||||
|
|
||||||
|
@ -100,4 +100,9 @@ public class Bip39Calculator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getWordList() {
|
||||||
|
loadWordlistIndex();
|
||||||
|
return Collections.unmodifiableList(new ArrayList<>(wordlistIndex.keySet()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package com.sparrowwallet.drongo.wallet;
|
package com.sparrowwallet.drongo.wallet;
|
||||||
|
|
||||||
public enum WalletModel {
|
public enum WalletModel {
|
||||||
SPARROW, BITCOIN_CORE, ELECTRUM, TREZOR_1, TREZOR_T, COLDCARD, LEDGER, DIGITALBITBOX, KEEPKEY;
|
SEED, SPARROW, BITCOIN_CORE, ELECTRUM, TREZOR_1, TREZOR_T, COLDCARD, LEDGER, DIGITALBITBOX, KEEPKEY;
|
||||||
|
|
||||||
public static WalletModel getModel(String model) {
|
public static WalletModel getModel(String model) {
|
||||||
return valueOf(model.toUpperCase());
|
return valueOf(model.toUpperCase());
|
||||||
|
|
|
@ -19,6 +19,15 @@ public class Bip39CalculatorTest {
|
||||||
Assert.assertEquals("727ecfcf0bce9d8ec0ef066f7aeb845c271bdd4ee06a37398cebd40dc810140bb620b6c10a8ad671afdceaf37aa55d92d6478f747e8b92430dd938ab5be961dd", Utils.bytesToHex(seed));
|
Assert.assertEquals("727ecfcf0bce9d8ec0ef066f7aeb845c271bdd4ee06a37398cebd40dc810140bb620b6c10a8ad671afdceaf37aa55d92d6478f747e8b92430dd938ab5be961dd", Utils.bytesToHex(seed));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void bip39TwelveWordsInvalidTest() {
|
||||||
|
String words = "absent absent absent absent absent absent absent absent absent absent absent absent";
|
||||||
|
List<String> wordlist = Arrays.asList(words.split(" "));
|
||||||
|
|
||||||
|
Bip39Calculator bip39Calculator = new Bip39Calculator();
|
||||||
|
byte[] seed = bip39Calculator.getSeed(wordlist, "");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bip39TwelveWordsPassphraseTest() {
|
public void bip39TwelveWordsPassphraseTest() {
|
||||||
String words = "arch easily near social civil image seminar monkey engine party promote turtle";
|
String words = "arch easily near social civil image seminar monkey engine party promote turtle";
|
||||||
|
|
Loading…
Reference in a new issue