|
13 | 13 | import PySimpleGUI as sg |
14 | 14 |
|
15 | 15 | from ..api import Account, create, group_parser, random_secret, cryptopaths_parser, paper_wallet_available |
16 | | -from ..recovery import recover, recover_bip39, produce_bip39, analyze_entropy |
17 | | -from ..util import log_level, log_cfg, ordinal, chunker, hue_shift |
| 16 | +from ..recovery import recover, recover_bip39, produce_bip39, scan_entropy, display_entropy |
| 17 | +from ..util import log_level, log_cfg, ordinal, chunker, hue_shift, rate_dB |
18 | 18 | from ..layout import write_pdfs, printers_available |
19 | 19 | from ..defaults import ( |
20 | 20 | GROUPS, GROUP_THRESHOLD_RATIO, MNEM_PREFIX, CRYPTO_PATHS, BITS, BITS_DEFAULT, |
|
34 | 34 | " earth warn lunar olympic clothes piece campus alpha short endless" |
35 | 35 |
|
36 | 36 |
|
| 37 | +SD_SEED_FRAME = 'Seed Source: Input or Create your Seed Entropy here' |
| 38 | + |
| 39 | + |
37 | 40 | def theme_color( thing, theme=None ): |
38 | 41 | """Get the currency configured PySimpleGUI Theme color for thing == eg. "TEXT", "BACKGROUND. |
39 | 42 | """ |
@@ -211,7 +214,7 @@ def groups_layout( |
211 | 214 | ] + [ |
212 | 215 | [ |
213 | 216 | # SLIP-39 only available in Recovery; SLIP-39 Passphrase only in Pro; BIP-39 and Fixed Hex only in Pro |
214 | | - sg.Frame( 'Seed Source: Input or Create your Seed Entropy here', [ |
| 217 | + sg.Frame( SD_SEED_FRAME, [ |
215 | 218 | [ |
216 | 219 | sg.Text( "Random:" if not LO_BAK else "Source:", visible=LO_CRE, **T_hue( T_kwds, 0/20 )), |
217 | 220 | sg.Radio( "128-bit", "SD", key='-SD-128-RND-', default=LO_CRE, |
@@ -458,6 +461,7 @@ def update_seed_data( event, window, values ): |
458 | 461 | restores our last-known radio button and data. Since we cannot know if/when our main window is |
459 | 462 | going to disappear and be replaced, we constantly save the current state. |
460 | 463 |
|
| 464 | + Reports the quality of the Seed Data in the frame label. |
461 | 465 | """ |
462 | 466 | SD_CONTROLS = [ |
463 | 467 | '-SD-128-RND-', |
@@ -615,14 +619,18 @@ def update_seed_data( event, window, values ): |
615 | 619 |
|
616 | 620 | # Analyze the seed for Signal harmonic or Shannon entropy failures, if we're in a __TIMEOUT__ |
617 | 621 | # (between keystrokes or after a major controls change). Otherwise, if the seed's changed, |
618 | | - # request a __TIMEOUT__; when it, perform the entropy analysis. |
619 | | - values['-SD-SIG-'] = '' |
| 622 | + # request a __TIMEOUT__; when it invokes, perform the entropy analysis. |
| 623 | + values['-SD-SIGS-'] = '' |
| 624 | + |
620 | 625 | if status is None and event == '__TIMEOUT__': |
621 | 626 | seed_bytes = codecs.decode( seed, 'hex_codec' ) |
622 | | - analysis = analyze_entropy( seed_bytes, what=f"{len(seed_bytes)*8}-bit Seed Source", show_details=False ) |
| 627 | + signals, shannons = scan_entropy( seed_bytes, show_details=True ) |
| 628 | + analysis = display_entropy( signals, shannons, what=f"{len(seed_bytes)*8}-bit Seed Source" ) |
623 | 629 | if analysis: |
624 | 630 | values['-SD-SIG-'] = analysis |
625 | 631 | status = analysis.split( '\n' )[0] |
| 632 | + window['-SD-SEED-F-'].update( |
| 633 | + f"{SD_SEED_FRAME}; {rate_dB( max( signals ).dB, what='Harmonics')}, {rate_dB( max( signals ).dB, what='Shannon')}, " ) |
626 | 634 | elif changed: |
627 | 635 | log.info( f"Seed Data requests __TIMEOUT__ w/ current source: {update_seed_data.src!r}" ) |
628 | 636 | values['__TIMEOUT__'] = .5 |
@@ -1001,7 +1009,7 @@ def app( |
1001 | 1009 | # specific instructional .txt we can load. Only if the current instructions is empty will |
1002 | 1010 | # we go all the way back to load the generic SLIP-39.txt. If the event corresponds to an |
1003 | 1011 | # object with text/backround_color, use it in the instructional text. |
1004 | | - txt_segs = ( event or '' ).strip('-').split( '-' ) |
| 1012 | + txt_segs = ( event or '' ).strip( '-' ).split( '-' ) |
1005 | 1013 | for txt_i in range( len( txt_segs ), 0 if instructions else -1, -1 ): |
1006 | 1014 | txt_name = '-'.join( [ 'SLIP', '39' ] + txt_segs[:txt_i] ) + '.txt' |
1007 | 1015 | txt_path = os.path.join( os.path.dirname( __file__ ), txt_name ) |
|
0 commit comments