Skip to content

Commit addb21d

Browse files
Update GetSignatureFormat to use ethrpc for chainID and accept wallet parameter
Co-Authored-By: Chris Li <chris.li.2046@gmail.com>
1 parent 1b19abc commit addb21d

3 files changed

Lines changed: 39 additions & 10 deletions

File tree

aggregator/auth.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,19 @@ func (r *RpcServer) verifyOperator(ctx context.Context, operatorAddr string) (bo
187187
}
188188

189189
func (r *RpcServer) GetSignatureFormat(ctx context.Context, req *avsproto.GetSignatureFormatReq) (*avsproto.GetSignatureFormatResp, error) {
190-
chainId := int64(1) // Example Ethereum mainnet
190+
chainId, err := r.ethrpc.ChainID(ctx)
191+
if err != nil {
192+
return nil, status.Errorf(codes.Internal, "Failed to get chainID: %v", err)
193+
}
194+
191195
issuedAt := time.Now().UTC().Format("2006-01-02T15:04:05.000Z")
196+
192197
expiredAt := time.Now().Add(time.Hour * 24).UTC().Format("2006-01-02T15:04:05.000Z")
193-
walletAddress := "0x0000000000000000000000000000000000000000" // Example address
194-
195-
formattedMessage := fmt.Sprintf(authTemplate, chainId, issuedAt, expiredAt, walletAddress)
196-
198+
199+
walletAddress := req.Wallet
200+
201+
formattedMessage := fmt.Sprintf(authTemplate, chainId.Int64(), issuedAt, expiredAt, walletAddress)
202+
197203
return &avsproto.GetSignatureFormatResp{
198204
Format: formattedMessage,
199205
}, nil

aggregator/auth_test.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package aggregator
33
import (
44
"context"
55
"fmt"
6+
"math/big"
7+
"strings"
68
"testing"
79
"time"
810

@@ -18,6 +20,14 @@ import (
1820
sdklogging "github.com/Layr-Labs/eigensdk-go/logging"
1921
)
2022

23+
type MockEthClient struct {
24+
chainID *big.Int
25+
}
26+
27+
func (m *MockEthClient) ChainID(ctx context.Context) (*big.Int, error) {
28+
return m.chainID, nil
29+
}
30+
2131
func TestGetKeyWithSignature(t *testing.T) {
2232
logger, _ := sdklogging.NewZapLogger("development")
2333

@@ -80,22 +90,34 @@ func TestGetKeyWithSignature(t *testing.T) {
8090
func TestGetSignatureFormat(t *testing.T) {
8191
logger, _ := sdklogging.NewZapLogger("development")
8292

93+
mockEthClient := &MockEthClient{
94+
chainID: big.NewInt(1), // Ethereum mainnet
95+
}
96+
8397
r := RpcServer{
8498
config: &config.Config{
8599
JwtSecret: []byte("test123"),
86100
Logger: logger,
87101
},
102+
ethrpc: mockEthClient,
88103
}
89104

90-
req := &avsproto.GetSignatureFormatReq{}
105+
walletAddress := "0x1234567890123456789012345678901234567890"
106+
req := &avsproto.GetSignatureFormatReq{
107+
Wallet: walletAddress,
108+
}
91109

92110
resp, err := r.GetSignatureFormat(context.Background(), req)
93111

94112
if err != nil {
95113
t.Errorf("expected GetSignatureFormat to succeed but got error: %s", err)
96114
}
97115

98-
if resp.Format != authTemplate {
99-
t.Errorf("expected format to be %s but got %s", authTemplate, resp.Format)
116+
if !strings.Contains(resp.Format, walletAddress) {
117+
t.Errorf("expected format to contain wallet address %s but got %s", walletAddress, resp.Format)
118+
}
119+
120+
if !strings.Contains(resp.Format, "Chain ID: 1") {
121+
t.Errorf("expected format to contain Chain ID: 1 but got %s", resp.Format)
100122
}
101123
}

protobuf/avs.proto

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -659,11 +659,12 @@ message DeleteSecretReq {
659659
}
660660

661661
message GetSignatureFormatReq {
662-
// Empty request
662+
// The wallet address to include in the signature format
663+
string wallet = 1;
663664
}
664665

665666
message GetSignatureFormatResp {
666-
// The template format for signature messages
667+
// The formatted signature message with server-side values filled in
667668
string format = 1;
668669
}
669670

0 commit comments

Comments
 (0)