Skip to content

Commit

Permalink
vspadmin: Reject private keys in fee xpub config.
Browse files Browse the repository at this point in the history
The provided key should always be a public key, enforcing this in
software provides an extra safety net for users.
  • Loading branch information
jholdstock committed Jun 19, 2024
1 parent 4e5fec8 commit 1fa81d3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cmd/vspadmin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package main

import (
"errors"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -54,11 +55,16 @@ func createDatabase(homeDir string, feeXPub string, network *config.Network) err
}

// Ensure provided xpub is a valid key for the selected network.
_, err := hdkeychain.NewKeyFromString(feeXPub, network.Params)
feeXpub, err := hdkeychain.NewKeyFromString(feeXPub, network.Params)
if err != nil {
return fmt.Errorf("failed to parse feexpub: %w", err)
}

// Ensure key is public.
if feeXpub.IsPrivate() {
return errors.New("feexpub is a private key, should be public")
}

// Ensure the data directory exists.
err = os.MkdirAll(dataDir, 0700)
if err != nil {
Expand Down

0 comments on commit 1fa81d3

Please sign in to comment.