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

# Secp256k1.getSharedSecret

:::info
`Secp256k1.getSharedSecret` is a re-export of ox's [`Secp256k1.getSharedSecret`](https://oxlib.sh/api/Secp256k1/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 { Secp256k1 } from 'viem/utils'
```

## Examples

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

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

const sharedSecret = Secp256k1.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>`
