@ledgerhq/context-module 0.0.0-signer-eth-plugin-fix-20250331141239 → 0.0.0-transactionInspector-resolutionObj-20250916095320

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 (414) hide show
  1. package/README.md +17 -5
  2. package/lib/cjs/package.json +12 -12
  3. package/lib/cjs/src/ContextModule.js +1 -1
  4. package/lib/cjs/src/ContextModule.js.map +1 -1
  5. package/lib/cjs/src/ContextModuleBuilder.js +1 -1
  6. package/lib/cjs/src/ContextModuleBuilder.js.map +3 -3
  7. package/lib/cjs/src/ContextModuleBuilder.test.js +1 -1
  8. package/lib/cjs/src/ContextModuleBuilder.test.js.map +3 -3
  9. package/lib/cjs/src/DefaultContextModule.js +1 -1
  10. package/lib/cjs/src/DefaultContextModule.js.map +3 -3
  11. package/lib/cjs/src/DefaultContextModule.test.js +1 -1
  12. package/lib/cjs/src/DefaultContextModule.test.js.map +2 -2
  13. package/lib/cjs/src/config/di/configModuleFactory.js +1 -1
  14. package/lib/cjs/src/config/di/configModuleFactory.js.map +3 -3
  15. package/lib/cjs/src/config/di/configTypes.js +1 -1
  16. package/lib/cjs/src/config/di/configTypes.js.map +2 -2
  17. package/lib/cjs/src/config/model/ContextModuleBuildArgs.js +2 -0
  18. package/lib/cjs/src/config/model/ContextModuleBuildArgs.js.map +7 -0
  19. package/lib/cjs/src/config/model/ContextModuleConfig.js +1 -1
  20. package/lib/cjs/src/config/model/ContextModuleConfig.js.map +1 -1
  21. package/lib/cjs/src/di.js +1 -1
  22. package/lib/cjs/src/di.js.map +3 -3
  23. package/lib/cjs/src/dynamic-network/data/DynamicNetworkDataSource.js +2 -0
  24. package/lib/cjs/src/dynamic-network/data/DynamicNetworkDataSource.js.map +7 -0
  25. package/lib/cjs/src/dynamic-network/data/HttpDynamicNetworkDataSource.js +2 -0
  26. package/lib/cjs/src/dynamic-network/data/HttpDynamicNetworkDataSource.js.map +7 -0
  27. package/lib/cjs/src/dynamic-network/data/HttpDynamicNetworkDataSource.test.js +2 -0
  28. package/lib/cjs/src/dynamic-network/data/HttpDynamicNetworkDataSource.test.js.map +7 -0
  29. package/lib/cjs/src/dynamic-network/data/dto/DynamicNetworkApiResponseDto.js +2 -0
  30. package/lib/cjs/src/dynamic-network/data/dto/DynamicNetworkApiResponseDto.js.map +7 -0
  31. package/lib/cjs/src/dynamic-network/di/dynamicNetworkModuleFactory.js +2 -0
  32. package/lib/cjs/src/dynamic-network/di/dynamicNetworkModuleFactory.js.map +7 -0
  33. package/lib/cjs/src/dynamic-network/di/dynamicNetworkTypes.js +2 -0
  34. package/lib/cjs/src/dynamic-network/di/dynamicNetworkTypes.js.map +7 -0
  35. package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.js +2 -0
  36. package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.js.map +7 -0
  37. package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js +2 -0
  38. package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js.map +7 -0
  39. package/lib/cjs/src/dynamic-network/model/DynamicNetworkConfiguration.js +2 -0
  40. package/lib/cjs/src/dynamic-network/model/DynamicNetworkConfiguration.js.map +7 -0
  41. package/lib/cjs/src/external-plugin/data/HttpExternalPluginDataSource.js +1 -1
  42. package/lib/cjs/src/external-plugin/data/HttpExternalPluginDataSource.js.map +3 -3
  43. package/lib/cjs/src/external-plugin/data/HttpExternalPluginDataSource.test.js +1 -1
  44. package/lib/cjs/src/external-plugin/data/HttpExternalPluginDataSource.test.js.map +3 -3
  45. package/lib/cjs/src/external-plugin/di/externalPluginModuleFactory.js +1 -1
  46. package/lib/cjs/src/external-plugin/di/externalPluginModuleFactory.js.map +3 -3
  47. package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.js +1 -1
  48. package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.js.map +3 -3
  49. package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.test.js +1 -1
  50. package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.test.js.map +3 -3
  51. package/lib/cjs/src/index.js +1 -1
  52. package/lib/cjs/src/index.js.map +2 -2
  53. package/lib/cjs/src/nft/data/HttpNftDataSource.js +1 -1
  54. package/lib/cjs/src/nft/data/HttpNftDataSource.js.map +3 -3
  55. package/lib/cjs/src/nft/data/HttpNftDataSource.test.js +1 -1
  56. package/lib/cjs/src/nft/data/HttpNftDataSource.test.js.map +3 -3
  57. package/lib/cjs/src/nft/di/nftModuleFactory.js +1 -1
  58. package/lib/cjs/src/nft/di/nftModuleFactory.js.map +3 -3
  59. package/lib/cjs/src/nft/domain/NftContextLoader.js +1 -1
  60. package/lib/cjs/src/nft/domain/NftContextLoader.js.map +3 -3
  61. package/lib/cjs/src/nft/domain/NftContextLoader.test.js +1 -1
  62. package/lib/cjs/src/nft/domain/NftContextLoader.test.js.map +2 -2
  63. package/lib/cjs/src/pki/data/HttpPkiCertificateDataSource.js +1 -1
  64. package/lib/cjs/src/pki/data/HttpPkiCertificateDataSource.js.map +3 -3
  65. package/lib/cjs/src/pki/di/pkiModuleFactory.js +1 -1
  66. package/lib/cjs/src/pki/di/pkiModuleFactory.js.map +3 -3
  67. package/lib/cjs/src/pki/domain/DefaultPkiCertificateLoader.js.map +2 -2
  68. package/lib/cjs/src/pki/domain/DefaultPkiCertificateLoader.test.js +1 -1
  69. package/lib/cjs/src/pki/domain/DefaultPkiCertificateLoader.test.js.map +3 -3
  70. package/lib/cjs/src/shared/constant/HttpHeaders.js +2 -0
  71. package/lib/cjs/src/shared/constant/HttpHeaders.js.map +7 -0
  72. package/lib/cjs/src/shared/model/ClearSignContext.js +1 -1
  73. package/lib/cjs/src/shared/model/ClearSignContext.js.map +2 -2
  74. package/lib/cjs/src/shared/model/SolanaTransactionContext.js +2 -0
  75. package/lib/cjs/src/shared/model/SolanaTransactionContext.js.map +7 -0
  76. package/lib/cjs/src/shared/model/TransactionSubset.js +1 -1
  77. package/lib/cjs/src/shared/model/TransactionSubset.js.map +1 -1
  78. package/lib/cjs/src/solana/data/HttpSolanaOwnerInfoDataSource.js +2 -0
  79. package/lib/cjs/src/solana/data/HttpSolanaOwnerInfoDataSource.js.map +7 -0
  80. package/lib/cjs/src/solana/data/HttpSolanaOwnerInfoDataSource.test.js +2 -0
  81. package/lib/cjs/src/solana/data/HttpSolanaOwnerInfoDataSource.test.js.map +7 -0
  82. package/lib/cjs/src/solana/data/SolanaDataSource.js +2 -0
  83. package/lib/cjs/src/solana/data/SolanaDataSource.js.map +7 -0
  84. package/lib/cjs/src/solana/di/SolanaContextModuleFactory.js +2 -0
  85. package/lib/cjs/src/solana/di/SolanaContextModuleFactory.js.map +7 -0
  86. package/lib/cjs/src/solana/di/solanaContextTypes.js +2 -0
  87. package/lib/cjs/src/solana/di/solanaContextTypes.js.map +7 -0
  88. package/lib/cjs/src/solana/domain/DefaultSolanaContextLoader.js +2 -0
  89. package/lib/cjs/src/solana/domain/DefaultSolanaContextLoader.js.map +7 -0
  90. package/lib/cjs/src/solana/domain/DefaultSolanaContextLoader.test.js +2 -0
  91. package/lib/cjs/src/solana/domain/DefaultSolanaContextLoader.test.js.map +7 -0
  92. package/lib/cjs/src/solana/domain/SolanaContextLoader.js +2 -0
  93. package/lib/cjs/src/solana/domain/SolanaContextLoader.js.map +7 -0
  94. package/lib/cjs/src/solana/domain/solanaContextTypes.js +2 -0
  95. package/lib/cjs/src/solana/domain/solanaContextTypes.js.map +7 -0
  96. package/lib/cjs/src/token/data/HttpTokenDataSource.js +1 -1
  97. package/lib/cjs/src/token/data/HttpTokenDataSource.js.map +3 -3
  98. package/lib/cjs/src/token/data/HttpTokenDataSource.test.js +1 -1
  99. package/lib/cjs/src/token/data/HttpTokenDataSource.test.js.map +3 -3
  100. package/lib/cjs/src/token/di/tokenModuleFactory.js +1 -1
  101. package/lib/cjs/src/token/di/tokenModuleFactory.js.map +3 -3
  102. package/lib/cjs/src/token/domain/TokenContextLoader.js +1 -1
  103. package/lib/cjs/src/token/domain/TokenContextLoader.js.map +3 -3
  104. package/lib/cjs/src/token/domain/TokenContextLoader.test.js +1 -1
  105. package/lib/cjs/src/token/domain/TokenContextLoader.test.js.map +2 -2
  106. package/lib/cjs/src/transaction/data/HttpProxyDataSource.js +2 -0
  107. package/lib/cjs/src/transaction/data/HttpProxyDataSource.js.map +7 -0
  108. package/lib/cjs/src/transaction/data/HttpProxyDataSource.test.js +2 -0
  109. package/lib/cjs/src/transaction/data/HttpProxyDataSource.test.js.map +7 -0
  110. package/lib/cjs/src/transaction/data/HttpTransactionDataSource.js +1 -1
  111. package/lib/cjs/src/transaction/data/HttpTransactionDataSource.js.map +3 -3
  112. package/lib/cjs/src/transaction/data/HttpTransactionDataSource.test.js +1 -1
  113. package/lib/cjs/src/transaction/data/HttpTransactionDataSource.test.js.map +3 -3
  114. package/lib/cjs/src/transaction/data/{CalldataDto.js.map → dto/CalldataDto.js.map} +1 -1
  115. package/lib/cjs/src/transaction/data/dto/ProxyDelegateCallDto.js +2 -0
  116. package/lib/cjs/src/transaction/data/dto/ProxyDelegateCallDto.js.map +7 -0
  117. package/lib/cjs/src/transaction/data/dto/ProxyImplementationAddressDto.js +2 -0
  118. package/lib/cjs/src/transaction/data/dto/ProxyImplementationAddressDto.js.map +7 -0
  119. package/lib/cjs/src/transaction/di/transactionModuleFactory.js +1 -1
  120. package/lib/cjs/src/transaction/di/transactionModuleFactory.js.map +3 -3
  121. package/lib/cjs/src/transaction/di/transactionTypes.js +1 -1
  122. package/lib/cjs/src/transaction/di/transactionTypes.js.map +2 -2
  123. package/lib/cjs/src/transaction/domain/TransactionContextLoader.js +1 -1
  124. package/lib/cjs/src/transaction/domain/TransactionContextLoader.js.map +3 -3
  125. package/lib/cjs/src/transaction/domain/TransactionContextLoader.test.js +1 -1
  126. package/lib/cjs/src/transaction/domain/TransactionContextLoader.test.js.map +3 -3
  127. package/lib/cjs/src/transaction/model/ProxyDelegateCall.js +2 -0
  128. package/lib/cjs/src/transaction/model/ProxyDelegateCall.js.map +7 -0
  129. package/lib/cjs/src/transaction/model/ProxyImplementationAddress.js +2 -0
  130. package/lib/cjs/src/transaction/model/ProxyImplementationAddress.js.map +7 -0
  131. package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.js +1 -1
  132. package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.js.map +3 -3
  133. package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.test.js +1 -1
  134. package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.test.js.map +3 -3
  135. package/lib/cjs/src/trusted-name/di/trustedNameModuleFactory.js +1 -1
  136. package/lib/cjs/src/trusted-name/di/trustedNameModuleFactory.js.map +3 -3
  137. package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.js +1 -1
  138. package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.js.map +3 -3
  139. package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.test.js +1 -1
  140. package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.test.js.map +2 -2
  141. package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.js +1 -1
  142. package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.js.map +3 -3
  143. package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.test.js +1 -1
  144. package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.test.js.map +3 -3
  145. package/lib/cjs/src/typed-data/di/typedDataModuleFactory.js +1 -1
  146. package/lib/cjs/src/typed-data/di/typedDataModuleFactory.js.map +3 -3
  147. package/lib/cjs/src/uniswap/di/uniswapModuleFactory.js +1 -1
  148. package/lib/cjs/src/uniswap/di/uniswapModuleFactory.js.map +3 -3
  149. package/lib/cjs/src/uniswap/domain/UniswapContextLoader.js +1 -1
  150. package/lib/cjs/src/uniswap/domain/UniswapContextLoader.js.map +3 -3
  151. package/lib/cjs/src/uniswap/domain/UniswapContextLoader.test.js +1 -1
  152. package/lib/cjs/src/uniswap/domain/UniswapContextLoader.test.js.map +2 -2
  153. package/lib/cjs/src/web3-check/data/HttpWeb3CheckDataSource.js +1 -1
  154. package/lib/cjs/src/web3-check/data/HttpWeb3CheckDataSource.js.map +3 -3
  155. package/lib/cjs/src/web3-check/data/HttpWeb3CheckDataSource.test.js +1 -1
  156. package/lib/cjs/src/web3-check/data/HttpWeb3CheckDataSource.test.js.map +3 -3
  157. package/lib/cjs/src/web3-check/di/web3CheckModuleFactory.js +1 -1
  158. package/lib/cjs/src/web3-check/di/web3CheckModuleFactory.js.map +3 -3
  159. package/lib/esm/package.json +12 -12
  160. package/lib/esm/src/ContextModuleBuilder.js +1 -1
  161. package/lib/esm/src/ContextModuleBuilder.js.map +3 -3
  162. package/lib/esm/src/ContextModuleBuilder.test.js +1 -1
  163. package/lib/esm/src/ContextModuleBuilder.test.js.map +3 -3
  164. package/lib/esm/src/DefaultContextModule.js +1 -1
  165. package/lib/esm/src/DefaultContextModule.js.map +3 -3
  166. package/lib/esm/src/DefaultContextModule.test.js +1 -1
  167. package/lib/esm/src/DefaultContextModule.test.js.map +2 -2
  168. package/lib/esm/src/config/di/configModuleFactory.js +1 -1
  169. package/lib/esm/src/config/di/configModuleFactory.js.map +3 -3
  170. package/lib/esm/src/config/di/configTypes.js +1 -1
  171. package/lib/esm/src/config/di/configTypes.js.map +2 -2
  172. package/lib/esm/src/config/model/ContextModuleBuildArgs.js +1 -0
  173. package/lib/esm/src/di.js +1 -1
  174. package/lib/esm/src/di.js.map +3 -3
  175. package/lib/esm/src/dynamic-network/data/DynamicNetworkDataSource.js +1 -0
  176. package/lib/esm/src/dynamic-network/data/DynamicNetworkDataSource.js.map +7 -0
  177. package/lib/esm/src/dynamic-network/data/HttpDynamicNetworkDataSource.js +2 -0
  178. package/lib/esm/src/dynamic-network/data/HttpDynamicNetworkDataSource.js.map +7 -0
  179. package/lib/esm/src/dynamic-network/data/HttpDynamicNetworkDataSource.test.js +2 -0
  180. package/lib/esm/src/dynamic-network/data/HttpDynamicNetworkDataSource.test.js.map +7 -0
  181. package/lib/esm/src/dynamic-network/data/dto/DynamicNetworkApiResponseDto.js +1 -0
  182. package/lib/esm/src/dynamic-network/data/dto/DynamicNetworkApiResponseDto.js.map +7 -0
  183. package/lib/esm/src/dynamic-network/di/dynamicNetworkModuleFactory.js +2 -0
  184. package/lib/esm/src/dynamic-network/di/dynamicNetworkModuleFactory.js.map +7 -0
  185. package/lib/esm/src/dynamic-network/di/dynamicNetworkTypes.js +2 -0
  186. package/lib/esm/src/dynamic-network/di/dynamicNetworkTypes.js.map +7 -0
  187. package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.js +2 -0
  188. package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.js.map +7 -0
  189. package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js +2 -0
  190. package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js.map +7 -0
  191. package/lib/esm/src/dynamic-network/model/DynamicNetworkConfiguration.js +1 -0
  192. package/lib/esm/src/dynamic-network/model/DynamicNetworkConfiguration.js.map +7 -0
  193. package/lib/esm/src/external-plugin/data/HttpExternalPluginDataSource.js +1 -1
  194. package/lib/esm/src/external-plugin/data/HttpExternalPluginDataSource.js.map +3 -3
  195. package/lib/esm/src/external-plugin/data/HttpExternalPluginDataSource.test.js +1 -1
  196. package/lib/esm/src/external-plugin/data/HttpExternalPluginDataSource.test.js.map +3 -3
  197. package/lib/esm/src/external-plugin/di/externalPluginModuleFactory.js +1 -1
  198. package/lib/esm/src/external-plugin/di/externalPluginModuleFactory.js.map +3 -3
  199. package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.js +1 -1
  200. package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.js.map +3 -3
  201. package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.test.js +1 -1
  202. package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.test.js.map +3 -3
  203. package/lib/esm/src/index.js +1 -1
  204. package/lib/esm/src/index.js.map +2 -2
  205. package/lib/esm/src/nft/data/HttpNftDataSource.js +1 -1
  206. package/lib/esm/src/nft/data/HttpNftDataSource.js.map +3 -3
  207. package/lib/esm/src/nft/data/HttpNftDataSource.test.js +1 -1
  208. package/lib/esm/src/nft/data/HttpNftDataSource.test.js.map +3 -3
  209. package/lib/esm/src/nft/di/nftModuleFactory.js +1 -1
  210. package/lib/esm/src/nft/di/nftModuleFactory.js.map +3 -3
  211. package/lib/esm/src/nft/domain/NftContextLoader.js +1 -1
  212. package/lib/esm/src/nft/domain/NftContextLoader.js.map +3 -3
  213. package/lib/esm/src/nft/domain/NftContextLoader.test.js +1 -1
  214. package/lib/esm/src/nft/domain/NftContextLoader.test.js.map +2 -2
  215. package/lib/esm/src/pki/data/HttpPkiCertificateDataSource.js +1 -1
  216. package/lib/esm/src/pki/data/HttpPkiCertificateDataSource.js.map +3 -3
  217. package/lib/esm/src/pki/di/pkiModuleFactory.js +1 -1
  218. package/lib/esm/src/pki/di/pkiModuleFactory.js.map +3 -3
  219. package/lib/esm/src/pki/domain/DefaultPkiCertificateLoader.js.map +2 -2
  220. package/lib/esm/src/pki/domain/DefaultPkiCertificateLoader.test.js +1 -1
  221. package/lib/esm/src/pki/domain/DefaultPkiCertificateLoader.test.js.map +3 -3
  222. package/lib/esm/src/shared/constant/HttpHeaders.js +2 -0
  223. package/lib/esm/src/shared/constant/HttpHeaders.js.map +7 -0
  224. package/lib/esm/src/shared/model/ClearSignContext.js +1 -1
  225. package/lib/esm/src/shared/model/ClearSignContext.js.map +2 -2
  226. package/lib/esm/src/shared/model/SolanaTransactionContext.js +1 -0
  227. package/lib/esm/src/shared/model/SolanaTransactionContext.js.map +7 -0
  228. package/lib/esm/src/solana/data/HttpSolanaOwnerInfoDataSource.js +2 -0
  229. package/lib/esm/src/solana/data/HttpSolanaOwnerInfoDataSource.js.map +7 -0
  230. package/lib/esm/src/solana/data/HttpSolanaOwnerInfoDataSource.test.js +2 -0
  231. package/lib/esm/src/solana/data/HttpSolanaOwnerInfoDataSource.test.js.map +7 -0
  232. package/lib/esm/src/solana/data/SolanaDataSource.js +1 -0
  233. package/lib/esm/src/solana/data/SolanaDataSource.js.map +7 -0
  234. package/lib/esm/src/solana/di/SolanaContextModuleFactory.js +2 -0
  235. package/lib/esm/src/solana/di/SolanaContextModuleFactory.js.map +7 -0
  236. package/lib/esm/src/solana/di/solanaContextTypes.js +2 -0
  237. package/lib/esm/src/solana/di/solanaContextTypes.js.map +7 -0
  238. package/lib/esm/src/solana/domain/DefaultSolanaContextLoader.js +2 -0
  239. package/lib/esm/src/solana/domain/DefaultSolanaContextLoader.js.map +7 -0
  240. package/lib/esm/src/solana/domain/DefaultSolanaContextLoader.test.js +2 -0
  241. package/lib/esm/src/solana/domain/DefaultSolanaContextLoader.test.js.map +7 -0
  242. package/lib/esm/src/solana/domain/SolanaContextLoader.js +1 -0
  243. package/lib/esm/src/solana/domain/SolanaContextLoader.js.map +7 -0
  244. package/lib/esm/src/solana/domain/solanaContextTypes.js +1 -0
  245. package/lib/esm/src/solana/domain/solanaContextTypes.js.map +7 -0
  246. package/lib/esm/src/token/data/HttpTokenDataSource.js +1 -1
  247. package/lib/esm/src/token/data/HttpTokenDataSource.js.map +3 -3
  248. package/lib/esm/src/token/data/HttpTokenDataSource.test.js +1 -1
  249. package/lib/esm/src/token/data/HttpTokenDataSource.test.js.map +3 -3
  250. package/lib/esm/src/token/di/tokenModuleFactory.js +1 -1
  251. package/lib/esm/src/token/di/tokenModuleFactory.js.map +3 -3
  252. package/lib/esm/src/token/domain/TokenContextLoader.js +1 -1
  253. package/lib/esm/src/token/domain/TokenContextLoader.js.map +3 -3
  254. package/lib/esm/src/token/domain/TokenContextLoader.test.js +1 -1
  255. package/lib/esm/src/token/domain/TokenContextLoader.test.js.map +2 -2
  256. package/lib/esm/src/transaction/data/HttpProxyDataSource.js +2 -0
  257. package/lib/esm/src/transaction/data/HttpProxyDataSource.js.map +7 -0
  258. package/lib/esm/src/transaction/data/HttpProxyDataSource.test.js +2 -0
  259. package/lib/esm/src/transaction/data/HttpProxyDataSource.test.js.map +7 -0
  260. package/lib/esm/src/transaction/data/HttpTransactionDataSource.js +1 -1
  261. package/lib/esm/src/transaction/data/HttpTransactionDataSource.js.map +3 -3
  262. package/lib/esm/src/transaction/data/HttpTransactionDataSource.test.js +1 -1
  263. package/lib/esm/src/transaction/data/HttpTransactionDataSource.test.js.map +3 -3
  264. package/lib/esm/src/transaction/data/dto/CalldataDto.js.map +7 -0
  265. package/lib/esm/src/transaction/data/dto/ProxyDelegateCallDto.js +1 -0
  266. package/lib/esm/src/transaction/data/dto/ProxyDelegateCallDto.js.map +7 -0
  267. package/lib/esm/src/transaction/data/dto/ProxyImplementationAddressDto.js +1 -0
  268. package/lib/esm/src/transaction/data/dto/ProxyImplementationAddressDto.js.map +7 -0
  269. package/lib/esm/src/transaction/di/transactionModuleFactory.js +1 -1
  270. package/lib/esm/src/transaction/di/transactionModuleFactory.js.map +3 -3
  271. package/lib/esm/src/transaction/di/transactionTypes.js +1 -1
  272. package/lib/esm/src/transaction/di/transactionTypes.js.map +2 -2
  273. package/lib/esm/src/transaction/domain/TransactionContextLoader.js +1 -1
  274. package/lib/esm/src/transaction/domain/TransactionContextLoader.js.map +3 -3
  275. package/lib/esm/src/transaction/domain/TransactionContextLoader.test.js +1 -1
  276. package/lib/esm/src/transaction/domain/TransactionContextLoader.test.js.map +3 -3
  277. package/lib/esm/src/transaction/model/ProxyDelegateCall.js +1 -0
  278. package/lib/esm/src/transaction/model/ProxyDelegateCall.js.map +7 -0
  279. package/lib/esm/src/transaction/model/ProxyImplementationAddress.js +1 -0
  280. package/lib/esm/src/transaction/model/ProxyImplementationAddress.js.map +7 -0
  281. package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.js +1 -1
  282. package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.js.map +3 -3
  283. package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.test.js +1 -1
  284. package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.test.js.map +3 -3
  285. package/lib/esm/src/trusted-name/di/trustedNameModuleFactory.js +1 -1
  286. package/lib/esm/src/trusted-name/di/trustedNameModuleFactory.js.map +3 -3
  287. package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.js +1 -1
  288. package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.js.map +3 -3
  289. package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.test.js +1 -1
  290. package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.test.js.map +2 -2
  291. package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.js +1 -1
  292. package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.js.map +3 -3
  293. package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.test.js +1 -1
  294. package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.test.js.map +3 -3
  295. package/lib/esm/src/typed-data/di/typedDataModuleFactory.js +1 -1
  296. package/lib/esm/src/typed-data/di/typedDataModuleFactory.js.map +3 -3
  297. package/lib/esm/src/uniswap/di/uniswapModuleFactory.js +1 -1
  298. package/lib/esm/src/uniswap/di/uniswapModuleFactory.js.map +3 -3
  299. package/lib/esm/src/uniswap/domain/UniswapContextLoader.js +1 -1
  300. package/lib/esm/src/uniswap/domain/UniswapContextLoader.js.map +3 -3
  301. package/lib/esm/src/uniswap/domain/UniswapContextLoader.test.js +1 -1
  302. package/lib/esm/src/uniswap/domain/UniswapContextLoader.test.js.map +2 -2
  303. package/lib/esm/src/web3-check/data/HttpWeb3CheckDataSource.js +1 -1
  304. package/lib/esm/src/web3-check/data/HttpWeb3CheckDataSource.js.map +3 -3
  305. package/lib/esm/src/web3-check/data/HttpWeb3CheckDataSource.test.js +1 -1
  306. package/lib/esm/src/web3-check/data/HttpWeb3CheckDataSource.test.js.map +3 -3
  307. package/lib/esm/src/web3-check/di/web3CheckModuleFactory.js +1 -1
  308. package/lib/esm/src/web3-check/di/web3CheckModuleFactory.js.map +3 -3
  309. package/lib/types/src/ContextModule.d.ts +3 -0
  310. package/lib/types/src/ContextModule.d.ts.map +1 -1
  311. package/lib/types/src/ContextModuleBuilder.d.ts +22 -4
  312. package/lib/types/src/ContextModuleBuilder.d.ts.map +1 -1
  313. package/lib/types/src/DefaultContextModule.d.ts +5 -0
  314. package/lib/types/src/DefaultContextModule.d.ts.map +1 -1
  315. package/lib/types/src/config/di/configModuleFactory.d.ts.map +1 -1
  316. package/lib/types/src/config/di/configTypes.d.ts +1 -0
  317. package/lib/types/src/config/di/configTypes.d.ts.map +1 -1
  318. package/lib/types/src/config/model/ContextModuleBuildArgs.d.ts +4 -0
  319. package/lib/types/src/config/model/ContextModuleBuildArgs.d.ts.map +1 -0
  320. package/lib/types/src/config/model/ContextModuleConfig.d.ts +7 -0
  321. package/lib/types/src/config/model/ContextModuleConfig.d.ts.map +1 -1
  322. package/lib/types/src/di.d.ts.map +1 -1
  323. package/lib/types/src/dynamic-network/data/DynamicNetworkDataSource.d.ts +6 -0
  324. package/lib/types/src/dynamic-network/data/DynamicNetworkDataSource.d.ts.map +1 -0
  325. package/lib/types/src/dynamic-network/data/HttpDynamicNetworkDataSource.d.ts +13 -0
  326. package/lib/types/src/dynamic-network/data/HttpDynamicNetworkDataSource.d.ts.map +1 -0
  327. package/lib/types/src/dynamic-network/data/HttpDynamicNetworkDataSource.test.d.ts +2 -0
  328. package/lib/types/src/dynamic-network/data/HttpDynamicNetworkDataSource.test.d.ts.map +1 -0
  329. package/lib/types/src/dynamic-network/data/dto/DynamicNetworkApiResponseDto.d.ts +14 -0
  330. package/lib/types/src/dynamic-network/data/dto/DynamicNetworkApiResponseDto.d.ts.map +1 -0
  331. package/lib/types/src/dynamic-network/di/dynamicNetworkModuleFactory.d.ts +3 -0
  332. package/lib/types/src/dynamic-network/di/dynamicNetworkModuleFactory.d.ts.map +1 -0
  333. package/lib/types/src/dynamic-network/di/dynamicNetworkTypes.d.ts +5 -0
  334. package/lib/types/src/dynamic-network/di/dynamicNetworkTypes.d.ts.map +1 -0
  335. package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.d.ts +15 -0
  336. package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.d.ts.map +1 -0
  337. package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.test.d.ts +2 -0
  338. package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.test.d.ts.map +1 -0
  339. package/lib/types/src/dynamic-network/model/DynamicNetworkConfiguration.d.ts +16 -0
  340. package/lib/types/src/dynamic-network/model/DynamicNetworkConfiguration.d.ts.map +1 -0
  341. package/lib/types/src/external-plugin/data/HttpExternalPluginDataSource.d.ts.map +1 -1
  342. package/lib/types/src/external-plugin/domain/ExternalPluginContextLoader.d.ts +1 -1
  343. package/lib/types/src/external-plugin/domain/ExternalPluginContextLoader.d.ts.map +1 -1
  344. package/lib/types/src/index.d.ts +2 -0
  345. package/lib/types/src/index.d.ts.map +1 -1
  346. package/lib/types/src/nft/data/HttpNftDataSource.d.ts +3 -0
  347. package/lib/types/src/nft/data/HttpNftDataSource.d.ts.map +1 -1
  348. package/lib/types/src/nft/domain/NftContextLoader.d.ts +1 -1
  349. package/lib/types/src/nft/domain/NftContextLoader.d.ts.map +1 -1
  350. package/lib/types/src/pki/data/HttpPkiCertificateDataSource.d.ts.map +1 -1
  351. package/lib/types/src/pki/domain/DefaultPkiCertificateLoader.d.ts.map +1 -1
  352. package/lib/types/src/shared/constant/HttpHeaders.d.ts +3 -0
  353. package/lib/types/src/shared/constant/HttpHeaders.d.ts.map +1 -0
  354. package/lib/types/src/shared/model/ClearSignContext.d.ts +3 -0
  355. package/lib/types/src/shared/model/ClearSignContext.d.ts.map +1 -1
  356. package/lib/types/src/shared/model/SolanaTransactionContext.d.ts +11 -0
  357. package/lib/types/src/shared/model/SolanaTransactionContext.d.ts.map +1 -0
  358. package/lib/types/src/shared/model/TransactionSubset.d.ts +3 -3
  359. package/lib/types/src/shared/model/TransactionSubset.d.ts.map +1 -1
  360. package/lib/types/src/solana/data/HttpSolanaOwnerInfoDataSource.d.ts +13 -0
  361. package/lib/types/src/solana/data/HttpSolanaOwnerInfoDataSource.d.ts.map +1 -0
  362. package/lib/types/src/solana/data/HttpSolanaOwnerInfoDataSource.test.d.ts +2 -0
  363. package/lib/types/src/solana/data/HttpSolanaOwnerInfoDataSource.test.d.ts.map +1 -0
  364. package/lib/types/src/solana/data/SolanaDataSource.d.ts +12 -0
  365. package/lib/types/src/solana/data/SolanaDataSource.d.ts.map +1 -0
  366. package/lib/types/src/solana/di/SolanaContextModuleFactory.d.ts +3 -0
  367. package/lib/types/src/solana/di/SolanaContextModuleFactory.d.ts.map +1 -0
  368. package/lib/types/src/solana/di/solanaContextTypes.d.ts +5 -0
  369. package/lib/types/src/solana/di/solanaContextTypes.d.ts.map +1 -0
  370. package/lib/types/src/solana/domain/DefaultSolanaContextLoader.d.ts +11 -0
  371. package/lib/types/src/solana/domain/DefaultSolanaContextLoader.d.ts.map +1 -0
  372. package/lib/types/src/solana/domain/DefaultSolanaContextLoader.test.d.ts +2 -0
  373. package/lib/types/src/solana/domain/DefaultSolanaContextLoader.test.d.ts.map +1 -0
  374. package/lib/types/src/solana/domain/SolanaContextLoader.d.ts +5 -0
  375. package/lib/types/src/solana/domain/SolanaContextLoader.d.ts.map +1 -0
  376. package/lib/types/src/solana/domain/solanaContextTypes.d.ts +27 -0
  377. package/lib/types/src/solana/domain/solanaContextTypes.d.ts.map +1 -0
  378. package/lib/types/src/token/data/HttpTokenDataSource.d.ts.map +1 -1
  379. package/lib/types/src/token/domain/TokenContextLoader.d.ts +1 -1
  380. package/lib/types/src/token/domain/TokenContextLoader.d.ts.map +1 -1
  381. package/lib/types/src/transaction/data/HttpProxyDataSource.d.ts +33 -0
  382. package/lib/types/src/transaction/data/HttpProxyDataSource.d.ts.map +1 -0
  383. package/lib/types/src/transaction/data/HttpProxyDataSource.test.d.ts +2 -0
  384. package/lib/types/src/transaction/data/HttpProxyDataSource.test.d.ts.map +1 -0
  385. package/lib/types/src/transaction/data/HttpTransactionDataSource.d.ts.map +1 -1
  386. package/lib/types/src/transaction/data/dto/CalldataDto.d.ts.map +1 -0
  387. package/lib/types/src/transaction/data/dto/ProxyDelegateCallDto.d.ts +5 -0
  388. package/lib/types/src/transaction/data/dto/ProxyDelegateCallDto.d.ts.map +1 -0
  389. package/lib/types/src/transaction/data/dto/ProxyImplementationAddressDto.d.ts +6 -0
  390. package/lib/types/src/transaction/data/dto/ProxyImplementationAddressDto.d.ts.map +1 -0
  391. package/lib/types/src/transaction/di/transactionModuleFactory.d.ts.map +1 -1
  392. package/lib/types/src/transaction/di/transactionTypes.d.ts +1 -0
  393. package/lib/types/src/transaction/di/transactionTypes.d.ts.map +1 -1
  394. package/lib/types/src/transaction/domain/TransactionContextLoader.d.ts +4 -2
  395. package/lib/types/src/transaction/domain/TransactionContextLoader.d.ts.map +1 -1
  396. package/lib/types/src/transaction/model/ProxyDelegateCall.d.ts +5 -0
  397. package/lib/types/src/transaction/model/ProxyDelegateCall.d.ts.map +1 -0
  398. package/lib/types/src/transaction/model/ProxyImplementationAddress.d.ts +4 -0
  399. package/lib/types/src/transaction/model/ProxyImplementationAddress.d.ts.map +1 -0
  400. package/lib/types/src/trusted-name/data/HttpTrustedNameDataSource.d.ts.map +1 -1
  401. package/lib/types/src/trusted-name/domain/TrustedNameContextLoader.d.ts +1 -1
  402. package/lib/types/src/trusted-name/domain/TrustedNameContextLoader.d.ts.map +1 -1
  403. package/lib/types/src/typed-data/data/HttpTypedDataDataSource.d.ts.map +1 -1
  404. package/lib/types/src/typed-data/data/HttpTypedDataDataSource.test.d.ts.map +1 -1
  405. package/lib/types/src/uniswap/domain/UniswapContextLoader.d.ts +1 -1
  406. package/lib/types/src/uniswap/domain/UniswapContextLoader.d.ts.map +1 -1
  407. package/lib/types/src/web3-check/data/HttpWeb3CheckDataSource.d.ts.map +1 -1
  408. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  409. package/package.json +13 -13
  410. package/lib/types/src/transaction/data/CalldataDto.d.ts.map +0 -1
  411. /package/lib/cjs/src/transaction/data/{CalldataDto.js → dto/CalldataDto.js} +0 -0
  412. /package/lib/esm/src/{transaction/data/CalldataDto.js.map → config/model/ContextModuleBuildArgs.js.map} +0 -0
  413. /package/lib/esm/src/transaction/data/{CalldataDto.js → dto/CalldataDto.js} +0 -0
  414. /package/lib/types/src/transaction/data/{CalldataDto.d.ts → dto/CalldataDto.d.ts} +0 -0
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/external-plugin/domain/ExternalPluginContextLoader.ts"],
4
- "sourcesContent": ["import { HexaString, isHexaString } from \"@ledgerhq/device-management-kit\";\nimport { ethers, Interface } from \"ethers\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, EitherAsync, Left, Right } from \"purify-ts\";\n\nimport type { ExternalPluginDataSource } from \"@/external-plugin/data/ExternalPluginDataSource\";\nimport { externalPluginTypes } from \"@/external-plugin/di/externalPluginTypes\";\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { TransactionContext } from \"@/shared/model/TransactionContext\";\nimport type { TokenDataSource } from \"@/token/data/TokenDataSource\";\nimport { tokenTypes } from \"@/token/di/tokenTypes\";\n\n@injectable()\nexport class ExternalPluginContextLoader implements ContextLoader {\n private _externalPluginDataSource: ExternalPluginDataSource;\n private _tokenDataSource: TokenDataSource;\n\n constructor(\n @inject(externalPluginTypes.ExternalPluginDataSource)\n externalPluginDataSource: ExternalPluginDataSource,\n @inject(tokenTypes.TokenDataSource) tokenDataSource: TokenDataSource,\n ) {\n this._externalPluginDataSource = externalPluginDataSource;\n this._tokenDataSource = tokenDataSource;\n }\n\n async load(transaction: TransactionContext): Promise<ClearSignContext[]> {\n if (!transaction.to || !transaction.data || transaction.data === \"0x\") {\n return [];\n }\n\n const selector = transaction.data.slice(0, 10);\n\n if (!isHexaString(selector)) {\n return [\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Invalid selector\"),\n },\n ];\n }\n\n const eitherDappInfos = await this._externalPluginDataSource.getDappInfos({\n address: transaction.to,\n chainId: transaction.chainId,\n selector,\n });\n\n return EitherAsync<Error, ClearSignContext[]>(async ({ liftEither }) => {\n const dappInfos = await liftEither(eitherDappInfos);\n\n // if the dappInfos is null, return an empty array\n // this means that the selector is not a known selector\n if (!dappInfos) {\n return [];\n }\n\n const externalPluginContext: ClearSignContext = {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: dappInfos.selectorDetails.serializedData.concat(\n dappInfos.selectorDetails.signature,\n ),\n };\n\n const decodedCallData = this.getDecodedCallData(\n dappInfos.abi,\n dappInfos.selectorDetails.method,\n transaction.data!, // trasaction.data is not null and not infered correctly\n );\n\n // if the call data cannot be decoded, return the error\n // but also the externalPluginContext because it is still valid\n if (decodedCallData.isLeft()) {\n return [\n {\n type: ClearSignContextType.ERROR,\n error: decodedCallData.extract(),\n },\n externalPluginContext,\n ];\n }\n\n // decodedCallData is a Right so we can extract it safely\n const extractedDecodedCallData =\n decodedCallData.extract() as ethers.Result;\n\n // get the token payload for each erc20OfInterest\n // and return the payload or the error\n const promises = dappInfos.selectorDetails.erc20OfInterest.map(\n async (erc20Path) =>\n this.getTokenPayload(\n transaction,\n erc20Path,\n extractedDecodedCallData,\n ),\n );\n\n const tokensPayload = await Promise.all(promises);\n\n // map the payload or the error to a ClearSignContext\n const contexts: ClearSignContext[] = tokensPayload.map((eitherToken) =>\n eitherToken.caseOf<ClearSignContext>({\n Left: (error) => ({ type: ClearSignContextType.ERROR, error }),\n Right: (payload) => ({ type: ClearSignContextType.TOKEN, payload }),\n }),\n );\n\n return [...contexts, externalPluginContext];\n }).caseOf<ClearSignContext[]>({\n // parse all errors into ClearSignContext\n Left: (error) => [{ type: ClearSignContextType.ERROR, error }],\n Right: (contexts) => contexts,\n });\n }\n\n private getTokenPayload(\n transaction: TransactionContext,\n erc20Path: string,\n decodedCallData: ethers.Result,\n ) {\n const address = this.getAddressFromPath(erc20Path, decodedCallData);\n\n return EitherAsync<Error, string>(({ fromPromise }) =>\n fromPromise(\n this._tokenDataSource.getTokenInfosPayload({\n address,\n chainId: transaction.chainId,\n }),\n ),\n );\n }\n\n private getDecodedCallData(\n abi: object[],\n method: string,\n data: string,\n ): Either<Error, ethers.Result> {\n try {\n const contractInterface = new Interface(abi);\n return Right(contractInterface.decodeFunctionData(method, data));\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] ExternalPluginContextLoader: Unable to parse abi\",\n ),\n );\n }\n }\n\n private getAddressFromPath(\n path: string,\n decodedCallData: ethers.Result,\n ): HexaString {\n // ethers.Result is a record string, any\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let value: any = decodedCallData;\n for (const key of path.split(\".\")) {\n // In Solidity, a struct cannot begin with a number\n // Additionally, when we use -1, it signifies the last element of the array.\n if (key === \"-1\") {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n value = value[value.length - 1];\n } else {\n // This access can throw a RangeError error in case of an invalid key\n // but is correctly caught by the liftEither above\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n value = value[key];\n }\n }\n\n if (!isHexaString(value)) {\n throw new Error(\n \"[ContextModule] ExternalPluginContextLoader: Unable to get address\",\n );\n }\n\n return value;\n }\n}\n"],
5
- "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAyC,2CACzCC,EAAkC,kBAClCC,EAAmC,qBACnCC,EAAiD,qBAGjDC,EAAoC,oDAEpCC,EAGO,2CAGPC,EAA2B,iCAGpB,IAAMC,EAAN,KAA2D,CACxD,0BACA,iBAER,YAEEC,EACoCC,EACpC,CACA,KAAK,0BAA4BD,EACjC,KAAK,iBAAmBC,CAC1B,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AAqB,MAAO,MAAAA,CAAM,CAAC,EAC7D,MAAQE,GAAaA,CACvB,CAAC,CACH,CAEQ,gBACNb,EACAS,EACAH,EACA,CACA,MAAMQ,EAAU,KAAK,mBAAmBL,EAAWH,CAAe,EAElE,SAAO,eAA2B,CAAC,CAAE,YAAAS,CAAY,IAC/CA,EACE,KAAK,iBAAiB,qBAAqB,CACzC,QAAAD,EACA,QAASd,EAAY,OACvB,CAAC,CACH,CACF,CACF,CAEQ,mBACNgB,EACAC,EACAC,EAC8B,CAC9B,GAAI,CACF,MAAMC,EAAoB,IAAI,YAAUH,CAAG,EAC3C,SAAO,SAAMG,EAAkB,mBAAmBF,EAAQC,CAAI,CAAC,CACjE,MAAiB,CACf,SAAO,QACL,IAAI,MACF,kEACF,CACF,CACF,CACF,CAEQ,mBACNE,EACAd,EACY,CAGZ,IAAIe,EAAaf,EACjB,UAAWgB,KAAOF,EAAK,MAAM,GAAG,EAG1BE,IAAQ,KAEVD,EAAQA,EAAMA,EAAM,OAAS,CAAC,EAK9BA,EAAQA,EAAMC,CAAG,EAIrB,GAAI,IAAC,gBAAaD,CAAK,EACrB,MAAM,IAAI,MACR,oEACF,EAGF,OAAOA,CACT,CACF,EArKaxB,EAAN0B,EAAA,IADN,cAAW,EAMPC,EAAA,eAAO,sBAAoB,wBAAwB,GAEnDA,EAAA,eAAO,aAAW,eAAe,IAPzB3B",
6
- "names": ["ExternalPluginContextLoader_exports", "__export", "ExternalPluginContextLoader", "__toCommonJS", "import_device_management_kit", "import_ethers", "import_inversify", "import_purify_ts", "import_externalPluginTypes", "import_ClearSignContext", "import_tokenTypes", "ExternalPluginContextLoader", "externalPluginDataSource", "tokenDataSource", "transaction", "selector", "eitherDappInfos", "liftEither", "dappInfos", "externalPluginContext", "decodedCallData", "extractedDecodedCallData", "promises", "erc20Path", "eitherToken", "error", "payload", "contexts", "address", "fromPromise", "abi", "method", "data", "contractInterface", "path", "value", "key", "__decorateClass", "__decorateParam"]
4
+ "sourcesContent": ["import { HexaString, isHexaString } from \"@ledgerhq/device-management-kit\";\nimport { ethers, Interface } from \"ethers\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, EitherAsync, Left, Right } from \"purify-ts\";\n\nimport type { ExternalPluginDataSource } from \"@/external-plugin/data/ExternalPluginDataSource\";\nimport { externalPluginTypes } from \"@/external-plugin/di/externalPluginTypes\";\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { TransactionContext } from \"@/shared/model/TransactionContext\";\nimport type { TokenDataSource } from \"@/token/data/TokenDataSource\";\nimport { tokenTypes } from \"@/token/di/tokenTypes\";\n\n@injectable()\nexport class ExternalPluginContextLoader implements ContextLoader {\n private _externalPluginDataSource: ExternalPluginDataSource;\n private _tokenDataSource: TokenDataSource;\n\n constructor(\n @inject(externalPluginTypes.ExternalPluginDataSource)\n externalPluginDataSource: ExternalPluginDataSource,\n @inject(tokenTypes.TokenDataSource) tokenDataSource: TokenDataSource,\n ) {\n this._externalPluginDataSource = externalPluginDataSource;\n this._tokenDataSource = tokenDataSource;\n }\n\n async load(ctx: TransactionContext): Promise<ClearSignContext[]> {\n const { to, data, selector, chainId } = ctx;\n if (to === undefined || data === \"0x\") {\n return [];\n }\n\n if (!isHexaString(selector)) {\n return [\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Invalid selector\"),\n },\n ];\n }\n\n const eitherDappInfos = await this._externalPluginDataSource.getDappInfos({\n address: to,\n chainId,\n selector,\n });\n\n return EitherAsync<Error, ClearSignContext[]>(async ({ liftEither }) => {\n const dappInfos = await liftEither(eitherDappInfos);\n\n // if the dappInfos is null, return an empty array\n // this means that the selector is not a known selector\n if (!dappInfos) {\n return [];\n }\n\n const externalPluginContext: ClearSignContext = {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: dappInfos.selectorDetails.serializedData.concat(\n dappInfos.selectorDetails.signature,\n ),\n };\n\n const decodedCallData = this.getDecodedCallData(\n dappInfos.abi,\n dappInfos.selectorDetails.method,\n data,\n );\n\n // if the call data cannot be decoded, return the error\n // but also the externalPluginContext because it is still valid\n if (decodedCallData.isLeft()) {\n return [\n {\n type: ClearSignContextType.ERROR,\n error: decodedCallData.extract(),\n },\n externalPluginContext,\n ];\n }\n\n // decodedCallData is a Right so we can extract it safely\n const extractedDecodedCallData =\n decodedCallData.extract() as ethers.Result;\n\n // get the token payload for each erc20OfInterest\n // and return the payload or the error\n const promises = dappInfos.selectorDetails.erc20OfInterest.map(\n async (erc20Path) =>\n this.getTokenPayload(ctx, erc20Path, extractedDecodedCallData),\n );\n\n const tokensPayload = await Promise.all(promises);\n\n // map the payload or the error to a ClearSignContext\n const contexts: ClearSignContext[] = tokensPayload.map((eitherToken) =>\n eitherToken.caseOf<ClearSignContext>({\n Left: (error) => ({ type: ClearSignContextType.ERROR, error }),\n Right: (payload) => ({ type: ClearSignContextType.TOKEN, payload }),\n }),\n );\n\n return [...contexts, externalPluginContext];\n }).caseOf<ClearSignContext[]>({\n // parse all errors into ClearSignContext\n Left: (error) => [{ type: ClearSignContextType.ERROR, error }],\n Right: (contexts) => contexts,\n });\n }\n\n private getTokenPayload(\n ctx: TransactionContext,\n erc20Path: string,\n decodedCallData: ethers.Result,\n ) {\n const address = this.getAddressFromPath(erc20Path, decodedCallData);\n\n return EitherAsync<Error, string>(({ fromPromise }) =>\n fromPromise(\n this._tokenDataSource.getTokenInfosPayload({\n address,\n chainId: ctx.chainId,\n }),\n ),\n );\n }\n\n private getDecodedCallData(\n abi: object[],\n method: string,\n data: string,\n ): Either<Error, ethers.Result> {\n try {\n const contractInterface = new Interface(abi);\n return Right(contractInterface.decodeFunctionData(method, data));\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] ExternalPluginContextLoader: Unable to parse abi\",\n ),\n );\n }\n }\n\n private getAddressFromPath(\n path: string,\n decodedCallData: ethers.Result,\n ): HexaString {\n // ethers.Result is a record string, any\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let value: any = decodedCallData;\n for (const key of path.split(\".\")) {\n // In Solidity, a struct cannot begin with a number\n // Additionally, when we use -1, it signifies the last element of the array.\n if (key === \"-1\") {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n value = value[value.length - 1];\n } else {\n // This access can throw a RangeError error in case of an invalid key\n // but is correctly caught by the liftEither above\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n value = value[key];\n }\n }\n\n if (!isHexaString(value)) {\n throw new Error(\n \"[ContextModule] ExternalPluginContextLoader: Unable to get address\",\n );\n }\n\n return value;\n }\n}\n"],
5
+ "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAyC,2CACzCC,EAAkC,kBAClCC,EAAmC,qBACnCC,EAAiD,qBAGjDC,EAAoC,oDAEpCC,EAGO,2CAGPC,EAA2B,iCAGpB,IAAMC,EAAN,KAA2D,CACxD,0BACA,iBAER,YAEEC,EACoCC,EACpC,CACA,KAAK,0BAA4BD,EACjC,KAAK,iBAAmBC,CAC1B,CAEA,MAAM,KAAKC,EAAsD,CAC/D,KAAM,CAAE,GAAAC,EAAI,KAAAC,EAAM,SAAAC,EAAU,QAAAC,CAAQ,EAAIJ,EACxC,GAAIC,IAAO,QAAaC,IAAS,KAC/B,MAAO,CAAC,EAGV,GAAI,IAAC,gBAAaC,CAAQ,EACxB,MAAO,CACL,CACE,KAAM,uBAAqB,MAC3B,MAAO,IAAI,MAAM,kBAAkB,CACrC,CACF,EAGF,MAAME,EAAkB,MAAM,KAAK,0BAA0B,aAAa,CACxE,QAASJ,EACT,QAAAG,EACA,SAAAD,CACF,CAAC,EAED,SAAO,eAAuC,MAAO,CAAE,WAAAG,CAAW,IAAM,CACtE,MAAMC,EAAY,MAAMD,EAAWD,CAAe,EAIlD,GAAI,CAACE,EACH,MAA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EQ,mBACNoB,EACAb,EACY,CAGZ,IAAIc,EAAad,EACjB,UAAWe,KAAOF,EAAK,MAAM,GAAG,EAG1BE,IAAQ,KAEVD,EAAQA,EAAMA,EAAM,OAAS,CAAC,EAK9BA,EAAQA,EAAMC,CAAG,EAIrB,GAAI,IAAC,gBAAaD,CAAK,EACrB,MAAM,IAAI,MACR,oEACF,EAGF,OAAOA,CACT,CACF,EAhKa1B,EAAN4B,EAAA,IADN,cAAW,EAMPC,EAAA,eAAO,sBAAoB,wBAAwB,GAEnDA,EAAA,eAAO,aAAW,eAAe,IAPzB7B",
6
+ "names": ["ExternalPluginContextLoader_exports", "__export", "ExternalPluginContextLoader", "__toCommonJS", "import_device_management_kit", "import_ethers", "import_inversify", "import_purify_ts", "import_externalPluginTypes", "import_ClearSignContext", "import_tokenTypes", "ExternalPluginContextLoader", "externalPluginDataSource", "tokenDataSource", "ctx", "to", "data", "selector", "chainId", "eitherDappInfos", "liftEither", "dappInfos", "externalPluginContext", "decodedCallData", "extractedDecodedCallData", "promises", "erc20Path", "eitherToken", "error", "payload", "contexts", "address", "fromPromise", "abi", "method", "contractInterface", "path", "value", "key", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var y=Object.create;var i=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var b=(s,o,r,a)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of f(o))!D.call(s,e)&&e!==r&&i(s,e,{get:()=>o[e],enumerable:!(a=E(o,e))||a.enumerable});return s};var I=(s,o,r)=>(r=s!=null?y(x(s)):{},b(o||!s||!s.__esModule?i(r,"default",{value:s,enumerable:!0}):r,s));var u=require("ethers"),l=require("purify-ts"),n=I(require("@/external-plugin/__tests__/abi.json")),m=require("../../external-plugin/domain/ExternalPluginContextLoader"),t=require("../../shared/model/ClearSignContext");const d=({abi:s,selectorDetails:o})=>({abi:s,selectorDetails:{erc20OfInterest:[],method:"",plugin:"",serializedData:"123456",signature:"7890",...o}}),p=(s,o,r)=>({to:"0x0",data:new u.Interface(JSON.stringify(s)).encodeFunctionData(o,r)});describe("ExternalPluginContextLoader",()=>{const s={getTokenInfosPayload:vi.fn()},o={getDappInfos:vi.fn()},r=new m.ExternalPluginContextLoader(o,s);beforeEach(()=>{vi.clearAllMocks(),vi.spyOn(s,"getTokenInfosPayload").mockImplementation(({address:a})=>Promise.resolve((0,l.Right)(`payload-${a}`)))}),describe("load function",async()=>{it("should return an empty array if no destination address is provided",async()=>{const a={},e=()=>r.load(a);await expect(e()).resolves.toEqual([])}),it("should return an empty array if data is undefined",async()=>{const a={to:"0x0"},e=await r.load(a);expect(e).toEqual([])}),it("should return an empty array if no data provided",async()=>{const a={to:"0x0",data:"0x"},e=await r.load(a);expect(e).toEqual([])}),it("should return an empty array if no dapp info is povided",async()=>{const a=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(void 0));const e=await r.load(a);expect(e).toEqual([])}),it("should return e plugin if no erc20OfInterest is provided",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:[],method:"singleParam"}}),e=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return a list of context responses when one erc20OfInterest is provided for a single parameter",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),e=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual(expect.arrayContaining([{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"}]))}),it("should return a context response with only set external plugin when one erc20OfInterest is provided for a single parameter but no payload is feched",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),e=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a)),vi.spyOn(s,"getTokenInfosPayload").mockResolvedValue((0,l.Left)(Error("error")));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.ERROR,error:new Error("error")},{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return a list of context responses when two erc20OfInterest are provided for two parameters",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["fromToken","toToken"],method:"multipleParams"}}),e=p(n.default,"multipleParams",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual(expect.arrayContaining([{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"}]))}),it("should return a list of context responses when one erc20OfInterest is an array",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["fromToken.0","fromToken.1","fromToken.2","fromToken.-1"],method:"arrayParam"}}),e=p(n.default,"arrayParam",[["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7","0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return an error when a token datasource returns an error",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),e=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a)),vi.spyOn(s,"getTokenInfosPayload").mockResolvedValue((0,l.Left)(new Error("error")));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.ERROR,error:new Error("error")},{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return an error when the abi is not conform",async()=>{const a=d({abi:[{fakeabi:"notworking"}],selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),e=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.ERROR,error:new Error("[ContextModule] ExternalPluginContextLoader: Unable to parse abi")},{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should throw an error when the erc20OfInterest doest not exist in the transaction",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["notFound"],method:"singleParam"}}),e=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.ERROR,error:new Error("[ContextModule] ExternalPluginContextLoader: Unable to get address")}])}),it("should throw an error when an out-of-bounds element is present in erc20OfInterest",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["fromToken.3"],method:"arrayParam"}}),e=p(n.default,"arrayParam",[["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7","0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.ERROR,error:new RangeError("out of result range")}])}),it("should return a list of context responses when one erc20OfInterest is a complex struct",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["complexStruct.address1","complexStruct.param1.param2.0.param3.addresses.0","complexStruct.param1.param2.0.param3.addresses.1","complexStruct.param1.param2.0.param3.addresses.-1","complexStruct.param1.param2.1.param3.addresses.0","complexStruct.param1.param2.-1.param3.addresses.0"],method:"complexStructParam"}}),e=p(n.default,"complexStructParam",[{address1:"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",param1:{param2:[{param3:{addresses:["0xdAC17F958D2ee523a2206206994597C13D831ec7","0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"]}},{param3:{addresses:["0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]}}]}}]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return an error when datasource return a Left",async()=>{const a=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Left)(new Error("error")));const e=await r.load(a);expect(e).toEqual([{type:t.ClearSignContextType.ERROR,error:new Error("error")}])}),it("should return an error when transaction data is not a valid hex string",async()=>{const a={to:"0x0",data:"notAHexString"},e=await r.load(a);expect(e).toEqual([{type:t.ClearSignContextType.ERROR,error:new Error("Invalid selector")}])})})});
1
+ "use strict";var y=Object.create;var i=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var b=(s,o,r,a)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of f(o))!D.call(s,e)&&e!==r&&i(s,e,{get:()=>o[e],enumerable:!(a=E(o,e))||a.enumerable});return s};var I=(s,o,r)=>(r=s!=null?y(x(s)):{},b(o||!s||!s.__esModule?i(r,"default",{value:s,enumerable:!0}):r,s));var m=require("ethers"),l=require("purify-ts"),n=I(require("@/external-plugin/__tests__/abi.json")),u=require("../../external-plugin/domain/ExternalPluginContextLoader"),t=require("../../shared/model/ClearSignContext");const d=({abi:s,selectorDetails:o})=>({abi:s,selectorDetails:{erc20OfInterest:[],method:"",plugin:"",serializedData:"123456",signature:"7890",...o}}),p=(s,o,r)=>{const e=new m.Interface(JSON.stringify(s)).encodeFunctionData(o,r);return{to:"0x0",data:e,selector:e.slice(0,10)}};describe("ExternalPluginContextLoader",()=>{const s={getTokenInfosPayload:vi.fn()},o={getDappInfos:vi.fn()},r=new u.ExternalPluginContextLoader(o,s);beforeEach(()=>{vi.clearAllMocks(),vi.spyOn(s,"getTokenInfosPayload").mockImplementation(({address:a})=>Promise.resolve((0,l.Right)(`payload-${a}`)))}),describe("load function",()=>{it("should return an empty array if no destination address is provided",async()=>{const a={},e=()=>r.load(a);await expect(e()).resolves.toEqual([])}),it("should return an empty array if no data provided",async()=>{const a={to:"0x0",data:"0x",selector:"0x0"},e=await r.load(a);expect(e).toEqual([])}),it("should return an empty array if no dapp info is povided",async()=>{const a=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(void 0));const e=await r.load(a);expect(e).toEqual([])}),it("should return e plugin if no erc20OfInterest is provided",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:[],method:"singleParam"}}),e=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return a list of context responses when one erc20OfInterest is provided for a single parameter",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),e=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual(expect.arrayContaining([{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"}]))}),it("should return a context response with only set external plugin when one erc20OfInterest is provided for a single parameter but no payload is feched",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),e=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a)),vi.spyOn(s,"getTokenInfosPayload").mockResolvedValue((0,l.Left)(Error("error")));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.ERROR,error:new Error("error")},{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return a list of context responses when two erc20OfInterest are provided for two parameters",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["fromToken","toToken"],method:"multipleParams"}}),e=p(n.default,"multipleParams",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual(expect.arrayContaining([{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"}]))}),it("should return a list of context responses when one erc20OfInterest is an array",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["fromToken.0","fromToken.1","fromToken.2","fromToken.-1"],method:"arrayParam"}}),e=p(n.default,"arrayParam",[["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7","0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return an error when a token datasource returns an error",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),e=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a)),vi.spyOn(s,"getTokenInfosPayload").mockResolvedValue((0,l.Left)(new Error("error")));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.ERROR,error:new Error("error")},{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return an error when the abi is not conform",async()=>{const a=d({abi:[{fakeabi:"notworking"}],selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),e=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.ERROR,error:new Error("[ContextModule] ExternalPluginContextLoader: Unable to parse abi")},{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should throw an error when the erc20OfInterest doest not exist in the transaction",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["notFound"],method:"singleParam"}}),e=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.ERROR,error:new Error("[ContextModule] ExternalPluginContextLoader: Unable to get address")}])}),it("should throw an error when an out-of-bounds element is present in erc20OfInterest",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["fromToken.3"],method:"arrayParam"}}),e=p(n.default,"arrayParam",[["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7","0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.ERROR,error:new RangeError("out of result range")}])}),it("should return a list of context responses when one erc20OfInterest is a complex struct",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["complexStruct.address1","complexStruct.param1.param2.0.param3.addresses.0","complexStruct.param1.param2.0.param3.addresses.1","complexStruct.param1.param2.0.param3.addresses.-1","complexStruct.param1.param2.1.param3.addresses.0","complexStruct.param1.param2.-1.param3.addresses.0"],method:"complexStructParam"}}),e=p(n.default,"complexStructParam",[{address1:"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",param1:{param2:[{param3:{addresses:["0xdAC17F958D2ee523a2206206994597C13D831ec7","0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"]}},{param3:{addresses:["0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]}}]}}]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return an error when datasource return a Left",async()=>{const a=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Left)(new Error("error")));const e=await r.load(a);expect(e).toEqual([{type:t.ClearSignContextType.ERROR,error:new Error("error")}])}),it("should return an error when transaction data is not a valid hex string",async()=>{const a={to:"0x0",data:"notAHexString"},e=await r.load(a);expect(e).toEqual([{type:t.ClearSignContextType.ERROR,error:new Error("Invalid selector")}])})})});
2
2
  //# sourceMappingURL=ExternalPluginContextLoader.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/external-plugin/domain/ExternalPluginContextLoader.test.ts"],
