Skip to content

Commit c278c71

Browse files
committed
Fixed bip39 dictionary word lookup botch.
1 parent 4985089 commit c278c71

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
* Maybe update bc-crypto-base version.
1+
* Whitespace cleanup in userinterface.ino, also "1 2 3 4"
22

33
* Remove the ESP32 code from lethe.ino?
44

seedtool/selftest.ino

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,16 @@ bool test_bip39_generate() {
199199
Seed * seed = Seed::from_rolls("123456");
200200
BIP39Seq * bip39 = new BIP39Seq(seed);
201201
for (size_t ii = 0; ii < BIP39Seq::WORD_COUNT; ++ii) {
202-
if (bip39->get_word(ii) != ref_bip39_words_correct[ii])
202+
uint16_t word = bip39->get_word(ii);
203+
if (word != ref_bip39_words_correct[ii])
203204
return test_failed("test_bip39_generate failed: word mismatch\n");
205+
if (strcmp(BIP39Seq::get_dict_string(word).c_str(),
206+
ref_bip39_mnemonics[ii]) != 0)
207+
return test_failed("test_bip39_generate failed: "
208+
"dict_string mismatch\n");
204209
if (strcmp(bip39->get_string(ii).c_str(), ref_bip39_mnemonics[ii]) != 0)
205-
return test_failed("test_bip39_generate failed: mnemonic mismatch\n");
210+
return test_failed("test_bip39_generate failed: "
211+
"mnemonic mismatch\n");
206212
}
207213
delete bip39;
208214
delete seed;

seedtool/userinterface.ino

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ struct WordListState {
786786
free(wordndx);
787787
}
788788

789-
virtual char const * refword(int ndx) = 0;
789+
virtual String refword(int ndx) = 0;
790790

791791
void set_words(uint16_t const * wordlist) {
792792
for (int ii = 0; ii < nwords; ++ii)
@@ -829,7 +829,7 @@ struct WordListState {
829829
}
830830

831831
void cursor_right() {
832-
if (pos < (int)strlen(refword(wordndx[selected])) - 1)
832+
if (pos < (int)refword(wordndx[selected]).length() - 1)
833833
++pos;
834834
}
835835

@@ -868,7 +868,7 @@ struct WordListState {
868868
}
869869

870870
String prefix(int word) {
871-
return String(refword(word)).substring(0, pos);
871+
return refword(word).substring(0, pos);
872872
}
873873

874874
char current(int word) {
@@ -890,8 +890,8 @@ struct WordListState {
890890

891891
struct SLIP39WordlistState : WordListState {
892892
SLIP39WordlistState(int i_nwords) : WordListState(i_nwords, 1024) {}
893-
virtual char const * refword(int ndx) {
894-
return slip39_string_for_word(ndx);
893+
virtual String refword(int ndx) {
894+
return String(slip39_string_for_word(ndx));
895895
}
896896
};
897897

@@ -901,8 +901,8 @@ struct BIP39WordlistState : WordListState {
901901
: WordListState(i_nwords, 2048)
902902
, bip39(i_bip39)
903903
{}
904-
virtual char const * refword(int ndx) {
905-
return BIP39Seq::get_dict_string(ndx).c_str();
904+
virtual String refword(int ndx) {
905+
return BIP39Seq::get_dict_string(ndx);
906906
}
907907
};
908908

@@ -935,7 +935,7 @@ void restore_bip39() {
935935

936936
for (int rr = 0; rr < state.nrows; ++rr) {
937937
int wndx = state.scroll + rr;
938-
String word = String(state.refword(state.wordndx[wndx]));
938+
String word = state.refword(state.wordndx[wndx]);
939939
Serial.println(String(wndx) + " " + word);
940940

941941
if (wndx != state.selected) {
@@ -1256,7 +1256,7 @@ void enter_share() {
12561256

12571257
for (int rr = 0; rr < state.nrows; ++rr) {
12581258
int wndx = state.scroll + rr;
1259-
String word = String(state.refword(state.wordndx[wndx]));
1259+
String word = state.refword(state.wordndx[wndx]);
12601260
Serial.println(String(wndx) + " " + word);
12611261

12621262
if (wndx != state.selected) {

0 commit comments

Comments
 (0)