@ledgerhq/device-signer-kit-ethereum 1.8.0 → 1.9.0

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 (171) hide show
  1. package/README.md +59 -1
  2. package/lib/cjs/api/SignerEth.js +1 -1
  3. package/lib/cjs/api/SignerEth.js.map +1 -1
  4. package/lib/cjs/api/SignerEthBuilder.test.js +1 -1
  5. package/lib/cjs/api/SignerEthBuilder.test.js.map +2 -2
  6. package/lib/cjs/api/app-binder/VerifySafeAddressDeviceActionTypes.js +2 -0
  7. package/lib/cjs/api/app-binder/VerifySafeAddressDeviceActionTypes.js.map +7 -0
  8. package/lib/cjs/api/model/SafeAddressOptions.js +2 -0
  9. package/lib/cjs/api/model/SafeAddressOptions.js.map +7 -0
  10. package/lib/cjs/internal/DefaultSignerEth.js +1 -1
  11. package/lib/cjs/internal/DefaultSignerEth.js.map +3 -3
  12. package/lib/cjs/internal/app-binder/EthAppBinder.js +1 -1
  13. package/lib/cjs/internal/app-binder/EthAppBinder.js.map +3 -3
  14. package/lib/cjs/internal/app-binder/command/ProvideSafeAccountCommand.js +2 -0
  15. package/lib/cjs/internal/app-binder/command/ProvideSafeAccountCommand.js.map +7 -0
  16. package/lib/cjs/internal/app-binder/command/ProvideSafeAccountCommand.test.js +2 -0
  17. package/lib/cjs/internal/app-binder/command/ProvideSafeAccountCommand.test.js.map +7 -0
  18. package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js +1 -1
  19. package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js.map +3 -3
  20. package/lib/cjs/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.js +2 -0
  21. package/lib/cjs/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.js.map +7 -0
  22. package/lib/cjs/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.test.js +2 -0
  23. package/lib/cjs/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.test.js.map +7 -0
  24. package/lib/cjs/internal/app-binder/task/BuildBaseContexts.js +1 -1
  25. package/lib/cjs/internal/app-binder/task/BuildBaseContexts.js.map +3 -3
  26. package/lib/cjs/internal/app-binder/task/BuildBaseContexts.test.js +1 -1
  27. package/lib/cjs/internal/app-binder/task/BuildBaseContexts.test.js.map +2 -2
  28. package/lib/cjs/internal/app-binder/task/BuildSafeAddressContextTask.js +2 -0
  29. package/lib/cjs/internal/app-binder/task/BuildSafeAddressContextTask.js.map +7 -0
  30. package/lib/cjs/internal/app-binder/task/BuildSafeAddressContextTask.test.js +2 -0
  31. package/lib/cjs/internal/app-binder/task/BuildSafeAddressContextTask.test.js.map +7 -0
  32. package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.js +1 -1
  33. package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.js.map +2 -2
  34. package/lib/cjs/internal/app-binder/task/ProvideContextTask.js +2 -0
  35. package/lib/cjs/internal/app-binder/task/ProvideContextTask.js.map +7 -0
  36. package/lib/cjs/internal/app-binder/task/ProvideContextTask.test.js +2 -0
  37. package/lib/cjs/internal/app-binder/task/ProvideContextTask.test.js.map +7 -0
  38. package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.js +1 -1
  39. package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.js.map +3 -3
  40. package/lib/cjs/internal/app-binder/task/ProvideTransactionContextsTask.js +2 -0
  41. package/lib/cjs/internal/app-binder/task/ProvideTransactionContextsTask.js.map +7 -0
  42. package/lib/cjs/internal/app-binder/task/ProvideTransactionContextsTask.test.js +2 -0
  43. package/lib/cjs/internal/app-binder/task/ProvideTransactionContextsTask.test.js.map +7 -0
  44. package/lib/cjs/internal/di.js +1 -1
  45. package/lib/cjs/internal/di.js.map +3 -3
  46. package/lib/cjs/internal/safe/di/safeModule.js +2 -0
  47. package/lib/cjs/internal/safe/di/safeModule.js.map +7 -0
  48. package/lib/cjs/internal/safe/di/safeModule.test.js +2 -0
  49. package/lib/cjs/internal/safe/di/safeModule.test.js.map +7 -0
  50. package/lib/cjs/internal/safe/di/safeTypes.js +2 -0
  51. package/lib/cjs/internal/safe/di/safeTypes.js.map +7 -0
  52. package/lib/cjs/internal/safe/use-case/VerifySafeAddressUseCase.js +2 -0
  53. package/lib/cjs/internal/safe/use-case/VerifySafeAddressUseCase.js.map +7 -0
  54. package/lib/cjs/internal/safe/use-case/VerifySafeAddressUseCase.test.js +2 -0
  55. package/lib/cjs/internal/safe/use-case/VerifySafeAddressUseCase.test.js.map +7 -0
  56. package/lib/cjs/package.json +2 -2
  57. package/lib/esm/api/SignerEthBuilder.test.js +1 -1
  58. package/lib/esm/api/SignerEthBuilder.test.js.map +2 -2
  59. package/lib/esm/api/app-binder/VerifySafeAddressDeviceActionTypes.js +2 -0
  60. package/lib/esm/api/app-binder/VerifySafeAddressDeviceActionTypes.js.map +7 -0
  61. package/lib/esm/api/model/SafeAddressOptions.js +1 -0
  62. package/lib/esm/api/model/SafeAddressOptions.js.map +7 -0
  63. package/lib/esm/internal/DefaultSignerEth.js +1 -1
  64. package/lib/esm/internal/DefaultSignerEth.js.map +3 -3
  65. package/lib/esm/internal/app-binder/EthAppBinder.js +1 -1
  66. package/lib/esm/internal/app-binder/EthAppBinder.js.map +3 -3
  67. package/lib/esm/internal/app-binder/command/ProvideSafeAccountCommand.js +2 -0
  68. package/lib/esm/internal/app-binder/command/ProvideSafeAccountCommand.js.map +7 -0
  69. package/lib/esm/internal/app-binder/command/ProvideSafeAccountCommand.test.js +2 -0
  70. package/lib/esm/internal/app-binder/command/ProvideSafeAccountCommand.test.js.map +7 -0
  71. package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js +1 -1
  72. package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js.map +3 -3
  73. package/lib/esm/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.js +2 -0
  74. package/lib/esm/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.js.map +7 -0
  75. package/lib/esm/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.test.js +2 -0
  76. package/lib/esm/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.test.js.map +7 -0
  77. package/lib/esm/internal/app-binder/task/BuildBaseContexts.js +1 -1
  78. package/lib/esm/internal/app-binder/task/BuildBaseContexts.js.map +3 -3
  79. package/lib/esm/internal/app-binder/task/BuildBaseContexts.test.js +1 -1
  80. package/lib/esm/internal/app-binder/task/BuildBaseContexts.test.js.map +3 -3
  81. package/lib/esm/internal/app-binder/task/BuildSafeAddressContextTask.js +2 -0
  82. package/lib/esm/internal/app-binder/task/BuildSafeAddressContextTask.js.map +7 -0
  83. package/lib/esm/internal/app-binder/task/BuildSafeAddressContextTask.test.js +2 -0
  84. package/lib/esm/internal/app-binder/task/BuildSafeAddressContextTask.test.js.map +7 -0
  85. package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.js +1 -1
  86. package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.js.map +2 -2
  87. package/lib/esm/internal/app-binder/task/ProvideContextTask.js +2 -0
  88. package/lib/esm/internal/app-binder/task/ProvideContextTask.js.map +7 -0
  89. package/lib/esm/internal/app-binder/task/ProvideContextTask.test.js +2 -0
  90. package/lib/esm/internal/app-binder/task/ProvideContextTask.test.js.map +7 -0
  91. package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.js +1 -1
  92. package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.js.map +3 -3
  93. package/lib/esm/internal/app-binder/task/ProvideTransactionContextsTask.js +2 -0
  94. package/lib/esm/internal/app-binder/task/ProvideTransactionContextsTask.js.map +7 -0
  95. package/lib/esm/internal/app-binder/task/ProvideTransactionContextsTask.test.js +2 -0
  96. package/lib/esm/internal/app-binder/task/ProvideTransactionContextsTask.test.js.map +7 -0
  97. package/lib/esm/internal/di.js +1 -1
  98. package/lib/esm/internal/di.js.map +3 -3
  99. package/lib/esm/internal/safe/di/safeModule.js +2 -0
  100. package/lib/esm/internal/safe/di/safeModule.js.map +7 -0
  101. package/lib/esm/internal/safe/di/safeModule.test.js +2 -0
  102. package/lib/esm/internal/safe/di/safeModule.test.js.map +7 -0
  103. package/lib/esm/internal/safe/di/safeTypes.js +2 -0
  104. package/lib/esm/internal/safe/di/safeTypes.js.map +7 -0
  105. package/lib/esm/internal/safe/use-case/VerifySafeAddressUseCase.js +2 -0
  106. package/lib/esm/internal/safe/use-case/VerifySafeAddressUseCase.js.map +7 -0
  107. package/lib/esm/internal/safe/use-case/VerifySafeAddressUseCase.test.js +2 -0
  108. package/lib/esm/internal/safe/use-case/VerifySafeAddressUseCase.test.js.map +7 -0
  109. package/lib/esm/package.json +2 -2
  110. package/lib/types/api/SignerEth.d.ts +3 -0
  111. package/lib/types/api/SignerEth.d.ts.map +1 -1
  112. package/lib/types/api/app-binder/VerifySafeAddressDeviceActionTypes.d.ts +30 -0
  113. package/lib/types/api/app-binder/VerifySafeAddressDeviceActionTypes.d.ts.map +1 -0
  114. package/lib/types/api/model/SafeAddressOptions.d.ts +5 -0
  115. package/lib/types/api/model/SafeAddressOptions.d.ts.map +1 -0
  116. package/lib/types/internal/DefaultSignerEth.d.ts +3 -0
  117. package/lib/types/internal/DefaultSignerEth.d.ts.map +1 -1
  118. package/lib/types/internal/app-binder/EthAppBinder.d.ts +6 -0
  119. package/lib/types/internal/app-binder/EthAppBinder.d.ts.map +1 -1
  120. package/lib/types/internal/app-binder/command/ProvideSafeAccountCommand.d.ts +34 -0
  121. package/lib/types/internal/app-binder/command/ProvideSafeAccountCommand.d.ts.map +1 -0
  122. package/lib/types/internal/app-binder/command/ProvideSafeAccountCommand.test.d.ts +2 -0
  123. package/lib/types/internal/app-binder/command/ProvideSafeAccountCommand.test.d.ts.map +1 -0
  124. package/lib/types/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.d.ts +3 -3
  125. package/lib/types/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.d.ts.map +1 -1
  126. package/lib/types/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.d.ts +20 -0
  127. package/lib/types/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.d.ts.map +1 -0
  128. package/lib/types/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.test.d.ts +2 -0
  129. package/lib/types/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.test.d.ts.map +1 -0
  130. package/lib/types/internal/app-binder/task/BuildBaseContexts.d.ts +3 -1
  131. package/lib/types/internal/app-binder/task/BuildBaseContexts.d.ts.map +1 -1
  132. package/lib/types/internal/app-binder/task/BuildSafeAddressContextTask.d.ts +19 -0
  133. package/lib/types/internal/app-binder/task/BuildSafeAddressContextTask.d.ts.map +1 -0
  134. package/lib/types/internal/app-binder/task/BuildSafeAddressContextTask.test.d.ts +2 -0
  135. package/lib/types/internal/app-binder/task/BuildSafeAddressContextTask.test.d.ts.map +1 -0
  136. package/lib/types/internal/app-binder/task/BuildSubcontextsTask.d.ts.map +1 -1
  137. package/lib/types/internal/app-binder/task/ProvideContextTask.d.ts +22 -0
  138. package/lib/types/internal/app-binder/task/ProvideContextTask.d.ts.map +1 -0
  139. package/lib/types/internal/app-binder/task/ProvideContextTask.test.d.ts +2 -0
  140. package/lib/types/internal/app-binder/task/ProvideContextTask.test.d.ts.map +1 -0
  141. package/lib/types/internal/app-binder/task/ProvideEIP712ContextTask.d.ts +2 -2
  142. package/lib/types/internal/app-binder/task/ProvideEIP712ContextTask.d.ts.map +1 -1
  143. package/lib/types/internal/app-binder/task/ProvideTransactionContextsTask.d.ts +36 -0
  144. package/lib/types/internal/app-binder/task/ProvideTransactionContextsTask.d.ts.map +1 -0
  145. package/lib/types/internal/app-binder/task/ProvideTransactionContextsTask.test.d.ts +2 -0
  146. package/lib/types/internal/app-binder/task/ProvideTransactionContextsTask.test.d.ts.map +1 -0
  147. package/lib/types/internal/di.d.ts.map +1 -1
  148. package/lib/types/internal/safe/di/safeModule.d.ts +3 -0
  149. package/lib/types/internal/safe/di/safeModule.d.ts.map +1 -0
  150. package/lib/types/internal/safe/di/safeModule.test.d.ts +2 -0
  151. package/lib/types/internal/safe/di/safeModule.test.d.ts.map +1 -0
  152. package/lib/types/internal/safe/di/safeTypes.d.ts +4 -0
  153. package/lib/types/internal/safe/di/safeTypes.d.ts.map +1 -0
  154. package/lib/types/internal/safe/use-case/VerifySafeAddressUseCase.d.ts +9 -0
  155. package/lib/types/internal/safe/use-case/VerifySafeAddressUseCase.d.ts.map +1 -0
  156. package/lib/types/internal/safe/use-case/VerifySafeAddressUseCase.test.d.ts +2 -0
  157. package/lib/types/internal/safe/use-case/VerifySafeAddressUseCase.test.d.ts.map +1 -0
  158. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  159. package/package.json +6 -6
  160. package/lib/cjs/internal/app-binder/task/ProvideContextsTask.js +0 -2
  161. package/lib/cjs/internal/app-binder/task/ProvideContextsTask.js.map +0 -7
  162. package/lib/cjs/internal/app-binder/task/ProvideContextsTask.test.js +0 -2
  163. package/lib/cjs/internal/app-binder/task/ProvideContextsTask.test.js.map +0 -7
  164. package/lib/esm/internal/app-binder/task/ProvideContextsTask.js +0 -2
  165. package/lib/esm/internal/app-binder/task/ProvideContextsTask.js.map +0 -7
  166. package/lib/esm/internal/app-binder/task/ProvideContextsTask.test.js +0 -2
  167. package/lib/esm/internal/app-binder/task/ProvideContextsTask.test.js.map +0 -7
  168. package/lib/types/internal/app-binder/task/ProvideContextsTask.d.ts +0 -44
  169. package/lib/types/internal/app-binder/task/ProvideContextsTask.d.ts.map +0 -1
  170. package/lib/types/internal/app-binder/task/ProvideContextsTask.test.d.ts +0 -2
  171. package/lib/types/internal/app-binder/task/ProvideContextsTask.test.d.ts.map +0 -1
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/internal/app-binder/task/ProvideContextTask.ts"],
4
+ "sourcesContent": ["import {\n type ClearSignContextSuccess,\n ClearSignContextType,\n} from \"@ledgerhq/context-module\";\nimport {\n type CommandResult,\n CommandResultFactory,\n type InternalApi,\n InvalidStatusWordError,\n LoadCertificateCommand,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { ProvideEnumCommand } from \"@internal/app-binder/command/ProvideEnumCommand\";\nimport {\n NetworkConfigurationType,\n ProvideNetworkConfigurationCommand,\n} from \"@internal/app-binder/command/ProvideNetworkConfigurationCommand\";\nimport { ProvideNFTInformationCommand } from \"@internal/app-binder/command/ProvideNFTInformationCommand\";\nimport { ProvideProxyInfoCommand } from \"@internal/app-binder/command/ProvideProxyInfoCommand\";\nimport {\n ProvideSafeAccountCommand,\n ProvideSafeAccountCommandType,\n} from \"@internal/app-binder/command/ProvideSafeAccountCommand\";\nimport { ProvideTokenInformationCommand } from \"@internal/app-binder/command/ProvideTokenInformationCommand\";\nimport { ProvideTransactionFieldDescriptionCommand } from \"@internal/app-binder/command/ProvideTransactionFieldDescriptionCommand\";\nimport { ProvideTransactionInformationCommand } from \"@internal/app-binder/command/ProvideTransactionInformationCommand\";\nimport { ProvideTrustedNameCommand } from \"@internal/app-binder/command/ProvideTrustedNameCommand\";\nimport { ProvideWeb3CheckCommand } from \"@internal/app-binder/command/ProvideWeb3CheckCommand\";\nimport { SetExternalPluginCommand } from \"@internal/app-binder/command/SetExternalPluginCommand\";\nimport { SetPluginCommand } from \"@internal/app-binder/command/SetPluginCommand\";\nimport { type EthErrorCodes } from \"@internal/app-binder/command/utils/ethAppErrors\";\n\nimport {\n SendPayloadInChunksTask,\n type SendPayloadInChunksTaskArgs,\n} from \"./SendPayloadInChunksTask\";\n\nexport type ProvideContextTaskArgs = {\n /**\n * The clear sign context to provide.\n */\n context: ClearSignContextSuccess;\n};\n\nexport type ProvideContextTaskResult = CommandResult<unknown, EthErrorCodes>;\n\n/**\n * This task is responsible for providing a single context to the device.\n */\nexport class ProvideContextTask {\n constructor(\n private _api: InternalApi,\n private _args: ProvideContextTaskArgs,\n private _sendPayloadInChunksTaskFactory = (\n api: InternalApi,\n args: SendPayloadInChunksTaskArgs<unknown>,\n ) => new SendPayloadInChunksTask(api, args),\n ) {}\n\n async run(): Promise<ProvideContextTaskResult> {\n const { type, payload, certificate } = this._args.context;\n\n // if a certificate is provided, we load it before sending the command\n if (certificate) {\n await this._api.sendCommand(\n new LoadCertificateCommand({\n keyUsage: certificate.keyUsageNumber,\n certificate: certificate.payload,\n }),\n );\n }\n\n switch (type) {\n case ClearSignContextType.PLUGIN: {\n return await this._api.sendCommand(new SetPluginCommand({ payload }));\n }\n case ClearSignContextType.EXTERNAL_PLUGIN: {\n return await this._api.sendCommand(\n new SetExternalPluginCommand({ payload }),\n );\n }\n case ClearSignContextType.NFT: {\n return await this._api.sendCommand(\n new ProvideNFTInformationCommand({ payload }),\n );\n }\n case ClearSignContextType.TOKEN: {\n return await this._api.sendCommand(\n new ProvideTokenInformationCommand({ payload }),\n );\n }\n case ClearSignContextType.TRANSACTION_INFO: {\n const transactionInfoResult =\n await this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideTransactionInformationCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n\n return transactionInfoResult;\n }\n case ClearSignContextType.TRUSTED_NAME: {\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideTrustedNameCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n }\n case ClearSignContextType.ENUM:\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideEnumCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n case ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideTransactionFieldDescriptionCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n case ClearSignContextType.WEB3_CHECK:\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideWeb3CheckCommand({\n payload: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n case ClearSignContextType.PROXY_INFO:\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideProxyInfoCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n case ClearSignContextType.DYNAMIC_NETWORK:\n // Dynamic network configuration uses the existing ProvideNetworkConfiguration command\n // but is provided as part of the context flow\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideNetworkConfigurationCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n configurationType: NetworkConfigurationType.CONFIGURATION,\n }),\n }).run();\n case ClearSignContextType.DYNAMIC_NETWORK_ICON: {\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideNetworkConfigurationCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n configurationType: NetworkConfigurationType.ICON,\n }),\n withPayloadLength: false,\n }).run();\n }\n case ClearSignContextType.SAFE:\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideSafeAccountCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n type: ProvideSafeAccountCommandType.SAFE_DESCRIPTOR,\n }),\n }).run();\n case ClearSignContextType.SIGNER:\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideSafeAccountCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n type: ProvideSafeAccountCommandType.SIGNER_DESCRIPTOR,\n }),\n }).run();\n default: {\n const uncoveredType: never = type;\n return CommandResultFactory({\n error: new InvalidStatusWordError(\n `The context type [${uncoveredType}] is not covered`,\n ),\n });\n }\n }\n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B,EACA,eAAiBF,GACf,IAAIlB,EAAmC,CACrC,KAAMkB,EAAK,YACX,aAAcA,EAAK,aACnB,kBAAmBnB,EAAyB,aAC9C,CAAC,CACL,CAAC,EAAE,IAAI,EACT,KAAKL,EAAqB,qBACxB,OAAO,KAAK,gCAAgC,KAAK,KAAM,CACrD,QAAA0B,EACA,eAAiBF,GACf,IAAIlB,EAAmC,CACrC,KAAMkB,EAAK,YACX,aAAcA,EAAK,aACnB,kBAAmBnB,EAAyB,IAC9C,CAAC,EACH,kBAAmB,EACrB,CAAC,EAAE,IAAI,EAET,KAAKL,EAAqB,KACxB,OAAO,KAAK,gCAAgC,KAAK,KAAM,CACrD,QAAA0B,EACA,eAAiBF,GACf,IAAIf,EAA0B,CAC5B,KAAMe,EAAK,YACX,aAAcA,EAAK,aACnB,KAAMd,EAA8B,eACtC,CAAC,CACL,CAAC,EAAE,IAAI,EACT,KAAKV,EAAqB,OACxB,OAAO,KAAK,gCAAgC,KAAK,KAAM,CACrD,QAAA0B,EACA,eAAiBF,GACf,IAAIf,EAA0B,CAC5B,KAAMe,EAAK,YACX,aAAcA,EAAK,aACnB,KAAMd,EAA8B,iBACtC,CAAC,CACL,CAAC,EAAE,IAAI,EACT,QAAS,CACP,MAAMkB,EAAuBH,EAC7B,OAAOxB,EAAqB,CAC1B,MAAO,IAAIC,EACT,qBAAqB0B,CAAa,kBACpC,CACF,CAAC,CACH,CACF,CACF,CACF",
6
+ "names": ["ClearSignContextType", "CommandResultFactory", "InvalidStatusWordError", "LoadCertificateCommand", "ProvideEnumCommand", "NetworkConfigurationType", "ProvideNetworkConfigurationCommand", "ProvideNFTInformationCommand", "ProvideProxyInfoCommand", "ProvideSafeAccountCommand", "ProvideSafeAccountCommandType", "ProvideTokenInformationCommand", "ProvideTransactionFieldDescriptionCommand", "ProvideTransactionInformationCommand", "ProvideTrustedNameCommand", "ProvideWeb3CheckCommand", "SetExternalPluginCommand", "SetPluginCommand", "SendPayloadInChunksTask", "ProvideContextTask", "_api", "_args", "_sendPayloadInChunksTaskFactory", "api", "args", "type", "payload", "certificate", "uncoveredType"]
7
+ }
@@ -0,0 +1,2 @@
1
+ import{ClearSignContextType as a}from"@ledgerhq/context-module";import{CommandResultFactory as u,InvalidStatusWordError as E,LoadCertificateCommand as k}from"@ledgerhq/device-management-kit";import{ProvideEnumCommand as A}from"../../app-binder/command/ProvideEnumCommand";import{NetworkConfigurationType as x,ProvideNetworkConfigurationCommand as T}from"../../app-binder/command/ProvideNetworkConfigurationCommand";import{ProvideNFTInformationCommand as I}from"../../app-binder/command/ProvideNFTInformationCommand";import{ProvideProxyInfoCommand as P}from"../../app-binder/command/ProvideProxyInfoCommand";import{ProvideSafeAccountCommand as h,ProvideSafeAccountCommandType as f}from"../../app-binder/command/ProvideSafeAccountCommand";import{ProvideTokenInformationCommand as C}from"../../app-binder/command/ProvideTokenInformationCommand";import{ProvideTransactionFieldDescriptionCommand as N}from"../../app-binder/command/ProvideTransactionFieldDescriptionCommand";import{ProvideTransactionInformationCommand as v}from"../../app-binder/command/ProvideTransactionInformationCommand";import{ProvideTrustedNameCommand as F}from"../../app-binder/command/ProvideTrustedNameCommand";import{ProvideWeb3CheckCommand as R}from"../../app-binder/command/ProvideWeb3CheckCommand";import{SetExternalPluginCommand as O}from"../../app-binder/command/SetExternalPluginCommand";import{SetPluginCommand as B}from"../../app-binder/command/SetPluginCommand";import{makeDeviceActionInternalApiMock as S}from"../../app-binder/device-action/__test-utils__/makeInternalApi";import{ProvideContextTask as l}from"./ProvideContextTask";import{SendPayloadInChunksTask as D}from"./SendPayloadInChunksTask";describe("ProvideContextTask",()=>{const e=S(),n=u({data:void 0}),y=u({data:void 0,error:{}});beforeEach(()=>{vi.resetAllMocks()}),describe("run",()=>{const r=vi.fn(),s=vi.fn();beforeEach(()=>{vi.clearAllMocks(),s.mockImplementation((t,c)=>({run:()=>r(t,c)}))}),describe("contexts with sendCommand",()=>{it.each([[a.PLUGIN,B],[a.EXTERNAL_PLUGIN,O],[a.NFT,I],[a.TOKEN,C]])("should provide context by calling sendCommand for a %s context",async(t,c)=>{const o={context:{type:t,payload:"payload"}};e.sendCommand.mockResolvedValue(n);const i=await new l(e,o,s).run();expect(i).toEqual(n),expect(e.sendCommand).toHaveBeenCalledTimes(1),expect(e.sendCommand).toHaveBeenCalledWith(expect.any(c))})}),describe("contexts with sendPayloadInChunksTask",()=>{it.each([[a.TRANSACTION_INFO,v],[a.TRUSTED_NAME,F],[a.ENUM,A],[a.TRANSACTION_FIELD_DESCRIPTION,N],[a.WEB3_CHECK,R],[a.PROXY_INFO,P]])("should provide context by calling sendPayloadInChunksTask for a %s context",async(t,c)=>{const o={context:{type:t,payload:"payload"}};r.mockResolvedValue(n);const i=await new l(e,o,s).run();expect(i).toEqual(n),expect(r).toHaveBeenCalledTimes(1),expect(r).toHaveBeenCalledWith(e,{payload:"payload",commandFactory:expect.any(Function)});const d=s.mock.calls[0][1].commandFactory,g={chunkedData:new Uint8Array([1,2,3]),isFirstChunk:!0},w=d(g);expect(w).toBeInstanceOf(c)}),it("should provide context for DYNAMIC_NETWORK with correct configuration type",async()=>{const t={context:{type:a.DYNAMIC_NETWORK,payload:"payload"}};r.mockResolvedValue(n);const o=await new l(e,t,s).run();expect(o).toEqual(n),expect(r).toHaveBeenCalledTimes(1);const i=s.mock.calls[0][1].commandFactory,m={chunkedData:new Uint8Array([1,2,3]),isFirstChunk:!0},d=i(m);expect(d).toBeInstanceOf(T),expect(d.args.configurationType).toBe(x.CONFIGURATION)}),it("should provide context for DYNAMIC_NETWORK_ICON with correct configuration type and withPayloadLength",async()=>{const t={context:{type:a.DYNAMIC_NETWORK_ICON,payload:"payload"}};r.mockResolvedValue(n);const o=await new l(e,t,s).run();expect(o).toEqual(n),expect(r).toHaveBeenCalledTimes(1),expect(r).toHaveBeenCalledWith(e,{payload:"payload",commandFactory:expect.any(Function),withPayloadLength:!1});const i=s.mock.calls[0][1].commandFactory,m={chunkedData:new Uint8Array([1,2,3]),isFirstChunk:!0},d=i(m);expect(d).toBeInstanceOf(T),expect(d.args.configurationType).toBe(x.ICON)}),it("should provide context for SAFE with correct type",async()=>{const t={context:{type:a.SAFE,payload:"payload"}};r.mockResolvedValue(n);const o=await new l(e,t,s).run();expect(o).toEqual(n),expect(r).toHaveBeenCalledTimes(1);const i=s.mock.calls[0][1].commandFactory,m={chunkedData:new Uint8Array([1,2,3]),isFirstChunk:!0},d=i(m);expect(d).toBeInstanceOf(h),expect(d.args.type).toBe(f.SAFE_DESCRIPTOR)}),it("should provide context for SIGNER with correct type",async()=>{const t={context:{type:a.SIGNER,payload:"payload"}};r.mockResolvedValue(n);const o=await new l(e,t,s).run();expect(o).toEqual(n),expect(r).toHaveBeenCalledTimes(1);const i=s.mock.calls[0][1].commandFactory,m={chunkedData:new Uint8Array([1,2,3]),isFirstChunk:!0},d=i(m);expect(d).toBeInstanceOf(h),expect(d.args.type).toBe(f.SIGNER_DESCRIPTOR)})}),describe("with certificate",()=>{it("should load certificate before providing context when certificate is present",async()=>{const t={context:{type:a.TOKEN,payload:"payload",certificate:{keyUsageNumber:1,payload:new Uint8Array([1,2,3])}}};e.sendCommand.mockResolvedValue(n);const o=await new l(e,t,s).run();expect(o).toEqual(n),expect(e.sendCommand).toHaveBeenCalledTimes(2),expect(e.sendCommand).toHaveBeenNthCalledWith(1,expect.any(k)),expect(e.sendCommand).toHaveBeenNthCalledWith(2,expect.any(C))}),it("should load certificate with sendPayloadInChunksTask context",async()=>{const t={context:{type:a.TRANSACTION_INFO,payload:"payload",certificate:{keyUsageNumber:2,payload:new Uint8Array([4,5,6])}}};e.sendCommand.mockResolvedValue(n),r.mockResolvedValue(n);const o=await new l(e,t,s).run();expect(o).toEqual(n),expect(e.sendCommand).toHaveBeenCalledTimes(1),expect(e.sendCommand).toHaveBeenCalledWith(expect.any(k)),expect(r).toHaveBeenCalledTimes(1)}),it("should not load certificate when not present",async()=>{const t={context:{type:a.TOKEN,payload:"payload"}};e.sendCommand.mockResolvedValue(n);const o=await new l(e,t,s).run();expect(o).toEqual(n),expect(e.sendCommand).toHaveBeenCalledTimes(1),expect(e.sendCommand).toHaveBeenCalledWith(expect.any(C))})}),describe("error handling",()=>{it("should return error when sendCommand fails",async()=>{const t={context:{type:a.NFT,payload:"payload"}};e.sendCommand.mockResolvedValue(y);const o=await new l(e,t,s).run();expect(o).toEqual(y)}),it("should return error when sendPayloadInChunksTask fails",async()=>{const t={context:{type:a.TRUSTED_NAME,payload:"payload"}};r.mockResolvedValue(y);const o=await new l(e,t,s).run();expect(o).toEqual(y)}),it("should return error for unsupported context type",async()=>{const t={context:{type:"unsupported",payload:"payload"}},o=await new l(e,t,s).run();expect(o).toEqual(u({error:new E("The context type [unsupported] is not covered")}))})}),describe("factory",()=>{it("should have a default sendPayloadInChunksTaskFactory",()=>{const t={context:{type:a.TOKEN,payload:"payload"}},c=new l(e,t);expect(c._sendPayloadInChunksTaskFactory).toBeDefined();const o=c._sendPayloadInChunksTaskFactory(e,{payload:"payload",commandFactory:()=>new v({data:new Uint8Array,isFirstChunk:!0})});expect(o).toBeInstanceOf(D)})})})});
2
+ //# sourceMappingURL=ProvideContextTask.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/internal/app-binder/task/ProvideContextTask.test.ts"],
4
+ "sourcesContent": ["import {\n type ClearSignContextSuccess,\n ClearSignContextType,\n} from \"@ledgerhq/context-module\";\nimport {\n CommandResultFactory,\n type InternalApi,\n InvalidStatusWordError,\n LoadCertificateCommand,\n type UnknownDeviceExchangeError,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { ProvideEnumCommand } from \"@internal/app-binder/command/ProvideEnumCommand\";\nimport {\n NetworkConfigurationType,\n ProvideNetworkConfigurationCommand,\n} from \"@internal/app-binder/command/ProvideNetworkConfigurationCommand\";\nimport { ProvideNFTInformationCommand } from \"@internal/app-binder/command/ProvideNFTInformationCommand\";\nimport { ProvideProxyInfoCommand } from \"@internal/app-binder/command/ProvideProxyInfoCommand\";\nimport {\n ProvideSafeAccountCommand,\n ProvideSafeAccountCommandType,\n} from \"@internal/app-binder/command/ProvideSafeAccountCommand\";\nimport { ProvideTokenInformationCommand } from \"@internal/app-binder/command/ProvideTokenInformationCommand\";\nimport { ProvideTransactionFieldDescriptionCommand } from \"@internal/app-binder/command/ProvideTransactionFieldDescriptionCommand\";\nimport { ProvideTransactionInformationCommand } from \"@internal/app-binder/command/ProvideTransactionInformationCommand\";\nimport { ProvideTrustedNameCommand } from \"@internal/app-binder/command/ProvideTrustedNameCommand\";\nimport { ProvideWeb3CheckCommand } from \"@internal/app-binder/command/ProvideWeb3CheckCommand\";\nimport { SetExternalPluginCommand } from \"@internal/app-binder/command/SetExternalPluginCommand\";\nimport { SetPluginCommand } from \"@internal/app-binder/command/SetPluginCommand\";\nimport { type EthErrorCodes } from \"@internal/app-binder/command/utils/ethAppErrors\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\n\nimport {\n ProvideContextTask,\n type ProvideContextTaskArgs,\n} from \"./ProvideContextTask\";\nimport {\n SendPayloadInChunksTask,\n type SendPayloadInChunksTaskArgs,\n} from \"./SendPayloadInChunksTask\";\n\ndescribe(\"ProvideContextTask\", () => {\n const api = makeDeviceActionInternalApiMock();\n const successResult = CommandResultFactory<void, EthErrorCodes>({\n data: undefined,\n });\n const errorResult = CommandResultFactory<void, EthErrorCodes>({\n data: undefined,\n error: {} as UnknownDeviceExchangeError,\n });\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n describe(\"run\", () => {\n const sendPayloadInChunksRunMock = vi.fn();\n const sendPayloadInChunksTaskMockFactory = vi.fn();\n\n beforeEach(() => {\n vi.clearAllMocks();\n sendPayloadInChunksTaskMockFactory.mockImplementation(\n (a: InternalApi, args: SendPayloadInChunksTaskArgs<unknown>) =>\n ({\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n run: () => sendPayloadInChunksRunMock(a, args),\n }) as unknown as SendPayloadInChunksTask<unknown>,\n );\n });\n\n describe(\"contexts with sendCommand\", () => {\n it.each([\n [ClearSignContextType.PLUGIN, SetPluginCommand],\n [ClearSignContextType.EXTERNAL_PLUGIN, SetExternalPluginCommand],\n [ClearSignContextType.NFT, ProvideNFTInformationCommand],\n [ClearSignContextType.TOKEN, ProvideTokenInformationCommand],\n ] as const)(\n \"should provide context by calling sendCommand for a %s context\",\n async (contextType, commandClass) => {\n // GIVEN\n const args: ProvideContextTaskArgs = {\n context: {\n type: contextType,\n payload: \"payload\",\n },\n };\n api.sendCommand.mockResolvedValue(successResult);\n\n // WHEN\n const task = new ProvideContextTask(\n api,\n args,\n sendPayloadInChunksTaskMockFactory,\n );\n const result = await task.run();\n\n // THEN\n expect(result).toEqual(successResult);\n expect(api.sendCommand).toHaveBeenCalledTimes(1);\n expect(api.sendCommand).toHaveBeenCalledWith(\n expect.any(commandClass),\n );\n },\n );\n });\n\n describe(\"contexts with sendPayloadInChunksTask\", () => {\n it.each([\n [\n ClearSignContextType.TRANSACTION_INFO,\n ProvideTransactionInformationCommand,\n ],\n [ClearSignContextType.TRUSTED_NAME, ProvideTrustedNameCommand],\n [ClearSignContextType.ENUM, ProvideEnumCommand],\n [\n ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n ProvideTransactionFieldDescriptionCommand,\n ],\n [ClearSignContextType.WEB3_CHECK, ProvideWeb3CheckCommand],\n [ClearSignContextType.PROXY_INFO, ProvideProxyInfoCommand],\n ] as const)(\n \"should provide context by calling sendPayloadInChunksTask for a %s context\",\n async (contextType, commandClass) => {\n // GIVEN\n const args: ProvideContextTaskArgs = {\n context: {\n type: contextType,\n payload: \"payload\",\n } as ClearSignContextSuccess<typeof contextType>,\n };\n sendPayloadInChunksRunMock.mockResolvedValue(successResult);\n\n // WHEN\n const task = new ProvideContextTask(\n api,\n args,\n sendPayloadInChunksTaskMockFactory,\n );\n const result = await task.run();\n\n // THEN\n expect(result).toEqual(successResult);\n expect(sendPayloadInChunksRunMock).toHaveBeenCalledTimes(1);\n expect(sendPayloadInChunksRunMock).toHaveBeenCalledWith(api, {\n payload: \"payload\",\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n commandFactory: expect.any(Function),\n });\n\n // Test that the commandFactory returns the correct command class\n const factoryCall = sendPayloadInChunksTaskMockFactory.mock.calls[0]!;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n const commandFactory = factoryCall[1].commandFactory;\n const mockArgs = {\n chunkedData: new Uint8Array([1, 2, 3]),\n isFirstChunk: true,\n };\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n const command = commandFactory(mockArgs);\n expect(command).toBeInstanceOf(commandClass);\n },\n );\n\n it(\"should provide context for DYNAMIC_NETWORK with correct configuration type\", async () => {\n // GIVEN\n const args: ProvideContextTaskArgs = {\n context: {\n type: ClearSignContextType.DYNAMIC_NETWORK,\n payload: \"payload\",\n },\n };\n sendPayloadInChunksRunMock.mockResolvedValue(successResult);\n\n // WHEN\n const task = new ProvideContextTask(\n api,\n args,\n sendPayloadInChunksTaskMockFactory,\n );\n const result = await task.run();\n\n // THEN\n expect(result).toEqual(successResult);\n expect(sendPayloadInChunksRunMock).toHaveBeenCalledTimes(1);\n\n // Test that the commandFactory returns ProvideNetworkConfigurationCommand with CONFIGURATION type\n const factoryCall = sendPayloadInChunksTaskMockFactory.mock.calls[0]!;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n const commandFactory = factoryCall[1].commandFactory;\n const mockArgs = {\n chunkedData: new Uint8Array([1, 2, 3]),\n isFirstChunk: true,\n };\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n const command = commandFactory(mockArgs);\n expect(command).toBeInstanceOf(ProvideNetworkConfigurationCommand);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n expect(command.args.configurationType).toBe(\n NetworkConfigurationType.CONFIGURATION,\n );\n });\n\n it(\"should provide context for DYNAMIC_NETWORK_ICON with correct configuration type and withPayloadLength\", async () => {\n // GIVEN\n const args: ProvideContextTaskArgs = {\n context: {\n type: ClearSignContextType.DYNAMIC_NETWORK_ICON,\n payload: \"payload\",\n },\n };\n sendPayloadInChunksRunMock.mockResolvedValue(successResult);\n\n // WHEN\n const task = new ProvideContextTask(\n api,\n args,\n sendPayloadInChunksTaskMockFactory,\n );\n const result = await task.run();\n\n // THEN\n expect(result).toEqual(successResult);\n expect(sendPayloadInChunksRunMock).toHaveBeenCalledTimes(1);\n expect(sendPayloadInChunksRunMock).toHaveBeenCalledWith(api, {\n payload: \"payload\",\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n commandFactory: expect.any(Function),\n withPayloadLength: false,\n });\n\n // Test that the commandFactory returns ProvideNetworkConfigurationCommand with ICON type\n const factoryCall = sendPayloadInChunksTaskMockFactory.mock.calls[0]!;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n const commandFactory = factoryCall[1].commandFactory;\n const mockArgs = {\n chunkedData: new Uint8Array([1, 2, 3]),\n isFirstChunk: true,\n };\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n const command = commandFactory(mockArgs);\n expect(command).toBeInstanceOf(ProvideNetworkConfigurationCommand);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n expect(command.args.configurationType).toBe(\n NetworkConfigurationType.ICON,\n );\n });\n\n it(\"should provide context for SAFE with correct type\", async () => {\n // GIVEN\n const args: ProvideContextTaskArgs = {\n context: {\n type: ClearSignContextType.SAFE,\n payload: \"payload\",\n },\n };\n sendPayloadInChunksRunMock.mockResolvedValue(successResult);\n\n // WHEN\n const task = new ProvideContextTask(\n api,\n args,\n sendPayloadInChunksTaskMockFactory,\n );\n const result = await task.run();\n\n // THEN\n expect(result).toEqual(successResult);\n expect(sendPayloadInChunksRunMock).toHaveBeenCalledTimes(1);\n\n // Test that the commandFactory returns ProvideSafeAccountCommand with SAFE_DESCRIPTOR type\n const factoryCall = sendPayloadInChunksTaskMockFactory.mock.calls[0]!;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n const commandFactory = factoryCall[1].commandFactory;\n const mockArgs = {\n chunkedData: new Uint8Array([1, 2, 3]),\n isFirstChunk: true,\n };\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n const command = commandFactory(mockArgs);\n expect(command).toBeInstanceOf(ProvideSafeAccountCommand);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n expect(command.args.type).toBe(\n ProvideSafeAccountCommandType.SAFE_DESCRIPTOR,\n );\n });\n\n it(\"should provide context for SIGNER with correct type\", async () => {\n // GIVEN\n const args: ProvideContextTaskArgs = {\n context: {\n type: ClearSignContextType.SIGNER,\n payload: \"payload\",\n },\n };\n sendPayloadInChunksRunMock.mockResolvedValue(successResult);\n\n // WHEN\n const task = new ProvideContextTask(\n api,\n args,\n sendPayloadInChunksTaskMockFactory,\n );\n const result = await task.run();\n\n // THEN\n expect(result).toEqual(successResult);\n expect(sendPayloadInChunksRunMock).toHaveBeenCalledTimes(1);\n\n // Test that the commandFactory returns ProvideSafeAccountCommand with SIGNER_DESCRIPTOR type\n const factoryCall = sendPayloadInChunksTaskMockFactory.mock.calls[0]!;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n const commandFactory = factoryCall[1].commandFactory;\n const mockArgs = {\n chunkedData: new Uint8Array([1, 2, 3]),\n isFirstChunk: true,\n };\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n const command = commandFactory(mockArgs);\n expect(command).toBeInstanceOf(ProvideSafeAccountCommand);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n expect(command.args.type).toBe(\n ProvideSafeAccountCommandType.SIGNER_DESCRIPTOR,\n );\n });\n });\n\n describe(\"with certificate\", () => {\n it(\"should load certificate before providing context when certificate is present\", async () => {\n // GIVEN\n const args: ProvideContextTaskArgs = {\n context: {\n type: ClearSignContextType.TOKEN,\n payload: \"payload\",\n certificate: {\n keyUsageNumber: 1,\n payload: new Uint8Array([1, 2, 3]),\n },\n },\n };\n api.sendCommand.mockResolvedValue(successResult);\n\n // WHEN\n const task = new ProvideContextTask(\n api,\n args,\n sendPayloadInChunksTaskMockFactory,\n );\n const result = await task.run();\n\n // THEN\n expect(result).toEqual(successResult);\n expect(api.sendCommand).toHaveBeenCalledTimes(2);\n expect(api.sendCommand).toHaveBeenNthCalledWith(\n 1,\n expect.any(LoadCertificateCommand),\n );\n expect(api.sendCommand).toHaveBeenNthCalledWith(\n 2,\n expect.any(ProvideTokenInformationCommand),\n );\n });\n\n it(\"should load certificate with sendPayloadInChunksTask context\", async () => {\n // GIVEN\n const args: ProvideContextTaskArgs = {\n context: {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload\",\n certificate: {\n keyUsageNumber: 2,\n payload: new Uint8Array([4, 5, 6]),\n },\n },\n };\n api.sendCommand.mockResolvedValue(successResult);\n sendPayloadInChunksRunMock.mockResolvedValue(successResult);\n\n // WHEN\n const task = new ProvideContextTask(\n api,\n args,\n sendPayloadInChunksTaskMockFactory,\n );\n const result = await task.run();\n\n // THEN\n expect(result).toEqual(successResult);\n expect(api.sendCommand).toHaveBeenCalledTimes(1);\n expect(api.sendCommand).toHaveBeenCalledWith(\n expect.any(LoadCertificateCommand),\n );\n expect(sendPayloadInChunksRunMock).toHaveBeenCalledTimes(1);\n });\n\n it(\"should not load certificate when not present\", async () => {\n // GIVEN\n const args: ProvideContextTaskArgs = {\n context: {\n type: ClearSignContextType.TOKEN,\n payload: \"payload\",\n },\n };\n api.sendCommand.mockResolvedValue(successResult);\n\n // WHEN\n const task = new ProvideContextTask(\n api,\n args,\n sendPayloadInChunksTaskMockFactory,\n );\n const result = await task.run();\n\n // THEN\n expect(result).toEqual(successResult);\n expect(api.sendCommand).toHaveBeenCalledTimes(1);\n expect(api.sendCommand).toHaveBeenCalledWith(\n expect.any(ProvideTokenInformationCommand),\n );\n });\n });\n\n describe(\"error handling\", () => {\n it(\"should return error when sendCommand fails\", async () => {\n // GIVEN\n const args: ProvideContextTaskArgs = {\n context: {\n type: ClearSignContextType.NFT,\n payload: \"payload\",\n },\n };\n api.sendCommand.mockResolvedValue(errorResult);\n\n // WHEN\n const task = new ProvideContextTask(\n api,\n args,\n sendPayloadInChunksTaskMockFactory,\n );\n const result = await task.run();\n\n // THEN\n expect(result).toEqual(errorResult);\n });\n\n it(\"should return error when sendPayloadInChunksTask fails\", async () => {\n // GIVEN\n const args: ProvideContextTaskArgs = {\n context: {\n type: ClearSignContextType.TRUSTED_NAME,\n payload: \"payload\",\n },\n };\n sendPayloadInChunksRunMock.mockResolvedValue(errorResult);\n\n // WHEN\n const task = new ProvideContextTask(\n api,\n args,\n sendPayloadInChunksTaskMockFactory,\n );\n const result = await task.run();\n\n // THEN\n expect(result).toEqual(errorResult);\n });\n\n it(\"should return error for unsupported context type\", async () => {\n // GIVEN\n const args: ProvideContextTaskArgs = {\n context: {\n type: \"unsupported\" as unknown as ClearSignContextType.TOKEN,\n payload: \"payload\",\n },\n };\n\n // WHEN\n const task = new ProvideContextTask(\n api,\n args,\n sendPayloadInChunksTaskMockFactory,\n );\n const result = await task.run();\n\n // THEN\n expect(result).toEqual(\n CommandResultFactory({\n error: new InvalidStatusWordError(\n `The context type [unsupported] is not covered`,\n ),\n }),\n );\n });\n });\n\n describe(\"factory\", () => {\n it(\"should have a default sendPayloadInChunksTaskFactory\", () => {\n // GIVEN\n const args: ProvideContextTaskArgs = {\n context: {\n type: ClearSignContextType.TOKEN,\n payload: \"payload\",\n },\n };\n\n // WHEN\n const task = new ProvideContextTask(api, args);\n\n // THEN\n expect(task[\"_sendPayloadInChunksTaskFactory\"]).toBeDefined();\n const sendPayloadInChunksTask = task[\"_sendPayloadInChunksTaskFactory\"](\n api,\n {\n payload: \"payload\",\n commandFactory: () =>\n new ProvideTransactionInformationCommand({\n data: new Uint8Array(),\n isFirstChunk: true,\n }),\n },\n );\n expect(sendPayloadInChunksTask).toBeInstanceOf(SendPayloadInChunksTask);\n });\n });\n });\n});\n"],
5
+ "mappings": "AAAA,OAEE,wBAAAA,MACK,2BACP,OACE,wBAAAC,EAEA,0BAAAC,EACA,0BAAAC,MAEK,kCAEP,OAAS,sBAAAC,MAA0B,kDACnC,OACE,4BAAAC,EACA,sCAAAC,MACK,kEACP,OAAS,gCAAAC,MAAoC,4DAC7C,OAAS,2BAAAC,MAA+B,uDACxC,OACE,6BAAAC,EACA,iCAAAC,MACK,yDACP,OAAS,kCAAAC,MAAsC,8DAC/C,OAAS,6CAAAC,MAAiD,yEAC1D,OAAS,wCAAAC,MAA4C,oEACrD,OAAS,6BAAAC,MAAiC,yDAC1C,OAAS,2BAAAC,MAA+B,uDACxC,OAAS,4BAAAC,MAAgC,wDACzC,OAAS,oBAAAC,MAAwB,gDAEjC,OAAS,mCAAAC,MAAuC,oEAEhD,OACE,sBAAAC,MAEK,uBACP,OACE,2BAAAC,MAEK,4BAEP,SAAS,qBAAsB,IAAM,CACnC,MAAMC,EAAMH,EAAgC,EACtCI,EAAgBrB,EAA0C,CAC9D,KAAM,MACR,CAAC,EACKsB,EAActB,EAA0C,CAC5D,KAAM,OACN,MAAO,CAAC,CACV,CAAC,EAED,WAAW,IAAM,CACf,GAAG,cAAc,CACnB,CAAC,EAED,SAAS,MAAO,IAAM,CACpB,MAAMuB,EAA6B,GAAG,GAAG,EACnCC,EAAqC,GAAG,GAAG,EAEjD,WAAW,IAAM,CACf,GAAG,cAAc,EACjBA,EAAmC,mBACjC,CAACC,EAAgBC,KACd,CAEC,IAAK,IAAMH,EAA2BE,EAAGC,CAAI,CAC/C,EACJ,CACF,CAAC,EAED,SAAS,4BAA6B,IAAM,CAC1C,GAAG,KA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,uDAAwD,IAAM,CAE/D,MAAMyB,EAA+B,CACnC,QAAS,CACP,KAAM3B,EAAqB,MAC3B,QAAS,SACX,CACF,EAGMkC,EAAO,IAAIf,EAAmBE,EAAKM,CAAI,EAG7C,OAAOO,EAAK,+BAAkC,EAAE,YAAY,EAC5D,MAAMC,EAA0BD,EAAK,gCACnCb,EACA,CACE,QAAS,UACT,eAAgB,IACd,IAAIR,EAAqC,CACvC,KAAM,IAAI,WACV,aAAc,EAChB,CAAC,CACL,CACF,EACA,OAAOsB,CAAuB,EAAE,eAAef,CAAuB,CACxE,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["ClearSignContextType", "CommandResultFactory", "InvalidStatusWordError", "LoadCertificateCommand", "ProvideEnumCommand", "NetworkConfigurationType", "ProvideNetworkConfigurationCommand", "ProvideNFTInformationCommand", "ProvideProxyInfoCommand", "ProvideSafeAccountCommand", "ProvideSafeAccountCommandType", "ProvideTokenInformationCommand", "ProvideTransactionFieldDescriptionCommand", "ProvideTransactionInformationCommand", "ProvideTrustedNameCommand", "ProvideWeb3CheckCommand", "SetExternalPluginCommand", "SetPluginCommand", "makeDeviceActionInternalApiMock", "ProvideContextTask", "SendPayloadInChunksTask", "api", "successResult", "errorResult", "sendPayloadInChunksRunMock", "sendPayloadInChunksTaskMockFactory", "a", "args", "contextType", "commandClass", "result", "commandFactory", "mockArgs", "command", "task", "sendPayloadInChunksTask"]
7
+ }
@@ -1,2 +1,2 @@
1
- import{TypedDataCalldataParamPresence as h,VERIFYING_CONTRACT_TOKEN_INDEX as S}from"@ledgerhq/context-module";import{ClearSignContextType as d}from"@ledgerhq/context-module";import{bufferToHexaString as R,CommandResultFactory as A,isSuccessCommandResult as c,LoadCertificateCommand as k}from"@ledgerhq/device-management-kit";import{Just as y,Maybe as g,Nothing as u}from"purify-ts";import{GetChallengeCommand as b}from"../../app-binder/command/GetChallengeCommand";import{ProvideProxyInfoCommand as M}from"../../app-binder/command/ProvideProxyInfoCommand";import{ProvideTokenInformationCommand as _}from"../../app-binder/command/ProvideTokenInformationCommand";import{ProvideTrustedNameCommand as V}from"../../app-binder/command/ProvideTrustedNameCommand";import{ProvideWeb3CheckCommand as O}from"../../app-binder/command/ProvideWeb3CheckCommand";import{CalldataParamPresence as f,Eip712FilterType as r,SendEIP712FilteringCommand as o}from"../../app-binder/command/SendEIP712FilteringCommand";import{SendEIP712StructDefinitionCommand as E,StructDefinitionCommand as P}from"../../app-binder/command/SendEIP712StructDefinitionCommand";import{StructImplemType as x}from"../../app-binder/command/SendEIP712StructImplemCommand";import{ProvideContextsTask as J}from"../../app-binder/task/ProvideContextsTask";import{SendEIP712StructImplemTask as I}from"../../app-binder/task/SendEIP712StructImplemTask";import{TypedDataValueField as U}from"../../typed-data/model/Types";import{TypedDataValueArray as F,TypedDataValueRoot as W}from"../../typed-data/model/Types";import{SendPayloadInChunksTask as T}from"./SendPayloadInChunksTask";const N=5;class re{constructor(e,t,n,a=s=>new J(this.api,s)){this.api=e;this.contextModule=t;this.args=n;this.provideContextFactory=a;for(const s of this.args.domain)if(s.path==="chainId"&&s.value instanceof U){const i=BigInt(R(s.value.data));i<=Number.MAX_SAFE_INTEGER&&(this.chainId=y(Number(i)));break}}chainId=u;calldataMetadatas={};async run(){this.args.web3Check&&await this.provideContext(this.args.web3Check),await this.args.clearSignContext.ifJust(async a=>{a.proxy!==void 0&&await this.provideContext(a.proxy)});const e=A({data:void 0}),t=Object.entries(this.args.types).sort(([a],[s])=>a.localeCompare(s));for(const[a,s]of t){const i=await this.api.sendCommand(new E({command:P.Name,name:a}));if(!c(i))return i;for(const[l,m]of Object.entries(s)){const C=await this.api.sendCommand(new E({command:P.Field,name:l,type:m}));if(!c(C))return C}}if(this.args.clearSignContext.isJust()){const a=await this.api.sendCommand(new o({type:r.Activation}));if(!c(a))return a}for(const a of this.args.domain){const i=await this.getImplementationTask(a).run();if(!c(i))return i}if(this.args.clearSignContext.isJust()){const a=this.args.clearSignContext.extract(),s=await this.api.sendCommand(new o({type:r.MessageInfo,displayName:a.messageInfo.displayName,filtersCount:a.messageInfo.filtersCount,signature:a.messageInfo.signature}));if(!c(s))return s}const n={indexes:{},nextIndex:0};for(const a of this.args.message){const s=await this.provideTokenInformation(a,n);if(s.isJust())return s.extract();const i=await this.provideTrustedName(a);if(i.isJust())return i.extract();const l=await this.filterValue(a,n);if(l.isJust()&&!c(l.extract()))return l.extract();const C=await this.getImplementationTask(a).run();if(!c(C))return C;if(await this.tryProvideTransactionContext(),this.args.clearSignContext.isJust()&&a.value instanceof F&&a.value.length===0){const D=Object.entries(this.args.clearSignContext.extract().filters).filter(([p])=>p.startsWith(`${a.path}.[]`)).map(([,p])=>p);for(const p of D){const w=await this.api.sendCommand(new o({type:r.DiscardedPath,path:p.path}));if(!c(w))return w;const v=await this.provideFiltering(p,n,!0);if(!c(v))return v}}}return e}async provideContext({type:e,payload:t,certificate:n}){switch(n&&await this.api.sendCommand(new k({keyUsage:n.keyUsageNumber,certificate:n.payload})),e){case d.WEB3_CHECK:await new T(this.api,{payload:t,commandFactory:a=>new O({payload:a.chunkedData,isFirstChunk:a.isFirstChunk})}).run();break;case d.PROXY_INFO:await new T(this.api,{payload:t,commandFactory:a=>new M({data:a.chunkedData,isFirstChunk:a.isFirstChunk})}).run();break;case d.TOKEN:case d.NFT:case d.TRUSTED_NAME:case d.PLUGIN:case d.EXTERNAL_PLUGIN:case d.ENUM:case d.TRANSACTION_INFO:case d.TRANSACTION_FIELD_DESCRIPTION:case d.DYNAMIC_NETWORK:case d.DYNAMIC_NETWORK_ICON:throw new Error(`Context type ${e} not supported in EIP712 messages`);default:{const a=e;throw new Error(`Unhandled context type ${a}`)}}}getImplementationTask(e){return e.value instanceof W?new I(this.api,{type:x.ROOT,value:e.value.root}):e.value instanceof F?new I(this.api,{type:x.ARRAY,value:e.value.length}):new I(this.api,{type:x.FIELD,value:e.value.data})}async provideTokenInformation(e,t){if(this.args.clearSignContext.isJust()){const n=this.args.clearSignContext.extract().filters[e.path];if(n!==void 0&&(n.type==="amount"||n.type==="token")&&t.indexes[n.tokenIndex]===void 0){const a=n.tokenIndex,i=this.args.clearSignContext.extract().tokens[a];if(i===void 0)return u;const l=await this.api.sendCommand(new _({payload:i}));if(!c(l))return g.of(l);let{tokenIndex:m}=l.data;t.nextIndex=(m+1)%N,Number(a)===S&&(m=S),t.indexes[Number(a)]=m}}return u}async provideTrustedName(e){if(this.args.clearSignContext.isJust()&&this.chainId.isJust()){const t=this.args.clearSignContext.extract(),n=t.filters[e.path],a=t.trustedNamesAddresses[e.path];if(n!==void 0&&n.type==="trusted-name"&&a!==void 0){const s=await this.api.sendCommand(new b);if(!c(s))return y(s);const i=await this.contextModule.getFieldContext({chainId:this.chainId.extract(),address:a,challenge:s.data.challenge,types:n.types,sources:n.sources,deviceModelId:this.args.deviceModelId},d.TRUSTED_NAME);if(i.type===d.TRUSTED_NAME){i.certificate&&await this.api.sendCommand(new k({keyUsage:i.certificate.keyUsageNumber,certificate:i.certificate.payload}));const l=await new T(this.api,{payload:i.payload,commandFactory:m=>new V({data:m.chunkedData,isFirstChunk:m.isFirstChunk})}).run();if(!c(l))return y(l)}}}return u}async filterValue(e,t){if(this.args.clearSignContext.isJust()){const n=this.args.clearSignContext.extract().filters[e.path];if(n===void 0)return u;const a=await this.provideFiltering(n,t,!1);return g.of(a)}return u}async provideFiltering(e,t,n){switch(e.type){case"trusted-name":return await this.api.sendCommand(new o({type:r.TrustedName,discarded:n,displayName:e.displayName,typesAndSourcesPayload:e.typesAndSourcesPayload,signature:e.signature}));case"datetime":return await this.api.sendCommand(new o({type:r.Datetime,discarded:n,displayName:e.displayName,signature:e.signature}));case"raw":return await this.api.sendCommand(new o({type:r.Raw,discarded:n,displayName:e.displayName,signature:e.signature}));case"token":return this.sanitizeDeviceIndex(e.tokenIndex,t),await this.api.sendCommand(new o({type:r.Token,discarded:n,tokenIndex:t.indexes[e.tokenIndex],signature:e.signature}));case"amount":return this.sanitizeDeviceIndex(e.tokenIndex,t),await this.api.sendCommand(new o({type:r.Amount,discarded:n,displayName:e.displayName,tokenIndex:t.indexes[e.tokenIndex],signature:e.signature}));case"calldata-value":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new o({type:r.CalldataValue,discarded:n,calldataIndex:e.calldataIndex,signature:e.signature}));case"calldata-callee":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new o({type:r.CalldataCallee,discarded:n,calldataIndex:e.calldataIndex,signature:e.signature}));case"calldata-spender":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new o({type:r.CalldataSpender,discarded:n,calldataIndex:e.calldataIndex,signature:e.signature}));case"calldata-chain-id":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new o({type:r.CalldataChainId,discarded:n,calldataIndex:e.calldataIndex,signature:e.signature}));case"calldata-selector":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new o({type:r.CalldataSelector,discarded:n,calldataIndex:e.calldataIndex,signature:e.signature}));case"calldata-amount":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new o({type:r.CalldataAmount,discarded:n,calldataIndex:e.calldataIndex,signature:e.signature}));default:{const a=e;throw new Error(`ProvideEIP712ContextTask/provideFiltering - Unhandled filter ${a}`)}}}async provideCalldataInfos(e){if(this.args.clearSignContext.isJust()){if(this.calldataMetadatas[e]!==void 0)return this.calldataMetadatas[e].remainingFilters--,u;const t=this.args.clearSignContext.extract().calldatas[e];if(t===void 0)return u;const a=[t.filter.valueFlag,t.filter.calleeFlag===h.Present,t.filter.chainIdFlag,t.filter.selectorFlag,t.filter.amountFlag,t.filter.spenderFlag===h.Present].filter(s=>s).length;return this.calldataMetadatas[e]={remainingFilters:a-1,contexts:this.args.calldatasContexts[e]},g.of(await this.api.sendCommand(new o({type:r.CalldataInfo,discarded:!1,calldataIndex:e,valueFlag:t.filter.valueFlag,calleeFlag:this.mapCalldataPresence(t.filter.calleeFlag),chainIdFlag:t.filter.chainIdFlag,selectorFlag:t.filter.selectorFlag,amountFlag:t.filter.amountFlag,spenderFlag:this.mapCalldataPresence(t.filter.spenderFlag),signature:t.filter.signature})))}return u}async tryProvideTransactionContext(){for(const e in this.calldataMetadatas){const t=this.calldataMetadatas[e];t.remainingFilters===0&&(t.contexts!==void 0&&await this.provideContextFactory({contexts:t.contexts,derivationPath:this.args.derivationPath}).run(),delete this.calldataMetadatas[e])}}mapCalldataPresence(e){switch(e){case h.None:return f.None;case h.Present:return f.Present;case h.VerifyingContract:return f.VerifyingContract;default:{const t=e;throw new Error(`Unhandled presence ${t}`)}}}sanitizeDeviceIndex(e,t){t.indexes[e]===void 0&&(t.indexes[e]=t.nextIndex,t.nextIndex=(t.nextIndex+1)%N)}}export{re as ProvideEIP712ContextTask};
1
+ import{TypedDataCalldataParamPresence as h,VERIFYING_CONTRACT_TOKEN_INDEX as S}from"@ledgerhq/context-module";import{ClearSignContextType as r}from"@ledgerhq/context-module";import{bufferToHexaString as R,CommandResultFactory as A,isSuccessCommandResult as c,LoadCertificateCommand as E}from"@ledgerhq/device-management-kit";import{Just as y,Maybe as g,Nothing as u}from"purify-ts";import{GetChallengeCommand as b}from"../../app-binder/command/GetChallengeCommand";import{ProvideProxyInfoCommand as M}from"../../app-binder/command/ProvideProxyInfoCommand";import{ProvideTokenInformationCommand as _}from"../../app-binder/command/ProvideTokenInformationCommand";import{ProvideTrustedNameCommand as V}from"../../app-binder/command/ProvideTrustedNameCommand";import{ProvideWeb3CheckCommand as O}from"../../app-binder/command/ProvideWeb3CheckCommand";import{CalldataParamPresence as f,Eip712FilterType as o,SendEIP712FilteringCommand as d}from"../../app-binder/command/SendEIP712FilteringCommand";import{SendEIP712StructDefinitionCommand as k,StructDefinitionCommand as F}from"../../app-binder/command/SendEIP712StructDefinitionCommand";import{StructImplemType as x}from"../../app-binder/command/SendEIP712StructImplemCommand";import{SendEIP712StructImplemTask as I}from"../../app-binder/task/SendEIP712StructImplemTask";import{TypedDataValueField as J}from"../../typed-data/model/Types";import{TypedDataValueArray as P,TypedDataValueRoot as U}from"../../typed-data/model/Types";import{ProvideTransactionContextsTask as W}from"./ProvideTransactionContextsTask";import{SendPayloadInChunksTask as T}from"./SendPayloadInChunksTask";const N=5;class re{constructor(e,t,n,a=s=>new W(this.api,s)){this.api=e;this.contextModule=t;this.args=n;this.provideContextFactory=a;for(const s of this.args.domain)if(s.path==="chainId"&&s.value instanceof J){const i=BigInt(R(s.value.data));i<=Number.MAX_SAFE_INTEGER&&(this.chainId=y(Number(i)));break}}chainId=u;calldataMetadatas={};async run(){this.args.web3Check&&await this.provideContext(this.args.web3Check),await this.args.clearSignContext.ifJust(async a=>{a.proxy!==void 0&&await this.provideContext(a.proxy)});const e=A({data:void 0}),t=Object.entries(this.args.types).sort(([a],[s])=>a.localeCompare(s));for(const[a,s]of t){const i=await this.api.sendCommand(new k({command:F.Name,name:a}));if(!c(i))return i;for(const[l,m]of Object.entries(s)){const C=await this.api.sendCommand(new k({command:F.Field,name:l,type:m}));if(!c(C))return C}}if(this.args.clearSignContext.isJust()){const a=await this.api.sendCommand(new d({type:o.Activation}));if(!c(a))return a}for(const a of this.args.domain){const i=await this.getImplementationTask(a).run();if(!c(i))return i}if(this.args.clearSignContext.isJust()){const a=this.args.clearSignContext.extract(),s=await this.api.sendCommand(new d({type:o.MessageInfo,displayName:a.messageInfo.displayName,filtersCount:a.messageInfo.filtersCount,signature:a.messageInfo.signature}));if(!c(s))return s}const n={indexes:{},nextIndex:0};for(const a of this.args.message){const s=await this.provideTokenInformation(a,n);if(s.isJust())return s.extract();const i=await this.provideTrustedName(a);if(i.isJust())return i.extract();const l=await this.filterValue(a,n);if(l.isJust()&&!c(l.extract()))return l.extract();const C=await this.getImplementationTask(a).run();if(!c(C))return C;if(await this.tryProvideTransactionContext(),this.args.clearSignContext.isJust()&&a.value instanceof P&&a.value.length===0){const D=Object.entries(this.args.clearSignContext.extract().filters).filter(([p])=>p.startsWith(`${a.path}.[]`)).map(([,p])=>p);for(const p of D){const w=await this.api.sendCommand(new d({type:o.DiscardedPath,path:p.path}));if(!c(w))return w;const v=await this.provideFiltering(p,n,!0);if(!c(v))return v}}}return e}async provideContext({type:e,payload:t,certificate:n}){switch(n&&await this.api.sendCommand(new E({keyUsage:n.keyUsageNumber,certificate:n.payload})),e){case r.WEB3_CHECK:await new T(this.api,{payload:t,commandFactory:a=>new O({payload:a.chunkedData,isFirstChunk:a.isFirstChunk})}).run();break;case r.PROXY_INFO:await new T(this.api,{payload:t,commandFactory:a=>new M({data:a.chunkedData,isFirstChunk:a.isFirstChunk})}).run();break;case r.TOKEN:case r.NFT:case r.TRUSTED_NAME:case r.PLUGIN:case r.EXTERNAL_PLUGIN:case r.ENUM:case r.TRANSACTION_INFO:case r.TRANSACTION_FIELD_DESCRIPTION:case r.DYNAMIC_NETWORK:case r.DYNAMIC_NETWORK_ICON:case r.SAFE:case r.SIGNER:throw new Error(`Context type ${e} not supported in EIP712 messages`);default:{const a=e;throw new Error(`Unhandled context type ${a}`)}}}getImplementationTask(e){return e.value instanceof U?new I(this.api,{type:x.ROOT,value:e.value.root}):e.value instanceof P?new I(this.api,{type:x.ARRAY,value:e.value.length}):new I(this.api,{type:x.FIELD,value:e.value.data})}async provideTokenInformation(e,t){if(this.args.clearSignContext.isJust()){const n=this.args.clearSignContext.extract().filters[e.path];if(n!==void 0&&(n.type==="amount"||n.type==="token")&&t.indexes[n.tokenIndex]===void 0){const a=n.tokenIndex,i=this.args.clearSignContext.extract().tokens[a];if(i===void 0)return u;const l=await this.api.sendCommand(new _({payload:i}));if(!c(l))return g.of(l);let{tokenIndex:m}=l.data;t.nextIndex=(m+1)%N,Number(a)===S&&(m=S),t.indexes[Number(a)]=m}}return u}async provideTrustedName(e){if(this.args.clearSignContext.isJust()&&this.chainId.isJust()){const t=this.args.clearSignContext.extract(),n=t.filters[e.path],a=t.trustedNamesAddresses[e.path];if(n!==void 0&&n.type==="trusted-name"&&a!==void 0){const s=await this.api.sendCommand(new b);if(!c(s))return y(s);const i=await this.contextModule.getFieldContext({chainId:this.chainId.extract(),address:a,challenge:s.data.challenge,types:n.types,sources:n.sources,deviceModelId:this.args.deviceModelId},r.TRUSTED_NAME);if(i.type===r.TRUSTED_NAME){i.certificate&&await this.api.sendCommand(new E({keyUsage:i.certificate.keyUsageNumber,certificate:i.certificate.payload}));const l=await new T(this.api,{payload:i.payload,commandFactory:m=>new V({data:m.chunkedData,isFirstChunk:m.isFirstChunk})}).run();if(!c(l))return y(l)}}}return u}async filterValue(e,t){if(this.args.clearSignContext.isJust()){const n=this.args.clearSignContext.extract().filters[e.path];if(n===void 0)return u;const a=await this.provideFiltering(n,t,!1);return g.of(a)}return u}async provideFiltering(e,t,n){switch(e.type){case"trusted-name":return await this.api.sendCommand(new d({type:o.TrustedName,discarded:n,displayName:e.displayName,typesAndSourcesPayload:e.typesAndSourcesPayload,signature:e.signature}));case"datetime":return await this.api.sendCommand(new d({type:o.Datetime,discarded:n,displayName:e.displayName,signature:e.signature}));case"raw":return await this.api.sendCommand(new d({type:o.Raw,discarded:n,displayName:e.displayName,signature:e.signature}));case"token":return this.sanitizeDeviceIndex(e.tokenIndex,t),await this.api.sendCommand(new d({type:o.Token,discarded:n,tokenIndex:t.indexes[e.tokenIndex],signature:e.signature}));case"amount":return this.sanitizeDeviceIndex(e.tokenIndex,t),await this.api.sendCommand(new d({type:o.Amount,discarded:n,displayName:e.displayName,tokenIndex:t.indexes[e.tokenIndex],signature:e.signature}));case"calldata-value":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new d({type:o.CalldataValue,discarded:n,calldataIndex:e.calldataIndex,signature:e.signature}));case"calldata-callee":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new d({type:o.CalldataCallee,discarded:n,calldataIndex:e.calldataIndex,signature:e.signature}));case"calldata-spender":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new d({type:o.CalldataSpender,discarded:n,calldataIndex:e.calldataIndex,signature:e.signature}));case"calldata-chain-id":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new d({type:o.CalldataChainId,discarded:n,calldataIndex:e.calldataIndex,signature:e.signature}));case"calldata-selector":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new d({type:o.CalldataSelector,discarded:n,calldataIndex:e.calldataIndex,signature:e.signature}));case"calldata-amount":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new d({type:o.CalldataAmount,discarded:n,calldataIndex:e.calldataIndex,signature:e.signature}));default:{const a=e;throw new Error(`ProvideEIP712ContextTask/provideFiltering - Unhandled filter ${a}`)}}}async provideCalldataInfos(e){if(this.args.clearSignContext.isJust()){if(this.calldataMetadatas[e]!==void 0)return this.calldataMetadatas[e].remainingFilters--,u;const t=this.args.clearSignContext.extract().calldatas[e];if(t===void 0)return u;const a=[t.filter.valueFlag,t.filter.calleeFlag===h.Present,t.filter.chainIdFlag,t.filter.selectorFlag,t.filter.amountFlag,t.filter.spenderFlag===h.Present].filter(s=>s).length;return this.calldataMetadatas[e]={remainingFilters:a-1,contexts:this.args.calldatasContexts[e]},g.of(await this.api.sendCommand(new d({type:o.CalldataInfo,discarded:!1,calldataIndex:e,valueFlag:t.filter.valueFlag,calleeFlag:this.mapCalldataPresence(t.filter.calleeFlag),chainIdFlag:t.filter.chainIdFlag,selectorFlag:t.filter.selectorFlag,amountFlag:t.filter.amountFlag,spenderFlag:this.mapCalldataPresence(t.filter.spenderFlag),signature:t.filter.signature})))}return u}async tryProvideTransactionContext(){for(const e in this.calldataMetadatas){const t=this.calldataMetadatas[e];t.remainingFilters===0&&(t.contexts!==void 0&&await this.provideContextFactory({contexts:t.contexts,derivationPath:this.args.derivationPath}).run(),delete this.calldataMetadatas[e])}}mapCalldataPresence(e){switch(e){case h.None:return f.None;case h.Present:return f.Present;case h.VerifyingContract:return f.VerifyingContract;default:{const t=e;throw new Error(`Unhandled presence ${t}`)}}}sanitizeDeviceIndex(e,t){t.indexes[e]===void 0&&(t.indexes[e]=t.nextIndex,t.nextIndex=(t.nextIndex+1)%N)}}export{re as ProvideEIP712ContextTask};
2
2
  //# sourceMappingURL=ProvideEIP712ContextTask.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/internal/app-binder/task/ProvideEIP712ContextTask.ts"],
