@ledgerhq/device-management-kit 0.11.1 → 0.12.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 (127) hide show
  1. package/lib/cjs/package.json +45 -40
  2. package/lib/cjs/src/api/device-action/os/Errors.js +1 -1
  3. package/lib/cjs/src/api/device-action/os/Errors.js.map +3 -3
  4. package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js +1 -1
  5. package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js.map +2 -2
  6. package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/types.js +1 -1
  7. package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/types.js.map +1 -1
  8. package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js +1 -1
  9. package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js.map +2 -2
  10. package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/types.js +1 -1
  11. package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/types.js.map +1 -1
  12. package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.js +1 -1
  13. package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.js.map +2 -2
  14. package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/types.js +1 -1
  15. package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/types.js.map +1 -1
  16. package/lib/cjs/src/api/device-action/task/BuildAppsInstallPlanTask.js +1 -1
  17. package/lib/cjs/src/api/device-action/task/BuildAppsInstallPlanTask.js.map +2 -2
  18. package/lib/cjs/src/api/device-action/task/BuildAppsInstallPlanTask.test.js +1 -1
  19. package/lib/cjs/src/api/device-action/task/BuildAppsInstallPlanTask.test.js.map +2 -2
  20. package/lib/cjs/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.js +1 -1
  21. package/lib/cjs/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.js.map +2 -2
  22. package/lib/cjs/src/api/secure-channel/device-action/GenuineCheck/types.js.map +1 -1
  23. package/lib/cjs/src/api/secure-channel/device-action/InstallApp/InstallAppDeviceAction.js +1 -1
  24. package/lib/cjs/src/api/secure-channel/device-action/InstallApp/InstallAppDeviceAction.js.map +2 -2
  25. package/lib/cjs/src/api/secure-channel/device-action/InstallApp/types.js.map +1 -1
  26. package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js +1 -1
  27. package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js.map +2 -2
  28. package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/types.js +1 -1
  29. package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/types.js.map +2 -2
  30. package/lib/cjs/src/api/secure-channel/device-action/UninstallApp/UninstallAppDeviceAction.js +1 -1
  31. package/lib/cjs/src/api/secure-channel/device-action/UninstallApp/UninstallAppDeviceAction.js.map +2 -2
  32. package/lib/cjs/src/api/secure-channel/device-action/UninstallApp/types.js.map +1 -1
  33. package/lib/cjs/src/api/secure-channel/task/ConnectToSecureChannelTask.js +1 -1
  34. package/lib/cjs/src/api/secure-channel/task/ConnectToSecureChannelTask.js.map +3 -3
  35. package/lib/cjs/src/api/secure-channel/task/ConnectToSecureChannelTask.test.js +1 -1
  36. package/lib/cjs/src/api/secure-channel/task/ConnectToSecureChannelTask.test.js.map +3 -3
  37. package/lib/cjs/src/api/secure-channel/task/types.js +1 -1
  38. package/lib/cjs/src/api/secure-channel/task/types.js.map +2 -2
  39. package/lib/cjs/src/api/secure-channel/utils.js +1 -1
  40. package/lib/cjs/src/api/secure-channel/utils.js.map +3 -3
  41. package/lib/cjs/src/api/secure-channel/utils.test.js +1 -1
  42. package/lib/cjs/src/api/secure-channel/utils.test.js.map +3 -3
  43. package/lib/cjs/src/internal/crypto/CryptoService.js +2 -0
  44. package/lib/cjs/src/internal/crypto/CryptoService.js.map +7 -0
  45. package/lib/cjs/src/internal/crypto/NobleCryptoService.js +2 -0
  46. package/lib/cjs/src/internal/crypto/NobleCryptoService.js.map +7 -0
  47. package/lib/cjs/src/internal/crypto/NobleCryptoService.test.js +2 -0
  48. package/lib/cjs/src/internal/crypto/NobleCryptoService.test.js.map +7 -0
  49. package/lib/cjs/src/internal/manager-api/data/ManagerApiDataSource.js.map +1 -1
  50. package/lib/esm/package.json +45 -40
  51. package/lib/esm/src/api/device-action/os/Errors.js +1 -1
  52. package/lib/esm/src/api/device-action/os/Errors.js.map +3 -3
  53. package/lib/esm/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js +1 -1
  54. package/lib/esm/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js.map +2 -2
  55. package/lib/esm/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js +1 -1
  56. package/lib/esm/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js.map +2 -2
  57. package/lib/esm/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.js +1 -1
  58. package/lib/esm/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.js.map +2 -2
  59. package/lib/esm/src/api/device-action/task/BuildAppsInstallPlanTask.js +1 -1
  60. package/lib/esm/src/api/device-action/task/BuildAppsInstallPlanTask.js.map +3 -3
  61. package/lib/esm/src/api/device-action/task/BuildAppsInstallPlanTask.test.js +1 -1
  62. package/lib/esm/src/api/device-action/task/BuildAppsInstallPlanTask.test.js.map +3 -3
  63. package/lib/esm/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.js +1 -1
  64. package/lib/esm/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.js.map +2 -2
  65. package/lib/esm/src/api/secure-channel/device-action/InstallApp/InstallAppDeviceAction.js +1 -1
  66. package/lib/esm/src/api/secure-channel/device-action/InstallApp/InstallAppDeviceAction.js.map +2 -2
  67. package/lib/esm/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js +1 -1
  68. package/lib/esm/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js.map +2 -2
  69. package/lib/esm/src/api/secure-channel/device-action/ListInstalledApps/types.js.map +2 -2
  70. package/lib/esm/src/api/secure-channel/device-action/UninstallApp/UninstallAppDeviceAction.js +1 -1
  71. package/lib/esm/src/api/secure-channel/device-action/UninstallApp/UninstallAppDeviceAction.js.map +2 -2
  72. package/lib/esm/src/api/secure-channel/task/ConnectToSecureChannelTask.js +1 -1
  73. package/lib/esm/src/api/secure-channel/task/ConnectToSecureChannelTask.js.map +3 -3
  74. package/lib/esm/src/api/secure-channel/task/ConnectToSecureChannelTask.test.js +1 -1
  75. package/lib/esm/src/api/secure-channel/task/ConnectToSecureChannelTask.test.js.map +3 -3
  76. package/lib/esm/src/api/secure-channel/task/types.js +1 -1
  77. package/lib/esm/src/api/secure-channel/task/types.js.map +2 -2
  78. package/lib/esm/src/api/secure-channel/utils.js +1 -1
  79. package/lib/esm/src/api/secure-channel/utils.js.map +3 -3
  80. package/lib/esm/src/api/secure-channel/utils.test.js +1 -1
  81. package/lib/esm/src/api/secure-channel/utils.test.js.map +3 -3
  82. package/lib/esm/src/internal/crypto/CryptoService.js +1 -0
  83. package/lib/esm/src/internal/crypto/CryptoService.js.map +7 -0
  84. package/lib/esm/src/internal/crypto/NobleCryptoService.js +2 -0
  85. package/lib/esm/src/internal/crypto/NobleCryptoService.js.map +7 -0
  86. package/lib/esm/src/internal/crypto/NobleCryptoService.test.js +2 -0
  87. package/lib/esm/src/internal/crypto/NobleCryptoService.test.js.map +7 -0
  88. package/lib/types/src/api/device-action/os/Errors.d.ts +5 -0
  89. package/lib/types/src/api/device-action/os/Errors.d.ts.map +1 -1
  90. package/lib/types/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.d.ts.map +1 -1
  91. package/lib/types/src/api/device-action/os/GetDeviceMetadata/types.d.ts +1 -0
  92. package/lib/types/src/api/device-action/os/GetDeviceMetadata/types.d.ts.map +1 -1
  93. package/lib/types/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.d.ts.map +1 -1
  94. package/lib/types/src/api/device-action/os/InstallOrUpdateApps/types.d.ts +3 -2
  95. package/lib/types/src/api/device-action/os/InstallOrUpdateApps/types.d.ts.map +1 -1
  96. package/lib/types/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.d.ts.map +1 -1
  97. package/lib/types/src/api/device-action/os/OpenAppWithDependencies/types.d.ts +1 -0
  98. package/lib/types/src/api/device-action/os/OpenAppWithDependencies/types.d.ts.map +1 -1
  99. package/lib/types/src/api/device-action/task/BuildAppsInstallPlanTask.d.ts +2 -2
  100. package/lib/types/src/api/device-action/task/BuildAppsInstallPlanTask.d.ts.map +1 -1
  101. package/lib/types/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.d.ts.map +1 -1
  102. package/lib/types/src/api/secure-channel/device-action/GenuineCheck/types.d.ts +1 -0
  103. package/lib/types/src/api/secure-channel/device-action/GenuineCheck/types.d.ts.map +1 -1
  104. package/lib/types/src/api/secure-channel/device-action/InstallApp/InstallAppDeviceAction.d.ts.map +1 -1
  105. package/lib/types/src/api/secure-channel/device-action/InstallApp/types.d.ts +1 -0
  106. package/lib/types/src/api/secure-channel/device-action/InstallApp/types.d.ts.map +1 -1
  107. package/lib/types/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.d.ts.map +1 -1
  108. package/lib/types/src/api/secure-channel/device-action/ListInstalledApps/types.d.ts +1 -0
  109. package/lib/types/src/api/secure-channel/device-action/ListInstalledApps/types.d.ts.map +1 -1
  110. package/lib/types/src/api/secure-channel/device-action/UninstallApp/UninstallAppDeviceAction.d.ts.map +1 -1
  111. package/lib/types/src/api/secure-channel/device-action/UninstallApp/types.d.ts +1 -0
  112. package/lib/types/src/api/secure-channel/device-action/UninstallApp/types.d.ts.map +1 -1
  113. package/lib/types/src/api/secure-channel/task/ConnectToSecureChannelTask.d.ts +4 -0
  114. package/lib/types/src/api/secure-channel/task/ConnectToSecureChannelTask.d.ts.map +1 -1
  115. package/lib/types/src/api/secure-channel/task/types.d.ts +7 -0
  116. package/lib/types/src/api/secure-channel/task/types.d.ts.map +1 -1
  117. package/lib/types/src/api/secure-channel/utils.d.ts +18 -1
  118. package/lib/types/src/api/secure-channel/utils.d.ts.map +1 -1
  119. package/lib/types/src/internal/crypto/CryptoService.d.ts +12 -0
  120. package/lib/types/src/internal/crypto/CryptoService.d.ts.map +1 -0
  121. package/lib/types/src/internal/crypto/NobleCryptoService.d.ts +8 -0
  122. package/lib/types/src/internal/crypto/NobleCryptoService.d.ts.map +1 -0
  123. package/lib/types/src/internal/crypto/NobleCryptoService.test.d.ts +2 -0
  124. package/lib/types/src/internal/crypto/NobleCryptoService.test.d.ts.map +1 -0
  125. package/lib/types/src/internal/manager-api/data/ManagerApiDataSource.d.ts +1 -1
  126. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  127. package/package.json +34 -29
