@ledgerhq/device-management-kit 0.11.0 → 0.11.2

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 +2 -1
  2. package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js +1 -1
  3. package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js.map +2 -2
  4. package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/types.js +1 -1
  5. package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/types.js.map +1 -1
  6. package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js +1 -1
  7. package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js.map +2 -2
  8. package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/types.js.map +1 -1
  9. package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.js +1 -1
  10. package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.js.map +2 -2
  11. package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/types.js +1 -1
  12. package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/types.js.map +1 -1
  13. package/lib/cjs/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.js +1 -1
  14. package/lib/cjs/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.js.map +2 -2
  15. package/lib/cjs/src/api/secure-channel/device-action/GenuineCheck/types.js.map +1 -1
  16. package/lib/cjs/src/api/secure-channel/device-action/InstallApp/InstallAppDeviceAction.js +1 -1
  17. package/lib/cjs/src/api/secure-channel/device-action/InstallApp/InstallAppDeviceAction.js.map +2 -2
  18. package/lib/cjs/src/api/secure-channel/device-action/InstallApp/types.js.map +1 -1
  19. package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js +1 -1
  20. package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js.map +2 -2
  21. package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/types.js +1 -1
  22. package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/types.js.map +2 -2
  23. package/lib/cjs/src/api/secure-channel/device-action/UninstallApp/UninstallAppDeviceAction.js +1 -1
  24. package/lib/cjs/src/api/secure-channel/device-action/UninstallApp/UninstallAppDeviceAction.js.map +2 -2
  25. package/lib/cjs/src/api/secure-channel/device-action/UninstallApp/types.js.map +1 -1
  26. package/lib/cjs/src/api/secure-channel/task/ConnectToSecureChannelTask.js +1 -1
  27. package/lib/cjs/src/api/secure-channel/task/ConnectToSecureChannelTask.js.map +3 -3
  28. package/lib/cjs/src/api/secure-channel/task/ConnectToSecureChannelTask.test.js +1 -1
  29. package/lib/cjs/src/api/secure-channel/task/ConnectToSecureChannelTask.test.js.map +3 -3
  30. package/lib/cjs/src/api/secure-channel/task/types.js +1 -1
  31. package/lib/cjs/src/api/secure-channel/task/types.js.map +2 -2
  32. package/lib/cjs/src/api/secure-channel/utils.js +1 -1
  33. package/lib/cjs/src/api/secure-channel/utils.js.map +3 -3
  34. package/lib/cjs/src/api/secure-channel/utils.test.js +1 -1
  35. package/lib/cjs/src/api/secure-channel/utils.test.js.map +3 -3
  36. package/lib/cjs/src/internal/crypto/CryptoService.js +2 -0
  37. package/lib/cjs/src/internal/crypto/CryptoService.js.map +7 -0
  38. package/lib/cjs/src/internal/crypto/NobleCryptoService.js +2 -0
  39. package/lib/cjs/src/internal/crypto/NobleCryptoService.js.map +7 -0
  40. package/lib/cjs/src/internal/crypto/NobleCryptoService.test.js +2 -0
  41. package/lib/cjs/src/internal/crypto/NobleCryptoService.test.js.map +7 -0
  42. package/lib/cjs/src/internal/device-session/service/DefaultDeviceSessionService.js +1 -1
  43. package/lib/cjs/src/internal/device-session/service/DefaultDeviceSessionService.js.map +3 -3
  44. package/lib/cjs/src/internal/device-session/service/DefaultDeviceSessionService.test.js +1 -1
  45. package/lib/cjs/src/internal/device-session/service/DefaultDeviceSessionService.test.js.map +3 -3
  46. package/lib/cjs/src/internal/device-session/service/DeviceSessionService.js +1 -1
  47. package/lib/cjs/src/internal/device-session/service/DeviceSessionService.js.map +1 -1
  48. package/lib/cjs/src/internal/discovery/use-case/ConnectUseCase.js +1 -1
  49. package/lib/cjs/src/internal/discovery/use-case/ConnectUseCase.js.map +3 -3
  50. package/lib/esm/package.json +2 -1
  51. package/lib/esm/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js +1 -1
  52. package/lib/esm/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js.map +2 -2
  53. package/lib/esm/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js +1 -1
  54. package/lib/esm/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js.map +2 -2
  55. package/lib/esm/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.js +1 -1
  56. package/lib/esm/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.js.map +2 -2
  57. package/lib/esm/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.js +1 -1
  58. package/lib/esm/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.js.map +2 -2
  59. package/lib/esm/src/api/secure-channel/device-action/InstallApp/InstallAppDeviceAction.js +1 -1
  60. package/lib/esm/src/api/secure-channel/device-action/InstallApp/InstallAppDeviceAction.js.map +2 -2
  61. package/lib/esm/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js +1 -1
  62. package/lib/esm/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js.map +2 -2
  63. package/lib/esm/src/api/secure-channel/device-action/ListInstalledApps/types.js.map +2 -2
  64. package/lib/esm/src/api/secure-channel/device-action/UninstallApp/UninstallAppDeviceAction.js +1 -1
  65. package/lib/esm/src/api/secure-channel/device-action/UninstallApp/UninstallAppDeviceAction.js.map +2 -2
  66. package/lib/esm/src/api/secure-channel/task/ConnectToSecureChannelTask.js +1 -1
  67. package/lib/esm/src/api/secure-channel/task/ConnectToSecureChannelTask.js.map +3 -3
  68. package/lib/esm/src/api/secure-channel/task/ConnectToSecureChannelTask.test.js +1 -1
  69. package/lib/esm/src/api/secure-channel/task/ConnectToSecureChannelTask.test.js.map +3 -3
  70. package/lib/esm/src/api/secure-channel/task/types.js +1 -1
  71. package/lib/esm/src/api/secure-channel/task/types.js.map +2 -2
  72. package/lib/esm/src/api/secure-channel/utils.js +1 -1
  73. package/lib/esm/src/api/secure-channel/utils.js.map +3 -3
  74. package/lib/esm/src/api/secure-channel/utils.test.js +1 -1
  75. package/lib/esm/src/api/secure-channel/utils.test.js.map +3 -3
  76. package/lib/esm/src/internal/crypto/CryptoService.js +1 -0
  77. package/lib/esm/src/internal/crypto/CryptoService.js.map +7 -0
  78. package/lib/esm/src/internal/crypto/NobleCryptoService.js +2 -0
  79. package/lib/esm/src/internal/crypto/NobleCryptoService.js.map +7 -0
  80. package/lib/esm/src/internal/crypto/NobleCryptoService.test.js +2 -0
  81. package/lib/esm/src/internal/crypto/NobleCryptoService.test.js.map +7 -0
  82. package/lib/esm/src/internal/device-session/service/DefaultDeviceSessionService.js +1 -1
  83. package/lib/esm/src/internal/device-session/service/DefaultDeviceSessionService.js.map +3 -3
  84. package/lib/esm/src/internal/device-session/service/DefaultDeviceSessionService.test.js +1 -1
  85. package/lib/esm/src/internal/device-session/service/DefaultDeviceSessionService.test.js.map +3 -3
  86. package/lib/esm/src/internal/discovery/use-case/ConnectUseCase.js +1 -1
  87. package/lib/esm/src/internal/discovery/use-case/ConnectUseCase.js.map +3 -3
  88. package/lib/types/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.d.ts.map +1 -1
  89. package/lib/types/src/api/device-action/os/GetDeviceMetadata/types.d.ts +1 -0
  90. package/lib/types/src/api/device-action/os/GetDeviceMetadata/types.d.ts.map +1 -1
  91. package/lib/types/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.d.ts.map +1 -1
  92. package/lib/types/src/api/device-action/os/InstallOrUpdateApps/types.d.ts +1 -0
  93. package/lib/types/src/api/device-action/os/InstallOrUpdateApps/types.d.ts.map +1 -1
  94. package/lib/types/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.d.ts.map +1 -1
  95. package/lib/types/src/api/device-action/os/OpenAppWithDependencies/types.d.ts +1 -0
  96. package/lib/types/src/api/device-action/os/OpenAppWithDependencies/types.d.ts.map +1 -1
  97. package/lib/types/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.d.ts.map +1 -1
  98. package/lib/types/src/api/secure-channel/device-action/GenuineCheck/types.d.ts +1 -0
  99. package/lib/types/src/api/secure-channel/device-action/GenuineCheck/types.d.ts.map +1 -1
  100. package/lib/types/src/api/secure-channel/device-action/InstallApp/InstallAppDeviceAction.d.ts.map +1 -1
  101. package/lib/types/src/api/secure-channel/device-action/InstallApp/types.d.ts +1 -0
  102. package/lib/types/src/api/secure-channel/device-action/InstallApp/types.d.ts.map +1 -1
  103. package/lib/types/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.d.ts.map +1 -1
  104. package/lib/types/src/api/secure-channel/device-action/ListInstalledApps/types.d.ts +1 -0
  105. package/lib/types/src/api/secure-channel/device-action/ListInstalledApps/types.d.ts.map +1 -1
  106. package/lib/types/src/api/secure-channel/device-action/UninstallApp/UninstallAppDeviceAction.d.ts.map +1 -1
  107. package/lib/types/src/api/secure-channel/device-action/UninstallApp/types.d.ts +1 -0
  108. package/lib/types/src/api/secure-channel/device-action/UninstallApp/types.d.ts.map +1 -1
  109. package/lib/types/src/api/secure-channel/task/ConnectToSecureChannelTask.d.ts +4 -0
  110. package/lib/types/src/api/secure-channel/task/ConnectToSecureChannelTask.d.ts.map +1 -1
  111. package/lib/types/src/api/secure-channel/task/types.d.ts +7 -0
  112. package/lib/types/src/api/secure-channel/task/types.d.ts.map +1 -1
  113. package/lib/types/src/api/secure-channel/utils.d.ts +18 -1
  114. package/lib/types/src/api/secure-channel/utils.d.ts.map +1 -1
  115. package/lib/types/src/internal/crypto/CryptoService.d.ts +12 -0
  116. package/lib/types/src/internal/crypto/CryptoService.d.ts.map +1 -0
  117. package/lib/types/src/internal/crypto/NobleCryptoService.d.ts +8 -0
  118. package/lib/types/src/internal/crypto/NobleCryptoService.d.ts.map +1 -0
  119. package/lib/types/src/internal/crypto/NobleCryptoService.test.d.ts +2 -0
  120. package/lib/types/src/internal/crypto/NobleCryptoService.test.d.ts.map +1 -0
  121. package/lib/types/src/internal/device-session/service/DefaultDeviceSessionService.d.ts +7 -5
  122. package/lib/types/src/internal/device-session/service/DefaultDeviceSessionService.d.ts.map +1 -1
  123. package/lib/types/src/internal/device-session/service/DeviceSessionService.d.ts +28 -1
  124. package/lib/types/src/internal/device-session/service/DeviceSessionService.d.ts.map +1 -1
  125. package/lib/types/src/internal/discovery/use-case/ConnectUseCase.d.ts.map +1 -1
  126. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  127. package/package.json +4 -3
