@swapkit/wallets 4.0.0-beta.54 → 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,130 +0,0 @@
1
- import {
2
- Chain,
3
- type EVMChain,
4
- SwapKitError,
5
- WalletOption,
6
- createWallet,
7
- filterSupportedChains,
8
- prepareNetworkSwitch,
9
- switchEVMWalletNetwork,
10
- } from "@swapkit/helpers";
11
- import type { Eip1193Provider } from "ethers";
12
- import { getWalletSupportedChains } from "../utils";
13
-
14
- export const talismanWallet = createWallet({
15
- name: "connectTalisman",
16
- walletType: WalletOption.TALISMAN,
17
- supportedChains: [
18
- Chain.Ethereum,
19
- Chain.Arbitrum,
20
- Chain.Avalanche,
21
- Chain.Base,
22
- Chain.Polygon,
23
- Chain.BinanceSmartChain,
24
- Chain.Optimism,
25
- Chain.Polkadot,
26
- Chain.Chainflip,
27
- ],
28
- connect: ({ addChain, supportedChains, walletType }) =>
29
- async function connectTalisman(chains: Chain[]) {
30
- const filteredChains = filterSupportedChains({ chains, supportedChains, walletType });
31
-
32
- await Promise.all(
33
- filteredChains.map(async (chain) => {
34
- const walletMethods = await getWalletMethods(chain);
35
-
36
- addChain({ ...walletMethods, chain, walletType });
37
- }),
38
- );
39
-
40
- return true;
41
- },
42
- });
43
-
44
- export const TALISMAN_SUPPORTED_CHAINS = getWalletSupportedChains(talismanWallet);
45
-
46
- async function getWeb3WalletMethods({
47
- walletProvider,
48
- chain,
49
- }: { walletProvider: Eip1193Provider | undefined; chain: EVMChain }) {
50
- const { getEvmToolbox } = await import("@swapkit/toolboxes/evm");
51
- const { BrowserProvider } = await import("ethers");
52
-
53
- if (!walletProvider) {
54
- throw new SwapKitError({
55
- errorKey: "wallet_provider_not_found",
56
- info: { wallet: WalletOption.TALISMAN, chain },
57
- });
58
- }
59
-
60
- const provider = new BrowserProvider(walletProvider, "any");
61
- const signer = await provider.getSigner();
62
- const toolbox = await getEvmToolbox(chain, { provider, signer });
63
-
64
- try {
65
- if (chain !== Chain.Ethereum) {
66
- await switchEVMWalletNetwork(provider, chain, toolbox.getNetworkParams());
67
- }
68
- } catch (_error) {
69
- throw new SwapKitError({
70
- errorKey: "wallet_failed_to_add_or_switch_network",
71
- info: { wallet: WalletOption.TALISMAN, chain },
72
- });
73
- }
74
-
75
- return prepareNetworkSwitch({ toolbox, chain, provider });
76
- }
77
-
78
- async function getWalletMethods(chain: Chain) {
79
- switch (chain) {
80
- case Chain.Ethereum:
81
- case Chain.Arbitrum:
82
- case Chain.Optimism:
83
- case Chain.Polygon:
84
- case Chain.Avalanche:
85
- case Chain.BinanceSmartChain:
86
- case Chain.Base: {
87
- if (!(window.talismanEth && "send" in window.talismanEth)) {
88
- throw new SwapKitError({ errorKey: "wallet_talisman_not_found", info: { chain } });
89
- }
90
-
91
- const evmWallet = await getWeb3WalletMethods({ chain, walletProvider: window.talismanEth });
92
- const address: string = (await window.talismanEth.send("eth_requestAccounts", []))[0];
93
-
94
- return { ...evmWallet, address };
95
- }
96
-
97
- case Chain.Polkadot:
98
- case Chain.Chainflip: {
99
- const { getSubstrateToolbox, SubstrateNetwork } = await import(
100
- "@swapkit/toolboxes/substrate"
101
- );
102
-
103
- const injectedExtension = window?.injectedWeb3?.talisman;
104
- const rawExtension = await injectedExtension?.enable?.("talisman");
105
-
106
- if (!rawExtension) {
107
- throw new SwapKitError({ errorKey: "wallet_talisman_not_enabled", info: { chain } });
108
- }
109
-
110
- const toolbox = await getSubstrateToolbox(chain, { signer: rawExtension.signer });
111
- const accounts = await rawExtension.accounts.get();
112
-
113
- if (!accounts[0]?.address) {
114
- throw new SwapKitError({
115
- errorKey: "wallet_missing_params",
116
- info: { wallet: WalletOption.TALISMAN, accounts, address: accounts[0]?.address },
117
- });
118
- }
119
- const address = toolbox.convertAddress(accounts[0].address, SubstrateNetwork[chain].prefix);
120
-
121
- return { ...toolbox, address };
122
- }
123
-
124
- default:
125
- throw new SwapKitError({
126
- errorKey: "wallet_chain_not_supported",
127
- info: { chain, wallet: WalletOption.TALISMAN },
128
- });
129
- }
130
- }
@@ -1,197 +0,0 @@
1
- import {
2
- type Chain,
3
- ChainToChainId,
4
- type DerivationPathArray,
5
- SwapKitError,
6
- SwapKitNumber,
7
- WalletOption,
8
- derivationPathToString,
9
- } from "@swapkit/helpers";
10
- import type { JsonRpcProvider, Provider, TransactionRequest } from "ethers";
11
-
12
- type TrezorEVMSignerParams = {
13
- chain: Chain;
14
- derivationPath: DerivationPathArray;
15
- provider: Provider | JsonRpcProvider;
16
- };
17
-
18
- export async function getEVMSigner({ chain, derivationPath, provider }: TrezorEVMSignerParams) {
19
- const { AbstractSigner, Signature } = await import("ethers");
20
-
21
- class TrezorSigner extends AbstractSigner {
22
- address: string;
23
- chain: Chain;
24
- derivationPath: DerivationPathArray;
25
- readonly provider: Provider | JsonRpcProvider;
26
-
27
- constructor({ chain, derivationPath, provider }: TrezorEVMSignerParams) {
28
- super(provider);
29
-
30
- this.address = "";
31
- this.chain = chain;
32
- this.derivationPath = derivationPath;
33
- this.provider = provider;
34
- }
35
-
36
- getAddress = async () => {
37
- if (!this.address) {
38
- const TrezorConnect = (await import("@trezor/connect-web")).default;
39
-
40
- const result = await TrezorConnect.ethereumGetAddress({
41
- path: derivationPathToString(this.derivationPath),
42
- showOnTrezor: true,
43
- });
44
-
45
- if (!result.success) {
46
- throw new SwapKitError({
47
- errorKey: "wallet_trezor_failed_to_get_address",
48
- info: { ...result, chain: this.chain, derivationPath: this.derivationPath },
49
- });
50
- }
51
-
52
- this.address = result.payload.address;
53
- }
54
-
55
- return this.address;
56
- };
57
-
58
- signMessage = async (message: string) => {
59
- const TrezorConnect = (await import("@trezor/connect-web")).default;
60
-
61
- const result = await TrezorConnect.ethereumSignMessage({
62
- path: derivationPathToString(this.derivationPath),
63
- message,
64
- });
65
-
66
- if (!result.success) {
67
- throw new SwapKitError({
68
- errorKey: "wallet_trezor_failed_to_sign_transaction",
69
- info: { ...result, message, chain: this.chain, derivationPath: this.derivationPath },
70
- });
71
- }
72
-
73
- return result.payload.signature;
74
- };
75
-
76
- signTypedData(): Promise<string> {
77
- throw new SwapKitError("wallet_trezor_method_not_supported", { method: "signTypedData" });
78
- }
79
-
80
- signTransaction = async ({
81
- to,
82
- gasLimit,
83
- value,
84
- data,
85
- nonce,
86
- maxFeePerGas,
87
- maxPriorityFeePerGas,
88
- gasPrice,
89
- // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: any: refactor
90
- }: TransactionRequest) => {
91
- if (!to) throw new SwapKitError({ errorKey: "wallet_missing_params", info: { to } });
92
- if (!gasLimit)
93
- throw new SwapKitError({ errorKey: "wallet_missing_params", info: { gasLimit } });
94
-
95
- const isEIP1559 = maxFeePerGas && maxPriorityFeePerGas;
96
-
97
- if (isEIP1559 && !maxFeePerGas) {
98
- throw new SwapKitError({ errorKey: "wallet_missing_params", info: { maxFeePerGas } });
99
- }
100
- if (isEIP1559 && !maxPriorityFeePerGas) {
101
- throw new SwapKitError({
102
- errorKey: "wallet_missing_params",
103
- info: { maxPriorityFeePerGas },
104
- });
105
- }
106
- if (!(isEIP1559 || gasPrice)) {
107
- throw new SwapKitError({ errorKey: "wallet_missing_params", info: { gasPrice } });
108
- }
109
-
110
- const TrezorConnect = (await import("@trezor/connect-web")).default;
111
- const { toHexString } = await import("@swapkit/toolboxes/evm");
112
- const { Transaction } = await import("ethers");
113
-
114
- const additionalFields = isEIP1559
115
- ? {
116
- maxFeePerGas: toHexString(BigInt(maxFeePerGas?.toString() || 0)),
117
- maxPriorityFeePerGas: toHexString(BigInt(maxPriorityFeePerGas?.toString() || 0)),
118
- }
119
- : (gasPrice && { gasPrice: toHexString(BigInt(gasPrice?.toString() || 0)) }) || {
120
- gasPrice: "0x0",
121
- };
122
-
123
- const hexifiedNonce = toHexString(
124
- BigInt(
125
- nonce || (await this.provider.getTransactionCount(await this.getAddress(), "pending")),
126
- ),
127
- );
128
-
129
- const formattedTx = {
130
- chainId: Number.parseInt(ChainToChainId[this.chain]),
131
- to: to.toString(),
132
- value: toHexString(BigInt(value?.toString() || 0)),
133
- gasLimit: toHexString(BigInt(gasLimit?.toString() || 0)),
134
- nonce: hexifiedNonce,
135
- data: data?.toString() || "0x",
136
- ...additionalFields,
137
- };
138
-
139
- const { success, payload } = await TrezorConnect.ethereumSignTransaction({
140
- path: derivationPathToString(this.derivationPath),
141
- transaction: formattedTx,
142
- });
143
-
144
- if (!success) {
145
- throw new SwapKitError({
146
- errorKey: "wallet_trezor_failed_to_sign_transaction",
147
- info: { ...payload, chain: this.chain, derivationPath: this.derivationPath },
148
- });
149
- }
150
-
151
- const { r, s, v } = payload;
152
-
153
- const signature = Signature.from({
154
- r,
155
- s,
156
- v: new SwapKitNumber(BigInt(v)).getBaseValue("number"),
157
- });
158
-
159
- const serializedTx = Transaction.from({
160
- ...formattedTx,
161
- nonce: Number.parseInt(formattedTx.nonce, 16),
162
- type: isEIP1559 ? 2 : 0,
163
- signature,
164
- }).serialized;
165
-
166
- if (!serializedTx) {
167
- throw new SwapKitError({
168
- errorKey: "wallet_trezor_failed_to_sign_transaction",
169
- info: { chain: this.chain, derivationPath: this.derivationPath },
170
- });
171
- }
172
-
173
- return serializedTx;
174
- };
175
-
176
- connect = (provider: Provider | null) => {
177
- if (!provider) {
178
- throw new SwapKitError({
179
- errorKey: "wallet_provider_not_found",
180
- info: {
181
- wallet: WalletOption.TREZOR,
182
- chain: this.chain,
183
- derivationPath: this.derivationPath,
184
- },
185
- });
186
- }
187
-
188
- return new TrezorSigner({
189
- chain: this.chain,
190
- derivationPath: this.derivationPath,
191
- provider,
192
- });
193
- };
194
- }
195
-
196
- return new TrezorSigner({ chain, derivationPath, provider });
197
- }
@@ -1,260 +0,0 @@
1
- import {
2
- Chain,
3
- type DerivationPathArray,
4
- FeeOption,
5
- type GenericTransferParams,
6
- SKConfig,
7
- SwapKitError,
8
- WalletOption,
9
- createWallet,
10
- derivationPathToString,
11
- filterSupportedChains,
12
- } from "@swapkit/helpers";
13
- import type { UTXOToolboxes, UTXOType } from "@swapkit/toolboxes/utxo";
14
- import type { Psbt } from "bitcoinjs-lib";
15
- import { getWalletSupportedChains } from "../utils";
16
-
17
- function getScriptType(derivationPath: DerivationPathArray) {
18
- switch (derivationPath[0]) {
19
- case 84:
20
- return { input: "SPENDWITNESS", output: "PAYTOWITNESS" } as const;
21
- case 49:
22
- return { input: "SPENDP2SHWITNESS", output: "PAYTOP2SHWITNESS" } as const;
23
- case 44:
24
- return { input: "SPENDADDRESS", output: "PAYTOADDRESS" } as const;
25
- default:
26
- return null;
27
- }
28
- }
29
-
30
- async function getTrezorWallet<T extends Chain>({
31
- chain,
32
- derivationPath,
33
- }: { chain: T; derivationPath: DerivationPathArray }) {
34
- switch (chain) {
35
- case Chain.Arbitrum:
36
- case Chain.Aurora:
37
- case Chain.Avalanche:
38
- case Chain.Base:
39
- case Chain.BinanceSmartChain:
40
- case Chain.Ethereum:
41
- case Chain.Gnosis:
42
- case Chain.Optimism:
43
- case Chain.Polygon: {
44
- const { getProvider, getEvmToolbox } = await import("@swapkit/toolboxes/evm");
45
- const { getEVMSigner } = await import("./evmSigner");
46
-
47
- const provider = await getProvider(chain);
48
- const signer = await getEVMSigner({ chain, derivationPath, provider });
49
- const address = await signer.getAddress();
50
- const toolbox = await getEvmToolbox(chain, { provider, signer });
51
-
52
- return { ...toolbox, address };
53
- }
54
-
55
- case Chain.Bitcoin:
56
- case Chain.BitcoinCash:
57
- case Chain.Dash:
58
- case Chain.Dogecoin:
59
- case Chain.Litecoin: {
60
- const { toCashAddress, getUtxoToolbox } = await import("@swapkit/toolboxes/utxo");
61
- const scriptType = getScriptType(derivationPath);
62
-
63
- if (!scriptType) {
64
- throw new SwapKitError({
65
- errorKey: "wallet_trezor_derivation_path_not_supported",
66
- info: { derivationPath },
67
- });
68
- }
69
-
70
- const coin = chain.toLowerCase();
71
-
72
- const getAddress = async (path: DerivationPathArray = derivationPath) => {
73
- const TrezorConnect = (await import("@trezor/connect-web")).default;
74
- const { success, payload } = await TrezorConnect.getAddress({
75
- path: derivationPathToString(path),
76
- coin,
77
- });
78
-
79
- if (!success) {
80
- throw new SwapKitError({
81
- errorKey: "wallet_trezor_failed_to_get_address",
82
- info: {
83
- chain,
84
- error: (payload as { error: string; code?: string }).error || "Unknown error",
85
- },
86
- });
87
- }
88
-
89
- if (chain === Chain.BitcoinCash) {
90
- const toolbox = await getUtxoToolbox(chain as Chain.BitcoinCash);
91
- return toolbox.stripPrefix(payload.address);
92
- }
93
-
94
- return payload.address;
95
- };
96
-
97
- const address = await getAddress();
98
-
99
- const signTransaction = async (psbt: Psbt, inputs: UTXOType[], memo = "") => {
100
- const TrezorConnect = (await import("@trezor/connect-web")).default;
101
- const address_n = derivationPath.map((pathElement, index) =>
102
- index < 3 ? ((pathElement as number) | 0x80000000) >>> 0 : (pathElement as number),
103
- );
104
- const toolbox = await getUtxoToolbox(chain as Chain.BitcoinCash);
105
-
106
- const result = await TrezorConnect.signTransaction({
107
- coin,
108
- inputs: inputs.map(({ hash, index, value }) => ({
109
- // Hardens the first 3 elements of the derivation path - required by trezor
110
- address_n,
111
- prev_hash: hash,
112
- prev_index: index,
113
- // object needs amount but does not use it for signing
114
- amount: value,
115
- script_type: scriptType.input,
116
- })),
117
- outputs: psbt.txOutputs.map((output) => {
118
- // OP_RETURN
119
- if (!output.address) {
120
- return {
121
- amount: "0",
122
- op_return_data: Buffer.from(memo).toString("hex"),
123
- script_type: "PAYTOOPRETURN",
124
- };
125
- }
126
-
127
- const outputAddress =
128
- chain === Chain.BitcoinCash
129
- ? toolbox.stripPrefix(toCashAddress(output.address))
130
- : output.address;
131
-
132
- const isChangeAddress = outputAddress === address;
133
-
134
- return isChangeAddress
135
- ? { amount: output.value, address_n, script_type: scriptType.output }
136
- : { amount: output.value, address: outputAddress, script_type: "PAYTOADDRESS" };
137
- }),
138
- });
139
-
140
- if (result.success) {
141
- return result.payload.serializedTx;
142
- }
143
-
144
- throw new SwapKitError({
145
- errorKey: "wallet_trezor_failed_to_sign_transaction",
146
- info: {
147
- chain,
148
- error: (result.payload as { error: string; code?: string }).error,
149
- },
150
- });
151
- };
152
-
153
- const transfer = async ({
154
- recipient,
155
- feeOptionKey,
156
- feeRate: paramFeeRate,
157
- memo,
158
- ...rest
159
- }: GenericTransferParams) => {
160
- if (!(address && recipient)) {
161
- throw new SwapKitError({
162
- errorKey: "wallet_missing_params",
163
- info: { wallet: WalletOption.TREZOR, memo, address, recipient },
164
- });
165
- }
166
-
167
- const toolbox = await getUtxoToolbox(chain);
168
-
169
- const feeRate =
170
- paramFeeRate || (await toolbox.getFeeRates())[feeOptionKey || FeeOption.Fast];
171
-
172
- const createTxMethod =
173
- chain === Chain.BitcoinCash
174
- ? (toolbox as UTXOToolboxes["BCH"]).buildTx
175
- : (toolbox as UTXOToolboxes["BTC"]).createTransaction;
176
-
177
- const { psbt, inputs } = await createTxMethod({
178
- ...rest,
179
- memo,
180
- recipient,
181
- feeRate,
182
- sender: address,
183
- fetchTxHex: true,
184
- });
185
-
186
- const txHex = await signTransaction(psbt, inputs, memo);
187
- const tx = await toolbox.broadcastTx(txHex);
188
-
189
- return tx;
190
- };
191
-
192
- const toolbox = await getUtxoToolbox(chain);
193
-
194
- return { ...toolbox, address, transfer, signTransaction };
195
- }
196
-
197
- default:
198
- throw new SwapKitError({
199
- errorKey: "wallet_chain_not_supported",
200
- info: { chain, wallet: WalletOption.TREZOR },
201
- });
202
- }
203
- }
204
-
205
- export const trezorWallet = createWallet({
206
- name: "connectTrezor",
207
- walletType: WalletOption.TREZOR,
208
- supportedChains: [
209
- Chain.Arbitrum,
210
- Chain.Aurora,
211
- Chain.Avalanche,
212
- Chain.Base,
213
- Chain.BinanceSmartChain,
214
- Chain.Bitcoin,
215
- Chain.BitcoinCash,
216
- Chain.Dash,
217
- Chain.Dogecoin,
218
- Chain.Ethereum,
219
- Chain.Gnosis,
220
- Chain.Litecoin,
221
- Chain.Optimism,
222
- Chain.Polygon,
223
- ],
224
- connect: ({ addChain, supportedChains, walletType }) =>
225
- async function connectTrezor(chains: Chain[], derivationPath: DerivationPathArray) {
226
- const [chain] = filterSupportedChains({ chains, supportedChains, walletType });
227
- if (!chain) {
228
- throw new SwapKitError({
229
- errorKey: "wallet_chain_not_supported",
230
- info: { chain, wallet: WalletOption.TREZOR },
231
- });
232
- }
233
-
234
- const TrezorConnect = (await import("@trezor/connect-web")).default;
235
- const { success } = await TrezorConnect.getDeviceState();
236
-
237
- if (!success) {
238
- const trezorConfig = SKConfig.get("integrations").trezor;
239
- const manifest = trezorConfig
240
- ? {
241
- ...trezorConfig,
242
- appName: (trezorConfig as any).appName || "SwapKit",
243
- }
244
- : {
245
- appUrl: "",
246
- email: "",
247
- appName: "SwapKit",
248
- };
249
- TrezorConnect.init({ lazyLoad: true, manifest });
250
- }
251
-
252
- const wallet = await getTrezorWallet({ chain, derivationPath });
253
-
254
- addChain({ ...wallet, chain, walletType });
255
-
256
- return true;
257
- },
258
- });
259
-
260
- export const TREZOR_SUPPORTED_CHAINS = getWalletSupportedChains(trezorWallet);