4
- "sourcesContent": ["import { Interface } from \"ethers\";\nimport { Left, Right } from \"purify-ts\";\n\nimport ABI from \"@/external-plugin/__tests__/abi.json\";\nimport { type ExternalPluginDataSource } from \"@/external-plugin/data/ExternalPluginDataSource\";\nimport { ExternalPluginContextLoader } from \"@/external-plugin/domain/ExternalPluginContextLoader\";\nimport { type DappInfos } from \"@/external-plugin/model/DappInfos\";\nimport { type SelectorDetails } from \"@/external-plugin/model/SelectorDetails\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport { type TransactionContext } from \"@/shared/model/TransactionContext\";\nimport { type TokenDataSource } from \"@/token/data/TokenDataSource\";\n\nconst dappInfosBuilder = ({\n abi,\n selectorDetails,\n}: {\n abi?: object[];\n selectorDetails?: Partial<SelectorDetails>;\n}) => {\n return {\n abi: abi,\n selectorDetails: {\n erc20OfInterest: [],\n method: \"\",\n plugin: \"\",\n serializedData: \"123456\",\n signature: \"7890\",\n ...selectorDetails,\n },\n } as DappInfos;\n};\n\nconst transactionBuilder = (\n abi: object,\n functionName: string,\n params: unknown[],\n): TransactionContext => {\n const contract = new Interface(JSON.stringify(abi));\n const data = contract.encodeFunctionData(functionName, params);\n return {\n to: \"0x0\",\n data,\n } as TransactionContext;\n};\n\ndescribe(\"ExternalPluginContextLoader\", () => {\n const mockTokenDataSource: TokenDataSource = {\n getTokenInfosPayload: vi.fn(),\n };\n const mockExternalPluginDataSource: ExternalPluginDataSource = {\n getDappInfos: vi.fn(),\n };\n const loader = new ExternalPluginContextLoader(\n mockExternalPluginDataSource,\n mockTokenDataSource,\n );\n\n beforeEach(() => {\n vi.clearAllMocks();\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockImplementation(\n ({ address }) => Promise.resolve(Right(`payload-${address}`)),\n );\n });\n\n describe(\"load function\", async () => {\n it(\"should return an empty array if no destination address is provided\", async () => {\n // GIVEN\n const transaction = {} as TransactionContext;\n\n // WHEN\n const promise = () => loader.load(transaction);\n\n // THEN\n await expect(promise()).resolves.toEqual([]);\n });\n\n it(\"should return an empty array if data is undefined\", async () => {\n // GIVEN\n const transaction = { to: \"0x0\" } 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 no data provided\", async () => {\n // GIVEN\n const transaction = { to: \"0x0\", data: \"0x\" } 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 no dapp info is povided\", async () => {\n // GIVEN\n const transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(undefined),\n );\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return e plugin if no erc20OfInterest is provided\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [],\n method: \"singleParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return a list of context responses when one erc20OfInterest is provided for a single parameter\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken\"],\n method: \"singleParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual(\n expect.arrayContaining([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n },\n ]),\n );\n });\n\n it(\"should return a context response with only set external plugin when one erc20OfInterest is provided for a single parameter but no payload is feched\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken\"],\n method: \"singleParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(Error(\"error\")),\n );\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(\"error\"),\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return a list of context responses when two erc20OfInterest are provided for two parameters\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken\", \"toToken\"],\n method: \"multipleParams\",\n },\n });\n const transaction = transactionBuilder(ABI, \"multipleParams\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual(\n expect.arrayContaining([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n },\n ]),\n );\n });\n\n it(\"should return a list of context responses when one erc20OfInterest is an array\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\n \"fromToken.0\",\n \"fromToken.1\",\n \"fromToken.2\",\n \"fromToken.-1\",\n ],\n method: \"arrayParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"arrayParam\", [\n [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n \"0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n ],\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\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-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n },\n // fromToken.2\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n // fromToken.-1\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return an error when a token datasource returns an error\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken\"],\n method: \"singleParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\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 {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return an error when the abi is not conform\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: [{ fakeabi: \"notworking\" }],\n selectorDetails: {\n erc20OfInterest: [\"fromToken\"],\n method: \"singleParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\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(\n \"[ContextModule] ExternalPluginContextLoader: Unable to parse abi\",\n ),\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should throw an error when the erc20OfInterest doest not exist in the transaction\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"notFound\"],\n method: \"singleParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\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(\n \"[ContextModule] ExternalPluginContextLoader: Unable to get address\",\n ),\n },\n ]);\n });\n\n it(\"should throw an error when an out-of-bounds element is present in erc20OfInterest\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken.3\"],\n method: \"arrayParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"arrayParam\", [\n [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n \"0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n ],\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\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 RangeError(\"out of result range\"),\n },\n ]);\n });\n\n it(\"should return a list of context responses when one erc20OfInterest is a complex struct\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\n \"complexStruct.address1\",\n \"complexStruct.param1.param2.0.param3.addresses.0\",\n \"complexStruct.param1.param2.0.param3.addresses.1\",\n \"complexStruct.param1.param2.0.param3.addresses.-1\",\n \"complexStruct.param1.param2.1.param3.addresses.0\",\n \"complexStruct.param1.param2.-1.param3.addresses.0\",\n ],\n method: \"complexStructParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"complexStructParam\", [\n {\n address1: \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n param1: {\n param2: [\n {\n param3: {\n addresses: [\n \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n \"0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE\",\n ],\n },\n },\n {\n param3: {\n addresses: [\"0xB8c77482e45F1F44dE1745F52C74426C631bDD52\"],\n },\n },\n ],\n },\n },\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\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-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return an error when datasource return a Left\", async () => {\n // GIVEN\n const transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").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 {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n ]);\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: \"0x0\",\n data: \"notAHexString\",\n } 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});\n"],
5
- "mappings": "wdAAA,IAAAA,EAA0B,kBAC1BC,EAA4B,qBAE5BC,EAAgB,mDAEhBC,EAA4C,gEAG5CC,EAAqC,2CAIrC,MAAMC,EAAmB,CAAC,CACxB,IAAAC,EACA,gBAAAC,CACF,KAIS,CACL,IAAKD,EACL,gBAAiB,CACf,gBAAiB,CAAC,EAClB,OAAQ,GACR,OAAQ,GACR,eAAgB,SAChB,UAAW,OACX,GAAGC,CACL,CACF,GAGIC,EAAqB,CACzBF,EACAG,EACAC,KAIO,CACL,GAAI,MACJ,KAJe,IAAI,YAAU,KAAK,UAAUJ,CAAG,CAAC,EAC5B,mBAAmBG,EAAcC,CAAM,CAI7D,GAGF,SAAS,8BAA+B,IAAM,CAC5C,MAAMC,EAAuC,CAC3C,qBAAsB,GAAG,GAAG,CAC9B,EACMC,EAAyD,CAC7D,aAAc,GAAG,GAAG,CACtB,EACMC,EAAS,IAAI,8BACjBD,EACAD,CACF,EAEA,WAAW,IAAM,CACf,GAAG,cAAc,EACjB,GAAG,MAAMA,EAAqB,sBAAsB,EAAE,mBACpD,CAAC,CAAE,QAAAG,CAAQ,IAAM,QAAQ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C3B,QAAS,YACX,CACF,CAAC,CACH,CAAC,EAED,GAAG,uDAAwD,SAAY,CAErE,MAAMF,EAAcP,EAAmB,EAAAU,QAAK,cAAe,CACzD,4CACF,CAAC,EACD,GAAG,MAAMN,EAA8B,cAAc,EAAE,qBACrD,QAAK,IAAI,MAAM,OAAO,CAAC,CACzB,EAGA,MAAMK,EAAS,MAAMJ,EAAO,KAAKE,CAAW,EAG5C,OAAOE,CAAM,EAAE,QAAQ,CACrB,CACE,KAAM,uBAAqB,MAC3B,MAAO,IAAI,MAAM,OAAO,CAC1B,CACF,CAAC,CACH,CAAC,EAED,GAAG,yEAA0E,SAAY,CAEvF,MAAMF,EAAc,CAClB,GAAI,MACJ,KAAM,eACR,EAGME,EAAS,MAAMJ,EAAO,KAAKE,CAAW,EAG5C,OAAOE,CAAM,EAAE,QAAQ,CACrB,CACE,KAAM,uBAAqB,MAC3B,MAAO,IAAI,MAAM,kBAAkB,CACrC,CACF,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["import_ethers", "import_purify_ts", "import_abi", "import_ExternalPluginContextLoader", "import_ClearSignContext", "dappInfosBuilder", "abi", "selectorDetails", "transactionBuilder", "functionName", "params", "mockTokenDataSource", "mockExternalPluginDataSource", "loader", "address", "transaction", "promise", "result", "ABI", "dappInfos"]
4
+ "sourcesContent": ["import { Interface } from \"ethers\";\nimport { Left, Right } from \"purify-ts\";\n\nimport ABI from \"@/external-plugin/__tests__/abi.json\";\nimport { type ExternalPluginDataSource } from \"@/external-plugin/data/ExternalPluginDataSource\";\nimport { ExternalPluginContextLoader } from \"@/external-plugin/domain/ExternalPluginContextLoader\";\nimport { type DappInfos } from \"@/external-plugin/model/DappInfos\";\nimport { type SelectorDetails } from \"@/external-plugin/model/SelectorDetails\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport { type TransactionContext } from \"@/shared/model/TransactionContext\";\nimport { type TokenDataSource } from \"@/token/data/TokenDataSource\";\n\nconst dappInfosBuilder = ({\n abi,\n selectorDetails,\n}: {\n abi?: object[];\n selectorDetails?: Partial<SelectorDetails>;\n}) => {\n return {\n abi: abi,\n selectorDetails: {\n erc20OfInterest: [],\n method: \"\",\n plugin: \"\",\n serializedData: \"123456\",\n signature: \"7890\",\n ...selectorDetails,\n },\n } as DappInfos;\n};\n\nconst transactionBuilder = (\n abi: object,\n functionName: string,\n params: unknown[],\n): TransactionContext => {\n const contract = new Interface(JSON.stringify(abi));\n const data = contract.encodeFunctionData(functionName, params);\n return {\n to: \"0x0\",\n data,\n selector: data.slice(0, 10),\n } as TransactionContext;\n};\n\ndescribe(\"ExternalPluginContextLoader\", () => {\n const mockTokenDataSource: TokenDataSource = {\n getTokenInfosPayload: vi.fn(),\n };\n const mockExternalPluginDataSource: ExternalPluginDataSource = {\n getDappInfos: vi.fn(),\n };\n const loader = new ExternalPluginContextLoader(\n mockExternalPluginDataSource,\n mockTokenDataSource,\n );\n\n beforeEach(() => {\n vi.clearAllMocks();\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 no destination address is provided\", async () => {\n // GIVEN\n const transaction = {} as TransactionContext;\n\n // WHEN\n const promise = () => loader.load(transaction);\n\n // THEN\n await expect(promise()).resolves.toEqual([]);\n });\n\n it(\"should return an empty array if no data provided\", async () => {\n // GIVEN\n const transaction = {\n to: \"0x0\",\n data: \"0x\",\n selector: \"0x0\",\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 no dapp info is povided\", async () => {\n // GIVEN\n const transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(undefined),\n );\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return e plugin if no erc20OfInterest is provided\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [],\n method: \"singleParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return a list of context responses when one erc20OfInterest is provided for a single parameter\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken\"],\n method: \"singleParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual(\n expect.arrayContaining([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n },\n ]),\n );\n });\n\n it(\"should return a context response with only set external plugin when one erc20OfInterest is provided for a single parameter but no payload is feched\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken\"],\n method: \"singleParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(Error(\"error\")),\n );\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(\"error\"),\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return a list of context responses when two erc20OfInterest are provided for two parameters\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken\", \"toToken\"],\n method: \"multipleParams\",\n },\n });\n const transaction = transactionBuilder(ABI, \"multipleParams\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual(\n expect.arrayContaining([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n },\n ]),\n );\n });\n\n it(\"should return a list of context responses when one erc20OfInterest is an array\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\n \"fromToken.0\",\n \"fromToken.1\",\n \"fromToken.2\",\n \"fromToken.-1\",\n ],\n method: \"arrayParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"arrayParam\", [\n [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n \"0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n ],\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\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-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n },\n // fromToken.2\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n // fromToken.-1\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return an error when a token datasource returns an error\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken\"],\n method: \"singleParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\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 {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return an error when the abi is not conform\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: [{ fakeabi: \"notworking\" }],\n selectorDetails: {\n erc20OfInterest: [\"fromToken\"],\n method: \"singleParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\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(\n \"[ContextModule] ExternalPluginContextLoader: Unable to parse abi\",\n ),\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should throw an error when the erc20OfInterest doest not exist in the transaction\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"notFound\"],\n method: \"singleParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\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(\n \"[ContextModule] ExternalPluginContextLoader: Unable to get address\",\n ),\n },\n ]);\n });\n\n it(\"should throw an error when an out-of-bounds element is present in erc20OfInterest\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken.3\"],\n method: \"arrayParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"arrayParam\", [\n [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n \"0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n ],\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\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 RangeError(\"out of result range\"),\n },\n ]);\n });\n\n it(\"should return a list of context responses when one erc20OfInterest is a complex struct\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\n \"complexStruct.address1\",\n \"complexStruct.param1.param2.0.param3.addresses.0\",\n \"complexStruct.param1.param2.0.param3.addresses.1\",\n \"complexStruct.param1.param2.0.param3.addresses.-1\",\n \"complexStruct.param1.param2.1.param3.addresses.0\",\n \"complexStruct.param1.param2.-1.param3.addresses.0\",\n ],\n method: \"complexStructParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"complexStructParam\", [\n {\n address1: \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n param1: {\n param2: [\n {\n param3: {\n addresses: [\n \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n \"0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE\",\n ],\n },\n },\n {\n param3: {\n addresses: [\"0xB8c77482e45F1F44dE1745F52C74426C631bDD52\"],\n },\n },\n ],\n },\n },\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\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-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return an error when datasource return a Left\", async () => {\n // GIVEN\n const transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").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 {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n ]);\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: \"0x0\",\n data: \"notAHexString\",\n } 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});\n"],
5
+ "mappings": "wdAAA,IAAAA,EAA0B,kBAC1BC,EAA4B,qBAE5BC,EAAgB,mDAEhBC,EAA4C,gEAG5CC,EAAqC,2CAIrC,MAAMC,EAAmB,CAAC,CACxB,IAAAC,EACA,gBAAAC,CACF,KAIS,CACL,IAAKD,EACL,gBAAiB,CACf,gBAAiB,CAAC,EAClB,OAAQ,GACR,OAAQ,GACR,eAAgB,SAChB,UAAW,OACX,GAAGC,CACL,CACF,GAGIC,EAAqB,CACzBF,EACAG,EACAC,IACuB,CAEvB,MAAMC,EADW,IAAI,YAAU,KAAK,UAAUL,CAAG,CAAC,EAC5B,mBAAmBG,EAAcC,CAAM,EAC7D,MAAO,CACL,GAAI,MACJ,KAAAC,EACA,SAAUA,EAAK,MAAM,EAAG,E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,KAAM,uBAAqB,MAC3B,QAAS,oDACX,EACA,CACE,KAAM,uBAAqB,MAC3B,QAAS,oDACX,EACA,CACE,KAAM,uBAAqB,MAC3B,QAAS,oDACX,EACA,CACE,KAAM,uBAAqB,gBAC3B,QAAS,YACX,CACF,CAAC,CACH,CAAC,EAED,GAAG,uDAAwD,SAAY,CAErE,MAAMF,EAAcR,EAAmB,EAAAW,QAAK,cAAe,CACzD,4CACF,CAAC,EACD,GAAG,MAAMN,EAA8B,cAAc,EAAE,qBACrD,QAAK,IAAI,MAAM,OAAO,CAAC,CACzB,EAGA,MAAMK,EAAS,MAAMJ,EAAO,KAAKE,CAAW,EAG5C,OAAOE,CAAM,EAAE,QAAQ,CACrB,CACE,KAAM,uBAAqB,MAC3B,MAAO,IAAI,MAAM,OAAO,CAC1B,CACF,CAAC,CACH,CAAC,EAED,GAAG,yEAA0E,SAAY,CAEvF,MAAMF,EAAc,CAClB,GAAI,MACJ,KAAM,eACR,EAGME,EAAS,MAAMJ,EAAO,KAAKE,CAAW,EAG5C,OAAOE,CAAM,EAAE,QAAQ,CACrB,CACE,KAAM,uBAAqB,MAC3B,MAAO,IAAI,MAAM,kBAAkB,CACrC,CACF,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["import_ethers", "import_purify_ts", "import_abi", "import_ExternalPluginContextLoader", "import_ClearSignContext", "dappInfosBuilder", "abi", "selectorDetails", "transactionBuilder", "functionName", "params", "data", "mockTokenDataSource", "mockExternalPluginDataSource", "loader", "address", "transaction", "promise", "result", "ABI", "dappInfos"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var a=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var t=(f,e,p,x)=>{if(e&&typeof e=="object"||typeof e=="function")for(let m of c(e))!d.call(f,m)&&m!==p&&a(f,m,{get:()=>e[m],enumerable:!(x=b(e,m))||x.enumerable});return f},r=(f,e,p)=>(t(f,e,"default"),p&&t(p,e,"default"));var g=f=>t(a({},"__esModule",{value:!0}),f);var o={};module.exports=g(o);r(o,require("./config/model/ContextModuleConfig"),module.exports);r(o,require("./ContextModule"),module.exports);r(o,require("./ContextModuleBuilder"),module.exports);r(o,require("./DefaultContextModule"),module.exports);r(o,require("./external-plugin/domain/ExternalPluginContextLoader"),module.exports);r(o,require("./nft/domain/NftContextLoader"),module.exports);r(o,require("./pki/domain/PkiCertificateLoader"),module.exports);r(o,require("./pki/model/KeyId"),module.exports);r(o,require("./pki/model/KeyUsage"),module.exports);r(o,require("./pki/model/PkiCertificate"),module.exports);r(o,require("./pki/model/PkiCertificateInfo"),module.exports);r(o,require("./shared/domain/ContextLoader"),module.exports);r(o,require("./shared/model/ClearSignContext"),module.exports);r(o,require("./shared/model/GenericPath"),module.exports);r(o,require("./shared/model/TransactionContext"),module.exports);r(o,require("./shared/model/TransactionSubset"),module.exports);r(o,require("./shared/model/TypedDataClearSignContext"),module.exports);r(o,require("./shared/model/TypedDataContext"),module.exports);r(o,require("./token/domain/TokenContextLoader"),module.exports);r(o,require("./trusted-name/domain/TrustedNameContextLoader"),module.exports);r(o,require("./web3-check/domain/Web3CheckContextLoader"),module.exports);r(o,require("./web3-check/domain/web3CheckTypes"),module.exports);0&&(module.exports={...require("./config/model/ContextModuleConfig"),...require("./ContextModule"),...require("./ContextModuleBuilder"),...require("./DefaultContextModule"),...require("./external-plugin/domain/ExternalPluginContextLoader"),...require("./nft/domain/NftContextLoader"),...require("./pki/domain/PkiCertificateLoader"),...require("./pki/model/KeyId"),...require("./pki/model/KeyUsage"),...require("./pki/model/PkiCertificate"),...require("./pki/model/PkiCertificateInfo"),...require("./shared/domain/ContextLoader"),...require("./shared/model/ClearSignContext"),...require("./shared/model/GenericPath"),...require("./shared/model/TransactionContext"),...require("./shared/model/TransactionSubset"),...require("./shared/model/TypedDataClearSignContext"),...require("./shared/model/TypedDataContext"),...require("./token/domain/TokenContextLoader"),...require("./trusted-name/domain/TrustedNameContextLoader"),...require("./web3-check/domain/Web3CheckContextLoader"),...require("./web3-check/domain/web3CheckTypes")});
1
+ "use strict";var a=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var t=(f,e,p,x)=>{if(e&&typeof e=="object"||typeof e=="function")for(let m of c(e))!d.call(f,m)&&m!==p&&a(f,m,{get:()=>e[m],enumerable:!(x=b(e,m))||x.enumerable});return f},r=(f,e,p)=>(t(f,e,"default"),p&&t(p,e,"default"));var g=f=>t(a({},"__esModule",{value:!0}),f);var o={};module.exports=g(o);r(o,require("./config/model/ContextModuleConfig"),module.exports);r(o,require("./ContextModule"),module.exports);r(o,require("./ContextModuleBuilder"),module.exports);r(o,require("./DefaultContextModule"),module.exports);r(o,require("./dynamic-network/domain/DynamicNetworkContextLoader"),module.exports);r(o,require("./dynamic-network/model/DynamicNetworkConfiguration"),module.exports);r(o,require("./external-plugin/domain/ExternalPluginContextLoader"),module.exports);r(o,require("./nft/domain/NftContextLoader"),module.exports);r(o,require("./pki/domain/PkiCertificateLoader"),module.exports);r(o,require("./pki/model/KeyId"),module.exports);r(o,require("./pki/model/KeyUsage"),module.exports);r(o,require("./pki/model/PkiCertificate"),module.exports);r(o,require("./pki/model/PkiCertificateInfo"),module.exports);r(o,require("./shared/domain/ContextLoader"),module.exports);r(o,require("./shared/model/ClearSignContext"),module.exports);r(o,require("./shared/model/GenericPath"),module.exports);r(o,require("./shared/model/TransactionContext"),module.exports);r(o,require("./shared/model/TransactionSubset"),module.exports);r(o,require("./shared/model/TypedDataClearSignContext"),module.exports);r(o,require("./shared/model/TypedDataContext"),module.exports);r(o,require("./token/domain/TokenContextLoader"),module.exports);r(o,require("./trusted-name/domain/TrustedNameContextLoader"),module.exports);r(o,require("./web3-check/domain/Web3CheckContextLoader"),module.exports);r(o,require("./web3-check/domain/web3CheckTypes"),module.exports);0&&(module.exports={...require("./config/model/ContextModuleConfig"),...require("./ContextModule"),...require("./ContextModuleBuilder"),...require("./DefaultContextModule"),...require("./dynamic-network/domain/DynamicNetworkContextLoader"),...require("./dynamic-network/model/DynamicNetworkConfiguration"),...require("./external-plugin/domain/ExternalPluginContextLoader"),...require("./nft/domain/NftContextLoader"),...require("./pki/domain/PkiCertificateLoader"),...require("./pki/model/KeyId"),...require("./pki/model/KeyUsage"),...require("./pki/model/PkiCertificate"),...require("./pki/model/PkiCertificateInfo"),...require("./shared/domain/ContextLoader"),...require("./shared/model/ClearSignContext"),...require("./shared/model/GenericPath"),...require("./shared/model/TransactionContext"),...require("./shared/model/TransactionSubset"),...require("./shared/model/TypedDataClearSignContext"),...require("./shared/model/TypedDataContext"),...require("./token/domain/TokenContextLoader"),...require("./trusted-name/domain/TrustedNameContextLoader"),...require("./web3-check/domain/Web3CheckContextLoader"),...require("./web3-check/domain/web3CheckTypes")});
2
2
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/index.ts"],
4
- "sourcesContent": ["export * from \"./config/model/ContextModuleConfig\";\nexport * from \"./ContextModule\";\nexport * from \"./ContextModuleBuilder\";\nexport * from \"./DefaultContextModule\";\nexport * from \"./external-plugin/domain/ExternalPluginContextLoader\";\nexport * from \"./nft/domain/NftContextLoader\";\nexport * from \"./pki/domain/PkiCertificateLoader\";\nexport * from \"./pki/model/KeyId\";\nexport * from \"./pki/model/KeyUsage\";\nexport * from \"./pki/model/PkiCertificate\";\nexport * from \"./pki/model/PkiCertificateInfo\";\nexport * from \"./shared/domain/ContextLoader\";\nexport * from \"./shared/model/ClearSignContext\";\nexport * from \"./shared/model/GenericPath\";\nexport * from \"./shared/model/TransactionContext\";\nexport * from \"./shared/model/TransactionSubset\";\nexport * from \"./shared/model/TypedDataClearSignContext\";\nexport * from \"./shared/model/TypedDataContext\";\nexport * from \"./token/domain/TokenContextLoader\";\nexport * from \"./trusted-name/domain/TrustedNameContextLoader\";\nexport * from \"./web3-check/domain/Web3CheckContextLoader\";\nexport * from \"./web3-check/domain/web3CheckTypes\";\n"],
5
- "mappings": "iaAAA,IAAAA,EAAA,kBAAAC,EAAAD,GAAAE,EAAAF,EAAc,8CAAd,gBACAE,EAAAF,EAAc,2BADd,gBAEAE,EAAAF,EAAc,kCAFd,gBAGAE,EAAAF,EAAc,kCAHd,gBAIAE,EAAAF,EAAc,gEAJd,gBAKAE,EAAAF,EAAc,yCALd,gBAMAE,EAAAF,EAAc,6CANd,gBAOAE,EAAAF,EAAc,6BAPd,gBAQAE,EAAAF,EAAc,gCARd,gBASAE,EAAAF,EAAc,sCATd,gBAUAE,EAAAF,EAAc,0CAVd,gBAWAE,EAAAF,EAAc,yCAXd,gBAYAE,EAAAF,EAAc,2CAZd,gBAaAE,EAAAF,EAAc,sCAbd,gBAcAE,EAAAF,EAAc,6CAdd,gBAeAE,EAAAF,EAAc,4CAfd,gBAgBAE,EAAAF,EAAc,oDAhBd,gBAiBAE,EAAAF,EAAc,2CAjBd,gBAkBAE,EAAAF,EAAc,6CAlBd,gBAmBAE,EAAAF,EAAc,0DAnBd,gBAoBAE,EAAAF,EAAc,sDApBd,gBAqBAE,EAAAF,EAAc,8CArBd",
4
+ "sourcesContent": ["export * from \"./config/model/ContextModuleConfig\";\nexport * from \"./ContextModule\";\nexport * from \"./ContextModuleBuilder\";\nexport * from \"./DefaultContextModule\";\nexport * from \"./dynamic-network/domain/DynamicNetworkContextLoader\";\nexport * from \"./dynamic-network/model/DynamicNetworkConfiguration\";\nexport * from \"./external-plugin/domain/ExternalPluginContextLoader\";\nexport * from \"./nft/domain/NftContextLoader\";\nexport * from \"./pki/domain/PkiCertificateLoader\";\nexport * from \"./pki/model/KeyId\";\nexport * from \"./pki/model/KeyUsage\";\nexport * from \"./pki/model/PkiCertificate\";\nexport * from \"./pki/model/PkiCertificateInfo\";\nexport * from \"./shared/domain/ContextLoader\";\nexport * from \"./shared/model/ClearSignContext\";\nexport * from \"./shared/model/GenericPath\";\nexport * from \"./shared/model/TransactionContext\";\nexport * from \"./shared/model/TransactionSubset\";\nexport * from \"./shared/model/TypedDataClearSignContext\";\nexport * from \"./shared/model/TypedDataContext\";\nexport * from \"./token/domain/TokenContextLoader\";\nexport * from \"./trusted-name/domain/TrustedNameContextLoader\";\nexport * from \"./web3-check/domain/Web3CheckContextLoader\";\nexport * from \"./web3-check/domain/web3CheckTypes\";\n"],
5
+ "mappings": "iaAAA,IAAAA,EAAA,kBAAAC,EAAAD,GAAAE,EAAAF,EAAc,8CAAd,gBACAE,EAAAF,EAAc,2BADd,gBAEAE,EAAAF,EAAc,kCAFd,gBAGAE,EAAAF,EAAc,kCAHd,gBAIAE,EAAAF,EAAc,gEAJd,gBAKAE,EAAAF,EAAc,+DALd,gBAMAE,EAAAF,EAAc,gEANd,gBAOAE,EAAAF,EAAc,yCAPd,gBAQAE,EAAAF,EAAc,6CARd,gBASAE,EAAAF,EAAc,6BATd,gBAUAE,EAAAF,EAAc,gCAVd,gBAWAE,EAAAF,EAAc,sCAXd,gBAYAE,EAAAF,EAAc,0CAZd,gBAaAE,EAAAF,EAAc,yCAbd,gBAcAE,EAAAF,EAAc,2CAdd,gBAeAE,EAAAF,EAAc,sCAfd,gBAgBAE,EAAAF,EAAc,6CAhBd,gBAiBAE,EAAAF,EAAc,4CAjBd,gBAkBAE,EAAAF,EAAc,oDAlBd,gBAmBAE,EAAAF,EAAc,2CAnBd,gBAoBAE,EAAAF,EAAc,6CApBd,gBAqBAE,EAAAF,EAAc,0DArBd,gBAsBAE,EAAAF,EAAc,sDAtBd,gBAuBAE,EAAAF,EAAc,8CAvBd",
6
6
  "names": ["src_exports", "__toCommonJS", "__reExport"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var y=Object.create;var i=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var E=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var C=(e,t)=>{for(var o in t)i(e,o,{get:t[o],enumerable:!0})},u=(e,t,o,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of P(t))!x.call(e,r)&&r!==o&&i(e,r,{get:()=>t[r],enumerable:!(a=c(t,r))||a.enumerable});return e};var f=(e,t,o)=>(o=e!=null?y(E(e)):{},u(t||!e||!e.__esModule?i(o,"default",{value:e,enumerable:!0}):o,e)),G=e=>u(i({},"__esModule",{value:!0}),e),g=(e,t,o,a)=>{for(var r=a>1?void 0:a?c(t,o):t,l=e.length-1,d;l>=0;l--)(d=e[l])&&(r=(a?d(t,o,r):d(r))||r);return a&&r&&i(t,o,r),r};var $={};C($,{HttpNftDataSource:()=>s});module.exports=G($);var m=f(require("axios")),h=require("inversify"),n=require("purify-ts"),p=f(require("../../../package.json"));let s=class{async getSetPluginPayload({chainId:t,address:o,selector:a}){try{const r=await m.default.request({method:"GET",url:`https://nft.api.live.ledger.com/v1/ethereum/${t}/contracts/${o}/plugin-selector/${a}`,headers:{"X-Ledger-Client-Version":`context-module/${p.default.version}`}});return r.data.payload?(0,n.Right)(r.data.payload):(0,n.Left)(new Error("[ContextModule] HttpNftDataSource: unexpected empty response"))}catch{return(0,n.Left)(new Error("[ContextModule] HttpNftDataSource: Failed to fetch set plugin payload"))}}async getNftInfosPayload({chainId:t,address:o}){try{const a=await m.default.request({method:"GET",url:`https://nft.api.live.ledger.com/v1/ethereum/${t}/contracts/${o}`,headers:{"X-Ledger-Client-Version":`context-module/${p.default.version}`}});return a.data.payload?(0,n.Right)(a.data.payload):(0,n.Left)(new Error("[ContextModule] HttpNftDataSource: no nft metadata"))}catch{return(0,n.Left)(new Error("[ContextModule] HttpNftDataSource: Failed to fetch nft informations"))}}};s=g([(0,h.injectable)()],s);0&&(module.exports={HttpNftDataSource});