4
- "sourcesContent": ["import {\n type ContextModule,\n type TypedDataCalldataIndex,\n TypedDataCalldataParamPresence,\n type TypedDataClearSignContextSuccess,\n type TypedDataFilter,\n type TypedDataTokenIndex,\n VERIFYING_CONTRACT_TOKEN_INDEX,\n} from \"@ledgerhq/context-module\";\nimport {\n type ClearSignContextSuccess,\n ClearSignContextType,\n} from \"@ledgerhq/context-module\";\nimport type {\n CommandResult,\n DeviceModelId,\n InternalApi,\n} from \"@ledgerhq/device-management-kit\";\nimport {\n bufferToHexaString,\n CommandResultFactory,\n isSuccessCommandResult,\n LoadCertificateCommand,\n} from \"@ledgerhq/device-management-kit\";\nimport { Just, Maybe, Nothing } from \"purify-ts\";\n\nimport { GetChallengeCommand } from \"@internal/app-binder/command/GetChallengeCommand\";\nimport { ProvideProxyInfoCommand } from \"@internal/app-binder/command/ProvideProxyInfoCommand\";\nimport { ProvideTokenInformationCommand } from \"@internal/app-binder/command/ProvideTokenInformationCommand\";\nimport { ProvideTrustedNameCommand } from \"@internal/app-binder/command/ProvideTrustedNameCommand\";\nimport { ProvideWeb3CheckCommand } from \"@internal/app-binder/command/ProvideWeb3CheckCommand\";\nimport {\n CalldataParamPresence,\n Eip712FilterType,\n SendEIP712FilteringCommand,\n} from \"@internal/app-binder/command/SendEIP712FilteringCommand\";\nimport {\n SendEIP712StructDefinitionCommand,\n StructDefinitionCommand,\n} from \"@internal/app-binder/command/SendEIP712StructDefinitionCommand\";\nimport { StructImplemType } from \"@internal/app-binder/command/SendEIP712StructImplemCommand\";\nimport { type EthErrorCodes } from \"@internal/app-binder/command/utils/ethAppErrors\";\nimport { type ContextWithSubContexts } from \"@internal/app-binder/task/BuildFullContextsTask\";\nimport {\n ProvideContextsTask,\n type ProvideContextsTaskArgs,\n} from \"@internal/app-binder/task/ProvideContextsTask\";\nimport { SendEIP712StructImplemTask } from \"@internal/app-binder/task/SendEIP712StructImplemTask\";\nimport { TypedDataValueField } from \"@internal/typed-data/model/Types\";\nimport {\n type FieldName,\n type FieldType,\n type StructName,\n type TypedDataValue,\n TypedDataValueArray,\n TypedDataValueRoot,\n} from \"@internal/typed-data/model/Types\";\n\nimport { SendPayloadInChunksTask } from \"./SendPayloadInChunksTask\";\n\ntype AllSuccessTypes = void | { tokenIndex: number };\n\nexport type ProvideEIP712ContextTaskReturnType = Promise<\n CommandResult<AllSuccessTypes, EthErrorCodes>\n>;\n\nexport type ProvideEIP712ContextTaskArgs = {\n deviceModelId: DeviceModelId;\n derivationPath: string;\n types: Record<StructName, Record<FieldName, FieldType>>;\n domain: Array<TypedDataValue>;\n message: Array<TypedDataValue>;\n clearSignContext: Maybe<TypedDataClearSignContextSuccess>;\n calldatasContexts: Record<TypedDataCalldataIndex, ContextWithSubContexts[]>;\n web3Check: ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK> | null;\n};\n\nconst DEVICE_ASSETS_MAX = 5;\n\ntype DeviceAssetIndexes = {\n indexes: Record<TypedDataTokenIndex, number>;\n nextIndex: number;\n};\n\ntype CalldataFiltersMetadata = {\n remainingFilters: number;\n contexts?: ContextWithSubContexts[];\n};\n\nexport class ProvideEIP712ContextTask {\n private chainId: Maybe<number> = Nothing;\n private calldataMetadatas: Record<\n TypedDataCalldataIndex,\n CalldataFiltersMetadata\n > = {};\n\n constructor(\n private api: InternalApi,\n private contextModule: ContextModule,\n private args: ProvideEIP712ContextTaskArgs,\n private readonly provideContextFactory = (args: ProvideContextsTaskArgs) =>\n new ProvideContextsTask(this.api, args),\n ) {\n for (const domainValue of this.args.domain) {\n if (\n domainValue.path === \"chainId\" &&\n domainValue.value instanceof TypedDataValueField\n ) {\n const val = BigInt(bufferToHexaString(domainValue.value.data));\n if (val <= Number.MAX_SAFE_INTEGER) {\n this.chainId = Just(Number(val));\n }\n break;\n }\n }\n }\n\n async run(): ProvideEIP712ContextTaskReturnType {\n // Send message simulation first\n if (this.args.web3Check) {\n await this.provideContext(this.args.web3Check);\n }\n\n // Send proxy descriptor first if required\n await this.args.clearSignContext.ifJust(async (clearSignContext) => {\n if (clearSignContext.proxy !== undefined) {\n await this.provideContext(clearSignContext.proxy);\n }\n });\n\n const result: CommandResult<AllSuccessTypes, EthErrorCodes> =\n CommandResultFactory<AllSuccessTypes, EthErrorCodes>({ data: undefined });\n\n // Provide the structure definitions.\n // Should be sent before struct implementations, as described here:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#eip712-send-struct-definition\n // Note that those types are used to compute the schema hash, in the device and in ClearSignContexts, as described here:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#eip712-filtering\n // Therefore it should be normalized on both sides: sorted per keys\n const types = Object.entries(this.args.types).sort(([aKey], [bKey]) =>\n aKey.localeCompare(bKey),\n );\n for (const [structName, fields] of types) {\n const structNameResult = await this.api.sendCommand(\n new SendEIP712StructDefinitionCommand({\n command: StructDefinitionCommand.Name,\n name: structName,\n }),\n );\n if (!isSuccessCommandResult(structNameResult)) {\n return structNameResult;\n }\n\n for (const [fieldName, fieldType] of Object.entries(fields)) {\n const fieldResult = await this.api.sendCommand(\n new SendEIP712StructDefinitionCommand({\n command: StructDefinitionCommand.Field,\n name: fieldName,\n type: fieldType,\n }),\n );\n if (!isSuccessCommandResult(fieldResult)) {\n return fieldResult;\n }\n }\n }\n\n // possibly activate the filtering, before sending domain and message implementations, as described here:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#activation\n if (this.args.clearSignContext.isJust()) {\n const activationResult = await this.api.sendCommand(\n new SendEIP712FilteringCommand({ type: Eip712FilterType.Activation }),\n );\n if (!isSuccessCommandResult(activationResult)) {\n return activationResult;\n }\n }\n\n // send domain implementation values.\n for (const value of this.args.domain) {\n const domainImplTask = this.getImplementationTask(value);\n const domainImplResult = await domainImplTask.run();\n if (!isSuccessCommandResult(domainImplResult)) {\n return domainImplResult;\n }\n }\n\n // possibly send MessageInformation filter (between Domain and Message)\n // should be sent between Domain and Message implementations, as described here:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#message-info\n if (this.args.clearSignContext.isJust()) {\n const clearSignContext = this.args.clearSignContext.extract();\n const messageInfoFilterResult = await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.MessageInfo,\n displayName: clearSignContext.messageInfo.displayName,\n filtersCount: clearSignContext.messageInfo.filtersCount,\n signature: clearSignContext.messageInfo.signature,\n }),\n );\n if (!isSuccessCommandResult(messageInfoFilterResult)) {\n return messageInfoFilterResult;\n }\n }\n\n // send message implementation values\n const deviceIndexes: DeviceAssetIndexes = { indexes: {}, nextIndex: 0 };\n for (const value of this.args.message) {\n // 5.1 Provide token descriptors, if any\n // Keep a map of all device indexes for those provided tokens.\n const maybeTokenError = await this.provideTokenInformation(\n value,\n deviceIndexes,\n );\n if (maybeTokenError.isJust()) {\n return maybeTokenError.extract();\n }\n\n // Provide trusted name descriptors, if any\n const maybeNameError = await this.provideTrustedName(value);\n if (maybeNameError.isJust()) {\n return maybeNameError.extract();\n }\n\n // if there's a filter, send it\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#amount-join-token\n const maybeFilterResult = await this.filterValue(value, deviceIndexes);\n if (\n maybeFilterResult.isJust() &&\n !isSuccessCommandResult(maybeFilterResult.extract())\n ) {\n return maybeFilterResult.extract();\n }\n\n // provide message value implementation\n const messageImplTask = this.getImplementationTask(value);\n const messageImplResult = await messageImplTask.run();\n if (!isSuccessCommandResult(messageImplResult)) {\n return messageImplResult;\n }\n\n // if a transaction was embedded in that value, provide the related clear sign context\n await this.tryProvideTransactionContext();\n\n // if the value is an empty array, discard sub-filters since\n // there will be no according sub-values in the message\n if (\n this.args.clearSignContext.isJust() &&\n value.value instanceof TypedDataValueArray &&\n value.value.length === 0\n ) {\n const filters = Object.entries(\n this.args.clearSignContext.extract().filters,\n );\n const discardedFilters = filters\n .filter(([path]) => path.startsWith(`${value.path}.[]`))\n .map(([, filter]) => filter);\n for (const filter of discardedFilters) {\n const discardedPathResult = await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.DiscardedPath,\n path: filter.path,\n }),\n );\n if (!isSuccessCommandResult(discardedPathResult)) {\n return discardedPathResult;\n }\n\n const provideFilteringResult = await this.provideFiltering(\n filter,\n deviceIndexes,\n true,\n );\n if (!isSuccessCommandResult(provideFilteringResult)) {\n return provideFilteringResult;\n }\n }\n }\n }\n\n return result;\n }\n\n async provideContext({\n type,\n payload,\n certificate,\n }: ClearSignContextSuccess) {\n // if a certificate is provided, we load it before sending the command\n if (certificate) {\n await this.api.sendCommand(\n new LoadCertificateCommand({\n keyUsage: certificate.keyUsageNumber,\n certificate: certificate.payload,\n }),\n );\n }\n\n switch (type) {\n case ClearSignContextType.WEB3_CHECK:\n await new SendPayloadInChunksTask(this.api, {\n payload,\n commandFactory: (args) =>\n new ProvideWeb3CheckCommand({\n payload: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n break;\n case ClearSignContextType.PROXY_INFO:\n await new SendPayloadInChunksTask(this.api, {\n payload,\n commandFactory: (args) =>\n new ProvideProxyInfoCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n break;\n case ClearSignContextType.TOKEN:\n case ClearSignContextType.NFT:\n case ClearSignContextType.TRUSTED_NAME:\n case ClearSignContextType.PLUGIN:\n case ClearSignContextType.EXTERNAL_PLUGIN:\n case ClearSignContextType.ENUM:\n case ClearSignContextType.TRANSACTION_INFO:\n case ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:\n case ClearSignContextType.DYNAMIC_NETWORK:\n case ClearSignContextType.DYNAMIC_NETWORK_ICON:\n throw new Error(\n `Context type ${type} not supported in EIP712 messages`,\n );\n default: {\n const uncoveredType: never = type;\n throw new Error(`Unhandled context type ${uncoveredType}`);\n }\n }\n }\n\n getImplementationTask(value: TypedDataValue): SendEIP712StructImplemTask {\n if (value.value instanceof TypedDataValueRoot) {\n return new SendEIP712StructImplemTask(this.api, {\n type: StructImplemType.ROOT,\n value: value.value.root,\n });\n } else if (value.value instanceof TypedDataValueArray) {\n return new SendEIP712StructImplemTask(this.api, {\n type: StructImplemType.ARRAY,\n value: value.value.length,\n });\n } else {\n return new SendEIP712StructImplemTask(this.api, {\n type: StructImplemType.FIELD,\n value: value.value.data,\n });\n }\n }\n\n async provideTokenInformation(\n value: TypedDataValue,\n deviceIndexes: DeviceAssetIndexes,\n ): Promise<Maybe<CommandResult<AllSuccessTypes, EthErrorCodes>>> {\n if (this.args.clearSignContext.isJust()) {\n const filter = this.args.clearSignContext.extract().filters[value.path];\n // tokens descriptors only needed when a tokenIndex is available in filter.\n // it should be sent to the device only 1 time so deviceIndexes has to be checked.\n if (\n filter !== undefined &&\n (filter.type === \"amount\" || filter.type === \"token\") &&\n deviceIndexes.indexes[filter.tokenIndex] === undefined\n ) {\n const descriptorIndex = filter.tokenIndex;\n const tokens = this.args.clearSignContext.extract().tokens;\n const token = tokens[descriptorIndex];\n if (token === undefined) {\n return Nothing;\n }\n\n const provideTokenInfoResult = await this.api.sendCommand(\n new ProvideTokenInformationCommand({ payload: token }),\n );\n if (!isSuccessCommandResult(provideTokenInfoResult)) {\n return Maybe.of(provideTokenInfoResult);\n }\n let { tokenIndex: deviceIndex } = provideTokenInfoResult.data;\n deviceIndexes.nextIndex = (deviceIndex + 1) % DEVICE_ASSETS_MAX;\n\n // the token corresponding to the Verifying Contract of message domain has a special index value, as described here:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#amount-join-value\n if (Number(descriptorIndex) === VERIFYING_CONTRACT_TOKEN_INDEX) {\n deviceIndex = VERIFYING_CONTRACT_TOKEN_INDEX;\n }\n\n deviceIndexes.indexes[Number(descriptorIndex)] = deviceIndex;\n }\n }\n return Nothing;\n }\n\n private async provideTrustedName(\n value: TypedDataValue,\n ): Promise<Maybe<CommandResult<AllSuccessTypes, EthErrorCodes>>> {\n if (this.args.clearSignContext.isJust() && this.chainId.isJust()) {\n const context = this.args.clearSignContext.extract();\n const filter = context.filters[value.path];\n const address = context.trustedNamesAddresses[value.path];\n if (\n filter !== undefined &&\n filter.type === \"trusted-name\" &&\n address !== undefined\n ) {\n const getChallengeResult = await this.api.sendCommand(\n new GetChallengeCommand(),\n );\n if (!isSuccessCommandResult(getChallengeResult)) {\n return Just(getChallengeResult);\n }\n\n const context = await this.contextModule.getFieldContext(\n {\n chainId: this.chainId.extract(),\n address,\n challenge: getChallengeResult.data.challenge,\n types: filter.types,\n sources: filter.sources,\n deviceModelId: this.args.deviceModelId,\n },\n ClearSignContextType.TRUSTED_NAME,\n );\n if (context.type === ClearSignContextType.TRUSTED_NAME) {\n if (context.certificate) {\n await this.api.sendCommand(\n new LoadCertificateCommand({\n keyUsage: context.certificate.keyUsageNumber,\n certificate: context.certificate.payload,\n }),\n );\n }\n const provideNameResult = await new SendPayloadInChunksTask(\n this.api,\n {\n payload: context.payload,\n commandFactory: (args) =>\n new ProvideTrustedNameCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n },\n ).run();\n if (!isSuccessCommandResult(provideNameResult)) {\n return Just(provideNameResult);\n }\n }\n }\n }\n return Nothing;\n }\n\n async filterValue(\n value: TypedDataValue,\n deviceIndexes: DeviceAssetIndexes,\n ): Promise<Maybe<CommandResult<AllSuccessTypes, EthErrorCodes>>> {\n if (this.args.clearSignContext.isJust()) {\n const filter = this.args.clearSignContext.extract().filters[value.path];\n if (filter === undefined) {\n return Nothing;\n }\n // provide the filter\n const filteringResult = await this.provideFiltering(\n filter,\n deviceIndexes,\n false,\n );\n return Maybe.of(filteringResult);\n }\n return Nothing;\n }\n\n async provideFiltering(\n filter: TypedDataFilter,\n deviceIndexes: DeviceAssetIndexes,\n discarded: boolean,\n ): Promise<CommandResult<AllSuccessTypes, EthErrorCodes>> {\n switch (filter.type) {\n case \"trusted-name\":\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.TrustedName,\n discarded,\n displayName: filter.displayName,\n typesAndSourcesPayload: filter.typesAndSourcesPayload,\n signature: filter.signature,\n }),\n );\n case \"datetime\":\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.Datetime,\n discarded,\n displayName: filter.displayName,\n signature: filter.signature,\n }),\n );\n case \"raw\":\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.Raw,\n discarded,\n displayName: filter.displayName,\n signature: filter.signature,\n }),\n );\n case \"token\":\n this.sanitizeDeviceIndex(filter.tokenIndex, deviceIndexes);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.Token,\n discarded,\n tokenIndex: deviceIndexes.indexes[filter.tokenIndex]!,\n signature: filter.signature,\n }),\n );\n case \"amount\":\n this.sanitizeDeviceIndex(filter.tokenIndex, deviceIndexes);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.Amount,\n discarded,\n displayName: filter.displayName,\n tokenIndex: deviceIndexes.indexes[filter.tokenIndex]!,\n signature: filter.signature,\n }),\n );\n case \"calldata-value\":\n await this.provideCalldataInfos(filter.calldataIndex);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.CalldataValue,\n discarded,\n calldataIndex: filter.calldataIndex,\n signature: filter.signature,\n }),\n );\n case \"calldata-callee\":\n await this.provideCalldataInfos(filter.calldataIndex);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.CalldataCallee,\n discarded,\n calldataIndex: filter.calldataIndex,\n signature: filter.signature,\n }),\n );\n case \"calldata-spender\":\n await this.provideCalldataInfos(filter.calldataIndex);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.CalldataSpender,\n discarded,\n calldataIndex: filter.calldataIndex,\n signature: filter.signature,\n }),\n );\n case \"calldata-chain-id\":\n await this.provideCalldataInfos(filter.calldataIndex);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.CalldataChainId,\n discarded,\n calldataIndex: filter.calldataIndex,\n signature: filter.signature,\n }),\n );\n case \"calldata-selector\":\n await this.provideCalldataInfos(filter.calldataIndex);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.CalldataSelector,\n discarded,\n calldataIndex: filter.calldataIndex,\n signature: filter.signature,\n }),\n );\n case \"calldata-amount\":\n await this.provideCalldataInfos(filter.calldataIndex);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.CalldataAmount,\n discarded,\n calldataIndex: filter.calldataIndex,\n signature: filter.signature,\n }),\n );\n default: {\n const unhandledType: never = filter;\n throw new Error(\n `ProvideEIP712ContextTask/provideFiltering - Unhandled filter ${unhandledType}`,\n );\n }\n }\n }\n\n private async provideCalldataInfos(\n calldataIndex: number,\n ): Promise<Maybe<CommandResult<AllSuccessTypes, EthErrorCodes>>> {\n if (this.args.clearSignContext.isJust()) {\n // ensure the calldata info was not already provided to the device\n if (this.calldataMetadatas[calldataIndex] !== undefined) {\n // If already provided, update the remaining filters count\n this.calldataMetadatas[calldataIndex]!.remainingFilters--;\n return Nothing;\n }\n\n // get the calldata infos\n const calldataInfos =\n this.args.clearSignContext.extract().calldatas[calldataIndex];\n if (calldataInfos === undefined) {\n return Nothing;\n }\n\n // Initialize the expected filters count\n const filtersPresence = [\n calldataInfos.filter.valueFlag,\n calldataInfos.filter.calleeFlag ===\n TypedDataCalldataParamPresence.Present,\n calldataInfos.filter.chainIdFlag,\n calldataInfos.filter.selectorFlag,\n calldataInfos.filter.amountFlag,\n calldataInfos.filter.spenderFlag ===\n TypedDataCalldataParamPresence.Present,\n ];\n const filtersCount = filtersPresence.filter((f) => f).length;\n this.calldataMetadatas[calldataIndex] = {\n remainingFilters: filtersCount - 1, // Minus 1 since a filter is already being sent\n contexts: this.args.calldatasContexts[calldataIndex],\n };\n\n // provide the transaction infos filter\n return Maybe.of(\n await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.CalldataInfo,\n discarded: false,\n calldataIndex: calldataIndex,\n valueFlag: calldataInfos.filter.valueFlag,\n calleeFlag: this.mapCalldataPresence(\n calldataInfos.filter.calleeFlag,\n ),\n chainIdFlag: calldataInfos.filter.chainIdFlag,\n selectorFlag: calldataInfos.filter.selectorFlag,\n amountFlag: calldataInfos.filter.amountFlag,\n spenderFlag: this.mapCalldataPresence(\n calldataInfos.filter.spenderFlag,\n ),\n signature: calldataInfos.filter.signature,\n }),\n ),\n );\n }\n return Nothing;\n }\n\n private async tryProvideTransactionContext() {\n for (const calldataIndex in this.calldataMetadatas) {\n const metadata = this.calldataMetadatas[calldataIndex]!;\n if (metadata.remainingFilters === 0) {\n // All the filters and implementations were sent for that TX,\n // the related clear sign contexts should now be provided\n if (metadata.contexts !== undefined) {\n await this.provideContextFactory({\n contexts: metadata.contexts,\n derivationPath: this.args.derivationPath,\n }).run();\n }\n delete this.calldataMetadatas[calldataIndex];\n }\n }\n }\n\n private mapCalldataPresence(\n presence: TypedDataCalldataParamPresence,\n ): CalldataParamPresence {\n switch (presence) {\n case TypedDataCalldataParamPresence.None:\n return CalldataParamPresence.None;\n case TypedDataCalldataParamPresence.Present:\n return CalldataParamPresence.Present;\n case TypedDataCalldataParamPresence.VerifyingContract:\n return CalldataParamPresence.VerifyingContract;\n default: {\n const unhandledPresence: never = presence;\n throw new Error(`Unhandled presence ${unhandledPresence}`);\n }\n }\n }\n\n private sanitizeDeviceIndex(\n descriptorIndex: number,\n deviceIndexes: DeviceAssetIndexes,\n ) {\n // If a token is missing, the device will replace it with a placeholder and use the next available index\n if (deviceIndexes.indexes[descriptorIndex] === undefined) {\n deviceIndexes.ind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7Cd,EAAc,QAAQc,CAAe,EAAId,EAAc,UACvDA,EAAc,WACXA,EAAc,UAAY,GAAKvB,EAEtC,CACF",
6
- "names": ["TypedDataCalldataParamPresence", "VERIFYING_CONTRACT_TOKEN_INDEX", "ClearSignContextType", "bufferToHexaString", "CommandResultFactory", "isSuccessCommandResult", "LoadCertificateCommand", "Just", "Maybe", "Nothing", "GetChallengeCommand", "ProvideProxyInfoCommand", "ProvideTokenInformationCommand", "ProvideTrustedNameCommand", "ProvideWeb3CheckCommand", "CalldataParamPresence", "Eip712FilterType", "SendEIP712FilteringCommand", "SendEIP712StructDefinitionCommand", "StructDefinitionCommand", "StructImplemType", "ProvideContextsTask", "SendEIP712StructImplemTask", "TypedDataValueField", "TypedDataValueArray", "TypedDataValueRoot", "SendPayloadInChunksTask", "DEVICE_ASSETS_MAX", "ProvideEIP712ContextTask", "api", "contextModule", "args", "provideContextFactory", "domainValue", "val", "clearSignContext", "result", "types", "aKey", "bKey", "structName", "fields", "structNameResult", "fieldName", "fieldType", "fieldResult", "activationResult", "value", "domainImplResult", "messageInfoFilterResult", "deviceIndexes", "maybeTokenError", "maybeNameError", "maybeFilterResult", "messageImplResult", "discardedFilters", "path", "filter", "discardedPathResult", "provideFilteringResult", "type", "payload", "certificate", "uncoveredType", "descriptorIndex", "token", "provideTokenInfoResult", "deviceIndex", "context", "address", "getChallengeResult", "provideNameResult", "filteringResult", "discarded", "unhandledType", "calldataIndex", "calldataInfos", "filtersCount", "f", "metadata", "presence", "unhandledPresence"]
4
+ "sourcesContent": ["import {\n type ContextModule,\n type TypedDataCalldataIndex,\n TypedDataCalldataParamPresence,\n type TypedDataClearSignContextSuccess,\n type TypedDataFilter,\n type TypedDataTokenIndex,\n VERIFYING_CONTRACT_TOKEN_INDEX,\n} from \"@ledgerhq/context-module\";\nimport {\n type ClearSignContextSuccess,\n ClearSignContextType,\n} from \"@ledgerhq/context-module\";\nimport type {\n CommandResult,\n DeviceModelId,\n InternalApi,\n} from \"@ledgerhq/device-management-kit\";\nimport {\n bufferToHexaString,\n CommandResultFactory,\n isSuccessCommandResult,\n LoadCertificateCommand,\n} from \"@ledgerhq/device-management-kit\";\nimport { Just, Maybe, Nothing } from \"purify-ts\";\n\nimport { GetChallengeCommand } from \"@internal/app-binder/command/GetChallengeCommand\";\nimport { ProvideProxyInfoCommand } from \"@internal/app-binder/command/ProvideProxyInfoCommand\";\nimport { ProvideTokenInformationCommand } from \"@internal/app-binder/command/ProvideTokenInformationCommand\";\nimport { ProvideTrustedNameCommand } from \"@internal/app-binder/command/ProvideTrustedNameCommand\";\nimport { ProvideWeb3CheckCommand } from \"@internal/app-binder/command/ProvideWeb3CheckCommand\";\nimport {\n CalldataParamPresence,\n Eip712FilterType,\n SendEIP712FilteringCommand,\n} from \"@internal/app-binder/command/SendEIP712FilteringCommand\";\nimport {\n SendEIP712StructDefinitionCommand,\n StructDefinitionCommand,\n} from \"@internal/app-binder/command/SendEIP712StructDefinitionCommand\";\nimport { StructImplemType } from \"@internal/app-binder/command/SendEIP712StructImplemCommand\";\nimport { type EthErrorCodes } from \"@internal/app-binder/command/utils/ethAppErrors\";\nimport { type ContextWithSubContexts } from \"@internal/app-binder/task/BuildFullContextsTask\";\nimport { SendEIP712StructImplemTask } from \"@internal/app-binder/task/SendEIP712StructImplemTask\";\nimport { TypedDataValueField } from \"@internal/typed-data/model/Types\";\nimport {\n type FieldName,\n type FieldType,\n type StructName,\n type TypedDataValue,\n TypedDataValueArray,\n TypedDataValueRoot,\n} from \"@internal/typed-data/model/Types\";\n\nimport {\n ProvideTransactionContextsTask,\n type ProvideTransactionContextsTaskArgs,\n} from \"./ProvideTransactionContextsTask\";\nimport { SendPayloadInChunksTask } from \"./SendPayloadInChunksTask\";\n\ntype AllSuccessTypes = void | { tokenIndex: number };\n\nexport type ProvideEIP712ContextTaskReturnType = Promise<\n CommandResult<AllSuccessTypes, EthErrorCodes>\n>;\n\nexport type ProvideEIP712ContextTaskArgs = {\n deviceModelId: DeviceModelId;\n derivationPath: string;\n types: Record<StructName, Record<FieldName, FieldType>>;\n domain: Array<TypedDataValue>;\n message: Array<TypedDataValue>;\n clearSignContext: Maybe<TypedDataClearSignContextSuccess>;\n calldatasContexts: Record<TypedDataCalldataIndex, ContextWithSubContexts[]>;\n web3Check: ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK> | null;\n};\n\nconst DEVICE_ASSETS_MAX = 5;\n\ntype DeviceAssetIndexes = {\n indexes: Record<TypedDataTokenIndex, number>;\n nextIndex: number;\n};\n\ntype CalldataFiltersMetadata = {\n remainingFilters: number;\n contexts?: ContextWithSubContexts[];\n};\n\nexport class ProvideEIP712ContextTask {\n private chainId: Maybe<number> = Nothing;\n private calldataMetadatas: Record<\n TypedDataCalldataIndex,\n CalldataFiltersMetadata\n > = {};\n\n constructor(\n private api: InternalApi,\n private contextModule: ContextModule,\n private args: ProvideEIP712ContextTaskArgs,\n private readonly provideContextFactory = (\n args: ProvideTransactionContextsTaskArgs,\n ) => new ProvideTransactionContextsTask(this.api, args),\n ) {\n for (const domainValue of this.args.domain) {\n if (\n domainValue.path === \"chainId\" &&\n domainValue.value instanceof TypedDataValueField\n ) {\n const val = BigInt(bufferToHexaString(domainValue.value.data));\n if (val <= Number.MAX_SAFE_INTEGER) {\n this.chainId = Just(Number(val));\n }\n break;\n }\n }\n }\n\n async run(): ProvideEIP712ContextTaskReturnType {\n // Send message simulation first\n if (this.args.web3Check) {\n await this.provideContext(this.args.web3Check);\n }\n\n // Send proxy descriptor first if required\n await this.args.clearSignContext.ifJust(async (clearSignContext) => {\n if (clearSignContext.proxy !== undefined) {\n await this.provideContext(clearSignContext.proxy);\n }\n });\n\n const result: CommandResult<AllSuccessTypes, EthErrorCodes> =\n CommandResultFactory<AllSuccessTypes, EthErrorCodes>({ data: undefined });\n\n // Provide the structure definitions.\n // Should be sent before struct implementations, as described here:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#eip712-send-struct-definition\n // Note that those types are used to compute the schema hash, in the device and in ClearSignContexts, as described here:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#eip712-filtering\n // Therefore it should be normalized on both sides: sorted per keys\n const types = Object.entries(this.args.types).sort(([aKey], [bKey]) =>\n aKey.localeCompare(bKey),\n );\n for (const [structName, fields] of types) {\n const structNameResult = await this.api.sendCommand(\n new SendEIP712StructDefinitionCommand({\n command: StructDefinitionCommand.Name,\n name: structName,\n }),\n );\n if (!isSuccessCommandResult(structNameResult)) {\n return structNameResult;\n }\n\n for (const [fieldName, fieldType] of Object.entries(fields)) {\n const fieldResult = await this.api.sendCommand(\n new SendEIP712StructDefinitionCommand({\n command: StructDefinitionCommand.Field,\n name: fieldName,\n type: fieldType,\n }),\n );\n if (!isSuccessCommandResult(fieldResult)) {\n return fieldResult;\n }\n }\n }\n\n // possibly activate the filtering, before sending domain and message implementations, as described here:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#activation\n if (this.args.clearSignContext.isJust()) {\n const activationResult = await this.api.sendCommand(\n new SendEIP712FilteringCommand({ type: Eip712FilterType.Activation }),\n );\n if (!isSuccessCommandResult(activationResult)) {\n return activationResult;\n }\n }\n\n // send domain implementation values.\n for (const value of this.args.domain) {\n const domainImplTask = this.getImplementationTask(value);\n const domainImplResult = await domainImplTask.run();\n if (!isSuccessCommandResult(domainImplResult)) {\n return domainImplResult;\n }\n }\n\n // possibly send MessageInformation filter (between Domain and Message)\n // should be sent between Domain and Message implementations, as described here:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#message-info\n if (this.args.clearSignContext.isJust()) {\n const clearSignContext = this.args.clearSignContext.extract();\n const messageInfoFilterResult = await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.MessageInfo,\n displayName: clearSignContext.messageInfo.displayName,\n filtersCount: clearSignContext.messageInfo.filtersCount,\n signature: clearSignContext.messageInfo.signature,\n }),\n );\n if (!isSuccessCommandResult(messageInfoFilterResult)) {\n return messageInfoFilterResult;\n }\n }\n\n // send message implementation values\n const deviceIndexes: DeviceAssetIndexes = { indexes: {}, nextIndex: 0 };\n for (const value of this.args.message) {\n // 5.1 Provide token descriptors, if any\n // Keep a map of all device indexes for those provided tokens.\n const maybeTokenError = await this.provideTokenInformation(\n value,\n deviceIndexes,\n );\n if (maybeTokenError.isJust()) {\n return maybeTokenError.extract();\n }\n\n // Provide trusted name descriptors, if any\n const maybeNameError = await this.provideTrustedName(value);\n if (maybeNameError.isJust()) {\n return maybeNameError.extract();\n }\n\n // if there's a filter, send it\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#amount-join-token\n const maybeFilterResult = await this.filterValue(value, deviceIndexes);\n if (\n maybeFilterResult.isJust() &&\n !isSuccessCommandResult(maybeFilterResult.extract())\n ) {\n return maybeFilterResult.extract();\n }\n\n // provide message value implementation\n const messageImplTask = this.getImplementationTask(value);\n const messageImplResult = await messageImplTask.run();\n if (!isSuccessCommandResult(messageImplResult)) {\n return messageImplResult;\n }\n\n // if a transaction was embedded in that value, provide the related clear sign context\n await this.tryProvideTransactionContext();\n\n // if the value is an empty array, discard sub-filters since\n // there will be no according sub-values in the message\n if (\n this.args.clearSignContext.isJust() &&\n value.value instanceof TypedDataValueArray &&\n value.value.length === 0\n ) {\n const filters = Object.entries(\n this.args.clearSignContext.extract().filters,\n );\n const discardedFilters = filters\n .filter(([path]) => path.startsWith(`${value.path}.[]`))\n .map(([, filter]) => filter);\n for (const filter of discardedFilters) {\n const discardedPathResult = await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.DiscardedPath,\n path: filter.path,\n }),\n );\n if (!isSuccessCommandResult(discardedPathResult)) {\n return discardedPathResult;\n }\n\n const provideFilteringResult = await this.provideFiltering(\n filter,\n deviceIndexes,\n true,\n );\n if (!isSuccessCommandResult(provideFilteringResult)) {\n return provideFilteringResult;\n }\n }\n }\n }\n\n return result;\n }\n\n async provideContext({\n type,\n payload,\n certificate,\n }: ClearSignContextSuccess) {\n // if a certificate is provided, we load it before sending the command\n if (certificate) {\n await this.api.sendCommand(\n new LoadCertificateCommand({\n keyUsage: certificate.keyUsageNumber,\n certificate: certificate.payload,\n }),\n );\n }\n\n switch (type) {\n case ClearSignContextType.WEB3_CHECK:\n await new SendPayloadInChunksTask(this.api, {\n payload,\n commandFactory: (args) =>\n new ProvideWeb3CheckCommand({\n payload: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n break;\n case ClearSignContextType.PROXY_INFO:\n await new SendPayloadInChunksTask(this.api, {\n payload,\n commandFactory: (args) =>\n new ProvideProxyInfoCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n break;\n case ClearSignContextType.TOKEN:\n case ClearSignContextType.NFT:\n case ClearSignContextType.TRUSTED_NAME:\n case ClearSignContextType.PLUGIN:\n case ClearSignContextType.EXTERNAL_PLUGIN:\n case ClearSignContextType.ENUM:\n case ClearSignContextType.TRANSACTION_INFO:\n case ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:\n case ClearSignContextType.DYNAMIC_NETWORK:\n case ClearSignContextType.DYNAMIC_NETWORK_ICON:\n case ClearSignContextType.SAFE:\n case ClearSignContextType.SIGNER:\n throw new Error(\n `Context type ${type} not supported in EIP712 messages`,\n );\n default: {\n const uncoveredType: never = type;\n throw new Error(`Unhandled context type ${uncoveredType}`);\n }\n }\n }\n\n getImplementationTask(value: TypedDataValue): SendEIP712StructImplemTask {\n if (value.value instanceof TypedDataValueRoot) {\n return new SendEIP712StructImplemTask(this.api, {\n type: StructImplemType.ROOT,\n value: value.value.root,\n });\n } else if (value.value instanceof TypedDataValueArray) {\n return new SendEIP712StructImplemTask(this.api, {\n type: StructImplemType.ARRAY,\n value: value.value.length,\n });\n } else {\n return new SendEIP712StructImplemTask(this.api, {\n type: StructImplemType.FIELD,\n value: value.value.data,\n });\n }\n }\n\n async provideTokenInformation(\n value: TypedDataValue,\n deviceIndexes: DeviceAssetIndexes,\n ): Promise<Maybe<CommandResult<AllSuccessTypes, EthErrorCodes>>> {\n if (this.args.clearSignContext.isJust()) {\n const filter = this.args.clearSignContext.extract().filters[value.path];\n // tokens descriptors only needed when a tokenIndex is available in filter.\n // it should be sent to the device only 1 time so deviceIndexes has to be checked.\n if (\n filter !== undefined &&\n (filter.type === \"amount\" || filter.type === \"token\") &&\n deviceIndexes.indexes[filter.tokenIndex] === undefined\n ) {\n const descriptorIndex = filter.tokenIndex;\n const tokens = this.args.clearSignContext.extract().tokens;\n const token = tokens[descriptorIndex];\n if (token === undefined) {\n return Nothing;\n }\n\n const provideTokenInfoResult = await this.api.sendCommand(\n new ProvideTokenInformationCommand({ payload: token }),\n );\n if (!isSuccessCommandResult(provideTokenInfoResult)) {\n return Maybe.of(provideTokenInfoResult);\n }\n let { tokenIndex: deviceIndex } = provideTokenInfoResult.data;\n deviceIndexes.nextIndex = (deviceIndex + 1) % DEVICE_ASSETS_MAX;\n\n // the token corresponding to the Verifying Contract of message domain has a special index value, as described here:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#amount-join-value\n if (Number(descriptorIndex) === VERIFYING_CONTRACT_TOKEN_INDEX) {\n deviceIndex = VERIFYING_CONTRACT_TOKEN_INDEX;\n }\n\n deviceIndexes.indexes[Number(descriptorIndex)] = deviceIndex;\n }\n }\n return Nothing;\n }\n\n private async provideTrustedName(\n value: TypedDataValue,\n ): Promise<Maybe<CommandResult<AllSuccessTypes, EthErrorCodes>>> {\n if (this.args.clearSignContext.isJust() && this.chainId.isJust()) {\n const context = this.args.clearSignContext.extract();\n const filter = context.filters[value.path];\n const address = context.trustedNamesAddresses[value.path];\n if (\n filter !== undefined &&\n filter.type === \"trusted-name\" &&\n address !== undefined\n ) {\n const getChallengeResult = await this.api.sendCommand(\n new GetChallengeCommand(),\n );\n if (!isSuccessCommandResult(getChallengeResult)) {\n return Just(getChallengeResult);\n }\n\n const context = await this.contextModule.getFieldContext(\n {\n chainId: this.chainId.extract(),\n address,\n challenge: getChallengeResult.data.challenge,\n types: filter.types,\n sources: filter.sources,\n deviceModelId: this.args.deviceModelId,\n },\n ClearSignContextType.TRUSTED_NAME,\n );\n if (context.type === ClearSignContextType.TRUSTED_NAME) {\n if (context.certificate) {\n await this.api.sendCommand(\n new LoadCertificateCommand({\n keyUsage: context.certificate.keyUsageNumber,\n certificate: context.certificate.payload,\n }),\n );\n }\n const provideNameResult = await new SendPayloadInChunksTask(\n this.api,\n {\n payload: context.payload,\n commandFactory: (args) =>\n new ProvideTrustedNameCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n },\n ).run();\n if (!isSuccessCommandResult(provideNameResult)) {\n return Just(provideNameResult);\n }\n }\n }\n }\n return Nothing;\n }\n\n async filterValue(\n value: TypedDataValue,\n deviceIndexes: DeviceAssetIndexes,\n ): Promise<Maybe<CommandResult<AllSuccessTypes, EthErrorCodes>>> {\n if (this.args.clearSignContext.isJust()) {\n const filter = this.args.clearSignContext.extract().filters[value.path];\n if (filter === undefined) {\n return Nothing;\n }\n // provide the filter\n const filteringResult = await this.provideFiltering(\n filter,\n deviceIndexes,\n false,\n );\n return Maybe.of(filteringResult);\n }\n return Nothing;\n }\n\n async provideFiltering(\n filter: TypedDataFilter,\n deviceIndexes: DeviceAssetIndexes,\n discarded: boolean,\n ): Promise<CommandResult<AllSuccessTypes, EthErrorCodes>> {\n switch (filter.type) {\n case \"trusted-name\":\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.TrustedName,\n discarded,\n displayName: filter.displayName,\n typesAndSourcesPayload: filter.typesAndSourcesPayload,\n signature: filter.signature,\n }),\n );\n case \"datetime\":\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.Datetime,\n discarded,\n displayName: filter.displayName,\n signature: filter.signature,\n }),\n );\n case \"raw\":\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.Raw,\n discarded,\n displayName: filter.displayName,\n signature: filter.signature,\n }),\n );\n case \"token\":\n this.sanitizeDeviceIndex(filter.tokenIndex, deviceIndexes);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.Token,\n discarded,\n tokenIndex: deviceIndexes.indexes[filter.tokenIndex]!,\n signature: filter.signature,\n }),\n );\n case \"amount\":\n this.sanitizeDeviceIndex(filter.tokenIndex, deviceIndexes);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.Amount,\n discarded,\n displayName: filter.displayName,\n tokenIndex: deviceIndexes.indexes[filter.tokenIndex]!,\n signature: filter.signature,\n }),\n );\n case \"calldata-value\":\n await this.provideCalldataInfos(filter.calldataIndex);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.CalldataValue,\n discarded,\n calldataIndex: filter.calldataIndex,\n signature: filter.signature,\n }),\n );\n case \"calldata-callee\":\n await this.provideCalldataInfos(filter.calldataIndex);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.CalldataCallee,\n discarded,\n calldataIndex: filter.calldataIndex,\n signature: filter.signature,\n }),\n );\n case \"calldata-spender\":\n await this.provideCalldataInfos(filter.calldataIndex);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.CalldataSpender,\n discarded,\n calldataIndex: filter.calldataIndex,\n signature: filter.signature,\n }),\n );\n case \"calldata-chain-id\":\n await this.provideCalldataInfos(filter.calldataIndex);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.CalldataChainId,\n discarded,\n calldataIndex: filter.calldataIndex,\n signature: filter.signature,\n }),\n );\n case \"calldata-selector\":\n await this.provideCalldataInfos(filter.calldataIndex);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.CalldataSelector,\n discarded,\n calldataIndex: filter.calldataIndex,\n signature: filter.signature,\n }),\n );\n case \"calldata-amount\":\n await this.provideCalldataInfos(filter.calldataIndex);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.CalldataAmount,\n discarded,\n calldataIndex: filter.calldataIndex,\n signature: filter.signature,\n }),\n );\n default: {\n const unhandledType: never = filter;\n throw new Error(\n `ProvideEIP712ContextTask/provideFiltering - Unhandled filter ${unhandledType}`,\n );\n }\n }\n }\n\n private async provideCalldataInfos(\n calldataIndex: number,\n ): Promise<Maybe<CommandResult<AllSuccessTypes, EthErrorCodes>>> {\n if (this.args.clearSignContext.isJust()) {\n // ensure the calldata info was not already provided to the device\n if (this.calldataMetadatas[calldataIndex] !== undefined) {\n // If already provided, update the remaining filters count\n this.calldataMetadatas[calldataIndex]!.remainingFilters--;\n return Nothing;\n }\n\n // get the calldata infos\n const calldataInfos =\n this.args.clearSignContext.extract().calldatas[calldataIndex];\n if (calldataInfos === undefined) {\n return Nothing;\n }\n\n // Initialize the expected filters count\n const filtersPresence = [\n calldataInfos.filter.valueFlag,\n calldataInfos.filter.calleeFlag ===\n TypedDataCalldataParamPresence.Present,\n calldataInfos.filter.chainIdFlag,\n calldataInfos.filter.selectorFlag,\n calldataInfos.filter.amountFlag,\n calldataInfos.filter.spenderFlag ===\n TypedDataCalldataParamPresence.Present,\n ];\n const filtersCount = filtersPresence.filter((f) => f).length;\n this.calldataMetadatas[calldataIndex] = {\n remainingFilters: filtersCount - 1, // Minus 1 since a filter is already being sent\n contexts: this.args.calldatasContexts[calldataIndex],\n };\n\n // provide the transaction infos filter\n return Maybe.of(\n await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.CalldataInfo,\n discarded: false,\n calldataIndex: calldataIndex,\n valueFlag: calldataInfos.filter.valueFlag,\n calleeFlag: this.mapCalldataPresence(\n calldataInfos.filter.calleeFlag,\n ),\n chainIdFlag: calldataInfos.filter.chainIdFlag,\n selectorFlag: calldataInfos.filter.selectorFlag,\n amountFlag: calldataInfos.filter.amountFlag,\n spenderFlag: this.mapCalldataPresence(\n calldataInfos.filter.spenderFlag,\n ),\n signature: calldataInfos.filter.signature,\n }),\n ),\n );\n }\n return Nothing;\n }\n\n private async tryProvideTransactionContext() {\n for (const calldataIndex in this.calldataMetadatas) {\n const metadata = this.calldataMetadatas[calldataIndex]!;\n if (metadata.remainingFilters === 0) {\n // All the filters and implementations were sent for that TX,\n // the related clear sign contexts should now be provided\n if (metadata.contexts !== undefined) {\n await this.provideContextFactory({\n contexts: metadata.contexts,\n derivationPath: this.args.derivationPath,\n }).run();\n }\n delete this.calldataMetadatas[calldataIndex];\n }\n }\n }\n\n private mapCalldataPresence(\n presence: TypedDataCalldataParamPresence,\n ): CalldataParamPresence {\n switch (presence) {\n case TypedDataCalldataParamPresence.None:\n return CalldataParamPresence.None;\n case TypedDataCalldataParamPresence.Present:\n return CalldataParamPresence.Present;\n case TypedDataCalldataParamPresence.VerifyingContract:\n return CalldataParamPresence.VerifyingContract;\n default: {\n const unhandledPresence: never = presence;\n throw new Error(`Unhandled presence ${unhandledPresence}`);\n }\n }\n }\n\n private sanitizeDeviceIndex(\n descriptorIndex: number,\n deviceIndexes: DeviceAssetIndexes,\n ) {\n // If a token is missing, the device will replace it with a placeholder and use the next available index\n if (deviceIndexes.indexes[descriptorIndex] === undefined) {\n deviceIndexes.indexes[descriptorIndex] = deviceIndexes.nextIndex;\n deviceIndexes.nextIndex =\n (deviceIndexes.nextIndex + 1) % DEVICE_ASSETS_MAX;\n }\n }\n}\n"],
5
+ "mappings": "AAAA,OAGE,kCAAAA,EAIA,kCAAAC,MACK,2BACP,OAEE,wBAAAC,MACK,2BAMP,OACE,sBAAAC,EACA,wBAAAC,EACA,0BAAAC,EACA,0BAAAC,MACK,kCACP,OAAS,QAAAC,EAAM,SAAAC,EAAO,WAAAC,MAAe,YAErC,OAAS,uBAAAC,MAA2B,mDACpC,OAAS,2BAAAC,MAA+B,uDACxC,OAAS,kCAAAC,MAAsC,8DAC/C,OAAS,6BAAAC,MAAiC,yDAC1C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AChC,WAAY,KAAK,oBACfA,EAAc,OAAO,UACvB,EACA,YAAaA,EAAc,OAAO,YAClC,aAAcA,EAAc,OAAO,aACnC,WAAYA,EAAc,OAAO,WACjC,YAAa,KAAK,oBAChBA,EAAc,OAAO,WACvB,EACA,UAAWA,EAAc,OAAO,SAClC,CAAC,CACH,CACF,CACF,CACA,OAAOnE,CACT,CAEA,MAAc,8BAA+B,CAC3C,UAAWkE,KAAiB,KAAK,kBAAmB,CAClD,MAAMI,EAAW,KAAK,kBAAkBJ,CAAa,EACjDI,EAAS,mBAAqB,IAG5BA,EAAS,WAAa,QACxB,MAAM,KAAK,sBAAsB,CAC/B,SAAUA,EAAS,SACnB,eAAgB,KAAK,KAAK,cAC5B,CAAC,EAAE,IAAI,EAET,OAAO,KAAK,kBAAkBJ,CAAa,EAE/C,CACF,CAEQ,oBACNK,EACuB,CACvB,OAAQA,EAAU,CAChB,KAAKhF,EAA+B,KAClC,OAAOe,EAAsB,KAC/B,KAAKf,EAA+B,QAClC,OAAOe,EAAsB,QAC/B,KAAKf,EAA+B,kBAClC,OAAOe,EAAsB,kBAC/B,QAAS,CACP,MAAMkE,EAA2BD,EACjC,MAAM,IAAI,MAAM,sBAAsBC,CAAiB,EAAE,CAC3D,CACF,CACF,CAEQ,oBACNjB,EACAd,EACA,CAEIA,EAAc,QAAQc,CAAe,IAAM,SAC7Cd,EAAc,QAAQc,CAAe,EAAId,EAAc,UACvDA,EAAc,WACXA,EAAc,UAAY,GAAKvB,EAEtC,CACF",
6
+ "names": ["TypedDataCalldataParamPresence", "VERIFYING_CONTRACT_TOKEN_INDEX", "ClearSignContextType", "bufferToHexaString", "CommandResultFactory", "isSuccessCommandResult", "LoadCertificateCommand", "Just", "Maybe", "Nothing", "GetChallengeCommand", "ProvideProxyInfoCommand", "ProvideTokenInformationCommand", "ProvideTrustedNameCommand", "ProvideWeb3CheckCommand", "CalldataParamPresence", "Eip712FilterType", "SendEIP712FilteringCommand", "SendEIP712StructDefinitionCommand", "StructDefinitionCommand", "StructImplemType", "SendEIP712StructImplemTask", "TypedDataValueField", "TypedDataValueArray", "TypedDataValueRoot", "ProvideTransactionContextsTask", "SendPayloadInChunksTask", "DEVICE_ASSETS_MAX", "ProvideEIP712ContextTask", "api", "contextModule", "args", "provideContextFactory", "domainValue", "val", "clearSignContext", "result", "types", "aKey", "bKey", "structName", "fields", "structNameResult", "fieldName", "fieldType", "fieldResult", "activationResult", "value", "domainImplResult", "messageInfoFilterResult", "deviceIndexes", "maybeTokenError", "maybeNameError", "maybeFilterResult", "messageImplResult", "discardedFilters", "path", "filter", "discardedPathResult", "provideFilteringResult", "type", "payload", "certificate", "uncoveredType", "descriptorIndex", "token", "provideTokenInfoResult", "deviceIndex", "context", "address", "getChallengeResult", "provideNameResult", "filteringResult", "discarded", "unhandledType", "calldataIndex", "calldataInfos", "filtersCount", "f", "metadata", "presence", "unhandledPresence"]
7
7
  }
