@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/shared/utils/HexStringUtils.test.ts"],
4
+ "sourcesContent": ["import { HexStringUtils } from \"@/shared/utils/HexStringUtils\";\n\ndescribe(\"HexStringUtils\", () => {\n describe(\"appendSignatureToPayload\", () => {\n it(\"should append signature to payload\", () => {\n // GIVEN\n const payload = \"01020304\";\n const signature = \"05060708\";\n const tag = \"15\";\n // WHEN\n const result = HexStringUtils.appendSignatureToPayload(\n payload,\n signature,\n tag,\n );\n // THEN\n expect(result).toEqual(\"01020304150405060708\");\n });\n\n it(\"should append signature to payload with odd length\", () => {\n // GIVEN\n const payload = \"01020304\";\n const signature = \"5060708\";\n const tag = \"15\";\n // WHEN\n const result = HexStringUtils.appendSignatureToPayload(\n payload,\n signature,\n tag,\n );\n // THEN\n expect(result).toEqual(\"01020304150405060708\");\n });\n });\n\n describe(\"stringToHex\", () => {\n it(\"should convert string to hex\", () => {\n // GIVEN\n const str = \"test\";\n // WHEN\n const result = HexStringUtils.stringToHex(str);\n // THEN\n expect(result).toEqual(\"74657374\");\n });\n\n it(\"should convert string to hex with odd length\", () => {\n // GIVEN\n const str = \"test1\";\n // WHEN\n const result = HexStringUtils.stringToHex(str);\n // THEN\n expect(result).toEqual(\"7465737431\");\n });\n });\n});\n"],
5
+ "mappings": "aAAA,IAAAA,EAA+B,yCAE/B,SAAS,iBAAkB,IAAM,CAC/B,SAAS,2BAA4B,IAAM,CACzC,GAAG,qCAAsC,IAAM,CAM7C,MAAMC,EAAS,iBAAe,yBAJd,WACE,WACN,IAMZ,EAEA,OAAOA,CAAM,EAAE,QAAQ,sBAAsB,CAC/C,CAAC,EAED,GAAG,qDAAsD,IAAM,CAM7D,MAAMA,EAAS,iBAAe,yBAJd,WACE,UACN,IAMZ,EAEA,OAAOA,CAAM,EAAE,QAAQ,sBAAsB,CAC/C,CAAC,CACH,CAAC,EAED,SAAS,cAAe,IAAM,CAC5B,GAAG,+BAAgC,IAAM,CAIvC,MAAMA,EAAS,iBAAe,YAFlB,MAEiC,EAE7C,OAAOA,CAAM,EAAE,QAAQ,UAAU,CACnC,CAAC,EAED,GAAG,+CAAgD,IAAM,CAIvD,MAAMA,EAAS,iBAAe,YAFlB,OAEiC,EAE7C,OAAOA,CAAM,EAAE,QAAQ,YAAY,CACrC,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["import_HexStringUtils", "result"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var i=Object.defineProperty;var n=Object.getOwnPropertyDescriptor;var o=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var u=(t,a)=>{for(var s in a)i(t,s,{get:a[s],enumerable:!0})},y=(t,a,s,g)=>{if(a&&typeof a=="object"||typeof a=="function")for(let r of o(a))!p.call(t,r)&&r!==s&&i(t,r,{get:()=>a[r],enumerable:!(g=n(a,r))||g.enumerable});return t};var c=t=>y(i({},"__esModule",{value:!0}),t);var U={};u(U,{KeyUsageMapper:()=>m});module.exports=c(U);var e=require("../../pki/model/KeyUsage");class m{static keyUsageMap=new Map([[e.KeyUsage.GenuineCheck,1],[e.KeyUsage.ExchangePayload,2],[e.KeyUsage.NftMeta,3],[e.KeyUsage.TrustedName,4],[e.KeyUsage.BackupProvider,5],[e.KeyUsage.ProtectOrchestrator,6],[e.KeyUsage.PluginMeta,7],[e.KeyUsage.CoinMeta,8],[e.KeyUsage.SeedIdAuth,9],[e.KeyUsage.TxSimulationSigner,10],[e.KeyUsage.Calldata,11],[e.KeyUsage.Network,12]]);static mapKeyUsageForFirmware(a){return this.keyUsageMap.get(a)??-1}}0&&(module.exports={KeyUsageMapper});
2
+ //# sourceMappingURL=KeyUsageMapper.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/shared/utils/KeyUsageMapper.ts"],
4
+ "sourcesContent": ["import { KeyUsage } from \"@/pki/model/KeyUsage\";\n\nexport class KeyUsageMapper {\n private static keyUsageMap = new Map<KeyUsage, number>([\n [KeyUsage.GenuineCheck, 1],\n [KeyUsage.ExchangePayload, 2],\n [KeyUsage.NftMeta, 3],\n [KeyUsage.TrustedName, 4],\n [KeyUsage.BackupProvider, 5],\n [KeyUsage.ProtectOrchestrator, 6],\n [KeyUsage.PluginMeta, 7],\n [KeyUsage.CoinMeta, 8],\n [KeyUsage.SeedIdAuth, 9],\n [KeyUsage.TxSimulationSigner, 10],\n [KeyUsage.Calldata, 11],\n [KeyUsage.Network, 12],\n ]);\n\n static mapKeyUsageForFirmware(keyUsage: KeyUsage): number {\n return this.keyUsageMap.get(keyUsage as KeyUsage) ?? -1;\n }\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,oBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAyB,gCAElB,MAAMF,CAAe,CAC1B,OAAe,YAAc,IAAI,IAAsB,CACrD,CAAC,WAAS,aAAc,CAAC,EACzB,CAAC,WAAS,gBAAiB,CAAC,EAC5B,CAAC,WAAS,QAAS,CAAC,EACpB,CAAC,WAAS,YAAa,CAAC,EACxB,CAAC,WAAS,eAAgB,CAAC,EAC3B,CAAC,WAAS,oBAAqB,CAAC,EAChC,CAAC,WAAS,WAAY,CAAC,EACvB,CAAC,WAAS,SAAU,CAAC,EACrB,CAAC,WAAS,WAAY,CAAC,EACvB,CAAC,WAAS,mBAAoB,EAAE,EAChC,CAAC,WAAS,SAAU,EAAE,EACtB,CAAC,WAAS,QAAS,EAAE,CACvB,CAAC,EAED,OAAO,uBAAuBG,EAA4B,CACxD,OAAO,KAAK,YAAY,IAAIA,CAAoB,GAAK,EACvD,CACF",
6
+ "names": ["KeyUsageMapper_exports", "__export", "KeyUsageMapper", "__toCommonJS", "import_KeyUsage", "keyUsage"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var e=require("../../pki/model/KeyUsage"),r=require("../../shared/utils/KeyUsageMapper");describe("KeyUsageMapper",()=>{describe("mapKeyUsageForFirmware",()=>{it.each([[e.KeyUsage.GenuineCheck,1],[e.KeyUsage.ExchangePayload,2],[e.KeyUsage.NftMeta,3],[e.KeyUsage.TrustedName,4],[e.KeyUsage.BackupProvider,5],[e.KeyUsage.ProtectOrchestrator,6],[e.KeyUsage.PluginMeta,7],[e.KeyUsage.CoinMeta,8],[e.KeyUsage.SeedIdAuth,9],[e.KeyUsage.TxSimulationSigner,10],[e.KeyUsage.Calldata,11],[e.KeyUsage.Network,12]])("should map key usage %s to %i",(a,t)=>{const o=r.KeyUsageMapper.mapKeyUsageForFirmware(a);expect(o).toEqual(t)}),it("should return -1 when key usage is not found",()=>{const a=r.KeyUsageMapper.mapKeyUsageForFirmware("unknown");expect(a).toEqual(-1)})})});
2
+ //# sourceMappingURL=KeyUsageMapper.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/shared/utils/KeyUsageMapper.test.ts"],
4
+ "sourcesContent": ["import { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { KeyUsageMapper } from \"@/shared/utils/KeyUsageMapper\";\n\ndescribe(\"KeyUsageMapper\", () => {\n describe(\"mapKeyUsageForFirmware\", () => {\n it.each([\n [KeyUsage.GenuineCheck, 1],\n [KeyUsage.ExchangePayload, 2],\n [KeyUsage.NftMeta, 3],\n [KeyUsage.TrustedName, 4],\n [KeyUsage.BackupProvider, 5],\n [KeyUsage.ProtectOrchestrator, 6],\n [KeyUsage.PluginMeta, 7],\n [KeyUsage.CoinMeta, 8],\n [KeyUsage.SeedIdAuth, 9],\n [KeyUsage.TxSimulationSigner, 10],\n [KeyUsage.Calldata, 11],\n [KeyUsage.Network, 12],\n ])(`should map key usage %s to %i`, (keyUsage, expected) => {\n // WHEN\n const result = KeyUsageMapper.mapKeyUsageForFirmware(keyUsage);\n\n // THEN\n expect(result).toEqual(expected);\n });\n\n it(\"should return -1 when key usage is not found\", () => {\n // WHEN\n const result = KeyUsageMapper.mapKeyUsageForFirmware(\n \"unknown\" as KeyUsage,\n );\n\n // THEN\n expect(result).toEqual(-1);\n });\n });\n});\n"],
5
+ "mappings": "aAAA,IAAAA,EAAyB,gCACzBC,EAA+B,yCAE/B,SAAS,iBAAkB,IAAM,CAC/B,SAAS,yBAA0B,IAAM,CACvC,GAAG,KAAK,CACN,CAAC,WAAS,aAAc,CAAC,EACzB,CAAC,WAAS,gBAAiB,CAAC,EAC5B,CAAC,WAAS,QAAS,CAAC,EACpB,CAAC,WAAS,YAAa,CAAC,EACxB,CAAC,WAAS,eAAgB,CAAC,EAC3B,CAAC,WAAS,oBAAqB,CAAC,EAChC,CAAC,WAAS,WAAY,CAAC,EACvB,CAAC,WAAS,SAAU,CAAC,EACrB,CAAC,WAAS,WAAY,CAAC,EACvB,CAAC,WAAS,mBAAoB,EAAE,EAChC,CAAC,WAAS,SAAU,EAAE,EACtB,CAAC,WAAS,QAAS,EAAE,CACvB,CAAC,EAAE,gCAAiC,CAACC,EAAUC,IAAa,CAE1D,MAAMC,EAAS,iBAAe,uBAAuBF,CAAQ,EAG7D,OAAOE,CAAM,EAAE,QAAQD,CAAQ,CACjC,CAAC,EAED,GAAG,+CAAgD,IAAM,CAEvD,MAAMC,EAAS,iBAAe,uBAC5B,SACF,EAGA,OAAOA,CAAM,EAAE,QAAQ,EAAE,CAC3B,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["import_KeyUsage", "import_KeyUsageMapper", "keyUsage", "expected", "result"]
7
+ }
@@ -1,2 +1,2 @@
1
- "use strict";var u=Object.create;var d=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var h=(t,e,o,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of k(e))!x.call(t,r)&&r!==o&&d(t,r,{get:()=>e[r],enumerable:!(s=p(e,r))||s.enumerable});return t};var c=(t,e,o)=>(o=t!=null?u(m(t)):{},h(e||!t||!t.__esModule?d(o,"default",{value:t,enumerable:!0}):o,t));var a=c(require("axios")),n=require("purify-ts"),i=require("../../token/data/HttpTokenDataSource"),l=c(require("../../../package.json"));jest.mock("axios");describe("HttpTokenDataSource",()=>{let t;beforeAll(()=>{const e={cal:{url:"https://crypto-assets-service.api.ledger.com/v1",mode:"prod",branch:"main"}};t=new i.HttpTokenDataSource(e),jest.clearAllMocks()}),it("should call axios with the ledger client version header",async()=>{const e=`context-module/${l.default.version}`,o=jest.fn(()=>Promise.resolve({data:[]}));jest.spyOn(a.default,"request").mockImplementation(o),await t.getTokenInfosPayload({address:"0x00",chainId:1}),expect(o).toHaveBeenCalledWith(expect.objectContaining({headers:{"X-Ledger-Client-Version":e}}))}),it("should return a string when axios response is correct",async()=>{const e={ticker:"USDC",descriptor:{data:"55534443000000000800000001",signatures:{prod:"0123"}}};jest.spyOn(a.default,"request").mockResolvedValue({data:[e]});const o=await t.getTokenInfosPayload({address:"0x00",chainId:1});expect(o.extract()).toEqual("04555344430000000008000000010123")}),it("should return an error when data is empty",async()=>{jest.spyOn(a.default,"request").mockResolvedValue({data:void 0});const e=await t.getTokenInfosPayload({address:"0x00",chainId:1});expect(e).toEqual((0,n.Left)(new Error("[ContextModule] HttpTokenDataSource: no token metadata for address 0x00 on chain 1")))}),it("should return undefined when no signature",async()=>{jest.spyOn(a.default,"request").mockResolvedValue({data:[{}]});const e=await t.getTokenInfosPayload({address:"0x00",chainId:1});expect(e).toEqual((0,n.Left)(new Error("[ContextModule] HttpTokenDataSource: no token metadata for address 0x00 on chain 1")))}),it("should return undefined when no ticker",async()=>{const e={ticker:"USDC",descriptor:{data:"55534443000000000800000001",signatures:{test:"0123"}}};jest.spyOn(a.default,"request").mockResolvedValue({data:[e]});const o=await t.getTokenInfosPayload({address:"0x00",chainId:1});expect(o).toEqual((0,n.Left)(new Error("[ContextModule] HttpTokenDataSource: no token metadata for address 0x00 on chain 1")))}),it("should return undefined when no decimals",async()=>{jest.spyOn(a.default,"request").mockResolvedValue({data:[{live_signature:"0x0",ticker:"USDC"}]});const e=await t.getTokenInfosPayload({address:"0x00",chainId:1});expect(e).toEqual((0,n.Left)(new Error("[ContextModule] HttpTokenDataSource: no token metadata for address 0x00 on chain 1")))}),it("should return an error when axios throws an error",async()=>{jest.spyOn(a.default,"request").mockRejectedValue(new Error);const e=await t.getTokenInfosPayload({address:"0x00",chainId:1});expect(e).toEqual((0,n.Left)(new Error("[ContextModule] HttpTokenDataSource: Failed to fetch token informations")))})});
1
+ "use strict";var u=Object.create;var d=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var h=(t,e,o,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of k(e))!x.call(t,r)&&r!==o&&d(t,r,{get:()=>e[r],enumerable:!(s=p(e,r))||s.enumerable});return t};var i=(t,e,o)=>(o=t!=null?u(m(t)):{},h(e||!t||!t.__esModule?d(o,"default",{value:t,enumerable:!0}):o,t));var a=i(require("axios")),n=require("purify-ts"),c=require("../../token/data/HttpTokenDataSource"),l=i(require("../../../package.json"));vi.mock("axios");describe("HttpTokenDataSource",()=>{let t;beforeAll(()=>{const e={cal:{url:"https://crypto-assets-service.api.ledger.com/v1",mode:"prod",branch:"main"}};t=new c.HttpTokenDataSource(e),vi.clearAllMocks()}),it("should call axios with the ledger client version header",async()=>{const e=`context-module/${l.default.version}`,o=vi.fn(()=>Promise.resolve({data:[]}));vi.spyOn(a.default,"request").mockImplementation(o),await t.getTokenInfosPayload({address:"0x00",chainId:1}),expect(o).toHaveBeenCalledWith(expect.objectContaining({headers:{"X-Ledger-Client-Version":e}}))}),it("should return a string when axios response is correct",async()=>{const e={ticker:"USDC",descriptor:{data:"55534443000000000800000001",signatures:{prod:"0123"}}};vi.spyOn(a.default,"request").mockResolvedValue({data:[e]});const o=await t.getTokenInfosPayload({address:"0x00",chainId:1});expect(o.extract()).toEqual("04555344430000000008000000010123")}),it("should return an error when data is empty",async()=>{vi.spyOn(a.default,"request").mockResolvedValue({data:void 0});const e=await t.getTokenInfosPayload({address:"0x00",chainId:1});expect(e).toEqual((0,n.Left)(new Error("[ContextModule] HttpTokenDataSource: no token metadata for address 0x00 on chain 1")))}),it("should return undefined when no signature",async()=>{vi.spyOn(a.default,"request").mockResolvedValue({data:[{}]});const e=await t.getTokenInfosPayload({address:"0x00",chainId:1});expect(e).toEqual((0,n.Left)(new Error("[ContextModule] HttpTokenDataSource: no token metadata for address 0x00 on chain 1")))}),it("should return undefined when no ticker",async()=>{const e={ticker:"USDC",descriptor:{data:"55534443000000000800000001",signatures:{test:"0123"}}};vi.spyOn(a.default,"request").mockResolvedValue({data:[e]});const o=await t.getTokenInfosPayload({address:"0x00",chainId:1});expect(o).toEqual((0,n.Left)(new Error("[ContextModule] HttpTokenDataSource: no token metadata for address 0x00 on chain 1")))}),it("should return undefined when no decimals",async()=>{vi.spyOn(a.default,"request").mockResolvedValue({data:[{live_signature:"0x0",ticker:"USDC"}]});const e=await t.getTokenInfosPayload({address:"0x00",chainId:1});expect(e).toEqual((0,n.Left)(new Error("[ContextModule] HttpTokenDataSource: no token metadata for address 0x00 on chain 1")))}),it("should return an error when axios throws an error",async()=>{vi.spyOn(a.default,"request").mockRejectedValue(new Error);const e=await t.getTokenInfosPayload({address:"0x00",chainId:1});expect(e).toEqual((0,n.Left)(new Error("[ContextModule] HttpTokenDataSource: Failed to fetch token informations")))})});
2
2
  //# sourceMappingURL=HttpTokenDataSource.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/token/data/HttpTokenDataSource.test.ts"],
