Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test vector for NUT-12 #498

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion tests/test_crypto.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from cashu.core.base import Proof
from cashu.core.crypto.b_dhke import (
alice_verify_dleq,
carol_verify_dleq,
Expand Down Expand Up @@ -284,6 +285,10 @@ def test_dleq_carol_verify_from_bob():
)
A = a.pubkey
assert A
assert (
A.serialize().hex()
== "0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"
)
secret_msg = "test_message"
r = PrivateKey(
privkey=bytes.fromhex(
Expand All @@ -295,11 +300,42 @@ def test_dleq_carol_verify_from_bob():
C_, e, s = step2_bob(B_, a)
assert alice_verify_dleq(B_, C_, e, s, A)
C = step3_alice(C_, r, A)

# carol does not know B_ and C_, but she receives C and r from Alice
assert carol_verify_dleq(secret_msg=secret_msg, C=C, r=r, e=e, s=s, A=A)


def test_dleq_carol_on_proof():
A = PublicKey(
bytes.fromhex(
"0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"
),
raw=True,
)
proof = Proof.parse_obj(
{
"amount": 1,
"id": "00882760bfa2eb41",
"secret": "daf4dd00a2b68a0858a80450f52c8a7d2ccf87d375e43e216e0c571f089f63e9",
"C": "024369d2d22a80ecf78f3937da9d5f30c1b9f74f0c32684d583cca0fa6a61cdcfc",
"dleq": {
"e": "b31e58ac6527f34975ffab13e70a48b6d2b0d35abc4b03f0151f09ee1a9763d4",
"s": "8fbae004c59e754d71df67e392b6ae4e29293113ddc2ec86592a0431d16306d8",
"r": "a6d13fcd7a18442e6076f5e1e7c887ad5de40a019824bdfa9fe740d302e8d861",
},
}
)
assert proof.dleq

assert carol_verify_dleq(
secret_msg=proof.secret,
r=PrivateKey(bytes.fromhex(proof.dleq.r), raw=True),
C=PublicKey(bytes.fromhex(proof.C), raw=True),
e=PrivateKey(bytes.fromhex(proof.dleq.e), raw=True),
s=PrivateKey(bytes.fromhex(proof.dleq.s), raw=True),
A=A,
)


# TESTS FOR DEPRECATED HASH TO CURVE


Expand Down
Loading