11package cmd
22
33import (
4- "errors"
54 "fmt"
65 "os"
76 "path/filepath"
8- "strings"
97
108 rollconf "github.com/evstack/ev-node/pkg/config"
119 "github.com/evstack/ev-node/pkg/hash"
1210 "github.com/evstack/ev-node/pkg/p2p/key"
13- "github.com/evstack/ev-node/pkg/signer"
1411 "github.com/evstack/ev-node/pkg/signer/file"
1512)
1613
@@ -21,54 +18,18 @@ func CreateSigner(config *rollconf.Config, homePath string, passphrase string) (
2118 return nil , fmt .Errorf ("passphrase is required when using local file signer" )
2219 }
2320
24- signerPath := config .Signer .SignerPath
25- if signerPath == "" {
26- signerPath = filepath .Join ("config" )
27- }
28- if ! filepath .IsAbs (signerPath ) {
29- signerPath = filepath .Join (homePath , signerPath )
30- }
31- if strings .HasSuffix (strings .ToLower (signerPath ), "signer.json" ) {
32- signerPath = filepath .Dir (signerPath )
33- }
34-
35- if info , err := os .Stat (signerPath ); err == nil {
36- if ! info .IsDir () {
37- return nil , fmt .Errorf ("signer path %s must be a directory" , signerPath )
38- }
39- } else if err != nil && ! errors .Is (err , os .ErrNotExist ) {
40- return nil , fmt .Errorf ("failed to inspect signer path: %w" , err )
41- }
42-
43- if err := os .MkdirAll (signerPath , 0o750 ); err != nil {
21+ signerDir := filepath .Join (homePath , "config" )
22+ if err := os .MkdirAll (signerDir , 0o750 ); err != nil {
4423 return nil , fmt .Errorf ("failed to create signer directory: %w" , err )
4524 }
4625
47- keyFile := filepath .Join (signerPath , "signer.json" )
48-
49- var (
50- signer signer.Signer
51- err error
52- )
53-
54- if _ , err = os .Stat (keyFile ); err != nil {
55- if ! errors .Is (err , os .ErrNotExist ) {
56- return nil , fmt .Errorf ("failed to check signer file: %w" , err )
57- }
26+ config .Signer .SignerPath = signerDir
5827
59- signer , err = file .CreateFileSystemSigner (signerPath , []byte (passphrase ))
60- if err != nil {
61- return nil , fmt .Errorf ("failed to initialize signer: %w" , err )
62- }
63- } else {
64- signer , err = file .LoadFileSystemSigner (signerPath , []byte (passphrase ))
65- if err != nil {
66- return nil , fmt .Errorf ("failed to load signer: %w" , err )
67- }
28+ signer , err := file .CreateFileSystemSigner (config .Signer .SignerPath , []byte (passphrase ))
29+ if err != nil {
30+ return nil , fmt .Errorf ("failed to initialize signer: %w" , err )
6831 }
6932
70- config .Signer .SignerPath = signerPath
71-
7233 pubKey , err := signer .GetPublic ()
7334 if err != nil {
7435 return nil , fmt .Errorf ("failed to get public key: %w" , err )
0 commit comments