Skip to content

Commit c0b1c80

Browse files
fix: include chain ID audience claim in JWT created by create-api-key (#513)
Co-authored-by: Wei Lin <wei@avaprotocol.org>
1 parent b724f1e commit c0b1c80

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

aggregator/key.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package aggregator
22

33
import (
44
"fmt"
5+
"strconv"
56
"time"
67

78
"github.com/AvaProtocol/EigenLayer-AVS/core/auth"
@@ -44,11 +45,24 @@ func CreateAdminKey(configPath string, opt CreateApiKeyOption) error {
4445
roles[i] = auth.ApiRole(v)
4546
}
4647

48+
// The verifier (aggregator/auth.go::verifyAuth) requires the JWT to have an
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")
57+
}
58+
audienceChainID := strconv.FormatInt(nodeConfig.SmartWallet.ChainID, 10)
59+
4760
claims := &auth.APIClaim{
4861
RegisteredClaims: &jwt.RegisteredClaims{
4962
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Hour * 24 * 365 * 10)),
50-
Issuer: "AvaProtocol",
63+
Issuer: auth.Issuer,
5164
Subject: opt.Subject,
65+
Audience: jwt.ClaimStrings{audienceChainID},
5266
},
5367
Roles: roles,
5468
}

0 commit comments

Comments
 (0)