@ledgerhq/device-signer-kit-ethereum 0.0.0-multisig-20250822145545 → 0.0.0-multisig-20250905101831

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/lib/cjs/api/SignerEthBuilder.test.js +1 -1
  2. package/lib/cjs/api/SignerEthBuilder.test.js.map +1 -1
  3. package/lib/cjs/internal/app-binder/EthAppBinder.test.js +1 -1
  4. package/lib/cjs/internal/app-binder/EthAppBinder.test.js.map +2 -2
  5. package/lib/cjs/internal/app-binder/command/ProvideNetworkConfigurationCommand.js +2 -0
  6. package/lib/cjs/internal/app-binder/command/ProvideNetworkConfigurationCommand.js.map +7 -0
  7. package/lib/cjs/internal/app-binder/command/ProvideNetworkConfigurationCommand.test.js +2 -0
  8. package/lib/cjs/internal/app-binder/command/ProvideNetworkConfigurationCommand.test.js.map +7 -0
  9. package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js +1 -1
  10. package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js.map +2 -2
  11. package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js +1 -1
  12. package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js.map +2 -2
  13. package/lib/cjs/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.test.js +1 -1
  14. package/lib/cjs/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.test.js.map +2 -2
  15. package/lib/cjs/internal/app-binder/task/BuildBaseContexts.js +1 -1
  16. package/lib/cjs/internal/app-binder/task/BuildBaseContexts.js.map +3 -3
  17. package/lib/cjs/internal/app-binder/task/BuildBaseContexts.test.js +1 -1
  18. package/lib/cjs/internal/app-binder/task/BuildBaseContexts.test.js.map +2 -2
  19. package/lib/cjs/internal/app-binder/task/BuildEIP712ContextTask.test.js +1 -1
  20. package/lib/cjs/internal/app-binder/task/BuildEIP712ContextTask.test.js.map +2 -2
  21. package/lib/cjs/internal/app-binder/task/BuildFullContextsTask.js +1 -1
  22. package/lib/cjs/internal/app-binder/task/BuildFullContextsTask.js.map +2 -2
  23. package/lib/cjs/internal/app-binder/task/BuildFullContextsTask.test.js +1 -1
  24. package/lib/cjs/internal/app-binder/task/BuildFullContextsTask.test.js.map +3 -3
  25. package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.js +1 -1
  26. package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.js.map +3 -3
  27. package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.test.js +1 -1
  28. package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.test.js.map +3 -3
  29. package/lib/cjs/internal/app-binder/task/ParseNestedTransactionTask.js.map +2 -2
  30. package/lib/cjs/internal/app-binder/task/ProvideContextsTask.js +1 -1
  31. package/lib/cjs/internal/app-binder/task/ProvideContextsTask.js.map +3 -3
  32. package/lib/cjs/internal/app-binder/task/ProvideContextsTask.test.js +1 -1
  33. package/lib/cjs/internal/app-binder/task/ProvideContextsTask.test.js.map +3 -3
  34. package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.js +1 -1
  35. package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.js.map +3 -3
  36. package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.test.js +1 -1
  37. package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.test.js.map +3 -3
  38. package/lib/cjs/internal/app-binder/task/SendPayloadInChunksTask.js +1 -1
  39. package/lib/cjs/internal/app-binder/task/SendPayloadInChunksTask.js.map +3 -3
  40. package/lib/cjs/internal/app-binder/task/SendPayloadInChunksTask.test.js +1 -1
  41. package/lib/cjs/internal/app-binder/task/SendPayloadInChunksTask.test.js.map +3 -3
  42. package/lib/esm/api/SignerEthBuilder.test.js +1 -1
  43. package/lib/esm/api/SignerEthBuilder.test.js.map +1 -1
  44. package/lib/esm/internal/app-binder/EthAppBinder.test.js +1 -1
  45. package/lib/esm/internal/app-binder/EthAppBinder.test.js.map +2 -2
  46. package/lib/esm/internal/app-binder/command/ProvideNetworkConfigurationCommand.js +2 -0
  47. package/lib/esm/internal/app-binder/command/ProvideNetworkConfigurationCommand.js.map +7 -0
  48. package/lib/esm/internal/app-binder/command/ProvideNetworkConfigurationCommand.test.js +2 -0
  49. package/lib/esm/internal/app-binder/command/ProvideNetworkConfigurationCommand.test.js.map +7 -0
  50. package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js +1 -1
  51. package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js.map +2 -2
  52. package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js +1 -1
  53. package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js.map +2 -2
  54. package/lib/esm/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.test.js +1 -1
  55. package/lib/esm/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.test.js.map +2 -2
  56. package/lib/esm/internal/app-binder/task/BuildBaseContexts.js +1 -1
  57. package/lib/esm/internal/app-binder/task/BuildBaseContexts.js.map +3 -3
  58. package/lib/esm/internal/app-binder/task/BuildBaseContexts.test.js +1 -1
  59. package/lib/esm/internal/app-binder/task/BuildBaseContexts.test.js.map +2 -2
  60. package/lib/esm/internal/app-binder/task/BuildEIP712ContextTask.test.js +1 -1
  61. package/lib/esm/internal/app-binder/task/BuildEIP712ContextTask.test.js.map +2 -2
  62. package/lib/esm/internal/app-binder/task/BuildFullContextsTask.js +1 -1
  63. package/lib/esm/internal/app-binder/task/BuildFullContextsTask.js.map +2 -2
  64. package/lib/esm/internal/app-binder/task/BuildFullContextsTask.test.js +1 -1
  65. package/lib/esm/internal/app-binder/task/BuildFullContextsTask.test.js.map +3 -3
  66. package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.js +1 -1
  67. package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.js.map +3 -3
  68. package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.test.js +1 -1
  69. package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.test.js.map +3 -3
  70. package/lib/esm/internal/app-binder/task/ParseNestedTransactionTask.js.map +2 -2
  71. package/lib/esm/internal/app-binder/task/ProvideContextsTask.js +1 -1
  72. package/lib/esm/internal/app-binder/task/ProvideContextsTask.js.map +3 -3
  73. package/lib/esm/internal/app-binder/task/ProvideContextsTask.test.js +1 -1
  74. package/lib/esm/internal/app-binder/task/ProvideContextsTask.test.js.map +3 -3
  75. package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.js +1 -1
  76. package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.js.map +3 -3
  77. package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.test.js +1 -1
  78. package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.test.js.map +3 -3
  79. package/lib/esm/internal/app-binder/task/SendPayloadInChunksTask.js +1 -1
  80. package/lib/esm/internal/app-binder/task/SendPayloadInChunksTask.js.map +3 -3
  81. package/lib/esm/internal/app-binder/task/SendPayloadInChunksTask.test.js +1 -1
  82. package/lib/esm/internal/app-binder/task/SendPayloadInChunksTask.test.js.map +3 -3
  83. package/lib/types/internal/app-binder/command/ProvideNetworkConfigurationCommand.d.ts +28 -0
  84. package/lib/types/internal/app-binder/command/ProvideNetworkConfigurationCommand.d.ts.map +1 -0
  85. package/lib/types/internal/app-binder/command/ProvideNetworkConfigurationCommand.test.d.ts +2 -0
  86. package/lib/types/internal/app-binder/command/ProvideNetworkConfigurationCommand.test.d.ts.map +1 -0
  87. package/lib/types/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.d.ts.map +1 -1
  88. package/lib/types/internal/app-binder/task/BuildBaseContexts.d.ts.map +1 -1
  89. package/lib/types/internal/app-binder/task/BuildFullContextsTask.d.ts +2 -1
  90. package/lib/types/internal/app-binder/task/BuildFullContextsTask.d.ts.map +1 -1
  91. package/lib/types/internal/app-binder/task/BuildSubcontextsTask.d.ts +10 -2
  92. package/lib/types/internal/app-binder/task/BuildSubcontextsTask.d.ts.map +1 -1
  93. package/lib/types/internal/app-binder/task/ParseNestedTransactionTask.d.ts.map +1 -1
  94. package/lib/types/internal/app-binder/task/ProvideContextsTask.d.ts.map +1 -1
  95. package/lib/types/internal/app-binder/task/ProvideEIP712ContextTask.d.ts.map +1 -1
  96. package/lib/types/internal/app-binder/task/SendPayloadInChunksTask.d.ts +1 -0
  97. package/lib/types/internal/app-binder/task/SendPayloadInChunksTask.d.ts.map +1 -1
  98. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  99. package/package.json +9 -9
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.test.ts"],
4
- "sourcesContent": ["/* eslint @typescript-eslint/consistent-type-imports: 0 */\nimport { type ContextModule } from \"@ledgerhq/context-module\";\nimport {\n CommandResultFactory,\n DeviceActionStatus,\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n InvalidStatusWordError,\n UnknownDAError,\n UnknownDeviceExchangeError,\n UserInteractionRequired,\n} from \"@ledgerhq/device-management-kit\";\nimport { Just, Nothing } from \"purify-ts\";\n\nimport { type SignTypedDataDAState } from \"@api/app-binder/SignTypedDataDeviceActionTypes\";\nimport { SignTypedDataDAStateStep } from \"@api/app-binder/SignTypedDataDeviceActionTypes\";\nimport { EthAppCommandErrorFactory } from \"@internal/app-binder/command/utils/ethAppErrors\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\nimport { setupOpenAppDAMock } from \"@internal/app-binder/device-action/__test-utils__/setupOpenAppDAMock\";\nimport { testDeviceActionStates } from \"@internal/app-binder/device-action/__test-utils__/testDeviceActionStates\";\nimport { type ProvideEIP712ContextTaskArgs } from \"@internal/app-binder/task/ProvideEIP712ContextTask\";\nimport {\n PrimitiveType,\n StructType,\n TypedDataValueField,\n} from \"@internal/typed-data/model/Types\";\nimport { type TypedDataParserService } from \"@internal/typed-data/service/TypedDataParserService\";\n\nimport { SignTypedDataDeviceAction } from \"./SignTypedDataDeviceAction\";\n\nvi.mock(\"@ledgerhq/device-management-kit\", async (importOriginal) => {\n const original =\n await importOriginal<typeof import(\"@ledgerhq/device-management-kit\")>();\n return {\n ...original,\n OpenAppDeviceAction: vi.fn(() => ({\n makeStateMachine: vi.fn(),\n })),\n };\n});\n\ndescribe(\"SignTypedDataDeviceAction\", () => {\n const TEST_MESSAGE = {\n domain: {},\n message: {},\n primaryType: \"TestMessage\",\n types: {},\n };\n const TEST_BUILT_CONTEXT: ProvideEIP712ContextTaskArgs = {\n web3Check: null,\n types: {\n PermitSingle: {\n details: new StructType(\"PermitDetails\"),\n spender: new PrimitiveType(\"address\", \"address\", Nothing),\n sigDeadline: new PrimitiveType(\"uint256\", \"uint\", Just(32)),\n },\n },\n domain: [\n {\n path: \"chainId\",\n type: \"uint256\",\n value: new TypedDataValueField(Uint8Array.from([137])),\n },\n ],\n message: [\n {\n path: \"details.expiration\",\n type: \"uint48\",\n value: new TypedDataValueField(Uint8Array.from([0x13])),\n },\n ],\n clearSignContext: Just({\n type: \"success\",\n messageInfo: {\n displayName: \"Permit2\",\n filtersCount: 1,\n signature:\n \"3045022100e3c597d13d28a87a88b0239404c668373cf5063362f2a81d09eed4582941dfe802207669aabb504fd5b95b2734057f6b8bbf51f14a69a5f9bdf658a5952cefbf44d3\",\n },\n trustedNamesAddresses: {},\n tokens: {},\n filters: {\n \"details.amount\": {\n displayName: \"Amount allowance\",\n path: \"details.amount\",\n signature:\n \"304402201a46e6b4ef89eaf9fcf4945d053bfc5616a826400fd758312fbbe976bafc07ec022025a9b408722baf983ee053f90179c75b0c55bb0668f437d55493e36069bbd5a3\",\n tokenIndex: 255,\n type: \"amount\",\n },\n },\n }),\n };\n\n const mockParser: TypedDataParserService = {\n parse: vi.fn(),\n };\n const mockContextModule: ContextModule = {\n getContext: vi.fn(),\n getContexts: vi.fn(),\n getTypedDataFilters: vi.fn(),\n getWeb3Checks: vi.fn(),\n getSolanaContext: vi.fn(),\n };\n const apiMock = makeDeviceActionInternalApiMock();\n const getAppConfigMock = vi.fn();\n const web3CheckOptInMock = vi.fn();\n const buildContextMock = vi.fn();\n const provideContextMock = vi.fn();\n const signTypedDataMock = vi.fn();\n const signTypedDataLegacyMock = vi.fn();\n function extractDependenciesMock() {\n return {\n getAppConfig: getAppConfigMock,\n web3CheckOptIn: web3CheckOptInMock,\n buildContext: buildContextMock,\n provideContext: provideContextMock,\n signTypedData: signTypedDataMock,\n signTypedDataLegacy: signTypedDataLegacyMock,\n };\n }\n\n function createAppConfig(\n version: string,\n web3ChecksEnabled: boolean,\n web3ChecksOptIn: boolean,\n ) {\n return {\n blindSigningEnabled: false,\n web3ChecksEnabled,\n web3ChecksOptIn,\n version,\n };\n }\n\n function setupAppConfig(\n version: string,\n web3ChecksEnabled: boolean,\n web3ChecksOptIn: boolean,\n ) {\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n getAppConfigMock.mockResolvedValue(\n CommandResultFactory({\n data: createAppConfig(version, web3ChecksEnabled, web3ChecksOptIn),\n }),\n );\n }\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n describe(\"Success case\", () => {\n it(\"should call external dependencies with the correct parameters\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n setupAppConfig(\"1.15.0\", false, false);\n\n const deviceAction = new SignTypedDataDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n data: TEST_MESSAGE,\n contextModule: mockContextModule,\n parser: mockParser,\n skipOpenApp: false,\n },\n });\n\n // Mock the dependencies to return some sample data\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n buildContextMock.mockResolvedValueOnce(TEST_BUILT_CONTEXT);\n provideContextMock.mockResolvedValueOnce(\n CommandResultFactory({ data: undefined }),\n );\n signTypedDataMock.mockResolvedValueOnce(\n CommandResultFactory({\n data: {\n v: 0x1c,\n r: \"0x8a540510e13b0f2b11a451275716d29e08caad07e89a1c84964782fb5e1ad788\",\n s: \"0x64a0de235b270fbe81e8e40688f4a9f9ad9d283d690552c9331d7773ceafa513\",\n },\n }),\n );\n\n // Expected intermediate values for the following state sequence:\n // Initial -> OpenApp -> BuildContext -> ProvideContext -> SignTypedData\n const expectedStates: Array<SignTypedDataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.GET_APP_CONFIG,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.BUILD_CONTEXT,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.SignTypedData,\n step: SignTypedDataDAStateStep.PROVIDE_CONTEXT,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.SignTypedData,\n step: SignTypedDataDAStateStep.SIGN_TYPED_DATA,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n output: {\n v: 0x1c,\n r: \"0x8a540510e13b0f2b11a451275716d29e08caad07e89a1c84964782fb5e1ad788\",\n s: \"0x64a0de235b270fbe81e8e40688f4a9f9ad9d283d690552c9331d7773ceafa513\",\n },\n status: DeviceActionStatus.Completed,\n },\n ];\n\n testDeviceActionStates(deviceAction, expectedStates, apiMock, {\n onError: reject,\n onDone: () => {\n // Verify mocks calls parameters\n expect(buildContextMock).toHaveBeenCalledWith(\n expect.objectContaining({\n input: {\n contextModule: mockContextModule,\n parser: mockParser,\n data: TEST_MESSAGE,\n appConfig: createAppConfig(\"1.15.0\", false, false),\n derivationPath: \"44'/60'/0'/0/0\",\n },\n }),\n );\n\n expect(provideContextMock).toHaveBeenCalledWith(\n expect.objectContaining({\n input: {\n contextModule: mockContextModule,\n taskArgs: TEST_BUILT_CONTEXT,\n },\n }),\n );\n\n expect(signTypedDataMock).toHaveBeenCalledWith(\n expect.objectContaining({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n },\n }),\n );\n\n resolve();\n },\n });\n }));\n\n it(\"should be successful whlie skipping OpenApp\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n setupAppConfig(\"1.15.0\", false, false);\n\n const deviceAction = new SignTypedDataDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n data: TEST_MESSAGE,\n contextModule: mockContextModule,\n parser: mockParser,\n skipOpenApp: true,\n },\n });\n\n // Mock the dependencies to return some sample data\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n buildContextMock.mockResolvedValueOnce(TEST_BUILT_CONTEXT);\n provideContextMock.mockResolvedValueOnce(\n CommandResultFactory({ data: undefined }),\n );\n signTypedDataMock.mockResolvedValueOnce(\n CommandResultFactory({\n data: {\n v: 0x1c,\n r: \"0x8a540510e13b0f2b11a451275716d29e08caad07e89a1c84964782fb5e1ad788\",\n s: \"0x64a0de235b270fbe81e8e40688f4a9f9ad9d283d690552c9331d7773ceafa513\",\n },\n }),\n );\n\n // Expected intermediate values for the following state sequence:\n // Initial -> BuildContext -> ProvideContext -> SignTypedData\n const expectedStates: Array<SignTypedDataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.GET_APP_CONFIG,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.BUILD_CONTEXT,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.SignTypedData,\n step: SignTypedDataDAStateStep.PROVIDE_CONTEXT,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.SignTypedData,\n step: SignTypedDataDAStateStep.SIGN_TYPED_DATA,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n output: {\n v: 0x1c,\n r: \"0x8a540510e13b0f2b11a451275716d29e08caad07e89a1c84964782fb5e1ad788\",\n s: \"0x64a0de235b270fbe81e8e40688f4a9f9ad9d283d690552c9331d7773ceafa513\",\n },\n status: DeviceActionStatus.Completed,\n },\n ];\n\n testDeviceActionStates(deviceAction, expectedStates, apiMock, {\n onError: reject,\n onDone: resolve,\n });\n }));\n\n it(\"should fallback to legacy signing if the new one fails\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n setupAppConfig(\"1.15.0\", false, false);\n\n const deviceAction = new SignTypedDataDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n data: TEST_MESSAGE,\n contextModule: mockContextModule,\n parser: mockParser,\n skipOpenApp: false,\n },\n });\n\n // Mock the providing error\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n buildContextMock.mockResolvedValueOnce(TEST_BUILT_CONTEXT);\n provideContextMock.mockResolvedValueOnce(\n CommandResultFactory({\n error: EthAppCommandErrorFactory({\n errorCode: \"6a80\",\n message: \"\",\n }),\n }),\n );\n signTypedDataLegacyMock.mockResolvedValueOnce(\n CommandResultFactory({\n data: {\n v: 0x1c,\n r: \"0x8a540510e13b0f2b11a451275716d29e08caad07e89a1c84964782fb5e1ad788\",\n s: \"0x64a0de235b270fbe81e8e40688f4a9f9ad9d283d690552c9331d7773ceafa513\",\n },\n }),\n );\n\n const expectedStates: Array<SignTypedDataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.GET_APP_CONFIG,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.BUILD_CONTEXT,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.SignTypedData,\n step: SignTypedDataDAStateStep.PROVIDE_CONTEXT,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.SignTypedData,\n step: SignTypedDataDAStateStep.SIGN_TYPED_DATA_LEGACY,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n output: {\n v: 0x1c,\n r: \"0x8a540510e13b0f2b11a451275716d29e08caad07e89a1c84964782fb5e1ad788\",\n s: \"0x64a0de235b270fbe81e8e40688f4a9f9ad9d283d690552c9331d7773ceafa513\",\n },\n status: DeviceActionStatus.Completed,\n },\n ];\n\n testDeviceActionStates(deviceAction, expectedStates, apiMock, {\n onError: reject,\n onDone: resolve,\n });\n }));\n\n it(\"should fallback to legacy signing BuildContext fails\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n setupAppConfig(\"1.15.0\", false, false);\n\n const deviceAction = new SignTypedDataDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n data: TEST_MESSAGE,\n contextModule: mockContextModule,\n parser: mockParser,\n skipOpenApp: false,\n },\n });\n\n // Mock the providing error\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n buildContextMock.mockRejectedValueOnce(new UnknownDAError(\"Error\"));\n signTypedDataLegacyMock.mockResolvedValueOnce(\n CommandResultFactory({\n data: {\n v: 0x1c,\n r: \"0x8a540510e13b0f2b11a451275716d29e08caad07e89a1c84964782fb5e1ad788\",\n s: \"0x64a0de235b270fbe81e8e40688f4a9f9ad9d283d690552c9331d7773ceafa513\",\n },\n }),\n );\n\n const expectedStates: Array<SignTypedDataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.GET_APP_CONFIG,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.BUILD_CONTEXT,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.SignTypedData,\n step: SignTypedDataDAStateStep.SIGN_TYPED_DATA_LEGACY,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n output: {\n v: 0x1c,\n r: \"0x8a540510e13b0f2b11a451275716d29e08caad07e89a1c84964782fb5e1ad788\",\n s: \"0x64a0de235b270fbe81e8e40688f4a9f9ad9d283d690552c9331d7773ceafa513\",\n },\n status: DeviceActionStatus.Completed,\n },\n ];\n\n testDeviceActionStates(deviceAction, expectedStates, apiMock, {\n onError: reject,\n onDone: resolve,\n });\n }));\n\n it(\"should not fallback to legacy signing if rejected by the user during streaming\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n setupAppConfig(\"1.15.0\", false, false);\n\n const deviceAction = new SignTypedDataDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n data: TEST_MESSAGE,\n contextModule: mockContextModule,\n parser: mockParser,\n skipOpenApp: false,\n },\n });\n\n // Mock the providing error\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n buildContextMock.mockResolvedValueOnce(TEST_BUILT_CONTEXT);\n provideContextMock.mockResolvedValueOnce(\n CommandResultFactory({\n error: EthAppCommandErrorFactory({\n errorCode: \"6985\",\n message: \"\",\n }),\n }),\n );\n signTypedDataLegacyMock.mockResolvedValueOnce(\n CommandResultFactory({\n data: {\n v: 0x1c,\n r: \"0x8a540510e13b0f2b11a451275716d29e08caad07e89a1c84964782fb5e1ad788\",\n s: \"0x64a0de235b270fbe81e8e40688f4a9f9ad9d283d690552c9331d7773ceafa513\",\n },\n }),\n );\n\n const expectedStates: Array<SignTypedDataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.GET_APP_CONFIG,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.BUILD_CONTEXT,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.SignTypedData,\n step: SignTypedDataDAStateStep.PROVIDE_CONTEXT,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n error: EthAppCommandErrorFactory({\n errorCode: \"6985\",\n message: \"\",\n }),\n status: DeviceActionStatus.Error,\n },\n ];\n\n testDeviceActionStates(deviceAction, expectedStates, apiMock, {\n onError: reject,\n onDone: resolve,\n });\n }));\n });\n\n describe(\"Web3Checks\", () => {\n it(\"should call external dependencies with web3Checks enabled and supported\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n setupAppConfig(\"1.16.0\", true, true);\n\n const deviceAction = new SignTypedDataDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n data: TEST_MESSAGE,\n contextModule: mockContextModule,\n parser: mockParser,\n skipOpenApp: false,\n },\n });\n\n // Mock the dependencies to return some sample data\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n buildContextMock.mockRejectedValueOnce(\n new InvalidStatusWordError(\"buildContext error\"),\n );\n signTypedDataLegacyMock.mockRejectedValueOnce(\n new InvalidStatusWordError(\"signTypedDataLegacy error\"),\n );\n\n // Expected intermediate values for the following state sequence:\n // Initial -> OpenApp -> GetAppConfiguration -> BuildContext\n const expectedStates: Array<SignTypedDataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.GET_APP_CONFIG,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.BUILD_CONTEXT,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.SignTypedData,\n step: SignTypedDataDAStateStep.SIGN_TYPED_DATA_LEGACY,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n error: new InvalidStatusWordError(\"signTypedDataLegacy error\"),\n status: DeviceActionStatus.Error,\n },\n ];\n\n testDeviceActionStates(deviceAction, expectedStates, apiMock, {\n onError: reject,\n onDone: () => {\n // Verify mocks calls parameters\n expect(getAppConfigMock).toHaveBeenCalled();\n expect(buildContextMock).toHaveBeenCalledWith(\n expect.objectContaining({\n input: {\n contextModule: mockContextModule,\n parser: mockParser,\n data: TEST_MESSAGE,\n appConfig: createAppConfig(\"1.16.0\", true, true),\n derivationPath: \"44'/60'/0'/0/0\",\n },\n }),\n );\n resolve();\n },\n });\n }));\n\n it(\"should call external dependencies with web3Checks supported but disabled\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n setupAppConfig(\"1.16.0\", false, true);\n\n const deviceAction = new SignTypedDataDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n data: TEST_MESSAGE,\n contextModule: mockContextModule,\n parser: mockParser,\n skipOpenApp: false,\n },\n });\n\n // Mock the dependencies to return some sample data\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n buildContextMock.mockRejectedValueOnce(\n new InvalidStatusWordError(\"buildContext error\"),\n );\n signTypedDataLegacyMock.mockRejectedValueOnce(\n new InvalidStatusWordError(\"signTypedDataLegacy error\"),\n );\n\n // Expected intermediate values for the following state sequence:\n // Initial -> OpenApp -> GetAppConfiguration -> BuildContext\n const expectedStates: Array<SignTypedDataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.GET_APP_CONFIG,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.BUILD_CONTEXT,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.SignTypedData,\n step: SignTypedDataDAStateStep.SIGN_TYPED_DATA_LEGACY,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n error: new InvalidStatusWordError(\"signTypedDataLegacy error\"),\n status: DeviceActionStatus.Error,\n },\n ];\n\n testDeviceActionStates(deviceAction, expectedStates, apiMock, {\n onError: reject,\n onDone: () => {\n // Verify mocks calls parameters\n expect(getAppConfigMock).toHaveBeenCalled();\n expect(buildContextMock).toHaveBeenCalledWith(\n expect.objectContaining({\n input: {\n contextModule: mockContextModule,\n parser: mockParser,\n data: TEST_MESSAGE,\n appConfig: createAppConfig(\"1.16.0\", false, true),\n derivationPath: \"44'/60'/0'/0/0\",\n },\n }),\n );\n resolve();\n },\n });\n }));\n\n it(\"should call external dependencies with web3Checks opt-in, then enabled\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n setupAppConfig(\"1.16.0\", false, false);\n\n const deviceAction = new SignTypedDataDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n data: TEST_MESSAGE,\n contextModule: mockContextModule,\n parser: mockParser,\n skipOpenApp: false,\n },\n });\n\n // Mock the dependencies to return some sample data\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n web3CheckOptInMock.mockResolvedValueOnce(\n CommandResultFactory({ data: { enabled: true } }),\n );\n buildContextMock.mockRejectedValueOnce(\n new InvalidStatusWordError(\"buildContext error\"),\n );\n signTypedDataLegacyMock.mockRejectedValueOnce(\n new InvalidStatusWordError(\"signTypedDataLegacy error\"),\n );\n\n // Expected intermediate values for the following state sequence:\n // Initial -> OpenApp -> GetAppConfiguration -> Web3ChecksOptIn -> BuildContext\n const expectedStates: Array<SignTypedDataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.GET_APP_CONFIG,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.Web3ChecksOptIn,\n step: SignTypedDataDAStateStep.WEB3_CHECKS_OPT_IN,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.WEB3_CHECKS_OPT_IN_RESULT,\n result: true,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.BUILD_CONTEXT,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.SignTypedData,\n step: SignTypedDataDAStateStep.SIGN_TYPED_DATA_LEGACY,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n error: new InvalidStatusWordError(\"signTypedDataLegacy error\"),\n status: DeviceActionStatus.Error,\n },\n ];\n\n testDeviceActionStates(deviceAction, expectedStates, apiMock, {\n onError: reject,\n onDone: () => {\n // Verify mocks calls parameters\n expect(getAppConfigMock).toHaveBeenCalled();\n expect(web3CheckOptInMock).toHaveBeenCalled();\n expect(buildContextMock).toHaveBeenCalledWith(\n expect.objectContaining({\n input: {\n contextModule: mockContextModule,\n parser: mockParser,\n data: TEST_MESSAGE,\n appConfig: createAppConfig(\"1.16.0\", true, false),\n derivationPath: \"44'/60'/0'/0/0\",\n },\n }),\n );\n resolve();\n },\n });\n }));\n\n it(\"should call external dependencies with web3Checks opt-in, then disabled\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n setupAppConfig(\"1.16.0\", false, false);\n\n const deviceAction = new SignTypedDataDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n data: TEST_MESSAGE,\n contextModule: mockContextModule,\n parser: mockParser,\n skipOpenApp: false,\n },\n });\n\n // Mock the dependencies to return some sample data\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n web3CheckOptInMock.mockResolvedValueOnce(\n CommandResultFactory({ data: { enabled: false } }),\n );\n buildContextMock.mockRejectedValueOnce(\n new InvalidStatusWordError(\"buildContext error\"),\n );\n signTypedDataLegacyMock.mockRejectedValueOnce(\n new InvalidStatusWordError(\"signTypedDataLegacy error\"),\n );\n\n // Expected intermediate values for the following state sequence:\n // Initial -> OpenApp -> GetAppConfiguration -> Web3ChecksOptIn -> BuildContext\n const expectedStates: Array<SignTypedDataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.GET_APP_CONFIG,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.Web3ChecksOptIn,\n step: SignTypedDataDAStateStep.WEB3_CHECKS_OPT_IN,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.WEB3_CHECKS_OPT_IN_RESULT,\n result: false,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.BUILD_CONTEXT,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.SignTypedData,\n step: SignTypedDataDAStateStep.SIGN_TYPED_DATA_LEGACY,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n error: new InvalidStatusWordError(\"signTypedDataLegacy error\"),\n status: DeviceActionStatus.Error,\n },\n ];\n\n testDeviceActionStates(deviceAction, expectedStates, apiMock, {\n onError: reject,\n onDone: () => {\n // Verify mocks calls parameters\n expect(getAppConfigMock).toHaveBeenCalled();\n expect(web3CheckOptInMock).toHaveBeenCalled();\n expect(buildContextMock).toHaveBeenCalledWith(\n expect.objectContaining({\n input: {\n contextModule: mockContextModule,\n parser: mockParser,\n data: TEST_MESSAGE,\n appConfig: createAppConfig(\"1.16.0\", false, false),\n derivationPath: \"44'/60'/0'/0/0\",\n },\n }),\n );\n resolve();\n },\n });\n }));\n });\n\n describe(\"error cases\", () => {\n it(\"Error if the open app fails\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock(new UnknownDAError(\"Mocked error\"));\n\n const expectedStates: Array<SignTypedDataDAState> = [\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n },\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n },\n {\n status: DeviceActionStatus.Error,\n error: new UnknownDAError(\"Mocked error\"),\n },\n ];\n\n const deviceAction = new SignTypedDataDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n data: TEST_MESSAGE,\n contextModule: mockContextModule,\n parser: mockParser,\n skipOpenApp: false,\n },\n });\n\n testDeviceActionStates(deviceAction, expectedStates, apiMock, {\n onError: reject,\n onDone: resolve,\n });\n }));\n\n it(\"Error thrown while providing context\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n setupAppConfig(\"1.15.0\", false, false);\n\n const deviceAction = new SignTypedDataDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n data: TEST_MESSAGE,\n contextModule: mockContextModule,\n parser: mockParser,\n skipOpenApp: false,\n },\n });\n\n // Mock the providing error\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n buildContextMock.mockResolvedValueOnce(TEST_BUILT_CONTEXT);\n provideContextMock.mockRejectedValueOnce(new UnknownDAError(\"Error\"));\n\n const expectedStates: Array<SignTypedDataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.GET_APP_CONFIG,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.BUILD_CONTEXT,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.SignTypedData,\n step: SignTypedDataDAStateStep.PROVIDE_CONTEXT,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n error: new UnknownDAError(\"Error\"),\n status: DeviceActionStatus.Error,\n },\n ];\n\n testDeviceActionStates(deviceAction, expectedStates, apiMock, {\n onError: reject,\n onDone: resolve,\n });\n }));\n\n it(\"Error while signing\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n setupAppConfig(\"1.15.0\", false, false);\n\n const deviceAction = new SignTypedDataDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n data: TEST_MESSAGE,\n contextModule: mockContextModule,\n parser: mockParser,\n skipOpenApp: false,\n },\n });\n\n // Mock signing error\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n buildContextMock.mockResolvedValueOnce(TEST_BUILT_CONTEXT);\n provideContextMock.mockResolvedValueOnce(\n CommandResultFactory({ data: undefined }),\n );\n signTypedDataMock.mockResolvedValueOnce(\n CommandResultFactory({\n error: new UnknownDeviceExchangeError(\n \"Error while signing the typed data\",\n ),\n }),\n );\n\n const expectedStates: Array<SignTypedDataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.GET_APP_CONFIG,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.BUILD_CONTEXT,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.SignTypedData,\n step: SignTypedDataDAStateStep.PROVIDE_CONTEXT,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.SignTypedData,\n step: SignTypedDataDAStateStep.SIGN_TYPED_DATA,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n error: new UnknownDeviceExchangeError(\n \"Error while signing the typed data\",\n ),\n status: DeviceActionStatus.Error,\n },\n ];\n\n testDeviceActionStates(deviceAction, expectedStates, apiMock, {\n onError: reject,\n onDone: resolve,\n });\n }));\n });\n});\n"],
5
- "mappings": "aAEA,IAAAA,EAUO,2CACPC,EAA8B,qBAG9BC,EAAyC,0DACzCC,EAA0C,2DAC1CC,EAAgD,6EAChDC,EAAmC,gFACnCC,EAAuC,oFAEvCC,EAIO,4CAGPC,EAA0C,uCAE1C,GAAG,KAAK,kCAAmC,MAAOC,IAGzC,CACL,GAFA,MAAMA,EAAiE,EAGvE,oBAAqB,GAAG,GAAG,KAAO,CAChC,iBAAkB,GAAG,GAAG,CAC1B,EAAE,CACJ,EACD,EAED,SAAS,4BAA6B,IAAM,CAC1C,MAAMC,EAAe,CACnB,OAAQ,CAAC,EACT,QAAS,CAAC,EACV,YAAa,cACb,MAAO,CAAC,CACV,EACMC,EAAmD,CACvD,UAAW,KACX,MAAO,CACL,aAAc,CACZ,QAAS,IAAI,aAAW,eAAe,EACvC,QAAS,IAAI,gBAAc,UAAW,UAAW,SAAO,EACxD,YAAa,IAAI,gBAAc,UAAW,UAAQ,QAAK,EAAE,CAAC,CAC5D,CACF,EACA,OAAQ,CACN,CACE,KAAM,UACN,KAAM,UACN,MAAO,IAAI,sBAAoB,WAAW,KAAK,CAAC,GAAG,CAAC,CAAC,CACvD,CACF,EACA,QAAS,CACP,CACE,KAAM,qBACN,KAAM,SACN,MAAO,IAAI,sBAAoB,WAAW,KAAK,CAAC,EAAI,CAAC,CAAC,CACxD,CACF,EACA,oBAAkB,QAAK,CACrB,KAAM,UACN,YAAa,CACX,YAAa,UACb,aAAc,EACd,UACE,gJACJ,EACA,sBAAuB,CAAC,EACxB,OAAQ,CAAC,EACT,QAAS,CACP,iBAAkB,CAChB,YAAa,mBACb,KAAM,iBACN,UACE,+IACF,WAAY,IACZ,KAAM,QACR,CACF,CACF,CAAC,CACH,EAEMC,EAAqC,CACzC,MAAO,GAAG,GAAG,CACf,EACMC,EAAmC,CACvC,WA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,IAAW,IACrC,sBAAmB,EACnBF,EAAe,SAAU,GAAO,EAAK,EAErC,MAAMG,EAAe,IAAI,4BAA0B,CACjD,MAAO,CACL,eAAgB,iBAChB,KAAMnB,EACN,cAAeG,EACf,OAAQD,EACR,YAAa,EACf,CACF,CAAC,EAGD,GAAG,MAAMiB,EAAc,qBAAqB,EAAE,gBAC5CR,EAAwB,CAC1B,EACAJ,EAAiB,sBAAsBN,CAAkB,EACzDO,EAAmB,yBACjB,wBAAqB,CAAE,KAAM,MAAU,CAAC,CAC1C,EACAC,EAAkB,yBAChB,wBAAqB,CACnB,MAAO,IAAI,6BACT,oCACF,CACF,CAAC,CACH,EAEA,MAAMW,EAA8C,CAClD,CACE,kBAAmB,CACjB,wBAAyB,0BAAwB,KACjD,KAAM,2BAAyB,QACjC,EACA,OAAQ,qBAAmB,OAC7B,EACA,CACE,kBAAmB,CACjB,wBAAyB,0BAAwB,eACjD,KAAM,2BAAyB,QACjC,EACA,OAAQ,qBAAmB,OAC7B,EACA,CACE,kBAAmB,CACjB,wBAAyB,0BAAwB,KACjD,KAAM,2BAAyB,cACjC,EACA,OAAQ,qBAAmB,OAC7B,EACA,CACE,kBAAmB,CACjB,wBAAyB,0BAAwB,KACjD,KAAM,2BAAyB,aACjC,EACA,OAAQ,qBAAmB,OAC7B,EACA,CACE,kBAAmB,CACjB,wBAAyB,0BAAwB,cACjD,KAAM,2BAAyB,eACjC,EACA,OAAQ,qBAAmB,OAC7B,EACA,CACE,kBAAmB,CACjB,wBAAyB,0BAAwB,cACjD,KAAM,2BAAyB,eACjC,EACA,OAAQ,qBAAmB,OAC7B,EACA,CACE,MAAO,IAAI,6BACT,oCACF,EACA,OAAQ,qBAAmB,KAC7B,CACF,KAEA,0BAAuBD,EAAcC,EAAgBhB,EAAS,CAC5D,QAASc,EACT,OAAQD,CACV,CAAC,CACH,CAAC,CAAC,CACN,CAAC,CACH,CAAC",
4
+ "sourcesContent": ["/* eslint @typescript-eslint/consistent-type-imports: 0 */\nimport { type ContextModule } from \"@ledgerhq/context-module\";\nimport {\n CommandResultFactory,\n DeviceActionStatus,\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n InvalidStatusWordError,\n UnknownDAError,\n UnknownDeviceExchangeError,\n UserInteractionRequired,\n} from \"@ledgerhq/device-management-kit\";\nimport { Just, Nothing } from \"purify-ts\";\n\nimport { type SignTypedDataDAState } from \"@api/app-binder/SignTypedDataDeviceActionTypes\";\nimport { SignTypedDataDAStateStep } from \"@api/app-binder/SignTypedDataDeviceActionTypes\";\nimport { EthAppCommandErrorFactory } from \"@internal/app-binder/command/utils/ethAppErrors\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\nimport { setupOpenAppDAMock } from \"@internal/app-binder/device-action/__test-utils__/setupOpenAppDAMock\";\nimport { testDeviceActionStates } from \"@internal/app-binder/device-action/__test-utils__/testDeviceActionStates\";\nimport { type ProvideEIP712ContextTaskArgs } from \"@internal/app-binder/task/ProvideEIP712ContextTask\";\nimport {\n PrimitiveType,\n StructType,\n TypedDataValueField,\n} from \"@internal/typed-data/model/Types\";\nimport { type TypedDataParserService } from \"@internal/typed-data/service/TypedDataParserService\";\n\nimport { SignTypedDataDeviceAction } from \"./SignTypedDataDeviceAction\";\n\nvi.mock(\"@ledgerhq/device-management-kit\", async (importOriginal) => {\n const original =\n await importOriginal<typeof import(\"@ledgerhq/device-management-kit\")>();\n return {\n ...original,\n OpenAppDeviceAction: vi.fn(() => ({\n makeStateMachine: vi.fn(),\n })),\n };\n});\n\ndescribe(\"SignTypedDataDeviceAction\", () => {\n const TEST_MESSAGE = {\n domain: {},\n message: {},\n primaryType: \"TestMessage\",\n types: {},\n };\n const TEST_BUILT_CONTEXT: ProvideEIP712ContextTaskArgs = {\n web3Check: null,\n types: {\n PermitSingle: {\n details: new StructType(\"PermitDetails\"),\n spender: new PrimitiveType(\"address\", \"address\", Nothing),\n sigDeadline: new PrimitiveType(\"uint256\", \"uint\", Just(32)),\n },\n },\n domain: [\n {\n path: \"chainId\",\n type: \"uint256\",\n value: new TypedDataValueField(Uint8Array.from([137])),\n },\n ],\n message: [\n {\n path: \"details.expiration\",\n type: \"uint48\",\n value: new TypedDataValueField(Uint8Array.from([0x13])),\n },\n ],\n clearSignContext: Just({\n type: \"success\",\n messageInfo: {\n displayName: \"Permit2\",\n filtersCount: 1,\n signature:\n \"3045022100e3c597d13d28a87a88b0239404c668373cf5063362f2a81d09eed4582941dfe802207669aabb504fd5b95b2734057f6b8bbf51f14a69a5f9bdf658a5952cefbf44d3\",\n },\n trustedNamesAddresses: {},\n tokens: {},\n filters: {\n \"details.amount\": {\n displayName: \"Amount allowance\",\n path: \"details.amount\",\n signature:\n \"304402201a46e6b4ef89eaf9fcf4945d053bfc5616a826400fd758312fbbe976bafc07ec022025a9b408722baf983ee053f90179c75b0c55bb0668f437d55493e36069bbd5a3\",\n tokenIndex: 255,\n type: \"amount\",\n },\n },\n }),\n };\n\n const mockParser: TypedDataParserService = {\n parse: vi.fn(),\n };\n const mockContextModule: ContextModule = {\n getFieldContext: vi.fn(),\n getContexts: vi.fn(),\n getTypedDataFilters: vi.fn(),\n getWeb3Checks: vi.fn(),\n getSolanaContext: vi.fn(),\n getProxyDelegateCall: vi.fn(),\n };\n const apiMock = makeDeviceActionInternalApiMock();\n const getAppConfigMock = vi.fn();\n const web3CheckOptInMock = vi.fn();\n const buildContextMock = vi.fn();\n const provideContextMock = vi.fn();\n const signTypedDataMock = vi.fn();\n const signTypedDataLegacyMock = vi.fn();\n function extractDependenciesMock() {\n return {\n getAppConfig: getAppConfigMock,\n web3CheckOptIn: web3CheckOptInMock,\n buildContext: buildContextMock,\n provideContext: provideContextMock,\n signTypedData: signTypedDataMock,\n signTypedDataLegacy: signTypedDataLegacyMock,\n };\n }\n\n function createAppConfig(\n version: string,\n web3ChecksEnabled: boolean,\n web3ChecksOptIn: boolean,\n ) {\n return {\n blindSigningEnabled: false,\n web3ChecksEnabled,\n web3ChecksOptIn,\n version,\n };\n }\n\n function setupAppConfig(\n version: string,\n web3ChecksEnabled: boolean,\n web3ChecksOptIn: boolean,\n ) {\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n getAppConfigMock.mockResolvedValue(\n CommandResultFactory({\n data: createAppConfig(version, web3ChecksEnabled, web3ChecksOptIn),\n }),\n );\n }\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n describe(\"Success case\", () => {\n it(\"should call external dependencies with the correct parameters\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n setupAppConfig(\"1.15.0\", false, false);\n\n const deviceAction = new SignTypedDataDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n data: TEST_MESSAGE,\n contextModule: mockContextModule,\n parser: mockParser,\n skipOpenApp: false,\n },\n });\n\n // Mock the dependencies to return some sample data\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n buildContextMock.mockResolvedValueOnce(TEST_BUILT_CONTEXT);\n provideContextMock.mockResolvedValueOnce(\n CommandResultFactory({ data: undefined }),\n );\n signTypedDataMock.mockResolvedValueOnce(\n CommandResultFactory({\n data: {\n v: 0x1c,\n r: \"0x8a540510e13b0f2b11a451275716d29e08caad07e89a1c84964782fb5e1ad788\",\n s: \"0x64a0de235b270fbe81e8e40688f4a9f9ad9d283d690552c9331d7773ceafa513\",\n },\n }),\n );\n\n // Expected intermediate values for the following state sequence:\n // Initial -> OpenApp -> BuildContext -> ProvideContext -> SignTypedData\n const expectedStates: Array<SignTypedDataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.GET_APP_CONFIG,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.BUILD_CONTEXT,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.SignTypedData,\n step: SignTypedDataDAStateStep.PROVIDE_CONTEXT,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.SignTypedData,\n step: SignTypedDataDAStateStep.SIGN_TYPED_DATA,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n output: {\n v: 0x1c,\n r: \"0x8a540510e13b0f2b11a451275716d29e08caad07e89a1c84964782fb5e1ad788\",\n s: \"0x64a0de235b270fbe81e8e40688f4a9f9ad9d283d690552c9331d7773ceafa513\",\n },\n status: DeviceActionStatus.Completed,\n },\n ];\n\n testDeviceActionStates(deviceAction, expectedStates, apiMock, {\n onError: reject,\n onDone: () => {\n // Verify mocks calls parameters\n expect(buildContextMock).toHaveBeenCalledWith(\n expect.objectContaining({\n input: {\n contextModule: mockContextModule,\n parser: mockParser,\n data: TEST_MESSAGE,\n appConfig: createAppConfig(\"1.15.0\", false, false),\n derivationPath: \"44'/60'/0'/0/0\",\n },\n }),\n );\n\n expect(provideContextMock).toHaveBeenCalledWith(\n expect.objectContaining({\n input: {\n contextModule: mockContextModule,\n taskArgs: TEST_BUILT_CONTEXT,\n },\n }),\n );\n\n expect(signTypedDataMock).toHaveBeenCalledWith(\n expect.objectContaining({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n },\n }),\n );\n\n resolve();\n },\n });\n }));\n\n it(\"should be successful whlie skipping OpenApp\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n setupAppConfig(\"1.15.0\", false, false);\n\n const deviceAction = new SignTypedDataDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n data: TEST_MESSAGE,\n contextModule: mockContextModule,\n parser: mockParser,\n skipOpenApp: true,\n },\n });\n\n // Mock the dependencies to return some sample data\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n buildContextMock.mockResolvedValueOnce(TEST_BUILT_CONTEXT);\n provideContextMock.mockResolvedValueOnce(\n CommandResultFactory({ data: undefined }),\n );\n signTypedDataMock.mockResolvedValueOnce(\n CommandResultFactory({\n data: {\n v: 0x1c,\n r: \"0x8a540510e13b0f2b11a451275716d29e08caad07e89a1c84964782fb5e1ad788\",\n s: \"0x64a0de235b270fbe81e8e40688f4a9f9ad9d283d690552c9331d7773ceafa513\",\n },\n }),\n );\n\n // Expected intermediate values for the following state sequence:\n // Initial -> BuildContext -> ProvideContext -> SignTypedData\n const expectedStates: Array<SignTypedDataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.GET_APP_CONFIG,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.BUILD_CONTEXT,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.SignTypedData,\n step: SignTypedDataDAStateStep.PROVIDE_CONTEXT,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.SignTypedData,\n step: SignTypedDataDAStateStep.SIGN_TYPED_DATA,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n output: {\n v: 0x1c,\n r: \"0x8a540510e13b0f2b11a451275716d29e08caad07e89a1c84964782fb5e1ad788\",\n s: \"0x64a0de235b270fbe81e8e40688f4a9f9ad9d283d690552c9331d7773ceafa513\",\n },\n status: DeviceActionStatus.Completed,\n },\n ];\n\n testDeviceActionStates(deviceAction, expectedStates, apiMock, {\n onError: reject,\n onDone: resolve,\n });\n }));\n\n it(\"should fallback to legacy signing if the new one fails\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n setupAppConfig(\"1.15.0\", false, false);\n\n const deviceAction = new SignTypedDataDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n data: TEST_MESSAGE,\n contextModule: mockContextModule,\n parser: mockParser,\n skipOpenApp: false,\n },\n });\n\n // Mock the providing error\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n buildContextMock.mockResolvedValueOnce(TEST_BUILT_CONTEXT);\n provideContextMock.mockResolvedValueOnce(\n CommandResultFactory({\n error: EthAppCommandErrorFactory({\n errorCode: \"6a80\",\n message: \"\",\n }),\n }),\n );\n signTypedDataLegacyMock.mockResolvedValueOnce(\n CommandResultFactory({\n data: {\n v: 0x1c,\n r: \"0x8a540510e13b0f2b11a451275716d29e08caad07e89a1c84964782fb5e1ad788\",\n s: \"0x64a0de235b270fbe81e8e40688f4a9f9ad9d283d690552c9331d7773ceafa513\",\n },\n }),\n );\n\n const expectedStates: Array<SignTypedDataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.GET_APP_CONFIG,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.BUILD_CONTEXT,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.SignTypedData,\n step: SignTypedDataDAStateStep.PROVIDE_CONTEXT,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.SignTypedData,\n step: SignTypedDataDAStateStep.SIGN_TYPED_DATA_LEGACY,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n output: {\n v: 0x1c,\n r: \"0x8a540510e13b0f2b11a451275716d29e08caad07e89a1c84964782fb5e1ad788\",\n s: \"0x64a0de235b270fbe81e8e40688f4a9f9ad9d283d690552c9331d7773ceafa513\",\n },\n status: DeviceActionStatus.Completed,\n },\n ];\n\n testDeviceActionStates(deviceAction, expectedStates, apiMock, {\n onError: reject,\n onDone: resolve,\n });\n }));\n\n it(\"should fallback to legacy signing BuildContext fails\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n setupAppConfig(\"1.15.0\", false, false);\n\n const deviceAction = new SignTypedDataDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n data: TEST_MESSAGE,\n contextModule: mockContextModule,\n parser: mockParser,\n skipOpenApp: false,\n },\n });\n\n // Mock the providing error\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n buildContextMock.mockRejectedValueOnce(new UnknownDAError(\"Error\"));\n signTypedDataLegacyMock.mockResolvedValueOnce(\n CommandResultFactory({\n data: {\n v: 0x1c,\n r: \"0x8a540510e13b0f2b11a451275716d29e08caad07e89a1c84964782fb5e1ad788\",\n s: \"0x64a0de235b270fbe81e8e40688f4a9f9ad9d283d690552c9331d7773ceafa513\",\n },\n }),\n );\n\n const expectedStates: Array<SignTypedDataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.GET_APP_CONFIG,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.BUILD_CONTEXT,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.SignTypedData,\n step: SignTypedDataDAStateStep.SIGN_TYPED_DATA_LEGACY,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n output: {\n v: 0x1c,\n r: \"0x8a540510e13b0f2b11a451275716d29e08caad07e89a1c84964782fb5e1ad788\",\n s: \"0x64a0de235b270fbe81e8e40688f4a9f9ad9d283d690552c9331d7773ceafa513\",\n },\n status: DeviceActionStatus.Completed,\n },\n ];\n\n testDeviceActionStates(deviceAction, expectedStates, apiMock, {\n onError: reject,\n onDone: resolve,\n });\n }));\n\n it(\"should not fallback to legacy signing if rejected by the user during streaming\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n setupAppConfig(\"1.15.0\", false, false);\n\n const deviceAction = new SignTypedDataDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n data: TEST_MESSAGE,\n contextModule: mockContextModule,\n parser: mockParser,\n skipOpenApp: false,\n },\n });\n\n // Mock the providing error\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n buildContextMock.mockResolvedValueOnce(TEST_BUILT_CONTEXT);\n provideContextMock.mockResolvedValueOnce(\n CommandResultFactory({\n error: EthAppCommandErrorFactory({\n errorCode: \"6985\",\n message: \"\",\n }),\n }),\n );\n signTypedDataLegacyMock.mockResolvedValueOnce(\n CommandResultFactory({\n data: {\n v: 0x1c,\n r: \"0x8a540510e13b0f2b11a451275716d29e08caad07e89a1c84964782fb5e1ad788\",\n s: \"0x64a0de235b270fbe81e8e40688f4a9f9ad9d283d690552c9331d7773ceafa513\",\n },\n }),\n );\n\n const expectedStates: Array<SignTypedDataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.GET_APP_CONFIG,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.BUILD_CONTEXT,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.SignTypedData,\n step: SignTypedDataDAStateStep.PROVIDE_CONTEXT,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n error: EthAppCommandErrorFactory({\n errorCode: \"6985\",\n message: \"\",\n }),\n status: DeviceActionStatus.Error,\n },\n ];\n\n testDeviceActionStates(deviceAction, expectedStates, apiMock, {\n onError: reject,\n onDone: resolve,\n });\n }));\n });\n\n describe(\"Web3Checks\", () => {\n it(\"should call external dependencies with web3Checks enabled and supported\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n setupAppConfig(\"1.16.0\", true, true);\n\n const deviceAction = new SignTypedDataDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n data: TEST_MESSAGE,\n contextModule: mockContextModule,\n parser: mockParser,\n skipOpenApp: false,\n },\n });\n\n // Mock the dependencies to return some sample data\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n buildContextMock.mockRejectedValueOnce(\n new InvalidStatusWordError(\"buildContext error\"),\n );\n signTypedDataLegacyMock.mockRejectedValueOnce(\n new InvalidStatusWordError(\"signTypedDataLegacy error\"),\n );\n\n // Expected intermediate values for the following state sequence:\n // Initial -> OpenApp -> GetAppConfiguration -> BuildContext\n const expectedStates: Array<SignTypedDataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.GET_APP_CONFIG,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.BUILD_CONTEXT,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.SignTypedData,\n step: SignTypedDataDAStateStep.SIGN_TYPED_DATA_LEGACY,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n error: new InvalidStatusWordError(\"signTypedDataLegacy error\"),\n status: DeviceActionStatus.Error,\n },\n ];\n\n testDeviceActionStates(deviceAction, expectedStates, apiMock, {\n onError: reject,\n onDone: () => {\n // Verify mocks calls parameters\n expect(getAppConfigMock).toHaveBeenCalled();\n expect(buildContextMock).toHaveBeenCalledWith(\n expect.objectContaining({\n input: {\n contextModule: mockContextModule,\n parser: mockParser,\n data: TEST_MESSAGE,\n appConfig: createAppConfig(\"1.16.0\", true, true),\n derivationPath: \"44'/60'/0'/0/0\",\n },\n }),\n );\n resolve();\n },\n });\n }));\n\n it(\"should call external dependencies with web3Checks supported but disabled\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n setupAppConfig(\"1.16.0\", false, true);\n\n const deviceAction = new SignTypedDataDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n data: TEST_MESSAGE,\n contextModule: mockContextModule,\n parser: mockParser,\n skipOpenApp: false,\n },\n });\n\n // Mock the dependencies to return some sample data\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n buildContextMock.mockRejectedValueOnce(\n new InvalidStatusWordError(\"buildContext error\"),\n );\n signTypedDataLegacyMock.mockRejectedValueOnce(\n new InvalidStatusWordError(\"signTypedDataLegacy error\"),\n );\n\n // Expected intermediate values for the following state sequence:\n // Initial -> OpenApp -> GetAppConfiguration -> BuildContext\n const expectedStates: Array<SignTypedDataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.GET_APP_CONFIG,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.BUILD_CONTEXT,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.SignTypedData,\n step: SignTypedDataDAStateStep.SIGN_TYPED_DATA_LEGACY,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n error: new InvalidStatusWordError(\"signTypedDataLegacy error\"),\n status: DeviceActionStatus.Error,\n },\n ];\n\n testDeviceActionStates(deviceAction, expectedStates, apiMock, {\n onError: reject,\n onDone: () => {\n // Verify mocks calls parameters\n expect(getAppConfigMock).toHaveBeenCalled();\n expect(buildContextMock).toHaveBeenCalledWith(\n expect.objectContaining({\n input: {\n contextModule: mockContextModule,\n parser: mockParser,\n data: TEST_MESSAGE,\n appConfig: createAppConfig(\"1.16.0\", false, true),\n derivationPath: \"44'/60'/0'/0/0\",\n },\n }),\n );\n resolve();\n },\n });\n }));\n\n it(\"should call external dependencies with web3Checks opt-in, then enabled\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n setupAppConfig(\"1.16.0\", false, false);\n\n const deviceAction = new SignTypedDataDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n data: TEST_MESSAGE,\n contextModule: mockContextModule,\n parser: mockParser,\n skipOpenApp: false,\n },\n });\n\n // Mock the dependencies to return some sample data\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n web3CheckOptInMock.mockResolvedValueOnce(\n CommandResultFactory({ data: { enabled: true } }),\n );\n buildContextMock.mockRejectedValueOnce(\n new InvalidStatusWordError(\"buildContext error\"),\n );\n signTypedDataLegacyMock.mockRejectedValueOnce(\n new InvalidStatusWordError(\"signTypedDataLegacy error\"),\n );\n\n // Expected intermediate values for the following state sequence:\n // Initial -> OpenApp -> GetAppConfiguration -> Web3ChecksOptIn -> BuildContext\n const expectedStates: Array<SignTypedDataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.GET_APP_CONFIG,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.Web3ChecksOptIn,\n step: SignTypedDataDAStateStep.WEB3_CHECKS_OPT_IN,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.WEB3_CHECKS_OPT_IN_RESULT,\n result: true,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.BUILD_CONTEXT,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.SignTypedData,\n step: SignTypedDataDAStateStep.SIGN_TYPED_DATA_LEGACY,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n error: new InvalidStatusWordError(\"signTypedDataLegacy error\"),\n status: DeviceActionStatus.Error,\n },\n ];\n\n testDeviceActionStates(deviceAction, expectedStates, apiMock, {\n onError: reject,\n onDone: () => {\n // Verify mocks calls parameters\n expect(getAppConfigMock).toHaveBeenCalled();\n expect(web3CheckOptInMock).toHaveBeenCalled();\n expect(buildContextMock).toHaveBeenCalledWith(\n expect.objectContaining({\n input: {\n contextModule: mockContextModule,\n parser: mockParser,\n data: TEST_MESSAGE,\n appConfig: createAppConfig(\"1.16.0\", true, false),\n derivationPath: \"44'/60'/0'/0/0\",\n },\n }),\n );\n resolve();\n },\n });\n }));\n\n it(\"should call external dependencies with web3Checks opt-in, then disabled\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n setupAppConfig(\"1.16.0\", false, false);\n\n const deviceAction = new SignTypedDataDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n data: TEST_MESSAGE,\n contextModule: mockContextModule,\n parser: mockParser,\n skipOpenApp: false,\n },\n });\n\n // Mock the dependencies to return some sample data\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n web3CheckOptInMock.mockResolvedValueOnce(\n CommandResultFactory({ data: { enabled: false } }),\n );\n buildContextMock.mockRejectedValueOnce(\n new InvalidStatusWordError(\"buildContext error\"),\n );\n signTypedDataLegacyMock.mockRejectedValueOnce(\n new InvalidStatusWordError(\"signTypedDataLegacy error\"),\n );\n\n // Expected intermediate values for the following state sequence:\n // Initial -> OpenApp -> GetAppConfiguration -> Web3ChecksOptIn -> BuildContext\n const expectedStates: Array<SignTypedDataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.GET_APP_CONFIG,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.Web3ChecksOptIn,\n step: SignTypedDataDAStateStep.WEB3_CHECKS_OPT_IN,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.WEB3_CHECKS_OPT_IN_RESULT,\n result: false,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.BUILD_CONTEXT,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.SignTypedData,\n step: SignTypedDataDAStateStep.SIGN_TYPED_DATA_LEGACY,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n error: new InvalidStatusWordError(\"signTypedDataLegacy error\"),\n status: DeviceActionStatus.Error,\n },\n ];\n\n testDeviceActionStates(deviceAction, expectedStates, apiMock, {\n onError: reject,\n onDone: () => {\n // Verify mocks calls parameters\n expect(getAppConfigMock).toHaveBeenCalled();\n expect(web3CheckOptInMock).toHaveBeenCalled();\n expect(buildContextMock).toHaveBeenCalledWith(\n expect.objectContaining({\n input: {\n contextModule: mockContextModule,\n parser: mockParser,\n data: TEST_MESSAGE,\n appConfig: createAppConfig(\"1.16.0\", false, false),\n derivationPath: \"44'/60'/0'/0/0\",\n },\n }),\n );\n resolve();\n },\n });\n }));\n });\n\n describe(\"error cases\", () => {\n it(\"Error if the open app fails\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock(new UnknownDAError(\"Mocked error\"));\n\n const expectedStates: Array<SignTypedDataDAState> = [\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n },\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n },\n {\n status: DeviceActionStatus.Error,\n error: new UnknownDAError(\"Mocked error\"),\n },\n ];\n\n const deviceAction = new SignTypedDataDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n data: TEST_MESSAGE,\n contextModule: mockContextModule,\n parser: mockParser,\n skipOpenApp: false,\n },\n });\n\n testDeviceActionStates(deviceAction, expectedStates, apiMock, {\n onError: reject,\n onDone: resolve,\n });\n }));\n\n it(\"Error thrown while providing context\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n setupAppConfig(\"1.15.0\", false, false);\n\n const deviceAction = new SignTypedDataDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n data: TEST_MESSAGE,\n contextModule: mockContextModule,\n parser: mockParser,\n skipOpenApp: false,\n },\n });\n\n // Mock the providing error\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n buildContextMock.mockResolvedValueOnce(TEST_BUILT_CONTEXT);\n provideContextMock.mockRejectedValueOnce(new UnknownDAError(\"Error\"));\n\n const expectedStates: Array<SignTypedDataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.GET_APP_CONFIG,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.BUILD_CONTEXT,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.SignTypedData,\n step: SignTypedDataDAStateStep.PROVIDE_CONTEXT,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n error: new UnknownDAError(\"Error\"),\n status: DeviceActionStatus.Error,\n },\n ];\n\n testDeviceActionStates(deviceAction, expectedStates, apiMock, {\n onError: reject,\n onDone: resolve,\n });\n }));\n\n it(\"Error while signing\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n setupAppConfig(\"1.15.0\", false, false);\n\n const deviceAction = new SignTypedDataDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n data: TEST_MESSAGE,\n contextModule: mockContextModule,\n parser: mockParser,\n skipOpenApp: false,\n },\n });\n\n // Mock signing error\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n buildContextMock.mockResolvedValueOnce(TEST_BUILT_CONTEXT);\n provideContextMock.mockResolvedValueOnce(\n CommandResultFactory({ data: undefined }),\n );\n signTypedDataMock.mockResolvedValueOnce(\n CommandResultFactory({\n error: new UnknownDeviceExchangeError(\n \"Error while signing the typed data\",\n ),\n }),\n );\n\n const expectedStates: Array<SignTypedDataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n step: SignTypedDataDAStateStep.OPEN_APP,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.GET_APP_CONFIG,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: SignTypedDataDAStateStep.BUILD_CONTEXT,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.SignTypedData,\n step: SignTypedDataDAStateStep.PROVIDE_CONTEXT,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.SignTypedData,\n step: SignTypedDataDAStateStep.SIGN_TYPED_DATA,\n },\n status: DeviceActionStatus.Pending,\n },\n {\n error: new UnknownDeviceExchangeError(\n \"Error while signing the typed data\",\n ),\n status: DeviceActionStatus.Error,\n },\n ];\n\n testDeviceActionStates(deviceAction, expectedStates, apiMock, {\n onError: reject,\n onDone: resolve,\n });\n }));\n });\n});\n"],
5
+ "mappings": "aAEA,IAAAA,EAUO,2CACPC,EAA8B,qBAG9BC,EAAyC,0DACzCC,EAA0C,2DAC1CC,EAAgD,6EAChDC,EAAmC,gFACnCC,EAAuC,oFAEvCC,EAIO,4CAGPC,EAA0C,uCAE1C,GAAG,KAAK,kCAAmC,MAAOC,IAGzC,CACL,GAFA,MAAMA,EAAiE,EAGvE,oBAAqB,GAAG,GAAG,KAAO,CAChC,iBAAkB,GAAG,GAAG,CAC1B,EAAE,CACJ,EACD,EAED,SAAS,4BAA6B,IAAM,CAC1C,MAAMC,EAAe,CACnB,OAAQ,CAAC,EACT,QAAS,CAAC,EACV,YAAa,cACb,MAAO,CAAC,CACV,EACMC,EAAmD,CACvD,UAAW,KACX,MAAO,C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AAmB,CACjB,wBAAyB,0BAAwB,eACjD,KAAM,2BAAyB,QACjC,EACA,OAAQ,qBAAmB,OAC7B,EACA,CACE,kBAAmB,CACjB,wBAAyB,0BAAwB,KACjD,KAAM,2BAAyB,cACjC,EACA,OAAQ,qBAAmB,OAC7B,EACA,CACE,kBAAmB,CACjB,wBAAyB,0BAAwB,KACjD,KAAM,2BAAyB,aACjC,EACA,OAAQ,qBAAmB,OAC7B,EACA,CACE,kBAAmB,CACjB,wBAAyB,0BAAwB,cACjD,KAAM,2BAAyB,eACjC,EACA,OAAQ,qBAAmB,OAC7B,EACA,CACE,kBAAmB,CACjB,wBAAyB,0BAAwB,cACjD,KAAM,2BAAyB,eACjC,EACA,OAAQ,qBAAmB,OAC7B,EACA,CACE,MAAO,IAAI,6BACT,oCACF,EACA,OAAQ,qBAAmB,KAC7B,CACF,KAEA,0BAAuBD,EAAcC,EAAgBhB,EAAS,CAC5D,QAASc,EACT,OAAQD,CACV,CAAC,CACH,CAAC,CAAC,CACN,CAAC,CACH,CAAC",
6
6
  "names": ["import_device_management_kit", "import_purify_ts", "import_SignTypedDataDeviceActionTypes", "import_ethAppErrors", "import_makeInternalApi", "import_setupOpenAppDAMock", "import_testDeviceActionStates", "import_Types", "import_SignTypedDataDeviceAction", "importOriginal", "TEST_MESSAGE", "TEST_BUILT_CONTEXT", "mockParser", "mockContextModule", "apiMock", "getAppConfigMock", "web3CheckOptInMock", "buildContextMock", "provideContextMock", "signTypedDataMock", "signTypedDataLegacyMock", "extractDependenciesMock", "createAppConfig", "version", "web3ChecksEnabled", "web3ChecksOptIn", "setupAppConfig", "resolve", "reject", "deviceAction", "expectedStates"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var y=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var v=(s,e)=>{for(var n in e)y(s,n,{get:e[n],enumerable:!0})},b=(s,e,n,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of R(e))!_.call(s,i)&&i!==n&&y(s,i,{get:()=>e[i],enumerable:!(a=O(e,i))||a.enumerable});return s};var M=s=>b(y({},"__esModule",{value:!0}),s);var B={};v(B,{BuildBaseContexts:()=>k});module.exports=M(B);var o=require("@ledgerhq/context-module"),c=require("@ledgerhq/device-management-kit"),u=require("../../../api/model/ClearSigningType"),A=require("../../app-binder/command/GetChallengeCommand"),I=require("../../app-binder/task/GetWeb3CheckTask"),N=require("../../shared/utils/ApplicationChecker");class k{constructor(e,n,a=(i,C)=>new I.GetWeb3CheckTask(i,C)){this._api=e;this._args=n;this.getWeb3ChecksFactory=a}async run(){const{contextModule:e,options:n,appConfig:a,derivationPath:i,transaction:C,subset:x}=this._args,d=this._api.getDeviceSessionState();let r=[],f=[],m=u.ClearSigningType.BASIC,l=null;C&&a.web3ChecksEnabled&&(l=(await this.getWeb3ChecksFactory(this._api,{contextModule:e,derivationPath:i,subset:x,transaction:C}).run()).web3Check);let T;if(d.deviceModelId!==c.DeviceModelId.NANO_S){const t=await this._api.sendCommand(new A.GetChallengeCommand);(0,c.isSuccessCommandResult)(t)&&(T=t.data.challenge)}const h=await e.getContexts({challenge:T,domain:n.domain,deviceModelId:d.deviceModelId,...x}),p=h.filter(t=>t.type!==o.ClearSignContextType.ERROR&&t.type!==o.ClearSignContextType.ENUM),E=h.filter(t=>t.type===o.ClearSignContextType.ENUM),S=p.find(t=>t.type===o.ClearSignContextType.TRANSACTION_INFO);if(!this.supportsGenericParser(d,a)||S===void 0)r=p.filter(t=>t.type!==o.ClearSignContextType.TRANSACTION_INFO&&t.type!==o.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION),l&&(r=[l,...r]);else if(S.certificate){const t=p.filter(g=>g.type===o.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION);r=[...p.filter(g=>g.type===o.ClearSignContextType.PROXY_DELEGATE_CALL),S,...t,...l?[l]:[]],f=[...E],m=u.ClearSigningType.EIP7730}return{clearSignContexts:r,clearSignContextsOptional:f,clearSigningType:m}}supportsGenericParser(e,n){return new N.ApplicationChecker(e,n).withMinVersionExclusive("1.14.0").excludeDeviceModel(c.DeviceModelId.NANO_S).check()}}0&&(module.exports={BuildBaseContexts});
