@swapkit/wallets 4.0.0-beta.53 → 4.0.0-beta.55

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 (284) hide show
  1. package/dist/{chunk-e674mh4n.js → chunk-mcrgqfr9.js} +3 -3
  2. package/dist/{chunk-e674mh4n.js.map → chunk-mcrgqfr9.js.map} +1 -1
  3. package/dist/{chunk-mvbb9fwb.js → chunk-sbf0f2p4.js} +2 -2
  4. package/dist/{chunk-p2ca0j1v.js → chunk-yqaz2d25.js} +3 -3
  5. package/dist/{chunk-p2ca0j1v.js.map → chunk-yqaz2d25.js.map} +1 -1
  6. package/dist/src/bitget/index.cjs +2 -2
  7. package/dist/src/bitget/index.cjs.map +3 -3
  8. package/dist/src/bitget/index.js +2 -2
  9. package/dist/src/bitget/index.js.map +3 -3
  10. package/dist/src/coinbase/index.cjs +2 -2
  11. package/dist/src/coinbase/index.cjs.map +3 -3
  12. package/dist/src/coinbase/index.js +2 -2
  13. package/dist/src/coinbase/index.js.map +3 -3
  14. package/dist/src/cosmostation/index.cjs +2 -2
  15. package/dist/src/cosmostation/index.cjs.map +3 -3
  16. package/dist/src/cosmostation/index.js +2 -2
  17. package/dist/src/cosmostation/index.js.map +3 -3
  18. package/dist/src/ctrl/index.cjs +2 -2
  19. package/dist/src/ctrl/index.cjs.map +3 -3
  20. package/dist/src/ctrl/index.js +2 -2
  21. package/dist/src/ctrl/index.js.map +3 -3
  22. package/dist/src/evm-extensions/index.cjs +2 -2
  23. package/dist/src/evm-extensions/index.cjs.map +3 -3
  24. package/dist/src/evm-extensions/index.js +2 -2
  25. package/dist/src/evm-extensions/index.js.map +3 -3
  26. package/dist/src/exodus/index.cjs +2 -2
  27. package/dist/src/exodus/index.cjs.map +3 -3
  28. package/dist/src/exodus/index.js +2 -2
  29. package/dist/src/exodus/index.js.map +3 -3
  30. package/dist/src/index.cjs +2 -2
  31. package/dist/src/index.cjs.map +5 -3
  32. package/dist/src/index.js +2 -2
  33. package/dist/src/index.js.map +5 -3
  34. package/dist/src/keepkey-bex/index.cjs +2 -2
  35. package/dist/src/keepkey-bex/index.cjs.map +3 -3
  36. package/dist/src/keepkey-bex/index.js +2 -2
  37. package/dist/src/keepkey-bex/index.js.map +3 -3
  38. package/dist/src/keepkey.cjs +4 -0
  39. package/dist/src/keepkey.cjs.map +10 -0
  40. package/dist/src/keepkey.js +4 -0
  41. package/dist/src/keepkey.js.map +10 -0
  42. package/dist/src/keplr/index.cjs +2 -2
  43. package/dist/src/keplr/index.cjs.map +3 -3
  44. package/dist/src/keplr/index.js +2 -2
  45. package/dist/src/keplr/index.js.map +3 -3
  46. package/dist/src/keystore.cjs +4 -0
  47. package/dist/src/keystore.cjs.map +10 -0
  48. package/dist/src/keystore.js +4 -0
  49. package/dist/src/keystore.js.map +10 -0
  50. package/dist/src/ledger.cjs +4 -0
  51. package/dist/src/ledger.cjs.map +10 -0
  52. package/dist/src/ledger.js +4 -0
  53. package/dist/src/ledger.js.map +10 -0
  54. package/dist/src/okx/index.cjs +2 -2
  55. package/dist/src/okx/index.cjs.map +4 -4
  56. package/dist/src/okx/index.js +2 -2
  57. package/dist/src/okx/index.js.map +4 -4
  58. package/dist/src/onekey/index.cjs +2 -2
  59. package/dist/src/onekey/index.cjs.map +3 -3
  60. package/dist/src/onekey/index.js +2 -2
  61. package/dist/src/onekey/index.js.map +3 -3
  62. package/dist/src/phantom/index.cjs +2 -2
  63. package/dist/src/phantom/index.cjs.map +3 -3
  64. package/dist/src/phantom/index.js +2 -2
  65. package/dist/src/phantom/index.js.map +3 -3
  66. package/dist/src/polkadotjs/index.cjs +2 -2
  67. package/dist/src/polkadotjs/index.cjs.map +3 -3
  68. package/dist/src/polkadotjs/index.js +2 -2
  69. package/dist/src/polkadotjs/index.js.map +3 -3
  70. package/dist/src/radix/index.cjs +2 -2
  71. package/dist/src/radix/index.cjs.map +3 -3
  72. package/dist/src/radix/index.js +2 -2
  73. package/dist/src/radix/index.js.map +3 -3
  74. package/dist/src/talisman/index.cjs +2 -2
  75. package/dist/src/talisman/index.cjs.map +3 -3
  76. package/dist/src/talisman/index.js +2 -2
  77. package/dist/src/talisman/index.js.map +3 -3
  78. package/dist/src/trezor.cjs +4 -0
  79. package/dist/src/trezor.cjs.map +10 -0
  80. package/dist/src/trezor.js +4 -0
  81. package/dist/src/trezor.js.map +10 -0
  82. package/dist/src/vultisig/index.cjs +2 -2
  83. package/dist/src/vultisig/index.cjs.map +3 -3
  84. package/dist/src/vultisig/index.js +2 -2
  85. package/dist/src/vultisig/index.js.map +3 -3
  86. package/dist/src/walletconnect/index.cjs +2 -2
  87. package/dist/src/walletconnect/index.cjs.map +3 -3
  88. package/dist/src/walletconnect/index.js +2 -2
  89. package/dist/src/walletconnect/index.js.map +3 -3
  90. package/dist/src/xaman/index.cjs +2 -2
  91. package/dist/src/xaman/index.cjs.map +5 -5
  92. package/dist/src/xaman/index.js +2 -2
  93. package/dist/src/xaman/index.js.map +5 -5
  94. package/dist/types/bitget/helpers.d.ts +330 -0
  95. package/dist/types/bitget/helpers.d.ts.map +1 -0
  96. package/dist/types/bitget/index.d.ts +11 -0
  97. package/dist/types/bitget/index.d.ts.map +1 -0
  98. package/dist/types/coinbase/index.d.ts +11 -0
  99. package/dist/types/coinbase/index.d.ts.map +1 -0
  100. package/dist/types/coinbase/signer.d.ts +91 -0
  101. package/dist/types/coinbase/signer.d.ts.map +1 -0
  102. package/dist/types/cosmostation/index.d.ts +21 -0
  103. package/dist/types/cosmostation/index.d.ts.map +1 -0
  104. package/dist/types/ctrl/index.d.ts +11 -0
  105. package/dist/types/ctrl/index.d.ts.map +1 -0
  106. package/dist/types/ctrl/walletHelpers.d.ts +24 -0
  107. package/dist/types/ctrl/walletHelpers.d.ts.map +1 -0
  108. package/dist/types/evm-extensions/index.d.ts +101 -0
  109. package/dist/types/evm-extensions/index.d.ts.map +1 -0
  110. package/{src/evm-extensions/types.ts → dist/types/evm-extensions/types.d.ts} +11 -13
  111. package/dist/types/evm-extensions/types.d.ts.map +1 -0
  112. package/dist/types/exodus/index.d.ts +14 -0
  113. package/dist/types/exodus/index.d.ts.map +1 -0
  114. package/dist/types/helpers/near.d.ts +57 -0
  115. package/dist/types/helpers/near.d.ts.map +1 -0
  116. package/dist/types/index.d.ts +4 -0
  117. package/dist/types/index.d.ts.map +1 -0
  118. package/dist/types/keepkey-bex/index.d.ts +11 -0
  119. package/dist/types/keepkey-bex/index.d.ts.map +1 -0
  120. package/dist/types/keepkey-bex/walletHelpers.d.ts +45 -0
  121. package/dist/types/keepkey-bex/walletHelpers.d.ts.map +1 -0
  122. package/dist/types/keepkey.d.ts +2 -0
  123. package/dist/types/keepkey.d.ts.map +1 -0
  124. package/dist/types/keplr/chainRegistry.d.ts +4 -0
  125. package/dist/types/keplr/chainRegistry.d.ts.map +1 -0
  126. package/dist/types/keplr/index.d.ts +11 -0
  127. package/dist/types/keplr/index.d.ts.map +1 -0
  128. package/dist/types/keystore.d.ts +2 -0
  129. package/dist/types/keystore.d.ts.map +1 -0
  130. package/dist/types/ledger.d.ts +2 -0
  131. package/dist/types/ledger.d.ts.map +1 -0
  132. package/dist/types/okx/helpers.d.ts +227 -0
  133. package/dist/types/okx/helpers.d.ts.map +1 -0
  134. package/dist/types/okx/index.d.ts +11 -0
  135. package/dist/types/okx/index.d.ts.map +1 -0
  136. package/dist/types/okx/types.d.ts +104 -0
  137. package/dist/types/okx/types.d.ts.map +1 -0
  138. package/dist/types/onekey/evmSigner.d.ts +29 -0
  139. package/dist/types/onekey/evmSigner.d.ts.map +1 -0
  140. package/dist/types/onekey/index.d.ts +11 -0
  141. package/dist/types/onekey/index.d.ts.map +1 -0
  142. package/dist/types/phantom/index.d.ts +12 -0
  143. package/dist/types/phantom/index.d.ts.map +1 -0
  144. package/dist/types/polkadotjs/index.d.ts +11 -0
  145. package/dist/types/polkadotjs/index.d.ts.map +1 -0
  146. package/dist/types/radix/index.d.ts +11 -0
  147. package/dist/types/radix/index.d.ts.map +1 -0
  148. package/dist/types/talisman/index.d.ts +11 -0
  149. package/dist/types/talisman/index.d.ts.map +1 -0
  150. package/dist/types/trezor.d.ts +2 -0
  151. package/dist/types/trezor.d.ts.map +1 -0
  152. package/dist/types/types.d.ts +246 -0
  153. package/dist/types/types.d.ts.map +1 -0
  154. package/dist/types/utils.d.ts +4 -0
  155. package/dist/types/utils.d.ts.map +1 -0
  156. package/dist/types/vultisig/index.d.ts +11 -0
  157. package/dist/types/vultisig/index.d.ts.map +1 -0
  158. package/dist/types/vultisig/walletHelpers.d.ts +34 -0
  159. package/dist/types/vultisig/walletHelpers.d.ts.map +1 -0
  160. package/dist/types/walletconnect/constants.d.ts +85 -0
  161. package/dist/types/walletconnect/constants.d.ts.map +1 -0
  162. package/dist/types/walletconnect/evmSigner.d.ts +25 -0
  163. package/dist/types/walletconnect/evmSigner.d.ts.map +1 -0
  164. package/dist/types/walletconnect/helpers.d.ts +4 -0
  165. package/dist/types/walletconnect/helpers.d.ts.map +1 -0
  166. package/dist/types/walletconnect/index.d.ts +22 -0
  167. package/dist/types/walletconnect/index.d.ts.map +1 -0
  168. package/dist/types/walletconnect/namespaces.d.ts +7 -0
  169. package/dist/types/walletconnect/namespaces.d.ts.map +1 -0
  170. package/dist/types/walletconnect/types.d.ts +7 -0
  171. package/dist/types/walletconnect/types.d.ts.map +1 -0
  172. package/dist/types/xaman/helpers.d.ts +54 -0
  173. package/dist/types/xaman/helpers.d.ts.map +1 -0
  174. package/dist/types/xaman/index.d.ts +14 -0
  175. package/dist/types/xaman/index.d.ts.map +1 -0
  176. package/dist/types/xaman/types.d.ts +24 -0
  177. package/dist/types/xaman/types.d.ts.map +1 -0
  178. package/dist/types/xaman/walletMethods.d.ts +16 -0
  179. package/dist/types/xaman/walletMethods.d.ts.map +1 -0
  180. package/package.json +44 -68
  181. package/dist/chunk-2aa1w78q.js +0 -4
  182. package/dist/chunk-2aa1w78q.js.map +0 -10
  183. package/dist/chunk-31bmhjxx.js +0 -4
  184. package/dist/chunk-31bmhjxx.js.map +0 -10
  185. package/dist/chunk-3etn0w20.js +0 -4
  186. package/dist/chunk-3etn0w20.js.map +0 -10
  187. package/dist/chunk-bk58smyr.js +0 -4
  188. package/dist/chunk-bk58smyr.js.map +0 -10
  189. package/dist/chunk-etm8zfkk.js +0 -4
  190. package/dist/chunk-etm8zfkk.js.map +0 -10
  191. package/dist/chunk-h7myvxxm.js +0 -5
  192. package/dist/chunk-h7myvxxm.js.map +0 -10
  193. package/dist/chunk-htvthkj1.js +0 -5
  194. package/dist/chunk-htvthkj1.js.map +0 -10
  195. package/dist/chunk-nfas79hz.js +0 -4
  196. package/dist/chunk-nfas79hz.js.map +0 -10
  197. package/dist/src/keepkey/index.cjs +0 -4
  198. package/dist/src/keepkey/index.cjs.map +0 -15
  199. package/dist/src/keepkey/index.js +0 -4
  200. package/dist/src/keepkey/index.js.map +0 -15
  201. package/dist/src/keystore/index.cjs +0 -4
  202. package/dist/src/keystore/index.cjs.map +0 -11
  203. package/dist/src/keystore/index.js +0 -4
  204. package/dist/src/keystore/index.js.map +0 -11
  205. package/dist/src/ledger/index.cjs +0 -5
  206. package/dist/src/ledger/index.cjs.map +0 -25
  207. package/dist/src/ledger/index.js +0 -5
  208. package/dist/src/ledger/index.js.map +0 -25
  209. package/dist/src/trezor/index.cjs +0 -4
  210. package/dist/src/trezor/index.cjs.map +0 -10
  211. package/dist/src/trezor/index.js +0 -4
  212. package/dist/src/trezor/index.js.map +0 -10
  213. package/src/bitget/helpers.ts +0 -167
  214. package/src/bitget/index.ts +0 -34
  215. package/src/coinbase/index.ts +0 -52
  216. package/src/coinbase/signer.ts +0 -83
  217. package/src/cosmostation/index.ts +0 -142
  218. package/src/ctrl/index.ts +0 -248
  219. package/src/ctrl/walletHelpers.ts +0 -297
  220. package/src/evm-extensions/index.ts +0 -134
  221. package/src/exodus/index.ts +0 -179
  222. package/src/helpers/near-browser-provider.d.ts +0 -286
  223. package/src/helpers/near.ts +0 -206
  224. package/src/index.ts +0 -2
  225. package/src/keepkey/chains/cosmos.ts +0 -78
  226. package/src/keepkey/chains/evm.ts +0 -125
  227. package/src/keepkey/chains/mayachain.ts +0 -123
  228. package/src/keepkey/chains/ripple.ts +0 -118
  229. package/src/keepkey/chains/thorchain.ts +0 -118
  230. package/src/keepkey/chains/utxo.ts +0 -147
  231. package/src/keepkey/coins.ts +0 -71
  232. package/src/keepkey/index.ts +0 -153
  233. package/src/keepkey-bex/index.ts +0 -162
  234. package/src/keepkey-bex/walletHelpers.ts +0 -255
  235. package/src/keplr/chainRegistry.ts +0 -211
  236. package/src/keplr/index.ts +0 -55
  237. package/src/keystore/helpers.ts +0 -102
  238. package/src/keystore/index.ts +0 -73
  239. package/src/ledger/clients/cosmos.ts +0 -102
  240. package/src/ledger/clients/evm.ts +0 -183
  241. package/src/ledger/clients/near.ts +0 -86
  242. package/src/ledger/clients/thorchain/common.ts +0 -117
  243. package/src/ledger/clients/thorchain/helpers.ts +0 -149
  244. package/src/ledger/clients/thorchain/index.ts +0 -94
  245. package/src/ledger/clients/thorchain/lib.ts +0 -300
  246. package/src/ledger/clients/thorchain/utils.ts +0 -76
  247. package/src/ledger/clients/tron.ts +0 -92
  248. package/src/ledger/clients/utxo.ts +0 -148
  249. package/src/ledger/clients/xrp.ts +0 -66
  250. package/src/ledger/cosmosTypes.ts +0 -101
  251. package/src/ledger/helpers/getLedgerAddress.ts +0 -67
  252. package/src/ledger/helpers/getLedgerClient.ts +0 -124
  253. package/src/ledger/helpers/getLedgerTransport.ts +0 -80
  254. package/src/ledger/helpers/index.ts +0 -3
  255. package/src/ledger/index.ts +0 -311
  256. package/src/ledger/interfaces/CosmosLedgerInterface.ts +0 -65
  257. package/src/ledger/types.ts +0 -45
  258. package/src/okx/helpers.ts +0 -181
  259. package/src/okx/index.ts +0 -43
  260. package/src/okx/types.ts +0 -117
  261. package/src/onekey/evmSigner.ts +0 -133
  262. package/src/onekey/index.ts +0 -213
  263. package/src/phantom/index.ts +0 -126
  264. package/src/polkadotjs/index.ts +0 -67
  265. package/src/radix/index.ts +0 -202
  266. package/src/talisman/index.ts +0 -130
  267. package/src/trezor/evmSigner.ts +0 -197
  268. package/src/trezor/index.ts +0 -260
  269. package/src/types.ts +0 -280
  270. package/src/utils.ts +0 -60
  271. package/src/vultisig/index.ts +0 -199
  272. package/src/vultisig/walletHelpers.ts +0 -359
  273. package/src/walletconnect/constants.ts +0 -104
  274. package/src/walletconnect/evmSigner.ts +0 -147
  275. package/src/walletconnect/helpers.ts +0 -77
  276. package/src/walletconnect/index.ts +0 -460
  277. package/src/walletconnect/namespaces.ts +0 -87
  278. package/src/walletconnect/types.ts +0 -6
  279. package/src/xaman/README.md +0 -66
  280. package/src/xaman/helpers.ts +0 -59
  281. package/src/xaman/index.ts +0 -79
  282. package/src/xaman/types.ts +0 -26
  283. package/src/xaman/walletMethods.ts +0 -126
  284. /package/dist/{chunk-mvbb9fwb.js.map → chunk-sbf0f2p4.js.map} +0 -0
