Skip to content

Commit

Permalink
safer check for P2PK secrets for SIG_ALL
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Oct 22, 2024
1 parent ad3e3e9 commit b986db2
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions cashu/wallet/p2pk.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ def sign_proofs(self, proofs: List[Proof]) -> List[str]:
return signatures

def sign_outputs(self, outputs: List[BlindedMessage]) -> List[str]:
assert (
self.private_key
), "No private key set in settings. Set NOSTR_PRIVATE_KEY in .env"
private_key = self.private_key
assert private_key.pubkey
return [
Expand Down Expand Up @@ -132,15 +129,16 @@ def add_witnesses_to_outputs(
# first we check whether all tokens have serialized secrets as their secret
try:
for p in proofs:
Secret.deserialize(p.secret)
secret = Secret.deserialize(p.secret)
except Exception:
# if not, we do not add witnesses (treat as regular token secret)
return outputs

# if any of the proofs provided require SIG_ALL, we must provide it
# if any of the proofs provided is P2PK and requires SIG_ALL, we must signatures to all outputs
if any(
[
P2PKSecret.deserialize(p.secret).sigflag == SigFlags.SIG_ALL
secret.kind == SecretKind.P2PK.value
and P2PKSecret.deserialize(p.secret).sigflag == SigFlags.SIG_ALL
for p in proofs
]
):
Expand Down

0 comments on commit b986db2

Please sign in to comment.