@talken/talkenkit 2.8.4 → 2.8.5

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 (99) hide show
  1. package/dist/{AbcCredentialManager-QM2BNLSR.js → AbcCredentialManager-WZBF3GHF.js} +1 -1
  2. package/dist/{abcWallet-4PXYWHYM.js → abcWallet-EOHU5AIB.js} +2 -2
  3. package/dist/{chunk-PS5CBMY5.js → chunk-CUPPBGFC.js} +13 -6
  4. package/dist/{chunk-ZISAJ7BZ.js → chunk-WGSS57V6.js} +998 -453
  5. package/dist/config/networks.d.ts +12 -0
  6. package/dist/gasless/utils/revokeDelegation.d.ts +4 -3
  7. package/dist/index.js +27 -21
  8. package/dist/utils/amount.d.ts +17 -0
  9. package/dist/wallets/walletConnectors/abcWallet/AbcCredentialManager.js +3 -3
  10. package/dist/wallets/walletConnectors/abcWallet/AbcEvmAutoConnector.js +4 -4
  11. package/dist/wallets/walletConnectors/abcWallet/ProviderError.d.ts +7 -0
  12. package/dist/wallets/walletConnectors/abcWallet/StorageService.js +2 -2
  13. package/dist/wallets/walletConnectors/abcWallet/abcBitcoinConnector.js +5 -5
  14. package/dist/wallets/walletConnectors/abcWallet/abcBitcoinProvider.js +13 -4
  15. package/dist/wallets/walletConnectors/abcWallet/abcConnector.js +19 -18
  16. package/dist/wallets/walletConnectors/abcWallet/abcProvider.d.ts +3 -4
  17. package/dist/wallets/walletConnectors/abcWallet/abcProvider.js +9 -6
  18. package/dist/wallets/walletConnectors/abcWallet/abcSolanaProvider.js +21 -19
  19. package/dist/wallets/walletConnectors/abcWallet/abcSolanaWalletAdapter.js +3 -3
  20. package/dist/wallets/walletConnectors/abcWallet/abcTronProvider.d.ts +1 -1
  21. package/dist/wallets/walletConnectors/abcWallet/abcTronProvider.js +13 -4
  22. package/dist/wallets/walletConnectors/abcWallet/abcWallet.js +20 -19
  23. package/dist/wallets/walletConnectors/abcWallet/abcXrplProvider.d.ts +18 -1
  24. package/dist/wallets/walletConnectors/abcWallet/abcXrplProvider.js +17 -6
  25. package/dist/wallets/walletConnectors/abcWallet/api/ConfigApi.js +2 -2
  26. package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiClient.js +16 -15
  27. package/dist/wallets/walletConnectors/abcWallet/api/TokenApi.js +2 -2
  28. package/dist/wallets/walletConnectors/abcWallet/api/WalletscanApi.js +3 -3
  29. package/dist/wallets/walletConnectors/abcWallet/api/index.js +21 -20
  30. package/dist/wallets/walletConnectors/abcWallet/api/modules/auth.js +3 -3
  31. package/dist/wallets/walletConnectors/abcWallet/api/modules/bitcoin.d.ts +16 -2
  32. package/dist/wallets/walletConnectors/abcWallet/api/modules/bitcoin.js +9 -8
  33. package/dist/wallets/walletConnectors/abcWallet/api/modules/evm.d.ts +19 -3
  34. package/dist/wallets/walletConnectors/abcWallet/api/modules/evm.js +8 -7
  35. package/dist/wallets/walletConnectors/abcWallet/api/modules/executeBodies.d.ts +79 -0
  36. package/dist/wallets/walletConnectors/abcWallet/api/modules/executeBodies.js +32 -0
  37. package/dist/wallets/walletConnectors/abcWallet/api/modules/signBodies.d.ts +4 -1
  38. package/dist/wallets/walletConnectors/abcWallet/api/modules/signBodies.js +6 -2
  39. package/dist/wallets/walletConnectors/abcWallet/api/modules/signingRefresh.d.ts +6 -2
  40. package/dist/wallets/walletConnectors/abcWallet/api/modules/signingRefresh.js +5 -5
  41. package/dist/wallets/walletConnectors/abcWallet/api/modules/solana.d.ts +9 -3
  42. package/dist/wallets/walletConnectors/abcWallet/api/modules/solana.js +5 -4
  43. package/dist/wallets/walletConnectors/abcWallet/api/modules/tron.d.ts +10 -4
  44. package/dist/wallets/walletConnectors/abcWallet/api/modules/tron.js +13 -2
  45. package/dist/wallets/walletConnectors/abcWallet/api/modules/wallet.js +2 -2
  46. package/dist/wallets/walletConnectors/abcWallet/api/modules/walletscan.js +2 -2
  47. package/dist/wallets/walletConnectors/abcWallet/api/modules/xrp.d.ts +13 -3
  48. package/dist/wallets/walletConnectors/abcWallet/api/modules/xrp.js +13 -2
  49. package/dist/wallets/walletConnectors/abcWallet/constants.d.ts +17 -5
  50. package/dist/wallets/walletConnectors/abcWallet/constants.js +3 -1
  51. package/dist/wallets/walletConnectors/abcWallet/index.js +36 -34
  52. package/dist/wallets/walletConnectors/abcWallet/sendFailure.d.ts +10 -0
  53. package/dist/wallets/walletConnectors/abcWallet/sendFailure.js +7 -0
  54. package/dist/wallets/walletConnectors/abcWallet/sessionUtils.js +3 -3
  55. package/dist/wallets/walletConnectors/abcWallet/types/api.types.d.ts +76 -1
  56. package/dist/wallets/walletConnectors/abcWallet/types/config.types.d.ts +4 -0
  57. package/dist/wallets/walletConnectors/abcWallet/types/error.types.d.ts +14 -1
  58. package/dist/wallets/walletConnectors/abcWallet/types/error.types.js +1 -1
  59. package/dist/wallets/walletConnectors/abcWallet/types.js +5 -5
  60. package/dist/wallets/walletConnectors/abcWallet/utils.js +4 -4
  61. package/dist/wallets/walletConnectors/abcWallet/walletGeneration.js +5 -5
  62. package/dist/wallets/walletConnectors/{chunk-KX3IFHJQ.js → chunk-2M6E3YXU.js} +28 -16
  63. package/dist/wallets/walletConnectors/{chunk-DPYQH3WE.js → chunk-365TL36N.js} +36 -31
  64. package/dist/wallets/walletConnectors/{chunk-CCUNTMLD.js → chunk-4CKIGJZD.js} +8 -8
  65. package/dist/wallets/walletConnectors/{chunk-XQTK7NGN.js → chunk-5SRSGEZR.js} +2 -2
  66. package/dist/wallets/walletConnectors/{chunk-HFW2XV2R.js → chunk-6MZWQBNQ.js} +28 -7
  67. package/dist/wallets/walletConnectors/chunk-6X2XITQP.js +71 -0
  68. package/dist/wallets/walletConnectors/{chunk-F6EG7H2O.js → chunk-743DKBGG.js} +2 -2
  69. package/dist/wallets/walletConnectors/chunk-DFG3BSSC.js +341 -0
  70. package/dist/wallets/walletConnectors/{chunk-ZTIRW7TR.js → chunk-DKMR2ML5.js} +3 -1
  71. package/dist/wallets/walletConnectors/{chunk-TXB6KXPR.js → chunk-DRL2CDHT.js} +24 -22
  72. package/dist/wallets/walletConnectors/{chunk-HXYOWG5P.js → chunk-EGLT3GPM.js} +1 -1
  73. package/dist/wallets/walletConnectors/{chunk-YECMDMEA.js → chunk-F4JUKZBB.js} +3 -3
  74. package/dist/wallets/walletConnectors/chunk-GAJ4FJTW.js +382 -0
  75. package/dist/wallets/walletConnectors/{chunk-UNLWNVSN.js → chunk-GO6HUJTP.js} +39 -10
  76. package/dist/wallets/walletConnectors/{chunk-5E7TNMON.js → chunk-HMIFFMGK.js} +18 -7
  77. package/dist/wallets/walletConnectors/chunk-M4SNNQU2.js +56 -0
  78. package/dist/wallets/walletConnectors/{chunk-6LPMWYFM.js → chunk-MNGSJBPX.js} +31 -14
  79. package/dist/wallets/walletConnectors/{chunk-6HR6CEOY.js → chunk-OMZSFUVN.js} +1 -1
  80. package/dist/wallets/walletConnectors/{chunk-75H6DQT6.js → chunk-OTLPTGHO.js} +1 -1
  81. package/dist/wallets/walletConnectors/{chunk-OEZE4GBQ.js → chunk-P64PMEPU.js} +2 -2
  82. package/dist/wallets/walletConnectors/{chunk-F6AHT6K4.js → chunk-PL56SINL.js} +1 -1
  83. package/dist/wallets/walletConnectors/{chunk-YUBS7MJ6.js → chunk-RSR35XOZ.js} +47 -12
  84. package/dist/wallets/walletConnectors/{chunk-5SHN7JNR.js → chunk-SORKIBWX.js} +1 -1
  85. package/dist/wallets/walletConnectors/{chunk-CIAVEXOY.js → chunk-SUPFF4EQ.js} +37 -811
  86. package/dist/wallets/walletConnectors/{chunk-BUAWEYGV.js → chunk-TP4BDK7W.js} +5 -1
  87. package/dist/wallets/walletConnectors/{chunk-FWKMNVWU.js → chunk-TRFREYPH.js} +1 -1
  88. package/dist/wallets/walletConnectors/{chunk-RQYBKCWA.js → chunk-UHVJ6AF6.js} +1 -1
  89. package/dist/wallets/walletConnectors/{chunk-ZITVWA4X.js → chunk-V6R6WDOQ.js} +1 -1
  90. package/dist/wallets/walletConnectors/chunk-XGQUYXTL.js +1215 -0
  91. package/dist/wallets/walletConnectors/{chunk-7GBAUSQJ.js → chunk-XPZCOEQL.js} +13 -6
  92. package/dist/wallets/walletConnectors/{chunk-QTBJ6WNZ.js → chunk-YPMD3ZHF.js} +33 -18
  93. package/dist/wallets/walletConnectors/chunk-Z66ETAKN.js +20 -0
  94. package/dist/wallets/walletConnectors/{chunk-HMMEOZDT.js → chunk-ZBI7MSWF.js} +5 -5
  95. package/dist/wallets/walletConnectors/chunk-ZWIAZOVB.js +58 -0
  96. package/dist/wallets/walletConnectors/index.js +51 -50
  97. package/package.json +1 -1
  98. package/dist/wallets/walletConnectors/chunk-6BHMNR5X.js +0 -46
  99. package/dist/wallets/walletConnectors/chunk-FLBJ7T4Q.js +0 -44
