> ## 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.

# createTinV1IdentityEnvelope — Encrypt a TIN identity

> Create the encrypted identity envelope and lookup commitment accepted by the legacy CreateTinV1 registry instruction.

## What it does

This SDK helper derives a lookup commitment from the supplied TIN, encrypts the display name and TIN with AES-GCM, and returns the ciphertext envelope. It does not create an on-chain TIN account.

## How the flow works

<Steps>
  <Step title="Caller invokes the function">The caller supplies the TIN lookup material and display name.</Step>
  <Step title="Validation">The function converts both values to UTF-8 bytes and prepares deterministic commitment/key material.</Step>
  <Step title="Main work">It derives the lookup commitment, generates a random AES-GCM nonce, and encrypts the JSON identity payload.</Step>
  <Step title="Result">It returns `lookupCommitment` and an envelope containing nonce bytes followed by ciphertext bytes.</Step>
</Steps>

## Signature

```ts theme={null}
export async function createTinV1IdentityEnvelope(params: {
  tin: bigint | number | string;
  displayName: string;
}): Promise<{ lookupCommitment: Uint8Array; encryptedIdentityEnvelope: Uint8Array }>
```

<ParamField path="tin" type="bigint | number | string" required>TIN lookup material.</ParamField>
<ParamField path="displayName" type="string" required>Name placed inside the encrypted JSON payload.</ParamField>

## Result and errors

The helper returns a 32-byte lookup commitment and AES-GCM envelope. It throws if the runtime does not expose WebCrypto AES-GCM support.

```ts theme={null}
const envelope = await createTinV1IdentityEnvelope({ tin: "1234567890", displayName: "Example" });
```

Source: [`tins.ts:1289-1304`](https://github.com/Trustlink-Labs/TSN-Protocol/blob/main/tsn-protocol/sdks/tsn-sdk/src/tins.ts#L1289-L1304)
