{"record":{"id":"0d1729426685a568","repo":"nautechsystems/nautilus_trader","slug":"signer-private-key-in-is-not-a-valid-hex-priv","errorCode":null,"errorMessage":"Signer private key in '{}' is not a valid hex private key","messagePattern":"Signer private key in '(.+?)' is not a valid hex private key","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/execution/client.rs","lineNumber":6178,"sourceCode":"            )\n        } else {\n            None\n        };\n\n        // Load the signer key from the configured environment variable; the key is never\n        // logged, serialized, or stored in configuration\n        let private_key = Zeroizing::new(\n            std::env::var(&self.config.signer_private_key_env).map_err(|_| {\n                anyhow::anyhow!(\n                    \"Signer private key environment variable '{}' is not set\",\n                    self.config.signer_private_key_env\n                )\n            })?,\n        );\n        let encoded_key = private_key.trim();\n        let encoded_key = encoded_key.strip_prefix(\"0x\").unwrap_or(encoded_key);\n        let key_bytes = Zeroizing::new(hex::decode_array::<32>(encoded_key).map_err(|_| {\n            anyhow::anyhow!(\n                \"Signer private key in '{}' is not a valid hex private key\",\n                self.config.signer_private_key_env\n            )\n        })?);\n        let signer = PrivateKeySigner::from_slice(&key_bytes[..]).map_err(|_| {\n            anyhow::anyhow!(\n                \"Signer private key in '{}' is not a valid secp256k1 private key\",\n                self.config.signer_private_key_env\n            )\n        })?;\n\n        if signer.address() != self.wallet_address {\n            anyhow::bail!(\n                \"Signer address {} derived from '{}' does not match configured wallet address {}\",\n                signer.address(),\n                self.config.signer_private_key_env,\n                self.wallet_address\n            );","sourceCodeStart":6160,"sourceCodeEnd":6196,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/execution/client.rs#L6160-L6196","documentation":"After trimming and stripping an optional 0x prefix, the signer key must decode into exactly 32 bytes via hex::decode_array::<32>. If the value contains non-hex characters or is not exactly 32 bytes, initialization fails with this error.","triggerScenarios":"hex::decode_array::<32>(encoded_key) errors — the env var value is not valid hex, has wrong length (not 64 hex chars after optional 0x), contains whitespace inside, or includes stray quotes.","commonSituations":"Copying a key wrapped in quotes from an export, pasting a truncated key, using a base64 or mnemonic seed phrase instead of a hex private key, or including '0x' twice or internal spaces.","solutions":["Set the env var to exactly 64 hex characters (optionally with a single 0x prefix), e.g. 0xabc...def (128/64 chars check).","Remove surrounding quotes, newlines, or trailing whitespace from the stored secret.","Confirm you are providing a raw secp256k1 private key, not a mnemonic phrase, JSON keystore, or base64 key.","Validate locally: printf '%s' \"$VAR\" | grep -Eq '^(0x)?[0-9a-fA-F]{64}$' before launching."],"exampleFix":"// before\nexport SIGNER_KEY=\"0xabc123\"           // truncated, quoted\n\n// after\nexport SIGNER_KEY=0xabc123...full-64-hex-chars...   // unquoted, exactly 64 hex chars","handlingStrategy":"validation","validationCode":"fn is_hex_key(s: &str) -> bool {\n    let t = s.trim().strip_prefix(\"0x\").unwrap_or(s.trim());\n    t.len() == 64 && t.chars().all(|c| c.is_ascii_hexdigit())\n}","typeGuard":"fn valid_private_key_env(v: &str) -> bool { let t = v.trim().strip_prefix(\"0x\").unwrap_or(v.trim()); t.len() == 64 && t.chars().all(|c| c.is_ascii_hexdigit()) }","tryCatchPattern":"if !valid_private_key_env(&std::env::var(\"SIGNER_KEY\")?) { eprintln!(\"SIGNER_KEY must be 64 hex chars, optional 0x\"); }","preventionTips":["Store the key as raw 64-char hex without quotes or whitespace","Never paste mnemonics or keystores where a raw hex key is expected","Lint secrets format at injection time in CI/deploy scripts","Trim and 0x-strip defensively before validation"],"tags":["hex","format-validation","signing","secrets"],"backgroundTag":"invalid-argument-format","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}