> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bluprynt.com/llms.txt
> Use this file to discover all available pages before exploring further.

# SDK reference

> Everything exported by @bluprynt/kyi-widget-sdk and its server entry point.

## `kyi(mode, scope, accessToken, options?)`

Browser only. Opens the widget and returns a [`KYIWidget`](#kyiwidget).

```ts theme={null}
import { kyi } from '@bluprynt/kyi-widget-sdk'
```

<ParamField path="mode" type="'drawer'" required>How the widget is displayed.</ParamField>
<ParamField path="scope" type="'kyi' | 'asset-list' | 'wallet-list'" required>Which screen the widget opens on.</ParamField>
<ParamField path="accessToken" type="string" required>Token generated by your backend.</ParamField>
<ParamField path="options" type="KYIOptions">Optional callbacks.</ParamField>

Throws if `accessToken` is empty, or if `mode` or `scope` isn't one of the values above.

### `KYIOptions`

| Option | Type | Called when |
| - | - | - |
| `onReady` | `() => void` | The widget has loaded. |
| `onClose` | `() => void` | The user closes the widget, or it closes itself. |
| `onError` | `(error: Error) => void` | The widget reports an error. |

### `KYIWidget`

| Property | Type | Description |
| - | - | - |
| `destroy` | `() => void` | Removes the widget immediately. Doesn't call `onClose`. |
| `iframe` | `HTMLIFrameElement` | The iframe that hosts the widget. |

## `generateToken(options)`

Server only, Node.js 18+. Returns a `Promise<string>` with a signed HS256 JWT.

```ts theme={null}
import { generateToken } from '@bluprynt/kyi-widget-sdk/server'
```

<ParamField path="issuer" type="string" required>Your partner ID. Becomes the `iss` claim.</ParamField>
<ParamField path="secretKey" type="string" required>Your `SECRET_KEY`.</ParamField>
<ParamField path="userId" type="string" required>Your internal, stable, never-reused ID for the user. Becomes the `sub` claim.</ParamField>
<ParamField path="expiresIn" type="number" default="3600">Lifetime in seconds.</ParamField>

Throws if `issuer`, `secretKey` or `userId` is empty.

## Not using Node.js

Sign an HS256 JWT with your `SECRET_KEY` and these claims:

```python token.py theme={null}
import time, jwt

now = int(time.time())
access_token = jwt.encode(
    {"sub": user.id, "iss": "your-partner-id", "iat": now, "exp": now + 3600},
    BLUPRYNT_SECRET_KEY,
    algorithm="HS256",
)
```

## Types

```ts theme={null}
import type { KYIMode, KYIScope, KYIOptions, KYIWidget } from '@bluprynt/kyi-widget-sdk'
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.