@@ -1,7 +1,14 @@
1
1
  "use client";
2
+ import {
3
+ sendFailure
4
+ } from "./chunk-Z66ETAKN.js";
5
+ import {
6
+ NATIVE_DECIMALS,
7
+ toBaseUnits
8
+ } from "./chunk-XGQUYXTL.js";
2
9
  import {
3
10
  getCredentialManager
4
- } from "./chunk-5SHN7JNR.js";
11
+ } from "./chunk-SORKIBWX.js";
5
12
  import {
6
13
  AbstractChainProvider
7
14
  } from "./chunk-3DHUDD4U.js";
@@ -191,6 +198,11 @@ ${msgBytes.length}`
191
198
  "Wallet not connected"
192
199
  );
193
200
  }
201
+ const txType = params.contractAddress ? "TRC20" : "NATIVE";
202
+ const amountRaw = toBaseUnits(
203
+ params.amount,
204
+ txType === "NATIVE" ? NATIVE_DECIMALS.tron : params.decimals
205
+ ).toString();
194
206
  try {
195
207
  const tokenMetadata = await this.fetchTokenMetadata(
196
208
  params.contractAddress
@@ -217,22 +229,7 @@ ${msgBytes.length}`
217
229
  "PIN hash not found. Please login again."
218
230
  );