1
+ "use strict";var x=Object.create;var s=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var G=Object.getPrototypeOf,N=Object.prototype.hasOwnProperty;var D=(e,t)=>{for(var o in t)s(e,o,{get:t[o],enumerable:!0})},g=(e,t,o,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of C(t))!N.call(e,r)&&r!==o&&s(e,r,{get:()=>t[r],enumerable:!(a=p(t,r))||a.enumerable});return e};var E=(e,t,o)=>(o=e!=null?x(G(e)):{},g(t||!e||!e.__esModule?s(o,"default",{value:e,enumerable:!0}):o,e)),S=e=>g(s({},"__esModule",{value:!0}),e),y=(e,t,o,a)=>{for(var r=a>1?void 0:a?p(t,o):t,c=e.length-1,d;c>=0;c--)(d=e[c])&&(r=(a?d(t,o,r):d(r))||r);return a&&r&&s(t,o,r),r},h=(e,t)=>(o,a)=>t(o,a,e);var $={};D($,{HttpNftDataSource:()=>m});module.exports=S($);var f=E(require("axios")),l=require("inversify"),n=require("purify-ts"),P=require("../../config/di/configTypes"),i=require("../../shared/constant/HttpHeaders"),u=E(require("../../../package.json"));let m=class{constructor(t){this.config=t}async getSetPluginPayload({chainId:t,address:o,selector:a}){try{const r=await f.default.request({method:"GET",url:`${this.config.metadataServiceDomain.url}/v1/ethereum/${t}/contracts/${o}/plugin-selector/${a}`,headers:{[i.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${u.default.version}`,[i.LEDGER_ORIGIN_TOKEN_HEADER]:this.config.originToken}});return r.data.payload?(0,n.Right)(r.data.payload):(0,n.Left)(new Error("[ContextModule] HttpNftDataSource: unexpected empty response"))}catch{return(0,n.Left)(new Error("[ContextModule] HttpNftDataSource: Failed to fetch set plugin payload"))}}async getNftInfosPayload({chainId:t,address:o}){try{const a=await f.default.request({method:"GET",url:`${this.config.metadataServiceDomain.url}/v1/ethereum/${t}/contracts/${o}`,headers:{[i.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${u.default.version}`,[i.LEDGER_ORIGIN_TOKEN_HEADER]:this.config.originToken}});return a.data.payload?(0,n.Right)(a.data.payload):(0,n.Left)(new Error("[ContextModule] HttpNftDataSource: no nft metadata"))}catch{return(0,n.Left)(new Error("[ContextModule] HttpNftDataSource: Failed to fetch nft informations"))}}};m=y([(0,l.injectable)(),h(0,(0,l.inject)(P.configTypes.Config))],m);0&&(module.exports={HttpNftDataSource});
2
2
  //# sourceMappingURL=HttpNftDataSource.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/nft/data/HttpNftDataSource.ts"],
4
- "sourcesContent": ["import axios from \"axios\";\nimport { injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport {\n GetNftInformationsParams,\n GetSetPluginPayloadParams,\n NftDataSource,\n} from \"@/nft/data/NftDataSource\";\nimport PACKAGE from \"@root/package.json\";\n\n@injectable()\nexport class HttpNftDataSource implements NftDataSource {\n public async getSetPluginPayload({\n chainId,\n address,\n selector,\n }: GetSetPluginPayloadParams): Promise<Either<Error, string>> {\n try {\n const response = await axios.request<{ payload: string }>({\n method: \"GET\",\n url: `https://nft.api.live.ledger.com/v1/ethereum/${chainId}/contracts/${address}/plugin-selector/${selector}`,\n headers: {\n \"X-Ledger-Client-Version\": `context-module/${PACKAGE.version}`,\n },\n });\n\n return response.data.payload\n ? Right(response.data.payload)\n : Left(\n new Error(\n \"[ContextModule] HttpNftDataSource: unexpected empty response\",\n ),\n );\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] HttpNftDataSource: Failed to fetch set plugin payload\",\n ),\n );\n }\n }\n\n public async getNftInfosPayload({\n chainId,\n address,\n }: GetNftInformationsParams): Promise<Either<Error, string>> {\n try {\n const response = await axios.request<{ payload: string }>({\n method: \"GET\",\n url: `https://nft.api.live.ledger.com/v1/ethereum/${chainId}/contracts/${address}`,\n headers: {\n \"X-Ledger-Client-Version\": `context-module/${PACKAGE.version}`,\n },\n });\n\n return response.data.payload\n ? Right(response.data.payload)\n : Left(new Error(\"[ContextModule] HttpNftDataSource: no nft metadata\"));\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] HttpNftDataSource: Failed to fetch nft informations\",\n ),\n );\n }\n }\n}\n"],
5
- "mappings": "4rBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkB,oBAClBC,EAA2B,qBAC3BC,EAAoC,qBAOpCC,EAAoB,iCAGb,IAAMC,EAAN,KAAiD,CACtD,MAAa,oBAAoB,CAC/B,QAAAC,EACA,QAAAC,EACA,SAAAC,CACF,EAA8D,CAC5D,GAAI,CACF,MAAMC,EAAW,MAAM,EAAAC,QAAM,QAA6B,CACxD,OAAQ,MACR,IAAK,+CAA+CJ,CAAO,cAAcC,CAAO,oBAAoBC,CAAQ,GAC5G,QAAS,CACP,0BAA2B,kBAAkB,EAAAG,QAAQ,OAAO,EAC9D,CACF,CAAC,EAED,OAAOF,EAAS,KAAK,WACjB,SAAMA,EAAS,KAAK,OAAO,KAC3B,QACE,IAAI,MACF,8DACF,CACF,CACN,MAAiB,CACf,SAAO,QACL,IAAI,MACF,uEACF,CACF,CACF,CACF,CAEA,MAAa,mBAAmB,CAC9B,QAAAH,EACA,QAAAC,CACF,EAA6D,CAC3D,GAAI,CACF,MAAME,EAAW,MAAM,EAAAC,QAAM,QAA6B,CACxD,OAAQ,MACR,IAAK,+CAA+CJ,CAAO,cAAcC,CAAO,GAChF,QAAS,CACP,0BAA2B,kBAAkB,EAAAI,QAAQ,OAAO,EAC9D,CACF,CAAC,EAED,OAAOF,EAAS,KAAK,WACjB,SAAMA,EAAS,KAAK,OAAO,KAC3B,QAAK,IAAI,MAAM,oDAAoD,CAAC,CAC1E,MAAiB,CACf,SAAO,QACL,IAAI,MACF,qEACF,CACF,CACF,CACF,CACF,EAvDaJ,EAANO,EAAA,IADN,cAAW,GACCP",
6
- "names": ["HttpNftDataSource_exports", "__export", "HttpNftDataSource", "__toCommonJS", "import_axios", "import_inversify", "import_purify_ts", "import_package", "HttpNftDataSource", "chainId", "address", "selector", "response", "axios", "PACKAGE", "__decorateClass"]
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 ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n GetNftInformationsParams,\n GetSetPluginPayloadParams,\n NftDataSource,\n} from \"@/nft/data/NftDataSource\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport PACKAGE from \"@root/package.json\";\n\n@injectable()\nexport class HttpNftDataSource implements NftDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n ) {}\n\n public async getSetPluginPayload({\n chainId,\n address,\n selector,\n }: GetSetPluginPayloadParams): Promise<Either<Error, string>> {\n try {\n const response = await axios.request<{ payload: string }>({\n method: \"GET\",\n url: `${this.config.metadataServiceDomain.url}/v1/ethereum/${chainId}/contracts/${address}/plugin-selector/${selector}`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n\n return response.data.payload\n ? Right(response.data.payload)\n : Left(\n new Error(\n \"[ContextModule] HttpNftDataSource: unexpected empty response\",\n ),\n );\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] HttpNftDataSource: Failed to fetch set plugin payload\",\n ),\n );\n }\n }\n\n public async getNftInfosPayload({\n chainId,\n address,\n }: GetNftInformationsParams): Promise<Either<Error, string>> {\n try {\n const response = await axios.request<{ payload: string }>({\n method: \"GET\",\n url: `${this.config.metadataServiceDomain.url}/v1/ethereum/${chainId}/contracts/${address}`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n\n return response.data.payload\n ? Right(response.data.payload)\n : Left(new Error(\"[ContextModule] HttpNftDataSource: no nft metadata\"));\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] Htt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,MAAiB,CACf,SAAO,QACL,IAAI,MACF,qEACF,CACF,CACF,CACF,CACF,EA7DaL,EAANQ,EAAA,IADN,cAAW,EAGPC,EAAA,eAAO,cAAY,MAAM,IAFjBT",
6
+ "names": ["HttpNftDataSource_exports", "__export", "HttpNftDataSource", "__toCommonJS", "import_axios", "import_inversify", "import_purify_ts", "import_configTypes", "import_HttpHeaders", "import_package", "HttpNftDataSource", "config", "chainId", "address", "selector", "response", "axios", "PACKAGE", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var i=Object.create;var n=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var h=(t,e,a,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of p(e))!y.call(t,r)&&r!==a&&n(t,r,{get:()=>e[r],enumerable:!(s=u(e,r))||s.enumerable});return t};var l=(t,e,a)=>(a=t!=null?i(x(t)):{},h(e||!t||!t.__esModule?n(a,"default",{value:t,enumerable:!0}):a,t));var o=l(require("axios")),d=l(require("../../../package.json")),c=require("./HttpNftDataSource");vi.mock("axios");describe("HttpNftDataSource",()=>{let t;beforeAll(()=>{t=new c.HttpNftDataSource,vi.clearAllMocks()}),it("should call axios with the ledger client version header",async()=>{const e=`context-module/${d.default.version}`,a=vi.fn(()=>Promise.resolve({data:[]}));vi.spyOn(o.default,"request").mockImplementation(a),await t.getNftInfosPayload({address:"0x00",chainId:1}),await t.getSetPluginPayload({address:"0x00",chainId:1,selector:"0x00"}),expect(a).toHaveBeenNthCalledWith(1,expect.objectContaining({headers:{"X-Ledger-Client-Version":e}})),expect(a).toHaveBeenNthCalledWith(2,expect.objectContaining({headers:{"X-Ledger-Client-Version":e}}))}),describe("getNftInfosPayload",()=>{it("should return an error when axios throws an error",async()=>{vi.spyOn(o.default,"request").mockRejectedValue(new Error("error"));const e=await t.getNftInfosPayload({address:"0x00",chainId:1});expect(e.extract()).toEqual(new Error("[ContextModule] HttpNftDataSource: Failed to fetch nft informations"))}),it("should return an error when the response is empty",async()=>{const e={data:{}};vi.spyOn(o.default,"request").mockResolvedValue(e);const a=await t.getNftInfosPayload({address:"0x00",chainId:1});expect(a.extract()).toEqual(new Error("[ContextModule] HttpNftDataSource: no nft metadata"))}),it("should return the payload",async()=>{const e={data:{payload:"payload"}};vi.spyOn(o.default,"request").mockResolvedValue(e);const a=await t.getNftInfosPayload({address:"0x00",chainId:1});expect(a.extract()).toEqual("payload")})}),describe("getSetPluginPayload",()=>{it("should return an error when axios throws an error",async()=>{vi.spyOn(o.default,"request").mockRejectedValue(new Error("error"));const e=await t.getSetPluginPayload({address:"0x00",chainId:1,selector:"0x00"});expect(e.extract()).toEqual(new Error("[ContextModule] HttpNftDataSource: Failed to fetch set plugin payload"))}),it("should return an error when the response is empty",async()=>{const e={data:{}};vi.spyOn(o.default,"request").mockResolvedValue(e);const a=await t.getSetPluginPayload({address:"0x00",chainId:1,selector:"0x00"});expect(a.extract()).toEqual(new Error("[ContextModule] HttpNftDataSource: unexpected empty response"))}),it("should return the payload",async()=>{const e={data:{payload:"payload"}};vi.spyOn(o.default,"request").mockResolvedValue(e);const a=await t.getSetPluginPayload({address:"0x00",chainId:1,selector:"0x00"});expect(a.extract()).toEqual("payload")})})});
1
+ "use strict";var p=Object.create;var l=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var y=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var m=(t,e,o,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of h(e))!f.call(t,n)&&n!==o&&l(t,n,{get:()=>e[n],enumerable:!(i=x(e,n))||i.enumerable});return t};var c=(t,e,o)=>(o=t!=null?p(y(t)):{},m(e||!t||!t.__esModule?l(o,"default",{value:t,enumerable:!0}):o,t));var a=c(require("axios")),r=require("../../shared/constant/HttpHeaders"),d=c(require("../../../package.json")),u=require("./HttpNftDataSource");vi.mock("axios");const s={web3checks:{url:"web3checksUrl"},metadataServiceDomain:{url:"https://nft.api.live.ledger.com"},originToken:"originToken"};describe("HttpNftDataSource",()=>{let t;beforeAll(()=>{t=new u.HttpNftDataSource(s),vi.clearAllMocks()}),it("should call axios with the ledger client version and origin Token header",async()=>{const e=`context-module/${d.default.version}`,o=vi.fn(()=>Promise.resolve({data:[]}));vi.spyOn(a.default,"request").mockImplementation(o),await t.getNftInfosPayload({address:"0x00",chainId:1}),await t.getSetPluginPayload({address:"0x00",chainId:1,selector:"0x00"}),expect(o).toHaveBeenNthCalledWith(1,expect.objectContaining({headers:{[r.LEDGER_CLIENT_VERSION_HEADER]:e,[r.LEDGER_ORIGIN_TOKEN_HEADER]:s.originToken}})),expect(o).toHaveBeenNthCalledWith(2,expect.objectContaining({headers:{[r.LEDGER_CLIENT_VERSION_HEADER]:e,[r.LEDGER_ORIGIN_TOKEN_HEADER]:s.originToken}}))}),describe("getNftInfosPayload",()=>{it("should return an error when axios throws an error",async()=>{vi.spyOn(a.default,"request").mockRejectedValue(new Error("error"));const e=await t.getNftInfosPayload({address:"0x00",chainId:1});expect(e.extract()).toEqual(new Error("[ContextModule] HttpNftDataSource: Failed to fetch nft informations"))}),it("should return an error when the response is empty",async()=>{const e={data:{}};vi.spyOn(a.default,"request").mockResolvedValue(e);const o=await t.getNftInfosPayload({address:"0x00",chainId:1});expect(o.extract()).toEqual(new Error("[ContextModule] HttpNftDataSource: no nft metadata"))}),it("should return the payload",async()=>{const e={data:{payload:"payload"}};vi.spyOn(a.default,"request").mockResolvedValue(e);const o=await t.getNftInfosPayload({address:"0x00",chainId:1});expect(o.extract()).toEqual("payload")})}),describe("getSetPluginPayload",()=>{it("should return an error when axios throws an error",async()=>{vi.spyOn(a.default,"request").mockRejectedValue(new Error("error"));const e=await t.getSetPluginPayload({address:"0x00",chainId:1,selector:"0x00"});expect(e.extract()).toEqual(new Error("[ContextModule] HttpNftDataSource: Failed to fetch set plugin payload"))}),it("should return an error when the response is empty",async()=>{const e={data:{}};vi.spyOn(a.default,"request").mockResolvedValue(e);const o=await t.getSetPluginPayload({address:"0x00",chainId:1,selector:"0x00"});expect(o.extract()).toEqual(new Error("[ContextModule] HttpNftDataSource: unexpected empty response"))}),it("should return the payload",async()=>{const e={data:{payload:"payload"}};vi.spyOn(a.default,"request").mockResolvedValue(e);const o=await t.getSetPluginPayload({address:"0x00",chainId:1,selector:"0x00"});expect(o.extract()).toEqual("payload")})})});
2
2
  //# sourceMappingURL=HttpNftDataSource.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/nft/data/HttpNftDataSource.test.ts"],
