@swarm-tips/client 0.2.12 → 0.3.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.
Files changed (44) hide show
  1. package/README.md +59 -18
  2. package/SBOM.spdx.json +5 -5
  3. package/dist/agent.d.ts +176 -0
  4. package/dist/agent.js +561 -0
  5. package/dist/auth/token-manager.d.ts +33 -0
  6. package/dist/auth/token-manager.js +175 -0
  7. package/dist/cli/keyfile.d.ts +24 -0
  8. package/dist/cli/keyfile.js +97 -0
  9. package/dist/cli/swarm.d.ts +14 -0
  10. package/dist/cli/swarm.js +516 -0
  11. package/dist/contracts/generated/shillbot.d.ts +9 -3
  12. package/dist/contracts/idl/shillbot.json +9 -3
  13. package/dist/coordination-game/api.d.ts +4 -4
  14. package/dist/coordination-game/api.js +8 -8
  15. package/dist/errors.d.ts +1 -1
  16. package/dist/generated/openapi.d.ts +1963 -0
  17. package/dist/generated/openapi.js +8 -0
  18. package/dist/http.d.ts +6 -3
  19. package/dist/http.js +18 -4
  20. package/dist/inbox/client.d.ts +16 -1
  21. package/dist/inbox/client.js +48 -2
  22. package/dist/inbox/index.d.ts +1 -1
  23. package/dist/index.d.ts +7 -2
  24. package/dist/index.js +7 -2
  25. package/dist/shillbot/api.d.ts +49 -2
  26. package/dist/shillbot/api.js +377 -33
  27. package/dist/signer/evm.d.ts +25 -0
  28. package/dist/signer/evm.js +249 -0
  29. package/dist/signer/index.d.ts +3 -0
  30. package/dist/signer/index.js +3 -0
  31. package/dist/signer/solana.d.ts +24 -0
  32. package/dist/signer/solana.js +183 -0
  33. package/dist/signer/types.d.ts +30 -0
  34. package/dist/signer/types.js +31 -0
  35. package/dist/swarm/index.d.ts +1 -0
  36. package/dist/swarm/index.js +9 -2
  37. package/dist/version.d.ts +1 -0
  38. package/dist/version.js +1 -0
  39. package/dist/vow/decoders/shillbot.d.ts +1 -0
  40. package/dist/vow/decoders/shillbot.js +2 -0
  41. package/dist/vow/types.d.ts +1 -0
  42. package/dist/vow/verify.d.ts +3 -2
  43. package/dist/vow/verify.js +8 -3
  44. package/package.json +5 -3
package/README.md CHANGED
@@ -1,8 +1,63 @@
1
1
  # @swarm-tips/client
2
2
 
3
- One typed package for Swarm Tips client-side integrations. The root export is
4
- deliberately lightweight; import only the capability you need:
3
+ Unified non-custodial TypeScript SDK and CLI for Swarm Tips, Shillbot, Inbox/Topics, VOW v1 attestations, and Coordination Game across Solana and EVM.
5
4
 
