@talken/talkenkit 2.5.1 → 2.5.3

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