4
- "sourcesContent": ["import axios from \"axios\";\n\nimport PACKAGE from \"@root/package.json\";\n\nimport { HttpNftDataSource } from \"./HttpNftDataSource\";\nimport { type NftDataSource } from \"./NftDataSource\";\n\nvi.mock(\"axios\");\n\ndescribe(\"HttpNftDataSource\", () => {\n let datasource: NftDataSource;\n\n beforeAll(() => {\n datasource = new HttpNftDataSource();\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.getNftInfosPayload({ address: \"0x00\", chainId: 1 });\n await datasource.getSetPluginPayload({\n address: \"0x00\",\n chainId: 1,\n selector: \"0x00\",\n });\n\n // THEN\n expect(requestSpy).toHaveBeenNthCalledWith(\n 1,\n expect.objectContaining({\n headers: { \"X-Ledger-Client-Version\": version },\n }),\n );\n expect(requestSpy).toHaveBeenNthCalledWith(\n 2,\n expect.objectContaining({\n headers: { \"X-Ledger-Client-Version\": version },\n }),\n );\n });\n\n describe(\"getNftInfosPayload\", () => {\n it(\"should return an error when axios throws an error\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockRejectedValue(new Error(\"error\"));\n\n // WHEN\n const result = await datasource.getNftInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result.extract()).toEqual(\n new Error(\n \"[ContextModule] HttpNftDataSource: Failed to fetch nft informations\",\n ),\n );\n });\n\n it(\"should return an error when the response is empty\", async () => {\n // GIVEN\n const response = { data: {} };\n vi.spyOn(axios, \"request\").mockResolvedValue(response);\n\n // WHEN\n const result = await datasource.getNftInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result.extract()).toEqual(\n new Error(\"[ContextModule] HttpNftDataSource: no nft metadata\"),\n );\n });\n\n it(\"should return the payload\", async () => {\n // GIVEN\n const response = { data: { payload: \"payload\" } };\n vi.spyOn(axios, \"request\").mockResolvedValue(response);\n\n // WHEN\n const result = await datasource.getNftInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result.extract()).toEqual(\"payload\");\n });\n });\n\n describe(\"getSetPluginPayload\", () => {\n it(\"should return an error when axios throws an error\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockRejectedValue(new Error(\"error\"));\n\n // WHEN\n const result = await datasource.getSetPluginPayload({\n address: \"0x00\",\n chainId: 1,\n selector: \"0x00\",\n });\n\n // THEN\n expect(result.extract()).toEqual(\n new Error(\n \"[ContextModule] HttpNftDataSource: Failed to fetch set plugin payload\",\n ),\n );\n });\n\n it(\"should return an error when the response is empty\", async () => {\n // GIVEN\n const response = { data: {} };\n vi.spyOn(axios, \"request\").mockResolvedValue(response);\n\n // WHEN\n const result = await datasource.getSetPluginPayload({\n address: \"0x00\",\n chainId: 1,\n selector: \"0x00\",\n });\n\n // THEN\n expect(result.extract()).toEqual(\n new Error(\n \"[ContextModule] HttpNftDataSource: unexpected empty response\",\n ),\n );\n });\n\n it(\"should return the payload\", async () => {\n // GIVEN\n const response = { data: { payload: \"payload\" } };\n vi.spyOn(axios, \"request\").mockResolvedValue(response);\n\n // WHEN\n const result = await datasource.getSetPluginPayload({\n address: \"0x00\",\n chainId: 1,\n selector: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AClD,QAAS,OACT,QAAS,EACT,SAAU,MACZ,CAAC,EAGD,OAAOK,EAAO,QAAQ,CAAC,EAAE,QAAQ,SAAS,CAC5C,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["import_axios", "import_package", "import_HttpNftDataSource", "datasource", "version", "PACKAGE", "requestSpy", "axios", "result", "response"]
4
+ "sourcesContent": ["import axios from \"axios\";\n\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport PACKAGE from \"@root/package.json\";\n\nimport { HttpNftDataSource } from \"./HttpNftDataSource\";\nimport { type NftDataSource } from \"./NftDataSource\";\n\nvi.mock(\"axios\");\n\nconst config = {\n web3checks: {\n url: \"web3checksUrl\",\n },\n metadataServiceDomain: {\n url: \"https://nft.api.live.ledger.com\",\n },\n originToken: \"originToken\",\n} as ContextModuleConfig;\ndescribe(\"HttpNftDataSource\", () => {\n let datasource: NftDataSource;\n\n beforeAll(() => {\n datasource = new HttpNftDataSource(config);\n vi.clearAllMocks();\n });\n\n it(\"should call axios with the ledger client version and origin Token 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.getNftInfosPayload({ address: \"0x00\", chainId: 1 });\n await datasource.getSetPluginPayload({\n address: \"0x00\",\n chainId: 1,\n selector: \"0x00\",\n });\n\n // THEN\n expect(requestSpy).toHaveBeenNthCalledWith(\n 1,\n expect.objectContaining({\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: version,\n [LEDGER_ORIGIN_TOKEN_HEADER]: config.originToken,\n },\n }),\n );\n expect(requestSpy).toHaveBeenNthCalledWith(\n 2,\n expect.objectContaining({\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: version,\n [LEDGER_ORIGIN_TOKEN_HEADER]: config.originToken,\n },\n }),\n );\n });\n\n describe(\"getNftInfosPayload\", () => {\n it(\"should return an error when axios throws an error\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockRejectedValue(new Error(\"error\"));\n\n // WHEN\n const result = await datasource.getNftInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result.extract()).toEqual(\n new Error(\n \"[ContextModule] HttpNftDataSource: Failed to fetch nft informations\",\n ),\n );\n });\n\n it(\"should return an error when the response is empty\", async () => {\n // GIVEN\n const response = { data: {} };\n vi.spyOn(axios, \"request\").mockResolvedValue(response);\n\n // WHEN\n const result = await datasource.getNftInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result.extract()).toEqual(\n new Error(\"[ContextModule] HttpNftDataSource: no nft metadata\"),\n );\n });\n\n it(\"should return the payload\", async () => {\n // GIVEN\n const response = { data: { payload: \"payload\" } };\n vi.spyOn(axios, \"request\").mockResolvedValue(response);\n\n // WHEN\n const result = await datasource.getNftInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result.extract()).toEqual(\"payload\");\n });\n });\n\n describe(\"getSetPluginPayload\", () => {\n it(\"should return an error when axios throws an error\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockRejectedValue(new Error(\"error\"));\n\n // WHEN\n const result = await datasource.getSetPluginPayload({\n address: \"0x00\",\n chainId: 1,\n selector: \"0x00\",\n });\n\n // THEN\n expect(result.extract()).toEqual(\n new Error(\n \"[ContextModule] HttpNftDataSource: Failed to fetch set plugin payload\",\n ),\n );\n });\n\n it(\"should return an error when the response is empty\", async () => {\n // GIVEN\n const response = { data: {} };\n vi.spyOn(axios, \"request\").mockResolvedValue(response);\n\n // WHEN\n const result = await datasource.getSetPluginPayload({\n address: \"0x00\",\n chainId: 1,\n selector: \"0x00\",\n });\n\n // THEN\n expect(result.extract()).toEqual(\n new Error(\n \"[ContextModule] HttpNftDataSource: unexpected empty response\",\n ),\n );\n });\n\n it(\"should return the payload\", async () => {\n // GIVEN\n const response = { data: { payload: \"payload\" } };\n vi.spyOn(axios, \"request\").mockResolvedValue(response);\n\n // WHEN\n const result = await datasource.getSetPluginPayload({\n address: \"0x00\",\n chainId: 1,\n selector: \"0x00\",\n });\n\n // THEN\n expect(result.extract()).toEqual(\"payload\");\n });\n });\n});\n"],
5
+ "mappings": "wdAAA,IAAAA,EAAkB,oBAGlBC,EAGO,yCACPC,EAAoB,iCAEpBC,EAAkC,+BAGlC,GAAG,KAAK,OAAO,EAEf,MAAMC,EAAS,CACb,WAAY,CACV,IAAK,eACP,EACA,sBAAuB,CACrB,IAAK,iCACP,EACA,YAAa,aACf,EACA,SAAS,oBAAqB,IAAM,CAClC,IAAIC,EAEJ,UAAU,IAAM,CACdA,EAAa,IAAI,oBAAkBD,CAAM,EACzC,GAAG,cAAc,CACnB,CAAC,EAED,GAAG,2EAA4E,SAAY,CAEzF,MAAME,EAAU,kBAAkB,EAAAC,QAAQ,OAAO,GAC3CC,EAAa,GAAG,GAAG,IAAM,QAAQ,QAAQ,CAAE,KAAM,CAAC,CAAE,CAAC,CAAC,EAC5D,GAAG,MAAM,EAAAC,QAAO,SAAS,EAAE,mBAAmBD,CAAU,EAGxD,MAAMH,EAAW,mBAAmB,CAAE,QAAS,OAAQ,QAAS,CAAE,CAAC,EACnE,MAAMA,EAAW,oBAAoB,CACnC,QAAS,OACT,QAAS,EACT,SAAU,MACZ,CAAC,EAGD,OAAOG,CAAU,EAAE,wBACjB,EACA,OAAO,iBAAiB,CACtB,QAAS,CACP,CAAC,8BAA4B,EAAGF,EAChC,CAAC,4BAA0B,EAAGF,EAAO,WACvC,CACF,CAAC,CACH,EACA,OAAOI,CAAU,EAAE,wBACjB,EACA,OAAO,iBAAiB,CACtB,QAAS,CACP,CAAC,8BAA4B,EAAGF,EAChC,CAAC,4BAA0B,EAAGF,EAAO,WACvC,CACF,CAAC,CACH,CACF,CAAC,EAED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,EAAAF,QAAO,SAAS,EAAE,kBAAkBE,CAAQ,EAGrD,MAAMD,EAAS,MAAML,EAAW,oBAAoB,CAClD,QAAS,OACT,QAAS,EACT,SAAU,MACZ,CAAC,EAGD,OAAOK,EAAO,QAAQ,CAAC,EAAE,QACvB,IAAI,MACF,8DACF,CACF,CACF,CAAC,EAED,GAAG,4BAA6B,SAAY,CAE1C,MAAMC,EAAW,CAAE,KAAM,CAAE,QAAS,SAAU,CAAE,EAChD,GAAG,MAAM,EAAAF,QAAO,SAAS,EAAE,kBAAkBE,CAAQ,EAGrD,MAAMD,EAAS,MAAML,EAAW,oBAAoB,CAClD,QAAS,OACT,QAAS,EACT,SAAU,MACZ,CAAC,EAGD,OAAOK,EAAO,QAAQ,CAAC,EAAE,QAAQ,SAAS,CAC5C,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["import_axios", "import_HttpHeaders", "import_package", "import_HttpNftDataSource", "config", "datasource", "version", "PACKAGE", "requestSpy", "axios", "result", "response"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var f=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var N=(t,o)=>{for(var r in o)f(t,r,{get:o[r],enumerable:!0})},s=(t,o,r,n)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of u(o))!c.call(t,e)&&e!==r&&f(t,e,{get:()=>o[e],enumerable:!(n=d(o,e))||n.enumerable});return t};var x=t=>s(f({},"__esModule",{value:!0}),t);var _={};N(_,{nftModuleFactory:()=>C});module.exports=x(_);var m=require("inversify"),i=require("../../nft/data/HttpNftDataSource"),a=require("../../nft/di/nftTypes"),p=require("../../nft/domain/NftContextLoader");const C=()=>new m.ContainerModule((t,o,r,n)=>{t(a.nftTypes.NftDataSource).to(i.HttpNftDataSource),t(a.nftTypes.NftContextLoader).to(p.NftContextLoader)});0&&(module.exports={nftModuleFactory});
1
+ "use strict";var f=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var N=Object.prototype.hasOwnProperty;var d=(t,o)=>{for(var e in o)f(t,e,{get:o[e],enumerable:!0})},x=(t,o,e,m)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of u(o))!N.call(t,r)&&r!==e&&f(t,r,{get:()=>o[r],enumerable:!(m=i(o,r))||m.enumerable});return t};var C=t=>x(f({},"__esModule",{value:!0}),t);var s={};d(s,{nftModuleFactory:()=>l});module.exports=C(s);var n=require("inversify"),p=require("../../nft/data/HttpNftDataSource"),a=require("../../nft/di/nftTypes"),c=require("../../nft/domain/NftContextLoader");const l=()=>new n.ContainerModule(({bind:t})=>{t(a.nftTypes.NftDataSource).to(p.HttpNftDataSource),t(a.nftTypes.NftContextLoader).to(c.NftContextLoader)});0&&(module.exports={nftModuleFactory});
2
2
  //# sourceMappingURL=nftModuleFactory.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/nft/di/nftModuleFactory.ts"],
