@ledgerhq/device-signer-kit-ethereum 1.2.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/lib/cjs/api/app-binder/GetConfigCommandTypes.js +2 -0
  2. package/lib/cjs/api/app-binder/GetConfigCommandTypes.js.map +7 -0
  3. package/lib/cjs/api/app-binder/SignTransactionDeviceActionTypes.js +1 -1
  4. package/lib/cjs/api/app-binder/SignTransactionDeviceActionTypes.js.map +1 -1
  5. package/lib/cjs/api/app-binder/SignTypedDataDeviceActionTypes.js +1 -1
  6. package/lib/cjs/api/app-binder/SignTypedDataDeviceActionTypes.js.map +1 -1
  7. package/lib/cjs/index.js.map +1 -1
  8. package/lib/cjs/internal/app-binder/EthAppBinder.test.js +1 -1
  9. package/lib/cjs/internal/app-binder/EthAppBinder.test.js.map +2 -2
  10. package/lib/cjs/internal/app-binder/command/GetAppConfigurationCommand.js +2 -0
  11. package/lib/cjs/internal/app-binder/command/GetAppConfigurationCommand.js.map +7 -0
  12. package/lib/cjs/internal/app-binder/command/GetAppConfigurationCommand.test.js +2 -0
  13. package/lib/cjs/internal/app-binder/command/GetAppConfigurationCommand.test.js.map +7 -0
  14. package/lib/cjs/internal/app-binder/command/ProvideWeb3CheckCommand.js +2 -0
  15. package/lib/cjs/internal/app-binder/command/ProvideWeb3CheckCommand.js.map +7 -0
  16. package/lib/cjs/internal/app-binder/command/ProvideWeb3CheckCommand.test.js +2 -0
  17. package/lib/cjs/internal/app-binder/command/ProvideWeb3CheckCommand.test.js.map +7 -0
  18. package/lib/cjs/internal/app-binder/command/Web3CheckOptInCommand.js +2 -0
  19. package/lib/cjs/internal/app-binder/command/Web3CheckOptInCommand.js.map +7 -0
  20. package/lib/cjs/internal/app-binder/command/Web3CheckOptInCommand.test.js +2 -0
  21. package/lib/cjs/internal/app-binder/command/Web3CheckOptInCommand.test.js.map +7 -0
  22. package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js +1 -1
  23. package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js.map +3 -3
  24. package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js +1 -1
  25. package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js.map +3 -3
  26. package/lib/cjs/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.js +1 -1
  27. package/lib/cjs/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.js.map +3 -3
  28. package/lib/cjs/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.test.js +1 -1
  29. package/lib/cjs/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.test.js.map +3 -3
  30. package/lib/cjs/internal/app-binder/device-action/__test-utils__/makeInternalApi.js +1 -1
  31. package/lib/cjs/internal/app-binder/device-action/__test-utils__/makeInternalApi.js.map +3 -3
  32. package/lib/cjs/internal/app-binder/task/BuildEIP712ContextTask.js +1 -1
  33. package/lib/cjs/internal/app-binder/task/BuildEIP712ContextTask.js.map +3 -3
  34. package/lib/cjs/internal/app-binder/task/BuildEIP712ContextTask.test.js +1 -1
  35. package/lib/cjs/internal/app-binder/task/BuildEIP712ContextTask.test.js.map +3 -3
  36. package/lib/cjs/internal/app-binder/task/BuildTransactionContextTask.js +1 -1
  37. package/lib/cjs/internal/app-binder/task/BuildTransactionContextTask.js.map +3 -3
  38. package/lib/cjs/internal/app-binder/task/BuildTransactionContextTask.test.js +1 -1
  39. package/lib/cjs/internal/app-binder/task/BuildTransactionContextTask.test.js.map +3 -3
  40. package/lib/cjs/internal/app-binder/task/GetWeb3CheckTask.js +2 -0
  41. package/lib/cjs/internal/app-binder/task/GetWeb3CheckTask.js.map +7 -0
  42. package/lib/cjs/internal/app-binder/task/GetWeb3CheckTask.test.js +2 -0
  43. package/lib/cjs/internal/app-binder/task/GetWeb3CheckTask.test.js.map +7 -0
  44. package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.js +1 -1
  45. package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.js.map +3 -3
  46. package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.test.js +1 -1
  47. package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.test.js.map +3 -3
  48. package/lib/cjs/internal/app-binder/task/ProvideTransactionContextTask.js +1 -1
  49. package/lib/cjs/internal/app-binder/task/ProvideTransactionContextTask.js.map +3 -3
  50. package/lib/cjs/internal/app-binder/task/ProvideTransactionContextTask.test.js +1 -1
  51. package/lib/cjs/internal/app-binder/task/ProvideTransactionContextTask.test.js.map +2 -2
  52. package/lib/cjs/internal/app-binder/task/ProvideTransactionFieldDescriptionTask.js +1 -1
  53. package/lib/cjs/internal/app-binder/task/ProvideTransactionFieldDescriptionTask.js.map +3 -3
  54. package/lib/cjs/internal/app-binder/task/ProvideTransactionGenericContextTask.js +1 -1
  55. package/lib/cjs/internal/app-binder/task/ProvideTransactionGenericContextTask.js.map +3 -3
  56. package/lib/cjs/internal/app-binder/task/ProvideTransactionGenericContextTask.test.js +1 -1
  57. package/lib/cjs/internal/app-binder/task/ProvideTransactionGenericContextTask.test.js.map +2 -2
  58. package/lib/cjs/internal/shared/utils/ApplicationChecker.js +2 -0
  59. package/lib/cjs/internal/shared/utils/ApplicationChecker.js.map +7 -0
  60. package/lib/cjs/internal/shared/utils/ApplicationChecker.test.js +2 -0
  61. package/lib/cjs/internal/shared/utils/ApplicationChecker.test.js.map +7 -0
  62. package/lib/cjs/package.json +4 -4
  63. package/lib/esm/api/app-binder/GetConfigCommandTypes.js +1 -0
  64. package/lib/esm/api/app-binder/GetConfigCommandTypes.js.map +7 -0
  65. package/lib/esm/internal/app-binder/EthAppBinder.test.js +1 -1
  66. package/lib/esm/internal/app-binder/EthAppBinder.test.js.map +2 -2
  67. package/lib/esm/internal/app-binder/command/GetAppConfigurationCommand.js +2 -0
  68. package/lib/esm/internal/app-binder/command/GetAppConfigurationCommand.js.map +7 -0
  69. package/lib/esm/internal/app-binder/command/GetAppConfigurationCommand.test.js +2 -0
  70. package/lib/esm/internal/app-binder/command/GetAppConfigurationCommand.test.js.map +7 -0
  71. package/lib/esm/internal/app-binder/command/ProvideWeb3CheckCommand.js +2 -0
  72. package/lib/esm/internal/app-binder/command/ProvideWeb3CheckCommand.js.map +7 -0
  73. package/lib/esm/internal/app-binder/command/ProvideWeb3CheckCommand.test.js +2 -0
  74. package/lib/esm/internal/app-binder/command/ProvideWeb3CheckCommand.test.js.map +7 -0
  75. package/lib/esm/internal/app-binder/command/Web3CheckOptInCommand.js +2 -0
  76. package/lib/esm/internal/app-binder/command/Web3CheckOptInCommand.js.map +7 -0
  77. package/lib/esm/internal/app-binder/command/Web3CheckOptInCommand.test.js +2 -0
  78. package/lib/esm/internal/app-binder/command/Web3CheckOptInCommand.test.js.map +7 -0
  79. package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js +1 -1
  80. package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js.map +3 -3
  81. package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js +1 -1
  82. package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js.map +3 -3
  83. package/lib/esm/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.js +1 -1
  84. package/lib/esm/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.js.map +3 -3
  85. package/lib/esm/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.test.js +1 -1
  86. package/lib/esm/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.test.js.map +3 -3
  87. package/lib/esm/internal/app-binder/device-action/__test-utils__/makeInternalApi.js +1 -1
  88. package/lib/esm/internal/app-binder/device-action/__test-utils__/makeInternalApi.js.map +3 -3
  89. package/lib/esm/internal/app-binder/task/BuildEIP712ContextTask.js +1 -1
  90. package/lib/esm/internal/app-binder/task/BuildEIP712ContextTask.js.map +3 -3
  91. package/lib/esm/internal/app-binder/task/BuildEIP712ContextTask.test.js +1 -1
  92. package/lib/esm/internal/app-binder/task/BuildEIP712ContextTask.test.js.map +3 -3
  93. package/lib/esm/internal/app-binder/task/BuildTransactionContextTask.js +1 -1
  94. package/lib/esm/internal/app-binder/task/BuildTransactionContextTask.js.map +3 -3
  95. package/lib/esm/internal/app-binder/task/BuildTransactionContextTask.test.js +1 -1
  96. package/lib/esm/internal/app-binder/task/BuildTransactionContextTask.test.js.map +3 -3
  97. package/lib/esm/internal/app-binder/task/GetWeb3CheckTask.js +2 -0
  98. package/lib/esm/internal/app-binder/task/GetWeb3CheckTask.js.map +7 -0
  99. package/lib/esm/internal/app-binder/task/GetWeb3CheckTask.test.js +2 -0
  100. package/lib/esm/internal/app-binder/task/GetWeb3CheckTask.test.js.map +7 -0
  101. package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.js +1 -1
  102. package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.js.map +3 -3
  103. package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.test.js +1 -1
  104. package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.test.js.map +3 -3
  105. package/lib/esm/internal/app-binder/task/ProvideTransactionContextTask.js +1 -1
  106. package/lib/esm/internal/app-binder/task/ProvideTransactionContextTask.js.map +3 -3
  107. package/lib/esm/internal/app-binder/task/ProvideTransactionContextTask.test.js +1 -1
  108. package/lib/esm/internal/app-binder/task/ProvideTransactionContextTask.test.js.map +2 -2
  109. package/lib/esm/internal/app-binder/task/ProvideTransactionFieldDescriptionTask.js +1 -1
  110. package/lib/esm/internal/app-binder/task/ProvideTransactionFieldDescriptionTask.js.map +3 -3
  111. package/lib/esm/internal/app-binder/task/ProvideTransactionGenericContextTask.js +1 -1
  112. package/lib/esm/internal/app-binder/task/ProvideTransactionGenericContextTask.js.map +3 -3
  113. package/lib/esm/internal/app-binder/task/ProvideTransactionGenericContextTask.test.js +1 -1
  114. package/lib/esm/internal/app-binder/task/ProvideTransactionGenericContextTask.test.js.map +2 -2
  115. package/lib/esm/internal/shared/utils/ApplicationChecker.js +2 -0
  116. package/lib/esm/internal/shared/utils/ApplicationChecker.js.map +7 -0
  117. package/lib/esm/internal/shared/utils/ApplicationChecker.test.js +2 -0
  118. package/lib/esm/internal/shared/utils/ApplicationChecker.test.js.map +7 -0
  119. package/lib/esm/package.json +4 -4
  120. package/lib/types/api/app-binder/GetConfigCommandTypes.d.ts +7 -0
  121. package/lib/types/api/app-binder/GetConfigCommandTypes.d.ts.map +1 -0
  122. package/lib/types/api/app-binder/SignTransactionDeviceActionTypes.d.ts +5 -3
  123. package/lib/types/api/app-binder/SignTransactionDeviceActionTypes.d.ts.map +1 -1
  124. package/lib/types/api/app-binder/SignTypedDataDeviceActionTypes.d.ts +3 -1
  125. package/lib/types/api/app-binder/SignTypedDataDeviceActionTypes.d.ts.map +1 -1
  126. package/lib/types/internal/app-binder/command/GetAppConfigurationCommand.d.ts +10 -0
  127. package/lib/types/internal/app-binder/command/GetAppConfigurationCommand.d.ts.map +1 -0
  128. package/lib/types/internal/app-binder/command/GetAppConfigurationCommand.test.d.ts +2 -0
  129. package/lib/types/internal/app-binder/command/GetAppConfigurationCommand.test.d.ts.map +1 -0
  130. package/lib/types/internal/app-binder/command/ProvideWeb3CheckCommand.d.ts +17 -0
  131. package/lib/types/internal/app-binder/command/ProvideWeb3CheckCommand.d.ts.map +1 -0
  132. package/lib/types/internal/app-binder/command/ProvideWeb3CheckCommand.test.d.ts +2 -0
  133. package/lib/types/internal/app-binder/command/ProvideWeb3CheckCommand.test.d.ts.map +1 -0
  134. package/lib/types/internal/app-binder/command/Web3CheckOptInCommand.d.ts +15 -0
  135. package/lib/types/internal/app-binder/command/Web3CheckOptInCommand.d.ts.map +1 -0
  136. package/lib/types/internal/app-binder/command/Web3CheckOptInCommand.test.d.ts +2 -0
  137. package/lib/types/internal/app-binder/command/Web3CheckOptInCommand.test.d.ts.map +1 -0
  138. package/lib/types/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.d.ts +9 -4
  139. package/lib/types/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.d.ts.map +1 -1
  140. package/lib/types/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.d.ts +6 -0
  141. package/lib/types/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.d.ts.map +1 -1
  142. package/lib/types/internal/app-binder/device-action/__test-utils__/makeInternalApi.d.ts.map +1 -1
  143. package/lib/types/internal/app-binder/task/BuildEIP712ContextTask.d.ts +9 -5
  144. package/lib/types/internal/app-binder/task/BuildEIP712ContextTask.d.ts.map +1 -1
  145. package/lib/types/internal/app-binder/task/BuildTransactionContextTask.d.ts +7 -3
  146. package/lib/types/internal/app-binder/task/BuildTransactionContextTask.d.ts.map +1 -1
  147. package/lib/types/internal/app-binder/task/GetWeb3CheckTask.d.ts +30 -0
  148. package/lib/types/internal/app-binder/task/GetWeb3CheckTask.d.ts.map +1 -0
  149. package/lib/types/internal/app-binder/task/GetWeb3CheckTask.test.d.ts +2 -0
  150. package/lib/types/internal/app-binder/task/GetWeb3CheckTask.test.d.ts.map +1 -0
  151. package/lib/types/internal/app-binder/task/ProvideEIP712ContextTask.d.ts +2 -0
  152. package/lib/types/internal/app-binder/task/ProvideEIP712ContextTask.d.ts.map +1 -1
  153. package/lib/types/internal/app-binder/task/ProvideTransactionContextTask.d.ts +3 -2
  154. package/lib/types/internal/app-binder/task/ProvideTransactionContextTask.d.ts.map +1 -1
  155. package/lib/types/internal/app-binder/task/ProvideTransactionFieldDescriptionTask.d.ts.map +1 -1
  156. package/lib/types/internal/app-binder/task/ProvideTransactionGenericContextTask.d.ts +1 -0
  157. package/lib/types/internal/app-binder/task/ProvideTransactionGenericContextTask.d.ts.map +1 -1
  158. package/lib/types/internal/shared/utils/ApplicationChecker.d.ts +12 -0
  159. package/lib/types/internal/shared/utils/ApplicationChecker.d.ts.map +1 -0
  160. package/lib/types/internal/shared/utils/ApplicationChecker.test.d.ts +2 -0
  161. package/lib/types/internal/shared/utils/ApplicationChecker.test.d.ts.map +1 -0
  162. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  163. package/package.json +9 -9
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/internal/app-binder/task/BuildEIP712ContextTask.test.ts"],
4
- "sourcesContent": ["import { type TypedDataClearSignContextSuccess } from \"@ledgerhq/context-module\";\nimport {\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n} from \"@ledgerhq/device-management-kit\";\nimport { Just, Left, Nothing, Right } from \"purify-ts\";\n\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\nimport {\n PrimitiveType,\n StructType,\n TypedDataValueField,\n TypedDataValueRoot,\n} from \"@internal/typed-data/model/Types\";\n\nimport { BuildEIP712ContextTask } from \"./BuildEIP712ContextTask\";\n\ndescribe(\"BuildEIP712ContextTask\", () => {\n const apiMock = makeDeviceActionInternalApiMock();\n const contextMouleMock = {\n getContext: vi.fn(),\n getContexts: vi.fn(),\n getTypedDataFilters: vi.fn(),\n };\n const parserMock = {\n parse: vi.fn(),\n };\n\n const TEST_DATA = {\n domain: {\n name: \"Permit2\",\n chainId: 137,\n verifyingContract: \"0x000000000022d473030f116ddee9f6b43ac78ba3\",\n },\n primaryType: \"PermitSingle\",\n message: {\n details: {\n token: \"0x7ceb23fd6bc0add59e62ac25578270cff1b9f619\",\n amount: \"69420000000000000000\",\n expiration: \"1718184249\",\n nonce: \"0\",\n },\n spender: \"0xec7be89e9d109e7e3fec59c222cf297125fefda2\",\n sigDeadline: \"1715594049\",\n },\n types: {\n PermitSingle: [\n {\n name: \"details\",\n type: \"PermitDetails\",\n },\n {\n name: \"spender\",\n type: \"address\",\n },\n {\n name: \"sigDeadline\",\n type: \"uint256\",\n },\n ],\n PermitDetails: [\n { name: \"token\", type: \"address\" },\n { name: \"amount\", type: \"uint\" },\n { name: \"expiration\", type: \"uint\" },\n { name: \"nonce\", type: \"uint\" },\n ],\n },\n };\n\n const TEST_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 PermitDetails: {\n token: new PrimitiveType(\"address\", \"address\", Nothing),\n amount: new PrimitiveType(\"uint160\", \"uint\", Just(20)),\n expiration: new PrimitiveType(\"uint48\", \"uint\", Just(6)),\n nonce: new PrimitiveType(\"uint48\", \"uint\", Just(6)),\n },\n };\n const TEST_DOMAIN_VALUES = [\n {\n path: \"\",\n type: \"\",\n value: new TypedDataValueRoot(\"EIP712Domain\"),\n },\n {\n path: \"chainId\",\n type: \"uint256\",\n value: new TypedDataValueField(Uint8Array.from([137])),\n },\n ];\n const TEST_MESSAGE_VALUES = [\n {\n path: \"\",\n type: \"\",\n value: new TypedDataValueRoot(\"PermitSingle\"),\n },\n {\n path: \"details.amount\",\n type: \"uint160\",\n value: new TypedDataValueField(Uint8Array.from([0x12])),\n },\n {\n path: \"details.expiration\",\n type: \"uint48\",\n value: new TypedDataValueField(Uint8Array.from([0x13])),\n },\n ];\n const TEST_CLEAR_SIGN_CONTEXT: TypedDataClearSignContextSuccess = {\n type: \"success\",\n messageInfo: {\n displayName: \"Permit2\",\n filtersCount: 1,\n signature:\n \"3045022100e3c597d13d28a87a88b0239404c668373cf5063362f2a81d09eed4582941dfe802207669aabb504fd5b95b2734057f6b8bbf51f14a69a5f9bdf658a5952cefbf44d3\",\n },\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 beforeEach(() => {\n vi.resetAllMocks();\n });\n\n it(\"Build context with clear signing context not supported by the device\", async () => {\n // GIVEN\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n TEST_DATA,\n );\n parserMock.parse.mockReturnValueOnce(\n Right({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n }),\n );\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Bitcoin\", version: \"1.0\" },\n deviceModelId: DeviceModelId.FLEX,\n });\n // WHEN\n const builtContext = await task.run();\n // THEN\n expect(builtContext).toStrictEqual({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n clearSignContext: Nothing,\n domainHash:\n \"0xf033048cb2764f596bc4d98e089fa38bb84b4be3d5da2e77f9bfac0e4d6c68ca\",\n messageHash:\n \"0x1087495b5e10337738059920fe1de8216235299745e8c97e21b409009a4c362a\",\n });\n });\n\n it(\"Build context with no clear signing context\", async () => {\n // GIVEN\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n TEST_DATA,\n );\n parserMock.parse.mockReturnValueOnce(\n Right({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n }),\n );\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n });\n contextMouleMock.getTypedDataFilters.mockResolvedValueOnce({\n type: \"error\",\n error: new Error(\"no filter\"),\n });\n // WHEN\n const builtContext = await task.run();\n // THEN\n expect(builtContext).toStrictEqual({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n clearSignContext: Nothing,\n domainHash:\n \"0xf033048cb2764f596bc4d98e089fa38bb84b4be3d5da2e77f9bfac0e4d6c68ca\",\n messageHash:\n \"0x1087495b5e10337738059920fe1de8216235299745e8c97e21b409009a4c362a\",\n });\n });\n\n it(\"Build context with clear signing context\", async () => {\n // GIVEN\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n TEST_DATA,\n );\n parserMock.parse.mockReturnValueOnce(\n Right({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n }),\n );\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n });\n contextMouleMock.getTypedDataFilters.mockResolvedValueOnce(\n TEST_CLEAR_SIGN_CONTEXT,\n );\n // WHEN\n const builtContext = await task.run();\n // THEN\n expect(builtContext).toStrictEqual({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n clearSignContext: Just(TEST_CLEAR_SIGN_CONTEXT),\n domainHash:\n \"0xf033048cb2764f596bc4d98e089fa38bb84b4be3d5da2e77f9bfac0e4d6c68ca\",\n messageHash:\n \"0x1087495b5e10337738059920fe1de8216235299745e8c97e21b409009a4c362a\",\n });\n expect(parserMock.parse).toHaveBeenCalledWith(TEST_DATA);\n expect(contextMouleMock.getTypedDataFilters).toHaveBeenCalledWith({\n verifyingContract: \"0x000000000022d473030f116ddee9f6b43ac78ba3\",\n chainId: 137,\n version: \"v2\",\n schema: TEST_DATA[\"types\"],\n fieldsValues: [\n {\n path: \"details.amount\",\n value: Uint8Array.from([0x12]),\n },\n {\n path: \"details.expiration\",\n value: Uint8Array.from([0x13]),\n },\n ],\n });\n });\n\n it(\"Build context with clear signing context V1\", async () => {\n // GIVEN\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n TEST_DATA,\n );\n parserMock.parse.mockReturnValueOnce(\n Right({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n }),\n );\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.11.0\" },\n deviceModelId: DeviceModelId.FLEX,\n });\n contextMouleMock.getTypedDataFilters.mockResolvedValueOnce(\n TEST_CLEAR_SIGN_CONTEXT,\n );\n // WHEN\n await task.run();\n // THEN\n expect(contextMouleMock.getTypedDataFilters).toHaveBeenCalledWith({\n verifyingContract: \"0x000000000022d473030f116ddee9f6b43ac78ba3\",\n chainId: 137,\n version: \"v1\",\n schema: TEST_DATA[\"types\"],\n fieldsValues: [\n {\n path: \"details.amount\",\n value: Uint8Array.from([0x12]),\n },\n {\n path: \"details.expiration\",\n value: Uint8Array.from([0x13]),\n },\n ],\n });\n });\n\n it(\"Should throw error if no primary type\", async () => {\n // GIVEN\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n {\n ...TEST_DATA,\n primaryType: \"\",\n },\n );\n parserMock.parse.mockReturnValueOnce(\n Right({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n }),\n );\n // WHEN\n try {\n await task.run();\n } catch (e) {\n // THEN\n expect(e).toBeInstanceOf(Error);\n // @ts-expect-error\n expect(e.message).toBe('Primary type \"\" is not defined in the types.');\n }\n });\n\n it(\"Should throw an error if parsing fails\", async () => {\n // GIVEN\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n TEST_DATA,\n );\n parserMock.parse.mockReturnValueOnce(Left(new Error(\"Parsing error\")));\n // WHEN\n try {\n await task.run();\n } catch (e) {\n // THEN\n expect(e).toBeInstanceOf(Error);\n // @ts-expect-error\n expect(e.message).toBe(\"Parsing error\");\n }\n });\n});\n"],
5
- "mappings": "aACA,IAAAA,EAIO,2CACPC,EAA2C,qBAE3CC,EAAgD,6EAChDC,EAKO,4CAEPC,EAAuC,oCAEvC,SAAS,yBAA0B,IAAM,CACvC,MAAMC,KAAU,mCAAgC,EAC1CC,EAAmB,CACvB,WAAY,GAAG,GAAG,EAClB,YAAa,GAAG,GAAG,EACnB,oBAAqB,GAAG,GAAG,CAC7B,EACMC,EAAa,CACjB,MAAO,GAAG,GAAG,CACf,EAEMC,EAAY,CAChB,OAAQ,CACN,KAAM,UACN,QAAS,IACT,kBAAmB,4CACrB,EACA,YAAa,eACb,QAAS,CACP,QAAS,CACP,MAAO,6CACP,OAAQ,uBACR,WAAY,aACZ,MAAO,GACT,EACA,QAAS,6CACT,YAAa,YACf,EACA,MAAO,CACL,aAAc,CACZ,CACE,KAAM,UACN,KAAM,eACR,EACA,CACE,KAAM,UACN,KAAM,SACR,EACA,CACE,KAAM,cACN,KAAM,SACR,CACF,EACA,cAAe,CACb,CAAE,KAAM,QAAS,KAAM,SAAU,EACjC,CAAE,KAAM,SAAU,KAAM,MAAO,EAC/B,CAAE,KAAM,aAAc,KAAM,MAAO,EACnC,CAAE,KAAM,QAAS,KAAM,MAAO,CAChC,CACF,CACF,EAEMC,EAAa,CACjB,aAAc,CACZ,QAAS,IAAI,aAAW,eAAe,EACvC,QAAS,IAAI,gBAAc,UAAW,UAAW,SAAO,EACxD,YAAa,IAAI,gBAAc,UAAW,UAAQ,QAAK,EAAE,CAAC,CAC5D,EACA,cAAe,CACb,MAAO,IAAI,gBAAc,UAAW,UAAW,SAAO,EACtD,OAAQ,IAAI,gBAAc,UAAW,UAAQ,QAAK,EAAE,CAAC,EACrD,WAAY,IAAI,gBAAc,SAAU,UAAQ,Q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AC,EAED,GAAG,yCAA0C,SAAY,CAEvD,MAAMF,EAAO,IAAI,yBACfR,EACAC,EACAC,EACAC,CACF,EACAD,EAAW,MAAM,uBAAoB,QAAK,IAAI,MAAM,eAAe,CAAC,CAAC,EAErE,GAAI,CACF,MAAMM,EAAK,IAAI,CACjB,OAASE,EAAG,CAEV,OAAOA,CAAC,EAAE,eAAe,KAAK,EAE9B,OAAOA,EAAE,OAAO,EAAE,KAAK,eAAe,CACxC,CACF,CAAC,CACH,CAAC",
6
- "names": ["import_device_management_kit", "import_purify_ts", "import_makeInternalApi", "import_Types", "import_BuildEIP712ContextTask", "apiMock", "contextMouleMock", "parserMock", "TEST_DATA", "TEST_TYPES", "TEST_DOMAIN_VALUES", "TEST_MESSAGE_VALUES", "TEST_CLEAR_SIGN_CONTEXT", "task", "builtContext", "e"]
4
+ "sourcesContent": ["import type {\n ClearSignContextSuccess,\n ClearSignContextType,\n TypedDataClearSignContextSuccess,\n} from \"@ledgerhq/context-module\";\nimport {\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n} from \"@ledgerhq/device-management-kit\";\nimport { Just, Left, Nothing, Right } from \"purify-ts\";\n\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\nimport {\n PrimitiveType,\n StructType,\n TypedDataValueField,\n TypedDataValueRoot,\n} from \"@internal/typed-data/model/Types\";\n\nimport { BuildEIP712ContextTask } from \"./BuildEIP712ContextTask\";\n\ndescribe(\"BuildEIP712ContextTask\", () => {\n const apiMock = makeDeviceActionInternalApiMock();\n const contextMouleMock = {\n getContext: vi.fn(),\n getContexts: vi.fn(),\n getTypedDataFilters: vi.fn(),\n getWeb3Checks: vi.fn(),\n };\n const parserMock = {\n parse: vi.fn(),\n };\n const getWeb3ChecksFactoryMock = vi.fn();\n\n const TEST_DATA = {\n domain: {\n name: \"Permit2\",\n chainId: 137,\n verifyingContract: \"0x000000000022d473030f116ddee9f6b43ac78ba3\",\n },\n primaryType: \"PermitSingle\",\n message: {\n details: {\n token: \"0x7ceb23fd6bc0add59e62ac25578270cff1b9f619\",\n amount: \"69420000000000000000\",\n expiration: \"1718184249\",\n nonce: \"0\",\n },\n spender: \"0xec7be89e9d109e7e3fec59c222cf297125fefda2\",\n sigDeadline: \"1715594049\",\n },\n types: {\n PermitSingle: [\n {\n name: \"details\",\n type: \"PermitDetails\",\n },\n {\n name: \"spender\",\n type: \"address\",\n },\n {\n name: \"sigDeadline\",\n type: \"uint256\",\n },\n ],\n PermitDetails: [\n { name: \"token\", type: \"address\" },\n { name: \"amount\", type: \"uint\" },\n { name: \"expiration\", type: \"uint\" },\n { name: \"nonce\", type: \"uint\" },\n ],\n },\n };\n\n const TEST_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 PermitDetails: {\n token: new PrimitiveType(\"address\", \"address\", Nothing),\n amount: new PrimitiveType(\"uint160\", \"uint\", Just(20)),\n expiration: new PrimitiveType(\"uint48\", \"uint\", Just(6)),\n nonce: new PrimitiveType(\"uint48\", \"uint\", Just(6)),\n },\n };\n const TEST_DOMAIN_VALUES = [\n {\n path: \"\",\n type: \"\",\n value: new TypedDataValueRoot(\"EIP712Domain\"),\n },\n {\n path: \"chainId\",\n type: \"uint256\",\n value: new TypedDataValueField(Uint8Array.from([137])),\n },\n ];\n const TEST_MESSAGE_VALUES = [\n {\n path: \"\",\n type: \"\",\n value: new TypedDataValueRoot(\"PermitSingle\"),\n },\n {\n path: \"details.amount\",\n type: \"uint160\",\n value: new TypedDataValueField(Uint8Array.from([0x12])),\n },\n {\n path: \"details.expiration\",\n type: \"uint48\",\n value: new TypedDataValueField(Uint8Array.from([0x13])),\n },\n ];\n const TEST_CLEAR_SIGN_CONTEXT: TypedDataClearSignContextSuccess = {\n type: \"success\",\n messageInfo: {\n displayName: \"Permit2\",\n filtersCount: 1,\n signature:\n \"3045022100e3c597d13d28a87a88b0239404c668373cf5063362f2a81d09eed4582941dfe802207669aabb504fd5b95b2734057f6b8bbf51f14a69a5f9bdf658a5952cefbf44d3\",\n },\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 beforeEach(() => {\n vi.resetAllMocks();\n getWeb3ChecksFactoryMock.mockReturnValue({\n run: async () => ({ web3Check: null }),\n });\n });\n\n it(\"Build context with clear signing context not supported by the device\", async () => {\n // GIVEN\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n TEST_DATA,\n \"44'/60'/0'/0/0\",\n false,\n getWeb3ChecksFactoryMock,\n );\n parserMock.parse.mockReturnValueOnce(\n Right({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n }),\n );\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.11.0\" },\n deviceModelId: DeviceModelId.NANO_S,\n isSecureConnectionAllowed: false,\n });\n // WHEN\n const builtContext = await task.run();\n // THEN\n expect(builtContext).toStrictEqual({\n web3Check: null,\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n clearSignContext: Nothing,\n domainHash:\n \"0xf033048cb2764f596bc4d98e089fa38bb84b4be3d5da2e77f9bfac0e4d6c68ca\",\n messageHash:\n \"0x1087495b5e10337738059920fe1de8216235299745e8c97e21b409009a4c362a\",\n });\n });\n\n it(\"Build context with no clear signing context\", async () => {\n // GIVEN\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n TEST_DATA,\n \"44'/60'/0'/0/0\",\n false,\n getWeb3ChecksFactoryMock,\n );\n parserMock.parse.mockReturnValueOnce(\n Right({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n }),\n );\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n contextMouleMock.getTypedDataFilters.mockResolvedValueOnce({\n type: \"error\",\n error: new Error(\"no filter\"),\n });\n // WHEN\n const builtContext = await task.run();\n // THEN\n expect(builtContext).toStrictEqual({\n web3Check: null,\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n clearSignContext: Nothing,\n domainHash:\n \"0xf033048cb2764f596bc4d98e089fa38bb84b4be3d5da2e77f9bfac0e4d6c68ca\",\n messageHash:\n \"0x1087495b5e10337738059920fe1de8216235299745e8c97e21b409009a4c362a\",\n });\n });\n\n it(\"Build context with clear signing context\", async () => {\n // GIVEN\n const expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n TEST_DATA,\n \"44'/60'/0'/0/0\",\n false,\n getWeb3ChecksFactoryMock,\n );\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => ({ web3Check: expectedWeb3Check }),\n });\n parserMock.parse.mockReturnValueOnce(\n Right({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n }),\n );\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n contextMouleMock.getTypedDataFilters.mockResolvedValueOnce(\n TEST_CLEAR_SIGN_CONTEXT,\n );\n // WHEN\n const builtContext = await task.run();\n // THEN\n expect(builtContext).toStrictEqual({\n web3Check: null,\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n clearSignContext: Just(TEST_CLEAR_SIGN_CONTEXT),\n domainHash:\n \"0xf033048cb2764f596bc4d98e089fa38bb84b4be3d5da2e77f9bfac0e4d6c68ca\",\n messageHash:\n \"0x1087495b5e10337738059920fe1de8216235299745e8c97e21b409009a4c362a\",\n });\n expect(parserMock.parse).toHaveBeenCalledWith(TEST_DATA);\n expect(contextMouleMock.getTypedDataFilters).toHaveBeenCalledWith({\n verifyingContract: \"0x000000000022d473030f116ddee9f6b43ac78ba3\",\n chainId: 137,\n version: \"v2\",\n schema: TEST_DATA[\"types\"],\n fieldsValues: [\n {\n path: \"details.amount\",\n value: Uint8Array.from([0x12]),\n },\n {\n path: \"details.expiration\",\n value: Uint8Array.from([0x13]),\n },\n ],\n });\n });\n\n it(\"Build context with clear signing context and web3Check\", async () => {\n // GIVEN\n const expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n TEST_DATA,\n \"44'/60'/0'/0/0\",\n true,\n getWeb3ChecksFactoryMock,\n );\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => ({ web3Check: expectedWeb3Check }),\n });\n parserMock.parse.mockReturnValueOnce(\n Right({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n }),\n );\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n contextMouleMock.getTypedDataFilters.mockResolvedValueOnce(\n TEST_CLEAR_SIGN_CONTEXT,\n );\n // WHEN\n const builtContext = await task.run();\n // THEN\n expect(builtContext).toStrictEqual({\n web3Check: expectedWeb3Check,\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n clearSignContext: Just(TEST_CLEAR_SIGN_CONTEXT),\n domainHash:\n \"0xf033048cb2764f596bc4d98e089fa38bb84b4be3d5da2e77f9bfac0e4d6c68ca\",\n messageHash:\n \"0x1087495b5e10337738059920fe1de8216235299745e8c97e21b409009a4c362a\",\n });\n expect(getWeb3ChecksFactoryMock).toHaveBeenCalledWith(apiMock, {\n contextModule: contextMouleMock,\n derivationPath: \"44'/60'/0'/0/0\",\n data: TEST_DATA,\n });\n });\n\n it(\"Build context with clear signing context V1\", async () => {\n // GIVEN\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n TEST_DATA,\n \"44'/60'/0'/0/0\",\n false,\n getWeb3ChecksFactoryMock,\n );\n parserMock.parse.mockReturnValueOnce(\n Right({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n }),\n );\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.11.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n contextMouleMock.getTypedDataFilters.mockResolvedValueOnce(\n TEST_CLEAR_SIGN_CONTEXT,\n );\n // WHEN\n await task.run();\n // THEN\n expect(contextMouleMock.getTypedDataFilters).toHaveBeenCalledWith({\n verifyingContract: \"0x000000000022d473030f116ddee9f6b43ac78ba3\",\n chainId: 137,\n version: \"v1\",\n schema: TEST_DATA[\"types\"],\n fieldsValues: [\n {\n path: \"details.amount\",\n value: Uint8Array.from([0x12]),\n },\n {\n path: \"details.expiration\",\n value: Uint8Array.from([0x13]),\n },\n ],\n });\n });\n\n it(\"Should throw error if no primary type\", async () => {\n // GIVEN\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n {\n ...TEST_DATA,\n primaryType: \"\",\n },\n \"44'/60'/0'/0/0\",\n false,\n getWeb3ChecksFactoryMock,\n );\n parserMock.parse.mockReturnValueOnce(\n Right({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n }),\n );\n // WHEN\n try {\n await task.run();\n } catch (e) {\n // THEN\n expect(e).toBeInstanceOf(Error);\n // @ts-expect-error\n expect(e.message).toBe('Primary type \"\" is not defined in the types.');\n }\n });\n\n it(\"Should throw an error if parsing fails\", async () => {\n // GIVEN\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n TEST_DATA,\n \"44'/60'/0'/0/0\",\n false,\n getWeb3ChecksFactoryMock,\n );\n parserMock.parse.mockReturnValueOnce(Left(new Error(\"Parsing error\")));\n // WHEN\n try {\n await task.run();\n } catch (e) {\n // THEN\n expect(e).toBeInstanceOf(Error);\n // @ts-expect-error\n expect(e.message).toBe(\"Parsing error\");\n }\n });\n});\n"],
5
+ "mappings": "aAKA,IAAAA,EAIO,2CACPC,EAA2C,qBAE3CC,EAAgD,6EAChDC,EAKO,4CAEPC,EAAuC,oCAEvC,SAAS,yBAA0B,IAAM,CACvC,MAAMC,KAAU,mCAAgC,EAC1CC,EAAmB,CACvB,WAAY,GAAG,GAAG,EAClB,YAAa,GAAG,GAAG,EACnB,oBAAqB,GAAG,GAAG,EAC3B,c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AAS,QAAS,EAClD,cAAe,gBAAc,KAC7B,0BAA2B,EAC7B,CAAC,EACDC,EAAiB,oBAAoB,sBACnCO,CACF,EAEA,MAAMC,EAAK,IAAI,EAEf,OAAOR,EAAiB,mBAAmB,EAAE,qBAAqB,CAChE,kBAAmB,6CACnB,QAAS,IACT,QAAS,KACT,OAAQG,EAAU,MAClB,aAAc,CACZ,CACE,KAAM,iBACN,MAAO,WAAW,KAAK,CAAC,EAAI,CAAC,CAC/B,EACA,CACE,KAAM,qBACN,MAAO,WAAW,KAAK,CAAC,EAAI,CAAC,CAC/B,CACF,CACF,CAAC,CACH,CAAC,EAED,GAAG,wCAAyC,SAAY,CAEtD,MAAMK,EAAO,IAAI,yBACfT,EACAC,EACAC,EACA,CACE,GAAGE,EACH,YAAa,EACf,EACA,iBACA,GACAD,CACF,EACAD,EAAW,MAAM,uBACf,SAAM,CACJ,MAAOG,EACP,OAAQC,EACR,QAASC,CACX,CAAC,CACH,EAEA,GAAI,CACF,MAAME,EAAK,IAAI,CACjB,OAASG,EAAG,CAEV,OAAOA,CAAC,EAAE,eAAe,KAAK,EAE9B,OAAOA,EAAE,OAAO,EAAE,KAAK,8CAA8C,CACvE,CACF,CAAC,EAED,GAAG,yCAA0C,SAAY,CAEvD,MAAMH,EAAO,IAAI,yBACfT,EACAC,EACAC,EACAE,EACA,iBACA,GACAD,CACF,EACAD,EAAW,MAAM,uBAAoB,QAAK,IAAI,MAAM,eAAe,CAAC,CAAC,EAErE,GAAI,CACF,MAAMO,EAAK,IAAI,CACjB,OAASG,EAAG,CAEV,OAAOA,CAAC,EAAE,eAAe,KAAK,EAE9B,OAAOA,EAAE,OAAO,EAAE,KAAK,eAAe,CACxC,CACF,CAAC,CACH,CAAC",
6
+ "names": ["import_device_management_kit", "import_purify_ts", "import_makeInternalApi", "import_Types", "import_BuildEIP712ContextTask", "apiMock", "contextMouleMock", "parserMock", "getWeb3ChecksFactoryMock", "TEST_DATA", "TEST_TYPES", "TEST_DOMAIN_VALUES", "TEST_MESSAGE_VALUES", "TEST_CLEAR_SIGN_CONTEXT", "task", "builtContext", "expectedWeb3Check", "e"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var d=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var h=(n,e)=>{for(var o in e)d(n,o,{get:e[o],enumerable:!0})},O=(n,e,o,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of E(e))!M.call(n,a)&&a!==o&&d(n,a,{get:()=>e[a],enumerable:!(s=A(e,a))||s.enumerable});return n};var R=n=>O(d({},"__esModule",{value:!0}),n);var D={};h(D,{BuildTransactionContextTask:()=>v});module.exports=R(D);var r=require("@ledgerhq/context-module"),c=require("@ledgerhq/device-management-kit"),S=require("semver"),f=require("../../app-binder/constant/plugins");class v{constructor(e,o){this.api=e;this.args=o}async run(){const{contextModule:e,mapper:o,transaction:s,options:a,challenge:m}=this.args,y=this.api.getDeviceSessionState(),C=o.mapTransactionToSubset(s);C.ifLeft(t=>{throw t});const{subset:T,serializedTransaction:x,type:g}=C.unsafeCoerce(),u=await e.getContexts({challenge:m??void 0,domain:a.domain,deviceModelId:y.deviceModelId,...T}),p=u.filter(t=>t.type!==r.ClearSignContextType.ERROR&&t.type!==r.ClearSignContextType.ENUM),I=u.filter(t=>t.type===r.ClearSignContextType.ENUM);let l=[];const i=p.find(t=>t.type===r.ClearSignContextType.TRANSACTION_INFO);if(i&&!i.certificate)throw new Error("Transaction info certificate is missing");if(!this.supportsGenericParser(y)||i===void 0)l=p.filter(t=>t.type!==r.ClearSignContextType.TRANSACTION_INFO&&t.type!==r.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION);else{const t=p.filter(N=>N.type===r.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION);l={transactionInfo:i.payload,transactionInfoCertificate:i.certificate,transactionFields:t,transactionEnums:I}}return{clearSignContexts:l,serializedTransaction:x,chainId:T.chainId,transactionType:g}}supportsGenericParser(e){if(e.sessionStateType===c.DeviceSessionStateType.Connected)return!1;if(e.currentApp.name!=="Ethereum"&&!f.ETHEREUM_PLUGINS.includes(e.currentApp.name))throw new Error("Unsupported app");return e.deviceModelId===c.DeviceModelId.NANO_S?!1:(0,S.gte)(e.currentApp.version,"1.15.0")}}0&&(module.exports={BuildTransactionContextTask});
1
+ "use strict";var d=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var R=(a,e)=>{for(var i in e)d(a,i,{get:e[i],enumerable:!0})},O=(a,e,i,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of w(e))!M.call(a,n)&&n!==i&&d(a,n,{get:()=>e[n],enumerable:!(o=v(e,n))||o.enumerable});return a};var D=a=>O(d({},"__esModule",{value:!0}),a);var _={};R(_,{BuildTransactionContextTask:()=>G});module.exports=D(_);var r=require("@ledgerhq/context-module"),c=require("@ledgerhq/device-management-kit"),m=require("../../app-binder/command/GetChallengeCommand"),h=require("../../app-binder/task/GetWeb3CheckTask"),I=require("../../shared/utils/ApplicationChecker");class G{constructor(e,i,o=(n,l)=>new h.GetWeb3CheckTask(n,l)){this.api=e;this.args=i;this.getWeb3ChecksFactory=o}async run(){const{contextModule:e,mapper:i,transaction:o,options:n,web3ChecksEnabled:l,derivationPath:k}=this.args,y=this.api.getDeviceSessionState(),S=i.mapTransactionToSubset(o);S.ifLeft(t=>{throw t});const{subset:T,serializedTransaction:A,type:E}=S.unsafeCoerce();let u=null;l&&(u=(await this.getWeb3ChecksFactory(this.api,{contextModule:e,derivationPath:k,mapper:i,transaction:o}).run()).web3Check);let g;const x=await this.api.sendCommand(new m.GetChallengeCommand);(0,c.isSuccessCommandResult)(x)&&(g=x.data.challenge);const f=await e.getContexts({challenge:g,domain:n.domain,deviceModelId:y.deviceModelId,...T}),p=f.filter(t=>t.type!==r.ClearSignContextType.ERROR&&t.type!==r.ClearSignContextType.ENUM),N=f.filter(t=>t.type===r.ClearSignContextType.ENUM);let C=[];const s=p.find(t=>t.type===r.ClearSignContextType.TRANSACTION_INFO);if(s&&!s.certificate)throw new Error("Transaction info certificate is missing");if(!this.supportsGenericParser(y)||s===void 0)C=p.filter(t=>t.type!==r.ClearSignContextType.TRANSACTION_INFO&&t.type!==r.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION);else{const t=p.filter(b=>b.type===r.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION);C={transactionInfo:s.payload,transactionInfoCertificate:s.certificate,transactionFields:t,transactionEnums:N}}return{clearSignContexts:C,serializedTransaction:A,chainId:T.chainId,transactionType:E,web3Check:u}}supportsGenericParser(e){return new I.ApplicationChecker(e).withMinVersionExclusive("1.14.0").excludeDeviceModel(c.DeviceModelId.NANO_S).check()}}0&&(module.exports={BuildTransactionContextTask});
2
2
  //# sourceMappingURL=BuildTransactionContextTask.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/internal/app-binder/task/BuildTransactionContextTask.ts"],
