BSMS (BIP-129)

This reverts commit e4e1844f
This commit is contained in:
scgbckbone 2023-05-08 21:01:48 +02:00 committed by doc-hex
parent 2749bc00fb
commit c7762eedf2
6 changed files with 2860 additions and 4 deletions

View File

@ -1389,10 +1389,11 @@ def usb_show_address(addr_format, subpath):
class NewEnrollRequest(UserAuthorizedAction):
def __init__(self, ms, auto_export=False):
def __init__(self, ms, auto_export=False, bsms_index=None):
super().__init__()
self.wallet = ms
self.auto_export = auto_export
self.bsms_index = bsms_index
# self.result ... will be re-serialized xpub
@ -1404,6 +1405,10 @@ class NewEnrollRequest(UserAuthorizedAction):
ch = await ms.confirm_import()
if ch == 'y':
if self.bsms_index is not None:
# remove signer round 2 from settings after multisig import is approved by user
from bsms import BSMSSettings
BSMSSettings.signer_delete(self.bsms_index)
if self.auto_export:
# save cosigner details now too
await ms.export_wallet_file('created on',
@ -1422,9 +1427,22 @@ class NewEnrollRequest(UserAuthorizedAction):
sys.print_exception(exc)
finally:
UserAuthorizedAction.cleanup() # because no results to store
self.pop_menu()
if self.bsms_index is not None:
# bsms special case, get him back to multisig menu
from ux import the_ux, restore_menu
from multisig import MultisigMenu
while 1:
top = the_ux.top_of_stack()
if not top: break
if not isinstance(top, MultisigMenu):
the_ux.pop()
continue
break
restore_menu()
else:
self.pop_menu()
def maybe_enroll_xpub(sf_len=None, config=None, name=None, ux_reset=False):
def maybe_enroll_xpub(sf_len=None, config=None, name=None, ux_reset=False, bsms_index=None):
# Offer to import (enroll) a new multisig wallet. Allow reject by user.
from multisig import MultisigWallet
@ -1438,7 +1456,7 @@ def maybe_enroll_xpub(sf_len=None, config=None, name=None, ux_reset=False):
# and be shown on screen/over usb
ms = MultisigWallet.from_file(config, name=name)
UserAuthorizedAction.active_request = NewEnrollRequest(ms)
UserAuthorizedAction.active_request = NewEnrollRequest(ms, bsms_index=bsms_index)
if ux_reset:
# for USB case, and import from PSBT

1095
shared/bsms.py Normal file

File diff suppressed because it is too large Load Diff

View File

@ -6,6 +6,7 @@ freeze_as_mpy('', [
'address_explorer.py',
'auth.py',
'backups.py',
'bsms.py',
'callgate.py',
'chains.py',
'choosers.py',

View File

@ -1238,6 +1238,7 @@ class MultisigMenu(MenuSystem):
@classmethod
def construct(cls):
# Dynamic menu with user-defined names of wallets shown
from bsms import make_ms_wallet_bsms_menu
if not MultisigWallet.exists():
rv = [MenuItem('(none setup yet)', f=no_ms_yet)]
@ -1250,6 +1251,7 @@ class MultisigMenu(MenuSystem):
rv.append(MenuItem('Import from File', f=import_multisig))
rv.append(MenuItem('Import via NFC', f=import_multisig_nfc, predicate=lambda: NFC is not None))
rv.append(MenuItem('Export XPUB', f=export_multisig_xpubs))
rv.append(MenuItem('BSMS (BIP-129)', menu=make_ms_wallet_bsms_menu))
rv.append(MenuItem('Create Airgapped', f=create_ms_step1))
rv.append(MenuItem('Trust PSBT?', f=trust_psbt_menu))
rv.append(MenuItem('Skip Checks?', f=disable_checks_menu))

View File

@ -739,4 +739,54 @@ class NFCHandler:
return winner
async def read_bsms_token(self):
data = await self.start_nfc_rx()
if not data:
await ux_show_story('Unable to find data expected in NDEF')
return
winner = None
for urn, msg, meta in ndef.record_parser(data):
msg = bytes(msg).decode().strip() # from memory view
try:
int(msg, 16)
winner = msg
break
except: pass
if not winner:
await ux_show_story('Unable to find BSMS token in NDEF data')
return
return winner
async def read_bsms_data(self):
data = await self.start_nfc_rx()
if not data:
await ux_show_story('Unable to find data expected in NDEF')
return
winner = None
for urn, msg, meta in ndef.record_parser(data):
msg = bytes(msg).decode().strip() # from memory view
try:
if "BSMS" in msg:
# unencrypted case
winner = msg
break
elif int(msg[:6], 16):
# encrypted hex case
winner = msg
break
else:
continue
except: pass
if not winner:
await ux_show_story('Unable to find BSMS data in NDEF data')
return
return winner
# EOF

1690
testing/test_bsms.py Normal file

File diff suppressed because it is too large Load Diff