@talken/talkenkit 2.8.5 → 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 (165) hide show
  1. package/dist/{abcWallet-EOHU5AIB.js → abcWallet-RPQPYWWR.js} +22 -25
  2. package/dist/{chunk-WGSS57V6.js → chunk-GS4L4ZIS.js} +2493 -696
  3. package/dist/gasless/index.d.ts +1 -1
  4. package/dist/gasless/services/GaslessTransferService.d.ts +2 -1
  5. package/dist/gasless/signer/AbcWaasSigner.d.ts +9 -0
  6. package/dist/gasless/signer/GaslessSigner.d.ts +10 -0
  7. package/dist/gasless/signer/WagmiSigner.d.ts +40 -0
  8. package/dist/gasless/signer/index.d.ts +1 -1
  9. package/dist/gasless/utils/delegationGuard.d.ts +11 -11
  10. package/dist/gasless/utils/revokeDelegation.d.ts +22 -23
  11. package/dist/hooks/useMultiChainBalances.d.ts +2 -0
  12. package/dist/index.css +17 -15
  13. package/dist/index.d.ts +2 -1
  14. package/dist/index.js +1279 -584
  15. package/dist/services/AbcAuthService.d.ts +12 -1
  16. package/dist/solana/clusterIdentity.d.ts +5 -0
  17. package/dist/wallets/walletConnectors/abcWallet/AbcCredentialManager.d.ts +0 -1
  18. package/dist/wallets/walletConnectors/abcWallet/AbcCredentialManager.js +1 -1
  19. package/dist/wallets/walletConnectors/abcWallet/AbcEvmAutoConnector.js +3 -3
  20. package/dist/wallets/walletConnectors/abcWallet/AbstractChainProvider.d.ts +11 -0
  21. package/dist/wallets/walletConnectors/abcWallet/AbstractChainProvider.js +5 -2
  22. package/dist/wallets/walletConnectors/abcWallet/abcBitcoinConnector.d.ts +2 -0
  23. package/dist/wallets/walletConnectors/abcWallet/abcBitcoinConnector.js +6 -4
  24. package/dist/wallets/walletConnectors/abcWallet/abcBitcoinProvider.d.ts +1 -0
  25. package/dist/wallets/walletConnectors/abcWallet/abcBitcoinProvider.js +9 -8
  26. package/dist/wallets/walletConnectors/abcWallet/abcConnector.js +22 -20
  27. package/dist/wallets/walletConnectors/abcWallet/abcProvider.d.ts +1 -0
  28. package/dist/wallets/walletConnectors/abcWallet/abcProvider.js +11 -10
  29. package/dist/wallets/walletConnectors/abcWallet/abcSolanaProvider.js +24 -22
  30. package/dist/wallets/walletConnectors/abcWallet/abcSolanaWalletAdapter.d.ts +3 -0
  31. package/dist/wallets/walletConnectors/abcWallet/abcSolanaWalletAdapter.js +182 -61
  32. package/dist/wallets/walletConnectors/abcWallet/abcTronProvider.d.ts +1 -0
  33. package/dist/wallets/walletConnectors/abcWallet/abcTronProvider.js +9 -8
  34. package/dist/wallets/walletConnectors/abcWallet/abcWallet.js +23 -21
  35. package/dist/wallets/walletConnectors/abcWallet/abcXrplProvider.d.ts +1 -0
  36. package/dist/wallets/walletConnectors/abcWallet/abcXrplProvider.js +9 -8
  37. package/dist/wallets/walletConnectors/abcWallet/api/AccessKeySessionBinding.d.ts +10 -0
  38. package/dist/wallets/walletConnectors/abcWallet/api/AccessKeySessionBinding.js +13 -0
  39. package/dist/wallets/walletConnectors/abcWallet/api/ConfigApi.js +4 -1
  40. package/dist/wallets/walletConnectors/abcWallet/api/GasApi.js +5 -1
  41. package/dist/wallets/walletConnectors/abcWallet/api/SolanaApi.js +5 -1
  42. package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiClient.d.ts +34 -12
  43. package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiClient.js +17 -14
  44. package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiSingleton.d.ts +6 -0
  45. package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiSingleton.js +10 -1
  46. package/dist/wallets/walletConnectors/abcWallet/api/TokenApi.js +4 -1
  47. package/dist/wallets/walletConnectors/abcWallet/api/WalletscanApi.js +12 -2
  48. package/dist/wallets/walletConnectors/abcWallet/api/index.js +24 -21
  49. package/dist/wallets/walletConnectors/abcWallet/api/modules/auth.d.ts +20 -10
  50. package/dist/wallets/walletConnectors/abcWallet/api/modules/auth.js +3 -3
  51. package/dist/wallets/walletConnectors/abcWallet/api/modules/bitcoin.js +10 -8
  52. package/dist/wallets/walletConnectors/abcWallet/api/modules/evm.d.ts +1 -1
  53. package/dist/wallets/walletConnectors/abcWallet/api/modules/evm.js +9 -7
  54. package/dist/wallets/walletConnectors/abcWallet/api/modules/executeBodies.js +5 -4
  55. package/dist/wallets/walletConnectors/abcWallet/api/modules/signBodies.js +3 -3
  56. package/dist/wallets/walletConnectors/abcWallet/api/modules/signingRefresh.js +5 -4
  57. package/dist/wallets/walletConnectors/abcWallet/api/modules/solana.js +6 -5
  58. package/dist/wallets/walletConnectors/abcWallet/api/modules/tron.js +9 -7
  59. package/dist/wallets/walletConnectors/abcWallet/api/modules/wallet.d.ts +2 -1
  60. package/dist/wallets/walletConnectors/abcWallet/api/modules/wallet.js +1 -1
  61. package/dist/wallets/walletConnectors/abcWallet/api/modules/xrp.js +9 -7
  62. package/dist/wallets/walletConnectors/abcWallet/index.d.ts +1 -0
  63. package/dist/wallets/walletConnectors/abcWallet/index.js +45 -43
  64. package/dist/wallets/walletConnectors/abcWallet/sessionUtils.js +9 -1
  65. package/dist/wallets/walletConnectors/abcWallet/types/auth.types.d.ts +75 -0
  66. package/dist/wallets/walletConnectors/abcWallet/types/error.types.d.ts +2 -0
  67. package/dist/wallets/walletConnectors/abcWallet/types/error.types.js +5 -3
  68. package/dist/wallets/walletConnectors/abcWallet/types.js +9 -7
  69. package/dist/wallets/walletConnectors/abcWallet/utils.js +3 -3
  70. package/dist/wallets/walletConnectors/abcWallet/walletGeneration.js +5 -4
  71. package/dist/wallets/walletConnectors/berasigWallet/berasigWallet.js +2 -2
  72. package/dist/wallets/walletConnectors/bifrostWallet/bifrostWallet.js +2 -2
  73. package/dist/wallets/walletConnectors/binanceWallet/binanceWallet.js +2 -2
  74. package/dist/wallets/walletConnectors/bitgetWallet/bitgetWallet.js +2 -2
  75. package/dist/wallets/walletConnectors/bybitWallet/bybitWallet.js +2 -2
  76. package/dist/wallets/walletConnectors/chunk-4K2V7RCL.js +96 -0
  77. package/dist/wallets/walletConnectors/{chunk-4CKIGJZD.js → chunk-4MCD2P7Q.js} +79 -30
  78. package/dist/wallets/walletConnectors/chunk-4UMY2AY7.js +414 -0
  79. package/dist/wallets/walletConnectors/{chunk-F4JUKZBB.js → chunk-5IY2JM5V.js} +1 -1
  80. package/dist/wallets/walletConnectors/{chunk-XGQUYXTL.js → chunk-5KPLYJOO.js} +12 -407
  81. package/dist/wallets/walletConnectors/{chunk-DFG3BSSC.js → chunk-64X6Z6JH.js} +79 -30
  82. package/dist/wallets/walletConnectors/chunk-74OE3YZX.js +739 -0
  83. package/dist/wallets/walletConnectors/chunk-76M232IF.js +101 -0
  84. package/dist/wallets/walletConnectors/chunk-CEOJSQAI.js +66 -0
  85. package/dist/wallets/walletConnectors/{chunk-6X2XITQP.js → chunk-CMSHILRF.js} +2 -2
  86. package/dist/wallets/walletConnectors/chunk-CNKRIZ6T.js +246 -0
  87. package/dist/wallets/walletConnectors/{chunk-SORKIBWX.js → chunk-CO5DIPSI.js} +3 -4
  88. package/dist/wallets/walletConnectors/chunk-CTAFZ5RQ.js +71 -0
  89. package/dist/wallets/walletConnectors/chunk-DHWJ3552.js +93 -0
  90. package/dist/wallets/walletConnectors/{chunk-OMZSFUVN.js → chunk-DMZ3PH25.js} +6 -2
  91. package/dist/wallets/walletConnectors/{chunk-DKMR2ML5.js → chunk-DUEQONAP.js} +1 -1
  92. package/dist/wallets/walletConnectors/{chunk-SUPFF4EQ.js → chunk-EJWP6MEK.js} +530 -184
  93. package/dist/wallets/walletConnectors/{chunk-HMIFFMGK.js → chunk-EMNOGQO2.js} +2 -2
  94. package/dist/wallets/walletConnectors/{chunk-MNGSJBPX.js → chunk-EUHXX2SF.js} +128 -77
  95. package/dist/wallets/walletConnectors/{chunk-OTLZVWY7.js → chunk-EZVOMG73.js} +3 -1
  96. package/dist/wallets/walletConnectors/{chunk-EGLT3GPM.js → chunk-F2OS4PE2.js} +58 -7
  97. package/dist/wallets/walletConnectors/chunk-FE2BFYJB.js +73 -0
  98. package/dist/wallets/walletConnectors/chunk-FGYJTUYV.js +94 -0
  99. package/dist/wallets/walletConnectors/chunk-FVA6H2VF.js +95 -0
  100. package/dist/wallets/walletConnectors/chunk-GNF5CHDQ.js +102 -0
  101. package/dist/wallets/walletConnectors/{chunk-DRL2CDHT.js → chunk-GOUMVJSK.js} +80 -44
  102. package/dist/wallets/walletConnectors/{chunk-365TL36N.js → chunk-GUXCFLV3.js} +106 -53
  103. package/dist/wallets/walletConnectors/chunk-GZPGNUNF.js +94 -0
  104. package/dist/wallets/walletConnectors/chunk-H63QJV3U.js +84 -0
  105. package/dist/wallets/walletConnectors/chunk-HALTGRQW.js +87 -0
  106. package/dist/wallets/walletConnectors/{chunk-743DKBGG.js → chunk-ICDXVAE5.js} +70 -18
  107. package/dist/wallets/walletConnectors/{chunk-OTLPTGHO.js → chunk-KHBX3RMO.js} +3 -1
  108. package/dist/wallets/walletConnectors/chunk-KNNHGFKJ.js +98 -0
  109. package/dist/wallets/walletConnectors/chunk-KQDFRZT4.js +65 -0
  110. package/dist/wallets/walletConnectors/chunk-KQROIRBW.js +27 -0
  111. package/dist/wallets/walletConnectors/chunk-LKNK2KKU.js +76 -0
  112. package/dist/wallets/walletConnectors/{chunk-6MZWQBNQ.js → chunk-LS4W2YJJ.js} +2 -2
  113. package/dist/wallets/walletConnectors/chunk-NM7YUGLV.js +186 -0
  114. package/dist/wallets/walletConnectors/{chunk-M4SNNQU2.js → chunk-NVJA6FA7.js} +30 -7
  115. package/dist/wallets/walletConnectors/chunk-NXLLPSM4.js +53 -0
  116. package/dist/wallets/walletConnectors/{chunk-ZBI7MSWF.js → chunk-PGV5K26R.js} +6 -4
  117. package/dist/wallets/walletConnectors/{chunk-RSR35XOZ.js → chunk-Q66E4NTB.js} +10 -6
  118. package/dist/wallets/walletConnectors/chunk-QRU6XFHH.js +110 -0
  119. package/dist/wallets/walletConnectors/{chunk-TRFREYPH.js → chunk-RVLR562W.js} +39 -9
  120. package/dist/wallets/walletConnectors/{chunk-5SRSGEZR.js → chunk-SUMQUG76.js} +35 -10
  121. package/dist/wallets/walletConnectors/chunk-TA4DDCKN.js +96 -0
  122. package/dist/wallets/walletConnectors/chunk-TWVKSPTP.js +91 -0
  123. package/dist/wallets/walletConnectors/chunk-U5UPCM5V.js +66 -0
  124. package/dist/wallets/walletConnectors/{chunk-TP4BDK7W.js → chunk-UVPRZEPJ.js} +5 -1
  125. package/dist/wallets/walletConnectors/chunk-V5LGED4F.js +103 -0
  126. package/dist/wallets/walletConnectors/{chunk-ZWIAZOVB.js → chunk-WBVDGWKA.js} +5 -3
  127. package/dist/wallets/walletConnectors/{chunk-UHVJ6AF6.js → chunk-WMDTUVBI.js} +3 -1
  128. package/dist/wallets/walletConnectors/{chunk-P64PMEPU.js → chunk-WXLW3QUZ.js} +65 -11
  129. package/dist/wallets/walletConnectors/chunk-WZMFQQ6R.js +108 -0
  130. package/dist/wallets/walletConnectors/{chunk-YPMD3ZHF.js → chunk-X3P74Y3M.js} +80 -44
  131. package/dist/wallets/walletConnectors/chunk-XS6GJRRA.js +98 -0
  132. package/dist/wallets/walletConnectors/{chunk-2OHHFQQ7.js → chunk-XSH5KJQV.js} +3 -1
  133. package/dist/wallets/walletConnectors/chunk-XSJUQHR7.js +95 -0
  134. package/dist/wallets/walletConnectors/chunk-XSX5EECZ.js +96 -0
  135. package/dist/wallets/walletConnectors/{chunk-GO6HUJTP.js → chunk-ZJCV4QR4.js} +5 -5
  136. package/dist/wallets/walletConnectors/clvWallet/clvWallet.js +2 -2
  137. package/dist/wallets/walletConnectors/coin98Wallet/coin98Wallet.js +2 -2
  138. package/dist/wallets/walletConnectors/coreWallet/coreWallet.js +2 -2
  139. package/dist/wallets/walletConnectors/dawnWallet/dawnWallet.js +2 -2
  140. package/dist/wallets/walletConnectors/foxWallet/foxWallet.js +2 -2
  141. package/dist/wallets/walletConnectors/frontierWallet/frontierWallet.js +2 -2
  142. package/dist/wallets/walletConnectors/gateWallet/gateWallet.js +2 -2
  143. package/dist/wallets/walletConnectors/index.js +92 -90
  144. package/dist/wallets/walletConnectors/iopayWallet/iopayWallet.js +2 -2
  145. package/dist/wallets/walletConnectors/kaiaWallet/kaiaWallet.js +2 -2
  146. package/dist/wallets/walletConnectors/kaikasWallet/kaikasWallet.js +2 -2
  147. package/dist/wallets/walletConnectors/metaMaskWallet/metaMaskWallet.js +2 -2
  148. package/dist/wallets/walletConnectors/okxWallet/okxWallet.js +2 -2
  149. package/dist/wallets/walletConnectors/rainbowWallet/rainbowWallet.js +2 -2
  150. package/dist/wallets/walletConnectors/roninWallet/roninWallet.js +2 -2
  151. package/dist/wallets/walletConnectors/safepalWallet/safepalWallet.js +2 -2
  152. package/dist/wallets/walletConnectors/subWallet/subWallet.js +2 -2
  153. package/dist/wallets/walletConnectors/tokenPocketWallet/tokenPocketWallet.js +2 -2
  154. package/dist/wallets/walletConnectors/trustWallet/trustWallet.js +2 -2
  155. package/dist/wallets/walletConnectors/zealWallet/zealWallet.js +2 -2
  156. package/dist/wallets/walletConnectors/zerionWallet/zerionWallet.js +2 -2
  157. package/package.json +1 -1
  158. package/dist/AbcCredentialManager-WZBF3GHF.js +0 -7
  159. package/dist/TalkenApiSingleton-TECFDCT4.js +0 -9
  160. package/dist/chunk-CUPPBGFC.js +0 -460
  161. package/dist/chunk-R6ZE7JAZ.js +0 -15
  162. package/dist/wallets/walletConnectors/chunk-2M6E3YXU.js +0 -382
  163. package/dist/wallets/walletConnectors/chunk-3DHUDD4U.js +0 -132
  164. package/dist/wallets/walletConnectors/chunk-GAJ4FJTW.js +0 -382
  165. package/dist/wallets/walletConnectors/chunk-R6ZE7JAZ.js +0 -15
