This commit is contained in:
scgbckbone 2024-10-10 21:44:26 +02:00
parent 00d8c841f7
commit 9761c65614
3 changed files with 14 additions and 14 deletions

View File

@ -792,7 +792,6 @@ class ApproveTransaction(UserAuthorizedAction):
# Prompt user w/ details and get approval
from glob import dis, hsm_active
from ccc import CCCFeature
from exceptions import CCCPolicyViolationError
# step 1: parse PSBT from PSRAM into in-memory objects.
@ -847,7 +846,7 @@ class ApproveTransaction(UserAuthorizedAction):
# early test for spending policy; not an error if violates policy
# - might add warnings
could_ccc_sign, needs_2fa = CCCFeature.could_sign(self.psbt)
could_ccc_sign, needs_2fa = await CCCFeature.could_sign(self.psbt)
# step 2: figure out what we are approving, so we can get sign-off
# - outputs, amounts

View File

@ -126,10 +126,10 @@ class CCCFeature:
@classmethod
def could_sign(cls, psbt):
async def could_sign(cls, psbt):
# We are looking at a PSBT: can we sign it, and would we?
# - if we **could** but will not, due to policy, add warning msg
# - return (we could sign, needs2fa step)
# - return (we could sign, needs 2fa step)
if not cls.is_enabled:
return False, False
@ -139,15 +139,15 @@ class CCCFeature:
return False, False
xfp = cls.get_xfp()
if (xfp not in ms.xfp_paths):
if xfp not in ms.xfp_paths:
# does not involve us
return False, False
try:
# check policy
needs_2fa = cls.meets_policy(psbt)
except CCCPolicyViolationError:
psbt.warning.append(('CCC', "Violates spending policy. Won't sign."))
needs_2fa = await cls.meets_policy(psbt)
except CCCPolicyViolationError as e:
psbt.warnings.append(('CCC', "Violates spending policy - %s. Won't sign." % e))
return False, False
return True, needs_2fa

View File

@ -372,13 +372,14 @@ def test_ccc_cosign(setup_ccc, enter_enabled_ccc, ccc_ms_setup, fake_ms_txn, sta
psbt = psbt_resp.get("psbt")
start_sign(base64.b64decode(psbt))
time.sleep(.1)
title, story = cap_story()
assert 'OK TO SEND?' == title
if not magnitude_ok:
time.sleep(.1)
title, story = cap_story()
assert "Policy Violation" == title
assert "magnitude" in story
assert "sign with A key" in story
press_select()
assert "(1 warning below)" in story
assert "CCC: Violates spending policy - magnitude. Won't sign." in story
else:
assert "warning" not in story
signed = end_sign(accept=True)
po = BasicPSBT().parse(signed)