@talken/talkenkit 2.4.24 → 2.4.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/dist/AbcCredentialManager-DDHLW2IH.js +7 -0
  2. package/dist/abcWallet-MWUFO3JQ.js +161 -0
  3. package/dist/abcWallet-OL47MLVO.js +161 -0
  4. package/dist/abcWallet-VYU3TEGJ.js +161 -0
  5. package/dist/abcWallet-WZGXGXUA.js +161 -0
  6. package/dist/chunk-2OHX4KTB.js +5382 -0
  7. package/dist/chunk-ALBABQ53.js +354 -0
  8. package/dist/chunk-NQCUKFAV.js +5381 -0
  9. package/dist/chunk-RIEG3EJO.js +5385 -0
  10. package/dist/chunk-UKIPSWEV.js +5386 -0
  11. package/dist/hooks/useProfile.d.ts +13 -6
  12. package/dist/hooks/useSolanaWallet.d.ts +9 -8
  13. package/dist/index.d.ts +2 -2
  14. package/dist/index.js +267 -176
  15. package/dist/providers/SignConfirmationProvider/useApiClient.d.ts +3 -0
  16. package/dist/solana/ConfiguredWalletProvider.d.ts +10 -0
  17. package/dist/solana/LegacySolflareWalletAdapter.d.ts +32 -0
  18. package/dist/solana/connectExternalWallet.d.ts +9 -0
  19. package/dist/solana/isWalletReady.d.ts +2 -0
  20. package/dist/transactions/transactionStore.d.ts +2 -5
  21. package/dist/utils/apiClientFactory.d.ts +16 -1
  22. package/dist/wallets/walletConnectors/abcWallet/AbcCredentialManager.js +2 -2
  23. package/dist/wallets/walletConnectors/abcWallet/AbcEvmAutoConnector.js +2 -2
  24. package/dist/wallets/walletConnectors/abcWallet/abcBitcoinConnector.js +3 -3
  25. package/dist/wallets/walletConnectors/abcWallet/abcBitcoinProvider.js +3 -3
  26. package/dist/wallets/walletConnectors/abcWallet/abcConnector.js +6 -6
  27. package/dist/wallets/walletConnectors/abcWallet/abcProvider.js +4 -4
  28. package/dist/wallets/walletConnectors/abcWallet/abcSolanaProvider.d.ts +0 -4
  29. package/dist/wallets/walletConnectors/abcWallet/abcSolanaProvider.js +11 -3
  30. package/dist/wallets/walletConnectors/abcWallet/abcSolanaWalletAdapter.js +5 -5
  31. package/dist/wallets/walletConnectors/abcWallet/abcTronProvider.js +3 -3
  32. package/dist/wallets/walletConnectors/abcWallet/abcWallet.js +7 -7
  33. package/dist/wallets/walletConnectors/abcWallet/api/ConfigApi.d.ts +21 -0
  34. package/dist/wallets/walletConnectors/abcWallet/api/ConfigApi.js +8 -0
  35. package/dist/wallets/walletConnectors/abcWallet/api/SolanaApi.d.ts +28 -115
  36. package/dist/wallets/walletConnectors/abcWallet/api/SolanaApi.js +1 -6
  37. package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiClient.d.ts +23 -1
  38. package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiClient.js +3 -3
  39. package/dist/wallets/walletConnectors/abcWallet/api/TokenApi.d.ts +14 -0
  40. package/dist/wallets/walletConnectors/abcWallet/api/TokenApi.js +8 -0
  41. package/dist/wallets/walletConnectors/abcWallet/api/WalletscanApi.d.ts +20 -0
  42. package/dist/wallets/walletConnectors/abcWallet/api/WalletscanApi.js +1 -1
  43. package/dist/wallets/walletConnectors/abcWallet/api/index.d.ts +3 -0
  44. package/dist/wallets/walletConnectors/abcWallet/api/index.js +17 -5
  45. package/dist/wallets/walletConnectors/abcWallet/constants.d.ts +4 -0
  46. package/dist/wallets/walletConnectors/abcWallet/constants.js +1 -1
  47. package/dist/wallets/walletConnectors/abcWallet/index.d.ts +1 -1
  48. package/dist/wallets/walletConnectors/abcWallet/index.js +33 -21
  49. package/dist/wallets/walletConnectors/abcWallet/sessionUtils.js +2 -2
  50. package/dist/wallets/walletConnectors/abcWallet/types.d.ts +4 -0
  51. package/dist/wallets/walletConnectors/abcWallet/utils.js +2 -2
  52. package/dist/wallets/walletConnectors/abcWallet/walletGeneration.js +3 -3
  53. package/dist/wallets/walletConnectors/berasigWallet/berasigWallet.js +2 -2
  54. package/dist/wallets/walletConnectors/bifrostWallet/bifrostWallet.js +2 -2
  55. package/dist/wallets/walletConnectors/binanceWallet/binanceWallet.js +2 -2
  56. package/dist/wallets/walletConnectors/bitgetWallet/bitgetWallet.js +2 -2
  57. package/dist/wallets/walletConnectors/bybitWallet/bybitWallet.js +2 -2
  58. package/dist/wallets/walletConnectors/chunk-6WF4SXLB.js +156 -0
  59. package/dist/wallets/walletConnectors/chunk-7DM6H5BJ.js +54 -0
  60. package/dist/wallets/walletConnectors/chunk-7ORDZ6EQ.js +1479 -0
  61. package/dist/wallets/walletConnectors/chunk-A66MTFML.js +223 -0
  62. package/dist/wallets/walletConnectors/chunk-ACLPF2UW.js +96 -0
  63. package/dist/wallets/walletConnectors/chunk-BXH3GDX5.js +273 -0
  64. package/dist/wallets/walletConnectors/chunk-CABLJOMU.js +194 -0
  65. package/dist/wallets/walletConnectors/chunk-CE37VZAR.js +300 -0
  66. package/dist/wallets/walletConnectors/chunk-DPTDOCWL.js +205 -0
  67. package/dist/wallets/walletConnectors/chunk-E7TDM6P6.js +205 -0
  68. package/dist/wallets/walletConnectors/chunk-GBMOX5JN.js +54 -0
  69. package/dist/wallets/walletConnectors/chunk-GWYZ2IPP.js +1479 -0
  70. package/dist/wallets/walletConnectors/chunk-HF6GFAE5.js +54 -0
  71. package/dist/wallets/walletConnectors/chunk-IM7DEERX.js +585 -0
  72. package/dist/wallets/walletConnectors/chunk-INFMRNND.js +300 -0
  73. package/dist/wallets/walletConnectors/chunk-JADQLTFW.js +194 -0
  74. package/dist/wallets/walletConnectors/chunk-JGXJY3SB.js +1 -0
  75. package/dist/wallets/walletConnectors/chunk-K3VHBOXQ.js +32 -0
  76. package/dist/wallets/walletConnectors/chunk-KZS2C73S.js +814 -0
  77. package/dist/wallets/walletConnectors/chunk-LJNUFDGO.js +205 -0
  78. package/dist/wallets/walletConnectors/chunk-MO2AXXLI.js +30 -0
  79. package/dist/wallets/walletConnectors/chunk-NYDDRNUI.js +445 -0
  80. package/dist/wallets/walletConnectors/chunk-O4DNG6JJ.js +54 -0
  81. package/dist/wallets/walletConnectors/chunk-OTLZVWY7.js +39 -0
  82. package/dist/wallets/walletConnectors/chunk-PDXO6AOG.js +300 -0
  83. package/dist/wallets/walletConnectors/chunk-VDWJ3NQ5.js +52 -0
  84. package/dist/wallets/walletConnectors/chunk-VKOPUEQG.js +445 -0
  85. package/dist/wallets/walletConnectors/chunk-VTOD7PXP.js +817 -0
  86. package/dist/wallets/walletConnectors/chunk-WC7BGU5Z.js +814 -0
  87. package/dist/wallets/walletConnectors/chunk-YDSBY7NO.js +54 -0
  88. package/dist/wallets/walletConnectors/chunk-YV6IZWGE.js +393 -0
  89. package/dist/wallets/walletConnectors/chunk-Z5SBGIWT.js +300 -0
  90. package/dist/wallets/walletConnectors/chunk-ZKCUYHBK.js +300 -0
  91. package/dist/wallets/walletConnectors/clvWallet/clvWallet.js +2 -2
  92. package/dist/wallets/walletConnectors/coin98Wallet/coin98Wallet.js +2 -2
  93. package/dist/wallets/walletConnectors/coreWallet/coreWallet.js +2 -2
  94. package/dist/wallets/walletConnectors/foxWallet/foxWallet.js +2 -2
  95. package/dist/wallets/walletConnectors/frontierWallet/frontierWallet.js +2 -2
  96. package/dist/wallets/walletConnectors/gateWallet/gateWallet.js +2 -2
  97. package/dist/wallets/walletConnectors/index.js +99 -99
  98. package/dist/wallets/walletConnectors/iopayWallet/iopayWallet.js +2 -2
  99. package/dist/wallets/walletConnectors/kaiaWallet/kaiaWallet.js +2 -2
  100. package/dist/wallets/walletConnectors/kaikasWallet/kaikasWallet.js +2 -2
  101. package/dist/wallets/walletConnectors/metaMaskWallet/metaMaskWallet.js +2 -2
  102. package/dist/wallets/walletConnectors/okxWallet/okxWallet.js +2 -2
  103. package/dist/wallets/walletConnectors/rainbowWallet/rainbowWallet.js +2 -2
  104. package/dist/wallets/walletConnectors/roninWallet/roninWallet.js +2 -2
  105. package/dist/wallets/walletConnectors/safepalWallet/safepalWallet.js +2 -2
  106. package/dist/wallets/walletConnectors/subWallet/subWallet.js +2 -2
  107. package/dist/wallets/walletConnectors/tokenPocketWallet/tokenPocketWallet.js +2 -2
  108. package/dist/wallets/walletConnectors/trustWallet/trustWallet.js +2 -2
  109. package/dist/wallets/walletConnectors/zealWallet/zealWallet.js +2 -2
  110. package/dist/wallets/walletConnectors/zerionWallet/zerionWallet.js +2 -2
  111. package/package.json +1 -1
