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

# 認証

> 認証付きAPIリクエストの署名方法

## リクエストの署名

ChainStreamは、すべてのAPI呼び出しの認証にAPIキーを使用します。**ベースAPI URL**は、ワークスペース環境のタイプに応じて以下のいずれかになります：

* メインネット: `https://api.chainstream.io/`

各APIリクエストには、以下のヘッダーを含める必要があります：

* `Authorization` - この値は `Bearer <Access Token>` に設定する必要があります。アクセストークンはBase64エンコードされたJSON Web Token（JWT）です。

## JWTトークンの生成

以下のコードを使用してJWTトークンを生成できます。`scope`パラメータはオプションで、特定のAPIモジュールへのアクセス権限を制御します。

### 利用可能なスコープ

現在、以下のスコープがサポートされています：

* `webhook.read` - Webhook APIエンドポイントへの読み取りアクセス
* `webhook.write` - Webhook APIエンドポイントへの書き込みアクセス
* `kyt.read` - KYT（Know Your Transaction）APIエンドポイントへの読み取りアクセス
* `kyt.write` - KYT APIエンドポイントへの書き込みアクセス

<Note>
  スコープを指定しない場合、トークンはすべての一般APIエンドポイントにアクセスできます。スコープは、保護されたWebhookまたはKYTエンドポイントにアクセスする場合にのみ必要です。
</Note>

### JavaScript

**例1: スコープなし（一般APIアクセス）**

```javascript theme={null}
import { AuthenticationClient } from 'auth0';

const auth0Client = new AuthenticationClient({
    domain: `dex.asia.auth.chainstream.io`,
    clientId: 'your client id',
    clientSecret: 'your client secret'
  });

const response = await auth0Client.oauth.clientCredentialsGrant({
      audience: 'https://api.dex.chainstream.io'
    });

return response.data.access_token;
```

**例2: Webhookアクセス付き**

```javascript theme={null}
import { AuthenticationClient } from 'auth0';

const auth0Client = new AuthenticationClient({
    domain: `dex.asia.auth.chainstream.io`,
    clientId: 'your client id',
    clientSecret: 'your client secret'
  });

const response = await auth0Client.oauth.clientCredentialsGrant({
      audience: 'https://api.dex.chainstream.io',
      scope: 'webhook.read webhook.write'
    });

return response.data.access_token;
```

**例3: KYTアクセス付き**

```javascript theme={null}
import { AuthenticationClient } from 'auth0';

const auth0Client = new AuthenticationClient({
    domain: `dex.asia.auth.chainstream.io`,
    clientId: 'your client id',
    clientSecret: 'your client secret'
  });

const response = await auth0Client.oauth.clientCredentialsGrant({
      audience: 'https://api.dex.chainstream.io',
      scope: 'kyt.read kyt.write'
    });

return response.data.access_token;
```

**例4: 複数スコープ付き**

```javascript theme={null}
import { AuthenticationClient } from 'auth0';

const auth0Client = new AuthenticationClient({
    domain: `dex.asia.auth.chainstream.io`,
    clientId: 'your client id',
    clientSecret: 'your client secret'
  });

const response = await auth0Client.oauth.clientCredentialsGrant({
      audience: 'https://api.dex.chainstream.io',
      scope: 'webhook.read webhook.write kyt.read kyt.write'
    });

return response.data.access_token;
```

## SDKの使用

JWTトークンを生成した後、それを使用してSDKを初期化できます：

### JavaScript SDK

```javascript theme={null}
import { ChainStreamClient } from "@chainstream-io/sdk";

// jwtToken generated from previous step
const dex = new ChainStreamClient("your-jwt-token");
```

<Note>
  プレースホルダーの値を実際のAPI認証情報に置き換えてください。
</Note>
