ipfs/kubo · error

unrecognized import format: %s

Error message

unrecognized import format: %s

What it means

Switch-default guard in `ipfs key import`: the value of the --format option is not one of the recognized import formats (pem-pkcs8-cleartext or libp2p-protobuf-cleartext). A plain sentinel error naming the unsupported format string; the input file was never parsed.

Source

Thrown at core/commands/keystore.go:525

			}

			sk, _, err = crypto.KeyPairFromStdKey(stdKey)
			if err != nil {
				return fmt.Errorf("converting std Go key to libp2p key: %w", err)
			}
		case keyFormatLibp2pCleartextOption:
			sk, err = crypto.UnmarshalPrivateKey(data)
			if err != nil {
				// check if data is PEM, if so, provide user with hint
				pemBlock, _ := pem.Decode(data)
				if pemBlock != nil {
					return fmt.Errorf("unexpected PEM block for format=%s: try again with format=%s", keyFormatLibp2pCleartextOption, keyFormatPemCleartextOption)
				}
				return fmt.Errorf("unable to unmarshall format=%s: %w", keyFormatLibp2pCleartextOption, err)
			}

		default:
			return fmt.Errorf("unrecognized import format: %s", importFormat)
		}

		// We only allow importing keys of the same type we generate (see list in
		// https://github.com/ipfs/interface-go-ipfs-core/blob/1c3d8fc/options/key.go#L58-L60),
		// unless explicitly stated by the user.
		allowAnyKeyType, _ := req.Options[keyAllowAnyTypeOptionName].(bool)
		if !allowAnyKeyType {
			switch t := sk.(type) {
			case *crypto.RsaPrivateKey, *crypto.Ed25519PrivateKey, *crypto.Secp256k1PrivateKey:
			default:
				return fmt.Errorf("key type %T is not allowed to be imported, only RSA, Ed25519, or Secp256k1;"+
					" use flag --%s if you are sure of what you're doing",
					t, keyAllowAnyTypeOptionName)
			}
		}

		cfgRoot, err := cmdenv.GetConfigRoot(env)
		if err != nil {

View on GitHub (pinned to 329838acdf)

Solutions

  1. Pass --format=libp2p-protobuf-cleartext for keys exported by ipfs key export in default format
  2. Pass --format=pem-pkcs8-cleartext for PEM PKCS8 private keys
  3. Omit --format to use the default and check `ipfs key import --help` for valid values

Example fix

// before
$ ipfs key import mykey -f pem key.pem
Error: unrecognized import format: pem
// after
$ ipfs key import mykey -f pem-pkcs8-cleartext key.pem
Defensive patterns

Strategy: validation

Validate before calling

var validFormats = map[string]bool{"libp2p-protobuf-cleartext": true, "pem-pkcs8-cleartext": true}
if !validFormats[format] {
    return fmt.Errorf("unsupported --format %q; use libp2p-protobuf-cleartext or pem-pkcs8-cleartext", format)
}

Prevention

When it happens

Trigger: `ipfs key import name -f pem key.pem`, `-f pkcs8`, `-f openssl`, or any typo/abbreviation of the two supported values.

Common situations: Guessing the flag value instead of copying it from `ipfs key import --help`; older scripts using format names from other tools.

Understand the failure class

Background: "unknown output mode", "invalid value for flag", "expects true/false": fixing invalid flag value errors in CLI tools — this error's family across 24 libraries.

Related errors


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