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

Compliance test for BLS signature #402

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
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
32 changes: 32 additions & 0 deletions chainio/clients/avsregistry/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import (

chainioutils "github.com/Layr-Labs/eigensdk-go/chainio/utils"
"github.com/Layr-Labs/eigensdk-go/crypto/bls"
"github.com/Layr-Labs/eigensdk-go/testutils"
"github.com/Layr-Labs/eigensdk-go/testutils/testclients"
"github.com/Layr-Labs/eigensdk-go/types"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -72,3 +74,33 @@ func TestWriterMethods(t *testing.T) {
require.NotNil(t, receipt)
})
}

func TestBlsSignature(t *testing.T) {
// read input from JSON if available, otherwise use default values
var defaultInput = struct {
Message string `json:"message"`
BlsPrivKey string `json:"bls_priv_key"`
}{
Message: "Hello, world!Hello, world!123456",
BlsPrivKey: "12248929636257230549931416853095037629726205319386239410403476017439825112537",
}

testData := testutils.NewTestData(defaultInput)
// The message to sign
messageArray := []byte(testData.Input.Message)

var messageArray32 [32]byte
copy(messageArray32[:], messageArray)

// The private key as a string
privKey, _ := bls.NewPrivateKey(testData.Input.BlsPrivKey)
keyPair := bls.NewKeyPair(privKey)

sig := keyPair.SignMessage(messageArray32)

x := sig.G1Affine.X.String()
y := sig.G1Affine.Y.String()

assert.Equal(t, x, "15790168376429033610067099039091292283117017641532256477437243974517959682102")
assert.Equal(t, y, "4960450323239587206117776989095741074887370703941588742100855592356200866613")
}
Loading