@ledgerhq/device-management-kit 1.6.0 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/package.json +1 -2
- package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js +1 -1
- package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js +1 -1
- package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js.map +2 -2
- package/lib/cjs/src/api/device-action/os/GetDeviceStatus/types.js +1 -1
- package/lib/cjs/src/api/device-action/os/GetDeviceStatus/types.js.map +1 -1
- package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.js +1 -1
- package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.js.map +2 -2
- package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.test.js +1 -1
- package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.test.js.map +2 -2
- package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/types.js +1 -1
- package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/types.js.map +1 -1
- package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/types.js.map +1 -1
- package/lib/cjs/src/api/logger-subscriber/service/WebLogsExporterLogger.js.map +2 -2
- package/lib/cjs/src/api/network/DmkNetworkClient.js +1 -1
- package/lib/cjs/src/api/network/DmkNetworkClient.js.map +3 -3
- package/lib/cjs/src/api/network/DmkNetworkClient.test.js +1 -1
- package/lib/cjs/src/api/network/DmkNetworkClient.test.js.map +3 -3
- package/lib/cjs/src/api/network/DmkNetworkClientError.js +1 -1
- package/lib/cjs/src/api/network/DmkNetworkClientError.js.map +2 -2
- package/lib/cjs/src/api/network/DmkNetworkClientHelpers.js +1 -1
- package/lib/cjs/src/api/network/DmkNetworkClientHelpers.js.map +3 -3
- package/lib/cjs/src/api/network/DmkNetworkClientHelpers.test.js +1 -1
- package/lib/cjs/src/api/network/DmkNetworkClientHelpers.test.js.map +3 -3
- package/lib/cjs/src/api/utils/Base64String.js +1 -1
- package/lib/cjs/src/api/utils/Base64String.js.map +3 -3
- package/lib/cjs/src/api/utils/Base64String.test.js +3 -1
- package/lib/cjs/src/api/utils/Base64String.test.js.map +3 -3
- package/lib/cjs/src/internal/secure-channel/data/DefaultSecureChannelDataSource.js +1 -1
- package/lib/cjs/src/internal/secure-channel/data/DefaultSecureChannelDataSource.js.map +3 -3
- package/lib/cjs/src/internal/secure-channel/data/DefaultSecureChannelDataSource.test.js +1 -1
- package/lib/cjs/src/internal/secure-channel/data/DefaultSecureChannelDataSource.test.js.map +2 -2
- package/lib/esm/package.json +1 -2
- package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js +1 -1
- package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js.map +3 -3
- package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js +1 -1
- package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js.map +2 -2
- package/lib/esm/src/api/device-action/os/GetDeviceStatus/types.js.map +1 -1
- package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.js +1 -1
- package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.js.map +2 -2
- package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.test.js +1 -1
- package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.test.js.map +2 -2
- package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/types.js.map +1 -1
- package/lib/esm/src/api/device-action/os/OpenAppWithDependencies/types.js.map +1 -1
- package/lib/esm/src/api/logger-subscriber/service/WebLogsExporterLogger.js.map +2 -2
- package/lib/esm/src/api/network/DmkNetworkClient.js +1 -1
- package/lib/esm/src/api/network/DmkNetworkClient.js.map +3 -3
- package/lib/esm/src/api/network/DmkNetworkClient.test.js +1 -1
- package/lib/esm/src/api/network/DmkNetworkClient.test.js.map +3 -3
- package/lib/esm/src/api/network/DmkNetworkClientError.js +1 -1
- package/lib/esm/src/api/network/DmkNetworkClientError.js.map +2 -2
- package/lib/esm/src/api/network/DmkNetworkClientHelpers.js +1 -1
- package/lib/esm/src/api/network/DmkNetworkClientHelpers.js.map +3 -3
- package/lib/esm/src/api/network/DmkNetworkClientHelpers.test.js +1 -1
- package/lib/esm/src/api/network/DmkNetworkClientHelpers.test.js.map +3 -3
- package/lib/esm/src/api/utils/Base64String.js +1 -1
- package/lib/esm/src/api/utils/Base64String.js.map +3 -3
- package/lib/esm/src/api/utils/Base64String.test.js +3 -1
- package/lib/esm/src/api/utils/Base64String.test.js.map +3 -3
- package/lib/esm/src/internal/secure-channel/data/DefaultSecureChannelDataSource.js +1 -1
- package/lib/esm/src/internal/secure-channel/data/DefaultSecureChannelDataSource.js.map +3 -3
- package/lib/esm/src/internal/secure-channel/data/DefaultSecureChannelDataSource.test.js +1 -1
- package/lib/esm/src/internal/secure-channel/data/DefaultSecureChannelDataSource.test.js.map +2 -2
- package/lib/types/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/GetDeviceStatus/types.d.ts +1 -0
- package/lib/types/src/api/device-action/os/GetDeviceStatus/types.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/OpenAppDeviceAction/types.d.ts +1 -1
- package/lib/types/src/api/device-action/os/OpenAppDeviceAction/types.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/OpenAppWithDependencies/types.d.ts +1 -1
- package/lib/types/src/api/device-action/os/OpenAppWithDependencies/types.d.ts.map +1 -1
- package/lib/types/src/api/logger-subscriber/service/WebLogsExporterLogger.d.ts.map +1 -1
- package/lib/types/src/api/network/DmkNetworkClient.d.ts +1 -6
- package/lib/types/src/api/network/DmkNetworkClient.d.ts.map +1 -1
- package/lib/types/src/api/network/DmkNetworkClientError.d.ts +2 -6
- package/lib/types/src/api/network/DmkNetworkClientError.d.ts.map +1 -1
- package/lib/types/src/api/network/DmkNetworkClientHelpers.d.ts +10 -7
- package/lib/types/src/api/network/DmkNetworkClientHelpers.d.ts.map +1 -1
- package/lib/types/src/api/utils/Base64String.d.ts.map +1 -1
- package/lib/types/src/internal/secure-channel/data/DefaultSecureChannelDataSource.d.ts.map +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +3 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.ts"],
|
|
4
|
-
"sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport {\n EMPTY,\n from,\n interval,\n mergeMap,\n type Observable,\n of,\n switchMap,\n take,\n} from \"rxjs\";\nimport { timeout } from \"rxjs/operators\";\nimport { assign, fromObservable, fromPromise, setup } from \"xstate\";\n\nimport { isSuccessCommandResult } from \"@api/command/model/CommandResult\";\nimport {\n GetAppAndVersionCommand,\n type GetAppAndVersionCommandResult,\n} from \"@api/command/os/GetAppAndVersionCommand\";\nimport {\n GetOsVersionCommand,\n type GetOsVersionCommandResult,\n type GetOsVersionResponse,\n} from \"@api/command/os/GetOsVersionCommand\";\nimport { DeviceStatus } from \"@api/device/DeviceStatus\";\nimport { type InternalApi } from \"@api/device-action/DeviceAction\";\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { DEFAULT_UNLOCK_TIMEOUT_MS } from \"@api/device-action/os/Const\";\nimport {\n DeviceLockedError,\n DeviceNotOnboardedError,\n} from \"@api/device-action/os/Errors\";\nimport { type StateMachineTypes } from \"@api/device-action/xstate-utils/StateMachineTypes\";\nimport {\n type DeviceActionStateMachine,\n XStateDeviceAction,\n} from \"@api/device-action/xstate-utils/XStateDeviceAction\";\nimport {\n type DeviceSessionState,\n DeviceSessionStateType,\n type FirmwareVersion,\n} from \"@api/device-session/DeviceSessionState\";\nimport { isDashboardName, LEDGER_OS_NAME } from \"@api/utils/AppName\";\n\nimport {\n type GetDeviceStatusDAError,\n type GetDeviceStatusDAInput,\n type GetDeviceStatusDAIntermediateValue,\n type GetDeviceStatusDAOutput,\n getDeviceStatusDAStateStep,\n} from \"./types\";\n\ntype GetDeviceStatusMachineInternalState = {\n readonly onboarded: boolean;\n readonly locked: boolean;\n readonly currentApp: string | null;\n readonly currentAppVersion: string | null;\n readonly osVersionMetadata: GetOsVersionResponse | null;\n readonly error: GetDeviceStatusDAError | null;\n};\n\nexport type MachineDependencies = {\n readonly getAppAndVersion: () => Promise<GetAppAndVersionCommandResult>;\n readonly getOsVersion: () => Promise<GetOsVersionCommandResult>;\n readonly getDeviceSessionState: () => DeviceSessionState;\n readonly waitForDeviceUnlock: (args: {\n input: { unlockTimeout: number };\n }) => Observable<void>;\n readonly setDeviceSessionState: (\n state: DeviceSessionState,\n ) => DeviceSessionState;\n};\n\nconst firmwareVersionFromOsVersion = (\n data: GetOsVersionResponse,\n): FirmwareVersion => ({\n mcu: data.mcuSephVersion,\n bootloader: data.mcuBootloaderVersion,\n os: data.seVersion,\n metadata: data,\n});\n\nexport type ExtractMachineDependencies = (\n internalApi: InternalApi,\n) => MachineDependencies;\n\nexport class GetDeviceStatusDeviceAction extends XStateDeviceAction<\n GetDeviceStatusDAOutput,\n GetDeviceStatusDAInput,\n GetDeviceStatusDAError,\n GetDeviceStatusDAIntermediateValue,\n GetDeviceStatusMachineInternalState\n> {\n makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n GetDeviceStatusDAOutput,\n GetDeviceStatusDAInput,\n GetDeviceStatusDAError,\n GetDeviceStatusDAIntermediateValue,\n GetDeviceStatusMachineInternalState\n > {\n type types = StateMachineTypes<\n GetDeviceStatusDAOutput,\n GetDeviceStatusDAInput,\n GetDeviceStatusDAError,\n GetDeviceStatusDAIntermediateValue,\n GetDeviceStatusMachineInternalState\n >;\n\n const {\n getAppAndVersion,\n getOsVersion,\n getDeviceSessionState,\n setDeviceSessionState,\n waitForDeviceUnlock,\n } = this.extractDependencies(internalApi);\n\n const unlockTimeout = this.input.unlockTimeout ?? DEFAULT_UNLOCK_TIMEOUT_MS;\n\n const updateSessionFromOsVersion = (data: GetOsVersionResponse) => {\n const currentState = getDeviceSessionState();\n if (currentState.sessionStateType === DeviceSessionStateType.Connected) {\n return;\n }\n setDeviceSessionState({\n ...currentState,\n firmwareVersion: firmwareVersionFromOsVersion(data),\n isSecureConnectionAllowed:\n data.secureElementFlags.isSecureConnectionAllowed,\n });\n };\n\n return setup({\n types: {\n input: {\n unlockTimeout,\n } as types[\"input\"],\n context: {} as types[\"context\"],\n output: {} as types[\"output\"],\n },\n actors: {\n getAppAndVersion: fromPromise(getAppAndVersion),\n getOsVersion: fromPromise(getOsVersion),\n waitForDeviceUnlock: fromObservable(waitForDeviceUnlock),\n },\n guards: {\n isCurrentAppBolos: ({ context }) =>\n isDashboardName(context._internalState.currentApp),\n isOnboardedFromOsVersion: ({ context }) =>\n context._internalState.osVersionMetadata?.secureElementFlags\n .isOnboarded === true,\n isDeviceLocked: ({ context }) => context._internalState.locked,\n hasError: ({ context }) => context._internalState.error !== null,\n },\n actions: {\n assignErrorDeviceNotOnboarded: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: new DeviceNotOnboardedError(),\n }),\n }),\n assignErrorDeviceLocked: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: new DeviceLockedError(),\n }),\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.UnlockDevice,\n step: getDeviceStatusDAStateStep.UNLOCK_DEVICE,\n },\n }),\n assignErrorFromEvent: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: _.event[\"error\"], // NOTE: it should never happen, the error is not typed anymore here\n }),\n }),\n assignNoUserActionNeeded: assign({\n intermediateValue: (_) =>\n ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n }) satisfies types[\"context\"][\"intermediateValue\"],\n }),\n assignUserActionUnlockNeeded: assign({\n intermediateValue: (_) =>\n ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.UnlockDevice,\n step: getDeviceStatusDAStateStep.UNLOCK_DEVICE,\n }) satisfies types[\"context\"][\"intermediateValue\"],\n }),\n },\n }).createMachine({\n /** @xstate-layout N4IgpgJg5mDOIC5QHEwBcAiYBuBLAxmAMpoCGaArrFnoQIL5q4D2AdgHQ0FgBKYpEAJ4BiANoAGALqJQAB2axcTNjJAAPRAFoArAHZx7AIwAmQ7oCcugMyHzANmMAWYwBoQgxI8vsAHOJM+VuLmVj5e2gC+EW6omDjcJORUXPSMLBwA8qwARsykAE4QuKxQAMIAFmD4ANZiUqryisqsqhoImo4O7OGhPj4h5n6Obh4IunZ2RoZ+ena6nYaGUTHoKcRklNTxqc3sWbkFRSUVVbWihtJIII1K6a1aVtoGTxOOjtbv84YjiObik7ofPM7GFDP9jNofMsQLE1olNmsGLsADLMGrFMqVGp1S5yBS3FRXNqaOzadjiHx2KyORbzcRBczmH4IbTOdjaabaKmdGy6XSRaIw1bbdZJLa0MBI9LsVHo45Ys4XBr45r3dps-n0ubaGxgx6PZlWULkkLBGmDCzGYzQ2Ei+HJEVStjsACqsDA+SdrBdrAANmjqmthBA2GB2MVsMxqmG3R6vT7-TU1hJcdcVXciYgglZycYQiYqRTQoZtMynDmbM4aW8rHYzD4BSs4hL7eLuF7Xe7PWk2AmA0GPflmPl2LJfeQAGbDgC2nbjPe9fv7IpTyqaGdAbXmxnZPkMNNM820VuZ+8M7Dsb3MznpwW31sFtpbGwdEo7dFksjorAgADUPYobAnNiIasGGEZRmGT4JC+bY7NKH5fj+-75IBrDAdUCAQfg5DpCmq5XDcqqZmMjgGDY-yGJeejjFRzJ2P47DZoEJb+Hyx42sKz5ioiC7sIh35-gB6QYcIg7DqO45oFO+SztBhCtrxuwCchwlAQqWGsJGOHNPh9SEemhKbogdLsIMTjmPuNF1nYZaOBW+5OPu9l1oCjZCs2ME8Y6fGIb6BC4WwdDYKQuDjtkvq8HAFC+mgokEXi65GeoiBguYZJOPSJa6Hm1hGsyuglkxxiUjYVjXlq7nyaKCI+cpn7+Tp6TBaF4WRXwsAxXFCpiEqBlJS0JFAo4vg+BCe55e8-QFUVVglVShjlWRtZ2FEgqsMwEBwKo1WKXVG5pgNaokmRZmQg4fyLHR7ieCNpjGPyx7aNo6UNo4nGeQpsFKdKax8AIoyJQSg3Ge0L07q9F3+Istk3Qg1IjUaZ7GNS-LlU4H1wt9+3OvseSFBiGFrsDx01mZ15mHooReFaVj0fZ5Jci5zissYIKY3a2NvnxsrVITCrE8RoMdDucxWgx1jpZCELDHDgKTC9jg6mNXKLDSHPcbV3O7LG3bNH2SYioLB3EmCI1-HuVL6Cj4hU6eNjsIVD3UrWfKXVCj5cV5Wvtr5n6CShaFE-1JMkWzPgXpCjh+Faw3Mjq5jdOlJhGvo-RzRr3uvr79VjgFzQtWFpARVFnWxcHQNCylCBm+eKPjJL4jWMEdNww4O46vSFVsfyD5Nlj3na9KRAUPghCwPAIdV20QIR7e-RzOYbNK98cN7ndgR-BSzgo+YmdfYPOfSgAovkQ75MbyVtItehmSrJgcijz2uHD+pmXyQSQnyVLs2tQA */\n id: \"GetDeviceStatusDeviceAction\",\n initial: \"DeviceReady\",\n context: (_) => {\n const sessionState = getDeviceSessionState();\n const { sessionStateType } = sessionState;\n return {\n input: {\n unlockTimeout: _.input.unlockTimeout,\n },\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: getDeviceStatusDAStateStep.ONBOARD_CHECK,\n },\n _internalState: {\n onboarded: false,\n locked: false,\n currentApp:\n sessionStateType ===\n DeviceSessionStateType.ReadyWithoutSecureChannel\n ? sessionState.currentApp.name\n : null,\n currentAppVersion: null,\n osVersionMetadata: null,\n error: null,\n },\n };\n },\n states: {\n DeviceReady: {\n always: {\n target: \"AppAndVersionCheck\",\n },\n },\n AppAndVersionCheck: {\n // We check the current app and version using the getAppAndVersion\n // command. This command is supported both on the dashboard (BOLOS)\n // and inside applications, so it is used to determine the currently\n // running app before deciding whether to read the OS version.\n invoke: {\n src: \"getAppAndVersion\",\n onDone: {\n target: \"ApplicationAvailableResultCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n const state: DeviceSessionState = getDeviceSessionState();\n if (\n state.sessionStateType !==\n DeviceSessionStateType.Connected\n ) {\n // Update the current app\n setDeviceSessionState({\n ...state,\n currentApp: _.event.output.data,\n });\n } else {\n // The device can be set to Ready if GetAppAndVersionCommand was successful.\n // The firmware version and secure connection flag are enriched later from\n // the OS version, which can only be read on the dashboard.\n setDeviceSessionState({\n deviceModelId: state.deviceModelId,\n sessionStateType:\n DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: _.event.output.data,\n installedApps: [],\n isSecureConnectionAllowed: false,\n });\n }\n return {\n ..._.context._internalState,\n locked: false,\n currentApp: _.event.output.data.name,\n currentAppVersion: _.event.output.data.version,\n };\n }\n if (\"errorCode\" in _.event.output.error) {\n if (_.event.output.error.errorCode === \"5515\") {\n // Locked device error\n return {\n ..._.context._internalState,\n locked: true,\n };\n } else if (_.event.output.error.errorCode === \"6e00\") {\n // CLA not supported\n // GetAppAndVersion should always be supported by the firmware or any app.\n // But on old firmware versions, that APDU was not supported in the dashboard.\n // On those firmwares, it fails with CLA_NOT_SUPPORTED in BOLOS, and INS_NOT_SUPPORTED\n // in applications. Therefore if CLA is not supported, we can consider we're on the\n // dashboard on an old firmware. We should therefore return that information to\n // ensure the user can still update his firmware and is not blocked at this step.\n return {\n ..._.context._internalState,\n locked: false,\n currentApp: LEDGER_OS_NAME,\n currentAppVersion: \"0.0.0\",\n };\n }\n }\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n ApplicationAvailableResultCheck: {\n always: [\n {\n guard: \"hasError\",\n target: \"Error\",\n },\n {\n target: \"UserActionUnlockDevice\",\n guard: \"isDeviceLocked\",\n },\n {\n target: \"OnboardingCheck\",\n },\n ],\n },\n OnboardingCheck: {\n always: [\n {\n // The OS version (and thus the onboarding flag) can only be read\n // on the dashboard. If we are inside an application, fetching it\n // would fail, so we only fetch it when the current app is BOLOS.\n guard: \"isCurrentAppBolos\",\n target: \"GetOsVersion\",\n },\n {\n // A non-BOLOS application can only run on an onboarded device, so\n // if an app is open we can safely consider the device onboarded\n // without reading the OS version.\n target: \"Success\",\n actions: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n onboarded: true,\n }),\n }),\n },\n ],\n },\n GetOsVersion: {\n invoke: {\n src: \"getOsVersion\",\n onDone: {\n target: \"OnboardingResultCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n updateSessionFromOsVersion(_.event.output.data);\n return {\n ..._.context._internalState,\n osVersionMetadata: _.event.output.data,\n };\n }\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n OnboardingResultCheck: {\n always: [\n {\n guard: \"hasError\",\n target: \"Error\",\n },\n {\n guard: \"isOnboardedFromOsVersion\",\n target: \"Success\",\n actions: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n onboarded: true,\n }),\n }),\n },\n {\n target: \"Error\",\n actions: \"assignErrorDeviceNotOnboarded\",\n },\n ],\n },\n UserActionUnlockDevice: {\n // we wait for the device to be unlocked (default timeout is 15s)\n entry: \"assignUserActionUnlockNeeded\",\n exit: \"assignNoUserActionNeeded\",\n invoke: {\n id: \"UserActionUnlockDevice\",\n src: \"waitForDeviceUnlock\",\n input: (_) => ({\n unlockTimeout,\n }),\n onDone: {\n target: \"AppAndVersionCheck\",\n actions: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n locked: false,\n }),\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorDeviceLocked\",\n },\n },\n },\n Success: {\n type: \"final\",\n },\n Error: {\n type: \"final\",\n },\n },\n output: (args) => {\n // TODO: instead we should rely on the current state (\"Success\" or \"Error\")\n const { context } = args;\n const { error, currentApp, currentAppVersion } = context._internalState;\n if (error) {\n return Left(error);\n }\n return Right<GetDeviceStatusDAOutput>({\n currentApp: currentApp!,\n currentAppVersion: currentAppVersion!,\n });\n },\n });\n }\n\n extractDependencies(internalApi: InternalApi): MachineDependencies {\n const getAppAndVersion = () => {\n return internalApi.sendCommand(new GetAppAndVersionCommand());\n };\n\n const waitForDeviceUnlock = ({\n input,\n }: {\n input: { unlockTimeout: number };\n }) =>\n interval(1000).pipe(\n switchMap(() =>\n from(internalApi.sendCommand(new GetAppAndVersionCommand())),\n ),\n mergeMap((output) => {\n const isLocked =\n !isSuccessCommandResult(output) &&\n \"errorCode\" in output.error &&\n output.error.errorCode === \"5515\";\n if (isLocked) {\n return EMPTY; // Continue the polling\n }\n return of(undefined); // Complete the observable\n }),\n take(1),\n timeout(input.unlockTimeout),\n );\n\n return {\n getAppAndVersion,\n getOsVersion: () => internalApi.sendCommand(new GetOsVersionCommand()),\n waitForDeviceUnlock,\n getDeviceSessionState: () => internalApi.getDeviceSessionState(),\n setDeviceSessionState: (state: DeviceSessionState) =>\n internalApi.setDeviceSessionState(state),\n };\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAC5B,OACE,SAAAC,EACA,QAAAC,EACA,YAAAC,EACA,YAAAC,EAEA,MAAAC,EACA,aAAAC,EACA,QAAAC,MACK,OACP,OAAS,WAAAC,MAAe,iBACxB,OAAS,UAAAC,EAAQ,kBAAAC,EAAgB,eAAAC,EAAa,SAAAC,MAAa,SAE3D,OAAS,0BAAAC,MAA8B,mCACvC,OACE,2BAAAC,MAEK,0CACP,OACE,uBAAAC,MAGK,sCACP,OAAS,gBAAAC,MAAoB,2BAE7B,OAAS,2BAAAC,MAA+B,mDACxC,OAAS,6BAAAC,MAAiC,8BAC1C,OACE,qBAAAC,EACA,2BAAAC,MACK,+BAEP,OAEE,sBAAAC,MACK,qDACP,OAEE,0BAAAC,MAEK,yCACP,OAAS,mBAAAC,EAAiB,kBAAAC,MAAsB,qBAEhD,OAKE,8BAAAC,MACK,UAuBP,MAAMC,EACJC,IACqB,CACrB,IAAKA,EAAK,eACV,WAAYA,EAAK,qBACjB,GAAIA,EAAK,UACT,SAAUA,CACZ,GAMO,MAAMC,WAAoCP,CAM/C,CACA,iBACEQ,EAOA,CASA,KAAM,CACJ,iBAAAC,EACA,aAAAC,EACA,sBAAAC,EACA,sBAAAC,EACA,oBAAAC,CACF,EAAI,KAAK,oBAAoBL,CAAW,EAElCM,EAAgB,KAAK,MAAM,eAAiBjB,
|
|
6
|
-
"names": ["Left", "Right", "EMPTY", "from", "interval", "mergeMap", "of", "switchMap", "take", "timeout", "assign", "fromObservable", "fromPromise", "setup", "isSuccessCommandResult", "GetAppAndVersionCommand", "GetOsVersionCommand", "DeviceStatus", "UserInteractionRequired", "DEFAULT_UNLOCK_TIMEOUT_MS", "DeviceLockedError", "DeviceNotOnboardedError", "XStateDeviceAction", "DeviceSessionStateType", "isDashboardName", "LEDGER_OS_NAME", "getDeviceStatusDAStateStep", "firmwareVersionFromOsVersion", "data", "GetDeviceStatusDeviceAction", "internalApi", "getAppAndVersion", "getOsVersion", "getDeviceSessionState", "setDeviceSessionState", "waitForDeviceUnlock", "unlockTimeout", "updateSessionFromOsVersion", "currentState", "context", "_", "sessionState", "sessionStateType", "state", "args", "error", "currentApp", "currentAppVersion", "input", "output"]
|
|
4
|
+
"sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport {\n EMPTY,\n from,\n interval,\n mergeMap,\n type Observable,\n of,\n switchMap,\n take,\n} from \"rxjs\";\nimport { timeout } from \"rxjs/operators\";\nimport { assign, fromObservable, fromPromise, setup } from \"xstate\";\n\nimport { isSuccessCommandResult } from \"@api/command/model/CommandResult\";\nimport {\n GetAppAndVersionCommand,\n type GetAppAndVersionCommandResult,\n} from \"@api/command/os/GetAppAndVersionCommand\";\nimport {\n GetOsVersionCommand,\n type GetOsVersionCommandResult,\n type GetOsVersionResponse,\n} from \"@api/command/os/GetOsVersionCommand\";\nimport { DeviceStatus } from \"@api/device/DeviceStatus\";\nimport { type InternalApi } from \"@api/device-action/DeviceAction\";\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { DEFAULT_UNLOCK_TIMEOUT_MS } from \"@api/device-action/os/Const\";\nimport {\n DeviceLockedError,\n DeviceNotOnboardedError,\n} from \"@api/device-action/os/Errors\";\nimport { type StateMachineTypes } from \"@api/device-action/xstate-utils/StateMachineTypes\";\nimport {\n type DeviceActionStateMachine,\n XStateDeviceAction,\n} from \"@api/device-action/xstate-utils/XStateDeviceAction\";\nimport {\n type DeviceSessionState,\n DeviceSessionStateType,\n type FirmwareVersion,\n} from \"@api/device-session/DeviceSessionState\";\nimport { isDashboardName, LEDGER_OS_NAME } from \"@api/utils/AppName\";\n\nimport {\n type GetDeviceStatusDAError,\n type GetDeviceStatusDAInput,\n type GetDeviceStatusDAIntermediateValue,\n type GetDeviceStatusDAOutput,\n getDeviceStatusDAStateStep,\n} from \"./types\";\n\ntype GetDeviceStatusMachineInternalState = {\n readonly onboarded: boolean;\n readonly locked: boolean;\n readonly currentApp: string | null;\n readonly currentAppVersion: string | null;\n readonly osVersionMetadata: GetOsVersionResponse | null;\n readonly error: GetDeviceStatusDAError | null;\n};\n\nexport type MachineDependencies = {\n readonly getAppAndVersion: () => Promise<GetAppAndVersionCommandResult>;\n readonly getOsVersion: () => Promise<GetOsVersionCommandResult>;\n readonly getDeviceSessionState: () => DeviceSessionState;\n readonly waitForDeviceUnlock: (args: {\n input: { unlockTimeout: number };\n }) => Observable<void>;\n readonly setDeviceSessionState: (\n state: DeviceSessionState,\n ) => DeviceSessionState;\n};\n\nconst firmwareVersionFromOsVersion = (\n data: GetOsVersionResponse,\n): FirmwareVersion => ({\n mcu: data.mcuSephVersion,\n bootloader: data.mcuBootloaderVersion,\n os: data.seVersion,\n metadata: data,\n});\n\nexport type ExtractMachineDependencies = (\n internalApi: InternalApi,\n) => MachineDependencies;\n\nexport class GetDeviceStatusDeviceAction extends XStateDeviceAction<\n GetDeviceStatusDAOutput,\n GetDeviceStatusDAInput,\n GetDeviceStatusDAError,\n GetDeviceStatusDAIntermediateValue,\n GetDeviceStatusMachineInternalState\n> {\n makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n GetDeviceStatusDAOutput,\n GetDeviceStatusDAInput,\n GetDeviceStatusDAError,\n GetDeviceStatusDAIntermediateValue,\n GetDeviceStatusMachineInternalState\n > {\n type types = StateMachineTypes<\n GetDeviceStatusDAOutput,\n GetDeviceStatusDAInput,\n GetDeviceStatusDAError,\n GetDeviceStatusDAIntermediateValue,\n GetDeviceStatusMachineInternalState\n >;\n\n const {\n getAppAndVersion,\n getOsVersion,\n getDeviceSessionState,\n setDeviceSessionState,\n waitForDeviceUnlock,\n } = this.extractDependencies(internalApi);\n\n const unlockTimeout = this.input.unlockTimeout ?? DEFAULT_UNLOCK_TIMEOUT_MS;\n const allowNonOnboardedDevice = this.input.allowNonOnboardedDevice ?? true;\n\n const updateSessionFromOsVersion = (data: GetOsVersionResponse) => {\n const currentState = getDeviceSessionState();\n if (currentState.sessionStateType === DeviceSessionStateType.Connected) {\n return;\n }\n setDeviceSessionState({\n ...currentState,\n firmwareVersion: firmwareVersionFromOsVersion(data),\n isSecureConnectionAllowed:\n data.secureElementFlags.isSecureConnectionAllowed,\n });\n };\n\n return setup({\n types: {\n input: {\n unlockTimeout,\n allowNonOnboardedDevice,\n } as types[\"input\"],\n context: {} as types[\"context\"],\n output: {} as types[\"output\"],\n },\n actors: {\n getAppAndVersion: fromPromise(getAppAndVersion),\n getOsVersion: fromPromise(getOsVersion),\n waitForDeviceUnlock: fromObservable(waitForDeviceUnlock),\n },\n guards: {\n isCurrentAppBolos: ({ context }) =>\n isDashboardName(context._internalState.currentApp),\n isOnboardedFromOsVersion: ({ context }) =>\n context._internalState.osVersionMetadata?.secureElementFlags\n .isOnboarded === true,\n isAllowedNonOnboardedDevice: ({ context }) => {\n const secureElementFlags =\n context._internalState.osVersionMetadata?.secureElementFlags;\n return (\n context.input.allowNonOnboardedDevice === true &&\n secureElementFlags?.isOnboarded === false\n );\n },\n isDeviceLocked: ({ context }) => context._internalState.locked,\n hasError: ({ context }) => context._internalState.error !== null,\n },\n actions: {\n assignErrorDeviceNotOnboarded: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: new DeviceNotOnboardedError(),\n }),\n }),\n assignErrorDeviceLocked: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: new DeviceLockedError(),\n }),\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.UnlockDevice,\n step: getDeviceStatusDAStateStep.UNLOCK_DEVICE,\n },\n }),\n assignErrorFromEvent: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: _.event[\"error\"], // NOTE: it should never happen, the error is not typed anymore here\n }),\n }),\n assignNoUserActionNeeded: assign({\n intermediateValue: (_) =>\n ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n }) satisfies types[\"context\"][\"intermediateValue\"],\n }),\n assignUserActionUnlockNeeded: assign({\n intermediateValue: (_) =>\n ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.UnlockDevice,\n step: getDeviceStatusDAStateStep.UNLOCK_DEVICE,\n }) satisfies types[\"context\"][\"intermediateValue\"],\n }),\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qsMwEBwKo1WKXVG5pgNaokmRZmQg4fyLHR7ieCNpjGPyx7aNo6UNo4nGeQpsFKdKax8AIoyJQSg3Ge0L07q9F3+Istk3Qg1IjUaZ7GNS-LlU4H1wt9+3OvseSFBiGFrsDx01mZ15mHooReFaVj0fZ5Jci5zissYIKY3a2NvnxsrVITCrE8RoMdDucxWgx1jpZCELDHDgKTC9jg6mNXKLDSHPcbV3O7LG3bNH2SYioLB3EmCI1-HuVL6Cj4hU6eNjsIVD3UrWfKXVCj5cV5Wvtr5n6CShaFE-1JMkWzPgXpCjh+Faw3Mjq5jdOlJhGvo-RzRr3uvr79VjgFzQtWFpARVFnWxcHQNCylCBm+eKPjJL4jWMEdNww4O46vSFVsfyD5Nlj3na9KRAUPghCwPAIdV20QIR7e-RzOYbNK98cN7ndgR-BSzgo+YmdfYPOfSgAovkQ75MbyVtItehmSrJgcijz2uHD+pmXyQSQnyVLs2tQA */\n id: \"GetDeviceStatusDeviceAction\",\n initial: \"DeviceReady\",\n context: (_) => {\n const sessionState = getDeviceSessionState();\n const { sessionStateType } = sessionState;\n return {\n input: {\n unlockTimeout: _.input.unlockTimeout,\n allowNonOnboardedDevice: _.input.allowNonOnboardedDevice ?? true,\n },\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: getDeviceStatusDAStateStep.ONBOARD_CHECK,\n },\n _internalState: {\n onboarded: false,\n locked: false,\n currentApp:\n sessionStateType ===\n DeviceSessionStateType.ReadyWithoutSecureChannel\n ? sessionState.currentApp.name\n : null,\n currentAppVersion: null,\n osVersionMetadata: null,\n error: null,\n },\n };\n },\n states: {\n DeviceReady: {\n always: {\n target: \"AppAndVersionCheck\",\n },\n },\n AppAndVersionCheck: {\n // We check the current app and version using the getAppAndVersion\n // command. This command is supported both on the dashboard (BOLOS)\n // and inside applications, so it is used to determine the currently\n // running app before deciding whether to read the OS version.\n invoke: {\n src: \"getAppAndVersion\",\n onDone: {\n target: \"ApplicationAvailableResultCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n const state: DeviceSessionState = getDeviceSessionState();\n if (\n state.sessionStateType !==\n DeviceSessionStateType.Connected\n ) {\n // Update the current app\n setDeviceSessionState({\n ...state,\n currentApp: _.event.output.data,\n });\n } else {\n // The device can be set to Ready if GetAppAndVersionCommand was successful.\n // The firmware version and secure connection flag are enriched later from\n // the OS version, which can only be read on the dashboard.\n setDeviceSessionState({\n deviceModelId: state.deviceModelId,\n sessionStateType:\n DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: _.event.output.data,\n installedApps: [],\n isSecureConnectionAllowed: false,\n });\n }\n return {\n ..._.context._internalState,\n locked: false,\n currentApp: _.event.output.data.name,\n currentAppVersion: _.event.output.data.version,\n };\n }\n if (\"errorCode\" in _.event.output.error) {\n if (_.event.output.error.errorCode === \"5515\") {\n // Locked device error\n return {\n ..._.context._internalState,\n locked: true,\n };\n } else if (_.event.output.error.errorCode === \"6e00\") {\n // CLA not supported\n // GetAppAndVersion should always be supported by the firmware or any app.\n // But on old firmware versions, that APDU was not supported in the dashboard.\n // On those firmwares, it fails with CLA_NOT_SUPPORTED in BOLOS, and INS_NOT_SUPPORTED\n // in applications. Therefore if CLA is not supported, we can consider we're on the\n // dashboard on an old firmware. We should therefore return that information to\n // ensure the user can still update his firmware and is not blocked at this step.\n return {\n ..._.context._internalState,\n locked: false,\n currentApp: LEDGER_OS_NAME,\n currentAppVersion: \"0.0.0\",\n };\n }\n }\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n ApplicationAvailableResultCheck: {\n always: [\n {\n guard: \"hasError\",\n target: \"Error\",\n },\n {\n target: \"UserActionUnlockDevice\",\n guard: \"isDeviceLocked\",\n },\n {\n target: \"OnboardingCheck\",\n },\n ],\n },\n OnboardingCheck: {\n always: [\n {\n // The OS version (and thus the onboarding flag) can only be read\n // on the dashboard. If we are inside an application, fetching it\n // would fail, so we only fetch it when the current app is BOLOS.\n guard: \"isCurrentAppBolos\",\n target: \"GetOsVersion\",\n },\n {\n // A non-BOLOS application can only run on an onboarded device, so\n // if an app is open we can safely consider the device onboarded\n // without reading the OS version.\n target: \"Success\",\n actions: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n onboarded: true,\n }),\n }),\n },\n ],\n },\n GetOsVersion: {\n invoke: {\n src: \"getOsVersion\",\n onDone: {\n target: \"OnboardingResultCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n updateSessionFromOsVersion(_.event.output.data);\n return {\n ..._.context._internalState,\n osVersionMetadata: _.event.output.data,\n };\n }\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n OnboardingResultCheck: {\n always: [\n {\n guard: \"hasError\",\n target: \"Error\",\n },\n {\n guard: \"isOnboardedFromOsVersion\",\n target: \"Success\",\n actions: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n onboarded: true,\n }),\n }),\n },\n {\n guard: \"isAllowedNonOnboardedDevice\",\n target: \"Success\",\n },\n {\n target: \"Error\",\n actions: \"assignErrorDeviceNotOnboarded\",\n },\n ],\n },\n UserActionUnlockDevice: {\n // we wait for the device to be unlocked (default timeout is 15s)\n entry: \"assignUserActionUnlockNeeded\",\n exit: \"assignNoUserActionNeeded\",\n invoke: {\n id: \"UserActionUnlockDevice\",\n src: \"waitForDeviceUnlock\",\n input: (_) => ({\n unlockTimeout,\n }),\n onDone: {\n target: \"AppAndVersionCheck\",\n actions: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n locked: false,\n }),\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorDeviceLocked\",\n },\n },\n },\n Success: {\n type: \"final\",\n },\n Error: {\n type: \"final\",\n },\n },\n output: (args) => {\n // TODO: instead we should rely on the current state (\"Success\" or \"Error\")\n const { context } = args;\n const { error, currentApp, currentAppVersion } = context._internalState;\n if (error) {\n return Left(error);\n }\n return Right<GetDeviceStatusDAOutput>({\n currentApp: currentApp!,\n currentAppVersion: currentAppVersion!,\n });\n },\n });\n }\n\n extractDependencies(internalApi: InternalApi): MachineDependencies {\n const getAppAndVersion = () => {\n return internalApi.sendCommand(new GetAppAndVersionCommand());\n };\n\n const waitForDeviceUnlock = ({\n input,\n }: {\n input: { unlockTimeout: number };\n }) =>\n interval(1000).pipe(\n switchMap(() =>\n from(internalApi.sendCommand(new GetAppAndVersionCommand())),\n ),\n mergeMap((output) => {\n const isLocked =\n !isSuccessCommandResult(output) &&\n \"errorCode\" in output.error &&\n output.error.errorCode === \"5515\";\n if (isLocked) {\n return EMPTY; // Continue the polling\n }\n return of(undefined); // Complete the observable\n }),\n take(1),\n timeout(input.unlockTimeout),\n );\n\n return {\n getAppAndVersion,\n getOsVersion: () => internalApi.sendCommand(new GetOsVersionCommand()),\n waitForDeviceUnlock,\n getDeviceSessionState: () => internalApi.getDeviceSessionState(),\n setDeviceSessionState: (state: DeviceSessionState) =>\n internalApi.setDeviceSessionState(state),\n };\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAC5B,OACE,SAAAC,EACA,QAAAC,EACA,YAAAC,EACA,YAAAC,EAEA,MAAAC,EACA,aAAAC,EACA,QAAAC,MACK,OACP,OAAS,WAAAC,MAAe,iBACxB,OAAS,UAAAC,EAAQ,kBAAAC,EAAgB,eAAAC,EAAa,SAAAC,MAAa,SAE3D,OAAS,0BAAAC,MAA8B,mCACvC,OACE,2BAAAC,MAEK,0CACP,OACE,uBAAAC,MAGK,sCACP,OAAS,gBAAAC,MAAoB,2BAE7B,OAAS,2BAAAC,MAA+B,mDACxC,OAAS,6BAAAC,MAAiC,8BAC1C,OACE,qBAAAC,EACA,2BAAAC,MACK,+BAEP,OAEE,sBAAAC,MACK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AC,CACH,CACF,CAAC,CACH,CAEA,oBAAoBnB,EAA+C,CA4BjE,MAAO,CACL,iBA5BuB,IAChBA,EAAY,YAAY,IAAIf,CAAyB,EA4B5D,aAAc,IAAMe,EAAY,YAAY,IAAId,CAAqB,EACrE,oBA1B0B,CAAC,CAC3B,MAAAkC,CACF,IAGE9C,EAAS,GAAI,EAAE,KACbG,EAAU,IACRJ,EAAK2B,EAAY,YAAY,IAAIf,CAAyB,CAAC,CAC7D,EACAV,EAAU8C,GAEN,CAACrC,EAAuBqC,CAAM,GAC9B,cAAeA,EAAO,OACtBA,EAAO,MAAM,YAAc,OAEpBjD,EAEFI,EAAG,MAAS,CACpB,EACDE,EAAK,CAAC,EACNC,EAAQyC,EAAM,aAAa,CAC7B,EAMA,sBAAuB,IAAMpB,EAAY,sBAAsB,EAC/D,sBAAwBe,GACtBf,EAAY,sBAAsBe,CAAK,CAC3C,CACF,CACF",
|
|
6
|
+
"names": ["Left", "Right", "EMPTY", "from", "interval", "mergeMap", "of", "switchMap", "take", "timeout", "assign", "fromObservable", "fromPromise", "setup", "isSuccessCommandResult", "GetAppAndVersionCommand", "GetOsVersionCommand", "DeviceStatus", "UserInteractionRequired", "DEFAULT_UNLOCK_TIMEOUT_MS", "DeviceLockedError", "DeviceNotOnboardedError", "XStateDeviceAction", "DeviceSessionStateType", "isDashboardName", "LEDGER_OS_NAME", "getDeviceStatusDAStateStep", "firmwareVersionFromOsVersion", "data", "GetDeviceStatusDeviceAction", "internalApi", "getAppAndVersion", "getOsVersion", "getDeviceSessionState", "setDeviceSessionState", "waitForDeviceUnlock", "unlockTimeout", "allowNonOnboardedDevice", "updateSessionFromOsVersion", "currentState", "context", "secureElementFlags", "_", "sessionState", "sessionStateType", "state", "args", "error", "currentApp", "currentAppVersion", "input", "output"]
|
|
7
7
|
}
|
package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{interval as B,Observable as E}from"rxjs";import{CommandResultFactory as y}from"../../../command/model/CommandResult";import{getOsVersionCommandResponseMockBuilder as P}from"../../../command/os/__mocks__/GetOsVersionCommand";import{GLOBAL_ERRORS as x,GlobalCommandError as L}from"../../../command/utils/GlobalCommandError";import{DeviceModelId as l}from"../../../device/DeviceModel";import{DeviceStatus as i}from"../../../device/DeviceStatus";import{makeDeviceActionInternalApiMock as a}from"../../../device-action/__test-utils__/makeInternalApi";import{testDeviceActionStates as d}from"../../../device-action/__test-utils__/testDeviceActionStates";import{DeviceActionStatus as c}from"../../../device-action/model/DeviceActionState";import{UserInteractionRequired as G}from"../../../device-action/model/UserInteractionRequired";import{DeviceLockedError as I,DeviceNotOnboardedError as _,UnknownDAError as M}from"../../../device-action/os/Errors";import{DeviceSessionStateType as s}from"../../../device-session/DeviceSessionState";import{GetDeviceStatusDeviceAction as p}from"./GetDeviceStatusDeviceAction";import{getDeviceStatusDAStateStep as b}from"./types";const O=(u={},D=l.NANO_X)=>y({data:P(D,u)}),k=(u,D)=>y({data:{name:u,version:D}}),f=()=>y({error:new L({...x[5515],errorCode:"5515"})}),v=()=>({intermediateValue:{requiredUserInteraction:G.None,step:b.ONBOARD_CHECK},status:c.Pending}),w=()=>[v(),v()],g=()=>({intermediateValue:{requiredUserInteraction:G.UnlockDevice,step:b.UNLOCK_DEVICE},status:c.Pending}),T=()=>({intermediateValue:{requiredUserInteraction:G.None,step:b.UNLOCK_DEVICE},status:c.Pending});describe("GetDeviceStatusDeviceAction",()=>{const u=vi.fn(),D=vi.fn(),S=vi.fn(),C=vi.fn(),R=vi.fn();function A(){return{getAppAndVersion:u,getOsVersion:D,getDeviceSessionState:S,waitForDeviceUnlock:C,setDeviceSessionState:R}}const{sendCommand:h,getDeviceSessionState:V,getDeviceSessionStateObservable:W}=a();beforeEach(()=>{vi.resetAllMocks(),D.mockResolvedValue(O())}),describe("without overriding `extractDependencies`",()=>{it("should run the device action with an unlocked device",()=>new Promise((o,r)=>{const e=new p({input:{unlockTimeout:500}});V.mockReturnValue({sessionStateType:s.Connected,deviceStatus:i.CONNECTED,deviceModelId:l.NANO_X}),h.mockImplementation(n=>n.name==="getOsVersion"?Promise.resolve(O()):Promise.resolve(k("BOLOS","1.0.0")));const t=[...w(),{output:{currentApp:"BOLOS",currentAppVersion:"1.0.0"},status:c.Completed}];d(e,t,a(),{onDone:o,onError:r})})),it("should run the device action with a locked device",()=>new Promise((o,r)=>{const e=new p({input:{unlockTimeout:1500}});V.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"},installedApps:[],deviceModelId:l.NANO_X,isSecureConnectionAllowed:!1});let t=0;h.mockImplementation(m=>m.name==="getOsVersion"?Promise.resolve(O()):(t+=1,t===1?Promise.resolve(f()):Promise.resolve(k("BOLOS","1.0.0"))));const n=[v(),g(),T(),T(),{output:{currentApp:"BOLOS",currentAppVersion:"1.0.0"},status:c.Completed}];d(e,n,a(),{onDone:o,onError:r})})),it("should timeout with a locked device",()=>new Promise((o,r)=>{const e=new p({input:{unlockTimeout:200}});V.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"},installedApps:[],deviceModelId:l.NANO_X,isSecureConnectionAllowed:!1}),h.mockImplementation(n=>n.name==="getOsVersion"?Promise.resolve(O()):Promise.resolve(f()));const t=[v(),g(),{error:new I("Device locked."),status:c.Error}];d(e,t,a(),{onDone:o,onError:r})})),it("should run the device action with an old firmware not supporting GetAppAndVersion",()=>new Promise((o,r)=>{const e=new p({input:{unlockTimeout:500}});V.mockReturnValue({sessionStateType:s.Connected,deviceStatus:i.CONNECTED,deviceModelId:l.NANO_X}),h.mockImplementation(n=>n.name==="getOsVersion"?Promise.resolve(O()):Promise.resolve(y({error:new L({...x["6e00"],errorCode:"6e00"})})));const t=[...w(),{output:{currentApp:"BOLOS",currentAppVersion:"0.0.0"},status:c.Completed}];d(e,t,a(),{onDone:o,onError:r})}))}),describe("success cases",()=>{it("should return the device status if the device is unlocked",()=>new Promise((o,r)=>{S.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.CONNECTED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),u.mockResolvedValue(k("BOLOS","1.0.0"));const e=new p({input:{unlockTimeout:void 0}});vi.spyOn(e,"extractDependencies").mockReturnValue(A());const t=[...w(),{status:c.Completed,output:{currentApp:"BOLOS",currentAppVersion:"1.0.0"}}];d(e,t,a(),{onDone:()=>{expect(R).toHaveBeenCalledWith({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.CONNECTED,currentApp:{name:"BOLOS",version:"1.0.0"}}),o()},onError:r})})),it("should return the device status and update session if the device is not ready",()=>new Promise((o,r)=>{let e={sessionStateType:s.Connected,deviceStatus:i.CONNECTED,deviceModelId:l.NANO_X};S.mockImplementation(()=>e),R.mockImplementation(N=>(e=N,N)),u.mockResolvedValue(k("BOLOS","1.0.0"));const t=new p({input:{unlockTimeout:void 0}});vi.spyOn(t,"extractDependencies").mockReturnValue(A());const n=P(l.NANO_X),m=[...w(),{status:c.Completed,output:{currentApp:"BOLOS",currentAppVersion:"1.0.0"}}];d(t,m,a(),{onDone:()=>{expect(R).toHaveBeenCalledWith({deviceModelId:l.NANO_X,sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.CONNECTED,currentApp:{name:"BOLOS",version:"1.0.0"},installedApps:[],isSecureConnectionAllowed:n.secureElementFlags.isSecureConnectionAllowed,firmwareVersion:{mcu:n.mcuSephVersion,bootloader:n.mcuBootloaderVersion,os:n.seVersion,metadata:n}}),o()},onError:r})})),it("should not fetch the OS version when an app other than BOLOS is open",()=>new Promise((o,r)=>{S.mockReturnValue({sessionStateType:s.Connected,deviceStatus:i.CONNECTED,deviceModelId:l.NANO_X}),u.mockResolvedValue(k("Bitcoin","2.1.0"));const e=new p({input:{unlockTimeout:void 0}});vi.spyOn(e,"extractDependencies").mockReturnValue(A());const t=[v(),{status:c.Completed,output:{currentApp:"Bitcoin",currentAppVersion:"2.1.0"}}];d(e,t,a(),{onDone:()=>{expect(D).not.toHaveBeenCalled(),o()},onError:r})})),it("should return the device status if the device is locked and the user unlocks the device",()=>new Promise((o,r)=>{S.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),u.mockResolvedValueOnce(f()).mockResolvedValueOnce(k("BOLOS","1.0.0")),C.mockImplementation(()=>new E(n=>{const m=B(50).subscribe({next:N=>{N>2?(n.next({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.CONNECTED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),n.complete()):n.next({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}})}});return()=>{m.unsubscribe()}}));const e=new p({input:{unlockTimeout:500}});vi.spyOn(e,"extractDependencies").mockReturnValue(A());const t=[v(),g(),T(),T(),{status:c.Completed,output:{currentApp:"BOLOS",currentAppVersion:"1.0.0"}}];d(e,t,a(),{onDone:o,onError:r})}))}),describe("errors cases",()=>{it("should end in an error if the device is not onboarded",()=>new Promise((o,r)=>{S.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.CONNECTED,currentApp:{name:"BOLOS",version:"1.0.0"},installedApps:[],deviceModelId:l.NANO_X,isSecureConnectionAllowed:!1}),u.mockResolvedValue(k("BOLOS","1.0.0")),D.mockResolvedValue(O({secureElementFlags:{...P().secureElementFlags,isOnboarded:!1}}));const e=new p({input:{unlockTimeout:500}});vi.spyOn(e,"extractDependencies").mockReturnValue(A());const t=[...w(),{error:new _,status:c.Error}];d(e,t,a(),{onDone:o,onError:r})})),it("should end in an error if the device is locked and the user does not unlock",()=>new Promise((o,r)=>{S.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),u.mockResolvedValue(f()),C.mockImplementation(()=>new E(n=>{n.error(new I("Device locked."))})),W.mockImplementation(()=>new E(n=>{const m=B(200).subscribe({next:()=>{n.next({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"},installedApps:[],deviceModelId:l.NANO_X,isSecureConnectionAllowed:!1})}});return()=>{m.unsubscribe()}}));const e=new p({input:{unlockTimeout:500}});vi.spyOn(e,"extractDependencies").mockReturnValue(A());const t=[v(),g(),{error:new I("Device locked."),status:c.Error}];d(e,t,a(),{onDone:o,onError:r})})),it("should end in an error if the GetAppAndVersion command fails",()=>new Promise((o,r)=>{S.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}});const e=new L({...x[5501],errorCode:"5501"});u.mockResolvedValue(y({error:e})),C.mockImplementation(()=>new E(m=>{m.complete()}));const t=new p({input:{unlockTimeout:500}});vi.spyOn(t,"extractDependencies").mockReturnValue(A());const n=[v(),{error:e,status:c.Error}];d(t,n,a(),{onDone:o,onError:r})})),it("should end in an error if getAppAndVersion actor throws an error",()=>new Promise((o,r)=>{S.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),u.mockImplementation(()=>{throw new M("error")}),C.mockImplementation(()=>new E(n=>{n.complete()}));const e=new p({input:{unlockTimeout:500}});vi.spyOn(e,"extractDependencies").mockReturnValue(A());const t=[v(),{error:new M("error"),status:c.Error}];d(e,t,a(),{onDone:o,onError:r})}))}),it("should emit a stopped state if the action is cancelled",()=>new Promise((o,r)=>{V.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.CONNECTED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"},installedApps:[],deviceModelId:l.NANO_X,isSecureConnectionAllowed:!1}),h.mockImplementation(m=>m.name==="getOsVersion"?Promise.resolve(O()):Promise.resolve(k("BOLOS","1.0.0")));const e=new p({input:{unlockTimeout:500}}),t=[v(),{status:c.Stopped}],{cancel:n}=d(e,t,a(),{onDone:o,onError:r});n()}))});
|
|
1
|
+
import{interval as B,Observable as w}from"rxjs";import{CommandResultFactory as y}from"../../../command/model/CommandResult";import{getOsVersionCommandResponseMockBuilder as I}from"../../../command/os/__mocks__/GetOsVersionCommand";import{GLOBAL_ERRORS as x,GlobalCommandError as L}from"../../../command/utils/GlobalCommandError";import{DeviceModelId as l}from"../../../device/DeviceModel";import{DeviceStatus as i}from"../../../device/DeviceStatus";import{makeDeviceActionInternalApiMock as a}from"../../../device-action/__test-utils__/makeInternalApi";import{testDeviceActionStates as d}from"../../../device-action/__test-utils__/testDeviceActionStates";import{DeviceActionStatus as c}from"../../../device-action/model/DeviceActionState";import{UserInteractionRequired as P}from"../../../device-action/model/UserInteractionRequired";import{DeviceLockedError as b,DeviceNotOnboardedError as _,UnknownDAError as M}from"../../../device-action/os/Errors";import{DeviceSessionStateType as s}from"../../../device-session/DeviceSessionState";import{GetDeviceStatusDeviceAction as p}from"./GetDeviceStatusDeviceAction";import{getDeviceStatusDAStateStep as G}from"./types";const k=(u={},D=l.NANO_X)=>y({data:I(D,u)}),O=(u,D)=>y({data:{name:u,version:D}}),f=()=>y({error:new L({...x[5515],errorCode:"5515"})}),S=()=>({intermediateValue:{requiredUserInteraction:P.None,step:G.ONBOARD_CHECK},status:c.Pending}),C=()=>[S(),S()],g=()=>({intermediateValue:{requiredUserInteraction:P.UnlockDevice,step:G.UNLOCK_DEVICE},status:c.Pending}),T=()=>({intermediateValue:{requiredUserInteraction:P.None,step:G.UNLOCK_DEVICE},status:c.Pending});describe("GetDeviceStatusDeviceAction",()=>{const u=vi.fn(),D=vi.fn(),v=vi.fn(),h=vi.fn(),R=vi.fn();function A(){return{getAppAndVersion:u,getOsVersion:D,getDeviceSessionState:v,waitForDeviceUnlock:h,setDeviceSessionState:R}}const{sendCommand:E,getDeviceSessionState:V,getDeviceSessionStateObservable:W}=a();beforeEach(()=>{vi.resetAllMocks(),D.mockResolvedValue(k())}),describe("without overriding `extractDependencies`",()=>{it("should run the device action with an unlocked device",()=>new Promise((n,o)=>{const e=new p({input:{unlockTimeout:500}});V.mockReturnValue({sessionStateType:s.Connected,deviceStatus:i.CONNECTED,deviceModelId:l.NANO_X}),E.mockImplementation(r=>r.name==="getOsVersion"?Promise.resolve(k()):Promise.resolve(O("BOLOS","1.0.0")));const t=[...C(),{output:{currentApp:"BOLOS",currentAppVersion:"1.0.0"},status:c.Completed}];d(e,t,a(),{onDone:n,onError:o})})),it("should run the device action with a locked device",()=>new Promise((n,o)=>{const e=new p({input:{unlockTimeout:1500}});V.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"},installedApps:[],deviceModelId:l.NANO_X,isSecureConnectionAllowed:!1});let t=0;E.mockImplementation(m=>m.name==="getOsVersion"?Promise.resolve(k()):(t+=1,t===1?Promise.resolve(f()):Promise.resolve(O("BOLOS","1.0.0"))));const r=[S(),g(),T(),T(),{output:{currentApp:"BOLOS",currentAppVersion:"1.0.0"},status:c.Completed}];d(e,r,a(),{onDone:n,onError:o})})),it("should timeout with a locked device",()=>new Promise((n,o)=>{const e=new p({input:{unlockTimeout:200}});V.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"},installedApps:[],deviceModelId:l.NANO_X,isSecureConnectionAllowed:!1}),E.mockImplementation(r=>r.name==="getOsVersion"?Promise.resolve(k()):Promise.resolve(f()));const t=[S(),g(),{error:new b("Device locked."),status:c.Error}];d(e,t,a(),{onDone:n,onError:o})})),it("should run the device action with an old firmware not supporting GetAppAndVersion",()=>new Promise((n,o)=>{const e=new p({input:{unlockTimeout:500}});V.mockReturnValue({sessionStateType:s.Connected,deviceStatus:i.CONNECTED,deviceModelId:l.NANO_X}),E.mockImplementation(r=>r.name==="getOsVersion"?Promise.resolve(k()):Promise.resolve(y({error:new L({...x["6e00"],errorCode:"6e00"})})));const t=[...C(),{output:{currentApp:"BOLOS",currentAppVersion:"0.0.0"},status:c.Completed}];d(e,t,a(),{onDone:n,onError:o})}))}),describe("success cases",()=>{it("should return the device status if the device is unlocked",()=>new Promise((n,o)=>{v.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.CONNECTED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),u.mockResolvedValue(O("BOLOS","1.0.0"));const e=new p({input:{unlockTimeout:void 0}});vi.spyOn(e,"extractDependencies").mockReturnValue(A());const t=[...C(),{status:c.Completed,output:{currentApp:"BOLOS",currentAppVersion:"1.0.0"}}];d(e,t,a(),{onDone:()=>{expect(R).toHaveBeenCalledWith({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.CONNECTED,currentApp:{name:"BOLOS",version:"1.0.0"}}),n()},onError:o})})),it("should return the device status and update session if the device is not ready",()=>new Promise((n,o)=>{let e={sessionStateType:s.Connected,deviceStatus:i.CONNECTED,deviceModelId:l.NANO_X};v.mockImplementation(()=>e),R.mockImplementation(N=>(e=N,N)),u.mockResolvedValue(O("BOLOS","1.0.0"));const t=new p({input:{unlockTimeout:void 0}});vi.spyOn(t,"extractDependencies").mockReturnValue(A());const r=I(l.NANO_X),m=[...C(),{status:c.Completed,output:{currentApp:"BOLOS",currentAppVersion:"1.0.0"}}];d(t,m,a(),{onDone:()=>{expect(R).toHaveBeenCalledWith({deviceModelId:l.NANO_X,sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.CONNECTED,currentApp:{name:"BOLOS",version:"1.0.0"},installedApps:[],isSecureConnectionAllowed:r.secureElementFlags.isSecureConnectionAllowed,firmwareVersion:{mcu:r.mcuSephVersion,bootloader:r.mcuBootloaderVersion,os:r.seVersion,metadata:r}}),n()},onError:o})})),it("should not fetch the OS version when an app other than BOLOS is open",()=>new Promise((n,o)=>{v.mockReturnValue({sessionStateType:s.Connected,deviceStatus:i.CONNECTED,deviceModelId:l.NANO_X}),u.mockResolvedValue(O("Bitcoin","2.1.0"));const e=new p({input:{unlockTimeout:void 0}});vi.spyOn(e,"extractDependencies").mockReturnValue(A());const t=[S(),{status:c.Completed,output:{currentApp:"Bitcoin",currentAppVersion:"2.1.0"}}];d(e,t,a(),{onDone:()=>{expect(D).not.toHaveBeenCalled(),n()},onError:o})})),it("GIVEN a non-onboarded device WHEN checking the device status THEN it returns the device status by default",()=>new Promise((n,o)=>{v.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.CONNECTED,currentApp:{name:"BOLOS",version:"1.0.0"},installedApps:[],deviceModelId:l.NANO_X,isSecureConnectionAllowed:!1}),u.mockResolvedValue(O("BOLOS","1.0.0")),D.mockResolvedValue(k({secureElementFlags:{...I().secureElementFlags,isOnboarded:!1}}));const e=new p({input:{unlockTimeout:void 0}});vi.spyOn(e,"extractDependencies").mockReturnValue(A());const t=[...C(),{status:c.Completed,output:{currentApp:"BOLOS",currentAppVersion:"1.0.0"}}];d(e,t,a(),{onDone:n,onError:o})})),it("should return the device status if the device is locked and the user unlocks the device",()=>new Promise((n,o)=>{v.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),u.mockResolvedValueOnce(f()).mockResolvedValueOnce(O("BOLOS","1.0.0")),h.mockImplementation(()=>new w(r=>{const m=B(50).subscribe({next:N=>{N>2?(r.next({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.CONNECTED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),r.complete()):r.next({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}})}});return()=>{m.unsubscribe()}}));const e=new p({input:{unlockTimeout:500}});vi.spyOn(e,"extractDependencies").mockReturnValue(A());const t=[S(),g(),T(),T(),{status:c.Completed,output:{currentApp:"BOLOS",currentAppVersion:"1.0.0"}}];d(e,t,a(),{onDone:n,onError:o})}))}),describe("errors cases",()=>{it("GIVEN a non-onboarded device and the non-onboarded allowance is disabled WHEN checking the device status THEN it returns a not-onboarded error",()=>new Promise((n,o)=>{v.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.CONNECTED,currentApp:{name:"BOLOS",version:"1.0.0"},installedApps:[],deviceModelId:l.NANO_X,isSecureConnectionAllowed:!1}),u.mockResolvedValue(O("BOLOS","1.0.0")),D.mockResolvedValue(k({secureElementFlags:{...I().secureElementFlags,isOnboarded:!1}}));const e=new p({input:{unlockTimeout:500,allowNonOnboardedDevice:!1}});vi.spyOn(e,"extractDependencies").mockReturnValue(A());const t=[...C(),{error:new _,status:c.Error}];d(e,t,a(),{onDone:n,onError:o})})),it("should end in an error if the device is locked and the user does not unlock",()=>new Promise((n,o)=>{v.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),u.mockResolvedValue(f()),h.mockImplementation(()=>new w(r=>{r.error(new b("Device locked."))})),W.mockImplementation(()=>new w(r=>{const m=B(200).subscribe({next:()=>{r.next({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"},installedApps:[],deviceModelId:l.NANO_X,isSecureConnectionAllowed:!1})}});return()=>{m.unsubscribe()}}));const e=new p({input:{unlockTimeout:500}});vi.spyOn(e,"extractDependencies").mockReturnValue(A());const t=[S(),g(),{error:new b("Device locked."),status:c.Error}];d(e,t,a(),{onDone:n,onError:o})})),it("should end in an error if the GetAppAndVersion command fails",()=>new Promise((n,o)=>{v.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}});const e=new L({...x[5501],errorCode:"5501"});u.mockResolvedValue(y({error:e})),h.mockImplementation(()=>new w(m=>{m.complete()}));const t=new p({input:{unlockTimeout:500}});vi.spyOn(t,"extractDependencies").mockReturnValue(A());const r=[S(),{error:e,status:c.Error}];d(t,r,a(),{onDone:n,onError:o})})),it("should end in an error if getAppAndVersion actor throws an error",()=>new Promise((n,o)=>{v.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),u.mockImplementation(()=>{throw new M("error")}),h.mockImplementation(()=>new w(r=>{r.complete()}));const e=new p({input:{unlockTimeout:500}});vi.spyOn(e,"extractDependencies").mockReturnValue(A());const t=[S(),{error:new M("error"),status:c.Error}];d(e,t,a(),{onDone:n,onError:o})}))}),it("should emit a stopped state if the action is cancelled",()=>new Promise((n,o)=>{V.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.CONNECTED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"},installedApps:[],deviceModelId:l.NANO_X,isSecureConnectionAllowed:!1}),E.mockImplementation(m=>m.name==="getOsVersion"?Promise.resolve(k()):Promise.resolve(O("BOLOS","1.0.0")));const e=new p({input:{unlockTimeout:500}}),t=[S(),{status:c.Stopped}],{cancel:r}=d(e,t,a(),{onDone:n,onError:o});r()}))});
|
|
2
2
|
//# sourceMappingURL=GetDeviceStatusDeviceAction.test.js.map
|
package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { interval, Observable } from \"rxjs\";\n\nimport { CommandResultFactory } from \"@api/command/model/CommandResult\";\nimport { getOsVersionCommandResponseMockBuilder } from \"@api/command/os/__mocks__/GetOsVersionCommand\";\nimport { type GetOsVersionResponse } from \"@api/command/os/GetOsVersionCommand\";\nimport {\n GLOBAL_ERRORS,\n GlobalCommandError,\n} from \"@api/command/utils/GlobalCommandError\";\nimport { DeviceModelId } from \"@api/device/DeviceModel\";\nimport { DeviceStatus } from \"@api/device/DeviceStatus\";\nimport { makeDeviceActionInternalApiMock } from \"@api/device-action/__test-utils__/makeInternalApi\";\nimport { testDeviceActionStates } from \"@api/device-action/__test-utils__/testDeviceActionStates\";\nimport { DeviceActionStatus } from \"@api/device-action/model/DeviceActionState\";\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport {\n DeviceLockedError,\n DeviceNotOnboardedError,\n UnknownDAError,\n} from \"@api/device-action/os/Errors\";\nimport { DeviceSessionStateType } from \"@api/device-session/DeviceSessionState\";\n\nimport { GetDeviceStatusDeviceAction } from \"./GetDeviceStatusDeviceAction\";\nimport {\n type GetDeviceStatusDAState,\n getDeviceStatusDAStateStep,\n} from \"./types\";\n\nconst osVersionCommandResult = (\n props: Partial<GetOsVersionResponse> = {},\n deviceModelId: DeviceModelId = DeviceModelId.NANO_X,\n) =>\n CommandResultFactory({\n data: getOsVersionCommandResponseMockBuilder(deviceModelId, props),\n });\n\nconst appAndVersionResult = (name: string, version: string) =>\n CommandResultFactory({\n data: {\n name,\n version,\n },\n });\n\nconst lockedErrorResult = () =>\n CommandResultFactory({\n error: new GlobalCommandError({\n ...GLOBAL_ERRORS[\"5515\"],\n errorCode: \"5515\",\n }),\n });\n\nconst onboardCheckPendingState = (): GetDeviceStatusDAState => ({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: getDeviceStatusDAStateStep.ONBOARD_CHECK,\n },\n status: DeviceActionStatus.Pending,\n});\n\nconst onboardCheckPendingStatesWithOsVersionFetch =\n (): Array<GetDeviceStatusDAState> => [\n onboardCheckPendingState(),\n onboardCheckPendingState(),\n ];\n\nconst unlockRequestedPendingState = (): GetDeviceStatusDAState => ({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.UnlockDevice,\n step: getDeviceStatusDAStateStep.UNLOCK_DEVICE,\n },\n status: DeviceActionStatus.Pending,\n});\n\nconst unlockResolvedPendingState = (): GetDeviceStatusDAState => ({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: getDeviceStatusDAStateStep.UNLOCK_DEVICE,\n },\n status: DeviceActionStatus.Pending,\n});\n\ndescribe(\"GetDeviceStatusDeviceAction\", () => {\n const getAppAndVersionMock = vi.fn();\n const getOsVersionMock = vi.fn();\n const getDeviceSessionStateMock = vi.fn();\n const waitForDeviceUnlockMock = vi.fn();\n const setDeviceSessionState = vi.fn();\n\n function extractDependenciesMock() {\n return {\n getAppAndVersion: getAppAndVersionMock,\n getOsVersion: getOsVersionMock,\n getDeviceSessionState: getDeviceSessionStateMock,\n waitForDeviceUnlock: waitForDeviceUnlockMock,\n setDeviceSessionState: setDeviceSessionState,\n };\n }\n\n const {\n sendCommand: sendCommandMock,\n getDeviceSessionState: apiGetDeviceSessionStateMock,\n getDeviceSessionStateObservable: apiGetDeviceSessionStateObservableMock,\n } = makeDeviceActionInternalApiMock();\n beforeEach(() => {\n vi.resetAllMocks();\n getOsVersionMock.mockResolvedValue(osVersionCommandResult());\n });\n\n describe(\"without overriding `extractDependencies`\", () => {\n it(\"should run the device action with an unlocked device\", () =>\n new Promise<void>((resolve, reject) => {\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 500 },\n });\n\n apiGetDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: DeviceModelId.NANO_X,\n });\n\n // GetAppAndVersion is called first to determine the current app, then\n // GetOsVersion is called because the app is BOLOS (dashboard).\n sendCommandMock.mockImplementation((command) =>\n command.name === \"getOsVersion\"\n ? Promise.resolve(osVersionCommandResult())\n : Promise.resolve(appAndVersionResult(\"BOLOS\", \"1.0.0\")),\n );\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n ...onboardCheckPendingStatesWithOsVersionFetch(),\n {\n output: {\n currentApp: \"BOLOS\",\n currentAppVersion: \"1.0.0\",\n },\n status: DeviceActionStatus.Completed,\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should run the device action with a locked device\", () =>\n new Promise<void>((resolve, reject) => {\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 1500 },\n });\n\n apiGetDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.LOCKED,\n currentApp: { name: \"mockedCurrentApp\", version: \"1.0.0\" },\n installedApps: [],\n deviceModelId: DeviceModelId.NANO_X,\n isSecureConnectionAllowed: false,\n });\n\n // First GetAppAndVersion fails because the device is locked, then it\n // succeeds (BOLOS) once unlocked, then GetOsVersion is fetched.\n let appCall = 0;\n sendCommandMock.mockImplementation((command) => {\n if (command.name === \"getOsVersion\") {\n return Promise.resolve(osVersionCommandResult());\n }\n appCall += 1;\n if (appCall === 1) {\n return Promise.resolve(lockedErrorResult());\n }\n return Promise.resolve(appAndVersionResult(\"BOLOS\", \"1.0.0\"));\n });\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n onboardCheckPendingState(),\n unlockRequestedPendingState(),\n unlockResolvedPendingState(),\n unlockResolvedPendingState(),\n {\n output: {\n currentApp: \"BOLOS\",\n currentAppVersion: \"1.0.0\",\n },\n status: DeviceActionStatus.Completed,\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should timeout with a locked device\", () =>\n new Promise<void>((resolve, reject) => {\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 200 },\n });\n\n apiGetDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.LOCKED,\n currentApp: { name: \"mockedCurrentApp\", version: \"1.0.0\" },\n installedApps: [],\n deviceModelId: DeviceModelId.NANO_X,\n isSecureConnectionAllowed: false,\n });\n\n // GetAppAndVersion always reports a locked device, so the unlock\n // polling times out.\n sendCommandMock.mockImplementation((command) =>\n command.name === \"getOsVersion\"\n ? Promise.resolve(osVersionCommandResult())\n : Promise.resolve(lockedErrorResult()),\n );\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n onboardCheckPendingState(),\n unlockRequestedPendingState(),\n {\n error: new DeviceLockedError(\"Device locked.\"),\n status: DeviceActionStatus.Error,\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should run the device action with an old firmware not supporting GetAppAndVersion\", () =>\n new Promise<void>((resolve, reject) => {\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 500 },\n });\n\n apiGetDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: DeviceModelId.NANO_X,\n });\n\n // GetAppAndVersion is not supported (CLA_NOT_SUPPORTED), which means we\n // are on the dashboard of an old firmware: the current app is BOLOS so\n // the OS version can still be fetched.\n sendCommandMock.mockImplementation((command) =>\n command.name === \"getOsVersion\"\n ? Promise.resolve(osVersionCommandResult())\n : Promise.resolve(\n CommandResultFactory({\n error: new GlobalCommandError({\n ...GLOBAL_ERRORS[\"6e00\"],\n errorCode: \"6e00\",\n }),\n }),\n ),\n );\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n ...onboardCheckPendingStatesWithOsVersionFetch(),\n {\n output: {\n currentApp: \"BOLOS\",\n currentAppVersion: \"0.0.0\",\n },\n status: DeviceActionStatus.Completed,\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n });\n\n describe(\"success cases\", () => {\n it(\"should return the device status if the device is unlocked\", () =>\n new Promise<void>((resolve, reject) => {\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: { name: \"mockedCurrentApp\", version: \"1.0.0\" },\n });\n\n getAppAndVersionMock.mockResolvedValue(\n appAndVersionResult(\"BOLOS\", \"1.0.0\"),\n );\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: undefined },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n ...onboardCheckPendingStatesWithOsVersionFetch(),\n {\n status: DeviceActionStatus.Completed,\n output: {\n currentApp: \"BOLOS\",\n currentAppVersion: \"1.0.0\",\n },\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: () => {\n // Session should be updated with current app\n expect(setDeviceSessionState).toHaveBeenCalledWith({\n sessionStateType:\n DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: {\n name: \"BOLOS\",\n version: \"1.0.0\",\n },\n });\n resolve();\n },\n onError: reject,\n },\n );\n }));\n\n it(\"should return the device status and update session if the device is not ready\", () =>\n new Promise<void>((resolve, reject) => {\n // The session state is stateful so the firmware version enrichment from\n // the OS version (which reads back the ready state) can be observed.\n let sessionState: object = {\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: DeviceModelId.NANO_X,\n };\n getDeviceSessionStateMock.mockImplementation(() => sessionState);\n setDeviceSessionState.mockImplementation((state) => {\n sessionState = state;\n return state;\n });\n\n getAppAndVersionMock.mockResolvedValue(\n appAndVersionResult(\"BOLOS\", \"1.0.0\"),\n );\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: undefined },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const osVersionData = getOsVersionCommandResponseMockBuilder(\n DeviceModelId.NANO_X,\n );\n const expectedStates: Array<GetDeviceStatusDAState> = [\n ...onboardCheckPendingStatesWithOsVersionFetch(),\n {\n status: DeviceActionStatus.Completed,\n output: {\n currentApp: \"BOLOS\",\n currentAppVersion: \"1.0.0\",\n },\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: () => {\n // Session should be set as ready if GetAppAndVersionCommand was successful\n // and then enriched with the firmware version from the OS version.\n expect(setDeviceSessionState).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.NANO_X,\n sessionStateType:\n DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: {\n name: \"BOLOS\",\n version: \"1.0.0\",\n },\n installedApps: [],\n isSecureConnectionAllowed:\n osVersionData.secureElementFlags.isSecureConnectionAllowed,\n firmwareVersion: {\n mcu: osVersionData.mcuSephVersion,\n bootloader: osVersionData.mcuBootloaderVersion,\n os: osVersionData.seVersion,\n metadata: osVersionData,\n },\n });\n resolve();\n },\n onError: reject,\n },\n );\n }));\n\n it(\"should not fetch the OS version when an app other than BOLOS is open\", () =>\n new Promise<void>((resolve, reject) => {\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: DeviceModelId.NANO_X,\n });\n\n // An application is open: the device is necessarily onboarded and the\n // OS version cannot be read outside of the dashboard.\n getAppAndVersionMock.mockResolvedValue(\n appAndVersionResult(\"Bitcoin\", \"2.1.0\"),\n );\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: undefined },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n onboardCheckPendingState(),\n {\n status: DeviceActionStatus.Completed,\n output: {\n currentApp: \"Bitcoin\",\n currentAppVersion: \"2.1.0\",\n },\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: () => {\n expect(getOsVersionMock).not.toHaveBeenCalled();\n resolve();\n },\n onError: reject,\n },\n );\n }));\n\n it(\"should return the device status if the device is locked and the user unlocks the device\", () =>\n new Promise<void>((resolve, reject) => {\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.LOCKED,\n currentApp: { name: \"mockedCurrentApp\", version: \"1.0.0\" },\n });\n\n getAppAndVersionMock\n .mockResolvedValueOnce(lockedErrorResult())\n .mockResolvedValueOnce(appAndVersionResult(\"BOLOS\", \"1.0.0\"));\n\n waitForDeviceUnlockMock.mockImplementation(\n () =>\n new Observable((o) => {\n const inner = interval(50).subscribe({\n next: (i) => {\n if (i > 2) {\n o.next({\n sessionStateType:\n DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: {\n name: \"mockedCurrentApp\",\n version: \"1.0.0\",\n },\n });\n o.complete();\n } else {\n o.next({\n sessionStateType:\n DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.LOCKED,\n currentApp: {\n name: \"mockedCurrentApp\",\n version: \"1.0.0\",\n },\n });\n }\n },\n });\n\n return () => {\n inner.unsubscribe();\n };\n }),\n );\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 500 },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n onboardCheckPendingState(),\n unlockRequestedPendingState(),\n unlockResolvedPendingState(),\n unlockResolvedPendingState(),\n {\n status: DeviceActionStatus.Completed,\n output: {\n currentApp: \"BOLOS\",\n currentAppVersion: \"1.0.0\",\n },\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n });\n\n describe(\"errors cases\", () => {\n it(\"should end in an error if the device is not onboarded\", () =>\n new Promise<void>((resolve, reject) => {\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: { name: \"BOLOS\", version: \"1.0.0\" },\n installedApps: [],\n deviceModelId: DeviceModelId.NANO_X,\n isSecureConnectionAllowed: false,\n });\n // A non-onboarded device sits on the dashboard (BOLOS), so the app check\n // succeeds and the OS version reveals the onboarding status.\n getAppAndVersionMock.mockResolvedValue(\n appAndVersionResult(\"BOLOS\", \"1.0.0\"),\n );\n getOsVersionMock.mockResolvedValue(\n osVersionCommandResult({\n secureElementFlags: {\n ...getOsVersionCommandResponseMockBuilder().secureElementFlags,\n isOnboarded: false,\n },\n }),\n );\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 500 },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n ...onboardCheckPendingStatesWithOsVersionFetch(),\n {\n error: new DeviceNotOnboardedError(),\n status: DeviceActionStatus.Error,\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should end in an error if the device is locked and the user does not unlock\", () =>\n new Promise<void>((resolve, reject) => {\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.LOCKED,\n currentApp: { name: \"mockedCurrentApp\", version: \"1.0.0\" },\n });\n\n getAppAndVersionMock.mockResolvedValue(lockedErrorResult());\n\n waitForDeviceUnlockMock.mockImplementation(\n () =>\n new Observable((o) => {\n o.error(new DeviceLockedError(\"Device locked.\"));\n }),\n );\n\n apiGetDeviceSessionStateObservableMock.mockImplementation(\n () =>\n new Observable((o) => {\n const inner = interval(200).subscribe({\n next: () => {\n o.next({\n sessionStateType:\n DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.LOCKED,\n currentApp: { name: \"mockedCurrentApp\", version: \"1.0.0\" },\n installedApps: [],\n deviceModelId: DeviceModelId.NANO_X,\n isSecureConnectionAllowed: false,\n });\n },\n });\n\n return () => {\n inner.unsubscribe();\n };\n }),\n );\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 500 },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n onboardCheckPendingState(),\n unlockRequestedPendingState(),\n {\n error: new DeviceLockedError(\"Device locked.\"),\n status: DeviceActionStatus.Error,\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should end in an error if the GetAppAndVersion command fails\", () =>\n new Promise<void>((resolve, reject) => {\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.LOCKED,\n currentApp: { name: \"mockedCurrentApp\", version: \"1.0.0\" },\n });\n\n const error = new GlobalCommandError({\n ...GLOBAL_ERRORS[\"5501\"],\n errorCode: \"5501\",\n });\n\n getAppAndVersionMock.mockResolvedValue(CommandResultFactory({ error }));\n\n waitForDeviceUnlockMock.mockImplementation(\n () =>\n new Observable((o) => {\n o.complete();\n }),\n );\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 500 },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n onboardCheckPendingState(),\n {\n error,\n status: DeviceActionStatus.Error,\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should end in an error if getAppAndVersion actor throws an error\", () =>\n new Promise<void>((resolve, reject) => {\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.LOCKED,\n currentApp: { name: \"mockedCurrentApp\", version: \"1.0.0\" },\n });\n\n getAppAndVersionMock.mockImplementation(() => {\n throw new UnknownDAError(\"error\");\n });\n\n waitForDeviceUnlockMock.mockImplementation(\n () =>\n new Observable((o) => {\n o.complete();\n }),\n );\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 500 },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n onboardCheckPendingState(),\n {\n error: new UnknownDAError(\"error\"),\n status: DeviceActionStatus.Error,\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n });\n\n it(\"should emit a stopped state if the action is cancelled\", () =>\n new Promise<void>((resolve, reject) => {\n apiGetDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: { name: \"mockedCurrentApp\", version: \"1.0.0\" },\n installedApps: [],\n deviceModelId: DeviceModelId.NANO_X,\n isSecureConnectionAllowed: false,\n });\n\n sendCommandMock.mockImplementation((command) =>\n command.name === \"getOsVersion\"\n ? Promise.resolve(osVersionCommandResult())\n : Promise.resolve(appAndVersionResult(\"BOLOS\", \"1.0.0\")),\n );\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 500 },\n });\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n onboardCheckPendingState(),\n {\n status: DeviceActionStatus.Stopped,\n },\n ];\n\n const { cancel } = testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n cancel();\n }));\n});\n"],
|
|
5
|
-
"mappings": "AAAA,OAAS,YAAAA,EAAU,cAAAC,MAAkB,OAErC,OAAS,wBAAAC,MAA4B,mCACrC,OAAS,0CAAAC,MAA8C,gDAEvD,OACE,iBAAAC,EACA,sBAAAC,MACK,wCACP,OAAS,iBAAAC,MAAqB,0BAC9B,OAAS,gBAAAC,MAAoB,2BAC7B,OAAS,mCAAAC,MAAuC,oDAChD,OAAS,0BAAAC,MAA8B,2DACvC,OAAS,sBAAAC,MAA0B,6CACnC,OAAS,2BAAAC,MAA+B,mDACxC,OACE,qBAAAC,EACA,2BAAAC,EACA,kBAAAC,MACK,+BACP,OAAS,0BAAAC,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O,CAAC,CAC3D,EAEA,MAAMmB,EAA6B,IAAIxB,EAA4B,CACjE,MAAO,CAAE,cAAe,GAAI,CAC9B,CAAC,EAEK0B,EAAgD,CACpDjB,EAAyB,EACzB,CACE,OAAQf,EAAmB,OAC7B,CACF,EAEM,CAAE,OAAAyC,CAAO,EAAI1C,EACjB+B,EACAE,EACAlC,EAAgC,EAChC,CACE,OAAQ8B,EACR,QAASC,CACX,CACF,EACAY,EAAO,CACT,CAAC,CAAC,CACN,CAAC",
|
|
4
|
+
"sourcesContent": ["import { interval, Observable } from \"rxjs\";\n\nimport { CommandResultFactory } from \"@api/command/model/CommandResult\";\nimport { getOsVersionCommandResponseMockBuilder } from \"@api/command/os/__mocks__/GetOsVersionCommand\";\nimport { type GetOsVersionResponse } from \"@api/command/os/GetOsVersionCommand\";\nimport {\n GLOBAL_ERRORS,\n GlobalCommandError,\n} from \"@api/command/utils/GlobalCommandError\";\nimport { DeviceModelId } from \"@api/device/DeviceModel\";\nimport { DeviceStatus } from \"@api/device/DeviceStatus\";\nimport { makeDeviceActionInternalApiMock } from \"@api/device-action/__test-utils__/makeInternalApi\";\nimport { testDeviceActionStates } from \"@api/device-action/__test-utils__/testDeviceActionStates\";\nimport { DeviceActionStatus } from \"@api/device-action/model/DeviceActionState\";\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport {\n DeviceLockedError,\n DeviceNotOnboardedError,\n UnknownDAError,\n} from \"@api/device-action/os/Errors\";\nimport { DeviceSessionStateType } from \"@api/device-session/DeviceSessionState\";\n\nimport { GetDeviceStatusDeviceAction } from \"./GetDeviceStatusDeviceAction\";\nimport {\n type GetDeviceStatusDAState,\n getDeviceStatusDAStateStep,\n} from \"./types\";\n\nconst osVersionCommandResult = (\n props: Partial<GetOsVersionResponse> = {},\n deviceModelId: DeviceModelId = DeviceModelId.NANO_X,\n) =>\n CommandResultFactory({\n data: getOsVersionCommandResponseMockBuilder(deviceModelId, props),\n });\n\nconst appAndVersionResult = (name: string, version: string) =>\n CommandResultFactory({\n data: {\n name,\n version,\n },\n });\n\nconst lockedErrorResult = () =>\n CommandResultFactory({\n error: new GlobalCommandError({\n ...GLOBAL_ERRORS[\"5515\"],\n errorCode: \"5515\",\n }),\n });\n\nconst onboardCheckPendingState = (): GetDeviceStatusDAState => ({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: getDeviceStatusDAStateStep.ONBOARD_CHECK,\n },\n status: DeviceActionStatus.Pending,\n});\n\nconst onboardCheckPendingStatesWithOsVersionFetch =\n (): Array<GetDeviceStatusDAState> => [\n onboardCheckPendingState(),\n onboardCheckPendingState(),\n ];\n\nconst unlockRequestedPendingState = (): GetDeviceStatusDAState => ({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.UnlockDevice,\n step: getDeviceStatusDAStateStep.UNLOCK_DEVICE,\n },\n status: DeviceActionStatus.Pending,\n});\n\nconst unlockResolvedPendingState = (): GetDeviceStatusDAState => ({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: getDeviceStatusDAStateStep.UNLOCK_DEVICE,\n },\n status: DeviceActionStatus.Pending,\n});\n\ndescribe(\"GetDeviceStatusDeviceAction\", () => {\n const getAppAndVersionMock = vi.fn();\n const getOsVersionMock = vi.fn();\n const getDeviceSessionStateMock = vi.fn();\n const waitForDeviceUnlockMock = vi.fn();\n const setDeviceSessionState = vi.fn();\n\n function extractDependenciesMock() {\n return {\n getAppAndVersion: getAppAndVersionMock,\n getOsVersion: getOsVersionMock,\n getDeviceSessionState: getDeviceSessionStateMock,\n waitForDeviceUnlock: waitForDeviceUnlockMock,\n setDeviceSessionState: setDeviceSessionState,\n };\n }\n\n const {\n sendCommand: sendCommandMock,\n getDeviceSessionState: apiGetDeviceSessionStateMock,\n getDeviceSessionStateObservable: apiGetDeviceSessionStateObservableMock,\n } = makeDeviceActionInternalApiMock();\n beforeEach(() => {\n vi.resetAllMocks();\n getOsVersionMock.mockResolvedValue(osVersionCommandResult());\n });\n\n describe(\"without overriding `extractDependencies`\", () => {\n it(\"should run the device action with an unlocked device\", () =>\n new Promise<void>((resolve, reject) => {\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 500 },\n });\n\n apiGetDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: DeviceModelId.NANO_X,\n });\n\n // GetAppAndVersion is called first to determine the current app, then\n // GetOsVersion is called because the app is BOLOS (dashboard).\n sendCommandMock.mockImplementation((command) =>\n command.name === \"getOsVersion\"\n ? Promise.resolve(osVersionCommandResult())\n : Promise.resolve(appAndVersionResult(\"BOLOS\", \"1.0.0\")),\n );\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n ...onboardCheckPendingStatesWithOsVersionFetch(),\n {\n output: {\n currentApp: \"BOLOS\",\n currentAppVersion: \"1.0.0\",\n },\n status: DeviceActionStatus.Completed,\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should run the device action with a locked device\", () =>\n new Promise<void>((resolve, reject) => {\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 1500 },\n });\n\n apiGetDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.LOCKED,\n currentApp: { name: \"mockedCurrentApp\", version: \"1.0.0\" },\n installedApps: [],\n deviceModelId: DeviceModelId.NANO_X,\n isSecureConnectionAllowed: false,\n });\n\n // First GetAppAndVersion fails because the device is locked, then it\n // succeeds (BOLOS) once unlocked, then GetOsVersion is fetched.\n let appCall = 0;\n sendCommandMock.mockImplementation((command) => {\n if (command.name === \"getOsVersion\") {\n return Promise.resolve(osVersionCommandResult());\n }\n appCall += 1;\n if (appCall === 1) {\n return Promise.resolve(lockedErrorResult());\n }\n return Promise.resolve(appAndVersionResult(\"BOLOS\", \"1.0.0\"));\n });\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n onboardCheckPendingState(),\n unlockRequestedPendingState(),\n unlockResolvedPendingState(),\n unlockResolvedPendingState(),\n {\n output: {\n currentApp: \"BOLOS\",\n currentAppVersion: \"1.0.0\",\n },\n status: DeviceActionStatus.Completed,\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should timeout with a locked device\", () =>\n new Promise<void>((resolve, reject) => {\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 200 },\n });\n\n apiGetDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.LOCKED,\n currentApp: { name: \"mockedCurrentApp\", version: \"1.0.0\" },\n installedApps: [],\n deviceModelId: DeviceModelId.NANO_X,\n isSecureConnectionAllowed: false,\n });\n\n // GetAppAndVersion always reports a locked device, so the unlock\n // polling times out.\n sendCommandMock.mockImplementation((command) =>\n command.name === \"getOsVersion\"\n ? Promise.resolve(osVersionCommandResult())\n : Promise.resolve(lockedErrorResult()),\n );\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n onboardCheckPendingState(),\n unlockRequestedPendingState(),\n {\n error: new DeviceLockedError(\"Device locked.\"),\n status: DeviceActionStatus.Error,\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should run the device action with an old firmware not supporting GetAppAndVersion\", () =>\n new Promise<void>((resolve, reject) => {\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 500 },\n });\n\n apiGetDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: DeviceModelId.NANO_X,\n });\n\n // GetAppAndVersion is not supported (CLA_NOT_SUPPORTED), which means we\n // are on the dashboard of an old firmware: the current app is BOLOS so\n // the OS version can still be fetched.\n sendCommandMock.mockImplementation((command) =>\n command.name === \"getOsVersion\"\n ? Promise.resolve(osVersionCommandResult())\n : Promise.resolve(\n CommandResultFactory({\n error: new GlobalCommandError({\n ...GLOBAL_ERRORS[\"6e00\"],\n errorCode: \"6e00\",\n }),\n }),\n ),\n );\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n ...onboardCheckPendingStatesWithOsVersionFetch(),\n {\n output: {\n currentApp: \"BOLOS\",\n currentAppVersion: \"0.0.0\",\n },\n status: DeviceActionStatus.Completed,\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n });\n\n describe(\"success cases\", () => {\n it(\"should return the device status if the device is unlocked\", () =>\n new Promise<void>((resolve, reject) => {\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: { name: \"mockedCurrentApp\", version: \"1.0.0\" },\n });\n\n getAppAndVersionMock.mockResolvedValue(\n appAndVersionResult(\"BOLOS\", \"1.0.0\"),\n );\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: undefined },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n ...onboardCheckPendingStatesWithOsVersionFetch(),\n {\n status: DeviceActionStatus.Completed,\n output: {\n currentApp: \"BOLOS\",\n currentAppVersion: \"1.0.0\",\n },\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: () => {\n // Session should be updated with current app\n expect(setDeviceSessionState).toHaveBeenCalledWith({\n sessionStateType:\n DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: {\n name: \"BOLOS\",\n version: \"1.0.0\",\n },\n });\n resolve();\n },\n onError: reject,\n },\n );\n }));\n\n it(\"should return the device status and update session if the device is not ready\", () =>\n new Promise<void>((resolve, reject) => {\n // The session state is stateful so the firmware version enrichment from\n // the OS version (which reads back the ready state) can be observed.\n let sessionState: object = {\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: DeviceModelId.NANO_X,\n };\n getDeviceSessionStateMock.mockImplementation(() => sessionState);\n setDeviceSessionState.mockImplementation((state) => {\n sessionState = state;\n return state;\n });\n\n getAppAndVersionMock.mockResolvedValue(\n appAndVersionResult(\"BOLOS\", \"1.0.0\"),\n );\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: undefined },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const osVersionData = getOsVersionCommandResponseMockBuilder(\n DeviceModelId.NANO_X,\n );\n const expectedStates: Array<GetDeviceStatusDAState> = [\n ...onboardCheckPendingStatesWithOsVersionFetch(),\n {\n status: DeviceActionStatus.Completed,\n output: {\n currentApp: \"BOLOS\",\n currentAppVersion: \"1.0.0\",\n },\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: () => {\n // Session should be set as ready if GetAppAndVersionCommand was successful\n // and then enriched with the firmware version from the OS version.\n expect(setDeviceSessionState).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.NANO_X,\n sessionStateType:\n DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: {\n name: \"BOLOS\",\n version: \"1.0.0\",\n },\n installedApps: [],\n isSecureConnectionAllowed:\n osVersionData.secureElementFlags.isSecureConnectionAllowed,\n firmwareVersion: {\n mcu: osVersionData.mcuSephVersion,\n bootloader: osVersionData.mcuBootloaderVersion,\n os: osVersionData.seVersion,\n metadata: osVersionData,\n },\n });\n resolve();\n },\n onError: reject,\n },\n );\n }));\n\n it(\"should not fetch the OS version when an app other than BOLOS is open\", () =>\n new Promise<void>((resolve, reject) => {\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: DeviceModelId.NANO_X,\n });\n\n // An application is open: the device is necessarily onboarded and the\n // OS version cannot be read outside of the dashboard.\n getAppAndVersionMock.mockResolvedValue(\n appAndVersionResult(\"Bitcoin\", \"2.1.0\"),\n );\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: undefined },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n onboardCheckPendingState(),\n {\n status: DeviceActionStatus.Completed,\n output: {\n currentApp: \"Bitcoin\",\n currentAppVersion: \"2.1.0\",\n },\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: () => {\n expect(getOsVersionMock).not.toHaveBeenCalled();\n resolve();\n },\n onError: reject,\n },\n );\n }));\n\n it(\"GIVEN a non-onboarded device WHEN checking the device status THEN it returns the device status by default\", () =>\n new Promise<void>((resolve, reject) => {\n // GIVEN\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: { name: \"BOLOS\", version: \"1.0.0\" },\n installedApps: [],\n deviceModelId: DeviceModelId.NANO_X,\n isSecureConnectionAllowed: false,\n });\n getAppAndVersionMock.mockResolvedValue(\n appAndVersionResult(\"BOLOS\", \"1.0.0\"),\n );\n getOsVersionMock.mockResolvedValue(\n osVersionCommandResult({\n secureElementFlags: {\n ...getOsVersionCommandResponseMockBuilder().secureElementFlags,\n isOnboarded: false,\n },\n }),\n );\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: undefined },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n ...onboardCheckPendingStatesWithOsVersionFetch(),\n {\n status: DeviceActionStatus.Completed,\n output: {\n currentApp: \"BOLOS\",\n currentAppVersion: \"1.0.0\",\n },\n },\n ];\n\n // WHEN\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n // THEN\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should return the device status if the device is locked and the user unlocks the device\", () =>\n new Promise<void>((resolve, reject) => {\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.LOCKED,\n currentApp: { name: \"mockedCurrentApp\", version: \"1.0.0\" },\n });\n\n getAppAndVersionMock\n .mockResolvedValueOnce(lockedErrorResult())\n .mockResolvedValueOnce(appAndVersionResult(\"BOLOS\", \"1.0.0\"));\n\n waitForDeviceUnlockMock.mockImplementation(\n () =>\n new Observable((o) => {\n const inner = interval(50).subscribe({\n next: (i) => {\n if (i > 2) {\n o.next({\n sessionStateType:\n DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: {\n name: \"mockedCurrentApp\",\n version: \"1.0.0\",\n },\n });\n o.complete();\n } else {\n o.next({\n sessionStateType:\n DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.LOCKED,\n currentApp: {\n name: \"mockedCurrentApp\",\n version: \"1.0.0\",\n },\n });\n }\n },\n });\n\n return () => {\n inner.unsubscribe();\n };\n }),\n );\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 500 },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n onboardCheckPendingState(),\n unlockRequestedPendingState(),\n unlockResolvedPendingState(),\n unlockResolvedPendingState(),\n {\n status: DeviceActionStatus.Completed,\n output: {\n currentApp: \"BOLOS\",\n currentAppVersion: \"1.0.0\",\n },\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n });\n\n describe(\"errors cases\", () => {\n it(\"GIVEN a non-onboarded device and the non-onboarded allowance is disabled WHEN checking the device status THEN it returns a not-onboarded error\", () =>\n new Promise<void>((resolve, reject) => {\n // GIVEN\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: { name: \"BOLOS\", version: \"1.0.0\" },\n installedApps: [],\n deviceModelId: DeviceModelId.NANO_X,\n isSecureConnectionAllowed: false,\n });\n // A non-onboarded device sits on the dashboard (BOLOS), so the app check\n // succeeds and the OS version reveals the onboarding status.\n getAppAndVersionMock.mockResolvedValue(\n appAndVersionResult(\"BOLOS\", \"1.0.0\"),\n );\n getOsVersionMock.mockResolvedValue(\n osVersionCommandResult({\n secureElementFlags: {\n ...getOsVersionCommandResponseMockBuilder().secureElementFlags,\n isOnboarded: false,\n },\n }),\n );\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: {\n unlockTimeout: 500,\n allowNonOnboardedDevice: false,\n },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n ...onboardCheckPendingStatesWithOsVersionFetch(),\n {\n error: new DeviceNotOnboardedError(),\n status: DeviceActionStatus.Error,\n },\n ];\n\n // WHEN\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n // THEN\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should end in an error if the device is locked and the user does not unlock\", () =>\n new Promise<void>((resolve, reject) => {\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.LOCKED,\n currentApp: { name: \"mockedCurrentApp\", version: \"1.0.0\" },\n });\n\n getAppAndVersionMock.mockResolvedValue(lockedErrorResult());\n\n waitForDeviceUnlockMock.mockImplementation(\n () =>\n new Observable((o) => {\n o.error(new DeviceLockedError(\"Device locked.\"));\n }),\n );\n\n apiGetDeviceSessionStateObservableMock.mockImplementation(\n () =>\n new Observable((o) => {\n const inner = interval(200).subscribe({\n next: () => {\n o.next({\n sessionStateType:\n DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.LOCKED,\n currentApp: { name: \"mockedCurrentApp\", version: \"1.0.0\" },\n installedApps: [],\n deviceModelId: DeviceModelId.NANO_X,\n isSecureConnectionAllowed: false,\n });\n },\n });\n\n return () => {\n inner.unsubscribe();\n };\n }),\n );\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 500 },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n onboardCheckPendingState(),\n unlockRequestedPendingState(),\n {\n error: new DeviceLockedError(\"Device locked.\"),\n status: DeviceActionStatus.Error,\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should end in an error if the GetAppAndVersion command fails\", () =>\n new Promise<void>((resolve, reject) => {\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.LOCKED,\n currentApp: { name: \"mockedCurrentApp\", version: \"1.0.0\" },\n });\n\n const error = new GlobalCommandError({\n ...GLOBAL_ERRORS[\"5501\"],\n errorCode: \"5501\",\n });\n\n getAppAndVersionMock.mockResolvedValue(CommandResultFactory({ error }));\n\n waitForDeviceUnlockMock.mockImplementation(\n () =>\n new Observable((o) => {\n o.complete();\n }),\n );\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 500 },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n onboardCheckPendingState(),\n {\n error,\n status: DeviceActionStatus.Error,\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should end in an error if getAppAndVersion actor throws an error\", () =>\n new Promise<void>((resolve, reject) => {\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.LOCKED,\n currentApp: { name: \"mockedCurrentApp\", version: \"1.0.0\" },\n });\n\n getAppAndVersionMock.mockImplementation(() => {\n throw new UnknownDAError(\"error\");\n });\n\n waitForDeviceUnlockMock.mockImplementation(\n () =>\n new Observable((o) => {\n o.complete();\n }),\n );\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 500 },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n onboardCheckPendingState(),\n {\n error: new UnknownDAError(\"error\"),\n status: DeviceActionStatus.Error,\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n });\n\n it(\"should emit a stopped state if the action is cancelled\", () =>\n new Promise<void>((resolve, reject) => {\n apiGetDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: { name: \"mockedCurrentApp\", version: \"1.0.0\" },\n installedApps: [],\n deviceModelId: DeviceModelId.NANO_X,\n isSecureConnectionAllowed: false,\n });\n\n sendCommandMock.mockImplementation((command) =>\n command.name === \"getOsVersion\"\n ? Promise.resolve(osVersionCommandResult())\n : Promise.resolve(appAndVersionResult(\"BOLOS\", \"1.0.0\")),\n );\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 500 },\n });\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n onboardCheckPendingState(),\n {\n status: DeviceActionStatus.Stopped,\n },\n ];\n\n const { cancel } = testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n cancel();\n }));\n});\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,YAAAA,EAAU,cAAAC,MAAkB,OAErC,OAAS,wBAAAC,MAA4B,mCACrC,OAAS,0CAAAC,MAA8C,gDAEvD,OACE,iBAAAC,EACA,sBAAAC,MACK,wCACP,OAAS,iBAAAC,MAAqB,0BAC9B,OAAS,gBAAAC,MAAoB,2BAC7B,OAAS,mCAAAC,MAAuC,oDAChD,OAAS,0B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["interval", "Observable", "CommandResultFactory", "getOsVersionCommandResponseMockBuilder", "GLOBAL_ERRORS", "GlobalCommandError", "DeviceModelId", "DeviceStatus", "makeDeviceActionInternalApiMock", "testDeviceActionStates", "DeviceActionStatus", "UserInteractionRequired", "DeviceLockedError", "DeviceNotOnboardedError", "UnknownDAError", "DeviceSessionStateType", "GetDeviceStatusDeviceAction", "getDeviceStatusDAStateStep", "osVersionCommandResult", "props", "deviceModelId", "appAndVersionResult", "name", "version", "lockedErrorResult", "onboardCheckPendingState", "onboardCheckPendingStatesWithOsVersionFetch", "unlockRequestedPendingState", "unlockResolvedPendingState", "getAppAndVersionMock", "getOsVersionMock", "getDeviceSessionStateMock", "waitForDeviceUnlockMock", "setDeviceSessionState", "extractDependenciesMock", "sendCommandMock", "apiGetDeviceSessionStateMock", "apiGetDeviceSessionStateObservableMock", "resolve", "reject", "getDeviceStateDeviceAction", "command", "expectedStates", "appCall", "sessionState", "state", "osVersionData", "o", "inner", "i", "error", "cancel"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../src/api/device-action/os/GetDeviceStatus/types.ts"],
|
|
4
|
-
"sourcesContent": ["import { type CommandErrorResult } from \"@api/command/model/CommandResult\";\nimport { type DeviceActionState } from \"@api/device-action/model/DeviceActionState\";\nimport { type UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport {\n type DeviceLockedError,\n type DeviceNotOnboardedError,\n type UnknownDAError,\n} from \"@api/device-action/os/Errors\";\n\nexport const getDeviceStatusDAStateStep = Object.freeze({\n ONBOARD_CHECK: \"os.getDeviceStatus.steps.onboardCheck\",\n UNLOCK_DEVICE: \"os.getDeviceStatus.steps.unlockDevice\",\n} as const);\n\nexport type GetDeviceStatusDAStateStep =\n (typeof getDeviceStatusDAStateStep)[keyof typeof getDeviceStatusDAStateStep];\n\nexport type GetDeviceStatusDAOutput = {\n readonly currentApp: string;\n readonly currentAppVersion: string;\n};\nexport type GetDeviceStatusDAInput = {\n readonly unlockTimeout?: number;\n};\n\nexport type GetDeviceStatusDAError =\n | DeviceNotOnboardedError\n | DeviceLockedError\n | UnknownDAError\n | CommandErrorResult[\"error\"];\n\nexport type GetDeviceStatusDARequiredInteraction =\n | UserInteractionRequired.None\n | UserInteractionRequired.UnlockDevice;\n\nexport type GetDeviceStatusDAIntermediateValue = {\n requiredUserInteraction: GetDeviceStatusDARequiredInteraction;\n step: GetDeviceStatusDAStateStep;\n};\n\nexport type GetDeviceStatusDAState = DeviceActionState<\n GetDeviceStatusDAOutput,\n GetDeviceStatusDAError,\n GetDeviceStatusDAIntermediateValue\n>;\n"],
|
|
4
|
+
"sourcesContent": ["import { type CommandErrorResult } from \"@api/command/model/CommandResult\";\nimport { type DeviceActionState } from \"@api/device-action/model/DeviceActionState\";\nimport { type UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport {\n type DeviceLockedError,\n type DeviceNotOnboardedError,\n type UnknownDAError,\n} from \"@api/device-action/os/Errors\";\n\nexport const getDeviceStatusDAStateStep = Object.freeze({\n ONBOARD_CHECK: \"os.getDeviceStatus.steps.onboardCheck\",\n UNLOCK_DEVICE: \"os.getDeviceStatus.steps.unlockDevice\",\n} as const);\n\nexport type GetDeviceStatusDAStateStep =\n (typeof getDeviceStatusDAStateStep)[keyof typeof getDeviceStatusDAStateStep];\n\nexport type GetDeviceStatusDAOutput = {\n readonly currentApp: string;\n readonly currentAppVersion: string;\n};\nexport type GetDeviceStatusDAInput = {\n readonly unlockTimeout?: number;\n readonly allowNonOnboardedDevice?: boolean;\n};\n\nexport type GetDeviceStatusDAError =\n | DeviceNotOnboardedError\n | DeviceLockedError\n | UnknownDAError\n | CommandErrorResult[\"error\"];\n\nexport type GetDeviceStatusDARequiredInteraction =\n | UserInteractionRequired.None\n | UserInteractionRequired.UnlockDevice;\n\nexport type GetDeviceStatusDAIntermediateValue = {\n requiredUserInteraction: GetDeviceStatusDARequiredInteraction;\n step: GetDeviceStatusDAStateStep;\n};\n\nexport type GetDeviceStatusDAState = DeviceActionState<\n GetDeviceStatusDAOutput,\n GetDeviceStatusDAError,\n GetDeviceStatusDAIntermediateValue\n>;\n"],
|
|
5
5
|
"mappings": "AASO,MAAMA,EAA6B,OAAO,OAAO,CACtD,cAAe,wCACf,cAAe,uCACjB,CAAU",
|
|
6
6
|
"names": ["getDeviceStatusDAStateStep"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Left as d,Right as D}from"purify-ts";import{assign as t,fromPromise as c,setup as g}from"xstate";import{isSuccessCommandResult as u}from"../../../command/model/CommandResult";import{CloseAppCommand as y}from"../../../command/os/CloseAppCommand";import{OpenAppCommand as v}from"../../../command/os/OpenAppCommand";import{UserInteractionRequired as i}from"../../../device-action/model/UserInteractionRequired";import{DEFAULT_UNLOCK_TIMEOUT_MS as
|
|
1
|
+
import{Left as d,Right as D}from"purify-ts";import{assign as t,fromPromise as c,setup as g}from"xstate";import{isSuccessCommandResult as u}from"../../../command/model/CommandResult";import{CloseAppCommand as y}from"../../../command/os/CloseAppCommand";import{OpenAppCommand as v}from"../../../command/os/OpenAppCommand";import{UserInteractionRequired as i}from"../../../device-action/model/UserInteractionRequired";import{DEFAULT_UNLOCK_TIMEOUT_MS as O}from"../../../device-action/os/Const";import{GetDeviceStatusDeviceAction as h}from"../../../device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction";import{XStateDeviceAction as E}from"../../../device-action/xstate-utils/XStateDeviceAction";import{DeviceSessionStateType as l}from"../../../device-session/DeviceSessionState";import{DeviceDisconnectedWhileSendingError as f}from"../../../transport/model/Errors";import{isDashboardName as R,LEDGER_OS_NAME as C}from"../../../utils/AppName";import{openAppDAStateStep as x}from"./types";class W extends E{makeStateMachine(r){const{closeApp:o,openApp:s,getDeviceSessionState:a,setDeviceSessionState:A}=this.extractDependencies(r),S=this.input.unlockTimeout??O,m=new h({input:{unlockTimeout:S,allowNonOnboardedDevice:!1}}).makeStateMachine(r);return g({types:{input:{},context:{},output:{}},actors:{closeApp:c(o),openApp:c(s),getDeviceStatus:m},guards:{isRequestedAppOpen:({context:e})=>e._internalState.currentlyRunningApp===null?!1:e._internalState.currentlyRunningApp===e.input.appName,isDashboardOpen:({context:e})=>{if(e._internalState.currentlyRunningApp===null)throw new Error("context.currentlyRunningApp === null");return R(e._internalState.currentlyRunningApp)},hasDisconnectedWhileSending:({context:e})=>e._internalState.error!==null&&e._internalState.error instanceof f,hasError:({context:e})=>e._internalState.error!==null},actions:{assignUserActionNeededOpenApp:t({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:i.ConfirmOpenApp})}),assignNoUserActionNeeded:t({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:i.None})}),assignErrorFromEvent:t({_internalState:e=>({...e.context._internalState,error:e.event.error})}),assignNoError:t({_internalState:e=>({...e.context._internalState,error:null})})}}).createMachine({id:"OpenAppDeviceAction",initial:"DeviceReady",context:({input:e})=>{const n=a(),{sessionStateType:p}=n;return{input:e,intermediateValue:{requiredUserInteraction:i.None,step:x.GET_DEVICE_STATUS},_internalState:{error:null,currentlyRunningApp:p===l.ReadyWithoutSecureChannel?n.currentApp.name:null}}},states:{DeviceReady:{always:{target:"GetDeviceStatus"}},GetDeviceStatus:{invoke:{id:"deviceStatus",src:"getDeviceStatus",input:e=>({unlockTimeout:e.context.input.unlockTimeout,allowNonOnboardedDevice:!1}),onSnapshot:{actions:t({intermediateValue:e=>e.event.snapshot.context.intermediateValue})},onDone:{target:"CheckDeviceStatus",actions:t({_internalState:e=>e.event.output.caseOf({Right:n=>{const p=a();return p.sessionStateType!==l.Connected&&A({...p,currentApp:{name:n.currentApp,version:n.currentAppVersion}}),{...e.context._internalState,currentlyRunningApp:n.currentApp}},Left:n=>({...e.context._internalState,currentlyRunningApp:null,error:n})})})},onError:{target:"Error",actions:[t({_internalState:e=>({...e.context._internalState,currentlyRunningApp:null})}),"assignErrorFromEvent"]}}},CheckDeviceStatus:{always:[{target:"ApplicationReady",guard:"isRequestedAppOpen",actions:"assignNoError"},{target:"Error",guard:"hasError"},{target:"DashboardCheck"}]},DashboardCheck:{always:[{target:"OpenApplication",guard:"isDashboardOpen"},"CloseApplication"]},OpenApplication:{entry:"assignUserActionNeededOpenApp",exit:"assignNoUserActionNeeded",invoke:{src:"openApp",input:({context:e})=>({appName:e.input.appName}),onDone:{target:"OpenApplicationResultCheck",actions:t({_internalState:e=>u(e.event.output)?{...e.context._internalState,currentlyRunningApp:e.context.input.appName}:{...e.context._internalState,error:e.event.output.error}})},onError:{target:"OpenApplicationResultCheck",actions:"assignErrorFromEvent"}}},OpenApplicationResultCheck:{always:[{target:"GetDeviceStatus",guard:"hasDisconnectedWhileSending"},{target:"Error",guard:"hasError"},{target:"GetDeviceStatus"}]},CloseApplication:{invoke:{src:"closeApp",onDone:{target:"CloseApplicationResultCheck",actions:t({_internalState:e=>u(e.event.output)?{...e.context._internalState,currentlyRunningApp:C}:{...e.context._internalState,error:e.event.output.error}})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},CloseApplicationResultCheck:{always:[{target:"Error",guard:"hasError"},{target:"OpenApplication"}]},ApplicationReady:{always:"Success"},Success:{type:"final",actions:"assignNoError"},Error:{type:"final"}},output:({context:e})=>e._internalState.error?d(e._internalState.error):D(void 0)})}extractDependencies(r){return{closeApp:async()=>r.sendCommand(new y),openApp:async a=>r.sendCommand(new v({appName:a.input.appName})),getDeviceSessionState:()=>r.getDeviceSessionState(),setDeviceSessionState:a=>r.setDeviceSessionState(a)}}}export{W as OpenAppDeviceAction};
|
|
2
2
|
//# sourceMappingURL=OpenAppDeviceAction.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.ts"],
|
|
4
|
-
"sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport { assign, fromPromise, setup } from \"xstate\";\n\nimport { isSuccessCommandResult } from \"@api/command/model/CommandResult\";\nimport {\n CloseAppCommand,\n type CloseAppCommandResult,\n} from \"@api/command/os/CloseAppCommand\";\nimport {\n OpenAppCommand,\n type OpenAppCommandResult,\n} from \"@api/command/os/OpenAppCommand\";\nimport { type InternalApi } from \"@api/device-action/DeviceAction\";\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { DEFAULT_UNLOCK_TIMEOUT_MS } from \"@api/device-action/os/Const\";\nimport { GetDeviceStatusDeviceAction } from \"@api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction\";\nimport { type StateMachineTypes } from \"@api/device-action/xstate-utils/StateMachineTypes\";\nimport {\n type DeviceActionStateMachine,\n XStateDeviceAction,\n} from \"@api/device-action/xstate-utils/XStateDeviceAction\";\nimport {\n type DeviceSessionState,\n DeviceSessionStateType,\n} from \"@api/device-session/DeviceSessionState\";\nimport { DeviceDisconnectedWhileSendingError } from \"@api/transport/model/Errors\";\nimport { isDashboardName, LEDGER_OS_NAME } from \"@api/utils/AppName\";\n\nimport {\n type OpenAppDAError,\n type OpenAppDAInput,\n type OpenAppDAIntermediateValue,\n type OpenAppDAOutput,\n openAppDAStateStep,\n} from \"./types\";\n\ntype OpenAppStateMachineInternalState = {\n readonly currentlyRunningApp: string | null;\n readonly error: OpenAppDAError | null;\n};\n\nexport type MachineDependencies = {\n readonly closeApp: () => Promise<CloseAppCommandResult>;\n readonly openApp: (arg0: {\n input: { appName: string };\n }) => Promise<OpenAppCommandResult>;\n readonly getDeviceSessionState: () => DeviceSessionState;\n readonly setDeviceSessionState: (state: DeviceSessionState) => void;\n};\n\nexport type ExtractMachineDependencies = (\n internalApi: InternalApi,\n) => MachineDependencies;\n\n/**\n * Opens a given app on the device.\n *\n * It checks if the device is onboarded, unlocked, and which app is currently open.\n * If the current app is the dashboard, it will directly open the requested app.\n * If another app is opened, it will close the current app and open the requested app.\n *\n * Example of usage:\n *\n * ```ts\n * const deviceAction = new OpenAppDeviceAction({\n * input: {\n * appName: \"MyApp\",\n * },\n * });\n * dmk.executeDeviceAction({ sessionId: \"mySessionId\", deviceAction });\n * ```\n */\nexport class OpenAppDeviceAction extends XStateDeviceAction<\n OpenAppDAOutput,\n OpenAppDAInput,\n OpenAppDAError,\n OpenAppDAIntermediateValue,\n OpenAppStateMachineInternalState\n> {\n makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n OpenAppDAOutput,\n OpenAppDAInput,\n OpenAppDAError,\n OpenAppDAIntermediateValue,\n OpenAppStateMachineInternalState\n > {\n type types = StateMachineTypes<\n OpenAppDAOutput,\n OpenAppDAInput,\n OpenAppDAError,\n OpenAppDAIntermediateValue,\n OpenAppStateMachineInternalState\n >;\n\n const { closeApp, openApp, getDeviceSessionState, setDeviceSessionState } =\n this.extractDependencies(internalApi);\n\n const unlockTimeout = this.input.unlockTimeout ?? DEFAULT_UNLOCK_TIMEOUT_MS;\n\n const getDeviceStatusMachine = new GetDeviceStatusDeviceAction({\n input: {\n unlockTimeout,\n },\n }).makeStateMachine(internalApi);\n\n return setup({\n types: {\n input: {} as types[\"input\"],\n context: {} as types[\"context\"],\n output: {} as types[\"output\"],\n },\n actors: {\n closeApp: fromPromise(closeApp),\n openApp: fromPromise(openApp),\n getDeviceStatus: getDeviceStatusMachine,\n },\n guards: {\n isRequestedAppOpen: ({ context }: { context: types[\"context\"] }) => {\n if (context._internalState.currentlyRunningApp === null) return false;\n return (\n context._internalState.currentlyRunningApp === context.input.appName\n );\n },\n isDashboardOpen: ({ context }: { context: types[\"context\"] }) => {\n if (context._internalState.currentlyRunningApp === null)\n throw new Error(\"context.currentlyRunningApp === null\");\n return isDashboardName(context._internalState.currentlyRunningApp);\n },\n hasDisconnectedWhileSending: ({ context }) =>\n context._internalState.error !== null &&\n context._internalState.error instanceof\n DeviceDisconnectedWhileSendingError,\n hasError: ({ context }) => context._internalState.error !== null,\n },\n actions: {\n assignUserActionNeededOpenApp: assign({\n intermediateValue: (_) =>\n ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n }) satisfies types[\"context\"][\"intermediateValue\"],\n }),\n assignNoUserActionNeeded: assign({\n intermediateValue: (_) =>\n ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n }) satisfies types[\"context\"][\"intermediateValue\"],\n }),\n assignErrorFromEvent: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: _.event[\"error\"], // FIXME: add a typeguard\n }),\n }),\n assignNoError: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: null,\n }),\n }),\n },\n }).createMachine({\n /** @xstate-layout N4IgpgJg5mDOIC5QHkAOYB2BBVqAiYAbgJYDGYWpALsQPYYB0BJ5ASmAIYQCeAxANoAGALqJQqWrGI16YkAA9EARhWCGADgAsAZm1b1SwUoDspgDQhuiAEzX1DbQE5tJlQDYlm414CsAXz8LNEwcfCIyCmo6RmQMACNaDgAnCGIMKABhAAswUgBrARE5CSkZDDlFBCUPbQYfZx91H0FtTRNjCysEbWM1bTdHAzcfH2q9awCg9GxcZgjKMoZYhOTU9Ozcgv4lUSQQEuloiuUauoamlrbzSxtBNTu7pW1BEe1rJUmQYJmwlkjFgAytHyaUyOXyhV24kkh1ke0q7w8DDcxmqjkM1l6Kh8nUQzR8DEEjjcz3UxKUjiMbk+31Cc3IC2iDCBIPW4K2O2KMLKxwQiKUyNRAwxWKUOJu3TaDFsw28bkExmsgnU-Rp0zp4QZUXoDFCABsyBwylhCBxiHqOHE9WBeBB6GAGGlCLQ8g7abNNf8mfrDcbTebLdaEE7gUbokJhBGuaUjvCbCSCdZNI5UQqhg1cQhNOprAxND4XP0xZTHI01SEPX9GTqfaQw-QTWaLVabWAkklaEkGKgLVQAGadgC2S3Vlfm2sYtfr2H9zaDIbrZQjUb2Bx5cb5CelydTxnT2nFXTcmjUBYTzlazkcE0CX1Hv3HiynfqbgbA7FgA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CyPI6j2SaJjsoUsBIBimB8MMeUZJqFdH6PYDwKYBjwQaEYpRtlOYzlfC2NxS8bB6HsM4RUIwiSH0VNxAy6lkL1EEjTYUtisLn1ISAhuDZZxvhvpsRJmVX51FJFlZ4-Qk5wUYcxR2BTTIGUKtEvCoDpwaMUobbqugUzIg8PmEwIiTJ9yqAMaUW90IngCaIgZcUEpJVUa1Vxoy+GVGMbvZiuVf5IM8CoTZOpNZDL4eQjcIlDLIRRH5FhoxDyIGFMiASe8IoFlGNchaS0waxNqfkepG4tACiMGeQw6IiQeBGncMaMycxEl8eoIFu0fiVPbg87qSE3q6MVBpehPQ4K6G+uoZUJIVB7laNiq+2s4DkRGYTLRygs6GSQtmO4iIaWljgvUBgip-K5RErofOdiYocLBZwHhBzOWSkKqKz6Lw3i6U+QgPchlTB7xTPBeCWVHDYoAMqflIOQWA8AlXuO6KMQylImipgMi4BZzhDIKkpM0FEypRimplXNWyABRMuSRIXjNaKvHQ3h0Q0reCYT+3khGNEKgqIRxgAgBCAA */\n id: \"OpenAppDeviceAction\",\n initial: \"DeviceReady\",\n context: ({ input }) => {\n const sessionState = getDeviceSessionState();\n const { sessionStateType } = sessionState;\n return {\n input,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: openAppDAStateStep.GET_DEVICE_STATUS,\n },\n _internalState: {\n error: null,\n currentlyRunningApp:\n sessionStateType ===\n DeviceSessionStateType.ReadyWithoutSecureChannel\n ? sessionState.currentApp.name\n : null,\n },\n };\n },\n states: {\n DeviceReady: {\n always: {\n target: \"GetDeviceStatus\",\n },\n },\n\n GetDeviceStatus: {\n // We run the GetDeviceStatus flow to get information about the device state\n invoke: {\n id: \"deviceStatus\",\n src: \"getDeviceStatus\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) =>\n _.event.snapshot.context.intermediateValue,\n }),\n },\n onDone: {\n target: \"CheckDeviceStatus\",\n actions: assign({\n _internalState: (_) => {\n return _.event.output.caseOf<OpenAppStateMachineInternalState>(\n {\n Right: (output) => {\n const state: DeviceSessionState =\n getDeviceSessionState();\n\n if (\n state.sessionStateType !==\n DeviceSessionStateType.Connected\n ) {\n setDeviceSessionState({\n ...state,\n currentApp: {\n name: output.currentApp,\n version: output.currentAppVersion,\n },\n });\n }\n return {\n ..._.context._internalState,\n currentlyRunningApp: output.currentApp,\n };\n },\n Left: (error) => ({\n ..._.context._internalState,\n currentlyRunningApp: null,\n error,\n }),\n },\n );\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: [\n assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n currentlyRunningApp: null,\n }),\n }),\n \"assignErrorFromEvent\",\n ],\n },\n },\n },\n CheckDeviceStatus: {\n // We check the device status to see if we can have an error\n always: [\n {\n target: \"ApplicationReady\",\n guard: \"isRequestedAppOpen\",\n // If target app is currently opened, we can ignore errors\n actions: \"assignNoError\",\n },\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"DashboardCheck\",\n },\n ],\n },\n\n DashboardCheck: {\n // Is the current application the dashboard\n always: [\n {\n target: \"OpenApplication\",\n guard: \"isDashboardOpen\",\n },\n \"CloseApplication\",\n ],\n },\n\n OpenApplication: {\n // execute openApp command,\n entry: \"assignUserActionNeededOpenApp\",\n exit: \"assignNoUserActionNeeded\",\n invoke: {\n src: \"openApp\",\n input: ({ context }) => ({ appName: context.input.appName }),\n onDone: {\n target: \"OpenApplicationResultCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n return {\n ..._.context._internalState,\n currentlyRunningApp: _.context.input.appName,\n };\n } else {\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n }\n },\n }),\n },\n onError: {\n target: \"OpenApplicationResultCheck\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n\n OpenApplicationResultCheck: {\n always: [\n {\n // When an APDU triggers a disconnection, some transports may possibly\n // be closed on device side before the APDU response could be received,\n // especially on BLE transports.\n // Therefore when a disconnection occurs while sending, we should verify\n // the device status because it may have been successfully executed.\n target: \"GetDeviceStatus\",\n guard: \"hasDisconnectedWhileSending\",\n },\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n { target: \"GetDeviceStatus\" },\n ],\n },\n\n CloseApplication: {\n invoke: {\n src: \"closeApp\",\n onDone: {\n target: \"CloseApplicationResultCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n return {\n ..._.context._internalState,\n currentlyRunningApp: LEDGER_OS_NAME,\n };\n } else {\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n }\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n CloseApplicationResultCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n { target: \"OpenApplication\" },\n ],\n },\n\n ApplicationReady: {\n // application is ready to be used\n always: \"Success\",\n },\n\n // success state\n Success: {\n type: \"final\",\n actions: \"assignNoError\", // TODO, we should not need this\n },\n\n // error state\n Error: {\n type: \"final\",\n },\n },\n output: ({ context }) =>\n context._internalState.error // TODO: instead we should rely on the current state (\"Success\" or \"Error\")\n ? Left(context._internalState.error)\n : Right(undefined),\n });\n }\n\n extractDependencies(internalApi: InternalApi): MachineDependencies {\n const closeApp = async () => internalApi.sendCommand(new CloseAppCommand());\n const openApp = async (arg0: { input: { appName: string } }) =>\n internalApi.sendCommand(\n new OpenAppCommand({ appName: arg0.input.appName }),\n );\n\n return {\n closeApp,\n openApp,\n getDeviceSessionState: () => internalApi.getDeviceSessionState(),\n setDeviceSessionState: (state: DeviceSessionState) =>\n internalApi.setDeviceSessionState(state),\n };\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAC5B,OAAS,UAAAC,EAAQ,eAAAC,EAAa,SAAAC,MAAa,SAE3C,OAAS,0BAAAC,MAA8B,mCACvC,OACE,mBAAAC,MAEK,kCACP,OACE,kBAAAC,MAEK,iCAEP,OAAS,2BAAAC,MAA+B,mDACxC,OAAS,6BAAAC,MAAiC,8BAC1C,OAAS,+BAAAC,MAAmC,oEAE5C,OAEE,sBAAAC,MACK,qDACP,OAEE,0BAAAC,MACK,yCACP,OAAS,uCAAAC,MAA2C,8BACpD,OAAS,mBAAAC,EAAiB,kBAAAC,MAAsB,qBAEhD,OAKE,sBAAAC,MACK,UAsCA,MAAMC,UAA4BN,CAMvC,CACA,iBACEO,EAOA,CASA,KAAM,CAAE,SAAAC,EAAU,QAAAC,EAAS,sBAAAC,EAAuB,sBAAAC,CAAsB,EACtE,KAAK,oBAAoBJ,CAAW,EAEhCK,EAAgB,KAAK,MAAM,eAAiBd,EAE5Ce,EAAyB,IAAId,EAA4B,CAC7D,MAAO,CACL,cAAAa,
|
|
4
|
+
"sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport { assign, fromPromise, setup } from \"xstate\";\n\nimport { isSuccessCommandResult } from \"@api/command/model/CommandResult\";\nimport {\n CloseAppCommand,\n type CloseAppCommandResult,\n} from \"@api/command/os/CloseAppCommand\";\nimport {\n OpenAppCommand,\n type OpenAppCommandResult,\n} from \"@api/command/os/OpenAppCommand\";\nimport { type InternalApi } from \"@api/device-action/DeviceAction\";\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { DEFAULT_UNLOCK_TIMEOUT_MS } from \"@api/device-action/os/Const\";\nimport { GetDeviceStatusDeviceAction } from \"@api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction\";\nimport { type StateMachineTypes } from \"@api/device-action/xstate-utils/StateMachineTypes\";\nimport {\n type DeviceActionStateMachine,\n XStateDeviceAction,\n} from \"@api/device-action/xstate-utils/XStateDeviceAction\";\nimport {\n type DeviceSessionState,\n DeviceSessionStateType,\n} from \"@api/device-session/DeviceSessionState\";\nimport { DeviceDisconnectedWhileSendingError } from \"@api/transport/model/Errors\";\nimport { isDashboardName, LEDGER_OS_NAME } from \"@api/utils/AppName\";\n\nimport {\n type OpenAppDAError,\n type OpenAppDAInput,\n type OpenAppDAIntermediateValue,\n type OpenAppDAOutput,\n openAppDAStateStep,\n} from \"./types\";\n\ntype OpenAppStateMachineInternalState = {\n readonly currentlyRunningApp: string | null;\n readonly error: OpenAppDAError | null;\n};\n\nexport type MachineDependencies = {\n readonly closeApp: () => Promise<CloseAppCommandResult>;\n readonly openApp: (arg0: {\n input: { appName: string };\n }) => Promise<OpenAppCommandResult>;\n readonly getDeviceSessionState: () => DeviceSessionState;\n readonly setDeviceSessionState: (state: DeviceSessionState) => void;\n};\n\nexport type ExtractMachineDependencies = (\n internalApi: InternalApi,\n) => MachineDependencies;\n\n/**\n * Opens a given app on the device.\n *\n * It checks if the device is onboarded, unlocked, and which app is currently open.\n * If the current app is the dashboard, it will directly open the requested app.\n * If another app is opened, it will close the current app and open the requested app.\n *\n * Example of usage:\n *\n * ```ts\n * const deviceAction = new OpenAppDeviceAction({\n * input: {\n * appName: \"MyApp\",\n * },\n * });\n * dmk.executeDeviceAction({ sessionId: \"mySessionId\", deviceAction });\n * ```\n */\nexport class OpenAppDeviceAction extends XStateDeviceAction<\n OpenAppDAOutput,\n OpenAppDAInput,\n OpenAppDAError,\n OpenAppDAIntermediateValue,\n OpenAppStateMachineInternalState\n> {\n makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n OpenAppDAOutput,\n OpenAppDAInput,\n OpenAppDAError,\n OpenAppDAIntermediateValue,\n OpenAppStateMachineInternalState\n > {\n type types = StateMachineTypes<\n OpenAppDAOutput,\n OpenAppDAInput,\n OpenAppDAError,\n OpenAppDAIntermediateValue,\n OpenAppStateMachineInternalState\n >;\n\n const { closeApp, openApp, getDeviceSessionState, setDeviceSessionState } =\n this.extractDependencies(internalApi);\n\n const unlockTimeout = this.input.unlockTimeout ?? DEFAULT_UNLOCK_TIMEOUT_MS;\n\n const getDeviceStatusMachine = new GetDeviceStatusDeviceAction({\n input: {\n unlockTimeout,\n allowNonOnboardedDevice: false,\n },\n }).makeStateMachine(internalApi);\n\n return setup({\n types: {\n input: {} as types[\"input\"],\n context: {} as types[\"context\"],\n output: {} as types[\"output\"],\n },\n actors: {\n closeApp: fromPromise(closeApp),\n openApp: fromPromise(openApp),\n getDeviceStatus: getDeviceStatusMachine,\n },\n guards: {\n isRequestedAppOpen: ({ context }: { context: types[\"context\"] }) => {\n if (context._internalState.currentlyRunningApp === null) return false;\n return (\n context._internalState.currentlyRunningApp === context.input.appName\n );\n },\n isDashboardOpen: ({ context }: { context: types[\"context\"] }) => {\n if (context._internalState.currentlyRunningApp === null)\n throw new Error(\"context.currentlyRunningApp === null\");\n return isDashboardName(context._internalState.currentlyRunningApp);\n },\n hasDisconnectedWhileSending: ({ context }) =>\n context._internalState.error !== null &&\n context._internalState.error instanceof\n DeviceDisconnectedWhileSendingError,\n hasError: ({ context }) => context._internalState.error !== null,\n },\n actions: {\n assignUserActionNeededOpenApp: assign({\n intermediateValue: (_) =>\n ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n }) satisfies types[\"context\"][\"intermediateValue\"],\n }),\n assignNoUserActionNeeded: assign({\n intermediateValue: (_) =>\n ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n }) satisfies types[\"context\"][\"intermediateValue\"],\n }),\n assignErrorFromEvent: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: _.event[\"error\"], // FIXME: add a typeguard\n }),\n }),\n assignNoError: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: null,\n }),\n }),\n },\n }).createMachine({\n /** @xstate-layout N4IgpgJg5mDOIC5QHkAOYB2BBVqAiYAbgJYDGYWpALsQPYYB0BJ5ASmAIYQCeAxANoAGALqJQqWrGI16YkAA9EARhWCGADgAsAZm1b1SwUoDspgDQhuiAEzX1DbQE5tJlQDYlm414CsAXz8LNEwcfCIyCmo6RmQMACNaDgAnCGIMKABhAAswUgBr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ction\",\n initial: \"DeviceReady\",\n context: ({ input }) => {\n const sessionState = getDeviceSessionState();\n const { sessionStateType } = sessionState;\n return {\n input,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: openAppDAStateStep.GET_DEVICE_STATUS,\n },\n _internalState: {\n error: null,\n currentlyRunningApp:\n sessionStateType ===\n DeviceSessionStateType.ReadyWithoutSecureChannel\n ? sessionState.currentApp.name\n : null,\n },\n };\n },\n states: {\n DeviceReady: {\n always: {\n target: \"GetDeviceStatus\",\n },\n },\n\n GetDeviceStatus: {\n // We run the GetDeviceStatus flow to get information about the device state\n invoke: {\n id: \"deviceStatus\",\n src: \"getDeviceStatus\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n allowNonOnboardedDevice: false,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) =>\n _.event.snapshot.context.intermediateValue,\n }),\n },\n onDone: {\n target: \"CheckDeviceStatus\",\n actions: assign({\n _internalState: (_) => {\n return _.event.output.caseOf<OpenAppStateMachineInternalState>(\n {\n Right: (output) => {\n const state: DeviceSessionState =\n getDeviceSessionState();\n\n if (\n state.sessionStateType !==\n DeviceSessionStateType.Connected\n ) {\n setDeviceSessionState({\n ...state,\n currentApp: {\n name: output.currentApp,\n version: output.currentAppVersion,\n },\n });\n }\n return {\n ..._.context._internalState,\n currentlyRunningApp: output.currentApp,\n };\n },\n Left: (error) => ({\n ..._.context._internalState,\n currentlyRunningApp: null,\n error,\n }),\n },\n );\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: [\n assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n currentlyRunningApp: null,\n }),\n }),\n \"assignErrorFromEvent\",\n ],\n },\n },\n },\n CheckDeviceStatus: {\n // We check the device status to see if we can have an error\n always: [\n {\n target: \"ApplicationReady\",\n guard: \"isRequestedAppOpen\",\n // If target app is currently opened, we can ignore errors\n actions: \"assignNoError\",\n },\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"DashboardCheck\",\n },\n ],\n },\n\n DashboardCheck: {\n // Is the current application the dashboard\n always: [\n {\n target: \"OpenApplication\",\n guard: \"isDashboardOpen\",\n },\n \"CloseApplication\",\n ],\n },\n\n OpenApplication: {\n // execute openApp command,\n entry: \"assignUserActionNeededOpenApp\",\n exit: \"assignNoUserActionNeeded\",\n invoke: {\n src: \"openApp\",\n input: ({ context }) => ({ appName: context.input.appName }),\n onDone: {\n target: \"OpenApplicationResultCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n return {\n ..._.context._internalState,\n currentlyRunningApp: _.context.input.appName,\n };\n } else {\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n }\n },\n }),\n },\n onError: {\n target: \"OpenApplicationResultCheck\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n\n OpenApplicationResultCheck: {\n always: [\n {\n // When an APDU triggers a disconnection, some transports may possibly\n // be closed on device side before the APDU response could be received,\n // especially on BLE transports.\n // Therefore when a disconnection occurs while sending, we should verify\n // the device status because it may have been successfully executed.\n target: \"GetDeviceStatus\",\n guard: \"hasDisconnectedWhileSending\",\n },\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n { target: \"GetDeviceStatus\" },\n ],\n },\n\n CloseApplication: {\n invoke: {\n src: \"closeApp\",\n onDone: {\n target: \"CloseApplicationResultCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n return {\n ..._.context._internalState,\n currentlyRunningApp: LEDGER_OS_NAME,\n };\n } else {\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n }\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n CloseApplicationResultCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n { target: \"OpenApplication\" },\n ],\n },\n\n ApplicationReady: {\n // application is ready to be used\n always: \"Success\",\n },\n\n // success state\n Success: {\n type: \"final\",\n actions: \"assignNoError\", // TODO, we should not need this\n },\n\n // error state\n Error: {\n type: \"final\",\n },\n },\n output: ({ context }) =>\n context._internalState.error // TODO: instead we should rely on the current state (\"Success\" or \"Error\")\n ? Left(context._internalState.error)\n : Right(undefined),\n });\n }\n\n extractDependencies(internalApi: InternalApi): MachineDependencies {\n const closeApp = async () => internalApi.sendCommand(new CloseAppCommand());\n const openApp = async (arg0: { input: { appName: string } }) =>\n internalApi.sendCommand(\n new OpenAppCommand({ appName: arg0.input.appName }),\n );\n\n return {\n closeApp,\n openApp,\n getDeviceSessionState: () => internalApi.getDeviceSessionState(),\n setDeviceSessionState: (state: DeviceSessionState) =>\n internalApi.setDeviceSessionState(state),\n };\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAC5B,OAAS,UAAAC,EAAQ,eAAAC,EAAa,SAAAC,MAAa,SAE3C,OAAS,0BAAAC,MAA8B,mCACvC,OACE,mBAAAC,MAEK,kCACP,OACE,kBAAAC,MAEK,iCAEP,OAAS,2BAAAC,MAA+B,mDACxC,OAAS,6BAAAC,MAAiC,8BAC1C,OAAS,+BAAAC,MAAmC,oEAE5C,OAEE,sBAAAC,MACK,qDACP,OAEE,0BAAAC,MACK,yCACP,OAAS,uCAAAC,MAA2C,8BACpD,OAAS,mBAAAC,EAAiB,kBAAAC,MAAsB,qBAEhD,OAKE,sBAAAC,MACK,UAsCA,MAAMC,UAA4BN,CAMvC,CACA,iBACEO,EAOA,CASA,KAAM,CAAE,SAAAC,EAAU,QAAAC,EAAS,sBAAAC,EAAuB,sBAAAC,CAAsB,EACtE,KAAK,oBAAoBJ,CAAW,EAEhCK,EAAgB,KAAK,MAAM,eAAiBd,EAE5Ce,EAAyB,IAAId,EAA4B,CAC7D,MAAO,CACL,cAAAa,EACA,wBAAyB,EAC3B,CACF,CAAC,EAAE,iBAAiBL,CAAW,EAE/B,OAAOd,EAAM,CACX,MAAO,CACL,MAAO,CAAC,EACR,QAAS,CAA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,CACL,SAPe,SAAYA,EAAY,YAAY,IAAIZ,CAAiB,EAQxE,QAPc,MAAO2B,GACrBf,EAAY,YACV,IAAIX,EAAe,CAAE,QAAS0B,EAAK,MAAM,OAAQ,CAAC,CACpD,EAKA,sBAAuB,IAAMf,EAAY,sBAAsB,EAC/D,sBAAwBa,GACtBb,EAAY,sBAAsBa,CAAK,CAC3C,CACF,CACF",
|
|
6
6
|
"names": ["Left", "Right", "assign", "fromPromise", "setup", "isSuccessCommandResult", "CloseAppCommand", "OpenAppCommand", "UserInteractionRequired", "DEFAULT_UNLOCK_TIMEOUT_MS", "GetDeviceStatusDeviceAction", "XStateDeviceAction", "DeviceSessionStateType", "DeviceDisconnectedWhileSendingError", "isDashboardName", "LEDGER_OS_NAME", "openAppDAStateStep", "OpenAppDeviceAction", "internalApi", "closeApp", "openApp", "getDeviceSessionState", "setDeviceSessionState", "unlockTimeout", "getDeviceStatusMachine", "context", "_", "input", "sessionState", "sessionStateType", "output", "state", "error", "arg0"]
|
|
7
7
|
}
|