import {Meta} from '@storybook/addon-docs/blocks'

<Meta title='@dxtmisha/en/figma/Classes/FigmaPostCode - Message Verification'/>

# FigmaPostCode Class

A utility class for managing a unique verification code used for message integrity between the Figma plugin (backend) and its UI (frontend). This ensures that messages received by one side were indeed sent by the other side of the same plugin session.

## Key Features

- **Security** — Prevents cross-plugin message interference.
- **Session Locking** — The code can only be set once per session, ensuring consistency.
- **Auto-generation** — A random code is generated by default (e.g., `figma-123456`) if not set manually.

## Static Methods

### `is`

Checks if the provided code matches the current post code.

**Parameters:**
- `code: string` — The verification code string to check.

**Returns:** `boolean` — `true` if the code matches the internal session code.

### `get`

Returns the current post code used for message verification in the current session.

**Returns:** `string`

### `set`

Sets a new post code. This method can only be successful once; once a code is set (or after the first access to `get`), the session is locked and the code can no longer be changed.

**Parameters:**
- `code: string` — The new code to be used for the remainder of the session.

**Returns:** `void`

## Recommendation

For stable and unique verification, it is recommended to use the `id` from your plugin's `manifest.json`.

```typescript
import manifest from '../manifest.json'
import { FigmaPostCode } from '@dxtmisha/figma'

// Set the post code using the plugin's unique ID from manifest
FigmaPostCode.set(manifest.id)
```