4
- "sourcesContent": ["import {\n type ClearSignContextSuccess,\n type ClearSignContextSuccessType,\n ClearSignContextType,\n type ContextModule,\n} from \"@ledgerhq/context-module\";\nimport {\n DeviceModelId,\n type DeviceSessionState,\n DeviceSessionStateType,\n type InternalApi,\n} from \"@ledgerhq/device-management-kit\";\nimport { gte } from \"semver\";\n\nimport { type TransactionOptions } from \"@api/model/TransactionOptions\";\nimport { type TransactionType } from \"@api/model/TransactionType\";\nimport { ETHEREUM_PLUGINS } from \"@internal/app-binder/constant/plugins\";\nimport { type TransactionMapperService } from \"@internal/transaction/service/mapper/TransactionMapperService\";\n\nimport { type GenericContext } from \"./ProvideTransactionGenericContextTask\";\n\nexport type BuildTransactionTaskResult = {\n readonly clearSignContexts: ClearSignContextSuccess[] | GenericContext;\n readonly serializedTransaction: Uint8Array;\n readonly chainId: number;\n readonly transactionType: TransactionType;\n};\n\nexport type BuildTransactionContextTaskArgs = {\n readonly contextModule: ContextModule;\n readonly mapper: TransactionMapperService;\n readonly transaction: Uint8Array;\n readonly options: TransactionOptions;\n readonly challenge: string | null;\n};\n\nexport class BuildTransactionContextTask {\n constructor(\n private readonly api: InternalApi,\n private readonly args: BuildTransactionContextTaskArgs,\n ) {}\n\n async run(): Promise<BuildTransactionTaskResult> {\n const { contextModule, mapper, transaction, options, challenge } =\n this.args;\n const deviceState = this.api.getDeviceSessionState();\n\n const parsed = mapper.mapTransactionToSubset(transaction);\n parsed.ifLeft((err) => {\n throw err;\n });\n const { subset, serializedTransaction, type } = parsed.unsafeCoerce();\n\n const clearSignContexts = await contextModule.getContexts({\n challenge: challenge ?? undefined,\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 let filteredContexts: ClearSignContextSuccess[] | GenericContext = [];\n const transactionInfo = clearSignContextsSuccess.find(\n (ctx) => ctx.type === ClearSignContextType.TRANSACTION_INFO,\n );\n\n if (transactionInfo && !transactionInfo.certificate) {\n throw new Error(\"Transaction info certificate is missing\");\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) ||\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 } else {\n const transactionFields = clearSignContextsSuccess.filter(\n (ctx) =>\n ctx.type === ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n );\n filteredContexts = {\n transactionInfo: transactionInfo.payload,\n transactionInfoCertificate: transactionInfo.certificate!,\n transactionFields,\n transactionEnums,\n };\n }\n\n return {\n clearSignContexts: filteredContexts,\n serializedTransaction,\n chainId: subset.chainId,\n transactionType: type,\n };\n }\n\n private supportsGenericParser(deviceState: DeviceSessionState): boolean {\n if (deviceState.sessionStateType === DeviceSessionStateType.Connected) {\n return false;\n }\n\n if (\n deviceState.currentApp.name !== \"Ethereum\" &&\n !ETHEREUM_PLUGINS.includes(deviceState.currentApp.name)\n ) {\n // Sanity check, should never happen as open app is called before this task\n throw new Error(\"Unsupported app\");\n }\n\n if (deviceState.deviceModelId === DeviceModelId.NANO_S) {\n return false;\n }\n return gte(deviceState.currentApp.version, \"1.15.0\");\n }\n}\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAKO,oCACPC,EAKO,2CACPC,EAAoB,kBAIpBC,EAAiC,iDAoB1B,MAAML,CAA4B,CACvC,YACmBM,EACAC,EACjB,CAFiB,SAAAD,EACA,UAAAC,CAChB,CAEH,MAAM,KAA2C,CAC/C,KAAM,CAAE,cAAAC,EAAe,OAAAC,EAAQ,YAAAC,EAAa,QAAAC,EAAS,UAAAC,CAAU,EAC7D,KAAK,KACDC,EAAc,KAAK,IAAI,sBAAsB,EAE7CC,EAASL,EAAO,uBAAuBC,CAAW,EACxDI,EAAO,OAAQC,GAAQ,CACrB,MAAMA,CACR,CAAC,EACD,KAAM,CAAE,OAAAC,EAAQ,sBAAAC,EAAuB,KAAAC,CAAK,EAAIJ,EAAO,aAAa,EAE9DK,EAAoB,MAAMX,EAAc,YAAY,CACxD,UAAWI,GAAa,OACxB,OAAQD,EAAQ,OAChB,cAAeE,EAAY,cAC3B,GAAGG,CACL,CAAC,EAKKI,EAEAD,EAAkB,OACrBE,GACCA,EAAQ,OAAS,uBAAqB,OACtCA,EAAQ,OAAS,uBAAqB,IAC1C,EAGMC,EACJH,EAAkB,OACfE,GAAYA,EAAQ,OAAS,uBAAqB,IACrD,EAEF,IAAIE,EAA+D,CAAC,EACpE,MAAMC,EAAkBJ,EAAyB,KAC9CK,GAAQA,EAAI,OAAS,uBAAqB,gBAC7C,EAEA,GAAID,GAAmB,CAACA,EAAgB,YACtC,MAAM,IAAI,MAAM,yCAAyC,EAM3D,GACE,CAAC,KAAK,sBAAsBX,CAAW,GACvCW,IAAoB,OAEpBD,EAAmBH,EAAyB,OACzCK,GACCA,EAAI,OAAS,uBAAqB,kBAClCA,EAAI,OAAS,uBAAqB,6BACtC,MACK,CACL,MAAMC,EAAoBN,EAAyB,OAChDK,GACCA,EAAI,OAAS,uBAAqB,6BACtC,EACAF,EAAmB,CACjB,gBAAiBC,EAAgB,QACjC,2BAA4BA,EAAgB,YAC5C,kBAAAE,EACA,iBAAAJ,CACF,CACF,CAEA,MAAO,CACL,kBAAmBC,EACnB,sBAAAN,EACA,QAASD,EAAO,QAChB,gBAAiBE,CACnB,CACF,CAEQ,sBAAsBL,EAA0C,CACtE,GAAIA,EAAY,mBAAqB,yBAAuB,UAC1D,MAAO,GAGT,GACEA,EAAY,WAAW,OAAS,YAChC,CAAC,mBAAiB,SAASA,EAAY,WAAW,IAAI,EAGtD,MAAM,IAAI,MAAM,iBAAiB,EAGnC,OAAIA,EAAY,gBAAkB,gBAAc,OACvC,MAEF,OAAIA,EAAY,WAAW,QAAS,QAAQ,CACrD,CACF",
6
- "names": ["BuildTransactionContextTask_exports", "__export", "BuildTransactionContextTask", "__toCommonJS", "import_context_module", "import_device_management_kit", "import_semver", "import_plugins", "api", "args", "contextModule", "mapper", "transaction", "options", "challenge", "deviceState", "parsed", "err", "subset", "serializedTransaction", "type", "clearSignContexts", "clearSignContextsSuccess", "context", "transactionEnums", "filteredContexts", "transactionInfo", "ctx", "transactionFields"]
4
+ "sourcesContent": ["import {\n type ClearSignContextSuccess,\n type ClearSignContextSuccessType,\n ClearSignContextType,\n type ContextModule,\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 TransactionOptions } from \"@api/model/TransactionOptions\";\nimport { type TransactionType } from \"@api/model/TransactionType\";\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\";\nimport { type TransactionMapperService } from \"@internal/transaction/service/mapper/TransactionMapperService\";\n\nimport { type GenericContext } from \"./ProvideTransactionGenericContextTask\";\n\nexport type BuildTransactionTaskResult = {\n readonly clearSignContexts: ClearSignContextSuccess[] | GenericContext;\n readonly serializedTransaction: Uint8Array;\n readonly chainId: number;\n readonly transactionType: TransactionType;\n readonly web3Check: ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK> | null;\n};\n\nexport type BuildTransactionContextTaskArgs = {\n readonly contextModule: ContextModule;\n readonly mapper: TransactionMapperService;\n readonly transaction: Uint8Array;\n readonly options: TransactionOptions;\n readonly web3ChecksEnabled: boolean;\n readonly derivationPath: string;\n};\n\nexport class BuildTransactionContextTask {\n constructor(\n private readonly api: InternalApi,\n private readonly args: BuildTransactionContextTaskArgs,\n private readonly getWeb3ChecksFactory = (\n api: InternalApi,\n args: GetWeb3CheckTaskArgs,\n ) => new GetWeb3CheckTask(api, args),\n ) {}\n\n async run(): Promise<BuildTransactionTaskResult> {\n const {\n contextModule,\n mapper,\n transaction,\n options,\n web3ChecksEnabled,\n derivationPath,\n } = this.args;\n const deviceState = this.api.getDeviceSessionState();\n\n // Parse transaction\n const parsed = mapper.mapTransactionToSubset(transaction);\n parsed.ifLeft((err) => {\n throw err;\n });\n const { subset, serializedTransaction, type } = parsed.unsafeCoerce();\n\n // Run the web3checks if needed\n let web3Check: ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK> | null =\n null;\n if (web3ChecksEnabled) {\n web3Check = (\n await this.getWeb3ChecksFactory(this.api, {\n contextModule,\n derivationPath,\n mapper,\n transaction,\n }).run()\n ).web3Check;\n }\n\n // Get challenge\n let challenge: string | undefined = undefined;\n const challengeRes = await this.api.sendCommand(new GetChallengeCommand());\n if (isSuccessCommandResult(challengeRes)) {\n challenge = challengeRes.data.challenge;\n }\n\n // Get the clear sign contexts\n const clearSignContexts = 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 let filteredContexts: ClearSignContextSuccess[] | GenericContext = [];\n const transactionInfo = clearSignContextsSuccess.find(\n (ctx) => ctx.type === ClearSignContextType.TRANSACTION_INFO,\n );\n\n if (transactionInfo && !transactionInfo.certificate) {\n throw new Error(\"Transaction info certificate is missing\");\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) ||\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 } else {\n const transactionFields = clearSignContextsSuccess.filter(\n (ctx) =>\n ctx.type === ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n );\n filteredContexts = {\n transactionInfo: transactionInfo.payload,\n transactionInfoCertificate: transactionInfo.certificate!,\n transactionFields,\n transactionEnums,\n };\n }\n\n return {\n clearSignContexts: filteredContexts,\n serializedTransaction,\n chainId: subset.chainId,\n transactionType: type,\n web3Check,\n };\n }\n\n private supportsGenericParser(deviceState: DeviceSessionState): boolean {\n return new ApplicationChecker(deviceState)\n .withMinVersionExclusive(\"1.14.0\")\n .excludeDeviceModel(DeviceModelId.NANO_S)\n .check();\n }\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAKO,oCACPC,EAKO,2CAIPC,EAAoC,4DACpCC,EAGO,sDACPC,EAAmC,qDAsB5B,MAAMN,CAA4B,CACvC,YACmBO,EACAC,EACAC,EAAuB,CACtCF,EACAC,IACG,IAAI,mBAAiBD,EAAKC,CAAI,EACnC,CANiB,SAAAD,EACA,UAAAC,EACA,0BAAAC,CAIhB,CAEH,MAAM,KAA2C,CAC/C,KAAM,CACJ,cAAAC,EACA,OAAAC,EACA,YAAAC,EACA,QAAAC,EACA,kBAAAC,EACA,eAAAC,CACF,EAAI,KAAK,KACHC,EAAc,KAAK,IAAI,sBAAsB,EAG7CC,EAASN,EAAO,uBAAuBC,CAAW,EACxDK,EAAO,OAAQC,GAAQ,CACrB,MAAMA,CACR,CAAC,EACD,KAAM,CAAE,OAAAC,EAAQ,sBAAAC,EAAuB,KAAAC,CAAK,EAAIJ,EAAO,aAAa,EAGpE,IAAIK,EACF,KACER,IACFQ,GACE,MAAM,KAAK,qBAAqB,KAAK,IAAK,CACxC,cAAAZ,EACA,eAAAK,EACA,OAAAJ,EACA,YAAAC,CACF,CAAC,EAAE,IAAI,GACP,WAIJ,IAAIW,EACJ,MAAMC,EAAe,MAAM,KAAK,IAAI,YAAY,IAAI,qBAAqB,KACrE,0BAAuBA,CAAY,IACrCD,EAAYC,EAAa,KAAK,WAIhC,MAAMC,EAAoB,MAAMf,EAAc,YAAY,CACxD,UAAWa,EACX,OAAQV,EAAQ,OAChB,cAAeG,EAAY,cAC3B,GAAGG,CACL,CAAC,EAKKO,EAEAD,EAAkB,OACrBE,GACCA,EAAQ,OAAS,uBAAqB,OACtCA,EAAQ,OAAS,uBAAqB,IAC1C,EAGMC,EACJH,EAAkB,OACfE,GAAYA,EAAQ,OAAS,uBAAqB,IACrD,EAEF,IAAIE,EAA+D,CAAC,EACpE,MAAMC,EAAkBJ,EAAyB,KAC9CK,GAAQA,EAAI,OAAS,uBAAqB,gBAC7C,EAEA,GAAID,GAAmB,CAACA,EAAgB,YACtC,MAAM,IAAI,MAAM,yCAAyC,EAM3D,GACE,CAAC,KAAK,sBAAsBd,CAAW,GACvCc,IAAoB,OAEpBD,EAAmBH,EAAyB,OACzCK,GACCA,EAAI,OAAS,uBAAqB,kBAClCA,EAAI,OAAS,uBAAqB,6BACtC,MACK,CACL,MAAMC,EAAoBN,EAAyB,OAChDK,GACCA,EAAI,OAAS,uBAAqB,6BACtC,EACAF,EAAmB,CACjB,gBAAiBC,EAAgB,QACjC,2BAA4BA,EAAgB,YAC5C,kBAAAE,EACA,iBAAAJ,CACF,CACF,CAEA,MAAO,CACL,kBAAmBC,EACnB,sBAAAT,EACA,QAASD,EAAO,QAChB,gBAAiBE,EACjB,UAAAC,CACF,CACF,CAEQ,sBAAsBN,EAA0C,CACtE,OAAO,IAAI,qBAAmBA,CAAW,EACtC,wBAAwB,QAAQ,EAChC,mBAAmB,gBAAc,MAAM,EACvC,MAAM,CACX,CACF",
6
+ "names": ["BuildTransactionContextTask_exports", "__export", "BuildTransactionContextTask", "__toCommonJS", "import_context_module", "import_device_management_kit", "import_GetChallengeCommand", "import_GetWeb3CheckTask", "import_ApplicationChecker", "api", "args", "getWeb3ChecksFactory", "contextModule", "mapper", "transaction", "options", "web3ChecksEnabled", "derivationPath", "deviceState", "parsed", "err", "subset", "serializedTransaction", "type", "web3Check", "challenge", "challengeRes", "clearSignContexts", "clearSignContextsSuccess", "context", "transactionEnums", "filteredContexts", "transactionInfo", "ctx", "transactionFields"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var a=require("@ledgerhq/context-module"),e=require("@ledgerhq/device-management-kit"),T=require("ethers"),l=require("purify-ts"),S=require("../../app-binder/constant/plugins"),C=require("../../app-binder/device-action/__test-utils__/makeInternalApi"),u=require("./BuildTransactionContextTask");describe("BuildTransactionContextTask",()=>{const p={getContext:vi.fn(),getContexts:vi.fn(),getTypedDataFilters:vi.fn()},r={mapTransactionToSubset:vi.fn()},x={domain:"domain-name.eth"},y=(0,e.hexaStringToBuffer)(T.Transaction.from({chainId:1n,nonce:0,data:"0x"}).unsignedSerialized),c={keyUsageNumber:1,payload:new Uint8Array([1,2,3])};let d;const o=(0,C.makeDeviceActionInternalApiMock)();beforeEach(()=>{vi.resetAllMocks(),d={contextModule:p,mapper:r,transaction:y,options:x,challenge:"challenge"}}),it("should build the transaction context without clear sign contexts",async()=>{const n=new Uint8Array([1,2,3]),t=[],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:t,serializedTransaction:n,chainId:1,transactionType:0})}),it("should build the transaction context with clear sign contexts",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.NFT,payload:"payload-2"}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:t,serializedTransaction:n,chainId:1,transactionType:2})}),it("should build the transaction context with generic-parser context",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:a.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:e.DeviceModelId.FLEX});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:{transactionInfo:"payload-1",transactionInfoCertificate:c,transactionFields:[t[1],t[3]],transactionEnums:[t[2]]},serializedTransaction:n,chainId:1,transactionType:2})}),it("should build the transaction context with generic-parser context and a plugin instead of Ethereum app",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:a.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:S.ETHEREUM_PLUGINS[0],version:"1.15.0"},deviceModelId:e.DeviceModelId.FLEX});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:{transactionInfo:"payload-1",transactionInfoCertificate:c,transactionFields:[t[1],t[3]],transactionEnums:[t[2]]},serializedTransaction:n,chainId:1,transactionType:2})}),it("should call the mapper with the transaction",async()=>{const n=new Uint8Array([1,2,3]),t=[],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX}),await new u.BuildTransactionContextTask(o,d).run(),expect(r.mapTransactionToSubset).toHaveBeenCalledWith(y)}),it("should call the context module with the correct parameters",async()=>{const n=new Uint8Array([1,2,3]),t=[],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX}),await new u.BuildTransactionContextTask(o,d).run(),expect(p.getContexts).toHaveBeenCalledWith({deviceModelId:e.DeviceModelId.FLEX,challenge:"challenge",domain:"domain-name.eth",...s.subset})}),it("should throw an error if the mapper returns an error",async()=>{const n=new Error("error");r.mapTransactionToSubset.mockReturnValueOnce((0,l.Left)(n)),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX});const t=new u.BuildTransactionContextTask(o,d);await expect(t.run()).rejects.toThrow(n)}),it("should exclude error contexts from the result",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.ERROR,error:new Error("error")},{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.ERROR,error:new Error("error")},{type:a.ClearSignContextType.NFT,payload:"payload-2"}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:[t[1],t[3]],serializedTransaction:n,chainId:1,transactionType:0})}),it("should exclude generic-parser contexts from the result on old apps",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"transaction_info",certificate:c},{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:a.ClearSignContextType.NFT,payload:"payload-2"},{type:a.ClearSignContextType.ENUM,payload:"enum",id:1,value:2,certificate:c}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:[t[1],t[3]],serializedTransaction:n,chainId:1,transactionType:0})}),it("should exclude generic-parser contexts from the result if no transaction_info was found",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.ENUM,payload:"enum",id:1,value:2},{type:a.ClearSignContextType.NFT,payload:"payload-2"}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:e.DeviceModelId.FLEX});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:[t[1],t[3]],serializedTransaction:n,chainId:1,transactionType:0})}),it("should exclude legacy contexts from the result for generic-parser transactions",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:c},{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"payload-3"},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"},{type:a.ClearSignContextType.ENUM,payload:"payload-5",id:1,value:2,certificate:c}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:e.DeviceModelId.FLEX});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:{transactionInfo:"payload-2",transactionInfoCertificate:c,transactionFields:[t[3]],transactionEnums:[t[4]]},serializedTransaction:n,chainId:1,transactionType:2})}),it("should exclude generic-parser contexts with a nano s device",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:a.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:c}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:e.DeviceModelId.NANO_S});const i=await new u.BuildTransactionContextTask(o,{...d,challenge:null}).run();expect(i).toEqual({clearSignContexts:[t[0]],serializedTransaction:n,chainId:1,transactionType:2})}),it("should exclude generic-parser contexts with an old app version",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:a.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:c}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX});const i=await new u.BuildTransactionContextTask(o,{...d,challenge:null}).run();expect(i).toEqual({clearSignContexts:[t[0]],serializedTransaction:n,chainId:1,transactionType:2})}),it("should exclude generic-parser contexts with a non ready device",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:a.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:c}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.Connected,deviceStatus:e.DeviceStatus.NOT_CONNECTED,deviceModelId:e.DeviceModelId.FLEX});const i=await new u.BuildTransactionContextTask(o,{...d,challenge:null}).run();expect(i).toEqual({clearSignContexts:[t[0]],serializedTransaction:n,chainId:1,transactionType:2})}),it("should throw an error if the app is not ethereum compatible",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:a.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:c}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Not Ethereum Compatible",version:"1.14.0"},deviceModelId:e.DeviceModelId.FLEX});const i=new u.BuildTransactionContextTask(o,d);await expect(i.run()).rejects.toThrow("Unsupported app")}),it("should return an error if the transaction info certificate is missing",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:a.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:e.DeviceModelId.FLEX});const i=new u.BuildTransactionContextTask(o,d);await expect(i.run()).rejects.toThrow("Transaction info certificate is missing")})});
1
+ "use strict";var a=require("@ledgerhq/context-module"),e=require("@ledgerhq/device-management-kit"),T=require("ethers"),u=require("purify-ts"),x=require("../../app-binder/device-action/__test-utils__/makeInternalApi"),p=require("./BuildTransactionContextTask");describe("BuildTransactionContextTask",()=>{const r={getContext:vi.fn(),getContexts:vi.fn(),getTypedDataFilters:vi.fn(),getWeb3Checks:vi.fn()},l={mapTransactionToSubset:vi.fn()},m={domain:"domain-name.eth"},C=(0,e.hexaStringToBuffer)(T.Transaction.from({chainId:1n,nonce:0,data:"0x"}).unsignedSerialized),y={keyUsageNumber:1,payload:new Uint8Array([1,2,3])};let d;const o=(0,x.makeDeviceActionInternalApiMock)(),i=vi.fn();beforeEach(()=>{vi.resetAllMocks(),o.sendCommand.mockResolvedValue((0,e.CommandResultFactory)({data:{challenge:"challenge"}})),i.mockReturnValue({run:async()=>({web3Check:null})}),d={contextModule:r,mapper:l,transaction:C,options:m,web3ChecksEnabled:!1,derivationPath:"44'/60'/0'/0/0"}}),it("should build the transaction context without clear sign contexts",async()=>{const n=new Uint8Array([1,2,3]),t=[],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};l.mapTransactionToSubset.mockReturnValueOnce((0,u.Right)(s)),r.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const c=await new p.BuildTransactionContextTask(o,{...d,web3ChecksEnabled:!0},i).run();expect(c).toEqual({clearSignContexts:t,serializedTransaction:n,chainId:1,transactionType:0,web3Check:null})}),it("should build the transaction context with web3checks",async()=>{const n=new Uint8Array([1,2,3]),t=[],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0},c="web3Check";i.mockReturnValueOnce({run:async()=>({web3Check:c})}),l.mapTransactionToSubset.mockReturnValueOnce((0,u.Right)(s)),r.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const S=await new p.BuildTransactionContextTask(o,{...d,web3ChecksEnabled:!0},i).run();expect(S).toEqual({clearSignContexts:t,serializedTransaction:n,chainId:1,transactionType:0,web3Check:c})}),it("should build the transaction context with clear sign contexts",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.NFT,payload:"payload-2"}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2},c="web3Check";i.mockReturnValueOnce({run:async()=>({web3Check:c})}),l.mapTransactionToSubset.mockReturnValueOnce((0,u.Right)(s)),r.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const S=await new p.BuildTransactionContextTask(o,d,i).run();expect(S).toEqual({clearSignContexts:t,serializedTransaction:n,chainId:1,transactionType:2,web3Check:null})}),it("should build the transaction context with generic-parser context",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:y},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:a.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:y},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};l.mapTransactionToSubset.mockReturnValueOnce((0,u.Right)(s)),r.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const c=await new p.BuildTransactionContextTask(o,d,i).run();expect(c).toEqual({clearSignContexts:{transactionInfo:"payload-1",transactionInfoCertificate:y,transactionFields:[t[1],t[3]],transactionEnums:[t[2]]},serializedTransaction:n,chainId:1,transactionType:2,web3Check:null})}),it("should call the mapper with the transaction",async()=>{const n=new Uint8Array([1,2,3]),t=[],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};l.mapTransactionToSubset.mockReturnValueOnce((0,u.Right)(s)),r.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),await new p.BuildTransactionContextTask(o,d,i).run(),expect(l.mapTransactionToSubset).toHaveBeenCalledWith(C)}),it("should call the web3checks factory with correct parameters",async()=>{const n=new Uint8Array([1,2,3]),t=[],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};l.mapTransactionToSubset.mockReturnValueOnce((0,u.Right)(s)),r.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),await new p.BuildTransactionContextTask(o,{...d,web3ChecksEnabled:!0},i).run(),expect(i).toHaveBeenCalledWith(o,{contextModule:r,derivationPath:"44'/60'/0'/0/0",mapper:l,transaction:C})}),it("should call the context module with the correct parameters",async()=>{const n=new Uint8Array([1,2,3]),t=[],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};l.mapTransactionToSubset.mockReturnValueOnce((0,u.Right)(s)),r.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),await new p.BuildTransactionContextTask(o,d,i).run(),expect(r.getContexts).toHaveBeenCalledWith({deviceModelId:e.DeviceModelId.FLEX,challenge:"challenge",domain:"domain-name.eth",...s.subset})}),it("should call the context module without context on error",async()=>{const n=new Uint8Array([1,2,3]),t=[],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};l.mapTransactionToSubset.mockReturnValueOnce((0,u.Right)(s)),r.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),o.sendCommand.mockResolvedValueOnce((0,e.CommandResultFactory)({error:new e.UnknownDeviceExchangeError})),await new p.BuildTransactionContextTask(o,d,i).run(),expect(r.getContexts).toHaveBeenCalledWith({deviceModelId:e.DeviceModelId.FLEX,challenge:void 0,domain:"domain-name.eth",...s.subset})}),it("should throw an error if the mapper returns an error",async()=>{const n=new Error("error");l.mapTransactionToSubset.mockReturnValueOnce((0,u.Left)(n)),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const t=new p.BuildTransactionContextTask(o,d,i);await expect(t.run()).rejects.toThrow(n)}),it("should exclude error contexts from the result",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.ERROR,error:new Error("error")},{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.ERROR,error:new Error("error")},{type:a.ClearSignContextType.NFT,payload:"payload-2"}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};l.mapTransactionToSubset.mockReturnValueOnce((0,u.Right)(s)),r.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const c=await new p.BuildTransactionContextTask(o,d,i).run();expect(c).toEqual({clearSignContexts:[t[1],t[3]],serializedTransaction:n,chainId:1,transactionType:0,web3Check:null})}),it("should exclude generic-parser contexts from the result on old apps",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"transaction_info",certificate:y},{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:a.ClearSignContextType.NFT,payload:"payload-2"},{type:a.ClearSignContextType.ENUM,payload:"enum",id:1,value:2,certificate:y}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};l.mapTransactionToSubset.mockReturnValueOnce((0,u.Right)(s)),r.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const c=await new p.BuildTransactionContextTask(o,d,i).run();expect(c).toEqual({clearSignContexts:[t[1],t[3]],serializedTransaction:n,chainId:1,transactionType:0,web3Check:null})}),it("should exclude generic-parser contexts from the result if no transaction_info was found",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.ENUM,payload:"enum",id:1,value:2},{type:a.ClearSignContextType.NFT,payload:"payload-2"}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};l.mapTransactionToSubset.mockReturnValueOnce((0,u.Right)(s)),r.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const c=await new p.BuildTransactionContextTask(o,d,i).run();expect(c).toEqual({clearSignContexts:[t[1],t[3]],serializedTransaction:n,chainId:1,transactionType:0,web3Check:null})}),it("should exclude legacy contexts from the result for generic-parser transactions",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:y},{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"payload-3"},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"},{type:a.ClearSignContextType.ENUM,payload:"payload-5",id:1,value:2,certificate:y}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};l.mapTransactionToSubset.mockReturnValueOnce((0,u.Right)(s)),r.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const c=await new p.BuildTransactionContextTask(o,d,i).run();expect(c).toEqual({clearSignContexts:{transactionInfo:"payload-2",transactionInfoCertificate:y,transactionFields:[t[3]],transactionEnums:[t[4]]},serializedTransaction:n,chainId:1,transactionType:2,web3Check:null})}),it("should exclude generic-parser contexts with a nano s device",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:y},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:a.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:y}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};l.mapTransactionToSubset.mockReturnValueOnce((0,u.Right)(s)),r.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:e.DeviceModelId.NANO_S,isSecureConnectionAllowed:!1});const c=await new p.BuildTransactionContextTask(o,d,i).run();expect(c).toEqual({clearSignContexts:[t[0]],serializedTransaction:n,chainId:1,transactionType:2,web3Check:null})}),it("should exclude generic-parser contexts with an old app version",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:y},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:a.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:y}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};l.mapTransactionToSubset.mockReturnValueOnce((0,u.Right)(s)),r.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const c=await new p.BuildTransactionContextTask(o,d,i).run();expect(c).toEqual({clearSignContexts:[t[0]],serializedTransaction:n,chainId:1,transactionType:2,web3Check:null})}),it("should exclude generic-parser contexts with a non ready device",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:y},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:a.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:y}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};l.mapTransactionToSubset.mockReturnValueOnce((0,u.Right)(s)),r.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.Connected,deviceStatus:e.DeviceStatus.NOT_CONNECTED,deviceModelId:e.DeviceModelId.FLEX});const c=await new p.BuildTransactionContextTask(o,d,i).run();expect(c).toEqual({clearSignContexts:[t[0]],serializedTransaction:n,chainId:1,transactionType:2,web3Check:null})}),it("should return an error if the transaction info certificate is missing",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:a.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};l.mapTransactionToSubset.mockReturnValueOnce((0,u.Right)(s)),r.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const c=new p.BuildTransactionContextTask(o,d,i);await expect(c.run()).rejects.toThrow("Transaction info certificate is missing")})});
2
2
  //# sourceMappingURL=BuildTransactionContextTask.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/internal/app-binder/task/BuildTransactionContextTask.test.ts"],
