@iamgame/wallet-sdk 0.1.0

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.
@@ -0,0 +1,470 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import React$1 from 'react';
3
+
4
+ type AuthMethod = "siws" | "telegram";
5
+ interface IUserIdentity {
6
+ id: string;
7
+ type: AuthMethod;
8
+ /** For SIWS: base58 Solana pubkey. For Telegram: numeric user id as string. */
9
+ externalId: string;
10
+ }
11
+ interface IUser {
12
+ id: string;
13
+ appId: string;
14
+ studioUserId?: string;
15
+ primaryIdentity: IUserIdentity;
16
+ identities: IUserIdentity[];
17
+ createdAt: string;
18
+ }
19
+ /** SIWS challenge issued by the signer; the client signs it with its external wallet. */
20
+ interface ISiwsChallenge {
21
+ nonce: string;
22
+ domain: string;
23
+ statement: string;
24
+ uri: string;
25
+ /** ISO timestamp; rejected if older than the freshness window on verify. */
26
+ issuedAt: string;
27
+ /** ISO timestamp after which the challenge cannot be redeemed. */
28
+ expiresAt: string;
29
+ }
30
+ interface ISiwsVerifyRequest {
31
+ challenge: ISiwsChallenge;
32
+ /** base58 Solana pubkey */
33
+ publicKey: string;
34
+ /** base64 ed25519 signature over the challenge message */
35
+ signature: string;
36
+ }
37
+ interface ITelegramVerifyRequest {
38
+ /** Raw `window.Telegram.WebApp.initData` string (URL-encoded). */
39
+ initData: string;
40
+ }
41
+ interface ISession {
42
+ /** Short-lived JWT (1h) signed with IAMGame session secret. Sent as bearer. */
43
+ accessToken: string;
44
+ /** Longer-lived (7d) refresh token. */
45
+ refreshToken: string;
46
+ expiresAt: string;
47
+ user: IUser;
48
+ }
49
+
50
+ type WalletCustody = "operator" | "self";
51
+ type WalletStatus = "active" | "exported" | "archived";
52
+ interface IWallet {
53
+ id: string;
54
+ userId: string;
55
+ appId: string;
56
+ /** base58 Solana pubkey */
57
+ address: string;
58
+ custody: WalletCustody;
59
+ status: WalletStatus;
60
+ createdAt: string;
61
+ }
62
+ interface ITokenBalance {
63
+ /** "SOL" or an SPL mint address. */
64
+ mint: string;
65
+ /** Stringified BigInt of base units (lamports for SOL, micro-units for USDC, etc.). */
66
+ amount: string;
67
+ decimals: number;
68
+ symbol?: string;
69
+ }
70
+ interface IWalletBalance {
71
+ walletId: string;
72
+ address: string;
73
+ tokens: ITokenBalance[];
74
+ /** Updated-at ISO timestamp for the cached snapshot; clients can re-fetch if stale. */
75
+ asOf: string;
76
+ }
77
+ interface IExportPreflightResponse {
78
+ /** Whether export is currently allowed. */
79
+ allowed: boolean;
80
+ /** Human-readable reason when not allowed (e.g. balance gate). */
81
+ reason?: string;
82
+ /** Lamports of SOL required to satisfy the balance gate. */
83
+ minBalanceLamports: string;
84
+ /** Lamports of SOL currently in W_old. */
85
+ currentBalanceLamports: string;
86
+ /** Lamports of SOL that will be bootstrapped into W_new. */
87
+ bootstrapLamports: string;
88
+ }
89
+ interface IExportInitiateRequest {
90
+ /** Idempotency key on the wallet level (one export per id). */
91
+ idempotencyKey: string;
92
+ }
93
+ interface IExportInitiateResponse {
94
+ /** base58 Solana pubkey of the new IAMGame wallet (W_new). */
95
+ newWalletAddress: string;
96
+ /** base58 ed25519 private key of W_old, revealed once. Never persisted server-side after this call. */
97
+ exportedPrivateKey: string;
98
+ /** Signature of the bootstrap transfer tx (W_old -> W_new). */
99
+ bootstrapTxSignature: string;
100
+ }
101
+
102
+ interface ISignActionRequest {
103
+ walletId: string;
104
+ /** base64-encoded serialized Solana transaction (versioned or legacy). */
105
+ txBase64: string;
106
+ /** Optional client-supplied label used in audit log. */
107
+ label?: string;
108
+ }
109
+ interface ISignActionResponse {
110
+ /** base64-encoded fully signed transaction, ready to submit to RPC. */
111
+ signedTxBase64: string;
112
+ /** Solana transaction signature (base58) for tracking. */
113
+ signature: string;
114
+ }
115
+ interface IWithdrawRequest {
116
+ walletId: string;
117
+ /** base58 destination Solana address. */
118
+ toAddress: string;
119
+ /** "SOL" or SPL mint address. */
120
+ mint: string;
121
+ /** Stringified BigInt of base units to transfer. */
122
+ amount: string;
123
+ idempotencyKey: string;
124
+ }
125
+ interface IWithdrawResponse {
126
+ /** Solana transaction signature (base58). */
127
+ signature: string;
128
+ status: "submitted" | "confirmed" | "failed";
129
+ }
130
+
131
+ type WebhookEventType = "user.created" | "user.suspended" | "wallet.created" | "wallet.exported" | "wallet.migrated" | "compliance.passed" | "compliance.failed" | "compliance.review_required" | "deposit.received" | "withdrawal.completed" | "withdrawal.failed";
132
+ interface IWebhookEnvelope<T = unknown> {
133
+ id: string;
134
+ type: WebhookEventType;
135
+ /** ISO timestamp the event was generated. */
136
+ createdAt: string;
137
+ appId: string;
138
+ /** Monotonically increasing per-app sequence number; lets consumers detect gaps/reorders. */
139
+ sequence: number;
140
+ data: T;
141
+ }
142
+ interface IWebhookSignatureHeader {
143
+ /** `t=<unix>,v1=<hex hmac>` — Stripe-style. */
144
+ raw: string;
145
+ timestamp: number;
146
+ signature: string;
147
+ }
148
+
149
+ type IAMGameErrorCode = "auth/invalid_signature" | "auth/challenge_expired" | "auth/challenge_already_redeemed" | "auth/invalid_init_data" | "auth/init_data_stale" | "auth/init_data_replayed" | "auth/missing_token" | "auth/invalid_token" | "auth/expired_token" | "wallet/not_found" | "wallet/insufficient_balance" | "wallet/export_blocked" | "wallet/already_exported" | "user/not_found" | "user/suspended" | "compliance/blocked" | "sign/invalid_transaction" | "sign/wallet_archived" | "sign/internal_failure" | "withdrawal/insufficient_balance" | "withdrawal/limit_exceeded" | "ratelimit/exceeded" | "idempotency/key_in_use" | "validation/bad_request" | "server/internal";
150
+ interface IIAMGameErrorEnvelope {
151
+ code: IAMGameErrorCode;
152
+ message: string;
153
+ details?: Record<string, unknown>;
154
+ }
155
+
156
+ type ComplianceModuleType = "kyc" | "aml" | "screening" | "sanctions";
157
+ type ComplianceStatus = "not_started" | "pending" | "passed" | "failed" | "review_required";
158
+ interface IComplianceState {
159
+ userId: string;
160
+ moduleType: ComplianceModuleType;
161
+ status: ComplianceStatus;
162
+ /** Provider-specific reference (e.g. Smile ID job id) for debugging. */
163
+ providerRef?: string;
164
+ updatedAt: string;
165
+ }
166
+
167
+ interface ISessionStorage {
168
+ get(): ISession | null;
169
+ set(session: ISession | null): void;
170
+ }
171
+ declare const localStorageSession: ISessionStorage;
172
+ declare const inMemorySession: () => ISessionStorage;
173
+
174
+ interface IAMGameClientOptions {
175
+ publishableKey: string;
176
+ /** Base URL incl. version path, e.g. "https://api.solven.xyz/v1" or "http://localhost:4100/v1". */
177
+ baseUrl: string;
178
+ storage?: ISessionStorage;
179
+ fetchImpl?: typeof fetch;
180
+ }
181
+ declare class IAMGameClient {
182
+ private readonly opts;
183
+ constructor(options: IAMGameClientOptions);
184
+ requestSiwsChallenge(publicKey: string): Promise<ISiwsChallenge>;
185
+ verifySiws(req: ISiwsVerifyRequest): Promise<ISession>;
186
+ verifyTelegram(req: ITelegramVerifyRequest): Promise<ISession>;
187
+ refreshSession(): Promise<ISession | null>;
188
+ logout(): Promise<void>;
189
+ getSession(): ISession | null;
190
+ getMe(): Promise<IUser>;
191
+ getMyWallet(): Promise<IWallet>;
192
+ getBalance(walletId: string): Promise<IWalletBalance>;
193
+ signAction(req: ISignActionRequest, idempotencyKey?: string): Promise<ISignActionResponse>;
194
+ withdraw(req: IWithdrawRequest): Promise<IWithdrawResponse>;
195
+ exportPreflight(walletId: string): Promise<IExportPreflightResponse>;
196
+ exportWallet(walletId: string, idempotencyKey: string): Promise<IExportInitiateResponse>;
197
+ private publicCall;
198
+ private userCall;
199
+ private doFetch;
200
+ }
201
+
202
+ declare class IAMGameSdkError extends Error {
203
+ readonly code: IAMGameErrorCode | "client/network" | "client/aborted";
204
+ readonly httpStatus?: number;
205
+ readonly details?: Record<string, unknown>;
206
+ constructor(args: {
207
+ code: IAMGameErrorCode | "client/network" | "client/aborted";
208
+ message: string;
209
+ httpStatus?: number;
210
+ details?: Record<string, unknown>;
211
+ });
212
+ static fromEnvelope(envelope: IIAMGameErrorEnvelope, httpStatus: number): IAMGameSdkError;
213
+ }
214
+
215
+ interface IExternalWalletAdapter {
216
+ /** Returns the wallet's public key (base58). May trigger a connect prompt. */
217
+ connect(): Promise<{
218
+ publicKey: string;
219
+ }>;
220
+ /** Disconnect the wallet, if supported. Some adapters no-op. */
221
+ disconnect?(): Promise<void>;
222
+ /**
223
+ * Sign an arbitrary UTF-8 message and return a detached ed25519 signature (base64).
224
+ * Both Phantom and Solflare expose this via signMessage(Uint8Array) → { signature: Uint8Array }.
225
+ */
226
+ signMessage(message: string): Promise<{
227
+ signature: string;
228
+ publicKey: string;
229
+ }>;
230
+ }
231
+ /**
232
+ * Default adapter for the Phantom-style `window.solana` injection.
233
+ * Usage: pass `phantomAdapter()` to IAMGameLogin or call useIAMGameAuth().connectExternal.
234
+ */
235
+ declare function phantomAdapter(): IExternalWalletAdapter;
236
+
237
+ interface IUseIAMGameAuth {
238
+ user: IUser | null;
239
+ status: "loading" | "anonymous" | "authenticated";
240
+ /** Run the SIWS flow with the supplied external wallet adapter. */
241
+ connectExternal: (adapter: IExternalWalletAdapter) => Promise<void>;
242
+ /** Run the Telegram TMA flow. Reads `window.Telegram.WebApp.initData` and posts to IAMGame. */
243
+ connectTelegram: () => Promise<void>;
244
+ logout: () => Promise<void>;
245
+ }
246
+ declare function useIAMGameAuth(): IUseIAMGameAuth;
247
+ declare function useIAMGameWallet(): IWallet | null;
248
+ declare function useIAMGameBalance(walletId: string | null, pollMs?: number): IWalletBalance | null;
249
+ interface IUseIAMGameSign {
250
+ signAction: (args: {
251
+ walletId: string;
252
+ txBase64: string;
253
+ label?: string;
254
+ idempotencyKey?: string;
255
+ }) => Promise<{
256
+ signedTxBase64: string;
257
+ signature: string;
258
+ }>;
259
+ }
260
+ declare function useIAMGameSign(): IUseIAMGameSign;
261
+ interface IUseIAMGameExport {
262
+ preflight: IExportPreflightResponse | null;
263
+ refreshPreflight: () => Promise<void>;
264
+ exportKey: (idempotencyKey: string) => Promise<IExportInitiateResponse>;
265
+ }
266
+ declare function useIAMGameExport(walletId: string | null): IUseIAMGameExport;
267
+ interface IUseIAMGameTransferIn {
268
+ /** Returns the destination address (the user's IAMGame wallet) for the top-up. */
269
+ destinationAddress: string | null;
270
+ }
271
+ declare function useIAMGameTransferIn(): IUseIAMGameTransferIn;
272
+
273
+ interface IAMGameLoginTheme {
274
+ primary?: string;
275
+ background?: string;
276
+ foreground?: string;
277
+ muted?: string;
278
+ /** Surface for secondary (un-detected wallet) buttons. */
279
+ surface?: string;
280
+ border?: string;
281
+ radius?: string;
282
+ fontFamily?: string;
283
+ }
284
+ interface CommonProps {
285
+ theme?: IAMGameLoginTheme;
286
+ /**
287
+ * Optional override for the default wallet picker. Pass a single adapter
288
+ * factory to force one wallet; omit to render the multi-wallet picker.
289
+ */
290
+ adapterFactory?: () => IExternalWalletAdapter;
291
+ /** Called once a session is successfully created. */
292
+ onSignIn?: () => void;
293
+ title?: React$1.ReactNode;
294
+ subtitle?: React$1.ReactNode;
295
+ /**
296
+ * If true and TMA context is detected, runs Telegram verify on mount with
297
+ * no clicks. Defaults to true.
298
+ */
299
+ autoTelegram?: boolean;
300
+ }
301
+ type IAMGameLoginProps = CommonProps;
302
+ interface IAMGameLoginModalProps extends CommonProps {
303
+ isOpen: boolean;
304
+ onClose: () => void;
305
+ /** Backdrop click closes by default. Set false to disable. */
306
+ closeOnBackdrop?: boolean;
307
+ /** Esc key closes by default. Set false to disable. */
308
+ closeOnEscape?: boolean;
309
+ }
310
+ declare function IAMGameLogin(props: IAMGameLoginProps): react_jsx_runtime.JSX.Element | null;
311
+ declare function IAMGameLoginModal(props: IAMGameLoginModalProps): React$1.ReactPortal | null;
312
+
313
+ interface IAMGameAddressTheme {
314
+ background?: string;
315
+ foreground?: string;
316
+ muted?: string;
317
+ surface?: string;
318
+ border?: string;
319
+ primary?: string;
320
+ radius?: string;
321
+ fontFamily?: string;
322
+ }
323
+ interface IAMGameAddressProps {
324
+ theme?: IAMGameAddressTheme;
325
+ /** Number of leading + trailing chars shown in the truncated address. Default 6. */
326
+ truncateChars?: number;
327
+ /** Render a custom QR code element. Receives the wallet address. Omit to skip QR. */
328
+ renderQr?: (address: string) => React$1.ReactNode;
329
+ /** Show copy button. Default true. */
330
+ showCopy?: boolean;
331
+ /** Label text above the address. Default "Wallet Address". */
332
+ label?: string;
333
+ }
334
+ declare function IAMGameAddress(props: IAMGameAddressProps): react_jsx_runtime.JSX.Element | null;
335
+
336
+ interface IAMGameBalanceTheme {
337
+ background?: string;
338
+ foreground?: string;
339
+ muted?: string;
340
+ surface?: string;
341
+ border?: string;
342
+ primary?: string;
343
+ radius?: string;
344
+ fontFamily?: string;
345
+ }
346
+ interface IAMGameBalanceProps {
347
+ theme?: IAMGameBalanceTheme;
348
+ /** Polling interval in ms. Default 15000. */
349
+ pollMs?: number;
350
+ /** Show only specific mints. Omit to show all. */
351
+ filterMints?: string[];
352
+ /** Show a manual refresh button. Default true. */
353
+ showRefresh?: boolean;
354
+ /** Label text. Default "Balance". */
355
+ label?: string;
356
+ /** Compact mode — single line, no card chrome. Default false. */
357
+ compact?: boolean;
358
+ }
359
+ declare function IAMGameBalance(props: IAMGameBalanceProps): react_jsx_runtime.JSX.Element | null;
360
+
361
+ interface IAMGameWithdrawTheme {
362
+ background?: string;
363
+ foreground?: string;
364
+ muted?: string;
365
+ surface?: string;
366
+ border?: string;
367
+ primary?: string;
368
+ danger?: string;
369
+ radius?: string;
370
+ fontFamily?: string;
371
+ }
372
+ interface IAMGameWithdrawProps {
373
+ theme?: IAMGameWithdrawTheme;
374
+ /** Restrict to a single mint. Omit to let user pick SOL or available SPL tokens. */
375
+ mint?: string;
376
+ /** Called after a successful withdrawal with the tx signature. */
377
+ onSuccess?: (signature: string) => void;
378
+ /** Called on error. */
379
+ onError?: (error: Error) => void;
380
+ /** Label text. Default "Withdraw". */
381
+ label?: string;
382
+ }
383
+ declare function IAMGameWithdraw(props: IAMGameWithdrawProps): react_jsx_runtime.JSX.Element | null;
384
+
385
+ interface IAMGameExportTheme {
386
+ background?: string;
387
+ foreground?: string;
388
+ muted?: string;
389
+ surface?: string;
390
+ border?: string;
391
+ primary?: string;
392
+ danger?: string;
393
+ radius?: string;
394
+ fontFamily?: string;
395
+ }
396
+ interface IAMGameExportProps {
397
+ theme?: IAMGameExportTheme;
398
+ /** Called after successful export. */
399
+ onSuccess?: (newWalletAddress: string) => void;
400
+ /** Called on error. */
401
+ onError?: (error: Error) => void;
402
+ /** Label text. Default "Export Wallet". */
403
+ label?: string;
404
+ }
405
+ declare function IAMGameExport(props: IAMGameExportProps): react_jsx_runtime.JSX.Element | null;
406
+
407
+ type WalletId = "phantom" | "solflare" | "backpack";
408
+ interface WalletDescriptor {
409
+ id: WalletId;
410
+ name: string;
411
+ /** Whether the wallet's injection is detectable on `window` right now. */
412
+ detected: boolean;
413
+ /** Download / discovery URL for users who don't have it installed. */
414
+ downloadUrl: string;
415
+ buildAdapter: () => IExternalWalletAdapter;
416
+ }
417
+ declare const solflareAdapter: () => IExternalWalletAdapter;
418
+ declare const backpackAdapter: () => IExternalWalletAdapter;
419
+ declare function listSupportedWallets(): WalletDescriptor[];
420
+
421
+ interface TransferInDeps {
422
+ Connection: any;
423
+ PublicKey: any;
424
+ Transaction: any;
425
+ SystemProgram: any;
426
+ TOKEN_PROGRAM_ID?: any;
427
+ createTransferCheckedInstruction?: any;
428
+ getAssociatedTokenAddressSync?: any;
429
+ createAssociatedTokenAccountInstruction?: any;
430
+ getMint?: any;
431
+ }
432
+ interface BuildSolTransferOpts {
433
+ /** base58 source wallet (the external wallet). */
434
+ fromAddress: string;
435
+ /** base58 destination wallet (the user's IAMGame wallet). */
436
+ toAddress: string;
437
+ /** Stringified BigInt of lamports. */
438
+ lamports: string;
439
+ /** RPC endpoint. */
440
+ rpcUrl: string;
441
+ }
442
+ interface BuildSplTransferOpts extends BuildSolTransferOpts {
443
+ /** base58 SPL mint address (USDC, USDT, etc.). */
444
+ mint: string;
445
+ /** Base-unit amount (the raw integer, not the decimal float). */
446
+ amount: string;
447
+ }
448
+ /**
449
+ * Builds an unsigned base64-serialized SOL transfer from the user's external
450
+ * wallet to the IAMGame wallet. Caller signs the returned bytes with their
451
+ * external wallet adapter and submits to RPC.
452
+ */
453
+ declare function buildSolTransferIn(deps: TransferInDeps, opts: BuildSolTransferOpts): Promise<string>;
454
+ /**
455
+ * Builds an unsigned SPL transfer. If the destination's ATA doesn't exist, an
456
+ * AssociatedTokenAccount create instruction is included; the payer is the
457
+ * source wallet (the user pays the ~0.002 SOL rent for opening the ATA).
458
+ */
459
+ declare function buildSplTransferIn(deps: TransferInDeps, opts: BuildSplTransferOpts): Promise<string>;
460
+
461
+ declare function getTelegramInitData(): string | null;
462
+ declare function isTelegramMiniApp(): boolean;
463
+ declare function notifyTelegramReady(): void;
464
+
465
+ interface IAMGameWalletProviderProps extends IAMGameClientOptions {
466
+ children: React.ReactNode;
467
+ }
468
+ declare const IAMGameWalletProvider: React.FC<IAMGameWalletProviderProps>;
469
+
470
+ export { type AuthMethod, type BuildSolTransferOpts, type BuildSplTransferOpts, type ComplianceModuleType, type ComplianceStatus, IAMGameClient as IAMGameWalletClient, type IAMGameClientOptions as IAMGameWalletClientOptions, IAMGameWalletProvider, type IAMGameWalletProviderProps, type IComplianceState, type IExportInitiateRequest, type IExportInitiateResponse, type IExportPreflightResponse, type IExternalWalletAdapter, type ISession, type ISessionStorage, type ISignActionRequest, type ISignActionResponse, type ISiwsChallenge, type ISiwsVerifyRequest, type ITelegramVerifyRequest, type ITokenBalance, type IUseIAMGameAuth as IUseWalletAuth, type IUseIAMGameExport as IUseWalletExport, type IUseIAMGameSign as IUseWalletSign, type IUseIAMGameTransferIn as IUseWalletTransferIn, type IUser, type IUserIdentity, type IWallet, type IWalletBalance, type IIAMGameErrorEnvelope as IWalletErrorEnvelope, type IWebhookEnvelope, type IWebhookSignatureHeader, type IWithdrawRequest, type IWithdrawResponse, type TransferInDeps, IAMGameAddress as WalletAddress, type IAMGameAddressProps as WalletAddressProps, type IAMGameAddressTheme as WalletAddressTheme, IAMGameBalance as WalletBalance, type IAMGameBalanceProps as WalletBalanceProps, type IAMGameBalanceTheme as WalletBalanceTheme, type WalletCustody, type WalletDescriptor, type IAMGameErrorCode as WalletErrorCode, IAMGameExport as WalletExport, type IAMGameExportProps as WalletExportProps, type IAMGameExportTheme as WalletExportTheme, type WalletId, IAMGameLogin as WalletLogin, IAMGameLoginModal as WalletLoginModal, type IAMGameLoginModalProps as WalletLoginModalProps, type IAMGameLoginProps as WalletLoginProps, type IAMGameLoginTheme as WalletLoginTheme, IAMGameSdkError as WalletSdkError, type WalletStatus, IAMGameWithdraw as WalletWithdraw, type IAMGameWithdrawProps as WalletWithdrawProps, type IAMGameWithdrawTheme as WalletWithdrawTheme, type WebhookEventType, backpackAdapter, buildSolTransferIn, buildSplTransferIn, getTelegramInitData, inMemorySession, isTelegramMiniApp, listSupportedWallets, localStorageSession, notifyTelegramReady, phantomAdapter, solflareAdapter, useIAMGameWallet as useWallet, useIAMGameAuth as useWalletAuth, useIAMGameBalance as useWalletBalance, useIAMGameExport as useWalletExport, useIAMGameSign as useWalletSign, useIAMGameTransferIn as useWalletTransferIn };