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

# decodeTinAccount — decode a TIN account

> Decodes the serialized legacy TIN account bytes into its stored identifier, display name, encrypted fields, and route commitments.

## What it does

`decodeTinAccount` is a pure SDK decoder for the serialized TIN account layout.
It reads the numeric TIN, display name, owner commitment, encrypted seed,
metadata, route envelope, and optional TCap relationship commitments from the
provided account bytes. It does not call Solana or change state.

## How the flow works

<Steps>
  <Step title="Caller invokes the function">
    The caller passes the raw account data returned by a Solana RPC request as
    a `Uint8Array`.
  </Step>

  <Step title="Validation">
    The decoder reads each length-prefixed field in the account layout. Invalid
    or truncated bytes can cause a buffer read error.
  </Step>

  <Step title="Main work">
    It decodes the TIN and display name, copies encrypted byte fields, reads
    the route version and nonce, and reads TCap fields when those bytes exist.
  </Step>

  <Step title="Result">
    It returns a plain object containing decoded values as `bigint`, strings,
    buffers, nullable fields, and route commitments. No RPC call is made.
  </Step>
</Steps>

## Signature

```ts theme={null}
export function decodeTinAccount(data: Uint8Array): {
  tin: bigint;
  displayName: string;
  ownerPubkeyHash: Buffer;
  encryptedMasterSeed: Buffer;
  createdAt: bigint;
  encryptedMetadataHash: Buffer | null;
  pruConfigurationHash: Buffer | null;
  encryptedPublicRouteEnvelope: Buffer | null;
  routeVersion: bigint | null;
  routeNonce: Buffer | null;
  tcapRouteVersion: number;
  tcapRelationshipCommitment: Buffer | null;
  tcapRelationshipReference: Buffer | null;
  tcapPolicyCommitment: Buffer | null;
};
```

## Errors

| Error              | When it occurs                                                                                   |
| ------------------ | ------------------------------------------------------------------------------------------------ |
| Buffer read errors | The byte array is shorter than the account layout requires or contains an invalid length prefix. |

## Example

```ts theme={null}
const account = await connection.getAccountInfo(identityPda);
if (!account) throw new Error("TIN account not found");

const decoded = decodeTinAccount(account.data);
console.log(decoded.tin.toString(), decoded.displayName);
```

## Source

[tins.ts:1025](https://github.com/Trustlink-Labs/TSN-Protocol/blob/main/tsn-protocol/sdks/tsn-sdk/src/tins.ts#L1025)
