diff --git a/README.md b/README.md index 51e4920..b15e01e 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/pkg/commands/auth/keyring.go b/pkg/commands/auth/keyring.go index f38f0da..6d9a5e7 100644 --- a/pkg/commands/auth/keyring.go +++ b/pkg/commands/auth/keyring.go @@ -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 } @@ -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) diff --git a/pkg/commands/auth/keyring_test.go b/pkg/commands/auth/keyring_test.go index e6c6977..334cdb6 100644 --- a/pkg/commands/auth/keyring_test.go +++ b/pkg/commands/auth/keyring_test.go @@ -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}, @@ -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 @@ -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) @@ -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}, @@ -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{} diff --git a/pkg/commands/auth/whoami.go b/pkg/commands/auth/whoami.go index 687d224..647d729 100644 --- a/pkg/commands/auth/whoami.go +++ b/pkg/commands/auth/whoami.go @@ -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 --private-key 0x... # Use flag") return nil } diff --git a/pkg/commands/auth/whoami_test.go b/pkg/commands/auth/whoami_test.go index a8f83e2..7d0c737 100644 --- a/pkg/commands/auth/whoami_test.go +++ b/pkg/commands/auth/whoami_test.go @@ -28,12 +28,12 @@ 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) } }() @@ -41,8 +41,8 @@ func TestWhoamiAction(t *testing.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) @@ -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) @@ -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 { @@ -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) diff --git a/pkg/commands/utils/preflight.go b/pkg/commands/utils/preflight.go index be8c237..1f90fe8 100644 --- a/pkg/commands/utils/preflight.go +++ b/pkg/commands/utils/preflight.go @@ -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 } @@ -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 diff --git a/pkg/common/constants.go b/pkg/common/constants.go index 46f147c..5948ece 100644 --- a/pkg/common/constants.go +++ b/pkg/common/constants.go @@ -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 diff --git a/pkg/common/flags.go b/pkg/common/flags.go index b4d083f..6125556 100644 --- a/pkg/common/flags.go +++ b/pkg/common/flags.go @@ -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{