@swapkit/wallets 4.0.0-beta.54 → 4.0.0-beta.56

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 (294) 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/tronlink/index.cjs +4 -0
  83. package/dist/src/tronlink/index.cjs.map +11 -0
  84. package/dist/src/tronlink/index.js +4 -0
  85. package/dist/src/tronlink/index.js.map +11 -0
  86. package/dist/src/vultisig/index.cjs +2 -2
  87. package/dist/src/vultisig/index.cjs.map +3 -3
  88. package/dist/src/vultisig/index.js +2 -2
  89. package/dist/src/vultisig/index.js.map +3 -3
  90. package/dist/src/walletconnect/index.cjs +2 -2
  91. package/dist/src/walletconnect/index.cjs.map +3 -3
  92. package/dist/src/walletconnect/index.js +2 -2
  93. package/dist/src/walletconnect/index.js.map +3 -3
  94. package/dist/src/xaman/index.cjs +2 -2
  95. package/dist/src/xaman/index.cjs.map +5 -5
  96. package/dist/src/xaman/index.js +2 -2
  97. package/dist/src/xaman/index.js.map +5 -5
  98. package/dist/types/bitget/helpers.d.ts +330 -0
  99. package/dist/types/bitget/helpers.d.ts.map +1 -0
  100. package/dist/types/bitget/index.d.ts +11 -0
  101. package/dist/types/bitget/index.d.ts.map +1 -0
  102. package/dist/types/coinbase/index.d.ts +11 -0
  103. package/dist/types/coinbase/index.d.ts.map +1 -0
  104. package/dist/types/coinbase/signer.d.ts +91 -0
  105. package/dist/types/coinbase/signer.d.ts.map +1 -0
  106. package/dist/types/cosmostation/index.d.ts +21 -0
  107. package/dist/types/cosmostation/index.d.ts.map +1 -0
  108. package/dist/types/ctrl/index.d.ts +11 -0
  109. package/dist/types/ctrl/index.d.ts.map +1 -0
  110. package/dist/types/ctrl/walletHelpers.d.ts +24 -0
  111. package/dist/types/ctrl/walletHelpers.d.ts.map +1 -0
  112. package/dist/types/evm-extensions/index.d.ts +101 -0
  113. package/dist/types/evm-extensions/index.d.ts.map +1 -0
  114. package/{src/evm-extensions/types.ts → dist/types/evm-extensions/types.d.ts} +11 -13
  115. package/dist/types/evm-extensions/types.d.ts.map +1 -0
  116. package/dist/types/exodus/index.d.ts +14 -0
  117. package/dist/types/exodus/index.d.ts.map +1 -0
  118. package/dist/types/helpers/near.d.ts +57 -0
  119. package/dist/types/helpers/near.d.ts.map +1 -0
  120. package/dist/types/index.d.ts +4 -0
  121. package/dist/types/index.d.ts.map +1 -0
  122. package/dist/types/keepkey-bex/index.d.ts +11 -0
  123. package/dist/types/keepkey-bex/index.d.ts.map +1 -0
  124. package/dist/types/keepkey-bex/walletHelpers.d.ts +45 -0
  125. package/dist/types/keepkey-bex/walletHelpers.d.ts.map +1 -0
  126. package/dist/types/keepkey.d.ts +2 -0
  127. package/dist/types/keepkey.d.ts.map +1 -0
  128. package/dist/types/keplr/chainRegistry.d.ts +4 -0
  129. package/dist/types/keplr/chainRegistry.d.ts.map +1 -0
  130. package/dist/types/keplr/index.d.ts +11 -0
  131. package/dist/types/keplr/index.d.ts.map +1 -0
  132. package/dist/types/keystore.d.ts +2 -0
  133. package/dist/types/keystore.d.ts.map +1 -0
  134. package/dist/types/ledger.d.ts +2 -0
  135. package/dist/types/ledger.d.ts.map +1 -0
  136. package/dist/types/okx/helpers.d.ts +227 -0
  137. package/dist/types/okx/helpers.d.ts.map +1 -0
  138. package/dist/types/okx/index.d.ts +11 -0
  139. package/dist/types/okx/index.d.ts.map +1 -0
  140. package/dist/types/okx/types.d.ts +104 -0
  141. package/dist/types/okx/types.d.ts.map +1 -0
  142. package/dist/types/onekey/evmSigner.d.ts +29 -0
  143. package/dist/types/onekey/evmSigner.d.ts.map +1 -0
  144. package/dist/types/onekey/index.d.ts +11 -0
  145. package/dist/types/onekey/index.d.ts.map +1 -0
  146. package/dist/types/phantom/index.d.ts +12 -0
  147. package/dist/types/phantom/index.d.ts.map +1 -0
  148. package/dist/types/polkadotjs/index.d.ts +11 -0
  149. package/dist/types/polkadotjs/index.d.ts.map +1 -0
  150. package/dist/types/radix/index.d.ts +11 -0
  151. package/dist/types/radix/index.d.ts.map +1 -0
  152. package/dist/types/talisman/index.d.ts +11 -0
  153. package/dist/types/talisman/index.d.ts.map +1 -0
  154. package/dist/types/trezor.d.ts +2 -0
  155. package/dist/types/trezor.d.ts.map +1 -0
  156. package/dist/types/tronlink/helpers.d.ts +24 -0
  157. package/dist/types/tronlink/helpers.d.ts.map +1 -0
  158. package/dist/types/tronlink/index.d.ts +11 -0
  159. package/dist/types/tronlink/index.d.ts.map +1 -0
  160. package/dist/types/tronlink/types.d.ts +59 -0
  161. package/dist/types/tronlink/types.d.ts.map +1 -0
  162. package/dist/types/types.d.ts +249 -0
  163. package/dist/types/types.d.ts.map +1 -0
  164. package/dist/types/utils.d.ts +4 -0
  165. package/dist/types/utils.d.ts.map +1 -0
  166. package/dist/types/vultisig/index.d.ts +11 -0
  167. package/dist/types/vultisig/index.d.ts.map +1 -0
  168. package/dist/types/vultisig/walletHelpers.d.ts +34 -0
  169. package/dist/types/vultisig/walletHelpers.d.ts.map +1 -0
  170. package/dist/types/walletconnect/constants.d.ts +85 -0
  171. package/dist/types/walletconnect/constants.d.ts.map +1 -0
  172. package/dist/types/walletconnect/evmSigner.d.ts +25 -0
  173. package/dist/types/walletconnect/evmSigner.d.ts.map +1 -0
  174. package/dist/types/walletconnect/helpers.d.ts +4 -0
  175. package/dist/types/walletconnect/helpers.d.ts.map +1 -0
  176. package/dist/types/walletconnect/index.d.ts +22 -0
  177. package/dist/types/walletconnect/index.d.ts.map +1 -0
  178. package/dist/types/walletconnect/namespaces.d.ts +7 -0
  179. package/dist/types/walletconnect/namespaces.d.ts.map +1 -0
  180. package/dist/types/walletconnect/types.d.ts +7 -0
  181. package/dist/types/walletconnect/types.d.ts.map +1 -0
  182. package/dist/types/xaman/helpers.d.ts +54 -0
  183. package/dist/types/xaman/helpers.d.ts.map +1 -0
  184. package/dist/types/xaman/index.d.ts +14 -0
  185. package/dist/types/xaman/index.d.ts.map +1 -0
  186. package/dist/types/xaman/types.d.ts +24 -0
  187. package/dist/types/xaman/types.d.ts.map +1 -0
  188. package/dist/types/xaman/walletMethods.d.ts +16 -0
  189. package/dist/types/xaman/walletMethods.d.ts.map +1 -0
  190. package/package.json +53 -74
  191. package/dist/chunk-2aa1w78q.js +0 -4
  192. package/dist/chunk-2aa1w78q.js.map +0 -10
  193. package/dist/chunk-31bmhjxx.js +0 -4
  194. package/dist/chunk-31bmhjxx.js.map +0 -10
  195. package/dist/chunk-3etn0w20.js +0 -4
  196. package/dist/chunk-3etn0w20.js.map +0 -10
  197. package/dist/chunk-bk58smyr.js +0 -4
  198. package/dist/chunk-bk58smyr.js.map +0 -10
  199. package/dist/chunk-etm8zfkk.js +0 -4
  200. package/dist/chunk-etm8zfkk.js.map +0 -10
  201. package/dist/chunk-h7myvxxm.js +0 -5
  202. package/dist/chunk-h7myvxxm.js.map +0 -10
  203. package/dist/chunk-htvthkj1.js +0 -5
  204. package/dist/chunk-htvthkj1.js.map +0 -10
  205. package/dist/chunk-nfas79hz.js +0 -4
  206. package/dist/chunk-nfas79hz.js.map +0 -10
  207. package/dist/src/keepkey/index.cjs +0 -4
  208. package/dist/src/keepkey/index.cjs.map +0 -15
  209. package/dist/src/keepkey/index.js +0 -4
  210. package/dist/src/keepkey/index.js.map +0 -15
  211. package/dist/src/keystore/index.cjs +0 -4
  212. package/dist/src/keystore/index.cjs.map +0 -11
  213. package/dist/src/keystore/index.js +0 -4
  214. package/dist/src/keystore/index.js.map +0 -11
  215. package/dist/src/ledger/index.cjs +0 -5
  216. package/dist/src/ledger/index.cjs.map +0 -25
  217. package/dist/src/ledger/index.js +0 -5
  218. package/dist/src/ledger/index.js.map +0 -25
  219. package/dist/src/trezor/index.cjs +0 -4
  220. package/dist/src/trezor/index.cjs.map +0 -10
  221. package/dist/src/trezor/index.js +0 -4
  222. package/dist/src/trezor/index.js.map +0 -10
  223. package/src/bitget/helpers.ts +0 -167
  224. package/src/bitget/index.ts +0 -34
  225. package/src/coinbase/index.ts +0 -52
  226. package/src/coinbase/signer.ts +0 -83
  227. package/src/cosmostation/index.ts +0 -142
  228. package/src/ctrl/index.ts +0 -248
  229. package/src/ctrl/walletHelpers.ts +0 -297
  230. package/src/evm-extensions/index.ts +0 -134
  231. package/src/exodus/index.ts +0 -179
  232. package/src/helpers/near-browser-provider.d.ts +0 -286
  233. package/src/helpers/near.ts +0 -206
  234. package/src/index.ts +0 -2
  235. package/src/keepkey/chains/cosmos.ts +0 -78
  236. package/src/keepkey/chains/evm.ts +0 -125
  237. package/src/keepkey/chains/mayachain.ts +0 -123
  238. package/src/keepkey/chains/ripple.ts +0 -118
  239. package/src/keepkey/chains/thorchain.ts +0 -118
  240. package/src/keepkey/chains/utxo.ts +0 -147
  241. package/src/keepkey/coins.ts +0 -71
  242. package/src/keepkey/index.ts +0 -153
  243. package/src/keepkey-bex/index.ts +0 -162
  244. package/src/keepkey-bex/walletHelpers.ts +0 -255
  245. package/src/keplr/chainRegistry.ts +0 -211
  246. package/src/keplr/index.ts +0 -55
  247. package/src/keystore/helpers.ts +0 -102
  248. package/src/keystore/index.ts +0 -73
  249. package/src/ledger/clients/cosmos.ts +0 -102
  250. package/src/ledger/clients/evm.ts +0 -183
  251. package/src/ledger/clients/near.ts +0 -86
  252. package/src/ledger/clients/thorchain/common.ts +0 -117
  253. package/src/ledger/clients/thorchain/helpers.ts +0 -149
  254. package/src/ledger/clients/thorchain/index.ts +0 -94
  255. package/src/ledger/clients/thorchain/lib.ts +0 -300
  256. package/src/ledger/clients/thorchain/utils.ts +0 -76
  257. package/src/ledger/clients/tron.ts +0 -92
  258. package/src/ledger/clients/utxo.ts +0 -148
  259. package/src/ledger/clients/xrp.ts +0 -66
  260. package/src/ledger/cosmosTypes.ts +0 -101
  261. package/src/ledger/helpers/getLedgerAddress.ts +0 -67
  262. package/src/ledger/helpers/getLedgerClient.ts +0 -124
  263. package/src/ledger/helpers/getLedgerTransport.ts +0 -80
  264. package/src/ledger/helpers/index.ts +0 -3
  265. package/src/ledger/index.ts +0 -311
  266. package/src/ledger/interfaces/CosmosLedgerInterface.ts +0 -65
  267. package/src/ledger/types.ts +0 -45
  268. package/src/okx/helpers.ts +0 -181
  269. package/src/okx/index.ts +0 -43
  270. package/src/okx/types.ts +0 -117
  271. package/src/onekey/evmSigner.ts +0 -133
  272. package/src/onekey/index.ts +0 -213
  273. package/src/phantom/index.ts +0 -126
  274. package/src/polkadotjs/index.ts +0 -67
  275. package/src/radix/index.ts +0 -202
  276. package/src/talisman/index.ts +0 -130
  277. package/src/trezor/evmSigner.ts +0 -197
  278. package/src/trezor/index.ts +0 -260
  279. package/src/types.ts +0 -280
  280. package/src/utils.ts +0 -60
  281. package/src/vultisig/index.ts +0 -199
  282. package/src/vultisig/walletHelpers.ts +0 -359
  283. package/src/walletconnect/constants.ts +0 -104
  284. package/src/walletconnect/evmSigner.ts +0 -147
  285. package/src/walletconnect/helpers.ts +0 -77
  286. package/src/walletconnect/index.ts +0 -460
  287. package/src/walletconnect/namespaces.ts +0 -87
  288. package/src/walletconnect/types.ts +0 -6
  289. package/src/xaman/README.md +0 -66
  290. package/src/xaman/helpers.ts +0 -59
  291. package/src/xaman/index.ts +0 -79
  292. package/src/xaman/types.ts +0 -26
  293. package/src/xaman/walletMethods.ts +0 -126
  294. /package/dist/{chunk-mvbb9fwb.js.map → chunk-sbf0f2p4.js.map} +0 -0