@@ -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+1GlA9qgHRlW0BKYWEAngGIA2gAYAuolCEmsSoxZSQAD0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-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 _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.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,sBAAAC,CACF,EAAI,KAAK,oBAAoBL,CAAW,EAElCM,EAAgB,KAAK,MAAM,eAAiBf,EAE5CgB,EAAuB,IAAId,EAA0B,CACzD,MAAO,CACL,cAAAa,CACF,CACF,CAAC,EAAE,iBAAiBN,CAAW,EAEzBQ,EAA2B,IAAIZ,EAA8B,CACjE,MAAO,CACL,cAAAU,CACF,CACF,CAAC,EAAE,iBAAiBN,CAAW,EAE/B,OAAOb,EAAM,CACX,MAAO,CACL,MAAO,CAAC,EACR,QAAS,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YD,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+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.DeviceId: {\n return {\n ..._.context.intermediateValue,\n deviceId: _.event.snapshot.context.payload.deviceId,\n };\n }\n case SecureChannelEventType.PermissionRequested: {\n return {\n ..._.context.intermediateValue,\n requiredUserInteraction:\n UserInteractionRequired.AllowSecureConnection,\n };\n }\n case SecureChannelEventType.PermissionGranted: {\n return {\n ..._.context.intermediateValue,\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.setDeviceSessionState(state),\n };\n }\n}\n"],
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,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",
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 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};
1
+ import I from"isomorphic-ws";import{Observable as T}from"rxjs";import{CommandUtils as h}from"../../command/utils/CommandUtils";import{InMessageQueryEnum as y,OutMessageResponseEnum as w,SecureChannelEventType as i}from"../../secure-channel/task/types";import{extractPublicKey as O,isGetCertificateApdu as R,willRequestPermission as D}from"../../secure-channel/utils";import{bufferToHexaString as x,hexaStringToBuffer as A}from"../../utils/HexaString";import{NobleCryptoService as N}from"../../../internal/crypto/NobleCryptoService";import{SecureChannelError as r,SecureChannelErrorType as S}from"../../../internal/secure-channel/model/Errors";class j{constructor(n,c){this._api=n;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())}`);this._cryptoService=this._args.cryptoService??new N}_connection;_cryptoService;_deviceIdCaptured=!1;run(){const n=this._api.disableRefresher("connectToSecureChannel");return new T(t=>{let g=!1,l=!1,v=!1;const a=f=>{t.next({type:i.Error,error:f}),t.complete(),l=!0};return this._connection.onopen=()=>{t.next({type:i.Opened})},this._connection.onerror=f=>{l||(t.next({type:i.Error,error:new r({url:this._connection.url,errorMessage:f.message})}),t.complete())},this._connection.onclose=()=>{l||(v?t.next({type:i.Closed}):t.next({type:i.Error,error:new r({url:this._connection.url,errorMessage:"Connection closed unexpectedly"})}),t.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{a(new r({url:this._connection.url,errorMessage:`Invalid message received: ${String(f.data)}`}));return}switch(o.query){case y.EXCHANGE:{const{nonce:e,data:p}=o;if(typeof p!="string"){a(new r(`${y.EXCHANGE} data type should be an APDU`));return}const s=A(p);if(s===null||s.length<5){a(new r(`Received invalid APDU data: ${p}`));return}t.next({type:i.PreExchange,payload:{nonce:e,apdu:s}});let u=!1;D(s)&&!this.isSecureConnectionAllowed()&&(u=!0,t.next({type:i.PermissionRequested}));const m=await this._api.sendApdu(s);if(g)return;m.caseOf({Left:d=>{a(new r(d))},Right:d=>{let C;const E=this.mapDeviceError(d);if(E===null){if(C=w.SUCCESS,!this._deviceIdCaptured&&R(s)){this._deviceIdCaptured=!0;const _=O(d);if(_){const k=this._cryptoService.sha3_256(_);t.next({type:i.DeviceId,payload:{deviceId:k}})}}t.next({type:i.Exchange,payload:{nonce:e,apdu:s,data:d.data,status:d.statusCode}}),u&&t.next({type:i.PermissionGranted})}else C=w.ERROR,a(E);const M={nonce:e,response:C,data:x(d.data,!1)};this._connection.send(JSON.stringify(M))}});break}case y.BULK:{if(l=!0,this._connection.close(),!Array.isArray(o.data)||o.data.length===0||!o.data.every(e=>typeof e=="string")){a(new r("Invalid bulk data received"));return}for(let e=0,p=o.data.length;e<p;e++){const s=A(o.data[e]);if(s===null||s.length<5){a(new r(`Received invalid APDU bulk data: ${o.data[e]}`));return}const u=await this._api.sendApdu(s);if(g)return;if(u.isLeft()){a(new r(u.extract()));return}else if(u.isRight()){const m=this.mapDeviceError(u.extract());if(m===null)t.next({type:i.Progress,payload:{progress:+Number((e+1)/p).toFixed(2),index:e,total:p}});else{a(m);return}}}v=!0,t.complete();break}case y.SUCCESS:{if(l)break;const e=o.result??o.data;e&&t.next({type:i.Result,payload:e??""}),v=!0,t.complete();break}case y.WARNING:{if(l)break;t.next({type:i.Warning,payload:{message:String(o.data)}});break}case y.ERROR:{if(l)break;a(new r({url:this._connection.url,errorMessage:String(o.data)}))}}},()=>{n(),g=!0,this._connection.readyState===I.OPEN&&this._connection.close()}})}isSecureConnectionAllowed(){const n=this._api.getDeviceSessionState();return"isSecureConnectionAllowed"in n&&n.isSecureConnectionAllowed}isInMessageType(n){if(typeof n!="object"||!n)return!1;const c=n;return typeof c.uuid=="string"&&typeof c.session=="string"&&typeof c.query=="string"&&Object.values(y).includes(c.query)&&typeof c.nonce=="number"}mapDeviceError(n){return h.isSuccessResponse(n)?null:h.isLockedDeviceResponse(n)?new r({url:this._connection.url,errorMessage:"Device is locked"},S.DeviceLocked):h.isRefusedByUser(n)?new r({url:this._connection.url,errorMessage:"User refused on the device"},S.RefusedByUser):h.isAppAlreadyInstalled(n)?new r({url:this._connection.url,errorMessage:"App already installed"},S.AppAlreadyInstalled):h.isOutOfMemory(n)?new r({url:this._connection.url,errorMessage:"Out of memory"},S.OutOfMemory):new r({url:this._connection.url,errorMessage:`Invalid status code: ${x(n.statusCode)}`})}}export{j 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 { 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,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qC,CACnC,MAAMoC,EAAqB,KAAK,KAAK,sBAAsB,EAC3D,MACE,8BAA+BA,GAC/BA,EAAmB,yBAEvB,CAEA,gBAAgBX,EAAsC,CACpD,GAAI,OAAOA,GAAS,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"]
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 extractPublicKey,\n isGetCertificateApdu,\n willRequestPermission,\n} from \"@api/secure-channel/utils\";\nimport { bufferToHexaString, hexaStringToBuffer } from \"@api/utils/HexaString\";\nimport { type CryptoService } from \"@internal/crypto/CryptoService\";\nimport { NobleCryptoService } from \"@internal/crypto/NobleCryptoService\";\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 cryptoService?: CryptoService;\n};\n\nexport class ConnectToSecureChannelTask {\n private readonly _connection: WebSocket;\n private readonly _cryptoService: CryptoService;\n private _deviceIdCaptured: boolean = false;\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 this._cryptoService = this._args.cryptoService ?? new NobleCryptoService();\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 // Check if this is the first GetCertificate call\n if (!this._deviceIdCaptured && isGetCertificateApdu(apdu)) {\n this._deviceIdCaptured = true;\n const publicKey = extractPublicKey(apduResponse);\n if (publicKey) {\n // Compute SHA3-256 hash of the public key to get the device ID\n const deviceId = this._cryptoService.sha3_256(publicKey);\n subscriber.next({\n type: SecureChannelEventType.DeviceId,\n payload: { deviceId },\n });\n }\n }\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,OACE,oBAAAC,EACA,wBAAAC,EACA,yBAAAC,MACK,4BACP,OAAS,sBAAAC,EAAoB,sBAAAC,MAA0B,wBAEvD,OAAS,sBAAAC,MAA0B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B,MAAO,GAGT,MAAMS,EAAUT,EAChB,OACE,OAAOS,EAAQ,MAAS,UACxB,OAAOA,EAAQ,SAAY,UAC3B,OAAOA,EAAQ,OAAU,UACzB,OAAO,OAAOlC,CAAkB,EAAE,SAASkC,EAAQ,KAAK,GACxD,OAAOA,EAAQ,OAAU,QAE7B,CAEA,eAAeL,EAAuD,CACpE,OAAI9B,EAAa,kBAAkB8B,CAAY,EACtC,KAIL9B,EAAa,uBAAuB8B,CAAY,EAC3C,IAAIpB,EACT,CACE,IAAK,KAAK,YAAY,IACtB,aAAc,kBAChB,EACAC,EAAuB,YACzB,EAIEX,EAAa,gBAAgB8B,CAAY,EACpC,IAAIpB,EACT,CACE,IAAK,KAAK,YAAY,IACtB,aAAc,4BAChB,EACAC,EAAuB,aACzB,EAIEX,EAAa,sBAAsB8B,CAAY,EAC1C,IAAIpB,EACT,CACE,IAAK,KAAK,YAAY,IACtB,aAAc,uBAChB,EACAC,EAAuB,mBACzB,EAIEX,EAAa,cAAc8B,CAAY,EAClC,IAAIpB,EACT,CACE,IAAK,KAAK,YAAY,IACtB,aAAc,eAChB,EACAC,EAAuB,WACzB,EAGK,IAAID,EAAmB,CAC5B,IAAK,KAAK,YAAY,IACtB,aAAc,wBAAwBH,EACpCuB,EAAa,UACf,CAAC,EACH,CAAC,CACH,CACF",
6
+ "names": ["WebSocket", "Observable", "CommandUtils", "InMessageQueryEnum", "OutMessageResponseEnum", "SecureChannelEventType", "extractPublicKey", "isGetCertificateApdu", "willRequestPermission", "bufferToHexaString", "hexaStringToBuffer", "NobleCryptoService", "SecureChannelError", "SecureChannelErrorType", "ConnectToSecureChannelTask", "_api", "_args", "reenableRefresher", "subscriber", "unsubscribed", "ignoreNetworkEvents", "communicationFinished", "notifyError", "error", "event", "input", "jsonData", "nonce", "data", "apdu", "permissionRequested", "response", "apduResponse", "outMessageResponse", "deviceError", "publicKey", "deviceId", "message", "i", "len", "payload", "deviceSessionState"]
7
7
  }
@@ -1,2 +1,2 @@
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"})}])})});
1
+ import S from"isomorphic-ws";import{Right as l}from"purify-ts";import{describe as w,it as c,vi as x}from"vitest";import{SecureChannelEventType as o}from"../../secure-channel/task/types";import{SecureChannelError as m,SecureChannelErrorType as f}from"../../../internal/secure-channel/model/Errors";import{ConnectToSecureChannelTask as v}from"./ConnectToSecureChannelTask";x.mock("isomorphic-ws",()=>({...x.importActual("isomorphic-ws"),__esModule:!0,default:class{onopen=null;onmessage=null;send=x.fn();close=x.fn();url;constructor(n){this.url=n}}}));const u=5;w("ConnectToSecureChannelTask",()=>{let n,y,b,r;const i=x.fn(),d={uuid:"5b776c8d-8af2-48c0-8250-04edca2ef5e9",session:"39ce749e-00a4-4c31-a697-1dc1a29e2cab",query:"success",nonce:15};beforeEach(()=>{n=new S("wss://test-host.com"),y={sendApdu:i,disableRefresher:e=>x.fn()},b={connection:l(n)},r=new v(y,b)}),afterEach(()=>{x.resetAllMocks()}),c("should emit Opened event on WebSocket open",async()=>{const e=[];r.run().subscribe(t=>e.push(t)),expect(n.onopen).toBeDefined(),n.onopen({type:"open",target:{}}),await new Promise(t=>setTimeout(t,u)),expect(e).toStrictEqual([{type:o.Opened}])}),c("Error on wrongly formatted message",async()=>{const e=[];r.run().subscribe({next:t=>{e.push(t)}}),expect(n.onmessage).toBeDefined(),n.onmessage({data:"invalidData",type:"",target:{}}),await new Promise(t=>setTimeout(t,u)),expect(e).toStrictEqual([{type:o.Error,error:new m({url:"wss://test-host.com",errorMessage:"Invalid message received: invalidData"})}])}),c("should handle incoming EXCHANGE message including requesting user permission",async()=>{i.mockResolvedValue(l({data:new Uint8Array([144,0]),statusCode:new Uint8Array([144,0])}));const e=x.spyOn(n,"send");x.spyOn(r,"isSecureConnectionAllowed").mockReturnValueOnce(!1);const s=[];r.run().subscribe({next:a=>{s.push(a)}}),expect(n.onmessage).toBeDefined(),n.onmessage({data:JSON.stringify({...d,query:"exchange",nonce:1,data:"e051000000"}),type:"",target:{}}),await new Promise(a=>setTimeout(a,u)),expect(e).toHaveBeenCalledExactlyOnceWith(JSON.stringify({nonce:1,response:"success",data:"9000"})),expect(s).toStrictEqual([{type:o.PreExchange,payload:{nonce:1,apdu:new Uint8Array([224,81,0,0,0])}},{type:o.PermissionRequested},{type:o.Exchange,payload:{nonce:1,apdu:new Uint8Array([224,81,0,0,0]),data:new Uint8Array([144,0]),status:new Uint8Array([144,0])}},{type:o.PermissionGranted}])}),c("should capture and emit device ID on first GetCertificate APDU",async()=>{const e=new Uint8Array([7,74,7,161,82,230,187,193,65,4,28,116,122,78,8,27,92,30,208,39,252,175,128,218,218,31,132,252,142,67,96,203,83,196,182,158,99,203,145,183,202,211,21,99,104,89,27,251,5,143,114,15,151,175,196,115,249,120,85,251,150,228,84,212,128,24,22,0,52,159,216,220,18,81,70,48,68,2,32,126,60,221,29,21,8,246,141,22,99,74,58,30,225,151,196,80,201,23,101,229,226,72,36,23,178,94,227,160,25,129,200,2,32,89,121,93,9,41,199,216,75,173,173,229,5,14,59,33,25,125,170,255,163,41,234,7,213,180,41,28,166,233,42,114,217]);i.mockResolvedValue(l({data:e,statusCode:new Uint8Array([144,0])}));const s=new Uint8Array([170,187,204,221]),t={sha3_256:x.fn().mockReturnValue(s)},a=new v(y,{connection:l(n),cryptoService:t}),g=[];a.run().subscribe({next:p=>{g.push(p)}}),expect(n.onmessage).toBeDefined(),n.onmessage({data:JSON.stringify({...d,query:"exchange",nonce:1,data:"e052000000"}),type:"",target:{}}),await new Promise(p=>setTimeout(p,u)),expect(t.sha3_256).toHaveBeenCalledWith(Uint8Array.from([4,28,116,122,78,8,27,92,30,208,39,252,175,128,218,218,31,132,252,142,67,96,203,83,196,182,158,99,203,145,183,202,211,21,99,104,89,27,251,5,143,114,15,151,175,196,115,249,120,85,251,150,228,84,212,128,24,22,0,52,159,216,220,18,81]));const h=g.find(p=>p.type===o.DeviceId);expect(h).toBeDefined(),expect(h?.payload?.deviceId).toBe(s)}),c("should handle incoming EXCHANGE message with a device error",async()=>{i.mockResolvedValue(l({data:new Uint8Array([]),statusCode:new Uint8Array([85,21])}));const e=x.spyOn(n,"send"),s=[];r.run().subscribe({next:a=>{s.push(a)}}),expect(n.onmessage).toBeDefined(),n.onmessage({data:JSON.stringify({...d,query:"exchange",nonce:1,data:"e053000000"}),type:"",target:{}}),await new Promise(a=>setTimeout(a,u)),expect(e).toHaveBeenCalledExactlyOnceWith(JSON.stringify({nonce:1,response:"error",data:""})),expect(s).toStrictEqual([{type:o.PreExchange,payload:{nonce:1,apdu:new Uint8Array([224,83,0,0,0])}},{type:o.Error,error:new m({url:"wss://test-host.com",errorMessage:"Device is locked"},f.DeviceLocked)}])}),c("should handle incoming BULK message",async()=>{i.mockResolvedValue(l({data:new Uint8Array([144,0]),statusCode:new Uint8Array([144,0])}));const e=x.fn(),s=r.run(),t=[];s.subscribe({next:a=>{t.push(a)},complete:()=>e()}),expect(n.onmessage).toBeDefined(),n.onmessage({data:JSON.stringify({...d,query:"bulk",nonce:1,data:["0000000100","0000000200","0000000300"]}),type:"",target:{}}),await new Promise(a=>setTimeout(a,u)),expect(i).toHaveBeenCalledTimes(3),expect(t).toStrictEqual([{type:o.Progress,payload:{progress:.33,index:0,total:3}},{type:o.Progress,payload:{progress:.67,index:1,total:3}},{type:o.Progress,payload:{progress:1,index:2,total:3}}]),expect(e).toHaveBeenCalledOnce()}),c("should handle incoming BULK message with a device error",async()=>{i.mockResolvedValue(l({data:new Uint8Array([]),statusCode:new Uint8Array([85,1])}));const e=x.fn(),s=r.run(),t=[];s.subscribe({next:a=>{t.push(a)},complete:()=>e()}),expect(n.onmessage).toBeDefined(),n.onmessage({data:JSON.stringify({...d,query:"bulk",nonce:1,data:["0000000100","0000000200","0000000300"]}),type:"",target:{}}),await new Promise(a=>setTimeout(a,u)),expect(i).toHaveBeenCalledTimes(1),expect(t).toStrictEqual([{type:o.Error,error:new m({url:"wss://test-host.com",errorMessage:"User refused on the device"},f.RefusedByUser)}]),expect(e).toHaveBeenCalledOnce()}),c("should handle incoming SUCCESS message",()=>{const e=x.fn(),s=[];r.run().subscribe({next:a=>s.push(a),complete:()=>e()}),n.onmessage({data:JSON.stringify({...d,query:"success",nonce:1,result:"success result"}),type:"",target:{}}),expect(s).toStrictEqual([{type:o.Result,payload:"success result"}]),expect(e).toHaveBeenCalledOnce()}),c("should handle incoming WARNING message",()=>{const e=[];r.run().subscribe({next:t=>e.push(t)}),expect(n.onmessage).toBeDefined(),n.onmessage({data:JSON.stringify({...d,query:"warning",nonce:1,data:"warning message"}),type:"",target:{}}),expect(e).toStrictEqual([{type:o.Warning,payload:{message:"warning message"}}])}),c("should handle incoming ERROR message",()=>{const e=[];r.run().subscribe({next:t=>e.push(t)}),expect(n.onmessage).toBeDefined(),n.onmessage({data:JSON.stringify({...d,query:"error",data:"My error"}),type:"",target:{}}),expect(e).toStrictEqual([{type:o.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 {\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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AAG,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"]
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 capture and emit device ID on first GetCertificate APDU\", async () => {\n // Mock response for GetCertificate\n const mockResponse = new Uint8Array([\n 0x07, 0x4a, 0x07, 0xa1, 0x52, 0xe6, 0xbb, 0xc1, 0x41, 0x04, 0x1c, 0x74,\n 0x7a, 0x4e, 0x08, 0x1b, 0x5c, 0x1e, 0xd0, 0x27, 0xfc, 0xaf, 0x80, 0xda,\n 0xda, 0x1f, 0x84, 0xfc, 0x8e, 0x43, 0x60, 0xcb, 0x53, 0xc4, 0xb6, 0x9e,\n 0x63, 0xcb, 0x91, 0xb7, 0xca, 0xd3, 0x15, 0x63, 0x68, 0x59, 0x1b, 0xfb,\n 0x05, 0x8f, 0x72, 0x0f, 0x97, 0xaf, 0xc4, 0x73, 0xf9, 0x78, 0x55, 0xfb,\n 0x96, 0xe4, 0x54, 0xd4, 0x80, 0x18, 0x16, 0x00, 0x34, 0x9f, 0xd8, 0xdc,\n 0x12, 0x51, 0x46, 0x30, 0x44, 0x02, 0x20, 0x7e, 0x3c, 0xdd, 0x1d, 0x15,\n 0x08, 0xf6, 0x8d, 0x16, 0x63, 0x4a, 0x3a, 0x1e, 0xe1, 0x97, 0xc4, 0x50,\n 0xc9, 0x17, 0x65, 0xe5, 0xe2, 0x48, 0x24, 0x17, 0xb2, 0x5e, 0xe3, 0xa0,\n 0x19, 0x81, 0xc8, 0x02, 0x20, 0x59, 0x79, 0x5d, 0x09, 0x29, 0xc7, 0xd8,\n 0x4b, 0xad, 0xad, 0xe5, 0x05, 0x0e, 0x3b, 0x21, 0x19, 0x7d, 0xaa, 0xff,\n 0xa3, 0x29, 0xea, 0x07, 0xd5, 0xb4, 0x29, 0x1c, 0xa6, 0xe9, 0x2a, 0x72,\n 0xd9,\n ]);\n\n sendApduFn.mockResolvedValue(\n Right({\n data: mockResponse,\n statusCode: new Uint8Array([0x90, 0x00]),\n }),\n );\n\n // Mock crypto service\n const mockDeviceId = new Uint8Array([0xaa, 0xbb, 0xcc, 0xdd]);\n const mockCryptoService = {\n sha3_256: vi.fn().mockReturnValue(mockDeviceId),\n };\n\n const taskWithMockCrypto = new ConnectToSecureChannelTask(mockInternalApi, {\n connection: Right(mockWebSocket),\n cryptoService: mockCryptoService,\n });\n\n const events: SecureChannelEvent[] = [];\n const obs = taskWithMockCrypto.run();\n obs.subscribe({\n next: (event) => {\n events.push(event);\n },\n });\n\n expect(mockWebSocket.onmessage).toBeDefined();\n // Send GetCertificate APDU (e052000000)\n mockWebSocket.onmessage!({\n data: JSON.stringify({\n ...mockMessage,\n query: \"exchange\",\n nonce: 1,\n data: \"e052000000\",\n }),\n type: \"\",\n target: {} as WebSocket,\n });\n\n await new Promise((resolve) => setTimeout(resolve, TEST_DELAY));\n\n // Verify the mock crypto service was called\n expect(mockCryptoService.sha3_256).toHaveBeenCalledWith(\n Uint8Array.from([\n 0x04, 0x1c, 0x74, 0x7a, 0x4e, 0x08, 0x1b, 0x5c, 0x1e, 0xd0, 0x27, 0xfc,\n 0xaf, 0x80, 0xda, 0xda, 0x1f, 0x84, 0xfc, 0x8e, 0x43, 0x60, 0xcb, 0x53,\n 0xc4, 0xb6, 0x9e, 0x63, 0xcb, 0x91, 0xb7, 0xca, 0xd3, 0x15, 0x63, 0x68,\n 0x59, 0x1b, 0xfb, 0x05, 0x8f, 0x72, 0x0f, 0x97, 0xaf, 0xc4, 0x73, 0xf9,\n 0x78, 0x55, 0xfb, 0x96, 0xe4, 0x54, 0xd4, 0x80, 0x18, 0x16, 0x00, 0x34,\n 0x9f, 0xd8, 0xdc, 0x12, 0x51,\n ]),\n );\n\n // Verify the device ID from the mock crypto service was emitted\n const deviceIdEvent = events.find(\n (e) => e.type === SecureChannelEventType.DeviceId,\n );\n expect(deviceIdEvent).toBeDefined();\n expect(deviceIdEvent?.payload?.deviceId).toBe(mockDeviceId);\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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AE,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", "mockResponse", "mockDeviceId", "mockCryptoService", "taskWithMockCrypto", "deviceIdEvent", "completeFn", "obs"]
7
7
  }
@@ -1,2 +1,2 @@
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};
1
+ var t=(r=>(r.GenuineCheck="GenuineCheck",r.ListInstalledApps="ListInstalledApps",r.UpdateMcu="UpdateMcu",r.UpdateFirmware="UpdateFirmware",r.InstallApp="InstallApp",r.UninstallApp="UninstallApp",r))(t||{}),s=(n=>(n.EXCHANGE="exchange",n.BULK="bulk",n.ERROR="error",n.WARNING="warning",n.SUCCESS="success",n))(s||{}),p=(a=>(a.SUCCESS="success",a.ERROR="error",a))(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.DeviceId="device-id",e.Progress="progress",e.Warning="warning",e.Error="error",e.Result="result",e))(o||{});export{s as InMessageQueryEnum,p as OutMessageResponseEnum,o as SecureChannelEventType,t 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": ["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",
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 DeviceId = \"device-id\",\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 DeviceId: { deviceId: Uint8Array };\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.DeviceId;\n payload: SecureChannelEventPayload[\"DeviceId\"];\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,YACXA,EAAA,SAAW,WACXA,EAAA,QAAU,UACVA,EAAA,MAAQ,QACRA,EAAA,OAAS,SAXCA,OAAA",
6
6
  "names": ["SecureChannelOperationEnum", "InMessageQueryEnum", "OutMessageResponseEnum", "SecureChannelEventType"]
7
7
  }
@@ -1,2 +1,2 @@
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};
1
+ import{ApduParser as t}from"../apdu/utils/ApduParser";import{GENUINE_DEVICE_RESULT as n}from"../secure-channel/constants";function c(e){return e[0]===224&&e[1]===81}function a(e){return e[0]===224&&e[1]===82}function p(e){try{const r=new t(e);return r.extractFieldLVEncoded()?r.extractFieldLVEncoded()??null:null}catch{return null}}function s(e){return e===n}export{p as extractPublicKey,s as isDeviceGenuine,a as isGetCertificateApdu,c 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 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"]
4
+ "sourcesContent": ["import { ApduParser } from \"@api/apdu/utils/ApduParser\";\nimport { type ApduResponse } from \"@api/device-session/ApduResponse\";\nimport { GENUINE_DEVICE_RESULT } from \"@api/secure-channel/constants\";\nimport { type SecureChannelEventPayload } from \"@api/secure-channel/task/types\";\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 given APDU command is a GetCertificate command.\n *\n * This method checks if the first byte of the APDU command is `0xe0` and the second byte is `0x52`.\n *\n * @param apdu - The APDU command as a Uint8Array.\n * @returns `true` if the APDU command is a GetCertificate command, otherwise `false`.\n */\nexport function isGetCertificateApdu(apdu: Uint8Array): boolean {\n return apdu[0] === 0xe0 && apdu[1] === 0x52;\n}\n\n/**\n * Extract the public key from a GetCertificate response.\n *\n * @param apduResponse - The APDU response containing the certificate data.\n * @returns The extracted public key as a Uint8Array, or null if extraction fails.\n */\nexport function extractPublicKey(\n apduResponse: ApduResponse,\n): Uint8Array | null {\n try {\n const parser = new ApduParser(apduResponse);\n\n // Skip header (length-value encoded)\n const header = parser.extractFieldLVEncoded();\n if (!header) {\n return null;\n }\n\n // Extract public key (length-value encoded)\n const publicKey = parser.extractFieldLVEncoded();\n return publicKey ?? null;\n } catch (_error) {\n return null;\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": "AAAA,OAAS,cAAAA,MAAkB,6BAE3B,OAAS,yBAAAC,MAA6B,gCAW/B,SAASC,EAAsBC,EAA2B,CAC/D,OAAOA,EAAK,CAAC,IAAM,KAAQA,EAAK,CAAC,IAAM,EACzC,CAUO,SAASC,EAAqBD,EAA2B,CAC9D,OAAOA,EAAK,CAAC,IAAM,KAAQA,EAAK,CAAC,IAAM,EACzC,CAQO,SAASE,EACdC,EACmB,CACnB,GAAI,CACF,MAAMC,EAAS,IAAIP,EAAWM,CAAY,EAI1C,OADeC,EAAO,sBAAsB,EAM1BA,EAAO,sBAAsB,GAC3B,KALX,IAMX,MAAiB,CACf,OAAO,IACT,CACF,CASO,SAASC,EAAgBC,EAA8C,CAC5E,OAAOA,IAAYR,CACrB",
6
+ "names": ["ApduParser", "GENUINE_DEVICE_RESULT", "willRequestPermission", "apdu", "isGetCertificateApdu", "extractPublicKey", "apduResponse", "parser", "isDeviceGenuine", "payload"]
7
7
  }
@@ -1,2 +1,2 @@
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)})});
1
+ import{ApduResponse as i}from"../device-session/ApduResponse";import{extractPublicKey as n,isDeviceGenuine as r,isGetCertificateApdu as a,willRequestPermission as s}from"./utils";describe("willRequestPermission",()=>{it("should return true if the APDU is a permission request",()=>{const x=new Uint8Array([224,81,0,0,0]);expect(s(x)).toBe(!0)}),it("should return false if the APDU is not a permission request",()=>{const x=new Uint8Array([224,82,0,0,0]);expect(s(x)).toBe(!1)})});describe("isGetCertificateApdu",()=>{it("should return true if the APDU is a GetCertificate command",()=>{const x=new Uint8Array([224,82,0,0,0]);expect(a(x)).toBe(!0)}),it("should return true for GetCertificate with different P1 and P2",()=>{const x=new Uint8Array([224,82,128,1,0]);expect(a(x)).toBe(!0)}),it("should return false if the APDU is not a GetCertificate command",()=>{const x=new Uint8Array([224,81,0,0,0]);expect(a(x)).toBe(!1)})});describe("extractPublicKey",()=>{it("should extract public key from a valid GetCertificate response",()=>{const x=new Uint8Array([7,74,7,161,82,230,187,193,65,4,28,116,122,78,8,27,92,30,208,39,252,175,128,218,218,31,132,252,142,67,96,203,83,196,182,158,99,203,145,183,202,211,21,99,104,89,27,251,5,143,114,15,151,175,196,115,249,120,85,251,150,228,84,212,128,24,22,0,52,159,216,220,18,81,70,48,68,2,32,126,60,221,29,21,8,246,141,22,99,74,58,30,225,151,196,80,201,23,101,229,226,72,36,23,178,94,227,160,25,129,200,2,32,89,121,93,9,41,199,216,75,173,173,229,5,14,59,33,25,125,170,255,163,41,234,7,213,180,41,28,166,233,42,114,217]),t=new i({statusCode:new Uint8Array([144,0]),data:x}),e=n(t);expect(e).not.toBeNull(),expect(e?.length).toBe(65),expect(e?.[0]).toBe(4),expect(e?.[64]).toBe(81)}),it("should return null for invalid response with missing header",()=>{const x=new i({statusCode:new Uint8Array([144,0]),data:new Uint8Array([])}),t=n(x);expect(t).toBeNull()}),it("should return null for invalid response with missing public key",()=>{const x=new Uint8Array([7,74,7,161,82,230,187,193]),t=new i({statusCode:new Uint8Array([144,0]),data:x}),e=n(t);expect(e).toBeNull()})});describe("isDeviceGenuine",()=>{it("should return true if the device is genuine",()=>{expect(r("0000")).toBe(!0)}),it("should return false if the device is not genuine",()=>{expect(r("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 { 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"]
4
+ "sourcesContent": ["import { ApduResponse } from \"@api/device-session/ApduResponse\";\n\nimport {\n extractPublicKey,\n isDeviceGenuine,\n isGetCertificateApdu,\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(\"isGetCertificateApdu\", () => {\n it(\"should return true if the APDU is a GetCertificate command\", () => {\n const apdu = new Uint8Array([0xe0, 0x52, 0x00, 0x00, 0x00]);\n expect(isGetCertificateApdu(apdu)).toBe(true);\n });\n it(\"should return true for GetCertificate with different P1 and P2\", () => {\n const apdu = new Uint8Array([0xe0, 0x52, 0x80, 0x01, 0x00]);\n expect(isGetCertificateApdu(apdu)).toBe(true);\n });\n it(\"should return false if the APDU is not a GetCertificate command\", () => {\n const apdu = new Uint8Array([0xe0, 0x51, 0x00, 0x00, 0x00]);\n expect(isGetCertificateApdu(apdu)).toBe(false);\n });\n});\n\ndescribe(\"extractPublicKey\", () => {\n it(\"should extract public key from a valid GetCertificate response\", () => {\n const responseData = new Uint8Array([\n 0x07, 0x4a, 0x07, 0xa1, 0x52, 0xe6, 0xbb, 0xc1, 0x41, 0x04, 0x1c, 0x74,\n 0x7a, 0x4e, 0x08, 0x1b, 0x5c, 0x1e, 0xd0, 0x27, 0xfc, 0xaf, 0x80, 0xda,\n 0xda, 0x1f, 0x84, 0xfc, 0x8e, 0x43, 0x60, 0xcb, 0x53, 0xc4, 0xb6, 0x9e,\n 0x63, 0xcb, 0x91, 0xb7, 0xca, 0xd3, 0x15, 0x63, 0x68, 0x59, 0x1b, 0xfb,\n 0x05, 0x8f, 0x72, 0x0f, 0x97, 0xaf, 0xc4, 0x73, 0xf9, 0x78, 0x55, 0xfb,\n 0x96, 0xe4, 0x54, 0xd4, 0x80, 0x18, 0x16, 0x00, 0x34, 0x9f, 0xd8, 0xdc,\n 0x12, 0x51, 0x46, 0x30, 0x44, 0x02, 0x20, 0x7e, 0x3c, 0xdd, 0x1d, 0x15,\n 0x08, 0xf6, 0x8d, 0x16, 0x63, 0x4a, 0x3a, 0x1e, 0xe1, 0x97, 0xc4, 0x50,\n 0xc9, 0x17, 0x65, 0xe5, 0xe2, 0x48, 0x24, 0x17, 0xb2, 0x5e, 0xe3, 0xa0,\n 0x19, 0x81, 0xc8, 0x02, 0x20, 0x59, 0x79, 0x5d, 0x09, 0x29, 0xc7, 0xd8,\n 0x4b, 0xad, 0xad, 0xe5, 0x05, 0x0e, 0x3b, 0x21, 0x19, 0x7d, 0xaa, 0xff,\n 0xa3, 0x29, 0xea, 0x07, 0xd5, 0xb4, 0x29, 0x1c, 0xa6, 0xe9, 0x2a, 0x72,\n 0xd9,\n ]);\n\n const response = new ApduResponse({\n statusCode: new Uint8Array([0x90, 0x00]),\n data: responseData,\n });\n\n const publicKey = extractPublicKey(response);\n\n expect(publicKey).not.toBeNull();\n expect(publicKey?.length).toBe(65);\n expect(publicKey?.[0]).toBe(0x04);\n expect(publicKey?.[64]).toBe(0x51);\n });\n\n it(\"should return null for invalid response with missing header\", () => {\n const response = new ApduResponse({\n statusCode: new Uint8Array([0x90, 0x00]),\n data: new Uint8Array([]),\n });\n\n const publicKey = extractPublicKey(response);\n\n expect(publicKey).toBeNull();\n });\n\n it(\"should return null for invalid response with missing public key\", () => {\n const responseData = new Uint8Array([\n 0x07, 0x4a, 0x07, 0xa1, 0x52, 0xe6, 0xbb, 0xc1,\n ]);\n\n const response = new ApduResponse({\n statusCode: new Uint8Array([0x90, 0x00]),\n data: responseData,\n });\n\n const publicKey = extractPublicKey(response);\n\n expect(publicKey).toBeNull();\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,gBAAAA,MAAoB,mCAE7B,OACE,oBAAAC,EACA,mBAAAC,EACA,wBAAAC,EACA,yBAAAC,MACK,UAEP,SAAS,wBAAyB,IAAM,CACtC,GAAG,yDAA0D,IAAM,CACjE,MAAMC,EAAO,IAAI,WAAW,CAAC,IAAM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EAAa,CAChC,WAAY,IAAI,WAAW,CAAC,IAAM,CAAI,CAAC,EACvC,KAAMM,CACR,CAAC,EAEKE,EAAYP,EAAiBM,CAAQ,EAE3C,OAAOC,CAAS,EAAE,SAAS,CAC7B,CAAC,CACH,CAAC,EAED,SAAS,kBAAmB,IAAM,CAChC,GAAG,8CAA+C,IAAM,CAEtD,OAAON,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": ["ApduResponse", "extractPublicKey", "isDeviceGenuine", "isGetCertificateApdu", "willRequestPermission", "apdu", "responseData", "response", "publicKey"]
7
7
  }
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=CryptoService.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ import{sha3_256 as e}from"@noble/hashes/sha3";class i{sha3_256(r){return e(r)}}export{i as NobleCryptoService};
2
+ //# sourceMappingURL=NobleCryptoService.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/internal/crypto/NobleCryptoService.ts"],
4
+ "sourcesContent": ["import { sha3_256 } from \"@noble/hashes/sha3\";\n\nimport { type CryptoService } from \"./CryptoService\";\n\n/**\n * Noble implementation of the crypto service\n */\nexport class NobleCryptoService implements CryptoService {\n sha3_256(data: Uint8Array): Uint8Array {\n return sha3_256(data);\n }\n}\n"],
5
+ "mappings": "AAAA,OAAS,YAAAA,MAAgB,qBAOlB,MAAMC,CAA4C,CACvD,SAASC,EAA8B,CACrC,OAAOF,EAASE,CAAI,CACtB,CACF",
6
+ "names": ["sha3_256", "NobleCryptoService", "data"]
7
+ }
@@ -0,0 +1,2 @@
1
+ import{NobleCryptoService as c}from"./NobleCryptoService";describe("NobleCryptoService",()=>{let x;beforeEach(()=>{x=new c}),describe("sha3_256",()=>{it("should compute SHA3-256 hash",()=>{const e=new Uint8Array([1,2,3,4]),r=x.sha3_256(e);expect(r).toStrictEqual(new Uint8Array([150,109,189,203,208,224,52,143,170,28,203,206,90,98,184,231,59,13,8,149,93,102,109,184,34,67,179,3,217,189,149,2]))})})});
2
+ //# sourceMappingURL=NobleCryptoService.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/internal/crypto/NobleCryptoService.test.ts"],
4
+ "sourcesContent": ["import { NobleCryptoService } from \"./NobleCryptoService\";\n\ndescribe(\"NobleCryptoService\", () => {\n let cryptoService: NobleCryptoService;\n\n beforeEach(() => {\n cryptoService = new NobleCryptoService();\n });\n\n describe(\"sha3_256\", () => {\n it(\"should compute SHA3-256 hash\", () => {\n const input = new Uint8Array([0x01, 0x02, 0x03, 0x04]);\n const hash = cryptoService.sha3_256(input);\n\n expect(hash).toStrictEqual(\n new Uint8Array([\n 0x96, 0x6d, 0xbd, 0xcb, 0xd0, 0xe0, 0x34, 0x8f, 0xaa, 0x1c, 0xcb,\n 0xce, 0x5a, 0x62, 0xb8, 0xe7, 0x3b, 0x0d, 0x08, 0x95, 0x5d, 0x66,\n 0x6d, 0xb8, 0x22, 0x43, 0xb3, 0x03, 0xd9, 0xbd, 0x95, 0x02,\n ]),\n );\n });\n });\n});\n"],
5
+ "mappings": "AAAA,OAAS,sBAAAA,MAA0B,uBAEnC,SAAS,qBAAsB,IAAM,CACnC,IAAIC,EAEJ,WAAW,IAAM,CACfA,EAAgB,IAAID,CACtB,CAAC,EAED,SAAS,WAAY,IAAM,CACzB,GAAG,+BAAgC,IAAM,CACvC,MAAME,EAAQ,IAAI,WAAW,CAAC,EAAM,EAAM,EAAM,CAAI,CAAC,EAC/CC,EAAOF,EAAc,SAASC,CAAK,EAEzC,OAAOC,CAAI,EAAE,cACX,IAAI,WAAW,CACb,IAAM,IAAM,IAAM,IAAM,IAAM,IAAM,GAAM,IAAM,IAAM,GAAM,IAC5D,IAAM,GAAM,GAAM,IAAM,IAAM,GAAM,GAAM,EAAM,IAAM,GAAM,IAC5D,IAAM,IAAM,GAAM,GAAM,IAAM,EAAM,IAAM,IAAM,IAAM,CACxD,CAAC,CACH,CACF,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["NobleCryptoService", "cryptoService", "input", "hash"]
7
+ }
@@ -34,4 +34,9 @@ export declare class UnknownDAError implements DmkError {
34
34
  readonly originalError?: Error;
35
35
  constructor(message?: string);
36
36
  }
37
+ export declare class UnsupportedApplicationDAError implements DmkError {
38
+ readonly _tag = "UnsupportedApplicationDAError";
39
+ readonly originalError?: Error;
40
+ constructor(message?: string);
41
+ }
37
42
  //# sourceMappingURL=Errors.d.ts.map