@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,183 +0,0 @@
1
- import type EthereumApp from "@ledgerhq/hw-app-eth";
2
- import {
3
- ChainId,
4
- type DerivationPathArray,
5
- NetworkDerivationPath,
6
- SwapKitError,
7
- derivationPathToString,
8
- } from "@swapkit/helpers";
9
- import { AbstractSigner, type Provider, type TransactionRequest } from "ethers";
10
-
11
- import { getLedgerTransport } from "../helpers/getLedgerTransport";
12
-
13
- class EVMLedgerInterface extends AbstractSigner {
14
- chainId: ChainId = ChainId.Ethereum;
15
- derivationPath = "";
16
- ledgerApp: InstanceType<typeof EthereumApp> | null = null;
17
- ledgerTimeout = 50000;
18
-
19
- constructor({
20
- provider,
21
- derivationPath = NetworkDerivationPath.OP,
22
- chainId = ChainId.Optimism,
23
- }: {
24
- provider: Provider;
25
- derivationPath?: DerivationPathArray | string;
26
- chainId?: ChainId;
27
- }) {
28
- super(provider);
29
-
30
- this.chainId = chainId || ChainId.Ethereum;
31
- this.derivationPath =
32
- typeof derivationPath === "string" ? derivationPath : derivationPathToString(derivationPath);
33
-
34
- Object.defineProperty(this, "provider", {
35
- enumerable: true,
36
- value: provider || null,
37
- writable: false,
38
- });
39
- }
40
-
41
- connect = (provider: Provider) =>
42
- new EVMLedgerInterface({
43
- provider,
44
- derivationPath: this.derivationPath,
45
- chainId: this.chainId,
46
- });
47
-
48
- checkOrCreateTransportAndLedger = async () => {
49
- if (this.ledgerApp) return;
50
- await this.createTransportAndLedger();
51
- };
52
-
53
- createTransportAndLedger = async () => {
54
- const transport = await getLedgerTransport();
55
- const EthereumApp = (await import("@ledgerhq/hw-app-eth")).default;
56
-
57
- this.ledgerApp = new EthereumApp(transport);
58
- };
59
-
60
- getAddress = async () => {
61
- const response = await this.getAddressAndPubKey();
62
- if (!response) throw new SwapKitError("wallet_ledger_failed_to_get_address");
63
- return response.address;
64
- };
65
-
66
- getAddressAndPubKey = async () => {
67
- await this.createTransportAndLedger();
68
- return this.ledgerApp?.getAddress(this.derivationPath);
69
- };
70
-
71
- showAddressAndPubKey = async () => {
72
- await this.createTransportAndLedger();
73
- return this.ledgerApp?.getAddress(this.derivationPath, true);
74
- };
75
-
76
- signMessage = async (messageHex: string) => {
77
- const { Signature } = await import("ethers");
78
- await this.createTransportAndLedger();
79
-
80
- const sig = await this.ledgerApp?.signPersonalMessage(this.derivationPath, messageHex);
81
-
82
- if (!sig) throw new SwapKitError("wallet_ledger_signing_error");
83
-
84
- sig.r = `0x${sig.r}`;
85
- sig.s = `0x${sig.s}`;
86
- return Signature.from(sig).serialized;
87
- };
88
-
89
- sendTransaction = async (tx: TransactionRequest): Promise<any> => {
90
- if (!this.provider) throw new SwapKitError("wallet_ledger_no_provider");
91
-
92
- const signedTxHex = await this.signTransaction(tx);
93
-
94
- return await this.provider.broadcastTransaction(signedTxHex);
95
- };
96
-
97
- signTypedData(): Promise<string> {
98
- throw new SwapKitError("wallet_ledger_method_not_supported", { method: "signTypedData" });
99
- }
100
-
101
- signTransaction = async (tx: TransactionRequest) => {
102
- const { Transaction } = await import("ethers");
103
- await this.createTransportAndLedger();
104
-
105
- const transactionCount = await this.provider?.getTransactionCount(
106
- tx.from || (await this.getAddress()),
107
- );
108
-
109
- const baseTx = {
110
- chainId: tx.chainId || this.chainId,
111
- data: tx.data,
112
- gasLimit: tx.gasLimit,
113
- ...(tx.gasPrice && { gasPrice: tx.gasPrice }),
114
- ...(!tx.gasPrice &&
115
- tx.maxFeePerGas && {
116
- maxFeePerGas: tx.maxFeePerGas,
117
- maxPriorityFeePerGas: tx.maxPriorityFeePerGas,
118
- }),
119
- nonce:
120
- tx.nonce !== undefined
121
- ? Number((tx.nonce || transactionCount || 0).toString())
122
- : transactionCount,
123
- to: tx.to?.toString(),
124
- value: tx.value,
125
- type: tx.type && !Number.isNaN(tx.type) ? tx.type : tx.maxFeePerGas ? 2 : 0,
126
- };
127
-
128
- // ledger expects the tx to be serialized without the 0x prefix
129
- const unsignedTx = Transaction.from(baseTx).unsignedSerialized.slice(2);
130
-
131
- const { ledgerService } = await import("@ledgerhq/hw-app-eth");
132
-
133
- const resolution = await ledgerService.resolveTransaction(
134
- unsignedTx,
135
- {},
136
- { externalPlugins: true, erc20: true },
137
- );
138
-
139
- const signature = await this.ledgerApp?.signTransaction(
140
- this.derivationPath,
141
- unsignedTx,
142
- resolution,
143
- );
144
-
145
- if (!signature) throw new SwapKitError("wallet_ledger_signing_error");
146
-
147
- const { r, s, v } = signature;
148
-
149
- return Transaction.from({
150
- ...baseTx,
151
- signature: { v: Number(BigInt(v)), r: `0x${r}`, s: `0x${s}` },
152
- }).serialized;
153
- };
154
- }
155
-
156
- type LedgerParams = { provider: Provider; derivationPath?: DerivationPathArray };
157
-
158
- export const EthereumLedger = ({ provider, derivationPath }: LedgerParams) =>
159
- new EVMLedgerInterface({ chainId: ChainId.Ethereum, provider, derivationPath });
160
-
161
- export const AvalancheLedger = ({ provider, derivationPath }: LedgerParams) =>
162
- new EVMLedgerInterface({ chainId: ChainId.Avalanche, provider, derivationPath });
163
-
164
- export const BinanceSmartChainLedger = ({ provider, derivationPath }: LedgerParams) =>
165
- new EVMLedgerInterface({ chainId: ChainId.BinanceSmartChain, provider, derivationPath });
166
-
167
- export const ArbitrumLedger = ({ provider, derivationPath }: LedgerParams) =>
168
- new EVMLedgerInterface({ chainId: ChainId.Arbitrum, provider, derivationPath });
169
-
170
- export const PolygonLedger = ({ provider, derivationPath }: LedgerParams) =>
171
- new EVMLedgerInterface({ chainId: ChainId.Polygon, provider, derivationPath });
172
-
173
- export const OptimismLedger = ({ provider, derivationPath }: LedgerParams) =>
174
- new EVMLedgerInterface({ chainId: ChainId.Optimism, provider, derivationPath });
175
-
176
- export const BaseLedger = ({ provider, derivationPath }: LedgerParams) =>
177
- new EVMLedgerInterface({ chainId: ChainId.Base, provider, derivationPath });
178
-
179
- export const AuroraLedger = ({ provider, derivationPath }: LedgerParams) =>
180
- new EVMLedgerInterface({ chainId: ChainId.Aurora, provider, derivationPath });
181
-
182
- export const GnosisLedger = ({ provider, derivationPath }: LedgerParams) =>
183
- new EVMLedgerInterface({ chainId: ChainId.Gnosis, provider, derivationPath });
@@ -1,86 +0,0 @@
1
- import type Transport from "@ledgerhq/hw-transport";
2
- import type { DerivationPathArray } from "@swapkit/helpers";
3
- import type { NearSigner } from "@swapkit/toolboxes/near";
4
- import type { SignedTransaction, Transaction } from "near-api-js/lib/transaction";
5
-
6
- export async function getNearLedgerClient(
7
- transport: Transport,
8
- derivationPath?: DerivationPathArray,
9
- ) {
10
- const Near = await import("@ledgerhq/hw-app-near");
11
- const { Chain, DerivationPath, derivationPathToString, SwapKitError } = await import(
12
- "@swapkit/helpers"
13
- );
14
- const nearApp = new Near.default(transport);
15
-
16
- // NEAR uses m/44'/397'/0'/0'/0' by default
17
- const path = derivationPath ? derivationPathToString(derivationPath) : DerivationPath[Chain.Near];
18
-
19
- // Get address and public key from Ledger
20
- const { address, publicKey: pubKeyHex } = await nearApp.getAddress(path);
21
-
22
- const signer = {
23
- async getPublicKey() {
24
- const { utils } = await import("near-api-js");
25
- // Convert hex public key to NEAR PublicKey format
26
- return utils.PublicKey.fromString(`ed25519:${pubKeyHex}`);
27
- },
28
-
29
- signNep413Message(
30
- _message: string,
31
- _accountId: string,
32
- _recipient: string,
33
- _nonce: Uint8Array,
34
- _callbackUrl?: string,
35
- ) {
36
- // Most NEAR Ledger apps don't support arbitrary message signing
37
- return Promise.reject(
38
- new SwapKitError("wallet_ledger_method_not_supported", {
39
- wallet: "Ledger",
40
- method: "signNep413Message",
41
- }),
42
- );
43
- },
44
-
45
- getAddress() {
46
- return Promise.resolve(address);
47
- },
48
-
49
- async signTransaction(transaction: Transaction) {
50
- const { Signature, SignedTransaction } = await import("near-api-js/lib/transaction");
51
- try {
52
- const signatureArray = await nearApp.signTransaction(transaction.encode(), path);
53
- if (!signatureArray) {
54
- throw new Error("Signature undefined");
55
- }
56
-
57
- const signature = new Signature({
58
- keyType: 0,
59
- data: signatureArray,
60
- });
61
-
62
- const signedTransaction = new SignedTransaction({ transaction, signature });
63
-
64
- return [signatureArray, signedTransaction] as [
65
- Uint8Array<ArrayBufferLike>,
66
- SignedTransaction,
67
- ];
68
- } catch (error) {
69
- throw new SwapKitError("wallet_ledger_signing_error", {
70
- error,
71
- });
72
- }
73
- },
74
-
75
- signDelegateAction(_delegateAction: any) {
76
- return Promise.reject(
77
- new SwapKitError("wallet_ledger_method_not_supported", {
78
- wallet: "Ledger",
79
- method: "signDelegateAction",
80
- }),
81
- );
82
- },
83
- };
84
-
85
- return signer as NearSigner;
86
- }
@@ -1,117 +0,0 @@
1
- export const CLA = 0x55;
2
- export const CHUNK_SIZE = 250;
3
- export const APP_KEY = "CSM";
4
-
5
- export const INS = {
6
- GET_VERSION: 0x00,
7
- INS_PUBLIC_KEY_SECP256K1: 0x01, // Obsolete
8
- SIGN_SECP256K1: 0x02,
9
- GET_ADDR_SECP256K1: 0x04,
10
- };
11
-
12
- export const PAYLOAD_TYPE = {
13
- INIT: 0x00,
14
- ADD: 0x01,
15
- LAST: 0x02,
16
- };
17
-
18
- export const P1_VALUES = {
19
- ONLY_RETRIEVE: 0x00,
20
- SHOW_ADDRESS_IN_DEVICE: 0x01,
21
- };
22
-
23
- export const P2_VALUES = {
24
- JSON: 0x0,
25
- };
26
-
27
- export const ERROR_CODE = {
28
- NoError: 0x9000,
29
- };
30
-
31
- const ERROR_DESCRIPTION: any = {
32
- 1: "U2F: Unknown",
33
- 2: "U2F: Bad request",
34
- 3: "U2F: Configuration unsupported",
35
- 4: "U2F: Device Ineligible",
36
- 5: "U2F: Timeout",
37
- 14: "Timeout",
38
- 36864: "No errors",
39
- 36865: "Device is busy",
40
- 26626: "Error deriving keys",
41
- 25600: "Execution Error",
42
- 26368: "Wrong Length",
43
- 27010: "Empty Buffer",
44
- 27011: "Output buffer too small",
45
- 27012: "Data is invalid",
46
- 27013: "Conditions not satisfied",
47
- 27014: "Transaction rejected",
48
- 27264: "Bad key handle",
49
- 27392: "Invalid P1/P2",
50
- 27904: "Instruction not supported",
51
- 28160: "App does not seem to be open",
52
- 28416: "Unknown error",
53
- 28417: "Sign/verify error",
54
- };
55
-
56
- export function errorCodeToString(statusCode: number) {
57
- if (statusCode in ERROR_DESCRIPTION) return ERROR_DESCRIPTION[statusCode];
58
- return `Unknown Status Code: ${statusCode}`;
59
- }
60
-
61
- function isDict(v: any) {
62
- return typeof v === "object" && v !== null && !Array.isArray(v) && !(v instanceof Date);
63
- }
64
-
65
- export function processErrorResponse(response: any) {
66
- if (response) {
67
- if (isDict(response)) {
68
- if (Object.prototype.hasOwnProperty.call(response, "statusCode")) {
69
- return {
70
- return_code: response.statusCode,
71
- error_message: errorCodeToString(response.statusCode),
72
- };
73
- }
74
-
75
- if (
76
- Object.prototype.hasOwnProperty.call(response, "return_code") &&
77
- Object.prototype.hasOwnProperty.call(response, "error_message")
78
- ) {
79
- return response;
80
- }
81
- }
82
- return {
83
- return_code: 0xffff,
84
- error_message: response.toString(),
85
- };
86
- }
87
-
88
- return {
89
- return_code: 0xffff,
90
- error_message: response.toString(),
91
- };
92
- }
93
-
94
- export async function getVersion(transport: any) {
95
- return transport.send(CLA, INS.GET_VERSION, 0, 0).then((response: any) => {
96
- const errorCodeData = response.slice(-2);
97
- const returnCode = errorCodeData[0] * 256 + errorCodeData[1];
98
-
99
- let targetId = 0;
100
- if (response.length >= 9) {
101
- targetId =
102
- (response[5] << 24) + (response[6] << 16) + (response[7] << 8) + (response[8] << 0);
103
- }
104
-
105
- return {
106
- return_code: returnCode,
107
- error_message: errorCodeToString(returnCode),
108
- // ///
109
- test_mode: response[0] !== 0,
110
- major: response[1],
111
- minor: response[2],
112
- patch: response[3],
113
- device_locked: response[4] === 1,
114
- target_id: targetId.toString(16),
115
- };
116
- }, processErrorResponse);
117
- }
@@ -1,149 +0,0 @@
1
- import { SwapKitError } from "@swapkit/helpers";
2
- import {
3
- CLA,
4
- ERROR_CODE,
5
- INS,
6
- P2_VALUES,
7
- PAYLOAD_TYPE,
8
- errorCodeToString,
9
- processErrorResponse,
10
- } from "./common";
11
-
12
- export function serializePathv1(path: number[]) {
13
- if (path == null || path.length < 3) {
14
- throw new SwapKitError("wallet_ledger_invalid_params", { reason: "Path too short" });
15
- }
16
- if (path.length > 10) {
17
- throw new SwapKitError("wallet_ledger_invalid_params", { reason: "Path too long" });
18
- }
19
- const buf = Buffer.alloc(1 + 4 * path.length);
20
- buf.writeUInt8(path.length, 0);
21
- for (let i = 0; i < path.length; i += 1) {
22
- let v = path[i] || 0;
23
- if (i < 3) {
24
- // eslint-disable-next-line no-bitwise
25
- v |= 0x80000000; // Harden
26
- }
27
- buf.writeInt32LE(v, 1 + i * 4);
28
- }
29
- return buf;
30
- }
31
-
32
- export async function signSendChunkv1(
33
- app: any,
34
- chunkIdx: number,
35
- _chunkNum: number,
36
- chunk: Buffer,
37
- txType = P2_VALUES.JSON,
38
- ) {
39
- return app.transport
40
- .send(CLA, INS.SIGN_SECP256K1, chunkIdx, txType, chunk, [ERROR_CODE.NoError, 0x6984, 0x6a80])
41
- .then((response: any) => {
42
- const errorCodeData = response.slice(-2);
43
- const returnCode = errorCodeData[0] * 256 + errorCodeData[1];
44
- let errorMessage = errorCodeToString(returnCode);
45
-
46
- if (returnCode === 0x6a80 || returnCode === 0x6984) {
47
- errorMessage = `${errorMessage} : ${response.slice(0, response.length - 2).toString("ascii")}`;
48
- }
49
-
50
- let signature: any = null;
51
- if (response.length > 2) {
52
- signature = response.slice(0, response.length - 2);
53
- }
54
-
55
- return {
56
- signature,
57
- return_code: returnCode,
58
- error_message: errorMessage,
59
- };
60
- }, processErrorResponse);
61
- }
62
-
63
- function compressPublicKey(publicKey: Buffer) {
64
- if (publicKey.length !== 65) {
65
- throw new SwapKitError("wallet_ledger_invalid_params", {
66
- reason: "decompressed public key length should be 65 bytes",
67
- });
68
- }
69
- const y = publicKey.slice(33, 65);
70
-
71
- // @ts-ignore
72
- const z = Buffer.from([2 + (y[y.length - 1] & 1)]);
73
- // @ts-ignore
74
- return Buffer.concat([z, publicKey.slice(1, 33)]);
75
- }
76
-
77
- export async function publicKeyv1(app: any, data: Buffer) {
78
- return app.transport
79
- .send(CLA, INS.INS_PUBLIC_KEY_SECP256K1, 0, 0, data, [ERROR_CODE.NoError])
80
- .then((response: any) => {
81
- const errorCodeData = response.slice(-2);
82
- const returnCode = errorCodeData[0] * 256 + errorCodeData[1];
83
- const pk = Buffer.from(response.slice(0, 65));
84
-
85
- return {
86
- pk,
87
- compressed_pk: compressPublicKey(pk),
88
- return_code: returnCode,
89
- error_message: errorCodeToString(returnCode),
90
- };
91
- }, processErrorResponse);
92
- }
93
-
94
- export function serializePathv2(path: number[]) {
95
- if (!path || path.length !== 5) {
96
- throw new SwapKitError("wallet_ledger_invalid_params", {
97
- reason: "Path must be exactly 5 elements",
98
- });
99
- }
100
-
101
- const buf = Buffer.alloc(20);
102
- // @ts-ignore
103
- buf.writeUInt32LE(0x80000000 + path[0], 0);
104
- // @ts-ignore
105
- buf.writeUInt32LE(0x80000000 + path[1], 4);
106
- // @ts-ignore
107
- buf.writeUInt32LE(0x80000000 + path[2], 8);
108
- // @ts-ignore
109
- buf.writeUInt32LE(path[3], 12);
110
- // @ts-ignore
111
- buf.writeUInt32LE(path[4], 16);
112
-
113
- return buf;
114
- }
115
-
116
- export function signSendChunkv2(
117
- app: any,
118
- chunkIdx: number,
119
- chunkNum: number,
120
- chunk: Buffer,
121
- txType = P2_VALUES.JSON,
122
- ) {
123
- let payloadType = PAYLOAD_TYPE.ADD;
124
- if (chunkIdx === 1) {
125
- payloadType = PAYLOAD_TYPE.INIT;
126
- }
127
- if (chunkIdx === chunkNum) {
128
- payloadType = PAYLOAD_TYPE.LAST;
129
- }
130
-
131
- return signSendChunkv1(app, payloadType, 0, chunk, txType);
132
- }
133
-
134
- export async function publicKeyv2(app: any, data: Buffer) {
135
- return app.transport
136
- .send(CLA, INS.GET_ADDR_SECP256K1, 0, 0, data, [ERROR_CODE.NoError])
137
- .then((response: any) => {
138
- const errorCodeData = response.slice(-2);
139
- const returnCode = errorCodeData[0] * 256 + errorCodeData[1];
140
- const compressedPk = Buffer.from(response.slice(0, 33));
141
-
142
- return {
143
- pk: "OBSOLETE PROPERTY",
144
- compressed_pk: compressedPk,
145
- return_code: returnCode,
146
- error_message: errorCodeToString(returnCode),
147
- };
148
- }, processErrorResponse);
149
- }
@@ -1,94 +0,0 @@
1
- import { base64 } from "@scure/base";
2
- import { type DerivationPathArray, NetworkDerivationPath, SwapKitError } from "@swapkit/helpers";
3
-
4
- import { CosmosLedgerInterface } from "../../interfaces/CosmosLedgerInterface";
5
- import type { GetAddressAndPubKeyResponse } from "../../types";
6
- import { getSignature } from "./utils";
7
-
8
- export class THORChainLedger extends CosmosLedgerInterface {
9
- private pubKey: string | null = null;
10
-
11
- derivationPath: DerivationPathArray;
12
-
13
- constructor(derivationPath: DerivationPathArray = NetworkDerivationPath.THOR) {
14
- super();
15
- this.chain = "thor";
16
- this.derivationPath = derivationPath;
17
- }
18
-
19
- get pubkey() {
20
- return this.pubKey;
21
- }
22
-
23
- connect = async () => {
24
- await this.checkOrCreateTransportAndLedger();
25
- const { compressed_pk, bech32_address }: GetAddressAndPubKeyResponse =
26
- await this.getAddressAndPubKey();
27
-
28
- this.pubKey = base64.encode(compressed_pk);
29
-
30
- return bech32_address;
31
- };
32
-
33
- getAddressAndPubKey = async () => {
34
- await this.checkOrCreateTransportAndLedger(true);
35
-
36
- const response: GetAddressAndPubKeyResponse = await this.ledgerApp.getAddressAndPubKey(
37
- this.derivationPath,
38
- this.chain,
39
- );
40
-
41
- this.validateResponse(response.return_code, response.error_message);
42
-
43
- return response;
44
- };
45
-
46
- showAddressAndPubKey = async () => {
47
- await this.checkOrCreateTransportAndLedger(true);
48
-
49
- const response: GetAddressAndPubKeyResponse = await this.ledgerApp.showAddressAndPubKey(
50
- this.derivationPath,
51
- this.chain,
52
- );
53
-
54
- this.validateResponse(response.return_code, response.error_message);
55
-
56
- return response;
57
- };
58
-
59
- signTransaction = async (rawTx: string, sequence = "0") => {
60
- await this.checkOrCreateTransportAndLedger(true);
61
-
62
- const { return_code, error_message, signature } = await this.ledgerApp.sign(
63
- this.derivationPath,
64
- rawTx,
65
- );
66
-
67
- if (!this.pubKey) throw new SwapKitError("wallet_ledger_pubkey_not_found");
68
-
69
- this.validateResponse(return_code, error_message);
70
-
71
- return [
72
- {
73
- pub_key: { type: "tendermint/PubKeySecp256k1", value: this.pubKey },
74
- sequence,
75
- signature: getSignature(signature),
76
- },
77
- ];
78
- };
79
-
80
- sign = async (message: string) => {
81
- await this.checkOrCreateTransportAndLedger(true);
82
-
83
- const { return_code, error_message, signature } = await this.ledgerApp.sign(
84
- this.derivationPath,
85
- message,
86
- );
87
-
88
- if (!this.pubKey) throw new SwapKitError("wallet_ledger_pubkey_not_found");
89
-
90
- this.validateResponse(return_code, error_message);
91
-
92
- return getSignature(signature);
93
- };
94
- }