@talken/talkenkit 2.5.3 → 2.5.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.
Files changed (69) hide show
  1. package/LICENSE +9 -0
  2. package/README.md +28 -8
  3. package/dist/{abcWallet-BFCI4NEM.js → abcWallet-QJ5BKEXW.js} +1 -1
  4. package/dist/{chunk-WPRIYR63.js → chunk-YORGXWYS.js} +26 -0
  5. package/dist/index.js +137 -104
  6. package/dist/klipWallet-TBZJ5GGT.js +7 -0
  7. package/dist/wallets/walletConnectors/abcWallet/abcAccessKeyProvider.d.ts +4 -0
  8. package/dist/wallets/walletConnectors/abcWallet/abcAccessKeyProvider.js +1 -1
  9. package/dist/wallets/walletConnectors/abcWallet/abcConnector.js +2 -2
  10. package/dist/wallets/walletConnectors/abcWallet/abcSolanaWalletAdapter.js +3 -4
  11. package/dist/wallets/walletConnectors/abcWallet/abcWallet.js +3 -3
  12. package/dist/wallets/walletConnectors/abcWallet/index.js +3 -3
  13. package/dist/wallets/walletConnectors/berasigWallet/berasigWallet.js +2 -2
  14. package/dist/wallets/walletConnectors/bifrostWallet/bifrostWallet.js +2 -2
  15. package/dist/wallets/walletConnectors/binanceWallet/binanceWallet.js +2 -2
  16. package/dist/wallets/walletConnectors/bitgetWallet/bitgetWallet.js +2 -2
  17. package/dist/wallets/walletConnectors/bybitWallet/bybitWallet.js +2 -2
  18. package/dist/wallets/walletConnectors/{chunk-2N244XPQ.js → chunk-E6ZG77AF.js} +26 -0
  19. package/dist/wallets/walletConnectors/{chunk-DW36LXIV.js → chunk-G6SV7RAS.js} +1 -1
  20. package/dist/wallets/walletConnectors/chunk-HKMJ67FD.js +37 -0
  21. package/dist/wallets/walletConnectors/{chunk-OOCL4OPQ.js → chunk-SDRE2D5I.js} +1 -1
  22. package/dist/wallets/walletConnectors/clvWallet/clvWallet.js +2 -2
  23. package/dist/wallets/walletConnectors/coin98Wallet/coin98Wallet.js +2 -2
  24. package/dist/wallets/walletConnectors/coreWallet/coreWallet.js +2 -2
  25. package/dist/wallets/walletConnectors/foxWallet/foxWallet.js +2 -2
  26. package/dist/wallets/walletConnectors/frontierWallet/frontierWallet.js +2 -2
  27. package/dist/wallets/walletConnectors/gateWallet/gateWallet.js +2 -2
  28. package/dist/wallets/walletConnectors/index.d.ts +2 -1
  29. package/dist/wallets/walletConnectors/index.js +65 -61
  30. package/dist/wallets/walletConnectors/iopayWallet/iopayWallet.js +2 -2
  31. package/dist/wallets/walletConnectors/kaiaWallet/kaiaWallet.js +2 -2
  32. package/dist/wallets/walletConnectors/kaikasWallet/kaikasWallet.js +2 -2
  33. package/dist/wallets/walletConnectors/klipWallet/klipWallet.js +3 -63
  34. package/dist/wallets/walletConnectors/metaMaskWallet/metaMaskWallet.js +2 -2
  35. package/dist/wallets/walletConnectors/okxWallet/okxWallet.js +2 -2
  36. package/dist/wallets/walletConnectors/rainbowWallet/rainbowWallet.js +2 -2
  37. package/dist/wallets/walletConnectors/roninWallet/roninWallet.js +2 -2
  38. package/dist/wallets/walletConnectors/safepalWallet/safepalWallet.js +2 -2
  39. package/dist/wallets/walletConnectors/subWallet/subWallet.js +2 -2
  40. package/dist/wallets/walletConnectors/tokenPocketWallet/tokenPocketWallet.js +2 -2
  41. package/dist/wallets/walletConnectors/trustWallet/trustWallet.js +2 -2
  42. package/dist/wallets/walletConnectors/zealWallet/zealWallet.js +2 -2
  43. package/dist/wallets/walletConnectors/zerionWallet/zerionWallet.js +2 -2
  44. package/package.json +11 -12
  45. package/dist/AbcCredentialManager-DDHLW2IH.js +0 -7
  46. package/dist/abcWallet-2BVT5XFX.js +0 -161
  47. package/dist/chunk-ALBABQ53.js +0 -354
  48. package/dist/chunk-KOK5ZBR4.js +0 -5447
  49. package/dist/wallets/walletConnectors/chunk-6WF4SXLB.js +0 -156
  50. package/dist/wallets/walletConnectors/chunk-A66MTFML.js +0 -223
  51. package/dist/wallets/walletConnectors/chunk-ACLPF2UW.js +0 -96
  52. package/dist/wallets/walletConnectors/chunk-BHEVY4QY.js +0 -827
  53. package/dist/wallets/walletConnectors/chunk-BXH3GDX5.js +0 -273
  54. package/dist/wallets/walletConnectors/chunk-CABLJOMU.js +0 -194
  55. package/dist/wallets/walletConnectors/chunk-DPTDOCWL.js +0 -205
  56. package/dist/wallets/walletConnectors/chunk-FBJ5H6PM.js +0 -300
  57. package/dist/wallets/walletConnectors/chunk-IM7DEERX.js +0 -585
  58. package/dist/wallets/walletConnectors/chunk-J3YPHDHM.js +0 -827
  59. package/dist/wallets/walletConnectors/chunk-JADQLTFW.js +0 -194
  60. package/dist/wallets/walletConnectors/chunk-L6WDO3ZN.js +0 -445
  61. package/dist/wallets/walletConnectors/chunk-MO2AXXLI.js +0 -30
  62. package/dist/wallets/walletConnectors/chunk-NLA45GHJ.js +0 -300
  63. package/dist/wallets/walletConnectors/chunk-NU3ITJNK.js +0 -1485
  64. package/dist/wallets/walletConnectors/chunk-NULM3THX.js +0 -241
  65. package/dist/wallets/walletConnectors/chunk-OMOYFHBT.js +0 -1485
  66. package/dist/wallets/walletConnectors/chunk-VDWJ3NQ5.js +0 -52
  67. package/dist/wallets/walletConnectors/chunk-VMCIDCO5.js +0 -54
  68. package/dist/wallets/walletConnectors/chunk-VNL7XEWF.js +0 -54
  69. package/dist/wallets/walletConnectors/chunk-YV6IZWGE.js +0 -393
