ipfs/kubo · error

failed to determine peer ID for private key: %w

Error message

failed to determine peer ID for private key: %w

What it means

The internal keylookup helper (used by Publish) derives the peer ID of the node's 'self' private key to match against the requested target. If peer.IDFromPrivateKey fails, the failure is wrapped with this message, meaning the stored identity key is malformed or unreadable.

Source

Thrown at core/coreapi/name.go:226

	}

	keys, err := kstore.List()
	if err != nil {
		return nil, err
	}

	//////////////////
	// Lookup by ID //
	//////////////////
	targetPid, err := peer.Decode(k)
	if err != nil {
		return nil, keystore.ErrNoSuchKey
	}

	// First, check self.
	pid, err := peer.IDFromPrivateKey(self)
	if err != nil {
		return nil, fmt.Errorf("failed to determine peer ID for private key: %w", err)
	}
	if pid == targetPid {
		return self, nil
	}

	// Then, look in the keystore.
	for _, key := range keys {
		privKey, err := kstore.Get(key)
		if err != nil {
			return nil, err
		}

		pid, err := peer.IDFromPrivateKey(privKey)
		if err != nil {
			return nil, err
		}

		if targetPid == pid {

View on GitHub (pinned to 329838acdf)

Solutions

  1. Check the wrapped cause (%w) — likely an unsupported key type or malformed key data.
  2. Regenerate the node identity: re-initialize the repo or restore a valid peer key.
  3. Verify `ipfs id` works; if it fails with the same root cause, the identity key is corrupt.
  4. If you meant to publish with a named key, pass that key's name instead of relying on self.

Example fix

// before
ipfs name publish /ipfs/<cid>  # with corrupt self key
// after
ipfs id  # diagnose identity first
ipfs key gen publish-key && ipfs name publish --key=publish-key /ipfs/<cid>
Defensive patterns

Strategy: validation

Validate before calling

// confirm the node identity is usable before publishing
if _, err := api.Key().Get(ctx, "self"); err != nil {
    return fmt.Errorf("node identity key unusable: %w", err)
}

Try / catch

_, err := api.Name().Publish(ctx, p, opts.Key(target))
if err != nil && strings.Contains(err.Error(), "failed to determine peer ID") {
    return fmt.Errorf("node identity corrupt; regenerate or restore the repo: %w", err)
}

Prevention

When it happens

Trigger: Calling Publish (with a Key or PeerID selector) when the node's self private key cannot produce a peer ID, e.g. a corrupted keystore or unsupported key type.

Common situations: Repo migrated between nodes with a damaged 'self' key; keystore file truncated or hand-edited; key generated by incompatible software.

Related errors


AI-assisted analysis of ipfs/kubo@329838acdf (2026-09-03). Data as JSON: /api/errors/9ec48b6ea0ec906f. Report an issue: GitHub.