@ledgerhq/device-signer-kit-ethereum 0.0.0-signer-eth-plugin-fix-20250331141239 → 0.0.0-transaction-unfunded-20250917151052

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 (470) hide show
  1. package/README.md +53 -0
  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.js +1 -1
  5. package/lib/cjs/api/SignerEthBuilder.js.map +3 -3
  6. package/lib/cjs/api/SignerEthBuilder.test.js +1 -1
  7. package/lib/cjs/api/SignerEthBuilder.test.js.map +3 -3
  8. package/lib/cjs/api/app-binder/SignDelegationAuthorizationTypes.js +2 -0
  9. package/lib/cjs/api/app-binder/SignDelegationAuthorizationTypes.js.map +7 -0
  10. package/lib/cjs/api/app-binder/SignTransactionDeviceActionTypes.js +1 -1
  11. package/lib/cjs/api/app-binder/SignTransactionDeviceActionTypes.js.map +2 -2
  12. package/lib/cjs/api/app-binder/SignTypedDataDeviceActionTypes.js +1 -1
  13. package/lib/cjs/api/app-binder/SignTypedDataDeviceActionTypes.js.map +2 -2
  14. package/lib/cjs/api/index.js +1 -1
  15. package/lib/cjs/api/index.js.map +3 -3
  16. package/lib/cjs/api/model/AddressOptions.js +1 -1
  17. package/lib/cjs/api/model/AddressOptions.js.map +1 -1
  18. package/lib/cjs/api/model/ClearSigningType.js +2 -0
  19. package/lib/cjs/api/model/ClearSigningType.js.map +7 -0
  20. package/lib/cjs/api/model/MessageOptions.js +2 -0
  21. package/lib/cjs/api/model/MessageOptions.js.map +7 -0
  22. package/lib/cjs/api/model/TransactionOptions.js +1 -1
  23. package/lib/cjs/api/model/TransactionOptions.js.map +1 -1
  24. package/lib/cjs/api/model/TypedDataOptions.js +2 -0
  25. package/lib/cjs/api/model/TypedDataOptions.js.map +7 -0
  26. package/lib/cjs/internal/DefaultSignerEth.js +1 -1
  27. package/lib/cjs/internal/DefaultSignerEth.js.map +3 -3
  28. package/lib/cjs/internal/DefaultSignerEth.test.js +1 -1
  29. package/lib/cjs/internal/DefaultSignerEth.test.js.map +3 -3
  30. package/lib/cjs/internal/address/di/addressModule.js +1 -1
  31. package/lib/cjs/internal/address/di/addressModule.js.map +3 -3
  32. package/lib/cjs/internal/address/di/addressModule.test.js +1 -1
  33. package/lib/cjs/internal/address/di/addressModule.test.js.map +2 -2
  34. package/lib/cjs/internal/address/use-case/GetAddressUseCase.js +1 -1
  35. package/lib/cjs/internal/address/use-case/GetAddressUseCase.js.map +2 -2
  36. package/lib/cjs/internal/address/use-case/GetAddressUseCase.test.js +1 -1
  37. package/lib/cjs/internal/address/use-case/GetAddressUseCase.test.js.map +2 -2
  38. package/lib/cjs/internal/app-binder/EthAppBinder.js +1 -1
  39. package/lib/cjs/internal/app-binder/EthAppBinder.js.map +3 -3
  40. package/lib/cjs/internal/app-binder/EthAppBinder.test.js +1 -1
  41. package/lib/cjs/internal/app-binder/EthAppBinder.test.js.map +3 -3
  42. package/lib/cjs/internal/app-binder/command/ProvideNetworkConfigurationCommand.js +2 -0
  43. package/lib/cjs/internal/app-binder/command/ProvideNetworkConfigurationCommand.js.map +7 -0
  44. package/lib/cjs/internal/app-binder/command/ProvideNetworkConfigurationCommand.test.js +2 -0
  45. package/lib/cjs/internal/app-binder/command/ProvideNetworkConfigurationCommand.test.js.map +7 -0
  46. package/lib/cjs/internal/app-binder/command/ProvideProxyInfoCommand.js +2 -0
  47. package/lib/cjs/internal/app-binder/command/ProvideProxyInfoCommand.js.map +7 -0
  48. package/lib/cjs/internal/app-binder/command/ProvideProxyInfoCommand.test.js +2 -0
  49. package/lib/cjs/internal/app-binder/command/ProvideProxyInfoCommand.test.js.map +7 -0
  50. package/lib/cjs/internal/app-binder/command/SignAuthorizationDelegationCommand.js +2 -0
  51. package/lib/cjs/internal/app-binder/command/SignAuthorizationDelegationCommand.js.map +7 -0
  52. package/lib/cjs/internal/app-binder/command/SignAuthorizationDelegationCommand.test.js +2 -0
  53. package/lib/cjs/internal/app-binder/command/SignAuthorizationDelegationCommand.test.js.map +7 -0
  54. package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js +1 -1
  55. package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js.map +3 -3
  56. package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js +1 -1
  57. package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js.map +3 -3
  58. package/lib/cjs/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.js +1 -1
  59. package/lib/cjs/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.js.map +3 -3
  60. package/lib/cjs/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.test.js +1 -1
  61. package/lib/cjs/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.test.js.map +2 -2
  62. package/lib/cjs/internal/app-binder/device-action/__test-utils__/makeInternalApi.js +1 -1
  63. package/lib/cjs/internal/app-binder/device-action/__test-utils__/makeInternalApi.js.map +3 -3
  64. package/lib/cjs/internal/app-binder/di/appBinderModule.js +1 -1
  65. package/lib/cjs/internal/app-binder/di/appBinderModule.js.map +3 -3
  66. package/lib/cjs/internal/app-binder/task/BuildEIP712ContextTask.js +1 -1
  67. package/lib/cjs/internal/app-binder/task/BuildEIP712ContextTask.js.map +3 -3
  68. package/lib/cjs/internal/app-binder/task/BuildEIP712ContextTask.test.js +1 -1
  69. package/lib/cjs/internal/app-binder/task/BuildEIP712ContextTask.test.js.map +2 -2
  70. package/lib/cjs/internal/app-binder/task/BuildSubContextTask.js +2 -0
  71. package/lib/cjs/internal/app-binder/task/BuildSubContextTask.js.map +7 -0
  72. package/lib/cjs/internal/app-binder/task/BuildSubContextTask.test.js +2 -0
  73. package/lib/cjs/internal/app-binder/task/BuildSubContextTask.test.js.map +7 -0
  74. package/lib/cjs/internal/app-binder/task/BuildTransactionContextTask.js +1 -1
  75. package/lib/cjs/internal/app-binder/task/BuildTransactionContextTask.js.map +3 -3
  76. package/lib/cjs/internal/app-binder/task/BuildTransactionContextTask.test.js +1 -1
  77. package/lib/cjs/internal/app-binder/task/BuildTransactionContextTask.test.js.map +3 -3
  78. package/lib/cjs/internal/app-binder/task/GetWeb3CheckTask.js +1 -1
  79. package/lib/cjs/internal/app-binder/task/GetWeb3CheckTask.js.map +3 -3
  80. package/lib/cjs/internal/app-binder/task/GetWeb3CheckTask.test.js +1 -1
  81. package/lib/cjs/internal/app-binder/task/GetWeb3CheckTask.test.js.map +3 -3
  82. package/lib/cjs/internal/app-binder/task/PreBuildContextTask.js +2 -0
  83. package/lib/cjs/internal/app-binder/task/PreBuildContextTask.js.map +7 -0
  84. package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.js.map +2 -2
  85. package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.test.js +1 -1
  86. package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.test.js.map +2 -2
  87. package/lib/cjs/internal/app-binder/task/ProvideTransactionContextTask.js +1 -1
  88. package/lib/cjs/internal/app-binder/task/ProvideTransactionContextTask.js.map +3 -3
  89. package/lib/cjs/internal/app-binder/task/ProvideTransactionContextTask.test.js +1 -1
  90. package/lib/cjs/internal/app-binder/task/ProvideTransactionContextTask.test.js.map +3 -3
  91. package/lib/cjs/internal/app-binder/task/SendPayloadInChunksTask.js +1 -1
  92. package/lib/cjs/internal/app-binder/task/SendPayloadInChunksTask.js.map +3 -3
  93. package/lib/cjs/internal/app-binder/task/SendPayloadInChunksTask.test.js +1 -1
  94. package/lib/cjs/internal/app-binder/task/SendPayloadInChunksTask.test.js.map +3 -3
  95. package/lib/cjs/internal/app-binder/task/SendSignAuthorizationDelegationTask.js +2 -0
  96. package/lib/cjs/internal/app-binder/task/SendSignAuthorizationDelegationTask.js.map +7 -0
  97. package/lib/cjs/internal/app-binder/task/SendSignAuthorizationDelegationTask.test.js +2 -0
  98. package/lib/cjs/internal/app-binder/task/SendSignAuthorizationDelegationTask.test.js.map +7 -0
  99. package/lib/cjs/internal/app-binder/task/SendSignTransactionTask.js +1 -1
  100. package/lib/cjs/internal/app-binder/task/SendSignTransactionTask.js.map +3 -3
  101. package/lib/cjs/internal/app-binder/task/SendSignTransactionTask.test.js +1 -1
  102. package/lib/cjs/internal/app-binder/task/SendSignTransactionTask.test.js.map +3 -3
  103. package/lib/cjs/internal/app-binder/task/SignTypedDataLegacyTask.js +2 -0
  104. package/lib/cjs/internal/app-binder/task/SignTypedDataLegacyTask.js.map +7 -0
  105. package/lib/cjs/internal/app-binder/task/SignTypedDataLegacyTask.test.js +2 -0
  106. package/lib/cjs/internal/app-binder/task/SignTypedDataLegacyTask.test.js.map +7 -0
  107. package/lib/cjs/internal/di.js +1 -1
  108. package/lib/cjs/internal/di.js.map +3 -3
  109. package/lib/cjs/internal/eip7702/di/eip7702Module.js +2 -0
  110. package/lib/cjs/internal/eip7702/di/eip7702Module.js.map +7 -0
  111. package/lib/cjs/internal/eip7702/di/eip7702Module.test.js +2 -0
  112. package/lib/cjs/internal/eip7702/di/eip7702Module.test.js.map +7 -0
  113. package/lib/cjs/internal/eip7702/di/eip7702Types.js +2 -0
  114. package/lib/cjs/internal/eip7702/di/eip7702Types.js.map +7 -0
  115. package/lib/cjs/internal/eip7702/use-case/SignDelegationAuthorizationUseCase.js +2 -0
  116. package/lib/cjs/internal/eip7702/use-case/SignDelegationAuthorizationUseCase.js.map +7 -0
  117. package/lib/cjs/internal/eip7702/use-case/SignDelegationAuthorizationUseCase.test.js +2 -0
  118. package/lib/cjs/internal/eip7702/use-case/SignDelegationAuthorizationUseCase.test.js.map +7 -0
  119. package/lib/cjs/internal/message/di/messageModule.js +1 -1
  120. package/lib/cjs/internal/message/di/messageModule.js.map +3 -3
  121. package/lib/cjs/internal/message/di/messageModule.test.js +1 -1
  122. package/lib/cjs/internal/message/di/messageModule.test.js.map +2 -2
  123. package/lib/cjs/internal/message/use-case/SignMessageUseCase.js +1 -1
  124. package/lib/cjs/internal/message/use-case/SignMessageUseCase.js.map +3 -3
  125. package/lib/cjs/internal/message/use-case/SignMessageUseCase.test.js +1 -1
  126. package/lib/cjs/internal/message/use-case/SignMessageUseCase.test.js.map +2 -2
  127. package/lib/cjs/internal/shared/utils/ApplicationChecker.js +1 -1
  128. package/lib/cjs/internal/shared/utils/ApplicationChecker.js.map +3 -3
  129. package/lib/cjs/internal/shared/utils/ApplicationChecker.test.js +1 -1
  130. package/lib/cjs/internal/shared/utils/ApplicationChecker.test.js.map +2 -2
  131. package/lib/cjs/internal/transaction/di/transactionModule.js +1 -1
  132. package/lib/cjs/internal/transaction/di/transactionModule.js.map +3 -3
  133. package/lib/cjs/internal/transaction/di/transactionModule.test.js +1 -1
  134. package/lib/cjs/internal/transaction/di/transactionModule.test.js.map +2 -2
  135. package/lib/cjs/internal/transaction/service/mapper/EthersTransactionMapperService.js +2 -0
  136. package/lib/cjs/internal/transaction/service/mapper/EthersTransactionMapperService.js.map +7 -0
  137. package/lib/cjs/internal/transaction/service/mapper/EthersTransactionMapperService.test.js +2 -0
  138. package/lib/cjs/internal/transaction/service/mapper/EthersTransactionMapperService.test.js.map +7 -0
  139. package/lib/cjs/internal/transaction/service/mapper/TransactionMapperService.js +1 -1
  140. package/lib/cjs/internal/transaction/service/mapper/TransactionMapperService.js.map +3 -3
  141. package/lib/cjs/internal/transaction/service/parser/TransactionParserService.js +1 -1
  142. package/lib/cjs/internal/transaction/service/parser/TransactionParserService.js.map +3 -3
  143. package/lib/cjs/internal/transaction/service/parser/TransactionParserService.test.js +1 -1
  144. package/lib/cjs/internal/transaction/service/parser/TransactionParserService.test.js.map +3 -3
  145. package/lib/cjs/internal/typed-data/di/typedDataModule.js +1 -1
  146. package/lib/cjs/internal/typed-data/di/typedDataModule.js.map +3 -3
  147. package/lib/cjs/internal/typed-data/di/typedDataModule.test.js +1 -1
  148. package/lib/cjs/internal/typed-data/di/typedDataModule.test.js.map +2 -2
  149. package/lib/cjs/internal/typed-data/service/DefaultTypedDataParserService.js +1 -1
  150. package/lib/cjs/internal/typed-data/service/DefaultTypedDataParserService.js.map +2 -2
  151. package/lib/cjs/internal/typed-data/service/TypedDataParser.js +1 -1
  152. package/lib/cjs/internal/typed-data/service/TypedDataParser.js.map +3 -3
  153. package/lib/cjs/internal/typed-data/service/TypedDataParser.test.js +1 -1
  154. package/lib/cjs/internal/typed-data/service/TypedDataParser.test.js.map +2 -2
  155. package/lib/cjs/internal/typed-data/use-case/SignTypedDataUseCase.js +1 -1
  156. package/lib/cjs/internal/typed-data/use-case/SignTypedDataUseCase.js.map +3 -3
  157. package/lib/cjs/internal/typed-data/use-case/SignTypedDataUseCase.test.js +1 -1
  158. package/lib/cjs/internal/typed-data/use-case/SignTypedDataUseCase.test.js.map +2 -2
  159. package/lib/cjs/package.json +13 -14
  160. package/lib/esm/api/SignerEthBuilder.js +1 -1
  161. package/lib/esm/api/SignerEthBuilder.js.map +3 -3
  162. package/lib/esm/api/SignerEthBuilder.test.js +1 -1
  163. package/lib/esm/api/SignerEthBuilder.test.js.map +3 -3
  164. package/lib/esm/api/app-binder/SignDelegationAuthorizationTypes.js +1 -0
  165. package/lib/esm/api/app-binder/SignTransactionDeviceActionTypes.js +1 -1
  166. package/lib/esm/api/app-binder/SignTransactionDeviceActionTypes.js.map +2 -2
  167. package/lib/esm/api/app-binder/SignTypedDataDeviceActionTypes.js +1 -1
  168. package/lib/esm/api/app-binder/SignTypedDataDeviceActionTypes.js.map +2 -2
  169. package/lib/esm/api/index.js +1 -1
  170. package/lib/esm/api/index.js.map +2 -2
  171. package/lib/esm/api/model/ClearSigningType.js +2 -0
  172. package/lib/esm/api/model/ClearSigningType.js.map +7 -0
  173. package/lib/esm/api/model/MessageOptions.js +1 -0
  174. package/lib/esm/api/model/MessageOptions.js.map +7 -0
  175. package/lib/esm/api/model/TypedDataOptions.js +1 -0
  176. package/lib/esm/api/model/TypedDataOptions.js.map +7 -0
  177. package/lib/esm/internal/DefaultSignerEth.js +1 -1
  178. package/lib/esm/internal/DefaultSignerEth.js.map +3 -3
  179. package/lib/esm/internal/DefaultSignerEth.test.js +1 -1
  180. package/lib/esm/internal/DefaultSignerEth.test.js.map +3 -3
  181. package/lib/esm/internal/address/di/addressModule.js +1 -1
  182. package/lib/esm/internal/address/di/addressModule.js.map +3 -3
  183. package/lib/esm/internal/address/di/addressModule.test.js +1 -1
  184. package/lib/esm/internal/address/di/addressModule.test.js.map +2 -2
  185. package/lib/esm/internal/address/use-case/GetAddressUseCase.js +1 -1
  186. package/lib/esm/internal/address/use-case/GetAddressUseCase.js.map +2 -2
  187. package/lib/esm/internal/address/use-case/GetAddressUseCase.test.js +1 -1
  188. package/lib/esm/internal/address/use-case/GetAddressUseCase.test.js.map +2 -2
  189. package/lib/esm/internal/app-binder/EthAppBinder.js +1 -1
  190. package/lib/esm/internal/app-binder/EthAppBinder.js.map +3 -3
  191. package/lib/esm/internal/app-binder/EthAppBinder.test.js +1 -1
  192. package/lib/esm/internal/app-binder/EthAppBinder.test.js.map +3 -3
  193. package/lib/esm/internal/app-binder/command/ProvideNetworkConfigurationCommand.js +2 -0
  194. package/lib/esm/internal/app-binder/command/ProvideNetworkConfigurationCommand.js.map +7 -0
  195. package/lib/esm/internal/app-binder/command/ProvideNetworkConfigurationCommand.test.js +2 -0
  196. package/lib/esm/internal/app-binder/command/ProvideNetworkConfigurationCommand.test.js.map +7 -0
  197. package/lib/esm/internal/app-binder/command/ProvideProxyInfoCommand.js +2 -0
  198. package/lib/esm/internal/app-binder/command/ProvideProxyInfoCommand.js.map +7 -0
  199. package/lib/esm/internal/app-binder/command/ProvideProxyInfoCommand.test.js +2 -0
  200. package/lib/esm/internal/app-binder/command/ProvideProxyInfoCommand.test.js.map +7 -0
  201. package/lib/esm/internal/app-binder/command/SignAuthorizationDelegationCommand.js +2 -0
  202. package/lib/esm/internal/app-binder/command/SignAuthorizationDelegationCommand.js.map +7 -0
  203. package/lib/esm/internal/app-binder/command/SignAuthorizationDelegationCommand.test.js +2 -0
  204. package/lib/esm/internal/app-binder/command/SignAuthorizationDelegationCommand.test.js.map +7 -0
  205. package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js +1 -1
  206. package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js.map +3 -3
  207. package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js +1 -1
  208. package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js.map +3 -3
  209. package/lib/esm/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.js +1 -1
  210. package/lib/esm/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.js.map +3 -3
  211. package/lib/esm/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.test.js +1 -1
  212. package/lib/esm/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.test.js.map +2 -2
  213. package/lib/esm/internal/app-binder/device-action/__test-utils__/makeInternalApi.js +1 -1
  214. package/lib/esm/internal/app-binder/device-action/__test-utils__/makeInternalApi.js.map +3 -3
  215. package/lib/esm/internal/app-binder/di/appBinderModule.js +1 -1
  216. package/lib/esm/internal/app-binder/di/appBinderModule.js.map +3 -3
  217. package/lib/esm/internal/app-binder/task/BuildEIP712ContextTask.js +1 -1
  218. package/lib/esm/internal/app-binder/task/BuildEIP712ContextTask.js.map +3 -3
  219. package/lib/esm/internal/app-binder/task/BuildEIP712ContextTask.test.js +1 -1
  220. package/lib/esm/internal/app-binder/task/BuildEIP712ContextTask.test.js.map +2 -2
  221. package/lib/esm/internal/app-binder/task/BuildSubContextTask.js +2 -0
  222. package/lib/esm/internal/app-binder/task/BuildSubContextTask.js.map +7 -0
  223. package/lib/esm/internal/app-binder/task/BuildSubContextTask.test.js +2 -0
  224. package/lib/esm/internal/app-binder/task/BuildSubContextTask.test.js.map +7 -0
  225. package/lib/esm/internal/app-binder/task/BuildTransactionContextTask.js +1 -1
  226. package/lib/esm/internal/app-binder/task/BuildTransactionContextTask.js.map +3 -3
  227. package/lib/esm/internal/app-binder/task/BuildTransactionContextTask.test.js +1 -1
  228. package/lib/esm/internal/app-binder/task/BuildTransactionContextTask.test.js.map +3 -3
  229. package/lib/esm/internal/app-binder/task/GetWeb3CheckTask.js +1 -1
  230. package/lib/esm/internal/app-binder/task/GetWeb3CheckTask.js.map +3 -3
  231. package/lib/esm/internal/app-binder/task/GetWeb3CheckTask.test.js +1 -1
  232. package/lib/esm/internal/app-binder/task/GetWeb3CheckTask.test.js.map +3 -3
  233. package/lib/esm/internal/app-binder/task/PreBuildContextTask.js +2 -0
  234. package/lib/esm/internal/app-binder/task/PreBuildContextTask.js.map +7 -0
  235. package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.js.map +2 -2
  236. package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.test.js +1 -1
  237. package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.test.js.map +2 -2
  238. package/lib/esm/internal/app-binder/task/ProvideTransactionContextTask.js +1 -1
  239. package/lib/esm/internal/app-binder/task/ProvideTransactionContextTask.js.map +3 -3
  240. package/lib/esm/internal/app-binder/task/ProvideTransactionContextTask.test.js +1 -1
  241. package/lib/esm/internal/app-binder/task/ProvideTransactionContextTask.test.js.map +3 -3
  242. package/lib/esm/internal/app-binder/task/SendPayloadInChunksTask.js +1 -1
  243. package/lib/esm/internal/app-binder/task/SendPayloadInChunksTask.js.map +3 -3
  244. package/lib/esm/internal/app-binder/task/SendPayloadInChunksTask.test.js +1 -1
  245. package/lib/esm/internal/app-binder/task/SendPayloadInChunksTask.test.js.map +3 -3
  246. package/lib/esm/internal/app-binder/task/SendSignAuthorizationDelegationTask.js +2 -0
  247. package/lib/esm/internal/app-binder/task/SendSignAuthorizationDelegationTask.js.map +7 -0
  248. package/lib/esm/internal/app-binder/task/SendSignAuthorizationDelegationTask.test.js +2 -0
  249. package/lib/esm/internal/app-binder/task/SendSignAuthorizationDelegationTask.test.js.map +7 -0
  250. package/lib/esm/internal/app-binder/task/SendSignTransactionTask.js +1 -1
  251. package/lib/esm/internal/app-binder/task/SendSignTransactionTask.js.map +3 -3
  252. package/lib/esm/internal/app-binder/task/SendSignTransactionTask.test.js +1 -1
  253. package/lib/esm/internal/app-binder/task/SendSignTransactionTask.test.js.map +3 -3
  254. package/lib/esm/internal/app-binder/task/SignTypedDataLegacyTask.js +2 -0
  255. package/lib/esm/internal/app-binder/task/SignTypedDataLegacyTask.js.map +7 -0
  256. package/lib/esm/internal/app-binder/task/SignTypedDataLegacyTask.test.js +2 -0
  257. package/lib/esm/internal/app-binder/task/SignTypedDataLegacyTask.test.js.map +7 -0
  258. package/lib/esm/internal/di.js +1 -1
  259. package/lib/esm/internal/di.js.map +3 -3
  260. package/lib/esm/internal/eip7702/di/eip7702Module.js +2 -0
  261. package/lib/esm/internal/eip7702/di/eip7702Module.js.map +7 -0
  262. package/lib/esm/internal/eip7702/di/eip7702Module.test.js +2 -0
  263. package/lib/esm/internal/eip7702/di/eip7702Module.test.js.map +7 -0
  264. package/lib/esm/internal/eip7702/di/eip7702Types.js +2 -0
  265. package/lib/esm/internal/eip7702/di/eip7702Types.js.map +7 -0
  266. package/lib/esm/internal/eip7702/use-case/SignDelegationAuthorizationUseCase.js +2 -0
  267. package/lib/esm/internal/eip7702/use-case/SignDelegationAuthorizationUseCase.js.map +7 -0
  268. package/lib/esm/internal/eip7702/use-case/SignDelegationAuthorizationUseCase.test.js +2 -0
  269. package/lib/esm/internal/eip7702/use-case/SignDelegationAuthorizationUseCase.test.js.map +7 -0
  270. package/lib/esm/internal/message/di/messageModule.js +1 -1
  271. package/lib/esm/internal/message/di/messageModule.js.map +3 -3
  272. package/lib/esm/internal/message/di/messageModule.test.js +1 -1
  273. package/lib/esm/internal/message/di/messageModule.test.js.map +2 -2
  274. package/lib/esm/internal/message/use-case/SignMessageUseCase.js +1 -1
  275. package/lib/esm/internal/message/use-case/SignMessageUseCase.js.map +3 -3
  276. package/lib/esm/internal/message/use-case/SignMessageUseCase.test.js +1 -1
  277. package/lib/esm/internal/message/use-case/SignMessageUseCase.test.js.map +2 -2
  278. package/lib/esm/internal/shared/utils/ApplicationChecker.js +1 -1
  279. package/lib/esm/internal/shared/utils/ApplicationChecker.js.map +3 -3
  280. package/lib/esm/internal/shared/utils/ApplicationChecker.test.js +1 -1
  281. package/lib/esm/internal/shared/utils/ApplicationChecker.test.js.map +2 -2
  282. package/lib/esm/internal/transaction/di/transactionModule.js +1 -1
  283. package/lib/esm/internal/transaction/di/transactionModule.js.map +3 -3
  284. package/lib/esm/internal/transaction/di/transactionModule.test.js +1 -1
  285. package/lib/esm/internal/transaction/di/transactionModule.test.js.map +2 -2
  286. package/lib/esm/internal/transaction/service/mapper/EthersTransactionMapperService.js +2 -0
  287. package/lib/esm/internal/transaction/service/mapper/EthersTransactionMapperService.js.map +7 -0
  288. package/lib/esm/internal/transaction/service/mapper/EthersTransactionMapperService.test.js +2 -0
  289. package/lib/esm/internal/transaction/service/mapper/EthersTransactionMapperService.test.js.map +7 -0
  290. package/lib/esm/internal/transaction/service/mapper/TransactionMapperService.js +0 -1
  291. package/lib/esm/internal/transaction/service/mapper/TransactionMapperService.js.map +4 -4
  292. package/lib/esm/internal/transaction/service/parser/TransactionParserService.js +1 -1
  293. package/lib/esm/internal/transaction/service/parser/TransactionParserService.js.map +3 -3
  294. package/lib/esm/internal/transaction/service/parser/TransactionParserService.test.js +1 -1
  295. package/lib/esm/internal/transaction/service/parser/TransactionParserService.test.js.map +3 -3
  296. package/lib/esm/internal/typed-data/di/typedDataModule.js +1 -1
  297. package/lib/esm/internal/typed-data/di/typedDataModule.js.map +3 -3
  298. package/lib/esm/internal/typed-data/di/typedDataModule.test.js +1 -1
  299. package/lib/esm/internal/typed-data/di/typedDataModule.test.js.map +2 -2
  300. package/lib/esm/internal/typed-data/service/DefaultTypedDataParserService.js +1 -1
  301. package/lib/esm/internal/typed-data/service/DefaultTypedDataParserService.js.map +2 -2
  302. package/lib/esm/internal/typed-data/service/TypedDataParser.js +1 -1
  303. package/lib/esm/internal/typed-data/service/TypedDataParser.js.map +3 -3
  304. package/lib/esm/internal/typed-data/service/TypedDataParser.test.js +1 -1
  305. package/lib/esm/internal/typed-data/service/TypedDataParser.test.js.map +2 -2
  306. package/lib/esm/internal/typed-data/use-case/SignTypedDataUseCase.js +1 -1
  307. package/lib/esm/internal/typed-data/use-case/SignTypedDataUseCase.js.map +3 -3
  308. package/lib/esm/internal/typed-data/use-case/SignTypedDataUseCase.test.js +1 -1
  309. package/lib/esm/internal/typed-data/use-case/SignTypedDataUseCase.test.js.map +2 -2
  310. package/lib/esm/package.json +13 -14
  311. package/lib/types/api/SignerEth.d.ts +8 -4
  312. package/lib/types/api/SignerEth.d.ts.map +1 -1
  313. package/lib/types/api/SignerEthBuilder.d.ts +4 -2
  314. package/lib/types/api/SignerEthBuilder.d.ts.map +1 -1
  315. package/lib/types/api/app-binder/SignDelegationAuthorizationTypes.d.ts +19 -0
  316. package/lib/types/api/app-binder/SignDelegationAuthorizationTypes.d.ts.map +1 -0
  317. package/lib/types/api/app-binder/SignTransactionDeviceActionTypes.d.ts +14 -10
  318. package/lib/types/api/app-binder/SignTransactionDeviceActionTypes.d.ts.map +1 -1
  319. package/lib/types/api/app-binder/SignTypedDataDeviceActionTypes.d.ts +7 -1
  320. package/lib/types/api/app-binder/SignTypedDataDeviceActionTypes.d.ts.map +1 -1
  321. package/lib/types/api/index.d.ts +5 -4
  322. package/lib/types/api/index.d.ts.map +1 -1
  323. package/lib/types/api/model/AddressOptions.d.ts +1 -0
  324. package/lib/types/api/model/AddressOptions.d.ts.map +1 -1
  325. package/lib/types/api/model/ClearSigningType.d.ts +5 -0
  326. package/lib/types/api/model/ClearSigningType.d.ts.map +1 -0
  327. package/lib/types/api/model/MessageOptions.d.ts +4 -0
  328. package/lib/types/api/model/MessageOptions.d.ts.map +1 -0
  329. package/lib/types/api/model/TransactionOptions.d.ts +1 -0
  330. package/lib/types/api/model/TransactionOptions.d.ts.map +1 -1
  331. package/lib/types/api/model/TypedDataOptions.d.ts +4 -0
  332. package/lib/types/api/model/TypedDataOptions.d.ts.map +1 -0
  333. package/lib/types/internal/DefaultSignerEth.d.ts +7 -3
  334. package/lib/types/internal/DefaultSignerEth.d.ts.map +1 -1
  335. package/lib/types/internal/address/di/addressModule.d.ts.map +1 -1
  336. package/lib/types/internal/address/use-case/GetAddressUseCase.d.ts.map +1 -1
  337. package/lib/types/internal/app-binder/EthAppBinder.d.ts +13 -3
  338. package/lib/types/internal/app-binder/EthAppBinder.d.ts.map +1 -1
  339. package/lib/types/internal/app-binder/command/ProvideNetworkConfigurationCommand.d.ts +28 -0
  340. package/lib/types/internal/app-binder/command/ProvideNetworkConfigurationCommand.d.ts.map +1 -0
  341. package/lib/types/internal/app-binder/command/ProvideNetworkConfigurationCommand.test.d.ts +2 -0
  342. package/lib/types/internal/app-binder/command/ProvideNetworkConfigurationCommand.test.d.ts.map +1 -0
  343. package/lib/types/internal/app-binder/command/ProvideProxyInfoCommand.d.ts +20 -0
  344. package/lib/types/internal/app-binder/command/ProvideProxyInfoCommand.d.ts.map +1 -0
  345. package/lib/types/internal/app-binder/command/ProvideProxyInfoCommand.test.d.ts +2 -0
  346. package/lib/types/internal/app-binder/command/ProvideProxyInfoCommand.test.d.ts.map +1 -0
  347. package/lib/types/internal/app-binder/command/SignAuthorizationDelegationCommand.d.ts +29 -0
  348. package/lib/types/internal/app-binder/command/SignAuthorizationDelegationCommand.d.ts.map +1 -0
  349. package/lib/types/internal/app-binder/command/SignAuthorizationDelegationCommand.test.d.ts +2 -0
  350. package/lib/types/internal/app-binder/command/SignAuthorizationDelegationCommand.test.d.ts.map +1 -0
  351. package/lib/types/internal/app-binder/command/utils/ethAppErrors.d.ts.map +1 -1
  352. package/lib/types/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.d.ts +14 -31
  353. package/lib/types/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.d.ts.map +1 -1
  354. package/lib/types/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.d.ts +1 -2
  355. package/lib/types/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.d.ts.map +1 -1
  356. package/lib/types/internal/app-binder/device-action/__test-utils__/makeInternalApi.d.ts.map +1 -1
  357. package/lib/types/internal/app-binder/device-action/__test-utils__/setupOpenAppDAMock.d.ts.map +1 -1
  358. package/lib/types/internal/app-binder/di/appBinderModule.d.ts.map +1 -1
  359. package/lib/types/internal/app-binder/task/BuildEIP712ContextTask.d.ts.map +1 -1
  360. package/lib/types/internal/app-binder/task/BuildSubContextTask.d.ts +20 -0
  361. package/lib/types/internal/app-binder/task/BuildSubContextTask.d.ts.map +1 -0
  362. package/lib/types/internal/app-binder/task/BuildSubContextTask.test.d.ts +2 -0
  363. package/lib/types/internal/app-binder/task/BuildSubContextTask.test.d.ts.map +1 -0
  364. package/lib/types/internal/app-binder/task/BuildTransactionContextTask.d.ts +10 -14
  365. package/lib/types/internal/app-binder/task/BuildTransactionContextTask.d.ts.map +1 -1
  366. package/lib/types/internal/app-binder/task/GetWeb3CheckTask.d.ts +2 -3
  367. package/lib/types/internal/app-binder/task/GetWeb3CheckTask.d.ts.map +1 -1
  368. package/lib/types/internal/app-binder/task/PreBuildContextTask.d.ts +17 -0
  369. package/lib/types/internal/app-binder/task/PreBuildContextTask.d.ts.map +1 -0
  370. package/lib/types/internal/app-binder/task/ProvideEIP712ContextTask.d.ts +0 -2
  371. package/lib/types/internal/app-binder/task/ProvideEIP712ContextTask.d.ts.map +1 -1
  372. package/lib/types/internal/app-binder/task/ProvideTransactionContextTask.d.ts +28 -22
  373. package/lib/types/internal/app-binder/task/ProvideTransactionContextTask.d.ts.map +1 -1
  374. package/lib/types/internal/app-binder/task/SendPayloadInChunksTask.d.ts +2 -2
  375. package/lib/types/internal/app-binder/task/SendPayloadInChunksTask.d.ts.map +1 -1
  376. package/lib/types/internal/app-binder/task/SendSignAuthorizationDelegationTask.d.ts +18 -0
  377. package/lib/types/internal/app-binder/task/SendSignAuthorizationDelegationTask.d.ts.map +1 -0
  378. package/lib/types/internal/app-binder/task/SendSignAuthorizationDelegationTask.test.d.ts +2 -0
  379. package/lib/types/internal/app-binder/task/SendSignAuthorizationDelegationTask.test.d.ts.map +1 -0
  380. package/lib/types/internal/app-binder/task/SendSignTransactionTask.d.ts +2 -1
  381. package/lib/types/internal/app-binder/task/SendSignTransactionTask.d.ts.map +1 -1
  382. package/lib/types/internal/app-binder/task/SignTypedDataLegacyTask.d.ts +12 -0
  383. package/lib/types/internal/app-binder/task/SignTypedDataLegacyTask.d.ts.map +1 -0
  384. package/lib/types/internal/app-binder/task/SignTypedDataLegacyTask.test.d.ts +2 -0
  385. package/lib/types/internal/app-binder/task/SignTypedDataLegacyTask.test.d.ts.map +1 -0
  386. package/lib/types/internal/di.d.ts.map +1 -1
  387. package/lib/types/internal/eip7702/di/eip7702Module.d.ts +3 -0
  388. package/lib/types/internal/eip7702/di/eip7702Module.d.ts.map +1 -0
  389. package/lib/types/internal/eip7702/di/eip7702Module.test.d.ts +2 -0
  390. package/lib/types/internal/eip7702/di/eip7702Module.test.d.ts.map +1 -0
  391. package/lib/types/internal/eip7702/di/eip7702Types.d.ts +4 -0
  392. package/lib/types/internal/eip7702/di/eip7702Types.d.ts.map +1 -0
  393. package/lib/types/internal/eip7702/use-case/SignDelegationAuthorizationUseCase.d.ts +8 -0
  394. package/lib/types/internal/eip7702/use-case/SignDelegationAuthorizationUseCase.d.ts.map +1 -0
  395. package/lib/types/internal/eip7702/use-case/SignDelegationAuthorizationUseCase.test.d.ts +2 -0
  396. package/lib/types/internal/eip7702/use-case/SignDelegationAuthorizationUseCase.test.d.ts.map +1 -0
  397. package/lib/types/internal/message/di/messageModule.d.ts.map +1 -1
  398. package/lib/types/internal/message/use-case/SignMessageUseCase.d.ts +2 -1
  399. package/lib/types/internal/message/use-case/SignMessageUseCase.d.ts.map +1 -1
  400. package/lib/types/internal/shared/utils/ApplicationChecker.d.ts.map +1 -1
  401. package/lib/types/internal/transaction/di/transactionModule.d.ts.map +1 -1
  402. package/lib/types/internal/transaction/service/mapper/EthersTransactionMapperService.d.ts +8 -0
  403. package/lib/types/internal/transaction/service/mapper/EthersTransactionMapperService.d.ts.map +1 -0
  404. package/lib/types/internal/transaction/service/mapper/EthersTransactionMapperService.test.d.ts +2 -0
  405. package/lib/types/internal/transaction/service/mapper/EthersTransactionMapperService.test.d.ts.map +1 -0
  406. package/lib/types/internal/transaction/service/mapper/TransactionMapperService.d.ts +4 -7
  407. package/lib/types/internal/transaction/service/mapper/TransactionMapperService.d.ts.map +1 -1
  408. package/lib/types/internal/transaction/service/parser/TransactionParserService.d.ts +2 -2
  409. package/lib/types/internal/transaction/service/parser/TransactionParserService.d.ts.map +1 -1
  410. package/lib/types/internal/typed-data/di/typedDataModule.d.ts.map +1 -1
  411. package/lib/types/internal/typed-data/service/TypedDataParser.d.ts +4 -2
  412. package/lib/types/internal/typed-data/service/TypedDataParser.d.ts.map +1 -1
  413. package/lib/types/internal/typed-data/use-case/SignTypedDataUseCase.d.ts +2 -1
  414. package/lib/types/internal/typed-data/use-case/SignTypedDataUseCase.d.ts.map +1 -1
  415. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  416. package/package.json +19 -20
  417. package/lib/cjs/internal/app-binder/constant/plugins.js +0 -2
  418. package/lib/cjs/internal/app-binder/constant/plugins.js.map +0 -7
  419. package/lib/cjs/internal/app-binder/task/ProvideTransactionFieldDescriptionTask.js +0 -2
  420. package/lib/cjs/internal/app-binder/task/ProvideTransactionFieldDescriptionTask.js.map +0 -7
  421. package/lib/cjs/internal/app-binder/task/ProvideTransactionFieldDescriptionTask.test.js +0 -2
  422. package/lib/cjs/internal/app-binder/task/ProvideTransactionFieldDescriptionTask.test.js.map +0 -7
  423. package/lib/cjs/internal/app-binder/task/ProvideTransactionGenericContextTask.js +0 -2
  424. package/lib/cjs/internal/app-binder/task/ProvideTransactionGenericContextTask.js.map +0 -7
  425. package/lib/cjs/internal/app-binder/task/ProvideTransactionGenericContextTask.test.js +0 -2
  426. package/lib/cjs/internal/app-binder/task/ProvideTransactionGenericContextTask.test.js.map +0 -7
  427. package/lib/cjs/internal/transaction/service/mapper/EthersRawTransactionMapper.js +0 -2
  428. package/lib/cjs/internal/transaction/service/mapper/EthersRawTransactionMapper.js.map +0 -7
  429. package/lib/cjs/internal/transaction/service/mapper/EthersRawTransactionMapper.test.js +0 -2
  430. package/lib/cjs/internal/transaction/service/mapper/EthersRawTransactionMapper.test.js.map +0 -7
  431. package/lib/cjs/internal/transaction/service/mapper/TransactionMapper.js +0 -2
  432. package/lib/cjs/internal/transaction/service/mapper/TransactionMapper.js.map +0 -7
  433. package/lib/cjs/internal/transaction/service/mapper/TransactionMapperService.test.js +0 -2
  434. package/lib/cjs/internal/transaction/service/mapper/TransactionMapperService.test.js.map +0 -7
  435. package/lib/esm/internal/app-binder/constant/plugins.js +0 -2
  436. package/lib/esm/internal/app-binder/constant/plugins.js.map +0 -7
  437. package/lib/esm/internal/app-binder/task/ProvideTransactionFieldDescriptionTask.js +0 -2
  438. package/lib/esm/internal/app-binder/task/ProvideTransactionFieldDescriptionTask.js.map +0 -7
  439. package/lib/esm/internal/app-binder/task/ProvideTransactionFieldDescriptionTask.test.js +0 -2
  440. package/lib/esm/internal/app-binder/task/ProvideTransactionFieldDescriptionTask.test.js.map +0 -7
  441. package/lib/esm/internal/app-binder/task/ProvideTransactionGenericContextTask.js +0 -2
  442. package/lib/esm/internal/app-binder/task/ProvideTransactionGenericContextTask.js.map +0 -7
  443. package/lib/esm/internal/app-binder/task/ProvideTransactionGenericContextTask.test.js +0 -2
  444. package/lib/esm/internal/app-binder/task/ProvideTransactionGenericContextTask.test.js.map +0 -7
  445. package/lib/esm/internal/transaction/service/mapper/EthersRawTransactionMapper.js +0 -2
  446. package/lib/esm/internal/transaction/service/mapper/EthersRawTransactionMapper.js.map +0 -7
  447. package/lib/esm/internal/transaction/service/mapper/EthersRawTransactionMapper.test.js +0 -2
  448. package/lib/esm/internal/transaction/service/mapper/EthersRawTransactionMapper.test.js.map +0 -7
  449. package/lib/esm/internal/transaction/service/mapper/TransactionMapper.js +0 -1
  450. package/lib/esm/internal/transaction/service/mapper/TransactionMapperService.test.js +0 -2
  451. package/lib/esm/internal/transaction/service/mapper/TransactionMapperService.test.js.map +0 -7
  452. package/lib/types/internal/app-binder/constant/plugins.d.ts +0 -2
  453. package/lib/types/internal/app-binder/constant/plugins.d.ts.map +0 -1
  454. package/lib/types/internal/app-binder/task/ProvideTransactionFieldDescriptionTask.d.ts +0 -80
  455. package/lib/types/internal/app-binder/task/ProvideTransactionFieldDescriptionTask.d.ts.map +0 -1
  456. package/lib/types/internal/app-binder/task/ProvideTransactionFieldDescriptionTask.test.d.ts +0 -2
  457. package/lib/types/internal/app-binder/task/ProvideTransactionFieldDescriptionTask.test.d.ts.map +0 -1
  458. package/lib/types/internal/app-binder/task/ProvideTransactionGenericContextTask.d.ts +0 -28
  459. package/lib/types/internal/app-binder/task/ProvideTransactionGenericContextTask.d.ts.map +0 -1
  460. package/lib/types/internal/app-binder/task/ProvideTransactionGenericContextTask.test.d.ts +0 -2
  461. package/lib/types/internal/app-binder/task/ProvideTransactionGenericContextTask.test.d.ts.map +0 -1
  462. package/lib/types/internal/transaction/service/mapper/EthersRawTransactionMapper.d.ts +0 -7
  463. package/lib/types/internal/transaction/service/mapper/EthersRawTransactionMapper.d.ts.map +0 -1
  464. package/lib/types/internal/transaction/service/mapper/EthersRawTransactionMapper.test.d.ts +0 -2
  465. package/lib/types/internal/transaction/service/mapper/EthersRawTransactionMapper.test.d.ts.map +0 -1
  466. package/lib/types/internal/transaction/service/mapper/TransactionMapper.d.ts +0 -6
  467. package/lib/types/internal/transaction/service/mapper/TransactionMapper.d.ts.map +0 -1
  468. package/lib/types/internal/transaction/service/mapper/TransactionMapperService.test.d.ts +0 -2
  469. package/lib/types/internal/transaction/service/mapper/TransactionMapperService.test.d.ts.map +0 -1
  470. /package/lib/esm/{internal/transaction/service/mapper/TransactionMapper.js.map → api/app-binder/SignDelegationAuthorizationTypes.js.map} +0 -0
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/internal/app-binder/task/BuildEIP712ContextTask.test.ts"],
4
- "sourcesContent": ["import type {\n ClearSignContextSuccess,\n ClearSignContextType,\n TypedDataClearSignContextSuccess,\n} from \"@ledgerhq/context-module\";\nimport {\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n} from \"@ledgerhq/device-management-kit\";\nimport { Just, Left, Nothing, Right } from \"purify-ts\";\n\nimport type { GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\nimport {\n PrimitiveType,\n StructType,\n TypedDataValueField,\n TypedDataValueRoot,\n} from \"@internal/typed-data/model/Types\";\n\nimport { BuildEIP712ContextTask } from \"./BuildEIP712ContextTask\";\n\ndescribe(\"BuildEIP712ContextTask\", () => {\n const apiMock = makeDeviceActionInternalApiMock();\n const contextMouleMock = {\n getContext: vi.fn(),\n getContexts: vi.fn(),\n getTypedDataFilters: vi.fn(),\n getWeb3Checks: vi.fn(),\n };\n const parserMock = {\n parse: vi.fn(),\n };\n const getWeb3ChecksFactoryMock = vi.fn();\n\n function createAppConfig(\n web3ChecksEnabled: boolean,\n ): GetConfigCommandResponse {\n return {\n blindSigningEnabled: false,\n web3ChecksEnabled,\n web3ChecksOptIn: false,\n version: \"1.13.0\",\n };\n }\n\n const TEST_DATA = {\n domain: {\n name: \"Permit2\",\n chainId: 137,\n verifyingContract: \"0x000000000022d473030f116ddee9f6b43ac78ba3\",\n },\n primaryType: \"PermitSingle\",\n message: {\n details: {\n token: \"0x7ceb23fd6bc0add59e62ac25578270cff1b9f619\",\n amount: \"69420000000000000000\",\n expiration: \"1718184249\",\n nonce: \"0\",\n },\n spender: \"0xec7be89e9d109e7e3fec59c222cf297125fefda2\",\n sigDeadline: \"1715594049\",\n },\n types: {\n PermitSingle: [\n {\n name: \"details\",\n type: \"PermitDetails\",\n },\n {\n name: \"spender\",\n type: \"address\",\n },\n {\n name: \"sigDeadline\",\n type: \"uint256\",\n },\n ],\n PermitDetails: [\n { name: \"token\", type: \"address\" },\n { name: \"amount\", type: \"uint\" },\n { name: \"expiration\", type: \"uint\" },\n { name: \"nonce\", type: \"uint\" },\n ],\n },\n };\n\n const TEST_TYPES = {\n PermitSingle: {\n details: new StructType(\"PermitDetails\"),\n spender: new PrimitiveType(\"address\", \"address\", Nothing),\n sigDeadline: new PrimitiveType(\"uint256\", \"uint\", Just(32)),\n },\n PermitDetails: {\n token: new PrimitiveType(\"address\", \"address\", Nothing),\n amount: new PrimitiveType(\"uint160\", \"uint\", Just(20)),\n expiration: new PrimitiveType(\"uint48\", \"uint\", Just(6)),\n nonce: new PrimitiveType(\"uint48\", \"uint\", Just(6)),\n },\n };\n const TEST_DOMAIN_VALUES = [\n {\n path: \"\",\n type: \"\",\n value: new TypedDataValueRoot(\"EIP712Domain\"),\n },\n {\n path: \"chainId\",\n type: \"uint256\",\n value: new TypedDataValueField(Uint8Array.from([137])),\n },\n ];\n const TEST_MESSAGE_VALUES = [\n {\n path: \"\",\n type: \"\",\n value: new TypedDataValueRoot(\"PermitSingle\"),\n },\n {\n path: \"details.amount\",\n type: \"uint160\",\n value: new TypedDataValueField(Uint8Array.from([0x12])),\n },\n {\n path: \"details.expiration\",\n type: \"uint48\",\n value: new TypedDataValueField(Uint8Array.from([0x13])),\n },\n ];\n const TEST_CLEAR_SIGN_CONTEXT: TypedDataClearSignContextSuccess = {\n type: \"success\",\n messageInfo: {\n displayName: \"Permit2\",\n filtersCount: 1,\n signature:\n \"3045022100e3c597d13d28a87a88b0239404c668373cf5063362f2a81d09eed4582941dfe802207669aabb504fd5b95b2734057f6b8bbf51f14a69a5f9bdf658a5952cefbf44d3\",\n },\n trustedNamesAddresses: {},\n tokens: {},\n filters: {\n \"details.amount\": {\n displayName: \"Amount allowance\",\n path: \"details.amount\",\n signature:\n \"304402201a46e6b4ef89eaf9fcf4945d053bfc5616a826400fd758312fbbe976bafc07ec022025a9b408722baf983ee053f90179c75b0c55bb0668f437d55493e36069bbd5a3\",\n tokenIndex: 255,\n type: \"amount\",\n },\n },\n };\n\n beforeEach(() => {\n vi.resetAllMocks();\n getWeb3ChecksFactoryMock.mockReturnValue({\n run: async () => ({ web3Check: null }),\n });\n });\n\n it(\"Build context with clear signing context not supported by the device\", async () => {\n // GIVEN\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n TEST_DATA,\n \"44'/60'/0'/0/0\",\n createAppConfig(false),\n getWeb3ChecksFactoryMock,\n );\n parserMock.parse.mockReturnValueOnce(\n Right({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n }),\n );\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.11.0\" },\n deviceModelId: DeviceModelId.NANO_S,\n isSecureConnectionAllowed: false,\n });\n // WHEN\n const builtContext = await task.run();\n // THEN\n expect(builtContext).toStrictEqual({\n web3Check: null,\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n clearSignContext: Nothing,\n domainHash:\n \"0xf033048cb2764f596bc4d98e089fa38bb84b4be3d5da2e77f9bfac0e4d6c68ca\",\n messageHash:\n \"0x1087495b5e10337738059920fe1de8216235299745e8c97e21b409009a4c362a\",\n });\n });\n\n it(\"Build context with no clear signing context\", async () => {\n // GIVEN\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n TEST_DATA,\n \"44'/60'/0'/0/0\",\n createAppConfig(false),\n getWeb3ChecksFactoryMock,\n );\n parserMock.parse.mockReturnValueOnce(\n Right({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n }),\n );\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n contextMouleMock.getTypedDataFilters.mockResolvedValueOnce({\n type: \"error\",\n error: new Error(\"no filter\"),\n });\n // WHEN\n const builtContext = await task.run();\n // THEN\n expect(builtContext).toStrictEqual({\n web3Check: null,\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n clearSignContext: Nothing,\n domainHash:\n \"0xf033048cb2764f596bc4d98e089fa38bb84b4be3d5da2e77f9bfac0e4d6c68ca\",\n messageHash:\n \"0x1087495b5e10337738059920fe1de8216235299745e8c97e21b409009a4c362a\",\n });\n });\n\n it(\"Build context with clear signing context\", async () => {\n // GIVEN\n const expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n TEST_DATA,\n \"44'/60'/0'/0/0\",\n createAppConfig(false),\n getWeb3ChecksFactoryMock,\n );\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => ({ web3Check: expectedWeb3Check }),\n });\n parserMock.parse.mockReturnValueOnce(\n Right({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n }),\n );\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n contextMouleMock.getTypedDataFilters.mockResolvedValueOnce(\n TEST_CLEAR_SIGN_CONTEXT,\n );\n // WHEN\n const builtContext = await task.run();\n // THEN\n expect(builtContext).toStrictEqual({\n web3Check: null,\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n clearSignContext: Just(TEST_CLEAR_SIGN_CONTEXT),\n domainHash:\n \"0xf033048cb2764f596bc4d98e089fa38bb84b4be3d5da2e77f9bfac0e4d6c68ca\",\n messageHash:\n \"0x1087495b5e10337738059920fe1de8216235299745e8c97e21b409009a4c362a\",\n });\n expect(parserMock.parse).toHaveBeenCalledWith(TEST_DATA);\n expect(contextMouleMock.getTypedDataFilters).toHaveBeenCalledWith({\n verifyingContract: \"0x000000000022d473030f116ddee9f6b43ac78ba3\",\n chainId: 137,\n version: \"v2\",\n schema: TEST_DATA[\"types\"],\n fieldsValues: [\n {\n path: \"details.amount\",\n value: Uint8Array.from([0x12]),\n },\n {\n path: \"details.expiration\",\n value: Uint8Array.from([0x13]),\n },\n ],\n });\n });\n\n it(\"Build context with clear signing context and web3Check\", async () => {\n // GIVEN\n const expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n TEST_DATA,\n \"44'/60'/0'/0/0\",\n createAppConfig(true),\n getWeb3ChecksFactoryMock,\n );\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => ({ web3Check: expectedWeb3Check }),\n });\n parserMock.parse.mockReturnValueOnce(\n Right({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n }),\n );\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n contextMouleMock.getTypedDataFilters.mockResolvedValueOnce(\n TEST_CLEAR_SIGN_CONTEXT,\n );\n // WHEN\n const builtContext = await task.run();\n // THEN\n expect(builtContext).toStrictEqual({\n web3Check: expectedWeb3Check,\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n clearSignContext: Just(TEST_CLEAR_SIGN_CONTEXT),\n domainHash:\n \"0xf033048cb2764f596bc4d98e089fa38bb84b4be3d5da2e77f9bfac0e4d6c68ca\",\n messageHash:\n \"0x1087495b5e10337738059920fe1de8216235299745e8c97e21b409009a4c362a\",\n });\n expect(getWeb3ChecksFactoryMock).toHaveBeenCalledWith(apiMock, {\n contextModule: contextMouleMock,\n derivationPath: \"44'/60'/0'/0/0\",\n data: TEST_DATA,\n });\n });\n\n it(\"Build context with clear signing context V1\", async () => {\n // GIVEN\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n TEST_DATA,\n \"44'/60'/0'/0/0\",\n createAppConfig(false),\n getWeb3ChecksFactoryMock,\n );\n parserMock.parse.mockReturnValueOnce(\n Right({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n }),\n );\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.11.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n contextMouleMock.getTypedDataFilters.mockResolvedValueOnce(\n TEST_CLEAR_SIGN_CONTEXT,\n );\n // WHEN\n await task.run();\n // THEN\n expect(contextMouleMock.getTypedDataFilters).toHaveBeenCalledWith({\n verifyingContract: \"0x000000000022d473030f116ddee9f6b43ac78ba3\",\n chainId: 137,\n version: \"v1\",\n schema: TEST_DATA[\"types\"],\n fieldsValues: [\n {\n path: \"details.amount\",\n value: Uint8Array.from([0x12]),\n },\n {\n path: \"details.expiration\",\n value: Uint8Array.from([0x13]),\n },\n ],\n });\n });\n\n it(\"Should throw error if no primary type\", async () => {\n // GIVEN\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n {\n ...TEST_DATA,\n primaryType: \"\",\n },\n \"44'/60'/0'/0/0\",\n createAppConfig(false),\n getWeb3ChecksFactoryMock,\n );\n parserMock.parse.mockReturnValueOnce(\n Right({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n }),\n );\n // WHEN\n try {\n await task.run();\n } catch (e) {\n // THEN\n expect(e).toBeInstanceOf(Error);\n // @ts-expect-error\n expect(e.message).toBe('Primary type \"\" is not defined in the types.');\n }\n });\n\n it(\"Should throw an error if parsing fails\", async () => {\n // GIVEN\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n TEST_DATA,\n \"44'/60'/0'/0/0\",\n createAppConfig(false),\n getWeb3ChecksFactoryMock,\n );\n parserMock.parse.mockReturnValueOnce(Left(new Error(\"Parsing error\")));\n // WHEN\n try {\n await task.run();\n } catch (e) {\n // THEN\n expect(e).toBeInstanceOf(Error);\n // @ts-expect-error\n expect(e.message).toBe(\"Parsing error\");\n }\n });\n});\n"],
5
- "mappings": "aAKA,IAAAA,EAIO,2CACPC,EAA2C,qBAG3CC,EAAgD,6EAChDC,EAKO,4CAEPC,EAAuC,oCAEvC,SAAS,yBAA0B,IAAM,CACvC,MAAMC,KAAU,mCAAgC,EAC1CC,EAAmB,CACvB,WAAY,GAAG,GAAG,EAClB,YAAa,GAAG,GAAG,EACnB,oBAAqB,GAAG,GAAG,EAC3B,cAAe,GAAG,GAAG,CACvB,EACMC,EAAa,CACjB,MAAO,GA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e,CACxC,CACF,CAAC,CACH,CAAC",
4
+ "sourcesContent": ["import type {\n ClearSignContextSuccess,\n ClearSignContextType,\n TypedDataClearSignContextSuccess,\n} from \"@ledgerhq/context-module\";\nimport {\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n} from \"@ledgerhq/device-management-kit\";\nimport { Just, Left, Nothing, Right } from \"purify-ts\";\n\nimport type { GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\nimport {\n PrimitiveType,\n StructType,\n TypedDataValueField,\n TypedDataValueRoot,\n} from \"@internal/typed-data/model/Types\";\n\nimport { BuildEIP712ContextTask } from \"./BuildEIP712ContextTask\";\n\ndescribe(\"BuildEIP712ContextTask\", () => {\n const apiMock = makeDeviceActionInternalApiMock();\n const contextMouleMock = {\n getContext: vi.fn(),\n getContexts: vi.fn(),\n getTypedDataFilters: vi.fn(),\n getWeb3Checks: vi.fn(),\n getSolanaContext: vi.fn(),\n };\n const parserMock = {\n parse: vi.fn(),\n };\n const getWeb3ChecksFactoryMock = vi.fn();\n\n function createAppConfig(\n web3ChecksEnabled: boolean,\n ): GetConfigCommandResponse {\n return {\n blindSigningEnabled: false,\n web3ChecksEnabled,\n web3ChecksOptIn: false,\n version: \"1.13.0\",\n };\n }\n\n const TEST_DATA = {\n domain: {\n name: \"Permit2\",\n chainId: 137,\n verifyingContract: \"0x000000000022d473030f116ddee9f6b43ac78ba3\",\n },\n primaryType: \"PermitSingle\",\n message: {\n details: {\n token: \"0x7ceb23fd6bc0add59e62ac25578270cff1b9f619\",\n amount: \"69420000000000000000\",\n expiration: \"1718184249\",\n nonce: \"0\",\n },\n spender: \"0xec7be89e9d109e7e3fec59c222cf297125fefda2\",\n sigDeadline: \"1715594049\",\n },\n types: {\n PermitSingle: [\n {\n name: \"details\",\n type: \"PermitDetails\",\n },\n {\n name: \"spender\",\n type: \"address\",\n },\n {\n name: \"sigDeadline\",\n type: \"uint256\",\n },\n ],\n PermitDetails: [\n { name: \"token\", type: \"address\" },\n { name: \"amount\", type: \"uint\" },\n { name: \"expiration\", type: \"uint\" },\n { name: \"nonce\", type: \"uint\" },\n ],\n },\n };\n\n const TEST_TYPES = {\n PermitSingle: {\n details: new StructType(\"PermitDetails\"),\n spender: new PrimitiveType(\"address\", \"address\", Nothing),\n sigDeadline: new PrimitiveType(\"uint256\", \"uint\", Just(32)),\n },\n PermitDetails: {\n token: new PrimitiveType(\"address\", \"address\", Nothing),\n amount: new PrimitiveType(\"uint160\", \"uint\", Just(20)),\n expiration: new PrimitiveType(\"uint48\", \"uint\", Just(6)),\n nonce: new PrimitiveType(\"uint48\", \"uint\", Just(6)),\n },\n };\n const TEST_DOMAIN_VALUES = [\n {\n path: \"\",\n type: \"\",\n value: new TypedDataValueRoot(\"EIP712Domain\"),\n },\n {\n path: \"chainId\",\n type: \"uint256\",\n value: new TypedDataValueField(Uint8Array.from([137])),\n },\n ];\n const TEST_MESSAGE_VALUES = [\n {\n path: \"\",\n type: \"\",\n value: new TypedDataValueRoot(\"PermitSingle\"),\n },\n {\n path: \"details.amount\",\n type: \"uint160\",\n value: new TypedDataValueField(Uint8Array.from([0x12])),\n },\n {\n path: \"details.expiration\",\n type: \"uint48\",\n value: new TypedDataValueField(Uint8Array.from([0x13])),\n },\n ];\n const TEST_CLEAR_SIGN_CONTEXT: TypedDataClearSignContextSuccess = {\n type: \"success\",\n messageInfo: {\n displayName: \"Permit2\",\n filtersCount: 1,\n signature:\n \"3045022100e3c597d13d28a87a88b0239404c668373cf5063362f2a81d09eed4582941dfe802207669aabb504fd5b95b2734057f6b8bbf51f14a69a5f9bdf658a5952cefbf44d3\",\n },\n trustedNamesAddresses: {},\n tokens: {},\n filters: {\n \"details.amount\": {\n displayName: \"Amount allowance\",\n path: \"details.amount\",\n signature:\n \"304402201a46e6b4ef89eaf9fcf4945d053bfc5616a826400fd758312fbbe976bafc07ec022025a9b408722baf983ee053f90179c75b0c55bb0668f437d55493e36069bbd5a3\",\n tokenIndex: 255,\n type: \"amount\",\n },\n },\n };\n\n beforeEach(() => {\n vi.resetAllMocks();\n getWeb3ChecksFactoryMock.mockReturnValue({\n run: async () => ({ web3Check: null }),\n });\n });\n\n it(\"Build context with clear signing context not supported by the device\", async () => {\n // GIVEN\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n TEST_DATA,\n \"44'/60'/0'/0/0\",\n createAppConfig(false),\n getWeb3ChecksFactoryMock,\n );\n parserMock.parse.mockReturnValueOnce(\n Right({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n }),\n );\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.11.0\" },\n deviceModelId: DeviceModelId.NANO_S,\n isSecureConnectionAllowed: false,\n });\n // WHEN\n const builtContext = await task.run();\n // THEN\n expect(builtContext).toStrictEqual({\n web3Check: null,\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n clearSignContext: Nothing,\n });\n });\n\n it(\"Build context with no clear signing context\", async () => {\n // GIVEN\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n TEST_DATA,\n \"44'/60'/0'/0/0\",\n createAppConfig(false),\n getWeb3ChecksFactoryMock,\n );\n parserMock.parse.mockReturnValueOnce(\n Right({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n }),\n );\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n contextMouleMock.getTypedDataFilters.mockResolvedValueOnce({\n type: \"error\",\n error: new Error(\"no filter\"),\n });\n // WHEN\n const builtContext = await task.run();\n // THEN\n expect(builtContext).toStrictEqual({\n web3Check: null,\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n clearSignContext: Nothing,\n });\n });\n\n it(\"Build context with clear signing context\", async () => {\n // GIVEN\n const expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n TEST_DATA,\n \"44'/60'/0'/0/0\",\n createAppConfig(false),\n getWeb3ChecksFactoryMock,\n );\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => ({ web3Check: expectedWeb3Check }),\n });\n parserMock.parse.mockReturnValueOnce(\n Right({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n }),\n );\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n contextMouleMock.getTypedDataFilters.mockResolvedValueOnce(\n TEST_CLEAR_SIGN_CONTEXT,\n );\n // WHEN\n const builtContext = await task.run();\n // THEN\n expect(builtContext).toStrictEqual({\n web3Check: null,\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n clearSignContext: Just(TEST_CLEAR_SIGN_CONTEXT),\n });\n expect(parserMock.parse).toHaveBeenCalledWith(TEST_DATA);\n expect(contextMouleMock.getTypedDataFilters).toHaveBeenCalledWith({\n verifyingContract: \"0x000000000022d473030f116ddee9f6b43ac78ba3\",\n chainId: 137,\n version: \"v2\",\n schema: TEST_DATA[\"types\"],\n fieldsValues: [\n {\n path: \"details.amount\",\n value: Uint8Array.from([0x12]),\n },\n {\n path: \"details.expiration\",\n value: Uint8Array.from([0x13]),\n },\n ],\n });\n });\n\n it(\"Build context with clear signing context and web3Check\", async () => {\n // GIVEN\n const expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n TEST_DATA,\n \"44'/60'/0'/0/0\",\n createAppConfig(true),\n getWeb3ChecksFactoryMock,\n );\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => ({ web3Check: expectedWeb3Check }),\n });\n parserMock.parse.mockReturnValueOnce(\n Right({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n }),\n );\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n contextMouleMock.getTypedDataFilters.mockResolvedValueOnce(\n TEST_CLEAR_SIGN_CONTEXT,\n );\n // WHEN\n const builtContext = await task.run();\n // THEN\n expect(builtContext).toStrictEqual({\n web3Check: expectedWeb3Check,\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n clearSignContext: Just(TEST_CLEAR_SIGN_CONTEXT),\n });\n expect(getWeb3ChecksFactoryMock).toHaveBeenCalledWith(apiMock, {\n contextModule: contextMouleMock,\n derivationPath: \"44'/60'/0'/0/0\",\n data: TEST_DATA,\n });\n });\n\n it(\"Build context with clear signing context V1\", async () => {\n // GIVEN\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n TEST_DATA,\n \"44'/60'/0'/0/0\",\n createAppConfig(false),\n getWeb3ChecksFactoryMock,\n );\n parserMock.parse.mockReturnValueOnce(\n Right({\n types: TEST_TYPES,\n domain: TEST_DOMAIN_VALUES,\n message: TEST_MESSAGE_VALUES,\n }),\n );\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.11.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n contextMouleMock.getTypedDataFilters.mockResolvedValueOnce(\n TEST_CLEAR_SIGN_CONTEXT,\n );\n // WHEN\n await task.run();\n // THEN\n expect(contextMouleMock.getTypedDataFilters).toHaveBeenCalledWith({\n verifyingContract: \"0x000000000022d473030f116ddee9f6b43ac78ba3\",\n chainId: 137,\n version: \"v1\",\n schema: TEST_DATA[\"types\"],\n fieldsValues: [\n {\n path: \"details.amount\",\n value: Uint8Array.from([0x12]),\n },\n {\n path: \"details.expiration\",\n value: Uint8Array.from([0x13]),\n },\n ],\n });\n });\n\n it(\"Should throw an error if parsing fails\", async () => {\n // GIVEN\n const task = new BuildEIP712ContextTask(\n apiMock,\n contextMouleMock,\n parserMock,\n TEST_DATA,\n \"44'/60'/0'/0/0\",\n createAppConfig(false),\n getWeb3ChecksFactoryMock,\n );\n parserMock.parse.mockReturnValueOnce(Left(new Error(\"Parsing error\")));\n // WHEN\n try {\n await task.run();\n } catch (e) {\n // THEN\n expect(e).toBeInstanceOf(Error);\n // @ts-expect-error\n expect(e.message).toBe(\"Parsing error\");\n }\n });\n});\n"],
5
+ "mappings": "aAKA,IAAAA,EAIO,2CACPC,EAA2C,qBAG3CC,EAAgD,6EAChDC,EAKO,4CAEPC,EAAuC,oCAEvC,SAAS,yBAA0B,IAAM,CACvC,MAAMC,KAAU,mCAAgC,EAC1CC,EAA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gB,EAAK,EACrBD,CACF,EACAD,EAAW,MAAM,uBACf,SAAM,CACJ,MAAOK,EACP,OAAQC,EACR,QAASC,CACX,CAAC,CACH,EACAT,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkB,yBAAuB,0BACzC,aAAc,eAAa,UAC3B,cAAe,CAAC,EAChB,WAAY,CAAE,KAAM,WAAY,QAAS,QAAS,EAClD,cAAe,gBAAc,KAC7B,0BAA2B,EAC7B,CAAC,EACDC,EAAiB,oBAAoB,sBACnCS,CACF,EAEA,MAAMC,EAAK,IAAI,EAEf,OAAOV,EAAiB,mBAAmB,EAAE,qBAAqB,CAChE,kBAAmB,6CACnB,QAAS,IACT,QAAS,KACT,OAAQK,EAAU,MAClB,aAAc,CACZ,CACE,KAAM,iBACN,MAAO,WAAW,KAAK,CAAC,EAAI,CAAC,CAC/B,EACA,CACE,KAAM,qBACN,MAAO,WAAW,KAAK,CAAC,EAAI,CAAC,CAC/B,CACF,CACF,CAAC,CACH,CAAC,EAED,GAAG,yCAA0C,SAAY,CAEvD,MAAMK,EAAO,IAAI,yBACfX,EACAC,EACAC,EACAI,EACA,iBACAF,EAAgB,EAAK,EACrBD,CACF,EACAD,EAAW,MAAM,uBAAoB,QAAK,IAAI,MAAM,eAAe,CAAC,CAAC,EAErE,GAAI,CACF,MAAMS,EAAK,IAAI,CACjB,OAASG,EAAG,CAEV,OAAOA,CAAC,EAAE,eAAe,KAAK,EAE9B,OAAOA,EAAE,OAAO,EAAE,KAAK,eAAe,CACxC,CACF,CAAC,CACH,CAAC",
6
6
  "names": ["import_device_management_kit", "import_purify_ts", "import_makeInternalApi", "import_Types", "import_BuildEIP712ContextTask", "apiMock", "contextMouleMock", "parserMock", "getWeb3ChecksFactoryMock", "createAppConfig", "web3ChecksEnabled", "TEST_DATA", "TEST_TYPES", "TEST_DOMAIN_VALUES", "TEST_MESSAGE_VALUES", "TEST_CLEAR_SIGN_CONTEXT", "task", "builtContext", "expectedWeb3Check", "e"]
