Skip to content

Commit

Permalink
Add env unlocker (#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
altafan authored Oct 5, 2024
1 parent 0d39bb6 commit bc8df68
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions server/cmd/arkd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion server/internal/app-config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -41,6 +42,7 @@ var (
"btcwallet": {},
}
supportedUnlockers = supportedType{
"env": {},
"file": {},
}
supportedNetworks = supportedType{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
Expand Down
3 changes: 3 additions & 0 deletions server/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Config struct {
TLSExtraDomains []string
UnlockerType string
UnlockerFilePath string
UnlockerPassword string
}

var (
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
23 changes: 23 additions & 0 deletions server/internal/infrastructure/unlocker/env/service.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit bc8df68

Please sign in to comment.