Skip to content

Commit 6b7457d

Browse files
committed
Handle EOF on stdin in slip39-generator --receive
1 parent b5dad61 commit 6b7457d

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

README.org

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,8 @@ by entering the mnemonics right on the device.
516516
: 2: [["ETH", "m/44'/60'/0'/0/2", "0x578270B5E5B53336baC354756b763b309eCA90Ef"], ["BTC", "m/84'/0'/0'/0/2", "bc1qvr7e5aytd0hpmtaz2d443k364hprvqpm3lxr8w"]]
517517
: 3: [["ETH", "m/44'/60'/0'/0/3", "0x909f59835A5a120EafE1c60742485b7ff0e305da"], ["BTC", "m/84'/0'/0'/0/3", "bc1q6t9vhestkcfgw4nutnm8y2z49n30uhc0kyjl0d"]]
518518

519-
We can encrypt the output, to secure the sequence (and ensure no errors occur over an insecure channel like a serial cable):
519+
We can encrypt the output, to secure the sequence (and due to integrated MACs, ensures no errors
520+
occur over an insecure channel like a serial cable):
520521

521522
#+LATEX: {\scriptsize
522523
#+BEGIN_SRC bash :exports both :results raw
@@ -533,20 +534,20 @@ by entering the mnemonics right on the device.
533534
: 2: 279dcb069fe37f33547f0a2bc763f6d1852733b94686807ef5dbe854326fc1a6e1e097afa3a52be48f75bf6c821a3cdebd2f2be228dfa36b0e9787f4234170bdc835afd96767e26f7f11796f376e546fdb67810bbdacf957b7bdee64fbfdf85abaf72a6d8eeb9508828931674b3e3db386ca923c13a8298d4835462af6cb1141c8021d753d28a88254d9c3997457d705f705328ba7ff507266745417381a70b3344d20ad84
534535
: 3: 0a044f98e88fe4c038d86710e6d128e173d6f5a42ff95647dd894868b0bb5d323ce0a1754327241b2c85458c22640d3401c343cdd94869cc86f250384ae642c01822b0ba91aa4a6c4635cd9bcd8f47ecf4396445c3a9af93419f4bf6ff773fa19d67c5ac10d2bd4da63b94a2128921aafa93b0133271db50c7fc6657f850daf9396f16aa71f491b0f472512144d7b02b98e3a0a6c4153505b3f8999b24b55585225c020f92
535536

536-
On the receiving computer, we can decrypt and recover the stream of accounts from the wallet seed:
537+
On the receiving computer, we can decrypt and recover the stream of accounts from the wallet
538+
seed; any rows with errors are ignored:
537539
#+LATEX: {\scriptsize
538540
#+BEGIN_SRC bash :exports both :results raw
539541
slip39-recovery --bip39 --mnemonic 'zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong' \
540-
| slip39-generator --secret - --path '../-' --encrypt 'password' \
541-
| slip39-generator --receive --decrypt 'password' | head -3 | sed 's/^/: /' # (just so output formatting looks correct)
542+
| slip39-generator --secret - --path '../-3' --encrypt 'password' \
543+
| slip39-generator --receive --decrypt 'password' | sed 's/^/: /' # (just so output formatting looks correct)
542544
#+END_SRC
543545

544546
#+RESULTS:
545547
: 1: [["ETH", "m/44'/60'/0'/0/1", "0xd1a7451beB6FE0326b4B78e3909310880B781d66"], ["BTC", "m/84'/0'/0'/0/1", "bc1qkd33yck74lg0kaq4tdcmu3hk4yruhjayxpe9ug"]]
546548
: 2: [["ETH", "m/44'/60'/0'/0/2", "0x578270B5E5B53336baC354756b763b309eCA90Ef"], ["BTC", "m/84'/0'/0'/0/2", "bc1qvr7e5aytd0hpmtaz2d443k364hprvqpm3lxr8w"]]
547549
: 3: [["ETH", "m/44'/60'/0'/0/3", "0x909f59835A5a120EafE1c60742485b7ff0e305da"], ["BTC", "m/84'/0'/0'/0/3", "bc1q6t9vhestkcfgw4nutnm8y2z49n30uhc0kyjl0d"]]
548550

549-
550551
** The =slip39= module API
551552

552553
Provide SLIP-39 Mnemonic set creation from a 128-bit master secret, and recovery of the secret

requirements-dev.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1+
build
12
pip
3+
pytest
24
setuptools
35
wheel
4-
build

slip39/generator/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def accountgroups_input(
5656
nonce = None
5757
while True:
5858
# Attempt to receive a record, while connection is healthy
59+
health = True
5960
try:
6061
record = None
6162
while not record or not record.endswith( b'\n' if type(record) is bytes else '\n' ):
@@ -70,9 +71,13 @@ def accountgroups_input(
7071
record = recv
7172
else:
7273
record += recv
73-
except EOFError:
74+
else:
75+
raise EOFError( f"No input: {recv!r}" )
76+
except EOFError as exc:
7477
# Session has terminated; TODO: yield the EOFError to signal no more inputs (ever) available?
78+
log.debug( f"Detected EOF: {exc}" )
7579
return
80+
log.debug( f"Received I/O: {record}" )
7681
if not health:
7782
yield None,None
7883
continue

slip39/generator/main.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,14 @@ def healthy_reset( file ):
212212
if read:
213213
log.warning( f"{file!r:.36} {serial_status(*flow)}; Discarded {len(read)} input: {read!r:.32}{'...' if len(read) > 32 else ''}{read[-3:]!r}" )
214214

215-
# Continually attempt to receive records.
216-
while True:
217-
# Establish a session.
215+
# Continually attempt to receive records. If a file_opener is provided, we'll continue
216+
# indefinitely (eg. a Serial connection, which may present multiple connections and
217+
# disconnections.) However, the default (sys.stdin) only continues 'til the first EOF.
218+
first = True
219+
while first or file_opener:
220+
first = False
221+
222+
# (Re-)establish a session, if None established and a file_opener is provided.
218223
if file is None and file_opener:
219224
file = file_opener()
220225
if healthy_reset:

0 commit comments

Comments
 (0)