@talken/talkenkit 2.3.4 → 2.3.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 (99) hide show
  1. package/dist/index.js +21 -27
  2. package/dist/wallets/walletConnectors/abcWallet/abcApi.js +1 -1
  3. package/dist/wallets/walletConnectors/abcWallet/abcConnector.js +2 -2
  4. package/dist/wallets/walletConnectors/abcWallet/abcSolanaWallet.js +2 -2
  5. package/dist/wallets/walletConnectors/abcWallet/abcWallet.js +3 -3
  6. package/dist/wallets/walletConnectors/abcWallet/api/index.js +4 -4
  7. package/dist/wallets/walletConnectors/abcWallet/index.js +6 -6
  8. package/dist/wallets/walletConnectors/chunk-2J66VMY5.js +152 -0
  9. package/dist/wallets/walletConnectors/chunk-2J6LHJAF.js +228 -0
  10. package/dist/wallets/walletConnectors/chunk-2W6UBYKX.js +66 -0
  11. package/dist/wallets/walletConnectors/chunk-2ZPGPZCP.js +228 -0
  12. package/dist/wallets/walletConnectors/chunk-3DPCIDW6.js +1730 -0
  13. package/dist/wallets/walletConnectors/chunk-3IVTKZ7V.js +87 -0
  14. package/dist/wallets/walletConnectors/chunk-47TQ23J4.js +63 -0
  15. package/dist/wallets/walletConnectors/chunk-4HKJ53H3.js +1742 -0
  16. package/dist/wallets/walletConnectors/chunk-4T3UOJYR.js +76 -0
  17. package/dist/wallets/walletConnectors/chunk-53IBFGVW.js +102 -0
  18. package/dist/wallets/walletConnectors/chunk-5EARL7FN.js +39 -0
  19. package/dist/wallets/walletConnectors/chunk-5NM2LK2G.js +95 -0
  20. package/dist/wallets/walletConnectors/chunk-66SCJ77O.js +63 -0
  21. package/dist/wallets/walletConnectors/chunk-6JKWIEGA.js +228 -0
  22. package/dist/wallets/walletConnectors/chunk-7L33BY4P.js +44 -0
  23. package/dist/wallets/walletConnectors/chunk-7SXCH5TL.js +1752 -0
  24. package/dist/wallets/walletConnectors/chunk-7UZBDZZZ.js +599 -0
  25. package/dist/wallets/walletConnectors/chunk-AKLKCDXT.js +186 -0
  26. package/dist/wallets/walletConnectors/chunk-ATQWOE4J.js +110 -0
  27. package/dist/wallets/walletConnectors/chunk-B6DM7J4N.js +71 -0
  28. package/dist/wallets/walletConnectors/chunk-BHMMHU7Y.js +228 -0
  29. package/dist/wallets/walletConnectors/chunk-BJYSWRV6.js +93 -0
  30. package/dist/wallets/walletConnectors/chunk-BRM4ZVXZ.js +44 -0
  31. package/dist/wallets/walletConnectors/chunk-BUDWZAL7.js +44 -0
  32. package/dist/wallets/walletConnectors/chunk-C7S72VGD.js +93 -0
  33. package/dist/wallets/walletConnectors/chunk-CSWWNAYR.js +44 -0
  34. package/dist/wallets/walletConnectors/chunk-CULIWWLV.js +101 -0
  35. package/dist/wallets/walletConnectors/chunk-D7U5WEH2.js +96 -0
  36. package/dist/wallets/walletConnectors/chunk-E4N7SPPU.js +39 -0
  37. package/dist/wallets/walletConnectors/chunk-ENU7XLF5.js +44 -0
  38. package/dist/wallets/walletConnectors/chunk-ESRU5KCF.js +151 -0
  39. package/dist/wallets/walletConnectors/chunk-FBI7UGNO.js +95 -0
  40. package/dist/wallets/walletConnectors/chunk-FF7ZIXKD.js +39 -0
  41. package/dist/wallets/walletConnectors/chunk-FJCL2YPU.js +1737 -0
  42. package/dist/wallets/walletConnectors/chunk-FSU3WBH3.js +63 -0
  43. package/dist/wallets/walletConnectors/chunk-G2IHR6PW.js +63 -0
  44. package/dist/wallets/walletConnectors/chunk-GILMNC3J.js +96 -0
  45. package/dist/wallets/walletConnectors/chunk-HDYBRMYW.js +194 -0
  46. package/dist/wallets/walletConnectors/chunk-HIZCIW5L.js +228 -0
  47. package/dist/wallets/walletConnectors/chunk-JBVBQUCS.js +73 -0
  48. package/dist/wallets/walletConnectors/chunk-JCMXNOQ5.js +63 -0
  49. package/dist/wallets/walletConnectors/chunk-JWO4ZQLK.js +98 -0
  50. package/dist/wallets/walletConnectors/chunk-K6GEK4JB.js +66 -0
  51. package/dist/wallets/walletConnectors/chunk-K6UZPSBG.js +94 -0
  52. package/dist/wallets/walletConnectors/chunk-KIQDE4N6.js +39 -0
  53. package/dist/wallets/walletConnectors/chunk-KM55XFBI.js +65 -0
  54. package/dist/wallets/walletConnectors/chunk-KOT7JYJR.js +39 -0
  55. package/dist/wallets/walletConnectors/chunk-KRAIITU7.js +39 -0
  56. package/dist/wallets/walletConnectors/chunk-KZOSE2PI.js +228 -0
  57. package/dist/wallets/walletConnectors/chunk-L7I5I4CZ.js +44 -0
  58. package/dist/wallets/walletConnectors/chunk-LNZJLKFB.js +39 -0
  59. package/dist/wallets/walletConnectors/chunk-LTBQU2GW.js +63 -0
  60. package/dist/wallets/walletConnectors/chunk-LV765WZL.js +1748 -0
  61. package/dist/wallets/walletConnectors/chunk-MSI2BPP5.js +1722 -0
  62. package/dist/wallets/walletConnectors/chunk-MX2IY5CD.js +44 -0
  63. package/dist/wallets/walletConnectors/chunk-NLX2EV7O.js +44 -0
  64. package/dist/wallets/walletConnectors/chunk-NVAZ3B3V.js +228 -0
  65. package/dist/wallets/walletConnectors/chunk-OEB7MRS5.js +39 -0
  66. package/dist/wallets/walletConnectors/chunk-OEWU3ZMN.js +39 -0
  67. package/dist/wallets/walletConnectors/chunk-P2E4LSYH.js +1678 -0
  68. package/dist/wallets/walletConnectors/chunk-P2MTINFI.js +280 -0
  69. package/dist/wallets/walletConnectors/chunk-PNMSIVVT.js +44 -0
  70. package/dist/wallets/walletConnectors/chunk-PZNYT2HC.js +1722 -0
  71. package/dist/wallets/walletConnectors/chunk-QZRNNI3E.js +39 -0
  72. package/dist/wallets/walletConnectors/chunk-R4UYVU5X.js +1721 -0
  73. package/dist/wallets/walletConnectors/chunk-R6JCHV55.js +39 -0
  74. package/dist/wallets/walletConnectors/chunk-RLBGBBIO.js +309 -0
  75. package/dist/wallets/walletConnectors/chunk-RSZS2RMC.js +44 -0
  76. package/dist/wallets/walletConnectors/chunk-S2PY4MDO.js +108 -0
  77. package/dist/wallets/walletConnectors/chunk-SCOX5RF4.js +91 -0
  78. package/dist/wallets/walletConnectors/chunk-TUUNSVKZ.js +345 -0
  79. package/dist/wallets/walletConnectors/chunk-U2CUEL35.js +240 -0
  80. package/dist/wallets/walletConnectors/chunk-V6NRLREB.js +44 -0
  81. package/dist/wallets/walletConnectors/chunk-V7E5KRXJ.js +103 -0
  82. package/dist/wallets/walletConnectors/chunk-VCBVYFLJ.js +63 -0
  83. package/dist/wallets/walletConnectors/chunk-VM7AEC7H.js +39 -0
  84. package/dist/wallets/walletConnectors/chunk-VPNKJ7PB.js +1674 -0
  85. package/dist/wallets/walletConnectors/chunk-W2VDZD74.js +478 -0
  86. package/dist/wallets/walletConnectors/chunk-WAO3KL5U.js +285 -0
  87. package/dist/wallets/walletConnectors/chunk-WPHTIILX.js +228 -0
  88. package/dist/wallets/walletConnectors/chunk-WR7HSVMH.js +228 -0
  89. package/dist/wallets/walletConnectors/chunk-WSCJY2QD.js +228 -0
  90. package/dist/wallets/walletConnectors/chunk-WSLFMQIG.js +98 -0
  91. package/dist/wallets/walletConnectors/chunk-X3JQB5QL.js +44 -0
  92. package/dist/wallets/walletConnectors/chunk-X4CDP7L7.js +228 -0
  93. package/dist/wallets/walletConnectors/chunk-XETOVXYM.js +228 -0
  94. package/dist/wallets/walletConnectors/chunk-XYPR4BAF.js +436 -0
  95. package/dist/wallets/walletConnectors/chunk-YZBFKVTX.js +1675 -0
  96. package/dist/wallets/walletConnectors/chunk-Z2E65XSS.js +96 -0
  97. package/dist/wallets/walletConnectors/chunk-Z2ZRPTPX.js +1726 -0
  98. package/dist/wallets/walletConnectors/index.js +13 -13
  99. package/package.json +1 -1
