@1claw/sdk 0.44.3 → 0.45.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # @1claw/sdk
2
2
 
3
- TypeScript SDK for **1Claw Vault** — HSM-backed secret management for AI agents and humans.
3
+ TypeScript/JavaScript client for the 1Claw Vault API.
4
+
5
+ This is the official SDK for Node.js, Next.js, and browser apps that call 1Claw over HTTP. It covers vaults, secrets, agents, policies, treasury, Intents API signing, execution bindings, platform apps, billing, and x402 payments. Types are generated from the OpenAPI spec, so request shapes stay in sync with the API.
6
+
7
+ Agent keys auto-exchange for JWTs and refresh before expiry. If you're wiring an AI agent in Cursor or Claude Desktop, you probably want [@1claw/mcp](https://www.npmjs.com/package/@1claw/mcp) instead. If you're building a web app or backend service in TypeScript, start here.
4
8
 
5
9
  ## Install
6
10
 
@@ -93,7 +97,7 @@ await client.auth.verifyEmailChange({ code: "123456" });
93
97
  | `client.billing` | `usage`, `history`, `llmTokenBilling`, `subscribeLlmTokenBilling`, `disableLlmTokenBilling` (LLM token billing / Stripe AI Gateway) |
94
98
  | `client.audit` | `query` |
95
99
  | `client.org` | `listMembers`, `getAgentKeysVault`, `updateMemberRole`, `removeMember` |
96
- | `client.auth` | `login`, `signup`, `agentToken`, `apiKeyToken`, `google`, `socialLogin`, `sendEmailOtp`, `verifyEmailOtp`, `exchangeOAuthCode`, `changePassword`, `setPassword`, `changeEmail`, `verifyEmailChange`, `forgotPassword`, `resetPassword`, `exportData`, `exchangeFederatedToken`, `logout`, `getMe`, `updateMe`, `deleteMe` |
100
+ | `client.auth` | `login`, `signup`, `agentToken`, `apiKeyToken`, `google`, `socialLogin`, `sendEmailOtp`, `verifyEmailOtp`, `exchangeOAuthCode`, `revokeToken`, `revokeConsent`, `getUserInfo`, `changePassword`, `setPassword`, `changeEmail`, `verifyEmailChange`, `forgotPassword`, `resetPassword`, `exportData`, `exchangeFederatedToken`, `logout`, `getMe`, `updateMe`, `deleteMe` |
97
101
  | `client.apiKeys` | `create`, `list`, `revoke` |
98
102
  | `client.treasury` | `create`, `list`, `get`, `update`, `delete`, `addSigner`, `removeSigner`, `requestAccess`, `listAccessRequests`, `approveAccess`, `denyAccess`, `propose`, `listProposals`, `getProposal`, `signProposal`, `executeProposal` |
99
103
  | `client.treasuryWallets` | `generateWallets`, `listWallets`, `getWallet`, `getWalletBalance`, `sendFromWallet`, `swapFromWallet`, `exportWallet`, `rotateWallet`, `deactivateWallet`, `getEffectiveSpendPolicy` |
@@ -102,7 +106,7 @@ await client.auth.verifyEmailChange({ code: "123456" });
102
106
  | `client.fiat` | `createOnrampSession`, `initiateOfframp` |
103
107
  | `client.signingKeys` | `create`, `list`, `rotate`, `deactivate`, `export` |
104
108
  | `client.agents` (Bankr) | `leaseBankrKey`, `listBankrKeys`, `revokeBankrKey` — privileged; `api_key` omitted for agent JWTs (use Shroud) |
105
- | `client.platform` | `createApp`, `listApps`, `getApp`, `updateApp`, `deleteApp`, `rotateKey`, `createTemplate`, `listTemplates`, `upsertUser`, `listUsers`, `bootstrapUser`, `reissueClaim`, `claimPreview`, `claimRedeem`, `listConnectedApps`, `disconnectApp`, `grantAccess`, `listGrants`, `revokeGrant`, `createSpendPolicy`, `listSpendPolicies`, `setUserSpendPolicy`, `deleteSpendPolicy`, `updateConnectionDelegation` |
109
+ | `client.platform` | `createApp`, `listApps`, `getApp`, `updateApp`, `deleteApp`, `rotateKey`, `rotateWebhookSecret`, `getAppStats`, `marketplace`, `createTemplate`, `listTemplates`, `upsertUser`, `listUsers`, `bootstrapUser`, `reissueClaim`, `claimPreview`, `claimRedeem`, `listConnectedApps`, `disconnectApp`, `grantAccess`, `listGrants`, `revokeGrant`, `createSpendPolicy`, `listSpendPolicies`, `setUserSpendPolicy`, `deleteSpendPolicy`, `updateConnectionDelegation` |
106
110
  | `client.devices` | `register`, `list`, `delete`, `challenge`, `attest`, `setPushToken` |
