@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,101 +0,0 @@
1
- import { SwapKitError } from "@swapkit/helpers";
2
-
3
- export interface Coin {
4
- readonly denom: string;
5
- readonly amount: string;
6
- }
7
-
8
- export interface EncodeObject {
9
- readonly typeUrl: string;
10
- readonly value: any;
11
- }
12
-
13
- export interface AminoMsg {
14
- readonly type: string;
15
- readonly value: any;
16
- }
17
-
18
- export interface AminoMsgSend extends AminoMsg {
19
- readonly type: "cosmos-sdk/MsgSend";
20
- readonly value: {
21
- /** Bech32 account address */
22
- readonly from_address: string;
23
- /** Bech32 account address */
24
- readonly to_address: string;
25
- readonly amount: readonly Coin[];
26
- };
27
- }
28
-
29
- export interface AminoConverter {
30
- readonly aminoType: string;
31
- readonly toAmino: (value: any) => any;
32
- readonly fromAmino: (value: any) => any;
33
- }
34
-
35
- /** A map from protobuf type URL to the AminoConverter implementation if supported on chain */
36
- export type AminoConverters = Record<string, AminoConverter | "not_supported_by_chain">;
37
-
38
- function isAminoConverter(
39
- converter: [string, AminoConverter | "not_supported_by_chain"],
40
- ): converter is [string, AminoConverter] {
41
- return typeof converter[1] !== "string";
42
- }
43
-
44
- /**
45
- * A map from Stargate message types as used in the messages's `Any` type
46
- * to Amino types.
47
- */
48
- export class AminoTypes {
49
- // The map type here ensures uniqueness of the protobuf type URL in the key.
50
- // There is no uniqueness guarantee of the Amino type identifier in the type
51
- // system or constructor. Instead it's the user's responsibility to ensure
52
- // there is no overlap when fromAmino is called.
53
- private readonly register: Record<string, AminoConverter | "not_supported_by_chain">;
54
-
55
- constructor(types: AminoConverters) {
56
- this.register = types;
57
- }
58
-
59
- toAmino({ typeUrl, value }: EncodeObject): AminoMsg {
60
- const converter = this.register[typeUrl];
61
- if (converter === "not_supported_by_chain") {
62
- throw new SwapKitError("wallet_ledger_chain_not_supported", {
63
- reason: `The message type '${typeUrl}' cannot be signed using the Amino JSON sign mode because this is not supported by chain.`,
64
- });
65
- }
66
- if (!converter) {
67
- throw new SwapKitError("wallet_ledger_invalid_params", {
68
- reason: `Type URL '${typeUrl}' does not exist in the Amino message type register.`,
69
- });
70
- }
71
- return {
72
- type: converter.aminoType,
73
- value: converter.toAmino(value),
74
- };
75
- }
76
-
77
- fromAmino({ type, value }: AminoMsg): EncodeObject {
78
- const matches = Object.entries(this.register)
79
- .filter(isAminoConverter)
80
- .filter(([_typeUrl, { aminoType }]) => aminoType === type);
81
-
82
- if (matches.length === 0) {
83
- throw new SwapKitError("wallet_ledger_invalid_params", {
84
- reason: `Amino type identifier '${type}' does not exist in the Amino message type register.`,
85
- });
86
- }
87
-
88
- if (matches.length > 1) {
89
- throw new SwapKitError("wallet_ledger_invalid_params", {
90
- reason: `Multiple types are registered with Amino type identifier '${type}': '${matches
91
- .map(([key, _value]) => key)
92
- .sort()
93
- .join("', '")}'. Thus fromAmino cannot be performed.`,
94
- });
95
- }
96
-
97
- const [typeUrl, converter] = matches[0] as [string, AminoConverter];
98
-
99
- return { typeUrl, value: converter.fromAmino(value) };
100
- }
101
- }
@@ -1,67 +0,0 @@
1
- import { Chain, SwapKitError, WalletOption } from "@swapkit/helpers";
2
-
3
- import type { getNearLedgerClient } from "../clients/near";
4
- import type { TronLedger } from "../clients/tron";
5
- import type { XRPLedger } from "../clients/xrp";
6
- import type { LEDGER_SUPPORTED_CHAINS } from "../index";
7
- import type { CosmosLedgerClients, EVMLedgerClients, UTXOLedgerClients } from "../types";
8
- import type { getLedgerClient } from "./getLedgerClient";
9
-
10
- export const getLedgerAddress = async <
11
- T extends (typeof LEDGER_SUPPORTED_CHAINS)[number],
12
- L extends Awaited<ReturnType<typeof getLedgerClient<T>>>,
13
- >({
14
- chain,
15
- ledgerClient,
16
- }: {
17
- chain: T;
18
- ledgerClient: L;
19
- }) => {
20
- if (!ledgerClient) return "";
21
-
22
- switch (chain) {
23
- case Chain.Cosmos:
24
- case Chain.THORChain: {
25
- return (ledgerClient as CosmosLedgerClients).connect();
26
- }
27
-
28
- case Chain.Ethereum:
29
- case Chain.BinanceSmartChain:
30
- case Chain.Avalanche:
31
- case Chain.Polygon:
32
- case Chain.Arbitrum:
33
- case Chain.Optimism:
34
- case Chain.Base:
35
- case Chain.Aurora:
36
- case Chain.Gnosis: {
37
- return (ledgerClient as EVMLedgerClients).getAddress();
38
- }
39
-
40
- case Chain.Bitcoin:
41
- case Chain.BitcoinCash:
42
- case Chain.Dash:
43
- case Chain.Dogecoin:
44
- case Chain.Litecoin: {
45
- const ledger = ledgerClient as UTXOLedgerClients;
46
- await ledger.connect();
47
- const address = await ledger.getAddress();
48
-
49
- return chain === Chain.BitcoinCash ? address.replace("bitcoincash:", "") : address;
50
- }
51
-
52
- case Chain.Near: {
53
- return await (ledgerClient as Awaited<ReturnType<typeof getNearLedgerClient>>).getAddress();
54
- }
55
-
56
- case Chain.Ripple: {
57
- return (ledgerClient as Awaited<ReturnType<typeof XRPLedger>>).address;
58
- }
59
-
60
- case Chain.Tron: {
61
- return (ledgerClient as Awaited<ReturnType<typeof TronLedger>>).getAddress();
62
- }
63
-
64
- default:
65
- throw new SwapKitError("wallet_chain_not_supported", { wallet: WalletOption.LEDGER, chain });
66
- }
67
- };
@@ -1,124 +0,0 @@
1
- import {
2
- Chain,
3
- type DerivationPathArray,
4
- type EVMChain,
5
- SwapKitError,
6
- WalletOption,
7
- } from "@swapkit/helpers";
8
-
9
- import { CosmosLedger } from "../clients/cosmos";
10
- import {
11
- ArbitrumLedger,
12
- AuroraLedger,
13
- AvalancheLedger,
14
- BaseLedger,
15
- BinanceSmartChainLedger,
16
- EthereumLedger,
17
- GnosisLedger,
18
- OptimismLedger,
19
- PolygonLedger,
20
- } from "../clients/evm";
21
- import { getNearLedgerClient } from "../clients/near";
22
- import { THORChainLedger } from "../clients/thorchain";
23
- import { TronLedger } from "../clients/tron";
24
- import {
25
- BitcoinCashLedger,
26
- BitcoinLedger,
27
- DashLedger,
28
- DogecoinLedger,
29
- LitecoinLedger,
30
- } from "../clients/utxo";
31
- import { XRPLedger } from "../clients/xrp";
32
- import { getLedgerTransport } from "./getLedgerTransport";
33
-
34
- type LedgerSignerMap = {
35
- [Chain.Arbitrum]: ReturnType<typeof ArbitrumLedger>;
36
- [Chain.Aurora]: ReturnType<typeof AuroraLedger>;
37
- [Chain.Avalanche]: ReturnType<typeof AvalancheLedger>;
38
- [Chain.Base]: ReturnType<typeof BaseLedger>;
39
- [Chain.BinanceSmartChain]: ReturnType<typeof BinanceSmartChainLedger>;
40
- [Chain.BitcoinCash]: ReturnType<typeof BitcoinCashLedger>;
41
- [Chain.Bitcoin]: ReturnType<typeof BitcoinLedger>;
42
- [Chain.Cosmos]: CosmosLedger;
43
- [Chain.Dash]: ReturnType<typeof DashLedger>;
44
- [Chain.Dogecoin]: ReturnType<typeof DogecoinLedger>;
45
- [Chain.Ethereum]: ReturnType<typeof EthereumLedger>;
46
- [Chain.Gnosis]: ReturnType<typeof GnosisLedger>;
47
- [Chain.Litecoin]: ReturnType<typeof LitecoinLedger>;
48
- [Chain.Near]: Awaited<ReturnType<typeof getNearLedgerClient>>;
49
- [Chain.Optimism]: ReturnType<typeof OptimismLedger>;
50
- [Chain.Polygon]: ReturnType<typeof PolygonLedger>;
51
- [Chain.Ripple]: ReturnType<typeof XRPLedger>;
52
- [Chain.THORChain]: THORChainLedger;
53
- [Chain.Tron]: ReturnType<typeof TronLedger>;
54
- };
55
-
56
- type LedgerSupportedChain = keyof LedgerSignerMap;
57
-
58
- export const getLedgerClient = async <T extends LedgerSupportedChain>({
59
- chain,
60
- derivationPath,
61
- }: {
62
- chain: T;
63
- derivationPath?: DerivationPathArray;
64
- }): Promise<LedgerSignerMap[T]> => {
65
- const { match } = await import("ts-pattern");
66
-
67
- return match(chain as LedgerSupportedChain)
68
- .returnType<Promise<LedgerSignerMap[T]>>()
69
- .with(Chain.THORChain, () =>
70
- Promise.resolve(new THORChainLedger(derivationPath) as LedgerSignerMap[T]),
71
- )
72
- .with(Chain.Cosmos, () =>
73
- Promise.resolve(new CosmosLedger(derivationPath) as LedgerSignerMap[T]),
74
- )
75
- .with(Chain.Bitcoin, () => Promise.resolve(BitcoinLedger(derivationPath) as LedgerSignerMap[T]))
76
- .with(Chain.BitcoinCash, () =>
77
- Promise.resolve(BitcoinCashLedger(derivationPath) as LedgerSignerMap[T]),
78
- )
79
- .with(Chain.Dash, () => Promise.resolve(DashLedger(derivationPath) as LedgerSignerMap[T]))
80
- .with(Chain.Dogecoin, () =>
81
- Promise.resolve(DogecoinLedger(derivationPath) as LedgerSignerMap[T]),
82
- )
83
- .with(Chain.Litecoin, () =>
84
- Promise.resolve(LitecoinLedger(derivationPath) as LedgerSignerMap[T]),
85
- )
86
- .with(Chain.Ripple, () => Promise.resolve(XRPLedger(derivationPath) as LedgerSignerMap[T]))
87
- .with(Chain.Tron, () => Promise.resolve(TronLedger(derivationPath) as LedgerSignerMap[T]))
88
- .with(Chain.Near, async () => {
89
- const transport = await getLedgerTransport();
90
- return getNearLedgerClient(transport, derivationPath) as unknown as LedgerSignerMap[T];
91
- })
92
- .with(
93
- Chain.Arbitrum,
94
- Chain.Aurora,
95
- Chain.Avalanche,
96
- Chain.BinanceSmartChain,
97
- Chain.Ethereum,
98
- Chain.Gnosis,
99
- Chain.Optimism,
100
- Chain.Polygon,
101
- Chain.Base,
102
- async () => {
103
- const { getProvider } = await import("@swapkit/toolboxes/evm");
104
- const params = { provider: await getProvider(chain as EVMChain), derivationPath };
105
-
106
- return match(chain as Chain)
107
- .with(
108
- Chain.BinanceSmartChain,
109
- () => BinanceSmartChainLedger(params) as LedgerSignerMap[T],
110
- )
111
- .with(Chain.Avalanche, () => AvalancheLedger(params) as LedgerSignerMap[T])
112
- .with(Chain.Arbitrum, () => ArbitrumLedger(params) as LedgerSignerMap[T])
113
- .with(Chain.Optimism, () => OptimismLedger(params) as LedgerSignerMap[T])
114
- .with(Chain.Polygon, () => PolygonLedger(params) as LedgerSignerMap[T])
115
- .with(Chain.Base, () => BaseLedger(params) as LedgerSignerMap[T])
116
- .with(Chain.Aurora, () => AuroraLedger(params) as LedgerSignerMap[T])
117
- .with(Chain.Gnosis, () => GnosisLedger(params) as LedgerSignerMap[T])
118
- .otherwise(() => EthereumLedger(params) as LedgerSignerMap[T]);
119
- },
120
- )
121
- .otherwise(() => {
122
- throw new SwapKitError("wallet_chain_not_supported", { wallet: WalletOption.LEDGER, chain });
123
- });
124
- };
@@ -1,80 +0,0 @@
1
- import type Transport from "@ledgerhq/hw-transport";
2
- import { SwapKitError } from "@swapkit/helpers";
3
-
4
- const getNavigatorUsb = () =>
5
- // @ts-ignore
6
- navigator?.usb as unknown as {
7
- getDevices: () => Promise<any[]>;
8
- requestDevice: (requestObject: any) => Promise<any>;
9
- removeEventListener: (event: string, callback: (e: any) => void) => void;
10
- addEventListener: (event: string, callback: (e: any) => void) => void;
11
- };
12
-
13
- const getLedgerDevices = async () => {
14
- const navigatorUsb = getNavigatorUsb();
15
-
16
- if (typeof navigatorUsb?.getDevices !== "function") return [];
17
- const { ledgerUSBVendorId } = await import("@ledgerhq/devices");
18
-
19
- const devices = await navigatorUsb?.getDevices();
20
- const existingDevices = devices.filter((d) => d.vendorId === ledgerUSBVendorId);
21
- if (existingDevices.length > 0) return existingDevices[0];
22
-
23
- return navigatorUsb?.requestDevice({
24
- filters: [{ vendorId: ledgerUSBVendorId }],
25
- });
26
- };
27
-
28
- export const getLedgerTransport = async () => {
29
- const device = await getLedgerDevices();
30
-
31
- if (!device) {
32
- throw new SwapKitError("wallet_ledger_device_not_found");
33
- }
34
-
35
- await device.open();
36
- if (device.configuration === null) await device.selectConfiguration(1);
37
-
38
- try {
39
- await device.reset();
40
- } catch {
41
- // reset fails on devices that are already open
42
- }
43
-
44
- const iface = device.configurations[0].interfaces.find(
45
- ({ alternates }: { alternates: { interfaceClass: number }[] }) =>
46
- alternates.some(({ interfaceClass }) => interfaceClass === 255),
47
- );
48
-
49
- if (!iface) {
50
- await device.close();
51
- throw new SwapKitError("wallet_ledger_connection_error");
52
- }
53
-
54
- try {
55
- await device.claimInterface(iface.interfaceNumber);
56
- } catch (error: unknown) {
57
- await device.close();
58
-
59
- throw new SwapKitError("wallet_ledger_connection_claimed", error);
60
- }
61
-
62
- const Transport = (await import("@ledgerhq/hw-transport-webusb")).default;
63
- const isSupported = await Transport.isSupported();
64
- if (!isSupported) throw new SwapKitError("wallet_ledger_webusb_not_supported");
65
-
66
- const { DisconnectedDevice } = await import("@ledgerhq/errors");
67
-
68
- const transport = new Transport(device, iface.interfaceNumber);
69
-
70
- const onDisconnect = (e: any) => {
71
- if (device === e.device) {
72
- getNavigatorUsb()?.removeEventListener("disconnect", onDisconnect);
73
-
74
- transport._emitDisconnect(new DisconnectedDevice());
75
- }
76
- };
77
- getNavigatorUsb()?.addEventListener("disconnect", onDisconnect);
78
-
79
- return transport as Transport;
80
- };
@@ -1,3 +0,0 @@
1
- export { getLedgerAddress } from "./getLedgerAddress";
2
- export { getLedgerClient } from "./getLedgerClient";
3
- export { getLedgerTransport } from "./getLedgerTransport";
@@ -1,311 +0,0 @@
1
- import {
2
- Chain,
3
- ChainId,
4
- type DerivationPathArray,
5
- FeeOption,
6
- type GenericTransferParams,
7
- SKConfig,
8
- StagenetChain,
9
- SwapKitError,
10
- WalletOption,
11
- createWallet,
12
- filterSupportedChains,
13
- } from "@swapkit/helpers";
14
- import type { ThorchainDepositParams } from "@swapkit/toolboxes/cosmos";
15
- import type { UTXOBuildTxParams } from "@swapkit/toolboxes/utxo";
16
-
17
- import { getWalletSupportedChains } from "../utils";
18
- import { getLedgerAddress, getLedgerClient } from "./helpers";
19
-
20
- export const ledgerWallet = createWallet({
21
- name: "connectLedger",
22
- supportedChains: [
23
- Chain.Arbitrum,
24
- Chain.Aurora,
25
- Chain.Avalanche,
26
- Chain.Base,
27
- Chain.BinanceSmartChain,
28
- Chain.Bitcoin,
29
- Chain.BitcoinCash,
30
- Chain.Cosmos,
31
- Chain.Dash,
32
- Chain.Dogecoin,
33
- Chain.Ethereum,
34
- Chain.Gnosis,
35
- Chain.Litecoin,
36
- Chain.Near,
37
- Chain.Optimism,
38
- Chain.Polygon,
39
- Chain.Ripple,
40
- Chain.THORChain,
41
- Chain.Tron,
42
- ],
43
- walletType: WalletOption.LEDGER,
44
- connect: ({ addChain, supportedChains, walletType }) =>
45
- async function connectLedger(chains: Chain[], derivationPath?: DerivationPathArray) {
46
- const [chain] = filterSupportedChains({ chains, supportedChains, walletType });
47
-
48
- if (!chain) return false;
49
-
50
- const walletMethods = await getWalletMethods({ chain, derivationPath });
51
-
52
- addChain({ ...walletMethods, chain, walletType: WalletOption.LEDGER });
53
-
54
- return true;
55
- },
56
- });
57
-
58
- export const LEDGER_SUPPORTED_CHAINS = getWalletSupportedChains(ledgerWallet);
59
-
60
- // reduce memo length by removing trade limit
61
- function reduceMemo(memo?: string, affiliateAddress = "t") {
62
- if (!memo?.includes("=:")) return memo;
63
-
64
- const removedAffiliate = memo.includes(`:${affiliateAddress}:`)
65
- ? memo.split(`:${affiliateAddress}:`)[0]
66
- : memo;
67
-
68
- return removedAffiliate?.substring(0, removedAffiliate.lastIndexOf(":"));
69
- }
70
-
71
- function recursivelyOrderKeys(unordered: any) {
72
- // If it's an array - recursively order any
73
- // dictionary items within the array
74
- if (Array.isArray(unordered)) {
75
- unordered.forEach((item, index) => {
76
- unordered[index] = recursivelyOrderKeys(item);
77
- });
78
- return unordered;
79
- }
80
-
81
- // If it's an object - let's order the keys
82
- if (typeof unordered !== "object") return unordered;
83
- const ordered: any = {};
84
- const sortedKeys = Object.keys(unordered).sort();
85
-
86
- for (const key of sortedKeys) {
87
- ordered[key] = recursivelyOrderKeys(unordered[key]);
88
- }
89
-
90
- return ordered;
91
- }
92
-
93
- function stringifyKeysInOrder(data: any) {
94
- return JSON.stringify(recursivelyOrderKeys(data));
95
- }
96
-
97
- async function getWalletMethods({
98
- chain,
99
- derivationPath,
100
- }: { chain: Chain; derivationPath?: DerivationPathArray }) {
101
- switch (chain) {
102
- case Chain.BitcoinCash:
103
- case Chain.Bitcoin:
104
- case Chain.Dash:
105
- case Chain.Dogecoin:
106
- case Chain.Litecoin: {
107
- const { getUtxoToolbox } = await import("@swapkit/toolboxes/utxo");
108
- const toolbox = await getUtxoToolbox(chain as Chain.Bitcoin);
109
-
110
- const signer = await getLedgerClient({ chain, derivationPath });
111
- const address = await getLedgerAddress({ chain, ledgerClient: signer });
112
-
113
- const transfer = async (params: UTXOBuildTxParams) => {
114
- const feeRate = params.feeRate || (await toolbox.getFeeRates())[FeeOption.Average];
115
- const memo = [Chain.Bitcoin].includes(chain) ? params.memo : reduceMemo(params.memo);
116
-
117
- const { psbt, inputs } = await toolbox.createTransaction({
118
- ...params,
119
- feeRate,
120
- memo,
121
- sender: address,
122
- fetchTxHex: true,
123
- });
124
- const txHex = await signer.signTransaction(psbt, inputs);
125
- const tx = await toolbox.broadcastTx(txHex);
126
-
127
- return tx;
128
- };
129
-
130
- return { ...toolbox, address, transfer };
131
- }
132
-
133
- case Chain.Ethereum:
134
- case Chain.Avalanche:
135
- case Chain.Arbitrum:
136
- case Chain.Optimism:
137
- case Chain.Polygon:
138
- case Chain.BinanceSmartChain:
139
- case Chain.Base:
140
- case Chain.Aurora:
141
- case Chain.Gnosis: {
142
- const { getEvmToolbox } = await import("@swapkit/toolboxes/evm");
143
- const signer = await getLedgerClient({ chain, derivationPath });
144
- const address = await getLedgerAddress({ chain, ledgerClient: signer });
145
- const toolbox = await getEvmToolbox(chain, { signer });
146
-
147
- return { ...toolbox, address };
148
- }
149
-
150
- case Chain.Cosmos: {
151
- const { createSigningStargateClient, getMsgSendDenom, getCosmosToolbox } = await import(
152
- "@swapkit/toolboxes/cosmos"
153
- );
154
- const toolbox = await getCosmosToolbox(Chain.Cosmos);
155
- const signer = await getLedgerClient({ chain, derivationPath });
156
- const address = await getLedgerAddress({ chain, ledgerClient: signer });
157
-
158
- const transfer = async ({ assetValue, recipient, memo }: GenericTransferParams) => {
159
- if (!assetValue) throw new SwapKitError("wallet_ledger_invalid_asset");
160
-
161
- const sendCoinsMessage = {
162
- amount: [
163
- {
164
- amount: assetValue.getBaseValue("string"),
165
- denom: getMsgSendDenom(`u${assetValue.symbol}`).toLowerCase(),
166
- },
167
- ],
168
- fromAddress: address,
169
- toAddress: recipient,
170
- };
171
-
172
- const signingClient = await createSigningStargateClient(
173
- SKConfig.get("rpcUrls")[chain],
174
- signer,
175
- "0.007uatom",
176
- );
177
-
178
- const { transactionHash } = await signingClient.signAndBroadcast(
179
- address,
180
- [{ typeUrl: "/cosmos.bank.v1beta1.MsgSend", value: sendCoinsMessage }],
181
- 2,
182
- memo,
183
- );
184
-
185
- return transactionHash;
186
- };
187
-
188
- return { ...toolbox, address, transfer };
189
- }
190
-
191
- case Chain.THORChain: {
192
- const { SignMode } = await import("cosmjs-types/cosmos/tx/signing/v1beta1/signing.js");
193
- const { TxRaw } = await import("cosmjs-types/cosmos/tx/v1beta1/tx.js");
194
- const importedSigning = await import("@cosmjs/proto-signing");
195
- const encodePubkey = importedSigning.encodePubkey ?? importedSigning.default?.encodePubkey;
196
- const makeAuthInfoBytes =
197
- importedSigning.makeAuthInfoBytes ?? importedSigning.default?.makeAuthInfoBytes;
198
- const {
199
- createStargateClient,
200
- buildEncodedTxBody,
201
- getCosmosToolbox,
202
- buildAminoMsg,
203
- getDefaultChainFee,
204
- fromBase64,
205
- parseAminoMessageForDirectSigning,
206
- } = await import("@swapkit/toolboxes/cosmos");
207
- const toolbox = await getCosmosToolbox(chain);
208
- const signer = await getLedgerClient({ chain, derivationPath });
209
- const address = await getLedgerAddress({ chain, ledgerClient: signer });
210
-
211
- const fee = getDefaultChainFee(chain);
212
- const { pubkey: value, signTransaction, sign: signMessage } = signer;
213
-
214
- // ANCHOR (@Chillios): Same parts in methods + can extract StargateClient init to toolbox
215
- const thorchainTransfer = async ({
216
- memo = "",
217
- assetValue,
218
- ...rest
219
- // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: Refactor to reduce complexity
220
- }: GenericTransferParams | ThorchainDepositParams) => {
221
- const account = await toolbox.getAccount(address);
222
- if (!account) throw new SwapKitError("wallet_ledger_invalid_account");
223
- if (!assetValue) throw new SwapKitError("wallet_ledger_invalid_asset");
224
- if (!value) throw new SwapKitError("wallet_ledger_pubkey_not_found");
225
-
226
- const { accountNumber, sequence: sequenceNumber } = account;
227
- const sequence = (sequenceNumber || 0).toString();
228
-
229
- const orderedMessages = recursivelyOrderKeys([
230
- buildAminoMsg({ sender: address, assetValue, memo, ...rest }),
231
- ]);
232
-
233
- // get tx signing msg
234
- const rawSendTx = stringifyKeysInOrder({
235
- account_number: accountNumber?.toString(),
236
- chain_id: ChainId.THORChain,
237
- fee,
238
- memo,
239
- msgs: orderedMessages,
240
- sequence,
241
- });
242
-
243
- const signatures = await signTransaction(rawSendTx, sequence);
244
- if (!signatures) throw new SwapKitError("wallet_ledger_signing_error");
245
-
246
- const pubkey = encodePubkey({ type: "tendermint/PubKeySecp256k1", value });
247
- const msgs = orderedMessages.map(parseAminoMessageForDirectSigning);
248
- const bodyBytes = await buildEncodedTxBody({ msgs, chain, memo });
249
-
250
- const authInfoBytes = makeAuthInfoBytes(
251
- [{ pubkey, sequence: Number(sequence) }],
252
- fee.amount,
253
- Number.parseInt(fee.gas),
254
- undefined,
255
- undefined,
256
- SignMode.SIGN_MODE_LEGACY_AMINO_JSON,
257
- );
258
-
259
- const signature = signatures?.[0]?.signature
260
- ? fromBase64(signatures[0].signature)
261
- : Uint8Array.from([]);
262
-
263
- const txRaw = TxRaw.fromPartial({ bodyBytes, authInfoBytes, signatures: [signature] });
264
- const txBytes = TxRaw.encode(txRaw).finish();
265
- const { isStagenet } = SKConfig.get("envs");
266
-
267
- const broadcaster = await createStargateClient(
268
- SKConfig.get("rpcUrls")[isStagenet ? StagenetChain.THORChain : Chain.THORChain],
269
- );
270
- const { transactionHash } = await broadcaster.broadcastTx(txBytes);
271
-
272
- return transactionHash;
273
- };
274
-
275
- const transfer = (params: GenericTransferParams) => thorchainTransfer(params);
276
- const deposit = (params: ThorchainDepositParams) => thorchainTransfer(params);
277
-
278
- return { ...toolbox, address, deposit, transfer, signMessage };
279
- }
280
-
281
- case Chain.Near: {
282
- const { getNearToolbox } = await import("@swapkit/toolboxes/near");
283
- const signer = await getLedgerClient({ chain, derivationPath });
284
- const accountId = await signer.getAddress();
285
- const toolbox = await getNearToolbox({ signer });
286
-
287
- return { ...toolbox, address: accountId };
288
- }
289
-
290
- case Chain.Ripple: {
291
- const { getRippleToolbox } = await import("@swapkit/toolboxes/ripple");
292
- const signer = await getLedgerClient({ chain, derivationPath });
293
- const address = signer.address;
294
- const toolbox = await getRippleToolbox({ signer });
295
-
296
- return { ...toolbox, address };
297
- }
298
-
299
- case Chain.Tron: {
300
- const { createTronToolbox } = await import("@swapkit/toolboxes/tron");
301
- const signer = await getLedgerClient({ chain, derivationPath });
302
- const address = await getLedgerAddress({ chain, ledgerClient: signer });
303
- const toolbox = await createTronToolbox({ signer });
304
-
305
- return { ...toolbox, address };
306
- }
307
-
308
- default:
309
- throw new SwapKitError("wallet_ledger_chain_not_supported", { chain });
310
- }
311
- }