def worst_case_policy(): MAX_NUMBER_USERS = 30 # from shared/users.py from helpers import prandom from base64 import b32encode users = { f'user{i:02d}': [1, b32encode(prandom(10)).decode('ascii'), 0] for i in range(MAX_NUMBER_USERS) } paths = [f'm/{i}p/{i+3}' for i in range(10)] addrs = [render_address(b'\x00\x14' + prandom(20)) for i in range(5)] p = DICT(period=30, share_xpubs=paths, share_addrs=paths + ['p2sh'], msg_paths=paths, warnings_ok=False, must_log=True) p.rules = [ dict(local_conf=True, whitelist=addrs, users=list(users.keys()), min_users=rn + 3, max_amount=int(1E10), per_period=int(1E10), wallet='1') for rn in range(3) ] return users, p
def web_cookup(proposed): # converse of above: take Coldcard policy file, and rework it so # Vue can display on webpage p = ObjectStruct.promote(proposed) def unlist(n): if not n: return '' return ','.join(n) for fn in ['msg_paths', 'share_xpubs', 'share_addrs']: p[fn] = unlist(p.get(fn)) for rule in p.rules: for fn in ['whitelist', 'users']: rule[fn] = unlist(rule.get(fn)) for fn in ['per_period', 'max_amount']: if rule[fn] is not None: rule[fn] = str(Decimal(rule[fn]) / Decimal('1E8')) if 'min_users' not in rule: rule.min_users = 'all' else: rule.min_users = str(rule.min_users) if ('boot_to_hsm' in p) and p.boot_to_hsm and invalid_pincode( p.boot_to_hsm): p.ewaste_enable = True else: p.ewaste_enable = False return p
def default_context(): # # Put values you want in every template here. They cannot vary per-request. # rv = ObjectStruct(VERSION=VERSION) # this defines the nav menu in top bar rv.PAGES = [ ('/', 'Sign Transaction'), ('/tools', 'Tools'), ('/setup', 'Coldcard Setup'), ('/bunker', 'Bunker Setup'), #('/help', 'Help') ] rv['zip'] = zip return rv
def reset_pending_auth(self): # clear and setup pending auth list from persist import BP # make a list of users that might need to auth ul = self.hsm.get('users') if not ul: if BP.get('policy'): ul = set() try: for r in BP['policy']['rules']: ul.union(r.users) except KeyError: pass ul = list(sorted(ul)) # they might have picked privacy over UX, so provide some "slots" # regardless of above. if not ul: ul = ['' for i in range(5)] # construct an obj for UX purposes, but keep the actual secrets separate self.pending_auth = [ObjectStruct(name=n, has_name=bool(n), has_guess='', totp=0) for n in ul] self._auth_guess = [None]*len(ul)