7
7
  }
@@ -0,0 +1,2 @@
1
+ "use strict";var x=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var y=(s,e)=>{for(var r in e)x(s,r,{get:e[r],enumerable:!0})},h=(s,e,r,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of f(e))!g.call(s,t)&&t!==r&&x(s,t,{get:()=>e[t],enumerable:!(a=d(e,t))||a.enumerable});return s};var S=s=>h(x({},"__esModule",{value:!0}),s);var b={};y(b,{BuildSubContextTask:()=>T});module.exports=S(b);var n=require("@ledgerhq/context-module"),i=require("@ledgerhq/device-management-kit"),p=require("../../app-binder/command/GetChallengeCommand");class T{constructor(e,r){this.api=e;this.args=r}run(){const e=this.args.context;if(e.type===n.ClearSignContextType.TRANSACTION_INFO||e.type===n.ClearSignContextType.ENUM||e.type===n.ClearSignContextType.WEB3_CHECK||e.type===n.ClearSignContextType.PLUGIN||e.type===n.ClearSignContextType.EXTERNAL_PLUGIN)return{subcontextCallbacks:[]};if(e.reference!==void 0&&"value"in e.reference&&e.reference.value!==void 0){const r={type:e.reference.type,chainId:this.args.subset.chainId,address:e.reference.value};return{subcontextCallbacks:[()=>this.args.contextModule.getContext(r)]}}if(e.reference!==void 0&&e.reference.valuePath!==void 0){const r=this.args.transactionParser.extractValue(this.args.subset,e.reference.valuePath);if(r.isRight()){const a=[];for(const t of r.extract()){if(e.reference.type===n.ClearSignContextType.ENUM){const o=e.reference,c=t[t.length-1];if(!c)continue;const C=this.args.contextOptional.filter(l=>l.type===n.ClearSignContextType.ENUM).find(l=>l.value===c&&l.id===o.id);C&&a.push(()=>Promise.resolve(C))}if(e.reference.type===n.ClearSignContextType.TOKEN||e.reference.type===n.ClearSignContextType.NFT){const o=e.reference,c=(0,i.bufferToHexaString)(t.slice(Math.max(0,t.length-20)));a.push(()=>this.args.contextModule.getContext({type:o.type,chainId:this.args.subset.chainId,address:c}))}if(e.reference.type===n.ClearSignContextType.TRUSTED_NAME){const o=e.reference;a.push(async()=>{const c=(0,i.bufferToHexaString)(t.slice(Math.max(0,t.length-20))),u=await this.api.sendCommand(new p.GetChallengeCommand);return(0,i.isSuccessCommandResult)(u)?await this.args.contextModule.getContext({type:o.type,chainId:this.args.subset.chainId,address:c,challenge:u.data.challenge,types:o.types,sources:o.sources}):{type:n.ClearSignContextType.ERROR,error:new Error("Failed to get challenge")}})}}return{subcontextCallbacks:a}}}return{subcontextCallbacks:[]}}}0&&(module.exports={BuildSubContextTask});
2
+ //# sourceMappingURL=BuildSubContextTask.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/internal/app-binder/task/BuildSubContextTask.ts"],
4
+ "sourcesContent": ["import {\n type ClearSignContext,\n type ClearSignContextReference,\n type ClearSignContextSuccess,\n ClearSignContextType,\n type ContextModule,\n type TransactionFieldContext,\n type TransactionSubset,\n} from \"@ledgerhq/context-module\";\nimport {\n bufferToHexaString,\n type InternalApi,\n isSuccessCommandResult,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { GetChallengeCommand } from \"@internal/app-binder/command/GetChallengeCommand\";\nimport { type TransactionParserService } from \"@internal/transaction/service/parser/TransactionParserService\";\n\nexport type BuildSubContextTaskArgs = {\n readonly context: ClearSignContextSuccess;\n readonly contextOptional: ClearSignContextSuccess[];\n readonly transactionParser: TransactionParserService;\n readonly subset: TransactionSubset;\n readonly contextModule: ContextModule;\n};\n\nexport type BuildSubContextTaskResult = {\n subcontextCallbacks: (() => Promise<ClearSignContext>)[];\n};\n\nexport class BuildSubContextTask {\n constructor(\n private readonly api: InternalApi,\n private readonly args: BuildSubContextTaskArgs,\n ) {}\n\n run(): BuildSubContextTaskResult {\n const context = this.args.context;\n\n if (\n context.type === ClearSignContextType.TRANSACTION_INFO ||\n context.type === ClearSignContextType.ENUM ||\n context.type === ClearSignContextType.WEB3_CHECK ||\n context.type === ClearSignContextType.PLUGIN ||\n context.type === ClearSignContextType.EXTERNAL_PLUGIN\n ) {\n return {\n subcontextCallbacks: [],\n };\n }\n\n // if the reference is a string, it means it is a direct address\n // and we don't need to extract the value from the transaction\n // as it is already provided in the reference\n if (\n context.reference !== undefined &&\n \"value\" in context.reference &&\n context.reference.value !== undefined\n ) {\n const transactionFieldContext: TransactionFieldContext = {\n type: context.reference.type,\n chainId: this.args.subset.chainId,\n address: context.reference.value,\n };\n\n return {\n subcontextCallbacks: [\n () => this.args.contextModule.getContext(transactionFieldContext),\n ],\n };\n }\n\n // if the reference is a path, it means we need to extract the value\n // from the transaction and provide it to the device\n if (\n context.reference !== undefined &&\n context.reference.valuePath !== undefined\n ) {\n // iterate on each reference and provide the context\n const referenceValues = this.args.transactionParser.extractValue(\n this.args.subset,\n context.reference.valuePath,\n );\n\n if (referenceValues.isRight()) {\n const subcontextCallbacks: (() => Promise<ClearSignContext>)[] = [];\n\n for (const value of referenceValues.extract()) {\n if (context.reference.type === ClearSignContextType.ENUM) {\n const reference: ClearSignContextReference<ClearSignContextType.ENUM> =\n context.reference;\n const enumValue = value[value.length - 1];\n if (!enumValue) continue;\n\n const enumsContext = this.args.contextOptional.filter(\n (c) => c.type === ClearSignContextType.ENUM,\n );\n\n const subcontext = enumsContext.find(\n (enumContext) =>\n enumContext.value === enumValue &&\n enumContext.id === reference.id,\n );\n\n if (subcontext) {\n subcontextCallbacks.push(() => Promise.resolve(subcontext));\n }\n }\n\n if (\n context.reference.type === ClearSignContextType.TOKEN ||\n context.reference.type === ClearSignContextType.NFT\n ) {\n const reference: ClearSignContextReference<\n ClearSignContextType.TOKEN | ClearSignContextType.NFT\n > = context.reference;\n const address = bufferToHexaString(\n value.slice(Math.max(0, value.length - 20)),\n );\n\n subcontextCallbacks.push(() =>\n this.args.contextModule.getContext({\n type: reference.type,\n chainId: this.args.subset.chainId,\n address,\n }),\n );\n }\n\n if (context.reference.type === ClearSignContextType.TRUSTED_NAME) {\n const reference: ClearSignContextReference<ClearSignContextType.TRUSTED_NAME> =\n context.reference;\n subcontextCallbacks.push(async () => {\n const address = bufferToHexaString(\n value.slice(Math.max(0, value.length - 20)),\n );\n\n const getChallengeResult = await this.api.sendCommand(\n new GetChallengeCommand(),\n );\n if (!isSuccessCommandResult(getChallengeResult)) {\n // TODO: we need to return an error here\n return {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Failed to get challenge\"),\n };\n }\n\n const subcontext = await this.args.contextModule.getContext({\n type: reference.type,\n chainId: this.args.subset.chainId,\n address,\n challenge: getChallengeResult.data.challenge,\n types: reference.types,\n sources: reference.sources,\n });\n\n return subcontext;\n });\n }\n }\n\n return {\n subcontextCallbacks,\n };\n }\n }\n\n return {\n subcontextCallbacks: [],\n };\n }\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,yBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAQO,oCACPC,EAIO,2CAEPC,EAAoC,4DAe7B,MAAMJ,CAAoB,CAC/B,YACmBK,EACAC,EACjB,CAFiB,SAAAD,EACA,UAAAC,CAChB,CAEH,KAAiC,CAC/B,MAAMC,EAAU,KAAK,KAAK,QAE1B,GACEA,EAAQ,OAAS,uBAAqB,kBACtCA,EAAQ,OAAS,uBAAqB,MACtCA,EAAQ,OAAS,uBAAqB,YACtCA,EAAQ,OAAS,uBAAqB,QACtCA,EAAQ,OAAS,uBAAqB,gBAEtC,MAAO,CACL,oBAAqB,CAAC,CACxB,EAMF,GACEA,EAAQ,YAAc,QACtB,UAAWA,EAAQ,WACnBA,EAAQ,UAAU,QAAU,OAC5B,CACA,MAAMC,EAAmD,CACvD,KAAMD,EAAQ,UAAU,KACxB,QAAS,KAAK,KAAK,OAAO,QAC1B,QAASA,EAAQ,UAAU,KAC7B,EAEA,MAAO,CACL,oBAAqB,CACnB,IAAM,KAAK,KAAK,cAAc,WAAWC,CAAuB,CAClE,CACF,CACF,CAIA,GACED,EAAQ,YAAc,QACtBA,EAAQ,UAAU,YAAc,OAChC,CAEA,MAAME,EAAkB,KAAK,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UACnC,MAAON,EAAU,MACjB,QAASA,EAAU,OACrB,CAAC,EAbQ,CACL,KAAM,uBAAqB,MAC3B,MAAO,IAAI,MAAM,yBAAyB,CAC5C,CAaJ,CAAC,CACH,CACF,CAEA,MAAO,CACL,oBAAAF,CACF,CACF,CACF,CAEA,MAAO,CACL,oBAAqB,CAAC,CACxB,CACF,CACF",
6
+ "names": ["BuildSubContextTask_exports", "__export", "BuildSubContextTask", "__toCommonJS", "import_context_module", "import_device_management_kit", "import_GetChallengeCommand", "api", "args", "context", "transactionFieldContext", "referenceValues", "subcontextCallbacks", "value", "reference", "enumValue", "subcontext", "c", "enumContext", "address", "getChallengeResult"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var e=require("@ledgerhq/context-module"),C=require("@ledgerhq/device-management-kit"),d=require("purify-ts"),h=require("../../app-binder/command/GetChallengeCommand"),g=require("../../app-binder/device-action/__test-utils__/makeInternalApi"),x=require("./BuildSubContextTask");describe("BuildSubContextTask",()=>{const r={getContext:vi.fn()},p={extractValue:vi.fn()},s=(0,g.makeDeviceActionInternalApiMock)();let l;beforeEach(()=>{vi.resetAllMocks(),l={context:{type:e.ClearSignContextType.TRANSACTION_INFO,payload:"test payload"},contextOptional:[],transactionParser:p,subset:{chainId:1,data:"0x",selector:"0x",to:"0x",value:BigInt(0)},contextModule:r}}),describe("when context type is a simple type",()=>{const n=[e.ClearSignContextType.TRANSACTION_INFO,e.ClearSignContextType.WEB3_CHECK,e.ClearSignContextType.PLUGIN,e.ClearSignContextType.EXTERNAL_PLUGIN,e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION];it.each(n)("should return context with empty subcontextCallbacks for %s",t=>{const c={...l,context:{type:t,payload:"test payload"}},o=new x.BuildSubContextTask(s,c).run();expect(o.subcontextCallbacks).toHaveLength(0)})}),describe("when context has a direct value reference",()=>{it("should create a callback to get context with the direct value",async()=>{const n={type:e.ClearSignContextType.TOKEN,payload:"test payload",reference:{type:e.ClearSignContextType.TOKEN,value:"0x1234567890123456789012345678901234567890"}},t={...l,context:n},a={type:e.ClearSignContextType.TOKEN,chainId:1,address:"0x1234567890123456789012345678901234567890"},c=new x.BuildSubContextTask(s,t).run();expect(c.subcontextCallbacks).toHaveLength(1);const o=c.subcontextCallbacks[0];await o(),expect(r.getContext).toHaveBeenCalledWith(a)}),it("should handle undefined value in reference",()=>{const n={type:e.ClearSignContextType.TOKEN,payload:"test payload",reference:void 0},t={...l,context:n},a=new x.BuildSubContextTask(s,t).run();expect(a.subcontextCallbacks).toHaveLength(0)})}),describe("when context has a valuePath reference",()=>{beforeEach(()=>{s.sendCommand.mockResolvedValue((0,C.CommandResultFactory)({data:{challenge:"test-challenge"}}))}),describe("when extractValue returns Left (error)",()=>{it("should return context with empty subcontextCallbacks",()=>{const n={type:e.ClearSignContextType.TOKEN,payload:"test payload",reference:{type:e.ClearSignContextType.TOKEN,valuePath:[{type:"SLICE",start:0,end:20}]}},t={...l,context:n};p.extractValue.mockReturnValue((0,d.Left)(new Error("Extraction failed")));const a=new x.BuildSubContextTask(s,t).run();expect(a.subcontextCallbacks).toHaveLength(0)})}),describe("when extractValue returns Right with values",()=>{describe("for ENUM type",()=>{it("should create callbacks for matching enum contexts",async()=>{const n={type:e.ClearSignContextType.TOKEN,payload:"test payload",reference:{type:e.ClearSignContextType.ENUM,id:1,valuePath:[{type:"TUPLE",offset:0}]}},t={type:e.ClearSignContextType.ENUM,id:1,value:1,payload:"enum context 1"},a={type:e.ClearSignContextType.ENUM,id:1,value:2,payload:"enum context 2"},c={type:e.ClearSignContextType.ENUM,id:2,value:2,payload:"enum context 3"},o={...l,context:n,contextOptional:[t,a,c]},u=[new Uint8Array([1,2])];p.extractValue.mockReturnValue((0,d.Right)(u));const i=new x.BuildSubContextTask(s,o).run();expect(i.subcontextCallbacks).toHaveLength(1);const y=i.subcontextCallbacks[0],b=await y();expect(b).toEqual(a)}),it("should create callbacks for matching enum contexts with two values",async()=>{const n={type:e.ClearSignContextType.TOKEN,payload:"test payload",reference:{type:e.ClearSignContextType.ENUM,id:1,valuePath:[{type:"TUPLE",offset:0}]}},t={type:e.ClearSignContextType.ENUM,id:1,value:1,payload:"enum context 1"},a={type:e.ClearSignContextType.ENUM,id:1,value:2,payload:"enum context 2"},c={type:e.ClearSignContextType.ENUM,id:2,value:2,payload:"enum context 3"},o={...l,context:n,contextOptional:[t,a,c]},u=[new Uint8Array([1,2]),new Uint8Array([3,2,1])];p.extractValue.mockReturnValue((0,d.Right)(u));const i=new x.BuildSubContextTask(s,o).run();expect(i.subcontextCallbacks).toHaveLength(2);const y=i.subcontextCallbacks[0],b=i.subcontextCallbacks[1],k=await y(),E=await b();expect(k).toEqual(a),expect(E).toEqual(t)}),it("should skip when enum value is undefined",()=>{const n={type:e.ClearSignContextType.TOKEN,payload:"test payload",reference:{type:e.ClearSignContextType.ENUM,id:1,valuePath:[{type:"TUPLE",offset:0}]}},t={...l,context:n},a=[new Uint8Array([])];p.extractValue.mockReturnValue((0,d.Right)(a));const c=new x.BuildSubContextTask(s,t).run();expect(c.subcontextCallbacks).toHaveLength(0)}),it("should skip when no matching enum context found",()=>{const n={type:e.ClearSignContextType.NFT,payload:"test payload",reference:{type:e.ClearSignContextType.ENUM,id:1,valuePath:[{type:"TUPLE",offset:0}]}},t={type:e.ClearSignContextType.ENUM,id:2,value:2,payload:"enum context"},a={...l,context:n,contextOptional:[t]},c=[new Uint8Array([1,2])];p.extractValue.mockReturnValue((0,d.Right)(c));const o=new x.BuildSubContextTask(s,a).run();expect(o.subcontextCallbacks).toHaveLength(0)})}),describe("for TOKEN type",()=>{it("should create callbacks to get token context",async()=>{const n={type:e.ClearSignContextType.TOKEN,payload:"test payload",reference:{type:e.ClearSignContextType.TOKEN,valuePath:[{type:"TUPLE",offset:0}]}},t={...l,context:n},a=[new Uint8Array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22])];p.extractValue.mockReturnValue((0,d.Right)(a)),r.getContext.mockResolvedValue({type:e.ClearSignContextType.TOKEN,payload:"token result"});const c=new x.BuildSubContextTask(s,t).run();expect(c.subcontextCallbacks).toHaveLength(1);const o=c.subcontextCallbacks[0],u=await o();expect(u).toEqual({type:e.ClearSignContextType.TOKEN,payload:"token result"}),expect(r.getContext).toHaveBeenCalledWith({type:e.ClearSignContextType.TOKEN,chainId:1,address:"0x030405060708090a0b0c0d0e0f10111213141516"})})}),describe("for NFT type",()=>{it("should create callbacks to get NFT context",async()=>{const n={type:e.ClearSignContextType.NFT,payload:"test payload",reference:{type:e.ClearSignContextType.NFT,valuePath:[{type:"TUPLE",offset:0}]}},t={...l,context:n},a=[new Uint8Array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22])];p.extractValue.mockReturnValue((0,d.Right)(a)),r.getContext.mockResolvedValue({type:e.ClearSignContextType.NFT,payload:"nft result"});const c=new x.BuildSubContextTask(s,t).run();expect(c.subcontextCallbacks).toHaveLength(1);const o=c.subcontextCallbacks[0],u=await o();expect(u).toEqual({type:e.ClearSignContextType.NFT,payload:"nft result"}),expect(r.getContext).toHaveBeenCalledWith({type:e.ClearSignContextType.NFT,chainId:1,address:"0x030405060708090a0b0c0d0e0f10111213141516"})})}),describe("for TRUSTED_NAME type",()=>{it("should create callbacks to get trusted name context with challenge",async()=>{const n={type:e.ClearSignContextType.TRUSTED_NAME,payload:"test payload",reference:{type:e.ClearSignContextType.TRUSTED_NAME,valuePath:[{type:"TUPLE",offset:0}],types:["type1","type2"],sources:["source1","source2"]}},t={...l,context:n},a=[new Uint8Array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22])];p.extractValue.mockReturnValue((0,d.Right)(a)),r.getContext.mockResolvedValue({type:e.ClearSignContextType.TRUSTED_NAME,payload:"trusted name result"});const c=new x.BuildSubContextTask(s,t).run();expect(c.subcontextCallbacks).toHaveLength(1);const o=c.subcontextCallbacks[0],u=await o();expect(u).toEqual({type:e.ClearSignContextType.TRUSTED_NAME,payload:"trusted name result"}),expect(s.sendCommand).toHaveBeenCalledWith(expect.any(h.GetChallengeCommand)),expect(r.getContext).toHaveBeenCalledWith({type:e.ClearSignContextType.TRUSTED_NAME,chainId:1,address:"0x030405060708090a0b0c0d0e0f10111213141516",challenge:"test-challenge",types:["type1","type2"],sources:["source1","source2"]})}),it("should handle challenge command failure",async()=>{const n={type:e.ClearSignContextType.TRUSTED_NAME,payload:"test payload",reference:{type:e.ClearSignContextType.TRUSTED_NAME,valuePath:[{type:"TUPLE",offset:0}],types:["type1"],sources:["source1"]}},t={...l,context:n},a=[new Uint8Array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22])];p.extractValue.mockReturnValue((0,d.Right)(a));const c=new C.UnknownDeviceExchangeError("Failed");s.sendCommand.mockResolvedValueOnce((0,C.CommandResultFactory)({error:c}));const o=new x.BuildSubContextTask(s,t).run();expect(o.subcontextCallbacks).toHaveLength(1);const u=o.subcontextCallbacks[0],i=await u();expect(i).toEqual({error:new Error("Failed to get challenge"),type:e.ClearSignContextType.ERROR})})}),describe("for multiple values",()=>{it("should create callbacks for each extracted value",async()=>{const n={type:e.ClearSignContextType.TOKEN,payload:"test payload",reference:{type:e.ClearSignContextType.TOKEN,valuePath:[{type:"TUPLE",offset:0}]}},t={...l,context:n},a=[new Uint8Array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22]),new Uint8Array([33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54])];p.extractValue.mockReturnValue((0,d.Right)(a)),r.getContext.mockResolvedValueOnce({type:e.ClearSignContextType.TOKEN,payload:"token result 1"}),r.getContext.mockResolvedValueOnce({type:e.ClearSignContextType.TOKEN,payload:"token result 2"});const c=new x.BuildSubContextTask(s,t).run();expect(c.subcontextCallbacks).toHaveLength(2);const o=c.subcontextCallbacks[0],u=c.subcontextCallbacks[1],i=await o(),y=await u();expect(i).toEqual({type:e.ClearSignContextType.TOKEN,payload:"token result 1"}),expect(y).toEqual({type:e.ClearSignContextType.TOKEN,payload:"token result 2"}),expect(r.getContext).toHaveBeenCalledTimes(2),expect(r.getContext).toHaveBeenNthCalledWith(1,{type:e.ClearSignContextType.TOKEN,chainId:1,address:"0x030405060708090a0b0c0d0e0f10111213141516"}),expect(r.getContext).toHaveBeenNthCalledWith(2,{type:e.ClearSignContextType.TOKEN,chainId:1,address:"0x232425262728292a2b2c2d2e2f30313233343536"})})})})}),describe("when context has no reference",()=>{it("should return context with empty subcontextCallbacks",()=>{const n={type:e.ClearSignContextType.TOKEN,payload:"test payload"},t={...l,context:n},a=new x.BuildSubContextTask(s,t).run();expect(a.subcontextCallbacks).toHaveLength(0)})}),describe("when context has reference but no valuePath",()=>{it("should return context with empty subcontextCallbacks",()=>{const n={type:e.ClearSignContextType.TOKEN,payload:"test payload",reference:{type:e.ClearSignContextType.TOKEN}},t={...l,context:n},a=new x.BuildSubContextTask(s,t).run();expect(a.subcontextCallbacks).toHaveLength(0)})}),describe("edge cases",()=>{it("should handle value array shorter than 20 bytes for address extraction",async()=>{const n={type:e.ClearSignContextType.TOKEN,payload:"test payload",reference:{type:e.ClearSignContextType.TOKEN,valuePath:[{type:"TUPLE",offset:0}]}},t={...l,context:n},a=[new Uint8Array([1,2,3])];p.extractValue.mockReturnValue((0,d.Right)(a)),r.getContext.mockResolvedValue({type:e.ClearSignContextType.ERROR,message:"Invalid address"});const c=new x.BuildSubContextTask(s,t).run();expect(c.subcontextCallbacks).toHaveLength(1);const o=c.subcontextCallbacks[0],u=await o();expect(u).toEqual({type:e.ClearSignContextType.ERROR,message:"Invalid address"}),expect(r.getContext).toHaveBeenCalledWith({type:e.ClearSignContextType.TOKEN,chainId:1,address:"0x010203"})}),it("should handle empty value array",async()=>{const n={type:e.ClearSignContextType.TOKEN,payload:"test payload",reference:{type:e.ClearSignContextType.TOKEN,valuePath:[{type:"TUPLE",offset:0}]}},t={...l,context:n},a=[new Uint8Array([])];p.extractValue.mockReturnValue((0,d.Right)(a)),r.getContext.mockResolvedValue({type:e.ClearSignContextType.TOKEN,payload:"token result"});const c=new x.BuildSubContextTask(s,t).run();expect(c.subcontextCallbacks).toHaveLength(1);const o=c.subcontextCallbacks[0],u=await o();expect(u).toEqual({type:e.ClearSignContextType.TOKEN,payload:"token result"}),expect(r.getContext).toHaveBeenCalledWith({type:e.ClearSignContextType.TOKEN,chainId:1,address:"0x"})})})});
2
+ //# sourceMappingURL=BuildSubContextTask.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/internal/app-binder/task/BuildSubContextTask.test.ts"],
4
+ "sourcesContent": ["import {\n type ClearSignContextReference,\n type ClearSignContextSuccess,\n ClearSignContextType,\n type ContextModule,\n type TransactionFieldContext,\n} from \"@ledgerhq/context-module\";\nimport {\n CommandResultFactory,\n UnknownDeviceExchangeError,\n} from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { GetChallengeCommand } from \"@internal/app-binder/command/GetChallengeCommand\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\nimport { type TransactionParserService } from \"@internal/transaction/service/parser/TransactionParserService\";\n\nimport {\n BuildSubContextTask,\n type BuildSubContextTaskArgs,\n} from \"./BuildSubContextTask\";\n\ndescribe(\"BuildSubContextTask\", () => {\n const contextModuleMock = {\n getContext: vi.fn(),\n };\n const transactionParserMock = {\n extractValue: vi.fn(),\n };\n const apiMock = makeDeviceActionInternalApiMock();\n\n let defaultArgs: BuildSubContextTaskArgs;\n\n beforeEach(() => {\n vi.resetAllMocks();\n defaultArgs = {\n context: {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"test payload\",\n },\n contextOptional: [],\n transactionParser:\n transactionParserMock as unknown as TransactionParserService,\n subset: {\n chainId: 1,\n data: \"0x\",\n selector: \"0x\",\n to: \"0x\",\n value: BigInt(0),\n },\n contextModule: contextModuleMock as unknown as ContextModule,\n };\n });\n\n describe(\"when context type is a simple type\", () => {\n const simpleTypes: ClearSignContextSuccess[\"type\"][] = [\n ClearSignContextType.TRANSACTION_INFO,\n ClearSignContextType.WEB3_CHECK,\n ClearSignContextType.PLUGIN,\n ClearSignContextType.EXTERNAL_PLUGIN,\n ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n ];\n\n it.each(simpleTypes)(\n \"should return context with empty subcontextCallbacks for %s\",\n (type) => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type,\n payload: \"test payload\",\n } as ClearSignContextSuccess;\n const args = { ...defaultArgs, context };\n\n // WHEN\n const result = new BuildSubContextTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(0);\n },\n );\n });\n\n describe(\"when context has a direct value reference\", () => {\n it(\"should create a callback to get context with the direct value\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TOKEN,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextType.TOKEN,\n value: \"0x1234567890123456789012345678901234567890\",\n },\n };\n const args = { ...defaultArgs, context };\n const expectedContext: TransactionFieldContext = {\n type: ClearSignContextType.TOKEN,\n chainId: 1,\n address: \"0x1234567890123456789012345678901234567890\",\n };\n\n // WHEN\n const result = new BuildSubContextTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n\n // Verify the callback calls getContext with correct parameters\n const callback = result.subcontextCallbacks[0]!;\n await callback();\n expect(contextModuleMock.getContext).toHaveBeenCalledWith(\n expectedContext,\n );\n });\n\n it(\"should handle undefined value in reference\", () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TOKEN,\n payload: \"test payload\",\n reference: undefined as unknown as ClearSignContextReference,\n };\n const args = { ...defaultArgs, context };\n\n // WHEN\n const result = new BuildSubContextTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(0);\n });\n });\n\n describe(\"when context has a valuePath reference\", () => {\n beforeEach(() => {\n apiMock.sendCommand.mockResolvedValue(\n CommandResultFactory({ data: { challenge: \"test-challenge\" } }),\n );\n });\n\n describe(\"when extractValue returns Left (error)\", () => {\n it(\"should return context with empty subcontextCallbacks\", () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TOKEN,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextType.TOKEN,\n valuePath: [{ type: \"SLICE\", start: 0, end: 20 }],\n },\n };\n const args = { ...defaultArgs, context };\n transactionParserMock.extractValue.mockReturnValue(\n Left(new Error(\"Extraction failed\")),\n );\n\n // WHEN\n const result = new BuildSubContextTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(0);\n });\n });\n\n describe(\"when extractValue returns Right with values\", () => {\n describe(\"for ENUM type\", () => {\n it(\"should create callbacks for matching enum contexts\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TOKEN,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextType.ENUM,\n id: 1,\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n },\n };\n // enum with the same id but different value\n const enumContext1: ClearSignContextSuccess = {\n type: ClearSignContextType.ENUM,\n id: 1,\n value: 1,\n payload: \"enum context 1\",\n };\n // enum to select, id and value match\n const enumContext2: ClearSignContextSuccess = {\n type: ClearSignContextType.ENUM,\n id: 1,\n value: 2,\n payload: \"enum context 2\",\n };\n // other enum context with different id\n const enumContext3: ClearSignContextSuccess = {\n type: ClearSignContextType.ENUM,\n id: 2,\n value: 2,\n payload: \"enum context 3\",\n };\n const args = {\n ...defaultArgs,\n context,\n contextOptional: [enumContext1, enumContext2, enumContext3],\n };\n const extractedValues = [new Uint8Array([0x01, 0x02])]; // Last byte is 2\n transactionParserMock.extractValue.mockReturnValue(\n Right(extractedValues),\n );\n\n // WHEN\n const result = new BuildSubContextTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n const callback = result.subcontextCallbacks[0]!;\n const callbackResult = await callback();\n expect(callbackResult).toEqual(enumContext2);\n });\n\n it(\"should create callbacks for matching enum contexts with two values\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TOKEN,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextType.ENUM,\n id: 1,\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n },\n };\n // enum to select, id and value match\n const enumContext1: ClearSignContextSuccess = {\n type: ClearSignContextType.ENUM,\n id: 1,\n value: 1,\n payload: \"enum context 1\",\n };\n // enum to select, id and value match\n const enumContext2: ClearSignContextSuccess = {\n type: ClearSignContextType.ENUM,\n id: 1,\n value: 2,\n payload: \"enum context 2\",\n };\n // other enum context with different id\n const enumContext3: ClearSignContextSuccess = {\n type: ClearSignContextType.ENUM,\n id: 2,\n value: 2,\n payload: \"enum context 3\",\n };\n const args = {\n ...defaultArgs,\n context,\n contextOptional: [enumContext1, enumContext2, enumContext3],\n };\n const extractedValues = [\n new Uint8Array([0x01, 0x02]),\n new Uint8Array([0x03, 0x02, 0x01]),\n ]; // Last byte is 2\n transactionParserMock.extractValue.mockReturnValue(\n Right(extractedValues),\n );\n\n // WHEN\n const result = new BuildSubContextTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(2);\n const callback1 = result.subcontextCallbacks[0]!;\n const callback2 = result.subcontextCallbacks[1]!;\n const callbackResult1 = await callback1();\n const callbackResult2 = await callback2();\n expect(callbackResult1).toEqual(enumContext2);\n expect(callbackResult2).toEqual(enumContext1);\n });\n\n it(\"should skip when enum value is undefined\", () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TOKEN,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextType.ENUM,\n id: 1,\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n },\n };\n const args = { ...defaultArgs, context };\n const extractedValues = [new Uint8Array([])]; // Empty array\n transactionParserMock.extractValue.mockReturnValue(\n Right(extractedValues),\n );\n\n // WHEN\n const result = new BuildSubContextTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(0);\n });\n\n it(\"should skip when no matching enum context found\", () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.NFT,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextType.ENUM,\n id: 1,\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n },\n };\n const enumContext: ClearSignContextSuccess = {\n type: ClearSignContextType.ENUM,\n id: 2, // Different ID\n value: 2,\n payload: \"enum context\",\n };\n const args = {\n ...defaultArgs,\n context,\n contextOptional: [enumContext],\n };\n const extractedValues = [new Uint8Array([0x01, 0x02])];\n transactionParserMock.extractValue.mockReturnValue(\n Right(extractedValues),\n );\n\n // WHEN\n const result = new BuildSubContextTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(0);\n });\n });\n\n describe(\"for TOKEN type\", () => {\n it(\"should create callbacks to get token context\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TOKEN,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextType.TOKEN,\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n },\n };\n const args = { ...defaultArgs, context };\n const extractedValues = [\n new Uint8Array([\n 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,\n 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,\n ]),\n ];\n transactionParserMock.extractValue.mockReturnValue(\n Right(extractedValues),\n );\n contextModuleMock.getContext.mockResolvedValue({\n type: ClearSignContextType.TOKEN,\n payload: \"token result\",\n });\n\n // WHEN\n const result = new BuildSubContextTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n const callback = result.subcontextCallbacks[0]!;\n const callbackResult = await callback();\n expect(callbackResult).toEqual({\n type: ClearSignContextType.TOKEN,\n payload: \"token result\",\n });\n expect(contextModuleMock.getContext).toHaveBeenCalledWith({\n type: ClearSignContextType.TOKEN,\n chainId: 1,\n address: \"0x030405060708090a0b0c0d0e0f10111213141516\",\n });\n });\n });\n\n describe(\"for NFT type\", () => {\n it(\"should create callbacks to get NFT context\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.NFT,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextType.NFT,\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n },\n };\n const args = { ...defaultArgs, context };\n const extractedValues = [\n new Uint8Array([\n 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,\n 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,\n ]),\n ];\n transactionParserMock.extractValue.mockReturnValue(\n Right(extractedValues),\n );\n contextModuleMock.getContext.mockResolvedValue({\n type: ClearSignContextType.NFT,\n payload: \"nft result\",\n });\n\n // WHEN\n const result = new BuildSubContextTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n const callback = result.subcontextCallbacks[0]!;\n const callbackResult = await callback();\n expect(callbackResult).toEqual({\n type: ClearSignContextType.NFT,\n payload: \"nft result\",\n });\n expect(contextModuleMock.getContext).toHaveBeenCalledWith({\n type: ClearSignContextType.NFT,\n chainId: 1,\n address: \"0x030405060708090a0b0c0d0e0f10111213141516\",\n });\n });\n });\n\n describe(\"for TRUSTED_NAME type\", () => {\n it(\"should create callbacks to get trusted name context with challenge\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRUSTED_NAME,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextType.TRUSTED_NAME,\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n types: [\"type1\", \"type2\"],\n sources: [\"source1\", \"source2\"],\n },\n };\n const args = { ...defaultArgs, context };\n const extractedValues = [\n new Uint8Array([\n 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,\n 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,\n ]),\n ];\n transactionParserMock.extractValue.mockReturnValue(\n Right(extractedValues),\n );\n contextModuleMock.getContext.mockResolvedValue({\n type: ClearSignContextType.TRUSTED_NAME,\n payload: \"trusted name result\",\n });\n\n // WHEN\n const result = new BuildSubContextTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n const callback = result.subcontextCallbacks[0]!;\n const callbackResult = await callback();\n expect(callbackResult).toEqual({\n type: ClearSignContextType.TRUSTED_NAME,\n payload: \"trusted name result\",\n });\n expect(apiMock.sendCommand).toHaveBeenCalledWith(\n expect.any(GetChallengeCommand),\n );\n expect(contextModuleMock.getContext).toHaveBeenCalledWith({\n type: ClearSignContextType.TRUSTED_NAME,\n chainId: 1,\n address: \"0x030405060708090a0b0c0d0e0f10111213141516\",\n challenge: \"test-challenge\",\n types: [\"type1\", \"type2\"],\n sources: [\"source1\", \"source2\"],\n });\n });\n\n it(\"should handle challenge command failure\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRUSTED_NAME,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextType.TRUSTED_NAME,\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n types: [\"type1\"],\n sources: [\"source1\"],\n },\n };\n const args = { ...defaultArgs, context };\n const extractedValues = [\n new Uint8Array([\n 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,\n 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,\n ]),\n ];\n transactionParserMock.extractValue.mockReturnValue(\n Right(extractedValues),\n );\n const error = new UnknownDeviceExchangeError(\"Failed\");\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({\n error,\n }),\n );\n\n // WHEN\n const result = new BuildSubContextTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n const callback = result.subcontextCallbacks[0]!;\n const callbackResult = await callback();\n expect(callbackResult).toEqual({\n error: new Error(\"Failed to get challenge\"),\n type: ClearSignContextType.ERROR,\n });\n });\n });\n\n describe(\"for multiple values\", () => {\n it(\"should create callbacks for each extracted value\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TOKEN,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextType.TOKEN,\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n },\n };\n const args = { ...defaultArgs, context };\n const extractedValues = [\n new Uint8Array([\n 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,\n 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,\n ]),\n new Uint8Array([\n 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,\n 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,\n ]),\n ];\n transactionParserMock.extractValue.mockReturnValue(\n Right(extractedValues),\n );\n contextModuleMock.getContext.mockResolvedValueOnce({\n type: ClearSignContextType.TOKEN,\n payload: \"token result 1\",\n });\n contextModuleMock.getContext.mockResolvedValueOnce({\n type: ClearSignContextType.TOKEN,\n payload: \"token result 2\",\n });\n\n // WHEN\n const result = new BuildSubContextTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(2);\n const callback1 = result.subcontextCallbacks[0]!;\n const callback2 = result.subcontextCallbacks[1]!;\n const callbackResult1 = await callback1();\n const callbackResult2 = await callback2();\n expect(callbackResult1).toEqual({\n type: ClearSignContextType.TOKEN,\n payload: \"token result 1\",\n });\n expect(callbackResult2).toEqual({\n type: ClearSignContextType.TOKEN,\n payload: \"token result 2\",\n });\n expect(contextModuleMock.getContext).toHaveBeenCalledTimes(2);\n expect(contextModuleMock.getContext).toHaveBeenNthCalledWith(1, {\n type: ClearSignContextType.TOKEN,\n chainId: 1,\n address: \"0x030405060708090a0b0c0d0e0f10111213141516\",\n });\n expect(contextModuleMock.getContext).toHaveBeenNthCalledWith(2, {\n type: ClearSignContextType.TOKEN,\n chainId: 1,\n address: \"0x232425262728292a2b2c2d2e2f30313233343536\",\n });\n });\n });\n });\n });\n\n describe(\"when context has no reference\", () => {\n it(\"should return context with empty subcontextCallbacks\", () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TOKEN,\n payload: \"test payload\",\n };\n const args = { ...defaultArgs, context };\n\n // WHEN\n const result = new BuildSubContextTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(0);\n });\n });\n\n describe(\"when context has reference but no valuePath\", () => {\n it(\"should return context with empty subcontextCallbacks\", () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TOKEN,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextType.TOKEN,\n } as ClearSignContextReference<ClearSignContextType.TOKEN>,\n };\n const args = { ...defaultArgs, context };\n\n // WHEN\n const result = new BuildSubContextTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(0);\n });\n });\n\n describe(\"edge cases\", () => {\n it(\"should handle value array shorter than 20 bytes for address extraction\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TOKEN,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextType.TOKEN,\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n },\n };\n const args = { ...defaultArgs, context };\n const extractedValues = [new Uint8Array([0x01, 0x02, 0x03])]; // Only 3 bytes\n transactionParserMock.extractValue.mockReturnValue(\n Right(extractedValues),\n );\n contextModuleMock.getContext.mockResolvedValue({\n type: ClearSignContextType.ERROR,\n message: \"Invalid address\",\n });\n\n // WHEN\n const result = new BuildSubContextTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n const callback = result.subcontextCallbacks[0]!;\n const callbackResult = await callback();\n expect(callbackResult).toEqual({\n type: ClearSignContextType.ERROR,\n message: \"Invalid address\",\n });\n expect(contextModuleMock.getContext).toHaveBeenCalledWith({\n type: ClearSignContextType.TOKEN,\n chainId: 1,\n address: \"0x010203\",\n });\n });\n\n it(\"should handle empty value array\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TOKEN,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextType.TOKEN,\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n },\n };\n const args = { ...defaultArgs, context };\n const extractedValues = [new Uint8Array([])]; // Empty array\n transactionParserMock.extractValue.mockReturnValue(\n Right(extractedValues),\n );\n contextModuleMock.getContext.mockResolvedValue({\n type: ClearSignContextType.TOKEN,\n payload: \"token result\",\n });\n\n // WHEN\n const result = new BuildSubContextTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n\n // Verify the callback calls getContext with empty address\n const callback = result.subcontextCallbacks[0]!;\n const callbackResult = await callback();\n expect(callbackResult).toEqual({\n type: ClearSignContextType.TOKEN,\n payload: \"token result\",\n });\n expect(contextModuleMock.getContext).toHaveBeenCalledWith({\n type: ClearSignContextType.TOKEN,\n chainId: 1,\n address: \"0x\",\n });\n });\n });\n});\n"],
5
+ "mappings": "aAAA,IAAAA,EAMO,oCACPC,EAGO,2CACPC,EAA4B,qBAE5BC,EAAoC,4DACpCC,EAAgD,6EAGhDC,EAGO,iCAEP,SAAS,sBAAuB,IAAM,CACpC,MAAMC,EAAoB,CACxB,WAAY,GAAG,GAAG,CACpB,EACMC,EAAwB,CAC5B,aAAc,GAAG,GAAG,CACtB,EACMC,KAAU,mCAAgC,EAEhD,IAAIC,EAEJ,WAAW,IAAM,CACf,GAAG,cA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AAM,uBAAqB,MAC3B,QAAS,EACT,QAAS,IACX,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["import_context_module", "import_device_management_kit", "import_purify_ts", "import_GetChallengeCommand", "import_makeInternalApi", "import_BuildSubContextTask", "contextModuleMock", "transactionParserMock", "apiMock", "defaultArgs", "simpleTypes", "type", "args", "result", "context", "expectedContext", "callback", "enumContext1", "enumContext2", "enumContext3", "extractedValues", "callbackResult", "callback1", "callback2", "callbackResult1", "callbackResult2", "enumContext", "error"]
7
+ }
@@ -1,2 +1,2 @@
1
- "use strict";var d=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var w=(i,e)=>{for(var n in e)d(i,n,{get:e[n],enumerable:!0})},G=(i,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of M(e))!b.call(i,a)&&a!==n&&d(i,a,{get:()=>e[a],enumerable:!(r=R(e,a))||r.enumerable});return i};var O=i=>G(d({},"__esModule",{value:!0}),i);var _={};w(_,{BuildTransactionContextTask:()=>D});module.exports=O(_);var o=require("@ledgerhq/context-module"),l=require("@ledgerhq/device-management-kit"),x=require("../../app-binder/command/GetChallengeCommand"),h=require("../../app-binder/task/GetWeb3CheckTask"),I=require("../../shared/utils/ApplicationChecker");class D{constructor(e,n,r=(a,c)=>new h.GetWeb3CheckTask(a,c)){this.api=e;this.args=n;this.getWeb3ChecksFactory=r}async run(){const{contextModule:e,mapper:n,transaction:r,options:a,appConfig:c,derivationPath:k}=this.args,y=this.api.getDeviceSessionState(),S=n.mapTransactionToSubset(r);S.ifLeft(t=>{throw t});const{subset:T,serializedTransaction:A,type:E}=S.unsafeCoerce();let u=null;c.web3ChecksEnabled&&(u=(await this.getWeb3ChecksFactory(this.api,{contextModule:e,derivationPath:k,mapper:n,transaction:r}).run()).web3Check);let g;const m=await this.api.sendCommand(new x.GetChallengeCommand);(0,l.isSuccessCommandResult)(m)&&(g=m.data.challenge);const f=await e.getContexts({challenge:g,domain:a.domain,deviceModelId:y.deviceModelId,...T}),p=f.filter(t=>t.type!==o.ClearSignContextType.ERROR&&t.type!==o.ClearSignContextType.ENUM),N=f.filter(t=>t.type===o.ClearSignContextType.ENUM);let C=[];const s=p.find(t=>t.type===o.ClearSignContextType.TRANSACTION_INFO);if(s&&!s.certificate)throw new Error("Transaction info certificate is missing");if(!this.supportsGenericParser(y,c)||s===void 0)C=p.filter(t=>t.type!==o.ClearSignContextType.TRANSACTION_INFO&&t.type!==o.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION);else{const t=p.filter(v=>v.type===o.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION);C={transactionInfo:s.payload,transactionInfoCertificate:s.certificate,transactionFields:t,transactionEnums:N}}return{clearSignContexts:C,serializedTransaction:A,chainId:T.chainId,transactionType:E,web3Check:u}}supportsGenericParser(e,n){return new I.ApplicationChecker(e,n).withMinVersionExclusive("1.14.0").excludeDeviceModel(l.DeviceModelId.NANO_S).check()}}0&&(module.exports={BuildTransactionContextTask});
1
+ "use strict";var y=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var R=Object.prototype.hasOwnProperty;var v=(a,e)=>{for(var i in e)y(a,i,{get:e[i],enumerable:!0})},M=(a,e,i,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of _(e))!R.call(a,o)&&o!==i&&y(a,o,{get:()=>e[o],enumerable:!(s=O(e,o))||s.enumerable});return a};var b=a=>M(y({},"__esModule",{value:!0}),a);var D={};v(D,{BuildTransactionContextTask:()=>w});module.exports=b(D);var n=require("@ledgerhq/context-module"),p=require("@ledgerhq/device-management-kit"),u=require("../../../api/model/ClearSigningType"),I=require("../../app-binder/command/GetChallengeCommand"),h=require("../../app-binder/task/GetWeb3CheckTask"),A=require("../../shared/utils/ApplicationChecker");class w{constructor(e,i,s=(o,d)=>new h.GetWeb3CheckTask(o,d)){this._api=e;this._args=i;this.getWeb3ChecksFactory=s}async run(){const{contextModule:e,options:i,appConfig:s,derivationPath:o,transaction:d,subset:T}=this._args,S=this._api.getDeviceSessionState();let l=[],x=[],m=u.ClearSigningType.BASIC,c=null;s.web3ChecksEnabled&&(c=(await this.getWeb3ChecksFactory(this._api,{contextModule:e,derivationPath:o,subset:T,transaction:d}).run()).web3Check);let f;if(S.deviceModelId!==p.DeviceModelId.NANO_S){const t=await this._api.sendCommand(new I.GetChallengeCommand);(0,p.isSuccessCommandResult)(t)&&(f=t.data.challenge)}const N=await e.getContexts({challenge:f,domain:i.domain,deviceModelId:S.deviceModelId,...T}),C=N.filter(t=>t.type!==n.ClearSignContextType.ERROR&&t.type!==n.ClearSignContextType.ENUM),E=N.filter(t=>t.type===n.ClearSignContextType.ENUM),g=C.find(t=>t.type===n.ClearSignContextType.TRANSACTION_INFO);if(!this.supportsGenericParser(S,s)||g===void 0)l=C.filter(t=>t.type!==n.ClearSignContextType.TRANSACTION_INFO&&t.type!==n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION),c&&(l=[c,...l]);else if(g.certificate){const t=C.filter(r=>r.type===n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION),k=C.filter(r=>r.type===n.ClearSignContextType.PROXY_DELEGATE_CALL);l=[...C.filter(r=>r.type===n.ClearSignContextType.DYNAMIC_NETWORK||r.type===n.ClearSignContextType.DYNAMIC_NETWORK_ICON),...k,g,...t,...c?[c]:[]],x=[...E],m=u.ClearSigningType.EIP7730}return{clearSignContexts:l,clearSignContextsOptional:x,clearSigningType:m}}supportsGenericParser(e,i){return new A.ApplicationChecker(e,i).withMinVersionExclusive("1.14.0").excludeDeviceModel(p.DeviceModelId.NANO_S).check()}}0&&(module.exports={BuildTransactionContextTask});
2
2
  //# sourceMappingURL=BuildTransactionContextTask.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/internal/app-binder/task/BuildTransactionContextTask.ts"],
