@ledgerhq/context-module 1.6.0 → 1.7.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 (165) hide show
  1. package/lib/cjs/package.json +1 -1
  2. package/lib/cjs/src/ContextModuleBuilder.js +1 -1
  3. package/lib/cjs/src/ContextModuleBuilder.js.map +3 -3
  4. package/lib/cjs/src/ContextModuleBuilder.test.js +1 -1
  5. package/lib/cjs/src/ContextModuleBuilder.test.js.map +2 -2
  6. package/lib/cjs/src/DefaultContextModule.js +1 -1
  7. package/lib/cjs/src/DefaultContextModule.js.map +3 -3
  8. package/lib/cjs/src/DefaultContextModule.test.js +1 -1
  9. package/lib/cjs/src/DefaultContextModule.test.js.map +2 -2
  10. package/lib/cjs/src/config/model/ContextModuleConfig.js +1 -1
  11. package/lib/cjs/src/config/model/ContextModuleConfig.js.map +1 -1
  12. package/lib/cjs/src/di.js +1 -1
  13. package/lib/cjs/src/di.js.map +3 -3
  14. package/lib/cjs/src/dynamic-network/data/DynamicNetworkDataSource.js +2 -0
  15. package/lib/cjs/src/dynamic-network/data/DynamicNetworkDataSource.js.map +7 -0
  16. package/lib/cjs/src/dynamic-network/data/HttpDynamicNetworkDataSource.js +2 -0
  17. package/lib/cjs/src/dynamic-network/data/HttpDynamicNetworkDataSource.js.map +7 -0
  18. package/lib/cjs/src/dynamic-network/data/HttpDynamicNetworkDataSource.test.js +2 -0
  19. package/lib/cjs/src/dynamic-network/data/HttpDynamicNetworkDataSource.test.js.map +7 -0
  20. package/lib/cjs/src/dynamic-network/data/dto/DynamicNetworkApiResponseDto.js +2 -0
  21. package/lib/cjs/src/dynamic-network/data/dto/DynamicNetworkApiResponseDto.js.map +7 -0
  22. package/lib/cjs/src/dynamic-network/di/dynamicNetworkModuleFactory.js +2 -0
  23. package/lib/cjs/src/dynamic-network/di/dynamicNetworkModuleFactory.js.map +7 -0
  24. package/lib/cjs/src/dynamic-network/di/dynamicNetworkTypes.js +2 -0
  25. package/lib/cjs/src/dynamic-network/di/dynamicNetworkTypes.js.map +7 -0
  26. package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.js +2 -0
  27. package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.js.map +7 -0
  28. package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js +2 -0
  29. package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js.map +7 -0
  30. package/lib/cjs/src/dynamic-network/model/DynamicNetworkConfiguration.js +2 -0
  31. package/lib/cjs/src/dynamic-network/model/DynamicNetworkConfiguration.js.map +7 -0
  32. package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.test.js +1 -1
  33. package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.test.js.map +2 -2
  34. package/lib/cjs/src/index.js +1 -1
  35. package/lib/cjs/src/index.js.map +2 -2
  36. package/lib/cjs/src/nft/data/HttpNftDataSource.js +1 -1
  37. package/lib/cjs/src/nft/data/HttpNftDataSource.js.map +2 -2
  38. package/lib/cjs/src/nft/data/HttpNftDataSource.test.js +1 -1
  39. package/lib/cjs/src/nft/data/HttpNftDataSource.test.js.map +2 -2
  40. package/lib/cjs/src/pki/domain/DefaultPkiCertificateLoader.js +1 -1
  41. package/lib/cjs/src/pki/domain/DefaultPkiCertificateLoader.js.map +3 -3
  42. package/lib/cjs/src/pki/domain/DefaultPkiCertificateLoader.test.js +1 -1
  43. package/lib/cjs/src/pki/domain/DefaultPkiCertificateLoader.test.js.map +3 -3
  44. package/lib/cjs/src/shared/model/ClearSignContext.js +1 -1
  45. package/lib/cjs/src/shared/model/ClearSignContext.js.map +2 -2
  46. package/lib/cjs/src/solana/data/HttpSolanaOwnerInfoDataSource.js +1 -1
  47. package/lib/cjs/src/solana/data/HttpSolanaOwnerInfoDataSource.js.map +2 -2
  48. package/lib/cjs/src/solana/data/HttpSolanaOwnerInfoDataSource.test.js +1 -1
  49. package/lib/cjs/src/solana/data/HttpSolanaOwnerInfoDataSource.test.js.map +2 -2
  50. package/lib/cjs/src/transaction/data/HttpProxyDataSource.js +1 -1
  51. package/lib/cjs/src/transaction/data/HttpProxyDataSource.js.map +3 -3
  52. package/lib/cjs/src/transaction/data/HttpProxyDataSource.test.js +1 -1
  53. package/lib/cjs/src/transaction/data/HttpProxyDataSource.test.js.map +2 -2
  54. package/lib/cjs/src/transaction/data/dto/ProxyDelegateCallDto.js +1 -1
  55. package/lib/cjs/src/transaction/data/dto/ProxyDelegateCallDto.js.map +1 -1
  56. package/lib/cjs/src/transaction/domain/TransactionContextLoader.js +1 -1
  57. package/lib/cjs/src/transaction/domain/TransactionContextLoader.js.map +3 -3
  58. package/lib/cjs/src/transaction/domain/TransactionContextLoader.test.js +1 -1
  59. package/lib/cjs/src/transaction/domain/TransactionContextLoader.test.js.map +3 -3
  60. package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.js +1 -1
  61. package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.js.map +2 -2
  62. package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.test.js +1 -1
  63. package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.test.js.map +2 -2
  64. package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.test.js +1 -1
  65. package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.test.js.map +2 -2
  66. package/lib/cjs/src/uniswap/domain/UniswapContextLoader.js +1 -1
  67. package/lib/cjs/src/uniswap/domain/UniswapContextLoader.js.map +2 -2
  68. package/lib/esm/package.json +1 -1
  69. package/lib/esm/src/ContextModuleBuilder.js +1 -1
  70. package/lib/esm/src/ContextModuleBuilder.js.map +3 -3
  71. package/lib/esm/src/ContextModuleBuilder.test.js +1 -1
  72. package/lib/esm/src/ContextModuleBuilder.test.js.map +2 -2
  73. package/lib/esm/src/DefaultContextModule.js +1 -1
  74. package/lib/esm/src/DefaultContextModule.js.map +3 -3
  75. package/lib/esm/src/DefaultContextModule.test.js +1 -1
  76. package/lib/esm/src/DefaultContextModule.test.js.map +2 -2
  77. package/lib/esm/src/di.js +1 -1
  78. package/lib/esm/src/di.js.map +3 -3
  79. package/lib/esm/src/dynamic-network/data/DynamicNetworkDataSource.js +1 -0
  80. package/lib/esm/src/dynamic-network/data/DynamicNetworkDataSource.js.map +7 -0
  81. package/lib/esm/src/dynamic-network/data/HttpDynamicNetworkDataSource.js +2 -0
  82. package/lib/esm/src/dynamic-network/data/HttpDynamicNetworkDataSource.js.map +7 -0
  83. package/lib/esm/src/dynamic-network/data/HttpDynamicNetworkDataSource.test.js +2 -0
  84. package/lib/esm/src/dynamic-network/data/HttpDynamicNetworkDataSource.test.js.map +7 -0
  85. package/lib/esm/src/dynamic-network/data/dto/DynamicNetworkApiResponseDto.js +1 -0
  86. package/lib/esm/src/dynamic-network/data/dto/DynamicNetworkApiResponseDto.js.map +7 -0
  87. package/lib/esm/src/dynamic-network/di/dynamicNetworkModuleFactory.js +2 -0
  88. package/lib/esm/src/dynamic-network/di/dynamicNetworkModuleFactory.js.map +7 -0
  89. package/lib/esm/src/dynamic-network/di/dynamicNetworkTypes.js +2 -0
  90. package/lib/esm/src/dynamic-network/di/dynamicNetworkTypes.js.map +7 -0
  91. package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.js +2 -0
  92. package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.js.map +7 -0
  93. package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js +2 -0
  94. package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js.map +7 -0
  95. package/lib/esm/src/dynamic-network/model/DynamicNetworkConfiguration.js +1 -0
  96. package/lib/esm/src/dynamic-network/model/DynamicNetworkConfiguration.js.map +7 -0
  97. package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.test.js +1 -1
  98. package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.test.js.map +2 -2
  99. package/lib/esm/src/index.js +1 -1
  100. package/lib/esm/src/index.js.map +2 -2
  101. package/lib/esm/src/nft/data/HttpNftDataSource.js +1 -1
  102. package/lib/esm/src/nft/data/HttpNftDataSource.js.map +2 -2
  103. package/lib/esm/src/nft/data/HttpNftDataSource.test.js +1 -1
  104. package/lib/esm/src/nft/data/HttpNftDataSource.test.js.map +2 -2
  105. package/lib/esm/src/pki/domain/DefaultPkiCertificateLoader.js +1 -1
  106. package/lib/esm/src/pki/domain/DefaultPkiCertificateLoader.js.map +3 -3
  107. package/lib/esm/src/pki/domain/DefaultPkiCertificateLoader.test.js +1 -1
  108. package/lib/esm/src/pki/domain/DefaultPkiCertificateLoader.test.js.map +3 -3
  109. package/lib/esm/src/shared/model/ClearSignContext.js +1 -1
  110. package/lib/esm/src/shared/model/ClearSignContext.js.map +2 -2
  111. package/lib/esm/src/solana/data/HttpSolanaOwnerInfoDataSource.js +1 -1
  112. package/lib/esm/src/solana/data/HttpSolanaOwnerInfoDataSource.js.map +2 -2
  113. package/lib/esm/src/solana/data/HttpSolanaOwnerInfoDataSource.test.js +1 -1
  114. package/lib/esm/src/solana/data/HttpSolanaOwnerInfoDataSource.test.js.map +2 -2
  115. package/lib/esm/src/transaction/data/HttpProxyDataSource.js +1 -1
  116. package/lib/esm/src/transaction/data/HttpProxyDataSource.js.map +3 -3
  117. package/lib/esm/src/transaction/data/HttpProxyDataSource.test.js +1 -1
  118. package/lib/esm/src/transaction/data/HttpProxyDataSource.test.js.map +2 -2
  119. package/lib/esm/src/transaction/domain/TransactionContextLoader.js +1 -1
  120. package/lib/esm/src/transaction/domain/TransactionContextLoader.js.map +3 -3
  121. package/lib/esm/src/transaction/domain/TransactionContextLoader.test.js +1 -1
  122. package/lib/esm/src/transaction/domain/TransactionContextLoader.test.js.map +3 -3
  123. package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.js +1 -1
  124. package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.js.map +2 -2
  125. package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.test.js +1 -1
  126. package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.test.js.map +2 -2
  127. package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.test.js +1 -1
  128. package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.test.js.map +2 -2
  129. package/lib/esm/src/uniswap/domain/UniswapContextLoader.js +1 -1
  130. package/lib/esm/src/uniswap/domain/UniswapContextLoader.js.map +2 -2
  131. package/lib/types/src/DefaultContextModule.d.ts.map +1 -1
  132. package/lib/types/src/config/model/ContextModuleConfig.d.ts +1 -1
  133. package/lib/types/src/config/model/ContextModuleConfig.d.ts.map +1 -1
  134. package/lib/types/src/di.d.ts.map +1 -1
  135. package/lib/types/src/dynamic-network/data/DynamicNetworkDataSource.d.ts +6 -0
  136. package/lib/types/src/dynamic-network/data/DynamicNetworkDataSource.d.ts.map +1 -0
  137. package/lib/types/src/dynamic-network/data/HttpDynamicNetworkDataSource.d.ts +13 -0
  138. package/lib/types/src/dynamic-network/data/HttpDynamicNetworkDataSource.d.ts.map +1 -0
  139. package/lib/types/src/dynamic-network/data/HttpDynamicNetworkDataSource.test.d.ts +2 -0
  140. package/lib/types/src/dynamic-network/data/HttpDynamicNetworkDataSource.test.d.ts.map +1 -0
  141. package/lib/types/src/dynamic-network/data/dto/DynamicNetworkApiResponseDto.d.ts +14 -0
  142. package/lib/types/src/dynamic-network/data/dto/DynamicNetworkApiResponseDto.d.ts.map +1 -0
  143. package/lib/types/src/dynamic-network/di/dynamicNetworkModuleFactory.d.ts +3 -0
  144. package/lib/types/src/dynamic-network/di/dynamicNetworkModuleFactory.d.ts.map +1 -0
  145. package/lib/types/src/dynamic-network/di/dynamicNetworkTypes.d.ts +5 -0
  146. package/lib/types/src/dynamic-network/di/dynamicNetworkTypes.d.ts.map +1 -0
  147. package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.d.ts +15 -0
  148. package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.d.ts.map +1 -0
  149. package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.test.d.ts +2 -0
  150. package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.test.d.ts.map +1 -0
  151. package/lib/types/src/dynamic-network/model/DynamicNetworkConfiguration.d.ts +16 -0
  152. package/lib/types/src/dynamic-network/model/DynamicNetworkConfiguration.d.ts.map +1 -0
  153. package/lib/types/src/index.d.ts +2 -0
  154. package/lib/types/src/index.d.ts.map +1 -1
  155. package/lib/types/src/pki/domain/DefaultPkiCertificateLoader.d.ts.map +1 -1
  156. package/lib/types/src/shared/model/ClearSignContext.d.ts +3 -0
  157. package/lib/types/src/shared/model/ClearSignContext.d.ts.map +1 -1
  158. package/lib/types/src/transaction/data/HttpProxyDataSource.d.ts +2 -1
  159. package/lib/types/src/transaction/data/HttpProxyDataSource.d.ts.map +1 -1
  160. package/lib/types/src/transaction/data/dto/ProxyDelegateCallDto.d.ts +1 -1
  161. package/lib/types/src/transaction/data/dto/ProxyDelegateCallDto.d.ts.map +1 -1
  162. package/lib/types/src/transaction/domain/TransactionContextLoader.d.ts +3 -1
  163. package/lib/types/src/transaction/domain/TransactionContextLoader.d.ts.map +1 -1
  164. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  165. package/package.json +4 -4
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/index.ts"],
4
- "sourcesContent": ["export * from \"./config/model/ContextModuleConfig\";\nexport * from \"./ContextModule\";\nexport * from \"./ContextModuleBuilder\";\nexport * from \"./DefaultContextModule\";\nexport * from \"./external-plugin/domain/ExternalPluginContextLoader\";\nexport * from \"./nft/domain/NftContextLoader\";\nexport * from \"./pki/domain/PkiCertificateLoader\";\nexport * from \"./pki/model/KeyId\";\nexport * from \"./pki/model/KeyUsage\";\nexport * from \"./pki/model/PkiCertificate\";\nexport * from \"./pki/model/PkiCertificateInfo\";\nexport * from \"./shared/domain/ContextLoader\";\nexport * from \"./shared/model/ClearSignContext\";\nexport * from \"./shared/model/GenericPath\";\nexport * from \"./shared/model/TransactionContext\";\nexport * from \"./shared/model/TransactionSubset\";\nexport * from \"./shared/model/TypedDataClearSignContext\";\nexport * from \"./shared/model/TypedDataContext\";\nexport * from \"./token/domain/TokenContextLoader\";\nexport * from \"./trusted-name/domain/TrustedNameContextLoader\";\nexport * from \"./web3-check/domain/Web3CheckContextLoader\";\nexport * from \"./web3-check/domain/web3CheckTypes\";\n"],
5
- "mappings": "AAAA,WAAc,qCACd,WAAc,kBACd,WAAc,yBACd,WAAc,yBACd,WAAc,uDACd,WAAc,gCACd,WAAc,oCACd,WAAc,oBACd,WAAc,uBACd,WAAc,6BACd,WAAc,iCACd,WAAc,gCACd,WAAc,kCACd,WAAc,6BACd,WAAc,oCACd,WAAc,mCACd,WAAc,2CACd,WAAc,kCACd,WAAc,oCACd,WAAc,iDACd,WAAc,6CACd,WAAc",
4
+ "sourcesContent": ["export * from \"./config/model/ContextModuleConfig\";\nexport * from \"./ContextModule\";\nexport * from \"./ContextModuleBuilder\";\nexport * from \"./DefaultContextModule\";\nexport * from \"./dynamic-network/domain/DynamicNetworkContextLoader\";\nexport * from \"./dynamic-network/model/DynamicNetworkConfiguration\";\nexport * from \"./external-plugin/domain/ExternalPluginContextLoader\";\nexport * from \"./nft/domain/NftContextLoader\";\nexport * from \"./pki/domain/PkiCertificateLoader\";\nexport * from \"./pki/model/KeyId\";\nexport * from \"./pki/model/KeyUsage\";\nexport * from \"./pki/model/PkiCertificate\";\nexport * from \"./pki/model/PkiCertificateInfo\";\nexport * from \"./shared/domain/ContextLoader\";\nexport * from \"./shared/model/ClearSignContext\";\nexport * from \"./shared/model/GenericPath\";\nexport * from \"./shared/model/TransactionContext\";\nexport * from \"./shared/model/TransactionSubset\";\nexport * from \"./shared/model/TypedDataClearSignContext\";\nexport * from \"./shared/model/TypedDataContext\";\nexport * from \"./token/domain/TokenContextLoader\";\nexport * from \"./trusted-name/domain/TrustedNameContextLoader\";\nexport * from \"./web3-check/domain/Web3CheckContextLoader\";\nexport * from \"./web3-check/domain/web3CheckTypes\";\n"],
5
+ "mappings": "AAAA,WAAc,qCACd,WAAc,kBACd,WAAc,yBACd,WAAc,yBACd,WAAc,uDACd,WAAc,sDACd,WAAc,uDACd,WAAc,gCACd,WAAc,oCACd,WAAc,oBACd,WAAc,uBACd,WAAc,6BACd,WAAc,iCACd,WAAc,gCACd,WAAc,kCACd,WAAc,6BACd,WAAc,oCACd,WAAc,mCACd,WAAc,2CACd,WAAc,kCACd,WAAc,oCACd,WAAc,iDACd,WAAc,6CACd,WAAc",
6
6
  "names": []