4
- "sourcesContent": ["import {\n type ClearSignContext,\n ClearSignContextType,\n type PkiCertificate,\n} from \"@ledgerhq/context-module\";\nimport {\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n hexaStringToBuffer,\n} from \"@ledgerhq/device-management-kit\";\nimport { Transaction } from \"ethers\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { ETHEREUM_PLUGINS } from \"@internal/app-binder/constant/plugins\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\nimport { type TransactionMapperResult } from \"@internal/transaction/service/mapper/model/TransactionMapperResult\";\nimport { type TransactionMapperService } from \"@internal/transaction/service/mapper/TransactionMapperService\";\n\nimport {\n BuildTransactionContextTask,\n type BuildTransactionContextTaskArgs,\n} from \"./BuildTransactionContextTask\";\n\ndescribe(\"BuildTransactionContextTask\", () => {\n const contextModuleMock = {\n getContext: vi.fn(),\n getContexts: vi.fn(),\n getTypedDataFilters: vi.fn(),\n };\n const mapperMock = {\n mapTransactionToSubset: vi.fn(),\n };\n const defaultOptions = {\n domain: \"domain-name.eth\",\n };\n const defaultTransaction: Uint8Array = hexaStringToBuffer(\n Transaction.from({\n chainId: 1n,\n nonce: 0,\n data: \"0x\",\n }).unsignedSerialized,\n )!;\n const defaultCertificate: PkiCertificate = {\n keyUsageNumber: 1,\n payload: new Uint8Array([0x01, 0x02, 0x03]),\n };\n\n let defaultArgs: BuildTransactionContextTaskArgs;\n const apiMock = makeDeviceActionInternalApiMock();\n\n beforeEach(() => {\n vi.resetAllMocks();\n\n defaultArgs = {\n contextModule: contextModuleMock,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction: defaultTransaction,\n options: defaultOptions,\n challenge: \"challenge\",\n };\n });\n\n it(\"should build the transaction context without clear sign contexts\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n serializedTransaction,\n chainId: 1,\n transactionType: 0,\n });\n });\n\n it(\"should build the transaction context with clear sign contexts\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n });\n });\n\n it(\"should build the transaction context with generic-parser context\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: {\n transactionInfo: \"payload-1\",\n transactionInfoCertificate: defaultCertificate,\n transactionFields: [clearSignContexts[1], clearSignContexts[3]],\n transactionEnums: [clearSignContexts[2]],\n },\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n });\n });\n\n it(\"should build the transaction context with generic-parser context and a plugin instead of Ethereum app\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: ETHEREUM_PLUGINS[0]!, version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: {\n transactionInfo: \"payload-1\",\n transactionInfoCertificate: defaultCertificate,\n transactionFields: [clearSignContexts[1], clearSignContexts[3]],\n transactionEnums: [clearSignContexts[2]],\n },\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n });\n });\n\n it(\"should call the mapper with the transaction\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n });\n\n // WHEN\n await new BuildTransactionContextTask(apiMock, defaultArgs).run();\n\n // THEN\n expect(mapperMock.mapTransactionToSubset).toHaveBeenCalledWith(\n defaultTransaction,\n );\n });\n\n it(\"should call the context module with the correct parameters\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n });\n\n // WHEN\n await new BuildTransactionContextTask(apiMock, defaultArgs).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.FLEX,\n challenge: \"challenge\",\n domain: \"domain-name.eth\",\n ...mapperResult.subset,\n });\n });\n\n it(\"should throw an error if the mapper returns an error\", async () => {\n // GIVEN\n const error = new Error(\"error\");\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Left(error));\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n });\n\n // WHEN\n const task = new BuildTransactionContextTask(apiMock, defaultArgs);\n\n // THEN\n await expect(task.run()).rejects.toThrow(error);\n });\n\n it(\"should exclude error contexts from the result\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n serializedTransaction,\n chainId: 1,\n transactionType: 0,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result on old apps\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"transaction_info\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"transaction_field\",\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"enum\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n serializedTransaction,\n chainId: 1,\n transactionType: 0,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result if no transaction_info was found\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"transaction_field\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"enum\",\n id: 1,\n value: 2,\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.14.0\" },\n deviceModelId: DeviceModelId.FLEX,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n serializedTransaction,\n chainId: 1,\n transactionType: 0,\n });\n });\n\n it(\"should exclude legacy contexts from the result for generic-parser transactions\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-5\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: {\n transactionInfo: \"payload-2\",\n transactionInfoCertificate: defaultCertificate,\n transactionFields: [clearSignContexts[3]],\n transactionEnums: [clearSignContexts[4]],\n },\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n });\n });\n\n it(\"should exclude generic-parser contexts with a nano s device\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.14.0\" },\n deviceModelId: DeviceModelId.NANO_S,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(apiMock, {\n ...defaultArgs,\n challenge: null,\n }).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n });\n });\n\n it(\"should exclude generic-parser contexts with an old app version\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(apiMock, {\n ...defaultArgs,\n challenge: null,\n }).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n });\n });\n\n it(\"should exclude generic-parser contexts with a non ready device\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.NOT_CONNECTED,\n deviceModelId: DeviceModelId.FLEX,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(apiMock, {\n ...defaultArgs,\n challenge: null,\n }).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n });\n });\n\n it(\"should throw an error if the app is not ethereum compatible\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Not Ethereum Compatible\", version: \"1.14.0\" },\n deviceModelId: DeviceModelId.FLEX,\n });\n\n // WHEN\n const task = new BuildTransactionContextTask(apiMock, defaultArgs);\n\n // THEN\n await expect(task.run()).rejects.toThrow(\"Unsupported app\");\n });\n\n it(\"should return an error if the transaction info certificate is missing\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.14.0\" },\n deviceModelId: DeviceModelId.FLEX,\n });\n\n // WHEN\n const task = new BuildTransactionContextTask(apiMock, defaultArgs);\n\n // THEN\n await expect(task.run()).rejects.toThrow(\n \"Transaction info certificate is missing\",\n );\n });\n});\n"],
5
- "mappings": "aAAA,IAAAA,EAIO,oCACPC,EAKO,2CACPC,EAA4B,kBAC5BC,EAA4B,qBAE5BC,EAAiC,iDACjCC,EAAgD,6EAIhDC,EAGO,yCAEP,SAAS,8BAA+B,IAAM,CAC5C,MAAMC,EAAoB,CACxB,WAAY,GAAG,GAAG,EAClB,YAAa,GAAG,GAAG,EACnB,oBAAqB,GAAG,GAAG,CAC7B,EACMC,EAAa,CACjB,uBAAwB,GAAG,GAAG,CAChC,EACMC,EAAiB,CACrB,OAAQ,iBACV,EACMC,KAAiC,sBACrC,cAAY,KAAK,CACf,QAAS,GACT,MAAO,EACP,KAAM,IACR,CAAC,EAAE,kBACL,EACMC,EAAqC,CACzC,eAAgB,EAChB,QAAS,IAAI,WAAW,CAAC,EAAM,EAAM,CAAI,CAAC,CAC5C,EAEA,IAAIC,EACJ,MAAMC,KAAU,mCAAgC,EAEhD,WAAW,IAAM,CACf,GAAG,cAAc,EAEjBD,EAAc,CACZ,cAAeL,EACf,OAAQC,EACR,YAAaE,EACb,QAASD,EACT,UAAW,WACb,CACF,CAAC,EAED,GAAG,mEAAoE,SAAY,CAEjF,MAAMK,EAAwB,IAAI,WAAW,CAAC,EAAM,EAAM,CAAI,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EACJ,MAAO,CACT,CACF,EACMC,EAAwC,CAC5C,OAAQ,CAAE,QAAS,EAAG,GAAI,OAAW,KAAM,IAAK,EAChD,sBAAAF,EACA,KAAM,CACR,EACAN,EAAW,uBAAuB,uBAAoB,SAAMQ,CAAY,CAAC,EACzET,EAAkB,YAAY,sBAAsBQ,CAAiB,EACrEF,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkB,yBAAuB,0BACzC,aAAc,eAAa,UAC3B,cAAe,CAAC,EAChB,WAAY,CAAE,KAAM,WAAY,QAAS,QAAS,EAClD,cAAe,gBAAc,IAC/B,CAAC,EAGD,MAAMM,EAAO,IAAI,8BAA4BN,EAASD,CAAW,EAGjE,MAAM,OAAOO,EAAK,IAAI,CAAC,EAAE,QAAQ,QAC/B,yCACF,CACF,CAAC,CACH,CAAC",
6
- "names": ["import_context_module", "import_device_management_kit", "import_ethers", "import_purify_ts", "import_plugins", "import_makeInternalApi", "import_BuildTransactionContextTask", "contextModuleMock", "mapperMock", "defaultOptions", "defaultTransaction", "defaultCertificate", "defaultArgs", "apiMock", "serializedTransaction", "clearSignContexts", "mapperResult", "result", "error", "task"]
4
+ "sourcesContent": ["import {\n type ClearSignContext,\n type ClearSignContextSuccess,\n ClearSignContextType,\n type PkiCertificate,\n} from \"@ledgerhq/context-module\";\nimport {\n CommandResultFactory,\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n hexaStringToBuffer,\n UnknownDeviceExchangeError,\n} from \"@ledgerhq/device-management-kit\";\nimport { Transaction } from \"ethers\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\nimport { type TransactionMapperResult } from \"@internal/transaction/service/mapper/model/TransactionMapperResult\";\nimport { type TransactionMapperService } from \"@internal/transaction/service/mapper/TransactionMapperService\";\n\nimport {\n BuildTransactionContextTask,\n type BuildTransactionContextTaskArgs,\n} from \"./BuildTransactionContextTask\";\n\ndescribe(\"BuildTransactionContextTask\", () => {\n const contextModuleMock = {\n getContext: vi.fn(),\n getContexts: vi.fn(),\n getTypedDataFilters: vi.fn(),\n getWeb3Checks: vi.fn(),\n };\n const mapperMock = {\n mapTransactionToSubset: vi.fn(),\n };\n const defaultOptions = {\n domain: \"domain-name.eth\",\n };\n const defaultTransaction: Uint8Array = hexaStringToBuffer(\n Transaction.from({\n chainId: 1n,\n nonce: 0,\n data: \"0x\",\n }).unsignedSerialized,\n )!;\n const defaultCertificate: PkiCertificate = {\n keyUsageNumber: 1,\n payload: new Uint8Array([0x01, 0x02, 0x03]),\n };\n\n let defaultArgs: BuildTransactionContextTaskArgs;\n const apiMock = makeDeviceActionInternalApiMock();\n const getWeb3ChecksFactoryMock = vi.fn();\n\n beforeEach(() => {\n vi.resetAllMocks();\n apiMock.sendCommand.mockResolvedValue(\n CommandResultFactory({ data: { challenge: \"challenge\" } }),\n );\n getWeb3ChecksFactoryMock.mockReturnValue({\n run: async () => ({ web3Check: null }),\n });\n\n defaultArgs = {\n contextModule: contextModuleMock,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction: defaultTransaction,\n options: defaultOptions,\n web3ChecksEnabled: false,\n derivationPath: \"44'/60'/0'/0/0\",\n };\n });\n\n it(\"should build the transaction context without clear sign contexts\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n { ...defaultArgs, web3ChecksEnabled: true },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n serializedTransaction,\n chainId: 1,\n transactionType: 0,\n web3Check: null,\n });\n });\n\n it(\"should build the transaction context with web3checks\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n const expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => ({ web3Check: expectedWeb3Check }),\n });\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n { ...defaultArgs, web3ChecksEnabled: true },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n serializedTransaction,\n chainId: 1,\n transactionType: 0,\n web3Check: expectedWeb3Check,\n });\n });\n\n it(\"should build the transaction context with clear sign contexts\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n const expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => ({ web3Check: expectedWeb3Check }),\n });\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n web3Check: null,\n });\n });\n\n it(\"should build the transaction context with generic-parser context\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: {\n transactionInfo: \"payload-1\",\n transactionInfoCertificate: defaultCertificate,\n transactionFields: [clearSignContexts[1], clearSignContexts[3]],\n transactionEnums: [clearSignContexts[2]],\n },\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n web3Check: null,\n });\n });\n\n it(\"should call the mapper with the transaction\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(mapperMock.mapTransactionToSubset).toHaveBeenCalledWith(\n defaultTransaction,\n );\n });\n\n it(\"should call the web3checks factory with correct parameters\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildTransactionContextTask(\n apiMock,\n { ...defaultArgs, web3ChecksEnabled: true },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(getWeb3ChecksFactoryMock).toHaveBeenCalledWith(apiMock, {\n contextModule: contextModuleMock,\n derivationPath: \"44'/60'/0'/0/0\",\n mapper: mapperMock,\n transaction: defaultTransaction,\n });\n });\n\n it(\"should call the context module with the correct parameters\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.FLEX,\n challenge: \"challenge\",\n domain: \"domain-name.eth\",\n ...mapperResult.subset,\n });\n });\n\n it(\"should call the context module without context on error\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ error: new UnknownDeviceExchangeError() }),\n );\n\n // WHEN\n await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.FLEX,\n challenge: undefined,\n domain: \"domain-name.eth\",\n ...mapperResult.subset,\n });\n });\n\n it(\"should throw an error if the mapper returns an error\", async () => {\n // GIVEN\n const error = new Error(\"error\");\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Left(error));\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const task = new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n );\n\n // THEN\n await expect(task.run()).rejects.toThrow(error);\n });\n\n it(\"should exclude error contexts from the result\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n serializedTransaction,\n chainId: 1,\n transactionType: 0,\n web3Check: null,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result on old apps\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"transaction_info\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"transaction_field\",\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"enum\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n serializedTransaction,\n chainId: 1,\n transactionType: 0,\n web3Check: null,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result if no transaction_info was found\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"transaction_field\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"enum\",\n id: 1,\n value: 2,\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.14.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n serializedTransaction,\n chainId: 1,\n transactionType: 0,\n web3Check: null,\n });\n });\n\n it(\"should exclude legacy contexts from the result for generic-parser transactions\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-5\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: {\n transactionInfo: \"payload-2\",\n transactionInfoCertificate: defaultCertificate,\n transactionFields: [clearSignContexts[3]],\n transactionEnums: [clearSignContexts[4]],\n },\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n web3Check: null,\n });\n });\n\n it(\"should exclude generic-parser contexts with a nano s device\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.14.0\" },\n deviceModelId: DeviceModelId.NANO_S,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n web3Check: null,\n });\n });\n\n it(\"should exclude generic-parser contexts with an old app version\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n web3Check: null,\n });\n });\n\n it(\"should exclude generic-parser contexts with a non ready device\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.NOT_CONNECTED,\n deviceModelId: DeviceModelId.FLEX,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n web3Check: null,\n });\n });\n\n it(\"should return an error if the transaction info certificate is missing\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.14.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const task = new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n );\n\n // THEN\n await expect(task.run()).rejects.toThrow(\n \"Transaction info certificate is missing\",\n );\n });\n});\n"],
5
+ "mappings": "aAAA,IAAAA,EAKO,oCACPC,EAOO,2CACPC,EAA4B,kBAC5BC,EAA4B,qBAE5BC,EAAgD,6EAIhDC,EAGO,yCAEP,SAAS,8BAA+B,IAAM,CAC5C,MAAMC,EAAoB,CACxB,WAAY,GAAG,GAAG,EAClB,YAAa,GAAG,GAAG,EACnB,oBAAqB,GAAG,GAAG,EAC3B,cAAe,GAAG,GAAG,CACvB,EACMC,EAAa,CACjB,uBAAwB,GAAG,GAAG,CAChC,EACMC,EAAiB,CACrB,OAAQ,iBACV,EACMC,KAAiC,sBACrC,cAAY,KAAK,CACf,QAAS,GACT,MAAO,EACP,KAAM,IACR,CAAC,EAAE,kBACL,EACMC,EAAqC,CACzC,eAAgB,EAChB,QAAS,IAAI,WAAW,CAAC,EAAM,EAAM,CAAI,CAAC,CAC5C,EAEA,IAAIC,EACJ,MAAMC,KAAU,mCAAgC,EAC1CC,EAA2B,GAAG,GAAG,EAEvC,WAAW,IAAM,CACf,GAAG,cAAc,EACjBD,EAAQ,YAAY,qBAClB,wBAAqB,CAAE,KAAM,CAAE,UAAW,WAAY,CAAE,CAAC,CAC3D,EACAC,EAAyB,gBAAgB,CACvC,IAAK,UAAa,CAAE,UAAW,IAAK,EACtC,CAAC,EAEDF,EAAc,CACZ,cAAeL,EACf,OAAQC,EACR,YAAaE,EACb,QAASD,EACT,kBAAmB,GACnB,eAAgB,gBAClB,CACF,CAAC,EAED,GAAG,mEAAoE,SAAY,CAEjF,MAAMM,EAAwB,IAAI,WAAW,CAAC,EAAM,EAAM,CAAI,CAAC,EACzDC,EAAwC,CAAC,EACzCC,EAAwC,CAC5C,OAAQ,CAAE,QAAS,EAAG,GAAI,OAAW,KAAM,IAAK,EAChD,sBAAAF,EACA,KAAM,CACR,EACAP,EAAW,uBAAuB,uBAAoB,SAAMS,CAAY,CAAC,EACzEV,EAAkB,YAAY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,sBAAsBS,CAAiB,EACrEH,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkB,yBAAuB,UACzC,aAAc,eAAa,cAC3B,cAAe,gBAAc,IAC/B,CAAC,EAGD,MAAMK,EAAS,MAAM,IAAI,8BACvBL,EACAD,EACAE,CACF,EAAE,IAAI,EAGN,OAAOI,CAAM,EAAE,QAAQ,CACrB,kBAAmB,CAACF,EAAkB,CAAC,CAAC,EACxC,sBAAAD,EACA,QAAS,EACT,gBAAiB,EACjB,UAAW,IACb,CAAC,CACH,CAAC,EAED,GAAG,wEAAyE,SAAY,CAEtF,MAAMA,EAAwB,IAAI,WAAW,CAAC,EAAM,EAAM,CAAI,CAAC,EACzDC,EAAwC,CAC5C,CACE,KAAM,uBAAqB,iBAC3B,QAAS,WACX,EACA,CACE,KAAM,uBAAqB,8BAC3B,QAAS,WACX,EACA,CACE,KAAM,uBAAqB,KAC3B,QAAS,YACT,GAAI,EACJ,MAAO,CACT,CACF,EACMC,EAAwC,CAC5C,OAAQ,CAAE,QAAS,EAAG,GAAI,OAAW,KAAM,IAAK,EAChD,sBAAAF,EACA,KAAM,CACR,EACAP,EAAW,uBAAuB,uBAAoB,SAAMS,CAAY,CAAC,EACzEV,EAAkB,YAAY,sBAAsBS,CAAiB,EACrEH,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkB,yBAAuB,0BACzC,aAAc,eAAa,UAC3B,cAAe,CAAC,EAChB,WAAY,CAAE,KAAM,WAAY,QAAS,QAAS,EAClD,cAAe,gBAAc,KAC7B,0BAA2B,EAC7B,CAAC,EAGD,MAAMQ,EAAO,IAAI,8BACfR,EACAD,EACAE,CACF,EAGA,MAAM,OAAOO,EAAK,IAAI,CAAC,EAAE,QAAQ,QAC/B,yCACF,CACF,CAAC,CACH,CAAC",
6
+ "names": ["import_context_module", "import_device_management_kit", "import_ethers", "import_purify_ts", "import_makeInternalApi", "import_BuildTransactionContextTask", "contextModuleMock", "mapperMock", "defaultOptions", "defaultTransaction", "defaultCertificate", "defaultArgs", "apiMock", "getWeb3ChecksFactoryMock", "serializedTransaction", "clearSignContexts", "mapperResult", "result", "expectedWeb3Check", "error", "task"]
7
7
  }
