@swarm-tips/client 0.4.6 → 0.4.8

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.
@@ -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: string): Promise<QueueJoinResponse>;
132
- leaveQueue(body: QueueRequest, token: string): Promise<OkResponse>;
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: string): Promise<OkResponse>;
156
+ }, token?: string): Promise<OkResponse>;
137
157
  gameJoined(body: {
138
158
  game_id: number;
139
159
  session_id: string;
140
- }, token: string): Promise<OkResponse>;
160
+ }, token?: string): Promise<OkResponse>;
141
161
  cosign(body: {
142
162
  session_id: string;
143
163
  message: string;
144
- }, token: string): Promise<{
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: string): Promise<{
170
+ }, token?: string): Promise<{
151
171
  signature: string;
152
172
  }>;
153
173
  committed(body: {
154
174
  session_id: string;
155
- }, token: string): Promise<{
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: string): Promise<{
181
+ }, token?: string): Promise<{
162
182
  r_matchup: string;
163
183
  }>;
164
- resolved(body: Record<string, number>, token: string): Promise<OkResponse>;
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
- chain: string;
168
- session_key: string;
169
- tournament_id: number;
170
- }, token?: string): Promise<XQueueResponse>;
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
- joinEvmGame(body: {
225
- wallet: string;
226
- player_wallet?: string;
227
- chain: string;
228
- tournament_id: number;
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
- }): Promise<{
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) { return this.http.post("/queue/join", body, token); }
14
- leaveQueue(body, token) { return this.http.post("/queue/leave", body, token); }
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(wallet, token) {
59
- return this.http.get(`/internal/evmgame/status?wallet=${encodeURIComponent(wallet)}`, token);
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 declare function findCrossChainMatch(api: CoordinationGameApiClient, input: {
15
+ export interface FindCrossChainMatchInput {
16
16
  wallet: string;
17
17
  sessionKeyAddress: string;
18
18
  tournamentId: number;
19
19
  chain: string;
20
- }, options?: {
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
- }): Promise<CrossChainMatchResult>;
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";
@@ -1,43 +1,98 @@
1
1
  /**
2
2
  * Ephemeral EVM session key — the Base-game analog of the Solana session
3
3
  * keypair (`session.ts`). One main-wallet popup funds the session address with
4
- * stake + gas; the session key then signs createGame/joinGame/commitGuess/
5
- * revealGuess locally.
4
+ * gas (while stake is escrowed to the player's on-chain ledger); the session key
5
+ * then signs createGame/joinGame/commitGuess/revealGuess locally.
6
6
  *
7
- * Under the shipped v3 WALLET-AS-PLAYER design the session key is a gas-only
8
- * DELEGATE, not the player: the wallet is `game.player1/2` on-chain, and the
9
- * payout is credited to the wallet and realized with `withdrawFor`. There is
10
- * therefore NO sweep, and no `evm-sweep.ts` — that file never existed under v3.
11
- *
12
- * The private key lives in sessionStorage (cleared on tab close) bound to the
13
- * main wallet, with a 24h TTL — same guards as the Solana session. Only gas
14
- * dust ever sits on the session address.
7
+ * Persistence invariant (`P1-5`): active EVM session keys are persisted in
8
+ * `localStorage` first (mirroring to `sessionStorage`, and falling back to
9
+ * `sessionStorage` when `localStorage` is unavailable) and retained until the
10
+ * delegate's on-chain ETH balance is swept to `0`, so closing and reopening a
11
+ * browser tab never orphans funded ETH in an ephemeral EVM session key. Legacy
12
+ * keys stored only in `sessionStorage` are transparently migrated to `localStorage`.
15
13
  */
16
- import { type Chain, type Hex, type PublicClient, type WalletClient } from "viem";
14
+ import { type Account, type Chain, type Hex, type PublicClient, type WalletClient } from "viem";
15
+ export declare const EVM_SESSION_STORAGE_KEY = "coordination-evm-session";
17
16
  export interface SessionStorageLike {
18
17
  getItem(key: string): string | null;
19
18
  setItem(key: string, value: string): void;
20
19
  removeItem(key: string): void;
21
20
  }
21
+ export interface EvmSessionStoragePair {
22
+ localStorage?: SessionStorageLike | null;
23
+ sessionStorage?: SessionStorageLike | null;
24
+ }
25
+ export type EvmSessionStorageInput = SessionStorageLike | EvmSessionStoragePair | null | undefined;
22
26
  /** Generate a fresh ephemeral secp256k1 private key for session signing. */
23
27
  export declare function generateEvmSessionKey(): Hex;
24
28
  /**
25
- * Read the session key from sessionStorage. Returns null if no session
26
- * exists, the session has expired (24h TTL), or it belongs to a different
27
- * main wallet. Any invalid stored value is removed.
28
- */
29
- export declare function getStoredEvmSession(storage: SessionStorageLike, walletAddress?: string, now?: () => number): Hex | null;
30
- /** Persist the session key in sessionStorage, bound to the main wallet. */
31
- export declare function storeEvmSession(storage: SessionStorageLike, privateKey: Hex, walletAddress: string, now?: () => number): void;
32
- /** Remove the session key from sessionStorage. */
33
- export declare function clearEvmSession(storage: SessionStorageLike): void;
34
- /** Persist the committed guess preimage for `gameId` so a reload can still reveal. */
35
- export declare function persistEvmGuess(storage: SessionStorageLike, gameId: string, r: Uint8Array): void;
36
- /** The persisted preimage for `gameId`, or null (missing / different game /
37
- * unreadable). A mismatched gameId guards against revealing a stale guess. */
38
- export declare function loadEvmGuess(storage: SessionStorageLike, gameId: string): Uint8Array | null;
29
+ * Read the persisted EVM session key from `localStorage` first, falling back to
30
+ * `sessionStorage` and migrating legacy `sessionStorage`-only keys into `localStorage`.
31
+ * Retains valid keys across tab closes and past 24h until explicitly cleared after
32
+ * on-chain ETH balance is swept to `0`.
33
+ */
34
+ export declare function getStoredEvmSession(storage?: EvmSessionStorageInput, walletAddress?: string, _now?: () => number): Hex | null;
35
+ /**
36
+ * Ergonomic loader for persisted EVM session keys (`localStorage` primary,
37
+ * `sessionStorage` fallback + legacy migration).
38
+ */
39
+ export declare function loadSessionKey(walletAddress?: string, storage?: EvmSessionStorageInput): Hex | null;
40
+ export declare function loadSessionKey(storage: EvmSessionStorageInput, walletAddress?: string): Hex | null;
41
+ /**
42
+ * Persist the EVM session key in `localStorage` first, mirroring to `sessionStorage`
43
+ * (and falling back to `sessionStorage` when `localStorage` is unavailable).
44
+ */
45
+ export declare function storeEvmSession(storage: EvmSessionStorageInput, privateKey: Hex, walletAddress: string, now?: () => number): void;
46
+ /** Ergonomic helper to persist an EVM session key in `localStorage` + `sessionStorage`. */
47
+ export declare function saveSessionKey(privateKey: Hex, walletAddress: string, options?: EvmSessionStoragePair & {
48
+ now?: () => number;
49
+ }): void;
50
+ /** Remove the EVM session key from both `localStorage` and `sessionStorage`. */
51
+ export declare function clearEvmSession(storage?: EvmSessionStorageInput): void;
52
+ /** A plain native-ETH transfer uses 21,000 gas. */
53
+ export declare const SWEEP_GAS_LIMIT = 21000n;
54
+ /**
55
+ * Compute the native ETH amount to sweep from a session key back to the main wallet:
56
+ * `balance - 1.25 * (21_000 * maxFeePerGas)`, clamped at `0n`.
57
+ */
58
+ export declare function sweepValueWei(balance: bigint, maxFeePerGas: bigint): bigint;
59
+ export interface SweepEvmSessionOptions {
60
+ storage?: EvmSessionStorageInput;
61
+ /** When `true`, deduct exact `21_000 * maxFeePerGas` with `maxPriorityFeePerGas = maxFeePerGas` so EIP-1559 drains to `0n`. */
62
+ exact?: boolean;
63
+ readClient?: {
64
+ getBalance: (args: {
65
+ address: Hex;
66
+ }) => Promise<bigint>;
67
+ estimateFeesPerGas?: () => Promise<{
68
+ maxFeePerGas?: bigint;
69
+ maxPriorityFeePerGas?: bigint;
70
+ }>;
71
+ getGasPrice?: () => Promise<bigint>;
72
+ waitForTransactionReceipt: (args: {
73
+ hash: Hex;
74
+ }) => Promise<{
75
+ status?: string;
76
+ }>;
77
+ };
78
+ walletClient?: {
79
+ account?: Account | Hex;
80
+ sendTransaction: (args: Record<string, unknown>) => Promise<Hex>;
81
+ };
82
+ }
83
+ /**
84
+ * Sweep leftover ETH from an EVM session key back to `mainWallet`, clearing
85
+ * persisted storage **only** once the session address's on-chain balance reaches `0n`.
86
+ * If the sweep fails or non-zero balance remains on-chain, the key is retained in
87
+ * `localStorage` so funded ETH is never orphaned.
88
+ */
89
+ export declare function sweepEvmSession(sessionKey: Hex, mainWallet: Hex, chain: Chain, rpcUrls: string[], options?: SweepEvmSessionOptions): Promise<bigint>;
90
+ /** Persist the committed guess preimage for `gameId` so a reload/reopen can still reveal. */
91
+ export declare function persistEvmGuess(storage: EvmSessionStorageInput, gameId: string, r: Uint8Array): void;
92
+ /** The persisted preimage for `gameId`, or null (missing / different game / unreadable). */
93
+ export declare function loadEvmGuess(storage: EvmSessionStorageInput, gameId: string): Uint8Array | null;
39
94
  /** Drop the persisted guess once the game is done. */
40
- export declare function clearEvmGuess(storage: SessionStorageLike): void;
95
+ export declare function clearEvmGuess(storage?: EvmSessionStorageInput): void;
41
96
  /** 0x address of a session private key. */
42
97
  export declare function evmSessionAddress(privateKey: Hex): Hex;
43
98
  /**