@ledgerhq/context-module 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (300) hide show
  1. package/lib/cjs/package.json +8 -7
  2. package/lib/cjs/src/ContextModuleBuilder.test.js +1 -1
  3. package/lib/cjs/src/ContextModuleBuilder.test.js.map +2 -2
  4. package/lib/cjs/src/DefaultContextModule.js +1 -1
  5. package/lib/cjs/src/DefaultContextModule.js.map +3 -3
  6. package/lib/cjs/src/DefaultContextModule.test.js +1 -1
  7. package/lib/cjs/src/DefaultContextModule.test.js.map +2 -2
  8. package/lib/cjs/src/di.js +1 -1
  9. package/lib/cjs/src/di.js.map +3 -3
  10. package/lib/cjs/src/external-plugin/data/HttpExternalPluginDataSource.test.js +1 -1
  11. package/lib/cjs/src/external-plugin/data/HttpExternalPluginDataSource.test.js.map +2 -2
  12. package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.test.js +1 -1
  13. package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.test.js.map +2 -2
  14. package/lib/cjs/src/index.js +1 -1
  15. package/lib/cjs/src/index.js.map +2 -2
  16. package/lib/cjs/src/nft/data/HttpNftDataSource.test.js +1 -1
  17. package/lib/cjs/src/nft/data/HttpNftDataSource.test.js.map +2 -2
  18. package/lib/cjs/src/nft/domain/NftContextLoader.test.js +1 -1
  19. package/lib/cjs/src/nft/domain/NftContextLoader.test.js.map +2 -2
  20. package/lib/cjs/src/pki/data/HttpPkiCertificateDataSource.js +2 -0
  21. package/lib/cjs/src/pki/data/HttpPkiCertificateDataSource.js.map +7 -0
  22. package/lib/cjs/src/pki/data/HttpPkiCertificateDataSource.test.js +2 -0
  23. package/lib/cjs/src/pki/data/HttpPkiCertificateDataSource.test.js.map +7 -0
  24. package/lib/cjs/src/pki/data/PkiCertificateDataSource.js +2 -0
  25. package/lib/cjs/src/pki/data/PkiCertificateDataSource.js.map +7 -0
  26. package/lib/cjs/src/pki/data/pkiDataSourceTypes.js +2 -0
  27. package/lib/cjs/src/pki/data/pkiDataSourceTypes.js.map +7 -0
  28. package/lib/cjs/src/pki/di/pkiModuleFactory.js +2 -0
  29. package/lib/cjs/src/pki/di/pkiModuleFactory.js.map +7 -0
  30. package/lib/cjs/src/pki/di/pkiTypes.js +2 -0
  31. package/lib/cjs/src/pki/di/pkiTypes.js.map +7 -0
  32. package/lib/cjs/src/pki/domain/DefaultPkiCertificateLoader.js +2 -0
  33. package/lib/cjs/src/pki/domain/DefaultPkiCertificateLoader.js.map +7 -0
  34. package/lib/cjs/src/pki/domain/DefaultPkiCertificateLoader.test.js +2 -0
  35. package/lib/cjs/src/pki/domain/DefaultPkiCertificateLoader.test.js.map +7 -0
  36. package/lib/cjs/src/pki/domain/PkiCertificateLoader.js +2 -0
  37. package/lib/cjs/src/pki/domain/PkiCertificateLoader.js.map +7 -0
  38. package/lib/cjs/src/pki/model/KeyId.js +2 -0
  39. package/lib/cjs/src/pki/model/KeyId.js.map +7 -0
  40. package/lib/cjs/src/pki/model/KeyUsage.js +2 -0
  41. package/lib/cjs/src/pki/model/KeyUsage.js.map +7 -0
  42. package/lib/cjs/src/pki/model/PkiCertificate.js +2 -0
  43. package/lib/cjs/src/pki/model/PkiCertificate.js.map +7 -0
  44. package/lib/cjs/src/pki/model/PkiCertificateInfo.js +2 -0
  45. package/lib/cjs/src/pki/model/PkiCertificateInfo.js.map +7 -0
  46. package/lib/cjs/src/shared/model/ClearSignContext.js +1 -1
  47. package/lib/cjs/src/shared/model/ClearSignContext.js.map +2 -2
  48. package/lib/cjs/src/shared/model/GenericPath.js +1 -1
  49. package/lib/cjs/src/shared/model/GenericPath.js.map +1 -1
  50. package/lib/cjs/src/shared/model/SignatureTags.js +2 -0
  51. package/lib/cjs/src/shared/model/SignatureTags.js.map +7 -0
  52. package/lib/cjs/src/shared/model/TransactionContext.js +1 -1
  53. package/lib/cjs/src/shared/model/TransactionContext.js.map +1 -1
  54. package/lib/cjs/src/shared/utils/HexStringUtils.js +1 -1
  55. package/lib/cjs/src/shared/utils/HexStringUtils.js.map +3 -3
  56. package/lib/cjs/src/shared/utils/HexStringUtils.test.js +2 -0
  57. package/lib/cjs/src/shared/utils/HexStringUtils.test.js.map +7 -0
  58. package/lib/cjs/src/shared/utils/KeyUsageMapper.js +2 -0
  59. package/lib/cjs/src/shared/utils/KeyUsageMapper.js.map +7 -0
  60. package/lib/cjs/src/shared/utils/KeyUsageMapper.test.js +2 -0
  61. package/lib/cjs/src/shared/utils/KeyUsageMapper.test.js.map +7 -0
  62. package/lib/cjs/src/token/data/HttpTokenDataSource.test.js +1 -1
  63. package/lib/cjs/src/token/data/HttpTokenDataSource.test.js.map +2 -2
  64. package/lib/cjs/src/token/domain/TokenContextLoader.test.js +1 -1
  65. package/lib/cjs/src/token/domain/TokenContextLoader.test.js.map +2 -2
  66. package/lib/cjs/src/transaction/data/CalldataDto.js +1 -1
  67. package/lib/cjs/src/transaction/data/CalldataDto.js.map +1 -1
  68. package/lib/cjs/src/transaction/data/HttpTransactionDataSource.js +1 -1
  69. package/lib/cjs/src/transaction/data/HttpTransactionDataSource.js.map +3 -3
  70. package/lib/cjs/src/transaction/data/HttpTransactionDataSource.test.js +1 -1
  71. package/lib/cjs/src/transaction/data/HttpTransactionDataSource.test.js.map +3 -3
  72. package/lib/cjs/src/transaction/data/TransactionDataSource.js +1 -1
  73. package/lib/cjs/src/transaction/data/TransactionDataSource.js.map +1 -1
  74. package/lib/cjs/src/transaction/domain/TransactionContextLoader.js +1 -1
  75. package/lib/cjs/src/transaction/domain/TransactionContextLoader.js.map +2 -2
  76. package/lib/cjs/src/transaction/domain/TransactionContextLoader.test.js +1 -1
  77. package/lib/cjs/src/transaction/domain/TransactionContextLoader.test.js.map +2 -2
  78. package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.test.js +1 -1
  79. package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.test.js.map +2 -2
  80. package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.js +1 -1
  81. package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.js.map +2 -2
  82. package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.test.js +1 -1
  83. package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.test.js.map +2 -2
  84. package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.test.js +1 -1
  85. package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.test.js.map +2 -2
  86. package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.test.js +1 -1
  87. package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.test.js.map +2 -2
  88. package/lib/cjs/src/uniswap/constants/plugin.js +2 -0
  89. package/lib/cjs/src/uniswap/constants/plugin.js.map +7 -0
  90. package/lib/cjs/src/uniswap/constants/uniswap.js +2 -0
  91. package/lib/cjs/src/uniswap/constants/uniswap.js.map +7 -0
  92. package/lib/cjs/src/uniswap/constants/weth.js +2 -0
  93. package/lib/cjs/src/uniswap/constants/weth.js.map +7 -0
  94. package/lib/cjs/src/uniswap/data/AbiDecoderDataSource.js +2 -0
  95. package/lib/cjs/src/uniswap/data/AbiDecoderDataSource.js.map +7 -0
  96. package/lib/cjs/src/uniswap/data/CommandDecoderDataSource.js +2 -0
  97. package/lib/cjs/src/uniswap/data/CommandDecoderDataSource.js.map +7 -0
  98. package/lib/cjs/src/uniswap/data/DefaultCommandDecoderDataSource.js +2 -0
  99. package/lib/cjs/src/uniswap/data/DefaultCommandDecoderDataSource.js.map +7 -0
  100. package/lib/cjs/src/uniswap/data/DefaultCommandDecoderDataSource.test.js +2 -0
  101. package/lib/cjs/src/uniswap/data/DefaultCommandDecoderDataSource.test.js.map +7 -0
  102. package/lib/cjs/src/uniswap/data/EthersAbiDecoderDataSource.js +2 -0
  103. package/lib/cjs/src/uniswap/data/EthersAbiDecoderDataSource.js.map +7 -0
  104. package/lib/cjs/src/uniswap/data/EthersAbiDecoderDataSource.test.js +2 -0
  105. package/lib/cjs/src/uniswap/data/EthersAbiDecoderDataSource.test.js.map +7 -0
  106. package/lib/cjs/src/uniswap/di/uniswapModuleFactory.js +2 -0
  107. package/lib/cjs/src/uniswap/di/uniswapModuleFactory.js.map +7 -0
  108. package/lib/cjs/src/uniswap/di/uniswapTypes.js +2 -0
  109. package/lib/cjs/src/uniswap/di/uniswapTypes.js.map +7 -0
  110. package/lib/cjs/src/uniswap/domain/UniswapContextLoader.js +2 -0
  111. package/lib/cjs/src/uniswap/domain/UniswapContextLoader.js.map +7 -0
  112. package/lib/cjs/src/uniswap/domain/UniswapContextLoader.test.js +2 -0
  113. package/lib/cjs/src/uniswap/domain/UniswapContextLoader.test.js.map +7 -0
  114. package/lib/esm/package.json +8 -7
  115. package/lib/esm/src/ContextModuleBuilder.test.js +1 -1
  116. package/lib/esm/src/ContextModuleBuilder.test.js.map +2 -2
  117. package/lib/esm/src/DefaultContextModule.js +1 -1
  118. package/lib/esm/src/DefaultContextModule.js.map +3 -3
  119. package/lib/esm/src/DefaultContextModule.test.js +1 -1
  120. package/lib/esm/src/DefaultContextModule.test.js.map +2 -2
  121. package/lib/esm/src/di.js +1 -1
  122. package/lib/esm/src/di.js.map +3 -3
  123. package/lib/esm/src/external-plugin/data/HttpExternalPluginDataSource.test.js +1 -1
  124. package/lib/esm/src/external-plugin/data/HttpExternalPluginDataSource.test.js.map +2 -2
  125. package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.test.js +1 -1
  126. package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.test.js.map +2 -2
  127. package/lib/esm/src/index.js +1 -1
  128. package/lib/esm/src/index.js.map +2 -2
  129. package/lib/esm/src/nft/data/HttpNftDataSource.test.js +1 -1
  130. package/lib/esm/src/nft/data/HttpNftDataSource.test.js.map +2 -2
  131. package/lib/esm/src/nft/domain/NftContextLoader.test.js +1 -1
  132. package/lib/esm/src/nft/domain/NftContextLoader.test.js.map +2 -2
  133. package/lib/esm/src/pki/data/HttpPkiCertificateDataSource.js +2 -0
  134. package/lib/esm/src/pki/data/HttpPkiCertificateDataSource.js.map +7 -0
  135. package/lib/esm/src/pki/data/HttpPkiCertificateDataSource.test.js +2 -0
  136. package/lib/esm/src/pki/data/HttpPkiCertificateDataSource.test.js.map +7 -0
  137. package/lib/esm/src/pki/data/PkiCertificateDataSource.js +1 -0
  138. package/lib/esm/src/pki/data/PkiCertificateDataSource.js.map +7 -0
  139. package/lib/esm/src/pki/data/pkiDataSourceTypes.js +1 -0
  140. package/lib/esm/src/pki/data/pkiDataSourceTypes.js.map +7 -0
  141. package/lib/esm/src/pki/di/pkiModuleFactory.js +2 -0
  142. package/lib/esm/src/pki/di/pkiModuleFactory.js.map +7 -0
  143. package/lib/esm/src/pki/di/pkiTypes.js +2 -0
  144. package/lib/esm/src/pki/di/pkiTypes.js.map +7 -0
  145. package/lib/esm/src/pki/domain/DefaultPkiCertificateLoader.js +2 -0
  146. package/lib/esm/src/pki/domain/DefaultPkiCertificateLoader.js.map +7 -0
  147. package/lib/esm/src/pki/domain/DefaultPkiCertificateLoader.test.js +2 -0
  148. package/lib/esm/src/pki/domain/DefaultPkiCertificateLoader.test.js.map +7 -0
  149. package/lib/esm/src/pki/domain/PkiCertificateLoader.js +1 -0
  150. package/lib/esm/src/pki/domain/PkiCertificateLoader.js.map +7 -0
  151. package/lib/esm/src/pki/model/KeyId.js +2 -0
  152. package/lib/esm/src/pki/model/KeyId.js.map +7 -0
  153. package/lib/esm/src/pki/model/KeyUsage.js +2 -0
  154. package/lib/esm/src/pki/model/KeyUsage.js.map +7 -0
  155. package/lib/esm/src/pki/model/PkiCertificate.js +1 -0
  156. package/lib/esm/src/pki/model/PkiCertificate.js.map +7 -0
  157. package/lib/esm/src/pki/model/PkiCertificateInfo.js +1 -0
  158. package/lib/esm/src/pki/model/PkiCertificateInfo.js.map +7 -0
  159. package/lib/esm/src/shared/model/ClearSignContext.js +1 -1
  160. package/lib/esm/src/shared/model/ClearSignContext.js.map +2 -2
  161. package/lib/esm/src/shared/model/GenericPath.js.map +1 -1
  162. package/lib/esm/src/shared/model/SignatureTags.js +2 -0
  163. package/lib/esm/src/shared/model/SignatureTags.js.map +7 -0
  164. package/lib/esm/src/shared/utils/HexStringUtils.js +1 -1
  165. package/lib/esm/src/shared/utils/HexStringUtils.js.map +3 -3
  166. package/lib/esm/src/shared/utils/HexStringUtils.test.js +2 -0
  167. package/lib/esm/src/shared/utils/HexStringUtils.test.js.map +7 -0
  168. package/lib/esm/src/shared/utils/KeyUsageMapper.js +2 -0
  169. package/lib/esm/src/shared/utils/KeyUsageMapper.js.map +7 -0
  170. package/lib/esm/src/shared/utils/KeyUsageMapper.test.js +2 -0
  171. package/lib/esm/src/shared/utils/KeyUsageMapper.test.js.map +7 -0
  172. package/lib/esm/src/token/data/HttpTokenDataSource.test.js +1 -1
  173. package/lib/esm/src/token/data/HttpTokenDataSource.test.js.map +2 -2
  174. package/lib/esm/src/token/domain/TokenContextLoader.test.js +1 -1
  175. package/lib/esm/src/token/domain/TokenContextLoader.test.js.map +2 -2
  176. package/lib/esm/src/transaction/data/HttpTransactionDataSource.js +1 -1
  177. package/lib/esm/src/transaction/data/HttpTransactionDataSource.js.map +3 -3
  178. package/lib/esm/src/transaction/data/HttpTransactionDataSource.test.js +1 -1
  179. package/lib/esm/src/transaction/data/HttpTransactionDataSource.test.js.map +3 -3
  180. package/lib/esm/src/transaction/domain/TransactionContextLoader.js +1 -1
  181. package/lib/esm/src/transaction/domain/TransactionContextLoader.js.map +2 -2
  182. package/lib/esm/src/transaction/domain/TransactionContextLoader.test.js +1 -1
  183. package/lib/esm/src/transaction/domain/TransactionContextLoader.test.js.map +2 -2
  184. package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.test.js +1 -1
  185. package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.test.js.map +2 -2
  186. package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.js +1 -1
  187. package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.js.map +2 -2
  188. package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.test.js +1 -1
  189. package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.test.js.map +2 -2
  190. package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.test.js +1 -1
  191. package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.test.js.map +2 -2
  192. package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.test.js +1 -1
  193. package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.test.js.map +2 -2
  194. package/lib/esm/src/uniswap/constants/plugin.js +2 -0
  195. package/lib/esm/src/uniswap/constants/plugin.js.map +7 -0
  196. package/lib/esm/src/uniswap/constants/uniswap.js +2 -0
  197. package/lib/esm/src/uniswap/constants/uniswap.js.map +7 -0
  198. package/lib/esm/src/uniswap/constants/weth.js +2 -0
  199. package/lib/esm/src/uniswap/constants/weth.js.map +7 -0
  200. package/lib/esm/src/uniswap/data/AbiDecoderDataSource.js +1 -0
  201. package/lib/esm/src/uniswap/data/AbiDecoderDataSource.js.map +7 -0
  202. package/lib/esm/src/uniswap/data/CommandDecoderDataSource.js +1 -0
  203. package/lib/esm/src/uniswap/data/CommandDecoderDataSource.js.map +7 -0
  204. package/lib/esm/src/uniswap/data/DefaultCommandDecoderDataSource.js +2 -0
  205. package/lib/esm/src/uniswap/data/DefaultCommandDecoderDataSource.js.map +7 -0
  206. package/lib/esm/src/uniswap/data/DefaultCommandDecoderDataSource.test.js +2 -0
  207. package/lib/esm/src/uniswap/data/DefaultCommandDecoderDataSource.test.js.map +7 -0
  208. package/lib/esm/src/uniswap/data/EthersAbiDecoderDataSource.js +2 -0
  209. package/lib/esm/src/uniswap/data/EthersAbiDecoderDataSource.js.map +7 -0
  210. package/lib/esm/src/uniswap/data/EthersAbiDecoderDataSource.test.js +2 -0
  211. package/lib/esm/src/uniswap/data/EthersAbiDecoderDataSource.test.js.map +7 -0
  212. package/lib/esm/src/uniswap/di/uniswapModuleFactory.js +2 -0
  213. package/lib/esm/src/uniswap/di/uniswapModuleFactory.js.map +7 -0
  214. package/lib/esm/src/uniswap/di/uniswapTypes.js +2 -0
  215. package/lib/esm/src/uniswap/di/uniswapTypes.js.map +7 -0
  216. package/lib/esm/src/uniswap/domain/UniswapContextLoader.js +2 -0
  217. package/lib/esm/src/uniswap/domain/UniswapContextLoader.js.map +7 -0
  218. package/lib/esm/src/uniswap/domain/UniswapContextLoader.test.js +2 -0
  219. package/lib/esm/src/uniswap/domain/UniswapContextLoader.test.js.map +7 -0
  220. package/lib/types/src/DefaultContextModule.d.ts.map +1 -1
  221. package/lib/types/src/di.d.ts.map +1 -1
  222. package/lib/types/src/index.d.ts +5 -0
  223. package/lib/types/src/index.d.ts.map +1 -1
  224. package/lib/types/src/pki/data/HttpPkiCertificateDataSource.d.ts +12 -0
  225. package/lib/types/src/pki/data/HttpPkiCertificateDataSource.d.ts.map +1 -0
  226. package/lib/types/src/pki/data/HttpPkiCertificateDataSource.test.d.ts +2 -0
  227. package/lib/types/src/pki/data/HttpPkiCertificateDataSource.test.d.ts.map +1 -0
  228. package/lib/types/src/pki/data/PkiCertificateDataSource.d.ts +7 -0
  229. package/lib/types/src/pki/data/PkiCertificateDataSource.d.ts.map +1 -0
  230. package/lib/types/src/pki/data/pkiDataSourceTypes.d.ts +23 -0
  231. package/lib/types/src/pki/data/pkiDataSourceTypes.d.ts.map +1 -0
  232. package/lib/types/src/pki/di/pkiModuleFactory.d.ts +3 -0
  233. package/lib/types/src/pki/di/pkiModuleFactory.d.ts.map +1 -0
  234. package/lib/types/src/pki/di/pkiTypes.d.ts +5 -0
  235. package/lib/types/src/pki/di/pkiTypes.d.ts.map +1 -0
  236. package/lib/types/src/pki/domain/DefaultPkiCertificateLoader.d.ts +10 -0
  237. package/lib/types/src/pki/domain/DefaultPkiCertificateLoader.d.ts.map +1 -0
  238. package/lib/types/src/pki/domain/DefaultPkiCertificateLoader.test.d.ts +2 -0
  239. package/lib/types/src/pki/domain/DefaultPkiCertificateLoader.test.d.ts.map +1 -0
  240. package/lib/types/src/pki/domain/PkiCertificateLoader.d.ts +6 -0
  241. package/lib/types/src/pki/domain/PkiCertificateLoader.d.ts.map +1 -0
  242. package/lib/types/src/pki/model/KeyId.d.ts +14 -0
  243. package/lib/types/src/pki/model/KeyId.d.ts.map +1 -0
  244. package/lib/types/src/pki/model/KeyUsage.d.ts +15 -0
  245. package/lib/types/src/pki/model/KeyUsage.d.ts.map +1 -0
  246. package/lib/types/src/pki/model/PkiCertificate.d.ts +5 -0
  247. package/lib/types/src/pki/model/PkiCertificate.d.ts.map +1 -0
  248. package/lib/types/src/pki/model/PkiCertificateInfo.d.ts +7 -0
  249. package/lib/types/src/pki/model/PkiCertificateInfo.d.ts.map +1 -0
  250. package/lib/types/src/shared/model/ClearSignContext.d.ts +24 -13
  251. package/lib/types/src/shared/model/ClearSignContext.d.ts.map +1 -1
  252. package/lib/types/src/shared/model/GenericPath.d.ts +2 -2
  253. package/lib/types/src/shared/model/GenericPath.d.ts.map +1 -1
  254. package/lib/types/src/shared/model/SignatureTags.d.ts +3 -0
  255. package/lib/types/src/shared/model/SignatureTags.d.ts.map +1 -0
  256. package/lib/types/src/shared/model/TransactionContext.d.ts +3 -1
  257. package/lib/types/src/shared/model/TransactionContext.d.ts.map +1 -1
  258. package/lib/types/src/shared/utils/HexStringUtils.d.ts +1 -0
  259. package/lib/types/src/shared/utils/HexStringUtils.d.ts.map +1 -1
  260. package/lib/types/src/shared/utils/HexStringUtils.test.d.ts +2 -0
  261. package/lib/types/src/shared/utils/HexStringUtils.test.d.ts.map +1 -0
  262. package/lib/types/src/shared/utils/KeyUsageMapper.d.ts +6 -0
  263. package/lib/types/src/shared/utils/KeyUsageMapper.d.ts.map +1 -0
  264. package/lib/types/src/shared/utils/KeyUsageMapper.test.d.ts +2 -0
  265. package/lib/types/src/shared/utils/KeyUsageMapper.test.d.ts.map +1 -0
  266. package/lib/types/src/transaction/data/CalldataDto.d.ts +15 -4
  267. package/lib/types/src/transaction/data/CalldataDto.d.ts.map +1 -1
  268. package/lib/types/src/transaction/data/HttpTransactionDataSource.d.ts +8 -4
  269. package/lib/types/src/transaction/data/HttpTransactionDataSource.d.ts.map +1 -1
  270. package/lib/types/src/transaction/data/TransactionDataSource.d.ts +2 -1
  271. package/lib/types/src/transaction/data/TransactionDataSource.d.ts.map +1 -1
  272. package/lib/types/src/transaction/domain/TransactionContextLoader.d.ts.map +1 -1
  273. package/lib/types/src/uniswap/constants/plugin.d.ts +3 -0
  274. package/lib/types/src/uniswap/constants/plugin.d.ts.map +1 -0
  275. package/lib/types/src/uniswap/constants/uniswap.d.ts +21 -0
  276. package/lib/types/src/uniswap/constants/uniswap.d.ts.map +1 -0
  277. package/lib/types/src/uniswap/constants/weth.d.ts +20 -0
  278. package/lib/types/src/uniswap/constants/weth.d.ts.map +1 -0
  279. package/lib/types/src/uniswap/data/AbiDecoderDataSource.d.ts +5 -0
  280. package/lib/types/src/uniswap/data/AbiDecoderDataSource.d.ts.map +1 -0
  281. package/lib/types/src/uniswap/data/CommandDecoderDataSource.d.ts +6 -0
  282. package/lib/types/src/uniswap/data/CommandDecoderDataSource.d.ts.map +1 -0
  283. package/lib/types/src/uniswap/data/DefaultCommandDecoderDataSource.d.ts +14 -0
  284. package/lib/types/src/uniswap/data/DefaultCommandDecoderDataSource.d.ts.map +1 -0
  285. package/lib/types/src/uniswap/data/DefaultCommandDecoderDataSource.test.d.ts +2 -0
  286. package/lib/types/src/uniswap/data/DefaultCommandDecoderDataSource.test.d.ts.map +1 -0
  287. package/lib/types/src/uniswap/data/EthersAbiDecoderDataSource.d.ts +5 -0
  288. package/lib/types/src/uniswap/data/EthersAbiDecoderDataSource.d.ts.map +1 -0
  289. package/lib/types/src/uniswap/data/EthersAbiDecoderDataSource.test.d.ts +2 -0
  290. package/lib/types/src/uniswap/data/EthersAbiDecoderDataSource.test.d.ts.map +1 -0
  291. package/lib/types/src/uniswap/di/uniswapModuleFactory.d.ts +3 -0
  292. package/lib/types/src/uniswap/di/uniswapModuleFactory.d.ts.map +1 -0
  293. package/lib/types/src/uniswap/di/uniswapTypes.d.ts +6 -0
  294. package/lib/types/src/uniswap/di/uniswapTypes.d.ts.map +1 -0
  295. package/lib/types/src/uniswap/domain/UniswapContextLoader.d.ts +105 -0
  296. package/lib/types/src/uniswap/domain/UniswapContextLoader.d.ts.map +1 -0
  297. package/lib/types/src/uniswap/domain/UniswapContextLoader.test.d.ts +2 -0
  298. package/lib/types/src/uniswap/domain/UniswapContextLoader.test.d.ts.map +1 -0
  299. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  300. package/package.json +10 -9
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/uniswap/data/DefaultCommandDecoderDataSource.ts"],
4
+ "sourcesContent": ["import { type HexaString, isHexaString } from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport { UniswapSupportedCommand } from \"@/uniswap/constants/uniswap\";\nimport {\n WETH_ADDRESS_BY_CHAIN_ID,\n WETHSupportedChainId,\n WETHSupportedChainIds,\n} from \"@/uniswap/constants/weth\";\nimport { uniswapTypes } from \"@/uniswap/di/uniswapTypes\";\n\nimport { type AbiDecoderDataSource } from \"./AbiDecoderDataSource\";\n\nconst ADDRESS_LENGTH = 20 * 2;\nconst FEE_LENGTH = 3 * 2;\n\n@injectable()\nexport class DefaultCommandDecoderDataSource {\n constructor(\n @inject(uniswapTypes.AbiDecoderDataSource)\n private abiDecoder: AbiDecoderDataSource,\n ) {}\n\n decode(\n command: UniswapSupportedCommand,\n input: HexaString,\n chainId: number,\n ): HexaString[] {\n switch (command) {\n case UniswapSupportedCommand.V2_SWAP_EXACT_IN:\n return this._decodeSwapV2(input);\n case UniswapSupportedCommand.V2_SWAP_EXACT_OUT:\n return this._decodeSwapV2(input);\n case UniswapSupportedCommand.V3_SWAP_EXACT_IN:\n return this._decodeSwapV3(input);\n case UniswapSupportedCommand.V3_SWAP_EXACT_OUT:\n return this._decodeSwapV3(input);\n case UniswapSupportedCommand.WRAP_ETH:\n return this._decodeWrappedEth(input, chainId);\n case UniswapSupportedCommand.UNWRAP_ETH:\n return this._decodeWrappedEth(input, chainId);\n case UniswapSupportedCommand.SWEEP:\n return this._decodeSweep(input);\n case UniswapSupportedCommand.PERMIT2_PERMIT:\n case UniswapSupportedCommand.PERMIT2_TRANSFER_FROM:\n case UniswapSupportedCommand.PERMIT2_PERMIT_BATCH:\n case UniswapSupportedCommand.PERMIT2_TRANSFER_FROM_BATCH:\n case UniswapSupportedCommand.PAY_PORTION:\n return [];\n default:\n return [];\n }\n }\n\n private _decodeSwapV2(input: HexaString): HexaString[] {\n const [, , , addresses] = this.abiDecoder.decode(\n [\"address\", \"uint256\", \"uint256\", \"address[]\", \"bool\"],\n input,\n );\n\n if (!Array.isArray(addresses) || !addresses.every(isHexaString)) {\n return [];\n }\n\n return addresses.map(\n (address: HexaString) => address.toLowerCase() as HexaString,\n );\n }\n\n private _decodeSwapV3(input: HexaString): HexaString[] {\n const [, , , path] = this.abiDecoder.decode(\n [\"address\", \"uint256\", \"uint256\", \"bytes\", \"bool\"],\n input,\n );\n // Path is at least 43 bytes long for 2 times 20B addresses + 3B fee in between\n // Example: 0x -> 20B address -> 3B fee -> 20B address -> 3B fee -> 20B address\n if (\n typeof path !== \"string\" ||\n !isHexaString(path) ||\n path.length < 2 + ADDRESS_LENGTH * 2 + FEE_LENGTH\n ) {\n return [];\n }\n\n // Get all the addresses, skip the 0x prefix\n const tokens: string[] = [];\n for (let i = 2; i < path.length; i += ADDRESS_LENGTH + FEE_LENGTH) {\n tokens.push(path.slice(i, i + ADDRESS_LENGTH));\n }\n\n return tokens\n .map((token) => token.toLowerCase())\n .map((token) => `0x${token}` as HexaString);\n }\n\n private _isSupportedChainId(\n chainId: number,\n ): chainId is WETHSupportedChainId {\n return Object.values(WETHSupportedChainIds).includes(chainId);\n }\n\n private _decodeWrappedEth(_input: HexaString, chainId: number): HexaString[] {\n if (!this._isSupportedChainId(chainId)) {\n return [];\n }\n\n return [WETH_ADDRESS_BY_CHAIN_ID[chainId].toLowerCase() as HexaString];\n }\n\n private _decodeSweep = (input: HexaString): HexaString[] => {\n const [token] = this.abiDecoder.decode(\n [\"address\", \"address\", \"uint256\"],\n input,\n );\n\n if (typeof token !== \"string\" || !isHexaString(token)) {\n return [];\n }\n\n return [token.toLowerCase() as HexaString];\n };\n}\n"],
5
+ "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAA8C,2CAC9CC,EAAmC,qBAEnCC,EAAwC,uCACxCC,EAIO,oCACPC,EAA6B,qCAI7B,MAAMC,EAAiB,GAAK,EACtBC,EAAa,EAAI,EAGhB,IAAMC,EAAN,KAAsC,CAC3C,YAEUC,EACR,CADQ,gBAAAA,CACP,CAEH,OACEC,EACAC,EACAC,EACc,CACd,OAAQF,EAAS,CACf,KAAK,0BAAwB,iBAC3B,OAAO,KAAK,cAAcC,CAAK,EACjC,KAAK,0BAAwB,kBAC3B,OAAO,KAAK,cAAcA,CAAK,EACjC,KAAK,0BAAwB,iBAC3B,OAAO,KAAK,cAAcA,CAAK,EACjC,KAAK,0BAAwB,kBAC3B,OAAO,KAAK,cAAcA,CAAK,EACjC,KAAK,0BAAwB,SAC3B,OAAO,KAAK,kBAAkBA,EAAOC,CAAO,EAC9C,KAAK,0BAAwB,WAC3B,OAAO,KAAK,kBAAkBD,EAAOC,CAAO,EAC9C,KAAK,0BAAwB,MAC3B,OAAO,KAAK,aAAaD,CAAK,EAChC,KAAK,0BAAwB,eAC7B,KAAK,0BAAwB,sBAC7B,KAAK,0BAAwB,qBAC7B,KAAK,0BAAwB,4BAC7B,KAAK,0BAAwB,YAC3B,MAAO,CAAC,EACV,QACE,MAAO,CAAC,CACZ,CACF,CAEQ,cAAcA,EAAiC,CACrD,KAAM,CAAC,CAAE,CAAE,CAAEE,CAAS,EAAI,KAAK,WAAW,OACxC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ecoderDataSource", "__toCommonJS", "import_device_management_kit", "import_inversify", "import_uniswap", "import_weth", "import_uniswapTypes", "ADDRESS_LENGTH", "FEE_LENGTH", "DefaultCommandDecoderDataSource", "abiDecoder", "command", "input", "chainId", "addresses", "address", "path", "tokens", "i", "token", "_input", "__decorateClass", "__decorateParam"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var o=require("../../uniswap/constants/uniswap"),s=require("../../uniswap/constants/weth"),x=require("./DefaultCommandDecoderDataSource"),p=require("./EthersAbiDecoderDataSource");describe("DefaultCommandDecoderDataSource",()=>{const r={decode:vi.fn()};let c;describe("decode with mocked apiDecoder",()=>{beforeEach(()=>{c=new x.DefaultCommandDecoderDataSource(r)}),describe.each([[o.UniswapSupportedCommand.V2_SWAP_EXACT_IN],[o.UniswapSupportedCommand.V2_SWAP_EXACT_OUT]])("%s",a=>{it("should return the correct command data",()=>{const e="0x";vi.spyOn(r,"decode").mockReturnValueOnce(["0x","0x","0x",["0x0102030405060708090a0b0c0d0e0f1011121314"],!1]);const t=c.decode(a,e,1);expect(t).toEqual(["0x0102030405060708090a0b0c0d0e0f1011121314"])}),it("should return the correct command data with multiple addresses",()=>{const e="0x";vi.spyOn(r,"decode").mockReturnValueOnce(["0x","0x","0x",["0x0102030405060708090a0b0c0d0e0f1011121314","0x0102030405060708090a0b0c0d0e0f1011121315"],!1]);const t=c.decode(a,e,1);expect(t).toEqual(["0x0102030405060708090a0b0c0d0e0f1011121314","0x0102030405060708090a0b0c0d0e0f1011121315"])}),it("should return an empty array if an address is not valid",()=>{const e="0x";vi.spyOn(r,"decode").mockReturnValueOnce(["0x","0x","0x",["0x0102030405060708090a0b0c0d0e0f1011121314","invalid"],!1]);const t=c.decode(a,e,1);expect(t).toEqual([])}),it("should return an empty array if the addresses are not an array",()=>{const e="0x";vi.spyOn(r,"decode").mockReturnValueOnce(["0x","0x","0x","invalid",!1]);const t=c.decode(a,e,1);expect(t).toEqual([])}),it("should return an empty array if the addresses are not an array of hexa strings",()=>{const e="0x";vi.spyOn(r,"decode").mockReturnValueOnce(["0x","0x","0x",["invalid"],!1]);const t=c.decode(a,e,1);expect(t).toEqual([])})}),describe.each([[o.UniswapSupportedCommand.V3_SWAP_EXACT_IN],[o.UniswapSupportedCommand.V3_SWAP_EXACT_OUT]])("%s",a=>{it("should return the correct command data",()=>{const e="0x",d=["0102030405060708090a0b0c0d0e0f1011121314","0102030405060708090a0b0c0d0e0f1011121315"].reduce((i,u)=>i.length===0?`0x${u}`:`${i}999999${u}`,"");vi.spyOn(r,"decode").mockReturnValueOnce(["0x","0x","0x",d,!1]);const n=c.decode(a,e,1);expect(n).toEqual(["0x0102030405060708090a0b0c0d0e0f1011121314","0x0102030405060708090a0b0c0d0e0f1011121315"])}),it("should return the correct command data with multiple addresses",()=>{const e="0x",d=["0102030405060708090a0b0c0d0e0f1011121314","0102030405060708090a0b0c0d0e0f1011121315","0102030405060708090a0b0c0d0e0f1011121316","0102030405060708090a0b0c0d0e0f1011121317"].reduce((i,u)=>i.length===0?`0x${u}`:`${i}999999${u}`,"");vi.spyOn(r,"decode").mockReturnValueOnce(["0x","0x","0x",d,!1]);const n=c.decode(a,e,1);expect(n).toEqual(["0x0102030405060708090a0b0c0d0e0f1011121314","0x0102030405060708090a0b0c0d0e0f1011121315","0x0102030405060708090a0b0c0d0e0f1011121316","0x0102030405060708090a0b0c0d0e0f1011121317"])}),it("should return an empty array if the path is not valid",()=>{const e="0x";vi.spyOn(r,"decode").mockReturnValueOnce(["0x","0x","0x","invalid",!1]);const t=c.decode(a,e,1);expect(t).toEqual([])}),it("should return an empty array if the path is not a string",()=>{const e="0x";vi.spyOn(r,"decode").mockReturnValueOnce(["0x","0x","0x",123,!1]);const t=c.decode(a,e,1);expect(t).toEqual([])}),it("should return an empty array if the path is not a hexa string",()=>{const e="0x";vi.spyOn(r,"decode").mockReturnValueOnce(["0x","0x","0x","invalid",!1]);const t=c.decode(a,e,1);expect(t).toEqual([])}),it("should return an empty array if the path is too short",()=>{const e="0x",d=["0102030405060708090a0b0c0d0e0f1011121314","0102030405060708090a0b0c0d0e0f101112131"].reduce((i,u)=>i.length===0?`0x${u}`:`${i}999999${u}`,"");vi.spyOn(r,"decode").mockReturnValueOnce(["0x","0x","0x",d,!1]);const n=c.decode(a,e,1);expect(n).toEqual([])})}),describe.each([o.UniswapSupportedCommand.WRAP_ETH,o.UniswapSupportedCommand.UNWRAP_ETH])("%s",a=>{it.each([s.WETHSupportedChainIds.ARBITRUM_GOERLI,s.WETHSupportedChainIds.ARBITRUM_ONE,s.WETHSupportedChainIds.AVALANCHE_C_CHAIN,s.WETHSupportedChainIds.BASE,s.WETHSupportedChainIds.BASE_GOERLI,s.WETHSupportedChainIds.BLAST,s.WETHSupportedChainIds.BSC,s.WETHSupportedChainIds.ETHEREUM_GOERLI,s.WETHSupportedChainIds.ETHEREUM_MAINNET,s.WETHSupportedChainIds.ETHEREUM_SEPOLIA,s.WETHSupportedChainIds.OPTIMISM,s.WETHSupportedChainIds.OPTIMISM_GOERLI,s.WETHSupportedChainIds.POLYGON,s.WETHSupportedChainIds.POLYGON_MUMBAI])("should return the correct command data for chainId %s",e=>{const d=c.decode(a,"0x",e);expect(d).toEqual([s.WETH_ADDRESS_BY_CHAIN_ID[e].toLowerCase()])}),it("should return an empty array if the chainId is not supported",()=>{const t=c.decode(o.UniswapSupportedCommand.WRAP_ETH,"0x",123);expect(t).toEqual([])})}),describe("SWEEP",()=>{it("should return the correct command data",()=>{const a="0x";vi.spyOn(r,"decode").mockReturnValueOnce(["0x0102030405060708090a0b0c0d0e0f1011121314","0x","0x","0x"]);const e=c.decode(o.UniswapSupportedCommand.SWEEP,a,1);expect(e).toEqual(["0x0102030405060708090a0b0c0d0e0f1011121314"])}),it("should return an empty array if the address is not valid",()=>{const a="0x";vi.spyOn(r,"decode").mockReturnValueOnce(["invalid","0x","0x","0x"]);const e=c.decode(o.UniswapSupportedCommand.SWEEP,a,1);expect(e).toEqual([])}),it("should return an empty array if the address is not a hexa string",()=>{const a="0x";vi.spyOn(r,"decode").mockReturnValueOnce([123,"0x","0x","0x"]);const e=c.decode(o.UniswapSupportedCommand.SWEEP,a,1);expect(e).toEqual([])})}),describe.each([o.UniswapSupportedCommand.PERMIT2_PERMIT,o.UniswapSupportedCommand.PERMIT2_TRANSFER_FROM,o.UniswapSupportedCommand.PERMIT2_PERMIT_BATCH,o.UniswapSupportedCommand.PERMIT2_TRANSFER_FROM_BATCH,o.UniswapSupportedCommand.PAY_PORTION,"invalid"])("%s",a=>{it("should return an empty array",()=>{const t=c.decode(a,"0x",1);expect(t).toEqual([])})})}),describe("decode with real apiDecoder",()=>{beforeEach(()=>{const a=new p.EthersAbiDecoderDataSource;c=new x.DefaultCommandDecoderDataSource(a)}),describe("V3_SWAP_EXACT_IN -> PAY_PORTION -> UNWRAP_ETH",()=>{const a=["0x00","0x06","0x0c"],e=["0x00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000a18f07d736b90be5500000000000000000000000000000000000000000000000000000000b0b8122abd8412900000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002bb9f599ce614feb2e1bbe58f180f370d05b39344e002710c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000","0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000017cc6042605381c158d2adab487434bde79aa61c000000000000000000000000000000000000000000000000000000000000005b","0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000b0b8122abd84129"];it("V3_SWAP_EXACT_IN",()=>{const t=a[0],d=e[0],n=c.decode(o.UNISWAP_COMMANDS[t],d,1);expect(n).toEqual(["0xb9f599ce614feb2e1bbe58f180f370d05b39344e","0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"])}),it("PAY_PORTION",()=>{const t=a[1],d=e[1],n=c.decode(o.UNISWAP_COMMANDS[t],d,1);expect(n).toEqual([])}),it("UNWRAP_ETH",()=>{const t=a[2],d=e[2],n=c.decode(o.UNISWAP_COMMANDS[t],d,1);expect(n).toEqual(["0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"])})}),describe("WRAP_ETH -> V3_SWAP_EXACT_OUT -> TRANSFERT -> SWEEP -> UNWRAP_ETH",()=>{const a=["0x0b","0x01","0x05","0x04","0x0c"],e=["0x0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000078e6708e70aed0f","0x00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000059a16770000000000000000000000000000000000000000000000000078e6708e70aed0f00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002ba0b86991c6218b36c1d19d4a2e9eb0ce3606eb480001f4c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000","0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000027213e28d7fda5c57fe9e5dd923818dbccf71c470000000000000000000000000000000000000000000000000000000000393870","0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000006f939b43d65be049b7533907db08e80ba6969f450000000000000000000000000000000000000000000000000000000059682f00","0x0000000000000000000000006f939b43d65be049b7533907db08e80ba6969f450000000000000000000000000000000000000000000000000000000000000000"];it("WRAP_ETH",()=>{const t=a[0],d=e[0],n=c.decode(o.UNISWAP_COMMANDS[t],d,1);expect(n).toEqual(["0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"])}),it("V3_SWAP_EXACT_OUT",()=>{const t=a[1],d=e[1],n=c.decode(o.UNISWAP_COMMANDS[t],d,1);expect(n).toEqual(["0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48","0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"])}),it("TRANSFERT",()=>{const t=a[2],d=e[2],n=c.decode(o.UNISWAP_COMMANDS[t],d,1);expect(n).toEqual([])}),it("SWEEP",()=>{const t=a[3],d=e[3],n=c.decode(o.UNISWAP_COMMANDS[t],d,1);expect(n).toEqual(["0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"])}),it("UNWRAP_ETH",()=>{const t=a[4],d=e[4],n=c.decode(o.UNISWAP_COMMANDS[t],d,1);expect(n).toEqual(["0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"])})}),describe("V2_SWAP_EXACT_IN -> PAY_PORTION -> UNWRAP_ETH",()=>{const a=["0x08","0x06","0x0c"],e=["0x0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000003ebb8addda849d38caed0000000000000000000000000000000000000000000000000f238e04a7ccbf5100000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000003b991130eae3cca364406d718da22fa1c3e7c256000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2","0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000fee13a103a10d593b9ae06b3e05f2e7e1c0000000000000000000000000000000000000000000000000000000000000019","0x00000000000000000000000002573c689ddedddd450e6c947f5bb67de70e80b50000000000000000000000000000000000000000000000000f19dda9c38a50c1"];it("V2_SWAP_EXACT_IN",()=>{const t=a[0],d=e[0],n=c.decode(o.UNISWAP_COMMANDS[t],d,1);expect(n).toEqual(["0x3b991130eae3cca364406d718da22fa1c3e7c256","0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"])}),it("PAY_PORTION",()=>{const t=a[1],d=e[1],n=c.decode(o.UNISWAP_COMMANDS[t],d,1);expect(n).toEqual([])}),it("UNWRAP_ETH",()=>{const t=a[2],d=e[2],n=c.decode(o.UNISWAP_COMMANDS[t],d,1);expect(n).toEqual(["0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"])})})})});
2
+ //# sourceMappingURL=DefaultCommandDecoderDataSource.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/uniswap/data/DefaultCommandDecoderDataSource.test.ts"],
4
+ "sourcesContent": ["import { type HexaString } from \"@ledgerhq/device-management-kit\";\n\nimport {\n UNISWAP_COMMANDS,\n UniswapSupportedCommand,\n} from \"@/uniswap/constants/uniswap\";\nimport {\n WETH_ADDRESS_BY_CHAIN_ID,\n WETHSupportedChainIds,\n} from \"@/uniswap/constants/weth\";\n\nimport { type AbiDecoderDataSource } from \"./AbiDecoderDataSource\";\nimport { DefaultCommandDecoderDataSource } from \"./DefaultCommandDecoderDataSource\";\nimport { EthersAbiDecoderDataSource } from \"./EthersAbiDecoderDataSource\";\n\ndescribe(\"DefaultCommandDecoderDataSource\", () => {\n const apiDecoderMock: AbiDecoderDataSource = {\n decode: vi.fn(),\n };\n let dataSource: DefaultCommandDecoderDataSource;\n\n describe(\"decode with mocked apiDecoder\", () => {\n beforeEach(() => {\n dataSource = new DefaultCommandDecoderDataSource(apiDecoderMock);\n });\n\n describe.each([\n [UniswapSupportedCommand.V2_SWAP_EXACT_IN],\n [UniswapSupportedCommand.V2_SWAP_EXACT_OUT],\n ])(\"%s\", (command) => {\n it(\"should return the correct command data\", () => {\n // GIVEN\n const input: HexaString = \"0x\";\n vi.spyOn(apiDecoderMock, \"decode\").mockReturnValueOnce([\n \"0x\",\n \"0x\",\n \"0x\",\n [\"0x0102030405060708090a0b0c0d0e0f1011121314\"],\n false,\n ]);\n\n // WHEN\n const result = dataSource.decode(command, input, 1);\n\n // THEN\n expect(result).toEqual([\"0x0102030405060708090a0b0c0d0e0f1011121314\"]);\n });\n\n it(\"should return the correct command data with multiple addresses\", () => {\n // GIVEN\n const input: HexaString = \"0x\";\n vi.spyOn(apiDecoderMock, \"decode\").mockReturnValueOnce([\n \"0x\",\n \"0x\",\n \"0x\",\n [\n \"0x0102030405060708090a0b0c0d0e0f1011121314\",\n \"0x0102030405060708090a0b0c0d0e0f1011121315\",\n ],\n false,\n ]);\n\n // WHEN\n const result = dataSource.decode(command, input, 1);\n\n // THEN\n expect(result).toEqual([\n \"0x0102030405060708090a0b0c0d0e0f1011121314\",\n \"0x0102030405060708090a0b0c0d0e0f1011121315\",\n ]);\n });\n\n it(\"should return an empty array if an address is not valid\", () => {\n // GIVEN\n const input: HexaString = \"0x\";\n vi.spyOn(apiDecoderMock, \"decode\").mockReturnValueOnce([\n \"0x\",\n \"0x\",\n \"0x\",\n [\"0x0102030405060708090a0b0c0d0e0f1011121314\", \"invalid\"],\n false,\n ]);\n\n // WHEN\n const result = dataSource.decode(command, input, 1);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if the addresses are not an array\", () => {\n // GIVEN\n const input: HexaString = \"0x\";\n vi.spyOn(apiDecoderMock, \"decode\").mockReturnValueOnce([\n \"0x\",\n \"0x\",\n \"0x\",\n \"invalid\",\n false,\n ]);\n\n // WHEN\n const result = dataSource.decode(command, input, 1);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if the addresses are not an array of hexa strings\", () => {\n // GIVEN\n const input: HexaString = \"0x\";\n vi.spyOn(apiDecoderMock, \"decode\").mockReturnValueOnce([\n \"0x\",\n \"0x\",\n \"0x\",\n [\"invalid\"],\n false,\n ]);\n\n // WHEN\n const result = dataSource.decode(command, input, 1);\n\n // THEN\n expect(result).toEqual([]);\n });\n });\n describe.each([\n [UniswapSupportedCommand.V3_SWAP_EXACT_IN],\n [UniswapSupportedCommand.V3_SWAP_EXACT_OUT],\n ])(\"%s\", (command) => {\n it(\"should return the correct command data\", () => {\n // GIVEN\n const input: HexaString = \"0x\";\n const addresses = [\n \"0102030405060708090a0b0c0d0e0f1011121314\",\n \"0102030405060708090a0b0c0d0e0f1011121315\",\n ];\n const path = addresses.reduce(\n (acc, address) =>\n acc.length === 0 ? `0x${address}` : `${acc}999999${address}`,\n \"\",\n );\n vi.spyOn(apiDecoderMock, \"decode\").mockReturnValueOnce([\n \"0x\",\n \"0x\",\n \"0x\",\n path,\n false,\n ]);\n\n // WHEN\n const result = dataSource.decode(command, input, 1);\n\n // THEN\n expect(result).toEqual([\n \"0x0102030405060708090a0b0c0d0e0f1011121314\",\n \"0x0102030405060708090a0b0c0d0e0f1011121315\",\n ]);\n });\n\n it(\"should return the correct command data with multiple addresses\", () => {\n // GIVEN\n const input: HexaString = \"0x\";\n const addresses = [\n \"0102030405060708090a0b0c0d0e0f1011121314\",\n \"0102030405060708090a0b0c0d0e0f1011121315\",\n \"0102030405060708090a0b0c0d0e0f1011121316\",\n \"0102030405060708090a0b0c0d0e0f1011121317\",\n ];\n const path = addresses.reduce(\n (acc, address) =>\n acc.length === 0 ? `0x${address}` : `${acc}999999${address}`,\n \"\",\n );\n vi.spyOn(apiDecoderMock, \"decode\").mockReturnValueOnce([\n \"0x\",\n \"0x\",\n \"0x\",\n path,\n false,\n ]);\n\n // WHEN\n const result = dataSource.decode(command, input, 1);\n\n // THEN\n expect(result).toEqual([\n \"0x0102030405060708090a0b0c0d0e0f1011121314\",\n \"0x0102030405060708090a0b0c0d0e0f1011121315\",\n \"0x0102030405060708090a0b0c0d0e0f1011121316\",\n \"0x0102030405060708090a0b0c0d0e0f1011121317\",\n ]);\n });\n\n it(\"should return an empty array if the path is not valid\", () => {\n // GIVEN\n const input: HexaString = \"0x\";\n vi.spyOn(apiDecoderMock, \"decode\").mockReturnValueOnce([\n \"0x\",\n \"0x\",\n \"0x\",\n \"invalid\",\n false,\n ]);\n\n // WHEN\n const result = dataSource.decode(command, input, 1);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if the path is not a string\", () => {\n // GIVEN\n const input: HexaString = \"0x\";\n vi.spyOn(apiDecoderMock, \"decode\").mockReturnValueOnce([\n \"0x\",\n \"0x\",\n \"0x\",\n 123,\n false,\n ]);\n\n // WHEN\n const result = dataSource.decode(command, input, 1);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if the path is not a hexa string\", () => {\n // GIVEN\n const input: HexaString = \"0x\";\n vi.spyOn(apiDecoderMock, \"decode\").mockReturnValueOnce([\n \"0x\",\n \"0x\",\n \"0x\",\n \"invalid\",\n false,\n ]);\n\n // WHEN\n const result = dataSource.decode(command, input, 1);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if the path is too short\", () => {\n // GIVEN\n const input: HexaString = \"0x\";\n\n const addresses = [\n \"0102030405060708090a0b0c0d0e0f1011121314\",\n \"0102030405060708090a0b0c0d0e0f101112131\", // 1 char missing\n ];\n const path = addresses.reduce(\n (acc, address) =>\n acc.length === 0 ? `0x${address}` : `${acc}999999${address}`,\n \"\",\n );\n vi.spyOn(apiDecoderMock, \"decode\").mockReturnValueOnce([\n \"0x\",\n \"0x\",\n \"0x\",\n path,\n false,\n ]);\n\n // WHEN\n const result = dataSource.decode(command, input, 1);\n\n // THEN\n expect(result).toEqual([]);\n });\n });\n\n describe.each([\n UniswapSupportedCommand.WRAP_ETH,\n UniswapSupportedCommand.UNWRAP_ETH,\n ])(\"%s\", (command) => {\n it.each([\n WETHSupportedChainIds.ARBITRUM_GOERLI,\n WETHSupportedChainIds.ARBITRUM_ONE,\n WETHSupportedChainIds.AVALANCHE_C_CHAIN,\n WETHSupportedChainIds.BASE,\n WETHSupportedChainIds.BASE_GOERLI,\n WETHSupportedChainIds.BLAST,\n WETHSupportedChainIds.BSC,\n WETHSupportedChainIds.ETHEREUM_GOERLI,\n WETHSupportedChainIds.ETHEREUM_MAINNET,\n WETHSupportedChainIds.ETHEREUM_SEPOLIA,\n WETHSupportedChainIds.OPTIMISM,\n WETHSupportedChainIds.OPTIMISM_GOERLI,\n WETHSupportedChainIds.POLYGON,\n WETHSupportedChainIds.POLYGON_MUMBAI,\n ])(\"should return the correct command data for chainId %s\", (chainId) => {\n // GIVEN\n const input: HexaString = \"0x\";\n\n // WHEN\n const result = dataSource.decode(command, input, chainId);\n\n // THEN\n expect(result).toEqual([\n WETH_ADDRESS_BY_CHAIN_ID[chainId].toLowerCase(),\n ]);\n });\n\n it(\"should return an empty array if the chainId is not supported\", () => {\n // GIVEN\n const input: HexaString = \"0x\";\n\n // WHEN\n const result = dataSource.decode(\n UniswapSupportedCommand.WRAP_ETH,\n input,\n 123,\n );\n\n // THEN\n expect(result).toEqual([]);\n });\n });\n\n describe(\"SWEEP\", () => {\n it(\"should return the correct command data\", () => {\n // GIVEN\n const input: HexaString = \"0x\";\n vi.spyOn(apiDecoderMock, \"decode\").mockReturnValueOnce([\n \"0x0102030405060708090a0b0c0d0e0f1011121314\",\n \"0x\",\n \"0x\",\n \"0x\",\n ]);\n\n // WHEN\n const result = dataSource.decode(\n UniswapSupportedCommand.SWEEP,\n input,\n 1,\n );\n\n // THEN\n expect(result).toEqual([\"0x0102030405060708090a0b0c0d0e0f1011121314\"]);\n });\n\n it(\"should return an empty array if the address is not valid\", () => {\n // GIVEN\n const input: HexaString = \"0x\";\n vi.spyOn(apiDecoderMock, \"decode\").mockReturnValueOnce([\n \"invalid\",\n \"0x\",\n \"0x\",\n \"0x\",\n ]);\n\n // WHEN\n const result = dataSource.decode(\n UniswapSupportedCommand.SWEEP,\n input,\n 1,\n );\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if the address is not a hexa string\", () => {\n // GIVEN\n const input: HexaString = \"0x\";\n vi.spyOn(apiDecoderMock, \"decode\").mockReturnValueOnce([\n 123,\n \"0x\",\n \"0x\",\n \"0x\",\n ]);\n\n // WHEN\n const result = dataSource.decode(\n UniswapSupportedCommand.SWEEP,\n input,\n 1,\n );\n\n // THEN\n expect(result).toEqual([]);\n });\n });\n\n describe.each([\n UniswapSupportedCommand.PERMIT2_PERMIT,\n UniswapSupportedCommand.PERMIT2_TRANSFER_FROM,\n UniswapSupportedCommand.PERMIT2_PERMIT_BATCH,\n UniswapSupportedCommand.PERMIT2_TRANSFER_FROM_BATCH,\n UniswapSupportedCommand.PAY_PORTION,\n \"invalid\" as UniswapSupportedCommand,\n ])(\"%s\", (command) => {\n it(\"should return an empty array\", () => {\n // GIVEN\n const input: HexaString = \"0x\";\n\n // WHEN\n const result = dataSource.decode(command, input, 1);\n\n // THEN\n expect(result).toEqual([]);\n });\n });\n });\n\n describe(\"decode with real apiDecoder\", () => {\n beforeEach(() => {\n const abiDecoder = new EthersAbiDecoderDataSource();\n dataSource = new DefaultCommandDecoderDataSource(abiDecoder);\n });\n\n describe(\"V3_SWAP_EXACT_IN -> PAY_PORTION -> UNWRAP_ETH\", () => {\n // https://etherscan.io/tx/0xc9821c32c1782d9ab6baf6f9ca4b2565bce11aaf5146a2d303215bda026f5e48\n const commands: HexaString[] = [\"0x00\", \"0x06\", \"0x0c\"];\n const inputs: HexaString[] = [\n \"0x00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000a18f07d736b90be5500000000000000000000000000000000000000000000000000000000b0b8122abd8412900000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002bb9f599ce614feb2e1bbe58f180f370d05b39344e002710c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000\",\n \"0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000017cc6042605381c158d2adab487434bde79aa61c000000000000000000000000000000000000000000000000000000000000005b\",\n \"0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000b0b8122abd84129\",\n ];\n\n it(\"V3_SWAP_EXACT_IN\", () => {\n // GIVEN\n const command = commands[0]!;\n const input = inputs[0]!;\n\n // WHEN\n const result = dataSource.decode(\n UNISWAP_COMMANDS[command] as UniswapSupportedCommand,\n input,\n 1,\n );\n\n // THEN\n expect(result).toEqual([\n \"0xb9f599ce614feb2e1bbe58f180f370d05b39344e\", // ERC20\n \"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2\", // WETH\n ]);\n });\n\n it(\"PAY_PORTION\", () => {\n // GIVEN\n const command = commands[1]!;\n const input = inputs[1]!;\n\n // WHEN\n const result = dataSource.decode(\n UNISWAP_COMMANDS[command] as UniswapSupportedCommand,\n input,\n 1,\n );\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"UNWRAP_ETH\", () => {\n // GIVEN\n const command = commands[2]!;\n const input = inputs[2]!;\n\n // WHEN\n const result = dataSource.decode(\n UNISWAP_COMMANDS[command] as UniswapSupportedCommand,\n input,\n 1,\n );\n\n // THEN\n expect(result).toEqual([\"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2\"]); // WETH\n });\n });\n\n describe(\"WRAP_ETH -> V3_SWAP_EXACT_OUT -> TRANSFERT -> SWEEP -> UNWRAP_ETH\", () => {\n // https://etherscan.io/tx/0xa628c8b3da2ad984aed0354d8ca4b4c3c42941491dc4e0d6a5f423fd65e6c90a\n const commands: HexaString[] = [\"0x0b\", \"0x01\", \"0x05\", \"0x04\", \"0x0c\"];\n const inputs: HexaString[] = [\n \"0x0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000078e6708e70aed0f\",\n \"0x00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000059a16770000000000000000000000000000000000000000000000000078e6708e70aed0f00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002ba0b86991c6218b36c1d19d4a2e9eb0ce3606eb480001f4c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000\",\n \"0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000027213e28d7fda5c57fe9e5dd923818dbccf71c470000000000000000000000000000000000000000000000000000000000393870\",\n \"0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000006f939b43d65be049b7533907db08e80ba6969f450000000000000000000000000000000000000000000000000000000059682f00\",\n \"0x0000000000000000000000006f939b43d65be049b7533907db08e80ba6969f450000000000000000000000000000000000000000000000000000000000000000\",\n ];\n\n it(\"WRAP_ETH\", () => {\n // GIVEN\n const command = commands[0]!;\n const input = inputs[0]!;\n\n // WHEN\n const result = dataSource.decode(\n UNISWAP_COMMANDS[command] as UniswapSupportedCommand,\n input,\n 1,\n );\n\n // THEN\n expect(result).toEqual([\"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2\"]); // WETH\n });\n\n it(\"V3_SWAP_EXACT_OUT\", () => {\n // GIVEN\n const command = commands[1]!;\n const input = inputs[1]!;\n\n // WHEN\n const result = dataSource.decode(\n UNISWAP_COMMANDS[command] as UniswapSupportedCommand,\n input,\n 1,\n );\n\n // THEN\n expect(result).toEqual([\n \"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48\", // USDC\n \"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2\", // WETH\n ]);\n });\n\n it(\"TRANSFERT\", () => {\n // GIVEN\n const command = commands[2]!;\n const input = inputs[2]!;\n\n // WHEN\n const result = dataSource.decode(\n UNISWAP_COMMANDS[command] as UniswapSupportedCommand,\n input,\n 1,\n );\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"SWEEP\", () => {\n // GIVEN\n const command = commands[3]!;\n const input = inputs[3]!;\n\n // WHEN\n const result = dataSource.decode(\n UNISWAP_COMMANDS[command] as UniswapSupportedCommand,\n input,\n 1,\n );\n\n // THEN\n expect(result).toEqual([\"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48\"]); // USDC\n });\n\n it(\"UNWRAP_ETH\", () => {\n // GIVEN\n const command = commands[4]!;\n const input = inputs[4]!;\n\n // WHEN\n const result = dataSource.decode(\n UNISWAP_COMMANDS[command] as UniswapSupportedCommand,\n input,\n 1,\n );\n\n // THEN\n expect(result).toEqual([\"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2\"]); // WETH\n });\n });\n\n describe(\"V2_SWAP_EXACT_IN -> PAY_PORTION -> UNWRAP_ETH\", () => {\n // https://etherscan.io/tx/0x78bc5732213e09d9ead8cabc269b7c426b0301dfe543c37d0a920e25eaa9447f\n const commands: HexaString[] = [\"0x08\", \"0x06\", \"0x0c\"];\n const inputs: HexaString[] = [\n \"0x0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000003ebb8addda849d38caed0000000000000000000000000000000000000000000000000f238e04a7ccbf5100000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000003b991130eae3cca364406d718da22fa1c3e7c256000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2\",\n \"0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000fee13a103a10d593b9ae06b3e05f2e7e1c0000000000000000000000000000000000000000000000000000000000000019\",\n \"0x00000000000000000000000002573c689ddedddd450e6c947f5bb67de70e80b50000000000000000000000000000000000000000000000000f19dda9c38a50c1\",\n ];\n\n it(\"V2_SWAP_EXACT_IN\", () => {\n // GIVEN\n const command = commands[0]!;\n const input = inputs[0]!;\n\n // WHEN\n const result = dataSource.decode(\n UNISWAP_COMMANDS[command] as UniswapSupportedCommand,\n input,\n 1,\n );\n\n // THEN\n expect(result).toEqual([\n \"0x3b991130eae3cca364406d718da22fa1c3e7c256\", // ERC20\n \"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2\", // WETH\n ]);\n });\n\n it(\"PAY_PORTION\", () => {\n // GIVEN\n const command = commands[1]!;\n const input = inputs[1]!;\n\n // WHEN\n const result = dataSource.decode(\n UNISWAP_COMMANDS[command] as UniswapSupportedCommand,\n input,\n 1,\n );\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"UNWRAP_ETH\", () => {\n // GIVEN\n const command = commands[2]!;\n const input = inputs[2]!;\n\n // WHEN\n const result = dataSource.decode(\n UNISWAP_COMMANDS[command] as UniswapSupportedCommand,\n input,\n 1,\n );\n\n // THEN\n expect(result).toEqual([\"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2\"]); // WETH\n });\n });\n });\n});\n"],
5
+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AM,EAAE,QAAQ,CAAC,4CAA4C,CAAC,CACvE,CAAC,CACH,CAAC,EAED,SAAS,gDAAiD,IAAM,CAE9D,MAAMM,EAAyB,CAAC,OAAQ,OAAQ,MAAM,EAChDC,EAAuB,CAC3B,qgBACA,qMACA,oIACF,EAEA,GAAG,mBAAoB,IAAM,CAE3B,MAAMT,EAAUQ,EAAS,CAAC,EACpBP,EAAQQ,EAAO,CAAC,EAGhBP,EAASH,EAAW,OACxB,mBAAiBC,CAAO,EACxBC,EACA,CACF,EAGA,OAAOC,CAAM,EAAE,QAAQ,CACrB,6CACA,4CACF,CAAC,CACH,CAAC,EAED,GAAG,cAAe,IAAM,CAEtB,MAAMF,EAAUQ,EAAS,CAAC,EACpBP,EAAQQ,EAAO,CAAC,EAGhBP,EAASH,EAAW,OACxB,mBAAiBC,CAAO,EACxBC,EACA,CACF,EAGA,OAAOC,CAAM,EAAE,QAAQ,CAAC,CAAC,CAC3B,CAAC,EAED,GAAG,aAAc,IAAM,CAErB,MAAMF,EAAUQ,EAAS,CAAC,EACpBP,EAAQQ,EAAO,CAAC,EAGhBP,EAASH,EAAW,OACxB,mBAAiBC,CAAO,EACxBC,EACA,CACF,EAGA,OAAOC,CAAM,EAAE,QAAQ,CAAC,4CAA4C,CAAC,CACvE,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["import_uniswap", "import_weth", "import_DefaultCommandDecoderDataSource", "import_EthersAbiDecoderDataSource", "apiDecoderMock", "dataSource", "command", "input", "result", "path", "acc", "address", "chainId", "abiDecoder", "commands", "inputs"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var m=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var g=(t,r)=>{for(var e in r)m(t,e,{get:r[e],enumerable:!0})},s=(t,r,e,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of a(r))!b.call(t,o)&&o!==e&&m(t,o,{get:()=>r[o],enumerable:!(n=c(r,o))||n.enumerable});return t};var y=t=>s(m({},"__esModule",{value:!0}),t),f=(t,r,e,n)=>{for(var o=n>1?void 0:n?c(r,e):r,d=t.length-1,p;d>=0;d--)(p=t[d])&&(o=(n?p(r,e,o):p(o))||o);return n&&o&&m(r,e,o),o};var C={};g(C,{EthersAbiDecoderDataSource:()=>i});module.exports=y(C);var l=require("ethers"),u=require("inversify");let i=class{decode(r,e){try{return l.AbiCoder.defaultAbiCoder().decode(r,e)}catch{return[]}}};i=f([(0,u.injectable)()],i);0&&(module.exports={EthersAbiDecoderDataSource});
2
+ //# sourceMappingURL=EthersAbiDecoderDataSource.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/uniswap/data/EthersAbiDecoderDataSource.ts"],
4
+ "sourcesContent": ["import { AbiCoder } from \"ethers\";\nimport { injectable } from \"inversify\";\n\nimport { type AbiDecoderDataSource } from \"./AbiDecoderDataSource\";\n\n@injectable()\nexport class EthersAbiDecoderDataSource implements AbiDecoderDataSource {\n decode(types: string[], data: string): unknown[] {\n try {\n return AbiCoder.defaultAbiCoder().decode(types, data);\n } catch (_) {\n return [];\n }\n }\n}\n"],
5
+ "mappings": "2iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAyB,kBACzBC,EAA2B,qBAKpB,IAAMC,EAAN,KAAiE,CACtE,OAAOC,EAAiBC,EAAyB,CAC/C,GAAI,CACF,OAAO,WAAS,gBAAgB,EAAE,OAAOD,EAAOC,CAAI,CACtD,MAAY,CACV,MAAO,CAAC,CACV,CACF,CACF,EARaF,EAANG,EAAA,IADN,cAAW,GACCH",
6
+ "names": ["EthersAbiDecoderDataSource_exports", "__export", "EthersAbiDecoderDataSource", "__toCommonJS", "import_ethers", "import_inversify", "EthersAbiDecoderDataSource", "types", "data", "__decorateClass"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var a=require("./EthersAbiDecoderDataSource");describe("EthersAbiDecoderDataSource",()=>{let t;beforeEach(()=>{t=new a.EthersAbiDecoderDataSource}),it("should correctly decode valid ABI data",()=>{const c=["uint256","address"],e=t.decode(c,"0x000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000027213e28d7fda5c57fe9e5dd923818dbccf71c47");expect(e[0]).toEqual(10n),expect(e[1]).toEqual("0x27213E28D7fDA5c57Fe9e5dD923818DBCcf71c47")}),it("should return an empty array on decode failure",()=>{const c=["uint256"],e=t.decode(c,"0x1234");expect(e).toEqual([])})});
2
+ //# sourceMappingURL=EthersAbiDecoderDataSource.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/uniswap/data/EthersAbiDecoderDataSource.test.ts"],
4
+ "sourcesContent": ["import { EthersAbiDecoderDataSource } from \"./EthersAbiDecoderDataSource\";\n\ndescribe(\"EthersAbiDecoderDataSource\", () => {\n let decoder: EthersAbiDecoderDataSource;\n\n beforeEach(() => {\n decoder = new EthersAbiDecoderDataSource();\n });\n\n it(\"should correctly decode valid ABI data\", () => {\n const types = [\"uint256\", \"address\"];\n const data =\n \"0x\" +\n \"000000000000000000000000000000000000000000000000000000000000000a\" + // 10 as uint256\n \"00000000000000000000000027213e28d7fda5c57fe9e5dd923818dbccf71c47\"; // Address\n\n const result = decoder.decode(types, data);\n expect(result[0]).toEqual(10n);\n expect(result[1]).toEqual(\"0x27213E28D7fDA5c57Fe9e5dD923818DBCcf71c47\");\n });\n\n it(\"should return an empty array on decode failure\", () => {\n const types = [\"uint256\"];\n const invalidData = \"0x1234\"; // Invalid encoded data\n\n const result = decoder.decode(types, invalidData);\n expect(result).toEqual([]);\n });\n});\n"],
5
+ "mappings": "aAAA,IAAAA,EAA2C,wCAE3C,SAAS,6BAA8B,IAAM,CAC3C,IAAIC,EAEJ,WAAW,IAAM,CACfA,EAAU,IAAI,4BAChB,CAAC,EAED,GAAG,yCAA0C,IAAM,CACjD,MAAMC,EAAQ,CAAC,UAAW,SAAS,EAM7BC,EAASF,EAAQ,OAAOC,EAJ5B,oIAIuC,EACzC,OAAOC,EAAO,CAAC,CAAC,EAAE,QAAQ,GAAG,EAC7B,OAAOA,EAAO,CAAC,CAAC,EAAE,QAAQ,4CAA4C,CACxE,CAAC,EAED,GAAG,iDAAkD,IAAM,CACzD,MAAMD,EAAQ,CAAC,SAAS,EAGlBC,EAASF,EAAQ,OAAOC,EAFV,QAE4B,EAChD,OAAOC,CAAM,EAAE,QAAQ,CAAC,CAAC,CAC3B,CAAC,CACH,CAAC",
6
+ "names": ["import_EthersAbiDecoderDataSource", "decoder", "types", "result"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var n=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var s=Object.prototype.hasOwnProperty;var f=(o,e)=>{for(var r in e)n(o,r,{get:e[r],enumerable:!0})},w=(o,e,r,m)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of D(e))!s.call(o,t)&&t!==r&&n(o,t,{get:()=>e[t],enumerable:!(m=c(e,t))||m.enumerable});return o};var C=o=>w(n({},"__esModule",{value:!0}),o);var l={};f(l,{uniswapModuleFactory:()=>S});module.exports=C(l);var i=require("inversify"),d=require("../../uniswap/data/DefaultCommandDecoderDataSource"),p=require("../../uniswap/data/EthersAbiDecoderDataSource"),u=require("../../uniswap/domain/UniswapContextLoader"),a=require("./uniswapTypes");const S=()=>new i.ContainerModule((o,e,r,m)=>{o(a.uniswapTypes.AbiDecoderDataSource).to(p.EthersAbiDecoderDataSource),o(a.uniswapTypes.CommandDecoderDataSource).to(d.DefaultCommandDecoderDataSource),o(a.uniswapTypes.UniswapContextLoader).to(u.UniswapContextLoader)});0&&(module.exports={uniswapModuleFactory});
2
+ //# sourceMappingURL=uniswapModuleFactory.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/uniswap/di/uniswapModuleFactory.ts"],
4
+ "sourcesContent": ["import { ContainerModule } from \"inversify\";\n\nimport { DefaultCommandDecoderDataSource } from \"@/uniswap/data/DefaultCommandDecoderDataSource\";\nimport { EthersAbiDecoderDataSource } from \"@/uniswap/data/EthersAbiDecoderDataSource\";\nimport { UniswapContextLoader } from \"@/uniswap/domain/UniswapContextLoader\";\n\nimport { uniswapTypes } from \"./uniswapTypes\";\n\nexport const uniswapModuleFactory = () =>\n new ContainerModule((bind, _unbind, _isBound, _rebind) => {\n bind(uniswapTypes.AbiDecoderDataSource).to(EthersAbiDecoderDataSource);\n bind(uniswapTypes.CommandDecoderDataSource).to(\n DefaultCommandDecoderDataSource,\n );\n bind(uniswapTypes.UniswapContextLoader).to(UniswapContextLoader);\n });\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAgC,qBAEhCC,EAAgD,0DAChDC,EAA2C,qDAC3CC,EAAqC,iDAErCC,EAA6B,0BAEtB,MAAMN,EAAuB,IAClC,IAAI,kBAAgB,CAACO,EAAMC,EAASC,EAAUC,IAAY,CACxDH,EAAK,eAAa,oBAAoB,EAAE,GAAG,4BAA0B,EACrEA,EAAK,eAAa,wBAAwB,EAAE,GAC1C,iCACF,EACAA,EAAK,eAAa,oBAAoB,EAAE,GAAG,sBAAoB,CACjE,CAAC",
6
+ "names": ["uniswapModuleFactory_exports", "__export", "uniswapModuleFactory", "__toCommonJS", "import_inversify", "import_DefaultCommandDecoderDataSource", "import_EthersAbiDecoderDataSource", "import_UniswapContextLoader", "import_uniswapTypes", "bind", "_unbind", "_isBound", "_rebind"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var t=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var n=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var m=(e,o)=>{for(var r in o)t(e,r,{get:o[r],enumerable:!0})},S=(e,o,r,c)=>{if(o&&typeof o=="object"||typeof o=="function")for(let a of n(o))!D.call(e,a)&&a!==r&&t(e,a,{get:()=>o[a],enumerable:!(c=d(o,a))||c.enumerable});return e};var b=e=>S(t({},"__esModule",{value:!0}),e);var p={};m(p,{uniswapTypes:()=>i});module.exports=b(p);const i={AbiDecoderDataSource:Symbol.for("AbiDecoderDataSource"),CommandDecoderDataSource:Symbol.for("CommandDecoderDataSource"),UniswapContextLoader:Symbol.for("UniswapContextLoader")};0&&(module.exports={uniswapTypes});
2
+ //# sourceMappingURL=uniswapTypes.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/uniswap/di/uniswapTypes.ts"],
4
+ "sourcesContent": ["export const uniswapTypes = {\n AbiDecoderDataSource: Symbol.for(\"AbiDecoderDataSource\"),\n CommandDecoderDataSource: Symbol.for(\"CommandDecoderDataSource\"),\n UniswapContextLoader: Symbol.for(\"UniswapContextLoader\"),\n};\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,IAAA,eAAAC,EAAAH,GAAO,MAAME,EAAe,CAC1B,qBAAsB,OAAO,IAAI,sBAAsB,EACvD,yBAA0B,OAAO,IAAI,0BAA0B,EAC/D,qBAAsB,OAAO,IAAI,sBAAsB,CACzD",
6
+ "names": ["uniswapTypes_exports", "__export", "uniswapTypes", "__toCommonJS"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var l=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var k=(n,e)=>{for(var t in e)l(n,t,{get:e[t],enumerable:!0})},H=(n,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of I(e))!w.call(n,r)&&r!==t&&l(n,r,{get:()=>e[r],enumerable:!(a=D(e,r))||a.enumerable});return n};var b=n=>H(l({},"__esModule",{value:!0}),n),_=(n,e,t,a)=>{for(var r=a>1?void 0:a?D(e,t):e,i=n.length-1,d;i>=0;i--)(d=n[i])&&(r=(a?d(e,t,r):d(r))||r);return a&&r&&l(e,t,r),r},C=(n,e)=>(t,a)=>e(t,a,n);var R={};k(R,{UniswapContextLoader:()=>p});module.exports=b(R);var o=require("@ledgerhq/device-management-kit"),A=require("ethers"),c=require("inversify"),S=require("purify-ts"),g=require("../../shared/model/ClearSignContext"),T=require("../../token/di/tokenTypes"),f=require("../../uniswap/constants/plugin"),s=require("../../uniswap/constants/uniswap"),h=require("../../uniswap/di/uniswapTypes");let p=class{constructor(e,t){this.commandDecoderDataSource=e;this.tokenDataSource=t}async load(e){if(!e.data||!(0,o.isHexaString)(e.data))return[];if(e.data.slice(0,10)!==s.UNISWAP_EXECUTE_SELECTOR)return[];const a=this._buildUniswapPluginCommandData(),r=await this._extractClearSignContexts(e.data,e.chainId);return r.length>0?[a,...r]:[]}_buildUniswapPluginCommandData(){const e=new o.ByteArrayBuilder().add8BitUIntToData(f.UNISWAP_PLUGIN_NAME.length).addAsciiStringToData(f.UNISWAP_PLUGIN_NAME).addBufferToData((0,o.hexaStringToBuffer)(s.UNISWAP_UNIVERSAL_ROUTER_ADDRESS)).addBufferToData((0,o.hexaStringToBuffer)(s.UNISWAP_EXECUTE_SELECTOR)).addBufferToData((0,o.hexaStringToBuffer)(f.UNISWAP_PLUGIN_SIGNATURE)).build();return{type:g.ClearSignContextType.EXTERNAL_PLUGIN,payload:(0,o.bufferToHexaString)(e).slice(2)}}async _extractClearSignContexts(e,t){try{const r=new A.Interface(s.UNISWAP_EXECUTE_ABI).parseTransaction({data:e}),i=r?.args[0],d=r?.args[1];if(!(0,o.isHexaString)(i)||!this._isHexaStringArray(d))return[];const x=this._extractCommands(i).orDefault([]);if(i.length===0||d.length!==x.length)return[];const y=x.reduce((m,u,U)=>{const N=d[U],E=this.commandDecoderDataSource.decode(u,N,t);return m.push([u,E]),m},[]);if(!this._isChainingSwapSupported(y))return[];const P=[...new Set(y.flatMap(([,m])=>m))];return(await Promise.all(P.map(m=>this.tokenDataSource.getTokenInfosPayload({address:m,chainId:t})))).map(m=>m.caseOf({Left:u=>({type:g.ClearSignContextType.ERROR,error:u}),Right:u=>({type:g.ClearSignContextType.TOKEN,payload:u})}))}catch{return[]}}_extractCommands(e){return S.Maybe.fromNullable(e.slice(2).match(/../g)).map(t=>t.map(a=>`0x${a}`)).map(t=>t.map(a=>s.UNISWAP_COMMANDS[a])).chain(t=>t.every(a=>a!==void 0)?S.Maybe.of(t):S.Nothing)}_isChainingSwapSupported(e){let t,a;for(const[r,i]of e){if(!s.UNISWAP_SWAP_COMMANDS.includes(r))continue;const d=r.slice(0,2);if(t&&(t!==i[0]||a!==d))return!1;t=i[i.length-1],a=d}return!0}_isHexaStringArray(e){return Array.isArray(e)&&e.every(t=>typeof t=="string"&&(0,o.isHexaString)(t))}};p=_([(0,c.injectable)(),C(0,(0,c.inject)(h.uniswapTypes.CommandDecoderDataSource)),C(1,(0,c.inject)(T.tokenTypes.TokenDataSource))],p);0&&(module.exports={UniswapContextLoader});
2
+ //# sourceMappingURL=UniswapContextLoader.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/uniswap/domain/UniswapContextLoader.ts"],
4
+ "sourcesContent": ["import {\n bufferToHexaString,\n ByteArrayBuilder,\n HexaString,\n hexaStringToBuffer,\n isHexaString,\n} from \"@ledgerhq/device-management-kit\";\nimport { Interface } from \"ethers\";\nimport { inject, injectable } from \"inversify\";\nimport { Maybe, Nothing } from \"purify-ts\";\n\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { TransactionContext } from \"@/shared/model/TransactionContext\";\nimport { type TokenDataSource } from \"@/token/data/TokenDataSource\";\nimport { tokenTypes } from \"@/token/di/tokenTypes\";\nimport {\n UNISWAP_PLUGIN_NAME,\n UNISWAP_PLUGIN_SIGNATURE,\n} from \"@/uniswap/constants/plugin\";\nimport {\n UNISWAP_COMMANDS,\n UNISWAP_EXECUTE_ABI,\n UNISWAP_EXECUTE_SELECTOR,\n UNISWAP_SWAP_COMMANDS,\n UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n UniswapSupportedCommand,\n} from \"@/uniswap/constants/uniswap\";\nimport { type CommandDecoderDataSource } from \"@/uniswap/data/CommandDecoderDataSource\";\nimport { uniswapTypes } from \"@/uniswap/di/uniswapTypes\";\n\n@injectable()\nexport class UniswapContextLoader implements ContextLoader {\n constructor(\n @inject(uniswapTypes.CommandDecoderDataSource)\n private commandDecoderDataSource: CommandDecoderDataSource,\n @inject(tokenTypes.TokenDataSource)\n private tokenDataSource: TokenDataSource,\n ) {}\n\n async load(transaction: TransactionContext): Promise<ClearSignContext[]> {\n if (!transaction.data || !isHexaString(transaction.data)) {\n return [];\n }\n\n const selector = transaction.data.slice(0, 10);\n if (selector !== UNISWAP_EXECUTE_SELECTOR) {\n return [];\n }\n\n const externalPluginContext = this._buildUniswapPluginCommandData();\n const tokenContexts = await this._extractClearSignContexts(\n transaction.data,\n transaction.chainId,\n );\n\n if (tokenContexts.length > 0)\n return [externalPluginContext, ...tokenContexts];\n\n return [];\n }\n\n /**\n * Constructs the external plugin context for Uniswap external plugin command.\n *\n * @private\n * @returns {ClearSignContext} - The generated external plugin context.\n */\n private _buildUniswapPluginCommandData(): ClearSignContext {\n const buffer = new ByteArrayBuilder()\n .add8BitUIntToData(UNISWAP_PLUGIN_NAME.length)\n .addAsciiStringToData(UNISWAP_PLUGIN_NAME)\n .addBufferToData(hexaStringToBuffer(UNISWAP_UNIVERSAL_ROUTER_ADDRESS)!)\n .addBufferToData(hexaStringToBuffer(UNISWAP_EXECUTE_SELECTOR)!)\n .addBufferToData(hexaStringToBuffer(UNISWAP_PLUGIN_SIGNATURE)!)\n .build();\n\n return {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: bufferToHexaString(buffer).slice(2),\n };\n }\n\n /**\n * Extracts and decodes the clear sign contexts from a Uniswap calldata transaction.\n *\n * This function:\n * - Parses the calldata using the Uniswap `execute` function signature.\n * - Extracts and validates the `commands` and `inputs`.\n * - Decodes the commands and ensures they match the number of inputs.\n * - Extracts addresses used in the transaction and verifies if chaining swaps are supported.\n * - Fetches token information for unique addresses.\n * - Returns an array of `ClearSignContext` objects representing either token data or errors.\n *\n * @private\n * @param {HexaString} calldata - The raw calldata of the Uniswap transaction.\n * @param {number} chainId - The blockchain chain ID where the transaction is being executed.\n * @returns {Promise<ClearSignContext[]>} - A promise resolving to an array of clear sign contexts.\n */\n private async _extractClearSignContexts(\n calldata: HexaString,\n chainId: number,\n ): Promise<ClearSignContext[]> {\n try {\n const iface = new Interface(UNISWAP_EXECUTE_ABI);\n\n const tx = iface.parseTransaction({ data: calldata });\n const commands: unknown = tx?.args[0];\n const inputs: unknown = tx?.args[1];\n\n if (!isHexaString(commands) || !this._isHexaStringArray(inputs)) {\n return [];\n }\n\n const decodedCommands = this._extractCommands(commands).orDefault([]);\n if (commands.length === 0 || inputs.length !== decodedCommands.length) {\n // Invalid commands or inputs\n return [];\n }\n\n const addressesByCommand = decodedCommands.reduce(\n (acc, command, index) => {\n const input = inputs[index]!;\n const decoded: HexaString[] = this.commandDecoderDataSource.decode(\n command,\n input,\n chainId,\n );\n\n acc.push([command, decoded]);\n\n return acc;\n },\n [] as [UniswapSupportedCommand, HexaString[]][],\n );\n\n if (!this._isChainingSwapSupported(addressesByCommand)) {\n return [];\n }\n\n const uniqueAddresses = [\n ...new Set(addressesByCommand.flatMap(([, addresses]) => addresses)),\n ];\n\n const tokensPayload = await Promise.all(\n uniqueAddresses.map((address) =>\n this.tokenDataSource.getTokenInfosPayload({ address, chainId }),\n ),\n );\n\n return tokensPayload.map((either) =>\n either.caseOf<ClearSignContext>({\n Left: (error) => ({ type: ClearSignContextType.ERROR, error }),\n Right: (payload) => ({ type: ClearSignContextType.TOKEN, payload }),\n }),\n );\n } catch (_) {\n return [];\n }\n }\n\n /**\n * Extracts Uniswap-supported commands from a hexadecimal string.\n * Each command is represented by one byte (2 hex characters), and this function:\n * - Maps each command to a known Uniswap command.\n * - Returns `Nothing` if any extracted command is unsupported.\n *\n * @private\n * @param {HexaString} hex - A hexadecimal string representing commands.\n * @returns {Maybe<UniswapSupportedCommand[]>} - A `Maybe` containing an array of recognized commands, or `Nothing` if any command is unsupported.\n *\n * @example\n * // Valid command extraction\n * _extractCommands('0x0008');\n * // Returns: Just(['0x00', '0x08'])\n *\n * @example\n * // Contains an unsupported command (0x05 is not supported)\n * _extractCommands('0x0005');\n * // Returns: Nothing\n *\n * @example\n * // Empty or invalid input\n * _extractCommands('0x');\n * // Returns: Nothing\n */\n private _extractCommands(hex: HexaString): Maybe<UniswapSupportedCommand[]> {\n return Maybe.fromNullable(hex.slice(2).match(/../g))\n .map((bytes) => bytes.map((b) => `0x${b}` as HexaString))\n .map((hexBytes) => hexBytes.map((b) => UNISWAP_COMMANDS[b]))\n .chain((commands) =>\n commands.every((command) => command !== undefined)\n ? Maybe.of(commands as UniswapSupportedCommand[])\n : Nothing,\n );\n }\n\n /**\n * Checks if the provided swap commands can be chained together.\n * A valid chain requires that:\n * - The output asset of the previous swap matches the input asset of the next swap.\n * - The pool version remains consistent across swaps.\n *\n * @private\n * @param {Array<[UniswapSupportedCommand, HexaString[]]>} data - An array of tuples containing a swap command and associated addresses.\n * @returns {boolean} - Returns `true` if the swap commands form a valid chain, otherwise `false`.\n *\n * @example\n * // Valid chaining: same output/input asset and pool version\n * _isChainingSwapSupported([\n * ['0x08', ['0xABC', '0xDEF']],\n * ['0x08', ['0xDEF', '0x123']]\n * ]);\n * // Returns: true\n *\n * @example\n * // Invalid chaining: different pool versions\n * _isChainingSwapSupported([\n * ['0x08', ['0xABC', '0xDEF']],\n * ['0x01', ['0xDEF', '0x123']]\n * ]);\n * // Returns: false\n *\n * @example\n * // Invalid chaining: output does not match next input\n * _isChainingSwapSupported([\n * ['0x01A1', ['0xABC', '0xDEF']],\n * ['0x01B2', ['0xXYZ', '0x123']]\n * ]);\n * // Returns: false\n */\n private _isChainingSwapSupported(\n data: [UniswapSupportedCommand, HexaString[]][],\n ): boolean {\n let lastAsset: HexaString | undefined = undefined;\n let lastPoolVersion: string | undefined = undefined;\n\n for (const [command, addresses] of data) {\n if (!UNISWAP_SWAP_COMMANDS.includes(command)) continue; // Ignore non-swap commands\n\n const poolVersion = command.slice(0, 2);\n\n if (\n lastAsset &&\n (lastAsset !== addresses[0] || lastPoolVersion !== poolVersion)\n ) {\n // Invalid chaining, return empty array\n return false;\n }\n\n // update last asset and pool version\n lastAsset = addresses[addresses.length - 1];\n lastPoolVersion = poolVersion;\n }\n\n return true;\n }\n\n /**\n * Checks if a given value is an array of hexadecimal strings.\n *\n * @private\n * @param {unknown} array - The value to check.\n * @returns {array is HexaString[]} - `true` if the value is an array of hexadecimal strings, otherwise `false`.\n */\n private _isHexaStringArray(array: unknown): array is HexaString[] {\n return (\n Array.isArray(array) &&\n array.every((item) => typeof item === \"string\" && isHexaString(item))\n );\n }\n}\n"],
5
+ "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAMO,2CACPC,EAA0B,kBAC1BC,EAAmC,qBACnCC,EAA+B,qBAG/BC,EAGO,2CAGPC,EAA2B,iCAC3BC,EAGO,sCACPC,EAOO,uCAEPC,EAA6B,qCAGtB,IAAMC,EAAN,KAAoD,CACzD,YAEUC,EAEAC,EACR,CAHQ,8BAAAD,EAEA,qBAAAC,CACP,CAEH,MAAM,KAAKC,EAA8D,CACvE,GAAI,CAACA,EAAY,MAAQ,IAAC,gBAAaA,EAAY,IAAI,EACrD,MAAO,CAAC,EAIV,GADiBA,EAAY,KAAK,MAAM,EAAG,EAAE,IAC5B,2BACf,MAAO,CAAC,EAGV,MAAMC,EAAwB,KAAK,+BAA+B,EAC5DC,EAAgB,MAAM,KAAK,0BAC/BF,EAAY,KACZA,EAAY,OACd,EAEA,OAAIE,EAAc,OAAS,EAClB,CA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S", "import_device_management_kit", "import_ethers", "import_inversify", "import_purify_ts", "import_ClearSignContext", "import_tokenTypes", "import_plugin", "import_uniswap", "import_uniswapTypes", "UniswapContextLoader", "commandDecoderDataSource", "tokenDataSource", "transaction", "externalPluginContext", "tokenContexts", "buffer", "calldata", "chainId", "tx", "commands", "inputs", "decodedCommands", "addressesByCommand", "acc", "command", "index", "input", "decoded", "uniqueAddresses", "addresses", "address", "either", "error", "payload", "hex", "bytes", "b", "hexBytes", "data", "lastAsset", "lastPoolVersion", "poolVersion", "array", "item", "__decorateClass", "__decorateParam"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var s=require("ethers"),r=require("purify-ts"),f=require("../../shared/model/ClearSignContext"),e=require("../../uniswap/constants/uniswap"),l=require("../../uniswap/data/DefaultCommandDecoderDataSource"),x=require("../../uniswap/data/EthersAbiDecoderDataSource"),p=require("./UniswapContextLoader");describe("UniswapContextLoader",()=>{const t={decode:vi.fn()},o={getTokenInfosPayload:vi.fn()};let c;describe("load",()=>{describe("with tokenDataSourceMock",()=>{beforeEach(()=>{vi.spyOn(o,"getTokenInfosPayload").mockImplementation(({address:a})=>Promise.resolve((0,r.Right)(`payload-${a}`))),c=new p.UniswapContextLoader(new l.DefaultCommandDecoderDataSource(new x.EthersAbiDecoderDataSource),o)}),it("should return the external plugin context and the decoded contexts",async()=>{const a={chainId:1,data:"0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000067a4855b000000000000000000000000000000000000000000000000000000000000000300060c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000a18f07d736b90be5500000000000000000000000000000000000000000000000000000000b0b8122abd8412900000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002bb9f599ce614feb2e1bbe58f180f370d05b39344e002710c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000017cc6042605381c158d2adab487434bde79aa61c000000000000000000000000000000000000000000000000000000000000005b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000b0b8122abd84129c001a053efc49d03b694742500f49aa09df2360bd7e297fa730c745e0d4320b42fc33fa01ca1c85a46c561f624830fffbae2441ba0f2d54eb5b0f17e0e3561d10db0b7ee"},n=await c.load(a);expect(n).toEqual([{type:f.ClearSignContextType.EXTERNAL_PLUGIN,payload:"07556e69737761703fc91a3afd70395cd496c647d5a6cc9d4b2b7fad3593564c3044022014391e8f355867a57fe88f6a5a4dbcb8bf8f888a9db3ff3449caf72d120396bd02200c13d9c3f79400fe0aa0434ac54d59b79503c9964a4abc3e8cd22763e0242935"},{type:"token",payload:"payload-0xb9f599ce614feb2e1bbe58f180f370d05b39344e"},{type:"token",payload:"payload-0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"}])}),it("should return the external plugin context and the decoded contexts with a permit",async()=>{const a={chainId:1,data:"0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000669b9ec100000000000000000000000000000000000000000000000000000000000000030a010c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000016000000000000000000000000055747be9f9f5beb232ad59fe7af013b81d95fd5e000000000000000000000000ffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000066c32b0d0000000000000000000000000000000000000000000000000000000000000008000000000000000000000000ef1c6e67703c7bd7107eed8303fbe6ec2554bf6b00000000000000000000000000000000000000000000000000000000669b9ec100000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000410d756f55acf289e9754faf91bba0a704b5c7c0aa4b1dfd551115ccbe4c7f290234e1a14265e1da0bc872a23627d997fe37a689c290d519f7b8c9bdde1b79108e1b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000030ba49cbff5a00000000000000000000000000000000000000000000000089677c957272141800000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002bc02aaa39b223fe8d0a0e5c4f27ead9083c756cc200271055747be9f9f5beb232ad59fe7af013b81d95fd5e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000030ba49cbff5a000c001a0e406d9c91c8b46d959fcd31a28518a77bb248ebb316c5fab7b98335cce922f2aa0462cb970c32a8dbfe71c57b888c43b9ed04fce41d169dbfcc745445587adb771"},n=await c.load(a);expect(n).toEqual([{type:f.ClearSignContextType.EXTERNAL_PLUGIN,payload:"07556e69737761703fc91a3afd70395cd496c647d5a6cc9d4b2b7fad3593564c3044022014391e8f355867a57fe88f6a5a4dbcb8bf8f888a9db3ff3449caf72d120396bd02200c13d9c3f79400fe0aa0434ac54d59b79503c9964a4abc3e8cd22763e0242935"},{type:"token",payload:"payload-0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"},{type:"token",payload:"payload-0x55747be9f9f5beb232ad59fe7af013b81d95fd5e"}])}),it("should return an empty array if the transaction is not supported",async()=>{const a={};vi.spyOn(t,"decode").mockReturnValue([]);const n=await c.load(a);expect(n).toEqual([])}),it("should return an empty array if a command is not supported",async()=>{const a={chainId:1,data:"0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000067a4bef600000000000000000000000000000000000000000000000000000000000000050b0105040c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000032000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000078e6708e70aed0f000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000059a16770000000000000000000000000000000000000000000000000078e6708e70aed0f00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002ba0b86991c6218b36c1d19d4a2e9eb0ce3606eb480001f4c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000027213e28d7fda5c57fe9e5dd923818dbccf71c4700000000000000000000000000000000000000000000000000000000003938700000000000000000000000000000000000000000000000000000000000000060000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000006f939b43d65be049b7533907db08e80ba6969f450000000000000000000000000000000000000000000000000000000059682f0000000000000000000000000000000000000000000000000000000000000000400000000000000000000000006f939b43d65be049b7533907db08e80ba6969f4500000000000000000000000000000000000000000000000000000000000000000cc080a07c86dd5813ec1f3725c402f8bea6105546d1093c59676023b971f1d83f61bd4ea02a353bf3028cabcbe68c5dc8906752bafe55afc86b6344edb3ffd8a3650332e8"},n=await c.load(a);expect(n).toEqual([])})}),describe("with mocked ethers parseTransaction",()=>{beforeEach(()=>{vi.resetAllMocks(),c=new p.UniswapContextLoader(t,o)}),it("should return an array with contexts if 2 chain swaps are supported",async()=>{const a={to:e.UNISWAP_UNIVERSAL_ROUTER_ADDRESS,data:e.UNISWAP_EXECUTE_SELECTOR,chainId:66};vi.spyOn(s.Interface.prototype,"parseTransaction").mockReturnValue({args:["0x0809",["0x0001","0x0002"]]}),vi.spyOn(t,"decode").mockReturnValueOnce(["0x01","0x04","0x02"]),vi.spyOn(t,"decode").mockReturnValueOnce(["0x02","0x03"]),vi.spyOn(o,"getTokenInfosPayload").mockImplementation(({address:i})=>Promise.resolve((0,r.Right)(`payload-${i}`)));const d=await c.load(a);expect(t.decode).toHaveBeenNthCalledWith(1,e.UniswapSupportedCommand.V2_SWAP_EXACT_IN,"0x0001",66),expect(t.decode).toHaveBeenNthCalledWith(2,e.UniswapSupportedCommand.V2_SWAP_EXACT_OUT,"0x0002",66),expect(o.getTokenInfosPayload).toHaveBeenNthCalledWith(1,{address:"0x01",chainId:66}),expect(o.getTokenInfosPayload).toHaveBeenNthCalledWith(2,{address:"0x04",chainId:66}),expect(o.getTokenInfosPayload).toHaveBeenNthCalledWith(3,{address:"0x02",chainId:66}),expect(o.getTokenInfosPayload).toHaveBeenNthCalledWith(4,{address:"0x03",chainId:66}),expect(d).toEqual([{type:f.ClearSignContextType.EXTERNAL_PLUGIN,payload:"07556e69737761703fc91a3afd70395cd496c647d5a6cc9d4b2b7fad3593564c3044022014391e8f355867a57fe88f6a5a4dbcb8bf8f888a9db3ff3449caf72d120396bd02200c13d9c3f79400fe0aa0434ac54d59b79503c9964a4abc3e8cd22763e0242935"},{type:"token",payload:"payload-0x01"},{type:"token",payload:"payload-0x04"},{type:"token",payload:"payload-0x02"},{type:"token",payload:"payload-0x03"}])}),it("should return an array with contexts if 1 chain swap with a non swap command",async()=>{const a={to:e.UNISWAP_UNIVERSAL_ROUTER_ADDRESS,data:e.UNISWAP_EXECUTE_SELECTOR,chainId:66};vi.spyOn(s.Interface.prototype,"parseTransaction").mockReturnValue({args:["0x0b0004",["0x0001","0x0002","0x0003"]]}),vi.spyOn(t,"decode").mockReturnValueOnce(["0x01"]),vi.spyOn(t,"decode").mockReturnValueOnce(["0x02","0x03"]),vi.spyOn(t,"decode").mockReturnValueOnce(["0x04"]),vi.spyOn(o,"getTokenInfosPayload").mockImplementation(({address:i})=>Promise.resolve((0,r.Right)(`payload-${i}`)));const d=await c.load(a);expect(t.decode).toHaveBeenNthCalledWith(1,e.UniswapSupportedCommand.WRAP_ETH,"0x0001",66),expect(o.getTokenInfosPayload).toHaveBeenNthCalledWith(1,{address:"0x01",chainId:66}),expect(o.getTokenInfosPayload).toHaveBeenNthCalledWith(2,{address:"0x02",chainId:66}),expect(o.getTokenInfosPayload).toHaveBeenNthCalledWith(3,{address:"0x03",chainId:66}),expect(o.getTokenInfosPayload).toHaveBeenNthCalledWith(4,{address:"0x04",chainId:66}),expect(d).toEqual([{type:f.ClearSignContextType.EXTERNAL_PLUGIN,payload:"07556e69737761703fc91a3afd70395cd496c647d5a6cc9d4b2b7fad3593564c3044022014391e8f355867a57fe88f6a5a4dbcb8bf8f888a9db3ff3449caf72d120396bd02200c13d9c3f79400fe0aa0434ac54d59b79503c9964a4abc3e8cd22763e0242935"},{type:"token",payload:"payload-0x01"},{type:"token",payload:"payload-0x02"},{type:"token",payload:"payload-0x03"},{type:"token",payload:"payload-0x04"}])}),it("should return an array with contexts if one token is not found",async()=>{const a={to:e.UNISWAP_UNIVERSAL_ROUTER_ADDRESS,data:e.UNISWAP_EXECUTE_SELECTOR,chainId:66};vi.spyOn(s.Interface.prototype,"parseTransaction").mockReturnValue({args:["0x0809",["0x0001","0x0002"]]}),vi.spyOn(t,"decode").mockReturnValueOnce(["0x01","0x02"]),vi.spyOn(t,"decode").mockReturnValueOnce(["0x02","0x03"]),vi.spyOn(o,"getTokenInfosPayload").mockResolvedValueOnce((0,r.Left)("error")),vi.spyOn(o,"getTokenInfosPayload").mockImplementation(({address:i})=>Promise.resolve((0,r.Right)(`payload-${i}`)));const d=await c.load(a);expect(t.decode).toHaveBeenNthCalledWith(1,e.UniswapSupportedCommand.V2_SWAP_EXACT_IN,"0x0001",66),expect(t.decode).toHaveBeenNthCalledWith(2,e.UniswapSupportedCommand.V2_SWAP_EXACT_OUT,"0x0002",66),expect(o.getTokenInfosPayload).toHaveBeenNthCalledWith(1,{address:"0x01",chainId:66}),expect(o.getTokenInfosPayload).toHaveBeenNthCalledWith(2,{address:"0x02",chainId:66}),expect(o.getTokenInfosPayload).toHaveBeenNthCalledWith(3,{address:"0x03",chainId:66}),expect(d).toEqual([{type:f.ClearSignContextType.EXTERNAL_PLUGIN,payload:"07556e69737761703fc91a3afd70395cd496c647d5a6cc9d4b2b7fad3593564c3044022014391e8f355867a57fe88f6a5a4dbcb8bf8f888a9db3ff3449caf72d120396bd02200c13d9c3f79400fe0aa0434ac54d59b79503c9964a4abc3e8cd22763e0242935"},{type:"error",error:"error"},{type:"token",payload:"payload-0x02"},{type:"token",payload:"payload-0x03"}])}),it("should return an empty array if the if 2 chain swaps are not supported",async()=>{const a={to:e.UNISWAP_UNIVERSAL_ROUTER_ADDRESS,data:e.UNISWAP_EXECUTE_SELECTOR,chainId:66};vi.spyOn(s.Interface.prototype,"parseTransaction").mockReturnValue({args:["0x0809",["0x0001","0x0002"]]}),vi.spyOn(t,"decode").mockReturnValueOnce(["0x01","0x02"]),vi.spyOn(t,"decode").mockReturnValueOnce(["0x03","0x04"]);const d=await c.load(a);expect(t.decode).toHaveBeenNthCalledWith(1,e.UniswapSupportedCommand.V2_SWAP_EXACT_IN,"0x0001",66),expect(t.decode).toHaveBeenNthCalledWith(2,e.UniswapSupportedCommand.V2_SWAP_EXACT_OUT,"0x0002",66),expect(o.getTokenInfosPayload).not.toHaveBeenCalled(),expect(d).toEqual([])}),it("should return an empty array if no command are returned from parseTransaction",async()=>{const a={to:e.UNISWAP_UNIVERSAL_ROUTER_ADDRESS,data:e.UNISWAP_EXECUTE_SELECTOR};vi.spyOn(s.Interface.prototype,"parseTransaction").mockReturnValue({args:[""]});const n=await c.load(a);expect(t.decode).not.toHaveBeenCalled(),expect(o.getTokenInfosPayload).not.toHaveBeenCalled(),expect(n).toEqual([])}),it("should return an empty array if no inputs are returned from parseTransaction",async()=>{const a={to:e.UNISWAP_UNIVERSAL_ROUTER_ADDRESS,data:e.UNISWAP_EXECUTE_SELECTOR};vi.spyOn(s.Interface.prototype,"parseTransaction").mockReturnValue({args:["0x08",[]]});const n=await c.load(a);expect(o.getTokenInfosPayload).not.toHaveBeenCalled(),expect(n).toEqual([])}),it("should return an empty array if parseTransaction throws an error",async()=>{const a={to:e.UNISWAP_UNIVERSAL_ROUTER_ADDRESS,data:e.UNISWAP_EXECUTE_SELECTOR};vi.spyOn(s.Interface.prototype,"parseTransaction").mockImplementation(()=>{throw new Error});const n=await c.load(a);expect(t.decode).not.toHaveBeenCalled(),expect(o.getTokenInfosPayload).not.toHaveBeenCalled(),expect(n).toEqual([])}),it("should return an empty array if the swap is with multiple pool versions",async()=>{const a={to:e.UNISWAP_UNIVERSAL_ROUTER_ADDRESS,data:e.UNISWAP_EXECUTE_SELECTOR,chainId:66};vi.spyOn(s.Interface.prototype,"parseTransaction").mockReturnValue({args:["0x080900",["0x00","0x01","0x02"]]}),vi.spyOn(t,"decode").mockReturnValue(["0x01","0x02"]);const d=await c.load(a);expect(t.decode).toHaveBeenNthCalledWith(1,e.UniswapSupportedCommand.V2_SWAP_EXACT_IN,"0x00",66),expect(t.decode).toHaveBeenNthCalledWith(2,e.UniswapSupportedCommand.V2_SWAP_EXACT_OUT,"0x01",66),expect(t.decode).toHaveBeenNthCalledWith(3,e.UniswapSupportedCommand.V3_SWAP_EXACT_IN,"0x02",66),expect(o.getTokenInfosPayload).not.toHaveBeenCalled(),expect(d).toEqual([])}),it("should return an empty array if the selector is not supported",async()=>{const a={to:e.UNISWAP_UNIVERSAL_ROUTER_ADDRESS,data:"0x00000000",chainId:66},n=await c.load(a);expect(t.decode).not.toHaveBeenCalled(),expect(o.getTokenInfosPayload).not.toHaveBeenCalled(),expect(n).toEqual([])}),it("should return an empty array if the length of the commands and inputs are different",async()=>{const a={to:e.UNISWAP_UNIVERSAL_ROUTER_ADDRESS,data:e.UNISWAP_EXECUTE_SELECTOR,chainId:66};vi.spyOn(s.Interface.prototype,"parseTransaction").mockReturnValue({args:["0x0809",["0x0001"]]});const d=await c.load(a);expect(t.decode).not.toHaveBeenCalled(),expect(o.getTokenInfosPayload).not.toHaveBeenCalled(),expect(d).toEqual([])})})})});
2
+ //# sourceMappingURL=UniswapContextLoader.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/uniswap/domain/UniswapContextLoader.test.ts"],
4
+ "sourcesContent": ["import { Interface, type TransactionDescription } from \"ethers\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport { type TransactionContext } from \"@/shared/model/TransactionContext\";\nimport { type HttpTokenDataSource } from \"@/token/data/HttpTokenDataSource\";\nimport {\n UNISWAP_EXECUTE_SELECTOR,\n UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n UniswapSupportedCommand,\n} from \"@/uniswap/constants/uniswap\";\nimport { type CommandDecoderDataSource } from \"@/uniswap/data/CommandDecoderDataSource\";\nimport { DefaultCommandDecoderDataSource } from \"@/uniswap/data/DefaultCommandDecoderDataSource\";\nimport { EthersAbiDecoderDataSource } from \"@/uniswap/data/EthersAbiDecoderDataSource\";\n\nimport { UniswapContextLoader } from \"./UniswapContextLoader\";\n\ndescribe(\"UniswapContextLoader\", () => {\n const commandDecoderMock: CommandDecoderDataSource = {\n decode: vi.fn(),\n };\n const tokenDataSourceMock = {\n getTokenInfosPayload: vi.fn(),\n };\n let loader: UniswapContextLoader;\n\n describe(\"load\", () => {\n describe(\"with tokenDataSourceMock\", () => {\n beforeEach(() => {\n vi.spyOn(\n tokenDataSourceMock,\n \"getTokenInfosPayload\",\n ).mockImplementation(({ address }) =>\n Promise.resolve(Right(`payload-${address}`)),\n );\n loader = new UniswapContextLoader(\n new DefaultCommandDecoderDataSource(new EthersAbiDecoderDataSource()),\n tokenDataSourceMock as unknown as HttpTokenDataSource,\n );\n });\n\n it(\"should return the external plugin context and the decoded contexts\", async () => {\n // GIVEN\n // https://etherscan.io/getRawTx?tx=0xc9821c32c1782d9ab6baf6f9ca4b2565bce11aaf5146a2d303215bda026f5e48\n const transactionContext = {\n chainId: 1,\n data: \"0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000067a4855b000000000000000000000000000000000000000000000000000000000000000300060c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000a18f07d736b90be5500000000000000000000000000000000000000000000000000000000b0b8122abd8412900000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002bb9f599ce614feb2e1bbe58f180f370d05b39344e002710c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000017cc6042605381c158d2adab487434bde79aa61c000000000000000000000000000000000000000000000000000000000000005b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000b0b8122abd84129c001a053efc49d03b694742500f49aa09df2360bd7e297fa730c745e0d4320b42fc33fa01ca1c85a46c561f624830fffbae2441ba0f2d54eb5b0f17e0e3561d10db0b7ee\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload:\n \"07556e69737761703fc91a3afd70395cd496c647d5a6cc9d4b2b7fad3593564c3044022014391e8f355867a57fe88f6a5a4dbcb8bf8f888a9db3ff3449caf72d120396bd02200c13d9c3f79400fe0aa0434ac54d59b79503c9964a4abc3e8cd22763e0242935\",\n },\n {\n type: \"token\",\n payload: \"payload-0xb9f599ce614feb2e1bbe58f180f370d05b39344e\",\n }, // ERC20\n {\n type: \"token\",\n payload: \"payload-0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2\",\n }, // WETH\n ]);\n });\n\n it(\"should return the external plugin context and the decoded contexts with a permit\", async () => {\n // GIVEN\n // https://etherscan.io/getRawTx?tx=0xc4df7ccc0527541d0e80856a8f38deedc48c84825e9355469ba02d873502ce2f\n // PERMIT2_PERMIT, V3_SWAP_EXACT_OUT, UNWRAP_ETH\n const transactionContext = {\n chainId: 1,\n data: \"0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000669b9ec100000000000000000000000000000000000000000000000000000000000000030a010c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000016000000000000000000000000055747be9f9f5beb232ad59fe7af013b81d95fd5e000000000000000000000000ffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000066c32b0d0000000000000000000000000000000000000000000000000000000000000008000000000000000000000000ef1c6e67703c7bd7107eed8303fbe6ec2554bf6b00000000000000000000000000000000000000000000000000000000669b9ec100000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000410d756f55acf289e9754faf91bba0a704b5c7c0aa4b1dfd551115ccbe4c7f290234e1a14265e1da0bc872a23627d997fe37a689c290d519f7b8c9bdde1b79108e1b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000030ba49cbff5a00000000000000000000000000000000000000000000000089677c957272141800000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002bc02aaa39b223fe8d0a0e5c4f27ead9083c756cc200271055747be9f9f5beb232ad59fe7af013b81d95fd5e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000030ba49cbff5a000c001a0e406d9c91c8b46d959fcd31a28518a77bb248ebb316c5fab7b98335cce922f2aa0462cb970c32a8dbfe71c57b888c43b9ed04fce41d169dbfcc745445587adb771\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload:\n \"07556e69737761703fc91a3afd70395cd496c647d5a6cc9d4b2b7fad3593564c3044022014391e8f355867a57fe88f6a5a4dbcb8bf8f888a9db3ff3449caf72d120396bd02200c13d9c3f79400fe0aa0434ac54d59b79503c9964a4abc3e8cd22763e0242935\",\n },\n {\n type: \"token\",\n payload: \"payload-0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2\",\n }, // WETH\n {\n type: \"token\",\n payload: \"payload-0x55747be9f9f5beb232ad59fe7af013b81d95fd5e\",\n }, // ERC20\n ]);\n });\n\n it(\"should return an empty array if the transaction is not supported\", async () => {\n // GIVEN\n const transactionContext = {} as TransactionContext;\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValue([]);\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if a command is not supported\", async () => {\n // GIVEN\n // https://etherscan.io/getRawTx?tx=0xa628c8b3da2ad984aed0354d8ca4b4c3c42941491dc4e0d6a5f423fd65e6c90a\n // The command 0x05 (TRANSFER) is not supported\n const transactionContext = {\n chainId: 1,\n data: \"0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000067a4bef600000000000000000000000000000000000000000000000000000000000000050b0105040c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000032000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000078e6708e70aed0f000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000059a16770000000000000000000000000000000000000000000000000078e6708e70aed0f00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002ba0b86991c6218b36c1d19d4a2e9eb0ce3606eb480001f4c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000027213e28d7fda5c57fe9e5dd923818dbccf71c4700000000000000000000000000000000000000000000000000000000003938700000000000000000000000000000000000000000000000000000000000000060000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000006f939b43d65be049b7533907db08e80ba6969f450000000000000000000000000000000000000000000000000000000059682f0000000000000000000000000000000000000000000000000000000000000000400000000000000000000000006f939b43d65be049b7533907db08e80ba6969f4500000000000000000000000000000000000000000000000000000000000000000cc080a07c86dd5813ec1f3725c402f8bea6105546d1093c59676023b971f1d83f61bd4ea02a353bf3028cabcbe68c5dc8906752bafe55afc86b6344edb3ffd8a3650332e8\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(result).toEqual([]);\n });\n });\n\n describe(\"with mocked ethers parseTransaction\", () => {\n beforeEach(() => {\n vi.resetAllMocks();\n loader = new UniswapContextLoader(\n commandDecoderMock,\n tokenDataSourceMock as unknown as HttpTokenDataSource,\n );\n });\n\n it(\"should return an array with contexts if 2 chain swaps are supported\", async () => {\n // GIVEN\n const transactionContext = {\n to: UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n data: UNISWAP_EXECUTE_SELECTOR,\n chainId: 0x42,\n } as TransactionContext;\n const commands = `0x0809`; // V2_SWAP_EXACT_IN, V2_SWAP_EXACT_OUT\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [commands, [\"0x0001\", \"0x0002\"]],\n } as TransactionDescription);\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValueOnce([\n \"0x01\",\n \"0x04\",\n \"0x02\",\n ]);\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValueOnce([\n \"0x02\",\n \"0x03\",\n ]);\n vi.spyOn(\n tokenDataSourceMock,\n \"getTokenInfosPayload\",\n ).mockImplementation(({ address }) =>\n Promise.resolve(Right(`payload-${address}`)),\n );\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 1,\n UniswapSupportedCommand.V2_SWAP_EXACT_IN,\n \"0x0001\",\n 0x42,\n );\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 2,\n UniswapSupportedCommand.V2_SWAP_EXACT_OUT,\n \"0x0002\",\n 0x42,\n );\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(1, { address: \"0x01\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(2, { address: \"0x04\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(3, { address: \"0x02\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(4, { address: \"0x03\", chainId: 0x42 });\n expect(result).toEqual([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload:\n \"07556e69737761703fc91a3afd70395cd496c647d5a6cc9d4b2b7fad3593564c3044022014391e8f355867a57fe88f6a5a4dbcb8bf8f888a9db3ff3449caf72d120396bd02200c13d9c3f79400fe0aa0434ac54d59b79503c9964a4abc3e8cd22763e0242935\",\n },\n {\n type: \"token\",\n payload: \"payload-0x01\",\n },\n {\n type: \"token\",\n payload: \"payload-0x04\",\n },\n {\n type: \"token\",\n payload: \"payload-0x02\",\n },\n {\n type: \"token\",\n payload: \"payload-0x03\",\n },\n ]);\n });\n\n it(\"should return an array with contexts if 1 chain swap with a non swap command\", async () => {\n // GIVEN\n const transactionContext = {\n to: UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n data: UNISWAP_EXECUTE_SELECTOR,\n chainId: 0x42,\n } as TransactionContext;\n const commands = `0x0b0004`; // WRAP_ETH, V3_SWAP_EXACT_IN, SWEEP\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [commands, [\"0x0001\", \"0x0002\", \"0x0003\"]],\n } as TransactionDescription);\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValueOnce([\"0x01\"]);\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValueOnce([\n \"0x02\",\n \"0x03\",\n ]);\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValueOnce([\"0x04\"]);\n vi.spyOn(\n tokenDataSourceMock,\n \"getTokenInfosPayload\",\n ).mockImplementation(({ address }) =>\n Promise.resolve(Right(`payload-${address}`)),\n );\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 1,\n UniswapSupportedCommand.WRAP_ETH,\n \"0x0001\",\n 0x42,\n );\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(1, { address: \"0x01\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(2, { address: \"0x02\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(3, { address: \"0x03\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(4, { address: \"0x04\", chainId: 0x42 });\n expect(result).toEqual([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload:\n \"07556e69737761703fc91a3afd70395cd496c647d5a6cc9d4b2b7fad3593564c3044022014391e8f355867a57fe88f6a5a4dbcb8bf8f888a9db3ff3449caf72d120396bd02200c13d9c3f79400fe0aa0434ac54d59b79503c9964a4abc3e8cd22763e0242935\",\n },\n {\n type: \"token\",\n payload: \"payload-0x01\",\n },\n {\n type: \"token\",\n payload: \"payload-0x02\",\n },\n {\n type: \"token\",\n payload: \"payload-0x03\",\n },\n {\n type: \"token\",\n payload: \"payload-0x04\",\n },\n ]);\n });\n\n it(\"should return an array with contexts if one token is not found\", async () => {\n // GIVEN\n const transactionContext = {\n to: UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n data: UNISWAP_EXECUTE_SELECTOR,\n chainId: 0x42,\n } as TransactionContext;\n const commands = `0x0809`; // V2_SWAP_EXACT_IN, V2_SWAP_EXACT_OUT\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [commands, [\"0x0001\", \"0x0002\"]],\n } as TransactionDescription);\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValueOnce([\n \"0x01\",\n \"0x02\",\n ]);\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValueOnce([\n \"0x02\",\n \"0x03\",\n ]);\n vi.spyOn(\n tokenDataSourceMock,\n \"getTokenInfosPayload\",\n ).mockResolvedValueOnce(Left(\"error\"));\n vi.spyOn(\n tokenDataSourceMock,\n \"getTokenInfosPayload\",\n ).mockImplementation(({ address }) =>\n Promise.resolve(Right(`payload-${address}`)),\n );\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 1,\n UniswapSupportedCommand.V2_SWAP_EXACT_IN,\n \"0x0001\",\n 0x42,\n );\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 2,\n UniswapSupportedCommand.V2_SWAP_EXACT_OUT,\n \"0x0002\",\n 0x42,\n );\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(1, { address: \"0x01\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(2, { address: \"0x02\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(3, { address: \"0x03\", chainId: 0x42 });\n expect(result).toEqual([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload:\n \"07556e69737761703fc91a3afd70395cd496c647d5a6cc9d4b2b7fad3593564c3044022014391e8f355867a57fe88f6a5a4dbcb8bf8f888a9db3ff3449caf72d120396bd02200c13d9c3f79400fe0aa0434ac54d59b79503c9964a4abc3e8cd22763e0242935\",\n },\n {\n type: \"error\",\n error: \"error\",\n },\n {\n type: \"token\",\n payload: \"payload-0x02\",\n },\n {\n type: \"token\",\n payload: \"payload-0x03\",\n },\n ]);\n });\n\n it(\"should return an empty array if the if 2 chain swaps are not supported\", async () => {\n // GIVEN\n const transactionContext = {\n to: UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n data: UNISWAP_EXECUTE_SELECTOR,\n chainId: 0x42,\n } as TransactionContext;\n const commands = `0x0809`; // V2_SWAP_EXACT_IN, V2_SWAP_EXACT_OUT\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [commands, [\"0x0001\", \"0x0002\"]],\n } as TransactionDescription);\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValueOnce([\n \"0x01\",\n \"0x02\",\n ]);\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValueOnce([\n \"0x03\", // should be 0x02\n \"0x04\",\n ]);\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 1,\n UniswapSupportedCommand.V2_SWAP_EXACT_IN,\n \"0x0001\",\n 0x42,\n );\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 2,\n UniswapSupportedCommand.V2_SWAP_EXACT_OUT,\n \"0x0002\",\n 0x42,\n );\n expect(tokenDataSourceMock.getTokenInfosPayload).not.toHaveBeenCalled();\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if no command are returned from parseTransaction\", async () => {\n // GIVEN\n const transactionContext = {\n to: UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n data: UNISWAP_EXECUTE_SELECTOR,\n } as TransactionContext;\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [\"\"],\n } as TransactionDescription);\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(commandDecoderMock.decode).not.toHaveBeenCalled();\n expect(tokenDataSourceMock.getTokenInfosPayload).not.toHaveBeenCalled();\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if no inputs are returned from parseTransaction\", async () => {\n // GIVEN\n const transactionContext = {\n to: UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n data: UNISWAP_EXECUTE_SELECTOR,\n } as TransactionContext;\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [\"0x08\", []],\n } as TransactionDescription);\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(tokenDataSourceMock.getTokenInfosPayload).not.toHaveBeenCalled();\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if parseTransaction throws an error\", async () => {\n // GIVEN\n const transactionContext = {\n to: UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n data: UNISWAP_EXECUTE_SELECTOR,\n } as TransactionContext;\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockImplementation(\n () => {\n throw new Error();\n },\n );\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(commandDecoderMock.decode).not.toHaveBeenCalled();\n expect(tokenDataSourceMock.getTokenInfosPayload).not.toHaveBeenCalled();\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if the swap is with multiple pool versions\", async () => {\n // GIVEN\n const transactionContext = {\n to: UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n data: UNISWAP_EXECUTE_SELECTOR,\n chainId: 0x42,\n } as TransactionContext;\n const commands = `0x080900`; // V2_SWAP_EXACT_IN, V2_SWAP_EXACT_OUT, V3_SWAP_EXACT_IN\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [commands, [\"0x00\", \"0x01\", \"0x02\"]],\n } as TransactionDescription);\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValue([\n \"0x01\",\n \"0x02\",\n ]);\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 1,\n UniswapSupportedCommand.V2_SWAP_EXACT_IN,\n \"0x00\",\n 0x42,\n );\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 2,\n UniswapSupportedCommand.V2_SWAP_EXACT_OUT,\n \"0x01\",\n 0x42,\n );\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 3,\n UniswapSupportedCommand.V3_SWAP_EXACT_IN,\n \"0x02\",\n 0x42,\n );\n expect(tokenDataSourceMock.getTokenInfosPayload).not.toHaveBeenCalled();\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if the selector is not supported\", async () => {\n // GIVEN\n const transactionContext = {\n to: UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n data: \"0x00000000\",\n chainId: 0x42,\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(commandDecoderMock.decode).not.toHaveBeenCalled();\n expect(tokenDataSourceMock.getTokenInfosPayload).not.toHaveBeenCalled();\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if the length of the commands and inputs are different\", async () => {\n // GIVEN\n const transactionContext = {\n to: UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n data: UNISWAP_EXECUTE_SELECTOR,\n chainId: 0x42,\n } as TransactionContext;\n const commands = `0x0809`; // V2_SWAP_EXACT_IN, V2_SWAP_EXACT_OUT\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [commands, [\"0x0001\"]],\n } as TransactionDescription);\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(commandDecoderMock.decode).not.toHaveBeenCalled();\n expect(tokenDataSourceMock.getTokenInfosPayload).not.toHaveBeenCalled();\n expect(result).toEqual([]);\n });\n });\n });\n});\n"],
5
+ "mappings": "aAAA,IAAAA,EAAuD,kBACvDC,EAA4B,qBAE5BC,EAAqC,2CAGrCC,EAIO,uCAEPC,EAAgD,0DAChDC,EAA2C,qDAE3CC,EAAqC,kCAErC,SAAS,uBAAwB,IAAM,CACrC,MAAMC,EAA+C,CACnD,OAAQ,GAAG,GAAG,CAChB,EACMC,EAAsB,CAC1B,qBAAsB,GAAG,GAAG,CAC9B,EACA,IAAIC,EAEJ,SAAS,OAAQ,IAAM,CACrB,SAAS,2BAA4B,IAAM,CACzC,WAAW,IAAM,CACf,GAAG,MACDD,EACA,sBACF,EAAE,mBAAmB,CAAC,CAAE,QAAAE,CAAQ,IAC9B,QAAQ,WAAQ,SAAM,WAAWA,CAAO,EAAE,CAAC,CAC7C,EACAD,EAAS,IAAI,uBACX,IAAI,kCAAgC,IAAI,4BAA4B,EACpED,CACF,CACF,CAAC,EAED,GAAG,qEAAsE,SAAY,CAGnF,MAAMG,EAAqB,CACzB,QAAS,EACT,KAAM,otDACR,EAGMC,EAAS,MAAMH,EAAO,KAAKE,CAAkB,EAGnD,OAAOC,CAAM,EAAE,QAAQ,CACrB,CACE,KAAM,uBAAqB,gBAC3B,QACE,8MACJ,E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KAAKE,CAAkB,EAGnD,OAAOJ,EAAmB,MAAM,EAAE,IAAI,iBAAiB,EACvD,OAAOC,EAAoB,oBAAoB,EAAE,IAAI,iBAAiB,EACtE,OAAOI,CAAM,EAAE,QAAQ,CAAC,CAAC,CAC3B,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["import_ethers", "import_purify_ts", "import_ClearSignContext", "import_uniswap", "import_DefaultCommandDecoderDataSource", "import_EthersAbiDecoderDataSource", "import_UniswapContextLoader", "commandDecoderMock", "tokenDataSourceMock", "loader", "address", "transactionContext", "result"]
7
+ }
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@ledgerhq/context-module",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
+ "private": false,
4
5
  "license": "Apache-2.0",
5
6
  "exports": {
6
7
  ".": {
@@ -28,18 +29,18 @@
28
29
  "postpack": "find . -name '*.tgz' -exec cp {} ../../../dist/ \\; ",
29
30
  "prettier": "prettier . --check",
30
31
  "prettier:fix": "prettier . --write",
31
- "test": "jest",
32
- "test:watch": "pnpm test -- --watch",
33
- "test:coverage": "pnpm test -- --coverage",
32
+ "test": "vitest run",
33
+ "test:watch": "vitest",
34
+ "test:coverage": "vitest run --coverage",
34
35
  "typecheck": "tsc --noEmit"
35
36
  },
36
37
  "devDependencies": {
37
38
  "@ledgerhq/device-management-kit": "workspace:*",
38
39
  "@ledgerhq/esbuild-tools": "workspace:*",
39
40
  "@ledgerhq/eslint-config-dsdk": "workspace:*",
40
- "@ledgerhq/jest-config-dsdk": "workspace:*",
41
41
  "@ledgerhq/prettier-config-dsdk": "workspace:*",
42
42
  "@ledgerhq/tsconfig-dsdk": "workspace:*",
43
+ "@ledgerhq/vitest-config-dmk": "workspace:*",
43
44
  "@types/crypto-js": "^4.2.2",
44
45
  "ts-node": "^10.9.2"
45
46
  },
@@ -47,11 +48,11 @@
47
48
  "axios": "^1.7.9",
48
49
  "crypto-js": "^4.2.0",
49
50
  "ethers": "6.13.4",
50
- "inversify": "^6.1.6",
51
+ "inversify": "^6.2.2",
51
52
  "purify-ts": "^2.1.0",
52
53
  "reflect-metadata": "^0.2.2"
53
54
  },
54
55
  "peerDependencies": {
55
- "@ledgerhq/device-management-kit": "^0.5.1"
56
+ "@ledgerhq/device-management-kit": "workspace:*"
56
57
  }
57
58
  }
@@ -1,2 +1,2 @@
1
- import{ContextModuleBuilder as o}from"./ContextModuleBuilder";import{DefaultContextModule as d}from"./DefaultContextModule";describe("ContextModuleBuilder",()=>{const u={url:"https://crypto-assets-service.api.ledger.com/v1",mode:"prod",branch:"main"};it("should return a default context module",()=>{const e=new o().build();expect(e).toBeInstanceOf(d)}),it("should return a custom context module",()=>{const t=new o,e={load:jest.fn()},n=t.removeDefaultLoaders().addLoader(e).build();expect(n).toBeInstanceOf(d)}),it("should return a custom context module with a custom typed data loader",()=>{const t=new o,e={load:jest.fn()},n=t.removeDefaultLoaders().addTypedDataLoader(e).build();expect(n).toBeInstanceOf(d)}),it("should return a custom context module with a custom config",()=>{const e=new o().addCalConfig(u).build();expect(e).toBeInstanceOf(d)})});
1
+ import{ContextModuleBuilder as o}from"./ContextModuleBuilder";import{DefaultContextModule as d}from"./DefaultContextModule";describe("ContextModuleBuilder",()=>{const u={url:"https://crypto-assets-service.api.ledger.com/v1",mode:"prod",branch:"main"};it("should return a default context module",()=>{const e=new o().build();expect(e).toBeInstanceOf(d)}),it("should return a custom context module",()=>{const t=new o,e={load:vi.fn()},n=t.removeDefaultLoaders().addLoader(e).build();expect(n).toBeInstanceOf(d)}),it("should return a custom context module with a custom typed data loader",()=>{const t=new o,e={load:vi.fn()},n=t.removeDefaultLoaders().addTypedDataLoader(e).build();expect(n).toBeInstanceOf(d)}),it("should return a custom context module with a custom config",()=>{const e=new o().addCalConfig(u).build();expect(e).toBeInstanceOf(d)})});
2
2
  //# sourceMappingURL=ContextModuleBuilder.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/ContextModuleBuilder.test.ts"],
4
- "sourcesContent": ["import { type ContextModuleCalConfig } from \"./config/model/ContextModuleConfig\";\nimport { ContextModuleBuilder } from \"./ContextModuleBuilder\";\nimport { DefaultContextModule } from \"./DefaultContextModule\";\n\ndescribe(\"ContextModuleBuilder\", () => {\n const defaultCalConfig: ContextModuleCalConfig = {\n url: \"https://crypto-assets-service.api.ledger.com/v1\",\n mode: \"prod\",\n branch: \"main\",\n };\n it(\"should return a default context module\", () => {\n const contextModuleBuilder = new ContextModuleBuilder();\n\n const res = contextModuleBuilder.build();\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n });\n\n it(\"should return a custom context module\", () => {\n const contextModuleBuilder = new ContextModuleBuilder();\n const customLoader = { load: jest.fn() };\n\n const res = contextModuleBuilder\n .removeDefaultLoaders()\n .addLoader(customLoader)\n .build();\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n });\n\n it(\"should return a custom context module with a custom typed data loader\", () => {\n const contextModuleBuilder = new ContextModuleBuilder();\n const customLoader = { load: jest.fn() };\n\n const res = contextModuleBuilder\n .removeDefaultLoaders()\n .addTypedDataLoader(customLoader)\n .build();\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n });\n\n it(\"should return a custom context module with a custom config\", () => {\n const contextModuleBuilder = new ContextModuleBuilder();\n\n const res = contextModuleBuilder.addCalConfig(defaultCalConfig).build();\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n });\n});\n"],
5
- "mappings": "AACA,OAAS,wBAAAA,MAA4B,yBACrC,OAAS,wBAAAC,MAA4B,yBAErC,SAAS,uBAAwB,IAAM,CACrC,MAAMC,EAA2C,CAC/C,IAAK,kDACL,KAAM,OACN,OAAQ,MACV,EACA,GAAG,yCAA0C,IAAM,CAGjD,MAAMC,EAFuB,IAAIH,EAAqB,EAErB,MAAM,EAEvC,OAAOG,CAAG,EAAE,eAAeF,CAAoB,CACjD,CAAC,EAED,GAAG,wCAAyC,IAAM,CAChD,MAAMG,EAAuB,IAAIJ,EAC3BK,EAAe,CAAE,KAAM,KAAK,GAAG,CAAE,EAEjCF,EAAMC,EACT,qBAAqB,EACrB,UAAUC,CAAY,EACtB,MAAM,EAET,OAAOF,CAAG,EAAE,eAAeF,CAAoB,CACjD,CAAC,EAED,GAAG,wEAAyE,IAAM,CAChF,MAAMG,EAAuB,IAAIJ,EAC3BK,EAAe,CAAE,KAAM,KAAK,GAAG,CAAE,EAEjCF,EAAMC,EACT,qBAAqB,EACrB,mBAAmBC,CAAY,EAC/B,MAAM,EAET,OAAOF,CAAG,EAAE,eAAeF,CAAoB,CACjD,CAAC,EAED,GAAG,6DAA8D,IAAM,CAGrE,MAAME,EAFuB,IAAIH,EAAqB,EAErB,aAAaE,CAAgB,EAAE,MAAM,EAEtE,OAAOC,CAAG,EAAE,eAAeF,CAAoB,CACjD,CAAC,CACH,CAAC",
4
+ "sourcesContent": ["import { type ContextModuleCalConfig } from \"./config/model/ContextModuleConfig\";\nimport { ContextModuleBuilder } from \"./ContextModuleBuilder\";\nimport { DefaultContextModule } from \"./DefaultContextModule\";\n\ndescribe(\"ContextModuleBuilder\", () => {\n const defaultCalConfig: ContextModuleCalConfig = {\n url: \"https://crypto-assets-service.api.ledger.com/v1\",\n mode: \"prod\",\n branch: \"main\",\n };\n it(\"should return a default context module\", () => {\n const contextModuleBuilder = new ContextModuleBuilder();\n\n const res = contextModuleBuilder.build();\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n });\n\n it(\"should return a custom context module\", () => {\n const contextModuleBuilder = new ContextModuleBuilder();\n const customLoader = { load: vi.fn() };\n\n const res = contextModuleBuilder\n .removeDefaultLoaders()\n .addLoader(customLoader)\n .build();\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n });\n\n it(\"should return a custom context module with a custom typed data loader\", () => {\n const contextModuleBuilder = new ContextModuleBuilder();\n const customLoader = { load: vi.fn() };\n\n const res = contextModuleBuilder\n .removeDefaultLoaders()\n .addTypedDataLoader(customLoader)\n .build();\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n });\n\n it(\"should return a custom context module with a custom config\", () => {\n const contextModuleBuilder = new ContextModuleBuilder();\n\n const res = contextModuleBuilder.addCalConfig(defaultCalConfig).build();\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n });\n});\n"],
5
+ "mappings": "AACA,OAAS,wBAAAA,MAA4B,yBACrC,OAAS,wBAAAC,MAA4B,yBAErC,SAAS,uBAAwB,IAAM,CACrC,MAAMC,EAA2C,CAC/C,IAAK,kDACL,KAAM,OACN,OAAQ,MACV,EACA,GAAG,yCAA0C,IAAM,CAGjD,MAAMC,EAFuB,IAAIH,EAAqB,EAErB,MAAM,EAEvC,OAAOG,CAAG,EAAE,eAAeF,CAAoB,CACjD,CAAC,EAED,GAAG,wCAAyC,IAAM,CAChD,MAAMG,EAAuB,IAAIJ,EAC3BK,EAAe,CAAE,KAAM,GAAG,GAAG,CAAE,EAE/BF,EAAMC,EACT,qBAAqB,EACrB,UAAUC,CAAY,EACtB,MAAM,EAET,OAAOF,CAAG,EAAE,eAAeF,CAAoB,CACjD,CAAC,EAED,GAAG,wEAAyE,IAAM,CAChF,MAAMG,EAAuB,IAAIJ,EAC3BK,EAAe,CAAE,KAAM,GAAG,GAAG,CAAE,EAE/BF,EAAMC,EACT,qBAAqB,EACrB,mBAAmBC,CAAY,EAC/B,MAAM,EAET,OAAOF,CAAG,EAAE,eAAeF,CAAoB,CACjD,CAAC,EAED,GAAG,6DAA8D,IAAM,CAGrE,MAAME,EAFuB,IAAIH,EAAqB,EAErB,aAAaE,CAAgB,EAAE,MAAM,EAEtE,OAAOC,CAAG,EAAE,eAAeF,CAAoB,CACjD,CAAC,CACH,CAAC",
6
6
  "names": ["ContextModuleBuilder", "DefaultContextModule", "defaultCalConfig", "res", "contextModuleBuilder", "customLoader"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{transactionTypes as r}from"./transaction/di/transactionTypes";import{trustedNameTypes as n}from"./trusted-name/di/trustedNameTypes";import{externalPluginTypes as i}from"./external-plugin/di/externalPluginTypes";import{nftTypes as p}from"./nft/di/nftTypes";import{ClearSignContextType as d}from"./shared/model/ClearSignContext";import{tokenTypes as s}from"./token/di/tokenTypes";import{typedDataTypes as m}from"./typed-data/di/typedDataTypes";import{makeContainer as C}from"./di";class g{_container;_loaders;_typedDataLoader;constructor(t){this._container=C({config:t}),this._loaders=t.defaultLoaders?this._getDefaultLoaders():[],this._loaders.push(...t.customLoaders),this._typedDataLoader=t.customTypedDataLoader??this._getDefaultTypedDataLoader()}_getDefaultLoaders(){return[this._container.get(i.ExternalPluginContextLoader),this._container.get(n.TrustedNameContextLoader),this._container.get(p.NftContextLoader),this._container.get(s.TokenContextLoader),this._container.get(r.TransactionContextLoader)]}_getDefaultTypedDataLoader(){return this._container.get(m.TypedDataContextLoader)}async getContexts(t){const o=this._loaders.map(e=>e.load(t));return(await Promise.all(o)).flat()}async getContext(t){const o=this._loaders.filter(e=>e.loadField).map(e=>e.loadField(t));return(await Promise.all(o)).find(e=>e!==null)||{type:d.ERROR,error:new Error(`Field type not supported: ${t.type}`)}}async getTypedDataFilters(t){return this._typedDataLoader.load(t)}}export{g as DefaultContextModule};
1
+ import{transactionTypes as r}from"./transaction/di/transactionTypes";import{trustedNameTypes as n}from"./trusted-name/di/trustedNameTypes";import{externalPluginTypes as i}from"./external-plugin/di/externalPluginTypes";import{nftTypes as p}from"./nft/di/nftTypes";import{ClearSignContextType as d}from"./shared/model/ClearSignContext";import{tokenTypes as s}from"./token/di/tokenTypes";import{typedDataTypes as m}from"./typed-data/di/typedDataTypes";import{uniswapTypes as C}from"./uniswap/di/uniswapTypes";import{makeContainer as l}from"./di";class h{_container;_loaders;_typedDataLoader;constructor(t){this._container=l({config:t}),this._loaders=t.defaultLoaders?this._getDefaultLoaders():[],this._loaders.push(...t.customLoaders),this._typedDataLoader=t.customTypedDataLoader??this._getDefaultTypedDataLoader()}_getDefaultLoaders(){return[this._container.get(i.ExternalPluginContextLoader),this._container.get(n.TrustedNameContextLoader),this._container.get(p.NftContextLoader),this._container.get(s.TokenContextLoader),this._container.get(r.TransactionContextLoader),this._container.get(C.UniswapContextLoader)]}_getDefaultTypedDataLoader(){return this._container.get(m.TypedDataContextLoader)}async getContexts(t){const o=this._loaders.map(e=>e.load(t));return(await Promise.all(o)).flat()}async getContext(t){const o=this._loaders.filter(e=>e.loadField).map(e=>e.loadField(t));return(await Promise.all(o)).find(e=>e!==null)||{type:d.ERROR,error:new Error(`Field type not supported: ${t.type}`)}}async getTypedDataFilters(t){return this._typedDataLoader.load(t)}}export{h as DefaultContextModule};
2
2
  //# sourceMappingURL=DefaultContextModule.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/DefaultContextModule.ts"],
4
- "sourcesContent": ["import { type Container } from \"inversify\";\n\nimport type { TypedDataClearSignContext } from \"@/shared/model/TypedDataClearSignContext\";\nimport type { TypedDataContext } from \"@/shared/model/TypedDataContext\";\nimport { transactionTypes } from \"@/transaction/di/transactionTypes\";\nimport { trustedNameTypes } from \"@/trusted-name/di/trustedNameTypes\";\n\nimport { type ContextModuleConfig } from \"./config/model/ContextModuleConfig\";\nimport { externalPluginTypes } from \"./external-plugin/di/externalPluginTypes\";\nimport { type ExternalPluginContextLoader } from \"./external-plugin/domain/ExternalPluginContextLoader\";\nimport { nftTypes } from \"./nft/di/nftTypes\";\nimport { type NftContextLoader } from \"./nft/domain/NftContextLoader\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport {\n type ClearSignContext,\n ClearSignContextType,\n} from \"./shared/model/ClearSignContext\";\nimport {\n type TransactionContext,\n type TransactionFieldContext,\n} from \"./shared/model/TransactionContext\";\nimport { tokenTypes } from \"./token/di/tokenTypes\";\nimport { type TokenContextLoader } from \"./token/domain/TokenContextLoader\";\nimport { type TransactionContextLoader } from \"./transaction/domain/TransactionContextLoader\";\nimport { type TrustedNameContextLoader } from \"./trusted-name/domain/TrustedNameContextLoader\";\nimport { typedDataTypes } from \"./typed-data/di/typedDataTypes\";\nimport type { TypedDataContextLoader } from \"./typed-data/domain/TypedDataContextLoader\";\nimport { type ContextModule } from \"./ContextModule\";\nimport { makeContainer } from \"./di\";\n\nexport class DefaultContextModule implements ContextModule {\n private _container: Container;\n private _loaders: ContextLoader[];\n private _typedDataLoader: TypedDataContextLoader;\n\n constructor(args: ContextModuleConfig) {\n this._container = makeContainer({ config: args });\n this._loaders = args.defaultLoaders ? this._getDefaultLoaders() : [];\n this._loaders.push(...args.customLoaders);\n this._typedDataLoader =\n args.customTypedDataLoader ?? this._getDefaultTypedDataLoader();\n }\n\n private _getDefaultLoaders(): ContextLoader[] {\n return [\n this._container.get<ExternalPluginContextLoader>(\n externalPluginTypes.ExternalPluginContextLoader,\n ),\n this._container.get<TrustedNameContextLoader>(\n trustedNameTypes.TrustedNameContextLoader,\n ),\n this._container.get<NftContextLoader>(nftTypes.NftContextLoader),\n this._container.get<TokenContextLoader>(tokenTypes.TokenContextLoader),\n this._container.get<TransactionContextLoader>(\n transactionTypes.TransactionContextLoader,\n ),\n ];\n }\n\n private _getDefaultTypedDataLoader(): TypedDataContextLoader {\n return this._container.get<TypedDataContextLoader>(\n typedDataTypes.TypedDataContextLoader,\n );\n }\n\n public async getContexts(\n transaction: TransactionContext,\n ): Promise<ClearSignContext[]> {\n const promises = this._loaders.map((fetcher) => fetcher.load(transaction));\n const responses = await Promise.all(promises);\n return responses.flat();\n }\n\n public async getContext(\n field: TransactionFieldContext,\n ): Promise<ClearSignContext> {\n const promises = this._loaders\n .filter((fetcher) => fetcher.loadField)\n .map((fetcher) => fetcher.loadField!(field));\n const responses = await Promise.all(promises);\n return (\n responses.find((resp) => resp !== null) || {\n type: ClearSignContextType.ERROR,\n error: new Error(`Field type not supported: ${field.type}`),\n }\n );\n }\n\n public async getTypedDataFilters(\n typedData: TypedDataContext,\n ): Promise<TypedDataClearSignContext> {\n return this._typedDataLoader.load(typedData);\n }\n}\n"],
5
- "mappings": "AAIA,OAAS,oBAAAA,M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CAEA,MAAa,oBACXE,EACoC,CACpC,OAAO,KAAK,iBAAiB,KAAKA,CAAS,CAC7C,CACF",
6
- "names": ["transactionTypes", "trustedNameTypes", "externalPluginTypes", "nftTypes", "ClearSignContextType", "tokenTypes", "typedDataTypes", "makeContainer", "DefaultContextModule", "args", "transaction", "promises", "fetcher", "field", "resp", "typedData"]
4
+ "sourcesContent": ["import { type Container } from \"inversify\";\n\nimport type { TypedDataClearSignContext } from \"@/shared/model/TypedDataClearSignContext\";\nimport type { TypedDataContext } from \"@/shared/model/TypedDataContext\";\nimport { transactionTypes } from \"@/transaction/di/transactionTypes\";\nimport { trustedNameTypes } from \"@/trusted-name/di/trustedNameTypes\";\n\nimport { type ContextModuleConfig } from \"./config/model/ContextModuleConfig\";\nimport { externalPluginTypes } from \"./external-plugin/di/externalPluginTypes\";\nimport { type ExternalPluginContextLoader } from \"./external-plugin/domain/ExternalPluginContextLoader\";\nimport { nftTypes } from \"./nft/di/nftTypes\";\nimport { type NftContextLoader } from \"./nft/domain/NftContextLoader\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport {\n type ClearSignContext,\n ClearSignContextType,\n} from \"./shared/model/ClearSignContext\";\nimport {\n type TransactionContext,\n type TransactionFieldContext,\n} from \"./shared/model/TransactionContext\";\nimport { tokenTypes } from \"./token/di/tokenTypes\";\nimport { type TokenContextLoader } from \"./token/domain/TokenContextLoader\";\nimport { type TransactionContextLoader } from \"./transaction/domain/TransactionContextLoader\";\nimport { type TrustedNameContextLoader } from \"./trusted-name/domain/TrustedNameContextLoader\";\nimport { typedDataTypes } from \"./typed-data/di/typedDataTypes\";\nimport type { TypedDataContextLoader } from \"./typed-data/domain/TypedDataContextLoader\";\nimport { uniswapTypes } from \"./uniswap/di/uniswapTypes\";\nimport { type UniswapContextLoader } from \"./uniswap/domain/UniswapContextLoader\";\nimport { type ContextModule } from \"./ContextModule\";\nimport { makeContainer } from \"./di\";\n\nexport class DefaultContextModule implements ContextModule {\n private _container: Container;\n private _loaders: ContextLoader[];\n private _typedDataLoader: TypedDataContextLoader;\n\n constructor(args: ContextModuleConfig) {\n this._container = makeContainer({ config: args });\n this._loaders = args.defaultLoaders ? this._getDefaultLoaders() : [];\n this._loaders.push(...args.customLoaders);\n this._typedDataLoader =\n args.customTypedDataLoader ?? this._getDefaultTypedDataLoader();\n }\n\n private _getDefaultLoaders(): ContextLoader[] {\n return [\n this._container.get<ExternalPluginContextLoader>(\n externalPluginTypes.ExternalPluginContextLoader,\n ),\n this._container.get<TrustedNameContextLoader>(\n trustedNameTypes.TrustedNameContextLoader,\n ),\n this._container.get<NftContextLoader>(nftTypes.NftContextLoader),\n this._container.get<TokenContextLoader>(tokenTypes.TokenContextLoader),\n this._container.get<TransactionContextLoader>(\n transactionTypes.TransactionContextLoader,\n ),\n this._container.get<UniswapContextLoader>(\n uniswapTypes.UniswapContextLoader,\n ),\n ];\n }\n\n private _getDefaultTypedDataLoader(): TypedDataContextLoader {\n return this._container.get<TypedDataContextLoader>(\n typedDataTypes.TypedDataContextLoader,\n );\n }\n\n public async getContexts(\n transaction: TransactionContext,\n ): Promise<ClearSignContext[]> {\n const promises = this._loaders.map((fetcher) => fetcher.load(transaction));\n const responses = await Promise.all(promises);\n return responses.flat();\n }\n\n public async getContext(\n field: TransactionFieldContext,\n ): Promise<ClearSignContext> {\n const promises = this._loaders\n .filter((fetcher) => fetcher.loadField)\n .map((fetcher) => fetcher.loadField!(field));\n const responses = await Promise.all(promises);\n return (\n responses.find((resp) => resp !== null) || {\n type: ClearSignContextType.ERROR,\n error: new Error(`Field type not supported: ${field.type}`),\n }\n );\n }\n\n public async getTypedDataFilters(\n typedData: TypedDataContext,\n ): Promise<TypedDataClearSignContext> {\n return this._typedDataLoader.load(typedData);\n }\n}\n"],
5
+ "mappings": "AAIA,OAAS,oBAAAA,MAAwB,oCACjC,OAAS,oBAAAC,MAAwB,qCAGjC,OAAS,uBAAAC,MAA2B,2CAEpC,OAAS,YAAAC,MAAgB,oBAGzB,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KAAK,iBAAiB,KAAKA,CAAS,CAC7C,CACF",
6
+ "names": ["transactionTypes", "trustedNameTypes", "externalPluginTypes", "nftTypes", "ClearSignContextType", "tokenTypes", "typedDataTypes", "uniswapTypes", "makeContainer", "DefaultContextModule", "args", "transaction", "promises", "fetcher", "field", "resp", "typedData"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{DefaultContextModule as a}from"./DefaultContextModule";const l=()=>({load:jest.fn(),loadField:jest.fn()});describe("DefaultContextModule",()=>{const s={load:jest.fn()},o={customLoaders:[],defaultLoaders:!1,customTypedDataLoader:s,cal:{url:"https://crypto-assets-service.api.ledger.com/v1",mode:"prod",branch:"main"}};beforeEach(()=>{jest.restoreAllMocks()}),it("should initialize the context module with all the default loaders",async()=>{const t=await new a(o).getContexts({});expect(t).toEqual([])}),it("should return an empty array when no loaders",async()=>{const t=await new a(o).getContexts({});expect(t).toEqual([])}),it("should call all fetch method from metadata fetcher",async()=>{const e=l();await new a({...o,customLoaders:[e,e]}).getContexts({}),expect(e.load).toHaveBeenCalledTimes(2)}),it("should return an array of context response",async()=>{const e=l(),t=[[{type:"provideERC20Info",payload:"payload1"}],[{type:"provideERC20Info",payload:"payload2"},{type:"plugin",payload:"payload3"}]];jest.spyOn(e,"load").mockResolvedValueOnce(t[0]).mockResolvedValueOnce(t[1]);const n=await new a({...o,customLoaders:[e,e]}).getContexts({});expect(e.load).toHaveBeenCalledTimes(2),expect(n).toEqual(t.flat())}),it("should call the typed data loader",async()=>{await new a({...o,customTypedDataLoader:s}).getTypedDataFilters({}),expect(s.load).toHaveBeenCalledTimes(1)}),it("should return a single context",async()=>{const e=l(),t=[null,{type:"token",payload:"payload"}];jest.spyOn(e,"loadField").mockResolvedValueOnce(t[0]).mockResolvedValueOnce(t[1]);const n=await new a({...o,customLoaders:[e,{load:jest.fn()},e]}).getContext({type:"token"});expect(e.loadField).toHaveBeenCalledTimes(2),expect(n).toEqual({type:"token",payload:"payload"})}),it("context field not supported",async()=>{const e=l(),t=[null,null];jest.spyOn(e,"loadField").mockResolvedValueOnce(t[0]).mockResolvedValueOnce(t[1]);const n=await new a({...o,customLoaders:[e,{load:jest.fn()},e]}).getContext({type:"token"});expect(e.loadField).toHaveBeenCalledTimes(2),expect(n).toEqual({type:"error",error:new Error("Field type not supported: token")})}),it("getField not implemented",async()=>{const t=await new a({...o,customLoaders:[{load:jest.fn()}]}).getContext({type:"token"});expect(t).toEqual({type:"error",error:new Error("Field type not supported: token")})})});
1
+ import{DefaultContextModule as a}from"./DefaultContextModule";const l=()=>({load:vi.fn(),loadField:vi.fn()});describe("DefaultContextModule",()=>{const d={load:vi.fn()},o={customLoaders:[],defaultLoaders:!1,customTypedDataLoader:d,cal:{url:"https://crypto-assets-service.api.ledger.com/v1",mode:"prod",branch:"main"}};beforeEach(()=>{vi.restoreAllMocks()}),it("should initialize the context module with all the default loaders",async()=>{const t=await new a(o).getContexts({});expect(t).toEqual([])}),it("should return an empty array when no loaders",async()=>{const t=await new a(o).getContexts({});expect(t).toEqual([])}),it("should call all fetch method from metadata fetcher",async()=>{const e=l();await new a({...o,customLoaders:[e,e]}).getContexts({}),expect(e.load).toHaveBeenCalledTimes(2)}),it("should return an array of context response",async()=>{const e=l(),t=[[{type:"provideERC20Info",payload:"payload1"}],[{type:"provideERC20Info",payload:"payload2"},{type:"plugin",payload:"payload3"}]];vi.spyOn(e,"load").mockResolvedValueOnce(t[0]).mockResolvedValueOnce(t[1]);const n=await new a({...o,customLoaders:[e,e]}).getContexts({});expect(e.load).toHaveBeenCalledTimes(2),expect(n).toEqual(t.flat())}),it("should call the typed data loader",async()=>{await new a({...o,customTypedDataLoader:d}).getTypedDataFilters({}),expect(d.load).toHaveBeenCalledTimes(1)}),it("should return a single context",async()=>{const e=l(),t=[null,{type:"token",payload:"payload"}];vi.spyOn(e,"loadField").mockResolvedValueOnce(t[0]).mockResolvedValueOnce(t[1]);const n=await new a({...o,customLoaders:[e,{load:vi.fn()},e]}).getContext({type:"token"});expect(e.loadField).toHaveBeenCalledTimes(2),expect(n).toEqual({type:"token",payload:"payload"})}),it("context field not supported",async()=>{const e=l(),t=[null,null];vi.spyOn(e,"loadField").mockResolvedValueOnce(t[0]).mockResolvedValueOnce(t[1]);const n=await new a({...o,customLoaders:[e,{load:vi.fn()},e]}).getContext({type:"token"});expect(e.loadField).toHaveBeenCalledTimes(2),expect(n).toEqual({type:"error",error:new Error("Field type not supported: token")})}),it("getField not implemented",async()=>{const t=await new a({...o,customLoaders:[{load:vi.fn()}]}).getContext({type:"token"});expect(t).toEqual({type:"error",error:new Error("Field type not supported: token")})})});
2
2
  //# sourceMappingURL=DefaultContextModule.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/DefaultContextModule.test.ts"],
4
- "sourcesContent": ["import { type ContextModuleConfig } from \"./config/model/ContextModuleConfig\";\nimport {\n type TransactionContext,\n type TransactionFieldContext,\n} from \"./shared/model/TransactionContext\";\nimport { type TypedDataContext } from \"./shared/model/TypedDataContext\";\nimport type { TypedDataContextLoader } from \"./typed-data/domain/TypedDataContextLoader\";\nimport { DefaultContextModule } from \"./DefaultContextModule\";\n\nconst contextLoaderStubBuilder = () => {\n return { load: jest.fn(), loadField: jest.fn() };\n};\n\ndescribe(\"DefaultContextModule\", () => {\n const typedDataLoader: TypedDataContextLoader = { load: jest.fn() };\n const defaultContextModuleConfig: ContextModuleConfig = {\n customLoaders: [],\n defaultLoaders: false,\n customTypedDataLoader: typedDataLoader,\n cal: {\n url: \"https://crypto-assets-service.api.ledger.com/v1\",\n mode: \"prod\",\n branch: \"main\",\n },\n };\n\n beforeEach(() => {\n jest.restoreAllMocks();\n });\n\n it(\"should initialize the context module with all the default loaders\", async () => {\n const contextModule = new DefaultContextModule(defaultContextModuleConfig);\n\n const res = await contextModule.getContexts({} as TransactionContext);\n\n expect(res).toEqual([]);\n });\n\n it(\"should return an empty array when no loaders\", async () => {\n const contextModule = new DefaultContextModule(defaultContextModuleConfig);\n\n const res = await contextModule.getContexts({} as TransactionContext);\n\n expect(res).toEqual([]);\n });\n\n it(\"should call all fetch method from metadata fetcher\", async () => {\n const loader = contextLoaderStubBuilder();\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader, loader],\n });\n\n await contextModule.getContexts({} as TransactionContext);\n\n expect(loader.load).toHaveBeenCalledTimes(2);\n });\n\n it(\"should return an array of context response\", async () => {\n const loader = contextLoaderStubBuilder();\n const responses = [\n [{ type: \"provideERC20Info\", payload: \"payload1\" }],\n [\n { type: \"provideERC20Info\", payload: \"payload2\" },\n { type: \"plugin\", payload: \"payload3\" },\n ],\n ];\n jest\n .spyOn(loader, \"load\")\n .mockResolvedValueOnce(responses[0])\n .mockResolvedValueOnce(responses[1]);\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader, loader],\n });\n\n const res = await contextModule.getContexts({} as TransactionContext);\n\n expect(loader.load).toHaveBeenCalledTimes(2);\n expect(res).toEqual(responses.flat());\n });\n\n it(\"should call the typed data loader\", async () => {\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customTypedDataLoader: typedDataLoader,\n });\n\n await contextModule.getTypedDataFilters({} as TypedDataContext);\n\n expect(typedDataLoader.load).toHaveBeenCalledTimes(1);\n });\n\n it(\"should return a single context\", async () => {\n const loader = contextLoaderStubBuilder();\n const responses = [null, { type: \"token\", payload: \"payload\" }];\n jest\n .spyOn(loader, \"loadField\")\n .mockResolvedValueOnce(responses[0])\n .mockResolvedValueOnce(responses[1]);\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader, { load: jest.fn() }, loader],\n });\n\n const res = await contextModule.getContext({\n type: \"token\",\n } as TransactionFieldContext);\n\n expect(loader.loadField).toHaveBeenCalledTimes(2);\n expect(res).toEqual({ type: \"token\", payload: \"payload\" });\n });\n\n it(\"context field not supported\", async () => {\n const loader = contextLoaderStubBuilder();\n const responses = [null, null];\n jest\n .spyOn(loader, \"loadField\")\n .mockResolvedValueOnce(responses[0])\n .mockResolvedValueOnce(responses[1]);\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader, { load: jest.fn() }, loader],\n });\n\n const res = await contextModule.getContext({\n type: \"token\",\n } as TransactionFieldContext);\n\n expect(loader.loadField).toHaveBeenCalledTimes(2);\n expect(res).toEqual({\n type: \"error\",\n error: new Error(\"Field type not supported: token\"),\n });\n });\n\n it(\"getField not implemented\", async () => {\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [{ load: jest.fn() }],\n });\n\n const res = await contextModule.getContext({\n type: \"token\",\n } as TransactionFieldContext);\n\n expect(res).toEqual({\n type: \"error\",\n error: new Error(\"Field type not supported: token\"),\n });\n });\n});\n"],
5
- "mappings": "AAOA,OAAS,wBAAAA,MAA4B,yBAErC,MAAMC,EAA2B,KACxB,CAAE,KAAM,KAAK,GAAG,EAAG,UAAW,KAAK,GAAG,CAAE,GAGjD,SAAS,uBAAwB,IAAM,CACrC,MAAMC,EAA0C,CAAE,KAAM,KAAK,GAAG,CAAE,EAC5DC,EAAkD,CACtD,cAAe,CAAC,EAChB,eAAgB,GAChB,sBAAuBD,EACvB,IAAK,CACH,IAAK,kDACL,KAAM,OACN,OAAQ,MACV,CACF,EAEA,WAAW,IAAM,CACf,KAAK,gBAAgB,CACvB,CAAC,EAED,GAAG,oEAAqE,SAAY,CAGlF,MAAME,EAAM,MAFU,IAAIJ,EAAqBG,CAA0B,EAEzC,YAAY,CAAC,CAAuB,EAEpE,OAAOC,CAAG,EAAE,QAAQ,CAAC,CAAC,CACxB,CAAC,EAED,GAAG,+CAAgD,SAAY,CAG7D,MAAMA,EAAM,MAFU,IAAIJ,EAAqBG,CAA0B,EAEzC,YAAY,CAAC,CAAuB,EAEpE,OAAOC,CAAG,EAAE,QAAQ,CAAC,CAAC,CACxB,CAAC,EAED,GAAG,qDAAsD,SAAY,CACnE,MAAMC,EAASJ,EAAyB,E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D,CAAC,EAE+B,WAAW,CACzC,KAAM,OACR,CAA4B,EAE5B,OAAOA,EAAO,SAAS,EAAE,sBAAsB,CAAC,EAChD,OAAOD,CAAG,EAAE,QAAQ,CAAE,KAAM,QAAS,QAAS,SAAU,CAAC,CAC3D,CAAC,EAED,GAAG,8BAA+B,SAAY,CAC5C,MAAMC,EAASJ,EAAyB,EAClCK,EAAY,CAAC,KAAM,IAAI,EAC7B,KACG,MAAMD,EAAQ,WAAW,EACzB,sBAAsBC,EAAU,CAAC,CAAC,EAClC,sBAAsBA,EAAU,CAAC,CAAC,EAMrC,MAAMF,EAAM,MALU,IAAIJ,EAAqB,CAC7C,GAAGG,EACH,cAAe,CAACE,EAAQ,CAAE,KAAM,KAAK,GAAG,CAAE,EAAGA,CAAM,CACrD,CAAC,EAE+B,WAAW,CACzC,KAAM,OACR,CAA4B,EAE5B,OAAOA,EAAO,SAAS,EAAE,sBAAsB,CAAC,EAChD,OAAOD,CAAG,EAAE,QAAQ,CAClB,KAAM,QACN,MAAO,IAAI,MAAM,iCAAiC,CACpD,CAAC,CACH,CAAC,EAED,GAAG,2BAA4B,SAAY,CAMzC,MAAMA,EAAM,MALU,IAAIJ,EAAqB,CAC7C,GAAGG,EACH,cAAe,CAAC,CAAE,KAAM,KAAK,GAAG,CAAE,CAAC,CACrC,CAAC,EAE+B,WAAW,CACzC,KAAM,OACR,CAA4B,EAE5B,OAAOC,CAAG,EAAE,QAAQ,CAClB,KAAM,QACN,MAAO,IAAI,MAAM,iCAAiC,CACpD,CAAC,CACH,CAAC,CACH,CAAC",
4
+ "sourcesContent": ["import { type ContextModuleConfig } from \"./config/model/ContextModuleConfig\";\nimport {\n type TransactionContext,\n type TransactionFieldContext,\n} from \"./shared/model/TransactionContext\";\nimport { type TypedDataContext } from \"./shared/model/TypedDataContext\";\nimport type { TypedDataContextLoader } from \"./typed-data/domain/TypedDataContextLoader\";\nimport { DefaultContextModule } from \"./DefaultContextModule\";\n\nconst contextLoaderStubBuilder = () => {\n return { load: vi.fn(), loadField: vi.fn() };\n};\n\ndescribe(\"DefaultContextModule\", () => {\n const typedDataLoader: TypedDataContextLoader = { load: vi.fn() };\n const defaultContextModuleConfig: ContextModuleConfig = {\n customLoaders: [],\n defaultLoaders: false,\n customTypedDataLoader: typedDataLoader,\n cal: {\n url: \"https://crypto-assets-service.api.ledger.com/v1\",\n mode: \"prod\",\n branch: \"main\",\n },\n };\n\n beforeEach(() => {\n vi.restoreAllMocks();\n });\n\n it(\"should initialize the context module with all the default loaders\", async () => {\n const contextModule = new DefaultContextModule(defaultContextModuleConfig);\n\n const res = await contextModule.getContexts({} as TransactionContext);\n\n expect(res).toEqual([]);\n });\n\n it(\"should return an empty array when no loaders\", async () => {\n const contextModule = new DefaultContextModule(defaultContextModuleConfig);\n\n const res = await contextModule.getContexts({} as TransactionContext);\n\n expect(res).toEqual([]);\n });\n\n it(\"should call all fetch method from metadata fetcher\", async () => {\n const loader = contextLoaderStubBuilder();\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader, loader],\n });\n\n await contextModule.getContexts({} as TransactionContext);\n\n expect(loader.load).toHaveBeenCalledTimes(2);\n });\n\n it(\"should return an array of context response\", async () => {\n const loader = contextLoaderStubBuilder();\n const responses = [\n [{ type: \"provideERC20Info\", payload: \"payload1\" }],\n [\n { type: \"provideERC20Info\", payload: \"payload2\" },\n { type: \"plugin\", payload: \"payload3\" },\n ],\n ];\n vi.spyOn(loader, \"load\")\n .mockResolvedValueOnce(responses[0])\n .mockResolvedValueOnce(responses[1]);\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader, loader],\n });\n\n const res = await contextModule.getContexts({} as TransactionContext);\n\n expect(loader.load).toHaveBeenCalledTimes(2);\n expect(res).toEqual(responses.flat());\n });\n\n it(\"should call the typed data loader\", async () => {\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customTypedDataLoader: typedDataLoader,\n });\n\n await contextModule.getTypedDataFilters({} as TypedDataContext);\n\n expect(typedDataLoader.load).toHaveBeenCalledTimes(1);\n });\n\n it(\"should return a single context\", async () => {\n const loader = contextLoaderStubBuilder();\n const responses = [null, { type: \"token\", payload: \"payload\" }];\n vi.spyOn(loader, \"loadField\")\n .mockResolvedValueOnce(responses[0])\n .mockResolvedValueOnce(responses[1]);\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader, { load: vi.fn() }, loader],\n });\n\n const res = await contextModule.getContext({\n type: \"token\",\n } as TransactionFieldContext);\n\n expect(loader.loadField).toHaveBeenCalledTimes(2);\n expect(res).toEqual({ type: \"token\", payload: \"payload\" });\n });\n\n it(\"context field not supported\", async () => {\n const loader = contextLoaderStubBuilder();\n const responses = [null, null];\n vi.spyOn(loader, \"loadField\")\n .mockResolvedValueOnce(responses[0])\n .mockResolvedValueOnce(responses[1]);\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader, { load: vi.fn() }, loader],\n });\n\n const res = await contextModule.getContext({\n type: \"token\",\n } as TransactionFieldContext);\n\n expect(loader.loadField).toHaveBeenCalledTimes(2);\n expect(res).toEqual({\n type: \"error\",\n error: new Error(\"Field type not supported: token\"),\n });\n });\n\n it(\"getField not implemented\", async () => {\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [{ load: vi.fn() }],\n });\n\n const res = await contextModule.getContext({\n type: \"token\",\n } as TransactionFieldContext);\n\n expect(res).toEqual({\n type: \"error\",\n error: new Error(\"Field type not supported: token\"),\n });\n });\n});\n"],
5
+ "mappings": "AAOA,OAAS,wBAAAA,MAA4B,yBAErC,MAAMC,EAA2B,KACxB,CAAE,KAAM,GAAG,GAAG,EAAG,UAAW,GAAG,GAAG,CAAE,GAG7C,SAAS,uBAAwB,IAAM,CACrC,MAAMC,EAA0C,CAAE,KAAM,GAAG,GAAG,CAAE,EAC1DC,EAAkD,CACtD,cAAe,CAAC,EAChB,eAAgB,GAChB,sBAA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AC7C,GAAGG,EACH,cAAe,CAAC,CAAE,KAAM,GAAG,GAAG,CAAE,CAAC,CACnC,CAAC,EAE+B,WAAW,CACzC,KAAM,OACR,CAA4B,EAE5B,OAAOC,CAAG,EAAE,QAAQ,CAClB,KAAM,QACN,MAAO,IAAI,MAAM,iCAAiC,CACpD,CAAC,CACH,CAAC,CACH,CAAC",
6
6
  "names": ["DefaultContextModule", "contextLoaderStubBuilder", "typedDataLoader", "defaultContextModuleConfig", "res", "loader", "responses"]
7
7
  }