7
7
  }
@@ -1,2 +1,2 @@
1
- var E=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var m=(a,e,r,t)=>{for(var o=t>1?void 0:t?y(e,r):e,s=a.length-1,l;s>=0;s--)(l=a[s])&&(o=(t?l(e,r,o):l(o))||o);return t&&o&&E(e,r,o),o},c=(a,e)=>(r,t)=>e(r,t,a);import d from"axios";import{inject as h,injectable as P}from"inversify";import{Left as n,Right as f}from"purify-ts";import{configTypes as x}from"../../config/di/configTypes";import{LEDGER_CLIENT_VERSION_HEADER as u,LEDGER_ORIGIN_TOKEN_HEADER as p}from"../../shared/constant/HttpHeaders";import g from"../../../package.json";let i=class{constructor(e){this.config=e}async getSetPluginPayload({chainId:e,address:r,selector:t}){try{const o=await d.request({method:"GET",url:`${this.config.metadataService.url}/ethereum/${e}/contracts/${r}/plugin-selector/${t}`,headers:{[u]:`context-module/${g.version}`,[p]:this.config.originToken}});return o.data.payload?f(o.data.payload):n(new Error("[ContextModule] HttpNftDataSource: unexpected empty response"))}catch{return n(new Error("[ContextModule] HttpNftDataSource: Failed to fetch set plugin payload"))}}async getNftInfosPayload({chainId:e,address:r}){try{const t=await d.request({method:"GET",url:`${this.config.metadataService.url}/ethereum/${e}/contracts/${r}`,headers:{[u]:`context-module/${g.version}`,[p]:this.config.originToken}});return t.data.payload?f(t.data.payload):n(new Error("[ContextModule] HttpNftDataSource: no nft metadata"))}catch{return n(new Error("[ContextModule] HttpNftDataSource: Failed to fetch nft informations"))}}};i=m([P(),c(0,h(x.Config))],i);export{i as HttpNftDataSource};
1
+ var E=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var l=(a,e,r,t)=>{for(var o=t>1?void 0:t?y(e,r):e,s=a.length-1,m;s>=0;s--)(m=a[s])&&(o=(t?m(e,r,o):m(o))||o);return t&&o&&E(e,r,o),o},c=(a,e)=>(r,t)=>e(r,t,a);import d from"axios";import{inject as h,injectable as P}from"inversify";import{Left as n,Right as f}from"purify-ts";import{configTypes as x}from"../../config/di/configTypes";import{LEDGER_CLIENT_VERSION_HEADER as u,LEDGER_ORIGIN_TOKEN_HEADER as p}from"../../shared/constant/HttpHeaders";import g from"../../../package.json";let i=class{constructor(e){this.config=e}async getSetPluginPayload({chainId:e,address:r,selector:t}){try{const o=await d.request({method:"GET",url:`${this.config.metadataServiceDomain.url}/v1/ethereum/${e}/contracts/${r}/plugin-selector/${t}`,headers:{[u]:`context-module/${g.version}`,[p]:this.config.originToken}});return o.data.payload?f(o.data.payload):n(new Error("[ContextModule] HttpNftDataSource: unexpected empty response"))}catch{return n(new Error("[ContextModule] HttpNftDataSource: Failed to fetch set plugin payload"))}}async getNftInfosPayload({chainId:e,address:r}){try{const t=await d.request({method:"GET",url:`${this.config.metadataServiceDomain.url}/v1/ethereum/${e}/contracts/${r}`,headers:{[u]:`context-module/${g.version}`,[p]:this.config.originToken}});return t.data.payload?f(t.data.payload):n(new Error("[ContextModule] HttpNftDataSource: no nft metadata"))}catch{return n(new Error("[ContextModule] HttpNftDataSource: Failed to fetch nft informations"))}}};i=l([P(),c(0,h(x.Config))],i);export{i as HttpNftDataSource};
2
2
  //# sourceMappingURL=HttpNftDataSource.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/nft/data/HttpNftDataSource.ts"],