@@ -0,0 +1,205 @@
1
+ "use client";
2
+
3
+ // src/wallets/walletConnectors/abcWallet/api/WalletscanApi.ts
4
+ import { getTalkenApiClient, networkNameToChainKey } from "@talken/talkenkit";
5
+ var WalletscanApi = class {
6
+ /**
7
+ * Get all wallet tokens with balances via TalkenApiClient walletscan endpoint
8
+ */
9
+ async getWalletTokens(params) {
10
+ const api = getTalkenApiClient();
11
+ if (!api)
12
+ throw new Error("TalkenApiClient not initialized");
13
+ try {
14
+ return await api.walletscan.getTokens({
15
+ walletAddress: params.walletAddress,
16
+ chainKeys: networkNameToChainKey(params.networks)
17
+ });
18
+ } catch (error) {
19
+ console.warn("[WalletscanApi] TalkenApi getTokens failed:", error);
20
+ return [];
21
+ }
22
+ }
23
+ /**
24
+ * Get all wallet tokens with balances with timeout
25
+ */
26
+ async getWalletTokensWithTimeout(params, timeoutMs = 3e3) {
27
+ try {
28
+ return await Promise.race([
29
+ this.getWalletTokens(params),
30
+ new Promise(
31
+ (resolve) => setTimeout(() => resolve([]), timeoutMs)
32
+ )
33
+ ]);
34
+ } catch (_error) {
35
+ console.warn("[WalletscanApi] Wallet token request timed out");
36
+ return [];
37
+ }
38
+ }
39
+ /**
40
+ * Get a specific wallet token balance by contract/mint address.
41
+ */
42
+ async getWalletTokenBalance(params) {
43
+ const tokens = await this.getWalletTokens(params);
44
+ const target = params.contractAddress.toLowerCase();
45
+ return tokens.find(
46
+ (token) => token.contractAddress?.toLowerCase() === target
47
+ ) ?? null;
48
+ }
49
+ /**
50
+ * Get a specific wallet token balance by contract/mint address with timeout.
51
+ */
52
+ async getWalletTokenBalanceWithTimeout(params, timeoutMs = 3e3) {
53
+ try {
54
+ return await Promise.race([
55
+ this.getWalletTokenBalance(params),
56
+ new Promise((resolve) => setTimeout(() => resolve(null), timeoutMs))
57
+ ]);
58
+ } catch (_error) {
59
+ console.warn("[WalletscanApi] Wallet token balance request timed out");
60
+ return null;
61
+ }
62
+ }
63
+ /**
64
+ * Get token metadata via TalkenApiClient walletscan endpoint
65
+ *
66
+ * @param params - Contract address and networks
67
+ * @returns Token metadata or null if not found/failed
68
+ */
69
+ async getContractToken(params) {
70
+ const api = getTalkenApiClient();
71
+ if (!api)
72
+ throw new Error("TalkenApiClient not initialized");
73
+ try {
74
+ const tokens = await api.walletscan.getToken({
75
+ contractAddress: params.contractAddress,
76
+ chainKeys: networkNameToChainKey(params.networks)
77
+ });
78
+ return tokens.length > 0 ? tokens[0] : null;
79
+ } catch (error) {
80
+ console.warn(
81
+ "[WalletscanApi] TalkenApi getToken failed:",
82
+ params.contractAddress,
83
+ error
84
+ );
85
+ return null;
86
+ }
87
+ }
88
+ /**
89
+ * Get token metadata with timeout
90
+ *
91
+ * @param params - Contract address and networks
92
+ * @param timeoutMs - Timeout in milliseconds (default: 3000)
93
+ * @returns Token metadata or null if timeout/failed
94
+ */
95
+ async getContractTokenWithTimeout(params, timeoutMs = 3e3) {
96
+ try {
97
+ const result = await Promise.race([
98
+ this.getContractToken(params),
99
+ new Promise(
100
+ (resolve) => setTimeout(() => resolve(null), timeoutMs)
101
+ )
102
+ ]);
103
+ return result;
104
+ } catch (_error) {
105
+ console.warn(
106
+ "[WalletscanApi] Token metadata request timed out:",
107
+ params.contractAddress
108
+ );
109
+ return null;
110
+ }
111
+ }
112
+ /**
113
+ * Get native coin info via TalkenApiClient walletscan endpoint
114
+ *
115
+ * @param params - Wallet address and networks
116
+ * @returns Array of native coins or empty array if failed
117
+ */
118
+ async getNativeToken(params) {
119
+ const api = getTalkenApiClient();
120
+ if (!api)
121
+ throw new Error("TalkenApiClient not initialized");
122
+ try {
123
+ return await api.walletscan.getNativeTokens({
124
+ walletAddress: params.walletAddress,
125
+ chainKeys: networkNameToChainKey(params.networks)
126
+ });
127
+ } catch (error) {
128
+ console.warn("[WalletscanApi] TalkenApi getNativeTokens failed:", error);
129
+ return [];
130
+ }
131
+ }
132
+ /**
133
+ * Get native coin info with timeout
134
+ *
135
+ * @param params - Wallet address and networks
136
+ * @param timeoutMs - Timeout in milliseconds (default: 3000)
137
+ * @returns First native coin or null if timeout/failed
138
+ */
139
+ async getNativeTokenWithTimeout(params, timeoutMs = 3e3) {
140
+ try {
141
+ const natives = await Promise.race([
142
+ this.getNativeToken(params),
143
+ new Promise(
144
+ (resolve) => setTimeout(() => resolve([]), timeoutMs)
145
+ )
146
+ ]);
147
+ return natives.length > 0 ? natives[0] : null;
148
+ } catch (_error) {
149
+ console.warn("[WalletscanApi] Native coin request timed out");
150
+ return null;
151
+ }
152
+ }
153
+ /**
154
+ * Get NFT metadata via TalkenApiClient walletscan endpoint
155
+ *
156
+ * @param params - Contract address, wallet address, and networks
157
+ * @returns Array of NFT metadata or empty array if failed
158
+ */
159
+ async getNFT(params) {
160
+ const api = getTalkenApiClient();
161
+ if (!api)
162
+ throw new Error("TalkenApiClient not initialized");
163
+ try {
164
+ return await api.walletscan.getNfts({
165
+ chainKeys: networkNameToChainKey(params.networks),
166
+ walletAddress: params.walletAddress
167
+ });
168
+ } catch (error) {
169
+ console.warn(
170
+ "[WalletscanApi] TalkenApi getNfts failed:",
171
+ params.contractAddress,
172
+ error
173
+ );
174
+ return [];
175
+ }
176
+ }
177
+ /**
178
+ * Get NFT metadata with timeout
179
+ *
180
+ * @param params - Contract address, wallet address, and networks
181
+ * @param timeoutMs - Timeout in milliseconds (default: 3000)
182
+ * @returns First NFT or null if timeout/failed/empty
183
+ */
184
+ async getNFTWithTimeout(params, timeoutMs = 3e3) {
185
+ try {
186
+ const nfts = await Promise.race([
187
+ this.getNFT(params),
188
+ new Promise(
189
+ (resolve) => setTimeout(() => resolve([]), timeoutMs)
190
+ )
191
+ ]);
192
+ return nfts.length > 0 ? nfts[0] : null;
193
+ } catch (_error) {
194
+ console.warn(
195
+ "[WalletscanApi] NFT metadata request timed out:",
196
+ params.contractAddress
197
+ );
198
+ return null;
199
+ }
200
+ }
201
+ };
202
+
203
+ export {
204
+ WalletscanApi
205
+ };
@@ -0,0 +1,30 @@
1
+ "use client";
2
+ import {
3
+ TALKEN_API_ENDPOINTS
4
+ } from "./chunk-DPTDOCWL.js";
5
+
6
+ // src/wallets/walletConnectors/abcWallet/api/TokenApi.ts
7
+ import { getTalkenApiClient } from "@talken/talkenkit";
8
+ var TokenApi = class {
9
+ async getBalances(address, chainKey) {
10
+ const api = getTalkenApiClient();
11
+ if (!api)
12
+ throw new Error("TalkenApiClient not initialized");
13
+ const query = new URLSearchParams({ address, chainKey }).toString();
14
+ const response = await api.get(`${TALKEN_API_ENDPOINTS.TOKENS_BALANCES}?${query}`);
15
+ return Array.isArray(response) ? response : response.tokens ?? [];
16
+ }
17
+ async getTokenBalance(address, chainKey, tokenAddress) {
18
+ const balances = await this.getBalances(address, chainKey);
19
+ const matched = balances.find(
20
+ (token) => token.address?.toLowerCase() === tokenAddress.toLowerCase()
21
+ );
22
+ if (!matched?.balance)
23
+ return null;
24
+ return BigInt(matched.balance);
25
+ }
26
+ };
27
+
28
+ export {
29
+ TokenApi
30
+ };
@@ -0,0 +1,445 @@
1
+ "use client";
2
+ import {
3
+ WalletscanApi
4
+ } from "./chunk-E7TDM6P6.js";
5
+ import {
6
+ getCredentialManager
7
+ } from "./chunk-6WF4SXLB.js";
8
+
9
+ // src/wallets/walletConnectors/abcWallet/abcSolanaProvider.ts
10
+ import { getTalkenApiClient } from "@talken/talkenkit";
11
+
12
+ // src/utils/apiClientFactory.ts
13
+ function createWalletscanApi() {
14
+ return new WalletscanApi();
15
+ }
16
+
17
+ // src/wallets/walletConnectors/abcWallet/abcSolanaProvider.ts
18
+ var EventEmitter = class {
19
+ constructor() {
20
+ this.events = /* @__PURE__ */ new Map();
21
+ }
22
+ on(event, listener) {
23
+ if (!this.events.has(event)) {
24
+ this.events.set(event, []);
25
+ }
26
+ this.events.get(event).push(listener);
27
+ return this;
28
+ }
29
+ off(event, listener) {
30
+ const listeners = this.events.get(event);
31
+ if (listeners) {
32
+ const index = listeners.indexOf(listener);
33
+ if (index !== -1) {
34
+ listeners.splice(index, 1);
35
+ }
36
+ }
37
+ return this;
38
+ }
39
+ removeListener(event, listener) {
40
+ return this.off(event, listener);
41
+ }
42
+ emit(event, ...args) {
43
+ const listeners = this.events.get(event);
44
+ if (listeners) {
45
+ for (const listener of listeners) {
46
+ listener(...args);
47
+ }
48
+ return true;
49
+ }
50
+ return false;
51
+ }
52
+ removeAllListeners(event) {
53
+ if (event) {
54
+ this.events.delete(event);
55
+ } else {
56
+ this.events.clear();
57
+ }
58
+ return this;
59
+ }
60
+ };
61
+ var SolanaErrorCode = {
62
+ USER_REJECTED: 4001,
63
+ UNAUTHORIZED: 4100,
64
+ UNSUPPORTED_METHOD: 4200,
65
+ DISCONNECTED: 4900,
66
+ INVALID_PARAMS: -32602,
67
+ INTERNAL_ERROR: -32603
68
+ };
69
+ var SolanaProviderError = class extends Error {
70
+ constructor(code, message, data) {
71
+ super(message);
72
+ this.code = code;
73
+ this.data = data;
74
+ this.name = "SolanaProviderError";
75
+ }
76
+ };
77
+ var AbcSolanaProvider = class extends EventEmitter {
78
+ constructor(talkenApi) {
79
+ super();
80
+ this.wallet = null;
81
+ this.connected = false;
82
+ this.talkenApi = talkenApi;
83
+ }
84
+ /**
85
+ * Set request interceptor for sign/transfer confirmation modals
86
+ */
87
+ setRequestInterceptor(interceptor) {
88
+ this.requestInterceptor = interceptor;
89
+ }
90
+ /**
91
+ * Call request interceptor if set (throws on user cancel)
92
+ */
93
+ async callInterceptor(request) {
94
+ if (this.requestInterceptor) {
95
+ await this.requestInterceptor(request);
96
+ }
97
+ }
98
+ /**
99
+ * Set wallet information
100
+ */
101
+ setWallet(wallet) {
102
+ const previousAddress = this.wallet?.address;
103
+ this.wallet = wallet;
104
+ this.connected = true;
105
+ if (previousAddress !== wallet.address) {
106
+ this.emit("accountsChanged", [wallet.address]);
107
+ }
108
+ this.emit("connect", {
109
+ address: wallet.address,
110
+ network: wallet.network
111
+ });
112
+ }
113
+ /**
114
+ * Clear wallet (disconnect)
115
+ */
116
+ clearWallet() {
117
+ this.wallet = null;
118
+ this.connected = false;
119
+ this.emit("disconnect");
120
+ this.emit("accountsChanged", []);
121
+ }
122
+ /**
123
+ * Set TalkenApiClient for backend-proxied transaction flow
124
+ * When set, native SOL transfers will use a single API call instead of multi-step WaaS
125
+ */
126
+ setTalkenApi(talkenApi) {
127
+ this.talkenApi = talkenApi;
128
+ }
129
+ getTalkenApiClientOrThrow() {
130
+ const api = this.talkenApi || getTalkenApiClient();
131
+ if (!api) {
132
+ throw new SolanaProviderError(
133
+ SolanaErrorCode.INTERNAL_ERROR,
134
+ "TalkenApiClient not initialized"
135
+ );
136
+ }
137
+ return api;
138
+ }
139
+ getSigningNetwork() {
140
+ return this.wallet?.network === "solana" ? "solana" : "solana_devnet";
141
+ }
142
+ /**
143
+ * Check if connected
144
+ */
145
+ isConnected() {
146
+ return this.connected && this.wallet !== null;
147
+ }
148
+ /**
149
+ * Get Solana address
150
+ */
151
+ async getAddress() {
152
+ if (!this.wallet) {
153
+ throw new SolanaProviderError(
154
+ SolanaErrorCode.DISCONNECTED,
155
+ "Wallet not connected"
156
+ );
157
+ }
158
+ return this.wallet.address;
159
+ }
160
+ /**
161
+ * Get public key
162
+ */
163
+ async getPublicKey() {
164
+ if (!this.wallet) {
165
+ throw new SolanaProviderError(
166
+ SolanaErrorCode.DISCONNECTED,
167
+ "Wallet not connected"
168
+ );
169
+ }
170
+ return this.wallet.publicKey;
171
+ }
172
+ /**
173
+ * Sign Solana message (no PIN required)
174
+ * Uses encrypted_share which doesn't require PIN
175
+ */
176
+ async signMessage(encodedMessage, _display) {
177
+ if (!this.wallet) {
178
+ throw new SolanaProviderError(
179
+ SolanaErrorCode.DISCONNECTED,
180
+ "Wallet not connected"
181
+ );
182
+ }
183
+ try {
184
+ const decodedText = new TextDecoder().decode(encodedMessage);
185
+ await this.callInterceptor({
186
+ chain: "solana",
187
+ method: "signMessage",
188
+ address: this.wallet.address,
189
+ network: this.wallet.network,
190
+ message: decodedText
191
+ });
192
+ const messageHex = `0x${Array.from(encodedMessage).map((b) => b.toString(16).padStart(2, "0")).join("")}`;
193
+ const result = await this.getTalkenApiClientOrThrow().solana.sign({
194
+ message: messageHex,
195
+ encryptedShare: this.wallet.encryptedShare,
196
+ keyId: this.wallet.keyId,
197
+ secretStore: this.wallet.secretStore || "",
198
+ network: this.getSigningNetwork()
199
+ });
200
+ const signatureHex = result.signature.startsWith("0x") ? result.signature.slice(2) : result.signature;
201
+ const signatureBytes = new Uint8Array(
202
+ signatureHex.match(/.{1,2}/g)?.map((byte) => Number.parseInt(byte, 16)) || []
203
+ );
204
+ return { signature: signatureBytes };
205
+ } catch (error) {
206
+ this.emit("error", error);
207
+ throw new SolanaProviderError(
208
+ SolanaErrorCode.INTERNAL_ERROR,
209
+ "Failed to sign message",
210
+ error
211
+ );
212
+ }
213
+ }
214
+ /**
215
+ * Sign arbitrary Solana transaction (requires PIN)
216
+ * Supports both Legacy Transaction and VersionedTransaction
217
+ * Used for custom transactions, dApp interactions, and protocol integrations
218
+ */
219
+ async signTransaction(transaction) {
220
+ if (!this.wallet) {
221
+ throw new SolanaProviderError(
222
+ SolanaErrorCode.DISCONNECTED,
223
+ "Wallet not connected"
224
+ );
225
+ }
226
+ try {
227
+ let txMessage = "";
228
+ try {
229
+ txMessage = JSON.stringify(transaction, null, 2);
230
+ } catch {
231
+ txMessage = String(transaction);
232
+ }
233
+ await this.callInterceptor({
234
+ chain: "solana",
235
+ method: "signTransaction",
236
+ address: this.wallet.address,
237
+ network: this.wallet.network,
238
+ message: txMessage,
239
+ isTransaction: true
240
+ });
241
+ const { VersionedTransaction, PublicKey } = await import("@solana/web3.js");
242
+ const isVersioned = transaction instanceof VersionedTransaction;
243
+ let serialized;
244
+ if (isVersioned) {
245
+ serialized = transaction.message.serialize();
246
+ } else {
247
+ serialized = transaction.serializeMessage();
248
+ }
249
+ const messageHex = Buffer.from(serialized).toString("hex");
250
+ const signatureResponse = await this.getTalkenApiClientOrThrow().solana.sign({
251
+ keyId: this.wallet.keyId,
252
+ encryptedShare: this.wallet.encryptedShare,
253
+ secretStore: this.wallet.secretStore || "",
254
+ message: messageHex,
255
+ network: this.getSigningNetwork()
256
+ });
257
+ const signatureHex = signatureResponse.signature.startsWith("0x") ? signatureResponse.signature.slice(2) : signatureResponse.signature;
258
+ const signatureBytes = Buffer.from(signatureHex, "hex");
259
+ const publicKey = new PublicKey(this.wallet.address);
260
+ if (isVersioned) {
261
+ transaction.addSignature(publicKey, signatureBytes);
262
+ } else {
263
+ transaction.addSignature(publicKey, signatureBytes);
264
+ }
265
+ return transaction;
266
+ } catch (error) {
267
+ if (error.code === 4001 || error.cancelled) {
268
+ throw error;
269
+ }
270
+ this.emit("error", error);
271
+ throw new SolanaProviderError(
272
+ SolanaErrorCode.INTERNAL_ERROR,
273
+ "Failed to sign transaction",
274
+ error
275
+ );
276
+ }
277
+ }
278
+ /**
279
+ * Sign multiple transactions (batch signing)
280
+ */
281
+ async signAllTransactions(transactions) {
282
+ const signedTransactions = [];
283
+ for (const transaction of transactions) {
284
+ const signed = await this.signTransaction(transaction);
285
+ signedTransactions.push(signed);
286
+ }
287
+ return signedTransactions;
288
+ }
289
+ /**
290
+ * Unified transfer: SOL, SPL token, or NFT
291
+ * - No mintAddress → native SOL transfer (kind='native')
292
+ * - With mintAddress → SPL/NFT transfer (kind='spl')
293
+ * - NFT = transfer({ mintAddress, toAddress, amount: 1 })
294
+ */
295
+ async transfer(params) {
296
+ if (!this.wallet) {
297
+ throw new SolanaProviderError(
298
+ SolanaErrorCode.DISCONNECTED,
299
+ "Wallet not connected"
300
+ );
301
+ }
302
+ try {
303
+ const symbol = params.mintAddress ? "SPL" : "SOL";
304
+ await this.callInterceptor({
305
+ chain: "solana",
306
+ method: "transfer",
307
+ fromAddress: this.wallet.address,
308
+ toAddress: params.toAddress,
309
+ amount: String(params.amount),
310
+ symbol,
311
+ network: this.wallet.network,
312
+ tokenAddress: params.mintAddress,
313
+ isNativeToken: !params.mintAddress,
314
+ feeSymbol: "SOL"
315
+ });
316
+ const pinHash = getCredentialManager().getPinHash();
317
+ if (!pinHash) {
318
+ throw new SolanaProviderError(
319
+ SolanaErrorCode.INTERNAL_ERROR,
320
+ "PIN hash not found. Please login again."
321
+ );
322
+ }
323
+ console.log("[AbcSolanaProvider] transfer START", {
324
+ kind: params.mintAddress ? "spl" : "native",
325
+ toAddress: params.toAddress,
326
+ amount: params.amount,
327
+ mintAddress: params.mintAddress || null,
328
+ network: this.wallet.network,
329
+ hasPinHash: !!pinHash
330
+ });
331
+ const api = this.getTalkenApiClientOrThrow();
332
+ const apiNetwork = this.wallet.network === "solana" ? "solana" : "solana_devnet";
333
+ if (params.mintAddress) {
334
+ const walletscanApi = createWalletscanApi();
335
+ const tokenMeta = await walletscanApi.getContractTokenWithTimeout({
336
+ contractAddress: params.mintAddress,
337
+ networks: apiNetwork
338
+ });
339
+ const decimals = tokenMeta?.decimals ?? 9;
340
+ const rawAmount = Math.floor(params.amount * 10 ** decimals);
341
+ const result2 = await api.solana.transfer({
342
+ kind: "spl",
343
+ toAddress: params.toAddress,
344
+ mintAddress: params.mintAddress,
345
+ amount: String(rawAmount),
346
+ decimals,
347
+ network: apiNetwork,
348
+ pin: pinHash
349
+ });
350
+ console.log("[AbcSolanaProvider] SPL transfer result:", result2);
351
+ return { signature: result2.txHash };
352
+ }
353
+ const { LAMPORTS_PER_SOL } = await import("@solana/web3.js");
354
+ const amountLamports = params.amount * LAMPORTS_PER_SOL;
355
+ console.log("[AbcSolanaProvider] native transfer request:", {
356
+ toAddress: params.toAddress,
357
+ amountLamports: String(amountLamports),
358
+ amountSOL: params.amount
359
+ });
360
+ const result = await api.solana.transfer({
361
+ kind: "native",
362
+ toAddress: params.toAddress,
363
+ amountLamports: String(amountLamports),
364
+ network: apiNetwork,
365
+ pin: pinHash
366
+ });
367
+ console.log("[AbcSolanaProvider] native transfer result:", result);
368
+ return { signature: result.txHash };
369
+ } catch (error) {
370
+ console.error("[AbcSolanaProvider] transfer FAILED:", {
371
+ message: error.message,
372
+ code: error.code,
373
+ status: error.status,
374
+ details: error.details || error.data
375
+ });
376
+ if (error.code === 4001 || error.cancelled) {
377
+ throw error;
378
+ }
379
+ this.emit("error", error);
380
+ throw new SolanaProviderError(
381
+ SolanaErrorCode.INTERNAL_ERROR,
382
+ "Failed to transfer",
383
+ error
384
+ );
385
+ }
386
+ }
387
+ /**
388
+ * Get wallet info
389
+ */
390
+ getWalletInfo() {
391
+ if (!this.wallet)
392
+ return null;
393
+ return {
394
+ address: this.wallet.address,
395
+ publicKey: this.wallet.publicKey,
396
+ network: this.wallet.network
397
+ };
398
+ }
399
+ /**
400
+ * Get SPL token balance
401
+ *
402
+ * @param mintAddress - Token mint address
403
+ * @returns Token balance information
404
+ */
405
+ async getTokenBalance(mintAddress) {
406
+ if (!this.wallet) {
407
+ throw new SolanaProviderError(
408
+ SolanaErrorCode.DISCONNECTED,
409
+ "Wallet not connected"
410
+ );
411
+ }
412
+ try {
413
+ const walletscanApi = createWalletscanApi();
414
+ const balance = await walletscanApi.getWalletTokenBalanceWithTimeout({
415
+ walletAddress: this.wallet.address,
416
+ networks: this.wallet.network,
417
+ contractAddress: mintAddress
418
+ });
419
+ if (!balance) {
420
+ return {
421
+ amount: "0",
422
+ decimals: 0,
423
+ uiAmount: 0
424
+ };
425
+ }
426
+ return {
427
+ amount: String(balance.balance ?? 0),
428
+ decimals: balance.decimals ?? 0,
429
+ uiAmount: balance.hrBalance ?? 0
430
+ };
431
+ } catch (error) {
432
+ this.emit("error", error);
433
+ throw new SolanaProviderError(
434
+ SolanaErrorCode.INTERNAL_ERROR,
435
+ "Failed to get token balance",
436
+ error
437
+ );
438
+ }
439
+ }
440
+ };
441
+
442
+ export {
443
+ SolanaProviderError,
444
+ AbcSolanaProvider
445
+ };