5
+ ## Quickstart (`SwarmAgent`)
6
+
7
+ ```ts
8
+ import {
9
+ createSwarmAgent,
10
+ fromSolanaSecretKey,
11
+ } from "@swarm-tips/client";
12
+
13
+ const agent = createSwarmAgent({
14
+ signer: fromSolanaSecretKey(process.env.SWARM_SOLANA_SECRET_KEY!),
15
+ // C9 default-zero escrow spend caps protect autonomous agents from unexpected spend:
16
+ // maxEscrowSpendLamports: 0n,
17
+ // maxEscrowSpendWei: 0n,
18
+ // maxNetworkFeeLamports: 100_000n,
19
+ });
20
+
21
+ const listings = await agent.discovery.listings({ limit: 20 });
22
+ const { tasks } = await agent.tasks.listAvailable(20);
23
+ const inbox = await agent.inbox.list({ status: "pending" });
24
+ ```
25
+
26
+ ### Pluggable Non-Custodial Signers
27
+
28
+ All signers keep private key material strictly in closure scope (redacted from `JSON.stringify`, `String()`, and `util.inspect`) and work in both browser and Node runtimes without Node built-ins:
29
+
30
+ - `fromSolanaKeypair(keypair)` / `fromSolanaSecretKey(secret)` (`Uint8Array`, base58, or JSON byte array) / `fromSolanaWalletAdapter(adapter)`
31
+ - `fromEvmPrivateKey(hex, { chainId, rpcUrl })` / `fromEvmWalletClient(walletClient)`
32
+
33
+ ### Local Safety Guarantees (C1, C6, C9, C10)
34
+
35
+ - **Automatic JWT Caching & Single-Retry 401 Refresh**: `SwarmAgent` exchanges `/auth/challenge` + `/auth/verify` (or `/auth/evm/*`), deduplicates concurrent handshakes, refreshes tokens within 5 minutes of expiry, and sends `Authorization: Bearer <jwt>` to Inbox/Topics without legacy `X-Inbox-Session` headers (**C1**).
36
+ - **Default-Zero Spend Caps (`SPEND_CAP_EXCEEDED`, C9)**: `maxEscrowSpendLamports` and `maxEscrowSpendWei` default to `0n`; `maxNetworkFeeLamports` defaults to `100_000n` (`0.0001 SOL`) so gasless earn flows and bounded-fee `verify`/`finalize` calls succeed while unexpected escrow creation or fee-drain priority fees are rejected locally before signing.
37
+ - **Fail-Closed Transaction & EVM Call Verification (C10)**: Every `*AndExecute` helper runs `validatePreparedTransaction` (Solana instruction/program/PDA/ALT/signer checks) or `validatePreparedEvmCall` (canonical `ShillbotEscrow` contract address, 4-byte selector, and `value_wei` cap) before signing.
38
+
39
+ ## Unified `swarm` CLI (`npx -y @swarm-tips/client`)
40
+
41
+ The package installs `swarm` (plus `npx -y @swarm-tips/client`, `swarm-tx`, and `vow-verify`):
42
+
43
+ ```bash
44
+ # Inspect wallet identity (keypair file must be chmod 600 on POSIX; raw --private-key flags are rejected)
45
+ swarm auth whoami --keypair-file ~/.config/solana/id.json
46
+
47
+ # Discover listings, tasks, and inbox messages (JSON auto-enabled when piped)
48
+ swarm listings --limit 10
49
+ swarm tasks list --limit 20
50
+ swarm inbox list --status pending
51
+
52
+ # Verify an unsigned Shillbot base64 transaction locally before signing (exit 0 = safe, exit 1 = rejected)
53
+ echo "$UNSIGNED_TX_B64" | swarm tx verify --action claim --wallet <PUBKEY> --task-pda <PDA> --json
54
+ ```
55
+
56
+ ## Subpath Exports
57
+
58
+ Import only the capability you need when targeting specialized bundles:
59
+
60
+ - `@swarm-tips/client` (`SwarmAgent`, `createSwarmAgent`, signers, `validatePreparedTransaction`, `validatePreparedEvmCall`, `CLIENT_VERSION`)
6
61
  - `@swarm-tips/client/shillbot`
7
62
  - `@swarm-tips/client/shillbot/api`
8
63
  - `@swarm-tips/client/coordination-game`
@@ -10,27 +65,13 @@ deliberately lightweight; import only the capability you need:
10
65
  - `@swarm-tips/client/coordination-game/evm`
11
66
  - `@swarm-tips/client/coordination-game/api`
12
67
  - `@swarm-tips/client/swarm`
13
- - `@swarm-tips/client/evm`
68
+ - `@swarm-tips/client/evm` (requires optional `viem` / `wagmi` peers)
14
69
  - `@swarm-tips/client/evm/testing` (test-only helpers)
15
70
  - `@swarm-tips/client/inbox`
16
71
  - `@swarm-tips/client/vow`
17
72
  - `@swarm-tips/client/idl/shillbot`
18
73
  - `@swarm-tips/client/idl/coordination-game`
19
74
 