4
- "sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n GetNftInformationsParams,\n GetSetPluginPayloadParams,\n NftDataSource,\n} from \"@/nft/data/NftDataSource\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport PACKAGE from \"@root/package.json\";\n\n@injectable()\nexport class HttpNftDataSource implements NftDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n ) {}\n\n public async getSetPluginPayload({\n chainId,\n address,\n selector,\n }: GetSetPluginPayloadParams): Promise<Either<Error, string>> {\n try {\n const response = await axios.request<{ payload: string }>({\n method: \"GET\",\n url: `${this.config.metadataService.url}/ethereum/${chainId}/contracts/${address}/plugin-selector/${selector}`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n\n return response.data.payload\n ? Right(response.data.payload)\n : Left(\n new Error(\n \"[ContextModule] HttpNftDataSource: unexpected empty response\",\n ),\n );\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] HttpNftDataSource: Failed to fetch set plugin payload\",\n ),\n );\n }\n }\n\n public async getNftInfosPayload({\n chainId,\n address,\n }: GetNftInformationsParams): Promise<Either<Error, string>> {\n try {\n const response = await axios.request<{ payload: string }>({\n method: \"GET\",\n url: `${this.config.metadataService.url}/ethereum/${chainId}/contracts/${address}`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n\n return response.data.payload\n ? Right(response.data.payload)\n : Left(new Error(\"[ContextModule] HttpNftDataSource: no nft metadata\"));\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] HttpNftDataSource: Failed to fetch n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I,MACF,qEACF,CACF,CACF,CACF,CACF,EA7DaX,EAANY,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAY,MAAM,IAFjBhB",
4
+ "sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n GetNftInformationsParams,\n GetSetPluginPayloadParams,\n NftDataSource,\n} from \"@/nft/data/NftDataSource\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport PACKAGE from \"@root/package.json\";\n\n@injectable()\nexport class HttpNftDataSource implements NftDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n ) {}\n\n public async getSetPluginPayload({\n chainId,\n address,\n selector,\n }: GetSetPluginPayloadParams): Promise<Either<Error, string>> {\n try {\n const response = await axios.request<{ payload: string }>({\n method: \"GET\",\n url: `${this.config.metadataServiceDomain.url}/v1/ethereum/${chainId}/contracts/${address}/plugin-selector/${selector}`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n\n return response.data.payload\n ? Right(response.data.payload)\n : Left(\n new Error(\n \"[ContextModule] HttpNftDataSource: unexpected empty response\",\n ),\n );\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] HttpNftDataSource: Failed to fetch set plugin payload\",\n ),\n );\n }\n }\n\n public async getNftInfosPayload({\n chainId,\n address,\n }: GetNftInformationsParams): Promise<Either<Error, string>> {\n try {\n const response = await axios.request<{ payload: string }>({\n method: \"GET\",\n url: `${this.config.metadataServiceDomain.url}/v1/ethereum/${chainId}/contracts/${address}`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n\n return response.data.payload\n ? Right(response.data.payload)\n : Left(new Error(\"[ContextModule] HttpNftDataSource: no nft metadata\"));\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] HttpNftDataSource: Failed to fetch nft informations\",\n ),\n );\n }\n }\n}\n"],
5
+ "mappings": "iOAAA,OAAOA,MAAW,QAClB,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YACnC,OAAiB,QAAAC,EAAM,SAAAC,MAAa,YAEpC,OAAS,eAAAC,MAAmB,0BAO5B,OACE,gCAAAC,EACA,8BAAAC,MACK,gCACP,OAAOC,MAAa,qBAGb,IAAMC,EAAN,KAAiD,CACtD,YAC+CC,EAC7C,CAD6C,YAAAA,CAC5C,CAEH,MAAa,oBAAoB,CAC/B,QAAAC,EACA,QAAAC,EACA,SAAAC,CACF,EAA8D,CAC5D,GAAI,CACF,MAAMC,EAAW,MAAMC,EAAM,QAA6B,CACxD,OAAQ,MACR,IAAK,GAAG,KAAK,OAAO,sBAAsB,GAAG,gBAAgBJ,CAAO,cAAcC,CAAO,oBAAoBC,CAAQ,GACrH,QAAS,CACP,CAACG,CAA4B,EAAG,kBAAkBC,EAAQ,OAAO,GACjE,CAACC,CAA0B,EAAG,KAAK,OAAO,WAC5C,CACF,CAAC,EAED,OAAOJ,EAAS,KAAK,QACjBK,EAAML,EAAS,KAAK,OAAO,EAC3BM,EACE,IAAI,MACF,8DACF,CACF,CACN,MAAiB,CACf,OAAOA,EACL,IAAI,MACF,uEACF,CACF,CACF,CACF,CAEA,MAAa,mBAAmB,CAC9B,QAAAT,EACA,QAAAC,CACF,EAA6D,CAC3D,GAAI,CACF,MAAME,EAAW,MAAMC,EAAM,QAA6B,CACxD,OAAQ,MACR,IAAK,GAAG,KAAK,OAAO,sBAAsB,GAAG,gBAAgBJ,CAAO,cAAcC,CAAO,GACzF,QAAS,CACP,CAACI,CAA4B,EAAG,kBAAkBC,EAAQ,OAAO,GACjE,CAACC,CAA0B,EAAG,KAAK,OAAO,WAC5C,CACF,CAAC,EAED,OAAOJ,EAAS,KAAK,QACjBK,EAAML,EAAS,KAAK,OAAO,EAC3BM,EAAK,IAAI,MAAM,oDAAoD,CAAC,CAC1E,MAAiB,CACf,OAAOA,EACL,IAAI,MACF,qEACF,CACF,CACF,CACF,CACF,EA7DaX,EAANY,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAY,MAAM,IAFjBhB",
6
6
  "names": ["axios", "inject", "injectable", "Left", "Right", "configTypes", "LEDGER_CLIENT_VERSION_HEADER", "LEDGER_ORIGIN_TOKEN_HEADER", "PACKAGE", "HttpNftDataSource", "config", "chainId", "address", "selector", "response", "axios", "LEDGER_CLIENT_VERSION_HEADER", "PACKAGE", "LEDGER_ORIGIN_TOKEN_HEADER", "Right", "Left", "__decorateClass", "injectable", "__decorateParam", "inject", "configTypes"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import a from"axios";import{LEDGER_CLIENT_VERSION_HEADER as n,LEDGER_ORIGIN_TOKEN_HEADER as s}from"../../shared/constant/HttpHeaders";import i from"../../../package.json";import{HttpNftDataSource as l}from"./HttpNftDataSource";vi.mock("axios");const r={web3checks:{url:"web3checksUrl"},metadataService:{url:"https://nft.api.live.ledger.com/v1"},originToken:"originToken"};describe("HttpNftDataSource",()=>{let o;beforeAll(()=>{o=new l(r),vi.clearAllMocks()}),it("should call axios with the ledger client version and origin Token header",async()=>{const e=`context-module/${i.version}`,t=vi.fn(()=>Promise.resolve({data:[]}));vi.spyOn(a,"request").mockImplementation(t),await o.getNftInfosPayload({address:"0x00",chainId:1}),await o.getSetPluginPayload({address:"0x00",chainId:1,selector:"0x00"}),expect(t).toHaveBeenNthCalledWith(1,expect.objectContaining({headers:{[n]:e,[s]:r.originToken}})),expect(t).toHaveBeenNthCalledWith(2,expect.objectContaining({headers:{[n]:e,[s]:r.originToken}}))}),describe("getNftInfosPayload",()=>{it("should return an error when axios throws an error",async()=>{vi.spyOn(a,"request").mockRejectedValue(new Error("error"));const e=await o.getNftInfosPayload({address:"0x00",chainId:1});expect(e.extract()).toEqual(new Error("[ContextModule] HttpNftDataSource: Failed to fetch nft informations"))}),it("should return an error when the response is empty",async()=>{const e={data:{}};vi.spyOn(a,"request").mockResolvedValue(e);const t=await o.getNftInfosPayload({address:"0x00",chainId:1});expect(t.extract()).toEqual(new Error("[ContextModule] HttpNftDataSource: no nft metadata"))}),it("should return the payload",async()=>{const e={data:{payload:"payload"}};vi.spyOn(a,"request").mockResolvedValue(e);const t=await o.getNftInfosPayload({address:"0x00",chainId:1});expect(t.extract()).toEqual("payload")})}),describe("getSetPluginPayload",()=>{it("should return an error when axios throws an error",async()=>{vi.spyOn(a,"request").mockRejectedValue(new Error("error"));const e=await o.getSetPluginPayload({address:"0x00",chainId:1,selector:"0x00"});expect(e.extract()).toEqual(new Error("[ContextModule] HttpNftDataSource: Failed to fetch set plugin payload"))}),it("should return an error when the response is empty",async()=>{const e={data:{}};vi.spyOn(a,"request").mockResolvedValue(e);const t=await o.getSetPluginPayload({address:"0x00",chainId:1,selector:"0x00"});expect(t.extract()).toEqual(new Error("[ContextModule] HttpNftDataSource: unexpected empty response"))}),it("should return the payload",async()=>{const e={data:{payload:"payload"}};vi.spyOn(a,"request").mockResolvedValue(e);const t=await o.getSetPluginPayload({address:"0x00",chainId:1,selector:"0x00"});expect(t.extract()).toEqual("payload")})})});
1
+ import a from"axios";import{LEDGER_CLIENT_VERSION_HEADER as n,LEDGER_ORIGIN_TOKEN_HEADER as s}from"../../shared/constant/HttpHeaders";import i from"../../../package.json";import{HttpNftDataSource as l}from"./HttpNftDataSource";vi.mock("axios");const r={web3checks:{url:"web3checksUrl"},metadataServiceDomain:{url:"https://nft.api.live.ledger.com"},originToken:"originToken"};describe("HttpNftDataSource",()=>{let o;beforeAll(()=>{o=new l(r),vi.clearAllMocks()}),it("should call axios with the ledger client version and origin Token header",async()=>{const e=`context-module/${i.version}`,t=vi.fn(()=>Promise.resolve({data:[]}));vi.spyOn(a,"request").mockImplementation(t),await o.getNftInfosPayload({address:"0x00",chainId:1}),await o.getSetPluginPayload({address:"0x00",chainId:1,selector:"0x00"}),expect(t).toHaveBeenNthCalledWith(1,expect.objectContaining({headers:{[n]:e,[s]:r.originToken}})),expect(t).toHaveBeenNthCalledWith(2,expect.objectContaining({headers:{[n]:e,[s]:r.originToken}}))}),describe("getNftInfosPayload",()=>{it("should return an error when axios throws an error",async()=>{vi.spyOn(a,"request").mockRejectedValue(new Error("error"));const e=await o.getNftInfosPayload({address:"0x00",chainId:1});expect(e.extract()).toEqual(new Error("[ContextModule] HttpNftDataSource: Failed to fetch nft informations"))}),it("should return an error when the response is empty",async()=>{const e={data:{}};vi.spyOn(a,"request").mockResolvedValue(e);const t=await o.getNftInfosPayload({address:"0x00",chainId:1});expect(t.extract()).toEqual(new Error("[ContextModule] HttpNftDataSource: no nft metadata"))}),it("should return the payload",async()=>{const e={data:{payload:"payload"}};vi.spyOn(a,"request").mockResolvedValue(e);const t=await o.getNftInfosPayload({address:"0x00",chainId:1});expect(t.extract()).toEqual("payload")})}),describe("getSetPluginPayload",()=>{it("should return an error when axios throws an error",async()=>{vi.spyOn(a,"request").mockRejectedValue(new Error("error"));const e=await o.getSetPluginPayload({address:"0x00",chainId:1,selector:"0x00"});expect(e.extract()).toEqual(new Error("[ContextModule] HttpNftDataSource: Failed to fetch set plugin payload"))}),it("should return an error when the response is empty",async()=>{const e={data:{}};vi.spyOn(a,"request").mockResolvedValue(e);const t=await o.getSetPluginPayload({address:"0x00",chainId:1,selector:"0x00"});expect(t.extract()).toEqual(new Error("[ContextModule] HttpNftDataSource: unexpected empty response"))}),it("should return the payload",async()=>{const e={data:{payload:"payload"}};vi.spyOn(a,"request").mockResolvedValue(e);const t=await o.getSetPluginPayload({address:"0x00",chainId:1,selector:"0x00"});expect(t.extract()).toEqual("payload")})})});
2
2
  //# sourceMappingURL=HttpNftDataSource.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/nft/data/HttpNftDataSource.test.ts"],
4
- "sourcesContent": ["import axios from \"axios\";\n\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport PACKAGE from \"@root/package.json\";\n\nimport { HttpNftDataSource } from \"./HttpNftDataSource\";\nimport { type NftDataSource } from \"./NftDataSource\";\n\nvi.mock(\"axios\");\n\nconst config = {\n web3checks: {\n url: \"web3checksUrl\",\n },\n metadataService: {\n url: \"https://nft.api.live.ledger.com/v1\",\n },\n originToken: \"originToken\",\n} as ContextModuleConfig;\ndescribe(\"HttpNftDataSource\", () => {\n let datasource: NftDataSource;\n\n beforeAll(() => {\n datasource = new HttpNftDataSource(config);\n vi.clearAllMocks();\n });\n\n it(\"should call axios with the ledger client version and origin Token header\", async () => {\n // GIVEN\n const version = `context-module/${PACKAGE.version}`;\n const requestSpy = vi.fn(() => Promise.resolve({ data: [] }));\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n // WHEN\n await datasource.getNftInfosPayload({ address: \"0x00\", chainId: 1 });\n await datasource.getSetPluginPayload({\n address: \"0x00\",\n chainId: 1,\n selector: \"0x00\",\n });\n\n // THEN\n expect(requestSpy).toHaveBeenNthCalledWith(\n 1,\n expect.objectContaining({\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: version,\n [LEDGER_ORIGIN_TOKEN_HEADER]: config.originToken,\n },\n }),\n );\n expect(requestSpy).toHaveBeenNthCalledWith(\n 2,\n expect.objectContaining({\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: version,\n [LEDGER_ORIGIN_TOKEN_HEADER]: config.originToken,\n },\n }),\n );\n });\n\n describe(\"getNftInfosPayload\", () => {\n it(\"should return an error when axios throws an error\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockRejectedValue(new Error(\"error\"));\n\n // WHEN\n const result = await datasource.getNftInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result.extract()).toEqual(\n new Error(\n \"[ContextModule] HttpNftDataSource: Failed to fetch nft informations\",\n ),\n );\n });\n\n it(\"should return an error when the response is empty\", async () => {\n // GIVEN\n const response = { data: {} };\n vi.spyOn(axios, \"request\").mockResolvedValue(response);\n\n // WHEN\n const result = await datasource.getNftInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result.extract()).toEqual(\n new Error(\"[ContextModule] HttpNftDataSource: no nft metadata\"),\n );\n });\n\n it(\"should return the payload\", async () => {\n // GIVEN\n const response = { data: { payload: \"payload\" } };\n vi.spyOn(axios, \"request\").mockResolvedValue(response);\n\n // WHEN\n const result = await datasource.getNftInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result.extract()).toEqual(\"payload\");\n });\n });\n\n describe(\"getSetPluginPayload\", () => {\n it(\"should return an error when axios throws an error\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockRejectedValue(new Error(\"error\"));\n\n // WHEN\n const result = await datasource.getSetPluginPayload({\n address: \"0x00\",\n chainId: 1,\n selector: \"0x00\",\n });\n\n // THEN\n expect(result.extract()).toEqual(\n new Error(\n \"[ContextModule] HttpNftDataSource: Failed to fetch set plugin payload\",\n ),\n );\n });\n\n it(\"should return an error when the response is empty\", async () => {\n // GIVEN\n const response = { data: {} };\n vi.spyOn(axios, \"request\").mockResolvedValue(response);\n\n // WHEN\n const result = await datasource.getSetPluginPayload({\n address: \"0x00\",\n chainId: 1,\n selector: \"0x00\",\n });\n\n // THEN\n expect(result.extract()).toEqual(\n new Error(\n \"[ContextModule] HttpNftDataSource: unexpected empty response\",\n ),\n );\n });\n\n it(\"should return the payload\", async () => {\n // GIVEN\n const response = { data: { payload: \"payload\" } };\n vi.spyOn(axios, \"request\").mockResolvedValue(response);\n\n // WHEN\n const result = await datasource.getSetPluginPayload({\n address: \"0x00\",\n chainId: 1,\n selector: \"0x00\",\n });\n\n // THEN\n expect(result.extract()).toEqual(\"payload\");\n });\n });\n});\n"],
5
- "mappings": "AAAA,OAAOA,MAAW,QAGlB,OACE,gCAAAC,EACA,8BAAAC,MACK,gCACP,OAAOC,MAAa,qBAEpB,OAAS,qBAAAC,MAAyB,sBAGlC,GAAG,KAAK,OAAO,EAEf,MAAMC,EAAS,CACb,WAAY,CACV,IAAK,eACP,EACA,gBAAiB,CACf,IAAK,oCACP,EACA,YAAa,aACf,EACA,SAAS,oBAAqB,IAAM,CAClC,IAAIC,EAEJ,UAAU,IAAM,CACdA,EAAa,IAAIF,EAAkBC,CAAM,EACzC,GAAG,cAAc,CACnB,CAAC,EAED,GAAG,2EAA4E,SAAY,CAEzF,MAAME,EAAU,kBAAkBJ,EAAQ,OAAO,GAC3CK,EAAa,GAAG,GAAG,IAAM,QAAQ,QAAQ,CAAE,KAAM,CAAC,CAAE,CAAC,CAAC,EAC5D,GAAG,MAAMR,EAAO,SAAS,EAAE,mBAAmBQ,CAAU,EAGxD,MAAMF,EAAW,mBAAmB,CAAE,QAAS,OAAQ,QAAS,CAAE,CAAC,EACnE,MAAMA,EAAW,oBAAoB,CACnC,QAAS,OACT,QAAS,EACT,SAAU,MACZ,CAAC,EAGD,OAAOE,CAAU,EAAE,wBACjB,EACA,OAAO,iBAAiB,CACtB,QAAS,CACP,CAACP,CAA4B,EAAGM,EAChC,CAACL,CAA0B,EAAGG,EAAO,WACvC,CACF,CAAC,CACH,EACA,OAAOG,CAAU,EAAE,wBACjB,EACA,OAAO,iBAAiB,CACtB,QAAS,CACP,CAACP,CAA4B,EAAGM,EAChC,CAACL,CAA0B,EAAGG,EAAO,WACvC,CACF,CAAC,CACH,CACF,CAAC,EAED,SAAS,qBAAsB,IAAM,CACnC,GAAG,oDAAqD,SAAY,CAElE,GAAG,MAAML,EAAO,SAAS,EAAE,kBAAkB,IAAI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,CAAC,EAGD,OAAOG,EAAO,QAAQ,CAAC,EAAE,QACvB,IAAI,MACF,8DACF,CACF,CACF,CAAC,EAED,GAAG,4BAA6B,SAAY,CAE1C,MAAMC,EAAW,CAAE,KAAM,CAAE,QAAS,SAAU,CAAE,EAChD,GAAG,MAAMV,EAAO,SAAS,EAAE,kBAAkBU,CAAQ,EAGrD,MAAMD,EAAS,MAAMH,EAAW,oBAAoB,CAClD,QAAS,OACT,QAAS,EACT,SAAU,MACZ,CAAC,EAGD,OAAOG,EAAO,QAAQ,CAAC,EAAE,QAAQ,SAAS,CAC5C,CAAC,CACH,CAAC,CACH,CAAC",
4
+ "sourcesContent": ["import axios from \"axios\";\n\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport PACKAGE from \"@root/package.json\";\n\nimport { HttpNftDataSource } from \"./HttpNftDataSource\";\nimport { type NftDataSource } from \"./NftDataSource\";\n\nvi.mock(\"axios\");\n\nconst config = {\n web3checks: {\n url: \"web3checksUrl\",\n },\n metadataServiceDomain: {\n url: \"https://nft.api.live.ledger.com\",\n },\n originToken: \"originToken\",\n} as ContextModuleConfig;\ndescribe(\"HttpNftDataSource\", () => {\n let datasource: NftDataSource;\n\n beforeAll(() => {\n datasource = new HttpNftDataSource(config);\n vi.clearAllMocks();\n });\n\n it(\"should call axios with the ledger client version and origin Token header\", async () => {\n // GIVEN\n const version = `context-module/${PACKAGE.version}`;\n const requestSpy = vi.fn(() => Promise.resolve({ data: [] }));\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n // WHEN\n await datasource.getNftInfosPayload({ address: \"0x00\", chainId: 1 });\n await datasource.getSetPluginPayload({\n address: \"0x00\",\n chainId: 1,\n selector: \"0x00\",\n });\n\n // THEN\n expect(requestSpy).toHaveBeenNthCalledWith(\n 1,\n expect.objectContaining({\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: version,\n [LEDGER_ORIGIN_TOKEN_HEADER]: config.originToken,\n },\n }),\n );\n expect(requestSpy).toHaveBeenNthCalledWith(\n 2,\n expect.objectContaining({\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: version,\n [LEDGER_ORIGIN_TOKEN_HEADER]: config.originToken,\n },\n }),\n );\n });\n\n describe(\"getNftInfosPayload\", () => {\n it(\"should return an error when axios throws an error\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockRejectedValue(new Error(\"error\"));\n\n // WHEN\n const result = await datasource.getNftInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result.extract()).toEqual(\n new Error(\n \"[ContextModule] HttpNftDataSource: Failed to fetch nft informations\",\n ),\n );\n });\n\n it(\"should return an error when the response is empty\", async () => {\n // GIVEN\n const response = { data: {} };\n vi.spyOn(axios, \"request\").mockResolvedValue(response);\n\n // WHEN\n const result = await datasource.getNftInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result.extract()).toEqual(\n new Error(\"[ContextModule] HttpNftDataSource: no nft metadata\"),\n );\n });\n\n it(\"should return the payload\", async () => {\n // GIVEN\n const response = { data: { payload: \"payload\" } };\n vi.spyOn(axios, \"request\").mockResolvedValue(response);\n\n // WHEN\n const result = await datasource.getNftInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result.extract()).toEqual(\"payload\");\n });\n });\n\n describe(\"getSetPluginPayload\", () => {\n it(\"should return an error when axios throws an error\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockRejectedValue(new Error(\"error\"));\n\n // WHEN\n const result = await datasource.getSetPluginPayload({\n address: \"0x00\",\n chainId: 1,\n selector: \"0x00\",\n });\n\n // THEN\n expect(result.extract()).toEqual(\n new Error(\n \"[ContextModule] HttpNftDataSource: Failed to fetch set plugin payload\",\n ),\n );\n });\n\n it(\"should return an error when the response is empty\", async () => {\n // GIVEN\n const response = { data: {} };\n vi.spyOn(axios, \"request\").mockResolvedValue(response);\n\n // WHEN\n const result = await datasource.getSetPluginPayload({\n address: \"0x00\",\n chainId: 1,\n selector: \"0x00\",\n });\n\n // THEN\n expect(result.extract()).toEqual(\n new Error(\n \"[ContextModule] HttpNftDataSource: unexpected empty response\",\n ),\n );\n });\n\n it(\"should return the payload\", async () => {\n // GIVEN\n const response = { data: { payload: \"payload\" } };\n vi.spyOn(axios, \"request\").mockResolvedValue(response);\n\n // WHEN\n const result = await datasource.getSetPluginPayload({\n address: \"0x00\",\n chainId: 1,\n selector: \"0x00\",\n });\n\n // THEN\n expect(result.extract()).toEqual(\"payload\");\n });\n });\n});\n"],
5
+ "mappings": "AAAA,OAAOA,MAAW,QAGlB,OACE,gCAAAC,EACA,8BAAAC,MACK,gCACP,OAAOC,MAAa,qBAEpB,OAAS,qBAAAC,MAAyB,sBAGlC,GAAG,KAAK,OAAO,EAEf,MAAMC,EAAS,CACb,WAAY,CACV,IAAK,eACP,EACA,sBAAuB,CACrB,IAAK,iCACP,EACA,YAAa,aACf,EACA,SAAS,oBAAqB,IAAM,CAClC,IAAIC,EAEJ,UAAU,IAAM,CACdA,EAAa,IAAIF,EAAkBC,CAAM,EACzC,GAAG,cAAc,CACnB,CAAC,EAED,GAAG,2EAA4E,SAAY,CAEzF,MAAME,EAAU,kBAAkBJ,EAAQ,OAAO,GAC3CK,EAAa,GAAG,GAAG,IAAM,QAAQ,QAAQ,CAAE,KAAM,CAAC,CAAE,CAAC,CAAC,EAC5D,GAAG,MAAMR,EAAO,SAAS,EAAE,mBAAmBQ,CAAU,EAGxD,MAAMF,EAAW,mBAAmB,CAAE,QAAS,OAAQ,QAAS,CAAE,CAAC,EACnE,MAAMA,EAAW,oBAAoB,CACnC,QAAS,OACT,QAAS,EACT,SAAU,MACZ,CAAC,EAGD,OAAOE,CAAU,EAAE,wBACjB,EACA,OAAO,iBAAiB,CACtB,QAAS,CACP,CAACP,CAA4B,EAAGM,EA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,EACT,SAAU,MACZ,CAAC,EAGD,OAAOG,EAAO,QAAQ,CAAC,EAAE,QACvB,IAAI,MACF,uEACF,CACF,CACF,CAAC,EAED,GAAG,oDAAqD,SAAY,CAElE,MAAMC,EAAW,CAAE,KAAM,CAAC,CAAE,EAC5B,GAAG,MAAMV,EAAO,SAAS,EAAE,kBAAkBU,CAAQ,EAGrD,MAAMD,EAAS,MAAMH,EAAW,oBAAoB,CAClD,QAAS,OACT,QAAS,EACT,SAAU,MACZ,CAAC,EAGD,OAAOG,EAAO,QAAQ,CAAC,EAAE,QACvB,IAAI,MACF,8DACF,CACF,CACF,CAAC,EAED,GAAG,4BAA6B,SAAY,CAE1C,MAAMC,EAAW,CAAE,KAAM,CAAE,QAAS,SAAU,CAAE,EAChD,GAAG,MAAMV,EAAO,SAAS,EAAE,kBAAkBU,CAAQ,EAGrD,MAAMD,EAAS,MAAMH,EAAW,oBAAoB,CAClD,QAAS,OACT,QAAS,EACT,SAAU,MACZ,CAAC,EAGD,OAAOG,EAAO,QAAQ,CAAC,EAAE,QAAQ,SAAS,CAC5C,CAAC,CACH,CAAC,CACH,CAAC",
6
6
  "names": ["axios", "LEDGER_CLIENT_VERSION_HEADER", "LEDGER_ORIGIN_TOKEN_HEADER", "PACKAGE", "HttpNftDataSource", "config", "datasource", "version", "requestSpy", "result", "response"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var p=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var m=(a,i,r,t)=>{for(var e=t>1?void 0:t?s(i,r):i,o=a.length-1,f;o>=0;o--)(f=a[o])&&(e=(t?f(i,r,e):f(e))||e);return t&&e&&p(i,r,e),e},n=(a,i)=>(r,t)=>i(r,t,a);import{inject as C,injectable as k}from"inversify";import{pkiTypes as P}from"../../pki/di/pkiTypes";let c=class{_dataSource;constructor(i){this._dataSource=i}async loadCertificate(i){return(await this._dataSource.fetchCertificate(i)).caseOf({Right:t=>t,Left:t=>{throw t instanceof Error?t:new Error(String(t))}})}};c=m([k(),n(0,C(P.PkiCertificateDataSource))],c);export{c as DefaultPkiCertificateLoader};
1
+ var n=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var m=(a,t,e,r)=>{for(var i=r>1?void 0:r?s(t,e):t,o=a.length-1,f;o>=0;o--)(f=a[o])&&(i=(r?f(t,e,i):f(i))||i);return r&&i&&n(t,e,i),i},p=(a,t)=>(e,r)=>t(e,r,a);import{inject as u,injectable as C}from"inversify";import{pkiTypes as k}from"../../pki/di/pkiTypes";let c=class{_dataSource;constructor(t){this._dataSource=t}async loadCertificate(t){return(await this._dataSource.fetchCertificate(t)).orDefault(void 0)}};c=m([C(),p(0,u(k.PkiCertificateDataSource))],c);export{c as DefaultPkiCertificateLoader};
2
2
  //# sourceMappingURL=DefaultPkiCertificateLoader.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/pki/domain/DefaultPkiCertificateLoader.ts"],
4
- "sourcesContent": ["import { inject, injectable } from \"inversify\";\n\nimport { type PkiCertificateDataSource } from \"@/pki/data/PkiCertificateDataSource\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { type PkiCertificateInfo } from \"@/pki/model/PkiCertificateInfo\";\n\nimport { PkiCertificateLoader } from \"./PkiCertificateLoader\";\n\n@injectable()\nexport class DefaultPkiCertificateLoader implements PkiCertificateLoader {\n private _dataSource: PkiCertificateDataSource;\n\n constructor(\n @inject(pkiTypes.PkiCertificateDataSource)\n dataSource: PkiCertificateDataSource,\n ) {\n this._dataSource = dataSource;\n }\n\n async loadCertificate(\n certificateInfos: PkiCertificateInfo,\n ): Promise<PkiCertificate | undefined> {\n const certificate =\n await this._dataSource.fetchCertificate(certificateInfos);\n\n return certificate.caseOf({\n Right: (cert) => cert,\n Left: (err) => {\n throw err instanceof Error ? err : new Error(String(err));\n },\n });\n }\n}\n"],
5
- "mappings": "iOAAA,OAAS,UAAAA,EAAQ,cAAAC,MAAkB,YAGnC,OAAS,YAAAC,MAAgB,oBAOlB,IAAMC,EAAN,KAAkE,CAC/D,YAER,YAEEC,EACA,CACA,KAAK,YAAcA,CACrB,CAEA,MAAM,gBACJC,EACqC,CAIrC,OAFE,MAAM,KAAK,YAAY,iBAAiBA,CAAgB,GAEvC,OAAO,CACxB,MAAQC,GAASA,EACjB,KAAOC,GAAQ,CACb,MAAMA,aAAe,MAAQA,EAAM,IAAI,MAAM,OAAOA,CAAG,CAAC,CAC1D,CACF,CAAC,CACH,CACF,EAvBaJ,EAANK,EAAA,CADNC,EAAW,EAKPC,EAAA,EAAAC,EAAOC,EAAS,wBAAwB,IAJhCT",
6
- "names": ["inject", "injectable", "pkiTypes", "DefaultPkiCertificateLoader", "dataSource", "certificateInfos", "cert", "err", "__decorateClass", "injectable", "__decorateParam", "inject", "pkiTypes"]
4
+ "sourcesContent": ["import { inject, injectable } from \"inversify\";\n\nimport { type PkiCertificateDataSource } from \"@/pki/data/PkiCertificateDataSource\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { type PkiCertificateInfo } from \"@/pki/model/PkiCertificateInfo\";\n\nimport { PkiCertificateLoader } from \"./PkiCertificateLoader\";\n\n@injectable()\nexport class DefaultPkiCertificateLoader implements PkiCertificateLoader {\n private _dataSource: PkiCertificateDataSource;\n\n constructor(\n @inject(pkiTypes.PkiCertificateDataSource)\n dataSource: PkiCertificateDataSource,\n ) {\n this._dataSource = dataSource;\n }\n\n async loadCertificate(\n certificateInfos: PkiCertificateInfo,\n ): Promise<PkiCertificate | undefined> {\n const certificate =\n await this._dataSource.fetchCertificate(certificateInfos);\n\n // TODO add logs error with certificate.left()\n return certificate.orDefault(undefined);\n }\n}\n"],
5
+ "mappings": "iOAAA,OAAS,UAAAA,EAAQ,cAAAC,MAAkB,YAGnC,OAAS,YAAAC,MAAgB,oBAOlB,IAAMC,EAAN,KAAkE,CAC/D,YAER,YAEEC,EACA,CACA,KAAK,YAAcA,CACrB,CAEA,MAAM,gBACJC,EACqC,CAKrC,OAHE,MAAM,KAAK,YAAY,iBAAiBA,CAAgB,GAGvC,UAAU,MAAS,CACxC,CACF,EAnBaF,EAANG,EAAA,CADNC,EAAW,EAKPC,EAAA,EAAAC,EAAOC,EAAS,wBAAwB,IAJhCP",
6
+ "names": ["inject", "injectable", "pkiTypes", "DefaultPkiCertificateLoader", "dataSource", "certificateInfos", "__decorateClass", "injectable", "__decorateParam", "inject", "pkiTypes"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{Left as l,Right as n}from"purify-ts";import{DefaultPkiCertificateLoader as i}from"../../pki/domain/DefaultPkiCertificateLoader";import{KeyId as o}from"../../pki/model/KeyId";import{KeyUsage as c}from"../../pki/model/KeyUsage";describe("DefaultPkiCertificateLoader",()=>{describe("loadCertificate",()=>{it("should call loadCertificate",async()=>{const e={targetDevice:"targetDevice",keyUsage:c.Calldata,keyId:o.CalNetwork},t={keyUsageNumber:11,payload:new Uint8Array([1,2,3,4,21,4,5,6,7,8])},a={fetchCertificate:vi.fn().mockResolvedValue(n(t))},f=await new i(a).loadCertificate(e);expect(f).toEqual(t),expect(a.fetchCertificate).toHaveBeenCalledWith(e)}),it("throws when the data source returns a Left(error)",async()=>{const e={targetDevice:"targetDevice",keyUsage:c.Calldata,keyId:o.CalNetwork},t=new Error("failed"),a={fetchCertificate:vi.fn().mockResolvedValue(l(t))},r=new i(a);await expect(r.loadCertificate(e)).rejects.toThrow(t),expect(a.fetchCertificate).toHaveBeenCalledWith(e)})})});
1
+ import{Left as n,Right as l}from"purify-ts";import{DefaultPkiCertificateLoader as r}from"../../pki/domain/DefaultPkiCertificateLoader";import{KeyId as o}from"../../pki/model/KeyId";import{KeyUsage as c}from"../../pki/model/KeyUsage";describe("DefaultPkiCertificateLoader",()=>{describe("loadCertificate",()=>{it("should call loadCertificate",async()=>{const e={targetDevice:"targetDevice",keyUsage:c.Calldata,keyId:o.CalNetwork},a={keyUsageNumber:11,payload:new Uint8Array([1,2,3,4,21,4,5,6,7,8])},t={fetchCertificate:vi.fn().mockResolvedValue(l(a))},i=await new r(t).loadCertificate(e);expect(i).toEqual(a),expect(t.fetchCertificate).toHaveBeenCalledWith(e)}),it("Returns undefined when the data source returns a Left(error)",async()=>{const e={targetDevice:"targetDevice",keyUsage:c.Calldata,keyId:o.CalNetwork},a=new Error("failed"),t={fetchCertificate:vi.fn().mockResolvedValue(n(a))},i=await new r(t).loadCertificate(e);expect(i).toBeUndefined(),expect(t.fetchCertificate).toHaveBeenCalledWith(e)})})});
2
2
  //# sourceMappingURL=DefaultPkiCertificateLoader.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/pki/domain/DefaultPkiCertificateLoader.test.ts"],
4
- "sourcesContent": ["import { Left, Right } from \"purify-ts\";\n\nimport { DefaultPkiCertificateLoader } from \"@/pki/domain/DefaultPkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { type PkiCertificateInfo } from \"@/pki/model/PkiCertificateInfo\";\n\ndescribe(\"DefaultPkiCertificateLoader\", () => {\n describe(\"loadCertificate\", () => {\n it(\"should call loadCertificate\", async () => {\n // GIVEN\n const certificateInfos: PkiCertificateInfo = {\n targetDevice: \"targetDevice\",\n keyUsage: KeyUsage.Calldata,\n keyId: KeyId.CalNetwork,\n };\n const certificate = {\n keyUsageNumber: 11,\n payload: new Uint8Array([\n 0x01, 0x02, 0x03, 0x04, 0x15, 0x04, 0x05, 0x06, 0x07, 0x08,\n ]),\n };\n const dataSource = {\n fetchCertificate: vi.fn().mockResolvedValue(Right(certificate)),\n };\n\n // WHEN\n const loader = new DefaultPkiCertificateLoader(dataSource);\n const result = await loader.loadCertificate(certificateInfos);\n\n // THEN\n expect(result).toEqual(certificate);\n expect(dataSource.fetchCertificate).toHaveBeenCalledWith(\n certificateInfos,\n );\n });\n\n it(\"throws when the data source returns a Left(error)\", async () => {\n // given\n const certificateInfos: PkiCertificateInfo = {\n targetDevice: \"targetDevice\",\n keyUsage: KeyUsage.Calldata,\n keyId: KeyId.CalNetwork,\n };\n const fetchError = new Error(\"failed\");\n const dataSource = {\n fetchCertificate: vi.fn().mockResolvedValue(Left(fetchError)),\n };\n const loader = new DefaultPkiCertificateLoader(dataSource);\n\n // when / then\n await expect(loader.loadCertificate(certificateInfos)).rejects.toThrow(\n fetchError,\n );\n expect(dataSource.fetchCertificate).toHaveBeenCalledWith(\n certificateInfos,\n );\n });\n });\n});\n"],
5
- "mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAE5B,OAAS,+BAAAC,MAAmC,2CAC5C,OAAS,SAAAC,MAAa,oBACtB,OAAS,YAAAC,MAAgB,uBAGzB,SAAS,8BAA+B,IAAM,CAC5C,SAAS,kBAAmB,IAAM,CAChC,GAAG,8BAA+B,SAAY,CAE5C,MAAMC,EAAuC,CAC3C,aAAc,eACd,SAAUD,EAAS,SACnB,MAAOD,EAAM,UACf,EACMG,EAAc,CAClB,eAAgB,GAChB,QAAS,IAAI,WAAW,CACtB,EAAM,EAAM,EAAM,EAAM,GAAM,EAAM,EAAM,EAAM,EAAM,CACxD,CAAC,CACH,EACMC,EAAa,CACjB,iBAAkB,GAAG,GAAG,EAAE,kBAAkBN,EAAMK,CAAW,CAAC,CAChE,EAIME,EAAS,MADA,IAAIN,EAA4BK,CAAU,EAC7B,gBAAgBF,CAAgB,EAG5D,OAAOG,CAAM,EAAE,QAAQF,CAAW,EAClC,OAAOC,EAAW,gBAAgB,EAAE,qBAClCF,CACF,CACF,CAAC,EAED,GAAG,oDAAqD,SAAY,CAElE,MAAMA,EAAuC,CAC3C,aAAc,eACd,SAAUD,EAAS,SACnB,MAAOD,EAAM,UACf,EACMM,EAAa,IAAI,MAAM,QAAQ,EAC/BF,EAAa,CACjB,iBAAkB,GAAG,GAAG,EAAE,kBAAkBP,EAAKS,CAAU,CAAC,CAC9D,EACMC,EAAS,IAAIR,EAA4BK,CAAU,EAGzD,MAAM,OAAOG,EAAO,gBAAgBL,CAAgB,CAAC,EAAE,QAAQ,QAC7DI,CACF,EACA,OAAOF,EAAW,gBAAgB,EAAE,qBAClCF,CACF,CACF,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["Left", "Right", "DefaultPkiCertificateLoader", "KeyId", "KeyUsage", "certificateInfos", "certificate", "dataSource", "result", "fetchError", "loader"]
4
+ "sourcesContent": ["import { Left, Right } from \"purify-ts\";\n\nimport { DefaultPkiCertificateLoader } from \"@/pki/domain/DefaultPkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { type PkiCertificateInfo } from \"@/pki/model/PkiCertificateInfo\";\n\ndescribe(\"DefaultPkiCertificateLoader\", () => {\n describe(\"loadCertificate\", () => {\n it(\"should call loadCertificate\", async () => {\n // GIVEN\n const certificateInfos: PkiCertificateInfo = {\n targetDevice: \"targetDevice\",\n keyUsage: KeyUsage.Calldata,\n keyId: KeyId.CalNetwork,\n };\n const certificate = {\n keyUsageNumber: 11,\n payload: new Uint8Array([\n 0x01, 0x02, 0x03, 0x04, 0x15, 0x04, 0x05, 0x06, 0x07, 0x08,\n ]),\n };\n const dataSource = {\n fetchCertificate: vi.fn().mockResolvedValue(Right(certificate)),\n };\n\n // WHEN\n const loader = new DefaultPkiCertificateLoader(dataSource);\n const result = await loader.loadCertificate(certificateInfos);\n\n // THEN\n expect(result).toEqual(certificate);\n expect(dataSource.fetchCertificate).toHaveBeenCalledWith(\n certificateInfos,\n );\n });\n\n it(\"Returns undefined when the data source returns a Left(error)\", async () => {\n // given\n const certificateInfos: PkiCertificateInfo = {\n targetDevice: \"targetDevice\",\n keyUsage: KeyUsage.Calldata,\n keyId: KeyId.CalNetwork,\n };\n const fetchError = new Error(\"failed\");\n const dataSource = {\n fetchCertificate: vi.fn().mockResolvedValue(Left(fetchError)),\n };\n const loader = new DefaultPkiCertificateLoader(dataSource);\n\n // when / then\n const result = await loader.loadCertificate(certificateInfos);\n expect(result).toBeUndefined();\n expect(dataSource.fetchCertificate).toHaveBeenCalledWith(\n certificateInfos,\n );\n });\n });\n});\n"],
5
+ "mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAE5B,OAAS,+BAAAC,MAAmC,2CAC5C,OAAS,SAAAC,MAAa,oBACtB,OAAS,YAAAC,MAAgB,uBAGzB,SAAS,8BAA+B,IAAM,CAC5C,SAAS,kBAAmB,IAAM,CAChC,GAAG,8BAA+B,SAAY,CAE5C,MAAMC,EAAuC,CAC3C,aAAc,eACd,SAAUD,EAAS,SACnB,MAAOD,EAAM,UACf,EACMG,EAAc,CAClB,eAAgB,GAChB,QAAS,IAAI,WAAW,CACtB,EAAM,EAAM,EAAM,EAAM,GAAM,EAAM,EAAM,EAAM,EAAM,CACxD,CAAC,CACH,EACMC,EAAa,CACjB,iBAAkB,GAAG,GAAG,EAAE,kBAAkBN,EAAMK,CAAW,CAAC,CAChE,EAIME,EAAS,MADA,IAAIN,EAA4BK,CAAU,EAC7B,gBAAgBF,CAAgB,EAG5D,OAAOG,CAAM,EAAE,QAAQF,CAAW,EAClC,OAAOC,EAAW,gBAAgB,EAAE,qBAClCF,CACF,CACF,CAAC,EAED,GAAG,+DAAgE,SAAY,CAE7E,MAAMA,EAAuC,CAC3C,aAAc,eACd,SAAUD,EAAS,SACnB,MAAOD,EAAM,UACf,EACMM,EAAa,IAAI,MAAM,QAAQ,EAC/BF,EAAa,CACjB,iBAAkB,GAAG,GAAG,EAAE,kBAAkBP,EAAKS,CAAU,CAAC,CAC9D,EAIMD,EAAS,MAHA,IAAIN,EAA4BK,CAAU,EAG7B,gBAAgBF,CAAgB,EAC5D,OAAOG,CAAM,EAAE,cAAc,EAC7B,OAAOD,EAAW,gBAAgB,EAAE,qBAClCF,CACF,CACF,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["Left", "Right", "DefaultPkiCertificateLoader", "KeyId", "KeyUsage", "certificateInfos", "certificate", "dataSource", "result", "fetchError"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var t=(e=>(e.TOKEN="token",e.NFT="nft",e.TRUSTED_NAME="trustedName",e.PLUGIN="plugin",e.EXTERNAL_PLUGIN="externalPlugin",e.TRANSACTION_INFO="transactionInfo",e.ENUM="enum",e.TRANSACTION_FIELD_DESCRIPTION="transactionFieldDescription",e.WEB3_CHECK="web3Check",e.ERROR="error",e))(t||{});export{t as ClearSignContextType};
1
+ var t=(e=>(e.TOKEN="token",e.NFT="nft",e.TRUSTED_NAME="trustedName",e.PLUGIN="plugin",e.EXTERNAL_PLUGIN="externalPlugin",e.TRANSACTION_INFO="transactionInfo",e.PROXY_DELEGATE_CALL="proxyDelegateCall",e.ENUM="enum",e.TRANSACTION_FIELD_DESCRIPTION="transactionFieldDescription",e.WEB3_CHECK="web3Check",e.DYNAMIC_NETWORK="dynamicNetwork",e.DYNAMIC_NETWORK_ICON="dynamicNetworkIcon",e.ERROR="error",e))(t||{});export{t as ClearSignContextType};
2
2
  //# sourceMappingURL=ClearSignContext.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/shared/model/ClearSignContext.ts"],
4
- "sourcesContent": ["import { type PkiCertificate } from \"@/pki/model/PkiCertificate\";\n\nimport { type GenericPath } from \"./GenericPath\";\n\nexport enum ClearSignContextType {\n TOKEN = \"token\",\n NFT = \"nft\",\n TRUSTED_NAME = \"trustedName\",\n PLUGIN = \"plugin\",\n EXTERNAL_PLUGIN = \"externalPlugin\",\n TRANSACTION_INFO = \"transactionInfo\",\n ENUM = \"enum\",\n TRANSACTION_FIELD_DESCRIPTION = \"transactionFieldDescription\",\n WEB3_CHECK = \"web3Check\",\n ERROR = \"error\",\n}\n\nexport type ClearSignContextReferenceType =\n | ClearSignContextType.TOKEN\n | ClearSignContextType.NFT\n | ClearSignContextType.ENUM\n | ClearSignContextType.TRUSTED_NAME;\n\nexport type ClearSignContextReference<\n Type extends ClearSignContextReferenceType = ClearSignContextReferenceType,\n> = Type extends ClearSignContextType.ENUM\n ? {\n type: ClearSignContextType.ENUM;\n valuePath: GenericPath;\n id: number; // enum id to reference\n }\n : Type extends ClearSignContextType.TRUSTED_NAME\n ? {\n type: ClearSignContextType.TRUSTED_NAME;\n valuePath: GenericPath;\n types: string[];\n sources: string[];\n }\n :\n | {\n type: Type;\n valuePath: GenericPath;\n value?: never;\n }\n | {\n type: Type;\n valuePath?: never;\n value: string;\n };\n\nexport type ClearSignContextSuccessType = Exclude<\n ClearSignContextType,\n ClearSignContextType.ERROR\n>;\n\n// NOTE: this is a union of all possible success types\n// There is currently two types of success:\n// - ENUM: which is a special case, we need to handle it differently\n// because we don't want to send the whole enum\n// but only the parts that are needed.\n// - id: the enum id to reference\n// - payload: the payload to send with a provideEnum command\n// - name: the name of the enum to be displayed on the device\n// - value: the value of the enum to be retrieved from the transaction\n// - All other types\n// - payload: the payload to send with a provide command\n// - reference: the reference to the value to be retrieved from the transaction\nexport type ClearSignContextSuccess<\n Type extends ClearSignContextSuccessType = ClearSignContextSuccessType,\n> = Type extends ClearSignContextType.ENUM\n ? {\n type: ClearSignContextType.ENUM;\n id: number;\n payload: string;\n value: number;\n certificate?: PkiCertificate;\n }\n : {\n type: Exclude<\n ClearSignContextType,\n ClearSignContextType.ENUM | ClearSignContextType.ERROR\n >;\n payload: string;\n reference?: ClearSignContextReference;\n certificate?: PkiCertificate;\n };\n\nexport type ClearSignContextError = {\n type: ClearSignContextType.ERROR;\n error: Error;\n};\n\nexport type ClearSignContext = ClearSignContextSuccess | ClearSignContextError;\n"],
5
- "mappings": "AAIO,IAAKA,OACVA,EAAA,MAAQ,QACRA,EAAA,IAAM,MACNA,EAAA,aAAe,cACfA,EAAA,OAAS,SACTA,EAAA,gBAAkB,iBAClBA,EAAA,iBAAmB,kBACnBA,EAAA,KAAO,OACPA,EAAA,8BAAgC,8BAChCA,EAAA,WAAa,YACbA,EAAA,MAAQ,QAVEA,OAAA",
4
+ "sourcesContent": ["import { type PkiCertificate } from \"@/pki/model/PkiCertificate\";\n\nimport { type GenericPath } from \"./GenericPath\";\n\nexport enum ClearSignContextType {\n TOKEN = \"token\",\n NFT = \"nft\",\n TRUSTED_NAME = \"trustedName\",\n PLUGIN = \"plugin\",\n EXTERNAL_PLUGIN = \"externalPlugin\",\n TRANSACTION_INFO = \"transactionInfo\",\n PROXY_DELEGATE_CALL = \"proxyDelegateCall\",\n ENUM = \"enum\",\n TRANSACTION_FIELD_DESCRIPTION = \"transactionFieldDescription\",\n WEB3_CHECK = \"web3Check\",\n DYNAMIC_NETWORK = \"dynamicNetwork\",\n DYNAMIC_NETWORK_ICON = \"dynamicNetworkIcon\",\n ERROR = \"error\",\n}\n\nexport type ClearSignContextReferenceType =\n | ClearSignContextType.TOKEN\n | ClearSignContextType.NFT\n | ClearSignContextType.ENUM\n | ClearSignContextType.TRUSTED_NAME;\n\nexport type ClearSignContextReference<\n Type extends ClearSignContextReferenceType = ClearSignContextReferenceType,\n> = Type extends ClearSignContextType.ENUM\n ? {\n type: ClearSignContextType.ENUM;\n valuePath: GenericPath;\n id: number; // enum id to reference\n }\n : Type extends ClearSignContextType.TRUSTED_NAME\n ? {\n type: ClearSignContextType.TRUSTED_NAME;\n valuePath: GenericPath;\n types: string[];\n sources: string[];\n }\n :\n | {\n type: Type;\n valuePath: GenericPath;\n value?: never;\n }\n | {\n type: Type;\n valuePath?: never;\n value: string;\n };\n\nexport type ClearSignContextSuccessType = Exclude<\n ClearSignContextType,\n ClearSignContextType.ERROR\n>;\n\n// NOTE: this is a union of all possible success types\n// There is currently two types of success:\n// - ENUM: which is a special case, we need to handle it differently\n// because we don't want to send the whole enum\n// but only the parts that are needed.\n// - id: the enum id to reference\n// - payload: the payload to send with a provideEnum command\n// - name: the name of the enum to be displayed on the device\n// - value: the value of the enum to be retrieved from the transaction\n// - All other types\n// - payload: the payload to send with a provide command\n// - reference: the reference to the value to be retrieved from the transaction\nexport type ClearSignContextSuccess<\n Type extends ClearSignContextSuccessType = ClearSignContextSuccessType,\n> = Type extends ClearSignContextType.ENUM\n ? {\n type: ClearSignContextType.ENUM;\n id: number;\n payload: string;\n value: number;\n certificate?: PkiCertificate;\n }\n : {\n type: Exclude<\n ClearSignContextType,\n ClearSignContextType.ENUM | ClearSignContextType.ERROR\n >;\n payload: string;\n reference?: ClearSignContextReference;\n certificate?: PkiCertificate;\n };\n\nexport type ClearSignContextError = {\n type: ClearSignContextType.ERROR;\n error: Error;\n};\n\nexport type ClearSignContext = ClearSignContextSuccess | ClearSignContextError;\n"],
5
+ "mappings": "AAIO,IAAKA,OACVA,EAAA,MAAQ,QACRA,EAAA,IAAM,MACNA,EAAA,aAAe,cACfA,EAAA,OAAS,SACTA,EAAA,gBAAkB,iBAClBA,EAAA,iBAAmB,kBACnBA,EAAA,oBAAsB,oBACtBA,EAAA,KAAO,OACPA,EAAA,8BAAgC,8BAChCA,EAAA,WAAa,YACbA,EAAA,gBAAkB,iBAClBA,EAAA,qBAAuB,qBACvBA,EAAA,MAAQ,QAbEA,OAAA",
6
6
  "names": ["ClearSignContextType"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var w=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var u=(s,e,o,t)=>{for(var r=t>1?void 0:t?g(e,o):e,a=s.length-1,n;a>=0;a--)(n=s[a])&&(r=(t?n(e,o,r):n(r))||r);return t&&r&&w(e,o,r),r},f=(s,e)=>(o,t)=>e(o,t,s);import{hexaStringToBuffer as h}from"@ledgerhq/device-management-kit";import p from"axios";import{inject as E,injectable as A}from"inversify";import{Left as i,Right as d}from"purify-ts";import{configTypes as O}from"../../config/di/configTypes";import{LEDGER_CLIENT_VERSION_HEADER as S,LEDGER_ORIGIN_TOKEN_HEADER as C}from"../../shared/constant/HttpHeaders";import m from"../../../package.json";let c=class{constructor(e){this.config=e;if(!this.config.originToken)throw new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: origin token is required")}isSolanaSPLOwnerInfo(e){return typeof e!="object"||e===null?!1:typeof e.tokenAccount=="string"&&typeof e.owner=="string"&&typeof e.contract=="string"&&typeof e.signedDescriptor=="string"}async fetchAddressMetadata(e,o){return await p.request({method:"GET",url:`${this.config.metadataService.url}/solana/owner/${e}?challenge=${o}`,headers:{[S]:`context-module/${m.version}`,[C]:this.config.originToken}}).then(t=>this.isSolanaSPLOwnerInfo(t.data)?d(t.data):i(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid fetchAddressMetadata response shape"))).catch(()=>i(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to fetch address metadata")))}async computeAddressMetadata(e,o,t){return await p.request({method:"GET",url:`${this.config.metadataService.url}/solana/computed-token-account/${e}/${o}?challenge=${t}`,headers:{[S]:`context-module/${m.version}`,"X-Ledger-Client-Origin":this.config.originToken}}).then(r=>this.isSolanaSPLOwnerInfo(r.data)?d(r.data):i(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid computeAddressMetadata response shape"))).catch(()=>i(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to compute address metadata")))}async getOwnerInfo(e){const{tokenAddress:o,challenge:t,createATA:r}=e;if(!t)return i(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: challenge is required"));let a;if(o)a=await this.fetchAddressMetadata(o,t);else if(r?.address&&r?.mintAddress)a=await this.computeAddressMetadata(r.address,r.mintAddress,t);else return i(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: either tokenAddress or valid createATA must be provided"));return a.chain(n=>{const l=h(n.signedDescriptor);return l?d({descriptor:l,tokenAccount:n.tokenAccount,owner:n.owner,contract:n.contract}):i(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid base64 descriptor received"))})}};c=u([A(),f(0,E(O.Config))],c);export{c as HttpSolanaOwnerInfoDataSource};
