Mk4 SSSP Word Check

This commit is contained in:
scgbckbone 2025-08-22 15:23:30 +02:00 committed by Peter D. Gray
parent 6213e997b6
commit d316fa0124
No known key found for this signature in database
GPG Key ID: A2DCD558C2BE5D7C
2 changed files with 37 additions and 20 deletions

View File

@ -1121,15 +1121,15 @@ async def sssp_word_challenge(*a):
from stash import SensitiveValues
with SensitiveValues() as sv:
if sv.mode == 'words':
words = bip39.b2a_words(sv.raw).split(' ')
want_words = words[:1] + words[-1:]
assert len(want_words) == 2
else:
if sv.mode != 'words':
# they are using XPRV or something, skip test entirely
return
got_words = None
words = bip39.b2a_words(sv.raw).split(' ')
want_words = words[:1] + words[-1:]
assert len(want_words) == 2
got_words = []
for retry in range(2):
if version.has_qwerty:
# see special rendering code for this case in ux_q1.py:ux_draw_words(num_words=2)
@ -1137,23 +1137,14 @@ async def sssp_word_challenge(*a):
got_words = await seed_word_entry('First and Last Seed Words', 2, has_checksum=False)
else:
from seed import WordNestMenu
# TODO: fix bugs here on Mk4. really not working. XXX
got_words = None
async def check_challenge_cb(words):
WordNestMenu.pop_all()
got_words = words
m = WordNestMenu(num_words=2, has_checksum=False, done_cb=check_challenge_cb)
the_ux.push(m)
await m.interact()
got_words = await WordNestMenu.login_sequence_word_check()
if got_words == want_words:
# success - done
return
await ux_show_story("Sorry, those words are incorrect.")
got_words = []
# they failed; log them out ... they can just try login again
from actions import login_now

View File

@ -150,23 +150,49 @@ class WordNestMenu(MenuSystem):
done_cb = None
def __init__(self, num_words=None, has_checksum=True, done_cb=commit_new_words,
items=None, is_commit=False):
items=None, is_commit=False, menu_cbf=None, prefix=""):
if num_words is not None:
WordNestMenu.target_words = num_words
WordNestMenu.has_checksum = has_checksum
WordNestMenu.words = []
assert done_cb
WordNestMenu.done_cb = done_cb
is_commit = True
if not items:
items = [MenuItem(i, menu=self.next_menu) for i in letter_choices()]
ch = letter_choices(prefix)
if menu_cbf:
items = [MenuItem(i, f=menu_cbf) for i in ch]
else:
items = [MenuItem(i, menu=self.next_menu) for i in ch]
self.is_commit = is_commit
super(WordNestMenu, self).__init__(items)
@classmethod
async def menu_done_cbf(cls, a, b, c):
if c.label[-1] == '-':
lc = c.label[0:-1]
else:
lc = ""
cls.words.append(c.label)
if len(cls.words) >= 2:
from glob import numpad
numpad.abort_ux()
return
m = cls(prefix=lc, menu_cbf=cls.menu_done_cbf)
the_ux.push(m)
await m.interact()
@classmethod
async def login_sequence_word_check(cls):
m = cls(num_words=2, menu_cbf=WordNestMenu.menu_done_cbf)
the_ux.push(m)
await the_ux.interact()
return cls.words
@staticmethod
async def next_menu(self, idx, choice):