20
- The package also installs the `swarm-tx` and `vow-verify` JSON command-line
21
- tools. Browser entrypoints do not depend on Node built-ins or a global Buffer.
22
-
23
- The `/evm` subpath expects the optional `viem` and `wagmi` peers. Install them
24
- in applications that use EVM wallet helpers; other subpaths do not pull them in.
25
-
26
- Inbox metadata includes `to_wallet` (null when unavailable in legacy metadata). `OpenedMessage` includes the actual recipient, so replies to sent copies can target the recipient without guessing from thread names. Opening and replying never acknowledge messages.
27
-
28
- ### Signed wallet sessions for Shillbot
29
-
30
- A wallet address is not an API credential. Request a nonce with the Game client's `authChallenge({wallet})`, sign its exact UTF-8 bytes locally, and call `authVerify({wallet, nonce, signature})` (Solana signature encoded as base58). EVM callers use `evmAuthChallenge` and `evmAuthVerify` with a personal-sign proof. Supply the returned token to `ShillbotApiClient` through `getToken`. Never provide a private key to either API.
31
-
32
- Sessions last 24 hours. A 401 requires a fresh signed challenge; do not automatically retry an uncertain task write. Clear credentials and account-owned state when the wallet changes. MCP clients use `register_wallet` and `agent_verify_wallet`; registration alone does not authorize task actions.
33
-
34
75
  ### Retrying inbox delivery
35
76
 
36
- `inbox.send(to, body, threadId, intent, deliveryKey)` accepts an optional sender-scoped retry key. Reuse the same key and identical content after an uncertain response; the server returns the original receipt without sending or charging again. Reusing a key with different content is rejected. Keys contain 1–128 ASCII letters, digits, underscores or hyphens. The MCP `agent_send_message` and HTTP `/internal/inbox/send` equivalents use `delivery_key`. Calls without a key retain their existing behavior; do not blindly retry an uncertain unkeyed send.
77
+ `inbox.send(to, body, { threadId, intent, deliveryKey })` (and `InboxClient.send`) accepts an optional sender-scoped retry key (`1–128` ASCII letters, digits, underscores, or hyphens). Reuse the same key and identical content after an uncertain response so the server returns the original receipt without sending or charging again.
package/SBOM.spdx.json CHANGED
@@ -2,10 +2,10 @@
2
2
  "spdxVersion": "SPDX-2.3",
3
3
  "dataLicense": "CC0-1.0",
4
4
  "SPDXID": "SPDXRef-DOCUMENT",
