@swarm-tips/client 0.4.5 → 0.4.7
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/SBOM.spdx.json +5 -5
- package/dist/agent.d.ts +45 -0
- package/dist/agent.js +173 -22
- package/dist/cli/keyfile.d.ts +3 -2
- package/dist/cli/keyfile.js +21 -4
- package/dist/cli/swarm.js +71 -14
- package/dist/coordination-game/api.d.ts +61 -26
- package/dist/coordination-game/api.js +47 -18
- package/dist/coordination-game/evm/cross-chain.d.ts +25 -4
- package/dist/coordination-game/evm/cross-chain.js +28 -2
- package/dist/coordination-game/evm/index.d.ts +1 -1
- package/dist/coordination-game/evm/session.d.ts +81 -26
- package/dist/coordination-game/evm/session.js +273 -75
- package/dist/coordination-game/index.d.ts +1 -1
- package/dist/errors.d.ts +4 -0
- package/dist/errors.js +6 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +4 -3
- package/dist/shillbot/api.d.ts +17 -4
- package/dist/shillbot/api.js +31 -8
- package/dist/shillbot/index.d.ts +42 -4
- package/dist/shillbot/index.js +115 -8
- package/dist/shillbot/verify-tx.d.ts +17 -4
- package/dist/shillbot/verify-tx.js +172 -23
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/cli/swarm.js
CHANGED
|
@@ -4,7 +4,7 @@ import { fileURLToPath } from "node:url";
|
|
|
4
4
|
import { SwarmAgent } from "../agent.js";
|
|
5
5
|
import { SwarmClientError } from "../errors.js";
|
|
6
6
|
import { VALID_TOPICS, isValidTopicId } from "../inbox/types.js";
|
|
7
|
-
import { validatePreparedTransaction } from "../shillbot/api.js";
|
|
7
|
+
import { validatePreparedTransaction, } from "../shillbot/api.js";
|
|
8
8
|
import { inspectTransaction } from "../shillbot/index.js";
|
|
9
9
|
import { CLIENT_VERSION } from "../version.js";
|
|
10
10
|
import { CliUsageError, assertNoSecretCliFlags, loadSignerFromCliOrEnv, } from "./keyfile.js";
|
|
@@ -99,13 +99,15 @@ Usage:
|
|
|
99
99
|
|
|
100
100
|
Commands:
|
|
101
101
|
auth whoami | token
|
|
102
|
+
onboard
|
|
102
103
|
listings [--limit N] [--category CAT] [--chain CHAIN]
|
|
103
104
|
reputation <wallet>
|
|
104
|
-
tasks list [--limit N] | get <id> | mine | earnings | next <task-json-or-id>
|
|
105
|
-
tasks claim <id> [--payout-to <pubkey>] [--no-exec]
|
|
106
|
-
tasks submit <id> --content <str> [--payout-to <pubkey>] [--no-exec]
|
|
105
|
+
tasks list [--limit N] | get <id> | mine | earnings | onboard | next <task-json-or-id>
|
|
106
|
+
tasks claim <id> [--payout-to <pubkey>] [--fee-payer <pubkey>] [--no-exec]
|
|
107
|
+
tasks submit <id> --content <str> [--payout-to <pubkey>] [--fee-payer <pubkey>] [--no-exec]
|
|
107
108
|
tasks verify <id> [--no-exec]
|
|
108
109
|
tasks finalize <id> [--no-exec]
|
|
110
|
+
tasks expire <id> [--no-exec] (client escrow refund past claim/submit deadline or past submitted_at + verification_timeout)
|
|
109
111
|
inbox list [--status pending|all] [--limit N]
|
|
110
112
|
inbox open <msg_id...>
|
|
111
113
|
inbox send <to_wallet> <body> [--thread <id>] [--intent <intent>]
|
|
@@ -114,14 +116,16 @@ Commands:
|
|
|
114
116
|
topics read <open-challenge|subcontract|town-square> [--limit N]
|
|
115
117
|
topics publish <open-challenge|subcontract|town-square> <body> [--ref <id>] [--reply-to <id>] [--intent <intent>]
|
|
116
118
|
tx inspect [--tx <base64>]
|
|
117
|
-
tx verify --action <claim|submit|verify|finalize|approve|create> --wallet <pubkey> [--task-pda <pda>] [--payout-to <pubkey>] [--tx <base64>]
|
|
119
|
+
tx verify --action <claim|submit|verify|finalize|expire|approve|create> --wallet <pubkey> [--task-pda <pda>] [--payout-to <pubkey>] [--expire-task-state <open|claimed|submitted|approved>] [--tx <base64>]
|
|
118
120
|
vow-verify <file-or-url> [--rpc <url>]
|
|
119
121
|
|
|
120
122
|
Global Options:
|
|
121
123
|
--json Output structured JSON (auto-enabled when stdout is non-TTY)
|
|
122
124
|
--network <mainnet|devnet> Target network (default: mainnet)
|
|
123
|
-
--keypair-file <path> Solana keypair file (
|
|
125
|
+
--keypair-file <path> Solana keypair or 0x-prefixed 32-byte EVM hex key file (chmod 600 on POSIX)
|
|
124
126
|
--rpc-url <url> Override Solana RPC URL
|
|
127
|
+
--evm-rpc-url <url> Override EVM JSON-RPC URL
|
|
128
|
+
--evm-chain-id <id> Optional EVM chain ID or CAIP-2 identifier (e.g. 84532, eip155:8453)
|
|
125
129
|
--max-spend-lamports <n> Max SOL escrow spend cap (default: 0)
|
|
126
130
|
--max-spend-wei <n> Max EVM escrow spend cap (default: 0)
|
|
127
131
|
--help, -h Show this help text
|
|
@@ -130,7 +134,9 @@ Global Options:
|
|
|
130
134
|
Environment Variables:
|
|
131
135
|
SWARM_SOLANA_KEYPAIR_PATH Path to chmod 600 Solana keypair JSON/base58 file
|
|
132
136
|
SWARM_SOLANA_SECRET_KEY Base58 or JSON 64-byte Solana secret key
|
|
137
|
+
SWARM_EVM_KEYPAIR_PATH Path to chmod 600 0x-prefixed 32-byte EVM hex private key file
|
|
133
138
|
SWARM_EVM_PRIVATE_KEY 0x-prefixed 32-byte EVM private key
|
|
139
|
+
SWARM_EVM_RPC_URL EVM JSON-RPC URL for EVM transaction broadcast
|
|
134
140
|
SWARM_AUTH_TOKEN Pre-minted Bearer JWT
|
|
135
141
|
`;
|
|
136
142
|
const VALID_ACTIONS = new Set([
|
|
@@ -140,6 +146,13 @@ const VALID_ACTIONS = new Set([
|
|
|
140
146
|
"approve",
|
|
141
147
|
"verify",
|
|
142
148
|
"finalize",
|
|
149
|
+
"expire",
|
|
150
|
+
]);
|
|
151
|
+
const VALID_EXPIRE_STATES = new Set([
|
|
152
|
+
"open",
|
|
153
|
+
"claimed",
|
|
154
|
+
"submitted",
|
|
155
|
+
"approved",
|
|
143
156
|
]);
|
|
144
157
|
function writeOutput(stdout, jsonMode, payload) {
|
|
145
158
|
if (jsonMode) {
|
|
@@ -215,7 +228,7 @@ export async function runSwarmCli(argv, io = {}) {
|
|
|
215
228
|
if (sub === "verify") {
|
|
216
229
|
const rawAction = getStringFlag(flags, "--action");
|
|
217
230
|
if (!rawAction || !VALID_ACTIONS.has(rawAction)) {
|
|
218
|
-
throw new CliUsageError("Usage: swarm tx verify --action <claim|submit|verify|finalize|approve|create> --wallet <pubkey> [--task-pda <pda>] [--tx <base64>]");
|
|
231
|
+
throw new CliUsageError("Usage: swarm tx verify --action <claim|submit|verify|finalize|expire|approve|create> --wallet <pubkey> [--task-pda <pda>] [--tx <base64>]");
|
|
219
232
|
}
|
|
220
233
|
const wallet = getStringFlag(flags, "--wallet");
|
|
221
234
|
if (!wallet) {
|
|
@@ -227,7 +240,14 @@ export async function runSwarmCli(argv, io = {}) {
|
|
|
227
240
|
}
|
|
228
241
|
const taskPda = getStringFlag(flags, "--task-pda");
|
|
229
242
|
const feePayer = getStringFlag(flags, "--fee-payer");
|
|
243
|
+
const sponsor = getStringFlag(flags, "--sponsor");
|
|
230
244
|
const payoutTo = getStringFlag(flags, "--payout-to");
|
|
245
|
+
const rawExpireState = getStringFlag(flags, "--expire-task-state")?.trim().toLowerCase();
|
|
246
|
+
if (rawExpireState !== undefined &&
|
|
247
|
+
!VALID_EXPIRE_STATES.has(rawExpireState)) {
|
|
248
|
+
throw new CliUsageError(`Invalid --expire-task-state "${rawExpireState}". Expected open, claimed, submitted, or approved.`);
|
|
249
|
+
}
|
|
250
|
+
const expireTaskState = rawExpireState;
|
|
231
251
|
const oracleAuthority = getStringFlag(flags, "--oracle-authority");
|
|
232
252
|
const escrowLamports = getBigIntFlag(flags, "--escrow-lamports");
|
|
233
253
|
try {
|
|
@@ -237,7 +257,9 @@ export async function runSwarmCli(argv, io = {}) {
|
|
|
237
257
|
wallet,
|
|
238
258
|
...(taskPda ? { taskPda } : {}),
|
|
239
259
|
...(feePayer ? { feePayer } : {}),
|
|
260
|
+
...(sponsor ? { sponsor } : {}),
|
|
240
261
|
...(payoutTo ? { payoutTo } : {}),
|
|
262
|
+
...(expireTaskState ? { expireTaskState } : {}),
|
|
241
263
|
...(oracleAuthority ? { oracleAuthority } : {}),
|
|
242
264
|
...(escrowLamports !== undefined ? { escrowLamports } : {}),
|
|
243
265
|
});
|
|
@@ -252,10 +274,13 @@ export async function runSwarmCli(argv, io = {}) {
|
|
|
252
274
|
}
|
|
253
275
|
throw new CliUsageError("Usage: swarm tx <inspect|verify> [options]");
|
|
254
276
|
}
|
|
277
|
+
const evmRpcUrl = getStringFlag(flags, "--evm-rpc-url") ?? env.SWARM_EVM_RPC_URL;
|
|
278
|
+
const evmChainId = getStringFlag(flags, "--evm-chain-id") ?? env.SWARM_EVM_CHAIN_ID;
|
|
255
279
|
const signer = loadSignerFromCliOrEnv({
|
|
256
280
|
keypairFile: getStringFlag(flags, "--keypair-file"),
|
|
257
281
|
env,
|
|
258
|
-
evmRpcUrl
|
|
282
|
+
evmRpcUrl,
|
|
283
|
+
evmChainId,
|
|
259
284
|
});
|
|
260
285
|
const agent = new SwarmAgent({
|
|
261
286
|
signer,
|
|
@@ -269,6 +294,14 @@ export async function runSwarmCli(argv, io = {}) {
|
|
|
269
294
|
maxEscrowSpendWei,
|
|
270
295
|
fetch: io.fetch,
|
|
271
296
|
});
|
|
297
|
+
if (cmd === "onboard") {
|
|
298
|
+
if (!signer && !agent.auth.walletAddress && !env.SWARM_AUTH_TOKEN) {
|
|
299
|
+
throw new CliUsageError("No wallet configured. Pass --keypair-file <path> (chmod 600) or set SWARM_SOLANA_KEYPAIR_PATH, SWARM_SOLANA_SECRET_KEY, or SWARM_EVM_PRIVATE_KEY.");
|
|
300
|
+
}
|
|
301
|
+
const res = await agent.onboard();
|
|
302
|
+
writeOutput(stdout, jsonMode, res);
|
|
303
|
+
return 0;
|
|
304
|
+
}
|
|
272
305
|
if (cmd === "auth") {
|
|
273
306
|
if (sub === "whoami") {
|
|
274
307
|
if (!signer && !agent.auth.walletAddress) {
|
|
@@ -336,6 +369,11 @@ export async function runSwarmCli(argv, io = {}) {
|
|
|
336
369
|
writeOutput(stdout, jsonMode, res);
|
|
337
370
|
return 0;
|
|
338
371
|
}
|
|
372
|
+
if (sub === "onboard") {
|
|
373
|
+
const res = await agent.onboard();
|
|
374
|
+
writeOutput(stdout, jsonMode, res);
|
|
375
|
+
return 0;
|
|
376
|
+
}
|
|
339
377
|
if (sub === "next") {
|
|
340
378
|
const arg = rest[0] ?? (await readStdinText(io));
|
|
341
379
|
if (!arg) {
|
|
@@ -349,12 +387,17 @@ export async function runSwarmCli(argv, io = {}) {
|
|
|
349
387
|
}
|
|
350
388
|
if (sub === "claim") {
|
|
351
389
|
const id = rest[0];
|
|
352
|
-
if (!id)
|
|
353
|
-
throw new CliUsageError("Usage: swarm tasks claim <task_id> [--payout-to <pubkey>] [--no-exec]");
|
|
390
|
+
if (!id) {
|
|
391
|
+
throw new CliUsageError("Usage: swarm tasks claim <task_id> [--payout-to <pubkey>] [--fee-payer <pubkey>] [--no-exec]");
|
|
392
|
+
}
|
|
354
393
|
const payoutTo = getStringFlag(flags, "--payout-to");
|
|
394
|
+
const feePayer = getStringFlag(flags, "--fee-payer");
|
|
395
|
+
const execOpts = payoutTo || feePayer
|
|
396
|
+
? { ...(payoutTo ? { payoutTo } : {}), ...(feePayer ? { feePayer } : {}) }
|
|
397
|
+
: undefined;
|
|
355
398
|
const res = noExec
|
|
356
399
|
? await agent.tasks.claim(id)
|
|
357
|
-
: await agent.tasks.claimAndExecute(id,
|
|
400
|
+
: await agent.tasks.claimAndExecute(id, execOpts);
|
|
358
401
|
writeOutput(stdout, jsonMode, res);
|
|
359
402
|
return 0;
|
|
360
403
|
}
|
|
@@ -362,12 +405,16 @@ export async function runSwarmCli(argv, io = {}) {
|
|
|
362
405
|
const id = rest[0];
|
|
363
406
|
const content = getStringFlag(flags, "--content");
|
|
364
407
|
if (!id || !content) {
|
|
365
|
-
throw new CliUsageError("Usage: swarm tasks submit <task_id> --content <str> [--payout-to <pubkey>] [--no-exec]");
|
|
408
|
+
throw new CliUsageError("Usage: swarm tasks submit <task_id> --content <str> [--payout-to <pubkey>] [--fee-payer <pubkey>] [--no-exec]");
|
|
366
409
|
}
|
|
367
410
|
const payoutTo = getStringFlag(flags, "--payout-to");
|
|
411
|
+
const feePayer = getStringFlag(flags, "--fee-payer");
|
|
412
|
+
const execOpts = payoutTo || feePayer
|
|
413
|
+
? { ...(payoutTo ? { payoutTo } : {}), ...(feePayer ? { feePayer } : {}) }
|
|
414
|
+
: undefined;
|
|
368
415
|
const res = noExec
|
|
369
416
|
? await agent.tasks.submit(id, { content_id: content })
|
|
370
|
-
: await agent.tasks.submitAndExecute(id, content,
|
|
417
|
+
: await agent.tasks.submitAndExecute(id, content, execOpts);
|
|
371
418
|
writeOutput(stdout, jsonMode, res);
|
|
372
419
|
return 0;
|
|
373
420
|
}
|
|
@@ -391,7 +438,17 @@ export async function runSwarmCli(argv, io = {}) {
|
|
|
391
438
|
writeOutput(stdout, jsonMode, res);
|
|
392
439
|
return 0;
|
|
393
440
|
}
|
|
394
|
-
|
|
441
|
+
if (sub === "expire") {
|
|
442
|
+
const id = rest[0];
|
|
443
|
+
if (!id)
|
|
444
|
+
throw new CliUsageError("Usage: swarm tasks expire <task_id> [--no-exec]");
|
|
445
|
+
const res = noExec
|
|
446
|
+
? await agent.tasks.buildExpire(id)
|
|
447
|
+
: await agent.tasks.expireAndExecute(id);
|
|
448
|
+
writeOutput(stdout, jsonMode, res);
|
|
449
|
+
return 0;
|
|
450
|
+
}
|
|
451
|
+
throw new CliUsageError("Usage: swarm tasks <list|get|mine|earnings|onboard|next|claim|submit|verify|finalize|expire> ...");
|
|
395
452
|
}
|
|
396
453
|
if (cmd === "inbox") {
|
|
397
454
|
if (sub === "list") {
|
|
@@ -24,6 +24,8 @@ export interface SessionAuthResponse {
|
|
|
24
24
|
export interface QueueRequest {
|
|
25
25
|
tournament_id: number;
|
|
26
26
|
is_ai?: boolean;
|
|
27
|
+
/** Ergonomic camelCase alias mapped to `is_ai` on the JSON wire. */
|
|
28
|
+
isAi?: boolean;
|
|
27
29
|
}
|
|
28
30
|
export type QueueJoinResponse = {
|
|
29
31
|
matched: true;
|
|
@@ -120,6 +122,24 @@ export interface EvmJoinResponse {
|
|
|
120
122
|
match?: EvmMatchPayload;
|
|
121
123
|
session_id?: string;
|
|
122
124
|
}
|
|
125
|
+
export interface XQueueJoinInput {
|
|
126
|
+
wallet: string;
|
|
127
|
+
chain: string;
|
|
128
|
+
session_key: string;
|
|
129
|
+
tournament_id: number;
|
|
130
|
+
is_ai?: boolean;
|
|
131
|
+
/** Ergonomic camelCase alias mapped to `is_ai` on the JSON wire. */
|
|
132
|
+
isAi?: boolean;
|
|
133
|
+
}
|
|
134
|
+
export interface EvmGameJoinInput {
|
|
135
|
+
wallet: string;
|
|
136
|
+
player_wallet?: string;
|
|
137
|
+
chain: string;
|
|
138
|
+
tournament_id: number;
|
|
139
|
+
is_ai?: boolean;
|
|
140
|
+
/** Ergonomic camelCase alias mapped to `is_ai` on the JSON wire. */
|
|
141
|
+
isAi?: boolean;
|
|
142
|
+
}
|
|
123
143
|
export declare class CoordinationGameApiClient {
|
|
124
144
|
readonly http: HttpClient;
|
|
125
145
|
constructor(options: HttpClientOptions);
|
|
@@ -128,46 +148,47 @@ export declare class CoordinationGameApiClient {
|
|
|
128
148
|
authSession(body: SessionAuthRequest): Promise<SessionAuthResponse>;
|
|
129
149
|
evmAuthChallenge(body: ChallengeRequest): Promise<ChallengeResponse>;
|
|
130
150
|
evmAuthVerify(body: VerifyRequest): Promise<VerifyResponse>;
|
|
131
|
-
joinQueue(body: QueueRequest, token
|
|
132
|
-
leaveQueue(body: QueueRequest, token
|
|
151
|
+
joinQueue(body: QueueRequest, token?: string): Promise<QueueJoinResponse>;
|
|
152
|
+
leaveQueue(body: QueueRequest, token?: string): Promise<OkResponse>;
|
|
133
153
|
gameStarted(body: {
|
|
134
154
|
game_id: number;
|
|
135
155
|
session_id: string;
|
|
136
|
-
}, token
|
|
156
|
+
}, token?: string): Promise<OkResponse>;
|
|
137
157
|
gameJoined(body: {
|
|
138
158
|
game_id: number;
|
|
139
159
|
session_id: string;
|
|
140
|
-
}, token
|
|
160
|
+
}, token?: string): Promise<OkResponse>;
|
|
141
161
|
cosign(body: {
|
|
142
162
|
session_id: string;
|
|
143
163
|
message: string;
|
|
144
|
-
}, token
|
|
164
|
+
}, token?: string): Promise<{
|
|
145
165
|
signature: string;
|
|
146
166
|
}>;
|
|
147
167
|
cosignJoin(body: {
|
|
148
168
|
session_id: string;
|
|
149
169
|
message: string;
|
|
150
|
-
}, token
|
|
170
|
+
}, token?: string): Promise<{
|
|
151
171
|
signature: string;
|
|
152
172
|
}>;
|
|
153
173
|
committed(body: {
|
|
154
174
|
session_id: string;
|
|
155
|
-
}, token
|
|
175
|
+
}, token?: string): Promise<{
|
|
156
176
|
ok: boolean;
|
|
157
177
|
both_committed: boolean;
|
|
158
178
|
}>;
|
|
159
179
|
bothCommitted(body: {
|
|
160
180
|
session_id: string;
|
|
161
|
-
}, token
|
|
181
|
+
}, token?: string): Promise<{
|
|
162
182
|
r_matchup: string;
|
|
163
183
|
}>;
|
|
164
|
-
resolved(body: Record<string, number>, token
|
|
165
|
-
joinCrossChainQueue(body:
|
|
184
|
+
resolved(body: Record<string, number>, token?: string): Promise<OkResponse>;
|
|
185
|
+
joinCrossChainQueue(body: XQueueJoinInput, token?: string): Promise<XQueueResponse>;
|
|
186
|
+
leaveCrossChainQueue(body: {
|
|
166
187
|
wallet: string;
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}, token?: string): Promise<
|
|
188
|
+
tournament_id?: number;
|
|
189
|
+
chain?: string;
|
|
190
|
+
handle?: string;
|
|
191
|
+
}, token?: string): Promise<OkResponse>;
|
|
171
192
|
crossChainStatus(by: {
|
|
172
193
|
handle: string;
|
|
173
194
|
} | {
|
|
@@ -177,7 +198,7 @@ export declare class CoordinationGameApiClient {
|
|
|
177
198
|
wallet: string;
|
|
178
199
|
commit: string;
|
|
179
200
|
handle?: string;
|
|
180
|
-
}): Promise<{
|
|
201
|
+
}, token?: string): Promise<{
|
|
181
202
|
status: string;
|
|
182
203
|
both_committed: boolean;
|
|
183
204
|
}>;
|
|
@@ -186,7 +207,7 @@ export declare class CoordinationGameApiClient {
|
|
|
186
207
|
step: number;
|
|
187
208
|
signature: string;
|
|
188
209
|
handle?: string;
|
|
189
|
-
}): Promise<{
|
|
210
|
+
}, token?: string): Promise<{
|
|
190
211
|
status: string;
|
|
191
212
|
relayed: boolean;
|
|
192
213
|
r_matchup: string | null;
|
|
@@ -195,7 +216,7 @@ export declare class CoordinationGameApiClient {
|
|
|
195
216
|
wallet: string;
|
|
196
217
|
preimage: string;
|
|
197
218
|
handle?: string;
|
|
198
|
-
}): Promise<{
|
|
219
|
+
}, token?: string): Promise<{
|
|
199
220
|
status: string;
|
|
200
221
|
both_revealed: boolean;
|
|
201
222
|
}>;
|
|
@@ -203,7 +224,7 @@ export declare class CoordinationGameApiClient {
|
|
|
203
224
|
handle: string;
|
|
204
225
|
} | {
|
|
205
226
|
wallet: string;
|
|
206
|
-
}): Promise<XGameplayView>;
|
|
227
|
+
}, token?: string): Promise<XGameplayView>;
|
|
207
228
|
submitCrossChainSettleSigs(body: {
|
|
208
229
|
handle?: string;
|
|
209
230
|
wallet?: string;
|
|
@@ -216,29 +237,43 @@ export declare class CoordinationGameApiClient {
|
|
|
216
237
|
live_signature?: string;
|
|
217
238
|
outcome_signature?: string;
|
|
218
239
|
}, token?: string): Promise<XOutcomeCertPayload>;
|
|
240
|
+
buildCrossChainSolFund(body: {
|
|
241
|
+
handle?: string;
|
|
242
|
+
wallet?: string;
|
|
243
|
+
payer?: string;
|
|
244
|
+
}, token?: string): Promise<XSolSettleTxResponse>;
|
|
245
|
+
buildCrossChainSolLock(body: {
|
|
246
|
+
handle?: string;
|
|
247
|
+
wallet?: string;
|
|
248
|
+
payer?: string;
|
|
249
|
+
}, token?: string): Promise<XSolSettleTxResponse>;
|
|
219
250
|
buildCrossChainSolSettle(body: {
|
|
220
251
|
handle?: string;
|
|
221
252
|
wallet?: string;
|
|
222
253
|
payer?: string;
|
|
223
254
|
}, token?: string): Promise<XSolSettleTxResponse>;
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
255
|
+
buildCrossChainSolRefund(body: {
|
|
256
|
+
handle?: string;
|
|
257
|
+
wallet?: string;
|
|
258
|
+
payer?: string;
|
|
259
|
+
}, token?: string): Promise<XSolSettleTxResponse>;
|
|
260
|
+
joinEvmGame(body: EvmGameJoinInput, token?: string): Promise<EvmJoinResponse>;
|
|
261
|
+
evmGameStatus(walletOrBy: string | {
|
|
262
|
+
wallet?: string;
|
|
263
|
+
handle?: string;
|
|
229
264
|
}, token?: string): Promise<EvmJoinResponse>;
|
|
230
|
-
evmGameStatus(wallet: string, token?: string): Promise<EvmJoinResponse>;
|
|
231
265
|
evmGameCommitted(body: {
|
|
232
266
|
game_id: string;
|
|
233
267
|
wallet: string;
|
|
234
|
-
}): Promise<{
|
|
268
|
+
}, token?: string): Promise<{
|
|
235
269
|
status: string;
|
|
236
270
|
both_committed: boolean;
|
|
237
271
|
r_matchup: string | null;
|
|
238
272
|
}>;
|
|
239
273
|
evmGameStaked(body: {
|
|
240
274
|
game_id: string;
|
|
241
|
-
|
|
275
|
+
wallet?: string;
|
|
276
|
+
}, token?: string): Promise<{
|
|
242
277
|
status: string;
|
|
243
278
|
}>;
|
|
244
279
|
}
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { HttpClient } from "../http.js";
|
|
2
2
|
import { SwarmClientError } from "../errors.js";
|
|
3
|
+
function normalizeAiFlag(body) {
|
|
4
|
+
const { isAi, is_ai, ...rest } = body;
|
|
5
|
+
const resolved = is_ai ?? isAi;
|
|
6
|
+
return {
|
|
7
|
+
...rest,
|
|
8
|
+
...(resolved !== undefined ? { is_ai: resolved } : {}),
|
|
9
|
+
};
|
|
10
|
+
}
|
|
3
11
|
export class CoordinationGameApiClient {
|
|
4
12
|
http;
|
|
5
13
|
constructor(options) {
|
|
@@ -10,8 +18,12 @@ export class CoordinationGameApiClient {
|
|
|
10
18
|
authSession(body) { return this.http.post("/auth/session", body); }
|
|
11
19
|
evmAuthChallenge(body) { return this.http.post("/auth/evm/challenge", body); }
|
|
12
20
|
evmAuthVerify(body) { return this.http.post("/auth/evm/verify", body); }
|
|
13
|
-
joinQueue(body, token) {
|
|
14
|
-
|
|
21
|
+
joinQueue(body, token) {
|
|
22
|
+
return this.http.post("/queue/join", normalizeAiFlag(body), token);
|
|
23
|
+
}
|
|
24
|
+
leaveQueue(body, token) {
|
|
25
|
+
return this.http.post("/queue/leave", normalizeAiFlag(body), token);
|
|
26
|
+
}
|
|
15
27
|
gameStarted(body, token) { return this.http.post("/games/started", body, token); }
|
|
16
28
|
gameJoined(body, token) { return this.http.post("/games/joined", body, token); }
|
|
17
29
|
cosign(body, token) { return this.http.post("/games/cosign", body, token); }
|
|
@@ -20,7 +32,10 @@ export class CoordinationGameApiClient {
|
|
|
20
32
|
bothCommitted(body, token) { return this.http.post("/games/both-committed", body, token); }
|
|
21
33
|
resolved(body, token) { return this.http.post("/games/resolved", body, token); }
|
|
22
34
|
joinCrossChainQueue(body, token) {
|
|
23
|
-
return this.http.post("/internal/xqueue/join", body, token);
|
|
35
|
+
return this.http.post("/internal/xqueue/join", normalizeAiFlag(body), token);
|
|
36
|
+
}
|
|
37
|
+
leaveCrossChainQueue(body, token) {
|
|
38
|
+
return this.http.post("/internal/xqueue/leave", body, token);
|
|
24
39
|
}
|
|
25
40
|
crossChainStatus(by, token) {
|
|
26
41
|
const query = "handle" in by
|
|
@@ -28,20 +43,20 @@ export class CoordinationGameApiClient {
|
|
|
28
43
|
: `wallet=${encodeURIComponent(by.wallet)}`;
|
|
29
44
|
return this.http.get(`/internal/xqueue/status?${query}`, token);
|
|
30
45
|
}
|
|
31
|
-
crossChainCommit(body) {
|
|
32
|
-
return this.http.post("/internal/xqueue/commit", body);
|
|
46
|
+
crossChainCommit(body, token) {
|
|
47
|
+
return this.http.post("/internal/xqueue/commit", body, token);
|
|
33
48
|
}
|
|
34
|
-
crossChainSign(body) {
|
|
35
|
-
return this.http.post("/internal/xqueue/sign", body);
|
|
49
|
+
crossChainSign(body, token) {
|
|
50
|
+
return this.http.post("/internal/xqueue/sign", body, token);
|
|
36
51
|
}
|
|
37
|
-
crossChainReveal(body) {
|
|
38
|
-
return this.http.post("/internal/xqueue/reveal", body);
|
|
52
|
+
crossChainReveal(body, token) {
|
|
53
|
+
return this.http.post("/internal/xqueue/reveal", body, token);
|
|
39
54
|
}
|
|
40
|
-
crossChainGameplay(by) {
|
|
55
|
+
crossChainGameplay(by, token) {
|
|
41
56
|
const query = "handle" in by
|
|
42
57
|
? `handle=${encodeURIComponent(by.handle)}`
|
|
43
58
|
: `wallet=${encodeURIComponent(by.wallet)}`;
|
|
44
|
-
return this.http.get(`/internal/xqueue/gameplay?${query}
|
|
59
|
+
return this.http.get(`/internal/xqueue/gameplay?${query}`, token);
|
|
45
60
|
}
|
|
46
61
|
submitCrossChainSettleSigs(body, token) {
|
|
47
62
|
return this.http.post("/internal/xqueue/settle-sigs", body, token);
|
|
@@ -49,20 +64,34 @@ export class CoordinationGameApiClient {
|
|
|
49
64
|
crossChainOutcomeCosign(body, token) {
|
|
50
65
|
return this.http.post("/internal/xqueue/outcome-cosign", body, token);
|
|
51
66
|
}
|
|
67
|
+
buildCrossChainSolFund(body, token) {
|
|
68
|
+
return this.http.post("/internal/xqueue/build-sol-fund", body, token);
|
|
69
|
+
}
|
|
70
|
+
buildCrossChainSolLock(body, token) {
|
|
71
|
+
return this.http.post("/internal/xqueue/build-sol-lock", body, token);
|
|
72
|
+
}
|
|
52
73
|
buildCrossChainSolSettle(body, token) {
|
|
53
74
|
return this.http.post("/internal/xqueue/build-sol-settle", body, token);
|
|
54
75
|
}
|
|
76
|
+
buildCrossChainSolRefund(body, token) {
|
|
77
|
+
return this.http.post("/internal/xqueue/build-sol-refund", body, token);
|
|
78
|
+
}
|
|
55
79
|
joinEvmGame(body, token) {
|
|
56
|
-
return this.http.post("/internal/evmgame/join", body, token);
|
|
80
|
+
return this.http.post("/internal/evmgame/join", normalizeAiFlag(body), token);
|
|
57
81
|
}
|
|
58
|
-
evmGameStatus(
|
|
59
|
-
|
|
82
|
+
evmGameStatus(walletOrBy, token) {
|
|
83
|
+
const query = typeof walletOrBy === "string"
|
|
84
|
+
? `wallet=${encodeURIComponent(walletOrBy)}`
|
|
85
|
+
: walletOrBy.handle
|
|
86
|
+
? `handle=${encodeURIComponent(walletOrBy.handle)}`
|
|
87
|
+
: `wallet=${encodeURIComponent(walletOrBy.wallet ?? "")}`;
|
|
88
|
+
return this.http.get(`/internal/evmgame/status?${query}`, token);
|
|
60
89
|
}
|
|
61
|
-
evmGameCommitted(body) {
|
|
62
|
-
return this.http.post("/internal/evmgame/committed", body);
|
|
90
|
+
evmGameCommitted(body, token) {
|
|
91
|
+
return this.http.post("/internal/evmgame/committed", body, token);
|
|
63
92
|
}
|
|
64
|
-
evmGameStaked(body) {
|
|
65
|
-
return this.http.post("/internal/evmgame/staked", body);
|
|
93
|
+
evmGameStaked(body, token) {
|
|
94
|
+
return this.http.post("/internal/evmgame/staked", body, token);
|
|
66
95
|
}
|
|
67
96
|
}
|
|
68
97
|
export class CoordinationGameWebSocketClient {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Hex } from "viem";
|
|
2
|
-
import type { CoordinationGameApiClient, XMatchPayload, XOutcomeCertPayload } from "../api.js";
|
|
2
|
+
import type { CoordinationGameApiClient, EvmMatchPayload, XMatchPayload, XOutcomeCertPayload } from "../api.js";
|
|
3
3
|
export declare function unpadAddress(word: string): Hex;
|
|
4
4
|
/**
|
|
5
5
|
* Normalize a 65-byte `0x` secp256k1 `[r||s||v]` signature so `v` is in the
|
|
@@ -12,16 +12,37 @@ export interface CrossChainMatchResult {
|
|
|
12
12
|
match: XMatchPayload;
|
|
13
13
|
handle: string | undefined;
|
|
14
14
|
}
|
|
15
|
-
export
|
|
15
|
+
export interface FindCrossChainMatchInput {
|
|
16
16
|
wallet: string;
|
|
17
17
|
sessionKeyAddress: string;
|
|
18
18
|
tournamentId: number;
|
|
19
19
|
chain: string;
|
|
20
|
-
|
|
20
|
+
isAi?: boolean;
|
|
21
|
+
is_ai?: boolean;
|
|
22
|
+
token?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface FindMatchPollOptions {
|
|
21
25
|
pollMs?: number;
|
|
22
26
|
maxPolls?: number;
|
|
23
27
|
sleep?: (ms: number) => Promise<void>;
|
|
24
|
-
|
|
28
|
+
token?: string;
|
|
29
|
+
isAi?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export declare function findCrossChainMatch(api: CoordinationGameApiClient, input: FindCrossChainMatchInput, options?: FindMatchPollOptions): Promise<CrossChainMatchResult>;
|
|
32
|
+
export interface FindEvmMatchInput {
|
|
33
|
+
wallet: string;
|
|
34
|
+
playerWallet?: string;
|
|
35
|
+
tournamentId: number;
|
|
36
|
+
chain: string;
|
|
37
|
+
isAi?: boolean;
|
|
38
|
+
is_ai?: boolean;
|
|
39
|
+
token?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface EvmMatchResult {
|
|
42
|
+
match: EvmMatchPayload;
|
|
43
|
+
sessionId: string | undefined;
|
|
44
|
+
}
|
|
45
|
+
export declare function findEvmMatch(api: CoordinationGameApiClient, input: FindEvmMatchInput, options?: FindMatchPollOptions): Promise<EvmMatchResult>;
|
|
25
46
|
export interface EvmFundCall {
|
|
26
47
|
to: Hex;
|
|
27
48
|
data: Hex;
|
|
@@ -22,24 +22,50 @@ export function normalizeEvmSigV(sig) {
|
|
|
22
22
|
return `0x${rs}${v.toString(16).padStart(2, "0")}`;
|
|
23
23
|
}
|
|
24
24
|
export async function findCrossChainMatch(api, input, options = {}) {
|
|
25
|
+
const resolvedToken = options.token ?? input.token;
|
|
26
|
+
const resolvedIsAi = options.isAi ?? input.isAi ?? input.is_ai;
|
|
25
27
|
const joined = await api.joinCrossChainQueue({
|
|
26
28
|
wallet: input.wallet,
|
|
27
29
|
chain: input.chain,
|
|
28
30
|
session_key: input.sessionKeyAddress,
|
|
29
31
|
tournament_id: input.tournamentId,
|
|
30
|
-
|
|
32
|
+
...(resolvedIsAi !== undefined ? { is_ai: resolvedIsAi } : {}),
|
|
33
|
+
}, resolvedToken);
|
|
31
34
|
const handle = joined.poll_handle;
|
|
32
35
|
if (joined.status === "matched" && joined.match)
|
|
33
36
|
return { match: joined.match, handle };
|
|
34
37
|
const sleep = options.sleep ?? ((ms) => new Promise((resolve) => globalThis.setTimeout(resolve, ms)));
|
|
35
38
|
for (let index = 0; index < (options.maxPolls ?? 60); index += 1) {
|
|
36
39
|
await sleep(options.pollMs ?? 4_000);
|
|
37
|
-
const next = await api.crossChainStatus(handle ? { handle } : { wallet: input.wallet });
|
|
40
|
+
const next = await api.crossChainStatus(handle ? { handle } : { wallet: input.wallet }, resolvedToken);
|
|
38
41
|
if (next.status === "matched" && next.match)
|
|
39
42
|
return { match: next.match, handle };
|
|
40
43
|
}
|
|
41
44
|
throw new Error("no opponent found before timeout");
|
|
42
45
|
}
|
|
46
|
+
export async function findEvmMatch(api, input, options = {}) {
|
|
47
|
+
const resolvedToken = options.token ?? input.token;
|
|
48
|
+
const resolvedIsAi = options.isAi ?? input.isAi ?? input.is_ai;
|
|
49
|
+
const joined = await api.joinEvmGame({
|
|
50
|
+
wallet: input.wallet,
|
|
51
|
+
...(input.playerWallet ? { player_wallet: input.playerWallet } : {}),
|
|
52
|
+
chain: input.chain,
|
|
53
|
+
tournament_id: input.tournamentId,
|
|
54
|
+
...(resolvedIsAi !== undefined ? { is_ai: resolvedIsAi } : {}),
|
|
55
|
+
}, resolvedToken);
|
|
56
|
+
if (joined.status === "matched" && joined.match) {
|
|
57
|
+
return { match: joined.match, sessionId: joined.session_id };
|
|
58
|
+
}
|
|
59
|
+
const sleep = options.sleep ?? ((ms) => new Promise((resolve) => globalThis.setTimeout(resolve, ms)));
|
|
60
|
+
for (let index = 0; index < (options.maxPolls ?? 60); index += 1) {
|
|
61
|
+
await sleep(options.pollMs ?? 4_000);
|
|
62
|
+
const next = await api.evmGameStatus(input.wallet, resolvedToken);
|
|
63
|
+
if (next.status === "matched" && next.match) {
|
|
64
|
+
return { match: next.match, sessionId: next.session_id ?? joined.session_id };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
throw new Error("no opponent found before timeout");
|
|
68
|
+
}
|
|
43
69
|
function verifyPin(match, pin) {
|
|
44
70
|
const to = unpadAddress(match.leg_b.contract);
|
|
45
71
|
if (to.toLowerCase() !== pin.contract.toLowerCase()) {
|
|
@@ -6,4 +6,4 @@ export * from "./transactions.js";
|
|
|
6
6
|
export * from "./cross-chain.js";
|
|
7
7
|
export * from "../chains.js";
|
|
8
8
|
export { signDigest, signDigestForRelay } from "../../evm/sign.js";
|
|
9
|
-
export type { XLegPayload, XMatchPayload, XOutcomeCertPayload, XSettleSigsResponse, XSolSettleTxResponse, } from "../api.js";
|
|
9
|
+
export type { EvmGameJoinInput, XLegPayload, XMatchPayload, XOutcomeCertPayload, XQueueJoinInput, XSettleSigsResponse, XSolSettleTxResponse, } from "../api.js";
|