NFC key in prompt

This commit is contained in:
Peter D. Gray 2023-08-04 09:50:00 -04:00 committed by scgbckbone
parent a2268c6560
commit f3527e1960
3 changed files with 22 additions and 9 deletions

View File

@ -10,6 +10,7 @@ from ux import ux_show_story
from glob import settings
from auth import write_sig_file
from public_constants import AF_CLASSIC, AF_P2WPKH, AF_P2WPKH_P2SH, AF_P2WSH, AF_P2WSH_P2SH, AF_P2SH
from charcodes import KEY_NFC
def generate_public_contents():
@ -123,7 +124,7 @@ async def write_text_file(fname_pattern, body, title, derive, addr_fmt):
prompt, escape = export_prompt_builder("%s file" % title)
if prompt:
ch = await ux_show_story(prompt, escape=escape)
if ch == '3':
if ch in '3'+KEY_NFC:
await NFC.share_text(body)
return
elif ch == "2":
@ -434,7 +435,7 @@ async def make_json_wallet(label, func, fname_pattern='new-wallet.json'):
prompt, escape = export_prompt_builder("%s file" % label)
if prompt:
ch = await ux_show_story(prompt, escape=escape)
if ch == '3':
if ch in '3'+KEY_NFC:
await NFC.share_json(json_str)
return
elif ch == '2':

View File

@ -13,6 +13,7 @@ from menu import MenuSystem, MenuItem
from opcodes import OP_CHECKMULTISIG
from exceptions import FatalPSBTIssue
from glob import settings
from charcodes import KEY_NFC
# PSBT Xpub trust policies
@ -870,7 +871,7 @@ class MultisigWallet:
prompt, escape = export_prompt_builder("%s file" % label)
if prompt:
ch = await ux_show_story(prompt, escape=escape)
if ch == "3":
if ch in "3"+KEY_NFC:
with uio.StringIO() as fp:
self.render_export(fp, hdr_comment=hdr, descriptor=descriptor,
core=core, desc_pretty=desc_pretty)
@ -1442,7 +1443,7 @@ OK to continue. X to abort.'''.format(coin=chain.b44_cointype)
fp.write(' "account": "%d",\n' % acct_num)
fp.write(' "xfp": "%s"\n}\n' % xfp)
if NFC and ch == '3':
if NFC and ch in "3"+KEY_NFC:
with uio.StringIO() as fp:
render(fp)
await NFC.share_json(fp.getvalue())

View File

@ -8,6 +8,8 @@ from ubinascii import hexlify as b2a_hex
from ubinascii import a2b_base64, b2a_base64
from uhashlib import sha256
from public_constants import AF_CLASSIC, AF_P2WPKH, AF_P2WPKH_P2SH
from charcodes import KEY_NFC
from version import has_qwerty
B2A = lambda x: str(b2a_hex(x), 'ascii')
@ -66,7 +68,7 @@ def pretty_delay(n):
if n < 48:
return '%.1f hours' % n
n /= 24
return 'about %d days' % n
return 'about %.1f days' % n
def pretty_short_delay(sec):
# precise, shorter on screen display
@ -482,6 +484,7 @@ def parse_extended_key(ln, private=False):
def import_prompt_builder(title, no_nfc=False):
# TODO add has_qr check, and offer QR button (at least for short strings maybe add arg for that)
from glob import NFC, VD
prompt, escape = None, None
if (NFC and (not no_nfc)) or VD:
@ -491,8 +494,12 @@ def import_prompt_builder(title, no_nfc=False):
prompt += ", press (2) to import from Virtual Disk"
escape += "2"
if NFC is not None and not no_nfc:
prompt += ", press (3) to import via NFC"
escape += "3"
if has_qwerty:
prompt += ", press (nfc) to import via NFC"
escape += KEY_NFC
else:
prompt += ", press (3) to import via NFC"
escape += "3"
prompt += "."
return prompt, escape
@ -508,8 +515,12 @@ def export_prompt_builder(title):
prompt += ", press (2) to save to Virtual Disk"
escape += "2"
if NFC is not None:
prompt += ", press (3) to share via NFC"
escape += "3"
if has_qwerty:
prompt += ", press (nfc) to share via NFC"
escape += KEY_NFC
else:
prompt += ", press (3) to share via NFC"
escape += "3"
prompt += "."
return prompt, escape