@talken/talkenkit 2.8.4 → 2.8.6

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 (188) hide show
  1. package/dist/{abcWallet-4PXYWHYM.js → abcWallet-RPQPYWWR.js} +22 -25
  2. package/dist/{chunk-ZISAJ7BZ.js → chunk-GS4L4ZIS.js} +3354 -1012
  3. package/dist/config/networks.d.ts +12 -0
  4. package/dist/gasless/index.d.ts +1 -1
  5. package/dist/gasless/services/GaslessTransferService.d.ts +2 -1
  6. package/dist/gasless/signer/AbcWaasSigner.d.ts +9 -0
  7. package/dist/gasless/signer/GaslessSigner.d.ts +10 -0
  8. package/dist/gasless/signer/WagmiSigner.d.ts +40 -0
  9. package/dist/gasless/signer/index.d.ts +1 -1
  10. package/dist/gasless/utils/delegationGuard.d.ts +11 -11
  11. package/dist/gasless/utils/revokeDelegation.d.ts +23 -23
  12. package/dist/hooks/useMultiChainBalances.d.ts +2 -0
  13. package/dist/index.css +17 -15
  14. package/dist/index.d.ts +2 -1
  15. package/dist/index.js +1287 -586
  16. package/dist/services/AbcAuthService.d.ts +12 -1
  17. package/dist/solana/clusterIdentity.d.ts +5 -0
  18. package/dist/utils/amount.d.ts +17 -0
  19. package/dist/wallets/walletConnectors/abcWallet/AbcCredentialManager.d.ts +0 -1
  20. package/dist/wallets/walletConnectors/abcWallet/AbcCredentialManager.js +3 -3
  21. package/dist/wallets/walletConnectors/abcWallet/AbcEvmAutoConnector.js +5 -5
  22. package/dist/wallets/walletConnectors/abcWallet/AbstractChainProvider.d.ts +11 -0
  23. package/dist/wallets/walletConnectors/abcWallet/AbstractChainProvider.js +5 -2
  24. package/dist/wallets/walletConnectors/abcWallet/ProviderError.d.ts +7 -0
  25. package/dist/wallets/walletConnectors/abcWallet/StorageService.js +2 -2
  26. package/dist/wallets/walletConnectors/abcWallet/abcBitcoinConnector.d.ts +2 -0
  27. package/dist/wallets/walletConnectors/abcWallet/abcBitcoinConnector.js +8 -6
  28. package/dist/wallets/walletConnectors/abcWallet/abcBitcoinProvider.d.ts +1 -0
  29. package/dist/wallets/walletConnectors/abcWallet/abcBitcoinProvider.js +16 -6
  30. package/dist/wallets/walletConnectors/abcWallet/abcConnector.js +24 -21
  31. package/dist/wallets/walletConnectors/abcWallet/abcProvider.d.ts +4 -4
  32. package/dist/wallets/walletConnectors/abcWallet/abcProvider.js +13 -9
  33. package/dist/wallets/walletConnectors/abcWallet/abcSolanaProvider.js +28 -24
  34. package/dist/wallets/walletConnectors/abcWallet/abcSolanaWalletAdapter.d.ts +3 -0
  35. package/dist/wallets/walletConnectors/abcWallet/abcSolanaWalletAdapter.js +183 -62
  36. package/dist/wallets/walletConnectors/abcWallet/abcTronProvider.d.ts +2 -1
  37. package/dist/wallets/walletConnectors/abcWallet/abcTronProvider.js +16 -6
  38. package/dist/wallets/walletConnectors/abcWallet/abcWallet.js +25 -22
  39. package/dist/wallets/walletConnectors/abcWallet/abcXrplProvider.d.ts +19 -1
  40. package/dist/wallets/walletConnectors/abcWallet/abcXrplProvider.js +20 -8
  41. package/dist/wallets/walletConnectors/abcWallet/api/AccessKeySessionBinding.d.ts +10 -0
  42. package/dist/wallets/walletConnectors/abcWallet/api/AccessKeySessionBinding.js +13 -0
  43. package/dist/wallets/walletConnectors/abcWallet/api/ConfigApi.js +5 -2
  44. package/dist/wallets/walletConnectors/abcWallet/api/GasApi.js +5 -1
  45. package/dist/wallets/walletConnectors/abcWallet/api/SolanaApi.js +5 -1
  46. package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiClient.d.ts +34 -12
  47. package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiClient.js +20 -16
  48. package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiSingleton.d.ts +6 -0
  49. package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiSingleton.js +10 -1
  50. package/dist/wallets/walletConnectors/abcWallet/api/TokenApi.js +5 -2
  51. package/dist/wallets/walletConnectors/abcWallet/api/WalletscanApi.js +13 -3
  52. package/dist/wallets/walletConnectors/abcWallet/api/index.js +29 -25
  53. package/dist/wallets/walletConnectors/abcWallet/api/modules/auth.d.ts +20 -10
  54. package/dist/wallets/walletConnectors/abcWallet/api/modules/auth.js +4 -4
  55. package/dist/wallets/walletConnectors/abcWallet/api/modules/bitcoin.d.ts +16 -2
  56. package/dist/wallets/walletConnectors/abcWallet/api/modules/bitcoin.js +12 -9
  57. package/dist/wallets/walletConnectors/abcWallet/api/modules/evm.d.ts +20 -4
  58. package/dist/wallets/walletConnectors/abcWallet/api/modules/evm.js +11 -8
  59. package/dist/wallets/walletConnectors/abcWallet/api/modules/executeBodies.d.ts +79 -0
  60. package/dist/wallets/walletConnectors/abcWallet/api/modules/executeBodies.js +33 -0
  61. package/dist/wallets/walletConnectors/abcWallet/api/modules/signBodies.d.ts +4 -1
  62. package/dist/wallets/walletConnectors/abcWallet/api/modules/signBodies.js +7 -3
  63. package/dist/wallets/walletConnectors/abcWallet/api/modules/signingRefresh.d.ts +6 -2
  64. package/dist/wallets/walletConnectors/abcWallet/api/modules/signingRefresh.js +7 -6
  65. package/dist/wallets/walletConnectors/abcWallet/api/modules/solana.d.ts +9 -3
  66. package/dist/wallets/walletConnectors/abcWallet/api/modules/solana.js +7 -5
  67. package/dist/wallets/walletConnectors/abcWallet/api/modules/tron.d.ts +10 -4
  68. package/dist/wallets/walletConnectors/abcWallet/api/modules/tron.js +15 -2
  69. package/dist/wallets/walletConnectors/abcWallet/api/modules/wallet.d.ts +2 -1
  70. package/dist/wallets/walletConnectors/abcWallet/api/modules/wallet.js +2 -2
  71. package/dist/wallets/walletConnectors/abcWallet/api/modules/walletscan.js +2 -2
  72. package/dist/wallets/walletConnectors/abcWallet/api/modules/xrp.d.ts +13 -3
  73. package/dist/wallets/walletConnectors/abcWallet/api/modules/xrp.js +15 -2
  74. package/dist/wallets/walletConnectors/abcWallet/constants.d.ts +17 -5
  75. package/dist/wallets/walletConnectors/abcWallet/constants.js +3 -1
  76. package/dist/wallets/walletConnectors/abcWallet/index.d.ts +1 -0
  77. package/dist/wallets/walletConnectors/abcWallet/index.js +49 -45
  78. package/dist/wallets/walletConnectors/abcWallet/sendFailure.d.ts +10 -0
  79. package/dist/wallets/walletConnectors/abcWallet/sendFailure.js +7 -0
  80. package/dist/wallets/walletConnectors/abcWallet/sessionUtils.js +11 -3
  81. package/dist/wallets/walletConnectors/abcWallet/types/api.types.d.ts +76 -1
  82. package/dist/wallets/walletConnectors/abcWallet/types/auth.types.d.ts +75 -0
  83. package/dist/wallets/walletConnectors/abcWallet/types/config.types.d.ts +4 -0
  84. package/dist/wallets/walletConnectors/abcWallet/types/error.types.d.ts +16 -1
  85. package/dist/wallets/walletConnectors/abcWallet/types/error.types.js +5 -3
  86. package/dist/wallets/walletConnectors/abcWallet/types.js +8 -6
  87. package/dist/wallets/walletConnectors/abcWallet/utils.js +5 -5
  88. package/dist/wallets/walletConnectors/abcWallet/walletGeneration.js +7 -6
  89. package/dist/wallets/walletConnectors/berasigWallet/berasigWallet.js +2 -2
  90. package/dist/wallets/walletConnectors/bifrostWallet/bifrostWallet.js +2 -2
  91. package/dist/wallets/walletConnectors/binanceWallet/binanceWallet.js +2 -2
  92. package/dist/wallets/walletConnectors/bitgetWallet/bitgetWallet.js +2 -2
  93. package/dist/wallets/walletConnectors/bybitWallet/bybitWallet.js +2 -2
  94. package/dist/wallets/walletConnectors/chunk-4K2V7RCL.js +96 -0
  95. package/dist/wallets/walletConnectors/{chunk-CCUNTMLD.js → chunk-4MCD2P7Q.js} +79 -30
  96. package/dist/wallets/walletConnectors/chunk-4UMY2AY7.js +414 -0
  97. package/dist/wallets/walletConnectors/{chunk-YECMDMEA.js → chunk-5IY2JM5V.js} +3 -3
  98. package/dist/wallets/walletConnectors/chunk-5KPLYJOO.js +820 -0
  99. package/dist/wallets/walletConnectors/chunk-64X6Z6JH.js +390 -0
  100. package/dist/wallets/walletConnectors/chunk-74OE3YZX.js +739 -0
  101. package/dist/wallets/walletConnectors/chunk-76M232IF.js +101 -0
  102. package/dist/wallets/walletConnectors/chunk-CEOJSQAI.js +66 -0
  103. package/dist/wallets/walletConnectors/chunk-CMSHILRF.js +71 -0
  104. package/dist/wallets/walletConnectors/chunk-CNKRIZ6T.js +246 -0
  105. package/dist/wallets/walletConnectors/{chunk-5SHN7JNR.js → chunk-CO5DIPSI.js} +4 -5
  106. package/dist/wallets/walletConnectors/chunk-CTAFZ5RQ.js +71 -0
  107. package/dist/wallets/walletConnectors/chunk-DHWJ3552.js +93 -0
  108. package/dist/wallets/walletConnectors/{chunk-6HR6CEOY.js → chunk-DMZ3PH25.js} +7 -3
  109. package/dist/wallets/walletConnectors/{chunk-ZTIRW7TR.js → chunk-DUEQONAP.js} +3 -1
  110. package/dist/wallets/walletConnectors/{chunk-CIAVEXOY.js → chunk-EJWP6MEK.js} +527 -955
  111. package/dist/wallets/walletConnectors/{chunk-5E7TNMON.js → chunk-EMNOGQO2.js} +18 -7
  112. package/dist/wallets/walletConnectors/{chunk-6LPMWYFM.js → chunk-EUHXX2SF.js} +151 -83
  113. package/dist/wallets/walletConnectors/{chunk-OTLZVWY7.js → chunk-EZVOMG73.js} +3 -1
  114. package/dist/wallets/walletConnectors/{chunk-HXYOWG5P.js → chunk-F2OS4PE2.js} +58 -7
  115. package/dist/wallets/walletConnectors/chunk-FE2BFYJB.js +73 -0
  116. package/dist/wallets/walletConnectors/chunk-FGYJTUYV.js +94 -0
  117. package/dist/wallets/walletConnectors/chunk-FVA6H2VF.js +95 -0
  118. package/dist/wallets/walletConnectors/chunk-GNF5CHDQ.js +102 -0
  119. package/dist/wallets/walletConnectors/{chunk-TXB6KXPR.js → chunk-GOUMVJSK.js} +101 -63
  120. package/dist/wallets/walletConnectors/{chunk-DPYQH3WE.js → chunk-GUXCFLV3.js} +130 -72
  121. package/dist/wallets/walletConnectors/chunk-GZPGNUNF.js +94 -0
  122. package/dist/wallets/walletConnectors/chunk-H63QJV3U.js +84 -0
  123. package/dist/wallets/walletConnectors/chunk-HALTGRQW.js +87 -0
  124. package/dist/wallets/walletConnectors/{chunk-F6EG7H2O.js → chunk-ICDXVAE5.js} +72 -20
  125. package/dist/wallets/walletConnectors/{chunk-75H6DQT6.js → chunk-KHBX3RMO.js} +4 -2
  126. package/dist/wallets/walletConnectors/chunk-KNNHGFKJ.js +98 -0
  127. package/dist/wallets/walletConnectors/chunk-KQDFRZT4.js +65 -0
  128. package/dist/wallets/walletConnectors/chunk-KQROIRBW.js +27 -0
  129. package/dist/wallets/walletConnectors/chunk-LKNK2KKU.js +76 -0
  130. package/dist/wallets/walletConnectors/{chunk-HFW2XV2R.js → chunk-LS4W2YJJ.js} +28 -7
  131. package/dist/wallets/walletConnectors/chunk-NM7YUGLV.js +186 -0
  132. package/dist/wallets/walletConnectors/chunk-NVJA6FA7.js +79 -0
  133. package/dist/wallets/walletConnectors/chunk-NXLLPSM4.js +53 -0
  134. package/dist/wallets/walletConnectors/{chunk-HMMEOZDT.js → chunk-PGV5K26R.js} +6 -4
  135. package/dist/wallets/walletConnectors/{chunk-F6AHT6K4.js → chunk-PL56SINL.js} +1 -1
  136. package/dist/wallets/walletConnectors/{chunk-YUBS7MJ6.js → chunk-Q66E4NTB.js} +53 -14
  137. package/dist/wallets/walletConnectors/chunk-QRU6XFHH.js +110 -0
  138. package/dist/wallets/walletConnectors/{chunk-FWKMNVWU.js → chunk-RVLR562W.js} +39 -9
  139. package/dist/wallets/walletConnectors/{chunk-XQTK7NGN.js → chunk-SUMQUG76.js} +35 -10
  140. package/dist/wallets/walletConnectors/chunk-TA4DDCKN.js +96 -0
  141. package/dist/wallets/walletConnectors/chunk-TWVKSPTP.js +91 -0
  142. package/dist/wallets/walletConnectors/chunk-U5UPCM5V.js +66 -0
  143. package/dist/wallets/walletConnectors/{chunk-BUAWEYGV.js → chunk-UVPRZEPJ.js} +10 -2
  144. package/dist/wallets/walletConnectors/chunk-V5LGED4F.js +103 -0
  145. package/dist/wallets/walletConnectors/{chunk-ZITVWA4X.js → chunk-V6R6WDOQ.js} +1 -1
  146. package/dist/wallets/walletConnectors/chunk-WBVDGWKA.js +60 -0
  147. package/dist/wallets/walletConnectors/{chunk-RQYBKCWA.js → chunk-WMDTUVBI.js} +4 -2
  148. package/dist/wallets/walletConnectors/{chunk-OEZE4GBQ.js → chunk-WXLW3QUZ.js} +66 -12
  149. package/dist/wallets/walletConnectors/chunk-WZMFQQ6R.js +108 -0
  150. package/dist/wallets/walletConnectors/{chunk-QTBJ6WNZ.js → chunk-X3P74Y3M.js} +110 -59
  151. package/dist/wallets/walletConnectors/{chunk-7GBAUSQJ.js → chunk-XPZCOEQL.js} +13 -6
  152. package/dist/wallets/walletConnectors/chunk-XS6GJRRA.js +98 -0
  153. package/dist/wallets/walletConnectors/{chunk-2OHHFQQ7.js → chunk-XSH5KJQV.js} +3 -1
  154. package/dist/wallets/walletConnectors/chunk-XSJUQHR7.js +95 -0
  155. package/dist/wallets/walletConnectors/chunk-XSX5EECZ.js +96 -0
  156. package/dist/wallets/walletConnectors/chunk-Z66ETAKN.js +20 -0
  157. package/dist/wallets/walletConnectors/{chunk-UNLWNVSN.js → chunk-ZJCV4QR4.js} +40 -11
  158. package/dist/wallets/walletConnectors/clvWallet/clvWallet.js +2 -2
  159. package/dist/wallets/walletConnectors/coin98Wallet/coin98Wallet.js +2 -2
  160. package/dist/wallets/walletConnectors/coreWallet/coreWallet.js +2 -2
  161. package/dist/wallets/walletConnectors/dawnWallet/dawnWallet.js +2 -2
  162. package/dist/wallets/walletConnectors/foxWallet/foxWallet.js +2 -2
  163. package/dist/wallets/walletConnectors/frontierWallet/frontierWallet.js +2 -2
  164. package/dist/wallets/walletConnectors/gateWallet/gateWallet.js +2 -2
  165. package/dist/wallets/walletConnectors/index.js +94 -91
  166. package/dist/wallets/walletConnectors/iopayWallet/iopayWallet.js +2 -2
  167. package/dist/wallets/walletConnectors/kaiaWallet/kaiaWallet.js +2 -2
  168. package/dist/wallets/walletConnectors/kaikasWallet/kaikasWallet.js +2 -2
  169. package/dist/wallets/walletConnectors/metaMaskWallet/metaMaskWallet.js +2 -2
  170. package/dist/wallets/walletConnectors/okxWallet/okxWallet.js +2 -2
  171. package/dist/wallets/walletConnectors/rainbowWallet/rainbowWallet.js +2 -2
  172. package/dist/wallets/walletConnectors/roninWallet/roninWallet.js +2 -2
  173. package/dist/wallets/walletConnectors/safepalWallet/safepalWallet.js +2 -2
  174. package/dist/wallets/walletConnectors/subWallet/subWallet.js +2 -2
  175. package/dist/wallets/walletConnectors/tokenPocketWallet/tokenPocketWallet.js +2 -2
  176. package/dist/wallets/walletConnectors/trustWallet/trustWallet.js +2 -2
  177. package/dist/wallets/walletConnectors/zealWallet/zealWallet.js +2 -2
  178. package/dist/wallets/walletConnectors/zerionWallet/zerionWallet.js +2 -2
  179. package/package.json +1 -1
  180. package/dist/AbcCredentialManager-QM2BNLSR.js +0 -7
  181. package/dist/TalkenApiSingleton-TECFDCT4.js +0 -9
  182. package/dist/chunk-PS5CBMY5.js +0 -453
  183. package/dist/chunk-R6ZE7JAZ.js +0 -15
  184. package/dist/wallets/walletConnectors/chunk-3DHUDD4U.js +0 -132
  185. package/dist/wallets/walletConnectors/chunk-6BHMNR5X.js +0 -46
  186. package/dist/wallets/walletConnectors/chunk-FLBJ7T4Q.js +0 -44
  187. package/dist/wallets/walletConnectors/chunk-KX3IFHJQ.js +0 -370
  188. package/dist/wallets/walletConnectors/chunk-R6ZE7JAZ.js +0 -15
package/dist/index.js CHANGED
@@ -1,4 +1,14 @@
1
1
  "use client";
