{"record":{"id":"89259a271377d23a","repo":"ipfs/kubo","slug":"cannot-create-new-key-w","errorCode":null,"errorMessage":"cannot create new key: %w","messagePattern":"cannot create new key: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/coreapi/key.go","lineNumber":32,"sourceCode":"\t\"github.com/ipfs/kubo/tracing\"\n\tcrypto \"github.com/libp2p/go-libp2p/core/crypto\"\n\tpeer \"github.com/libp2p/go-libp2p/core/peer\"\n\t\"go.opentelemetry.io/otel/attribute\"\n\t\"go.opentelemetry.io/otel/trace\"\n)\n\ntype KeyAPI CoreAPI\n\ntype key struct {\n\tname   string\n\tpeerID peer.ID\n\tpath   path.Path\n}\n\nfunc newKey(name string, pid peer.ID) (*key, error) {\n\tp, err := path.NewPath(\"/ipns/\" + ipns.NameFromPeer(pid).String())\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"cannot create new key: %w\", err)\n\t}\n\treturn &key{\n\t\tname:   name,\n\t\tpeerID: pid,\n\t\tpath:   p,\n\t}, nil\n}\n\n// Name returns the key name\nfunc (k *key) Name() string {\n\treturn k.name\n}\n\n// Path returns the path of the key.\nfunc (k *key) Path() path.Path {\n\treturn k.path\n}\n","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/coreapi/key.go#L14-L50","documentation":"newKey builds a key's IPLD path by turning the peer ID into an IPNS name and constructing \"/ipns/<name>\". If path.NewPath or ipns.NameFromPeer fails (malformed path or peer ID that cannot be converted to an IPNS name), the failure is wrapped as 'cannot create new key'.","triggerScenarios":"Any KeyAPI operation that materializes a key object (Generate, List, Rename, Remove, Self, Sign) when the peer ID derived from the key's public key cannot produce a valid IPNS name/path.","commonSituations":"A keystore entry corrupted so its derived peer ID is invalid; peer.IDFromPublicKey succeeded but ipns.NameFromPeer rejected the ID; unexpected identity key formats on repos created by very old or third-party tooling.","solutions":["Inspect the wrapped cause to see whether the peer ID or the path construction failed.","Verify the keystore entry: `ipfs key list` and remove/recreate the corrupted key.","Regenerate the key with `ipfs key gen` if its stored bytes are invalid.","Check repo integrity with `ipfs repo verify` / fsck the datastore."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if _, err := peer.IDFromPublicKey(pubKey); err != nil {\n    return fmt.Errorf(\"key has invalid public key: %w\", err)\n}","typeGuard":"func validPeerID(pid peer.ID) bool {\n    _, err := peer.ToCid(pid).Bytes()\n    return err == nil\n}","tryCatchPattern":"k, err := newKey(name, pid)\nif err != nil {\n    // key material corrupted; regenerate this keystore entry\n    return nil, fmt.Errorf(\"keystore entry %q unusable: %w\", name, err)\n}","preventionTips":["Keep keystore entries written only by kubo (no manual edits to $IPFS_PATH/keystore)","Back up the keystore directory","Recreate keys rather than importing hand-edited key material"],"tags":["keystore","ipns","peer-id"],"backgroundTag":"invalid-peer-id","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"}