From 956c46458aaf0f839cf272529a7b9d71e55d1f5e Mon Sep 17 00:00:00 2001 From: elnosh Date: Thu, 19 Sep 2024 16:14:14 -0500 Subject: [PATCH] mint - tests for DLEQ proofs returned from mint ops --- mint/mint_integration_test.go | 42 +++++++++++++++++++++++++++++++++++ testutils/utils.go | 14 ++++++++++-- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/mint/mint_integration_test.go b/mint/mint_integration_test.go index e5f4347..722a2b7 100644 --- a/mint/mint_integration_test.go +++ b/mint/mint_integration_test.go @@ -21,6 +21,7 @@ import ( "github.com/elnosh/gonuts/cashu/nuts/nut05" "github.com/elnosh/gonuts/cashu/nuts/nut07" "github.com/elnosh/gonuts/cashu/nuts/nut11" + "github.com/elnosh/gonuts/cashu/nuts/nut12" "github.com/elnosh/gonuts/crypto" "github.com/elnosh/gonuts/mint" "github.com/elnosh/gonuts/testutils" @@ -959,3 +960,44 @@ func TestNUT11P2PK(t *testing.T) { t.Fatalf("expected error '%v' but got '%v' instead", nut11.SigAllOnlySwap, err) } } + +func TestDLEQProofs(t *testing.T) { + var amount uint64 = 5000 + proofs, err := testutils.GetValidProofsForAmount(amount, testMint, lnd2) + if err != nil { + t.Fatalf("error generating valid proofs: %v", err) + } + + keyset := testMint.GetActiveKeyset() + + // check proofs minted from testMint have valid DLEQ proofs + for _, proof := range proofs { + if proof.DLEQ == nil { + t.Fatal("mint returned nil DLEQ proof") + } + + if !nut12.VerifyProofDLEQ(proof, keyset.Keys[proof.Amount].PublicKey) { + t.Fatal("generated invalid DLEQ proof from MintTokens") + } + } + + blindedMessages, _, _, err := testutils.CreateBlindedMessages(amount, keyset) + blindSignatures, err := testMint.Swap(proofs, blindedMessages) + if err != nil { + t.Fatalf("unexpected error in swap: %v", err) + } + + for i, sig := range blindSignatures { + if sig.DLEQ == nil { + t.Fatal("mint returned nil DLEQ proof from swap") + } + if !nut12.VerifyBlindSignatureDLEQ( + *sig.DLEQ, + keyset.Keys[sig.Amount].PublicKey, + blindedMessages[i].B_, + sig.C_, + ) { + t.Fatal("mint generated invalid DLEQ proof in swap") + } + } +} diff --git a/testutils/utils.go b/testutils/utils.go index 2ab32b6..aee98bc 100644 --- a/testutils/utils.go +++ b/testutils/utils.go @@ -402,8 +402,18 @@ func ConstructProofs(blindedSignatures cashu.BlindedSignatures, C := crypto.UnblindSignature(C_, rs[i], keyp.PublicKey) Cstr := hex.EncodeToString(C.SerializeCompressed()) - proof := cashu.Proof{Amount: blindedSignature.Amount, - Secret: secrets[i], C: Cstr, Id: blindedSignature.Id} + r := hex.EncodeToString(rs[i].Serialize()) + proof := cashu.Proof{ + Amount: blindedSignature.Amount, + Secret: secrets[i], + C: Cstr, + Id: blindedSignature.Id, + DLEQ: &cashu.DLEQProof{ + E: blindedSignature.DLEQ.E, + S: blindedSignature.DLEQ.S, + R: r, + }, + } proofs[i] = proof }