1
+ var w=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var u=(s,e,o,t)=>{for(var r=t>1?void 0:t?g(e,o):e,a=s.length-1,n;a>=0;a--)(n=s[a])&&(r=(t?n(e,o,r):n(r))||r);return t&&r&&w(e,o,r),r},f=(s,e)=>(o,t)=>e(o,t,s);import{hexaStringToBuffer as h}from"@ledgerhq/device-management-kit";import m from"axios";import{inject as E,injectable as A}from"inversify";import{Left as i,Right as d}from"purify-ts";import{configTypes as O}from"../../config/di/configTypes";import{LEDGER_CLIENT_VERSION_HEADER as p,LEDGER_ORIGIN_TOKEN_HEADER as C}from"../../shared/constant/HttpHeaders";import S from"../../../package.json";let c=class{constructor(e){this.config=e;if(!this.config.originToken)throw new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: origin token is required")}isSolanaSPLOwnerInfo(e){return typeof e!="object"||e===null?!1:typeof e.tokenAccount=="string"&&typeof e.owner=="string"&&typeof e.contract=="string"&&typeof e.signedDescriptor=="string"}async fetchAddressMetadata(e,o){return await m.request({method:"GET",url:`${this.config.metadataServiceDomain.url}/v2/solana/owner/${e}?challenge=${o}`,headers:{[p]:`context-module/${S.version}`,[C]:this.config.originToken}}).then(t=>this.isSolanaSPLOwnerInfo(t.data)?d(t.data):i(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid fetchAddressMetadata response shape"))).catch(()=>i(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to fetch address metadata")))}async computeAddressMetadata(e,o,t){return await m.request({method:"GET",url:`${this.config.metadataServiceDomain.url}/v2/solana/computed-token-account/${e}/${o}?challenge=${t}`,headers:{[p]:`context-module/${S.version}`,"X-Ledger-Client-Origin":this.config.originToken}}).then(r=>this.isSolanaSPLOwnerInfo(r.data)?d(r.data):i(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid computeAddressMetadata response shape"))).catch(()=>i(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to compute address metadata")))}async getOwnerInfo(e){const{tokenAddress:o,challenge:t,createATA:r}=e;if(!t)return i(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: challenge is required"));let a;if(o)a=await this.fetchAddressMetadata(o,t);else if(r?.address&&r?.mintAddress)a=await this.computeAddressMetadata(r.address,r.mintAddress,t);else return i(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: either tokenAddress or valid createATA must be provided"));return a.chain(n=>{const l=h(n.signedDescriptor);return l?d({descriptor:l,tokenAccount:n.tokenAccount,owner:n.owner,contract:n.contract}):i(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid base64 descriptor received"))})}};c=u([A(),f(0,E(O.Config))],c);export{c as HttpSolanaOwnerInfoDataSource};
2
2
  //# sourceMappingURL=HttpSolanaOwnerInfoDataSource.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/solana/data/HttpSolanaOwnerInfoDataSource.ts"],
