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

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 (119) hide show
  1. package/lib/cjs/api/app-binder/SignTransactionDeviceActionTypes.js +1 -1
  2. package/lib/cjs/api/app-binder/SignTransactionDeviceActionTypes.js.map +2 -2
  3. package/lib/cjs/api/app-binder/SignTypedDataDeviceActionTypes.js +1 -1
  4. package/lib/cjs/api/app-binder/SignTypedDataDeviceActionTypes.js.map +2 -2
  5. package/lib/cjs/api/index.js +1 -1
  6. package/lib/cjs/api/index.js.map +3 -3
  7. package/lib/cjs/internal/app-binder/EthAppBinder.js +1 -1
  8. package/lib/cjs/internal/app-binder/EthAppBinder.js.map +2 -2
  9. package/lib/cjs/internal/app-binder/EthAppBinder.test.js +1 -1
  10. package/lib/cjs/internal/app-binder/EthAppBinder.test.js.map +2 -2
  11. package/lib/cjs/internal/app-binder/command/SendEIP712FilteringCommand.js +1 -1
  12. package/lib/cjs/internal/app-binder/command/SendEIP712FilteringCommand.js.map +3 -3
  13. package/lib/cjs/internal/app-binder/command/SendEIP712FilteringCommand.test.js +1 -1
  14. package/lib/cjs/internal/app-binder/command/SendEIP712FilteringCommand.test.js.map +3 -3
  15. package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js +1 -1
  16. package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js.map +3 -3
  17. package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js +1 -1
  18. package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js.map +3 -3
  19. package/lib/cjs/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.js +1 -1
  20. package/lib/cjs/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.js.map +2 -2
  21. package/lib/cjs/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.test.js +1 -1
  22. package/lib/cjs/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.test.js.map +3 -3
  23. package/lib/cjs/internal/app-binder/task/BuildBaseContexts.test.js +1 -1
  24. package/lib/cjs/internal/app-binder/task/BuildBaseContexts.test.js.map +2 -2
  25. package/lib/cjs/internal/app-binder/task/BuildEIP712ContextTask.js +1 -1
  26. package/lib/cjs/internal/app-binder/task/BuildEIP712ContextTask.js.map +3 -3
  27. package/lib/cjs/internal/app-binder/task/BuildEIP712ContextTask.test.js +1 -1
  28. package/lib/cjs/internal/app-binder/task/BuildEIP712ContextTask.test.js.map +3 -3
  29. package/lib/cjs/internal/app-binder/task/BuildFullContextsTask.js +1 -1
  30. package/lib/cjs/internal/app-binder/task/BuildFullContextsTask.js.map +2 -2
  31. package/lib/cjs/internal/app-binder/task/BuildFullContextsTask.test.js +1 -1
  32. package/lib/cjs/internal/app-binder/task/BuildFullContextsTask.test.js.map +2 -2
  33. package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.js +1 -1
  34. package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.js.map +3 -3
  35. package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.test.js +1 -1
  36. package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.test.js.map +3 -3
  37. package/lib/cjs/internal/app-binder/task/ParseTransactionTask.test.js +2 -0
  38. package/lib/cjs/internal/app-binder/task/ParseTransactionTask.test.js.map +7 -0
  39. package/lib/cjs/internal/app-binder/task/ProvideContextsTask.js +1 -1
  40. package/lib/cjs/internal/app-binder/task/ProvideContextsTask.js.map +2 -2
  41. package/lib/cjs/internal/app-binder/task/ProvideContextsTask.test.js +1 -1
  42. package/lib/cjs/internal/app-binder/task/ProvideContextsTask.test.js.map +2 -2
  43. package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.js +1 -1
  44. package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.js.map +3 -3
  45. package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.test.js +1 -1
  46. package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.test.js.map +3 -3
  47. package/lib/cjs/package.json +1 -1
  48. package/lib/esm/api/app-binder/SignTransactionDeviceActionTypes.js +1 -1
  49. package/lib/esm/api/app-binder/SignTransactionDeviceActionTypes.js.map +2 -2
  50. package/lib/esm/api/app-binder/SignTypedDataDeviceActionTypes.js +1 -1
  51. package/lib/esm/api/app-binder/SignTypedDataDeviceActionTypes.js.map +2 -2
  52. package/lib/esm/api/index.js +1 -1
  53. package/lib/esm/api/index.js.map +2 -2
  54. package/lib/esm/internal/app-binder/EthAppBinder.js +1 -1
  55. package/lib/esm/internal/app-binder/EthAppBinder.js.map +2 -2
  56. package/lib/esm/internal/app-binder/EthAppBinder.test.js +1 -1
  57. package/lib/esm/internal/app-binder/EthAppBinder.test.js.map +2 -2
  58. package/lib/esm/internal/app-binder/command/SendEIP712FilteringCommand.js +1 -1
  59. package/lib/esm/internal/app-binder/command/SendEIP712FilteringCommand.js.map +3 -3
  60. package/lib/esm/internal/app-binder/command/SendEIP712FilteringCommand.test.js +1 -1
  61. package/lib/esm/internal/app-binder/command/SendEIP712FilteringCommand.test.js.map +3 -3
  62. package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js +1 -1
  63. package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js.map +3 -3
  64. package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js +1 -1
  65. package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js.map +3 -3
  66. package/lib/esm/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.js +1 -1
  67. package/lib/esm/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.js.map +2 -2
  68. package/lib/esm/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.test.js +1 -1
  69. package/lib/esm/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.test.js.map +3 -3
  70. package/lib/esm/internal/app-binder/task/BuildBaseContexts.test.js +1 -1
  71. package/lib/esm/internal/app-binder/task/BuildBaseContexts.test.js.map +2 -2
  72. package/lib/esm/internal/app-binder/task/BuildEIP712ContextTask.js +1 -1
  73. package/lib/esm/internal/app-binder/task/BuildEIP712ContextTask.js.map +3 -3
  74. package/lib/esm/internal/app-binder/task/BuildEIP712ContextTask.test.js +1 -1
  75. package/lib/esm/internal/app-binder/task/BuildEIP712ContextTask.test.js.map +3 -3
  76. package/lib/esm/internal/app-binder/task/BuildFullContextsTask.js +1 -1
  77. package/lib/esm/internal/app-binder/task/BuildFullContextsTask.js.map +2 -2
  78. package/lib/esm/internal/app-binder/task/BuildFullContextsTask.test.js +1 -1
  79. package/lib/esm/internal/app-binder/task/BuildFullContextsTask.test.js.map +2 -2
  80. package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.js +1 -1
  81. package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.js.map +2 -2
  82. package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.test.js +1 -1
  83. package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.test.js.map +2 -2
  84. package/lib/esm/internal/app-binder/task/ParseTransactionTask.test.js +2 -0
  85. package/lib/esm/internal/app-binder/task/ParseTransactionTask.test.js.map +7 -0
  86. package/lib/esm/internal/app-binder/task/ProvideContextsTask.js +1 -1
  87. package/lib/esm/internal/app-binder/task/ProvideContextsTask.js.map +2 -2
  88. package/lib/esm/internal/app-binder/task/ProvideContextsTask.test.js +1 -1
  89. package/lib/esm/internal/app-binder/task/ProvideContextsTask.test.js.map +2 -2
  90. package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.js +1 -1
  91. package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.js.map +3 -3
  92. package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.test.js +1 -1
  93. package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.test.js.map +3 -3
  94. package/lib/esm/package.json +1 -1
  95. package/lib/types/api/app-binder/SignTransactionDeviceActionTypes.d.ts +2 -1
  96. package/lib/types/api/app-binder/SignTransactionDeviceActionTypes.d.ts.map +1 -1
  97. package/lib/types/api/app-binder/SignTypedDataDeviceActionTypes.d.ts +4 -0
  98. package/lib/types/api/app-binder/SignTypedDataDeviceActionTypes.d.ts.map +1 -1
  99. package/lib/types/api/index.d.ts +5 -9
  100. package/lib/types/api/index.d.ts.map +1 -1
  101. package/lib/types/internal/app-binder/EthAppBinder.d.ts.map +1 -1
  102. package/lib/types/internal/app-binder/command/SendEIP712FilteringCommand.d.ts +29 -1
  103. package/lib/types/internal/app-binder/command/SendEIP712FilteringCommand.d.ts.map +1 -1
  104. package/lib/types/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.d.ts +1 -1
  105. package/lib/types/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.d.ts.map +1 -1
  106. package/lib/types/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.d.ts +4 -0
  107. package/lib/types/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.d.ts.map +1 -1
  108. package/lib/types/internal/app-binder/task/BuildEIP712ContextTask.d.ts +8 -1
  109. package/lib/types/internal/app-binder/task/BuildEIP712ContextTask.d.ts.map +1 -1
  110. package/lib/types/internal/app-binder/task/BuildFullContextsTask.d.ts.map +1 -1
  111. package/lib/types/internal/app-binder/task/BuildSubcontextsTask.d.ts.map +1 -1
  112. package/lib/types/internal/app-binder/task/ParseTransactionTask.test.d.ts +2 -0
  113. package/lib/types/internal/app-binder/task/ParseTransactionTask.test.d.ts.map +1 -0
  114. package/lib/types/internal/app-binder/task/ProvideContextsTask.d.ts +3 -1
  115. package/lib/types/internal/app-binder/task/ProvideContextsTask.d.ts.map +1 -1
  116. package/lib/types/internal/app-binder/task/ProvideEIP712ContextTask.d.ts +12 -2
  117. package/lib/types/internal/app-binder/task/ProvideEIP712ContextTask.d.ts.map +1 -1
  118. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  119. package/package.json +8 -8
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/internal/app-binder/task/BuildBaseContexts.test.ts"],
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\";\n\nimport type { GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\nimport { ClearSigningType } from \"@api/model/ClearSigningType\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\n\nimport {\n BuildBaseContexts,\n type BuildBaseContextsArgs,\n} from \"./BuildBaseContexts\";\nimport { GetWeb3CheckTask } from \"./GetWeb3CheckTask\";\n\ndescribe(\"BuildBaseContexts\", () => {\n const contextModuleMock = {\n getFieldContext: vi.fn(),\n getContexts: vi.fn(),\n getTypedDataFilters: vi.fn(),\n getWeb3Checks: vi.fn(),\n getSolanaContext: vi.fn(),\n getProxyDelegateCall: vi.fn(),\n };\n const 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: BuildBaseContextsArgs;\n const apiMock = makeDeviceActionInternalApiMock();\n const getWeb3ChecksFactoryMock = vi.fn();\n\n function createAppConfig(\n web3ChecksEnabled: boolean,\n ): GetConfigCommandResponse {\n return {\n blindSigningEnabled: false,\n web3ChecksEnabled,\n web3ChecksOptIn: false,\n version: \"1.13.0\",\n };\n }\n\n beforeEach(() => {\n vi.resetAllMocks();\n apiMock.sendCommand.mockResolvedValue(\n CommandResultFactory({ data: { challenge: \"challenge\" } }),\n );\n getWeb3ChecksFactoryMock.mockReturnValue({\n run: async () => Promise.resolve({ web3Check: null }),\n });\n\n defaultArgs = {\n contextModule: contextModuleMock,\n subset: { chainId: 1, to: undefined, data: \"0x\", selector: \"0x\" },\n transaction: defaultTransaction,\n options: defaultOptions,\n appConfig: createAppConfig(false),\n derivationPath: \"44'/60'/0'/0/0\",\n };\n });\n\n it(\"should init with a default GetWeb3CheckTaskFactory\", () => {\n // GIVEN\n const task = new BuildBaseContexts(apiMock, defaultArgs);\n\n // THEN\n expect(task[\"getWeb3ChecksFactory\"]).toBeDefined();\n expect(\n task[\"getWeb3ChecksFactory\"](apiMock, {\n contextModule: defaultArgs.contextModule,\n derivationPath: defaultArgs.derivationPath,\n subset: defaultArgs.subset,\n transaction: defaultArgs.transaction!,\n }),\n ).toBeInstanceOf(GetWeb3CheckTask);\n });\n\n it(\"should build the transaction context without clear sign contexts\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n const clearSignContextsOptional: ClearSignContext[] = [];\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 BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n clearSignContextsOptional,\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should build the transaction context with web3checks\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n const clearSignContextsOptional: ClearSignContext[] = [];\n const expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\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 BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [expectedWeb3Check, ...clearSignContexts],\n clearSignContextsOptional,\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should build the transaction context with web3checks and generic-parser clear sign contexts\", async () => {\n // GIVEN\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 expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\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 BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [\n clearSignContexts[0],\n clearSignContexts[1],\n clearSignContexts[3],\n expectedWeb3Check,\n ],\n clearSignContextsOptional: [clearSignContexts[2]],\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should build the transaction context with web3checks and generic-parser clear sign contexts in the correct order\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\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 type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n ];\n const expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\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 BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [\n clearSignContexts[3], // transaction info\n clearSignContexts[1], // transaction field description\n clearSignContexts[2], // transaction field description\n expectedWeb3Check, // web3 check\n ],\n clearSignContextsOptional: [clearSignContexts[0]], // enum\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should build the transaction context with clear sign contexts\", async () => {\n // GIVEN\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 expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\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 BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should build the transaction context with generic-parser context\", async () => {\n // GIVEN\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 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 BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [\n clearSignContexts[0],\n clearSignContexts[1],\n clearSignContexts[3],\n ],\n clearSignContextsOptional: [clearSignContexts[2]],\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should build the transaction context with proxy delegate call context\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.PROXY_DELEGATE_CALL,\n payload: \"payload-2\",\n },\n ];\n const clearSignContextsOptional: ClearSignContext[] = [];\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 BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[0]],\n clearSignContextsOptional,\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should call the web3checks factory with correct parameters\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\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 BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(getWeb3ChecksFactoryMock).toHaveBeenCalledWith(apiMock, {\n contextModule: contextModuleMock,\n derivationPath: \"44'/60'/0'/0/0\",\n subset: defaultArgs.subset,\n transaction: defaultTransaction,\n });\n });\n\n it(\"should call the context module with the correct parameters\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\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 BuildBaseContexts(\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 ...defaultArgs.subset,\n });\n });\n\n it(\"should call the context module without challenge for Nano S\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\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.NANO_S,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.NANO_S,\n domain: \"domain-name.eth\",\n ...defaultArgs.subset,\n });\n });\n\n it(\"should call the context module without context on error\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\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 BuildBaseContexts(\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 ...defaultArgs.subset,\n });\n });\n\n it(\"should exclude error contexts from the result\", async () => {\n // GIVEN\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 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 BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result on old apps\", async () => {\n // GIVEN\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 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 BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result if no transaction_info was found\", async () => {\n // GIVEN\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 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 BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude legacy contexts from the result for generic-parser transactions\", async () => {\n // GIVEN\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 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 BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [clearSignContexts[4]],\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should exclude generic-parser contexts with a nano s device\", async () => {\n // GIVEN\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 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 BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts with an old app version\", async () => {\n // GIVEN\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 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 BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts with a non ready device\", async () => {\n // GIVEN\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 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 BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should return no clear sign context if the transaction info certificate is missing\", async () => {\n // GIVEN\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 contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.17.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should not return web3check if the transaction is undefined\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\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.17.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, transaction: undefined },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(getWeb3ChecksFactoryMock).not.toHaveBeenCalled();\n });\n});\n"],
5
- "mappings": "AAAA,OAGE,wBAAAA,MAEK,2BACP,OACE,wBAAAC,EACA,iBAAAC,EACA,0BAAAC,EACA,gBAAAC,EACA,sBAAAC,EACA,8BAAAC,MACK,kCACP,OAAS,eAAAC,MAAmB,SAG5B,OAAS,oBAAAC,MAAwB,8BACjC,OAAS,mCAAAC,MAAuC,oEAEhD,OACE,qBAAAC,MAEK,sBACP,OAAS,oBAAAC,MAAwB,qBAEjC,SAAS,oBAAqB,IAAM,CAClC,MAAMC,EAAoB,CACxB,gBAAiB,GAAG,GAAG,EACvB,YAAa,GAAG,GAAG,EACnB,oBAAqB,GAAG,GAAG,EAC3B,cAAe,GAAG,GAAG,EACrB,iBAAkB,GAAG,GAAG,EACxB,qBAAsB,GAAG,GAAG,CAC9B,EACMC,EAAiB,CACrB,OAAQ,iBACV,EACMC,EAAiCT,EACrCE,EAAY,KAAK,CACf,QAAS,GACT,MAAO,EACP,KAAM,IACR,CAAC,EAAE,kBACL,EACMQ,EAAqC,CACzC,eAAgB,EAChB,QAAS,IAAI,WAAW,CAAC,EAAM,EAAM,CAAI,CAAC,CAC5C,EAEA,IAAIC,EACJ,MAAMC,EAAUR,EAAgC,EAC1CS,EAA2B,GAAG,GAAG,EAEvC,SAASC,EACPC,EAC0B,CAC1B,MAAO,CACL,oBAAqB,GACrB,kBAAAA,EACA,gBAAiB,GACjB,QAAS,QACX,CACF,CAEA,WAAW,IAAM,CACf,GAAG,cAAc,EACjBH,EAAQ,YAAY,kBAClBhB,EAAqB,CAAE,KAAM,CAAE,UAAW,WAAY,CAAE,CAAC,CAC3D,EACAiB,EAAyB,gBAAgB,CACvC,IAAK,SAAY,QAAQ,QAAQ,CAAE,UAAW,IAAK,CAAC,CACtD,CAAC,EAEDF,EAAc,CACZ,cAAeJ,EACf,OAAQ,CAAE,QAAS,EA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C,CACH,CAAC,EAED,GAAG,qFAAsF,SAAY,CAEnG,MAAMc,EAAwC,CAC5C,CACE,KAAMtB,EAAqB,iBAC3B,QAAS,WACX,EACA,CACE,KAAMA,EAAqB,8BAC3B,QAAS,WACX,EACA,CACE,KAAMA,EAAqB,KAC3B,QAAS,YACT,GAAI,EACJ,MAAO,CACT,CACF,EACAY,EAAkB,YAAY,sBAAsBU,CAAiB,EACrEL,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkBd,EAAuB,0BACzC,aAAcC,EAAa,UAC3B,cAAe,CAAC,EAChB,WAAY,CAAE,KAAM,WAAY,QAAS,QAAS,EAClD,cAAeF,EAAc,KAC7B,0BAA2B,EAC7B,CAAC,EAGD,MAAMsB,EAAS,MAAM,IAAId,EACvBO,EACAD,EACAE,CACF,EAAE,IAAI,EAGN,OAAOM,CAAM,EAAE,QAAQ,CACrB,kBAAmB,CAAC,EACpB,0BAA2B,CAAC,EAC5B,iBAAkBhB,EAAiB,KACrC,CAAC,CACH,CAAC,EAED,GAAG,8DAA+D,SAAY,CAE5E,MAAMc,EAAwC,CAAC,EAC/CV,EAAkB,YAAY,sBAAsBU,CAAiB,EACrEL,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkBd,EAAuB,0BACzC,aAAcC,EAAa,UAC3B,cAAe,CAAC,EAChB,WAAY,CAAE,KAAM,WAAY,QAAS,QAAS,EAClD,cAAeF,EAAc,KAC7B,0BAA2B,EAC7B,CAAC,EAGD,MAAM,IAAIQ,EACRO,EACA,CAAE,GAAGD,EAAa,YAAa,MAAU,EACzCE,CACF,EAAE,IAAI,EAGN,OAAOA,CAAwB,EAAE,IAAI,iBAAiB,CACxD,CAAC,CACH,CAAC",
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\";\n\nimport type { GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\nimport { ClearSigningType } from \"@api/model/ClearSigningType\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\n\nimport {\n BuildBaseContexts,\n type BuildBaseContextsArgs,\n} from \"./BuildBaseContexts\";\nimport { GetWeb3CheckTask } from \"./GetWeb3CheckTask\";\n\ndescribe(\"BuildBaseContexts\", () => {\n const contextModuleMock = {\n getFieldContext: vi.fn(),\n getContexts: vi.fn(),\n getTypedDataFilters: vi.fn(),\n getWeb3Checks: vi.fn(),\n getSolanaContext: 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: BuildBaseContextsArgs;\n const apiMock = makeDeviceActionInternalApiMock();\n const getWeb3ChecksFactoryMock = vi.fn();\n\n function createAppConfig(\n web3ChecksEnabled: boolean,\n ): GetConfigCommandResponse {\n return {\n blindSigningEnabled: false,\n web3ChecksEnabled,\n web3ChecksOptIn: false,\n version: \"1.13.0\",\n };\n }\n\n beforeEach(() => {\n vi.resetAllMocks();\n apiMock.sendCommand.mockResolvedValue(\n CommandResultFactory({ data: { challenge: \"challenge\" } }),\n );\n getWeb3ChecksFactoryMock.mockReturnValue({\n run: async () => Promise.resolve({ web3Check: null }),\n });\n\n defaultArgs = {\n contextModule: contextModuleMock,\n subset: { chainId: 1, to: undefined, data: \"0x\", selector: \"0x\" },\n transaction: defaultTransaction,\n options: defaultOptions,\n appConfig: createAppConfig(false),\n derivationPath: \"44'/60'/0'/0/0\",\n };\n });\n\n it(\"should init with a default GetWeb3CheckTaskFactory\", () => {\n // GIVEN\n const task = new BuildBaseContexts(apiMock, defaultArgs);\n\n // THEN\n expect(task[\"getWeb3ChecksFactory\"]).toBeDefined();\n expect(\n task[\"getWeb3ChecksFactory\"](apiMock, {\n contextModule: defaultArgs.contextModule,\n derivationPath: defaultArgs.derivationPath,\n subset: defaultArgs.subset,\n transaction: defaultArgs.transaction!,\n }),\n ).toBeInstanceOf(GetWeb3CheckTask);\n });\n\n it(\"should build the transaction context without clear sign contexts\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n const clearSignContextsOptional: ClearSignContext[] = [];\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 BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n clearSignContextsOptional,\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should build the transaction context with web3checks\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n const clearSignContextsOptional: ClearSignContext[] = [];\n const expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\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 BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [expectedWeb3Check, ...clearSignContexts],\n clearSignContextsOptional,\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should build the transaction context with web3checks and generic-parser clear sign contexts\", async () => {\n // GIVEN\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 expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\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 BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [\n clearSignContexts[0],\n clearSignContexts[1],\n clearSignContexts[3],\n expectedWeb3Check,\n ],\n clearSignContextsOptional: [clearSignContexts[2]],\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should build the transaction context with web3checks and generic-parser clear sign contexts in the correct order\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\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 type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n ];\n const expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\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 BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [\n clearSignContexts[3], // transaction info\n clearSignContexts[1], // transaction field description\n clearSignContexts[2], // transaction field description\n expectedWeb3Check, // web3 check\n ],\n clearSignContextsOptional: [clearSignContexts[0]], // enum\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should build the transaction context with clear sign contexts\", async () => {\n // GIVEN\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 expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\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 BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should build the transaction context with generic-parser context\", async () => {\n // GIVEN\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 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 BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [\n clearSignContexts[0],\n clearSignContexts[1],\n clearSignContexts[3],\n ],\n clearSignContextsOptional: [clearSignContexts[2]],\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should build the transaction context with proxy delegate call context\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.PROXY_DELEGATE_CALL,\n payload: \"payload-2\",\n },\n ];\n const clearSignContextsOptional: ClearSignContext[] = [];\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 BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[0]],\n clearSignContextsOptional,\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should call the web3checks factory with correct parameters\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\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 BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(getWeb3ChecksFactoryMock).toHaveBeenCalledWith(apiMock, {\n contextModule: contextModuleMock,\n derivationPath: \"44'/60'/0'/0/0\",\n subset: defaultArgs.subset,\n transaction: defaultTransaction,\n });\n });\n\n it(\"should call the context module with the correct parameters\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\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 BuildBaseContexts(\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 ...defaultArgs.subset,\n });\n });\n\n it(\"should call the context module without challenge for Nano S\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\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.NANO_S,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.NANO_S,\n domain: \"domain-name.eth\",\n ...defaultArgs.subset,\n });\n });\n\n it(\"should call the context module without context on error\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\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 BuildBaseContexts(\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 ...defaultArgs.subset,\n });\n });\n\n it(\"should exclude error contexts from the result\", async () => {\n // GIVEN\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 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 BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result on old apps\", async () => {\n // GIVEN\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 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 BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result if no transaction_info was found\", async () => {\n // GIVEN\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 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 BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude legacy contexts from the result for generic-parser transactions\", async () => {\n // GIVEN\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 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 BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [clearSignContexts[4]],\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should exclude generic-parser contexts with a nano s device\", async () => {\n // GIVEN\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 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 BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts with an old app version\", async () => {\n // GIVEN\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 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 BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts with a non ready device\", async () => {\n // GIVEN\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 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 BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should return no clear sign context if the transaction info certificate is missing\", async () => {\n // GIVEN\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 contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.17.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should not return web3check if the transaction is undefined\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\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.17.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, transaction: undefined },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(getWeb3ChecksFactoryMock).not.toHaveBeenCalled();\n });\n});\n"],
5
+ "mappings": "AAAA,OAGE,wBAAAA,MAEK,2BACP,OACE,wBAAAC,EACA,iBAAAC,EACA,0BAAAC,EACA,gBAAAC,EACA,sBAAAC,EACA,8BAAAC,MACK,kCACP,OAAS,eAAAC,MAAmB,SAG5B,OAAS,oBAAAC,MAAwB,8BACjC,OAAS,mCAAAC,MAAuC,oEAEhD,OACE,qBAAAC,MAEK,sBACP,OAAS,oBAAAC,MAAwB,qBAEjC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EAAc,KAC7B,0BAA2B,EAC7B,CAAC,EAGD,MAAMsB,EAAS,MAAM,IAAId,EACvBO,EACAD,EACAE,CACF,EAAE,IAAI,EAGN,OAAOM,CAAM,EAAE,QAAQ,CACrB,kBAAmB,CAAC,EACpB,0BAA2B,CAAC,EAC5B,iBAAkBhB,EAAiB,KACrC,CAAC,CACH,CAAC,EAED,GAAG,8DAA+D,SAAY,CAE5E,MAAMc,EAAwC,CAAC,EAC/CV,EAAkB,YAAY,sBAAsBU,CAAiB,EACrEL,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkBd,EAAuB,0BACzC,aAAcC,EAAa,UAC3B,cAAe,CAAC,EAChB,WAAY,CAAE,KAAM,WAAY,QAAS,QAAS,EAClD,cAAeF,EAAc,KAC7B,0BAA2B,EAC7B,CAAC,EAGD,MAAM,IAAIQ,EACRO,EACA,CAAE,GAAGD,EAAa,YAAa,MAAU,EACzCE,CACF,EAAE,IAAI,EAGN,OAAOA,CAAwB,EAAE,IAAI,iBAAiB,CACxD,CAAC,CACH,CAAC",
6
6
  "names": ["ClearSignContextType", "CommandResultFactory", "DeviceModelId", "DeviceSessionStateType", "DeviceStatus", "hexaStringToBuffer", "UnknownDeviceExchangeError", "Transaction", "ClearSigningType", "makeDeviceActionInternalApiMock", "BuildBaseContexts", "GetWeb3CheckTask", "contextModuleMock", "defaultOptions", "defaultTransaction", "defaultCertificate", "defaultArgs", "apiMock", "getWeb3ChecksFactoryMock", "createAppConfig", "web3ChecksEnabled", "task", "clearSignContexts", "clearSignContextsOptional", "result", "expectedWeb3Check"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{DeviceModelId as v}from"@ledgerhq/device-management-kit";import{Just as n,Nothing as C}from"purify-ts";import{GetWeb3CheckTask as g}from"../../app-binder/task/GetWeb3CheckTask";import{ApplicationChecker as h}from"../../shared/utils/ApplicationChecker";import{TypedDataValueField as m}from"../../typed-data/model/Types";const f="0x0000000000000000000000000000000000000000";class M{constructor(e,t,p,c,i,r,o=(d,s)=>new g(d,s)){this.api=e;this.contextModule=t;this.parser=p;this.data=c;this.derivationPath=i;this.appConfig=r;this.getWeb3ChecksFactory=o}async run(){let e=null;this.appConfig.web3ChecksEnabled&&(e=(await this.getWeb3ChecksFactory(this.api,{contextModule:this.contextModule,derivationPath:this.derivationPath,data:this.data}).run()).web3Check);const t=this.parser.parse(this.data);if(t.isLeft())throw t.extract();const{types:p,domain:c,message:i}=t.unsafeCoerce();let r=C;const o=this.getClearSignVersion();if(o.isJust()){const s=this.data.domain.verifyingContract?.toLowerCase()||f,y=this.data.domain.chainId||0,u=i.filter(a=>a.value instanceof m).map(a=>({path:a.path,value:a.value.data})),l=await this.contextModule.getTypedDataFilters({verifyingContract:s,chainId:y,version:o.extract(),schema:this.data.types,fieldsValues:u});l.type==="success"&&(r=n(l))}return{web3Check:e,types:p,domain:c,message:i,clearSignContext:r}}getClearSignVersion(){const e=this.api.getDeviceSessionState();return new h(e,this.appConfig).withMinVersionInclusive("1.10.0").excludeDeviceModel(v.NANO_S).check()?new h(e,this.appConfig).withMinVersionInclusive("1.12.0").check()?n("v2"):n("v1"):C}}export{M as BuildEIP712ContextTask,f as ZERO_ADDRESS};
1
+ import{DeviceModelId as f,isSuccessCommandResult as S}from"@ledgerhq/device-management-kit";import{Just as h,Nothing as y}from"purify-ts";import{ClearSigningType as T}from"../../../api/model/ClearSigningType";import{GetChallengeCommand as k}from"../../app-binder/command/GetChallengeCommand";import{BuildFullContextsTask as I}from"../../app-binder/task/BuildFullContextsTask";import{GetWeb3CheckTask as M}from"../../app-binder/task/GetWeb3CheckTask";import{ApplicationChecker as u}from"../../shared/utils/ApplicationChecker";import{TypedDataValueField as P}from"../../typed-data/model/Types";const D="0x0000000000000000000000000000000000000000";class B{constructor(e,t,o,r,s,a,d,p,c=(i,n)=>new M(i,n),v=(i,n)=>new I(i,n)){this.api=e;this.contextModule=t;this.parser=o;this.transactionParser=r;this.transactionMapper=s;this.data=a;this.derivationPath=d;this.appConfig=p;this.getWeb3ChecksFactory=c;this.buildFullContextFactory=v}async run(){let e=null;this.appConfig.web3ChecksEnabled&&(e=(await this.getWeb3ChecksFactory(this.api,{contextModule:this.contextModule,derivationPath:this.derivationPath,data:this.data}).run()).web3Check);const t=this.parser.parse(this.data);if(t.isLeft())throw t.extract();const{types:o,domain:r,message:s}=t.unsafeCoerce(),a=this.api.getDeviceSessionState();let d=y,p={};const c=this.getClearSignVersion(a);if(c.isJust()){let i;const n=await this.api.sendCommand(new k);S(n)&&(i=n.data.challenge);const g=this.data.domain.verifyingContract?.toLowerCase()||D,x=this.data.domain.chainId||0,m=s.filter(l=>l.value instanceof P).map(l=>({path:l.path,value:l.value.data})),C=await this.contextModule.getTypedDataFilters({verifyingContract:g,chainId:x,version:c.extract(),schema:this.data.types,challenge:i,deviceModelId:a.deviceModelId,fieldsValues:m});C.type==="success"&&(d=h(C),p=await this.getCalldatasContexts(a,C))}return{derivationPath:this.derivationPath,web3Check:e,types:o,domain:r,message:s,clearSignContext:d,calldatasContexts:p}}getClearSignVersion(e){return new u(e,this.appConfig).withMinVersionInclusive("1.10.0").excludeDeviceModel(f.NANO_S).check()?new u(e,this.appConfig).withMinVersionInclusive("1.12.0").check()?h("v2"):h("v1"):y}async getCalldatasContexts(e,t){const o={};for(const r in t.calldatas){const{subset:s}=t.calldatas[r],a=await this.buildFullContextFactory(this.api,{contextModule:this.contextModule,mapper:this.transactionMapper,parser:this.transactionParser,options:{},appConfig:this.appConfig,derivationPath:this.derivationPath,subset:s,deviceModelId:e.deviceModelId}).run();a.clearSigningType===T.EIP7730&&(o[r]=a.clearSignContexts)}return o}}export{B as BuildEIP712ContextTask,D as ZERO_ADDRESS};
2
2
  //# sourceMappingURL=BuildEIP712ContextTask.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/internal/app-binder/task/BuildEIP712ContextTask.ts"],
4
- "sourcesContent": ["import {\n type ClearSignContextSuccess,\n type ClearSignContextType,\n type ContextModule,\n type TypedDataClearSignContextSuccess,\n} from \"@ledgerhq/context-module\";\nimport {\n DeviceModelId,\n type InternalApi,\n} from \"@ledgerhq/device-management-kit\";\nimport { Just, type Maybe, Nothing } from \"purify-ts\";\n\nimport { type GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\nimport { type TypedData } from \"@api/model/TypedData\";\nimport {\n GetWeb3CheckTask,\n type GetWeb3CheckTaskArgs,\n} from \"@internal/app-binder/task/GetWeb3CheckTask\";\nimport { type ProvideEIP712ContextTaskArgs } from \"@internal/app-binder/task/ProvideEIP712ContextTask\";\nimport { ApplicationChecker } from \"@internal/shared/utils/ApplicationChecker\";\nimport { TypedDataValueField } from \"@internal/typed-data/model/Types\";\nimport { type TypedDataParserService } from \"@internal/typed-data/service/TypedDataParserService\";\n\nexport const ZERO_ADDRESS = \"0x0000000000000000000000000000000000000000\";\n\nexport class BuildEIP712ContextTask {\n constructor(\n private readonly api: InternalApi,\n private readonly contextModule: ContextModule,\n private readonly parser: TypedDataParserService,\n private readonly data: TypedData,\n private readonly derivationPath: string,\n private readonly appConfig: GetConfigCommandResponse,\n private readonly getWeb3ChecksFactory = (\n api: InternalApi,\n args: GetWeb3CheckTaskArgs,\n ) => new GetWeb3CheckTask(api, args),\n ) {}\n\n async run(): Promise<ProvideEIP712ContextTaskArgs> {\n // Run the web3checks if needed\n let web3Check: ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK> | null =\n null;\n if (this.appConfig.web3ChecksEnabled) {\n web3Check = (\n await this.getWeb3ChecksFactory(this.api, {\n contextModule: this.contextModule,\n derivationPath: this.derivationPath,\n data: this.data,\n }).run()\n ).web3Check;\n }\n\n // Clear signing context\n // Parse the message types and values\n const parsed = this.parser.parse(this.data);\n if (parsed.isLeft()) {\n throw parsed.extract();\n }\n const { types, domain, message } = parsed.unsafeCoerce();\n\n // Get clear signing context, if any\n let clearSignContext: Maybe<TypedDataClearSignContextSuccess> = Nothing;\n const version = this.getClearSignVersion();\n if (version.isJust()) {\n const verifyingContract =\n this.data.domain.verifyingContract?.toLowerCase() || ZERO_ADDRESS;\n const chainId = this.data.domain.chainId || 0;\n const fieldsValues = message\n .filter((v) => v.value instanceof TypedDataValueField)\n .map((v) => ({\n path: v.path,\n value: (v.value as TypedDataValueField).data,\n }));\n const filters = await this.contextModule.getTypedDataFilters({\n verifyingContract,\n chainId,\n version: version.extract(),\n schema: this.data.types,\n fieldsValues,\n });\n if (filters.type === \"success\") {\n clearSignContext = Just(filters);\n }\n }\n\n // Return the args for provide context task\n const provideTaskArgs: ProvideEIP712ContextTaskArgs = {\n web3Check,\n types,\n domain,\n message,\n clearSignContext,\n };\n return provideTaskArgs;\n }\n\n private getClearSignVersion(): Maybe<\"v1\" | \"v2\"> {\n const deviceState = this.api.getDeviceSessionState();\n if (\n !new ApplicationChecker(deviceState, this.appConfig)\n .withMinVersionInclusive(\"1.10.0\")\n .excludeDeviceModel(DeviceModelId.NANO_S)\n .check()\n ) {\n return Nothing;\n }\n\n // EIP712 v2 (amount & datetime filters) supported since 1.11.0:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#1110-1\n // But some issues were still present until 1.12.0 among which:\n // * V2 descriptor with missing token not supported by the app\n // * Empty arrays with filters not correctly handled\n // * Trusted name filters not yet released\n // Therefore it's safer and easier to use V1 filters before 1.12.0:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#1120\n const shouldUseV2Filters = new ApplicationChecker(\n deviceState,\n this.appConfig,\n )\n .withMinVersionInclusive(\"1.12.0\")\n .check();\n return shouldUseV2Filters ? Just(\"v2\") : Just(\"v1\");\n }\n}\n"],
5
- "mappings": "AAMA,OACE,iBAAAA,MAEK,kCACP,OAAS,QAAAC,EAAkB,WAAAC,MAAe,YAI1C,OACE,oBAAAC,MAEK,6CAEP,OAAS,sBAAAC,MAA0B,4CACnC,OAAS,uBAAAC,MAA2B,mCAG7B,MAAMC,EAAe,6CAErB,MAAMC,CAAuB,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,sBAAsB,EACnD,OACG,IAAIxB,EAAmBwB,EAAa,KAAK,SAAS,EAChD,wBAAwB,QAAQ,EAChC,mBAAmB5B,EAAc,MAAM,EACvC,MAAM,EAagB,IAAII,EAC7BwB,EACA,KAAK,SACP,EACG,wBAAwB,QAAQ,EAChC,MAAM,EACmB3B,EAAK,IAAI,EAAIA,EAAK,IAAI,EAjBzCC,CAkBX,CACF",
6
- "names": ["DeviceModelId", "Just", "Nothing", "GetWeb3CheckTask", "ApplicationChecker", "TypedDataValueField", "ZERO_ADDRESS", "BuildEIP712ContextTask", "api", "contextModule", "parser", "data", "derivationPath", "appConfig", "getWeb3ChecksFactory", "args", "web3Check", "parsed", "types", "domain", "message", "clearSignContext", "version", "verifyingContract", "chainId", "fieldsValues", "v", "filters", "deviceState"]
4
+ "sourcesContent": ["import {\n type ClearSignContextSuccess,\n type ClearSignContextType,\n type ContextModule,\n type TypedDataCalldataIndex,\n type TypedDataClearSignContextSuccess,\n} from \"@ledgerhq/context-module\";\nimport {\n DeviceModelId,\n type DeviceSessionState,\n type InternalApi,\n isSuccessCommandResult,\n} from \"@ledgerhq/device-management-kit\";\nimport { Just, type Maybe, Nothing } from \"purify-ts\";\n\nimport { type GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\nimport { ClearSigningType } from \"@api/model/ClearSigningType\";\nimport { type TypedData } from \"@api/model/TypedData\";\nimport { GetChallengeCommand } from \"@internal/app-binder/command/GetChallengeCommand\";\nimport {\n BuildFullContextsTask,\n type BuildFullContextsTaskArgs,\n type ContextWithSubContexts,\n} from \"@internal/app-binder/task/BuildFullContextsTask\";\nimport {\n GetWeb3CheckTask,\n type GetWeb3CheckTaskArgs,\n} from \"@internal/app-binder/task/GetWeb3CheckTask\";\nimport { type ProvideEIP712ContextTaskArgs } from \"@internal/app-binder/task/ProvideEIP712ContextTask\";\nimport { ApplicationChecker } from \"@internal/shared/utils/ApplicationChecker\";\nimport { type TransactionMapperService } from \"@internal/transaction/service/mapper/TransactionMapperService\";\nimport { type TransactionParserService } from \"@internal/transaction/service/parser/TransactionParserService\";\nimport { TypedDataValueField } from \"@internal/typed-data/model/Types\";\nimport { type TypedDataParserService } from \"@internal/typed-data/service/TypedDataParserService\";\n\nexport const ZERO_ADDRESS = \"0x0000000000000000000000000000000000000000\";\n\nexport class BuildEIP712ContextTask {\n constructor(\n private readonly api: InternalApi,\n private readonly contextModule: ContextModule,\n private readonly parser: TypedDataParserService,\n private readonly transactionParser: TransactionParserService,\n private readonly transactionMapper: TransactionMapperService,\n private readonly data: TypedData,\n private readonly derivationPath: string,\n private readonly appConfig: GetConfigCommandResponse,\n private readonly getWeb3ChecksFactory = (\n api: InternalApi,\n args: GetWeb3CheckTaskArgs,\n ) => new GetWeb3CheckTask(api, args),\n private readonly buildFullContextFactory = (\n api: InternalApi,\n args: BuildFullContextsTaskArgs,\n ) => new BuildFullContextsTask(api, args),\n ) {}\n\n async run(): Promise<ProvideEIP712ContextTaskArgs> {\n // Run the web3checks if needed\n let web3Check: ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK> | null =\n null;\n if (this.appConfig.web3ChecksEnabled) {\n web3Check = (\n await this.getWeb3ChecksFactory(this.api, {\n contextModule: this.contextModule,\n derivationPath: this.derivationPath,\n data: this.data,\n }).run()\n ).web3Check;\n }\n\n // Clear signing context\n // Parse the message types and values\n const parsed = this.parser.parse(this.data);\n if (parsed.isLeft()) {\n throw parsed.extract();\n }\n const { types, domain, message } = parsed.unsafeCoerce();\n\n // Get clear signing context, if any\n const deviceState = this.api.getDeviceSessionState();\n let clearSignContext: Maybe<TypedDataClearSignContextSuccess> = Nothing;\n let calldatasContexts: Record<\n TypedDataCalldataIndex,\n ContextWithSubContexts[]\n > = {};\n const version = this.getClearSignVersion(deviceState);\n if (version.isJust()) {\n // Get challenge\n let challenge: string | undefined = undefined;\n const challengeRes = await this.api.sendCommand(\n new GetChallengeCommand(),\n );\n if (isSuccessCommandResult(challengeRes)) {\n challenge = challengeRes.data.challenge;\n }\n\n // Get filters\n const verifyingContract =\n this.data.domain.verifyingContract?.toLowerCase() || ZERO_ADDRESS;\n const chainId = this.data.domain.chainId || 0;\n const fieldsValues = message\n .filter((v) => v.value instanceof TypedDataValueField)\n .map((v) => ({\n path: v.path,\n value: (v.value as TypedDataValueField).data,\n }));\n const filters = await this.contextModule.getTypedDataFilters({\n verifyingContract,\n chainId,\n version: version.extract(),\n schema: this.data.types,\n challenge,\n deviceModelId: deviceState.deviceModelId,\n fieldsValues,\n });\n if (filters.type === \"success\") {\n clearSignContext = Just(filters);\n calldatasContexts = await this.getCalldatasContexts(\n deviceState,\n filters,\n );\n }\n }\n\n // Return the args for provide context task\n const provideTaskArgs: ProvideEIP712ContextTaskArgs = {\n derivationPath: this.derivationPath,\n web3Check,\n types,\n domain,\n message,\n clearSignContext,\n calldatasContexts,\n };\n return provideTaskArgs;\n }\n\n private getClearSignVersion(\n deviceState: DeviceSessionState,\n ): Maybe<\"v1\" | \"v2\"> {\n if (\n !new ApplicationChecker(deviceState, this.appConfig)\n .withMinVersionInclusive(\"1.10.0\")\n .excludeDeviceModel(DeviceModelId.NANO_S)\n .check()\n ) {\n return Nothing;\n }\n\n // EIP712 v2 (amount & datetime filters) supported since 1.11.0:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#1110-1\n // But some issues were still present until 1.12.0 among which:\n // * V2 descriptor with missing token not supported by the app\n // * Empty arrays with filters not correctly handled\n // * Trusted name filters not yet released\n // Therefore it's safer and easier to use V1 filters before 1.12.0:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#1120\n const shouldUseV2Filters = new ApplicationChecker(\n deviceState,\n this.appConfig,\n )\n .withMinVersionInclusive(\"1.12.0\")\n .check();\n return shouldUseV2Filters ? Just(\"v2\") : Just(\"v1\");\n }\n\n private async getCalldatasContexts(\n deviceState: DeviceSessionState,\n filters: TypedDataClearSignContextSuccess,\n ): Promise<Record<TypedDataCalldataIndex, ContextWithSubContexts[]>> {\n const calldatasContexts: Record<\n TypedDataCalldataIndex,\n ContextWithSubContexts[]\n > = {};\n for (const calldataIndex in filters.calldatas) {\n const { subset } = filters.calldatas[calldataIndex]!;\n const calldataContext = await this.buildFullContextFactory(this.api, {\n contextModule: this.contextModule,\n mapper: this.transactionMapper,\n parser: this.transactionParser,\n options: {},\n appConfig: this.appConfig,\n derivationPath: this.derivationPath,\n subset,\n deviceModelId: deviceState.deviceModelId,\n }).run();\n if (calldataContext.clearSigningType === ClearSigningType.EIP7730) {\n calldatasContexts[calldataIndex] = calldataContext.clearSignContexts;\n }\n }\n return calldatasContexts;\n }\n}\n"],
5
+ "mappings": "AAOA,OACE,iBAAAA,EAGA,0BAAAC,MACK,kCACP,OAAS,QAAAC,EAAkB,WAAAC,MAAe,YAG1C,OAAS,oBAAAC,MAAwB,8BAEjC,OAAS,uBAAAC,MAA2B,mDACpC,OACE,yBAAAC,MAGK,kDACP,OACE,oBAAAC,MAEK,6CAEP,OAAS,sBAAAC,MAA0B,4CAGnC,OAAS,uBAAAC,MAA2B,mCAG7B,MAAMC,EAAe,6CAErB,MAAMC,CAAuB,CAClC,YACmBC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAAuB,CACtCR,EACAS,IACG,IAAId,EAAiBK,EAAKS,CAAI,EAClBC,EAA0B,CACzCV,EACAS,IACG,IAAIf,EAAsBM,EAAKS,CAAI,EACxC,CAhBiB,SAAAT,EACA,mBAAAC,EACA,YAAAC,EACA,uBAAAC,EACA,uBAAAC,EACA,UAAAC,EACA,oBAAAC,EACA,eAAAC,EACA,0BAAAC,EAIA,6BAAAE,CAIhB,CAEH,MAAM,KAA6C,CAEjD,IAAIC,EACF,KACE,KAAK,UAAU,oBACjBA,GACE,MAAM,KAAK,qBAAqB,KAAK,IAAK,CACxC,cAAe,KAAK,cACpB,eAAgB,KAAK,eACrB,KAAM,KAAK,IACb,CAAC,EAAE,IAAI,GACP,WAKJ,MAAMC,EAAS,KAAK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,SACP,EACG,wBAAwB,QAAQ,EAChC,MAAM,EACmB1B,EAAK,IAAI,EAAIA,EAAK,IAAI,EAjBzCC,CAkBX,CAEA,MAAc,qBACZyB,EACAU,EACmE,CACnE,MAAMR,EAGF,CAAC,EACL,UAAWS,KAAiBD,EAAQ,UAAW,CAC7C,KAAM,CAAE,OAAAE,CAAO,EAAIF,EAAQ,UAAUC,CAAa,EAC5CE,EAAkB,MAAM,KAAK,wBAAwB,KAAK,IAAK,CACnE,cAAe,KAAK,cACpB,OAAQ,KAAK,kBACb,OAAQ,KAAK,kBACb,QAAS,CAAC,EACV,UAAW,KAAK,UAChB,eAAgB,KAAK,eACrB,OAAAD,EACA,cAAeZ,EAAY,aAC7B,CAAC,EAAE,IAAI,EACHa,EAAgB,mBAAqBrC,EAAiB,UACxD0B,EAAkBS,CAAa,EAAIE,EAAgB,kBAEvD,CACA,OAAOX,CACT,CACF",
6
+ "names": ["DeviceModelId", "isSuccessCommandResult", "Just", "Nothing", "ClearSigningType", "GetChallengeCommand", "BuildFullContextsTask", "GetWeb3CheckTask", "ApplicationChecker", "TypedDataValueField", "ZERO_ADDRESS", "BuildEIP712ContextTask", "api", "contextModule", "parser", "transactionParser", "transactionMapper", "data", "derivationPath", "appConfig", "getWeb3ChecksFactory", "args", "buildFullContextFactory", "web3Check", "parsed", "types", "domain", "message", "deviceState", "clearSignContext", "calldatasContexts", "version", "challenge", "challengeRes", "verifyingContract", "chainId", "fieldsValues", "v", "filters", "calldataIndex", "subset", "calldataContext"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{DeviceModelId as C,DeviceSessionStateType as y,DeviceStatus as g}from"@ledgerhq/device-management-kit";import{Just as u,Left as k,Nothing as x,Right as S}from"purify-ts";import{makeDeviceActionInternalApiMock as w}from"../../app-binder/device-action/__test-utils__/makeInternalApi";import{PrimitiveType as p,StructType as E,TypedDataValueField as v,TypedDataValueRoot as b}from"../../typed-data/model/Types";import{BuildEIP712ContextTask as m}from"./BuildEIP712ContextTask";describe("BuildEIP712ContextTask",()=>{const a=w(),t={getFieldContext:vi.fn(),getContexts:vi.fn(),getTypedDataFilters:vi.fn(),getWeb3Checks:vi.fn(),getSolanaContext:vi.fn(),getProxyDelegateCall:vi.fn()},n={parse:vi.fn()},i=vi.fn();function d(e){return{blindSigningEnabled:!1,web3ChecksEnabled:e,web3ChecksOptIn:!1,version:"1.13.0"}}const s={domain:{name:"Permit2",chainId:137,verifyingContract:"0x000000000022d473030f116ddee9f6b43ac78ba3"},primaryType:"PermitSingle",message:{details:{token:"0x7ceb23fd6bc0add59e62ac25578270cff1b9f619",amount:"69420000000000000000",expiration:"1718184249",nonce:"0"},spender:"0xec7be89e9d109e7e3fec59c222cf297125fefda2",sigDeadline:"1715594049"},types:{PermitSingle:[{name:"details",type:"PermitDetails"},{name:"spender",type:"address"},{name:"sigDeadline",type:"uint256"}],PermitDetails:[{name:"token",type:"address"},{name:"amount",type:"uint"},{name:"expiration",type:"uint"},{name:"nonce",type:"uint"}]}},c={PermitSingle:{details:new E("PermitDetails"),spender:new p("address","address",x),sigDeadline:new p("uint256","uint",u(32))},PermitDetails:{token:new p("address","address",x),amount:new p("uint160","uint",u(20)),expiration:new p("uint48","uint",u(6)),nonce:new p("uint48","uint",u(6))}},r=[{path:"",type:"",value:new b("EIP712Domain")},{path:"chainId",type:"uint256",value:new v(Uint8Array.from([137]))}],l=[{path:"",type:"",value:new b("PermitSingle")},{path:"details.amount",type:"uint160",value:new v(Uint8Array.from([18]))},{path:"details.expiration",type:"uint48",value:new v(Uint8Array.from([19]))}],f={type:"success",messageInfo:{displayName:"Permit2",filtersCount:1,signature:"3045022100e3c597d13d28a87a88b0239404c668373cf5063362f2a81d09eed4582941dfe802207669aabb504fd5b95b2734057f6b8bbf51f14a69a5f9bdf658a5952cefbf44d3"},trustedNamesAddresses:{},tokens:{},filters:{"details.amount":{displayName:"Amount allowance",path:"details.amount",signature:"304402201a46e6b4ef89eaf9fcf4945d053bfc5616a826400fd758312fbbe976bafc07ec022025a9b408722baf983ee053f90179c75b0c55bb0668f437d55493e36069bbd5a3",tokenIndex:255,type:"amount"}}};beforeEach(()=>{vi.resetAllMocks(),i.mockReturnValue({run:async()=>({web3Check:null})})}),it("Build context with clear signing context not supported by the device",async()=>{const e=new m(a,t,n,s,"44'/60'/0'/0/0",d(!1),i);n.parse.mockReturnValueOnce(S({types:c,domain:r,message:l})),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:y.ReadyWithoutSecureChannel,deviceStatus:g.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.11.0"},deviceModelId:C.NANO_S,isSecureConnectionAllowed:!1});const o=await e.run();expect(o).toStrictEqual({web3Check:null,types:c,domain:r,message:l,clearSignContext:x})}),it("Build context with no clear signing context",async()=>{const e=new m(a,t,n,s,"44'/60'/0'/0/0",d(!1),i);n.parse.mockReturnValueOnce(S({types:c,domain:r,message:l})),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:y.ReadyWithoutSecureChannel,deviceStatus:g.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:C.FLEX,isSecureConnectionAllowed:!1}),t.getTypedDataFilters.mockResolvedValueOnce({type:"error",error:new Error("no filter")});const o=await e.run();expect(o).toStrictEqual({web3Check:null,types:c,domain:r,message:l,clearSignContext:x})}),it("Build context with clear signing context",async()=>{const e="web3Check",o=new m(a,t,n,s,"44'/60'/0'/0/0",d(!1),i);i.mockReturnValueOnce({run:async()=>({web3Check:e})}),n.parse.mockReturnValueOnce(S({types:c,domain:r,message:l})),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:y.ReadyWithoutSecureChannel,deviceStatus:g.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:C.FLEX,isSecureConnectionAllowed:!1}),t.getTypedDataFilters.mockResolvedValueOnce(f);const h=await o.run();expect(h).toStrictEqual({web3Check:null,types:c,domain:r,message:l,clearSignContext:u(f)}),expect(n.parse).toHaveBeenCalledWith(s),expect(t.getTypedDataFilters).toHaveBeenCalledWith({verifyingContract:"0x000000000022d473030f116ddee9f6b43ac78ba3",chainId:137,version:"v2",schema:s.types,fieldsValues:[{path:"details.amount",value:Uint8Array.from([18])},{path:"details.expiration",value:Uint8Array.from([19])}]})}),it("Build context with clear signing context and web3Check",async()=>{const e="web3Check",o=new m(a,t,n,s,"44'/60'/0'/0/0",d(!0),i);i.mockReturnValueOnce({run:async()=>({web3Check:e})}),n.parse.mockReturnValueOnce(S({types:c,domain:r,message:l})),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:y.ReadyWithoutSecureChannel,deviceStatus:g.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:C.FLEX,isSecureConnectionAllowed:!1}),t.getTypedDataFilters.mockResolvedValueOnce(f);const h=await o.run();expect(h).toStrictEqual({web3Check:e,types:c,domain:r,message:l,clearSignContext:u(f)}),expect(i).toHaveBeenCalledWith(a,{contextModule:t,derivationPath:"44'/60'/0'/0/0",data:s})}),it("Build context with clear signing context V1",async()=>{const e=new m(a,t,n,s,"44'/60'/0'/0/0",d(!1),i);n.parse.mockReturnValueOnce(S({types:c,domain:r,message:l})),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:y.ReadyWithoutSecureChannel,deviceStatus:g.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.11.0"},deviceModelId:C.FLEX,isSecureConnectionAllowed:!1}),t.getTypedDataFilters.mockResolvedValueOnce(f),await e.run(),expect(t.getTypedDataFilters).toHaveBeenCalledWith({verifyingContract:"0x000000000022d473030f116ddee9f6b43ac78ba3",chainId:137,version:"v1",schema:s.types,fieldsValues:[{path:"details.amount",value:Uint8Array.from([18])},{path:"details.expiration",value:Uint8Array.from([19])}]})}),it("Should throw an error if parsing fails",async()=>{const e=new m(a,t,n,s,"44'/60'/0'/0/0",d(!1),i);n.parse.mockReturnValueOnce(k(new Error("Parsing error")));try{await e.run()}catch(o){expect(o).toBeInstanceOf(Error),expect(o.message).toBe("Parsing error")}})});
1
+ import{TypedDataCalldataParamPresence as w}from"@ledgerhq/context-module";import{CommandResultFactory as P,DeviceModelId as u,DeviceSessionStateType as x,DeviceStatus as v}from"@ledgerhq/device-management-kit";import{Just as C,Left as V,Nothing as k,Right as b}from"purify-ts";import{ClearSigningType as A}from"../../../api/model/ClearSigningType";import{makeDeviceActionInternalApiMock as O}from"../../app-binder/device-action/__test-utils__/makeInternalApi";import{PrimitiveType as h,StructType as I,TypedDataValueField as E,TypedDataValueRoot as D}from"../../typed-data/model/Types";import{BuildEIP712ContextTask as g}from"./BuildEIP712ContextTask";describe("BuildEIP712ContextTask",()=>{const e=O(),a={getFieldContext:vi.fn(),getContexts:vi.fn(),getTypedDataFilters:vi.fn(),getWeb3Checks:vi.fn(),getSolanaContext:vi.fn()},n={parse:vi.fn()},p={extractValue:vi.fn()},m={mapTransactionToSubset:vi.fn()},s=vi.fn(),d=vi.fn();function f(t){return{blindSigningEnabled:!1,web3ChecksEnabled:t,web3ChecksOptIn:!1,version:"1.13.0"}}const o={domain:{name:"Permit2",chainId:137,verifyingContract:"0x000000000022d473030f116ddee9f6b43ac78ba3"},primaryType:"PermitSingle",message:{details:{token:"0x7ceb23fd6bc0add59e62ac25578270cff1b9f619",amount:"69420000000000000000",expiration:"1718184249",nonce:"0"},spender:"0xec7be89e9d109e7e3fec59c222cf297125fefda2",sigDeadline:"1715594049"},types:{PermitSingle:[{name:"details",type:"PermitDetails"},{name:"spender",type:"address"},{name:"sigDeadline",type:"uint256"}],PermitDetails:[{name:"token",type:"address"},{name:"amount",type:"uint"},{name:"expiration",type:"uint"},{name:"nonce",type:"uint"}]}},c={PermitSingle:{details:new I("PermitDetails"),spender:new h("address","address",k),sigDeadline:new h("uint256","uint",C(32))},PermitDetails:{token:new h("address","address",k),amount:new h("uint160","uint",C(20)),expiration:new h("uint48","uint",C(6)),nonce:new h("uint48","uint",C(6))}},r=[{path:"",type:"",value:new D("EIP712Domain")},{path:"chainId",type:"uint256",value:new E(Uint8Array.from([137]))}],l=[{path:"",type:"",value:new D("PermitSingle")},{path:"details.amount",type:"uint160",value:new E(Uint8Array.from([18]))},{path:"details.expiration",type:"uint48",value:new E(Uint8Array.from([19]))}],y={type:"success",messageInfo:{displayName:"Permit2",filtersCount:1,signature:"3045022100e3c597d13d28a87a88b0239404c668373cf5063362f2a81d09eed4582941dfe802207669aabb504fd5b95b2734057f6b8bbf51f14a69a5f9bdf658a5952cefbf44d3"},trustedNamesAddresses:{},tokens:{},calldatas:{},proxy:void 0,filters:{"details.amount":{displayName:"Amount allowance",path:"details.amount",signature:"304402201a46e6b4ef89eaf9fcf4945d053bfc5616a826400fd758312fbbe976bafc07ec022025a9b408722baf983ee053f90179c75b0c55bb0668f437d55493e36069bbd5a3",tokenIndex:255,type:"amount"}}},T="0x1234";beforeEach(()=>{vi.resetAllMocks(),s.mockReturnValue({run:async()=>({web3Check:null})}),d.mockReturnValue({run:async()=>({clearSignContexts:[],clearSigningType:A.BASIC})}),e.sendCommand.mockResolvedValue(P({data:{challenge:T}}))}),it("Build context with clear signing context not supported by the device",async()=>{const t=new g(e,a,n,p,m,o,"44'/60'/0'/0/0",f(!1),s,d);n.parse.mockReturnValueOnce(b({types:c,domain:r,message:l})),e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:x.ReadyWithoutSecureChannel,deviceStatus:v.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.11.0"},deviceModelId:u.NANO_S,isSecureConnectionAllowed:!1});const i=await t.run();expect(i).toStrictEqual({derivationPath:"44'/60'/0'/0/0",web3Check:null,types:c,domain:r,message:l,clearSignContext:k,calldatasContexts:{}})}),it("Build context with no clear signing context",async()=>{const t=new g(e,a,n,p,m,o,"44'/60'/0'/0/0",f(!1),s,d);n.parse.mockReturnValueOnce(b({types:c,domain:r,message:l})),e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:x.ReadyWithoutSecureChannel,deviceStatus:v.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:u.FLEX,isSecureConnectionAllowed:!1}),a.getTypedDataFilters.mockResolvedValueOnce({type:"error",error:new Error("no filter")});const i=await t.run();expect(i).toStrictEqual({derivationPath:"44'/60'/0'/0/0",web3Check:null,types:c,domain:r,message:l,clearSignContext:k,calldatasContexts:{}})}),it("Build context with clear signing context",async()=>{const t="web3Check",i=new g(e,a,n,p,m,o,"44'/60'/0'/0/0",f(!1),s,d);s.mockReturnValueOnce({run:async()=>({web3Check:t})}),n.parse.mockReturnValueOnce(b({types:c,domain:r,message:l})),e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:x.ReadyWithoutSecureChannel,deviceStatus:v.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:u.FLEX,isSecureConnectionAllowed:!1}),a.getTypedDataFilters.mockResolvedValueOnce(y);const S=await i.run();expect(S).toStrictEqual({derivationPath:"44'/60'/0'/0/0",web3Check:null,types:c,domain:r,message:l,clearSignContext:C(y),calldatasContexts:{}}),expect(n.parse).toHaveBeenCalledWith(o),expect(a.getTypedDataFilters).toHaveBeenCalledWith({verifyingContract:"0x000000000022d473030f116ddee9f6b43ac78ba3",chainId:137,version:"v2",schema:o.types,challenge:T,deviceModelId:u.FLEX,fieldsValues:[{path:"details.amount",value:Uint8Array.from([18])},{path:"details.expiration",value:Uint8Array.from([19])}]})}),it("Build context with clear signing context and web3Check",async()=>{const t="web3Check",i=new g(e,a,n,p,m,o,"44'/60'/0'/0/0",f(!0),s,d);s.mockReturnValueOnce({run:async()=>({web3Check:t})}),n.parse.mockReturnValueOnce(b({types:c,domain:r,message:l})),e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:x.ReadyWithoutSecureChannel,deviceStatus:v.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:u.FLEX,isSecureConnectionAllowed:!1}),a.getTypedDataFilters.mockResolvedValueOnce(y);const S=await i.run();expect(S).toStrictEqual({derivationPath:"44'/60'/0'/0/0",web3Check:t,types:c,domain:r,message:l,clearSignContext:C(y),calldatasContexts:{}}),expect(s).toHaveBeenCalledWith(e,{contextModule:a,derivationPath:"44'/60'/0'/0/0",data:o})}),it("Build context with clear signing context V1",async()=>{const t=new g(e,a,n,p,m,o,"44'/60'/0'/0/0",f(!1),s,d);n.parse.mockReturnValueOnce(b({types:c,domain:r,message:l})),e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:x.ReadyWithoutSecureChannel,deviceStatus:v.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.11.0"},deviceModelId:u.FLEX,isSecureConnectionAllowed:!1}),a.getTypedDataFilters.mockResolvedValueOnce(y),await t.run(),expect(a.getTypedDataFilters).toHaveBeenCalledWith({verifyingContract:"0x000000000022d473030f116ddee9f6b43ac78ba3",chainId:137,version:"v1",schema:o.types,challenge:T,deviceModelId:u.FLEX,fieldsValues:[{path:"details.amount",value:Uint8Array.from([18])},{path:"details.expiration",value:Uint8Array.from([19])}]})}),it("Build context with clear signing context and calldatas",async()=>{const t=new g(e,a,n,p,m,o,"44'/60'/0'/0/0",f(!1),s,d),i={chainId:4660,data:"0x6a76120200000000000000000000000023f8abfc2824c397ccb3da89ae772984107ddb99",from:"0x8ceb23fd6bc0add59e62ac25578270cff1b9f619",selector:"0x778899aa",to:"0x7ceb23fd6bc0add59e62ac25578270cff1b9f619",value:4200000000000000n},S={...y,calldatas:{0:{filter:{calldataIndex:0,displayName:"Transaction",valueFlag:!0,calleeFlag:w.Present,chainIdFlag:!1,selectorFlag:!1,amountFlag:!0,spenderFlag:w.Present,signature:"3045022100d8496ab69152efeef6a923a3ebd225334ad65dcb985814994243be7bc09bf27e02206314835816908dd6d51d3cbb0f9465d91d7ddc9104b34dd6c4247f65c551836e"},subset:i}}};n.parse.mockReturnValueOnce(b({types:c,domain:r,message:l})),e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:x.ReadyWithoutSecureChannel,deviceStatus:v.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:u.FLEX,isSecureConnectionAllowed:!1}),a.getTypedDataFilters.mockResolvedValueOnce(S),d.mockReturnValue({run:async()=>({clearSignContexts:[],clearSigningType:A.EIP7730})});const R=await t.run();expect(d).toHaveBeenCalledWith(e,expect.objectContaining({subset:i})),expect(R).toStrictEqual({derivationPath:"44'/60'/0'/0/0",web3Check:null,types:c,domain:r,message:l,clearSignContext:C(S),calldatasContexts:{0:[]}})}),it("Should throw an error if parsing fails",async()=>{const t=new g(e,a,n,p,m,o,"44'/60'/0'/0/0",f(!1),s,d);n.parse.mockReturnValueOnce(V(new Error("Parsing error")));try{await t.run()}catch(i){expect(i).toBeInstanceOf(Error),expect(i.message).toBe("Parsing error")}})});
2
2
  //# sourceMappingURL=BuildEIP712ContextTask.test.js.map
@@ -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 {\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 type { GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\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 getFieldContext: vi.fn(),\n getContexts: vi.fn(),\n getTypedDataFilters: vi.fn(),\n getWeb3Checks: vi.fn(),\n getSolanaContext: vi.fn(),\n getProxyDelegateCall: vi.fn(),\n };\n const parserMock = {\n parse: vi.fn(),\n };\n const getWeb3ChecksFactoryMock = vi.fn();\n\n function createAppConfig(\n web3ChecksEnabled: boolean,\n ): GetConfigCommandResponse {\n return {\n blindSigningEnabled: false,\n web3ChecksEnabled,\n web3ChecksOptIn: false,\n version: \"1.13.0\",\n };\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 trustedNamesAddresses: {},\n tokens: {},\n filters: {\n \"details.amount\": {\n displayName: \"Amount allowance\",\n path: \"details.amount\",\n signature:\n \"304402201a46e6b4ef89eaf9fcf4945d053bfc5616a826400fd758312fbbe976bafc07ec022025a9b408722baf983ee053f90179c75b0c55bb0668f437d55493e36069bbd5a3\",\n tokenIndex: 255,\n type: \"amount\",\n },\n },\n };\n\n 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 createAppConfig(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 });\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 createAppConfig(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 });\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 createAppConfig(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 });\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 createAppConfig(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 });\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 createAppConfig(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 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 createAppConfig(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,OACE,iBAAAA,EACA,0BAAAC,EACA,gBAAAC,MACK,kCACP,OAAS,QAAAC,EAAM,QAAAC,EAAM,WAAAC,EAAS,SAAAC,MAAa,YAG3C,OAAS,mCAAAC,MAAuC,oEAChD,OACE,iBAAAC,EACA,cAAAC,EACA,uBAAAC,EACA,sBAAAC,MACK,mCAEP,OAAS,0BAAAC,MAA8B,2BAEvC,SAAS,yBAA0B,IAAM,CACvC,MAAMC,EAAUN,EAAgC,EAC1CO,EAAmB,CACvB,gBAAiB,GAAG,GAAG,EACvB,YAAa,GAAG,GAAG,EACnB,oBAAqB,GAAG,GAAG,EAC3B,cAAe,GAAG,GAAG,EACrB,iBAAkB,GAAG,GAAG,EACxB,qBAAsB,GAAG,GAAG,CAC9B,EACMC,EAAa,CACjB,MAAO,GAAG,GAAG,CACf,EACMC,EAA2B,GAAG,GAAG,EAEvC,SAASC,EACPC,EAC0B,CAC1B,MAAO,CACL,oBAAqB,GACrB,kBAAAA,EACA,gBAAiB,GACjB,QAAS,QACX,CACF,CAEA,MAAMC,EAAY,CAChB,OAAQ,CACN,KAAM,UACN,QAAS,IACT,kBAAmB,4CACrB,EACA,YAAa,eACb,QAAS,CACP,QAAS,CACP,MAAO,6CACP,OAA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ChE,kBAAmB,6CACnB,QAAS,IACT,QAAS,KACT,OAAQK,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,yCAA0C,SAAY,CAEvD,MAAMK,EAAO,IAAIZ,EACfC,EACAC,EACAC,EACAI,EACA,iBACAF,EAAgB,EAAK,EACrBD,CACF,EACAD,EAAW,MAAM,oBAAoBX,EAAK,IAAI,MAAM,eAAe,CAAC,CAAC,EAErE,GAAI,CACF,MAAMoB,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": ["DeviceModelId", "DeviceSessionStateType", "DeviceStatus", "Just", "Left", "Nothing", "Right", "makeDeviceActionInternalApiMock", "PrimitiveType", "StructType", "TypedDataValueField", "TypedDataValueRoot", "BuildEIP712ContextTask", "apiMock", "contextMouleMock", "parserMock", "getWeb3ChecksFactoryMock", "createAppConfig", "web3ChecksEnabled", "TEST_DATA", "TEST_TYPES", "TEST_DOMAIN_VALUES", "TEST_MESSAGE_VALUES", "TEST_CLEAR_SIGN_CONTEXT", "task", "builtContext", "expectedWeb3Check", "e"]
4
+ "sourcesContent": ["import type {\n ClearSignContextSuccess,\n ClearSignContextType,\n TypedDataClearSignContextSuccess,\n} from \"@ledgerhq/context-module\";\nimport { TypedDataCalldataParamPresence } from \"@ledgerhq/context-module\";\nimport {\n CommandResultFactory,\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n} from \"@ledgerhq/device-management-kit\";\nimport { Just, Left, Nothing, Right } from \"purify-ts\";\n\nimport type { GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\nimport { ClearSigningType } from \"@api/model/ClearSigningType\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\nimport { type TransactionMapperService } from \"@internal/transaction/service/mapper/TransactionMapperService\";\nimport { type TransactionParserService } from \"@internal/transaction/service/parser/TransactionParserService\";\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 getFieldContext: vi.fn(),\n getContexts: vi.fn(),\n getTypedDataFilters: vi.fn(),\n getWeb3Checks: vi.fn(),\n getSolanaContext: vi.fn(),\n };\n const parserMock = {\n parse: vi.fn(),\n };\n const mockTransactionParser: TransactionParserService = {\n extractValue: vi.fn(),\n } as unknown as TransactionParserService;\n const mockTransactionMapper: TransactionMapperService = {\n mapTransactionToSubset: vi.fn(),\n };\n const getWeb3ChecksFactoryMock = vi.fn();\n const buildFullContextFactoryMock = vi.fn();\n\n function createAppConfig(\n web3ChecksEnabled: boolean,\n ): GetConfigCommandResponse {\n return {\n blindSigningEnabled: false,\n web3ChecksEnabled,\n web3ChecksOptIn: false,\n version: \"1.13.0\",\n };\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 trustedNamesAddresses: {},\n tokens: {},\n calldatas: {},\n proxy: undefined,\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 const TEST_CHALLENGE = \"0x1234\";\n\n beforeEach(() => {\n vi.resetAllMocks();\n getWeb3ChecksFactoryMock.mockReturnValue({\n run: async () => ({ web3Check: null }),\n });\n buildFullContextFactoryMock.mockReturnValue({\n run: async () => ({\n clearSignContexts: [],\n clearSigningType: ClearSigningType.BASIC,\n }),\n });\n apiMock.sendCommand.mockResolvedValue(\n CommandResultFactory({ data: { challenge: TEST_CHALLENGE } }),\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 mockTransactionParser,\n mockTransactionMapper,\n TEST_DATA,\n \"44'/60'/0'/0/0\",\n createAppConfig(false),\n getWeb3ChecksFactoryMock,\n buildFullContextFactoryMock,\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 derivationPath: \"44'/60'/0'/0/0\",\n web3Check: null,\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n clearSignContext: Nothing,\n calldatasContexts: {},\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 mockTransactionParser,\n mockTransactionMapper,\n TEST_DATA,\n \"44'/60'/0'/0/0\",\n createAppConfig(false),\n getWeb3ChecksFactoryMock,\n buildFullContextFactoryMock,\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 derivationPath: \"44'/60'/0'/0/0\",\n web3Check: null,\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n clearSignContext: Nothing,\n calldatasContexts: {},\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 mockTransactionParser,\n mockTransactionMapper,\n TEST_DATA,\n \"44'/60'/0'/0/0\",\n createAppConfig(false),\n getWeb3ChecksFactoryMock,\n buildFullContextFactoryMock,\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 derivationPath: \"44'/60'/0'/0/0\",\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 calldatasContexts: {},\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 challenge: TEST_CHALLENGE,\n deviceModelId: DeviceModelId.FLEX,\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 mockTransactionParser,\n mockTransactionMapper,\n TEST_DATA,\n \"44'/60'/0'/0/0\",\n createAppConfig(true),\n getWeb3ChecksFactoryMock,\n buildFullContextFactoryMock,\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 derivationPath: \"44'/60'/0'/0/0\",\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 calldatasContexts: {},\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 mockTransactionParser,\n mockTransactionMapper,\n TEST_DATA,\n \"44'/60'/0'/0/0\",\n createAppConfig(false),\n getWeb3ChecksFactoryMock,\n buildFullContextFactoryMock,\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 challenge: TEST_CHALLENGE,\n deviceModelId: DeviceModelId.FLEX,\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 calldatas\", async () => {\n // GIVEN\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n mockTransactionParser,\n mockTransactionMapper,\n TEST_DATA,\n \"44'/60'/0'/0/0\",\n createAppConfig(false),\n getWeb3ChecksFactoryMock,\n buildFullContextFactoryMock,\n );\n const subset = {\n chainId: 0x1234,\n data: \"0x6a76120200000000000000000000000023f8abfc2824c397ccb3da89ae772984107ddb99\",\n from: \"0x8ceb23fd6bc0add59e62ac25578270cff1b9f619\",\n selector: \"0x778899aa\",\n to: \"0x7ceb23fd6bc0add59e62ac25578270cff1b9f619\",\n value: 4200000000000000n,\n };\n const clearSignContext = {\n ...TEST_CLEAR_SIGN_CONTEXT,\n calldatas: {\n 0: {\n filter: {\n calldataIndex: 0,\n displayName: \"Transaction\",\n valueFlag: true,\n calleeFlag: TypedDataCalldataParamPresence.Present,\n chainIdFlag: false,\n selectorFlag: false,\n amountFlag: true,\n spenderFlag: TypedDataCalldataParamPresence.Present,\n signature:\n \"3045022100d8496ab69152efeef6a923a3ebd225334ad65dcb985814994243be7bc09bf27e02206314835816908dd6d51d3cbb0f9465d91d7ddc9104b34dd6c4247f65c551836e\",\n },\n subset,\n },\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 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 clearSignContext,\n );\n buildFullContextFactoryMock.mockReturnValue({\n run: async () => ({\n clearSignContexts: [],\n clearSigningType: ClearSigningType.EIP7730,\n }),\n });\n // WHEN\n const builtContext = await task.run();\n // THEN\n expect(buildFullContextFactoryMock).toHaveBeenCalledWith(\n apiMock,\n expect.objectContaining({\n subset,\n }),\n );\n expect(builtContext).toStrictEqual({\n derivationPath: \"44'/60'/0'/0/0\",\n web3Check: null,\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n clearSignContext: Just(clearSignContext),\n calldatasContexts: {\n 0: [],\n },\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 mockTransactionParser,\n mockTransactionMapper,\n TEST_DATA,\n \"44'/60'/0'/0/0\",\n createAppConfig(false),\n getWeb3ChecksFactoryMock,\n buildFullContextFactoryMock,\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,OAAS,kCAAAA,MAAsC,2BAC/C,OACE,wBAAAC,EACA,iBAAAC,EACA,0BAAAC,EACA,gBAAAC,MACK,kCACP,OAAS,QAAAC,EAAM,QAAAC,EAAM,WAAAC,EAAS,SAAAC,MAAa,YAG3C,OAAS,oBAAAC,MAAwB,8BACjC,OAAS,mCAAAC,MAAuC,oEAGhD,OACE,iBAAAC,EACA,cAAAC,EACA,uBAAAC,EACA,sBAAAC,MACK,mCAEP,OAAS,0BAAAC,MAA8B,2BAEvC,SAAS,yBAA0B,IAAM,CACvC,MAAMC,EAAUN,EAAgC,EA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,CACH,CAAC,EAED,GAAG,yCAA0C,SAAY,CAEvD,MAAMJ,EAAO,IAAIhB,EACfC,EACAC,EACAC,EACAC,EACAC,EACAK,EACA,iBACAF,EAAgB,EAAK,EACrBF,EACAC,CACF,EACAJ,EAAW,MAAM,oBAAoBZ,EAAK,IAAI,MAAM,eAAe,CAAC,CAAC,EAErE,GAAI,CACF,MAAMyB,EAAK,IAAI,CACjB,OAASK,EAAG,CAEV,OAAOA,CAAC,EAAE,eAAe,KAAK,EAE9B,OAAOA,EAAE,OAAO,EAAE,KAAK,eAAe,CACxC,CACF,CAAC,CACH,CAAC",
6
+ "names": ["TypedDataCalldataParamPresence", "CommandResultFactory", "DeviceModelId", "DeviceSessionStateType", "DeviceStatus", "Just", "Left", "Nothing", "Right", "ClearSigningType", "makeDeviceActionInternalApiMock", "PrimitiveType", "StructType", "TypedDataValueField", "TypedDataValueRoot", "BuildEIP712ContextTask", "apiMock", "contextMouleMock", "parserMock", "mockTransactionParser", "mockTransactionMapper", "getWeb3ChecksFactoryMock", "buildFullContextFactoryMock", "createAppConfig", "web3ChecksEnabled", "TEST_DATA", "TEST_TYPES", "TEST_DOMAIN_VALUES", "TEST_MESSAGE_VALUES", "TEST_CLEAR_SIGN_CONTEXT", "TEST_CHALLENGE", "task", "builtContext", "expectedWeb3Check", "subset", "clearSignContext", "e"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{ClearSignContextReferenceType as p,ClearSignContextType as d}from"@ledgerhq/context-module";import{BuildBaseContexts as u}from"./BuildBaseContexts";import{BuildSubcontextsTask as x}from"./BuildSubcontextsTask";import{ParseNestedTransactionTask as C}from"./ParseNestedTransactionTask";class i{constructor(n,a,o=(t,e)=>new x(t,e),r=(t,e)=>new u(t,e),s=t=>new C(t)){this._api=n;this._args=a;this._buildSubcontextsTaskFactory=o;this._buildBaseContextsTaskFactory=r;this._preBuildNestedCallDataTaskFactory=s}async run(){const{clearSignContexts:n,clearSigningType:a,clearSignContextsOptional:o}=await this._buildBaseContextsTaskFactory(this._api,this._args).run(),r=n.map(t=>{const{subcontextCallbacks:e}=this._buildSubcontextsTaskFactory(this._api,{context:t,contextOptional:o,contextModule:this._args.contextModule,subset:this._args.subset,transactionParser:this._args.parser,deviceModelId:this._args.deviceModelId}).run();return{context:t,subcontextCallbacks:e}});let s=[];for(const t of r)if(t.context.type===d.TRANSACTION_FIELD_DESCRIPTION&&t.context.reference?.type===p.CALLDATA){const{subsets:e}=this._preBuildNestedCallDataTaskFactory({parser:this._args.parser,subset:this._args.subset,context:t.context}).run();for(const l of e){const{clearSignContexts:c}=await new i(this._api,{...this._args,subset:l},this._buildSubcontextsTaskFactory,this._buildBaseContextsTaskFactory,this._preBuildNestedCallDataTaskFactory).run();s=[...s,...c,t]}}else s.push(t);return{clearSignContexts:s,clearSigningType:a}}}export{i as BuildFullContextsTask};
1
+ import{ClearSignContextReferenceType as p,ClearSignContextType as u}from"@ledgerhq/context-module";import{BuildBaseContexts as d}from"./BuildBaseContexts";import{BuildSubcontextsTask as x}from"./BuildSubcontextsTask";import{ParseNestedTransactionTask as C}from"./ParseNestedTransactionTask";class i{constructor(n,o,a=(t,e)=>new x(t,e),r=(t,e)=>new d(t,e),s=t=>new C(t)){this._api=n;this._args=o;this._buildSubcontextsTaskFactory=a;this._buildBaseContextsTaskFactory=r;this._preBuildNestedCallDataTaskFactory=s}async run(){const{clearSignContexts:n,clearSigningType:o,clearSignContextsOptional:a}=await this._buildBaseContextsTaskFactory(this._api,this._args).run(),r=n.map(t=>{const{subcontextCallbacks:e}=this._buildSubcontextsTaskFactory(this._api,{context:t,contextOptional:a,contextModule:this._args.contextModule,subset:this._args.subset,transactionParser:this._args.parser,deviceModelId:this._args.deviceModelId}).run();return{context:t,subcontextCallbacks:e}}),s=[];for(const t of r)if(s.push(t),t.context.type===u.TRANSACTION_FIELD_DESCRIPTION&&t.context.reference?.type===p.CALLDATA){const{subsets:e}=this._preBuildNestedCallDataTaskFactory({parser:this._args.parser,subset:this._args.subset,context:t.context}).run();for(const l of e){const{clearSignContexts:c}=await new i(this._api,{...this._args,subset:l},this._buildSubcontextsTaskFactory,this._buildBaseContextsTaskFactory,this._preBuildNestedCallDataTaskFactory).run();s.push(...c)}}return{clearSignContexts:s,clearSigningType:o}}}export{i as BuildFullContextsTask};
2
2
  //# sourceMappingURL=BuildFullContextsTask.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/internal/app-binder/task/BuildFullContextsTask.ts"],
4
- "sourcesContent": ["import {\n type ClearSignContext,\n ClearSignContextReferenceType,\n type ClearSignContextSuccess,\n ClearSignContextType,\n type ContextModule,\n type TransactionSubset,\n} from \"@ledgerhq/context-module\";\nimport {\n type DeviceModelId,\n type InternalApi,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { type GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\nimport { type ClearSigningType } from \"@api/model/ClearSigningType\";\nimport { type TransactionOptions } from \"@api/model/TransactionOptions\";\nimport { type TransactionMapperService } from \"@internal/transaction/service/mapper/TransactionMapperService\";\nimport { type TransactionParserService } from \"@internal/transaction/service/parser/TransactionParserService\";\n\nimport {\n BuildBaseContexts,\n type BuildBaseContextsArgs,\n} from \"./BuildBaseContexts\";\nimport {\n BuildSubcontextsTask,\n type BuildSubcontextsTaskArgs,\n} from \"./BuildSubcontextsTask\";\nimport {\n ParseNestedTransactionTask,\n type ParseNestedTransactionTaskArgs,\n} from \"./ParseNestedTransactionTask\";\n\nexport type BuildFullContextsTaskResult = {\n readonly clearSignContexts: ContextWithSubContexts[];\n readonly clearSigningType: ClearSigningType;\n};\n\nexport type BuildFullContextsTaskArgs = {\n readonly contextModule: ContextModule;\n readonly mapper: TransactionMapperService;\n readonly parser: TransactionParserService;\n readonly options: TransactionOptions;\n readonly appConfig: GetConfigCommandResponse;\n readonly derivationPath: string;\n readonly subset: TransactionSubset;\n readonly deviceModelId: DeviceModelId;\n readonly transaction?: Uint8Array;\n};\n\nexport type ContextWithSubContexts = {\n context: ClearSignContextSuccess;\n subcontextCallbacks: (() => Promise<ClearSignContext>)[];\n};\n\nexport class BuildFullContextsTask {\n constructor(\n private readonly _api: InternalApi,\n private readonly _args: BuildFullContextsTaskArgs,\n private readonly _buildSubcontextsTaskFactory = (\n api: InternalApi,\n args: BuildSubcontextsTaskArgs,\n ) => new BuildSubcontextsTask(api, args),\n private readonly _buildBaseContextsTaskFactory = (\n api: InternalApi,\n args: BuildBaseContextsArgs,\n ) => new BuildBaseContexts(api, args),\n private readonly _preBuildNestedCallDataTaskFactory = (\n args: ParseNestedTransactionTaskArgs,\n ) => new ParseNestedTransactionTask(args),\n ) {}\n\n async run(): Promise<BuildFullContextsTaskResult> {\n // get the base contexts\n const { clearSignContexts, clearSigningType, clearSignContextsOptional } =\n await this._buildBaseContextsTaskFactory(this._api, this._args).run();\n\n // for each context, build the subcontexts\n const contextsWithSubContexts: ContextWithSubContexts[] =\n clearSignContexts.map((context: ClearSignContextSuccess) => {\n const { subcontextCallbacks } = this._buildSubcontextsTaskFactory(\n this._api,\n {\n context,\n contextOptional: clearSignContextsOptional,\n contextModule: this._args.contextModule,\n subset: this._args.subset,\n transactionParser: this._args.parser,\n deviceModelId: this._args.deviceModelId,\n },\n ).run();\n\n return {\n context,\n subcontextCallbacks,\n };\n });\n\n // recursively build the nested contexts\n let contextWithNestedContexts: ContextWithSubContexts[] = [];\n for (const context of contextsWithSubContexts) {\n if (\n context.context.type ===\n ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION &&\n context.context.reference?.type ===\n ClearSignContextReferenceType.CALLDATA\n ) {\n const { subsets } = this._preBuildNestedCallDataTaskFactory({\n parser: this._args.parser,\n subset: this._args.subset,\n context: context.context,\n }).run();\n\n for (const subset of subsets) {\n const { clearSignContexts: nestedContexts } =\n await new BuildFullContextsTask(\n this._api,\n {\n ...this._args,\n subset,\n },\n // inject the factories for testing\n this._buildSubcontextsTaskFactory,\n this._buildBaseContextsTaskFactory,\n this._preBuildNestedCallDataTaskFactory,\n ).run();\n\n // TODO: this order will change with app optimizations\n // currently the order is:\n // previous contexts, nested transaction info and nested fields, calldata field from the parent,\n // futurre order:\n // previous contexts, nested transaction info, calldata field from the parent, then nested fields\n contextWithNestedContexts = [\n ...contextWithNestedContexts, // previous contexts\n ...nestedContexts, // nested transaction info and nested fields\n context, // calldatafield from the parent,\n ];\n }\n } else {\n contextWithNestedContexts.push(context);\n }\n }\n\n return {\n clearSignContexts: contextWithNestedContexts,\n clearSigningType,\n };\n }\n}\n"],
5
- "mappings": "AAAA,OAEE,iCAAAA,EAEA,wBAAAC,MAGK,2BAYP,OACE,qBAAAC,MAEK,sBACP,OACE,wBAAAC,MAEK,yBACP,OACE,8BAAAC,MAEK,+BAwBA,MAAMC,CAAsB,CACjC,YACmBC,EACAC,EACAC,EAA+B,CAC9CC,EACAC,IACG,IAAIP,EAAqBM,EAAKC,CAAI,EACtBC,EAAgC,CAC/CF,EACAC,IACG,IAAIR,EAAkBO,EAAKC,CAAI,EACnBE,EACfF,GACG,IAAIN,EAA2BM,CAAI,EACxC,CAbiB,UAAAJ,EACA,WAAAC,EACA,kCAAAC,EAIA,mCAAAG,EAIA,wCAAAC,CAGhB,CAEH,MAAM,KAA4C,CAEhD,KAAM,CAAE,kBAAAC,EAAmB,iBAAAC,EAAkB,0BAAAC,CAA0B,EACrE,MAAM,KAAK,8BAA8B,KAAK,KAAM,KAAK,KAAK,EAAE,IAAI,EAGhEC,EACJH,EAAkB,IAAKI,GAAqC,CAC1D,KAAM,CAAE,oBAAAC,CAAoB,EAAI,KAAK,6BACnC,KAAK,KACL,CACE,QAAAD,EACA,gBAAiBF,EACjB,cAAe,KAAK,MAAM,cAC1B,OAAQ,KAAK,MAAM,OACnB,kBAAmB,KAAK,MAAM,OAC9B,cAAe,KAAK,MAAM,aAC5B,CACF,EAAE,IAAI,EAEN,MAAO,CACL,QAAAE,EACA,oBAAAC,CACF,CACF,CAAC,EAGH,IAAIC,EAAsD,CAAC,EAC3D,UAAWF,KAAWD,EACpB,GACEC,EAAQ,QAAQ,OACdhB,EAAqB,+BACvBgB,EAAQ,QAAQ,WAAW,OACzBjB,EAA8B,SAChC,CACA,KAAM,CAAE,QAAAoB,CAAQ,EAAI,KAAK,mCAAmC,CAC1D,OAAQ,KAAK,MAAM,OACnB,OAAQ,KAAK,MAAM,OACnB,QAASH,EAAQ,OACnB,CAAC,EAAE,IAAI,EAEP,UAAWI,KAAUD,EAAS,CAC5B,KAAM,CAAE,kBAAmBE,CAAe,EACxC,MAAM,IAAIjB,EACR,KAAK,KACL,CACE,GAAG,KAAK,MACR,OAAAgB,CACF,EAEA,KAAK,6BACL,KAAK,8BACL,KAAK,kCACP,EAAE,IAAI,EAORF,EAA4B,CAC1B,GAAGA,EACH,GAAGG,EACHL,CACF,CACF,CACF,MACEE,EAA0B,KAAKF,CAAO,EAI1C,MAAO,CACL,kBAAmBE,EACnB,iBAAAL,CACF,CACF,CACF",
4
+ "sourcesContent": ["import {\n type ClearSignContext,\n ClearSignContextReferenceType,\n type ClearSignContextSuccess,\n ClearSignContextType,\n type ContextModule,\n type TransactionSubset,\n} from \"@ledgerhq/context-module\";\nimport {\n type DeviceModelId,\n type InternalApi,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { type GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\nimport { type ClearSigningType } from \"@api/model/ClearSigningType\";\nimport { type TransactionOptions } from \"@api/model/TransactionOptions\";\nimport { type TransactionMapperService } from \"@internal/transaction/service/mapper/TransactionMapperService\";\nimport { type TransactionParserService } from \"@internal/transaction/service/parser/TransactionParserService\";\n\nimport {\n BuildBaseContexts,\n type BuildBaseContextsArgs,\n} from \"./BuildBaseContexts\";\nimport {\n BuildSubcontextsTask,\n type BuildSubcontextsTaskArgs,\n} from \"./BuildSubcontextsTask\";\nimport {\n ParseNestedTransactionTask,\n type ParseNestedTransactionTaskArgs,\n} from \"./ParseNestedTransactionTask\";\n\nexport type BuildFullContextsTaskResult = {\n readonly clearSignContexts: ContextWithSubContexts[];\n readonly clearSigningType: ClearSigningType;\n};\n\nexport type BuildFullContextsTaskArgs = {\n readonly contextModule: ContextModule;\n readonly mapper: TransactionMapperService;\n readonly parser: TransactionParserService;\n readonly options: TransactionOptions;\n readonly appConfig: GetConfigCommandResponse;\n readonly derivationPath: string;\n readonly subset: TransactionSubset;\n readonly deviceModelId: DeviceModelId;\n readonly transaction?: Uint8Array;\n};\n\nexport type ContextWithSubContexts = {\n context: ClearSignContextSuccess;\n subcontextCallbacks: (() => Promise<ClearSignContext>)[];\n};\n\nexport class BuildFullContextsTask {\n constructor(\n private readonly _api: InternalApi,\n private readonly _args: BuildFullContextsTaskArgs,\n private readonly _buildSubcontextsTaskFactory = (\n api: InternalApi,\n args: BuildSubcontextsTaskArgs,\n ) => new BuildSubcontextsTask(api, args),\n private readonly _buildBaseContextsTaskFactory = (\n api: InternalApi,\n args: BuildBaseContextsArgs,\n ) => new BuildBaseContexts(api, args),\n private readonly _preBuildNestedCallDataTaskFactory = (\n args: ParseNestedTransactionTaskArgs,\n ) => new ParseNestedTransactionTask(args),\n ) {}\n\n async run(): Promise<BuildFullContextsTaskResult> {\n // get the base contexts\n const { clearSignContexts, clearSigningType, clearSignContextsOptional } =\n await this._buildBaseContextsTaskFactory(this._api, this._args).run();\n\n // for each context, build the subcontexts\n const contextsWithSubContexts: ContextWithSubContexts[] =\n clearSignContexts.map((context: ClearSignContextSuccess) => {\n const { subcontextCallbacks } = this._buildSubcontextsTaskFactory(\n this._api,\n {\n context,\n contextOptional: clearSignContextsOptional,\n contextModule: this._args.contextModule,\n subset: this._args.subset,\n transactionParser: this._args.parser,\n deviceModelId: this._args.deviceModelId,\n },\n ).run();\n\n return {\n context,\n subcontextCallbacks,\n };\n });\n\n // recursively build the nested contexts\n const contextWithNestedContexts: ContextWithSubContexts[] = [];\n for (const context of contextsWithSubContexts) {\n contextWithNestedContexts.push(context);\n\n if (\n context.context.type ===\n ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION &&\n context.context.reference?.type ===\n ClearSignContextReferenceType.CALLDATA\n ) {\n const { subsets } = this._preBuildNestedCallDataTaskFactory({\n parser: this._args.parser,\n subset: this._args.subset,\n context: context.context,\n }).run();\n\n for (const subset of subsets) {\n const { clearSignContexts: nestedContexts } =\n await new BuildFullContextsTask(\n this._api,\n {\n ...this._args,\n subset,\n },\n // inject the factories for testing\n this._buildSubcontextsTaskFactory,\n this._buildBaseContextsTaskFactory,\n this._preBuildNestedCallDataTaskFactory,\n ).run();\n\n // Contexts order as expected by the Ethereum application:\n // * previous contexts\n // * calldata field from the parent\n // * list of nested transactions infos and nested fields\n contextWithNestedContexts.push(...nestedContexts);\n }\n }\n }\n\n return {\n clearSignContexts: contextWithNestedContexts,\n clearSigningType,\n };\n }\n}\n"],
5
+ "mappings": "AAAA,OAEE,iCAAAA,EAEA,wBAAAC,MAGK,2BAYP,OACE,qBAAAC,MAEK,sBACP,OACE,wBAAAC,MAEK,yBACP,OACE,8BAAAC,MAEK,+BAwBA,MAAMC,CAAsB,CACjC,YACmBC,EACAC,EACAC,EAA+B,CAC9CC,EACAC,IACG,IAAIP,EAAqBM,EAAKC,CAAI,EACtBC,EAAgC,CAC/CF,EACAC,IACG,IAAIR,EAAkBO,EAAKC,CAAI,EACnBE,EACfF,GACG,IAAIN,EAA2BM,CAAI,EACxC,CAbiB,UAAAJ,EACA,WAAAC,EACA,kCAAAC,EAIA,mCAAAG,EAIA,wCAAAC,CAGhB,CAEH,MAAM,KAA4C,CAEhD,KAAM,CAAE,kBAAAC,EAAmB,iBAAAC,EAAkB,0BAAAC,CAA0B,EACrE,MAAM,KAAK,8BAA8B,KAAK,KAAM,KAAK,KAAK,EAAE,IAAI,EAGhEC,EACJH,EAAkB,IAAKI,GAAqC,CAC1D,KAAM,CAAE,oBAAAC,CAAoB,EAAI,KAAK,6BACnC,KAAK,KACL,CACE,QAAAD,EACA,gBAAiBF,EACjB,cAAe,KAAK,MAAM,cAC1B,OAAQ,KAAK,MAAM,OACnB,kBAAmB,KAAK,MAAM,OAC9B,cAAe,KAAK,MAAM,aAC5B,CACF,EAAE,IAAI,EAEN,MAAO,CACL,QAAAE,EACA,oBAAAC,CACF,CACF,CAAC,EAGGC,EAAsD,CAAC,EAC7D,UAAWF,KAAWD,EAGpB,GAFAG,EAA0B,KAAKF,CAAO,EAGpCA,EAAQ,QAAQ,OACdhB,EAAqB,+BACvBgB,EAAQ,QAAQ,WAAW,OACzBjB,EAA8B,SAChC,CACA,KAAM,CAAE,QAAAoB,CAAQ,EAAI,KAAK,mCAAmC,CAC1D,OAAQ,KAAK,MAAM,OACnB,OAAQ,KAAK,MAAM,OACnB,QAASH,EAAQ,OACnB,CAAC,EAAE,IAAI,EAEP,UAAWI,KAAUD,EAAS,CAC5B,KAAM,CAAE,kBAAmBE,CAAe,EACxC,MAAM,IAAIjB,EACR,KAAK,KACL,CACE,GAAG,KAAK,MACR,OAAAgB,CACF,EAEA,KAAK,6BACL,KAAK,8BACL,KAAK,kCACP,EAAE,IAAI,EAMRF,EAA0B,KAAK,GAAGG,CAAc,CAClD,CACF,CAGF,MAAO,CACL,kBAAmBH,EACnB,iBAAAL,CACF,CACF,CACF",
6
6
  "names": ["ClearSignContextReferenceType", "ClearSignContextType", "BuildBaseContexts", "BuildSubcontextsTask", "ParseNestedTransactionTask", "BuildFullContextsTask", "_api", "_args", "_buildSubcontextsTaskFactory", "api", "args", "_buildBaseContextsTaskFactory", "_preBuildNestedCallDataTaskFactory", "clearSignContexts", "clearSigningType", "clearSignContextsOptional", "contextsWithSubContexts", "context", "subcontextCallbacks", "contextWithNestedContexts", "subsets", "subset", "nestedContexts"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{ClearSignContextReferenceType as b,ClearSignContextType as e}from"@ledgerhq/context-module";import{DeviceModelId as x}from"@ledgerhq/device-management-kit";import{ClearSigningType as o}from"../../../api/model/ClearSigningType";import{makeDeviceActionInternalApiMock as A}from"../../app-binder/device-action/__test-utils__/makeInternalApi";import{BuildBaseContexts as N}from"./BuildBaseContexts";import{BuildFullContextsTask as T}from"./BuildFullContextsTask";import{BuildSubcontextsTask as g}from"./BuildSubcontextsTask";import{ParseNestedTransactionTask as O}from"./ParseNestedTransactionTask";describe("BuildFullContextsTask",()=>{const n=A(),c={},l={},p={},i={blindSigningEnabled:!1,web3ChecksEnabled:!1,web3ChecksOptIn:!1,version:"1.0.0"},r={},d={chainId:1,data:"0x",selector:"0x"},u="44'/60'/0'/0/0",y=vi.fn(),C=(a,t)=>({run:y}),s=vi.fn(),S=(a,t)=>({run:s}),k=vi.fn(),I=a=>({run:k});describe("Init",()=>{it("should init with defaults tasks",()=>{const a=new T(n,{contextModule:c,mapper:l,parser:p,options:r,appConfig:i,derivationPath:u,subset:d,deviceModelId:x.STAX});expect(a).toBeDefined(),expect(a._buildSubcontextsTaskFactory(n,{})).toBeInstanceOf(g),expect(a._buildBaseContextsTaskFactory(n,{})).toBeInstanceOf(N),expect(a._preBuildNestedCallDataTaskFactory({})).toBeInstanceOf(O)})}),describe("Happy path",()=>{beforeEach(()=>{vi.resetAllMocks()}),it("should build with no context",async()=>{s.mockReturnValue({clearSignContexts:[],clearSignContextsOptional:[],clearSigningType:o.BASIC});const t=await new T(n,{contextModule:c,mapper:l,parser:p,options:r,appConfig:i,derivationPath:u,subset:d,deviceModelId:x.STAX},C,S,I).run();expect(t).toEqual({clearSignContexts:[],clearSigningType:o.BASIC})}),it("should build with multiple contexts and no subcontexts",async()=>{s.mockReturnValueOnce({clearSignContexts:[{type:e.TRANSACTION_INFO,payload:"payload-1"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"}],clearSigningType:o.EIP7730}),y.mockReturnValue({subcontextCallbacks:[]});const t=await new T(n,{contextModule:c,mapper:l,parser:p,options:r,appConfig:i,derivationPath:u,subset:d,deviceModelId:x.STAX},C,S,I).run();expect(t).toEqual({clearSignContexts:[{context:{type:e.TRANSACTION_INFO,payload:"payload-1"},subcontextCallbacks:[]},{context:{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},subcontextCallbacks:[]},{context:{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},subcontextCallbacks:[]}],clearSigningType:o.EIP7730})}),it("should build with multiple contexts and subcontexts",async()=>{s.mockReturnValueOnce({clearSignContexts:[{type:e.TRANSACTION_INFO,payload:"payload-1"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"}],clearSignContextsOptional:[],clearSigningType:o.EIP7730}),y.mockReturnValueOnce({subcontextCallbacks:[]}),y.mockReturnValueOnce({subcontextCallbacks:[()=>Promise.resolve({type:e.TOKEN,payload:"payload-3"}),()=>Promise.resolve({type:e.TOKEN,payload:"payload-4"})]});const t=await new T(n,{contextModule:c,mapper:l,parser:p,options:r,appConfig:i,derivationPath:u,subset:d,deviceModelId:x.STAX},C,S,I).run();expect(t.clearSignContexts[0]).toEqual({context:{type:e.TRANSACTION_INFO,payload:"payload-1"},subcontextCallbacks:[]}),expect(t.clearSignContexts[1]).toEqual({context:{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},subcontextCallbacks:[expect.any(Function),expect.any(Function)]}),expect(t.clearSignContexts[1].subcontextCallbacks[0]()).resolves.toEqual({type:e.TOKEN,payload:"payload-3"}),expect(t.clearSignContexts[1].subcontextCallbacks[1]()).resolves.toEqual({type:e.TOKEN,payload:"payload-4"})}),it("should build with nested contexts",async()=>{s.mockReturnValueOnce({clearSignContexts:[{type:e.TRANSACTION_INFO,payload:"payload-1"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2",reference:{type:b.CALLDATA,subset:{chainId:1,data:"0x",selector:"0x"}}}],clearSigningType:o.EIP7730}),s.mockReturnValueOnce({clearSignContexts:[{type:e.TRANSACTION_INFO,payload:"payload-3"},{type:e.TOKEN,payload:"payload-4"}],clearSignContextsOptional:[],clearSigningType:o.EIP7730}),y.mockReturnValue({subcontextCallbacks:[]}),k.mockReturnValue({subsets:[{chainId:1,data:"0x",selector:"0x"}]});const t=await new T(n,{contextModule:c,mapper:l,parser:p,options:r,appConfig:i,derivationPath:u,subset:d,deviceModelId:x.STAX},C,S,I).run();expect(t).toEqual({clearSignContexts:expect.any(Array),clearSigningType:o.EIP7730}),expect(t.clearSignContexts[0]).toEqual({context:{type:e.TRANSACTION_INFO,payload:"payload-1"},subcontextCallbacks:[]}),expect(t.clearSignContexts[1]).toEqual({context:{type:e.TRANSACTION_INFO,payload:"payload-3"},subcontextCallbacks:[]}),expect(t.clearSignContexts[2]).toEqual({context:{type:e.TOKEN,payload:"payload-4"},subcontextCallbacks:[]}),expect(t.clearSignContexts[3]).toEqual({context:{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2",reference:{type:b.CALLDATA,subset:{chainId:1,data:"0x",selector:"0x"}}},subcontextCallbacks:[]})})})});
1
+ import{ClearSignContextReferenceType as b,ClearSignContextType as e}from"@ledgerhq/context-module";import{DeviceModelId as x}from"@ledgerhq/device-management-kit";import{ClearSigningType as o}from"../../../api/model/ClearSigningType";import{makeDeviceActionInternalApiMock as A}from"../../app-binder/device-action/__test-utils__/makeInternalApi";import{BuildBaseContexts as N}from"./BuildBaseContexts";import{BuildFullContextsTask as T}from"./BuildFullContextsTask";import{BuildSubcontextsTask as g}from"./BuildSubcontextsTask";import{ParseNestedTransactionTask as O}from"./ParseNestedTransactionTask";describe("BuildFullContextsTask",()=>{const n=A(),c={},l={},p={},i={blindSigningEnabled:!1,web3ChecksEnabled:!1,web3ChecksOptIn:!1,version:"1.0.0"},r={},d={chainId:1,data:"0x",selector:"0x"},u="44'/60'/0'/0/0",y=vi.fn(),C=(a,t)=>({run:y}),s=vi.fn(),S=(a,t)=>({run:s}),k=vi.fn(),I=a=>({run:k});describe("Init",()=>{it("should init with defaults tasks",()=>{const a=new T(n,{contextModule:c,mapper:l,parser:p,options:r,appConfig:i,derivationPath:u,subset:d,deviceModelId:x.STAX});expect(a).toBeDefined(),expect(a._buildSubcontextsTaskFactory(n,{})).toBeInstanceOf(g),expect(a._buildBaseContextsTaskFactory(n,{})).toBeInstanceOf(N),expect(a._preBuildNestedCallDataTaskFactory({})).toBeInstanceOf(O)})}),describe("Happy path",()=>{beforeEach(()=>{vi.resetAllMocks()}),it("should build with no context",async()=>{s.mockReturnValue({clearSignContexts:[],clearSignContextsOptional:[],clearSigningType:o.BASIC});const t=await new T(n,{contextModule:c,mapper:l,parser:p,options:r,appConfig:i,derivationPath:u,subset:d,deviceModelId:x.STAX},C,S,I).run();expect(t).toEqual({clearSignContexts:[],clearSigningType:o.BASIC})}),it("should build with multiple contexts and no subcontexts",async()=>{s.mockReturnValueOnce({clearSignContexts:[{type:e.TRANSACTION_INFO,payload:"payload-1"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"}],clearSigningType:o.EIP7730}),y.mockReturnValue({subcontextCallbacks:[]});const t=await new T(n,{contextModule:c,mapper:l,parser:p,options:r,appConfig:i,derivationPath:u,subset:d,deviceModelId:x.STAX},C,S,I).run();expect(t).toEqual({clearSignContexts:[{context:{type:e.TRANSACTION_INFO,payload:"payload-1"},subcontextCallbacks:[]},{context:{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},subcontextCallbacks:[]},{context:{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},subcontextCallbacks:[]}],clearSigningType:o.EIP7730})}),it("should build with multiple contexts and subcontexts",async()=>{s.mockReturnValueOnce({clearSignContexts:[{type:e.TRANSACTION_INFO,payload:"payload-1"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"}],clearSignContextsOptional:[],clearSigningType:o.EIP7730}),y.mockReturnValueOnce({subcontextCallbacks:[]}),y.mockReturnValueOnce({subcontextCallbacks:[()=>Promise.resolve({type:e.TOKEN,payload:"payload-3"}),()=>Promise.resolve({type:e.TOKEN,payload:"payload-4"})]});const t=await new T(n,{contextModule:c,mapper:l,parser:p,options:r,appConfig:i,derivationPath:u,subset:d,deviceModelId:x.STAX},C,S,I).run();expect(t.clearSignContexts[0]).toEqual({context:{type:e.TRANSACTION_INFO,payload:"payload-1"},subcontextCallbacks:[]}),expect(t.clearSignContexts[1]).toEqual({context:{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},subcontextCallbacks:[expect.any(Function),expect.any(Function)]}),await expect(t.clearSignContexts[1].subcontextCallbacks[0]()).resolves.toEqual({type:e.TOKEN,payload:"payload-3"}),await expect(t.clearSignContexts[1].subcontextCallbacks[1]()).resolves.toEqual({type:e.TOKEN,payload:"payload-4"})}),it("should build with nested contexts",async()=>{s.mockReturnValueOnce({clearSignContexts:[{type:e.TRANSACTION_INFO,payload:"payload-1"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2",reference:{type:b.CALLDATA,subset:{chainId:1,data:"0x",selector:"0x"}}}],clearSigningType:o.EIP7730}),s.mockReturnValueOnce({clearSignContexts:[{type:e.TRANSACTION_INFO,payload:"payload-3"},{type:e.TOKEN,payload:"payload-4"}],clearSignContextsOptional:[],clearSigningType:o.EIP7730}),y.mockReturnValue({subcontextCallbacks:[]}),k.mockReturnValue({subsets:[{chainId:1,data:"0x",selector:"0x"}]});const t=await new T(n,{contextModule:c,mapper:l,parser:p,options:r,appConfig:i,derivationPath:u,subset:d,deviceModelId:x.STAX},C,S,I).run();expect(t).toEqual({clearSignContexts:expect.any(Array),clearSigningType:o.EIP7730}),expect(t.clearSignContexts[0]).toEqual({context:{type:e.TRANSACTION_INFO,payload:"payload-1"},subcontextCallbacks:[]}),expect(t.clearSignContexts[1]).toEqual({context:{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2",reference:{type:b.CALLDATA,subset:{chainId:1,data:"0x",selector:"0x"}}},subcontextCallbacks:[]}),expect(t.clearSignContexts[2]).toEqual({context:{type:e.TRANSACTION_INFO,payload:"payload-3"},subcontextCallbacks:[]}),expect(t.clearSignContexts[3]).toEqual({context:{type:e.TOKEN,payload:"payload-4"},subcontextCallbacks:[]})})})});
2
2
  //# sourceMappingURL=BuildFullContextsTask.test.js.map