{"record":{"id":"9ec48b6ea0ec906f","repo":"ipfs/kubo","slug":"failed-to-determine-peer-id-for-private-key-w","errorCode":null,"errorMessage":"failed to determine peer ID for private key: %w","messagePattern":"failed to determine peer ID for private key: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/coreapi/name.go","lineNumber":226,"sourceCode":"\t}\n\n\tkeys, err := kstore.List()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\t//////////////////\n\t// Lookup by ID //\n\t//////////////////\n\ttargetPid, err := peer.Decode(k)\n\tif err != nil {\n\t\treturn nil, keystore.ErrNoSuchKey\n\t}\n\n\t// First, check self.\n\tpid, err := peer.IDFromPrivateKey(self)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to determine peer ID for private key: %w\", err)\n\t}\n\tif pid == targetPid {\n\t\treturn self, nil\n\t}\n\n\t// Then, look in the keystore.\n\tfor _, key := range keys {\n\t\tprivKey, err := kstore.Get(key)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\tpid, err := peer.IDFromPrivateKey(privKey)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\tif targetPid == pid {","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/coreapi/name.go#L208-L244","documentation":"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.","triggerScenarios":"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.","commonSituations":"Repo migrated between nodes with a damaged 'self' key; keystore file truncated or hand-edited; key generated by incompatible software.","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."],"exampleFix":"// before\nipfs name publish /ipfs/<cid>  # with corrupt self key\n// after\nipfs id  # diagnose identity first\nipfs key gen publish-key && ipfs name publish --key=publish-key /ipfs/<cid>","handlingStrategy":"validation","validationCode":"// confirm the node identity is usable before publishing\nif _, err := api.Key().Get(ctx, \"self\"); err != nil {\n    return fmt.Errorf(\"node identity key unusable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"_, err := api.Name().Publish(ctx, p, opts.Key(target))\nif err != nil && strings.Contains(err.Error(), \"failed to determine peer ID\") {\n    return fmt.Errorf(\"node identity corrupt; regenerate or restore the repo: %w\", err)\n}","preventionTips":["Check `ipfs id` works as a health check for the identity key.","Never hand-edit keystore files.","Back up the repo identity before migrations."],"tags":["ipns","identity","keystore","corruption"],"backgroundTag":"invalid-private-key","analyzedSha":"329838acdfafae224582930457efe80aa217afc0","analyzedAt":"2026-09-03T18:30:52.135Z","contentChangedAt":"2026-09-03T18:30:52.135Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}