Skip to content

Commit 0b07f28

Browse files
committed
fix: address PR review feedback for create-api-key audience claim
- Use nodeConfig.SmartWallet.ChainID directly instead of dialing the EigenLayer RPC. The verifier's r.chainID is sourced from the smart wallet RPC, so cross-chain configs (e.g. EigenLayer on Ethereum + SmartWallet on Base) would have failed with the previous approach. - Drops the extra RPC round-trip and the context-timeout concern entirely. - Use the auth.Issuer constant instead of the hard-coded "AvaProtocol" string.
1 parent 4442205 commit 0b07f28

1 file changed

Lines changed: 12 additions & 16 deletions

File tree

aggregator/key.go

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package aggregator
22

33
import (
4-
"context"
54
"fmt"
5+
"strconv"
66
"time"
77

88
"github.com/AvaProtocol/EigenLayer-AVS/core/auth"
99
"github.com/AvaProtocol/EigenLayer-AVS/core/config"
1010
"github.com/ethereum/go-ethereum/common"
11-
"github.com/ethereum/go-ethereum/ethclient"
1211
"github.com/golang-jwt/jwt/v5"
1312
)
1413

@@ -47,26 +46,23 @@ func CreateAdminKey(configPath string, opt CreateApiKeyOption) error {
4746
}
4847

4948
// The verifier (aggregator/auth.go::verifyAuth) requires the JWT to have an
50-
// `aud` claim containing the chain ID string. NewAggregator does not run
51-
// the lifecycle init that populates agg.chainID, so dial the RPC directly
52-
// and read it here. Without this claim, every key generated by
53-
// `create-api-key` is rejected with "API key is invalid".
54-
rpcClient, err := ethclient.Dial(nodeConfig.EthHttpRpcUrl)
55-
if err != nil {
56-
return fmt.Errorf("failed to dial eth rpc to determine chainId for audience claim: %w", err)
57-
}
58-
defer rpcClient.Close()
59-
chainID, err := rpcClient.ChainID(context.Background())
60-
if err != nil {
61-
return fmt.Errorf("failed to fetch chainId for audience claim: %w", err)
49+
// `aud` claim containing the smart wallet chain ID. r.chainID in the
50+
// verifier is sourced from the smart wallet RPC (see rpc_server.go), not
51+
// the EigenLayer RPC, so we must use SmartWallet.ChainID here too — using
52+
// the EigenLayer chain ID would silently break cross-chain configs (e.g.
53+
// EigenLayer on Ethereum + SmartWallet on Base). config.NewConfig already
54+
// populated SmartWallet.ChainID at startup, so no extra RPC dial is needed.
55+
if nodeConfig.SmartWallet == nil || nodeConfig.SmartWallet.ChainID == 0 {
56+
return fmt.Errorf("smart wallet chain ID not populated in config; cannot build audience claim")
6257
}
58+
audienceChainID := strconv.FormatInt(nodeConfig.SmartWallet.ChainID, 10)
6359

6460
claims := &auth.APIClaim{
6561
RegisteredClaims: &jwt.RegisteredClaims{
6662
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Hour * 24 * 365 * 10)),
67-
Issuer: "AvaProtocol",
63+
Issuer: auth.Issuer,
6864
Subject: opt.Subject,
69-
Audience: jwt.ClaimStrings{chainID.String()},
65+
Audience: jwt.ClaimStrings{audienceChainID},
7066
},
7167
Roles: roles,
7268
}

0 commit comments

Comments
 (0)