# CoseKey.fromPublicKey

Converts a P256 [`PublicKey.PublicKey`](/api/PublicKey/types#publickey) to a CBOR-encoded COSE\_Key.

The COSE\_Key uses integer map keys per [RFC 9053](https://datatracker.ietf.org/doc/html/rfc9053): - `1` (kty): `2` (EC2) - `3` (alg): `-7` (ES256) - `-1` (crv): `1` (P-256) - `-2` (x): x coordinate bytes - `-3` (y): y coordinate bytes

## Imports

:::code-group
```ts [Named]
import { CoseKey } from 'ox'
```

```ts [Entrypoint]
import * as CoseKey from 'ox/CoseKey'
```
:::

## Examples

```ts twoslash
import { CoseKey, P256 } from 'ox'

const { publicKey } = P256.createKeyPair()

const coseKey = CoseKey.fromPublicKey(publicKey)
```

## Definition

```ts
function fromPublicKey(
  publicKey: PublicKey.PublicKey,
): Hex.Hex
```

**Source:** [src/core/CoseKey.ts](https://github.com/wevm/ox/blob/main/src/core/CoseKey.ts#L222)

## Parameters

### publicKey

* **Type:** `PublicKey.PublicKey`

The P256 public key to convert.

#### publicKey.prefix

* **Type:** `numberType`

#### publicKey.x

* **Type:** `0x${string}`

#### publicKey.y

* **Type:** `0x${string}`

## Return Type

The CBOR-encoded COSE\_Key as a Hex string.

`Hex.Hex`