4
- "sourcesContent": ["import { ContainerModule } from \"inversify\";\n\nimport { HttpNftDataSource } from \"@/nft/data/HttpNftDataSource\";\nimport { nftTypes } from \"@/nft/di/nftTypes\";\nimport { NftContextLoader } from \"@/nft/domain/NftContextLoader\";\n\nexport const nftModuleFactory = () =>\n new ContainerModule((bind, _unbind, _isBound, _rebind) => {\n bind(nftTypes.NftDataSource).to(HttpNftDataSource);\n bind(nftTypes.NftContextLoader).to(NftContextLoader);\n });\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,sBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAgC,qBAEhCC,EAAkC,wCAClCC,EAAyB,6BACzBC,EAAiC,yCAE1B,MAAML,EAAmB,IAC9B,IAAI,kBAAgB,CAACM,EAAMC,EAASC,EAAUC,IAAY,CACxDH,EAAK,WAAS,aAAa,EAAE,GAAG,mBAAiB,EACjDA,EAAK,WAAS,gBAAgB,EAAE,GAAG,kBAAgB,CACrD,CAAC",
6
- "names": ["nftModuleFactory_exports", "__export", "nftModuleFactory", "__toCommonJS", "import_inversify", "import_HttpNftDataSource", "import_nftTypes", "import_NftContextLoader", "bind", "_unbind", "_isBound", "_rebind"]
4
+ "sourcesContent": ["import { ContainerModule } from \"inversify\";\n\nimport { HttpNftDataSource } from \"@/nft/data/HttpNftDataSource\";\nimport { nftTypes } from \"@/nft/di/nftTypes\";\nimport { NftContextLoader } from \"@/nft/domain/NftContextLoader\";\n\nexport const nftModuleFactory = () =>\n new ContainerModule(({ bind }) => {\n bind(nftTypes.NftDataSource).to(HttpNftDataSource);\n bind(nftTypes.NftContextLoader).to(NftContextLoader);\n });\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,sBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAgC,qBAEhCC,EAAkC,wCAClCC,EAAyB,6BACzBC,EAAiC,yCAE1B,MAAML,EAAmB,IAC9B,IAAI,kBAAgB,CAAC,CAAE,KAAAM,CAAK,IAAM,CAChCA,EAAK,WAAS,aAAa,EAAE,GAAG,mBAAiB,EACjDA,EAAK,WAAS,gBAAgB,EAAE,GAAG,kBAAgB,CACrD,CAAC",
6
+ "names": ["nftModuleFactory_exports", "__export", "nftModuleFactory", "__toCommonJS", "import_inversify", "import_HttpNftDataSource", "import_nftTypes", "import_NftContextLoader", "bind"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var p=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var I=Object.prototype.hasOwnProperty;var b=(o,e)=>{for(var a in e)p(o,a,{get:e[a],enumerable:!0})},C=(o,e,a,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of F(e))!I.call(o,r)&&r!==a&&p(o,r,{get:()=>e[r],enumerable:!(t=u(e,r))||t.enumerable});return o};var N=o=>C(p({},"__esModule",{value:!0}),o),g=(o,e,a,t)=>{for(var r=t>1?void 0:t?u(e,a):e,n=o.length-1,d;n>=0;n--)(d=o[n])&&(r=(t?d(e,a,r):d(r))||r);return t&&r&&p(e,a,r),r},y=(o,e)=>(a,t)=>e(a,t,o);var j={};b(j,{NftContextLoader:()=>l});module.exports=N(j);var x=require("@ledgerhq/device-management-kit"),c=require("inversify"),m=require("../../nft/di/nftTypes"),s=require("../../shared/model/ClearSignContext");var S=(n=>(n.Approve="0x095ea7b3",n.SetApprovalForAll="0xa22cb465",n.TransferFrom="0x23b872dd",n.SafeTransferFrom="0x42842e0e",n.SafeTransferFromWithData="0xb88d4fde",n))(S||{}),h=(t=>(t.SetApprovalForAll="0xa22cb465",t.SafeTransferFrom="0xf242432a",t.SafeBatchTransferFrom="0x2eb2c2d6",t))(h||{});const v=[...Object.values(S),...Object.values(h)];let l=class{_dataSource;constructor(e){this._dataSource=e}async load(e){const a=[];if(!e.to||!e.data||e.data==="0x")return[];const t=e.data.slice(0,10);if(!(0,x.isHexaString)(t))return[{type:s.ClearSignContextType.ERROR,error:new Error("Invalid selector")}];if(!this.isSelectorSupported(t))return[];const n=(await this._dataSource.getSetPluginPayload({chainId:e.chainId,address:e.to,selector:t})).caseOf({Left:i=>({type:s.ClearSignContextType.ERROR,error:i}),Right:i=>({type:s.ClearSignContextType.PLUGIN,payload:i})});if(n.type===s.ClearSignContextType.ERROR)return[n];a.push(n);const f=(await this._dataSource.getNftInfosPayload({chainId:e.chainId,address:e.to})).caseOf({Left:i=>({type:s.ClearSignContextType.ERROR,error:i}),Right:i=>({type:s.ClearSignContextType.NFT,payload:i})});return f.type===s.ClearSignContextType.ERROR?[f]:(a.push(f),a)}async loadField(e){return e.type!==s.ClearSignContextType.NFT?null:(await this._dataSource.getNftInfosPayload({address:e.address,chainId:e.chainId})).caseOf({Left:t=>({type:s.ClearSignContextType.ERROR,error:t}),Right:t=>({type:s.ClearSignContextType.NFT,payload:t})})}isSelectorSupported(e){return Object.values(v).includes(e)}};l=g([(0,c.injectable)(),y(0,(0,c.inject)(m.nftTypes.NftDataSource))],l);0&&(module.exports={NftContextLoader});
1
+ "use strict";var p=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var I=(o,e)=>{for(var r in e)p(o,r,{get:e[r],enumerable:!0})},N=(o,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of b(e))!C.call(o,a)&&a!==r&&p(o,a,{get:()=>e[a],enumerable:!(t=g(e,a))||t.enumerable});return o};var v=o=>N(p({},"__esModule",{value:!0}),o),y=(o,e,r,t)=>{for(var a=t>1?void 0:t?g(e,r):e,n=o.length-1,c;n>=0;n--)(c=o[n])&&(a=(t?c(e,r,a):c(a))||a);return t&&a&&p(e,r,a),a},x=(o,e)=>(r,t)=>e(r,t,o);var A={};I(A,{NftContextLoader:()=>l});module.exports=v(A);var m=require("@ledgerhq/device-management-kit"),d=require("inversify"),S=require("../../nft/di/nftTypes"),s=require("../../shared/model/ClearSignContext");var h=(n=>(n.Approve="0x095ea7b3",n.SetApprovalForAll="0xa22cb465",n.TransferFrom="0x23b872dd",n.SafeTransferFrom="0x42842e0e",n.SafeTransferFromWithData="0xb88d4fde",n))(h||{}),F=(t=>(t.SetApprovalForAll="0xa22cb465",t.SafeTransferFrom="0xf242432a",t.SafeBatchTransferFrom="0x2eb2c2d6",t))(F||{});const j=[...Object.values(h),...Object.values(F)];let l=class{_dataSource;constructor(e){this._dataSource=e}async load(e){const r=[],{to:t,selector:a,chainId:n}=e;if(t===void 0)return[];if(!(0,m.isHexaString)(a))return[{type:s.ClearSignContextType.ERROR,error:new Error("Invalid selector")}];if(!this.isSelectorSupported(a))return[];const f=(await this._dataSource.getSetPluginPayload({chainId:n,address:t,selector:a})).caseOf({Left:i=>({type:s.ClearSignContextType.ERROR,error:i}),Right:i=>({type:s.ClearSignContextType.PLUGIN,payload:i})});if(f.type===s.ClearSignContextType.ERROR)return[f];r.push(f);const u=(await this._dataSource.getNftInfosPayload({chainId:n,address:t})).caseOf({Left:i=>({type:s.ClearSignContextType.ERROR,error:i}),Right:i=>({type:s.ClearSignContextType.NFT,payload:i})});return u.type===s.ClearSignContextType.ERROR?[u]:(r.push(u),r)}async loadField(e){return e.type!==s.ClearSignContextType.NFT?null:(await this._dataSource.getNftInfosPayload({address:e.address,chainId:e.chainId})).caseOf({Left:t=>({type:s.ClearSignContextType.ERROR,error:t}),Right:t=>({type:s.ClearSignContextType.NFT,payload:t})})}isSelectorSupported(e){return Object.values(j).includes(e)}};l=y([(0,d.injectable)(),x(0,(0,d.inject)(S.nftTypes.NftDataSource))],l);0&&(module.exports={NftContextLoader});
2
2
  //# sourceMappingURL=NftContextLoader.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/nft/domain/NftContextLoader.ts"],
4
- "sourcesContent": ["import { HexaString, isHexaString } from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport type { NftDataSource } from \"@/nft/data/NftDataSource\";\nimport { nftTypes } from \"@/nft/di/nftTypes\";\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport {\n TransactionContext,\n TransactionFieldContext,\n} from \"@/shared/model/TransactionContext\";\n\nenum ERC721_SUPPORTED_SELECTOR {\n Approve = \"0x095ea7b3\",\n SetApprovalForAll = \"0xa22cb465\",\n TransferFrom = \"0x23b872dd\",\n SafeTransferFrom = \"0x42842e0e\",\n SafeTransferFromWithData = \"0xb88d4fde\",\n}\n\nenum ERC1155_SUPPORTED_SELECTOR {\n SetApprovalForAll = \"0xa22cb465\",\n SafeTransferFrom = \"0xf242432a\",\n SafeBatchTransferFrom = \"0x2eb2c2d6\",\n}\n\nconst SUPPORTED_SELECTORS: HexaString[] = [\n ...Object.values(ERC721_SUPPORTED_SELECTOR),\n ...Object.values(ERC1155_SUPPORTED_SELECTOR),\n];\n\n@injectable()\nexport class NftContextLoader implements ContextLoader {\n private _dataSource: NftDataSource;\n\n constructor(@inject(nftTypes.NftDataSource) dataSource: NftDataSource) {\n this._dataSource = dataSource;\n }\n\n async load(transaction: TransactionContext): Promise<ClearSignContext[]> {\n const responses: ClearSignContext[] = [];\n\n if (!transaction.to || !transaction.data || transaction.data === \"0x\") {\n return [];\n }\n\n const selector = transaction.data.slice(0, 10);\n\n if (!isHexaString(selector)) {\n return [\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Invalid selector\"),\n },\n ];\n }\n\n if (!this.isSelectorSupported(selector)) {\n return [];\n }\n\n // EXAMPLE:\n // https://nft.api.live.ledger.com/v1/ethereum/1/contracts/0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D/plugin-selector/0x095ea7b3\n const getPluginPayloadResponse = await this._dataSource.getSetPluginPayload(\n {\n chainId: transaction.chainId,\n address: transaction.to,\n selector,\n },\n );\n\n const pluginPayload = getPluginPayloadResponse.caseOf({\n Left: (error): ClearSignContext => ({\n type: ClearSignContextType.ERROR,\n error,\n }),\n Right: (value): ClearSignContext => ({\n type: ClearSignContextType.PLUGIN,\n payload: value,\n }),\n });\n\n if (pluginPayload.type === ClearSignContextType.ERROR) {\n return [pluginPayload];\n }\n\n responses.push(pluginPayload);\n\n const getNftInfosPayloadResponse =\n await this._dataSource.getNftInfosPayload({\n chainId: transaction.chainId,\n address: transaction.to,\n });\n\n const nftInfosPayload = getNftInfosPayloadResponse.caseOf({\n Left: (error): ClearSignContext => ({\n type: ClearSignContextType.ERROR,\n error,\n }),\n Right: (value): ClearSignContext => ({\n type: ClearSignContextType.NFT,\n payload: value,\n }),\n });\n\n if (nftInfosPayload.type === ClearSignContextType.ERROR) {\n return [nftInfosPayload];\n }\n\n responses.push(nftInfosPayload);\n\n return responses;\n }\n\n async loadField(\n field: TransactionFieldContext,\n ): Promise<ClearSignContext | null> {\n if (field.type !== ClearSignContextType.NFT) {\n return null;\n }\n const payload = await this._dataSource.getNftInfosPayload({\n address: field.address,\n chainId: field.chainId,\n });\n return payload.caseOf({\n Left: (error): ClearSignContext => ({\n type: ClearSignContextType.ERROR,\n error,\n }),\n Right: (value): ClearSignContext => ({\n type: ClearSignContextType.NFT,\n payload: value,\n }),\n });\n }\n\n private isSelectorSupported(selector: HexaString) {\n return Object.values(SUPPORTED_SELECTORS).includes(selector);\n }\n}\n"],
5
- "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,sBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAyC,2CACzCC,EAAmC,qBAGnCC,EAAyB,6BAEzBC,EAGO,2CAMP,IAAKC,OACHA,EAAA,QAAU,aACVA,EAAA,kBAAoB,aACpBA,EAAA,aAAe,aACfA,EAAA,iBAAmB,aACnBA,EAAA,yBAA2B,aALxBA,OAAA,IAQAC,OACHA,EAAA,kBAAoB,aACpBA,EAAA,iBAAmB,aACnBA,EAAA,sBAAwB,aAHrBA,OAAA,IAML,MAAMC,EAAoC,CACxC,GAAG,OAAO,OAAOF,CAAyB,EAC1C,GAAG,OAAO,OAAOC,CAA0B,CAC7C,EAGO,IAAME,EAAN,KAAgD,CAC7C,YAER,YAA4CC,EAA2B,CACrE,KAAK,YAAcA,CACrB,CAEA,MAAM,KAAKC,EAA8D,CACvE,MAAMC,EAAgC,CAAC,EAEvC,GAAI,CAACD,EAAY,IAAM,CAACA,EAAY,MAAQA,EAAY,OAAS,KAC/D,MAAO,CAAC,EAGV,MAAME,EAAWF,EAAY,KAAK,MAAM,EAAG,EAAE,EAE7C,GAAI,IAAC,gBAAaE,CAAQ,EACxB,MAAO,CACL,CACE,KAAM,uBAAqB,MAC3B,MAAO,IAAI,MAAM,kBAAkB,CACrC,CACF,EAGF,GAAI,CAAC,KAAK,oBAAoBA,CAAQ,EACpC,MAAO,CAAC,EAaV,MAAMC,GAR2B,MAAM,KAAK,YAAY,oBACtD,CACE,QAASH,EAAY,QACrB,QAASA,EAAY,GACrB,SAAAE,CACF,CACF,GAE+C,OAAO,CACpD,KAAOE,IAA6B,CAClC,KAAM,uBAAqB,MAC3B,MAAAA,CACF,GACA,MAAQC,IAA6B,CACnC,KAAM,uBAAqB,OAC3B,QAASA,CACX,EACF,CAAC,EAED,GAAIF,EAAc,OAAS,uBAAqB,MAC9C,MAAO,CAACA,CAAa,EAGvBF,EAAU,KAAKE,CAAa,EAQ5B,MAAMG,GALJ,MAAM,KAAK,YAAY,mBAAmB,CACxC,QAASN,EAAY,QACrB,QAASA,EAAY,EACvB,CAAC,GAEgD,OAAO,CACxD,KAAOI,IAA6B,CAClC,KAAM,uBAAqB,MAC3B,MAAAA,CACF,GACA,MAAQC,IAA6B,CACnC,KAAM,uBAAqB,IAC3B,QAASA,CACX,EACF,CAAC,EAED,OAAIC,EAAgB,OAAS,uBAAqB,MACzC,CAACA,CAAe,GAGzBL,EAAU,KAAKK,CAAe,EAEvBL,EACT,CAEA,MAAM,UACJM,EACkC,CAClC,OAAIA,EAAM,OAAS,uBAAqB,IAC/B,MAEO,MAAM,KAAK,YAAY,mBAAmB,CACxD,QAASA,EAAM,QACf,QAASA,EAAM,OACjB,CAAC,GACc,OAAO,CACpB,KAAOH,IAA6B,CAClC,KAAM,uBAAqB,MAC3B,MAAAA,CACF,GACA,MAAQC,IAA6B,CACnC,KAAM,uBAAqB,IAC3B,QAASA,CACX,EACF,CAAC,CACH,CAEQ,oBAAoBH,EAAsB,CAChD,OAAO,OAAO,OAAOL,CAAmB,EAAE,SAASK,CAAQ,CAC7D,CACF,EA3GaJ,EAANU,EAAA,IADN,cAAW,EAIGC,EAAA,eAAO,WAAS,aAAa,IAH/BX",
6
- "names": ["NftContextLoader_exports", "__export", "NftContextLoader", "__toCommonJS", "import_device_management_kit", "import_inversify", "import_nftTypes", "import_ClearSignContext", "ERC721_SUPPORTED_SELECTOR", "ERC1155_SUPPORTED_SELECTOR", "SUPPORTED_SELECTORS", "NftContextLoader", "dataSource", "transaction", "responses", "selector", "pluginPayload", "error", "value", "nftInfosPayload", "field", "__decorateClass", "__decorateParam"]
4
+ "sourcesContent": ["import { HexaString, isHexaString } from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport type { NftDataSource } from \"@/nft/data/NftDataSource\";\nimport { nftTypes } from \"@/nft/di/nftTypes\";\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport {\n TransactionContext,\n TransactionFieldContext,\n} from \"@/shared/model/TransactionContext\";\n\nenum ERC721_SUPPORTED_SELECTOR {\n Approve = \"0x095ea7b3\",\n SetApprovalForAll = \"0xa22cb465\",\n TransferFrom = \"0x23b872dd\",\n SafeTransferFrom = \"0x42842e0e\",\n SafeTransferFromWithData = \"0xb88d4fde\",\n}\n\nenum ERC1155_SUPPORTED_SELECTOR {\n SetApprovalForAll = \"0xa22cb465\",\n SafeTransferFrom = \"0xf242432a\",\n SafeBatchTransferFrom = \"0x2eb2c2d6\",\n}\n\nconst SUPPORTED_SELECTORS: HexaString[] = [\n ...Object.values(ERC721_SUPPORTED_SELECTOR),\n ...Object.values(ERC1155_SUPPORTED_SELECTOR),\n];\n\n@injectable()\nexport class NftContextLoader implements ContextLoader {\n private _dataSource: NftDataSource;\n\n constructor(@inject(nftTypes.NftDataSource) dataSource: NftDataSource) {\n this._dataSource = dataSource;\n }\n\n async load(ctx: TransactionContext): Promise<ClearSignContext[]> {\n const responses: ClearSignContext[] = [];\n\n const { to, selector, chainId } = ctx;\n if (to === undefined) {\n return [];\n }\n\n if (!isHexaString(selector)) {\n return [\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Invalid selector\"),\n },\n ];\n }\n\n if (!this.isSelectorSupported(selector)) {\n return [];\n }\n\n // EXAMPLE:\n // https://nft.api.live.ledger.com/v1/ethereum/1/contracts/0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D/plugin-selector/0x095ea7b3\n const getPluginPayloadResponse = await this._dataSource.getSetPluginPayload(\n {\n chainId,\n address: to,\n selector,\n },\n );\n\n const pluginPayload = getPluginPayloadResponse.caseOf({\n Left: (error): ClearSignContext => ({\n type: ClearSignContextType.ERROR,\n error,\n }),\n Right: (value): ClearSignContext => ({\n type: ClearSignContextType.PLUGIN,\n payload: value,\n }),\n });\n\n if (pluginPayload.type === ClearSignContextType.ERROR) {\n return [pluginPayload];\n }\n\n responses.push(pluginPayload);\n\n const getNftInfosPayloadResponse =\n await this._dataSource.getNftInfosPayload({\n chainId,\n address: to,\n });\n\n const nftInfosPayload = getNftInfosPayloadResponse.caseOf({\n Left: (error): ClearSignContext => ({\n type: ClearSignContextType.ERROR,\n error,\n }),\n Right: (value): ClearSignContext => ({\n type: ClearSignContextType.NFT,\n payload: value,\n }),\n });\n\n if (nftInfosPayload.type === ClearSignContextType.ERROR) {\n return [nftInfosPayload];\n }\n\n responses.push(nftInfosPayload);\n\n return responses;\n }\n\n async loadField(\n field: TransactionFieldContext,\n ): Promise<ClearSignContext | null> {\n if (field.type !== ClearSignContextType.NFT) {\n return null;\n }\n const payload = await this._dataSource.getNftInfosPayload({\n address: field.address,\n chainId: field.chainId,\n });\n return payload.caseOf({\n Left: (error): ClearSignContext => ({\n type: ClearSignContextType.ERROR,\n error,\n }),\n Right: (value): ClearSignContext => ({\n type: ClearSignContextType.NFT,\n payload: value,\n }),\n });\n }\n\n private isSelectorSupported(selector: HexaString) {\n return Object.values(SUPPORTED_SELECTORS).includes(selector);\n }\n}\n"],
5
+ "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,sBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAyC,2CACzCC,EAAmC,qBAGnCC,EAAyB,6BAEzBC,EAGO,2CAMP,IAAKC,OACHA,EAAA,QAAU,aACVA,EAAA,kBAAoB,aACpBA,EAAA,aAAe,aACfA,EAAA,iBAAmB,aACnBA,EAAA,yBAA2B,aALxBA,OAAA,IAQAC,OACHA,EAAA,kBAAoB,aACpBA,EAAA,i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qB,IAC/B,MAEO,MAAM,KAAK,YAAY,mBAAmB,CACxD,QAASA,EAAM,QACf,QAASA,EAAM,OACjB,CAAC,GACc,OAAO,CACpB,KAAOH,IAA6B,CAClC,KAAM,uBAAqB,MAC3B,MAAAA,CACF,GACA,MAAQC,IAA6B,CACnC,KAAM,uBAAqB,IAC3B,QAASA,CACX,EACF,CAAC,CACH,CAEQ,oBAAoBJ,EAAsB,CAChD,OAAO,OAAO,OAAON,CAAmB,EAAE,SAASM,CAAQ,CAC7D,CACF,EA1GaL,EAANY,EAAA,IADN,cAAW,EAIGC,EAAA,eAAO,WAAS,aAAa,IAH/Bb",
6
+ "names": ["NftContextLoader_exports", "__export", "NftContextLoader", "__toCommonJS", "import_device_management_kit", "import_inversify", "import_nftTypes", "import_ClearSignContext", "ERC721_SUPPORTED_SELECTOR", "ERC1155_SUPPORTED_SELECTOR", "SUPPORTED_SELECTORS", "NftContextLoader", "dataSource", "ctx", "responses", "to", "selector", "chainId", "pluginPayload", "error", "value", "nftInfosPayload", "field", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var n=require("purify-ts"),d=require("../../nft/domain/NftContextLoader"),o=require("../../shared/model/ClearSignContext");describe("NftContextLoader",()=>{const r=vi.fn(),s=vi.fn();let c,e;beforeEach(()=>{vi.restoreAllMocks(),c={getNftInfosPayload:r,getSetPluginPayload:s},e=new d.NftContextLoader(c)}),describe("load function",()=>{it("should return an empty array if no dest",async()=>{const t={to:void 0,data:"0x01"},a=await e.load(t);expect(a).toEqual([])}),it("should return an empty array if undefined data",async()=>{const t={to:"0xdAC17F958D2ee523a2206206994597C13D831ec7",data:void 0},a=await e.load(t);expect(a).toEqual([])}),it("should return an empty array if empty data",async()=>{const t={to:"0xdAC17F958D2ee523a2206206994597C13D831ec7",data:"0x"},a=await e.load(t);expect(a).toEqual([])}),it("should return an empty array if selector 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 get plugin payload return a Left",async()=>{const t={to:"0xdAC17F958D2ee523a2206206994597C13D831ec7",data:"0x095ea7b30000000000000"};s.mockResolvedValueOnce((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 an error when datasource get nft infos payload return a Left",async()=>{const t={to:"0xdAC17F958D2ee523a2206206994597C13D831ec7",data:"0x095ea7b30000000000000"};s.mockResolvedValueOnce((0,n.Right)("payload1")),r.mockResolvedValueOnce((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 response",async()=>{const t={to:"0xdAC17F958D2ee523a2206206994597C13D831ec7",data:"0x095ea7b30000000000000"};s.mockResolvedValueOnce((0,n.Right)("payload1")),r.mockResolvedValueOnce((0,n.Right)("payload2"));const a=await e.load(t);expect(a).toEqual([{type:o.ClearSignContextType.PLUGIN,payload:"payload1"},{type:o.ClearSignContextType.NFT,payload:"payload2"}])})}),describe("loadField function",()=>{it("should return an error when field type if not supported",async()=>{const t={type:o.ClearSignContextType.TOKEN,chainId:7,address:"0x1234"},a=await e.loadField(t);expect(a).toEqual(null)}),it("should return a payload",async()=>{const t={type:o.ClearSignContextType.NFT,chainId:7,address:"0x1234"};r.mockResolvedValueOnce((0,n.Right)("payload"));const a=await e.loadField(t);expect(a).toEqual({type:o.ClearSignContextType.NFT,payload:"payload"})}),it("should return an error when unable to fetch the datasource",async()=>{const t={type:o.ClearSignContextType.NFT,chainId:7,address:"0x1234"};r.mockResolvedValueOnce((0,n.Left)(new Error("error")));const a=await e.loadField(t);expect(a).toEqual({type:o.ClearSignContextType.ERROR,error:new Error("error")})})})});
1
+ "use strict";var a=require("purify-ts"),c=require("../../nft/domain/NftContextLoader"),o=require("../../shared/model/ClearSignContext");describe("NftContextLoader",()=>{const n=vi.fn(),l=vi.fn();let s,r;beforeEach(()=>{vi.restoreAllMocks(),s={getNftInfosPayload:n,getSetPluginPayload:l},r=new c.NftContextLoader(s)}),describe("load function",()=>{it("should return an empty array if no dest",async()=>{const e={to:void 0},t=await r.load(e);expect(t).toEqual([])}),it("should return an error when datasource get plugin payload return a Left",async()=>{const e={to:"0xdAC17F958D2ee523a2206206994597C13D831ec7",selector:"0x095ea7b3"};l.mockResolvedValueOnce((0,a.Left)(new Error("error")));const t=await r.load(e);expect(t).toEqual([{type:o.ClearSignContextType.ERROR,error:new Error("error")}])}),it("should return an error when datasource get nft infos payload return a Left",async()=>{const e={to:"0xdAC17F958D2ee523a2206206994597C13D831ec7",selector:"0x095ea7b3"};l.mockResolvedValueOnce((0,a.Right)("payload1")),n.mockResolvedValueOnce((0,a.Left)(new Error("error")));const t=await r.load(e);expect(t).toEqual([{type:o.ClearSignContextType.ERROR,error:new Error("error")}])}),it("should return a response",async()=>{const e={to:"0xdAC17F958D2ee523a2206206994597C13D831ec7",selector:"0x095ea7b3"};l.mockResolvedValueOnce((0,a.Right)("payload1")),n.mockResolvedValueOnce((0,a.Right)("payload2"));const t=await r.load(e);expect(t).toEqual([{type:o.ClearSignContextType.PLUGIN,payload:"payload1"},{type:o.ClearSignContextType.NFT,payload:"payload2"}])})}),describe("loadField function",()=>{it("should return an error when field type if not supported",async()=>{const e={type:o.ClearSignContextType.TOKEN,chainId:7,address:"0x1234"},t=await r.loadField(e);expect(t).toEqual(null)}),it("should return a payload",async()=>{const e={type:o.ClearSignContextType.NFT,chainId:7,address:"0x1234"};n.mockResolvedValueOnce((0,a.Right)("payload"));const t=await r.loadField(e);expect(t).toEqual({type:o.ClearSignContextType.NFT,payload:"payload"})}),it("should return an error when unable to fetch the datasource",async()=>{const e={type:o.ClearSignContextType.NFT,chainId:7,address:"0x1234"};n.mockResolvedValueOnce((0,a.Left)(new Error("error")));const t=await r.loadField(e);expect(t).toEqual({type:o.ClearSignContextType.ERROR,error:new Error("error")})})})});
2
2
  //# sourceMappingURL=NftContextLoader.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/nft/domain/NftContextLoader.test.ts"],
4
- "sourcesContent": ["import { Left, Right } from \"purify-ts\";\n\nimport { type NftDataSource } from \"@/nft/data/NftDataSource\";\nimport { NftContextLoader } from \"@/nft/domain/NftContextLoader\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport {\n type TransactionContext,\n type TransactionFieldContext,\n} from \"@/shared/model/TransactionContext\";\n\ndescribe(\"NftContextLoader\", () => {\n const spyGetNftInfosPayload = vi.fn();\n const spyGetPluginPayload = vi.fn();\n let mockDataSource: NftDataSource;\n let loader: NftContextLoader;\n\n beforeEach(() => {\n vi.restoreAllMocks();\n mockDataSource = {\n getNftInfosPayload: spyGetNftInfosPayload,\n getSetPluginPayload: spyGetPluginPayload,\n };\n loader = new NftContextLoader(mockDataSource);\n });\n\n describe(\"load function\", () => {\n it(\"should return an empty array if no dest\", async () => {\n const transaction = { to: undefined, data: \"0x01\" } as TransactionContext;\n\n const result = await loader.load(transaction);\n\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if undefined data\", async () => {\n const transaction = {\n to: \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n data: undefined,\n } as unknown as TransactionContext;\n\n const result = await loader.load(transaction);\n\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if empty data\", async () => {\n const transaction = {\n to: \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n data: \"0x\",\n } as unknown as TransactionContext;\n\n const result = await loader.load(transaction);\n\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if selector not supported\", async () => {\n const transaction = {\n to: \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n data: \"0x095ea7b20000000000000\",\n } as unknown as TransactionContext;\n\n const result = await loader.load(transaction);\n\n expect(result).toEqual([]);\n });\n\n it(\"should return an error when transaction data is not a valid hex string\", async () => {\n const transaction = {\n to: \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n data: \"notahexstring\",\n } as TransactionContext;\n\n const result = await loader.load(transaction);\n\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 get plugin payload return a Left\", async () => {\n const transaction = {\n to: \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n data: \"0x095ea7b30000000000000\",\n } as TransactionContext;\n spyGetPluginPayload.mockResolvedValueOnce(Left(new Error(\"error\")));\n\n const result = await loader.load(transaction);\n\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n ]);\n });\n\n it(\"should return an error when datasource get nft infos payload return a Left\", async () => {\n const transaction = {\n to: \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n data: \"0x095ea7b30000000000000\",\n } as TransactionContext;\n spyGetPluginPayload.mockResolvedValueOnce(Right(\"payload1\"));\n spyGetNftInfosPayload.mockResolvedValueOnce(Left(new Error(\"error\")));\n\n const result = await loader.load(transaction);\n\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n ]);\n });\n\n it(\"should return a response\", async () => {\n const transaction = {\n to: \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n data: \"0x095ea7b30000000000000\",\n } as TransactionContext;\n spyGetPluginPayload.mockResolvedValueOnce(Right(\"payload1\"));\n spyGetNftInfosPayload.mockResolvedValueOnce(Right(\"payload2\"));\n\n const result = await loader.load(transaction);\n\n expect(result).toEqual([\n {\n type: ClearSignContextType.PLUGIN,\n payload: \"payload1\",\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload2\",\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.TOKEN,\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.NFT,\n chainId: 7,\n address: \"0x1234\",\n };\n\n // WHEN\n spyGetNftInfosPayload.mockResolvedValueOnce(Right(\"payload\"));\n const result = await loader.loadField(field);\n\n // THEN\n expect(result).toEqual({\n type: ClearSignContextType.NFT,\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.NFT,\n chainId: 7,\n address: \"0x1234\",\n };\n\n // WHEN\n spyGetNftInfosPayload.mockResolvedValueOnce(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,qBAG5BC,EAAiC,yCACjCC,EAAqC,2CAMrC,SAAS,mBAAoB,IAAM,CACjC,MAAMC,EAAwB,GAAG,GAAG,EAC9BC,EAAsB,GAAG,GAAG,EAClC,IAAIC,EACAC,EAEJ,WAAW,IAAM,CACf,GAAG,gBAAgB,EACnBD,EAAiB,CACf,mBAAoBF,EACpB,oBAAqBC,CACvB,EACAE,EAAS,IAAI,mBAAiBD,CAAc,CAC9C,CAAC,EAED,SAAS,gBAAiB,IAAM,CAC9B,GAAG,0CAA2C,SAAY,CACxD,MAAME,EAAc,CAAE,GAAI,OAAW,KAAM,MAAO,EAE5CC,EAAS,MAAMF,EAAO,KAAKC,CAAW,EAE5C,OAAOC,CAAM,EAAE,QAAQ,CAAC,CAAC,CAC3B,CAAC,EAED,GAAG,iDAAkD,SAAY,CAC/D,MAAMD,EAAc,CAClB,GAAI,6CACJ,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AC1B,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
4
+ "sourcesContent": ["import { Left, Right } from \"purify-ts\";\n\nimport { type NftDataSource } from \"@/nft/data/NftDataSource\";\nimport { NftContextLoader } from \"@/nft/domain/NftContextLoader\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport {\n type TransactionContext,\n type TransactionFieldContext,\n} from \"@/shared/model/TransactionContext\";\n\ndescribe(\"NftContextLoader\", () => {\n const spyGetNftInfosPayload = vi.fn();\n const spyGetPluginPayload = vi.fn();\n let mockDataSource: NftDataSource;\n let loader: NftContextLoader;\n\n beforeEach(() => {\n vi.restoreAllMocks();\n mockDataSource = {\n getNftInfosPayload: spyGetNftInfosPayload,\n getSetPluginPayload: spyGetPluginPayload,\n };\n loader = new NftContextLoader(mockDataSource);\n });\n\n describe(\"load function\", () => {\n it(\"should return an empty array if no dest\", async () => {\n const transaction = { to: undefined } as TransactionContext;\n\n const result = await loader.load(transaction);\n\n expect(result).toEqual([]);\n });\n\n it(\"should return an error when datasource get plugin payload return a Left\", async () => {\n const transaction = {\n to: \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n selector: \"0x095ea7b3\",\n } as TransactionContext;\n spyGetPluginPayload.mockResolvedValueOnce(Left(new Error(\"error\")));\n\n const result = await loader.load(transaction);\n\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n ]);\n });\n\n it(\"should return an error when datasource get nft infos payload return a Left\", async () => {\n const transaction = {\n to: \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n selector: \"0x095ea7b3\",\n } as TransactionContext;\n spyGetPluginPayload.mockResolvedValueOnce(Right(\"payload1\"));\n spyGetNftInfosPayload.mockResolvedValueOnce(Left(new Error(\"error\")));\n\n const result = await loader.load(transaction);\n\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n ]);\n });\n\n it(\"should return a response\", async () => {\n const transaction = {\n to: \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n selector: \"0x095ea7b3\",\n } as TransactionContext;\n spyGetPluginPayload.mockResolvedValueOnce(Right(\"payload1\"));\n spyGetNftInfosPayload.mockResolvedValueOnce(Right(\"payload2\"));\n\n const result = await loader.load(transaction);\n\n expect(result).toEqual([\n {\n type: ClearSignContextType.PLUGIN,\n payload: \"payload1\",\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload2\",\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.TOKEN,\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.NFT,\n chainId: 7,\n address: \"0x1234\",\n };\n\n // WHEN\n spyGetNftInfosPayload.mockResolvedValueOnce(Right(\"payload\"));\n const result = await loader.loadField(field);\n\n // THEN\n expect(result).toEqual({\n type: ClearSignContextType.NFT,\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.NFT,\n chainId: 7,\n address: \"0x1234\",\n };\n\n // WHEN\n spyGetNftInfosPayload.mockResolvedValueOnce(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,qBAG5BC,EAAiC,yCACjCC,EAAqC,2CAMrC,SAAS,mBAAoB,IAAM,CACjC,MAAMC,EAAwB,GAAG,GAAG,EAC9BC,EAAsB,GAAG,GAAG,EAClC,IAAIC,EACAC,EAEJ,WAAW,IAAM,CACf,GAAG,gBAAgB,EACnBD,EAAiB,CACf,mBAAoBF,EACpB,oBAAqBC,C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CAAC,EAED,SAAS,qBAAsB,IAAM,CACnC,GAAG,0DAA2D,SAAY,CACxE,MAAMC,EAAiC,CACrC,KAAM,uBAAqB,MAC3B,QAAS,EACT,QAAS,QACX,EAEMD,EAAS,MAAMF,EAAO,UAAUG,CAAK,EAE3C,OAAOD,CAAM,EAAE,QAAQ,IAAI,CAC7B,CAAC,EAED,GAAG,0BAA2B,SAAY,CAExC,MAAMC,EAAiC,CACrC,KAAM,uBAAqB,IAC3B,QAAS,EACT,QAAS,QACX,EAGAN,EAAsB,yBAAsB,SAAM,SAAS,CAAC,EAC5D,MAAMK,EAAS,MAAMF,EAAO,UAAUG,CAAK,EAG3C,OAAOD,CAAM,EAAE,QAAQ,CACrB,KAAM,uBAAqB,IAC3B,QAAS,SACX,CAAC,CACH,CAAC,EAED,GAAG,6DAA8D,SAAY,CAE3E,MAAMC,EAAiC,CACrC,KAAM,uBAAqB,IAC3B,QAAS,EACT,QAAS,QACX,EAGAN,EAAsB,yBAAsB,QAAK,IAAI,MAAM,OAAO,CAAC,CAAC,EACpE,MAAMK,EAAS,MAAMF,EAAO,UAAUG,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_NftContextLoader", "import_ClearSignContext", "spyGetNftInfosPayload", "spyGetPluginPayload", "mockDataSource", "loader", "transaction", "result", "field"]
7
7
  }