@@ -0,0 +1,2 @@
1
+ import{ClearSignContextType as i}from"@ledgerhq/context-module";import{ByteArrayBuilder as d,isSuccessCommandResult as c}from"@ledgerhq/device-management-kit";import{DerivationPathUtils as p}from"@ledgerhq/signer-utils";import{Left as m,Right as C}from"purify-ts";import{StoreTransactionCommand as u}from"../../app-binder/command/StoreTransactionCommand";import{ProvideContextTask as h}from"./ProvideContextTask";import{SendCommandInChunksTask as T}from"./SendCommandInChunksTask";class P{constructor(a,r,s=(n,t)=>new h(n,t),e=(n,t)=>new T(n,t)){this._api=a;this._args=r;this._provideContextTaskFactory=s;this._sendCommandInChunksTaskFactory=e}async run(){let a=!1;for(const{context:r,subcontextCallbacks:s}of this._args.contexts){for(const n of s){const t=await n();t.type!==i.ERROR&&await this._provideContextTaskFactory(this._api,{context:t}).run()}if(r.type===i.PROXY_INFO)continue;if(!a&&this._args.serializedTransaction!==void 0&&r.type===i.TRANSACTION_INFO){a=!0;const n=p.splitPath(this._args.derivationPath),t=new d;t.add8BitUIntToData(n.length),n.forEach(o=>{t.add32BitUIntToData(o)}),t.addBufferToData(this._args.serializedTransaction),await this._sendCommandInChunksTaskFactory(this._api,{data:t.build(),commandFactory:o=>new u({serializedTransaction:o.chunkedData,isFirstChunk:o.isFirstChunk})}).run()}const e=await this._provideContextTaskFactory(this._api,{context:r}).run();if(!c(e))return m(e)}return C(void 0)}}export{P as ProvideTransactionContextsTask};
2
+ //# sourceMappingURL=ProvideTransactionContextsTask.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/internal/app-binder/task/ProvideTransactionContextsTask.ts"],
4
+ "sourcesContent": ["import { ClearSignContextType } from \"@ledgerhq/context-module\";\nimport {\n ByteArrayBuilder,\n type CommandErrorResult,\n type InternalApi,\n isSuccessCommandResult,\n} from \"@ledgerhq/device-management-kit\";\nimport { DerivationPathUtils } from \"@ledgerhq/signer-utils\";\nimport { type Either, Left, Right } from \"purify-ts\";\n\nimport { StoreTransactionCommand } from \"@internal/app-binder/command/StoreTransactionCommand\";\nimport { type EthErrorCodes } from \"@internal/app-binder/command/utils/ethAppErrors\";\n\nimport { type ContextWithSubContexts } from \"./BuildFullContextsTask\";\nimport {\n ProvideContextTask,\n type ProvideContextTaskArgs,\n} from \"./ProvideContextTask\";\nimport {\n SendCommandInChunksTask,\n type SendCommandInChunksTaskArgs,\n} from \"./SendCommandInChunksTask\";\n\nexport type ProvideTransactionContextsTaskArgs = {\n /**\n * The list of clear sign context with subcontexts callback to provide.\n */\n contexts: ContextWithSubContexts[];\n /**\n * The derivation path to provide.\n */\n derivationPath: string;\n /**\n * The serialized transaction to provide.\n * This parameter is optional in the case there is no transaction at all, for instance\n * if there is only a standalone calldata embedded in a message.\n */\n serializedTransaction?: Uint8Array;\n};\n\nexport type ProvideTransactionContextsTaskResult = Either<\n CommandErrorResult<EthErrorCodes>,\n void\n>;\n\n/**\n * This task is responsible for providing the transaction context to the device.\n * It will send the subcontexts callbacks in order and finish with the context.\n */\nexport class ProvideTransactionContextsTask {\n constructor(\n private _api: InternalApi,\n private _args: ProvideTransactionContextsTaskArgs,\n private _provideContextTaskFactory = (\n api: InternalApi,\n args: ProvideContextTaskArgs,\n ) => new ProvideContextTask(api, args),\n private _sendCommandInChunksTaskFactory = (\n api: InternalApi,\n args: SendCommandInChunksTaskArgs<unknown>,\n ) => new SendCommandInChunksTask(api, args),\n ) {}\n\n async run(): Promise<ProvideTransactionContextsTaskResult> {\n let transactionInfoProvided = false;\n\n for (const { context, subcontextCallbacks } of this._args.contexts) {\n for (const callback of subcontextCallbacks) {\n const subcontext = await callback();\n\n if (subcontext.type === ClearSignContextType.ERROR) {\n // silently ignore error subcontexts\n continue;\n }\n\n // Don't fail immediately on subcontext errors because the main context may still be successful\n await this._provideContextTaskFactory(this._api, {\n context: subcontext,\n }).run();\n }\n\n if (context.type === ClearSignContextType.PROXY_INFO) {\n // In this specific case, the context is not valid as the challenge is not valid on the first call\n // the real data is provided in the subcontext callback\n continue;\n }\n\n if (\n !transactionInfoProvided &&\n this._args.serializedTransaction !== undefined &&\n context.type === ClearSignContextType.TRANSACTION_INFO\n ) {\n // Send the serialized transaction for the first TRANSACTION_INFO.\n // All other TRANSACTION_INFO contexts will be ignored as it will be for nested calldata.\n transactionInfoProvided = true;\n\n const paths = DerivationPathUtils.splitPath(this._args.derivationPath);\n const builder = new ByteArrayBuilder();\n builder.add8BitUIntToData(paths.length);\n paths.forEach((path) => {\n builder.add32BitUIntToData(path);\n });\n builder.addBufferToData(this._args.serializedTransaction);\n await this._sendCommandInChunksTaskFactory(this._api, {\n data: builder.build(),\n commandFactory: (args) =>\n new StoreTransactionCommand({\n serializedTransaction: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n }\n\n const res = await this._provideContextTaskFactory(this._api, {\n context,\n }).run();\n if (!isSuccessCommandResult(res)) {\n return Left(res);\n }\n }\n\n return Right(void 0);\n }\n}\n"],
5
+ "mappings": "AAAA,OAAS,wBAAAA,MAA4B,2BACrC,OACE,oBAAAC,EAGA,0BAAAC,MACK,kCAC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,KAAK,2BAA2B,KAAK,KAAM,CAC3D,QAAAP,CACF,CAAC,EAAE,IAAI,EACP,GAAI,CAACf,EAAuBsB,CAAG,EAC7B,OAAOpB,EAAKoB,CAAG,CAEnB,CAEA,OAAOnB,EAAM,MAAM,CACrB,CACF",
6
+ "names": ["ClearSignContextType", "ByteArrayBuilder", "isSuccessCommandResult", "DerivationPathUtils", "Left", "Right", "StoreTransactionCommand", "ProvideContextTask", "SendCommandInChunksTask", "ProvideTransactionContextsTask", "_api", "_args", "_provideContextTaskFactory", "api", "args", "_sendCommandInChunksTaskFactory", "transactionInfoProvided", "context", "subcontextCallbacks", "callback", "subcontext", "paths", "builder", "path", "res"]
7
+ }
@@ -0,0 +1,2 @@
1
+ import{ClearSignContextType as t}from"@ledgerhq/context-module";import{CommandResultFactory as y}from"@ledgerhq/device-management-kit";import{Left as u,Right as d}from"purify-ts";import{StoreTransactionCommand as C}from"../../app-binder/command/StoreTransactionCommand";import{makeDeviceActionInternalApiMock as m}from"../../app-binder/device-action/__test-utils__/makeInternalApi";import{ProvideTransactionContextsTask as l}from"./ProvideTransactionContextsTask";describe("ProvideTransactionContextsTask",()=>{const o=m(),r=y({data:void 0}),p=y({data:void 0,error:{}});beforeEach(()=>{vi.resetAllMocks()}),describe("run",()=>{const e=vi.fn(),x=vi.fn(),i=vi.fn(),s=vi.fn();beforeEach(()=>{vi.clearAllMocks(),i.mockImplementation((a,c)=>({run:()=>e(a,c)})),s.mockImplementation((a,c)=>({run:()=>x(a,c)}))}),describe("with no subcontexts",()=>{it("should provide the transaction context for a TRANSACTION_INFO context",async()=>{const a={contexts:[{context:{type:t.TRANSACTION_INFO,payload:"0x00"},subcontextCallbacks:[]}],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"};x.mockResolvedValue(r),e.mockResolvedValue(r);const n=await new l(o,a,i,s).run();expect(n).toEqual(d(void 0)),expect(x).toHaveBeenCalledTimes(1),expect(s).toHaveBeenCalledWith(o,{data:new Uint8Array([5,128,0,0,44,128,0,0,60,128,0,0,0,0,0,0,0,0,0,0,0]),commandFactory:expect.any(Function)});const T=s.mock.calls[0][1].commandFactory,k={chunkedData:new Uint8Array([1,2,3,4]),isFirstChunk:!0},v=T(k);expect(v).toBeInstanceOf(C),expect(e).toHaveBeenCalledTimes(1),expect(e).toHaveBeenCalledWith(o,{context:{type:t.TRANSACTION_INFO,payload:"0x00"}})}),it("should provide context without serialized transaction when not provided",async()=>{const a={contexts:[{context:{type:t.TOKEN,payload:"payload"},subcontextCallbacks:[]}],derivationPath:"44'/60'/0'/0/0"};e.mockResolvedValue(r);const n=await new l(o,a,i,s).run();expect(n).toEqual(d(void 0)),expect(x).not.toHaveBeenCalled(),expect(e).toHaveBeenCalledTimes(1)}),it("should skip PROXY_INFO context and only provide subcontexts",async()=>{const a={contexts:[{context:{type:t.PROXY_INFO,payload:"payload"},subcontextCallbacks:[()=>Promise.resolve({type:t.PROXY_INFO,payload:"subcontext payload"})]}],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"};e.mockResolvedValue(r);const n=await new l(o,a,i,s).run();expect(n).toEqual(d(void 0)),expect(e).toHaveBeenCalledTimes(1),expect(e).toHaveBeenCalledWith(o,{context:{type:t.PROXY_INFO,payload:"subcontext payload"}})}),it("should skip ERROR subcontexts silently",async()=>{const a={contexts:[{context:{type:t.TOKEN,payload:"payload"},subcontextCallbacks:[()=>Promise.resolve({type:t.ERROR,error:new Error("error")})]}],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"};e.mockResolvedValue(r);const n=await new l(o,a,i,s).run();expect(n).toEqual(d(void 0)),expect(e).toHaveBeenCalledTimes(1),expect(e).toHaveBeenCalledWith(o,{context:{type:t.TOKEN,payload:"payload"}})}),it("should only store transaction once for first TRANSACTION_INFO context",async()=>{const a={contexts:[{context:{type:t.TRANSACTION_INFO,payload:"payload1"},subcontextCallbacks:[]},{context:{type:t.TRANSACTION_INFO,payload:"payload2"},subcontextCallbacks:[]}],serializedTransaction:new Uint8Array([1,2,3]),derivationPath:"44'/60'/0'/0/0"};x.mockResolvedValue(r),e.mockResolvedValue(r);const n=await new l(o,a,i,s).run();expect(n).toEqual(d(void 0)),expect(x).toHaveBeenCalledTimes(1),expect(e).toHaveBeenCalledTimes(2)})}),describe("with subcontexts",()=>{it("should provide subcontexts before the main context",async()=>{const a={contexts:[{context:{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"main payload"},subcontextCallbacks:[()=>Promise.resolve({type:t.TOKEN,payload:"subcontext payload"})]}],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"};e.mockResolvedValue(r);const n=await new l(o,a,i,s).run();expect(n).toEqual(d(void 0)),expect(e).toHaveBeenCalledTimes(2),expect(e).toHaveBeenNthCalledWith(1,o,{context:{type:t.TOKEN,payload:"subcontext payload"}}),expect(e).toHaveBeenNthCalledWith(2,o,{context:{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"main payload"}})}),it("should provide multiple subcontexts in order",async()=>{const a={contexts:[{context:{type:t.TRUSTED_NAME,payload:"main payload"},subcontextCallbacks:[()=>Promise.resolve({type:t.NFT,payload:"subcontext1"}),()=>Promise.resolve({type:t.TOKEN,payload:"subcontext2"})]}],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"};e.mockResolvedValue(r);const n=await new l(o,a,i,s).run();expect(n).toEqual(d(void 0)),expect(e).toHaveBeenCalledTimes(3),expect(e).toHaveBeenNthCalledWith(1,o,{context:{type:t.NFT,payload:"subcontext1"}}),expect(e).toHaveBeenNthCalledWith(2,o,{context:{type:t.TOKEN,payload:"subcontext2"}}),expect(e).toHaveBeenNthCalledWith(3,o,{context:{type:t.TRUSTED_NAME,payload:"main payload"}})}),it("should continue providing main context even if subcontext fails",async()=>{const a={contexts:[{context:{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"main payload"},subcontextCallbacks:[()=>Promise.resolve({type:t.TOKEN,payload:"subcontext payload"})]}],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"};e.mockResolvedValueOnce(p).mockResolvedValueOnce(r);const n=await new l(o,a,i,s).run();expect(n).toEqual(d(void 0)),expect(e).toHaveBeenCalledTimes(2)})}),describe("with multiple contexts",()=>{it("should provide all contexts in order",async()=>{const a={contexts:[{context:{type:t.TOKEN,payload:"payload1"},subcontextCallbacks:[]},{context:{type:t.NFT,payload:"payload2"},subcontextCallbacks:[]},{context:{type:t.TRUSTED_NAME,payload:"payload3"},subcontextCallbacks:[]}],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"};e.mockResolvedValue(r);const n=await new l(o,a,i,s).run();expect(n).toEqual(d(void 0)),expect(e).toHaveBeenCalledTimes(3),expect(e).toHaveBeenNthCalledWith(1,o,{context:{type:t.TOKEN,payload:"payload1"}}),expect(e).toHaveBeenNthCalledWith(2,o,{context:{type:t.NFT,payload:"payload2"}}),expect(e).toHaveBeenNthCalledWith(3,o,{context:{type:t.TRUSTED_NAME,payload:"payload3"}})})}),describe("error handling",()=>{it("should return error if main context fails",async()=>{const a={contexts:[{context:{type:t.TOKEN,payload:"payload"},subcontextCallbacks:[]}],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"};e.mockResolvedValue(p);const n=await new l(o,a,i,s).run();expect(n).toEqual(u(p))}),it("should stop providing contexts after first main context failure",async()=>{const a={contexts:[{context:{type:t.TOKEN,payload:"payload1"},subcontextCallbacks:[]},{context:{type:t.NFT,payload:"payload2"},subcontextCallbacks:[]}],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"};e.mockResolvedValue(p);const n=await new l(o,a,i,s).run();expect(n).toEqual(u(p)),expect(e).toHaveBeenCalledTimes(1)})}),describe("derivation path handling",()=>{it("should correctly parse and include derivation path in StoreTransaction",async()=>{const a={contexts:[{context:{type:t.TRANSACTION_INFO,payload:"payload"},subcontextCallbacks:[]}],serializedTransaction:new Uint8Array([170,187,204]),derivationPath:"44'/60'/0'/0/0"};x.mockResolvedValue(r),e.mockResolvedValue(r),await new l(o,a,i,s).run(),expect(s).toHaveBeenCalledWith(o,expect.objectContaining({data:new Uint8Array([5,128,0,0,44,128,0,0,60,128,0,0,0,0,0,0,0,0,0,0,0,170,187,204])}))})}),describe("factory types",()=>{it("should have default factories",()=>{const a=new l(o,{contexts:[{context:{type:t.TOKEN,payload:"payload"},subcontextCallbacks:[]}],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"});expect(a._provideContextTaskFactory).toBeDefined(),expect(a._sendCommandInChunksTaskFactory).toBeDefined()})})})});
2
+ //# sourceMappingURL=ProvideTransactionContextsTask.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/internal/app-binder/task/ProvideTransactionContextsTask.test.ts"],
4
+ "sourcesContent": ["import { ClearSignContextType } from \"@ledgerhq/context-module\";\nimport {\n CommandResultFactory,\n type InternalApi,\n type UnknownDeviceExchangeError,\n} from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { StoreTransactionCommand } from \"@internal/app-binder/command/StoreTransactionCommand\";\nimport { type EthErrorCodes } from \"@internal/app-binder/command/utils/ethAppErrors\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\n\nimport {\n type ProvideContextTask,\n type ProvideContextTaskArgs,\n} from \"./ProvideContextTask\";\nimport {\n ProvideTransactionContextsTask,\n type ProvideTransactionContextsTaskArgs,\n} from \"./ProvideTransactionContextsTask\";\nimport {\n type SendCommandInChunksTask,\n type SendCommandInChunksTaskArgs,\n} from \"./SendCommandInChunksTask\";\n\ndescribe(\"ProvideTransactionContextsTask\", () => {\n const api = makeDeviceActionInternalApiMock();\n const successResult = CommandResultFactory<void, EthErrorCodes>({\n data: undefined,\n });\n const errorResult = CommandResultFactory<void, EthErrorCodes>({\n data: undefined,\n error: {} as UnknownDeviceExchangeError,\n });\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n describe(\"run\", () => {\n const provideContextTaskRunMock = vi.fn();\n const sendCommandInChunksTaskRunMock = vi.fn();\n const provideContextTaskMockFactory = vi.fn();\n const sendCommandInChunksTaskMockFactory = vi.fn();\n\n beforeEach(() => {\n vi.clearAllMocks();\n provideContextTaskMockFactory.mockImplementation(\n (a: InternalApi, args: ProvideContextTaskArgs) =>\n ({\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n run: () => provideContextTaskRunMock(a, args),\n }) as unknown as ProvideContextTask,\n );\n sendCommandInChunksTaskMockFactory.mockImplementation(\n (a: InternalApi, args: SendCommandInChunksTaskArgs<unknown>) =>\n ({\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n run: () => sendCommandInChunksTaskRunMock(a, args),\n }) as unknown as SendCommandInChunksTask<unknown>,\n );\n });\n\n describe(\"with no subcontexts\", () => {\n it(\"should provide the transaction context for a TRANSACTION_INFO context\", async () => {\n // GIVEN\n const args: ProvideTransactionContextsTaskArgs = {\n contexts: [\n {\n context: {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"0x00\",\n },\n subcontextCallbacks: [],\n },\n ],\n serializedTransaction: new Uint8Array(),\n derivationPath: \"44'/60'/0'/0/0\",\n };\n sendCommandInChunksTaskRunMock.mockResolvedValue(successResult);\n provideContextTaskRunMock.mockResolvedValue(successResult);\n\n // WHEN\n const task = new ProvideTransactionContextsTask(\n api,\n args,\n provideContextTaskMockFactory,\n sendCommandInChunksTaskMockFactory,\n );\n const result = await task.run();\n\n // THEN\n expect(result).toEqual(Right(void 0));\n\n // StoreTransactionCommand should be called\n expect(sendCommandInChunksTaskRunMock).toHaveBeenCalledTimes(1);\n expect(sendCommandInChunksTaskMockFactory).toHaveBeenCalledWith(api, {\n data: new Uint8Array([\n 0x05, 0x80, 0x00, 0x00, 0x2c, 0x80, 0x00, 0x00, 0x3c, 0x80, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n ]),\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n commandFactory: expect.any(Function),\n });\n // Test that the commandFactory returns a StoreTransactionCommand\n const factoryCall = sendCommandInChunksTaskMockFactory.mock.calls[0]!;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n const commandFactory = factoryCall[1].commandFactory;\n const mockArgs = {\n chunkedData: new Uint8Array([1, 2, 3, 4]),\n isFirstChunk: true,\n };\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n const command = commandFactory(mockArgs);\n expect(command).toBeInstanceOf(StoreTransactionCommand);\n\n // ProvideContextTask should be called for the context\n expect(provideContextTaskRunMock).toHaveBeenCalledTimes(1);\n expect(provideContextTaskRunMock).toHaveBeenCalledWith(api, {\n context: {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"0x00\",\n },\n });\n });\n\n it(\"should provide context without serialized transaction when not provided\", async () => {\n // GIVEN\n const args: ProvideTransactionContextsTaskArgs = {\n contexts: [\n {\n context: {\n type: ClearSignContextType.TOKEN,\n payload: \"payload\",\n },\n subcontextCallbacks: [],\n },\n ],\n derivationPath: \"44'/60'/0'/0/0\",\n };\n provideContextTaskRunMock.mockResolvedValue(successResult);\n\n // WHEN\n const task = new ProvideTransactionContextsTask(\n api,\n args,\n provideContextTaskMockFactory,\n sendCommandInChunksTaskMockFactory,\n );\n const result = await task.run();\n\n // THEN\n expect(result).toEqual(Right(void 0));\n expect(sendCommandInChunksTaskRunMock).not.toHaveBeenCalled();\n expect(provideContextTaskRunMock).toHaveBeenCalledTimes(1);\n });\n\n it(\"should skip PROXY_INFO context and only provide subcontexts\", async () => {\n // GIVEN\n const args: ProvideTransactionContextsTaskArgs = {\n contexts: [\n {\n context: {\n type: ClearSignContextType.PROXY_INFO,\n payload: \"payload\",\n },\n subcontextCallbacks: [\n () =>\n Promise.resolve({\n type: ClearSignContextType.PROXY_INFO,\n payload: \"subcontext payload\",\n }),\n ],\n },\n ],\n serializedTransaction: new Uint8Array(),\n derivationPath: \"44'/60'/0'/0/0\",\n };\n provideContextTaskRunMock.mockResolvedValue(successResult);\n\n // WHEN\n const task = new ProvideTransactionContextsTask(\n api,\n args,\n provideContextTaskMockFactory,\n sendCommandInChunksTaskMockFactory,\n );\n const result = await task.run();\n\n // THEN\n expect(result).toEqual(Right(void 0));\n expect(provideContextTaskRunMock).toHaveBeenCalledTimes(1);\n expect(provideContextTaskRunMock).toHaveBeenCalledWith(api, {\n context: {\n type: ClearSignContextType.PROXY_INFO,\n payload: \"subcontext payload\",\n },\n });\n });\n\n it(\"should skip ERROR subcontexts silently\", async () => {\n // GIVEN\n const args: ProvideTransactionContextsTaskArgs = {\n contexts: [\n {\n context: {\n type: ClearSignContextType.TOKEN,\n payload: \"payload\",\n },\n subcontextCallbacks: [\n () =>\n Promise.resolve({\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n }),\n ],\n },\n ],\n serializedTransaction: new Uint8Array(),\n derivationPath: \"44'/60'/0'/0/0\",\n };\n provideContextTaskRunMock.mockResolvedValue(successResult);\n\n // WHEN\n const task = new ProvideTransactionContextsTask(\n api,\n args,\n provideContextTaskMockFactory,\n sendCommandInChunksTaskMockFactory,\n );\n const result = await task.run();\n\n // THEN\n expect(result).toEqual(Right(void 0));\n // Only the main context should be provided, not the error subcontext\n expect(provideContextTaskRunMock).toHaveBeenCalledTimes(1);\n expect(provideContextTaskRunMock).toHaveBeenCalledWith(api, {\n context: {\n type: ClearSignContextType.TOKEN,\n payload: \"payload\",\n },\n });\n });\n\n it(\"should only store transaction once for first TRANSACTION_INFO context\", async () => {\n // GIVEN\n const args: ProvideTransactionContextsTaskArgs = {\n contexts: [\n {\n context: {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload1\",\n },\n subcontextCallbacks: [],\n },\n {\n context: {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload2\",\n },\n subcontextCallbacks: [],\n },\n ],\n serializedTransaction: new Uint8Array([1, 2, 3]),\n derivationPath: \"44'/60'/0'/0/0\",\n };\n sendCommandInChunksTaskRunMock.mockResolvedValue(successResult);\n provideContextTaskRunMock.mockResolvedValue(successResult);\n\n // WHEN\n const task = new ProvideTransactionContextsTask(\n api,\n args,\n provideContextTaskMockFactory,\n sendCommandInChunksTaskMockFactory,\n );\n const result = await task.run();\n\n // THEN\n expect(result).toEqual(Right(void 0));\n // StoreTransactionCommand should only be called once\n expect(sendCommandInChunksTaskRunMock).toHaveBeenCalledTimes(1);\n // But both contexts should be provided\n expect(provideContextTaskRunMock).toHaveBeenCalledTimes(2);\n });\n });\n\n describe(\"with subcontexts\", () => {\n it(\"should provide subcontexts before the main context\", async () => {\n // GIVEN\n const args: ProvideTransactionContextsTaskArgs = {\n contexts: [\n {\n context: {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"main payload\",\n },\n subcontextCallbacks: [\n () =>\n Promise.resolve({\n type: ClearSignContextType.TOKEN,\n payload: \"subcontext payload\",\n }),\n ],\n },\n ],\n serializedTransaction: new Uint8Array(),\n derivationPath: \"44'/60'/0'/0/0\",\n };\n provideContextTaskRunMock.mockResolvedValue(successResult);\n\n // WHEN\n const task = new ProvideTransactionContextsTask(\n api,\n args,\n provideContextTaskMockFactory,\n sendCommandInChunksTaskMockFactory,\n );\n const result = await task.run();\n\n // THEN\n expect(result).toEqual(Right(void 0));\n expect(provideContextTaskRunMock).toHaveBeenCalledTimes(2);\n // Subcontext should be provided first\n expect(provideContextTaskRunMock).toHaveBeenNthCalledWith(1, api, {\n context: {\n type: ClearSignContextType.TOKEN,\n payload: \"subcontext payload\",\n },\n });\n // Then main context\n expect(provideContextTaskRunMock).toHaveBeenNthCalledWith(2, api, {\n context: {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"main payload\",\n },\n });\n });\n\n it(\"should provide multiple subcontexts in order\", async () => {\n // GIVEN\n const args: ProvideTransactionContextsTaskArgs = {\n contexts: [\n {\n context: {\n type: ClearSignContextType.TRUSTED_NAME,\n payload: \"main payload\",\n },\n subcontextCallbacks: [\n () =>\n Promise.resolve({\n type: ClearSignContextType.NFT,\n payload: \"subcontext1\",\n }),\n () =>\n Promise.resolve({\n type: ClearSignContextType.TOKEN,\n payload: \"subcontext2\",\n }),\n ],\n },\n ],\n serializedTransaction: new Uint8Array(),\n derivationPath: \"44'/60'/0'/0/0\",\n };\n provideContextTaskRunMock.mockResolvedValue(successResult);\n\n // WHEN\n const task = new ProvideTransactionContextsTask(\n api,\n args,\n provideContextTaskMockFactory,\n sendCommandInChunksTaskMockFactory,\n );\n const result = await task.run();\n\n // THEN\n expect(result).toEqual(Right(void 0));\n expect(provideContextTaskRunMock).toHaveBeenCalledTimes(3);\n expect(provideContextTaskRunMock).toHaveBeenNthCalledWith(1, api, {\n context: {\n type: ClearSignContextType.NFT,\n payload: \"subcontext1\",\n },\n });\n expect(provideContextTaskRunMock).toHaveBeenNthCalledWith(2, api, {\n context: {\n type: ClearSignContextType.TOKEN,\n payload: \"subcontext2\",\n },\n });\n expect(provideContextTaskRunMock).toHaveBeenNthCalledWith(3, api, {\n context: {\n type: ClearSignContextType.TRUSTED_NAME,\n payload: \"main payload\",\n },\n });\n });\n\n it(\"should continue providing main context even if subcontext fails\", async () => {\n // GIVEN\n const args: ProvideTransactionContextsTaskArgs = {\n contexts: [\n {\n context: {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"main payload\",\n },\n subcontextCallbacks: [\n () =>\n Promise.resolve({\n type: ClearSignContextType.TOKEN,\n payload: \"subcontext payload\",\n }),\n ],\n },\n ],\n serializedTransaction: new Uint8Array(),\n derivationPath: \"44'/60'/0'/0/0\",\n };\n provideContextTaskRunMock\n .mockResolvedValueOnce(errorResult) // subcontext fails\n .mockResolvedValueOnce(successResult); // main context succeeds\n\n // WHEN\n const task = new ProvideTransactionContextsTask(\n api,\n args,\n provideContextTaskMockFactory,\n sendCommandInChunksTaskMockFactory,\n );\n const result = await task.run();\n\n // THEN\n expect(result).toEqual(Right(void 0));\n expect(provideContextTaskRunMock).toHaveBeenCalledTimes(2);\n });\n });\n\n describe(\"with multiple contexts\", () => {\n it(\"should provide all contexts in order\", async () => {\n // GIVEN\n const args: ProvideTransactionContextsTaskArgs = {\n contexts: [\n {\n context: {\n type: ClearSignContextType.TOKEN,\n payload: \"payload1\",\n },\n subcontextCallbacks: [],\n },\n {\n context: {\n type: ClearSignContextType.NFT,\n payload: \"payload2\",\n },\n subcontextCallbacks: [],\n },\n {\n context: {\n type: ClearSignContextType.TRUSTED_NAME,\n payload: \"payload3\",\n },\n subcontextCallbacks: [],\n },\n ],\n serializedTransaction: new Uint8Array(),\n derivationPath: \"44'/60'/0'/0/0\",\n };\n provideContextTaskRunMock.mockResolvedValue(successResult);\n\n // WHEN\n const task = new ProvideTransactionContextsTask(\n api,\n args,\n provideContextTaskMockFactory,\n sendCommandInChunksTaskMockFactory,\n );\n const result = await task.run();\n\n // THEN\n expect(result).toEqual(Right(void 0));\n expect(provideContextTaskRunMock).toHaveBeenCalledTimes(3);\n expect(provideContextTaskRunMock).toHaveBeenNthCalledWith(1, api, {\n context: {\n type: ClearSignContextType.TOKEN,\n payload: \"payload1\",\n },\n });\n expect(provideContextTaskRunMock).toHaveBeenNthCalledWith(2, api, {\n context: {\n type: ClearSignContextType.NFT,\n payload: \"payload2\",\n },\n });\n expect(provideContextTaskRunMock).toHaveBeenNthCalledWith(3, api, {\n context: {\n type: ClearSignContextType.TRUSTED_NAME,\n payload: \"payload3\",\n },\n });\n });\n });\n\n describe(\"error handling\", () => {\n it(\"should return error if main context fails\", async () => {\n // GIVEN\n const args: ProvideTransactionContextsTaskArgs = {\n contexts: [\n {\n context: {\n type: ClearSignContextType.TOKEN,\n payload: \"payload\",\n },\n subcontextCallbacks: [],\n },\n ],\n serializedTransaction: new Uint8Array(),\n derivationPath: \"44'/60'/0'/0/0\",\n };\n provideContextTaskRunMock.mockResolvedValue(errorResult);\n\n // WHEN\n const task = new ProvideTransactionContextsTask(\n api,\n args,\n provideContextTaskMockFactory,\n sendCommandInChunksTaskMockFactory,\n );\n const result = await task.run();\n\n // THEN\n expect(result).toEqual(Left(errorResult));\n });\n\n it(\"should stop providing contexts after first main context failure\", async () => {\n // GIVEN\n const args: ProvideTransactionContextsTaskArgs = {\n contexts: [\n {\n context: {\n type: ClearSignContextType.TOKEN,\n payload: \"payload1\",\n },\n subcontextCallbacks: [],\n },\n {\n context: {\n type: ClearSignContextType.NFT,\n payload: \"payload2\",\n },\n subcontextCallbacks: [],\n },\n ],\n serializedTransaction: new Uint8Array(),\n derivationPath: \"44'/60'/0'/0/0\",\n };\n provideContextTaskRunMock.mockResolvedValue(errorResult);\n\n // WHEN\n const task = new ProvideTransactionContextsTask(\n api,\n args,\n provideContextTaskMockFactory,\n sendCommandInChunksTaskMockFactory,\n );\n const result = await task.run();\n\n // THEN\n expect(result).toEqual(Left(errorResult));\n // Should only try to provide the first context\n expect(provideContextTaskRunMock).toHaveBeenCalledTimes(1);\n });\n });\n\n describe(\"derivation path handling\", () => {\n it(\"should correctly parse and include derivation path in StoreTransaction\", async () => {\n // GIVEN\n const args: ProvideTransactionContextsTaskArgs = {\n contexts: [\n {\n context: {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload\",\n },\n subcontextCallbacks: [],\n },\n ],\n serializedTransaction: new Uint8Array([0xaa, 0xbb, 0xcc]),\n derivationPath: \"44'/60'/0'/0/0\",\n };\n sendCommandInChunksTaskRunMock.mockResolvedValue(successResult);\n provideContextTaskRunMock.mockResolvedValue(successResult);\n\n // WHEN\n const task = new ProvideTransactionContextsTask(\n api,\n args,\n provideContextTaskMockFactory,\n sendCommandInChunksTaskMockFactory,\n );\n await task.run();\n\n // THEN\n expect(sendCommandInChunksTaskMockFactory).toHaveBeenCalledWith(\n api,\n expect.objectContaining({\n data: new Uint8Array([\n 0x05, // path length\n 0x80,\n 0x00,\n 0x00,\n 0x2c, // 44'\n 0x80,\n 0x00,\n 0x00,\n 0x3c, // 60'\n 0x80,\n 0x00,\n 0x00,\n 0x00, // 0'\n 0x00,\n 0x00,\n 0x00,\n 0x00, // 0\n 0x00,\n 0x00,\n 0x00,\n 0x00, // 0\n 0xaa,\n 0xbb,\n 0xcc, // transaction\n ]),\n }),\n );\n });\n });\n\n describe(\"factory types\", () => {\n it(\"should have default factories\", () => {\n // GIVEN\n const task = new ProvideTransactionContextsTask(api, {\n contexts: [\n {\n context: {\n type: ClearSignContextType.TOKEN,\n payload: \"payload\",\n },\n subcontextCallbacks: [],\n },\n ],\n serializedTransaction: new Uint8Array(),\n derivationPath: \"44'/60'/0'/0/0\",\n });\n\n // THEN\n expect(task[\"_provideContextTaskFactory\"]).toBeDefined();\n expect(task[\"_sendCommandInChunksTaskFactory\"]).toBeDefined();\n });\n });\n });\n});\n"],
5
+ "mappings": "AAAA,OAAS,wBAAAA,MAA4B,2BACrC,OACE,wBAAAC,MAGK,kCACP,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAE5B,OAAS,2BAAAC,MAA+B,uDAExC,OAAS,mCAAAC,MAAuC,oEAMhD,OACE,kCAAAC,MAEK,mCAMP,SAAS,iCAAkC,IAAM,CAC/C,MAAMC,EAAMF,EAAgC,EACtCG,EAAgBP,EAA0C,CAC9D,KAAM,MACR,CAAC,EACKQ,EAAcR,EAA0C,CAC5D,KAAM,OACN,MAAO,CAAC,CACV,CAAC,EAED,WAAW,IAAM,CACf,GAAG,cAAc,CACnB,CAAC,EAED,SAAS,MAAO,IAAM,CACpB,MAAMS,EAA4B,GAAG,GAAG,EAClCC,EAAiC,GAAG,GAAG,EACvCC,EAAgC,GAAG,GAAG,EACtCC,EAAqC,GAAG,GAAG,EAEjD,WAAW,IAAM,CACf,GAAG,cAAc,EACjBD,EAA8B,mBAC5B,CAAC,EAAgBE,KACd,CAEC,IAAK,IAAMJ,EAA0B,EAAGI,CAAI,CAC9C,EACJ,EACAD,EAAmC,mBACjC,CAAC,EA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9DE,EAA0B,kBAAkBF,CAAa,EASzD,MANa,IAAIF,EACfC,EACAO,EACAF,EACAC,CACF,EACW,IAAI,EAGf,OAAOA,CAAkC,EAAE,qBACzCN,EACA,OAAO,iBAAiB,CACtB,KAAM,IAAI,WAAW,CACnB,EACA,IACA,EACA,EACA,GACA,IACA,EACA,EACA,GACA,IACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,IACA,IACA,GACF,CAAC,CACH,CAAC,CACH,CACF,CAAC,CACH,CAAC,EAED,SAAS,gBAAiB,IAAM,CAC9B,GAAG,gCAAiC,IAAM,CAExC,MAAMY,EAAO,IAAIb,EAA+BC,EAAK,CACnD,SAAU,CACR,CACE,QAAS,CACP,KAAMP,EAAqB,MAC3B,QAAS,SACX,EACA,oBAAqB,CAAC,CACxB,CACF,EACA,sBAAuB,IAAI,WAC3B,eAAgB,gBAClB,CAAC,EAGD,OAAOmB,EAAK,0BAA6B,EAAE,YAAY,EACvD,OAAOA,EAAK,+BAAkC,EAAE,YAAY,CAC9D,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["ClearSignContextType", "CommandResultFactory", "Left", "Right", "StoreTransactionCommand", "makeDeviceActionInternalApiMock", "ProvideTransactionContextsTask", "api", "successResult", "errorResult", "provideContextTaskRunMock", "sendCommandInChunksTaskRunMock", "provideContextTaskMockFactory", "sendCommandInChunksTaskMockFactory", "args", "result", "commandFactory", "mockArgs", "command", "task"]
7
+ }
@@ -1,2 +1,2 @@
1
- import{Container as i}from"inversify";import{addressModuleFactory as a}from"./address/di/addressModule";import{appBindingModuleFactory as m}from"./app-binder/di/appBinderModule";import{eip7702ModuleFactory as d}from"./eip7702/di/eip7702Module";import{externalTypes as o}from"./externalTypes";import{messageModuleFactory as s}from"./message/di/messageModule";import{transactionModuleFactory as p}from"./transaction/di/transactionModule";import{typedDataModuleFactory as c}from"./typed-data/di/typedDataModule";const v=({dmk:t,sessionId:n,contextModule:r})=>{const e=new i;return e.bind(o.Dmk).toConstantValue(t),e.bind(o.ContextModule).toConstantValue(r),e.bind(o.SessionId).toConstantValue(n),e.loadSync(a(),m(),d(),s(),p(),c()),e};export{v as makeContainer};
1
+ import{Container as a}from"inversify";import{addressModuleFactory as i}from"./address/di/addressModule";import{appBindingModuleFactory as m}from"./app-binder/di/appBinderModule";import{eip7702ModuleFactory as d}from"./eip7702/di/eip7702Module";import{externalTypes as e}from"./externalTypes";import{messageModuleFactory as s}from"./message/di/messageModule";import{safeModuleFactory as p}from"./safe/di/safeModule";import{transactionModuleFactory as c}from"./transaction/di/transactionModule";import{typedDataModuleFactory as l}from"./typed-data/di/typedDataModule";const g=({dmk:t,sessionId:n,contextModule:r})=>{const o=new a;return o.bind(e.Dmk).toConstantValue(t),o.bind(e.ContextModule).toConstantValue(r),o.bind(e.SessionId).toConstantValue(n),o.loadSync(i(),m(),d(),s(),c(),l(),p()),o};export{g as makeContainer};
2
2
  //# sourceMappingURL=di.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/internal/di.ts"],
4
- "sourcesContent": ["import { type ContextModule } from \"@ledgerhq/context-module\";\nimport {\n type DeviceManagementKit,\n type DeviceSessionId,\n} from \"@ledgerhq/device-management-kit\";\nimport { Container } from \"inversify\";\n\nimport { addressModuleFactory } from \"@internal/address/di/addressModule\";\nimport { appBindingModuleFactory } from \"@internal/app-binder/di/appBinderModule\";\nimport { eip7702ModuleFactory } from \"@internal/eip7702/di/eip7702Module\";\nimport { externalTypes } from \"@internal/externalTypes\";\nimport { messageModuleFactory } from \"@internal/message/di/messageModule\";\nimport { transactionModuleFactory } from \"@internal/transaction/di/transactionModule\";\nimport { typedDataModuleFactory } from \"@internal/typed-data/di/typedDataModule\";\n\nexport type MakeContainerProps = {\n dmk: DeviceManagementKit;\n sessionId: DeviceSessionId;\n contextModule: ContextModule;\n};\n\nexport const makeContainer = ({\n dmk,\n sessionId,\n contextModule,\n}: MakeContainerProps) => {\n const container = new Container();\n\n container.bind<DeviceManagementKit>(externalTypes.Dmk).toConstantValue(dmk);\n container\n .bind<ContextModule>(externalTypes.ContextModule)\n .toConstantValue(contextModule);\n container\n .bind<DeviceSessionId>(externalTypes.SessionId)\n .toConstantValue(sessionId);\n\n container.loadSync(\n addressModuleFactory(),\n appBindingModuleFactory(),\n eip7702ModuleFactory(),\n messageModuleFactory(),\n transactionModuleFactory(),\n typedDataModuleFactory(),\n );\n\n return container;\n};\n"],
5
- "mappings": "AAKA,OAAS,aAAAA,MAAiB,YAE1B,OAAS,wBAAAC,MAA4B,qCACrC,OAAS,2BAAAC,MAA+B,0CACxC,OAAS,wBAAAC,MAA4B,qCACrC,OAAS,iBAAAC,MAAqB,0BAC9B,OAAS,wBAAAC,MAA4B,qCACrC,OAAS,4BAAAC,MAAgC,6CACzC,OAAS,0BAAAC,MAA8B,0CAQhC,MAAMC,EAAgB,CAAC,CAC5B,IAAAC,EACA,UAAAC,EACA,cAAAC,CACF,IAA0B,CACxB,MAAMC,EAAY,IAAIZ,EAEtB,OAAAY,EAAU,KAA0BR,EAAc,GAAG,EAAE,gBAAgBK,CAAG,EAC1EG,EACG,KAAoBR,EAAc,aAAa,EAC/C,gBAAgBO,CAAa,EAChCC,EACG,KAAsBR,EAAc,SAAS,EAC7C,gBAAgBM,CAAS,EAE5BE,EAAU,SACRX,EAAqB,EACrBC,EAAwB,EACxBC,EAAqB,EACrBE,EAAqB,EACrBC,EAAyB,EACzBC,EAAuB,CACzB,EAEOK,CACT",
6
- "names": ["Container", "addressModuleFactory", "appBindingModuleFactory", "eip7702ModuleFactory", "externalTypes", "messageModuleFactory", "transactionModuleFactory", "typedDataModuleFactory", "makeContainer", "dmk", "sessionId", "contextModule", "container"]
4
+ "sourcesContent": ["import { type ContextModule } from \"@ledgerhq/context-module\";\nimport {\n type DeviceManagementKit,\n type DeviceSessionId,\n} from \"@ledgerhq/device-management-kit\";\nimport { Container } from \"inversify\";\n\nimport { addressModuleFactory } from \"@internal/address/di/addressModule\";\nimport { appBindingModuleFactory } from \"@internal/app-binder/di/appBinderModule\";\nimport { eip7702ModuleFactory } from \"@internal/eip7702/di/eip7702Module\";\nimport { externalTypes } from \"@internal/externalTypes\";\nimport { messageModuleFactory } from \"@internal/message/di/messageModule\";\nimport { safeModuleFactory } from \"@internal/safe/di/safeModule\";\nimport { transactionModuleFactory } from \"@internal/transaction/di/transactionModule\";\nimport { typedDataModuleFactory } from \"@internal/typed-data/di/typedDataModule\";\n\nexport type MakeContainerProps = {\n dmk: DeviceManagementKit;\n sessionId: DeviceSessionId;\n contextModule: ContextModule;\n};\n\nexport const makeContainer = ({\n dmk,\n sessionId,\n contextModule,\n}: MakeContainerProps) => {\n const container = new Container();\n\n container.bind<DeviceManagementKit>(externalTypes.Dmk).toConstantValue(dmk);\n container\n .bind<ContextModule>(externalTypes.ContextModule)\n .toConstantValue(contextModule);\n container\n .bind<DeviceSessionId>(externalTypes.SessionId)\n .toConstantValue(sessionId);\n\n container.loadSync(\n addressModuleFactory(),\n appBindingModuleFactory(),\n eip7702ModuleFactory(),\n messageModuleFactory(),\n transactionModuleFactory(),\n typedDataModuleFactory(),\n safeModuleFactory(),\n );\n\n return container;\n};\n"],
5
+ "mappings": "AAKA,OAAS,aAAAA,MAAiB,YAE1B,OAAS,wBAAAC,MAA4B,qCACrC,OAAS,2BAAAC,MAA+B,0CACxC,OAAS,wBAAAC,MAA4B,qCACrC,OAAS,iBAAAC,MAAqB,0BAC9B,OAAS,wBAAAC,MAA4B,qCACrC,OAAS,qBAAAC,MAAyB,+BAClC,OAAS,4BAAAC,MAAgC,6CACzC,OAAS,0BAAAC,MAA8B,0CAQhC,MAAMC,EAAgB,CAAC,CAC5B,IAAAC,EACA,UAAAC,EACA,cAAAC,CACF,IAA0B,CACxB,MAAMC,EAAY,IAAIb,EAEtB,OAAAa,EAAU,KAA0BT,EAAc,GAAG,EAAE,gBAAgBM,CAAG,EAC1EG,EACG,KAAoBT,EAAc,aAAa,EAC/C,gBAAgBQ,CAAa,EAChCC,EACG,KAAsBT,EAAc,SAAS,EAC7C,gBAAgBO,CAAS,EAE5BE,EAAU,SACRZ,EAAqB,EACrBC,EAAwB,EACxBC,EAAqB,EACrBE,EAAqB,EACrBE,EAAyB,EACzBC,EAAuB,EACvBF,EAAkB,CACpB,EAEOO,CACT",
6
+ "names": ["Container", "addressModuleFactory", "appBindingModuleFactory", "eip7702ModuleFactory", "externalTypes", "messageModuleFactory", "safeModuleFactory", "transactionModuleFactory", "typedDataModuleFactory", "makeContainer", "dmk", "sessionId", "contextModule", "container"]
7
7
  }
@@ -0,0 +1,2 @@
1
+ import{ContainerModule as o}from"inversify";import{VerifySafeAddressUseCase as r}from"../../safe/use-case/VerifySafeAddressUseCase";import{safeTypes as s}from"./safeTypes";const d=()=>new o(({bind:e})=>{e(s.VerifySafeAddressUseCase).to(r)});export{d as safeModuleFactory};
2
+ //# sourceMappingURL=safeModule.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/internal/safe/di/safeModule.ts"],
4
+ "sourcesContent": ["import { ContainerModule } from \"inversify\";\n\nimport { VerifySafeAddressUseCase } from \"@internal/safe/use-case/VerifySafeAddressUseCase\";\n\nimport { safeTypes } from \"./safeTypes\";\n\nexport const safeModuleFactory = () =>\n new ContainerModule(({ bind }) => {\n bind(safeTypes.VerifySafeAddressUseCase).to(VerifySafeAddressUseCase);\n });\n"],
5
+ "mappings": "AAAA,OAAS,mBAAAA,MAAuB,YAEhC,OAAS,4BAAAC,MAAgC,mDAEzC,OAAS,aAAAC,MAAiB,cAEnB,MAAMC,EAAoB,IAC/B,IAAIH,EAAgB,CAAC,CAAE,KAAAI,CAAK,IAAM,CAChCA,EAAKF,EAAU,wBAAwB,EAAE,GAAGD,CAAwB,CACtE,CAAC",
6
+ "names": ["ContainerModule", "VerifySafeAddressUseCase", "safeTypes", "safeModuleFactory", "bind"]
7
+ }
@@ -0,0 +1,2 @@
1
+ import{Container as t}from"inversify";import{safeModuleFactory as r}from"./safeModule";describe("safeModuleFactory",()=>{describe("Default",()=>{let o,e;beforeEach(()=>{e=r(),o=new t,o.loadSync(e)}),it("should return the safe module",()=>{expect(e).toBeDefined()})})});
2
+ //# sourceMappingURL=safeModule.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/internal/safe/di/safeModule.test.ts"],
4
+ "sourcesContent": ["import { Container } from \"inversify\";\n\nimport { safeModuleFactory } from \"./safeModule\";\n\ndescribe(\"safeModuleFactory\", () => {\n describe(\"Default\", () => {\n let container: Container;\n let mod: ReturnType<typeof safeModuleFactory>;\n beforeEach(() => {\n mod = safeModuleFactory();\n container = new Container();\n container.loadSync(mod);\n });\n\n it(\"should return the safe module\", () => {\n expect(mod).toBeDefined();\n });\n });\n});\n"],
5
+ "mappings": "AAAA,OAAS,aAAAA,MAAiB,YAE1B,OAAS,qBAAAC,MAAyB,eAElC,SAAS,oBAAqB,IAAM,CAClC,SAAS,UAAW,IAAM,CACxB,IAAIC,EACAC,EACJ,WAAW,IAAM,CACfA,EAAMF,EAAkB,EACxBC,EAAY,IAAIF,EAChBE,EAAU,SAASC,CAAG,CACxB,CAAC,EAED,GAAG,gCAAiC,IAAM,CACxC,OAAOA,CAAG,EAAE,YAAY,CAC1B,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["Container", "safeModuleFactory", "container", "mod"]
7
+ }
@@ -0,0 +1,2 @@
1
+ const e={VerifySafeAddressUseCase:Symbol.for("VerifySafeAddressUseCase")};export{e as safeTypes};
2
+ //# sourceMappingURL=safeTypes.js.map