ipfs/kubo · error

identity not loaded

Error message

identity not loaded

What it means

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.

Source

Thrown at core/coreapi/key.go:275

	pubKey := removed.GetPublic()

	pid, err := peer.IDFromPublicKey(pubKey)
	if err != nil {
		return nil, err
	}

	err = ks.Delete(name)
	if err != nil {
		return nil, err
	}

	return newKey("", pid)
}

func (api *KeyAPI) Self(ctx context.Context) (coreiface.Key, error) {
	if api.identity == "" {
		return nil, errors.New("identity not loaded")
	}

	return newKey("self", api.identity)
}

const signedMessagePrefix = "libp2p-key signed message:"

func (api *KeyAPI) Sign(ctx context.Context, name string, data []byte) (coreiface.Key, []byte, error) {
	var (
		sk  crypto.PrivKey
		err error
	)
	if name == "" || name == "self" {
		name = "self"
		sk = api.privateKey
	} else {
		sk, err = api.repo.Keystore().Get(name)
	}

View on GitHub (pinned to 329838acdf)

Solutions

  1. Ensure the node is constructed with a valid identity (repo with a peer private key) before calling Self.
  2. When building CoreAPI manually, set the identity option on the KeyAPI.
  3. Fall back to Key().Get(ctx, "self") or reading the peerstore if you only need the public key.

Example fix

// before
k, err := api.Key().Self(ctx)
// after
k, err := api.Key().Get(ctx, "self")
if err != nil {
    return fmt.Errorf("identity unavailable: %w", err)
}
Defensive patterns

Strategy: try-catch

Validate before calling

if api == nil || api.Key() == nil {
    return fmt.Errorf("key API unavailable")
}

Try / catch

k, err := api.Key().Self(ctx)
if err != nil {
    // fall back to keystore lookup of "self"
    k, err = api.Key().Get(ctx, "self")
    if err != nil {
        return fmt.Errorf("node identity unavailable: %w", err)
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: Using kubo-as-a-library with a manually assembled CoreAPI that omitted the identity; daemon started with a repo lacking a valid peer key.

Related errors


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