4
- "sourcesContent": ["import { hexaStringToBuffer } from \"@ledgerhq/device-management-kit\";\nimport axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport type { ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport {\n SolanaSPLOwnerInfo,\n type SolanaTransactionContext,\n} from \"@/solana/domain/solanaContextTypes\";\nimport PACKAGE from \"@root/package.json\";\n\nimport {\n HttpSolanaOwnerInfoDataSourceResult,\n SolanaDataSource,\n} from \"./SolanaDataSource\";\n\n@injectable()\nexport class HttpSolanaOwnerInfoDataSource implements SolanaDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n ) {\n if (!this.config.originToken) {\n throw new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: origin token is required\",\n );\n }\n }\n\n private isSolanaSPLOwnerInfo(data: {\n tokenAccount?: unknown;\n owner?: unknown;\n contract?: unknown;\n signedDescriptor?: unknown;\n }): data is SolanaSPLOwnerInfo {\n if (typeof data !== \"object\" || data === null) return false;\n return (\n typeof data.tokenAccount === \"string\" &&\n typeof data.owner === \"string\" &&\n typeof data.contract === \"string\" &&\n typeof data.signedDescriptor === \"string\"\n );\n }\n\n async fetchAddressMetadata(\n tokenAddress: string,\n challenge: string,\n ): Promise<Either<Error, SolanaSPLOwnerInfo>> {\n return await axios\n .request<SolanaSPLOwnerInfo>({\n method: \"GET\",\n url: `${this.config.metadataService.url}/solana/owner/${tokenAddress}?challenge=${challenge}`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n })\n .then((res) => {\n if (!this.isSolanaSPLOwnerInfo(res.data))\n return Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid fetchAddressMetadata response shape\",\n ),\n );\n return Right(res.data);\n })\n .catch(() =>\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to fetch address metadata\",\n ),\n ),\n );\n }\n\n async computeAddressMetadata(\n address: string,\n mintAddress: string,\n challenge: string,\n ): Promise<Either<Error, SolanaSPLOwnerInfo>> {\n return await axios\n .request<SolanaSPLOwnerInfo>({\n method: \"GET\",\n url: `${this.config.metadataService.url}/solana/computed-token-account/${address}/${mintAddress}?challenge=${challenge}`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n \"X-Ledger-Client-Origin\": this.config.originToken,\n },\n })\n .then((res) => {\n if (!this.isSolanaSPLOwnerInfo(res.data))\n return Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid computeAddressMetadata response shape\",\n ),\n );\n return Right(res.data);\n })\n .catch(() =>\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to compute address metadata\",\n ),\n ),\n );\n }\n\n async getOwnerInfo(\n context: SolanaTransactionContext,\n ): Promise<Either<Error, HttpSolanaOwnerInfoDataSourceResult>> {\n const { tokenAddress, challenge, createATA } = context;\n\n if (!challenge) {\n return Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: challenge is required\",\n ),\n );\n }\n\n let ownerInfoResult: Either<Error, SolanaSPLOwnerInfo>;\n\n if (tokenAddress) {\n ownerInfoResult = await this.fetchAddressMetadata(\n tokenAddress,\n challenge,\n );\n } else if (createATA?.address && createATA?.mintAddress) {\n ownerInfoResult = await this.computeAddressMetadata(\n createATA.address,\n createATA.mintAddress,\n challenge,\n );\n } else {\n return Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: either tokenAddress or valid createATA must be provided\",\n ),\n );\n }\n\n return ownerInfoResult.chain((ownerInfo) => {\n const descriptor = hexaStringToBuffer(ownerInfo.signedDescriptor);\n if (!descriptor) {\n return Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid base64 descriptor received\",\n ),\n );\n }\n return Right({\n descriptor,\n tokenAccount: ownerInfo.tokenAccount,\n owner: ownerInfo.owner,\n contract: ownerInfo.contract,\n });\n });\n }\n}\n"],
5
- "mappings": "iOAAA,OAAS,sBAAAA,MAA0B,kCACnC,OAAOC,MAAW,QAClB,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YACnC,OAAiB,QAAAC,EAAM,SAAAC,MAAa,YAEpC,OAAS,eAAAC,MAAmB,0BAE5B,OACE,gCAAAC,EACA,8BAAAC,MACK,gCAKP,OAAOC,MAAa,qBAQb,IAAMC,EAAN,KAAgE,CACrE,YAC+CC,EAC7C,CAD6C,YAAAA,EAE7C,GAAI,CAAC,KAAK,OAAO,YACf,MAAM,IAAI,MACR,2EACF,CAEJ,CAEQ,qBAAqBC,EAKE,CAC7B,OAAI,OAAOA,GAAS,UAAYA,IAAS,KAAa,GAEpD,OAAOA,EAAK,cAAiB,UAC7B,OAAO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,QACVA,EAAU,YACVX,CACF,MAEA,QAAOO,EACL,IAAI,MACF,0GACF,CACF,EAGF,OAAOK,EAAgB,MAAOC,GAAc,CAC1C,MAAMC,EAAaC,EAAmBF,EAAU,gBAAgB,EAChE,OAAKC,EAOER,EAAM,CACX,WAAAQ,EACA,aAAcD,EAAU,aACxB,MAAOA,EAAU,MACjB,SAAUA,EAAU,QACtB,CAAC,EAXQN,EACL,IAAI,MACF,qFACF,CACF,CAQJ,CAAC,CACH,CACF,EA5IaX,EAANoB,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAY,MAAM,IAFjBxB",
4
+ "sourcesContent": ["import { hexaStringToBuffer } from \"@ledgerhq/device-management-kit\";\nimport axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport type { ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport {\n SolanaSPLOwnerInfo,\n type SolanaTransactionContext,\n} from \"@/solana/domain/solanaContextTypes\";\nimport PACKAGE from \"@root/package.json\";\n\nimport {\n HttpSolanaOwnerInfoDataSourceResult,\n SolanaDataSource,\n} from \"./SolanaDataSource\";\n\n@injectable()\nexport class HttpSolanaOwnerInfoDataSource implements SolanaDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n ) {\n if (!this.config.originToken) {\n throw new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: origin token is required\",\n );\n }\n }\n\n private isSolanaSPLOwnerInfo(data: {\n tokenAccount?: unknown;\n owner?: unknown;\n contract?: unknown;\n signedDescriptor?: unknown;\n }): data is SolanaSPLOwnerInfo {\n if (typeof data !== \"object\" || data === null) return false;\n return (\n typeof data.tokenAccount === \"string\" &&\n typeof data.owner === \"string\" &&\n typeof data.contract === \"string\" &&\n typeof data.signedDescriptor === \"string\"\n );\n }\n\n async fetchAddressMetadata(\n tokenAddress: string,\n challenge: string,\n ): Promise<Either<Error, SolanaSPLOwnerInfo>> {\n return await axios\n .request<SolanaSPLOwnerInfo>({\n method: \"GET\",\n url: `${this.config.metadataServiceDomain.url}/v2/solana/owner/${tokenAddress}?challenge=${challenge}`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n })\n .then((res) => {\n if (!this.isSolanaSPLOwnerInfo(res.data))\n return Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid fetchAddressMetadata response shape\",\n ),\n );\n return Right(res.data);\n })\n .catch(() =>\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to fetch address metadata\",\n ),\n ),\n );\n }\n\n async computeAddressMetadata(\n address: string,\n mintAddress: string,\n challenge: string,\n ): Promise<Either<Error, SolanaSPLOwnerInfo>> {\n return await axios\n .request<SolanaSPLOwnerInfo>({\n method: \"GET\",\n url: `${this.config.metadataServiceDomain.url}/v2/solana/computed-token-account/${address}/${mintAddress}?challenge=${challenge}`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n \"X-Ledger-Client-Origin\": this.config.originToken,\n },\n })\n .then((res) => {\n if (!this.isSolanaSPLOwnerInfo(res.data))\n return Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid computeAddressMetadata response shape\",\n ),\n );\n return Right(res.data);\n })\n .catch(() =>\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to compute address metadata\",\n ),\n ),\n );\n }\n\n async getOwnerInfo(\n context: SolanaTransactionContext,\n ): Promise<Either<Error, HttpSolanaOwnerInfoDataSourceResult>> {\n const { tokenAddress, challenge, createATA } = context;\n\n if (!challenge) {\n return Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: challenge is required\",\n ),\n );\n }\n\n let ownerInfoResult: Either<Error, SolanaSPLOwnerInfo>;\n\n if (tokenAddress) {\n ownerInfoResult = await this.fetchAddressMetadata(\n tokenAddress,\n challenge,\n );\n } else if (createATA?.address && createATA?.mintAddress) {\n ownerInfoResult = await this.computeAddressMetadata(\n createATA.address,\n createATA.mintAddress,\n challenge,\n );\n } else {\n return Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: either tokenAddress or valid createATA must be provided\",\n ),\n );\n }\n\n return ownerInfoResult.chain((ownerInfo) => {\n const descriptor = hexaStringToBuffer(ownerInfo.signedDescriptor);\n if (!descriptor) {\n return Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid base64 descriptor received\",\n ),\n );\n }\n return Right({\n descriptor,\n tokenAccount: ownerInfo.tokenAccount,\n owner: ownerInfo.owner,\n contract: ownerInfo.contract,\n });\n });\n }\n}\n"],
5
+ "mappings": "iOAAA,OAAS,sBAAAA,MAA0B,kCACnC,OAAOC,MAAW,QAClB,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YACnC,OAAiB,QAAAC,EAAM,SAAAC,MAAa,YAEpC,OAAS,eAAAC,MAAmB,0BAE5B,OACE,gCAAAC,EACA,8BAAAC,MACK,gCAKP,OAAOC,MAAa,qBAQb,IAAMC,EAAN,KAAgE,CACrE,YAC+CC,EAC7C,CAD6C,YAAAA,EAE7C,GAAI,CAAC,KAAK,OAAO,YACf,MAAM,IAAI,MACR,2EACF,CAEJ,CAEQ,qBAAqBC,EAKE,CAC7B,OAAI,OAAOA,GAAS,UAAYA,IAAS,KAAa,GAEpD,OAAOA,EAAK,cAAiB,UAC7B,OAAOA,EAAK,OAAU,UACtB,OAAOA,EAAK,UAAa,UACzB,OAAOA,EAAK,kBAAqB,QAErC,CAEA,MAAM,qBACJC,EACAC,EAC4C,CAC5C,OAAO,MAAMC,EACV,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U,gBAAgB,EAChE,OAAKC,EAOER,EAAM,CACX,WAAAQ,EACA,aAAcD,EAAU,aACxB,MAAOA,EAAU,MACjB,SAAUA,EAAU,QACtB,CAAC,EAXQN,EACL,IAAI,MACF,qFACF,CACF,CAQJ,CAAC,CACH,CACF,EA5IaX,EAANoB,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAY,MAAM,IAFjBxB",
6
6
  "names": ["hexaStringToBuffer", "axios", "inject", "injectable", "Left", "Right", "configTypes", "LEDGER_CLIENT_VERSION_HEADER", "LEDGER_ORIGIN_TOKEN_HEADER", "PACKAGE", "HttpSolanaOwnerInfoDataSource", "config", "data", "tokenAddress", "challenge", "axios", "LEDGER_CLIENT_VERSION_HEADER", "PACKAGE", "LEDGER_ORIGIN_TOKEN_HEADER", "res", "Right", "Left", "address", "mintAddress", "context", "createATA", "ownerInfoResult", "ownerInfo", "descriptor", "hexaStringToBuffer", "__decorateClass", "injectable", "__decorateParam", "inject", "configTypes"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{DeviceModelId as r,hexaStringToBuffer as l}from"@ledgerhq/device-management-kit";import s from"axios";import{Left as c}from"purify-ts";import{LEDGER_CLIENT_VERSION_HEADER as u}from"../../shared/constant/HttpHeaders";import{HttpSolanaOwnerInfoDataSource as n}from"../../solana/data/HttpSolanaOwnerInfoDataSource";import m from"../../../package.json";vi.mock("axios");function f(o){const d=new TextEncoder().encode(o);return Array.from(d).map(e=>e.toString(16).padStart(2,"0")).join("")}describe("HttpSolanaOwnerInfoDataSource",()=>{const o={metadataService:{url:"https://some.doma.in"},originToken:"mock-origin-token"},i=f("mock-descriptor"),d={tokenAccount:"token-account",owner:"owner-address",contract:"contract-address",signedDescriptor:i};beforeEach(()=>{vi.resetAllMocks()}),it("should fetch address metadata via tokenAddress",async()=>{const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0};vi.spyOn(s,"request").mockResolvedValueOnce({data:d});const t=await new n(o).getOwnerInfo(e);expect(t.isRight()).toBe(!0),expect(t.extract()).toEqual({descriptor:l(i),tokenAccount:"token-account",owner:"owner-address",contract:"contract-address"})}),it("should compute address when tokenAddress is not provided",async()=>{const e={deviceModelId:r.FLEX,tokenAddress:void 0,challenge:"random",createATA:{address:"some-address",mintAddress:"some-mint"}};vi.spyOn(s,"request").mockResolvedValueOnce({data:d});const t=await new n(o).getOwnerInfo(e);expect(t.isRight()).toBe(!0),expect(t.extract().tokenAccount).toBe("token-account")}),it("should return an error if both tokenAddress and createATA are missing or invalid",async()=>{const e={deviceModelId:r.FLEX,tokenAddress:void 0,challenge:"random",createATA:void 0},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(c(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: either tokenAddress or valid createATA must be provided")))}),it("should return an error if challenge is missing",async()=>{const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:void 0,createATA:void 0},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(c(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: challenge is required")))}),it("should return an error if the descriptor is not valid base64",async()=>{vi.spyOn(s,"request").mockResolvedValueOnce({data:{...d,signedDescriptor:"!!!not-valid-base64!!!"}});const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(c(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid base64 descriptor received")))}),it("should return an error if the metadata request fails",async()=>{vi.spyOn(s,"request").mockRejectedValueOnce(new Error("Network error"));const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(c(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to fetch address metadata")))}),it("should return an error if axios request return wrong shape for fetchAddressMetadata",async()=>{vi.spyOn(s,"request").mockResolvedValueOnce({data:{wrong:"field"}});const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(c(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid fetchAddressMetadata response shape")))}),it("should return an error if axios request return wrong shape for computeAddressMetadata",async()=>{vi.spyOn(s,"request").mockResolvedValueOnce({data:{wrong:"field"}});const e={deviceModelId:r.FLEX,tokenAddress:void 0,challenge:"random",createATA:{address:"some-address",mintAddress:"some-mint"}},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(c(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid computeAddressMetadata response shape")))}),it("should throw if originToken is missing",()=>{expect(()=>{new n({...o,originToken:void 0})}).toThrow("[ContextModule] - HttpSolanaOwnerInfoDataSource: origin token is required")}),it("should call axios with correct headers",async()=>{const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},a=vi.spyOn(s,"request").mockResolvedValueOnce({data:d});await new n(o).getOwnerInfo(e),expect(a).toHaveBeenCalledWith(expect.objectContaining({headers:{[u]:`context-module/${m.version}`,"X-Ledger-Client-Origin":o.originToken}}))})});
