# Decryption of Provably Encrypted Data

## With mishtiwasm

Install.

```bash
npm i @holonym-foundation/mishtiwasm
```

Import, fetch parameters, and decrypt.

```typescript
import wasm from '@holonym-foundation/mishtiwasm'

// -------- Fetch parameters --------
// To decrypt, Mishti needs to verify the user's signature of the
// access conditions contract address. We retrieve the ciphertext
// as well as the signature and conditions contract from the observer.

const user = '0x123'
// This example uses Holonym's default observer to store ciphertext and assist in decryption
const observerUrl = 'https://observer.holonym.io'

const resp = await fetch(`${observerUrl}/observations?user_address=${user}`)
const data = await resp.json()
const { 
  user_address,
  signature,
  access_contract,
  zkp_public_values,
} = data[0]

// C1 and C2 are the two points in the ElGamal Ciphertext: the ephemeral public key and the masked plaintext, respectively
const ciphertext = {
  c1: {
    x: BigInt('0x' + zkp_public_values[7]).toString(),
    y: BigInt('0x' + zkp_public_values[8]).toString()
  },
  c2: {
    x: BigInt('0x' + zkp_public_values[9]).toString(),
    y: BigInt('0x' + zkp_public_values[10]).toString()
  }
}

// -------- Decrypt --------

// privateKey should be the private key to your wallet with Mishti credits.
// It is used to sign the request to Mishti Network.
const privateKey = '0x123'

const result = await wasm.decrypt(
  privateKey,
  JSON.stringify(ciphertext),
  access_contract,
  signature
);

// If the decrypted value is a UTF-8 encoded string, we need to decode
// by doing something like this:
const decoded = Buffer.from(BigInt(result).toString(16), 'hex').toString()
```


---

# Agent Instructions: 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://docs.network.human.tech/for-developers/types-of-requests/decryption-of-provably-encrypted-data.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.
