> ## Documentation Index
> Fetch the complete documentation index at: https://trust-link-tsn.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# encryptTinSocialIdentity — Encrypt social identity

> Encrypt a social identity locally with an AES-GCM key derived from the TIN and return the nonce and ciphertext for linking.

## What it does

This function derives the SDK social-identity key from the TIN and encrypts an arbitrary identity value locally. Plaintext is not included in the returned payload.

## How the flow works

<Steps>
  <Step title="Caller invokes the function">The caller supplies the TIN and plaintext identity value, with an optional nonce for deterministic tests.</Step>
  <Step title="Validation">The SDK requires WebCrypto AES-GCM support.</Step>
  <Step title="Main work">It derives the social key, generates a 12-byte nonce when needed, and encrypts the value.</Step>
  <Step title="Result">It returns `{ nonce, ciphertext }` for a later registry instruction.</Step>
</Steps>

## Signature

```ts theme={null}
export async function encryptTinSocialIdentity(params: {
  tin: bigint | number | string; value: string; nonce?: Uint8Array;
}): Promise<{ nonce: Uint8Array; ciphertext: Uint8Array }>
```

<ParamField path="tin" type="bigint | number | string" required>Input for deterministic key derivation.</ParamField>
<ParamField path="value" type="string" required>Plaintext identity value held only during local encryption.</ParamField>
<ParamField path="nonce" type="Uint8Array" required={false}>Optional AES-GCM nonce; otherwise generated locally.</ParamField>

## Result and errors

Returns nonce and ciphertext. Throws `WebCrypto subtle API is required for TIN encryption` when WebCrypto is unavailable.

```ts theme={null}
const encrypted = await encryptTinSocialIdentity({ tin, value: "example" });
```

Source: [`tins.ts:1335-1346`](https://github.com/Trustlink-Labs/TSN-Protocol/blob/main/tsn-protocol/sdks/tsn-sdk/src/tins.ts#L1335-L1346)
