Skip to content

Commit

Permalink
fix: for backends that don't use a mnemonic, create appKey from nostr…
Browse files Browse the repository at this point in the history
…SecretKey
  • Loading branch information
frnandu committed Nov 4, 2024
1 parent 606c33b commit 877509e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 0 additions & 1 deletion nip47/notifications/nip47_notifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"github.com/nbd-wtf/go-nostr"
"github.com/stretchr/testify/require"
"testing"
"time"

Expand Down
17 changes: 17 additions & 0 deletions service/keys/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@ func (keys *keys) Init(cfg config.Config, encryptionKey string) error {
keys.appKey = appKey
}

// for backends that don't use a mnemonic, create appKey from nostrSecretKey
if keys.appKey == nil {
// Convert nostrSecretKey to btcec private key
privKeyBytes, err := hex.DecodeString(keys.nostrSecretKey)
if err != nil {
return err
}
privKey, _ := btcec.PrivKeyFromBytes(privKeyBytes)

// Create a BIP32 master key from the private key
masterKey, err := bip32.NewMasterKey(privKey.Serialize())
if err != nil {
return err
}
keys.appKey = masterKey
}

return nil
}

Expand Down

0 comments on commit 877509e

Please sign in to comment.