@ledgerhq/context-module 1.15.0 → 1.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (410) hide show
  1. package/README.md +10 -0
  2. package/lib/cjs/package.json +1 -2
  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/account-ownership/data/AccountOwnershipDataSource.js +2 -0
  14. package/lib/cjs/src/account-ownership/data/AccountOwnershipDataSource.js.map +7 -0
  15. package/lib/cjs/src/account-ownership/data/AccountOwnershipError.js +2 -0
  16. package/lib/cjs/src/account-ownership/data/AccountOwnershipError.js.map +7 -0
  17. package/lib/cjs/src/account-ownership/data/HttpAccountOwnershipDataSource.js +2 -0
  18. package/lib/cjs/src/account-ownership/data/HttpAccountOwnershipDataSource.js.map +7 -0
  19. package/lib/cjs/src/account-ownership/data/HttpAccountOwnershipDataSource.test.js +2 -0
  20. package/lib/cjs/src/account-ownership/data/HttpAccountOwnershipDataSource.test.js.map +7 -0
  21. package/lib/cjs/src/account-ownership/data/dto/AccountOwnershipDto.js +2 -0
  22. package/lib/cjs/src/account-ownership/data/dto/AccountOwnershipDto.js.map +7 -0
  23. package/lib/cjs/src/account-ownership/di/accountOwnershipModuleFactory.js +2 -0
  24. package/lib/cjs/src/account-ownership/di/accountOwnershipModuleFactory.js.map +7 -0
  25. package/lib/cjs/src/account-ownership/di/accountOwnershipTypes.js +2 -0
  26. package/lib/cjs/src/account-ownership/di/accountOwnershipTypes.js.map +7 -0
  27. package/lib/cjs/src/account-ownership/domain/AccountOwnershipContextLoader.js +2 -0
  28. package/lib/cjs/src/account-ownership/domain/AccountOwnershipContextLoader.js.map +7 -0
  29. package/lib/cjs/src/account-ownership/domain/AccountOwnershipContextLoader.test.js +2 -0
  30. package/lib/cjs/src/account-ownership/domain/AccountOwnershipContextLoader.test.js.map +7 -0
  31. package/lib/cjs/src/calldata/data/HttpCalldataDescriptorDataSource.js +1 -1
  32. package/lib/cjs/src/calldata/data/HttpCalldataDescriptorDataSource.js.map +3 -3
  33. package/lib/cjs/src/calldata/data/HttpCalldataDescriptorDataSource.test.js +1 -1
  34. package/lib/cjs/src/calldata/data/HttpCalldataDescriptorDataSource.test.js.map +3 -3
  35. package/lib/cjs/src/calldata/di/calldataModuleFactory.js +1 -1
  36. package/lib/cjs/src/calldata/di/calldataModuleFactory.js.map +3 -3
  37. package/lib/cjs/src/config/di/configModuleFactory.js +1 -1
  38. package/lib/cjs/src/config/di/configModuleFactory.js.map +2 -2
  39. package/lib/cjs/src/config/model/ContextModuleConfig.js +1 -1
  40. package/lib/cjs/src/config/model/ContextModuleConfig.js.map +1 -1
  41. package/lib/cjs/src/di.js +1 -1
  42. package/lib/cjs/src/di.js.map +3 -3
  43. package/lib/cjs/src/dynamic-network/data/HttpDynamicNetworkDataSource.js +1 -1
  44. package/lib/cjs/src/dynamic-network/data/HttpDynamicNetworkDataSource.js.map +3 -3
  45. package/lib/cjs/src/dynamic-network/data/HttpDynamicNetworkDataSource.test.js +1 -1
  46. package/lib/cjs/src/dynamic-network/data/HttpDynamicNetworkDataSource.test.js.map +3 -3
  47. package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.js +1 -1
  48. package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.js.map +1 -1
  49. package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js.map +1 -1
  50. package/lib/cjs/src/external-plugin/data/HttpExternalPluginDataSource.js +1 -1
  51. package/lib/cjs/src/external-plugin/data/HttpExternalPluginDataSource.js.map +3 -3
  52. package/lib/cjs/src/external-plugin/data/HttpExternalPluginDataSource.test.js +1 -1
  53. package/lib/cjs/src/external-plugin/data/HttpExternalPluginDataSource.test.js.map +3 -3
  54. package/lib/cjs/src/gated-signing/data/HttpGatedDescriptorDataSource.js +1 -1
  55. package/lib/cjs/src/gated-signing/data/HttpGatedDescriptorDataSource.js.map +3 -3
  56. package/lib/cjs/src/gated-signing/data/HttpGatedDescriptorDataSource.test.js +1 -1
  57. package/lib/cjs/src/gated-signing/data/HttpGatedDescriptorDataSource.test.js.map +3 -3
  58. package/lib/cjs/src/index.js +1 -1
  59. package/lib/cjs/src/index.js.map +2 -2
  60. package/lib/cjs/src/network/di/networkModuleFactory.js +2 -0
  61. package/lib/cjs/src/network/di/networkModuleFactory.js.map +7 -0
  62. package/lib/cjs/src/network/di/networkTypes.js +2 -0
  63. package/lib/cjs/src/network/di/networkTypes.js.map +7 -0
  64. package/lib/cjs/src/nft/data/HttpNftDataSource.js +1 -1
  65. package/lib/cjs/src/nft/data/HttpNftDataSource.js.map +3 -3
  66. package/lib/cjs/src/nft/data/HttpNftDataSource.test.js +1 -1
  67. package/lib/cjs/src/nft/data/HttpNftDataSource.test.js.map +3 -3
  68. package/lib/cjs/src/pki/data/HttpPkiCertificateDataSource.js +1 -1
  69. package/lib/cjs/src/pki/data/HttpPkiCertificateDataSource.js.map +3 -3
  70. package/lib/cjs/src/pki/data/HttpPkiCertificateDataSource.test.js +1 -1
  71. package/lib/cjs/src/pki/data/HttpPkiCertificateDataSource.test.js.map +3 -3
  72. package/lib/cjs/src/proxy/data/HttpProxyDataSource.js +1 -1
  73. package/lib/cjs/src/proxy/data/HttpProxyDataSource.js.map +3 -3
  74. package/lib/cjs/src/proxy/data/HttpProxyDataSource.test.js +1 -1
  75. package/lib/cjs/src/proxy/data/HttpProxyDataSource.test.js.map +3 -3
  76. package/lib/cjs/src/proxy/data/HttpSafeProxyDataSource.js +1 -1
  77. package/lib/cjs/src/proxy/data/HttpSafeProxyDataSource.js.map +3 -3
  78. package/lib/cjs/src/proxy/data/HttpSafeProxyDataSource.test.js +1 -1
  79. package/lib/cjs/src/proxy/data/HttpSafeProxyDataSource.test.js.map +3 -3
  80. package/lib/cjs/src/proxy/di/proxyModuleFactory.js +1 -1
  81. package/lib/cjs/src/proxy/di/proxyModuleFactory.js.map +3 -3
  82. package/lib/cjs/src/proxy/di/proxyModuleFactory.test.js +1 -1
  83. package/lib/cjs/src/proxy/di/proxyModuleFactory.test.js.map +3 -3
  84. package/lib/cjs/src/reporter/data/BlindSigningReporterDatasource.js +2 -0
  85. package/lib/cjs/src/reporter/data/BlindSigningReporterDatasource.js.map +7 -0
  86. package/lib/cjs/src/reporter/data/HttpBlindSigningReporterDatasource.js +2 -0
  87. package/lib/cjs/src/reporter/data/HttpBlindSigningReporterDatasource.js.map +7 -0
  88. package/lib/cjs/src/reporter/data/HttpBlindSigningReporterDatasource.test.js +2 -0
  89. package/lib/cjs/src/reporter/data/HttpBlindSigningReporterDatasource.test.js.map +7 -0
  90. package/lib/cjs/src/reporter/data/dto/BlindSigningEventDto.js +2 -0
  91. package/lib/cjs/src/reporter/data/dto/BlindSigningEventDto.js.map +7 -0
  92. package/lib/cjs/src/reporter/di/reporterModuleFactory.js +2 -0
  93. package/lib/cjs/src/reporter/di/reporterModuleFactory.js.map +7 -0
  94. package/lib/cjs/src/reporter/di/reporterTypes.js +2 -0
  95. package/lib/cjs/src/reporter/di/reporterTypes.js.map +7 -0
  96. package/lib/cjs/src/reporter/domain/BlindSigningReporter.js +2 -0
  97. package/lib/cjs/src/reporter/domain/BlindSigningReporter.js.map +7 -0
  98. package/lib/cjs/src/reporter/domain/DefaultBlindSigningReporter.js +2 -0
  99. package/lib/cjs/src/reporter/domain/DefaultBlindSigningReporter.js.map +7 -0
  100. package/lib/cjs/src/reporter/domain/DefaultBlindSigningReporter.test.js +2 -0
  101. package/lib/cjs/src/reporter/domain/DefaultBlindSigningReporter.test.js.map +7 -0
  102. package/lib/cjs/src/reporter/model/BlindSigningEvent.js +2 -0
  103. package/lib/cjs/src/reporter/model/BlindSigningEvent.js.map +7 -0
  104. package/lib/cjs/src/reporter/model/BlindSigningModelId.js +2 -0
  105. package/lib/cjs/src/reporter/model/BlindSigningModelId.js.map +7 -0
  106. package/lib/cjs/src/safe/data/HttpSafeAccountDataSource.js +1 -1
  107. package/lib/cjs/src/safe/data/HttpSafeAccountDataSource.js.map +3 -3
  108. package/lib/cjs/src/safe/data/HttpSafeAccountDataSource.test.js +1 -1
  109. package/lib/cjs/src/safe/data/HttpSafeAccountDataSource.test.js.map +3 -3
  110. package/lib/cjs/src/shared/model/ClearSignContext.js +1 -1
  111. package/lib/cjs/src/shared/model/ClearSignContext.js.map +2 -2
  112. package/lib/cjs/src/solana/data/HttpSolanaOwnerInfoDataSource.js +1 -1
  113. package/lib/cjs/src/solana/data/HttpSolanaOwnerInfoDataSource.js.map +3 -3
  114. package/lib/cjs/src/solana/data/HttpSolanaOwnerInfoDataSource.test.js +1 -1
  115. package/lib/cjs/src/solana/data/HttpSolanaOwnerInfoDataSource.test.js.map +3 -3
  116. package/lib/cjs/src/solana/domain/DefaultSolanaContextLoader.test.js +1 -1
  117. package/lib/cjs/src/solana/domain/DefaultSolanaContextLoader.test.js.map +1 -1
  118. package/lib/cjs/src/solanaLifi/data/HttpSolanaLifiDataSource.js +1 -1
  119. package/lib/cjs/src/solanaLifi/data/HttpSolanaLifiDataSource.js.map +3 -3
  120. package/lib/cjs/src/solanaLifi/data/HttpSolanaLifiDataSource.test.js +1 -1
  121. package/lib/cjs/src/solanaLifi/data/HttpSolanaLifiDataSource.test.js.map +3 -3
  122. package/lib/cjs/src/solanaLifi/domain/SolanaLifiContextLoader.js.map +1 -1
  123. package/lib/cjs/src/solanaLifi/domain/SolanaLifiContextLoader.test.js.map +1 -1
  124. package/lib/cjs/src/solanaToken/data/HttpSolanaTokenDataSource.js +1 -1
  125. package/lib/cjs/src/solanaToken/data/HttpSolanaTokenDataSource.js.map +3 -3
  126. package/lib/cjs/src/solanaToken/data/HttpSolanaTokenDataSource.test.js +6 -6
  127. package/lib/cjs/src/solanaToken/data/HttpSolanaTokenDataSource.test.js.map +3 -3
  128. package/lib/cjs/src/solanaToken/domain/SolanaTokenContextLoader.js +1 -1
  129. package/lib/cjs/src/solanaToken/domain/SolanaTokenContextLoader.js.map +2 -2
  130. package/lib/cjs/src/solanaToken/domain/SolanaTokenContextLoader.test.js +1 -1
  131. package/lib/cjs/src/solanaToken/domain/SolanaTokenContextLoader.test.js.map +1 -1
  132. package/lib/cjs/src/token/data/HttpTokenDataSource.js +1 -1
  133. package/lib/cjs/src/token/data/HttpTokenDataSource.js.map +3 -3
  134. package/lib/cjs/src/token/data/HttpTokenDataSource.test.js +1 -1
  135. package/lib/cjs/src/token/data/HttpTokenDataSource.test.js.map +3 -3
  136. package/lib/cjs/src/transaction-check/data/HttpTransactionCheckDataSource.js +1 -1
  137. package/lib/cjs/src/transaction-check/data/HttpTransactionCheckDataSource.js.map +3 -3
  138. package/lib/cjs/src/transaction-check/data/HttpTransactionCheckDataSource.test.js +1 -1
  139. package/lib/cjs/src/transaction-check/data/HttpTransactionCheckDataSource.test.js.map +3 -3
  140. package/lib/cjs/src/transaction-check/data/HttpTypedDataCheckDataSource.js +1 -1
  141. package/lib/cjs/src/transaction-check/data/HttpTypedDataCheckDataSource.js.map +3 -3
  142. package/lib/cjs/src/transaction-check/data/HttpTypedDataCheckDataSource.test.js +1 -1
  143. package/lib/cjs/src/transaction-check/data/HttpTypedDataCheckDataSource.test.js.map +3 -3
  144. package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.js +1 -1
  145. package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.js.map +3 -3
  146. package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.test.js +1 -1
  147. package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.test.js.map +3 -3
  148. package/lib/cjs/src/trusted-name/di/trustedNameModuleFactory.js +1 -1
  149. package/lib/cjs/src/trusted-name/di/trustedNameModuleFactory.js.map +3 -3
  150. package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.js +1 -1
  151. package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.js.map +3 -3
  152. package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.test.js +1 -1
  153. package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.test.js.map +3 -3
  154. package/lib/esm/package.json +1 -2
  155. package/lib/esm/src/ContextModuleBuilder.js +1 -1
  156. package/lib/esm/src/ContextModuleBuilder.js.map +3 -3
  157. package/lib/esm/src/ContextModuleBuilder.test.js +1 -1
  158. package/lib/esm/src/ContextModuleBuilder.test.js.map +3 -3
  159. package/lib/esm/src/DefaultContextModule.js +1 -1
  160. package/lib/esm/src/DefaultContextModule.js.map +3 -3
  161. package/lib/esm/src/DefaultContextModule.test.js +1 -1
  162. package/lib/esm/src/DefaultContextModule.test.js.map +2 -2
  163. package/lib/esm/src/account-ownership/data/AccountOwnershipDataSource.js +1 -0
  164. package/lib/esm/src/account-ownership/data/AccountOwnershipDataSource.js.map +7 -0
  165. package/lib/esm/src/account-ownership/data/AccountOwnershipError.js +2 -0
  166. package/lib/esm/src/account-ownership/data/AccountOwnershipError.js.map +7 -0
  167. package/lib/esm/src/account-ownership/data/HttpAccountOwnershipDataSource.js +2 -0
  168. package/lib/esm/src/account-ownership/data/HttpAccountOwnershipDataSource.js.map +7 -0
  169. package/lib/esm/src/account-ownership/data/HttpAccountOwnershipDataSource.test.js +2 -0
  170. package/lib/esm/src/account-ownership/data/HttpAccountOwnershipDataSource.test.js.map +7 -0
  171. package/lib/esm/src/account-ownership/data/dto/AccountOwnershipDto.js +1 -0
  172. package/lib/esm/src/account-ownership/data/dto/AccountOwnershipDto.js.map +7 -0
  173. package/lib/esm/src/account-ownership/di/accountOwnershipModuleFactory.js +2 -0
  174. package/lib/esm/src/account-ownership/di/accountOwnershipModuleFactory.js.map +7 -0
  175. package/lib/esm/src/account-ownership/di/accountOwnershipTypes.js +2 -0
  176. package/lib/esm/src/account-ownership/di/accountOwnershipTypes.js.map +7 -0
  177. package/lib/esm/src/account-ownership/domain/AccountOwnershipContextLoader.js +2 -0
  178. package/lib/esm/src/account-ownership/domain/AccountOwnershipContextLoader.js.map +7 -0
  179. package/lib/esm/src/account-ownership/domain/AccountOwnershipContextLoader.test.js +2 -0
  180. package/lib/esm/src/account-ownership/domain/AccountOwnershipContextLoader.test.js.map +7 -0
  181. package/lib/esm/src/calldata/data/HttpCalldataDescriptorDataSource.js +1 -1
  182. package/lib/esm/src/calldata/data/HttpCalldataDescriptorDataSource.js.map +3 -3
  183. package/lib/esm/src/calldata/data/HttpCalldataDescriptorDataSource.test.js +1 -1
  184. package/lib/esm/src/calldata/data/HttpCalldataDescriptorDataSource.test.js.map +3 -3
  185. package/lib/esm/src/calldata/di/calldataModuleFactory.js +1 -1
  186. package/lib/esm/src/calldata/di/calldataModuleFactory.js.map +3 -3
  187. package/lib/esm/src/config/di/configModuleFactory.js +1 -1
  188. package/lib/esm/src/config/di/configModuleFactory.js.map +2 -2
  189. package/lib/esm/src/di.js +1 -1
  190. package/lib/esm/src/di.js.map +3 -3
  191. package/lib/esm/src/dynamic-network/data/HttpDynamicNetworkDataSource.js +1 -1
  192. package/lib/esm/src/dynamic-network/data/HttpDynamicNetworkDataSource.js.map +3 -3
  193. package/lib/esm/src/dynamic-network/data/HttpDynamicNetworkDataSource.test.js +1 -1
  194. package/lib/esm/src/dynamic-network/data/HttpDynamicNetworkDataSource.test.js.map +3 -3
  195. package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.js +1 -1
  196. package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.js.map +1 -1
  197. package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js.map +1 -1
  198. package/lib/esm/src/external-plugin/data/HttpExternalPluginDataSource.js +1 -1
  199. package/lib/esm/src/external-plugin/data/HttpExternalPluginDataSource.js.map +3 -3
  200. package/lib/esm/src/external-plugin/data/HttpExternalPluginDataSource.test.js +1 -1
  201. package/lib/esm/src/external-plugin/data/HttpExternalPluginDataSource.test.js.map +3 -3
  202. package/lib/esm/src/gated-signing/data/HttpGatedDescriptorDataSource.js +1 -1
  203. package/lib/esm/src/gated-signing/data/HttpGatedDescriptorDataSource.js.map +3 -3
  204. package/lib/esm/src/gated-signing/data/HttpGatedDescriptorDataSource.test.js +1 -1
  205. package/lib/esm/src/gated-signing/data/HttpGatedDescriptorDataSource.test.js.map +3 -3
  206. package/lib/esm/src/index.js +1 -1
  207. package/lib/esm/src/index.js.map +2 -2
  208. package/lib/esm/src/network/di/networkModuleFactory.js +2 -0
  209. package/lib/esm/src/network/di/networkModuleFactory.js.map +7 -0
  210. package/lib/esm/src/network/di/networkTypes.js +2 -0
  211. package/lib/esm/src/network/di/networkTypes.js.map +7 -0
  212. package/lib/esm/src/nft/data/HttpNftDataSource.js +1 -1
  213. package/lib/esm/src/nft/data/HttpNftDataSource.js.map +3 -3
  214. package/lib/esm/src/nft/data/HttpNftDataSource.test.js +1 -1
  215. package/lib/esm/src/nft/data/HttpNftDataSource.test.js.map +3 -3
  216. package/lib/esm/src/pki/data/HttpPkiCertificateDataSource.js +1 -1
  217. package/lib/esm/src/pki/data/HttpPkiCertificateDataSource.js.map +3 -3
  218. package/lib/esm/src/pki/data/HttpPkiCertificateDataSource.test.js +1 -1
  219. package/lib/esm/src/pki/data/HttpPkiCertificateDataSource.test.js.map +3 -3
  220. package/lib/esm/src/proxy/data/HttpProxyDataSource.js +1 -1
  221. package/lib/esm/src/proxy/data/HttpProxyDataSource.js.map +3 -3
  222. package/lib/esm/src/proxy/data/HttpProxyDataSource.test.js +1 -1
  223. package/lib/esm/src/proxy/data/HttpProxyDataSource.test.js.map +3 -3
  224. package/lib/esm/src/proxy/data/HttpSafeProxyDataSource.js +1 -1
  225. package/lib/esm/src/proxy/data/HttpSafeProxyDataSource.js.map +3 -3
  226. package/lib/esm/src/proxy/data/HttpSafeProxyDataSource.test.js +1 -1
  227. package/lib/esm/src/proxy/data/HttpSafeProxyDataSource.test.js.map +3 -3
  228. package/lib/esm/src/proxy/di/proxyModuleFactory.js +1 -1
  229. package/lib/esm/src/proxy/di/proxyModuleFactory.js.map +3 -3
  230. package/lib/esm/src/proxy/di/proxyModuleFactory.test.js +1 -1
  231. package/lib/esm/src/proxy/di/proxyModuleFactory.test.js.map +3 -3
  232. package/lib/esm/src/reporter/data/BlindSigningReporterDatasource.js +1 -0
  233. package/lib/esm/src/reporter/data/BlindSigningReporterDatasource.js.map +7 -0
  234. package/lib/esm/src/reporter/data/HttpBlindSigningReporterDatasource.js +2 -0
  235. package/lib/esm/src/reporter/data/HttpBlindSigningReporterDatasource.js.map +7 -0
  236. package/lib/esm/src/reporter/data/HttpBlindSigningReporterDatasource.test.js +2 -0
  237. package/lib/esm/src/reporter/data/HttpBlindSigningReporterDatasource.test.js.map +7 -0
  238. package/lib/esm/src/reporter/data/dto/BlindSigningEventDto.js +1 -0
  239. package/lib/esm/src/reporter/data/dto/BlindSigningEventDto.js.map +7 -0
  240. package/lib/esm/src/reporter/di/reporterModuleFactory.js +2 -0
  241. package/lib/esm/src/reporter/di/reporterModuleFactory.js.map +7 -0
  242. package/lib/esm/src/reporter/di/reporterTypes.js +2 -0
  243. package/lib/esm/src/reporter/di/reporterTypes.js.map +7 -0
  244. package/lib/esm/src/reporter/domain/BlindSigningReporter.js +1 -0
  245. package/lib/esm/src/reporter/domain/BlindSigningReporter.js.map +7 -0
  246. package/lib/esm/src/reporter/domain/DefaultBlindSigningReporter.js +2 -0
  247. package/lib/esm/src/reporter/domain/DefaultBlindSigningReporter.js.map +7 -0
  248. package/lib/esm/src/reporter/domain/DefaultBlindSigningReporter.test.js +2 -0
  249. package/lib/esm/src/reporter/domain/DefaultBlindSigningReporter.test.js.map +7 -0
  250. package/lib/esm/src/reporter/model/BlindSigningEvent.js +2 -0
  251. package/lib/esm/src/reporter/model/BlindSigningEvent.js.map +7 -0
  252. package/lib/esm/src/reporter/model/BlindSigningModelId.js +2 -0
  253. package/lib/esm/src/reporter/model/BlindSigningModelId.js.map +7 -0
  254. package/lib/esm/src/safe/data/HttpSafeAccountDataSource.js +1 -1
  255. package/lib/esm/src/safe/data/HttpSafeAccountDataSource.js.map +3 -3
  256. package/lib/esm/src/safe/data/HttpSafeAccountDataSource.test.js +1 -1
  257. package/lib/esm/src/safe/data/HttpSafeAccountDataSource.test.js.map +3 -3
  258. package/lib/esm/src/shared/model/ClearSignContext.js +1 -1
  259. package/lib/esm/src/shared/model/ClearSignContext.js.map +2 -2
  260. package/lib/esm/src/solana/data/HttpSolanaOwnerInfoDataSource.js +1 -1
  261. package/lib/esm/src/solana/data/HttpSolanaOwnerInfoDataSource.js.map +3 -3
  262. package/lib/esm/src/solana/data/HttpSolanaOwnerInfoDataSource.test.js +1 -1
  263. package/lib/esm/src/solana/data/HttpSolanaOwnerInfoDataSource.test.js.map +3 -3
  264. package/lib/esm/src/solana/domain/DefaultSolanaContextLoader.test.js +1 -1
  265. package/lib/esm/src/solana/domain/DefaultSolanaContextLoader.test.js.map +1 -1
  266. package/lib/esm/src/solanaLifi/data/HttpSolanaLifiDataSource.js +1 -1
  267. package/lib/esm/src/solanaLifi/data/HttpSolanaLifiDataSource.js.map +3 -3
  268. package/lib/esm/src/solanaLifi/data/HttpSolanaLifiDataSource.test.js +1 -1
  269. package/lib/esm/src/solanaLifi/data/HttpSolanaLifiDataSource.test.js.map +3 -3
  270. package/lib/esm/src/solanaLifi/domain/SolanaLifiContextLoader.js.map +1 -1
  271. package/lib/esm/src/solanaLifi/domain/SolanaLifiContextLoader.test.js +1 -1
  272. package/lib/esm/src/solanaLifi/domain/SolanaLifiContextLoader.test.js.map +1 -1
  273. package/lib/esm/src/solanaToken/data/HttpSolanaTokenDataSource.js +1 -1
  274. package/lib/esm/src/solanaToken/data/HttpSolanaTokenDataSource.js.map +3 -3
  275. package/lib/esm/src/solanaToken/data/HttpSolanaTokenDataSource.test.js +6 -6
  276. package/lib/esm/src/solanaToken/data/HttpSolanaTokenDataSource.test.js.map +3 -3
  277. package/lib/esm/src/solanaToken/domain/SolanaTokenContextLoader.js +1 -1
  278. package/lib/esm/src/solanaToken/domain/SolanaTokenContextLoader.js.map +2 -2
  279. package/lib/esm/src/solanaToken/domain/SolanaTokenContextLoader.test.js +1 -1
  280. package/lib/esm/src/solanaToken/domain/SolanaTokenContextLoader.test.js.map +1 -1
  281. package/lib/esm/src/token/data/HttpTokenDataSource.js +1 -1
  282. package/lib/esm/src/token/data/HttpTokenDataSource.js.map +3 -3
  283. package/lib/esm/src/token/data/HttpTokenDataSource.test.js +1 -1
  284. package/lib/esm/src/token/data/HttpTokenDataSource.test.js.map +3 -3
  285. package/lib/esm/src/transaction-check/data/HttpTransactionCheckDataSource.js +1 -1
  286. package/lib/esm/src/transaction-check/data/HttpTransactionCheckDataSource.js.map +3 -3
  287. package/lib/esm/src/transaction-check/data/HttpTransactionCheckDataSource.test.js +1 -1
  288. package/lib/esm/src/transaction-check/data/HttpTransactionCheckDataSource.test.js.map +3 -3
  289. package/lib/esm/src/transaction-check/data/HttpTypedDataCheckDataSource.js +1 -1
  290. package/lib/esm/src/transaction-check/data/HttpTypedDataCheckDataSource.js.map +3 -3
  291. package/lib/esm/src/transaction-check/data/HttpTypedDataCheckDataSource.test.js +1 -1
  292. package/lib/esm/src/transaction-check/data/HttpTypedDataCheckDataSource.test.js.map +3 -3
  293. package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.js +1 -1
  294. package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.js.map +3 -3
  295. package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.test.js +1 -1
  296. package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.test.js.map +3 -3
  297. package/lib/esm/src/trusted-name/di/trustedNameModuleFactory.js +1 -1
  298. package/lib/esm/src/trusted-name/di/trustedNameModuleFactory.js.map +3 -3
  299. package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.js +1 -1
  300. package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.js.map +3 -3
  301. package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.test.js +1 -1
  302. package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.test.js.map +3 -3
  303. package/lib/types/src/ContextModule.d.ts +2 -0
  304. package/lib/types/src/ContextModule.d.ts.map +1 -1
  305. package/lib/types/src/ContextModuleBuilder.d.ts +30 -3
  306. package/lib/types/src/ContextModuleBuilder.d.ts.map +1 -1
  307. package/lib/types/src/DefaultContextModule.d.ts +6 -2
  308. package/lib/types/src/DefaultContextModule.d.ts.map +1 -1
  309. package/lib/types/src/account-ownership/data/AccountOwnershipDataSource.d.ts +17 -0
  310. package/lib/types/src/account-ownership/data/AccountOwnershipDataSource.d.ts.map +1 -0
  311. package/lib/types/src/account-ownership/data/AccountOwnershipError.d.ts +17 -0
  312. package/lib/types/src/account-ownership/data/AccountOwnershipError.d.ts.map +1 -0
  313. package/lib/types/src/account-ownership/data/HttpAccountOwnershipDataSource.d.ts +30 -0
  314. package/lib/types/src/account-ownership/data/HttpAccountOwnershipDataSource.d.ts.map +1 -0
  315. package/lib/types/src/account-ownership/data/HttpAccountOwnershipDataSource.test.d.ts +2 -0
  316. package/lib/types/src/account-ownership/data/HttpAccountOwnershipDataSource.test.d.ts.map +1 -0
  317. package/lib/types/src/account-ownership/data/dto/AccountOwnershipDto.d.ts +6 -0
  318. package/lib/types/src/account-ownership/data/dto/AccountOwnershipDto.d.ts.map +1 -0
  319. package/lib/types/src/account-ownership/di/accountOwnershipModuleFactory.d.ts +3 -0
  320. package/lib/types/src/account-ownership/di/accountOwnershipModuleFactory.d.ts.map +1 -0
  321. package/lib/types/src/account-ownership/di/accountOwnershipTypes.d.ts +5 -0
  322. package/lib/types/src/account-ownership/di/accountOwnershipTypes.d.ts.map +1 -0
  323. package/lib/types/src/account-ownership/domain/AccountOwnershipContextLoader.d.ts +20 -0
  324. package/lib/types/src/account-ownership/domain/AccountOwnershipContextLoader.d.ts.map +1 -0
  325. package/lib/types/src/account-ownership/domain/AccountOwnershipContextLoader.test.d.ts +2 -0
  326. package/lib/types/src/account-ownership/domain/AccountOwnershipContextLoader.test.d.ts.map +1 -0
  327. package/lib/types/src/calldata/data/HttpCalldataDescriptorDataSource.d.ts +4 -2
  328. package/lib/types/src/calldata/data/HttpCalldataDescriptorDataSource.d.ts.map +1 -1
  329. package/lib/types/src/calldata/di/calldataModuleFactory.d.ts.map +1 -1
  330. package/lib/types/src/config/di/configModuleFactory.d.ts +2 -2
  331. package/lib/types/src/config/di/configModuleFactory.d.ts.map +1 -1
  332. package/lib/types/src/config/model/ContextModuleConfig.d.ts +14 -3
  333. package/lib/types/src/config/model/ContextModuleConfig.d.ts.map +1 -1
  334. package/lib/types/src/di.d.ts +2 -2
  335. package/lib/types/src/di.d.ts.map +1 -1
  336. package/lib/types/src/dynamic-network/data/HttpDynamicNetworkDataSource.d.ts +4 -2
  337. package/lib/types/src/dynamic-network/data/HttpDynamicNetworkDataSource.d.ts.map +1 -1
  338. package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.d.ts +2 -2
  339. package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.d.ts.map +1 -1
  340. package/lib/types/src/external-plugin/data/HttpExternalPluginDataSource.d.ts +4 -2
  341. package/lib/types/src/external-plugin/data/HttpExternalPluginDataSource.d.ts.map +1 -1
  342. package/lib/types/src/gated-signing/data/HttpGatedDescriptorDataSource.d.ts +4 -2
  343. package/lib/types/src/gated-signing/data/HttpGatedDescriptorDataSource.d.ts.map +1 -1
  344. package/lib/types/src/index.d.ts +11 -1
  345. package/lib/types/src/index.d.ts.map +1 -1
  346. package/lib/types/src/network/di/networkModuleFactory.d.ts +4 -0
  347. package/lib/types/src/network/di/networkModuleFactory.d.ts.map +1 -0
  348. package/lib/types/src/network/di/networkTypes.d.ts +4 -0
  349. package/lib/types/src/network/di/networkTypes.d.ts.map +1 -0
  350. package/lib/types/src/nft/data/HttpNftDataSource.d.ts +4 -2
  351. package/lib/types/src/nft/data/HttpNftDataSource.d.ts.map +1 -1
  352. package/lib/types/src/pki/data/HttpPkiCertificateDataSource.d.ts +5 -2
  353. package/lib/types/src/pki/data/HttpPkiCertificateDataSource.d.ts.map +1 -1
  354. package/lib/types/src/proxy/data/HttpProxyDataSource.d.ts +4 -2
  355. package/lib/types/src/proxy/data/HttpProxyDataSource.d.ts.map +1 -1
  356. package/lib/types/src/proxy/data/HttpSafeProxyDataSource.d.ts +4 -2
  357. package/lib/types/src/proxy/data/HttpSafeProxyDataSource.d.ts.map +1 -1
  358. package/lib/types/src/proxy/di/proxyModuleFactory.d.ts +2 -2
  359. package/lib/types/src/proxy/di/proxyModuleFactory.d.ts.map +1 -1
  360. package/lib/types/src/reporter/data/BlindSigningReporterDatasource.d.ts +29 -0
  361. package/lib/types/src/reporter/data/BlindSigningReporterDatasource.d.ts.map +1 -0
  362. package/lib/types/src/reporter/data/HttpBlindSigningReporterDatasource.d.ts +11 -0
  363. package/lib/types/src/reporter/data/HttpBlindSigningReporterDatasource.d.ts.map +1 -0
  364. package/lib/types/src/reporter/data/HttpBlindSigningReporterDatasource.test.d.ts +2 -0
  365. package/lib/types/src/reporter/data/HttpBlindSigningReporterDatasource.test.d.ts.map +1 -0
  366. package/lib/types/src/reporter/data/dto/BlindSigningEventDto.d.ts +26 -0
  367. package/lib/types/src/reporter/data/dto/BlindSigningEventDto.d.ts.map +1 -0
  368. package/lib/types/src/reporter/di/reporterModuleFactory.d.ts +3 -0
  369. package/lib/types/src/reporter/di/reporterModuleFactory.d.ts.map +1 -0
  370. package/lib/types/src/reporter/di/reporterTypes.d.ts +5 -0
  371. package/lib/types/src/reporter/di/reporterTypes.d.ts.map +1 -0
  372. package/lib/types/src/reporter/domain/BlindSigningReporter.d.ts +6 -0
  373. package/lib/types/src/reporter/domain/BlindSigningReporter.d.ts.map +1 -0
  374. package/lib/types/src/reporter/domain/DefaultBlindSigningReporter.d.ts +9 -0
  375. package/lib/types/src/reporter/domain/DefaultBlindSigningReporter.d.ts.map +1 -0
  376. package/lib/types/src/reporter/domain/DefaultBlindSigningReporter.test.d.ts +2 -0
  377. package/lib/types/src/reporter/domain/DefaultBlindSigningReporter.test.d.ts.map +1 -0
  378. package/lib/types/src/reporter/model/BlindSigningEvent.d.ts +21 -0
  379. package/lib/types/src/reporter/model/BlindSigningEvent.d.ts.map +1 -0
  380. package/lib/types/src/reporter/model/BlindSigningModelId.d.ts +12 -0
  381. package/lib/types/src/reporter/model/BlindSigningModelId.d.ts.map +1 -0
  382. package/lib/types/src/safe/data/HttpSafeAccountDataSource.d.ts +4 -2
  383. package/lib/types/src/safe/data/HttpSafeAccountDataSource.d.ts.map +1 -1
  384. package/lib/types/src/shared/model/ClearSignContext.d.ts +2 -1
  385. package/lib/types/src/shared/model/ClearSignContext.d.ts.map +1 -1
  386. package/lib/types/src/solana/data/HttpSolanaOwnerInfoDataSource.d.ts +4 -2
  387. package/lib/types/src/solana/data/HttpSolanaOwnerInfoDataSource.d.ts.map +1 -1
  388. package/lib/types/src/solanaLifi/data/HttpSolanaLifiDataSource.d.ts +4 -3
  389. package/lib/types/src/solanaLifi/data/HttpSolanaLifiDataSource.d.ts.map +1 -1
  390. package/lib/types/src/solanaLifi/domain/SolanaLifiContextLoader.d.ts +2 -2
  391. package/lib/types/src/solanaLifi/domain/SolanaLifiContextLoader.d.ts.map +1 -1
  392. package/lib/types/src/solanaToken/data/HttpSolanaTokenDataSource.d.ts +4 -2
  393. package/lib/types/src/solanaToken/data/HttpSolanaTokenDataSource.d.ts.map +1 -1
  394. package/lib/types/src/solanaToken/domain/SolanaTokenContextLoader.d.ts +2 -2
  395. package/lib/types/src/solanaToken/domain/SolanaTokenContextLoader.d.ts.map +1 -1
  396. package/lib/types/src/token/data/HttpTokenDataSource.d.ts +4 -2
  397. package/lib/types/src/token/data/HttpTokenDataSource.d.ts.map +1 -1
  398. package/lib/types/src/transaction-check/data/HttpTransactionCheckDataSource.d.ts +4 -2
  399. package/lib/types/src/transaction-check/data/HttpTransactionCheckDataSource.d.ts.map +1 -1
  400. package/lib/types/src/transaction-check/data/HttpTypedDataCheckDataSource.d.ts +4 -2
  401. package/lib/types/src/transaction-check/data/HttpTypedDataCheckDataSource.d.ts.map +1 -1
  402. package/lib/types/src/trusted-name/data/HttpTrustedNameDataSource.d.ts +4 -2
  403. package/lib/types/src/trusted-name/data/HttpTrustedNameDataSource.d.ts.map +1 -1
  404. package/lib/types/src/trusted-name/di/trustedNameModuleFactory.d.ts +2 -2
  405. package/lib/types/src/trusted-name/di/trustedNameModuleFactory.d.ts.map +1 -1
  406. package/lib/types/src/typed-data/data/HttpTypedDataDataSource.d.ts +4 -2
  407. package/lib/types/src/typed-data/data/HttpTypedDataDataSource.d.ts.map +1 -1
  408. package/lib/types/src/typed-data/data/HttpTypedDataDataSource.test.d.ts.map +1 -1
  409. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  410. package/package.json +6 -7
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/account-ownership/data/HttpAccountOwnershipDataSource.test.ts"],
4
+ "sourcesContent": ["import { type DmkNetworkClient } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { AccountOwnershipError } from \"@/account-ownership/data/AccountOwnershipError\";\nimport { type ContextModuleServiceConfig } from \"@/config/model/ContextModuleConfig\";\n\nimport { HttpAccountOwnershipDataSource } from \"./HttpAccountOwnershipDataSource\";\n\n/**\n * Build an error that quacks like a {@link DmkNetworkClientError}: a real\n * `Error` with numeric `.status` and raw `.responseBody` text. Callers can\n * omit fields to simulate specific shapes.\n */\nfunction makeHttpError(options: {\n status?: number;\n message?: string;\n responseBody?: string;\n}): Error {\n const err = new Error(options.message ?? \"HTTP error\");\n if (options.status !== undefined) {\n (err as unknown as { status: number }).status = options.status;\n }\n if (options.responseBody !== undefined) {\n (err as unknown as { responseBody: string }).responseBody =\n options.responseBody;\n }\n return err;\n}\n\ndescribe(\"HttpAccountOwnershipDataSource\", () => {\n const config: ContextModuleServiceConfig = {\n metadataServiceDomain: {\n url: \"https://nft.api.live.ledger-test.com\",\n },\n originToken: \"test-origin-token\",\n } as ContextModuleServiceConfig;\n\n const validDto = {\n signedDescriptor: \"signed-descriptor-data\",\n keyId: \"domain_metadata_key\",\n keyUsage: \"trusted_name\",\n };\n\n const baseParams = {\n publicKey: \"abcdef1234567890\",\n address: \"3kFkntk2H5FGMzeR3GjQKPhdZK9LShKdPHsj2fiGKCdmDXj2WB\",\n challenge: \"0xabcdef\",\n network: \"mainnet\" as const,\n };\n\n let httpMock: { get: ReturnType<typeof vi.fn> };\n let datasource: HttpAccountOwnershipDataSource;\n\n beforeEach(() => {\n vi.clearAllMocks();\n httpMock = { get: vi.fn() };\n datasource = new HttpAccountOwnershipDataSource(\n config,\n httpMock as unknown as DmkNetworkClient,\n );\n });\n\n describe(\"getDescriptor\", () => {\n it(\"should return descriptor on successful request\", async () => {\n httpMock.get.mockResolvedValue(validDto);\n\n const result = await datasource.getDescriptor(baseParams);\n\n expect(httpMock.get).toHaveBeenCalledWith(\n `${config.metadataServiceDomain.url}/v2/concordium/owner/${baseParams.publicKey}/${baseParams.address}`,\n {\n params: {\n challenge: baseParams.challenge,\n network: baseParams.network,\n },\n },\n );\n expect(result).toEqual(Right(validDto));\n });\n\n it(\"should pass testnet network parameter\", async () => {\n httpMock.get.mockResolvedValue(validDto);\n\n await datasource.getDescriptor({ ...baseParams, network: \"testnet\" });\n\n expect(httpMock.get).toHaveBeenCalledWith(expect.any(String), {\n params: { challenge: baseParams.challenge, network: \"testnet\" },\n });\n });\n\n it(\"should classify empty response as service_unavailable\", async () => {\n httpMock.get.mockResolvedValue(null);\n\n const result = await datasource.getDescriptor(baseParams);\n\n expect(result.isLeft()).toBe(true);\n const err = result.extract() as AccountOwnershipError;\n expect(err).toBeInstanceOf(AccountOwnershipError);\n expect(err.kind).toBe(\"service_unavailable\");\n expect(err.message).toContain(\"unexpected empty response\");\n });\n\n it.each([\n [\"signedDescriptor missing\", { keyId: \"k\", keyUsage: \"u\" }],\n [\"keyId missing\", { signedDescriptor: \"s\", keyUsage: \"u\" }],\n [\"keyUsage missing\", { signedDescriptor: \"s\", keyId: \"k\" }],\n [\n \"wrong field type\",\n { signedDescriptor: \"s\", keyId: 123, keyUsage: \"u\" },\n ],\n ])(\n \"should classify malformed response (%s) as service_unavailable\",\n async (_label, data) => {\n httpMock.get.mockResolvedValue(data);\n\n const result = await datasource.getDescriptor(baseParams);\n\n expect(result.isLeft()).toBe(true);\n const err = result.extract() as AccountOwnershipError;\n expect(err).toBeInstanceOf(AccountOwnershipError);\n expect(err.kind).toBe(\"service_unavailable\");\n expect(err.message).toContain(\"invalid response format\");\n },\n );\n\n it(\"should classify 422 with { message } body as verification_failed and forward backend message\", async () => {\n const backendMessage =\n \"Address ByteVector(32 bytes, 0xa63c) is not associated with the given public key ByteVector(32 bytes, 0x9dc1) on the network Testnet\";\n httpMock.get.mockRejectedValue(\n makeHttpError({\n status: 422,\n message: \"HTTP error 422\",\n responseBody: JSON.stringify({ message: backendMessage }),\n }),\n );\n\n const result = await datasource.getDescriptor(baseParams);\n\n expect(result.isLeft()).toBe(true);\n const err = result.extract() as AccountOwnershipError;\n expect(err).toBeInstanceOf(AccountOwnershipError);\n expect(err.kind).toBe(\"verification_failed\");\n expect(err.message).toBe(backendMessage);\n });\n\n it.each([400, 401, 403, 404, 429])(\n \"should classify HTTP %s as verification_failed with forwarded message\",\n async (status) => {\n httpMock.get.mockRejectedValue(\n makeHttpError({\n status,\n message: `HTTP error ${status}`,\n responseBody: JSON.stringify({ message: \"refused\" }),\n }),\n );\n\n const result = await datasource.getDescriptor(baseParams);\n\n const err = result.extract() as AccountOwnershipError;\n expect(err.kind).toBe(\"verification_failed\");\n expect(err.message).toBe(\"refused\");\n },\n );\n\n it(\"should classify 500 as service_unavailable with status prefix\", async () => {\n httpMock.get.mockRejectedValue(\n makeHttpError({\n status: 500,\n message: \"HTTP error 500\",\n responseBody: JSON.stringify({ message: \"internal error\" }),\n }),\n );\n\n const result = await datasource.getDescriptor(baseParams);\n\n const err = result.extract() as AccountOwnershipError;\n expect(err.kind).toBe(\"service_unavailable\");\n expect(err.message).toContain(\"backend 500\");\n expect(err.message).toContain(\"internal error\");\n });\n\n it.each([502, 503, 504])(\n \"should classify HTTP %s as service_unavailable\",\n async (status) => {\n httpMock.get.mockRejectedValue(\n makeHttpError({\n status,\n message: `HTTP error ${status}`,\n responseBody: JSON.stringify({ message: \"down\" }),\n }),\n );\n\n const result = await datasource.getDescriptor(baseParams);\n\n const err = result.extract() as AccountOwnershipError;\n expect(err.kind).toBe(\"service_unavailable\");\n expect(err.message).toContain(`backend ${status}`);\n expect(err.message).toContain(\"down\");\n },\n );\n\n it(\"should accept plain-text response body and forward it on 4xx\", async () => {\n httpMock.get.mockRejectedValue(\n makeHttpError({\n status: 422,\n message: \"HTTP error 422\",\n responseBody: \"plain text reason\",\n }),\n );\n\n const result = await datasource.getDescriptor(baseParams);\n\n const err = result.extract() as AccountOwnershipError;\n expect(err.kind).toBe(\"verification_failed\");\n expect(err.message).toBe(\"plain text reason\");\n });\n\n it(\"should fall back to the client error message when response body is empty\", async () => {\n httpMock.get.mockRejectedValue(\n makeHttpError({\n status: 422,\n message: \"HTTP error 422\",\n responseBody: \"\",\n }),\n );\n\n const result = await datasource.getDescriptor(baseParams);\n\n const err = result.extract() as AccountOwnershipError;\n expect(err.kind).toBe(\"verification_failed\");\n expect(err.message).toBe(\"HTTP error 422\");\n });\n\n it(\"should classify network errors (no status) as service_unavailable\", async () => {\n httpMock.get.mockRejectedValue(new Error(\"Network error\"));\n\n const result = await datasource.getDescriptor(baseParams);\n\n expect(result).toEqual(\n Left(\n new AccountOwnershipError(\n \"service_unavailable\",\n \"[ContextModule] HttpAccountOwnershipDataSource: Failed to fetch account ownership descriptor\",\n ),\n ),\n );\n });\n\n // Errors surfaced by the network client (or any wrapping layer) that\n // expose a numeric `.status` field must still be classified, even if\n // they are not true `DmkNetworkClientError` instances.\n describe(\"errors with numeric .status\", () => {\n it.each([400, 401, 403, 404, 422, 429])(\n \"should classify HTTP %s on .status as verification_failed and forward .message\",\n async (status) => {\n const backendMessage =\n \"Address ByteVector(...) is not associated with the given public key ByteVector(...)\";\n httpMock.get.mockRejectedValue(\n makeHttpError({ status, message: backendMessage }),\n );\n\n const result = await datasource.getDescriptor(baseParams);\n\n const err = result.extract() as AccountOwnershipError;\n expect(err.kind).toBe(\"verification_failed\");\n expect(err.message).toBe(backendMessage);\n },\n );\n\n it.each([500, 502, 503, 504])(\n \"should classify HTTP %s on .status as service_unavailable with status prefix\",\n async (status) => {\n httpMock.get.mockRejectedValue(\n makeHttpError({ status, message: \"down\" }),\n );\n\n const result = await datasource.getDescriptor(baseParams);\n\n const err = result.extract() as AccountOwnershipError;\n expect(err.kind).toBe(\"service_unavailable\");\n expect(err.message).toContain(`backend ${status}`);\n expect(err.message).toContain(\"down\");\n },\n );\n\n it(\"should ignore non-numeric .status and fall through to service_unavailable fallback\", async () => {\n const err = new Error(\"bad\");\n (err as unknown as { status: string }).status = \"422\";\n httpMock.get.mockRejectedValue(err);\n\n const result = await datasource.getDescriptor(baseParams);\n\n expect(result).toEqual(\n Left(\n new AccountOwnershipError(\n \"service_unavailable\",\n \"[ContextModule] HttpAccountOwnershipDataSource: Failed to fetch account ownership descriptor\",\n ),\n ),\n );\n });\n\n it(\"should forward .message from plain object errors (not Error instances)\", async () => {\n httpMock.get.mockRejectedValue({\n status: 422,\n message: \"plain object message\",\n });\n\n const result = await datasource.getDescriptor(baseParams);\n\n const err = result.extract() as AccountOwnershipError;\n expect(err.kind).toBe(\"verification_failed\");\n expect(err.message).toBe(\"plain object message\");\n });\n\n it(\"should use an 'Unknown error' fallback when the object has no usable message\", async () => {\n httpMock.get.mockRejectedValue({ status: 422 });\n\n const result = await datasource.getDescriptor(baseParams);\n\n const err = result.extract() as AccountOwnershipError;\n expect(err.kind).toBe(\"verification_failed\");\n expect(err.message).toBe(\"Unknown error\");\n });\n });\n\n it(\"should use correct metadata service URL from config\", async () => {\n const customConfig: ContextModuleServiceConfig = {\n metadataServiceDomain: {\n url: \"https://custom-metadata.example.com\",\n },\n originToken: \"custom-token\",\n } as ContextModuleServiceConfig;\n const customDatasource = new HttpAccountOwnershipDataSource(\n customConfig,\n httpMock as unknown as DmkNetworkClient,\n );\n httpMock.get.mockResolvedValue(validDto);\n\n await customDatasource.getDescriptor(baseParams);\n\n expect(httpMock.get).toHaveBeenCalledWith(\n \"https://custom-metadata.example.com/v2/concordium/owner/abcdef1234567890/3kFkntk2H5FGMzeR3GjQKPhdZK9LShKdPHsj2fiGKCdmDXj2WB\",\n expect.anything(),\n );\n });\n });\n});\n"],
5
+ "mappings": "AACA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAE5B,OAAS,yBAAAC,MAA6B,iDAGtC,OAAS,kCAAAC,MAAsC,mCAO/C,SAASC,EAAcC,EAIb,CACR,MAAMC,EAAM,IAAI,MAAMD,EAAQ,SAAW,YAAY,EACrD,OAAIA,EAAQ,SAAW,SACpBC,EAAsC,OAASD,EAAQ,QAEtDA,EAAQ,eAAiB,SAC1BC,EAA4C,aAC3CD,EAAQ,cAELC,CACT,CAEA,SAAS,iCAAkC,IAAM,CAC/C,MAAMC,EAAqC,CACzC,sBAAuB,CACrB,IAAK,sCACP,EACA,YAAa,mBACf,EAEMC,EAAW,CACf,iBAAkB,yBAClB,MAAO,sBACP,SAAU,cACZ,EAEMC,EAAa,CACjB,UAAW,mBACX,QAAS,qDACT,UAAW,WACX,QAAS,SACX,EAEA,IAAIC,EACAC,EAEJ,WAAW,IAAM,CACf,GAAG,cAAc,EACjBD,EAAW,CAAE,IAAK,GAAG,GAAG,CAAE,EAC1BC,EAAa,IAAIR,EACfI,EACAG,CACF,CACF,CAAC,EAED,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sBACA,8FACF,CACF,CACF,CACF,CAAC,EAED,GAAG,yEAA0E,SAAY,CACvFQ,EAAS,IAAI,kBAAkB,CAC7B,OAAQ,IACR,QAAS,sBACX,CAAC,EAID,MAAMJ,GAFS,MAAMK,EAAW,cAAcF,CAAU,GAErC,QAAQ,EAC3B,OAAOH,EAAI,IAAI,EAAE,KAAK,qBAAqB,EAC3C,OAAOA,EAAI,OAAO,EAAE,KAAK,sBAAsB,CACjD,CAAC,EAED,GAAG,+EAAgF,SAAY,CAC7FI,EAAS,IAAI,kBAAkB,CAAE,OAAQ,GAAI,CAAC,EAI9C,MAAMJ,GAFS,MAAMK,EAAW,cAAcF,CAAU,GAErC,QAAQ,EAC3B,OAAOH,EAAI,IAAI,EAAE,KAAK,qBAAqB,EAC3C,OAAOA,EAAI,OAAO,EAAE,KAAK,eAAe,CAC1C,CAAC,CACH,CAAC,EAED,GAAG,sDAAuD,SAAY,CACpE,MAAMW,EAA2C,CAC/C,sBAAuB,CACrB,IAAK,qCACP,EACA,YAAa,cACf,EACMC,EAAmB,IAAIf,EAC3Bc,EACAP,CACF,EACAA,EAAS,IAAI,kBAAkBF,CAAQ,EAEvC,MAAMU,EAAiB,cAAcT,CAAU,EAE/C,OAAOC,EAAS,GAAG,EAAE,qBACnB,8HACA,OAAO,SAAS,CAClB,CACF,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["Left", "Right", "AccountOwnershipError", "HttpAccountOwnershipDataSource", "makeHttpError", "options", "err", "config", "validDto", "baseParams", "httpMock", "datasource", "result", "_label", "data", "backendMessage", "status", "customConfig", "customDatasource"]
7
+ }
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=AccountOwnershipDto.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ import{ContainerModule as r}from"inversify";import{HttpAccountOwnershipDataSource as e}from"../../account-ownership/data/HttpAccountOwnershipDataSource";import{AccountOwnershipContextLoader as n}from"../../account-ownership/domain/AccountOwnershipContextLoader";import{accountOwnershipTypes as t}from"./accountOwnershipTypes";const u=()=>new r(({bind:o})=>{o(t.AccountOwnershipDataSource).to(e),o(t.AccountOwnershipContextLoader).to(n)});export{u as accountOwnershipModuleFactory};
2
+ //# sourceMappingURL=accountOwnershipModuleFactory.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/account-ownership/di/accountOwnershipModuleFactory.ts"],
4
+ "sourcesContent": ["import { ContainerModule } from \"inversify\";\n\nimport { HttpAccountOwnershipDataSource } from \"@/account-ownership/data/HttpAccountOwnershipDataSource\";\nimport { AccountOwnershipContextLoader } from \"@/account-ownership/domain/AccountOwnershipContextLoader\";\n\nimport { accountOwnershipTypes } from \"./accountOwnershipTypes\";\n\nexport const accountOwnershipModuleFactory = () =>\n new ContainerModule(({ bind }) => {\n bind(accountOwnershipTypes.AccountOwnershipDataSource).to(\n HttpAccountOwnershipDataSource,\n );\n bind(accountOwnershipTypes.AccountOwnershipContextLoader).to(\n AccountOwnershipContextLoader,\n );\n });\n"],
5
+ "mappings": "AAAA,OAAS,mBAAAA,MAAuB,YAEhC,OAAS,kCAAAC,MAAsC,0DAC/C,OAAS,iCAAAC,MAAqC,2DAE9C,OAAS,yBAAAC,MAA6B,0BAE/B,MAAMC,EAAgC,IAC3C,IAAIJ,EAAgB,CAAC,CAAE,KAAAK,CAAK,IAAM,CAChCA,EAAKF,EAAsB,0BAA0B,EAAE,GACrDF,CACF,EACAI,EAAKF,EAAsB,6BAA6B,EAAE,GACxDD,CACF,CACF,CAAC",
6
+ "names": ["ContainerModule", "HttpAccountOwnershipDataSource", "AccountOwnershipContextLoader", "accountOwnershipTypes", "accountOwnershipModuleFactory", "bind"]
7
+ }
@@ -0,0 +1,2 @@
1
+ const o={AccountOwnershipDataSource:Symbol.for("AccountOwnershipDataSource"),AccountOwnershipContextLoader:Symbol.for("AccountOwnershipContextLoader")};export{o as accountOwnershipTypes};
2
+ //# sourceMappingURL=accountOwnershipTypes.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/account-ownership/di/accountOwnershipTypes.ts"],
4
+ "sourcesContent": ["export const accountOwnershipTypes = {\n AccountOwnershipDataSource: Symbol.for(\"AccountOwnershipDataSource\"),\n AccountOwnershipContextLoader: Symbol.for(\"AccountOwnershipContextLoader\"),\n};\n"],
5
+ "mappings": "AAAO,MAAMA,EAAwB,CACnC,2BAA4B,OAAO,IAAI,4BAA4B,EACnE,8BAA+B,OAAO,IAAI,+BAA+B,CAC3E",
6
+ "names": ["accountOwnershipTypes"]
7
+ }
@@ -0,0 +1,2 @@
1
+ var g=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var l=(i,e,t,r)=>{for(var o=r>1?void 0:r?C(e,t):e,n=i.length-1,c;n>=0;n--)(c=i[n])&&(o=(r?c(e,t,o):c(o))||o);return r&&o&&g(e,t,o),o},d=(i,e)=>(t,r)=>e(t,r,i);import{inject as y,injectable as m}from"inversify";import{accountOwnershipTypes as f}from"../../account-ownership/di/accountOwnershipTypes";import{pkiTypes as h}from"../../pki/di/pkiTypes";import{ClearSignContextType as p}from"../../shared/model/ClearSignContext";const w=[p.ACCOUNT_OWNERSHIP];let s=class{constructor(e,t){this._dataSource=e;this._certificateLoader=t}canHandle(e,t){return w.every(r=>t.includes(r))&&typeof e=="object"&&e!==null&&"publicKey"in e&&typeof e.publicKey=="string"&&e.publicKey.length>0&&"address"in e&&typeof e.address=="string"&&e.address.length>0&&"network"in e&&(e.network==="mainnet"||e.network==="testnet")&&"deviceModelId"in e&&e.deviceModelId!==void 0&&"challenge"in e&&typeof e.challenge=="string"&&e.challenge.length>0}async load({publicKey:e,address:t,network:r,deviceModelId:o,challenge:n}){return(await this._dataSource.getDescriptor({publicKey:e,address:t,challenge:n,network:r})).caseOf({Left:a=>Promise.resolve([{type:p.ERROR,error:a}]),Right:async a=>[{type:p.ACCOUNT_OWNERSHIP,payload:a.signedDescriptor,certificate:await this._certificateLoader.loadCertificate({keyId:a.keyId,keyUsage:a.keyUsage,targetDevice:o})}]})}};s=l([m(),d(0,y(f.AccountOwnershipDataSource)),d(1,y(h.PkiCertificateLoader))],s);export{s as AccountOwnershipContextLoader};
2
+ //# sourceMappingURL=AccountOwnershipContextLoader.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/account-ownership/domain/AccountOwnershipContextLoader.ts"],
4
+ "sourcesContent": ["import { type DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport type {\n AccountOwnershipDataSource,\n AccountOwnershipNetwork,\n} from \"@/account-ownership/data/AccountOwnershipDataSource\";\nimport { accountOwnershipTypes } from \"@/account-ownership/di/accountOwnershipTypes\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { type ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n type ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\n\nexport type AccountOwnershipContextInput = {\n publicKey: string;\n address: string;\n network: AccountOwnershipNetwork;\n deviceModelId: DeviceModelId;\n challenge: string;\n};\n\nconst SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.ACCOUNT_OWNERSHIP,\n];\n\n@injectable()\nexport class AccountOwnershipContextLoader\n implements ContextLoader<AccountOwnershipContextInput>\n{\n constructor(\n @inject(accountOwnershipTypes.AccountOwnershipDataSource)\n private readonly _dataSource: AccountOwnershipDataSource,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n ) {}\n\n canHandle(\n input: unknown,\n expectedTypes: ClearSignContextType[],\n ): input is AccountOwnershipContextInput {\n return (\n SUPPORTED_TYPES.every((type) => expectedTypes.includes(type)) &&\n typeof input === \"object\" &&\n input !== null &&\n \"publicKey\" in input &&\n typeof input.publicKey === \"string\" &&\n input.publicKey.length > 0 &&\n \"address\" in input &&\n typeof input.address === \"string\" &&\n input.address.length > 0 &&\n \"network\" in input &&\n (input.network === \"mainnet\" || input.network === \"testnet\") &&\n \"deviceModelId\" in input &&\n input.deviceModelId !== undefined &&\n \"challenge\" in input &&\n typeof input.challenge === \"string\" &&\n input.challenge.length > 0\n );\n }\n\n async load({\n publicKey,\n address,\n network,\n deviceModelId,\n challenge,\n }: AccountOwnershipContextInput): Promise<ClearSignContext[]> {\n const descriptor = await this._dataSource.getDescriptor({\n publicKey,\n address,\n challenge,\n network,\n });\n\n return descriptor.caseOf({\n Left: (error): Promise<ClearSignContext[]> =>\n Promise.resolve([\n {\n type: ClearSignContextType.ERROR,\n error,\n },\n ]),\n Right: async (result): Promise<ClearSignContext[]> => [\n {\n type: ClearSignContextType.ACCOUNT_OWNERSHIP,\n payload: result.signedDescriptor,\n certificate: await this._certificateLoader.loadCertificate({\n keyId: result.keyId,\n keyUsage: result.keyUsage,\n targetDevice: deviceModelId,\n }),\n },\n ],\n });\n }\n}\n"],
5
+ "mappings": "iOACA,OAAS,UAAAA,EAAQ,cAAAC,MAAkB,YAMnC,OAAS,yBAAAC,MAA6B,+CACtC,OAAS,YAAAC,MAAgB,oBAGzB,OAEE,wBAAAC,MACK,kCAUP,MAAMC,EAA0C,CAC9CC,EAAqB,iBACvB,EAGO,IAAMC,EAAN,KAEP,CACE,YAEmBC,EAEAC,EACjB,CAHiB,iBAAAD,EAEA,wBAAAC,CAChB,CAEH,UACEC,EACAC,EACuC,CACvC,OACEN,EAAgB,MAAOO,GAASD,EAAc,SAASC,CAAI,CAAC,GAC5D,OAAOF,GAAU,UACjBA,IAAU,MACV,cAAeA,GACf,OAAOA,EAAM,WAAc,UAC3BA,EAAM,UAAU,OAAS,GACzB,YAAaA,GACb,OAAOA,EAAM,SAAY,UACzBA,EAAM,QAAQ,OAAS,GACvB,YAAaA,IACZA,EAAM,UAAY,WAAaA,EAAM,UAAY,YAClD,kBAAmBA,GACnBA,EAAM,gBAAkB,QACxB,cAAeA,GACf,OAAOA,EAAM,WAAc,UAC3BA,EAAM,UAAU,OAAS,CAE7B,CAEA,MAAM,KAAK,CACT,UAAAG,EACA,QAAAC,EACA,QAAAC,EACA,cAAAC,EACA,UAAAC,CACF,EAA8D,CAQ5D,OAPmB,MAAM,KAAK,YAAY,cAAc,CACtD,UAAAJ,EACA,QAAAC,EACA,UAAAG,EACA,QAAAF,CACF,CAAC,GAEiB,OAAO,CACvB,KAAOG,GACL,QAAQ,QAAQ,CACd,CACE,KAAMZ,EAAqB,MAC3B,MAAAY,CACF,CACF,CAAC,EACH,MAAO,MAAOC,GAAwC,CACpD,CACE,KAAMb,EAAqB,kBAC3B,QAASa,EAAO,iBAChB,YAAa,MAAM,KAAK,mBAAmB,gBAAgB,CACzD,MAAOA,EAAO,MACd,SAAUA,EAAO,SACjB,aAAcH,CAChB,CAAC,CACH,CACF,CACF,CAAC,CACH,CACF,EArEaT,EAANa,EAAA,CADNC,EAAW,EAKPC,EAAA,EAAAC,EAAOC,EAAsB,0BAA0B,GAEvDF,EAAA,EAAAC,EAAOE,EAAS,oBAAoB,IAN5BlB",
6
+ "names": ["inject", "injectable", "accountOwnershipTypes", "pkiTypes", "ClearSignContextType", "SUPPORTED_TYPES", "ClearSignContextType", "AccountOwnershipContextLoader", "_dataSource", "_certificateLoader", "input", "expectedTypes", "type", "publicKey", "address", "network", "deviceModelId", "challenge", "error", "result", "__decorateClass", "injectable", "__decorateParam", "inject", "accountOwnershipTypes", "pkiTypes"]
7
+ }
@@ -0,0 +1,2 @@
1
+ import{DeviceModelId as a}from"@ledgerhq/device-management-kit";import{Left as p,Right as s}from"purify-ts";import{AccountOwnershipContextLoader as u}from"../../account-ownership/domain/AccountOwnershipContextLoader";import{ClearSignContextType as o}from"../../shared/model/ClearSignContext";describe("AccountOwnershipContextLoader",()=>{const i={getDescriptor:vi.fn()},c={loadCertificate:vi.fn()},n=new u(i,c),l={keyUsageNumber:4,payload:new Uint8Array([1,2,3])},d={signedDescriptor:"account-ownership-descriptor-payload",keyId:"domain_metadata_key",keyUsage:"trusted_name"};beforeEach(()=>{vi.clearAllMocks(),vi.spyOn(c,"loadCertificate").mockResolvedValue(l)}),describe("canHandle",()=>{const e={publicKey:"abcdef1234567890",address:"3kFkntk2H5FGMzeR3GjQKPhdZK9LShKdPHsj2fiGKCdmDXj2WB",network:"mainnet",deviceModelId:a.FLEX,challenge:"0xabcdef"};it("should return true for valid input with ACCOUNT_OWNERSHIP type",()=>{expect(n.canHandle(e,[o.ACCOUNT_OWNERSHIP])).toBe(!0)}),it("should return false when expected types include unsupported types",()=>{expect(n.canHandle(e,[o.TOKEN])).toBe(!1),expect(n.canHandle(e,[o.TRUSTED_NAME])).toBe(!1)}),it("should return true when expected types include ACCOUNT_OWNERSHIP among others",()=>{expect(n.canHandle(e,[o.ACCOUNT_OWNERSHIP,o.TOKEN])).toBe(!0)}),it.each([[null,"null input"],[void 0,"undefined input"],[{},"empty object"],["string","string input"],[123,"number input"]])("should return false for %s",(t,r)=>{expect(n.canHandle(t,[o.ACCOUNT_OWNERSHIP])).toBe(!1)}),it.each([[{...e,publicKey:void 0},"missing publicKey"],[{...e,address:void 0},"missing address"],[{...e,network:void 0},"missing network"],[{...e,deviceModelId:void 0},"missing deviceModelId"],[{...e,challenge:void 0},"missing challenge"]])("should return false for %s",(t,r)=>{expect(n.canHandle(t,[o.ACCOUNT_OWNERSHIP])).toBe(!1)}),it.each([[{...e,publicKey:""},"empty publicKey"],[{...e,address:""},"empty address"],[{...e,challenge:""},"empty challenge"]])("should return false for %s",(t,r)=>{expect(n.canHandle(t,[o.ACCOUNT_OWNERSHIP])).toBe(!1)}),it("should return false for invalid network value",()=>{expect(n.canHandle({...e,network:"devnet"},[o.ACCOUNT_OWNERSHIP])).toBe(!1)}),it("should return true for testnet network",()=>{expect(n.canHandle({...e,network:"testnet"},[o.ACCOUNT_OWNERSHIP])).toBe(!0)}),it("should return true for different device models",()=>{for(const t of[a.NANO_S,a.NANO_SP,a.NANO_X,a.STAX,a.FLEX])expect(n.canHandle({...e,deviceModelId:t},[o.ACCOUNT_OWNERSHIP])).toBe(!0)})}),describe("load",()=>{const e={publicKey:"abcdef1234567890",address:"3kFkntk2H5FGMzeR3GjQKPhdZK9LShKdPHsj2fiGKCdmDXj2WB",network:"mainnet",deviceModelId:a.FLEX,challenge:"0xabcdef"};it("should return ACCOUNT_OWNERSHIP context with certificate",async()=>{vi.spyOn(i,"getDescriptor").mockResolvedValue(s(d));const t=await n.load(e);expect(i.getDescriptor).toHaveBeenCalledWith({publicKey:"abcdef1234567890",address:"3kFkntk2H5FGMzeR3GjQKPhdZK9LShKdPHsj2fiGKCdmDXj2WB",challenge:"0xabcdef",network:"mainnet"}),expect(c.loadCertificate).toHaveBeenCalledWith({keyId:"domain_metadata_key",keyUsage:"trusted_name",targetDevice:a.FLEX}),expect(t).toEqual([{type:o.ACCOUNT_OWNERSHIP,payload:"account-ownership-descriptor-payload",certificate:l}])}),it("should return ACCOUNT_OWNERSHIP context without certificate when loadCertificate returns undefined",async()=>{vi.spyOn(i,"getDescriptor").mockResolvedValue(s(d)),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const t=await n.load(e);expect(t).toEqual([{type:o.ACCOUNT_OWNERSHIP,payload:"account-ownership-descriptor-payload",certificate:void 0}])}),it("should return ERROR context when data source returns Left",async()=>{const t=new Error("Failed to get descriptor");vi.spyOn(i,"getDescriptor").mockResolvedValue(p(t));const r=await n.load(e);expect(r).toEqual([{type:o.ERROR,error:t}]),expect(c.loadCertificate).not.toHaveBeenCalled()}),it("should pass correct device model to certificate loader",async()=>{const t={...e,deviceModelId:a.NANO_X};vi.spyOn(i,"getDescriptor").mockResolvedValue(s(d)),await n.load(t),expect(c.loadCertificate).toHaveBeenCalledWith(expect.objectContaining({targetDevice:a.NANO_X}))}),it("should pass testnet network to data source",async()=>{const t={...e,network:"testnet"};vi.spyOn(i,"getDescriptor").mockResolvedValue(s(d)),await n.load(t),expect(i.getDescriptor).toHaveBeenCalledWith(expect.objectContaining({network:"testnet"}))}),it("should handle long descriptor payloads",async()=>{const t="a".repeat(1e3);vi.spyOn(i,"getDescriptor").mockResolvedValue(s({...d,signedDescriptor:t}));const r=await n.load(e);expect(r[0].payload).toBe(t)})})});
2
+ //# sourceMappingURL=AccountOwnershipContextLoader.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/account-ownership/domain/AccountOwnershipContextLoader.test.ts"],
4
+ "sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport type {\n AccountOwnershipDataSource,\n AccountOwnershipDescriptor,\n} from \"@/account-ownership/data/AccountOwnershipDataSource\";\nimport {\n type AccountOwnershipContextInput,\n AccountOwnershipContextLoader,\n} from \"@/account-ownership/domain/AccountOwnershipContextLoader\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { type PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport {\n type ClearSignContextSuccess,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\n\ndescribe(\"AccountOwnershipContextLoader\", () => {\n const mockDataSource: AccountOwnershipDataSource = {\n getDescriptor: vi.fn(),\n };\n const mockPkiCertificateLoader: PkiCertificateLoader = {\n loadCertificate: vi.fn(),\n };\n const loader = new AccountOwnershipContextLoader(\n mockDataSource,\n mockPkiCertificateLoader,\n );\n\n const mockCertificate: PkiCertificate = {\n keyUsageNumber: 4,\n payload: new Uint8Array([1, 2, 3]),\n };\n\n const mockDescriptor: AccountOwnershipDescriptor = {\n signedDescriptor: \"account-ownership-descriptor-payload\",\n keyId: \"domain_metadata_key\",\n keyUsage: \"trusted_name\",\n };\n\n beforeEach(() => {\n vi.clearAllMocks();\n vi.spyOn(mockPkiCertificateLoader, \"loadCertificate\").mockResolvedValue(\n mockCertificate,\n );\n });\n\n describe(\"canHandle\", () => {\n const validInput: AccountOwnershipContextInput = {\n publicKey: \"abcdef1234567890\",\n address: \"3kFkntk2H5FGMzeR3GjQKPhdZK9LShKdPHsj2fiGKCdmDXj2WB\",\n network: \"mainnet\",\n deviceModelId: DeviceModelId.FLEX,\n challenge: \"0xabcdef\",\n };\n\n it(\"should return true for valid input with ACCOUNT_OWNERSHIP type\", () => {\n expect(\n loader.canHandle(validInput, [ClearSignContextType.ACCOUNT_OWNERSHIP]),\n ).toBe(true);\n });\n\n it(\"should return false when expected types include unsupported types\", () => {\n expect(loader.canHandle(validInput, [ClearSignContextType.TOKEN])).toBe(\n false,\n );\n expect(\n loader.canHandle(validInput, [ClearSignContextType.TRUSTED_NAME]),\n ).toBe(false);\n });\n\n it(\"should return true when expected types include ACCOUNT_OWNERSHIP among others\", () => {\n expect(\n loader.canHandle(validInput, [\n ClearSignContextType.ACCOUNT_OWNERSHIP,\n ClearSignContextType.TOKEN,\n ]),\n ).toBe(true);\n });\n\n it.each([\n [null, \"null input\"],\n [undefined, \"undefined input\"],\n [{}, \"empty object\"],\n [\"string\", \"string input\"],\n [123, \"number input\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(\n loader.canHandle(input, [ClearSignContextType.ACCOUNT_OWNERSHIP]),\n ).toBe(false);\n });\n\n it.each([\n [{ ...validInput, publicKey: undefined }, \"missing publicKey\"],\n [{ ...validInput, address: undefined }, \"missing address\"],\n [{ ...validInput, network: undefined }, \"missing network\"],\n [{ ...validInput, deviceModelId: undefined }, \"missing deviceModelId\"],\n [{ ...validInput, challenge: undefined }, \"missing challenge\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(\n loader.canHandle(input, [ClearSignContextType.ACCOUNT_OWNERSHIP]),\n ).toBe(false);\n });\n\n it.each([\n [{ ...validInput, publicKey: \"\" }, \"empty publicKey\"],\n [{ ...validInput, address: \"\" }, \"empty address\"],\n [{ ...validInput, challenge: \"\" }, \"empty challenge\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(\n loader.canHandle(input, [ClearSignContextType.ACCOUNT_OWNERSHIP]),\n ).toBe(false);\n });\n\n it(\"should return false for invalid network value\", () => {\n expect(\n loader.canHandle({ ...validInput, network: \"devnet\" }, [\n ClearSignContextType.ACCOUNT_OWNERSHIP,\n ]),\n ).toBe(false);\n });\n\n it(\"should return true for testnet network\", () => {\n expect(\n loader.canHandle({ ...validInput, network: \"testnet\" }, [\n ClearSignContextType.ACCOUNT_OWNERSHIP,\n ]),\n ).toBe(true);\n });\n\n it(\"should return true for different device models\", () => {\n for (const deviceModelId of [\n DeviceModelId.NANO_S,\n DeviceModelId.NANO_SP,\n DeviceModelId.NANO_X,\n DeviceModelId.STAX,\n DeviceModelId.FLEX,\n ]) {\n expect(\n loader.canHandle({ ...validInput, deviceModelId }, [\n ClearSignContextType.ACCOUNT_OWNERSHIP,\n ]),\n ).toBe(true);\n }\n });\n });\n\n describe(\"load\", () => {\n const input: AccountOwnershipContextInput = {\n publicKey: \"abcdef1234567890\",\n address: \"3kFkntk2H5FGMzeR3GjQKPhdZK9LShKdPHsj2fiGKCdmDXj2WB\",\n network: \"mainnet\",\n deviceModelId: DeviceModelId.FLEX,\n challenge: \"0xabcdef\",\n };\n\n it(\"should return ACCOUNT_OWNERSHIP context with certificate\", async () => {\n // GIVEN\n vi.spyOn(mockDataSource, \"getDescriptor\").mockResolvedValue(\n Right(mockDescriptor),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(mockDataSource.getDescriptor).toHaveBeenCalledWith({\n publicKey: \"abcdef1234567890\",\n address: \"3kFkntk2H5FGMzeR3GjQKPhdZK9LShKdPHsj2fiGKCdmDXj2WB\",\n challenge: \"0xabcdef\",\n network: \"mainnet\",\n });\n expect(mockPkiCertificateLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: \"domain_metadata_key\",\n keyUsage: \"trusted_name\",\n targetDevice: DeviceModelId.FLEX,\n });\n expect(result).toEqual([\n {\n type: ClearSignContextType.ACCOUNT_OWNERSHIP,\n payload: \"account-ownership-descriptor-payload\",\n certificate: mockCertificate,\n },\n ]);\n });\n\n it(\"should return ACCOUNT_OWNERSHIP context without certificate when loadCertificate returns undefined\", async () => {\n // GIVEN\n vi.spyOn(mockDataSource, \"getDescriptor\").mockResolvedValue(\n Right(mockDescriptor),\n );\n vi.spyOn(mockPkiCertificateLoader, \"loadCertificate\").mockResolvedValue(\n undefined,\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ACCOUNT_OWNERSHIP,\n payload: \"account-ownership-descriptor-payload\",\n certificate: undefined,\n },\n ]);\n });\n\n it(\"should return ERROR context when data source returns Left\", async () => {\n // GIVEN\n const error = new Error(\"Failed to get descriptor\");\n vi.spyOn(mockDataSource, \"getDescriptor\").mockResolvedValue(Left(error));\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error,\n },\n ]);\n expect(mockPkiCertificateLoader.loadCertificate).not.toHaveBeenCalled();\n });\n\n it(\"should pass correct device model to certificate loader\", async () => {\n // GIVEN\n const inputNanoX = { ...input, deviceModelId: DeviceModelId.NANO_X };\n vi.spyOn(mockDataSource, \"getDescriptor\").mockResolvedValue(\n Right(mockDescriptor),\n );\n\n // WHEN\n await loader.load(inputNanoX);\n\n // THEN\n expect(mockPkiCertificateLoader.loadCertificate).toHaveBeenCalledWith(\n expect.objectContaining({\n targetDevice: DeviceModelId.NANO_X,\n }),\n );\n });\n\n it(\"should pass testnet network to data source\", async () => {\n // GIVEN\n const inputTestnet = { ...input, network: \"testnet\" as const };\n vi.spyOn(mockDataSource, \"getDescriptor\").mockResolvedValue(\n Right(mockDescriptor),\n );\n\n // WHEN\n await loader.load(inputTestnet);\n\n // THEN\n expect(mockDataSource.getDescriptor).toHaveBeenCalledWith(\n expect.objectContaining({\n network: \"testnet\",\n }),\n );\n });\n\n it(\"should handle long descriptor payloads\", async () => {\n // GIVEN\n const longPayload = \"a\".repeat(1000);\n vi.spyOn(mockDataSource, \"getDescriptor\").mockResolvedValue(\n Right({ ...mockDescriptor, signedDescriptor: longPayload }),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect((result[0] as ClearSignContextSuccess).payload).toBe(longPayload);\n });\n });\n});\n"],
5
+ "mappings": "AAAA,OAAS,iBAAAA,MAAqB,kCAC9B,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAM5B,OAEE,iCAAAC,MACK,2DAGP,OAEE,wBAAAC,MACK,kCAEP,SAAS,gCAAiC,IAAM,CAC9C,MAAMC,EAA6C,CACjD,cAAe,GAAG,GAAG,CACvB,EACMC,EAAiD,CACrD,gBAAiB,GAAG,GAAG,CACzB,EACMC,EAAS,IAAIJ,EACjBE,EACAC,CACF,EAEME,EAAkC,CACtC,eAAgB,EAChB,QAAS,IAAI,WAAW,CAAC,EAAG,EAAG,CAAC,CAAC,CACnC,EAEMC,EAA6C,CACjD,iBAAkB,uCAClB,MAAO,sBACP,SAAU,cACZ,EAEA,WAAW,IAAM,CACf,GAAG,cAAc,EACjB,GAAG,MAAMH,EAA0B,iBAAiB,EAAE,kBACpDE,CACF,CACF,CAAC,EAED,SAAS,YAAa,IAAM,CAC1B,MAAME,EAA2C,CAC/C,UAAW,mBACX,QAAS,qDACT,QAAS,UACT,cAAeV,EAAc,KAC7B,UAAW,UACb,EAEA,GAAG,iEAAkE,IAAM,CACzE,OACEO,EAAO,UAAUG,EAAY,CAACN,EAAqB,iBAAiB,CAAC,CACvE,EAAE,KAAK,EAAI,CACb,CAAC,EAED,GAAG,oEAAqE,IAAM,CAC5E,OAAOG,EAAO,UAAUG,EAAY,CAACN,EAAqB,KAAK,CAAC,CAAC,EAAE,KACjE,EACF,EACA,OACEG,EAAO,UAAUG,EAAY,CAACN,EAAqB,YAAY,CAAC,CAClE,EAAE,KAAK,EAAK,CACd,CAAC,EAED,GAAG,gFAAiF,IAA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QG,EAAO,CAAC,EAA8B,OAAO,EAAE,KAAKI,CAAW,CACzE,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["DeviceModelId", "Left", "Right", "AccountOwnershipContextLoader", "ClearSignContextType", "mockDataSource", "mockPkiCertificateLoader", "loader", "mockCertificate", "mockDescriptor", "validInput", "input", "_description", "deviceModelId", "result", "error", "inputNanoX", "inputTestnet", "longPayload"]
7
+ }
@@ -1,2 +1,2 @@
1
- var I=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var h=(l,e,t,r)=>{for(var i=r>1?void 0:r?S(e,t):e,n=l.length-1,o;n>=0;n--)(o=l[n])&&(i=(r?o(e,t,i):o(i))||i);return r&&i&&I(e,t,i),i},y=(l,e)=>(t,r)=>e(t,r,l);import M from"axios";import{inject as m,injectable as R}from"inversify";import{Left as c,Right as L}from"purify-ts";import{configTypes as x}from"../../config/di/configTypes";import{pkiTypes as O}from"../../pki/di/pkiTypes";import{KeyId as F}from"../../pki/model/KeyId";import{KeyUsage as G}from"../../pki/model/KeyUsage";import{LEDGER_CLIENT_VERSION_HEADER as k,LEDGER_ORIGIN_TOKEN_HEADER as U}from"../../shared/constant/HttpHeaders";import{ClearSignContextReferenceType as a,ClearSignContextType as f}from"../../shared/model/ClearSignContext";import{INFO_SIGNATURE_TAG as D}from"../../shared/model/SignatureTags";import{HexStringUtils as E}from"../../shared/utils/HexStringUtils";import j from"../../../package.json";let u=class{constructor(e,t,r){this.config=e;this._certificateLoader=t;this.endpoint=r}async getCalldataDescriptors({chainId:e,address:t,selector:r,deviceModelId:i}){let n;try{n=(await M.request({method:"GET",url:`${this.config.cal.url}/${this.endpoint}`,params:{output:"descriptors_calldata",chain_id:e,contracts:t,contract_address:t,ref:`branch:${this.config.cal.branch}`},headers:{[k]:`context-module/${j.version}`,[U]:this.config.originToken}})).data}catch(o){return c(new Error(`[ContextModule] HttpCalldataDescriptorDataSource: Failed to fetch calldata descriptors: ${o}`))}if(!Array.isArray(n))return c(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Response is not an array"));if(n.length===0)return c(new Error(`[ContextModule] HttpCalldataDescriptorDataSource: No data for contract ${t} and selector ${r}`));for(const o of n){t=t.toLowerCase(),r=`0x${r.slice(2).toLowerCase()}`;const s=o.descriptors_calldata?.[t]?.[r];if(!s||!this.isCalldataDescriptorV1(s,this.config.cal.mode))continue;const V=s.transaction_info.descriptor.data,T=s.transaction_info.descriptor.signatures[this.config.cal.mode],g={targetDevice:i,keyUsage:G.Calldata,keyId:F.CalCalldataKey},C=await this._certificateLoader.loadCertificate(g),A={type:f.TRANSACTION_INFO,payload:E.appendSignatureToPayload(V,T,D),certificate:C},d=[];for(const[p,b]of Object.entries(s.enums))for(const[v,{data:P,signatures:N}]of Object.entries(b))d.push({type:f.ENUM,id:Number(p),value:Number(v),payload:E.appendSignatureToPayload(P,N[this.config.cal.mode],D),certificate:C});const _=s.fields.map(p=>({type:f.TRANSACTION_FIELD_DESCRIPTION,payload:p.descriptor,reference:this.getReference(p.param)}));return L([A,...d,..._])}return c(new Error(`[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract ${t} and selector ${r}`))}getReference(e){if(e.type==="TOKEN_AMOUNT"&&e.token!==void 0&&e.token.type==="path")return{type:a.TOKEN,valuePath:this.toGenericPath(e.token.binary_path)};if(e.type==="TOKEN_AMOUNT"&&e.token!==void 0&&e.token.type==="constant")return{type:a.TOKEN,value:e.token.value};if(e.type==="NFT"&&e.collection.type==="path")return{type:a.NFT,valuePath:this.toGenericPath(e.collection.binary_path)};if(e.type==="NFT"&&e.collection.type==="constant")return{type:a.NFT,value:e.collection.value};if(e.type==="TRUSTED_NAME"&&e.value.type==="path")return{type:a.TRUSTED_NAME,valuePath:this.toGenericPath(e.value.binary_path),types:e.types,sources:e.sources};if(e.type==="ENUM"&&e.value.type==="path")return{type:a.ENUM,valuePath:this.toGenericPath(e.value.binary_path),id:e.id};if(e.type==="CALLDATA"&&e.value.type==="path"&&e.callee.type==="path")return{type:a.CALLDATA,valuePath:this.toGenericPath(e.value.binary_path),callee:this.toGenericPath(e.callee.binary_path),selector:e.selector?.type==="path"?this.toGenericPath(e.selector.binary_path):void 0,amount:e.amount?.type==="path"?this.toGenericPath(e.amount.binary_path):void 0,spender:e.spender?.type==="path"?this.toGenericPath(e.spender.binary_path):void 0,chainId:e.chainId?.type==="path"?this.toGenericPath(e.chainId.binary_path):void 0}}toGenericPath(e){return e.type==="CONTAINER"?e.value:e.elements.map(t=>{if(t.type==="ARRAY"){const{weight:r,...i}=t;return{itemSize:r,...i}}else if(t.type==="LEAF"){const{leaf_type:r,...i}=t;return{leafType:r,...i}}return t})}isCalldataDescriptorV1(e,t){return typeof e=="object"&&e.type==="calldata"&&e.version==="v1"&&this.isTransactionInfoV1(e.transaction_info,t)&&this.isEnumV1(e.enums,t)&&Array.isArray(e.fields)&&e.fields.every(r=>this.isFieldV1(r))}isTransactionInfoV1(e,t){return typeof e=="object"&&typeof e.descriptor=="object"&&typeof e.descriptor.data=="string"&&typeof e.descriptor.signatures=="object"&&typeof e.descriptor.signatures[t]=="string"}isEnumV1(e,t){return typeof e=="object"&&Object.entries(e).every(([r,i])=>typeof r=="string"&&typeof i=="object"&&Object.entries(i).every(([n,o])=>typeof n=="string"&&typeof o=="object"&&typeof o.data=="string"&&o.signatures!==void 0&&this.isCalldataSignatures(o.signatures,t)))}isCalldataSignatures(e,t){return typeof e=="object"&&typeof e[t]=="string"}isFieldV1(e){return typeof e=="object"&&typeof e.descriptor=="string"&&typeof e.param=="object"&&typeof e.param.value=="object"&&this.isDescriptorValueV1(e.param.value)&&(e.param.type==="RAW"||e.param.type==="AMOUNT"||e.param.type==="DATETIME"||e.param.type==="DURATION"||e.param.type==="UNIT"||e.param.type==="ENUM"||e.param.type==="NFT"&&this.isDescriptorValueV1(e.param.collection)||e.param.type==="TOKEN_AMOUNT"&&(e.param.token===void 0||this.isDescriptorValueV1(e.param.token))||e.param.type==="TRUSTED_NAME"&&Array.isArray(e.param.types)&&Array.isArray(e.param.sources)&&e.param.types.every(t=>typeof t=="string")&&e.param.sources.every(t=>typeof t=="string")||e.param.type==="CALLDATA"&&this.isDescriptorValueV1(e.param.value)&&this.isDescriptorValueV1(e.param.callee)&&(e.param.selector===void 0||this.isDescriptorValueV1(e.param.selector))&&(e.param.amount===void 0||this.isDescriptorValueV1(e.param.amount))&&(e.param.spender===void 0||this.isDescriptorValueV1(e.param.spender))&&(e.param.chainId===void 0||this.isDescriptorValueV1(e.param.chainId)))}isDescriptorValueV1(e){return typeof e=="object"&&typeof e.type_family=="string"&&["UINT","INT","UFIXED","FIXED","ADDRESS","BOOL","BYTES","STRING"].includes(e.type_family)&&(typeof e.type_size>"u"||typeof e.type_size=="number")&&(e.type==="path"&&this.isCalldataDescriptorValueBinaryPathV1(e)||e.type==="constant"&&this.isCalldataDescriptorValueConstantV1(e))}isCalldataDescriptorValueConstantV1(e){return typeof e=="object"&&e.type==="constant"&&typeof e.value=="string"}isCalldataDescriptorValueBinaryPathV1(e){return typeof e=="object"&&(e.type==="path"&&e.binary_path.type==="CONTAINER"&&["FROM","TO","VALUE"].includes(e.binary_path.value)||e.binary_path.type==="DATA"&&Array.isArray(e.binary_path.elements)&&e.binary_path.elements.every(t=>this.isPathElementV1(t)))}isPathElementV1(e){return typeof e=="object"&&(e.type==="REF"||e.type==="TUPLE"&&typeof e.offset=="number"||e.type==="ARRAY"&&typeof e.weight=="number"&&(typeof e.start>"u"||typeof e.start=="number")&&(typeof e.end>"u"||typeof e.end=="number")||e.type==="LEAF"&&typeof e.leaf_type=="string"&&["ARRAY_LEAF","TUPLE_LEAF","STATIC_LEAF","DYNAMIC_LEAF"].includes(e.leaf_type)||e.type==="SLICE"&&(typeof e.start>"u"||typeof e.start=="number")&&(typeof e.end>"u"||typeof e.end=="number"))}};u=h([R(),y(0,m(x.Config)),y(1,m(O.PkiCertificateLoader))],u);export{u as HttpCalldataDescriptorDataSource};
1
+ var S=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var m=(l,e,t,r)=>{for(var i=r>1?void 0:r?I(e,t):e,n=l.length-1,o;n>=0;n--)(o=l[n])&&(i=(r?o(e,t,i):o(i))||i);return r&&i&&S(e,t,i),i},c=(l,e)=>(t,r)=>e(t,r,l);import{inject as f,injectable as M}from"inversify";import{Left as y,Right as R}from"purify-ts";import{configTypes as k}from"../../config/di/configTypes";import{networkTypes as x}from"../../network/di/networkTypes";import{pkiTypes as L}from"../../pki/di/pkiTypes";import{KeyId as O}from"../../pki/model/KeyId";import{KeyUsage as F}from"../../pki/model/KeyUsage";import{ClearSignContextReferenceType as a,ClearSignContextType as C}from"../../shared/model/ClearSignContext";import{INFO_SIGNATURE_TAG as D}from"../../shared/model/SignatureTags";import{HexStringUtils as V}from"../../shared/utils/HexStringUtils";let u=class{constructor(e,t,r,i){this.config=e;this._certificateLoader=t;this.endpoint=r;this.http=i}async getCalldataDescriptors({chainId:e,address:t,selector:r,deviceModelId:i}){let n;try{n=await this.http.get(`${this.config.cal.url}/${this.endpoint}`,{params:{output:"descriptors_calldata",chain_id:e,contracts:t,contract_address:t,ref:`branch:${this.config.cal.branch}`}})}catch(o){return y(new Error(`[ContextModule] HttpCalldataDescriptorDataSource: Failed to fetch calldata descriptors: ${o}`))}if(!Array.isArray(n))return y(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Response is not an array"));if(n.length===0)return y(new Error(`[ContextModule] HttpCalldataDescriptorDataSource: No data for contract ${t} and selector ${r}`));for(const o of n){t=t.toLowerCase(),r=`0x${r.slice(2).toLowerCase()}`;const s=o.descriptors_calldata?.[t]?.[r];if(!s||!this.isCalldataDescriptorV1(s,this.config.cal.mode))continue;const g=s.transaction_info.descriptor.data,T=s.transaction_info.descriptor.signatures[this.config.cal.mode],A={targetDevice:i,keyUsage:F.Calldata,keyId:O.CalCalldataKey},d=await this._certificateLoader.loadCertificate(A),E={type:C.TRANSACTION_INFO,payload:V.appendSignatureToPayload(g,T,D),certificate:d},h=[];for(const[p,_]of Object.entries(s.enums))for(const[b,{data:P,signatures:N}]of Object.entries(_))h.push({type:C.ENUM,id:Number(p),value:Number(b),payload:V.appendSignatureToPayload(P,N[this.config.cal.mode],D),certificate:d});const v=s.fields.map(p=>({type:C.TRANSACTION_FIELD_DESCRIPTION,payload:p.descriptor,reference:this.getReference(p.param)}));return R([E,...h,...v])}return y(new Error(`[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract ${t} and selector ${r}`))}getReference(e){if(e.type==="TOKEN_AMOUNT"&&e.token!==void 0&&e.token.type==="path")return{type:a.TOKEN,valuePath:this.toGenericPath(e.token.binary_path)};if(e.type==="TOKEN_AMOUNT"&&e.token!==void 0&&e.token.type==="constant")return{type:a.TOKEN,value:e.token.value};if(e.type==="NFT"&&e.collection.type==="path")return{type:a.NFT,valuePath:this.toGenericPath(e.collection.binary_path)};if(e.type==="NFT"&&e.collection.type==="constant")return{type:a.NFT,value:e.collection.value};if(e.type==="TRUSTED_NAME"&&e.value.type==="path")return{type:a.TRUSTED_NAME,valuePath:this.toGenericPath(e.value.binary_path),types:e.types,sources:e.sources};if(e.type==="ENUM"&&e.value.type==="path")return{type:a.ENUM,valuePath:this.toGenericPath(e.value.binary_path),id:e.id};if(e.type==="CALLDATA"&&e.value.type==="path"&&e.callee.type==="path")return{type:a.CALLDATA,valuePath:this.toGenericPath(e.value.binary_path),callee:this.toGenericPath(e.callee.binary_path),selector:e.selector?.type==="path"?this.toGenericPath(e.selector.binary_path):void 0,amount:e.amount?.type==="path"?this.toGenericPath(e.amount.binary_path):void 0,spender:e.spender?.type==="path"?this.toGenericPath(e.spender.binary_path):void 0,chainId:e.chainId?.type==="path"?this.toGenericPath(e.chainId.binary_path):void 0}}toGenericPath(e){return e.type==="CONTAINER"?e.value:e.elements.map(t=>{if(t.type==="ARRAY"){const{weight:r,...i}=t;return{itemSize:r,...i}}else if(t.type==="LEAF"){const{leaf_type:r,...i}=t;return{leafType:r,...i}}return t})}isCalldataDescriptorV1(e,t){return typeof e=="object"&&e.type==="calldata"&&e.version==="v1"&&this.isTransactionInfoV1(e.transaction_info,t)&&this.isEnumV1(e.enums,t)&&Array.isArray(e.fields)&&e.fields.every(r=>this.isFieldV1(r))}isTransactionInfoV1(e,t){return typeof e=="object"&&typeof e.descriptor=="object"&&typeof e.descriptor.data=="string"&&typeof e.descriptor.signatures=="object"&&typeof e.descriptor.signatures[t]=="string"}isEnumV1(e,t){return typeof e=="object"&&Object.entries(e).every(([r,i])=>typeof r=="string"&&typeof i=="object"&&Object.entries(i).every(([n,o])=>typeof n=="string"&&typeof o=="object"&&typeof o.data=="string"&&o.signatures!==void 0&&this.isCalldataSignatures(o.signatures,t)))}isCalldataSignatures(e,t){return typeof e=="object"&&typeof e[t]=="string"}isFieldV1(e){return typeof e=="object"&&typeof e.descriptor=="string"&&typeof e.param=="object"&&typeof e.param.value=="object"&&this.isDescriptorValueV1(e.param.value)&&(e.param.type==="RAW"||e.param.type==="AMOUNT"||e.param.type==="DATETIME"||e.param.type==="DURATION"||e.param.type==="UNIT"||e.param.type==="ENUM"||e.param.type==="NFT"&&this.isDescriptorValueV1(e.param.collection)||e.param.type==="TOKEN_AMOUNT"&&(e.param.token===void 0||this.isDescriptorValueV1(e.param.token))||e.param.type==="TRUSTED_NAME"&&Array.isArray(e.param.types)&&Array.isArray(e.param.sources)&&e.param.types.every(t=>typeof t=="string")&&e.param.sources.every(t=>typeof t=="string")||e.param.type==="CALLDATA"&&this.isDescriptorValueV1(e.param.value)&&this.isDescriptorValueV1(e.param.callee)&&(e.param.selector===void 0||this.isDescriptorValueV1(e.param.selector))&&(e.param.amount===void 0||this.isDescriptorValueV1(e.param.amount))&&(e.param.spender===void 0||this.isDescriptorValueV1(e.param.spender))&&(e.param.chainId===void 0||this.isDescriptorValueV1(e.param.chainId)))}isDescriptorValueV1(e){return typeof e=="object"&&typeof e.type_family=="string"&&["UINT","INT","UFIXED","FIXED","ADDRESS","BOOL","BYTES","STRING"].includes(e.type_family)&&(typeof e.type_size>"u"||typeof e.type_size=="number")&&(e.type==="path"&&this.isCalldataDescriptorValueBinaryPathV1(e)||e.type==="constant"&&this.isCalldataDescriptorValueConstantV1(e))}isCalldataDescriptorValueConstantV1(e){return typeof e=="object"&&e.type==="constant"&&typeof e.value=="string"}isCalldataDescriptorValueBinaryPathV1(e){return typeof e=="object"&&(e.type==="path"&&e.binary_path.type==="CONTAINER"&&["FROM","TO","VALUE"].includes(e.binary_path.value)||e.binary_path.type==="DATA"&&Array.isArray(e.binary_path.elements)&&e.binary_path.elements.every(t=>this.isPathElementV1(t)))}isPathElementV1(e){return typeof e=="object"&&(e.type==="REF"||e.type==="TUPLE"&&typeof e.offset=="number"||e.type==="ARRAY"&&typeof e.weight=="number"&&(typeof e.start>"u"||typeof e.start=="number")&&(typeof e.end>"u"||typeof e.end=="number")||e.type==="LEAF"&&typeof e.leaf_type=="string"&&["ARRAY_LEAF","TUPLE_LEAF","STATIC_LEAF","DYNAMIC_LEAF"].includes(e.leaf_type)||e.type==="SLICE"&&(typeof e.start>"u"||typeof e.start=="number")&&(typeof e.end>"u"||typeof e.end=="number"))}};u=m([M(),c(0,f(k.Config)),c(1,f(L.PkiCertificateLoader)),c(3,f(x.NetworkClient))],u);export{u as HttpCalldataDescriptorDataSource};
2
2
  //# sourceMappingURL=HttpCalldataDescriptorDataSource.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/calldata/data/HttpCalldataDescriptorDataSource.ts"],
4
- "sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport {\n type ContextModuleCalMode,\n type ContextModuleConfig,\n} from \"@/config/model/ContextModuleConfig\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { PkiCertificateInfo } from \"@/pki/model/PkiCertificateInfo\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport {\n ClearSignContextReference,\n ClearSignContextReferenceType,\n ClearSignContextSuccess,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { GenericPath } from \"@/shared/model/GenericPath\";\nimport { INFO_SIGNATURE_TAG } from \"@/shared/model/SignatureTags\";\nimport { HexStringUtils } from \"@/shared/utils/HexStringUtils\";\nimport PACKAGE from \"@root/package.json\";\n\nimport {\n CalldataDescriptor,\n CalldataDescriptorContainerPathV1,\n CalldataDescriptorParam,\n CalldataDescriptorPathElementsV1,\n CalldataDescriptorPathElementV1,\n CalldataDescriptorV1,\n CalldataDescriptorValueBinaryPathV1,\n CalldataDescriptorValueConstantV1,\n CalldataDescriptorValueV1,\n CalldataDto,\n CalldataEnumV1,\n CalldataFieldV1,\n CalldataSignatures,\n CalldataTransactionDescriptor,\n CalldataTransactionInfoV1,\n} from \"./dto/CalldataDto\";\nimport {\n CalldataDescriptorDataSource,\n GetCalldataDescriptorsParams,\n} from \"./CalldataDescriptorDataSource\";\n\n@injectable()\nexport class HttpCalldataDescriptorDataSource\n implements CalldataDescriptorDataSource\n{\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n private readonly endpoint: string,\n ) {}\n\n public async getCalldataDescriptors({\n chainId,\n address,\n selector,\n deviceModelId,\n }: GetCalldataDescriptorsParams): Promise<\n Either<Error, ClearSignContextSuccess[]>\n > {\n let dto: CalldataDto[] | undefined;\n try {\n const response = await axios.request<CalldataDto[]>({\n method: \"GET\",\n url: `${this.config.cal.url}/${this.endpoint}`,\n params: {\n output: \"descriptors_calldata\",\n chain_id: chainId,\n contracts: address, // used for dapps\n contract_address: address, // used for tokens\n ref: `branch:${this.config.cal.branch}`,\n },\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n dto = response.data;\n } catch (error) {\n return Left(\n new Error(\n `[ContextModule] HttpCalldataDescriptorDataSource: Failed to fetch calldata descriptors: ${error}`,\n ),\n );\n }\n\n if (!Array.isArray(dto)) {\n return Left(\n new Error(\n `[ContextModule] HttpCalldataDescriptorDataSource: Response is not an array`,\n ),\n );\n }\n\n if (dto.length === 0) {\n return Left(\n new Error(\n `[ContextModule] HttpCalldataDescriptorDataSource: No data for contract ${address} and selector ${selector}`,\n ),\n );\n }\n\n for (const calldata of dto) {\n // Normalize the address and selector\n address = address.toLowerCase();\n selector = `0x${selector.slice(2).toLowerCase()}`;\n const calldataDescriptor =\n calldata.descriptors_calldata?.[address]?.[selector];\n\n if (\n !calldataDescriptor ||\n !this.isCalldataDescriptorV1(calldataDescriptor, this.config.cal.mode)\n ) {\n continue;\n }\n\n const infoData = calldataDescriptor.transaction_info.descriptor.data;\n const infoSignature =\n calldataDescriptor.transaction_info.descriptor.signatures[\n this.config.cal.mode\n ];\n\n const certificateInfos: PkiCertificateInfo = {\n targetDevice: deviceModelId,\n keyUsage: KeyUsage.Calldata,\n keyId: KeyId.CalCalldataKey,\n };\n const certificate: PkiCertificate | undefined =\n await this._certificateLoader.loadCertificate(certificateInfos);\n\n const info: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: HexStringUtils.appendSignatureToPayload(\n infoData,\n infoSignature,\n INFO_SIGNATURE_TAG,\n ),\n certificate,\n };\n\n const enums: ClearSignContextSuccess[] = [];\n for (const [id, values] of Object.entries(calldataDescriptor.enums)) {\n for (const [\n value,\n { data, signatures },\n ] of Object.entries<CalldataTransactionDescriptor>(values)) {\n enums.push({\n type: ClearSignContextType.ENUM,\n id: Number(id),\n value: Number(value),\n payload: HexStringUtils.appendSignatureToPayload(\n data,\n signatures[this.config.cal.mode]!,\n INFO_SIGNATURE_TAG,\n ),\n certificate,\n });\n }\n }\n\n const fields: ClearSignContextSuccess[] = calldataDescriptor.fields.map(\n (field) => ({\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: field.descriptor,\n reference: this.getReference(field.param),\n }),\n );\n return Right([info, ...enums, ...fields]);\n }\n\n return Left(\n new Error(\n `[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract ${address} and selector ${selector}`,\n ),\n );\n }\n\n private getReference(\n param: CalldataDescriptorParam,\n ): ClearSignContextReference | undefined {\n if (\n param.type === \"TOKEN_AMOUNT\" &&\n param.token !== undefined &&\n param.token.type === \"path\"\n ) {\n return {\n type: ClearSignContextReferenceType.TOKEN,\n valuePath: this.toGenericPath(param.token.binary_path),\n };\n } else if (\n param.type === \"TOKEN_AMOUNT\" &&\n param.token !== undefined &&\n param.token.type === \"constant\"\n ) {\n return {\n type: ClearSignContextReferenceType.TOKEN,\n value: param.token.value,\n };\n } else if (param.type === \"NFT\" && param.collection.type === \"path\") {\n return {\n type: ClearSignContextReferenceType.NFT,\n valuePath: this.toGenericPath(param.collection.binary_path),\n };\n } else if (param.type === \"NFT\" && param.collection.type === \"constant\") {\n return {\n type: ClearSignContextReferenceType.NFT,\n value: param.collection.value,\n };\n } else if (param.type === \"TRUSTED_NAME\" && param.value.type === \"path\") {\n return {\n type: ClearSignContextReferenceType.TRUSTED_NAME,\n valuePath: this.toGenericPath(param.value.binary_path),\n types: param.types,\n sources: param.sources,\n };\n } else if (param.type === \"ENUM\" && param.value.type === \"path\") {\n return {\n type: ClearSignContextReferenceType.ENUM,\n valuePath: this.toGenericPath(param.value.binary_path),\n id: param.id,\n };\n } else if (\n param.type === \"CALLDATA\" &&\n param.value.type === \"path\" &&\n param.callee.type === \"path\"\n ) {\n return {\n type: ClearSignContextReferenceType.CALLDATA,\n valuePath: this.toGenericPath(param.value.binary_path),\n callee: this.toGenericPath(param.callee.binary_path),\n selector:\n param.selector?.type === \"path\"\n ? this.toGenericPath(param.selector.binary_path)\n : undefined,\n amount:\n param.amount?.type === \"path\"\n ? this.toGenericPath(param.amount.binary_path)\n : undefined,\n spender:\n param.spender?.type === \"path\"\n ? this.toGenericPath(param.spender.binary_path)\n : undefined,\n chainId:\n param.chainId?.type === \"path\"\n ? this.toGenericPath(param.chainId.binary_path)\n : undefined,\n };\n }\n return undefined;\n }\n\n private toGenericPath(\n path: CalldataDescriptorContainerPathV1 | CalldataDescriptorPathElementsV1,\n ): GenericPath {\n if (path.type === \"CONTAINER\") {\n return path.value;\n }\n return path.elements.map((element) => {\n if (element.type === \"ARRAY\") {\n const { weight: itemSize, ...rest } = element;\n return {\n itemSize,\n ...rest,\n };\n } else if (element.type === \"LEAF\") {\n const { leaf_type: leafType, ...rest } = element;\n return {\n leafType,\n ...rest,\n };\n }\n return element;\n });\n }\n\n private isCalldataDescriptorV1(\n data: CalldataDescriptor,\n mode: ContextModuleCalMode,\n ): data is CalldataDescriptorV1 & {\n transaction_info: {\n descriptor: {\n signatures: { [_key in ContextModuleCalMode]: string };\n };\n };\n } {\n return (\n typeof data === \"object\" &&\n data.type === \"calldata\" &&\n data.version === \"v1\" &&\n this.isTransactionInfoV1(data.transaction_info, mode) &&\n this.isEnumV1(data.enums, mode) &&\n Array.isArray(data.fields) &&\n data.fields.every((f) => this.isFieldV1(f))\n );\n }\n\n private isTransactionInfoV1(\n data: CalldataTransactionInfoV1,\n mode: ContextModuleCalMode,\n ): data is CalldataTransactionInfoV1 & {\n descriptor: {\n signatures: { [_key in ContextModuleCalMode]: string };\n };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.descriptor === \"object\" &&\n typeof data.descriptor.data === \"string\" &&\n typeof data.descriptor.signatures === \"object\" &&\n typeof data.descriptor.signatures[mode] === \"string\"\n );\n }\n\n private isEnumV1(\n calldata: CalldataEnumV1,\n mode: ContextModuleCalMode,\n ): calldata is CalldataEnumV1 {\n return (\n typeof calldata === \"object\" &&\n Object.entries(calldata).every(\n ([id, values]) =>\n typeof id === \"string\" &&\n typeof values === \"object\" &&\n Object.entries<CalldataTransactionDescriptor>(values).every(\n ([value, obj]) =>\n typeof value === \"string\" &&\n typeof obj === \"object\" &&\n typeof obj.data === \"string\" &&\n obj.signatures !== undefined &&\n this.isCalldataSignatures(obj.signatures, mode),\n ),\n )\n );\n }\n\n private isCalldataSignatures(\n data: CalldataSignatures,\n mode: ContextModuleCalMode,\n ): data is CalldataSignatures & { [_key in ContextModuleCalMode]: string } {\n return typeof data === \"object\" && typeof data[mode] === \"string\";\n }\n\n private isFieldV1(data: CalldataFieldV1): boolean {\n return (\n typeof data === \"object\" &&\n typeof data.descriptor === \"string\" &&\n typeof data.param === \"object\" &&\n typeof data.param.value === \"object\" &&\n this.isDescriptorValueV1(data.param.value) &&\n (data.param.type === \"RAW\" ||\n data.param.type === \"AMOUNT\" ||\n data.param.type === \"DATETIME\" ||\n data.param.type === \"DURATION\" ||\n data.param.type === \"UNIT\" ||\n data.param.type === \"ENUM\" ||\n (data.param.type === \"NFT\" &&\n this.isDescriptorValueV1(data.param.collection)) ||\n (data.param.type === \"TOKEN_AMOUNT\" &&\n (data.param.token === undefined ||\n this.isDescriptorValueV1(data.param.token))) ||\n (data.param.type === \"TRUSTED_NAME\" &&\n Array.isArray(data.param.types) &&\n Array.isArray(data.param.sources) &&\n data.param.types.every((t) => typeof t === \"string\") &&\n data.param.sources.every((t) => typeof t === \"string\")) ||\n (data.param.type === \"CALLDATA\" &&\n this.isDescriptorValueV1(data.param.value) &&\n this.isDescriptorValueV1(data.param.callee) &&\n (data.param.selector === undefined ||\n this.isDescriptorValueV1(data.param.selector)) &&\n (data.param.amount === undefined ||\n this.isDescriptorValueV1(data.param.amount)) &&\n (data.param.spender === undefined ||\n this.isDescriptorValueV1(data.param.spender)) &&\n (data.param.chainId === undefined ||\n this.isDescriptorValueV1(data.param.chainId))))\n );\n }\n\n private isDescriptorValueV1(data: CalldataDescriptorValueV1): boolean {\n return (\n typeof data === \"object\" &&\n typeof data.type_family === \"string\" &&\n [\n \"UINT\",\n \"INT\",\n \"UFIXED\",\n \"FIXED\",\n \"ADDRESS\",\n \"BOOL\",\n \"BYTES\",\n \"STRING\",\n ].includes(data.type_family) &&\n (typeof data.type_size === \"undefined\" ||\n typeof data.type_size === \"number\") &&\n ((data.type === \"path\" &&\n this.isCalldataDescriptorValueBinaryPathV1(data)) ||\n (data.type === \"constant\" &&\n this.isCalldataDescriptorValueConstantV1(data)))\n );\n }\n\n private isCalldataDescriptorValueConstantV1(\n data: CalldataDescriptorValueConstantV1,\n ): boolean {\n return (\n typeof data === \"object\" &&\n data.type === \"constant\" &&\n typeof data.value === \"string\"\n );\n }\n\n private isCalldataDescriptorValueBinaryPathV1(\n data: CalldataDescriptorValueBinaryPathV1,\n ): boolean {\n return (\n typeof data === \"object\" &&\n ((data.type === \"path\" &&\n data.binary_path.type === \"CONTAINER\" &&\n [\"FROM\", \"TO\", \"VALUE\"].includes(data.binary_path.value)) ||\n (data.binary_path.type === \"DATA\" &&\n Array.isArray(data.binary_path.elements) &&\n data.binary_path.elements.every((e) => this.isPathElementV1(e))))\n );\n }\n\n private isPathElementV1(data: CalldataDescriptorPathElementV1): boolean {\n return (\n typeof data === \"object\" &&\n (data.type === \"REF\" ||\n (data.type === \"TUPLE\" && typeof data.offset === \"number\") ||\n (data.type === \"ARRAY\" &&\n typeof data.weight === \"number\" &&\n (typeof data.start === \"undefined\" ||\n typeof data.start === \"number\") &&\n (typeof data.end === \"undefined\" || typeof data.end === \"number\")) ||\n (data.type === \"LEAF\" &&\n typeof data.leaf_type === \"string\" &&\n [\"ARRAY_LEAF\", \"TUPLE_LEAF\", \"STATIC_LEAF\", \"DYNAMIC_LEAF\"].includes(\n data.leaf_type,\n )) ||\n (data.type === \"SLICE\" &&\n (typeof data.start === \"undefined\" ||\n typeof data.start === \"number\") &&\n (typeof data.end === \"undefined\" || typeof data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AAA,EAAAC,EAAOC,EAAY,MAAM,GACzBF,EAAA,EAAAC,EAAOE,EAAS,oBAAoB,IAL5BpD",
6
- "names": ["axios", "inject", "injectable", "Left", "Right", "configTypes", "pkiTypes", "KeyId", "KeyUsage", "LEDGER_CLIENT_VERSION_HEADER", "LEDGER_ORIGIN_TOKEN_HEADER", "ClearSignContextReferenceType", "ClearSignContextType", "INFO_SIGNATURE_TAG", "HexStringUtils", "PACKAGE", "HttpCalldataDescriptorDataSource", "config", "_certificateLoader", "endpoint", "chainId", "address", "selector", "deviceModelId", "dto", "axios", "LEDGER_CLIENT_VERSION_HEADER", "PACKAGE", "LEDGER_ORIGIN_TOKEN_HEADER", "error", "Left", "calldata", "calldataDescriptor", "infoData", "infoSignature", "certificateInfos", "KeyUsage", "KeyId", "certificate", "info", "ClearSignContextType", "HexStringUtils", "INFO_SIGNATURE_TAG", "enums", "id", "values", "value", "data", "signatures", "fields", "field", "Right", "param", "ClearSignContextReferenceType", "path", "element", "itemSize", "rest", "leafType", "mode", "f", "obj", "e", "__decorateClass", "injectable", "__decorateParam", "inject", "configTypes", "pkiTypes"]
4
+ "sourcesContent": ["import { DmkNetworkClient } from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport {\n type ContextModuleCalMode,\n type ContextModuleServiceConfig,\n} from \"@/config/model/ContextModuleConfig\";\nimport { networkTypes } from \"@/network/di/networkTypes\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { PkiCertificateInfo } from \"@/pki/model/PkiCertificateInfo\";\nimport {\n ClearSignContextReference,\n ClearSignContextReferenceType,\n ClearSignContextSuccess,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { GenericPath } from \"@/shared/model/GenericPath\";\nimport { INFO_SIGNATURE_TAG } from \"@/shared/model/SignatureTags\";\nimport { HexStringUtils } from \"@/shared/utils/HexStringUtils\";\n\nimport {\n CalldataDescriptor,\n CalldataDescriptorContainerPathV1,\n CalldataDescriptorParam,\n CalldataDescriptorPathElementsV1,\n CalldataDescriptorPathElementV1,\n CalldataDescriptorV1,\n CalldataDescriptorValueBinaryPathV1,\n CalldataDescriptorValueConstantV1,\n CalldataDescriptorValueV1,\n CalldataDto,\n CalldataEnumV1,\n CalldataFieldV1,\n CalldataSignatures,\n CalldataTransactionDescriptor,\n CalldataTransactionInfoV1,\n} from \"./dto/CalldataDto\";\nimport {\n CalldataDescriptorDataSource,\n GetCalldataDescriptorsParams,\n} from \"./CalldataDescriptorDataSource\";\n\n@injectable()\nexport class HttpCalldataDescriptorDataSource\n implements CalldataDescriptorDataSource\n{\n constructor(\n @inject(configTypes.Config)\n private readonly config: ContextModuleServiceConfig,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n private readonly endpoint: string,\n @inject(networkTypes.NetworkClient)\n private readonly http: DmkNetworkClient,\n ) {}\n\n public async getCalldataDescriptors({\n chainId,\n address,\n selector,\n deviceModelId,\n }: GetCalldataDescriptorsParams): Promise<\n Either<Error, ClearSignContextSuccess[]>\n > {\n let dto: CalldataDto[] | undefined;\n try {\n dto = (await this.http.get(`${this.config.cal.url}/${this.endpoint}`, {\n params: {\n output: \"descriptors_calldata\",\n chain_id: chainId,\n contracts: address,\n contract_address: address,\n ref: `branch:${this.config.cal.branch}`,\n },\n })) as CalldataDto[];\n } catch (error) {\n return Left(\n new Error(\n `[ContextModule] HttpCalldataDescriptorDataSource: Failed to fetch calldata descriptors: ${error}`,\n ),\n );\n }\n\n if (!Array.isArray(dto)) {\n return Left(\n new Error(\n `[ContextModule] HttpCalldataDescriptorDataSource: Response is not an array`,\n ),\n );\n }\n\n if (dto.length === 0) {\n return Left(\n new Error(\n `[ContextModule] HttpCalldataDescriptorDataSource: No data for contract ${address} and selector ${selector}`,\n ),\n );\n }\n\n for (const calldata of dto) {\n // Normalize the address and selector\n address = address.toLowerCase();\n selector = `0x${selector.slice(2).toLowerCase()}`;\n const calldataDescriptor =\n calldata.descriptors_calldata?.[address]?.[selector];\n\n if (\n !calldataDescriptor ||\n !this.isCalldataDescriptorV1(calldataDescriptor, this.config.cal.mode)\n ) {\n continue;\n }\n\n const infoData = calldataDescriptor.transaction_info.descriptor.data;\n const infoSignature =\n calldataDescriptor.transaction_info.descriptor.signatures[\n this.config.cal.mode\n ];\n\n const certificateInfos: PkiCertificateInfo = {\n targetDevice: deviceModelId,\n keyUsage: KeyUsage.Calldata,\n keyId: KeyId.CalCalldataKey,\n };\n const certificate: PkiCertificate | undefined =\n await this._certificateLoader.loadCertificate(certificateInfos);\n\n const info: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: HexStringUtils.appendSignatureToPayload(\n infoData,\n infoSignature,\n INFO_SIGNATURE_TAG,\n ),\n certificate,\n };\n\n const enums: ClearSignContextSuccess[] = [];\n for (const [id, values] of Object.entries(calldataDescriptor.enums)) {\n for (const [\n value,\n { data, signatures },\n ] of Object.entries<CalldataTransactionDescriptor>(values)) {\n enums.push({\n type: ClearSignContextType.ENUM,\n id: Number(id),\n value: Number(value),\n payload: HexStringUtils.appendSignatureToPayload(\n data,\n signatures[this.config.cal.mode]!,\n INFO_SIGNATURE_TAG,\n ),\n certificate,\n });\n }\n }\n\n const fields: ClearSignContextSuccess[] = calldataDescriptor.fields.map(\n (field) => ({\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: field.descriptor,\n reference: this.getReference(field.param),\n }),\n );\n return Right([info, ...enums, ...fields]);\n }\n\n return Left(\n new Error(\n `[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract ${address} and selector ${selector}`,\n ),\n );\n }\n\n private getReference(\n param: CalldataDescriptorParam,\n ): ClearSignContextReference | undefined {\n if (\n param.type === \"TOKEN_AMOUNT\" &&\n param.token !== undefined &&\n param.token.type === \"path\"\n ) {\n return {\n type: ClearSignContextReferenceType.TOKEN,\n valuePath: this.toGenericPath(param.token.binary_path),\n };\n } else if (\n param.type === \"TOKEN_AMOUNT\" &&\n param.token !== undefined &&\n param.token.type === \"constant\"\n ) {\n return {\n type: ClearSignContextReferenceType.TOKEN,\n value: param.token.value,\n };\n } else if (param.type === \"NFT\" && param.collection.type === \"path\") {\n return {\n type: ClearSignContextReferenceType.NFT,\n valuePath: this.toGenericPath(param.collection.binary_path),\n };\n } else if (param.type === \"NFT\" && param.collection.type === \"constant\") {\n return {\n type: ClearSignContextReferenceType.NFT,\n value: param.collection.value,\n };\n } else if (param.type === \"TRUSTED_NAME\" && param.value.type === \"path\") {\n return {\n type: ClearSignContextReferenceType.TRUSTED_NAME,\n valuePath: this.toGenericPath(param.value.binary_path),\n types: param.types,\n sources: param.sources,\n };\n } else if (param.type === \"ENUM\" && param.value.type === \"path\") {\n return {\n type: ClearSignContextReferenceType.ENUM,\n valuePath: this.toGenericPath(param.value.binary_path),\n id: param.id,\n };\n } else if (\n param.type === \"CALLDATA\" &&\n param.value.type === \"path\" &&\n param.callee.type === \"path\"\n ) {\n return {\n type: ClearSignContextReferenceType.CALLDATA,\n valuePath: this.toGenericPath(param.value.binary_path),\n callee: this.toGenericPath(param.callee.binary_path),\n selector:\n param.selector?.type === \"path\"\n ? this.toGenericPath(param.selector.binary_path)\n : undefined,\n amount:\n param.amount?.type === \"path\"\n ? this.toGenericPath(param.amount.binary_path)\n : undefined,\n spender:\n param.spender?.type === \"path\"\n ? this.toGenericPath(param.spender.binary_path)\n : undefined,\n chainId:\n param.chainId?.type === \"path\"\n ? this.toGenericPath(param.chainId.binary_path)\n : undefined,\n };\n }\n return undefined;\n }\n\n private toGenericPath(\n path: CalldataDescriptorContainerPathV1 | CalldataDescriptorPathElementsV1,\n ): GenericPath {\n if (path.type === \"CONTAINER\") {\n return path.value;\n }\n return path.elements.map((element) => {\n if (element.type === \"ARRAY\") {\n const { weight: itemSize, ...rest } = element;\n return {\n itemSize,\n ...rest,\n };\n } else if (element.type === \"LEAF\") {\n const { leaf_type: leafType, ...rest } = element;\n return {\n leafType,\n ...rest,\n };\n }\n return element;\n });\n }\n\n private isCalldataDescriptorV1(\n data: CalldataDescriptor,\n mode: ContextModuleCalMode,\n ): data is CalldataDescriptorV1 & {\n transaction_info: {\n descriptor: {\n signatures: { [_key in ContextModuleCalMode]: string };\n };\n };\n } {\n return (\n typeof data === \"object\" &&\n data.type === \"calldata\" &&\n data.version === \"v1\" &&\n this.isTransactionInfoV1(data.transaction_info, mode) &&\n this.isEnumV1(data.enums, mode) &&\n Array.isArray(data.fields) &&\n data.fields.every((f) => this.isFieldV1(f))\n );\n }\n\n private isTransactionInfoV1(\n data: CalldataTransactionInfoV1,\n mode: ContextModuleCalMode,\n ): data is CalldataTransactionInfoV1 & {\n descriptor: {\n signatures: { [_key in ContextModuleCalMode]: string };\n };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.descriptor === \"object\" &&\n typeof data.descriptor.data === \"string\" &&\n typeof data.descriptor.signatures === \"object\" &&\n typeof data.descriptor.signatures[mode] === \"string\"\n );\n }\n\n private isEnumV1(\n calldata: CalldataEnumV1,\n mode: ContextModuleCalMode,\n ): calldata is CalldataEnumV1 {\n return (\n typeof calldata === \"object\" &&\n Object.entries(calldata).every(\n ([id, values]) =>\n typeof id === \"string\" &&\n typeof values === \"object\" &&\n Object.entries<CalldataTransactionDescriptor>(values).every(\n ([value, obj]) =>\n typeof value === \"string\" &&\n typeof obj === \"object\" &&\n typeof obj.data === \"string\" &&\n obj.signatures !== undefined &&\n this.isCalldataSignatures(obj.signatures, mode),\n ),\n )\n );\n }\n\n private isCalldataSignatures(\n data: CalldataSignatures,\n mode: ContextModuleCalMode,\n ): data is CalldataSignatures & { [_key in ContextModuleCalMode]: string } {\n return typeof data === \"object\" && typeof data[mode] === \"string\";\n }\n\n private isFieldV1(data: CalldataFieldV1): boolean {\n return (\n typeof data === \"object\" &&\n typeof data.descriptor === \"string\" &&\n typeof data.param === \"object\" &&\n typeof data.param.value === \"object\" &&\n this.isDescriptorValueV1(data.param.value) &&\n (data.param.type === \"RAW\" ||\n data.param.type === \"AMOUNT\" ||\n data.param.type === \"DATETIME\" ||\n data.param.type === \"DURATION\" ||\n data.param.type === \"UNIT\" ||\n data.param.type === \"ENUM\" ||\n (data.param.type === \"NFT\" &&\n this.isDescriptorValueV1(data.param.collection)) ||\n (data.param.type === \"TOKEN_AMOUNT\" &&\n (data.param.token === undefined ||\n this.isDescriptorValueV1(data.param.token))) ||\n (data.param.type === \"TRUSTED_NAME\" &&\n Array.isArray(data.param.types) &&\n Array.isArray(data.param.sources) &&\n data.param.types.every((t) => typeof t === \"string\") &&\n data.param.sources.every((t) => typeof t === \"string\")) ||\n (data.param.type === \"CALLDATA\" &&\n this.isDescriptorValueV1(data.param.value) &&\n this.isDescriptorValueV1(data.param.callee) &&\n (data.param.selector === undefined ||\n this.isDescriptorValueV1(data.param.selector)) &&\n (data.param.amount === undefined ||\n this.isDescriptorValueV1(data.param.amount)) &&\n (data.param.spender === undefined ||\n this.isDescriptorValueV1(data.param.spender)) &&\n (data.param.chainId === undefined ||\n this.isDescriptorValueV1(data.param.chainId))))\n );\n }\n\n private isDescriptorValueV1(data: CalldataDescriptorValueV1): boolean {\n return (\n typeof data === \"object\" &&\n typeof data.type_family === \"string\" &&\n [\n \"UINT\",\n \"INT\",\n \"UFIXED\",\n \"FIXED\",\n \"ADDRESS\",\n \"BOOL\",\n \"BYTES\",\n \"STRING\",\n ].includes(data.type_family) &&\n (typeof data.type_size === \"undefined\" ||\n typeof data.type_size === \"number\") &&\n ((data.type === \"path\" &&\n this.isCalldataDescriptorValueBinaryPathV1(data)) ||\n (data.type === \"constant\" &&\n this.isCalldataDescriptorValueConstantV1(data)))\n );\n }\n\n private isCalldataDescriptorValueConstantV1(\n data: CalldataDescriptorValueConstantV1,\n ): boolean {\n return (\n typeof data === \"object\" &&\n data.type === \"constant\" &&\n typeof data.value === \"string\"\n );\n }\n\n private isCalldataDescriptorValueBinaryPathV1(\n data: CalldataDescriptorValueBinaryPathV1,\n ): boolean {\n return (\n typeof data === \"object\" &&\n ((data.type === \"path\" &&\n data.binary_path.type === \"CONTAINER\" &&\n [\"FROM\", \"TO\", \"VALUE\"].includes(data.binary_path.value)) ||\n (data.binary_path.type === \"DATA\" &&\n Array.isArray(data.binary_path.elements) &&\n data.binary_path.elements.every((e) => this.isPathElementV1(e))))\n );\n }\n\n private isPathElementV1(data: CalldataDescriptorPathElementV1): boolean {\n return (\n typeof data === \"object\" &&\n (data.type === \"REF\" ||\n (data.type === \"TUPLE\" && typeof data.offset === \"number\") ||\n (data.type === \"ARRAY\" &&\n typeof data.weight === \"number\" &&\n (typeof data.start === \"undefined\" ||\n typeof data.start === \"number\") &&\n (typeof data.end === \"undefined\" || typeof data.end === \"number\")) ||\n (data.type === \"LEAF\" &&\n typeof data.leaf_type === \"string\" &&\n [\"ARRAY_LEAF\", \"TUPLE_LEAF\", \"STATIC_LEAF\", \"DYNAMIC_LEAF\"].includes(\n data.leaf_type,\n )) ||\n (data.type === \"SLICE\" &&\n (typeof data.start === \"undefined\" ||\n typeof data.start === \"number\") &&\n (typeof data.end === \"undefined\" || typeof data.end === \"number\")))\n );\n }\n}\n"],
5
+ "mappings": "iOACA,OAAS,UAAAA,EAAQ,cAAAC,MAAkB,YACnC,OAAiB,QAAAC,EAAM,SAAAC,MAAa,YAEpC,OAAS,eAAAC,MAAmB,0BAK5B,OAAS,gBAAAC,MAAoB,4BAC7B,OAAS,YAAAC,MAAgB,oBAEzB,OAAS,SAAAC,MAAa,oBACtB,OAAS,YAAAC,MAAgB,uBAGzB,OAEE,iCAAAC,EAEA,wBAAAC,MACK,kCAEP,OAAS,sBAAAC,MAA0B,+BACnC,OAAS,kBAAAC,MAAsB,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AAO,EAAE,SAASA,EAAK,YAAY,KAAK,GACtDA,EAAK,YAAY,OAAS,QACzB,MAAM,QAAQA,EAAK,YAAY,QAAQ,GACvCA,EAAK,YAAY,SAAS,MAAOe,GAAM,KAAK,gBAAgBA,CAAC,CAAC,EAEtE,CAEQ,gBAAgBf,EAAgD,CACtE,OACE,OAAOA,GAAS,WACfA,EAAK,OAAS,OACZA,EAAK,OAAS,SAAW,OAAOA,EAAK,QAAW,UAChDA,EAAK,OAAS,SACb,OAAOA,EAAK,QAAW,WACtB,OAAOA,EAAK,MAAU,KACrB,OAAOA,EAAK,OAAU,YACvB,OAAOA,EAAK,IAAQ,KAAe,OAAOA,EAAK,KAAQ,WACzDA,EAAK,OAAS,QACb,OAAOA,EAAK,WAAc,UAC1B,CAAC,aAAc,aAAc,cAAe,cAAc,EAAE,SAC1DA,EAAK,SACP,GACDA,EAAK,OAAS,UACZ,OAAOA,EAAK,MAAU,KACrB,OAAOA,EAAK,OAAU,YACvB,OAAOA,EAAK,IAAQ,KAAe,OAAOA,EAAK,KAAQ,UAEhE,CACF,EAjZa5B,EAAN4C,EAAA,CADNC,EAAW,EAKPC,EAAA,EAAAC,EAAOC,EAAY,MAAM,GAEzBF,EAAA,EAAAC,EAAOE,EAAS,oBAAoB,GAGpCH,EAAA,EAAAC,EAAOG,EAAa,aAAa,IATzBlD",
6
+ "names": ["inject", "injectable", "Left", "Right", "configTypes", "networkTypes", "pkiTypes", "KeyId", "KeyUsage", "ClearSignContextReferenceType", "ClearSignContextType", "INFO_SIGNATURE_TAG", "HexStringUtils", "HttpCalldataDescriptorDataSource", "config", "_certificateLoader", "endpoint", "http", "chainId", "address", "selector", "deviceModelId", "dto", "error", "Left", "calldata", "calldataDescriptor", "infoData", "infoSignature", "certificateInfos", "KeyUsage", "KeyId", "certificate", "info", "ClearSignContextType", "HexStringUtils", "INFO_SIGNATURE_TAG", "enums", "id", "values", "value", "data", "signatures", "fields", "field", "Right", "param", "ClearSignContextReferenceType", "path", "element", "itemSize", "rest", "leafType", "mode", "f", "obj", "e", "__decorateClass", "injectable", "__decorateParam", "inject", "configTypes", "pkiTypes", "networkTypes"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{DeviceModelId as o}from"@ledgerhq/device-management-kit";import t from"axios";import{Left as i}from"purify-ts";import{LEDGER_CLIENT_VERSION_HEADER as A,LEDGER_ORIGIN_TOKEN_HEADER as h}from"../../shared/constant/HttpHeaders";import T from"../../../package.json";import{HttpCalldataDescriptorDataSource as I}from"./HttpCalldataDescriptorDataSource";vi.mock("axios");const C={cal:{url:"https://crypto-assets-service.api.ledger.com/v1",mode:"test",branch:"main"},originToken:"originToken"};describe("HttpCalldataDescriptorDataSource",()=>{let d,l,u,n,v,E,p,f,b,y,m,x;const c={loadCertificate:vi.fn()};beforeAll(()=>{vi.clearAllMocks(),d=new I(C,c,"dapps"),l={descriptor:{data:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c",signatures:{test:"3045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f"}}},u={0:{1:{data:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec0401000501010606737461626c65",signatures:{test:"3045022100862e724db664f5d94484928a6a5963268a22cd8178ad36e8c4ff13769ac5c27e0220079da2b6e86810156f6b5955b8190bc016c2fe813d27fcb878a9b99658546582"}},2:{data:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04010005010206087661726961626c65",signatures:{test:"3045022100b838ee3d597d6bad2533606cef7335f6c8a45b46d5717803e646777f6c8a6897022074f04b82c3dad8445bb6230ab762010c5fc6ee06198fd3e54752287cbf95c523"}}}},p=D("FROM","UFIXED","AMOUNT","06"),f=D("TO","FIXED","DATETIME","07"),b=D("TO","BOOL","UNIT","08"),y=D("VALUE","INT","DURATION","09"),n={param:{value:{type:"path",binary_path:{type:"DATA",elements:[{type:"ARRAY",start:0,end:5,weight:1},{type:"LEAF",leaf_type:"DYNAMIC_LEAF"}]},type_family:"ADDRESS",type_size:20},type:"TOKEN_AMOUNT",token:{type:"path",binary_path:{type:"DATA",elements:[{type:"ARRAY",start:0,end:5,weight:1},{type:"LEAF",leaf_type:"DYNAMIC_LEAF"}]},type_family:"ADDRESS",type_size:20}},descriptor:"0001000112416d6f756e7420746f20776974686472617702010203580001000115000100010101020120030a000100010200010401030215000100010105020114030a000100010200000401030420ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff05034d6178"},v={param:{value:{type:"path",binary_path:{type:"CONTAINER",value:"TO"},type_family:"STRING",type_size:20},type:"TRUSTED_NAME",types:["eoa"],sources:["ens","unstoppable_domain"]},descriptor:"000100010c546f20726563697069656e7402010803230001000115000100010105020114030a00010001020002040103020101030402030402"},E={param:{value:{type:"path",binary_path:{type:"DATA",elements:[{type:"ARRAY",weight:2},{type:"LEAF",leaf_type:"TUPLE_LEAF"},{type:"SLICE",end:2}]},type_family:"BYTES",type_size:20},collection:{type:"path",binary_path:{type:"DATA",elements:[{type:"REF"},{type:"LEAF",leaf_type:"ARRAY_LEAF"},{type:"SLICE",start:1}]},type_family:"INT",type_size:20},type:"NFT"},descriptor:"000100010c546f20726563697069656e7402010803230001000115000100010105020114"},m={param:{id:0,value:{type:"path",binary_path:{type:"DATA",elements:[]},type_family:"BYTES",type_size:20},type:"ENUM"},descriptor:"000100010c546f20726563697069656e7402010803230001000115000100010105020112"},x={param:{value:{type:"path",binary_path:{type:"DATA",elements:[{type:"TUPLE",offset:0},{type:"LEAF",leaf_type:"STATIC_LEAF"}]},type_family:"BYTES",type_size:32},callee:{type:"path",binary_path:{type:"DATA",elements:[{type:"ARRAY",weight:1},{type:"LEAF",leaf_type:"DYNAMIC_LEAF"}]},type_family:"ADDRESS",type_size:20},selector:{type:"path",binary_path:{type:"CONTAINER",value:"FROM"},type_family:"BYTES",type_size:4},amount:{type:"path",binary_path:{type:"DATA",elements:[{type:"REF"},{type:"LEAF",leaf_type:"TUPLE_LEAF"}]},type_family:"UINT",type_size:32},spender:{type:"path",binary_path:{type:"DATA",elements:[{type:"SLICE",start:0,end:20},{type:"LEAF",leaf_type:"ARRAY_LEAF"}]},type_family:"ADDRESS",type_size:20},type:"CALLDATA"},descriptor:"000100010c43616c6c64617461207465737402010803230001000115000100010105020114"}});function D(a,e,r,F){return{param:{value:{type:"path",binary_path:{type:"CONTAINER",value:a},type_family:e,type_size:32},type:r},descriptor:F}}function s(a,e,r){return{descriptors_calldata:{"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9":{"0x69328dec":{type:"calldata",version:"v1",transaction_info:a,enums:e,fields:r}}}}}it("should call axios with the ledger client version header",async()=>{const a=`context-module/${T.version}`,e=vi.fn(()=>Promise.resolve({data:[]}));vi.spyOn(t,"request").mockImplementation(e),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0),await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x0abc",selector:"0x01ff"}),expect(e).toHaveBeenCalledWith(expect.objectContaining({headers:{[A]:a,[h]:C.originToken}}))}),it.each([["dapps"],["tokens"]])("should call axios with the correct url for endpoint '%s'",async a=>{const e=vi.fn(()=>Promise.resolve({data:[]}));vi.spyOn(t,"request").mockImplementation(e),await new I(C,c,a).getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x0abc",selector:"0x01ff"}),expect(e).toHaveBeenCalledWith(expect.objectContaining({url:`https://crypto-assets-service.api.ledger.com/v1/${a}`}))}),it("should return an error when axios throws an error",async()=>{vi.spyOn(t,"request").mockRejectedValue(new Error),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const a=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x0abc",selector:"0x01ff"});expect(a).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Failed to fetch calldata descriptors: Error")))}),it("should return an error when no payload is returned",async()=>{const a={data:{test:""}};vi.spyOn(t,"request").mockResolvedValue(a),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const e=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x0abc",selector:"0x01ff"});expect(e).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Response is not an array")))}),it("should return an error when an empty array is returned",async()=>{vi.spyOn(t,"request").mockResolvedValue({data:[]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const a=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x0abc",selector:"0x01ff"});expect(a).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: No data for contract 0x0abc and selector 0x01ff")))}),it("should return an error when selector is not found",async()=>{const a=s(l,u,[n]);vi.spyOn(t,"request").mockResolvedValue({data:[a]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const e=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x01fe"});expect(e).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x01fe")))}),it("Calldata with fields references and enums",async()=>{const a=s(l,u,[n,v,E,m]);vi.spyOn(t,"request").mockResolvedValue({data:[a]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const e=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80B7a3454c06bdac94a69ddc7a9",selector:"0x69328dEc"});expect(e.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{payload:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec0401000501010606737461626c6581ff473045022100862e724db664f5d94484928a6a5963268a22cd8178ad36e8c4ff13769ac5c27e0220079da2b6e86810156f6b5955b8190bc016c2fe813d27fcb878a9b99658546582",type:"enum",id:0,value:1},{payload:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04010005010206087661726961626c6581ff473045022100b838ee3d597d6bad2533606cef7335f6c8a45b46d5717803e646777f6c8a6897022074f04b82c3dad8445bb6230ab762010c5fc6ee06198fd3e54752287cbf95c523",type:"enum",id:0,value:2},{payload:n.descriptor,type:"transactionFieldDescription",reference:{type:"token",valuePath:[{type:"ARRAY",start:0,end:5,itemSize:1},{type:"LEAF",leafType:"DYNAMIC_LEAF"}]}},{payload:v.descriptor,type:"transactionFieldDescription",reference:{type:"trustedName",valuePath:"TO",types:["eoa"],sources:["ens","unstoppable_domain"]}},{payload:E.descriptor,type:"transactionFieldDescription",reference:{type:"nft",valuePath:[{type:"REF"},{type:"LEAF",leafType:"ARRAY_LEAF"},{type:"SLICE",start:1}]}},{payload:m.descriptor,type:"transactionFieldDescription",reference:{type:"enum",valuePath:[],id:0}}])}),it("Calldata with fields references and enums with certificates",async()=>{const a=s(l,u,[n,v,E,m]),e={keyUsageNumber:11,payload:new Uint8Array([1,2,3,4,21,4,5,6,7,8])};vi.spyOn(t,"request").mockResolvedValue({data:[a]}),vi.spyOn(c,"loadCertificate").mockResolvedValueOnce(e);const r=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80B7a3454c06bdac94a69ddc7a9",selector:"0x69328dEc"});expect(r.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo",certificate:e},{payload:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec0401000501010606737461626c6581ff473045022100862e724db664f5d94484928a6a5963268a22cd8178ad36e8c4ff13769ac5c27e0220079da2b6e86810156f6b5955b8190bc016c2fe813d27fcb878a9b99658546582",type:"enum",id:0,value:1,certificate:e},{payload:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04010005010206087661726961626c6581ff473045022100b838ee3d597d6bad2533606cef7335f6c8a45b46d5717803e646777f6c8a6897022074f04b82c3dad8445bb6230ab762010c5fc6ee06198fd3e54752287cbf95c523",type:"enum",id:0,value:2,certificate:e},{payload:n.descriptor,type:"transactionFieldDescription",reference:{type:"token",valuePath:[{type:"ARRAY",start:0,end:5,itemSize:1},{type:"LEAF",leafType:"DYNAMIC_LEAF"}]}},{payload:v.descriptor,type:"transactionFieldDescription",reference:{type:"trustedName",valuePath:"TO",types:["eoa"],sources:["ens","unstoppable_domain"]}},{payload:E.descriptor,type:"transactionFieldDescription",reference:{type:"nft",valuePath:[{type:"REF"},{type:"LEAF",leafType:"ARRAY_LEAF"},{type:"SLICE",start:1}]}},{payload:m.descriptor,type:"transactionFieldDescription",reference:{type:"enum",valuePath:[],id:0}}])}),it("Calldata without fields references",async()=>{const a=s(l,[],[p,f,b,y]);vi.spyOn(t,"request").mockResolvedValue({data:[a]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const e=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(e.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{type:"transactionFieldDescription",payload:p.descriptor},{type:"transactionFieldDescription",payload:f.descriptor},{type:"transactionFieldDescription",payload:b.descriptor},{type:"transactionFieldDescription",payload:y.descriptor}])}),it("Calldata on third array element",async()=>{const a=s(l,[],[p,f,b,y]);vi.spyOn(t,"request").mockResolvedValue({data:[{},{},a]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const e=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(e.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{type:"transactionFieldDescription",payload:p.descriptor},{type:"transactionFieldDescription",payload:f.descriptor},{type:"transactionFieldDescription",payload:b.descriptor},{type:"transactionFieldDescription",payload:y.descriptor}])}),it("Calldata without fields references and transaction info signature length % 2 different from 0",async()=>{const a={descriptor:{data:l.descriptor.data,signatures:{test:l.descriptor.signatures.test+"0"}}},e=s(a,[],[p,f,b,y]);vi.spyOn(t,"request").mockResolvedValue({data:[e]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const r=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(r.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff4803045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f0",type:"transactionInfo"},{type:"transactionFieldDescription",payload:p.descriptor},{type:"transactionFieldDescription",payload:f.descriptor},{type:"transactionFieldDescription",payload:b.descriptor},{type:"transactionFieldDescription",payload:y.descriptor}])}),it("Calldata with token fields references as constants",async()=>{const a={name:"Amount to exchange",param:{type:"TOKEN_AMOUNT",token:{raw:"0xae7ab96520de3a18e5e111b5eaab095312d7fe84",type:"constant",value:"0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84",version:1,type_size:20,type_family:"ADDRESS"},value:{type:"path",version:1,abi_path:{type:"data",absolute:!0,elements:[{type:"field",identifier:"_stETHAmount"}]},type_size:32,binary_path:{type:"DATA",version:1,elements:[{type:"TUPLE",offset:0},{type:"LEAF",leaf_type:"STATIC_LEAF"}]},type_family:"UINT"},version:1},version:1,descriptor:"0001010112416d6f756e7420746f2065786368616e6765020102033b0001010115000101010101020120030a00010101020000040103021f0001010101050201140514ae7ab96520de3a18e5e111b5eaab095312d7fe84"},e=s(l,[],[a]);vi.spyOn(t,"request").mockResolvedValue({data:[e]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const r=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(r.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{payload:a.descriptor,type:"transactionFieldDescription",reference:{type:"token",value:"0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84"}}])}),it("Calldata with collection fields references as constants",async()=>{const a={name:"Collection ID",param:{type:"NFT",collection:{raw:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",type:"constant",value:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",version:1,type_size:20,type_family:"ADDRESS"},value:{type:"path",version:1,abi_path:{type:"data",absolute:!0,elements:[{type:"field",identifier:"_collectionId"}]},type_size:20,binary_path:{type:"DATA",version:1,elements:[{type:"ARRAY",weight:2},{type:"LEAF",leaf_type:"TUPLE_LEAF"},{type:"SLICE",end:2}]},type_family:"BYTES"},version:1},version:1,descriptor:"0001010112416d6f756e7420746f2065786368616e6765020102033b0001010115000101010101020120030a00010101020000040103021f00010101010502011405147d2768de32b0b80b7a3454c06bdac94a69ddc7a9"},e=s(l,[],[a]);vi.spyOn(t,"request").mockResolvedValue({data:[e]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const r=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(r.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{payload:a.descriptor,type:"transactionFieldDescription",reference:{type:"nft",value:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9"}}])}),it("Calldata with CALLDATA fields references",async()=>{const a=s(l,[],[x]);vi.spyOn(t,"request").mockResolvedValue({data:[a]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const e=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(e.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{payload:x.descriptor,type:"transactionFieldDescription",reference:{type:"calldata",valuePath:[{type:"TUPLE",offset:0},{type:"LEAF",leafType:"STATIC_LEAF"}],callee:[{type:"ARRAY",itemSize:1},{type:"LEAF",leafType:"DYNAMIC_LEAF"}],selector:"FROM",amount:[{type:"REF"},{type:"LEAF",leafType:"TUPLE_LEAF"}],spender:[{type:"SLICE",start:0,end:20},{type:"LEAF",leafType:"ARRAY_LEAF"}]}}])}),it("Calldata with CALLDATA fields references without optional properties",async()=>{const a={param:{value:{type:"path",binary_path:{type:"DATA",elements:[{type:"TUPLE",offset:0},{type:"LEAF",leaf_type:"STATIC_LEAF"}]},type_family:"BYTES",type_size:32},callee:{type:"path",binary_path:{type:"DATA",elements:[{type:"TUPLE",offset:0},{type:"LEAF",leaf_type:"STATIC_LEAF"}]},type_family:"BYTES",type_size:32},type:"CALLDATA"},descriptor:"000100010c43616c6c64617461207465737402010803230001000115000100010105020114"},e=s(l,[],[a]);vi.spyOn(t,"request").mockResolvedValue({data:[e]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const r=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(r.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{payload:a.descriptor,type:"transactionFieldDescription",reference:{type:"calldata",valuePath:[{type:"TUPLE",offset:0},{type:"LEAF",leafType:"STATIC_LEAF"}],callee:[{type:"TUPLE",offset:0},{type:"LEAF",leafType:"STATIC_LEAF"}],selector:void 0,amount:void 0,spender:void 0,chainId:void 0}}])}),it("should return an error when calldata is not correctly formatted",async()=>{const a={descriptors_calldata:{"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9":{"0x69328dec":{type:"calldat",version:"v1",transaction_info:l,enums:u,fields:[n]}}}};vi.spyOn(t,"request").mockResolvedValue({data:[a]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const e=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(e).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when transactionInfo is not correctly formatted",async()=>{const a=s({descriptor:{data:"1234",signatures:{prod:"1234"}}},u,[n]);vi.spyOn(t,"request").mockResolvedValue({data:[a]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const e=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(e).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when enum is not correctly formatted",async()=>{const a=s(l,["badEnum"],[n]);vi.spyOn(t,"request").mockResolvedValue({data:[a]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const e=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(e).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when enum does not contain a signature",async()=>{const a=s(l,{0:{1:{data:"1234"}}},[n]);vi.spyOn(t,"request").mockResolvedValue({data:[a]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const e=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(e).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when enum contain the wrong signature",async()=>{const a=s(l,{0:{1:{data:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04010005010106067374626c65",signatures:{prod:"wrongSignature"}}}},[n]);vi.spyOn(t,"request").mockResolvedValue({data:[a]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const e=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(e).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when field is not correctly formatted",async()=>{const a=s(l,[],[{descriptor:3}]);vi.spyOn(t,"request").mockResolvedValue({data:[a]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const e=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(e).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when field value is not correctly formatted",async()=>{const e=s(l,[],[{param:{value:{binary_path:"TO",type_family:"UNKNOWN",type_size:20},type:"DATETIME"},descriptor:"000100010c546f20726563697069667"}]);vi.spyOn(t,"request").mockResolvedValue({data:[e]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const r=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(r).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when field container path is not correctly formatted",async()=>{const e=s(l,[],[{param:{value:{binary_path:"UNKNOWN",type_family:"ADDRESS",type_size:20},type:"DATETIME"},descriptor:"000100010c546f20726563697069667"}]);vi.spyOn(t,"request").mockResolvedValue({data:[e]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const r=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(r).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when field calldata path is not correctly formatted",async()=>{const e=s(l,[],[{param:{value:{binary_path:{elements:[{type:"UNKNOWN"}]},type_family:"ADDRESS",type_size:20},type:"DATETIME"},descriptor:"000100010c546f20726563697069667"}]);vi.spyOn(t,"request").mockResolvedValue({data:[e]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const r=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(r).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when field type is not correctly formatted",async()=>{const e=s(l,[],[{param:{value:{binary_path:"TO",type_family:"ADDRESS",type_size:20},type:"UNKNOWN"},descriptor:"000100010c546f20726563697069667"}]);vi.spyOn(t,"request").mockResolvedValue({data:[e]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const r=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(r).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should call axios with the correct headers",async()=>{vi.spyOn(t,"request").mockResolvedValueOnce({data:{}}),await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"}),expect(t.request).toHaveBeenCalledWith(expect.objectContaining({headers:{[A]:`context-module/${T.version}`,[h]:C.originToken}}))})});
1
+ import{DeviceModelId as o}from"@ledgerhq/device-management-kit";import{Left as i}from"purify-ts";import{HttpCalldataDescriptorDataSource as x}from"./HttpCalldataDescriptorDataSource";const C={cal:{url:"https://crypto-assets-service.api.ledger.com/v1",mode:"test",branch:"main"},originToken:"originToken"};describe("HttpCalldataDescriptorDataSource",()=>{let c,t,r,u,s,E,m,f,p,b,y,D,A;const d={loadCertificate:vi.fn()};beforeEach(()=>{t={get:vi.fn()},c=new x(C,d,"dapps",t)}),beforeAll(()=>{vi.clearAllMocks(),r={descriptor:{data:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c",signatures:{test:"3045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f"}}},u={0:{1:{data:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec0401000501010606737461626c65",signatures:{test:"3045022100862e724db664f5d94484928a6a5963268a22cd8178ad36e8c4ff13769ac5c27e0220079da2b6e86810156f6b5955b8190bc016c2fe813d27fcb878a9b99658546582"}},2:{data:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04010005010206087661726961626c65",signatures:{test:"3045022100b838ee3d597d6bad2533606cef7335f6c8a45b46d5717803e646777f6c8a6897022074f04b82c3dad8445bb6230ab762010c5fc6ee06198fd3e54752287cbf95c523"}}}},f=v("FROM","UFIXED","AMOUNT","06"),p=v("TO","FIXED","DATETIME","07"),b=v("TO","BOOL","UNIT","08"),y=v("VALUE","INT","DURATION","09"),s={param:{value:{type:"path",binary_path:{type:"DATA",elements:[{type:"ARRAY",start:0,end:5,weight:1},{type:"LEAF",leaf_type:"DYNAMIC_LEAF"}]},type_family:"ADDRESS",type_size:20},type:"TOKEN_AMOUNT",token:{type:"path",binary_path:{type:"DATA",elements:[{type:"ARRAY",start:0,end:5,weight:1},{type:"LEAF",leaf_type:"DYNAMIC_LEAF"}]},type_family:"ADDRESS",type_size:20}},descriptor:"0001000112416d6f756e7420746f20776974686472617702010203580001000115000100010101020120030a000100010200010401030215000100010105020114030a000100010200000401030420ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff05034d6178"},E={param:{value:{type:"path",binary_path:{type:"CONTAINER",value:"TO"},type_family:"STRING",type_size:20},type:"TRUSTED_NAME",types:["eoa"],sources:["ens","unstoppable_domain"]},descriptor:"000100010c546f20726563697069656e7402010803230001000115000100010105020114030a00010001020002040103020101030402030402"},m={param:{value:{type:"path",binary_path:{type:"DATA",elements:[{type:"ARRAY",weight:2},{type:"LEAF",leaf_type:"TUPLE_LEAF"},{type:"SLICE",end:2}]},type_family:"BYTES",type_size:20},collection:{type:"path",binary_path:{type:"DATA",elements:[{type:"REF"},{type:"LEAF",leaf_type:"ARRAY_LEAF"},{type:"SLICE",start:1}]},type_family:"INT",type_size:20},type:"NFT"},descriptor:"000100010c546f20726563697069656e7402010803230001000115000100010105020114"},D={param:{id:0,value:{type:"path",binary_path:{type:"DATA",elements:[]},type_family:"BYTES",type_size:20},type:"ENUM"},descriptor:"000100010c546f20726563697069656e7402010803230001000115000100010105020112"},A={param:{value:{type:"path",binary_path:{type:"DATA",elements:[{type:"TUPLE",offset:0},{type:"LEAF",leaf_type:"STATIC_LEAF"}]},type_family:"BYTES",type_size:32},callee:{type:"path",binary_path:{type:"DATA",elements:[{type:"ARRAY",weight:1},{type:"LEAF",leaf_type:"DYNAMIC_LEAF"}]},type_family:"ADDRESS",type_size:20},selector:{type:"path",binary_path:{type:"CONTAINER",value:"FROM"},type_family:"BYTES",type_size:4},amount:{type:"path",binary_path:{type:"DATA",elements:[{type:"REF"},{type:"LEAF",leaf_type:"TUPLE_LEAF"}]},type_family:"UINT",type_size:32},spender:{type:"path",binary_path:{type:"DATA",elements:[{type:"SLICE",start:0,end:20},{type:"LEAF",leaf_type:"ARRAY_LEAF"}]},type_family:"ADDRESS",type_size:20},type:"CALLDATA"},descriptor:"000100010c43616c6c64617461207465737402010803230001000115000100010105020114"}});function v(e,a,l,h){return{param:{value:{type:"path",binary_path:{type:"CONTAINER",value:e},type_family:a,type_size:32},type:l},descriptor:h}}function n(e,a,l){return{descriptors_calldata:{"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9":{"0x69328dec":{type:"calldata",version:"v1",transaction_info:e,enums:a,fields:l}}}}}it.each([["dapps"],["tokens"]])("should call http.get with the correct url for endpoint '%s'",async e=>{t.get.mockResolvedValue([]),await new x(C,d,e,t).getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x0abc",selector:"0x01ff"}),expect(t.get).toHaveBeenCalledWith(`${C.cal.url}/${e}`,{params:{output:"descriptors_calldata",chain_id:1,contracts:"0x0abc",contract_address:"0x0abc",ref:`branch:${C.cal.branch}`}})}),it("should return an error when http.get throws an error",async()=>{t.get.mockRejectedValue(new Error("boom")),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const e=await c.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x0abc",selector:"0x01ff"});expect(e).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Failed to fetch calldata descriptors: Error: boom")))}),it("should return an error when no payload is returned",async()=>{t.get.mockResolvedValue({test:""}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const e=await c.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x0abc",selector:"0x01ff"});expect(e).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Response is not an array")))}),it("should return an error when an empty array is returned",async()=>{t.get.mockResolvedValue([]),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const e=await c.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x0abc",selector:"0x01ff"});expect(e).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: No data for contract 0x0abc and selector 0x01ff")))}),it("should return an error when selector is not found",async()=>{const e=n(r,u,[s]);t.get.mockResolvedValue([e]),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const a=await c.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x01fe"});expect(a).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x01fe")))}),it("Calldata with fields references and enums",async()=>{const e=n(r,u,[s,E,m,D]);t.get.mockResolvedValue([e]),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const a=await c.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80B7a3454c06bdac94a69ddc7a9",selector:"0x69328dEc"});expect(a.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{payload:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec0401000501010606737461626c6581ff473045022100862e724db664f5d94484928a6a5963268a22cd8178ad36e8c4ff13769ac5c27e0220079da2b6e86810156f6b5955b8190bc016c2fe813d27fcb878a9b99658546582",type:"enum",id:0,value:1},{payload:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04010005010206087661726961626c6581ff473045022100b838ee3d597d6bad2533606cef7335f6c8a45b46d5717803e646777f6c8a6897022074f04b82c3dad8445bb6230ab762010c5fc6ee06198fd3e54752287cbf95c523",type:"enum",id:0,value:2},{payload:s.descriptor,type:"transactionFieldDescription",reference:{type:"token",valuePath:[{type:"ARRAY",start:0,end:5,itemSize:1},{type:"LEAF",leafType:"DYNAMIC_LEAF"}]}},{payload:E.descriptor,type:"transactionFieldDescription",reference:{type:"trustedName",valuePath:"TO",types:["eoa"],sources:["ens","unstoppable_domain"]}},{payload:m.descriptor,type:"transactionFieldDescription",reference:{type:"nft",valuePath:[{type:"REF"},{type:"LEAF",leafType:"ARRAY_LEAF"},{type:"SLICE",start:1}]}},{payload:D.descriptor,type:"transactionFieldDescription",reference:{type:"enum",valuePath:[],id:0}}])}),it("Calldata with fields references and enums with certificates",async()=>{const e=n(r,u,[s,E,m,D]),a={keyUsageNumber:11,payload:new Uint8Array([1,2,3,4,21,4,5,6,7,8])};t.get.mockResolvedValue([e]),vi.spyOn(d,"loadCertificate").mockResolvedValueOnce(a);const l=await c.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80B7a3454c06bdac94a69ddc7a9",selector:"0x69328dEc"});expect(l.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo",certificate:a},{payload:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec0401000501010606737461626c6581ff473045022100862e724db664f5d94484928a6a5963268a22cd8178ad36e8c4ff13769ac5c27e0220079da2b6e86810156f6b5955b8190bc016c2fe813d27fcb878a9b99658546582",type:"enum",id:0,value:1,certificate:a},{payload:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04010005010206087661726961626c6581ff473045022100b838ee3d597d6bad2533606cef7335f6c8a45b46d5717803e646777f6c8a6897022074f04b82c3dad8445bb6230ab762010c5fc6ee06198fd3e54752287cbf95c523",type:"enum",id:0,value:2,certificate:a},{payload:s.descriptor,type:"transactionFieldDescription",reference:{type:"token",valuePath:[{type:"ARRAY",start:0,end:5,itemSize:1},{type:"LEAF",leafType:"DYNAMIC_LEAF"}]}},{payload:E.descriptor,type:"transactionFieldDescription",reference:{type:"trustedName",valuePath:"TO",types:["eoa"],sources:["ens","unstoppable_domain"]}},{payload:m.descriptor,type:"transactionFieldDescription",reference:{type:"nft",valuePath:[{type:"REF"},{type:"LEAF",leafType:"ARRAY_LEAF"},{type:"SLICE",start:1}]}},{payload:D.descriptor,type:"transactionFieldDescription",reference:{type:"enum",valuePath:[],id:0}}])}),it("Calldata without fields references",async()=>{const e=n(r,[],[f,p,b,y]);t.get.mockResolvedValue([e]),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const a=await c.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(a.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{type:"transactionFieldDescription",payload:f.descriptor},{type:"transactionFieldDescription",payload:p.descriptor},{type:"transactionFieldDescription",payload:b.descriptor},{type:"transactionFieldDescription",payload:y.descriptor}])}),it("Calldata on third array element",async()=>{const e=n(r,[],[f,p,b,y]);t.get.mockResolvedValue([{},{},e]),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const a=await c.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(a.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{type:"transactionFieldDescription",payload:f.descriptor},{type:"transactionFieldDescription",payload:p.descriptor},{type:"transactionFieldDescription",payload:b.descriptor},{type:"transactionFieldDescription",payload:y.descriptor}])}),it("Calldata without fields references and transaction info signature length % 2 different from 0",async()=>{const e={descriptor:{data:r.descriptor.data,signatures:{test:r.descriptor.signatures.test+"0"}}},a=n(e,[],[f,p,b,y]);t.get.mockResolvedValue([a]),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const l=await c.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(l.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff4803045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f0",type:"transactionInfo"},{type:"transactionFieldDescription",payload:f.descriptor},{type:"transactionFieldDescription",payload:p.descriptor},{type:"transactionFieldDescription",payload:b.descriptor},{type:"transactionFieldDescription",payload:y.descriptor}])}),it("Calldata with token fields references as constants",async()=>{const e={name:"Amount to exchange",param:{type:"TOKEN_AMOUNT",token:{raw:"0xae7ab96520de3a18e5e111b5eaab095312d7fe84",type:"constant",value:"0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84",version:1,type_size:20,type_family:"ADDRESS"},value:{type:"path",version:1,abi_path:{type:"data",absolute:!0,elements:[{type:"field",identifier:"_stETHAmount"}]},type_size:32,binary_path:{type:"DATA",version:1,elements:[{type:"TUPLE",offset:0},{type:"LEAF",leaf_type:"STATIC_LEAF"}]},type_family:"UINT"},version:1},version:1,descriptor:"0001010112416d6f756e7420746f2065786368616e6765020102033b0001010115000101010101020120030a00010101020000040103021f0001010101050201140514ae7ab96520de3a18e5e111b5eaab095312d7fe84"},a=n(r,[],[e]);t.get.mockResolvedValue([a]),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const l=await c.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(l.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{payload:e.descriptor,type:"transactionFieldDescription",reference:{type:"token",value:"0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84"}}])}),it("Calldata with collection fields references as constants",async()=>{const e={name:"Collection ID",param:{type:"NFT",collection:{raw:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",type:"constant",value:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",version:1,type_size:20,type_family:"ADDRESS"},value:{type:"path",version:1,abi_path:{type:"data",absolute:!0,elements:[{type:"field",identifier:"_collectionId"}]},type_size:20,binary_path:{type:"DATA",version:1,elements:[{type:"ARRAY",weight:2},{type:"LEAF",leaf_type:"TUPLE_LEAF"},{type:"SLICE",end:2}]},type_family:"BYTES"},version:1},version:1,descriptor:"0001010112416d6f756e7420746f2065786368616e6765020102033b0001010115000101010101020120030a00010101020000040103021f00010101010502011405147d2768de32b0b80b7a3454c06bdac94a69ddc7a9"},a=n(r,[],[e]);t.get.mockResolvedValue([a]),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const l=await c.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(l.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{payload:e.descriptor,type:"transactionFieldDescription",reference:{type:"nft",value:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9"}}])}),it("Calldata with CALLDATA fields references",async()=>{const e=n(r,[],[A]);t.get.mockResolvedValue([e]),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const a=await c.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(a.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{payload:A.descriptor,type:"transactionFieldDescription",reference:{type:"calldata",valuePath:[{type:"TUPLE",offset:0},{type:"LEAF",leafType:"STATIC_LEAF"}],callee:[{type:"ARRAY",itemSize:1},{type:"LEAF",leafType:"DYNAMIC_LEAF"}],selector:"FROM",amount:[{type:"REF"},{type:"LEAF",leafType:"TUPLE_LEAF"}],spender:[{type:"SLICE",start:0,end:20},{type:"LEAF",leafType:"ARRAY_LEAF"}]}}])}),it("Calldata with CALLDATA fields references without optional properties",async()=>{const e={param:{value:{type:"path",binary_path:{type:"DATA",elements:[{type:"TUPLE",offset:0},{type:"LEAF",leaf_type:"STATIC_LEAF"}]},type_family:"BYTES",type_size:32},callee:{type:"path",binary_path:{type:"DATA",elements:[{type:"TUPLE",offset:0},{type:"LEAF",leaf_type:"STATIC_LEAF"}]},type_family:"BYTES",type_size:32},type:"CALLDATA"},descriptor:"000100010c43616c6c64617461207465737402010803230001000115000100010105020114"},a=n(r,[],[e]);t.get.mockResolvedValue([a]),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const l=await c.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(l.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{payload:e.descriptor,type:"transactionFieldDescription",reference:{type:"calldata",valuePath:[{type:"TUPLE",offset:0},{type:"LEAF",leafType:"STATIC_LEAF"}],callee:[{type:"TUPLE",offset:0},{type:"LEAF",leafType:"STATIC_LEAF"}],selector:void 0,amount:void 0,spender:void 0,chainId:void 0}}])}),it("should return an error when calldata is not correctly formatted",async()=>{const e={descriptors_calldata:{"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9":{"0x69328dec":{type:"calldat",version:"v1",transaction_info:r,enums:u,fields:[s]}}}};t.get.mockResolvedValue([e]),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const a=await c.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(a).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when transactionInfo is not correctly formatted",async()=>{const e=n({descriptor:{data:"1234",signatures:{prod:"1234"}}},u,[s]);t.get.mockResolvedValue([e]),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const a=await c.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(a).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when enum is not correctly formatted",async()=>{const e=n(r,["badEnum"],[s]);t.get.mockResolvedValue([e]),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const a=await c.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(a).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when enum does not contain a signature",async()=>{const e=n(r,{0:{1:{data:"1234"}}},[s]);t.get.mockResolvedValue([e]),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const a=await c.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(a).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when enum contain the wrong signature",async()=>{const e=n(r,{0:{1:{data:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04010005010106067374626c65",signatures:{prod:"wrongSignature"}}}},[s]);t.get.mockResolvedValue([e]),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const a=await c.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(a).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when field is not correctly formatted",async()=>{const e=n(r,[],[{descriptor:3}]);t.get.mockResolvedValue([e]),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const a=await c.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(a).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when field value is not correctly formatted",async()=>{const a=n(r,[],[{param:{value:{binary_path:"TO",type_family:"UNKNOWN",type_size:20},type:"DATETIME"},descriptor:"000100010c546f20726563697069667"}]);t.get.mockResolvedValue([a]),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const l=await c.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(l).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when field container path is not correctly formatted",async()=>{const a=n(r,[],[{param:{value:{binary_path:"UNKNOWN",type_family:"ADDRESS",type_size:20},type:"DATETIME"},descriptor:"000100010c546f20726563697069667"}]);t.get.mockResolvedValue([a]),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const l=await c.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(l).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when field calldata path is not correctly formatted",async()=>{const a=n(r,[],[{param:{value:{binary_path:{elements:[{type:"UNKNOWN"}]},type_family:"ADDRESS",type_size:20},type:"DATETIME"},descriptor:"000100010c546f20726563697069667"}]);t.get.mockResolvedValue([a]),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const l=await c.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(l).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when field type is not correctly formatted",async()=>{const a=n(r,[],[{param:{value:{binary_path:"TO",type_family:"ADDRESS",type_size:20},type:"UNKNOWN"},descriptor:"000100010c546f20726563697069667"}]);t.get.mockResolvedValue([a]),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const l=await c.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(l).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))})});
2
2
  //# sourceMappingURL=HttpCalldataDescriptorDataSource.test.js.map