diff --git a/mint/mint.go b/mint/mint.go index 4686ca1..637f837 100644 --- a/mint/mint.go +++ b/mint/mint.go @@ -898,9 +898,9 @@ func (m *Mint) SetMintInfo(mintInfo MintInfo) error { }, Disabled: false, }, - 7: map[string]bool{"supported": false}, + 7: map[string]bool{"supported": true}, 8: map[string]bool{"supported": false}, - 9: map[string]bool{"supported": false}, + 9: map[string]bool{"supported": true}, 10: map[string]bool{"supported": true}, 11: map[string]bool{"supported": true}, 12: map[string]bool{"supported": false}, diff --git a/mint/mint_integration_test.go b/mint/mint_integration_test.go index bad175d..e5f4347 100644 --- a/mint/mint_integration_test.go +++ b/mint/mint_integration_test.go @@ -10,6 +10,7 @@ import ( "log" "os" "path/filepath" + "reflect" "testing" "time" @@ -621,6 +622,58 @@ func TestProofsStateCheck(t *testing.T) { } } +func TestRestoreSignatures(t *testing.T) { + // create blinded messages + blindedMessages, _, _, blindedSignatures, err := testutils.GetBlindedSignatures(5000, testMint, lnd2) + if err != nil { + t.Fatalf("error generating blinded signatures: %v", err) + } + + outputs, signatures, err := testMint.RestoreSignatures(blindedMessages) + if err != nil { + t.Fatalf("unexpected error restoring signatures: %v\n", err) + } + + if len(outputs) != len(signatures) { + t.Fatalf("length of ouputs '%v' does not match length of signatures '%v'\n", len(outputs), len(signatures)) + } + if !reflect.DeepEqual(blindedMessages, outputs) { + t.Fatal("outputs in request do not match outputs from mint response") + } + if !reflect.DeepEqual(blindedSignatures, signatures) { + t.Fatal("blinded signatures do not match signatures from mint response") + } + + // test with blinded messages that have not been previously signed + unsigned, _, _, _ := testutils.CreateBlindedMessages(4200, testMint.GetActiveKeyset()) + outputs, signatures, err = testMint.RestoreSignatures(unsigned) + if err != nil { + t.Fatalf("unexpected error restoring signatures: %v\n", err) + } + + // response should be empty + if len(outputs) != 0 && len(signatures) != 0 { + t.Fatalf("expected empty outputs and signatures but got %v and %v\n", len(outputs), len(signatures)) + } + + // test with only a portion of blinded messages signed + partial := append(blindedMessages, unsigned...) + outputs, signatures, err = testMint.RestoreSignatures(partial) + if err != nil { + t.Fatalf("unexpected error restoring signatures: %v\n", err) + } + + if len(outputs) != len(signatures) { + t.Fatalf("length of ouputs '%v' does not match length of signatures '%v'\n", len(outputs), len(signatures)) + } + if !reflect.DeepEqual(blindedMessages, outputs) { + t.Fatal("outputs in request do not match outputs from mint response") + } + if !reflect.DeepEqual(blindedSignatures, signatures) { + t.Fatal("blinded signatures do not match signatures from mint response") + } +} + func TestMintLimits(t *testing.T) { // setup mint with limits limitsMintPath := filepath.Join(".", "limitsMint") @@ -905,5 +958,4 @@ func TestNUT11P2PK(t *testing.T) { if !errors.Is(err, nut11.SigAllOnlySwap) { t.Fatalf("expected error '%v' but got '%v' instead", nut11.SigAllOnlySwap, err) } - } diff --git a/testutils/utils.go b/testutils/utils.go index 1921f17..2ab32b6 100644 --- a/testutils/utils.go +++ b/testutils/utils.go @@ -411,17 +411,22 @@ func ConstructProofs(blindedSignatures cashu.BlindedSignatures, return proofs, nil } -func GetValidProofsForAmount(amount uint64, mint *mint.Mint, payer *btcdocker.Lnd) (cashu.Proofs, error) { +func GetBlindedSignatures(amount uint64, mint *mint.Mint, payer *btcdocker.Lnd) ( + cashu.BlindedMessages, + []string, + []*secp256k1.PrivateKey, + cashu.BlindedSignatures, + error) { + mintQuoteResponse, err := mint.RequestMintQuote(BOLT11_METHOD, amount, SAT_UNIT) if err != nil { - return nil, fmt.Errorf("error requesting mint quote: %v", err) + return nil, nil, nil, nil, fmt.Errorf("error requesting mint quote: %v", err) } keyset := mint.GetActiveKeyset() - blindedMessages, secrets, rs, err := CreateBlindedMessages(amount, keyset) if err != nil { - return nil, fmt.Errorf("error creating blinded message: %v", err) + return nil, nil, nil, nil, fmt.Errorf("error creating blinded message: %v", err) } ctx := context.Background() @@ -431,12 +436,22 @@ func GetValidProofsForAmount(amount uint64, mint *mint.Mint, payer *btcdocker.Ln } response, _ := payer.Client.SendPaymentSync(ctx, &sendPaymentRequest) if len(response.PaymentError) > 0 { - return nil, fmt.Errorf("error paying invoice: %v", response.PaymentError) + return nil, nil, nil, nil, fmt.Errorf("error paying invoice: %v", response.PaymentError) } blindedSignatures, err := mint.MintTokens(BOLT11_METHOD, mintQuoteResponse.Id, blindedMessages) if err != nil { - return nil, fmt.Errorf("got unexpected error minting tokens: %v", err) + return nil, nil, nil, nil, fmt.Errorf("got unexpected error minting tokens: %v", err) + } + + return blindedMessages, secrets, rs, blindedSignatures, nil +} + +func GetValidProofsForAmount(amount uint64, mint *mint.Mint, payer *btcdocker.Lnd) (cashu.Proofs, error) { + keyset := mint.GetActiveKeyset() + _, secrets, rs, blindedSignatures, err := GetBlindedSignatures(amount, mint, payer) + if err != nil { + return nil, fmt.Errorf("error generating blinded signatures: %v", err) } proofs, err := ConstructProofs(blindedSignatures, secrets, rs, &keyset)