|
1 | 1 | package aggregator |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "context" |
5 | 4 | "fmt" |
| 5 | + "strconv" |
6 | 6 | "time" |
7 | 7 |
|
8 | 8 | "github.com/AvaProtocol/EigenLayer-AVS/core/auth" |
9 | 9 | "github.com/AvaProtocol/EigenLayer-AVS/core/config" |
10 | 10 | "github.com/ethereum/go-ethereum/common" |
11 | | - "github.com/ethereum/go-ethereum/ethclient" |
12 | 11 | "github.com/golang-jwt/jwt/v5" |
13 | 12 | ) |
14 | 13 |
|
@@ -47,26 +46,23 @@ func CreateAdminKey(configPath string, opt CreateApiKeyOption) error { |
47 | 46 | } |
48 | 47 |
|
49 | 48 | // 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") |
62 | 57 | } |
| 58 | + audienceChainID := strconv.FormatInt(nodeConfig.SmartWallet.ChainID, 10) |
63 | 59 |
|
64 | 60 | claims := &auth.APIClaim{ |
65 | 61 | RegisteredClaims: &jwt.RegisteredClaims{ |
66 | 62 | ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Hour * 24 * 365 * 10)), |
67 | | - Issuer: "AvaProtocol", |
| 63 | + Issuer: auth.Issuer, |
68 | 64 | Subject: opt.Subject, |
69 | | - Audience: jwt.ClaimStrings{chainID.String()}, |
| 65 | + Audience: jwt.ClaimStrings{audienceChainID}, |
70 | 66 | }, |
71 | 67 | Roles: roles, |
72 | 68 | } |
|
0 commit comments