async def test_ae508a(): assert not get_is_bricked(), "AE508a is bricked" for ph in range(5): gg = get_genuine() dis.clear() if gg: dis.text(-1, 8, "Green ON? -->") else: dis.text(-1, 50, "Red ON? -->") dis.show() k = await ux_wait_keyup('xy') assert k == 'y', "LED bust" if ph and gg: # stop once it's on and we've tested both states return # attempt to switch to other state if gg: clear_genuine() else: # very slow! dis.text(0, 0, "Wait") dis.show() set_genuine() ux_clear_keys() ng = get_genuine() assert ng != gg, "Could not invert LED"
async def failure(self, msg, exc=None, title='Failure'): self.failed = msg self.done() # show line number and/or simple text about error if exc: print("%s:" % msg) sys.print_exception(exc) msg += '\n\n' em = str(exc) if em: msg += em msg += '\n\n' msg += problem_file_line(exc) from main import hsm_active, dis # do nothing more for HSM case: msg will be available over USB if hsm_active: dis.progress_bar(1) # finish the Validating... or whatever was up return # may be a user-abort waiting, but we want to see error msg; so clear it ux_clear_keys(True) return await ux_show_story(msg, title)
async def failure(self, msg, exc=None, title='Failure'): self.failed = msg self.done() if exc: print("%s:" % msg) sys.print_exception(exc) msg += "\n\n(%s)" % problem_file_line(exc) # may be a user-abort waiting, but we want to see error msg; so clear it ux_clear_keys(True) return await ux_show_story(msg, title)
async def test_secure_element(): assert not get_is_bricked() # bricked already # test right chips installed is_fat = ckcc.is_stm32l496() if is_fat: assert version.has_608 # expect 608a assert version.hw_label == 'mk3' else: assert not version.has_608 # expect 508a assert version.hw_label != 'mk3' if ckcc.is_simulator(): return for ph in range(5): gg = get_genuine() dis.clear() if gg: dis.text(-1, 8, "Green ON? -->") else: dis.text(-1,50, "Red ON? -->") dis.show() k = await ux_wait_keyup('xy') assert k == 'y' # "LED bust" if ph and gg: # stop once it's on and we've tested both states return # attempt to switch to other state if gg: clear_genuine() else: # very slow! dis.text(0,0, "Wait") dis.show() set_genuine() ux_clear_keys() ng = get_genuine() assert ng != gg # "Could not invert LED"
async def confirm_import(self): # prompt them about a new wallet, let them see details and then commit change. M, N = self.M, self.N if M == N == 1: exp = 'The one signer must approve spends.' if M == N: exp = 'All %d co-signers must approve spends.' % N elif M == 1: exp = 'Any signature from %d co-signers will approve spends.' % N else: exp = '{M} signatures, from {N} possible co-signers, will be required to approve spends.'.format( M=M, N=N) # Look for duplicate case. is_dup, diff_count = self.has_dup() if not is_dup: story = 'Create new multisig wallet?' elif diff_count: story = '''\ CAUTION: This updated wallet has %d different XPUB values, but matching fingerprints \ and same M of N. Perhaps the derivation path has changed legitimately, otherwise, much \ DANGER!''' % diff_count else: story = 'Update existing multisig wallet?' story += '''\n Wallet Name: {name} Policy: {M} of {N} {exp} Derivation: m/{deriv} Press (1) to see extended public keys, \ OK to approve, X to cancel.'''.format(M=M, N=N, name=self.name, exp=exp, deriv=self.common_prefix or 'unknown') ux_clear_keys(True) while 1: ch = await ux_show_story(story, escape='1') if ch == '1': # Show the xpubs; might be 2k or more rendered. msg = uio.StringIO() for idx, (xfp, xpub) in enumerate(self.xpubs): if idx: msg.write('\n\n') # Not showing index numbers here because order # is non-deterministic both here, our storage, and in usage. msg.write('%s:\n%s' % (xfp2str(xfp), xpub)) await ux_show_story(msg, title='%d of %d' % (self.M, self.N)) continue if ch == 'y': # save to nvram, may raise MultisigOutOfSpace if is_dup: is_dup.delete() self.commit() await ux_dramatic_pause("Saved.", 2) break return ch
async def confirm_import(self): # prompt them about a new wallet, let them see details and then commit change. M, N = self.M, self.N if M == N == 1: exp = 'The one signer must approve spends.' if M == N: exp = 'All %d co-signers must approve spends.' % N elif M == 1: exp = 'Any signature from %d co-signers will approve spends.' % N else: exp = '{M} signatures, from {N} possible co-signers, will be required to approve spends.'.format(M=M, N=N) # Look for duplicate stuff name_change, diff_items, num_dups = self.has_similar() is_dup = False if name_change: story = 'Update NAME only of existing multisig wallet?' elif diff_items: # Concern here is overwrite when similar, but we don't overwrite anymore, so # more of a warning about funny business. story = '''\ WARNING: This new wallet is similar to an existing wallet, but will NOT replace it. Consider deleting previous wallet first. Differences: \ ''' + ', '.join(diff_items) elif num_dups: story = 'Duplicate wallet. All details are the same as existing!' is_dup = True else: story = 'Create new multisig wallet?' derivs, dsum = self.get_deriv_paths() story += '''\n Wallet Name: {name} Policy: {M} of {N} {exp} Addresses: {at} Derivation: {dsum} Press (1) to see extended public keys, '''.format(M=M, N=N, name=self.name, exp=exp, dsum=dsum, at=self.render_addr_fmt(self.addr_fmt)) story += 'OK to approve, X to cancel.' if not is_dup else 'X to cancel' ux_clear_keys(True) while 1: ch = await ux_show_story(story, escape='1') if ch == '1': await self.show_detail(verbose=False) continue if ch == 'y' and not is_dup: # save to nvram, may raise MultisigOutOfSpace if name_change: name_change.delete() assert self.storage_idx == -1 self.commit() await ux_dramatic_pause("Saved.", 2) break return ch