107
111
  | `client.passkeys` | `list`, `registerBegin`, `registerComplete`, `assertBegin`, `assertComplete`, `delete` |
108
112
  | `client.risk` | `listEvents`, `getVerdict`, `listVerdicts`, `createHoneytoken`, `listHoneytokens`, `deleteHoneytoken` |
@@ -352,6 +356,44 @@ console.log(agent.data?.tx_count_today); // e.g. 42
352
356
  console.log(agent.data?.tx_overhead_today_by_chain); // e.g. { "solana": "0.12" }
353
357
  ```
354
358
 
359
+ ## OAuth2 / PKCE ("Sign in with 1Claw")
360
+
361
+ The SDK provides helpers for implementing the full OAuth2 PKCE flow and managing tokens/consent:
362
+
363
+ ```typescript
364
+ import { generatePKCE, buildAuthorizeUrl, createClient } from "@1claw/sdk";
365
+
366
+ // 1. Generate PKCE pair
367
+ const pkce = await generatePKCE();
368
+
369
+ // 2. Build the authorize URL
370
+ const authUrl = buildAuthorizeUrl("https://1claw.xyz", {
371
+ clientId: "your-platform-app-slug",
372
+ redirectUri: "https://yourapp.com/callback",
373
+ scopes: ["openid", "profile", "email"],
374
+ state: "random-state",
375
+ codeChallenge: pkce.codeChallenge,
376
+ });
377
+
378
+ // 3. After redirect, exchange the code for tokens
379
+ const client = createClient({ baseUrl: "https://api.1claw.xyz" });
380
+ const tokens = await client.auth.exchangeOAuthCode({
381
+ code: "authorization-code-from-callback",
382
+ client_id: "your-platform-app-slug",
383
+ redirect_uri: "https://yourapp.com/callback",
384
+ code_verifier: pkce.codeVerifier,
385
+ });
386
+
387
+ // 4. Fetch user info
388
+ const userInfo = await client.auth.getUserInfo(tokens.data?.access_token);
389
+
390
+ // 5. Revoke a token (RFC 7009)
391
+ await client.auth.revokeToken({ token: "...", token_type_hint: "refresh_token" });
392
+
393
+ // 6. Revoke consent for an app (invalidates all tokens)
394
+ await client.auth.revokeConsent("platform-app-id");
395
+ ```
396
+
355
397
  ## OIDC Federation (Anthropic WIF, GCP STS, AWS STS)
356
398
 
357
399
  `https://api.1claw.xyz` is a fully OpenID Connect–compliant issuer. External relying parties — Anthropic Workload Identity Federation, GCP STS, AWS STS, Stytch, etc. — can validate 1claw-issued JWTs by fetching:
@@ -3221,6 +3221,46 @@ export interface paths {
3221
3221
  patch?: never;
3222
3222
  trace?: never;
3223
3223
  };
