alby-hub/config/models.go
Roland 3b3c37dd0c
fix: remove legacy acceptance of empty unlock password check (#2534)
* fix: remove legacy acceptance of empty unlock password check

CheckUnlockPassword previously treated a missing or empty
UnlockPasswordCheck value as a match — a legacy compatibility path from
before the canary was always written. It now requires the stored value
to be present and to equal the expected string.

StartApp checks for the canary up front and, if it is missing, stops
with a message asking the user to restore from a backup rather than
continuing. A new IsUnlockPasswordCheckSet helper reports whether the
value is present.

keys.Init now returns the error from reading NostrSecretKey instead of
ignoring it, so a read failure aborts instead of generating and saving a
new key.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* chore: add operation context to unlock password check errors

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-12 14:48:06 +07:00

106 lines
5.8 KiB
Go

package config
const (
LNDBackendType = "LND"
LDKBackendType = "LDK"
PhoenixBackendType = "PHOENIX"
CashuBackendType = "CASHU"
CLNBackendType = "CLN"
BarkBackendType = "BARK"
)
const (
OnchainAddressKey = "OnchainAddress"
AutoSwapBalanceThresholdKey = "AutoSwapBalanceThreshold"
AutoSwapAmountKey = "AutoSwapAmount"
AutoSwapDestinationKey = "AutoSwapDestination"
AutoSwapXpubIndexStart = "AutoSwapXpubIndexStart"
)
type AppConfig struct {
Relay string `envconfig:"RELAY" default:"wss://relay.getalby.com,wss://relay2.getalby.com"`
LNBackendType string `envconfig:"LN_BACKEND_TYPE"`
LNDAddress string `envconfig:"LND_ADDRESS"`
LNDCertFile string `envconfig:"LND_CERT_FILE"`
LNDMacaroonFile string `envconfig:"LND_MACAROON_FILE"`
Workdir string `envconfig:"WORK_DIR"`
Port string `envconfig:"PORT" default:"8080"`
DatabaseUri string `envconfig:"DATABASE_URI" default:"nwc.db"`
LogLevel string `envconfig:"LOG_LEVEL" default:"4"`
LogToFile bool `envconfig:"LOG_TO_FILE" default:"true"`
Network string `envconfig:"NETWORK"`
LDKNetwork string `envconfig:"LDK_NETWORK"`
LDKEsploraServer string `envconfig:"LDK_ESPLORA_SERVER" default:"https://electrs.getalbypro.com"` // TODO: remove LDK prefix
LDKElectrumServer string `envconfig:"LDK_ELECTRUM_SERVER"`
LDKGossipSource string `envconfig:"LDK_GOSSIP_SOURCE"`
LDKLogLevel string `envconfig:"LDK_LOG_LEVEL" default:"3"`
LDKMaxChannelSaturationPowerOfHalf uint8 `envconfig:"LDK_MAX_CHANNEL_SATURATION" default:"2"`
LDKMaxPathCount uint8 `envconfig:"LDK_MAX_PATH_COUNT" default:"5"`
LDKChannelMonitorWarningSizeBytes uint64 `envconfig:"LDK_CHANNEL_MONITOR_WARNING_SIZE_BYTES" default:"5000000"`
LDKVssUrl string `envconfig:"LDK_VSS_URL" default:"https://vss.getalbypro.com/vss"`
LDKLiquiditySourceLsps2 string `envconfig:"LDK_LSPS2_ADDRESSES"`
LDKListeningAddresses string `envconfig:"LDK_LISTENING_ADDRESSES" default:"[::]:9735"`
LDKAnnouncementAddresses string `envconfig:"LDK_ANNOUNCEMENT_ADDRESSES"`
LDKTransientNetworkGraph bool `envconfig:"LDK_TRANSIENT_NETWORK_GRAPH" default:"false"`
RebalanceServiceUrl string `envconfig:"REBALANCE_SERVICE_URL" default:"https://megalithic.me"`
LDKBitcoindRpcHost string `envconfig:"LDK_BITCOIND_RPC_HOST"`
LDKBitcoindRpcPort string `envconfig:"LDK_BITCOIND_RPC_PORT"`
LDKBitcoindRpcUser string `envconfig:"LDK_BITCOIND_RPC_USER"`
LDKBitcoindRpcPassword string `envconfig:"LDK_BITCOIND_RPC_PASSWORD"`
MempoolApi string `envconfig:"MEMPOOL_API" default:"https://mempool.space/api"`
AlbyClientId string `envconfig:"ALBY_OAUTH_CLIENT_ID" default:"J2PbXS1yOf"`
AlbyClientSecret string `envconfig:"ALBY_OAUTH_CLIENT_SECRET" default:"rABK2n16IWjLTZ9M1uKU"`
BaseUrl string `envconfig:"BASE_URL"`
FrontendUrl string `envconfig:"FRONTEND_URL"`
SendEventsToAlby bool `envconfig:"SEND_EVENTS_TO_ALBY" default:"true"`
AutoLinkAlbyAccount bool `envconfig:"AUTO_LINK_ALBY_ACCOUNT" default:"true"`
PhoenixdAddress string `envconfig:"PHOENIXD_ADDRESS"`
PhoenixdAuthorization string `envconfig:"PHOENIXD_AUTHORIZATION"`
GoProfilerAddr string `envconfig:"GO_PROFILER_ADDR"`
EnableAdvancedSetup bool `envconfig:"ENABLE_ADVANCED_SETUP" default:"true"`
AutoUnlockPassword string `envconfig:"AUTO_UNLOCK_PASSWORD"`
LogDBQueries bool `envconfig:"LOG_DB_QUERIES" default:"false"`
BoltzApi string `envconfig:"BOLTZ_API" default:"https://api.boltz.exchange"`
HideUpdateBanner bool `envconfig:"HIDE_UPDATE_BANNER" default:"false"`
CLNAddress string `envconfig:"CLN_ADDRESS"`
CLNLightningDir string `envconfig:"CLN_LIGHTNING_DIR"`
CLNAddressHold string `envconfig:"CLN_ADDRESS_HOLD"`
BarkServer string `envconfig:"BARK_SERVER" default:"https://ark.second.tech"`
BarkEsploraServer string `envconfig:"BARK_ESPLORA_SERVER" default:"https://mempool.second.tech/api"`
BarkServerAccessToken string `envconfig:"BARK_SERVER_ACCESS_TOKEN"`
BarkLogLevel string `envconfig:"BARK_LOG_LEVEL" default:"3"`
}
func (c *AppConfig) IsDefaultClientId() bool {
return c.AlbyClientId == "J2PbXS1yOf"
}
func (c *AppConfig) GetBaseFrontendUrl() string {
url := c.FrontendUrl
if url == "" {
url = c.BaseUrl
}
return url
}
type Config interface {
Get(key string, encryptionKey string) (string, error)
SetIgnore(key string, value string, encryptionKey string) error
SetUpdate(key string, value string, encryptionKey string) error
LoadJWTSecret(encryptionKey string) error
GetJWTSecret() (string, error)
GetRelayUrls() []string
GetNetwork() string
GetMempoolUrl() string
GetEnv() *AppConfig
CheckUnlockPassword(password string) bool
IsUnlockPasswordCheckSet() (bool, error)
ChangeUnlockPassword(currentUnlockPassword string, newUnlockPassword string) error
SetAutoUnlockPassword(unlockPassword string) error
SaveUnlockPasswordCheck(encryptionKey string) error
SetupCompleted() (bool, error)
GetCurrency() string
SetCurrency(value string) error
GetBitcoinDisplayFormat() string
SetBitcoinDisplayFormat(value string) error
}