Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ eigenx auth logout # Remove key
### 2. Environment Variable

```bash
export PRIVATE_KEY=0x1234...
export EIGENX_PRIVATE_KEY=0x1234...
eigenx app deploy
```

Expand Down
4 changes: 2 additions & 2 deletions pkg/commands/auth/keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func GetPrivateKeyWithSource(cCtx *cli.Context) (string, string, error) {
}

// 2. Check environment variable
if privateKey := os.Getenv("PRIVATE_KEY"); privateKey != "" {
if privateKey := os.Getenv(common.EigenXPrivateKeyEnvVar); privateKey != "" {
return privateKey, "environment variable", nil
}

Expand All @@ -54,7 +54,7 @@ func GetPrivateKeyWithSource(cCtx *cli.Context) (string, string, error) {
baseMsg := `Private key required. Please provide it via:
• Keyring: eigenx auth login
• Flag: --private-key YOUR_KEY
• Environment: export PRIVATE_KEY=YOUR_KEY`
• Environment: export EIGENX_PRIVATE_KEY=YOUR_KEY`

if len(keyringErrors) > 0 {
return "", "", fmt.Errorf("%s\n\nKeyring issues detected:\n%v", baseMsg, keyringErrors)
Expand Down
20 changes: 10 additions & 10 deletions pkg/commands/auth/keyring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ func TestListStoredKeys(t *testing.T) {
}

func TestGetPrivateKeyWithSource(t *testing.T) {
originalEnv := os.Getenv("PRIVATE_KEY")
originalEnv := os.Getenv(common.EigenXPrivateKeyEnvVar)
defer func() {
if originalEnv == "" {
os.Unsetenv("PRIVATE_KEY")
os.Unsetenv(common.EigenXPrivateKeyEnvVar)
} else {
os.Setenv("PRIVATE_KEY", originalEnv)
os.Setenv(common.EigenXPrivateKeyEnvVar, originalEnv)
}
}()

mock := testutils.SetupMockKeyring(t)

t.Run("from command flag", func(t *testing.T) {
os.Unsetenv("PRIVATE_KEY")
os.Unsetenv(common.EigenXPrivateKeyEnvVar)

app := &cli.App{
Flags: []cli.Flag{common.PrivateKeyFlag},
Expand All @@ -79,8 +79,8 @@ func TestGetPrivateKeyWithSource(t *testing.T) {

t.Run("from environment variable", func(t *testing.T) {
testKey := "0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd"
os.Setenv("PRIVATE_KEY", testKey)
defer os.Unsetenv("PRIVATE_KEY")
os.Setenv(common.EigenXPrivateKeyEnvVar, testKey)
defer os.Unsetenv(common.EigenXPrivateKeyEnvVar)

app := &cli.App{}
var ctx *cli.Context
Expand All @@ -99,7 +99,7 @@ func TestGetPrivateKeyWithSource(t *testing.T) {
})

t.Run("from stored credentials", func(t *testing.T) {
os.Unsetenv("PRIVATE_KEY")
os.Unsetenv(common.EigenXPrivateKeyEnvVar)
mock.Clear()
err := mock.StorePrivateKey("sepolia", "0x1111111111111111111111111111111111111111111111111111111111111111")
require.NoError(t, err)
Expand All @@ -124,8 +124,8 @@ func TestGetPrivateKeyWithSource(t *testing.T) {
flagKey := "0x1111111111111111111111111111111111111111111111111111111111111111"
envKey := "0x2222222222222222222222222222222222222222222222222222222222222222"

os.Setenv("PRIVATE_KEY", envKey)
defer os.Unsetenv("PRIVATE_KEY")
os.Setenv(common.EigenXPrivateKeyEnvVar, envKey)
defer os.Unsetenv(common.EigenXPrivateKeyEnvVar)

app := &cli.App{
Flags: []cli.Flag{common.PrivateKeyFlag},
Expand All @@ -146,7 +146,7 @@ func TestGetPrivateKeyWithSource(t *testing.T) {
})

t.Run("no key available", func(t *testing.T) {
os.Unsetenv("PRIVATE_KEY")
os.Unsetenv(common.EigenXPrivateKeyEnvVar)
mock.Clear()

app := &cli.App{}
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/auth/whoami.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func whoamiAction(cCtx *cli.Context) error {
fmt.Println("")
fmt.Println("To authenticate, use one of:")
fmt.Println(" eigenx auth login # Store key in keyring")
fmt.Println(" export PRIVATE_KEY=0x... # Use environment variable")
fmt.Println(" export EIGENX_PRIVATE_KEY=0x... # Use environment variable")
fmt.Println(" eigenx <command> --private-key 0x... # Use flag")
return nil
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/commands/auth/whoami_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ func TestWhoamiCommand(t *testing.T) {
}

func TestWhoamiAction(t *testing.T) {
originalEnv := os.Getenv("PRIVATE_KEY")
originalEnv := os.Getenv(common.EigenXPrivateKeyEnvVar)
defer func() {
if originalEnv == "" {
os.Unsetenv("PRIVATE_KEY")
os.Unsetenv(common.EigenXPrivateKeyEnvVar)
} else {
os.Setenv("PRIVATE_KEY", originalEnv)
os.Setenv(common.EigenXPrivateKeyEnvVar, originalEnv)
}
}()

mock := testutils.SetupMockKeyring(t)

t.Run("with environment variable", func(t *testing.T) {
testKey := "0x1234567890123456789012345678901234567890123456789012345678901234"
os.Setenv("PRIVATE_KEY", testKey)
defer os.Unsetenv("PRIVATE_KEY")
os.Setenv(common.EigenXPrivateKeyEnvVar, testKey)
defer os.Unsetenv(common.EigenXPrivateKeyEnvVar)

app, noopLogger := testutils.CreateTestAppWithNoopLoggerAndAccess("test-app", common.GlobalFlags, func(cCtx *cli.Context) error {
return whoamiAction(cCtx)
Expand All @@ -60,7 +60,7 @@ func TestWhoamiAction(t *testing.T) {
})

t.Run("with stored credentials", func(t *testing.T) {
os.Unsetenv("PRIVATE_KEY")
os.Unsetenv(common.EigenXPrivateKeyEnvVar)
mock.Clear()
err := mock.StorePrivateKey("sepolia", "0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd")
require.NoError(t, err)
Expand All @@ -81,7 +81,7 @@ func TestWhoamiAction(t *testing.T) {
})

t.Run("not authenticated", func(t *testing.T) {
os.Unsetenv("PRIVATE_KEY")
os.Unsetenv(common.EigenXPrivateKeyEnvVar)
mock.Clear()

app, noopLogger := testutils.CreateTestAppWithNoopLoggerAndAccess("test-app", common.GlobalFlags, func(cCtx *cli.Context) error {
Expand All @@ -101,7 +101,7 @@ func TestWhoamiAction(t *testing.T) {
})

t.Run("with environment flag", func(t *testing.T) {
os.Unsetenv("PRIVATE_KEY")
os.Unsetenv(common.EigenXPrivateKeyEnvVar)
mock.Clear()
err := mock.StorePrivateKey("sepolia", "0x2222222222222222222222222222222222222222222222222222222222222222")
require.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions pkg/commands/utils/preflight.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ func GetPrivateKeyOrFail(cCtx *cli.Context) (string, error) {
}

// Check environment variable
if privateKey := os.Getenv("PRIVATE_KEY"); privateKey != "" {
if privateKey := os.Getenv(common.EigenXPrivateKeyEnvVar); privateKey != "" {
// Validate the key format
if err := common.ValidatePrivateKey(privateKey); err != nil {
return "", fmt.Errorf("invalid private key in PRIVATE_KEY environment variable: %w", err)
return "", fmt.Errorf("invalid private key in %s environment variable: %w", common.EigenXPrivateKeyEnvVar, err)
}
return privateKey, nil
}
Expand All @@ -113,7 +113,7 @@ func GetPrivateKeyOrFail(cCtx *cli.Context) (string, error) {
return "", fmt.Errorf(`private key required. Please provide it via:
• Keyring: eigenx auth login
• Flag: --private-key YOUR_KEY
• Environment: export PRIVATE_KEY=YOUR_KEY`)
• Environment: export EIGENX_PRIVATE_KEY=YOUR_KEY`)
}

// GetDeveloperAddress gets developer address from private key
Expand Down
1 change: 1 addition & 0 deletions pkg/common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const (
// Environment variable names
MnemonicEnvVar = "MNEMONIC" // Filtered out, overridden by protocol
EigenMachineTypeEnvVar = "EIGEN_MACHINE_TYPE_PUBLIC" // Instance type configuration
EigenXPrivateKeyEnvVar = "EIGENX_PRIVATE_KEY" // Private key for authentication
)

// API permissions constants
Expand Down
4 changes: 2 additions & 2 deletions pkg/common/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ var (
RpcUrlFlag = &cli.StringFlag{
Name: "rpc-url",
Usage: "RPC URL to connect to blockchain",
EnvVars: []string{"RPC_URL"},
EnvVars: []string{"EIGENX_RPC_URL"},
}

PrivateKeyFlag = &cli.StringFlag{
Name: "private-key",
Usage: "Private key for signing transactions",
EnvVars: []string{"PRIVATE_KEY"},
EnvVars: []string{EigenXPrivateKeyEnvVar},
}

ForceFlag = &cli.BoolFlag{
Expand Down
Loading