@@ -0,0 +1,63 @@
1
+ "use client";
2
+ import {
3
+ WalletApi
4
+ } from "./chunk-ESRU5KCF.js";
5
+ import {
6
+ TransactionApi
7
+ } from "./chunk-HDYBRMYW.js";
8
+ import {
9
+ AuthApi
10
+ } from "./chunk-RLBGBBIO.js";
11
+ import {
12
+ SigningApi
13
+ } from "./chunk-TUUNSVKZ.js";
14
+ import {
15
+ BitcoinApi
16
+ } from "./chunk-7UZBDZZZ.js";
17
+ import {
18
+ SolanaApi
19
+ } from "./chunk-2J66VMY5.js";
20
+
21
+ // src/wallets/walletConnectors/abcWallet/api/index.ts
22
+ var AbcWaasApiClient = class {
23
+ constructor(config) {
24
+ this.auth = new AuthApi(config);
25
+ this.wallet = new WalletApi(config);
26
+ this.transaction = new TransactionApi(config);
27
+ this.signing = new SigningApi(config);
28
+ this.solana = new SolanaApi(config);
29
+ this.bitcoin = new BitcoinApi(config);
30
+ }
31
+ /**
32
+ * Check if user is authenticated
33
+ */
34
+ isAuthenticated() {
35
+ return this.auth.isAuthenticated();
36
+ }
37
+ /**
38
+ * Check if access token is expired
39
+ */
40
+ isTokenExpired() {
41
+ return this.auth.isTokenExpired();
42
+ }
43
+ /**
44
+ * Get current access token
45
+ */
46
+ getAccessToken() {
47
+ return this.auth.getAccessToken();
48
+ }
49
+ /**
50
+ * Logout (clear tokens)
51
+ */
52
+ async logout() {
53
+ await this.auth.logout();
54
+ }
55
+ };
56
+ function createAbcWaasApiClient(config) {
57
+ return new AbcWaasApiClient(config);
58
+ }
59
+
60
+ export {
61
+ AbcWaasApiClient,
62
+ createAbcWaasApiClient
63
+ };
@@ -0,0 +1,63 @@
1
+ "use client";
2
+ import {
3
+ SigningApi
4
+ } from "./chunk-TUUNSVKZ.js";
5
+ import {
6
+ SolanaApi
7
+ } from "./chunk-2J66VMY5.js";
8
+ import {
9
+ AuthApi
10
+ } from "./chunk-RLBGBBIO.js";
11
+ import {
12
+ BitcoinApi
13
+ } from "./chunk-7UZBDZZZ.js";
14
+ import {
15
+ TransactionApi
16
+ } from "./chunk-HDYBRMYW.js";
17
+ import {
18
+ WalletApi
19
+ } from "./chunk-ESRU5KCF.js";
20
+
21
+ // src/wallets/walletConnectors/abcWallet/api/index.ts
22
+ var AbcWaasApiClient = class {
23
+ constructor(config) {
24
+ this.auth = new AuthApi(config);
25
+ this.wallet = new WalletApi(config);
26
+ this.transaction = new TransactionApi(config);
27
+ this.signing = new SigningApi(config);
28
+ this.solana = new SolanaApi(config);
29
+ this.bitcoin = new BitcoinApi(config);
30
+ }
31
+ /**
32
+ * Check if user is authenticated
33
+ */
34
+ isAuthenticated() {
35
+ return this.auth.isAuthenticated();
36
+ }
37
+ /**
38
+ * Check if access token is expired
39
+ */
40
+ isTokenExpired() {
41
+ return this.auth.isTokenExpired();
42
+ }
43
+ /**
44
+ * Get current access token
45
+ */
46
+ getAccessToken() {
47
+ return this.auth.getAccessToken();
48
+ }
49
+ /**
50
+ * Logout (clear tokens)
51
+ */
52
+ async logout() {
53
+ await this.auth.logout();
54
+ }
55
+ };
56
+ function createAbcWaasApiClient(config) {
57
+ return new AbcWaasApiClient(config);
58
+ }
59
+
60
+ export {
61
+ AbcWaasApiClient,
62
+ createAbcWaasApiClient
63
+ };
@@ -0,0 +1,96 @@
1
+ "use client";
2
+ import {
3
+ getInjectedConnector,
4
+ hasInjectedProvider
5
+ } from "./chunk-MBBGZGXF.js";
6
+ import {
7
+ getWalletConnectConnector
8
+ } from "./chunk-PODFK4OS.js";
9
+
10
+ // src/wallets/walletConnectors/coin98Wallet/coin98Wallet.ts
11
+ var coin98Wallet = ({
12
+ projectId,
13
+ walletConnectParameters
14
+ }) => {
15
+ const isCoin98WalletInjected = hasInjectedProvider({
16
+ namespace: "coin98.provider",
17
+ flag: "isCoin98"
18
+ });
19
+ const shouldUseWalletConnect = !isCoin98WalletInjected;
20
+ return {
21
+ id: "coin98",
22
+ name: "Coin98 Wallet",
23
+ iconUrl: async () => (await import("./coin98Wallet-RFXRNVWP.js")).default,
24
+ installed: isCoin98WalletInjected,
25
+ iconAccent: "#CDA349",
26
+ iconBackground: "#fff",
27
+ rdns: "coin98.com",
28
+ downloadUrls: {
29
+ android: "https://play.google.com/store/apps/details?id=coin98.crypto.finance.media",
30
+ ios: "https://apps.apple.com/vn/app/coin98-super-app/id1561969966",
31
+ mobile: "https://coin98.com/wallet",
32
+ qrCode: "https://coin98.com/wallet",
33
+ chrome: "https://chrome.google.com/webstore/detail/coin98-wallet/aeachknmefphepccionboohckonoeemg",
34
+ browserExtension: "https://coin98.com/wallet"
35
+ },
36
+ mobile: {
37
+ getUri: shouldUseWalletConnect ? (uri) => uri : void 0
38
+ },
39
+ qrCode: shouldUseWalletConnect ? {
40
+ getUri: (uri) => uri,
41
+ instructions: {
42
+ learnMoreUrl: "https://coin98.com/wallet",
43
+ steps: [
44
+ {
45
+ description: "wallet_connectors.coin98.qr_code.step1.description",
46
+ step: "install",
47
+ title: "wallet_connectors.coin98.qr_code.step1.title"
48
+ },
49
+ {
50
+ description: "wallet_connectors.coin98.qr_code.step2.description",
51
+ step: "create",
52
+ title: "wallet_connectors.coin98.qr_code.step2.title"
53
+ },
54
+ {
55
+ description: "wallet_connectors.coin98.qr_code.step3.description",
56
+ step: "scan",
57
+ title: "wallet_connectors.coin98.qr_code.step3.title"
58
+ }
59
+ ]
60
+ }
61
+ } : void 0,
62
+ extension: {
63
+ instructions: {
64
+ learnMoreUrl: "https://coin98.com/wallet",
65
+ steps: [
66
+ {
67
+ description: "wallet_connectors.coin98.extension.step1.description",
68
+ step: "install",
69
+ title: "wallet_connectors.coin98.extension.step1.title"
70
+ },
71
+ {
72
+ description: "wallet_connectors.coin98.extension.step2.description",
73
+ step: "create",
74
+ title: "wallet_connectors.coin98.extension.step2.title"
75
+ },
76
+ {
77
+ description: "wallet_connectors.coin98.extension.step3.description",
78
+ step: "refresh",
79
+ title: "wallet_connectors.coin98.extension.step3.title"
80
+ }
81
+ ]
82
+ }
83
+ },
84
+ createConnector: shouldUseWalletConnect ? getWalletConnectConnector({
85
+ projectId,
86
+ walletConnectParameters
87
+ }) : getInjectedConnector({
88
+ namespace: "coin98Wallet",
89
+ flag: "isCoin98"
90
+ })
91
+ };
92
+ };
93
+
94
+ export {
95
+ coin98Wallet
96
+ };
@@ -0,0 +1,194 @@
1
+ "use client";
2
+ import {
3
+ BaseApiClient
4
+ } from "./chunk-WAO3KL5U.js";
5
+ import {
6
+ createAbcError
7
+ } from "./chunk-W2VDZD74.js";
8
+
9
+ // src/wallets/walletConnectors/abcWallet/api/TransactionApi.ts
10
+ var TransactionApi = class extends BaseApiClient {
11
+ /**
12
+ * Send raw transaction
13
+ */
14
+ async sendRawTransaction(chainId, signedTransaction) {
15
+ const network = this.getNetworkName(chainId);
16
+ const secureChannelId = await this.secure.getSecureChannelId();
17
+ const bodyData = {
18
+ signedSerializeTx: signedTransaction,
19
+ network
20
+ };
21
+ const bodyString = new URLSearchParams(bodyData).toString();
22
+ const url = "${this.baseURL}${ABC_ENDPOINTS.SEND_RAW_TX}";
23
+ const response = await fetch(url, {
24
+ method: "POST",
25
+ headers: {
26
+ "Content-Type": "application/x-www-form-urlencoded",
27
+ "Secure-Channel": secureChannelId,
28
+ ...this.accessToken ? { Authorization: "Bearer ${this.accessToken}" } : {}
29
+ },
30
+ body: bodyString
31
+ });
32
+ const text = await response.text();
33
+ if (!text) {
34
+ throw createAbcError(
35
+ "NETWORK_ERROR" /* NETWORK_ERROR */,
36
+ "Empty response from sendRawTx API (status: ${response.status})",
37
+ { status: response.status }
38
+ );
39
+ }
40
+ const res = JSON.parse(text);
41
+ if (response.status === 401 && this.refreshToken) {
42
+ try {
43
+ await this.refreshAccessToken();
44
+ const retryResponse = await fetch(url, {
45
+ method: "POST",
46
+ headers: {
47
+ "Content-Type": "application/x-www-form-urlencoded",
48
+ "Secure-Channel": secureChannelId,
49
+ ...this.accessToken ? { Authorization: "Bearer ${this.accessToken}" } : {}
50
+ },
51
+ body: bodyString
52
+ });
53
+ const retryText = await retryResponse.text();
54
+ if (!retryText) {
55
+ throw createAbcError(
56
+ "NETWORK_ERROR" /* NETWORK_ERROR */,
57
+ "Empty response after retry (status: ${retryResponse.status})",
58
+ { status: retryResponse.status }
59
+ );
60
+ }
61
+ const retryRes = JSON.parse(retryText);
62
+ if (retryRes.item || retryRes.txHash || retryRes.result?.txHash) {
63
+ const txHash = retryRes.item || retryRes.txHash || retryRes.result.txHash;
64
+ return { txHash };
65
+ }
66
+ throw createAbcError(
67
+ "NETWORK_ERROR" /* NETWORK_ERROR */,
68
+ "Failed to send transaction after token refresh",
69
+ retryRes
70
+ );
71
+ } catch (refreshError) {
72
+ console.error(
73
+ "Token refresh failed in sendRawTransaction:",
74
+ refreshError
75
+ );
76
+ throw refreshError;
77
+ }
78
+ }
79
+ if (res.result) {
80
+ if (typeof res.result === "string") {
81
+ return { txHash: res.result };
82
+ }
83
+ if (res.result.txHash) {
84
+ return { txHash: res.result.txHash };
85
+ }
86
+ }
87
+ if (res.item) {
88
+ return { txHash: res.item };
89
+ }
90
+ if (res.txHash) {
91
+ return { txHash: res.txHash };
92
+ }
93
+ throw createAbcError(
94
+ "NETWORK_ERROR" /* NETWORK_ERROR */,
95
+ "Failed to send transaction",
96
+ res
97
+ );
98
+ }
99
+ /**
100
+ * Get transaction count (nonce)
101
+ */
102
+ async getTransactionCount(_address, _network, _block = "latest") {
103
+ const nonceUrl = "${this.baseURL}${ABC_ENDPOINTS.TRANSACTION_COUNT}?address=${address}&network=${network}&block=${block}";
104
+ const response = await fetch(nonceUrl, {
105
+ method: "GET",
106
+ headers: {
107
+ ...this.accessToken ? { Authorization: "Bearer ${this.accessToken}" } : {}
108
+ }
109
+ });
110
+ if (response.ok) {
111
+ const data = await response.json();
112
+ return Number.parseInt(data.result, 16);
113
+ }
114
+ throw createAbcError(
115
+ "NETWORK_ERROR" /* NETWORK_ERROR */,
116
+ "Failed to get transaction count"
117
+ );
118
+ }
119
+ /**
120
+ * Get suggested gas fees for EIP-1559
121
+ */
122
+ async getSuggestedGasFees(_network) {
123
+ const url = "${this.baseURL}${ABC_ENDPOINTS.GAS_SUGGESTED_FEES}?network=${network}";
124
+ const response = await fetch(url, {
125
+ method: "GET",
126
+ headers: {
127
+ ...this.accessToken ? { Authorization: "Bearer ${this.accessToken}" } : {}
128
+ }
129
+ });
130
+ if (response.ok) {
131
+ const data = await response.json();
132
+ return data;
133
+ }
134
+ throw createAbcError(
135
+ "NETWORK_ERROR" /* NETWORK_ERROR */,
136
+ "Failed to get suggested gas fees"
137
+ );
138
+ }
139
+ /**
140
+ * Estimate gas limit for EIP-1559 transaction
141
+ */
142
+ async estimateGas(params) {
143
+ const estimateBody = new URLSearchParams({
144
+ network: params.network,
145
+ to: params.to || "0x",
146
+ ...params.from ? { from: params.from } : {},
147
+ ...params.value ? { value: params.value } : {},
148
+ ...params.data && params.data !== "0x" ? { data: params.data } : {},
149
+ ...params.maxFeePerGas ? { maxFeePerGas: params.maxFeePerGas } : {},
150
+ ...params.maxPriorityFeePerGas ? { maxPriorityFeePerGas: params.maxPriorityFeePerGas } : {}
151
+ });
152
+ const url = "${this.baseURL}${ABC_ENDPOINTS.GAS_ESTIMATE_EIP1559}";
153
+ const response = await fetch(url, {
154
+ method: "POST",
155
+ headers: {
156
+ "Content-Type": "application/x-www-form-urlencoded",
157
+ ...this.accessToken ? { Authorization: "Bearer ${this.accessToken}" } : {}
158
+ },
159
+ body: estimateBody.toString()
160
+ });
161
+ const data = await response.json();
162
+ if (response.ok && data.result) {
163
+ return data.result;
164
+ }
165
+ const fallbackGasLimit = "0x2dc6c0";
166
+ console.warn("\u26A0\uFE0F Gas estimate failed, using fallback:", {
167
+ error: data.errorMessage || data.msg,
168
+ fallbackGasLimit
169
+ });
170
+ return fallbackGasLimit;
171
+ }
172
+ /**
173
+ * Convert chainId to network name
174
+ */
175
+ getNetworkName(chainId) {
176
+ const networkMap = {
177
+ 1: "ethereum",
178
+ 11155111: "ethereum_sepolia",
179
+ 8217: "klaytn",
180
+ 1001: "klaytn_baobab",
181
+ 137: "polygon",
182
+ 80002: "polygon_amoy",
183
+ 42161: "arbitrum",
184
+ 421614: "arbitrum_sepolia",
185
+ 5e3: "mantle",
186
+ 5003: "mantle_testnet"
187
+ };
188
+ return networkMap[chainId] || "ethereum";
189
+ }
190
+ };
191
+
192
+ export {
193
+ TransactionApi
194
+ };
@@ -0,0 +1,228 @@
1
+ "use client";
2
+ import {
3
+ createAbcWaasClient
4
+ } from "./chunk-MSI2BPP5.js";
5
+ import {
6
+ createAbcEvmProvider
7
+ } from "./chunk-73B7HWCT.js";
8
+ import {
9
+ clearAuthState,
10
+ clearEncryptedTokens,
11
+ loadAuthState,
12
+ saveAuthState
13
+ } from "./chunk-W23N7VC4.js";
14
+
15
+ // src/wallets/walletConnectors/abcWallet/abcConnector.ts
16
+ import { createConnector } from "wagmi";
17
+ function abcConnector(options) {
18
+ const { config } = options;
19
+ return createConnector((wagmiConfig) => {
20
+ const client = createAbcWaasClient(config);
21
+ const provider = createAbcEvmProvider(client);
22
+ let accountsChangedHandler;
23
+ let chainChangedHandler;
24
+ let disconnectHandler;
25
+ return {
26
+ id: "abc",
27
+ name: "ABC Wallet",
28
+ type: "abc",
29
+ /**
30
+ * Connect wallet
31
+ */
32
+ async connect() {
33
+ try {
34
+ const authState = loadAuthState();
35
+ console.log("\u{1F527} ABC Connector connect() called:", {
36
+ hasAuthState: !!authState,
37
+ isAuthenticated: authState?.isAuthenticated,
38
+ hasWallet: !!authState?.wallet,
39
+ walletAddress: authState?.wallet?.address
40
+ });
41
+ if (!authState || !authState.isAuthenticated || !authState.wallet) {
42
+ throw new Error("ABC_LOGIN_REQUIRED");
43
+ }
44
+ provider.setWallet(authState.wallet);
45
+ console.log("\u2705 Provider wallet set:", {
46
+ address: authState.wallet.address,
47
+ hasPIN: !!authState.pin
48
+ });
49
+ const accounts = await provider.request({
50
+ method: "eth_requestAccounts"
51
+ });
52
+ const currentChainId = await provider.request({
53
+ method: "eth_chainId"
54
+ });
55
+ if (accountsChangedHandler) {
56
+ provider.removeListener("accountsChanged", accountsChangedHandler);
57
+ }
58
+ accountsChangedHandler = (accounts2) => {
59
+ wagmiConfig.emitter.emit("change", {
60
+ accounts: accounts2
61
+ });
62
+ };
63
+ provider.on("accountsChanged", accountsChangedHandler);
64
+ if (chainChangedHandler) {
65
+ provider.removeListener("chainChanged", chainChangedHandler);
66
+ }
67
+ chainChangedHandler = (chainId) => {
68
+ wagmiConfig.emitter.emit("change", {
69
+ chainId: Number(chainId)
70
+ });
71
+ };
72
+ provider.on("chainChanged", chainChangedHandler);
73
+ if (disconnectHandler) {
74
+ provider.removeListener("disconnect", disconnectHandler);
75
+ }
76
+ disconnectHandler = () => {
77
+ wagmiConfig.emitter.emit("disconnect");
78
+ this.onDisconnect();
79
+ };
80
+ provider.on("disconnect", disconnectHandler);
81
+ return {
82
+ accounts,
83
+ chainId: Number(currentChainId)
84
+ };
85
+ } catch (error) {
86
+ if (error.message === "ABC_LOGIN_REQUIRED") {
87
+ throw error;
88
+ }
89
+ throw error;
90
+ }
91
+ },
92
+ /**
93
+ * Disconnect wallet
94
+ */
95
+ async disconnect() {
96
+ if (accountsChangedHandler) {
97
+ provider.removeListener("accountsChanged", accountsChangedHandler);
98
+ accountsChangedHandler = void 0;
99
+ }
100
+ if (chainChangedHandler) {
101
+ provider.removeListener("chainChanged", chainChangedHandler);
102
+ chainChangedHandler = void 0;
103
+ }
104
+ if (disconnectHandler) {
105
+ provider.removeListener("disconnect", disconnectHandler);
106
+ disconnectHandler = void 0;
107
+ }
108
+ provider.clearWallet();
109
+ await client.logout();
110
+ let savedPinHash = null;
111
+ let savedEmail = null;
112
+ if (typeof window !== "undefined") {
113
+ savedPinHash = localStorage.getItem("talkenkit_abc_pin_hash");
114
+ savedEmail = localStorage.getItem("talkenkit_abc_saved_email");
115
+ }
116
+ clearAuthState();
117
+ clearEncryptedTokens();
118
+ if (typeof window !== "undefined") {
119
+ localStorage.removeItem("talkenkit_abc_enc_salt");
120
+ localStorage.removeItem("talkenkit_abc_enc_tokens");
121
+ if (savedPinHash) {
122
+ localStorage.setItem("talkenkit_abc_pin_hash", savedPinHash);
123
+ }
124
+ if (savedEmail) {
125
+ localStorage.setItem("talkenkit_abc_saved_email", savedEmail);
126
+ }
127
+ }
128
+ console.log("\u2705 ABC Wallet disconnected (PIN preserved)");
129
+ },
130
+ /**
131
+ * Get accounts
132
+ */
133
+ async getAccounts() {
134
+ const accounts = await provider.request({
135
+ method: "eth_accounts"
136
+ });
137
+ return accounts.map((account) => account);
138
+ },
139
+ /**
140
+ * Get chain ID
141
+ */
142
+ async getChainId() {
143
+ const chainId = await provider.request({
144
+ method: "eth_chainId"
145
+ });
146
+ return Number(chainId);
147
+ },
148
+ /**
149
+ * Get provider
150
+ */
151
+ async getProvider() {
152
+ return provider;
153
+ },
154
+ /**
155
+ * Check if authorized (has valid session)
156
+ */
157
+ async isAuthorized() {
158
+ try {
159
+ const authState = loadAuthState();
160
+ if (!authState || !authState.isAuthenticated) {
161
+ return false;
162
+ }
163
+ return client.isAuthenticated();
164
+ } catch {
165
+ return false;
166
+ }
167
+ },
168
+ /**
169
+ * Switch chain
170
+ */
171
+ async switchChain({ chainId }) {
172
+ await provider.request({
173
+ method: "wallet_switchEthereumChain",
174
+ params: [{ chainId: `0x${chainId.toString(16)}` }]
175
+ });
176
+ const newChainId = await this.getChainId();
177
+ const authState = loadAuthState();
178
+ if (authState?.wallet) {
179
+ authState.wallet.chainId = newChainId;
180
+ saveAuthState(authState);
181
+ }
182
+ return wagmiConfig.chains.find((x) => x.id === chainId) ?? {
183
+ id: chainId,
184
+ name: `Chain ${chainId}`,
185
+ nativeCurrency: {
186
+ name: "Ether",
187
+ decimals: 18,
188
+ symbol: "ETH"
189
+ },
190
+ rpcUrls: {
191
+ default: { http: [""] }
192
+ }
193
+ };
194
+ },
195
+ /**
196
+ * Handle accounts changed
197
+ */
198
+ onAccountsChanged(accounts) {
199
+ if (accounts.length === 0) {
200
+ this.onDisconnect();
201
+ } else {
202
+ wagmiConfig.emitter.emit("change", {
203
+ accounts
204
+ });
205
+ }
206
+ },
207
+ /**
208
+ * Handle chain changed
209
+ */
210
+ onChainChanged(chain) {
211
+ const chainId = Number(chain);
212
+ wagmiConfig.emitter.emit("change", { chainId });
213
+ },
214
+ /**
215
+ * Handle disconnect
216
+ */
217
+ onDisconnect(_error) {
218
+ provider.clearWallet();
219
+ clearAuthState();
220
+ wagmiConfig.emitter.emit("disconnect");
221
+ }
222
+ };
223
+ });
224
+ }
225
+
226
+ export {
227
+ abcConnector
228
+ };