219
231
  }
220
- const txType = params.contractAddress ? "TRC20" : "NATIVE";
221
- let amountRaw;
222
- if (txType === "NATIVE") {
223
- amountRaw = Math.floor(
224
- Number.parseFloat(params.amount) * 1e6
225
- ).toString();
226
- logger.debug(`Converting ${params.amount} TRX -> ${amountRaw} SUN`);
227
- } else {
228
- const decimals = params.decimals ?? 6;
229
- amountRaw = Math.floor(
230
- Number.parseFloat(params.amount) * 10 ** decimals
231
- ).toString();
232
- logger.debug(
233
- `Converting ${params.amount} -> ${amountRaw} (decimals: ${decimals})`
234
- );
235
- }
232
+ logger.debug(`Converted ${params.amount} -> ${amountRaw} base units`);
236
233
  const email = getCredentialManager().getEmail() || void 0;
237
234
  const request = txType === "NATIVE" ? {
238
235
  kind: "native",
@@ -248,6 +245,7 @@ ${msgBytes.length}`
248
245
  toAddress: params.toAddress,
249
246
  contractAddress: params.contractAddress,
250
247
  amount: amountRaw,
248
+ decimals: params.decimals,
251
249
  feeLimit: params.feeLimit,
252
250
  pin: pinHash || void 0,
253
251
  waitForConfirmation: true,
@@ -282,15 +280,19 @@ ${msgBytes.length}`
282
280
  errorMessage: error.message
283
281
  });
