@talken/talkenkit 2.3.7 → 2.3.8

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 (194) hide show
  1. package/LICENSE +9 -0
  2. package/dist/Arc-ILTINY4C.js +8 -0
  3. package/dist/Brave-4L5B7JJR.js +8 -0
  4. package/dist/Browser-XMB4J5WD.js +8 -0
  5. package/dist/Chrome-6ZDQIHC5.js +8 -0
  6. package/dist/Edge-OAWCEU7H.js +8 -0
  7. package/dist/Firefox-O66FZK3V.js +8 -0
  8. package/dist/Linux-NUJF4EPC.js +8 -0
  9. package/dist/Macos-46EJ2NPK.js +8 -0
  10. package/dist/Opera-KTUB3UWN.js +8 -0
  11. package/dist/Safari-A3Q6PIT2.js +8 -0
  12. package/dist/Windows-NL32NG52.js +8 -0
  13. package/dist/abcWallet-ES4OPRSK.js +8 -0
  14. package/dist/ar_AR-YBBYUEGS.js +8 -0
  15. package/dist/arbitrum-D2TUFPZI.js +8 -0
  16. package/dist/argentWallet-A5HM5FRP.js +8 -0
  17. package/dist/assets-4NDWRKXE.js +8 -0
  18. package/dist/avalanche-BOOSH35S.js +8 -0
  19. package/dist/base-3JMRS35B.js +8 -0
  20. package/dist/berasigWallet-6IOU73YL.js +8 -0
  21. package/dist/bestWallet-6LJUU6OL.js +8 -0
  22. package/dist/bifrostWallet-SLPPXZ2K.js +8 -0
  23. package/dist/binanceWallet-Z67J7362.js +8 -0
  24. package/dist/bitgetWallet-DLLOWMCI.js +8 -0
  25. package/dist/bitskiWallet-CPOXGABT.js +8 -0
  26. package/dist/bitverseWallet-SAK4MIS6.js +8 -0
  27. package/dist/blast-4GF24NR7.js +8 -0
  28. package/dist/bloomWallet-YIRCNQZJ.js +8 -0
  29. package/dist/braveWallet-PNBKQKJC.js +8 -0
  30. package/dist/bsc-KU6MBOYR.js +8 -0
  31. package/dist/bybitWallet-GCDBAJKO.js +8 -0
  32. package/dist/celo-5A5VXMPX.js +8 -0
  33. package/dist/chunk-TJX4M23U.js +27 -0
  34. package/dist/clvWallet-R6YRCMZO.js +8 -0
  35. package/dist/coin98Wallet-4Y3ROAGP.js +8 -0
  36. package/dist/coinbaseWallet-L4QDZB5W.js +8 -0
  37. package/dist/compassWallet-NNBX35AV.js +8 -0
  38. package/dist/components/ConnectButton/ConnectButtonRenderer.d.ts +1 -1
  39. package/dist/components/RainbowKitProvider/RainbowKitProvider.d.ts +1 -1
  40. package/dist/config/networks.d.ts +125 -0
  41. package/dist/connect-Q2RLUT5B.js +8 -0
  42. package/dist/contexts/index.d.ts +2 -2
  43. package/dist/coreWallet-PN2LMNGN.js +8 -0
  44. package/dist/create-HQ4QXTKY.js +8 -0
  45. package/dist/cronos-KZAB32FC.js +8 -0
  46. package/dist/dawnWallet-AMO43DL3.js +8 -0
  47. package/dist/de_DE-RUWMVYCQ.js +8 -0
  48. package/dist/desigWallet-AD335WX5.js +8 -0
  49. package/dist/en_US-NQ25CUR4.js +8 -0
  50. package/dist/enkryptWallet-OOP27GE2.js +8 -0
  51. package/dist/es_419-HKJPYJRI.js +8 -0
  52. package/dist/ethereum-WAFT6DML.js +8 -0
  53. package/dist/flow-XANNOAPJ.js +8 -0
  54. package/dist/foxWallet-UDUWOW52.js +8 -0
  55. package/dist/fr_FR-2O5ZDLPQ.js +1356 -0
  56. package/dist/frameWallet-BEABTFIT.js +8 -0
  57. package/dist/frontierWallet-RG47M3C5.js +8 -0
  58. package/dist/gateWallet-XOP74BMB.js +8 -0
  59. package/dist/gnosis-7GFI4V27.js +8 -0
  60. package/dist/hardhat-6HKZWC4T.js +8 -0
  61. package/dist/hi_IN-XRZ4YIUW.js +8 -0
  62. package/dist/id_ID-REEY4CSS.js +8 -0
  63. package/dist/imTokenWallet-LTPKXYUD.js +8 -0
  64. package/dist/index.d.ts +5 -1
  65. package/dist/index.js +1114 -403
  66. package/dist/injectedWallet-YCFZTULL.js +8 -0
  67. package/dist/iopayWallet-XS37QAUO.js +8 -0
  68. package/dist/ja_JP-2OPCVN6X.js +8 -0
  69. package/dist/kaia-DQ3OSYXE.js +8 -0
  70. package/dist/kaiaWallet-2XZDQZ63.js +8 -0
  71. package/dist/kaikasWallet-V2GCFPEB.js +8 -0
  72. package/dist/ko_KR-DDXBZTYT.js +8 -0
  73. package/dist/krakenWallet-3VM7ZM2O.js +8 -0
  74. package/dist/kresusWallet-4MXFQP4P.js +8 -0
  75. package/dist/ledgerWallet-YC3HF3NJ.js +8 -0
  76. package/dist/login-DGIK764Z.js +8 -0
  77. package/dist/magicEden-BLYGUG47.js +8 -0
  78. package/dist/manta-OEF3QP66.js +8 -0
  79. package/dist/mantle-EYIH4GGM.js +8 -0
  80. package/dist/metaMaskWallet-ZZMFVM52.js +8 -0
  81. package/dist/mewWallet-D6JN37EZ.js +8 -0
  82. package/dist/ms_MY-PX7G4XTD.js +8 -0
  83. package/dist/nestWallet-X3CDHKNV.js +8 -0
  84. package/dist/oktoWallet-ZYLL2RLN.js +8 -0
  85. package/dist/okxWallet-FLICEG4S.js +8 -0
  86. package/dist/omniWallet-DAQHKHUN.js +8 -0
  87. package/dist/oneInchWallet-BRGGUXND.js +8 -0
  88. package/dist/oneKeyWallet-KDU2JIFD.js +8 -0
  89. package/dist/optimism-6GXRYJDW.js +8 -0
  90. package/dist/paraSwapWallet-7UHWT54G.js +8 -0
  91. package/dist/phantomWallet-BSCGZT6L.js +8 -0
  92. package/dist/polygon-YNJM552P.js +8 -0
  93. package/dist/pt_BR-A5R4SBSC.js +8 -0
  94. package/dist/rabbyWallet-RZIUL3YN.js +8 -0
  95. package/dist/rainbowWallet-4ALDT5ZL.js +8 -0
  96. package/dist/ramperWallet-IB3JRE2F.js +8 -0
  97. package/dist/refresh-R5NYTT3S.js +8 -0
  98. package/dist/ronin-LU7LZPWA.js +8 -0
  99. package/dist/roninWallet-BS7VDK7U.js +8 -0
  100. package/dist/ru_RU-4QDZLRSW.js +1356 -0
  101. package/dist/safeWallet-5NR62MJV.js +8 -0
  102. package/dist/safeheronWallet-7ELUSU44.js +8 -0
  103. package/dist/safepalWallet-CZJABQ5N.js +8 -0
  104. package/dist/scan-BVZ7DVJ4.js +8 -0
  105. package/dist/scroll-XRP46UTI.js +8 -0
  106. package/dist/secure-GEK7TTJY.js +8 -0
  107. package/dist/seifWallet-XLBMTX4R.js +8 -0
  108. package/dist/sign-PREOQ4RR.js +8 -0
  109. package/dist/solana/SolanaWalletProvider.d.ts +1 -1
  110. package/dist/subWallet-47USA4OE.js +8 -0
  111. package/dist/tahoWallet-N3XXJ3NW.js +8 -0
  112. package/dist/talismanWallet-SV3B42TQ.js +8 -0
  113. package/dist/th_TH-4TWPYDKX.js +1356 -0
  114. package/dist/themes/baseTheme.js +1 -0
  115. package/dist/themes/darkTheme.js +1 -0
  116. package/dist/themes/lightTheme.js +1 -0
  117. package/dist/themes/midnightTheme.js +1 -0
  118. package/dist/tokenPocketWallet-7IYW3MIL.js +8 -0
  119. package/dist/tokenaryWallet-7D2LN65X.js +8 -0
  120. package/dist/tr_TR-C37KIU7M.js +1356 -0
  121. package/dist/trustWallet-HJQBMBC6.js +8 -0
  122. package/dist/uk_UA-I77HS4GO.js +1356 -0
  123. package/dist/uniswapWallet-JZ2ULELN.js +8 -0
  124. package/dist/utils/abcWaasAdapter.d.ts +75 -0
  125. package/dist/valoraWallet-PCTL6UBB.js +8 -0
  126. package/dist/vi_VN-KVPDLW26.js +8 -0
  127. package/dist/walletConnectWallet-AJ36XVBT.js +8 -0
  128. package/dist/wallets/walletConnectors/abcWallet/abcBitcoinConnector.d.ts +11 -8
  129. package/dist/wallets/walletConnectors/abcWallet/abcBitcoinConnector.js +1 -1
  130. package/dist/wallets/walletConnectors/abcWallet/abcBitcoinProvider.d.ts +4 -11
  131. package/dist/wallets/walletConnectors/abcWallet/abcBitcoinProvider.js +1 -1
  132. package/dist/wallets/walletConnectors/abcWallet/api/BitcoinApi.d.ts +1 -19
  133. package/dist/wallets/walletConnectors/abcWallet/api/BitcoinApi.js +1 -1
  134. package/dist/wallets/walletConnectors/abcWallet/api/index.js +6 -6
  135. package/dist/wallets/walletConnectors/abcWallet/index.js +6 -6
  136. package/dist/wallets/walletConnectors/abcWallet/types.d.ts +2 -0
  137. package/dist/wallets/walletConnectors/chunk-2GIBC7XF.js +39 -0
  138. package/dist/wallets/walletConnectors/chunk-2J66VMY5.js +152 -0
  139. package/dist/wallets/walletConnectors/chunk-34WMJDUY.js +481 -0
  140. package/dist/wallets/walletConnectors/chunk-3J3XZMJ7.js +39 -0
  141. package/dist/wallets/walletConnectors/chunk-4IRVZPIN.js +63 -0
  142. package/dist/wallets/walletConnectors/chunk-5OFAP55G.js +44 -0
  143. package/dist/wallets/walletConnectors/chunk-6YPK343Z.js +63 -0
  144. package/dist/wallets/walletConnectors/chunk-7P5HZGEV.js +627 -0
  145. package/dist/wallets/walletConnectors/chunk-A6LBRVGP.js +63 -0
  146. package/dist/wallets/walletConnectors/chunk-BKXPGZMQ.js +228 -0
  147. package/dist/wallets/walletConnectors/chunk-CNHVIXPV.js +228 -0
  148. package/dist/wallets/walletConnectors/chunk-DAZZIITX.js +1678 -0
  149. package/dist/wallets/walletConnectors/chunk-ESRU5KCF.js +151 -0
  150. package/dist/wallets/walletConnectors/chunk-F4JFONDA.js +601 -0
  151. package/dist/wallets/walletConnectors/chunk-GXHCAEWR.js +63 -0
  152. package/dist/wallets/walletConnectors/chunk-HDYBRMYW.js +194 -0
  153. package/dist/wallets/walletConnectors/chunk-HOE4UOHR.js +514 -0
  154. package/dist/wallets/walletConnectors/chunk-JJAJOFZI.js +63 -0
  155. package/dist/wallets/walletConnectors/chunk-KFIUFVQH.js +624 -0
  156. package/dist/wallets/walletConnectors/chunk-KFROJI25.js +535 -0
  157. package/dist/wallets/walletConnectors/chunk-KHVILXGK.js +514 -0
  158. package/dist/wallets/walletConnectors/chunk-LGT7LQAJ.js +63 -0
  159. package/dist/wallets/walletConnectors/chunk-LHBQ2Z3Q.js +63 -0
  160. package/dist/wallets/walletConnectors/chunk-M76GLEFL.js +63 -0
  161. package/dist/wallets/walletConnectors/chunk-MFIE6UCG.js +63 -0
  162. package/dist/wallets/walletConnectors/chunk-NKJLO4QH.js +39 -0
  163. package/dist/wallets/walletConnectors/chunk-NURTFXQU.js +568 -0
  164. package/dist/wallets/walletConnectors/chunk-NWDLOM7Q.js +646 -0
  165. package/dist/wallets/walletConnectors/chunk-OHRTTVNJ.js +44 -0
  166. package/dist/wallets/walletConnectors/chunk-OMYDLPUM.js +63 -0
  167. package/dist/wallets/walletConnectors/chunk-P2MTINFI.js +280 -0
  168. package/dist/wallets/walletConnectors/chunk-PUFQKZA7.js +63 -0
  169. package/dist/wallets/walletConnectors/chunk-RLBGBBIO.js +309 -0
  170. package/dist/wallets/walletConnectors/chunk-S2B56ZVJ.js +481 -0
  171. package/dist/wallets/walletConnectors/chunk-SFP47DS6.js +63 -0
  172. package/dist/wallets/walletConnectors/chunk-SNZL5LJ6.js +637 -0
  173. package/dist/wallets/walletConnectors/chunk-SPR4W5TG.js +474 -0
  174. package/dist/wallets/walletConnectors/chunk-SSDCG5BG.js +63 -0
  175. package/dist/wallets/walletConnectors/chunk-TUUNSVKZ.js +345 -0
  176. package/dist/wallets/walletConnectors/chunk-U2CUEL35.js +240 -0
  177. package/dist/wallets/walletConnectors/chunk-VLEVJVJR.js +63 -0
  178. package/dist/wallets/walletConnectors/chunk-W2VDZD74.js +478 -0
  179. package/dist/wallets/walletConnectors/chunk-WAO3KL5U.js +285 -0
  180. package/dist/wallets/walletConnectors/chunk-WYSKBMHW.js +280 -0
  181. package/dist/wallets/walletConnectors/chunk-XYPR4BAF.js +436 -0
  182. package/dist/wallets/walletConnectors/index.js +58 -58
  183. package/dist/wigwamWallet-D3MVGB5Z.js +8 -0
  184. package/dist/xdc-5NQHQJE5.js +8 -0
  185. package/dist/xdefiWallet-B4O6HAIP.js +8 -0
  186. package/dist/zealWallet-6SPNICRX.js +8 -0
  187. package/dist/zerionWallet-XZ3JCAOO.js +8 -0
  188. package/dist/zetachain-U6IILKZJ.js +8 -0
  189. package/dist/zh_CN-KGLAIP3N.js +8 -0
  190. package/dist/zh_HK-AEXEN6P6.js +8 -0
  191. package/dist/zh_TW-6C7R5V3K.js +8 -0
  192. package/dist/zkSync-TMPB52ZN.js +8 -0
  193. package/dist/zora-S46CHEOU.js +8 -0
  194. package/package.json +11 -12