@@ -1,827 +0,0 @@
1
- "use client";
2
- import {
3
- TalkenApiError
4
- } from "./chunk-4P3SPC44.js";
5
- import {
6
- getCredentialManager
7
- } from "./chunk-6WF4SXLB.js";
8
- import {
9
- DEFAULT_TALKEN_API_CONFIG,
10
- TALKEN_API_ENDPOINTS,
11
- TOKEN_EXPIRY
12
- } from "./chunk-DPTDOCWL.js";
13
-
14
- // src/wallets/walletConnectors/abcWallet/api/TalkenApiClient.ts
15
- var STORAGE_KEY_PREFIX = "talken_api_";
16
- function loadToken(key) {
17
- if (typeof window === "undefined")
18
- return null;
19
- try {
20
- return localStorage.getItem(`${STORAGE_KEY_PREFIX}${key}`);
21
- } catch {
22
- return null;
23
- }
24
- }
25
- function saveToken(key, value) {
26
- if (typeof window === "undefined")
27
- return;
28
- try {
29
- localStorage.setItem(`${STORAGE_KEY_PREFIX}${key}`, value);
30
- } catch {
31
- }
32
- }
33
- function removeToken(key) {
34
- if (typeof window === "undefined")
35
- return;
36
- try {
37
- localStorage.removeItem(`${STORAGE_KEY_PREFIX}${key}`);
38
- } catch {
39
- }
40
- }
41
- function normalizeAuthResponse(raw) {
42
- const d = raw.data || raw;
43
- const loginData = d.login || d;
44
- return {
45
- accessToken: loginData.access_token || loginData.accessToken || "",
46
- refreshToken: loginData.refresh_token || loginData.refreshToken || "",
47
- expiresIn: loginData.expires_in || loginData.expire_in || loginData.expiresIn || 3600,
48
- uid: d.uid || loginData.uid || "",
49
- email: d.email || loginData.email || "",
50
- isNewUser: d.isNewUser
51
- };
52
- }
53
- var TalkenAuthModule = class {
54
- constructor(client) {
55
- this.client = client;
56
- }
57
- /**
58
- * Login with email and password
59
- * POST /wallet/auth { action: 'login', method: 'password', email, password }
60
- */
61
- async loginWithPassword(email, password) {
62
- const raw = await this.client.post(
63
- TALKEN_API_ENDPOINTS.AUTH,
64
- { action: "login", method: "password", email, password },
65
- { skipAuth: true }
66
- );
67
- const res = normalizeAuthResponse(raw);
68
- this.client.handleAuthResponse(res);
69
- return res;
70
- }
71
- /**
72
- * Send OTP code to email
73
- * POST /wallet/auth { action: 'otp.send', email }
74
- */
75
- async sendOtp(email) {
76
- const raw = await this.client.post(
77
- TALKEN_API_ENDPOINTS.AUTH,
78
- { action: "otp.send", email },
79
- { skipAuth: true }
80
- );
81
- const res = raw;
82
- if (res.success === false) {
83
- const data = res.data || {};
84
- throw new Error(data.msg || res.error || "OTP send failed");
85
- }
86
- return res.data || raw;
87
- }
88
- /**
89
- * Verify OTP code
90
- * POST /wallet/auth { action: 'otp.verify', email, otpCode }
91
- */
92
- async verifyOtp(email, otpCode) {
93
- const raw = await this.client.post(
94
- TALKEN_API_ENDPOINTS.AUTH,
95
- { action: "otp.verify", email, otpCode },
96
- { skipAuth: true }
97
- );
98
- const res = raw;
99
- if (res.success === false) {
100
- const data = res.data || {};
101
- throw new Error(data.msg || res.error || "OTP verification failed");
102
- }
103
- return res.data || raw;
104
- }
105
- /**
106
- * Check if email is already registered
107
- * POST /wallet/auth { action: 'email.check', email }
108
- * Returns code 606 if email exists
109
- */
110
- async checkEmail(email) {
111
- const raw = await this.client.post(
112
- TALKEN_API_ENDPOINTS.AUTH,
113
- { action: "email.check", email },
114
- { skipAuth: true }
115
- );
116
- const d = raw.data || raw;
117
- return {
118
- code: d.code,
119
- message: d.message,
120
- exists: d.code === 606
121
- };
122
- }
123
- /**
124
- * Register a new user (creates account + auto-login)
125
- * POST /wallet/auth { action: 'register', email, otpCode, password, name? }
126
- */
127
- async register(params) {
128
- const raw = await this.client.post(
129
- TALKEN_API_ENDPOINTS.AUTH,
130
- { action: "register", ...params },
131
- { skipAuth: true }
132
- );
133
- const res = normalizeAuthResponse(raw);
134
- this.client.handleAuthResponse(res);
135
- return res;
136
- }
137
- /**
138
- * Reset password for existing user
139
- * POST /wallet/auth { action: 'password.reset', email, newPassword, emailCode }
140
- */
141
- async resetPassword(email, newPassword, emailCode) {
142
- const raw = await this.client.post(
143
- TALKEN_API_ENDPOINTS.AUTH,
144
- { action: "password.reset", email, newPassword, emailCode },
145
- { skipAuth: true }
146
- );
147
- return raw.data || raw;
148
- }
149
- /**
150
- * Login with social provider (Google, Apple, Kakao, etc.)
151
- * POST /wallet/auth { action: 'login', method: 'sns', token, service, audience? }
152
- */
153
- async loginWithSns(params) {
154
- const raw = await this.client.post(
155
- TALKEN_API_ENDPOINTS.AUTH,
156
- {
157
- action: "login",
158
- method: "sns",
159
- token: params.token,
160
- service: params.service,
161
- ...params.audience && { audience: params.audience }
162
- },
163
- { skipAuth: true }
164
- );
165
- const res = normalizeAuthResponse(raw);
166
- this.client.handleAuthResponse(res);
167
- return res;
168
- }
169
- /**
170
- * Refresh access token
171
- * POST /wallet/auth { action: 'token.refresh', refreshToken }
172
- */
173
- async refresh() {
174
- const refreshToken = this.client.getRefreshToken();
175
- if (!refreshToken) {
176
- throw new TalkenApiError(
177
- "TOKEN_EXPIRED",
178
- "No refresh token available",
179
- 401
180
- );
181
- }
182
- const raw = await this.client.post(
183
- TALKEN_API_ENDPOINTS.AUTH,
184
- { action: "token.refresh", refreshToken },
185
- { skipAuth: true }
186
- );
187
- const res = normalizeAuthResponse(raw);
188
- this.client.handleAuthResponse(res);
189
- return res;
190
- }
191
- /**
192
- * Logout (clear local session only — no server endpoint)
193
- */
194
- logout() {
195
- this.client.clearSession();
196
- }
197
- };
198
- var TalkenWalletModule = class {
199
- constructor(client) {
200
- this.client = client;
201
- }
202
- /**
203
- * Generate/recover MPC wallets (create = idempotent generate/recover)
204
- * POST /wallet/mpc { action: 'create', email?, pin }
205
- *
206
- * @param pin - SHA-256 hashed PIN
207
- * @param email - User email (optional; server resolves from bearer token if omitted)
208
- */
209
- async generate(pin, email) {
210
- return this.client.post(TALKEN_API_ENDPOINTS.WALLET_MPC, {
211
- action: "create",
212
- ...email && { email },
213
- pin
214
- });
215
- }
216
- /**
217
- * Recover is the same as generate (create is idempotent)
218
- */
219
- async recover(pin, email) {
220
- return this.generate(pin, email);
221
- }
222
- /**
223
- * Get wallet info
224
- * POST /wallet/mpc { action: 'info' }
225
- */
226
- async getInfo() {
227
- return this.client.post(TALKEN_API_ENDPOINTS.WALLET_MPC, {
228
- action: "info"
229
- });
230
- }
231
- /**
232
- * Get addresses for all chains
233
- * POST /wallet/address { chain: 'all' }
234
- */
235
- async getAddresses() {
236
- return this.client.post(TALKEN_API_ENDPOINTS.WALLET_ADDRESS, {
237
- chain: "all"
238
- });
239
- }
240
- /**
241
- * Get addresses for a specific chain
242
- * POST /wallet/address { chain, publicKey?, pin? }
243
- */
244
- async getAddressForChain(chain, publicKey, pin) {
245
- return this.client.post(TALKEN_API_ENDPOINTS.WALLET_ADDRESS, {
246
- chain,
247
- ...publicKey && { publicKey },
248
- ...pin && { pin }
249
- });
250
- }
251
- };
252
- function withCachedEvmCreds(params) {
253
- if (typeof window === "undefined")
254
- return params;
255
- try {
256
- const creds = getCredentialManager().getEvmSigningCredentials();
257
- if (creds)
258
- return { ...params, evmCreds: creds };
259
- } catch {
260
- }
261
- return params;
262
- }
263
- var TalkenEvmModule = class {
264
- constructor(client) {
265
- this.client = client;
266
- }
267
- /**
268
- * Sign EVM transaction (sign only, no broadcast)
269
- * POST /wallet/sign/evm { network, to, from?, value?, data?, ... }
270
- * Server handles SecureChannel internally
271
- */
272
- async signTransaction(params) {
273
- return this.client.post(
274
- TALKEN_API_ENDPOINTS.SIGN_EVM,
275
- withCachedEvmCreds(params)
276
- );
277
- }
278
- /**
279
- * Sign EIP-712 typed data
280
- * POST /wallet/sign/evm/typed { network, typedData }
281
- */
282
- async signTypedData(params) {
283
- return this.client.post(
284
- TALKEN_API_ENDPOINTS.SIGN_TYPED,
285
- withCachedEvmCreds(params)
286
- );
287
- }
288
- /**
289
- * Sign personal message (EIP-191)
290
- * POST /wallet/sign/evm/personal { network, message, address? }
291
- */
292
- async signPersonal(params) {
293
- const res = await this.client.post(
294
- TALKEN_API_ENDPOINTS.SIGN_PERSONAL,
295
- withCachedEvmCreds(params)
296
- );
297
- return {
298
- signature: res?.signature ?? res?.serializedTx ?? "",
299
- txHash: res?.txHash ?? res?.rawTx
300
- };
301
- }
302
- /**
303
- * Sign EIP-7702 authorization payload
304
- * POST /wallet/sign/authorization { network, authorization, pin? }
305
- */
306
- async signAuthorization(params) {
307
- return this.client.post(
308
- TALKEN_API_ENDPOINTS.SIGN_AUTHORIZATION,
309
- withCachedEvmCreds(params)
310
- );
311
- }
312
- /**
313
- * Broadcast signed transaction
314
- * POST /wallet/tx/raw { network, signedSerializeTx }
315
- */
316
- async sendRawTransaction(params) {
317
- return this.client.post(
318
- TALKEN_API_ENDPOINTS.TX_RAW,
319
- params
320
- );
321
- }
322
- /**
323
- * Integrated EVM transfer (sign + broadcast)
324
- * POST /wallet/tx/evm { chainKey, to, amountWei, pin, ... }
325
- */
326
- async sendTransaction(params) {
327
- return this.client.post(
328
- TALKEN_API_ENDPOINTS.TX_EVM,
329
- withCachedEvmCreds(params)
330
- );
331
- }
332
- /**
333
- * Get gas price
334
- * GET /wallet/gas/price?network=
335
- */
336
- async getGasPrice(network) {
337
- return this.client.get(
338
- `${TALKEN_API_ENDPOINTS.GAS_PRICE}?network=${encodeURIComponent(network)}`
339
- );
340
- }
341
- /**
342
- * Get suggested gas fees (EIP-1559)
343
- * GET /wallet/gas/suggested?network=
344
- */
345
- async getGasSuggested(network) {
346
- return this.client.get(
347
- `${TALKEN_API_ENDPOINTS.GAS_SUGGESTED}?network=${encodeURIComponent(network)}`
348
- );
349
- }
350
- /**
351
- * Estimate gas
352
- * POST /wallet/gas/estimate { network, from, to, value?, data? }
353
- */
354
- async estimateGas(params) {
355
- return this.client.post(
356
- TALKEN_API_ENDPOINTS.GAS_ESTIMATE,
357
- params
358
- );
359
- }
360
- /**
361
- * Get nonce for address
362
- * GET /wallet/nonce?network=&address=
363
- */
364
- async getNonce(network, address) {
365
- const qs = new URLSearchParams({ network, address }).toString();
366
- return this.client.get(`${TALKEN_API_ENDPOINTS.NONCE}?${qs}`);
367
- }
368
- };
369
- var TalkenSolanaModule = class {
370
- constructor(client) {
371
- this.client = client;
372
- }
373
- async getLatestBlockhash(network) {
374
- const qs = new URLSearchParams({ network }).toString();
375
- return this.client.get(
376
- `${TALKEN_API_ENDPOINTS.SOLANA_LATEST_BLOCKHASH}?${qs}`,
377
- {
378
- skipAuth: true
379
- }
380
- );
381
- }
382
- async getTransactionStatus(params) {
383
- const qs = new URLSearchParams({
384
- network: params.network,
385
- signature: params.signature
386
- }).toString();
387
- return this.client.get(`${TALKEN_API_ENDPOINTS.SOLANA_TX_STATUS}?${qs}`, {
388
- skipAuth: true
389
- });
390
- }
391
- /**
392
- * Transfer SOL or SPL token (integrated sign + broadcast)
393
- * POST /wallet/tx/sol
394
- * - kind='native': { toAddress, amountLamports, pin }
395
- * - kind='spl': { toAddress, mintAddress, amount, decimals, network, pin }
396
- */
397
- async transfer(params) {
398
- return this.client.post(
399
- TALKEN_API_ENDPOINTS.TX_SOL,
400
- params
401
- );
402
- }
403
- /**
404
- * Sign Solana transaction or message (sign-only, no broadcast)
405
- * POST /wallet/sign/sol
406
- *
407
- * Two modes:
408
- * - PIN mode: { message, pin } — server resolves signing material
409
- * - Share mode: { message, keyId, encryptedShare } — no PIN required (for signMessage)
410
- *
411
- * @returns Ed25519 signature (hex) and optionally public key
412
- */
413
- async sign(params) {
414
- return this.client.post(
415
- TALKEN_API_ENDPOINTS.SIGN_SVM,
416
- params
417
- );
418
- }
419
- };
420
- var TalkenBitcoinModule = class {
421
- constructor(client) {
422
- this.client = client;
423
- }
424
- /**
425
- * BTC fee rate lookup
426
- * GET /wallet/btc?mode=fee&network=&blocks=
427
- */
428
- async getFeeRate(network, blocks) {
429
- const qs = new URLSearchParams({
430
- mode: "fee",
431
- network,
432
- ...typeof blocks === "number" ? { blocks: String(blocks) } : {}
433
- }).toString();
434
- return this.client.get(
435
- `${TALKEN_API_ENDPOINTS.WALLET_BTC}?${qs}`
436
- );
437
- }
438
- /**
439
- * BTC tx status by hash
440
- * GET /wallet/btc?mode=txHash&network=&txHash=
441
- */
442
- async getTxByHash(txHash, network) {
443
- const qs = new URLSearchParams({
444
- mode: "txHash",
445
- network,
446
- txHash
447
- }).toString();
448
- return this.client.get(
449
- `${TALKEN_API_ENDPOINTS.WALLET_BTC}?${qs}`
450
- );
451
- }
452
- /**
453
- * BTC UTXO list
454
- * GET /wallet/btc?mode=utxos&network=&address=
455
- */
456
- async getUtxos(network, address) {
457
- const qs = new URLSearchParams({
458
- mode: "utxos",
459
- network,
460
- ...address ? { address } : {}
461
- }).toString();
462
- return this.client.get(
463
- `${TALKEN_API_ENDPOINTS.WALLET_BTC}?${qs}`
464
- );
465
- }
466
- /**
467
- * BTC address validation
468
- * GET /wallet/btc?mode=validateAddress&network=&address=
469
- */
470
- async validateAddress(address, network) {
471
- const qs = new URLSearchParams({
472
- mode: "validateAddress",
473
- network,
474
- address
475
- }).toString();
476
- return this.client.get(
477
- `${TALKEN_API_ENDPOINTS.WALLET_BTC}?${qs}`
478
- );
479
- }
480
- /**
481
- * Send BTC (integrated sign + broadcast, action=transfer)
482
- * POST /wallet/tx/btc
483
- */
484
- async sendTransaction(params) {
485
- const payload = { action: "transfer", ...params };
486
- return this.client.post(
487
- TALKEN_API_ENDPOINTS.TX_BTC,
488
- withCachedEvmCreds(payload)
489
- );
490
- }
491
- /**
492
- * Execute BTC action endpoint (transfer|generate|signHash|finalize)
493
- * POST /wallet/tx/btc
494
- */
495
- async execute(params) {
496
- return this.client.post(
497
- TALKEN_API_ENDPOINTS.TX_BTC,
498
- withCachedEvmCreds(params)
499
- );
500
- }
501
- /**
502
- * Sign raw hash via secp256k1 MPC (universal: EVM/BTC/TVM)
503
- * POST /wallet/sign/hash { hash, pin, network? }
504
- */
505
- async signHash(params) {
506
- return this.client.post(
507
- TALKEN_API_ENDPOINTS.SIGN_HASH,
508
- withCachedEvmCreds(params)
509
- );
510
- }
511
- /**
512
- * Broadcast raw BTC transaction
513
- * POST /wallet/tx/raw { network, signedSerializeTx }
514
- */
515
- async broadcastRawTransaction(params) {
516
- return this.client.post(TALKEN_API_ENDPOINTS.TX_RAW, {
517
- network: params.network,
518
- signedSerializeTx: params.rawTransaction
519
- });
520
- }
521
- };
522
- var TalkenTronModule = class {
523
- constructor(client) {
524
- this.client = client;
525
- }
526
- /**
527
- * Execute TVM(TRON) transfer/call (integrated sign + broadcast)
528
- * POST /wallet/tx/tvm
529
- * - kind=native: TRX transfer (amountSun)
530
- * - kind=trc20: TRC-20 transfer (contractAddress + amount)
531
- * - kind=contract: arbitrary contract call (contractAddress + data)
532
- */
533
- async transferTrx(params) {
534
- return this.client.post(
535
- TALKEN_API_ENDPOINTS.TX_TVM,
536
- params
537
- );
538
- }
539
- };
540
- var TalkenWalletscanModule = class {
541
- constructor(client) {
542
- this.client = client;
543
- }
544
- /**
545
- * Get all wallet tokens with balances
546
- * GET /wallet/scan?type=tokens&chainKeys=...&walletAddress=...
547
- */
548
- async getTokens(params) {
549
- const qs = new URLSearchParams({
550
- type: "tokens",
551
- chainKeys: params.chainKeys,
552
- walletAddress: params.walletAddress
553
- }).toString();
554
- return this.client.get(
555
- `${TALKEN_API_ENDPOINTS.WALLET_SCAN}?${qs}`
556
- );
557
- }
558
- /**
559
- * Get token metadata by contract address
560
- * GET /wallet/scan?type=tokens&chainKeys=...&contractAddress=...
561
- */
562
- async getToken(params) {
563
- const qs = new URLSearchParams({
564
- type: "tokens",
565
- chainKeys: params.chainKeys,
566
- contractAddress: params.contractAddress
567
- }).toString();
568
- return this.client.get(
569
- `${TALKEN_API_ENDPOINTS.WALLET_SCAN}?${qs}`
570
- );
571
- }
572
- /**
573
- * Get native coin balances
574
- * GET /wallet/scan?type=natives&chainKeys=...&walletAddress=...
575
- */
576
- async getNativeTokens(params) {
577
- const qs = new URLSearchParams({
578
- type: "natives",
579
- chainKeys: params.chainKeys,
580
- walletAddress: params.walletAddress
581
- }).toString();
582
- return this.client.get(
583
- `${TALKEN_API_ENDPOINTS.WALLET_SCAN}?${qs}`
584
- );
585
- }
586
- /**
587
- * Get NFT metadata
588
- * GET /wallet/scan?type=nfts&chainKeys=...&walletAddress=...
589
- */
590
- async getNfts(params) {
591
- const qs = new URLSearchParams({
592
- type: "nfts",
593
- chainKeys: params.chainKeys,
594
- walletAddress: params.walletAddress
595
- }).toString();
596
- return this.client.get(
597
- `${TALKEN_API_ENDPOINTS.WALLET_SCAN}?${qs}`
598
- );
599
- }
600
- };
601
- var TalkenApiClient = class {
602
- constructor(config) {
603
- this.accessToken = null;
604
- this.refreshToken_ = null;
605
- this.expiresAt = null;
606
- this.isRefreshing = false;
607
- this.refreshPromise = null;
608
- this.config = {
609
- baseUrl: config?.baseUrl || DEFAULT_TALKEN_API_CONFIG.baseUrl || "",
610
- timeout: config?.timeout || DEFAULT_TALKEN_API_CONFIG.timeout,
611
- environment: config?.environment || "development",
612
- defaultChainId: config?.defaultChainId,
613
- debug: config?.debug || false
614
- };
615
- this.auth = new TalkenAuthModule(this);
616
- this.wallet = new TalkenWalletModule(this);
617
- this.evm = new TalkenEvmModule(this);
618
- this.solana = new TalkenSolanaModule(this);
619
- this.bitcoin = new TalkenBitcoinModule(this);
620
- this.tron = new TalkenTronModule(this);
621
- this.walletscan = new TalkenWalletscanModule(this);
622
- this.restoreSession();
623
- }
624
- // ── Session Management ──────────────────────────────────────────────
625
- restoreSession() {
626
- this.accessToken = loadToken("access_token");
627
- this.refreshToken_ = loadToken("refresh_token");
628
- const expiresAtStr = loadToken("expires_at");
629
- this.expiresAt = expiresAtStr ? Number(expiresAtStr) : null;
630
- }
631
- /** @internal Called by auth module after successful login/register */
632
- handleAuthResponse(response) {
633
- this.accessToken = response.accessToken;
634
- this.refreshToken_ = response.refreshToken;
635
- this.expiresAt = Date.now() + response.expiresIn * 1e3;
636
- saveToken("access_token", response.accessToken);
637
- saveToken("refresh_token", response.refreshToken);
638
- saveToken("expires_at", String(this.expiresAt));
639
- }
640
- /** @internal Clear all session data */
641
- clearSession() {
642
- this.accessToken = null;
643
- this.refreshToken_ = null;
644
- this.expiresAt = null;
645
- removeToken("access_token");
646
- removeToken("refresh_token");
647
- removeToken("expires_at");
648
- }
649
- /**
650
- * Check if user is authenticated (has valid access token)
651
- */
652
- isAuthenticated() {
653
- return !!this.accessToken && !this.isTokenExpired();
654
- }
655
- /**
656
- * Check if current access token is expired
657
- */
658
- isTokenExpired() {
659
- if (!this.expiresAt)
660
- return true;
661
- return Date.now() >= this.expiresAt - TOKEN_EXPIRY.REFRESH_BUFFER;
662
- }
663
- /**
664
- * Get current access token
665
- */
666
- getAccessToken() {
667
- return this.accessToken;
668
- }
669
- /**
670
- * Get current refresh token
671
- * @internal Used by auth module for token refresh
672
- */
673
- getRefreshToken() {
674
- return this.refreshToken_;
675
- }
676
- /**
677
- * Get client configuration
678
- */
679
- getConfig() {
680
- return { ...this.config };
681
- }
682
- /**
683
- * Set tokens externally (useful for SSR or state management integration)
684
- */
685
- setTokens(accessToken, refreshToken, expiresAt) {
686
- this.accessToken = accessToken;
687
- this.refreshToken_ = refreshToken;
688
- this.expiresAt = expiresAt;
689
- saveToken("access_token", accessToken);
690
- saveToken("refresh_token", refreshToken);
691
- saveToken("expires_at", String(expiresAt));
692
- }
693
- // ── HTTP Methods (Internal) ─────────────────────────────────────────
694
- /** @internal Make a GET request */
695
- async get(endpoint, options) {
696
- return this.request(endpoint, { method: "GET", ...options });
697
- }
698
- /** @internal Make a POST request */
699
- async post(endpoint, body, options) {
700
- return this.request(endpoint, { method: "POST", body, ...options });
701
- }
702
- /**
703
- * Core HTTP request handler with automatic token refresh
704
- * @internal
705
- */
706
- async request(endpoint, options) {
707
- const { method, body, skipAuth = false } = options;
708
- if (!skipAuth && this.isTokenExpired() && this.refreshToken_) {
709
- await this.ensureTokenRefreshed();
710
- }
711
- const url = `${this.config.baseUrl}${endpoint}`;
712
- const headers = {
713
- "Content-Type": "application/json",
714
- Accept: "application/json"
715
- };
716
- if (!skipAuth && this.accessToken) {
717
- headers.Authorization = `Bearer ${this.accessToken}`;
718
- }
719
- if (this.config.debug) {
720
- console.log(`[TalkenApiClient] ${method} ${url}`);
721
- }
722
- try {
723
- const controller = new AbortController();
724
- const timeoutId = setTimeout(
725
- () => controller.abort(),
726
- this.config.timeout || 3e4
727
- );
728
- const response = await fetch(url, {
729
- method,
730
- headers,
731
- body: body ? JSON.stringify(body) : void 0,
732
- signal: controller.signal,
733
- credentials: "include"
734
- });
735
- clearTimeout(timeoutId);
736
- const text = await response.text();
737
- let data;
738
- if (text) {
739
- try {
740
- data = JSON.parse(text);
741
- } catch {
742
- throw new TalkenApiError(
743
- "PARSE_ERROR",
744
- "Invalid JSON response from server",
745
- response.status,
746
- { text: text.substring(0, 200) }
747
- );
748
- }
749
- } else {
750
- data = { success: true };
751
- }
752
- if (response.status === 401 && !skipAuth && this.refreshToken_) {
753
- try {
754
- await this.forceTokenRefresh();
755
- return this.request(endpoint, { ...options, skipAuth: true });
756
- } catch {
757
- this.clearSession();
758
- throw new TalkenApiError(
759
- "TOKEN_EXPIRED",
760
- "Session expired. Please login again.",
761
- 401
762
- );
763
- }
764
- }
765
- if (!response.ok) {
766
- const errCode = data.error?.code || "UNKNOWN_ERROR";
767
- const errMsg = data.error?.message || `Request failed with status ${response.status}`;
768
- if (this.config.debug) {
769
- console.error(`[TalkenApiClient] Error: ${errCode} - ${errMsg}`);
770
- }
771
- throw new TalkenApiError(
772
- errCode,
773
- errMsg,
774
- response.status,
775
- data.error?.details || data.details
776
- );
777
- }
778
- return data.data ?? data;
779
- } catch (error) {
780
- if (error instanceof TalkenApiError) {
781
- throw error;
782
- }
783
- if (error instanceof DOMException && error.name === "AbortError") {
784
- throw new TalkenApiError("TIMEOUT", "Request timed out", 408);
785
- }
786
- const errorMessage = error instanceof Error ? error.message : "Network request failed";
787
- throw new TalkenApiError("NETWORK_ERROR", errorMessage, 0);
788
- }
789
- }
790
- /**
791
- * Ensure token is refreshed (handles concurrent requests)
792
- */
793
- async ensureTokenRefreshed() {
794
- if (this.isRefreshing && this.refreshPromise) {
795
- await this.refreshPromise;
796
- return;
797
- }
798
- await this.forceTokenRefresh();
799
- }
800
- /**
801
- * Force a token refresh
802
- */
803
- async forceTokenRefresh() {
804
- if (this.isRefreshing && this.refreshPromise) {
805
- await this.refreshPromise;
806
- return;
807
- }
808
- this.isRefreshing = true;
809
- this.refreshPromise = (async () => {
810
- try {
811
- await this.auth.refresh();
812
- } finally {
813
- this.isRefreshing = false;
814
- this.refreshPromise = null;
815
- }
816
- })();
817
- await this.refreshPromise;
818
- }
819
- };
820
- function createTalkenApiClient(config) {
821
- return new TalkenApiClient(config);
822
- }
823
-
824
- export {
825
- TalkenApiClient,
826
- createTalkenApiClient
827
- };