1
+ "use strict";var y=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var M=(s,e)=>{for(var i in e)y(s,i,{get:e[i],enumerable:!0})},k=(s,e,i,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of R(e))!v.call(s,o)&&o!==i&&y(s,o,{get:()=>e[o],enumerable:!(a=_(e,o))||a.enumerable});return s};var b=s=>k(y({},"__esModule",{value:!0}),s);var B={};M(B,{BuildBaseContexts:()=>w});module.exports=b(B);var n=require("@ledgerhq/context-module"),p=require("@ledgerhq/device-management-kit"),u=require("../../../api/model/ClearSigningType"),I=require("../../app-binder/command/GetChallengeCommand"),h=require("../../app-binder/task/GetWeb3CheckTask"),A=require("../../shared/utils/ApplicationChecker");class w{constructor(e,i,a=(o,d)=>new h.GetWeb3CheckTask(o,d)){this._api=e;this._args=i;this.getWeb3ChecksFactory=a}async run(){const{contextModule:e,options:i,appConfig:a,derivationPath:o,transaction:d,subset:x}=this._args,S=this._api.getDeviceSessionState();let l=[],f=[],m=u.ClearSigningType.BASIC,c=null;d&&a.web3ChecksEnabled&&(c=(await this.getWeb3ChecksFactory(this._api,{contextModule:e,derivationPath:o,subset:x,transaction:d}).run()).web3Check);let T;if(S.deviceModelId!==p.DeviceModelId.NANO_S){const t=await this._api.sendCommand(new I.GetChallengeCommand);(0,p.isSuccessCommandResult)(t)&&(T=t.data.challenge)}const N=await e.getContexts({challenge:T,domain:i.domain,deviceModelId:S.deviceModelId,...x}),C=N.filter(t=>t.type!==n.ClearSignContextType.ERROR&&t.type!==n.ClearSignContextType.ENUM),E=N.filter(t=>t.type===n.ClearSignContextType.ENUM),g=C.find(t=>t.type===n.ClearSignContextType.TRANSACTION_INFO);if(!this.supportsGenericParser(S,a)||g===void 0)l=C.filter(t=>t.type!==n.ClearSignContextType.TRANSACTION_INFO&&t.type!==n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION),c&&(l=[c,...l]);else if(g.certificate){const t=C.filter(r=>r.type===n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION),O=C.filter(r=>r.type===n.ClearSignContextType.PROXY_DELEGATE_CALL);l=[...C.filter(r=>r.type===n.ClearSignContextType.DYNAMIC_NETWORK||r.type===n.ClearSignContextType.DYNAMIC_NETWORK_ICON),...O,g,...t,...c?[c]:[]],f=[...E],m=u.ClearSigningType.EIP7730}return{clearSignContexts:l,clearSignContextsOptional:f,clearSigningType:m}}supportsGenericParser(e,i){return new A.ApplicationChecker(e,i).withMinVersionExclusive("1.14.0").excludeDeviceModel(p.DeviceModelId.NANO_S).check()}}0&&(module.exports={BuildBaseContexts});
2
2
  //# sourceMappingURL=BuildBaseContexts.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/internal/app-binder/task/BuildBaseContexts.ts"],
