infinite-games-sdk 0.0.6 → 0.0.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.
- package/README.md +126 -113
- package/dist/index.d.ts +208 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +597 -29
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/errors.d.ts +0 -4
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js +0 -11
- package/dist/errors.js.map +0 -1
- package/dist/history/HistoryClient.d.ts +0 -20
- package/dist/history/HistoryClient.d.ts.map +0 -1
- package/dist/history/HistoryClient.js +0 -96
- package/dist/history/HistoryClient.js.map +0 -1
- package/dist/history/index.d.ts +0 -4
- package/dist/history/index.d.ts.map +0 -1
- package/dist/history/index.js +0 -8
- package/dist/history/index.js.map +0 -1
- package/dist/history/types.d.ts +0 -7
- package/dist/history/types.d.ts.map +0 -1
- package/dist/history/types.js +0 -3
- package/dist/history/types.js.map +0 -1
- package/dist/history/useHistoryClient.d.ts +0 -21
- package/dist/history/useHistoryClient.d.ts.map +0 -1
- package/dist/history/useHistoryClient.js +0 -77
- package/dist/history/useHistoryClient.js.map +0 -1
- package/dist/launcher/index.d.ts +0 -4
- package/dist/launcher/index.d.ts.map +0 -1
- package/dist/launcher/index.js +0 -9
- package/dist/launcher/index.js.map +0 -1
- package/dist/launcher/types.d.ts +0 -59
- package/dist/launcher/types.d.ts.map +0 -1
- package/dist/launcher/types.js +0 -20
- package/dist/launcher/types.js.map +0 -1
- package/dist/launcher/useGameLauncher.d.ts +0 -3
- package/dist/launcher/useGameLauncher.d.ts.map +0 -1
- package/dist/launcher/useGameLauncher.js +0 -144
- package/dist/launcher/useGameLauncher.js.map +0 -1
- package/dist/session/SessionClient.d.ts +0 -22
- package/dist/session/SessionClient.d.ts.map +0 -1
- package/dist/session/SessionClient.js +0 -87
- package/dist/session/SessionClient.js.map +0 -1
- package/dist/session/index.d.ts +0 -7
- package/dist/session/index.d.ts.map +0 -1
- package/dist/session/index.js +0 -13
- package/dist/session/index.js.map +0 -1
- package/dist/session/initializeGame.d.ts +0 -48
- package/dist/session/initializeGame.d.ts.map +0 -1
- package/dist/session/initializeGame.js +0 -59
- package/dist/session/initializeGame.js.map +0 -1
- package/dist/session/tokens.d.ts +0 -21
- package/dist/session/tokens.d.ts.map +0 -1
- package/dist/session/tokens.js +0 -71
- package/dist/session/tokens.js.map +0 -1
- package/dist/session/types.d.ts +0 -15
- package/dist/session/types.d.ts.map +0 -1
- package/dist/session/types.js +0 -3
- package/dist/session/types.js.map +0 -1
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js +0 -8
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/scale.d.ts +0 -4
- package/dist/utils/scale.d.ts.map +0 -1
- package/dist/utils/scale.js +0 -13
- package/dist/utils/scale.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,74 +1,138 @@
|
|
|
1
1
|
# Infinite Games SDK
|
|
2
2
|
|
|
3
|
+
TypeScript SDK for Infinite Games session management and real-time game sync.
|
|
4
|
+
|
|
3
5
|
## Installation
|
|
4
6
|
|
|
5
7
|
```bash
|
|
6
8
|
pnpm add infinite-games-sdk
|
|
7
9
|
```
|
|
8
10
|
|
|
9
|
-
##
|
|
11
|
+
## Game Frontend Integration
|
|
12
|
+
|
|
13
|
+
### Initialize Game Session
|
|
10
14
|
|
|
11
|
-
|
|
15
|
+
The `initializeGame` function handles the complete session flow in one call:
|
|
12
16
|
|
|
13
17
|
```typescript
|
|
14
|
-
import {
|
|
18
|
+
import { initializeGame, AuthError } from 'infinite-games-sdk';
|
|
19
|
+
import { createTable, getBalanceFromBackend } from './api';
|
|
15
20
|
|
|
16
|
-
|
|
21
|
+
// Get token from URL
|
|
22
|
+
const params = new URLSearchParams(window.location.search);
|
|
23
|
+
const token = params.get('token');
|
|
24
|
+
const coinType = params.get('coinType');
|
|
17
25
|
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
try {
|
|
27
|
+
const result = await initializeGame({
|
|
28
|
+
token,
|
|
29
|
+
coinType,
|
|
30
|
+
sessionToken: sessionStorage.getItem('session_token'),
|
|
31
|
+
createTable: (session, coin) => createTable(session, coin),
|
|
32
|
+
getTableInfo: (tableId, session) => getBalanceFromBackend(session, tableId),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Save session token for future use
|
|
36
|
+
if (result.sessionToken) {
|
|
37
|
+
sessionStorage.setItem('session_token', result.sessionToken);
|
|
38
|
+
}
|
|
25
39
|
|
|
26
|
-
//
|
|
27
|
-
|
|
40
|
+
// Start the game
|
|
41
|
+
startGame(result.tableId, result.coinType, result.sessionToken);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
if (error instanceof AuthError) {
|
|
44
|
+
showError('Launch link expired. Please launch again from the main website.');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
28
47
|
```
|
|
29
48
|
|
|
30
|
-
|
|
49
|
+
The function automatically handles:
|
|
50
|
+
- **OTT (one-time token)**: Exchanges for session JWT, creates table, returns result
|
|
51
|
+
- **table_id**: Fetches table info (spectator/returning player), returns result
|
|
52
|
+
- **Expired JWT**: Throws `AuthError` with user-friendly message
|
|
53
|
+
|
|
54
|
+
### Real-time Game Sync (React)
|
|
31
55
|
|
|
32
56
|
```typescript
|
|
33
|
-
import {
|
|
57
|
+
import { useHistoryClient } from 'infinite-games-sdk';
|
|
34
58
|
|
|
35
|
-
|
|
36
|
-
const
|
|
59
|
+
function Game({ tableId, coinType, isSpectator }) {
|
|
60
|
+
const [spectatorBets, setSpectatorBets] = useState({ playerBet: 0, bankerBet: 0 });
|
|
61
|
+
|
|
62
|
+
const { isConnected, sendBetUpdate } = useHistoryClient(tableId, coinType, {
|
|
63
|
+
onMessage: (message) => {
|
|
64
|
+
// Game events from history service
|
|
65
|
+
if (message.playerHand) {
|
|
66
|
+
playGameAnimation(message);
|
|
67
|
+
}
|
|
68
|
+
// Bet updates for spectators
|
|
69
|
+
if (message.type === 'bet_update' && isSpectator) {
|
|
70
|
+
setSpectatorBets(message);
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
});
|
|
37
74
|
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
} else if (result.tokenType === 'ott') {
|
|
45
|
-
// New session - create table with session token
|
|
46
|
-
const table = await createTable(result.sessionToken, coinType);
|
|
47
|
-
}
|
|
48
|
-
} catch (error) {
|
|
49
|
-
if (error instanceof AuthError) {
|
|
50
|
-
showExpiredLinkError();
|
|
51
|
-
}
|
|
75
|
+
// Owner broadcasts bets to spectators
|
|
76
|
+
const handleBetChange = (bets) => {
|
|
77
|
+
if (!isSpectator) {
|
|
78
|
+
sendBetUpdate(bets);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
52
81
|
}
|
|
53
82
|
```
|
|
54
83
|
|
|
55
|
-
###
|
|
84
|
+
### Real-time Game Sync (Vanilla JS)
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
import { HistoryClient } from 'infinite-games-sdk';
|
|
88
|
+
|
|
89
|
+
const client = new HistoryClient();
|
|
90
|
+
|
|
91
|
+
client.onMessage = (event) => {
|
|
92
|
+
const msg = JSON.parse(event.data);
|
|
93
|
+
if (msg.channel && msg.data) {
|
|
94
|
+
// Game event from history service
|
|
95
|
+
handleGameEvent(msg.data);
|
|
96
|
+
} else if (msg.type === 'bet_update') {
|
|
97
|
+
// Bet update relay
|
|
98
|
+
handleBetUpdate(msg);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
client.connect(tableId, 'sui/sui');
|
|
103
|
+
client.send({ type: 'bet_update', playerBet: 100, bankerBet: 0 });
|
|
104
|
+
client.disconnect();
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Parent Site Integration (doubleup-io)
|
|
108
|
+
|
|
109
|
+
### Launch a Game
|
|
56
110
|
|
|
57
111
|
```typescript
|
|
58
|
-
|
|
59
|
-
|
|
112
|
+
import { SessionClient } from 'infinite-games-sdk';
|
|
113
|
+
|
|
114
|
+
const session = new SessionClient();
|
|
115
|
+
|
|
116
|
+
const { launchUrl, origin, token } = await session.getLaunchUrl({
|
|
117
|
+
address: wallet.address,
|
|
118
|
+
signature: await wallet.signMessage('Sign in to Infinite Games'),
|
|
119
|
+
chain: 'sui',
|
|
120
|
+
gameType: 'baccarat',
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// Load game in iframe
|
|
124
|
+
iframe.src = launchUrl;
|
|
60
125
|
```
|
|
61
126
|
|
|
62
|
-
|
|
127
|
+
### useGameLauncher Hook
|
|
63
128
|
|
|
64
|
-
React hook
|
|
129
|
+
React hook for complete game launch flow with URL management:
|
|
65
130
|
|
|
66
131
|
```typescript
|
|
67
132
|
import { useGameLauncher } from 'infinite-games-sdk';
|
|
68
133
|
import { useSearchParams } from 'react-router-dom';
|
|
69
|
-
import { useAuth } from './hooks/useAuth';
|
|
70
134
|
|
|
71
|
-
function
|
|
135
|
+
function BaccaratPage() {
|
|
72
136
|
const { wallet, launch } = useAuth();
|
|
73
137
|
const [searchParams, setSearchParams] = useSearchParams();
|
|
74
138
|
|
|
@@ -81,11 +145,8 @@ function Blackjack() {
|
|
|
81
145
|
retry,
|
|
82
146
|
} = useGameLauncher(
|
|
83
147
|
{
|
|
84
|
-
gameType: '
|
|
85
|
-
defaultOrigin: 'https://
|
|
86
|
-
// Optional: for local development
|
|
87
|
-
localOrigin: 'http://localhost:3001',
|
|
88
|
-
useLocal: false,
|
|
148
|
+
gameType: 'baccarat',
|
|
149
|
+
defaultOrigin: 'https://baccaratdev.infiniteedgers.com',
|
|
89
150
|
},
|
|
90
151
|
{
|
|
91
152
|
wallet,
|
|
@@ -95,89 +156,35 @@ function Blackjack() {
|
|
|
95
156
|
}
|
|
96
157
|
);
|
|
97
158
|
|
|
98
|
-
if (
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
/>
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (showConnectPrompt) return <div>Connect your wallet to play</div>;
|
|
108
|
-
if (error) return <div>Error: {error} <button onClick={retry}>Retry</button></div>;
|
|
109
|
-
if (isLoading) return <div>Launching...</div>;
|
|
159
|
+
if (showConnectPrompt) return <ConnectWallet />;
|
|
160
|
+
if (error) return <Error message={error} onRetry={retry} />;
|
|
161
|
+
if (isLoading) return <Loading />;
|
|
162
|
+
|
|
163
|
+
return <iframe src={iframeSrc} style={{ height: iframeHeight ?? '100vh' }} />;
|
|
110
164
|
}
|
|
111
165
|
```
|
|
112
166
|
|
|
113
|
-
|
|
114
|
-
- Handles URL tokens for shareable links and spectator mode
|
|
115
|
-
- Launches new sessions when wallet is connected
|
|
116
|
-
- Listens for iframe messages (table creation, height updates)
|
|
117
|
-
- Updates URL params when tables are created
|
|
118
|
-
- Manages loading, error, and retry states
|
|
167
|
+
## Utilities
|
|
119
168
|
|
|
120
|
-
|
|
169
|
+
### Scale Conversion
|
|
121
170
|
|
|
122
|
-
|
|
171
|
+
Backend uses 10^9 scale for precision:
|
|
123
172
|
|
|
124
173
|
```typescript
|
|
125
|
-
import {
|
|
126
|
-
|
|
127
|
-
function BaccaratGame({ tableId, coinType, sessionToken }) {
|
|
128
|
-
const isSpectator = !sessionToken;
|
|
129
|
-
|
|
130
|
-
const { isConnected, sendBetUpdate, sendGameReset } = useHistoryClient(
|
|
131
|
-
tableId,
|
|
132
|
-
coinType,
|
|
133
|
-
{
|
|
134
|
-
onGameEvent: (event) => {
|
|
135
|
-
// Game result broadcast - both owner and spectators receive this
|
|
136
|
-
playAnimation(event);
|
|
137
|
-
},
|
|
138
|
-
onBetUpdate: (bets) => {
|
|
139
|
-
// Spectators see owner's bet placement
|
|
140
|
-
if (isSpectator) setSpectatorBets(bets);
|
|
141
|
-
},
|
|
142
|
-
onGameReset: () => {
|
|
143
|
-
// Owner clicked Play Again
|
|
144
|
-
if (isSpectator) resetGame();
|
|
145
|
-
},
|
|
146
|
-
}
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
// Owner broadcasts bets to spectators
|
|
150
|
-
const handleBetChange = (bets) => {
|
|
151
|
-
if (!isSpectator) sendBetUpdate(bets);
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
### Vanilla JavaScript
|
|
157
|
-
|
|
158
|
-
```typescript
|
|
159
|
-
import { HistoryClient } from 'infinite-games-sdk';
|
|
160
|
-
|
|
161
|
-
const history = new HistoryClient();
|
|
162
|
-
|
|
163
|
-
history.onMessage = (event) => {
|
|
164
|
-
const msg = JSON.parse(event.data);
|
|
165
|
-
if (msg.channel && msg.data) handleGameEvent(msg.data);
|
|
166
|
-
if (msg.type === 'bet_update') handleBetUpdate(msg);
|
|
167
|
-
};
|
|
174
|
+
import { toBackendScale, fromBackendScale } from 'infinite-games-sdk';
|
|
168
175
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
history.disconnect();
|
|
176
|
+
toBackendScale(1.5); // 1500000000
|
|
177
|
+
fromBackendScale(1500000000); // 1.5
|
|
172
178
|
```
|
|
173
179
|
|
|
174
|
-
|
|
180
|
+
### Token Utilities
|
|
175
181
|
|
|
176
182
|
```typescript
|
|
177
|
-
import {
|
|
183
|
+
import { isTableId, isOneTimeToken, getTokenType } from 'infinite-games-sdk';
|
|
178
184
|
|
|
179
|
-
|
|
180
|
-
|
|
185
|
+
isTableId('550e8400-e29b-41d4-a716-446655440000'); // true
|
|
186
|
+
isOneTimeToken(jwtWithAudLogin); // true
|
|
187
|
+
getTokenType(token); // 'ott' | 'table_id' | 'expired_jwt' | 'unknown'
|
|
181
188
|
```
|
|
182
189
|
|
|
183
190
|
## Configuration
|
|
@@ -190,4 +197,10 @@ new HistoryClient();
|
|
|
190
197
|
// Production
|
|
191
198
|
new SessionClient({ baseUrl: 'https://session.infiniteedgers.com' });
|
|
192
199
|
new HistoryClient({ baseUrl: 'history.infiniteedgers.com' });
|
|
200
|
+
|
|
201
|
+
// initializeGame with custom session URL
|
|
202
|
+
initializeGame({
|
|
203
|
+
// ...options
|
|
204
|
+
sessionConfig: { baseUrl: 'https://session.infiniteedgers.com' },
|
|
205
|
+
});
|
|
193
206
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,209 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
export declare class AuthError extends Error {
|
|
2
|
+
name: string;
|
|
3
|
+
}
|
|
4
|
+
export declare const SCALE_FACTOR = 1000000000;
|
|
5
|
+
export declare function toBackendScale(amount: number): number;
|
|
6
|
+
export declare function fromBackendScale(amount: number): number;
|
|
7
|
+
export interface SessionConfig {
|
|
8
|
+
baseUrl?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface LaunchParams {
|
|
11
|
+
address: string;
|
|
12
|
+
signature: string;
|
|
13
|
+
chain: string;
|
|
14
|
+
gameType: string;
|
|
15
|
+
}
|
|
16
|
+
export interface LaunchResult {
|
|
17
|
+
launchUrl: string;
|
|
18
|
+
origin: string;
|
|
19
|
+
token: string;
|
|
20
|
+
}
|
|
21
|
+
export interface TableInfo {
|
|
22
|
+
tableId: string;
|
|
23
|
+
coinType: string;
|
|
24
|
+
}
|
|
25
|
+
export interface InitializeGameOptions {
|
|
26
|
+
/** Token from URL - can be OTT or table_id */
|
|
27
|
+
token: string;
|
|
28
|
+
/** Coin type from URL (required for OTT, ignored for table_id) */
|
|
29
|
+
coinType: string | null;
|
|
30
|
+
/** Existing session token from storage (optional) */
|
|
31
|
+
sessionToken?: string | null;
|
|
32
|
+
/** Game-specific function to create a new table */
|
|
33
|
+
createTable: (sessionToken: string, coinType: string) => Promise<TableInfo>;
|
|
34
|
+
/** Game-specific function to get table info (e.g., via getBalance) */
|
|
35
|
+
getTableInfo: (tableId: string, sessionToken: string | null) => Promise<{
|
|
36
|
+
coinType: string;
|
|
37
|
+
}>;
|
|
38
|
+
/** Session client config (optional) */
|
|
39
|
+
sessionConfig?: SessionConfig;
|
|
40
|
+
}
|
|
41
|
+
export interface InitializeGameResult {
|
|
42
|
+
tableId: string;
|
|
43
|
+
coinType: string;
|
|
44
|
+
sessionToken: string | null;
|
|
45
|
+
}
|
|
46
|
+
export interface HistoryConfig {
|
|
47
|
+
baseUrl?: string;
|
|
48
|
+
keepAliveIntervalMs?: number;
|
|
49
|
+
reconnectDelayMs?: number;
|
|
50
|
+
autoReconnect?: boolean;
|
|
51
|
+
}
|
|
52
|
+
export interface WalletState {
|
|
53
|
+
address: string | null;
|
|
54
|
+
connected: boolean;
|
|
55
|
+
chain: string | null;
|
|
56
|
+
}
|
|
57
|
+
export interface LaunchMutation {
|
|
58
|
+
mutateAsync: (params: {
|
|
59
|
+
gameType: string;
|
|
60
|
+
}) => Promise<{
|
|
61
|
+
origin: string;
|
|
62
|
+
token: string;
|
|
63
|
+
chain: string;
|
|
64
|
+
}>;
|
|
65
|
+
reset: () => void;
|
|
66
|
+
}
|
|
67
|
+
export interface GameLauncherConfig {
|
|
68
|
+
/** Game type identifier (e.g., 'baccarat', 'blackjack', 'range') */
|
|
69
|
+
gameType: string;
|
|
70
|
+
/** Default game origin URL (used when no token in URL) */
|
|
71
|
+
defaultOrigin: string;
|
|
72
|
+
/** Optional local development origin */
|
|
73
|
+
localOrigin?: string;
|
|
74
|
+
/** Use local origin instead of production */
|
|
75
|
+
useLocal?: boolean;
|
|
76
|
+
/** Message type for table creation events (e.g., 'baccarat-table-created') */
|
|
77
|
+
tableCreatedMessageType?: string;
|
|
78
|
+
}
|
|
79
|
+
export interface UseGameLauncherOptions {
|
|
80
|
+
/** Wallet state from useWallet() */
|
|
81
|
+
wallet: WalletState;
|
|
82
|
+
/** Launch mutation from useAuth() */
|
|
83
|
+
launch: LaunchMutation;
|
|
84
|
+
/** Function to get current URL search params */
|
|
85
|
+
getSearchParams: () => URLSearchParams;
|
|
86
|
+
/** Function to set URL search params */
|
|
87
|
+
setSearchParams: (params: Record<string, string>, options?: {
|
|
88
|
+
replace?: boolean;
|
|
89
|
+
}) => void;
|
|
90
|
+
}
|
|
91
|
+
export interface GameLauncherState {
|
|
92
|
+
/** Ready-to-use iframe src URL, or null if not ready */
|
|
93
|
+
iframeSrc: string | null;
|
|
94
|
+
/** Current iframe height from postMessage, or null */
|
|
95
|
+
iframeHeight: number | null;
|
|
96
|
+
/** Current iframe origin for security checks */
|
|
97
|
+
iframeOrigin: string | null;
|
|
98
|
+
/** Error message if launch failed */
|
|
99
|
+
error: string | null;
|
|
100
|
+
/** Whether the game is currently loading */
|
|
101
|
+
isLoading: boolean;
|
|
102
|
+
/** Whether the user needs to connect their wallet */
|
|
103
|
+
showConnectPrompt: boolean;
|
|
104
|
+
/** Retry the launch after an error */
|
|
105
|
+
retry: () => void;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Check if a token looks like a JWT (has 3 non-empty parts separated by dots).
|
|
109
|
+
*/
|
|
110
|
+
export declare function looksLikeJwt(token: string | null | undefined): boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Check if a token is a one-time token (OTT) based on JWT audience claim.
|
|
113
|
+
* OTTs have aud: "login" in their payload.
|
|
114
|
+
*/
|
|
115
|
+
export declare function isOneTimeToken(token: string): boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Check if a token looks like a UUID (table_id format).
|
|
118
|
+
* UUIDs are 36 characters: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
|
119
|
+
*/
|
|
120
|
+
export declare function isTableId(token: string): boolean;
|
|
121
|
+
export type TokenType = 'ott' | 'table_id' | 'expired_jwt' | 'unknown';
|
|
122
|
+
/**
|
|
123
|
+
* Classify a URL token into its type.
|
|
124
|
+
* Useful for quick UI decisions before making network calls.
|
|
125
|
+
*/
|
|
126
|
+
export declare function getTokenType(token: string | null | undefined): TokenType;
|
|
127
|
+
export declare const VALID_COINS: Record<string, string[]>;
|
|
128
|
+
/** Get coin type: use URL param if compatible with chain, otherwise default */
|
|
129
|
+
export declare function getCompatibleCoinType(chain: string, urlCoinType: string | null): string;
|
|
130
|
+
export declare class SessionClient {
|
|
131
|
+
private baseUrl;
|
|
132
|
+
constructor(config?: SessionConfig);
|
|
133
|
+
/**
|
|
134
|
+
* Get a launch URL with one-time token for a game.
|
|
135
|
+
* Used by the parent site (e.g., doubleup-io) to launch games.
|
|
136
|
+
*
|
|
137
|
+
* @param params - Wallet address, signature, chain, and game type
|
|
138
|
+
* @returns Launch URL containing the one-time token
|
|
139
|
+
*/
|
|
140
|
+
getLaunchUrl(params: LaunchParams): Promise<LaunchResult>;
|
|
141
|
+
/**
|
|
142
|
+
* Exchange a one-time token (OTT) for a session JWT.
|
|
143
|
+
*
|
|
144
|
+
* @param oneTimeToken - The one-time token from the launch URL
|
|
145
|
+
* @returns The session JWT token
|
|
146
|
+
* @throws AuthError if the token is invalid or expired
|
|
147
|
+
*/
|
|
148
|
+
getSessionToken(oneTimeToken: string): Promise<string>;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Initialize a game session from a URL token.
|
|
152
|
+
*
|
|
153
|
+
* Handles the complete flow:
|
|
154
|
+
* - OTT: exchange for session token → create table → return result
|
|
155
|
+
* - table_id: fetch table info → return result
|
|
156
|
+
* - expired JWT: throw AuthError
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```ts
|
|
160
|
+
* const result = await initializeGame({
|
|
161
|
+
* token: urlParams.get('token'),
|
|
162
|
+
* coinType: urlParams.get('coinType'),
|
|
163
|
+
* sessionToken: sessionStorage.getItem('session_token'),
|
|
164
|
+
* createTable: (session, coin) => baccaratApi.createTable(session, coin),
|
|
165
|
+
* getTableInfo: (tableId, session) => baccaratApi.getBalance(session, tableId),
|
|
166
|
+
* });
|
|
167
|
+
* // result = { tableId, coinType, sessionToken }
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
export declare function initializeGame(options: InitializeGameOptions): Promise<InitializeGameResult>;
|
|
171
|
+
export declare class HistoryClient {
|
|
172
|
+
private ws;
|
|
173
|
+
private config;
|
|
174
|
+
private keepAliveInterval;
|
|
175
|
+
private reconnectTimeout;
|
|
176
|
+
private tableId;
|
|
177
|
+
private coinType;
|
|
178
|
+
onMessage: ((event: MessageEvent) => void) | null;
|
|
179
|
+
onConnect: (() => void) | null;
|
|
180
|
+
onDisconnect: (() => void) | null;
|
|
181
|
+
onError: ((error: Event) => void) | null;
|
|
182
|
+
constructor(config?: HistoryConfig);
|
|
183
|
+
connect(tableId: string, coinType: string): void;
|
|
184
|
+
disconnect(): void;
|
|
185
|
+
send(message: object): void;
|
|
186
|
+
private startKeepAlive;
|
|
187
|
+
private cleanup;
|
|
188
|
+
}
|
|
189
|
+
interface UseHistoryClientOptions {
|
|
190
|
+
/**
|
|
191
|
+
* Callback for all incoming WebSocket messages.
|
|
192
|
+
* Receives the parsed JSON message.
|
|
193
|
+
*/
|
|
194
|
+
onMessage?: (message: any) => void;
|
|
195
|
+
/**
|
|
196
|
+
* History client configuration (baseUrl, reconnect settings, etc.)
|
|
197
|
+
*/
|
|
198
|
+
config?: HistoryConfig;
|
|
199
|
+
}
|
|
200
|
+
export declare function useHistoryClient(tableId: string | null, coinType: string | null, options?: UseHistoryClientOptions): {
|
|
201
|
+
isConnected: boolean;
|
|
202
|
+
send: (message: object) => void;
|
|
203
|
+
sendBetUpdate: (bets: Record<string, number>) => void;
|
|
204
|
+
sendGameReset: () => void;
|
|
205
|
+
disconnect: () => void;
|
|
206
|
+
};
|
|
207
|
+
export declare function useGameLauncher(config: GameLauncherConfig, options: UseGameLauncherOptions): GameLauncherState;
|
|
208
|
+
export {};
|
|
13
209
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,qBAAa,SAAU,SAAQ,KAAK;IAClC,IAAI,SAAe;CACpB;AAMD,eAAO,MAAM,YAAY,aAAgB,CAAC;AAE1C,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAErD;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEvD;AAOD,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,qBAAqB;IACpC,8CAA8C;IAC9C,KAAK,EAAE,MAAM,CAAC;IACd,kEAAkE;IAClE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,qDAAqD;IACrD,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,mDAAmD;IACnD,WAAW,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,SAAS,CAAC,CAAC;IAC5E,sEAAsE;IACtE,YAAY,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,Y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