@swarm-tips/client 0.4.3 → 0.4.5
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 +3 -2
- package/SBOM.spdx.json +5 -5
- package/dist/agent.d.ts +1 -1
- package/dist/agent.js +1 -1
- package/dist/cli/swarm.js +11 -2
- package/dist/coordination-game/api.d.ts +49 -0
- package/dist/coordination-game/api.js +9 -0
- package/dist/coordination-game/evm/abi.d.ts +273 -5
- package/dist/coordination-game/evm/abi.js +347 -5
- package/dist/coordination-game/evm/cross-chain.d.ts +64 -1
- package/dist/coordination-game/evm/cross-chain.js +129 -6
- package/dist/coordination-game/evm/index.d.ts +2 -0
- package/dist/coordination-game/evm/index.js +1 -0
- package/dist/coordination-game/index.d.ts +1 -0
- package/dist/evm/index.d.ts +1 -1
- package/dist/evm/index.js +1 -1
- package/dist/evm/sign.d.ts +6 -0
- package/dist/evm/sign.js +17 -0
- package/dist/generated/openapi.d.ts +1 -1
- package/dist/generated/openapi.js +1 -1
- package/dist/http.js +1 -1
- package/dist/shillbot/api.d.ts +1 -1
- package/dist/shillbot/api.js +12 -3
- package/dist/signer/solana.d.ts +3 -2
- package/dist/signer/solana.js +36 -9
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Minimal CrossChainGame ABI for client-side EVM-leg calls (viem
|
|
3
3
|
* encodeFunctionData). Vendored from the Foundry artifact
|
|
4
|
-
* (swarm-tips-repo/evm/out/CrossChainGame.sol/CrossChainGame.json) —
|
|
5
|
-
*
|
|
6
|
-
* (refundTimeout/refundNoCert), and the read views (stakeWei,
|
|
7
|
-
* matches).
|
|
8
|
-
* vendored here. Regenerate if the contract ABI changes.
|
|
4
|
+
* (swarm-tips-repo/evm/out/CrossChainGame.sol/CrossChainGame.json) — covers
|
|
5
|
+
* fund (createMatch), lock (lockTranche), settle, refund
|
|
6
|
+
* (refundTimeout/refundNoCert), and the read views (stakeWei, poolFree,
|
|
7
|
+
* CHAIN_TAG, matches). Regenerate if the contract ABI changes.
|
|
9
8
|
*/
|
|
10
9
|
export const CROSS_CHAIN_GAME_ABI = [
|
|
11
10
|
{
|
|
@@ -64,6 +63,140 @@ export const CROSS_CHAIN_GAME_ABI = [
|
|
|
64
63
|
"outputs": [],
|
|
65
64
|
"stateMutability": "payable"
|
|
66
65
|
},
|
|
66
|
+
{
|
|
67
|
+
"type": "function",
|
|
68
|
+
"name": "lockTranche",
|
|
69
|
+
"inputs": [
|
|
70
|
+
{
|
|
71
|
+
"name": "cert",
|
|
72
|
+
"type": "tuple",
|
|
73
|
+
"internalType": "struct CertLib.MatchLiveCert",
|
|
74
|
+
"components": [
|
|
75
|
+
{
|
|
76
|
+
"name": "matchId",
|
|
77
|
+
"type": "bytes32",
|
|
78
|
+
"internalType": "bytes32"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"name": "tournamentId",
|
|
82
|
+
"type": "uint64",
|
|
83
|
+
"internalType": "uint64"
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"name": "matchupCommitment",
|
|
87
|
+
"type": "bytes32",
|
|
88
|
+
"internalType": "bytes32"
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"name": "legA",
|
|
92
|
+
"type": "tuple",
|
|
93
|
+
"internalType": "struct CertLib.Leg",
|
|
94
|
+
"components": [
|
|
95
|
+
{
|
|
96
|
+
"name": "chainTag",
|
|
97
|
+
"type": "bytes32",
|
|
98
|
+
"internalType": "bytes32"
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"name": "contractId",
|
|
102
|
+
"type": "bytes32",
|
|
103
|
+
"internalType": "bytes32"
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"name": "player",
|
|
107
|
+
"type": "bytes32",
|
|
108
|
+
"internalType": "bytes32"
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"name": "sessionKey",
|
|
112
|
+
"type": "address",
|
|
113
|
+
"internalType": "address"
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"name": "stake",
|
|
117
|
+
"type": "uint128",
|
|
118
|
+
"internalType": "uint128"
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"name": "tranche",
|
|
122
|
+
"type": "uint128",
|
|
123
|
+
"internalType": "uint128"
|
|
124
|
+
}
|
|
125
|
+
]
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
"name": "legB",
|
|
129
|
+
"type": "tuple",
|
|
130
|
+
"internalType": "struct CertLib.Leg",
|
|
131
|
+
"components": [
|
|
132
|
+
{
|
|
133
|
+
"name": "chainTag",
|
|
134
|
+
"type": "bytes32",
|
|
135
|
+
"internalType": "bytes32"
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
"name": "contractId",
|
|
139
|
+
"type": "bytes32",
|
|
140
|
+
"internalType": "bytes32"
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
"name": "player",
|
|
144
|
+
"type": "bytes32",
|
|
145
|
+
"internalType": "bytes32"
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
"name": "sessionKey",
|
|
149
|
+
"type": "address",
|
|
150
|
+
"internalType": "address"
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
"name": "stake",
|
|
154
|
+
"type": "uint128",
|
|
155
|
+
"internalType": "uint128"
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
"name": "tranche",
|
|
159
|
+
"type": "uint128",
|
|
160
|
+
"internalType": "uint128"
|
|
161
|
+
}
|
|
162
|
+
]
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
"name": "quoteTimestamp",
|
|
166
|
+
"type": "uint64",
|
|
167
|
+
"internalType": "uint64"
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
"name": "quoteMaxAgeSecs",
|
|
171
|
+
"type": "uint32",
|
|
172
|
+
"internalType": "uint32"
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
"name": "matchDeadline",
|
|
176
|
+
"type": "uint64",
|
|
177
|
+
"internalType": "uint64"
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
"name": "claimWindowSecs",
|
|
181
|
+
"type": "uint32",
|
|
182
|
+
"internalType": "uint32"
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
"name": "aIsP1",
|
|
186
|
+
"type": "uint8",
|
|
187
|
+
"internalType": "uint8"
|
|
188
|
+
}
|
|
189
|
+
]
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
"name": "operatorSig",
|
|
193
|
+
"type": "bytes",
|
|
194
|
+
"internalType": "bytes"
|
|
195
|
+
}
|
|
196
|
+
],
|
|
197
|
+
"outputs": [],
|
|
198
|
+
"stateMutability": "nonpayable"
|
|
199
|
+
},
|
|
67
200
|
{
|
|
68
201
|
"type": "function",
|
|
69
202
|
"name": "matches",
|
|
@@ -154,6 +287,24 @@ export const CROSS_CHAIN_GAME_ABI = [
|
|
|
154
287
|
"name": "bestOutcomeKind",
|
|
155
288
|
"type": "uint8",
|
|
156
289
|
"internalType": "uint8"
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
"name": "timeoutOpensAt",
|
|
293
|
+
"type": "uint64",
|
|
294
|
+
"internalType": "uint64"
|
|
295
|
+
}
|
|
296
|
+
],
|
|
297
|
+
"stateMutability": "view"
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
"type": "function",
|
|
301
|
+
"name": "poolFree",
|
|
302
|
+
"inputs": [],
|
|
303
|
+
"outputs": [
|
|
304
|
+
{
|
|
305
|
+
"name": "",
|
|
306
|
+
"type": "uint256",
|
|
307
|
+
"internalType": "uint256"
|
|
157
308
|
}
|
|
158
309
|
],
|
|
159
310
|
"stateMutability": "view"
|
|
@@ -184,6 +335,197 @@ export const CROSS_CHAIN_GAME_ABI = [
|
|
|
184
335
|
"outputs": [],
|
|
185
336
|
"stateMutability": "nonpayable"
|
|
186
337
|
},
|
|
338
|
+
{
|
|
339
|
+
"type": "function",
|
|
340
|
+
"name": "settle",
|
|
341
|
+
"inputs": [
|
|
342
|
+
{
|
|
343
|
+
"name": "cert",
|
|
344
|
+
"type": "tuple",
|
|
345
|
+
"internalType": "struct CertLib.MatchLiveCert",
|
|
346
|
+
"components": [
|
|
347
|
+
{
|
|
348
|
+
"name": "matchId",
|
|
349
|
+
"type": "bytes32",
|
|
350
|
+
"internalType": "bytes32"
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
"name": "tournamentId",
|
|
354
|
+
"type": "uint64",
|
|
355
|
+
"internalType": "uint64"
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
"name": "matchupCommitment",
|
|
359
|
+
"type": "bytes32",
|
|
360
|
+
"internalType": "bytes32"
|
|
361
|
+
},
|
|
362
|
+
{
|
|
363
|
+
"name": "legA",
|
|
364
|
+
"type": "tuple",
|
|
365
|
+
"internalType": "struct CertLib.Leg",
|
|
366
|
+
"components": [
|
|
367
|
+
{
|
|
368
|
+
"name": "chainTag",
|
|
369
|
+
"type": "bytes32",
|
|
370
|
+
"internalType": "bytes32"
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
"name": "contractId",
|
|
374
|
+
"type": "bytes32",
|
|
375
|
+
"internalType": "bytes32"
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
"name": "player",
|
|
379
|
+
"type": "bytes32",
|
|
380
|
+
"internalType": "bytes32"
|
|
381
|
+
},
|
|
382
|
+
{
|
|
383
|
+
"name": "sessionKey",
|
|
384
|
+
"type": "address",
|
|
385
|
+
"internalType": "address"
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
"name": "stake",
|
|
389
|
+
"type": "uint128",
|
|
390
|
+
"internalType": "uint128"
|
|
391
|
+
},
|
|
392
|
+
{
|
|
393
|
+
"name": "tranche",
|
|
394
|
+
"type": "uint128",
|
|
395
|
+
"internalType": "uint128"
|
|
396
|
+
}
|
|
397
|
+
]
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
"name": "legB",
|
|
401
|
+
"type": "tuple",
|
|
402
|
+
"internalType": "struct CertLib.Leg",
|
|
403
|
+
"components": [
|
|
404
|
+
{
|
|
405
|
+
"name": "chainTag",
|
|
406
|
+
"type": "bytes32",
|
|
407
|
+
"internalType": "bytes32"
|
|
408
|
+
},
|
|
409
|
+
{
|
|
410
|
+
"name": "contractId",
|
|
411
|
+
"type": "bytes32",
|
|
412
|
+
"internalType": "bytes32"
|
|
413
|
+
},
|
|
414
|
+
{
|
|
415
|
+
"name": "player",
|
|
416
|
+
"type": "bytes32",
|
|
417
|
+
"internalType": "bytes32"
|
|
418
|
+
},
|
|
419
|
+
{
|
|
420
|
+
"name": "sessionKey",
|
|
421
|
+
"type": "address",
|
|
422
|
+
"internalType": "address"
|
|
423
|
+
},
|
|
424
|
+
{
|
|
425
|
+
"name": "stake",
|
|
426
|
+
"type": "uint128",
|
|
427
|
+
"internalType": "uint128"
|
|
428
|
+
},
|
|
429
|
+
{
|
|
430
|
+
"name": "tranche",
|
|
431
|
+
"type": "uint128",
|
|
432
|
+
"internalType": "uint128"
|
|
433
|
+
}
|
|
434
|
+
]
|
|
435
|
+
},
|
|
436
|
+
{
|
|
437
|
+
"name": "quoteTimestamp",
|
|
438
|
+
"type": "uint64",
|
|
439
|
+
"internalType": "uint64"
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
"name": "quoteMaxAgeSecs",
|
|
443
|
+
"type": "uint32",
|
|
444
|
+
"internalType": "uint32"
|
|
445
|
+
},
|
|
446
|
+
{
|
|
447
|
+
"name": "matchDeadline",
|
|
448
|
+
"type": "uint64",
|
|
449
|
+
"internalType": "uint64"
|
|
450
|
+
},
|
|
451
|
+
{
|
|
452
|
+
"name": "claimWindowSecs",
|
|
453
|
+
"type": "uint32",
|
|
454
|
+
"internalType": "uint32"
|
|
455
|
+
},
|
|
456
|
+
{
|
|
457
|
+
"name": "aIsP1",
|
|
458
|
+
"type": "uint8",
|
|
459
|
+
"internalType": "uint8"
|
|
460
|
+
}
|
|
461
|
+
]
|
|
462
|
+
},
|
|
463
|
+
{
|
|
464
|
+
"name": "oc",
|
|
465
|
+
"type": "tuple",
|
|
466
|
+
"internalType": "struct CertLib.OutcomeCert",
|
|
467
|
+
"components": [
|
|
468
|
+
{
|
|
469
|
+
"name": "matchId",
|
|
470
|
+
"type": "bytes32",
|
|
471
|
+
"internalType": "bytes32"
|
|
472
|
+
},
|
|
473
|
+
{
|
|
474
|
+
"name": "matchLiveDigest",
|
|
475
|
+
"type": "bytes32",
|
|
476
|
+
"internalType": "bytes32"
|
|
477
|
+
},
|
|
478
|
+
{
|
|
479
|
+
"name": "outcomeKind",
|
|
480
|
+
"type": "uint8",
|
|
481
|
+
"internalType": "uint8"
|
|
482
|
+
},
|
|
483
|
+
{
|
|
484
|
+
"name": "stepCount",
|
|
485
|
+
"type": "uint8",
|
|
486
|
+
"internalType": "uint8"
|
|
487
|
+
},
|
|
488
|
+
{
|
|
489
|
+
"name": "p1Guess",
|
|
490
|
+
"type": "uint8",
|
|
491
|
+
"internalType": "uint8"
|
|
492
|
+
},
|
|
493
|
+
{
|
|
494
|
+
"name": "p2Guess",
|
|
495
|
+
"type": "uint8",
|
|
496
|
+
"internalType": "uint8"
|
|
497
|
+
},
|
|
498
|
+
{
|
|
499
|
+
"name": "firstCommitter",
|
|
500
|
+
"type": "uint8",
|
|
501
|
+
"internalType": "uint8"
|
|
502
|
+
},
|
|
503
|
+
{
|
|
504
|
+
"name": "matchupType",
|
|
505
|
+
"type": "uint8",
|
|
506
|
+
"internalType": "uint8"
|
|
507
|
+
},
|
|
508
|
+
{
|
|
509
|
+
"name": "transcriptHash",
|
|
510
|
+
"type": "bytes32",
|
|
511
|
+
"internalType": "bytes32"
|
|
512
|
+
}
|
|
513
|
+
]
|
|
514
|
+
},
|
|
515
|
+
{
|
|
516
|
+
"name": "liveSigs",
|
|
517
|
+
"type": "bytes[3]",
|
|
518
|
+
"internalType": "bytes[3]"
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
"name": "ocSigs",
|
|
522
|
+
"type": "bytes[3]",
|
|
523
|
+
"internalType": "bytes[3]"
|
|
524
|
+
}
|
|
525
|
+
],
|
|
526
|
+
"outputs": [],
|
|
527
|
+
"stateMutability": "nonpayable"
|
|
528
|
+
},
|
|
187
529
|
{
|
|
188
530
|
"type": "function",
|
|
189
531
|
"name": "stakeWei",
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { type Hex } from "viem";
|
|
2
|
-
import type { CoordinationGameApiClient, XMatchPayload } from "../api.js";
|
|
2
|
+
import type { CoordinationGameApiClient, XMatchPayload, XOutcomeCertPayload } from "../api.js";
|
|
3
3
|
export declare function unpadAddress(word: string): Hex;
|
|
4
|
+
/**
|
|
5
|
+
* Normalize a 65-byte `0x` secp256k1 `[r||s||v]` signature so `v` is in the
|
|
6
|
+
* EVM `ecrecover` / OpenZeppelin `ECDSA.recover` domain (`27 | 28`). The
|
|
7
|
+
* off-chain relay stores signatures with `v = 0 | 1`; passing `v < 27` directly
|
|
8
|
+
* to `CrossChainGame` reverts with `ECDSAInvalidSignature`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function normalizeEvmSigV(sig: string): Hex;
|
|
4
11
|
export interface CrossChainMatchResult {
|
|
5
12
|
match: XMatchPayload;
|
|
6
13
|
handle: string | undefined;
|
|
@@ -24,7 +31,63 @@ export interface EvmFundPin {
|
|
|
24
31
|
contract: Hex;
|
|
25
32
|
stakeWei: bigint;
|
|
26
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Reconstruct the `CertLib.MatchLiveCert` tuple expected by `CrossChainGame`
|
|
36
|
+
* (`lockTranche`, `settle`, `openClaim`, `supersedeClaim`,
|
|
37
|
+
* `submitEquivocationProof`) from a matched `XMatchPayload`. `chainTag` is
|
|
38
|
+
* recomputed as `keccak256(utf8(leg.chain))`, matching `game-api`.
|
|
39
|
+
*/
|
|
40
|
+
export declare function certTupleFromMatchPayload(match: XMatchPayload): {
|
|
41
|
+
readonly matchId: Hex;
|
|
42
|
+
readonly tournamentId: bigint;
|
|
43
|
+
readonly matchupCommitment: Hex;
|
|
44
|
+
readonly legA: {
|
|
45
|
+
readonly chainTag: `0x${string}`;
|
|
46
|
+
readonly contractId: Hex;
|
|
47
|
+
readonly player: Hex;
|
|
48
|
+
readonly sessionKey: `0x${string}`;
|
|
49
|
+
readonly stake: bigint;
|
|
50
|
+
readonly tranche: bigint;
|
|
51
|
+
};
|
|
52
|
+
readonly legB: {
|
|
53
|
+
readonly chainTag: `0x${string}`;
|
|
54
|
+
readonly contractId: Hex;
|
|
55
|
+
readonly player: Hex;
|
|
56
|
+
readonly sessionKey: `0x${string}`;
|
|
57
|
+
readonly stake: bigint;
|
|
58
|
+
readonly tranche: bigint;
|
|
59
|
+
};
|
|
60
|
+
readonly quoteTimestamp: bigint;
|
|
61
|
+
readonly quoteMaxAgeSecs: number;
|
|
62
|
+
readonly matchDeadline: bigint;
|
|
63
|
+
readonly claimWindowSecs: number;
|
|
64
|
+
readonly aIsP1: number;
|
|
65
|
+
};
|
|
27
66
|
export declare function buildEvmFundCall(match: XMatchPayload, pin: EvmFundPin): EvmFundCall;
|
|
67
|
+
/**
|
|
68
|
+
* Build the unsigned permissionless `CrossChainGame.lockTranche(cert, operatorSig)`
|
|
69
|
+
* call (`value === 0n`) from the matched `XMatchPayload`, verifying `leg_b`
|
|
70
|
+
* against `pin` and normalizing `operator_signature` `v` to `27 | 28`.
|
|
71
|
+
*/
|
|
72
|
+
export declare function buildEvmLockTrancheCall(match: XMatchPayload, pin: EvmFundPin): EvmFundCall;
|
|
73
|
+
export interface XSettleBundle {
|
|
74
|
+
outcome: Pick<XOutcomeCertPayload, "match_id" | "match_live_digest" | "outcome_kind" | "step_count" | "p1_guess" | "p2_guess" | "first_committer" | "matchup_type" | "transcript_hash">;
|
|
75
|
+
live_sigs: readonly [string, string, string];
|
|
76
|
+
oc_sigs: readonly [string, string, string];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Build the unsigned permissionless `CrossChainGame.settle(cert, oc, liveSigs, ocSigs)`
|
|
80
|
+
* call (`value === 0n`), verifying `leg_b` against `pin`, checking `match_id`
|
|
81
|
+
* and `match_live_digest` consistency, and normalizing all 6 signatures to
|
|
82
|
+
* EVM `v = 27 | 28`.
|
|
83
|
+
*/
|
|
84
|
+
export declare function buildEvmSettleCall(match: XMatchPayload, bundle: XSettleBundle, pin: EvmFundPin): EvmFundCall;
|
|
85
|
+
/**
|
|
86
|
+
* Read `CrossChainGame.matches(matchId).status` (`0 = None, 1 = Funded,
|
|
87
|
+
* 2 = Locked, 3 = Claiming, 4 = Settled, 5 = ClaimSettled, 6 = RefundedNoCert,
|
|
88
|
+
* 7 = RefundedTimeout`).
|
|
89
|
+
*/
|
|
90
|
+
export declare function readEvmXMatchStatus(rpcUrl: string, contract: Hex, matchId: Hex): Promise<number>;
|
|
28
91
|
export interface FundTargetReader {
|
|
29
92
|
stakeWei(contract: Hex): Promise<bigint>;
|
|
30
93
|
matchStatus(contract: Hex, matchId: Hex): Promise<number>;
|
|
@@ -1,9 +1,26 @@
|
|
|
1
|
-
import { createPublicClient, encodeFunctionData, http } from "viem";
|
|
1
|
+
import { createPublicClient, encodeFunctionData, http, keccak256, toBytes, } from "viem";
|
|
2
2
|
import { CROSS_CHAIN_GAME_ABI } from "./abi.js";
|
|
3
3
|
export function unpadAddress(word) {
|
|
4
4
|
const hex = word.startsWith("0x") ? word.slice(2) : word;
|
|
5
5
|
return `0x${hex.slice(-40)}`;
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Normalize a 65-byte `0x` secp256k1 `[r||s||v]` signature so `v` is in the
|
|
9
|
+
* EVM `ecrecover` / OpenZeppelin `ECDSA.recover` domain (`27 | 28`). The
|
|
10
|
+
* off-chain relay stores signatures with `v = 0 | 1`; passing `v < 27` directly
|
|
11
|
+
* to `CrossChainGame` reverts with `ECDSAInvalidSignature`.
|
|
12
|
+
*/
|
|
13
|
+
export function normalizeEvmSigV(sig) {
|
|
14
|
+
if (!/^0x[0-9a-fA-F]{130}$/.test(sig)) {
|
|
15
|
+
throw new Error(`expected 65-byte 0x signature (130 hex chars), got length ${sig.length}`);
|
|
16
|
+
}
|
|
17
|
+
const body = sig.slice(2).toLowerCase();
|
|
18
|
+
const rs = body.slice(0, 128);
|
|
19
|
+
let v = parseInt(body.slice(128, 130), 16);
|
|
20
|
+
if (v < 27)
|
|
21
|
+
v += 27;
|
|
22
|
+
return `0x${rs}${v.toString(16).padStart(2, "0")}`;
|
|
23
|
+
}
|
|
7
24
|
export async function findCrossChainMatch(api, input, options = {}) {
|
|
8
25
|
const joined = await api.joinCrossChainQueue({
|
|
9
26
|
wallet: input.wallet,
|
|
@@ -23,15 +40,49 @@ export async function findCrossChainMatch(api, input, options = {}) {
|
|
|
23
40
|
}
|
|
24
41
|
throw new Error("no opponent found before timeout");
|
|
25
42
|
}
|
|
26
|
-
|
|
43
|
+
function verifyPin(match, pin) {
|
|
27
44
|
const to = unpadAddress(match.leg_b.contract);
|
|
28
45
|
if (to.toLowerCase() !== pin.contract.toLowerCase()) {
|
|
29
46
|
throw new Error(`relay leg_b.contract ${to} != pinned CrossChainGame ${pin.contract}`);
|
|
30
47
|
}
|
|
31
|
-
const
|
|
32
|
-
if (
|
|
33
|
-
throw new Error(`relay leg_b.stake ${
|
|
48
|
+
const stakeWei = BigInt(match.leg_b.stake_base_units);
|
|
49
|
+
if (stakeWei !== pin.stakeWei) {
|
|
50
|
+
throw new Error(`relay leg_b.stake ${stakeWei} != pinned stake ${pin.stakeWei}`);
|
|
34
51
|
}
|
|
52
|
+
return { to, stakeWei };
|
|
53
|
+
}
|
|
54
|
+
function legTupleFromPayload(leg) {
|
|
55
|
+
return {
|
|
56
|
+
chainTag: keccak256(toBytes(leg.chain)),
|
|
57
|
+
contractId: leg.contract,
|
|
58
|
+
player: leg.player,
|
|
59
|
+
sessionKey: unpadAddress(leg.session_key),
|
|
60
|
+
stake: BigInt(leg.stake_base_units),
|
|
61
|
+
tranche: BigInt(leg.tranche_base_units),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Reconstruct the `CertLib.MatchLiveCert` tuple expected by `CrossChainGame`
|
|
66
|
+
* (`lockTranche`, `settle`, `openClaim`, `supersedeClaim`,
|
|
67
|
+
* `submitEquivocationProof`) from a matched `XMatchPayload`. `chainTag` is
|
|
68
|
+
* recomputed as `keccak256(utf8(leg.chain))`, matching `game-api`.
|
|
69
|
+
*/
|
|
70
|
+
export function certTupleFromMatchPayload(match) {
|
|
71
|
+
return {
|
|
72
|
+
matchId: match.match_id,
|
|
73
|
+
tournamentId: BigInt(match.tournament_id),
|
|
74
|
+
matchupCommitment: match.matchup_commitment,
|
|
75
|
+
legA: legTupleFromPayload(match.leg_a),
|
|
76
|
+
legB: legTupleFromPayload(match.leg_b),
|
|
77
|
+
quoteTimestamp: BigInt(match.quote_timestamp),
|
|
78
|
+
quoteMaxAgeSecs: Number(match.quote_max_age_secs),
|
|
79
|
+
matchDeadline: BigInt(match.match_deadline),
|
|
80
|
+
claimWindowSecs: Number(match.claim_window_secs),
|
|
81
|
+
aIsP1: Number(match.a_is_p1),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
export function buildEvmFundCall(match, pin) {
|
|
85
|
+
const { to, stakeWei } = verifyPin(match, pin);
|
|
35
86
|
const data = encodeFunctionData({
|
|
36
87
|
abi: CROSS_CHAIN_GAME_ABI,
|
|
37
88
|
functionName: "createMatch",
|
|
@@ -45,7 +96,79 @@ export function buildEvmFundCall(match, pin) {
|
|
|
45
96
|
match.create_match_operator_sig,
|
|
46
97
|
],
|
|
47
98
|
});
|
|
48
|
-
return { to, data, value };
|
|
99
|
+
return { to, data, value: stakeWei };
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Build the unsigned permissionless `CrossChainGame.lockTranche(cert, operatorSig)`
|
|
103
|
+
* call (`value === 0n`) from the matched `XMatchPayload`, verifying `leg_b`
|
|
104
|
+
* against `pin` and normalizing `operator_signature` `v` to `27 | 28`.
|
|
105
|
+
*/
|
|
106
|
+
export function buildEvmLockTrancheCall(match, pin) {
|
|
107
|
+
const { to } = verifyPin(match, pin);
|
|
108
|
+
const data = encodeFunctionData({
|
|
109
|
+
abi: CROSS_CHAIN_GAME_ABI,
|
|
110
|
+
functionName: "lockTranche",
|
|
111
|
+
args: [certTupleFromMatchPayload(match), normalizeEvmSigV(match.operator_signature)],
|
|
112
|
+
});
|
|
113
|
+
return { to, data, value: 0n };
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Build the unsigned permissionless `CrossChainGame.settle(cert, oc, liveSigs, ocSigs)`
|
|
117
|
+
* call (`value === 0n`), verifying `leg_b` against `pin`, checking `match_id`
|
|
118
|
+
* and `match_live_digest` consistency, and normalizing all 6 signatures to
|
|
119
|
+
* EVM `v = 27 | 28`.
|
|
120
|
+
*/
|
|
121
|
+
export function buildEvmSettleCall(match, bundle, pin) {
|
|
122
|
+
const { to } = verifyPin(match, pin);
|
|
123
|
+
if (bundle.outcome.match_id.toLowerCase() !== match.match_id.toLowerCase()) {
|
|
124
|
+
throw new Error(`outcome.match_id ${bundle.outcome.match_id} != match.match_id ${match.match_id}`);
|
|
125
|
+
}
|
|
126
|
+
if (match.match_live_digest &&
|
|
127
|
+
bundle.outcome.match_live_digest.toLowerCase() !== match.match_live_digest.toLowerCase()) {
|
|
128
|
+
throw new Error(`outcome.match_live_digest ${bundle.outcome.match_live_digest} != match.match_live_digest ${match.match_live_digest}`);
|
|
129
|
+
}
|
|
130
|
+
const oc = {
|
|
131
|
+
matchId: bundle.outcome.match_id,
|
|
132
|
+
matchLiveDigest: bundle.outcome.match_live_digest,
|
|
133
|
+
outcomeKind: Number(bundle.outcome.outcome_kind),
|
|
134
|
+
stepCount: Number(bundle.outcome.step_count),
|
|
135
|
+
p1Guess: Number(bundle.outcome.p1_guess),
|
|
136
|
+
p2Guess: Number(bundle.outcome.p2_guess),
|
|
137
|
+
firstCommitter: Number(bundle.outcome.first_committer),
|
|
138
|
+
matchupType: Number(bundle.outcome.matchup_type),
|
|
139
|
+
transcriptHash: bundle.outcome.transcript_hash,
|
|
140
|
+
};
|
|
141
|
+
const liveSigs = [
|
|
142
|
+
normalizeEvmSigV(bundle.live_sigs[0]),
|
|
143
|
+
normalizeEvmSigV(bundle.live_sigs[1]),
|
|
144
|
+
normalizeEvmSigV(bundle.live_sigs[2]),
|
|
145
|
+
];
|
|
146
|
+
const ocSigs = [
|
|
147
|
+
normalizeEvmSigV(bundle.oc_sigs[0]),
|
|
148
|
+
normalizeEvmSigV(bundle.oc_sigs[1]),
|
|
149
|
+
normalizeEvmSigV(bundle.oc_sigs[2]),
|
|
150
|
+
];
|
|
151
|
+
const data = encodeFunctionData({
|
|
152
|
+
abi: CROSS_CHAIN_GAME_ABI,
|
|
153
|
+
functionName: "settle",
|
|
154
|
+
args: [certTupleFromMatchPayload(match), oc, liveSigs, ocSigs],
|
|
155
|
+
});
|
|
156
|
+
return { to, data, value: 0n };
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Read `CrossChainGame.matches(matchId).status` (`0 = None, 1 = Funded,
|
|
160
|
+
* 2 = Locked, 3 = Claiming, 4 = Settled, 5 = ClaimSettled, 6 = RefundedNoCert,
|
|
161
|
+
* 7 = RefundedTimeout`).
|
|
162
|
+
*/
|
|
163
|
+
export async function readEvmXMatchStatus(rpcUrl, contract, matchId) {
|
|
164
|
+
const client = createPublicClient({ transport: http(rpcUrl) });
|
|
165
|
+
const result = (await client.readContract({
|
|
166
|
+
address: contract,
|
|
167
|
+
abi: CROSS_CHAIN_GAME_ABI,
|
|
168
|
+
functionName: "matches",
|
|
169
|
+
args: [matchId],
|
|
170
|
+
}));
|
|
171
|
+
return Number(result[0]);
|
|
49
172
|
}
|
|
50
173
|
export async function verifyEvmFundTarget(match, pin, readers) {
|
|
51
174
|
if (readers.length < 2)
|
|
@@ -5,3 +5,5 @@ export * from "./session-funding.js";
|
|
|
5
5
|
export * from "./transactions.js";
|
|
6
6
|
export * from "./cross-chain.js";
|
|
7
7
|
export * from "../chains.js";
|
|
8
|
+
export { signDigest, signDigestForRelay } from "../../evm/sign.js";
|
|
9
|
+
export type { XLegPayload, XMatchPayload, XOutcomeCertPayload, XSettleSigsResponse, XSolSettleTxResponse, } from "../api.js";
|
package/dist/evm/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { signDigestForRelay } from "./sign.js";
|
|
1
|
+
export { signDigest, signDigestForRelay } from "./sign.js";
|
|
2
2
|
export { sendUnsignedCall, sendContractCall, type UnsignedEvmCall, type CallSender, } from "./tx.js";
|
|
3
3
|
export { buildWagmiConfig, getEvmTestWalletKey, getEvmRpcOverride, type ChainWithRpcs, type WagmiConfigOpts, } from "./wallet.js";
|
package/dist/evm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Product-agnostic EVM frontend primitives shared across
|
|
2
2
|
// Swarm Tips frontends (coordination-game today; a future shillbot EVM flow
|
|
3
3
|
// just adds this package as a dependency + brings its own ABI/flow).
|
|
4
|
-
export { signDigestForRelay } from "./sign.js";
|
|
4
|
+
export { signDigest, signDigestForRelay } from "./sign.js";
|
|
5
5
|
export { sendUnsignedCall, sendContractCall, } from "./tx.js";
|
|
6
6
|
export { buildWagmiConfig, getEvmTestWalletKey, getEvmRpcOverride, } from "./wallet.js";
|
package/dist/evm/sign.d.ts
CHANGED
|
@@ -10,3 +10,9 @@ import type { Hex } from "viem";
|
|
|
10
10
|
* (the inverse axis; see chain-core `sign_digest_eth` / `evm_operator_sig_v_convention`).
|
|
11
11
|
*/
|
|
12
12
|
export declare function signDigestForRelay(privateKey: Hex, digestHex: Hex): Promise<Hex>;
|
|
13
|
+
/**
|
|
14
|
+
* Sign a `0x` 32-byte digest with an EVM private key, returning a `0x` 65-byte
|
|
15
|
+
* `[r||s||v]` secp256k1 signature with `v = 27 | 28` (the EVM `ecrecover` /
|
|
16
|
+
* OpenZeppelin `ECDSA.recover` convention verified by on-chain EVM contracts).
|
|
17
|
+
*/
|
|
18
|
+
export declare function signDigest(privateKey: Hex, digestHex: Hex): Promise<Hex>;
|