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
- Check the wrapped cause (%w) — likely an unsupported key type or malformed key data.
- Regenerate the node identity: re-initialize the repo or restore a valid peer key.
- Verify `ipfs id` works; if it fails with the same root cause, the identity key is corrupt.
- 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
- Check `ipfs id` works as a health check for the identity key.
- Never hand-edit keystore files.
- Back up the repo identity before migrations.
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
- cannot import key with name 'self'
- cannot create new key: %w
- cannot remove key with name 'self'
- no key by the given name or PeerID was found
- got unexpected number of keys back
AI-assisted analysis of ipfs/kubo@329838acdf (2026-09-03).
Data as JSON: /api/errors/9ec48b6ea0ec906f.
Report an issue: GitHub.