2
+ import {
3
+ darkTheme
4
+ } from "./chunk-PUVP4PUZ.js";
5
+ import {
6
+ lightTheme
7
+ } from "./chunk-V22G3VGP.js";
8
+ import {
9
+ midnightTheme
10
+ } from "./chunk-7ZP3ENJ2.js";
11
+ import "./chunk-DQLAW7KN.js";
2
12
  import {
3
13
  AbcError,
4
14
  AbcErrorCode,
@@ -12,6 +22,8 @@ import {
12
22
  NETWORK_CONFIGS,
13
23
  NetworkType,
14
24
  SESSION_EXPIRED_EVENT,
25
+ STORAGE_NS,
26
+ STORAGE_PREFIX,
15
27
  SessionExpiredError,
16
28
  SolanaApi,
17
29
  SolanaNetwork,
@@ -24,6 +36,7 @@ import {
24
36
  cancelProactiveRefresh,
25
37
  chainIdToNetwork,
26
38
  checkDelegation,
39
+ clearNamespace,
27
40
  clearSession,
28
41
  configureLogger,
29
42
  createConfigApi,
@@ -38,67 +51,61 @@ import {
38
51
  dispatchSessionExpired,
39
52
  encryptWithPin,
40
53
  ensureDelegationCleared,
54
+ get,
41
55
  getBitcoinNetwork,
42
56
  getChainKey,
57
+ getCredentialManager,
43
58
  getEvmNetwork,
44
59
  getExplorerAddressUrl,
45
60
  getExplorerTxUrl,
46
61
  getGaslessConfig,
62
+ getJSON,
47
63
  getLoggerConfig,
48
64
  getNetworkByChainId,
49
65
  getNetworkByParam,
50
66
  getNetworkName,
51
67
  getSharedGaslessFeeService,
68
+ getShowPendingTransaction,
69
+ getShowTransactionResult,
52
70
  getSolanaNetwork,
53
71
  getSupportedChainIds,
54
72
  getSupportedNetworks,
73
+ getTalkenApiClient,
55
74
  getTronNetwork,
75
+ getUpdateTransactionResult,
56
76
  getXrplNetwork,
57
77
  hashPin,
58
78
  isEvmNetwork,
59
79
  isGaslessEligible,
60
80
  isTestnet,
61
81
  loadAuthState,
82
+ loadTgAccessKey,
62
83
  networkNameToChainKey,
63
84
  networkToChainId,
85
+ ownsTalkenApiSession,
86
+ ownsTalkenApiStorage,
87
+ remove,
64
88
  resolveFeeTokensFromConfig,
65
89
  resolveTalkenApiUrl,
66
90
  scheduleProactiveRefresh,
91
+ sendRevokeViaWalletClient,
92
+ set,
67
93
  setGaslessConfig,
68
- setupVisibilityRefresh
69
- } from "./chunk-ZISAJ7BZ.js";
94
+ setJSON,
95
+ setShowPendingTransaction,
96
+ setShowTransactionResult,
97
+ setTalkenApiClient,
98
+ setUpdateTransactionResult,
99
+ setupVisibilityRefresh,
100
+ toSplRawAmount,
101
+ validateAmount
102
+ } from "./chunk-GS4L4ZIS.js";
70
103
  import {
71
104
  en_US_default
72
105
  } from "./chunk-X4GSACNW.js";
73
- import {
74
- darkTheme
75
- } from "./chunk-PUVP4PUZ.js";
76
- import {
77
- lightTheme
78
- } from "./chunk-V22G3VGP.js";
79
- import {
80
- midnightTheme
81
- } from "./chunk-7ZP3ENJ2.js";
82
- import "./chunk-DQLAW7KN.js";
83
- import {
84
- getTalkenApiClient,
85
- setTalkenApiClient
86
- } from "./chunk-R6ZE7JAZ.js";
87
- import {
88
- STORAGE_NS,
89
- STORAGE_PREFIX,
90
- clearNamespace,
91
- get,
92
- getCredentialManager,
93
- getJSON,
94
- loadTgAccessKey,
95
- remove,
96
- set,
97
- setJSON
98
- } from "./chunk-PS5CBMY5.js";
99
106
 
100
107
  // src/components/ConnectButton/ConnectButton.tsx
101
- import React105, { useContext as useContext32, useEffect as useEffect38, useState as useState45 } from "react";
108
+ import React105, { useContext as useContext32, useEffect as useEffect39, useState as useState45 } from "react";
102
109
 
103
110
  // src/css/sprinkles.css.ts
104
111
  import { createMapValueFn as _51c72 } from "@vanilla-extract/sprinkles/createUtils";
@@ -197,7 +204,7 @@ function useBitcoinWallet() {
197
204
  wallet: bitcoinWallet,
198
205
  emptyState: emptyWalletState2,
199
206
  requestInterceptor,
200
- importProvider: async () => (await import("./abcWallet-4PXYWHYM.js")).AbcBitcoinProvider,
207
+ importProvider: async () => (await import("./abcWallet-RPQPYWWR.js")).AbcBitcoinProvider,
201
208
  mapState: (nextWallet, provider) => ({
202
209
  address: nextWallet.address,
203
210
  publicKey: nextWallet.publicKey,
@@ -1306,7 +1313,7 @@ var useShowBalance = () => useContext5(ShowBalanceContext);
1306
1313
 
1307
1314
  // src/components/ConnectButton/ConnectButtonRenderer.tsx
1308
1315
  import React104, { useContext as useContext31 } from "react";
1309
- import { useAccount as useAccount21, useConfig as useConfig5 } from "wagmi";
1316
+ import { useAccount as useAccount21, useConfig as useConfig6 } from "wagmi";
1310
1317
 
1311
1318
  // src/contexts/MultiChainContext.tsx
1312
1319
  import { useWallet as useWallet2 } from "@solana/wallet-adapter-react";
@@ -1370,7 +1377,7 @@ function useAbcSolanaState(evmConnected, connector, requestInterceptor) {
1370
1377
  wallet: solanaWallet,
1371
1378
  emptyState: emptyWalletState,
1372
1379
  requestInterceptor,
1373
- importProvider: async () => (await import("./abcWallet-4PXYWHYM.js")).AbcSolanaProvider,
1380
+ importProvider: async () => (await import("./abcWallet-RPQPYWWR.js")).AbcSolanaProvider,
1374
1381
  mapState: (nextWallet, provider) => ({
1375
1382
  address: nextWallet.address,
1376
1383
  publicKey: nextWallet.publicKey,
@@ -1404,6 +1411,12 @@ function useAbcSolanaState(evmConnected, connector, requestInterceptor) {
1404
1411
  };
1405
1412
  }
1406
1413
 
1414
+ // src/solana/clusterIdentity.ts
1415
+ var SOLANA_GENESIS_BY_NETWORK = Object.freeze({
1416
+ solana: "5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d",
1417
+ solana_devnet: "EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG"
1418
+ });
1419
+
1407
1420
  // src/hooks/useSolanaActions.ts
1408
1421
  async function sendExternalSolanaTransaction(params) {
1409
1422
  const { transaction, connection, externalWallet, options } = params;
@@ -1450,7 +1463,10 @@ async function normalizeSolanaSignature(signature) {
1450
1463
  );
1451
1464
  }
1452
1465
  function useSolanaActions(activeWallet, abcProvider, externalWallet, connection, solanaApiNetwork) {
1453
- const getWalletscanNetwork = () => process.env.NEXT_PUBLIC_ENVIRONMENT === "production" ? "solana" : "solana_devnet";
1466
+ const assertExternalNetwork = async () => {
1467
+ if (await connection.getGenesisHash() !== SOLANA_GENESIS_BY_NETWORK[solanaApiNetwork])
1468
+ throw new Error("Solana RPC cluster does not match the selected network");
1469
+ };
1454
1470
  const signMessage = async (params) => {
1455
1471
  if (activeWallet.type === "abc") {
1456
1472
  if (!abcProvider) {
@@ -1484,25 +1500,25 @@ function useSolanaActions(activeWallet, abcProvider, externalWallet, connection,
1484
1500
  if (!externalWallet.publicKey || !externalWallet.sendTransaction) {
1485
1501
  throw new Error("Wallet does not support transactions");
1486
1502
  }
1503
+ validateAmount(params.amount);
1504
+ const lamports = params.mintAddress ? void 0 : toSplRawAmount(params.amount, 9);
1505
+ await assertExternalNetwork();
1487
1506
  const solanaApi = createSolanaApi();
1488
- const { blockhash } = await solanaApi.getLatestBlockhash(solanaApiNetwork);
1489
1507
  if (params.mintAddress) {
1490
- const { PublicKey: PublicKey3, Transaction: Transaction3 } = await import("@solana/web3.js");
1508
+ const { PublicKey: PublicKey4, Transaction: Transaction3 } = await import("@solana/web3.js");
1491
1509
  const {
1492
1510
  getAssociatedTokenAddress,
1493
1511
  createAssociatedTokenAccountIdempotentInstruction,
1494
1512
  createTransferInstruction,
1495
- TOKEN_PROGRAM_ID
1513
+ TOKEN_PROGRAM_ID,
1514
+ getMint
1496
1515
  } = await import("@solana/spl-token");
1497
- const mintPubkey = new PublicKey3(params.mintAddress);
1516
+ const mintPubkey = new PublicKey4(params.mintAddress);
1498
1517
  const fromPubkey2 = externalWallet.publicKey;
1499
- const toPubkey2 = new PublicKey3(params.toAddress);
1500
- const walletscanApi = createWalletscanApi();
1501
- const tokenInfo = await walletscanApi.getContractTokenWithTimeout({
1502
- contractAddress: params.mintAddress,
1503
- networks: solanaApiNetwork
1504
- });
1505
- const decimals = tokenInfo?.decimals ?? 0;
1518
+ const toPubkey2 = new PublicKey4(params.toAddress);
1519
+ const { decimals } = await getMint(connection, mintPubkey);
1520
+ const rawAmount = toSplRawAmount(params.amount, decimals);
1521
+ const { blockhash: blockhash2 } = await connection.getLatestBlockhash();
1506
1522
  const fromTokenAccount = await getAssociatedTokenAddress(
1507
1523
  mintPubkey,
1508
1524
  fromPubkey2,
@@ -1525,7 +1541,6 @@ function useSolanaActions(activeWallet, abcProvider, externalWallet, connection,
1525
1541
  TOKEN_PROGRAM_ID
1526
1542
  )
1527
1543
  );
1528
- const rawAmount = Math.floor(params.amount * 10 ** decimals);
1529
1544
  transaction2.add(
1530
1545
  createTransferInstruction(
1531
1546
  fromTokenAccount,
@@ -1536,7 +1551,7 @@ function useSolanaActions(activeWallet, abcProvider, externalWallet, connection,
1536
1551
  TOKEN_PROGRAM_ID
1537
1552
  )
1538
1553
  );
1539
- transaction2.recentBlockhash = blockhash;
1554
+ transaction2.recentBlockhash = blockhash2;
1540
1555
  transaction2.feePayer = fromPubkey2;
1541
1556
  const signature2 = await sendExternalSolanaTransaction({
1542
1557
  transaction: transaction2,
@@ -1549,14 +1564,15 @@ function useSolanaActions(activeWallet, abcProvider, externalWallet, connection,
1549
1564
  });
1550
1565
  return { signature: signature2 };
1551
1566
  }
1552
- const { PublicKey: PublicKey2, SystemProgram, Transaction: Transaction2, LAMPORTS_PER_SOL } = await import("@solana/web3.js");
1567
+ const { PublicKey: PublicKey3, SystemProgram, Transaction: Transaction2 } = await import("@solana/web3.js");
1568
+ const { blockhash } = await connection.getLatestBlockhash();
1553
1569
  const fromPubkey = externalWallet.publicKey;
1554
- const toPubkey = new PublicKey2(params.toAddress);
1570
+ const toPubkey = new PublicKey3(params.toAddress);
1555
1571
  const transaction = new Transaction2().add(
1556
1572
  SystemProgram.transfer({
1557
1573
  fromPubkey,
1558
1574
  toPubkey,
1559
- lamports: params.amount * LAMPORTS_PER_SOL
1575
+ lamports
1560
1576
  })
1561
1577
  );
1562
1578
  transaction.recentBlockhash = blockhash;
@@ -1585,23 +1601,28 @@ function useSolanaActions(activeWallet, abcProvider, externalWallet, connection,
1585
1601
  if (!externalWallet.publicKey) {
1586
1602
  throw new Error("Wallet not connected");
1587
1603
  }
1588
- const walletscanApi = createWalletscanApi();
1589
- const balance = await walletscanApi.getWalletTokenBalanceWithTimeout({
1590
- walletAddress: externalWallet.publicKey.toBase58(),
1591
- networks: getWalletscanNetwork(),
1592
- contractAddress: mintAddress
1593
- });
1594
- if (!balance) {
1595
- return {
1596
- amount: "0",
1597
- decimals: 0,
1598
- uiAmount: 0
1599
- };
1604
+ await assertExternalNetwork();
1605
+ const { PublicKey: PublicKey3 } = await import("@solana/web3.js");
1606
+ const { getMint, unpackAccount, TOKEN_PROGRAM_ID } = await import("@solana/spl-token");
1607
+ const mint = new PublicKey3(mintAddress);
1608
+ const { decimals } = await getMint(connection, mint);
1609
+ const accounts = await connection.getTokenAccountsByOwner(
1610
+ externalWallet.publicKey,
1611
+ { mint }
1612
+ );
1613
+ let amount = BigInt(0);
1614
+ for (const { pubkey, account } of accounts.value) {
1615
+ const token = unpackAccount(pubkey, account, TOKEN_PROGRAM_ID);
1616
+ if (!token.mint.equals(mint) || !token.owner.equals(externalWallet.publicKey))
1617
+ throw new Error(
1618
+ "Solana token account does not match the requested owner/mint"
1619
+ );
1620
+ amount += token.amount;
1600
1621
  }
1601
1622
  return {
1602
- amount: String(balance.balance ?? 0),
1603
- decimals: balance.decimals ?? 0,
1604
- uiAmount: balance.hrBalance ?? 0
1623
+ amount: amount.toString(),
1624
+ decimals,
1625
+ uiAmount: Number(amount) / 10 ** decimals
1605
1626
  };
1606
1627
  }
1607
1628
  throw new Error("No Solana wallet connected");
@@ -1719,7 +1740,14 @@ function useSolanaWallet() {
1719
1740
  );
1720
1741
  const stableActions = useMemo6(
1721
1742
  () => actions5,
1722
- [activeWallet.type, activeWallet.isConnected, abcWallet.provider]
1743
+ [
1744
+ activeWallet.type,
1745
+ activeWallet.isConnected,
1746
+ abcWallet.provider,
1747
+ externalWallet,
1748
+ connection,
1749
+ solanaApiNetwork
1750
+ ]
1723
1751
  );
1724
1752
  return {
1725
1753
  address: activeWallet.address,
@@ -2063,7 +2091,7 @@ var ENHANCED_PROVIDER_ENABLED = Boolean(
2063
2091
  var enhancedProviderHttp = createHttpClient({
2064
2092
  baseUrl: "https://enhanced-provider.rainbow.me",
2065
2093
  headers: {
2066
- "x-api-key": typeof process !== "undefined" && typeof process.env !== "undefined" && process.env.RAINBOW_PROVIDER_API_KEY || ""
2094
+ "x-api-key": typeof process !== "undefined" && typeof process.env !== "undefined" && process.env.RAINBOW_PROVIDER_API_KEY || "undefined"
2067
2095
  }
2068
2096
  });
2069
2097
 
@@ -2384,50 +2412,142 @@ import React103, {
2384
2412
  createContext as createContext20,
2385
2413
  useCallback as useCallback28,
2386
2414
  useContext as useContext30,
2387
- useEffect as useEffect37,
2415
+ useEffect as useEffect38,
2388
2416
  useMemo as useMemo24,
2389
2417
  useState as useState44
2390
2418
  } from "react";
2391
- import { useAccount as useAccount20, useAccountEffect as useAccountEffect3, useConfig as useConfig4 } from "wagmi";
2419
+ import { useAccount as useAccount20, useAccountEffect as useAccountEffect3, useConfig as useConfig5 } from "wagmi";
2392
2420
 
2393
2421
  // src/components/AccountModal/AccountModal.tsx
2394
2422
  import React67, { useContext as useContext19, useMemo as useMemo19 } from "react";
2395
2423
  import { useAccount as useAccount16, useDisconnect } from "wagmi";
2396
2424
 
2397
2425
  // src/hooks/useMultiChainBalances.ts
2426
+ import { useConnection as useConnection2 } from "@solana/wallet-adapter-react";
2427
+ import { PublicKey } from "@solana/web3.js";
2398
2428
  import { useQueries } from "@tanstack/react-query";
2399
- import { formatUnits } from "viem";
2429
+ import { formatUnits, keccak256, stringToHex } from "viem";
2430
+ import { useConfig as useConfig2 } from "wagmi";
2431
+ import { getPublicClient } from "wagmi/actions";
2432
+ var ownerIds = /* @__PURE__ */ new WeakMap();
2433
+ var nextOwnerId = 0;
2434
+ function ownerId(client) {
2435
+ if (!client)
2436
+ return 0;
2437
+ let id = ownerIds.get(client);
2438
+ if (id === void 0) {
2439
+ id = ++nextOwnerId;
2440
+ ownerIds.set(client, id);
2441
+ }
2442
+ return id;
2443
+ }
2444
+ function matchesWallet(chain, session) {
2445
+ if (chain.walletType !== "abc" || !session)
2446
+ return false;
2447
+ const address = session.wallets[chain.chainType];
2448
+ return !!address && (chain.chainType === "evm" ? address.toLowerCase() === chain.address.toLowerCase() : address === chain.address);
2449
+ }
2400
2450
  function useMultiChainBalances(chains, enabled) {
2451
+ const config = useConfig2();
2452
+ const { connection } = useConnection2();
2453
+ const client = getTalkenApiClient();
2454
+ const session = client?.getAuthenticatedWalletSession();
2455
+ const revision = client?.getSessionRevision();
2456
+ const solanaRpcIdentity = connection?.rpcEndpoint ? keccak256(stringToHex(connection.rpcEndpoint)) : void 0;
2401
2457
  const queries = useQueries({
2402
- queries: chains.map((chain) => ({
2403
- queryKey: createQueryKey("multiChainBalance", {
2404
- address: chain.address,
2405
- network: chain.network
2406
- }),
2407
- queryFn: async () => {
2408
- const api = createWalletscanApi();
2409
- const token = await api.getNativeTokenWithTimeout(
2410
- {
2411
- walletAddress: chain.address,
2412
- networks: chain.network,
2413
- minimalInfo: false
2414
- },
2415
- 3e3
2416
- );
2417
- if (!token)
2418
- return null;
2419
- const decimals = token.decimals ?? 18;
2420
- const value2 = BigInt(String(token.balance ?? 0));
2421
- return {
2422
- decimals,
2423
- formatted: formatUnits(value2, decimals),
2424
- symbol: token.symbol,
2425
- value: value2
2426
- };
2427
- },
2428
- enabled,
2429
- staleTime: 3e4
2430
- }))
2458
+ queries: chains.map((chain) => {
2459
+ const authenticated = matchesWallet(chain, session);
2460
+ const assertCurrent = () => {
2461
+ if (chain.walletType !== "abc")
2462
+ return;
2463
+ const active2 = getTalkenApiClient();
2464
+ if (active2 !== client || active2?.getSessionRevision() !== revision || matchesWallet(chain, active2?.getAuthenticatedWalletSession()) !== authenticated) {
2465
+ throw new Error("Wallet authentication changed; refresh balances");
2466
+ }
2467
+ };
2468
+ return {
2469
+ queryKey: createQueryKey("multiChainBalance", {
2470
+ address: chain.address,
2471
+ network: chain.network,
2472
+ chainType: chain.chainType,
2473
+ chainId: chain.chainId ?? getNetworkByParam(chain.network)?.chainId,
2474
+ solanaRpcIdentity: chain.chainType === "solana" ? solanaRpcIdentity : void 0,
2475
+ authenticated,
2476
+ walletType: chain.walletType ?? "external",
2477
+ session: chain.walletType === "abc" ? [ownerId(client), revision] : void 0
2478
+ }),
2479
+ queryFn: async () => {
2480
+ assertCurrent();
2481
+ const chainId = chain.chainId ?? getNetworkByParam(chain.network)?.chainId;
2482
+ const network = chain.chainType === "evm" ? typeof chainId === "number" ? chainIdToNetwork(chainId) : void 0 : chain.network;
2483
+ if (!authenticated || !network) {
2484
+ if (chain.chainType === "evm") {
2485
+ const configured = config.chains.find(
2486
+ (entry) => entry.id === chainId
2487
+ );
2488
+ if (!configured)
2489
+ throw new Error("Native balance network is not configured");
2490
+ const client2 = getPublicClient(config, {
2491
+ chainId: configured.id
2492
+ });
2493
+ if (!client2)
2494
+ throw new Error("Native balance RPC is unavailable");
2495
+ const value3 = await client2.getBalance({
2496
+ address: chain.address
2497
+ });
2498
+ assertCurrent();
2499
+ const { decimals: decimals2, symbol } = configured.nativeCurrency;
2500
+ return {
2501
+ value: value3,
2502
+ decimals: decimals2,
2503
+ symbol,
2504
+ formatted: formatUnits(value3, decimals2)
2505
+ };
2506
+ }
2507
+ if (chain.chainType === "solana") {
2508
+ if (!connection)
2509
+ return null;
2510
+ const expectedGenesis = SOLANA_GENESIS_BY_NETWORK[chain.network];
2511
+ if (!expectedGenesis || await connection.getGenesisHash() !== expectedGenesis)
2512
+ return null;
2513
+ const value3 = BigInt(
2514
+ await connection.getBalance(new PublicKey(chain.address))
2515
+ );
2516
+ assertCurrent();
2517
+ return {
2518
+ value: value3,
2519
+ decimals: 9,
2520
+ symbol: "SOL",
2521
+ formatted: formatUnits(value3, 9)
2522
+ };
2523
+ }
2524
+ return null;
2525
+ }
2526
+ const api = createWalletscanApi();
2527
+ const token = await api.getNativeTokenWithTimeout(
2528
+ {
2529
+ walletAddress: chain.address,
2530
+ networks: network,
2531
+ minimalInfo: false
2532
+ },
2533
+ 3e3
2534
+ );
2535
+ assertCurrent();
2536
+ if (!token)
2537
+ return null;
2538
+ const decimals = token.decimals ?? 18;
2539
+ const value2 = BigInt(String(token.balance ?? 0));
2540
+ return {
2541
+ decimals,
2542
+ formatted: formatUnits(value2, decimals),
2543
+ symbol: token.symbol,
2544
+ value: value2
2545
+ };
2546
+ },
2547
+ enabled,
2548
+ staleTime: 3e4
2549
+ };
2550
+ })
2431
2551
  });
2432
2552
  const balances = {};
2433
2553
  for (let i = 0; i < chains.length; i++) {
@@ -2462,7 +2582,7 @@ function useTronWallet() {
2462
2582
  wallet: tronWallet,
2463
2583
  emptyState: emptyWalletState2,
2464
2584
  requestInterceptor,
2465
- importProvider: async () => (await import("./abcWallet-4PXYWHYM.js")).AbcTronProvider,
2585
+ importProvider: async () => (await import("./abcWallet-RPQPYWWR.js")).AbcTronProvider,
2466
2586
  mapState: (nextWallet, provider) => ({
2467
2587
  address: nextWallet.address,
2468
2588
  publicKey: nextWallet.publicKey,
@@ -2539,7 +2659,7 @@ function useXrplWallet() {
2539
2659
  wallet: xrplWallet,
2540
2660
  emptyState: emptyWalletState2,
2541
2661
  requestInterceptor,
2542
- importProvider: async () => (await import("./abcWallet-4PXYWHYM.js")).AbcXrplProvider,
2662
+ importProvider: async () => (await import("./abcWallet-RPQPYWWR.js")).AbcXrplProvider,
2543
2663
  mapState: (nextWallet, provider) => ({
2544
2664
  address: nextWallet.address,
2545
2665
  publicKey: nextWallet.publicKey,
@@ -8162,29 +8282,6 @@ function useTransactionResult() {
8162
8282
  return useContext13(TransactionResultContext);
8163
8283
  }
8164
8284
 
8165
- // src/providers/TransactionResultProvider/TransactionResultSingleton.ts
8166
- var _showResult = null;
8167
- var _showPending = null;
8168
- var _updateResult = null;
8169
- function setShowTransactionResult(fn) {
8170
- _showResult = fn;
8171
- }
8172
- function getShowTransactionResult() {
8173
- return _showResult ?? void 0;
8174
- }
8175
- function setShowPendingTransaction(fn) {
8176
- _showPending = fn;
8177
- }
8178
- function getShowPendingTransaction() {
8179
- return _showPending ?? void 0;
8180
- }
8181
- function setUpdateTransactionResult(fn) {
8182
- _updateResult = fn;
8183
- }
8184
- function getUpdateTransactionResult() {
8185
- return _updateResult ?? void 0;
8186
- }
8187
-
8188
8285
  // src/providers/TransactionResultProvider/TransactionResultProvider.tsx
8189
8286
  function TransactionResultProvider({
8190
8287
  disabled,
@@ -8285,7 +8382,7 @@ import {
8285
8382
  isVersionedTransaction
8286
8383
  } from "@solana/wallet-adapter-base";
8287
8384
  import {
8288
- PublicKey
8385
+ PublicKey as PublicKey2
8289
8386
  } from "@solana/web3.js";
8290
8387
  var logger12 = createLogger("AbcSolanaWalletAdapter");
8291
8388
  var AbcWalletName = "ABC Wallet";
@@ -8491,39 +8588,103 @@ var AbcSolanaWalletAdapter = class extends BaseMessageSignerWalletAdapter {
8491
8588
  get readyState() {
8492
8589
  return WalletReadyState.Installed;
8493
8590
  }
8591
+ assertWalletBinding() {
8592
+ this._talkenApi.getSessionRevision();
8593
+ if (getTalkenApiClient() === this._talkenApi && !ownsTalkenApiStorage(this._talkenApi))
8594
+ throw new WalletNotReadyError();
8595
+ if (!ownsTalkenApiSession(this._talkenApi))
8596
+ throw new WalletNotReadyError();
8597
+ if (getTalkenApiClient() !== this._talkenApi || !this._talkenApi.isAccessKeyMode())
8598
+ return;
8599
+ const session = this._talkenApi.getAuthenticatedWalletSession();
8600
+ if (!session || !this._wallet || session.wallets.solana !== this._wallet.address || this._wallet.uid && session.user.uid && String(this._wallet.uid) !== session.user.uid) {
8601
+ throw new WalletNotReadyError(
8602
+ "Please sign in again to bind the Solana wallet."
8603
+ );
8604
+ }
8605
+ }
8606
+ captureWalletOperation() {
8607
+ this.assertWalletBinding();
8608
+ const api = this._talkenApi;
8609
+ const revision = api.getSessionRevision();
8610
+ const wallet = this._wallet;
8611
+ const address = wallet?.address;
8612
+ const publicKey = this._publicKey?.toBase58();
8613
+ const network = this._getSigningNetwork();
8614
+ return () => {
8615
+ if (this._talkenApi !== api || api.getSessionRevision() !== revision || this._wallet !== wallet || this._wallet?.address !== address || this._publicKey?.toBase58() !== publicKey || this._getSigningNetwork() !== network) {
8616
+ throw new WalletNotReadyError(
8617
+ "The wallet session or network changed while the request was pending."
8618
+ );
8619
+ }
8620
+ this.assertWalletBinding();
8621
+ };
8622
+ }
8623
+ async awaitWalletOperation(assertCurrent, operation) {
8624
+ assertCurrent();
8625
+ try {
8626
+ const result = await operation();
8627
+ assertCurrent();
8628
+ return result;
8629
+ } catch (error2) {
8630
+ assertCurrent();
8631
+ throw error2;
8632
+ }
8633
+ }
8494
8634
  /**
8495
8635
  * Connect to ABC Wallet
8496
8636
  */
8497
8637
  async connect() {
8638
+ const originatingApi = this._talkenApi;
8639
+ const originatingNetwork = this._getSigningNetwork();
8640
+ let revision = this._talkenApi.getSessionRevision();
8641
+ const assertCurrent = () => {
8642
+ if (this._talkenApi !== originatingApi || this._getSigningNetwork() !== originatingNetwork)
8643
+ throw new WalletConnectionError(
8644
+ "The wallet context changed during authentication."
8645
+ );
8646
+ if (getTalkenApiClient() === this._talkenApi && !ownsTalkenApiStorage(this._talkenApi))
8647
+ throw new WalletConnectionError("The shared wallet session changed.");
8648
+ if (!ownsTalkenApiSession(this._talkenApi) || this._talkenApi.getSessionRevision() !== revision)
8649
+ throw new WalletConnectionError(
8650
+ "The wallet session changed. Please reconnect."
8651
+ );
8652
+ };
8498
8653
  try {
8654
+ assertCurrent();
8499
8655
  if (this.connecting)
8500
8656
  return;
8501
8657
  if (this.connected && this._publicKey) {
8658
+ this.assertWalletBinding();
8502
8659
  this.emit("connect", this._publicKey);
8503
8660
  return;
8504
8661
  }
8505
8662
  this._connecting = true;
8506
- const authStateRaw = get(STORAGE_NS.ABC, "auth_state");
8663
+ const authStateRaw = ownsTalkenApiStorage(this._talkenApi) ? get(STORAGE_NS.ABC, "auth_state") : null;
8507
8664
  if (authStateRaw) {
8508
8665
  try {
8509
8666
  const authData = JSON.parse(authStateRaw);
8510
- const hasAccessKey = !!loadTgAccessKey();
8667
+ const hasAccessKey = !!this._talkenApi.getAuthenticatedWalletSession();
8511
8668
  if (authData.solanaWallet && (this._talkenApi.isAuthenticated() || hasAccessKey)) {
8512
8669
  const wallet = authData.solanaWallet;
8513
8670
  const keyId = wallet.keyId || wallet.key_id;
8514
8671
  const encryptedShare = wallet.encryptedShare || wallet.encrypted_share;
8515
8672
  const secretStore = wallet.secretStore || wallet.secret_store;
8516
- if (!keyId || !encryptedShare) {
8673
+ if ((!keyId || !encryptedShare) && !this._talkenApi.getAuthenticatedWalletSession()) {
8517
8674
  this._connecting = false;
8518
8675
  return;
8519
8676
  }
8520
8677
  const normalizedWallet = {
8521
8678
  ...wallet,
8522
- keyId,
8523
- encryptedShare,
8679
+ keyId: keyId || "",
8680
+ encryptedShare: encryptedShare || "",
8524
8681
  secretStore: secretStore || ""
8525
8682
  };
8526
8683
  if (!this._talkenApi.isAccessKeyMode() && authData.accessToken) {
8684
+ if (this._talkenApi.getAccessToken() !== authData.accessToken || this._talkenApi.getRefreshToken() !== authData.refreshToken)
8685
+ throw new WalletConnectionError(
8686
+ "Stored wallet credentials do not match this session."
8687
+ );
8527
8688
  this._talkenApi.setTokens(
8528
8689
  authData.accessToken,
8529
8690
  authData.refreshToken,
@@ -8531,13 +8692,14 @@ var AbcSolanaWalletAdapter = class extends BaseMessageSignerWalletAdapter {
8531
8692
  );
8532
8693
  }
8533
8694
  this._wallet = normalizedWallet;
8695
+ this.assertWalletBinding();
8534
8696
  const addressOrPubkey = normalizedWallet.address || normalizedWallet.publicKey;
8535
8697
  try {
8536
- this._publicKey = new PublicKey(addressOrPubkey);
8698
+ this._publicKey = new PublicKey2(addressOrPubkey);
8537
8699
  } catch (_error) {
8538
8700
  const hexKey = addressOrPubkey.startsWith("0x") ? addressOrPubkey.slice(2) : addressOrPubkey;
8539
8701
  const bytes = new Uint8Array(Buffer.from(hexKey, "hex"));
8540
- this._publicKey = new PublicKey(bytes);
8702
+ this._publicKey = new PublicKey2(bytes);
8541
8703
  }
8542
8704
  this._connecting = false;
8543
8705
  const displayAddress2 = this._publicKey.toBase58();
@@ -8547,7 +8709,8 @@ var AbcSolanaWalletAdapter = class extends BaseMessageSignerWalletAdapter {
8547
8709
  this.emit("connect", this._publicKey);
8548
8710
  return;
8549
8711
  }
8550
- if (!this._talkenApi.isAccessKeyMode() && !hasAccessKey) {
8712
+ if (!this._talkenApi.isAccessKeyMode() && !hasAccessKey && ownsTalkenApiStorage(this._talkenApi)) {
8713
+ assertCurrent();
8551
8714
  logger12.info("Not authenticated, clearing session");
8552
8715
  remove(STORAGE_NS.ABC, "auth_state");
8553
8716
  }
@@ -8562,13 +8725,21 @@ var AbcSolanaWalletAdapter = class extends BaseMessageSignerWalletAdapter {
8562
8725
  );
8563
8726
  }
8564
8727
  const authHandler = this._config.onRequestAuth || this._showAuthModal.bind(this);
8565
- await authHandler();
8566
- const loginResponse = await this._talkenApi.auth.loginWithSns({
8567
- token: "demo-token",
8568
- // Simplified authentication for standalone adapter
8569
- service: "google",
8570
- audience: "abc_wallet"
8571
- });
8728
+ const auth = await authHandler();
8729
+ assertCurrent();
8730
+ if (!auth.email || !auth.password)
8731
+ throw new WalletConnectionError(
8732
+ "This adapter requires completed TalkenKit authentication or an email/password auth handler."
8733
+ );
8734
+ const loginResponse = await this._talkenApi.auth.loginWithPassword(
8735
+ auth.email,
8736
+ auth.password
8737
+ );
8738
+ if (getTalkenApiClient() !== this._talkenApi || this._talkenApi.getSessionRevision() !== loginResponse.sessionRevision)
8739
+ throw new WalletConnectionError(
8740
+ "The wallet session changed during authentication."
8741
+ );
8742
+ revision = this._talkenApi.getSessionRevision();
8572
8743
  const expiresAt = Date.now() + loginResponse.expiresIn * 1e3;
8573
8744
  this._talkenApi.setTokens(
8574
8745
  loginResponse.accessToken,
@@ -8577,17 +8748,22 @@ var AbcSolanaWalletAdapter = class extends BaseMessageSignerWalletAdapter {
8577
8748
  );
8578
8749
  const pinHandler = this._config.onRequestPin || this._showPinModal.bind(this);
8579
8750
  const pin = await pinHandler();
8751
+ assertCurrent();
8580
8752
  const pinHash = await hashPin(pin);
8753
+ assertCurrent();
8581
8754
  let walletResult;
8582
8755
  try {
8583
8756
  const response = await this._talkenApi.wallet.generate(pinHash);
8757
+ assertCurrent();
8584
8758
  if (!response.solana) {
8585
8759
  throw new Error("Solana wallet not returned from generation");
8586
8760
  }
8587
8761
  walletResult = response.solana;
8588
8762
  } catch (error2) {
8763
+ assertCurrent();
8589
8764
  if (error2.response?.status === 409 || error2.message?.includes("already exists")) {
8590
8765
  const response = await this._talkenApi.wallet.recover(pinHash);
8766
+ assertCurrent();
8591
8767
  if (!response.solana) {
8592
8768
  throw new Error("Solana wallet not returned from recovery");
8593
8769
  }
@@ -8597,12 +8773,13 @@ var AbcSolanaWalletAdapter = class extends BaseMessageSignerWalletAdapter {
8597
8773
  }
8598
8774
  }
8599
8775
  this._wallet = walletResult;
8776
+ this.assertWalletBinding();
8600
8777
  try {
8601
- this._publicKey = new PublicKey(walletResult.address);
8778
+ this._publicKey = new PublicKey2(walletResult.address);
8602
8779
  } catch {
8603
8780
  const hexKey = walletResult.address.startsWith("0x") ? walletResult.address.slice(2) : walletResult.address;
8604
8781
  const bytes = new Uint8Array(Buffer.from(hexKey, "hex"));
8605
- this._publicKey = new PublicKey(bytes);
8782
+ this._publicKey = new PublicKey2(bytes);
8606
8783
  }
8607
8784
  this._connecting = false;
8608
8785
  const displayAddress = this._publicKey.toBase58();
@@ -8675,28 +8852,41 @@ var AbcSolanaWalletAdapter = class extends BaseMessageSignerWalletAdapter {
8675
8852
  * Sign a message
8676
8853
  */
8677
8854
  async signMessage(message) {
8855
+ const assertOperation = this.captureWalletOperation();
8678
8856
  try {
8857
+ this.assertWalletBinding();
8858
+ const revision = this._talkenApi.getSessionRevision();
8679
8859
  if (!this._wallet)
8680
8860
  throw new WalletNotReadyError();
8681
8861
  const messageText = new TextDecoder().decode(message);
8682
- await this.callInterceptor({
8683
- chain: "solana",
8684
- method: "signMessage",
8685
- address: this._publicKey?.toBase58() || "",
8686
- network: this._config.network || "solana",
8687
- message: messageText
8688
- });
8862
+ await this.awaitWalletOperation(
8863
+ assertOperation,
8864
+ async () => this.callInterceptor({
8865
+ chain: "solana",
8866
+ method: "signMessage",
8867
+ address: this._publicKey?.toBase58() || "",
8868
+ network: this._config.network || "solana",
8869
+ message: messageText
8870
+ })
8871
+ );
8872
+ this.assertWalletBinding();
8873
+ if (this._talkenApi.getSessionRevision() !== revision)
8874
+ throw new WalletNotReadyError();
8689
8875
  const messageHex = Buffer.from(message).toString("hex");
8690
- const pinHash = getCredentialManager().getPinHash() || "";
8691
- const signatureResponse = await this._talkenApi.solana.sign({
8692
- message: messageHex,
8693
- pin: pinHash || void 0,
8694
- network: this._getSigningNetwork()
8695
- });
8876
+ const pinHash = (ownsTalkenApiStorage(this._talkenApi) ? getCredentialManager().getPinHash() : null) || "";
8877
+ const signatureResponse = await this.awaitWalletOperation(
8878
+ assertOperation,
8879
+ async () => this._talkenApi.solana.sign({
8880
+ message: messageHex,
8881
+ pin: pinHash || void 0,
8882
+ network: this._getSigningNetwork()
8883
+ })
8884
+ );
8696
8885
  const sig = signatureResponse.signature;
8697
8886
  const signatureBytes = /^[0-9a-fA-F]+$/.test(sig) && sig.length === 128 ? Buffer.from(sig, "hex") : Buffer.from(sig, "base64");
8698
8887
  return new Uint8Array(signatureBytes);
8699
8888
  } catch (error2) {
8889
+ assertOperation();
8700
8890
  throw new WalletSignMessageError(error2?.message, error2);
8701
8891
  }
8702
8892
  }
@@ -8704,22 +8894,30 @@ var AbcSolanaWalletAdapter = class extends BaseMessageSignerWalletAdapter {
8704
8894
  * Sign a transaction
8705
8895
  */
8706
8896
  async signTransaction(transaction) {
8897
+ const assertOperation = this.captureWalletOperation();
8707
8898
  try {
8708
8899
  if (!this._wallet)
8709
8900
  throw new WalletNotReadyError();
8710
8901
  if (!this._publicKey)
8711
8902
  throw new WalletNotReadyError();
8712
8903
  const instructionsJson = this.serializeTransactionForDisplay(transaction);
8713
- await this.callInterceptor({
8714
- chain: "solana",
8715
- method: "signTransaction",
8716
- address: this._publicKey.toBase58(),
8717
- network: this._config.network || "solana",
8718
- message: instructionsJson,
8719
- isTransaction: true
8720
- });
8721
- return this._signTransactionInternal(transaction);
8904
+ await this.awaitWalletOperation(
8905
+ assertOperation,
8906
+ async () => this.callInterceptor({
8907
+ chain: "solana",
8908
+ method: "signTransaction",
8909
+ address: this._publicKey.toBase58(),
8910
+ network: this._config.network || "solana",
8911
+ message: instructionsJson,
8912
+ isTransaction: true
8913
+ })
8914
+ );
8915
+ return await this.awaitWalletOperation(
8916
+ assertOperation,
8917
+ async () => this._signTransactionInternal(transaction)
8918
+ );
8722
8919
  } catch (error2) {
8920
+ assertOperation();
8723
8921
  if (error2?.code !== 4001 && !error2?.cancelled) {
8724
8922
  logger12.error("signTransaction failed:", error2);
8725
8923
  }
@@ -8730,18 +8928,23 @@ var AbcSolanaWalletAdapter = class extends BaseMessageSignerWalletAdapter {
8730
8928
  * Internal signing logic (no interceptor). Used by signTransaction and sendTransaction.
8731
8929
  */
8732
8930
  async _signTransactionInternal(transaction) {
8931
+ this.assertWalletBinding();
8733
8932
  if (!this._wallet)
8734
8933
  throw new WalletNotReadyError();
8735
8934
  if (!this._publicKey)
8736
8935
  throw new WalletNotReadyError();
8737
8936
  const messageBytes = isVersionedTransaction(transaction) ? transaction.message.serialize() : transaction.serializeMessage();
8738
8937
  const messageHex = Buffer.from(messageBytes).toString("hex");
8739
- const pinHash = getCredentialManager().getPinHash();
8740
- const signatureResponse = await this._talkenApi.solana.sign({
8741
- message: messageHex,
8742
- pin: pinHash || void 0,
8743
- network: this._getSigningNetwork()
8744
- });
8938
+ const pinHash = ownsTalkenApiStorage(this._talkenApi) ? getCredentialManager().getPinHash() : null;
8939
+ const assertOperation = this.captureWalletOperation();
8940
+ const signatureResponse = await this.awaitWalletOperation(
8941
+ assertOperation,
8942
+ async () => this._talkenApi.solana.sign({
8943
+ message: messageHex,
8944
+ pin: pinHash || void 0,
8945
+ network: this._getSigningNetwork()
8946
+ })
8947
+ );
8745
8948
  const signature = Buffer.from(signatureResponse.signature, "hex");
8746
8949
  if (isVersionedTransaction(transaction)) {
8747
8950
  transaction.addSignature(
@@ -8758,8 +8961,12 @@ var AbcSolanaWalletAdapter = class extends BaseMessageSignerWalletAdapter {
8758
8961
  */
8759
8962
  async signAllTransactions(transactions) {
8760
8963
  const signedTransactions = [];
8964
+ const assertOperation = this.captureWalletOperation();
8761
8965
  for (const transaction of transactions) {
8762
- const signed = await this.signTransaction(transaction);
8966
+ const signed = await this.awaitWalletOperation(
8967
+ assertOperation,
8968
+ async () => this.signTransaction(transaction)
8969
+ );
8763
8970
  signedTransactions.push(signed);
8764
8971
  }
8765
8972
  return signedTransactions;
@@ -8771,25 +8978,36 @@ var AbcSolanaWalletAdapter = class extends BaseMessageSignerWalletAdapter {
8771
8978
  * Supports any Solana transaction (SOL, SPL, dApp interactions, etc.).
8772
8979
  */
8773
8980
  async sendTransaction(transaction, connection, options = {}) {
8981
+ const assertOperation = this.captureWalletOperation();
8774
8982
  try {
8775
8983
  if (!this._wallet)
8776
8984
  throw new WalletNotReadyError();
8777
8985
  if (!this._publicKey)
8778
8986
  throw new WalletNotReadyError();
8779
8987
  const instructionsJson = this.serializeTransactionForDisplay(transaction);
8780
- await this.callInterceptor({
8781
- chain: "solana",
8782
- method: "signTransaction",
8783
- address: this._publicKey.toBase58(),
8784
- network: this._config.network || "solana",
8785
- message: instructionsJson,
8786
- isTransaction: true
8787
- });
8788
- const signed = await this._signTransactionInternal(transaction);
8988
+ await this.awaitWalletOperation(
8989
+ assertOperation,
8990
+ async () => this.callInterceptor({
8991
+ chain: "solana",
8992
+ method: "signTransaction",
8993
+ address: this._publicKey.toBase58(),
8994
+ network: this._config.network || "solana",
8995
+ message: instructionsJson,
8996
+ isTransaction: true
8997
+ })
8998
+ );
8999
+ const signed = await this.awaitWalletOperation(
9000
+ assertOperation,
9001
+ async () => this._signTransactionInternal(transaction)
9002
+ );
8789
9003
  const serialized = Buffer.from(signed.serialize());
8790
- const txHash = await connection.sendRawTransaction(serialized, options);
9004
+ const txHash = await this.awaitWalletOperation(
9005
+ assertOperation,
9006
+ async () => connection.sendRawTransaction(serialized, options)
9007
+ );
8791
9008
  return txHash;
8792
9009
  } catch (error2) {
9010
+ assertOperation();
8793
9011
  if (error2?.code !== 4001 && !error2?.cancelled) {
8794
9012
  logger12.error("sendTransaction failed:", error2);
8795
9013
  }
@@ -9052,27 +9270,38 @@ function AbcSolanaAutoConnector() {
9052
9270
  const maxRetries = 3;
9053
9271
  const retryDelay = 500;
9054
9272
  const handleAutoConnect = async () => {
9273
+ const api = getTalkenApiClient();
9274
+ const revision = api?.getSessionRevision();
9275
+ const current = () => !!api && getTalkenApiClient() === api && api.getSessionRevision() === revision && ownsTalkenApiStorage(api);
9055
9276
  if (connected) {
9056
9277
  return;
9057
9278
  }
9058
9279
  if (isConnectingRef.current) {
9059
9280
  return;
9060
9281
  }
9061
- const authData = loadAuthState();
9282
+ const authData = getJSON(
9283
+ STORAGE_NS.ABC,
9284
+ "auth_state"
9285
+ );
9062
9286
  if (authData) {
9287
+ if (!current() || api?.isAccessKeyMode() && !api.getAuthenticatedWalletSession())
9288
+ return;
9063
9289
  try {
9064
9290
  if (authData.solanaWallet?.address) {
9065
9291
  const solWallet = authData.solanaWallet;
9066
9292
  const keyId = solWallet.keyId;
9067
9293
  const encryptedShare = solWallet.encryptedShare;
9068
- if (keyId && encryptedShare) {
9294
+ if (keyId && encryptedShare || api?.getAuthenticatedWalletSession()?.wallets.solana === solWallet.address) {
9069
9295
  const abcWallet = wallets.find(
9070
9296
  (w) => w.adapter.name === "ABC Wallet"
9071
9297
  );
9072
9298
  if (!abcWallet) {
9073
9299
  if (retryCount < maxRetries) {
9074
9300
  retryCount++;
9075
- setTimeout(() => handleAutoConnect(), retryDelay);
9301
+ setTimeout(() => {
9302
+ if (current())
9303
+ void handleAutoConnect();
9304
+ }, retryDelay);
9076
9305
  }
9077
9306
  return;
9078
9307
  }
@@ -9080,17 +9309,29 @@ function AbcSolanaAutoConnector() {
9080
9309
  try {
9081
9310
  select(abcWallet.adapter.name);
9082
9311
  await new Promise((r) => setTimeout(r, 50));
9312
+ if (!current())
9313
+ return;
9083
9314
  await abcWallet.adapter.connect();
9315
+ if (!current())
9316
+ return;
9084
9317
  hasAttemptedRef.current = true;
9085
9318
  return;
9086
9319
  } catch (error2) {
9320
+ if (!current())
9321
+ return;
9087
9322
  const hasAccessKey = loadTgAccessKey();
9088
9323
  if (!hasAccessKey && error2?.message?.includes("requires authentication")) {
9324
+ api?.clearSession();
9325
+ if (!api || !ownsTalkenApiStorage(api))
9326
+ return;
9089
9327
  localStorage.removeItem(`${STORAGE_PREFIX}auth_state`);
9090
9328
  }
9091
9329
  if (retryCount < maxRetries) {
9092
9330
  retryCount++;
9093
- setTimeout(() => handleAutoConnect(), retryDelay);
9331
+ setTimeout(() => {
9332
+ if (current())
9333
+ void handleAutoConnect();
9334
+ }, retryDelay);
9094
9335
  }
9095
9336
  } finally {
9096
9337
  isConnectingRef.current = false;
@@ -9241,7 +9482,7 @@ function setRainbowKitVersion({ version }) {
9241
9482
  }
9242
9483
  function useFingerprint() {
9243
9484
  const fingerprint = useCallback16(() => {
9244
- setRainbowKitVersion({ version: "2.8.4" });
9485
+ setRainbowKitVersion({ version: "2.8.6" });
9245
9486
  }, []);
9246
9487
  useEffect25(() => {
9247
9488
  fingerprint();
@@ -10848,7 +11089,7 @@ function ProfileDetails({
10848
11089
  size: mobile ? "14" : "13",
10849
11090
  weight: "medium"
10850
11091
  },
10851
- `${displayBalance ?? "0"} ${balance?.symbol || chain.symbol}`
11092
+ `${displayBalance ?? "\u2014"} ${balance?.symbol || chain.symbol}`
10852
11093
  )
10853
11094
  )
10854
11095
  );
@@ -10906,7 +11147,7 @@ function ProfileDetails({
10906
11147
 
10907
11148
  // src/components/AccountModal/AccountModal.tsx
10908
11149
  function AccountModal({ onClose, open }) {
10909
- const { address } = useAccount16();
11150
+ const { address, connector } = useAccount16();
10910
11151
  const chainId = useChainId();
10911
11152
  const { ensAvatar } = useProfile({ address });
10912
11153
  const { disconnect } = useDisconnect();
@@ -10921,7 +11162,9 @@ function AccountModal({ onClose, open }) {
10921
11162
  if (address && chainId) {
10922
11163
  chains.push({
10923
11164
  chainType: "evm",
11165
+ walletType: connector?.id === "abc" ? "abc" : "external",
10924
11166
  address,
11167
+ chainId,
10925
11168
  network: getNetworkName(chainId),
10926
11169
  symbol: "ETH",
10927
11170
  iconUrl: "https://coin-images.coingecko.com/coins/images/279/large/ethereum.png?1696501628"
@@ -10930,6 +11173,7 @@ function AccountModal({ onClose, open }) {
10930
11173
  if (solanaWallet?.address && solanaWallet.isConnected) {
10931
11174
  chains.push({
10932
11175
  chainType: "solana",
11176
+ walletType: solanaWallet.type === "abc" ? "abc" : "external",
10933
11177
  address: solanaWallet.address,
10934
11178
  network: solanaWallet.network || "solana",
10935
11179
  symbol: "SOL",
@@ -10939,6 +11183,7 @@ function AccountModal({ onClose, open }) {
10939
11183
  if (bitcoinWallet?.address && bitcoinWallet.isConnected) {
10940
11184
  chains.push({
10941
11185
  chainType: "bitcoin",
11186
+ walletType: "abc",
10942
11187
  address: bitcoinWallet.address,
10943
11188
  network: bitcoinWallet.network || "bitcoin",
10944
11189
  symbol: "BTC",
@@ -10948,6 +11193,7 @@ function AccountModal({ onClose, open }) {
10948
11193
  if (tronWallet?.address && tronWallet.isConnected) {
10949
11194
  chains.push({
10950
11195
  chainType: "tron",
11196
+ walletType: "abc",
10951
11197
  address: tronWallet.address,
10952
11198
  network: tronWallet.network || "tron",
10953
11199
  symbol: "TRX",
@@ -10957,6 +11203,7 @@ function AccountModal({ onClose, open }) {
10957
11203
  if (xrplWallet?.address && xrplWallet.isConnected) {
10958
11204
  chains.push({
10959
11205
  chainType: "xrpl",
11206
+ walletType: "abc",
10960
11207
  address: xrplWallet.address,
10961
11208
  network: xrplWallet.network || "xrpl",
10962
11209
  symbol: "XRP",
@@ -10964,7 +11211,15 @@ function AccountModal({ onClose, open }) {
10964
11211
  });
10965
11212
  }
10966
11213
  return chains;
10967
- }, [address, chainId, solanaWallet, bitcoinWallet, tronWallet, xrplWallet]);
11214
+ }, [
11215
+ address,
11216
+ connector?.id,
11217
+ chainId,
11218
+ solanaWallet,
11219
+ bitcoinWallet,
11220
+ tronWallet,
11221
+ xrplWallet
11222
+ ]);
10968
11223
  const balances = useMultiChainBalances(chainAddresses, open);
10969
11224
  if (!displayAddress) {
10970
11225
  return null;
@@ -10994,7 +11249,7 @@ function AccountModal({ onClose, open }) {
10994
11249
  // src/components/ChainModal/ChainModal.tsx
10995
11250
  import React71, { useContext as useContext21, useState as useState28 } from "react";
10996
11251
  import { useAccount as useAccount17, useDisconnect as useDisconnect2, useSwitchChain } from "wagmi";
10997
- import { useConfig as useConfig2 } from "wagmi";
11252
+ import { useConfig as useConfig3 } from "wagmi";
10998
11253
 
10999
11254
  // src/components/Icons/DisconnectSq.tsx
11000
11255
  import React68 from "react";
@@ -11187,7 +11442,7 @@ var MobileScrollClassName = "ty310n1";
11187
11442
  // src/components/ChainModal/ChainModal.tsx
11188
11443
  function ChainModal({ onClose, open }) {
11189
11444
  const { chainId } = useAccount17();
11190
- const { chains } = useConfig2();
11445
+ const { chains } = useConfig3();
11191
11446
  const [pendingChainId, setPendingChainId] = useState28(null);
11192
11447
  const { switchChain } = useSwitchChain({
11193
11448
  mutation: {
@@ -11348,7 +11603,7 @@ function addRecentSolanaWalletId(walletName2) {
11348
11603
  }
11349
11604
 
11350
11605
  // src/components/ConnectOptions/ConnectOptionsModal.tsx
11351
- import React95, { useContext as useContext24, useEffect as useEffect35, useRef as useRef18, useState as useState39 } from "react";
11606
+ import React95, { useContext as useContext24, useEffect as useEffect36, useRef as useRef19, useState as useState39 } from "react";
11352
11607
  import { useConnect as useConnect2, useConnectors } from "wagmi";
11353
11608
 
11354
11609
  // src/components/Disclaimer/DisclaimerLink.tsx
@@ -11753,7 +12008,6 @@ function AbcWaasAuthSections(props) {
11753
12008
  }
11754
12009
 
11755
12010
  // src/components/ConnectOptions/AbcWaasAuth/hooks/useAbcWaasAuth.ts
11756
- import { getTalkenApiClient as getTalkenApiClient2 } from "@talken/talkenkit";
11757
12011
  import { useState as useState30 } from "react";
11758
12012
  var logger15 = createLogger("useAbcWaasAuth");
11759
12013
  function useAbcWaasAuth(props) {
@@ -11764,27 +12018,8 @@ function useAbcWaasAuth(props) {
11764
12018
  const [error2, setError] = useState30("");
11765
12019
  const [isLoading, setIsLoading] = useState30(false);
11766
12020
  const [loginData, setLoginData] = useState30(null);
11767
- const clearExpiredEncryptedData = () => {
11768
- const expiresAtStr = get(STORAGE_NS.ABC, "expires_at");
11769
- const hasEncryptedTokens = get(STORAGE_NS.ABC, "enc_tokens");
11770
- if (!hasEncryptedTokens)
11771
- return;
11772
- const expiresAt = expiresAtStr ? Number(expiresAtStr) : 0;
11773
- const isExpired = Date.now() >= expiresAt;
11774
- if (isExpired) {
11775
- remove(STORAGE_NS.ABC, "enc_tokens");
11776
- remove(STORAGE_NS.ABC, "enc_salt");
11777
- remove(STORAGE_NS.ABC, "auth_state");
11778
- remove(STORAGE_NS.ABC, "user");
11779
- remove(STORAGE_NS.ABC, "wallet");
11780
- remove(STORAGE_NS.ABC, "solana_wallet");
11781
- remove(STORAGE_NS.ABC, "bitcoin_wallet");
11782
- remove(STORAGE_NS.ABC, "tron_wallet");
11783
- remove(STORAGE_NS.ABC, "xrpl_wallet");
11784
- }
11785
- };
11786
12021
  const getApi = () => {
11787
- const api = getTalkenApiClient2();
12022
+ const api = getTalkenApiClient();
11788
12023
  if (!api) {
11789
12024
  throw new Error("TalkenApiClient not initialized");
11790
12025
  }
@@ -11819,7 +12054,22 @@ function useAbcWaasAuth(props) {
11819
12054
  setError("");
11820
12055
  try {
11821
12056
  const api = getApi();
11822
- clearExpiredEncryptedData();
12057
+ const result = await api.auth.ensureAccessKey({
12058
+ credential: { type: "email_otp", email, otpCode: otp },
12059
+ accessKeyName: `talkenkit_${email}`
12060
+ });
12061
+ const assertLogin = () => {
12062
+ if (getTalkenApiClient() !== api || api.getSessionRevision() !== result.sessionRevision)
12063
+ throw new TalkenApiError(
12064
+ "AUTH_SESSION_CHANGED",
12065
+ "The wallet session changed during login.",
12066
+ 401
12067
+ );
12068
+ };
12069
+ assertLogin();
12070
+ remove(STORAGE_NS.ABC, "enc_tokens");
12071
+ remove(STORAGE_NS.ABC, "enc_salt");
12072
+ getCredentialManager().clear();
11823
12073
  remove(STORAGE_NS.ABC, "auth_state");
11824
12074
  remove(STORAGE_NS.ABC, "user");
11825
12075
  remove(STORAGE_NS.ABC, "wallet");
@@ -11830,15 +12080,10 @@ function useAbcWaasAuth(props) {
11830
12080
  remove(STORAGE_NS.ABC, "access_token");
11831
12081
  remove(STORAGE_NS.ABC, "refresh_token");
11832
12082
  remove(STORAGE_NS.ABC, "expires_at");
11833
- const result = await api.auth.ensureUser(
11834
- email,
11835
- otp,
11836
- `talkenkit_${email}`
11837
- );
11838
- api.setAccessKey(result.accessKey);
11839
12083
  const authState = {
11840
12084
  isAuthenticated: true,
11841
12085
  user: {
12086
+ uid: result.uid,
11842
12087
  email: result.email,
11843
12088
  provider: "email"
11844
12089
  },
@@ -11851,13 +12096,14 @@ function useAbcWaasAuth(props) {
11851
12096
  refreshToken: null,
11852
12097
  expiresAt: null,
11853
12098
  accessKeyMode: true,
11854
- accessKeyExpiresAt: result.accessKeyExpiresAt ?? result.expiresAt ?? null
12099
+ accessKeyExpiresAt: result.accessKeyExpiresAt ? new Date(result.accessKeyExpiresAt).toISOString() : null
11855
12100
  };
11856
12101
  setJSON(STORAGE_NS.ABC, "auth_state", authState);
11857
12102
  setJSON(STORAGE_NS.ABC, "user", authState.user);
11858
12103
  if (typeof window !== "undefined") {
11859
12104
  window.dispatchEvent(new Event("talkenkit_storage_update"));
11860
12105
  }
12106
+ assertLogin();
11861
12107
  const accessKeyLoginData = {
11862
12108
  email: result.email,
11863
12109
  credential: ""
@@ -11902,9 +12148,6 @@ function useAbcWaasAuth(props) {
11902
12148
  // src/components/ConnectOptions/AbcWaasAuth/hooks/useAbcWaasSocial.ts
11903
12149
  import { useState as useState31 } from "react";
11904
12150
 
11905
- // src/services/AbcAuthService.ts
11906
- import { getTalkenApiClient as getTalkenApiClient3 } from "@talken/talkenkit";
11907
-
11908
12151
  // src/wallets/walletConnectors/abcWallet/firebase.ts
11909
12152
  import { initializeApp } from "firebase/app";
11910
12153
  import { getAuth } from "firebase/auth";
@@ -12183,187 +12426,102 @@ async function kakaoLogin() {
12183
12426
  }
12184
12427
  }
12185
12428
 
12186
- // src/services/AbcAuthService.ts
12187
- async function registerUser(params, _config) {
12188
- const api = getTalkenApiClient3();
12189
- if (!api) {
12190
- throw new Error("TalkenApiClient not initialized");
12191
- }
12192
- const res = await api.auth.register({
12193
- email: params.username,
12194
- otpCode: params.emailCode,
12195
- password: params.password,
12196
- name: params.name
12197
- });
12198
- return { status: "success", data: res };
12199
- }
12200
- async function registerSnsUser(params, _config) {
12201
- const api = getTalkenApiClient3();
12202
- if (!api) {
12203
- throw new Error("TalkenApiClient not initialized");
12204
- }
12205
- const res = await api.auth.register({
12206
- email: params.username,
12207
- otpCode: params.sixCode,
12208
- password: "",
12209
- name: params.name
12210
- });
12211
- return { status: "success", data: res };
12212
- }
12213
- async function resetPassword(params, _config) {
12214
- const api = getTalkenApiClient3();
12215
- if (!api) {
12216
- throw new Error("TalkenApiClient not initialized");
12217
- }
12218
- const res = await api.auth.resetPassword(
12219
- params.username,
12220
- params.password,
12221
- params.emailCode
12222
- );
12223
- return { status: "success", data: res };
12224
- }
12225
- async function emailCheck(email, _config) {
12226
- const api = getTalkenApiClient3();
12227
- if (!api) {
12228
- throw new Error("TalkenApiClient not initialized");
12229
- }
12230
- const res = await api.auth.checkEmail(email);
12231
- return {
12232
- status: "success",
12233
- message: { code: res.code || 0, text: res.message || "" }
12429
+ // src/components/ConnectOptions/AbcWaasAuth/hooks/useAbcWaasSocial.ts
12430
+ function useAbcWaasSocial(props) {
12431
+ const { onPinRequired, onEmailSet } = props;
12432
+ const [isLoading, setIsLoading] = useState31(false);
12433
+ const [error2, setError] = useState31("");
12434
+ const captureLogin = () => {
12435
+ const api = getTalkenApiClient();
12436
+ if (!api)
12437
+ throw new Error("TalkenApiClient not initialized");
12438
+ return { api, revision: api.getSessionRevision() };
12234
12439
  };
12235
- }
12236
- async function sendOtpCode(email, _config) {
12237
- const api = getTalkenApiClient3();
12238
- if (!api) {
12239
- throw new Error("TalkenApiClient not initialized");
12240
- }
12241
- await api.auth.sendOtp(email);
12242
- return { status: "success", data: { sent: true } };
12243
- }
12244
- async function verifyOtpCode(email, code, _config) {
12245
- const api = getTalkenApiClient3();
12246
- if (!api) {
12247
- throw new Error("TalkenApiClient not initialized");
12248
- }
12249
- await api.auth.verifyOtp(email, code);
12250
- return { status: "success", data: { verified: true } };
12251
- }
12252
- async function loginWithPassword(params, _apiServer) {
12253
- const api = getTalkenApiClient3();
12254
- if (!api) {
12255
- throw new Error("TalkenApiClient not initialized");
12256
- }
12257
- const res = await api.auth.loginWithPassword(
12258
- params.username,
12259
- params.password
12260
- );
12261
- return {
12262
- access_token: res.accessToken,
12263
- refresh_token: res.refreshToken,
12264
- expires_in: res.expiresIn,
12265
- uid: res.uid,
12266
- email: res.email
12267
- };
12268
- }
12269
- async function performSnsLogin(token, service, email) {
12270
- const api = getTalkenApiClient3();
12271
- if (!api) {
12272
- throw new Error("TalkenApiClient not initialized");
12273
- }
12274
- const res = await api.auth.loginWithSns({ token, service });
12275
- return {
12276
- uid: res.uid,
12277
- access_token: res.accessToken,
12278
- refresh_token: res.refreshToken,
12279
- email: res.email || email,
12280
- user_type: res.isNewUser ? "new" : "existing"
12281
- };
12282
- }
12283
- async function googleLogin2(_config) {
12284
- initializeFirebase();
12285
- const googleAuth = await googleLogin();
12286
- if (!googleAuth)
12287
- return null;
12288
- return performSnsLogin(googleAuth.idToken, "google", googleAuth.email);
12289
- }
12290
- async function appleLogin2(_config) {
12291
- initializeFirebase();
12292
- const appleAuth = await appleLogin();
12293
- if (!appleAuth)
12294
- return null;
12295
- return performSnsLogin(appleAuth.idToken, "apple", appleAuth.email);
12296
- }
12297
- async function kakaoLogin2(_config) {
12298
- const kakaoAuth = await kakaoLogin();
12299
- if (!kakaoAuth)
12300
- return null;
12301
- return performSnsLogin(kakaoAuth.idToken, "kakao", kakaoAuth.email);
12302
- }
12303
-
12304
- // src/components/ConnectOptions/AbcWaasAuth/hooks/useAbcWaasSocial.ts
12305
- function useAbcWaasSocial(props) {
12306
- const { onPinRequired, onEmailSet } = props;
12307
- const [isLoading, setIsLoading] = useState31(false);
12308
- const [error2, setError] = useState31("");
12309
- const clearExpiredEncryptedData = () => {
12310
- const expiresAtStr = get(STORAGE_NS.ABC, "expires_at");
12311
- const hasEncryptedTokens = get(STORAGE_NS.ABC, "enc_tokens");
12312
- if (!hasEncryptedTokens)
12313
- return;
12314
- const expiresAt = expiresAtStr ? Number(expiresAtStr) : 0;
12315
- const isExpired = Date.now() >= expiresAt;
12316
- if (isExpired) {
12317
- remove(STORAGE_NS.ABC, "enc_tokens");
12318
- remove(STORAGE_NS.ABC, "enc_salt");
12319
- remove(STORAGE_NS.ABC, "auth_state");
12320
- remove(STORAGE_NS.ABC, "user");
12321
- remove(STORAGE_NS.ABC, "wallet");
12322
- remove(STORAGE_NS.ABC, "solana_wallet");
12323
- remove(STORAGE_NS.ABC, "bitcoin_wallet");
12324
- remove(STORAGE_NS.ABC, "tron_wallet");
12325
- remove(STORAGE_NS.ABC, "xrpl_wallet");
12440
+ const assertLogin = (session) => {
12441
+ if (getTalkenApiClient() !== session.api || session.api.getSessionRevision() !== session.revision) {
12442
+ throw new TalkenApiError(
12443
+ "AUTH_SESSION_CHANGED",
12444
+ "The wallet session changed during login.",
12445
+ 401
12446
+ );
12326
12447
  }
12327
12448
  };
12328
- const saveAuthState = (response, provider) => {
12449
+ const clearLegacyTokenState = () => {
12450
+ remove(STORAGE_NS.ABC, "enc_tokens");
12451
+ remove(STORAGE_NS.ABC, "enc_salt");
12452
+ getCredentialManager().clear();
12453
+ remove(STORAGE_NS.ABC, "auth_state");
12454
+ remove(STORAGE_NS.ABC, "user");
12455
+ remove(STORAGE_NS.ABC, "wallet");
12456
+ remove(STORAGE_NS.ABC, "solana_wallet");
12457
+ remove(STORAGE_NS.ABC, "bitcoin_wallet");
12458
+ remove(STORAGE_NS.ABC, "tron_wallet");
12459
+ remove(STORAGE_NS.ABC, "xrpl_wallet");
12460
+ remove(STORAGE_NS.ABC, "access_token");
12461
+ remove(STORAGE_NS.ABC, "refresh_token");
12462
+ remove(STORAGE_NS.ABC, "expires_at");
12463
+ };
12464
+ const bootstrapSnsAccessKey = async (service, providerIdToken, email, provider, session) => {
12465
+ assertLogin(session);
12466
+ const api = session.api;
12467
+ const result = await api.auth.ensureAccessKey({
12468
+ credential: { type: "sns", service, token: providerIdToken },
12469
+ accessKeyName: `talkenkit_${email}`
12470
+ });
12471
+ assertLogin({ api, revision: result.sessionRevision });
12472
+ clearLegacyTokenState();
12329
12473
  const authState = {
12330
12474
  isAuthenticated: true,
12331
12475
  user: {
12332
- uid: response.uid,
12333
- email: response.email,
12476
+ uid: result.uid,
12477
+ email: result.email,
12334
12478
  provider
12335
12479
  },
12336
- wallet: null,
12337
- solanaWallet: null,
12338
- accessToken: response.access_token,
12339
- refreshToken: response.refresh_token,
12340
- expiresAt: Date.now() + ((response.expires_in || response.expiresIn || 3600) > 0 ? response.expires_in || response.expiresIn || 3600 : 3600) * 1e3
12480
+ wallet: result.evmAddress ? { address: result.evmAddress, chainId: getEvmNetwork() } : null,
12481
+ solanaWallet: result.addresses?.sol ? { address: result.addresses.sol } : null,
12482
+ bitcoinWallet: result.addresses?.btc ? { address: result.addresses.btc } : null,
12483
+ tronWallet: result.addresses?.trx ? { address: result.addresses.trx } : null,
12484
+ xrplWallet: result.addresses?.xrp ? { address: result.addresses.xrp } : null,
12485
+ accessToken: null,
12486
+ refreshToken: null,
12487
+ expiresAt: null,
12488
+ accessKeyMode: true,
12489
+ accessKeyExpiresAt: result.accessKeyExpiresAt ? new Date(result.accessKeyExpiresAt).toISOString() : null
12341
12490
  };
12342
12491
  setJSON(STORAGE_NS.ABC, "auth_state", authState);
12343
12492
  setJSON(STORAGE_NS.ABC, "user", authState.user);
12344
- set(STORAGE_NS.ABC, "access_token", response.access_token);
12345
- set(STORAGE_NS.ABC, "refresh_token", response.refresh_token);
12346
- set(STORAGE_NS.ABC, "expires_at", String(authState.expiresAt));
12347
- };
12348
- const handleSocialSuccess = (response, provider) => {
12349
- onEmailSet?.(response.email);
12350
- clearExpiredEncryptedData();
12351
- saveAuthState(response, provider);
12493
+ if (typeof window !== "undefined") {
12494
+ window.dispatchEvent(new Event("talkenkit_storage_update"));
12495
+ }
12496
+ assertLogin({ api, revision: result.sessionRevision });
12497
+ onEmailSet?.(result.email);
12498
+ assertLogin({ api, revision: result.sessionRevision });
12499
+ const accessKeyLoginData = {
12500
+ email: result.email,
12501
+ credential: ""
12502
+ // PIN handled server-side
12503
+ };
12352
12504
  const hasEncryptedTokens = !!(get(STORAGE_NS.ABC, "enc_tokens") && get(STORAGE_NS.ABC, "enc_salt"));
12353
- onPinRequired(response, response.email, hasEncryptedTokens);
12505
+ onPinRequired(accessKeyLoginData, result.email, hasEncryptedTokens);
12354
12506
  };
12355
12507
  const handleGoogleLogin = async () => {
12356
12508
  setIsLoading(true);
12357
12509
  setError("");
12358
12510
  try {
12359
- const response = await googleLogin2({
12360
- environment: process.env.NEXT_PUBLIC_ENVIRONMENT || "development"
12361
- });
12362
- if (!response)
12511
+ const session = captureLogin();
12512
+ initializeFirebase();
12513
+ const auth = await googleLogin();
12514
+ if (!auth)
12363
12515
  return;
12364
- handleSocialSuccess(response, "google");
12516
+ await bootstrapSnsAccessKey(
12517
+ "google",
12518
+ auth.idToken,
12519
+ auth.email,
12520
+ "google",
12521
+ session
12522
+ );
12365
12523
  } catch (e) {
12366
- setError(e.message || "Google login failed. Please try again.");
12524
+ setError(e?.message || "Google login failed. Please try again.");
12367
12525
  } finally {
12368
12526
  setIsLoading(false);
12369
12527
  }
@@ -12372,14 +12530,20 @@ function useAbcWaasSocial(props) {
12372
12530
  setIsLoading(true);
12373
12531
  setError("");
12374
12532
  try {
12375
- const response = await appleLogin2({
12376
- environment: process.env.NEXT_PUBLIC_ENVIRONMENT || "development"
12377
- });
12378
- if (!response)
12533
+ const session = captureLogin();
12534
+ initializeFirebase();
12535
+ const auth = await appleLogin();
12536
+ if (!auth)
12379
12537
  return;
12380
- handleSocialSuccess(response, "apple");
12538
+ await bootstrapSnsAccessKey(
12539
+ "apple",
12540
+ auth.idToken,
12541
+ auth.email,
12542
+ "apple",
12543
+ session
12544
+ );
12381
12545
  } catch (e) {
12382
- setError(e.message || "Apple login failed. Please try again.");
12546
+ setError(e?.message || "Apple login failed. Please try again.");
12383
12547
  } finally {
12384
12548
  setIsLoading(false);
12385
12549
  }
@@ -12388,14 +12552,19 @@ function useAbcWaasSocial(props) {
12388
12552
  setIsLoading(true);
12389
12553
  setError("");
12390
12554
  try {
12391
- const response = await kakaoLogin2({
12392
- environment: process.env.NEXT_PUBLIC_ENVIRONMENT || "development"
12393
- });
12394
- if (!response)
12555
+ const session = captureLogin();
12556
+ const auth = await kakaoLogin();
12557
+ if (!auth)
12395
12558
  return;
12396
- handleSocialSuccess(response, "kakao");
12559
+ await bootstrapSnsAccessKey(
12560
+ "kakao",
12561
+ auth.idToken,
12562
+ auth.email,
12563
+ "kakao",
12564
+ session
12565
+ );
12397
12566
  } catch (e) {
12398
- setError(e.message || "Kakao login failed. Please try again.");
12567
+ setError(e?.message || "Kakao login failed. Please try again.");
12399
12568
  } finally {
12400
12569
  setIsLoading(false);
12401
12570
  }
@@ -12934,7 +13103,7 @@ PopularWalletList.displayName = "PopularWalletList";
12934
13103
 
12935
13104
  // src/components/ConnectOptions/ExternalWallets/hooks/useWalletConnection.ts
12936
13105
  import { useCallback as useCallback23, useEffect as useEffect31, useRef as useRef17, useState as useState32 } from "react";
12937
- import { useAccount as useAccount18, useConfig as useConfig3 } from "wagmi";
13106
+ import { useAccount as useAccount18, useConfig as useConfig4 } from "wagmi";
12938
13107
  import { reconnect } from "wagmi/actions";
12939
13108
 
12940
13109
  // src/wallets/latestWalletId.ts
@@ -12959,7 +13128,7 @@ function useWalletConnection({
12959
13128
  const [qrCodeUri, setQrCodeUri] = useState32();
12960
13129
  const [connectionError, setConnectionError] = useState32(false);
12961
13130
  const { isConnected } = useAccount18();
12962
- const config = useConfig3();
13131
+ const config = useConfig4();
12963
13132
  const onSuccessRef = useRef17(onSuccess);
12964
13133
  onSuccessRef.current = onSuccess;
12965
13134
  const successCalledRef = useRef17(false);
@@ -13358,6 +13527,12 @@ function usePinCreation(props) {
13358
13527
  onShowConfirmModal?.();
13359
13528
  };
13360
13529
  const handlePinConfirm = async (confirmedPin) => {
13530
+ const api = getTalkenApiClient();
13531
+ const revision = api?.getSessionRevision();
13532
+ const assertCurrent = () => {
13533
+ if (!api || getTalkenApiClient() !== api || api.getSessionRevision() !== revision)
13534
+ throw new Error("AUTH_SESSION_CHANGED");
13535
+ };
13361
13536
  logger19.info("Confirming PIN");
13362
13537
  if (confirmedPin !== pin) {
13363
13538
  logger19.error("PINs do not match");
@@ -13369,8 +13544,10 @@ function usePinCreation(props) {
13369
13544
  try {
13370
13545
  logger19.debug("Hashing PIN...");
13371
13546
  const hashedPin = await hashPin(pin);
13547
+ assertCurrent();
13372
13548
  logger19.info("PIN hashed successfully");
13373
13549
  await onPinConfirmed(hashedPin);
13550
+ assertCurrent();
13374
13551
  setPin("");
13375
13552
  setConfirmPin("");
13376
13553
  } catch (error3) {
@@ -13399,14 +13576,52 @@ function usePinCreation(props) {
13399
13576
  }
13400
13577
 
13401
13578
  // src/components/ConnectOptions/PinAuth/hooks/usePinVerification.ts
13402
- import { useState as useState35 } from "react";
13579
+ import { useEffect as useEffect33, useRef as useRef18, useState as useState35 } from "react";
13403
13580
  var logger20 = createLogger("PinVerification");
13404
13581
  function usePinVerification(props) {
13405
13582
  const { email, onVerified, onSessionExpired } = props;
13406
13583
  const [isVerifying, setIsVerifying] = useState35(false);
13407
13584
  const [error2, setError] = useState35("");
13408
13585
  const [progress, setProgress] = useState35([]);
13586
+ const attempt = useRef18(0);
13587
+ const currentEmail = useRef18(email);
13588
+ currentEmail.current = email;
13589
+ useEffect33(
13590
+ () => () => {
13591
+ attempt.current++;
13592
+ },
13593
+ []
13594
+ );
13409
13595
  const handlePinVerify = async (pin) => {
13596
+ const operation = ++attempt.current;
13597
+ const api = getTalkenApiClient();
13598
+ let revision = api?.getSessionRevision();
13599
+ let storedAuth = get(STORAGE_NS.ABC, "auth_state");
13600
+ let encryptedData = get(STORAGE_NS.ABC, "enc_tokens");
13601
+ let saltHex = get(STORAGE_NS.ABC, "enc_salt");
13602
+ let credentials = JSON.stringify([
13603
+ api?.getAccessToken(),
13604
+ api?.getRefreshToken()
13605
+ ]);
13606
+ const ownerIdentity = (raw) => {
13607
+ try {
13608
+ const { accessToken, refreshToken, expiresAt, expires_in, ...owner2 } = JSON.parse(raw || "null") || {};
13609
+ return JSON.stringify(owner2);
13610
+ } catch {
13611
+ return raw;
13612
+ }
13613
+ };
13614
+ let owner = ownerIdentity(storedAuth);
13615
+ const ownsOperation = () => operation === attempt.current && currentEmail.current === email && getTalkenApiClient() === api && api?.getSessionRevision() === revision && !!api && ownsTalkenApiStorage(api) && ownerIdentity(get(STORAGE_NS.ABC, "auth_state")) === owner;
13616
+ const isCurrent = () => ownsOperation() && get(STORAGE_NS.ABC, "auth_state") === storedAuth && get(STORAGE_NS.ABC, "enc_tokens") === encryptedData && get(STORAGE_NS.ABC, "enc_salt") === saltHex && JSON.stringify([api?.getAccessToken(), api?.getRefreshToken()]) === credentials;
13617
+ const sessionChanged = () => Object.assign(
13618
+ new Error("The wallet session changed. Please try again."),
13619
+ { code: "AUTH_SESSION_CHANGED" }
13620
+ );
13621
+ const assertCurrent = () => {
13622
+ if (!isCurrent())
13623
+ throw sessionChanged();
13624
+ };
13410
13625
  logger20.info("Verifying PIN");
13411
13626
  setProgress([
13412
13627
  { label: "Verifying PIN...", status: "active" },
@@ -13414,13 +13629,13 @@ function usePinVerification(props) {
13414
13629
  ]);
13415
13630
  setIsVerifying(true);
13416
13631
  setError("");
13417
- await new Promise((resolve) => setTimeout(resolve, 100));
13418
13632
  try {
13633
+ await new Promise((resolve) => setTimeout(resolve, 100));
13634
+ assertCurrent();
13419
13635
  logger20.debug("Hashing PIN...");
13420
13636
  const hashedPin = await hashPin(pin);
13637
+ assertCurrent();
13421
13638
  logger20.debug("Decrypting stored data...");
13422
- const saltHex = get(STORAGE_NS.ABC, "enc_salt");
13423
- const encryptedData = get(STORAGE_NS.ABC, "enc_tokens");
13424
13639
  let sensitiveData;
13425
13640
  let isExpired = false;
13426
13641
  if (!saltHex || !encryptedData) {
@@ -13447,19 +13662,30 @@ function usePinVerification(props) {
13447
13662
  hashedPin,
13448
13663
  saltHex
13449
13664
  );
13665
+ assertCurrent();
13450
13666
  sensitiveData = JSON.parse(decrypted);
13451
13667
  logger20.info("PIN verified successfully");
13452
13668
  } catch (_decryptError) {
13669
+ assertCurrent();
13453
13670
  throw new Error("Incorrect PIN. Please try again.");
13454
13671
  }
13455
13672
  isExpired = sensitiveData.expiresAt ? Date.now() >= sensitiveData.expiresAt : true;
13456
13673
  }
13674
+ assertCurrent();
13675
+ const persisted = JSON.parse(storedAuth || "null");
13676
+ if (api?.isAccessKeyMode() || [api?.getAccessToken(), persisted?.accessToken].some(
13677
+ (token) => token && token !== sensitiveData.accessToken
13678
+ ) || [api?.getRefreshToken(), persisted?.refreshToken].some(
13679
+ (token) => token && token !== sensitiveData.refreshToken
13680
+ ))
13681
+ throw sessionChanged();
13457
13682
  setProgress([
13458
13683
  { label: "Verifying PIN...", status: "completed" },
13459
13684
  { label: "Restoring wallet data...", status: "active" }
13460
13685
  ]);
13461
13686
  logger20.info("Restoring wallet data...");
13462
13687
  await new Promise((resolve) => setTimeout(resolve, 100));
13688
+ assertCurrent();
13463
13689
  const authStateStr = get(STORAGE_NS.ABC, "auth_state");
13464
13690
  if (!authStateStr) {
13465
13691
  throw new Error("Auth state not found. Please login again.");
@@ -13475,16 +13701,31 @@ function usePinVerification(props) {
13475
13701
  if (!refreshToken) {
13476
13702
  throw new Error("No refresh token available");
13477
13703
  }
13478
- const api = getTalkenApiClient();
13479
13704
  if (!api) {
13480
13705
  throw new Error("TalkenApiClient not initialized");
13481
13706
  }
13707
+ assertCurrent();
13708
+ if (api.hasCredentials() && (api.isAccessKeyMode() || api.getAccessToken() !== sensitiveData.accessToken || api.getRefreshToken() !== refreshToken))
13709
+ throw sessionChanged();
13482
13710
  api.setTokens(
13483
13711
  sensitiveData.accessToken || "",
13484
13712
  refreshToken,
13485
13713
  sensitiveData.expiresAt || 0
13486
13714
  );
13715
+ revision = api.getSessionRevision();
13716
+ credentials = JSON.stringify([
13717
+ api.getAccessToken(),
13718
+ api.getRefreshToken()
13719
+ ]);
13487
13720
  const res = await api.auth.refresh();
13721
+ if (!ownsOperation() || get(STORAGE_NS.ABC, "enc_tokens") !== encryptedData || get(STORAGE_NS.ABC, "enc_salt") !== saltHex || api.getAccessToken() !== res.accessToken || api.getRefreshToken() !== (res.refreshToken || refreshToken))
13722
+ throw sessionChanged();
13723
+ storedAuth = get(STORAGE_NS.ABC, "auth_state");
13724
+ credentials = JSON.stringify([
13725
+ api.getAccessToken(),
13726
+ api.getRefreshToken()
13727
+ ]);
13728
+ assertCurrent();
13488
13729
  if (!res.accessToken) {
13489
13730
  throw new Error("Your session has expired. Please login again.");
13490
13731
  }
@@ -13513,10 +13754,16 @@ function usePinVerification(props) {
13513
13754
  hashedPin,
13514
13755
  saltBytes
13515
13756
  );
13757
+ assertCurrent();
13516
13758
  set(STORAGE_NS.ABC, "enc_tokens", encryptedTokens);
13759
+ encryptedData = encryptedTokens;
13517
13760
  setJSON(STORAGE_NS.ABC, "auth_state", authState);
13761
+ storedAuth = get(STORAGE_NS.ABC, "auth_state");
13762
+ owner = ownerIdentity(storedAuth);
13518
13763
  logger20.info("Encrypted tokens updated");
13519
13764
  } catch (refreshError) {
13765
+ if (!isCurrent() || refreshError?.code === "AUTH_SESSION_CHANGED")
13766
+ return;
13520
13767
  logger20.error("Token refresh failed:", refreshError);
13521
13768
  const freshAuthState = getJSON(STORAGE_NS.ABC, "auth_state");
13522
13769
  const hasFreshTokens = freshAuthState && (() => {
@@ -13529,6 +13776,14 @@ function usePinVerification(props) {
13529
13776
  })();
13530
13777
  if (!hasFreshTokens) {
13531
13778
  logger20.info("Clearing all auth data");
13779
+ assertCurrent();
13780
+ api?.clearSession();
13781
+ revision = api?.getSessionRevision();
13782
+ credentials = JSON.stringify([
13783
+ api?.getAccessToken(),
13784
+ api?.getRefreshToken()
13785
+ ]);
13786
+ getCredentialManager().clear();
13532
13787
  remove(STORAGE_NS.ABC, "auth_state");
13533
13788
  remove(STORAGE_NS.ABC, "enc_tokens");
13534
13789
  remove(STORAGE_NS.ABC, "enc_salt");
@@ -13536,12 +13791,18 @@ function usePinVerification(props) {
13536
13791
  remove(STORAGE_NS.ABC, "wallet");
13537
13792
  remove(STORAGE_NS.ABC, "access_token");
13538
13793
  remove(STORAGE_NS.ABC, "refresh_token");
13794
+ storedAuth = get(STORAGE_NS.ABC, "auth_state");
13795
+ owner = ownerIdentity(storedAuth);
13796
+ encryptedData = get(STORAGE_NS.ABC, "enc_tokens");
13797
+ saltHex = get(STORAGE_NS.ABC, "enc_salt");
13798
+ assertCurrent();
13539
13799
  onSessionExpired?.();
13540
13800
  throw new Error("Your session has expired. Please login again.");
13541
13801
  }
13542
13802
  logger20.info("Using fresh tokens from login, skipping refresh");
13543
13803
  }
13544
13804
  }
13805
+ assertCurrent();
13545
13806
  const user = getJSON(STORAGE_NS.ABC, "user");
13546
13807
  if (sensitiveData.solanaWallet)
13547
13808
  authState.solanaWallet = sensitiveData.solanaWallet;
@@ -13556,7 +13817,10 @@ function usePinVerification(props) {
13556
13817
  authState.wallet = wallet;
13557
13818
  if (user)
13558
13819
  authState.user = user;
13820
+ assertCurrent();
13559
13821
  setJSON(STORAGE_NS.ABC, "auth_state", authState);
13822
+ storedAuth = get(STORAGE_NS.ABC, "auth_state");
13823
+ owner = ownerIdentity(storedAuth);
13560
13824
  const credMgr = getCredentialManager();
13561
13825
  credMgr.setPinHash(hashedPin);
13562
13826
  credMgr.setEmail(email);
@@ -13566,17 +13830,23 @@ function usePinVerification(props) {
13566
13830
  ]);
13567
13831
  logger20.info("Wallet data restored successfully");
13568
13832
  window.dispatchEvent(new Event("talkenkit_storage_update"));
13833
+ assertCurrent();
13569
13834
  onVerified();
13570
13835
  } catch (err) {
13836
+ if (!isCurrent() || err?.code === "AUTH_SESSION_CHANGED")
13837
+ return;
13571
13838
  logger20.error("PIN verification failed:", err);
13572
13839
  setError(err.message || "Failed to verify PIN");
13573
13840
  throw err;
13574
13841
  } finally {
13575
- setIsVerifying(false);
13842
+ if (operation === attempt.current)
13843
+ setIsVerifying(false);
13576
13844
  }
13577
13845
  };
13578
13846
  const resetVerification = () => {
13579
13847
  logger20.debug("Resetting verification state");
13848
+ attempt.current++;
13849
+ setIsVerifying(false);
13580
13850
  setError("");
13581
13851
  setProgress([]);
13582
13852
  };
@@ -13613,20 +13883,45 @@ function useWalletGeneration(props) {
13613
13883
  setStatusMessage("Preparing wallet generation...");
13614
13884
  try {
13615
13885
  const api = getTalkenApiClient();
13886
+ if (!api)
13887
+ throw new Error("TalkenApiClient not initialized");
13888
+ const boundSession = api.isAccessKeyMode() ? api.getAuthenticatedWalletSession() : null;
13889
+ if (api.isAccessKeyMode() && (!boundSession || boundSession.user.email && boundSession.user.email !== email.trim().toLowerCase())) {
13890
+ throw new TalkenApiError(
13891
+ "AUTH_SESSION_UNBOUND",
13892
+ "Please sign in again before creating wallets.",
13893
+ 401
13894
+ );
13895
+ }
13616
13896
  if (!api.isAccessKeyMode()) {
13617
13897
  if (!loginData || !loginData.access_token) {
13618
13898
  throw new Error("Login data not found");
13619
13899
  }
13620
- const expiresAt = Date.now() + (loginData.expires_in > 0 ? loginData.expires_in : 3600) * 1e3;
13621
- set(STORAGE_NS.ABC, "access_token", loginData.access_token);
13622
- set(STORAGE_NS.ABC, "refresh_token", loginData.refresh_token || "");
13623
- set(STORAGE_NS.ABC, "expires_at", String(expiresAt));
13624
- api.setTokens(
13625
- loginData.access_token,
13626
- loginData.refresh_token || "",
13627
- expiresAt
13628
- );
13900
+ if (api.getAccessToken() !== loginData.access_token || api.getRefreshToken() !== (loginData.refresh_token || "") || loginData.sessionRevision !== void 0 && loginData.sessionRevision !== api.getSessionRevision()) {
13901
+ throw new TalkenApiError(
13902
+ "AUTH_SESSION_CHANGED",
13903
+ "The wallet login changed before wallet creation.",
13904
+ 401
13905
+ );
13906
+ }
13907
+ const expiresAt = api.getTokenExpiresAt();
13908
+ if (!expiresAt)
13909
+ throw new TalkenApiError(
13910
+ "AUTH_SESSION_CHANGED",
13911
+ "Token expiry is missing.",
13912
+ 401
13913
+ );
13629
13914
  }
13915
+ const revision = api.getSessionRevision();
13916
+ const assertCurrent = () => {
13917
+ if (getTalkenApiClient() !== api || api.getSessionRevision() !== revision) {
13918
+ throw new TalkenApiError(
13919
+ "AUTH_SESSION_CHANGED",
13920
+ "The wallet session changed during wallet creation.",
13921
+ 401
13922
+ );
13923
+ }
13924
+ };
13630
13925
  setProgress([
13631
13926
  { label: "Preparing wallet generation...", status: "completed" },
13632
13927
  { label: "Creating EVM wallet...", status: "active" },
@@ -13636,7 +13931,9 @@ function useWalletGeneration(props) {
13636
13931
  ]);
13637
13932
  setStatusMessage("Creating wallets...");
13638
13933
  const genResponse = await api.wallet.generate(hashedPin, email);
13934
+ assertCurrent();
13639
13935
  const infoResponse = await api.wallet.getInfo();
13936
+ assertCurrent();
13640
13937
  setProgress([
13641
13938
  { label: "Preparing wallet generation...", status: "completed" },
13642
13939
  { label: "Creating EVM wallet...", status: "completed" },
@@ -13657,6 +13954,7 @@ function useWalletGeneration(props) {
13657
13954
  if ((!btcAddress || !trxAddress || !xrpAddress) && pubkey) {
13658
13955
  try {
13659
13956
  const addrResponse = await api.wallet.getAddressForChain("all");
13957
+ assertCurrent();
13660
13958
  if (!btcAddress)
13661
13959
  btcAddress = addrResponse?.btc || addrResponse?.btcAddress || "";
13662
13960
  if (!trxAddress)
@@ -13664,6 +13962,7 @@ function useWalletGeneration(props) {
13664
13962
  if (!xrpAddress)
13665
13963
  xrpAddress = addrResponse?.xrp || addrResponse?.xrpAddress || "";
13666
13964
  } catch (err) {
13965
+ assertCurrent();
13667
13966
  logger21.warn("Failed to derive BTC/TRX/XRP addresses:", err);
13668
13967
  }
13669
13968
  }
@@ -13710,22 +14009,31 @@ function useWalletGeneration(props) {
13710
14009
  encryptedShare: "",
13711
14010
  network: getXrplNetwork()
13712
14011
  } : null;
13713
- getCredentialManager().setPinHash(hashedPin);
13714
- const pvencstr = evmAccount.pvencstr || "";
13715
- const encryptDevicePassword = evmAccount.encryptDevicePassword || "";
13716
- if (uid && genResponse.wid && sid && pvencstr && encryptDevicePassword) {
13717
- getCredentialManager().setEvmSigningCredentials({
13718
- uid,
13719
- wid: String(genResponse.wid),
13720
- sid,
13721
- pvencstr: String(pvencstr),
13722
- encryptDevicePassword: String(encryptDevicePassword)
13723
- });
13724
- }
14012
+ assertCurrent();
14013
+ const bearerSession = api.isAccessKeyMode() ? null : {
14014
+ accessToken: api.getAccessToken(),
14015
+ refreshToken: api.getRefreshToken(),
14016
+ expiresAt: api.getTokenExpiresAt()
14017
+ };
14018
+ if (bearerSession && (!bearerSession.accessToken || !bearerSession.refreshToken || !bearerSession.expiresAt))
14019
+ throw new TalkenApiError(
14020
+ "AUTH_SESSION_CHANGED",
14021
+ "Wallet credentials changed during creation.",
14022
+ 401
14023
+ );
14024
+ const assertCredentials = () => {
14025
+ assertCurrent();
14026
+ if (bearerSession && (api.getAccessToken() !== bearerSession.accessToken || api.getRefreshToken() !== bearerSession.refreshToken || api.getTokenExpiresAt() !== bearerSession.expiresAt))
14027
+ throw new TalkenApiError(
14028
+ "AUTH_SESSION_CHANGED",
14029
+ "Wallet credentials rotated during encryption.",
14030
+ 401
14031
+ );
14032
+ };
13725
14033
  const isAccessKey = api.isAccessKeyMode();
13726
14034
  const existingAuthState = getJSON(STORAGE_NS.ABC, "auth_state") || {};
13727
14035
  const walletData = {
13728
- address: sid,
14036
+ address: evmAddress,
13729
14037
  chainId: getEvmNetwork(),
13730
14038
  uid,
13731
14039
  sid,
@@ -13753,32 +14061,25 @@ function useWalletGeneration(props) {
13753
14061
  expiresAt: null,
13754
14062
  accessKeyMode: true
13755
14063
  } : {
13756
- accessToken: loginData.access_token,
13757
- refreshToken: loginData.refresh_token,
13758
- expiresAt: Date.now() + (loginData.expires_in > 0 ? loginData.expires_in : 3600) * 1e3
14064
+ accessToken: bearerSession.accessToken,
14065
+ refreshToken: bearerSession.refreshToken,
14066
+ expiresAt: bearerSession.expiresAt
13759
14067
  }
13760
14068
  };
13761
- setJSON(STORAGE_NS.ABC, "auth_state", authState);
13762
- setJSON(STORAGE_NS.ABC, "user", authState.user);
13763
- setJSON(STORAGE_NS.ABC, "wallet", walletData);
13764
- if (!isAccessKey) {
13765
- set(STORAGE_NS.ABC, "access_token", loginData.access_token);
13766
- set(STORAGE_NS.ABC, "refresh_token", loginData.refresh_token || "");
13767
- set(STORAGE_NS.ABC, "expires_at", String(authState.expiresAt));
13768
- }
13769
- if (typeof window !== "undefined") {
13770
- window.dispatchEvent(
13771
- new CustomEvent("talkenkit:token_updated", {
13772
- detail: { expiresAt: authState.expiresAt }
13773
- })
14069
+ assertCurrent();
14070
+ if (isAccessKey && !api.getAuthenticatedWalletSession(authState)) {
14071
+ throw new TalkenApiError(
14072
+ "AUTH_SESSION_CHANGED",
14073
+ "The generated account does not match this wallet login.",
14074
+ 401
13774
14075
  );
13775
- window.dispatchEvent(new Event("talkenkit_storage_update"));
13776
14076
  }
14077
+ let encryptedSession = null;
13777
14078
  if (!isAccessKey) {
13778
14079
  const salt = crypto.getRandomValues(new Uint8Array(16));
13779
14080
  const sensitiveData = JSON.stringify({
13780
- accessToken: loginData.access_token,
13781
- refreshToken: loginData.refresh_token || "",
14081
+ accessToken: bearerSession.accessToken,
14082
+ refreshToken: bearerSession.refreshToken,
13782
14083
  expiresAt: authState.expiresAt,
13783
14084
  solanaWallet: authState.solanaWallet,
13784
14085
  bitcoinWallet: authState.bitcoinWallet,
@@ -13786,18 +14087,55 @@ function useWalletGeneration(props) {
13786
14087
  xrplWallet: authState.xrplWallet
13787
14088
  });
13788
14089
  const encrypted = await encryptWithPin(sensitiveData, hashedPin, salt);
13789
- set(
13790
- STORAGE_NS.ABC,
13791
- "enc_salt",
13792
- Array.from(salt).map((b) => b.toString(16).padStart(2, "0")).join("")
14090
+ assertCredentials();
14091
+ encryptedSession = {
14092
+ salt: Array.from(salt).map((b) => b.toString(16).padStart(2, "0")).join(""),
14093
+ tokens: encrypted
14094
+ };
14095
+ }
14096
+ assertCredentials();
14097
+ getCredentialManager().setPinHash(hashedPin);
14098
+ const pvencstr = evmAccount.pvencstr || "";
14099
+ const encryptDevicePassword = evmAccount.encryptDevicePassword || "";
14100
+ if (uid && genResponse.wid && sid && pvencstr && encryptDevicePassword) {
14101
+ getCredentialManager().setEvmSigningCredentials({
14102
+ uid,
14103
+ wid: String(genResponse.wid),
14104
+ sid,
14105
+ pvencstr: String(pvencstr),
14106
+ encryptDevicePassword: String(encryptDevicePassword)
14107
+ });
14108
+ }
14109
+ setJSON(STORAGE_NS.ABC, "auth_state", authState);
14110
+ setJSON(STORAGE_NS.ABC, "user", authState.user);
14111
+ setJSON(STORAGE_NS.ABC, "wallet", walletData);
14112
+ if (!isAccessKey) {
14113
+ set(STORAGE_NS.ABC, "access_token", bearerSession.accessToken);
14114
+ set(STORAGE_NS.ABC, "refresh_token", bearerSession.refreshToken);
14115
+ set(STORAGE_NS.ABC, "expires_at", String(authState.expiresAt));
14116
+ }
14117
+ if (encryptedSession) {
14118
+ set(STORAGE_NS.ABC, "enc_salt", encryptedSession.salt);
14119
+ set(STORAGE_NS.ABC, "enc_tokens", encryptedSession.tokens);
14120
+ }
14121
+ if (typeof window !== "undefined") {
14122
+ assertCredentials();
14123
+ window.dispatchEvent(
14124
+ new CustomEvent("talkenkit:token_updated", {
14125
+ detail: { expiresAt: authState.expiresAt }
14126
+ })
13793
14127
  );
13794
- set(STORAGE_NS.ABC, "enc_tokens", encrypted);
14128
+ assertCredentials();
14129
+ window.dispatchEvent(new Event("talkenkit_storage_update"));
13795
14130
  }
14131
+ assertCredentials();
13796
14132
  if (loginData.credential) {
13797
14133
  delete loginData.credential;
13798
14134
  }
13799
14135
  if (typeof window !== "undefined") {
13800
14136
  setTimeout(() => {
14137
+ if (getTalkenApiClient() !== api || api.getSessionRevision() !== revision || bearerSession && (api.getAccessToken() !== bearerSession.accessToken || api.getRefreshToken() !== bearerSession.refreshToken))
14138
+ return;
13801
14139
  window.dispatchEvent(new Event("talkenkit_storage_update"));
13802
14140
  }, 500);
13803
14141
  }
@@ -13807,7 +14145,9 @@ function useWalletGeneration(props) {
13807
14145
  if (!abcConnector) {
13808
14146
  throw new Error("ABC connector not found");
13809
14147
  }
14148
+ assertCredentials();
13810
14149
  await connect({ connector: abcConnector });
14150
+ assertCredentials();
13811
14151
  onSuccess();
13812
14152
  } finally {
13813
14153
  setIsGenerating(false);
@@ -13856,7 +14196,11 @@ var PinAuthFlow = forwardRef(
13856
14196
  });
13857
14197
  },
13858
14198
  onShowConfirmModal: () => {
14199
+ const api = getTalkenApiClient();
14200
+ const revision = api?.getSessionRevision();
13859
14201
  setTimeout(() => {
14202
+ if (!api || getTalkenApiClient() !== api || api.getSessionRevision() !== revision)
14203
+ return;
13860
14204
  setIsPinCreateModalOpen(false);
13861
14205
  setIsPinConfirmModalOpen(true);
13862
14206
  }, 100);
@@ -13865,19 +14209,26 @@ var PinAuthFlow = forwardRef(
13865
14209
  const pinVerification = usePinVerification({
13866
14210
  email,
13867
14211
  onVerified: async () => {
14212
+ const api = getTalkenApiClient();
14213
+ const revision = api?.getSessionRevision();
14214
+ const assertCurrent = () => {
14215
+ if (!api || getTalkenApiClient() !== api || api.getSessionRevision() !== revision)
14216
+ throw new Error("AUTH_SESSION_CHANGED");
14217
+ };
14218
+ assertCurrent();
13868
14219
  setIsPinVerifyModalOpen(false);
13869
14220
  const authStateStr = localStorage.getItem(`${storagePrefix}auth_state`);
13870
14221
  const authState = authStateStr ? JSON.parse(authStateStr) : null;
13871
14222
  const needsWalletGeneration = authState && (!authState.wallet || !authState.solanaWallet || !authState.bitcoinWallet || !authState.tronWallet || !authState.xrplWallet);
13872
14223
  if (needsWalletGeneration) {
13873
- const { getCredentialManager: getCredentialManager2 } = await import("./AbcCredentialManager-QM2BNLSR.js");
13874
- const pinHash = getCredentialManager2().getPinHash();
14224
+ const pinHash = getCredentialManager().getPinHash();
13875
14225
  if (pinHash) {
13876
14226
  await walletGeneration.generateWallets({
13877
14227
  hashedPin: pinHash,
13878
14228
  email,
13879
14229
  loginData
13880
14230
  });
14231
+ assertCurrent();
13881
14232
  return;
13882
14233
  }
13883
14234
  }
@@ -13885,10 +14236,12 @@ var PinAuthFlow = forwardRef(
13885
14236
  (c) => c.id === "abc" || c.name === "ABC Wallet"
13886
14237
  );
13887
14238
  if (abcConnector) {
14239
+ assertCurrent();
13888
14240
  connect({ connector: abcConnector });
13889
14241
  } else {
13890
14242
  logger22.error("ABC Wallet connector not found");
13891
14243
  }
14244
+ assertCurrent();
13892
14245
  onComplete();
13893
14246
  },
13894
14247
  onSessionExpired: () => {
@@ -14051,7 +14404,7 @@ function ConnectModalIntro({
14051
14404
  }
14052
14405
 
14053
14406
  // src/components/ConnectOptions/ConnectDetails.tsx
14054
- import React94, { useContext as useContext23, useEffect as useEffect34 } from "react";
14407
+ import React94, { useContext as useContext23, useEffect as useEffect35 } from "react";
14055
14408
 
14056
14409
  // src/utils/colors.ts
14057
14410
  var convertHexToRGBA = (hexCode, opacity = 1) => {
@@ -14462,7 +14815,7 @@ function ConnectDetail({
14462
14815
  } : null;
14463
14816
  const { width: windowWidth } = useWindowSize();
14464
14817
  const smallWindow = windowWidth && windowWidth < 768;
14465
- useEffect34(() => {
14818
+ useEffect35(() => {
14466
14819
  preloadBrowserIcon();
14467
14820
  preloadPlatformIcon();
14468
14821
  }, []);
@@ -14842,7 +15195,7 @@ function DownloadOptionsDetail({
14842
15195
  mobileDownloadUrl
14843
15196
  } = wallet;
14844
15197
  const { i18n: i18n2 } = useContext23(I18nContext);
14845
- useEffect34(() => {
15198
+ useEffect35(() => {
14846
15199
  preloadCreateIcon();
14847
15200
  preloadScanIcon();
14848
15201
  preloadRefreshIcon();
@@ -14938,7 +15291,7 @@ function DownloadDetail({
14938
15291
  }) {
14939
15292
  const { downloadUrls, qrCode } = wallet;
14940
15293
  const { i18n: i18n2 } = useContext23(I18nContext);
14941
- useEffect34(() => {
15294
+ useEffect35(() => {
14942
15295
  preloadCreateIcon();
14943
15296
  preloadScanIcon();
14944
15297
  }, []);
@@ -15414,8 +15767,8 @@ function ConnectOptionsModal({
15414
15767
  const { i18n: i18n2 } = useContext24(I18nContext);
15415
15768
  const [abcWaasLoginData, setAbcWaasLoginData] = useState39(null);
15416
15769
  const [email, setEmail] = useState39("");
15417
- const initialized = useRef18(false);
15418
- const pinAuthFlowRef = useRef18(null);
15770
+ const initialized = useRef19(false);
15771
+ const pinAuthFlowRef = useRef19(null);
15419
15772
  const { connector } = useContext24(WalletButtonContext);
15420
15773
  const wallets = useWalletConnectors(false).filter((wallet) => wallet.ready || !!wallet.extensionDownloadUrl).sort((a, b) => a.groupIndex - b.groupIndex);
15421
15774
  const unfilteredWallets = useWalletConnectors();
@@ -15492,7 +15845,7 @@ function ConnectOptionsModal({
15492
15845
  connectWallet: walletConnection.connectWallet,
15493
15846
  selectWallet: walletConnection.selectWallet
15494
15847
  });
15495
- useEffect35(() => {
15848
+ useEffect36(() => {
15496
15849
  if (connector && !initialized.current) {
15497
15850
  changeWalletStep("CONNECT" /* Connect */);
15498
15851
  walletConnection.selectWallet(connector);
@@ -15776,8 +16129,8 @@ function ConnectOptionsModal({
15776
16129
  import React96, {
15777
16130
  useCallback as useCallback24,
15778
16131
  useContext as useContext25,
15779
- useEffect as useEffect36,
15780
- useRef as useRef19,
16132
+ useEffect as useEffect37,
16133
+ useRef as useRef20,
15781
16134
  useState as useState40
15782
16135
  } from "react";
15783
16136
 
@@ -15830,7 +16183,7 @@ function WalletButton({
15830
16183
  showWalletConnectModal
15831
16184
  } = wallet;
15832
16185
  const coolModeRef = useCoolMode2(iconUrl);
15833
- const initialized = useRef19(false);
16186
+ const initialized = useRef20(false);
15834
16187
  const { i18n: i18n2 } = useContext25(I18nContext);
15835
16188
  const onConnect = useCallback24(async () => {
15836
16189
  const onMobileUri = async () => {
@@ -15859,7 +16212,7 @@ function WalletButton({
15859
16212
  }
15860
16213
  connect?.();
15861
16214
  }, [connect, getMobileUri, showWalletConnectModal, onClose, name, id]);
15862
- useEffect36(() => {
16215
+ useEffect37(() => {
15863
16216
  if (connecting && !initialized.current) {
15864
16217
  onConnect();
15865
16218
  initialized.current = true;
@@ -16709,7 +17062,7 @@ function ModalProvider({ children }) {
16709
17062
  const [isWalletConnectModalOpen, setIsWalletConnectModalOpen] = useState44(false);
16710
17063
  const connectionStatus = useConnectionStatus();
16711
17064
  const { chainId } = useAccount20();
16712
- const { chains } = useConfig4();
17065
+ const { chains } = useConfig5();
16713
17066
  const isCurrentChainSupported = chains.some((chain) => chain.id === chainId);
16714
17067
  const multiChainContext = useContext30(MultiChainContext);
16715
17068
  const _isAnyChainConnected = connectionStatus === "connected" || multiChainContext?.solanaConnected;
@@ -16728,7 +17081,7 @@ function ModalProvider({ children }) {
16728
17081
  onConnect: () => closeModals({ keepConnectModalOpen: isUnauthenticated }),
16729
17082
  onDisconnect: () => closeModals()
16730
17083
  });
16731
- useEffect37(() => {
17084
+ useEffect38(() => {
16732
17085
  if (isUnauthenticated)
16733
17086
  closeModals();
16734
17087
  }, [isUnauthenticated, closeModals]);
@@ -16825,7 +17178,7 @@ function ConnectButtonRenderer({
16825
17178
  const isMounted = useIsMounted();
16826
17179
  const { address } = useAccount21();
16827
17180
  const { chainId } = useAccount21();
16828
- const { chains: wagmiChains } = useConfig5();
17181
+ const { chains: wagmiChains } = useConfig6();
16829
17182
  const isCurrentChainSupported = wagmiChains.some(
16830
17183
  (chain) => chain.id === chainId
16831
17184
  );
@@ -16913,12 +17266,12 @@ function ConnectButton({
16913
17266
  "bitcoin",
16914
17267
  "solana"
16915
17268
  ];
16916
- useEffect38(() => {
17269
+ useEffect39(() => {
16917
17270
  setShowBalance(showBalance);
16918
17271
  if (!ready)
16919
17272
  setReady(true);
16920
17273
  }, [showBalance, setShowBalance]);
16921
- useEffect38(() => {
17274
+ useEffect39(() => {
16922
17275
  const interval = setInterval(() => {
16923
17276
  setRollingChainIndex((prev) => (prev + 1) % chainTypes.length);
16924
17277
  }, 1e4);
@@ -17200,7 +17553,7 @@ var maxWidth = "hk857q1";
17200
17553
  // src/components/WalletButton/WalletButtonRenderer.tsx
17201
17554
  import React106, {
17202
17555
  useContext as useContext33,
17203
- useEffect as useEffect39,
17556
+ useEffect as useEffect40,
17204
17557
  useMemo as useMemo25,
17205
17558
  useState as useState46
17206
17559
  } from "react";
@@ -17224,7 +17577,7 @@ function WalletButtonRenderer({
17224
17577
  const [loading, setLoading] = useState46(false);
17225
17578
  const [isError, setIsError] = useState46(false);
17226
17579
  const mobile = isMobile();
17227
- useEffect39(() => {
17580
+ useEffect40(() => {
17228
17581
  if (!connectModalOpen && connector)
17229
17582
  setConnector(null);
17230
17583
  }, [connectModalOpen, connector, setConnector]);
@@ -18131,7 +18484,7 @@ var __private__ = {
18131
18484
  };
18132
18485
 
18133
18486
  // src/hooks/useDeviceType.ts
18134
- import { useEffect as useEffect40, useState as useState47 } from "react";
18487
+ import { useEffect as useEffect41, useState as useState47 } from "react";
18135
18488
  var BREAKPOINTS = {
18136
18489
  mobile: 1024,
18137
18490
  // 0-1024px (includes phones and tablets)
@@ -18156,7 +18509,7 @@ function useDeviceType() {
18156
18509
  }
18157
18510
  return getDeviceState(window.innerWidth);
18158
18511
  });
18159
- useEffect40(() => {
18512
+ useEffect41(() => {
18160
18513
  setState(getDeviceState(window.innerWidth));
18161
18514
  function handleResize() {
18162
18515
  setState(getDeviceState(window.innerWidth));
@@ -18168,7 +18521,7 @@ function useDeviceType() {
18168
18521
  }
18169
18522
 
18170
18523
  // src/hooks/useWalletCapabilities.ts
18171
- import { useCallback as useCallback30, useEffect as useEffect41, useState as useState48 } from "react";
18524
+ import { useCallback as useCallback30, useEffect as useEffect42, useState as useState48 } from "react";
18172
18525
  import { useAccount as useAccount24, useWalletClient } from "wagmi";
18173
18526
 
18174
18527
  // src/wallets/capabilities/requestWalletAction.ts
@@ -18376,7 +18729,7 @@ function useWalletCapabilities() {
18376
18729
  setIsLoading(false);
18377
18730
  }
18378
18731
  }, [address, connector?.id, connector?.name, isConnected, walletClient]);
18379
- useEffect41(() => {
18732
+ useEffect42(() => {
18380
18733
  void refresh();
18381
18734
  }, [refresh]);
18382
18735
  const signAuthorization = useCallback30(
@@ -18476,13 +18829,13 @@ function getSolanaConfig(options = {}) {
18476
18829
  }
18477
18830
 
18478
18831
  // src/wallets/walletConnectors/abcWallet/AbcEvmAutoConnector.tsx
18479
- import { useEffect as useEffect42, useRef as useRef20 } from "react";
18832
+ import { useEffect as useEffect43, useRef as useRef21 } from "react";
18480
18833
  import { useAccount as useAccount25, useConnect as useConnect3 } from "wagmi";
18481
18834
  function AbcEvmAutoConnector() {
18482
18835
  const { connectors, connect } = useConnect3();
18483
18836
  const { isConnected } = useAccount25();
18484
- const hasAttemptedRef = useRef20(false);
18485
- useEffect42(() => {
18837
+ const hasAttemptedRef = useRef21(false);
18838
+ useEffect43(() => {
18486
18839
  if (isConnected || hasAttemptedRef.current) {
18487
18840
  return;
18488
18841
  }
@@ -18541,13 +18894,118 @@ function ChainIndicator({
18541
18894
  ), showName && /* @__PURE__ */ React109.createElement(Text, { color: "modalText", className: chainName }, resolvedName), showBadge && /* @__PURE__ */ React109.createElement("div", { className: chainBadge }));
18542
18895
  }
18543
18896
 
18897
+ // src/services/AbcAuthService.ts
18898
+ async function registerUser(params, _config) {
18899
+ const api = getTalkenApiClient();
18900
+ if (!api) {
18901
+ throw new Error("TalkenApiClient not initialized");
18902
+ }
18903
+ const res = await api.auth.register({
18904
+ email: params.username,
18905
+ otpCode: params.emailCode,
18906
+ password: params.password,
18907
+ name: params.name
18908
+ });
18909
+ return { status: "success", data: res };
18910
+ }
18911
+ async function registerSnsUser(params, _config) {
18912
+ const api = getTalkenApiClient();
18913
+ if (!api) {
18914
+ throw new Error("TalkenApiClient not initialized");
18915
+ }
18916
+ const res = await api.auth.register({
18917
+ email: params.username,
18918
+ otpCode: params.sixCode,
18919
+ password: "",
18920
+ name: params.name
18921
+ });
18922
+ return { status: "success", data: res };
18923
+ }
18924
+ async function resetPassword(params, _config) {
18925
+ const api = getTalkenApiClient();
18926
+ if (!api) {
18927
+ throw new Error("TalkenApiClient not initialized");
18928
+ }
18929
+ const res = await api.auth.resetPassword(
18930
+ params.username,
18931
+ params.password,
18932
+ params.emailCode
18933
+ );
18934
+ return { status: "success", data: res };
18935
+ }
18936
+ async function emailCheck(email, _config) {
18937
+ const api = getTalkenApiClient();
18938
+ if (!api) {
18939
+ throw new Error("TalkenApiClient not initialized");
18940
+ }
18941
+ const res = await api.auth.checkEmail(email);
18942
+ return {
18943
+ status: "success",
18944
+ message: { code: res.code || 0, text: res.message || "" }
18945
+ };
18946
+ }
18947
+ async function sendOtpCode(email, _config) {
18948
+ const api = getTalkenApiClient();
18949
+ if (!api) {
18950
+ throw new Error("TalkenApiClient not initialized");
18951
+ }
18952
+ await api.auth.sendOtp(email);
18953
+ return { status: "success", data: { sent: true } };
18954
+ }
18955
+ async function verifyOtpCode(email, code, _config) {
18956
+ const api = getTalkenApiClient();
18957
+ if (!api) {
18958
+ throw new Error("TalkenApiClient not initialized");
18959
+ }
18960
+ await api.auth.verifyOtp(email, code);
18961
+ return { status: "success", data: { verified: true } };
18962
+ }
18963
+ async function loginWithPassword(params, _apiServer) {
18964
+ const api = getTalkenApiClient();
18965
+ if (!api) {
18966
+ throw new Error("TalkenApiClient not initialized");
18967
+ }
18968
+ const res = await api.auth.loginWithPassword(
18969
+ params.username,
18970
+ params.password
18971
+ );
18972
+ return {
18973
+ access_token: res.accessToken,
18974
+ refresh_token: res.refreshToken,
18975
+ expires_in: res.expiresIn,
18976
+ uid: res.uid,
18977
+ email: res.email
18978
+ };
18979
+ }
18980
+ async function performSnsLogin(token, service, email) {
18981
+ const api = getTalkenApiClient();
18982
+ if (!api) {
18983
+ throw new Error("TalkenApiClient not initialized");
18984
+ }
18985
+ const res = await api.auth.loginWithSns({ token, service });
18986
+ return {
18987
+ uid: res.uid,
18988
+ access_token: res.accessToken,
18989
+ refresh_token: res.refreshToken,
18990
+ email: res.email || email,
18991
+ user_type: res.isNewUser ? "new" : "existing"
18992
+ };
18993
+ }
18994
+ async function kakaoLogin2(_config) {
18995
+ const kakaoAuth = await kakaoLogin();
18996
+ if (!kakaoAuth)
18997
+ return null;
18998
+ return performSnsLogin(kakaoAuth.idToken, "kakao", kakaoAuth.email);
18999
+ }
19000
+
18544
19001
  // src/providers/AbcAuthProvider.tsx
18545
19002
  import React110, {
18546
19003
  createContext as createContext22,
18547
19004
  useContext as useContext36,
18548
19005
  useState as useState49,
18549
- useEffect as useEffect43,
18550
- useCallback as useCallback31
19006
+ useEffect as useEffect44,
19007
+ useCallback as useCallback31,
19008
+ useRef as useRef22
18551
19009
  } from "react";
18552
19010
  var logger28 = createLogger("AbcAuthProvider");
18553
19011
  var AbcAuthContext = createContext22(null);
@@ -18579,12 +19037,19 @@ function AbcAuthProvider({ children }) {
18579
19037
  },
18580
19038
  pinHash: null
18581
19039
  });
19040
+ const authGeneration = useRef22(0);
19041
+ useEffect44(
19042
+ () => () => {
19043
+ authGeneration.current++;
19044
+ },
19045
+ []
19046
+ );
18582
19047
  const isTokenExpired = useCallback31(() => {
18583
19048
  if (!state.tokens.expiresAt)
18584
19049
  return true;
18585
19050
  return Date.now() >= state.tokens.expiresAt;
18586
19051
  }, [state.tokens.expiresAt]);
18587
- useEffect43(() => {
19052
+ useEffect44(() => {
18588
19053
  if (state.tokens.expiresAt && state.tokens.expiresAt > Date.now()) {
18589
19054
  scheduleProactiveRefresh(state.tokens.expiresAt);
18590
19055
  }
@@ -18599,27 +19064,32 @@ function AbcAuthProvider({ children }) {
18599
19064
  logger28.debug("No refresh token available");
18600
19065
  return false;
18601
19066
  }
19067
+ const generation = authGeneration.current;
19068
+ const storedAuth = get(STORAGE_NS.ABC, "auth_state");
19069
+ const api = getTalkenApiClient();
19070
+ const revision = api?.getSessionRevision();
19071
+ const isCurrent = () => authGeneration.current === generation && getTalkenApiClient() === api && api?.getSessionRevision() === revision && !!api && ownsTalkenApiStorage(api) && get(STORAGE_NS.ABC, "auth_state") === storedAuth;
18602
19072
  try {
18603
- const api = getTalkenApiClient();
18604
19073
  if (!api) {
18605
19074
  logger28.error("TalkenApiClient not initialized");
18606
19075
  return false;
18607
19076
  }
18608
- api.setTokens(
18609
- state.tokens.accessToken || "",
18610
- state.tokens.refreshToken,
18611
- state.tokens.expiresAt || 0
18612
- );
19077
+ if (api.isAccessKeyMode() || api.getAccessToken() !== state.tokens.accessToken || api.getRefreshToken() !== state.tokens.refreshToken)
19078
+ return false;
18613
19079
  const res = await api.auth.refresh();
19080
+ if (!isCurrent())
19081
+ return false;
18614
19082
  const expiresAt = Date.now() + res.expiresIn * 1e3;
18615
- setState((prev) => ({
18616
- ...prev,
18617
- tokens: {
18618
- accessToken: res.accessToken,
18619
- refreshToken: res.refreshToken || prev.tokens.refreshToken,
18620
- expiresAt
18621
- }
18622
- }));
19083
+ setState(
19084
+ (prev) => isCurrent() ? {
19085
+ ...prev,
19086
+ tokens: {
19087
+ accessToken: res.accessToken,
19088
+ refreshToken: res.refreshToken || prev.tokens.refreshToken,
19089
+ expiresAt
19090
+ }
19091
+ } : prev
19092
+ );
18623
19093
  set(STORAGE_NS.ABC, "access_token", res.accessToken);
18624
19094
  if (res.refreshToken) {
18625
19095
  set(STORAGE_NS.ABC, "refresh_token", res.refreshToken);
@@ -18629,26 +19099,34 @@ function AbcAuthProvider({ children }) {
18629
19099
  logger28.info("Token refreshed");
18630
19100
  return true;
18631
19101
  } catch (error2) {
19102
+ if (!isCurrent())
19103
+ return false;
18632
19104
  logger28.error("Token refresh error:", error2);
18633
19105
  return false;
18634
19106
  }
18635
- }, [
18636
- state.tokens.refreshToken,
18637
- state.tokens.accessToken,
18638
- state.tokens.expiresAt
18639
- ]);
19107
+ }, [state.tokens.refreshToken, state.tokens.accessToken]);
18640
19108
  const unlockWithPin = useCallback31(async (pin) => {
19109
+ const api = getTalkenApiClient();
19110
+ const revision = api?.getSessionRevision();
19111
+ const generation = authGeneration.current;
19112
+ const storedAuth = get(STORAGE_NS.ABC, "auth_state");
19113
+ const credentials = JSON.stringify([
19114
+ api?.getAccessToken(),
19115
+ api?.getRefreshToken()
19116
+ ]);
19117
+ const encryptedTokens = get(STORAGE_NS.ABC, "enc_tokens");
19118
+ const saltHex = get(STORAGE_NS.ABC, "enc_salt");
19119
+ const storedPinHash = getCredentialManager().getPinHash();
19120
+ const isCurrent = () => authGeneration.current === generation && getTalkenApiClient() === api && api?.getSessionRevision() === revision && !!api && ownsTalkenApiStorage(api) && JSON.stringify([api?.getAccessToken(), api?.getRefreshToken()]) === credentials && get(STORAGE_NS.ABC, "auth_state") === storedAuth && get(STORAGE_NS.ABC, "enc_tokens") === encryptedTokens && get(STORAGE_NS.ABC, "enc_salt") === saltHex && getCredentialManager().getPinHash() === storedPinHash;
18641
19121
  try {
18642
- const encryptedTokens = get(STORAGE_NS.ABC, "enc_tokens");
18643
- const saltHex = get(STORAGE_NS.ABC, "enc_salt");
18644
- const { getCredentialManager: getCredentialManager2 } = await import("./AbcCredentialManager-QM2BNLSR.js");
18645
- const storedPinHash = getCredentialManager2().getPinHash();
18646
19122
  if (!encryptedTokens || !saltHex || !storedPinHash) {
18647
19123
  throw new Error("No encrypted data found");
18648
19124
  }
18649
19125
  const encoder = new TextEncoder();
18650
19126
  const data = encoder.encode(pin);
18651
19127
  const hash = await crypto.subtle.digest("SHA-256", data);
19128
+ if (!isCurrent())
19129
+ return false;
18652
19130
  const hashedPin = Array.from(new Uint8Array(hash)).map((b) => b.toString(16).padStart(2, "0")).join("");
18653
19131
  if (hashedPin !== storedPinHash) {
18654
19132
  throw new Error("Incorrect PIN");
@@ -18658,32 +19136,49 @@ function AbcAuthProvider({ children }) {
18658
19136
  hashedPin,
18659
19137
  saltHex
18660
19138
  );
19139
+ if (!isCurrent())
19140
+ return false;
18661
19141
  const sensitiveData = JSON.parse(decrypted);
18662
- setState((prev) => ({
18663
- ...prev,
18664
- isAuthenticated: true,
18665
- tokens: {
18666
- accessToken: sensitiveData.accessToken,
18667
- refreshToken: sensitiveData.refreshToken,
18668
- expiresAt: sensitiveData.expiresAt || Date.now() + 6e5
18669
- },
18670
- wallets: {
18671
- evm: sensitiveData.evmWallet || null,
18672
- solana: sensitiveData.solanaWallet || null,
18673
- bitcoin: sensitiveData.bitcoinWallet || null,
18674
- tron: sensitiveData.tronWallet || null,
18675
- xrpl: sensitiveData.xrplWallet || null
18676
- },
18677
- pinHash: hashedPin
18678
- }));
19142
+ const persisted = JSON.parse(storedAuth || "null");
19143
+ if (api?.isAccessKeyMode() || [api?.getAccessToken(), persisted?.accessToken].some(
19144
+ (token) => token && token !== sensitiveData.accessToken
19145
+ ) || [api?.getRefreshToken(), persisted?.refreshToken].some(
19146
+ (token) => token && token !== sensitiveData.refreshToken
19147
+ ))
19148
+ return false;
19149
+ setState(
19150
+ (prev) => isCurrent() ? {
19151
+ ...prev,
19152
+ isAuthenticated: true,
19153
+ tokens: {
19154
+ accessToken: sensitiveData.accessToken,
19155
+ refreshToken: sensitiveData.refreshToken,
19156
+ expiresAt: sensitiveData.expiresAt || Date.now() + 6e5
19157
+ },
19158
+ wallets: {
19159
+ evm: sensitiveData.evmWallet || null,
19160
+ solana: sensitiveData.solanaWallet || null,
19161
+ bitcoin: sensitiveData.bitcoinWallet || null,
19162
+ tron: sensitiveData.tronWallet || null,
19163
+ xrpl: sensitiveData.xrplWallet || null
19164
+ },
19165
+ pinHash: hashedPin
19166
+ } : prev
19167
+ );
18679
19168
  logger28.info("Unlocked with PIN");
18680
19169
  return true;
18681
19170
  } catch (error2) {
19171
+ if (!isCurrent())
19172
+ return false;
18682
19173
  logger28.error("Unlock failed:", error2);
18683
19174
  return false;
18684
19175
  }
18685
19176
  }, []);
18686
19177
  const logout = useCallback31(async () => {
19178
+ authGeneration.current++;
19179
+ const api = getTalkenApiClient();
19180
+ api?.clearSession();
19181
+ const ownsStorage = !!api && ownsTalkenApiStorage(api);
18687
19182
  setState({
18688
19183
  isAuthenticated: false,
18689
19184
  user: { email: null, uid: null },
@@ -18697,20 +19192,20 @@ function AbcAuthProvider({ children }) {
18697
19192
  },
18698
19193
  pinHash: null
18699
19194
  });
19195
+ if (!ownsStorage)
19196
+ return;
19197
+ cancelProactiveRefresh();
19198
+ getCredentialManager().clear();
18700
19199
  clearNamespace(STORAGE_NS.ABC);
18701
19200
  clearNamespace(STORAGE_NS.ABC, "session");
18702
19201
  remove(STORAGE_NS.API, "access_key_raw");
18703
- try {
18704
- const { getTalkenApiClient: getTalkenApiClient4 } = await import("./TalkenApiSingleton-TECFDCT4.js");
18705
- getTalkenApiClient4()?.clearSession();
18706
- } catch {
18707
- }
18708
19202
  logger28.info("Logged out");
18709
19203
  }, []);
18710
19204
  const setAuthState = useCallback31((partial) => {
19205
+ authGeneration.current++;
18711
19206
  setState((prev) => ({ ...prev, ...partial }));
18712
19207
  }, []);
18713
- useEffect43(() => {
19208
+ useEffect44(() => {
18714
19209
  const restoreSession = async () => {
18715
19210
  try {
18716
19211
  const authState = getJSON(STORAGE_NS.ABC, "auth_state");
@@ -18787,8 +19282,11 @@ function AbcAuthProvider({ children }) {
18787
19282
  );
18788
19283
  };
18789
19284
  }, []);
18790
- useEffect43(() => {
18791
- const handleExpired = () => {
19285
+ useEffect44(() => {
19286
+ const handleExpired = (event) => {
19287
+ const isCurrent = event.detail?.isCurrent;
19288
+ if (typeof isCurrent !== "function" || !isCurrent())
19289
+ return;
18792
19290
  logger28.info("Access key expired \u2014 logging out");
18793
19291
  logout();
18794
19292
  };
@@ -18811,73 +19309,115 @@ import React111, {
18811
19309
  createContext as createContext23,
18812
19310
  useContext as useContext37,
18813
19311
  useState as useState50,
18814
- useCallback as useCallback32
19312
+ useCallback as useCallback32,
19313
+ useRef as useRef23,
19314
+ useEffect as useEffect45
18815
19315
  } from "react";
18816
19316
  var PinContext = createContext23(null);
19317
+ var pinSessionChangedError = () => Object.assign(
19318
+ new Error("The wallet session changed. Please request PIN again."),
19319
+ { code: "AUTH_SESSION_CHANGED" }
19320
+ );
18817
19321
  function PinProvider({ children }) {
18818
19322
  const [isModalOpen, setIsModalOpen] = useState50(false);
18819
19323
  const [purpose, setPurpose] = useState50("transaction");
18820
- const [pinResolver, setPinResolver] = useState50(null);
18821
- const [pinRejecter, setPinRejecter] = useState50(null);
18822
- const [error2, setError] = useState50("");
19324
+ const [pending, setPending] = useState50(null);
19325
+ const pendingRef = useRef23(null);
19326
+ const nextModal = useRef23(0);
19327
+ const isCurrent = (request) => pendingRef.current === request && getTalkenApiClient() === request.api && request.api.getSessionRevision() === request.revision && ownsTalkenApiStorage(request.api) && getCredentialManager().getPinHash() === request.pinHash;
19328
+ useEffect45(
19329
+ () => () => {
19330
+ pendingRef.current?.reject(pinSessionChangedError());
19331
+ pendingRef.current = null;
19332
+ },
19333
+ []
19334
+ );
18823
19335
  const requestPin = useCallback32(
18824
19336
  (requestPurpose = "transaction") => {
19337
+ const api = getTalkenApiClient();
19338
+ const revision = api?.getSessionRevision();
19339
+ if (!api || !ownsTalkenApiStorage(api))
19340
+ return Promise.reject(pinSessionChangedError());
19341
+ pendingRef.current?.reject(pinSessionChangedError());
18825
19342
  return new Promise((resolve, reject) => {
19343
+ const request = {
19344
+ id: ++nextModal.current,
19345
+ api,
19346
+ revision,
19347
+ pinHash: getCredentialManager().getPinHash(),
19348
+ resolve,
19349
+ reject
19350
+ };
19351
+ pendingRef.current = request;
19352
+ setPending(request);
18826
19353
  setPurpose(requestPurpose);
18827
19354
  setIsModalOpen(true);
18828
- setError("");
18829
- setPinResolver(() => resolve);
18830
- setPinRejecter(() => reject);
18831
19355
  });
18832
19356
  },
18833
19357
  []
18834
19358
  );
18835
- const handlePinSubmit = useCallback32(
18836
- async (pin) => {
18837
- if (!pinResolver) {
19359
+ const closeRequest = (request) => {
19360
+ if (pendingRef.current !== request)
19361
+ return;
19362
+ pendingRef.current = null;
19363
+ setPending(null);
19364
+ setIsModalOpen(false);
19365
+ };
19366
+ const handlePinSubmit = async (pin) => {
19367
+ const request = pending;
19368
+ if (!request)
19369
+ return;
19370
+ if (!isCurrent(request)) {
19371
+ request.reject(pinSessionChangedError());
19372
+ closeRequest(request);
19373
+ return;
19374
+ }
19375
+ if (!request.pinHash)
19376
+ throw new Error("PIN not set. Please login again.");
19377
+ try {
19378
+ const enteredPinHash = await hashPin(pin);
19379
+ if (!isCurrent(request)) {
19380
+ request.reject(pinSessionChangedError());
19381
+ closeRequest(request);
18838
19382
  return;
18839
19383
  }
18840
- const { getCredentialManager: getCredentialManager2 } = await import("./AbcCredentialManager-QM2BNLSR.js");
18841
- const storedPinHash = getCredentialManager2().getPinHash();
18842
- if (!storedPinHash) {
18843
- throw new Error("PIN not set. Please login again.");
18844
- }
18845
- const enteredPinHash = await hashPin(pin);
18846
- if (enteredPinHash !== storedPinHash) {
19384
+ if (enteredPinHash !== request.pinHash)
18847
19385
  throw new Error("Incorrect PIN. Please try again.");
19386
+ request.resolve(pin);
19387
+ closeRequest(request);
19388
+ } catch (error2) {
19389
+ if (!isCurrent(request)) {
19390
+ request.reject(pinSessionChangedError());
19391
+ closeRequest(request);
19392
+ return;
18848
19393
  }
18849
- pinResolver(pin);
18850
- setIsModalOpen(false);
18851
- setPinResolver(null);
18852
- setPinRejecter(null);
18853
- setError("");
18854
- },
18855
- [pinResolver]
18856
- );
18857
- const handleModalClose = useCallback32(() => {
18858
- if (pinRejecter) {
18859
- const error3 = new Error("User cancelled PIN request");
18860
- error3.code = 4001;
18861
- error3.cancelled = true;
18862
- pinRejecter(error3);
18863
- setIsModalOpen(false);
18864
- setPinResolver(null);
18865
- setPinRejecter(null);
18866
- setError("");
19394
+ throw error2;
18867
19395
  }
18868
- }, [pinRejecter]);
19396
+ };
19397
+ const handleModalClose = () => {
19398
+ const request = pending;
19399
+ if (!request || pendingRef.current !== request)
19400
+ return;
19401
+ const error2 = Object.assign(new Error("User cancelled PIN request"), {
19402
+ code: 4001,
19403
+ cancelled: true
19404
+ });
19405
+ request.reject(error2);
19406
+ closeRequest(request);
19407
+ };
18869
19408
  const value2 = {
18870
19409
  requestPin
18871
19410
  };
18872
19411
  return /* @__PURE__ */ React111.createElement(PinContext.Provider, { value: value2 }, children, /* @__PURE__ */ React111.createElement(
18873
19412
  PinInputModal,
18874
19413
  {
19414
+ key: pending?.id ?? "closed",
18875
19415
  isOpen: isModalOpen,
18876
19416
  onClose: handleModalClose,
18877
19417
  onSubmit: handlePinSubmit,
18878
19418
  title: purpose === "transaction" ? "Confirm Transaction" : "Enter PIN",
18879
19419
  subtitle: purpose === "transaction" ? "Enter your PIN to sign this transaction" : "Enter your 6-digit PIN",
18880
- errorMessage: error2,
19420
+ errorMessage: "",
18881
19421
  showForgotPin: false
18882
19422
  }
18883
19423
  ));
@@ -19060,8 +19600,8 @@ function embeddedTxToWagmi(embeddedTx) {
19060
19600
  }
19061
19601
 
19062
19602
  // src/gasless/hooks/useGaslessTransfer.ts
19063
- import { useCallback as useCallback34, useEffect as useEffect44, useRef as useRef21, useState as useState51 } from "react";
19064
- import { useAccount as useAccount26, usePublicClient as usePublicClient2, useWalletClient as useWalletClient2 } from "wagmi";
19603
+ import { useCallback as useCallback34, useEffect as useEffect46, useRef as useRef24, useState as useState51 } from "react";
19604
+ import { useAccount as useAccount26, useConfig as useConfig7, usePublicClient as usePublicClient2, useWalletClient as useWalletClient2 } from "wagmi";
19065
19605
 
19066
19606
  // src/gasless/signer/WagmiSigner.ts
19067
19607
  var MAX_RETRY = 3;
@@ -19081,13 +19621,132 @@ var WagmiSigner = class {
19081
19621
  this.walletClient = params.walletClient;
19082
19622
  this.publicClient = params.publicClient;
19083
19623
  this._supportsAuth = params.supportsAuthorization ?? false;
19624
+ this.assertOrigin = params.assertSessionCurrent;
19625
+ const account = params.walletClient.account;
19626
+ this.originAccount = typeof account === "object" ? { ...account } : account;
19627
+ this.originAddress = this.accountAddress()?.toLowerCase();
19628
+ this.originChain = params.walletClient.chain ? { ...params.walletClient.chain } : void 0;
19629
+ this.originChainId = params.walletClient.chain?.id;
19630
+ }
19631
+ accountAddress() {
19632
+ const account = this.walletClient.account;
19633
+ return typeof account === "string" ? account : account?.address;
19634
+ }
19635
+ assertSessionCurrent() {
19636
+ if (!this.assertOrigin || !this.originAddress || !this.originChainId)
19637
+ throw new TalkenApiError(
19638
+ "AUTH_SESSION_UNBOUND",
19639
+ "An originating external wallet connection is required.",
19640
+ 401
19641
+ );
19642
+ this.assertOrigin();
19643
+ if (this.accountAddress()?.toLowerCase() !== this.originAddress || this.walletClient.chain?.id !== this.originChainId || this.publicClient.chain && this.publicClient.chain.id !== this.originChainId)
19644
+ throw new TalkenApiError(
19645
+ "AUTH_SESSION_CHANGED",
19646
+ "The originating external account or chain changed.",
19647
+ 401
19648
+ );
19649
+ }
19650
+ assertRequestedOrigin(address, chainId) {
19651
+ this.assertSessionCurrent();
19652
+ if (address !== void 0 && address.toLowerCase() !== this.originAddress || chainId !== void 0 && chainId !== this.originChainId)
19653
+ throw new TalkenApiError(
19654
+ "AUTH_SESSION_CHANGED",
19655
+ "The request does not match the originating external account and chain.",
19656
+ 401
19657
+ );
19658
+ }
19659
+ assertDelegationOrigin(chainKey, address) {
19660
+ this.assertRequestedOrigin(address);
19661
+ let originChainKey;
19662
+ try {
19663
+ originChainKey = getChainKey(this.originChainId);
19664
+ } catch {
19665
+ throw new TalkenApiError(
19666
+ "AUTH_SESSION_UNBOUND",
19667
+ "The originating external chain is unsupported.",
19668
+ 401
19669
+ );
19670
+ }
19671
+ if (chainKey !== originChainKey)
19672
+ throw new TalkenApiError(
19673
+ "AUTH_SESSION_CHANGED",
19674
+ "The delegation lookup does not match the originating chain.",
19675
+ 401
19676
+ );
19677
+ }
19678
+ async withSession(operation) {
19679
+ this.assertSessionCurrent();
19680
+ try {
19681
+ const result = await operation();
19682
+ this.assertSessionCurrent();
19683
+ return result;
19684
+ } catch (error2) {
19685
+ this.assertSessionCurrent();
19686
+ throw error2;
19687
+ }
19688
+ }
19689
+ getDelegationClient() {
19690
+ const readCode = this.publicClient.getCode;
19691
+ if (!readCode)
19692
+ return null;
19693
+ return {
19694
+ readCode: (chainKey, address) => this.withSession(async () => {
19695
+ this.assertDelegationOrigin(chainKey, address);
19696
+ return await readCode.call(this.publicClient, {
19697
+ address
19698
+ }) ?? "0x";
19699
+ }),
19700
+ revoke: (chainKey, chainId, address) => this.withSession(async () => {
19701
+ this.assertDelegationOrigin(chainKey, address);
19702
+ this.assertRequestedOrigin(address, chainId);
19703
+ const sign = this.walletClient.signAuthorization;
19704
+ const send = this.walletClient.sendTransaction;
19705
+ if (!sign || !send)
19706
+ throw new TalkenApiError(
19707
+ "EXTERNAL_REVOKE_UNSUPPORTED",
19708
+ "This wallet cannot sign and send an EIP-7702 revoke.",
19709
+ 400
19710
+ );
19711
+ return sendRevokeViaWalletClient(
19712
+ {
19713
+ assertSessionCurrent: () => this.assertSessionCurrent(),
19714
+ getTransactionCount: (args) => this.withSession(
19715
+ () => this.publicClient.getTransactionCount(args)
19716
+ ),
19717
+ signAuthorization: (args) => this.withSession(
19718
+ () => sign.call(this.walletClient, {
19719
+ ...args,
19720
+ account: this.originAccount
19721
+ })
19722
+ ),
19723
+ sendTransaction: (args) => this.withSession(
19724
+ () => send.call(this.walletClient, {
19725
+ ...args,
19726
+ account: this.originAccount,
19727
+ chain: this.originChain
19728
+ })
19729
+ ),
19730
+ ...this.publicClient.waitForTransactionReceipt && {
19731
+ waitForTransactionReceipt: (args) => this.withSession(
19732
+ () => this.publicClient.waitForTransactionReceipt(args)
19733
+ )
19734
+ }
19735
+ },
19736
+ chainId,
19737
+ address
19738
+ );
19739
+ })
19740
+ };
19084
19741
  }
19085
19742
  supportsAuthorization() {
19086
19743
  return this._supportsAuth && typeof this.walletClient.signAuthorization === "function";
19087
19744
  }
19088
19745
  async signTypedData(typedData) {
19746
+ this.assertRequestedOrigin(void 0, typedData.domain.chainId);
19089
19747
  return this.withRetry(
19090
19748
  () => this.walletClient.signTypedData({
19749
+ account: this.originAccount,
19091
19750
  domain: typedData.domain,
19092
19751
  types: typedData.types,
19093
19752
  primaryType: typedData.primaryType,
@@ -19096,11 +19755,13 @@ var WagmiSigner = class {
19096
19755
  );
19097
19756
  }
19098
19757
  async signAuthorization(authorization) {
19758
+ this.assertRequestedOrigin(void 0, authorization.chainId);
19099
19759
  if (!this.supportsAuthorization()) {
19100
19760
  throw new Error("This wallet does not support EIP-7702 authorization");
19101
19761
  }
19102
19762
  const result = await this.withRetry(
19103
19763
  () => this.walletClient.signAuthorization({
19764
+ account: this.originAccount,
19104
19765
  contractAddress: authorization.address,
19105
19766
  chainId: authorization.chainId,
19106
19767
  nonce: authorization.nonce
@@ -19116,10 +19777,13 @@ var WagmiSigner = class {
19116
19777
  };
19117
19778
  }
19118
19779
  async getNonce(address) {
19119
- return this.publicClient.getTransactionCount({
19120
- address,
19121
- blockTag: "pending"
19122
- });
19780
+ this.assertRequestedOrigin(address);
19781
+ return this.withSession(
19782
+ () => this.publicClient.getTransactionCount({
19783
+ address,
19784
+ blockTag: "pending"
19785
+ })
19786
+ );
19123
19787
  }
19124
19788
  /**
19125
19789
  * Retry wrapper. Retries on transient errors but NOT on user rejection.
@@ -19127,10 +19791,12 @@ var WagmiSigner = class {
19127
19791
  async withRetry(fn) {
19128
19792
  let lastError = null;
19129
19793
  for (let attempt = 0; attempt < MAX_RETRY; attempt++) {
19794
+ this.assertSessionCurrent();
19130
19795
  try {
19131
- return await fn();
19796
+ return await this.withSession(fn);
19132
19797
  } catch (error2) {
19133
- if (isUserRejection(error2))
19798
+ this.assertSessionCurrent();
19799
+ if (isUserRejection(error2) || error2?.code === "AUTH_SESSION_CHANGED" || error2?.code === "AUTH_SESSION_UNBOUND")
19134
19800
  throw error2;
19135
19801
  lastError = error2;
19136
19802
  if (attempt < MAX_RETRY - 1) {
@@ -19282,6 +19948,7 @@ function tryGetChainKey2(chainId) {
19282
19948
  function useGaslessTransfer(params) {
19283
19949
  const gaslessConfig = useGaslessConfig();
19284
19950
  const { connector } = useAccount26();
19951
+ const wagmiConfig = useConfig7();
19285
19952
  const { data: walletClient } = useWalletClient2();
19286
19953
  const publicClient = usePublicClient2();
19287
19954
  const [canGasless, setCanGasless] = useState51(false);
@@ -19292,48 +19959,81 @@ function useGaslessTransfer(params) {
19292
19959
  const [isExecuting, setIsExecuting] = useState51(false);
19293
19960
  const [error2, setError] = useState51(null);
19294
19961
  const [unavailableReason, setUnavailableReason] = useState51(null);
19295
- const feeServiceRef = useRef21(getSharedGaslessFeeService());
19296
- const abortRef = useRef21(0);
19297
- const executeLockRef = useRef21(Promise.resolve());
19298
- const mountedRef = useRef21(true);
19962
+ const feeServiceRef = useRef24(getSharedGaslessFeeService());
19963
+ const abortRef = useRef24(0);
19964
+ const executeLockRef = useRef24(Promise.resolve());
19965
+ const mountedRef = useRef24(true);
19299
19966
  const chainId = params?.chainId;
19300
19967
  const address = params?.address;
19301
19968
  const tokenAddress = params?.tokenAddress;
19302
19969
  const toAddress = params?.toAddress;
19303
19970
  const amount = params?.amount;
19304
19971
  const isAbcWallet = connector?.id === "abc";
19972
+ const originatingApi = isAbcWallet ? getTalkenApiClient() : void 0;
19973
+ const originatingRevision = originatingApi?.getSessionRevision();
19305
19974
  const signerSupportsAuth = isAbcWallet ? true : typeof walletClient?.signAuthorization === "function";
19306
19975
  const createSigner = useCallback34(() => {
19307
19976
  if (!chainId)
19308
19977
  return null;
19309
19978
  if (isAbcWallet) {
19979
+ const api = getTalkenApiClient();
19980
+ if (!api || api !== originatingApi || api.getSessionRevision() !== originatingRevision || !ownsTalkenApiStorage(api))
19981
+ return null;
19982
+ const session = api.isAccessKeyMode() ? api.getAuthenticatedWalletSession() : null;
19983
+ if (api.isAccessKeyMode() && (!session || !address || session.wallets.evm.toLowerCase() !== address.toLowerCase()))
19984
+ return null;
19310
19985
  const credentialManager = getCredentialManager();
19311
- const pinHash = credentialManager.getPinHash();
19312
- if (!pinHash)
19986
+ const pinHash = session ? void 0 : credentialManager.getPinHash() ?? void 0;
19987
+ if (!session && !pinHash)
19313
19988
  return null;
19314
19989
  return new AbcWaasSigner({
19315
19990
  pinHash,
19316
19991
  network: getNetworkName(chainId),
19317
- email: credentialManager.getEmail() ?? void 0
19992
+ email: session ? session.user.email ?? void 0 : credentialManager.getEmail() ?? void 0
19318
19993
  });
19319
19994
  }
19320
19995
  if (walletClient && publicClient) {
19996
+ const connection = wagmiConfig.state.connections.get(
19997
+ wagmiConfig.state.current ?? ""
19998
+ );
19999
+ if (wagmiConfig.state.status !== "connected" || !connection || connection.connector !== connector || connection.chainId !== chainId || !address || connection.accounts[0]?.toLowerCase() !== address.toLowerCase() || walletClient.account?.address.toLowerCase() !== address.toLowerCase())
20000
+ return null;
19321
20001
  return new WagmiSigner({
19322
20002
  walletClient,
19323
20003
  publicClient,
19324
- supportsAuthorization: true
20004
+ supportsAuthorization: true,
19325
20005
  // MetaMask supports EIP-7702
20006
+ assertSessionCurrent: () => {
20007
+ if (wagmiConfig.state.status !== "connected" || wagmiConfig.state.connections.get(
20008
+ wagmiConfig.state.current ?? ""
20009
+ ) !== connection)
20010
+ throw new TalkenApiError(
20011
+ "AUTH_SESSION_CHANGED",
20012
+ "The external wallet connection changed during the operation.",
20013
+ 401
20014
+ );
20015
+ }
19326
20016
  });
19327
20017
  }
19328
20018
  return null;
19329
- }, [isAbcWallet, chainId, walletClient, publicClient]);
19330
- useEffect44(() => {
20019
+ }, [
20020
+ isAbcWallet,
20021
+ chainId,
20022
+ address,
20023
+ walletClient,
20024
+ publicClient,
20025
+ originatingApi,
20026
+ originatingRevision,
20027
+ wagmiConfig,
20028
+ connector
20029
+ ]);
20030
+ useEffect46(() => {
19331
20031
  mountedRef.current = true;
19332
20032
  return () => {
19333
20033
  mountedRef.current = false;
19334
20034
  };
19335
20035
  }, []);
19336
- useEffect44(() => {
20036
+ useEffect46(() => {
19337
20037
  if (!gaslessConfig?.enabled || !chainId) {
19338
20038
  setFeeTokens([]);
19339
20039
  setCanGasless(false);
@@ -19446,7 +20146,7 @@ function useGaslessTransfer(params) {
19446
20146
  amount,
19447
20147
  signerSupportsAuth
19448
20148
  ]);
19449
- useEffect44(() => {
20149
+ useEffect46(() => {
19450
20150
  refreshEstimate();
19451
20151
  }, [refreshEstimate]);
19452
20152
  const execute = useCallback34(
@@ -19462,6 +20162,7 @@ function useGaslessTransfer(params) {
19462
20162
  throw new Error("Unsupported chain");
19463
20163
  const attempt = executeLockRef.current.catch(() => {
19464
20164
  }).then(async () => {
20165
+ signer.assertSessionCurrent?.();
19465
20166
  if (mountedRef.current) {
19466
20167
  setIsExecuting(true);
19467
20168
  setError(null);