From 486322e751786afd9f3a4e7e36d22f9cf6e221f2 Mon Sep 17 00:00:00 2001 From: Sergio Mena Date: Wed, 17 Jul 2024 15:54:10 +0200 Subject: [PATCH 1/4] add unit test --- curves/bls12381/signature_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/curves/bls12381/signature_test.go b/curves/bls12381/signature_test.go index 1a2956c..0b0dfa1 100644 --- a/curves/bls12381/signature_test.go +++ b/curves/bls12381/signature_test.go @@ -2,6 +2,7 @@ package blst import ( "bytes" + "crypto/sha256" "errors" "reflect" "testing" @@ -19,6 +20,22 @@ func TestSignVerify(t *testing.T) { assert.Equal(t, true, sig.Verify(pub, msg), "Signature did not verify") } +func TestSignVerifyRecreatedKey(t *testing.T) { + //seed := [32]byte(sha256.Sum("this is my little key")) + seedStr := []byte("this is my little key") + seed := sha256.Sum256(seedStr) + priv, err := GenPrivKeyFromSeed(seed) + require.NoError(t, err) + msg := []byte("hello crypto") + sig := priv.Sign(msg) + + priv2, err := GenPrivKeyFromSeed(seed) + require.NoError(t, err) + pub2 := priv2.PublicKey() + + assert.Equal(t, true, sig.Verify(pub2, msg), "Signature did not verify") +} + func TestVerifySingleSignature_InvalidSignature(t *testing.T) { priv, err := RandKey() require.NoError(t, err) From 661dfd3f225ab884063ca325dbb48030cb2a2bab Mon Sep 17 00:00:00 2001 From: Sergio Mena Date: Wed, 17 Jul 2024 16:09:44 +0200 Subject: [PATCH 2/4] Update curves/bls12381/signature_test.go --- curves/bls12381/signature_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/curves/bls12381/signature_test.go b/curves/bls12381/signature_test.go index 0b0dfa1..a5f58ab 100644 --- a/curves/bls12381/signature_test.go +++ b/curves/bls12381/signature_test.go @@ -21,7 +21,6 @@ func TestSignVerify(t *testing.T) { } func TestSignVerifyRecreatedKey(t *testing.T) { - //seed := [32]byte(sha256.Sum("this is my little key")) seedStr := []byte("this is my little key") seed := sha256.Sum256(seedStr) priv, err := GenPrivKeyFromSeed(seed) From 950e2b013bf8026c7c2042bdd3d9f7efe9044770 Mon Sep 17 00:00:00 2001 From: Sergio Mena Date: Wed, 17 Jul 2024 16:10:25 +0200 Subject: [PATCH 3/4] Update curves/bls12381/signature_test.go --- curves/bls12381/signature_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/curves/bls12381/signature_test.go b/curves/bls12381/signature_test.go index a5f58ab..010ceee 100644 --- a/curves/bls12381/signature_test.go +++ b/curves/bls12381/signature_test.go @@ -31,7 +31,6 @@ func TestSignVerifyRecreatedKey(t *testing.T) { priv2, err := GenPrivKeyFromSeed(seed) require.NoError(t, err) pub2 := priv2.PublicKey() - assert.Equal(t, true, sig.Verify(pub2, msg), "Signature did not verify") } From 12004d7656eb93a40dcb4c756fceb731017680fe Mon Sep 17 00:00:00 2001 From: Sergio Mena Date: Wed, 17 Jul 2024 18:22:55 +0200 Subject: [PATCH 4/4] small improvement --- curves/bls12381/signature_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/curves/bls12381/signature_test.go b/curves/bls12381/signature_test.go index 010ceee..051cedb 100644 --- a/curves/bls12381/signature_test.go +++ b/curves/bls12381/signature_test.go @@ -31,7 +31,7 @@ func TestSignVerifyRecreatedKey(t *testing.T) { priv2, err := GenPrivKeyFromSeed(seed) require.NoError(t, err) pub2 := priv2.PublicKey() - assert.Equal(t, true, sig.Verify(pub2, msg), "Signature did not verify") + assert.True(t, sig.Verify(pub2, msg), "Signature did not verify") } func TestVerifySingleSignature_InvalidSignature(t *testing.T) {