@@ -1,300 +0,0 @@
1
- import type Transport from "@ledgerhq/hw-transport";
2
- import { SwapKitError } from "@swapkit/helpers";
3
- /** ******************************************************************************
4
- * (c) 2019 ZondaX GmbH
5
- * (c) 2016-2017 Ledger
6
- *
7
- * Licensed under the Apache License, Version 2.0 (the "License");
8
- * you may not use this file except in compliance with the License.
9
- * You may obtain a copy of the License at
10
- *
11
- * http://www.apache.org/licenses/LICENSE-2.0
12
- *
13
- * Unless required by applicable law or agreed to in writing, software
14
- * distributed under the License is distributed on an "AS IS" BASIS,
15
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- * See the License for the specific language governing permissions and
17
- * limitations under the License.
18
- ******************************************************************************* */
19
-
20
- import {
21
- CHUNK_SIZE,
22
- CLA,
23
- ERROR_CODE,
24
- INS,
25
- P1_VALUES,
26
- P2_VALUES,
27
- errorCodeToString,
28
- getVersion,
29
- processErrorResponse,
30
- } from "./common";
31
- import {
32
- publicKeyv1,
33
- publicKeyv2,
34
- serializePathv1,
35
- serializePathv2,
36
- signSendChunkv1,
37
- signSendChunkv2,
38
- } from "./helpers";
39
-
40
- export class THORChainApp {
41
- transport: Transport;
42
- versionResponse: any;
43
-
44
- constructor(transport: any) {
45
- if (!transport) {
46
- throw new SwapKitError("wallet_ledger_transport_not_defined");
47
- }
48
-
49
- this.transport = transport;
50
- }
51
-
52
- static serializeHRP(hrp: string) {
53
- if (hrp == null || hrp.length < 3 || hrp.length > 83) {
54
- throw new SwapKitError("wallet_ledger_invalid_params", { reason: "Invalid HRP" });
55
- }
56
- const buf = Buffer.alloc(1 + hrp.length);
57
- buf.writeUInt8(hrp.length, 0);
58
- buf.write(hrp, 1);
59
- return buf;
60
- }
61
-
62
- async serializePath(path: number[]) {
63
- this.versionResponse = await getVersion(this.transport);
64
-
65
- if (this.versionResponse.return_code !== ERROR_CODE.NoError) {
66
- throw this.versionResponse;
67
- }
68
-
69
- switch (this.versionResponse.major) {
70
- case 1:
71
- return serializePathv1(path);
72
- case 2:
73
- return serializePathv2(path);
74
- default:
75
- return Buffer.alloc(0);
76
- }
77
- }
78
-
79
- async signGetChunks(path: number[], buffer: Buffer) {
80
- const serializedPath = await this.serializePath(path);
81
-
82
- const chunks = [];
83
- chunks.push(serializedPath);
84
-
85
- for (let i = 0; i < buffer.length; i += CHUNK_SIZE) {
86
- let end = i + CHUNK_SIZE;
87
- if (i > buffer.length) {
88
- end = buffer.length;
89
- }
90
- chunks.push(buffer.slice(i, end));
91
- }
92
-
93
- return chunks;
94
- }
95
-
96
- async getVersion() {
97
- try {
98
- this.versionResponse = await getVersion(this.transport);
99
- return this.versionResponse;
100
- } catch (e) {
101
- return processErrorResponse(e);
102
- }
103
- }
104
-
105
- async appInfo() {
106
- return this.transport.send(0xb0, 0x01, 0, 0).then((response: any) => {
107
- const errorCodeData = response.slice(-2);
108
- const returnCode = errorCodeData[0] * 256 + errorCodeData[1];
109
-
110
- let appName = "";
111
- let appVersion = "";
112
- let flagLen = 0;
113
- let flagsValue = 0;
114
-
115
- if (response[0] !== 1) {
116
- // Ledger responds with format ID 1. There is no spec for any format != 1
117
- return {
118
- return_code: 0x9001,
119
- error_message: "response format ID not recognized",
120
- };
121
- }
122
-
123
- const appNameLen = response[1];
124
- appName = response.slice(2, 2 + appNameLen).toString("ascii");
125
- let idx = 2 + appNameLen;
126
- const appVersionLen = response[idx];
127
- idx += 1;
128
- appVersion = response.slice(idx, idx + appVersionLen).toString("ascii");
129
- idx += appVersionLen;
130
- const appFlagsLen = response[idx];
131
- idx += 1;
132
- flagLen = appFlagsLen;
133
- flagsValue = response[idx];
134
-
135
- return {
136
- return_code: returnCode,
137
- error_message: errorCodeToString(returnCode),
138
- appName,
139
- appVersion,
140
- flagLen,
141
- flagsValue,
142
- flag_recovery: (flagsValue & 1) !== 0,
143
- flag_signed_mcu_code: (flagsValue & 2) !== 0,
144
- flag_onboarded: (flagsValue & 4) !== 0,
145
- flag_pin_validated: (flagsValue & 128) !== 0,
146
- };
147
- }, processErrorResponse);
148
- }
149
-
150
- async deviceInfo() {
151
- return this.transport
152
- .send(0xe0, 0x01, 0, 0, Buffer.from([]), [ERROR_CODE.NoError, 0x6e00])
153
- .then((response: any) => {
154
- const errorCodeData = response.slice(-2);
155
- const returnCode = errorCodeData[0] * 256 + errorCodeData[1];
156
-
157
- if (returnCode === 0x6e00) {
158
- return {
159
- return_code: returnCode,
160
- error_message: "This command is only available in the Dashboard",
161
- };
162
- }
163
-
164
- const targetId = response.slice(0, 4).toString("hex");
165
-
166
- let pos = 4;
167
- const secureElementVersionLen = response[pos];
168
- pos += 1;
169
- const seVersion = response.slice(pos, pos + secureElementVersionLen).toString();
170
- pos += secureElementVersionLen;
171
-
172
- const flagsLen = response[pos];
173
- pos += 1;
174
- const flag = response.slice(pos, pos + flagsLen).toString("hex");
175
- pos += flagsLen;
176
-
177
- const mcuVersionLen = response[pos];
178
- pos += 1;
179
- // Patch issue in mcu version
180
- let tmp = response.slice(pos, pos + mcuVersionLen);
181
- if (tmp[mcuVersionLen - 1] === 0) {
182
- tmp = response.slice(pos, pos + mcuVersionLen - 1);
183
- }
184
- const mcuVersion = tmp.toString();
185
-
186
- return {
187
- return_code: returnCode,
188
- error_message: errorCodeToString(returnCode),
189
- // //
190
- targetId,
191
- seVersion,
192
- flag,
193
- mcuVersion,
194
- };
195
- }, processErrorResponse);
196
- }
197
-
198
- async publicKey(path: number[]) {
199
- try {
200
- const serializedPath = await this.serializePath(path);
201
-
202
- switch (this.versionResponse.major) {
203
- case 1:
204
- return publicKeyv1(this, serializedPath);
205
- case 2: {
206
- // @ts-ignore
207
- const data = Buffer.concat([THORChainApp.serializeHRP("thor"), serializedPath]);
208
- return publicKeyv2(this, data);
209
- }
210
- default:
211
- return {
212
- return_code: 0x6400,
213
- error_message: "App Version is not supported",
214
- };
215
- }
216
- } catch (e) {
217
- return processErrorResponse(e);
218
- }
219
- }
220
-
221
- async getAddressAndPubKey(path: number[], hrp: string, showInDevice = false) {
222
- return this.serializePath(path)
223
- .then((serializedPath: Buffer) => {
224
- // @ts-ignore
225
- const data = Buffer.concat([THORChainApp.serializeHRP(hrp), serializedPath]);
226
- return this.transport
227
- .send(
228
- CLA,
229
- INS.GET_ADDR_SECP256K1,
230
- showInDevice ? P1_VALUES.SHOW_ADDRESS_IN_DEVICE : P1_VALUES.ONLY_RETRIEVE,
231
- 0,
232
- data,
233
- [ERROR_CODE.NoError],
234
- )
235
- .then((response: any) => {
236
- const errorCodeData = response.slice(-2);
237
- const returnCode = errorCodeData[0] * 256 + errorCodeData[1];
238
-
239
- const compressedPk = Buffer.from(response.slice(0, 33));
240
- const bech32Address = Buffer.from(response.slice(33, -2)).toString();
241
-
242
- return {
243
- bech32_address: bech32Address,
244
- compressed_pk: compressedPk,
245
- return_code: returnCode,
246
- error_message: errorCodeToString(returnCode),
247
- };
248
- }, processErrorResponse);
249
- })
250
- .catch((err) => processErrorResponse(err));
251
- }
252
-
253
- showAddressAndPubKey(path: number[], hrp: string) {
254
- return this.getAddressAndPubKey(path, hrp, true);
255
- }
256
-
257
- signSendChunk(chunkIdx: number, chunkNum: number, chunk: Buffer, txType = P2_VALUES.JSON) {
258
- switch (this.versionResponse.major) {
259
- case 1:
260
- return signSendChunkv1(this, chunkIdx, chunkNum, chunk, txType);
261
- case 2:
262
- return signSendChunkv2(this, chunkIdx, chunkNum, chunk, txType);
263
- default:
264
- return {
265
- return_code: 0x6400,
266
- error_message: "App Version is not supported",
267
- };
268
- }
269
- }
270
-
271
- async sign(path: number[], message: string, txType = P2_VALUES.JSON) {
272
- const buffer = Buffer.from(message);
273
- let chunks: Buffer[] = [];
274
- let response: any;
275
- try {
276
- chunks = await this.signGetChunks(path, buffer);
277
- response = await this.signSendChunk(1, chunks.length, chunks[0] as Buffer, txType);
278
- } catch (error) {
279
- processErrorResponse(error);
280
- }
281
- let result = {
282
- return_code: response.return_code,
283
- error_message: response.error_message,
284
- signature: null,
285
- };
286
-
287
- for (let i = 1; i < chunks.length; i += 1) {
288
- result = await this.signSendChunk(1 + i, chunks.length, chunks[i] as Buffer, txType);
289
- if (result.return_code !== ERROR_CODE.NoError) {
290
- break;
291
- }
292
- }
293
-
294
- return {
295
- return_code: result.return_code,
296
- error_message: result.error_message,
297
- signature: result.signature,
298
- };
299
- }
300
- }
@@ -1,76 +0,0 @@
1
- import { base64 } from "@scure/base";
2
- import { SwapKitError } from "@swapkit/helpers";
3
-
4
- // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: any: refactor
5
- export const getSignature = (signatureArray: any) => {
6
- // Check Type Length Value encoding
7
- if (signatureArray.length < 64) {
8
- throw new SwapKitError("wallet_ledger_invalid_signature", { reason: "Too short" });
9
- }
10
- if (signatureArray[0] !== 0x30) {
11
- throw new SwapKitError("wallet_ledger_invalid_signature", {
12
- reason: "TLV encoding: expected first byte 0x30",
13
- });
14
- }
15
- if (signatureArray[1] + 2 !== signatureArray.length) {
16
- throw new SwapKitError("wallet_ledger_invalid_signature", {
17
- reason: "signature length does not match TLV",
18
- });
19
- }
20
- if (signatureArray[2] !== 0x02) {
21
- throw new SwapKitError("wallet_ledger_invalid_signature", {
22
- reason: "TLV encoding: expected length type 0x02",
23
- });
24
- }
25
-
26
- // r signature
27
- const rLength = signatureArray[3];
28
- let rSignature = signatureArray.slice(4, rLength + 4);
29
-
30
- // Drop leading zero on some 'r' signatures that are 33 bytes.
31
- if (rSignature.length === 33 && rSignature[0] === 0) {
32
- rSignature = rSignature.slice(1, 33);
33
- } else if (rSignature.length === 33) {
34
- throw new SwapKitError("wallet_ledger_invalid_signature", { reason: "r too long" });
35
- }
36
-
37
- // add leading zero's to pad to 32 bytes
38
- while (rSignature.length < 32) {
39
- rSignature.unshift(0);
40
- }
41
-
42
- // s signature
43
- if (signatureArray[rLength + 4] !== 0x02) {
44
- throw new SwapKitError("wallet_ledger_invalid_signature", {
45
- reason: "TLV encoding: expected length type 0x02 for s",
46
- });
47
- }
48
-
49
- const sLength = signatureArray[rLength + 5];
50
-
51
- if (4 + rLength + 2 + sLength !== signatureArray.length) {
52
- throw new SwapKitError("wallet_ledger_invalid_signature", {
53
- reason: "TLV byte lengths do not match message length",
54
- });
55
- }
56
-
57
- let sSignature = signatureArray.slice(rLength + 6, signatureArray.length);
58
-
59
- // Drop leading zero on 's' signatures that are 33 bytes. This shouldn't occur since ledger signs using "Small s" math. But just to be sure...
60
- if (sSignature.length === 33 && sSignature[0] === 0) {
61
- sSignature = sSignature.slice(1, 33);
62
- } else if (sSignature.length === 33) {
63
- throw new SwapKitError("wallet_ledger_invalid_signature", { reason: "s too long" });
64
- }
65
-
66
- // add leading zero's to pad to 32 bytes
67
- while (sSignature.length < 32) {
68
- sSignature.unshift(0);
69
- }
70
-
71
- if (rSignature.length !== 32 || sSignature.length !== 32) {
72
- throw new SwapKitError("wallet_ledger_invalid_signature", { reason: "must be 32 bytes each" });
73
- }
74
-
75
- return base64.encode(Buffer.concat([rSignature, sSignature]));
76
- };
@@ -1,92 +0,0 @@
1
- import type TronApp from "@ledgerhq/hw-app-trx";
2
- import {
3
- type DerivationPathArray,
4
- NetworkDerivationPath,
5
- SwapKitError,
6
- derivationPathToString,
7
- } from "@swapkit/helpers";
8
- import type { TronSigner, TronTransaction } from "@swapkit/toolboxes/tron";
9
-
10
- import { getLedgerTransport } from "../helpers/getLedgerTransport";
11
-
12
- export class TronLedgerInterface implements TronSigner {
13
- derivationPath: string;
14
- ledgerApp: InstanceType<typeof TronApp> | null = null;
15
- ledgerTimeout = 50000;
16
-
17
- constructor(derivationPath?: DerivationPathArray | string) {
18
- this.derivationPath =
19
- typeof derivationPath === "string"
20
- ? derivationPath
21
- : derivationPathToString(derivationPath || NetworkDerivationPath.TRX);
22
- }
23
-
24
- checkOrCreateTransportAndLedger = async () => {
25
- if (this.ledgerApp) return;
26
- await this.createTransportAndLedger();
27
- };
28
-
29
- createTransportAndLedger = async () => {
30
- const transport = await getLedgerTransport();
31
- const TronApp = (await import("@ledgerhq/hw-app-trx")).default;
32
-
33
- this.ledgerApp = new TronApp(transport);
34
- };
35
-
36
- getAddress = async (): Promise<string> => {
37
- const response = await this.getAddressAndPubKey();
38
- if (!response) throw new SwapKitError("wallet_ledger_failed_to_get_address");
39
- return response.address;
40
- };
41
-
42
- getAddressAndPubKey = async () => {
43
- await this.createTransportAndLedger();
44
- const result = await this.ledgerApp?.getAddress(this.derivationPath);
45
-
46
- if (!result) throw new SwapKitError("wallet_ledger_failed_to_get_address");
47
-
48
- return {
49
- address: result.address,
50
- publicKey: result.publicKey,
51
- };
52
- };
53
-
54
- showAddressAndPubKey = async () => {
55
- await this.createTransportAndLedger();
56
- return this.ledgerApp?.getAddress(this.derivationPath, true);
57
- };
58
-
59
- signTransaction = async (transaction: TronTransaction) => {
60
- await this.createTransportAndLedger();
61
-
62
- if (!this.ledgerApp) {
63
- throw new SwapKitError("wallet_ledger_transport_error");
64
- }
65
-
66
- // Tron transactions need to be serialized before signing
67
- const serializedTx = JSON.stringify(transaction);
68
-
69
- try {
70
- const signature = await this.ledgerApp.signTransaction(
71
- this.derivationPath,
72
- serializedTx,
73
- [], // Token signatures array - empty for native TRX transfers
74
- );
75
-
76
- if (!signature) {
77
- throw new SwapKitError("wallet_ledger_signing_error");
78
- }
79
-
80
- // Return the signed transaction in Tron's expected format
81
- return {
82
- ...transaction,
83
- signature: [signature],
84
- };
85
- } catch (error) {
86
- throw new SwapKitError("wallet_ledger_signing_error", { error });
87
- }
88
- };
89
- }
90
-
91
- export const TronLedger = (derivationPath?: DerivationPathArray) =>
92
- new TronLedgerInterface(derivationPath);
@@ -1,148 +0,0 @@
1
- import type BitcoinApp from "@ledgerhq/hw-app-btc";
2
- import type { CreateTransactionArg } from "@ledgerhq/hw-app-btc/lib-es/createTransaction";
3
- import {
4
- type DerivationPathArray,
5
- SwapKitError,
6
- derivationPathToString,
7
- getWalletFormatFor,
8
- } from "@swapkit/helpers";
9
- import type { UTXOType } from "@swapkit/toolboxes/utxo";
10
- import { type Psbt, Transaction } from "bitcoinjs-lib";
11
-
12
- import { getLedgerTransport } from "../helpers/getLedgerTransport";
13
-
14
- type Params = {
15
- psbt: Psbt;
16
- inputUtxos: UTXOType[];
17
- btcApp: any;
18
- derivationPath: string;
19
- };
20
-
21
- const signUTXOTransaction = async (
22
- { psbt, inputUtxos, btcApp, derivationPath }: Params,
23
- options?: Partial<CreateTransactionArg>,
24
- ) => {
25
- const inputs = inputUtxos.map((item) => {
26
- const utxoTx = Transaction.fromHex(item.txHex || "");
27
- const splitTx = btcApp.splitTransaction(utxoTx.toHex(), utxoTx.hasWitnesses());
28
-
29
- return [
30
- splitTx,
31
- item.index,
32
- undefined as string | null | undefined,
33
- undefined as number | null | undefined,
34
- ] as any;
35
- });
36
-
37
- const newTxHex = psbt.data.globalMap.unsignedTx.toBuffer().toString("hex");
38
-
39
- const splitNewTx = btcApp.splitTransaction(newTxHex, true);
40
- const outputScriptHex = btcApp.serializeTransactionOutputs(splitNewTx).toString("hex");
41
-
42
- const params: CreateTransactionArg = {
43
- additionals: ["bech32"],
44
- associatedKeysets: inputs.map(() => derivationPath),
45
- inputs,
46
- outputScriptHex,
47
- segwit: true,
48
- useTrustedInputForSegwit: true,
49
- };
50
-
51
- return btcApp.createPaymentTransaction({ ...params, ...options });
52
- };
53
-
54
- const BaseLedgerUTXO = ({
55
- chain,
56
- additionalSignParams,
57
- }: {
58
- chain: "bitcoin-cash" | "bitcoin" | "litecoin" | "dogecoin" | "dash";
59
- additionalSignParams?: Partial<CreateTransactionArg>;
60
- }) => {
61
- let btcApp: InstanceType<typeof BitcoinApp>;
62
- let transport: any = null;
63
-
64
- async function checkBtcAppAndCreateTransportWebUSB(checkBtcApp = true) {
65
- if (checkBtcApp && !btcApp) {
66
- new SwapKitError("wallet_ledger_connection_error", {
67
- message: `Ledger connection failed:\n${JSON.stringify({ checkBtcApp, btcApp })}`,
68
- });
69
- }
70
-
71
- transport ||= await getLedgerTransport();
72
- }
73
-
74
- async function createTransportWebUSB() {
75
- transport = await getLedgerTransport();
76
- const BitcoinApp = (await import("@ledgerhq/hw-app-btc")).default;
77
-
78
- btcApp = new BitcoinApp({ transport, currency: chain });
79
- }
80
-
81
- return (derivationPathArray?: DerivationPathArray | string) => {
82
- const derivationPath =
83
- typeof derivationPathArray === "string"
84
- ? derivationPathArray
85
- : derivationPathToString(derivationPathArray as DerivationPathArray);
86
-
87
- const format = getWalletFormatFor(derivationPath);
88
-
89
- return {
90
- connect: async () => {
91
- await checkBtcAppAndCreateTransportWebUSB(false);
92
- const BitcoinApp = (await import("@ledgerhq/hw-app-btc")).default;
93
-
94
- btcApp = new BitcoinApp({ transport, currency: chain });
95
- },
96
- getExtendedPublicKey: async (path = "84'/0'/0'", xpubVersion = 76067358) => {
97
- await checkBtcAppAndCreateTransportWebUSB(false);
98
-
99
- return btcApp.getWalletXpub({ path, xpubVersion });
100
- },
101
- signTransaction: async (psbt: Psbt, inputUtxos: UTXOType[]) => {
102
- await createTransportWebUSB();
103
-
104
- return signUTXOTransaction(
105
- { psbt, derivationPath, btcApp, inputUtxos },
106
- additionalSignParams,
107
- );
108
- },
109
- getAddress: async () => {
110
- const { toCashAddress } = await import("@swapkit/toolboxes/utxo");
111
-
112
- await checkBtcAppAndCreateTransportWebUSB(false);
113
-
114
- const { bitcoinAddress: address } = await btcApp.getWalletPublicKey(derivationPath, {
115
- format,
116
- });
117
-
118
- if (!address) {
119
- throw new SwapKitError("wallet_ledger_get_address_error", {
120
- message: `Cannot get ${chain} address from ledger derivation path: ${derivationPath}`,
121
- });
122
- }
123
-
124
- return chain === "bitcoin-cash" && format === "legacy"
125
- ? toCashAddress(address).replace(/(bchtest:|bitcoincash:)/, "")
126
- : address;
127
- },
128
- };
129
- };
130
- };
131
-
132
- export const BitcoinLedger = BaseLedgerUTXO({ chain: "bitcoin" });
133
- export const LitecoinLedger = BaseLedgerUTXO({ chain: "litecoin" });
134
-
135
- export const BitcoinCashLedger = BaseLedgerUTXO({
136
- chain: "bitcoin-cash",
137
- additionalSignParams: { segwit: false, additionals: ["abc"], sigHashType: 0x41 },
138
- });
139
-
140
- export const DogecoinLedger = BaseLedgerUTXO({
141
- chain: "dogecoin",
142
- additionalSignParams: { additionals: [], segwit: false, useTrustedInputForSegwit: false },
143
- });
144
-
145
- export const DashLedger = BaseLedgerUTXO({
146
- chain: "dash",
147
- additionalSignParams: { additionals: [], segwit: false, useTrustedInputForSegwit: false },
148
- });
@@ -1,66 +0,0 @@
1
- import type Xrp from "@ledgerhq/hw-app-xrp";
2
- import type Transport from "@ledgerhq/hw-transport";
3
- import {
4
- Chain,
5
- type DerivationPathArray,
6
- NetworkDerivationPath,
7
- derivationPathToString,
8
- } from "@swapkit/helpers";
9
- import type { Transaction } from "@swapkit/toolboxes/ripple";
10
- import { encode } from "ripple-binary-codec";
11
- import type { Payment } from "xrpl";
12
- import { getLedgerTransport } from "../helpers";
13
-
14
- const TF_FULLY_CANONICAL_SIG = 2147483648;
15
-
16
- function cleanTransactionObject(obj: Record<string, any>) {
17
- const cleaned: Record<string, any> = {};
18
- for (const key in obj) {
19
- if (obj[key] !== null && obj[key] !== undefined) {
20
- cleaned[key] = obj[key];
21
- }
22
- }
23
- return cleaned;
24
- }
25
-
26
- async function establishConnection(transport: Transport) {
27
- const { default: Xrp } = await import("@ledgerhq/hw-app-xrp");
28
- return new Xrp(transport);
29
- }
30
-
31
- function fetchAddressAndPublicKey({
32
- instance,
33
- derivationPath,
34
- }: { instance: Xrp; derivationPath: string }) {
35
- return instance.getAddress(derivationPath);
36
- }
37
-
38
- export const XRPLedger = async (derivationPath?: DerivationPathArray) => {
39
- const path = derivationPathToString(derivationPath || NetworkDerivationPath[Chain.Ripple]);
40
- const transport = await getLedgerTransport();
41
- const xrpInstance = await establishConnection(transport);
42
-
43
- const { address, publicKey } = await fetchAddressAndPublicKey({
44
- instance: xrpInstance,
45
- derivationPath: path,
46
- });
47
-
48
- async function sign(transaction: Payment | Transaction) {
49
- const { hashes } = await import("@swapkit/toolboxes/ripple");
50
- const cleanedTxWithPubKey = cleanTransactionObject(transaction);
51
- const transactionJSON = {
52
- ...cleanedTxWithPubKey,
53
- Flags: transaction.Flags || TF_FULLY_CANONICAL_SIG,
54
- SigningPubKey: publicKey.toUpperCase(),
55
- };
56
-
57
- const transactionToSignOnLedger = encode(transactionJSON);
58
- const txnSignature = await xrpInstance.signTransaction(path, transactionToSignOnLedger);
59
- const tx_blob = encode({ ...transactionJSON, TxnSignature: txnSignature });
60
- const hash = hashes.hashSignedTx(tx_blob);
61
-
62
- return { tx_blob, hash };
63
- }
64
-
65
- return { address, sign };
66
- };