> **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.

# P256.getSharedSecret

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

Computes a shared secret using ECDH (Elliptic Curve Diffie-Hellman) between a private key and a public key.

## Imports

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

## Examples

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

const { privateKey: privateKeyA } = P256.createKeyPair()
const { publicKey: publicKeyB } = P256.createKeyPair()

const sharedSecret = P256.getSharedSecret({
  privateKey: privateKeyA,
  publicKey: publicKeyB
})
```

## Definition

```ts
function getSharedSecret<as>(
  options: getSharedSecret.Options<as>,
): getSharedSecret.ReturnType<as>
```

## Parameters

### options

* **Type:** `getSharedSecret.Options<as>`

The options to compute the shared secret.

#### options.as

* **Type:** `"Bytes" | "Hex" | as`
* **Optional**

Format of the returned shared secret.

#### options.privateKey

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

Private key to use for the shared secret computation.

#### options.publicKey

* **Type:** `0x${string} | Uint8Array | { prefix: number; x: 0x${string}; y: 0x${string}; } | { prefix: number; x: 0x${string}; y?: undefined; }`

Public key to use for the shared secret computation.

Accepts a structured [`PublicKey.PublicKey`](/docs/utilities/publickey/types#publickey), a serialized hex
string, or a `Uint8Array` (SEC1 encoding).

## Return Type

The computed shared secret.

`getSharedSecret.ReturnType<as>`