@@ -0,0 +1,535 @@
1
+ "use client";
2
+
3
+ // src/wallets/walletConnectors/abcWallet/abcBitcoinProvider.ts
4
+ var EventEmitter = class {
5
+ constructor() {
6
+ this.events = /* @__PURE__ */ new Map();
7
+ }
8
+ on(event, listener) {
9
+ if (!this.events.has(event)) {
10
+ this.events.set(event, []);
11
+ }
12
+ this.events.get(event).push(listener);
13
+ return this;
14
+ }
15
+ off(event, listener) {
16
+ const listeners = this.events.get(event);
17
+ if (listeners) {
18
+ const index = listeners.indexOf(listener);
19
+ if (index !== -1) {
20
+ listeners.splice(index, 1);
21
+ }
22
+ }
23
+ return this;
24
+ }
25
+ removeListener(event, listener) {
26
+ return this.off(event, listener);
27
+ }
28
+ emit(event, ...args) {
29
+ const listeners = this.events.get(event);
30
+ if (listeners) {
31
+ for (const listener of listeners) {
32
+ listener(...args);
33
+ }
34
+ return true;
35
+ }
36
+ return false;
37
+ }
38
+ removeAllListeners(event) {
39
+ if (event) {
40
+ this.events.delete(event);
41
+ } else {
42
+ this.events.clear();
43
+ }
44
+ return this;
45
+ }
46
+ };
47
+ var BitcoinErrorCode = {
48
+ USER_REJECTED: 4001,
49
+ UNAUTHORIZED: 4100,
50
+ UNSUPPORTED_METHOD: 4200,
51
+ DISCONNECTED: 4900,
52
+ INVALID_PARAMS: -32602,
53
+ INTERNAL_ERROR: -32603,
54
+ INSUFFICIENT_FUNDS: 5001,
55
+ UTXO_NOT_FOUND: 5002
56
+ };
57
+ var BitcoinProviderError = class extends Error {
58
+ constructor(code, message, data) {
59
+ super(message);
60
+ this.code = code;
61
+ this.data = data;
62
+ this.name = "BitcoinProviderError";
63
+ }
64
+ };
65
+ var BITCOIN_NETWORKS = {
66
+ mainnet: {
67
+ name: "Bitcoin Mainnet",
68
+ type: "bitcoin",
69
+ explorer: "https://blockstream.info"
70
+ },
71
+ testnet: {
72
+ name: "Bitcoin Testnet",
73
+ type: "bitcoin_testnet",
74
+ explorer: "https://blockstream.info/testnet"
75
+ }
76
+ };
77
+ var AbcBitcoinProvider = class extends EventEmitter {
78
+ // 1 minute
79
+ constructor(client) {
80
+ super();
81
+ this.wallet = null;
82
+ this.network = BITCOIN_NETWORKS.testnet;
83
+ this.connected = false;
84
+ this.utxoCache = /* @__PURE__ */ new Map();
85
+ this.cacheExpiry = /* @__PURE__ */ new Map();
86
+ this.CACHE_TTL = 6e4;
87
+ this.client = client;
88
+ }
89
+ /**
90
+ * Set wallet information
91
+ */
92
+ setWallet(wallet) {
93
+ const previousAddress = this.wallet?.address;
94
+ this.wallet = wallet;
95
+ this.connected = true;
96
+ if (wallet.network === "bitcoin") {
97
+ this.network = BITCOIN_NETWORKS.mainnet;
98
+ } else {
99
+ this.network = BITCOIN_NETWORKS.testnet;
100
+ }
101
+ if (previousAddress !== wallet.address) {
102
+ this.emit("accountsChanged", [wallet.address]);
103
+ this.clearUtxoCache();
104
+ }
105
+ this.emit("connect", {
106
+ address: wallet.address,
107
+ network: this.network.type
108
+ });
109
+ console.log("[BitcoinProvider] \u2705 Wallet connected:", wallet.address);
110
+ }
111
+ /**
112
+ * Clear wallet (disconnect)
113
+ */
114
+ clearWallet() {
115
+ this.wallet = null;
116
+ this.connected = false;
117
+ this.clearUtxoCache();
118
+ this.emit("disconnect");
119
+ this.emit("accountsChanged", []);
120
+ console.log("[BitcoinProvider] \u{1F50C} Wallet disconnected");
121
+ }
122
+ /**
123
+ * Set PIN request callback for transaction signing
124
+ */
125
+ setRequestPinCallback(callback) {
126
+ this.requestPinCallback = callback;
127
+ }
128
+ /**
129
+ * Request PIN from user
130
+ * First tries global callback, then falls back to manual callback
131
+ */
132
+ async requestPin() {
133
+ const globalRequestPin = window.__TALKENKIT_REQUEST_PIN__;
134
+ if (globalRequestPin && typeof globalRequestPin === "function") {
135
+ return globalRequestPin("transaction");
136
+ }
137
+ if (!this.requestPinCallback) {
138
+ throw new BitcoinProviderError(
139
+ BitcoinErrorCode.INTERNAL_ERROR,
140
+ "PIN request callback not configured. Make sure RainbowKitProvider is rendered."
141
+ );
142
+ }
143
+ return this.requestPinCallback();
144
+ }
145
+ /**
146
+ * Set network
147
+ */
148
+ setNetwork(networkKey) {
149
+ const newNetwork = BITCOIN_NETWORKS[networkKey];
150
+ if (!newNetwork) {
151
+ throw new BitcoinProviderError(
152
+ BitcoinErrorCode.INVALID_PARAMS,
153
+ `Unknown network: ${networkKey}`
154
+ );
155
+ }
156
+ const previousType = this.network.type;
157
+ this.network = newNetwork;
158
+ if (previousType !== newNetwork.type) {
159
+ this.emit("networkChanged", newNetwork.type);
160
+ this.clearUtxoCache();
161
+ }
162
+ }
163
+ /**
164
+ * Get current network
165
+ */
166
+ getNetwork() {
167
+ return this.network;
168
+ }
169
+ /**
170
+ * Check if connected
171
+ */
172
+ isConnected() {
173
+ return this.connected && this.wallet !== null;
174
+ }
175
+ /**
176
+ * Get Bitcoin address
177
+ */
178
+ async getAddress() {
179
+ if (!this.wallet) {
180
+ throw new BitcoinProviderError(
181
+ BitcoinErrorCode.DISCONNECTED,
182
+ "Wallet not connected"
183
+ );
184
+ }
185
+ return this.wallet.address;
186
+ }
187
+ /**
188
+ * Get compressed public key (33 bytes)
189
+ */
190
+ async getPublicKey() {
191
+ if (!this.wallet) {
192
+ throw new BitcoinProviderError(
193
+ BitcoinErrorCode.DISCONNECTED,
194
+ "Wallet not connected"
195
+ );
196
+ }
197
+ return this.wallet.publicKey;
198
+ }
199
+ /**
200
+ * Get address type (bech32, p2pkh, etc.)
201
+ */
202
+ getAddressType() {
203
+ if (!this.wallet) {
204
+ throw new BitcoinProviderError(
205
+ BitcoinErrorCode.DISCONNECTED,
206
+ "Wallet not connected"
207
+ );
208
+ }
209
+ return this.wallet.addressType;
210
+ }
211
+ /**
212
+ * Clear UTXO cache
213
+ */
214
+ clearUtxoCache() {
215
+ this.utxoCache.clear();
216
+ this.cacheExpiry.clear();
217
+ }
218
+ /**
219
+ * Check if cache is valid
220
+ */
221
+ isCacheValid(address) {
222
+ const expiry = this.cacheExpiry.get(address);
223
+ if (!expiry)
224
+ return false;
225
+ return Date.now() < expiry;
226
+ }
227
+ /**
228
+ * Get UTXOs for address (with caching)
229
+ */
230
+ async getUtxos(forceRefresh = false) {
231
+ if (!this.wallet) {
232
+ throw new BitcoinProviderError(
233
+ BitcoinErrorCode.DISCONNECTED,
234
+ "Wallet not connected"
235
+ );
236
+ }
237
+ const address = this.wallet.address;
238
+ if (!forceRefresh && this.isCacheValid(address)) {
239
+ const cached = this.utxoCache.get(address);
240
+ if (cached) {
241
+ console.log(
242
+ `[BitcoinProvider] \u{1F4E6} Using cached UTXOs (${cached.length} items)`
243
+ );
244
+ return cached;
245
+ }
246
+ }
247
+ try {
248
+ console.log("[BitcoinProvider] \u{1F50D} Fetching UTXOs from network...");
249
+ const utxos = await this.client.bitcoin.getUtxos(
250
+ address,
251
+ this.network.type
252
+ );
253
+ this.utxoCache.set(address, utxos);
254
+ this.cacheExpiry.set(address, Date.now() + this.CACHE_TTL);
255
+ console.log(`[BitcoinProvider] \u2705 Fetched ${utxos.length} UTXOs`);
256
+ return utxos;
257
+ } catch (error) {
258
+ console.error(
259
+ "[BitcoinProvider] \u274C Failed to fetch UTXOs:",
260
+ error.message
261
+ );
262
+ throw new BitcoinProviderError(
263
+ BitcoinErrorCode.INTERNAL_ERROR,
264
+ "Failed to fetch UTXOs",
265
+ error
266
+ );
267
+ }
268
+ }
269
+ /**
270
+ * Get total balance (sum of all UTXOs)
271
+ * Returns balance in satoshis
272
+ */
273
+ async getBalance(forceRefresh = false) {
274
+ const utxos = await this.getUtxos(forceRefresh);
275
+ const balance = utxos.reduce((sum, utxo) => sum + utxo.value, 0);
276
+ console.log(
277
+ `[BitcoinProvider] \u{1F4B0} Balance: ${balance} satoshis (${balance / 1e8} BTC)`
278
+ );
279
+ return balance;
280
+ }
281
+ /**
282
+ * Estimate transaction fee
283
+ * Returns fee rate in satoshis per byte
284
+ */
285
+ async estimateFee(targetBlocks = 6) {
286
+ try {
287
+ const feeRate = await this.client.bitcoin.estimateFee(
288
+ this.network.type,
289
+ targetBlocks
290
+ );
291
+ console.log(`[BitcoinProvider] \u26FD Fee rate: ${feeRate} sat/byte`);
292
+ return feeRate;
293
+ } catch (_error) {
294
+ console.error("[BitcoinProvider] \u26A0\uFE0F Fee estimation failed, using default");
295
+ return 1;
296
+ }
297
+ }
298
+ /**
299
+ * Sign Bitcoin transaction (PSBT)
300
+ * Requires PIN input from user
301
+ *
302
+ * @param psbt - PSBT in base64 format
303
+ * @returns Signed PSBT in base64 format
304
+ */
305
+ async signTransaction(psbt) {
306
+ if (!this.wallet) {
307
+ throw new BitcoinProviderError(
308
+ BitcoinErrorCode.DISCONNECTED,
309
+ "Wallet not connected"
310
+ );
311
+ }
312
+ try {
313
+ console.log("[BitcoinProvider] \u{1F510} Signing transaction (PSBT)...");
314
+ const pin = await this.requestPin();
315
+ const result = await this.client.bitcoin.signBitcoinTransaction({
316
+ uid: this.wallet.uid,
317
+ shareId: this.wallet.shareId,
318
+ publicKey: this.wallet.publicKey,
319
+ psbt,
320
+ pin,
321
+ network: this.network.type
322
+ });
323
+ console.log(
324
+ `[BitcoinProvider] \u2705 Transaction signed (${result.signatures.length} inputs)`
325
+ );
326
+ this.emit("transactionSigned", {
327
+ psbt: result.signedPsbt,
328
+ signatures: result.signatures
329
+ });
330
+ this.clearUtxoCache();
331
+ return result.signedPsbt;
332
+ } catch (error) {
333
+ console.error(
334
+ "[BitcoinProvider] \u274C Transaction signing failed:",
335
+ error.message
336
+ );
337
+ if (error.message?.includes("cancelled") || error.message?.includes("rejected")) {
338
+ throw new BitcoinProviderError(
339
+ BitcoinErrorCode.USER_REJECTED,
340
+ "User rejected transaction",
341
+ error
342
+ );
343
+ }
344
+ this.emit("error", error);
345
+ throw new BitcoinProviderError(
346
+ BitcoinErrorCode.INTERNAL_ERROR,
347
+ "Failed to sign transaction",
348
+ error
349
+ );
350
+ }
351
+ }
352
+ /**
353
+ * Sign Bitcoin message (BIP-322)
354
+ * NOTE: Currently not supported - Bitcoin uses v2 API which doesn't have message signing endpoint
355
+ * Only transaction signing is supported via PSBT
356
+ *
357
+ * @param message - Message to sign (string)
358
+ * @returns Signature in base64 format
359
+ */
360
+ async signMessage(message) {
361
+ console.log("[BitcoinProvider] \u26A0\uFE0F Bitcoin message signing requested");
362
+ throw new BitcoinProviderError(
363
+ BitcoinErrorCode.UNSUPPORTED_METHOD,
364
+ "Bitcoin message signing is not supported. Bitcoin uses v2 API which only supports transaction signing (PSBT). Use signTransaction() instead."
365
+ );
366
+ }
367
+ /**
368
+ * High-level transaction sending (like Solana pattern)
369
+ * Creates, signs, and broadcasts transaction
370
+ *
371
+ * @param params - Transaction parameters
372
+ * @param params.toAddress - Recipient Bitcoin address
373
+ * @param params.amount - Amount in BTC (will be converted to satoshis)
374
+ * @returns Transaction hash
375
+ */
376
+ async sendTransaction(params) {
377
+ if (!this.wallet) {
378
+ throw new BitcoinProviderError(
379
+ BitcoinErrorCode.DISCONNECTED,
380
+ "Wallet not connected"
381
+ );
382
+ }
383
+ try {
384
+ console.log("[BitcoinProvider] \u{1F4B8} Starting high-level transaction...");
385
+ const authStateKey = "talkenkit_abc_auth_state";
386
+ const authState = typeof window !== "undefined" ? localStorage.getItem(authStateKey) : null;
387
+ if (!authState) {
388
+ throw new BitcoinProviderError(
389
+ BitcoinErrorCode.UNAUTHORIZED,
390
+ "Not authenticated - auth state not found"
391
+ );
392
+ }
393
+ const parsed = JSON.parse(authState);
394
+ const evmWallet = parsed.wallet;
395
+ if (!evmWallet?.uid || !evmWallet?.sid || !evmWallet?.pvencstr || !evmWallet?.wid) {
396
+ throw new BitcoinProviderError(
397
+ BitcoinErrorCode.UNAUTHORIZED,
398
+ "EVM wallet data not found (required for Bitcoin signing)"
399
+ );
400
+ }
401
+ console.log(
402
+ "[BitcoinProvider] \u{1F510} Requesting PIN for Bitcoin transaction..."
403
+ );
404
+ const pin = await this.requestPin();
405
+ const encoder = new TextEncoder();
406
+ const data = encoder.encode(pin);
407
+ const hashBuffer = await crypto.subtle.digest("SHA-256", data);
408
+ const hashArray = Array.from(new Uint8Array(hashBuffer));
409
+ const pinHash = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
410
+ const satoshis = Math.floor(params.amount * 1e8);
411
+ const SecureService = (await import("./abcWallet/secure.js")).default;
412
+ const secureService = new SecureService(this.client.bitcoin.getBaseURL());
413
+ const walletData = {
414
+ address: evmWallet.address,
415
+ keyId: evmWallet.keyId,
416
+ encryptedShare: evmWallet.encryptedShare,
417
+ uid: evmWallet.uid,
418
+ sid: evmWallet.sid,
419
+ wid: evmWallet.wid,
420
+ pvencstr: evmWallet.pvencstr,
421
+ encryptDevicePassword: evmWallet.encryptDevicePassword,
422
+ pubkey: evmWallet.pubkey
423
+ };
424
+ const txHash = await this.client.bitcoin.sendTransaction(
425
+ {
426
+ amount: satoshis.toString(),
427
+ to: params.toAddress,
428
+ pubkey: this.wallet.publicKey,
429
+ network: this.network.type
430
+ },
431
+ walletData,
432
+ pinHash,
433
+ secureService
434
+ );
435
+ console.log("[BitcoinProvider] \u2705 Transaction complete:", txHash);
436
+ this.emit("transactionBroadcasted", {
437
+ txHash,
438
+ explorerUrl: `${this.network.explorer}/tx/${txHash}`
439
+ });
440
+ this.clearUtxoCache();
441
+ return txHash;
442
+ } catch (error) {
443
+ console.error("[BitcoinProvider] \u274C Transaction failed:", error.message);
444
+ if (error.message?.includes("insufficient")) {
445
+ throw new BitcoinProviderError(
446
+ BitcoinErrorCode.INSUFFICIENT_FUNDS,
447
+ "Insufficient BTC balance",
448
+ error
449
+ );
450
+ }
451
+ if (error.message?.includes("cancelled") || error.message?.includes("rejected")) {
452
+ throw new BitcoinProviderError(
453
+ BitcoinErrorCode.USER_REJECTED,
454
+ "User rejected transaction",
455
+ error
456
+ );
457
+ }
458
+ this.emit("error", error);
459
+ throw new BitcoinProviderError(
460
+ BitcoinErrorCode.INTERNAL_ERROR,
461
+ "Failed to send transaction",
462
+ error
463
+ );
464
+ }
465
+ }
466
+ /**
467
+ * Broadcast signed transaction to network
468
+ *
469
+ * @param rawTransaction - Raw transaction in hex format
470
+ * @param psbt - Optional finalized PSBT
471
+ * @returns Transaction hash
472
+ */
473
+ async broadcastTransaction(rawTransaction, psbt) {
474
+ if (!this.wallet) {
475
+ throw new BitcoinProviderError(
476
+ BitcoinErrorCode.DISCONNECTED,
477
+ "Wallet not connected"
478
+ );
479
+ }
480
+ try {
481
+ console.log("[BitcoinProvider] \u{1F4E1} Broadcasting transaction...");
482
+ const result = await this.client.bitcoin.sendBitcoinTransaction({
483
+ network: this.network.type,
484
+ rawTransaction,
485
+ ...psbt && { psbt }
486
+ });
487
+ console.log(
488
+ "[BitcoinProvider] \u2705 Transaction broadcasted:",
489
+ result.txHash
490
+ );
491
+ this.emit("transactionBroadcasted", {
492
+ txHash: result.txHash,
493
+ explorerUrl: `${this.network.explorer}/tx/${result.txHash}`
494
+ });
495
+ this.clearUtxoCache();
496
+ return result.txHash;
497
+ } catch (error) {
498
+ console.error(
499
+ "[BitcoinProvider] \u274C Transaction broadcast failed:",
500
+ error.message
501
+ );
502
+ this.emit("error", error);
503
+ throw new BitcoinProviderError(
504
+ BitcoinErrorCode.INTERNAL_ERROR,
505
+ "Failed to broadcast transaction",
506
+ error
507
+ );
508
+ }
509
+ }
510
+ /**
511
+ * Get wallet info
512
+ */
513
+ getWalletInfo() {
514
+ if (!this.wallet)
515
+ return null;
516
+ return {
517
+ address: this.wallet.address,
518
+ publicKey: this.wallet.publicKey,
519
+ addressType: this.wallet.addressType,
520
+ network: this.network.type
521
+ };
522
+ }
523
+ /**
524
+ * Refresh UTXO cache
525
+ */
526
+ async refreshUtxos() {
527
+ return this.getUtxos(true);
528
+ }
529
+ };
530
+
531
+ export {
532
+ BitcoinProviderError,
533
+ BITCOIN_NETWORKS,
534
+ AbcBitcoinProvider
535
+ };