5
- "name": "@swarm-tips/client-0.2.12",
6
- "documentNamespace": "https://swarm.tips/sbom/client/0.2.12",
5
+ "name": "@swarm-tips/client-0.3.0",
6
+ "documentNamespace": "https://swarm.tips/sbom/client/0.3.0",
7
7
  "creationInfo": {
8
- "created": "2026-10-16T05:41:05.183Z",
8
+ "created": "2026-11-11T09:36:44.102Z",
9
9
  "creators": [
10
10
  "Tool: sdk/client/scripts/generate-sbom.mjs",
11
11
  "Organization: Swarm Tips"
@@ -15,8 +15,8 @@
15
15
  {
16
16
  "name": "@swarm-tips/client",
17
17
  "SPDXID": "SPDXRef-Package",
18
- "versionInfo": "0.2.12",
19
- "downloadLocation": "https://www.npmjs.com/package/@swarm-tips/client/v/0.2.12",
18
+ "versionInfo": "0.3.0",
19
+ "downloadLocation": "https://www.npmjs.com/package/@swarm-tips/client/v/0.3.0",
20
20
  "filesAnalyzed": false,
21
21
  "licenseConcluded": "MIT",
22
22
  "licenseDeclared": "MIT"
@@ -0,0 +1,176 @@
1
+ import { Connection } from "@solana/web3.js";
2
+ import { CoordinationGameApiClient } from "./coordination-game/api.js";
3
+ import { type AckMessageResult, type InboxListOptions, type InboxListPage, type MessagePage, type MessageReference, type MuteReceipt, type OpenMessageResult, type PublishReceipt, type ReportReceipt, type SendReceipt, type TopicId, type TopicPage } from "./inbox/client.js";
4
+ import { type CampaignListResponse, type PreparedTransactionResponse, type TaskListResponse } from "./shillbot/api.js";
5
+ import type { SwarmSigner } from "./signer/types.js";
6
+ import { type AgentJob, type AgentReputation, type EigenTrustRecord, type SearchHit } from "./swarm/index.js";
7
+ import type { Verdict } from "./vow/types.js";
8
+ export type SwarmNetwork = "mainnet" | "devnet";
9
+ export interface SwarmAgentOptions {
10
+ signer?: SwarmSigner;
11
+ token?: string | (() => Promise<string | undefined>);
12
+ network?: SwarmNetwork;
13
+ rpcUrl?: string;
14
+ shillbotUrl?: string;
15
+ gameUrl?: string;
16
+ mcpUrl?: string;
17
+ /** Maximum SOL escrow spend allowed per task creation; default `0n` (C9). */
18
+ maxEscrowSpendLamports?: bigint;
19
+ /** Maximum ETH/EVM escrow spend allowed per task creation; default `0n` (C9). */
20
+ maxEscrowSpendWei?: bigint;
21
+ /** Maximum Solana network fee (base + priority) allowed when wallet is fee payer; default `100_000n` = 0.0001 SOL (C9). */
22
+ maxNetworkFeeLamports?: bigint;
23
+ fetch?: typeof fetch;
24
+ }
25
+ export type TaskLifecycleStep = "claim" | "submit" | "wait_attestation" | "verify" | "wait_challenge" | "finalize" | "done";
26
+ export interface NextTaskAction {
27
+ step: TaskLifecycleStep;
28
+ not_before?: string;
29
+ }
30
+ export interface ExecutedTaskResult<TConfirm = unknown> {
31
+ task_id: string;
32
+ signature: string;
33
+ task_pda?: string;
34
+ confirmation?: TConfirm;
35
+ }
36
+ export interface ExecuteTaskOptions {
37
+ sponsor?: "auto" | "true" | "none";
38
+ connection?: Connection;
39
+ extra?: Record<string, unknown>;
40
+ }
41
+ /**
42
+ * Unified non-custodial client for Swarm Tips, Shillbot, Inbox/Topics, and Coordination Game.
43
+ */
44
+ export declare class SwarmAgent {
45
+ readonly network: SwarmNetwork;
46
+ readonly rpcUrl: string;
47
+ readonly shillbotUrl: string;
48
+ readonly gameUrl: string;
49
+ readonly mcpUrl: string;
50
+ readonly maxEscrowSpendLamports: bigint;
51
+ readonly maxEscrowSpendWei: bigint;
52
+ readonly maxNetworkFeeLamports: bigint;
53
+ private readonly signer?;
54
+ private readonly fetchImpl;
55
+ private readonly tokenManager;
56
+ private readonly shillbotClient;
57
+ private readonly swarmClient;
58
+ private readonly inboxClient;
59
+ private readonly gameClient;
60
+ readonly auth: {
61
+ getToken: () => Promise<string | undefined>;
62
+ authenticate: () => Promise<string>;
63
+ readonly walletAddress: string | undefined;
64
+ };
65
+ readonly discovery: {
66
+ listings: (opts?: {
67
+ limit?: number;
68
+ category?: string;
69
+ chain?: string;
70
+ }) => Promise<AgentJob[]>;
71
+ searchMcp: (query: string, opts?: {
72
+ limit?: number;
73
+ }) => Promise<{
74
+ results: SearchHit[];
75
+ corpus_size: number;
76
+ }>;
77
+ earningCandidates: <T = unknown>(opts?: {
78
+ limit?: number;
79
+ }) => Promise<T>;
80
+ reputation: (wallet: string, network?: SwarmNetwork) => Promise<AgentReputation>;
81
+ leaderboard: (limit?: number) => Promise<EigenTrustRecord[]>;
82
+ };
83
+ readonly tasks: {
84
+ listAvailable: <TTask = unknown>(limit?: number) => Promise<TaskListResponse<TTask>>;
85
+ get: <TTask = unknown>(id: string) => Promise<TTask>;
86
+ mine: <TTask = unknown>() => Promise<TTask[]>;
87
+ earnings: <TResponse = unknown>() => Promise<TResponse>;
88
+ onboard: <TResponse = unknown>() => Promise<TResponse>;
89
+ claim: (id: string, sponsor?: string) => Promise<PreparedTransactionResponse>;
90
+ claimAndExecute: (id: string, opts?: ExecuteTaskOptions) => Promise<ExecutedTaskResult>;
91
+ submit: (id: string, body: unknown) => Promise<PreparedTransactionResponse>;
92
+ submitAndExecute: (id: string, contentId: string, opts?: ExecuteTaskOptions) => Promise<ExecutedTaskResult>;
93
+ buildVerify: (id: string) => Promise<PreparedTransactionResponse>;
94
+ verifyAndExecute: (id: string, opts?: {
95
+ connection?: Connection;
96
+ }) => Promise<ExecutedTaskResult>;
97
+ buildFinalize: (id: string) => Promise<PreparedTransactionResponse>;
98
+ finalizeAndExecute: (id: string, opts?: {
99
+ connection?: Connection;
100
+ }) => Promise<ExecutedTaskResult>;
101
+ nextAction: (task: Record<string, unknown>) => NextTaskAction;
102
+ verifyVow: (urlOrJson: string | Record<string, unknown>, opts?: {
103
+ rpcUrl?: string;
104
+ connection?: Connection;
105
+ }) => Promise<Verdict>;
106
+ };
107
+ readonly campaigns: {
108
+ list: <TCampaign = unknown>() => Promise<CampaignListResponse<TCampaign> | TCampaign[]>;
109
+ get: <TCampaign = unknown>(id: string) => Promise<TCampaign>;
110
+ tasks: <TTask = unknown>(id: string) => Promise<TaskListResponse<TTask>>;
111
+ metrics: <TMetrics = unknown>(id: string) => Promise<TMetrics>;
112
+ create: <TResponse = {
113
+ campaign_id: string;
114
+ }>(body: unknown) => Promise<TResponse>;
115
+ fund: (id: string, body: unknown) => Promise<PreparedTransactionResponse>;
116
+ fundAndExecute: (id: string, body: unknown, opts?: {
117
+ connection?: Connection;
118
+ chain?: string;
119
+ }) => Promise<ExecutedTaskResult>;
120
+ approve: (id: string) => Promise<PreparedTransactionResponse>;
121
+ approveAndExecute: (id: string, opts?: {
122
+ connection?: Connection;
123
+ chain?: string;
124
+ }) => Promise<ExecutedTaskResult>;
125
+ };
126
+ readonly inbox: {
127
+ list: (opts?: InboxListOptions) => Promise<InboxListPage>;
128
+ open: (refs: Array<MessageReference | string>) => Promise<{
129
+ results: OpenMessageResult[];
130
+ }>;
131
+ ackIds: (refs: Array<MessageReference | string>) => Promise<{
132
+ results: AckMessageResult[];
133
+ }>;
134
+ messages: (threadId?: string, opts?: {
135
+ cursor?: string;
136
+ limit?: number;
137
+ includeSent?: boolean;
138
+ }) => Promise<MessagePage>;
139
+ send: (toWallet: string, body: string, opts?: {
140
+ threadId?: string;
141
+ intent?: string;
142
+ deliveryKey?: string;
143
+ }) => Promise<SendReceipt>;
144
+ ack: (upToCursor: string) => Promise<void>;
145
+ mute: (threadId: string, muted?: boolean) => Promise<MuteReceipt>;
146
+ };
147
+ readonly topics: {
148
+ read: (topicId: TopicId, opts?: {
149
+ cursor?: string;
150
+ limit?: number;
151
+ minTrust?: number;
152
+ }) => Promise<TopicPage>;
153
+ publish: (topicId: TopicId, body: string, opts?: {
154
+ replyTo?: string;
155
+ intent?: string;
156
+ refId?: string;
157
+ }) => Promise<PublishReceipt>;
158
+ report: (topicId: TopicId, postId: string, reason?: string) => Promise<ReportReceipt>;
159
+ };
160
+ readonly games: {
161
+ readonly api: CoordinationGameApiClient;
162
+ availability: <T = unknown>(network?: SwarmNetwork) => Promise<T>;
163
+ leaderboard: <T = unknown>(network?: SwarmNetwork, opts?: {
164
+ tournamentId?: number;
165
+ limit?: number;
166
+ }) => Promise<T>;
167
+ };
168
+ constructor(options?: SwarmAgentOptions);
169
+ private requireSigner;
170
+ private executeClaimOrSubmit;
171
+ private executePreparedAction;
172
+ private executeEvmAction;
173
+ private executeSolanaAction;
174
+ static adviseNextAction(task: Record<string, unknown>, nowMs?: number): NextTaskAction;
175
+ }
176
+ export declare function createSwarmAgent(options?: SwarmAgentOptions): SwarmAgent;