@trezor/connect 9.0.0-beta.1

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 (495) hide show
  1. package/LICENSE.md +50 -0
  2. package/README.md +38 -0
  3. package/lib/api/applyFlags.d.ts +8 -0
  4. package/lib/api/applyFlags.js +37 -0
  5. package/lib/api/applySettings.d.ts +8 -0
  6. package/lib/api/applySettings.js +57 -0
  7. package/lib/api/authorizeCoinJoin.d.ts +7 -0
  8. package/lib/api/authorizeCoinJoin.js +45 -0
  9. package/lib/api/backupDevice.d.ts +7 -0
  10. package/lib/api/backupDevice.js +31 -0
  11. package/lib/api/binance/binanceSignTx.d.ts +6 -0
  12. package/lib/api/binance/binanceSignTx.js +91 -0
  13. package/lib/api/binanceGetAddress.d.ts +22 -0
  14. package/lib/api/binanceGetAddress.js +126 -0
  15. package/lib/api/binanceGetPublicKey.d.ts +10 -0
  16. package/lib/api/binanceGetPublicKey.js +72 -0
  17. package/lib/api/binanceSignTransaction.d.ts +12 -0
  18. package/lib/api/binanceSignTransaction.js +31 -0
  19. package/lib/api/bitcoin/Fees.d.ts +15 -0
  20. package/lib/api/bitcoin/Fees.js +175 -0
  21. package/lib/api/bitcoin/TransactionComposer.d.ts +36 -0
  22. package/lib/api/bitcoin/TransactionComposer.js +150 -0
  23. package/lib/api/bitcoin/__fixtures__/inputs.d.ts +112 -0
  24. package/lib/api/bitcoin/__fixtures__/inputs.js +102 -0
  25. package/lib/api/bitcoin/__fixtures__/signtxVerify.d.ts +147 -0
  26. package/lib/api/bitcoin/__fixtures__/signtxVerify.js +216 -0
  27. package/lib/api/bitcoin/enhanceSignTx.d.ts +4 -0
  28. package/lib/api/bitcoin/enhanceSignTx.js +63 -0
  29. package/lib/api/bitcoin/index.d.ts +10 -0
  30. package/lib/api/bitcoin/index.js +13 -0
  31. package/lib/api/bitcoin/inputs.d.ts +8 -0
  32. package/lib/api/bitcoin/inputs.js +60 -0
  33. package/lib/api/bitcoin/outputs.d.ts +8 -0
  34. package/lib/api/bitcoin/outputs.js +115 -0
  35. package/lib/api/bitcoin/refTx.d.ts +11 -0
  36. package/lib/api/bitcoin/refTx.js +220 -0
  37. package/lib/api/bitcoin/signtx.d.ts +25 -0
  38. package/lib/api/bitcoin/signtx.js +164 -0
  39. package/lib/api/bitcoin/signtxLegacy.d.ts +4 -0
  40. package/lib/api/bitcoin/signtxLegacy.js +136 -0
  41. package/lib/api/bitcoin/signtxVerify.d.ts +8 -0
  42. package/lib/api/bitcoin/signtxVerify.js +130 -0
  43. package/lib/api/blockchainDisconnect.d.ts +13 -0
  44. package/lib/api/blockchainDisconnect.js +34 -0
  45. package/lib/api/blockchainEstimateFee.d.ts +12 -0
  46. package/lib/api/blockchainEstimateFee.js +70 -0
  47. package/lib/api/blockchainGetAccountBalanceHistory.d.ts +12 -0
  48. package/lib/api/blockchainGetAccountBalanceHistory.js +41 -0
  49. package/lib/api/blockchainGetCurrentFiatRates.d.ts +15 -0
  50. package/lib/api/blockchainGetCurrentFiatRates.js +33 -0
  51. package/lib/api/blockchainGetFiatRatesForTimestamps.d.ts +17 -0
  52. package/lib/api/blockchainGetFiatRatesForTimestamps.js +33 -0
  53. package/lib/api/blockchainGetTransactions.d.ts +12 -0
  54. package/lib/api/blockchainGetTransactions.js +33 -0
  55. package/lib/api/blockchainSetCustomBackend.d.ts +11 -0
  56. package/lib/api/blockchainSetCustomBackend.js +38 -0
  57. package/lib/api/blockchainSubscribe.d.ts +14 -0
  58. package/lib/api/blockchainSubscribe.js +38 -0
  59. package/lib/api/blockchainSubscribeFiatRates.d.ts +14 -0
  60. package/lib/api/blockchainSubscribeFiatRates.js +33 -0
  61. package/lib/api/blockchainUnsubscribe.d.ts +14 -0
  62. package/lib/api/blockchainUnsubscribe.js +38 -0
  63. package/lib/api/blockchainUnsubscribeFiatRates.d.ts +13 -0
  64. package/lib/api/blockchainUnsubscribeFiatRates.js +29 -0
  65. package/lib/api/cardano/cardanoAddressParameters.d.ts +8 -0
  66. package/lib/api/cardano/cardanoAddressParameters.js +100 -0
  67. package/lib/api/cardano/cardanoAuxiliaryData.d.ts +6 -0
  68. package/lib/api/cardano/cardanoAuxiliaryData.js +51 -0
  69. package/lib/api/cardano/cardanoCertificate.d.ts +14 -0
  70. package/lib/api/cardano/cardanoCertificate.js +149 -0
  71. package/lib/api/cardano/cardanoInputs.d.ts +13 -0
  72. package/lib/api/cardano/cardanoInputs.js +34 -0
  73. package/lib/api/cardano/cardanoOutputs.d.ts +8 -0
  74. package/lib/api/cardano/cardanoOutputs.js +38 -0
  75. package/lib/api/cardano/cardanoTokenBundle.d.ts +8 -0
  76. package/lib/api/cardano/cardanoTokenBundle.js +36 -0
  77. package/lib/api/cardano/cardanoWitnesses.d.ts +5 -0
  78. package/lib/api/cardano/cardanoWitnesses.js +48 -0
  79. package/lib/api/cardanoGetAddress.d.ts +23 -0
  80. package/lib/api/cardanoGetAddress.js +158 -0
  81. package/lib/api/cardanoGetNativeScriptHash.d.ts +12 -0
  82. package/lib/api/cardanoGetNativeScriptHash.js +79 -0
  83. package/lib/api/cardanoGetPublicKey.d.ts +10 -0
  84. package/lib/api/cardanoGetPublicKey.js +78 -0
  85. package/lib/api/cardanoSignTransaction.d.ts +48 -0
  86. package/lib/api/cardanoSignTransaction.js +283 -0
  87. package/lib/api/changePin.d.ts +7 -0
  88. package/lib/api/changePin.js +22 -0
  89. package/lib/api/cipherKeyValue.d.ts +8 -0
  90. package/lib/api/cipherKeyValue.js +56 -0
  91. package/lib/api/common/Discovery.d.ts +35 -0
  92. package/lib/api/common/Discovery.js +113 -0
  93. package/lib/api/common/__fixtures__/paramsValidator.d.ts +596 -0
  94. package/lib/api/common/__fixtures__/paramsValidator.js +355 -0
  95. package/lib/api/common/paramsValidator.d.ts +14 -0
  96. package/lib/api/common/paramsValidator.js +140 -0
  97. package/lib/api/composeTransaction.d.ts +33 -0
  98. package/lib/api/composeTransaction.js +270 -0
  99. package/lib/api/customMessage.d.ts +13 -0
  100. package/lib/api/customMessage.js +56 -0
  101. package/lib/api/eos/eosSignTx.d.ts +17 -0
  102. package/lib/api/eos/eosSignTx.js +347 -0
  103. package/lib/api/eosGetPublicKey.d.ts +10 -0
  104. package/lib/api/eosGetPublicKey.js +73 -0
  105. package/lib/api/eosSignTransaction.d.ts +16 -0
  106. package/lib/api/eosSignTransaction.js +36 -0
  107. package/lib/api/ethereum/__fixtures__/ethereumSignTypedData.d.ts +225 -0
  108. package/lib/api/ethereum/__fixtures__/ethereumSignTypedData.js +341 -0
  109. package/lib/api/ethereum/ethereumSignTx.d.ts +13 -0
  110. package/lib/api/ethereum/ethereumSignTx.js +92 -0
  111. package/lib/api/ethereum/ethereumSignTypedData.d.ts +9 -0
  112. package/lib/api/ethereum/ethereumSignTypedData.js +120 -0
  113. package/lib/api/ethereumGetAddress.d.ts +28 -0
  114. package/lib/api/ethereumGetAddress.js +133 -0
  115. package/lib/api/ethereumGetPublicKey.d.ts +15 -0
  116. package/lib/api/ethereumGetPublicKey.js +79 -0
  117. package/lib/api/ethereumSignMessage.d.ts +7 -0
  118. package/lib/api/ethereumSignMessage.js +41 -0
  119. package/lib/api/ethereumSignTransaction.d.ts +20 -0
  120. package/lib/api/ethereumSignTransaction.js +82 -0
  121. package/lib/api/ethereumSignTypedData.d.ts +14 -0
  122. package/lib/api/ethereumSignTypedData.js +151 -0
  123. package/lib/api/ethereumVerifyMessage.d.ts +7 -0
  124. package/lib/api/ethereumVerifyMessage.js +34 -0
  125. package/lib/api/firmware/getBinary.d.ts +20 -0
  126. package/lib/api/firmware/getBinary.js +37 -0
  127. package/lib/api/firmware/modifyFirmware.d.ts +6 -0
  128. package/lib/api/firmware/modifyFirmware.js +18 -0
  129. package/lib/api/firmwareUpdate.d.ts +15 -0
  130. package/lib/api/firmwareUpdate.js +89 -0
  131. package/lib/api/getAccountInfo.d.ts +98 -0
  132. package/lib/api/getAccountInfo.js +326 -0
  133. package/lib/api/getAddress.d.ts +28 -0
  134. package/lib/api/getAddress.js +152 -0
  135. package/lib/api/getCoinInfo.d.ts +11 -0
  136. package/lib/api/getCoinInfo.js +27 -0
  137. package/lib/api/getDeviceState.d.ts +8 -0
  138. package/lib/api/getDeviceState.js +15 -0
  139. package/lib/api/getFeatures.d.ts +6 -0
  140. package/lib/api/getFeatures.js +18 -0
  141. package/lib/api/getOwnershipId.d.ts +10 -0
  142. package/lib/api/getOwnershipId.js +75 -0
  143. package/lib/api/getOwnershipProof.d.ts +14 -0
  144. package/lib/api/getOwnershipProof.js +86 -0
  145. package/lib/api/getPublicKey.d.ts +15 -0
  146. package/lib/api/getPublicKey.js +84 -0
  147. package/lib/api/getSettings.d.ts +6 -0
  148. package/lib/api/getSettings.js +16 -0
  149. package/lib/api/index.d.ts +64 -0
  150. package/lib/api/index.js +134 -0
  151. package/lib/api/management/uploadFirmware.d.ts +6 -0
  152. package/lib/api/management/uploadFirmware.js +49 -0
  153. package/lib/api/nem/nemSignTx.d.ts +4 -0
  154. package/lib/api/nem/nemSignTx.js +139 -0
  155. package/lib/api/nemGetAddress.d.ts +22 -0
  156. package/lib/api/nemGetAddress.js +144 -0
  157. package/lib/api/nemSignTransaction.d.ts +7 -0
  158. package/lib/api/nemSignTransaction.js +29 -0
  159. package/lib/api/pushTransaction.d.ts +14 -0
  160. package/lib/api/pushTransaction.js +40 -0
  161. package/lib/api/rebootToBootloader.d.ts +8 -0
  162. package/lib/api/rebootToBootloader.js +43 -0
  163. package/lib/api/recoveryDevice.d.ts +8 -0
  164. package/lib/api/recoveryDevice.js +57 -0
  165. package/lib/api/requestLogin.d.ts +12 -0
  166. package/lib/api/requestLogin.js +63 -0
  167. package/lib/api/resetDevice.d.ts +9 -0
  168. package/lib/api/resetDevice.js +59 -0
  169. package/lib/api/rippleGetAddress.d.ts +22 -0
  170. package/lib/api/rippleGetAddress.js +126 -0
  171. package/lib/api/rippleSignTransaction.d.ts +10 -0
  172. package/lib/api/rippleSignTransaction.js +54 -0
  173. package/lib/api/setProxy.d.ts +8 -0
  174. package/lib/api/setProxy.js +26 -0
  175. package/lib/api/signMessage.d.ts +7 -0
  176. package/lib/api/signMessage.js +51 -0
  177. package/lib/api/signTransaction.d.ts +21 -0
  178. package/lib/api/signTransaction.js +146 -0
  179. package/lib/api/stellar/stellarSignTx.d.ts +5 -0
  180. package/lib/api/stellar/stellarSignTx.js +198 -0
  181. package/lib/api/stellarGetAddress.d.ts +22 -0
  182. package/lib/api/stellarGetAddress.js +126 -0
  183. package/lib/api/stellarSignTransaction.d.ts +23 -0
  184. package/lib/api/stellarSignTransaction.js +62 -0
  185. package/lib/api/tezos/tezosSignTx.d.ts +4 -0
  186. package/lib/api/tezos/tezosSignTx.js +237 -0
  187. package/lib/api/tezosGetAddress.d.ts +22 -0
  188. package/lib/api/tezosGetAddress.js +126 -0
  189. package/lib/api/tezosGetPublicKey.d.ts +10 -0
  190. package/lib/api/tezosGetPublicKey.js +72 -0
  191. package/lib/api/tezosSignTransaction.d.ts +7 -0
  192. package/lib/api/tezosSignTransaction.js +30 -0
  193. package/lib/api/verifyMessage.d.ts +7 -0
  194. package/lib/api/verifyMessage.js +47 -0
  195. package/lib/api/wipeDevice.d.ts +8 -0
  196. package/lib/api/wipeDevice.js +41 -0
  197. package/lib/backend/BlockchainLink.d.ts +75 -0
  198. package/lib/backend/BlockchainLink.js +298 -0
  199. package/lib/constants/cardano.d.ts +9 -0
  200. package/lib/constants/cardano.js +14 -0
  201. package/lib/constants/errors.d.ts +49 -0
  202. package/lib/constants/errors.js +62 -0
  203. package/lib/constants/index.d.ts +6 -0
  204. package/lib/constants/index.js +10 -0
  205. package/lib/constants/nem.d.ts +22 -0
  206. package/lib/constants/nem.js +28 -0
  207. package/lib/constants/network.d.ts +13 -0
  208. package/lib/constants/network.js +15 -0
  209. package/lib/core/AbstractMethod.d.ts +59 -0
  210. package/lib/core/AbstractMethod.js +159 -0
  211. package/lib/core/index.d.ts +16 -0
  212. package/lib/core/index.js +671 -0
  213. package/lib/core/method.d.ts +6 -0
  214. package/lib/core/method.js +19 -0
  215. package/lib/data/DataManager.d.ts +31 -0
  216. package/lib/data/DataManager.js +98 -0
  217. package/lib/data/coinInfo.d.ts +37 -0
  218. package/lib/data/coinInfo.js +278 -0
  219. package/lib/data/config.d.ts +98 -0
  220. package/lib/data/config.js +201 -0
  221. package/lib/data/connectSettings.d.ts +6 -0
  222. package/lib/data/connectSettings.js +150 -0
  223. package/lib/data/firmwareInfo.d.ts +11 -0
  224. package/lib/data/firmwareInfo.js +148 -0
  225. package/lib/data/transportInfo.d.ts +4 -0
  226. package/lib/data/transportInfo.js +29 -0
  227. package/lib/data/udevInfo.d.ts +3 -0
  228. package/lib/data/udevInfo.js +21 -0
  229. package/lib/data/version.d.ts +3 -0
  230. package/lib/data/version.js +7 -0
  231. package/lib/device/AbortController.d.ts +21 -0
  232. package/lib/device/AbortController.js +40 -0
  233. package/lib/device/DescriptorStream.d.ts +28 -0
  234. package/lib/device/DescriptorStream.js +139 -0
  235. package/lib/device/Device.d.ts +105 -0
  236. package/lib/device/Device.js +527 -0
  237. package/lib/device/DeviceCommands.d.ts +63 -0
  238. package/lib/device/DeviceCommands.js +465 -0
  239. package/lib/device/DeviceList.d.ts +76 -0
  240. package/lib/device/DeviceList.js +411 -0
  241. package/lib/events/blockchain.d.ts +56 -0
  242. package/lib/events/blockchain.js +18 -0
  243. package/lib/events/call.d.ts +41 -0
  244. package/lib/events/call.js +14 -0
  245. package/lib/events/core.d.ts +20 -0
  246. package/lib/events/core.js +28 -0
  247. package/lib/events/device.d.ts +40 -0
  248. package/lib/events/device.js +28 -0
  249. package/lib/events/iframe.d.ts +39 -0
  250. package/lib/events/iframe.js +18 -0
  251. package/lib/events/index.d.ts +62 -0
  252. package/lib/events/index.js +21 -0
  253. package/lib/events/popup.d.ts +51 -0
  254. package/lib/events/popup.js +22 -0
  255. package/lib/events/transport.d.ts +62 -0
  256. package/lib/events/transport.js +21 -0
  257. package/lib/events/ui-promise.d.ts +12 -0
  258. package/lib/events/ui-promise.js +3 -0
  259. package/lib/events/ui-request.d.ts +180 -0
  260. package/lib/events/ui-request.js +50 -0
  261. package/lib/events/ui-response.d.ts +97 -0
  262. package/lib/events/ui-response.js +25 -0
  263. package/lib/exports.d.ts +5 -0
  264. package/lib/exports.js +10 -0
  265. package/lib/factory.d.ts +20 -0
  266. package/lib/factory.js +122 -0
  267. package/lib/index-browser.d.ts +4 -0
  268. package/lib/index-browser.js +29 -0
  269. package/lib/index.d.ts +11 -0
  270. package/lib/index.js +236 -0
  271. package/lib/types/account.d.ts +37 -0
  272. package/lib/types/account.js +3 -0
  273. package/lib/types/api/applyFlags.d.ts +4 -0
  274. package/lib/types/api/applyFlags.js +3 -0
  275. package/lib/types/api/applySettings.d.ts +4 -0
  276. package/lib/types/api/applySettings.js +3 -0
  277. package/lib/types/api/authorizeCoinJoin.d.ts +14 -0
  278. package/lib/types/api/authorizeCoinJoin.js +3 -0
  279. package/lib/types/api/backupDevice.d.ts +4 -0
  280. package/lib/types/api/backupDevice.js +3 -0
  281. package/lib/types/api/binanceGetAddress.d.ts +4 -0
  282. package/lib/types/api/binanceGetAddress.js +3 -0
  283. package/lib/types/api/binanceGetPublicKey.d.ts +4 -0
  284. package/lib/types/api/binanceGetPublicKey.js +3 -0
  285. package/lib/types/api/binanceSignTransaction.d.ts +31 -0
  286. package/lib/types/api/binanceSignTransaction.js +3 -0
  287. package/lib/types/api/blockchainDisconnect.d.ts +5 -0
  288. package/lib/types/api/blockchainDisconnect.js +3 -0
  289. package/lib/types/api/blockchainEstimateFee.d.ts +29 -0
  290. package/lib/types/api/blockchainEstimateFee.js +3 -0
  291. package/lib/types/api/blockchainGetAccountBalanceHistory.d.ts +4 -0
  292. package/lib/types/api/blockchainGetAccountBalanceHistory.js +3 -0
  293. package/lib/types/api/blockchainGetCurrentFiatRates.d.ts +4 -0
  294. package/lib/types/api/blockchainGetCurrentFiatRates.js +3 -0
  295. package/lib/types/api/blockchainGetFiatRatesForTimestamps.d.ts +4 -0
  296. package/lib/types/api/blockchainGetFiatRatesForTimestamps.js +3 -0
  297. package/lib/types/api/blockchainGetTransactions.d.ts +7 -0
  298. package/lib/types/api/blockchainGetTransactions.js +3 -0
  299. package/lib/types/api/blockchainSetCustomBackend.d.ts +7 -0
  300. package/lib/types/api/blockchainSetCustomBackend.js +3 -0
  301. package/lib/types/api/blockchainSubscribe.d.ts +7 -0
  302. package/lib/types/api/blockchainSubscribe.js +3 -0
  303. package/lib/types/api/blockchainSubscribeFiatRates.d.ts +7 -0
  304. package/lib/types/api/blockchainSubscribeFiatRates.js +3 -0
  305. package/lib/types/api/blockchainUnsubscribe.d.ts +5 -0
  306. package/lib/types/api/blockchainUnsubscribe.js +3 -0
  307. package/lib/types/api/blockchainUnsubscribeFiatRates.d.ts +5 -0
  308. package/lib/types/api/blockchainUnsubscribeFiatRates.js +3 -0
  309. package/lib/types/api/cancel.d.ts +2 -0
  310. package/lib/types/api/cancel.js +3 -0
  311. package/lib/types/api/cardanoGetAddress.d.ts +35 -0
  312. package/lib/types/api/cardanoGetAddress.js +3 -0
  313. package/lib/types/api/cardanoGetNativeScriptHash.d.ts +21 -0
  314. package/lib/types/api/cardanoGetNativeScriptHash.js +3 -0
  315. package/lib/types/api/cardanoGetPublicKey.d.ts +16 -0
  316. package/lib/types/api/cardanoGetPublicKey.js +3 -0
  317. package/lib/types/api/cardanoSignTransaction.d.ts +130 -0
  318. package/lib/types/api/cardanoSignTransaction.js +3 -0
  319. package/lib/types/api/changePin.d.ts +4 -0
  320. package/lib/types/api/changePin.js +3 -0
  321. package/lib/types/api/cipherKeyValue.d.ts +17 -0
  322. package/lib/types/api/cipherKeyValue.js +3 -0
  323. package/lib/types/api/composeTransaction.d.ts +92 -0
  324. package/lib/types/api/composeTransaction.js +3 -0
  325. package/lib/types/api/customMessage.d.ts +12 -0
  326. package/lib/types/api/customMessage.js +3 -0
  327. package/lib/types/api/disableWebUSB.d.ts +2 -0
  328. package/lib/types/api/disableWebUSB.js +3 -0
  329. package/lib/types/api/dispose.d.ts +2 -0
  330. package/lib/types/api/dispose.js +3 -0
  331. package/lib/types/api/eosGetPublicKey.d.ts +14 -0
  332. package/lib/types/api/eosGetPublicKey.js +3 -0
  333. package/lib/types/api/eosSignTransaction.d.ts +111 -0
  334. package/lib/types/api/eosSignTransaction.js +3 -0
  335. package/lib/types/api/ethereumGetAddress.d.ts +4 -0
  336. package/lib/types/api/ethereumGetAddress.js +3 -0
  337. package/lib/types/api/ethereumGetPublicKey.d.ts +5 -0
  338. package/lib/types/api/ethereumGetPublicKey.js +3 -0
  339. package/lib/types/api/ethereumSignMessage.d.ts +9 -0
  340. package/lib/types/api/ethereumSignMessage.js +3 -0
  341. package/lib/types/api/ethereumSignTransaction.d.ts +40 -0
  342. package/lib/types/api/ethereumSignTransaction.js +3 -0
  343. package/lib/types/api/ethereumSignTypedData.d.ts +42 -0
  344. package/lib/types/api/ethereumSignTypedData.js +3 -0
  345. package/lib/types/api/ethereumVerifyMessage.d.ts +10 -0
  346. package/lib/types/api/ethereumVerifyMessage.js +3 -0
  347. package/lib/types/api/firmwareUpdate.d.ts +14 -0
  348. package/lib/types/api/firmwareUpdate.js +3 -0
  349. package/lib/types/api/getAccountInfo.d.ts +14 -0
  350. package/lib/types/api/getAccountInfo.js +3 -0
  351. package/lib/types/api/getAddress.d.ts +13 -0
  352. package/lib/types/api/getAddress.js +3 -0
  353. package/lib/types/api/getCoinInfo.d.ts +4 -0
  354. package/lib/types/api/getCoinInfo.js +3 -0
  355. package/lib/types/api/getDeviceState.d.ts +6 -0
  356. package/lib/types/api/getDeviceState.js +3 -0
  357. package/lib/types/api/getFeatures.d.ts +4 -0
  358. package/lib/types/api/getFeatures.js +3 -0
  359. package/lib/types/api/getOwnershipId.d.ts +15 -0
  360. package/lib/types/api/getOwnershipId.js +3 -0
  361. package/lib/types/api/getOwnershipProof.d.ts +19 -0
  362. package/lib/types/api/getOwnershipProof.js +3 -0
  363. package/lib/types/api/getPublicKey.d.ts +19 -0
  364. package/lib/types/api/getPublicKey.js +3 -0
  365. package/lib/types/api/getSettings.d.ts +4 -0
  366. package/lib/types/api/getSettings.js +3 -0
  367. package/lib/types/api/index.d.ts +149 -0
  368. package/lib/types/api/index.js +3 -0
  369. package/lib/types/api/init.d.ts +5 -0
  370. package/lib/types/api/init.js +3 -0
  371. package/lib/types/api/manifest.d.ts +3 -0
  372. package/lib/types/api/manifest.js +3 -0
  373. package/lib/types/api/nemGetAddress.d.ts +7 -0
  374. package/lib/types/api/nemGetAddress.js +3 -0
  375. package/lib/types/api/nemSignTransaction.d.ts +92 -0
  376. package/lib/types/api/nemSignTransaction.js +3 -0
  377. package/lib/types/api/off.d.ts +11 -0
  378. package/lib/types/api/off.js +3 -0
  379. package/lib/types/api/on.d.ts +14 -0
  380. package/lib/types/api/on.js +3 -0
  381. package/lib/types/api/pushTransaction.d.ts +10 -0
  382. package/lib/types/api/pushTransaction.js +3 -0
  383. package/lib/types/api/rebootToBootloader.d.ts +4 -0
  384. package/lib/types/api/rebootToBootloader.js +3 -0
  385. package/lib/types/api/recoveryDevice.d.ts +7 -0
  386. package/lib/types/api/recoveryDevice.js +3 -0
  387. package/lib/types/api/removeAllListeners.d.ts +3 -0
  388. package/lib/types/api/removeAllListeners.js +3 -0
  389. package/lib/types/api/renderWebUSBButton.d.ts +2 -0
  390. package/lib/types/api/renderWebUSBButton.js +3 -0
  391. package/lib/types/api/requestLogin.d.ts +20 -0
  392. package/lib/types/api/requestLogin.js +3 -0
  393. package/lib/types/api/resetDevice.d.ts +16 -0
  394. package/lib/types/api/resetDevice.js +3 -0
  395. package/lib/types/api/rippleGetAddress.d.ts +4 -0
  396. package/lib/types/api/rippleGetAddress.js +3 -0
  397. package/lib/types/api/rippleSignTransaction.d.ts +23 -0
  398. package/lib/types/api/rippleSignTransaction.js +3 -0
  399. package/lib/types/api/setProxy.d.ts +9 -0
  400. package/lib/types/api/setProxy.js +3 -0
  401. package/lib/types/api/signMessage.d.ts +11 -0
  402. package/lib/types/api/signMessage.js +3 -0
  403. package/lib/types/api/signTransaction.d.ts +70 -0
  404. package/lib/types/api/signTransaction.js +3 -0
  405. package/lib/types/api/stellarGetAddress.d.ts +4 -0
  406. package/lib/types/api/stellarGetAddress.js +3 -0
  407. package/lib/types/api/stellarSignTransaction.d.ts +182 -0
  408. package/lib/types/api/stellarSignTransaction.js +3 -0
  409. package/lib/types/api/tezosGetAddress.d.ts +4 -0
  410. package/lib/types/api/tezosGetAddress.js +3 -0
  411. package/lib/types/api/tezosGetPublicKey.d.ts +4 -0
  412. package/lib/types/api/tezosGetPublicKey.js +3 -0
  413. package/lib/types/api/tezosSignTransaction.d.ts +61 -0
  414. package/lib/types/api/tezosSignTransaction.js +3 -0
  415. package/lib/types/api/uiResponse.d.ts +3 -0
  416. package/lib/types/api/uiResponse.js +3 -0
  417. package/lib/types/api/verifyMessage.d.ts +11 -0
  418. package/lib/types/api/verifyMessage.js +3 -0
  419. package/lib/types/api/wipeDevice.d.ts +4 -0
  420. package/lib/types/api/wipeDevice.js +3 -0
  421. package/lib/types/coinInfo.d.ts +79 -0
  422. package/lib/types/coinInfo.js +3 -0
  423. package/lib/types/device.d.ts +92 -0
  424. package/lib/types/device.js +3 -0
  425. package/lib/types/firmware.d.ts +36 -0
  426. package/lib/types/firmware.js +3 -0
  427. package/lib/types/index.d.ts +15 -0
  428. package/lib/types/index.js +11 -0
  429. package/lib/types/params.d.ts +56 -0
  430. package/lib/types/params.js +3 -0
  431. package/lib/types/settings.d.ts +34 -0
  432. package/lib/types/settings.js +3 -0
  433. package/lib/types/utils.d.ts +15 -0
  434. package/lib/types/utils.js +3 -0
  435. package/lib/utils/__fixtures__/accountUtils.d.ts +4 -0
  436. package/lib/utils/__fixtures__/accountUtils.js +32 -0
  437. package/lib/utils/__fixtures__/addressUtils.d.ts +10 -0
  438. package/lib/utils/__fixtures__/addressUtils.js +214 -0
  439. package/lib/utils/__fixtures__/ethereumUtils.d.ts +3 -0
  440. package/lib/utils/__fixtures__/ethereumUtils.js +20 -0
  441. package/lib/utils/__fixtures__/formatUtils.d.ts +3 -0
  442. package/lib/utils/__fixtures__/formatUtils.js +15 -0
  443. package/lib/utils/__fixtures__/hdnodeUtils.d.ts +186 -0
  444. package/lib/utils/__fixtures__/hdnodeUtils.js +206 -0
  445. package/lib/utils/accountUtils.d.ts +11 -0
  446. package/lib/utils/accountUtils.js +99 -0
  447. package/lib/utils/addressUtils.d.ts +3 -0
  448. package/lib/utils/addressUtils.js +32 -0
  449. package/lib/utils/assets-browser.d.ts +2 -0
  450. package/lib/utils/assets-browser.js +21 -0
  451. package/lib/utils/assets.d.ts +2 -0
  452. package/lib/utils/assets.js +28 -0
  453. package/lib/utils/bip39.d.ts +3 -0
  454. package/lib/utils/bip39.js +2053 -0
  455. package/lib/utils/browserUtils.d.ts +21 -0
  456. package/lib/utils/browserUtils.js +100 -0
  457. package/lib/utils/bufferUtils.d.ts +3 -0
  458. package/lib/utils/bufferUtils.js +11 -0
  459. package/lib/utils/debug.d.ts +24 -0
  460. package/lib/utils/debug.js +90 -0
  461. package/lib/utils/deferred.d.ts +18 -0
  462. package/lib/utils/deferred.js +66 -0
  463. package/lib/utils/deviceFeaturesUtils.d.ts +6 -0
  464. package/lib/utils/deviceFeaturesUtils.js +115 -0
  465. package/lib/utils/ethereumUtils.d.ts +3 -0
  466. package/lib/utils/ethereumUtils.js +12 -0
  467. package/lib/utils/firmwareUtils.d.ts +7 -0
  468. package/lib/utils/firmwareUtils.js +28 -0
  469. package/lib/utils/formatUtils.d.ts +8 -0
  470. package/lib/utils/formatUtils.js +57 -0
  471. package/lib/utils/hdnodeUtils.d.ts +8 -0
  472. package/lib/utils/hdnodeUtils.js +80 -0
  473. package/lib/utils/interactionTimeout.d.ts +10 -0
  474. package/lib/utils/interactionTimeout.js +34 -0
  475. package/lib/utils/objectUtils.d.ts +10 -0
  476. package/lib/utils/objectUtils.js +37 -0
  477. package/lib/utils/pathUtils.d.ts +20 -0
  478. package/lib/utils/pathUtils.js +159 -0
  479. package/lib/utils/promiseUtils.d.ts +2 -0
  480. package/lib/utils/promiseUtils.js +8 -0
  481. package/lib/utils/urlUtils.d.ts +5 -0
  482. package/lib/utils/urlUtils.js +27 -0
  483. package/lib/utils/versionUtils.d.ts +6 -0
  484. package/lib/utils/versionUtils.js +72 -0
  485. package/lib/utils/windowsUtils.d.ts +2 -0
  486. package/lib/utils/windowsUtils.js +6 -0
  487. package/lib/workers/RNUsbPlugin.d.ts +31 -0
  488. package/lib/workers/RNUsbPlugin.js +65 -0
  489. package/lib/workers/workers-browser.d.ts +8 -0
  490. package/lib/workers/workers-browser.js +19 -0
  491. package/lib/workers/workers-react-native.d.ts +8 -0
  492. package/lib/workers/workers-react-native.js +19 -0
  493. package/lib/workers/workers.d.ts +10 -0
  494. package/lib/workers/workers.js +17 -0
  495. package/package.json +62 -0
