@pokertools/sdk 1.0.4
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 +199 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/index.cjs +1126 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +750 -0
- package/dist/index.d.ts +750 -0
- package/dist/index.js +1096 -0
- package/dist/index.js.map +1 -0
- package/dist/react/index.cjs +1099 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +683 -0
- package/dist/react/index.d.ts +683 -0
- package/dist/react/index.js +1090 -0
- package/dist/react/index.js.map +1 -0
- package/package.json +82 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,750 @@
|
|
|
1
|
+
import * as _pokertools_types from '@pokertools/types';
|
|
2
|
+
import { LoginRequest, LoginResponse, TableListItem, CreateTableRequest, PublicState, BuyInRequest, GameActionRequest, AddChipsRequest, PublicPlayer } from '@pokertools/types';
|
|
3
|
+
export { Action, ActionType, AddChipsRequest, BuyInRequest, ClientMessage, CreateTableRequest, ErrorMessage, GameActionRequest, GameState, JoinTableMessage, LeaveTableMessage, LoginRequest, LoginResponse, NonceResponse, Player, PublicPlayer, PublicState, ServerMessage, SnapshotMessage, StateUpdateMessage, TableConfig, TableListItem } from '@pokertools/types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* SDK-specific types and configuration
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* SDK configuration options
|
|
10
|
+
*/
|
|
11
|
+
interface PokerSDKConfig {
|
|
12
|
+
/** Base URL of the PokerTools API (e.g., "https://api.poker.example.com") */
|
|
13
|
+
baseUrl: string;
|
|
14
|
+
/** WebSocket URL (defaults to baseUrl with ws:// protocol) */
|
|
15
|
+
wsUrl?: string;
|
|
16
|
+
/** JWT token for authentication */
|
|
17
|
+
token?: string;
|
|
18
|
+
/** Request timeout in milliseconds (default: 30000) */
|
|
19
|
+
timeout?: number;
|
|
20
|
+
/** Retry configuration */
|
|
21
|
+
retry?: {
|
|
22
|
+
/** Number of retries for failed requests (default: 3) */
|
|
23
|
+
count?: number;
|
|
24
|
+
/** Delay between retries in ms (default: 1000) */
|
|
25
|
+
delay?: number;
|
|
26
|
+
/** Exponential backoff multiplier (default: 2) */
|
|
27
|
+
backoff?: number;
|
|
28
|
+
};
|
|
29
|
+
/** Custom fetch implementation (for React Native or custom environments) */
|
|
30
|
+
fetch?: typeof fetch;
|
|
31
|
+
/** Custom WebSocket implementation (for React Native or Node.js) */
|
|
32
|
+
WebSocket?: typeof WebSocket;
|
|
33
|
+
/** Enable debug logging */
|
|
34
|
+
debug?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Authentication state
|
|
38
|
+
*/
|
|
39
|
+
interface AuthState {
|
|
40
|
+
token: string | null;
|
|
41
|
+
user: {
|
|
42
|
+
id: string;
|
|
43
|
+
username: string;
|
|
44
|
+
address: string;
|
|
45
|
+
} | null;
|
|
46
|
+
isAuthenticated: boolean;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* User balance information
|
|
50
|
+
*/
|
|
51
|
+
interface UserBalances {
|
|
52
|
+
main: number;
|
|
53
|
+
inPlay: number;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* User profile with balances
|
|
57
|
+
*/
|
|
58
|
+
interface UserProfile {
|
|
59
|
+
id: string;
|
|
60
|
+
username: string;
|
|
61
|
+
address: string;
|
|
62
|
+
role: "PLAYER" | "ADMIN" | "BOT";
|
|
63
|
+
createdAt: string;
|
|
64
|
+
balances: UserBalances;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Blockchain configuration
|
|
68
|
+
*/
|
|
69
|
+
interface BlockchainInfo {
|
|
70
|
+
id: string;
|
|
71
|
+
name: string;
|
|
72
|
+
chainId: number;
|
|
73
|
+
tokens: TokenInfo[];
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Token configuration
|
|
77
|
+
*/
|
|
78
|
+
interface TokenInfo {
|
|
79
|
+
id: string;
|
|
80
|
+
symbol: string;
|
|
81
|
+
name: string;
|
|
82
|
+
decimals: number;
|
|
83
|
+
minDeposit: string;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Deposit session info
|
|
87
|
+
*/
|
|
88
|
+
interface DepositSession {
|
|
89
|
+
address: string;
|
|
90
|
+
expiresAt: string;
|
|
91
|
+
message: string;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Deposit record
|
|
95
|
+
*/
|
|
96
|
+
interface DepositRecord {
|
|
97
|
+
id: string;
|
|
98
|
+
txHash: string | null;
|
|
99
|
+
chain: string;
|
|
100
|
+
token: string;
|
|
101
|
+
amountRaw: string;
|
|
102
|
+
amountCredit: number;
|
|
103
|
+
status: "PENDING" | "PROCESSING" | "CONFIRMED" | "FAILED";
|
|
104
|
+
createdAt: string;
|
|
105
|
+
confirmedAt: string | null;
|
|
106
|
+
explorerUrl: string;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Withdrawal request
|
|
110
|
+
*/
|
|
111
|
+
interface WithdrawalRequest {
|
|
112
|
+
amount: number;
|
|
113
|
+
blockchainId: string;
|
|
114
|
+
tokenId: string;
|
|
115
|
+
address: string;
|
|
116
|
+
message: string;
|
|
117
|
+
signature: `0x${string}`;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Withdrawal record
|
|
121
|
+
*/
|
|
122
|
+
interface WithdrawalRecord {
|
|
123
|
+
id: string;
|
|
124
|
+
txHash: string | null;
|
|
125
|
+
chain: string;
|
|
126
|
+
token: string;
|
|
127
|
+
address: string;
|
|
128
|
+
amountRaw: string;
|
|
129
|
+
amountUSD: number;
|
|
130
|
+
status: "PENDING" | "PROCESSING" | "CONFIRMED" | "FAILED" | "REJECTED" | "CANCELLED";
|
|
131
|
+
createdAt: string;
|
|
132
|
+
confirmedAt: string | null;
|
|
133
|
+
explorerUrl: string | null;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Hand history entry (simplified)
|
|
137
|
+
*/
|
|
138
|
+
interface HandHistoryEntry {
|
|
139
|
+
id: string;
|
|
140
|
+
amount: number;
|
|
141
|
+
type: "HAND_WIN" | "HAND_LOSS";
|
|
142
|
+
referenceId: string | null;
|
|
143
|
+
createdAt: string;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Player note
|
|
147
|
+
*/
|
|
148
|
+
interface PlayerNote {
|
|
149
|
+
id: string;
|
|
150
|
+
targetId: string;
|
|
151
|
+
content: string;
|
|
152
|
+
label: string | null;
|
|
153
|
+
createdAt: string;
|
|
154
|
+
updatedAt: string;
|
|
155
|
+
target?: {
|
|
156
|
+
id: string;
|
|
157
|
+
username: string;
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* SDK error class
|
|
162
|
+
*/
|
|
163
|
+
declare class PokerSDKError extends Error {
|
|
164
|
+
readonly code: string;
|
|
165
|
+
readonly statusCode?: number | undefined;
|
|
166
|
+
readonly details?: unknown | undefined;
|
|
167
|
+
constructor(message: string, code: string, statusCode?: number | undefined, details?: unknown | undefined);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* WebSocket connection state
|
|
171
|
+
*/
|
|
172
|
+
type ConnectionState = "disconnected" | "connecting" | "connected" | "reconnecting";
|
|
173
|
+
/**
|
|
174
|
+
* Event emitter types
|
|
175
|
+
*/
|
|
176
|
+
interface PokerSocketEvents {
|
|
177
|
+
connect: () => void;
|
|
178
|
+
disconnect: (reason?: string) => void;
|
|
179
|
+
reconnect: (attempt: number) => void;
|
|
180
|
+
error: (error: Error) => void;
|
|
181
|
+
stateUpdate: (tableId: string, state: _pokertools_types.PublicState) => void;
|
|
182
|
+
snapshot: (tableId: string, state: _pokertools_types.PublicState) => void;
|
|
183
|
+
action: (tableId: string, playerId: string, actionType: string, amount?: number) => void;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Type-safe event listener
|
|
187
|
+
*/
|
|
188
|
+
type EventListener<T extends keyof PokerSocketEvents> = PokerSocketEvents[T];
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* PokerClient - HTTP client for PokerTools REST API
|
|
192
|
+
*
|
|
193
|
+
* Provides type-safe methods for all API endpoints with automatic
|
|
194
|
+
* retry, authentication, and error handling.
|
|
195
|
+
*/
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* PokerClient - Main HTTP client for PokerTools API
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```typescript
|
|
202
|
+
* const client = new PokerClient({
|
|
203
|
+
* baseUrl: "https://api.poker.example.com",
|
|
204
|
+
* token: "jwt-token",
|
|
205
|
+
* });
|
|
206
|
+
*
|
|
207
|
+
* // Get tables
|
|
208
|
+
* const tables = await client.getTables();
|
|
209
|
+
*
|
|
210
|
+
* // Create a table
|
|
211
|
+
* const tableId = await client.createTable({
|
|
212
|
+
* name: "My Table",
|
|
213
|
+
* mode: "CASH",
|
|
214
|
+
* smallBlind: 5,
|
|
215
|
+
* bigBlind: 10,
|
|
216
|
+
* maxPlayers: 6,
|
|
217
|
+
* });
|
|
218
|
+
*
|
|
219
|
+
* // Buy in
|
|
220
|
+
* await client.buyIn(tableId, {
|
|
221
|
+
* amount: 500,
|
|
222
|
+
* seat: 3,
|
|
223
|
+
* idempotencyKey: crypto.randomUUID(),
|
|
224
|
+
* });
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
declare class PokerClient {
|
|
228
|
+
private readonly baseUrl;
|
|
229
|
+
private readonly timeout;
|
|
230
|
+
private readonly retry;
|
|
231
|
+
private readonly fetchFn;
|
|
232
|
+
private readonly debug;
|
|
233
|
+
private token;
|
|
234
|
+
constructor(config: PokerSDKConfig);
|
|
235
|
+
/**
|
|
236
|
+
* Set the authentication token
|
|
237
|
+
*/
|
|
238
|
+
setToken(token: string | null): void;
|
|
239
|
+
/**
|
|
240
|
+
* Get current token
|
|
241
|
+
*/
|
|
242
|
+
getToken(): string | null;
|
|
243
|
+
/**
|
|
244
|
+
* Check if client is authenticated
|
|
245
|
+
*/
|
|
246
|
+
isAuthenticated(): boolean;
|
|
247
|
+
/**
|
|
248
|
+
* Get a nonce for SIWE authentication
|
|
249
|
+
*/
|
|
250
|
+
getNonce(): Promise<string>;
|
|
251
|
+
/**
|
|
252
|
+
* Login with SIWE signature
|
|
253
|
+
*/
|
|
254
|
+
login(request: LoginRequest): Promise<LoginResponse>;
|
|
255
|
+
/**
|
|
256
|
+
* Logout and revoke session
|
|
257
|
+
*/
|
|
258
|
+
logout(): Promise<void>;
|
|
259
|
+
/**
|
|
260
|
+
* Get list of active tables
|
|
261
|
+
*/
|
|
262
|
+
getTables(): Promise<TableListItem[]>;
|
|
263
|
+
/**
|
|
264
|
+
* Create a new table
|
|
265
|
+
*/
|
|
266
|
+
createTable(config: CreateTableRequest): Promise<string>;
|
|
267
|
+
/**
|
|
268
|
+
* Get table state
|
|
269
|
+
* @param tableId - Table ID
|
|
270
|
+
* @param since - Optional version for conditional fetch (returns null if unchanged)
|
|
271
|
+
*/
|
|
272
|
+
getTableState(tableId: string, since?: number): Promise<PublicState | null>;
|
|
273
|
+
/**
|
|
274
|
+
* Buy in to a table
|
|
275
|
+
*/
|
|
276
|
+
buyIn(tableId: string, request: BuyInRequest): Promise<void>;
|
|
277
|
+
/**
|
|
278
|
+
* Execute a game action
|
|
279
|
+
*/
|
|
280
|
+
action(tableId: string, request: GameActionRequest): Promise<PublicState>;
|
|
281
|
+
/**
|
|
282
|
+
* Add chips to stack (rebuy/top-up)
|
|
283
|
+
*/
|
|
284
|
+
addChips(tableId: string, request: AddChipsRequest): Promise<void>;
|
|
285
|
+
/**
|
|
286
|
+
* Stand from table (leave and cash out)
|
|
287
|
+
*/
|
|
288
|
+
stand(tableId: string): Promise<void>;
|
|
289
|
+
/**
|
|
290
|
+
* Fold hand
|
|
291
|
+
*/
|
|
292
|
+
fold(tableId: string): Promise<PublicState>;
|
|
293
|
+
/**
|
|
294
|
+
* Check (pass action)
|
|
295
|
+
*/
|
|
296
|
+
check(tableId: string): Promise<PublicState>;
|
|
297
|
+
/**
|
|
298
|
+
* Call current bet
|
|
299
|
+
*/
|
|
300
|
+
call(tableId: string): Promise<PublicState>;
|
|
301
|
+
/**
|
|
302
|
+
* Place a bet
|
|
303
|
+
*/
|
|
304
|
+
bet(tableId: string, amount: number): Promise<PublicState>;
|
|
305
|
+
/**
|
|
306
|
+
* Raise the current bet
|
|
307
|
+
*/
|
|
308
|
+
raise(tableId: string, amount: number): Promise<PublicState>;
|
|
309
|
+
/**
|
|
310
|
+
* Deal new hand
|
|
311
|
+
*/
|
|
312
|
+
deal(tableId: string): Promise<PublicState>;
|
|
313
|
+
/**
|
|
314
|
+
* Show cards at showdown
|
|
315
|
+
*/
|
|
316
|
+
show(tableId: string, cardIndices?: number[]): Promise<PublicState>;
|
|
317
|
+
/**
|
|
318
|
+
* Muck cards at showdown
|
|
319
|
+
*/
|
|
320
|
+
muck(tableId: string): Promise<PublicState>;
|
|
321
|
+
/**
|
|
322
|
+
* Use time bank
|
|
323
|
+
*/
|
|
324
|
+
timeBank(tableId: string): Promise<PublicState>;
|
|
325
|
+
/**
|
|
326
|
+
* Get current user profile and balances
|
|
327
|
+
*/
|
|
328
|
+
getProfile(): Promise<UserProfile>;
|
|
329
|
+
/**
|
|
330
|
+
* Get hand history
|
|
331
|
+
*/
|
|
332
|
+
getHandHistory(): Promise<HandHistoryEntry[]>;
|
|
333
|
+
/**
|
|
334
|
+
* Request a withdrawal
|
|
335
|
+
*/
|
|
336
|
+
withdraw(request: WithdrawalRequest): Promise<{
|
|
337
|
+
id: string;
|
|
338
|
+
status: string;
|
|
339
|
+
amount: number;
|
|
340
|
+
destination: string;
|
|
341
|
+
blockchain: string;
|
|
342
|
+
token: string;
|
|
343
|
+
}>;
|
|
344
|
+
/**
|
|
345
|
+
* Get withdrawal history
|
|
346
|
+
*/
|
|
347
|
+
getWithdrawals(): Promise<WithdrawalRecord[]>;
|
|
348
|
+
/**
|
|
349
|
+
* Get supported blockchains and tokens
|
|
350
|
+
*/
|
|
351
|
+
getChains(): Promise<BlockchainInfo[]>;
|
|
352
|
+
/**
|
|
353
|
+
* Start deposit monitoring session
|
|
354
|
+
*/
|
|
355
|
+
startDeposit(): Promise<DepositSession>;
|
|
356
|
+
/**
|
|
357
|
+
* Get deposit address
|
|
358
|
+
*/
|
|
359
|
+
getDepositAddress(): Promise<string>;
|
|
360
|
+
/**
|
|
361
|
+
* Get deposit history
|
|
362
|
+
*/
|
|
363
|
+
getDeposits(): Promise<DepositRecord[]>;
|
|
364
|
+
/**
|
|
365
|
+
* Get all notes by current user
|
|
366
|
+
*/
|
|
367
|
+
getNotes(): Promise<PlayerNote[]>;
|
|
368
|
+
/**
|
|
369
|
+
* Get note for specific player
|
|
370
|
+
*/
|
|
371
|
+
getNote(targetId: string): Promise<PlayerNote | null>;
|
|
372
|
+
/**
|
|
373
|
+
* Save or update note
|
|
374
|
+
*/
|
|
375
|
+
saveNote(targetId: string, content: string, label?: string): Promise<PlayerNote>;
|
|
376
|
+
/**
|
|
377
|
+
* Delete note
|
|
378
|
+
*/
|
|
379
|
+
deleteNote(targetId: string): Promise<void>;
|
|
380
|
+
/**
|
|
381
|
+
* Health check
|
|
382
|
+
*/
|
|
383
|
+
health(): Promise<{
|
|
384
|
+
status: string;
|
|
385
|
+
timestamp: number;
|
|
386
|
+
}>;
|
|
387
|
+
/**
|
|
388
|
+
* Make HTTP request with retry logic
|
|
389
|
+
*/
|
|
390
|
+
private request;
|
|
391
|
+
/**
|
|
392
|
+
* Sleep helper
|
|
393
|
+
*/
|
|
394
|
+
private sleep;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* PokerSocket - WebSocket client for real-time game updates
|
|
399
|
+
*
|
|
400
|
+
* Provides automatic reconnection, heartbeat, and typed event handling
|
|
401
|
+
* for real-time poker game state synchronization.
|
|
402
|
+
*/
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* WebSocket configuration
|
|
406
|
+
*/
|
|
407
|
+
interface SocketConfig {
|
|
408
|
+
/** WebSocket URL */
|
|
409
|
+
url: string;
|
|
410
|
+
/** JWT token for authentication */
|
|
411
|
+
token: string;
|
|
412
|
+
/** Heartbeat interval in ms (default: 25000) */
|
|
413
|
+
heartbeatInterval?: number;
|
|
414
|
+
/** Reconnection attempts (default: 10) */
|
|
415
|
+
reconnectAttempts?: number;
|
|
416
|
+
/** Base reconnection delay in ms (default: 1000) */
|
|
417
|
+
reconnectDelay?: number;
|
|
418
|
+
/** Max reconnection delay in ms (default: 30000) */
|
|
419
|
+
maxReconnectDelay?: number;
|
|
420
|
+
/** Custom WebSocket implementation */
|
|
421
|
+
WebSocket?: typeof WebSocket;
|
|
422
|
+
/** Enable debug logging */
|
|
423
|
+
debug?: boolean;
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* PokerSocket - Real-time WebSocket client
|
|
427
|
+
*
|
|
428
|
+
* @example
|
|
429
|
+
* ```typescript
|
|
430
|
+
* const socket = new PokerSocket({
|
|
431
|
+
* url: "wss://api.poker.example.com/ws/play",
|
|
432
|
+
* token: "jwt-token",
|
|
433
|
+
* });
|
|
434
|
+
*
|
|
435
|
+
* // Listen for events
|
|
436
|
+
* socket.on("connect", () => console.log("Connected!"));
|
|
437
|
+
* socket.on("stateUpdate", (tableId, state) => {
|
|
438
|
+
* console.log("State updated:", state);
|
|
439
|
+
* });
|
|
440
|
+
*
|
|
441
|
+
* // Connect
|
|
442
|
+
* await socket.connect();
|
|
443
|
+
*
|
|
444
|
+
* // Join a table
|
|
445
|
+
* await socket.join("table-123");
|
|
446
|
+
*
|
|
447
|
+
* // Later: disconnect
|
|
448
|
+
* socket.disconnect();
|
|
449
|
+
* ```
|
|
450
|
+
*/
|
|
451
|
+
declare class PokerSocket {
|
|
452
|
+
private readonly url;
|
|
453
|
+
private readonly token;
|
|
454
|
+
private readonly heartbeatInterval;
|
|
455
|
+
private readonly reconnectAttempts;
|
|
456
|
+
private readonly reconnectDelay;
|
|
457
|
+
private readonly maxReconnectDelay;
|
|
458
|
+
private readonly WebSocketImpl;
|
|
459
|
+
private readonly debug;
|
|
460
|
+
private ws;
|
|
461
|
+
private connectionState;
|
|
462
|
+
private reconnectCount;
|
|
463
|
+
private heartbeatTimer;
|
|
464
|
+
private pendingRequests;
|
|
465
|
+
private joinedTables;
|
|
466
|
+
private listeners;
|
|
467
|
+
private shouldReconnect;
|
|
468
|
+
private stateCache;
|
|
469
|
+
constructor(config: SocketConfig);
|
|
470
|
+
/**
|
|
471
|
+
* Create a PokerSocket from SDK config
|
|
472
|
+
*/
|
|
473
|
+
static fromConfig(config: PokerSDKConfig): PokerSocket;
|
|
474
|
+
/**
|
|
475
|
+
* Connect to the WebSocket server
|
|
476
|
+
*/
|
|
477
|
+
connect(): Promise<void>;
|
|
478
|
+
/**
|
|
479
|
+
* Disconnect from the WebSocket server
|
|
480
|
+
*/
|
|
481
|
+
disconnect(): void;
|
|
482
|
+
/**
|
|
483
|
+
* Get current connection state
|
|
484
|
+
*/
|
|
485
|
+
getState(): ConnectionState;
|
|
486
|
+
/**
|
|
487
|
+
* Check if connected
|
|
488
|
+
*/
|
|
489
|
+
isConnected(): boolean;
|
|
490
|
+
/**
|
|
491
|
+
* Join a table to receive real-time updates
|
|
492
|
+
*/
|
|
493
|
+
join(tableId: string): Promise<PublicState>;
|
|
494
|
+
/**
|
|
495
|
+
* Leave a table
|
|
496
|
+
*/
|
|
497
|
+
leave(tableId: string): void;
|
|
498
|
+
/**
|
|
499
|
+
* Get currently joined tables
|
|
500
|
+
*/
|
|
501
|
+
getJoinedTables(): string[];
|
|
502
|
+
/**
|
|
503
|
+
* Get cached state for a table
|
|
504
|
+
*/
|
|
505
|
+
getCachedState(tableId: string): PublicState | undefined;
|
|
506
|
+
/**
|
|
507
|
+
* Subscribe to an event
|
|
508
|
+
*/
|
|
509
|
+
on<E extends keyof PokerSocketEvents>(event: E, listener: PokerSocketEvents[E]): () => void;
|
|
510
|
+
/**
|
|
511
|
+
* Unsubscribe from an event
|
|
512
|
+
*/
|
|
513
|
+
off<E extends keyof PokerSocketEvents>(event: E, listener: PokerSocketEvents[E]): void;
|
|
514
|
+
/**
|
|
515
|
+
* Subscribe to an event (once)
|
|
516
|
+
*/
|
|
517
|
+
once<E extends keyof PokerSocketEvents>(event: E, listener: PokerSocketEvents[E]): () => void;
|
|
518
|
+
/**
|
|
519
|
+
* Send application-level ping (not WebSocket ping)
|
|
520
|
+
*/
|
|
521
|
+
ping(): Promise<number>;
|
|
522
|
+
/**
|
|
523
|
+
* Send a message to the server
|
|
524
|
+
*/
|
|
525
|
+
private send;
|
|
526
|
+
/**
|
|
527
|
+
* Handle incoming message
|
|
528
|
+
*/
|
|
529
|
+
private handleMessage;
|
|
530
|
+
/**
|
|
531
|
+
* Handle disconnect
|
|
532
|
+
*/
|
|
533
|
+
private handleDisconnect;
|
|
534
|
+
/**
|
|
535
|
+
* Attempt to reconnect
|
|
536
|
+
*/
|
|
537
|
+
private reconnect;
|
|
538
|
+
/**
|
|
539
|
+
* Rejoin previously joined tables
|
|
540
|
+
*/
|
|
541
|
+
private rejoinTables;
|
|
542
|
+
/**
|
|
543
|
+
* Start heartbeat timer
|
|
544
|
+
*/
|
|
545
|
+
private startHeartbeat;
|
|
546
|
+
/**
|
|
547
|
+
* Stop heartbeat timer
|
|
548
|
+
*/
|
|
549
|
+
private stopHeartbeat;
|
|
550
|
+
/**
|
|
551
|
+
* Clear all pending requests
|
|
552
|
+
*/
|
|
553
|
+
private clearPendingRequests;
|
|
554
|
+
/**
|
|
555
|
+
* Emit event to listeners
|
|
556
|
+
*/
|
|
557
|
+
private emit;
|
|
558
|
+
/**
|
|
559
|
+
* Generate unique request ID
|
|
560
|
+
*/
|
|
561
|
+
private generateRequestId;
|
|
562
|
+
/**
|
|
563
|
+
* Sleep helper
|
|
564
|
+
*/
|
|
565
|
+
private sleep;
|
|
566
|
+
/**
|
|
567
|
+
* Debug logger
|
|
568
|
+
*/
|
|
569
|
+
private log;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Authentication helpers for SIWE (Sign-In with Ethereum)
|
|
574
|
+
*
|
|
575
|
+
* These utilities help construct SIWE messages for wallet signing.
|
|
576
|
+
*/
|
|
577
|
+
/**
|
|
578
|
+
* SIWE message parameters
|
|
579
|
+
*/
|
|
580
|
+
interface SiweMessageParams {
|
|
581
|
+
/** Domain making the request (e.g., "poker.example.com") */
|
|
582
|
+
domain: string;
|
|
583
|
+
/** Ethereum address (checksummed) */
|
|
584
|
+
address: string;
|
|
585
|
+
/** Human-readable statement (optional) */
|
|
586
|
+
statement?: string;
|
|
587
|
+
/** URI of the signing resource */
|
|
588
|
+
uri: string;
|
|
589
|
+
/** Current version of the message (always "1") */
|
|
590
|
+
version?: "1";
|
|
591
|
+
/** Chain ID */
|
|
592
|
+
chainId?: number;
|
|
593
|
+
/** Nonce from server */
|
|
594
|
+
nonce: string;
|
|
595
|
+
/** Issued at timestamp (ISO 8601) */
|
|
596
|
+
issuedAt?: string;
|
|
597
|
+
/** Expiration time (ISO 8601) */
|
|
598
|
+
expirationTime?: string;
|
|
599
|
+
/** Not before time (ISO 8601) */
|
|
600
|
+
notBefore?: string;
|
|
601
|
+
/** Request ID */
|
|
602
|
+
requestId?: string;
|
|
603
|
+
/** Resources (URIs) */
|
|
604
|
+
resources?: string[];
|
|
605
|
+
}
|
|
606
|
+
/**
|
|
607
|
+
* Create a SIWE message string for signing
|
|
608
|
+
*
|
|
609
|
+
* @example
|
|
610
|
+
* ```typescript
|
|
611
|
+
* import { createSiweMessage } from "@pokertools/sdk";
|
|
612
|
+
*
|
|
613
|
+
* // Get nonce from server
|
|
614
|
+
* const nonce = await client.getNonce();
|
|
615
|
+
*
|
|
616
|
+
* // Create message
|
|
617
|
+
* const message = createSiweMessage({
|
|
618
|
+
* domain: "poker.example.com",
|
|
619
|
+
* address: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
|
|
620
|
+
* uri: "https://poker.example.com",
|
|
621
|
+
* nonce,
|
|
622
|
+
* statement: "Sign in to PokerTools",
|
|
623
|
+
* });
|
|
624
|
+
*
|
|
625
|
+
* // Sign with wallet (e.g., wagmi, ethers, viem)
|
|
626
|
+
* const signature = await signMessage({ message });
|
|
627
|
+
*
|
|
628
|
+
* // Login
|
|
629
|
+
* const { token, user } = await client.login({ message, signature });
|
|
630
|
+
* ```
|
|
631
|
+
*/
|
|
632
|
+
declare function createSiweMessage(params: SiweMessageParams): string;
|
|
633
|
+
/**
|
|
634
|
+
* Parse a SIWE message string back into params
|
|
635
|
+
*/
|
|
636
|
+
declare function parseSiweMessage(message: string): Partial<SiweMessageParams>;
|
|
637
|
+
/**
|
|
638
|
+
* Check if a SIWE message is expired
|
|
639
|
+
*/
|
|
640
|
+
declare function isSiweExpired(message: string): boolean;
|
|
641
|
+
/**
|
|
642
|
+
* Create a withdrawal message for signing
|
|
643
|
+
*
|
|
644
|
+
* @example
|
|
645
|
+
* ```typescript
|
|
646
|
+
* const message = createWithdrawalMessage(100, "0x...");
|
|
647
|
+
* const signature = await signMessage({ message });
|
|
648
|
+
* await client.withdraw({ amount: 100, address: "0x...", message, signature, ... });
|
|
649
|
+
* ```
|
|
650
|
+
*/
|
|
651
|
+
declare function createWithdrawalMessage(amount: number, destinationAddress: string): string;
|
|
652
|
+
/**
|
|
653
|
+
* Generate a random idempotency key
|
|
654
|
+
* Uses crypto.randomUUID if available, otherwise falls back to timestamp + random
|
|
655
|
+
*/
|
|
656
|
+
declare function generateIdempotencyKey(): string;
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* Utility functions for the PokerTools SDK
|
|
660
|
+
*/
|
|
661
|
+
|
|
662
|
+
/**
|
|
663
|
+
* Format chip amount to display string
|
|
664
|
+
* @param chips - Amount in cents (1 chip = 1 cent)
|
|
665
|
+
* @param currency - Currency symbol (default: "$")
|
|
666
|
+
*/
|
|
667
|
+
declare function formatChips(chips: number, currency?: string): string;
|
|
668
|
+
/**
|
|
669
|
+
* Parse display amount to chips (cents)
|
|
670
|
+
* @param amount - Display amount string (e.g., "$10.50", "10.50", "1050")
|
|
671
|
+
*/
|
|
672
|
+
declare function parseChips(amount: string): number;
|
|
673
|
+
/**
|
|
674
|
+
* Get the player whose turn it is
|
|
675
|
+
*/
|
|
676
|
+
declare function getActivePlayer(state: PublicState): PublicPlayer | null;
|
|
677
|
+
/**
|
|
678
|
+
* Get player by ID
|
|
679
|
+
*/
|
|
680
|
+
declare function getPlayerById(state: PublicState, playerId: string): PublicPlayer | null;
|
|
681
|
+
/**
|
|
682
|
+
* Get player seat index by ID
|
|
683
|
+
*/
|
|
684
|
+
declare function getPlayerSeat(state: PublicState, playerId: string): number | null;
|
|
685
|
+
/**
|
|
686
|
+
* Check if it's a specific player's turn
|
|
687
|
+
*/
|
|
688
|
+
declare function isPlayerTurn(state: PublicState, playerId: string): boolean;
|
|
689
|
+
/**
|
|
690
|
+
* Get the amount needed to call
|
|
691
|
+
*/
|
|
692
|
+
declare function getCallAmount(state: PublicState, playerId: string): number;
|
|
693
|
+
/**
|
|
694
|
+
* Get minimum raise amount
|
|
695
|
+
*/
|
|
696
|
+
declare function getMinRaise(state: PublicState): number;
|
|
697
|
+
/**
|
|
698
|
+
* Check if player can check
|
|
699
|
+
*/
|
|
700
|
+
declare function canCheck(state: PublicState, playerId: string): boolean;
|
|
701
|
+
/**
|
|
702
|
+
* Check if player can bet (no prior bets this round)
|
|
703
|
+
*/
|
|
704
|
+
declare function canBet(state: PublicState, playerId: string): boolean;
|
|
705
|
+
/**
|
|
706
|
+
* Get total pot size (main pot + side pots)
|
|
707
|
+
*/
|
|
708
|
+
declare function getTotalPot(state: PublicState): number;
|
|
709
|
+
/**
|
|
710
|
+
* Get number of active players (not folded, has chips)
|
|
711
|
+
*/
|
|
712
|
+
declare function getActivePlayers(state: PublicState): PublicPlayer[];
|
|
713
|
+
/**
|
|
714
|
+
* Get number of players in hand (not folded)
|
|
715
|
+
*/
|
|
716
|
+
declare function getPlayersInHand(state: PublicState): PublicPlayer[];
|
|
717
|
+
/**
|
|
718
|
+
* Card suit to emoji
|
|
719
|
+
*/
|
|
720
|
+
declare function suitToEmoji(suit: string): string;
|
|
721
|
+
/**
|
|
722
|
+
* Format card for display (e.g., "As" -> "A♠")
|
|
723
|
+
*/
|
|
724
|
+
declare function formatCard(card: string): string;
|
|
725
|
+
/**
|
|
726
|
+
* Format card array for display
|
|
727
|
+
*/
|
|
728
|
+
declare function formatCards(cards: Array<string | null> | null): string;
|
|
729
|
+
/**
|
|
730
|
+
* Get street display name
|
|
731
|
+
*/
|
|
732
|
+
declare function getStreetName(street: string): string;
|
|
733
|
+
/**
|
|
734
|
+
* Check if game is in showdown phase
|
|
735
|
+
*/
|
|
736
|
+
declare function isShowdown(state: PublicState): boolean;
|
|
737
|
+
/**
|
|
738
|
+
* Check if hand is complete (has winners)
|
|
739
|
+
*/
|
|
740
|
+
declare function isHandComplete(state: PublicState): boolean;
|
|
741
|
+
/**
|
|
742
|
+
* Calculate pot odds as a ratio
|
|
743
|
+
*/
|
|
744
|
+
declare function getPotOdds(state: PublicState, playerId: string): number;
|
|
745
|
+
/**
|
|
746
|
+
* Abbreviate large numbers (e.g., 1000 -> "1K")
|
|
747
|
+
*/
|
|
748
|
+
declare function abbreviateNumber(num: number): string;
|
|
749
|
+
|
|
750
|
+
export { type AuthState, type BlockchainInfo, type ConnectionState, type DepositRecord, type DepositSession, type EventListener, type HandHistoryEntry, type PlayerNote, PokerClient, type PokerSDKConfig, PokerSDKError, PokerSocket, type PokerSocketEvents, type SiweMessageParams, type TokenInfo, type UserBalances, type UserProfile, type WithdrawalRecord, type WithdrawalRequest, abbreviateNumber, canBet, canCheck, createSiweMessage, createWithdrawalMessage, formatCard, formatCards, formatChips, generateIdempotencyKey, getActivePlayer, getActivePlayers, getCallAmount, getMinRaise, getPlayerById, getPlayerSeat, getPlayersInHand, getPotOdds, getStreetName, getTotalPot, isHandComplete, isPlayerTurn, isShowdown, isSiweExpired, parseChips, parseSiweMessage, suitToEmoji };
|