{"record":{"id":"a5af5140fb0ceadf","repo":"ipfs/kubo","slug":"identity-not-loaded","errorCode":null,"errorMessage":"identity not loaded","messagePattern":"identity not loaded","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/coreapi/key.go","lineNumber":275,"sourceCode":"\n\tpubKey := removed.GetPublic()\n\n\tpid, err := peer.IDFromPublicKey(pubKey)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\terr = ks.Delete(name)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn newKey(\"\", pid)\n}\n\nfunc (api *KeyAPI) Self(ctx context.Context) (coreiface.Key, error) {\n\tif api.identity == \"\" {\n\t\treturn nil, errors.New(\"identity not loaded\")\n\t}\n\n\treturn newKey(\"self\", api.identity)\n}\n\nconst signedMessagePrefix = \"libp2p-key signed message:\"\n\nfunc (api *KeyAPI) Sign(ctx context.Context, name string, data []byte) (coreiface.Key, []byte, error) {\n\tvar (\n\t\tsk  crypto.PrivKey\n\t\terr error\n\t)\n\tif name == \"\" || name == \"self\" {\n\t\tname = \"self\"\n\t\tsk = api.privateKey\n\t} else {\n\t\tsk, err = api.repo.Keystore().Get(name)\n\t}","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/coreapi/key.go#L257-L293","documentation":"KeyAPI.Self returns the node's own identity key, but only if the KeyAPI was constructed with an identity. If api.identity is empty (identity not wired into the API instance), the call fails with this error.","triggerScenarios":"Calling KeyAPI.Self(ctx) on a CoreAPI instance whose identity field was never set, e.g. a partially constructed or offline node core lacking a loaded private key.","commonSituations":"Using kubo-as-a-library with a manually assembled CoreAPI that omitted the identity; daemon started with a repo lacking a valid peer key.","solutions":["Ensure the node is constructed with a valid identity (repo with a peer private key) before calling Self.","When building CoreAPI manually, set the identity option on the KeyAPI.","Fall back to Key().Get(ctx, \"self\") or reading the peerstore if you only need the public key."],"exampleFix":"// before\nk, err := api.Key().Self(ctx)\n// after\nk, err := api.Key().Get(ctx, \"self\")\nif err != nil {\n    return fmt.Errorf(\"identity unavailable: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"if api == nil || api.Key() == nil {\n    return fmt.Errorf(\"key API unavailable\")\n}","typeGuard":null,"tryCatchPattern":"k, err := api.Key().Self(ctx)\nif err != nil {\n    // fall back to keystore lookup of \"self\"\n    k, err = api.Key().Get(ctx, \"self\")\n    if err != nil {\n        return fmt.Errorf(\"node identity unavailable: %w\", err)\n    }\n}","preventionTips":["Only call Self on a fully constructed node core with a loaded identity.","In library usage, pass the identity when wiring CoreAPI.","Confirm `ipfs id` succeeds before using identity-dependent APIs."],"tags":["identity","ipfs","initialization"],"backgroundTag":"identity-not-loaded","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"}