minor bip39 fixes

This commit is contained in:
Craig Raw 2020-05-08 14:36:29 +02:00
parent d394c25a3c
commit be0c4d1176
3 changed files with 17 additions and 3 deletions

View file

@ -11,7 +11,7 @@ import java.text.Normalizer;
import java.util.*;
public class Bip39Calculator {
private Map<String, Integer> wordlistIndex;
private static Map<String, Integer> wordlistIndex;
public byte[] getSeed(List<String> mnemonicWords, String passphrase) {
loadWordlistIndex();
@ -85,7 +85,7 @@ public class Bip39Calculator {
}
}
private void loadWordlistIndex() {
private synchronized void loadWordlistIndex() {
if(wordlistIndex == null) {
wordlistIndex = new HashMap<>();
@ -100,4 +100,9 @@ public class Bip39Calculator {
}
}
}
public List<String> getWordList() {
loadWordlistIndex();
return Collections.unmodifiableList(new ArrayList<>(wordlistIndex.keySet()));
}
}

View file

@ -1,7 +1,7 @@
package com.sparrowwallet.drongo.wallet;
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) {
return valueOf(model.toUpperCase());

View file

@ -19,6 +19,15 @@ public class Bip39CalculatorTest {
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
public void bip39TwelveWordsPassphraseTest() {
String words = "arch easily near social civil image seminar monkey engine party promote turtle";