@@ -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": "wdAAA,IAAAA,EAAsB,4BACtBC,EAAsB,qBACtBC,EAAiC,kBAGjCC,EAGO,0CACPC,EAGO,iDAEPC,EAGO,wCAEP,KAAG,KAAK,gBAAiB,KAAO,CAC9B,GAAG,KAAG,aAAa,eAAe,EAClC,WAAY,GACZ,QAAS,KAAM,CACb,OAA8B,KAC9B,UAAwD,KACxD,KAAO,KAAG,GAAG,EACb,MAAQ,KAAG,GAAG,EACd,IACA,YAAYC,EAAa,CACvB,KAAK,IAAMA,CACb,CACF,CACF,EAAE,EAEF,MAAMC,EAAa,KAEnB,YAAS,6BAA8B,IAAM,CAC3C,IAAIC,EACAC,EACAC,EACAC,EACJ,MAAMC,EAAa,KAAG,GAAG,EACnBC,EAAc,CAClB,KAAM,uCACN,QAAS,uCACT,MAAO,UACP,MAAO,EACT,EAEA,WAAW,IAAM,CAGfL,EAAgB,IAAI,EAAAM,QAAU,qBAAqB,EACnDL,EAAkB,CAChB,SAAUG,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M,EAAE,cAAc,CAC3B,CACE,KAAM,yBAAuB,MAC7B,MAAO,IAAI,qBAAmB,CAC5B,IAAK,sBACL,aAAc,UAChB,CAAC,CACH,CACF,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["import_isomorphic_ws", "import_purify_ts", "import_vitest", "import_types", "import_Errors", "import_ConnectToSecureChannelTask", "url", "TEST_DELAY", "mockWebSocket", "mockInternalApi", "taskArgs", "task", "sendApduFn", "mockMessage", "WebSocket", "_", "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": "wdAAA,IAAAA,EAAsB,4BACtBC,EAAsB,qBACtBC,EAAiC,kBAGjCC,EAGO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AAG,uCAAwC,IAAM,CAC/C,MAAMA,EAA+B,CAAC,EACnBL,EAAK,IAAI,EACjB,UAAU,CACnB,KAAOQ,GAA8BH,EAAO,KAAKG,CAAK,CACxD,CAAC,EAED,OAAOX,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,OAAOG,CAAM,EAAE,cAAc,CAC3B,CACE,KAAM,yBAAuB,MAC7B,MAAO,IAAI,qBAAmB,CAC5B,IAAK,sBACL,aAAc,UAChB,CAAC,CACH,CACF,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["import_isomorphic_ws", "import_purify_ts", "import_vitest", "import_types", "import_Errors", "import_ConnectToSecureChannelTask", "url", "TEST_DELAY", "mockWebSocket", "mockInternalApi", "taskArgs", "task", "sendApduFn", "mockMessage", "WebSocket", "_", "events", "e", "resolve", "event", "sendSpy", "mockResponse", "mockDeviceId", "mockCryptoService", "taskWithMockCrypto", "deviceIdEvent", "completeFn", "obs"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var o=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var P=(n,r)=>{for(var t in r)o(n,t,{get:r[t],enumerable:!0})},h=(n,r,t,l)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of u(r))!x.call(n,s)&&s!==t&&o(n,s,{get:()=>r[s],enumerable:!(l=g(r,s))||l.enumerable});return n};var E=n=>h(o({},"__esModule",{value:!0}),n);var U={};P(U,{InMessageQueryEnum:()=>i,OutMessageResponseEnum:()=>y,SecureChannelEventType:()=>c,SecureChannelOperationEnum:()=>d});module.exports=E(U);var d=(a=>(a.GenuineCheck="GenuineCheck",a.ListInstalledApps="ListInstalledApps",a.UpdateMcu="UpdateMcu",a.UpdateFirmware="UpdateFirmware",a.InstallApp="InstallApp",a.UninstallApp="UninstallApp",a))(d||{}),i=(p=>(p.EXCHANGE="exchange",p.BULK="bulk",p.ERROR="error",p.WARNING="warning",p.SUCCESS="success",p))(i||{}),y=(t=>(t.SUCCESS="success",t.ERROR="error",t))(y||{}),c=(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))(c||{});0&&(module.exports={InMessageQueryEnum,OutMessageResponseEnum,SecureChannelEventType,SecureChannelOperationEnum});
1
+ "use strict";var o=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var P=(n,r)=>{for(var a in r)o(n,a,{get:r[a],enumerable:!0})},h=(n,r,a,d)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of u(r))!x.call(n,s)&&s!==a&&o(n,s,{get:()=>r[s],enumerable:!(d=g(r,s))||d.enumerable});return n};var E=n=>h(o({},"__esModule",{value:!0}),n);var v={};P(v,{InMessageQueryEnum:()=>l,OutMessageResponseEnum:()=>c,SecureChannelEventType:()=>y,SecureChannelOperationEnum:()=>i});module.exports=E(v);var i=(t=>(t.GenuineCheck="GenuineCheck",t.ListInstalledApps="ListInstalledApps",t.UpdateMcu="UpdateMcu",t.UpdateFirmware="UpdateFirmware",t.InstallApp="InstallApp",t.UninstallApp="UninstallApp",t))(i||{}),l=(p=>(p.EXCHANGE="exchange",p.BULK="bulk",p.ERROR="error",p.WARNING="warning",p.SUCCESS="success",p))(l||{}),c=(a=>(a.SUCCESS="success",a.ERROR="error",a))(c||{}),y=(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))(y||{});0&&(module.exports={InMessageQueryEnum,OutMessageResponseEnum,SecureChannelEventType,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": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,wBAAAE,EAAA,2BAAAC,EAAA,2BAAAC,EAAA,+BAAAC,IAAA,eAAAC,EAAAN,GAEO,IAAKK,OACVA,EAAA,aAAe,eACfA,EAAA,kBAAoB,oBACpBA,EAAA,UAAY,YACZA,EAAA,eAAiB,iBACjBA,EAAA,WAAa,aACbA,EAAA,aAAe,eANLA,OAAA,IAqBAH,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": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,wBAAAE,EAAA,2BAAAC,EAAA,2BAAAC,EAAA,+BAAAC,IAAA,eAAAC,EAAAN,GAEO,IAAKK,OACVA,EAAA,aAAe,eACfA,EAAA,kBAAoB,oBACpBA,EAAA,UAAY,YACZA,EAAA,eAAiB,iBACjBA,EAAA,WAAa,aACbA,EAAA,aAAe,eANLA,OAAA,IAqBAH,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": ["types_exports", "__export", "InMessageQueryEnum", "OutMessageResponseEnum", "SecureChannelEventType", "SecureChannelOperationEnum", "__toCommonJS"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var o=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var c=(e,n)=>{for(var t in n)o(e,t,{get:n[t],enumerable:!0})},m=(e,n,t,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of a(n))!E.call(e,r)&&r!==t&&o(e,r,{get:()=>n[r],enumerable:!(i=u(n,r))||i.enumerable});return e};var s=e=>m(o({},"__esModule",{value:!0}),e);var x={};c(x,{isDeviceGenuine:()=>p,willRequestPermission:()=>f});module.exports=s(x);var l=require("./constants");function f(e){return e[0]===224&&e[1]===81}function p(e){return e===l.GENUINE_DEVICE_RESULT}0&&(module.exports={isDeviceGenuine,willRequestPermission});
1
+ "use strict";var i=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var s=(e,r)=>{for(var t in r)i(e,t,{get:r[t],enumerable:!0})},d=(e,r,t,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of a(r))!p.call(e,n)&&n!==t&&i(e,n,{get:()=>r[n],enumerable:!(o=c(r,n))||o.enumerable});return e};var x=e=>d(i({},"__esModule",{value:!0}),e);var A={};s(A,{extractPublicKey:()=>m,isDeviceGenuine:()=>E,isGetCertificateApdu:()=>f,willRequestPermission:()=>y});module.exports=x(A);var u=require("../apdu/utils/ApduParser"),l=require("../secure-channel/constants");function y(e){return e[0]===224&&e[1]===81}function f(e){return e[0]===224&&e[1]===82}function m(e){try{const r=new u.ApduParser(e);return r.extractFieldLVEncoded()?r.extractFieldLVEncoded()??null:null}catch{return null}}function E(e){return e===l.GENUINE_DEVICE_RESULT}0&&(module.exports={extractPublicKey,isDeviceGenuine,isGetCertificateApdu,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": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,0BAAAC,IAAA,eAAAC,EAAAJ,GACA,IAAAK,EAAsC,uBAU/B,SAASF,EAAsBG,EAA2B,CAC/D,OAAOA,EAAK,CAAC,IAAM,KAAQA,EAAK,CAAC,IAAM,EACzC,CASO,SAASJ,EAAgBK,EAA8C,CAC5E,OAAOA,IAAY,uBACrB",
6
- "names": ["utils_exports", "__export", "isDeviceGenuine", "willRequestPermission", "__toCommonJS", "import_constants", "apdu", "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": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,sBAAAE,EAAA,oBAAAC,EAAA,yBAAAC,EAAA,0BAAAC,IAAA,eAAAC,EAAAN,GAAA,IAAAO,EAA2B,sCAE3BC,EAAsC,yCAW/B,SAASH,EAAsBI,EAA2B,CAC/D,OAAOA,EAAK,CAAC,IAAM,KAAQA,EAAK,CAAC,IAAM,EACzC,CAUO,SAASL,EAAqBK,EAA2B,CAC9D,OAAOA,EAAK,CAAC,IAAM,KAAQA,EAAK,CAAC,IAAM,EACzC,CAQO,SAASP,EACdQ,EACmB,CACnB,GAAI,CACF,MAAMC,EAAS,IAAI,aAAWD,CAAY,EAI1C,OADeC,EAAO,sBAAsB,EAM1BA,EAAO,sBAAsB,GAC3B,KALX,IAMX,MAAiB,CACf,OAAO,IACT,CACF,CASO,SAASR,EAAgBS,EAA8C,CAC5E,OAAOA,IAAY,uBACrB",
6
+ "names": ["utils_exports", "__export", "extractPublicKey", "isDeviceGenuine", "isGetCertificateApdu", "willRequestPermission", "__toCommonJS", "import_ApduParser", "import_constants", "apdu", "apduResponse", "parser", "payload"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("./utils");describe("willRequestPermission",()=>{it("should return true if the APDU is a permission request",()=>{const i=new Uint8Array([224,81,0,0,0]);expect((0,e.willRequestPermission)(i)).toBe(!0)}),it("should return false if the APDU is not a permission request",()=>{const i=new Uint8Array([224,82,0,0,0]);expect((0,e.willRequestPermission)(i)).toBe(!1)})});describe("isDeviceGenuine",()=>{it("should return true if the device is genuine",()=>{expect((0,e.isDeviceGenuine)("0000")).toBe(!0)}),it("should return false if the device is not genuine",()=>{expect((0,e.isDeviceGenuine)("not genuine")).toBe(!1)})});
1
+ "use strict";var n=require("../device-session/ApduResponse"),e=require("./utils");describe("willRequestPermission",()=>{it("should return true if the APDU is a permission request",()=>{const x=new Uint8Array([224,81,0,0,0]);expect((0,e.willRequestPermission)(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((0,e.willRequestPermission)(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((0,e.isGetCertificateApdu)(x)).toBe(!0)}),it("should return true for GetCertificate with different P1 and P2",()=>{const x=new Uint8Array([224,82,128,1,0]);expect((0,e.isGetCertificateApdu)(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((0,e.isGetCertificateApdu)(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]),i=new n.ApduResponse({statusCode:new Uint8Array([144,0]),data:x}),t=(0,e.extractPublicKey)(i);expect(t).not.toBeNull(),expect(t?.length).toBe(65),expect(t?.[0]).toBe(4),expect(t?.[64]).toBe(81)}),it("should return null for invalid response with missing header",()=>{const x=new n.ApduResponse({statusCode:new Uint8Array([144,0]),data:new Uint8Array([])}),i=(0,e.extractPublicKey)(x);expect(i).toBeNull()}),it("should return null for invalid response with missing public key",()=>{const x=new Uint8Array([7,74,7,161,82,230,187,193]),i=new n.ApduResponse({statusCode:new Uint8Array([144,0]),data:x}),t=(0,e.extractPublicKey)(i);expect(t).toBeNull()})});describe("isDeviceGenuine",()=>{it("should return true if the device is genuine",()=>{expect((0,e.isDeviceGenuine)("0000")).toBe(!0)}),it("should return false if the device is not genuine",()=>{expect((0,e.isDeviceGenuine)("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,IAAAA,EAAuD,mBAEvD,SAAS,wBAAyB,IAAM,CACtC,GAAG,yDAA0D,IAAM,CACjE,MAAMC,EAAO,IAAI,WAAW,CAAC,IAAM,GAAM,EAAM,EAAM,CAAI,CAAC,EAC1D,UAAO,yBAAsBA,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,UAAO,yBAAsBA,CAAI,CAAC,EAAE,KAAK,EAAK,CAChD,CAAC,CACH,CAAC,EAED,SAAS,kBAAmB,IAAM,CAChC,GAAG,8CAA+C,IAAM,CAEtD,UAAO,mBADS,MACc,CAAC,EAAE,KAAK,EAAI,CAC5C,CAAC,EACD,GAAG,mDAAoD,IAAM,CAE3D,UAAO,mBADS,aACc,CAAC,EAAE,KAAK,EAAK,CAC7C,CAAC,CACH,CAAC",
6
- "names": ["import_utils", "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,IAAAA,EAA6B,4CAE7BC,EAKO,mBAEP,SAAS,wBAAyB,IAAM,CACtC,GAAG,yDAA0D,IAAM,CACjE,MAAMC,EAAO,IAAI,WAAW,CAAC,IAAM,GAAM,EAAM,EAAM,CAAI,CAAC,EAC1D,UAAO,yBAAsBA,CAAI,CAAC,EAAE,KAAK,EAAI,CAC/C,CAAC,EACD,GAAG,8DAA+D,IAAM,CACtE,M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SAAS,CAC7B,CAAC,CACH,CAAC,EAED,SAAS,kBAAmB,IAAM,CAChC,GAAG,8CAA+C,IAAM,CAEtD,UAAO,mBADS,MACc,CAAC,EAAE,KAAK,EAAI,CAC5C,CAAC,EACD,GAAG,mDAAoD,IAAM,CAE3D,UAAO,mBADS,aACc,CAAC,EAAE,KAAK,EAAK,CAC7C,CAAC,CACH,CAAC",
6
+ "names": ["import_ApduResponse", "import_utils", "apdu", "responseData", "response", "publicKey"]
7
7
  }
@@ -0,0 +1,2 @@
1
+ "use strict";var i=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var o=Object.prototype.hasOwnProperty;var p=(a,r,n,e)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of c(r))!o.call(a,t)&&t!==n&&i(a,t,{get:()=>r[t],enumerable:!(e=y(r,t))||e.enumerable});return a};var A=a=>p(i({},"__esModule",{value:!0}),a);var U={};module.exports=A(U);
2
+ //# sourceMappingURL=CryptoService.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/internal/crypto/CryptoService.ts"],
4
+ "sourcesContent": ["/**\n * Simple crypto service abstraction for hashing operations\n */\nexport interface CryptoService {\n /**\n * Compute SHA3-256 hash of the input data\n * @param data - The input data to hash\n * @returns The SHA3-256 hash as a Uint8Array (32 bytes)\n */\n sha3_256(data: Uint8Array): Uint8Array;\n}\n"],
5
+ "mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
6
+ "names": ["CryptoService_exports", "__toCommonJS"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var i=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var s=Object.prototype.hasOwnProperty;var c=(e,r)=>{for(var o in r)i(e,o,{get:r[o],enumerable:!0})},n=(e,r,o,p)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of a(r))!s.call(e,t)&&t!==o&&i(e,t,{get:()=>r[t],enumerable:!(p=y(r,t))||p.enumerable});return e};var l=e=>n(i({},"__esModule",{value:!0}),e);var C={};c(C,{NobleCryptoService:()=>v});module.exports=l(C);var m=require("@noble/hashes/sha3");class v{sha3_256(r){return(0,m.sha3_256)(r)}}0&&(module.exports={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": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,wBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAyB,8BAOlB,MAAMF,CAA4C,CACvD,SAASG,EAA8B,CACrC,SAAO,YAASA,CAAI,CACtB,CACF",
6
+ "names": ["NobleCryptoService_exports", "__export", "NobleCryptoService", "__toCommonJS", "import_sha3", "data"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var e=require("./NobleCryptoService");describe("NobleCryptoService",()=>{let x;beforeEach(()=>{x=new e.NobleCryptoService}),describe("sha3_256",()=>{it("should compute SHA3-256 hash",()=>{const r=new Uint8Array([1,2,3,4]),c=x.sha3_256(r);expect(c).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,IAAAA,EAAmC,gCAEnC,SAAS,qBAAsB,IAAM,CACnC,IAAIC,EAEJ,WAAW,IAAM,CACfA,EAAgB,IAAI,oBACtB,CAAC,EAED,SAAS,WAAY,IAAM,CACzB,GAAG,+BAAgC,IAAM,CACvC,MAAMC,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": ["import_NobleCryptoService", "cryptoService", "input", "hash"]
7
+ }
@@ -1,2 +1,2 @@
1
- "use strict";var n=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var _=(o,e)=>{for(var i in e)n(o,i,{get:e[i],enumerable:!0})},p=(o,e,i,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of m(e))!f.call(o,t)&&t!==i&&n(o,t,{get:()=>e[t],enumerable:!(s=h(e,t))||s.enumerable});return o};var D=o=>p(n({},"__esModule",{value:!0}),o),l=(o,e,i,s)=>{for(var t=s>1?void 0:s?h(e,i):e,g=o.length-1,d;g>=0;g--)(d=o[g])&&(t=(s?d(e,i,t):d(t))||t);return s&&t&&n(e,i,t),t},u=(o,e)=>(i,s)=>e(i,s,o);var y={};_(y,{DefaultDeviceSessionService:()=>r});module.exports=D(y);var c=require("inversify"),v=require("purify-ts"),S=require("rxjs"),a=require("../../device-session/model/Errors"),b=require("../../logger-publisher/di/loggerTypes");let r=class{_sessions;_logger;_sessionsSubject;constructor(e){this._sessions=[],this._sessionsSubject=new S.ReplaySubject,this._logger=e("DeviceSessionService")}get sessionsObs(){return this._sessionsSubject.asObservable()}addDeviceSession(e){return this._sessions.find(s=>s.id===e.id)?(this._logger.warn("DeviceSession already exists",{data:{deviceSession:e}}),this):(this._sessions.push(e),this._sessionsSubject.next(e),this._logger.info("DeviceSession added",{data:{sessionId:e.id}}),this)}removeDeviceSession(e){const i=this._sessions.find(s=>s.id===e);return i?(i.close(),this._sessions=this._sessions.filter(s=>s.id!==e),this._logger.info("DeviceSession removed",{data:{sessionId:e}}),this):(this._logger.warn("DeviceSession not found",{data:{sessionId:e}}),this)}getDeviceSessionById(e){return v.Maybe.fromNullable(this._sessions.find(s=>s.id===e)).toEither(new a.DeviceSessionNotFound)}getDeviceSessionByDeviceId(e){return v.Maybe.fromNullable(this._sessions.find(s=>s.connectedDevice.id===e)).toEither(new a.DeviceSessionNotFound)}getDeviceSessions(){return this._sessions}};r=l([(0,c.injectable)(),u(0,(0,c.inject)(b.loggerTypes.LoggerPublisherServiceFactory))],r);0&&(module.exports={DefaultDeviceSessionService});
1
+ "use strict";var n=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var f=(o,e)=>{for(var s in e)n(o,s,{get:e[s],enumerable:!0})},_=(o,e,s,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of D(e))!b.call(o,r)&&r!==s&&n(o,r,{get:()=>e[r],enumerable:!(i=S(e,r))||i.enumerable});return o};var p=o=>_(n({},"__esModule",{value:!0}),o),a=(o,e,s,i)=>{for(var r=i>1?void 0:i?S(e,s):e,v=o.length-1,h;v>=0;v--)(h=o[v])&&(r=(i?h(e,s,r):h(r))||r);return i&&r&&n(e,s,r),r},l=(o,e)=>(s,i)=>e(s,i,o);var y={};f(y,{DefaultDeviceSessionService:()=>t});module.exports=p(y);var c=require("inversify"),d=require("purify-ts"),u=require("rxjs"),g=require("../../device-session/model/Errors"),m=require("../../logger-publisher/di/loggerTypes");let t=class{_sessions;_sessionsSubject;_logger;constructor(e){this._sessions=[],this._sessionsSubject=new u.ReplaySubject,this._logger=e("DeviceSessionService")}get sessionsObs(){return this._sessionsSubject.asObservable()}addDeviceSession(e){return this._sessions.find(i=>i.id===e.id)?(this._logger.warn("DeviceSession already exists",{data:{deviceSession:e}}),this):(this._sessions.push(e),this._sessionsSubject.next(e),this._logger.info("DeviceSession added",{data:{sessionId:e.id}}),this)}removeDeviceSession(e){const s=this._sessions.find(i=>i.id===e);return s?(s.close(),this._sessions=this._sessions.filter(i=>i.id!==e),this._logger.info("DeviceSession removed",{data:{sessionId:e}}),this):(this._logger.warn("DeviceSession not found",{data:{sessionId:e}}),this)}getDeviceSessionById(e){return d.Maybe.fromNullable(this._sessions.find(s=>s.id===e)).toEither(new g.DeviceSessionNotFound)}getDeviceSessionsByDeviceId(e){return d.Maybe.fromPredicate(({length:s})=>s>0,this._sessions.filter(s=>s.connectedDevice.id===e)).toEither(new g.DeviceSessionNotFound)}getDeviceSessions(){return this._sessions}};t=a([(0,c.injectable)(),l(0,(0,c.inject)(m.loggerTypes.LoggerPublisherServiceFactory))],t);0&&(module.exports={DefaultDeviceSessionService});
2
2
  //# sourceMappingURL=DefaultDeviceSessionService.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/internal/device-session/service/DefaultDeviceSessionService.ts"],
4
- "sourcesContent": ["import { inject, injectable } from \"inversify\";\nimport { Maybe } from \"purify-ts\";\nimport { Observable, ReplaySubject } from \"rxjs\";\n\nimport { LoggerPublisherService } from \"@api/logger-publisher/service/LoggerPublisherService\";\nimport { DeviceSession } from \"@internal/device-session/model/DeviceSession\";\nimport { DeviceSessionNotFound } from \"@internal/device-session/model/Errors\";\nimport { DeviceSessionService } from \"@internal/device-session/service/DeviceSessionService\";\nimport { loggerTypes } from \"@internal/logger-publisher/di/loggerTypes\";\n\n@injectable()\nexport class DefaultDeviceSessionService implements DeviceSessionService {\n private _sessions: DeviceSession[];\n private readonly _logger: LoggerPublisherService;\n private _sessionsSubject: ReplaySubject<DeviceSession>;\n\n constructor(\n @inject(loggerTypes.LoggerPublisherServiceFactory)\n loggerModuleFactory: (tag: string) => LoggerPublisherService,\n ) {\n this._sessions = [];\n this._sessionsSubject = new ReplaySubject();\n this._logger = loggerModuleFactory(\"DeviceSessionService\");\n }\n\n public get sessionsObs(): Observable<DeviceSession> {\n return this._sessionsSubject.asObservable();\n }\n\n addDeviceSession(deviceSession: DeviceSession) {\n const found = this._sessions.find((s) => s.id === deviceSession.id);\n if (found) {\n this._logger.warn(\"DeviceSession already exists\", {\n data: { deviceSession },\n });\n return this;\n }\n\n this._sessions.push(deviceSession);\n this._sessionsSubject.next(deviceSession);\n this._logger.info(\"DeviceSession added\", {\n data: { sessionId: deviceSession.id },\n });\n return this;\n }\n\n removeDeviceSession(sessionId: string) {\n const found = this._sessions.find((s) => s.id === sessionId);\n if (found) {\n found.close();\n this._sessions = this._sessions.filter((s) => s.id !== sessionId);\n this._logger.info(\"DeviceSession removed\", { data: { sessionId } });\n return this;\n }\n\n this._logger.warn(\"DeviceSession not found\", { data: { sessionId } });\n return this;\n }\n\n getDeviceSessionById(sessionId: string) {\n const deviceSession = Maybe.fromNullable(\n this._sessions.find((s) => s.id === sessionId),\n );\n\n return deviceSession.toEither(new DeviceSessionNotFound());\n }\n\n getDeviceSessionByDeviceId(deviceId: string) {\n const deviceSession = Maybe.fromNullable(\n this._sessions.find((s) => s.connectedDevice.id === deviceId),\n );\n\n return deviceSession.toEither(new DeviceSessionNotFound());\n }\n\n getDeviceSessions() {\n return this._sessions;\n }\n}\n"],
5
- "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAmC,qBACnCC,EAAsB,qBACtBC,EAA0C,gBAI1CC,EAAsC,iDAEtCC,EAA4B,qDAGrB,IAAMC,EAAN,KAAkE,CAC/D,UACS,QACT,iBAER,YAEEC,EACA,CACA,KAAK,UAAY,CAAC,EAClB,KAAK,iBAAmB,IAAI,gBAC5B,KAAK,QAAUA,EAAoB,sBAAsB,CAC3D,CAEA,IAAW,aAAyC,CAClD,OAAO,KAAK,iBAAiB,aAAa,CAC5C,CAEA,iBAAiBC,EAA8B,CAE7C,OADc,KAAK,UAAU,KAAM,GAAM,EAAE,KAAOA,EAAc,EAAE,GAEhE,KAAK,QAAQ,KAAK,+BAAgC,CAChD,KAAM,CAAE,cAAAA,CAAc,CACxB,CAAC,EACM,OAGT,KAAK,UAAU,KAAKA,CAAa,EACjC,KAAK,iBAAiB,KAAKA,CAAa,EACxC,KAAK,QAAQ,KAAK,sBAAuB,CACvC,KAAM,CAAE,UAAWA,EAAc,EAAG,CACtC,CAAC,EACM,KACT,CAEA,oBAAoBC,EAAmB,CACrC,MAAMC,EAAQ,KAAK,UAAU,KAAM,GAAM,EAAE,KAAOD,CAAS,EAC3D,OAAIC,GACFA,EAAM,MAAM,EACZ,KAAK,UAAY,KAAK,UAAU,OAAQ,GAAM,EAAE,KAAOD,CAAS,EAChE,KAAK,QAAQ,KAAK,wBAAyB,CAAE,KAAM,CAAE,UAAAA,CAAU,CAAE,CAAC,EAC3D,OAGT,KAAK,QAAQ,KAAK,0BAA2B,CAAE,KAAM,CAAE,UAAAA,CAAU,CAAE,CAAC,EAC7D,KACT,CAEA,qBAAqBA,EAAmB,CAKtC,OAJsB,QAAM,aAC1B,KAAK,UAAU,KAAM,GAAM,EAAE,KAAOA,CAAS,CAC/C,EAEqB,SAAS,IAAI,uBAAuB,CAC3D,CAEA,2BAA2BE,EAAkB,CAK3C,OAJsB,QAAM,aAC1B,KAAK,UAAU,KAAM,GAAM,EAAE,gBAAgB,KAAOA,CAAQ,CAC9D,EAEqB,SAAS,IAAI,uBAAuB,CAC3D,CAEA,mBAAoB,CAClB,OAAO,KAAK,SACd,CACF,EAnEaL,EAANM,EAAA,IADN,cAAW,EAOPC,EAAA,eAAO,cAAY,6BAA6B,IANxCP",
6
- "names": ["DefaultDeviceSessionService_exports", "__export", "DefaultDeviceSessionService", "__toCommonJS", "import_inversify", "import_purify_ts", "import_rxjs", "import_Errors", "import_loggerTypes", "DefaultDeviceSessionService", "loggerModuleFactory", "deviceSession", "sessionId", "found", "deviceId", "__decorateClass", "__decorateParam"]
4
+ "sourcesContent": ["import { inject, injectable } from \"inversify\";\nimport { Either, Maybe } from \"purify-ts\";\nimport { Observable, ReplaySubject } from \"rxjs\";\n\nimport { LoggerPublisherService } from \"@api/logger-publisher/service/LoggerPublisherService\";\nimport { DeviceId } from \"@api/types\";\nimport { DeviceSession } from \"@internal/device-session/model/DeviceSession\";\nimport { DeviceSessionNotFound } from \"@internal/device-session/model/Errors\";\nimport { DeviceSessionService } from \"@internal/device-session/service/DeviceSessionService\";\nimport { loggerTypes } from \"@internal/logger-publisher/di/loggerTypes\";\n\n@injectable()\nexport class DefaultDeviceSessionService implements DeviceSessionService {\n private _sessions: DeviceSession[];\n private readonly _sessionsSubject: ReplaySubject<DeviceSession>;\n private readonly _logger: LoggerPublisherService;\n\n constructor(\n @inject(loggerTypes.LoggerPublisherServiceFactory)\n loggerModuleFactory: (tag: string) => LoggerPublisherService,\n ) {\n this._sessions = [];\n this._sessionsSubject = new ReplaySubject();\n this._logger = loggerModuleFactory(\"DeviceSessionService\");\n }\n\n public get sessionsObs(): Observable<DeviceSession> {\n return this._sessionsSubject.asObservable();\n }\n\n addDeviceSession(deviceSession: DeviceSession): DeviceSessionService {\n const found = this._sessions.find((s) => s.id === deviceSession.id);\n if (found) {\n this._logger.warn(\"DeviceSession already exists\", {\n data: { deviceSession },\n });\n return this;\n }\n this._sessions.push(deviceSession);\n this._sessionsSubject.next(deviceSession);\n this._logger.info(\"DeviceSession added\", {\n data: { sessionId: deviceSession.id },\n });\n return this;\n }\n\n removeDeviceSession(sessionId: string): DeviceSessionService {\n const found = this._sessions.find((s) => s.id === sessionId);\n if (found) {\n found.close();\n this._sessions = this._sessions.filter((s) => s.id !== sessionId);\n this._logger.info(\"DeviceSession removed\", { data: { sessionId } });\n return this;\n }\n this._logger.warn(\"DeviceSession not found\", { data: { sessionId } });\n return this;\n }\n\n getDeviceSessionById(\n sessionId: string,\n ): Either<DeviceSessionNotFound, DeviceSession> {\n return Maybe.fromNullable(\n this._sessions.find((s) => s.id === sessionId),\n ).toEither(new DeviceSessionNotFound());\n }\n\n getDeviceSessionsByDeviceId(\n deviceId: DeviceId,\n ): Either<DeviceSessionNotFound, DeviceSession[]> {\n return Maybe.fromPredicate(\n ({ length }) => length > 0,\n this._sessions.filter((s) => s.connectedDevice.id === deviceId),\n ).toEither(new DeviceSessionNotFound());\n }\n\n getDeviceSessions(): DeviceSession[] {\n return this._sessions;\n }\n}\n"],
5
+ "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAmC,qBACnCC,EAA8B,qBAC9BC,EAA0C,gBAK1CC,EAAsC,iDAEtCC,EAA4B,qDAGrB,IAAMC,EAAN,KAAkE,CAC/D,UACS,iBACA,QAEjB,YAEEC,EACA,CACA,KAAK,UAAY,CAAC,EAClB,KAAK,iBAAmB,IAAI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ceSessionService_exports", "__export", "DefaultDeviceSessionService", "__toCommonJS", "import_inversify", "import_purify_ts", "import_rxjs", "import_Errors", "import_loggerTypes", "DefaultDeviceSessionService", "loggerModuleFactory", "deviceSession", "s", "sessionId", "found", "deviceId", "length", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var r=require("purify-ts"),m=require("rxjs"),l=require("../../device-session/data/DeviceSessionRefresherConst"),v=require("../../device-session/model/DeviceSession.stub"),p=require("../../device-session/model/Errors"),D=require("../../logger-publisher/service/DefaultLoggerPublisherService"),f=require("../../manager-api/data/AxiosManagerApiDataSource"),g=require("../../manager-api/service/DefaultManagerApiService"),h=require("../../secure-channel/data/DefaultSecureChannelDataSource"),b=require("../../secure-channel/service/DefaultSecureChannelService"),E=require("./DefaultDeviceSessionService");vi.mock("@internal/logger-publisher/service/DefaultLoggerPublisherService");vi.mock("@internal/manager-api/data/AxiosManagerApiDataSource");let e,t,i,u,c,d,S;describe("DefaultDeviceSessionService",()=>{beforeEach(()=>{vi.restoreAllMocks(),t=new D.DefaultLoggerPublisherService([],"deviceSession"),e=new E.DefaultDeviceSessionService(()=>t),u=new f.AxiosManagerApiDataSource({}),c=new g.DefaultManagerApiService(u),d=new h.DefaultSecureChannelDataSource({}),S=new b.DefaultSecureChannelService(d),i=(0,v.deviceSessionStubBuilder)({},()=>t,c,S,l.DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS)}),afterEach(()=>{i.close()}),it("should have an empty sessions list",()=>{expect(e.getDeviceSessions()).toEqual([])}),it("should add a deviceSession",()=>{e.addDeviceSession(i),expect(e.getDeviceSessions()).toEqual([i])}),it("should not add a deviceSession if it already exists",()=>{e.addDeviceSession(i),e.addDeviceSession(i),expect(e.getDeviceSessions()).toEqual([i])}),it("should remove a deviceSession",()=>{e.addDeviceSession(i),e.removeDeviceSession(i.id),expect(e.getDeviceSessions()).toEqual([])}),it("should not remove a deviceSession if it does not exist",()=>{e.removeDeviceSession(i.id),expect(e.getDeviceSessions()).toEqual([])}),it("should get a deviceSession",()=>{e.addDeviceSession(i),expect(e.getDeviceSessionById(i.id)).toEqual(r.Either.of(i))}),it("should not get a deviceSession if it does not exist",()=>{expect(e.getDeviceSessionById(i.id)).toEqual((0,r.Left)(new p.DeviceSessionNotFound))}),it("should get all sessions",()=>{e.addDeviceSession(i),expect(e.getDeviceSessions()).toEqual([i])}),it("should retrieve sessionObs",()=>{expect(e.sessionsObs).toBeInstanceOf(m.Observable)}),it("should emit new session",()=>new Promise((s,o)=>{const n=e.sessionsObs.subscribe({next(a){try{expect(a).toStrictEqual(i),n.unsubscribe(),s()}catch(x){o(x)}}});e.addDeviceSession(i)})),it("should emit previous added session",()=>{const s=(0,v.deviceSessionStubBuilder)({id:"last-session"},()=>t,c,S,l.DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS),o=[];e.addDeviceSession(i),e.addDeviceSession(s);const n=e.sessionsObs.subscribe({next(a){o.push(a)}});s.close(),expect(o).toEqual([i,s]),n.unsubscribe()})});
1
+ "use strict";var s=require("purify-ts"),f=require("rxjs"),u=require("../../../api/transport/model/TransportConnectedDevice.stub"),r=require("../../device-session/data/DeviceSessionRefresherConst"),a=require("../../device-session/model/DeviceSession.stub"),p=require("../../device-session/model/Errors"),h=require("../../logger-publisher/service/DefaultLoggerPublisherService"),b=require("../../manager-api/data/AxiosManagerApiDataSource"),x=require("../../manager-api/service/DefaultManagerApiService"),E=require("../../secure-channel/data/DefaultSecureChannelDataSource"),y=require("../../secure-channel/service/DefaultSecureChannelService"),I=require("./DefaultDeviceSessionService");vi.mock("@internal/logger-publisher/service/DefaultLoggerPublisherService");vi.mock("@internal/manager-api/data/AxiosManagerApiDataSource");let e,o,i,d,S,m,c,g,n;describe("DefaultDeviceSessionService",()=>{o=new h.DefaultLoggerPublisherService([],"deviceSession"),m=new b.AxiosManagerApiDataSource({}),c=new x.DefaultManagerApiService(m),g=new E.DefaultSecureChannelDataSource({}),n=new y.DefaultSecureChannelService(g),beforeEach(()=>{vi.restoreAllMocks(),e=new I.DefaultDeviceSessionService(()=>o),i=(0,a.deviceSessionStubBuilder)({},()=>o,c,n,r.DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS)}),afterEach(()=>{i.close()}),it("should have an empty DeviceSession list",()=>{expect(e.getDeviceSessions()).toEqual([])}),describe("DeviceSessionService addDeviceSession",()=>{it("should add a DeviceSession if it does not already exist",()=>{e.addDeviceSession(i),expect(e.getDeviceSessions()).toEqual([i])}),it("should not add a DeviceSession if it already exists",()=>{e.addDeviceSession(i),e.addDeviceSession(i),expect(e.getDeviceSessions()).toEqual([i])})}),describe("DeviceSessionService removeDeviceSession",()=>{it("should remove the DeviceSession of given ID",()=>{e.addDeviceSession(i),e.removeDeviceSession(i.id),expect(e.getDeviceSessions()).toEqual([])}),it("should not remove the DeviceSession of given ID if it does not exist",()=>{e.addDeviceSession(i),e.removeDeviceSession("non-existent-id"),expect(e.getDeviceSessions()).toEqual([i])})}),describe("DeviceSessionService getDeviceSessionById",()=>{it("should get the DeviceSession of given ID if it exists",()=>{e.addDeviceSession(i),expect(e.getDeviceSessionById(i.id)).toEqual(s.Either.of(i))}),it("should not get the DeviceSession if it does not exist",()=>{e.addDeviceSession(i),expect(e.getDeviceSessionById("non-existent-id")).toEqual((0,s.Left)(new p.DeviceSessionNotFound))})}),describe("DeviceSessionService getDeviceSessionsByDeviceId",()=>{it("should not get device sessions by deviceId if none exist",()=>{e.addDeviceSession(i),expect(e.getDeviceSessionsByDeviceId("non-existent-device-id")).toEqual((0,s.Left)(new p.DeviceSessionNotFound))}),it("should get a single device session by deviceId",()=>{e.addDeviceSession(i),expect(e.getDeviceSessionsByDeviceId(i.connectedDevice.id)).toEqual(s.Either.of([i]))}),it("should get device sessions by deviceId",()=>{e.addDeviceSession(i),d=(0,a.deviceSessionStubBuilder)({connectedDevice:(0,u.connectedDeviceStubBuilder)({id:"device-1"}),id:"session-1"},()=>o,c,n,r.DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS),S=(0,a.deviceSessionStubBuilder)({connectedDevice:(0,u.connectedDeviceStubBuilder)({id:"device-1"}),id:"session-2"},()=>o,c,n,r.DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS),e.addDeviceSession(d),e.addDeviceSession(S),expect(e.getDeviceSessionsByDeviceId("device-1")).toEqual(s.Either.of([d,S])),d.close(),S.close()})}),it("should get all sessions",()=>{e.addDeviceSession(i),expect(e.getDeviceSessions()).toEqual([i])}),it("should retrieve sessionObs",()=>{expect(e.sessionsObs).toBeInstanceOf(f.Observable)}),it("should emit new session",()=>new Promise((t,v)=>{const D=e.sessionsObs.subscribe({next(l){try{expect(l).toStrictEqual(i),D.unsubscribe(),t()}catch(A){v(A)}}});e.addDeviceSession(i)})),it("should emit previous added session",()=>{const t=(0,a.deviceSessionStubBuilder)({id:"last-session"},()=>o,c,n,r.DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS),v=[];e.addDeviceSession(i),e.addDeviceSession(t);const D=e.sessionsObs.subscribe({next(l){v.push(l)}});t.close(),expect(v).toEqual([i,t]),D.unsubscribe()})});
2
2
  //# sourceMappingURL=DefaultDeviceSessionService.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/internal/device-session/service/DefaultDeviceSessionService.test.ts"],
4
- "sourcesContent": ["import { Either, Left } from \"purify-ts\";\nimport { Observable } from \"rxjs\";\n\nimport { type DmkConfig } from \"@api/DmkConfig\";\nimport { DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS } from \"@internal/device-session/data/DeviceSessionRefresherConst\";\nimport { type DeviceSession } from \"@internal/device-session/model/DeviceSession\";\nimport { deviceSessionStubBuilder } from \"@internal/device-session/model/DeviceSession.stub\";\nimport { DeviceSessionNotFound } from \"@internal/device-session/model/Errors\";\nimport { DefaultLoggerPublisherService } from \"@internal/logger-publisher/service/DefaultLoggerPublisherService\";\nimport { AxiosManagerApiDataSource } from \"@internal/manager-api/data/AxiosManagerApiDataSource\";\nimport { type ManagerApiDataSource } from \"@internal/manager-api/data/ManagerApiDataSource\";\nimport { DefaultManagerApiService } from \"@internal/manager-api/service/DefaultManagerApiService\";\nimport type { ManagerApiService } from \"@internal/manager-api/service/ManagerApiService\";\nimport { DefaultSecureChannelDataSource } from \"@internal/secure-channel/data/DefaultSecureChannelDataSource\";\nimport { type SecureChannelDataSource } from \"@internal/secure-channel/data/SecureChannelDataSource\";\nimport { DefaultSecureChannelService } from \"@internal/secure-channel/service/DefaultSecureChannelService\";\nimport { type SecureChannelService } from \"@internal/secure-channel/service/SecureChannelService\";\n\nimport { DefaultDeviceSessionService } from \"./DefaultDeviceSessionService\";\n\nvi.mock(\"@internal/logger-publisher/service/DefaultLoggerPublisherService\");\nvi.mock(\"@internal/manager-api/data/AxiosManagerApiDataSource\");\n\nlet sessionService: DefaultDeviceSessionService;\nlet loggerService: DefaultLoggerPublisherService;\nlet deviceSession: DeviceSession;\nlet managerApiDataSource: ManagerApiDataSource;\nlet managerApi: ManagerApiService;\nlet secureChannelDataSource: SecureChannelDataSource;\nlet secureChannel: SecureChannelService;\n\ndescribe(\"DefaultDeviceSessionService\", () => {\n beforeEach(() => {\n vi.restoreAllMocks();\n loggerService = new DefaultLoggerPublisherService([], \"deviceSession\");\n sessionService = new DefaultDeviceSessionService(() => loggerService);\n managerApiDataSource = new AxiosManagerApiDataSource({} as DmkConfig);\n managerApi = new DefaultManagerApiService(managerApiDataSource);\n secureChannelDataSource = new DefaultSecureChannelDataSource(\n {} as DmkConfig,\n );\n secureChannel = new DefaultSecureChannelService(secureChannelDataSource);\n\n deviceSession = deviceSessionStubBuilder(\n {},\n () => loggerService,\n managerApi,\n secureChannel,\n DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS,\n );\n });\n\n afterEach(() => {\n deviceSession.close();\n });\n\n it(\"should have an empty sessions list\", () => {\n expect(sessionService.getDeviceSessions()).toEqual([]);\n });\n\n it(\"should add a deviceSession\", () => {\n sessionService.addDeviceSession(deviceSession);\n expect(sessionService.getDeviceSessions()).toEqual([deviceSession]);\n });\n\n it(\"should not add a deviceSession if it already exists\", () => {\n sessionService.addDeviceSession(deviceSession);\n sessionService.addDeviceSession(deviceSession);\n expect(sessionService.getDeviceSessions()).toEqual([deviceSession]);\n });\n\n it(\"should remove a deviceSession\", () => {\n sessionService.addDeviceSession(deviceSession);\n sessionService.removeDeviceSession(deviceSession.id);\n expect(sessionService.getDeviceSessions()).toEqual([]);\n });\n\n it(\"should not remove a deviceSession if it does not exist\", () => {\n sessionService.removeDeviceSession(deviceSession.id);\n expect(sessionService.getDeviceSessions()).toEqual([]);\n });\n\n it(\"should get a deviceSession\", () => {\n sessionService.addDeviceSession(deviceSession);\n expect(sessionService.getDeviceSessionById(deviceSession.id)).toEqual(\n Either.of(deviceSession),\n );\n });\n\n it(\"should not get a deviceSession if it does not exist\", () => {\n expect(sessionService.getDeviceSessionById(deviceSession.id)).toEqual(\n Left(new DeviceSessionNotFound()),\n );\n });\n\n it(\"should get all sessions\", () => {\n sessionService.addDeviceSession(deviceSession);\n expect(sessionService.getDeviceSessions()).toEqual([deviceSession]);\n });\n\n it(\"should retrieve sessionObs\", () => {\n expect(sessionService.sessionsObs).toBeInstanceOf(\n Observable<DeviceSession>,\n );\n });\n\n it(\"should emit new session\", () =>\n new Promise<void>((resolve, reject) => {\n const subscription = sessionService.sessionsObs.subscribe({\n next(emittedDeviceSession) {\n try {\n expect(emittedDeviceSession).toStrictEqual(deviceSession);\n subscription.unsubscribe();\n resolve();\n } catch (error) {\n reject(error);\n }\n },\n });\n sessionService.addDeviceSession(deviceSession);\n }));\n\n it(\"should emit previous added session\", () => {\n const lastDeviceSession = deviceSessionStubBuilder(\n { id: \"last-session\" },\n () => loggerService,\n managerApi,\n secureChannel,\n DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS,\n );\n const emittedSessions: DeviceSession[] = [];\n sessionService.addDeviceSession(deviceSession);\n sessionService.addDeviceSession(lastDeviceSession);\n\n const subscription = sessionService.sessionsObs.subscribe({\n next(emittedDeviceSession) {\n emittedSessions.push(emittedDeviceSession);\n },\n });\n lastDeviceSession.close();\n expect(emittedSessions).toEqual([deviceSession, lastDeviceSession]);\n subscription.unsubscribe();\n });\n});\n"],
5
- "mappings": "aAAA,IAAAA,EAA6B,qBAC7BC,EAA2B,gBAG3BC,EAAyD,qEAEzDC,EAAyC,6DACzCC,EAAsC,iDACtCC,EAA8C,4EAC9CC,EAA0C,gEAE1CC,EAAyC,kEAEzCC,EAA+C,wEAE/CC,EAA4C,wEAG5CC,EAA4C,yCAE5C,GAAG,KAAK,kEAAkE,EAC1E,GAAG,KAAK,sDAAsD,EAE9D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,SAAS,8BAA+B,IAAM,CAC5C,WAAW,IAAM,CACf,GAAG,gBAAgB,EACnBL,EAAgB,IAAI,gCAA8B,CAAC,EAAG,eAAe,EACrED,EAAiB,IAAI,8BAA4B,IAAMC,CAAa,EACpEE,EAAuB,IAAI,4BAA0B,CAAC,CAAc,EACpEC,EAAa,IAAI,2BAAyBD,CAAoB,EAC9DE,EAA0B,IAAI,iCAC5B,CAAC,CACH,EACAC,EAAgB,IAAI,8BAA4BD,CAAuB,EAEvEH,KAAgB,4BACd,CAAC,EACD,IAAMD,EACNG,EACAE,EACA,0CACF,CACF,CAAC,EAED,UAAU,IAAM,CACdJ,EAAc,MAAM,CACtB,CAAC,EAED,GAAG,qCAAsC,IAAM,CAC7C,OAAOF,EAAe,kBAAkB,CAAC,EAAE,QAAQ,CAAC,CAAC,CACvD,CAAC,EAED,GAAG,6BAA8B,IAAM,CACrCA,EAAe,iBAAiBE,CAAa,EAC7C,OAAOF,EAAe,kBAAkB,CAAC,EAAE,QAAQ,CAACE,CAAa,CAAC,CACpE,CAAC,EAED,GAAG,sDAAuD,IAAM,CAC9DF,EAAe,iBAAiBE,CAAa,EAC7CF,EAAe,iBAAiBE,CAAa,EAC7C,OAAOF,EAA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NG,EACAE,EACA,0CACF,EACMO,EAAmC,CAAC,EAC1Cb,EAAe,iBAAiBE,CAAa,EAC7CF,EAAe,iBAAiBY,CAAiB,EAEjD,MAAMH,EAAeT,EAAe,YAAY,UAAU,CACxD,KAAKU,EAAsB,CACzBG,EAAgB,KAAKH,CAAoB,CAC3C,CACF,CAAC,EACDE,EAAkB,MAAM,EACxB,OAAOC,CAAe,EAAE,QAAQ,CAACX,EAAeU,CAAiB,CAAC,EAClEH,EAAa,YAAY,CAC3B,CAAC,CACH,CAAC",
6
- "names": ["import_purify_ts", "import_rxjs", "import_DeviceSessionRefresherConst", "import_DeviceSession", "import_Errors", "import_DefaultLoggerPublisherService", "import_AxiosManagerApiDataSource", "import_DefaultManagerApiService", "import_DefaultSecureChannelDataSource", "import_DefaultSecureChannelService", "import_DefaultDeviceSessionService", "sessionService", "loggerService", "deviceSession", "managerApiDataSource", "managerApi", "secureChannelDataSource", "secureChannel", "resolve", "reject", "subscription", "emittedDeviceSession", "error", "lastDeviceSession", "emittedSessions"]
4
+ "sourcesContent": ["import { Either, Left } from \"purify-ts\";\nimport { Observable } from \"rxjs\";\n\nimport { type DmkConfig } from \"@api/DmkConfig\";\nimport { connectedDeviceStubBuilder } from \"@api/transport/model/TransportConnectedDevice.stub\";\nimport { DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS } from \"@internal/device-session/data/DeviceSessionRefresherConst\";\nimport { type DeviceSession } from \"@internal/device-session/model/DeviceSession\";\nimport { deviceSessionStubBuilder } from \"@internal/device-session/model/DeviceSession.stub\";\nimport { DeviceSessionNotFound } from \"@internal/device-session/model/Errors\";\nimport { DefaultLoggerPublisherService } from \"@internal/logger-publisher/service/DefaultLoggerPublisherService\";\nimport { AxiosManagerApiDataSource } from \"@internal/manager-api/data/AxiosManagerApiDataSource\";\nimport { type ManagerApiDataSource } from \"@internal/manager-api/data/ManagerApiDataSource\";\nimport { DefaultManagerApiService } from \"@internal/manager-api/service/DefaultManagerApiService\";\nimport type { ManagerApiService } from \"@internal/manager-api/service/ManagerApiService\";\nimport { DefaultSecureChannelDataSource } from \"@internal/secure-channel/data/DefaultSecureChannelDataSource\";\nimport { type SecureChannelDataSource } from \"@internal/secure-channel/data/SecureChannelDataSource\";\nimport { DefaultSecureChannelService } from \"@internal/secure-channel/service/DefaultSecureChannelService\";\nimport { type SecureChannelService } from \"@internal/secure-channel/service/SecureChannelService\";\n\nimport { DefaultDeviceSessionService } from \"./DefaultDeviceSessionService\";\n\nvi.mock(\"@internal/logger-publisher/service/DefaultLoggerPublisherService\");\nvi.mock(\"@internal/manager-api/data/AxiosManagerApiDataSource\");\n\nlet sessionService: DefaultDeviceSessionService;\nlet loggerService: DefaultLoggerPublisherService;\nlet deviceSession: DeviceSession;\nlet deviceSession1: DeviceSession;\nlet deviceSession2: DeviceSession;\nlet managerApiDataSource: ManagerApiDataSource;\nlet managerApi: ManagerApiService;\nlet secureChannelDataSource: SecureChannelDataSource;\nlet secureChannel: SecureChannelService;\n\ndescribe(\"DefaultDeviceSessionService\", () => {\n // Initialize shared resources\n loggerService = new DefaultLoggerPublisherService([], \"deviceSession\");\n managerApiDataSource = new AxiosManagerApiDataSource({} as DmkConfig);\n managerApi = new DefaultManagerApiService(managerApiDataSource);\n secureChannelDataSource = new DefaultSecureChannelDataSource({} as DmkConfig);\n secureChannel = new DefaultSecureChannelService(secureChannelDataSource);\n\n beforeEach(() => {\n vi.restoreAllMocks();\n // Create a new instance before each test\n sessionService = new DefaultDeviceSessionService(() => loggerService);\n // Create a device session stub with default properties\n deviceSession = deviceSessionStubBuilder(\n {},\n () => loggerService,\n managerApi,\n secureChannel,\n DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS,\n );\n });\n\n afterEach(() => {\n deviceSession.close();\n });\n\n it(\"should have an empty DeviceSession list\", () => {\n expect(sessionService.getDeviceSessions()).toEqual([]);\n });\n\n describe(\"DeviceSessionService addDeviceSession\", () => {\n it(\"should add a DeviceSession if it does not already exist\", () => {\n sessionService.addDeviceSession(deviceSession);\n expect(sessionService.getDeviceSessions()).toEqual([deviceSession]);\n });\n it(\"should not add a DeviceSession if it already exists\", () => {\n sessionService.addDeviceSession(deviceSession);\n sessionService.addDeviceSession(deviceSession);\n expect(sessionService.getDeviceSessions()).toEqual([deviceSession]);\n });\n });\n\n describe(\"DeviceSessionService removeDeviceSession\", () => {\n it(\"should remove the DeviceSession of given ID\", () => {\n sessionService.addDeviceSession(deviceSession);\n sessionService.removeDeviceSession(deviceSession.id);\n expect(sessionService.getDeviceSessions()).toEqual([]);\n });\n it(\"should not remove the DeviceSession of given ID if it does not exist\", () => {\n sessionService.addDeviceSession(deviceSession);\n sessionService.removeDeviceSession(\"non-existent-id\");\n expect(sessionService.getDeviceSessions()).toEqual([deviceSession]);\n });\n });\n\n describe(\"DeviceSessionService getDeviceSessionById\", () => {\n it(\"should get the DeviceSession of given ID if it exists\", () => {\n sessionService.addDeviceSession(deviceSession);\n expect(sessionService.getDeviceSessionById(deviceSession.id)).toEqual(\n Either.of(deviceSession),\n );\n });\n it(\"should not get the DeviceSession if it does not exist\", () => {\n sessionService.addDeviceSession(deviceSession);\n expect(sessionService.getDeviceSessionById(\"non-existent-id\")).toEqual(\n Left(new DeviceSessionNotFound()),\n );\n });\n });\n\n describe(\"DeviceSessionService getDeviceSessionsByDeviceId\", () => {\n it(\"should not get device sessions by deviceId if none exist\", () => {\n sessionService.addDeviceSession(deviceSession);\n expect(\n sessionService.getDeviceSessionsByDeviceId(\"non-existent-device-id\"),\n ).toEqual(Left(new DeviceSessionNotFound()));\n });\n it(\"should get a single device session by deviceId\", () => {\n sessionService.addDeviceSession(deviceSession);\n expect(\n sessionService.getDeviceSessionsByDeviceId(\n deviceSession.connectedDevice.id,\n ),\n ).toEqual(Either.of([deviceSession]));\n });\n it(\"should get device sessions by deviceId\", () => {\n sessionService.addDeviceSession(deviceSession);\n deviceSession1 = deviceSessionStubBuilder(\n {\n connectedDevice: connectedDeviceStubBuilder({ id: \"device-1\" }),\n id: \"session-1\",\n },\n () => loggerService,\n managerApi,\n secureChannel,\n DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS,\n );\n\n deviceSession2 = deviceSessionStubBuilder(\n {\n connectedDevice: connectedDeviceStubBuilder({ id: \"device-1\" }),\n id: \"session-2\",\n },\n () => loggerService,\n managerApi,\n secureChannel,\n DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS,\n );\n sessionService.addDeviceSession(deviceSession1);\n sessionService.addDeviceSession(deviceSession2);\n expect(sessionService.getDeviceSessionsByDeviceId(\"device-1\")).toEqual(\n Either.of([deviceSession1, deviceSession2]),\n );\n deviceSession1.close();\n deviceSession2.close();\n });\n });\n\n it(\"should get all sessions\", () => {\n sessionService.addDeviceSession(deviceSession);\n expect(sessionService.getDeviceSessions()).toEqual([deviceSession]);\n });\n\n it(\"should retrieve sessionObs\", () => {\n expect(sessionService.sessionsObs).toBeInstanceOf(\n Observable<DeviceSession>,\n );\n });\n\n it(\"should emit new session\", () =>\n new Promise<void>((resolve, reject) => {\n const subscription = sessionService.sessionsObs.subscribe({\n next(emittedDeviceSession) {\n try {\n expect(emittedDeviceSession).toStrictEqual(deviceSession);\n subscription.unsubscribe();\n resolve();\n } catch (error) {\n reject(error);\n }\n },\n });\n sessionService.addDeviceSession(deviceSession);\n }));\n\n it(\"should emit previous added session\", () => {\n const lastDeviceSession = deviceSessionStubBuilder(\n { id: \"last-session\" },\n () => loggerService,\n managerApi,\n secureChannel,\n DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS,\n );\n const emittedSessions: DeviceSession[] = [];\n sessionService.addDeviceSession(deviceSession);\n sessionService.addDeviceSession(lastDeviceSession);\n\n const subscription = sessionService.sessionsObs.subscribe({\n next(emittedDeviceSession) {\n emittedSessions.push(emittedDeviceSession);\n },\n });\n lastDeviceSession.close();\n expect(emittedSessions).toEqual([deviceSession, lastDeviceSession]);\n subscription.unsubscribe();\n });\n});\n"],
5
+ "mappings": "aAAA,IAAAA,EAA6B,qBAC7BC,E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", "import_DeviceSessionRefresherConst", "import_DeviceSession", "import_Errors", "import_DefaultLoggerPublisherService", "import_AxiosManagerApiDataSource", "import_DefaultManagerApiService", "import_DefaultSecureChannelDataSource", "import_DefaultSecureChannelService", "import_DefaultDeviceSessionService", "sessionService", "loggerService", "deviceSession", "deviceSession1", "deviceSession2", "managerApiDataSource", "managerApi", "secureChannelDataSource", "secureChannel", "resolve", "reject", "subscription", "emittedDeviceSession", "error", "lastDeviceSession", "emittedSessions"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var r=Object.defineProperty;var n=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var t=Object.prototype.hasOwnProperty;var D=(i,e,v,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of c(e))!t.call(i,s)&&s!==v&&r(i,s,{get:()=>e[s],enumerable:!(o=n(e,s))||o.enumerable});return i};var S=i=>D(r({},"__esModule",{value:!0}),i);var m={};module.exports=S(m);
1
+ "use strict";var r=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var n=Object.getOwnPropertyNames;var t=Object.prototype.hasOwnProperty;var D=(i,e,v,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of n(e))!t.call(i,s)&&s!==v&&r(i,s,{get:()=>e[s],enumerable:!(o=c(e,s))||o.enumerable});return i};var S=i=>D(r({},"__esModule",{value:!0}),i);var m={};module.exports=S(m);
2
2
  //# sourceMappingURL=DeviceSessionService.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/internal/device-session/service/DeviceSessionService.ts"],
4
- "sourcesContent": ["import { type Either } from \"purify-ts\";\nimport { type Observable } from \"rxjs\";\n\nimport { type DmkError } from \"@api/Error\";\nimport { type DeviceSession } from \"@internal/device-session/model/DeviceSession\";\n\nexport interface DeviceSessionService {\n addDeviceSession(deviceSession: DeviceSession): DeviceSessionService;\n getDeviceSessionById(sessionId: string): Either<DmkError, DeviceSession>;\n getDeviceSessionByDeviceId(deviceId: string): Either<DmkError, DeviceSession>;\n removeDeviceSession(sessionId: string): DeviceSessionService;\n getDeviceSessions(): DeviceSession[];\n get sessionsObs(): Observable<DeviceSession>;\n}\n"],
4
+ "sourcesContent": ["import { type Either } from \"purify-ts\";\nimport { type Observable } from \"rxjs\";\n\nimport { type DmkError } from \"@api/Error\";\nimport { type DeviceId } from \"@api/types\";\nimport { type DeviceSession } from \"@internal/device-session/model/DeviceSession\";\n\nexport interface DeviceSessionService {\n /**\n * Add a device session.\n * @param deviceSession The device session to add.\n */\n addDeviceSession(deviceSession: DeviceSession): DeviceSessionService;\n\n /**\n * Get a device session by its ID.\n * @param sessionId The ID of the session to retrieve.\n * @returns The device session or an error if not found.\n */\n getDeviceSessionById(sessionId: string): Either<DmkError, DeviceSession>;\n\n /**\n * Get device sessions by device ID.\n * @param deviceId The ID of the device.\n * @returns The device sessions of the device or an error if not found.\n */\n getDeviceSessionsByDeviceId(\n deviceId: DeviceId,\n ): Either<DmkError, DeviceSession[]>;\n\n /**\n * Remove a device session by its ID.\n * @param sessionId The ID of the session to remove.\n */\n removeDeviceSession(sessionId: string): DeviceSessionService;\n\n /**\n * Get all device sessions.\n * @returns An array of device sessions.\n */\n getDeviceSessions(): DeviceSession[];\n\n /**\n * Get an observable of device sessions.\n * @returns An observable of device sessions.\n */\n get sessionsObs(): Observable<DeviceSession>;\n}\n"],
5
5
  "mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
6
6
  "names": ["DeviceSessionService_exports", "__toCommonJS"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var p=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var C=(n,e)=>{for(var s in e)p(n,s,{get:e[s],enumerable:!0})},T=(n,e,s,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of _(e))!A.call(n,r)&&r!==s&&p(n,r,{get:()=>e[r],enumerable:!(i=S(e,r))||i.enumerable});return n};var I=n=>T(p({},"__esModule",{value:!0}),n),m=(n,e,s,i)=>{for(var r=i>1?void 0:i?S(e,s):e,o=n.length-1,t;o>=0;o--)(t=n[o])&&(r=(i?t(e,s,r):t(r))||r);return i&&r&&p(e,s,r),r},a=(n,e)=>(s,i)=>e(s,i,n);var E={};C(E,{ConnectUseCase:()=>v});module.exports=I(E);var c=require("inversify"),g=require("purify-ts"),h=require("../../../api/transport/model/Errors"),d=require("../../device-session/di/deviceSessionTypes"),l=require("../../device-session/model/DeviceSession"),D=require("../../logger-publisher/di/loggerTypes"),f=require("../../manager-api/di/managerApiTypes"),y=require("../../secure-channel/di/secureChannelTypes"),u=require("../../transport/di/transportDiTypes");let v=class{_transportService;_sessionService;_loggerFactory;_managerApi;_secureChannel;_logger;constructor(e,s,i,r,o){this._sessionService=s,this._transportService=e,this._loggerFactory=i,this._logger=i("ConnectUseCase"),this._managerApi=r,this._secureChannel=o}handleDeviceDisconnect(e){this._sessionService.getDeviceSessionByDeviceId(e).map(i=>{this._sessionService.removeDeviceSession(i.id)})}async execute({device:e,sessionRefresherOptions:s}){const i=this._transportService.getTransport(e.transport),r="sessionId"in e?e.sessionId:void 0;return g.EitherAsync.liftEither(i.toEither(new h.TransportNotSupportedError(new Error("Unknown transport")))).chain(async o=>o.connect({deviceId:e.id,onDisconnect:t=>this.handleDeviceDisconnect(t)})).ifLeft(o=>{this._logger.error("Error connecting to device",{data:{deviceId:e.id,error:o}})}).map(async o=>{const t=new l.DeviceSession({connectedDevice:o,id:r},this._loggerFactory,this._managerApi,this._secureChannel,s);return this._sessionService.addDeviceSession(t),await t.initialiseSession(),t.id}).caseOf({Left:o=>{throw o},Right:o=>o})}};v=m([(0,c.injectable)(),a(0,(0,c.inject)(u.transportDiTypes.TransportService)),a(1,(0,c.inject)(d.deviceSessionTypes.DeviceSessionService)),a(2,(0,c.inject)(D.loggerTypes.LoggerPublisherServiceFactory)),a(3,(0,c.inject)(f.managerApiTypes.ManagerApiService)),a(4,(0,c.inject)(y.secureChannelTypes.SecureChannelService))],v);0&&(module.exports={ConnectUseCase});
1
+ "use strict";var p=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var C=(n,e)=>{for(var s in e)p(n,s,{get:e[s],enumerable:!0})},T=(n,e,s,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of _(e))!A.call(n,i)&&i!==s&&p(n,i,{get:()=>e[i],enumerable:!(r=S(e,i))||r.enumerable});return n};var I=n=>T(p({},"__esModule",{value:!0}),n),g=(n,e,s,r)=>{for(var i=r>1?void 0:r?S(e,s):e,o=n.length-1,t;o>=0;o--)(t=n[o])&&(i=(r?t(e,s,i):t(i))||i);return r&&i&&p(e,s,i),i},a=(n,e)=>(s,r)=>e(s,r,n);var E={};C(E,{ConnectUseCase:()=>v});module.exports=I(E);var c=require("inversify"),m=require("purify-ts"),h=require("../../../api/transport/model/Errors"),d=require("../../device-session/di/deviceSessionTypes"),l=require("../../device-session/model/DeviceSession"),f=require("../../logger-publisher/di/loggerTypes"),D=require("../../manager-api/di/managerApiTypes"),y=require("../../secure-channel/di/secureChannelTypes"),u=require("../../transport/di/transportDiTypes");let v=class{_transportService;_sessionService;_loggerFactory;_managerApi;_secureChannel;_logger;constructor(e,s,r,i,o){this._sessionService=s,this._transportService=e,this._loggerFactory=r,this._logger=r("ConnectUseCase"),this._managerApi=i,this._secureChannel=o}handleDeviceDisconnect(e){this._sessionService.getDeviceSessionsByDeviceId(e).ifRight(s=>{s.forEach(r=>{this._sessionService.removeDeviceSession(r.id),this._logger.info("Session removed",{data:{deviceId:e,sessionId:r.id}})})})}async execute({device:e,sessionRefresherOptions:s}){const r=this._transportService.getTransport(e.transport),i="sessionId"in e?e.sessionId:void 0;return m.EitherAsync.liftEither(r.toEither(new h.TransportNotSupportedError(new Error("Unknown transport")))).chain(async o=>o.connect({deviceId:e.id,onDisconnect:t=>this.handleDeviceDisconnect(t)})).ifLeft(o=>{this._logger.error("Error connecting to device",{data:{deviceId:e.id,error:o}})}).map(async o=>{const t=new l.DeviceSession({connectedDevice:o,id:i},this._loggerFactory,this._managerApi,this._secureChannel,s);return this._sessionService.addDeviceSession(t),await t.initialiseSession(),t.id}).caseOf({Left:o=>{throw o},Right:o=>o})}};v=g([(0,c.injectable)(),a(0,(0,c.inject)(u.transportDiTypes.TransportService)),a(1,(0,c.inject)(d.deviceSessionTypes.DeviceSessionService)),a(2,(0,c.inject)(f.loggerTypes.LoggerPublisherServiceFactory)),a(3,(0,c.inject)(D.managerApiTypes.ManagerApiService)),a(4,(0,c.inject)(y.secureChannelTypes.SecureChannelService))],v);0&&(module.exports={ConnectUseCase});
2
2
  //# sourceMappingURL=ConnectUseCase.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/internal/discovery/use-case/ConnectUseCase.ts"],
4
- "sourcesContent": ["import { inject, injectable } from \"inversify\";\nimport { EitherAsync } from \"purify-ts\";\n\nimport { DeviceSessionId } from \"@api/device-session/types\";\nimport { LoggerPublisherService } from \"@api/logger-publisher/service/LoggerPublisherService\";\nimport { ConnectedDevice } from \"@api/transport/model/ConnectedDevice\";\nimport { DiscoveredDevice } from \"@api/transport/model/DiscoveredDevice\";\nimport { TransportNotSupportedError } from \"@api/transport/model/Errors\";\nimport { DeviceId } from \"@api/types\";\nimport { deviceSessionTypes } from \"@internal/device-session/di/deviceSessionTypes\";\nimport {\n DeviceSession,\n DeviceSessionRefresherOptions,\n} from \"@internal/device-session/model/DeviceSession\";\nimport type { DeviceSessionService } from \"@internal/device-session/service/DeviceSessionService\";\nimport { loggerTypes } from \"@internal/logger-publisher/di/loggerTypes\";\nimport { managerApiTypes } from \"@internal/manager-api/di/managerApiTypes\";\nimport type { ManagerApiService } from \"@internal/manager-api/service/ManagerApiService\";\nimport { secureChannelTypes } from \"@internal/secure-channel/di/secureChannelTypes\";\nimport type { SecureChannelService } from \"@internal/secure-channel/service/SecureChannelService\";\nimport { transportDiTypes } from \"@internal/transport/di/transportDiTypes\";\nimport { type TransportService } from \"@internal/transport/service/TransportService\";\n\n/**\n * The arguments for the ConnectUseCase.\n */\nexport type ConnectUseCaseArgs = {\n /**\n * Discovered device or connected device.\n */\n device: DiscoveredDevice | ConnectedDevice;\n\n /**\n * sessionRefresherOptions - optional\n * isRefresherDisabled - whether the refresher is disabled\n * pollingInterval - optional - the refresh interval in milliseconds\n */\n sessionRefresherOptions?: DeviceSessionRefresherOptions;\n};\n\n/**\n * Connects to a discovered device.\n */\n@injectable()\nexport class ConnectUseCase {\n private readonly _transportService: TransportService;\n private readonly _sessionService: DeviceSessionService;\n private readonly _loggerFactory: (tag: string) => LoggerPublisherService;\n private readonly _managerApi: ManagerApiService;\n private readonly _secureChannel: SecureChannelService;\n private readonly _logger: LoggerPublisherService;\n\n constructor(\n @inject(transportDiTypes.TransportService)\n transportService: TransportService,\n @inject(deviceSessionTypes.DeviceSessionService)\n sessionService: DeviceSessionService,\n @inject(loggerTypes.LoggerPublisherServiceFactory)\n loggerFactory: (tag: string) => LoggerPublisherService,\n @inject(managerApiTypes.ManagerApiService)\n managerApi: ManagerApiService,\n @inject(secureChannelTypes.SecureChannelService)\n secureChannel: SecureChannelService,\n ) {\n this._sessionService = sessionService;\n this._transportService = transportService;\n this._loggerFactory = loggerFactory;\n this._logger = loggerFactory(\"ConnectUseCase\");\n this._managerApi = managerApi;\n this._secureChannel = secureChannel;\n }\n\n private handleDeviceDisconnect(deviceId: DeviceId) {\n const deviceSessionOrError =\n this._sessionService.getDeviceSessionByDeviceId(deviceId);\n deviceSessionOrError.map((deviceSession) => {\n this._sessionService.removeDeviceSession(deviceSession.id);\n });\n }\n\n async execute({\n device,\n sessionRefresherOptions,\n }: ConnectUseCaseArgs): Promise<DeviceSessionId> {\n const transport = this._transportService.getTransport(device.transport);\n // In case of a connected device, we reconnect using the same session id.\n // If not provided, a new device session id will be generated.\n const deviceSessionId =\n \"sessionId\" in device ? device.sessionId : undefined;\n\n return EitherAsync.liftEither(\n transport.toEither(\n new TransportNotSupportedError(new Error(\"Unknown transport\")),\n ),\n )\n .chain(async (t) => {\n return t.connect({\n deviceId: device.id,\n onDisconnect: (dId) => this.handleDeviceDisconnect(dId),\n });\n })\n .ifLeft((error) => {\n this._logger.error(\"Error connecting to device\", {\n data: { deviceId: device.id, error },\n });\n })\n .map(async (connectedDevice) => {\n const deviceSession = new DeviceSession(\n { connectedDevice, id: deviceSessionId },\n this._loggerFactory,\n this._managerApi,\n this._secureChannel,\n sessionRefresherOptions,\n );\n this._sessionService.addDeviceSession(deviceSession);\n await deviceSession.initialiseSession();\n return deviceSession.id;\n })\n .caseOf({\n Left: (error) => {\n throw error;\n },\n Right: (s) => s,\n });\n }\n}\n"],
5
- "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,oBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAmC,qBACnCC,EAA4B,qBAM5BC,EAA2C,uCAE3CC,EAAmC,0DACnCC,EAGO,wDAEPC,EAA4B,qDAC5BC,EAAgC,oDAEhCC,EAAmC,0DAEnCC,EAAiC,mDAwB1B,IAAMC,EAAN,KAAqB,CACT,kBACA,gBACA,eACA,YACA,eACA,QAEjB,YAEEC,EAEAC,EAEAC,EAEAC,EAEAC,EACA,CACA,KAAK,gBAAkBH,EACvB,KAAK,kBAAoBD,EACzB,KAAK,eAAiBE,EACtB,KAAK,QAAUA,EAAc,gBAAgB,EAC7C,KAAK,YAAcC,EACnB,KAAK,eAAiBC,CACxB,CAEQ,uBAAuBC,EAAoB,CAE/C,KAAK,gBAAgB,2BAA2BA,CAAQ,EACrC,IAAKC,GAAkB,CAC1C,KAAK,gBAAgB,oBAAoBA,EAAc,EAAE,CAC3D,CAAC,CACH,CAEA,MAAM,QAAQ,CACZ,OAAAC,EACA,wBAAAC,CACF,EAAiD,CAC/C,MAAMC,EAAY,KAAK,kBAAkB,aAAaF,EAAO,SAAS,EAGhEG,EACJ,cAAeH,EAASA,EAAO,UAAY,OAE7C,OAAO,cAAY,WACjBE,EAAU,SACR,IAAI,6BAA2B,IAAI,MAAM,mBAAmB,CAAC,CAC/D,CACF,EACG,MAAM,MAAOE,GACLA,EAAE,QAAQ,CACf,SAAUJ,EAAO,GACjB,aAAeK,GAAQ,KAAK,uBAAuBA,CAAG,CACxD,CAAC,CACF,EACA,OAAQC,GAAU,CACjB,KAAK,QAAQ,MAAM,6BAA8B,CAC/C,KAAM,CAAE,SAAUN,EAAO,GAAI,MAAAM,CAAM,CACrC,CAAC,CACH,CAAC,EACA,IAAI,MAAOC,GAAoB,CAC9B,MAAMR,EAAgB,IAAI,gBACxB,CAAE,gBAAAQ,EAAiB,GAAIJ,CAAgB,EACvC,KAAK,eACL,KAAK,YACL,KAAK,eACLF,CACF,EACA,YAAK,gBAAgB,iBAAiBF,CAAa,EACnD,MAAMA,EAAc,kBAAkB,EAC/BA,EAAc,EACvB,CAAC,EACA,OAAO,CACN,KAAOO,GAAU,CACf,MAAMA,CACR,EACA,MAAQE,GAAMA,CAChB,CAAC,CACL,CACF,EAjFahB,EAANiB,EAAA,IADN,cAAW,EAUPC,EAAA,eAAO,mBAAiB,gBAAgB,GAExCA,EAAA,eAAO,qBAAmB,oBAAoB,GAE9CA,EAAA,eAAO,cAAY,6BAA6B,GAEhDA,EAAA,eAAO,kBAAgB,iBAAiB,GAExCA,EAAA,eAAO,qBAAmB,oBAAoB,IAjBtClB",
6
- "names": ["ConnectUseCase_exports", "__export", "ConnectUseCase", "__toCommonJS", "import_inversify", "import_purify_ts", "import_Errors", "import_deviceSessionTypes", "import_DeviceSession", "import_loggerTypes", "import_managerApiTypes", "import_secureChannelTypes", "import_transportDiTypes", "ConnectUseCase", "transportService", "sessionService", "loggerFactory", "managerApi", "secureChannel", "deviceId", "deviceSession", "device", "sessionRefresherOptions", "transport", "deviceSessionId", "t", "dId", "error", "connectedDevice", "s", "__decorateClass", "__decorateParam"]
4
+ "sourcesContent": ["import { inject, injectable } from \"inversify\";\nimport { EitherAsync } from \"purify-ts\";\n\nimport { DeviceSessionId } from \"@api/device-session/types\";\nimport { LoggerPublisherService } from \"@api/logger-publisher/service/LoggerPublisherService\";\nimport { ConnectedDevice } from \"@api/transport/model/ConnectedDevice\";\nimport { DiscoveredDevice } from \"@api/transport/model/DiscoveredDevice\";\nimport { TransportNotSupportedError } from \"@api/transport/model/Errors\";\nimport { DeviceId } from \"@api/types\";\nimport { deviceSessionTypes } from \"@internal/device-session/di/deviceSessionTypes\";\nimport {\n DeviceSession,\n DeviceSessionRefresherOptions,\n} from \"@internal/device-session/model/DeviceSession\";\nimport type { DeviceSessionService } from \"@internal/device-session/service/DeviceSessionService\";\nimport { loggerTypes } from \"@internal/logger-publisher/di/loggerTypes\";\nimport { managerApiTypes } from \"@internal/manager-api/di/managerApiTypes\";\nimport type { ManagerApiService } from \"@internal/manager-api/service/ManagerApiService\";\nimport { secureChannelTypes } from \"@internal/secure-channel/di/secureChannelTypes\";\nimport type { SecureChannelService } from \"@internal/secure-channel/service/SecureChannelService\";\nimport { transportDiTypes } from \"@internal/transport/di/transportDiTypes\";\nimport { type TransportService } from \"@internal/transport/service/TransportService\";\n\n/**\n * The arguments for the ConnectUseCase.\n */\nexport type ConnectUseCaseArgs = {\n /**\n * Discovered device or connected device.\n */\n device: DiscoveredDevice | ConnectedDevice;\n\n /**\n * sessionRefresherOptions - optional\n * isRefresherDisabled - whether the refresher is disabled\n * pollingInterval - optional - the refresh interval in milliseconds\n */\n sessionRefresherOptions?: DeviceSessionRefresherOptions;\n};\n\n/**\n * Connects to a discovered device.\n */\n@injectable()\nexport class ConnectUseCase {\n private readonly _transportService: TransportService;\n private readonly _sessionService: DeviceSessionService;\n private readonly _loggerFactory: (tag: string) => LoggerPublisherService;\n private readonly _managerApi: ManagerApiService;\n private readonly _secureChannel: SecureChannelService;\n private readonly _logger: LoggerPublisherService;\n\n constructor(\n @inject(transportDiTypes.TransportService)\n transportService: TransportService,\n @inject(deviceSessionTypes.DeviceSessionService)\n sessionService: DeviceSessionService,\n @inject(loggerTypes.LoggerPublisherServiceFactory)\n loggerFactory: (tag: string) => LoggerPublisherService,\n @inject(managerApiTypes.ManagerApiService)\n managerApi: ManagerApiService,\n @inject(secureChannelTypes.SecureChannelService)\n secureChannel: SecureChannelService,\n ) {\n this._sessionService = sessionService;\n this._transportService = transportService;\n this._loggerFactory = loggerFactory;\n this._logger = loggerFactory(\"ConnectUseCase\");\n this._managerApi = managerApi;\n this._secureChannel = secureChannel;\n }\n\n private handleDeviceDisconnect(deviceId: DeviceId) {\n this._sessionService\n .getDeviceSessionsByDeviceId(deviceId)\n .ifRight((deviceSessions) => {\n deviceSessions.forEach((deviceSession) => {\n this._sessionService.removeDeviceSession(deviceSession.id);\n this._logger.info(\"Session removed\", {\n data: { deviceId, sessionId: deviceSession.id },\n });\n });\n });\n }\n\n async execute({\n device,\n sessionRefresherOptions,\n }: ConnectUseCaseArgs): Promise<DeviceSessionId> {\n const transport = this._transportService.getTransport(device.transport);\n // In case of a connected device, we reconnect using the same session id.\n // If not provided, a new device session id will be generated.\n const deviceSessionId =\n \"sessionId\" in device ? device.sessionId : undefined;\n\n return EitherAsync.liftEither(\n transport.toEither(\n new TransportNotSupportedError(new Error(\"Unknown transport\")),\n ),\n )\n .chain(async (t) => {\n return t.connect({\n deviceId: device.id,\n onDisconnect: (dId) => this.handleDeviceDisconnect(dId),\n });\n })\n .ifLeft((error) => {\n this._logger.error(\"Error connecting to device\", {\n data: { deviceId: device.id, error },\n });\n })\n .map(async (connectedDevice) => {\n const deviceSession = new DeviceSession(\n { connectedDevice, id: deviceSessionId },\n this._loggerFactory,\n this._managerApi,\n this._secureChannel,\n sessionRefresherOptions,\n );\n this._sessionService.addDeviceSession(deviceSession);\n await deviceSession.initialiseSession();\n return deviceSession.id;\n })\n .caseOf({\n Left: (error) => {\n throw error;\n },\n Right: (s) => s,\n });\n }\n}\n"],
5
+ "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAA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MR,EAAgB,IAAI,gBACxB,CAAE,gBAAAQ,EAAiB,GAAIJ,CAAgB,EACvC,KAAK,eACL,KAAK,YACL,KAAK,eACLF,CACF,EACA,YAAK,gBAAgB,iBAAiBF,CAAa,EACnD,MAAMA,EAAc,kBAAkB,EAC/BA,EAAc,EACvB,CAAC,EACA,OAAO,CACN,KAAOO,GAAU,CACf,MAAMA,CACR,EACA,MAAQE,GAAMA,CAChB,CAAC,CACL,CACF,EAtFajB,EAANkB,EAAA,IADN,cAAW,EAUPC,EAAA,eAAO,mBAAiB,gBAAgB,GAExCA,EAAA,eAAO,qBAAmB,oBAAoB,GAE9CA,EAAA,eAAO,cAAY,6BAA6B,GAEhDA,EAAA,eAAO,kBAAgB,iBAAiB,GAExCA,EAAA,eAAO,qBAAmB,oBAAoB,IAjBtCnB",
6
+ "names": ["ConnectUseCase_exports", "__export", "ConnectUseCase", "__toCommonJS", "import_inversify", "import_purify_ts", "import_Errors", "import_deviceSessionTypes", "import_DeviceSession", "import_loggerTypes", "import_managerApiTypes", "import_secureChannelTypes", "import_transportDiTypes", "ConnectUseCase", "transportService", "sessionService", "loggerFactory", "managerApi", "secureChannel", "deviceId", "deviceSessions", "deviceSession", "device", "sessionRefresherOptions", "transport", "deviceSessionId", "t", "dId", "error", "connectedDevice", "s", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ledgerhq/device-management-kit",
3
- "version": "0.11.0",
3
+ "version": "0.11.2",
4
4
  "private": false,
5
5
  "license": "Apache-2.0",
6
6
  "exports": {
@@ -32,6 +32,7 @@
32
32
  "module:create": "pnpm hygen core-module with-prompt"
33
33
  },
34
34
  "dependencies": {
35
+ "@noble/hashes": "^1.8.0",
35
36
  "@sentry/minimal": "catalog:",
36
37
  "axios": "catalog:",
37
38
  "inversify": "catalog:",