{"record":{"id":"d996eab310001703","repo":"FuelLabs/fuels-ts","slug":"invalid-public-key","errorCode":"INVALID_PUBLIC_KEY","errorMessage":"Invalid Public Key: ${publicKey}.","messagePattern":"Invalid Public Key: (.+?)\\.","errorType":"validation","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/address/src/utils.ts","lineNumber":146,"sourceCode":" * @param address - The EVM address to convert\n * @returns The B256 address\n *\n * @hidden\n */\nexport const fromEvmAddressToB256 = (address: string): B256Address =>\n  padFirst12BytesOfEvmAddress(address);\n\n/**\n * Converts a Public Key to a B256 address\n *\n * @param publicKey - The Public Key to convert\n * @returns The B256 address\n *\n * @hidden\n */\nexport const fromPublicKeyToB256 = (publicKey: string): B256Address => {\n  if (!isPublicKey(publicKey)) {\n    throw new FuelError(FuelError.CODES.INVALID_PUBLIC_KEY, `Invalid Public Key: ${publicKey}.`);\n  }\n\n  return hexlify(sha256(arrayify(publicKey)));\n};\n\n/**\n * Converts a dynamic input to a B256 address\n *\n * @param address - The dynamic input to convert\n * @returns The B256 address\n *\n * @hidden\n */\nexport const fromDynamicInputToB256 = (address: string | Address): B256Address => {\n  if (typeof address !== 'string' && 'toB256' in address) {\n    return address.toB256();\n  }\n","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/address/src/utils.ts#L128-L164","documentation":"Thrown by fromPublicKeyToB256() (packages/address/src/utils.ts:146) when isPublicKey(publicKey) returns false. A valid Fuel public key is exactly 130 characters: 0x followed by 128 hex digits (512 bits / 64 bytes). The function hashes the public key with SHA-256 to derive a B256 address. An invalid key cannot be hashed meaningfully, so the format is validated first.","triggerScenarios":"Calling fromPublicKeyToB256() with a string that is not 130 characters matching 0x + 128 hex digits — e.g. a compressed public key (66 chars), a private key, a B256 address, or a key missing the 0x prefix.","commonSituations":"Deriving a Fuel address from an uncompressed secp256k1 public key; accidentally passing a compressed key or a B256 address instead; key material truncated or hex-encoded incorrectly (e.g. with a 0X uppercase prefix or whitespace).","solutions":["Validate with isPublicKey() before calling fromPublicKeyToB256().","Ensure you are passing the uncompressed public key (512 bits / 130 hex chars including 0x), not a compressed key (256 bits).","If deriving from a wallet, use the wallet's public key getter which returns the correct uncompressed format."],"exampleFix":"// before\nconst addr = fromPublicKeyToB256(maybeCompressedKey);\n\n// after\nimport { isPublicKey } from '@fuel-ts/address';\nif (!isPublicKey(publicKey)) {\n  throw new Error(`Expected uncompressed public key (0x + 128 hex), got length ${publicKey.length}`);\n}\nconst addr = fromPublicKeyToB256(publicKey);","handlingStrategy":"type-guard","validationCode":"import { isPublicKey } from '@fuel-ts/address';\n\nif (!isPublicKey(publicKey)) {\n  throw new Error(`Invalid public key: ${publicKey}. Must be 0x + 128 hex characters (uncompressed).`);\n}\nconst b256 = fromPublicKeyToB256(publicKey);","typeGuard":"import { isPublicKey } from '@fuel-ts/address';\n\nfunction isUncompressedPublicKey(value: string): boolean {\n  return value.length === 130 && /(0x)[0-9a-f]{128}$/i.test(value);\n}\n// Use isPublicKey() directly for the guard","tryCatchPattern":"try {\n  const b256 = fromPublicKeyToB256(publicKey);\n} catch (e) {\n  if (e instanceof FuelError && e.code === 'invalid-public-key') {\n    // key is not 0x + 128 hex; check for compressed key or missing prefix\n  }\n  throw e;\n}","preventionTips":["Validate with isPublicKey() before calling fromPublicKeyToB256().","Use uncompressed public keys (512 bits, 130 hex chars with 0x), not compressed (256 bits).","Obtain public keys from wallet.getPublicKey() or equivalent SDK methods that return the correct format."],"tags":["address","public-key","crypto","input-validation"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}