@1claw/sdk 0.44.3 → 0.46.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
 
@@ -86,14 +90,14 @@ await client.auth.verifyEmailChange({ code: "123456" });
86
90
  | `client.vault` | `create`, `get`, `list`, `delete`, `enableMpc`, `disableMpc` |
87
91
  | `client.secrets` | `set`, `get`, `delete`, `list`, `rotate` |
88
92
  | `client.access` | `grantHuman`, `grantAgent`, `update`, `revoke`, `listGrants` |
89
- | `client.agents` | `enroll` (also `AgentsResource.enroll(baseUrl, …)` static), `create`, `getSelf`, `get`, `list`, `update`, `delete`, `rotateKey`, `generateEoa`, `createSmartAccount`, `deleteSmartAccount`, `rotateSigner`, `submitTransaction`, `signTransaction`, `getTransaction`, `listTransactions`, `simulateTransaction`, `simulateBundle`, `sign` |
93
+ | `client.agents` | `enroll` (also `AgentsResource.enroll(baseUrl, …)` static), `create`, `getSelf`, `get`, `list`, `update`, `delete`, `rotateKey`, `generateEoa`, `createSmartAccount`, `deleteSmartAccount`, `rotateSigner`, `submitTransaction`, `signTransaction`, `getTransaction`, `listTransactions`, `simulateTransaction`, `simulateBundle`, `sign`, `createDelegation`, `listDelegations`, `getDelegation`, `updateDelegation`, `revokeDelegation`, `getEffectiveDelegations` |
90
94
  | `client.chains` | `list`, `get`, `adminList`, `create`, `update`, `delete` |
91
95
  | `client.sharing` | `create`, `access`, `listOutbound`, `listInbound`, `accept`, `decline`, `revoke` |
92
96
  | `client.approvals` | `request`, `list`, `approve`, `deny`, `check`, `subscribe` |
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` |
@@ -326,6 +330,39 @@ When `execution_require_tee` is true:
326
330
 
327
331
  Both require `intents_api_enabled` / `execution_intents_enabled` to be on first.
328
332
 
333
+ ### Agent-to-Agent Delegation
334
+
335
+ Human-controlled authorization for inter-agent task delegation. Agents cannot delegate to other agents without an explicit delegation record created by a human.
336
+
337
+ ```typescript
338
+ // Create a delegation (human-only)
339
+ await client.agents.createDelegation(orchestratorId, {
340
+ delegate_id: subAgentId,
341
+ allowed_tools: ["delegate_task", "search_memory"],
342
+ max_daily_delegations: 100,
343
+ max_depth: 2,
344
+ delegation_mode: "caller",
345
+ expires_at: "2026-12-31T23:59:59Z",
346
+ });
347
+
348
+ // List delegations for an agent
349
+ const delegations = await client.agents.listDelegations(agentId);
350
+
351
+ // Get effective delegations (agent-callable — for runtime tool discovery)
352
+ const effective = await client.agents.getEffectiveDelegations(agentId);
353
+
354
+ // Update a delegation (human-only)
355
+ await client.agents.updateDelegation(agentId, delegationId, {
356
+ max_daily_delegations: 200,
357
+ is_active: false,
358
+ });
359
+
360
+ // Revoke a delegation (human-only)
361
+ await client.agents.revokeDelegation(agentId, delegationId);
362
+ ```
363
+
364
+ Delegation modes: `caller` (delegate uses its own credentials), `target` (delegate uses target's config), `both` (either mode per invocation).
365
+
329
366
  ### Overhead Budget and Transaction Count Limits
330
367
 
331
368
  Protect against non-value drain attacks (ATA rent drain, XRP reserve exhaustion, Tron energy drain):
@@ -352,6 +389,44 @@ console.log(agent.data?.tx_count_today); // e.g. 42
352
389
  console.log(agent.data?.tx_overhead_today_by_chain); // e.g. { "solana": "0.12" }
353
390
  ```
354
391
 
392
+ ## OAuth2 / PKCE ("Sign in with 1Claw")
393
+
394
+ The SDK provides helpers for implementing the full OAuth2 PKCE flow and managing tokens/consent:
395
+
396
+ ```typescript
397
+ import { generatePKCE, buildAuthorizeUrl, createClient } from "@1claw/sdk";
398
+
399
+ // 1. Generate PKCE pair
400
+ const pkce = await generatePKCE();
401
+
402
+ // 2. Build the authorize URL
403
+ const authUrl = buildAuthorizeUrl("https://1claw.xyz", {
404
+ clientId: "your-platform-app-slug",
405
+ redirectUri: "https://yourapp.com/callback",
406
+ scopes: ["openid", "profile", "email"],
407
+ state: "random-state",
408
+ codeChallenge: pkce.codeChallenge,
409
+ });
410
+
411
+ // 3. After redirect, exchange the code for tokens
412
+ const client = createClient({ baseUrl: "https://api.1claw.xyz" });
413
+ const tokens = await client.auth.exchangeOAuthCode({
414
+ code: "authorization-code-from-callback",
415
+ client_id: "your-platform-app-slug",
416
+ redirect_uri: "https://yourapp.com/callback",
417
+ code_verifier: pkce.codeVerifier,
418
+ });
419
+
420
+ // 4. Fetch user info
421
+ const userInfo = await client.auth.getUserInfo(tokens.data?.access_token);
422
+
423
+ // 5. Revoke a token (RFC 7009)
424
+ await client.auth.revokeToken({ token: "...", token_type_hint: "refresh_token" });
425
+
426
+ // 6. Revoke consent for an app (invalidates all tokens)
427
+ await client.auth.revokeConsent("platform-app-id");
428
+ ```
429
+
355
430
  ## OIDC Federation (Anthropic WIF, GCP STS, AWS STS)
356
431
 
357
432
  `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: