{"record":{"id":"d9897a6eabb803a9","repo":"ipfs/kubo","slug":"unable-to-unmarshall-format-s-w","errorCode":null,"errorMessage":"unable to unmarshall format=%s: %w","messagePattern":"unable to unmarshall format=(.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/keystore.go","lineNumber":521,"sourceCode":"\t\t\t// In case ed25519.PrivateKey is returned we need the pointer for\n\t\t\t// conversion to libp2p (see export command for more details).\n\t\t\tif ed25519KeyPointer, ok := stdKey.(ed25519.PrivateKey); ok {\n\t\t\t\tstdKey = &ed25519KeyPointer\n\t\t\t}\n\n\t\t\tsk, _, err = crypto.KeyPairFromStdKey(stdKey)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"converting std Go key to libp2p key: %w\", err)\n\t\t\t}\n\t\tcase keyFormatLibp2pCleartextOption:\n\t\t\tsk, err = crypto.UnmarshalPrivateKey(data)\n\t\t\tif err != nil {\n\t\t\t\t// check if data is PEM, if so, provide user with hint\n\t\t\t\tpemBlock, _ := pem.Decode(data)\n\t\t\t\tif pemBlock != nil {\n\t\t\t\t\treturn fmt.Errorf(\"unexpected PEM block for format=%s: try again with format=%s\", keyFormatLibp2pCleartextOption, keyFormatPemCleartextOption)\n\t\t\t\t}\n\t\t\t\treturn fmt.Errorf(\"unable to unmarshall format=%s: %w\", keyFormatLibp2pCleartextOption, err)\n\t\t\t}\n\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"unrecognized import format: %s\", importFormat)\n\t\t}\n\n\t\t// We only allow importing keys of the same type we generate (see list in\n\t\t// https://github.com/ipfs/interface-go-ipfs-core/blob/1c3d8fc/options/key.go#L58-L60),\n\t\t// unless explicitly stated by the user.\n\t\tallowAnyKeyType, _ := req.Options[keyAllowAnyTypeOptionName].(bool)\n\t\tif !allowAnyKeyType {\n\t\t\tswitch t := sk.(type) {\n\t\t\tcase *crypto.RsaPrivateKey, *crypto.Ed25519PrivateKey, *crypto.Secp256k1PrivateKey:\n\t\t\tdefault:\n\t\t\t\treturn fmt.Errorf(\"key type %T is not allowed to be imported, only RSA, Ed25519, or Secp256k1;\"+\n\t\t\t\t\t\" use flag --%s if you are sure of what you're doing\",\n\t\t\t\t\tt, keyAllowAnyTypeOptionName)\n\t\t\t}","sourceCodeStart":503,"sourceCodeEnd":539,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/keystore.go#L503-L539","documentation":"The input was not a PEM block, but crypto.UnmarshalPrivateKey (libp2p protobuf-cleartext format) failed to decode the bytes as a valid libp2p private key. The wrapped error carries the underlying protobuf/unmarshal reason.","triggerScenarios":"`ipfs key import name keyfile` (default format) where keyfile is garbage, a corrupted export from `ipfs key export`, a raw openssl/PEM-ish file that pem.Decode also rejects, or a truncated protobuf key.","commonSituations":"Importing a file exported with a different `--format` than used at import time, binary corruption during transfer, or accidentally importing a public key or certificate.","solutions":["Confirm the file's origin and format: `file keyfile` and compare with how it was exported (`ipfs key export --format=...`)","Re-export the key from the source node and retry the import","If it is a PEM key, use `-f pem-pkcs8-cleartext` (note error 343 covers the detectable PEM case)","Check file size/integrity; re-copy if the transfer may have truncated it"],"exampleFix":"// before: format mismatch between export and import\n$ ipfs key export mykey -f pem-pkcs8-cleartext > k.pem && ipfs key import mykey k.pem\nError: unable to unmarshall format=libp2p-protobuf-cleartext: ...\n// after: match formats\n$ ipfs key import mykey -f pem-pkcs8-cleartext k.pem","handlingStrategy":"validation","validationCode":"info, _ := os.Stat(keyFile)\nif info.Size() == 0 || info.Size() < 16 {\n    return fmt.Errorf(\"key file %s looks truncated or empty\", keyFile)\n}\n// also verify it is not PEM (that needs -f pem-pkcs8-cleartext)","typeGuard":null,"tryCatchPattern":"if err := importKey(); err != nil {\n    if strings.Contains(err.Error(), \"unable to unmarshall\") {\n        // wrong format or corrupt file: re-export from source node\n    }\n}","preventionTips":["Export and import with the same `--format` value","Check file integrity after copying (size, sha256sum)","Do not import public keys or certificates with key import"],"tags":["keystore","libp2p","protobuf","key-import","corrupt-input"],"backgroundTag":"key-unmarshal-failed","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"}