> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://v3.viem.sh/api/mcp` to find what you need.

# PublicKey.assert

:::info
`PublicKey.assert` is a re-export of ox's [`PublicKey.assert`](https://oxlib.sh/api/PublicKey/assert). Refer to the ox documentation for the full reference.
:::

Asserts that a [`PublicKey.PublicKey`](/docs/utilities/publickey/types#publickey) is valid.

## Imports

```ts
import { PublicKey } from 'viem/utils'
```

## Examples

```ts twoslash
// @noErrors
import { PublicKey } from 'viem/utils'

PublicKey.assert({
  prefix: 4,
  y: '0x6e1c1f59ee1cf25b75a8d57b3c89e7e6b3b1da823df8b3b89497f30c1f000000'
})
// @error: PublicKey.InvalidError: Value \`{"y":"0x..."}\` is not a valid public key.
// @error: Public key must contain:
// @error: - an `x` and `prefix` value (compressed)
// @error: - an `x`, `y`, and `prefix` value (uncompressed)
```

## Definition

```ts
function assert(
  publicKey: ExactPartial<PublicKey>,
  options?: assert.Options,
): asserts publicKey is PublicKey
```

## Parameters

### publicKey

* **Type:** `ExactPartial<PublicKey>`

The public key object to assert.

### options

* **Type:** `assert.Options`
* **Optional**

#### options.compressed

* **Type:** `boolean`
* **Optional**

Whether or not the public key should be compressed.