1
+ import{DeviceModelId as r,hexaStringToBuffer as l}from"@ledgerhq/device-management-kit";import s from"axios";import{Left as c}from"purify-ts";import{LEDGER_CLIENT_VERSION_HEADER as u}from"../../shared/constant/HttpHeaders";import{HttpSolanaOwnerInfoDataSource as n}from"../../solana/data/HttpSolanaOwnerInfoDataSource";import m from"../../../package.json";vi.mock("axios");function f(o){const d=new TextEncoder().encode(o);return Array.from(d).map(e=>e.toString(16).padStart(2,"0")).join("")}describe("HttpSolanaOwnerInfoDataSource",()=>{const o={metadataServiceDomain:{url:"https://some.doma.in"},originToken:"mock-origin-token"},i=f("mock-descriptor"),d={tokenAccount:"token-account",owner:"owner-address",contract:"contract-address",signedDescriptor:i};beforeEach(()=>{vi.resetAllMocks()}),it("should fetch address metadata via tokenAddress",async()=>{const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0};vi.spyOn(s,"request").mockResolvedValueOnce({data:d});const t=await new n(o).getOwnerInfo(e);expect(t.isRight()).toBe(!0),expect(t.extract()).toEqual({descriptor:l(i),tokenAccount:"token-account",owner:"owner-address",contract:"contract-address"})}),it("should compute address when tokenAddress is not provided",async()=>{const e={deviceModelId:r.FLEX,tokenAddress:void 0,challenge:"random",createATA:{address:"some-address",mintAddress:"some-mint"}};vi.spyOn(s,"request").mockResolvedValueOnce({data:d});const t=await new n(o).getOwnerInfo(e);expect(t.isRight()).toBe(!0),expect(t.extract().tokenAccount).toBe("token-account")}),it("should return an error if both tokenAddress and createATA are missing or invalid",async()=>{const e={deviceModelId:r.FLEX,tokenAddress:void 0,challenge:"random",createATA:void 0},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(c(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: either tokenAddress or valid createATA must be provided")))}),it("should return an error if challenge is missing",async()=>{const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:void 0,createATA:void 0},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(c(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: challenge is required")))}),it("should return an error if the descriptor is not valid base64",async()=>{vi.spyOn(s,"request").mockResolvedValueOnce({data:{...d,signedDescriptor:"!!!not-valid-base64!!!"}});const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(c(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid base64 descriptor received")))}),it("should return an error if the metadata request fails",async()=>{vi.spyOn(s,"request").mockRejectedValueOnce(new Error("Network error"));const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(c(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to fetch address metadata")))}),it("should return an error if axios request return wrong shape for fetchAddressMetadata",async()=>{vi.spyOn(s,"request").mockResolvedValueOnce({data:{wrong:"field"}});const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(c(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid fetchAddressMetadata response shape")))}),it("should return an error if axios request return wrong shape for computeAddressMetadata",async()=>{vi.spyOn(s,"request").mockResolvedValueOnce({data:{wrong:"field"}});const e={deviceModelId:r.FLEX,tokenAddress:void 0,challenge:"random",createATA:{address:"some-address",mintAddress:"some-mint"}},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(c(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid computeAddressMetadata response shape")))}),it("should throw if originToken is missing",()=>{expect(()=>{new n({...o,originToken:void 0})}).toThrow("[ContextModule] - HttpSolanaOwnerInfoDataSource: origin token is required")}),it("should call axios with correct headers",async()=>{const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},a=vi.spyOn(s,"request").mockResolvedValueOnce({data:d});await new n(o).getOwnerInfo(e),expect(a).toHaveBeenCalledWith(expect.objectContaining({headers:{[u]:`context-module/${m.version}`,"X-Ledger-Client-Origin":o.originToken}}))})});
2
2
  //# sourceMappingURL=HttpSolanaOwnerInfoDataSource.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/solana/data/HttpSolanaOwnerInfoDataSource.test.ts"],