4
- "sourcesContent": ["import {\n type ClearSignContext,\n type ClearSignContextSuccess,\n type ClearSignContextSuccessType,\n ClearSignContextType,\n type ContextModule,\n type TransactionSubset,\n} from \"@ledgerhq/context-module\";\nimport {\n DeviceModelId,\n type DeviceSessionState,\n type InternalApi,\n isSuccessCommandResult,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { type GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\nimport { ClearSigningType } from \"@api/model/ClearSigningType\";\nimport { type TransactionOptions } from \"@api/model/TransactionOptions\";\nimport { GetChallengeCommand } from \"@internal/app-binder/command/GetChallengeCommand\";\nimport {\n GetWeb3CheckTask,\n type GetWeb3CheckTaskArgs,\n} from \"@internal/app-binder/task/GetWeb3CheckTask\";\nimport { ApplicationChecker } from \"@internal/shared/utils/ApplicationChecker\";\n\nexport type BuildBaseContextsResult = {\n readonly clearSignContexts: ClearSignContextSuccess[];\n readonly clearSignContextsOptional: ClearSignContextSuccess[];\n readonly clearSigningType: ClearSigningType;\n};\n\nexport type BuildBaseContextsArgs = {\n readonly contextModule: ContextModule;\n readonly options: TransactionOptions;\n readonly appConfig: GetConfigCommandResponse;\n readonly derivationPath: string;\n readonly subset: TransactionSubset;\n readonly transaction?: Uint8Array;\n};\n\n/**\n * Builds the base contexts for a transaction\n * @param api - The internal API\n * @param args - The arguments for the build\n * @param getWeb3ChecksFactory - The factory for the web3 checks\n *\n * returns the base contexts for a transaction, without subcontexts or nested call data contexts\n */\nexport class BuildBaseContexts {\n constructor(\n private readonly _api: InternalApi,\n private readonly _args: BuildBaseContextsArgs,\n private readonly getWeb3ChecksFactory = (\n api: InternalApi,\n args: GetWeb3CheckTaskArgs,\n ) => new GetWeb3CheckTask(api, args),\n ) {}\n\n async run(): Promise<BuildBaseContextsResult> {\n const {\n contextModule,\n options,\n appConfig,\n derivationPath,\n transaction,\n subset,\n } = this._args;\n const deviceState = this._api.getDeviceSessionState();\n let filteredContexts: ClearSignContextSuccess[] = [];\n let filteredContextOptional: ClearSignContextSuccess[] = [];\n let clearSigningType: ClearSigningType = ClearSigningType.BASIC;\n let web3Check: ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK> | null =\n null;\n\n // Run the web3checks if needed\n if (transaction) {\n if (appConfig.web3ChecksEnabled) {\n web3Check = (\n await this.getWeb3ChecksFactory(this._api, {\n contextModule,\n derivationPath,\n subset,\n transaction,\n }).run()\n ).web3Check;\n }\n }\n\n // Get challenge (not supported on Nano S)\n let challenge: string | undefined = undefined;\n if (deviceState.deviceModelId !== DeviceModelId.NANO_S) {\n const challengeRes = await this._api.sendCommand(\n new GetChallengeCommand(),\n );\n if (isSuccessCommandResult(challengeRes)) {\n challenge = challengeRes.data.challenge;\n }\n }\n\n // Get the clear sign contexts\n const clearSignContexts: ClearSignContext[] =\n await contextModule.getContexts({\n challenge: challenge,\n domain: options.domain,\n deviceModelId: deviceState.deviceModelId,\n ...subset,\n });\n\n // NOTE: we need to filter out the ENUM and ERROR types\n // ENUM are handled differently\n // ERROR are not handled at all for now\n const clearSignContextsSuccess: ClearSignContextSuccess<\n Exclude<ClearSignContextSuccessType, ClearSignContextType.ENUM>\n >[] = clearSignContexts.filter(\n (context) =>\n context.type !== ClearSignContextType.ERROR &&\n context.type !== ClearSignContextType.ENUM,\n );\n\n // Retrieve all ENUM contexts\n const transactionEnums: ClearSignContextSuccess<ClearSignContextType.ENUM>[] =\n clearSignContexts.filter(\n (context) => context.type === ClearSignContextType.ENUM,\n );\n\n const transactionInfo = clearSignContextsSuccess.find(\n (ctx) => ctx.type === ClearSignContextType.TRANSACTION_INFO,\n );\n\n // If the device does not support the generic parser,\n // we need to filter out the transaction info and transaction field description\n // as they are not supported by the device\n if (\n !this.supportsGenericParser(deviceState, appConfig) ||\n transactionInfo === undefined\n ) {\n filteredContexts = clearSignContextsSuccess.filter(\n (ctx) =>\n ctx.type !== ClearSignContextType.TRANSACTION_INFO &&\n ctx.type !== ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n );\n\n // If the device supports the web3 check, we need to add it to the list of contexts\n if (web3Check) {\n filteredContexts = [web3Check, ...filteredContexts];\n }\n } else if (transactionInfo.certificate) {\n const transactionFields = clearSignContextsSuccess.filter(\n (ctx) =>\n ctx.type === ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n );\n const proxyContexts = clearSignContextsSuccess.filter(\n (ctx) => ctx.type === ClearSignContextType.PROXY_DELEGATE_CALL,\n );\n\n filteredContexts = [\n ...proxyContexts,\n transactionInfo,\n ...transactionFields,\n ...(web3Check ? [web3Check] : []),\n ];\n filteredContextOptional = [...transactionEnums];\n clearSigningType = ClearSigningType.EIP7730;\n }\n\n return {\n clearSignContexts: filteredContexts,\n clearSignContextsOptional: filteredContextOptional,\n clearSigningType,\n };\n }\n\n private supportsGenericParser(\n deviceState: DeviceSessionState,\n appConfig: GetConfigCommandResponse,\n ): boolean {\n return new ApplicationChecker(deviceState, appConfig)\n .withMinVersionExclusive(\"1.14.0\")\n .excludeDeviceModel(DeviceModelId.NANO_S)\n .check();\n }\n}\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAOO,oCACPC,EAKO,2CAGPC,EAAiC,uCAEjCC,EAAoC,4DACpCC,EAGO,sDACPC,EAAmC,qDAyB5B,MAAMP,CAAkB,CAC7B,YACmBQ,EACAC,EACAC,EAAuB,CACtCC,EACAC,IACG,IAAI,mBAAiBD,EAAKC,CAAI,EACnC,CANiB,UAAAJ,EACA,WAAAC,EACA,0BAAAC,CAIhB,CAEH,MAAM,KAAwC,CAC5C,KAAM,CACJ,cAAAG,EACA,QAAAC,EACA,UAAAC,EACA,eAAAC,EACA,YAAAC,EACA,OAAAC,CACF,EAAI,KAAK,MACHC,EAAc,KAAK,KAAK,sBAAsB,EACpD,IAAIC,EAA8C,CAAC,EAC/CC,EAAqD,CAAC,EACtDC,EAAqC,mBAAiB,MACtDC,EACF,KAGEN,GACEF,EAAU,oBACZQ,GACE,MAAM,KAAK,qBAAqB,KAAK,KAAM,CACzC,cAAAV,EACA,eAAAG,EACA,OAAAE,EACA,YAAAD,CACF,CAAC,EAAE,IAAI,GACP,WAKN,IAAIO,EACJ,GAAIL,EAAY,gBAAkB,gBAAc,OAAQ,CACtD,MAAMM,EAAe,MAAM,KAAK,KAAK,YACnC,IAAI,qBACN,KACI,0BAAuBA,CAAY,IACrCD,EAAYC,EAAa,KAAK,UAElC,CAGA,MAAMC,EACJ,MAAMb,EAAc,YAAY,CAC9B,UAAWW,EACX,OAAQV,EAAQ,OAChB,cAAeK,EAAY,cAC3B,GAAGD,CACL,CAAC,EAKGS,EAEAD,EAAkB,OACrBE,GACCA,EAAQ,OAAS,uBAAqB,OACtCA,EAAQ,OAAS,uBAAqB,IAC1C,EAGMC,EACJH,EAAkB,OACfE,GAAYA,EAAQ,OAAS,uBAAqB,IACrD,EAEIE,EAAkBH,EAAyB,KAC9CI,GAAQA,EAAI,OAAS,uBAAqB,gBAC7C,EAKA,GACE,CAAC,KAAK,sBAAsBZ,EAAaJ,CAAS,GAClDe,IAAoB,OAEpBV,EAAmBO,EAAyB,OACzCI,GACCA,EAAI,OAAS,uBAAqB,kBAClCA,EAAI,OAAS,uBAAqB,6BACtC,EAGIR,IACFH,EAAmB,CAACG,EAAW,GAAGH,CAAgB,WAE3CU,EAAgB,YAAa,CACtC,MAAME,EAAoBL,EAAyB,OAChDI,GACCA,EAAI,OAAS,uBAAqB,6BACtC,EAKAX,EAAmB,CACjB,GALoBO,EAAyB,OAC5CI,GAAQA,EAAI,OAAS,uBAAqB,mBAC7C,EAIED,EACA,GAAGE,EACH,GAAIT,EAAY,CAACA,CAAS,EAAI,CAAC,CACjC,EACAF,EAA0B,CAAC,GAAGQ,CAAgB,EAC9CP,EAAmB,mBAAiB,OACtC,CAEA,MAAO,CACL,kBAAmBF,EACnB,0BAA2BC,EAC3B,iBAAAC,CACF,CACF,CAEQ,sBACNH,EACAJ,EACS,CACT,OAAO,IAAI,qBAAmBI,EAAaJ,CAAS,EACjD,wBAAwB,QAAQ,EAChC,mBAAmB,gBAAc,MAAM,EACvC,MAAM,CACX,CACF",
6
- "names": ["BuildBaseContexts_exports", "__export", "BuildBaseContexts", "__toCommonJS", "import_context_module", "import_device_management_kit", "import_ClearSigningType", "import_GetChallengeCommand", "import_GetWeb3CheckTask", "import_ApplicationChecker", "_api", "_args", "getWeb3ChecksFactory", "api", "args", "contextModule", "options", "appConfig", "derivationPath", "transaction", "subset", "deviceState", "filteredContexts", "filteredContextOptional", "clearSigningType", "web3Check", "challenge", "challengeRes", "clearSignContexts", "clearSignContextsSuccess", "context", "transactionEnums", "transactionInfo", "ctx", "transactionFields"]
4
+ "sourcesContent": ["import {\n type ClearSignContext,\n type ClearSignContextSuccess,\n type ClearSignContextSuccessType,\n ClearSignContextType,\n type ContextModule,\n type TransactionSubset,\n} from \"@ledgerhq/context-module\";\nimport {\n DeviceModelId,\n type DeviceSessionState,\n type InternalApi,\n isSuccessCommandResult,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { type GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\nimport { ClearSigningType } from \"@api/model/ClearSigningType\";\nimport { type TransactionOptions } from \"@api/model/TransactionOptions\";\nimport { GetChallengeCommand } from \"@internal/app-binder/command/GetChallengeCommand\";\nimport {\n GetWeb3CheckTask,\n type GetWeb3CheckTaskArgs,\n} from \"@internal/app-binder/task/GetWeb3CheckTask\";\nimport { ApplicationChecker } from \"@internal/shared/utils/ApplicationChecker\";\n\nexport type BuildBaseContextsResult = {\n readonly clearSignContexts: ClearSignContextSuccess[];\n readonly clearSignContextsOptional: ClearSignContextSuccess[];\n readonly clearSigningType: ClearSigningType;\n};\n\nexport type BuildBaseContextsArgs = {\n readonly contextModule: ContextModule;\n readonly options: TransactionOptions;\n readonly appConfig: GetConfigCommandResponse;\n readonly derivationPath: string;\n readonly subset: TransactionSubset;\n readonly transaction?: Uint8Array;\n};\n\n/**\n * Builds the base contexts for a transaction\n * @param api - The internal API\n * @param args - The arguments for the build\n * @param getWeb3ChecksFactory - The factory for the web3 checks\n *\n * returns the base contexts for a transaction, without subcontexts or nested call data contexts\n */\nexport class BuildBaseContexts {\n constructor(\n private readonly _api: InternalApi,\n private readonly _args: BuildBaseContextsArgs,\n private readonly getWeb3ChecksFactory = (\n api: InternalApi,\n args: GetWeb3CheckTaskArgs,\n ) => new GetWeb3CheckTask(api, args),\n ) {}\n\n async run(): Promise<BuildBaseContextsResult> {\n const {\n contextModule,\n options,\n appConfig,\n derivationPath,\n transaction,\n subset,\n } = this._args;\n const deviceState = this._api.getDeviceSessionState();\n let filteredContexts: ClearSignContextSuccess[] = [];\n let filteredContextOptional: ClearSignContextSuccess[] = [];\n let clearSigningType: ClearSigningType = ClearSigningType.BASIC;\n let web3Check: ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK> | null =\n null;\n\n // Run the web3checks if needed\n if (transaction) {\n if (appConfig.web3ChecksEnabled) {\n web3Check = (\n await this.getWeb3ChecksFactory(this._api, {\n contextModule,\n derivationPath,\n subset,\n transaction,\n }).run()\n ).web3Check;\n }\n }\n\n // Get challenge (not supported on Nano S)\n let challenge: string | undefined = undefined;\n if (deviceState.deviceModelId !== DeviceModelId.NANO_S) {\n const challengeRes = await this._api.sendCommand(\n new GetChallengeCommand(),\n );\n if (isSuccessCommandResult(challengeRes)) {\n challenge = challengeRes.data.challenge;\n }\n }\n\n // Get the clear sign contexts\n const clearSignContexts: ClearSignContext[] =\n await contextModule.getContexts({\n challenge: challenge,\n domain: options.domain,\n deviceModelId: deviceState.deviceModelId,\n ...subset,\n });\n\n // NOTE: we need to filter out the ENUM and ERROR types\n // ENUM are handled differently\n // ERROR are not handled at all for now\n const clearSignContextsSuccess: ClearSignContextSuccess<\n Exclude<ClearSignContextSuccessType, ClearSignContextType.ENUM>\n >[] = clearSignContexts.filter(\n (context) =>\n context.type !== ClearSignContextType.ERROR &&\n context.type !== ClearSignContextType.ENUM,\n );\n\n // Retrieve all ENUM contexts\n const transactionEnums: ClearSignContextSuccess<ClearSignContextType.ENUM>[] =\n clearSignContexts.filter(\n (context) => context.type === ClearSignContextType.ENUM,\n );\n\n const transactionInfo = clearSignContextsSuccess.find(\n (ctx) => ctx.type === ClearSignContextType.TRANSACTION_INFO,\n );\n\n // If the device does not support the generic parser,\n // we need to filter out the transaction info and transaction field description\n // as they are not supported by the device\n if (\n !this.supportsGenericParser(deviceState, appConfig) ||\n transactionInfo === undefined\n ) {\n filteredContexts = clearSignContextsSuccess.filter(\n (ctx) =>\n ctx.type !== ClearSignContextType.TRANSACTION_INFO &&\n ctx.type !== ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n );\n\n // If the device supports the web3 check, we need to add it to the list of contexts\n if (web3Check) {\n filteredContexts = [web3Check, ...filteredContexts];\n }\n } else if (transactionInfo.certificate) {\n const transactionFields = clearSignContextsSuccess.filter(\n (ctx) =>\n ctx.type === ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n );\n const proxyContexts = clearSignContextsSuccess.filter(\n (ctx) => ctx.type === ClearSignContextType.PROXY_DELEGATE_CALL,\n );\n const dynamicNetworkContexts = clearSignContextsSuccess.filter(\n (ctx) =>\n ctx.type === ClearSignContextType.DYNAMIC_NETWORK ||\n ctx.type === ClearSignContextType.DYNAMIC_NETWORK_ICON,\n );\n\n filteredContexts = [\n ...dynamicNetworkContexts,\n ...proxyContexts,\n transactionInfo,\n ...transactionFields,\n ...(web3Check ? [web3Check] : []),\n ];\n filteredContextOptional = [...transactionEnums];\n clearSigningType = ClearSigningType.EIP7730;\n }\n\n return {\n clearSignContexts: filteredContexts,\n clearSignContextsOptional: filteredContextOptional,\n clearSigningType,\n };\n }\n\n private supportsGenericParser(\n deviceState: DeviceSessionState,\n appConfig: GetConfigCommandResponse,\n ): boolean {\n return new ApplicationChecker(deviceState, appConfig)\n .withMinVersionExclusive(\"1.14.0\")\n .excludeDeviceModel(DeviceModelId.NANO_S)\n .check();\n }\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAOO,oCACPC,EAKO,2CAGPC,EAAiC,uCAEjCC,EAAoC,4DACpCC,EAGO,sDACPC,EAAmC,qDAyB5B,MAAMP,CAAkB,CAC7B,YACmBQ,EACAC,EACAC,EAAuB,CACtCC,EACAC,IACG,IAAI,mBAAiBD,EAAKC,CAAI,EACnC,CANiB,UAAAJ,EACA,WAAAC,EACA,0BAAAC,CAIhB,CAEH,MAAM,KAAwC,CAC5C,KAAM,CACJ,cAAAG,EACA,QAAAC,EACA,UAAAC,EACA,eAAAC,EACA,YAAAC,EACA,OAAAC,CACF,EAAI,KAAK,MACHC,EAAc,KAAK,KAAK,sBAAsB,EACpD,IAAIC,EAA8C,CAAC,EAC/CC,EAA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EACAF,EAA0B,CAAC,GAAGQ,CAAgB,EAC9CP,EAAmB,mBAAiB,OACtC,CAEA,MAAO,CACL,kBAAmBF,EACnB,0BAA2BC,EAC3B,iBAAAC,CACF,CACF,CAEQ,sBACNH,EACAJ,EACS,CACT,OAAO,IAAI,qBAAmBI,EAAaJ,CAAS,EACjD,wBAAwB,QAAQ,EAChC,mBAAmB,gBAAc,MAAM,EACvC,MAAM,CACX,CACF",
6
+ "names": ["BuildBaseContexts_exports", "__export", "BuildBaseContexts", "__toCommonJS", "import_context_module", "import_device_management_kit", "import_ClearSigningType", "import_GetChallengeCommand", "import_GetWeb3CheckTask", "import_ApplicationChecker", "_api", "_args", "getWeb3ChecksFactory", "api", "args", "contextModule", "options", "appConfig", "derivationPath", "transaction", "subset", "deviceState", "filteredContexts", "filteredContextOptional", "clearSigningType", "web3Check", "challenge", "challengeRes", "clearSignContexts", "clearSignContextsSuccess", "context", "transactionEnums", "transactionInfo", "ctx", "transactionFields", "proxyContexts"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var n=require("@ledgerhq/context-module"),t=require("@ledgerhq/device-management-kit"),S=require("ethers"),d=require("../../../api/model/ClearSigningType"),y=require("../../app-binder/device-action/__test-utils__/makeInternalApi"),l=require("./BuildBaseContexts"),g=require("./GetWeb3CheckTask");describe("BuildBaseContexts",()=>{const s={getContext:vi.fn(),getContexts:vi.fn(),getTypedDataFilters:vi.fn(),getWeb3Checks:vi.fn(),getSolanaContext:vi.fn()},x={domain:"domain-name.eth"},C=(0,t.hexaStringToBuffer)(S.Transaction.from({chainId:1n,nonce:0,data:"0x"}).unsignedSerialized),r={keyUsageNumber:1,payload:new Uint8Array([1,2,3])};let c;const a=(0,y.makeDeviceActionInternalApiMock)(),i=vi.fn();function u(e){return{blindSigningEnabled:!1,web3ChecksEnabled:e,web3ChecksOptIn:!1,version:"1.13.0"}}beforeEach(()=>{vi.resetAllMocks(),a.sendCommand.mockResolvedValue((0,t.CommandResultFactory)({data:{challenge:"challenge"}})),i.mockReturnValue({run:async()=>Promise.resolve({web3Check:null})}),c={contextModule:s,subset:{chainId:1,to:void 0,data:"0x",selector:"0x"},transaction:C,options:x,appConfig:u(!1),derivationPath:"44'/60'/0'/0/0"}}),it("should init with a default GetWeb3CheckTaskFactory",()=>{const e=new l.BuildBaseContexts(a,c);expect(e.getWeb3ChecksFactory).toBeDefined(),expect(e.getWeb3ChecksFactory(a,{contextModule:c.contextModule,derivationPath:c.derivationPath,subset:c.subset,transaction:c.transaction})).toBeInstanceOf(g.GetWeb3CheckTask)}),it("should build the transaction context without clear sign contexts",async()=>{const e=[],o=[];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new l.BuildBaseContexts(a,{...c,appConfig:u(!0)},i).run();expect(p).toEqual({clearSignContexts:e,clearSignContextsOptional:o,clearSigningType:d.ClearSigningType.BASIC})}),it("should build the transaction context with web3checks",async()=>{const e=[],o=[],p="web3Check";i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:p})}),s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const E=await new l.BuildBaseContexts(a,{...c,appConfig:u(!0)},i).run();expect(E).toEqual({clearSignContexts:[p,...e],clearSignContextsOptional:o,clearSigningType:d.ClearSigningType.BASIC})}),it("should build the transaction context with web3checks and generic-parser clear sign contexts",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}],o="web3Check";i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:o})}),s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new l.BuildBaseContexts(a,{...c,appConfig:u(!0)},i).run();expect(p).toEqual({clearSignContexts:[e[0],e[1],e[3],o],clearSignContextsOptional:[e[2]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should build the transaction context with web3checks and generic-parser clear sign contexts in the correct order",async()=>{const e=[{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:r}],o="web3Check";i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:o})}),s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new l.BuildBaseContexts(a,{...c,appConfig:u(!0)},i).run();expect(p).toEqual({clearSignContexts:[e[3],e[1],e[2],o],clearSignContextsOptional:[e[0]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should build the transaction context with clear sign contexts",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.NFT,payload:"payload-2"}],o="web3Check";i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:o})}),s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new l.BuildBaseContexts(a,c,i).run();expect(p).toEqual({clearSignContexts:e,clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should build the transaction context with generic-parser context",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new l.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0],e[1],e[3]],clearSignContextsOptional:[e[2]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should build the transaction context with proxy delegate call context",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:r},{type:n.ClearSignContextType.PROXY_DELEGATE_CALL,payload:"payload-2"}],o=[];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new l.BuildBaseContexts(a,c,i).run();expect(p).toEqual({clearSignContexts:[e[1],e[0]],clearSignContextsOptional:o,clearSigningType:d.ClearSigningType.EIP7730})}),it("should call the web3checks factory with correct parameters",async()=>{const e=[];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),await new l.BuildBaseContexts(a,{...c,appConfig:u(!0)},i).run(),expect(i).toHaveBeenCalledWith(a,{contextModule:s,derivationPath:"44'/60'/0'/0/0",subset:c.subset,transaction:C})}),it("should call the context module with the correct parameters",async()=>{const e=[];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),await new l.BuildBaseContexts(a,c,i).run(),expect(s.getContexts).toHaveBeenCalledWith({deviceModelId:t.DeviceModelId.FLEX,challenge:"challenge",domain:"domain-name.eth",...c.subset})}),it("should call the context module without challenge for Nano S",async()=>{const e=[];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.NANO_S,isSecureConnectionAllowed:!1}),await new l.BuildBaseContexts(a,c,i).run(),expect(s.getContexts).toHaveBeenCalledWith({deviceModelId:t.DeviceModelId.NANO_S,domain:"domain-name.eth",...c.subset})}),it("should call the context module without context on error",async()=>{const e=[];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),a.sendCommand.mockResolvedValueOnce((0,t.CommandResultFactory)({error:new t.UnknownDeviceExchangeError})),await new l.BuildBaseContexts(a,c,i).run(),expect(s.getContexts).toHaveBeenCalledWith({deviceModelId:t.DeviceModelId.FLEX,challenge:void 0,domain:"domain-name.eth",...c.subset})}),it("should exclude error contexts from the result",async()=>{const e=[{type:n.ClearSignContextType.ERROR,error:new Error("error")},{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.ERROR,error:new Error("error")},{type:n.ClearSignContextType.NFT,payload:"payload-2"}];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new l.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts from the result on old apps",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"transaction_info",certificate:r},{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:n.ClearSignContextType.NFT,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"enum",id:1,value:2,certificate:r}];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new l.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts from the result if no transaction_info was found",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.ENUM,payload:"enum",id:1,value:2},{type:n.ClearSignContextType.NFT,payload:"payload-2"}];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new l.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude legacy contexts from the result for generic-parser transactions",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.EXTERNAL_PLUGIN,payload:"payload-3"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"},{type:n.ClearSignContextType.ENUM,payload:"payload-5",id:1,value:2,certificate:r}];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new l.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[e[4]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should exclude generic-parser contexts with a nano s device",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:n.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:r}];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:t.DeviceModelId.NANO_S,isSecureConnectionAllowed:!1});const o=await new l.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts with an old app version",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:n.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:r}];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new l.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts with a non ready device",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:n.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:r}];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.Connected,deviceStatus:t.DeviceStatus.NOT_CONNECTED,deviceModelId:t.DeviceModelId.FLEX});const o=await new l.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should return no clear sign context if the transaction info certificate is missing",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2}];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.17.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new l.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should not return web3check if the transaction is undefined",async()=>{const e=[];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.17.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),await new l.BuildBaseContexts(a,{...c,transaction:void 0},i).run(),expect(i).not.toHaveBeenCalled()})});
1
+ "use strict";var n=require("@ledgerhq/context-module"),t=require("@ledgerhq/device-management-kit"),S=require("ethers"),d=require("../../../api/model/ClearSigningType"),y=require("../../app-binder/device-action/__test-utils__/makeInternalApi"),s=require("./BuildBaseContexts"),g=require("./GetWeb3CheckTask");describe("BuildBaseContexts",()=>{const l={getFieldContext:vi.fn(),getContexts:vi.fn(),getTypedDataFilters:vi.fn(),getWeb3Checks:vi.fn(),getSolanaContext:vi.fn(),getProxyDelegateCall:vi.fn()},x={domain:"domain-name.eth"},C=(0,t.hexaStringToBuffer)(S.Transaction.from({chainId:1n,nonce:0,data:"0x"}).unsignedSerialized),r={keyUsageNumber:1,payload:new Uint8Array([1,2,3])};let c;const a=(0,y.makeDeviceActionInternalApiMock)(),i=vi.fn();function u(e){return{blindSigningEnabled:!1,web3ChecksEnabled:e,web3ChecksOptIn:!1,version:"1.13.0"}}beforeEach(()=>{vi.resetAllMocks(),a.sendCommand.mockResolvedValue((0,t.CommandResultFactory)({data:{challenge:"challenge"}})),i.mockReturnValue({run:async()=>Promise.resolve({web3Check:null})}),c={contextModule:l,subset:{chainId:1,to:void 0,data:"0x",selector:"0x"},transaction:C,options:x,appConfig:u(!1),derivationPath:"44'/60'/0'/0/0"}}),it("should init with a default GetWeb3CheckTaskFactory",()=>{const e=new s.BuildBaseContexts(a,c);expect(e.getWeb3ChecksFactory).toBeDefined(),expect(e.getWeb3ChecksFactory(a,{contextModule:c.contextModule,derivationPath:c.derivationPath,subset:c.subset,transaction:c.transaction})).toBeInstanceOf(g.GetWeb3CheckTask)}),it("should build the transaction context without clear sign contexts",async()=>{const e=[],o=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new s.BuildBaseContexts(a,{...c,appConfig:u(!0)},i).run();expect(p).toEqual({clearSignContexts:e,clearSignContextsOptional:o,clearSigningType:d.ClearSigningType.BASIC})}),it("should build the transaction context with web3checks",async()=>{const e=[],o=[],p="web3Check";i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:p})}),l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const E=await new s.BuildBaseContexts(a,{...c,appConfig:u(!0)},i).run();expect(E).toEqual({clearSignContexts:[p,...e],clearSignContextsOptional:o,clearSigningType:d.ClearSigningType.BASIC})}),it("should build the transaction context with web3checks and generic-parser clear sign contexts",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}],o="web3Check";i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:o})}),l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new s.BuildBaseContexts(a,{...c,appConfig:u(!0)},i).run();expect(p).toEqual({clearSignContexts:[e[0],e[1],e[3],o],clearSignContextsOptional:[e[2]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should build the transaction context with web3checks and generic-parser clear sign contexts in the correct order",async()=>{const e=[{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:r}],o="web3Check";i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:o})}),l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new s.BuildBaseContexts(a,{...c,appConfig:u(!0)},i).run();expect(p).toEqual({clearSignContexts:[e[3],e[1],e[2],o],clearSignContextsOptional:[e[0]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should build the transaction context with clear sign contexts",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.NFT,payload:"payload-2"}],o="web3Check";i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:o})}),l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new s.BuildBaseContexts(a,c,i).run();expect(p).toEqual({clearSignContexts:e,clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should build the transaction context with generic-parser context",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0],e[1],e[3]],clearSignContextsOptional:[e[2]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should build the transaction context with proxy delegate call context",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:r},{type:n.ClearSignContextType.PROXY_DELEGATE_CALL,payload:"payload-2"}],o=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new s.BuildBaseContexts(a,c,i).run();expect(p).toEqual({clearSignContexts:[e[1],e[0]],clearSignContextsOptional:o,clearSigningType:d.ClearSigningType.EIP7730})}),it("should call the web3checks factory with correct parameters",async()=>{const e=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),await new s.BuildBaseContexts(a,{...c,appConfig:u(!0)},i).run(),expect(i).toHaveBeenCalledWith(a,{contextModule:l,derivationPath:"44'/60'/0'/0/0",subset:c.subset,transaction:C})}),it("should call the context module with the correct parameters",async()=>{const e=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),await new s.BuildBaseContexts(a,c,i).run(),expect(l.getContexts).toHaveBeenCalledWith({deviceModelId:t.DeviceModelId.FLEX,challenge:"challenge",domain:"domain-name.eth",...c.subset})}),it("should call the context module without challenge for Nano S",async()=>{const e=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.NANO_S,isSecureConnectionAllowed:!1}),await new s.BuildBaseContexts(a,c,i).run(),expect(l.getContexts).toHaveBeenCalledWith({deviceModelId:t.DeviceModelId.NANO_S,domain:"domain-name.eth",...c.subset})}),it("should call the context module without context on error",async()=>{const e=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),a.sendCommand.mockResolvedValueOnce((0,t.CommandResultFactory)({error:new t.UnknownDeviceExchangeError})),await new s.BuildBaseContexts(a,c,i).run(),expect(l.getContexts).toHaveBeenCalledWith({deviceModelId:t.DeviceModelId.FLEX,challenge:void 0,domain:"domain-name.eth",...c.subset})}),it("should exclude error contexts from the result",async()=>{const e=[{type:n.ClearSignContextType.ERROR,error:new Error("error")},{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.ERROR,error:new Error("error")},{type:n.ClearSignContextType.NFT,payload:"payload-2"}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts from the result on old apps",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"transaction_info",certificate:r},{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:n.ClearSignContextType.NFT,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"enum",id:1,value:2,certificate:r}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts from the result if no transaction_info was found",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.ENUM,payload:"enum",id:1,value:2},{type:n.ClearSignContextType.NFT,payload:"payload-2"}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude legacy contexts from the result for generic-parser transactions",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.EXTERNAL_PLUGIN,payload:"payload-3"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"},{type:n.ClearSignContextType.ENUM,payload:"payload-5",id:1,value:2,certificate:r}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[e[4]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should exclude generic-parser contexts with a nano s device",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:n.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:r}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:t.DeviceModelId.NANO_S,isSecureConnectionAllowed:!1});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts with an old app version",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:n.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:r}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts with a non ready device",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:n.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:r}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.Connected,deviceStatus:t.DeviceStatus.NOT_CONNECTED,deviceModelId:t.DeviceModelId.FLEX});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should return no clear sign context if the transaction info certificate is missing",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.17.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should not return web3check if the transaction is undefined",async()=>{const e=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.17.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),await new s.BuildBaseContexts(a,{...c,transaction:void 0},i).run(),expect(i).not.toHaveBeenCalled()})});
2
2
  //# sourceMappingURL=BuildBaseContexts.test.js.map