@@ -0,0 +1,411 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDeviceList = exports.DeviceList = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const events_1 = (0, tslib_1.__importDefault)(require("events"));
6
+ const transport_1 = (0, tslib_1.__importDefault)(require("@trezor/transport"));
7
+ const cross_fetch_1 = (0, tslib_1.__importDefault)(require("cross-fetch"));
8
+ const constants_1 = require("../constants");
9
+ const events_2 = require("../events");
10
+ const DescriptorStream_1 = require("./DescriptorStream");
11
+ const Device_1 = require("./Device");
12
+ const DataManager_1 = require("../data/DataManager");
13
+ const transportInfo_1 = require("../data/transportInfo");
14
+ const debug_1 = require("../utils/debug");
15
+ const promiseUtils_1 = require("../utils/promiseUtils");
16
+ const workers_1 = require("../workers/workers");
17
+ const AbortController_1 = require("./AbortController");
18
+ const { BridgeV2, Fallback } = transport_1.default;
19
+ const _log = (0, debug_1.initLog)('DeviceList');
20
+ class DeviceList extends events_1.default {
21
+ constructor() {
22
+ super();
23
+ this.devices = {};
24
+ this.creatingDevicesDescriptors = {};
25
+ this.hasCustomMessages = false;
26
+ this.transportStartPending = 0;
27
+ this.penalizedDevices = {};
28
+ const { env, webusb } = DataManager_1.DataManager.settings;
29
+ const transports = [];
30
+ if (env === 'react-native' && typeof workers_1.ReactNativeUsbPlugin !== 'undefined') {
31
+ transports.push((0, workers_1.ReactNativeUsbPlugin)());
32
+ }
33
+ else {
34
+ const bridgeLatestVersion = (0, transportInfo_1.getBridgeInfo)().version.join('.');
35
+ const bridge = new BridgeV2(undefined, undefined);
36
+ bridge.setBridgeLatestVersion(bridgeLatestVersion);
37
+ this.fetchController = (0, AbortController_1.getAbortController)();
38
+ const { signal } = this.fetchController;
39
+ const fetchWithSignal = (args, options = {}) => (0, cross_fetch_1.default)(args, { ...options, signal });
40
+ BridgeV2.setFetch(fetchWithSignal, typeof window === 'undefined');
41
+ transports.push(bridge);
42
+ }
43
+ if (webusb && typeof workers_1.WebUsbPlugin !== 'undefined') {
44
+ transports.push((0, workers_1.WebUsbPlugin)());
45
+ }
46
+ this.transport = new Fallback(transports);
47
+ this.defaultMessages = DataManager_1.DataManager.getProtobufMessages();
48
+ this.currentMessages = this.defaultMessages;
49
+ }
50
+ async init() {
51
+ const { transport } = this;
52
+ try {
53
+ _log.debug('Initializing transports');
54
+ await transport.init(_log.enabled);
55
+ _log.debug('Configuring transports');
56
+ await transport.configure(JSON.stringify(this.defaultMessages));
57
+ _log.debug('Configuring transports done');
58
+ const { activeName } = transport;
59
+ if (activeName === 'LowlevelTransportWithSharedConnections') {
60
+ this.transportPlugin = transport.activeTransport.plugin;
61
+ }
62
+ await this._initStream();
63
+ this.on(events_2.DEVICE.CONNECT, this.resolveTransportEvent.bind(this));
64
+ this.on(events_2.DEVICE.CONNECT_UNACQUIRED, this.resolveTransportEvent.bind(this));
65
+ }
66
+ catch (error) {
67
+ this.emit(events_2.TRANSPORT.ERROR, error);
68
+ }
69
+ }
70
+ async reconfigure(messages, custom) {
71
+ if (Array.isArray(messages)) {
72
+ messages = DataManager_1.DataManager.getProtobufMessages(messages);
73
+ }
74
+ if (this.currentMessages === messages || !messages)
75
+ return;
76
+ try {
77
+ await this.transport.configure(JSON.stringify(messages));
78
+ this.currentMessages = messages;
79
+ this.hasCustomMessages = typeof custom === 'boolean' ? custom : false;
80
+ }
81
+ catch (error) {
82
+ throw constants_1.ERRORS.TypedError('Transport_InvalidProtobuf', error.message);
83
+ }
84
+ }
85
+ async restoreMessages() {
86
+ if (!this.hasCustomMessages)
87
+ return;
88
+ try {
89
+ await this.transport.configure(JSON.stringify(this.defaultMessages));
90
+ this.hasCustomMessages = false;
91
+ }
92
+ catch (error) {
93
+ throw constants_1.ERRORS.TypedError('Transport_InvalidProtobuf', error.message);
94
+ }
95
+ }
96
+ resolveTransportEvent() {
97
+ this.transportStartPending--;
98
+ if (this.transportStartPending === 0) {
99
+ this.stream.emit(events_2.TRANSPORT.START);
100
+ }
101
+ }
102
+ async waitForTransportFirstEvent() {
103
+ await new Promise(resolve => {
104
+ const handler = () => {
105
+ this.removeListener(events_2.TRANSPORT.START, handler);
106
+ this.removeListener(events_2.TRANSPORT.ERROR, handler);
107
+ resolve();
108
+ };
109
+ this.on(events_2.TRANSPORT.START, handler);
110
+ this.on(events_2.TRANSPORT.ERROR, handler);
111
+ });
112
+ }
113
+ _initStream() {
114
+ const stream = new DescriptorStream_1.DescriptorStream(this.transport);
115
+ stream.on(events_2.TRANSPORT.START_PENDING, (pending) => {
116
+ this.transportStartPending = pending;
117
+ });
118
+ stream.on(events_2.TRANSPORT.START, () => {
119
+ this.emit(events_2.TRANSPORT.START, this.getTransportInfo());
120
+ });
121
+ stream.on(events_2.TRANSPORT.UPDATE, (diff) => {
122
+ new DiffHandler(this, diff).handle();
123
+ });
124
+ stream.on(events_2.TRANSPORT.ERROR, error => {
125
+ this.emit(events_2.TRANSPORT.ERROR, error);
126
+ stream.stop();
127
+ });
128
+ stream.listen();
129
+ this.stream = stream;
130
+ if (this.transportPlugin && this.transportPlugin.name === 'WebUsbPlugin') {
131
+ const { unreadableHidDeviceChange } = this.transportPlugin;
132
+ const UNREADABLE_PATH = 'unreadable';
133
+ unreadableHidDeviceChange.on('change', () => {
134
+ if (this.transportPlugin && this.transportPlugin.unreadableHidDevice) {
135
+ const device = this._createUnreadableDevice({
136
+ path: UNREADABLE_PATH,
137
+ session: null,
138
+ debugSession: null,
139
+ debug: false,
140
+ }, 'HID_DEVICE');
141
+ this.devices[UNREADABLE_PATH] = device;
142
+ this.emit(events_2.DEVICE.CONNECT_UNACQUIRED, device.toMessageObject());
143
+ }
144
+ else {
145
+ const device = this.devices[UNREADABLE_PATH];
146
+ delete this.devices[UNREADABLE_PATH];
147
+ this.emit(events_2.DEVICE.DISCONNECT, device.toMessageObject());
148
+ }
149
+ });
150
+ }
151
+ this.emit(events_2.TRANSPORT.STREAM, stream);
152
+ }
153
+ async _createAndSaveDevice(descriptor) {
154
+ _log.debug('Creating Device', descriptor);
155
+ await new CreateDeviceHandler(descriptor, this).handle();
156
+ }
157
+ _createUnacquiredDevice(descriptor) {
158
+ _log.debug('Creating Unacquired Device', descriptor);
159
+ const device = Device_1.Device.createUnacquired(this.transport, descriptor);
160
+ device.once(events_2.DEVICE.ACQUIRED, () => {
161
+ this.emit(events_2.DEVICE.CONNECT, device.toMessageObject());
162
+ });
163
+ return device;
164
+ }
165
+ _createUnreadableDevice(descriptor, unreadableError) {
166
+ _log.debug('Creating Unreadable Device', descriptor, unreadableError);
167
+ return Device_1.Device.createUnacquired(this.transport, descriptor, unreadableError);
168
+ }
169
+ getDevice(path) {
170
+ return this.devices[path];
171
+ }
172
+ getFirstDevicePath() {
173
+ return this.asArray()[0].path;
174
+ }
175
+ asArray() {
176
+ return this.allDevices().map(device => device.toMessageObject());
177
+ }
178
+ allDevices() {
179
+ return Object.keys(this.devices).map(key => this.devices[key]);
180
+ }
181
+ length() {
182
+ return this.asArray().length;
183
+ }
184
+ transportType() {
185
+ const { transport, transportPlugin } = this;
186
+ const { activeName } = transport;
187
+ if (activeName === 'BridgeTransport') {
188
+ return 'bridge';
189
+ }
190
+ if (transportPlugin) {
191
+ return transportPlugin.name;
192
+ }
193
+ return transport.name;
194
+ }
195
+ getTransportInfo() {
196
+ return {
197
+ type: this.transportType(),
198
+ version: this.transport.version,
199
+ outdated: this.transport.isOutdated,
200
+ };
201
+ }
202
+ dispose() {
203
+ this.removeAllListeners();
204
+ if (this.stream) {
205
+ this.stream.stop();
206
+ }
207
+ if (this.transport) {
208
+ this.transport.stop();
209
+ }
210
+ if (this.fetchController) {
211
+ this.fetchController.abort();
212
+ this.fetchController = null;
213
+ }
214
+ this.allDevices().forEach(device => device.dispose());
215
+ }
216
+ disconnectDevices() {
217
+ this.allDevices().forEach(device => {
218
+ this.emit(events_2.DEVICE.DISCONNECT, device.toMessageObject());
219
+ });
220
+ }
221
+ enumerate() {
222
+ this.stream.enumerate();
223
+ if (!this.stream.current)
224
+ return;
225
+ this.stream.current.forEach(descriptor => {
226
+ const path = descriptor.path.toString();
227
+ const device = this.devices[path];
228
+ if (device) {
229
+ device.updateDescriptor(descriptor);
230
+ }
231
+ });
232
+ }
233
+ addAuthPenalty(device) {
234
+ if (!device.isInitialized() || device.isBootloader() || !device.features.device_id)
235
+ return;
236
+ const deviceID = device.features.device_id;
237
+ const penalty = this.penalizedDevices[deviceID]
238
+ ? this.penalizedDevices[deviceID] + 500
239
+ : 2000;
240
+ this.penalizedDevices[deviceID] = Math.min(penalty, 5000);
241
+ }
242
+ getAuthPenalty() {
243
+ const { penalizedDevices } = this;
244
+ return Object.keys(penalizedDevices).reduce((penalty, key) => Math.max(penalty, penalizedDevices[key]), 0);
245
+ }
246
+ removeAuthPenalty(device) {
247
+ if (!device.isInitialized() || device.isBootloader() || !device.features.device_id)
248
+ return;
249
+ const deviceID = device.features.device_id;
250
+ delete this.penalizedDevices[deviceID];
251
+ }
252
+ }
253
+ exports.DeviceList = DeviceList;
254
+ const getDeviceList = async () => {
255
+ const list = new DeviceList();
256
+ await list.init();
257
+ return list;
258
+ };
259
+ exports.getDeviceList = getDeviceList;
260
+ class CreateDeviceHandler {
261
+ constructor(descriptor, list) {
262
+ this.descriptor = descriptor;
263
+ this.list = list;
264
+ this.path = descriptor.path.toString();
265
+ }
266
+ async handle() {
267
+ this.list.creatingDevicesDescriptors[this.path] = this.descriptor;
268
+ try {
269
+ await this._takeAndCreateDevice();
270
+ }
271
+ catch (error) {
272
+ _log.debug('Cannot create device', error);
273
+ if (error.code === 'Device_NotFound') {
274
+ }
275
+ else if (error.message === constants_1.ERRORS.WRONG_PREVIOUS_SESSION_ERROR_MESSAGE ||
276
+ error.toString() === constants_1.ERRORS.WEBUSB_ERROR_MESSAGE) {
277
+ this.list.enumerate();
278
+ this._handleUsedElsewhere();
279
+ }
280
+ else if (error.message.indexOf(constants_1.ERRORS.LIBUSB_ERROR_MESSAGE) >= 0) {
281
+ const device = this.list._createUnreadableDevice(this.list.creatingDevicesDescriptors[this.path], error.message);
282
+ this.list.devices[this.path] = device;
283
+ this.list.emit(events_2.DEVICE.CONNECT_UNACQUIRED, device.toMessageObject());
284
+ }
285
+ else if (error.code === 'Device_InitializeFailed') {
286
+ this._handleUsedElsewhere();
287
+ }
288
+ else if (error.code === 'Device_UsedElsewhere') {
289
+ this._handleUsedElsewhere();
290
+ }
291
+ else {
292
+ await (0, promiseUtils_1.resolveAfter)(501, null);
293
+ await this.handle();
294
+ }
295
+ }
296
+ delete this.list.creatingDevicesDescriptors[this.path];
297
+ }
298
+ async _takeAndCreateDevice() {
299
+ const device = Device_1.Device.fromDescriptor(this.list.transport, this.descriptor);
300
+ this.list.devices[this.path] = device;
301
+ await device.run();
302
+ this.list.emit(events_2.DEVICE.CONNECT, device.toMessageObject());
303
+ }
304
+ _handleUsedElsewhere() {
305
+ const device = this.list._createUnacquiredDevice(this.list.creatingDevicesDescriptors[this.path]);
306
+ this.list.devices[this.path] = device;
307
+ this.list.emit(events_2.DEVICE.CONNECT_UNACQUIRED, device.toMessageObject());
308
+ }
309
+ }
310
+ class DiffHandler {
311
+ constructor(list, diff) {
312
+ this.list = list;
313
+ this.diff = diff;
314
+ }
315
+ handle() {
316
+ _log.debug('Update DescriptorStream', this.diff);
317
+ this._createConnectedDevices();
318
+ this._createReleasedDevices();
319
+ this._signalAcquiredDevices();
320
+ this._updateDescriptors();
321
+ this._emitEvents();
322
+ this._disconnectDevices();
323
+ }
324
+ _updateDescriptors() {
325
+ this.diff.descriptors.forEach((descriptor) => {
326
+ const path = descriptor.path.toString();
327
+ const device = this.list.devices[path];
328
+ if (device) {
329
+ device.updateDescriptor(descriptor);
330
+ }
331
+ });
332
+ }
333
+ _emitEvents() {
334
+ const events = [
335
+ {
336
+ d: this.diff.changedSessions,
337
+ e: events_2.DEVICE.CHANGED,
338
+ },
339
+ {
340
+ d: this.diff.acquired,
341
+ e: events_2.DEVICE.ACQUIRED,
342
+ },
343
+ {
344
+ d: this.diff.released,
345
+ e: events_2.DEVICE.RELEASED,
346
+ },
347
+ ];
348
+ events.forEach(({ d, e }) => {
349
+ d.forEach(descriptor => {
350
+ const path = descriptor.path.toString();
351
+ const device = this.list.devices[path];
352
+ _log.debug('Event', e, device);
353
+ if (device) {
354
+ this.list.emit(e, device.toMessageObject());
355
+ }
356
+ });
357
+ });
358
+ }
359
+ _createConnectedDevices() {
360
+ this.diff.connected.forEach(async (descriptor) => {
361
+ const path = descriptor.path.toString();
362
+ const priority = DataManager_1.DataManager.getSettings('priority');
363
+ const penalty = this.list.getAuthPenalty();
364
+ _log.debug('Connected', priority, penalty, descriptor.session, this.list.devices);
365
+ if (priority || penalty) {
366
+ await (0, promiseUtils_1.resolveAfter)(501 + penalty + 100 * priority, null);
367
+ }
368
+ if (descriptor.session == null) {
369
+ await this.list._createAndSaveDevice(descriptor);
370
+ }
371
+ else {
372
+ const device = await this.list._createUnacquiredDevice(descriptor);
373
+ this.list.devices[path] = device;
374
+ this.list.emit(events_2.DEVICE.CONNECT_UNACQUIRED, device.toMessageObject());
375
+ }
376
+ });
377
+ }
378
+ _signalAcquiredDevices() {
379
+ this.diff.acquired.forEach(descriptor => {
380
+ const path = descriptor.path.toString();
381
+ if (this.list.creatingDevicesDescriptors[path]) {
382
+ this.list.creatingDevicesDescriptors[path] = descriptor;
383
+ }
384
+ });
385
+ }
386
+ _createReleasedDevices() {
387
+ this.diff.released.forEach(async (descriptor) => {
388
+ const path = descriptor.path.toString();
389
+ const device = this.list.devices[path];
390
+ if (device) {
391
+ if (device.isUnacquired() && !device.isInconsistent()) {
392
+ await (0, promiseUtils_1.resolveAfter)(501, null);
393
+ _log.debug('Create device from unacquired', device);
394
+ await this.list._createAndSaveDevice(descriptor);
395
+ }
396
+ }
397
+ });
398
+ }
399
+ _disconnectDevices() {
400
+ this.diff.disconnected.forEach(descriptor => {
401
+ const path = descriptor.path.toString();
402
+ const device = this.list.devices[path];
403
+ if (device != null) {
404
+ device.disconnect();
405
+ delete this.list.devices[path];
406
+ this.list.emit(events_2.DEVICE.DISCONNECT, device.toMessageObject());
407
+ }
408
+ });
409
+ }
410
+ }
411
+ //# sourceMappingURL=DeviceList.js.map
@@ -0,0 +1,56 @@
1
+ import type { ServerInfo, BlockEvent, FiatRates, NotificationEvent } from '@trezor/blockchain-link';
2
+ import type { CoinInfo } from '../types/coinInfo';
3
+ import type { MessageFactoryFn } from '../types/utils';
4
+ export declare const BLOCKCHAIN_EVENT = "BLOCKCHAIN_EVENT";
5
+ export declare const BLOCKCHAIN: {
6
+ readonly CONNECT: "blockchain-connect";
7
+ readonly ERROR: "blockchain-error";
8
+ readonly BLOCK: "blockchain-block";
9
+ readonly NOTIFICATION: "blockchain-notification";
10
+ readonly FIAT_RATES_UPDATE: "fiat-rates-update";
11
+ };
12
+ export interface BlockchainInfo extends ServerInfo {
13
+ coin: CoinInfo;
14
+ cleanUrl?: string;
15
+ misc?: {
16
+ reserve?: string;
17
+ };
18
+ }
19
+ export interface BlockchainError {
20
+ coin: CoinInfo;
21
+ error: string;
22
+ code?: string;
23
+ }
24
+ export declare type BlockchainBlock = BlockEvent['payload'] & {
25
+ coin: CoinInfo;
26
+ };
27
+ export interface BlockchainNotification {
28
+ coin: CoinInfo;
29
+ notification: NotificationEvent['payload'];
30
+ }
31
+ export interface BlockchainFiatRatesUpdate {
32
+ coin: CoinInfo;
33
+ rates: FiatRates;
34
+ }
35
+ export declare type BlockchainEvent = {
36
+ type: typeof BLOCKCHAIN.CONNECT;
37
+ payload: BlockchainInfo;
38
+ } | {
39
+ type: typeof BLOCKCHAIN.ERROR;
40
+ payload: BlockchainError;
41
+ } | {
42
+ type: typeof BLOCKCHAIN.BLOCK;
43
+ payload: BlockchainBlock;
44
+ } | {
45
+ type: typeof BLOCKCHAIN.NOTIFICATION;
46
+ payload: BlockchainNotification;
47
+ } | {
48
+ type: typeof BLOCKCHAIN.FIAT_RATES_UPDATE;
49
+ payload: BlockchainFiatRatesUpdate;
50
+ };
51
+ export declare type BlockchainEventMessage = BlockchainEvent & {
52
+ event: typeof BLOCKCHAIN_EVENT;
53
+ };
54
+ export declare type BlockchainEventListenerFn = (type: typeof BLOCKCHAIN_EVENT, cb: (event: BlockchainEventMessage) => void) => void;
55
+ export declare const createBlockchainMessage: MessageFactoryFn<typeof BLOCKCHAIN_EVENT, BlockchainEvent>;
56
+ //# sourceMappingURL=blockchain.d.ts.map
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createBlockchainMessage = exports.BLOCKCHAIN = exports.BLOCKCHAIN_EVENT = void 0;
4
+ exports.BLOCKCHAIN_EVENT = 'BLOCKCHAIN_EVENT';
5
+ exports.BLOCKCHAIN = {
6
+ CONNECT: 'blockchain-connect',
7
+ ERROR: 'blockchain-error',
8
+ BLOCK: 'blockchain-block',
9
+ NOTIFICATION: 'blockchain-notification',
10
+ FIAT_RATES_UPDATE: 'fiat-rates-update',
11
+ };
12
+ const createBlockchainMessage = (type, payload) => ({
13
+ event: exports.BLOCKCHAIN_EVENT,
14
+ type,
15
+ payload,
16
+ });
17
+ exports.createBlockchainMessage = createBlockchainMessage;
18
+ //# sourceMappingURL=blockchain.js.map
@@ -0,0 +1,41 @@
1
+ import type { IFRAME } from './iframe';
2
+ import type { TrezorConnect } from '../types/api';
3
+ import type { CommonParams } from '../types/params';
4
+ declare type UnwrappedResponse<T> = T extends Promise<infer R> ? R extends {
5
+ success: true;
6
+ payload: infer P;
7
+ } ? P : never : void;
8
+ declare type OverloadedMethod<T, E extends Record<string, string>> = T extends {
9
+ (params: infer P1): infer R1;
10
+ (params: infer P2): infer R2;
11
+ } ? ((params: P1 & E) => R1) | ((params: P2 & E) => R2) : T extends (...args: infer P) => infer R ? (params: E & P[0]) => R : never;
12
+ declare type UnwrappedMethod<T, M extends Record<string, string>> = T extends () => infer R ? (params: M & CommonParams) => R : OverloadedMethod<T, M>;
13
+ declare type IsMethodCallable<T> = T extends (...args: any[]) => infer R ? R extends Promise<{
14
+ success: boolean;
15
+ }> ? R : never : never;
16
+ declare type CallApi = {
17
+ [K in keyof TrezorConnect]: IsMethodCallable<TrezorConnect[K]> extends never ? never : UnwrappedMethod<TrezorConnect[K], {
18
+ method: K;
19
+ }>;
20
+ };
21
+ export declare type CallMethodUnion = CallApi[keyof CallApi];
22
+ export declare type CallMethodPayload = Parameters<CallMethodUnion>[0];
23
+ export declare type CallMethodResponse<M extends keyof CallApi> = UnwrappedResponse<ReturnType<CallApi[M]>>;
24
+ export declare type CallMethodAnyResponse = ReturnType<CallMethodUnion>;
25
+ export declare type CallMethod = (params: CallMethodPayload) => Promise<any>;
26
+ export interface IFrameCallMessage {
27
+ event: typeof IFRAME.CALL;
28
+ type: typeof IFRAME.CALL;
29
+ payload: CallMethodPayload;
30
+ }
31
+ export declare const RESPONSE_EVENT = "RESPONSE_EVENT";
32
+ export interface MethodResponseMessage {
33
+ event: typeof RESPONSE_EVENT;
34
+ type: typeof RESPONSE_EVENT;
35
+ id: number;
36
+ success: boolean;
37
+ payload: CallMethodResponse<keyof CallApi>;
38
+ }
39
+ export declare const createResponseMessage: (id: number, success: boolean, payload: any) => MethodResponseMessage;
40
+ export {};
41
+ //# sourceMappingURL=call.d.ts.map
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createResponseMessage = exports.RESPONSE_EVENT = void 0;
4
+ const errors_1 = require("../constants/errors");
5
+ exports.RESPONSE_EVENT = 'RESPONSE_EVENT';
6
+ const createResponseMessage = (id, success, payload) => ({
7
+ event: exports.RESPONSE_EVENT,
8
+ type: exports.RESPONSE_EVENT,
9
+ id,
10
+ success,
11
+ payload: success ? payload : (0, errors_1.serializeError)(payload),
12
+ });
13
+ exports.createResponseMessage = createResponseMessage;
14
+ //# sourceMappingURL=call.js.map
@@ -0,0 +1,20 @@
1
+ import type { BlockchainEventMessage } from './blockchain';
2
+ import type { IFrameCallMessage, MethodResponseMessage } from './call';
3
+ import type { DeviceEventMessage } from './device';
4
+ import type { IFrameEventMessage } from './iframe';
5
+ import type { PopupEventMessage } from './popup';
6
+ import type { TransportEventMessage } from './transport';
7
+ import type { UiEventMessage } from './ui-request';
8
+ import type { UiResponseMessage } from './ui-response';
9
+ import type { Unsuccessful } from '../types/params';
10
+ export declare const CORE_EVENT = "CORE_EVENT";
11
+ export declare type CoreMessage = {
12
+ id?: number;
13
+ success?: boolean;
14
+ } & (BlockchainEventMessage | DeviceEventMessage | TransportEventMessage | UiEventMessage | UiResponseMessage | IFrameCallMessage | MethodResponseMessage | IFrameEventMessage | PopupEventMessage);
15
+ export declare type PostMessageEvent = MessageEvent<CoreMessage>;
16
+ export declare const parseMessage: (messageData: any) => CoreMessage;
17
+ export declare const createErrorMessage: (error: Error & {
18
+ code?: string;
19
+ }) => Unsuccessful;
20
+ //# sourceMappingURL=core.d.ts.map
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createErrorMessage = exports.parseMessage = exports.CORE_EVENT = void 0;
4
+ exports.CORE_EVENT = 'CORE_EVENT';
5
+ const parseMessage = (messageData) => {
6
+ const message = {
7
+ event: messageData.event,
8
+ type: messageData.type,
9
+ payload: messageData.payload,
10
+ };
11
+ if (typeof messageData.id === 'number') {
12
+ message.id = messageData.id;
13
+ }
14
+ if (typeof messageData.success === 'boolean') {
15
+ message.success = messageData.success;
16
+ }
17
+ return message;
18
+ };
19
+ exports.parseMessage = parseMessage;
20
+ const createErrorMessage = (error) => ({
21
+ success: false,
22
+ payload: {
23
+ error: error.message,
24
+ code: error.code,
25
+ },
26
+ });
27
+ exports.createErrorMessage = createErrorMessage;
28
+ //# sourceMappingURL=core.js.map
@@ -0,0 +1,40 @@
1
+ import type { PROTO } from '../constants';
2
+ import type { Device } from '../types/device';
3
+ import type { MessageFactoryFn } from '../types/utils';
4
+ export declare const DEVICE_EVENT = "DEVICE_EVENT";
5
+ export declare const DEVICE: {
6
+ readonly CONNECT: "device-connect";
7
+ readonly CONNECT_UNACQUIRED: "device-connect_unacquired";
8
+ readonly DISCONNECT: "device-disconnect";
9
+ readonly CHANGED: "device-changed";
10
+ readonly ACQUIRE: "device-acquire";
11
+ readonly RELEASE: "device-release";
12
+ readonly ACQUIRED: "device-acquired";
13
+ readonly RELEASED: "device-released";
14
+ readonly USED_ELSEWHERE: "device-used_elsewhere";
15
+ readonly LOADING: "device-loading";
16
+ readonly BUTTON: "button";
17
+ readonly PIN: "pin";
18
+ readonly PASSPHRASE: "passphrase";
19
+ readonly PASSPHRASE_ON_DEVICE: "passphrase_on_device";
20
+ readonly WORD: "word";
21
+ };
22
+ export interface DeviceButtonRequestPayload extends Omit<PROTO.ButtonRequest, 'code'> {
23
+ code?: PROTO.ButtonRequest['code'] | 'ButtonRequest_FirmwareUpdate';
24
+ }
25
+ export interface DeviceButtonRequest {
26
+ type: typeof DEVICE.BUTTON;
27
+ payload: DeviceButtonRequestPayload & {
28
+ device: Device;
29
+ };
30
+ }
31
+ export declare type DeviceEvent = {
32
+ type: typeof DEVICE.CONNECT | typeof DEVICE.CONNECT_UNACQUIRED | typeof DEVICE.CHANGED | typeof DEVICE.DISCONNECT;
33
+ payload: Device;
34
+ } | DeviceButtonRequest;
35
+ export declare type DeviceEventMessage = DeviceEvent & {
36
+ event: typeof DEVICE_EVENT;
37
+ };
38
+ export declare type DeviceEventListenerFn = (type: typeof DEVICE_EVENT, cb: (event: DeviceEventMessage) => void) => void;
39
+ export declare const createDeviceMessage: MessageFactoryFn<typeof DEVICE_EVENT, DeviceEvent>;
40
+ //# sourceMappingURL=device.d.ts.map
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createDeviceMessage = exports.DEVICE = exports.DEVICE_EVENT = void 0;
4
+ exports.DEVICE_EVENT = 'DEVICE_EVENT';
5
+ exports.DEVICE = {
6
+ CONNECT: 'device-connect',
7
+ CONNECT_UNACQUIRED: 'device-connect_unacquired',
8
+ DISCONNECT: 'device-disconnect',
9
+ CHANGED: 'device-changed',
10
+ ACQUIRE: 'device-acquire',
11
+ RELEASE: 'device-release',
12
+ ACQUIRED: 'device-acquired',
13
+ RELEASED: 'device-released',
14
+ USED_ELSEWHERE: 'device-used_elsewhere',
15
+ LOADING: 'device-loading',
16
+ BUTTON: 'button',
17
+ PIN: 'pin',
18
+ PASSPHRASE: 'passphrase',
19
+ PASSPHRASE_ON_DEVICE: 'passphrase_on_device',
20
+ WORD: 'word',
21
+ };
22
+ const createDeviceMessage = (type, payload) => ({
23
+ event: exports.DEVICE_EVENT,
24
+ type,
25
+ payload,
26
+ });
27
+ exports.createDeviceMessage = createDeviceMessage;
28
+ //# sourceMappingURL=device.js.map