> For the complete documentation index, see [llms.txt](https://comet-3.gitbook.io/comet-sdk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://comet-3.gitbook.io/comet-sdk/reference/comet-sdk-reference/comet-react-sdk/hooks/usegetsharedsecret.md).

# useGetSharedSecret

{% hint style="info" %}
`useGetSharedSecret` is an advanced feature of Comet's React SDK. Except for situations which require secure symmetric encryption, you will probably not need this React hook.
{% endhint %}

Using Comet's built in cloud wallets, users can perform Diffie-Hellman key exchange to generate a shared secret with another party's Solana public key. This shared secret can be used for secure communication between two Solana addresses.

<figure><img src="/files/7RZoCtKKD2iD1cVOsCjt" alt=""><figcaption></figcaption></figure>

## API

```javascript
const { getSharedSecret } = useGetSharedSecret({ publicKey: '<SOLANA ADDRESS>' });
```

In the example above, the `publicKey` can be a `string`, `Buffer`, or `Uint8Array`.

`getSharedSecret` is a function that can be called later on, which will bring up the confirmation dialog. Users will be prompted to log in to Comet if needed. When the user clicks "Confirm", a shared secret will be calculated between the user's private key and the supplied public key.

`getSharedSecret` returns a successful `Promise` containing the shared secret in `Uint8Array` format if the user clicks "Confirm"; otherwise it will return a failed `Promise` if the user clicks "Cancel".

## Example

```tsx
import { useGetSharedSecret } from '@comet-labs/react';

function App() {
  const { getSharedSecret } = useGetSharedSecret({ publicKey: 'Dgq5B8i5NJJfPoUgpkFZDzRr84zd1BJrUBntJt1EBvgd' });

  return (
    <div className="App">
      <button onClick={getSharedSecret}>
        click for diffie hellman
      </button>
    </div>
  );
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://comet-3.gitbook.io/comet-sdk/reference/comet-sdk-reference/comet-react-sdk/hooks/usegetsharedsecret.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