@@ -1,213 +0,0 @@
1
- import {
2
- Chain,
3
- type NetworkParams,
4
- SKConfig,
5
- SwapKitError,
6
- WalletOption,
7
- addEVMWalletNetwork,
8
- createWallet,
9
- filterSupportedChains,
10
- prepareNetworkSwitch,
11
- } from "@swapkit/helpers";
12
- import { Psbt } from "bitcoinjs-lib";
13
- import type {
14
- BitcoinProvider,
15
- GetAddressOptions,
16
- GetAddressResponse,
17
- SignTransactionOptions,
18
- } from "sats-connect";
19
- import { getWalletSupportedChains } from "../utils";
20
-
21
- async function getWalletMethodsForExtension(chain: Chain) {
22
- switch (chain) {
23
- case Chain.Bitcoin: {
24
- if (!window.$onekey?.btc) {
25
- throw new SwapKitError({ errorKey: "wallet_onekey_not_found", info: { chain } });
26
- }
27
-
28
- const { getUtxoToolbox } = await import("@swapkit/toolboxes/utxo");
29
- const {
30
- signTransaction: satsSignTransaction,
31
- getAddress,
32
- AddressPurpose,
33
- BitcoinNetworkType,
34
- } = await import("sats-connect");
35
-
36
- let address = "";
37
-
38
- const getProvider = () => new Promise<BitcoinProvider>((res) => res(window.$onekey?.btc));
39
-
40
- const getAddressOptions: GetAddressOptions = {
41
- getProvider,
42
- payload: {
43
- purposes: [AddressPurpose.Payment],
44
- message: "Address for receiving and sending payments",
45
- network: { type: BitcoinNetworkType.Mainnet },
46
- },
47
- onFinish: (response: GetAddressResponse) => {
48
- if (response.addresses[0]?.address) {
49
- address = response.addresses[0].address;
50
- }
51
- },
52
- onCancel: () => {
53
- throw new SwapKitError("wallet_connection_rejected_by_user");
54
- },
55
- };
56
-
57
- await getAddress(getAddressOptions);
58
-
59
- async function signTransaction(psbt: Psbt) {
60
- let signedPsbt: Psbt | undefined;
61
- const signPsbtOptions: SignTransactionOptions = {
62
- getProvider,
63
- payload: {
64
- message: "Sign transaction",
65
- network: {
66
- type: BitcoinNetworkType.Mainnet,
67
- },
68
- psbtBase64: psbt.toBase64(),
69
- broadcast: false,
70
- inputsToSign: [
71
- {
72
- address,
73
- signingIndexes: psbt.txInputs.map((_: any, index: number) => index),
74
- },
75
- ],
76
- },
77
- onFinish: (response) => {
78
- signedPsbt = Psbt.fromBase64(response.psbtBase64);
79
- },
80
- onCancel: () => {
81
- throw new SwapKitError("wallet_connection_rejected_by_user");
82
- },
83
- };
84
-
85
- await satsSignTransaction(signPsbtOptions);
86
- if (!signedPsbt) throw new SwapKitError("wallet_onekey_sign_transaction_error");
87
- return signedPsbt;
88
- }
89
-
90
- const signer = {
91
- signTransaction,
92
- getAddress: () => Promise.resolve(address),
93
- };
94
-
95
- const toolbox = await getUtxoToolbox(chain, { signer });
96
-
97
- return { ...toolbox, address };
98
- }
99
-
100
- case Chain.Solana: {
101
- if (!window.$onekey?.sol) {
102
- throw new SwapKitError({
103
- errorKey: "wallet_onekey_not_found",
104
- info: { chain },
105
- });
106
- }
107
-
108
- const { getSolanaToolbox } = await import("@swapkit/toolboxes/solana");
109
-
110
- const signer = window.$onekey.sol;
111
- const address = await signer.getAddress();
112
- const toolbox = getSolanaToolbox({ signer });
113
-
114
- return { ...toolbox, address };
115
- }
116
-
117
- case Chain.Arbitrum:
118
- case Chain.Aurora:
119
- case Chain.Avalanche:
120
- case Chain.Base:
121
- case Chain.BinanceSmartChain:
122
- case Chain.Ethereum:
123
- case Chain.Gnosis:
124
- case Chain.Optimism:
125
- case Chain.Polygon: {
126
- const { getProvider, getEvmToolbox } = await import("@swapkit/toolboxes/evm");
127
- if (!window.$onekey?.ethereum) {
128
- throw new SwapKitError({
129
- errorKey: "wallet_onekey_not_found",
130
- info: { chain },
131
- });
132
- }
133
-
134
- const { BrowserProvider } = await import("ethers");
135
- const provider = new BrowserProvider(window.$onekey.ethereum, "any");
136
-
137
- const rpcUrl = SKConfig.get("rpcUrls")[chain];
138
-
139
- await provider.send("eth_requestAccounts", []);
140
- const jsonRpcProvider = await getProvider(chain, rpcUrl);
141
- const signer = await provider.getSigner();
142
- const address = await signer.getAddress();
143
-
144
- const toolbox = await getEvmToolbox(chain, { provider: jsonRpcProvider, signer });
145
- try {
146
- if (chain !== Chain.Ethereum) {
147
- const networkParams = toolbox.getNetworkParams() as NetworkParams;
148
-
149
- await addEVMWalletNetwork(provider, networkParams);
150
- }
151
- } catch (error) {
152
- throw new SwapKitError({
153
- errorKey: "wallet_failed_to_add_or_switch_network",
154
- info: { chain, error },
155
- });
156
- }
157
-
158
- return {
159
- address,
160
- ...prepareNetworkSwitch({ toolbox, chain, provider }),
161
- };
162
- }
163
-
164
- default:
165
- throw new SwapKitError({
166
- errorKey: "wallet_chain_not_supported",
167
- info: { chain, wallet: WalletOption.ONEKEY },
168
- });
169
- }
170
- }
171
-
172
- export const onekeyWallet = createWallet({
173
- name: "connectOnekeyWallet",
174
- walletType: WalletOption.ONEKEY,
175
- supportedChains: [
176
- Chain.Arbitrum,
177
- Chain.Aurora,
178
- Chain.Avalanche,
179
- Chain.Base,
180
- Chain.BinanceSmartChain,
181
- Chain.Bitcoin,
182
- Chain.Ethereum,
183
- Chain.Gnosis,
184
- Chain.Optimism,
185
- Chain.Polygon,
186
- Chain.Solana,
187
- ],
188
- connect: ({ addChain, walletType, supportedChains }) =>
189
- async function connectOnekeyWallet(chains: Chain[]) {
190
- if (!window.$onekey) {
191
- throw new SwapKitError({
192
- errorKey: "wallet_onekey_not_found",
193
- info: { wallet: WalletOption.ONEKEY },
194
- });
195
- }
196
-
197
- const filteredChains = filterSupportedChains({ chains, supportedChains, walletType });
198
-
199
- await Promise.all(
200
- filteredChains.map(async (chain) => {
201
- const walletMethods = await getWalletMethodsForExtension(chain);
202
-
203
- const address = (await walletMethods.getAddress()) || "F";
204
-
205
- addChain({ ...walletMethods, chain, address, walletType });
206
- }),
207
- );
208
-
209
- return true;
210
- },
211
- });
212
-
213
- export const ONEKEY_WALLET_SUPPORTED_CHAINS = getWalletSupportedChains(onekeyWallet);
@@ -1,126 +0,0 @@
1
- import {
2
- type AssetValue,
3
- Chain,
4
- type GenericTransferParams,
5
- SwapKitError,
6
- WalletOption,
7
- createWallet,
8
- filterSupportedChains,
9
- } from "@swapkit/helpers";
10
- import { getWalletSupportedChains } from "../utils";
11
-
12
- export const phantomWallet = createWallet({
13
- name: "connectPhantom",
14
- walletType: WalletOption.PHANTOM,
15
- supportedChains: [Chain.Bitcoin, Chain.Ethereum, Chain.Solana],
16
- connect: ({ addChain, supportedChains, walletType }) =>
17
- async function connectPhantom(chains: Chain[]) {
18
- const filteredChains = filterSupportedChains({ chains, supportedChains, walletType });
19
-
20
- try {
21
- await Promise.all(
22
- filteredChains.map(async (chain) => {
23
- const { address, ...methods } = await getWalletMethods(chain);
24
-
25
- addChain({ ...methods, chain, address, walletType });
26
- }),
27
- );
28
-
29
- return true;
30
- } catch (error) {
31
- if (error instanceof SwapKitError) throw error;
32
-
33
- throw new SwapKitError("wallet_connection_rejected_by_user", error);
34
- }
35
- },
36
- });
37
-
38
- export const PHANTOM_SUPPORTED_CHAINS = getWalletSupportedChains(phantomWallet);
39
- export type PhantomSupportedChain = (typeof PHANTOM_SUPPORTED_CHAINS)[number];
40
-
41
- async function getWalletMethods(chain: PhantomSupportedChain) {
42
- const phantom: any = window?.phantom;
43
-
44
- switch (chain) {
45
- case Chain.Bitcoin: {
46
- const provider = phantom?.bitcoin;
47
- if (!provider?.isPhantom) {
48
- throw new SwapKitError("wallet_phantom_not_found");
49
- }
50
-
51
- const { getUtxoToolbox } = await import("@swapkit/toolboxes/utxo");
52
- const [{ address }] = await provider.requestAccounts();
53
- const toolbox = await getUtxoToolbox(chain);
54
-
55
- return { ...toolbox, address };
56
- }
57
-
58
- case Chain.Ethereum: {
59
- const { getEvmToolbox } = await import("@swapkit/toolboxes/evm");
60
- const { BrowserProvider } = await import("ethers");
61
-
62
- const provider = new BrowserProvider(phantom?.ethereum, "any");
63
- const [address] = await provider.send("eth_requestAccounts", []);
64
-
65
- const signer = await provider.getSigner();
66
- const toolbox = await getEvmToolbox(chain, { signer, provider });
67
-
68
- return { ...toolbox, address };
69
- }
70
-
71
- case Chain.Solana: {
72
- const { getSolanaToolbox } = await import("@swapkit/toolboxes/solana");
73
- const provider = phantom?.solana;
74
- if (!provider?.isPhantom) {
75
- throw new SwapKitError("wallet_phantom_not_found");
76
- }
77
-
78
- const providerConnection = await provider.connect();
79
- const address: string = providerConnection.publicKey.toString();
80
- const toolbox = await getSolanaToolbox();
81
-
82
- const transfer = async ({
83
- recipient,
84
- assetValue,
85
- isProgramDerivedAddress,
86
- }: GenericTransferParams & { assetValue: AssetValue; isProgramDerivedAddress?: boolean }) => {
87
- const { PublicKey } = await import("@solana/web3.js");
88
- const validateAddress = await toolbox.getAddressValidator();
89
-
90
- if (!(isProgramDerivedAddress || validateAddress(recipient))) {
91
- throw new SwapKitError("core_transaction_invalid_recipient_address");
92
- }
93
-
94
- const fromPubkey = new PublicKey(address);
95
- const connection = await toolbox.getConnection();
96
-
97
- const transaction = await toolbox.createTransaction({
98
- recipient,
99
- assetValue,
100
- sender: address,
101
- isProgramDerivedAddress,
102
- });
103
-
104
- if (!transaction) {
105
- throw new SwapKitError("core_transaction_invalid_sender_address");
106
- }
107
-
108
- const blockHash = await connection.getLatestBlockhash();
109
- transaction.recentBlockhash = blockHash.blockhash;
110
- transaction.feePayer = fromPubkey;
111
-
112
- const signedTransaction = await provider.signTransaction(transaction);
113
-
114
- const txid = await connection.sendRawTransaction(signedTransaction.serialize());
115
-
116
- return txid;
117
- };
118
-
119
- return { ...toolbox, transfer, address };
120
- }
121
-
122
- default: {
123
- throw new SwapKitError("wallet_chain_not_supported", { wallet: WalletOption.PHANTOM, chain });
124
- }
125
- }
126
- }
@@ -1,67 +0,0 @@
1
- import {
2
- Chain,
3
- SwapKitError,
4
- WalletOption,
5
- createWallet,
6
- filterSupportedChains,
7
- } from "@swapkit/helpers";
8
- import { getWalletSupportedChains } from "../utils";
9
-
10
- export const polkadotWallet = createWallet({
11
- name: "connectPolkadotJs",
12
- walletType: WalletOption.POLKADOT_JS,
13
- supportedChains: [Chain.Polkadot],
14
- connect: ({ addChain, supportedChains, walletType }) =>
15
- async function connectPolkadotJs(chains: Chain[]) {
16
- const filteredChains = filterSupportedChains({ chains, supportedChains, walletType });
17
-
18
- await Promise.all(
19
- filteredChains.map(async (chain) => {
20
- const { address, ...walletMethods } = await getWalletMethods(chain);
21
-
22
- addChain({ ...walletMethods, chain, address, walletType });
23
- }),
24
- );
25
-
26
- return true;
27
- },
28
- });
29
-
30
- export const POLKADOT_SUPPORTED_CHAINS = getWalletSupportedChains(polkadotWallet);
31
-
32
- async function getWalletMethods(chain: Chain) {
33
- switch (chain) {
34
- case Chain.Polkadot: {
35
- const { getSubstrateToolbox } = await import("@swapkit/toolboxes/substrate");
36
- const injectedExtension = window?.injectedWeb3?.["polkadot-js"];
37
-
38
- const rawExtension = await injectedExtension?.enable?.("polkadot-js");
39
- if (!rawExtension) {
40
- throw new SwapKitError({ errorKey: "wallet_polkadot_not_found", info: { chain } });
41
- }
42
-
43
- const toolbox = await getSubstrateToolbox(chain, { signer: rawExtension.signer });
44
- const [account] = await rawExtension.accounts.get();
45
-
46
- if (!account?.address) {
47
- throw new SwapKitError({
48
- errorKey: "wallet_missing_params",
49
- info: { wallet: WalletOption.POLKADOT_JS, address: account?.address },
50
- });
51
- }
52
-
53
- const address = toolbox.convertAddress(account.address, 0);
54
- return {
55
- ...toolbox,
56
- getAddress: () => address,
57
- address,
58
- };
59
- }
60
-
61
- default:
62
- throw new SwapKitError({
63
- errorKey: "wallet_chain_not_supported",
64
- info: { chain, wallet: WalletOption.POLKADOT_JS },
65
- });
66
- }
67
- }
@@ -1,202 +0,0 @@
1
- import type {
2
- FungibleResourcesCollectionItem,
3
- GatewayApiClient,
4
- StateEntityDetailsVaultResponseItem,
5
- StateEntityFungiblesPageRequest,
6
- StateEntityFungiblesPageResponse,
7
- } from "@radixdlt/babylon-gateway-api-sdk";
8
- import {
9
- AssetValue,
10
- Chain,
11
- SKConfig,
12
- SwapKitError,
13
- WalletOption,
14
- createWallet,
15
- filterSupportedChains,
16
- } from "@swapkit/helpers";
17
- import { getWalletSupportedChains } from "../utils";
18
-
19
- export const radixWallet = createWallet({
20
- name: "connectRadixWallet",
21
- walletType: WalletOption.RADIX_WALLET,
22
- supportedChains: [Chain.Radix],
23
- connect: ({ addChain, supportedChains, walletType }) =>
24
- async function connectRadixWallet(chains: Chain[]) {
25
- const filteredChains = filterSupportedChains({ chains, supportedChains, walletType });
26
- const radixConfig = SKConfig.get("integrations").radix;
27
-
28
- if (!radixConfig) {
29
- throw new SwapKitError("wallet_radix_not_found");
30
- }
31
-
32
- await Promise.all(
33
- filteredChains.map(async (chain) => {
34
- const walletMethods = await getWalletMethods();
35
-
36
- addChain({ ...walletMethods, chain, walletType });
37
- }),
38
- );
39
-
40
- return true;
41
- },
42
- });
43
-
44
- export const RADIX_SUPPORTED_CHAINS = getWalletSupportedChains(radixWallet);
45
-
46
- async function fetchFungibleResources(address: string): Promise<FungibleResourcesCollectionItem[]> {
47
- const { GatewayApiClient } = await import("@radixdlt/babylon-gateway-api-sdk");
48
- const { applicationName } = SKConfig.get("integrations").radix;
49
- const networkApi = GatewayApiClient.initialize({ networkId: 1, applicationName });
50
-
51
- let hasNextPage = true;
52
- let nextCursor: string | undefined;
53
- let fungibleResources: FungibleResourcesCollectionItem[] = [];
54
-
55
- const stateVersion = await currentStateVersion(networkApi);
56
-
57
- while (hasNextPage) {
58
- const stateEntityFungiblesPageRequest: StateEntityFungiblesPageRequest = {
59
- address: address,
60
- limit_per_page: 100,
61
- cursor: nextCursor,
62
- at_ledger_state: { state_version: stateVersion },
63
- };
64
-
65
- const stateEntityFungiblesPageResponse: StateEntityFungiblesPageResponse =
66
- await networkApi.state.innerClient.entityFungiblesPage({
67
- stateEntityFungiblesPageRequest: stateEntityFungiblesPageRequest,
68
- });
69
-
70
- fungibleResources = fungibleResources.concat(stateEntityFungiblesPageResponse.items);
71
-
72
- if (stateEntityFungiblesPageResponse.next_cursor) {
73
- nextCursor = stateEntityFungiblesPageResponse.next_cursor;
74
- } else {
75
- hasNextPage = false;
76
- }
77
- }
78
- return fungibleResources;
79
- }
80
-
81
- async function currentStateVersion(networkApi: GatewayApiClient) {
82
- return networkApi.status.getCurrent().then((status) => status.ledger_state.state_version);
83
- }
84
-
85
- // TODO - @Towan: is that still needed with SwapKitApi.getChainBalance()?
86
- // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: TODO: Split into multiple functions
87
- async function getBalance(address: string): Promise<AssetValue[]> {
88
- const { GatewayApiClient } = await import("@radixdlt/babylon-gateway-api-sdk");
89
- const resources = await fetchFungibleResources(address);
90
- const { applicationName } = SKConfig.get("integrations").radix;
91
- const networkApi = GatewayApiClient.initialize({ networkId: 1, applicationName });
92
-
93
- const balances: AssetValue[] = [];
94
- const BATCH_SIZE = 50;
95
-
96
- // Split resources into batches of up to 50 items
97
- const resourceBatches: FungibleResourcesCollectionItem[][] = [];
98
- for (let i = 0; i < resources.length; i += BATCH_SIZE) {
99
- resourceBatches.push(resources.slice(i, i + BATCH_SIZE));
100
- }
101
-
102
- for (const batch of resourceBatches) {
103
- const addresses = batch.map((item) => item.resource_address);
104
- const response: StateEntityDetailsVaultResponseItem[] =
105
- await networkApi.state.getEntityDetailsVaultAggregated(addresses);
106
-
107
- const divisibilities = new Map<string, { decimals: number; symbol: string }>();
108
-
109
- for (const result of response) {
110
- if (result.details !== undefined) {
111
- const metaDataSymbol = result.metadata?.items.find((item) => item.key === "symbol");
112
- const symbol =
113
- metaDataSymbol?.value.typed.type === "String" ? metaDataSymbol.value.typed.value : "?";
114
-
115
- if (result.details.type === "FungibleResource") {
116
- divisibilities.set(result.address, { decimals: result.details.divisibility, symbol });
117
- }
118
- }
119
- }
120
-
121
- for (const item of batch) {
122
- if (item.aggregation_level === "Global") {
123
- const assetInfo = divisibilities.get(item.resource_address) || { decimals: 0, symbol: "?" };
124
-
125
- const balance = AssetValue.from({
126
- asset:
127
- assetInfo.symbol !== Chain.Radix
128
- ? `${Chain.Radix}.${assetInfo.symbol}-${item.resource_address}`
129
- : "XRD.XRD",
130
- value: item.amount,
131
- });
132
- balances.push(balance);
133
- }
134
- }
135
- }
136
-
137
- return balances;
138
- }
139
-
140
- async function getWalletMethods() {
141
- const { RadixDappToolkit } = await import("@radixdlt/radix-dapp-toolkit");
142
- const dappConfig = SKConfig.get("integrations").radix;
143
- const rdt = RadixDappToolkit({ ...dappConfig, networkId: dappConfig.network.networkId });
144
-
145
- function delay(ms: number) {
146
- return new Promise((resolve) => setTimeout(resolve, ms));
147
- }
148
-
149
- // TODO: @Towan - Wat is dat?
150
- await delay(400);
151
-
152
- function getAddress() {
153
- const existingWalletData = rdt.walletApi.getWalletData();
154
- const account = existingWalletData?.accounts?.[0];
155
-
156
- return account?.address;
157
- }
158
-
159
- const getNewAddress = async () => {
160
- const { DataRequestBuilder } = await import("@radixdlt/radix-dapp-toolkit");
161
- rdt.walletApi.setRequestData(DataRequestBuilder.accounts().exactly(1));
162
- const res = await rdt.walletApi.sendRequest();
163
-
164
- if (!res) {
165
- throw new SwapKitError("wallet_radix_no_account");
166
- }
167
-
168
- const newAddress = res.unwrapOr(null)?.accounts[0]?.address;
169
-
170
- if (!newAddress) {
171
- throw new SwapKitError("wallet_radix_no_account");
172
- }
173
-
174
- return newAddress;
175
- };
176
-
177
- const address = getAddress() || (await getNewAddress());
178
-
179
- return {
180
- radixDappToolkit: rdt,
181
- address,
182
- getAddress,
183
- getBalance: () => getBalance(address),
184
- transfer: (_params: { assetValue: AssetValue; recipient: string; from: string }) => {
185
- throw new SwapKitError("wallet_radix_method_not_supported", { method: "transfer" });
186
- },
187
- signAndBroadcast: async ({ manifest, message }: { manifest: string; message: string }) => {
188
- const tx = await rdt.walletApi.sendTransaction({
189
- transactionManifest: manifest,
190
- message,
191
- });
192
-
193
- const txResult = tx.unwrapOr(null)?.transactionIntentHash;
194
-
195
- if (!txResult) {
196
- throw new SwapKitError("wallet_radix_transaction_failed");
197
- }
198
-
199
- return txResult;
200
- },
201
- };
202
- }