4
- "sourcesContent": ["import axios from \"axios\";\nimport { Left } from \"purify-ts\";\n\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { HttpTokenDataSource } from \"@/token/data/HttpTokenDataSource\";\nimport { type TokenDataSource } from \"@/token/data/TokenDataSource\";\nimport { type TokenDto } from \"@/token/data/TokenDto\";\nimport PACKAGE from \"@root/package.json\";\n\njest.mock(\"axios\");\n\ndescribe(\"HttpTokenDataSource\", () => {\n let datasource: TokenDataSource;\n\n beforeAll(() => {\n const config = {\n cal: {\n url: \"https://crypto-assets-service.api.ledger.com/v1\",\n mode: \"prod\",\n branch: \"main\",\n },\n } as ContextModuleConfig;\n datasource = new HttpTokenDataSource(config);\n jest.clearAllMocks();\n });\n\n it(\"should call axios with the ledger client version header\", async () => {\n // GIVEN\n const version = `context-module/${PACKAGE.version}`;\n const requestSpy = jest.fn(() => Promise.resolve({ data: [] }));\n jest.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n // WHEN\n await datasource.getTokenInfosPayload({ address: \"0x00\", chainId: 1 });\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n headers: { \"X-Ledger-Client-Version\": version },\n }),\n );\n });\n\n it(\"should return a string when axios response is correct\", async () => {\n // GIVEN\n const tokenDTO: TokenDto = {\n ticker: \"USDC\",\n descriptor: {\n data: \"55534443000000000800000001\",\n signatures: {\n prod: \"0123\",\n },\n },\n };\n jest.spyOn(axios, \"request\").mockResolvedValue({ data: [tokenDTO] });\n\n // WHEN\n const result = await datasource.getTokenInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result.extract()).toEqual(\"04555344430000000008000000010123\");\n });\n\n it(\"should return an error when data is empty\", async () => {\n // GIVEN\n jest.spyOn(axios, \"request\").mockResolvedValue({ data: undefined });\n\n // WHEN\n const result = await datasource.getTokenInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpTokenDataSource: no token metadata for address 0x00 on chain 1\",\n ),\n ),\n );\n });\n\n it(\"should return undefined when no signature\", async () => {\n // GIVEN\n jest.spyOn(axios, \"request\").mockResolvedValue({ data: [{}] });\n\n // WHEN\n const result = await datasource.getTokenInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpTokenDataSource: no token metadata for address 0x00 on chain 1\",\n ),\n ),\n );\n });\n\n it(\"should return undefined when no ticker\", async () => {\n // GIVEN\n const tokenDTO: TokenDto = {\n ticker: \"USDC\",\n descriptor: {\n data: \"55534443000000000800000001\",\n signatures: {\n test: \"0123\",\n },\n },\n };\n jest.spyOn(axios, \"request\").mockResolvedValue({ data: [tokenDTO] });\n\n // WHEN\n const result = await datasource.getTokenInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpTokenDataSource: no token metadata for address 0x00 on chain 1\",\n ),\n ),\n );\n });\n\n it(\"should return undefined when no decimals\", async () => {\n // GIVEN\n jest\n .spyOn(axios, \"request\")\n .mockResolvedValue({ data: [{ live_signature: \"0x0\", ticker: \"USDC\" }] });\n\n // WHEN\n const result = await datasource.getTokenInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpTokenDataSource: no token metadata for address 0x00 on chain 1\",\n ),\n ),\n );\n });\n\n it(\"should return an error when axios throws an error\", async () => {\n // GIVEN\n jest.spyOn(axios, \"request\").mockRejectedValue(new Error());\n\n // WHEN\n const result = await datasource.getTokenInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpTokenDataSource: Failed to fetch token informations\",\n ),\n ),\n );\n });\n});\n"],
5
- "mappings": "wdAAA,IAAAA,EAAkB,oBAClBC,EAAqB,qBAGrBC,EAAoC,4CAGpCC,EAAoB,iCAEpB,KAAK,KAAK,OAAO,EAEjB,SAAS,sBAAuB,IAAM,CACpC,IAAIC,EAEJ,UAAU,IAAM,CACd,MAAMC,EAAS,CACb,IAAK,CACH,IAAK,kDACL,KAAM,OACN,OAAQ,MACV,CACF,EACAD,EAAa,IAAI,sBAAoBC,CAAM,EAC3C,KAAK,cAAc,CACrB,CAAC,EAED,GAAG,0DAA2D,SAAY,CAExE,MAAMC,EAAU,kBAAkB,EAAAC,QAAQ,OAAO,GAC3CC,EAAa,KAAK,GAAG,IAAM,QAAQ,QAAQ,CAAE,KAAM,CAAC,CAAE,CAAC,CAAC,EAC9D,KAAK,MAAM,EAAAC,QAAO,SAAS,EAAE,mBAAmBD,CAAU,EAG1D,MAAMJ,EAAW,qBAAqB,CAAE,QAAS,OAAQ,QAAS,CAAE,CAAC,EAGrE,OAAOI,CAAU,EAAE,qBACjB,OAAO,iBAAiB,CACtB,QAAS,CAAE,0BAA2BF,CAAQ,CAChD,CAAC,CACH,CACF,CAAC,EAED,GAAG,wDAAyD,SAAY,CAEtE,MAAMI,EAAqB,CACzB,OAAQ,OACR,WAAY,CACV,KAAM,6BACN,WAAY,CACV,KAAM,MACR,CACF,CACF,EACA,KAAK,MAAM,EAAAD,QAAO,SAAS,EAAE,kBAAkB,CAAE,KAAM,CAACC,CAAQ,CAAE,CAAC,EAGnE,MAAMC,EAAS,MAAMP,EAAW,qBAAqB,CACnD,QAAS,OACT,QAAS,CACX,CAAC,EAGD,OAAOO,EAAO,QAAQ,CAAC,EAAE,QAAQ,kCAAkC,CACrE,CAAC,EAED,GAAG,4CAA6C,SAAY,CAE1D,KAAK,MAAM,EAAAF,QAAO,SAAS,EAAE,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AS,OACT,QAAS,CACX,CAAC,EAGD,OAAOO,CAAM,EAAE,WACb,QACE,IAAI,MACF,yEACF,CACF,CACF,CACF,CAAC,CACH,CAAC",
4
+ "sourcesContent": ["import axios from \"axios\";\nimport { Left } from \"purify-ts\";\n\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { HttpTokenDataSource } from \"@/token/data/HttpTokenDataSource\";\nimport { type TokenDataSource } from \"@/token/data/TokenDataSource\";\nimport { type TokenDto } from \"@/token/data/TokenDto\";\nimport PACKAGE from \"@root/package.json\";\n\nvi.mock(\"axios\");\n\ndescribe(\"HttpTokenDataSource\", () => {\n let datasource: TokenDataSource;\n\n beforeAll(() => {\n const config = {\n cal: {\n url: \"https://crypto-assets-service.api.ledger.com/v1\",\n mode: \"prod\",\n branch: \"main\",\n },\n } as ContextModuleConfig;\n datasource = new HttpTokenDataSource(config);\n vi.clearAllMocks();\n });\n\n it(\"should call axios with the ledger client version header\", async () => {\n // GIVEN\n const version = `context-module/${PACKAGE.version}`;\n const requestSpy = vi.fn(() => Promise.resolve({ data: [] }));\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n // WHEN\n await datasource.getTokenInfosPayload({ address: \"0x00\", chainId: 1 });\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n headers: { \"X-Ledger-Client-Version\": version },\n }),\n );\n });\n\n it(\"should return a string when axios response is correct\", async () => {\n // GIVEN\n const tokenDTO: TokenDto = {\n ticker: \"USDC\",\n descriptor: {\n data: \"55534443000000000800000001\",\n signatures: {\n prod: \"0123\",\n },\n },\n };\n vi.spyOn(axios, \"request\").mockResolvedValue({ data: [tokenDTO] });\n\n // WHEN\n const result = await datasource.getTokenInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result.extract()).toEqual(\"04555344430000000008000000010123\");\n });\n\n it(\"should return an error when data is empty\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({ data: undefined });\n\n // WHEN\n const result = await datasource.getTokenInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpTokenDataSource: no token metadata for address 0x00 on chain 1\",\n ),\n ),\n );\n });\n\n it(\"should return undefined when no signature\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({ data: [{}] });\n\n // WHEN\n const result = await datasource.getTokenInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpTokenDataSource: no token metadata for address 0x00 on chain 1\",\n ),\n ),\n );\n });\n\n it(\"should return undefined when no ticker\", async () => {\n // GIVEN\n const tokenDTO: TokenDto = {\n ticker: \"USDC\",\n descriptor: {\n data: \"55534443000000000800000001\",\n signatures: {\n test: \"0123\",\n },\n },\n };\n vi.spyOn(axios, \"request\").mockResolvedValue({ data: [tokenDTO] });\n\n // WHEN\n const result = await datasource.getTokenInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpTokenDataSource: no token metadata for address 0x00 on chain 1\",\n ),\n ),\n );\n });\n\n it(\"should return undefined when no decimals\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({\n data: [{ live_signature: \"0x0\", ticker: \"USDC\" }],\n });\n\n // WHEN\n const result = await datasource.getTokenInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpTokenDataSource: no token metadata for address 0x00 on chain 1\",\n ),\n ),\n );\n });\n\n it(\"should return an error when axios throws an error\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockRejectedValue(new Error());\n\n // WHEN\n const result = await datasource.getTokenInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \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AE,WACb,QACE,IAAI,MACF,yEACF,CACF,CACF,CACF,CAAC,CACH,CAAC",
6
6
  "names": ["import_axios", "import_purify_ts", "import_HttpTokenDataSource", "import_package", "datasource", "config", "version", "PACKAGE", "requestSpy", "axios", "tokenDTO", "result"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var n=require("purify-ts"),o=require("../../shared/model/ClearSignContext"),s=require("../../token/domain/TokenContextLoader");describe("TokenContextLoader",()=>{const r={getTokenInfosPayload:jest.fn()},a=new s.TokenContextLoader(r);beforeEach(()=>{jest.restoreAllMocks(),jest.spyOn(r,"getTokenInfosPayload").mockImplementation(({address:t})=>Promise.resolve((0,n.Right)(`payload-${t}`)))}),describe("load function",()=>{it("should return an empty array if transaction dest is undefined",async()=>{const t={to:void 0,data:"0x01"},e=await a.load(t);expect(e).toEqual([])}),it("should return an empty array if transaction data is undefined",async()=>{const t={to:"0xdAC17F958D2ee523a2206206994597C13D831ec7",data:void 0},e=await a.load(t);expect(e).toEqual([])}),it("should return an empty array if transaction data is empty",async()=>{const t={to:"0xdAC17F958D2ee523a2206206994597C13D831ec7",data:"0x"},e=await a.load(t);expect(e).toEqual([])}),it("should return an empty array if the selector is not supported",async()=>{const t={to:"0xdAC17F958D2ee523a2206206994597C13D831ec7",data:"0x095ea7b20000000000000"},e=await a.load(t);expect(e).toEqual([])}),it("should return an error when transaction data is not a valid hex string",async()=>{const t={to:"0xdAC17F958D2ee523a2206206994597C13D831ec7",data:"notahexstring"},e=await a.load(t);expect(e).toEqual([{type:o.ClearSignContextType.ERROR,error:new Error("Invalid selector")}])}),it("should return an error when datasource returns an error",async()=>{const t={to:"0xdAC17F958D2ee523a2206206994597C13D831ec7",data:"0x095ea7b30000000000",chainId:1};jest.spyOn(r,"getTokenInfosPayload").mockResolvedValue((0,n.Left)(new Error("error")));const e=await a.load(t);expect(e).toEqual([{type:o.ClearSignContextType.ERROR,error:new Error("error")}])}),it("should return a correct response",async()=>{const t={to:"0xdAC17F958D2ee523a2206206994597C13D831ec7",data:"0x095ea7b30000000000",chainId:1},e=await a.load(t);expect(e).toEqual([{type:o.ClearSignContextType.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"}])})}),describe("loadField function",()=>{it("should return an error when field type if not supported",async()=>{const t={type:o.ClearSignContextType.NFT,chainId:7,address:"0x1234"},e=await a.loadField(t);expect(e).toEqual(null)}),it("should return a payload",async()=>{const t={type:o.ClearSignContextType.TOKEN,chainId:7,address:"0x1234"};jest.spyOn(r,"getTokenInfosPayload").mockResolvedValue((0,n.Right)("payload"));const e=await a.loadField(t);expect(e).toEqual({type:o.ClearSignContextType.TOKEN,payload:"payload"})}),it("should return an error when unable to fetch the datasource",async()=>{const t={type:o.ClearSignContextType.TOKEN,chainId:7,address:"0x1234"};jest.spyOn(r,"getTokenInfosPayload").mockResolvedValue((0,n.Left)(new Error("error")));const e=await a.loadField(t);expect(e).toEqual({type:o.ClearSignContextType.ERROR,error:new Error("error")})})})});
1
+ "use strict";var n=require("purify-ts"),o=require("../../shared/model/ClearSignContext"),s=require("../../token/domain/TokenContextLoader");describe("TokenContextLoader",()=>{const r={getTokenInfosPayload:vi.fn()},e=new s.TokenContextLoader(r);beforeEach(()=>{vi.restoreAllMocks(),vi.spyOn(r,"getTokenInfosPayload").mockImplementation(({address:t})=>Promise.resolve((0,n.Right)(`payload-${t}`)))}),describe("load function",()=>{it("should return an empty array if transaction dest is undefined",async()=>{const t={to:void 0,data:"0x01"},a=await e.load(t);expect(a).toEqual([])}),it("should return an empty array if transaction data is undefined",async()=>{const t={to:"0xdAC17F958D2ee523a2206206994597C13D831ec7",data:void 0},a=await e.load(t);expect(a).toEqual([])}),it("should return an empty array if transaction data is empty",async()=>{const t={to:"0xdAC17F958D2ee523a2206206994597C13D831ec7",data:"0x"},a=await e.load(t);expect(a).toEqual([])}),it("should return an empty array if the selector is not supported",async()=>{const t={to:"0xdAC17F958D2ee523a2206206994597C13D831ec7",data:"0x095ea7b20000000000000"},a=await e.load(t);expect(a).toEqual([])}),it("should return an error when transaction data is not a valid hex string",async()=>{const t={to:"0xdAC17F958D2ee523a2206206994597C13D831ec7",data:"notahexstring"},a=await e.load(t);expect(a).toEqual([{type:o.ClearSignContextType.ERROR,error:new Error("Invalid selector")}])}),it("should return an error when datasource returns an error",async()=>{const t={to:"0xdAC17F958D2ee523a2206206994597C13D831ec7",data:"0x095ea7b30000000000",chainId:1};vi.spyOn(r,"getTokenInfosPayload").mockResolvedValue((0,n.Left)(new Error("error")));const a=await e.load(t);expect(a).toEqual([{type:o.ClearSignContextType.ERROR,error:new Error("error")}])}),it("should return a correct response",async()=>{const t={to:"0xdAC17F958D2ee523a2206206994597C13D831ec7",data:"0x095ea7b30000000000",chainId:1},a=await e.load(t);expect(a).toEqual([{type:o.ClearSignContextType.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"}])})}),describe("loadField function",()=>{it("should return an error when field type if not supported",async()=>{const t={type:o.ClearSignContextType.NFT,chainId:7,address:"0x1234"},a=await e.loadField(t);expect(a).toEqual(null)}),it("should return a payload",async()=>{const t={type:o.ClearSignContextType.TOKEN,chainId:7,address:"0x1234"};vi.spyOn(r,"getTokenInfosPayload").mockResolvedValue((0,n.Right)("payload"));const a=await e.loadField(t);expect(a).toEqual({type:o.ClearSignContextType.TOKEN,payload:"payload"})}),it("should return an error when unable to fetch the datasource",async()=>{const t={type:o.ClearSignContextType.TOKEN,chainId:7,address:"0x1234"};vi.spyOn(r,"getTokenInfosPayload").mockResolvedValue((0,n.Left)(new Error("error")));const a=await e.loadField(t);expect(a).toEqual({type:o.ClearSignContextType.ERROR,error:new Error("error")})})})});
2
2
  //# sourceMappingURL=TokenContextLoader.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/token/domain/TokenContextLoader.test.ts"],
4
- "sourcesContent": ["import { Left, Right } from \"purify-ts\";\n\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport {\n type TransactionContext,\n type TransactionFieldContext,\n} from \"@/shared/model/TransactionContext\";\nimport { type TokenDataSource } from \"@/token/data/TokenDataSource\";\nimport { TokenContextLoader } from \"@/token/domain/TokenContextLoader\";\n\ndescribe(\"TokenContextLoader\", () => {\n const mockTokenDataSource: TokenDataSource = {\n getTokenInfosPayload: jest.fn(),\n };\n const loader = new TokenContextLoader(mockTokenDataSource);\n\n beforeEach(() => {\n jest.restoreAllMocks();\n jest\n .spyOn(mockTokenDataSource, \"getTokenInfosPayload\")\n .mockImplementation(({ address }) =>\n Promise.resolve(Right(`payload-${address}`)),\n );\n });\n\n describe(\"load function\", () => {\n it(\"should return an empty array if transaction dest is undefined\", async () => {\n // GIVEN\n const transaction = { to: undefined, data: \"0x01\" } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if transaction data is undefined\", async () => {\n // GIVEN\n const transaction = {\n to: \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n data: undefined,\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if transaction data is empty\", async () => {\n // GIVEN\n const transaction = {\n to: \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n data: \"0x\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if the selector is not supported\", async () => {\n // GIVEN\n const transaction = {\n to: \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n data: \"0x095ea7b20000000000000\",\n } as unknown as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an error when transaction data is not a valid hex string\", async () => {\n // GIVEN\n const transaction = {\n to: \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n data: \"notahexstring\",\n } as unknown as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Invalid selector\"),\n },\n ]);\n });\n\n it(\"should return an error when datasource returns an error\", async () => {\n // GIVEN\n const transaction = {\n to: \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n data: \"0x095ea7b30000000000\",\n chainId: 1,\n } as TransactionContext;\n jest\n .spyOn(mockTokenDataSource, \"getTokenInfosPayload\")\n .mockResolvedValue(Left(new Error(\"error\")));\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n { type: ClearSignContextType.ERROR, error: new Error(\"error\") },\n ]);\n });\n\n it(\"should return a correct response\", async () => {\n // GIVEN\n const transaction = {\n to: \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n data: \"0x095ea7b30000000000\",\n chainId: 1,\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n },\n ]);\n });\n });\n\n describe(\"loadField function\", () => {\n it(\"should return an error when field type if not supported\", async () => {\n const field: TransactionFieldContext = {\n type: ClearSignContextType.NFT,\n chainId: 7,\n address: \"0x1234\",\n };\n\n const result = await loader.loadField(field);\n\n expect(result).toEqual(null);\n });\n\n it(\"should return a payload\", async () => {\n // GIVEN\n const field: TransactionFieldContext = {\n type: ClearSignContextType.TOKEN,\n chainId: 7,\n address: \"0x1234\",\n };\n\n // WHEN\n jest\n .spyOn(mockTokenDataSource, \"getTokenInfosPayload\")\n .mockResolvedValue(Right(\"payload\"));\n const result = await loader.loadField(field);\n\n // THEN\n expect(result).toEqual({\n type: ClearSignContextType.TOKEN,\n payload: \"payload\",\n });\n });\n\n it(\"should return an error when unable to fetch the datasource\", async () => {\n // GIVEN\n const field: TransactionFieldContext = {\n type: ClearSignContextType.TOKEN,\n chainId: 7,\n address: \"0x1234\",\n };\n\n // WHEN\n jest\n .spyOn(mockTokenDataSource, \"getTokenInfosPayload\")\n .mockResolvedValue(Left(new Error(\"error\")));\n const result = await loader.loadField(field);\n\n // THEN\n expect(result).toEqual({\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n });\n });\n });\n});\n"],
5
- "mappings": "aAAA,IAAAA,EAA4B,qBAE5BC,EAAqC,2CAMrCC,EAAmC,6CAEnC,SAAS,qBAAsB,IAAM,CACnC,MAAMC,EAAuC,CAC3C,qBAAsB,KAAK,GAAG,CAChC,EACMC,EAAS,IAAI,qBAAmBD,CAAmB,EAEzD,WAAW,IAAM,CACf,KAAK,gBAAgB,EACrB,KACG,MAAMA,EAAqB,sBAAsB,EACjD,mBAAmB,CAAC,CAAE,QAAAE,CAAQ,IAC7B,QAAQ,WAAQ,SAAM,WAAWA,CAAO,EAAE,CAAC,CAC7C,CACJ,CAAC,EAED,SAAS,gBAAiB,IAAM,CAC9B,GAAG,gEAAiE,SAAY,CAE9E,MAAMC,EAAc,CAAE,GAAI,OAAW,KAAM,MAAO,EAG5CC,EAAS,MAAMH,EAAO,KAAKE,CAAW,EAG5C,OAAOC,CAAM,EAAE,QAAQ,CAAC,CAAC,CAC3B,CAAC,EAED,GAAG,gEAAiE,SAAY,CAE9E,MAAMD,EAAc,CAClB,GAAI,6CACJ,KAAM,MACR,EAGMC,EAAS,MAAMH,EAAO,KAAKE,CAAW,EAG5C,OAAOC,CAAM,EAAE,QAAQ,CAAC,CAAC,CAC3B,CAAC,EAED,GAAG,4DAA6D,SAAY,CAE1E,MAAMD,EAAc,CAClB,GAAI,6CACJ,KAAM,IACR,EAGMC,EAAS,MAAMH,EAAO,KAAKE,CAAW,EAG5C,OAAOC,CAAM,EAAE,QAAQ,CAAC,CAAC,CAC3B,CAAC,EAED,GAAG,gEAAiE,SAAY,CAE9E,MAAMD,EAAc,CAClB,GAAI,6CACJ,KAAM,yBACR,EAGMC,EAAS,MAAMH,EAAO,KAAKE,CAAW,EAG5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CAAC,EACrC,MAAMI,EAAS,MAAMH,EAAO,UAAUI,CAAK,EAG3C,OAAOD,CAAM,EAAE,QAAQ,CACrB,KAAM,uBAAqB,MAC3B,QAAS,SACX,CAAC,CACH,CAAC,EAED,GAAG,6DAA8D,SAAY,CAE3E,MAAMC,EAAiC,CACrC,KAAM,uBAAqB,MAC3B,QAAS,EACT,QAAS,QACX,EAGA,KACG,MAAML,EAAqB,sBAAsB,EACjD,qBAAkB,QAAK,IAAI,MAAM,OAAO,CAAC,CAAC,EAC7C,MAAMI,EAAS,MAAMH,EAAO,UAAUI,CAAK,EAG3C,OAAOD,CAAM,EAAE,QAAQ,CACrB,KAAM,uBAAqB,MAC3B,MAAO,IAAI,MAAM,OAAO,CAC1B,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
4
+ "sourcesContent": ["import { Left, Right } from \"purify-ts\";\n\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport {\n type TransactionContext,\n type TransactionFieldContext,\n} from \"@/shared/model/TransactionContext\";\nimport { type TokenDataSource } from \"@/token/data/TokenDataSource\";\nimport { TokenContextLoader } from \"@/token/domain/TokenContextLoader\";\n\ndescribe(\"TokenContextLoader\", () => {\n const mockTokenDataSource: TokenDataSource = {\n getTokenInfosPayload: vi.fn(),\n };\n const loader = new TokenContextLoader(mockTokenDataSource);\n\n beforeEach(() => {\n vi.restoreAllMocks();\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockImplementation(\n ({ address }) => Promise.resolve(Right(`payload-${address}`)),\n );\n });\n\n describe(\"load function\", () => {\n it(\"should return an empty array if transaction dest is undefined\", async () => {\n // GIVEN\n const transaction = { to: undefined, data: \"0x01\" } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if transaction data is undefined\", async () => {\n // GIVEN\n const transaction = {\n to: \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n data: undefined,\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if transaction data is empty\", async () => {\n // GIVEN\n const transaction = {\n to: \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n data: \"0x\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if the selector is not supported\", async () => {\n // GIVEN\n const transaction = {\n to: \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n data: \"0x095ea7b20000000000000\",\n } as unknown as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an error when transaction data is not a valid hex string\", async () => {\n // GIVEN\n const transaction = {\n to: \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n data: \"notahexstring\",\n } as unknown as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Invalid selector\"),\n },\n ]);\n });\n\n it(\"should return an error when datasource returns an error\", async () => {\n // GIVEN\n const transaction = {\n to: \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n data: \"0x095ea7b30000000000\",\n chainId: 1,\n } as TransactionContext;\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(new Error(\"error\")),\n );\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n { type: ClearSignContextType.ERROR, error: new Error(\"error\") },\n ]);\n });\n\n it(\"should return a correct response\", async () => {\n // GIVEN\n const transaction = {\n to: \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n data: \"0x095ea7b30000000000\",\n chainId: 1,\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n },\n ]);\n });\n });\n\n describe(\"loadField function\", () => {\n it(\"should return an error when field type if not supported\", async () => {\n const field: TransactionFieldContext = {\n type: ClearSignContextType.NFT,\n chainId: 7,\n address: \"0x1234\",\n };\n\n const result = await loader.loadField(field);\n\n expect(result).toEqual(null);\n });\n\n it(\"should return a payload\", async () => {\n // GIVEN\n const field: TransactionFieldContext = {\n type: ClearSignContextType.TOKEN,\n chainId: 7,\n address: \"0x1234\",\n };\n\n // WHEN\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(\"payload\"),\n );\n const result = await loader.loadField(field);\n\n // THEN\n expect(result).toEqual({\n type: ClearSignContextType.TOKEN,\n payload: \"payload\",\n });\n });\n\n it(\"should return an error when unable to fetch the datasource\", async () => {\n // GIVEN\n const field: TransactionFieldContext = {\n type: ClearSignContextType.TOKEN,\n chainId: 7,\n address: \"0x1234\",\n };\n\n // WHEN\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(new Error(\"error\")),\n );\n const result = await loader.loadField(field);\n\n // THEN\n expect(result).toEqual({\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n });\n });\n });\n});\n"],
5
+ "mappings": "aAAA,IAAAA,EAA4B,qBAE5BC,EAAqC,2CAMrCC,EAAmC,6CAEnC,SAAS,qBAAsB,IAAM,CACnC,MAAMC,EAAuC,CAC3C,qBAAsB,GAAG,GAAG,CAC9B,EACMC,EAAS,IAAI,qBAAmBD,CAAmB,EAEzD,WAAW,IAAM,CACf,GAAG,gBAAgB,EACnB,GAAG,MAAMA,EAAqB,sBAAsB,EAAE,mBACpD,CAAC,CAAE,QAAAE,CAAQ,IAAM,QAAQ,WAAQ,SAAM,WAAWA,CAAO,EAAE,CAAC,CAC9D,CACF,CAAC,EAED,SAAS,gBAAiB,IAAM,CAC9B,GAAG,gEAAiE,SAAY,CAE9E,MAAMC,EAAc,CAAE,GAAI,OAAW,KAAM,M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MAAMD,EAAc,CAClB,GAAI,6CACJ,KAAM,uBACN,QAAS,CACX,EAGMC,EAAS,MAAMH,EAAO,KAAKE,CAAW,EAG5C,OAAOC,CAAM,EAAE,QAAQ,CACrB,CACE,KAAM,uBAAqB,MAC3B,QAAS,oDACX,CACF,CAAC,CACH,CAAC,CACH,CAAC,EAED,SAAS,qBAAsB,IAAM,CACnC,GAAG,0DAA2D,SAAY,CACxE,MAAMC,EAAiC,CACrC,KAAM,uBAAqB,IAC3B,QAAS,EACT,QAAS,QACX,EAEMD,EAAS,MAAMH,EAAO,UAAUI,CAAK,EAE3C,OAAOD,CAAM,EAAE,QAAQ,IAAI,CAC7B,CAAC,EAED,GAAG,0BAA2B,SAAY,CAExC,MAAMC,EAAiC,CACrC,KAAM,uBAAqB,MAC3B,QAAS,EACT,QAAS,QACX,EAGA,GAAG,MAAML,EAAqB,sBAAsB,EAAE,qBACpD,SAAM,SAAS,CACjB,EACA,MAAMI,EAAS,MAAMH,EAAO,UAAUI,CAAK,EAG3C,OAAOD,CAAM,EAAE,QAAQ,CACrB,KAAM,uBAAqB,MAC3B,QAAS,SACX,CAAC,CACH,CAAC,EAED,GAAG,6DAA8D,SAAY,CAE3E,MAAMC,EAAiC,CACrC,KAAM,uBAAqB,MAC3B,QAAS,EACT,QAAS,QACX,EAGA,GAAG,MAAML,EAAqB,sBAAsB,EAAE,qBACpD,QAAK,IAAI,MAAM,OAAO,CAAC,CACzB,EACA,MAAMI,EAAS,MAAMH,EAAO,UAAUI,CAAK,EAG3C,OAAOD,CAAM,EAAE,QAAQ,CACrB,KAAM,uBAAqB,MAC3B,MAAO,IAAI,MAAM,OAAO,CAC1B,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
6
  "names": ["import_purify_ts", "import_ClearSignContext", "import_TokenContextLoader", "mockTokenDataSource", "loader", "address", "transaction", "result", "field"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var l=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var o=Object.getOwnPropertyNames;var s=Object.prototype.hasOwnProperty;var n=(t,a,p,r)=>{if(a&&typeof a=="object"||typeof a=="function")for(let e of o(a))!s.call(t,e)&&e!==p&&l(t,e,{get:()=>a[e],enumerable:!(r=i(a,e))||r.enumerable});return t};var c=t=>n(l({},"__esModule",{value:!0}),t);var d={};module.exports=c(d);
1
+ "use strict";var l=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var o=Object.getOwnPropertyNames;var n=Object.prototype.hasOwnProperty;var s=(t,a,p,r)=>{if(a&&typeof a=="object"||typeof a=="function")for(let e of o(a))!n.call(t,e)&&e!==p&&l(t,e,{get:()=>a[e],enumerable:!(r=i(a,e))||r.enumerable});return t};var c=t=>s(l({},"__esModule",{value:!0}),t);var d={};module.exports=c(d);
2
2
  //# sourceMappingURL=CalldataDto.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/transaction/data/CalldataDto.ts"],
4
- "sourcesContent": ["export interface CalldataDto {\n descriptors_calldata: {\n [address: string]: {\n [selector: string]: CalldataDescriptor;\n };\n };\n}\n\nexport type CalldataDescriptor = CalldataDescriptorV1; // For now only V1 descriptors are supported\n\nexport interface CalldataDescriptorV1 {\n type: \"calldata\";\n version: \"v1\";\n transaction_info: CalldataTransactionInfoV1;\n enums: CalldataEnumV1[];\n fields: CalldataFieldV1[];\n}\n\nexport type CalldataTransactionDescriptor = {\n data: string;\n signatures: CalldataSignatures;\n};\n\nexport type CalldataSignatures =\n | {\n prod: string;\n test?: string;\n }\n | {\n prod?: string;\n test: string;\n };\n\nexport interface CalldataTransactionInfoV1 {\n descriptor: CalldataTransactionDescriptor;\n}\n\nexport interface CalldataEnumV1 {\n descriptor: string;\n}\n\nexport interface CalldataFieldV1 {\n descriptor: string;\n param: CalldataDescriptorParam;\n}\n\nexport type CalldataDescriptorParam =\n | CalldataDescriptorParamRawV1\n | CalldataDescriptorParamAmountV1\n | CalldataDescriptorParamTokenAmountV1\n | CalldataDescriptorParamNFTV1\n | CalldataDescriptorParamDatetimeV1\n | CalldataDescriptorParamDurationV1\n | CalldataDescriptorParamUnitV1\n | CalldataDescriptorParamEnumV1\n | CalldataDescriptorParamTrustedNameV1;\n\nexport interface CalldataDescriptorParamRawV1 {\n type: \"RAW\";\n value: CalldataDescriptorValueV1;\n}\n\nexport interface CalldataDescriptorParamAmountV1 {\n type: \"AMOUNT\";\n value: CalldataDescriptorValueV1;\n}\n\nexport interface CalldataDescriptorParamTokenAmountV1 {\n type: \"TOKEN_AMOUNT\";\n value: CalldataDescriptorValueV1;\n token?: CalldataDescriptorValueV1;\n}\n\nexport interface CalldataDescriptorParamNFTV1 {\n type: \"NFT\";\n value: CalldataDescriptorValueV1;\n collection: CalldataDescriptorValueV1;\n}\n\nexport interface CalldataDescriptorParamDatetimeV1 {\n type: \"DATETIME\";\n value: CalldataDescriptorValueV1;\n}\n\nexport interface CalldataDescriptorParamDurationV1 {\n type: \"DURATION\";\n value: CalldataDescriptorValueV1;\n}\n\nexport interface CalldataDescriptorParamUnitV1 {\n type: \"UNIT\";\n value: CalldataDescriptorValueV1;\n}\n\nexport interface CalldataDescriptorParamEnumV1 {\n type: \"ENUM\";\n value: CalldataDescriptorValueV1;\n}\n\nexport interface CalldataDescriptorParamTrustedNameV1 {\n type: \"TRUSTED_NAME\";\n value: CalldataDescriptorValueV1;\n types: string[];\n sources: string[];\n}\n\nexport interface CalldataDescriptorValueV1 {\n binary_path:\n | CalldataDescriptorContainerPathV1\n | CalldataDescriptorPathElementsV1;\n type_family: CalldataDescriptorTypeFamilyV1;\n type_size?: number;\n}\n\nexport interface CalldataDescriptorContainerPathV1 {\n type: \"CONTAINER\";\n value: CalldataDescriptorContainerPathTypeV1;\n}\n\nexport interface CalldataDescriptorPathElementsV1 {\n type: \"DATA\";\n elements: CalldataDescriptorPathElementV1[];\n}\n\nexport type CalldataDescriptorPathElementV1 =\n | CalldataDescriptorPathElementTupleV1\n | CalldataDescriptorPathElementArrayV1\n | CalldataDescriptorPathElementRefV1\n | CalldataDescriptorPathElementLeafV1\n | CalldataDescriptorPathElementSliceV1;\n\nexport interface CalldataDescriptorPathElementTupleV1 {\n type: \"TUPLE\";\n offset: number;\n}\n\nexport interface CalldataDescriptorPathElementArrayV1 {\n type: \"ARRAY\";\n start?: number;\n length?: number;\n weight: number;\n}\n\nexport interface CalldataDescriptorPathElementRefV1 {\n type: \"REF\";\n}\n\nexport interface CalldataDescriptorPathElementLeafV1 {\n type: \"LEAF\";\n leaf_type: CalldataDescriptorPathLeafTypeV1;\n}\n\nexport interface CalldataDescriptorPathElementSliceV1 {\n type: \"SLICE\";\n start?: number;\n end?: number;\n}\n\nexport type CalldataDescriptorContainerPathTypeV1 = \"FROM\" | \"TO\" | \"VALUE\";\nexport type CalldataDescriptorPathLeafTypeV1 =\n | \"ARRAY_LEAF\"\n | \"TUPLE_LEAF\"\n | \"STATIC_LEAF\"\n | \"DYNAMIC_LEAF\";\nexport type CalldataDescriptorTypeFamilyV1 =\n | \"UINT\"\n | \"INT\"\n | \"UFIXED\"\n | \"FIXED\"\n | \"ADDRESS\"\n | \"BOOL\"\n | \"BYTES\"\n | \"STRING\";\n"],
4
+ "sourcesContent": ["export interface CalldataDto {\n descriptors_calldata: {\n [address: string]: {\n [selector: string]: CalldataDescriptor;\n };\n };\n}\n\nexport type CalldataDescriptor = CalldataDescriptorV1; // For now only V1 descriptors are supported\n\nexport interface CalldataDescriptorV1 {\n type: \"calldata\";\n version: \"v1\";\n transaction_info: CalldataTransactionInfoV1;\n enums: CalldataEnumV1;\n fields: CalldataFieldV1[];\n}\n\nexport type CalldataTransactionDescriptor = {\n data: string;\n signatures: CalldataSignatures;\n};\n\nexport type CalldataSignatures =\n | {\n prod: string;\n test?: string;\n }\n | {\n prod?: string;\n test: string;\n };\n\nexport interface CalldataTransactionInfoV1 {\n descriptor: CalldataTransactionDescriptor;\n}\n\nexport interface CalldataEnumV1 {\n [id: number]: {\n [value: number]: CalldataTransactionDescriptor;\n };\n}\n\nexport interface CalldataFieldV1 {\n descriptor: string;\n param: CalldataDescriptorParam;\n}\n\nexport type CalldataDescriptorParam =\n | CalldataDescriptorParamRawV1\n | CalldataDescriptorParamAmountV1\n | CalldataDescriptorParamTokenAmountV1\n | CalldataDescriptorParamNFTV1\n | CalldataDescriptorParamDatetimeV1\n | CalldataDescriptorParamDurationV1\n | CalldataDescriptorParamUnitV1\n | CalldataDescriptorParamEnumV1\n | CalldataDescriptorParamTrustedNameV1;\n\nexport interface CalldataDescriptorParamRawV1 {\n type: \"RAW\";\n value: CalldataDescriptorValueV1;\n}\n\nexport interface CalldataDescriptorParamAmountV1 {\n type: \"AMOUNT\";\n value: CalldataDescriptorValueV1;\n}\n\nexport interface CalldataDescriptorParamTokenAmountV1 {\n type: \"TOKEN_AMOUNT\";\n value: CalldataDescriptorValueV1;\n token?: CalldataDescriptorValueV1;\n}\n\nexport interface CalldataDescriptorParamNFTV1 {\n type: \"NFT\";\n value: CalldataDescriptorValueV1;\n collection: CalldataDescriptorValueV1;\n}\n\nexport interface CalldataDescriptorParamDatetimeV1 {\n type: \"DATETIME\";\n value: CalldataDescriptorValueV1;\n}\n\nexport interface CalldataDescriptorParamDurationV1 {\n type: \"DURATION\";\n value: CalldataDescriptorValueV1;\n}\n\nexport interface CalldataDescriptorParamUnitV1 {\n type: \"UNIT\";\n value: CalldataDescriptorValueV1;\n}\n\nexport interface CalldataDescriptorParamEnumV1 {\n type: \"ENUM\";\n value: CalldataDescriptorValueV1;\n id: number;\n}\n\nexport interface CalldataDescriptorParamTrustedNameV1 {\n type: \"TRUSTED_NAME\";\n value: CalldataDescriptorValueV1;\n types: string[];\n sources: string[];\n}\n\nexport interface CalldataDescriptorValueBinaryPathV1 {\n type: \"path\";\n binary_path:\n | CalldataDescriptorContainerPathV1\n | CalldataDescriptorPathElementsV1;\n type_family: CalldataDescriptorTypeFamilyV1;\n type_size?: number;\n}\n\nexport interface CalldataDescriptorValueConstantV1 {\n type: \"constant\";\n value: string;\n type_family: CalldataDescriptorTypeFamilyV1;\n type_size?: number;\n}\n\nexport type CalldataDescriptorValueV1 =\n | CalldataDescriptorValueBinaryPathV1\n | CalldataDescriptorValueConstantV1;\n\nexport interface CalldataDescriptorContainerPathV1 {\n type: \"CONTAINER\";\n value: CalldataDescriptorContainerPathTypeV1;\n}\n\nexport interface CalldataDescriptorPathElementsV1 {\n type: \"DATA\";\n elements: CalldataDescriptorPathElementV1[];\n}\n\nexport type CalldataDescriptorPathElementV1 =\n | CalldataDescriptorPathElementTupleV1\n | CalldataDescriptorPathElementArrayV1\n | CalldataDescriptorPathElementRefV1\n | CalldataDescriptorPathElementLeafV1\n | CalldataDescriptorPathElementSliceV1;\n\nexport interface CalldataDescriptorPathElementTupleV1 {\n type: \"TUPLE\";\n offset: number;\n}\n\nexport interface CalldataDescriptorPathElementArrayV1 {\n type: \"ARRAY\";\n start?: number;\n end?: number;\n weight: number;\n}\n\nexport interface CalldataDescriptorPathElementRefV1 {\n type: \"REF\";\n}\n\nexport interface CalldataDescriptorPathElementLeafV1 {\n type: \"LEAF\";\n leaf_type: CalldataDescriptorPathLeafTypeV1;\n}\n\nexport interface CalldataDescriptorPathElementSliceV1 {\n type: \"SLICE\";\n start?: number;\n end?: number;\n}\n\nexport type CalldataDescriptorContainerPathTypeV1 = \"FROM\" | \"TO\" | \"VALUE\";\nexport type CalldataDescriptorPathLeafTypeV1 =\n | \"ARRAY_LEAF\"\n | \"TUPLE_LEAF\"\n | \"STATIC_LEAF\"\n | \"DYNAMIC_LEAF\";\nexport type CalldataDescriptorTypeFamilyV1 =\n | \"UINT\"\n | \"INT\"\n | \"UFIXED\"\n | \"FIXED\"\n | \"ADDRESS\"\n | \"BOOL\"\n | \"BYTES\"\n | \"STRING\";\n"],
5
5
  "mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
6
6
  "names": ["CalldataDto_exports", "__toCommonJS"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var _=Object.create;var c=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,M=Object.prototype.hasOwnProperty;var v=(n,e)=>{for(var t in e)c(n,t,{get:e[t],enumerable:!0})},C=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of N(e))!M.call(n,o)&&o!==t&&c(n,o,{get:()=>e[o],enumerable:!(r=u(e,o))||r.enumerable});return n};var m=(n,e,t)=>(t=n!=null?_(S(n)):{},C(e||!n||!n.__esModule?c(t,"default",{value:n,enumerable:!0}):t,n)),I=n=>C(c({},"__esModule",{value:!0}),n),h=(n,e,t,r)=>{for(var o=r>1?void 0:r?u(e,t):e,i=n.length-1,l;i>=0;i--)(l=n[i])&&(o=(r?l(e,t,o):l(o))||o);return r&&o&&c(e,t,o),o},T=(n,e)=>(t,r)=>e(t,r,n);var P={};v(P,{HttpTransactionDataSource:()=>f});module.exports=I(P);var g=m(require("axios")),y=require("inversify"),p=require("purify-ts"),E=require("../../config/di/configTypes"),s=require("../../shared/model/ClearSignContext"),d=m(require("../../../package.json"));let f=class{constructor(e){this.config=e}async getTransactionDescriptors({chainId:e,address:t,selector:r}){let o;try{o=(await g.default.request({method:"GET",url:`${this.config.cal.url}/dapps`,params:{output:"descriptors_calldata",chain_id:e,contracts:t,ref:`branch:${this.config.cal.branch}`},headers:{"X-Ledger-Client-Version":`context-module/${d.default.version}`}})).data?.[0]}catch(a){return(0,p.Left)(new Error(`[ContextModule] HttpTransactionDataSource: Failed to fetch transaction informations: ${a}`))}if(!o)return(0,p.Left)(new Error(`[ContextModule] HttpTransactionDataSource: No generic descriptor for contract ${t}`));t=t.toLowerCase(),r=`0x${r.slice(2).toLowerCase()}`;const i=o.descriptors_calldata?.[t]?.[r];if(!i)return(0,p.Left)(new Error(`[ContextModule] HttpTransactionDataSource: Invalid response for contract ${t} and selector ${r}`));if(!this.isCalldataDescriptorV1(i,this.config.cal.mode))return(0,p.Left)(new Error(`[ContextModule] HttpTransactionDataSource: Failed to decode transaction descriptor for contract ${t} and selector ${r}`));const l=i.transaction_info.descriptor.data,A=i.transaction_info.descriptor.signatures[this.config.cal.mode],D={type:s.ClearSignContextType.TRANSACTION_INFO,payload:this.formatTransactionInfo(l,A)},V=i.enums.map(a=>({type:s.ClearSignContextType.ENUM,payload:a.descriptor})),b=i.fields.map(a=>({type:s.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:a.descriptor,reference:this.getReference(a.param)}));return(0,p.Right)([D,...V,...b])}formatTransactionInfo(e,t){t.length%2!==0&&(t="0"+t);const r="81ff",o=(t.length/2).toString(16);return`${e}${r}${o}${t}`}getReference(e){if(e.type==="TOKEN_AMOUNT"&&e.token!==void 0)return{type:s.ClearSignContextType.TOKEN,valuePath:this.toGenericPath(e.token.binary_path)};if(e.type==="NFT")return{type:s.ClearSignContextType.NFT,valuePath:this.toGenericPath(e.collection.binary_path)};if(e.type==="TRUSTED_NAME")return{type:s.ClearSignContextType.TRUSTED_NAME,valuePath:this.toGenericPath(e.value.binary_path),types:e.types,sources:e.sources}}toGenericPath(e){return e.type==="CONTAINER"?e.value:e.elements.map(t=>{if(t.type==="ARRAY"){const{weight:r,...o}=t;return{itemSize:r,...o}}else if(t.type==="LEAF"){const{leaf_type:r,...o}=t;return{leafType:r,...o}}return t})}isCalldataDescriptorV1(e,t){return typeof e=="object"&&e.type==="calldata"&&e.version==="v1"&&this.isTransactionInfoV1(e.transaction_info,t)&&Array.isArray(e.enums)&&Array.isArray(e.fields)&&e.enums.every(r=>this.isEnumV1(r))&&e.fields.every(r=>this.isFieldV1(r))}isTransactionInfoV1(e,t){return typeof e=="object"&&typeof e.descriptor=="object"&&typeof e.descriptor.data=="string"&&typeof e.descriptor.signatures=="object"&&typeof e.descriptor.signatures[t]=="string"}isEnumV1(e){return typeof e=="object"&&typeof e.descriptor=="string"}isFieldV1(e){return typeof e=="object"&&typeof e.descriptor=="string"&&typeof e.param=="object"&&typeof e.param.value=="object"&&this.isDescriptorValueV1(e.param.value)&&(e.param.type==="RAW"||e.param.type==="AMOUNT"||e.param.type==="DATETIME"||e.param.type==="DURATION"||e.param.type==="UNIT"||e.param.type==="ENUM"||e.param.type==="NFT"&&this.isDescriptorValueV1(e.param.collection)||e.param.type==="TOKEN_AMOUNT"&&(e.param.token===void 0||this.isDescriptorValueV1(e.param.token))||e.param.type==="TRUSTED_NAME"&&Array.isArray(e.param.types)&&Array.isArray(e.param.sources)&&e.param.types.every(t=>typeof t=="string")&&e.param.sources.every(t=>typeof t=="string"))}isDescriptorValueV1(e){return typeof e=="object"&&typeof e.type_family=="string"&&["UINT","INT","UFIXED","FIXED","ADDRESS","BOOL","BYTES","STRING"].includes(e.type_family)&&(typeof e.type_size>"u"||typeof e.type_size=="number")&&(typeof e.binary_path=="object"&&e.binary_path.type==="CONTAINER"&&["FROM","TO","VALUE"].includes(e.binary_path.value)||e.binary_path.type==="DATA"&&Array.isArray(e.binary_path.elements)&&e.binary_path.elements.every(t=>this.isPathElementV1(t)))}isPathElementV1(e){return typeof e=="object"&&(e.type==="REF"||e.type==="TUPLE"&&typeof e.offset=="number"||e.type==="ARRAY"&&typeof e.weight=="number"&&(typeof e.start>"u"||typeof e.start=="number")&&(typeof e.length>"u"||typeof e.length=="number")||e.type==="LEAF"&&typeof e.leaf_type=="string"&&["ARRAY_LEAF","TUPLE_LEAF","STATIC_LEAF","DYNAMIC_LEAF"].includes(e.leaf_type)||e.type==="SLICE"&&(typeof e.start>"u"||typeof e.start=="number")&&(typeof e.end>"u"||typeof e.end=="number"))}};f=h([(0,y.injectable)(),T(0,(0,y.inject)(E.configTypes.Config))],f);0&&(module.exports={HttpTransactionDataSource});
1
+ "use strict";var L=Object.create;var c=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var G=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var K=(i,e)=>{for(var t in e)c(i,t,{get:e[t],enumerable:!0})},E=(i,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of j(e))!w.call(i,o)&&o!==t&&c(i,o,{get:()=>e[o],enumerable:!(r=g(e,o))||r.enumerable});return i};var D=(i,e,t)=>(t=i!=null?L(G(i)):{},E(e||!i||!i.__esModule?c(t,"default",{value:i,enumerable:!0}):t,i)),$=i=>E(c({},"__esModule",{value:!0}),i),V=(i,e,t,r)=>{for(var o=r>1?void 0:r?g(e,t):e,a=i.length-1,n;a>=0;a--)(n=i[a])&&(o=(r?n(e,t,o):n(o))||o);return r&&o&&c(e,t,o),o},C=(i,e)=>(t,r)=>e(t,r,i);var B={};K(B,{HttpTransactionDataSource:()=>y});module.exports=$(B);var A=D(require("axios")),f=require("inversify"),l=require("purify-ts"),b=require("../../config/di/configTypes"),v=require("../../pki/di/pkiTypes"),N=require("../../pki/model/KeyId"),P=require("../../pki/model/KeyUsage"),s=require("../../shared/model/ClearSignContext"),d=require("../../shared/model/SignatureTags"),m=require("../../shared/utils/HexStringUtils"),_=D(require("../../../package.json"));let y=class{constructor(e,t){this.config=e;this._certificateLoader=t}async getTransactionDescriptors({chainId:e,address:t,selector:r,deviceModelId:o}){let a;try{a=(await A.default.request({method:"GET",url:`${this.config.cal.url}/dapps`,params:{output:"descriptors_calldata",chain_id:e,contracts:t,ref:`branch:${this.config.cal.branch}`},headers:{"X-Ledger-Client-Version":`context-module/${_.default.version}`}})).data}catch(n){return(0,l.Left)(new Error(`[ContextModule] HttpTransactionDataSource: Failed to fetch transaction informations: ${n}`))}if(!Array.isArray(a))return(0,l.Left)(new Error("[ContextModule] HttpTransactionDataSource: Response is not an array"));if(a.length===0)return(0,l.Left)(new Error(`[ContextModule] HttpTransactionDataSource: No data for contract ${t} and selector ${r}`));for(const n of a){t=t.toLowerCase(),r=`0x${r.slice(2).toLowerCase()}`;const p=n.descriptors_calldata?.[t]?.[r];if(!p||!this.isCalldataDescriptorV1(p,this.config.cal.mode))continue;const S=p.transaction_info.descriptor.data,M=p.transaction_info.descriptor.signatures[this.config.cal.mode],I={targetDevice:o,keyUsage:P.KeyUsage.Calldata,keyId:N.KeyId.CalCalldataKey},h=await this._certificateLoader.loadCertificate(I),x={type:s.ClearSignContextType.TRANSACTION_INFO,payload:m.HexStringUtils.appendSignatureToPayload(S,M,d.INFO_SIGNATURE_TAG),certificate:h},T=[];for(const[u,O]of Object.entries(p.enums))for(const[F,{data:U,signatures:k}]of Object.entries(O))T.push({type:s.ClearSignContextType.ENUM,id:Number(u),value:Number(F),payload:m.HexStringUtils.appendSignatureToPayload(U,k[this.config.cal.mode],d.INFO_SIGNATURE_TAG),certificate:h});const R=p.fields.map(u=>({type:s.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:u.descriptor,reference:this.getReference(u.param)}));return(0,l.Right)([x,...T,...R])}return(0,l.Left)(new Error(`[ContextModule] HttpTransactionDataSource: Invalid response for contract ${t} and selector ${r}`))}getReference(e){if(e.type==="TOKEN_AMOUNT"&&e.token!==void 0&&e.token.type==="path")return{type:s.ClearSignContextType.TOKEN,valuePath:this.toGenericPath(e.token.binary_path)};if(e.type==="TOKEN_AMOUNT"&&e.token!==void 0&&e.token.type==="constant")return{type:s.ClearSignContextType.TOKEN,value:e.token.value};if(e.type==="NFT"&&e.collection.type==="path")return{type:s.ClearSignContextType.NFT,valuePath:this.toGenericPath(e.collection.binary_path)};if(e.type==="NFT"&&e.collection.type==="constant")return{type:s.ClearSignContextType.NFT,value:e.collection.value};if(e.type==="TRUSTED_NAME"&&e.value.type==="path")return{type:s.ClearSignContextType.TRUSTED_NAME,valuePath:this.toGenericPath(e.value.binary_path),types:e.types,sources:e.sources};if(e.type==="ENUM"&&e.value.type==="path")return{type:s.ClearSignContextType.ENUM,valuePath:this.toGenericPath(e.value.binary_path),id:e.id}}toGenericPath(e){return e.type==="CONTAINER"?e.value:e.elements.map(t=>{if(t.type==="ARRAY"){const{weight:r,...o}=t;return{itemSize:r,...o}}else if(t.type==="LEAF"){const{leaf_type:r,...o}=t;return{leafType:r,...o}}return t})}isCalldataDescriptorV1(e,t){return typeof e=="object"&&e.type==="calldata"&&e.version==="v1"&&this.isTransactionInfoV1(e.transaction_info,t)&&this.isEnumV1(e.enums,t)&&Array.isArray(e.fields)&&e.fields.every(r=>this.isFieldV1(r))}isTransactionInfoV1(e,t){return typeof e=="object"&&typeof e.descriptor=="object"&&typeof e.descriptor.data=="string"&&typeof e.descriptor.signatures=="object"&&typeof e.descriptor.signatures[t]=="string"}isEnumV1(e,t){return typeof e=="object"&&Object.entries(e).every(([r,o])=>typeof r=="string"&&typeof o=="object"&&Object.entries(o).every(([a,n])=>typeof a=="string"&&typeof n=="object"&&typeof n.data=="string"&&n.signatures!==void 0&&this.isCalldataSignatures(n.signatures,t)))}isCalldataSignatures(e,t){return typeof e=="object"&&typeof e[t]=="string"}isFieldV1(e){return typeof e=="object"&&typeof e.descriptor=="string"&&typeof e.param=="object"&&typeof e.param.value=="object"&&this.isDescriptorValueV1(e.param.value)&&(e.param.type==="RAW"||e.param.type==="AMOUNT"||e.param.type==="DATETIME"||e.param.type==="DURATION"||e.param.type==="UNIT"||e.param.type==="ENUM"||e.param.type==="NFT"&&this.isDescriptorValueV1(e.param.collection)||e.param.type==="TOKEN_AMOUNT"&&(e.param.token===void 0||this.isDescriptorValueV1(e.param.token))||e.param.type==="TRUSTED_NAME"&&Array.isArray(e.param.types)&&Array.isArray(e.param.sources)&&e.param.types.every(t=>typeof t=="string")&&e.param.sources.every(t=>typeof t=="string"))}isDescriptorValueV1(e){return typeof e=="object"&&typeof e.type_family=="string"&&["UINT","INT","UFIXED","FIXED","ADDRESS","BOOL","BYTES","STRING"].includes(e.type_family)&&(typeof e.type_size>"u"||typeof e.type_size=="number")&&(e.type==="path"&&this.isCalldataDescriptorValueBinaryPathV1(e)||e.type==="constant"&&this.isCalldataDescriptorValueConstantV1(e))}isCalldataDescriptorValueConstantV1(e){return typeof e=="object"&&e.type==="constant"&&typeof e.value=="string"}isCalldataDescriptorValueBinaryPathV1(e){return typeof e=="object"&&(e.type==="path"&&e.binary_path.type==="CONTAINER"&&["FROM","TO","VALUE"].includes(e.binary_path.value)||e.binary_path.type==="DATA"&&Array.isArray(e.binary_path.elements)&&e.binary_path.elements.every(t=>this.isPathElementV1(t)))}isPathElementV1(e){return typeof e=="object"&&(e.type==="REF"||e.type==="TUPLE"&&typeof e.offset=="number"||e.type==="ARRAY"&&typeof e.weight=="number"&&(typeof e.start>"u"||typeof e.start=="number")&&(typeof e.end>"u"||typeof e.end=="number")||e.type==="LEAF"&&typeof e.leaf_type=="string"&&["ARRAY_LEAF","TUPLE_LEAF","STATIC_LEAF","DYNAMIC_LEAF"].includes(e.leaf_type)||e.type==="SLICE"&&(typeof e.start>"u"||typeof e.start=="number")&&(typeof e.end>"u"||typeof e.end=="number"))}};y=V([(0,f.injectable)(),C(0,(0,f.inject)(b.configTypes.Config)),C(1,(0,f.inject)(v.pkiTypes.PkiCertificateLoader))],y);0&&(module.exports={HttpTransactionDataSource});
2
2
  //# sourceMappingURL=HttpTransactionDataSource.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/transaction/data/HttpTransactionDataSource.ts"],
4
- "sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport type {\n ContextModuleCalMode,\n ContextModuleConfig,\n} from \"@/config/model/ContextModuleConfig\";\nimport {\n ClearSignContextReference,\n ClearSignContextSuccess,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { GenericPath } from \"@/shared/model/GenericPath\";\nimport PACKAGE from \"@root/package.json\";\n\nimport {\n CalldataDescriptor,\n CalldataDescriptorContainerPathV1,\n CalldataDescriptorParam,\n CalldataDescriptorPathElementsV1,\n CalldataDescriptorPathElementV1,\n CalldataDescriptorV1,\n CalldataDescriptorValueV1,\n CalldataDto,\n CalldataEnumV1,\n CalldataFieldV1,\n CalldataTransactionInfoV1,\n} from \"./CalldataDto\";\nimport {\n GetTransactionDescriptorsParams,\n TransactionDataSource,\n} from \"./TransactionDataSource\";\n\n@injectable()\nexport class HttpTransactionDataSource implements TransactionDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n ) {}\n public async getTransactionDescriptors({\n chainId,\n address,\n selector,\n }: GetTransactionDescriptorsParams): Promise<\n Either<Error, ClearSignContextSuccess[]>\n > {\n let calldata: CalldataDto | undefined;\n try {\n const response = await axios.request<CalldataDto[]>({\n method: \"GET\",\n url: `${this.config.cal.url}/dapps`,\n params: {\n output: \"descriptors_calldata\",\n chain_id: chainId,\n contracts: address,\n ref: `branch:${this.config.cal.branch}`,\n },\n headers: {\n \"X-Ledger-Client-Version\": `context-module/${PACKAGE.version}`,\n },\n });\n calldata = response.data?.[0];\n } catch (error) {\n return Left(\n new Error(\n `[ContextModule] HttpTransactionDataSource: Failed to fetch transaction informations: ${error}`,\n ),\n );\n }\n\n if (!calldata) {\n return Left(\n new Error(\n `[ContextModule] HttpTransactionDataSource: No generic descriptor for contract ${address}`,\n ),\n );\n }\n\n // Normalize the address and selector\n address = address.toLowerCase();\n selector = `0x${selector.slice(2).toLowerCase()}`;\n\n const calldataDescriptor =\n calldata.descriptors_calldata?.[address]?.[selector];\n if (!calldataDescriptor) {\n return Left(\n new Error(\n `[ContextModule] HttpTransactionDataSource: Invalid response for contract ${address} and selector ${selector}`,\n ),\n );\n }\n\n if (\n !this.isCalldataDescriptorV1(calldataDescriptor, this.config.cal.mode)\n ) {\n return Left(\n new Error(\n `[ContextModule] HttpTransactionDataSource: Failed to decode transaction descriptor for contract ${address} and selector ${selector}`,\n ),\n );\n }\n\n const infoData = calldataDescriptor.transaction_info.descriptor.data;\n const infoSignature =\n calldataDescriptor.transaction_info.descriptor.signatures[\n this.config.cal.mode\n ];\n const info: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: this.formatTransactionInfo(infoData, infoSignature),\n };\n const enums: ClearSignContextSuccess[] = calldataDescriptor.enums.map(\n (e) => ({\n type: ClearSignContextType.ENUM,\n payload: e.descriptor,\n }),\n );\n const fields: ClearSignContextSuccess[] = calldataDescriptor.fields.map(\n (field) => ({\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: field.descriptor,\n reference: this.getReference(field.param),\n }),\n );\n return Right([info, ...enums, ...fields]);\n }\n\n private formatTransactionInfo(\n infoData: string,\n infoSignature: string,\n ): string {\n // Ensure correct padding\n if (infoSignature.length % 2 !== 0) {\n infoSignature = \"0\" + infoSignature;\n }\n // TLV encoding as according to generic parser documentation\n const infoSignatureTag = \"81ff\";\n const infoSignatureLength = (infoSignature.length / 2).toString(16);\n return `${infoData}${infoSignatureTag}${infoSignatureLength}${infoSignature}`;\n }\n\n private getReference(\n param: CalldataDescriptorParam,\n ): ClearSignContextReference | undefined {\n if (param.type === \"TOKEN_AMOUNT\" && param.token !== undefined) {\n return {\n type: ClearSignContextType.TOKEN,\n valuePath: this.toGenericPath(param.token.binary_path),\n };\n } else if (param.type === \"NFT\") {\n return {\n type: ClearSignContextType.NFT,\n valuePath: this.toGenericPath(param.collection.binary_path),\n };\n } else if (param.type === \"TRUSTED_NAME\") {\n return {\n type: ClearSignContextType.TRUSTED_NAME,\n valuePath: this.toGenericPath(param.value.binary_path),\n types: param.types,\n sources: param.sources,\n };\n }\n return undefined;\n }\n\n private toGenericPath(\n path: CalldataDescriptorContainerPathV1 | CalldataDescriptorPathElementsV1,\n ): GenericPath {\n if (path.type === \"CONTAINER\") {\n return path.value;\n }\n return path.elements.map((element) => {\n if (element.type === \"ARRAY\") {\n const { weight: itemSize, ...rest } = element;\n return {\n itemSize,\n ...rest,\n };\n } else if (element.type === \"LEAF\") {\n const { leaf_type: leafType, ...rest } = element;\n return {\n leafType,\n ...rest,\n };\n }\n return element;\n });\n }\n\n private isCalldataDescriptorV1(\n data: CalldataDescriptor,\n mode: ContextModuleCalMode,\n ): data is CalldataDescriptorV1 & {\n transaction_info: {\n descriptor: {\n signatures: { [key in ContextModuleCalMode]: string };\n };\n };\n } {\n return (\n typeof data === \"object\" &&\n data.type === \"calldata\" &&\n data.version === \"v1\" &&\n this.isTransactionInfoV1(data.transaction_info, mode) &&\n Array.isArray(data.enums) &&\n Array.isArray(data.fields) &&\n data.enums.every((e) => this.isEnumV1(e)) &&\n data.fields.every((f) => this.isFieldV1(f))\n );\n }\n\n private isTransactionInfoV1(\n data: CalldataTransactionInfoV1,\n mode: ContextModuleCalMode,\n ): data is CalldataTransactionInfoV1 & {\n descriptor: {\n signatures: { [key in ContextModuleCalMode]: string };\n };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.descriptor === \"object\" &&\n typeof data.descriptor.data === \"string\" &&\n typeof data.descriptor.signatures === \"object\" &&\n typeof data.descriptor.signatures[mode] === \"string\"\n );\n }\n\n private isEnumV1(data: CalldataEnumV1): boolean {\n return typeof data === \"object\" && typeof data.descriptor === \"string\";\n }\n\n private isFieldV1(data: CalldataFieldV1): boolean {\n return (\n typeof data === \"object\" &&\n typeof data.descriptor === \"string\" &&\n typeof data.param === \"object\" &&\n typeof data.param.value === \"object\" &&\n this.isDescriptorValueV1(data.param.value) &&\n (data.param.type === \"RAW\" ||\n data.param.type === \"AMOUNT\" ||\n data.param.type === \"DATETIME\" ||\n data.param.type === \"DURATION\" ||\n data.param.type === \"UNIT\" ||\n data.param.type === \"ENUM\" ||\n (data.param.type === \"NFT\" &&\n this.isDescriptorValueV1(data.param.collection)) ||\n (data.param.type === \"TOKEN_AMOUNT\" &&\n (data.param.token === undefined ||\n this.isDescriptorValueV1(data.param.token))) ||\n (data.param.type === \"TRUSTED_NAME\" &&\n Array.isArray(data.param.types) &&\n Array.isArray(data.param.sources) &&\n data.param.types.every((t) => typeof t === \"string\") &&\n data.param.sources.every((t) => typeof t === \"string\")))\n );\n }\n\n private isDescriptorValueV1(data: CalldataDescriptorValueV1): boolean {\n return (\n typeof data === \"object\" &&\n typeof data.type_family === \"string\" &&\n [\n \"UINT\",\n \"INT\",\n \"UFIXED\",\n \"FIXED\",\n \"ADDRESS\",\n \"BOOL\",\n \"BYTES\",\n \"STRING\",\n ].includes(data.type_family) &&\n (typeof data.type_size === \"undefined\" ||\n typeof data.type_size === \"number\") &&\n ((typeof data.binary_path === \"object\" &&\n data.binary_path.type === \"CONTAINER\" &&\n [\"FROM\", \"TO\", \"VALUE\"].includes(data.binary_path.value)) ||\n (data.binary_path.type === \"DATA\" &&\n Array.isArray(data.binary_path.elements) &&\n data.binary_path.elements.every((e) => this.isPathElementV1(e))))\n );\n }\n\n private isPathElementV1(data: CalldataDescriptorPathElementV1): boolean {\n return (\n typeof data === \"object\" &&\n (data.type === \"REF\" ||\n (data.type === \"TUPLE\" && typeof data.offset === \"number\") ||\n (data.type === \"ARRAY\" &&\n typeof data.weight === \"number\" &&\n (typeof data.start === \"undefined\" ||\n typeof data.start === \"number\") &&\n (typeof data.length === \"undefined\" ||\n typeof data.length === \"number\")) ||\n (data.type === \"LEAF\" &&\n typeof data.leaf_type === \"string\" &&\n [\"ARRAY_LEAF\", \"TUPLE_LEAF\", \"STATIC_LEAF\", \"DYNAMIC_LEAF\"].includes(\n data.leaf_type,\n )) ||\n (data.type === \"SLICE\" &&\n (typeof data.start === \"undefined\" ||\n typeof data.start === \"number\") &&\n (typeof data.end === \"undefined\" || typeof data.end === \"number\")))\n );\n }\n}\n"],
5
- "mappings": "qtBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,+BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkB,oBAClBC,EAAmC,qBACnCC,EAAoC,qBAEpCC,EAA4B,mCAK5BC,EAIO,2CAEPC,EAAoB,iCAqBb,IAAMC,EAAN,KAAiE,CACtE,YAC+CC,EAC7C,CAD6C,YAAAA,CAC5C,CACH,MAAa,0BAA0B,CACrC,QAAAC,EACA,QAAAC,EACA,SAAAC,CACF,EAEE,CACA,IAAIC,EACJ,GAAI,CAcFA,GAbiB,MAAM,EAAAC,Q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A,EAAK,UAAc,KACzB,OAAOA,EAAK,WAAc,YAC1B,OAAOA,EAAK,aAAgB,UAC5BA,EAAK,YAAY,OAAS,aAC1B,CAAC,OAAQ,KAAM,OAAO,EAAE,SAASA,EAAK,YAAY,KAAK,GACtDA,EAAK,YAAY,OAAS,QACzB,MAAM,QAAQA,EAAK,YAAY,QAAQ,GACvCA,EAAK,YAAY,SAAS,MAAOX,GAAM,KAAK,gBAAgBA,CAAC,CAAC,EAEtE,CAEQ,gBAAgBW,EAAgD,CACtE,OACE,OAAOA,GAAS,WACfA,EAAK,OAAS,OACZA,EAAK,OAAS,SAAW,OAAOA,EAAK,QAAW,UAChDA,EAAK,OAAS,SACb,OAAOA,EAAK,QAAW,WACtB,OAAOA,EAAK,MAAU,KACrB,OAAOA,EAAK,OAAU,YACvB,OAAOA,EAAK,OAAW,KACtB,OAAOA,EAAK,QAAW,WAC1BA,EAAK,OAAS,QACb,OAAOA,EAAK,WAAc,UAC1B,CAAC,aAAc,aAAc,cAAe,cAAc,EAAE,SAC1DA,EAAK,SACP,GACDA,EAAK,OAAS,UACZ,OAAOA,EAAK,MAAU,KACrB,OAAOA,EAAK,OAAU,YACvB,OAAOA,EAAK,IAAQ,KAAe,OAAOA,EAAK,KAAQ,UAEhE,CACF,EA9QazB,EAAN4B,EAAA,IADN,cAAW,EAGPC,EAAA,eAAO,cAAY,MAAM,IAFjB7B",
6
- "names": ["HttpTransactionDataSource_exports", "__export", "HttpTransactionDataSource", "__toCommonJS", "import_axios", "import_inversify", "import_purify_ts", "import_configTypes", "import_ClearSignContext", "import_package", "HttpTransactionDataSource", "config", "chainId", "address", "selector", "calldata", "axios", "PACKAGE", "error", "calldataDescriptor", "infoData", "infoSignature", "info", "enums", "e", "fields", "field", "infoSignatureTag", "infoSignatureLength", "param", "path", "element", "itemSize", "rest", "leafType", "data", "mode", "f", "__decorateClass", "__decorateParam"]
4
+ "sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport {\n type ContextModuleCalMode,\n type ContextModuleConfig,\n} from \"@/config/model/ContextModuleConfig\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { PkiCertificateInfo } from \"@/pki/model/PkiCertificateInfo\";\nimport {\n ClearSignContextReference,\n ClearSignContextSuccess,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { GenericPath } from \"@/shared/model/GenericPath\";\nimport { INFO_SIGNATURE_TAG } from \"@/shared/model/SignatureTags\";\nimport { HexStringUtils } from \"@/shared/utils/HexStringUtils\";\nimport PACKAGE from \"@root/package.json\";\n\nimport {\n CalldataDescriptor,\n CalldataDescriptorContainerPathV1,\n CalldataDescriptorParam,\n CalldataDescriptorPathElementsV1,\n CalldataDescriptorPathElementV1,\n CalldataDescriptorV1,\n CalldataDescriptorValueBinaryPathV1,\n CalldataDescriptorValueConstantV1,\n CalldataDescriptorValueV1,\n CalldataDto,\n CalldataEnumV1,\n CalldataFieldV1,\n CalldataSignatures,\n CalldataTransactionDescriptor,\n CalldataTransactionInfoV1,\n} from \"./CalldataDto\";\nimport {\n GetTransactionDescriptorsParams,\n TransactionDataSource,\n} from \"./TransactionDataSource\";\n\n@injectable()\nexport class HttpTransactionDataSource implements TransactionDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n ) {}\n\n public async getTransactionDescriptors({\n chainId,\n address,\n selector,\n deviceModelId,\n }: GetTransactionDescriptorsParams): Promise<\n Either<Error, ClearSignContextSuccess[]>\n > {\n let dto: CalldataDto[] | undefined;\n try {\n const response = await axios.request<CalldataDto[]>({\n method: \"GET\",\n url: `${this.config.cal.url}/dapps`,\n params: {\n output: \"descriptors_calldata\",\n chain_id: chainId,\n contracts: address,\n ref: `branch:${this.config.cal.branch}`,\n },\n headers: {\n \"X-Ledger-Client-Version\": `context-module/${PACKAGE.version}`,\n },\n });\n dto = response.data;\n } catch (error) {\n return Left(\n new Error(\n `[ContextModule] HttpTransactionDataSource: Failed to fetch transaction informations: ${error}`,\n ),\n );\n }\n\n if (!Array.isArray(dto)) {\n return Left(\n new Error(\n `[ContextModule] HttpTransactionDataSource: Response is not an array`,\n ),\n );\n }\n\n if (dto.length === 0) {\n return Left(\n new Error(\n `[ContextModule] HttpTransactionDataSource: No data for contract ${address} and selector ${selector}`,\n ),\n );\n }\n\n for (const calldata of dto) {\n // Normalize the address and selector\n address = address.toLowerCase();\n selector = `0x${selector.slice(2).toLowerCase()}`;\n const calldataDescriptor =\n calldata.descriptors_calldata?.[address]?.[selector];\n\n if (\n !calldataDescriptor ||\n !this.isCalldataDescriptorV1(calldataDescriptor, this.config.cal.mode)\n ) {\n continue;\n }\n\n const infoData = calldataDescriptor.transaction_info.descriptor.data;\n const infoSignature =\n calldataDescriptor.transaction_info.descriptor.signatures[\n this.config.cal.mode\n ];\n\n const certificateInfos: PkiCertificateInfo = {\n targetDevice: deviceModelId,\n keyUsage: KeyUsage.Calldata,\n keyId: KeyId.CalCalldataKey,\n };\n const certificate: PkiCertificate | undefined =\n await this._certificateLoader.loadCertificate(certificateInfos);\n\n const info: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: HexStringUtils.appendSignatureToPayload(\n infoData,\n infoSignature,\n INFO_SIGNATURE_TAG,\n ),\n certificate,\n };\n\n const enums: ClearSignContextSuccess[] = [];\n for (const [id, values] of Object.entries(calldataDescriptor.enums)) {\n for (const [\n value,\n { data, signatures },\n ] of Object.entries<CalldataTransactionDescriptor>(values)) {\n enums.push({\n type: ClearSignContextType.ENUM,\n id: Number(id),\n value: Number(value),\n payload: HexStringUtils.appendSignatureToPayload(\n data,\n signatures[this.config.cal.mode]!,\n INFO_SIGNATURE_TAG,\n ),\n certificate,\n });\n }\n }\n\n const fields: ClearSignContextSuccess[] = calldataDescriptor.fields.map(\n (field) => ({\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: field.descriptor,\n reference: this.getReference(field.param),\n }),\n );\n return Right([info, ...enums, ...fields]);\n }\n\n return Left(\n new Error(\n `[ContextModule] HttpTransactionDataSource: Invalid response for contract ${address} and selector ${selector}`,\n ),\n );\n }\n\n private getReference(\n param: CalldataDescriptorParam,\n ): ClearSignContextReference | undefined {\n if (\n param.type === \"TOKEN_AMOUNT\" &&\n param.token !== undefined &&\n param.token.type === \"path\"\n ) {\n return {\n type: ClearSignContextType.TOKEN,\n valuePath: this.toGenericPath(param.token.binary_path),\n };\n } else if (\n param.type === \"TOKEN_AMOUNT\" &&\n param.token !== undefined &&\n param.token.type === \"constant\"\n ) {\n return {\n type: ClearSignContextType.TOKEN,\n value: param.token.value,\n };\n } else if (param.type === \"NFT\" && param.collection.type === \"path\") {\n return {\n type: ClearSignContextType.NFT,\n valuePath: this.toGenericPath(param.collection.binary_path),\n };\n } else if (param.type === \"NFT\" && param.collection.type === \"constant\") {\n return {\n type: ClearSignContextType.NFT,\n value: param.collection.value,\n };\n } else if (param.type === \"TRUSTED_NAME\" && param.value.type === \"path\") {\n return {\n type: ClearSignContextType.TRUSTED_NAME,\n valuePath: this.toGenericPath(param.value.binary_path),\n types: param.types,\n sources: param.sources,\n };\n } else if (param.type === \"ENUM\" && param.value.type === \"path\") {\n return {\n type: ClearSignContextType.ENUM,\n valuePath: this.toGenericPath(param.value.binary_path),\n id: param.id,\n };\n }\n return undefined;\n }\n\n private toGenericPath(\n path: CalldataDescriptorContainerPathV1 | CalldataDescriptorPathElementsV1,\n ): GenericPath {\n if (path.type === \"CONTAINER\") {\n return path.value;\n }\n return path.elements.map((element) => {\n if (element.type === \"ARRAY\") {\n const { weight: itemSize, ...rest } = element;\n return {\n itemSize,\n ...rest,\n };\n } else if (element.type === \"LEAF\") {\n const { leaf_type: leafType, ...rest } = element;\n return {\n leafType,\n ...rest,\n };\n }\n return element;\n });\n }\n\n private isCalldataDescriptorV1(\n data: CalldataDescriptor,\n mode: ContextModuleCalMode,\n ): data is CalldataDescriptorV1 & {\n transaction_info: {\n descriptor: {\n signatures: { [key in ContextModuleCalMode]: string };\n };\n };\n } {\n return (\n typeof data === \"object\" &&\n data.type === \"calldata\" &&\n data.version === \"v1\" &&\n this.isTransactionInfoV1(data.transaction_info, mode) &&\n this.isEnumV1(data.enums, mode) &&\n Array.isArray(data.fields) &&\n data.fields.every((f) => this.isFieldV1(f))\n );\n }\n\n private isTransactionInfoV1(\n data: CalldataTransactionInfoV1,\n mode: ContextModuleCalMode,\n ): data is CalldataTransactionInfoV1 & {\n descriptor: {\n signatures: { [key in ContextModuleCalMode]: string };\n };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.descriptor === \"object\" &&\n typeof data.descriptor.data === \"string\" &&\n typeof data.descriptor.signatures === \"object\" &&\n typeof data.descriptor.signatures[mode] === \"string\"\n );\n }\n\n private isEnumV1(\n calldata: CalldataEnumV1,\n mode: ContextModuleCalMode,\n ): calldata is CalldataEnumV1 {\n return (\n typeof calldata === \"object\" &&\n Object.entries(calldata).every(\n ([id, values]) =>\n typeof id === \"string\" &&\n typeof values === \"object\" &&\n Object.entries<CalldataTransactionDescriptor>(values).every(\n ([value, obj]) =>\n typeof value === \"string\" &&\n typeof obj === \"object\" &&\n typeof obj.data === \"string\" &&\n obj.signatures !== undefined &&\n this.isCalldataSignatures(obj.signatures, mode),\n ),\n )\n );\n }\n\n private isCalldataSignatures(\n data: CalldataSignatures,\n mode: ContextModuleCalMode,\n ): data is CalldataSignatures & { [key in ContextModuleCalMode]: string } {\n return typeof data === \"object\" && typeof data[mode] === \"string\";\n }\n\n private isFieldV1(data: CalldataFieldV1): boolean {\n return (\n typeof data === \"object\" &&\n typeof data.descriptor === \"string\" &&\n typeof data.param === \"object\" &&\n typeof data.param.value === \"object\" &&\n this.isDescriptorValueV1(data.param.value) &&\n (data.param.type === \"RAW\" ||\n data.param.type === \"AMOUNT\" ||\n data.param.type === \"DATETIME\" ||\n data.param.type === \"DURATION\" ||\n data.param.type === \"UNIT\" ||\n data.param.type === \"ENUM\" ||\n (data.param.type === \"NFT\" &&\n this.isDescriptorValueV1(data.param.collection)) ||\n (data.param.type === \"TOKEN_AMOUNT\" &&\n (data.param.token === undefined ||\n this.isDescriptorValueV1(data.param.token))) ||\n (data.param.type === \"TRUSTED_NAME\" &&\n Array.isArray(data.param.types) &&\n Array.isArray(data.param.sources) &&\n data.param.types.every((t) => typeof t === \"string\") &&\n data.param.sources.every((t) => typeof t === \"string\")))\n );\n }\n\n private isDescriptorValueV1(data: CalldataDescriptorValueV1): boolean {\n return (\n typeof data === \"object\" &&\n typeof data.type_family === \"string\" &&\n [\n \"UINT\",\n \"INT\",\n \"UFIXED\",\n \"FIXED\",\n \"ADDRESS\",\n \"BOOL\",\n \"BYTES\",\n \"STRING\",\n ].includes(data.type_family) &&\n (typeof data.type_size === \"undefined\" ||\n typeof data.type_size === \"number\") &&\n ((data.type === \"path\" &&\n this.isCalldataDescriptorValueBinaryPathV1(data)) ||\n (data.type === \"constant\" &&\n this.isCalldataDescriptorValueConstantV1(data)))\n );\n }\n\n private isCalldataDescriptorValueConstantV1(\n data: CalldataDescriptorValueConstantV1,\n ): boolean {\n return (\n typeof data === \"object\" &&\n data.type === \"constant\" &&\n typeof data.value === \"string\"\n );\n }\n\n private isCalldataDescriptorValueBinaryPathV1(\n data: CalldataDescriptorValueBinaryPathV1,\n ): boolean {\n return (\n typeof data === \"object\" &&\n ((data.type === \"path\" &&\n data.binary_path.type === \"CONTAINER\" &&\n [\"FROM\", \"TO\", \"VALUE\"].includes(data.binary_path.value)) ||\n (data.binary_path.type === \"DATA\" &&\n Array.isArray(data.binary_path.elements) &&\n data.binary_path.elements.every((e) => this.isPathElementV1(e))))\n );\n }\n\n private isPathElementV1(data: CalldataDescriptorPathElementV1): boolean {\n return (\n typeof data === \"object\" &&\n (data.type === \"REF\" ||\n (data.type === \"TUPLE\" && typeof data.offset === \"number\") ||\n (data.type === \"ARRAY\" &&\n typeof data.weight === \"number\" &&\n (typeof data.start === \"undefined\" ||\n typeof data.start === \"number\") &&\n (typeof data.end === \"undefined\" || typeof data.end === \"number\")) ||\n (data.type === \"LEAF\" &&\n typeof data.leaf_type === \"string\" &&\n [\"ARRAY_LEAF\", \"TUPLE_LEAF\", \"STATIC_LEAF\", \"DYNAMIC_LEAF\"].includes(\n data.leaf_type,\n )) ||\n (data.type === \"SLICE\" &&\n (typeof data.start === \"undefined\" ||\n typeof data.start === \"number\") &&\n (typeof data.end === \"undefined\" || typeof data.end === \"number\")))\n );\n }\n}\n"],
5
+ "mappings": "qtBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,+BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkB,oBAClBC,EAAmC,qBACnCC,EAAoC,qBAEpCC,EAA4B,mCAK5BC,EAAyB,6BAEzBC,EAAsB,6BACtBC,EAAyB,gCAGzBC,EAIO,2CAEPC,EAAmC,wCACnCC,EAA+B,yCAC/BC,EAAoB,iCAyBb,IAAMC,EAAN,KAAiE,CACtE,YAC+CC,EAE5BC,EACjB,CAH6C,YAAAD,EAE5B,wBAAAC,CAChB,CAEH,MAAa,0BAA0B,CACrC,QAAAC,EACA,QAAAC,EACA,SAAAC,EACA,cAAAC,CACF,EAEE,CACA,IAAIC,EACJ,GAAI,CAcFA,GAbiB,MAAM,EAAAC,QAAM,QAAuB,CAClD,OAAQ,MACR,IAAK,GAAG,KAAK,OAAO,IAAI,GAAG,SAC3B,OAAQ,CACN,OAAQ,uBACR,SAAUL,EACV,UAAWC,EACX,IAAK,UAAU,KAAK,OAAO,IAAI,MAAM,EACvC,EACA,QAAS,CACP,0BAA2B,kBAAkB,EAAAK,Q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,OAAS,QACzB,MAAM,QAAQA,EAAK,YAAY,QAAQ,GACvCA,EAAK,YAAY,SAAS,MAAOa,GAAM,KAAK,gBAAgBA,CAAC,CAAC,EAEtE,CAEQ,gBAAgBb,EAAgD,CACtE,OACE,OAAOA,GAAS,WACfA,EAAK,OAAS,OACZA,EAAK,OAAS,SAAW,OAAOA,EAAK,QAAW,UAChDA,EAAK,OAAS,SACb,OAAOA,EAAK,QAAW,WACtB,OAAOA,EAAK,MAAU,KACrB,OAAOA,EAAK,OAAU,YACvB,OAAOA,EAAK,IAAQ,KAAe,OAAOA,EAAK,KAAQ,WACzDA,EAAK,OAAS,QACb,OAAOA,EAAK,WAAc,UAC1B,CAAC,aAAc,aAAc,cAAe,cAAc,EAAE,SAC1DA,EAAK,SACP,GACDA,EAAK,OAAS,UACZ,OAAOA,EAAK,MAAU,KACrB,OAAOA,EAAK,OAAU,YACvB,OAAOA,EAAK,IAAQ,KAAe,OAAOA,EAAK,KAAQ,UAEhE,CACF,EA3WatB,EAANoC,EAAA,IADN,cAAW,EAGPC,EAAA,eAAO,cAAY,MAAM,GACzBA,EAAA,eAAO,WAAS,oBAAoB,IAH5BrC",
6
+ "names": ["HttpTransactionDataSource_exports", "__export", "HttpTransactionDataSource", "__toCommonJS", "import_axios", "import_inversify", "import_purify_ts", "import_configTypes", "import_pkiTypes", "import_KeyId", "import_KeyUsage", "import_ClearSignContext", "import_SignatureTags", "import_HexStringUtils", "import_package", "HttpTransactionDataSource", "config", "_certificateLoader", "chainId", "address", "selector", "deviceModelId", "dto", "axios", "PACKAGE", "error", "calldata", "calldataDescriptor", "infoData", "infoSignature", "certificateInfos", "certificate", "info", "enums", "id", "values", "value", "data", "signatures", "fields", "field", "param", "path", "element", "itemSize", "rest", "leafType", "mode", "f", "obj", "e", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var A=Object.create;var m=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty;var O=(t,d,o,s)=>{if(d&&typeof d=="object"||typeof d=="function")for(let i of C(d))!F.call(t,i)&&i!==o&&m(t,i,{get:()=>d[i],enumerable:!(s=w(d,i))||s.enumerable});return t};var T=(t,d,o)=>(o=t!=null?A(_(t)):{},O(d||!t||!t.__esModule?m(o,"default",{value:t,enumerable:!0}):o,t));var c=T(require("axios")),r=require("purify-ts"),D=require("../../transaction/data/HttpTransactionDataSource"),E=T(require("../../../package.json"));jest.mock("axios");describe("HttpTransactionDataSource",()=>{let t,d,o,s,i,p,b,u,y,x;beforeAll(()=>{jest.clearAllMocks();const a={cal:{url:"https://crypto-assets-service.api.ledger.com/v1",mode:"test",branch:"main"}};t=new D.HttpTransactionDataSource(a),d={descriptor:{data:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c",signatures:{test:"3045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f"}}},o=[{descriptor:"0001000401000501010606737461626c65"},{descriptor:"00010004010005010206087661726961626c65"}],b=f("FROM","UFIXED","AMOUNT","06"),u=f("TO","FIXED","DATETIME","07"),y=f("TO","BOOL","UNIT","08"),x=f("VALUE","INT","DURATION","09"),s={param:{value:{binary_path:{type:"DATA",elements:[{type:"TUPLE",offset:0},{type:"LEAF",leaf_type:"STATIC_LEAF"}]},type_family:"UINT",type_size:32},type:"TOKEN_AMOUNT",token:{binary_path:{type:"DATA",elements:[{type:"ARRAY",start:0,length:5,weight:1},{type:"LEAF",leaf_type:"DYNAMIC_LEAF"}]},type_family:"ADDRESS",type_size:20}},descriptor:"0001000112416d6f756e7420746f20776974686472617702010203580001000115000100010101020120030a000100010200010401030215000100010105020114030a000100010200000401030420ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff05034d6178"},i={param:{value:{binary_path:{type:"CONTAINER",value:"TO"},type_family:"STRING",type_size:20},type:"TRUSTED_NAME",types:["eoa"],sources:["ens","unstoppable_domain"]},descriptor:"000100010c546f20726563697069656e7402010803230001000115000100010105020114030a00010001020002040103020101030402030402"},p={param:{value:{binary_path:{type:"DATA",elements:[{type:"ARRAY",weight:2},{type:"LEAF",leaf_type:"TUPLE_LEAF"},{type:"SLICE",end:2}]},type_family:"BYTES",type_size:20},collection:{binary_path:{type:"DATA",elements:[{type:"REF"},{type:"LEAF",leaf_type:"ARRAY_LEAF"},{type:"SLICE",start:1}]},type_family:"INT",type_size:20},type:"NFT"},descriptor:"000100010c546f20726563697069656e7402010803230001000115000100010105020114"}});function f(a,e,n,h){return{param:{value:{binary_path:{type:"CONTAINER",value:a},type_family:e,type_size:32},type:n},descriptor:h}}function l(a,e,n){return{descriptors_calldata:{"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9":{"0x69328dec":{type:"calldata",version:"v1",transaction_info:a,enums:e,fields:n}}}}}it("should call axios with the ledger client version header",async()=>{const a=`context-module/${E.default.version}`,e=jest.fn(()=>Promise.resolve({data:[]}));jest.spyOn(c.default,"request").mockImplementation(e),await t.getTransactionDescriptors({chainId:1,address:"0x0abc",selector:"0x01ff"}),expect(e).toHaveBeenCalledWith(expect.objectContaining({headers:{"X-Ledger-Client-Version":a}}))}),it("should return an error when axios throws an error",async()=>{jest.spyOn(c.default,"request").mockRejectedValue(new Error);const a=await t.getTransactionDescriptors({chainId:1,address:"0x0abc",selector:"0x01ff"});expect(a).toEqual((0,r.Left)(new Error("[ContextModule] HttpTransactionDataSource: Failed to fetch transaction informations: Error")))}),it("should return an error when no payload is returned",async()=>{const a={data:{test:""}};jest.spyOn(c.default,"request").mockResolvedValue(a);const e=await t.getTransactionDescriptors({chainId:1,address:"0x0abc",selector:"0x01ff"});expect(e).toEqual((0,r.Left)(new Error("[ContextModule] HttpTransactionDataSource: No generic descriptor for contract 0x0abc")))}),it("should return an error when selector is not found",async()=>{const a=l(d,o,[s]);jest.spyOn(c.default,"request").mockResolvedValue({data:[a]});const e=await t.getTransactionDescriptors({chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x01fe"});expect(e).toEqual((0,r.Left)(new Error("[ContextModule] HttpTransactionDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x01fe")))}),it("Calldata with fields references and enums",async()=>{const a=l(d,o,[s,i,p]);jest.spyOn(c.default,"request").mockResolvedValue({data:[a]});const e=await t.getTransactionDescriptors({chainId:1,address:"0x7d2768de32b0b80B7a3454c06bdac94a69ddc7a9",selector:"0x69328dEc"});expect(e.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{payload:"0001000401000501010606737461626c65",type:"enum"},{payload:"00010004010005010206087661726961626c65",type:"enum"},{payload:s.descriptor,type:"transactionFieldDescription",reference:{type:"token",valuePath:[{type:"ARRAY",start:0,length:5,itemSize:1},{type:"LEAF",leafType:"DYNAMIC_LEAF"}]}},{payload:i.descriptor,type:"transactionFieldDescription",reference:{type:"trustedName",valuePath:"TO",types:["eoa"],sources:["ens","unstoppable_domain"]}},{payload:p.descriptor,type:"transactionFieldDescription",reference:{type:"nft",valuePath:[{type:"REF"},{type:"LEAF",leafType:"ARRAY_LEAF"},{type:"SLICE",start:1}]}}])}),it("Calldata without fields references",async()=>{const a=l(d,[],[b,u,y,x]);jest.spyOn(c.default,"request").mockResolvedValue({data:[a]});const e=await t.getTransactionDescriptors({chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(e.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{type:"transactionFieldDescription",payload:b.descriptor},{type:"transactionFieldDescription",payload:u.descriptor},{type:"transactionFieldDescription",payload:y.descriptor},{type:"transactionFieldDescription",payload:x.descriptor}])}),it("should return an error when calldata is not correctly formatted",async()=>{const a={descriptors_calldata:{"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9":{"0x69328dec":{type:"calldat",version:"v1",transaction_info:d,enums:o,fields:[s]}}}};jest.spyOn(c.default,"request").mockResolvedValue({data:[a]});const e=await t.getTransactionDescriptors({chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(e).toEqual((0,r.Left)(new Error("[ContextModule] HttpTransactionDataSource: Failed to decode transaction descriptor for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when transactionInfo is not correctly formatted",async()=>{const a=l({descriptor:{data:"1234",signatures:{prod:"1234"}}},o,[s]);jest.spyOn(c.default,"request").mockResolvedValue({data:[a]});const e=await t.getTransactionDescriptors({chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(e).toEqual((0,r.Left)(new Error("[ContextModule] HttpTransactionDataSource: Failed to decode transaction descriptor for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when enum is not correctly formatted",async()=>{const a=l(d,["badEnum"],[s]);jest.spyOn(c.default,"request").mockResolvedValue({data:[a]});const e=await t.getTransactionDescriptors({chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(e).toEqual((0,r.Left)(new Error("[ContextModule] HttpTransactionDataSource: Failed to decode transaction descriptor for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when field is not correctly formatted",async()=>{const a=l(d,[],[{descriptor:3}]);jest.spyOn(c.default,"request").mockResolvedValue({data:[a]});const e=await t.getTransactionDescriptors({chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(e).toEqual((0,r.Left)(new Error("[ContextModule] HttpTransactionDataSource: Failed to decode transaction descriptor for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when field value is not correctly formatted",async()=>{const e=l(d,[],[{param:{value:{binary_path:"TO",type_family:"UNKNOWN",type_size:20},type:"DATETIME"},descriptor:"000100010c546f20726563697069667"}]);jest.spyOn(c.default,"request").mockResolvedValue({data:[e]});const n=await t.getTransactionDescriptors({chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(n).toEqual((0,r.Left)(new Error("[ContextModule] HttpTransactionDataSource: Failed to decode transaction descriptor for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when field container path is not correctly formatted",async()=>{const e=l(d,[],[{param:{value:{binary_path:"UNKNOWN",type_family:"ADDRESS",type_size:20},type:"DATETIME"},descriptor:"000100010c546f20726563697069667"}]);jest.spyOn(c.default,"request").mockResolvedValue({data:[e]});const n=await t.getTransactionDescriptors({chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(n).toEqual((0,r.Left)(new Error("[ContextModule] HttpTransactionDataSource: Failed to decode transaction descriptor for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when field calldata path is not correctly formatted",async()=>{const e=l(d,[],[{param:{value:{binary_path:{elements:[{type:"UNKNOWN"}]},type_family:"ADDRESS",type_size:20},type:"DATETIME"},descriptor:"000100010c546f20726563697069667"}]);jest.spyOn(c.default,"request").mockResolvedValue({data:[e]});const n=await t.getTransactionDescriptors({chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(n).toEqual((0,r.Left)(new Error("[ContextModule] HttpTransactionDataSource: Failed to decode transaction descriptor for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when field type is not correctly formatted",async()=>{const e=l(d,[],[{param:{value:{binary_path:"TO",type_family:"ADDRESS",type_size:20},type:"UNKNOWN"},descriptor:"000100010c546f20726563697069667"}]);jest.spyOn(c.default,"request").mockResolvedValue({data:[e]});const n=await t.getTransactionDescriptors({chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(n).toEqual((0,r.Left)(new Error("[ContextModule] HttpTransactionDataSource: Failed to decode transaction descriptor for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))})});
1
+ "use strict";var A=Object.create;var T=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var R=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var _=(t,d,f,l)=>{if(d&&typeof d=="object"||typeof d=="function")for(let p of O(d))!w.call(t,p)&&p!==f&&T(t,p,{get:()=>d[p],enumerable:!(l=F(d,p))||l.enumerable});return t};var D=(t,d,f)=>(f=t!=null?A(R(t)):{},_(d||!t||!t.__esModule?T(f,"default",{value:t,enumerable:!0}):f,t));var o=require("@ledgerhq/device-management-kit"),r=D(require("axios")),i=require("purify-ts"),h=require("../../transaction/data/HttpTransactionDataSource"),I=D(require("../../../package.json"));vi.mock("axios");describe("HttpTransactionDataSource",()=>{let t,d,f,l,p,m,b,y,u,v,x;const c={loadCertificate:vi.fn()};beforeAll(()=>{vi.clearAllMocks();const e={cal:{url:"https://crypto-assets-service.api.ledger.com/v1",mode:"test",branch:"main"}};t=new h.HttpTransactionDataSource(e,c),d={descriptor:{data:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c",signatures:{test:"3045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f"}}},f={0:{1:{data:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec0401000501010606737461626c65",signatures:{test:"3045022100862e724db664f5d94484928a6a5963268a22cd8178ad36e8c4ff13769ac5c27e0220079da2b6e86810156f6b5955b8190bc016c2fe813d27fcb878a9b99658546582"}},2:{data:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04010005010206087661726961626c65",signatures:{test:"3045022100b838ee3d597d6bad2533606cef7335f6c8a45b46d5717803e646777f6c8a6897022074f04b82c3dad8445bb6230ab762010c5fc6ee06198fd3e54752287cbf95c523"}}}},b=E("FROM","UFIXED","AMOUNT","06"),y=E("TO","FIXED","DATETIME","07"),u=E("TO","BOOL","UNIT","08"),v=E("VALUE","INT","DURATION","09"),l={param:{value:{type:"path",binary_path:{type:"DATA",elements:[{type:"TUPLE",offset:0},{type:"LEAF",leaf_type:"STATIC_LEAF"}]},type_family:"UINT",type_size:32},type:"TOKEN_AMOUNT",token:{type:"path",binary_path:{type:"DATA",elements:[{type:"ARRAY",start:0,end:5,weight:1},{type:"LEAF",leaf_type:"DYNAMIC_LEAF"}]},type_family:"ADDRESS",type_size:20}},descriptor:"0001000112416d6f756e7420746f20776974686472617702010203580001000115000100010101020120030a000100010200010401030215000100010105020114030a000100010200000401030420ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff05034d6178"},p={param:{value:{type:"path",binary_path:{type:"CONTAINER",value:"TO"},type_family:"STRING",type_size:20},type:"TRUSTED_NAME",types:["eoa"],sources:["ens","unstoppable_domain"]},descriptor:"000100010c546f20726563697069656e7402010803230001000115000100010105020114030a00010001020002040103020101030402030402"},m={param:{value:{type:"path",binary_path:{type:"DATA",elements:[{type:"ARRAY",weight:2},{type:"LEAF",leaf_type:"TUPLE_LEAF"},{type:"SLICE",end:2}]},type_family:"BYTES",type_size:20},collection:{type:"path",binary_path:{type:"DATA",elements:[{type:"REF"},{type:"LEAF",leaf_type:"ARRAY_LEAF"},{type:"SLICE",start:1}]},type_family:"INT",type_size:20},type:"NFT"},descriptor:"000100010c546f20726563697069656e7402010803230001000115000100010105020114"},x={param:{id:0,value:{type:"path",binary_path:{type:"DATA",elements:[]},type_family:"BYTES",type_size:20},type:"ENUM"},descriptor:"000100010c546f20726563697069656e7402010803230001000115000100010105020112"}});function E(e,a,n,C){return{param:{value:{type:"path",binary_path:{type:"CONTAINER",value:e},type_family:a,type_size:32},type:n},descriptor:C}}function s(e,a,n){return{descriptors_calldata:{"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9":{"0x69328dec":{type:"calldata",version:"v1",transaction_info:e,enums:a,fields:n}}}}}it("should call axios with the ledger client version header",async()=>{const e=`context-module/${I.default.version}`,a=vi.fn(()=>Promise.resolve({data:[]}));vi.spyOn(r.default,"request").mockImplementation(a),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0),await t.getTransactionDescriptors({deviceModelId:o.DeviceModelId.FLEX,chainId:1,address:"0x0abc",selector:"0x01ff"}),expect(a).toHaveBeenCalledWith(expect.objectContaining({headers:{"X-Ledger-Client-Version":e}}))}),it("should return an error when axios throws an error",async()=>{vi.spyOn(r.default,"request").mockRejectedValue(new Error),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const e=await t.getTransactionDescriptors({deviceModelId:o.DeviceModelId.FLEX,chainId:1,address:"0x0abc",selector:"0x01ff"});expect(e).toEqual((0,i.Left)(new Error("[ContextModule] HttpTransactionDataSource: Failed to fetch transaction informations: Error")))}),it("should return an error when no payload is returned",async()=>{const e={data:{test:""}};vi.spyOn(r.default,"request").mockResolvedValue(e),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const a=await t.getTransactionDescriptors({deviceModelId:o.DeviceModelId.FLEX,chainId:1,address:"0x0abc",selector:"0x01ff"});expect(a).toEqual((0,i.Left)(new Error("[ContextModule] HttpTransactionDataSource: Response is not an array")))}),it("should return an error when an empty array is returned",async()=>{vi.spyOn(r.default,"request").mockResolvedValue({data:[]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const e=await t.getTransactionDescriptors({deviceModelId:o.DeviceModelId.FLEX,chainId:1,address:"0x0abc",selector:"0x01ff"});expect(e).toEqual((0,i.Left)(new Error("[ContextModule] HttpTransactionDataSource: No data for contract 0x0abc and selector 0x01ff")))}),it("should return an error when selector is not found",async()=>{const e=s(d,f,[l]);vi.spyOn(r.default,"request").mockResolvedValue({data:[e]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const a=await t.getTransactionDescriptors({deviceModelId:o.DeviceModelId.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x01fe"});expect(a).toEqual((0,i.Left)(new Error("[ContextModule] HttpTransactionDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x01fe")))}),it("Calldata with fields references and enums",async()=>{const e=s(d,f,[l,p,m,x]);vi.spyOn(r.default,"request").mockResolvedValue({data:[e]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const a=await t.getTransactionDescriptors({deviceModelId:o.DeviceModelId.FLEX,chainId:1,address:"0x7d2768de32b0b80B7a3454c06bdac94a69ddc7a9",selector:"0x69328dEc"});expect(a.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{payload:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec0401000501010606737461626c6581ff473045022100862e724db664f5d94484928a6a5963268a22cd8178ad36e8c4ff13769ac5c27e0220079da2b6e86810156f6b5955b8190bc016c2fe813d27fcb878a9b99658546582",type:"enum",id:0,value:1},{payload:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04010005010206087661726961626c6581ff473045022100b838ee3d597d6bad2533606cef7335f6c8a45b46d5717803e646777f6c8a6897022074f04b82c3dad8445bb6230ab762010c5fc6ee06198fd3e54752287cbf95c523",type:"enum",id:0,value:2},{payload:l.descriptor,type:"transactionFieldDescription",reference:{type:"token",valuePath:[{type:"ARRAY",start:0,end:5,itemSize:1},{type:"LEAF",leafType:"DYNAMIC_LEAF"}]}},{payload:p.descriptor,type:"transactionFieldDescription",reference:{type:"trustedName",valuePath:"TO",types:["eoa"],sources:["ens","unstoppable_domain"]}},{payload:m.descriptor,type:"transactionFieldDescription",reference:{type:"nft",valuePath:[{type:"REF"},{type:"LEAF",leafType:"ARRAY_LEAF"},{type:"SLICE",start:1}]}},{payload:x.descriptor,type:"transactionFieldDescription",reference:{type:"enum",valuePath:[],id:0}}])}),it("Calldata with fields references and enums with certificates",async()=>{const e=s(d,f,[l,p,m,x]),a={keyUsageNumber:11,payload:new Uint8Array([1,2,3,4,21,4,5,6,7,8])};vi.spyOn(r.default,"request").mockResolvedValue({data:[e]}),vi.spyOn(c,"loadCertificate").mockResolvedValueOnce(a);const n=await t.getTransactionDescriptors({deviceModelId:o.DeviceModelId.FLEX,chainId:1,address:"0x7d2768de32b0b80B7a3454c06bdac94a69ddc7a9",selector:"0x69328dEc"});expect(n.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo",certificate:a},{payload:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec0401000501010606737461626c6581ff473045022100862e724db664f5d94484928a6a5963268a22cd8178ad36e8c4ff13769ac5c27e0220079da2b6e86810156f6b5955b8190bc016c2fe813d27fcb878a9b99658546582",type:"enum",id:0,value:1,certificate:a},{payload:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04010005010206087661726961626c6581ff473045022100b838ee3d597d6bad2533606cef7335f6c8a45b46d5717803e646777f6c8a6897022074f04b82c3dad8445bb6230ab762010c5fc6ee06198fd3e54752287cbf95c523",type:"enum",id:0,value:2,certificate:a},{payload:l.descriptor,type:"transactionFieldDescription",reference:{type:"token",valuePath:[{type:"ARRAY",start:0,end:5,itemSize:1},{type:"LEAF",leafType:"DYNAMIC_LEAF"}]}},{payload:p.descriptor,type:"transactionFieldDescription",reference:{type:"trustedName",valuePath:"TO",types:["eoa"],sources:["ens","unstoppable_domain"]}},{payload:m.descriptor,type:"transactionFieldDescription",reference:{type:"nft",valuePath:[{type:"REF"},{type:"LEAF",leafType:"ARRAY_LEAF"},{type:"SLICE",start:1}]}},{payload:x.descriptor,type:"transactionFieldDescription",reference:{type:"enum",valuePath:[],id:0}}])}),it("Calldata without fields references",async()=>{const e=s(d,[],[b,y,u,v]);vi.spyOn(r.default,"request").mockResolvedValue({data:[e]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const a=await t.getTransactionDescriptors({deviceModelId:o.DeviceModelId.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(a.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{type:"transactionFieldDescription",payload:b.descriptor},{type:"transactionFieldDescription",payload:y.descriptor},{type:"transactionFieldDescription",payload:u.descriptor},{type:"transactionFieldDescription",payload:v.descriptor}])}),it("Calldata on third array element",async()=>{const e=s(d,[],[b,y,u,v]);vi.spyOn(r.default,"request").mockResolvedValue({data:[{},{},e]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const a=await t.getTransactionDescriptors({deviceModelId:o.DeviceModelId.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(a.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{type:"transactionFieldDescription",payload:b.descriptor},{type:"transactionFieldDescription",payload:y.descriptor},{type:"transactionFieldDescription",payload:u.descriptor},{type:"transactionFieldDescription",payload:v.descriptor}])}),it("Calldata without fields references and transaction info signature length % 2 different from 0",async()=>{const e={descriptor:{data:d.descriptor.data,signatures:{test:d.descriptor.signatures.test+"0"}}},a=s(e,[],[b,y,u,v]);vi.spyOn(r.default,"request").mockResolvedValue({data:[a]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const n=await t.getTransactionDescriptors({deviceModelId:o.DeviceModelId.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(n.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff4803045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f0",type:"transactionInfo"},{type:"transactionFieldDescription",payload:b.descriptor},{type:"transactionFieldDescription",payload:y.descriptor},{type:"transactionFieldDescription",payload:u.descriptor},{type:"transactionFieldDescription",payload:v.descriptor}])}),it("Calldata with token fields references as constants",async()=>{const e={name:"Amount to exchange",param:{type:"TOKEN_AMOUNT",token:{raw:"0xae7ab96520de3a18e5e111b5eaab095312d7fe84",type:"constant",value:"0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84",version:1,type_size:20,type_family:"ADDRESS"},value:{type:"path",version:1,abi_path:{type:"data",absolute:!0,elements:[{type:"field",identifier:"_stETHAmount"}]},type_size:32,binary_path:{type:"DATA",version:1,elements:[{type:"TUPLE",offset:0},{type:"LEAF",leaf_type:"STATIC_LEAF"}]},type_family:"UINT"},version:1},version:1,descriptor:"0001010112416d6f756e7420746f2065786368616e6765020102033b0001010115000101010101020120030a00010101020000040103021f0001010101050201140514ae7ab96520de3a18e5e111b5eaab095312d7fe84"},a=s(d,[],[e]);vi.spyOn(r.default,"request").mockResolvedValue({data:[a]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const n=await t.getTransactionDescriptors({deviceModelId:o.DeviceModelId.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(n.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{payload:e.descriptor,type:"transactionFieldDescription",reference:{type:"token",value:"0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84"}}])}),it("Calldata with collection fields references as constants",async()=>{const e={name:"Collection ID",param:{type:"NFT",collection:{raw:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",type:"constant",value:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",version:1,type_size:20,type_family:"ADDRESS"},value:{type:"path",version:1,abi_path:{type:"data",absolute:!0,elements:[{type:"field",identifier:"_collectionId"}]},type_size:20,binary_path:{type:"DATA",version:1,elements:[{type:"ARRAY",weight:2},{type:"LEAF",leaf_type:"TUPLE_LEAF"},{type:"SLICE",end:2}]},type_family:"BYTES"},version:1},version:1,descriptor:"0001010112416d6f756e7420746f2065786368616e6765020102033b0001010115000101010101020120030a00010101020000040103021f00010101010502011405147d2768de32b0b80b7a3454c06bdac94a69ddc7a9"},a=s(d,[],[e]);vi.spyOn(r.default,"request").mockResolvedValue({data:[a]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const n=await t.getTransactionDescriptors({deviceModelId:o.DeviceModelId.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(n.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{payload:e.descriptor,type:"transactionFieldDescription",reference:{type:"nft",value:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9"}}])}),it("should return an error when calldata is not correctly formatted",async()=>{const e={descriptors_calldata:{"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9":{"0x69328dec":{type:"calldat",version:"v1",transaction_info:d,enums:f,fields:[l]}}}};vi.spyOn(r.default,"request").mockResolvedValue({data:[e]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const a=await t.getTransactionDescriptors({deviceModelId:o.DeviceModelId.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(a).toEqual((0,i.Left)(new Error("[ContextModule] HttpTransactionDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when transactionInfo is not correctly formatted",async()=>{const e=s({descriptor:{data:"1234",signatures:{prod:"1234"}}},f,[l]);vi.spyOn(r.default,"request").mockResolvedValue({data:[e]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const a=await t.getTransactionDescriptors({deviceModelId:o.DeviceModelId.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(a).toEqual((0,i.Left)(new Error("[ContextModule] HttpTransactionDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when enum is not correctly formatted",async()=>{const e=s(d,["badEnum"],[l]);vi.spyOn(r.default,"request").mockResolvedValue({data:[e]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const a=await t.getTransactionDescriptors({deviceModelId:o.DeviceModelId.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(a).toEqual((0,i.Left)(new Error("[ContextModule] HttpTransactionDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when enum does not contain a signature",async()=>{const e=s(d,{0:{1:{data:"1234"}}},[l]);vi.spyOn(r.default,"request").mockResolvedValue({data:[e]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const a=await t.getTransactionDescriptors({deviceModelId:o.DeviceModelId.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(a).toEqual((0,i.Left)(new Error("[ContextModule] HttpTransactionDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when enum contain the wrong signature",async()=>{const e=s(d,{0:{1:{data:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04010005010106067374626c65",signatures:{prod:"wrongSignature"}}}},[l]);vi.spyOn(r.default,"request").mockResolvedValue({data:[e]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const a=await t.getTransactionDescriptors({deviceModelId:o.DeviceModelId.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(a).toEqual((0,i.Left)(new Error("[ContextModule] HttpTransactionDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when field is not correctly formatted",async()=>{const e=s(d,[],[{descriptor:3}]);vi.spyOn(r.default,"request").mockResolvedValue({data:[e]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const a=await t.getTransactionDescriptors({deviceModelId:o.DeviceModelId.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(a).toEqual((0,i.Left)(new Error("[ContextModule] HttpTransactionDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when field value is not correctly formatted",async()=>{const a=s(d,[],[{param:{value:{binary_path:"TO",type_family:"UNKNOWN",type_size:20},type:"DATETIME"},descriptor:"000100010c546f20726563697069667"}]);vi.spyOn(r.default,"request").mockResolvedValue({data:[a]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const n=await t.getTransactionDescriptors({deviceModelId:o.DeviceModelId.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(n).toEqual((0,i.Left)(new Error("[ContextModule] HttpTransactionDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when field container path is not correctly formatted",async()=>{const a=s(d,[],[{param:{value:{binary_path:"UNKNOWN",type_family:"ADDRESS",type_size:20},type:"DATETIME"},descriptor:"000100010c546f20726563697069667"}]);vi.spyOn(r.default,"request").mockResolvedValue({data:[a]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const n=await t.getTransactionDescriptors({deviceModelId:o.DeviceModelId.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(n).toEqual((0,i.Left)(new Error("[ContextModule] HttpTransactionDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when field calldata path is not correctly formatted",async()=>{const a=s(d,[],[{param:{value:{binary_path:{elements:[{type:"UNKNOWN"}]},type_family:"ADDRESS",type_size:20},type:"DATETIME"},descriptor:"000100010c546f20726563697069667"}]);vi.spyOn(r.default,"request").mockResolvedValue({data:[a]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const n=await t.getTransactionDescriptors({deviceModelId:o.DeviceModelId.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(n).toEqual((0,i.Left)(new Error("[ContextModule] HttpTransactionDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when field type is not correctly formatted",async()=>{const a=s(d,[],[{param:{value:{binary_path:"TO",type_family:"ADDRESS",type_size:20},type:"UNKNOWN"},descriptor:"000100010c546f20726563697069667"}]);vi.spyOn(r.default,"request").mockResolvedValue({data:[a]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const n=await t.getTransactionDescriptors({deviceModelId:o.DeviceModelId.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(n).toEqual((0,i.Left)(new Error("[ContextModule] HttpTransactionDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))})});
2
2
  //# sourceMappingURL=HttpTransactionDataSource.test.js.map