> 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>
  );
}
```
