Skip to content

Commit

Permalink
feat: generate a random private key if not provided
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen committed Sep 17, 2024
1 parent b1ec821 commit 2c7e31f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
10 changes: 8 additions & 2 deletions e2e/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package e2e

import (
"context"
"encoding/hex"
"fmt"
"os"
"testing"
Expand Down Expand Up @@ -93,10 +94,15 @@ type TestSuite struct {
func CreateTestSuite(t *testing.T, testCfg *Cfg) (TestSuite, func()) {
ctx := context.Background()

// load signer key from environment
// load signer key from environment or generate a random one
pk := os.Getenv(privateKey)
if pk == "" && !testCfg.UseMemory {
t.Fatal("SIGNER_PRIVATE_KEY environment variable not set")
t.Logf("SIGNER_PRIVATE_KEY environment variable not set. Generated random private key")
randomBytes := make([]byte, 32)
if _, err := rand.Read(randomBytes); err != nil {
t.Fatalf("Failed to generate random private key: %v", err)
}
pk = hex.EncodeToString(randomBytes)
}

// load node url from environment
Expand Down
25 changes: 18 additions & 7 deletions server/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package server

import (
"crypto/rand"
"encoding/hex"
"fmt"
"runtime"
"time"
Expand Down Expand Up @@ -179,13 +181,22 @@ func ReadConfig(ctx *cli.Context) Config {
Timeout: ctx.Duration(S3TimeoutFlagName),
},
ClientConfig: clients.EigenDAClientConfig{
RPC: ctx.String(EigenDADisperserRPCFlagName),
StatusQueryRetryInterval: ctx.Duration(StatusQueryRetryIntervalFlagName),
StatusQueryTimeout: ctx.Duration(StatusQueryTimeoutFlagName),
DisableTLS: ctx.Bool(DisableTLSFlagName),
ResponseTimeout: ctx.Duration(ResponseTimeoutFlagName),
CustomQuorumIDs: ctx.UintSlice(CustomQuorumIDsFlagName),
SignerPrivateKeyHex: ctx.String(SignerPrivateKeyHexFlagName),
RPC: ctx.String(EigenDADisperserRPCFlagName),
StatusQueryRetryInterval: ctx.Duration(StatusQueryRetryIntervalFlagName),
StatusQueryTimeout: ctx.Duration(StatusQueryTimeoutFlagName),
DisableTLS: ctx.Bool(DisableTLSFlagName),
ResponseTimeout: ctx.Duration(ResponseTimeoutFlagName),
CustomQuorumIDs: ctx.UintSlice(CustomQuorumIDsFlagName),
SignerPrivateKeyHex: func() string {
if key := ctx.String(SignerPrivateKeyHexFlagName); key != "" {
return key
}
randomBytes := make([]byte, 32)
if _, err := rand.Read(randomBytes); err != nil {
panic(fmt.Errorf("failed to generate random private key: %w", err))
}
return hex.EncodeToString(randomBytes)
}(),
PutBlobEncodingVersion: codecs.BlobEncodingVersion(ctx.Uint(PutBlobEncodingVersionFlagName)),
DisablePointVerificationMode: ctx.Bool(DisablePointVerificationModeFlagName),
},
Expand Down

0 comments on commit 2c7e31f

Please sign in to comment.