@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,601 @@
1
+ "use client";
2
+ import {
3
+ BaseApiClient
4
+ } from "./chunk-WAO3KL5U.js";
5
+ import {
6
+ createAbcError
7
+ } from "./chunk-W2VDZD74.js";
8
+ import {
9
+ DEFAULT_HEADERS
10
+ } from "./chunk-VETRBBA2.js";
11
+
12
+ // src/wallets/walletConnectors/abcWallet/api/BitcoinApi.ts
13
+ var BitcoinApi = class extends BaseApiClient {
14
+ /**
15
+ * Generate Bitcoin wallet
16
+ * Uses V3 API with secp256k1 curve (same as EVM but compressed public key)
17
+ *
18
+ * @param pin - Hashed PIN (SHA-256)
19
+ * @param network - Bitcoin network (mainnet or testnet)
20
+ * @param addressType - Bitcoin address type (bech32 recommended)
21
+ * @returns Bitcoin wallet information
22
+ */
23
+ async generateBitcoinWallet(pin, network = "bitcoin", addressType = "bech32") {
24
+ console.log("[BitcoinApi] \u{1F527} Generating Bitcoin wallet...", {
25
+ network,
26
+ addressType
27
+ });
28
+ const response = await this.request("/v3/wallet/generate", {
29
+ method: "POST",
30
+ contentType: "json",
31
+ body: {
32
+ curve: "secp256k1",
33
+ // Same as EVM but compressed public key
34
+ password: pin,
35
+ network
36
+ }
37
+ });
38
+ if (response.status !== "success" || !response.result) {
39
+ console.error("[BitcoinApi] \u274C Generation failed:", response);
40
+ throw createAbcError(
41
+ "WALLET_NOT_FOUND" /* WALLET_NOT_FOUND */,
42
+ "Failed to generate Bitcoin wallet",
43
+ response
44
+ );
45
+ }
46
+ const result = response.result;
47
+ const addressResult = await this.getBitcoinAddress(
48
+ result.public_key,
49
+ network,
50
+ addressType
51
+ );
52
+ console.log("[BitcoinApi] \u2705 Bitcoin wallet generated:", addressResult);
53
+ return {
54
+ uid: result.uid || "",
55
+ sessionId: result.share_id,
56
+ shareId: result.share_id,
57
+ publicKey: result.public_key,
58
+ // Compressed (33 bytes, 0x02 or 0x03 prefix)
59
+ address: addressResult,
60
+ addressType,
61
+ keyId: result.key_id || result.share_id,
62
+ encryptedShare: result.encrypted_share || "",
63
+ network
64
+ };
65
+ }
66
+ /**
67
+ * Recover Bitcoin wallet
68
+ * Uses V3 API wallet recovery endpoint
69
+ *
70
+ * @param pin - Hashed PIN (SHA-256)
71
+ * @param network - Bitcoin network
72
+ * @param addressType - Bitcoin address type
73
+ * @returns Recovered Bitcoin wallet information
74
+ */
75
+ async recoverBitcoinWallet(pin, network = "bitcoin", addressType = "bech32") {
76
+ console.log("[BitcoinApi] \u{1F527} Recovering Bitcoin wallet...", {
77
+ network,
78
+ addressType
79
+ });
80
+ const response = await this.request("/v3/wallet/recover", {
81
+ method: "POST",
82
+ contentType: "json",
83
+ body: {
84
+ curve: "secp256k1",
85
+ password: pin,
86
+ network
87
+ }
88
+ });
89
+ if (response.status !== "success" || !response.result) {
90
+ console.error("[BitcoinApi] \u274C Recovery failed:", response);
91
+ throw createAbcError(
92
+ "WALLET_NOT_FOUND" /* WALLET_NOT_FOUND */,
93
+ "Failed to recover Bitcoin wallet",
94
+ response
95
+ );
96
+ }
97
+ const result = response.result;
98
+ const addressResult = await this.getBitcoinAddress(
99
+ result.public_key,
100
+ network,
101
+ addressType
102
+ );
103
+ console.log("[BitcoinApi] \u2705 Bitcoin wallet recovered:", addressResult);
104
+ return {
105
+ uid: result.uid || "",
106
+ sessionId: result.share_id,
107
+ shareId: result.share_id,
108
+ publicKey: result.public_key,
109
+ address: addressResult,
110
+ addressType,
111
+ keyId: result.key_id || result.share_id,
112
+ encryptedShare: result.encrypted_share || "",
113
+ network
114
+ };
115
+ }
116
+ /**
117
+ * Get Bitcoin address from compressed public key
118
+ * Converts compressed public key to Bitcoin address based on address type
119
+ *
120
+ * @param publicKey - Compressed public key (33 bytes, hex)
121
+ * @param network - Bitcoin network
122
+ * @param addressType - Address format type (currently not used by API)
123
+ * @returns Bitcoin address
124
+ */
125
+ async getBitcoinAddress(publicKey, network, _addressType = "bech32") {
126
+ const url = `${this.baseURL}/wapi/v2/btc/address`;
127
+ const params = new URLSearchParams({
128
+ pubkey: publicKey,
129
+ network
130
+ });
131
+ const response = await fetch(`${url}?${params}`, {
132
+ method: "GET",
133
+ headers: {
134
+ ...this.accessToken ? { Authorization: `Bearer ${this.accessToken}` } : {}
135
+ }
136
+ });
137
+ const data = await response.json();
138
+ if (!response.ok) {
139
+ throw createAbcError(
140
+ "NETWORK_ERROR" /* NETWORK_ERROR */,
141
+ "Failed to get Bitcoin address",
142
+ data
143
+ );
144
+ }
145
+ return data.address;
146
+ }
147
+ /**
148
+ * Get UTXOs (Unspent Transaction Outputs) for address
149
+ * Bitcoin uses UTXO model unlike EVM/Solana account model
150
+ *
151
+ * @param address - Bitcoin address
152
+ * @param network - Bitcoin network
153
+ * @returns Array of UTXOs
154
+ */
155
+ async getUtxos(address, network) {
156
+ const url = `${this.baseURL}/wapi/v2/bitcoin/utxo/list`;
157
+ const params = new URLSearchParams({ network, address });
158
+ console.log("[BitcoinApi] \u{1F50D} Fetching UTXOs for:", address);
159
+ const response = await fetch(`${url}?${params}`, {
160
+ method: "GET",
161
+ headers: {
162
+ ...DEFAULT_HEADERS,
163
+ ...this.accessToken ? { Authorization: `Bearer ${this.accessToken}` } : {}
164
+ }
165
+ });
166
+ const data = await response.json();
167
+ if (!response.ok || data.status !== "success") {
168
+ throw createAbcError(
169
+ "NETWORK_ERROR" /* NETWORK_ERROR */,
170
+ "Failed to get UTXOs",
171
+ data
172
+ );
173
+ }
174
+ const utxos = data.result?.utxos || [];
175
+ console.log(`[BitcoinApi] \u2705 Found ${utxos.length} UTXOs`);
176
+ return utxos;
177
+ }
178
+ /**
179
+ * Sign Bitcoin transaction (PSBT-based)
180
+ * Bitcoin transactions are signed using PSBT (BIP-174) format
181
+ * Each input requires individual signature
182
+ *
183
+ * @param params - Transaction signing parameters
184
+ * @returns Signed PSBT with multiple input signatures
185
+ */
186
+ async signBitcoinTransaction(params) {
187
+ const url = `${this.baseURL}/v3/wallet/sign`;
188
+ console.log("[BitcoinApi] \u{1F510} Signing Bitcoin transaction (PSBT)...");
189
+ const response = await fetch(url, {
190
+ method: "POST",
191
+ headers: {
192
+ "Content-Type": "application/json",
193
+ Accept: "application/json",
194
+ ...this.accessToken ? { Authorization: `Bearer ${this.accessToken}` } : {}
195
+ },
196
+ body: JSON.stringify({
197
+ uid: params.uid,
198
+ share_id: params.shareId,
199
+ message: params.psbt,
200
+ // PSBT in base64
201
+ password: params.pin,
202
+ network: params.network
203
+ })
204
+ });
205
+ const data = await response.json();
206
+ if (!response.ok || data.status !== "success") {
207
+ console.error("[BitcoinApi] \u274C Transaction signing failed:", data);
208
+ throw createAbcError(
209
+ "SIGNATURE_FAILED" /* SIGNATURE_FAILED */,
210
+ "Failed to sign Bitcoin transaction",
211
+ data
212
+ );
213
+ }
214
+ console.log("[BitcoinApi] \u2705 Transaction signed successfully");
215
+ return {
216
+ signedPsbt: data.result?.signedPsbt,
217
+ signatures: data.result?.signatures || []
218
+ };
219
+ }
220
+ /**
221
+ * Sign Bitcoin message (BIP-322)
222
+ * Bitcoin message signing using BIP-322 standard
223
+ * Supports both legacy and modern address types
224
+ *
225
+ * @param params - Message signing parameters
226
+ * @returns BIP-322 signature
227
+ */
228
+ async signBitcoinMessage(params) {
229
+ const url = `${this.baseURL}/v3/wallet/sign`;
230
+ console.log("[BitcoinApi] \u{1F510} Signing Bitcoin message (BIP-322)...");
231
+ const response = await fetch(url, {
232
+ method: "POST",
233
+ headers: {
234
+ "Content-Type": "application/json",
235
+ Accept: "application/json",
236
+ ...this.accessToken ? { Authorization: `Bearer ${this.accessToken}` } : {}
237
+ },
238
+ body: JSON.stringify({
239
+ uid: params.uid,
240
+ share_id: params.shareId,
241
+ message: params.message,
242
+ // Hex-encoded message
243
+ password: params.pin,
244
+ messageType: params.messageType || "bip322",
245
+ network: params.network
246
+ })
247
+ });
248
+ const data = await response.json();
249
+ if (!response.ok || data.status !== "success") {
250
+ console.error("[BitcoinApi] \u274C Message signing failed:", data);
251
+ throw createAbcError(
252
+ "SIGNATURE_FAILED" /* SIGNATURE_FAILED */,
253
+ "Failed to sign Bitcoin message",
254
+ data
255
+ );
256
+ }
257
+ console.log("[BitcoinApi] \u2705 Message signed successfully");
258
+ return {
259
+ signature: data.result?.signature,
260
+ messageHash: data.result?.messageHash,
261
+ address: data.result?.address,
262
+ network: params.network
263
+ };
264
+ }
265
+ /**
266
+ * Send Bitcoin transaction
267
+ * Broadcasts signed transaction to Bitcoin network
268
+ *
269
+ * @param params - Transaction broadcast parameters
270
+ * @returns Transaction hash
271
+ */
272
+ async sendBitcoinTransaction(params) {
273
+ const url = `${this.baseURL}/wapi/v2/bitcoin/tx/sendTransaction`;
274
+ console.log("[BitcoinApi] \u{1F4E1} Broadcasting Bitcoin transaction...");
275
+ const response = await fetch(url, {
276
+ method: "POST",
277
+ headers: {
278
+ ...DEFAULT_HEADERS,
279
+ ...this.accessToken ? { Authorization: `Bearer ${this.accessToken}` } : {}
280
+ },
281
+ body: JSON.stringify({
282
+ network: params.network,
283
+ rawTransaction: params.rawTransaction,
284
+ ...params.psbt && { psbt: params.psbt }
285
+ })
286
+ });
287
+ const data = await response.json();
288
+ if (!response.ok || data.status !== "success") {
289
+ console.error("[BitcoinApi] \u274C Transaction broadcast failed:", data);
290
+ throw createAbcError(
291
+ "NETWORK_ERROR" /* NETWORK_ERROR */,
292
+ "Failed to send Bitcoin transaction",
293
+ data
294
+ );
295
+ }
296
+ const txHash = data.result?.data;
297
+ console.log("[BitcoinApi] \u2705 Transaction broadcasted:", txHash);
298
+ return {
299
+ txHash
300
+ };
301
+ }
302
+ /**
303
+ * Generate Bitcoin transaction (Step 1 of 3)
304
+ * Creates PSBT and returns hashes to sign
305
+ *
306
+ * @param params - Transaction parameters
307
+ * @returns Transaction data with hashes to sign
308
+ */
309
+ async generateTransaction(params) {
310
+ const url = `${this.baseURL}/wapi/v2/btc/transaction/generate`;
311
+ console.log("[BitcoinApi] \u{1F527} Generating transaction...", params);
312
+ const response = await fetch(url, {
313
+ method: "POST",
314
+ headers: {
315
+ "Content-Type": "application/json",
316
+ ...this.accessToken ? { Authorization: `Bearer ${this.accessToken}` } : {}
317
+ },
318
+ body: JSON.stringify(params)
319
+ });
320
+ const data = await response.json();
321
+ if (!response.ok || !data.hashes) {
322
+ const errorMsg = typeof data.error === "string" ? data.error : JSON.stringify(data.error || data);
323
+ console.error("[BitcoinApi] \u274C Generate failed:", errorMsg);
324
+ throw createAbcError(
325
+ "NETWORK_ERROR" /* NETWORK_ERROR */,
326
+ `Failed to generate transaction: ${errorMsg}`,
327
+ data
328
+ );
329
+ }
330
+ console.log(
331
+ `[BitcoinApi] \u2705 Generated ${data.hashes.length} hashes to sign`
332
+ );
333
+ return data;
334
+ }
335
+ /**
336
+ * Sign transaction hash (Step 2 of 3)
337
+ * Uses Secure Channel encryption for signing
338
+ * Based on tg-wallet-frontend reference implementation
339
+ *
340
+ * @param hash - Transaction hash to sign
341
+ * @param wallet - Full wallet object with Bitcoin signing fields
342
+ * @param pinHash - Hashed PIN for device password
343
+ * @param secureService - Secure service instance for encryption
344
+ * @returns Signature hex string (r + s without 0x prefix on s)
345
+ */
346
+ async signHash(hash, wallet, pinHash, secureService) {
347
+ console.log("[BitcoinApi] \u{1F510} Signing hash:", `${hash.substring(0, 20)}...`);
348
+ if (!wallet.wid || !wallet.pvencstr) {
349
+ console.error("[BitcoinApi] \u274C Missing Bitcoin signing fields:", {
350
+ hasWid: !!wallet.wid,
351
+ hasPvencstr: !!wallet.pvencstr,
352
+ hasSid: !!wallet.sid,
353
+ hasUid: !!wallet.uid
354
+ });
355
+ throw createAbcError(
356
+ "WALLET_NOT_FOUND" /* WALLET_NOT_FOUND */,
357
+ "Wallet missing required fields for Bitcoin signing (wid, pvencstr)",
358
+ { hasWid: !!wallet.wid, hasPvencstr: !!wallet.pvencstr }
359
+ );
360
+ }
361
+ console.log("[BitcoinApi] \u2705 Wallet fields validated for Bitcoin signing");
362
+ console.log("[BitcoinApi] \u{1F4CB} Wallet PLAINTEXT values:", {
363
+ hasWid: !!wallet.wid,
364
+ widLength: wallet.wid?.length,
365
+ hasPvencstr: !!wallet.pvencstr,
366
+ pvencstrLength: wallet.pvencstr?.length,
367
+ hasEncryptDevicePassword: !!wallet.encryptDevicePassword,
368
+ encryptDevicePasswordLength: wallet.encryptDevicePassword?.length
369
+ });
370
+ const encryptDevicePassword = await secureService.getEncryptPlain(
371
+ wallet.encryptDevicePassword || pinHash
372
+ );
373
+ const pvencstr = await secureService.getEncryptPlain(wallet.pvencstr);
374
+ const wid = await secureService.getEncryptPlain(wallet.wid);
375
+ const secureChannelId = await secureService.getSecureChannelId();
376
+ console.log("[BitcoinApi] \u{1F510} Encrypted values:", {
377
+ encryptDevicePasswordLength: encryptDevicePassword.length,
378
+ pvencstrLength: pvencstr.length,
379
+ widLength: wid.length,
380
+ secureChannelId
381
+ });
382
+ const params = new URLSearchParams({
383
+ uid: wallet.uid,
384
+ sid: wallet.sid || "",
385
+ // Handle optional sid
386
+ hash,
387
+ pvencstr,
388
+ wid,
389
+ encryptDevicePassword
390
+ });
391
+ console.log("[BitcoinApi] \u{1F4E4} Request params:", {
392
+ uid: wallet.uid,
393
+ sid: wallet.sid || "",
394
+ hashLength: hash.length,
395
+ bodyLength: params.toString().length
396
+ });
397
+ const url = `${this.baseURL}/wapi/v2/sign/hash`;
398
+ const response = await fetch(url, {
399
+ method: "POST",
400
+ headers: {
401
+ "Content-Type": "application/x-www-form-urlencoded",
402
+ "Secure-Channel": secureChannelId,
403
+ ...this.accessToken ? { Authorization: `Bearer ${this.accessToken}` } : {}
404
+ },
405
+ body: params.toString()
406
+ });
407
+ const responseText = await response.text();
408
+ console.log("[BitcoinApi] \u{1F4E5} Raw response:", {
409
+ status: response.status,
410
+ statusText: response.statusText,
411
+ text: responseText.substring(0, 200)
412
+ });
413
+ if (!responseText) {
414
+ throw createAbcError(
415
+ "NETWORK_ERROR" /* NETWORK_ERROR */,
416
+ "Empty response from sign hash API",
417
+ { status: response.status }
418
+ );
419
+ }
420
+ let data;
421
+ try {
422
+ data = JSON.parse(responseText);
423
+ } catch (parseError) {
424
+ console.error("[BitcoinApi] \u274C JSON parse error:", parseError);
425
+ throw createAbcError(
426
+ "NETWORK_ERROR" /* NETWORK_ERROR */,
427
+ "Invalid JSON response from sign hash API",
428
+ { responseText, parseError }
429
+ );
430
+ }
431
+ if (!response.ok || data.iserr === true || !data.signstr) {
432
+ const errorDetails = data.errmsg || data.errors?.[0] || data.message || data;
433
+ console.error("[BitcoinApi] \u274C Sign failed:", errorDetails);
434
+ throw createAbcError(
435
+ "SIGNATURE_FAILED" /* SIGNATURE_FAILED */,
436
+ `Failed to sign hash: ${JSON.stringify(errorDetails)}`,
437
+ data
438
+ );
439
+ }
440
+ console.log("[BitcoinApi] \u2705 Sign successful, parsing signature...");
441
+ const signstr = JSON.parse(data.signstr);
442
+ const sig_list = signstr.sig_list;
443
+ const signatures = [];
444
+ for (const sig of sig_list) {
445
+ const r = sig.r;
446
+ const s = sig.s.startsWith("0x") ? sig.s.substring(2) : sig.s;
447
+ const combinedSig = r + s;
448
+ signatures.push(combinedSig);
449
+ }
450
+ console.log(
451
+ "[BitcoinApi] \u2705 Signature generated:",
452
+ `${signatures[0].substring(0, 32)}...`
453
+ );
454
+ return signatures[0];
455
+ }
456
+ /**
457
+ * Finalize and broadcast transaction (Step 3 of 3)
458
+ * Broadcasts signed transaction to Bitcoin network
459
+ *
460
+ * @param params - Transaction parameters with signatures
461
+ * @returns Transaction hash
462
+ */
463
+ async finalizeTransaction(params) {
464
+ const url = `${this.baseURL}/wapi/v2/btc/transaction/finalize`;
465
+ console.log("[BitcoinApi] \u{1F4E1} Broadcasting transaction...");
466
+ console.log("[BitcoinApi] \u{1F4E4} Finalize params:", {
467
+ signatureCount: params.signatureHex.length,
468
+ amount: params.amount,
469
+ to: params.to,
470
+ pubkey: `${params.pubkey.substring(0, 20)}...`
471
+ });
472
+ const response = await fetch(url, {
473
+ method: "POST",
474
+ headers: {
475
+ "Content-Type": "application/json",
476
+ ...this.accessToken ? { Authorization: `Bearer ${this.accessToken}` } : {}
477
+ },
478
+ body: JSON.stringify(params)
479
+ });
480
+ const responseText = await response.text();
481
+ console.log("[BitcoinApi] \u{1F4E5} Finalize raw response:", {
482
+ status: response.status,
483
+ statusText: response.statusText,
484
+ text: responseText.substring(0, 200)
485
+ });
486
+ if (!responseText) {
487
+ throw createAbcError(
488
+ "NETWORK_ERROR" /* NETWORK_ERROR */,
489
+ "Empty response from finalize API",
490
+ { status: response.status }
491
+ );
492
+ }
493
+ let data;
494
+ try {
495
+ data = JSON.parse(responseText);
496
+ } catch (parseError) {
497
+ console.error("[BitcoinApi] \u274C JSON parse error:", parseError);
498
+ throw createAbcError(
499
+ "NETWORK_ERROR" /* NETWORK_ERROR */,
500
+ "Invalid JSON response from finalize API",
501
+ { responseText, parseError }
502
+ );
503
+ }
504
+ console.log("[BitcoinApi] \u{1F4CB} Finalize parsed data:", data);
505
+ if (!response.ok) {
506
+ const errorMsg = data.error || data.message || data.errmsg || "Unknown error";
507
+ console.error("[BitcoinApi] \u274C Finalize failed:", errorMsg);
508
+ throw createAbcError(
509
+ "NETWORK_ERROR" /* NETWORK_ERROR */,
510
+ `Failed to finalize transaction: ${errorMsg}`,
511
+ data
512
+ );
513
+ }
514
+ const txHash = data.result?.tx_hash || data.tx_hash || data.result?.txHash || data.txHash;
515
+ if (!txHash) {
516
+ console.error("[BitcoinApi] \u274C No tx_hash in response:", data);
517
+ throw createAbcError(
518
+ "NETWORK_ERROR" /* NETWORK_ERROR */,
519
+ "Transaction hash not found in response",
520
+ data
521
+ );
522
+ }
523
+ console.log("[BitcoinApi] \u2705 Transaction sent:", txHash);
524
+ return txHash;
525
+ }
526
+ /**
527
+ * Send Bitcoin transaction (Complete flow: generate → sign → finalize)
528
+ * High-level API that handles all 3 steps
529
+ *
530
+ * @param params - Transaction parameters
531
+ * @param wallet - EVM wallet credentials
532
+ * @param pinHash - Hashed PIN
533
+ * @param secureService - Secure service instance
534
+ * @returns Transaction hash
535
+ */
536
+ async sendTransaction(params, wallet, pinHash, secureService) {
537
+ console.log("[BitcoinApi] \u{1F4B8} Starting Bitcoin transaction flow...");
538
+ const generateData = await this.generateTransaction({
539
+ amount: params.amount,
540
+ pubkey: params.pubkey,
541
+ to: params.to,
542
+ feeRate: "2"
543
+ // Default fee rate
544
+ });
545
+ const { hashes, fee_rate } = generateData;
546
+ const signatureHex = [];
547
+ for (let i = 0; i < hashes.length; i++) {
548
+ const signature = await this.signHash(
549
+ hashes[i],
550
+ wallet,
551
+ pinHash,
552
+ secureService
553
+ );
554
+ signatureHex.push(signature);
555
+ }
556
+ const txHash = await this.finalizeTransaction({
557
+ network: params.network,
558
+ signatureHex,
559
+ feeRate: fee_rate,
560
+ amount: params.amount,
561
+ pubkey: params.pubkey,
562
+ to: params.to
563
+ });
564
+ console.log("[BitcoinApi] \u2705 Transaction complete:", txHash);
565
+ return txHash;
566
+ }
567
+ /**
568
+ * Estimate Bitcoin transaction fee
569
+ * Gets recommended fee rate (satoshis per byte) for target confirmation blocks
570
+ *
571
+ * @param network - Bitcoin network
572
+ * @param targetBlocks - Target confirmation blocks (default: 6)
573
+ * @returns Fee rate in satoshis per byte
574
+ */
575
+ async estimateFee(network, targetBlocks = 6) {
576
+ const url = `${this.baseURL}/wapi/v2/bitcoin/fee/estimate`;
577
+ const params = new URLSearchParams({
578
+ network,
579
+ targetBlocks: targetBlocks.toString()
580
+ });
581
+ const response = await fetch(`${url}?${params}`, {
582
+ method: "GET",
583
+ headers: {
584
+ ...DEFAULT_HEADERS,
585
+ ...this.accessToken ? { Authorization: `Bearer ${this.accessToken}` } : {}
586
+ }
587
+ });
588
+ const data = await response.json();
589
+ if (!response.ok || data.status !== "success") {
590
+ console.warn("[BitcoinApi] \u26A0\uFE0F Fee estimation failed, using fallback");
591
+ return 1;
592
+ }
593
+ const feeRate = data.result?.feeRate || 1;
594
+ console.log(`[BitcoinApi] \u26FD Estimated fee rate: ${feeRate} sat/byte`);
595
+ return feeRate;
596
+ }
597
+ };
598
+
599
+ export {
600
+ BitcoinApi
601
+ };
@@ -0,0 +1,63 @@
1
+ "use client";
2
+ import {
3
+ TransactionApi
4
+ } from "./chunk-KD2OAMDA.js";
5
+ import {
6
+ AuthApi
7
+ } from "./chunk-W7R3JGSC.js";
8
+ import {
9
+ BitcoinApi
10
+ } from "./chunk-SPR4W5TG.js";
11
+ import {
12
+ SigningApi
13
+ } from "./chunk-4UGXLYKP.js";
14
+ import {
15
+ SolanaApi
16
+ } from "./chunk-DMRM7XAS.js";
17
+ import {
18
+ WalletApi
19
+ } from "./chunk-JBRW4UTW.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
+ };