@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,2 +1,2 @@
1
- "use strict";var C=Object.create;var c=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,M=Object.prototype.hasOwnProperty;var D=(o,e)=>{for(var t in e)c(o,t,{get:e[t],enumerable:!0})},w=(o,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of I(e))!M.call(o,r)&&r!==t&&c(o,r,{get:()=>e[r],enumerable:!(n=m(e,r))||n.enumerable});return o};var g=(o,e,t)=>(t=o!=null?C(x(o)):{},w(e||!o||!o.__esModule?c(t,"default",{value:o,enumerable:!0}):t,o)),k=o=>w(c({},"__esModule",{value:!0}),o),h=(o,e,t,n)=>{for(var r=n>1?void 0:n?m(e,t):e,s=o.length-1,i;s>=0;s--)(i=o[s])&&(r=(n?i(e,t,r):i(r))||r);return n&&r&&c(e,t,r),r},E=(o,e)=>(t,n)=>e(t,n,o);var L={};D(L,{HttpSolanaOwnerInfoDataSource:()=>d});module.exports=k(L);var A=require("@ledgerhq/device-management-kit"),f=g(require("axios")),u=require("inversify"),a=require("purify-ts"),O=require("../../config/di/configTypes"),l=require("../../shared/constant/HttpHeaders"),p=g(require("../../../package.json"));let d=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,t){return await f.default.request({method:"GET",url:`${this.config.metadataService.url}/solana/owner/${e}?challenge=${t}`,headers:{[l.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${p.default.version}`,[l.LEDGER_ORIGIN_TOKEN_HEADER]:this.config.originToken}}).then(n=>this.isSolanaSPLOwnerInfo(n.data)?(0,a.Right)(n.data):(0,a.Left)(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid fetchAddressMetadata response shape"))).catch(()=>(0,a.Left)(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to fetch address metadata")))}async computeAddressMetadata(e,t,n){return await f.default.request({method:"GET",url:`${this.config.metadataService.url}/solana/computed-token-account/${e}/${t}?challenge=${n}`,headers:{[l.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${p.default.version}`,"X-Ledger-Client-Origin":this.config.originToken}}).then(r=>this.isSolanaSPLOwnerInfo(r.data)?(0,a.Right)(r.data):(0,a.Left)(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid computeAddressMetadata response shape"))).catch(()=>(0,a.Left)(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to compute address metadata")))}async getOwnerInfo(e){const{tokenAddress:t,challenge:n,createATA:r}=e;if(!n)return(0,a.Left)(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: challenge is required"));let s;if(t)s=await this.fetchAddressMetadata(t,n);else if(r?.address&&r?.mintAddress)s=await this.computeAddressMetadata(r.address,r.mintAddress,n);else return(0,a.Left)(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: either tokenAddress or valid createATA must be provided"));return s.chain(i=>{const S=(0,A.hexaStringToBuffer)(i.signedDescriptor);return S?(0,a.Right)({descriptor:S,tokenAccount:i.tokenAccount,owner:i.owner,contract:i.contract}):(0,a.Left)(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid base64 descriptor received"))})}};d=h([(0,u.injectable)(),E(0,(0,u.inject)(O.configTypes.Config))],d);0&&(module.exports={HttpSolanaOwnerInfoDataSource});
1
+ "use strict";var C=Object.create;var c=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var M=(o,e)=>{for(var t in e)c(o,t,{get:e[t],enumerable:!0})},w=(o,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of I(e))!D.call(o,r)&&r!==t&&c(o,r,{get:()=>e[r],enumerable:!(n=S(e,r))||n.enumerable});return o};var g=(o,e,t)=>(t=o!=null?C(x(o)):{},w(e||!o||!o.__esModule?c(t,"default",{value:o,enumerable:!0}):t,o)),k=o=>w(c({},"__esModule",{value:!0}),o),h=(o,e,t,n)=>{for(var r=n>1?void 0:n?S(e,t):e,s=o.length-1,i;s>=0;s--)(i=o[s])&&(r=(n?i(e,t,r):i(r))||r);return n&&r&&c(e,t,r),r},E=(o,e)=>(t,n)=>e(t,n,o);var L={};M(L,{HttpSolanaOwnerInfoDataSource:()=>d});module.exports=k(L);var A=require("@ledgerhq/device-management-kit"),f=g(require("axios")),u=require("inversify"),a=require("purify-ts"),O=require("../../config/di/configTypes"),l=require("../../shared/constant/HttpHeaders"),m=g(require("../../../package.json"));let d=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,t){return await f.default.request({method:"GET",url:`${this.config.metadataServiceDomain.url}/v2/solana/owner/${e}?challenge=${t}`,headers:{[l.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${m.default.version}`,[l.LEDGER_ORIGIN_TOKEN_HEADER]:this.config.originToken}}).then(n=>this.isSolanaSPLOwnerInfo(n.data)?(0,a.Right)(n.data):(0,a.Left)(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid fetchAddressMetadata response shape"))).catch(()=>(0,a.Left)(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to fetch address metadata")))}async computeAddressMetadata(e,t,n){return await f.default.request({method:"GET",url:`${this.config.metadataServiceDomain.url}/v2/solana/computed-token-account/${e}/${t}?challenge=${n}`,headers:{[l.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${m.default.version}`,"X-Ledger-Client-Origin":this.config.originToken}}).then(r=>this.isSolanaSPLOwnerInfo(r.data)?(0,a.Right)(r.data):(0,a.Left)(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid computeAddressMetadata response shape"))).catch(()=>(0,a.Left)(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to compute address metadata")))}async getOwnerInfo(e){const{tokenAddress:t,challenge:n,createATA:r}=e;if(!n)return(0,a.Left)(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: challenge is required"));let s;if(t)s=await this.fetchAddressMetadata(t,n);else if(r?.address&&r?.mintAddress)s=await this.computeAddressMetadata(r.address,r.mintAddress,n);else return(0,a.Left)(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: either tokenAddress or valid createATA must be provided"));return s.chain(i=>{const p=(0,A.hexaStringToBuffer)(i.signedDescriptor);return p?(0,a.Right)({descriptor:p,tokenAccount:i.tokenAccount,owner:i.owner,contract:i.contract}):(0,a.Left)(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid base64 descriptor received"))})}};d=h([(0,u.injectable)(),E(0,(0,u.inject)(O.configTypes.Config))],d);0&&(module.exports={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": "qtBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAmC,2CACnCC,EAAkB,oBAClBC,EAAmC,qBACnCC,EAAoC,qBAEpCC,EAA4B,mCAE5BC,EAGO,yCAKPC,EAAoB,iCAQb,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,MAAM,EAAAC,QACV,QAA4B,CAC3B,OAAQ,MACR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B,EAChE,OAAKC,KAOE,SAAM,CACX,WAAAA,EACA,aAAcD,EAAU,aACxB,MAAOA,EAAU,MACjB,SAAUA,EAAU,QACtB,CAAC,KAXQ,QACL,IAAI,MACF,qFACF,CACF,CAQJ,CAAC,CACH,CACF,EA5Iab,EAANe,EAAA,IADN,cAAW,EAGPC,EAAA,eAAO,cAAY,MAAM,IAFjBhB",
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": "qtBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAmC,2CACnCC,EAAkB,oBAClBC,EAAmC,qBACnCC,EAAoC,qBAEpCC,EAA4B,mCAE5BC,EAGO,yCAKPC,EAAoB,iCAQb,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,MAAM,EAAAC,QACV,QAA4B,CAC3B,OAAQ,MACR,IAAK,GAAG,KAAK,OAAO,sBAAsB,GAAG,oBAAoBF,CAAY,cAAcC,CAAS,GACpG,QAAS,CACP,CAAC,8BAA4B,EAAG,kBAAkB,EAAAE,QAAQ,OAAO,GACjE,CAAC,4BAA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AC,CACH,CACF,EA5Iab,EAANe,EAAA,IADN,cAAW,EAGPC,EAAA,eAAO,cAAY,MAAM,IAFjBhB",
6
6
  "names": ["HttpSolanaOwnerInfoDataSource_exports", "__export", "HttpSolanaOwnerInfoDataSource", "__toCommonJS", "import_device_management_kit", "import_axios", "import_inversify", "import_purify_ts", "import_configTypes", "import_HttpHeaders", "import_package", "HttpSolanaOwnerInfoDataSource", "config", "data", "tokenAddress", "challenge", "axios", "PACKAGE", "res", "address", "mintAddress", "context", "createATA", "ownerInfoResult", "ownerInfo", "descriptor", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var p=Object.create;var l=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var A=(e,a,r,t)=>{if(a&&typeof a=="object"||typeof a=="function")for(let n of x(a))!S.call(e,n)&&n!==r&&l(e,n,{get:()=>a[n],enumerable:!(t=w(a,n))||t.enumerable});return e};var u=(e,a,r)=>(r=e!=null?p(g(e)):{},A(a||!e||!e.__esModule?l(r,"default",{value:e,enumerable:!0}):r,e));var s=require("@ledgerhq/device-management-kit"),c=u(require("axios")),i=require("purify-ts"),m=require("../../shared/constant/HttpHeaders"),d=require("../../solana/data/HttpSolanaOwnerInfoDataSource"),f=u(require("../../../package.json"));vi.mock("axios");function h(e){const r=new TextEncoder().encode(e);return Array.from(r).map(t=>t.toString(16).padStart(2,"0")).join("")}describe("HttpSolanaOwnerInfoDataSource",()=>{const e={metadataService:{url:"https://some.doma.in"},originToken:"mock-origin-token"},a=h("mock-descriptor"),r={tokenAccount:"token-account",owner:"owner-address",contract:"contract-address",signedDescriptor:a};beforeEach(()=>{vi.resetAllMocks()}),it("should fetch address metadata via tokenAddress",async()=>{const t={deviceModelId:s.DeviceModelId.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0};vi.spyOn(c.default,"request").mockResolvedValueOnce({data:r});const o=await new d.HttpSolanaOwnerInfoDataSource(e).getOwnerInfo(t);expect(o.isRight()).toBe(!0),expect(o.extract()).toEqual({descriptor:(0,s.hexaStringToBuffer)(a),tokenAccount:"token-account",owner:"owner-address",contract:"contract-address"})}),it("should compute address when tokenAddress is not provided",async()=>{const t={deviceModelId:s.DeviceModelId.FLEX,tokenAddress:void 0,challenge:"random",createATA:{address:"some-address",mintAddress:"some-mint"}};vi.spyOn(c.default,"request").mockResolvedValueOnce({data:r});const o=await new d.HttpSolanaOwnerInfoDataSource(e).getOwnerInfo(t);expect(o.isRight()).toBe(!0),expect(o.extract().tokenAccount).toBe("token-account")}),it("should return an error if both tokenAddress and createATA are missing or invalid",async()=>{const t={deviceModelId:s.DeviceModelId.FLEX,tokenAddress:void 0,challenge:"random",createATA:void 0},o=await new d.HttpSolanaOwnerInfoDataSource(e).getOwnerInfo(t);expect(o).toEqual((0,i.Left)(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: either tokenAddress or valid createATA must be provided")))}),it("should return an error if challenge is missing",async()=>{const t={deviceModelId:s.DeviceModelId.FLEX,tokenAddress:"some-token",challenge:void 0,createATA:void 0},o=await new d.HttpSolanaOwnerInfoDataSource(e).getOwnerInfo(t);expect(o).toEqual((0,i.Left)(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: challenge is required")))}),it("should return an error if the descriptor is not valid base64",async()=>{vi.spyOn(c.default,"request").mockResolvedValueOnce({data:{...r,signedDescriptor:"!!!not-valid-base64!!!"}});const t={deviceModelId:s.DeviceModelId.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},o=await new d.HttpSolanaOwnerInfoDataSource(e).getOwnerInfo(t);expect(o).toEqual((0,i.Left)(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid base64 descriptor received")))}),it("should return an error if the metadata request fails",async()=>{vi.spyOn(c.default,"request").mockRejectedValueOnce(new Error("Network error"));const t={deviceModelId:s.DeviceModelId.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},o=await new d.HttpSolanaOwnerInfoDataSource(e).getOwnerInfo(t);expect(o).toEqual((0,i.Left)(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(c.default,"request").mockResolvedValueOnce({data:{wrong:"field"}});const t={deviceModelId:s.DeviceModelId.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},o=await new d.HttpSolanaOwnerInfoDataSource(e).getOwnerInfo(t);expect(o).toEqual((0,i.Left)(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid fetchAddressMetadata response shape")))}),it("should return an error if axios request return wrong shape for computeAddressMetadata",async()=>{vi.spyOn(c.default,"request").mockResolvedValueOnce({data:{wrong:"field"}});const t={deviceModelId:s.DeviceModelId.FLEX,tokenAddress:void 0,challenge:"random",createATA:{address:"some-address",mintAddress:"some-mint"}},o=await new d.HttpSolanaOwnerInfoDataSource(e).getOwnerInfo(t);expect(o).toEqual((0,i.Left)(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid computeAddressMetadata response shape")))}),it("should throw if originToken is missing",()=>{expect(()=>{new d.HttpSolanaOwnerInfoDataSource({...e,originToken:void 0})}).toThrow("[ContextModule] - HttpSolanaOwnerInfoDataSource: origin token is required")}),it("should call axios with correct headers",async()=>{const t={deviceModelId:s.DeviceModelId.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},n=vi.spyOn(c.default,"request").mockResolvedValueOnce({data:r});await new d.HttpSolanaOwnerInfoDataSource(e).getOwnerInfo(t),expect(n).toHaveBeenCalledWith(expect.objectContaining({headers:{[m.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${f.default.version}`,"X-Ledger-Client-Origin":e.originToken}}))})});
1
+ "use strict";var p=Object.create;var l=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var A=(e,a,r,t)=>{if(a&&typeof a=="object"||typeof a=="function")for(let n of x(a))!S.call(e,n)&&n!==r&&l(e,n,{get:()=>a[n],enumerable:!(t=w(a,n))||t.enumerable});return e};var u=(e,a,r)=>(r=e!=null?p(g(e)):{},A(a||!e||!e.__esModule?l(r,"default",{value:e,enumerable:!0}):r,e));var s=require("@ledgerhq/device-management-kit"),c=u(require("axios")),i=require("purify-ts"),m=require("../../shared/constant/HttpHeaders"),d=require("../../solana/data/HttpSolanaOwnerInfoDataSource"),f=u(require("../../../package.json"));vi.mock("axios");function h(e){const r=new TextEncoder().encode(e);return Array.from(r).map(t=>t.toString(16).padStart(2,"0")).join("")}describe("HttpSolanaOwnerInfoDataSource",()=>{const e={metadataServiceDomain:{url:"https://some.doma.in"},originToken:"mock-origin-token"},a=h("mock-descriptor"),r={tokenAccount:"token-account",owner:"owner-address",contract:"contract-address",signedDescriptor:a};beforeEach(()=>{vi.resetAllMocks()}),it("should fetch address metadata via tokenAddress",async()=>{const t={deviceModelId:s.DeviceModelId.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0};vi.spyOn(c.default,"request").mockResolvedValueOnce({data:r});const o=await new d.HttpSolanaOwnerInfoDataSource(e).getOwnerInfo(t);expect(o.isRight()).toBe(!0),expect(o.extract()).toEqual({descriptor:(0,s.hexaStringToBuffer)(a),tokenAccount:"token-account",owner:"owner-address",contract:"contract-address"})}),it("should compute address when tokenAddress is not provided",async()=>{const t={deviceModelId:s.DeviceModelId.FLEX,tokenAddress:void 0,challenge:"random",createATA:{address:"some-address",mintAddress:"some-mint"}};vi.spyOn(c.default,"request").mockResolvedValueOnce({data:r});const o=await new d.HttpSolanaOwnerInfoDataSource(e).getOwnerInfo(t);expect(o.isRight()).toBe(!0),expect(o.extract().tokenAccount).toBe("token-account")}),it("should return an error if both tokenAddress and createATA are missing or invalid",async()=>{const t={deviceModelId:s.DeviceModelId.FLEX,tokenAddress:void 0,challenge:"random",createATA:void 0},o=await new d.HttpSolanaOwnerInfoDataSource(e).getOwnerInfo(t);expect(o).toEqual((0,i.Left)(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: either tokenAddress or valid createATA must be provided")))}),it("should return an error if challenge is missing",async()=>{const t={deviceModelId:s.DeviceModelId.FLEX,tokenAddress:"some-token",challenge:void 0,createATA:void 0},o=await new d.HttpSolanaOwnerInfoDataSource(e).getOwnerInfo(t);expect(o).toEqual((0,i.Left)(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: challenge is required")))}),it("should return an error if the descriptor is not valid base64",async()=>{vi.spyOn(c.default,"request").mockResolvedValueOnce({data:{...r,signedDescriptor:"!!!not-valid-base64!!!"}});const t={deviceModelId:s.DeviceModelId.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},o=await new d.HttpSolanaOwnerInfoDataSource(e).getOwnerInfo(t);expect(o).toEqual((0,i.Left)(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid base64 descriptor received")))}),it("should return an error if the metadata request fails",async()=>{vi.spyOn(c.default,"request").mockRejectedValueOnce(new Error("Network error"));const t={deviceModelId:s.DeviceModelId.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},o=await new d.HttpSolanaOwnerInfoDataSource(e).getOwnerInfo(t);expect(o).toEqual((0,i.Left)(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(c.default,"request").mockResolvedValueOnce({data:{wrong:"field"}});const t={deviceModelId:s.DeviceModelId.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},o=await new d.HttpSolanaOwnerInfoDataSource(e).getOwnerInfo(t);expect(o).toEqual((0,i.Left)(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid fetchAddressMetadata response shape")))}),it("should return an error if axios request return wrong shape for computeAddressMetadata",async()=>{vi.spyOn(c.default,"request").mockResolvedValueOnce({data:{wrong:"field"}});const t={deviceModelId:s.DeviceModelId.FLEX,tokenAddress:void 0,challenge:"random",createATA:{address:"some-address",mintAddress:"some-mint"}},o=await new d.HttpSolanaOwnerInfoDataSource(e).getOwnerInfo(t);expect(o).toEqual((0,i.Left)(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid computeAddressMetadata response shape")))}),it("should throw if originToken is missing",()=>{expect(()=>{new d.HttpSolanaOwnerInfoDataSource({...e,originToken:void 0})}).toThrow("[ContextModule] - HttpSolanaOwnerInfoDataSource: origin token is required")}),it("should call axios with correct headers",async()=>{const t={deviceModelId:s.DeviceModelId.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},n=vi.spyOn(c.default,"request").mockResolvedValueOnce({data:r});await new d.HttpSolanaOwnerInfoDataSource(e).getOwnerInfo(t),expect(n).toHaveBeenCalledWith(expect.objectContaining({headers:{[m.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${f.default.version}`,"X-Ledger-Client-Origin":e.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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EAAG,kBAAkB,EAAAC,QAAQ,OAAO,GACjE,yBAA0BP,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": "wdAEA,IAAAA,EAGO,2CACPC,EAAkB,oBAClBC,EAAqB,qBAGrBC,EAA6C,yCAC7CC,EAA8C,uDAE9CC,EAAoB,iCAEpB,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,sBAAuB,EACrD,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,C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AAa,WACf,CACF,EAGME,EAAS,MADI,IAAI,gCAA8BL,CAAM,EAC3B,aAAaG,CAAO,EAEpD,OAAOE,CAAM,EAAE,WACb,QACE,IAAI,MACF,gGACF,CACF,CACF,CACF,CAAC,EAED,GAAG,yCAA0C,IAAM,CACjD,OAAO,IAAM,CACX,IAAI,gCAA8B,CAChC,GAAGL,EACH,YAAa,MACf,CAAQ,CACV,CAAC,EAAE,QACD,2EACF,CACF,CAAC,EAED,GAAG,yCAA0C,SAAY,CACvD,MAAMG,EAAoC,CACxC,cAAe,gBAAc,KAC7B,aAAc,aACd,UAAW,SACX,UAAW,MACb,EACMG,EAAM,GACT,MAAM,EAAAF,QAAO,SAAS,EACtB,sBAAsB,CAAE,KAAMF,CAAa,CAAC,EAG/C,MADmB,IAAI,gCAA8BF,CAAM,EAC1C,aAAaG,CAAO,EAErC,OAAOG,CAAG,EAAE,qBACV,OAAO,iBAAiB,CACtB,QAAS,CACP,CAAC,8BAA4B,EAAG,kBAAkB,EAAAC,QAAQ,OAAO,GACjE,yBAA0BP,EAAO,WACnC,CACF,CAAC,CACH,CACF,CAAC,CACH,CAAC",
6
6
  "names": ["import_device_management_kit", "import_axios", "import_purify_ts", "import_HttpHeaders", "import_HttpSolanaOwnerInfoDataSource", "import_package", "stringToHex", "str", "bytes", "byte", "config", "signedDescriptorHex", "responseData", "context", "axios", "result", "spy", "PACKAGE"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var C=Object.create;var d=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var A=Object.getPrototypeOf,h=Object.prototype.hasOwnProperty;var I=(t,e)=>{for(var r in e)d(t,r,{get:e[r],enumerable:!0})},c=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of E(e))!h.call(t,o)&&o!==r&&d(t,o,{get:()=>e[o],enumerable:!(n=g(e,o))||n.enumerable});return t};var P=(t,e,r)=>(r=t!=null?C(A(t)):{},c(e||!t||!t.__esModule?d(r,"default",{value:t,enumerable:!0}):r,t)),$=t=>c(d({},"__esModule",{value:!0}),t),f=(t,e,r,n)=>{for(var o=n>1?void 0:n?g(e,r):e,s=t.length-1,p;s>=0;s--)(p=t[s])&&(o=(n?p(e,r,o):p(o))||o);return n&&o&&d(e,r,o),o},D=(t,e)=>(r,n)=>e(r,n,t);var G={};I(G,{HttpProxyDataSource:()=>l});module.exports=$(G);var y=P(require("axios")),m=require("inversify"),a=require("purify-ts"),u=require("../../config/di/configTypes"),i=require("../../shared/constant/HttpHeaders"),x=P(require("../../../package.json"));let l=class{constructor(e){this.config=e}async getProxyDelegateCall({proxyAddress:e,calldata:r,chainId:n}){let o;try{o=(await y.default.request({method:"POST",url:`${this.config.metadataService.url}/ethereum/${n}/contract/proxy/delegate`,headers:{[i.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${x.default.version}`,[i.LEDGER_ORIGIN_TOKEN_HEADER]:this.config.originToken},data:{proxy:e,data:r}})).data}catch{return(0,a.Left)(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy"))}return o?this.isProxyDelegateCallDto(o)?(0,a.Right)(o):(0,a.Left)(new Error(`[ContextModule] HttpProxyDataSource: Invalid proxy delegate call response format for proxy ${e} on chain ${n}`)):(0,a.Left)(new Error(`[ContextModule] HttpProxyDataSource: No data received for proxy ${e} on chain ${n}`))}async getProxyImplementationAddress({proxyAddress:e,chainId:r}){let n;try{n=(await y.default.request({method:"GET",url:`${this.config.metadataService.url}/ethereum/${r}/contract/proxy/${e}`,headers:{[i.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${x.default.version}`,[i.LEDGER_ORIGIN_TOKEN_HEADER]:this.config.originToken}})).data}catch{return(0,a.Left)(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch implementation address"))}return n?this.isProxyImplementationAddressDto(n)?(0,a.Right)({implementationAddress:n.implementationAddress}):(0,a.Left)(new Error(`[ContextModule] HttpProxyDataSource: Invalid proxy implementation address response format for proxy ${e} on chain ${r}`)):(0,a.Left)(new Error(`[ContextModule] HttpProxyDataSource: No data received for proxy ${e} on chain ${r}`))}isProxyDelegateCallDto(e){return typeof e=="object"&&e!==null&&"delegateAddresses"in e&&"signedDescriptor"in e&&Array.isArray(e.delegateAddresses)&&e.delegateAddresses.every(r=>typeof r=="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}};l=f([(0,m.injectable)(),D(0,(0,m.inject)(u.configTypes.Config))],l);0&&(module.exports={HttpProxyDataSource});
1
+ "use strict";var E=Object.create;var l=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var h=Object.getPrototypeOf,A=Object.prototype.hasOwnProperty;var I=(t,e)=>{for(var r in e)l(t,r,{get:e[r],enumerable:!0})},g=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of C(e))!A.call(t,n)&&n!==r&&l(t,n,{get:()=>e[n],enumerable:!(o=c(e,n))||o.enumerable});return t};var P=(t,e,r)=>(r=t!=null?E(h(t)):{},g(e||!t||!t.__esModule?l(r,"default",{value:t,enumerable:!0}):r,t)),$=t=>g(l({},"__esModule",{value:!0}),t),f=(t,e,r,o)=>{for(var n=o>1?void 0:o?c(e,r):e,i=t.length-1,d;i>=0;i--)(d=t[i])&&(n=(o?d(e,r,n):d(n))||n);return o&&n&&l(e,r,n),n},D=(t,e)=>(r,o)=>e(r,o,t);var G={};I(G,{HttpProxyDataSource:()=>m});module.exports=$(G);var y=P(require("axios")),p=require("inversify"),a=require("purify-ts"),u=require("../../config/di/configTypes"),s=require("../../shared/constant/HttpHeaders"),x=P(require("../../../package.json"));let m=class{constructor(e){this.config=e}async getProxyDelegateCall({proxyAddress:e,calldata:r,chainId:o,challenge:n}){let i;try{i=(await y.default.request({method:"POST",url:`${this.config.metadataServiceDomain.url}/v2/ethereum/${o}/contract/proxy/delegate`,headers:{[s.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${x.default.version}`,[s.LEDGER_ORIGIN_TOKEN_HEADER]:this.config.originToken},data:{proxy:e,data:r,challenge:n}})).data}catch{return(0,a.Left)(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy"))}return i?this.isProxyDelegateCallDto(i)?(0,a.Right)({delegateAddresses:i.addresses,signedDescriptor:i.signedDescriptor}):(0,a.Left)(new Error(`[ContextModule] HttpProxyDataSource: Invalid proxy delegate call response format for proxy ${e} on chain ${o}`)):(0,a.Left)(new Error(`[ContextModule] HttpProxyDataSource: No data received for proxy ${e} on chain ${o}`))}async getProxyImplementationAddress({proxyAddress:e,chainId:r}){let o;try{o=(await y.default.request({method:"GET",url:`${this.config.metadataServiceDomain.url}/v2/ethereum/${r}/contract/proxy/${e}`,headers:{[s.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${x.default.version}`,[s.LEDGER_ORIGIN_TOKEN_HEADER]:this.config.originToken}})).data}catch{return(0,a.Left)(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch implementation address"))}return o?this.isProxyImplementationAddressDto(o)?(0,a.Right)({implementationAddress:o.implementationAddress}):(0,a.Left)(new Error(`[ContextModule] HttpProxyDataSource: Invalid proxy implementation address response format for proxy ${e} on chain ${r}`)):(0,a.Left)(new Error(`[ContextModule] HttpProxyDataSource: No data received for proxy ${e} on chain ${r}`))}isProxyDelegateCallDto(e){return typeof e=="object"&&e!==null&&"addresses"in e&&"signedDescriptor"in e&&Array.isArray(e.addresses)&&e.addresses.every(r=>typeof r=="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}};m=f([(0,p.injectable)(),D(0,(0,p.inject)(u.configTypes.Config))],m);0&&(module.exports={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": "qtBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,yBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkB,oBAClBC,EAAmC,qBACnCC,EAAoC,qBAEpCC,EAA4B,mCAE5BC,EAGO,yCAGPC,EAAoB,iCA0Bb,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,MAAM,EAAAC,QAAM,QAA8B,CACzD,OAAQ,OACR,IAAK,GAAG,KAAK,OAAO,gBAAgB,GAAG,aAAaF,CAAO,2BAC3D,QAAS,CACP,CAAC,8BAA4B,EAAG,kBAAkB,EAAAG,QAAQ,OAAO,GACjE,CAAC,4BAA0B,EAAG,KAAK,OAAO,WAC5C,EACA,KAAM,CACJ,MAAOL,EACP,KAAMC,CACR,CACF,CAAC,GACc,IACjB,MAAiB,CACf,SAAO,QACL,IAAI,MACF,qEACF,CACF,CACF,CAEA,OAAKE,EAQA,KAAK,uBAAuBA,CAAG,KAQ7B,SA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eAAO,cAAY,MAAM,IAFjBX",
6
- "names": ["HttpProxyDataSource_exports", "__export", "HttpProxyDataSource", "__toCommonJS", "import_axios", "import_inversify", "import_purify_ts", "import_configTypes", "import_HttpHeaders", "import_package", "HttpProxyDataSource", "config", "proxyAddress", "calldata", "chainId", "dto", "axios", "PACKAGE", "value", "address", "__decorateClass", "__decorateParam"]
4
+ "sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { 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": "qtBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,yBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkB,oBAClBC,EAAmC,qBACnCC,EAAoC,qBAEpCC,EAA4B,mCAE5BC,EAGO,yCAGPC,EAAoB,iCA2Bb,IAAMC,EAAN,KAAqD,CAC1D,YAC+CC,EAC7C,CAD6C,YAAAA,CAC5C,CAEH,MAAa,qBAAqB,CAChC,aAAAC,EACA,SAAAC,EACA,QAAAC,EACA,UAAAC,CACF,EAAyE,CACvE,IAAIC,EACJ,GAAI,CAcFA,GAbiB,MAAM,EAAAC,QAAM,QAA8B,CACzD,OAAQ,OACR,IAAK,GAAG,KAAK,OAAO,sBAAsB,GAAG,gBAAgBH,CAAO,2BACpE,QAAS,CACP,CAAC,8BAA4B,EAAG,kBAAkB,EAAAI,QAAQ,OAAO,GACjE,CAAC,4BAA0B,EAAG,KAAK,OAAO,WAC5C,EACA,KAAM,CACJ,MAAON,EACP,KA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B,0BAA2BA,GAC3B,aAAcA,GACd,OAAOA,EAAM,cAAiB,UAC9B,OAAOA,EAAM,uBAA0B,UACvC,OAAOA,EAAM,UAAa,UAC1BA,EAAM,SAAS,OAAS,CAE5B,CACF,EAxIaT,EAANW,EAAA,IADN,cAAW,EAGPC,EAAA,eAAO,cAAY,MAAM,IAFjBZ",
6
+ "names": ["HttpProxyDataSource_exports", "__export", "HttpProxyDataSource", "__toCommonJS", "import_axios", "import_inversify", "import_purify_ts", "import_configTypes", "import_HttpHeaders", "import_package", "HttpProxyDataSource", "config", "proxyAddress", "calldata", "chainId", "challenge", "dto", "axios", "PACKAGE", "value", "address", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var f=Object.create;var m=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,P=Object.prototype.hasOwnProperty;var C=(o,t,r,d)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of v(t))!P.call(o,n)&&n!==r&&m(o,n,{get:()=>t[n],enumerable:!(d=h(t,n))||d.enumerable});return o};var x=(o,t,r)=>(r=o!=null?f(g(o)):{},C(t||!o||!o.__esModule?m(r,"default",{value:o,enumerable:!0}):r,o));var a=x(require("axios")),s=require("purify-ts"),c=require("../../shared/constant/HttpHeaders"),p=x(require("../../../package.json")),u=require("./HttpProxyDataSource");vi.mock("axios");describe("HttpProxyDataSource",()=>{const o={web3checks:{url:"web3checksUrl"},originToken:"originToken"};let t;const r={proxyAddress:"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0",calldata:"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000",chainId:1},d={proxyAddress:"0xee6a57ec80ea46401049e92587e52f5ec1c24785",chainId:1},n={delegateAddresses:["0xd9db270c1b5e3bd161e8c8503c55ceabee709552"],signedDescriptor:"0x1234567890abcdef"},y={implementationAddress:"0x91ae842a5ffd8d12023116943e72a606179294f3"},l={implementationAddress:"0x91ae842a5ffd8d12023116943e72a606179294f3",proxyAddress:"0xee6a57ec80ea46401049e92587e52f5ec1c24785",standard:"proxy"};beforeEach(()=>{vi.clearAllMocks(),t=new u.HttpProxyDataSource({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/${p.default.version}`,i=vi.fn(()=>Promise.resolve({data:n}));vi.spyOn(a.default,"request").mockImplementation(i),await t.getProxyDelegateCall(r),expect(i).toHaveBeenCalledWith(expect.objectContaining({headers:{[c.LEDGER_CLIENT_VERSION_HEADER]:e,[c.LEDGER_ORIGIN_TOKEN_HEADER]:o.originToken}}))}),it("should return the delegate proxy response on success",async()=>{vi.spyOn(a.default,"request").mockResolvedValue({data:n});const e=await t.getProxyDelegateCall(r);expect(e).toEqual((0,s.Right)(n))}),it("should return an error when axios throws an error",async()=>{vi.spyOn(a.default,"request").mockRejectedValue(new Error("fail"));const e=await t.getProxyDelegateCall(r);expect(e).toEqual((0,s.Left)(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy")))}),it("should return an error if response shape is invalid",async()=>{vi.spyOn(a.default,"request").mockResolvedValue({data:{foo:"bar"}});const e=await t.getProxyDelegateCall(r);expect(e).toEqual((0,s.Left)(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:n}));vi.spyOn(a.default,"request").mockImplementation(e);const i={proxyAddress:"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0",calldata:"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000",chainId:137};await t.getProxyDelegateCall(i),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.default,"request").mockResolvedValue({data:void 0});const e=await t.getProxyDelegateCall(r);expect(e).toEqual((0,s.Left)(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/${p.default.version}`,i=vi.fn(()=>Promise.resolve({data:l}));vi.spyOn(a.default,"request").mockImplementation(i),await t.getProxyImplementationAddress(d),expect(i).toHaveBeenCalledWith(expect.objectContaining({headers:{[c.LEDGER_CLIENT_VERSION_HEADER]:e,[c.LEDGER_ORIGIN_TOKEN_HEADER]:o.originToken}}))}),it("should make a GET request to the correct URL",async()=>{const e=vi.fn(()=>Promise.resolve({data:l}));vi.spyOn(a.default,"request").mockImplementation(e),await t.getProxyImplementationAddress(d),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:l}));vi.spyOn(a.default,"request").mockImplementation(e);const i={proxyAddress:"0xee6a57ec80ea46401049e92587e52f5ec1c24785",chainId:137};await t.getProxyImplementationAddress(i),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.default,"request").mockResolvedValue({data:l});const e=await t.getProxyImplementationAddress(d);expect(e).toEqual((0,s.Right)(y))}),it("should return an error when axios throws an error",async()=>{vi.spyOn(a.default,"request").mockRejectedValue(new Error("network error"));const e=await t.getProxyImplementationAddress(d);expect(e).toEqual((0,s.Left)(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch implementation address")))}),it("should return an error if response shape is invalid",async()=>{vi.spyOn(a.default,"request").mockResolvedValue({data:{invalid:"data"}});const e=await t.getProxyImplementationAddress(d);expect(e).toEqual((0,s.Left)(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.default,"request").mockResolvedValue({data:void 0});const e=await t.getProxyImplementationAddress(d);expect(e).toEqual((0,s.Left)(new Error("[ContextModule] HttpProxyDataSource: No data received for proxy 0xee6a57ec80ea46401049e92587e52f5ec1c24785 on chain 1")))})})});
1
+ "use strict";var f=Object.create;var m=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var v=Object.getPrototypeOf,P=Object.prototype.hasOwnProperty;var C=(o,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let d of g(t))!P.call(o,d)&&d!==r&&m(o,d,{get:()=>t[d],enumerable:!(s=h(t,d))||s.enumerable});return o};var x=(o,t,r)=>(r=o!=null?f(v(o)):{},C(t||!o||!o.__esModule?m(r,"default",{value:o,enumerable:!0}):r,o));var a=x(require("axios")),n=require("purify-ts"),c=require("../../shared/constant/HttpHeaders"),p=x(require("../../../package.json")),u=require("./HttpProxyDataSource");vi.mock("axios");describe("HttpProxyDataSource",()=>{const o={web3checks:{url:"web3checksUrl"},originToken:"originToken"};let t;const r={proxyAddress:"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0",calldata:"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000",chainId:1,challenge:"0x1234567890abcdef"},s={proxyAddress:"0xee6a57ec80ea46401049e92587e52f5ec1c24785",chainId:1},d={addresses:["0xd9db270c1b5e3bd161e8c8503c55ceabee709552"],signedDescriptor:"0x1234567890abcdef"},y={implementationAddress:"0x91ae842a5ffd8d12023116943e72a606179294f3"},l={implementationAddress:"0x91ae842a5ffd8d12023116943e72a606179294f3",proxyAddress:"0xee6a57ec80ea46401049e92587e52f5ec1c24785",standard:"proxy"};beforeEach(()=>{vi.clearAllMocks(),t=new u.HttpProxyDataSource({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/${p.default.version}`,i=vi.fn(()=>Promise.resolve({data:d}));vi.spyOn(a.default,"request").mockImplementation(i),await t.getProxyDelegateCall(r),expect(i).toHaveBeenCalledWith(expect.objectContaining({headers:{[c.LEDGER_CLIENT_VERSION_HEADER]:e,[c.LEDGER_ORIGIN_TOKEN_HEADER]:o.originToken}}))}),it("should return the delegate proxy response on success",async()=>{vi.spyOn(a.default,"request").mockResolvedValue({data:d});const e=await t.getProxyDelegateCall(r);expect(e).toEqual((0,n.Right)({delegateAddresses:["0xd9db270c1b5e3bd161e8c8503c55ceabee709552"],signedDescriptor:"0x1234567890abcdef"}))}),it("should return an error when axios throws an error",async()=>{vi.spyOn(a.default,"request").mockRejectedValue(new Error("fail"));const e=await t.getProxyDelegateCall(r);expect(e).toEqual((0,n.Left)(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy")))}),it("should return an error if response shape is invalid",async()=>{vi.spyOn(a.default,"request").mockResolvedValue({data:{foo:"bar"}});const e=await t.getProxyDelegateCall(r);expect(e).toEqual((0,n.Left)(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.default,"request").mockImplementation(e);const i={proxyAddress:"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0",calldata:"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000",chainId:137,challenge:"0x1234567890abcdef"};await t.getProxyDelegateCall(i),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.default,"request").mockResolvedValue({data:void 0});const e=await t.getProxyDelegateCall(r);expect(e).toEqual((0,n.Left)(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/${p.default.version}`,i=vi.fn(()=>Promise.resolve({data:l}));vi.spyOn(a.default,"request").mockImplementation(i),await t.getProxyImplementationAddress(s),expect(i).toHaveBeenCalledWith(expect.objectContaining({headers:{[c.LEDGER_CLIENT_VERSION_HEADER]:e,[c.LEDGER_ORIGIN_TOKEN_HEADER]:o.originToken}}))}),it("should make a GET request to the correct URL",async()=>{const e=vi.fn(()=>Promise.resolve({data:l}));vi.spyOn(a.default,"request").mockImplementation(e),await t.getProxyImplementationAddress(s),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:l}));vi.spyOn(a.default,"request").mockImplementation(e);const i={proxyAddress:"0xee6a57ec80ea46401049e92587e52f5ec1c24785",chainId:137};await t.getProxyImplementationAddress(i),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.default,"request").mockResolvedValue({data:l});const e=await t.getProxyImplementationAddress(s);expect(e).toEqual((0,n.Right)(y))}),it("should return an error when axios throws an error",async()=>{vi.spyOn(a.default,"request").mockRejectedValue(new Error("network error"));const e=await t.getProxyImplementationAddress(s);expect(e).toEqual((0,n.Left)(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch implementation address")))}),it("should return an error if response shape is invalid",async()=>{vi.spyOn(a.default,"request").mockResolvedValue({data:{invalid:"data"}});const e=await t.getProxyImplementationAddress(s);expect(e).toEqual((0,n.Left)(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.default,"request").mockResolvedValue({data:void 0});const e=await t.getProxyImplementationAddress(s);expect(e).toEqual((0,n.Left)(new Error("[ContextModule] HttpProxyDataSource: No data received for proxy 0xee6a57ec80ea46401049e92587e52f5ec1c24785 on chain 1")))})})});
2
2
  //# sourceMappingURL=HttpProxyDataSource.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/transaction/data/HttpProxyDataSource.test.ts"],
4
- "sourcesContent": ["import axios from \"axios\";\nimport { Left, Right } from \"purify-ts\";\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 type { ProxyDelegateCall } from \"@/transaction/model/ProxyDelegateCall\";\nimport type { ProxyImplementationAddress } from \"@/transaction/model/ProxyImplementationAddress\";\nimport PACKAGE from \"@root/package.json\";\n\nimport { type ProxyImplementationAddressDto } from \"./dto/ProxyImplementationAddressDto\";\nimport type {\n GetProxyDelegateCallParam,\n GetProxyImplementationAddressParam,\n ProxyDataSource,\n} from \"./HttpProxyDataSource\";\nimport { HttpProxyDataSource } from \"./HttpProxyDataSource\";\n\nvi.mock(\"axios\");\n\ndescribe(\"HttpProxyDataSource\", () => {\n const config = {\n web3checks: {\n url: \"web3checksUrl\",\n },\n originToken: \"originToken\",\n } as ContextModuleConfig;\n\n let datasource: ProxyDataSource;\n const defaultParams: GetProxyDelegateCallParam = {\n proxyAddress: \"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0\",\n calldata:\n \"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000\",\n chainId: 1,\n };\n const defaultImplementAddressParams: GetProxyImplementationAddressParam = {\n proxyAddress: \"0xee6a57ec80ea46401049e92587e52f5ec1c24785\",\n chainId: 1,\n };\n const delegateProxyResponse: ProxyDelegateCall = {\n delegateAddresses: [\"0xd9db270c1b5e3bd161e8c8503c55ceabee709552\"],\n signedDescriptor: \"0x1234567890abcdef\",\n };\n const implementationAddressResponse: ProxyImplementationAddress = {\n implementationAddress: \"0x91ae842a5ffd8d12023116943e72a606179294f3\",\n };\n const implementationAddressDto: ProxyImplementationAddressDto = {\n implementationAddress: \"0x91ae842a5ffd8d12023116943e72a606179294f3\",\n proxyAddress: \"0xee6a57ec80ea46401049e92587e52f5ec1c24785\",\n standard: \"proxy\",\n };\n\n beforeEach(() => {\n vi.clearAllMocks();\n datasource = new HttpProxyDataSource({\n metadataService: {\n url: \"https://nft.api.live.ledger.com/v2\",\n },\n originToken: \"originToken\",\n } as ContextModuleConfig);\n });\n\n describe(\"getDelegateProxy\", () => {\n it(\"should call axios with the ledger client version header\", async () => {\n // GIVEN\n const version = `context-module/${PACKAGE.version}`;\n const requestSpy = vi.fn(() =>\n Promise.resolve({ data: delegateProxyResponse }),\n );\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n // WHEN\n await datasource.getProxyDelegateCall(defaultParams);\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: version,\n [LEDGER_ORIGIN_TOKEN_HEADER]: config.originToken,\n },\n }),\n );\n });\n\n it(\"should return the delegate proxy response on success\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({\n data: delegateProxyResponse,\n });\n\n // WHEN\n const result = await datasource.getProxyDelegateCall(defaultParams);\n\n // THEN\n expect(result).toEqual(Right(delegateProxyResponse));\n });\n\n it(\"should return an error when axios throws an error\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockRejectedValue(new Error(\"fail\"));\n\n // WHEN\n const result = await datasource.getProxyDelegateCall(defaultParams);\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy\",\n ),\n ),\n );\n });\n\n it(\"should return an error if response shape is invalid\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({ data: { foo: \"bar\" } });\n\n // WHEN\n const result = await datasource.getProxyDelegateCall(defaultParams);\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: Invalid proxy delegate call response format for proxy 0x72CBdEaAdddD14Ec95b92995933CeC69566650f0 on chain 1\",\n ),\n ),\n );\n });\n\n it(\"should use the provided chainId in the URL\", async () => {\n // GIVEN\n const requestSpy = vi.fn(() =>\n Promise.resolve({ data: delegateProxyResponse }),\n );\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n const paramsWithDifferentChainId: GetProxyDelegateCallParam = {\n proxyAddress: \"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0\",\n calldata:\n \"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000\",\n chainId: 137, // Polygon\n };\n\n // WHEN\n await datasource.getProxyDelegateCall(paramsWithDifferentChainId);\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n method: \"POST\",\n url: \"https://nft.api.live.ledger.com/v2/ethereum/137/contract/proxy/delegate\",\n }),\n );\n });\n\n it(\"should return an error if no dto is returned from the api\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({\n data: undefined,\n });\n\n // WHEN\n const result = await datasource.getProxyDelegateCall(defaultParams);\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: No data received for proxy 0x72CBdEaAdddD14Ec95b92995933CeC69566650f0 on chain 1\",\n ),\n ),\n );\n });\n });\n\n describe(\"getImplementAddress\", () => {\n it(\"should call axios with the ledger client version header\", async () => {\n // GIVEN\n const version = `context-module/${PACKAGE.version}`;\n const requestSpy = vi.fn(() =>\n Promise.resolve({ data: implementationAddressDto }),\n );\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n // WHEN\n await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: version,\n [LEDGER_ORIGIN_TOKEN_HEADER]: config.originToken,\n },\n }),\n );\n });\n\n it(\"should make a GET request to the correct URL\", async () => {\n // GIVEN\n const requestSpy = vi.fn(() =>\n Promise.resolve({ data: implementationAddressDto }),\n );\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n // WHEN\n await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n method: \"GET\",\n url: \"https://nft.api.live.ledger.com/v2/ethereum/1/contract/proxy/0xee6a57ec80ea46401049e92587e52f5ec1c24785\",\n }),\n );\n });\n\n it(\"should use the provided chainId in the URL\", async () => {\n // GIVEN\n const requestSpy = vi.fn(() =>\n Promise.resolve({ data: implementationAddressDto }),\n );\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n const paramsWithDifferentChainId: GetProxyImplementationAddressParam = {\n proxyAddress: \"0xee6a57ec80ea46401049e92587e52f5ec1c24785\",\n chainId: 137, // Polygon\n };\n\n // WHEN\n await datasource.getProxyImplementationAddress(\n paramsWithDifferentChainId,\n );\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n method: \"GET\",\n url: \"https://nft.api.live.ledger.com/v2/ethereum/137/contract/proxy/0xee6a57ec80ea46401049e92587e52f5ec1c24785\",\n }),\n );\n });\n\n it(\"should return the implementation address response on success\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({\n data: implementationAddressDto,\n });\n\n // WHEN\n const result = await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(result).toEqual(Right(implementationAddressResponse));\n });\n\n it(\"should return an error when axios throws an error\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockRejectedValue(new Error(\"network error\"));\n\n // WHEN\n const result = await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: Failed to fetch implementation address\",\n ),\n ),\n );\n });\n\n it(\"should return an error if response shape is invalid\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({\n data: { invalid: \"data\" },\n });\n\n // WHEN\n const result = await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: Invalid proxy implementation address response format for proxy 0xee6a57ec80ea46401049e92587e52f5ec1c24785 on chain 1\",\n ),\n ),\n );\n });\n\n it(\"should return an error if no dto is returned from the api\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({\n data: undefined,\n });\n\n // WHEN\n const result = await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: No data received for proxy 0xee6a57ec80ea46401049e92587e52f5ec1c24785 on chain 1\",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QAAO,SAAS,EAAE,kBAAkB,IAAI,MAAM,eAAe,CAAC,EAGvE,MAAMC,EAAS,MAAMV,EAAW,8BAC9BE,CACF,EAGA,OAAOQ,CAAM,EAAE,WACb,QACE,IAAI,MACF,6EACF,CACF,CACF,CACF,CAAC,EAED,GAAG,sDAAuD,SAAY,CAEpE,GAAG,MAAM,EAAAD,QAAO,SAAS,EAAE,kBAAkB,CAC3C,KAAM,CAAE,QAAS,MAAO,CAC1B,CAAC,EAGD,MAAMC,EAAS,MAAMV,EAAW,8BAC9BE,CACF,EAGA,OAAOQ,CAAM,EAAE,WACb,QACE,IAAI,MACF,2JACF,CACF,CACF,CACF,CAAC,EAED,GAAG,4DAA6D,SAAY,CAE1E,GAAG,MAAM,EAAAD,QAAO,SAAS,EAAE,kBAAkB,CAC3C,KAAM,MACR,CAAC,EAGD,MAAMC,EAAS,MAAMV,EAAW,8BAC9BE,CACF,EAGA,OAAOQ,CAAM,EAAE,WACb,QACE,IAAI,MACF,uHACF,CACF,CACF,CACF,CAAC,CACH,CAAC,CACH,CAAC",
4
+ "sourcesContent": ["import axios from \"axios\";\nimport { Left, Right } from \"purify-ts\";\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 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\";\nimport type {\n GetProxyDelegateCallParam,\n GetProxyImplementationAddressParam,\n ProxyDataSource,\n} from \"./HttpProxyDataSource\";\nimport { HttpProxyDataSource } from \"./HttpProxyDataSource\";\n\nvi.mock(\"axios\");\n\ndescribe(\"HttpProxyDataSource\", () => {\n const config = {\n web3checks: {\n url: \"web3checksUrl\",\n },\n originToken: \"originToken\",\n } as ContextModuleConfig;\n\n let datasource: ProxyDataSource;\n const defaultParams: GetProxyDelegateCallParam = {\n proxyAddress: \"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0\",\n calldata:\n \"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000\",\n chainId: 1,\n challenge: \"0x1234567890abcdef\",\n };\n const defaultImplementAddressParams: GetProxyImplementationAddressParam = {\n proxyAddress: \"0xee6a57ec80ea46401049e92587e52f5ec1c24785\",\n chainId: 1,\n };\n const delegateProxyResponse: ProxyDelegateCallDto = {\n addresses: [\"0xd9db270c1b5e3bd161e8c8503c55ceabee709552\"],\n signedDescriptor: \"0x1234567890abcdef\",\n };\n const implementationAddressResponse: ProxyImplementationAddress = {\n implementationAddress: \"0x91ae842a5ffd8d12023116943e72a606179294f3\",\n };\n const implementationAddressDto: ProxyImplementationAddressDto = {\n implementationAddress: \"0x91ae842a5ffd8d12023116943e72a606179294f3\",\n proxyAddress: \"0xee6a57ec80ea46401049e92587e52f5ec1c24785\",\n standard: \"proxy\",\n };\n\n beforeEach(() => {\n vi.clearAllMocks();\n datasource = new HttpProxyDataSource({\n metadataServiceDomain: {\n url: \"https://nft.api.live.ledger.com\",\n },\n originToken: \"originToken\",\n } as ContextModuleConfig);\n });\n\n describe(\"getDelegateProxy\", () => {\n it(\"should call axios with the ledger client version header\", async () => {\n // GIVEN\n const version = `context-module/${PACKAGE.version}`;\n const requestSpy = vi.fn(() =>\n Promise.resolve({ data: delegateProxyResponse }),\n );\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n // WHEN\n await datasource.getProxyDelegateCall(defaultParams);\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: version,\n [LEDGER_ORIGIN_TOKEN_HEADER]: config.originToken,\n },\n }),\n );\n });\n\n it(\"should return the delegate proxy response on success\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({\n data: delegateProxyResponse,\n });\n\n // WHEN\n const result = await datasource.getProxyDelegateCall(defaultParams);\n\n // THEN\n expect(result).toEqual(\n Right({\n delegateAddresses: [\"0xd9db270c1b5e3bd161e8c8503c55ceabee709552\"],\n signedDescriptor: \"0x1234567890abcdef\",\n }),\n );\n });\n\n it(\"should return an error when axios throws an error\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockRejectedValue(new Error(\"fail\"));\n\n // WHEN\n const result = await datasource.getProxyDelegateCall(defaultParams);\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy\",\n ),\n ),\n );\n });\n\n it(\"should return an error if response shape is invalid\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({ data: { foo: \"bar\" } });\n\n // WHEN\n const result = await datasource.getProxyDelegateCall(defaultParams);\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: Invalid proxy delegate call response format for proxy 0x72CBdEaAdddD14Ec95b92995933CeC69566650f0 on chain 1\",\n ),\n ),\n );\n });\n\n it(\"should use the provided chainId in the URL\", async () => {\n // GIVEN\n const requestSpy = vi.fn(() =>\n Promise.resolve({ data: delegateProxyResponse }),\n );\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n const paramsWithDifferentChainId: GetProxyDelegateCallParam = {\n proxyAddress: \"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0\",\n calldata:\n \"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000\",\n chainId: 137, // Polygon\n challenge: \"0x1234567890abcdef\",\n };\n\n // WHEN\n await datasource.getProxyDelegateCall(paramsWithDifferentChainId);\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n method: \"POST\",\n url: \"https://nft.api.live.ledger.com/v2/ethereum/137/contract/proxy/delegate\",\n }),\n );\n });\n\n it(\"should return an error if no dto is returned from the api\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({\n data: undefined,\n });\n\n // WHEN\n const result = await datasource.getProxyDelegateCall(defaultParams);\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: No data received for proxy 0x72CBdEaAdddD14Ec95b92995933CeC69566650f0 on chain 1\",\n ),\n ),\n );\n });\n });\n\n describe(\"getImplementAddress\", () => {\n it(\"should call axios with the ledger client version header\", async () => {\n // GIVEN\n const version = `context-module/${PACKAGE.version}`;\n const requestSpy = vi.fn(() =>\n Promise.resolve({ data: implementationAddressDto }),\n );\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n // WHEN\n await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: version,\n [LEDGER_ORIGIN_TOKEN_HEADER]: config.originToken,\n },\n }),\n );\n });\n\n it(\"should make a GET request to the correct URL\", async () => {\n // GIVEN\n const requestSpy = vi.fn(() =>\n Promise.resolve({ data: implementationAddressDto }),\n );\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n // WHEN\n await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n method: \"GET\",\n url: \"https://nft.api.live.ledger.com/v2/ethereum/1/contract/proxy/0xee6a57ec80ea46401049e92587e52f5ec1c24785\",\n }),\n );\n });\n\n it(\"should use the provided chainId in the URL\", async () => {\n // GIVEN\n const requestSpy = vi.fn(() =>\n Promise.resolve({ data: implementationAddressDto }),\n );\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n const paramsWithDifferentChainId: GetProxyImplementationAddressParam = {\n proxyAddress: \"0xee6a57ec80ea46401049e92587e52f5ec1c24785\",\n chainId: 137, // Polygon\n };\n\n // WHEN\n await datasource.getProxyImplementationAddress(\n paramsWithDifferentChainId,\n );\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n method: \"GET\",\n url: \"https://nft.api.live.ledger.com/v2/ethereum/137/contract/proxy/0xee6a57ec80ea46401049e92587e52f5ec1c24785\",\n }),\n );\n });\n\n it(\"should return the implementation address response on success\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({\n data: implementationAddressDto,\n });\n\n // WHEN\n const result = await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(result).toEqual(Right(implementationAddressResponse));\n });\n\n it(\"should return an error when axios throws an error\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockRejectedValue(new Error(\"network error\"));\n\n // WHEN\n const result = await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: Failed to fetch implementation address\",\n ),\n ),\n );\n });\n\n it(\"should return an error if response shape is invalid\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({\n data: { invalid: \"data\" },\n });\n\n // WHEN\n const result = await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: Invalid proxy implementation address response format for proxy 0xee6a57ec80ea46401049e92587e52f5ec1c24785 on chain 1\",\n ),\n ),\n );\n });\n\n it(\"should return an error if no dto is returned from the api\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({\n data: undefined,\n });\n\n // WHEN\n const result = await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: No data received for proxy 0xee6a57ec80ea46401049e92587e52f5ec1c24785 on chain 1\",\n ),\n ),\n );\n });\n });\n});\n"],
5
+ "mappings": "wdAAA,IAAAA,EAAkB,oBAClBC,EAA4B,qBAG5BC,EAGO,yCAEPC,EAAoB,iCASpBC,EAAoC,iCAEpC,GAAG,KAAK,OAAO,EAEf,SAAS,sBAAuB,IAAM,CACpC,MAAMC,EAAS,CACb,WAAY,CACV,IAAK,eACP,EACA,YAAa,aACf,EAEA,IAAIC,EACJ,MAAMC,EAA2C,CAC/C,aAAc,6CACd,SACE,0oCACF,QAAS,EACT,UAAW,oBACb,EAC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AE,QAAS,MAAO,CAC1B,CAAC,EAGD,MAAMC,EAAS,MAAMV,EAAW,8BAC9BE,CACF,EAGA,OAAOQ,CAAM,EAAE,WACb,QACE,IAAI,MACF,2JACF,CACF,CACF,CACF,CAAC,EAED,GAAG,4DAA6D,SAAY,CAE1E,GAAG,MAAM,EAAAD,QAAO,SAAS,EAAE,kBAAkB,CAC3C,KAAM,MACR,CAAC,EAGD,MAAMC,EAAS,MAAMV,EAAW,8BAC9BE,CACF,EAGA,OAAOQ,CAAM,EAAE,WACb,QACE,IAAI,MACF,uHACF,CACF,CACF,CACF,CAAC,CACH,CAAC,CACH,CAAC",
6
6
  "names": ["import_axios", "import_purify_ts", "import_HttpHeaders", "import_package", "import_HttpProxyDataSource", "config", "datasource", "defaultParams", "defaultImplementAddressParams", "delegateProxyResponse", "implementationAddressResponse", "implementationAddressDto", "version", "PACKAGE", "requestSpy", "axios", "result", "paramsWithDifferentChainId"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var g=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var o=Object.prototype.hasOwnProperty;var a=(t,e,d,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of l(e))!o.call(t,r)&&r!==d&&g(t,r,{get:()=>e[r],enumerable:!(s=i(e,r))||s.enumerable});return t};var n=t=>a(g({},"__esModule",{value:!0}),t);var p={};module.exports=n(p);
1
+ "use strict";var g=Object.defineProperty;var o=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var l=(r,e,i,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of a(e))!d.call(r,s)&&s!==i&&g(r,s,{get:()=>e[s],enumerable:!(t=o(e,s))||t.enumerable});return r};var n=r=>l(g({},"__esModule",{value:!0}),r);var p={};module.exports=n(p);
2
2
  //# sourceMappingURL=ProxyDelegateCallDto.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/transaction/data/dto/ProxyDelegateCallDto.ts"],
4
- "sourcesContent": ["export type ProxyDelegateCallDto = {\n delegateAddresses: string[];\n signedDescriptor: string;\n};\n"],
4
+ "sourcesContent": ["export type ProxyDelegateCallDto = {\n addresses: string[];\n signedDescriptor: string;\n};\n"],
5
5
  "mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
6
6
  "names": ["ProxyDelegateCallDto_exports", "__toCommonJS"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var s=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var D=(e,t)=>{for(var a in t)s(e,a,{get:t[a],enumerable:!0})},R=(e,t,a,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of x(t))!g.call(e,r)&&r!==a&&s(e,r,{get:()=>t[r],enumerable:!(o=u(t,r))||o.enumerable});return e};var y=e=>R(s({},"__esModule",{value:!0}),e),f=(e,t,a,o)=>{for(var r=o>1?void 0:o?u(t,a):t,n=e.length-1,i;n>=0;n--)(i=e[n])&&(r=(o?i(t,a,r):i(r))||r);return o&&r&&s(t,a,r),r},S=(e,t)=>(a,o)=>t(a,o,e);var T={};D(T,{TransactionContextLoader:()=>c});module.exports=y(T);var d=require("@ledgerhq/device-management-kit"),m=require("inversify"),l=require("../../shared/model/ClearSignContext"),C=require("../../transaction/di/transactionTypes");let c=class{constructor(t){this.transactionDataSource=t}async load(t){const{to:a,data:o,selector:r,chainId:n,deviceModelId:i}=t;return a===void 0||o==="0x"?[]:(0,d.isHexaString)(r)?(await this.transactionDataSource.getTransactionDescriptors({deviceModelId:i,address:a,chainId:n,selector:r})).caseOf({Left:p=>[{type:l.ClearSignContextType.ERROR,error:p}],Right:p=>p}):[{type:l.ClearSignContextType.ERROR,error:new Error("Invalid selector")}]}};c=f([(0,m.injectable)(),S(0,(0,m.inject)(C.transactionTypes.TransactionDataSource))],c);0&&(module.exports={TransactionContextLoader});
1
+ "use strict";var s=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var R=Object.prototype.hasOwnProperty;var T=(i,e)=>{for(var r in e)s(i,r,{get:e[r],enumerable:!0})},E=(i,e,r,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of P(e))!R.call(i,t)&&t!==r&&s(i,t,{get:()=>e[t],enumerable:!(a=y(e,t))||a.enumerable});return i};var O=i=>E(s({},"__esModule",{value:!0}),i),g=(i,e,r,a)=>{for(var t=a>1?void 0:a?y(e,r):e,o=i.length-1,n;o>=0;o--)(n=i[o])&&(t=(a?n(e,r,t):n(t))||t);return a&&t&&s(e,r,t),t},C=(i,e)=>(r,a)=>e(r,a,i);var h={};T(h,{TransactionContextLoader:()=>c});module.exports=O(h);var l=require("@ledgerhq/device-management-kit"),d=require("inversify"),S=require("../../pki/di/pkiTypes"),D=require("../../pki/model/KeyId"),x=require("../../pki/model/KeyUsage"),f=require("../../shared/model/ClearSignContext"),k=require("../../transaction/di/transactionTypes");let c=class{constructor(e,r){this.transactionDataSource=e;this.certificateLoader=r}async load(e){if(e.deviceModelId===l.DeviceModelId.NANO_S)return[];const{to:r,data:a,selector:t,chainId:o,deviceModelId:n}=e;if(r===void 0||a==="0x")return[];if(!(0,l.isHexaString)(t))return[{type:f.ClearSignContextType.ERROR,error:new Error("Invalid selector")}];const p=void 0,v=r;let u;p&&(u=await this.certificateLoader.loadCertificate({keyId:D.KeyId.CalCalldataKey,keyUsage:x.KeyUsage.Calldata,targetDevice:e.deviceModelId}));const L=p?[{type:f.ClearSignContextType.PROXY_DELEGATE_CALL,payload:p,certificate:u}]:[],I=(await this.transactionDataSource.getTransactionDescriptors({deviceModelId:n,address:v,chainId:o,selector:t})).caseOf({Left:m=>[{type:f.ClearSignContextType.ERROR,error:m}],Right:m=>m});return[...L,...I]}};c=g([(0,d.injectable)(),C(0,(0,d.inject)(k.transactionTypes.TransactionDataSource)),C(1,(0,d.inject)(S.pkiTypes.PkiCertificateLoader))],c);0&&(module.exports={TransactionContextLoader});
2
2
  //# sourceMappingURL=TransactionContextLoader.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/transaction/domain/TransactionContextLoader.ts"],
4
- "sourcesContent": ["import { isHexaString } from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { TransactionContext } from \"@/shared/model/TransactionContext\";\nimport type { TransactionDataSource } from \"@/transaction/data/TransactionDataSource\";\nimport { transactionTypes } from \"@/transaction/di/transactionTypes\";\n\n@injectable()\nexport class TransactionContextLoader implements ContextLoader {\n constructor(\n @inject(transactionTypes.TransactionDataSource)\n private transactionDataSource: TransactionDataSource,\n ) {}\n\n async load(ctx: TransactionContext): Promise<ClearSignContext[]> {\n const { to, data, selector, chainId, deviceModelId } = ctx;\n if (to === undefined || data === \"0x\") {\n return [];\n }\n\n if (!isHexaString(selector)) {\n return [\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Invalid selector\"),\n },\n ];\n }\n\n const result = await this.transactionDataSource.getTransactionDescriptors({\n deviceModelId,\n address: to,\n chainId,\n selector,\n });\n\n return result.caseOf({\n Left: (error): ClearSignContext[] => [\n {\n type: ClearSignContextType.ERROR,\n error,\n },\n ],\n Right: (contexts): ClearSignContext[] => contexts,\n });\n }\n}\n"],
5
- "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,8BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAA6B,2CAC7BC,EAAmC,qBAGnCC,EAGO,2CAGPC,EAAiC,6CAG1B,IAAMC,EAAN,KAAwD,CAC7D,YAEUC,EACR,CADQ,2BAAAA,CACP,CAEH,MAAM,KAAKC,EAAsD,CAC/D,KAAM,CAAE,GAAAC,EAAI,KAAAC,EAAM,SAAAC,EAAU,QAAAC,EAAS,cAAAC,CAAc,EAAIL,EACvD,OAAIC,IAAO,QAAaC,IAAS,KACxB,CAAC,KAGL,gBAAaC,CAAQ,GASX,MAAM,KAAK,sBAAsB,0BAA0B,CACxE,cAAAE,EACA,QAASJ,EACT,QAAAG,EACA,SAAAD,CACF,CAAC,GAEa,OAAO,CACnB,KAAOG,GAA8B,CACnC,CACE,KAAM,uBAAqB,MAC3B,MAAAA,CACF,CACF,EACA,MAAQC,GAAiCA,CAC3C,CAAC,EAvBQ,CACL,CACE,KAAM,uBAAqB,MAC3B,MAAO,IAAI,MAAM,kBAAkB,CACrC,CACF,CAmBJ,CACF,EAtCaT,EAANU,EAAA,IADN,cAAW,EAGPC,EAAA,eAAO,mBAAiB,qBAAqB,IAFrCX",
6
- "names": ["TransactionContextLoader_exports", "__export", "TransactionContextLoader", "__toCommonJS", "import_device_management_kit", "import_inversify", "import_ClearSignContext", "import_transactionTypes", "TransactionContextLoader", "transactionDataSource", "ctx", "to", "data", "selector", "chainId", "deviceModelId", "error", "contexts", "__decorateClass", "__decorateParam"]
4
+ "sourcesContent": ["import { DeviceModelId, isHexaString } from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport type { PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { TransactionContext } from \"@/shared/model/TransactionContext\";\n//import type { ProxyDataSource } from \"@/transaction/data/HttpProxyDataSource\";\nimport type { TransactionDataSource } from \"@/transaction/data/TransactionDataSource\";\nimport { transactionTypes } from \"@/transaction/di/transactionTypes\";\n\n@injectable()\nexport class TransactionContextLoader implements ContextLoader {\n constructor(\n @inject(transactionTypes.TransactionDataSource)\n private transactionDataSource: TransactionDataSource,\n /*@inject(transactionTypes.ProxyDataSource)\n private _proxyDataSource: ProxyDataSource,*/\n @inject(pkiTypes.PkiCertificateLoader)\n private certificateLoader: PkiCertificateLoader,\n ) {}\n\n async load(ctx: TransactionContext): Promise<ClearSignContext[]> {\n if (ctx.deviceModelId === DeviceModelId.NANO_S) {\n return [];\n }\n\n //TODO add challenge when proxy is enabled\n const { to, data, selector, chainId, deviceModelId } = ctx;\n if (to === undefined || data === \"0x\") {\n return [];\n }\n\n if (!isHexaString(selector)) {\n return [\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Invalid selector\"),\n },\n ];\n }\n /*\nDISABLE PROXY FOR NOW, to be enabled later\n\n const proxyDelegateCall = await this.proxyDataSource.getProxyDelegateCall({\n calldata: data,\n proxyAddress: to,\n chainId,\n challenge: challenge || \"\",\n });\n\n // get the resolved address from the list of delegate addresses\n // if the transaction.to is not in the list of delegate addresses,\n // return the first element as the resolved address,\n // and undefined as the proxy delegate call descriptor\n // if the transaction.to is in the list of delegate addresses,\n // return the transaction.to as the resolved address,\n // and the proxy delegate call descriptor\n const [resolvedAddress, proxyDelegateCallDescriptor]: [\n string,\n string | undefined,\n ] = proxyDelegateCall.caseOf({\n Left: () => [to!, undefined],\n Right: (proxyData: ProxyDelegateCall): [string, string | undefined] => {\n return [\n proxyData.delegateAddresses.find((address) => address === to) ||\n proxyData.delegateAddresses[0]!,\n proxyData.signedDescriptor,\n ];\n },\n });\n*/\n // TMP Values to be removed when proxy is enabled\n const proxyDelegateCallDescriptor: string | undefined = undefined;\n const resolvedAddress: string | undefined = to;\n\n let certificate: PkiCertificate | undefined = undefined;\n if (proxyDelegateCallDescriptor) {\n certificate = await this.certificateLoader.loadCertificate({\n keyId: KeyId.CalCalldataKey,\n keyUsage: KeyUsage.Calldata,\n targetDevice: ctx.deviceModelId,\n });\n }\n\n const proxyDelegateCallContext: ClearSignContext[] =\n proxyDelegateCallDescriptor\n ? [\n {\n type: ClearSignContextType.PROXY_DELEGATE_CALL,\n payload: proxyDelegateCallDescriptor,\n certificate: certificate,\n },\n ]\n : [];\n\n const transactionContexts = (\n await this.transactionDataSource.getTransactionDescriptors({\n deviceModelId,\n address: resolvedAddress,\n chainId,\n selector,\n })\n ).caseOf({\n Left: (error): ClearSignContext[] => [\n {\n type: ClearSignContextType.ERROR,\n error,\n },\n ],\n Right: (contexts): ClearSignContext[] => contexts,\n });\n\n return [...proxyDelegateCallContext, ...transactionContexts];\n }\n}\n"],
5
+ "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,8BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAA4C,2CAC5CC,EAAmC,qBAEnCC,EAAyB,6BAEzBC,EAAsB,6BACtBC,EAAyB,gCAGzBC,EAGO,2CAIPC,EAAiC,6CAG1B,IAAMC,EAAN,KAAwD,CAC7D,YAEUC,EAIAC,EACR,CALQ,2BAAAD,EAIA,uBAAAC,CACP,CAEH,MAAM,KAAKC,EAAsD,CAC/D,GAAIA,EAAI,gBAAkB,gBAAc,OACtC,MAAO,CAAC,EAIV,KAAM,CAAE,GAAAC,EAAI,KAAAC,EAAM,SAAAC,EAAU,QAAAC,EAAS,cAAAC,CAAc,EAAIL,EACvD,GAAIC,IAAO,QAAaC,IAAS,KAC/B,MAAO,CAAC,EAGV,GAAI,IAAC,gBAAaC,CAAQ,EACxB,MAAO,CACL,CACE,KAAM,uBAAqB,MAC3B,MAAO,IAAI,MAAM,kBAAkB,CACrC,CACF,EAkCF,MAAMG,EAAkD,OAClDC,EAAsCN,EAE5C,IAAIO,EACAF,IACFE,EAAc,MAAM,KAAK,kBAAkB,gBAAgB,CACzD,MAAO,QAAM,eACb,SAAU,WAAS,SACnB,aAAcR,EAAI,aACpB,CAAC,GAGH,MAAMS,EACJH,EACI,CACE,CACE,KAAM,uBAAqB,oBAC3B,QAASA,EACT,YAAaE,CACf,CACF,EACA,CAAC,EAEDE,GACJ,MAAM,KAAK,sBAAsB,0BAA0B,CACzD,cAAAL,EACA,QAASE,EACT,QAAAH,EACA,SAAAD,CACF,CAAC,GACD,OAAO,CACP,KAAOQ,GAA8B,CACnC,CACE,KAAM,uBAAqB,MAC3B,MAAAA,CACF,CACF,EACA,MAAQC,GAAiCA,CAC3C,CAAC,EAED,MAAO,CAAC,GAAGH,EAA0B,GAAGC,CAAmB,CAC7D,CACF,EAvGab,EAANgB,EAAA,IADN,cAAW,EAGPC,EAAA,eAAO,mBAAiB,qBAAqB,GAI7CA,EAAA,eAAO,WAAS,oBAAoB,IAN5BjB",
6
+ "names": ["TransactionContextLoader_exports", "__export", "TransactionContextLoader", "__toCommonJS", "import_device_management_kit", "import_inversify", "import_pkiTypes", "import_KeyId", "import_KeyUsage", "import_ClearSignContext", "import_transactionTypes", "TransactionContextLoader", "transactionDataSource", "certificateLoader", "ctx", "to", "data", "selector", "chainId", "deviceModelId", "proxyDelegateCallDescriptor", "resolvedAddress", "certificate", "proxyDelegateCallContext", "transactionContexts", "error", "contexts", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var n=require("purify-ts"),o=require("../../shared/model/ClearSignContext"),s=require("../../transaction/domain/TransactionContextLoader");describe("TransactionContextLoader",()=>{const r=vi.fn(),c={getTransactionDescriptors:r},e=new s.TransactionContextLoader(c);beforeEach(()=>{vi.clearAllMocks()}),it("should return an empty array if no destination address is provided",async()=>{const a={},t=await e.load(a);expect(t).toEqual([])}),it("should return an empty array if no data provided",async()=>{const a={to:"0x0",data:"0x"},t=await e.load(a);expect(t).toEqual([])}),it("should return an error if selector is invalid",async()=>{const a={to:"0x7",chainId:3,data:"0xzf68b302000000000000000000000000000000000000000000000000000000000002"},t=await e.load(a);expect(t).toEqual([{type:o.ClearSignContextType.ERROR,error:new Error("Invalid selector")}])}),it("should return an error if data source fails",async()=>{r.mockResolvedValue((0,n.Left)(new Error("data source error")));const a={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await e.load(a);expect(r).toHaveBeenCalledWith({address:"0x7",chainId:3,selector:"0xaf68b302"}),expect(t).toEqual([{type:o.ClearSignContextType.ERROR,error:new Error("data source error")}])}),it("should return the contexts on success",async()=>{r.mockResolvedValue((0,n.Right)([{type:o.ClearSignContextType.TRANSACTION_INFO,payload:"1234567890"},{type:o.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}]));const a={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await e.load(a);expect(t).toEqual([{type:o.ClearSignContextType.TRANSACTION_INFO,payload:"1234567890"},{type:o.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])})});
1
+ "use strict";var o=require("purify-ts"),e=require("../../shared/model/ClearSignContext"),c=require("../../transaction/domain/TransactionContextLoader");describe("TransactionContextLoader",()=>{const s=vi.fn(),n=vi.fn(),d={getTransactionDescriptors:s},i={loadCertificate:vi.fn()},r=new c.TransactionContextLoader(d,i);beforeEach(()=>{vi.resetAllMocks()}),it("should return an empty array if no destination address is provided",async()=>{const a={},t=await r.load(a);expect(t).toEqual([])}),it("should return an empty array if no data provided",async()=>{const a={to:"0x0",data:"0x"},t=await r.load(a);expect(t).toEqual([])}),it("should return an error if selector is invalid",async()=>{const a={to:"0x7",chainId:3,data:"0xzf68b302000000000000000000000000000000000000000000000000000000000002"},t=await r.load(a);expect(t).toEqual([{type:e.ClearSignContextType.ERROR,error:new Error("Invalid selector")}])}),it("should return an error if data source fails",async()=>{n.mockResolvedValue((0,o.Left)(new Error("data source error"))),s.mockResolvedValue((0,o.Left)(new Error("data source error")));const a={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await r.load(a);expect(s).toHaveBeenCalledWith({address:"0x7",chainId:3,selector:"0xaf68b302"}),expect(t).toEqual([{type:e.ClearSignContextType.ERROR,error:new Error("data source error")}])}),it("should return the contexts on success",async()=>{s.mockResolvedValue((0,o.Right)([{type:e.ClearSignContextType.TRANSACTION_INFO,payload:"1234567890"},{type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),n.mockResolvedValue((0,o.Left)(new Error("data source error")));const a={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await r.load(a);expect(t).toEqual([{type:e.ClearSignContextType.TRANSACTION_INFO,payload:"1234567890"},{type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])}),it("should return the proxy delegate call context on success",async()=>{s.mockResolvedValue((0,o.Right)([{type:e.ClearSignContextType.TRANSACTION_INFO,payload:"1234567890"},{type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),n.mockResolvedValue((0,o.Right)({delegateAddresses:["0x7"],signedDescriptor:"0x1234567890abcdef"}));const a={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await r.load(a);expect(t).toEqual([{type:e.ClearSignContextType.TRANSACTION_INFO,payload:"1234567890"},{type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])}),it("should return the proxy delegate call context if the transaction.to is in the delegate addresses and the transaction.to is not the first element",async()=>{s.mockResolvedValue((0,o.Right)([{type:e.ClearSignContextType.TRANSACTION_INFO,payload:"1234567890"},{type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),n.mockResolvedValue((0,o.Right)({delegateAddresses:["0x7","0x8"],signedDescriptor:"0x1234567890abcdef"}));const a={to:"0x8",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await r.load(a);expect(t).toEqual([{type:e.ClearSignContextType.TRANSACTION_INFO,payload:"1234567890"},{type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])}),it("should return the proxy delegate call context if the transaction.to is not in the delegate addresses",async()=>{s.mockResolvedValue((0,o.Right)([{type:e.ClearSignContextType.TRANSACTION_INFO,payload:"1234567890"},{type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),n.mockResolvedValue((0,o.Right)({delegateAddresses:["0x8"],signedDescriptor:"0x1234567890abcdef"}));const a={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await r.load(a);expect(t).toEqual([{type:e.ClearSignContextType.TRANSACTION_INFO,payload:"1234567890"},{type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])})});
2
2
  //# sourceMappingURL=TransactionContextLoader.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/transaction/domain/TransactionContextLoader.test.ts"],
4
- "sourcesContent": ["import { Left, Right } from \"purify-ts\";\n\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport type { TransactionContext } from \"@/shared/model/TransactionContext\";\nimport type { TransactionDataSource } from \"@/transaction/data/TransactionDataSource\";\nimport { TransactionContextLoader } from \"@/transaction/domain/TransactionContextLoader\";\n\ndescribe(\"TransactionContextLoader\", () => {\n const getTransactionDescriptorsMock = vi.fn();\n const mockTransactionDataSource: TransactionDataSource = {\n getTransactionDescriptors: getTransactionDescriptorsMock,\n };\n const loader = new TransactionContextLoader(mockTransactionDataSource);\n\n beforeEach(() => {\n vi.clearAllMocks();\n });\n\n it(\"should return an empty array if no destination address is provided\", async () => {\n // GIVEN\n const transaction = {} as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if no data provided\", async () => {\n // GIVEN\n const transaction = { to: \"0x0\", data: \"0x\" } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an error if selector is invalid\", async () => {\n // GIVEN\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xzf68b302000000000000000000000000000000000000000000000000000000000002\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Invalid selector\"),\n },\n ]);\n });\n\n it(\"should return an error if data source fails\", async () => {\n // GIVEN\n getTransactionDescriptorsMock.mockResolvedValue(\n Left(new Error(\"data source error\")),\n );\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(getTransactionDescriptorsMock).toHaveBeenCalledWith({\n address: \"0x7\",\n chainId: 3,\n selector: \"0xaf68b302\",\n });\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"data source error\"),\n },\n ]);\n });\n\n it(\"should return the contexts on success\", async () => {\n // GIVEN\n getTransactionDescriptorsMock.mockResolvedValue(\n Right([\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]),\n );\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]);\n });\n});\n"],
5
- "mappings": "aAAA,IAAAA,EAA4B,qB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SAAM,CACJ,CACE,KAAM,uBAAqB,iBAC3B,QAAS,YACX,EACA,CACE,KAAM,uBAAqB,8BAC3B,QAAS,UACX,CACF,CAAC,CACH,EACA,MAAMG,EAAc,CAClB,GAAI,MACJ,QAAS,EACT,KAAM,yEACN,SAAU,YACZ,EAGMC,EAAS,MAAMF,EAAO,KAAKC,CAAW,EAG5C,OAAOC,CAAM,EAAE,QAAQ,CACrB,CACE,KAAM,uBAAqB,iBAC3B,QAAS,YACX,EACA,CACE,KAAM,uBAAqB,8BAC3B,QAAS,UACX,CACF,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["import_purify_ts", "import_ClearSignContext", "import_TransactionContextLoader", "getTransactionDescriptorsMock", "mockTransactionDataSource", "loader", "transaction", "result"]
4
+ "sourcesContent": ["import { Left, Right } from \"purify-ts\";\n\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport type { TransactionContext } from \"@/shared/model/TransactionContext\";\nimport type { TransactionDataSource } from \"@/transaction/data/TransactionDataSource\";\nimport { TransactionContextLoader } from \"@/transaction/domain/TransactionContextLoader\";\n\ndescribe(\"TransactionContextLoader\", () => {\n const getTransactionDescriptorsMock = vi.fn();\n const getProxyDelegateCallMock = vi.fn();\n const mockTransactionDataSource: TransactionDataSource = {\n getTransactionDescriptors: getTransactionDescriptorsMock,\n };\n /* const mockProxyDatasource: ProxyDataSource = {\n getProxyDelegateCall: getProxyDelegateCallMock,\n getProxyImplementationAddress: vi.fn(),\n }; */\n const mockCertificateLoader: PkiCertificateLoader = {\n loadCertificate: vi.fn(),\n };\n const loader = new TransactionContextLoader(\n mockTransactionDataSource,\n //mockProxyDatasource,\n mockCertificateLoader,\n );\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n it(\"should return an empty array if no destination address is provided\", async () => {\n // GIVEN\n const transaction = {} as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if no data provided\", async () => {\n // GIVEN\n const transaction = { to: \"0x0\", data: \"0x\" } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an error if selector is invalid\", async () => {\n // GIVEN\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xzf68b302000000000000000000000000000000000000000000000000000000000002\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Invalid selector\"),\n },\n ]);\n });\n\n it(\"should return an error if data source fails\", async () => {\n // GIVEN\n getProxyDelegateCallMock.mockResolvedValue(\n Left(new Error(\"data source error\")),\n );\n getTransactionDescriptorsMock.mockResolvedValue(\n Left(new Error(\"data source error\")),\n );\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(getTransactionDescriptorsMock).toHaveBeenCalledWith({\n address: \"0x7\",\n chainId: 3,\n selector: \"0xaf68b302\",\n });\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"data source error\"),\n },\n ]);\n });\n\n it(\"should return the contexts on success\", async () => {\n // GIVEN\n getTransactionDescriptorsMock.mockResolvedValue(\n Right([\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]),\n );\n getProxyDelegateCallMock.mockResolvedValue(\n Left(new Error(\"data source error\")),\n );\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]);\n });\n\n it(\"should return the proxy delegate call context on success\", async () => {\n // GIVEN\n getTransactionDescriptorsMock.mockResolvedValue(\n Right([\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]),\n );\n getProxyDelegateCallMock.mockResolvedValue(\n Right({\n delegateAddresses: [\"0x7\"],\n signedDescriptor: \"0x1234567890abcdef\",\n }),\n );\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n /* TODO reenable when proxy is enabled\n {\n type: ClearSignContextType.PROXY_DELEGATE_CALL,\n payload: \"0x1234567890abcdef\",\n },*/\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]);\n });\n\n it(\"should return the proxy delegate call context if the transaction.to is in the delegate addresses and the transaction.to is not the first element\", async () => {\n // GIVEN\n getTransactionDescriptorsMock.mockResolvedValue(\n Right([\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]),\n );\n getProxyDelegateCallMock.mockResolvedValue(\n Right({\n delegateAddresses: [\"0x7\", \"0x8\"],\n signedDescriptor: \"0x1234567890abcdef\",\n }),\n );\n const transaction = {\n to: \"0x8\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n /* TODO reenable when proxy is enabled\n {\n type: ClearSignContextType.PROXY_DELEGATE_CALL,\n payload: \"0x1234567890abcdef\",\n },*/\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]);\n });\n\n it(\"should return the proxy delegate call context if the transaction.to is not in the delegate addresses\", async () => {\n // GIVEN\n getTransactionDescriptorsMock.mockResolvedValue(\n Right([\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]),\n );\n getProxyDelegateCallMock.mockResolvedValue(\n Right({\n delegateAddresses: [\"0x8\"],\n signedDescriptor: \"0x1234567890abcdef\",\n }),\n );\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n /* TODO reenable when proxy is enabled\n {\n type: ClearSignContextType.PROXY_DELEGATE_CALL,\n payload: \"0x1234567890abcdef\",\n },*/\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]);\n });\n});\n"],
5
+ "mappings": "aAAA,IAAAA,EAA4B,qBAG5BC,EAAqC,2CAGrCC,EAAyC,yDAEzC,SAAS,2BAA4B,IAAM,CACzC,MAAMC,EAAgC,GAAG,GAAG,EACtCC,EAA2B,GAAG,GAAG,EACjCC,EAAmD,CACvD,0BAA2BF,CAC7B,E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S,MAAMF,EAAO,KAAKC,CAAW,EAG5C,OAAOC,CAAM,EAAE,QAAQ,CAMrB,CACE,KAAM,uBAAqB,iBAC3B,QAAS,YACX,EACA,CACE,KAAM,uBAAqB,8BAC3B,QAAS,UACX,CACF,CAAC,CACH,CAAC,EAED,GAAG,uGAAwG,SAAY,CAErHN,EAA8B,qBAC5B,SAAM,CACJ,CACE,KAAM,uBAAqB,iBAC3B,QAAS,YACX,EACA,CACE,KAAM,uBAAqB,8BAC3B,QAAS,UACX,CACF,CAAC,CACH,EACAC,EAAyB,qBACvB,SAAM,CACJ,kBAAmB,CAAC,KAAK,EACzB,iBAAkB,oBACpB,CAAC,CACH,EACA,MAAMI,EAAc,CAClB,GAAI,MACJ,QAAS,EACT,KAAM,yEACN,SAAU,YACZ,EAGMC,EAAS,MAAMF,EAAO,KAAKC,CAAW,EAG5C,OAAOC,CAAM,EAAE,QAAQ,CAMrB,CACE,KAAM,uBAAqB,iBAC3B,QAAS,YACX,EACA,CACE,KAAM,uBAAqB,8BAC3B,QAAS,UACX,CACF,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["import_purify_ts", "import_ClearSignContext", "import_TransactionContextLoader", "getTransactionDescriptorsMock", "getProxyDelegateCallMock", "mockTransactionDataSource", "mockCertificateLoader", "loader", "transaction", "result"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var x=Object.create;var c=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,P=Object.prototype.hasOwnProperty;var I=(o,e)=>{for(var t in e)c(o,t,{get:e[t],enumerable:!0})},D=(o,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of G(e))!P.call(o,r)&&r!==t&&c(o,r,{get:()=>e[r],enumerable:!(a=E(e,r))||a.enumerable});return o};var N=(o,e,t)=>(t=o!=null?x(_(o)):{},D(e||!o||!o.__esModule?c(t,"default",{value:o,enumerable:!0}):t,o)),v=o=>D(c({},"__esModule",{value:!0}),o),T=(o,e,t,a)=>{for(var r=a>1?void 0:a?E(e,t):e,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(a?s(e,t,r):s(r))||r);return a&&r&&c(e,t,r),r},$=(o,e)=>(t,a)=>e(t,a,o);var w={};I(w,{HttpTrustedNameDataSource:()=>u});module.exports=v(w);var f=N(require("axios")),g=require("inversify"),n=require("purify-ts"),y=require("../../config/di/configTypes"),m=require("../../shared/constant/HttpHeaders"),l=N(require("../../../package.json"));let u=class{constructor(e){this.config=e}async getDomainNamePayload({chainId:e,domain:t,challenge:a}){try{const s=await f.default.request({method:"GET",url:`${this.config.metadataService.url}/names/ethereum/${e}/forward/${t}?types=eoa&sources=ens&challenge=${a}`,headers:{[m.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${l.default.version}`,[m.LEDGER_ORIGIN_TOKEN_HEADER]:this.config.originToken}});return s.data.signedDescriptor?.data?(0,n.Right)(s.data.signedDescriptor.data):(0,n.Left)(new Error("[ContextModule] HttpTrustedNameDataSource: error getting domain payload"))}catch{return(0,n.Left)(new Error("[ContextModule] HttpTrustedNameDataSource: Failed to fetch domain name"))}}async getTrustedNamePayload({chainId:e,address:t,challenge:a,sources:r,types:i}){try{r=r.filter(h=>h==="ens"||h==="crypto_asset_list");const d=(await f.default.request({method:"GET",url:`${this.config.metadataService.url}/names/ethereum/${e}/reverse/${t}?types=${i.join(",")}&sources=${r.join(",")}&challenge=${a}`,headers:{[m.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${l.default.version}`,[m.LEDGER_ORIGIN_TOKEN_HEADER]:this.config.originToken}})).data;if(!d?.signedDescriptor?.data)return(0,n.Left)(new Error(`[ContextModule] HttpTrustedNameDataSource: no trusted name metadata for address ${t}`));const p=d.signedDescriptor.data;if(!d.signedDescriptor.signatures||typeof d.signedDescriptor.signatures[this.config.cal.mode]!="string")return(0,n.Right)(p);const C=d.signedDescriptor.signatures[this.config.cal.mode];return(0,n.Right)(this.formatTrustedName(p,C))}catch{return(0,n.Left)(new Error("[ContextModule] HttpTrustedNameDataSource: Failed to fetch trusted name"))}}formatTrustedName(e,t){t.length%2!==0&&(t="0"+t);const a="15",r=(t.length/2).toString(16);return`${e}${a}${r}${t}`}};u=T([(0,g.injectable)(),$(0,(0,g.inject)(y.configTypes.Config))],u);0&&(module.exports={HttpTrustedNameDataSource});
1
+ "use strict";var x=Object.create;var c=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty;var P=(o,e)=>{for(var t in e)c(o,t,{get:e[t],enumerable:!0})},D=(o,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of G(e))!v.call(o,r)&&r!==t&&c(o,r,{get:()=>e[r],enumerable:!(a=E(e,r))||a.enumerable});return o};var N=(o,e,t)=>(t=o!=null?x(_(o)):{},D(e||!o||!o.__esModule?c(t,"default",{value:o,enumerable:!0}):t,o)),I=o=>D(c({},"__esModule",{value:!0}),o),T=(o,e,t,a)=>{for(var r=a>1?void 0:a?E(e,t):e,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(a?s(e,t,r):s(r))||r);return a&&r&&c(e,t,r),r},$=(o,e)=>(t,a)=>e(t,a,o);var w={};P(w,{HttpTrustedNameDataSource:()=>u});module.exports=I(w);var f=N(require("axios")),g=require("inversify"),n=require("purify-ts"),y=require("../../config/di/configTypes"),m=require("../../shared/constant/HttpHeaders"),l=N(require("../../../package.json"));let u=class{constructor(e){this.config=e}async getDomainNamePayload({chainId:e,domain:t,challenge:a}){try{const s=await f.default.request({method:"GET",url:`${this.config.metadataServiceDomain.url}/v2/names/ethereum/${e}/forward/${t}?types=eoa&sources=ens&challenge=${a}`,headers:{[m.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${l.default.version}`,[m.LEDGER_ORIGIN_TOKEN_HEADER]:this.config.originToken}});return s.data.signedDescriptor?.data?(0,n.Right)(s.data.signedDescriptor.data):(0,n.Left)(new Error("[ContextModule] HttpTrustedNameDataSource: error getting domain payload"))}catch{return(0,n.Left)(new Error("[ContextModule] HttpTrustedNameDataSource: Failed to fetch domain name"))}}async getTrustedNamePayload({chainId:e,address:t,challenge:a,sources:r,types:i}){try{r=r.filter(h=>h==="ens"||h==="crypto_asset_list");const d=(await f.default.request({method:"GET",url:`${this.config.metadataServiceDomain.url}/v2/names/ethereum/${e}/reverse/${t}?types=${i.join(",")}&sources=${r.join(",")}&challenge=${a}`,headers:{[m.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${l.default.version}`,[m.LEDGER_ORIGIN_TOKEN_HEADER]:this.config.originToken}})).data;if(!d?.signedDescriptor?.data)return(0,n.Left)(new Error(`[ContextModule] HttpTrustedNameDataSource: no trusted name metadata for address ${t}`));const p=d.signedDescriptor.data;if(!d.signedDescriptor.signatures||typeof d.signedDescriptor.signatures[this.config.cal.mode]!="string")return(0,n.Right)(p);const C=d.signedDescriptor.signatures[this.config.cal.mode];return(0,n.Right)(this.formatTrustedName(p,C))}catch{return(0,n.Left)(new Error("[ContextModule] HttpTrustedNameDataSource: Failed to fetch trusted name"))}}formatTrustedName(e,t){t.length%2!==0&&(t="0"+t);const a="15",r=(t.length/2).toString(16);return`${e}${a}${r}${t}`}};u=T([(0,g.injectable)(),$(0,(0,g.inject)(y.configTypes.Config))],u);0&&(module.exports={HttpTrustedNameDataSource});
2
2
  //# sourceMappingURL=HttpTrustedNameDataSource.js.map