From 17fa6f1112a66f74f979093e1a0f68ecc3dda27c Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Fri, 22 Sep 2023 16:33:42 +0200 Subject: [PATCH] simplify hash lock signature check --- cashu/mint/conditions.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/cashu/mint/conditions.py b/cashu/mint/conditions.py index 830489c5..b3425c9e 100644 --- a/cashu/mint/conditions.py +++ b/cashu/mint/conditions.py @@ -175,20 +175,20 @@ def _verify_input_spending_conditions(self, proof: Proof) -> bool: # then we check whether a signature is required hashlock_pubkeys = htlc_secret.tags.get_tag_all("pubkeys") - if hashlock_pubkeys and not proof.htlcsignature: - # none of the pubkeys had a match - raise TransactionError("HTLC no hash lock signatures provided.") - for pubkey in hashlock_pubkeys: - if verify_p2pk_signature( - message=htlc_secret.serialize().encode("utf-8"), - pubkey=PublicKey(bytes.fromhex(pubkey), raw=True), - signature=bytes.fromhex(proof.htlcsignature), - ): - # a signature matches - return True if hashlock_pubkeys: - # none of the pubkeys had a match - raise TransactionError("HTLC hash lock signatures did not match.") + assert proof.htlcsignature, TransactionError( + "HTLC no hash lock signatures provided." + ) + for pubkey in hashlock_pubkeys: + if verify_p2pk_signature( + message=htlc_secret.serialize().encode("utf-8"), + pubkey=PublicKey(bytes.fromhex(pubkey), raw=True), + signature=bytes.fromhex(proof.htlcsignature), + ): + # a signature matches + return True + # none of the pubkeys had a match + raise TransactionError("HTLC hash lock signatures did not match.") # no pubkeys were included, anyone can spend return True