From bc8df6802e707ee1401f28ac0e28db1b73d3941e Mon Sep 17 00:00:00 2001 From: Pietralberto Mazza <18440657+altafan@users.noreply.github.com> Date: Sat, 5 Oct 2024 16:33:55 +0200 Subject: [PATCH] Add env unlocker (#350) --- server/cmd/arkd/main.go | 1 + server/internal/app-config/config.go | 7 +++++- server/internal/config/config.go | 3 +++ .../infrastructure/unlocker/env/service.go | 23 +++++++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 server/internal/infrastructure/unlocker/env/service.go diff --git a/server/cmd/arkd/main.go b/server/cmd/arkd/main.go index 116ec596f..f66bf22a1 100755 --- a/server/cmd/arkd/main.go +++ b/server/cmd/arkd/main.go @@ -81,6 +81,7 @@ func mainAction(_ *cli.Context) error { BoardingExitDelay: cfg.BoardingExitDelay, UnlockerType: cfg.UnlockerType, UnlockerFilePath: cfg.UnlockerFilePath, + UnlockerPassword: cfg.UnlockerPassword, } svc, err := grpcservice.NewService(svcConfig, appConfig) if err != nil { diff --git a/server/internal/app-config/config.go b/server/internal/app-config/config.go index 59e6e75b7..24add35a4 100644 --- a/server/internal/app-config/config.go +++ b/server/internal/app-config/config.go @@ -12,6 +12,7 @@ import ( timescheduler "github.com/ark-network/ark/server/internal/infrastructure/scheduler/gocron" txbuilder "github.com/ark-network/ark/server/internal/infrastructure/tx-builder/covenant" cltxbuilder "github.com/ark-network/ark/server/internal/infrastructure/tx-builder/covenantless" + envunlocker "github.com/ark-network/ark/server/internal/infrastructure/unlocker/env" fileunlocker "github.com/ark-network/ark/server/internal/infrastructure/unlocker/file" btcwallet "github.com/ark-network/ark/server/internal/infrastructure/wallet/btc-embedded" liquidwallet "github.com/ark-network/ark/server/internal/infrastructure/wallet/liquid-standalone" @@ -41,6 +42,7 @@ var ( "btcwallet": {}, } supportedUnlockers = supportedType{ + "env": {}, "file": {}, } supportedNetworks = supportedType{ @@ -77,7 +79,8 @@ type Config struct { BitcoindRpcHost string UnlockerType string - UnlockerFilePath string + UnlockerFilePath string // file unlocker + UnlockerPassword string // env unlocker repo ports.RepoManager svc application.Service @@ -394,6 +397,8 @@ func (c *Config) unlockerService() error { switch c.UnlockerType { case "file": svc, err = fileunlocker.NewService(c.UnlockerFilePath) + case "env": + svc, err = envunlocker.NewService(c.UnlockerPassword) default: err = fmt.Errorf("unknown unlocker type") } diff --git a/server/internal/config/config.go b/server/internal/config/config.go index ba44727a8..94e0578db 100644 --- a/server/internal/config/config.go +++ b/server/internal/config/config.go @@ -38,6 +38,7 @@ type Config struct { TLSExtraDomains []string UnlockerType string UnlockerFilePath string + UnlockerPassword string } var ( @@ -69,6 +70,7 @@ var ( TLSExtraDomain = "TLS_EXTRA_DOMAIN" UnlockerType = "UNLOCKER_TYPE" UnlockerFilePath = "UNLOCKER_FILE_PATH" + UnlockerPassword = "UNLOCKER_PASSWORD" defaultDatadir = common.AppDataDir("arkd", false) defaultRoundInterval = 5 @@ -148,6 +150,7 @@ func LoadConfig() (*Config, error) { TLSExtraDomains: viper.GetStringSlice(TLSExtraDomain), UnlockerType: viper.GetString(UnlockerType), UnlockerFilePath: viper.GetString(UnlockerFilePath), + UnlockerPassword: viper.GetString(UnlockerPassword), }, nil } diff --git a/server/internal/infrastructure/unlocker/env/service.go b/server/internal/infrastructure/unlocker/env/service.go new file mode 100644 index 000000000..ca02c32c0 --- /dev/null +++ b/server/internal/infrastructure/unlocker/env/service.go @@ -0,0 +1,23 @@ +package envunlocker + +import ( + "context" + "fmt" + + "github.com/ark-network/ark/server/internal/core/ports" +) + +type service struct { + password string +} + +func NewService(password string) (ports.Unlocker, error) { + if len(password) <= 0 { + return nil, fmt.Errorf("missing password in env") + } + return &service{password}, nil +} + +func (s *service) GetPassword(_ context.Context) (string, error) { + return s.password, nil +}