Skip to content

Commit

Permalink
fix: initialize keys before starting ln backend
Browse files Browse the repository at this point in the history
  • Loading branch information
rolznz committed Oct 31, 2024
1 parent 03aa76f commit 631aa3c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
5 changes: 5 additions & 0 deletions service/keys/keys.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package keys

import (
"errors"

"github.com/getAlby/hub/config"
"github.com/getAlby/hub/logger"
"github.com/nbd-wtf/go-nostr"
Expand Down Expand Up @@ -81,6 +83,9 @@ func (keys *keys) GetNostrSecretKey() string {
}

func (keys *keys) DeriveKey(path []uint32) (*bip32.Key, error) {
if keys.appKey == nil {
return nil, errors.New("app key not set")
}
key := keys.appKey
for _, index := range path {
var err error
Expand Down
19 changes: 10 additions & 9 deletions service/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,10 @@ import (
"github.com/getAlby/hub/logger"
)

func (svc *service) startNostr(ctx context.Context, encryptionKey string) error {
func (svc *service) startNostr(ctx context.Context) error {

relayUrl := svc.cfg.GetRelayUrl()

err := svc.keys.Init(svc.cfg, encryptionKey)
if err != nil {
logger.Logger.WithError(err).Error("Failed to init nostr keys")
return err
}

npub, err := nip19.EncodePublicKey(svc.keys.GetNostrPublicKey())
if err != nil {
logger.Logger.WithError(err).Error("Error converting nostr privkey to pubkey")
Expand Down Expand Up @@ -130,7 +124,14 @@ func (svc *service) StartApp(encryptionKey string) error {

ctx, cancelFn := context.WithCancel(svc.ctx)

err := svc.launchLNBackend(ctx, encryptionKey)
err := svc.keys.Init(svc.cfg, encryptionKey)
if err != nil {
logger.Logger.WithError(err).Error("Failed to init nostr keys")
cancelFn()
return err
}

err = svc.launchLNBackend(ctx, encryptionKey)
if err != nil {
logger.Logger.Errorf("Failed to launch LN backend: %v", err)
svc.eventPublisher.Publish(&events.Event{
Expand All @@ -140,7 +141,7 @@ func (svc *service) StartApp(encryptionKey string) error {
return err
}

err = svc.startNostr(ctx, encryptionKey)
err = svc.startNostr(ctx)
if err != nil {
cancelFn()
return err
Expand Down

0 comments on commit 631aa3c

Please sign in to comment.