リクエストの署名
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エンドポイントへの書き込みアクセス
スコープを指定しない場合、トークンはすべての一般APIエンドポイントにアクセスできます。スコープは、保護されたWebhookまたはKYTエンドポイントにアクセスする場合にのみ必要です。
JavaScript
例1: スコープなし(一般APIアクセス)
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アクセス付き
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アクセス付き
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: 複数スコープ付き
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
import { ChainStreamClient } from "@chainstream-io/sdk";
// jwtToken generated from previous step
const dex = new ChainStreamClient("your-jwt-token");
プレースホルダーの値を実際のAPI認証情報に置き換えてください。