@@ -4,22 +4,18 @@ import {
4
4
  } from "./chunk-OESFVVLA.js";
5
5
  import {
6
6
  isSigningCredentialError
7
- } from "./chunk-M4SNNQU2.js";
7
+ } from "./chunk-NVJA6FA7.js";
8
8
  import {
9
- getChainKey,
10
- getExplorerTxUrl,
11
- getNetworkName,
12
9
  toBroadcastBody
13
- } from "./chunk-XGQUYXTL.js";
10
+ } from "./chunk-4UMY2AY7.js";
14
11
  import {
15
- getCredentialManager
16
- } from "./chunk-SORKIBWX.js";
12
+ getChainKey,
13
+ getExplorerTxUrl,
14
+ getNetworkName
15
+ } from "./chunk-5KPLYJOO.js";
17
16
  import {
18
17
  AbstractChainProvider
19
- } from "./chunk-3DHUDD4U.js";
20
- import {
21
- getTalkenApiClient
22
- } from "./chunk-R6ZE7JAZ.js";
18
+ } from "./chunk-CNKRIZ6T.js";
23
19
  import {
24
20
  ProviderErrorCode,
25
21
  ProviderRpcError
@@ -30,7 +26,17 @@ import {
30
26
  import {
31
27
  hexToNumber,
32
28
  numberToHex
33
- } from "./chunk-F4JUKZBB.js";
29
+ } from "./chunk-5IY2JM5V.js";
30
+ import {
31
+ TalkenApiError
32
+ } from "./chunk-UVPRZEPJ.js";
33
+ import {
34
+ getTalkenApiClient,
35
+ ownsTalkenApiStorage
36
+ } from "./chunk-NXLLPSM4.js";
37
+ import {
38
+ getCredentialManager
39
+ } from "./chunk-CO5DIPSI.js";
34
40
  import {
35
41
  SEND_REQUEST_TIMEOUT,
36
42
  TALKEN_API_ENDPOINTS
@@ -590,15 +596,26 @@ async function recoverYParity(hash, r, s, expectedAddress) {
590
596
  }
591
597
  throw new Error("Failed to recover yParity from tx signature");
592
598
  }
593
- async function sendRevokeTx(userAddress, chainKey, chainId) {
599
+ async function sendRevokeTx(userAddress, chainKey, chainId, assertOrigin) {
600
+ assertOrigin?.();
594
601
  const api = getTalkenApiClient();
595
602
  if (!api)
596
603
  throw new Error("TalkenApiClient not initialized");
604
+ const revision = api.getSessionRevision();
605
+ const assertCurrent = () => {
606
+ assertOrigin?.();
607
+ if (getTalkenApiClient() !== api || api.getSessionRevision() !== revision || !ownsTalkenApiStorage(api))
608
+ throw new Error("AUTH_SESSION_CHANGED");
609
+ if (api.isAccessKeyMode() && api.getAuthenticatedWalletSession()?.wallets.evm !== userAddress.toLowerCase())
610
+ throw new Error("AUTH_SESSION_CHANGED");
611
+ };
612
+ assertCurrent();
597
613
  const credentialManager = getCredentialManager();
598
614
  const pinHash = credentialManager.getPinHash() || "";
599
- const email = credentialManager.getEmail() ?? void 0;
615
+ const email = api.isAccessKeyMode() ? api.getAuthenticatedWalletSession()?.user.email ?? void 0 : credentialManager.getEmail() ?? void 0;
600
616
  const network = getNetworkName(chainId);
601
617
  const nonceResult = await api.evm.getNonce(network, userAddress);
618
+ assertCurrent();
602
619
  const nonceRaw = nonceResult?.data?.result ?? nonceResult?.nonce ?? nonceResult?.result ?? nonceResult;
603
620
  const currentNonce = Number(nonceRaw);
604
621
  if (!Number.isFinite(currentNonce)) {
@@ -615,6 +632,7 @@ async function sendRevokeTx(userAddress, chainKey, chainId) {
615
632
  pin: pinHash,
616
633
  ...email && { email }
617
634
  });
635
+ assertCurrent();
618
636
  const auth = authResult?.authorization ?? authResult;
619
637
  if (!auth?.r || !auth?.s) {
620
638
  throw new Error("signAuthorization returned empty r/s for revoke");
@@ -627,6 +645,7 @@ async function sendRevokeTx(userAddress, chainKey, chainId) {
627
645
  let maxPriorityFeePerGas = DEFAULT_MAX_PRIORITY_FEE;
628
646
  try {
629
647
  const suggested = await api.evm.getGasSuggested(network);
648
+ assertCurrent();
630
649
  if (suggested?.high) {
631
650
  maxPriorityFeePerGas = BigInt(
632
651
  Math.round(Number(suggested.high.suggestedMaxPriorityFeePerGas) * 1e9)
@@ -636,6 +655,7 @@ async function sendRevokeTx(userAddress, chainKey, chainId) {
636
655
  );
637
656
  }
638
657
  } catch {
658
+ assertCurrent();
639
659
  }
640
660
  const authEntry = [
641
661
  rlpUint(chainId),
@@ -669,6 +689,7 @@ async function sendRevokeTx(userAddress, chainKey, chainId) {
669
689
  ...network && { network },
670
690
  ...email && { email }
671
691
  });
692
+ assertCurrent();
672
693
  const signStr = signResult?.signstr ?? signResult?.signature ?? "";
673
694
  if (!signStr)
674
695
  throw new Error("signHash returned empty signature");
@@ -696,6 +717,7 @@ async function sendRevokeTx(userAddress, chainKey, chainId) {
696
717
  txSRaw,
697
718
  userAddress
698
719
  );
720
+ assertCurrent();
699
721
  const signedFields = [...unsignedFields, txYParity ? "0x01" : "0x", txR, txS];
700
722
  const signedTx = `0x04${toRlp(signedFields).slice(2)}`;
701
723
  const { txHash } = await api.post(
@@ -703,31 +725,137 @@ async function sendRevokeTx(userAddress, chainKey, chainId) {
703
725
  toBroadcastBody(chainKey, signedTx),
704
726
  { timeout: SEND_REQUEST_TIMEOUT }
705
727
  );
728
+ assertCurrent();
706
729
  console.log(`[RevokeDelegation] Revoke tx broadcast: ${txHash}`);
707
730
  return { txHash };
708
731
  }
732
+ function unsupportedRevoke(message) {
733
+ return new TalkenApiError("EXTERNAL_REVOKE_UNSUPPORTED", message, 400);
734
+ }
735
+ function unsupportedAuthorization(error) {
736
+ let current = error;
737
+ for (let depth = 0; current && typeof current === "object" && depth < 5; depth++) {
738
+ const value = current;
739
+ if (value.name === "AccountTypeNotSupportedError" || value.name === "MethodNotSupportedRpcError" || value.name === "MethodNotFoundRpcError" || value.code === -32601 || value.code === 4200)
740
+ return true;
741
+ current = value.cause;
742
+ }
743
+ return false;
744
+ }
745
+ function normalizeRevokeRejection(error) {
746
+ const topCode = error?.code;
747
+ if (topCode === 4001 || topCode === "AUTH_SESSION_CHANGED" || topCode === "AUTH_SESSION_UNBOUND")
748
+ return error;
749
+ let current = error;
750
+ let rejected = false;
751
+ for (let depth = 0; current && typeof current === "object" && depth < 5; depth++) {
752
+ const value = current;
753
+ if (value.possibleTxHash || value.txHash || value.transactionHash || value.details?.broadcast === true || value.details?.broadcast === "unknown")
754
+ return error;
755
+ if (value.code === 4001)
756
+ rejected = true;
757
+ current = value.cause;
758
+ }
759
+ return rejected ? Object.assign(new Error("User rejected the external revoke request."), {
760
+ code: 4001,
761
+ cause: error
762
+ }) : error;
763
+ }
709
764
  async function sendRevokeViaWalletClient(walletClient, chainId, userAddress) {
710
- if (!isAddress(userAddress)) {
765
+ if (!walletClient || typeof walletClient.assertSessionCurrent !== "function")
766
+ throw unsupportedRevoke(
767
+ "External revoke requires an originating account and network guard."
768
+ );
769
+ const assertCurrent = () => walletClient.assertSessionCurrent();
770
+ assertCurrent();
771
+ if (typeof walletClient.getTransactionCount !== "function" || typeof walletClient.signAuthorization !== "function" || typeof walletClient.sendTransaction !== "function" || walletClient.waitForTransactionReceipt !== void 0 && typeof walletClient.waitForTransactionReceipt !== "function")
772
+ throw unsupportedRevoke(
773
+ "External revoke requires pending nonce, authorization signing and transaction capabilities."
774
+ );
775
+ if (!isAddress(userAddress))
711
776
  throw new Error(`Invalid address for revoke: ${userAddress}`);
777
+ if (!Number.isSafeInteger(chainId) || chainId <= 0)
778
+ throw unsupportedRevoke(
779
+ "External revoke requires an explicit valid chain."
780
+ );
781
+ const guarded = async (operation) => {
782
+ assertCurrent();
783
+ try {
784
+ const result = await operation();
785
+ assertCurrent();
786
+ return result;
787
+ } catch (error) {
788
+ assertCurrent();
789
+ throw error;
790
+ }
791
+ };
792
+ const nonce = await guarded(
793
+ () => walletClient.getTransactionCount({
794
+ address: userAddress,
795
+ blockTag: "pending"
796
+ })
797
+ );
798
+ if (!Number.isSafeInteger(nonce) || nonce < 0 || nonce >= Number.MAX_SAFE_INTEGER)
799
+ throw unsupportedRevoke(
800
+ "External revoke could not prepare a safe pending nonce."
801
+ );
802
+ let raw;
803
+ try {
804
+ raw = await guarded(
805
+ () => walletClient.signAuthorization({
806
+ contractAddress: ZERO_ADDRESS2,
807
+ chainId,
808
+ nonce: nonce + 1,
809
+ executor: "self"
810
+ })
811
+ );
812
+ } catch (error) {
813
+ const refusal = normalizeRevokeRejection(error);
814
+ if (refusal !== error)
815
+ throw refusal;
816
+ if (["AUTH_SESSION_CHANGED", "AUTH_SESSION_UNBOUND", 4001].includes(
817
+ error?.code ?? ""
818
+ ))
819
+ throw error;
820
+ if (unsupportedAuthorization(error))
821
+ throw unsupportedRevoke(
822
+ "This wallet cannot sign an EIP-7702 revoke authorization."
823
+ );
824
+ throw error;
825
+ }
826
+ const signed = raw;
827
+ const parity = signed?.yParity ?? (signed?.v === BigInt(0) || signed?.v === 0 || signed?.v === BigInt(27) || signed?.v === 27 ? 0 : signed?.v === BigInt(1) || signed?.v === 1 || signed?.v === BigInt(28) || signed?.v === 28 ? 1 : signed?.v);
828
+ if (!signed || signed.address !== ZERO_ADDRESS2 || signed.chainId !== chainId || signed.nonce !== nonce + 1 || typeof signed.r !== "string" || !/^0x[0-9a-fA-F]{1,64}$/.test(signed.r) || typeof signed.s !== "string" || !/^0x[0-9a-fA-F]{1,64}$/.test(signed.s) || parity !== 0 && parity !== 1)
829
+ throw unsupportedRevoke(
830
+ "The wallet returned an invalid EIP-7702 revoke authorization."
831
+ );
832
+ const authorization = {
833
+ address: ZERO_ADDRESS2,
834
+ chainId,
835
+ nonce: nonce + 1,
836
+ r: signed.r,
837
+ s: signed.s,
838
+ yParity: parity
839
+ };
840
+ let txHash;
841
+ try {
842
+ txHash = await guarded(
843
+ () => walletClient.sendTransaction({
844
+ authorizationList: [authorization],
845
+ nonce,
846
+ to: userAddress,
847
+ value: BigInt(0)
848
+ })
849
+ );
850
+ } catch (error) {
851
+ throw normalizeRevokeRejection(error);
712
852
  }
713
- const txHash = await walletClient.sendTransaction({
714
- authorizationList: [
715
- { contractAddress: ZERO_ADDRESS2, chainId }
716
- ],
717
- to: userAddress,
718
- value: BigInt(0)
719
- });
720
- console.log(`[RevokeDelegation] External wallet revoke tx sent: ${txHash}`);
721
853
  if (walletClient.waitForTransactionReceipt) {
722
- const receipt = await walletClient.waitForTransactionReceipt({
723
- hash: txHash
724
- });
725
- if (receipt.status === "reverted") {
726
- throw new Error(`Revoke transaction reverted: ${txHash}`);
727
- }
728
- console.log(
729
- `[RevokeDelegation] External wallet revoke tx confirmed: ${txHash}`
854
+ const receipt = await guarded(
855
+ () => walletClient.waitForTransactionReceipt({ hash: txHash })
730
856
  );
857
+ if (receipt.status === "reverted")
858
+ throw new Error(`Revoke transaction reverted: ${txHash}`);
731
859
  }
732
860
  return { txHash };
733
861
  }
@@ -741,38 +869,56 @@ var _locks = /* @__PURE__ */ new Map();
741
869
  function lockKey(chainKey, address) {
742
870
  return `${chainKey}:${address.toLowerCase()}`;
743
871
  }
744
- async function checkDelegation(chainKey, address) {
745
- const api = getTalkenApiClient();
746
- if (!api) {
747
- return { hasDelegation: false, delegateAddress: "", code: "0x" };
748
- }
749
- try {
750
- const response = await api.get(
751
- `${TALKEN_API_ENDPOINTS.WALLET_CODE}/${encodeURIComponent(chainKey)}/${encodeURIComponent(address)}`
872
+ async function checkDelegation(chainKey, address, delegationClient, assertCurrent) {
873
+ if (!delegationClient || typeof delegationClient.readCode !== "function")
874
+ throw new TalkenApiError(
875
+ "DELEGATION_CONTEXT_REQUIRED",
876
+ "An originating wallet delegation client is required.",
877
+ 401
752
878
  );
753
- const rawCode = response?.code ?? response?.data?.code ?? "0x";
754
- const code = String(rawCode).toLowerCase();
755
- const minDelegationCodeLength = EIP7702_CODE_PREFIX.length + 40;
756
- const hasDelegation = !!code && code.startsWith(EIP7702_CODE_PREFIX) && code.length >= minDelegationCodeLength;
757
- const delegateAddress = hasDelegation ? `0x${code.slice(EIP7702_CODE_PREFIX.length, EIP7702_CODE_PREFIX.length + 40)}` : "";
758
- return { hasDelegation, delegateAddress, code };
759
- } catch (err) {
760
- logger.warn("eth_getCode check failed:", err);
761
- return { hasDelegation: false, delegateAddress: "", code: "0x" };
762
- }
879
+ assertCurrent?.();
880
+ let rawCode;
881
+ try {
882
+ rawCode = await delegationClient.readCode(chainKey, address);
883
+ } catch (error) {
884
+ assertCurrent?.();
885
+ throw error;
886
+ }
887
+ assertCurrent?.();
888
+ const code = String(rawCode).toLowerCase();
889
+ const hasDelegation = code.startsWith(EIP7702_CODE_PREFIX) && code.length >= EIP7702_CODE_PREFIX.length + 40;
890
+ return {
891
+ hasDelegation,
892
+ code,
893
+ delegateAddress: hasDelegation ? `0x${code.slice(EIP7702_CODE_PREFIX.length, EIP7702_CODE_PREFIX.length + 40)}` : ""
894
+ };
763
895
  }
764
896
  async function ensureDelegationCleared(chainKey, chainId, address, options) {
897
+ const delegationClient = options?.delegationClient;
898
+ if (!delegationClient)
899
+ throw new TalkenApiError(
900
+ "DELEGATION_CONTEXT_REQUIRED",
901
+ "An originating wallet delegation client is required.",
902
+ 401
903
+ );
904
+ const assertCurrent = () => options?.assertSessionCurrent?.();
905
+ const readDelegation = () => checkDelegation(chainKey, address, delegationClient, assertCurrent);
906
+ assertCurrent();
765
907
  const key = lockKey(chainKey, address);
766
908
  const existing = _locks.get(key);
767
909
  if (existing) {
768
910
  try {
769
911
  await existing;
912
+ assertCurrent();
770
913
  return;
771
914
  } catch {
915
+ assertCurrent();
772
916
  }
773
917
  }
774
918
  const check = async () => {
775
- const initial = await checkDelegation(chainKey, address);
919
+ assertCurrent();
920
+ const initial = await readDelegation();
921
+ assertCurrent();
776
922
  if (!initial.hasDelegation)
777
923
  return;
778
924
  logger.warn(
@@ -783,9 +929,21 @@ async function ensureDelegationCleared(chainKey, chainId, address, options) {
783
929
  options.walletClient,
784
930
  chainId,
785
931
  address
786
- ) : await sendRevokeTx(address, chainKey, chainId);
932
+ ) : delegationClient.revoke ? await delegationClient.revoke(chainKey, chainId, address) : (() => {
933
+ throw new TalkenApiError(
934
+ "EXTERNAL_REVOKE_UNSUPPORTED",
935
+ "This wallet has no delegation revoke capability.",
936
+ 400
937
+ );
938
+ })();
939
+ assertCurrent();
787
940
  logger.info(`Revoke tx sent: ${txHash}. Polling for clearance...`);
788
941
  } catch (revokeErr) {
942
+ assertCurrent();
943
+ if (["AUTH_SESSION_CHANGED", "EXTERNAL_REVOKE_UNSUPPORTED"].includes(
944
+ revokeErr?.code ?? ""
945
+ ))
946
+ throw revokeErr;
789
947
  if (revokeErr && typeof revokeErr === "object" && "code" in revokeErr && revokeErr.code === 4001) {
790
948
  throw revokeErr;
791
949
  }
@@ -794,13 +952,16 @@ async function ensureDelegationCleared(chainKey, chainId, address, options) {
794
952
  const deadline = Date.now() + POLL_TIMEOUT_MS;
795
953
  while (Date.now() < deadline) {
796
954
  await new Promise((r) => setTimeout(r, POLL_INTERVAL_MS));
797
- const current = await checkDelegation(chainKey, address);
955
+ assertCurrent();
956
+ const current = await readDelegation();
957
+ assertCurrent();
798
958
  if (!current.hasDelegation) {
799
959
  logger.info("Delegation cleared");
800
960
  return;
801
961
  }
802
962
  }
803
963
  const message = "Previous transaction delegation is still active. Please wait a moment and try again.";
964
+ assertCurrent();
804
965
  if (options?.onDelegationError) {
805
966
  options.onDelegationError({
806
967
  chainId,
@@ -812,7 +973,8 @@ async function ensureDelegationCleared(chainKey, chainId, address, options) {
812
973
  throw new Error(message);
813
974
  };
814
975
  const promise = check().finally(() => {
815
- _locks.delete(key);
976
+ if (_locks.get(key) === promise)
977
+ _locks.delete(key);
816
978
  });
817
979
  _locks.set(key, promise);
818
980
  return promise;
@@ -833,7 +995,14 @@ var Eip7702Service = class {
833
995
  */
834
996
  async preflight(chainKey, chainId, address, options) {
835
997
  try {
836
- await ensureDelegationCleared(chainKey, chainId, address, options);
998
+ await ensureDelegationCleared(chainKey, chainId, address, {
999
+ ...options,
1000
+ delegationClient: options?.delegationClient ?? this.signer.getDelegationClient?.(),
1001
+ assertSessionCurrent: () => {
1002
+ this.signer.assertSessionCurrent?.();
1003
+ options?.assertSessionCurrent?.();
1004
+ }
1005
+ });
837
1006
  } catch (error) {
838
1007
  console.warn(
839
1008
  "[Eip7702Service] Pre-flight delegation check failed:",
@@ -1084,6 +1253,7 @@ var RelayPhase2Error = class extends Error {
1084
1253
  };
1085
1254
  var GaslessTransferService = class {
1086
1255
  constructor(deps) {
1256
+ this.assertSessionCurrent = () => this.signer.assertSessionCurrent?.();
1087
1257
  this.relayerApi = deps.relayerApi ?? new RelayerApi();
1088
1258
  this.signer = deps.signer;
1089
1259
  this.walletClient = deps.walletClient;
@@ -1094,14 +1264,20 @@ var GaslessTransferService = class {
1094
1264
  });
1095
1265
  }
1096
1266
  async execute(params, gaslessConfig) {
1097
- switch (params.gaslessMode) {
1098
- case "generic":
1099
- return this.executeGenericRelay(params);
1100
- case "eip7702-fee":
1101
- case "eip7702-points":
1102
- return this.executeEip7702Relay(params, gaslessConfig);
1103
- default:
1104
- throw new Error(`Unknown gasless mode: ${params.gaslessMode}`);
1267
+ this.assertSessionCurrent();
1268
+ try {
1269
+ switch (params.gaslessMode) {
1270
+ case "generic":
1271
+ return await this.executeGenericRelay(params);
1272
+ case "eip7702-fee":
1273
+ case "eip7702-points":
1274
+ return await this.executeEip7702Relay(params, gaslessConfig);
1275
+ default:
1276
+ throw new Error(`Unknown gasless mode: ${params.gaslessMode}`);
1277
+ }
1278
+ } catch (error) {
1279
+ this.assertSessionCurrent();
1280
+ throw error;
1105
1281
  }
1106
1282
  }
1107
1283
  /**
@@ -1118,14 +1294,24 @@ var GaslessTransferService = class {
1118
1294
  params.chainKey,
1119
1295
  params.chainId,
1120
1296
  params.fromAddress,
1121
- { walletClient: this.walletClient }
1297
+ {
1298
+ walletClient: this.walletClient,
1299
+ assertSessionCurrent: this.assertSessionCurrent,
1300
+ delegationClient: this.signer.getDelegationClient?.()
1301
+ }
1122
1302
  );
1123
1303
  } catch (err) {
1304
+ this.assertSessionCurrent();
1305
+ if (["AUTH_SESSION_CHANGED", "EXTERNAL_REVOKE_UNSUPPORTED", 4001].includes(
1306
+ err?.code ?? ""
1307
+ ))
1308
+ throw err;
1124
1309
  console.warn(
1125
1310
  "[GaslessTransferService] Preflight check failed (non-blocking):",
1126
1311
  err
1127
1312
  );
1128
1313
  }
1314
+ this.assertSessionCurrent();
1129
1315
  const deadline = Math.floor(Date.now() / 1e3) + 20 * 60;
1130
1316
  const feeMaxAmount = (BigInt(params.feeAmountRaw) * BigInt(3) / BigInt(2)).toString();
1131
1317
  const baseRequest = {
@@ -1147,12 +1333,14 @@ var GaslessTransferService = class {
1147
1333
  auth: { method: "auto" }
1148
1334
  };
1149
1335
  const phase1 = await this.relayerApi.execute(baseRequest);
1336
+ this.assertSessionCurrent();
1150
1337
  if (phase1.phase !== "sign") {
1151
1338
  return this.extractResult(phase1, params);
1152
1339
  }
1153
1340
  const signatures = await this.permitService.signAll(
1154
1341
  phase1.signatureRequests
1155
1342
  );
1343
+ this.assertSessionCurrent();
1156
1344
  let phase2;
1157
1345
  try {
1158
1346
  phase2 = await this.relayerApi.execute({
@@ -1161,8 +1349,12 @@ var GaslessTransferService = class {
1161
1349
  signatures
1162
1350
  });
1163
1351
  } catch (err) {
1352
+ this.assertSessionCurrent();
1353
+ if (err?.code === "AUTH_SESSION_CHANGED")
1354
+ throw err;
1164
1355
  throw new RelayPhase2Error(phase1.requestId, err);
1165
1356
  }
1357
+ this.assertSessionCurrent();
1166
1358
  return this.extractResult(phase2, params);
1167
1359
  }
1168
1360
  /**
@@ -1182,19 +1374,24 @@ var GaslessTransferService = class {
1182
1374
  params.fromAddress,
1183
1375
  {
1184
1376
  walletClient: this.walletClient,
1185
- onDelegationError: gaslessConfig.onDelegationError
1377
+ onDelegationError: gaslessConfig.onDelegationError,
1378
+ assertSessionCurrent: this.assertSessionCurrent,
1379
+ delegationClient: this.signer.getDelegationClient?.()
1186
1380
  }
1187
1381
  );
1382
+ this.assertSessionCurrent();
1188
1383
  try {
1189
1384
  const { delegateAuth } = await this.eip7702Service.signDelegate(
1190
1385
  params.chainKey,
1191
1386
  params.chainId,
1192
1387
  params.fromAddress
1193
1388
  );
1389
+ this.assertSessionCurrent();
1194
1390
  const { relayerAddress, executionNonce } = await this.eip7702Service.getRelayerInfo(
1195
1391
  params.chainKey,
1196
1392
  params.fromAddress
1197
1393
  );
1394
+ this.assertSessionCurrent();
1198
1395
  const deadline = Math.floor(Date.now() / 1e3) + 20 * 60;
1199
1396
  const isPointsMode = params.gaslessMode === "eip7702-points";
1200
1397
  const transferCalldata = this.encodeErc20Transfer(
@@ -1221,6 +1418,7 @@ var GaslessTransferService = class {
1221
1418
  feeAmount: params.feeAmountRaw
1222
1419
  });
1223
1420
  const executionAuth = await this.eip7702Service.signExecutionTypedData(executionTypedData);
1421
+ this.assertSessionCurrent();
1224
1422
  const feeAmount = isPointsMode ? "0" : params.feeAmountRaw;
1225
1423
  const feeMaxAmount = isPointsMode ? "0" : (BigInt(params.feeAmountRaw) * BigInt(3) / BigInt(2)).toString();
1226
1424
  const result = await this.relayerApi.execute({
@@ -1246,8 +1444,12 @@ var GaslessTransferService = class {
1246
1444
  executionAuth
1247
1445
  }
1248
1446
  });
1447
+ this.assertSessionCurrent();
1249
1448
  return this.extractResult(result, params);
1250
1449
  } catch (error) {
1450
+ this.assertSessionCurrent();
1451
+ if (error?.code === "AUTH_SESSION_CHANGED")
1452
+ throw error;
1251
1453
  try {
1252
1454
  await ensureDelegationCleared(
1253
1455
  params.chainKey,
@@ -1255,10 +1457,15 @@ var GaslessTransferService = class {
1255
1457
  params.fromAddress,
1256
1458
  {
1257
1459
  walletClient: this.walletClient,
1258
- onDelegationError: gaslessConfig.onDelegationError
1460
+ onDelegationError: gaslessConfig.onDelegationError,
1461
+ assertSessionCurrent: this.assertSessionCurrent,
1462
+ delegationClient: this.signer.getDelegationClient?.()
1259
1463
  }
1260
1464
  );
1261
1465
  } catch (cleanupError) {
1466
+ this.assertSessionCurrent();
1467
+ if (cleanupError?.code === "AUTH_SESSION_CHANGED")
1468
+ throw cleanupError;
1262
1469
  console.error(
1263
1470
  "[GaslessTransferService] Post-failure delegation cleanup failed:",
1264
1471
  cleanupError
@@ -1311,10 +1518,33 @@ function sleep(ms) {
1311
1518
  }
1312
1519
  var AbcWaasSigner = class {
1313
1520
  constructor(params) {
1521
+ this.api = getTalkenApiClient();
1522
+ this.revision = this.api?.getSessionRevision();
1314
1523
  this.pinHash = params.pinHash;
1315
1524
  this.network = params.network;
1316
1525
  this.email = params.email;
1317
1526
  }
1527
+ getDelegationClient() {
1528
+ return {
1529
+ readCode: async (chainKey, address) => {
1530
+ const api = this.getApiOrThrow();
1531
+ const result = await api.get(
1532
+ `/wallet/code/${encodeURIComponent(chainKey)}/${encodeURIComponent(address)}`
1533
+ );
1534
+ this.getApiOrThrow();
1535
+ return result.code ?? "0x";
1536
+ },
1537
+ revoke: (chainKey, chainId, address) => sendRevokeTx(
1538
+ address,
1539
+ chainKey,
1540
+ chainId,
1541
+ () => this.assertSessionCurrent()
1542
+ )
1543
+ };
1544
+ }
1545
+ assertSessionCurrent() {
1546
+ this.getApiOrThrow();
1547
+ }
1318
1548
  supportsAuthorization() {
1319
1549
  return true;
1320
1550
  }
@@ -1323,20 +1553,24 @@ var AbcWaasSigner = class {
1323
1553
  let lastError = null;
1324
1554
  for (let attempt = 0; attempt < MAX_SIGN_ATTEMPTS; attempt++) {
1325
1555
  try {
1556
+ this.getApiOrThrow();
1326
1557
  const result = await api.evm.signTypedData({
1327
1558
  network: this.network,
1328
1559
  typedData: JSON.stringify(typedData),
1329
1560
  ...this.pinHash && { pin: this.pinHash },
1330
1561
  ...this.email && { email: this.email }
1331
1562
  });
1563
+ this.getApiOrThrow();
1332
1564
  const sig = typeof result === "string" ? result : result?.signature ?? result?.result;
1333
1565
  if (sig)
1334
1566
  return sig;
1335
1567
  throw new Error("signTypedData returned empty signature");
1336
1568
  } catch (error) {
1569
+ this.getApiOrThrow();
1337
1570
  lastError = error instanceof Error ? error : new Error(String(error));
1338
1571
  if (attempt < MAX_SIGN_ATTEMPTS - 1) {
1339
1572
  await sleep(RETRY_BASE_MS * 2 ** attempt);
1573
+ this.getApiOrThrow();
1340
1574
  }
1341
1575
  }
1342
1576
  }
@@ -1347,6 +1581,7 @@ var AbcWaasSigner = class {
1347
1581
  let lastError = null;
1348
1582
  for (let attempt = 0; attempt < MAX_SIGN_ATTEMPTS; attempt++) {
1349
1583
  try {
1584
+ this.getApiOrThrow();
1350
1585
  const result = await api.evm.signAuthorization({
1351
1586
  network: this.network,
1352
1587
  authorization: {
@@ -1357,6 +1592,7 @@ var AbcWaasSigner = class {
1357
1592
  ...this.pinHash && { pin: this.pinHash },
1358
1593
  ...this.email && { email: this.email }
1359
1594
  });
1595
+ this.getApiOrThrow();
1360
1596
  const auth = result?.authorization ?? result;
1361
1597
  if (!auth?.r || !auth?.s) {
1362
1598
  throw new Error("signAuthorization returned empty r/s");
@@ -1370,9 +1606,11 @@ var AbcWaasSigner = class {
1370
1606
  s: auth.s
1371
1607
  };
1372
1608
  } catch (error) {
1609
+ this.getApiOrThrow();
1373
1610
  lastError = error instanceof Error ? error : new Error(String(error));
1374
1611
  if (attempt < MAX_SIGN_ATTEMPTS - 1) {
1375
1612
  await sleep(RETRY_BASE_MS * 2 ** attempt);
1613
+ this.getApiOrThrow();
1376
1614
  }
1377
1615
  }
1378
1616
  }
@@ -1381,6 +1619,7 @@ var AbcWaasSigner = class {
1381
1619
  async getNonce(address) {
1382
1620
  const api = this.getApiOrThrow();
1383
1621
  const nonceResult = await api.evm.getNonce(this.network, address);
1622
+ this.getApiOrThrow();
1384
1623
  const raw = nonceResult?.data?.result ?? nonceResult?.nonce ?? nonceResult?.result ?? nonceResult;
1385
1624
  const nonce = Number(raw);
1386
1625
  if (!Number.isFinite(nonce)) {
@@ -1392,6 +1631,19 @@ var AbcWaasSigner = class {
1392
1631
  const api = getTalkenApiClient();
1393
1632
  if (!api)
1394
1633
  throw new Error("TalkenApiClient not initialized");
1634
+ if (api !== this.api || api.getSessionRevision() !== this.revision || !ownsTalkenApiStorage(api))
1635
+ throw new TalkenApiError(
1636
+ "AUTH_SESSION_CHANGED",
1637
+ "The signer wallet session changed.",
1638
+ 401
1639
+ );
1640
+ const session = api.isAccessKeyMode() ? api.getAuthenticatedWalletSession() : null;
1641
+ if (api.isAccessKeyMode() && (!session || this.email && session.user.email !== this.email.trim().toLowerCase()))
1642
+ throw new TalkenApiError(
1643
+ "AUTH_SESSION_CHANGED",
1644
+ "The signer account does not match this login.",
1645
+ 401
1646
+ );
1395
1647
  return api;
1396
1648
  }
1397
1649
  };
@@ -1470,17 +1722,21 @@ var AbcEvmProvider = class extends AbstractChainProvider {
1470
1722
  this.gaslessFeeService = getSharedGaslessFeeService();
1471
1723
  this.gaslessLock = Promise.resolve();
1472
1724
  }
1725
+ getWalletOperationNetwork() {
1726
+ return this.chainId;
1727
+ }
1473
1728
  getRecoveryEmail() {
1474
1729
  const walletEmail = this.wallet?.email?.trim();
1475
1730
  if (walletEmail) {
1476
1731
  return walletEmail;
1477
1732
  }
1478
- return getCredentialManager().getEmail() || void 0;
1733
+ return this.getSharedCredentials()?.getEmail() || void 0;
1479
1734
  }
1480
1735
  /**
1481
1736
  * Set wallet — EVM override for chainId tracking + chainChanged event
1482
1737
  */
1483
1738
  setWallet(wallet) {
1739
+ this.assertWalletSession(wallet);
1484
1740
  const previousChainId = this.chainId;
1485
1741
  this.chainId = wallet.chainId;
1486
1742
  super.setWallet(wallet);
@@ -1518,13 +1774,17 @@ var AbcEvmProvider = class extends AbstractChainProvider {
1518
1774
  * so this refresh is the only recovery from a cold server credential cache.
1519
1775
  */
1520
1776
  async refreshSigningCredentials() {
1521
- const credMgr = getCredentialManager();
1522
- const pinHash = credMgr.getPinHash();
1777
+ const credMgr = this.getSharedCredentials();
1778
+ const pinHash = credMgr?.getPinHash();
1523
1779
  const email = this.getRecoveryEmail();
1780
+ const assertOperation = this.captureWalletOperation();
1524
1781
  if (pinHash && email) {
1525
1782
  const api = this.getTalkenApiClientOrThrow();
1526
1783
  logger2.info("Refreshing signing credentials via wallet.generate...");
1527
- await api.wallet.generate(pinHash, email);
1784
+ await this.awaitWalletOperation(
1785
+ assertOperation,
1786
+ async () => api.wallet.generate(pinHash, email)
1787
+ );
1528
1788
  logger2.info("Signing credentials refreshed via PIN");
1529
1789
  return;
1530
1790
  }
@@ -1541,15 +1801,26 @@ var AbcEvmProvider = class extends AbstractChainProvider {
1541
1801
  * On first failure, refreshes the server's signing credential cache and retries once.
1542
1802
  */
1543
1803
  async withSigningCredentialRetry(operation) {
1804
+ const assertOperation = this.captureWalletOperation();
1544
1805
  try {
1545
- return await operation();
1806
+ return await this.awaitWalletOperation(
1807
+ assertOperation,
1808
+ async () => operation()
1809
+ );
1546
1810
  } catch (error) {
1811
+ assertOperation();
1547
1812
  if (this.isSigningCredentialError(error)) {
1548
1813
  logger2.info(
1549
1814
  "Signing credentials missing on server \u2014 attempting refresh and retry"
1550
1815
  );
1551
- await this.refreshSigningCredentials();
1552
- return await operation();
1816
+ await this.awaitWalletOperation(
1817
+ assertOperation,
1818
+ async () => this.refreshSigningCredentials()
1819
+ );
1820
+ return await this.awaitWalletOperation(
1821
+ assertOperation,
1822
+ async () => operation()
1823
+ );
1553
1824
  }
1554
1825
  throw error;
1555
1826
  }
@@ -1575,6 +1846,8 @@ var AbcEvmProvider = class extends AbstractChainProvider {
1575
1846
  * EIP-1193 request method
1576
1847
  */
1577
1848
  async request(args) {
1849
+ if (this.wallet)
1850
+ this.assertWalletSession();
1578
1851
  const { method, params } = args;
1579
1852
  switch (method) {
1580
1853
  case "eth_requestAccounts":
@@ -1677,7 +1950,11 @@ var AbcEvmProvider = class extends AbstractChainProvider {
1677
1950
  );
1678
1951
  }
1679
1952
  resolveEvmSignType(params[0]);
1680
- const resolved = await this.callInterceptor("eth_sendTransaction", params);
1953
+ const assertOperation = this.captureWalletOperation();
1954
+ const resolved = await this.awaitWalletOperation(
1955
+ assertOperation,
1956
+ async () => this.callInterceptor("eth_sendTransaction", params)
1957
+ );
1681
1958
  const tx = params[0];
1682
1959
  logger2.debug("eth_sendTransaction incoming gas params:", {
1683
1960
  gas: tx.gas ?? tx.gasLimit,
@@ -1694,6 +1971,7 @@ var AbcEvmProvider = class extends AbstractChainProvider {
1694
1971
  const maxFeeWei = parseGwei(resolved.gasFee.maxFeePerGas);
1695
1972
  tx.maxFeePerGas = `0x${maxFeeWei.toString(16)}`;
1696
1973
  } catch (error) {
1974
+ assertOperation();
1697
1975
  logger2.error("Failed to parse maxFeePerGas:", error);
1698
1976
  }
1699
1977
  }
@@ -1704,6 +1982,7 @@ var AbcEvmProvider = class extends AbstractChainProvider {
1704
1982
  );
1705
1983
  tx.maxPriorityFeePerGas = `0x${priorityFeeWei.toString(16)}`;
1706
1984
  } catch (error) {
1985
+ assertOperation();
1707
1986
  logger2.error("Failed to parse maxPriorityFeePerGas:", error);
1708
1987
  }
1709
1988
  }
@@ -1724,7 +2003,7 @@ var AbcEvmProvider = class extends AbstractChainProvider {
1724
2003
  );
1725
2004
  }
1726
2005
  const api = this.getTalkenApiClientOrThrow();
1727
- const pinHash = api.isAccessKeyMode() ? void 0 : getCredentialManager().getPinHash() || void 0;
2006
+ const pinHash = api.isAccessKeyMode() ? void 0 : this.getSharedCredentials()?.getPinHash() || void 0;
1728
2007
  if (!pinHash && !api.isAccessKeyMode()) {
1729
2008
  throw new ProviderRpcError(
1730
2009
  ProviderErrorCode.INTERNAL_ERROR,
@@ -1740,22 +2019,27 @@ var AbcEvmProvider = class extends AbstractChainProvider {
1740
2019
  if (shouldTryGasless) {
1741
2020
  const effectiveConfig = gaslessConfig ?? { enabled: true };
1742
2021
  const attempt = this.gaslessLock.catch(() => {
1743
- }).then(
1744
- () => this.tryGaslessTransfer(
2022
+ }).then(() => {
2023
+ assertOperation();
2024
+ return this.tryGaslessTransfer(
1745
2025
  tx,
1746
2026
  chainKey,
1747
2027
  pinHash,
1748
2028
  email,
1749
2029
  effectiveConfig,
1750
2030
  preEstimatedFee
1751
- )
1752
- );
2031
+ );
2032
+ });
1753
2033
  this.gaslessLock = attempt;
1754
2034
  try {
1755
- const gaslessResult = await attempt;
2035
+ const gaslessResult = await this.awaitWalletOperation(
2036
+ assertOperation,
2037
+ async () => attempt
2038
+ );
1756
2039
  if (gaslessResult)
1757
2040
  return gaslessResult;
1758
2041
  } catch (gaslessError) {
2042
+ assertOperation();
1759
2043
  const failedTxHash = gaslessError?.txHash || "";
1760
2044
  this.updateTxResult({
1761
2045
  txHash: failedTxHash,
@@ -1777,21 +2061,24 @@ var AbcEvmProvider = class extends AbstractChainProvider {
1777
2061
  const amountWei = BigInt(hexValue).toString();
1778
2062
  try {
1779
2063
  const gasLimit = tx.gas || tx.gasLimit;
1780
- const result = await api.evm.sendTransaction({
1781
- chainKey,
1782
- to: tx.to,
1783
- amountWei,
1784
- pin: pinHash,
1785
- data: tx.data || "0x",
1786
- waitForReceipt: true,
1787
- ...gasLimit && { gasLimit },
1788
- ...tx.gasPrice && { gasPrice: tx.gasPrice },
1789
- ...tx.maxFeePerGas && { maxFeePerGas: tx.maxFeePerGas },
1790
- ...tx.maxPriorityFeePerGas && {
1791
- maxPriorityFeePerGas: tx.maxPriorityFeePerGas
1792
- },
1793
- ...email && { email }
1794
- });
2064
+ const result = await this.awaitWalletOperation(
2065
+ assertOperation,
2066
+ async () => api.evm.sendTransaction({
2067
+ chainKey,
2068
+ to: tx.to,
2069
+ amountWei,
2070
+ pin: pinHash,
2071
+ data: tx.data || "0x",
2072
+ waitForReceipt: true,
2073
+ ...gasLimit && { gasLimit },
2074
+ ...tx.gasPrice && { gasPrice: tx.gasPrice },
2075
+ ...tx.maxFeePerGas && { maxFeePerGas: tx.maxFeePerGas },
2076
+ ...tx.maxPriorityFeePerGas && {
2077
+ maxPriorityFeePerGas: tx.maxPriorityFeePerGas
2078
+ },
2079
+ ...email && { email }
2080
+ })
2081
+ );
1795
2082
  this.updateTxResult({
1796
2083
  txHash: result.txHash,
1797
2084
  network: chainKey,
@@ -1801,6 +2088,7 @@ var AbcEvmProvider = class extends AbstractChainProvider {
1801
2088
  });
1802
2089
  return result.txHash;
1803
2090
  } catch (error) {
2091
+ assertOperation();
1804
2092
  this.failTxResult({
1805
2093
  network: chainKey,
1806
2094
  chain: "evm",
@@ -1822,18 +2110,23 @@ var AbcEvmProvider = class extends AbstractChainProvider {
1822
2110
  if (!detected)
1823
2111
  return null;
1824
2112
  let feeEstimate = preEstimatedFee ?? null;
2113
+ const assertOperation = this.captureWalletOperation();
1825
2114
  if (!feeEstimate) {
1826
2115
  try {
1827
- feeEstimate = await this.gaslessFeeService.estimateFee({
1828
- chainKey,
1829
- chainId: this.chainId,
1830
- tokenAddress: tx.to,
1831
- fromAddress: this.wallet.address,
1832
- toAddress: detected.to,
1833
- amount: detected.amount,
1834
- gaslessConfig
1835
- });
2116
+ feeEstimate = await this.awaitWalletOperation(
2117
+ assertOperation,
2118
+ async () => this.gaslessFeeService.estimateFee({
2119
+ chainKey,
2120
+ chainId: this.chainId,
2121
+ tokenAddress: tx.to,
2122
+ fromAddress: this.wallet.address,
2123
+ toAddress: detected.to,
2124
+ amount: detected.amount,
2125
+ gaslessConfig
2126
+ })
2127
+ );
1836
2128
  } catch (err) {
2129
+ assertOperation();
1837
2130
  console.warn("[AbcProvider] Gasless fee estimation failed:", err);
1838
2131
  return null;
1839
2132
  }
@@ -1849,19 +2142,22 @@ var AbcEvmProvider = class extends AbstractChainProvider {
1849
2142
  relayerApi: this._sharedRelayerApi,
1850
2143
  signer
1851
2144
  });
1852
- const gaslessResult = await transferService.execute(
1853
- {
1854
- chainId: this.chainId,
1855
- chainKey,
1856
- fromAddress: this.wallet.address,
1857
- toAddress: detected.to,
1858
- tokenAddress: tx.to,
1859
- amount: detected.amount,
1860
- feeToken: feeEstimate.feeToken,
1861
- gaslessMode: feeEstimate.gaslessMode,
1862
- feeAmountRaw: feeEstimate.feeAmountRaw
1863
- },
1864
- gaslessConfig
2145
+ const gaslessResult = await this.awaitWalletOperation(
2146
+ assertOperation,
2147
+ async () => transferService.execute(
2148
+ {
2149
+ chainId: this.chainId,
2150
+ chainKey,
2151
+ fromAddress: this.wallet.address,
2152
+ toAddress: detected.to,
2153
+ tokenAddress: tx.to,
2154
+ amount: detected.amount,
2155
+ feeToken: feeEstimate.feeToken,
2156
+ gaslessMode: feeEstimate.gaslessMode,
2157
+ feeAmountRaw: feeEstimate.feeAmountRaw
2158
+ },
2159
+ gaslessConfig
2160
+ )
1865
2161
  );
1866
2162
  this.updateTxResult({
1867
2163
  txHash: gaslessResult.txHash,
@@ -1897,7 +2193,11 @@ var AbcEvmProvider = class extends AbstractChainProvider {
1897
2193
  );
1898
2194
  }
1899
2195
  const signType = resolveEvmSignType(params[0]);
1900
- const resolved = await this.callInterceptor("eth_signTransaction", params);
2196
+ const assertOperation = this.captureWalletOperation();
2197
+ const resolved = await this.awaitWalletOperation(
2198
+ assertOperation,
2199
+ async () => this.callInterceptor("eth_signTransaction", params)
2200
+ );
1901
2201
  const tx = params[0];
1902
2202
  if (resolved) {
1903
2203
  if (resolved.data) {
@@ -1908,6 +2208,7 @@ var AbcEvmProvider = class extends AbstractChainProvider {
1908
2208
  const maxFeeWei = parseGwei(resolved.gasFee.maxFeePerGas);
1909
2209
  tx.maxFeePerGas = `0x${maxFeeWei.toString(16)}`;
1910
2210
  } catch (error) {
2211
+ assertOperation();
1911
2212
  logger2.error("Failed to parse maxFeePerGas:", error);
1912
2213
  }
1913
2214
  }
@@ -1918,27 +2219,31 @@ var AbcEvmProvider = class extends AbstractChainProvider {
1918
2219
  );
1919
2220
  tx.maxPriorityFeePerGas = `0x${priorityFeeWei.toString(16)}`;
1920
2221
  } catch (error) {
2222
+ assertOperation();
1921
2223
  logger2.error("Failed to parse maxPriorityFeePerGas:", error);
1922
2224
  }
1923
2225
  }
1924
2226
  }
1925
2227
  const api = this.getTalkenApiClientOrThrow();
1926
- const pinHash = getCredentialManager().getPinHash() || void 0;
2228
+ const pinHash = this.getSharedCredentials()?.getPinHash() || void 0;
1927
2229
  const email = this.getRecoveryEmail();
1928
- const result = await this.withSigningCredentialRetry(
1929
- () => api.evm.signTransaction({
1930
- network: getNetworkName(this.chainId),
1931
- to: tx.to,
1932
- value: tx.value || "0x0",
1933
- data: tx.data || "0x",
1934
- gasLimit: tx.gas || tx.gasLimit,
1935
- maxFeePerGas: tx.maxFeePerGas,
1936
- maxPriorityFeePerGas: tx.maxPriorityFeePerGas,
1937
- nonce: tx.nonce ? String(Number.parseInt(tx.nonce, 16)) : void 0,
1938
- ...signType && { type: signType },
1939
- ...pinHash && { pin: pinHash },
1940
- ...email && { email }
1941
- })
2230
+ const result = await this.awaitWalletOperation(
2231
+ assertOperation,
2232
+ async () => this.withSigningCredentialRetry(
2233
+ () => api.evm.signTransaction({
2234
+ network: getNetworkName(this.chainId),
2235
+ to: tx.to,
2236
+ value: tx.value || "0x0",
2237
+ data: tx.data || "0x",
2238
+ gasLimit: tx.gas || tx.gasLimit,
2239
+ maxFeePerGas: tx.maxFeePerGas,
2240
+ maxPriorityFeePerGas: tx.maxPriorityFeePerGas,
2241
+ nonce: tx.nonce ? String(Number.parseInt(tx.nonce, 16)) : void 0,
2242
+ ...signType && { type: signType },
2243
+ ...pinHash && { pin: pinHash },
2244
+ ...email && { email }
2245
+ })
2246
+ )
1942
2247
  );
1943
2248
  return result.signature;
1944
2249
  }
@@ -1960,7 +2265,11 @@ var AbcEvmProvider = class extends AbstractChainProvider {
1960
2265
  "Invalid personal_sign params"
1961
2266
  );
1962
2267
  }
1963
- await this.callInterceptor("personal_sign", params);
2268
+ const assertOperation = this.captureWalletOperation();
2269
+ await this.awaitWalletOperation(
2270
+ assertOperation,
2271
+ async () => this.callInterceptor("personal_sign", params)
2272
+ );
1964
2273
  const [message, address] = params;
1965
2274
  if (address.toLowerCase() !== this.wallet.address.toLowerCase()) {
1966
2275
  logger2.error("Address mismatch");
@@ -1971,20 +2280,23 @@ var AbcEvmProvider = class extends AbstractChainProvider {
1971
2280
  }
1972
2281
  const api = this.getTalkenApiClientOrThrow();
1973
2282
  const network = getNetworkName(this.chainId);
1974
- const pinHash = getCredentialManager().getPinHash() || void 0;
2283
+ const pinHash = this.getSharedCredentials()?.getPinHash() || void 0;
1975
2284
  const email = this.getRecoveryEmail();
1976
2285
  const rawOpts = Array.isArray(params) && params.length > 2 ? params[2] : null;
1977
2286
  const validPrefixes = ["eip191", "native"];
1978
2287
  const signaturePrefix = rawOpts != null && typeof rawOpts === "object" && "signaturePrefix" in rawOpts && validPrefixes.includes(rawOpts.signaturePrefix) ? rawOpts.signaturePrefix : void 0;
1979
- const result = await this.withSigningCredentialRetry(
1980
- () => api.evm.signPersonal({
1981
- network,
1982
- message,
1983
- address,
1984
- pin: pinHash,
1985
- ...email && { email },
1986
- ...signaturePrefix && { signaturePrefix }
1987
- })
2288
+ const result = await this.awaitWalletOperation(
2289
+ assertOperation,
2290
+ async () => this.withSigningCredentialRetry(
2291
+ () => api.evm.signPersonal({
2292
+ network,
2293
+ message,
2294
+ address,
2295
+ pin: pinHash,
2296
+ ...email && { email },
2297
+ ...signaturePrefix && { signaturePrefix }
2298
+ })
2299
+ )
1988
2300
  );
1989
2301
  return result.signature;
1990
2302
  }
@@ -2017,7 +2329,11 @@ var AbcEvmProvider = class extends AbstractChainProvider {
2017
2329
  "Invalid signTypedData params"
2018
2330
  );
2019
2331
  }
2020
- await this.callInterceptor("eth_signTypedData_v4", params);
2332
+ const assertOperation = this.captureWalletOperation();
2333
+ await this.awaitWalletOperation(
2334
+ assertOperation,
2335
+ async () => this.callInterceptor("eth_signTypedData_v4", params)
2336
+ );
2021
2337
  const [address, typedData] = params;
2022
2338
  if (address.toLowerCase() !== this.wallet.address.toLowerCase()) {
2023
2339
  throw new ProviderRpcError(
@@ -2027,15 +2343,18 @@ var AbcEvmProvider = class extends AbstractChainProvider {
2027
2343
  }
2028
2344
  const api = this.getTalkenApiClientOrThrow();
2029
2345
  const network = getNetworkName(this.chainId);
2030
- const pinHash = getCredentialManager().getPinHash() || void 0;
2346
+ const pinHash = this.getSharedCredentials()?.getPinHash() || void 0;
2031
2347
  const email = this.getRecoveryEmail();
2032
- const result = await this.withSigningCredentialRetry(
2033
- () => api.evm.signTypedData({
2034
- network,
2035
- typedData: typeof typedData === "string" ? typedData : JSON.stringify(typedData),
2036
- pin: pinHash,
2037
- ...email && { email }
2038
- })
2348
+ const result = await this.awaitWalletOperation(
2349
+ assertOperation,
2350
+ async () => this.withSigningCredentialRetry(
2351
+ () => api.evm.signTypedData({
2352
+ network,
2353
+ typedData: typeof typedData === "string" ? typedData : JSON.stringify(typedData),
2354
+ pin: pinHash,
2355
+ ...email && { email }
2356
+ })
2357
+ )
2039
2358
  );
2040
2359
  return result.signature;
2041
2360
  }
@@ -2082,25 +2401,32 @@ var AbcEvmProvider = class extends AbstractChainProvider {
2082
2401
  "Authorization payload is incomplete"
2083
2402
  );
2084
2403
  }
2085
- await this.callInterceptor("eth_signAuthorization", params);
2404
+ const assertOperation = this.captureWalletOperation();
2405
+ await this.awaitWalletOperation(
2406
+ assertOperation,
2407
+ async () => this.callInterceptor("eth_signAuthorization", params)
2408
+ );
2086
2409
  const api = this.getTalkenApiClientOrThrow();
2087
2410
  const network = getNetworkName(this.chainId);
2088
- const pinHash = getCredentialManager().getPinHash() || void 0;
2411
+ const pinHash = this.getSharedCredentials()?.getPinHash() || void 0;
2089
2412
  const email = this.getRecoveryEmail();
2090
2413
  const chainIdValue = typeof authorization.chainId === "string" ? Number(BigInt(authorization.chainId)) : Number(authorization.chainId);
2091
2414
  const nonceValue = typeof authorization.nonce === "string" ? BigInt(authorization.nonce).toString() : String(authorization.nonce);
2092
2415
  const authAddress = authorization.address;
2093
- const result = await this.withSigningCredentialRetry(
2094
- () => api.evm.signAuthorization({
2095
- network,
2096
- authorization: {
2097
- chainId: chainIdValue,
2098
- address: authAddress,
2099
- nonce: nonceValue
2100
- },
2101
- pin: pinHash,
2102
- ...email && { email }
2103
- })
2416
+ const result = await this.awaitWalletOperation(
2417
+ assertOperation,
2418
+ async () => this.withSigningCredentialRetry(
2419
+ () => api.evm.signAuthorization({
2420
+ network,
2421
+ authorization: {
2422
+ chainId: chainIdValue,
2423
+ address: authAddress,
2424
+ nonce: nonceValue
2425
+ },
2426
+ pin: pinHash,
2427
+ ...email && { email }
2428
+ })
2429
+ )
2104
2430
  );
2105
2431
  return result.authorization;
2106
2432
  }
@@ -2120,6 +2446,7 @@ var AbcEvmProvider = class extends AbstractChainProvider {
2120
2446
  return null;
2121
2447
  }
2122
2448
  const _previousChainId = this.chainId;
2449
+ this.invalidateWalletOperations();
2123
2450
  this.chainId = newChainId;
2124
2451
  if (this.wallet) {
2125
2452
  this.wallet.chainId = newChainId;
@@ -2146,11 +2473,12 @@ var AbcEvmProvider = class extends AbstractChainProvider {
2146
2473
  );
2147
2474
  }
2148
2475
  const currentChainId = this.chainId;
2476
+ const assertOperation = this.captureWalletOperation();
2149
2477
  try {
2150
2478
  const api = this.getTalkenApiClientOrThrow();
2151
- const response = await api.evm.getNonce(
2152
- getNetworkName(currentChainId),
2153
- address
2479
+ const response = await this.awaitWalletOperation(
2480
+ assertOperation,
2481
+ async () => api.evm.getNonce(getNetworkName(currentChainId), address)
2154
2482
  );
2155
2483
  const nonce = response.result !== void 0 ? typeof response.result === "number" ? `0x${response.result.toString(16)}` : response.result : void 0;
2156
2484
  if (!nonce) {
@@ -2158,6 +2486,7 @@ var AbcEvmProvider = class extends AbstractChainProvider {
2158
2486
  }
2159
2487
  return nonce;
2160
2488
  } catch (error) {
2489
+ assertOperation();
2161
2490
  logger2.error("Failed to get transaction count from ABC WaaS:", error);
2162
2491
  throw new ProviderRpcError(
2163
2492
  ProviderErrorCode.INTERNAL_ERROR,
@@ -2183,19 +2512,24 @@ var AbcEvmProvider = class extends AbstractChainProvider {
2183
2512
  'Transaction must have "to" field'
2184
2513
  );
2185
2514
  }
2515
+ const assertOperation = this.captureWalletOperation();
2186
2516
  try {
2187
- const response = await this.getTalkenApiClientOrThrow().evm.estimateGas({
2188
- network: getNetworkName(this.chainId),
2189
- from: tx.from || this.wallet?.address || "",
2190
- to: tx.to,
2191
- value: tx.value,
2192
- data: tx.data
2193
- });
2517
+ const response = await this.awaitWalletOperation(
2518
+ assertOperation,
2519
+ async () => this.getTalkenApiClientOrThrow().evm.estimateGas({
2520
+ network: getNetworkName(this.chainId),
2521
+ from: tx.from || this.wallet?.address || "",
2522
+ to: tx.to,
2523
+ value: tx.value,
2524
+ data: tx.data
2525
+ })
2526
+ );
2194
2527
  if (!response.result) {
2195
2528
  throw new Error("No result in gas estimate response");
2196
2529
  }
2197
2530
  return response.result;
2198
2531
  } catch (error) {
2532
+ assertOperation();
2199
2533
  logger2.warn("Gas estimation failed, using fallback:", error);
2200
2534
  if (tx.data && tx.data !== "0x") {
2201
2535
  return "0x493e0";
@@ -2215,16 +2549,21 @@ var AbcEvmProvider = class extends AbstractChainProvider {
2215
2549
  "eth_call requires to and data"
2216
2550
  );
2217
2551
  }
2552
+ const assertOperation = this.captureWalletOperation();
2218
2553
  try {
2219
2554
  const api = this.getTalkenApiClientOrThrow();
2220
- const response = await api.evm.ethCall({
2221
- network: getNetworkName(this.chainId),
2222
- to: tx.to,
2223
- data: tx.data,
2224
- from: tx.from || this.wallet?.address
2225
- });
2555
+ const response = await this.awaitWalletOperation(
2556
+ assertOperation,
2557
+ async () => api.evm.ethCall({
2558
+ network: getNetworkName(this.chainId),
2559
+ to: tx.to,
2560
+ data: tx.data,
2561
+ from: tx.from || this.wallet?.address
2562
+ })
2563
+ );
2226
2564
  return response?.result ?? response?.data ?? "0x";
2227
2565
  } catch (error) {
2566
+ assertOperation();
2228
2567
  throw new ProviderRpcError(
2229
2568
  ProviderErrorCode.INTERNAL_ERROR,
2230
2569
  `eth_call failed: ${error instanceof Error ? error.message : String(error)}`
@@ -2243,14 +2582,16 @@ var AbcEvmProvider = class extends AbstractChainProvider {
2243
2582
  "Missing address parameter"
2244
2583
  );
2245
2584
  }
2585
+ const assertOperation = this.captureWalletOperation();
2246
2586
  try {
2247
2587
  const api = this.getTalkenApiClientOrThrow();
2248
- const response = await api.evm.getBalance(
2249
- getNetworkName(this.chainId),
2250
- address
2588
+ const response = await this.awaitWalletOperation(
2589
+ assertOperation,
2590
+ async () => api.evm.getBalance(getNetworkName(this.chainId), address)
2251
2591
  );
2252
2592
  return response?.balance ?? "0x0";
2253
2593
  } catch (error) {
2594
+ assertOperation();
2254
2595
  throw new ProviderRpcError(
2255
2596
  ProviderErrorCode.INTERNAL_ERROR,
2256
2597
  `eth_getBalance failed: ${error instanceof Error ? error.message : String(error)}`
@@ -2261,6 +2602,11 @@ var AbcEvmProvider = class extends AbstractChainProvider {
2261
2602
  * Get current wallet
2262
2603
  */
2263
2604
  getWallet() {
2605
+ try {
2606
+ this.assertWalletSession();
2607
+ } catch {
2608
+ return null;
2609
+ }
2264
2610
  return this.wallet;
2265
2611
  }
2266
2612
  /**