# WebCryptoP256.getSharedSecret

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

## Imports

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

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

## Examples

```ts twoslash
import { WebCryptoP256 } from 'ox'

const { privateKey: privateKeyA } =
  await WebCryptoP256.createKeyPairECDH()
const { publicKey: publicKeyB } =
  await WebCryptoP256.createKeyPairECDH()

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

## Definition

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

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

## 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:** `CryptoKey`

Private key to use for the shared secret computation (must be a CryptoKey for ECDH).

#### options.publicKey

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

Public key to use for the shared secret computation.

## Return Type

The computed shared secret.

`Promise<getSharedSecret.ReturnType<as>>`