284
282
  if (error.message?.includes("insufficient")) {
285
- throw new TronProviderError(
286
- ProviderErrorCode.INSUFFICIENT_FUNDS,
283
+ throw sendFailure(
284
+ (message, cause) => new TronProviderError(
285
+ ProviderErrorCode.INSUFFICIENT_FUNDS,
286
+ message,
287
+ cause
288
+ ),
287
289
  "Insufficient TRX balance",
288
290
  error
289
291
  );
290
292
  }
291
293
  this.emit("error", error);
292
- throw new TronProviderError(
293
- ProviderErrorCode.INTERNAL_ERROR,
294
+ throw sendFailure(
295
+ (message, cause) => new TronProviderError(ProviderErrorCode.INTERNAL_ERROR, message, cause),
294
296
  error.message || "Failed to send TRON transaction",
295
297
  error
296
298
  );
@@ -317,7 +319,7 @@ ${msgBytes.length}`
317
319
  const blockNumber = info?.blockNumber ?? info?.result?.blockNumber ?? null;
318
320
  const rcpt = info?.receipt ?? info?.result?.receipt;
319
321
  const ret = tx?.ret ?? tx?.result?.ret;
320
- const contractRet = Array.isArray(ret) ? ret[0]?.contractRet : void 0;
322
+ const contractRet = (Array.isArray(ret) ? ret[0]?.contractRet : void 0) ?? rcpt?.result;
321
323
  receipt = {
322
324
  status: contractRet === "SUCCESS" ? 1 : contractRet ? 0 : null,
323
325
  blockNumber,
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import {
3
3
  TokenApi
4
- } from "./chunk-RQYBKCWA.js";
4
+ } from "./chunk-UHVJ6AF6.js";
5
5
  import {
6
6
  createLogger
7
7
  } from "./chunk-2DFJ6LEN.js";
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import {
3
3
  AbcError
4
- } from "./chunk-BUAWEYGV.js";
4
+ } from "./chunk-TP4BDK7W.js";
5
5
  import {
6
6
  STORAGE_NS,
7
7
  clearNamespace,
@@ -9,11 +9,11 @@ import {
9
9
  remove,
10
10
  set,
11
11
  setJSON
12
- } from "./chunk-ZITVWA4X.js";
12
+ } from "./chunk-V6R6WDOQ.js";
13
13
  import {
14
14
  PIN_CONFIG,
15
15
  TOKEN_EXPIRY
16
- } from "./chunk-7GBAUSQJ.js";
16
+ } from "./chunk-XPZCOEQL.js";
17
17
 
18
18
  // src/wallets/walletConnectors/abcWallet/utils.ts
19
19
  function validatePin(pin) {
@@ -0,0 +1,382 @@
1
+ "use client";
2
+ import {
3
+ TalkenSolanaModule
4
+ } from "./chunk-HMIFFMGK.js";
5
+ import {
6
+ TalkenTronModule
7
+ } from "./chunk-6X2XITQP.js";
8
+ import {
9
+ TalkenWalletModule
10
+ } from "./chunk-OMZSFUVN.js";
11
+ import {
12
+ TalkenWalletscanModule
13
+ } from "./chunk-PL56SINL.js";
14
+ import {
15
+ TalkenXrpModule
16
+ } from "./chunk-6MZWQBNQ.js";
17
+ import {
18
+ TalkenAuthModule
19
+ } from "./chunk-P64PMEPU.js";
20
+ import {
21
+ TalkenBitcoinModule
22
+ } from "./chunk-GO6HUJTP.js";
23
+ import {
24
+ TalkenEvmModule
25
+ } from "./chunk-RSR35XOZ.js";
26
+ import {
27
+ createLogger
28
+ } from "./chunk-2DFJ6LEN.js";
29
+ import {
30
+ TalkenApiError
31
+ } from "./chunk-TP4BDK7W.js";
32
+ import {
33
+ STORAGE_NS,
34
+ get,
35
+ remove,
36
+ set
37
+ } from "./chunk-V6R6WDOQ.js";
38
+ import {
39
+ DEFAULT_TALKEN_API_CONFIG,
40
+ TOKEN_EXPIRY,
41
+ loadTgAccessKey
42
+ } from "./chunk-XPZCOEQL.js";
43
+
44
+ // src/wallets/walletConnectors/abcWallet/api/TalkenApiClient.ts
45
+ var logger = createLogger("TalkenApiClient");
46
+ function loadToken(key) {
47
+ return get(STORAGE_NS.API, key);
48
+ }
49
+ function saveToken(key, value) {
50
+ set(STORAGE_NS.API, key, value);
51
+ }
52
+ function removeToken(key) {
53
+ remove(STORAGE_NS.API, key);
54
+ }
55
+ function errorOutcome(error, details) {
56
+ const fromDetails = typeof details === "object" && details !== null ? details.possibleTxHash : void 0;
57
+ const hash = error?.possibleTxHash ?? fromDetails;
58
+ return {
59
+ ...typeof error?.retryable === "boolean" && {
60
+ retryable: error.retryable
61
+ },
62
+ ...typeof hash === "string" && hash !== "" && { possibleTxHash: hash }
63
+ };
64
+ }
65
+ var TalkenApiClient = class _TalkenApiClient {
66
+ constructor(config) {
67
+ this.accessToken = null;
68
+ this.refreshToken_ = null;
69
+ this.expiresAt = null;
70
+ this.accessKeyRaw = null;
71
+ this.isRefreshing = false;
72
+ this.refreshPromise = null;
73
+ this.config = {
74
+ baseUrl: config?.baseUrl || DEFAULT_TALKEN_API_CONFIG.baseUrl || "",
75
+ timeout: config?.timeout || DEFAULT_TALKEN_API_CONFIG.timeout,
76
+ environment: config?.environment || "development",
77
+ defaultChainId: config?.defaultChainId,
78
+ debug: config?.debug || false
79
+ };
80
+ this.auth = new TalkenAuthModule(this);
81
+ this.wallet = new TalkenWalletModule(this);
82
+ this.evm = new TalkenEvmModule(this);
83
+ this.solana = new TalkenSolanaModule(this);
84
+ this.bitcoin = new TalkenBitcoinModule(this);
85
+ this.tron = new TalkenTronModule(this);
86
+ this.xrp = new TalkenXrpModule(this);
87
+ this.walletscan = new TalkenWalletscanModule(this);
88
+ this.restoreSession();
89
+ }
90
+ // ── Session Management ──────────────────────────────────────────────
91
+ restoreSession() {
92
+ this.accessKeyRaw = loadToken("access_key_raw");
93
+ if (this.accessKeyRaw) {
94
+ return;
95
+ }
96
+ this.accessToken = loadToken("access_token");
97
+ this.refreshToken_ = loadToken("refresh_token");
98
+ const expiresAtStr = loadToken("expires_at");
99
+ this.expiresAt = expiresAtStr ? Number(expiresAtStr) : null;
100
+ }
101
+ /** @internal Called by auth module after successful login/register */
102
+ handleAuthResponse(response) {
103
+ this.accessToken = response.accessToken;
104
+ this.refreshToken_ = response.refreshToken;
105
+ this.expiresAt = Date.now() + response.expiresIn * 1e3;
106
+ saveToken("access_token", response.accessToken);
107
+ saveToken("refresh_token", response.refreshToken);
108
+ saveToken("expires_at", String(this.expiresAt));
109
+ }
110
+ /** @internal Clear all session data */
111
+ clearSession() {
112
+ this.accessToken = null;
113
+ this.refreshToken_ = null;
114
+ this.expiresAt = null;
115
+ this.accessKeyRaw = null;
116
+ removeToken("access_token");
117
+ removeToken("refresh_token");
118
+ removeToken("expires_at");
119
+ removeToken("access_key_raw");
120
+ }
121
+ static {
122
+ /** All known access key prefixes (any environment). */
123
+ this.KNOWN_AK_PREFIXES = [
124
+ "talken_live_",
125
+ "talken_stg_",
126
+ "talken_dev_",
127
+ "talken_local_"
128
+ ];
129
+ }
130
+ /** Validate access key format: talken_<env>_<publicId>.<secret> */
131
+ static isValidAccessKeyFormat(key) {
132
+ const trimmed = key.trim();
133
+ for (const prefix of _TalkenApiClient.KNOWN_AK_PREFIXES) {
134
+ if (trimmed.startsWith(prefix)) {
135
+ const payload = trimmed.slice(prefix.length);
136
+ const dot = payload.indexOf(".");
137
+ if (dot < 1)
138
+ return false;
139
+ return payload.slice(0, dot).length > 0 && payload.slice(dot + 1).length > 0;
140
+ }
141
+ }
142
+ return false;
143
+ }
144
+ /**
145
+ * Set Access Key and switch to Access Key mode.
146
+ * Accepts any known env prefix (talken_live_, talken_stg_, talken_dev_, talken_local_).
147
+ */
148
+ setAccessKey(key) {
149
+ const trimmed = key.trim();
150
+ if (!_TalkenApiClient.isValidAccessKeyFormat(trimmed)) {
151
+ throw new Error(
152
+ "Invalid access key format. Expected: talken_<env>_<publicId>.<secret>"
153
+ );
154
+ }
155
+ this.accessKeyRaw = trimmed;
156
+ saveToken("access_key_raw", trimmed);
157
+ this.accessToken = null;
158
+ this.refreshToken_ = null;
159
+ this.expiresAt = null;
160
+ removeToken("access_token");
161
+ removeToken("refresh_token");
162
+ removeToken("expires_at");
163
+ }
164
+ /**
165
+ * Clear Access Key
166
+ */
167
+ clearAccessKey() {
168
+ this.accessKeyRaw = null;
169
+ removeToken("access_key_raw");
170
+ }
171
+ /**
172
+ * Check if running in Access Key mode
173
+ */
174
+ isAccessKeyMode() {
175
+ return !!this.accessKeyRaw;
176
+ }
177
+ /**
178
+ * Check if user is authenticated (has valid access token)
179
+ */
180
+ isAuthenticated() {
181
+ if (this.accessKeyRaw)
182
+ return true;
183
+ return !!this.accessToken && !this.isTokenExpired();
184
+ }
185
+ /**
186
+ * Check if current access token is expired
187
+ */
188
+ isTokenExpired() {
189
+ if (!this.expiresAt)
190
+ return true;
191
+ return Date.now() >= this.expiresAt - TOKEN_EXPIRY.REFRESH_BUFFER;
192
+ }
193
+ /**
194
+ * Get current access token
195
+ */
196
+ getAccessToken() {
197
+ return this.accessToken;
198
+ }
199
+ /**
200
+ * Get current refresh token
201
+ * @internal Used by auth module for token refresh
202
+ */
203
+ getRefreshToken() {
204
+ return this.refreshToken_;
205
+ }
206
+ /**
207
+ * Get client configuration
208
+ */
209
+ getConfig() {
210
+ return { ...this.config };
211
+ }
212
+ /**
213
+ * Set tokens externally (useful for SSR or state management integration)
214
+ */
215
+ setTokens(accessToken, refreshToken, expiresAt) {
216
+ this.accessToken = accessToken;
217
+ this.refreshToken_ = refreshToken;
218
+ this.expiresAt = expiresAt;
219
+ saveToken("access_token", accessToken);
220
+ saveToken("refresh_token", refreshToken);
221
+ saveToken("expires_at", String(expiresAt));
222
+ }
223
+ // ── HTTP Methods (Internal) ─────────────────────────────────────────
224
+ /** @internal Make a GET request */
225
+ async get(endpoint, options) {
226
+ return this.request(endpoint, { method: "GET", ...options });
227
+ }
228
+ /** @internal Make a POST request */
229
+ async post(endpoint, body, options) {
230
+ return this.request(endpoint, { method: "POST", body, ...options });
231
+ }
232
+ /**
233
+ * Core HTTP request handler with automatic token refresh
234
+ * @internal
235
+ */
236
+ async request(endpoint, options) {
237
+ const { method, body, skipAuth = false, timeout } = options;
238
+ if (!skipAuth && !this.accessKeyRaw && this.isTokenExpired() && this.refreshToken_) {
239
+ await this.ensureTokenRefreshed();
240
+ }
241
+ const url = `${this.config.baseUrl}${endpoint}`;
242
+ const headers = {
243
+ "Content-Type": "application/json",
244
+ Accept: "application/json"
245
+ };
246
+ if (!skipAuth) {
247
+ if (this.accessKeyRaw) {
248
+ headers["X-Access-Key"] = this.accessKeyRaw;
249
+ } else if (this.accessToken) {
250
+ headers.Authorization = `Bearer ${this.accessToken}`;
251
+ } else {
252
+ const tgAk = loadTgAccessKey();
253
+ if (tgAk) {
254
+ headers["X-Access-Key"] = tgAk;
255
+ }
256
+ }
257
+ }
258
+ if (this.config.debug) {
259
+ logger.debug(`${method} ${url}`);
260
+ }
261
+ try {
262
+ const controller = new AbortController();
263
+ const timeoutId = setTimeout(
264
+ () => controller.abort(),
265
+ timeout || this.config.timeout || 3e4
266
+ );
267
+ const response = await fetch(url, {
268
+ method,
269
+ headers,
270
+ body: body ? JSON.stringify(body) : void 0,
271
+ signal: controller.signal,
272
+ credentials: "include"
273
+ });
274
+ clearTimeout(timeoutId);
275
+ const text = await response.text();
276
+ let data;
277
+ if (text) {
278
+ try {
279
+ data = JSON.parse(text);
280
+ } catch {
281
+ throw new TalkenApiError(
282
+ "PARSE_ERROR",
283
+ "Invalid JSON response from server",
284
+ response.status,
285
+ { text: text.substring(0, 200) }
286
+ );
287
+ }
288
+ } else {
289
+ data = { success: true };
290
+ }
291
+ if (response.status === 401 && !skipAuth) {
292
+ if (this.accessKeyRaw) {
293
+ if (typeof window !== "undefined") {
294
+ window.dispatchEvent(
295
+ new CustomEvent("talkenkit:access_key_expired")
296
+ );
297
+ }
298
+ throw new TalkenApiError(
299
+ "ACCESS_KEY_EXPIRED",
300
+ "Access key expired. Please login again.",
301
+ 401
302
+ );
303
+ }
304
+ if (this.refreshToken_) {
305
+ try {
306
+ await this.forceTokenRefresh();
307
+ return this.request(endpoint, { ...options, skipAuth: true });
308
+ } catch {
309
+ this.clearSession();
310
+ throw new TalkenApiError(
311
+ "TOKEN_EXPIRED",
312
+ "Session expired. Please login again.",
313
+ 401
314
+ );
315
+ }
316
+ }
317
+ }
318
+ if (!response.ok) {
319
+ const errCode = data.error?.code || "UNKNOWN_ERROR";
320
+ const errMsg = data.error?.message || `Request failed with status ${response.status}`;
321
+ if (this.config.debug) {
322
+ logger.error(`Error: ${errCode} - ${errMsg}`);
323
+ }
324
+ const details = data.error?.details || data.details;
325
+ throw new TalkenApiError(
326
+ errCode,
327
+ errMsg,
328
+ response.status,
329
+ details,
330
+ errorOutcome(data.error, details)
331
+ );
332
+ }
333
+ return data.data ?? data;
334
+ } catch (error) {
335
+ if (error instanceof TalkenApiError) {
336
+ throw error;
337
+ }
338
+ if (error instanceof DOMException && error.name === "AbortError") {
339
+ throw new TalkenApiError("TIMEOUT", "Request timed out", 408);
340
+ }
341
+ const errorMessage = error instanceof Error ? error.message : "Network request failed";
342
+ throw new TalkenApiError("NETWORK_ERROR", errorMessage, 0);
343
+ }
344
+ }
345
+ /**
346
+ * Ensure token is refreshed (handles concurrent requests)
347
+ */
348
+ async ensureTokenRefreshed() {
349
+ if (this.isRefreshing && this.refreshPromise) {
350
+ await this.refreshPromise;
351
+ return;
352
+ }
353
+ await this.forceTokenRefresh();
354
+ }
355
+ /**
356
+ * Force a token refresh
357
+ */
358
+ async forceTokenRefresh() {
359
+ if (this.isRefreshing && this.refreshPromise) {
360
+ await this.refreshPromise;
361
+ return;
362
+ }
363
+ this.isRefreshing = true;
364
+ this.refreshPromise = (async () => {
365
+ try {
366
+ await this.auth.refresh();
367
+ } finally {
368
+ this.isRefreshing = false;
369
+ this.refreshPromise = null;
370
+ }
371
+ })();
372
+ await this.refreshPromise;
373
+ }
374
+ };
375
+ function createTalkenApiClient(config) {
376
+ return new TalkenApiClient(config);
377
+ }
378
+
379
+ export {
380
+ TalkenApiClient,
381
+ createTalkenApiClient
382
+ };
@@ -1,16 +1,21 @@
1
1
  "use client";
2
2
  import {
3
3
  withCachedEvmCreds
4
- } from "./chunk-YUBS7MJ6.js";
4
+ } from "./chunk-RSR35XOZ.js";
5
5
  import {
6
6
  withSigningCredentialRefresh
7
- } from "./chunk-FLBJ7T4Q.js";
7
+ } from "./chunk-M4SNNQU2.js";
8
8
  import {
9
+ toBitcoinSendBody
10
+ } from "./chunk-XGQUYXTL.js";
11
+ import {
12
+ badRequest,
9
13
  toSignHashBody
10
- } from "./chunk-ZTIRW7TR.js";
14
+ } from "./chunk-DKMR2ML5.js";
11
15
  import {
16
+ SEND_REQUEST_TIMEOUT,
12
17
  TALKEN_API_ENDPOINTS
13
- } from "./chunk-7GBAUSQJ.js";
18
+ } from "./chunk-XPZCOEQL.js";
14
19
 
15
20
  // src/wallets/walletConnectors/abcWallet/api/modules/bitcoin.ts
16
21
  var TalkenBitcoinModule = class {
@@ -75,20 +80,41 @@ var TalkenBitcoinModule = class {
75
80
  }
76
81
  /**
77
82
  * Send BTC (integrated sign + broadcast, action=transfer)
78
- * POST /wallet/tx/btc
83
+ * POST /execute/send { to, chainKey, amount, feeRate?, pin, email, idempotencyKey }
84
+ * `amountSats` is sent as a BTC `amount` and `network` (required) as the chain
85
+ * key. `waitForConfirmation` is not forwarded: the server's confirmation poll
86
+ * outlasts the client timeout, so the answer is the broadcast `txHash`.
87
+ * A cold server credential cache (502 "Missing required wallet fields",
88
+ * answered before anything is signed, `details.broadcast: false`) is refreshed
89
+ * once and the same request re-sent under the same key. The cached `evmCreds`
90
+ * the legacy route took as its fallback are not accepted by /execute/send.
79
91
  */
80
92
  async sendTransaction(params) {
81
- const payload = { action: "transfer", ...params };
82
- return this.client.post(
83
- TALKEN_API_ENDPOINTS.TX_BTC,
84
- withCachedEvmCreds(payload)
93
+ const body = toBitcoinSendBody(params);
94
+ return withSigningCredentialRefresh(
95
+ this.client,
96
+ () => this.client.post(
97
+ TALKEN_API_ENDPOINTS.EXECUTE_SEND,
98
+ body,
99
+ { timeout: SEND_REQUEST_TIMEOUT }
100
+ ),
101
+ { email: params.email }
85
102
  );
86
103
  }
87
104
  /**
88
- * Execute BTC action endpoint (transfer|generate|signHash|finalize)
105
+ * Execute a BTC action endpoint (generate|finalize)
89
106
  * POST /wallet/tx/btc
107
+ *
108
+ * @deprecated No /execute/* successor for the generate and finalize steps; stays
109
+ * on /wallet/tx/btc until its 2027-03-10 sunset. Use `sendTransaction` to send
110
+ * and `signHash` to sign.
90
111
  */
91
112
  async execute(params) {
113
+ if (params.action !== "generate" && params.action !== "finalize") {
114
+ throw badRequest(
115
+ "execute supports only action=generate or finalize; use sendTransaction to send and signHash to sign"
116
+ );
117
+ }
92
118
  return this.client.post(
93
119
  TALKEN_API_ENDPOINTS.TX_BTC,
94
120
  withCachedEvmCreds(params)
@@ -111,6 +137,9 @@ var TalkenBitcoinModule = class {
111
137
  /**
112
138
  * Broadcast raw BTC transaction
113
139
  * POST /wallet/tx/raw { network, signedSerializeTx }
140
+ *
141
+ * @deprecated No /execute/* successor (/execute/broadcast answers 501 for
142
+ * Bitcoin); stays on /wallet/tx/raw until its 2027-03-10 sunset.
114
143
  */
115
144
  async broadcastRawTransaction(params) {
116
145
  return this.client.post(TALKEN_API_ENDPOINTS.TX_RAW, {
@@ -1,10 +1,14 @@
1
1
  "use client";
2
+ import {
3
+ toSolanaSendBody
4
+ } from "./chunk-XGQUYXTL.js";
2
5
  import {
3
6
  toSignSolanaBody
4
- } from "./chunk-ZTIRW7TR.js";
7
+ } from "./chunk-DKMR2ML5.js";
5
8
  import {
9
+ SEND_REQUEST_TIMEOUT,
6
10
  TALKEN_API_ENDPOINTS
7
- } from "./chunk-7GBAUSQJ.js";
11
+ } from "./chunk-XPZCOEQL.js";
8
12
 
9
13
  // src/wallets/walletConnectors/abcWallet/api/modules/solana.ts
10
14
  var TalkenSolanaModule = class {
@@ -31,14 +35,21 @@ var TalkenSolanaModule = class {
31
35
  }
32
36
  /**
33
37
  * Transfer SOL or SPL token (integrated sign + broadcast)
34
- * POST /wallet/tx/sol
35
- * - kind='native': { toAddress, amountLamports, pin }
36
- * - kind='spl': { toAddress, mintAddress, amount, decimals, network, pin }
38
+ * POST /execute/send { to, chainKey, amount, token?, decimals?, pin, ... }
39
+ * - kind='native': `amountLamports` (base units) is sent as a SOL `amount`
40
+ * - kind='spl': `amount` (raw units) and `decimals` are sent as the human
41
+ * `amount` with `token` (the mint) and `decimals`
42
+ * `network` is required and becomes the chain key; `waitForConfirmation` is
43
+ * sent as `waitForReceipt`.
44
+ * Not wrapped in `withSigningCredentialRefresh`: Solana signs with the
45
+ * wallet's encrypted share, not the EVM signing credentials, so the server
46
+ * never answers this send with the cold-credential 502.
37
47
  */
38
48
  async transfer(params) {
39
49
  return this.client.post(
40
- TALKEN_API_ENDPOINTS.TX_SOL,
41
- params
50
+ TALKEN_API_ENDPOINTS.EXECUTE_SEND,
51
+ toSolanaSendBody(params),
52
+ { timeout: SEND_REQUEST_TIMEOUT }
42
53
  );
43
54
  }
44
55
  /**
@@ -0,0 +1,56 @@
1
+ "use client";
2
+ import {
3
+ getCredentialManager
4
+ } from "./chunk-SORKIBWX.js";
5
+ import {
6
+ TalkenApiError
7
+ } from "./chunk-TP4BDK7W.js";
8
+ import {
9
+ TALKEN_API_ENDPOINTS
10
+ } from "./chunk-XPZCOEQL.js";
11
+
12
+ // src/wallets/walletConnectors/abcWallet/api/modules/signingRefresh.ts
13
+ function isSigningCredentialError(error) {
14
+ if (!(error instanceof TalkenApiError) || error.statusCode !== 502 || !error.message.includes("Missing required wallet fields")) {
15
+ return false;
16
+ }
17
+ const broadcast = broadcastMarker(error.details);
18
+ if (broadcast === false)
19
+ return true;
20
+ return !(error.retryable === false || broadcast === "unknown" || isUnconfirmedBroadcastCode(error.code) || error.possibleTxHash !== void 0);
21
+ }
22
+ function isUnconfirmedBroadcastCode(code) {
23
+ return code === "BROADCAST_UNCONFIRMED" || code.endsWith("_BROADCAST_UNCONFIRMED");
24
+ }
25
+ function broadcastMarker(details) {
26
+ return typeof details === "object" && details !== null ? details.broadcast : void 0;
27
+ }
28
+ async function withSigningCredentialRefresh(client, call, options) {
29
+ try {
30
+ return await call();
31
+ } catch (error) {
32
+ if (!isSigningCredentialError(error))
33
+ throw error;
34
+ let pin = null;
35
+ let email = null;
36
+ try {
37
+ const credentials = getCredentialManager();
38
+ pin = credentials.getPinHash();
39
+ email = options?.email || credentials.getEmail();
40
+ } catch {
41
+ }
42
+ if (!pin || !email)
43
+ throw error;
44
+ await client.post(TALKEN_API_ENDPOINTS.WALLET_MPC, {
45
+ action: "create",
46
+ email,
47
+ pin
48
+ });
49
+ return call();
50
+ }
51
+ }
52
+
53
+ export {
54
+ isSigningCredentialError,
55
+ withSigningCredentialRefresh
56
+ };