Skip to content

Commit

Permalink
push g1 api sign
Browse files Browse the repository at this point in the history
  • Loading branch information
shrimalmadhur committed Jan 8, 2025
1 parent 9313acc commit 59122e8
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 7 deletions.
22 changes: 18 additions & 4 deletions signer/bls/cerberus/cerberus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down
10 changes: 10 additions & 0 deletions signer/bls/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 10 additions & 0 deletions signer/bls/privatekey/privatekey.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions signer/bls/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion signer/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
4 changes: 2 additions & 2 deletions signer/go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down

0 comments on commit 59122e8

Please sign in to comment.