@iamgame/wallet-sdk 0.1.0 → 0.1.1

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/dist/index.cjs CHANGED
@@ -254,7 +254,7 @@ function useSolvenContext() {
254
254
  if (!ctx) throw new Error("useSolvenContext must be inside a <SolvenProvider />");
255
255
  return ctx;
256
256
  }
257
- function SolvenProvider({ children, ...opts }) {
257
+ function SolvenProvider({ children, autoTelegram = true, ...opts }) {
258
258
  const client = react.useMemo(() => new SolvenClient(opts), [
259
259
  opts.publishableKey,
260
260
  opts.baseUrl,
@@ -295,6 +295,32 @@ function SolvenProvider({ children, ...opts }) {
295
295
  cancelled = true;
296
296
  };
297
297
  }, [client]);
298
+ const triedTelegram = react.useRef(false);
299
+ react.useEffect(() => {
300
+ if (!autoTelegram || status !== "anonymous" || triedTelegram.current) return;
301
+ triedTelegram.current = true;
302
+ let cancelled = false;
303
+ (async () => {
304
+ let initData = getTelegramInitData();
305
+ for (let i = 0; i < 4 && !initData; i++) {
306
+ await new Promise((r) => setTimeout(r, 400));
307
+ if (cancelled) return;
308
+ initData = getTelegramInitData();
309
+ }
310
+ if (!initData) return;
311
+ try {
312
+ notifyTelegramReady();
313
+ const next = await client.verifyTelegram({ initData });
314
+ if (cancelled) return;
315
+ setSession(next);
316
+ setStatus("authenticated");
317
+ } catch {
318
+ }
319
+ })();
320
+ return () => {
321
+ cancelled = true;
322
+ };
323
+ }, [autoTelegram, status, client]);
298
324
  const value = {
299
325
  client,
300
326
  session,
package/dist/index.d.cts CHANGED
@@ -8,12 +8,22 @@ interface IUserIdentity {
8
8
  /** For SIWS: base58 Solana pubkey. For Telegram: numeric user id as string. */
9
9
  externalId: string;
10
10
  }
11
+ interface IUserWallet {
12
+ /** base58 Solana pubkey */
13
+ address: string;
14
+ /** test (devnet) or live (mainnet) — wallets are isolated per environment. */
15
+ environment: "test" | "live";
16
+ custody: "self" | "operator";
17
+ status: "active" | "exported" | "archived";
18
+ }
11
19
  interface IUser {
12
20
  id: string;
13
21
  appId: string;
14
22
  studioUserId?: string;
15
23
  primaryIdentity: IUserIdentity;
16
24
  identities: IUserIdentity[];
25
+ /** Managed wallets owned by this user. Lets a relying server confirm a claimed address. */
26
+ wallets: IUserWallet[];
17
27
  createdAt: string;
18
28
  }
19
29
  /** SIWS challenge issued by the signer; the client signs it with its external wallet. */
@@ -146,7 +156,7 @@ interface IWebhookSignatureHeader {
146
156
  signature: string;
147
157
  }
148
158
 
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";
159
+ 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" | "ledger/insufficient_balance" | "ledger/session_not_found" | "ledger/session_closed" | "ledger/bet_not_found" | "ledger/bet_rolled_back" | "ledger/currency_mismatch" | "ratelimit/exceeded" | "idempotency/key_in_use" | "validation/bad_request" | "server/internal";
150
160
  interface IIAMGameErrorEnvelope {
151
161
  code: IAMGameErrorCode;
152
162
  message: string;
package/dist/index.d.ts CHANGED
@@ -8,12 +8,22 @@ interface IUserIdentity {
8
8
  /** For SIWS: base58 Solana pubkey. For Telegram: numeric user id as string. */
9
9
  externalId: string;
10
10
  }
11
+ interface IUserWallet {
12
+ /** base58 Solana pubkey */
13
+ address: string;
14
+ /** test (devnet) or live (mainnet) — wallets are isolated per environment. */
15
+ environment: "test" | "live";
16
+ custody: "self" | "operator";
17
+ status: "active" | "exported" | "archived";
18
+ }
11
19
  interface IUser {
12
20
  id: string;
13
21
  appId: string;
14
22
  studioUserId?: string;
15
23
  primaryIdentity: IUserIdentity;
16
24
  identities: IUserIdentity[];
25
+ /** Managed wallets owned by this user. Lets a relying server confirm a claimed address. */
26
+ wallets: IUserWallet[];
17
27
  createdAt: string;
18
28
  }
19
29
  /** SIWS challenge issued by the signer; the client signs it with its external wallet. */
@@ -146,7 +156,7 @@ interface IWebhookSignatureHeader {
146
156
  signature: string;
147
157
  }
148
158
 
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";
159
+ 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" | "ledger/insufficient_balance" | "ledger/session_not_found" | "ledger/session_closed" | "ledger/bet_not_found" | "ledger/bet_rolled_back" | "ledger/currency_mismatch" | "ratelimit/exceeded" | "idempotency/key_in_use" | "validation/bad_request" | "server/internal";
150
160
  interface IIAMGameErrorEnvelope {
151
161
  code: IAMGameErrorCode;
152
162
  message: string;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createContext, useMemo, useState, useEffect, useCallback, useRef, useContext } from 'react';
1
+ import { createContext, useMemo, useState, useEffect, useRef, useCallback, useContext } from 'react';
2
2
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
3
3
  import { createPortal } from 'react-dom';
4
4
 
@@ -252,7 +252,7 @@ function useSolvenContext() {
252
252
  if (!ctx) throw new Error("useSolvenContext must be inside a <SolvenProvider />");
253
253
  return ctx;
254
254
  }
255
- function SolvenProvider({ children, ...opts }) {
255
+ function SolvenProvider({ children, autoTelegram = true, ...opts }) {
256
256
  const client = useMemo(() => new SolvenClient(opts), [
257
257
  opts.publishableKey,
258
258
  opts.baseUrl,
@@ -293,6 +293,32 @@ function SolvenProvider({ children, ...opts }) {
293
293
  cancelled = true;
294
294
  };
295
295
  }, [client]);
296
+ const triedTelegram = useRef(false);
297
+ useEffect(() => {
298
+ if (!autoTelegram || status !== "anonymous" || triedTelegram.current) return;
299
+ triedTelegram.current = true;
300
+ let cancelled = false;
301
+ (async () => {
302
+ let initData = getTelegramInitData();
303
+ for (let i = 0; i < 4 && !initData; i++) {
304
+ await new Promise((r) => setTimeout(r, 400));
305
+ if (cancelled) return;
306
+ initData = getTelegramInitData();
307
+ }
308
+ if (!initData) return;
309
+ try {
310
+ notifyTelegramReady();
311
+ const next = await client.verifyTelegram({ initData });
312
+ if (cancelled) return;
313
+ setSession(next);
314
+ setStatus("authenticated");
315
+ } catch {
316
+ }
317
+ })();
318
+ return () => {
319
+ cancelled = true;
320
+ };
321
+ }, [autoTelegram, status, client]);
296
322
  const value = {
297
323
  client,
298
324
  session,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iamgame/wallet-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "IAMGame Wallet browser SDK — Telegram & Solana wallet auth, balances, server-side signing, and key export. Drop-in React provider for game frontends.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://wallet.iamgame.com",