OpenNHP/opennhp · error

relay: invalid privateKeyBase64

Error message

relay: invalid privateKeyBase64: %w

What it means

Raised in relay New while constructing the RelayServer: base64.StdEncoding.DecodeString of cfg.PrivateKeyBase64 failed. The relay's identity private key in config.toml is not valid standard base64 (wrong length, invalid characters, or URL-safe base64 pasted instead of Std).

Solutions

  1. Regenerate the relay key pair (e.g. keygen --curve) and paste the fresh PrivateKeyBase64 into config.toml
  2. Ensure the value was copied completely without truncation, whitespace or newlines
  3. Confirm the key was encoded with standard base64, not base64url
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at endpoints/relay/relay.go:196 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of OpenNHP/opennhp@6e04ca5ff0 (2026-09-07). Data as JSON: /api/errors/ad59cef857700a4e. Report an issue: GitHub.

Appendix: source

Thrown at endpoints/relay/relay.go:196

	sendMsgCh chan *core.MsgData
	recvMsgCh <-chan *core.PacketParserData

	wg      sync.WaitGroup
	running atomic.Bool
	stopCh  chan struct{}

	stats struct {
		totalRecvBytes uint64
		totalSendBytes uint64
	}
}

// New creates a RelayServer from the given configuration.
func New(cfg *Config) (*RelayServer, error) {
	// Decode relay private key.
	prk, err := base64.StdEncoding.DecodeString(cfg.PrivateKeyBase64)
	if err != nil {
		return nil, fmt.Errorf("relay: invalid privateKeyBase64: %w", err)
	}

	// Create NHP device with relay identity.
	device := core.NewDevice(core.NHP_RELAY, prk, nil)
	if device == nil {
		return nil, fmt.Errorf("relay: failed to create NHP device")
	}

	rs := &RelayServer{
		config:    cfg,
		device:    device,
		servers:   make(map[string]*serverRuntime, len(cfg.Servers)),
		sendMsgCh: make(chan *core.MsgData, PacketQueueSizePerConnection),
		stopCh:    make(chan struct{}),
	}
	rs.recvMsgCh = device.DecryptedMsgQueue

	for i := range cfg.Servers {

View on GitHub (pinned to 6e04ca5ff0)