Skip to content

Commit

Permalink
simplify hash lock signature check
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Sep 22, 2023
1 parent 600c288 commit 17fa6f1
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions cashu/mint/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 17fa6f1

Please sign in to comment.