mirror of
https://github.com/bitcoin/bips.git
synced 2026-10-19 19:29:18 +00:00
bip-0352: do not require the optional expected argument
create_outputs and scanning declare expected with a default of None but dereference it unconditionally (expected.get(...)), so calling either without it raises AttributeError, although the parameter is documented optional. Guard the expected-value checks with `if expected is not None:`. The self-test, which always passes expected, is unaffected.
This commit is contained in:
@@ -137,6 +137,7 @@ def create_outputs(input_priv_keys: List[Tuple[Scalar, bool]], outpoints: List[C
|
|||||||
if a_sum == 0:
|
if a_sum == 0:
|
||||||
# Input privkeys sum is zero -> fail
|
# Input privkeys sum is zero -> fail
|
||||||
return []
|
return []
|
||||||
|
if expected is not None:
|
||||||
assert Scalar.from_bytes_checked(bytes.fromhex(expected.get("input_private_key_sum"))) == a_sum, "a_sum did not match expected input_private_key_sum"
|
assert Scalar.from_bytes_checked(bytes.fromhex(expected.get("input_private_key_sum"))) == a_sum, "a_sum did not match expected input_private_key_sum"
|
||||||
input_hash_scalar = Scalar.from_bytes_checked(get_input_hash(outpoints, a_sum * G))
|
input_hash_scalar = Scalar.from_bytes_checked(get_input_hash(outpoints, a_sum * G))
|
||||||
silent_payment_groups: Dict[GE, List[GE]] = {}
|
silent_payment_groups: Dict[GE, List[GE]] = {}
|
||||||
@@ -159,6 +160,7 @@ def create_outputs(input_priv_keys: List[Tuple[Scalar, bool]], outpoints: List[C
|
|||||||
outputs = []
|
outputs = []
|
||||||
for B_scan, B_m_values in silent_payment_groups.items():
|
for B_scan, B_m_values in silent_payment_groups.items():
|
||||||
ecdh_shared_secret = input_hash_scalar * a_sum * B_scan
|
ecdh_shared_secret = input_hash_scalar * a_sum * B_scan
|
||||||
|
if expected is not None:
|
||||||
expected_shared_secrets = expected.get("shared_secrets", {})
|
expected_shared_secrets = expected.get("shared_secrets", {})
|
||||||
# Find the recipient address that corresponds to this B_scan and get its index
|
# Find the recipient address that corresponds to this B_scan and get its index
|
||||||
for recipient_idx, recipient in enumerate(recipients):
|
for recipient_idx, recipient in enumerate(recipients):
|
||||||
@@ -180,8 +182,9 @@ def create_outputs(input_priv_keys: List[Tuple[Scalar, bool]], outpoints: List[C
|
|||||||
def scanning(b_scan: Scalar, B_spend: GE, A_sum: GE, input_hash: bytes, outputs_to_check: List[bytes], labels: Dict[str, str] = None, expected: Dict[str, Any] = None) -> List[Dict[str, str]]:
|
def scanning(b_scan: Scalar, B_spend: GE, A_sum: GE, input_hash: bytes, outputs_to_check: List[bytes], labels: Dict[str, str] = None, expected: Dict[str, Any] = None) -> List[Dict[str, str]]:
|
||||||
input_hash_scalar = Scalar.from_bytes_checked(input_hash)
|
input_hash_scalar = Scalar.from_bytes_checked(input_hash)
|
||||||
computed_tweak_point = input_hash_scalar * A_sum
|
computed_tweak_point = input_hash_scalar * A_sum
|
||||||
assert computed_tweak_point.to_bytes_compressed().hex() == expected.get("tweak"), "tweak did not match expected"
|
|
||||||
ecdh_shared_secret = input_hash_scalar * b_scan * A_sum
|
ecdh_shared_secret = input_hash_scalar * b_scan * A_sum
|
||||||
|
if expected is not None:
|
||||||
|
assert computed_tweak_point.to_bytes_compressed().hex() == expected.get("tweak"), "tweak did not match expected"
|
||||||
assert ecdh_shared_secret.to_bytes_compressed().hex() == expected.get("shared_secret"), "ecdh_shared_secret did not match expected shared_secret"
|
assert ecdh_shared_secret.to_bytes_compressed().hex() == expected.get("shared_secret"), "ecdh_shared_secret did not match expected shared_secret"
|
||||||
k = 0
|
k = 0
|
||||||
wallet = []
|
wallet = []
|
||||||
|
|||||||
Reference in New Issue
Block a user