3224
+ "/v1/platform/apps/{appId}/stats": {
3225
+ parameters: {
3226
+ query?: never;
3227
+ header?: never;
3228
+ path?: never;
3229
+ cookie?: never;
3230
+ };
3231
+ /**
3232
+ * Get platform app statistics
3233
+ * @description Returns aggregate statistics about a platform app's connected users, bootstraps, and grants.
3234
+ */
3235
+ get: operations["getPlatformAppStats"];
3236
+ put?: never;
3237
+ post?: never;
3238
+ delete?: never;
3239
+ options?: never;
3240
+ head?: never;
3241
+ patch?: never;
3242
+ trace?: never;
3243
+ };
3244
+ "/v1/platform/apps/{appId}/rotate-webhook-secret": {
3245
+ parameters: {
3246
+ query?: never;
3247
+ header?: never;
3248
+ path?: never;
3249
+ cookie?: never;
3250
+ };
3251
+ get?: never;
3252
+ put?: never;
3253
+ /**
3254
+ * Rotate webhook secret
3255
+ * @description Generate a new webhook signing secret for the platform app. The old secret is immediately invalidated. Returns the new secret (one-time).
3256
+ */
3257
+ post: operations["rotatePlatformWebhookSecret"];
3258
+ delete?: never;
3259
+ options?: never;
3260
+ head?: never;
3261
+ patch?: never;
3262
+ trace?: never;
3263
+ };
3224
3264
  "/v1/platform/apps/{appId}/templates": {
3225
3265
  parameters: {
3226
3266
  query?: never;
@@ -4406,6 +4446,48 @@ export interface paths {
4406
4446
  patch?: never;
4407
4447
  trace?: never;
4408
4448
  };
4449
+ "/v1/oauth/revoke": {
4450
+ parameters: {
4451
+ query?: never;
4452
+ header?: never;
4453
+ path?: never;
4454
+ cookie?: never;
4455
+ };
4456
+ get?: never;
4457
+ put?: never;
4458
+ /**
4459
+ * Revoke an OAuth token (RFC 7009)
4460
+ * @description Revokes an access token or refresh token. The authorization server
4461
+ * invalidates the token so it can no longer be used. Follows RFC 7009.
4462
+ */
4463
+ post: operations["revokeOAuthToken"];
4464
+ delete?: never;
4465
+ options?: never;
4466
+ head?: never;
4467
+ patch?: never;
4468
+ trace?: never;
4469
+ };
4470
+ "/v1/oauth/consents/{app_id}": {
4471
+ parameters: {
4472
+ query?: never;
4473
+ header?: never;
4474
+ path?: never;
4475
+ cookie?: never;
4476
+ };
4477
+ get?: never;
4478
+ put?: never;
4479
+ post?: never;
4480
+ /**
4481
+ * Revoke consent for a platform app
4482
+ * @description Revokes the user's previously granted OAuth consent for a specific platform app.
4483
+ * All active tokens issued to the app are invalidated and the consent record is deleted.
4484
+ */
4485
+ delete: operations["revokeOAuthConsent"];
4486
+ options?: never;
4487
+ head?: never;
4488
+ patch?: never;
4489
+ trace?: never;
4490
+ };
4409
4491
  "/v1/risk/events": {
4410
4492
  parameters: {
4411
4493
  query?: never;
@@ -5275,7 +5357,7 @@ export interface paths {
5275
5357
  };
5276
5358
  /**
5277
5359
  * Public marketplace
5278
- * @description Browse the public platform marketplace of agents and apps.
5360
+ * @description Browse the public platform marketplace of listed apps and agents. Returns approved platform apps with category, tags, pricing summaries, and screenshots.
5279
5361
  */
5280
5362
  get: operations["listMarketplace"];
5281
5363
  put?: never;
@@ -8238,6 +8320,8 @@ export interface components {
8238
8320
  vault_id?: string | null;
8239
8321
  /** Format: uuid */
8240
8322
  agent_id?: string | null;
8323
+ /** @description All agent IDs provisioned by the template (when multiple agents are defined) */
8324
+ agent_ids?: string[];
8241
8325
  policy_ids?: string[];
8242
8326
  /** @description Chains with provisioned signing keys */
8243
8327
  signing_key_chains?: string[];
@@ -8258,6 +8342,32 @@ export interface components {
8258
8342
  automation_ids?: string[];
8259
8343
  };
8260
8344
  };
8345
+ PlatformAppStatsResponse: {
8346
+ /** @description Total number of user connections (all statuses) */
8347
+ total_connections: number;
8348
+ /** @description Number of active connections */
8349
+ active_connections: number;
8350
+ /** @description Number of claimed connections */
8351
+ claimed_connections: number;
8352
+ /** @description Total bootstrap operations performed */
8353
+ total_bootstraps: number;
8354
+ /** @description Total resource grants issued */
8355
+ total_grants: number;
8356
+ };
8357
+ MarketplaceResponse: {
8358
+ apps?: {
8359
+ /** Format: uuid */
8360
+ id?: string;
8361
+ name?: string;
8362
+ slug?: string;
8363
+ description?: string;
8364
+ logo_url?: string | null;
8365
+ category?: string | null;
8366
+ listing_tags?: string[];
8367
+ listing_screenshots?: string[];
8368
+ pricing_summary?: string | null;
8369
+ }[];
8370
+ };
8261
8371
  ConnectedAppResponse: {
8262
8372
  /** Format: uuid */
8263
8373
  connection_id?: string;
@@ -8463,6 +8573,8 @@ export interface components {
8463
8573
  token_type: "Bearer";
8464
8574
  /** @description Token lifetime in seconds */
8465
8575
  expires_in: number;
8576
+ /** @description Refresh token for obtaining new access tokens (when offline_access scope was granted) */
8577
+ refresh_token?: string | null;
8466
8578
  /** @description OIDC ID token (when openid scope was granted) */
8467
8579
  id_token?: string | null;
8468
8580
  scope: string;
@@ -9171,6 +9283,14 @@ export interface components {
9171
9283
  config: {
9172
9284
  [key: string]: string;
9173
9285
  };
9286
+ /** @description Enable slash commands on this channel */
9287
+ slash_commands_enabled?: boolean;
9288
+ /** @description Enable voice message transcription */
9289
+ voice_transcription_enabled?: boolean;
9290
+ /** @description List of allowed sender IDs */
9291
+ sender_allowlist?: string[];
9292
+ /** @description Enable auto-respond */
9293
+ auto_respond_enabled?: boolean;
9174
9294
  };
9175
9295
  UpdateChannelRequest: {
9176
9296
  channel_name?: string;
@@ -9178,6 +9298,10 @@ export interface components {
9178
9298
  config?: {
9179
9299
  [key: string]: string;
9180
9300
  };
9301
+ slash_commands_enabled?: boolean;
9302
+ voice_transcription_enabled?: boolean;
9303
+ sender_allowlist?: string[];
9304
+ auto_respond_enabled?: boolean;
9181
9305
  };
9182
9306
  ChannelResponse: {
9183
9307
  /** Format: uuid */
@@ -9200,6 +9324,21 @@ export interface components {
9200
9324
  config?: {
9201
9325
  [key: string]: unknown;
9202
9326
  } | null;
9327
+ /** @description Whether slash commands are enabled for this channel */
9328
+ slash_commands_enabled?: boolean;
9329
+ /** @description Whether voice message transcription is enabled */
9330
+ voice_transcription_enabled?: boolean;
9331
+ /**
9332
+ * Format: uuid
9333
+ * @description ID linking this channel to a unified cross-platform conversation
9334
+ */
9335
+ unified_conversation_id?: string | null;
9336
+ /** @description Whether this is the agent's home platform channel */
9337
+ is_home_platform?: boolean;
9338
+ /** @description List of allowed sender IDs for auto-respond */
9339
+ sender_allowlist?: string[] | null;
9340
+ /** @description Whether auto-respond is enabled for this channel */
9341
+ auto_respond_enabled?: boolean;
9203
9342
  /** Format: date-time */
9204
9343
  created_at?: string;
9205
9344
  /** Format: date-time */
@@ -9227,6 +9366,17 @@ export interface components {
9227
9366
  sender_name?: string;
9228
9367
  content?: string;
9229
9368
  media_url?: string;
9369
+ /** @description Whether this message was a voice message */
9370
+ is_voice_message?: boolean;
9371
+ /** @description Telegram voice file ID */
9372
+ voice_file_id?: string | null;
9373
+ /** @description Duration of voice message in seconds */
9374
+ voice_duration_secs?: number | null;
9375
+ /**
9376
+ * @description Status of voice transcription
9377
+ * @enum {string|null}
9378
+ */
9379
+ transcription_status?: "pending" | "completed" | "failed" | null;
9230
9380
  /** Format: date-time */
9231
9381
  created_at?: string;
9232
9382
  };
@@ -14118,6 +14268,64 @@ export interface operations {
14118
14268
  };
14119
14269
  };
14120
14270
  };
14271
+ getPlatformAppStats: {
14272
+ parameters: {
14273
+ query?: never;
14274
+ header?: never;
14275
+ path: {
14276
+ appId: string;
14277
+ };
14278
+ cookie?: never;
14279
+ };
14280
+ requestBody?: never;
14281
+ responses: {
14282
+ /** @description App statistics */
14283
+ 200: {
14284
+ headers: {
14285
+ [name: string]: unknown;
14286
+ };
14287
+ content: {
14288
+ "application/json": components["schemas"]["PlatformAppStatsResponse"];
14289
+ };
14290
+ };
14291
+ 401: components["responses"]["Unauthorized"];
14292
+ 404: components["responses"]["NotFound"];
14293
+ };
14294
+ };
14295
+ rotatePlatformWebhookSecret: {
14296
+ parameters: {
14297
+ query?: never;
14298
+ header?: never;
14299
+ path: {
14300
+ appId: string;
14301
+ };
14302
+ cookie?: never;
14303
+ };
14304
+ requestBody?: never;
14305
+ responses: {
14306
+ /** @description New webhook secret generated */
14307
+ 200: {
14308
+ headers: {
14309
+ [name: string]: unknown;
14310
+ };
14311
+ content: {
14312
+ "application/json": {
14313
+ /** @description The new webhook signing secret (shown once) */
14314
+ webhook_secret: string;
14315
+ };
14316
+ };
14317
+ };
14318
+ 401: components["responses"]["Unauthorized"];
14319
+ /** @description Only human users can rotate webhook secrets */
14320
+ 403: {
14321
+ headers: {
14322
+ [name: string]: unknown;
14323
+ };
14324
+ content?: never;
14325
+ };
14326
+ 404: components["responses"]["NotFound"];
14327
+ };
14328
+ };
14121
14329
  deletePlatformTemplate: {
14122
14330
  parameters: {
14123
14331
  query?: never;
@@ -15049,6 +15257,71 @@ export interface operations {
15049
15257
  401: components["responses"]["Unauthorized"];
15050
15258
  };
15051
15259
  };
15260
+ revokeOAuthToken: {
15261
+ parameters: {
15262
+ query?: never;
15263
+ header?: never;
15264
+ path?: never;
15265
+ cookie?: never;
15266
+ };
15267
+ requestBody: {
15268
+ content: {
15269
+ "application/json": {
15270
+ /** @description The token to revoke (access_token or refresh_token) */
15271
+ token: string;
15272
+ /**
15273
+ * @description Hint about the type of token being revoked
15274
+ * @enum {string}
15275
+ */
15276
+ token_type_hint?: "access_token" | "refresh_token";
15277
+ };
15278
+ };
15279
+ };
15280
+ responses: {
15281
+ /** @description Token revoked successfully (or was already invalid) */
15282
+ 200: {
15283
+ headers: {
15284
+ [name: string]: unknown;
15285
+ };
15286
+ content: {
15287
+ "application/json": {
15288
+ /** @example true */
15289
+ revoked?: boolean;
15290
+ };
15291
+ };
15292
+ };
15293
+ };
15294
+ };
15295
+ revokeOAuthConsent: {
15296
+ parameters: {
15297
+ query?: never;
15298
+ header?: never;
15299
+ path: {
15300
+ /** @description The platform app ID whose consent to revoke */
15301
+ app_id: string;
15302
+ };
15303
+ cookie?: never;
15304
+ };
15305
+ requestBody?: never;
15306
+ responses: {
15307
+ /** @description Consent revoked */
15308
+ 200: {
15309
+ headers: {
15310
+ [name: string]: unknown;
15311
+ };
15312
+ content: {
15313
+ "application/json": {
15314
+ /** @example true */
15315
+ revoked?: boolean;
15316
+ /** Format: uuid */
15317
+ app_id?: string;
15318
+ };
15319
+ };
15320
+ };
15321
+ 401: components["responses"]["Unauthorized"];
15322
+ 404: components["responses"]["NotFound"];
15323
+ };
15324
+ };
15052
15325
  listRiskEvents: {
15053
15326
  parameters: {
15054
15327
  query?: {
@@ -16485,6 +16758,8 @@ export interface operations {
16485
16758
  per_page?: number;
16486
16759
  /** @description Search query */
16487
16760
  q?: string;
16761
+ /** @description Filter by app category */
16762
+ category?: string;
16488
16763
  };
16489
16764
  header?: never;
16490
16765
  path?: never;
@@ -16498,7 +16773,7 @@ export interface operations {
16498
16773
  [name: string]: unknown;
16499
16774
  };
16500
16775
  content: {
16501
- "application/json": components["schemas"]["DirectoryResponse"];
16776
+ "application/json": components["schemas"]["MarketplaceResponse"];
16502
16777
  };
16503
16778
  };
16504
16779
  };