4
- "sourcesContent": ["/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n DeviceModelId,\n hexaStringToBuffer,\n} from \"@ledgerhq/device-management-kit\";\nimport axios from \"axios\";\nimport { Left } from \"purify-ts\";\n\nimport type { ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { LEDGER_CLIENT_VERSION_HEADER } from \"@/shared/constant/HttpHeaders\";\nimport { HttpSolanaOwnerInfoDataSource } from \"@/solana/data/HttpSolanaOwnerInfoDataSource\";\nimport type { SolanaTransactionContext } from \"@/solana/domain/solanaContextTypes\";\nimport PACKAGE from \"@root/package.json\";\n\nvi.mock(\"axios\");\n\nfunction stringToHex(str: string): string {\n const encoder = new TextEncoder();\n const bytes = encoder.encode(str); // Uint8Array\n return Array.from(bytes)\n .map((byte) => byte.toString(16).padStart(2, \"0\"))\n .join(\"\");\n}\n\ndescribe(\"HttpSolanaOwnerInfoDataSource\", () => {\n const config = {\n metadataService: { url: \"https://some.doma.in\" },\n originToken: \"mock-origin-token\",\n } as ContextModuleConfig;\n\n const signedDescriptorHex = stringToHex(\"mock-descriptor\");\n const responseData = {\n tokenAccount: \"token-account\",\n owner: \"owner-address\",\n contract: \"contract-address\",\n signedDescriptor: signedDescriptorHex,\n };\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n it(\"should fetch address metadata via tokenAddress\", async () => {\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({ data: responseData });\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result.isRight()).toBe(true);\n expect(result.extract()).toEqual({\n descriptor: hexaStringToBuffer(signedDescriptorHex),\n tokenAccount: \"token-account\",\n owner: \"owner-address\",\n contract: \"contract-address\",\n });\n });\n\n it(\"should compute address when tokenAddress is not provided\", async () => {\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: undefined,\n challenge: \"random\",\n createATA: {\n address: \"some-address\",\n mintAddress: \"some-mint\",\n },\n };\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({ data: responseData });\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result.isRight()).toBe(true);\n expect((result.extract() as any).tokenAccount).toBe(\"token-account\");\n });\n\n it(\"should return an error if both tokenAddress and createATA are missing or invalid\", async () => {\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: undefined,\n challenge: \"random\",\n createATA: undefined,\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: either tokenAddress or valid createATA must be provided\",\n ),\n ),\n );\n });\n\n it(\"should return an error if challenge is missing\", async () => {\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: undefined,\n createATA: undefined,\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: challenge is required\",\n ),\n ),\n );\n });\n\n it(\"should return an error if the descriptor is not valid base64\", async () => {\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({\n data: { ...responseData, signedDescriptor: \"!!!not-valid-base64!!!\" },\n });\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid base64 descriptor received\",\n ),\n ),\n );\n });\n\n it(\"should return an error if the metadata request fails\", async () => {\n vi.spyOn(axios, \"request\").mockRejectedValueOnce(\n new Error(\"Network error\"),\n );\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to fetch address metadata\",\n ),\n ),\n );\n });\n\n it(\"should return an error if axios request return wrong shape for fetchAddressMetadata\", async () => {\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({\n data: { wrong: \"field\" },\n });\n\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid fetchAddressMetadata response shape\",\n ),\n ),\n );\n });\n\n it(\"should return an error if axios request return wrong shape for computeAddressMetadata\", async () => {\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({\n data: { wrong: \"field\" },\n });\n\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: undefined,\n challenge: \"random\",\n createATA: {\n address: \"some-address\",\n mintAddress: \"some-mint\",\n },\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid computeAddressMetadata response shape\",\n ),\n ),\n );\n });\n\n it(\"should throw if originToken is missing\", () => {\n expect(() => {\n new HttpSolanaOwnerInfoDataSource({\n ...config,\n originToken: undefined,\n } as any);\n }).toThrow(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: origin token is required\",\n );\n });\n\n it(\"should call axios with correct headers\", async () => {\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n const spy = vi\n .spyOn(axios, \"request\")\n .mockResolvedValueOnce({ data: responseData });\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n await dataSource.getOwnerInfo(context);\n\n expect(spy).toHaveBeenCalledWith(\n expect.objectContaining({\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n \"X-Ledger-Client-Origin\": config.originToken,\n },\n }),\n );\n });\n});\n"],
5
- "mappings": "AAEA,OACE,iBAAAA,EACA,sBAAAC,MACK,kCACP,OAAOC,MAAW,QAClB,OAAS,QAAAC,MAAY,YAGrB,OAAS,gCAAAC,MAAoC,gCAC7C,OAAS,iCAAAC,MAAqC,8CAE9C,OAAOC,MAAa,qBAEpB,GAAG,KAAK,OAAO,EAEf,SAASC,EAAYC,EAAqB,CAExC,MAAMC,EADU,IAAI,YAAY,EACV,OAAOD,CAAG,EAChC,OAAO,MAAM,KAAKC,CAAK,EACpB,IAAKC,GAASA,EAAK,SAAS,EAAE,EAAE,SAAS,EAAG,GAAG,CAAC,EAChD,KAAK,EAAE,CACZ,CAEA,SAAS,gCAAiC,IAAM,CAC9C,MAAMC,EAAS,CACb,gBAAiB,CAAE,IAAK,sBAAuB,EAC/C,YAAa,mBACf,EAEMC,EAAsBL,EAAY,iBAAiB,EACnDM,EAAe,CACnB,aAAc,gBACd,MAAO,gBACP,SAAU,mBACV,iBAAkBD,CACpB,EAEA,WAAW,IAAM,CACf,GAAG,cAAc,CACnB,CAAC,EAED,GAAG,iDAAkD,SAAY,CAC/D,MAAME,EAAoC,CACxC,cAAed,EAAc,KAC7B,aAAc,aACd,UAAW,SACX,UAAW,MACb,EACA,GAAG,MAAME,EAAO,SAAS,EAAE,sBAAsB,CAAE,KAAMW,CAAa,CAAC,EAGvE,MAAME,EAAS,MADI,IAAIV,EAA8BM,CAAM,EAC3B,aAAaG,CAAO,EAEpD,OAAOC,EAAO,QAAQ,CAAC,EAAE,KAAK,EAAI,EAClC,OAAOA,EAAO,QAAQ,CAAC,EAAE,QAAQ,CAC/B,WAAYd,EAAmBW,CAAmB,EAClD,aAAc,gBACd,MAAO,gBACP,SAAU,kBACZ,CAAC,CACH,CAAC,EAED,GAAG,2DAA4D,SA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sBAAsB,CAAE,KAAMW,CAAa,CAAC,EAG/C,MADmB,IAAIR,EAA8BM,CAAM,EAC1C,aAAaG,CAAO,EAErC,OAAOE,CAAG,EAAE,qBACV,OAAO,iBAAiB,CACtB,QAAS,CACP,CAACZ,CAA4B,EAAG,kBAAkBE,EAAQ,OAAO,GACjE,yBAA0BK,EAAO,WACnC,CACF,CAAC,CACH,CACF,CAAC,CACH,CAAC",
4
+ "sourcesContent": ["/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n DeviceModelId,\n hexaStringToBuffer,\n} from \"@ledgerhq/device-management-kit\";\nimport axios from \"axios\";\nimport { Left } from \"purify-ts\";\n\nimport type { ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { LEDGER_CLIENT_VERSION_HEADER } from \"@/shared/constant/HttpHeaders\";\nimport { HttpSolanaOwnerInfoDataSource } from \"@/solana/data/HttpSolanaOwnerInfoDataSource\";\nimport type { SolanaTransactionContext } from \"@/solana/domain/solanaContextTypes\";\nimport PACKAGE from \"@root/package.json\";\n\nvi.mock(\"axios\");\n\nfunction stringToHex(str: string): string {\n const encoder = new TextEncoder();\n const bytes = encoder.encode(str); // Uint8Array\n return Array.from(bytes)\n .map((byte) => byte.toString(16).padStart(2, \"0\"))\n .join(\"\");\n}\n\ndescribe(\"HttpSolanaOwnerInfoDataSource\", () => {\n const config = {\n metadataServiceDomain: { url: \"https://some.doma.in\" },\n originToken: \"mock-origin-token\",\n } as ContextModuleConfig;\n\n const signedDescriptorHex = stringToHex(\"mock-descriptor\");\n const responseData = {\n tokenAccount: \"token-account\",\n owner: \"owner-address\",\n contract: \"contract-address\",\n signedDescriptor: signedDescriptorHex,\n };\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n it(\"should fetch address metadata via tokenAddress\", async () => {\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({ data: responseData });\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result.isRight()).toBe(true);\n expect(result.extract()).toEqual({\n descriptor: hexaStringToBuffer(signedDescriptorHex),\n tokenAccount: \"token-account\",\n owner: \"owner-address\",\n contract: \"contract-address\",\n });\n });\n\n it(\"should compute address when tokenAddress is not provided\", async () => {\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: undefined,\n challenge: \"random\",\n createATA: {\n address: \"some-address\",\n mintAddress: \"some-mint\",\n },\n };\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({ data: responseData });\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result.isRight()).toBe(true);\n expect((result.extract() as any).tokenAccount).toBe(\"token-account\");\n });\n\n it(\"should return an error if both tokenAddress and createATA are missing or invalid\", async () => {\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: undefined,\n challenge: \"random\",\n createATA: undefined,\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: either tokenAddress or valid createATA must be provided\",\n ),\n ),\n );\n });\n\n it(\"should return an error if challenge is missing\", async () => {\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: undefined,\n createATA: undefined,\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: challenge is required\",\n ),\n ),\n );\n });\n\n it(\"should return an error if the descriptor is not valid base64\", async () => {\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({\n data: { ...responseData, signedDescriptor: \"!!!not-valid-base64!!!\" },\n });\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid base64 descriptor received\",\n ),\n ),\n );\n });\n\n it(\"should return an error if the metadata request fails\", async () => {\n vi.spyOn(axios, \"request\").mockRejectedValueOnce(\n new Error(\"Network error\"),\n );\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to fetch address metadata\",\n ),\n ),\n );\n });\n\n it(\"should return an error if axios request return wrong shape for fetchAddressMetadata\", async () => {\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({\n data: { wrong: \"field\" },\n });\n\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid fetchAddressMetadata response shape\",\n ),\n ),\n );\n });\n\n it(\"should return an error if axios request return wrong shape for computeAddressMetadata\", async () => {\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({\n data: { wrong: \"field\" },\n });\n\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: undefined,\n challenge: \"random\",\n createATA: {\n address: \"some-address\",\n mintAddress: \"some-mint\",\n },\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid computeAddressMetadata response shape\",\n ),\n ),\n );\n });\n\n it(\"should throw if originToken is missing\", () => {\n expect(() => {\n new HttpSolanaOwnerInfoDataSource({\n ...config,\n originToken: undefined,\n } as any);\n }).toThrow(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: origin token is required\",\n );\n });\n\n it(\"should call axios with correct headers\", async () => {\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n const spy = vi\n .spyOn(axios, \"request\")\n .mockResolvedValueOnce({ data: responseData });\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n await dataSource.getOwnerInfo(context);\n\n expect(spy).toHaveBeenCalledWith(\n expect.objectContaining({\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n \"X-Ledger-Client-Origin\": config.originToken,\n },\n }),\n );\n });\n});\n"],
5
+ "mappings": "AAEA,OACE,iBAAAA,EACA,sBAAAC,MACK,kCACP,OAAOC,MAAW,QAClB,OAAS,QAAAC,MAAY,YAGrB,OAAS,gCAAAC,MAAoC,gCAC7C,OAAS,iCAAAC,MAAqC,8CAE9C,OAAOC,MAAa,qBAEpB,GAAG,KAAK,OAAO,EAEf,SAASC,EAAYC,EAAqB,CAExC,MAAMC,EADU,IAAI,YAAY,EACV,OAAOD,CAAG,EAChC,OAAO,MAAM,KAAKC,CAAK,EACpB,IAAKC,GAASA,EAAK,SAAS,EAAE,EAAE,SAAS,EAAG,GAAG,CAAC,EAChD,KAAK,EAAE,CACZ,CAEA,SAAS,gCAAiC,IAAM,CAC9C,MAAMC,EAAS,CACb,sBAAuB,CAAE,IAAK,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F,SAAY,CACtG,GAAG,MAAMD,EAAO,SAAS,EAAE,sBAAsB,CAC/C,KAAM,CAAE,MAAO,OAAQ,CACzB,CAAC,EAED,MAAMY,EAAoC,CACxC,cAAed,EAAc,KAC7B,aAAc,OACd,UAAW,SACX,UAAW,CACT,QAAS,eACT,YAAa,WACf,CACF,EAGMe,EAAS,MADI,IAAIV,EAA8BM,CAAM,EAC3B,aAAaG,CAAO,EAEpD,OAAOC,CAAM,EAAE,QACbZ,EACE,IAAI,MACF,gGACF,CACF,CACF,CACF,CAAC,EAED,GAAG,yCAA0C,IAAM,CACjD,OAAO,IAAM,CACX,IAAIE,EAA8B,CAChC,GAAGM,EACH,YAAa,MACf,CAAQ,CACV,CAAC,EAAE,QACD,2EACF,CACF,CAAC,EAED,GAAG,yCAA0C,SAAY,CACvD,MAAMG,EAAoC,CACxC,cAAed,EAAc,KAC7B,aAAc,aACd,UAAW,SACX,UAAW,MACb,EACMgB,EAAM,GACT,MAAMd,EAAO,SAAS,EACtB,sBAAsB,CAAE,KAAMW,CAAa,CAAC,EAG/C,MADmB,IAAIR,EAA8BM,CAAM,EAC1C,aAAaG,CAAO,EAErC,OAAOE,CAAG,EAAE,qBACV,OAAO,iBAAiB,CACtB,QAAS,CACP,CAACZ,CAA4B,EAAG,kBAAkBE,EAAQ,OAAO,GACjE,yBAA0BK,EAAO,WACnC,CACF,CAAC,CACH,CACF,CAAC,CACH,CAAC",
6
6
  "names": ["DeviceModelId", "hexaStringToBuffer", "axios", "Left", "LEDGER_CLIENT_VERSION_HEADER", "HttpSolanaOwnerInfoDataSource", "PACKAGE", "stringToHex", "str", "bytes", "byte", "config", "signedDescriptorHex", "responseData", "context", "result", "spy"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var P=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var l=(a,e,o,r)=>{for(var t=r>1?void 0:r?f(e,o):e,i=a.length-1,d;i>=0;i--)(d=a[i])&&(t=(r?d(e,o,t):d(t))||t);return r&&t&&P(e,o,t),t},m=(a,e)=>(o,r)=>e(o,r,a);import p from"axios";import{inject as D,injectable as u}from"inversify";import{Left as n,Right as y}from"purify-ts";import{configTypes as C}from"../../config/di/configTypes";import{LEDGER_CLIENT_VERSION_HEADER as x,LEDGER_ORIGIN_TOKEN_HEADER as g}from"../../shared/constant/HttpHeaders";import c from"../../../package.json";let s=class{constructor(e){this.config=e}async getProxyDelegateCall({proxyAddress:e,calldata:o,chainId:r}){let t;try{t=(await p.request({method:"POST",url:`${this.config.metadataService.url}/ethereum/${r}/contract/proxy/delegate`,headers:{[x]:`context-module/${c.version}`,[g]:this.config.originToken},data:{proxy:e,data:o}})).data}catch{return n(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy"))}return t?this.isProxyDelegateCallDto(t)?y(t):n(new Error(`[ContextModule] HttpProxyDataSource: Invalid proxy delegate call response format for proxy ${e} on chain ${r}`)):n(new Error(`[ContextModule] HttpProxyDataSource: No data received for proxy ${e} on chain ${r}`))}async getProxyImplementationAddress({proxyAddress:e,chainId:o}){let r;try{r=(await p.request({method:"GET",url:`${this.config.metadataService.url}/ethereum/${o}/contract/proxy/${e}`,headers:{[x]:`context-module/${c.version}`,[g]:this.config.originToken}})).data}catch{return n(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch implementation address"))}return r?this.isProxyImplementationAddressDto(r)?y({implementationAddress:r.implementationAddress}):n(new Error(`[ContextModule] HttpProxyDataSource: Invalid proxy implementation address response format for proxy ${e} on chain ${o}`)):n(new Error(`[ContextModule] HttpProxyDataSource: No data received for proxy ${e} on chain ${o}`))}isProxyDelegateCallDto(e){return typeof e=="object"&&e!==null&&"delegateAddresses"in e&&"signedDescriptor"in e&&Array.isArray(e.delegateAddresses)&&e.delegateAddresses.every(o=>typeof o=="string")&&typeof e.signedDescriptor=="string"}isProxyImplementationAddressDto(e){return typeof e=="object"&&e!==null&&"proxyAddress"in e&&"implementationAddress"in e&&"standard"in e&&typeof e.proxyAddress=="string"&&typeof e.implementationAddress=="string"&&typeof e.standard=="string"&&e.standard.length>0}};s=l([u(),m(0,D(C.Config))],s);export{s as HttpProxyDataSource};
1
+ var P=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var l=(i,e,t,r)=>{for(var o=r>1?void 0:r?f(e,t):e,n=i.length-1,s;n>=0;n--)(s=i[n])&&(o=(r?s(e,t,o):s(o))||o);return r&&o&&P(e,t,o),o},m=(i,e)=>(t,r)=>e(t,r,i);import p from"axios";import{inject as D,injectable as u}from"inversify";import{Left as a,Right as y}from"purify-ts";import{configTypes as E}from"../../config/di/configTypes";import{LEDGER_CLIENT_VERSION_HEADER as x,LEDGER_ORIGIN_TOKEN_HEADER as c}from"../../shared/constant/HttpHeaders";import g from"../../../package.json";let d=class{constructor(e){this.config=e}async getProxyDelegateCall({proxyAddress:e,calldata:t,chainId:r,challenge:o}){let n;try{n=(await p.request({method:"POST",url:`${this.config.metadataServiceDomain.url}/v2/ethereum/${r}/contract/proxy/delegate`,headers:{[x]:`context-module/${g.version}`,[c]:this.config.originToken},data:{proxy:e,data:t,challenge:o}})).data}catch{return a(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy"))}return n?this.isProxyDelegateCallDto(n)?y({delegateAddresses:n.addresses,signedDescriptor:n.signedDescriptor}):a(new Error(`[ContextModule] HttpProxyDataSource: Invalid proxy delegate call response format for proxy ${e} on chain ${r}`)):a(new Error(`[ContextModule] HttpProxyDataSource: No data received for proxy ${e} on chain ${r}`))}async getProxyImplementationAddress({proxyAddress:e,chainId:t}){let r;try{r=(await p.request({method:"GET",url:`${this.config.metadataServiceDomain.url}/v2/ethereum/${t}/contract/proxy/${e}`,headers:{[x]:`context-module/${g.version}`,[c]:this.config.originToken}})).data}catch{return a(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch implementation address"))}return r?this.isProxyImplementationAddressDto(r)?y({implementationAddress:r.implementationAddress}):a(new Error(`[ContextModule] HttpProxyDataSource: Invalid proxy implementation address response format for proxy ${e} on chain ${t}`)):a(new Error(`[ContextModule] HttpProxyDataSource: No data received for proxy ${e} on chain ${t}`))}isProxyDelegateCallDto(e){return typeof e=="object"&&e!==null&&"addresses"in e&&"signedDescriptor"in e&&Array.isArray(e.addresses)&&e.addresses.every(t=>typeof t=="string")&&typeof e.signedDescriptor=="string"}isProxyImplementationAddressDto(e){return typeof e=="object"&&e!==null&&"proxyAddress"in e&&"implementationAddress"in e&&"standard"in e&&typeof e.proxyAddress=="string"&&typeof e.implementationAddress=="string"&&typeof e.standard=="string"&&e.standard.length>0}};d=l([u(),m(0,D(E.Config))],d);export{d as HttpProxyDataSource};
2
2
  //# sourceMappingURL=HttpProxyDataSource.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/transaction/data/HttpProxyDataSource.ts"],
