> For the complete documentation index, see [llms.txt](https://docs.coti.io/coti-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.coti.io/coti-documentation/privacy-on-demand/coti-typescript-sdk-for-pod.md).

# COTI TypeScript SDK for PoD

Package: **`@coti-io/coti-sdk-typescript`**

This is the **low-level cryptography layer** beneath [`@coti/pod-sdk`](/coti-documentation/privacy-on-demand/typescript-pod-sdk.md). Use it when you need signed `it*` payload construction, account key recovery, or direct decrypt helpers. Most PoD apps call `CotiPodCrypto` instead, which delegates decrypt to this package.

```bash
npm install @coti-io/coti-sdk-typescript
```

## APIs commonly used with PoD

| API                              | Purpose                                           |
| -------------------------------- | ------------------------------------------------- |
| `buildInputText`                 | Build signed encrypted numeric input payload      |
| `buildStringInputText`           | Build signed encrypted string input payload       |
| `decryptUint` / `decryptUint256` | Decrypt numeric ciphertext with account AES key   |
| `decryptString`                  | Decrypt string ciphertext with account AES key    |
| `generateRSAKeyPair`             | Generate onboarding RSA keys                      |
| `recoverUserKey`                 | Reconstruct account AES key from encrypted shares |

See [Account onboarding (AES key)](/coti-documentation/privacy-on-demand/account-onboarding-aes-key.md) for the recovery flow.

## Safer selector handling

Avoid hardcoding function selectors. Build from the contract ABI:

```typescript
import { Interface, Wallet } from "ethers";
import { buildInputText } from "@coti-io/coti-sdk-typescript";

const iface = new Interface(["function compare((uint256,bytes),(uint256,bytes))"]);
const selector = iface.getFunction("compare")!.selector;

const sender = {
  wallet: new Wallet(process.env.PRIVATE_KEY!),
  userKey: accountAesKey,
};

const itValue = buildInputText(42n, sender, contractAddress, selector);
```

The `contractAddress` and `selector` used when signing must match the on-chain call target exactly.

## String input example

```typescript
import { buildStringInputText } from "@coti-io/coti-sdk-typescript";

const itMemo = buildStringInputText("private memo", sender, contractAddress, selector);
```

## Decryption example

```typescript
import { decryptUint, decryptString } from "@coti-io/coti-sdk-typescript";

const amount = decryptUint(BigInt(ctAmountHex), accountAesKey);
const note = decryptString({ value: ctStringCells }, accountAesKey);
```

For `ctUint256` limbs, prefer `decryptUint256({ ciphertextHigh, ciphertextLow }, accountAesKey)` (see [Reference: data types](/coti-documentation/privacy-on-demand/reference-data-types.md)).

## Relationship to `@coti/pod-sdk`

| Task                                              | Package                                                            |
| ------------------------------------------------- | ------------------------------------------------------------------ |
| Encrypt plaintext via PoD encryption HTTP service | `@coti/pod-sdk` (`CotiPodCrypto.encrypt`)                          |
| Decrypt `ct*` in app code                         | `@coti/pod-sdk` (`CotiPodCrypto.decrypt`) or this package directly |
| Onboard user / recover AES key                    | This package                                                       |
| Fee estimate, submit tx, track request            | `@coti/pod-sdk` (`PodContract`, `PodRequest`)                      |

## See also

* [Account onboarding (AES key)](/coti-documentation/privacy-on-demand/account-onboarding-aes-key.md)
* [TypeScript PoD SDK](/coti-documentation/privacy-on-demand/typescript-pod-sdk.md)


---

# 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, and the optional `goal` query parameter:

```
GET https://docs.coti.io/coti-documentation/privacy-on-demand/coti-typescript-sdk-for-pod.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
