From 59122e8557bce20ce1586fa73b503fc80285355a Mon Sep 17 00:00:00 2001 From: Madhur Shrimal Date: Wed, 8 Jan 2025 10:32:17 -0800 Subject: [PATCH] push g1 api sign --- signer/bls/cerberus/cerberus.go | 22 ++++++++++++++++++---- signer/bls/local/local.go | 10 ++++++++++ signer/bls/privatekey/privatekey.go | 10 ++++++++++ signer/bls/signer.go | 4 ++++ signer/go.mod | 2 +- signer/go.sum | 4 ++-- 6 files changed, 45 insertions(+), 7 deletions(-) diff --git a/signer/bls/cerberus/cerberus.go b/signer/bls/cerberus/cerberus.go index bd1f3f69..426a553e 100644 --- a/signer/bls/cerberus/cerberus.go +++ b/signer/bls/cerberus/cerberus.go @@ -66,11 +66,25 @@ func (s Signer) Sign(ctx context.Context, msg []byte) ([]byte, error) { return nil, types.ErrInvalidMessageLength } - var data [32]byte - copy(data[:], msg) - resp, err := s.signerClient.SignGeneric(ctx, &v1.SignGenericRequest{ - Data: data[:], + Data: msg, + PublicKeyG1: s.pubKeyHex, + Password: s.password, + }) + if err != nil { + return nil, err + } + + return resp.Signature, nil +} + +func (s Signer) SignG1(ctx context.Context, msg []byte) ([]byte, error) { + if len(msg) != 64 { + return nil, types.ErrInvalidMessageLength + } + + resp, err := s.signerClient.SignG1(ctx, &v1.SignG1Request{ + Data: msg, PublicKeyG1: s.pubKeyHex, Password: s.password, }) diff --git a/signer/bls/local/local.go b/signer/bls/local/local.go index c7ce28c0..ec4aa280 100644 --- a/signer/bls/local/local.go +++ b/signer/bls/local/local.go @@ -38,6 +38,16 @@ func (s Signer) Sign(ctx context.Context, msg []byte) ([]byte, error) { return s.key.SignMessage(data).Serialize(), nil } +func (s Signer) SignG1(ctx context.Context, msg []byte) ([]byte, error) { + if len(msg) != 64 { + return nil, types.ErrInvalidMessageLength + } + + msgG1 := new(sdkBls.G1Point) + msgG1 = msgG1.Deserialize(msg) + return s.key.SignHashedToCurveMessage(msgG1.G1Affine).Serialize(), nil +} + func (s Signer) GetOperatorId() (string, error) { return s.key.PubKey.GetOperatorID(), nil } diff --git a/signer/bls/privatekey/privatekey.go b/signer/bls/privatekey/privatekey.go index 8eec155c..1e4f1c08 100644 --- a/signer/bls/privatekey/privatekey.go +++ b/signer/bls/privatekey/privatekey.go @@ -37,6 +37,16 @@ func (s Signer) Sign(ctx context.Context, msg []byte) ([]byte, error) { return s.key.SignMessage(data).Serialize(), nil } +func (s Signer) SignG1(ctx context.Context, msg []byte) ([]byte, error) { + if len(msg) != 64 { + return nil, types.ErrInvalidMessageLength + } + + msgG1 := new(sdkBls.G1Point) + msgG1 = msgG1.Deserialize(msg) + return s.key.SignHashedToCurveMessage(msgG1.G1Affine).Serialize(), nil +} + func (s Signer) GetOperatorId() (string, error) { return s.key.PubKey.GetOperatorID(), nil } diff --git a/signer/bls/signer.go b/signer/bls/signer.go index b5ebf2f5..ccbcb1d2 100644 --- a/signer/bls/signer.go +++ b/signer/bls/signer.go @@ -13,6 +13,10 @@ type Signer interface { // Sign signs the message using the BLS signature scheme Sign(ctx context.Context, msg []byte) ([]byte, error) + // SignG1 signs the message using the BLS signature scheme + // This message is assumed to be already mapped to G1 point + SignG1(ctx context.Context, msg []byte) ([]byte, error) + // GetOperatorId returns the operator ID of the signer. // This is hash of the G1 public key of the signer GetOperatorId() (string, error) diff --git a/signer/go.mod b/signer/go.mod index 70abad45..a0c001a1 100644 --- a/signer/go.mod +++ b/signer/go.mod @@ -5,7 +5,7 @@ go 1.21.13 replace github.com/Layr-Labs/eigensdk-go => ../../eigensdk-go require ( - github.com/Layr-Labs/cerberus-api v0.0.2-0.20250107174124-05df6050f723 + github.com/Layr-Labs/cerberus-api v0.0.2-0.20250108174619-d5e1eb03fbd5 github.com/Layr-Labs/eigensdk-go v0.1.13 google.golang.org/grpc v1.64.1 ) diff --git a/signer/go.sum b/signer/go.sum index edc7535d..dbbb9188 100644 --- a/signer/go.sum +++ b/signer/go.sum @@ -1,7 +1,7 @@ github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ= github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= -github.com/Layr-Labs/cerberus-api v0.0.2-0.20250107174124-05df6050f723 h1:f6gJS/egys133nGcOGKduiPHq9hyK9KRiEB9fARB5t0= -github.com/Layr-Labs/cerberus-api v0.0.2-0.20250107174124-05df6050f723/go.mod h1:Lm4fhzy0S3P7GjerzuseGaBFVczsIKmEhIjcT52Hluo= +github.com/Layr-Labs/cerberus-api v0.0.2-0.20250108174619-d5e1eb03fbd5 h1:s24M6HYObEuV9OSY36jUM09kp5fOhuz/g1ev2qWDPzU= +github.com/Layr-Labs/cerberus-api v0.0.2-0.20250108174619-d5e1eb03fbd5/go.mod h1:Lm4fhzy0S3P7GjerzuseGaBFVczsIKmEhIjcT52Hluo= github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA= github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8= github.com/VictoriaMetrics/fastcache v1.12.1 h1:i0mICQuojGDL3KblA7wUNlY5lOK6a4bwt3uRKnkZU40=