@ledgerhq/device-management-kit 0.7.0 → 0.9.0

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 (415) hide show
  1. package/README.md +3 -3
  2. package/lib/cjs/package.json +1 -2
  3. package/lib/cjs/src/api/DeviceManagementKit.js +1 -1
  4. package/lib/cjs/src/api/DeviceManagementKit.js.map +3 -3
  5. package/lib/cjs/src/api/DeviceManagementKit.test.js +1 -1
  6. package/lib/cjs/src/api/DeviceManagementKit.test.js.map +3 -3
  7. package/lib/cjs/src/api/apdu/utils/ByteArrayBuilder.js +1 -1
  8. package/lib/cjs/src/api/apdu/utils/ByteArrayBuilder.js.map +3 -3
  9. package/lib/cjs/src/api/apdu/utils/ByteArrayBuilder.test.js +1 -1
  10. package/lib/cjs/src/api/apdu/utils/ByteArrayBuilder.test.js.map +2 -2
  11. package/lib/cjs/src/api/apdu/utils/ByteArrayParser.js +1 -1
  12. package/lib/cjs/src/api/apdu/utils/ByteArrayParser.js.map +3 -3
  13. package/lib/cjs/src/api/command/di/commandModule.js +1 -1
  14. package/lib/cjs/src/api/command/di/commandModule.js.map +3 -3
  15. package/lib/cjs/src/api/command/di/commandModule.test.js +1 -1
  16. package/lib/cjs/src/api/command/di/commandModule.test.js.map +2 -2
  17. package/lib/cjs/src/api/command/os/__mocks__/GetOsVersionCommand.js +1 -1
  18. package/lib/cjs/src/api/command/os/__mocks__/GetOsVersionCommand.js.map +2 -2
  19. package/lib/cjs/src/api/command/utils/CommandUtils.js +1 -1
  20. package/lib/cjs/src/api/command/utils/CommandUtils.js.map +2 -2
  21. package/lib/cjs/src/api/command/utils/CommandUtils.test.js +1 -1
  22. package/lib/cjs/src/api/command/utils/CommandUtils.test.js.map +2 -2
  23. package/lib/cjs/src/api/command/utils/GlobalCommandError.js +1 -1
  24. package/lib/cjs/src/api/command/utils/GlobalCommandError.js.map +2 -2
  25. package/lib/cjs/src/api/device/DeviceModel.js +1 -1
  26. package/lib/cjs/src/api/device/DeviceModel.js.map +2 -2
  27. package/lib/cjs/src/api/device-action/di/deviceActionModule.js +1 -1
  28. package/lib/cjs/src/api/device-action/di/deviceActionModule.js.map +3 -3
  29. package/lib/cjs/src/api/device-action/di/deviceActionModule.test.js +1 -1
  30. package/lib/cjs/src/api/device-action/di/deviceActionModule.test.js.map +2 -2
  31. package/lib/cjs/src/api/device-action/model/UserInteractionRequired.js +1 -1
  32. package/lib/cjs/src/api/device-action/model/UserInteractionRequired.js.map +2 -2
  33. package/lib/cjs/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.js +1 -1
  34. package/lib/cjs/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.js.map +2 -2
  35. package/lib/cjs/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceActionTypes.js.map +1 -1
  36. package/lib/cjs/src/api/device-action/os/Errors.js +1 -1
  37. package/lib/cjs/src/api/device-action/os/Errors.js.map +3 -3
  38. package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js +1 -1
  39. package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js.map +2 -2
  40. package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/types.js.map +1 -1
  41. package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js +1 -1
  42. package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js.map +2 -2
  43. package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js +1 -1
  44. package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js.map +2 -2
  45. package/lib/cjs/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.js +1 -1
  46. package/lib/cjs/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.js.map +3 -3
  47. package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js +1 -1
  48. package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js.map +2 -2
  49. package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/types.js +1 -1
  50. package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/types.js.map +1 -1
  51. package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.js +1 -1
  52. package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.js.map +3 -3
  53. package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.test.js +1 -1
  54. package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.test.js.map +2 -2
  55. package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/types.js +1 -1
  56. package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/types.js.map +1 -1
  57. package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.js +1 -1
  58. package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.js.map +2 -2
  59. package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/types.js.map +1 -1
  60. package/lib/cjs/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.js +1 -1
  61. package/lib/cjs/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.js.map +2 -2
  62. package/lib/cjs/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceActionTypes.js +1 -1
  63. package/lib/cjs/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceActionTypes.js.map +1 -1
  64. package/lib/cjs/src/api/device-action/task/BuildAppsInstallPlanTask.js +1 -1
  65. package/lib/cjs/src/api/device-action/task/BuildAppsInstallPlanTask.js.map +2 -2
  66. package/lib/cjs/src/api/device-action/task/BuildAppsInstallPlanTask.test.js +1 -1
  67. package/lib/cjs/src/api/device-action/task/BuildAppsInstallPlanTask.test.js.map +2 -2
  68. package/lib/cjs/src/api/device-action/xstate-utils/XStateDeviceAction.js +1 -1
  69. package/lib/cjs/src/api/device-action/xstate-utils/XStateDeviceAction.js.map +2 -2
  70. package/lib/cjs/src/api/device-model/data/StaticDeviceModelDataSource.js +1 -1
  71. package/lib/cjs/src/api/device-model/data/StaticDeviceModelDataSource.js.map +2 -2
  72. package/lib/cjs/src/api/device-model/data/StaticDeviceModelDataSource.test.js +1 -1
  73. package/lib/cjs/src/api/device-model/data/StaticDeviceModelDataSource.test.js.map +2 -2
  74. package/lib/cjs/src/api/device-model/model/DeviceModel.js +1 -1
  75. package/lib/cjs/src/api/device-model/model/DeviceModel.js.map +2 -2
  76. package/lib/cjs/src/api/index.js +1 -1
  77. package/lib/cjs/src/api/index.js.map +2 -2
  78. package/lib/cjs/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.js +1 -1
  79. package/lib/cjs/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.js.map +2 -2
  80. package/lib/cjs/src/api/secure-channel/device-action/GenuineCheck/types.js.map +1 -1
  81. package/lib/cjs/src/api/secure-channel/device-action/InstallApp/InstallAppDeviceAction.js +1 -1
  82. package/lib/cjs/src/api/secure-channel/device-action/InstallApp/InstallAppDeviceAction.js.map +2 -2
  83. package/lib/cjs/src/api/secure-channel/device-action/InstallApp/types.js +1 -1
  84. package/lib/cjs/src/api/secure-channel/device-action/InstallApp/types.js.map +1 -1
  85. package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js +1 -1
  86. package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js.map +2 -2
  87. package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/types.js +1 -1
  88. package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/types.js.map +2 -2
  89. package/lib/cjs/src/api/secure-channel/device-action/UninstallApp/UninstallAppDeviceAction.js +1 -1
  90. package/lib/cjs/src/api/secure-channel/device-action/UninstallApp/UninstallAppDeviceAction.js.map +2 -2
  91. package/lib/cjs/src/api/secure-channel/device-action/UninstallApp/types.js +1 -1
  92. package/lib/cjs/src/api/secure-channel/device-action/UninstallApp/types.js.map +1 -1
  93. package/lib/cjs/src/api/secure-channel/task/ConnectToSecureChannelTask.js +1 -1
  94. package/lib/cjs/src/api/secure-channel/task/ConnectToSecureChannelTask.js.map +3 -3
  95. package/lib/cjs/src/api/secure-channel/task/ConnectToSecureChannelTask.test.js +1 -1
  96. package/lib/cjs/src/api/secure-channel/task/ConnectToSecureChannelTask.test.js.map +3 -3
  97. package/lib/cjs/src/api/secure-channel/task/types.js +1 -1
  98. package/lib/cjs/src/api/secure-channel/task/types.js.map +2 -2
  99. package/lib/cjs/src/api/secure-channel/utils.js +1 -1
  100. package/lib/cjs/src/api/secure-channel/utils.js.map +3 -3
  101. package/lib/cjs/src/api/secure-channel/utils.test.js +1 -1
  102. package/lib/cjs/src/api/secure-channel/utils.test.js.map +3 -3
  103. package/lib/cjs/src/api/transport/model/DeviceConnectionStateMachine.js +1 -1
  104. package/lib/cjs/src/api/transport/model/DeviceConnectionStateMachine.js.map +3 -3
  105. package/lib/cjs/src/api/transport/model/DeviceConnectionStateMachine.test.js +2 -0
  106. package/lib/cjs/src/api/transport/model/DeviceConnectionStateMachine.test.js.map +7 -0
  107. package/lib/cjs/src/api/transport/model/Errors.js +1 -1
  108. package/lib/cjs/src/api/transport/model/Errors.js.map +3 -3
  109. package/lib/cjs/src/api/utils/AppName.js +2 -0
  110. package/lib/cjs/src/api/utils/AppName.js.map +7 -0
  111. package/lib/cjs/src/api/utils/AppName.test.js +2 -0
  112. package/lib/cjs/src/api/utils/AppName.test.js.map +7 -0
  113. package/lib/cjs/src/api/utils/HexaString.js +1 -1
  114. package/lib/cjs/src/api/utils/HexaString.js.map +3 -3
  115. package/lib/cjs/src/api/utils/HexaString.test.js +1 -1
  116. package/lib/cjs/src/api/utils/HexaString.test.js.map +2 -2
  117. package/lib/cjs/src/di.js +1 -1
  118. package/lib/cjs/src/di.js.map +2 -2
  119. package/lib/cjs/src/internal/config/di/configModule.js +1 -1
  120. package/lib/cjs/src/internal/config/di/configModule.js.map +3 -3
  121. package/lib/cjs/src/internal/config/di/configModule.test.js +1 -1
  122. package/lib/cjs/src/internal/config/di/configModule.test.js.map +2 -2
  123. package/lib/cjs/src/internal/device-model/di/deviceModelModule.js +1 -1
  124. package/lib/cjs/src/internal/device-model/di/deviceModelModule.js.map +3 -3
  125. package/lib/cjs/src/internal/device-model/di/deviceModelModule.test.js +1 -1
  126. package/lib/cjs/src/internal/device-model/di/deviceModelModule.test.js.map +2 -2
  127. package/lib/cjs/src/internal/device-session/di/deviceSessionModule.js +1 -1
  128. package/lib/cjs/src/internal/device-session/di/deviceSessionModule.js.map +3 -3
  129. package/lib/cjs/src/internal/device-session/di/deviceSessionModule.test.js +1 -1
  130. package/lib/cjs/src/internal/device-session/di/deviceSessionModule.test.js.map +2 -2
  131. package/lib/cjs/src/internal/device-session/service/DefaultApduReceiverService.js +1 -1
  132. package/lib/cjs/src/internal/device-session/service/DefaultApduReceiverService.js.map +2 -2
  133. package/lib/cjs/src/internal/device-session/service/DefaultApduSenderService.js +1 -1
  134. package/lib/cjs/src/internal/device-session/service/DefaultApduSenderService.js.map +2 -2
  135. package/lib/cjs/src/internal/device-session/service/DefaultApduSenderService.test.js +1 -1
  136. package/lib/cjs/src/internal/device-session/service/DefaultApduSenderService.test.js.map +2 -2
  137. package/lib/cjs/src/internal/discovery/di/discoveryModule.js +1 -1
  138. package/lib/cjs/src/internal/discovery/di/discoveryModule.js.map +3 -3
  139. package/lib/cjs/src/internal/discovery/di/discoveryModule.test.js +1 -1
  140. package/lib/cjs/src/internal/discovery/di/discoveryModule.test.js.map +2 -2
  141. package/lib/cjs/src/internal/logger-publisher/di/loggerModule.js +1 -1
  142. package/lib/cjs/src/internal/logger-publisher/di/loggerModule.js.map +3 -3
  143. package/lib/cjs/src/internal/logger-publisher/di/loggerModule.test.js +1 -1
  144. package/lib/cjs/src/internal/logger-publisher/di/loggerModule.test.js.map +2 -2
  145. package/lib/cjs/src/internal/manager-api/di/managerApiModule.js +1 -1
  146. package/lib/cjs/src/internal/manager-api/di/managerApiModule.js.map +3 -3
  147. package/lib/cjs/src/internal/manager-api/di/managerApiModule.test.js +1 -1
  148. package/lib/cjs/src/internal/manager-api/di/managerApiModule.test.js.map +2 -2
  149. package/lib/cjs/src/internal/secure-channel/di/secureChannelModule.js +1 -1
  150. package/lib/cjs/src/internal/secure-channel/di/secureChannelModule.js.map +3 -3
  151. package/lib/cjs/src/internal/secure-channel/di/secureChannelModule.test.js +1 -1
  152. package/lib/cjs/src/internal/secure-channel/di/secureChannelModule.test.js.map +2 -2
  153. package/lib/cjs/src/internal/secure-channel/model/Errors.js +1 -1
  154. package/lib/cjs/src/internal/secure-channel/model/Errors.js.map +3 -3
  155. package/lib/cjs/src/internal/send/di/sendModule.js +1 -1
  156. package/lib/cjs/src/internal/send/di/sendModule.js.map +3 -3
  157. package/lib/cjs/src/internal/send/di/sendModule.test.js +1 -1
  158. package/lib/cjs/src/internal/send/di/sendModule.test.js.map +2 -2
  159. package/lib/cjs/src/internal/send/use-case/SendApduUseCase.js +1 -1
  160. package/lib/cjs/src/internal/send/use-case/SendApduUseCase.js.map +3 -3
  161. package/lib/cjs/src/internal/transport/di/transportModule.js +1 -1
  162. package/lib/cjs/src/internal/transport/di/transportModule.js.map +3 -3
  163. package/lib/cjs/src/internal/transport/di/transportModule.test.js +1 -1
  164. package/lib/cjs/src/internal/transport/di/transportModule.test.js.map +2 -2
  165. package/lib/esm/package.json +1 -2
  166. package/lib/esm/src/api/DeviceManagementKit.js +1 -1
  167. package/lib/esm/src/api/DeviceManagementKit.js.map +3 -3
  168. package/lib/esm/src/api/DeviceManagementKit.test.js +1 -1
  169. package/lib/esm/src/api/DeviceManagementKit.test.js.map +3 -3
  170. package/lib/esm/src/api/apdu/utils/ByteArrayBuilder.js +1 -1
  171. package/lib/esm/src/api/apdu/utils/ByteArrayBuilder.js.map +3 -3
  172. package/lib/esm/src/api/apdu/utils/ByteArrayBuilder.test.js +1 -1
  173. package/lib/esm/src/api/apdu/utils/ByteArrayBuilder.test.js.map +2 -2
  174. package/lib/esm/src/api/apdu/utils/ByteArrayParser.js +1 -1
  175. package/lib/esm/src/api/apdu/utils/ByteArrayParser.js.map +3 -3
  176. package/lib/esm/src/api/command/di/commandModule.js +1 -1
  177. package/lib/esm/src/api/command/di/commandModule.js.map +3 -3
  178. package/lib/esm/src/api/command/di/commandModule.test.js +1 -1
  179. package/lib/esm/src/api/command/di/commandModule.test.js.map +2 -2
  180. package/lib/esm/src/api/command/os/__mocks__/GetOsVersionCommand.js +1 -1
  181. package/lib/esm/src/api/command/os/__mocks__/GetOsVersionCommand.js.map +2 -2
  182. package/lib/esm/src/api/command/utils/CommandUtils.js +1 -1
  183. package/lib/esm/src/api/command/utils/CommandUtils.js.map +3 -3
  184. package/lib/esm/src/api/command/utils/CommandUtils.test.js +1 -1
  185. package/lib/esm/src/api/command/utils/CommandUtils.test.js.map +2 -2
  186. package/lib/esm/src/api/command/utils/GlobalCommandError.js +1 -1
  187. package/lib/esm/src/api/command/utils/GlobalCommandError.js.map +2 -2
  188. package/lib/esm/src/api/device/DeviceModel.js +1 -1
  189. package/lib/esm/src/api/device/DeviceModel.js.map +2 -2
  190. package/lib/esm/src/api/device-action/di/deviceActionModule.js +1 -1
  191. package/lib/esm/src/api/device-action/di/deviceActionModule.js.map +3 -3
  192. package/lib/esm/src/api/device-action/di/deviceActionModule.test.js +1 -1
  193. package/lib/esm/src/api/device-action/di/deviceActionModule.test.js.map +2 -2
  194. package/lib/esm/src/api/device-action/model/UserInteractionRequired.js +1 -1
  195. package/lib/esm/src/api/device-action/model/UserInteractionRequired.js.map +2 -2
  196. package/lib/esm/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.js +1 -1
  197. package/lib/esm/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.js.map +2 -2
  198. package/lib/esm/src/api/device-action/os/Errors.js +1 -1
  199. package/lib/esm/src/api/device-action/os/Errors.js.map +3 -3
  200. package/lib/esm/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js +1 -1
  201. package/lib/esm/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js.map +2 -2
  202. package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js +1 -1
  203. package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js.map +2 -2
  204. package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js +1 -1
  205. package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js.map +2 -2
  206. package/lib/esm/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.js +1 -1
  207. package/lib/esm/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.js.map +3 -3
  208. package/lib/esm/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js +1 -1
  209. package/lib/esm/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js.map +2 -2
  210. package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.js +1 -1
  211. package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.js.map +3 -3
  212. package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.test.js +1 -1
  213. package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.test.js.map +3 -3
  214. package/lib/esm/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.js +1 -1
  215. package/lib/esm/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.js.map +2 -2
  216. package/lib/esm/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.js +1 -1
  217. package/lib/esm/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.js.map +2 -2
  218. package/lib/esm/src/api/device-action/task/BuildAppsInstallPlanTask.js +1 -1
  219. package/lib/esm/src/api/device-action/task/BuildAppsInstallPlanTask.js.map +3 -3
  220. package/lib/esm/src/api/device-action/task/BuildAppsInstallPlanTask.test.js +1 -1
  221. package/lib/esm/src/api/device-action/task/BuildAppsInstallPlanTask.test.js.map +3 -3
  222. package/lib/esm/src/api/device-action/xstate-utils/XStateDeviceAction.js +1 -1
  223. package/lib/esm/src/api/device-action/xstate-utils/XStateDeviceAction.js.map +2 -2
  224. package/lib/esm/src/api/device-model/data/StaticDeviceModelDataSource.js +1 -1
  225. package/lib/esm/src/api/device-model/data/StaticDeviceModelDataSource.js.map +2 -2
  226. package/lib/esm/src/api/device-model/data/StaticDeviceModelDataSource.test.js +1 -1
  227. package/lib/esm/src/api/device-model/data/StaticDeviceModelDataSource.test.js.map +2 -2
  228. package/lib/esm/src/api/device-model/model/DeviceModel.js +1 -1
  229. package/lib/esm/src/api/device-model/model/DeviceModel.js.map +2 -2
  230. package/lib/esm/src/api/index.js +1 -1
  231. package/lib/esm/src/api/index.js.map +3 -3
  232. package/lib/esm/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.js +1 -1
  233. package/lib/esm/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.js.map +2 -2
  234. package/lib/esm/src/api/secure-channel/device-action/InstallApp/InstallAppDeviceAction.js +1 -1
  235. package/lib/esm/src/api/secure-channel/device-action/InstallApp/InstallAppDeviceAction.js.map +2 -2
  236. package/lib/esm/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js +1 -1
  237. package/lib/esm/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js.map +2 -2
  238. package/lib/esm/src/api/secure-channel/device-action/ListInstalledApps/types.js +1 -1
  239. package/lib/esm/src/api/secure-channel/device-action/ListInstalledApps/types.js.map +2 -2
  240. package/lib/esm/src/api/secure-channel/device-action/UninstallApp/UninstallAppDeviceAction.js +1 -1
  241. package/lib/esm/src/api/secure-channel/device-action/UninstallApp/UninstallAppDeviceAction.js.map +2 -2
  242. package/lib/esm/src/api/secure-channel/task/ConnectToSecureChannelTask.js +1 -1
  243. package/lib/esm/src/api/secure-channel/task/ConnectToSecureChannelTask.js.map +3 -3
  244. package/lib/esm/src/api/secure-channel/task/ConnectToSecureChannelTask.test.js +1 -1
  245. package/lib/esm/src/api/secure-channel/task/ConnectToSecureChannelTask.test.js.map +3 -3
  246. package/lib/esm/src/api/secure-channel/task/types.js +1 -1
  247. package/lib/esm/src/api/secure-channel/task/types.js.map +2 -2
  248. package/lib/esm/src/api/secure-channel/utils.js +1 -1
  249. package/lib/esm/src/api/secure-channel/utils.js.map +3 -3
  250. package/lib/esm/src/api/secure-channel/utils.test.js +1 -1
  251. package/lib/esm/src/api/secure-channel/utils.test.js.map +3 -3
  252. package/lib/esm/src/api/transport/model/DeviceConnectionStateMachine.js +1 -1
  253. package/lib/esm/src/api/transport/model/DeviceConnectionStateMachine.js.map +3 -3
  254. package/lib/esm/src/api/transport/model/DeviceConnectionStateMachine.test.js +2 -0
  255. package/lib/esm/src/api/transport/model/DeviceConnectionStateMachine.test.js.map +7 -0
  256. package/lib/esm/src/api/transport/model/Errors.js +1 -1
  257. package/lib/esm/src/api/transport/model/Errors.js.map +3 -3
  258. package/lib/esm/src/api/utils/AppName.js +2 -0
  259. package/lib/esm/src/api/utils/AppName.js.map +7 -0
  260. package/lib/esm/src/api/utils/AppName.test.js +2 -0
  261. package/lib/esm/src/api/utils/AppName.test.js.map +7 -0
  262. package/lib/esm/src/api/utils/HexaString.js +1 -1
  263. package/lib/esm/src/api/utils/HexaString.js.map +3 -3
  264. package/lib/esm/src/api/utils/HexaString.test.js +1 -1
  265. package/lib/esm/src/api/utils/HexaString.test.js.map +2 -2
  266. package/lib/esm/src/di.js +1 -1
  267. package/lib/esm/src/di.js.map +2 -2
  268. package/lib/esm/src/internal/config/di/configModule.js +1 -1
  269. package/lib/esm/src/internal/config/di/configModule.js.map +3 -3
  270. package/lib/esm/src/internal/config/di/configModule.test.js +1 -1
  271. package/lib/esm/src/internal/config/di/configModule.test.js.map +2 -2
  272. package/lib/esm/src/internal/device-model/di/deviceModelModule.js +1 -1
  273. package/lib/esm/src/internal/device-model/di/deviceModelModule.js.map +3 -3
  274. package/lib/esm/src/internal/device-model/di/deviceModelModule.test.js +1 -1
  275. package/lib/esm/src/internal/device-model/di/deviceModelModule.test.js.map +2 -2
  276. package/lib/esm/src/internal/device-session/di/deviceSessionModule.js +1 -1
  277. package/lib/esm/src/internal/device-session/di/deviceSessionModule.js.map +3 -3
  278. package/lib/esm/src/internal/device-session/di/deviceSessionModule.test.js +1 -1
  279. package/lib/esm/src/internal/device-session/di/deviceSessionModule.test.js.map +2 -2
  280. package/lib/esm/src/internal/device-session/service/DefaultApduReceiverService.js +1 -1
  281. package/lib/esm/src/internal/device-session/service/DefaultApduReceiverService.js.map +2 -2
  282. package/lib/esm/src/internal/device-session/service/DefaultApduSenderService.js +1 -1
  283. package/lib/esm/src/internal/device-session/service/DefaultApduSenderService.js.map +2 -2
  284. package/lib/esm/src/internal/device-session/service/DefaultApduSenderService.test.js +1 -1
  285. package/lib/esm/src/internal/device-session/service/DefaultApduSenderService.test.js.map +2 -2
  286. package/lib/esm/src/internal/discovery/di/discoveryModule.js +1 -1
  287. package/lib/esm/src/internal/discovery/di/discoveryModule.js.map +3 -3
  288. package/lib/esm/src/internal/discovery/di/discoveryModule.test.js +1 -1
  289. package/lib/esm/src/internal/discovery/di/discoveryModule.test.js.map +2 -2
  290. package/lib/esm/src/internal/logger-publisher/di/loggerModule.js +1 -1
  291. package/lib/esm/src/internal/logger-publisher/di/loggerModule.js.map +3 -3
  292. package/lib/esm/src/internal/logger-publisher/di/loggerModule.test.js +1 -1
  293. package/lib/esm/src/internal/logger-publisher/di/loggerModule.test.js.map +2 -2
  294. package/lib/esm/src/internal/manager-api/di/managerApiModule.js +1 -1
  295. package/lib/esm/src/internal/manager-api/di/managerApiModule.js.map +3 -3
  296. package/lib/esm/src/internal/manager-api/di/managerApiModule.test.js +1 -1
  297. package/lib/esm/src/internal/manager-api/di/managerApiModule.test.js.map +2 -2
  298. package/lib/esm/src/internal/secure-channel/di/secureChannelModule.js +1 -1
  299. package/lib/esm/src/internal/secure-channel/di/secureChannelModule.js.map +3 -3
  300. package/lib/esm/src/internal/secure-channel/di/secureChannelModule.test.js +1 -1
  301. package/lib/esm/src/internal/secure-channel/di/secureChannelModule.test.js.map +2 -2
  302. package/lib/esm/src/internal/secure-channel/model/Errors.js +1 -1
  303. package/lib/esm/src/internal/secure-channel/model/Errors.js.map +3 -3
  304. package/lib/esm/src/internal/send/di/sendModule.js +1 -1
  305. package/lib/esm/src/internal/send/di/sendModule.js.map +3 -3
  306. package/lib/esm/src/internal/send/di/sendModule.test.js +1 -1
  307. package/lib/esm/src/internal/send/di/sendModule.test.js.map +2 -2
  308. package/lib/esm/src/internal/send/use-case/SendApduUseCase.js +1 -1
  309. package/lib/esm/src/internal/send/use-case/SendApduUseCase.js.map +3 -3
  310. package/lib/esm/src/internal/transport/di/transportModule.js +1 -1
  311. package/lib/esm/src/internal/transport/di/transportModule.js.map +3 -3
  312. package/lib/esm/src/internal/transport/di/transportModule.test.js +1 -1
  313. package/lib/esm/src/internal/transport/di/transportModule.test.js.map +2 -2
  314. package/lib/types/src/api/DeviceManagementKit.d.ts +4 -0
  315. package/lib/types/src/api/DeviceManagementKit.d.ts.map +1 -1
  316. package/lib/types/src/api/apdu/utils/ApduBuilder.d.ts.map +1 -1
  317. package/lib/types/src/api/apdu/utils/ApduParser.d.ts.map +1 -1
  318. package/lib/types/src/api/apdu/utils/ByteArrayBuilder.d.ts +66 -0
  319. package/lib/types/src/api/apdu/utils/ByteArrayBuilder.d.ts.map +1 -1
  320. package/lib/types/src/api/apdu/utils/ByteArrayParser.d.ts +1 -0
  321. package/lib/types/src/api/apdu/utils/ByteArrayParser.d.ts.map +1 -1
  322. package/lib/types/src/api/command/di/commandModule.d.ts.map +1 -1
  323. package/lib/types/src/api/command/os/__mocks__/GetOsVersionCommand.d.ts.map +1 -1
  324. package/lib/types/src/api/command/utils/CommandErrors.d.ts.map +1 -1
  325. package/lib/types/src/api/command/utils/CommandUtils.d.ts +3 -0
  326. package/lib/types/src/api/command/utils/CommandUtils.d.ts.map +1 -1
  327. package/lib/types/src/api/command/utils/GlobalCommandError.d.ts +1 -1
  328. package/lib/types/src/api/command/utils/GlobalCommandError.d.ts.map +1 -1
  329. package/lib/types/src/api/device/DeviceModel.d.ts +2 -1
  330. package/lib/types/src/api/device/DeviceModel.d.ts.map +1 -1
  331. package/lib/types/src/api/device-action/__test-utils__/setupTestMachine.d.ts.map +1 -1
  332. package/lib/types/src/api/device-action/di/deviceActionModule.d.ts.map +1 -1
  333. package/lib/types/src/api/device-action/model/UserInteractionRequired.d.ts +1 -0
  334. package/lib/types/src/api/device-action/model/UserInteractionRequired.d.ts.map +1 -1
  335. package/lib/types/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.d.ts.map +1 -1
  336. package/lib/types/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceActionTypes.d.ts +0 -1
  337. package/lib/types/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceActionTypes.d.ts.map +1 -1
  338. package/lib/types/src/api/device-action/os/Errors.d.ts +10 -0
  339. package/lib/types/src/api/device-action/os/Errors.d.ts.map +1 -1
  340. package/lib/types/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.d.ts.map +1 -1
  341. package/lib/types/src/api/device-action/os/GetDeviceMetadata/types.d.ts +2 -1
  342. package/lib/types/src/api/device-action/os/GetDeviceMetadata/types.d.ts.map +1 -1
  343. package/lib/types/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.d.ts.map +1 -1
  344. package/lib/types/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.d.ts.map +1 -1
  345. package/lib/types/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.d.ts.map +1 -1
  346. package/lib/types/src/api/device-action/os/InstallOrUpdateApps/types.d.ts +3 -2
  347. package/lib/types/src/api/device-action/os/InstallOrUpdateApps/types.d.ts.map +1 -1
  348. package/lib/types/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.d.ts.map +1 -1
  349. package/lib/types/src/api/device-action/os/OpenAppDeviceAction/types.d.ts +0 -1
  350. package/lib/types/src/api/device-action/os/OpenAppDeviceAction/types.d.ts.map +1 -1
  351. package/lib/types/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.d.ts.map +1 -1
  352. package/lib/types/src/api/device-action/os/OpenAppWithDependencies/types.d.ts +0 -1
  353. package/lib/types/src/api/device-action/os/OpenAppWithDependencies/types.d.ts.map +1 -1
  354. package/lib/types/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.d.ts.map +1 -1
  355. package/lib/types/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceActionTypes.d.ts +0 -1
  356. package/lib/types/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceActionTypes.d.ts.map +1 -1
  357. package/lib/types/src/api/device-action/task/BuildAppsInstallPlanTask.d.ts +2 -2
  358. package/lib/types/src/api/device-action/task/BuildAppsInstallPlanTask.d.ts.map +1 -1
  359. package/lib/types/src/api/device-action/xstate-utils/XStateDeviceAction.d.ts +1 -0
  360. package/lib/types/src/api/device-action/xstate-utils/XStateDeviceAction.d.ts.map +1 -1
  361. package/lib/types/src/api/device-model/data/StaticDeviceModelDataSource.d.ts.map +1 -1
  362. package/lib/types/src/api/device-model/model/DeviceModel.d.ts.map +1 -1
  363. package/lib/types/src/api/device-session/service/DefaultApduReceiverService.stub.d.ts.map +1 -1
  364. package/lib/types/src/api/device-session/service/DefaultApduSenderService.stub.d.ts.map +1 -1
  365. package/lib/types/src/api/index.d.ts +1 -1
  366. package/lib/types/src/api/index.d.ts.map +1 -1
  367. package/lib/types/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.d.ts.map +1 -1
  368. package/lib/types/src/api/secure-channel/device-action/GenuineCheck/types.d.ts +2 -1
  369. package/lib/types/src/api/secure-channel/device-action/GenuineCheck/types.d.ts.map +1 -1
  370. package/lib/types/src/api/secure-channel/device-action/InstallApp/InstallAppDeviceAction.d.ts.map +1 -1
  371. package/lib/types/src/api/secure-channel/device-action/InstallApp/types.d.ts +2 -1
  372. package/lib/types/src/api/secure-channel/device-action/InstallApp/types.d.ts.map +1 -1
  373. package/lib/types/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.d.ts.map +1 -1
  374. package/lib/types/src/api/secure-channel/device-action/ListInstalledApps/types.d.ts +2 -1
  375. package/lib/types/src/api/secure-channel/device-action/ListInstalledApps/types.d.ts.map +1 -1
  376. package/lib/types/src/api/secure-channel/device-action/UninstallApp/UninstallAppDeviceAction.d.ts.map +1 -1
  377. package/lib/types/src/api/secure-channel/device-action/UninstallApp/types.d.ts +2 -1
  378. package/lib/types/src/api/secure-channel/device-action/UninstallApp/types.d.ts.map +1 -1
  379. package/lib/types/src/api/secure-channel/task/ConnectToSecureChannelTask.d.ts +5 -2
  380. package/lib/types/src/api/secure-channel/task/ConnectToSecureChannelTask.d.ts.map +1 -1
  381. package/lib/types/src/api/secure-channel/task/types.d.ts +6 -1
  382. package/lib/types/src/api/secure-channel/task/types.d.ts.map +1 -1
  383. package/lib/types/src/api/secure-channel/utils.d.ts +0 -11
  384. package/lib/types/src/api/secure-channel/utils.d.ts.map +1 -1
  385. package/lib/types/src/api/transport/model/DeviceConnectionStateMachine.d.ts +8 -7
  386. package/lib/types/src/api/transport/model/DeviceConnectionStateMachine.d.ts.map +1 -1
  387. package/lib/types/src/api/transport/model/DeviceConnectionStateMachine.test.d.ts +2 -0
  388. package/lib/types/src/api/transport/model/DeviceConnectionStateMachine.test.d.ts.map +1 -0
  389. package/lib/types/src/api/transport/model/Errors.d.ts +5 -0
  390. package/lib/types/src/api/transport/model/Errors.d.ts.map +1 -1
  391. package/lib/types/src/api/utils/AppName.d.ts +2 -0
  392. package/lib/types/src/api/utils/AppName.d.ts.map +1 -0
  393. package/lib/types/src/api/utils/AppName.test.d.ts +2 -0
  394. package/lib/types/src/api/utils/AppName.test.d.ts.map +1 -0
  395. package/lib/types/src/api/utils/HexaString.d.ts +4 -3
  396. package/lib/types/src/api/utils/HexaString.d.ts.map +1 -1
  397. package/lib/types/src/di.d.ts.map +1 -1
  398. package/lib/types/src/internal/config/di/configModule.d.ts.map +1 -1
  399. package/lib/types/src/internal/device-model/di/deviceModelModule.d.ts.map +1 -1
  400. package/lib/types/src/internal/device-session/di/deviceSessionModule.d.ts.map +1 -1
  401. package/lib/types/src/internal/device-session/model/DeviceSession.stub.d.ts.map +1 -1
  402. package/lib/types/src/internal/device-session/service/DefaultApduReceiverService.d.ts.map +1 -1
  403. package/lib/types/src/internal/device-session/utils/deviceSessionUtils.d.ts.map +1 -1
  404. package/lib/types/src/internal/discovery/di/discoveryModule.d.ts.map +1 -1
  405. package/lib/types/src/internal/logger-publisher/di/loggerModule.d.ts.map +1 -1
  406. package/lib/types/src/internal/manager-api/di/managerApiModule.d.ts.map +1 -1
  407. package/lib/types/src/internal/secure-channel/di/secureChannelModule.d.ts.map +1 -1
  408. package/lib/types/src/internal/secure-channel/model/Errors.d.ts +22 -2
  409. package/lib/types/src/internal/secure-channel/model/Errors.d.ts.map +1 -1
  410. package/lib/types/src/internal/send/di/sendModule.d.ts.map +1 -1
  411. package/lib/types/src/internal/send/use-case/SendApduUseCase.d.ts +5 -1
  412. package/lib/types/src/internal/send/use-case/SendApduUseCase.d.ts.map +1 -1
  413. package/lib/types/src/internal/transport/di/transportModule.d.ts.map +1 -1
  414. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  415. package/package.json +5 -6
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/api/secure-channel/device-action/ListInstalledApps/types.ts"],
4
- "sourcesContent": ["import { type EitherAsync } from \"purify-ts\";\nimport { type Observable } from \"rxjs\";\n\nimport { type CommandErrorResult } from \"@api/command/model/CommandResult\";\nimport {\n type GetOsVersionCommandResult,\n type GetOsVersionResponse,\n} from \"@api/command/os/GetOsVersionCommand\";\nimport { type DeviceActionState } from \"@api/device-action/model/DeviceActionState\";\nimport { type UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { type UnknownDAError } from \"@api/device-action/os/Errors\";\nimport {\n type GoToDashboardDAError,\n type GoToDashboardDAInput,\n} from \"@api/device-action/os/GoToDashboard/types\";\nimport { type DeviceSessionState } from \"@api/device-session/DeviceSessionState\";\nimport { type SecureChannelEvent } from \"@api/secure-channel/task/types\";\nimport { type Input } from \"@api/secure-channel/types\";\nimport { type DeviceVersion } from \"@internal/manager-api/model/Device\";\nimport { type HttpFetchApiError } from \"@internal/manager-api/model/Errors\";\nimport { type FinalFirmware } from \"@internal/manager-api/model/Firmware\";\n\nexport type ListInstalledAppsDAOutput = {\n installedApps: Array<InstalledApp>;\n};\n\nexport type ListInstalledAppsDAInput = GoToDashboardDAInput;\n\nexport type ListInstalledAppsDAError =\n | CommandErrorResult[\"error\"]\n | GoToDashboardDAError\n | HttpFetchApiError\n | UnknownDAError;\n\nexport type ListInstalledAppsDARequiredInteraction =\n | UserInteractionRequired.None\n | UserInteractionRequired.UnlockDevice\n | UserInteractionRequired.AllowSecureConnection;\n\nexport type ListInstalledAppsDAIntermediateValue = {\n requiredUserInteraction: ListInstalledAppsDARequiredInteraction;\n};\n\nexport type ListInstalledAppsDAState = DeviceActionState<\n ListInstalledAppsDAOutput,\n ListInstalledAppsDAError,\n ListInstalledAppsDAIntermediateValue\n>;\n\nexport type ListInstalledAppsStateMachineInternalState = {\n error: ListInstalledAppsDAError | null;\n result: { installedApps: Array<InstalledApp> };\n getOsVersionResponse: GetOsVersionResponse | null;\n deviceVersion: DeviceVersion | null;\n firmwareVersion: FinalFirmware | null;\n};\n\nexport type MachineDependencies = {\n getOsVersion: () => Promise<GetOsVersionCommandResult>;\n getDeviceVersion: (\n args: Input<{ deviceInfo: GetOsVersionResponse }>,\n ) => EitherAsync<HttpFetchApiError, DeviceVersion>;\n getFirmwareVersion: (\n args: Input<{\n deviceInfo: GetOsVersionResponse;\n deviceVersion: DeviceVersion;\n }>,\n ) => EitherAsync<HttpFetchApiError, FinalFirmware>;\n listInstalledApps: (\n args: Input<{\n deviceInfo: GetOsVersionResponse;\n finalFirmware: FinalFirmware;\n }>,\n ) => Observable<SecureChannelEvent>;\n getDeviceSessionState: () => DeviceSessionState;\n setDeviceSessionState: (state: DeviceSessionState) => DeviceSessionState;\n};\n\nexport type InstalledApp = {\n flags: number;\n hash: string;\n hash_code_data: string;\n name: string;\n};\n\nexport function installedAppResultGuard(\n value: unknown,\n): value is ListInstalledAppsDAOutput[\"installedApps\"] {\n return (\n Array.isArray(value) &&\n value.every(\n (item) =>\n typeof item === \"object\" &&\n item !== null &&\n \"flags\" in item &&\n \"hash\" in item &&\n \"hash_code_data\" in item &&\n \"name\" in item &&\n typeof item.flags === \"number\" &&\n typeof item.hash === \"string\" &&\n typeof item.hash_code_data === \"string\" &&\n typeof item.name === \"string\",\n )\n );\n}\n"],
5
- "mappings": "AAqFO,SAASA,EACdC,EACqD,CACrD,OACE,MAAM,QAAQA,CAAK,GACnBA,EAAM,MACHC,GACC,OAAOA,GAAS,UAChBA,IAAS,MACT,UAAWA,GACX,SAAUA,GACV,mBAAoBA,GACpB,SAAUA,GACV,OAAOA,EAAK,OAAU,UACtB,OAAOA,EAAK,MAAS,UACrB,OAAOA,EAAK,gBAAmB,UAC/B,OAAOA,EAAK,MAAS,QACzB,CAEJ",
4
+ "sourcesContent": ["import { type EitherAsync } from \"purify-ts\";\nimport { type Observable } from \"rxjs\";\n\nimport { type CommandErrorResult } from \"@api/command/model/CommandResult\";\nimport {\n type GetOsVersionCommandResult,\n type GetOsVersionResponse,\n} from \"@api/command/os/GetOsVersionCommand\";\nimport { type DeviceActionState } from \"@api/device-action/model/DeviceActionState\";\nimport { type UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { type UnknownDAError } from \"@api/device-action/os/Errors\";\nimport {\n type GoToDashboardDAError,\n type GoToDashboardDAInput,\n} from \"@api/device-action/os/GoToDashboard/types\";\nimport { type DeviceSessionState } from \"@api/device-session/DeviceSessionState\";\nimport { type SecureChannelEvent } from \"@api/secure-channel/task/types\";\nimport { type Input } from \"@api/secure-channel/types\";\nimport { type DeviceVersion } from \"@internal/manager-api/model/Device\";\nimport { type HttpFetchApiError } from \"@internal/manager-api/model/Errors\";\nimport { type FinalFirmware } from \"@internal/manager-api/model/Firmware\";\nimport type { SecureChannelDAErrors } from \"@internal/secure-channel/model/Errors\";\n\nexport type ListInstalledAppsDAOutput = {\n installedApps: Array<InstalledApp>;\n};\n\nexport type ListInstalledAppsDAInput = GoToDashboardDAInput;\n\nexport type ListInstalledAppsDAError =\n | CommandErrorResult[\"error\"]\n | GoToDashboardDAError\n | HttpFetchApiError\n | SecureChannelDAErrors\n | UnknownDAError;\n\nexport type ListInstalledAppsDARequiredInteraction =\n | UserInteractionRequired.None\n | UserInteractionRequired.UnlockDevice\n | UserInteractionRequired.AllowSecureConnection;\n\nexport type ListInstalledAppsDAIntermediateValue = {\n requiredUserInteraction: ListInstalledAppsDARequiredInteraction;\n};\n\nexport type ListInstalledAppsDAState = DeviceActionState<\n ListInstalledAppsDAOutput,\n ListInstalledAppsDAError,\n ListInstalledAppsDAIntermediateValue\n>;\n\nexport type ListInstalledAppsStateMachineInternalState = {\n error: ListInstalledAppsDAError | null;\n result: { installedApps: Array<InstalledApp> };\n getOsVersionResponse: GetOsVersionResponse | null;\n deviceVersion: DeviceVersion | null;\n firmwareVersion: FinalFirmware | null;\n};\n\nexport type MachineDependencies = {\n getOsVersion: () => Promise<GetOsVersionCommandResult>;\n getDeviceVersion: (\n args: Input<{ deviceInfo: GetOsVersionResponse }>,\n ) => EitherAsync<HttpFetchApiError, DeviceVersion>;\n getFirmwareVersion: (\n args: Input<{\n deviceInfo: GetOsVersionResponse;\n deviceVersion: DeviceVersion;\n }>,\n ) => EitherAsync<HttpFetchApiError, FinalFirmware>;\n listInstalledApps: (\n args: Input<{\n deviceInfo: GetOsVersionResponse;\n finalFirmware: FinalFirmware;\n }>,\n ) => Observable<SecureChannelEvent>;\n getDeviceSessionState: () => DeviceSessionState;\n setDeviceSessionState: (state: DeviceSessionState) => DeviceSessionState;\n};\n\nexport type InstalledApp = {\n flags: number;\n hash: string;\n hash_code_data: string;\n name: string;\n};\n\nexport function installedAppResultGuard(\n value: unknown,\n): value is ListInstalledAppsDAOutput[\"installedApps\"] {\n return (\n Array.isArray(value) &&\n value.every(\n (item) =>\n typeof item === \"object\" &&\n item !== null &&\n \"flags\" in item &&\n \"hash\" in item &&\n \"hash_code_data\" in item &&\n \"name\" in item &&\n typeof item.flags === \"number\" &&\n typeof item.hash === \"string\" &&\n typeof item.hash_code_data === \"string\" &&\n typeof item.name === \"string\",\n )\n );\n}\n"],
5
+ "mappings": "AAuFO,SAASA,EACdC,EACqD,CACrD,OACE,MAAM,QAAQA,CAAK,GACnBA,EAAM,MACHC,GACC,OAAOA,GAAS,UAChBA,IAAS,MACT,UAAWA,GACX,SAAUA,GACV,mBAAoBA,GACpB,SAAUA,GACV,OAAOA,EAAK,OAAU,UACtB,OAAOA,EAAK,MAAS,UACrB,OAAOA,EAAK,gBAAmB,UAC/B,OAAOA,EAAK,MAAS,QACzB,CAEJ",
6
6
  "names": ["installedAppResultGuard", "value", "item"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{Left as D,Right as v}from"purify-ts";import{assign as a,fromObservable as I,fromPromise as d,setup as f}from"xstate";import{isSuccessCommandResult as y}from"../../../command/model/CommandResult";import{GetOsVersionCommand as E}from"../../../command/os/GetOsVersionCommand";import{UserInteractionRequired as p}from"../../../device-action/model/UserInteractionRequired";import{DEFAULT_UNLOCK_TIMEOUT_MS as U}from"../../../device-action/os/Const";import{UnknownDAError as A}from"../../../device-action/os/Errors";import{GoToDashboardDeviceAction as x}from"../../../device-action/os/GoToDashboard/GoToDashboardDeviceAction";import{XStateDeviceAction as O}from"../../../device-action/xstate-utils/XStateDeviceAction";import{DeviceSessionStateType as m}from"../../../device-session/DeviceSessionState";import{ListInstalledAppsDeviceAction as V}from"../../../secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction";import{ConnectToSecureChannelTask as T}from"../../../secure-channel/task/ConnectToSecureChannelTask";import{SecureChannelEventType as S}from"../../../secure-channel/task/types";class P extends O{makeStateMachine(n){const{getOsVersion:l,getAppsByHash:c,uninstallApp:u,getDeviceSessionState:r,setDeviceSessionState:s}=this.extractDependencies(n),o=this.input.unlockTimeout??U,i=new x({input:{unlockTimeout:o}}).makeStateMachine(n),h=new V({input:{unlockTimeout:o}}).makeStateMachine(n);return f({types:{input:{},context:{},output:{}},actors:{listInstalledApps:h,goToDashboard:i,getOsVersion:d(l),getAppsByHash:d(c),uninstallApp:I(u)},guards:{hasError:t=>t.context._internalState.error!==null,appNotInstalled:t=>!t.context._internalState.installedApps.some(e=>e.name===t.context.input.appName),appNotFound:t=>t.context._internalState.appList.findIndex(e=>e?.versionName===t.context.input.appName)===-1,isDepAppOfOther:t=>t.context._internalState.appList.some(e=>e?.parentName===t.context.input.appName)},actions:{assignErrorFromEvent:a({_internalState:t=>({...t.context._internalState,error:t.event.error})}),assignAppNotFound:a({_internalState:t=>({...t.context._internalState,error:new A("App to uninstall not found in manager API")})}),assignIsDepAppOfOther:a({_internalState:t=>({...t.context._internalState,error:new A("App to uninstall is a dependency of another installed app")})}),cleanupDeviceState:()=>{const t=r();t.sessionStateType!==m.Connected&&s({...t,installedApps:[],appsUpdates:void 0})}}}).createMachine({id:"UninstallAppDeviceAction",initial:"DeviceReady",context:t=>({input:{unlockTimeout:t.input.unlockTimeout,appName:t.input.appName},intermediateValue:{requiredUserInteraction:p.None},_internalState:{error:null,installedApps:[],appList:[],getOsVersionResponse:null}}),states:{DeviceReady:{always:{target:"ListInstalledApps"}},ListInstalledApps:{invoke:{id:"listInstalledApps",src:"listInstalledApps",input:t=>({unlockTimeout:t.context.input.unlockTimeout}),onSnapshot:{actions:a({intermediateValue:t=>({...t.context.intermediateValue,requiredUserInteraction:t.event.snapshot.context.intermediateValue.requiredUserInteraction})})},onDone:{target:"ListInstalledAppsCheck",actions:a({_internalState:t=>t.event.output.caseOf({Right:({installedApps:e})=>({...t.context._internalState,installedApps:e,hasCheckedInstalledApps:!0}),Left:e=>({...t.context._internalState,error:e})})})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},ListInstalledAppsCheck:{always:[{target:"Error",guard:"hasError"},{target:"Success",guard:"appNotInstalled"},{target:"GetAppsByHash"}]},GetAppsByHash:{invoke:{id:"getAppsByHash",src:"getAppsByHash",input:t=>t.context._internalState.installedApps,onDone:{target:"GetAppsByHashCheck",actions:a({_internalState:t=>t.event.output.caseOf({Right:e=>({...t.context._internalState,appList:e}),Left:e=>({...t.context._internalState,error:e})})})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},GetAppsByHashCheck:{always:[{target:"Error",guard:"hasError"},{target:"Error",guard:"appNotFound",actions:"assignAppNotFound"},{target:"Error",guard:"isDepAppOfOther",actions:"assignIsDepAppOfOther"},{target:"GoToDashboard"}]},GoToDashboard:{invoke:{id:"goToDashboard",src:"goToDashboard",input:t=>({unlockTimeout:t.context.input.unlockTimeout}),onSnapshot:{actions:a({intermediateValue:t=>({...t.context.intermediateValue,requiredUserInteraction:t.event.snapshot.context.intermediateValue.requiredUserInteraction})})},onDone:{target:"GoToDashboardCheck",actions:a({_internalState:t=>t.event.output.caseOf({Right:()=>t.context._internalState,Left:e=>({...t.context._internalState,error:e})})})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},GoToDashboardCheck:{always:[{target:"Error",guard:"hasError"},{target:"GetOsVersion"}]},GetOsVersion:{invoke:{id:"getOsVersion",src:"getOsVersion",input:t=>{},onDone:{target:"GetOsVersionCheck",actions:a({_internalState:t=>{if(y(t.event.output)){const e=r(),g=t.event.output.data.secureElementFlags.isSecureConnectionAllowed;return e.sessionStateType!==m.Connected&&s({...e,isSecureConnectionAllowed:g}),{...t.context._internalState,getOsVersionResponse:t.event.output.data}}return{...t.context._internalState,error:t.event.output.error}}})}}},GetOsVersionCheck:{always:[{target:"Error",guard:"hasError"},{target:"UninstallApp"}]},UninstallApp:{invoke:{id:"uninstallApp",src:"uninstallApp",input:t=>({deviceInfo:t.context._internalState.getOsVersionResponse,app:t.context._internalState.appList.find(e=>e?.versionName===t.context.input.appName)}),onSnapshot:{actions:a({intermediateValue:t=>{switch(t.event.snapshot.context?.type){case S.PermissionRequested:return{requiredUserInteraction:p.AllowSecureConnection};case S.PermissionGranted:return{requiredUserInteraction:p.None};default:return{...t.context.intermediateValue}}}})},onDone:{target:"ListInstalledApps",actions:"cleanupDeviceState"},onError:{target:"Error",actions:"assignErrorFromEvent"}}},Success:{type:"final",description:"App uninstalled successfully"},Error:{type:"final"}},output:({context:t})=>t._internalState.error?D(t._internalState.error):v(void 0)})}extractDependencies(n){return{getOsVersion:()=>n.sendCommand(new E),getAppsByHash:({input:r})=>{const s=r.map(o=>o.hash);return n.getManagerApiService().getAppsByHash(s)},uninstallApp:({input:r})=>{const{deviceInfo:s,app:o}=r,i=n.getSecureChannelService().uninstallApp(s,o);return new T(n,{connection:i}).run()},getDeviceSessionState:()=>n.getDeviceSessionState(),setDeviceSessionState:r=>n.setDeviceSessionState(r)}}}export{P as UninstallAppDeviceAction};
1
+ import{Left as D,Right as v}from"purify-ts";import{assign as a,fromObservable as I,fromPromise as A,setup as f}from"xstate";import{isSuccessCommandResult as y}from"../../../command/model/CommandResult";import{GetOsVersionCommand as x}from"../../../command/os/GetOsVersionCommand";import{UserInteractionRequired as p}from"../../../device-action/model/UserInteractionRequired";import{DEFAULT_UNLOCK_TIMEOUT_MS as E}from"../../../device-action/os/Const";import{UnknownDAError as m}from"../../../device-action/os/Errors";import{GoToDashboardDeviceAction as U}from"../../../device-action/os/GoToDashboard/GoToDashboardDeviceAction";import{XStateDeviceAction as O}from"../../../device-action/xstate-utils/XStateDeviceAction";import{DeviceSessionStateType as S}from"../../../device-session/DeviceSessionState";import{ListInstalledAppsDeviceAction as V}from"../../../secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction";import{ConnectToSecureChannelTask as T}from"../../../secure-channel/task/ConnectToSecureChannelTask";import{SecureChannelEventType as l}from"../../../secure-channel/task/types";class P extends O{makeStateMachine(n){const{getOsVersion:c,getAppsByHash:u,uninstallApp:d,getDeviceSessionState:r,setDeviceSessionState:s}=this.extractDependencies(n),o=this.input.unlockTimeout??E,i=new U({input:{unlockTimeout:o}}).makeStateMachine(n),h=new V({input:{unlockTimeout:o}}).makeStateMachine(n);return f({types:{input:{},context:{},output:{}},actors:{listInstalledApps:h,goToDashboard:i,getOsVersion:A(c),getAppsByHash:A(u),uninstallApp:I(d)},guards:{hasError:t=>t.context._internalState.error!==null,appNotInstalled:t=>!t.context._internalState.installedApps.some(e=>e.name===t.context.input.appName),appNotFound:t=>t.context._internalState.appList.findIndex(e=>e?.versionName===t.context.input.appName)===-1,isDepAppOfOther:t=>t.context._internalState.appList.some(e=>e?.parentName===t.context.input.appName)},actions:{assignErrorFromEvent:a({_internalState:t=>({...t.context._internalState,error:t.event.error})}),assignAppNotFound:a({_internalState:t=>({...t.context._internalState,error:new m("App to uninstall not found in manager API")})}),assignIsDepAppOfOther:a({_internalState:t=>({...t.context._internalState,error:new m("App to uninstall is a dependency of another installed app")})}),cleanupDeviceState:()=>{const t=r();t.sessionStateType!==S.Connected&&s({...t,installedApps:[],appsUpdates:void 0})}}}).createMachine({id:"UninstallAppDeviceAction",initial:"DeviceReady",context:t=>({input:{unlockTimeout:t.input.unlockTimeout,appName:t.input.appName},intermediateValue:{requiredUserInteraction:p.None},_internalState:{error:null,installedApps:[],appList:[],getOsVersionResponse:null}}),states:{DeviceReady:{always:{target:"ListInstalledApps"}},ListInstalledApps:{invoke:{id:"listInstalledApps",src:"listInstalledApps",input:t=>({unlockTimeout:t.context.input.unlockTimeout}),onSnapshot:{actions:a({intermediateValue:t=>({...t.context.intermediateValue,requiredUserInteraction:t.event.snapshot.context.intermediateValue.requiredUserInteraction})})},onDone:{target:"ListInstalledAppsCheck",actions:a({_internalState:t=>t.event.output.caseOf({Right:({installedApps:e})=>({...t.context._internalState,installedApps:e,hasCheckedInstalledApps:!0}),Left:e=>({...t.context._internalState,error:e})})})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},ListInstalledAppsCheck:{always:[{target:"Error",guard:"hasError"},{target:"Success",guard:"appNotInstalled"},{target:"GetAppsByHash"}]},GetAppsByHash:{invoke:{id:"getAppsByHash",src:"getAppsByHash",input:t=>t.context._internalState.installedApps,onDone:{target:"GetAppsByHashCheck",actions:a({_internalState:t=>t.event.output.caseOf({Right:e=>({...t.context._internalState,appList:e}),Left:e=>({...t.context._internalState,error:e})})})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},GetAppsByHashCheck:{always:[{target:"Error",guard:"hasError"},{target:"Error",guard:"appNotFound",actions:"assignAppNotFound"},{target:"Error",guard:"isDepAppOfOther",actions:"assignIsDepAppOfOther"},{target:"GoToDashboard"}]},GoToDashboard:{invoke:{id:"goToDashboard",src:"goToDashboard",input:t=>({unlockTimeout:t.context.input.unlockTimeout}),onSnapshot:{actions:a({intermediateValue:t=>({...t.context.intermediateValue,requiredUserInteraction:t.event.snapshot.context.intermediateValue.requiredUserInteraction})})},onDone:{target:"GoToDashboardCheck",actions:a({_internalState:t=>t.event.output.caseOf({Right:()=>t.context._internalState,Left:e=>({...t.context._internalState,error:e})})})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},GoToDashboardCheck:{always:[{target:"Error",guard:"hasError"},{target:"GetOsVersion"}]},GetOsVersion:{invoke:{id:"getOsVersion",src:"getOsVersion",input:t=>{},onDone:{target:"GetOsVersionCheck",actions:a({_internalState:t=>{if(y(t.event.output)){const e=r(),g=t.event.output.data.secureElementFlags.isSecureConnectionAllowed;return e.sessionStateType!==S.Connected&&s({...e,isSecureConnectionAllowed:g}),{...t.context._internalState,getOsVersionResponse:t.event.output.data}}return{...t.context._internalState,error:t.event.output.error}}})}}},GetOsVersionCheck:{always:[{target:"Error",guard:"hasError"},{target:"UninstallApp"}]},UninstallApp:{invoke:{id:"uninstallApp",src:"uninstallApp",input:t=>({deviceInfo:t.context._internalState.getOsVersionResponse,app:t.context._internalState.appList.find(e=>e?.versionName===t.context.input.appName)}),onSnapshot:{actions:a({intermediateValue:t=>{switch(t.event.snapshot.context?.type){case l.PermissionRequested:return{requiredUserInteraction:p.AllowSecureConnection};case l.PermissionGranted:return{requiredUserInteraction:p.None};default:return{...t.context.intermediateValue}}},_internalState:t=>t.event.snapshot.context?.type===l.Error?{...t.context._internalState,error:t.event.snapshot.context.error.mapDAErrors()}:t.context._internalState})},onDone:{target:"ListInstalledApps",actions:"cleanupDeviceState"},onError:{target:"Error",actions:"assignErrorFromEvent"}}},Success:{type:"final",description:"App uninstalled successfully"},Error:{type:"final"}},output:({context:t})=>t._internalState.error?D(t._internalState.error):v(void 0)})}extractDependencies(n){return{getOsVersion:()=>n.sendCommand(new x),getAppsByHash:({input:r})=>{const s=r.map(o=>o.hash);return n.getManagerApiService().getAppsByHash(s)},uninstallApp:({input:r})=>{const{deviceInfo:s,app:o}=r,i=n.getSecureChannelService().uninstallApp(s,o);return new T(n,{connection:i}).run()},getDeviceSessionState:()=>n.getDeviceSessionState(),setDeviceSessionState:r=>n.setDeviceSessionState(r)}}}export{P as UninstallAppDeviceAction};
2
2
  //# sourceMappingURL=UninstallAppDeviceAction.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/api/secure-channel/device-action/UninstallApp/UninstallAppDeviceAction.ts"],
4
- "sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport { assign, fromObservable, fromPromise, setup } from \"xstate\";\n\nimport { isSuccessCommandResult } from \"@api/command/model/CommandResult\";\nimport {\n GetOsVersionCommand,\n type GetOsVersionResponse,\n} from \"@api/command/os/GetOsVersionCommand\";\nimport { type InternalApi } from \"@api/device-action/DeviceAction\";\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { DEFAULT_UNLOCK_TIMEOUT_MS } from \"@api/device-action/os/Const\";\nimport { UnknownDAError } from \"@api/device-action/os/Errors\";\nimport { GoToDashboardDeviceAction } from \"@api/device-action/os/GoToDashboard/GoToDashboardDeviceAction\";\nimport { type StateMachineTypes } from \"@api/device-action/xstate-utils/StateMachineTypes\";\nimport {\n type DeviceActionStateMachine,\n XStateDeviceAction,\n} from \"@api/device-action/xstate-utils/XStateDeviceAction\";\nimport {\n type DeviceSessionState,\n DeviceSessionStateType,\n} from \"@api/device-session/DeviceSessionState\";\nimport { ListInstalledAppsDeviceAction } from \"@api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction\";\nimport { type InstalledApp } from \"@api/secure-channel/device-action/ListInstalledApps/types\";\nimport { ConnectToSecureChannelTask } from \"@api/secure-channel/task/ConnectToSecureChannelTask\";\nimport { SecureChannelEventType } from \"@api/secure-channel/task/types\";\nimport { type Input } from \"@api/secure-channel/types\";\nimport { type Application } from \"@internal/manager-api/model/Application\";\n\nimport {\n type MachineDependencies,\n type UninstallAppDAError,\n type UninstallAppDAInput,\n type UninstallAppDAIntermediateValue,\n type UninstallAppDAOutput,\n type UninstallAppStateMachineInternalState,\n} from \"./types\";\n\nexport class UninstallAppDeviceAction extends XStateDeviceAction<\n UninstallAppDAOutput,\n UninstallAppDAInput,\n UninstallAppDAError,\n UninstallAppDAIntermediateValue,\n UninstallAppStateMachineInternalState\n> {\n override makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n UninstallAppDAOutput,\n UninstallAppDAInput,\n UninstallAppDAError,\n UninstallAppDAIntermediateValue,\n UninstallAppStateMachineInternalState\n > {\n type types = StateMachineTypes<\n UninstallAppDAOutput,\n UninstallAppDAInput,\n UninstallAppDAError,\n UninstallAppDAIntermediateValue,\n UninstallAppStateMachineInternalState\n >;\n\n const {\n getOsVersion,\n getAppsByHash,\n uninstallApp,\n getDeviceSessionState,\n setDeviceSessionState,\n } = this.extractDependencies(internalApi);\n\n const unlockTimeout = this.input.unlockTimeout ?? DEFAULT_UNLOCK_TIMEOUT_MS;\n\n const goToDashboardMachine = new GoToDashboardDeviceAction({\n input: {\n unlockTimeout,\n },\n }).makeStateMachine(internalApi);\n\n const listInstalledAppsMachine = new ListInstalledAppsDeviceAction({\n input: {\n unlockTimeout,\n },\n }).makeStateMachine(internalApi);\n\n return setup({\n types: {\n input: {} as types[\"input\"],\n context: {} as types[\"context\"],\n output: {} as types[\"output\"],\n },\n actors: {\n listInstalledApps: listInstalledAppsMachine,\n goToDashboard: goToDashboardMachine,\n getOsVersion: fromPromise(getOsVersion),\n getAppsByHash: fromPromise(getAppsByHash),\n uninstallApp: fromObservable(uninstallApp),\n },\n guards: {\n hasError: (_) => _.context._internalState.error !== null,\n appNotInstalled: (_) =>\n !_.context._internalState.installedApps.some(\n (app) => app.name === _.context.input.appName,\n ),\n appNotFound: (_) =>\n _.context._internalState.appList.findIndex(\n (app) => app?.versionName === _.context.input.appName,\n ) === -1,\n isDepAppOfOther: (_) =>\n _.context._internalState.appList.some(\n (app) => app?.parentName === _.context.input.appName,\n ),\n },\n actions: {\n assignErrorFromEvent: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: _.event[\"error\"],\n }),\n }),\n assignAppNotFound: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: new UnknownDAError(\n \"App to uninstall not found in manager API\",\n ),\n }),\n }),\n assignIsDepAppOfOther: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: new UnknownDAError(\n \"App to uninstall is a dependency of another installed app\",\n ),\n }),\n }),\n cleanupDeviceState: () => {\n // After app successful uninstallation, cleanup the device session state\n // to force fetching the new device state when required\n const state = getDeviceSessionState();\n if (state.sessionStateType !== DeviceSessionStateType.Connected) {\n setDeviceSessionState({\n ...state,\n installedApps: [],\n appsUpdates: undefined,\n });\n }\n },\n },\n }).createMachine({\n /** @xstate-layout N4IgpgJg5mDOIC5QEkB2sAuBDANjgggA6EAiYAbgJYDGY+1GlA9qgHRlW0BKYWEAngGIA2gAYAuolCEmsSoxZSQAD0QBGAJyjWADgDsAFg0A2HSb2iArMbUBmADQh+iAExrjrS6KuWNtte7Glga2AL6hjmiYuATEHDR0DMxsAOJMACpMJFiwABYARkxYAE4QghAsYKyUqORMANZVUBlZOQVFpWKSSCAycgqoSqoIxi6WrKJq1rYGNgaiBrOOzgi2th5qonouorYuo9YBBuGR6Nh4RKQUCfQDrGmZ2XmFJWVgxcVMxayEOFgYADMvgBbVjNR5tF6dCRKPryZJDRAHCZTYwzOYLJZOdR6DSeFy2MwBPaaXzGE4gKLnWJXTiJO4PVrPDoQADCuTA1HqIhhPThA0RCE2XlY+0semMomMBgsOjMyyRoh0E28BmClhc+0mxwilLOMUu8Vot2S9xaT3ar3ZnO5wjU3Wksnhih6w2F2jFEqlMqV8uxq0stlYgTlGg02wJOjCuqpBri12NSRY9zAGAA8rAAGrvOQscqVaq1BpNVMZ7PFXOoLqwp0C13qDVqVhaIK+HSifazNQK1YuPHGLTWQxabaLSwU2MXeN0k3JlKlrM55LWrk8h29WsI+tCjRqAysebSvY6TWagw6HvnvFeDsaGX6UR+Wx6Cf6qe0m5J1IL8uVle2+0a36LdQDdXd90PEIXBPU9zx7dFWD0LwxgMHYFkmckYzfGkjXpU15wwS4ABlKEwfNUCqGo6kaFNCOIEjMGrPlNxdUDXFscVRR0VFxXDJCL39PYgxcPRbD8NQ9DUOV9BfLDonfXDZ2-OjCAYjB-zXIDnUGbcRIkxDNEfEIwwCFx4MDYNjFMMxw01Qlo1OeScITPC51TYjSPUjlVztdd+RAlRXEkvQDK0O8xN3NQzP9HR9xvKxCT0E9Jj0WTdVQJgIDgJRJ2cmcvy0us2IQABaYwezK18nMNFylPYFyeD4FZHWA1jAoQVCezccYb02JDDPcQkqupGr8oZc1IRZQqAuGaDxhMfQxjsKMlQcf1NBcFVdlmPs9wJNVhrjD9E3GiFmStbz6mmtrhijTaFu4tZRJMSZzJCqNnyS9x5m2DRDoU2qv1osslza-ybvUNwg02DRLFi+YZnbSx4JE5sJO8Xc3CsWZMMckbp0-Bkf1B1B-2unTiokuxWGlJULHWWwOzGcymwMKnULEuzRn+vLCfw9z6M88nBR2VLRWQ6xxR0GxRhRpsb2fNYjDcXFZLxo7FKBgiPMwMnmNain2rGDiD01PdUs0NVu0EtUtq8KydginV1YBsbTQAZQAV2oWhYHgfXtJFsxtGsXbuMsCPdh7bjPG8AkNFi70-B50a+eTABRD4vmF3Tg88UZd3DyO1pWDj9wlCwLFMDQ+1xcdwlCIA */\n id: \"UninstallAppDeviceAction\",\n initial: \"DeviceReady\",\n context: (_) => {\n return {\n input: {\n unlockTimeout: _.input.unlockTimeout,\n appName: _.input.appName,\n },\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n _internalState: {\n error: null,\n installedApps: [],\n appList: [],\n getOsVersionResponse: null,\n },\n };\n },\n states: {\n DeviceReady: {\n always: {\n target: \"ListInstalledApps\",\n },\n },\n ListInstalledApps: {\n invoke: {\n id: \"listInstalledApps\",\n src: \"listInstalledApps\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction:\n _.event.snapshot.context.intermediateValue\n .requiredUserInteraction,\n }),\n }),\n },\n onDone: {\n target: \"ListInstalledAppsCheck\",\n actions: assign({\n _internalState: (_) =>\n _.event.output.caseOf<UninstallAppStateMachineInternalState>({\n Right: ({ installedApps }) => ({\n ..._.context._internalState,\n installedApps,\n hasCheckedInstalledApps: true,\n }),\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n }),\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n ListInstalledAppsCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"Success\",\n guard: \"appNotInstalled\",\n },\n {\n target: \"GetAppsByHash\",\n },\n ],\n },\n GetAppsByHash: {\n invoke: {\n id: \"getAppsByHash\",\n src: \"getAppsByHash\",\n input: (_) => _.context._internalState.installedApps!,\n onDone: {\n target: \"GetAppsByHashCheck\",\n actions: assign({\n _internalState: (_) =>\n _.event.output.caseOf({\n Right: (apps) => ({\n ..._.context._internalState,\n appList: apps,\n }),\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n }),\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n GetAppsByHashCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"Error\",\n guard: \"appNotFound\",\n actions: \"assignAppNotFound\",\n },\n {\n target: \"Error\",\n guard: \"isDepAppOfOther\",\n actions: \"assignIsDepAppOfOther\",\n },\n {\n target: \"GoToDashboard\",\n },\n ],\n },\n GoToDashboard: {\n invoke: {\n id: \"goToDashboard\",\n src: \"goToDashboard\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction:\n _.event.snapshot.context.intermediateValue\n .requiredUserInteraction,\n }),\n }),\n },\n onDone: {\n target: \"GoToDashboardCheck\",\n actions: assign({\n _internalState: (_) =>\n _.event.output.caseOf<UninstallAppStateMachineInternalState>({\n Right: () => _.context._internalState,\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n }),\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n GoToDashboardCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"GetOsVersion\",\n },\n ],\n },\n GetOsVersion: {\n invoke: {\n id: \"getOsVersion\",\n src: \"getOsVersion\",\n input: (_) => undefined,\n onDone: {\n target: \"GetOsVersionCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n const currentState: DeviceSessionState =\n getDeviceSessionState();\n const isSecureConnectionAllowed =\n _.event.output.data.secureElementFlags\n .isSecureConnectionAllowed;\n if (\n currentState.sessionStateType !==\n DeviceSessionStateType.Connected\n ) {\n setDeviceSessionState({\n ...currentState,\n isSecureConnectionAllowed,\n });\n }\n return {\n ..._.context._internalState,\n getOsVersionResponse: _.event.output.data,\n };\n }\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n },\n }),\n },\n },\n },\n GetOsVersionCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"UninstallApp\",\n },\n ],\n },\n UninstallApp: {\n invoke: {\n id: \"uninstallApp\",\n src: \"uninstallApp\",\n input: (_) => ({\n deviceInfo: _.context._internalState.getOsVersionResponse!,\n app: _.context._internalState.appList.find(\n (app) => app?.versionName === _.context.input.appName,\n )!,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) => {\n switch (_.event.snapshot.context?.type) {\n case SecureChannelEventType.PermissionRequested: {\n return {\n requiredUserInteraction:\n UserInteractionRequired.AllowSecureConnection,\n };\n }\n case SecureChannelEventType.PermissionGranted: {\n return {\n requiredUserInteraction: UserInteractionRequired.None,\n };\n }\n default:\n return {\n ..._.context.intermediateValue,\n };\n }\n },\n }),\n },\n onDone: {\n target: \"ListInstalledApps\",\n actions: \"cleanupDeviceState\",\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n Success: {\n type: \"final\",\n description: \"App uninstalled successfully\",\n },\n Error: {\n type: \"final\",\n },\n },\n output: ({ context }) =>\n context._internalState.error\n ? Left(context._internalState.error)\n : Right(undefined),\n });\n }\n\n extractDependencies(internalApi: InternalApi): MachineDependencies {\n const getOsVersion = () =>\n internalApi.sendCommand(new GetOsVersionCommand());\n\n const getAppsByHash = ({ input }: Input<InstalledApp[]>) => {\n const appHashes = input.map((app) => app.hash);\n return internalApi.getManagerApiService().getAppsByHash(appHashes);\n };\n\n const uninstallApp = ({\n input,\n }: Input<{\n deviceInfo: GetOsVersionResponse;\n app: Application;\n }>) => {\n const { deviceInfo, app } = input;\n const eitherConnection = internalApi\n .getSecureChannelService()\n .uninstallApp(deviceInfo, app);\n return new ConnectToSecureChannelTask(internalApi, {\n connection: eitherConnection,\n }).run();\n };\n\n return {\n getOsVersion,\n getAppsByHash,\n uninstallApp,\n getDeviceSessionState: () => internalApi.getDeviceSessionState(),\n setDeviceSessionState: (state) =>\n internalApi.setDeviceSessionState(state),\n };\n }\n}\n"],
5
- "mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAC5B,OAAS,UAAAC,EAAQ,kBAAAC,EAAgB,eAAAC,EAAa,SAAAC,MAAa,SAE3D,OAAS,0BAAAC,MAA8B,mCACvC,OACE,uBAAAC,MAEK,sCAEP,OAAS,2BAAAC,MAA+B,mDACxC,OAAS,6BAAAC,MAAiC,8BAC1C,OAAS,kBAAAC,MAAsB,+BAC/B,OAAS,6BAAAC,MAAiC,gEAE1C,OAEE,sBAAAC,MACK,qDACP,OAEE,0BAAAC,MACK,yCACP,OAAS,iCAAAC,MAAqC,oFAE9C,OAAS,8BAAAC,MAAkC,sDAC3C,OAAS,0BAAAC,MAA8B,iCAahC,MAAMC,UAAiCL,CAM5C,CACS,iBACPM,EAOA,CASA,KAAM,CACJ,aAAAC,EACA,cAAAC,EACA,aAAAC,EACA,sBAAAC,EACA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EA,oBAAoBiB,EAA+C,CAwBjE,MAAO,CACL,aAxBmB,IACnBA,EAAY,YAAY,IAAIX,CAAqB,EAwBjD,cAtBoB,CAAC,CAAE,MAAA6B,CAAM,IAA6B,CAC1D,MAAMC,EAAYD,EAAM,IAAKR,GAAQA,EAAI,IAAI,EAC7C,OAAOV,EAAY,qBAAqB,EAAE,cAAcmB,CAAS,CACnE,EAoBE,aAlBmB,CAAC,CACpB,MAAAD,CACF,IAGO,CACL,KAAM,CAAE,WAAAE,EAAY,IAAAV,CAAI,EAAIQ,EACtBG,EAAmBrB,EACtB,wBAAwB,EACxB,aAAaoB,EAAYV,CAAG,EAC/B,OAAO,IAAIb,EAA2BG,EAAa,CACjD,WAAYqB,CACd,CAAC,EAAE,IAAI,CACT,EAME,sBAAuB,IAAMrB,EAAY,sBAAsB,EAC/D,sBAAwBW,GACtBX,EAAY,sBAAsBW,CAAK,CAC3C,CACF,CACF",
4
+ "sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport { assign, fromObservable, fromPromise, setup } from \"xstate\";\n\nimport { isSuccessCommandResult } from \"@api/command/model/CommandResult\";\nimport {\n GetOsVersionCommand,\n type GetOsVersionResponse,\n} from \"@api/command/os/GetOsVersionCommand\";\nimport { type InternalApi } from \"@api/device-action/DeviceAction\";\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { DEFAULT_UNLOCK_TIMEOUT_MS } from \"@api/device-action/os/Const\";\nimport { UnknownDAError } from \"@api/device-action/os/Errors\";\nimport { GoToDashboardDeviceAction } from \"@api/device-action/os/GoToDashboard/GoToDashboardDeviceAction\";\nimport { type StateMachineTypes } from \"@api/device-action/xstate-utils/StateMachineTypes\";\nimport {\n type DeviceActionStateMachine,\n XStateDeviceAction,\n} from \"@api/device-action/xstate-utils/XStateDeviceAction\";\nimport {\n type DeviceSessionState,\n DeviceSessionStateType,\n} from \"@api/device-session/DeviceSessionState\";\nimport { ListInstalledAppsDeviceAction } from \"@api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction\";\nimport { type InstalledApp } from \"@api/secure-channel/device-action/ListInstalledApps/types\";\nimport { ConnectToSecureChannelTask } from \"@api/secure-channel/task/ConnectToSecureChannelTask\";\nimport { SecureChannelEventType } from \"@api/secure-channel/task/types\";\nimport { type Input } from \"@api/secure-channel/types\";\nimport { type Application } from \"@internal/manager-api/model/Application\";\n\nimport {\n type MachineDependencies,\n type UninstallAppDAError,\n type UninstallAppDAInput,\n type UninstallAppDAIntermediateValue,\n type UninstallAppDAOutput,\n type UninstallAppStateMachineInternalState,\n} from \"./types\";\n\nexport class UninstallAppDeviceAction extends XStateDeviceAction<\n UninstallAppDAOutput,\n UninstallAppDAInput,\n UninstallAppDAError,\n UninstallAppDAIntermediateValue,\n UninstallAppStateMachineInternalState\n> {\n override makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n UninstallAppDAOutput,\n UninstallAppDAInput,\n UninstallAppDAError,\n UninstallAppDAIntermediateValue,\n UninstallAppStateMachineInternalState\n > {\n type types = StateMachineTypes<\n UninstallAppDAOutput,\n UninstallAppDAInput,\n UninstallAppDAError,\n UninstallAppDAIntermediateValue,\n UninstallAppStateMachineInternalState\n >;\n\n const {\n getOsVersion,\n getAppsByHash,\n uninstallApp,\n getDeviceSessionState,\n setDeviceSessionState,\n } = this.extractDependencies(internalApi);\n\n const unlockTimeout = this.input.unlockTimeout ?? DEFAULT_UNLOCK_TIMEOUT_MS;\n\n const goToDashboardMachine = new GoToDashboardDeviceAction({\n input: {\n unlockTimeout,\n },\n }).makeStateMachine(internalApi);\n\n const listInstalledAppsMachine = new ListInstalledAppsDeviceAction({\n input: {\n unlockTimeout,\n },\n }).makeStateMachine(internalApi);\n\n return setup({\n types: {\n input: {} as types[\"input\"],\n context: {} as types[\"context\"],\n output: {} as types[\"output\"],\n },\n actors: {\n listInstalledApps: listInstalledAppsMachine,\n goToDashboard: goToDashboardMachine,\n getOsVersion: fromPromise(getOsVersion),\n getAppsByHash: fromPromise(getAppsByHash),\n uninstallApp: fromObservable(uninstallApp),\n },\n guards: {\n hasError: (_) => _.context._internalState.error !== null,\n appNotInstalled: (_) =>\n !_.context._internalState.installedApps.some(\n (app) => app.name === _.context.input.appName,\n ),\n appNotFound: (_) =>\n _.context._internalState.appList.findIndex(\n (app) => app?.versionName === _.context.input.appName,\n ) === -1,\n isDepAppOfOther: (_) =>\n _.context._internalState.appList.some(\n (app) => app?.parentName === _.context.input.appName,\n ),\n },\n actions: {\n assignErrorFromEvent: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: _.event[\"error\"],\n }),\n }),\n assignAppNotFound: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: new UnknownDAError(\n \"App to uninstall not found in manager API\",\n ),\n }),\n }),\n assignIsDepAppOfOther: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: new UnknownDAError(\n \"App to uninstall is a dependency of another installed app\",\n ),\n }),\n }),\n cleanupDeviceState: () => {\n // After app successful uninstallation, cleanup the device session state\n // to force fetching the new device state when required\n const state = getDeviceSessionState();\n if (state.sessionStateType !== DeviceSessionStateType.Connected) {\n setDeviceSessionState({\n ...state,\n installedApps: [],\n appsUpdates: undefined,\n });\n }\n },\n },\n }).createMachine({\n /** @xstate-layout N4IgpgJg5mDOIC5QEkB2sAuBDANjgggA6EAiYAbgJYDGY+1GlA9qgHRlW0BKYWEAngGIA2gAYAuolCEmsSoxZSQAD0QBGAJyjWADgDsAFg0A2HSb2iArMbUBmADQh+iAExrjrS6KuWNtte7Glga2AL6hjmiYuATEHDR0DMxsAOJMACpMJFiwABYARkxYAE4QghAsYKyUqORMANZVUBlZOQVFpWKSSCAycgqoSqoIxi6WrKJq1rYGNgaiBrOOzgi2th5qonouorYuo9YBBuGR6Nh4RKQUCfQDrGmZ2XmFJWVgxcVMxayEOFgYADMvgBbVjNR5tF6dCRKPryZJDRAHCZTYwzOYLJZOdR6DSeFy2MwBPaaXzGE4gKLnWJXTiJO4PVr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{\n input: {\n unlockTimeout: _.input.unlockTimeout,\n appName: _.input.appName,\n },\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n _internalState: {\n error: null,\n installedApps: [],\n appList: [],\n getOsVersionResponse: null,\n },\n };\n },\n states: {\n DeviceReady: {\n always: {\n target: \"ListInstalledApps\",\n },\n },\n ListInstalledApps: {\n invoke: {\n id: \"listInstalledApps\",\n src: \"listInstalledApps\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction:\n _.event.snapshot.context.intermediateValue\n .requiredUserInteraction,\n }),\n }),\n },\n onDone: {\n target: \"ListInstalledAppsCheck\",\n actions: assign({\n _internalState: (_) =>\n _.event.output.caseOf<UninstallAppStateMachineInternalState>({\n Right: ({ installedApps }) => ({\n ..._.context._internalState,\n installedApps,\n hasCheckedInstalledApps: true,\n }),\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n }),\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n ListInstalledAppsCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"Success\",\n guard: \"appNotInstalled\",\n },\n {\n target: \"GetAppsByHash\",\n },\n ],\n },\n GetAppsByHash: {\n invoke: {\n id: \"getAppsByHash\",\n src: \"getAppsByHash\",\n input: (_) => _.context._internalState.installedApps!,\n onDone: {\n target: \"GetAppsByHashCheck\",\n actions: assign({\n _internalState: (_) =>\n _.event.output.caseOf({\n Right: (apps) => ({\n ..._.context._internalState,\n appList: apps,\n }),\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n }),\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n GetAppsByHashCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"Error\",\n guard: \"appNotFound\",\n actions: \"assignAppNotFound\",\n },\n {\n target: \"Error\",\n guard: \"isDepAppOfOther\",\n actions: \"assignIsDepAppOfOther\",\n },\n {\n target: \"GoToDashboard\",\n },\n ],\n },\n GoToDashboard: {\n invoke: {\n id: \"goToDashboard\",\n src: \"goToDashboard\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction:\n _.event.snapshot.context.intermediateValue\n .requiredUserInteraction,\n }),\n }),\n },\n onDone: {\n target: \"GoToDashboardCheck\",\n actions: assign({\n _internalState: (_) =>\n _.event.output.caseOf<UninstallAppStateMachineInternalState>({\n Right: () => _.context._internalState,\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n }),\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n GoToDashboardCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"GetOsVersion\",\n },\n ],\n },\n GetOsVersion: {\n invoke: {\n id: \"getOsVersion\",\n src: \"getOsVersion\",\n input: (_) => undefined,\n onDone: {\n target: \"GetOsVersionCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n const currentState: DeviceSessionState =\n getDeviceSessionState();\n const isSecureConnectionAllowed =\n _.event.output.data.secureElementFlags\n .isSecureConnectionAllowed;\n if (\n currentState.sessionStateType !==\n DeviceSessionStateType.Connected\n ) {\n setDeviceSessionState({\n ...currentState,\n isSecureConnectionAllowed,\n });\n }\n return {\n ..._.context._internalState,\n getOsVersionResponse: _.event.output.data,\n };\n }\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n },\n }),\n },\n },\n },\n GetOsVersionCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"UninstallApp\",\n },\n ],\n },\n UninstallApp: {\n invoke: {\n id: \"uninstallApp\",\n src: \"uninstallApp\",\n input: (_) => ({\n deviceInfo: _.context._internalState.getOsVersionResponse!,\n app: _.context._internalState.appList.find(\n (app) => app?.versionName === _.context.input.appName,\n )!,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) => {\n switch (_.event.snapshot.context?.type) {\n case SecureChannelEventType.PermissionRequested: {\n return {\n requiredUserInteraction:\n UserInteractionRequired.AllowSecureConnection,\n };\n }\n case SecureChannelEventType.PermissionGranted: {\n return {\n requiredUserInteraction: UserInteractionRequired.None,\n };\n }\n default:\n return {\n ..._.context.intermediateValue,\n };\n }\n },\n _internalState: (_) => {\n if (\n _.event.snapshot.context?.type ===\n SecureChannelEventType.Error\n ) {\n return {\n ..._.context._internalState,\n error: _.event.snapshot.context.error.mapDAErrors(),\n };\n }\n return _.context._internalState;\n },\n }),\n },\n onDone: {\n target: \"ListInstalledApps\",\n actions: \"cleanupDeviceState\",\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n Success: {\n type: \"final\",\n description: \"App uninstalled successfully\",\n },\n Error: {\n type: \"final\",\n },\n },\n output: ({ context }) =>\n context._internalState.error\n ? Left(context._internalState.error)\n : Right(undefined),\n });\n }\n\n extractDependencies(internalApi: InternalApi): MachineDependencies {\n const getOsVersion = () =>\n internalApi.sendCommand(new GetOsVersionCommand());\n\n const getAppsByHash = ({ input }: Input<InstalledApp[]>) => {\n const appHashes = input.map((app) => app.hash);\n return internalApi.getManagerApiService().getAppsByHash(appHashes);\n };\n\n const uninstallApp = ({\n input,\n }: Input<{\n deviceInfo: GetOsVersionResponse;\n app: Application;\n }>) => {\n const { deviceInfo, app } = input;\n const eitherConnection = internalApi\n .getSecureChannelService()\n .uninstallApp(deviceInfo, app);\n return new ConnectToSecureChannelTask(internalApi, {\n connection: eitherConnection,\n }).run();\n };\n\n return {\n getOsVersion,\n getAppsByHash,\n uninstallApp,\n getDeviceSessionState: () => internalApi.getDeviceSessionState(),\n setDeviceSessionState: (state) =>\n internalApi.set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AuB,IAAMrB,EAAY,sBAAsB,EAC/D,sBAAwBW,GACtBX,EAAY,sBAAsBW,CAAK,CAC3C,CACF,CACF",
6
6
  "names": ["Left", "Right", "assign", "fromObservable", "fromPromise", "setup", "isSuccessCommandResult", "GetOsVersionCommand", "UserInteractionRequired", "DEFAULT_UNLOCK_TIMEOUT_MS", "UnknownDAError", "GoToDashboardDeviceAction", "XStateDeviceAction", "DeviceSessionStateType", "ListInstalledAppsDeviceAction", "ConnectToSecureChannelTask", "SecureChannelEventType", "UninstallAppDeviceAction", "internalApi", "getOsVersion", "getAppsByHash", "uninstallApp", "getDeviceSessionState", "setDeviceSessionState", "unlockTimeout", "goToDashboardMachine", "listInstalledAppsMachine", "_", "app", "state", "installedApps", "error", "apps", "currentState", "isSecureConnectionAllowed", "context", "input", "appHashes", "deviceInfo", "eitherConnection"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import w from"isomorphic-ws";import{Observable as A}from"rxjs";import{CommandUtils as S}from"../../command/utils/CommandUtils";import{InMessageQueryEnum as l,OutMessageResponseEnum as m,SecureChannelEventType as i}from"../../secure-channel/task/types";import{isRefusedByUser as v,willRequestPermission as x}from"../../secure-channel/utils";import{bufferToHexaString as C,hexaStringToBuffer as k}from"../../utils/HexaString";import{SecureChannelError as o}from"../../../internal/secure-channel/model/Errors";class P{constructor(d,E){this._api=d;this._args=E;if(this._args.connection.isRight())this._connection=this._args.connection.extract();else throw new o(`Invalid WebSocket connection: ${String(this._args.connection.extract())}`)}_connection;run(){const d=this._api.disableRefresher("connectToSecureChannel");return new A(e=>{let u=!1,c=!1,y=!1,p=null,h=!1;return this._connection.onopen=()=>{e.next({type:i.Opened})},this._connection.onerror=f=>{c||e.error(new o({url:this._connection.url,errorMessage:f.message}))},this._connection.onclose=()=>{c||(y?(e.next({type:i.Closed}),e.complete()):e.error(new o(p??{url:this._connection.url,errorMessage:"Connection closed unexpectedly"})))},this._connection.onmessage=async f=>{if(!u){p=null;try{const t=JSON.parse(String(f.data));switch(t.query){case l.EXCHANGE:{const{nonce:a}=t;if(Array.isArray(t.data)){e.error(new o(`${l.EXCHANGE} data type should not be Array`));break}const n=k(t.data);if(n===null||n.length<5){e.error(new o(`Received invalid APDU data: ${t.data}`));break}e.next({type:i.PreExchange,payload:{nonce:a,apdu:n}}),x(n)&&!this.isSecureConnectionAllowed()&&(h=!0,e.next({type:i.PermissionRequested}));const s=await this._api.sendApdu(n);if(u)return;s.caseOf({Left:r=>{e.error(new o(r))},Right:r=>{let g;if(S.isSuccessResponse(r))g=m.SUCCESS,e.next({type:i.Exchange,payload:{nonce:a,apdu:n,data:r.data,status:r.statusCode}});else{if(g=m.ERROR,p=new o({url:this._connection.url,errorMessage:`Invalid status code: ${C(r.statusCode)}`}),S.isLockedDeviceResponse(r)){e.error(new o({url:this._connection.url,errorMessage:"Device is locked"}));return}if(v(r.statusCode)&&h){e.error(new o({url:this._connection.url,errorMessage:"User refused on the device"}));return}}h&&(e.next({type:i.PermissionGranted}),h=!1);const _={nonce:a,response:g,data:C(r.data).slice(2)};this._connection.send(JSON.stringify(_))}});break}case l.BULK:{if(c=!0,this._connection.close(),!Array.isArray(t.data)||t.data.length===0){e.error(new o("Invalid bulk data received"));break}const a=t.data.reduce((n,s)=>{const r=k(s);return r===null?n:[...n,r]},[]);for(let n=0,s=a.length;n<s;n++){if(await this._api.sendApdu(a[n]),u){e.error(new o("Bulk sending cancelled by unsubscribing"));break}e.next({type:i.Progress,payload:{progress:+Number((n+1)/s).toFixed(2),index:n,total:s}})}y=!0,e.complete();break}case l.SUCCESS:{if(c)break;const a=t.result??t.data;a&&e.next({type:i.Result,payload:a??""}),y=!0,e.complete();break}case l.WARNING:{if(c)break;e.next({type:i.Warning,payload:{message:String(t.data)}});break}case l.ERROR:{if(c)break;e.error(new o({url:this._connection.url,errorMessage:String(t.data)}))}}}catch(t){p=new o(t),e.error(p)}}},()=>{d(),u=!0,this._connection.readyState===w.OPEN&&this._connection.close()}})}isSecureConnectionAllowed(){const d=this._api.getDeviceSessionState();return"isSecureConnectionAllowed"in d&&d.isSecureConnectionAllowed}}export{P as ConnectToSecureChannelTask};
1
+ import M from"isomorphic-ws";import{Observable as k}from"rxjs";import{CommandUtils as h}from"../../command/utils/CommandUtils";import{InMessageQueryEnum as d,OutMessageResponseEnum as w,SecureChannelEventType as s}from"../../secure-channel/task/types";import{willRequestPermission as R}from"../../secure-channel/utils";import{bufferToHexaString as _,hexaStringToBuffer as A}from"../../utils/HexaString";import{SecureChannelError as r,SecureChannelErrorType as S}from"../../../internal/secure-channel/model/Errors";class q{constructor(t,c){this._api=t;this._args=c;if(this._args.connection.isRight())this._connection=this._args.connection.extract();else throw new r(`Invalid WebSocket connection: ${String(this._args.connection.extract())}`)}_connection;run(){const t=this._api.disableRefresher("connectToSecureChannel");return new k(n=>{let g=!1,l=!1,E=!1;const i=f=>{n.next({type:s.Error,error:f}),n.complete(),l=!0};return this._connection.onopen=()=>{n.next({type:s.Opened})},this._connection.onerror=f=>{l||(n.next({type:s.Error,error:new r({url:this._connection.url,errorMessage:f.message})}),n.complete())},this._connection.onclose=()=>{l||(E?n.next({type:s.Closed}):n.next({type:s.Error,error:new r({url:this._connection.url,errorMessage:"Connection closed unexpectedly"})}),n.complete())},this._connection.onmessage=async f=>{if(g)return;let o;try{const e=JSON.parse(String(f.data));if(this.isInMessageType(e))o=e;else throw new Error("Data does not match InMessageType")}catch{i(new r({url:this._connection.url,errorMessage:`Invalid message received: ${String(f.data)}`}));return}switch(o.query){case d.EXCHANGE:{const{nonce:e,data:u}=o;if(typeof u!="string"){i(new r(`${d.EXCHANGE} data type should be an APDU`));return}const a=A(u);if(a===null||a.length<5){i(new r(`Received invalid APDU data: ${u}`));return}n.next({type:s.PreExchange,payload:{nonce:e,apdu:a}});let p=!1;R(a)&&!this.isSecureConnectionAllowed()&&(p=!0,n.next({type:s.PermissionRequested}));const m=await this._api.sendApdu(a);if(g)return;m.caseOf({Left:y=>{i(new r(y))},Right:y=>{let v;const C=this.mapDeviceError(y);C===null?(v=w.SUCCESS,n.next({type:s.Exchange,payload:{nonce:e,apdu:a,data:y.data,status:y.statusCode}}),p&&n.next({type:s.PermissionGranted})):(v=w.ERROR,i(C));const x={nonce:e,response:v,data:_(y.data,!1)};this._connection.send(JSON.stringify(x))}});break}case d.BULK:{if(l=!0,this._connection.close(),!Array.isArray(o.data)||o.data.length===0||!o.data.every(e=>typeof e=="string")){i(new r("Invalid bulk data received"));return}for(let e=0,u=o.data.length;e<u;e++){const a=A(o.data[e]);if(a===null||a.length<5){i(new r(`Received invalid APDU bulk data: ${o.data[e]}`));return}const p=await this._api.sendApdu(a);if(g)return;if(p.isLeft()){i(new r(p.extract()));return}else if(p.isRight()){const m=this.mapDeviceError(p.extract());if(m===null)n.next({type:s.Progress,payload:{progress:+Number((e+1)/u).toFixed(2),index:e,total:u}});else{i(m);return}}}E=!0,n.complete();break}case d.SUCCESS:{if(l)break;const e=o.result??o.data;e&&n.next({type:s.Result,payload:e??""}),E=!0,n.complete();break}case d.WARNING:{if(l)break;n.next({type:s.Warning,payload:{message:String(o.data)}});break}case d.ERROR:{if(l)break;i(new r({url:this._connection.url,errorMessage:String(o.data)}))}}},()=>{t(),g=!0,this._connection.readyState===M.OPEN&&this._connection.close()}})}isSecureConnectionAllowed(){const t=this._api.getDeviceSessionState();return"isSecureConnectionAllowed"in t&&t.isSecureConnectionAllowed}isInMessageType(t){if(typeof t!="object"||!t)return!1;const c=t;return typeof c.uuid=="string"&&typeof c.session=="string"&&typeof c.query=="string"&&Object.values(d).includes(c.query)&&typeof c.nonce=="number"}mapDeviceError(t){return h.isSuccessResponse(t)?null:h.isLockedDeviceResponse(t)?new r({url:this._connection.url,errorMessage:"Device is locked"},S.DeviceLocked):h.isRefusedByUser(t)?new r({url:this._connection.url,errorMessage:"User refused on the device"},S.RefusedByUser):h.isAppAlreadyInstalled(t)?new r({url:this._connection.url,errorMessage:"App already installed"},S.AppAlreadyInstalled):h.isOutOfMemory(t)?new r({url:this._connection.url,errorMessage:"Out of memory"},S.OutOfMemory):new r({url:this._connection.url,errorMessage:`Invalid status code: ${_(t.statusCode)}`})}}export{q as ConnectToSecureChannelTask};
2
2
  //# sourceMappingURL=ConnectToSecureChannelTask.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/api/secure-channel/task/ConnectToSecureChannelTask.ts"],
4
- "sourcesContent": ["import WebSocket from \"isomorphic-ws\";\nimport { type Either } from \"purify-ts\";\nimport { Observable } from \"rxjs\";\n\nimport { CommandUtils } from \"@api/command/utils/CommandUtils\";\nimport { type InternalApi } from \"@api/device-action/DeviceAction\";\nimport { type ApduResponse } from \"@api/device-session/ApduResponse\";\nimport {\n InMessageQueryEnum,\n type InMessageType,\n OutMessageResponseEnum,\n type OutMessageType,\n type SecureChannelEvent,\n SecureChannelEventType,\n} from \"@api/secure-channel/task/types\";\nimport {\n isRefusedByUser,\n willRequestPermission,\n} from \"@api/secure-channel/utils\";\nimport { bufferToHexaString, hexaStringToBuffer } from \"@api/utils/HexaString\";\nimport {\n SecureChannelError,\n type WebSocketConnectionError,\n} from \"@internal/secure-channel/model/Errors\";\n\nexport type ConnectToSecureChannelTaskArgs = {\n connection: Either<WebSocketConnectionError, WebSocket>;\n};\n\nexport class ConnectToSecureChannelTask {\n private readonly _connection: WebSocket;\n constructor(\n private readonly _api: InternalApi,\n private readonly _args: ConnectToSecureChannelTaskArgs,\n ) {\n if (this._args.connection.isRight()) {\n this._connection = this._args.connection.extract();\n } else {\n throw new SecureChannelError(\n `Invalid WebSocket connection: ${String(this._args.connection.extract())}`,\n );\n }\n }\n\n run(): Observable<SecureChannelEvent> {\n const reenableRefresher = this._api.disableRefresher(\n \"connectToSecureChannel\",\n );\n\n const obs = new Observable<SecureChannelEvent>((subscriber) => {\n let unsubscribed: boolean = false;\n let inBulkMode = false;\n let communicationFinished = false;\n let deviceError: SecureChannelError | null = null;\n let waitingForUserAction = false;\n\n this._connection.onopen = () => {\n subscriber.next({\n type: SecureChannelEventType.Opened,\n });\n };\n\n this._connection.onerror = (error) => {\n // When the bulk sending is in progress, network error is ignored\n if (inBulkMode) {\n return;\n }\n\n subscriber.error(\n new SecureChannelError({\n url: this._connection.url,\n errorMessage: error.message,\n }),\n );\n };\n\n this._connection.onclose = () => {\n // When the bulk sending is in progress, network event is ignored\n if (inBulkMode) {\n return;\n }\n\n if (communicationFinished) {\n subscriber.next({\n type: SecureChannelEventType.Closed,\n });\n subscriber.complete();\n } else {\n subscriber.error(\n new SecureChannelError(\n deviceError ?? {\n url: this._connection.url,\n errorMessage: \"Connection closed unexpectedly\",\n },\n ),\n );\n }\n };\n\n this._connection.onmessage = async (event) => {\n // When unsubscribed, ignore the message\n if (unsubscribed) {\n return;\n }\n deviceError = null;\n\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const input: InMessageType = JSON.parse(String(event.data));\n\n switch (input.query) {\n case InMessageQueryEnum.EXCHANGE: {\n const { nonce } = input;\n\n if (Array.isArray(input.data)) {\n subscriber.error(\n new SecureChannelError(\n `${InMessageQueryEnum.EXCHANGE} data type should not be Array`,\n ),\n );\n break;\n }\n\n const apdu = hexaStringToBuffer(input.data);\n\n if (apdu === null || apdu.length < 5) {\n subscriber.error(\n new SecureChannelError(\n `Received invalid APDU data: ${input.data}`,\n ),\n );\n break;\n }\n\n subscriber.next({\n type: SecureChannelEventType.PreExchange,\n payload: { nonce, apdu },\n });\n\n if (\n willRequestPermission(apdu) &&\n !this.isSecureConnectionAllowed()\n ) {\n waitingForUserAction = true;\n subscriber.next({\n type: SecureChannelEventType.PermissionRequested,\n });\n }\n\n const response = await this._api.sendApdu(apdu);\n\n if (unsubscribed) {\n return;\n }\n\n response.caseOf({\n Left: (error) => {\n subscriber.error(new SecureChannelError(error));\n },\n Right: (apduResponse: ApduResponse) => {\n let outMessageResponse: OutMessageResponseEnum;\n /**\n * | Status Code | Description | Event Emitted |\n * |-------------|------------------------------------|------------------------------------|\n * | 0x9000 | Success | SecureChannelEventEnum.Exchange |\n * | 0x5515 | Device is locked | Error |\n * | 0x5501 | User refused on the device | Error |\n * | 0x6985 | Condition of use not satisfied | Error |\n */\n // Success response\n if (CommandUtils.isSuccessResponse(apduResponse)) {\n outMessageResponse = OutMessageResponseEnum.SUCCESS;\n // Emit event for the exchange\n subscriber.next({\n type: SecureChannelEventType.Exchange,\n payload: {\n nonce,\n apdu,\n data: apduResponse.data,\n status: apduResponse.statusCode,\n },\n });\n } else {\n outMessageResponse = OutMessageResponseEnum.ERROR;\n\n deviceError = new SecureChannelError({\n url: this._connection.url,\n errorMessage: `Invalid status code: ${bufferToHexaString(\n apduResponse.statusCode,\n )}`,\n });\n\n // Device is locked\n if (CommandUtils.isLockedDeviceResponse(apduResponse)) {\n subscriber.error(\n new SecureChannelError({\n url: this._connection.url,\n errorMessage: `Device is locked`,\n }),\n );\n return;\n }\n\n // User refused the permission\n if (\n isRefusedByUser(apduResponse.statusCode) &&\n waitingForUserAction\n ) {\n subscriber.error(\n new SecureChannelError({\n url: this._connection.url,\n errorMessage: \"User refused on the device\",\n }),\n );\n return;\n }\n }\n\n if (waitingForUserAction) {\n subscriber.next({\n type: SecureChannelEventType.PermissionGranted,\n });\n waitingForUserAction = false;\n }\n\n // Send the message back to the server\n const message: OutMessageType = {\n nonce,\n response: outMessageResponse,\n data: bufferToHexaString(apduResponse.data).slice(2),\n };\n this._connection.send(JSON.stringify(message));\n },\n });\n break;\n }\n case InMessageQueryEnum.BULK: {\n inBulkMode = true;\n this._connection.close();\n\n if (!Array.isArray(input.data) || input.data.length === 0) {\n subscriber.error(\n new SecureChannelError(\"Invalid bulk data received\"),\n );\n break;\n }\n\n const apdus = input.data.reduce(\n (acc: Array<Uint8Array>, cur: string) => {\n const apdu = hexaStringToBuffer(cur);\n return apdu === null ? acc : [...acc, apdu];\n },\n [],\n );\n\n for (let i = 0, len = apdus.length; i < len; i++) {\n await this._api.sendApdu(apdus[i]!);\n if (unsubscribed) {\n subscriber.error(\n new SecureChannelError(\n \"Bulk sending cancelled by unsubscribing\",\n ),\n );\n break;\n }\n subscriber.next({\n type: SecureChannelEventType.Progress,\n payload: {\n progress: +Number((i + 1) / len).toFixed(2),\n index: i,\n total: len,\n },\n });\n }\n communicationFinished = true;\n subscriber.complete();\n break;\n }\n case InMessageQueryEnum.SUCCESS: {\n // Ignore success message when in bulk mode\n if (inBulkMode) {\n break;\n }\n // Emit the result if there is any\n const payload = input.result ?? input.data;\n if (payload) {\n subscriber.next({\n type: SecureChannelEventType.Result,\n payload: payload ?? \"\",\n });\n }\n communicationFinished = true;\n subscriber.complete();\n break;\n }\n case InMessageQueryEnum.WARNING: {\n // Ignore warning message when in bulk mode\n if (inBulkMode) {\n break;\n }\n subscriber.next({\n type: SecureChannelEventType.Warning,\n payload: { message: String(input.data) },\n });\n break;\n }\n case InMessageQueryEnum.ERROR: {\n if (inBulkMode) {\n break;\n }\n subscriber.error(\n new SecureChannelError({\n url: this._connection.url,\n errorMessage: String(input.data),\n }),\n );\n }\n }\n } catch (error) {\n deviceError = new SecureChannelError(error);\n subscriber.error(deviceError);\n }\n };\n\n return () => {\n reenableRefresher();\n unsubscribed = true;\n // Close the connection if it is open when unsubscribing\n if (this._connection.readyState === WebSocket.OPEN) {\n this._connection.close();\n }\n };\n });\n\n return obs;\n }\n\n /**\n * Determines if a secure connection is already allowed based on the current device session state.\n *\n * @returns {boolean} `true` if a secure connection is allowed, otherwise `false`.\n */\n isSecureConnectionAllowed(): boolean {\n const deviceSessionState = this._api.getDeviceSessionState();\n return (\n \"isSecureConnectionAllowed\" in deviceSessionState &&\n deviceSessionState.isSecureConnectionAllowed\n );\n }\n}\n"],
5
- "mappings": "AAAA,OAAOA,MAAe,gBAEtB,OAAS,cAAAC,MAAkB,OAE3B,OAAS,gBAAAC,MAAoB,kCAG7B,OACE,sBAAAC,EAEA,0BAAAC,EAGA,0BAAAC,MACK,iCACP,OACE,mBAAAC,EACA,yBAAAC,MACK,4BACP,OAAS,sBAAAC,EAAoB,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ACpB,KACF,CACA,KAAKZ,EAAmB,QAAS,CAE/B,GAAIc,EACF,MAEFF,EAAW,KAAK,CACd,KAAMV,EAAuB,QAC7B,QAAS,CAAE,QAAS,OAAOkB,EAAM,IAAI,CAAE,CACzC,CAAC,EACD,KACF,CACA,KAAKpB,EAAmB,MAAO,CAC7B,GAAIc,EACF,MAEFF,EAAW,MACT,IAAIL,EAAmB,CACrB,IAAK,KAAK,YAAY,IACtB,aAAc,OAAOa,EAAM,IAAI,CACjC,CAAC,CACH,CACF,CACF,CACF,OAASF,EAAO,CACdF,EAAc,IAAIT,EAAmBW,CAAK,EAC1CN,EAAW,MAAMI,CAAW,CAC9B,EACF,EAEO,IAAM,CACXL,EAAkB,EAClBE,EAAe,GAEX,KAAK,YAAY,aAAehB,EAAU,MAC5C,KAAK,YAAY,MAAM,CAE3B,CACF,CAAC,CAGH,CAOA,2BAAqC,CACnC,MAAMoC,EAAqB,KAAK,KAAK,sBAAsB,EAC3D,MACE,8BAA+BA,GAC/BA,EAAmB,yBAEvB,CACF",
6
- "names": ["WebSocket", "Observable", "CommandUtils", "InMessageQueryEnum", "OutMessageResponseEnum", "SecureChannelEventType", "isRefusedByUser", "willRequestPermission", "bufferToHexaString", "hexaStringToBuffer", "SecureChannelError", "ConnectToSecureChannelTask", "_api", "_args", "reenableRefresher", "subscriber", "unsubscribed", "inBulkMode", "communicationFinished", "deviceError", "waitingForUserAction", "error", "event", "input", "nonce", "apdu", "response", "apduResponse", "outMessageResponse", "message", "apdus", "acc", "cur", "i", "len", "payload", "deviceSessionState"]
4
+ "sourcesContent": ["import WebSocket from \"isomorphic-ws\";\nimport { type Either } from \"purify-ts\";\nimport { Observable } from \"rxjs\";\n\nimport { CommandUtils } from \"@api/command/utils/CommandUtils\";\nimport { type InternalApi } from \"@api/device-action/DeviceAction\";\nimport { type ApduResponse } from \"@api/device-session/ApduResponse\";\nimport {\n InMessageQueryEnum,\n type InMessageType,\n OutMessageResponseEnum,\n type OutMessageType,\n type SecureChannelEvent,\n SecureChannelEventType,\n} from \"@api/secure-channel/task/types\";\nimport { willRequestPermission } from \"@api/secure-channel/utils\";\nimport { bufferToHexaString, hexaStringToBuffer } from \"@api/utils/HexaString\";\nimport {\n SecureChannelError,\n SecureChannelErrorType,\n type WebSocketConnectionError,\n} from \"@internal/secure-channel/model/Errors\";\n\nexport type ConnectToSecureChannelTaskArgs = {\n connection: Either<WebSocketConnectionError, WebSocket>;\n};\n\nexport class ConnectToSecureChannelTask {\n private readonly _connection: WebSocket;\n constructor(\n private readonly _api: InternalApi,\n private readonly _args: ConnectToSecureChannelTaskArgs,\n ) {\n if (this._args.connection.isRight()) {\n this._connection = this._args.connection.extract();\n } else {\n throw new SecureChannelError(\n `Invalid WebSocket connection: ${String(this._args.connection.extract())}`,\n );\n }\n }\n\n run(): Observable<SecureChannelEvent> {\n const reenableRefresher = this._api.disableRefresher(\n \"connectToSecureChannel\",\n );\n\n const obs = new Observable<SecureChannelEvent>((subscriber) => {\n let unsubscribed: boolean = false;\n let ignoreNetworkEvents = false;\n let communicationFinished = false;\n\n const notifyError = (error: SecureChannelError) => {\n subscriber.next({\n type: SecureChannelEventType.Error,\n error,\n });\n subscriber.complete();\n\n // Netowrks events can be ignored once the obervable has been completed\n ignoreNetworkEvents = true;\n };\n\n this._connection.onopen = () => {\n subscriber.next({\n type: SecureChannelEventType.Opened,\n });\n };\n\n this._connection.onerror = (error) => {\n if (ignoreNetworkEvents) {\n return;\n }\n\n subscriber.next({\n type: SecureChannelEventType.Error,\n error: new SecureChannelError({\n url: this._connection.url,\n errorMessage: error.message,\n }),\n });\n subscriber.complete();\n };\n\n this._connection.onclose = () => {\n if (ignoreNetworkEvents) {\n return;\n }\n\n if (communicationFinished) {\n subscriber.next({\n type: SecureChannelEventType.Closed,\n });\n } else {\n subscriber.next({\n type: SecureChannelEventType.Error,\n error: new SecureChannelError({\n url: this._connection.url,\n errorMessage: \"Connection closed unexpectedly\",\n }),\n });\n }\n subscriber.complete();\n };\n\n this._connection.onmessage = async (event) => {\n // When unsubscribed, ignore the message\n if (unsubscribed) {\n return;\n }\n\n // Parse input message\n let input: InMessageType;\n try {\n const jsonData = JSON.parse(String(event.data));\n if (this.isInMessageType(jsonData)) {\n input = jsonData;\n } else {\n throw new Error(\"Data does not match InMessageType\");\n }\n } catch (_) {\n notifyError(\n new SecureChannelError({\n url: this._connection.url,\n errorMessage: `Invalid message received: ${String(event.data)}`,\n }),\n );\n return;\n }\n\n // Execute message query\n switch (input.query) {\n case InMessageQueryEnum.EXCHANGE: {\n const { nonce, data } = input;\n\n // Exchange query should contain a single APDU\n if (typeof data !== \"string\") {\n notifyError(\n new SecureChannelError(\n `${InMessageQueryEnum.EXCHANGE} data type should be an APDU`,\n ),\n );\n return;\n }\n\n // APDU should be a valid hex string\n const apdu = hexaStringToBuffer(data);\n if (apdu === null || apdu.length < 5) {\n notifyError(\n new SecureChannelError(`Received invalid APDU data: ${data}`),\n );\n return;\n }\n subscriber.next({\n type: SecureChannelEventType.PreExchange,\n payload: { nonce, apdu },\n });\n\n // Notify permission requested\n let permissionRequested = false;\n if (\n willRequestPermission(apdu) &&\n !this.isSecureConnectionAllowed()\n ) {\n permissionRequested = true;\n subscriber.next({\n type: SecureChannelEventType.PermissionRequested,\n });\n }\n\n // Send APDU to the device\n const response = await this._api.sendApdu(apdu);\n if (unsubscribed) {\n return;\n }\n\n // Map device response\n response.caseOf({\n Left: (error) => {\n notifyError(new SecureChannelError(error));\n },\n Right: (apduResponse: ApduResponse) => {\n let outMessageResponse: OutMessageResponseEnum;\n const deviceError = this.mapDeviceError(apduResponse);\n if (deviceError === null) {\n outMessageResponse = OutMessageResponseEnum.SUCCESS;\n\n // Emit event for the exchange\n subscriber.next({\n type: SecureChannelEventType.Exchange,\n payload: {\n nonce,\n apdu,\n data: apduResponse.data,\n status: apduResponse.statusCode,\n },\n });\n\n // If manager consent was requested, notify the \"granted\" event\n if (permissionRequested) {\n subscriber.next({\n type: SecureChannelEventType.PermissionGranted,\n });\n }\n } else {\n outMessageResponse = OutMessageResponseEnum.ERROR;\n notifyError(deviceError);\n }\n\n // Send the message back to the server\n const message: OutMessageType = {\n nonce,\n response: outMessageResponse,\n data: bufferToHexaString(apduResponse.data, false),\n };\n this._connection.send(JSON.stringify(message));\n },\n });\n break;\n }\n case InMessageQueryEnum.BULK: {\n // Network not needed anymore during bulk APDUs sending\n ignoreNetworkEvents = true;\n this._connection.close();\n\n // A valid array of APDUs is required in a bulk query\n if (\n !Array.isArray(input.data) ||\n input.data.length === 0 ||\n !input.data.every((data) => typeof data === \"string\")\n ) {\n notifyError(new SecureChannelError(\"Invalid bulk data received\"));\n return;\n }\n\n for (let i = 0, len = input.data.length; i < len; i++) {\n // APDU should be a valid hex string\n const apdu = hexaStringToBuffer(input.data[i]!);\n if (apdu === null || apdu.length < 5) {\n notifyError(\n new SecureChannelError(\n `Received invalid APDU bulk data: ${input.data[i]}`,\n ),\n );\n return;\n }\n\n // Send APDU to the device\n const response = await this._api.sendApdu(apdu);\n if (unsubscribed) {\n return;\n }\n\n // Map device response\n if (response.isLeft()) {\n notifyError(new SecureChannelError(response.extract()));\n return;\n } else if (response.isRight()) {\n const deviceError = this.mapDeviceError(response.extract());\n if (deviceError === null) {\n // Notify the progress\n subscriber.next({\n type: SecureChannelEventType.Progress,\n payload: {\n progress: +Number((i + 1) / len).toFixed(2),\n index: i,\n total: len,\n },\n });\n } else {\n notifyError(deviceError);\n return;\n }\n }\n }\n communicationFinished = true;\n subscriber.complete();\n break;\n }\n case InMessageQueryEnum.SUCCESS: {\n if (ignoreNetworkEvents) {\n break;\n }\n // Emit the result if there is any\n const payload = input.result ?? input.data;\n if (payload) {\n subscriber.next({\n type: SecureChannelEventType.Result,\n payload: payload ?? \"\",\n });\n }\n communicationFinished = true;\n subscriber.complete();\n break;\n }\n case InMessageQueryEnum.WARNING: {\n if (ignoreNetworkEvents) {\n break;\n }\n subscriber.next({\n type: SecureChannelEventType.Warning,\n payload: { message: String(input.data) },\n });\n break;\n }\n case InMessageQueryEnum.ERROR: {\n if (ignoreNetworkEvents) {\n break;\n }\n notifyError(\n new SecureChannelError({\n url: this._connection.url,\n errorMessage: String(input.data),\n }),\n );\n }\n }\n };\n\n return () => {\n reenableRefresher();\n unsubscribed = true;\n // Close the connection if it is open when unsubscribing\n if (this._connection.readyState === WebSocket.OPEN) {\n this._connection.close();\n }\n };\n });\n\n return obs;\n }\n\n /**\n * Determines if a secure connection is already allowed based on the current device session state.\n *\n * @returns {boolean} `true` if a secure connection is allowed, otherwise `false`.\n */\n isSecureConnectionAllowed(): boolean {\n const deviceSessionState = this._api.getDeviceSessionState();\n return (\n \"isSecureConnectionAllowed\" in deviceSessionState &&\n deviceSessionState.isSecureConnectionAllowed\n );\n }\n\n isInMessageType(data: unknown): data is InMessageType {\n if (typeof data !== \"object\" || !data) {\n return false;\n }\n\n const message = data as InMessageType;\n return (\n typeof message.uuid === \"string\" &&\n typeof message.session === \"string\" &&\n typeof message.query === \"string\" &&\n Object.values(InMessageQueryEnum).includes(message.query) &&\n typeof message.nonce === \"number\"\n );\n }\n\n mapDeviceError(apduResponse: ApduResponse): SecureChannelError | null {\n if (CommandUtils.isSuccessResponse(apduResponse)) {\n return null;\n }\n\n // Device is locked\n if (CommandUtils.isLockedDeviceResponse(apduResponse)) {\n return new SecureChannelError(\n {\n url: this._connection.url,\n errorMessage: `Device is locked`,\n },\n SecureChannelErrorType.DeviceLocked,\n );\n }\n\n // User refused the permission\n if (CommandUtils.isRefusedByUser(apduResponse)) {\n return new SecureChannelError(\n {\n url: this._connection.url,\n errorMessage: \"User refused on the device\",\n },\n SecureChannelErrorType.RefusedByUser,\n );\n }\n\n // App already installed\n if (CommandUtils.isAppAlreadyInstalled(apduResponse)) {\n return new SecureChannelError(\n {\n url: this._connection.url,\n errorMessage: \"App already installed\",\n },\n SecureChannelErrorType.AppAlreadyInstalled,\n );\n }\n\n // Out of memory\n if (CommandUtils.isOutOfMemory(apduResponse)) {\n return new SecureChannelError(\n {\n url: this._connection.url,\n errorMessage: \"Out of memory\",\n },\n SecureChannelErrorType.OutOfMemory,\n );\n }\n\n return new SecureChannelError({\n url: this._connection.url,\n errorMessage: `Invalid status code: ${bufferToHexaString(\n apduResponse.statusCode,\n )}`,\n });\n }\n}\n"],
5
+ "mappings": "AAAA,OAAOA,MAAe,gBAEtB,OAAS,cAAAC,MAAkB,OAE3B,OAAS,gBAAAC,MAAoB,kCAG7B,OACE,sBAAAC,EAEA,0BAAAC,EAGA,0BAAAC,MACK,iCACP,OAAS,yBAAAC,MAA6B,4BACtC,OAAS,sBAAAC,EAAoB,sBAAAC,MAA0B,wBACvD,OACE,sBAAAC,EACA,0BAAAC,MAEK,wCAMA,MAAMC,CAA2B,CAEtC,YACmBC,EACAC,EACjB,CAFiB,UAAAD,EACA,WAAAC,EAEjB,GAAI,KAAK,MAAM,WAAW,QAAQ,EAChC,KAAK,YAAc,KAAK,MAAM,WAAW,QAAQ,MAEjD,OAAM,IAAIJ,EACR,iCAAiC,OAAO,KAAK,MAAM,WAAW,QAAQ,CAAC,CAAC,EAC1E,CAEJ,CAZiB,YAcjB,KAAsC,CACpC,MAAMK,EAAoB,KAAK,KAAK,iBAClC,wBACF,EA4RA,OA1RY,IAAIb,EAAgCc,GAAe,CAC7D,IAAIC,EAAwB,GACxBC,EAAsB,GACtBC,EAAwB,GAE5B,MAAMC,EAAeC,GAA8B,CACjDL,EAAW,KAAK,CACd,KAAMV,EAAuB,MAC7B,MAAAe,CACF,CAAC,EACDL,EAAW,SAAS,EAGpBE,EAAsB,EACxB,EAEA,YAAK,YAAY,OAAS,IAAM,CAC9BF,EAAW,KAAK,CACd,KAAMV,EAAuB,MAC/B,CAAC,CACH,EAEA,KAAK,YAAY,QAAWe,GAAU,CAChCH,IAIJF,EAAW,KAAK,CACd,KAAMV,EAAuB,MAC7B,MAAO,IAAII,EAAmB,CAC5B,IAAK,KAAK,YAAY,IACtB,aAAcW,EAAM,OACtB,CAAC,CACH,CAAC,EACDL,EAAW,SAA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AAS,UAAY,CAACA,EAC/B,MAAO,GAGT,MAAMO,EAAUP,EAChB,OACE,OAAOO,EAAQ,MAAS,UACxB,OAAOA,EAAQ,SAAY,UAC3B,OAAOA,EAAQ,OAAU,UACzB,OAAO,OAAO7B,CAAkB,EAAE,SAAS6B,EAAQ,KAAK,GACxD,OAAOA,EAAQ,OAAU,QAE7B,CAEA,eAAeH,EAAuD,CACpE,OAAI3B,EAAa,kBAAkB2B,CAAY,EACtC,KAIL3B,EAAa,uBAAuB2B,CAAY,EAC3C,IAAIpB,EACT,CACE,IAAK,KAAK,YAAY,IACtB,aAAc,kBAChB,EACAC,EAAuB,YACzB,EAIER,EAAa,gBAAgB2B,CAAY,EACpC,IAAIpB,EACT,CACE,IAAK,KAAK,YAAY,IACtB,aAAc,4BAChB,EACAC,EAAuB,aACzB,EAIER,EAAa,sBAAsB2B,CAAY,EAC1C,IAAIpB,EACT,CACE,IAAK,KAAK,YAAY,IACtB,aAAc,uBAChB,EACAC,EAAuB,mBACzB,EAIER,EAAa,cAAc2B,CAAY,EAClC,IAAIpB,EACT,CACE,IAAK,KAAK,YAAY,IACtB,aAAc,eAChB,EACAC,EAAuB,WACzB,EAGK,IAAID,EAAmB,CAC5B,IAAK,KAAK,YAAY,IACtB,aAAc,wBAAwBF,EACpCsB,EAAa,UACf,CAAC,EACH,CAAC,CACH,CACF",
6
+ "names": ["WebSocket", "Observable", "CommandUtils", "InMessageQueryEnum", "OutMessageResponseEnum", "SecureChannelEventType", "willRequestPermission", "bufferToHexaString", "hexaStringToBuffer", "SecureChannelError", "SecureChannelErrorType", "ConnectToSecureChannelTask", "_api", "_args", "reenableRefresher", "subscriber", "unsubscribed", "ignoreNetworkEvents", "communicationFinished", "notifyError", "error", "event", "input", "jsonData", "nonce", "data", "apdu", "permissionRequested", "response", "apduResponse", "outMessageResponse", "deviceError", "message", "i", "len", "payload", "deviceSessionState"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import g from"isomorphic-ws";import{Right as u}from"purify-ts";import{describe as y,it as i,vi as s}from"vitest";import{SecureChannelEventType as a}from"../../secure-channel/task/types";import{SecureChannelError as x}from"../../../internal/secure-channel/model/Errors";import{ConnectToSecureChannelTask as h}from"./ConnectToSecureChannelTask";s.mock("isomorphic-ws",()=>({...s.importActual("isomorphic-ws"),__esModule:!0,default:class{onopen=null;onmessage=null;send=s.fn();close=s.fn();url;constructor(e){this.url=e}}}));const p=5;y("ConnectToSecureChannelTask",()=>{let e,d,m,c;const l=s.fn();beforeEach(()=>{e=new g("wss://test-host.com"),d={sendApdu:l,disableRefresher:s.fn()},m={connection:u(e)},c=new h(d,m)}),afterEach(()=>{s.resetAllMocks()}),i("should emit Opened event on WebSocket open",async()=>{const n=[];c.run().subscribe(t=>n.push(t)),expect(e.onopen).toBeDefined(),e.onopen({type:"open",target:{}}),await new Promise(t=>setTimeout(t,p)),expect(n).toStrictEqual([{type:a.Opened}])}),i("should handle incoming EXCHANGE message including requesting user permission",async()=>{l.mockResolvedValue(u({data:new Uint8Array([144,0]),statusCode:new Uint8Array([144,0])}));const n=s.spyOn(e,"send");s.spyOn(c,"isSecureConnectionAllowed").mockReturnValueOnce(!1);const o=[];c.run().subscribe({next:r=>{o.push(r)}}),expect(e.onmessage).toBeDefined(),e.onmessage({data:JSON.stringify({query:"exchange",nonce:1,data:"e051000000"}),type:"",target:{}}),await new Promise(r=>setTimeout(r,p)),expect(n).toHaveBeenCalledExactlyOnceWith(JSON.stringify({nonce:1,response:"success",data:"9000"})),expect(o).toStrictEqual([{type:a.PreExchange,payload:{nonce:1,apdu:new Uint8Array([224,81,0,0,0])}},{type:a.PermissionRequested},{type:a.Exchange,payload:{nonce:1,apdu:new Uint8Array([224,81,0,0,0]),data:new Uint8Array([144,0]),status:new Uint8Array([144,0])}},{type:a.PermissionGranted}])}),i("should handle incoming BULK message",async()=>{l.mockResolvedValue(u({data:new Uint8Array([144,0]),statusCode:new Uint8Array([144,0])}));const n=s.fn(),o=c.run(),t=[];o.subscribe({next:r=>{t.push(r)},complete:()=>n()}),expect(e.onmessage).toBeDefined(),e.onmessage({data:JSON.stringify({query:"bulk",nonce:1,data:["0000000100","0000000200","0000000300"]}),type:"",target:{}}),await new Promise(r=>setTimeout(r,p)),expect(l).toHaveBeenCalledTimes(3),expect(t).toStrictEqual([{type:a.Progress,payload:{progress:.33,index:0,total:3}},{type:a.Progress,payload:{progress:.67,index:1,total:3}},{type:a.Progress,payload:{progress:1,index:2,total:3}}]),expect(n).toHaveBeenCalledOnce()}),i("should handle incoming SUCCESS message",()=>{const n=s.fn(),o=[];c.run().subscribe({next:r=>o.push(r),complete:()=>n()}),e.onmessage({data:JSON.stringify({query:"success",nonce:1,result:"success result"}),type:"",target:{}}),expect(o).toStrictEqual([{type:a.Result,payload:"success result"}]),expect(n).toHaveBeenCalledOnce()}),i("should handle incoming WARNING message",()=>{const n=[];c.run().subscribe({next:t=>n.push(t)}),expect(e.onmessage).toBeDefined(),e.onmessage({data:JSON.stringify({query:"warning",nonce:1,data:"warning message"}),type:"",target:{}}),expect(n).toStrictEqual([{type:a.Warning,payload:{message:"warning message"}}])}),i("should handle incoming ERROR message",()=>{const n=s.fn();c.run().subscribe({error:t=>{expect(t).toBeInstanceOf(x),n(t)}}),expect(e.onmessage).toBeDefined(),e.onmessage({data:JSON.stringify({query:"error"}),type:"",target:{}}),expect(n).toHaveBeenCalled()})});
1
+ import h from"isomorphic-ws";import{Right as p}from"purify-ts";import{describe as S,it as i,vi as r}from"vitest";import{SecureChannelEventType as a}from"../../secure-channel/task/types";import{SecureChannelError as m,SecureChannelErrorType as x}from"../../../internal/secure-channel/model/Errors";import{ConnectToSecureChannelTask as b}from"./ConnectToSecureChannelTask";r.mock("isomorphic-ws",()=>({...r.importActual("isomorphic-ws"),__esModule:!0,default:class{onopen=null;onmessage=null;send=r.fn();close=r.fn();url;constructor(n){this.url=n}}}));const d=5;S("ConnectToSecureChannelTask",()=>{let n,y,g,c;const l=r.fn(),u={uuid:"5b776c8d-8af2-48c0-8250-04edca2ef5e9",session:"39ce749e-00a4-4c31-a697-1dc1a29e2cab",query:"success",nonce:15};beforeEach(()=>{n=new h("wss://test-host.com"),y={sendApdu:l,disableRefresher:e=>r.fn()},g={connection:p(n)},c=new b(y,g)}),afterEach(()=>{r.resetAllMocks()}),i("should emit Opened event on WebSocket open",async()=>{const e=[];c.run().subscribe(t=>e.push(t)),expect(n.onopen).toBeDefined(),n.onopen({type:"open",target:{}}),await new Promise(t=>setTimeout(t,d)),expect(e).toStrictEqual([{type:a.Opened}])}),i("Error on wrongly formatted message",async()=>{const e=[];c.run().subscribe({next:t=>{e.push(t)}}),expect(n.onmessage).toBeDefined(),n.onmessage({data:"invalidData",type:"",target:{}}),await new Promise(t=>setTimeout(t,d)),expect(e).toStrictEqual([{type:a.Error,error:new m({url:"wss://test-host.com",errorMessage:"Invalid message received: invalidData"})}])}),i("should handle incoming EXCHANGE message including requesting user permission",async()=>{l.mockResolvedValue(p({data:new Uint8Array([144,0]),statusCode:new Uint8Array([144,0])}));const e=r.spyOn(n,"send");r.spyOn(c,"isSecureConnectionAllowed").mockReturnValueOnce(!1);const o=[];c.run().subscribe({next:s=>{o.push(s)}}),expect(n.onmessage).toBeDefined(),n.onmessage({data:JSON.stringify({...u,query:"exchange",nonce:1,data:"e051000000"}),type:"",target:{}}),await new Promise(s=>setTimeout(s,d)),expect(e).toHaveBeenCalledExactlyOnceWith(JSON.stringify({nonce:1,response:"success",data:"9000"})),expect(o).toStrictEqual([{type:a.PreExchange,payload:{nonce:1,apdu:new Uint8Array([224,81,0,0,0])}},{type:a.PermissionRequested},{type:a.Exchange,payload:{nonce:1,apdu:new Uint8Array([224,81,0,0,0]),data:new Uint8Array([144,0]),status:new Uint8Array([144,0])}},{type:a.PermissionGranted}])}),i("should handle incoming EXCHANGE message with a device error",async()=>{l.mockResolvedValue(p({data:new Uint8Array([]),statusCode:new Uint8Array([85,21])}));const e=r.spyOn(n,"send"),o=[];c.run().subscribe({next:s=>{o.push(s)}}),expect(n.onmessage).toBeDefined(),n.onmessage({data:JSON.stringify({...u,query:"exchange",nonce:1,data:"e053000000"}),type:"",target:{}}),await new Promise(s=>setTimeout(s,d)),expect(e).toHaveBeenCalledExactlyOnceWith(JSON.stringify({nonce:1,response:"error",data:""})),expect(o).toStrictEqual([{type:a.PreExchange,payload:{nonce:1,apdu:new Uint8Array([224,83,0,0,0])}},{type:a.Error,error:new m({url:"wss://test-host.com",errorMessage:"Device is locked"},x.DeviceLocked)}])}),i("should handle incoming BULK message",async()=>{l.mockResolvedValue(p({data:new Uint8Array([144,0]),statusCode:new Uint8Array([144,0])}));const e=r.fn(),o=c.run(),t=[];o.subscribe({next:s=>{t.push(s)},complete:()=>e()}),expect(n.onmessage).toBeDefined(),n.onmessage({data:JSON.stringify({...u,query:"bulk",nonce:1,data:["0000000100","0000000200","0000000300"]}),type:"",target:{}}),await new Promise(s=>setTimeout(s,d)),expect(l).toHaveBeenCalledTimes(3),expect(t).toStrictEqual([{type:a.Progress,payload:{progress:.33,index:0,total:3}},{type:a.Progress,payload:{progress:.67,index:1,total:3}},{type:a.Progress,payload:{progress:1,index:2,total:3}}]),expect(e).toHaveBeenCalledOnce()}),i("should handle incoming BULK message with a device error",async()=>{l.mockResolvedValue(p({data:new Uint8Array([]),statusCode:new Uint8Array([85,1])}));const e=r.fn(),o=c.run(),t=[];o.subscribe({next:s=>{t.push(s)},complete:()=>e()}),expect(n.onmessage).toBeDefined(),n.onmessage({data:JSON.stringify({...u,query:"bulk",nonce:1,data:["0000000100","0000000200","0000000300"]}),type:"",target:{}}),await new Promise(s=>setTimeout(s,d)),expect(l).toHaveBeenCalledTimes(1),expect(t).toStrictEqual([{type:a.Error,error:new m({url:"wss://test-host.com",errorMessage:"User refused on the device"},x.RefusedByUser)}]),expect(e).toHaveBeenCalledOnce()}),i("should handle incoming SUCCESS message",()=>{const e=r.fn(),o=[];c.run().subscribe({next:s=>o.push(s),complete:()=>e()}),n.onmessage({data:JSON.stringify({...u,query:"success",nonce:1,result:"success result"}),type:"",target:{}}),expect(o).toStrictEqual([{type:a.Result,payload:"success result"}]),expect(e).toHaveBeenCalledOnce()}),i("should handle incoming WARNING message",()=>{const e=[];c.run().subscribe({next:t=>e.push(t)}),expect(n.onmessage).toBeDefined(),n.onmessage({data:JSON.stringify({...u,query:"warning",nonce:1,data:"warning message"}),type:"",target:{}}),expect(e).toStrictEqual([{type:a.Warning,payload:{message:"warning message"}}])}),i("should handle incoming ERROR message",()=>{const e=[];c.run().subscribe({next:t=>e.push(t)}),expect(n.onmessage).toBeDefined(),n.onmessage({data:JSON.stringify({...u,query:"error",data:"My error"}),type:"",target:{}}),expect(e).toStrictEqual([{type:a.Error,error:new m({url:"wss://test-host.com",errorMessage:"My error"})}])})});
2
2
  //# sourceMappingURL=ConnectToSecureChannelTask.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/api/secure-channel/task/ConnectToSecureChannelTask.test.ts"],
4
- "sourcesContent": ["import WebSocket from \"isomorphic-ws\";\nimport { Right } from \"purify-ts\";\nimport { describe, it, vi } from \"vitest\";\n\nimport { type InternalApi } from \"@api/index\";\nimport {\n type SecureChannelEvent,\n SecureChannelEventType,\n} from \"@api/secure-channel/task/types\";\nimport { SecureChannelError } from \"@internal/secure-channel/model/Errors\";\n\nimport {\n ConnectToSecureChannelTask,\n type ConnectToSecureChannelTaskArgs,\n} from \"./ConnectToSecureChannelTask\";\n\nvi.mock(\"isomorphic-ws\", () => ({\n ...vi.importActual(\"isomorphic-ws\"),\n __esModule: true,\n default: class {\n onopen: (() => void) | null = null;\n onmessage: ((event: { data: string }) => void) | null = null;\n send = vi.fn();\n close = vi.fn();\n url: string;\n constructor(url: string) {\n this.url = url;\n }\n },\n}));\n\nconst TEST_DELAY = 5;\n\ndescribe(\"ConnectToSecureChannelTask\", () => {\n let mockWebSocket: WebSocket;\n let mockInternalApi: InternalApi;\n let taskArgs: ConnectToSecureChannelTaskArgs;\n let task: ConnectToSecureChannelTask;\n const sendApduFn = vi.fn();\n\n beforeEach(() => {\n // vi.useFakeTimers({ shouldAdvanceTime: true });\n\n mockWebSocket = new WebSocket(\"wss://test-host.com\");\n mockInternalApi = {\n sendApdu: sendApduFn,\n disableRefresher: vi.fn(),\n } as unknown as InternalApi;\n taskArgs = { connection: Right(mockWebSocket) };\n task = new ConnectToSecureChannelTask(mockInternalApi, taskArgs);\n });\n\n afterEach(() => {\n vi.resetAllMocks();\n });\n\n it(\"should emit Opened event on WebSocket open\", async () => {\n const events: SecureChannelEvent[] = [];\n const obs = task.run();\n obs.subscribe((e) => events.push(e));\n\n expect(mockWebSocket.onopen).toBeDefined();\n mockWebSocket.onopen!({\n type: \"open\",\n target: {} as WebSocket,\n });\n\n await new Promise((resolve) => setTimeout(resolve, TEST_DELAY));\n\n expect(events).toStrictEqual([{ type: SecureChannelEventType.Opened }]);\n });\n\n it(\"should handle incoming EXCHANGE message including requesting user permission\", async () => {\n sendApduFn.mockResolvedValue(\n Right({\n data: new Uint8Array([0x90, 0x00]),\n statusCode: new Uint8Array([0x90, 0x00]),\n }),\n );\n\n const sendSpy = vi.spyOn(mockWebSocket, \"send\");\n vi.spyOn(task, \"isSecureConnectionAllowed\").mockReturnValueOnce(false);\n\n const events: SecureChannelEvent[] = [];\n const obs = task.run();\n obs.subscribe({\n next: (event) => {\n events.push(event);\n },\n });\n\n expect(mockWebSocket.onmessage).toBeDefined();\n mockWebSocket.onmessage!({\n data: JSON.stringify({\n query: \"exchange\",\n nonce: 1,\n data: \"e051000000\",\n }),\n type: \"\",\n target: {} as WebSocket,\n });\n\n await new Promise((resolve) => setTimeout(resolve, TEST_DELAY));\n\n expect(sendSpy).toHaveBeenCalledExactlyOnceWith(\n JSON.stringify({\n nonce: 1,\n response: \"success\",\n data: \"9000\",\n }),\n );\n expect(events).toStrictEqual([\n {\n type: SecureChannelEventType.PreExchange,\n payload: {\n nonce: 1,\n apdu: new Uint8Array([0xe0, 0x51, 0x00, 0x00, 0x00]),\n },\n },\n {\n type: SecureChannelEventType.PermissionRequested,\n },\n {\n type: SecureChannelEventType.Exchange,\n payload: {\n nonce: 1,\n apdu: new Uint8Array([0xe0, 0x51, 0x00, 0x00, 0x00]),\n data: new Uint8Array([0x90, 0x00]),\n status: new Uint8Array([0x90, 0x00]),\n },\n },\n {\n type: SecureChannelEventType.PermissionGranted,\n },\n ]);\n });\n\n it(\"should handle incoming BULK message\", async () => {\n sendApduFn.mockResolvedValue(\n Right({\n data: new Uint8Array([0x90, 0x00]),\n statusCode: new Uint8Array([0x90, 0x00]),\n }),\n );\n const completeFn: () => void = vi.fn();\n const obs = task.run();\n const events: SecureChannelEvent[] = [];\n obs.subscribe({\n next: (event: SecureChannelEvent) => {\n events.push(event);\n },\n complete: () => completeFn(),\n });\n\n expect(mockWebSocket.onmessage).toBeDefined();\n mockWebSocket.onmessage!({\n data: JSON.stringify({\n query: \"bulk\",\n nonce: 1,\n data: [\"0000000100\", \"0000000200\", \"0000000300\"],\n }),\n type: \"\",\n target: {} as WebSocket,\n });\n\n await new Promise((resolve) => setTimeout(resolve, TEST_DELAY));\n\n expect(sendApduFn).toHaveBeenCalledTimes(3);\n expect(events).toStrictEqual([\n {\n type: SecureChannelEventType.Progress,\n payload: { progress: 0.33, index: 0, total: 3 },\n },\n {\n type: SecureChannelEventType.Progress,\n payload: { progress: 0.67, index: 1, total: 3 },\n },\n {\n type: SecureChannelEventType.Progress,\n payload: { progress: 1.0, index: 2, total: 3 },\n },\n ]);\n expect(completeFn).toHaveBeenCalledOnce();\n });\n\n it(\"should handle incoming SUCCESS message\", () => {\n const completeFn: () => void = vi.fn();\n const events: SecureChannelEvent[] = [];\n const observable = task.run();\n observable.subscribe({\n next: (event: SecureChannelEvent) => events.push(event),\n complete: () => completeFn(),\n });\n\n mockWebSocket.onmessage!({\n data: JSON.stringify({\n query: \"success\",\n nonce: 1,\n result: \"success result\",\n }),\n type: \"\",\n target: {} as WebSocket,\n });\n\n expect(events).toStrictEqual([\n { type: SecureChannelEventType.Result, payload: \"success result\" },\n ]);\n expect(completeFn).toHaveBeenCalledOnce();\n });\n\n it(\"should handle incoming WARNING message\", () => {\n const events: SecureChannelEvent[] = [];\n const observable = task.run();\n observable.subscribe({\n next: (event: SecureChannelEvent) => events.push(event),\n });\n\n expect(mockWebSocket.onmessage).toBeDefined();\n mockWebSocket.onmessage!({\n data: JSON.stringify({\n query: \"warning\",\n nonce: 1,\n data: \"warning message\",\n }),\n type: \"\",\n target: {} as WebSocket,\n });\n\n expect(events).toStrictEqual([\n {\n type: SecureChannelEventType.Warning,\n payload: { message: \"warning message\" },\n },\n ]);\n });\n\n it(\"should handle incoming ERROR message\", () => {\n const errorFn = vi.fn();\n const observable = task.run();\n observable.subscribe({\n error: (err) => {\n expect(err).toBeInstanceOf(SecureChannelError);\n errorFn(err);\n },\n });\n\n expect(mockWebSocket.onmessage).toBeDefined();\n mockWebSocket.onmessage!({\n data: JSON.stringify({\n query: \"error\",\n }),\n type: \"\",\n target: {} as WebSocket,\n });\n\n expect(errorFn).toHaveBeenCalled();\n });\n});\n"],
5
- "mappings": "AAAA,OAAOA,MAAe,gBACtB,OAAS,SAAAC,MAAa,YACtB,OAAS,YAAAC,EAAU,MAAAC,EAAI,MAAAC,MAAU,SAGjC,OAEE,0BAAAC,MACK,iCACP,OAAS,sBAAAC,MAA0B,wCAEnC,OACE,8BAAAC,MAEK,+BAEPH,EAAG,KAAK,gBAAiB,KAAO,CAC9B,GAAGA,EAAG,aAAa,eAAe,EAClC,WAAY,GACZ,QAAS,KAAM,CACb,OAA8B,KAC9B,UAAwD,KACxD,KAAOA,EAAG,GAAG,EACb,MAAQA,EAAG,GAAG,EACd,IACA,YAAYI,EAAa,CACvB,KAAK,IAAMA,CACb,CACF,CACF,EAAE,EAEF,MAAMC,EAAa,EAEnBP,EAAS,6BAA8B,IAAM,CAC3C,IAAIQ,EACAC,EACAC,EACAC,EACJ,MAAMC,EAAaV,EAAG,GAAG,EAEzB,WAAW,IAAM,CAG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MAAMmB,EAAUlB,EAAG,GAAG,EACHS,EAAK,IAAI,EACjB,UAAU,CACnB,MAAQU,GAAQ,CACd,OAAOA,CAAG,EAAE,eAAejB,CAAkB,EAC7CgB,EAAQC,CAAG,CACb,CACF,CAAC,EAED,OAAOb,EAAc,SAAS,EAAE,YAAY,EAC5CA,EAAc,UAAW,CACvB,KAAM,KAAK,UAAU,CACnB,MAAO,OACT,CAAC,EACD,KAAM,GACN,OAAQ,CAAC,CACX,CAAC,EAED,OAAOY,CAAO,EAAE,iBAAiB,CACnC,CAAC,CACH,CAAC",
6
- "names": ["WebSocket", "Right", "describe", "it", "vi", "SecureChannelEventType", "SecureChannelError", "ConnectToSecureChannelTask", "url", "TEST_DELAY", "mockWebSocket", "mockInternalApi", "taskArgs", "task", "sendApduFn", "events", "e", "resolve", "sendSpy", "event", "completeFn", "obs", "errorFn", "err"]
4
+ "sourcesContent": ["import WebSocket from \"isomorphic-ws\";\nimport { Right } from \"purify-ts\";\nimport { describe, it, vi } from \"vitest\";\n\nimport { type InternalApi } from \"@api/index\";\nimport {\n type SecureChannelEvent,\n SecureChannelEventType,\n} from \"@api/secure-channel/task/types\";\nimport {\n SecureChannelError,\n SecureChannelErrorType,\n} from \"@internal/secure-channel/model/Errors\";\n\nimport {\n ConnectToSecureChannelTask,\n type ConnectToSecureChannelTaskArgs,\n} from \"./ConnectToSecureChannelTask\";\n\nvi.mock(\"isomorphic-ws\", () => ({\n ...vi.importActual(\"isomorphic-ws\"),\n __esModule: true,\n default: class {\n onopen: (() => void) | null = null;\n onmessage: ((event: { data: string }) => void) | null = null;\n send = vi.fn();\n close = vi.fn();\n url: string;\n constructor(url: string) {\n this.url = url;\n }\n },\n}));\n\nconst TEST_DELAY = 5;\n\ndescribe(\"ConnectToSecureChannelTask\", () => {\n let mockWebSocket: WebSocket;\n let mockInternalApi: InternalApi;\n let taskArgs: ConnectToSecureChannelTaskArgs;\n let task: ConnectToSecureChannelTask;\n const sendApduFn = vi.fn();\n const mockMessage = {\n uuid: \"5b776c8d-8af2-48c0-8250-04edca2ef5e9\",\n session: \"39ce749e-00a4-4c31-a697-1dc1a29e2cab\",\n query: \"success\",\n nonce: 15,\n };\n\n beforeEach(() => {\n // vi.useFakeTimers({ shouldAdvanceTime: true });\n\n mockWebSocket = new WebSocket(\"wss://test-host.com\");\n mockInternalApi = {\n sendApdu: sendApduFn,\n disableRefresher: (_: unknown) => vi.fn(),\n } as unknown as InternalApi;\n taskArgs = { connection: Right(mockWebSocket) };\n task = new ConnectToSecureChannelTask(mockInternalApi, taskArgs);\n });\n\n afterEach(() => {\n vi.resetAllMocks();\n });\n\n it(\"should emit Opened event on WebSocket open\", async () => {\n const events: SecureChannelEvent[] = [];\n const obs = task.run();\n obs.subscribe((e) => events.push(e));\n\n expect(mockWebSocket.onopen).toBeDefined();\n mockWebSocket.onopen!({\n type: \"open\",\n target: {} as WebSocket,\n });\n\n await new Promise((resolve) => setTimeout(resolve, TEST_DELAY));\n\n expect(events).toStrictEqual([{ type: SecureChannelEventType.Opened }]);\n });\n\n it(\"Error on wrongly formatted message\", async () => {\n const events: SecureChannelEvent[] = [];\n const obs = task.run();\n obs.subscribe({\n next: (event) => {\n events.push(event);\n },\n });\n\n expect(mockWebSocket.onmessage).toBeDefined();\n mockWebSocket.onmessage!({\n data: \"invalidData\",\n type: \"\",\n target: {} as WebSocket,\n });\n\n await new Promise((resolve) => setTimeout(resolve, TEST_DELAY));\n\n expect(events).toStrictEqual([\n {\n type: SecureChannelEventType.Error,\n error: new SecureChannelError({\n url: \"wss://test-host.com\",\n errorMessage: \"Invalid message received: invalidData\",\n }),\n },\n ]);\n });\n\n it(\"should handle incoming EXCHANGE message including requesting user permission\", async () => {\n sendApduFn.mockResolvedValue(\n Right({\n data: new Uint8Array([0x90, 0x00]),\n statusCode: new Uint8Array([0x90, 0x00]),\n }),\n );\n\n const sendSpy = vi.spyOn(mockWebSocket, \"send\");\n vi.spyOn(task, \"isSecureConnectionAllowed\").mockReturnValueOnce(false);\n\n const events: SecureChannelEvent[] = [];\n const obs = task.run();\n obs.subscribe({\n next: (event) => {\n events.push(event);\n },\n });\n\n expect(mockWebSocket.onmessage).toBeDefined();\n mockWebSocket.onmessage!({\n data: JSON.stringify({\n ...mockMessage,\n query: \"exchange\",\n nonce: 1,\n data: \"e051000000\",\n }),\n type: \"\",\n target: {} as WebSocket,\n });\n\n await new Promise((resolve) => setTimeout(resolve, TEST_DELAY));\n\n expect(sendSpy).toHaveBeenCalledExactlyOnceWith(\n JSON.stringify({\n nonce: 1,\n response: \"success\",\n data: \"9000\",\n }),\n );\n expect(events).toStrictEqual([\n {\n type: SecureChannelEventType.PreExchange,\n payload: {\n nonce: 1,\n apdu: new Uint8Array([0xe0, 0x51, 0x00, 0x00, 0x00]),\n },\n },\n {\n type: SecureChannelEventType.PermissionRequested,\n },\n {\n type: SecureChannelEventType.Exchange,\n payload: {\n nonce: 1,\n apdu: new Uint8Array([0xe0, 0x51, 0x00, 0x00, 0x00]),\n data: new Uint8Array([0x90, 0x00]),\n status: new Uint8Array([0x90, 0x00]),\n },\n },\n {\n type: SecureChannelEventType.PermissionGranted,\n },\n ]);\n });\n\n it(\"should handle incoming EXCHANGE message with a device error\", async () => {\n sendApduFn.mockResolvedValue(\n Right({\n data: new Uint8Array([]),\n statusCode: new Uint8Array([0x55, 0x15]),\n }),\n );\n\n const sendSpy = vi.spyOn(mockWebSocket, \"send\");\n const events: SecureChannelEvent[] = [];\n const obs = task.run();\n obs.subscribe({\n next: (event) => {\n events.push(event);\n },\n });\n\n expect(mockWebSocket.onmessage).toBeDefined();\n mockWebSocket.onmessage!({\n data: JSON.stringify({\n ...mockMessage,\n query: \"exchange\",\n nonce: 1,\n data: \"e053000000\",\n }),\n type: \"\",\n target: {} as WebSocket,\n });\n\n await new Promise((resolve) => setTimeout(resolve, TEST_DELAY));\n\n expect(sendSpy).toHaveBeenCalledExactlyOnceWith(\n JSON.stringify({\n nonce: 1,\n response: \"error\",\n data: \"\",\n }),\n );\n expect(events).toStrictEqual([\n {\n type: SecureChannelEventType.PreExchange,\n payload: {\n nonce: 1,\n apdu: new Uint8Array([0xe0, 0x53, 0x00, 0x00, 0x00]),\n },\n },\n {\n type: SecureChannelEventType.Error,\n error: new SecureChannelError(\n {\n url: \"wss://test-host.com\",\n errorMessage: \"Device is locked\",\n },\n SecureChannelErrorType.DeviceLocked,\n ),\n },\n ]);\n });\n\n it(\"should handle incoming BULK message\", async () => {\n sendApduFn.mockResolvedValue(\n Right({\n data: new Uint8Array([0x90, 0x00]),\n statusCode: new Uint8Array([0x90, 0x00]),\n }),\n );\n const completeFn: () => void = vi.fn();\n const obs = task.run();\n const events: SecureChannelEvent[] = [];\n obs.subscribe({\n next: (event: SecureChannelEvent) => {\n events.push(event);\n },\n complete: () => completeFn(),\n });\n\n expect(mockWebSocket.onmessage).toBeDefined();\n mockWebSocket.onmessage!({\n data: JSON.stringify({\n ...mockMessage,\n query: \"bulk\",\n nonce: 1,\n data: [\"0000000100\", \"0000000200\", \"0000000300\"],\n }),\n type: \"\",\n target: {} as WebSocket,\n });\n\n await new Promise((resolve) => setTimeout(resolve, TEST_DELAY));\n\n expect(sendApduFn).toHaveBeenCalledTimes(3);\n expect(events).toStrictEqual([\n {\n type: SecureChannelEventType.Progress,\n payload: { progress: 0.33, index: 0, total: 3 },\n },\n {\n type: SecureChannelEventType.Progress,\n payload: { progress: 0.67, index: 1, total: 3 },\n },\n {\n type: SecureChannelEventType.Progress,\n payload: { progress: 1.0, index: 2, total: 3 },\n },\n ]);\n expect(completeFn).toHaveBeenCalledOnce();\n });\n\n it(\"should handle incoming BULK message with a device error\", async () => {\n sendApduFn.mockResolvedValue(\n Right({\n data: new Uint8Array([]),\n statusCode: new Uint8Array([0x55, 0x01]),\n }),\n );\n const completeFn: () => void = vi.fn();\n const obs = task.run();\n const events: SecureChannelEvent[] = [];\n obs.subscribe({\n next: (event: SecureChannelEvent) => {\n events.push(event);\n },\n complete: () => completeFn(),\n });\n\n expect(mockWebSocket.onmessage).toBeDefined();\n mockWebSocket.onmessage!({\n data: JSON.stringify({\n ...mockMessage,\n query: \"bulk\",\n nonce: 1,\n data: [\"0000000100\", \"0000000200\", \"0000000300\"],\n }),\n type: \"\",\n target: {} as WebSocket,\n });\n\n await new Promise((resolve) => setTimeout(resolve, TEST_DELAY));\n\n expect(sendApduFn).toHaveBeenCalledTimes(1);\n expect(events).toStrictEqual([\n {\n type: SecureChannelEventType.Error,\n error: new SecureChannelError(\n {\n url: \"wss://test-host.com\",\n errorMessage: \"User refused on the device\",\n },\n SecureChannelErrorType.RefusedByUser,\n ),\n },\n ]);\n expect(completeFn).toHaveBeenCalledOnce();\n });\n\n it(\"should handle incoming SUCCESS message\", () => {\n const completeFn: () => void = vi.fn();\n const events: SecureChannelEvent[] = [];\n const observable = task.run();\n observable.subscribe({\n next: (event: SecureChannelEvent) => events.push(event),\n complete: () => completeFn(),\n });\n\n mockWebSocket.onmessage!({\n data: JSON.stringify({\n ...mockMessage,\n query: \"success\",\n nonce: 1,\n result: \"success result\",\n }),\n type: \"\",\n target: {} as WebSocket,\n });\n\n expect(events).toStrictEqual([\n { type: SecureChannelEventType.Result, payload: \"success result\" },\n ]);\n expect(completeFn).toHaveBeenCalledOnce();\n });\n\n it(\"should handle incoming WARNING message\", () => {\n const events: SecureChannelEvent[] = [];\n const observable = task.run();\n observable.subscribe({\n next: (event: SecureChannelEvent) => events.push(event),\n });\n\n expect(mockWebSocket.onmessage).toBeDefined();\n mockWebSocket.onmessage!({\n data: JSON.stringify({\n ...mockMessage,\n query: \"warning\",\n nonce: 1,\n data: \"warning message\",\n }),\n type: \"\",\n target: {} as WebSocket,\n });\n\n expect(events).toStrictEqual([\n {\n type: SecureChannelEventType.Warning,\n payload: { message: \"warning message\" },\n },\n ]);\n });\n\n it(\"should handle incoming ERROR message\", () => {\n const events: SecureChannelEvent[] = [];\n const observable = task.run();\n observable.subscribe({\n next: (event: SecureChannelEvent) => events.push(event),\n });\n\n expect(mockWebSocket.onmessage).toBeDefined();\n mockWebSocket.onmessage!({\n data: JSON.stringify({\n ...mockMessage,\n query: \"error\",\n data: \"My error\",\n }),\n type: \"\",\n target: {} as WebSocket,\n });\n\n expect(events).toStrictEqual([\n {\n type: SecureChannelEventType.Error,\n error: new SecureChannelError({\n url: \"wss://test-host.com\",\n errorMessage: \"My error\",\n }),\n },\n ]);\n });\n});\n"],
5
+ "mappings": "AAAA,OAAOA,MAAe,gBACtB,OAAS,SAAAC,MAAa,YACtB,OAAS,YAAAC,EAAU,MAAAC,EAAI,MAAAC,MAAU,SAGjC,OAEE,0BAAAC,MACK,iCACP,OACE,sBAAAC,EACA,0BAAAC,MACK,wCAEP,OACE,8BAAAC,MAEK,+BAEPJ,EAAG,KAAK,gBAAiB,KAAO,CAC9B,GAAGA,EAAG,aAAa,eAAe,EAClC,WAAY,GACZ,QAAS,KAAM,CACb,OAA8B,KAC9B,UAAwD,KACxD,KAAOA,EAAG,GAAG,EACb,MAAQA,EAAG,GAAG,EACd,IACA,YAAYK,EAAa,CACvB,KAAK,IAAMA,CACb,CACF,CACF,EAAE,EAEF,MAAMC,EAAa,EAEnBR,EAAS,6BAA8B,IAAM,CAC3C,IAAIS,EACAC,EACAC,EACAC,EACJ,MAAMC,EAAaX,EAAG,GAAG,EACnBY,EAAc,CAClB,KAAM,uCACN,QAAS,uCACT,MAAO,UACP,MAAO,EACT,EAEA,WAAW,IAAM,CAGfL,EAAgB,IAAIX,EAAU,qBAAqB,EACnDY,EAAkB,CAChB,SAAUG,EACV,iBAAmBE,GAAeb,EAAG,GAAG,CAC1C,EACAS,EAAW,CAAE,WAAYZ,EAAMU,CAAa,CAAE,EAC9CG,EAAO,IAAIN,EAA2BI,EAAiBC,CAAQ,CACjE,CAAC,EAED,UAAU,IAAM,CACdT,EAAG,cAAc,CACnB,CAAC,EAEDD,EAAG,6CAA8C,SAAY,CAC3D,MAAMe,EAA+B,CAAC,EAC1BJ,EAAK,IAAI,EACjB,UAAWK,GAAMD,EAAO,KAAK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ACnB,GAAGK,EACH,MAAO,UACP,MAAO,EACP,OAAQ,gBACV,CAAC,EACD,KAAM,GACN,OAAQ,CAAC,CACX,CAAC,EAED,OAAOE,CAAM,EAAE,cAAc,CAC3B,CAAE,KAAMb,EAAuB,OAAQ,QAAS,gBAAiB,CACnE,CAAC,EACD,OAAOkB,CAAU,EAAE,qBAAqB,CAC1C,CAAC,EAEDpB,EAAG,yCAA0C,IAAM,CACjD,MAAMe,EAA+B,CAAC,EACnBJ,EAAK,IAAI,EACjB,UAAU,CACnB,KAAOO,GAA8BH,EAAO,KAAKG,CAAK,CACxD,CAAC,EAED,OAAOV,EAAc,SAAS,EAAE,YAAY,EAC5CA,EAAc,UAAW,CACvB,KAAM,KAAK,UAAU,CACnB,GAAGK,EACH,MAAO,UACP,MAAO,EACP,KAAM,iBACR,CAAC,EACD,KAAM,GACN,OAAQ,CAAC,CACX,CAAC,EAED,OAAOE,CAAM,EAAE,cAAc,CAC3B,CACE,KAAMb,EAAuB,QAC7B,QAAS,CAAE,QAAS,iBAAkB,CACxC,CACF,CAAC,CACH,CAAC,EAEDF,EAAG,uCAAwC,IAAM,CAC/C,MAAMe,EAA+B,CAAC,EACnBJ,EAAK,IAAI,EACjB,UAAU,CACnB,KAAOO,GAA8BH,EAAO,KAAKG,CAAK,CACxD,CAAC,EAED,OAAOV,EAAc,SAAS,EAAE,YAAY,EAC5CA,EAAc,UAAW,CACvB,KAAM,KAAK,UAAU,CACnB,GAAGK,EACH,MAAO,QACP,KAAM,UACR,CAAC,EACD,KAAM,GACN,OAAQ,CAAC,CACX,CAAC,EAED,OAAOE,CAAM,EAAE,cAAc,CAC3B,CACE,KAAMb,EAAuB,MAC7B,MAAO,IAAIC,EAAmB,CAC5B,IAAK,sBACL,aAAc,UAChB,CAAC,CACH,CACF,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["WebSocket", "Right", "describe", "it", "vi", "SecureChannelEventType", "SecureChannelError", "SecureChannelErrorType", "ConnectToSecureChannelTask", "url", "TEST_DELAY", "mockWebSocket", "mockInternalApi", "taskArgs", "task", "sendApduFn", "mockMessage", "_", "events", "e", "resolve", "event", "sendSpy", "completeFn", "obs"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var a=(n=>(n.GenuineCheck="GenuineCheck",n.ListInstalledApps="ListInstalledApps",n.UpdateMcu="UpdateMcu",n.UpdateFirmware="UpdateFirmware",n.InstallApp="InstallApp",n.UninstallApp="UninstallApp",n))(a||{}),s=(r=>(r.EXCHANGE="exchange",r.BULK="bulk",r.ERROR="error",r.WARNING="warning",r.SUCCESS="success",r))(s||{}),p=(t=>(t.SUCCESS="success",t.ERROR="error",t))(p||{}),o=(e=>(e.Opened="opened",e.Closed="closed",e.PermissionRequested="permission-requested",e.PermissionGranted="permission-granted",e.PreExchange="pre-exchange",e.Exchange="exchange",e.Progress="progress",e.Warning="warning",e.Result="result",e))(o||{});export{s as InMessageQueryEnum,p as OutMessageResponseEnum,o as SecureChannelEventType,a as SecureChannelOperationEnum};
1
+ var a=(r=>(r.GenuineCheck="GenuineCheck",r.ListInstalledApps="ListInstalledApps",r.UpdateMcu="UpdateMcu",r.UpdateFirmware="UpdateFirmware",r.InstallApp="InstallApp",r.UninstallApp="UninstallApp",r))(a||{}),s=(n=>(n.EXCHANGE="exchange",n.BULK="bulk",n.ERROR="error",n.WARNING="warning",n.SUCCESS="success",n))(s||{}),p=(t=>(t.SUCCESS="success",t.ERROR="error",t))(p||{}),o=(e=>(e.Opened="opened",e.Closed="closed",e.PermissionRequested="permission-requested",e.PermissionGranted="permission-granted",e.PreExchange="pre-exchange",e.Exchange="exchange",e.Progress="progress",e.Warning="warning",e.Error="error",e.Result="result",e))(o||{});export{s as InMessageQueryEnum,p as OutMessageResponseEnum,o as SecureChannelEventType,a as SecureChannelOperationEnum};
2
2
  //# sourceMappingURL=types.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/api/secure-channel/task/types.ts"],
4
- "sourcesContent": ["export enum SecureChannelOperationEnum {\n GenuineCheck = \"GenuineCheck\",\n ListInstalledApps = \"ListInstalledApps\",\n UpdateMcu = \"UpdateMcu\",\n UpdateFirmware = \"UpdateFirmware\",\n InstallApp = \"InstallApp\",\n UninstallApp = \"UninstallApp\",\n}\n\n/**\n * The message that will be received from the server by the secure channel.\n */\nexport type InMessageType = {\n uuid: string;\n session: string;\n query: InMessageQueryEnum;\n nonce: number;\n data: string | Array<string>;\n result?: unknown;\n};\n\nexport enum InMessageQueryEnum {\n EXCHANGE = \"exchange\",\n BULK = \"bulk\",\n ERROR = \"error\",\n WARNING = \"warning\",\n SUCCESS = \"success\",\n}\n\n/**\n * The message that will be sent to the server by the secure channel.\n */\nexport type OutMessageType = {\n nonce: number;\n response: OutMessageResponseEnum;\n data: string;\n};\n\nexport enum OutMessageResponseEnum {\n SUCCESS = \"success\",\n ERROR = \"error\",\n}\n\n/**\n * The all event types that can be emitted to the client by the secure channel.\n *\n */\nexport enum SecureChannelEventType {\n Opened = \"opened\",\n Closed = \"closed\",\n PermissionRequested = \"permission-requested\",\n PermissionGranted = \"permission-granted\",\n PreExchange = \"pre-exchange\",\n Exchange = \"exchange\",\n Progress = \"progress\",\n Warning = \"warning\",\n Result = \"result\",\n}\n\n/**\n * The possible payload that will be sent to the client when a secure channel event occurs.\n */\nexport type SecureChannelEventPayload = {\n PreExchange: { nonce: number; apdu: Uint8Array };\n Exchange: {\n nonce: number;\n apdu: Uint8Array;\n data: Uint8Array;\n status: Uint8Array;\n };\n Progress: { progress: number; index: number; total: number };\n Warning: { message: string };\n Result: unknown;\n};\n\n/**\n * The event type that will be emitted to the client when a secure channel event occurs.\n */\nexport type SecureChannelEvent =\n | {\n type: SecureChannelEventType.Opened;\n }\n | {\n type: SecureChannelEventType.Closed;\n }\n | {\n type: SecureChannelEventType.PermissionRequested;\n }\n | {\n type: SecureChannelEventType.PermissionGranted;\n }\n | {\n type: SecureChannelEventType.PreExchange;\n payload: SecureChannelEventPayload[\"PreExchange\"];\n }\n | {\n type: SecureChannelEventType.Exchange;\n payload: SecureChannelEventPayload[\"Exchange\"];\n }\n | {\n type: SecureChannelEventType.Progress;\n payload: SecureChannelEventPayload[\"Progress\"];\n }\n | {\n type: SecureChannelEventType.Warning;\n payload: SecureChannelEventPayload[\"Warning\"];\n }\n | {\n type: SecureChannelEventType.Result;\n payload: SecureChannelEventPayload[\"Result\"];\n };\n"],
5
- "mappings": "AAAO,IAAKA,OACVA,EAAA,aAAe,eACfA,EAAA,kBAAoB,oBACpBA,EAAA,UAAY,YACZA,EAAA,eAAiB,iBACjBA,EAAA,WAAa,aACbA,EAAA,aAAe,eANLA,OAAA,IAqBAC,OACVA,EAAA,SAAW,WACXA,EAAA,KAAO,OACPA,EAAA,MAAQ,QACRA,EAAA,QAAU,UACVA,EAAA,QAAU,UALAA,OAAA,IAiBAC,OACVA,EAAA,QAAU,UACVA,EAAA,MAAQ,QAFEA,OAAA,IASAC,OACVA,EAAA,OAAS,SACTA,EAAA,OAAS,SACTA,EAAA,oBAAsB,uBACtBA,EAAA,kBAAoB,qBACpBA,EAAA,YAAc,eACdA,EAAA,SAAW,WACXA,EAAA,SAAW,WACXA,EAAA,QAAU,UACVA,EAAA,OAAS,SATCA,OAAA",
4
+ "sourcesContent": ["import { type SecureChannelError } from \"@internal/secure-channel/model/Errors\";\n\nexport enum SecureChannelOperationEnum {\n GenuineCheck = \"GenuineCheck\",\n ListInstalledApps = \"ListInstalledApps\",\n UpdateMcu = \"UpdateMcu\",\n UpdateFirmware = \"UpdateFirmware\",\n InstallApp = \"InstallApp\",\n UninstallApp = \"UninstallApp\",\n}\n\n/**\n * The message that will be received from the server by the secure channel.\n */\nexport type InMessageType = {\n uuid: string;\n session: string;\n query: InMessageQueryEnum;\n nonce: number;\n data: unknown;\n result?: unknown;\n};\n\nexport enum InMessageQueryEnum {\n EXCHANGE = \"exchange\",\n BULK = \"bulk\",\n ERROR = \"error\",\n WARNING = \"warning\",\n SUCCESS = \"success\",\n}\n\n/**\n * The message that will be sent to the server by the secure channel.\n */\nexport type OutMessageType = {\n nonce: number;\n response: OutMessageResponseEnum;\n data: string;\n};\n\nexport enum OutMessageResponseEnum {\n SUCCESS = \"success\",\n ERROR = \"error\",\n}\n\n/**\n * The all event types that can be emitted to the client by the secure channel.\n *\n */\nexport enum SecureChannelEventType {\n Opened = \"opened\",\n Closed = \"closed\",\n PermissionRequested = \"permission-requested\",\n PermissionGranted = \"permission-granted\",\n PreExchange = \"pre-exchange\",\n Exchange = \"exchange\",\n Progress = \"progress\",\n Warning = \"warning\",\n Error = \"error\",\n Result = \"result\",\n}\n\n/**\n * The possible payload that will be sent to the client when a secure channel event occurs.\n */\nexport type SecureChannelEventPayload = {\n PreExchange: { nonce: number; apdu: Uint8Array };\n Exchange: {\n nonce: number;\n apdu: Uint8Array;\n data: Uint8Array;\n status: Uint8Array;\n };\n Progress: { progress: number; index: number; total: number };\n Warning: { message: string };\n Result: unknown;\n};\n\n/**\n * The event type that will be emitted to the client when a secure channel event occurs.\n */\nexport type SecureChannelEvent =\n | {\n type: SecureChannelEventType.Opened;\n }\n | {\n type: SecureChannelEventType.Closed;\n }\n | {\n type: SecureChannelEventType.PermissionRequested;\n }\n | {\n type: SecureChannelEventType.PermissionGranted;\n }\n | {\n type: SecureChannelEventType.PreExchange;\n payload: SecureChannelEventPayload[\"PreExchange\"];\n }\n | {\n type: SecureChannelEventType.Exchange;\n payload: SecureChannelEventPayload[\"Exchange\"];\n }\n | {\n type: SecureChannelEventType.Progress;\n payload: SecureChannelEventPayload[\"Progress\"];\n }\n | {\n type: SecureChannelEventType.Warning;\n payload: SecureChannelEventPayload[\"Warning\"];\n }\n | {\n type: SecureChannelEventType.Error;\n error: SecureChannelError;\n }\n | {\n type: SecureChannelEventType.Result;\n payload: SecureChannelEventPayload[\"Result\"];\n };\n"],
5
+ "mappings": "AAEO,IAAKA,OACVA,EAAA,aAAe,eACfA,EAAA,kBAAoB,oBACpBA,EAAA,UAAY,YACZA,EAAA,eAAiB,iBACjBA,EAAA,WAAa,aACbA,EAAA,aAAe,eANLA,OAAA,IAqBAC,OACVA,EAAA,SAAW,WACXA,EAAA,KAAO,OACPA,EAAA,MAAQ,QACRA,EAAA,QAAU,UACVA,EAAA,QAAU,UALAA,OAAA,IAiBAC,OACVA,EAAA,QAAU,UACVA,EAAA,MAAQ,QAFEA,OAAA,IASAC,OACVA,EAAA,OAAS,SACTA,EAAA,OAAS,SACTA,EAAA,oBAAsB,uBACtBA,EAAA,kBAAoB,qBACpBA,EAAA,YAAc,eACdA,EAAA,SAAW,WACXA,EAAA,SAAW,WACXA,EAAA,QAAU,UACVA,EAAA,MAAQ,QACRA,EAAA,OAAS,SAVCA,OAAA",
6
6
  "names": ["SecureChannelOperationEnum", "InMessageQueryEnum", "OutMessageResponseEnum", "SecureChannelEventType"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{GENUINE_DEVICE_RESULT as n}from"./constants";function i(e){return e[0]===224&&e[1]===81}function o(e){return e.length===2&&(e[0]===85&&e[1]===1||e[0]===105&&e[1]===133)}function t(e){return e===n}export{t as isDeviceGenuine,o as isRefusedByUser,i as willRequestPermission};
1
+ import{GENUINE_DEVICE_RESULT as n}from"./constants";function t(e){return e[0]===224&&e[1]===81}function o(e){return e===n}export{o as isDeviceGenuine,t as willRequestPermission};
2
2
  //# sourceMappingURL=utils.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/api/secure-channel/utils.ts"],
4
- "sourcesContent": ["import { type SecureChannelEventPayload } from \"./task/types\";\nimport { GENUINE_DEVICE_RESULT } from \"./constants\";\n\n/**\n * Checks if the given APDU command will request permission.\n *\n * This method checks if the first byte of the APDU command is `0xe0` and the second byte is `0x51`.\n *\n * @param apdu - The APDU command as a Uint8Array.\n * @returns `true` if the APDU command will request permission, otherwise `false`.\n */\nexport function willRequestPermission(apdu: Uint8Array): boolean {\n return apdu[0] === 0xe0 && apdu[1] === 0x51;\n}\n\n/**\n * Checks if the user refused the permission on the device.\n *\n * The following status codes indicate a refusal:\n * - \"0x5501\": User refused the permission.\n * - \"0x6985\": Condition of use not satisfied.\n *\n * @param statusCode - The status code to check.\n * @returns `true` if the status code indicates a refusal, otherwise `false`.\n */\nexport function isRefusedByUser(statusCode: Uint8Array): boolean {\n return (\n statusCode.length === 2 &&\n ((statusCode[0] === 0x55 && statusCode[1] === 0x01) ||\n (statusCode[0] === 0x69 && statusCode[1] === 0x85))\n );\n}\n\n/**\n * Checks if the device is genuine.\n *\n * @param payload - The payload of the result secure channel event.\n * The payload has already been stringified, so that the type check is not necessary.\n * @returns `true` if the device is genuine, otherwise `false`.\n */\nexport function isDeviceGenuine(payload: SecureChannelEventPayload[\"Result\"]) {\n return payload === GENUINE_DEVICE_RESULT;\n}\n"],
5
- "mappings": "AACA,OAAS,yBAAAA,MAA6B,cAU/B,SAASC,EAAsBC,EAA2B,CAC/D,OAAOA,EAAK,CAAC,IAAM,KAAQA,EAAK,CAAC,IAAM,EACzC,CAYO,SAASC,EAAgBC,EAAiC,CAC/D,OACEA,EAAW,SAAW,IACpBA,EAAW,CAAC,IAAM,IAAQA,EAAW,CAAC,IAAM,GAC3CA,EAAW,CAAC,IAAM,KAAQA,EAAW,CAAC,IAAM,IAEnD,CASO,SAASC,EAAgBC,EAA8C,CAC5E,OAAOA,IAAYN,CACrB",
6
- "names": ["GENUINE_DEVICE_RESULT", "willRequestPermission", "apdu", "isRefusedByUser", "statusCode", "isDeviceGenuine", "payload"]
4
+ "sourcesContent": ["import { type SecureChannelEventPayload } from \"./task/types\";\nimport { GENUINE_DEVICE_RESULT } from \"./constants\";\n\n/**\n * Checks if the given APDU command will request permission.\n *\n * This method checks if the first byte of the APDU command is `0xe0` and the second byte is `0x51`.\n *\n * @param apdu - The APDU command as a Uint8Array.\n * @returns `true` if the APDU command will request permission, otherwise `false`.\n */\nexport function willRequestPermission(apdu: Uint8Array): boolean {\n return apdu[0] === 0xe0 && apdu[1] === 0x51;\n}\n\n/**\n * Checks if the device is genuine.\n *\n * @param payload - The payload of the result secure channel event.\n * The payload has already been stringified, so that the type check is not necessary.\n * @returns `true` if the device is genuine, otherwise `false`.\n */\nexport function isDeviceGenuine(payload: SecureChannelEventPayload[\"Result\"]) {\n return payload === GENUINE_DEVICE_RESULT;\n}\n"],
5
+ "mappings": "AACA,OAAS,yBAAAA,MAA6B,cAU/B,SAASC,EAAsBC,EAA2B,CAC/D,OAAOA,EAAK,CAAC,IAAM,KAAQA,EAAK,CAAC,IAAM,EACzC,CASO,SAASC,EAAgBC,EAA8C,CAC5E,OAAOA,IAAYJ,CACrB",
6
+ "names": ["GENUINE_DEVICE_RESULT", "willRequestPermission", "apdu", "isDeviceGenuine", "payload"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{isDeviceGenuine as t,isRefusedByUser as s,willRequestPermission as i}from"./utils";describe("willRequestPermission",()=>{it("should return true if the APDU is a permission request",()=>{const e=new Uint8Array([224,81,0,0,0]);expect(i(e)).toBe(!0)}),it("should return false if the APDU is not a permission request",()=>{const e=new Uint8Array([224,82,0,0,0]);expect(i(e)).toBe(!1)})});describe("isRefusedByUser",()=>{it("should return true if the status code indicates a refusal",()=>{[new Uint8Array([85,1]),new Uint8Array([105,133])].forEach(e=>{expect(s(e)).toBe(!0)})}),it("should return false if the status code does not indicate a refusal",()=>{const e=new Uint8Array([144,0]);expect(s(e)).toBe(!1)})});describe("isDeviceGenuine",()=>{it("should return true if the device is genuine",()=>{expect(t("0000")).toBe(!0)}),it("should return false if the device is not genuine",()=>{expect(t("not genuine")).toBe(!1)})});
1
+ import{isDeviceGenuine as i,willRequestPermission as t}from"./utils";describe("willRequestPermission",()=>{it("should return true if the APDU is a permission request",()=>{const e=new Uint8Array([224,81,0,0,0]);expect(t(e)).toBe(!0)}),it("should return false if the APDU is not a permission request",()=>{const e=new Uint8Array([224,82,0,0,0]);expect(t(e)).toBe(!1)})});describe("isDeviceGenuine",()=>{it("should return true if the device is genuine",()=>{expect(i("0000")).toBe(!0)}),it("should return false if the device is not genuine",()=>{expect(i("not genuine")).toBe(!1)})});
2
2
  //# sourceMappingURL=utils.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/api/secure-channel/utils.test.ts"],
4
- "sourcesContent": ["import {\n isDeviceGenuine,\n isRefusedByUser,\n willRequestPermission,\n} from \"./utils\";\n\ndescribe(\"willRequestPermission\", () => {\n it(\"should return true if the APDU is a permission request\", () => {\n const apdu = new Uint8Array([0xe0, 0x51, 0x00, 0x00, 0x00]);\n expect(willRequestPermission(apdu)).toBe(true);\n });\n it(\"should return false if the APDU is not a permission request\", () => {\n const apdu = new Uint8Array([0xe0, 0x52, 0x00, 0x00, 0x00]);\n expect(willRequestPermission(apdu)).toBe(false);\n });\n});\n\ndescribe(\"isRefusedByUser\", () => {\n it(\"should return true if the status code indicates a refusal\", () => {\n [new Uint8Array([0x55, 0x01]), new Uint8Array([0x69, 0x85])].forEach(\n (statusCode) => {\n expect(isRefusedByUser(statusCode)).toBe(true);\n },\n );\n });\n it(\"should return false if the status code does not indicate a refusal\", () => {\n const statusCode = new Uint8Array([0x90, 0x00]);\n expect(isRefusedByUser(statusCode)).toBe(false);\n });\n});\n\ndescribe(\"isDeviceGenuine\", () => {\n it(\"should return true if the device is genuine\", () => {\n const payload = \"0000\";\n expect(isDeviceGenuine(payload)).toBe(true);\n });\n it(\"should return false if the device is not genuine\", () => {\n const payload = \"not genuine\";\n expect(isDeviceGenuine(payload)).toBe(false);\n });\n});\n"],
5
- "mappings": "AAAA,OACE,mBAAAA,EACA,mBAAAC,EACA,yBAAAC,MACK,UAEP,SAAS,wBAAyB,IAAM,CACtC,GAAG,yDAA0D,IAAM,CACjE,MAAMC,EAAO,IAAI,WAAW,CAAC,IAAM,GAAM,EAAM,EAAM,CAAI,CAAC,EAC1D,OAAOD,EAAsBC,CAAI,CAAC,EAAE,KAAK,EAAI,CAC/C,CAAC,EACD,GAAG,8DAA+D,IAAM,CACtE,MAAMA,EAAO,IAAI,WAAW,CAAC,IAAM,GAAM,EAAM,EAAM,CAAI,CAAC,EAC1D,OAAOD,EAAsBC,CAAI,CAAC,EAAE,KAAK,EAAK,CAChD,CAAC,CACH,CAAC,EAED,SAAS,kBAAmB,IAAM,CAChC,GAAG,4DAA6D,IAAM,CACpE,CAAC,IAAI,WAAW,CAAC,GAAM,CAAI,CAAC,EAAG,IAAI,WAAW,CAAC,IAAM,GAAI,CAAC,CAAC,EAAE,QAC1DC,GAAe,CACd,OAAOH,EAAgBG,CAAU,CAAC,EAAE,KAAK,EAAI,CAC/C,CACF,CACF,CAAC,EACD,GAAG,qEAAsE,IAAM,CAC7E,MAAMA,EAAa,IAAI,WAAW,CAAC,IAAM,CAAI,CAAC,EAC9C,OAAOH,EAAgBG,CAAU,CAAC,EAAE,KAAK,EAAK,CAChD,CAAC,CACH,CAAC,EAED,SAAS,kBAAmB,IAAM,CAChC,GAAG,8CAA+C,IAAM,CAEtD,OAAOJ,EADS,MACc,CAAC,EAAE,KAAK,EAAI,CAC5C,CAAC,EACD,GAAG,mDAAoD,IAAM,CAE3D,OAAOA,EADS,aACc,CAAC,EAAE,KAAK,EAAK,CAC7C,CAAC,CACH,CAAC",
6
- "names": ["isDeviceGenuine", "isRefusedByUser", "willRequestPermission", "apdu", "statusCode"]
4
+ "sourcesContent": ["import { isDeviceGenuine, willRequestPermission } from \"./utils\";\n\ndescribe(\"willRequestPermission\", () => {\n it(\"should return true if the APDU is a permission request\", () => {\n const apdu = new Uint8Array([0xe0, 0x51, 0x00, 0x00, 0x00]);\n expect(willRequestPermission(apdu)).toBe(true);\n });\n it(\"should return false if the APDU is not a permission request\", () => {\n const apdu = new Uint8Array([0xe0, 0x52, 0x00, 0x00, 0x00]);\n expect(willRequestPermission(apdu)).toBe(false);\n });\n});\n\ndescribe(\"isDeviceGenuine\", () => {\n it(\"should return true if the device is genuine\", () => {\n const payload = \"0000\";\n expect(isDeviceGenuine(payload)).toBe(true);\n });\n it(\"should return false if the device is not genuine\", () => {\n const payload = \"not genuine\";\n expect(isDeviceGenuine(payload)).toBe(false);\n });\n});\n"],
5
+ "mappings": "AAAA,OAAS,mBAAAA,EAAiB,yBAAAC,MAA6B,UAEvD,SAAS,wBAAyB,IAAM,CACtC,GAAG,yDAA0D,IAAM,CACjE,MAAMC,EAAO,IAAI,WAAW,CAAC,IAAM,GAAM,EAAM,EAAM,CAAI,CAAC,EAC1D,OAAOD,EAAsBC,CAAI,CAAC,EAAE,KAAK,EAAI,CAC/C,CAAC,EACD,GAAG,8DAA+D,IAAM,CACtE,MAAMA,EAAO,IAAI,WAAW,CAAC,IAAM,GAAM,EAAM,EAAM,CAAI,CAAC,EAC1D,OAAOD,EAAsBC,CAAI,CAAC,EAAE,KAAK,EAAK,CAChD,CAAC,CACH,CAAC,EAED,SAAS,kBAAmB,IAAM,CAChC,GAAG,8CAA+C,IAAM,CAEtD,OAAOF,EADS,MACc,CAAC,EAAE,KAAK,EAAI,CAC5C,CAAC,EACD,GAAG,mDAAoD,IAAM,CAE3D,OAAOA,EADS,aACc,CAAC,EAAE,KAAK,EAAK,CAC7C,CAAC,CACH,CAAC",
6
+ "names": ["isDeviceGenuine", "willRequestPermission", "apdu"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{Left as r,Maybe as u,Nothing as m,Right as l}from"purify-ts";import{assign as d,createActor as D,emit as C,setup as v}from"xstate";import{CommandUtils as A}from"../../command/utils/CommandUtils";import{UnknownDeviceExchangeError as y}from"../../Error";import{AlreadySendingApduError as g,DeviceDisconnectedBeforeSendingApdu as R,DeviceDisconnectedWhileSendingError as p}from"./Errors";class x{deviceId;deviceAdpuSender;machineActor;timeoutDuration;timeout=null;startReconnectionTimeout(){this.timeout=setTimeout(()=>{this.machineActor.send({type:"ReconnectionTimedOut"})},this.timeoutDuration)}constructor(n){this.deviceId=n.deviceId,this.deviceAdpuSender=n.deviceApduSender,this.timeoutDuration=n.timeoutDuration,this.machineActor=D(T({sendApduFn:(o,i,t)=>this.sendApduToDeviceConnection(o,i,t),startReconnectionTimeout:()=>this.startReconnectionTimeout(),cancelReconnectionTimeout:()=>{this.timeout&&(clearTimeout(this.timeout),this.timeout=null)},onTerminated:n.onTerminated,closeConnection:()=>{this.deviceAdpuSender.closeConnection()}})),this.machineActor.start()}sendApduToDeviceConnection(n,o,i){this.deviceAdpuSender.sendApdu(n,o,i).then(t=>{t.caseOf({Left:e=>{this.machineActor.send({type:"ApduSendingError",error:e})},Right:e=>{this.machineActor.send({type:"ApduResponseReceived",apduResponse:e})}})}).catch(t=>{this.machineActor.send({type:"ApduSendingError",error:new y(t)})})}getDependencies(){return this.deviceAdpuSender.getDependencies()}setDependencies(n){this.deviceAdpuSender.setDependencies(n)}getDeviceId(){return this.deviceId}sendApdu(n,o,i){return new Promise(t=>{this.machineActor.send({type:"SendApduCalled",apdu:n,triggersDisconnection:!!o,abortTimeout:i,responseCallback:t})})}async setupConnection(){await this.deviceAdpuSender.setupConnection()}eventDeviceAttached(){this.machineActor.send({type:"DeviceAttached"})}eventDeviceDetached(){this.machineActor.send({type:"DeviceDetached"})}closeConnection(){this.machineActor.send({type:"CloseConnectionCalled"})}}function T({sendApduFn:a,startReconnectionTimeout:n,cancelReconnectionTimeout:o,onTerminated:i,closeConnection:t}){return v({types:{},actions:{startTimer:()=>{n()},cancelTimer:()=>{o()},reconnectionTimeoutEvent:C({type:"ReconnectionTimedOut"}),sendApdu:({context:e})=>{e.apduInProgress.map(({apdu:s,abortTimeout:c})=>{a(s,!1,c)})},sendApduResponse:({context:e},s)=>{e.apduInProgress.map(({responseCallback:c})=>c(s.response))},cleanupContext:d({apduInProgress:m}),signalTermination:()=>{i()},closeConnection:()=>{t()}},guards:{isApduThatTriggersDisconnection:({context:e},s)=>e.apduInProgress.caseOf({Just:({triggersDisconnection:c,apdu:h})=>(c||A.isApduThatTriggersDisconnection(h))&&A.isSuccessResponse(s.apduResponse),Nothing:()=>!1})}}).createMachine({id:"deviceConnection",initial:"Connected",context:{apduInProgress:m},states:{Connected:{on:{DeviceDetached:{target:"WaitingForReconnection"},SendApduCalled:{target:"SendingApdu",actions:d({apduInProgress:({event:e})=>u.of({apdu:e.apdu,triggersDisconnection:e.triggersDisconnection,abortTimeout:e.abortTimeout,responseCallback:e.responseCallback})})},CloseConnectionCalled:{target:"Terminated"}}},SendingApdu:{entry:"sendApdu",on:{ApduResponseReceived:[{guard:{type:"isApduThatTriggersDisconnection",params:({event:e})=>({apduResponse:e.apduResponse})},target:"WaitingForReconnection",actions:[{type:"sendApduResponse",params:({event:e})=>({response:l(e.apduResponse)})},{type:"cleanupContext"}]},{target:"Connected",actions:[{type:"sendApduResponse",params:({event:e})=>({response:l(e.apduResponse)})},{type:"cleanupContext"}]}],ApduSendingError:{target:"Connected",actions:[{type:"sendApduResponse",params:({event:e})=>({response:r(e.error)})},"cleanupContext"]},DeviceDetached:{target:"WaitingForReconnection",actions:[{type:"sendApduResponse",params:{response:r(new p)}},"cleanupContext"]},CloseConnectionCalled:{target:"Terminated",actions:[{type:"sendApduResponse",params:{response:r(new p)}},"cleanupContext"]},SendApduCalled:{actions:({event:e})=>{e.responseCallback(r(new g))}}}},WaitingForReconnection:{entry:"startTimer",on:{DeviceAttached:{target:"Connected",actions:"cancelTimer"},SendApduCalled:{target:"WaitingForReconnectionWithQueuedSendApdu",actions:d({apduInProgress:({event:e})=>u.of({apdu:e.apdu,triggersDisconnection:e.triggersDisconnection,abortTimeout:e.abortTimeout,responseCallback:e.responseCallback})})},ReconnectionTimedOut:{target:"Terminated"},CloseConnectionCalled:{target:"Terminated"}}},WaitingForReconnectionWithQueuedSendApdu:{on:{DeviceAttached:{target:"SendingApdu",actions:"cancelTimer"},ReconnectionTimedOut:{target:"Terminated",actions:[{type:"sendApduResponse",params:{response:r(new R)}},{type:"cleanupContext"}]},CloseConnectionCalled:{target:"Terminated",actions:[{type:"sendApduResponse",params:{response:r(new p)}},"cleanupContext"]},SendApduCalled:{actions:({event:e})=>{e.responseCallback(r(new g))}}}},Terminated:{entry:["signalTermination","closeConnection"],type:"final"}}})}export{x as DeviceConnectionStateMachine};
1
+ import{Left as o,Maybe as l,Nothing as a,Right as g}from"purify-ts";import{assign as p,createActor as y,emit as v,setup as h}from"xstate";import{GetAppAndVersionCommand as T}from"../../command/os/GetAppAndVersionCommand";import{CommandUtils as D}from"../../command/utils/CommandUtils";import{UnknownDeviceExchangeError as C}from"../../Error";import{AlreadySendingApduError as m,DeviceDisconnectedBeforeSendingApdu as S,DeviceDisconnectedWhileSendingError as A}from"./Errors";class W{deviceId;deviceAdpuSender;machineActor;timeoutDuration;timeout=null;startReconnectionTimeout(){this.timeout=setTimeout(()=>{this.machineActor.send({type:"ReconnectionTimedOut"})},this.timeoutDuration)}constructor(n){this.deviceId=n.deviceId,this.deviceAdpuSender=n.deviceApduSender,this.timeoutDuration=n.timeoutDuration,this.machineActor=y(b({sendApduFn:(r,s,t)=>this.sendApduToDeviceConnection(r,s,t),startReconnectionTimeout:()=>this.startReconnectionTimeout(),cancelReconnectionTimeout:()=>{this.timeout&&(clearTimeout(this.timeout),this.timeout=null)},tryToReconnect:()=>{n.tryToReconnect(this.timeoutDuration)},onTerminated:n.onTerminated,closeConnection:()=>{this.deviceAdpuSender.closeConnection()}})),this.machineActor.start()}sendApduToDeviceConnection(n,r,s){this.deviceAdpuSender.sendApdu(n,r,s).then(t=>{t.caseOf({Left:c=>{this.machineActor.send({type:"ApduSendingError",error:c})},Right:c=>{this.machineActor.send({type:"ApduResponseReceived",apduResponse:c})}})}).catch(t=>{this.machineActor.send({type:"ApduSendingError",error:new C(t)})})}getDependencies(){return this.deviceAdpuSender.getDependencies()}setDependencies(n){this.deviceAdpuSender.setDependencies(n)}getDeviceId(){return this.deviceId}sendApdu(n,r,s){return new Promise(t=>{this.machineActor.send({type:"SendApduCalled",apdu:n,triggersDisconnection:!!r,abortTimeout:s,responseCallback:t})})}async setupConnection(){await this.deviceAdpuSender.setupConnection()}eventDeviceConnected(){this.machineActor.send({type:"DeviceConnected"})}eventDeviceDisconnected(){this.machineActor.send({type:"DeviceDisconnected"})}closeConnection(){this.machineActor.send({type:"CloseConnectionCalled"})}}function b({sendApduFn:u,startReconnectionTimeout:n,cancelReconnectionTimeout:r,tryToReconnect:s,onTerminated:t,closeConnection:c}){return h({types:{},actions:{startTimer:()=>{n()},cancelTimer:()=>{r()},reconnectionTimeoutEvent:v({type:"ReconnectionTimedOut"}),sendApdu:({context:e})=>{e.apduInProgress.map(({apdu:i,abortTimeout:d})=>{u(i,!1,d)})},sendApduResponse:({context:e},i)=>{e.apduInProgress.map(({responseCallback:d})=>d(i.response))},sendGetAppAndVersion:()=>{u(new T().getApdu().getRawApdu(),!1)},tryToReconnect:()=>{s()},clearApduInProgress:p({apduInProgress:a}),clearApduResponse:p({apduResponse:a}),signalTermination:()=>{t()},closeConnection:()=>{c()}},guards:{isApduThatTriggersDisconnection:({context:e,event:i})=>i.type!=="ApduResponseReceived"?!1:e.apduInProgress.caseOf({Just:({triggersDisconnection:d,apdu:R})=>(d||D.isApduThatTriggersDisconnection(R))&&D.isSuccessResponse(i.apduResponse),Nothing:()=>!1}),isSendApduBusyError:({event:e})=>e.type!=="ApduResponseReceived"?!1:e.apduResponse.statusCode[0]===102&&e.apduResponse.statusCode[1]===1}}).createMachine({id:"deviceConnection",initial:"Connected",context:{apduInProgress:a,apduResponse:a},states:{Connected:{on:{DeviceDisconnected:{target:"WaitingForReconnection"},SendApduCalled:{target:"SendingApdu",actions:p({apduInProgress:({event:e})=>l.of({apdu:e.apdu,triggersDisconnection:e.triggersDisconnection,abortTimeout:e.abortTimeout,responseCallback:e.responseCallback})})},CloseConnectionCalled:{target:"Terminated"}}},SendingApdu:{entry:"sendApdu",on:{ApduResponseReceived:[{guard:"isApduThatTriggersDisconnection",target:"WaitingForDisconnection",actions:[p({apduResponse:({event:e})=>l.of(e.apduResponse)})]},{target:"Connected",actions:[{type:"sendApduResponse",params:({event:e})=>({response:g(e.apduResponse)})},{type:"clearApduInProgress"}]}],ApduSendingError:{target:"Connected",actions:[{type:"sendApduResponse",params:({event:e})=>({response:o(e.error)})},"clearApduInProgress"]},DeviceDisconnected:{target:"WaitingForReconnection",actions:[{type:"sendApduResponse",params:{response:o(new A)}},"clearApduInProgress"]},CloseConnectionCalled:{target:"Terminated",actions:[{type:"sendApduResponse",params:{response:o(new A)}},"clearApduInProgress"]},SendApduCalled:{actions:({event:e})=>{e.responseCallback(o(new m))}}}},WaitingForDisconnection:{entry:["sendGetAppAndVersion"],exit:[{type:"sendApduResponse",params:({context:e})=>({response:e.apduResponse.caseOf({Just:i=>g(i),Nothing:()=>o(new C)})})},{type:"clearApduInProgress"},{type:"clearApduResponse"}],on:{ApduResponseReceived:[{guard:"isSendApduBusyError",actions:["sendGetAppAndVersion"],target:"WaitingForDisconnection"},{target:"Connected"}],ApduSendingError:[{target:"WaitingForReconnection"}],SendApduCalled:{actions:({event:e})=>{e.responseCallback(o(new m))}},DeviceDisconnected:{target:"WaitingForReconnection"},CloseConnectionCalled:{target:"Terminated"}}},WaitingForReconnection:{entry:["startTimer","tryToReconnect"],on:{DeviceConnected:{target:"Connected",actions:"cancelTimer"},SendApduCalled:{target:"WaitingForReconnectionWithQueuedSendApdu",actions:p({apduInProgress:({event:e})=>l.of({apdu:e.apdu,triggersDisconnection:e.triggersDisconnection,abortTimeout:e.abortTimeout,responseCallback:e.responseCallback})})},ReconnectionTimedOut:{target:"Terminated"},CloseConnectionCalled:{target:"Terminated"}}},WaitingForReconnectionWithQueuedSendApdu:{on:{DeviceConnected:{target:"SendingApdu",actions:"cancelTimer"},ReconnectionTimedOut:{target:"Terminated",actions:[{type:"sendApduResponse",params:{response:o(new S)}},{type:"clearApduInProgress"}]},CloseConnectionCalled:{target:"Terminated",actions:[{type:"sendApduResponse",params:{response:o(new A)}},"clearApduInProgress"]},SendApduCalled:{actions:({event:e})=>{e.responseCallback(o(new m))}}}},Terminated:{entry:["signalTermination","closeConnection"],type:"final"}}})}export{W as DeviceConnectionStateMachine};
2
2
  //# sourceMappingURL=DeviceConnectionStateMachine.js.map