4
- "sourcesContent": ["import {\n type ClearSignContextSuccess,\n type ClearSignContextSuccessType,\n ClearSignContextType,\n type ContextModule,\n} from \"@ledgerhq/context-module\";\nimport {\n DeviceModelId,\n type DeviceSessionState,\n type InternalApi,\n isSuccessCommandResult,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { type GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\nimport { type TransactionOptions } from \"@api/model/TransactionOptions\";\nimport { type TransactionType } from \"@api/model/TransactionType\";\nimport { GetChallengeCommand } from \"@internal/app-binder/command/GetChallengeCommand\";\nimport {\n GetWeb3CheckTask,\n type GetWeb3CheckTaskArgs,\n} from \"@internal/app-binder/task/GetWeb3CheckTask\";\nimport { ApplicationChecker } from \"@internal/shared/utils/ApplicationChecker\";\nimport { type TransactionMapperService } from \"@internal/transaction/service/mapper/TransactionMapperService\";\n\nimport { type GenericContext } from \"./ProvideTransactionGenericContextTask\";\n\nexport type BuildTransactionTaskResult = {\n readonly clearSignContexts: ClearSignContextSuccess[] | GenericContext;\n readonly serializedTransaction: Uint8Array;\n readonly chainId: number;\n readonly transactionType: TransactionType;\n readonly web3Check: ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK> | null;\n};\n\nexport type BuildTransactionContextTaskArgs = {\n readonly contextModule: ContextModule;\n readonly mapper: TransactionMapperService;\n readonly transaction: Uint8Array;\n readonly options: TransactionOptions;\n readonly appConfig: GetConfigCommandResponse;\n readonly derivationPath: string;\n};\n\nexport class BuildTransactionContextTask {\n constructor(\n private readonly api: InternalApi,\n private readonly args: BuildTransactionContextTaskArgs,\n private readonly getWeb3ChecksFactory = (\n api: InternalApi,\n args: GetWeb3CheckTaskArgs,\n ) => new GetWeb3CheckTask(api, args),\n ) {}\n\n async run(): Promise<BuildTransactionTaskResult> {\n const {\n contextModule,\n mapper,\n transaction,\n options,\n appConfig,\n derivationPath,\n } = this.args;\n const deviceState = this.api.getDeviceSessionState();\n\n // Parse transaction\n const parsed = mapper.mapTransactionToSubset(transaction);\n parsed.ifLeft((err) => {\n throw err;\n });\n const { subset, serializedTransaction, type } = parsed.unsafeCoerce();\n\n // Run the web3checks if needed\n let web3Check: ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK> | null =\n null;\n if (appConfig.web3ChecksEnabled) {\n web3Check = (\n await this.getWeb3ChecksFactory(this.api, {\n contextModule,\n derivationPath,\n mapper,\n transaction,\n }).run()\n ).web3Check;\n }\n\n // Get challenge\n let challenge: string | undefined = undefined;\n const challengeRes = await this.api.sendCommand(new GetChallengeCommand());\n if (isSuccessCommandResult(challengeRes)) {\n challenge = challengeRes.data.challenge;\n }\n\n // Get the clear sign contexts\n const clearSignContexts = await contextModule.getContexts({\n challenge: challenge,\n domain: options.domain,\n deviceModelId: deviceState.deviceModelId,\n ...subset,\n });\n\n // NOTE: we need to filter out the ENUM and ERROR types\n // ENUM are handled differently\n // ERROR are not handled at all for now\n const clearSignContextsSuccess: ClearSignContextSuccess<\n Exclude<ClearSignContextSuccessType, ClearSignContextType.ENUM>\n >[] = clearSignContexts.filter(\n (context) =>\n context.type !== ClearSignContextType.ERROR &&\n context.type !== ClearSignContextType.ENUM,\n );\n\n // Retrieve all ENUM contexts\n const transactionEnums: ClearSignContextSuccess<ClearSignContextType.ENUM>[] =\n clearSignContexts.filter(\n (context) => context.type === ClearSignContextType.ENUM,\n );\n\n let filteredContexts: ClearSignContextSuccess[] | GenericContext = [];\n const transactionInfo = clearSignContextsSuccess.find(\n (ctx) => ctx.type === ClearSignContextType.TRANSACTION_INFO,\n );\n\n if (transactionInfo && !transactionInfo.certificate) {\n throw new Error(\"Transaction info certificate is missing\");\n }\n\n // If the device does not support the generic parser,\n // we need to filter out the transaction info and transaction field description\n // as they are not supported by the device\n if (\n !this.supportsGenericParser(deviceState, appConfig) ||\n transactionInfo === undefined\n ) {\n filteredContexts = clearSignContextsSuccess.filter(\n (ctx) =>\n ctx.type !== ClearSignContextType.TRANSACTION_INFO &&\n ctx.type !== ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n );\n } else {\n const transactionFields = clearSignContextsSuccess.filter(\n (ctx) =>\n ctx.type === ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n );\n filteredContexts = {\n transactionInfo: transactionInfo.payload,\n transactionInfoCertificate: transactionInfo.certificate!,\n transactionFields,\n transactionEnums,\n };\n }\n\n return {\n clearSignContexts: filteredContexts,\n serializedTransaction,\n chainId: subset.chainId,\n transactionType: type,\n web3Check,\n };\n }\n\n private supportsGenericParser(\n deviceState: DeviceSessionState,\n appConfig: GetConfigCommandResponse,\n ): boolean {\n return new ApplicationChecker(deviceState, appConfig)\n .withMinVersionExclusive(\"1.14.0\")\n .excludeDeviceModel(DeviceModelId.NANO_S)\n .check();\n }\n}\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAKO,oCACPC,EAKO,2CAKPC,EAAoC,4DACpCC,EAGO,sDACPC,EAAmC,qDAsB5B,MAAMN,CAA4B,CACvC,YACmBO,EACAC,EACAC,EAAuB,CACtCF,EACAC,IACG,IAAI,mBAAiBD,EAAKC,CAAI,EACnC,CANiB,SAAAD,EACA,UAAAC,EACA,0BAAAC,CAIhB,CAEH,MAAM,KAA2C,CAC/C,KAAM,CACJ,cAAAC,EACA,OAAAC,EACA,YAAAC,EACA,QAAAC,EACA,UAAAC,EACA,eAAAC,CACF,EAAI,KAAK,KACHC,EAAc,KAAK,IAAI,sBAAsB,EAG7CC,EAASN,EAAO,uBAAuBC,CAAW,EACxDK,EAAO,OAAQC,GAAQ,CACrB,MAAMA,CACR,CAAC,EACD,KAAM,CAAE,OAAAC,EAAQ,sBAAAC,EAAuB,KAAAC,CAAK,EAAIJ,EAAO,aAAa,EAGpE,IAAIK,EACF,KACER,EAAU,oBACZQ,GACE,MAAM,KAAK,qBAAqB,KAAK,IAAK,CACxC,cAAAZ,EACA,eAAAK,EACA,OAAAJ,EACA,YAAAC,CACF,CAAC,EAAE,IAAI,GACP,WAIJ,IAAIW,EACJ,MAAMC,EAAe,MAAM,KAAK,IAAI,YAAY,IAAI,qBAAqB,KACrE,0BAAuBA,CAAY,IACrCD,EAAYC,EAAa,KAAK,WAIhC,MAAMC,EAAoB,MAAMf,EAAc,YAAY,CACxD,UAAWa,EACX,OAAQV,EAAQ,OAChB,cAAeG,EAAY,cAC3B,GAAGG,CACL,CAAC,EAKKO,EAEAD,EAAkB,OACrBE,GACCA,EAAQ,OAAS,uBAAqB,OACtCA,EAAQ,OAAS,uBAAqB,IAC1C,EAGMC,EACJH,EAAkB,OACfE,GAAYA,EAAQ,OAAS,uBAAqB,IACrD,EAEF,IAAIE,EAA+D,CAAC,EACpE,MAAMC,EAAkBJ,EAAyB,KAC9CK,GAAQA,EAAI,OAAS,uBAAqB,gBAC7C,EAEA,GAAID,GAAmB,CAACA,EAAgB,YACtC,MAAM,IAAI,MAAM,yCAAyC,EAM3D,GACE,CAAC,KAAK,sBAAsBd,EAAaF,CAAS,GAClDgB,IAAoB,OAEpBD,EAAmBH,EAAyB,OACzCK,GACCA,EAAI,OAAS,uBAAqB,kBAClCA,EAAI,OAAS,uBAAqB,6BACtC,MACK,CACL,MAAMC,EAAoBN,EAAyB,OAChDK,GACCA,EAAI,OAAS,uBAAqB,6BACtC,EACAF,EAAmB,CACjB,gBAAiBC,EAAgB,QACjC,2BAA4BA,EAAgB,YAC5C,kBAAAE,EACA,iBAAAJ,CACF,CACF,CAEA,MAAO,CACL,kBAAmBC,EACnB,sBAAAT,EACA,QAASD,EAAO,QAChB,gBAAiBE,EACjB,UAAAC,CACF,CACF,CAEQ,sBACNN,EACAF,EACS,CACT,OAAO,IAAI,qBAAmBE,EAAaF,CAAS,EACjD,wBAAwB,QAAQ,EAChC,mBAAmB,gBAAc,MAAM,EACvC,MAAM,CACX,CACF",
6
- "names": ["BuildTransactionContextTask_exports", "__export", "BuildTransactionContextTask", "__toCommonJS", "import_context_module", "import_device_management_kit", "import_GetChallengeCommand", "import_GetWeb3CheckTask", "import_ApplicationChecker", "api", "args", "getWeb3ChecksFactory", "contextModule", "mapper", "transaction", "options", "appConfig", "derivationPath", "deviceState", "parsed", "err", "subset", "serializedTransaction", "type", "web3Check", "challenge", "challengeRes", "clearSignContexts", "clearSignContextsSuccess", "context", "transactionEnums", "filteredContexts", "transactionInfo", "ctx", "transactionFields"]
4
+ "sourcesContent": ["import {\n type ClearSignContext,\n type ClearSignContextSuccess,\n type ClearSignContextSuccessType,\n ClearSignContextType,\n type ContextModule,\n type TransactionSubset,\n} from \"@ledgerhq/context-module\";\nimport {\n DeviceModelId,\n type DeviceSessionState,\n type InternalApi,\n isSuccessCommandResult,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { type GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\nimport { ClearSigningType } from \"@api/model/ClearSigningType\";\nimport { type TransactionOptions } from \"@api/model/TransactionOptions\";\nimport { GetChallengeCommand } from \"@internal/app-binder/command/GetChallengeCommand\";\nimport {\n GetWeb3CheckTask,\n type GetWeb3CheckTaskArgs,\n} from \"@internal/app-binder/task/GetWeb3CheckTask\";\nimport { ApplicationChecker } from \"@internal/shared/utils/ApplicationChecker\";\n\nexport type BuildTransactionTaskResult = {\n readonly clearSignContexts: ClearSignContextSuccess[];\n readonly clearSignContextsOptional: ClearSignContextSuccess[];\n readonly clearSigningType: ClearSigningType;\n};\n\nexport type BuildTransactionContextTaskArgs = {\n readonly contextModule: ContextModule;\n readonly options: TransactionOptions;\n readonly appConfig: GetConfigCommandResponse;\n readonly derivationPath: string;\n readonly transaction: Uint8Array;\n readonly subset: TransactionSubset;\n};\n\nexport class BuildTransactionContextTask {\n constructor(\n private readonly _api: InternalApi,\n private readonly _args: BuildTransactionContextTaskArgs,\n private readonly getWeb3ChecksFactory = (\n api: InternalApi,\n args: GetWeb3CheckTaskArgs,\n ) => new GetWeb3CheckTask(api, args),\n ) {}\n\n async run(): Promise<BuildTransactionTaskResult> {\n const {\n contextModule,\n options,\n appConfig,\n derivationPath,\n transaction,\n subset,\n } = this._args;\n const deviceState = this._api.getDeviceSessionState();\n let filteredContexts: ClearSignContextSuccess[] = [];\n let filteredContextOptional: ClearSignContextSuccess[] = [];\n let clearSigningType: ClearSigningType = ClearSigningType.BASIC;\n\n // Run the web3checks if needed\n let web3Check: ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK> | null =\n null;\n if (appConfig.web3ChecksEnabled) {\n web3Check = (\n await this.getWeb3ChecksFactory(this._api, {\n contextModule,\n derivationPath,\n subset,\n transaction,\n }).run()\n ).web3Check;\n }\n\n // Get challenge (not supported on Nano S)\n let challenge: string | undefined = undefined;\n if (deviceState.deviceModelId !== DeviceModelId.NANO_S) {\n const challengeRes = await this._api.sendCommand(\n new GetChallengeCommand(),\n );\n if (isSuccessCommandResult(challengeRes)) {\n challenge = challengeRes.data.challenge;\n }\n }\n\n // Get the clear sign contexts\n const clearSignContexts: ClearSignContext[] =\n await contextModule.getContexts({\n challenge: challenge,\n domain: options.domain,\n deviceModelId: deviceState.deviceModelId,\n ...subset,\n });\n\n // NOTE: we need to filter out the ENUM and ERROR types\n // ENUM are handled differently\n // ERROR are not handled at all for now\n const clearSignContextsSuccess: ClearSignContextSuccess<\n Exclude<ClearSignContextSuccessType, ClearSignContextType.ENUM>\n >[] = clearSignContexts.filter(\n (context) =>\n context.type !== ClearSignContextType.ERROR &&\n context.type !== ClearSignContextType.ENUM,\n );\n\n // Retrieve all ENUM contexts\n const transactionEnums: ClearSignContextSuccess<ClearSignContextType.ENUM>[] =\n clearSignContexts.filter(\n (context) => context.type === ClearSignContextType.ENUM,\n );\n\n const transactionInfo = clearSignContextsSuccess.find(\n (ctx) => ctx.type === ClearSignContextType.TRANSACTION_INFO,\n );\n\n // If the device does not support the generic parser,\n // we need to filter out the transaction info and transaction field description\n // as they are not supported by the device\n if (\n !this.supportsGenericParser(deviceState, appConfig) ||\n transactionInfo === undefined\n ) {\n filteredContexts = clearSignContextsSuccess.filter(\n (ctx) =>\n ctx.type !== ClearSignContextType.TRANSACTION_INFO &&\n ctx.type !== ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n );\n\n // If the device supports the web3 check, we need to add it to the list of contexts\n if (web3Check) {\n filteredContexts = [web3Check, ...filteredContexts];\n }\n } else if (transactionInfo.certificate) {\n const transactionFields = clearSignContextsSuccess.filter(\n (ctx) =>\n ctx.type === ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n );\n const proxyContexts = clearSignContextsSuccess.filter(\n (ctx) => ctx.type === ClearSignContextType.PROXY_DELEGATE_CALL,\n );\n const dynamicNetworkContexts = clearSignContextsSuccess.filter(\n (ctx) =>\n ctx.type === ClearSignContextType.DYNAMIC_NETWORK ||\n ctx.type === ClearSignContextType.DYNAMIC_NETWORK_ICON,\n );\n\n filteredContexts = [\n ...dynamicNetworkContexts,\n ...proxyContexts,\n transactionInfo,\n ...transactionFields,\n ...(web3Check ? [web3Check] : []),\n ];\n filteredContextOptional = [...transactionEnums];\n clearSigningType = ClearSigningType.EIP7730;\n }\n\n return {\n clearSignContexts: filteredContexts,\n clearSignContextsOptional: filteredContextOptional,\n clearSigningType,\n };\n }\n\n private supportsGenericParser(\n deviceState: DeviceSessionState,\n appConfig: GetConfigCommandResponse,\n ): boolean {\n return new ApplicationChecker(deviceState, appConfig)\n .withMinVersionExclusive(\"1.14.0\")\n .excludeDeviceModel(DeviceModelId.NANO_S)\n .check();\n }\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAOO,oCACPC,EAKO,2CAGPC,EAAiC,uCAEjCC,EAAoC,4DACpCC,EAGO,sDACPC,EAAmC,qDAiB5B,MAAMP,CAA4B,CACvC,YACmBQ,EACAC,EACAC,EAAuB,CACtCC,EACAC,IACG,IAAI,mBAAiBD,EAAKC,CAAI,EACnC,CANiB,UAAAJ,EACA,WAAAC,EACA,0BAAAC,CAIhB,CAEH,MA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,EAAmB,CACjB,GAP6BO,EAAyB,OACrDI,GACCA,EAAI,OAAS,uBAAqB,iBAClCA,EAAI,OAAS,uBAAqB,oBACtC,EAIE,GAAGE,EACHH,EACA,GAAGE,EACH,GAAIT,EAAY,CAACA,CAAS,EAAI,CAAC,CACjC,EACAF,EAA0B,CAAC,GAAGQ,CAAgB,EAC9CP,EAAmB,mBAAiB,OACtC,CAEA,MAAO,CACL,kBAAmBF,EACnB,0BAA2BC,EAC3B,iBAAAC,CACF,CACF,CAEQ,sBACNH,EACAJ,EACS,CACT,OAAO,IAAI,qBAAmBI,EAAaJ,CAAS,EACjD,wBAAwB,QAAQ,EAChC,mBAAmB,gBAAc,MAAM,EACvC,MAAM,CACX,CACF",
6
+ "names": ["BuildTransactionContextTask_exports", "__export", "BuildTransactionContextTask", "__toCommonJS", "import_context_module", "import_device_management_kit", "import_ClearSigningType", "import_GetChallengeCommand", "import_GetWeb3CheckTask", "import_ApplicationChecker", "_api", "_args", "getWeb3ChecksFactory", "api", "args", "contextModule", "options", "appConfig", "derivationPath", "transaction", "subset", "deviceState", "filteredContexts", "filteredContextOptional", "clearSigningType", "web3Check", "challenge", "challengeRes", "clearSignContexts", "clearSignContextsSuccess", "context", "transactionEnums", "transactionInfo", "ctx", "transactionFields", "proxyContexts"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var a=require("@ledgerhq/context-module"),e=require("@ledgerhq/device-management-kit"),x=require("ethers"),u=require("purify-ts"),m=require("../../app-binder/device-action/__test-utils__/makeInternalApi"),p=require("./BuildTransactionContextTask");describe("BuildTransactionContextTask",()=>{const r={getContext:vi.fn(),getContexts:vi.fn(),getTypedDataFilters:vi.fn(),getWeb3Checks:vi.fn()},l={mapTransactionToSubset:vi.fn()},h={domain:"domain-name.eth"},S=(0,e.hexaStringToBuffer)(x.Transaction.from({chainId:1n,nonce:0,data:"0x"}).unsignedSerialized),C={keyUsageNumber:1,payload:new Uint8Array([1,2,3])};let d;const o=(0,m.makeDeviceActionInternalApiMock)(),i=vi.fn();function y(n){return{blindSigningEnabled:!1,web3ChecksEnabled:n,web3ChecksOptIn:!1,version:"1.13.0"}}beforeEach(()=>{vi.resetAllMocks(),o.sendCommand.mockResolvedValue((0,e.CommandResultFactory)({data:{challenge:"challenge"}})),i.mockReturnValue({run:async()=>({web3Check:null})}),d={contextModule:r,mapper:l,transaction:S,options:h,appConfig:y(!1),derivationPath:"44'/60'/0'/0/0"}}),it("should build the transaction context without clear sign contexts",async()=>{const n=new Uint8Array([1,2,3]),t=[],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};l.mapTransactionToSubset.mockReturnValueOnce((0,u.Right)(s)),r.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const c=await new p.BuildTransactionContextTask(o,{...d,appConfig:y(!0)},i).run();expect(c).toEqual({clearSignContexts:t,serializedTransaction:n,chainId:1,transactionType:0,web3Check:null})}),it("should build the transaction context with web3checks",async()=>{const n=new Uint8Array([1,2,3]),t=[],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0},c="web3Check";i.mockReturnValueOnce({run:async()=>({web3Check:c})}),l.mapTransactionToSubset.mockReturnValueOnce((0,u.Right)(s)),r.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const T=await new p.BuildTransactionContextTask(o,{...d,appConfig:y(!0)},i).run();expect(T).toEqual({clearSignContexts:t,serializedTransaction:n,chainId:1,transactionType:0,web3Check:c})}),it("should build the transaction context with clear sign contexts",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.NFT,payload:"payload-2"}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2},c="web3Check";i.mockReturnValueOnce({run:async()=>({web3Check:c})}),l.mapTransactionToSubset.mockReturnValueOnce((0,u.Right)(s)),r.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const T=await new p.BuildTransactionContextTask(o,d,i).run();expect(T).toEqual({clearSignContexts:t,serializedTransaction:n,chainId:1,transactionType:2,web3Check:null})}),it("should build the transaction context with generic-parser context",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:C},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:a.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:C},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};l.mapTransactionToSubset.mockReturnValueOnce((0,u.Right)(s)),r.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const c=await new p.BuildTransactionContextTask(o,d,i).run();expect(c).toEqual({clearSignContexts:{transactionInfo:"payload-1",transactionInfoCertificate:C,transactionFields:[t[1],t[3]],transactionEnums:[t[2]]},serializedTransaction:n,chainId:1,transactionType:2,web3Check:null})}),it("should call the mapper with the transaction",async()=>{const n=new Uint8Array([1,2,3]),t=[],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};l.mapTransactionToSubset.mockReturnValueOnce((0,u.Right)(s)),r.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),await new p.BuildTransactionContextTask(o,d,i).run(),expect(l.mapTransactionToSubset).toHaveBeenCalledWith(S)}),it("should call the web3checks factory with correct parameters",async()=>{const n=new Uint8Array([1,2,3]),t=[],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};l.mapTransactionToSubset.mockReturnValueOnce((0,u.Right)(s)),r.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),await new p.BuildTransactionContextTask(o,{...d,appConfig:y(!0)},i).run(),expect(i).toHaveBeenCalledWith(o,{contextModule:r,derivationPath:"44'/60'/0'/0/0",mapper:l,transaction:S})}),it("should call the context module with the correct parameters",async()=>{const n=new Uint8Array([1,2,3]),t=[],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};l.mapTransactionToSubset.mockReturnValueOnce((0,u.Right)(s)),r.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),await new p.BuildTransactionContextTask(o,d,i).run(),expect(r.getContexts).toHaveBeenCalledWith({deviceModelId:e.DeviceModelId.FLEX,challenge:"challenge",domain:"domain-name.eth",...s.subset})}),it("should call the context module without context on error",async()=>{const n=new Uint8Array([1,2,3]),t=[],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};l.mapTransactionToSubset.mockReturnValueOnce((0,u.Right)(s)),r.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),o.sendCommand.mockResolvedValueOnce((0,e.CommandResultFactory)({error:new e.UnknownDeviceExchangeError})),await new p.BuildTransactionContextTask(o,d,i).run(),expect(r.getContexts).toHaveBeenCalledWith({deviceModelId:e.DeviceModelId.FLEX,challenge:void 0,domain:"domain-name.eth",...s.subset})}),it("should throw an error if the mapper returns an error",async()=>{const n=new Error("error");l.mapTransactionToSubset.mockReturnValueOnce((0,u.Left)(n)),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const t=new p.BuildTransactionContextTask(o,d,i);await expect(t.run()).rejects.toThrow(n)}),it("should exclude error contexts from the result",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.ERROR,error:new Error("error")},{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.ERROR,error:new Error("error")},{type:a.ClearSignContextType.NFT,payload:"payload-2"}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};l.mapTransactionToSubset.mockReturnValueOnce((0,u.Right)(s)),r.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const c=await new p.BuildTransactionContextTask(o,d,i).run();expect(c).toEqual({clearSignContexts:[t[1],t[3]],serializedTransaction:n,chainId:1,transactionType:0,web3Check:null})}),it("should exclude generic-parser contexts from the result on old apps",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"transaction_info",certificate:C},{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:a.ClearSignContextType.NFT,payload:"payload-2"},{type:a.ClearSignContextType.ENUM,payload:"enum",id:1,value:2,certificate:C}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};l.mapTransactionToSubset.mockReturnValueOnce((0,u.Right)(s)),r.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const c=await new p.BuildTransactionContextTask(o,d,i).run();expect(c).toEqual({clearSignContexts:[t[1],t[3]],serializedTransaction:n,chainId:1,transactionType:0,web3Check:null})}),it("should exclude generic-parser contexts from the result if no transaction_info was found",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.ENUM,payload:"enum",id:1,value:2},{type:a.ClearSignContextType.NFT,payload:"payload-2"}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};l.mapTransactionToSubset.mockReturnValueOnce((0,u.Right)(s)),r.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const c=await new p.BuildTransactionContextTask(o,d,i).run();expect(c).toEqual({clearSignContexts:[t[1],t[3]],serializedTransaction:n,chainId:1,transactionType:0,web3Check:null})}),it("should exclude legacy contexts from the result for generic-parser transactions",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:C},{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"payload-3"},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"},{type:a.ClearSignContextType.ENUM,payload:"payload-5",id:1,value:2,certificate:C}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};l.mapTransactionToSubset.mockReturnValueOnce((0,u.Right)(s)),r.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const c=await new p.BuildTransactionContextTask(o,d,i).run();expect(c).toEqual({clearSignContexts:{transactionInfo:"payload-2",transactionInfoCertificate:C,transactionFields:[t[3]],transactionEnums:[t[4]]},serializedTransaction:n,chainId:1,transactionType:2,web3Check:null})}),it("should exclude generic-parser contexts with a nano s device",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:C},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:a.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:C}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};l.mapTransactionToSubset.mockReturnValueOnce((0,u.Right)(s)),r.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:e.DeviceModelId.NANO_S,isSecureConnectionAllowed:!1});const c=await new p.BuildTransactionContextTask(o,d,i).run();expect(c).toEqual({clearSignContexts:[t[0]],serializedTransaction:n,chainId:1,transactionType:2,web3Check:null})}),it("should exclude generic-parser contexts with an old app version",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:C},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:a.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:C}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};l.mapTransactionToSubset.mockReturnValueOnce((0,u.Right)(s)),r.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const c=await new p.BuildTransactionContextTask(o,d,i).run();expect(c).toEqual({clearSignContexts:[t[0]],serializedTransaction:n,chainId:1,transactionType:2,web3Check:null})}),it("should exclude generic-parser contexts with a non ready device",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:C},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:a.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:C}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};l.mapTransactionToSubset.mockReturnValueOnce((0,u.Right)(s)),r.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.Connected,deviceStatus:e.DeviceStatus.NOT_CONNECTED,deviceModelId:e.DeviceModelId.FLEX});const c=await new p.BuildTransactionContextTask(o,d,i).run();expect(c).toEqual({clearSignContexts:[t[0]],serializedTransaction:n,chainId:1,transactionType:2,web3Check:null})}),it("should return an error if the transaction info certificate is missing",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:a.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};l.mapTransactionToSubset.mockReturnValueOnce((0,u.Right)(s)),r.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const c=new p.BuildTransactionContextTask(o,d,i);await expect(c.run()).rejects.toThrow("Transaction info certificate is missing")})});
1
+ "use strict";var n=require("@ledgerhq/context-module"),t=require("@ledgerhq/device-management-kit"),S=require("ethers"),d=require("../../../api/model/ClearSigningType"),y=require("../../app-binder/device-action/__test-utils__/makeInternalApi"),s=require("./BuildTransactionContextTask"),g=require("./GetWeb3CheckTask");describe("BuildTransactionContextTask",()=>{const l={getContext:vi.fn(),getContexts:vi.fn(),getTypedDataFilters:vi.fn(),getWeb3Checks:vi.fn(),getSolanaContext:vi.fn()},x={domain:"domain-name.eth"},C=(0,t.hexaStringToBuffer)(S.Transaction.from({chainId:1n,nonce:0,data:"0x"}).unsignedSerialized),r={keyUsageNumber:1,payload:new Uint8Array([1,2,3])};let c;const a=(0,y.makeDeviceActionInternalApiMock)(),i=vi.fn();function u(e){return{blindSigningEnabled:!1,web3ChecksEnabled:e,web3ChecksOptIn:!1,version:"1.13.0"}}beforeEach(()=>{vi.resetAllMocks(),a.sendCommand.mockResolvedValue((0,t.CommandResultFactory)({data:{challenge:"challenge"}})),i.mockReturnValue({run:async()=>Promise.resolve({web3Check:null})}),c={contextModule:l,subset:{chainId:1,to:void 0,data:"0x",selector:"0x"},transaction:C,options:x,appConfig:u(!1),derivationPath:"44'/60'/0'/0/0"}}),it("should init with a default GetWeb3CheckTaskFactory",()=>{const e=new s.BuildTransactionContextTask(a,c);expect(e.getWeb3ChecksFactory).toBeDefined(),expect(e.getWeb3ChecksFactory(a,{contextModule:c.contextModule,derivationPath:c.derivationPath,subset:c.subset,transaction:c.transaction})).toBeInstanceOf(g.GetWeb3CheckTask)}),it("should build the transaction context without clear sign contexts",async()=>{const e=[],o=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new s.BuildTransactionContextTask(a,{...c,appConfig:u(!0)},i).run();expect(p).toEqual({clearSignContexts:e,clearSignContextsOptional:o,clearSigningType:d.ClearSigningType.BASIC})}),it("should build the transaction context with web3checks",async()=>{const e=[],o=[],p="web3Check";i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:p})}),l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const E=await new s.BuildTransactionContextTask(a,{...c,appConfig:u(!0)},i).run();expect(E).toEqual({clearSignContexts:[p,...e],clearSignContextsOptional:o,clearSigningType:d.ClearSigningType.BASIC})}),it("should build the transaction context with web3checks and generic-parser clear sign contexts",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}],o="web3Check";i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:o})}),l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new s.BuildTransactionContextTask(a,{...c,appConfig:u(!0)},i).run();expect(p).toEqual({clearSignContexts:[e[0],e[1],e[3],o],clearSignContextsOptional:[e[2]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should build the transaction context with web3checks and generic-parser clear sign contexts in the correct order",async()=>{const e=[{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:r}],o="web3Check";i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:o})}),l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new s.BuildTransactionContextTask(a,{...c,appConfig:u(!0)},i).run();expect(p).toEqual({clearSignContexts:[e[3],e[1],e[2],o],clearSignContextsOptional:[e[0]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should build the transaction context with clear sign contexts",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.NFT,payload:"payload-2"}],o="web3Check";i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:o})}),l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new s.BuildTransactionContextTask(a,c,i).run();expect(p).toEqual({clearSignContexts:e,clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should build the transaction context with generic-parser context",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildTransactionContextTask(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0],e[1],e[3]],clearSignContextsOptional:[e[2]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should build the transaction context with proxy delegate call context",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:r},{type:n.ClearSignContextType.PROXY_DELEGATE_CALL,payload:"payload-2"}],o=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new s.BuildTransactionContextTask(a,c,i).run();expect(p).toEqual({clearSignContexts:[e[1],e[0]],clearSignContextsOptional:o,clearSigningType:d.ClearSigningType.EIP7730})}),it("should call the web3checks factory with correct parameters",async()=>{const e=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),await new s.BuildTransactionContextTask(a,{...c,appConfig:u(!0)},i).run(),expect(i).toHaveBeenCalledWith(a,{contextModule:l,derivationPath:"44'/60'/0'/0/0",subset:c.subset,transaction:C})}),it("should call the context module with the correct parameters",async()=>{const e=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),await new s.BuildTransactionContextTask(a,c,i).run(),expect(l.getContexts).toHaveBeenCalledWith({deviceModelId:t.DeviceModelId.FLEX,challenge:"challenge",domain:"domain-name.eth",...c.subset})}),it("should call the context module without challenge for Nano S",async()=>{const e=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.NANO_S,isSecureConnectionAllowed:!1}),await new s.BuildTransactionContextTask(a,c,i).run(),expect(l.getContexts).toHaveBeenCalledWith({deviceModelId:t.DeviceModelId.NANO_S,domain:"domain-name.eth",...c.subset})}),it("should call the context module without context on error",async()=>{const e=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),a.sendCommand.mockResolvedValueOnce((0,t.CommandResultFactory)({error:new t.UnknownDeviceExchangeError})),await new s.BuildTransactionContextTask(a,c,i).run(),expect(l.getContexts).toHaveBeenCalledWith({deviceModelId:t.DeviceModelId.FLEX,challenge:void 0,domain:"domain-name.eth",...c.subset})}),it("should exclude error contexts from the result",async()=>{const e=[{type:n.ClearSignContextType.ERROR,error:new Error("error")},{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.ERROR,error:new Error("error")},{type:n.ClearSignContextType.NFT,payload:"payload-2"}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildTransactionContextTask(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts from the result on old apps",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"transaction_info",certificate:r},{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:n.ClearSignContextType.NFT,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"enum",id:1,value:2,certificate:r}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildTransactionContextTask(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts from the result if no transaction_info was found",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.ENUM,payload:"enum",id:1,value:2},{type:n.ClearSignContextType.NFT,payload:"payload-2"}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildTransactionContextTask(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude legacy contexts from the result for generic-parser transactions",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.EXTERNAL_PLUGIN,payload:"payload-3"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"},{type:n.ClearSignContextType.ENUM,payload:"payload-5",id:1,value:2,certificate:r}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildTransactionContextTask(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[e[4]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should exclude generic-parser contexts with a nano s device",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:n.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:r}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:t.DeviceModelId.NANO_S,isSecureConnectionAllowed:!1});const o=await new s.BuildTransactionContextTask(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts with an old app version",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:n.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:r}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildTransactionContextTask(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts with a non ready device",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:n.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:r}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.Connected,deviceStatus:t.DeviceStatus.NOT_CONNECTED,deviceModelId:t.DeviceModelId.FLEX});const o=await new s.BuildTransactionContextTask(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should return no clear sign context if the transaction info certificate is missing",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.17.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildTransactionContextTask(a,c,i).run();expect(o).toEqual({clearSignContexts:[],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})})});
2
2
  //# sourceMappingURL=BuildTransactionContextTask.test.js.map