@@ -0,0 +1,2 @@
1
+ "use strict";var c=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var x=(t,e)=>{for(var a in e)c(t,a,{get:e[a],enumerable:!0})},u=(t,e,a,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of y(e))!g.call(t,r)&&r!==a&&c(t,r,{get:()=>e[r],enumerable:!(s=k(e,r))||s.enumerable});return t};var T=t=>u(c({},"__esModule",{value:!0}),t);var m={};x(m,{GetWeb3CheckTask:()=>b});module.exports=T(m);var C=require("@ledgerhq/context-module"),i=require("@ledgerhq/device-management-kit"),d=require("../../app-binder/command/GetAddressCommand");class b{constructor(e,a){this.api=e;this.args=a}async run(){const e=await this.api.sendCommand(new d.GetAddressCommand({derivationPath:this.args.derivationPath,checkOnDevice:!1,returnChainCode:!1}));if(!(0,i.isSuccessCommandResult)(e))return{web3Check:null,error:e.error};const a=e.data.address,{deviceModelId:s}=this.api.getDeviceSessionState(),{contextModule:r}=this.args;let n;if(this.isRawTx(this.args)){const o=this.args.mapper.mapTransactionToSubset(this.args.transaction);if(o.isRight()){const{subset:l,serializedTransaction:p}=o.extract(),h={deviceModelId:s,from:a,rawTx:(0,i.bufferToHexaString)(p),chainId:l.chainId};n=await r.getWeb3Checks(h)}else throw o.extract()}else{const o={deviceModelId:s,from:a,data:this.args.data};n=await r.getWeb3Checks(o)}return n===null||n?.type!==C.ClearSignContextType.WEB3_CHECK?{web3Check:null}:{web3Check:n}}isRawTx(e){return"transaction"in e}}0&&(module.exports={GetWeb3CheckTask});
2
+ //# sourceMappingURL=GetWeb3CheckTask.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/internal/app-binder/task/GetWeb3CheckTask.ts"],
4
+ "sourcesContent": ["import {\n type ClearSignContext,\n type ClearSignContextSuccess,\n ClearSignContextType,\n type ContextModule,\n type Web3CheckContext,\n} from \"@ledgerhq/context-module\";\nimport {\n bufferToHexaString,\n type DmkError,\n type InternalApi,\n isSuccessCommandResult,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { type TypedData } from \"@api/model/TypedData\";\nimport { GetAddressCommand } from \"@internal/app-binder/command/GetAddressCommand\";\nimport { type TransactionMapperService } from \"@internal/transaction/service/mapper/TransactionMapperService\";\n\nexport type GetWeb3CheckTaskResult =\n | {\n readonly web3Check: ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK> | null;\n }\n | {\n readonly web3Check: null;\n error: DmkError;\n };\n\nexport type GetWeb3CheckTypedDataTaskArgs = {\n readonly contextModule: ContextModule;\n readonly derivationPath: string;\n readonly data: TypedData;\n};\nexport type GetWeb3CheckRawTxTaskArgs = {\n readonly contextModule: ContextModule;\n readonly derivationPath: string;\n readonly mapper: TransactionMapperService;\n readonly transaction: Uint8Array;\n};\nexport type GetWeb3CheckTaskArgs =\n | GetWeb3CheckTypedDataTaskArgs\n | GetWeb3CheckRawTxTaskArgs;\n\nexport class GetWeb3CheckTask {\n constructor(\n private readonly api: InternalApi,\n private readonly args: GetWeb3CheckTaskArgs,\n ) {}\n\n async run(): Promise<GetWeb3CheckTaskResult> {\n // Get sender address\n const getAddressResult = await this.api.sendCommand(\n new GetAddressCommand({\n derivationPath: this.args.derivationPath,\n checkOnDevice: false,\n returnChainCode: false,\n }),\n );\n if (!isSuccessCommandResult(getAddressResult)) {\n return {\n web3Check: null,\n error: getAddressResult.error,\n };\n }\n\n const address = getAddressResult.data.address;\n const { deviceModelId } = this.api.getDeviceSessionState();\n const { contextModule } = this.args;\n let web3CheckContext: ClearSignContext | null;\n\n if (this.isRawTx(this.args)) {\n // Transaction simulation\n const parsed = this.args.mapper.mapTransactionToSubset(\n this.args.transaction,\n );\n if (parsed.isRight()) {\n const { subset, serializedTransaction } = parsed.extract();\n const web3Params: Web3CheckContext = {\n deviceModelId,\n from: address,\n rawTx: bufferToHexaString(serializedTransaction),\n chainId: subset.chainId,\n };\n web3CheckContext = await contextModule.getWeb3Checks(web3Params);\n } else {\n throw parsed.extract();\n }\n } else {\n // Typed data simulation\n const web3Params: Web3CheckContext = {\n deviceModelId,\n from: address,\n data: this.args.data,\n };\n web3CheckContext = await contextModule.getWeb3Checks(web3Params);\n }\n\n if (\n web3CheckContext === null ||\n web3CheckContext?.type !== ClearSignContextType.WEB3_CHECK\n ) {\n return {\n web3Check: null,\n };\n }\n\n return {\n web3Check: web3CheckContext,\n };\n }\n\n private isRawTx(\n args: GetWeb3CheckTaskArgs,\n ): args is GetWeb3CheckRawTxTaskArgs {\n return \"transaction\" in args;\n }\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,sBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAMO,oCACPC,EAKO,2CAGPC,EAAkC,0DA2B3B,MAAMJ,CAAiB,CAC5B,YACmBK,EACAC,EACjB,CAFiB,SAAAD,EACA,UAAAC,CAChB,CAEH,MAAM,KAAuC,CAE3C,MAAMC,EAAmB,MAAM,KAAK,IAAI,YACtC,IAAI,oBAAkB,CACpB,eAAgB,KAAK,KAAK,eAC1B,cAAe,GACf,gBAAiB,EACnB,CAAC,CACH,EACA,GAAI,IAAC,0BAAuBA,CAAgB,EAC1C,MAAO,CACL,UAAW,KACX,MAAOA,EAAiB,KAC1B,EAGF,MAAMC,EAAUD,EAAiB,KAAK,QAChC,CAAE,cAAAE,CAAc,EAAI,KAAK,IAAI,sBAAsB,EACnD,CAAE,cAAAC,CAAc,EAAI,KAAK,KAC/B,IAAIC,EAEJ,GAAI,KAAK,QAAQ,KAAK,IAAI,EAAG,CAE3B,MAAMC,EAAS,KAAK,KAAK,OAAO,uBAC9B,KAAK,KAAK,WACZ,EACA,GAAIA,EAAO,QAAQ,EAAG,CACpB,KAAM,CAAE,OAAAC,EAAQ,sBAAAC,CAAsB,EAAIF,EAAO,QAAQ,EACnDG,EAA+B,CACnC,cAAAN,EACA,KAAMD,EACN,SAAO,sBAAmBM,CAAqB,EAC/C,QAASD,EAAO,OAClB,EACAF,EAAmB,MAAMD,EAAc,cAAcK,CAAU,CACjE,KACE,OAAMH,EAAO,QAAQ,CAEzB,KAAO,CAEL,MAAMG,EAA+B,CACnC,cAAAN,EACA,KAAMD,EACN,KAAM,KAAK,KAAK,IAClB,EACAG,EAAmB,MAAMD,EAAc,cAAcK,CAAU,CACjE,CAEA,OACEJ,IAAqB,MACrBA,GAAkB,OAAS,uBAAqB,WAEzC,CACL,UAAW,IACb,EAGK,CACL,UAAWA,CACb,CACF,CAEQ,QACNL,EACmC,CACnC,MAAO,gBAAiBA,CAC1B,CACF",
6
+ "names": ["GetWeb3CheckTask_exports", "__export", "GetWeb3CheckTask", "__toCommonJS", "import_context_module", "import_device_management_kit", "import_GetAddressCommand", "api", "args", "getAddressResult", "address", "deviceModelId", "contextModule", "web3CheckContext", "parsed", "subset", "serializedTransaction", "web3Params"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var e=require("@ledgerhq/device-management-kit"),r=require("purify-ts"),i=require("../../app-binder/device-action/__test-utils__/makeInternalApi"),s=require("../../app-binder/task/GetWeb3CheckTask");describe("GetWeb3CheckTask",()=>{const a=(0,i.makeDeviceActionInternalApiMock)(),t={getWeb3Checks:vi.fn()},o={mapTransactionToSubset:vi.fn()},d=new Uint8Array([1,2,3,4]),c="44'/60'/0'/0/0";describe("run",()=>{beforeEach(()=>{vi.clearAllMocks(),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.16.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!0})}),describe("errors",()=>{it("should throw an error if mapTransactionToSubset assert.fails",async()=>{const n=new Error("error");a.sendCommand.mockResolvedValueOnce((0,e.CommandResultFactory)({data:{address:"address"}})),o.mapTransactionToSubset.mockReturnValue((0,r.Left)(n));try{await new s.GetWeb3CheckTask(a,{contextModule:t,mapper:o,transaction:d,derivationPath:c}).run(),assert.fail("should throw an error")}catch(u){expect(u).toEqual(n)}}),it("should return a context error if GetAddressCommand assert.fails",async()=>{o.mapTransactionToSubset.mockReturnValue((0,r.Right)({subset:{},serializedTransaction:new Uint8Array})),a.sendCommand.mockResolvedValueOnce((0,e.CommandResultFactory)({error:new e.InvalidStatusWordError("error")}));const n=await new s.GetWeb3CheckTask(a,{contextModule:t,mapper:o,transaction:d,derivationPath:c}).run();expect(n).toEqual({web3Check:null,error:new e.InvalidStatusWordError("error")})}),it("should return null if the type is not a ClearSignContextSuccess web3check",async()=>{o.mapTransactionToSubset.mockReturnValue((0,r.Right)({subset:{},serializedTransaction:new Uint8Array})),a.sendCommand.mockResolvedValueOnce((0,e.CommandResultFactory)({data:{address:"address"}})),t.getWeb3Checks.mockResolvedValue({type:"invalid-type",id:1});const n=await new s.GetWeb3CheckTask(a,{contextModule:t,mapper:o,transaction:d,derivationPath:c}).run();expect(n).toEqual({web3Check:null})})}),describe("success",()=>{it("should return null if the context module does not have a web3 check",async()=>{o.mapTransactionToSubset.mockReturnValue((0,r.Right)({subset:{},serializedTransaction:new Uint8Array})),a.sendCommand.mockResolvedValueOnce((0,e.CommandResultFactory)({data:{address:"address"}})),t.getWeb3Checks.mockResolvedValue(null);const n=await new s.GetWeb3CheckTask(a,{contextModule:t,mapper:o,transaction:d,derivationPath:c}).run();expect(n).toEqual({web3Check:null})}),it("should return a web3 check",async()=>{const n={type:"web3Check",id:1};o.mapTransactionToSubset.mockReturnValue((0,r.Right)({subset:{},serializedTransaction:new Uint8Array})),a.sendCommand.mockResolvedValueOnce((0,e.CommandResultFactory)({data:{address:"address"}})),t.getWeb3Checks.mockResolvedValue(n);const u=await new s.GetWeb3CheckTask(a,{contextModule:t,mapper:o,transaction:d,derivationPath:c}).run();expect(u).toEqual({web3Check:n})}),it("should return a web3 check for typed data",async()=>{const n={type:"web3Check",id:1};a.sendCommand.mockResolvedValueOnce((0,e.CommandResultFactory)({data:{address:"address"}})),t.getWeb3Checks.mockResolvedValue(n);const u=await new s.GetWeb3CheckTask(a,{contextModule:t,data:"typed data",derivationPath:c}).run();expect(u).toEqual({web3Check:n})}),it("should call the context module with the right parameters",async()=>{o.mapTransactionToSubset.mockReturnValue((0,r.Right)({subset:{chainId:15,from:"from"},serializedTransaction:new Uint8Array([1,2,3])})),a.sendCommand.mockResolvedValueOnce((0,e.CommandResultFactory)({data:{address:"address"}})),t.getWeb3Checks.mockResolvedValue(null),await new s.GetWeb3CheckTask(a,{contextModule:t,mapper:o,transaction:d,derivationPath:c}).run(),expect(t.getWeb3Checks).toHaveBeenCalledWith({deviceModelId:e.DeviceModelId.FLEX,from:"address",rawTx:"0x010203",chainId:15})})})})});
2
+ //# sourceMappingURL=GetWeb3CheckTask.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/internal/app-binder/task/GetWeb3CheckTask.test.ts"],
4
+ "sourcesContent": ["import { type ContextModule } from \"@ledgerhq/context-module\";\nimport {\n CommandResultFactory,\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n InvalidStatusWordError,\n} from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type TypedData } from \"@api/model/TypedData\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\nimport { GetWeb3CheckTask } from \"@internal/app-binder/task/GetWeb3CheckTask\";\nimport { type TransactionMapperService } from \"@internal/transaction/service/mapper/TransactionMapperService\";\n\ndescribe(\"GetWeb3CheckTask\", () => {\n const apiMock = makeDeviceActionInternalApiMock();\n const contextModuleMock = {\n getWeb3Checks: vi.fn(),\n };\n const mapperMock = {\n mapTransactionToSubset: vi.fn(),\n };\n const transaction = new Uint8Array([0x01, 0x02, 0x03, 0x04]);\n const derivationPath = \"44'/60'/0'/0/0\";\n\n describe(\"run\", () => {\n beforeEach(() => {\n vi.clearAllMocks();\n\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.16.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: true,\n });\n });\n\n describe(\"errors\", () => {\n it(\"should throw an error if mapTransactionToSubset assert.fails\", async () => {\n // GIVEN\n const error = new Error(\"error\");\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ data: { address: \"address\" } }),\n );\n mapperMock.mapTransactionToSubset.mockReturnValue(Left(error));\n\n // WHEN\n try {\n await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n assert.fail(\"should throw an error\");\n } catch (e) {\n // THEN\n expect(e).toEqual(error);\n }\n });\n\n it(\"should return a context error if GetAddressCommand assert.fails\", async () => {\n // GIVEN\n mapperMock.mapTransactionToSubset.mockReturnValue(\n Right({ subset: {}, serializedTransaction: new Uint8Array() }),\n );\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ error: new InvalidStatusWordError(\"error\") }),\n );\n\n // WHEN\n const result = await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n\n // THEN\n expect(result).toEqual({\n web3Check: null,\n error: new InvalidStatusWordError(\"error\"),\n });\n });\n\n it(\"should return null if the type is not a ClearSignContextSuccess web3check\", async () => {\n // GIVEN\n mapperMock.mapTransactionToSubset.mockReturnValue(\n Right({ subset: {}, serializedTransaction: new Uint8Array() }),\n );\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ data: { address: \"address\" } }),\n );\n contextModuleMock.getWeb3Checks.mockResolvedValue({\n type: \"invalid-type\",\n id: 1,\n });\n\n // WHEN\n const result = await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n\n // THEN\n expect(result).toEqual({\n web3Check: null,\n });\n });\n });\n\n describe(\"success\", () => {\n it(\"should return null if the context module does not have a web3 check\", async () => {\n // GIVEN\n mapperMock.mapTransactionToSubset.mockReturnValue(\n Right({ subset: {}, serializedTransaction: new Uint8Array() }),\n );\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ data: { address: \"address\" } }),\n );\n contextModuleMock.getWeb3Checks.mockResolvedValue(null);\n\n // WHEN\n const result = await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n\n // THEN\n expect(result).toEqual({\n web3Check: null,\n });\n });\n\n it(\"should return a web3 check\", async () => {\n // GIVEN\n const web3Check = { type: \"web3Check\", id: 1 };\n mapperMock.mapTransactionToSubset.mockReturnValue(\n Right({ subset: {}, serializedTransaction: new Uint8Array() }),\n );\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ data: { address: \"address\" } }),\n );\n contextModuleMock.getWeb3Checks.mockResolvedValue(web3Check);\n\n // WHEN\n const result = await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n\n // THEN\n expect(result).toEqual({\n web3Check,\n });\n });\n\n it(\"should return a web3 check for typed data\", async () => {\n // GIVEN\n const web3Check = { type: \"web3Check\", id: 1 };\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ data: { address: \"address\" } }),\n );\n contextModuleMock.getWeb3Checks.mockResolvedValue(web3Check);\n\n // WHEN\n const result = await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n data: \"typed data\" as unknown as TypedData,\n derivationPath,\n }).run();\n\n // THEN\n expect(result).toEqual({\n web3Check,\n });\n });\n\n it(\"should call the context module with the right parameters\", async () => {\n // GIVEN\n mapperMock.mapTransactionToSubset.mockReturnValue(\n Right({\n subset: { chainId: 15, from: \"from\" },\n serializedTransaction: new Uint8Array([0x01, 0x02, 0x03]),\n }),\n );\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ data: { address: \"address\" } }),\n );\n contextModuleMock.getWeb3Checks.mockResolvedValue(null);\n\n // WHEN\n await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n\n // THEN\n expect(contextModuleMock.getWeb3Checks).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.FLEX,\n from: \"address\",\n rawTx: \"0x010203\",\n chainId: 15,\n });\n });\n });\n });\n});\n"],
5
+ "mappings": "aACA,IAAAA,EAMO,2CACPC,EAA4B,qBAG5BC,EAAgD,6EAChDC,EAAiC,sDAGjC,SAAS,mBAAoB,IAAM,CACjC,MAAMC,KAAU,mCAAgC,EAC1CC,EAAoB,CACxB,cAAe,GAAG,GAAG,CACvB,EACMC,EAAa,CACjB,uBAAwB,GAAG,GAAG,CAChC,EACMC,EAAc,IAAI,WAAW,CAAC,EAAM,EAAM,EAAM,CAAI,CAAC,EACrDC,EAAiB,iBAEvB,SAAS,MAAO,IAAM,CACpB,WAAW,IAAM,CACf,GAAG,cAAc,EAEjBJ,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkB,yBAAuB,0BACzC,aAAc,eAAa,UAC3B,cAAe,CAAC,EAChB,WAAY,CAAE,KAAM,WAAY,QAAS,QAAS,EAClD,cAAe,gBAAc,KAC7B,0BAA2B,EAC7B,CAAC,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AAMD,EAAS,MAAM,IAAI,mBAAiBP,EAAS,CACjD,cAAeC,EACf,KAAM,aACN,eAAAG,CACF,CAAC,EAAE,IAAI,EAGP,OAAOG,CAAM,EAAE,QAAQ,CACrB,UAAAC,CACF,CAAC,CACH,CAAC,EAED,GAAG,2DAA4D,SAAY,CAEzEN,EAAW,uBAAuB,mBAChC,SAAM,CACJ,OAAQ,CAAE,QAAS,GAAI,KAAM,MAAO,EACpC,sBAAuB,IAAI,WAAW,CAAC,EAAM,EAAM,CAAI,CAAC,CAC1D,CAAC,CACH,EACAF,EAAQ,YAAY,yBAClB,wBAAqB,CAAE,KAAM,CAAE,QAAS,SAAU,CAAE,CAAC,CACvD,EACAC,EAAkB,cAAc,kBAAkB,IAAI,EAGtD,MAAM,IAAI,mBAAiBD,EAAS,CAClC,cAAeC,EACf,OAAQC,EACR,YAAAC,EACA,eAAAC,CACF,CAAC,EAAE,IAAI,EAGP,OAAOH,EAAkB,aAAa,EAAE,qBAAqB,CAC3D,cAAe,gBAAc,KAC7B,KAAM,UACN,MAAO,WACP,QAAS,EACX,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["import_device_management_kit", "import_purify_ts", "import_makeInternalApi", "import_GetWeb3CheckTask", "apiMock", "contextModuleMock", "mapperMock", "transaction", "derivationPath", "error", "e", "result", "web3Check"]
7
+ }
@@ -1,2 +1,2 @@
1
- "use strict";var I=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var R=Object.prototype.hasOwnProperty;var D=(d,e)=>{for(var n in e)I(d,n,{get:e[n],enumerable:!0})},A=(d,e,n,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of w(e))!R.call(d,t)&&t!==n&&I(d,t,{get:()=>e[t],enumerable:!(a=v(e,t))||a.enumerable});return d};var N=d=>A(I({},"__esModule",{value:!0}),d);var F={};D(F,{ProvideEIP712ContextTask:()=>P});module.exports=N(F);var h=require("@ledgerhq/context-module"),s=require("@ledgerhq/device-management-kit"),l=require("purify-ts"),k=require("../../app-binder/command/ProvideTokenInformationCommand"),i=require("../../app-binder/command/SendEIP712FilteringCommand"),c=require("../../app-binder/command/SendEIP712StructDefinitionCommand"),f=require("../../app-binder/command/SendEIP712StructImplemCommand"),g=require("../../app-binder/task/SendEIP712StructImplemTask"),y=require("../../typed-data/model/Types");const S=5;class P{constructor(e,n){this.api=e;this.args=n}async run(){const e=(0,s.CommandResultFactory)({data:void 0}),n=Object.entries(this.args.types).sort(([t],[o])=>t.localeCompare(o));for(const[t,o]of n){const r=await this.api.sendCommand(new c.SendEIP712StructDefinitionCommand({command:c.StructDefinitionCommand.Name,name:t}));if(!(0,s.isSuccessCommandResult)(r))return r;for(const[p,m]of Object.entries(o)){const x=await this.api.sendCommand(new c.SendEIP712StructDefinitionCommand({command:c.StructDefinitionCommand.Field,name:p,type:m}));if(!(0,s.isSuccessCommandResult)(x))return x}}if(this.args.clearSignContext.isJust()){const t=await this.api.sendCommand(new i.SendEIP712FilteringCommand({type:i.Eip712FilterType.Activation}));if(!(0,s.isSuccessCommandResult)(t))return t}for(const t of this.args.domain){const r=await this.getImplementationTask(t).run();if(!(0,s.isSuccessCommandResult)(r))return r}if(this.args.clearSignContext.isJust()){const t=this.args.clearSignContext.extract(),o=await this.api.sendCommand(new i.SendEIP712FilteringCommand({type:i.Eip712FilterType.MessageInfo,displayName:t.messageInfo.displayName,filtersCount:t.messageInfo.filtersCount,signature:t.messageInfo.signature}));if(!(0,s.isSuccessCommandResult)(o))return o}const a={indexes:{},nextIndex:0};for(const t of this.args.message){const o=await this.provideTokenInformation(t,a);if(o.isJust())return o.extract();const r=await this.filterValue(t,a);if(r.isJust()&&!(0,s.isSuccessCommandResult)(r.extract()))return r.extract();const m=await this.getImplementationTask(t).run();if(!(0,s.isSuccessCommandResult)(m))return m;if(this.args.clearSignContext.isJust()&&t.value instanceof y.TypedDataValueArray&&t.value.length===0){const E=Object.entries(this.args.clearSignContext.extract().filters).filter(([u])=>u.startsWith(`${t.path}.[]`)).map(([,u])=>u);for(const u of E){const C=await this.api.sendCommand(new i.SendEIP712FilteringCommand({type:i.Eip712FilterType.DiscardedPath,path:u.path}));if(!(0,s.isSuccessCommandResult)(C))return C;const T=await this.provideFiltering(u,a,!0);if(!(0,s.isSuccessCommandResult)(T))return T}}}return e}getImplementationTask(e){return e.value instanceof y.TypedDataValueRoot?new g.SendEIP712StructImplemTask(this.api,{type:f.StructImplemType.ROOT,value:e.value.root}):e.value instanceof y.TypedDataValueArray?new g.SendEIP712StructImplemTask(this.api,{type:f.StructImplemType.ARRAY,value:e.value.length}):new g.SendEIP712StructImplemTask(this.api,{type:f.StructImplemType.FIELD,value:e.value.data})}async provideTokenInformation(e,n){if(this.args.clearSignContext.isJust()){const a=this.args.clearSignContext.extract().filters[e.path];if(a!==void 0&&(a.type==="amount"||a.type==="token")&&n.indexes[a.tokenIndex]===void 0){const t=a.tokenIndex,r=this.args.clearSignContext.extract().tokens[t];if(r===void 0)return l.Nothing;const p=await this.api.sendCommand(new k.ProvideTokenInformationCommand({payload:r}));if(!(0,s.isSuccessCommandResult)(p))return l.Maybe.of(p);let{tokenIndex:m}=p.data;n.nextIndex=(m+1)%S,Number(t)===h.VERIFYING_CONTRACT_TOKEN_INDEX&&(m=h.VERIFYING_CONTRACT_TOKEN_INDEX),n.indexes[Number(t)]=m}}return l.Nothing}async filterValue(e,n){if(this.args.clearSignContext.isJust()){const a=this.args.clearSignContext.extract().filters[e.path];if(a===void 0)return l.Nothing;const t=await this.provideFiltering(a,n,!1);return l.Maybe.of(t)}return l.Nothing}async provideFiltering(e,n,a){switch(e.type){case"datetime":return await this.api.sendCommand(new i.SendEIP712FilteringCommand({type:i.Eip712FilterType.Datetime,discarded:a,displayName:e.displayName,signature:e.signature}));case"raw":return await this.api.sendCommand(new i.SendEIP712FilteringCommand({type:i.Eip712FilterType.Raw,discarded:a,displayName:e.displayName,signature:e.signature}));case"token":return this.sanitizeDeviceIndex(e.tokenIndex,n),await this.api.sendCommand(new i.SendEIP712FilteringCommand({type:i.Eip712FilterType.Token,discarded:a,tokenIndex:n.indexes[e.tokenIndex],signature:e.signature}));case"amount":return this.sanitizeDeviceIndex(e.tokenIndex,n),await this.api.sendCommand(new i.SendEIP712FilteringCommand({type:i.Eip712FilterType.Amount,discarded:a,displayName:e.displayName,tokenIndex:n.indexes[e.tokenIndex],signature:e.signature}));default:return(0,s.CommandResultFactory)({error:new s.InvalidStatusWordError("ProvideEIP712ContextTask/provideFiltering - Unhandled filter type")})}}sanitizeDeviceIndex(e,n){n.indexes[e]===void 0&&(n.indexes[e]=n.nextIndex,n.nextIndex=(n.nextIndex+1)%S)}}0&&(module.exports={ProvideEIP712ContextTask});
1
+ "use strict";var h=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var P=(m,e)=>{for(var a in e)h(m,a,{get:e[a],enumerable:!0})},b=(m,e,a,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of R(e))!A.call(m,t)&&t!==a&&h(m,t,{get:()=>e[t],enumerable:!(n=D(e,t))||n.enumerable});return m};var N=m=>b(h({},"__esModule",{value:!0}),m);var V={};P(V,{ProvideEIP712ContextTask:()=>F});module.exports=N(V);var x=require("@ledgerhq/context-module"),s=require("@ledgerhq/device-management-kit"),p=require("purify-ts"),S=require("../../app-binder/command/ProvideTokenInformationCommand"),w=require("../../app-binder/command/ProvideWeb3CheckCommand"),i=require("../../app-binder/command/SendEIP712FilteringCommand"),u=require("../../app-binder/command/SendEIP712StructDefinitionCommand"),f=require("../../app-binder/command/SendEIP712StructImplemCommand"),C=require("../../app-binder/task/SendEIP712StructImplemTask"),y=require("../../typed-data/model/Types"),E=require("./SendPayloadInChunksTask");const k=5;class F{constructor(e,a){this.api=e;this.args=a}async run(){this.args.web3Check&&(this.args.web3Check.certificate&&await this.api.sendCommand(new s.LoadCertificateCommand({keyUsage:this.args.web3Check.certificate.keyUsageNumber,certificate:this.args.web3Check.certificate.payload})),await new E.SendPayloadInChunksTask(this.api,{payload:this.args.web3Check.payload,commandFactory:t=>new w.ProvideWeb3CheckCommand({payload:t.chunkedData,isFirstChunk:t.isFirstChunk})}).run());const e=(0,s.CommandResultFactory)({data:void 0}),a=Object.entries(this.args.types).sort(([t],[o])=>t.localeCompare(o));for(const[t,o]of a){const r=await this.api.sendCommand(new u.SendEIP712StructDefinitionCommand({command:u.StructDefinitionCommand.Name,name:t}));if(!(0,s.isSuccessCommandResult)(r))return r;for(const[l,d]of Object.entries(o)){const g=await this.api.sendCommand(new u.SendEIP712StructDefinitionCommand({command:u.StructDefinitionCommand.Field,name:l,type:d}));if(!(0,s.isSuccessCommandResult)(g))return g}}if(this.args.clearSignContext.isJust()){const t=await this.api.sendCommand(new i.SendEIP712FilteringCommand({type:i.Eip712FilterType.Activation}));if(!(0,s.isSuccessCommandResult)(t))return t}for(const t of this.args.domain){const r=await this.getImplementationTask(t).run();if(!(0,s.isSuccessCommandResult)(r))return r}if(this.args.clearSignContext.isJust()){const t=this.args.clearSignContext.extract(),o=await this.api.sendCommand(new i.SendEIP712FilteringCommand({type:i.Eip712FilterType.MessageInfo,displayName:t.messageInfo.displayName,filtersCount:t.messageInfo.filtersCount,signature:t.messageInfo.signature}));if(!(0,s.isSuccessCommandResult)(o))return o}const n={indexes:{},nextIndex:0};for(const t of this.args.message){const o=await this.provideTokenInformation(t,n);if(o.isJust())return o.extract();const r=await this.filterValue(t,n);if(r.isJust()&&!(0,s.isSuccessCommandResult)(r.extract()))return r.extract();const d=await this.getImplementationTask(t).run();if(!(0,s.isSuccessCommandResult)(d))return d;if(this.args.clearSignContext.isJust()&&t.value instanceof y.TypedDataValueArray&&t.value.length===0){const v=Object.entries(this.args.clearSignContext.extract().filters).filter(([c])=>c.startsWith(`${t.path}.[]`)).map(([,c])=>c);for(const c of v){const I=await this.api.sendCommand(new i.SendEIP712FilteringCommand({type:i.Eip712FilterType.DiscardedPath,path:c.path}));if(!(0,s.isSuccessCommandResult)(I))return I;const T=await this.provideFiltering(c,n,!0);if(!(0,s.isSuccessCommandResult)(T))return T}}}return e}getImplementationTask(e){return e.value instanceof y.TypedDataValueRoot?new C.SendEIP712StructImplemTask(this.api,{type:f.StructImplemType.ROOT,value:e.value.root}):e.value instanceof y.TypedDataValueArray?new C.SendEIP712StructImplemTask(this.api,{type:f.StructImplemType.ARRAY,value:e.value.length}):new C.SendEIP712StructImplemTask(this.api,{type:f.StructImplemType.FIELD,value:e.value.data})}async provideTokenInformation(e,a){if(this.args.clearSignContext.isJust()){const n=this.args.clearSignContext.extract().filters[e.path];if(n!==void 0&&(n.type==="amount"||n.type==="token")&&a.indexes[n.tokenIndex]===void 0){const t=n.tokenIndex,r=this.args.clearSignContext.extract().tokens[t];if(r===void 0)return p.Nothing;const l=await this.api.sendCommand(new S.ProvideTokenInformationCommand({payload:r}));if(!(0,s.isSuccessCommandResult)(l))return p.Maybe.of(l);let{tokenIndex:d}=l.data;a.nextIndex=(d+1)%k,Number(t)===x.VERIFYING_CONTRACT_TOKEN_INDEX&&(d=x.VERIFYING_CONTRACT_TOKEN_INDEX),a.indexes[Number(t)]=d}}return p.Nothing}async filterValue(e,a){if(this.args.clearSignContext.isJust()){const n=this.args.clearSignContext.extract().filters[e.path];if(n===void 0)return p.Nothing;const t=await this.provideFiltering(n,a,!1);return p.Maybe.of(t)}return p.Nothing}async provideFiltering(e,a,n){switch(e.type){case"datetime":return await this.api.sendCommand(new i.SendEIP712FilteringCommand({type:i.Eip712FilterType.Datetime,discarded:n,displayName:e.displayName,signature:e.signature}));case"raw":return await this.api.sendCommand(new i.SendEIP712FilteringCommand({type:i.Eip712FilterType.Raw,discarded:n,displayName:e.displayName,signature:e.signature}));case"token":return this.sanitizeDeviceIndex(e.tokenIndex,a),await this.api.sendCommand(new i.SendEIP712FilteringCommand({type:i.Eip712FilterType.Token,discarded:n,tokenIndex:a.indexes[e.tokenIndex],signature:e.signature}));case"amount":return this.sanitizeDeviceIndex(e.tokenIndex,a),await this.api.sendCommand(new i.SendEIP712FilteringCommand({type:i.Eip712FilterType.Amount,discarded:n,displayName:e.displayName,tokenIndex:a.indexes[e.tokenIndex],signature:e.signature}));default:return(0,s.CommandResultFactory)({error:new s.InvalidStatusWordError("ProvideEIP712ContextTask/provideFiltering - Unhandled filter type")})}}sanitizeDeviceIndex(e,a){a.indexes[e]===void 0&&(a.indexes[e]=a.nextIndex,a.nextIndex=(a.nextIndex+1)%k)}}0&&(module.exports={ProvideEIP712ContextTask});
2
2
  //# sourceMappingURL=ProvideEIP712ContextTask.js.map