4
- "sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport { type ProxyDelegateCall } from \"@/transaction/model/ProxyDelegateCall\";\nimport { type ProxyImplementationAddress } from \"@/transaction/model/ProxyImplementationAddress\";\nimport PACKAGE from \"@root/package.json\";\n\nimport { type ProxyDelegateCallDto } from \"./dto/ProxyDelegateCallDto\";\nimport { type ProxyImplementationAddressDto } from \"./dto/ProxyImplementationAddressDto\";\n\nexport type GetProxyDelegateCallParam = {\n proxyAddress: string;\n calldata: string;\n chainId: number;\n};\n\nexport type GetProxyImplementationAddressParam = {\n proxyAddress: string;\n chainId: number;\n};\n\nexport interface ProxyDataSource {\n getProxyDelegateCall(\n params: GetProxyDelegateCallParam,\n ): Promise<Either<Error, ProxyDelegateCall>>;\n getProxyImplementationAddress(\n params: GetProxyImplementationAddressParam,\n ): Promise<Either<Error, ProxyImplementationAddress>>;\n}\n\n@injectable()\nexport class HttpProxyDataSource implements ProxyDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n ) {}\n\n public async getProxyDelegateCall({\n proxyAddress,\n calldata,\n chainId,\n }: GetProxyDelegateCallParam): Promise<Either<Error, ProxyDelegateCall>> {\n let dto: ProxyDelegateCallDto | undefined;\n try {\n const response = await axios.request<ProxyDelegateCallDto>({\n method: \"POST\",\n url: `${this.config.metadataService.url}/ethereum/${chainId}/contract/proxy/delegate`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n data: {\n proxy: proxyAddress,\n data: calldata,\n },\n });\n dto = response.data;\n } catch (_error) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy`,\n ),\n );\n }\n\n if (!dto) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: No data received for proxy ${proxyAddress} on chain ${chainId}`,\n ),\n );\n }\n\n if (!this.isProxyDelegateCallDto(dto)) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: Invalid proxy delegate call response format for proxy ${proxyAddress} on chain ${chainId}`,\n ),\n );\n }\n\n return Right(dto as ProxyDelegateCall);\n }\n\n public async getProxyImplementationAddress({\n proxyAddress,\n chainId,\n }: GetProxyImplementationAddressParam): Promise<\n Either<Error, ProxyImplementationAddress>\n > {\n let dto: ProxyImplementationAddressDto | undefined;\n try {\n const response = await axios.request<ProxyImplementationAddressDto>({\n method: \"GET\",\n url: `${this.config.metadataService.url}/ethereum/${chainId}/contract/proxy/${proxyAddress}`,\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] HttpProxyDataSource: Failed to fetch implementation address`,\n ),\n );\n }\n\n if (!dto) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: No data received for proxy ${proxyAddress} on chain ${chainId}`,\n ),\n );\n }\n\n if (!this.isProxyImplementationAddressDto(dto)) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: Invalid proxy implementation address response format for proxy ${proxyAddress} on chain ${chainId}`,\n ),\n );\n }\n\n return Right({ implementationAddress: dto.implementationAddress });\n }\n\n /**\n * Type guard to validate ProxyDelegateCallDto\n */\n private isProxyDelegateCallDto(\n value: unknown,\n ): value is ProxyDelegateCallDto {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"delegateAddresses\" in value &&\n \"signedDescriptor\" in value &&\n Array.isArray(value.delegateAddresses) &&\n value.delegateAddresses.every((address) => typeof address === \"string\") &&\n typeof value.signedDescriptor === \"string\"\n );\n }\n\n /**\n * Type guard to validate ProxyImplementationAddressDto\n */\n private isProxyImplementationAddressDto(\n value: unknown,\n ): value is ProxyImplementationAddressDto {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"proxyAddress\" in value &&\n \"implementationAddress\" in value &&\n \"standard\" in value &&\n typeof value.proxyAddress === \"string\" &&\n typeof value.implementationAddress === \"string\" &&\n typeof value.standard === \"string\" &&\n value.standard.length > 0\n );\n }\n}\n"],
5
- "mappings": "iOAAA,OAAOA,MAAW,QAClB,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YACnC,OAAiB,QAAAC,EAAM,SAAAC,MAAa,YAEpC,OAAS,eAAAC,MAAmB,0BAE5B,OACE,gCAAAC,EACA,8BAAAC,MACK,gCAGP,OAAOC,MAAa,qBA0Bb,IAAMC,EAAN,KAAqD,CAC1D,YAC+CC,EAC7C,CAD6C,YAAAA,CAC5C,CAEH,MAAa,qBAAqB,CAChC,aAAAC,EACA,SAAAC,EACA,QAAAC,CACF,EAAyE,CACvE,IAAIC,EACJ,GAAI,CAaFA,GAZiB,MAAMC,EAAM,QAA8B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,MAAOC,GAAY,OAAOA,GAAY,QAAQ,GACtE,OAAOD,EAAM,kBAAqB,QAEtC,CAKQ,gCACNA,EACwC,CACxC,OACE,OAAOA,GAAU,UACjBA,IAAU,MACV,iBAAkBA,GAClB,0BAA2BA,GAC3B,aAAcA,GACd,OAAOA,EAAM,cAAiB,UAC9B,OAAOA,EAAM,uBAA0B,UACvC,OAAOA,EAAM,UAAa,UAC1BA,EAAM,SAAS,OAAS,CAE5B,CACF,EAnIaZ,EAANc,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAY,MAAM,IAFjBlB",
6
- "names": ["axios", "inject", "injectable", "Left", "Right", "configTypes", "LEDGER_CLIENT_VERSION_HEADER", "LEDGER_ORIGIN_TOKEN_HEADER", "PACKAGE", "HttpProxyDataSource", "config", "proxyAddress", "calldata", "chainId", "dto", "axios", "LEDGER_CLIENT_VERSION_HEADER", "PACKAGE", "LEDGER_ORIGIN_TOKEN_HEADER", "Left", "Right", "value", "address", "__decorateClass", "injectable", "__decorateParam", "inject", "configTypes"]
4
+ "sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport { type ProxyDelegateCall } from \"@/transaction/model/ProxyDelegateCall\";\nimport { type ProxyImplementationAddress } from \"@/transaction/model/ProxyImplementationAddress\";\nimport PACKAGE from \"@root/package.json\";\n\nimport { type ProxyDelegateCallDto } from \"./dto/ProxyDelegateCallDto\";\nimport { type ProxyImplementationAddressDto } from \"./dto/ProxyImplementationAddressDto\";\n\nexport type GetProxyDelegateCallParam = {\n proxyAddress: string;\n calldata: string;\n chainId: number;\n challenge: string;\n};\n\nexport type GetProxyImplementationAddressParam = {\n proxyAddress: string;\n chainId: number;\n};\n\nexport interface ProxyDataSource {\n getProxyDelegateCall(\n params: GetProxyDelegateCallParam,\n ): Promise<Either<Error, ProxyDelegateCall>>;\n getProxyImplementationAddress(\n params: GetProxyImplementationAddressParam,\n ): Promise<Either<Error, ProxyImplementationAddress>>;\n}\n\n@injectable()\nexport class HttpProxyDataSource implements ProxyDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n ) {}\n\n public async getProxyDelegateCall({\n proxyAddress,\n calldata,\n chainId,\n challenge,\n }: GetProxyDelegateCallParam): Promise<Either<Error, ProxyDelegateCall>> {\n let dto: ProxyDelegateCallDto | undefined;\n try {\n const response = await axios.request<ProxyDelegateCallDto>({\n method: \"POST\",\n url: `${this.config.metadataServiceDomain.url}/v2/ethereum/${chainId}/contract/proxy/delegate`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n data: {\n proxy: proxyAddress,\n data: calldata,\n challenge,\n },\n });\n dto = response.data;\n } catch (_error) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy`,\n ),\n );\n }\n\n if (!dto) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: No data received for proxy ${proxyAddress} on chain ${chainId}`,\n ),\n );\n }\n\n if (!this.isProxyDelegateCallDto(dto)) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: Invalid proxy delegate call response format for proxy ${proxyAddress} on chain ${chainId}`,\n ),\n );\n }\n\n return Right({\n delegateAddresses: dto.addresses,\n signedDescriptor: dto.signedDescriptor,\n });\n }\n\n public async getProxyImplementationAddress({\n proxyAddress,\n chainId,\n }: GetProxyImplementationAddressParam): Promise<\n Either<Error, ProxyImplementationAddress>\n > {\n let dto: ProxyImplementationAddressDto | undefined;\n try {\n const response = await axios.request<ProxyImplementationAddressDto>({\n method: \"GET\",\n url: `${this.config.metadataServiceDomain.url}/v2/ethereum/${chainId}/contract/proxy/${proxyAddress}`,\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] HttpProxyDataSource: Failed to fetch implementation address`,\n ),\n );\n }\n\n if (!dto) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: No data received for proxy ${proxyAddress} on chain ${chainId}`,\n ),\n );\n }\n\n if (!this.isProxyImplementationAddressDto(dto)) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: Invalid proxy implementation address response format for proxy ${proxyAddress} on chain ${chainId}`,\n ),\n );\n }\n\n return Right({ implementationAddress: dto.implementationAddress });\n }\n\n /**\n * Type guard to validate ProxyDelegateCallDto\n */\n private isProxyDelegateCallDto(\n value: unknown,\n ): value is ProxyDelegateCallDto {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"addresses\" in value &&\n \"signedDescriptor\" in value &&\n Array.isArray(value.addresses) &&\n value.addresses.every((address) => typeof address === \"string\") &&\n typeof value.signedDescriptor === \"string\"\n );\n }\n\n /**\n * Type guard to validate ProxyImplementationAddressDto\n */\n private isProxyImplementationAddressDto(\n value: unknown,\n ): value is ProxyImplementationAddressDto {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"proxyAddress\" in value &&\n \"implementationAddress\" in value &&\n \"standard\" in value &&\n typeof value.proxyAddress === \"string\" &&\n typeof value.implementationAddress === \"string\" &&\n typeof value.standard === \"string\" &&\n value.standard.length > 0\n );\n }\n}\n"],
5
+ "mappings": "iOAAA,OAAOA,MAAW,QAClB,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YACnC,OAAiB,QAAAC,EAAM,SAAAC,MAAa,YAEpC,OAAS,eAAAC,MAAmB,0BAE5B,OACE,gCAAAC,EACA,8BAAAC,MACK,gCAGP,OAAO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CAAC,EAPxDK,EACL,IAAI,MACF,uGAAuGT,CAAY,aAAaE,CAAO,EACzI,CACF,EAZOO,EACL,IAAI,MACF,mEAAmET,CAAY,aAAaE,CAAO,EACrG,CACF,CAYJ,CAKQ,uBACNS,EAC+B,CAC/B,OACE,OAAOA,GAAU,UACjBA,IAAU,MACV,cAAeA,GACf,qBAAsBA,GACtB,MAAM,QAAQA,EAAM,SAAS,GAC7BA,EAAM,UAAU,MAAOC,GAAY,OAAOA,GAAY,QAAQ,GAC9D,OAAOD,EAAM,kBAAqB,QAEtC,CAKQ,gCACNA,EACwC,CACxC,OACE,OAAOA,GAAU,UACjBA,IAAU,MACV,iBAAkBA,GAClB,0BAA2BA,GAC3B,aAAcA,GACd,OAAOA,EAAM,cAAiB,UAC9B,OAAOA,EAAM,uBAA0B,UACvC,OAAOA,EAAM,UAAa,UAC1BA,EAAM,SAAS,OAAS,CAE5B,CACF,EAxIab,EAANe,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAY,MAAM,IAFjBnB",
6
+ "names": ["axios", "inject", "injectable", "Left", "Right", "configTypes", "LEDGER_CLIENT_VERSION_HEADER", "LEDGER_ORIGIN_TOKEN_HEADER", "PACKAGE", "HttpProxyDataSource", "config", "proxyAddress", "calldata", "chainId", "challenge", "dto", "axios", "LEDGER_CLIENT_VERSION_HEADER", "PACKAGE", "LEDGER_ORIGIN_TOKEN_HEADER", "Left", "Right", "value", "address", "__decorateClass", "injectable", "__decorateParam", "inject", "configTypes"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import a from"axios";import{Left as n,Right as l}from"purify-ts";import{LEDGER_CLIENT_VERSION_HEADER as p,LEDGER_ORIGIN_TOKEN_HEADER as m}from"../../shared/constant/HttpHeaders";import x from"../../../package.json";import{HttpProxyDataSource as y}from"./HttpProxyDataSource";vi.mock("axios");describe("HttpProxyDataSource",()=>{const c={web3checks:{url:"web3checksUrl"},originToken:"originToken"};let t;const s={proxyAddress:"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0",calldata:"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000",chainId:1},r={proxyAddress:"0xee6a57ec80ea46401049e92587e52f5ec1c24785",chainId:1},d={delegateAddresses:["0xd9db270c1b5e3bd161e8c8503c55ceabee709552"],signedDescriptor:"0x1234567890abcdef"},u={implementationAddress:"0x91ae842a5ffd8d12023116943e72a606179294f3"},i={implementationAddress:"0x91ae842a5ffd8d12023116943e72a606179294f3",proxyAddress:"0xee6a57ec80ea46401049e92587e52f5ec1c24785",standard:"proxy"};beforeEach(()=>{vi.clearAllMocks(),t=new y({metadataService:{url:"https://nft.api.live.ledger.com/v2"},originToken:"originToken"})}),describe("getDelegateProxy",()=>{it("should call axios with the ledger client version header",async()=>{const e=`context-module/${x.version}`,o=vi.fn(()=>Promise.resolve({data:d}));vi.spyOn(a,"request").mockImplementation(o),await t.getProxyDelegateCall(s),expect(o).toHaveBeenCalledWith(expect.objectContaining({headers:{[p]:e,[m]:c.originToken}}))}),it("should return the delegate proxy response on success",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:d});const e=await t.getProxyDelegateCall(s);expect(e).toEqual(l(d))}),it("should return an error when axios throws an error",async()=>{vi.spyOn(a,"request").mockRejectedValue(new Error("fail"));const e=await t.getProxyDelegateCall(s);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy")))}),it("should return an error if response shape is invalid",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:{foo:"bar"}});const e=await t.getProxyDelegateCall(s);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: Invalid proxy delegate call response format for proxy 0x72CBdEaAdddD14Ec95b92995933CeC69566650f0 on chain 1")))}),it("should use the provided chainId in the URL",async()=>{const e=vi.fn(()=>Promise.resolve({data:d}));vi.spyOn(a,"request").mockImplementation(e);const o={proxyAddress:"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0",calldata:"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000",chainId:137};await t.getProxyDelegateCall(o),expect(e).toHaveBeenCalledWith(expect.objectContaining({method:"POST",url:"https://nft.api.live.ledger.com/v2/ethereum/137/contract/proxy/delegate"}))}),it("should return an error if no dto is returned from the api",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:void 0});const e=await t.getProxyDelegateCall(s);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: No data received for proxy 0x72CBdEaAdddD14Ec95b92995933CeC69566650f0 on chain 1")))})}),describe("getImplementAddress",()=>{it("should call axios with the ledger client version header",async()=>{const e=`context-module/${x.version}`,o=vi.fn(()=>Promise.resolve({data:i}));vi.spyOn(a,"request").mockImplementation(o),await t.getProxyImplementationAddress(r),expect(o).toHaveBeenCalledWith(expect.objectContaining({headers:{[p]:e,[m]:c.originToken}}))}),it("should make a GET request to the correct URL",async()=>{const e=vi.fn(()=>Promise.resolve({data:i}));vi.spyOn(a,"request").mockImplementation(e),await t.getProxyImplementationAddress(r),expect(e).toHaveBeenCalledWith(expect.objectContaining({method:"GET",url:"https://nft.api.live.ledger.com/v2/ethereum/1/contract/proxy/0xee6a57ec80ea46401049e92587e52f5ec1c24785"}))}),it("should use the provided chainId in the URL",async()=>{const e=vi.fn(()=>Promise.resolve({data:i}));vi.spyOn(a,"request").mockImplementation(e);const o={proxyAddress:"0xee6a57ec80ea46401049e92587e52f5ec1c24785",chainId:137};await t.getProxyImplementationAddress(o),expect(e).toHaveBeenCalledWith(expect.objectContaining({method:"GET",url:"https://nft.api.live.ledger.com/v2/ethereum/137/contract/proxy/0xee6a57ec80ea46401049e92587e52f5ec1c24785"}))}),it("should return the implementation address response on success",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:i});const e=await t.getProxyImplementationAddress(r);expect(e).toEqual(l(u))}),it("should return an error when axios throws an error",async()=>{vi.spyOn(a,"request").mockRejectedValue(new Error("network error"));const e=await t.getProxyImplementationAddress(r);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch implementation address")))}),it("should return an error if response shape is invalid",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:{invalid:"data"}});const e=await t.getProxyImplementationAddress(r);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: Invalid proxy implementation address response format for proxy 0xee6a57ec80ea46401049e92587e52f5ec1c24785 on chain 1")))}),it("should return an error if no dto is returned from the api",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:void 0});const e=await t.getProxyImplementationAddress(r);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: No data received for proxy 0xee6a57ec80ea46401049e92587e52f5ec1c24785 on chain 1")))})})});
1
+ import a from"axios";import{Left as n,Right as l}from"purify-ts";import{LEDGER_CLIENT_VERSION_HEADER as p,LEDGER_ORIGIN_TOKEN_HEADER as m}from"../../shared/constant/HttpHeaders";import x from"../../../package.json";import{HttpProxyDataSource as y}from"./HttpProxyDataSource";vi.mock("axios");describe("HttpProxyDataSource",()=>{const c={web3checks:{url:"web3checksUrl"},originToken:"originToken"};let t;const s={proxyAddress:"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0",calldata:"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000",chainId:1,challenge:"0x1234567890abcdef"},r={proxyAddress:"0xee6a57ec80ea46401049e92587e52f5ec1c24785",chainId:1},i={addresses:["0xd9db270c1b5e3bd161e8c8503c55ceabee709552"],signedDescriptor:"0x1234567890abcdef"},u={implementationAddress:"0x91ae842a5ffd8d12023116943e72a606179294f3"},d={implementationAddress:"0x91ae842a5ffd8d12023116943e72a606179294f3",proxyAddress:"0xee6a57ec80ea46401049e92587e52f5ec1c24785",standard:"proxy"};beforeEach(()=>{vi.clearAllMocks(),t=new y({metadataServiceDomain:{url:"https://nft.api.live.ledger.com"},originToken:"originToken"})}),describe("getDelegateProxy",()=>{it("should call axios with the ledger client version header",async()=>{const e=`context-module/${x.version}`,o=vi.fn(()=>Promise.resolve({data:i}));vi.spyOn(a,"request").mockImplementation(o),await t.getProxyDelegateCall(s),expect(o).toHaveBeenCalledWith(expect.objectContaining({headers:{[p]:e,[m]:c.originToken}}))}),it("should return the delegate proxy response on success",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:i});const e=await t.getProxyDelegateCall(s);expect(e).toEqual(l({delegateAddresses:["0xd9db270c1b5e3bd161e8c8503c55ceabee709552"],signedDescriptor:"0x1234567890abcdef"}))}),it("should return an error when axios throws an error",async()=>{vi.spyOn(a,"request").mockRejectedValue(new Error("fail"));const e=await t.getProxyDelegateCall(s);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy")))}),it("should return an error if response shape is invalid",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:{foo:"bar"}});const e=await t.getProxyDelegateCall(s);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: Invalid proxy delegate call response format for proxy 0x72CBdEaAdddD14Ec95b92995933CeC69566650f0 on chain 1")))}),it("should use the provided chainId in the URL",async()=>{const e=vi.fn(()=>Promise.resolve({data:i}));vi.spyOn(a,"request").mockImplementation(e);const o={proxyAddress:"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0",calldata:"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000",chainId:137,challenge:"0x1234567890abcdef"};await t.getProxyDelegateCall(o),expect(e).toHaveBeenCalledWith(expect.objectContaining({method:"POST",url:"https://nft.api.live.ledger.com/v2/ethereum/137/contract/proxy/delegate"}))}),it("should return an error if no dto is returned from the api",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:void 0});const e=await t.getProxyDelegateCall(s);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: No data received for proxy 0x72CBdEaAdddD14Ec95b92995933CeC69566650f0 on chain 1")))})}),describe("getImplementAddress",()=>{it("should call axios with the ledger client version header",async()=>{const e=`context-module/${x.version}`,o=vi.fn(()=>Promise.resolve({data:d}));vi.spyOn(a,"request").mockImplementation(o),await t.getProxyImplementationAddress(r),expect(o).toHaveBeenCalledWith(expect.objectContaining({headers:{[p]:e,[m]:c.originToken}}))}),it("should make a GET request to the correct URL",async()=>{const e=vi.fn(()=>Promise.resolve({data:d}));vi.spyOn(a,"request").mockImplementation(e),await t.getProxyImplementationAddress(r),expect(e).toHaveBeenCalledWith(expect.objectContaining({method:"GET",url:"https://nft.api.live.ledger.com/v2/ethereum/1/contract/proxy/0xee6a57ec80ea46401049e92587e52f5ec1c24785"}))}),it("should use the provided chainId in the URL",async()=>{const e=vi.fn(()=>Promise.resolve({data:d}));vi.spyOn(a,"request").mockImplementation(e);const o={proxyAddress:"0xee6a57ec80ea46401049e92587e52f5ec1c24785",chainId:137};await t.getProxyImplementationAddress(o),expect(e).toHaveBeenCalledWith(expect.objectContaining({method:"GET",url:"https://nft.api.live.ledger.com/v2/ethereum/137/contract/proxy/0xee6a57ec80ea46401049e92587e52f5ec1c24785"}))}),it("should return the implementation address response on success",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:d});const e=await t.getProxyImplementationAddress(r);expect(e).toEqual(l(u))}),it("should return an error when axios throws an error",async()=>{vi.spyOn(a,"request").mockRejectedValue(new Error("network error"));const e=await t.getProxyImplementationAddress(r);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch implementation address")))}),it("should return an error if response shape is invalid",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:{invalid:"data"}});const e=await t.getProxyImplementationAddress(r);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: Invalid proxy implementation address response format for proxy 0xee6a57ec80ea46401049e92587e52f5ec1c24785 on chain 1")))}),it("should return an error if no dto is returned from the api",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:void 0});const e=await t.getProxyImplementationAddress(r);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: No data received for proxy 0xee6a57ec80ea46401049e92587e52f5ec1c24785 on chain 1")))})})});
2
2
  //# sourceMappingURL=HttpProxyDataSource.test.js.map