@ledgerhq/context-module 0.0.0-multisig-2-20250922095845 → 0.0.0-multisig-20250925175241

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 (174) hide show
  1. package/lib/cjs/src/ContextModule.js +1 -1
  2. package/lib/cjs/src/ContextModule.js.map +1 -1
  3. package/lib/cjs/src/ContextModuleBuilder.test.js +1 -1
  4. package/lib/cjs/src/ContextModuleBuilder.test.js.map +2 -2
  5. package/lib/cjs/src/DefaultContextModule.js +1 -1
  6. package/lib/cjs/src/DefaultContextModule.js.map +3 -3
  7. package/lib/cjs/src/DefaultContextModule.test.js +1 -1
  8. package/lib/cjs/src/DefaultContextModule.test.js.map +3 -3
  9. package/lib/cjs/src/calldata/data/HttpCalldataDescriptorDataSource.js +1 -1
  10. package/lib/cjs/src/calldata/data/HttpCalldataDescriptorDataSource.js.map +3 -3
  11. package/lib/cjs/src/calldata/domain/CalldataContextLoader.js +1 -1
  12. package/lib/cjs/src/calldata/domain/CalldataContextLoader.js.map +3 -3
  13. package/lib/cjs/src/calldata/domain/CalldataContextLoader.test.js +1 -1
  14. package/lib/cjs/src/calldata/domain/CalldataContextLoader.test.js.map +3 -3
  15. package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.js +1 -1
  16. package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.js.map +3 -3
  17. package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js +1 -1
  18. package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js.map +3 -3
  19. package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.js +1 -1
  20. package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.js.map +3 -3
  21. package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.test.js +1 -1
  22. package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.test.js.map +3 -3
  23. package/lib/cjs/src/index.js +1 -1
  24. package/lib/cjs/src/index.js.map +2 -2
  25. package/lib/cjs/src/nft/domain/NftContextLoader.js +1 -1
  26. package/lib/cjs/src/nft/domain/NftContextLoader.js.map +3 -3
  27. package/lib/cjs/src/nft/domain/NftContextLoader.test.js +1 -1
  28. package/lib/cjs/src/nft/domain/NftContextLoader.test.js.map +3 -3
  29. package/lib/cjs/src/pki/model/PkiCertificateInfo.js +1 -1
  30. package/lib/cjs/src/pki/model/PkiCertificateInfo.js.map +1 -1
  31. package/lib/cjs/src/proxy/data/HttpProxyDataSource.js +1 -1
  32. package/lib/cjs/src/proxy/data/HttpProxyDataSource.js.map +3 -3
  33. package/lib/cjs/src/proxy/data/HttpProxyDataSource.test.js +1 -1
  34. package/lib/cjs/src/proxy/data/HttpProxyDataSource.test.js.map +3 -3
  35. package/lib/cjs/src/proxy/data/HttpSafeProxyDataSource.js +1 -1
  36. package/lib/cjs/src/proxy/data/HttpSafeProxyDataSource.js.map +2 -2
  37. package/lib/cjs/src/proxy/data/HttpSafeProxyDataSource.test.js +1 -1
  38. package/lib/cjs/src/proxy/data/HttpSafeProxyDataSource.test.js.map +2 -2
  39. package/lib/cjs/src/proxy/data/ProxyDataSource.js +1 -1
  40. package/lib/cjs/src/proxy/data/ProxyDataSource.js.map +1 -1
  41. package/lib/cjs/src/proxy/data/dto/SafeProxyImplementationAddressDto.js +1 -1
  42. package/lib/cjs/src/proxy/data/dto/SafeProxyImplementationAddressDto.js.map +1 -1
  43. package/lib/cjs/src/proxy/domain/ProxyContextFieldLoader.js +1 -1
  44. package/lib/cjs/src/proxy/domain/ProxyContextFieldLoader.js.map +3 -3
  45. package/lib/cjs/src/proxy/domain/ProxyContextFieldLoader.test.js +1 -1
  46. package/lib/cjs/src/proxy/domain/ProxyContextFieldLoader.test.js.map +2 -2
  47. package/lib/cjs/src/proxy/model/ProxyDelegateCall.js +1 -1
  48. package/lib/cjs/src/proxy/model/ProxyDelegateCall.js.map +1 -1
  49. package/lib/cjs/src/shared/domain/ContextLoader.js +1 -1
  50. package/lib/cjs/src/shared/domain/ContextLoader.js.map +1 -1
  51. package/lib/cjs/src/shared/utils/KeyUsageMapper.js +1 -1
  52. package/lib/cjs/src/shared/utils/KeyUsageMapper.js.map +2 -2
  53. package/lib/cjs/src/token/domain/TokenContextLoader.js +1 -1
  54. package/lib/cjs/src/token/domain/TokenContextLoader.js.map +3 -3
  55. package/lib/cjs/src/token/domain/TokenContextLoader.test.js +1 -1
  56. package/lib/cjs/src/token/domain/TokenContextLoader.test.js.map +3 -3
  57. package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.js +1 -1
  58. package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.js.map +3 -3
  59. package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.test.js +1 -1
  60. package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.test.js.map +3 -3
  61. package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.js +1 -1
  62. package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.js.map +2 -2
  63. package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.js +1 -1
  64. package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.js.map +3 -3
  65. package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.test.js +1 -1
  66. package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.test.js.map +2 -2
  67. package/lib/cjs/src/uniswap/domain/UniswapContextLoader.js +1 -1
  68. package/lib/cjs/src/uniswap/domain/UniswapContextLoader.js.map +3 -3
  69. package/lib/cjs/src/uniswap/domain/UniswapContextLoader.test.js +1 -1
  70. package/lib/cjs/src/uniswap/domain/UniswapContextLoader.test.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 +3 -3
  77. package/lib/esm/src/calldata/data/HttpCalldataDescriptorDataSource.js +1 -1
  78. package/lib/esm/src/calldata/data/HttpCalldataDescriptorDataSource.js.map +3 -3
  79. package/lib/esm/src/calldata/domain/CalldataContextLoader.js +1 -1
  80. package/lib/esm/src/calldata/domain/CalldataContextLoader.js.map +3 -3
  81. package/lib/esm/src/calldata/domain/CalldataContextLoader.test.js +1 -1
  82. package/lib/esm/src/calldata/domain/CalldataContextLoader.test.js.map +3 -3
  83. package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.js +1 -1
  84. package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.js.map +3 -3
  85. package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js +1 -1
  86. package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js.map +3 -3
  87. package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.js +1 -1
  88. package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.js.map +3 -3
  89. package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.test.js +1 -1
  90. package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.test.js.map +3 -3
  91. package/lib/esm/src/index.js +1 -1
  92. package/lib/esm/src/index.js.map +2 -2
  93. package/lib/esm/src/nft/domain/NftContextLoader.js +1 -1
  94. package/lib/esm/src/nft/domain/NftContextLoader.js.map +3 -3
  95. package/lib/esm/src/nft/domain/NftContextLoader.test.js +1 -1
  96. package/lib/esm/src/nft/domain/NftContextLoader.test.js.map +3 -3
  97. package/lib/esm/src/proxy/data/HttpProxyDataSource.js +1 -1
  98. package/lib/esm/src/proxy/data/HttpProxyDataSource.js.map +3 -3
  99. package/lib/esm/src/proxy/data/HttpProxyDataSource.test.js +1 -1
  100. package/lib/esm/src/proxy/data/HttpProxyDataSource.test.js.map +3 -3
  101. package/lib/esm/src/proxy/data/HttpSafeProxyDataSource.js +1 -1
  102. package/lib/esm/src/proxy/data/HttpSafeProxyDataSource.js.map +2 -2
  103. package/lib/esm/src/proxy/data/HttpSafeProxyDataSource.test.js +1 -1
  104. package/lib/esm/src/proxy/data/HttpSafeProxyDataSource.test.js.map +2 -2
  105. package/lib/esm/src/proxy/domain/ProxyContextFieldLoader.js +1 -1
  106. package/lib/esm/src/proxy/domain/ProxyContextFieldLoader.js.map +3 -3
  107. package/lib/esm/src/proxy/domain/ProxyContextFieldLoader.test.js +1 -1
  108. package/lib/esm/src/proxy/domain/ProxyContextFieldLoader.test.js.map +2 -2
  109. package/lib/esm/src/shared/utils/KeyUsageMapper.js +1 -1
  110. package/lib/esm/src/shared/utils/KeyUsageMapper.js.map +2 -2
  111. package/lib/esm/src/token/domain/TokenContextLoader.js +1 -1
  112. package/lib/esm/src/token/domain/TokenContextLoader.js.map +3 -3
  113. package/lib/esm/src/token/domain/TokenContextLoader.test.js +1 -1
  114. package/lib/esm/src/token/domain/TokenContextLoader.test.js.map +3 -3
  115. package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.js +1 -1
  116. package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.js.map +3 -3
  117. package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.test.js +1 -1
  118. package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.test.js.map +3 -3
  119. package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.js +1 -1
  120. package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.js.map +2 -2
  121. package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.js +1 -1
  122. package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.js.map +3 -3
  123. package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.test.js +1 -1
  124. package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.test.js.map +2 -2
  125. package/lib/esm/src/uniswap/domain/UniswapContextLoader.js +1 -1
  126. package/lib/esm/src/uniswap/domain/UniswapContextLoader.js.map +3 -3
  127. package/lib/esm/src/uniswap/domain/UniswapContextLoader.test.js +1 -1
  128. package/lib/esm/src/uniswap/domain/UniswapContextLoader.test.js.map +3 -3
  129. package/lib/types/src/ContextModule.d.ts +1 -2
  130. package/lib/types/src/ContextModule.d.ts.map +1 -1
  131. package/lib/types/src/DefaultContextModule.d.ts +1 -2
  132. package/lib/types/src/DefaultContextModule.d.ts.map +1 -1
  133. package/lib/types/src/calldata/data/HttpCalldataDescriptorDataSource.d.ts.map +1 -1
  134. package/lib/types/src/calldata/domain/CalldataContextLoader.d.ts +12 -4
  135. package/lib/types/src/calldata/domain/CalldataContextLoader.d.ts.map +1 -1
  136. package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.d.ts +9 -4
  137. package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.d.ts.map +1 -1
  138. package/lib/types/src/external-plugin/domain/ExternalPluginContextLoader.d.ts +11 -4
  139. package/lib/types/src/external-plugin/domain/ExternalPluginContextLoader.d.ts.map +1 -1
  140. package/lib/types/src/index.d.ts +0 -1
  141. package/lib/types/src/index.d.ts.map +1 -1
  142. package/lib/types/src/nft/domain/NftContextLoader.d.ts +10 -4
  143. package/lib/types/src/nft/domain/NftContextLoader.d.ts.map +1 -1
  144. package/lib/types/src/pki/model/PkiCertificateInfo.d.ts +1 -2
  145. package/lib/types/src/pki/model/PkiCertificateInfo.d.ts.map +1 -1
  146. package/lib/types/src/proxy/data/HttpProxyDataSource.d.ts.map +1 -1
  147. package/lib/types/src/proxy/data/HttpSafeProxyDataSource.d.ts.map +1 -1
  148. package/lib/types/src/proxy/data/ProxyDataSource.d.ts +2 -0
  149. package/lib/types/src/proxy/data/ProxyDataSource.d.ts.map +1 -1
  150. package/lib/types/src/proxy/data/dto/SafeProxyImplementationAddressDto.d.ts +2 -0
  151. package/lib/types/src/proxy/data/dto/SafeProxyImplementationAddressDto.d.ts.map +1 -1
  152. package/lib/types/src/proxy/domain/ProxyContextFieldLoader.d.ts.map +1 -1
  153. package/lib/types/src/proxy/model/ProxyDelegateCall.d.ts +2 -0
  154. package/lib/types/src/proxy/model/ProxyDelegateCall.d.ts.map +1 -1
  155. package/lib/types/src/shared/domain/ContextLoader.d.ts +13 -4
  156. package/lib/types/src/shared/domain/ContextLoader.d.ts.map +1 -1
  157. package/lib/types/src/shared/utils/KeyUsageMapper.d.ts +1 -2
  158. package/lib/types/src/shared/utils/KeyUsageMapper.d.ts.map +1 -1
  159. package/lib/types/src/token/domain/TokenContextLoader.d.ts +10 -4
  160. package/lib/types/src/token/domain/TokenContextLoader.d.ts.map +1 -1
  161. package/lib/types/src/trusted-name/domain/TrustedNameContextLoader.d.ts +9 -4
  162. package/lib/types/src/trusted-name/domain/TrustedNameContextLoader.d.ts.map +1 -1
  163. package/lib/types/src/typed-data/data/HttpTypedDataDataSource.d.ts.map +1 -1
  164. package/lib/types/src/typed-data/domain/DefaultTypedDataContextLoader.d.ts.map +1 -1
  165. package/lib/types/src/uniswap/domain/UniswapContextLoader.d.ts +11 -4
  166. package/lib/types/src/uniswap/domain/UniswapContextLoader.d.ts.map +1 -1
  167. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  168. package/package.json +6 -6
  169. package/lib/cjs/src/shared/model/TransactionContext.js +0 -2
  170. package/lib/cjs/src/shared/model/TransactionContext.js.map +0 -7
  171. package/lib/esm/src/shared/model/TransactionContext.js +0 -1
  172. package/lib/esm/src/shared/model/TransactionContext.js.map +0 -7
  173. package/lib/types/src/shared/model/TransactionContext.d.ts +0 -8
  174. package/lib/types/src/shared/model/TransactionContext.d.ts.map +0 -1
@@ -1,2 +1,2 @@
1
- "use strict";var d=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var v=(o,t)=>{for(var r in t)d(o,r,{get:t[r],enumerable:!0})},A=(o,t,r,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of P(t))!M.call(o,e)&&e!==r&&d(o,e,{get:()=>t[e],enumerable:!(a=S(t,e))||a.enumerable});return o};var I=o=>A(d({},"__esModule",{value:!0}),o),g=(o,t,r,a)=>{for(var e=a>1?void 0:a?S(t,r):t,s=o.length-1,n;s>=0;s--)(n=o[s])&&(e=(a?n(t,r,e):n(e))||e);return a&&e&&d(t,r,e),e},x=(o,t)=>(r,a)=>t(r,a,o);var b={};v(b,{CalldataContextLoader:()=>l});module.exports=I(b);var u=require("@ledgerhq/device-management-kit"),c=require("inversify"),C=require("purify-ts"),D=require("../../calldata/di/calldataTypes"),f=require("../../proxy/di/proxyTypes"),y=require("../../shared/model/ClearSignContext");let l=class{constructor(t,r,a){this.dappDataSource=t;this.tokenDataSource=r;this.proxyDataSource=a}async load(t){if(t.deviceModelId===u.DeviceModelId.NANO_S)return[];const{to:r,data:a,selector:e,chainId:s,deviceModelId:n}=t;if(r===void 0)return[];if(!(0,u.isHexaString)(e))return[{type:y.ClearSignContextType.ERROR,error:new Error("Invalid selector")}];const i={address:r,chainId:s,selector:e,deviceModelId:n,data:a};return this._getContexts(i,this.dappDataSource).alt(this._getContexts(i,this.tokenDataSource)).alt(this._getContextsWithProxy(i,this.dappDataSource)).orDefault([{type:y.ClearSignContextType.ERROR,error:new Error("[ContextModule] CalldataContextLoader: No calldata contexts found")}])}_getContexts({address:t,chainId:r,selector:a,deviceModelId:e},s){return(0,C.MaybeAsync)(async({liftMaybe:n})=>{const i=await s.getCalldataDescriptors({deviceModelId:e,address:t,chainId:r,selector:a});return n(i.toMaybe().filter(p=>p.length>0))})}_getContextsWithProxy({address:t,chainId:r,selector:a,deviceModelId:e,data:s},n){return(0,C.MaybeAsync)(async({liftMaybe:p})=>{const m=await this.proxyDataSource.getProxyImplementationAddress({calldata:s,proxyAddress:t,chainId:r,challenge:""});return p(m.toMaybe())}).map(({implementationAddress:p})=>{const m={address:p,chainId:r,selector:a,deviceModelId:e,data:s};return this._getContexts(m,n).map(h=>[{type:y.ClearSignContextType.PROXY_INFO,payload:"0x"},...h])}).join()}};l=g([(0,c.injectable)(),x(0,(0,c.inject)(D.calldataTypes.DappCalldataDescriptorDataSource)),x(1,(0,c.inject)(D.calldataTypes.TokenCalldataDescriptorDataSource)),x(2,(0,c.inject)(f.proxyTypes.ProxyDataSource))],l);0&&(module.exports={CalldataContextLoader});
1
+ "use strict";var C=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var f=(o,e)=>{for(var t in e)C(o,t,{get:e[t],enumerable:!0})},v=(o,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of M(e))!h.call(o,a)&&a!==t&&C(o,a,{get:()=>e[a],enumerable:!(r=u(e,a))||r.enumerable});return o};var A=o=>v(C({},"__esModule",{value:!0}),o),g=(o,e,t,r)=>{for(var a=r>1?void 0:r?u(e,t):e,n=o.length-1,s;n>=0;n--)(s=o[n])&&(a=(r?s(e,t,a):s(a))||a);return r&&a&&C(e,t,a),a},y=(o,e)=>(t,r)=>e(t,r,o);var _={};f(_,{CalldataContextLoader:()=>x});module.exports=A(_);var l=require("@ledgerhq/device-management-kit"),i=require("inversify"),D=require("purify-ts"),m=require("../../calldata/di/calldataTypes"),I=require("../../proxy/di/proxyTypes"),c=require("../../shared/model/ClearSignContext");const T=[c.ClearSignContextType.TRANSACTION_INFO,c.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,c.ClearSignContextType.PROXY_INFO,c.ClearSignContextType.ENUM];let x=class{constructor(e,t,r){this.dappDataSource=e;this.tokenDataSource=t;this.proxyDataSource=r}canHandle(e,t){return typeof e=="object"&&e!==null&&"to"in e&&"data"in e&&"selector"in e&&"chainId"in e&&"deviceModelId"in e&&e.deviceModelId!==void 0&&e.deviceModelId!==l.DeviceModelId.NANO_S&&typeof e.chainId=="number"&&(0,l.isHexaString)(e.to)&&e.to!=="0x"&&(0,l.isHexaString)(e.data)&&(0,l.isHexaString)(e.selector)&&e.selector!=="0x"&&T.every(r=>t.includes(r))}async load(e){const{to:t,data:r,selector:a,chainId:n,deviceModelId:s}=e,d={address:t,chainId:n,selector:a,deviceModelId:s,data:r};return this._getContexts(d,this.dappDataSource).alt(this._getContexts(d,this.tokenDataSource)).alt(this._getContextsWithProxy(d,this.dappDataSource)).orDefault([{type:c.ClearSignContextType.ERROR,error:new Error("[ContextModule] CalldataContextLoader: No calldata contexts found")}])}_getContexts({address:e,chainId:t,selector:r,deviceModelId:a},n){return(0,D.MaybeAsync)(async({liftMaybe:s})=>{const d=await n.getCalldataDescriptors({deviceModelId:a,address:e,chainId:t,selector:r});return s(d.toMaybe().filter(p=>p.length>0))})}_getContextsWithProxy({address:e,chainId:t,selector:r,deviceModelId:a,data:n},s){return(0,D.MaybeAsync)(async({liftMaybe:p})=>{const S=await this.proxyDataSource.getProxyImplementationAddress({calldata:n,proxyAddress:e,chainId:t,challenge:""});return p(S.toMaybe())}).map(({implementationAddress:p})=>{const S={address:p,chainId:t,selector:r,deviceModelId:a,data:n};return this._getContexts(S,s).map(P=>[{type:c.ClearSignContextType.PROXY_INFO,payload:"0x"},...P])}).join()}};x=g([(0,i.injectable)(),y(0,(0,i.inject)(m.calldataTypes.DappCalldataDescriptorDataSource)),y(1,(0,i.inject)(m.calldataTypes.TokenCalldataDescriptorDataSource)),y(2,(0,i.inject)(I.proxyTypes.ProxyDataSource))],x);0&&(module.exports={CalldataContextLoader});
2
2
  //# sourceMappingURL=CalldataContextLoader.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/calldata/domain/CalldataContextLoader.ts"],
4
- "sourcesContent": ["import {\n DeviceModelId,\n HexaString,\n isHexaString,\n} from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\nimport { MaybeAsync } from \"purify-ts\";\n\nimport type { CalldataDescriptorDataSource } from \"@/calldata/data/CalldataDescriptorDataSource\";\nimport { calldataTypes } from \"@/calldata/di/calldataTypes\";\nimport type { ProxyDataSource } from \"@/proxy/data/ProxyDataSource\";\nimport { proxyTypes } from \"@/proxy/di/proxyTypes\";\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { TransactionContext } from \"@/shared/model/TransactionContext\";\n\ntype GetContextsParams = {\n address: string;\n chainId: number;\n data: string;\n selector: HexaString;\n deviceModelId: DeviceModelId;\n};\n\n@injectable()\nexport class CalldataContextLoader implements ContextLoader {\n constructor(\n @inject(calldataTypes.DappCalldataDescriptorDataSource)\n private dappDataSource: CalldataDescriptorDataSource,\n @inject(calldataTypes.TokenCalldataDescriptorDataSource)\n private tokenDataSource: CalldataDescriptorDataSource,\n @inject(proxyTypes.ProxyDataSource)\n private proxyDataSource: ProxyDataSource,\n ) {}\n\n async load(ctx: TransactionContext): Promise<ClearSignContext[]> {\n if (ctx.deviceModelId === DeviceModelId.NANO_S) {\n return [];\n }\n\n const { to, data, selector, chainId, deviceModelId } = ctx;\n if (to === undefined) {\n return [];\n }\n\n if (!isHexaString(selector)) {\n return [\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Invalid selector\"),\n },\n ];\n }\n\n const param: GetContextsParams = {\n address: to,\n chainId,\n selector,\n deviceModelId,\n data,\n };\n\n return this._getContexts(param, this.dappDataSource)\n .alt(this._getContexts(param, this.tokenDataSource))\n .alt(this._getContextsWithProxy(param, this.dappDataSource))\n .orDefault([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\n \"[ContextModule] CalldataContextLoader: No calldata contexts found\",\n ),\n },\n ]);\n }\n\n private _getContexts(\n { address, chainId, selector, deviceModelId }: GetContextsParams,\n datasource: CalldataDescriptorDataSource,\n ): MaybeAsync<ClearSignContext[]> {\n return MaybeAsync(async ({ liftMaybe }) => {\n const result = await datasource.getCalldataDescriptors({\n deviceModelId,\n address,\n chainId,\n selector,\n });\n\n return liftMaybe(result.toMaybe().filter((ctxs) => ctxs.length > 0));\n });\n }\n\n private _getContextsWithProxy(\n { address, chainId, selector, deviceModelId, data }: GetContextsParams,\n datasource: CalldataDescriptorDataSource,\n ): MaybeAsync<ClearSignContext[]> {\n const proxyAddress = MaybeAsync(async ({ liftMaybe }) => {\n const result = await this.proxyDataSource.getProxyImplementationAddress({\n calldata: data,\n proxyAddress: address,\n chainId,\n challenge: \"\",\n });\n return liftMaybe(result.toMaybe());\n });\n\n return proxyAddress\n .map<MaybeAsync<ClearSignContext[]>>(({ implementationAddress }) => {\n const params = {\n address: implementationAddress,\n chainId,\n selector,\n deviceModelId,\n data,\n };\n return this._getContexts(params, datasource).map((contexts) => [\n // Add a proxy info context to the list of contexts\n // to specify that the proxy info should be refetched during the provide step\n {\n type: ClearSignContextType.PROXY_INFO,\n payload: \"0x\",\n },\n ...contexts,\n ]);\n })\n .join(); // join the two MaybeAsyncs\n }\n}\n"],
5
- "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,2BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAIO,2CACPC,EAAmC,qBACnCC,EAA2B,qBAG3BC,EAA8B,uCAE9BC,EAA2B,iCAE3BC,EAGO,2CAYA,IAAMC,EAAN,KAAqD,CAC1D,YAEUC,EAEAC,EAEAC,EACR,CALQ,oBAAAF,EAEA,qBAAAC,EAEA,qBAAAC,CACP,CAEH,MAAM,KAAKC,EAAsD,CAC/D,GAAIA,EAAI,gBAAkB,gBAAc,OACtC,MAAO,CAAC,EAGV,KAAM,CAAE,GAAAC,EAAI,KAAAC,EAAM,SAAAC,EAAU,QAAAC,EAAS,cAAAC,CAAc,EAAIL,EACvD,GAAIC,IAAO,OACT,MAAO,CAAC,EAGV,GAAI,IAAC,gBAAaE,CAAQ,EACxB,MAAO,CACL,CACE,KAAM,uBAAqB,MAC3B,MAAO,IAAI,MAAM,kBAAkB,CACrC,CACF,EAGF,MAAMG,EAA2B,CAC/B,QAASL,EACT,QAAAG,EACA,SAAAD,EACA,cAAAE,EACA,KAAAH,CACF,EAEA,OAAO,K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c,iCAAiC,GAEtDA,EAAA,eAAO,aAAW,eAAe,IANzBpB",
6
- "names": ["CalldataContextLoader_exports", "__export", "CalldataContextLoader", "__toCommonJS", "import_device_management_kit", "import_inversify", "import_purify_ts", "import_calldataTypes", "import_proxyTypes", "import_ClearSignContext", "CalldataContextLoader", "dappDataSource", "tokenDataSource", "proxyDataSource", "ctx", "to", "data", "selector", "chainId", "deviceModelId", "param", "address", "datasource", "liftMaybe", "result", "ctxs", "implementationAddress", "params", "contexts", "__decorateClass", "__decorateParam"]
4
+ "sourcesContent": ["import {\n DeviceModelId,\n HexaString,\n isHexaString,\n} from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\nimport { MaybeAsync } from \"purify-ts\";\n\nimport type { CalldataDescriptorDataSource } from \"@/calldata/data/CalldataDescriptorDataSource\";\nimport { calldataTypes } from \"@/calldata/di/calldataTypes\";\nimport type { ProxyDataSource } from \"@/proxy/data/ProxyDataSource\";\nimport { proxyTypes } from \"@/proxy/di/proxyTypes\";\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\n\nexport type CalldataContextInput = {\n to: HexaString;\n data: HexaString;\n selector: HexaString;\n chainId: number;\n deviceModelId: DeviceModelId;\n};\n\ntype GetContextsParams = {\n address: string;\n chainId: number;\n data: string;\n selector: HexaString;\n deviceModelId: DeviceModelId;\n};\n\nconst SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.TRANSACTION_INFO,\n ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n ClearSignContextType.PROXY_INFO,\n ClearSignContextType.ENUM,\n];\n\n@injectable()\nexport class CalldataContextLoader\n implements ContextLoader<CalldataContextInput>\n{\n constructor(\n @inject(calldataTypes.DappCalldataDescriptorDataSource)\n private dappDataSource: CalldataDescriptorDataSource,\n @inject(calldataTypes.TokenCalldataDescriptorDataSource)\n private tokenDataSource: CalldataDescriptorDataSource,\n @inject(proxyTypes.ProxyDataSource)\n private proxyDataSource: ProxyDataSource,\n ) {}\n\n canHandle(\n input: unknown,\n expectedTypes: ClearSignContextType[],\n ): input is CalldataContextInput {\n return (\n typeof input === \"object\" &&\n input !== null &&\n \"to\" in input &&\n \"data\" in input &&\n \"selector\" in input &&\n \"chainId\" in input &&\n \"deviceModelId\" in input &&\n input.deviceModelId !== undefined &&\n input.deviceModelId !== DeviceModelId.NANO_S &&\n typeof input.chainId === \"number\" &&\n isHexaString(input.to) &&\n input.to !== \"0x\" &&\n isHexaString(input.data) &&\n isHexaString(input.selector) &&\n input.selector !== \"0x\" &&\n SUPPORTED_TYPES.every((type) => expectedTypes.includes(type))\n );\n }\n\n async load(input: CalldataContextInput): Promise<ClearSignContext[]> {\n const { to, data, selector, chainId, deviceModelId } = input;\n\n const param: GetContextsParams = {\n address: to,\n chainId,\n selector,\n deviceModelId,\n data,\n };\n\n return this._getContexts(param, this.dappDataSource)\n .alt(this._getContexts(param, this.tokenDataSource))\n .alt(this._getContextsWithProxy(param, this.dappDataSource))\n .orDefault([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\n \"[ContextModule] CalldataContextLoader: No calldata contexts found\",\n ),\n },\n ]);\n }\n\n private _getContexts(\n { address, chainId, selector, deviceModelId }: GetContextsParams,\n datasource: CalldataDescriptorDataSource,\n ): MaybeAsync<ClearSignContext[]> {\n return MaybeAsync(async ({ liftMaybe }) => {\n const result = await datasource.getCalldataDescriptors({\n deviceModelId,\n address,\n chainId,\n selector,\n });\n\n return liftMaybe(result.toMaybe().filter((ctxs) => ctxs.length > 0));\n });\n }\n\n private _getContextsWithProxy(\n { address, chainId, selector, deviceModelId, data }: GetContextsParams,\n datasource: CalldataDescriptorDataSource,\n ): MaybeAsync<ClearSignContext[]> {\n const proxyAddress = MaybeAsync(async ({ liftMaybe }) => {\n const result = await this.proxyDataSource.getProxyImplementationAddress({\n calldata: data,\n proxyAddress: address,\n chainId,\n challenge: \"\",\n });\n return liftMaybe(result.toMaybe());\n });\n\n return proxyAddress\n .map<MaybeAsync<ClearSignContext[]>>(({ implementationAddress }) => {\n const params = {\n address: implementationAddress,\n chainId,\n selector,\n deviceModelId,\n data,\n };\n return this._getContexts(params, datasource).map((contexts) => [\n // Add a proxy info context to the list of contexts\n // to specify that the proxy info should be refetched during the provide step\n {\n type: ClearSignContextType.PROXY_INFO,\n payload: \"0x\",\n },\n ...contexts,\n ]);\n })\n .join(); // join the two MaybeAsyncs\n }\n}\n"],
5
+ "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,2BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAIO,2CACPC,EAAmC,qBACnCC,EAA2B,qBAG3BC,EAA8B,uCAE9BC,EAA2B,iCAE3BC,EAGO,2CAkBP,MAAMC,EAA0C,CAC9C,uBAAqB,iBACrB,uBAAqB,8BACrB,uBAAqB,WACrB,uBAAqB,IACvB,EAGO,IAAMC,EAAN,KAEP,CACE,YAEUC,EAEAC,EAEAC,EACR,CALQ,oBAAAF,EAEA,qBAAAC,EAEA,qBAAAC,CACP,CAEH,UACEC,EACAC,EAC+B,CAC/B,OACE,OAAOD,GAAU,UACjBA,IAAU,MACV,OAAQA,GACR,SAAUA,GACV,aAAcA,GACd,YAAaA,GACb,kBAAmBA,GACnBA,EAAM,gBAAkB,QACxBA,EAAM,gBAAkB,gBAAc,QACtC,OAAOA,EAAM,SAAY,aACzB,gBAAaA,EAAM,EAAE,GACrBA,EAAM,KAAO,SACb,gBAAaA,EAAM,IAAI,MACvB,gBAAaA,EAAM,QAAQ,GAC3BA,EAAM,WAAa,MACnBL,EAAgB,MAAOO,GAASD,EAAc,SAASC,CAAI,CAAC,CAEhE,CAEA,MAAM,KAAKF,EAA0D,CACnE,KAAM,CAAE,GAAAG,EAAI,KAAAC,EAAM,SAAAC,EAAU,QAAAC,EAAS,cAAAC,CAAc,EAAIP,EAEjDQ,EAA2B,CAC/B,QAASL,EACT,QAAAG,EACA,S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AA,eAAO,gBAAc,gCAAgC,GAErDA,EAAA,eAAO,gBAAc,iCAAiC,GAEtDA,EAAA,eAAO,aAAW,eAAe,IARzBtB",
6
+ "names": ["CalldataContextLoader_exports", "__export", "CalldataContextLoader", "__toCommonJS", "import_device_management_kit", "import_inversify", "import_purify_ts", "import_calldataTypes", "import_proxyTypes", "import_ClearSignContext", "SUPPORTED_TYPES", "CalldataContextLoader", "dappDataSource", "tokenDataSource", "proxyDataSource", "input", "expectedTypes", "type", "to", "data", "selector", "chainId", "deviceModelId", "param", "address", "datasource", "liftMaybe", "result", "ctxs", "implementationAddress", "params", "contexts", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var c=require("@ledgerhq/device-management-kit"),o=require("purify-ts"),d=require("../../calldata/domain/CalldataContextLoader"),t=require("../../shared/model/ClearSignContext");describe("CalldataContextLoader",()=>{const n=vi.fn(),r=vi.fn(),l=vi.fn(),i={getCalldataDescriptors:r},p={getCalldataDescriptors:l},x={getProxyImplementationAddress:n},s=new d.CalldataContextLoader(i,p,x);beforeEach(()=>{vi.resetAllMocks()}),it("should return an empty array if no destination address is provided",async()=>{const e={},a=await s.load(e);expect(a).toEqual([])}),it("should return an empty array if 'to' is undefined",async()=>{const e={to:void 0,data:"0x"},a=await s.load(e);expect(a).toEqual([])}),it("should return an error if selector is invalid",async()=>{const e={to:"0x7",chainId:3,data:"0xzf68b302000000000000000000000000000000000000000000000000000000000002"},a=await s.load(e);expect(a).toEqual([{type:t.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"))),r.mockResolvedValue((0,o.Left)(new Error("data source error")));const e={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},a=await s.load(e);expect(r).toHaveBeenCalledWith({address:"0x7",chainId:3,selector:"0xaf68b302"}),expect(a).toEqual([{type:t.ClearSignContextType.ERROR,error:new Error("[ContextModule] CalldataContextLoader: No calldata contexts found")}])}),it("should return the contexts on success",async()=>{r.mockResolvedValue((0,o.Right)([{type:t.ClearSignContextType.TRANSACTION_INFO,payload:"1234567890"},{type:t.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),n.mockResolvedValue((0,o.Left)(new Error("data source error")));const e={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},a=await s.load(e);expect(a).toEqual([{type:t.ClearSignContextType.TRANSACTION_INFO,payload:"1234567890"},{type:t.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])}),it("should return the proxy delegate call context on success",async()=>{r.mockResolvedValueOnce((0,o.Right)([])),r.mockResolvedValue((0,o.Right)([{type:t.ClearSignContextType.TRANSACTION_INFO,payload:"1234567890"},{type:t.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),n.mockResolvedValue((0,o.Right)({implementationAddress:"0x1234567890abcdef",signedDescriptor:"0x1234567890abcdef"}));const e={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},a=await s.load(e);expect(a).toEqual([{type:t.ClearSignContextType.PROXY_INFO,payload:"0x"},{type:t.ClearSignContextType.TRANSACTION_INFO,payload:"1234567890"},{type:t.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])}),it("should return an empty array if device model is NANO_S",async()=>{const e={deviceModelId:c.DeviceModelId.NANO_S,to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},a=await s.load(e);expect(a).toEqual([]),expect(r).not.toHaveBeenCalled(),expect(n).not.toHaveBeenCalled()}),it("should return an error when proxy delegate call succeeds but transaction descriptors for resolved address fail",async()=>{r.mockResolvedValueOnce((0,o.Right)([])),r.mockResolvedValueOnce((0,o.Left)(new Error("data source error"))),n.mockResolvedValue((0,o.Right)({implementationAddress:"0xResolvedAddress",signedDescriptor:"0x1234567890abcdef"}));const e={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},a=await s.load(e);expect(r).toHaveBeenCalledTimes(2),expect(r).toHaveBeenNthCalledWith(2,{address:"0xResolvedAddress",chainId:3,selector:"0xaf68b302"}),expect(a).toEqual([{type:t.ClearSignContextType.ERROR,error:new Error("[ContextModule] CalldataContextLoader: No calldata contexts found")}])})});
1
+ "use strict";var n=require("@ledgerhq/device-management-kit"),d=require("purify-ts"),i=require("../../calldata/domain/CalldataContextLoader"),a=require("../../shared/model/ClearSignContext");describe("CalldataContextLoader",()=>{const r=vi.fn(),l=vi.fn(),p=vi.fn(),u={getCalldataDescriptors:l},x={getCalldataDescriptors:p},I={getProxyImplementationAddress:r},o=new i.CalldataContextLoader(u,x,I),c=[a.ClearSignContextType.TRANSACTION_INFO,a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,a.ClearSignContextType.PROXY_INFO,a.ClearSignContextType.ENUM];beforeEach(()=>{vi.resetAllMocks()}),describe("canHandle function",()=>{const e={to:"0x1234567890123456789012345678901234567890",data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302",chainId:1,deviceModelId:n.DeviceModelId.NANO_X};it("should return true for valid input",()=>{expect(o.canHandle(e,c)).toBe(!0)}),it("should return false for invalid expected type",()=>{expect(o.canHandle(e,[a.ClearSignContextType.TOKEN])).toBe(!1),expect(o.canHandle(e,[a.ClearSignContextType.NFT])).toBe(!1),expect(o.canHandle(e,[a.ClearSignContextType.PROXY_INFO])).toBe(!1),expect(o.canHandle(e,[a.ClearSignContextType.ENUM])).toBe(!1),expect(o.canHandle(e,[a.ClearSignContextType.TRANSACTION_INFO])).toBe(!1)}),it.each([[null,"null input"],[void 0,"undefined input"],[{},"empty object"],["string","string input"],[123,"number input"]])("should return false for %s",(t,s)=>{expect(o.canHandle(t,c)).toBe(!1)}),it.each([[{...e,to:void 0},"missing to"],[{...e,data:void 0},"missing data"],[{...e,selector:void 0},"missing selector"],[{...e,chainId:void 0},"missing chainId"],[{...e,deviceModelId:void 0},"missing deviceModelId"]])("should return false for %s",(t,s)=>{expect(o.canHandle(t,c)).toBe(!1)}),it.each([[{...e,to:"invalid-hex"},"invalid to hex"],[{...e,to:"0x"},"empty to hex"],[{...e,data:"invalid-hex"},"invalid data hex"],[{...e,selector:"invalid-hex"},"invalid selector hex"],[{...e,selector:"0x"},"empty selector hex"]])("should return false for %s",(t,s)=>{expect(o.canHandle(t,c)).toBe(!1)}),it.each([[{...e,chainId:"1"},"string chainId"],[{...e,chainId:null},"null chainId"],[{...e,deviceModelId:n.DeviceModelId.NANO_S},"deviceModelId is NANO_S"]])("should return false for %s",(t,s)=>{expect(o.canHandle(t,c)).toBe(!1)})}),it("should return an error if data source fails",async()=>{r.mockResolvedValue((0,d.Left)(new Error("data source error"))),l.mockResolvedValue((0,d.Left)(new Error("data source error")));const e={to:"0x1234567890123456789012345678901234567890",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302",deviceModelId:n.DeviceModelId.NANO_X},t=await o.load(e);expect(l).toHaveBeenCalledWith({address:"0x1234567890123456789012345678901234567890",chainId:3,selector:"0xaf68b302",deviceModelId:n.DeviceModelId.NANO_X}),expect(t).toEqual([{type:a.ClearSignContextType.ERROR,error:new Error("[ContextModule] CalldataContextLoader: No calldata contexts found")}])}),it("should return the contexts on success",async()=>{l.mockResolvedValue((0,d.Right)([{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"1234567890"},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),r.mockResolvedValue((0,d.Left)(new Error("data source error")));const e={to:"0x1234567890123456789012345678901234567890",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302",deviceModelId:n.DeviceModelId.NANO_X},t=await o.load(e);expect(t).toEqual([{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"1234567890"},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])}),it("should return the proxy delegate call context on success",async()=>{l.mockResolvedValueOnce((0,d.Right)([])),l.mockResolvedValue((0,d.Right)([{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"1234567890"},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),r.mockResolvedValue((0,d.Right)({implementationAddress:"0x1234567890abcdef",signedDescriptor:"0x1234567890abcdef"}));const e={to:"0x1234567890123456789012345678901234567890",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302",deviceModelId:n.DeviceModelId.NANO_X},t=await o.load(e);expect(t).toEqual([{type:a.ClearSignContextType.PROXY_INFO,payload:"0x"},{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"1234567890"},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])}),it("should return an error when proxy delegate call succeeds but transaction descriptors for resolved address fail",async()=>{l.mockResolvedValueOnce((0,d.Right)([])),l.mockResolvedValueOnce((0,d.Left)(new Error("data source error"))),r.mockResolvedValue((0,d.Right)({implementationAddress:"0xResolvedAddress",signedDescriptor:"0x1234567890abcdef"}));const e={to:"0x1234567890123456789012345678901234567890",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302",deviceModelId:n.DeviceModelId.NANO_X},t=await o.load(e);expect(l).toHaveBeenCalledTimes(2),expect(l).toHaveBeenNthCalledWith(2,{address:"0xResolvedAddress",chainId:3,selector:"0xaf68b302",deviceModelId:n.DeviceModelId.NANO_X}),expect(t).toEqual([{type:a.ClearSignContextType.ERROR,error:new Error("[ContextModule] CalldataContextLoader: No calldata contexts found")}])})});
2
2
  //# sourceMappingURL=CalldataContextLoader.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/calldata/domain/CalldataContextLoader.test.ts"],
4
- "sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport type { CalldataDescriptorDataSource } from \"@/calldata/data/CalldataDescriptorDataSource\";\nimport { CalldataContextLoader } from \"@/calldata/domain/CalldataContextLoader\";\nimport type { ProxyDataSource } from \"@/proxy/data/ProxyDataSource\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport type { TransactionContext } from \"@/shared/model/TransactionContext\";\n\ndescribe(\"CalldataContextLoader\", () => {\n const getProxyImplementationAddress = vi.fn();\n const getDappDescriptorsMock = vi.fn();\n const getTokenDescriptorsMock = vi.fn();\n const mockDappDataSource: CalldataDescriptorDataSource = {\n getCalldataDescriptors: getDappDescriptorsMock,\n };\n const mockTokenDataSource: CalldataDescriptorDataSource = {\n getCalldataDescriptors: getTokenDescriptorsMock,\n };\n const mockProxyDatasource: ProxyDataSource = {\n getProxyImplementationAddress: getProxyImplementationAddress,\n };\n const loader = new CalldataContextLoader(\n mockDappDataSource,\n mockTokenDataSource,\n mockProxyDatasource,\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 'to' is undefined\", async () => {\n // GIVEN\n const transaction = { to: undefined, 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 getProxyImplementationAddress.mockResolvedValue(\n Left(new Error(\"data source error\")),\n );\n getDappDescriptorsMock.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(getDappDescriptorsMock).toHaveBeenCalledWith({\n address: \"0x7\",\n chainId: 3,\n selector: \"0xaf68b302\",\n });\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\n \"[ContextModule] CalldataContextLoader: No calldata contexts found\",\n ),\n },\n ]);\n });\n\n it(\"should return the contexts on success\", async () => {\n // GIVEN\n getDappDescriptorsMock.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 getProxyImplementationAddress.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 getDappDescriptorsMock.mockResolvedValueOnce(Right([])); // No transaction descriptors found for the first call\n getDappDescriptorsMock.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 getProxyImplementationAddress.mockResolvedValue(\n Right({\n implementationAddress: \"0x1234567890abcdef\",\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 {\n type: ClearSignContextType.PROXY_INFO,\n payload: \"0x\",\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 an empty array if device model is NANO_S\", async () => {\n // GIVEN\n const transaction = {\n deviceModelId: DeviceModelId.NANO_S,\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 expect(getDappDescriptorsMock).not.toHaveBeenCalled();\n expect(getProxyImplementationAddress).not.toHaveBeenCalled();\n });\n\n it(\"should return an error when proxy delegate call succeeds but transaction descriptors for resolved address fail\", async () => {\n // GIVEN\n getDappDescriptorsMock.mockResolvedValueOnce(Right([])); // No transaction descriptors found for the first call\n getDappDescriptorsMock.mockResolvedValueOnce(\n Left(new Error(\"data source error\")),\n ); // Second call fails\n getProxyImplementationAddress.mockResolvedValue(\n Right({\n implementationAddress: \"0xResolvedAddress\",\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(getDappDescriptorsMock).toHaveBeenCalledTimes(2);\n expect(getDappDescriptorsMock).toHaveBeenNthCalledWith(2, {\n address: \"0xResolvedAddress\",\n chainId: 3,\n selector: \"0xaf68b302\",\n });\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\n \"[ContextModule] CalldataContextLoader: No calldata contexts found\",\n ),\n },\n ]);\n });\n});\n"],
5
- "mappings": "aAAA,IAAAA,EAA8B,2CAC9BC,EAA4B,qBAG5BC,EAAsC,mDAEtCC,EAAqC,2CAGrC,SAAS,wBAAyB,IAAM,CACtC,MAAMC,EAAgC,GAAG,GAAG,EACtCC,EAAyB,GAAG,GAAG,EAC/BC,EAA0B,GAAG,GAAG,EAChCC,EAAmD,CACvD,uBAAwBF,CAC1B,EACMG,EAAoD,CACxD,uBAAwBF,CAC1B,EACMG,EAAuC,CAC3C,8BAA+BL,CACjC,EACMM,EAAS,IAAI,wBACjBH,EACAC,EACAC,CACF,EAEA,WAAW,IAAM,CACf,GAAG,cAAc,CACnB,CAAC,EAED,GAAG,qEAAsE,SAAY,CAEnF,MAAME,EAAc,CAAC,EAGfC,EAAS,MAAMF,EAAO,KAAKC,CAAW,EAG5C,OAAOC,CAAM,EAAE,QAAQ,CAAC,CAAC,CAC3B,CAAC,EAED,GAAG,oDAAqD,SAAY,CAElE,MAAMD,EAAc,CAAE,GAAI,OAAW,KAAM,IAAK,EAG1CC,EAAS,MAAMF,EAAO,KAAKC,CAAW,EAG5C,OAAOC,CAAM,EAAE,QAAQ,CAAC,CAAC,CAC3B,CAAC,EAED,GAAG,gDAAiD,SAAY,CAE9D,MAAMD,EAAc,CAClB,GAAI,MACJ,QAAS,EACT,KAAM,wEACR,EAGMC,EAAS,MAAMF,EAAO,KAAKC,CAAW,EAG5C,OAAOC,CAAM,EAAE,QAAQ,CACrB,CACE,KAAM,uBAAqB,MAC3B,MAAO,IAAI,MAAM,kBAAkB,CACrC,CACF,CAAC,CACH,CAAC,EAED,GA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QAAS,EACT,KAAM,yEACN,SAAU,YACZ,EAGMC,EAAS,MAAMF,EAAO,KAAKC,CAAW,EAG5C,OAAOC,CAAM,EAAE,QAAQ,CACrB,CACE,KAAM,uBAAqB,WAC3B,QAAS,IACX,EACA,CACE,KAAM,uBAAqB,iBAC3B,QAAS,YACX,EACA,CACE,KAAM,uBAAqB,8BAC3B,QAAS,UACX,CACF,CAAC,CACH,CAAC,EAED,GAAG,yDAA0D,SAAY,CAEvE,MAAMD,EAAc,CAClB,cAAe,gBAAc,OAC7B,GAAI,MACJ,QAAS,EACT,KAAM,yEACN,SAAU,YACZ,EAGMC,EAAS,MAAMF,EAAO,KAAKC,CAAW,EAG5C,OAAOC,CAAM,EAAE,QAAQ,CAAC,CAAC,EACzB,OAAOP,CAAsB,EAAE,IAAI,iBAAiB,EACpD,OAAOD,CAA6B,EAAE,IAAI,iBAAiB,CAC7D,CAAC,EAED,GAAG,iHAAkH,SAAY,CAE/HC,EAAuB,yBAAsB,SAAM,CAAC,CAAC,CAAC,EACtDA,EAAuB,yBACrB,QAAK,IAAI,MAAM,mBAAmB,CAAC,CACrC,EACAD,EAA8B,qBAC5B,SAAM,CACJ,sBAAuB,oBACvB,iBAAkB,oBACpB,CAAC,CACH,EACA,MAAMO,EAAc,CAClB,GAAI,MACJ,QAAS,EACT,KAAM,yEACN,SAAU,YACZ,EAGMC,EAAS,MAAMF,EAAO,KAAKC,CAAW,EAG5C,OAAON,CAAsB,EAAE,sBAAsB,CAAC,EACtD,OAAOA,CAAsB,EAAE,wBAAwB,EAAG,CACxD,QAAS,oBACT,QAAS,EACT,SAAU,YACZ,CAAC,EACD,OAAOO,CAAM,EAAE,QAAQ,CACrB,CACE,KAAM,uBAAqB,MAC3B,MAAO,IAAI,MACT,mEACF,CACF,CACF,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["import_device_management_kit", "import_purify_ts", "import_CalldataContextLoader", "import_ClearSignContext", "getProxyImplementationAddress", "getDappDescriptorsMock", "getTokenDescriptorsMock", "mockDappDataSource", "mockTokenDataSource", "mockProxyDatasource", "loader", "transaction", "result"]
4
+ "sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport type { CalldataDescriptorDataSource } from \"@/calldata/data/CalldataDescriptorDataSource\";\nimport {\n type CalldataContextInput,\n CalldataContextLoader,\n} from \"@/calldata/domain/CalldataContextLoader\";\nimport type { ProxyDataSource } from \"@/proxy/data/ProxyDataSource\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\n\ndescribe(\"CalldataContextLoader\", () => {\n const getProxyImplementationAddress = vi.fn();\n const getDappDescriptorsMock = vi.fn();\n const getTokenDescriptorsMock = vi.fn();\n const mockDappDataSource: CalldataDescriptorDataSource = {\n getCalldataDescriptors: getDappDescriptorsMock,\n };\n const mockTokenDataSource: CalldataDescriptorDataSource = {\n getCalldataDescriptors: getTokenDescriptorsMock,\n };\n const mockProxyDatasource: ProxyDataSource = {\n getProxyImplementationAddress: getProxyImplementationAddress,\n };\n const loader = new CalldataContextLoader(\n mockDappDataSource,\n mockTokenDataSource,\n mockProxyDatasource,\n );\n const SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.TRANSACTION_INFO,\n ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n ClearSignContextType.PROXY_INFO,\n ClearSignContextType.ENUM,\n ];\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n describe(\"canHandle function\", () => {\n const validInput: CalldataContextInput = {\n to: \"0x1234567890123456789012345678901234567890\",\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n chainId: 1,\n deviceModelId: DeviceModelId.NANO_X,\n };\n\n it(\"should return true for valid input\", () => {\n expect(loader.canHandle(validInput, SUPPORTED_TYPES)).toBe(true);\n });\n\n it(\"should return false for invalid expected type\", () => {\n expect(loader.canHandle(validInput, [ClearSignContextType.TOKEN])).toBe(\n false,\n );\n expect(loader.canHandle(validInput, [ClearSignContextType.NFT])).toBe(\n false,\n );\n expect(\n loader.canHandle(validInput, [ClearSignContextType.PROXY_INFO]),\n ).toBe(false);\n expect(loader.canHandle(validInput, [ClearSignContextType.ENUM])).toBe(\n false,\n );\n expect(\n loader.canHandle(validInput, [ClearSignContextType.TRANSACTION_INFO]),\n ).toBe(false);\n });\n\n it.each([\n [null, \"null input\"],\n [undefined, \"undefined input\"],\n [{}, \"empty object\"],\n [\"string\", \"string input\"],\n [123, \"number input\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, SUPPORTED_TYPES)).toBe(false);\n });\n\n it.each([\n [{ ...validInput, to: undefined }, \"missing to\"],\n [{ ...validInput, data: undefined }, \"missing data\"],\n [{ ...validInput, selector: undefined }, \"missing selector\"],\n [{ ...validInput, chainId: undefined }, \"missing chainId\"],\n [{ ...validInput, deviceModelId: undefined }, \"missing deviceModelId\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, SUPPORTED_TYPES)).toBe(false);\n });\n\n it.each([\n [{ ...validInput, to: \"invalid-hex\" }, \"invalid to hex\"],\n [{ ...validInput, to: \"0x\" }, \"empty to hex\"],\n [{ ...validInput, data: \"invalid-hex\" }, \"invalid data hex\"],\n [{ ...validInput, selector: \"invalid-hex\" }, \"invalid selector hex\"],\n [{ ...validInput, selector: \"0x\" }, \"empty selector hex\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, SUPPORTED_TYPES)).toBe(false);\n });\n\n it.each([\n [{ ...validInput, chainId: \"1\" }, \"string chainId\"],\n [{ ...validInput, chainId: null }, \"null chainId\"],\n [\n { ...validInput, deviceModelId: DeviceModelId.NANO_S },\n \"deviceModelId is NANO_S\",\n ],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, SUPPORTED_TYPES)).toBe(false);\n });\n });\n\n it(\"should return an error if data source fails\", async () => {\n // GIVEN\n getProxyImplementationAddress.mockResolvedValue(\n Left(new Error(\"data source error\")),\n );\n getDappDescriptorsMock.mockResolvedValue(\n Left(new Error(\"data source error\")),\n );\n const input = {\n to: \"0x1234567890123456789012345678901234567890\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n deviceModelId: DeviceModelId.NANO_X,\n } as CalldataContextInput;\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(getDappDescriptorsMock).toHaveBeenCalledWith({\n address: \"0x1234567890123456789012345678901234567890\",\n chainId: 3,\n selector: \"0xaf68b302\",\n deviceModelId: DeviceModelId.NANO_X,\n });\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\n \"[ContextModule] CalldataContextLoader: No calldata contexts found\",\n ),\n },\n ]);\n });\n\n it(\"should return the contexts on success\", async () => {\n // GIVEN\n getDappDescriptorsMock.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 getProxyImplementationAddress.mockResolvedValue(\n Left(new Error(\"data source error\")),\n );\n const input = {\n to: \"0x1234567890123456789012345678901234567890\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n deviceModelId: DeviceModelId.NANO_X,\n } as CalldataContextInput;\n\n // WHEN\n const result = await loader.load(input);\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 getDappDescriptorsMock.mockResolvedValueOnce(Right([])); // No transaction descriptors found for the first call\n getDappDescriptorsMock.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 getProxyImplementationAddress.mockResolvedValue(\n Right({\n implementationAddress: \"0x1234567890abcdef\",\n signedDescriptor: \"0x1234567890abcdef\",\n }),\n );\n const input = {\n to: \"0x1234567890123456789012345678901234567890\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n deviceModelId: DeviceModelId.NANO_X,\n } as CalldataContextInput;\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.PROXY_INFO,\n payload: \"0x\",\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 an error when proxy delegate call succeeds but transaction descriptors for resolved address fail\", async () => {\n // GIVEN\n getDappDescriptorsMock.mockResolvedValueOnce(Right([])); // No transaction descriptors found for the first call\n getDappDescriptorsMock.mockResolvedValueOnce(\n Left(new Error(\"data source error\")),\n ); // Second call fails\n getProxyImplementationAddress.mockResolvedValue(\n Right({\n implementationAddress: \"0xResolvedAddress\",\n signedDescriptor: \"0x1234567890abcdef\",\n }),\n );\n const input = {\n to: \"0x1234567890123456789012345678901234567890\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n deviceModelId: DeviceModelId.NANO_X,\n } as CalldataContextInput;\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(getDappDescriptorsMock).toHaveBeenCalledTimes(2);\n expect(getDappDescriptorsMock).toHaveBeenNthCalledWith(2, {\n address: \"0xResolvedAddress\",\n chainId: 3,\n selector: \"0xaf68b302\",\n deviceModelId: DeviceModelId.NANO_X,\n });\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\n \"[ContextModule] CalldataContextLoader: No calldata contexts found\",\n ),\n },\n ]);\n });\n});\n"],
5
+ "mappings": "aAAA,IAAAA,EAA8B,2CAC9BC,EAA4B,qBAG5BC,EAGO,mDAEPC,EAAqC,2CAErC,SAAS,wBAAyB,IAAM,CACtC,MAAMC,EAAgC,GAAG,GAAG,EACtCC,EAAyB,GAAG,GAAG,EAC/BC,EAA0B,GAAG,GAAG,EAChCC,EAAmD,CACvD,uBAAwBF,CAC1B,EACMG,EAAoD,CACxD,uBAAwBF,CAC1B,EACMG,EAAuC,CAC3C,8BAA+BL,CACjC,EACMM,EAAS,IAAI,wBACjBH,EACAC,EACAC,CACF,EACME,EAA0C,CAC9C,uBAAqB,iBACrB,uBAAqB,8BACrB,uBAAqB,WACrB,uBAAqB,IACvB,EAEA,WAAW,IAAM,CACf,GAAG,cAAc,CACnB,CAAC,EAED,SAAS,qBAAsB,IAAM,CACnC,MAAMC,EAAmC,CACvC,GAAI,6CACJ,KAAM,yEACN,SAAU,aACV,QAAS,EACT,cAAe,gBAAc,MAC/B,EAEA,GAAG,qCAAsC,IAAM,CAC7C,OAAOF,EAAO,UAAUE,EAAYD,CAAe,CAAC,EAAE,KAAK,EAAI,CACjE,CAAC,EAED,GAAG,gDAAiD,IAAM,CACxD,OAAOD,EAAO,UAAUE,EAAY,CAAC,uBAAqB,KAAK,CAAC,CAAC,EAAE,KACjE,EACF,EACA,OAAOF,EAAO,UAAUE,EAAY,CAAC,uBAAqB,GAAG,CAAC,CAAC,EAAE,KAC/D,EACF,EACA,OACEF,EAAO,UAAUE,EAAY,CAAC,uBAAqB,UAAU,CAAC,CAChE,EAAE,KAAK,EAAK,EACZ,OAAOF,EAAO,UAAUE,EAAY,CAAC,uBAAqB,IAAI,CAAC,CAAC,EAAE,KAChE,EACF,EACA,OACEF,EAAO,UAAUE,EAAY,CAAC,uBAAqB,gBAAgB,CAAC,CACtE,EAAE,KAAK,EAAK,CACd,C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AY,CAEzEV,EAAuB,yBAAsB,SAAM,CAAC,CAAC,CAAC,EACtDA,EAAuB,qBACrB,SAAM,CACJ,CACE,KAAM,uBAAqB,iBAC3B,QAAS,YACX,EACA,CACE,KAAM,uBAAqB,8BAC3B,QAAS,UACX,CACF,CAAC,CACH,EACAD,EAA8B,qBAC5B,SAAM,CACJ,sBAAuB,qBACvB,iBAAkB,oBACpB,CAAC,CACH,EACA,MAAMS,EAAQ,CACZ,GAAI,6CACJ,QAAS,EACT,KAAM,yEACN,SAAU,aACV,cAAe,gBAAc,MAC/B,EAGME,EAAS,MAAML,EAAO,KAAKG,CAAK,EAGtC,OAAOE,CAAM,EAAE,QAAQ,CACrB,CACE,KAAM,uBAAqB,WAC3B,QAAS,IACX,EACA,CACE,KAAM,uBAAqB,iBAC3B,QAAS,YACX,EACA,CACE,KAAM,uBAAqB,8BAC3B,QAAS,UACX,CACF,CAAC,CACH,CAAC,EAED,GAAG,iHAAkH,SAAY,CAE/HV,EAAuB,yBAAsB,SAAM,CAAC,CAAC,CAAC,EACtDA,EAAuB,yBACrB,QAAK,IAAI,MAAM,mBAAmB,CAAC,CACrC,EACAD,EAA8B,qBAC5B,SAAM,CACJ,sBAAuB,oBACvB,iBAAkB,oBACpB,CAAC,CACH,EACA,MAAMS,EAAQ,CACZ,GAAI,6CACJ,QAAS,EACT,KAAM,yEACN,SAAU,aACV,cAAe,gBAAc,MAC/B,EAGME,EAAS,MAAML,EAAO,KAAKG,CAAK,EAGtC,OAAOR,CAAsB,EAAE,sBAAsB,CAAC,EACtD,OAAOA,CAAsB,EAAE,wBAAwB,EAAG,CACxD,QAAS,oBACT,QAAS,EACT,SAAU,aACV,cAAe,gBAAc,MAC/B,CAAC,EACD,OAAOU,CAAM,EAAE,QAAQ,CACrB,CACE,KAAM,uBAAqB,MAC3B,MAAO,IAAI,MACT,mEACF,CACF,CACF,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["import_device_management_kit", "import_purify_ts", "import_CalldataContextLoader", "import_ClearSignContext", "getProxyImplementationAddress", "getDappDescriptorsMock", "getTokenDescriptorsMock", "mockDappDataSource", "mockTokenDataSource", "mockProxyDatasource", "loader", "SUPPORTED_TYPES", "validInput", "input", "_description", "result"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var d=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var I=Object.prototype.hasOwnProperty;var h=(r,e)=>{for(var o in e)d(r,o,{get:e[o],enumerable:!0})},w=(r,e,o,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of T(e))!I.call(r,t)&&t!==o&&d(r,t,{get:()=>e[t],enumerable:!(i=l(e,t))||i.enumerable});return r};var M=r=>w(d({},"__esModule",{value:!0}),r),C=(r,e,o,i)=>{for(var t=i>1?void 0:i?l(e,o):e,n=r.length-1,a;n>=0;n--)(a=r[n])&&(t=(i?a(e,o,t):a(t))||t);return i&&t&&d(e,o,t),t},s=(r,e)=>(o,i)=>e(o,i,r);var x={};h(x,{DynamicNetworkContextLoader:()=>f});module.exports=M(x);var y=require("@ledgerhq/device-management-kit"),c=require("inversify"),g=require("../../config/di/configTypes"),u=require("../../dynamic-network/di/dynamicNetworkTypes"),k=require("../../pki/di/pkiTypes"),S=require("../../pki/model/KeyId"),_=require("../../pki/model/KeyUsage"),p=require("../../shared/model/ClearSignContext"),N=require("../../shared/utils/HexStringUtils");const v="15";let f=class{_networkDataSource;_config;_certificateLoader;constructor(e,o,i){this._networkDataSource=e,this._config=o,this._certificateLoader=i}async load(e){if(e.deviceModelId===y.DeviceModelId.NANO_S)return[];const o=await this._networkDataSource.getDynamicNetworkConfiguration(e.chainId),i=await this._certificateLoader.loadCertificate({keyId:S.KeyId.CalNetwork,keyUsage:_.KeyUsage.Network,targetDevice:e.deviceModelId});return o.caseOf({Left:()=>[],Right:t=>{const n=[],a=t.descriptors[e.deviceModelId];if(!a)return[];const m=a.signatures[this._config.cal.mode];if(!m)return[];const D=N.HexStringUtils.appendSignatureToPayload(a.data,m,v);return n.push({type:p.ClearSignContextType.DYNAMIC_NETWORK,payload:D,certificate:i}),a.icon&&n.push({type:p.ClearSignContextType.DYNAMIC_NETWORK_ICON,payload:a.icon}),n}})}};f=C([(0,c.injectable)(),s(0,(0,c.inject)(u.dynamicNetworkTypes.DynamicNetworkDataSource)),s(1,(0,c.inject)(g.configTypes.Config)),s(2,(0,c.inject)(k.pkiTypes.PkiCertificateLoader))],f);0&&(module.exports={DynamicNetworkContextLoader});
1
+ "use strict";var s=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var M=(i,e)=>{for(var t in e)s(i,t,{get:e[t],enumerable:!0})},h=(i,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of T(e))!w.call(i,r)&&r!==t&&s(i,r,{get:()=>e[r],enumerable:!(o=y(e,r))||o.enumerable});return i};var v=i=>h(s({},"__esModule",{value:!0}),i),u=(i,e,t,o)=>{for(var r=o>1?void 0:o?y(e,t):e,a=i.length-1,c;a>=0;a--)(c=i[a])&&(r=(o?c(e,t,r):c(r))||r);return o&&r&&s(e,t,r),r},m=(i,e)=>(t,o)=>e(t,o,i);var E={};M(E,{DynamicNetworkContextLoader:()=>p});module.exports=v(E);var g=require("@ledgerhq/device-management-kit"),n=require("inversify"),I=require("../../config/di/configTypes"),N=require("../../dynamic-network/di/dynamicNetworkTypes"),D=require("../../pki/di/pkiTypes"),k=require("../../pki/model/KeyId"),S=require("../../pki/model/KeyUsage"),f=require("../../shared/model/ClearSignContext"),_=require("../../shared/utils/HexStringUtils");const O="15",P=[f.ClearSignContextType.DYNAMIC_NETWORK,f.ClearSignContextType.DYNAMIC_NETWORK_ICON];let p=class{_networkDataSource;_config;_certificateLoader;constructor(e,t,o){this._networkDataSource=e,this._config=t,this._certificateLoader=o}canHandle(e,t){return typeof e=="object"&&e!==null&&"chainId"in e&&"deviceModelId"in e&&e.deviceModelId!==void 0&&e.deviceModelId!==g.DeviceModelId.NANO_S&&typeof e.chainId=="number"&&P.every(o=>t.includes(o))}async load(e){const{chainId:t,deviceModelId:o}=e,r=await this._networkDataSource.getDynamicNetworkConfiguration(t),a=await this._certificateLoader.loadCertificate({keyId:k.KeyId.CalNetwork,keyUsage:S.KeyUsage.Network,targetDevice:o});return r.caseOf({Left:()=>[],Right:c=>{const l=[],d=c.descriptors[o];if(!d)return[];const C=d.signatures[this._config.cal.mode];if(!C)return[];const x=_.HexStringUtils.appendSignatureToPayload(d.data,C,O);return l.push({type:f.ClearSignContextType.DYNAMIC_NETWORK,payload:x,certificate:a}),d.icon&&l.push({type:f.ClearSignContextType.DYNAMIC_NETWORK_ICON,payload:d.icon}),l}})}};p=u([(0,n.injectable)(),m(0,(0,n.inject)(N.dynamicNetworkTypes.DynamicNetworkDataSource)),m(1,(0,n.inject)(I.configTypes.Config)),m(2,(0,n.inject)(D.pkiTypes.PkiCertificateLoader))],p);0&&(module.exports={DynamicNetworkContextLoader});
2
2
  //# sourceMappingURL=DynamicNetworkContextLoader.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/dynamic-network/domain/DynamicNetworkContextLoader.ts"],
4
- "sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { type DynamicNetworkDataSource } from \"@/dynamic-network/data/DynamicNetworkDataSource\";\nimport { dynamicNetworkTypes } from \"@/dynamic-network/di/dynamicNetworkTypes\";\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 { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { TransactionContext } from \"@/shared/model/TransactionContext\";\nimport { HexStringUtils } from \"@/shared/utils/HexStringUtils\";\n\nconst NETWORK_SIGNATURE_TAG = \"15\";\n\n@injectable()\nexport class DynamicNetworkContextLoader implements ContextLoader {\n private readonly _networkDataSource: DynamicNetworkDataSource;\n private readonly _config: ContextModuleConfig;\n private readonly _certificateLoader: PkiCertificateLoader;\n\n constructor(\n @inject(dynamicNetworkTypes.DynamicNetworkDataSource)\n networkDataSource: DynamicNetworkDataSource,\n @inject(configTypes.Config)\n config: ContextModuleConfig,\n @inject(pkiTypes.PkiCertificateLoader)\n certificateLoader: PkiCertificateLoader,\n ) {\n this._networkDataSource = networkDataSource;\n this._config = config;\n this._certificateLoader = certificateLoader;\n }\n\n async load(ctx: TransactionContext): Promise<ClearSignContext[]> {\n if (ctx.deviceModelId === DeviceModelId.NANO_S) return [];\n\n const result = await this._networkDataSource.getDynamicNetworkConfiguration(\n ctx.chainId,\n );\n\n // Fetch certificate for the network configuration upfront\n const certificate = await this._certificateLoader.loadCertificate({\n keyId: KeyId.CalNetwork,\n keyUsage: KeyUsage.Network,\n targetDevice: ctx.deviceModelId,\n });\n\n return result.caseOf({\n Left: () => [],\n Right: (configuration) => {\n const contexts: ClearSignContext[] = [];\n const descriptor = configuration.descriptors[ctx.deviceModelId];\n\n if (!descriptor) {\n return [];\n }\n\n const signature = descriptor.signatures[this._config.cal.mode];\n\n if (!signature) {\n return [];\n }\n\n const configPayload = HexStringUtils.appendSignatureToPayload(\n descriptor.data,\n signature,\n NETWORK_SIGNATURE_TAG,\n );\n\n contexts.push({\n type: ClearSignContextType.DYNAMIC_NETWORK,\n payload: configPayload,\n certificate,\n });\n\n // Add icon if available in the descriptor\n if (descriptor.icon) {\n // Icons don't need signatures appended\n contexts.push({\n type: ClearSignContextType.DYNAMIC_NETWORK_ICON,\n payload: descriptor.icon,\n });\n }\n\n return contexts;\n },\n });\n }\n}\n"],
5
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BAAwB,GAEnDA,EAAA,eAAO,cAAY,MAAM,GAEzBA,EAAA,eAAO,WAAS,oBAAoB,IAV5Bb",
6
- "names": ["DynamicNetworkContextLoader_exports", "__export", "DynamicNetworkContextLoader", "__toCommonJS", "import_device_management_kit", "import_inversify", "import_configTypes", "import_dynamicNetworkTypes", "import_pkiTypes", "import_KeyId", "import_KeyUsage", "import_ClearSignContext", "import_HexStringUtils", "NETWORK_SIGNATURE_TAG", "DynamicNetworkContextLoader", "networkDataSource", "config", "certificateLoader", "ctx", "result", "certificate", "configuration", "contexts", "descriptor", "signature", "configPayload", "__decorateClass", "__decorateParam"]
4
+ "sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { type DynamicNetworkDataSource } from \"@/dynamic-network/data/DynamicNetworkDataSource\";\nimport { dynamicNetworkTypes } from \"@/dynamic-network/di/dynamicNetworkTypes\";\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 { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { HexStringUtils } from \"@/shared/utils/HexStringUtils\";\n\nexport type DynamicNetworkContextInput = {\n chainId: number;\n deviceModelId: DeviceModelId;\n};\n\nconst NETWORK_SIGNATURE_TAG = \"15\";\n\nconst SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.DYNAMIC_NETWORK,\n ClearSignContextType.DYNAMIC_NETWORK_ICON,\n];\n\n@injectable()\nexport class DynamicNetworkContextLoader\n implements ContextLoader<DynamicNetworkContextInput>\n{\n private readonly _networkDataSource: DynamicNetworkDataSource;\n private readonly _config: ContextModuleConfig;\n private readonly _certificateLoader: PkiCertificateLoader;\n\n constructor(\n @inject(dynamicNetworkTypes.DynamicNetworkDataSource)\n networkDataSource: DynamicNetworkDataSource,\n @inject(configTypes.Config)\n config: ContextModuleConfig,\n @inject(pkiTypes.PkiCertificateLoader)\n certificateLoader: PkiCertificateLoader,\n ) {\n this._networkDataSource = networkDataSource;\n this._config = config;\n this._certificateLoader = certificateLoader;\n }\n\n canHandle(\n input: unknown,\n expectedTypes: ClearSignContextType[],\n ): input is DynamicNetworkContextInput {\n return (\n typeof input === \"object\" &&\n input !== null &&\n \"chainId\" in input &&\n \"deviceModelId\" in input &&\n input.deviceModelId !== undefined &&\n input.deviceModelId !== DeviceModelId.NANO_S &&\n typeof input.chainId === \"number\" &&\n SUPPORTED_TYPES.every((type) => expectedTypes.includes(type))\n );\n }\n\n async load(input: DynamicNetworkContextInput): Promise<ClearSignContext[]> {\n const { chainId, deviceModelId } = input;\n\n const result =\n await this._networkDataSource.getDynamicNetworkConfiguration(chainId);\n\n // Fetch certificate for the network configuration upfront\n const certificate = await this._certificateLoader.loadCertificate({\n keyId: KeyId.CalNetwork,\n keyUsage: KeyUsage.Network,\n targetDevice: deviceModelId,\n });\n\n return result.caseOf({\n Left: () => [],\n Right: (configuration) => {\n const contexts: ClearSignContext[] = [];\n const descriptor = configuration.descriptors[deviceModelId];\n\n if (!descriptor) {\n return [];\n }\n\n const signature = descriptor.signatures[this._config.cal.mode];\n\n if (!signature) {\n return [];\n }\n\n const configPayload = HexStringUtils.appendSignatureToPayload(\n descriptor.data,\n signature,\n NETWORK_SIGNATURE_TAG,\n );\n\n contexts.push({\n type: ClearSignContextType.DYNAMIC_NETWORK,\n payload: configPayload,\n certificate,\n });\n\n // Add icon if available in the descriptor\n if (descriptor.icon) {\n // Icons don't need signatures appended\n contexts.push({\n type: ClearSignContextType.DYNAMIC_NETWORK_ICON,\n payload: descriptor.icon,\n });\n }\n\n return contexts;\n },\n });\n }\n}\n"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A,OAAAc,EAAS,KAAK,CACZ,KAAM,uBAAqB,gBAC3B,QAASG,EACT,YAAAL,CACF,CAAC,EAGGG,EAAW,MAEbD,EAAS,KAAK,CACZ,KAAM,uBAAqB,qBAC3B,QAASC,EAAW,IACtB,CAAC,EAGID,CACT,CACF,CAAC,CACH,CACF,EA1FaZ,EAANgB,EAAA,IADN,cAAW,EASPC,EAAA,eAAO,sBAAoB,wBAAwB,GAEnDA,EAAA,eAAO,cAAY,MAAM,GAEzBA,EAAA,eAAO,WAAS,oBAAoB,IAZ5BjB",
6
+ "names": ["DynamicNetworkContextLoader_exports", "__export", "DynamicNetworkContextLoader", "__toCommonJS", "import_device_management_kit", "import_inversify", "import_configTypes", "import_dynamicNetworkTypes", "import_pkiTypes", "import_KeyId", "import_KeyUsage", "import_ClearSignContext", "import_HexStringUtils", "NETWORK_SIGNATURE_TAG", "SUPPORTED_TYPES", "DynamicNetworkContextLoader", "networkDataSource", "config", "certificateLoader", "input", "expectedTypes", "type", "chainId", "deviceModelId", "result", "certificate", "configuration", "contexts", "descriptor", "signature", "configPayload", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("@ledgerhq/device-management-kit"),a=require("purify-ts"),f=require("../../dynamic-network/domain/DynamicNetworkContextLoader"),m=require("../../pki/model/KeyId"),g=require("../../pki/model/KeyUsage"),p=require("../../shared/model/ClearSignContext");describe("DynamicNetworkContextLoader",()=>{const n={getDynamicNetworkConfiguration:vi.fn()},l={cal:{url:"https://crypto-assets-service.api.ledger.com",mode:"prod",branch:"main"}},d={loadCertificate:vi.fn()},u={keyUsageNumber:1,payload:new Uint8Array([1,2,3])},s=new f.DynamicNetworkContextLoader(n,l,d),t=o=>({data:"",descriptorType:"",descriptorVersion:"",signatures:{prod:"",test:""},icon:void 0,...o});beforeEach(()=>{vi.restoreAllMocks(),vi.spyOn(d,"loadCertificate").mockResolvedValue(u)}),describe("load function",()=>{it("should return empty array when network data source returns error",async()=>{const o={chainId:1,deviceModelId:e.DeviceModelId.STAX,to:"0x123",data:"0x456",selector:"0x789"};vi.spyOn(n,"getDynamicNetworkConfiguration").mockResolvedValue((0,a.Left)(new Error("Network error")));const r=await s.load(o);expect(r).toEqual([]),expect(n.getDynamicNetworkConfiguration).toHaveBeenCalledWith(1)}),it("should return empty array when descriptor for device model is not found",async()=>{const o={chainId:1,deviceModelId:e.DeviceModelId.STAX,to:"0x123",data:"0x456",selector:"0x789"},r={id:"ethereum",descriptors:{[e.DeviceModelId.NANO_S]:t(),[e.DeviceModelId.NANO_SP]:t(),[e.DeviceModelId.NANO_X]:t(),[e.DeviceModelId.FLEX]:t({data:"0x0101",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"prod-sig",test:"test-sig"},icon:void 0})}};vi.spyOn(n,"getDynamicNetworkConfiguration").mockResolvedValue((0,a.Right)(r));const i=await s.load(o);expect(i).toEqual([])}),it("should return empty array when signature for mode is not found",async()=>{const o={chainId:1,deviceModelId:e.DeviceModelId.STAX,to:"0x123",data:"0x456",selector:"0x789"},r={id:"ethereum",descriptors:{[e.DeviceModelId.APEX]:t(),[e.DeviceModelId.NANO_S]:t(),[e.DeviceModelId.NANO_SP]:t(),[e.DeviceModelId.NANO_X]:t(),[e.DeviceModelId.FLEX]:t(),[e.DeviceModelId.STAX]:t({data:"0x0101",descriptorType:"network",descriptorVersion:"v1",signatures:{test:"test-sig"},icon:void 0})}};vi.spyOn(n,"getDynamicNetworkConfiguration").mockResolvedValue((0,a.Right)(r));const i=await s.load(o);expect(i).toEqual([])}),it("should return context with network configuration when all data is available",async()=>{const o={chainId:137,deviceModelId:e.DeviceModelId.STAX,to:"0x123",data:"0x456",selector:"0x789"},r={id:"polygon",descriptors:{[e.DeviceModelId.APEX]:t(),[e.DeviceModelId.NANO_S]:t(),[e.DeviceModelId.NANO_SP]:t(),[e.DeviceModelId.NANO_X]:t(),[e.DeviceModelId.FLEX]:t(),[e.DeviceModelId.STAX]:{data:"0x0101080201015101012308000000000000008952",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"3045022100cf42c039c16fc95dc97c09f15cdd93bed0e63ee45cf5c38c2b30bb8a3bc17f8d022053a96c9e51695c3c1c1a31f5cbf84bd6febadc97f4bb02bdc67cf3e24ad0c32d",test:"test-sig"},icon:void 0}}};vi.spyOn(n,"getDynamicNetworkConfiguration").mockResolvedValue((0,a.Right)(r));const i=await s.load(o);expect(i).toHaveLength(1),expect(i[0]).toMatchObject({type:p.ClearSignContextType.DYNAMIC_NETWORK,payload:expect.stringContaining("0x0101080201015101012308000000000000008952"),certificate:u}),expect(d.loadCertificate).toHaveBeenCalledWith({keyId:m.KeyId.CalNetwork,keyUsage:g.KeyUsage.Network,targetDevice:e.DeviceModelId.STAX})}),it("should include icon context when icon is available",async()=>{const o={chainId:1,deviceModelId:e.DeviceModelId.STAX,to:"0x123",data:"0x456",selector:"0x789"},r={id:"ethereum",descriptors:{[e.DeviceModelId.APEX]:t(),[e.DeviceModelId.NANO_S]:t(),[e.DeviceModelId.NANO_SP]:t(),[e.DeviceModelId.NANO_X]:t(),[e.DeviceModelId.FLEX]:t(),[e.DeviceModelId.STAX]:{data:"0x0101",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"prod-sig",test:"test-sig"},icon:"icon-hex-data"}}};vi.spyOn(n,"getDynamicNetworkConfiguration").mockResolvedValue((0,a.Right)(r));const i=await s.load(o);expect(i).toHaveLength(2),expect(i[0]).toMatchObject({type:p.ClearSignContextType.DYNAMIC_NETWORK,payload:expect.any(String),certificate:u}),expect(i[1]).toMatchObject({type:p.ClearSignContextType.DYNAMIC_NETWORK_ICON,payload:"icon-hex-data"})}),it("should handle multiple device models correctly",async()=>{const o={chainId:1,deviceModelId:e.DeviceModelId.FLEX,to:"0x123",data:"0x456",selector:"0x789"},r={id:"ethereum",descriptors:{[e.DeviceModelId.APEX]:t(),[e.DeviceModelId.NANO_S]:t(),[e.DeviceModelId.NANO_SP]:t(),[e.DeviceModelId.NANO_X]:t(),[e.DeviceModelId.FLEX]:{data:"0xFLEX",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"flex-prod-sig",test:"flex-test-sig"},icon:void 0},[e.DeviceModelId.STAX]:{data:"0xSTAX",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"stax-prod-sig",test:"stax-test-sig"},icon:void 0}}};vi.spyOn(n,"getDynamicNetworkConfiguration").mockResolvedValue((0,a.Right)(r));const i=await s.load(o);expect(i).toHaveLength(1);const c=i[0];c&&"payload"in c&&(expect(c.payload).toContain("0xFLEX"),expect(c.payload).toContain("flex-prod-sig"))}),it("should use test mode signature when configured",async()=>{const o=new f.DynamicNetworkContextLoader(n,{...l,cal:{...l.cal,mode:"test"}},d),r={chainId:1,deviceModelId:e.DeviceModelId.STAX,to:"0x123",data:"0x456",selector:"0x789"},i={id:"ethereum",descriptors:{[e.DeviceModelId.APEX]:t(),[e.DeviceModelId.NANO_S]:t(),[e.DeviceModelId.NANO_SP]:t(),[e.DeviceModelId.NANO_X]:t(),[e.DeviceModelId.FLEX]:t(),[e.DeviceModelId.STAX]:{data:"0x0101",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"prod-sig",test:"test-sig"},icon:void 0}}};vi.spyOn(n,"getDynamicNetworkConfiguration").mockResolvedValue((0,a.Right)(i));const c=await o.load(r);expect(c).toHaveLength(1);const y=c[0];y&&"payload"in y&&expect(y.payload).toContain("test-sig")})})});
1
+ "use strict";var e=require("@ledgerhq/device-management-kit"),d=require("purify-ts"),f=require("../../dynamic-network/domain/DynamicNetworkContextLoader"),y=require("../../pki/model/KeyId"),m=require("../../pki/model/KeyUsage"),r=require("../../shared/model/ClearSignContext");describe("DynamicNetworkContextLoader",()=>{const c={getDynamicNetworkConfiguration:vi.fn()},l={cal:{url:"https://crypto-assets-service.api.ledger.com",mode:"prod",branch:"main"}},p={loadCertificate:vi.fn()},u={keyUsageNumber:1,payload:new Uint8Array([1,2,3])},a=new f.DynamicNetworkContextLoader(c,l,p),t=o=>({data:"",descriptorType:"",descriptorVersion:"",signatures:{prod:"",test:""},icon:void 0,...o});beforeEach(()=>{vi.restoreAllMocks(),vi.spyOn(p,"loadCertificate").mockResolvedValue(u)}),describe("canHandle function",()=>{const o={chainId:1,deviceModelId:e.DeviceModelId.STAX};it("should return true for valid input",()=>{expect(a.canHandle(o,[r.ClearSignContextType.DYNAMIC_NETWORK,r.ClearSignContextType.DYNAMIC_NETWORK_ICON])).toBe(!0)}),it("should return false for invalid expected type",()=>{expect(a.canHandle(o,[r.ClearSignContextType.TOKEN])).toBe(!1),expect(a.canHandle(o,[r.ClearSignContextType.DYNAMIC_NETWORK])).toBe(!1),expect(a.canHandle(o,[r.ClearSignContextType.DYNAMIC_NETWORK_ICON])).toBe(!1)}),it.each([[null,"null input"],[void 0,"undefined input"],[{},"empty object"],["string","string input"],[123,"number input"]])("should return false for %s",(n,i)=>{expect(a.canHandle(n,[r.ClearSignContextType.DYNAMIC_NETWORK,r.ClearSignContextType.DYNAMIC_NETWORK_ICON])).toBe(!1)}),it.each([[{...o,chainId:void 0},"missing chainId"],[{...o,deviceModelId:void 0},"missing deviceModelId"]])("should return false for %s",(n,i)=>{expect(a.canHandle(n,[r.ClearSignContextType.DYNAMIC_NETWORK,r.ClearSignContextType.DYNAMIC_NETWORK_ICON])).toBe(!1)}),it.each([[{...o,chainId:"1"},"string chainId"],[{...o,chainId:null},"null chainId"],[{...o,deviceModelId:e.DeviceModelId.NANO_S},"NANO_S deviceModelId"]])("should return false for %s",(n,i)=>{expect(a.canHandle(n,[r.ClearSignContextType.DYNAMIC_NETWORK,r.ClearSignContextType.DYNAMIC_NETWORK_ICON])).toBe(!1)})}),describe("load function",()=>{it("should return empty array when network data source returns error",async()=>{const o={chainId:1,deviceModelId:e.DeviceModelId.STAX};vi.spyOn(c,"getDynamicNetworkConfiguration").mockResolvedValue((0,d.Left)(new Error("Network error")));const n=await a.load(o);expect(n).toEqual([]),expect(c.getDynamicNetworkConfiguration).toHaveBeenCalledWith(1)}),it("should return empty array when descriptor for device model is not found",async()=>{const o={chainId:1,deviceModelId:e.DeviceModelId.STAX},n={id:"ethereum",descriptors:{[e.DeviceModelId.NANO_S]:t(),[e.DeviceModelId.NANO_SP]:t(),[e.DeviceModelId.NANO_X]:t(),[e.DeviceModelId.FLEX]:t({data:"0x0101",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"prod-sig",test:"test-sig"},icon:void 0})}};vi.spyOn(c,"getDynamicNetworkConfiguration").mockResolvedValue((0,d.Right)(n));const i=await a.load(o);expect(i).toEqual([])}),it("should return empty array when signature for mode is not found",async()=>{const o={chainId:1,deviceModelId:e.DeviceModelId.STAX},n={id:"ethereum",descriptors:{[e.DeviceModelId.APEX]:t(),[e.DeviceModelId.NANO_S]:t(),[e.DeviceModelId.NANO_SP]:t(),[e.DeviceModelId.NANO_X]:t(),[e.DeviceModelId.FLEX]:t(),[e.DeviceModelId.STAX]:t({data:"0x0101",descriptorType:"network",descriptorVersion:"v1",signatures:{test:"test-sig"},icon:void 0})}};vi.spyOn(c,"getDynamicNetworkConfiguration").mockResolvedValue((0,d.Right)(n));const i=await a.load(o);expect(i).toEqual([])}),it("should return context with network configuration when all data is available",async()=>{const o={chainId:137,deviceModelId:e.DeviceModelId.STAX},n={id:"polygon",descriptors:{[e.DeviceModelId.APEX]:t(),[e.DeviceModelId.NANO_S]:t(),[e.DeviceModelId.NANO_SP]:t(),[e.DeviceModelId.NANO_X]:t(),[e.DeviceModelId.FLEX]:t(),[e.DeviceModelId.STAX]:{data:"0x0101080201015101012308000000000000008952",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"3045022100cf42c039c16fc95dc97c09f15cdd93bed0e63ee45cf5c38c2b30bb8a3bc17f8d022053a96c9e51695c3c1c1a31f5cbf84bd6febadc97f4bb02bdc67cf3e24ad0c32d",test:"test-sig"},icon:void 0}}};vi.spyOn(c,"getDynamicNetworkConfiguration").mockResolvedValue((0,d.Right)(n));const i=await a.load(o);expect(i).toHaveLength(1),expect(i[0]).toMatchObject({type:r.ClearSignContextType.DYNAMIC_NETWORK,payload:expect.stringContaining("0x0101080201015101012308000000000000008952"),certificate:u}),expect(p.loadCertificate).toHaveBeenCalledWith({keyId:y.KeyId.CalNetwork,keyUsage:m.KeyUsage.Network,targetDevice:e.DeviceModelId.STAX})}),it("should include icon context when icon is available",async()=>{const o={chainId:1,deviceModelId:e.DeviceModelId.STAX},n={id:"ethereum",descriptors:{[e.DeviceModelId.APEX]:t(),[e.DeviceModelId.NANO_S]:t(),[e.DeviceModelId.NANO_SP]:t(),[e.DeviceModelId.NANO_X]:t(),[e.DeviceModelId.FLEX]:t(),[e.DeviceModelId.STAX]:{data:"0x0101",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"prod-sig",test:"test-sig"},icon:"icon-hex-data"}}};vi.spyOn(c,"getDynamicNetworkConfiguration").mockResolvedValue((0,d.Right)(n));const i=await a.load(o);expect(i).toHaveLength(2),expect(i[0]).toMatchObject({type:r.ClearSignContextType.DYNAMIC_NETWORK,payload:expect.any(String),certificate:u}),expect(i[1]).toMatchObject({type:r.ClearSignContextType.DYNAMIC_NETWORK_ICON,payload:"icon-hex-data"})}),it("should handle multiple device models correctly",async()=>{const o={chainId:1,deviceModelId:e.DeviceModelId.FLEX},n={id:"ethereum",descriptors:{[e.DeviceModelId.APEX]:t(),[e.DeviceModelId.NANO_S]:t(),[e.DeviceModelId.NANO_SP]:t(),[e.DeviceModelId.NANO_X]:t(),[e.DeviceModelId.FLEX]:{data:"0xFLEX",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"flex-prod-sig",test:"flex-test-sig"},icon:void 0},[e.DeviceModelId.STAX]:{data:"0xSTAX",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"stax-prod-sig",test:"stax-test-sig"},icon:void 0}}};vi.spyOn(c,"getDynamicNetworkConfiguration").mockResolvedValue((0,d.Right)(n));const i=await a.load(o);expect(i).toHaveLength(1);const s=i[0];s&&"payload"in s&&(expect(s.payload).toContain("0xFLEX"),expect(s.payload).toContain("flex-prod-sig"))}),it("should use test mode signature when configured",async()=>{const o=new f.DynamicNetworkContextLoader(c,{...l,cal:{...l.cal,mode:"test"}},p),n={chainId:1,deviceModelId:e.DeviceModelId.STAX},i={id:"ethereum",descriptors:{[e.DeviceModelId.APEX]:t(),[e.DeviceModelId.NANO_S]:t(),[e.DeviceModelId.NANO_SP]:t(),[e.DeviceModelId.NANO_X]:t(),[e.DeviceModelId.FLEX]:t(),[e.DeviceModelId.STAX]:{data:"0x0101",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"prod-sig",test:"test-sig"},icon:void 0}}};vi.spyOn(c,"getDynamicNetworkConfiguration").mockResolvedValue((0,d.Right)(i));const s=await o.load(n);expect(s).toHaveLength(1);const N=s[0];N&&"payload"in N&&expect(N.payload).toContain("test-sig")})})});
2
2
  //# sourceMappingURL=DynamicNetworkContextLoader.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/dynamic-network/domain/DynamicNetworkContextLoader.test.ts"],
4
- "sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { type DynamicNetworkDataSource } from \"@/dynamic-network/data/DynamicNetworkDataSource\";\nimport { DynamicNetworkContextLoader } from \"@/dynamic-network/domain/DynamicNetworkContextLoader\";\nimport {\n type DynamicNetworkConfiguration,\n type DynamicNetworkDescriptor,\n} from \"@/dynamic-network/model/DynamicNetworkConfiguration\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { type PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport { type TransactionContext } from \"@/shared/model/TransactionContext\";\n\ndescribe(\"DynamicNetworkContextLoader\", () => {\n const mockNetworkDataSource: DynamicNetworkDataSource = {\n getDynamicNetworkConfiguration: vi.fn(),\n };\n\n const mockConfig = {\n cal: {\n url: \"https://crypto-assets-service.api.ledger.com\",\n mode: \"prod\",\n branch: \"main\",\n },\n } as ContextModuleConfig;\n\n const mockCertificateLoader: PkiCertificateLoader = {\n loadCertificate: vi.fn(),\n };\n\n const mockCertificate: PkiCertificate = {\n keyUsageNumber: 1,\n payload: new Uint8Array([0x01, 0x02, 0x03]),\n };\n\n const loader = new DynamicNetworkContextLoader(\n mockNetworkDataSource,\n mockConfig,\n mockCertificateLoader,\n );\n\n // Helper function to create a mock NetworkDescriptor\n const createMockDescriptor = (\n partial?: Partial<DynamicNetworkDescriptor>,\n ): DynamicNetworkDescriptor => ({\n data: \"\",\n descriptorType: \"\",\n descriptorVersion: \"\",\n signatures: {\n prod: \"\",\n test: \"\",\n },\n icon: undefined,\n ...partial,\n });\n\n beforeEach(() => {\n vi.restoreAllMocks();\n vi.spyOn(mockCertificateLoader, \"loadCertificate\").mockResolvedValue(\n mockCertificate,\n );\n });\n\n describe(\"load function\", () => {\n it(\"should return empty array when network data source returns error\", async () => {\n // GIVEN\n const transaction: TransactionContext = {\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n to: \"0x123\",\n data: \"0x456\",\n selector: \"0x789\",\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Left(new Error(\"Network error\")));\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n expect(\n mockNetworkDataSource.getDynamicNetworkConfiguration,\n ).toHaveBeenCalledWith(1);\n });\n\n it(\"should return empty array when descriptor for device model is not found\", async () => {\n // GIVEN\n const transaction: TransactionContext = {\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n to: \"0x123\",\n data: \"0x456\",\n selector: \"0x789\",\n };\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"ethereum\",\n descriptors: {\n [DeviceModelId.NANO_S]: createMockDescriptor(),\n [DeviceModelId.NANO_SP]: createMockDescriptor(),\n [DeviceModelId.NANO_X]: createMockDescriptor(),\n // STAX descriptor is intentionally missing\n [DeviceModelId.FLEX]: createMockDescriptor({\n data: \"0x0101\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"prod-sig\",\n test: \"test-sig\",\n },\n icon: undefined,\n }),\n } as Record<DeviceModelId, DynamicNetworkDescriptor>,\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return empty array when signature for mode is not found\", async () => {\n // GIVEN\n const transaction: TransactionContext = {\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n to: \"0x123\",\n data: \"0x456\",\n selector: \"0x789\",\n };\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"ethereum\",\n descriptors: {\n [DeviceModelId.APEX]: createMockDescriptor(),\n [DeviceModelId.NANO_S]: createMockDescriptor(),\n [DeviceModelId.NANO_SP]: createMockDescriptor(),\n [DeviceModelId.NANO_X]: createMockDescriptor(),\n [DeviceModelId.FLEX]: createMockDescriptor(),\n [DeviceModelId.STAX]: createMockDescriptor({\n data: \"0x0101\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n test: \"test-sig\",\n // Missing prod signature - intentionally partial\n } as { prod: string; test: string },\n icon: undefined,\n }),\n },\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return context with network configuration when all data is available\", async () => {\n // GIVEN\n const transaction: TransactionContext = {\n chainId: 137,\n deviceModelId: DeviceModelId.STAX,\n to: \"0x123\",\n data: \"0x456\",\n selector: \"0x789\",\n };\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"polygon\",\n descriptors: {\n [DeviceModelId.APEX]: createMockDescriptor(),\n [DeviceModelId.NANO_S]: createMockDescriptor(),\n [DeviceModelId.NANO_SP]: createMockDescriptor(),\n [DeviceModelId.NANO_X]: createMockDescriptor(),\n [DeviceModelId.FLEX]: createMockDescriptor(),\n [DeviceModelId.STAX]: {\n data: \"0x0101080201015101012308000000000000008952\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"3045022100cf42c039c16fc95dc97c09f15cdd93bed0e63ee45cf5c38c2b30bb8a3bc17f8d022053a96c9e51695c3c1c1a31f5cbf84bd6febadc97f4bb02bdc67cf3e24ad0c32d\",\n test: \"test-sig\",\n },\n icon: undefined,\n },\n },\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toHaveLength(1);\n expect(result[0]).toMatchObject({\n type: ClearSignContextType.DYNAMIC_NETWORK,\n payload: expect.stringContaining(\n \"0x0101080201015101012308000000000000008952\",\n ),\n certificate: mockCertificate,\n });\n expect(mockCertificateLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: KeyId.CalNetwork,\n keyUsage: KeyUsage.Network,\n targetDevice: DeviceModelId.STAX,\n });\n });\n\n it(\"should include icon context when icon is available\", async () => {\n // GIVEN\n const transaction: TransactionContext = {\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n to: \"0x123\",\n data: \"0x456\",\n selector: \"0x789\",\n };\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"ethereum\",\n descriptors: {\n [DeviceModelId.APEX]: createMockDescriptor(),\n [DeviceModelId.NANO_S]: createMockDescriptor(),\n [DeviceModelId.NANO_SP]: createMockDescriptor(),\n [DeviceModelId.NANO_X]: createMockDescriptor(),\n [DeviceModelId.FLEX]: createMockDescriptor(),\n [DeviceModelId.STAX]: {\n data: \"0x0101\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"prod-sig\",\n test: \"test-sig\",\n },\n icon: \"icon-hex-data\",\n },\n },\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toHaveLength(2);\n expect(result[0]).toMatchObject({\n type: ClearSignContextType.DYNAMIC_NETWORK,\n payload: expect.any(String),\n certificate: mockCertificate,\n });\n expect(result[1]).toMatchObject({\n type: ClearSignContextType.DYNAMIC_NETWORK_ICON,\n payload: \"icon-hex-data\",\n });\n });\n\n it(\"should handle multiple device models correctly\", async () => {\n // GIVEN\n const transaction: TransactionContext = {\n chainId: 1,\n deviceModelId: DeviceModelId.FLEX,\n to: \"0x123\",\n data: \"0x456\",\n selector: \"0x789\",\n };\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"ethereum\",\n descriptors: {\n [DeviceModelId.APEX]: createMockDescriptor(),\n [DeviceModelId.NANO_S]: createMockDescriptor(),\n [DeviceModelId.NANO_SP]: createMockDescriptor(),\n [DeviceModelId.NANO_X]: createMockDescriptor(),\n [DeviceModelId.FLEX]: {\n data: \"0xFLEX\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"flex-prod-sig\",\n test: \"flex-test-sig\",\n },\n icon: undefined,\n },\n [DeviceModelId.STAX]: {\n data: \"0xSTAX\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"stax-prod-sig\",\n test: \"stax-test-sig\",\n },\n icon: undefined,\n },\n },\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toHaveLength(1);\n const context = result[0];\n if (context && \"payload\" in context) {\n expect(context.payload).toContain(\"0xFLEX\");\n expect(context.payload).toContain(\"flex-prod-sig\");\n }\n });\n\n it(\"should use test mode signature when configured\", async () => {\n // GIVEN\n const testModeLoader = new DynamicNetworkContextLoader(\n mockNetworkDataSource,\n { ...mockConfig, cal: { ...mockConfig.cal, mode: \"test\" } },\n mockCertificateLoader,\n );\n const transaction: TransactionContext = {\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n to: \"0x123\",\n data: \"0x456\",\n selector: \"0x789\",\n };\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"ethereum\",\n descriptors: {\n [DeviceModelId.APEX]: createMockDescriptor(),\n [DeviceModelId.NANO_S]: createMockDescriptor(),\n [DeviceModelId.NANO_SP]: createMockDescriptor(),\n [DeviceModelId.NANO_X]: createMockDescriptor(),\n [DeviceModelId.FLEX]: createMockDescriptor(),\n [DeviceModelId.STAX]: {\n data: \"0x0101\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"prod-sig\",\n test: \"test-sig\",\n },\n icon: undefined,\n },\n },\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await testModeLoader.load(transaction);\n\n // THEN\n expect(result).toHaveLength(1);\n const context = result[0];\n if (context && \"payload\" in context) {\n expect(context.payload).toContain(\"test-sig\");\n }\n });\n });\n});\n"],
5
- "mappings": "aAAA,IAAAA,EAA8B,2CAC9BC,EAA4B,qBAI5BC,EAA4C,gEAM5CC,EAAsB,6BACtBC,EAAyB,gCAEzBC,EAAqC,2CAGrC,SAAS,8BAA+B,IAAM,CAC5C,MAAMC,EAAkD,CACtD,+BAAgC,GAAG,GAAG,CACxC,EAEMC,EAAa,CACjB,IAAK,CACH,IAAK,+CACL,KAAM,OACN,OAAQ,MACV,CACF,EAEMC,EAA8C,CAClD,gBAAiB,GAAG,GAAG,CACzB,EAEMC,EAAkC,CACtC,eAAgB,EAChB,QAAS,IAAI,WA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EAAqB,EAC7C,CAAC,gBAAc,OAAO,EAAGA,EAAqB,EAC9C,CAAC,gBAAc,MAAM,EAAGA,EAAqB,EAC7C,CAAC,gBAAc,IAAI,EAAGA,EAAqB,EAC3C,CAAC,gBAAc,IAAI,EAAG,CACpB,KAAM,SACN,eAAgB,UAChB,kBAAmB,KACnB,WAAY,CACV,KAAM,WACN,KAAM,UACR,EACA,KAAM,MACR,CACF,CACF,EACA,GAAG,MACDL,EACA,gCACF,EAAE,qBAAkB,SAAMS,CAAa,CAAC,EAGxC,MAAMD,EAAS,MAAMG,EAAe,KAAKJ,CAAW,EAGpD,OAAOC,CAAM,EAAE,aAAa,CAAC,EAC7B,MAAME,EAAUF,EAAO,CAAC,EACpBE,GAAW,YAAaA,GAC1B,OAAOA,EAAQ,OAAO,EAAE,UAAU,UAAU,CAEhD,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["import_device_management_kit", "import_purify_ts", "import_DynamicNetworkContextLoader", "import_KeyId", "import_KeyUsage", "import_ClearSignContext", "mockNetworkDataSource", "mockConfig", "mockCertificateLoader", "mockCertificate", "loader", "createMockDescriptor", "partial", "transaction", "result", "networkConfig", "context", "testModeLoader"]
4
+ "sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { type DynamicNetworkDataSource } from \"@/dynamic-network/data/DynamicNetworkDataSource\";\nimport {\n type DynamicNetworkContextInput,\n DynamicNetworkContextLoader,\n} from \"@/dynamic-network/domain/DynamicNetworkContextLoader\";\nimport {\n type DynamicNetworkConfiguration,\n type DynamicNetworkDescriptor,\n} from \"@/dynamic-network/model/DynamicNetworkConfiguration\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { type PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\n\ndescribe(\"DynamicNetworkContextLoader\", () => {\n const mockNetworkDataSource: DynamicNetworkDataSource = {\n getDynamicNetworkConfiguration: vi.fn(),\n };\n\n const mockConfig = {\n cal: {\n url: \"https://crypto-assets-service.api.ledger.com\",\n mode: \"prod\",\n branch: \"main\",\n },\n } as ContextModuleConfig;\n\n const mockCertificateLoader: PkiCertificateLoader = {\n loadCertificate: vi.fn(),\n };\n\n const mockCertificate: PkiCertificate = {\n keyUsageNumber: 1,\n payload: new Uint8Array([0x01, 0x02, 0x03]),\n };\n\n const loader = new DynamicNetworkContextLoader(\n mockNetworkDataSource,\n mockConfig,\n mockCertificateLoader,\n );\n\n // Helper function to create a mock NetworkDescriptor\n const createMockDescriptor = (\n partial?: Partial<DynamicNetworkDescriptor>,\n ): DynamicNetworkDescriptor => ({\n data: \"\",\n descriptorType: \"\",\n descriptorVersion: \"\",\n signatures: {\n prod: \"\",\n test: \"\",\n },\n icon: undefined,\n ...partial,\n });\n\n beforeEach(() => {\n vi.restoreAllMocks();\n vi.spyOn(mockCertificateLoader, \"loadCertificate\").mockResolvedValue(\n mockCertificate,\n );\n });\n\n describe(\"canHandle function\", () => {\n const validInput: DynamicNetworkContextInput = {\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n };\n\n it(\"should return true for valid input\", () => {\n expect(\n loader.canHandle(validInput, [\n ClearSignContextType.DYNAMIC_NETWORK,\n ClearSignContextType.DYNAMIC_NETWORK_ICON,\n ]),\n ).toBe(true);\n });\n\n it(\"should return false for invalid expected type\", () => {\n expect(loader.canHandle(validInput, [ClearSignContextType.TOKEN])).toBe(\n false,\n );\n expect(\n loader.canHandle(validInput, [ClearSignContextType.DYNAMIC_NETWORK]),\n ).toBe(false);\n expect(\n loader.canHandle(validInput, [\n ClearSignContextType.DYNAMIC_NETWORK_ICON,\n ]),\n ).toBe(false);\n });\n\n it.each([\n [null, \"null input\"],\n [undefined, \"undefined input\"],\n [{}, \"empty object\"],\n [\"string\", \"string input\"],\n [123, \"number input\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(\n loader.canHandle(input, [\n ClearSignContextType.DYNAMIC_NETWORK,\n ClearSignContextType.DYNAMIC_NETWORK_ICON,\n ]),\n ).toBe(false);\n });\n\n it.each([\n [{ ...validInput, chainId: undefined }, \"missing chainId\"],\n [{ ...validInput, deviceModelId: undefined }, \"missing deviceModelId\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(\n loader.canHandle(input, [\n ClearSignContextType.DYNAMIC_NETWORK,\n ClearSignContextType.DYNAMIC_NETWORK_ICON,\n ]),\n ).toBe(false);\n });\n\n it.each([\n [{ ...validInput, chainId: \"1\" }, \"string chainId\"],\n [{ ...validInput, chainId: null }, \"null chainId\"],\n [\n { ...validInput, deviceModelId: DeviceModelId.NANO_S },\n \"NANO_S deviceModelId\",\n ],\n ])(\"should return false for %s\", (input, _description) => {\n expect(\n loader.canHandle(input, [\n ClearSignContextType.DYNAMIC_NETWORK,\n ClearSignContextType.DYNAMIC_NETWORK_ICON,\n ]),\n ).toBe(false);\n });\n });\n\n describe(\"load function\", () => {\n it(\"should return empty array when network data source returns error\", async () => {\n // GIVEN\n const input: DynamicNetworkContextInput = {\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Left(new Error(\"Network error\")));\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([]);\n expect(\n mockNetworkDataSource.getDynamicNetworkConfiguration,\n ).toHaveBeenCalledWith(1);\n });\n\n it(\"should return empty array when descriptor for device model is not found\", async () => {\n // GIVEN\n const input: DynamicNetworkContextInput = {\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n };\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"ethereum\",\n descriptors: {\n [DeviceModelId.NANO_S]: createMockDescriptor(),\n [DeviceModelId.NANO_SP]: createMockDescriptor(),\n [DeviceModelId.NANO_X]: createMockDescriptor(),\n // STAX descriptor is intentionally missing\n [DeviceModelId.FLEX]: createMockDescriptor({\n data: \"0x0101\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"prod-sig\",\n test: \"test-sig\",\n },\n icon: undefined,\n }),\n } as Record<DeviceModelId, DynamicNetworkDescriptor>,\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return empty array when signature for mode is not found\", async () => {\n // GIVEN\n const input: DynamicNetworkContextInput = {\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n };\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"ethereum\",\n descriptors: {\n [DeviceModelId.APEX]: createMockDescriptor(),\n [DeviceModelId.NANO_S]: createMockDescriptor(),\n [DeviceModelId.NANO_SP]: createMockDescriptor(),\n [DeviceModelId.NANO_X]: createMockDescriptor(),\n [DeviceModelId.FLEX]: createMockDescriptor(),\n [DeviceModelId.STAX]: createMockDescriptor({\n data: \"0x0101\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n test: \"test-sig\",\n // Missing prod signature - intentionally partial\n } as { prod: string; test: string },\n icon: undefined,\n }),\n },\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return context with network configuration when all data is available\", async () => {\n // GIVEN\n const input: DynamicNetworkContextInput = {\n chainId: 137,\n deviceModelId: DeviceModelId.STAX,\n };\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"polygon\",\n descriptors: {\n [DeviceModelId.APEX]: createMockDescriptor(),\n [DeviceModelId.NANO_S]: createMockDescriptor(),\n [DeviceModelId.NANO_SP]: createMockDescriptor(),\n [DeviceModelId.NANO_X]: createMockDescriptor(),\n [DeviceModelId.FLEX]: createMockDescriptor(),\n [DeviceModelId.STAX]: {\n data: \"0x0101080201015101012308000000000000008952\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"3045022100cf42c039c16fc95dc97c09f15cdd93bed0e63ee45cf5c38c2b30bb8a3bc17f8d022053a96c9e51695c3c1c1a31f5cbf84bd6febadc97f4bb02bdc67cf3e24ad0c32d\",\n test: \"test-sig\",\n },\n icon: undefined,\n },\n },\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toHaveLength(1);\n expect(result[0]).toMatchObject({\n type: ClearSignContextType.DYNAMIC_NETWORK,\n payload: expect.stringContaining(\n \"0x0101080201015101012308000000000000008952\",\n ),\n certificate: mockCertificate,\n });\n expect(mockCertificateLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: KeyId.CalNetwork,\n keyUsage: KeyUsage.Network,\n targetDevice: DeviceModelId.STAX,\n });\n });\n\n it(\"should include icon context when icon is available\", async () => {\n // GIVEN\n const input: DynamicNetworkContextInput = {\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n };\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"ethereum\",\n descriptors: {\n [DeviceModelId.APEX]: createMockDescriptor(),\n [DeviceModelId.NANO_S]: createMockDescriptor(),\n [DeviceModelId.NANO_SP]: createMockDescriptor(),\n [DeviceModelId.NANO_X]: createMockDescriptor(),\n [DeviceModelId.FLEX]: createMockDescriptor(),\n [DeviceModelId.STAX]: {\n data: \"0x0101\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"prod-sig\",\n test: \"test-sig\",\n },\n icon: \"icon-hex-data\",\n },\n },\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toHaveLength(2);\n expect(result[0]).toMatchObject({\n type: ClearSignContextType.DYNAMIC_NETWORK,\n payload: expect.any(String),\n certificate: mockCertificate,\n });\n expect(result[1]).toMatchObject({\n type: ClearSignContextType.DYNAMIC_NETWORK_ICON,\n payload: \"icon-hex-data\",\n });\n });\n\n it(\"should handle multiple device models correctly\", async () => {\n // GIVEN\n const input: DynamicNetworkContextInput = {\n chainId: 1,\n deviceModelId: DeviceModelId.FLEX,\n };\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"ethereum\",\n descriptors: {\n [DeviceModelId.APEX]: createMockDescriptor(),\n [DeviceModelId.NANO_S]: createMockDescriptor(),\n [DeviceModelId.NANO_SP]: createMockDescriptor(),\n [DeviceModelId.NANO_X]: createMockDescriptor(),\n [DeviceModelId.FLEX]: {\n data: \"0xFLEX\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"flex-prod-sig\",\n test: \"flex-test-sig\",\n },\n icon: undefined,\n },\n [DeviceModelId.STAX]: {\n data: \"0xSTAX\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"stax-prod-sig\",\n test: \"stax-test-sig\",\n },\n icon: undefined,\n },\n },\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toHaveLength(1);\n const context = result[0];\n if (context && \"payload\" in context) {\n expect(context.payload).toContain(\"0xFLEX\");\n expect(context.payload).toContain(\"flex-prod-sig\");\n }\n });\n\n it(\"should use test mode signature when configured\", async () => {\n // GIVEN\n const testModeLoader = new DynamicNetworkContextLoader(\n mockNetworkDataSource,\n { ...mockConfig, cal: { ...mockConfig.cal, mode: \"test\" } },\n mockCertificateLoader,\n );\n const input: DynamicNetworkContextInput = {\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n };\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"ethereum\",\n descriptors: {\n [DeviceModelId.APEX]: createMockDescriptor(),\n [DeviceModelId.NANO_S]: createMockDescriptor(),\n [DeviceModelId.NANO_SP]: createMockDescriptor(),\n [DeviceModelId.NANO_X]: createMockDescriptor(),\n [DeviceModelId.FLEX]: createMockDescriptor(),\n [DeviceModelId.STAX]: {\n data: \"0x0101\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"prod-sig\",\n test: \"test-sig\",\n },\n icon: undefined,\n },\n },\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await testModeLoader.load(input);\n\n // THEN\n expect(result).toHaveLength(1);\n const context = result[0];\n if (context && \"payload\" in context) {\n expect(context.payload).toContain(\"test-sig\");\n }\n });\n });\n});\n"],
5
+ "mappings": "aAAA,IAAAA,EAA8B,2CAC9BC,EAA4B,qBAI5BC,EAGO,gEAMPC,EAAsB,6BACtBC,EAAyB,gCAEzBC,EAAqC,2CAErC,SAAS,8BAA+B,IAAM,CAC5C,MAAMC,EAAkD,CACtD,+BAAgC,GAAG,GAAG,CACxC,EAEMC,EAAa,CACjB,IAAK,CACH,IAAK,+CACL,KAAM,OACN,OAAQ,MACV,CACF,EAEMC,EAA8C,CAClD,gBAAiB,GAAG,GAAG,CACzB,EAEMC,EAAkC,CACtC,eAAgB,EAChB,QAAS,IAAI,WAAW,CAAC,EAAM,EAAM,CAAI,CAAC,CAC5C,EAEMC,EAAS,IAAI,8BACjBJ,EACAC,EACAC,CACF,EAGMG,EACJC,IAC8B,CAC9B,KAAM,GACN,eAAgB,GAChB,kBAAmB,GACnB,WAAY,CACV,KAAM,GACN,KAAM,EACR,EACA,KAAM,OACN,GAAGA,CACL,GAEA,WAAW,IAAM,CACf,GAAG,gBAAg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,gCACF,EAAE,qBAAkB,SAAMW,CAAa,CAAC,EAGxC,MAAMD,EAAS,MAAMG,EAAe,KAAKL,CAAK,EAG9C,OAAOE,CAAM,EAAE,aAAa,CAAC,EAC7B,MAAME,EAAUF,EAAO,CAAC,EACpBE,GAAW,YAAaA,GAC1B,OAAOA,EAAQ,OAAO,EAAE,UAAU,UAAU,CAEhD,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["import_device_management_kit", "import_purify_ts", "import_DynamicNetworkContextLoader", "import_KeyId", "import_KeyUsage", "import_ClearSignContext", "mockNetworkDataSource", "mockConfig", "mockCertificateLoader", "mockCertificate", "loader", "createMockDescriptor", "partial", "validInput", "input", "_description", "result", "networkConfig", "context", "testModeLoader"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var g=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var O=(o,t)=>{for(var a in t)g(o,a,{get:t[a],enumerable:!0})},_=(o,t,a,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of I(t))!w.call(o,r)&&r!==a&&g(o,r,{get:()=>t[r],enumerable:!(e=S(t,r))||e.enumerable});return o};var v=o=>_(g({},"__esModule",{value:!0}),o),y=(o,t,a,e)=>{for(var r=e>1?void 0:e?S(t,a):t,n=o.length-1,c;n>=0;n--)(c=o[n])&&(r=(e?c(t,a,r):c(r))||r);return e&&r&&g(t,a,r),r},D=(o,t)=>(a,e)=>t(a,e,o);var L={};O(L,{ExternalPluginContextLoader:()=>d});module.exports=v(L);var h=require("@ledgerhq/device-management-kit"),E=require("ethers"),p=require("inversify"),s=require("purify-ts"),R=require("../../external-plugin/di/externalPluginTypes"),i=require("../../shared/model/ClearSignContext"),P=require("../../token/di/tokenTypes");let d=class{_externalPluginDataSource;_tokenDataSource;constructor(t,a){this._externalPluginDataSource=t,this._tokenDataSource=a}async load(t){const{to:a,data:e,selector:r,chainId:n}=t;if(a===void 0||e==="0x")return[];if(!(0,h.isHexaString)(r))return[{type:i.ClearSignContextType.ERROR,error:new Error("Invalid selector")}];const c=await this._externalPluginDataSource.getDappInfos({address:a,chainId:n,selector:r});return(0,s.EitherAsync)(async({liftEither:u})=>{const l=await u(c);if(!l)return[];const C={type:i.ClearSignContextType.EXTERNAL_PLUGIN,payload:l.selectorDetails.serializedData.concat(l.selectorDetails.signature)},x=this.getDecodedCallData(l.abi,l.selectorDetails.method,e);if(x.isLeft())return[{type:i.ClearSignContextType.ERROR,error:x.extract()},C];const k=x.extract(),T=l.selectorDetails.erc20OfInterest.map(async f=>this.getTokenPayload(t,f,k));return[...(await Promise.all(T)).map(f=>f.caseOf({Left:m=>({type:i.ClearSignContextType.ERROR,error:m}),Right:m=>({type:i.ClearSignContextType.TOKEN,payload:m})})),C]}).caseOf({Left:u=>[{type:i.ClearSignContextType.ERROR,error:u}],Right:u=>u})}getTokenPayload(t,a,e){const r=this.getAddressFromPath(a,e);return(0,s.EitherAsync)(({fromPromise:n})=>n(this._tokenDataSource.getTokenInfosPayload({address:r,chainId:t.chainId})))}getDecodedCallData(t,a,e){try{const r=new E.Interface(t);return(0,s.Right)(r.decodeFunctionData(a,e))}catch{return(0,s.Left)(new Error("[ContextModule] ExternalPluginContextLoader: Unable to parse abi"))}}getAddressFromPath(t,a){let e=a;for(const r of t.split("."))r==="-1"?e=e[e.length-1]:e=e[r];if(!(0,h.isHexaString)(e))throw new Error("[ContextModule] ExternalPluginContextLoader: Unable to get address");return e}};d=y([(0,p.injectable)(),D(0,(0,p.inject)(R.externalPluginTypes.ExternalPluginDataSource)),D(1,(0,p.inject)(P.tokenTypes.TokenDataSource))],d);0&&(module.exports={ExternalPluginContextLoader});
1
+ "use strict";var p=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var b=(n,e)=>{for(var r in e)p(n,r,{get:e[r],enumerable:!0})},L=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of k(e))!_.call(n,a)&&a!==r&&p(n,a,{get:()=>e[a],enumerable:!(t=h(e,a))||t.enumerable});return n};var O=n=>L(p({},"__esModule",{value:!0}),n),y=(n,e,r,t)=>{for(var a=t>1?void 0:t?h(e,r):e,s=n.length-1,c;s>=0;s--)(c=n[s])&&(a=(t?c(e,r,a):c(a))||a);return t&&a&&p(e,r,a),a},D=(n,e)=>(r,t)=>e(r,t,n);var v={};b(v,{ExternalPluginContextLoader:()=>x});module.exports=O(v);var g=require("@ledgerhq/device-management-kit"),E=require("ethers"),u=require("inversify"),i=require("purify-ts"),P=require("../../external-plugin/di/externalPluginTypes"),o=require("../../shared/model/ClearSignContext"),I=require("../../token/di/tokenTypes");const w=[o.ClearSignContextType.EXTERNAL_PLUGIN,o.ClearSignContextType.TOKEN];let x=class{_externalPluginDataSource;_tokenDataSource;constructor(e,r){this._externalPluginDataSource=e,this._tokenDataSource=r}canHandle(e,r){return typeof e=="object"&&e!==null&&"to"in e&&"data"in e&&"selector"in e&&"chainId"in e&&typeof e.chainId=="number"&&(0,g.isHexaString)(e.to)&&e.to!=="0x"&&(0,g.isHexaString)(e.data)&&e.data!=="0x"&&(0,g.isHexaString)(e.selector)&&e.selector!=="0x"&&w.every(t=>r.includes(t))}async load(e){const{to:r,data:t,selector:a,chainId:s}=e,c=await this._externalPluginDataSource.getDappInfos({address:r,chainId:s,selector:a});return(0,i.EitherAsync)(async({liftEither:d})=>{const l=await d(c);if(!l)return[];const f={type:o.ClearSignContextType.EXTERNAL_PLUGIN,payload:l.selectorDetails.serializedData.concat(l.selectorDetails.signature)},S=this.getDecodedCallData(l.abi,l.selectorDetails.method,t);if(S.isLeft())return[{type:o.ClearSignContextType.ERROR,error:S.extract()},f];const R=S.extract(),T=l.selectorDetails.erc20OfInterest.map(async C=>this.getTokenPayload(e,C,R));return[...(await Promise.all(T)).map(C=>C.caseOf({Left:m=>({type:o.ClearSignContextType.ERROR,error:m}),Right:m=>({type:o.ClearSignContextType.TOKEN,payload:m})})),f]}).caseOf({Left:d=>[{type:o.ClearSignContextType.ERROR,error:d}],Right:d=>d})}getTokenPayload(e,r,t){const a=this.getAddressFromPath(r,t);return(0,i.EitherAsync)(({fromPromise:s})=>s(this._tokenDataSource.getTokenInfosPayload({address:a,chainId:e.chainId})))}getDecodedCallData(e,r,t){try{const a=new E.Interface(e);return(0,i.Right)(a.decodeFunctionData(r,t))}catch{return(0,i.Left)(new Error("[ContextModule] ExternalPluginContextLoader: Unable to parse abi"))}}getAddressFromPath(e,r){let t=r;for(const a of e.split("."))a==="-1"?t=t[t.length-1]:t=t[a];if(!(0,g.isHexaString)(t))throw new Error("[ContextModule] ExternalPluginContextLoader: Unable to get address");return t}};x=y([(0,u.injectable)(),D(0,(0,u.inject)(P.externalPluginTypes.ExternalPluginDataSource)),D(1,(0,u.inject)(I.tokenTypes.TokenDataSource))],x);0&&(module.exports={ExternalPluginContextLoader});
2
2
  //# sourceMappingURL=ExternalPluginContextLoader.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/external-plugin/domain/ExternalPluginContextLoader.ts"],
4
- "sourcesContent": ["import { HexaString, isHexaString } from \"@ledgerhq/device-management-kit\";\nimport { ethers, Interface } from \"ethers\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, EitherAsync, Left, Right } from \"purify-ts\";\n\nimport type { ExternalPluginDataSource } from \"@/external-plugin/data/ExternalPluginDataSource\";\nimport { externalPluginTypes } from \"@/external-plugin/di/externalPluginTypes\";\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { TransactionContext } from \"@/shared/model/TransactionContext\";\nimport type { TokenDataSource } from \"@/token/data/TokenDataSource\";\nimport { tokenTypes } from \"@/token/di/tokenTypes\";\n\n@injectable()\nexport class ExternalPluginContextLoader implements ContextLoader {\n private _externalPluginDataSource: ExternalPluginDataSource;\n private _tokenDataSource: TokenDataSource;\n\n constructor(\n @inject(externalPluginTypes.ExternalPluginDataSource)\n externalPluginDataSource: ExternalPluginDataSource,\n @inject(tokenTypes.TokenDataSource) tokenDataSource: TokenDataSource,\n ) {\n this._externalPluginDataSource = externalPluginDataSource;\n this._tokenDataSource = tokenDataSource;\n }\n\n async load(ctx: TransactionContext): Promise<ClearSignContext[]> {\n const { to, data, selector, chainId } = ctx;\n if (to === undefined || data === \"0x\") {\n return [];\n }\n\n if (!isHexaString(selector)) {\n return [\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Invalid selector\"),\n },\n ];\n }\n\n const eitherDappInfos = await this._externalPluginDataSource.getDappInfos({\n address: to,\n chainId,\n selector,\n });\n\n return EitherAsync<Error, ClearSignContext[]>(async ({ liftEither }) => {\n const dappInfos = await liftEither(eitherDappInfos);\n\n // if the dappInfos is null, return an empty array\n // this means that the selector is not a known selector\n if (!dappInfos) {\n return [];\n }\n\n const externalPluginContext: ClearSignContext = {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: dappInfos.selectorDetails.serializedData.concat(\n dappInfos.selectorDetails.signature,\n ),\n };\n\n const decodedCallData = this.getDecodedCallData(\n dappInfos.abi,\n dappInfos.selectorDetails.method,\n data,\n );\n\n // if the call data cannot be decoded, return the error\n // but also the externalPluginContext because it is still valid\n if (decodedCallData.isLeft()) {\n return [\n {\n type: ClearSignContextType.ERROR,\n error: decodedCallData.extract(),\n },\n externalPluginContext,\n ];\n }\n\n // decodedCallData is a Right so we can extract it safely\n const extractedDecodedCallData =\n decodedCallData.extract() as ethers.Result;\n\n // get the token payload for each erc20OfInterest\n // and return the payload or the error\n const promises = dappInfos.selectorDetails.erc20OfInterest.map(\n async (erc20Path) =>\n this.getTokenPayload(ctx, erc20Path, extractedDecodedCallData),\n );\n\n const tokensPayload = await Promise.all(promises);\n\n // map the payload or the error to a ClearSignContext\n const contexts: ClearSignContext[] = tokensPayload.map((eitherToken) =>\n eitherToken.caseOf<ClearSignContext>({\n Left: (error) => ({ type: ClearSignContextType.ERROR, error }),\n Right: (payload) => ({ type: ClearSignContextType.TOKEN, payload }),\n }),\n );\n\n return [...contexts, externalPluginContext];\n }).caseOf<ClearSignContext[]>({\n // parse all errors into ClearSignContext\n Left: (error) => [{ type: ClearSignContextType.ERROR, error }],\n Right: (contexts) => contexts,\n });\n }\n\n private getTokenPayload(\n ctx: TransactionContext,\n erc20Path: string,\n decodedCallData: ethers.Result,\n ) {\n const address = this.getAddressFromPath(erc20Path, decodedCallData);\n\n return EitherAsync<Error, string>(({ fromPromise }) =>\n fromPromise(\n this._tokenDataSource.getTokenInfosPayload({\n address,\n chainId: ctx.chainId,\n }),\n ),\n );\n }\n\n private getDecodedCallData(\n abi: object[],\n method: string,\n data: string,\n ): Either<Error, ethers.Result> {\n try {\n const contractInterface = new Interface(abi);\n return Right(contractInterface.decodeFunctionData(method, data));\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] ExternalPluginContextLoader: Unable to parse abi\",\n ),\n );\n }\n }\n\n private getAddressFromPath(\n path: string,\n decodedCallData: ethers.Result,\n ): HexaString {\n // ethers.Result is a record string, any\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let value: any = decodedCallData;\n for (const key of path.split(\".\")) {\n // In Solidity, a struct cannot begin with a number\n // Additionally, when we use -1, it signifies the last element of the array.\n if (key === \"-1\") {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n value = value[value.length - 1];\n } else {\n // This access can throw a RangeError error in case of an invalid key\n // but is correctly caught by the liftEither above\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n value = value[key];\n }\n }\n\n if (!isHexaString(value)) {\n throw new Error(\n \"[ContextModule] ExternalPluginContextLoader: Unable to get address\",\n );\n }\n\n return value;\n }\n}\n"],
5
- "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iCAAAE,IAAA,eAAAC,E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OAAyB,CACnC,KAAOC,IAAW,CAAE,KAAM,uBAAqB,MAAO,MAAAA,CAAM,GAC5D,MAAQC,IAAa,CAAE,KAAM,uBAAqB,MAAO,QAAAA,CAAQ,EACnE,CAAC,CACH,EAEqBP,CAAqB,CAC5C,CAAC,EAAE,OAA2B,CAE5B,KAAOM,GAAU,CAAC,CAAE,KAAM,uBAAqB,MAAO,MAAAA,CAAM,CAAC,EAC7D,MAAQE,GAAaA,CACvB,CAAC,CACH,CAEQ,gBACNhB,EACAY,EACAH,EACA,CACA,MAAMQ,EAAU,KAAK,mBAAmBL,EAAWH,CAAe,EAElE,SAAO,eAA2B,CAAC,CAAE,YAAAS,CAAY,IAC/CA,EACE,KAAK,iBAAiB,qBAAqB,CACzC,QAAAD,EACA,QAASjB,EAAI,OACf,CAAC,CACH,CACF,CACF,CAEQ,mBACNmB,EACAC,EACAlB,EAC8B,CAC9B,GAAI,CACF,MAAMmB,EAAoB,IAAI,YAAUF,CAAG,EAC3C,SAAO,SAAME,EAAkB,mBAAmBD,EAAQlB,CAAI,CAAC,CACjE,MAAiB,CACf,SAAO,QACL,IAAI,MACF,kEACF,CACF,CACF,CACF,CAEQ,mBACNoB,EACAb,EACY,CAGZ,IAAIc,EAAad,EACjB,UAAWe,KAAOF,EAAK,MAAM,GAAG,EAG1BE,IAAQ,KAEVD,EAAQA,EAAMA,EAAM,OAAS,CAAC,EAK9BA,EAAQA,EAAMC,CAAG,EAIrB,GAAI,IAAC,gBAAaD,CAAK,EACrB,MAAM,IAAI,MACR,oEACF,EAGF,OAAOA,CACT,CACF,EAhKa1B,EAAN4B,EAAA,IADN,cAAW,EAMPC,EAAA,eAAO,sBAAoB,wBAAwB,GAEnDA,EAAA,eAAO,aAAW,eAAe,IAPzB7B",
6
- "names": ["ExternalPluginContextLoader_exports", "__export", "ExternalPluginContextLoader", "__toCommonJS", "import_device_management_kit", "import_ethers", "import_inversify", "import_purify_ts", "import_externalPluginTypes", "import_ClearSignContext", "import_tokenTypes", "ExternalPluginContextLoader", "externalPluginDataSource", "tokenDataSource", "ctx", "to", "data", "selector", "chainId", "eitherDappInfos", "liftEither", "dappInfos", "externalPluginContext", "decodedCallData", "extractedDecodedCallData", "promises", "erc20Path", "eitherToken", "error", "payload", "contexts", "address", "fromPromise", "abi", "method", "contractInterface", "path", "value", "key", "__decorateClass", "__decorateParam"]
4
+ "sourcesContent": ["import { HexaString, isHexaString } from \"@ledgerhq/device-management-kit\";\nimport { ethers, Interface } from \"ethers\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, EitherAsync, Left, Right } from \"purify-ts\";\n\nimport type { ExternalPluginDataSource } from \"@/external-plugin/data/ExternalPluginDataSource\";\nimport { externalPluginTypes } from \"@/external-plugin/di/externalPluginTypes\";\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport type { TokenDataSource } from \"@/token/data/TokenDataSource\";\nimport { tokenTypes } from \"@/token/di/tokenTypes\";\n\nexport type ExternalPluginContextInput = {\n to: HexaString;\n data: HexaString;\n selector: HexaString;\n chainId: number;\n};\n\nconst SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.EXTERNAL_PLUGIN,\n ClearSignContextType.TOKEN,\n];\n\n@injectable()\nexport class ExternalPluginContextLoader\n implements ContextLoader<ExternalPluginContextInput>\n{\n private _externalPluginDataSource: ExternalPluginDataSource;\n private _tokenDataSource: TokenDataSource;\n\n constructor(\n @inject(externalPluginTypes.ExternalPluginDataSource)\n externalPluginDataSource: ExternalPluginDataSource,\n @inject(tokenTypes.TokenDataSource) tokenDataSource: TokenDataSource,\n ) {\n this._externalPluginDataSource = externalPluginDataSource;\n this._tokenDataSource = tokenDataSource;\n }\n\n canHandle(\n input: unknown,\n expectedTypes: ClearSignContextType[],\n ): input is ExternalPluginContextInput {\n return (\n typeof input === \"object\" &&\n input !== null &&\n \"to\" in input &&\n \"data\" in input &&\n \"selector\" in input &&\n \"chainId\" in input &&\n typeof input.chainId === \"number\" &&\n isHexaString(input.to) &&\n input.to !== \"0x\" &&\n isHexaString(input.data) &&\n input.data !== \"0x\" && // non empty data\n isHexaString(input.selector) &&\n input.selector !== \"0x\" &&\n SUPPORTED_TYPES.every((type) => expectedTypes.includes(type))\n );\n }\n\n async load(input: ExternalPluginContextInput): Promise<ClearSignContext[]> {\n const { to, data, selector, chainId } = input;\n\n const eitherDappInfos = await this._externalPluginDataSource.getDappInfos({\n address: to,\n chainId,\n selector,\n });\n\n return EitherAsync<Error, ClearSignContext[]>(async ({ liftEither }) => {\n const dappInfos = await liftEither(eitherDappInfos);\n\n // if the dappInfos is null, return an empty array\n // this means that the selector is not a known selector\n if (!dappInfos) {\n return [];\n }\n\n const externalPluginContext: ClearSignContext = {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: dappInfos.selectorDetails.serializedData.concat(\n dappInfos.selectorDetails.signature,\n ),\n };\n\n const decodedCallData = this.getDecodedCallData(\n dappInfos.abi,\n dappInfos.selectorDetails.method,\n data,\n );\n\n // if the call data cannot be decoded, return the error\n // but also the externalPluginContext because it is still valid\n if (decodedCallData.isLeft()) {\n return [\n {\n type: ClearSignContextType.ERROR,\n error: decodedCallData.extract(),\n },\n externalPluginContext,\n ];\n }\n\n // decodedCallData is a Right so we can extract it safely\n const extractedDecodedCallData =\n decodedCallData.extract() as ethers.Result;\n\n // get the token payload for each erc20OfInterest\n // and return the payload or the error\n const promises = dappInfos.selectorDetails.erc20OfInterest.map(\n async (erc20Path) =>\n this.getTokenPayload(input, erc20Path, extractedDecodedCallData),\n );\n\n const tokensPayload = await Promise.all(promises);\n\n // map the payload or the error to a ClearSignContext\n const contexts: ClearSignContext[] = tokensPayload.map((eitherToken) =>\n eitherToken.caseOf<ClearSignContext>({\n Left: (error) => ({ type: ClearSignContextType.ERROR, error }),\n Right: (payload) => ({ type: ClearSignContextType.TOKEN, payload }),\n }),\n );\n\n return [...contexts, externalPluginContext];\n }).caseOf<ClearSignContext[]>({\n // parse all errors into ClearSignContext\n Left: (error) => [{ type: ClearSignContextType.ERROR, error }],\n Right: (contexts) => contexts,\n });\n }\n\n private getTokenPayload(\n input: ExternalPluginContextInput,\n erc20Path: string,\n decodedCallData: ethers.Result,\n ) {\n const address = this.getAddressFromPath(erc20Path, decodedCallData);\n\n return EitherAsync<Error, string>(({ fromPromise }) =>\n fromPromise(\n this._tokenDataSource.getTokenInfosPayload({\n address,\n chainId: input.chainId,\n }),\n ),\n );\n }\n\n private getDecodedCallData(\n abi: object[],\n method: string,\n data: string,\n ): Either<Error, ethers.Result> {\n try {\n const contractInterface = new Interface(abi);\n return Right(contractInterface.decodeFunctionData(method, data));\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] ExternalPluginContextLoader: Unable to parse abi\",\n ),\n );\n }\n }\n\n private getAddressFromPath(\n path: string,\n decodedCallData: ethers.Result,\n ): HexaString {\n // ethers.Result is a record string, any\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let value: any = decodedCallData;\n for (const key of path.split(\".\")) {\n // In Solidity, a struct cannot begin with a number\n // Additionally, when we use -1, it signifies the last element of the array.\n if (key === \"-1\") {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n value = value[value.length - 1];\n } else {\n // This access can throw a RangeError error in case of an invalid key\n // but is correctly caught by the liftEither above\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n value = value[key];\n }\n }\n\n if (!isHexaString(value)) {\n throw new Error(\n \"[ContextModule] ExternalPluginContextLoader: Unable to get address\",\n );\n }\n\n return value;\n }\n}\n"],
5
+ "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAyC,2CACzCC,EAAkC,kBAClCC,EAAmC,qBACnCC,EAAiD,qBAGjDC,EAAoC,oDAEpCC,EAGO,2CAEPC,EAA2B,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", "__toCommonJS", "import_device_management_kit", "import_ethers", "import_inversify", "import_purify_ts", "import_externalPluginTypes", "import_ClearSignContext", "import_tokenTypes", "SUPPORTED_TYPES", "ExternalPluginContextLoader", "externalPluginDataSource", "tokenDataSource", "input", "expectedTypes", "type", "to", "data", "selector", "chainId", "eitherDappInfos", "liftEither", "dappInfos", "externalPluginContext", "decodedCallData", "extractedDecodedCallData", "promises", "erc20Path", "eitherToken", "error", "payload", "contexts", "address", "fromPromise", "abi", "method", "contractInterface", "path", "value", "key", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var y=Object.create;var i=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var b=(s,o,r,a)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of f(o))!D.call(s,e)&&e!==r&&i(s,e,{get:()=>o[e],enumerable:!(a=E(o,e))||a.enumerable});return s};var I=(s,o,r)=>(r=s!=null?y(x(s)):{},b(o||!s||!s.__esModule?i(r,"default",{value:s,enumerable:!0}):r,s));var m=require("ethers"),l=require("purify-ts"),n=I(require("@/external-plugin/__tests__/abi.json")),u=require("../../external-plugin/domain/ExternalPluginContextLoader"),t=require("../../shared/model/ClearSignContext");const d=({abi:s,selectorDetails:o})=>({abi:s,selectorDetails:{erc20OfInterest:[],method:"",plugin:"",serializedData:"123456",signature:"7890",...o}}),p=(s,o,r)=>{const e=new m.Interface(JSON.stringify(s)).encodeFunctionData(o,r);return{to:"0x0",data:e,selector:e.slice(0,10)}};describe("ExternalPluginContextLoader",()=>{const s={getTokenInfosPayload:vi.fn()},o={getDappInfos:vi.fn()},r=new u.ExternalPluginContextLoader(o,s);beforeEach(()=>{vi.clearAllMocks(),vi.spyOn(s,"getTokenInfosPayload").mockImplementation(({address:a})=>Promise.resolve((0,l.Right)(`payload-${a}`)))}),describe("load function",()=>{it("should return an empty array if no destination address is provided",async()=>{const a={},e=()=>r.load(a);await expect(e()).resolves.toEqual([])}),it("should return an empty array if no data provided",async()=>{const a={to:"0x0",data:"0x",selector:"0x0"},e=await r.load(a);expect(e).toEqual([])}),it("should return an empty array if no dapp info is povided",async()=>{const a=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(void 0));const e=await r.load(a);expect(e).toEqual([])}),it("should return e plugin if no erc20OfInterest is provided",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:[],method:"singleParam"}}),e=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return a list of context responses when one erc20OfInterest is provided for a single parameter",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),e=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual(expect.arrayContaining([{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"}]))}),it("should return a context response with only set external plugin when one erc20OfInterest is provided for a single parameter but no payload is feched",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),e=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a)),vi.spyOn(s,"getTokenInfosPayload").mockResolvedValue((0,l.Left)(Error("error")));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.ERROR,error:new Error("error")},{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return a list of context responses when two erc20OfInterest are provided for two parameters",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["fromToken","toToken"],method:"multipleParams"}}),e=p(n.default,"multipleParams",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual(expect.arrayContaining([{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"}]))}),it("should return a list of context responses when one erc20OfInterest is an array",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["fromToken.0","fromToken.1","fromToken.2","fromToken.-1"],method:"arrayParam"}}),e=p(n.default,"arrayParam",[["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7","0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return an error when a token datasource returns an error",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),e=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a)),vi.spyOn(s,"getTokenInfosPayload").mockResolvedValue((0,l.Left)(new Error("error")));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.ERROR,error:new Error("error")},{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return an error when the abi is not conform",async()=>{const a=d({abi:[{fakeabi:"notworking"}],selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),e=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.ERROR,error:new Error("[ContextModule] ExternalPluginContextLoader: Unable to parse abi")},{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should throw an error when the erc20OfInterest doest not exist in the transaction",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["notFound"],method:"singleParam"}}),e=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.ERROR,error:new Error("[ContextModule] ExternalPluginContextLoader: Unable to get address")}])}),it("should throw an error when an out-of-bounds element is present in erc20OfInterest",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["fromToken.3"],method:"arrayParam"}}),e=p(n.default,"arrayParam",[["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7","0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.ERROR,error:new RangeError("out of result range")}])}),it("should return a list of context responses when one erc20OfInterest is a complex struct",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["complexStruct.address1","complexStruct.param1.param2.0.param3.addresses.0","complexStruct.param1.param2.0.param3.addresses.1","complexStruct.param1.param2.0.param3.addresses.-1","complexStruct.param1.param2.1.param3.addresses.0","complexStruct.param1.param2.-1.param3.addresses.0"],method:"complexStructParam"}}),e=p(n.default,"complexStructParam",[{address1:"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",param1:{param2:[{param3:{addresses:["0xdAC17F958D2ee523a2206206994597C13D831ec7","0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"]}},{param3:{addresses:["0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]}}]}}]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return an error when datasource return a Left",async()=>{const a=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Left)(new Error("error")));const e=await r.load(a);expect(e).toEqual([{type:t.ClearSignContextType.ERROR,error:new Error("error")}])}),it("should return an error when transaction data is not a valid hex string",async()=>{const a={to:"0x0",data:"notAHexString"},e=await r.load(a);expect(e).toEqual([{type:t.ClearSignContextType.ERROR,error:new Error("Invalid selector")}])})})});
1
+ "use strict";var m=Object.create;var i=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var D=(c,n,o,e)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of y(n))!b.call(c,t)&&t!==o&&i(c,t,{get:()=>n[t],enumerable:!(e=f(n,t))||e.enumerable});return c};var I=(c,n,o)=>(o=c!=null?m(x(c)):{},D(n||!c||!c.__esModule?i(o,"default",{value:c,enumerable:!0}):o,c));var u=require("ethers"),l=require("purify-ts"),s=I(require("@/external-plugin/__tests__/abi.json")),E=require("../../external-plugin/domain/ExternalPluginContextLoader"),a=require("../../shared/model/ClearSignContext");const p=({abi:c,selectorDetails:n})=>({abi:c,selectorDetails:{erc20OfInterest:[],method:"",plugin:"",serializedData:"123456",signature:"7890",...n}}),d=(c,n,o)=>{const t=new u.Interface(JSON.stringify(c)).encodeFunctionData(n,o);return{to:"0x0",data:t,selector:t.slice(0,10),chainId:1}};describe("ExternalPluginContextLoader",()=>{const c={getTokenInfosPayload:vi.fn()},n={getDappInfos:vi.fn()},o=new E.ExternalPluginContextLoader(n,c);beforeEach(()=>{vi.clearAllMocks(),vi.spyOn(c,"getTokenInfosPayload").mockImplementation(({address:e})=>Promise.resolve((0,l.Right)(`payload-${e}`)))}),describe("canHandle function",()=>{const e={to:"0x1234567890123456789012345678901234567890",data:"0x095ea7b30000000000000000000000001234567890123456789012345678901234567890",selector:"0x095ea7b3",chainId:1};it("should return true for valid input",()=>{expect(o.canHandle(e,[a.ClearSignContextType.EXTERNAL_PLUGIN,a.ClearSignContextType.TOKEN])).toBe(!0)}),it("should return false for invalid expected type",()=>{expect(o.canHandle(e,[a.ClearSignContextType.NFT])).toBe(!1),expect(o.canHandle(e,[a.ClearSignContextType.TOKEN])).toBe(!1),expect(o.canHandle(e,[a.ClearSignContextType.EXTERNAL_PLUGIN])).toBe(!1)}),it.each([[null,"null input"],[void 0,"undefined input"],[{},"empty object"],["string","string input"],[123,"number input"]])("should return false for %s",(t,r)=>{expect(o.canHandle(t,[a.ClearSignContextType.EXTERNAL_PLUGIN,a.ClearSignContextType.TOKEN])).toBe(!1)}),it.each([[{...e,to:void 0},"missing to"],[{...e,data:void 0},"missing data"],[{...e,selector:void 0},"missing selector"],[{...e,chainId:void 0},"missing chainId"]])("should return false for %s",(t,r)=>{expect(o.canHandle(t,[a.ClearSignContextType.EXTERNAL_PLUGIN,a.ClearSignContextType.TOKEN])).toBe(!1)}),it.each([[{...e,to:"invalid-hex"},"invalid to hex"],[{...e,to:"0x"},"empty to hex"],[{...e,data:"invalid-hex"},"invalid data hex"],[{...e,data:"0x"},"empty data (0x)"],[{...e,selector:"invalid-hex"},"invalid selector hex"],[{...e,selector:"0x"},"empty selector hex"]])("should return false for %s",(t,r)=>{expect(o.canHandle(t,[a.ClearSignContextType.EXTERNAL_PLUGIN,a.ClearSignContextType.TOKEN])).toBe(!1)}),it.each([[{...e,chainId:"1"},"string chainId"],[{...e,chainId:null},"null chainId"],[{...e,chainId:void 0},"undefined chainId"]])("should return false for %s",(t,r)=>{expect(o.canHandle(t,[a.ClearSignContextType.EXTERNAL_PLUGIN,a.ClearSignContextType.TOKEN])).toBe(!1)})}),describe("load function",()=>{it("should return an empty array if no dapp info is provided",async()=>{const e=d(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Right)(void 0));const t=await o.load(e);expect(t).toEqual([])}),it("should return e plugin if no erc20OfInterest is provided",async()=>{const e=p({abi:s.default,selectorDetails:{erc20OfInterest:[],method:"singleParam"}}),t=d(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Right)(e));const r=await o.load(t);expect(r).toEqual([{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return a list of context responses when one erc20OfInterest is provided for a single parameter",async()=>{const e=p({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),t=d(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Right)(e));const r=await o.load(t);expect(r).toEqual(expect.arrayContaining([{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"}]))}),it("should return a context response with only set external plugin when one erc20OfInterest is provided for a single parameter but no payload is feched",async()=>{const e=p({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),t=d(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Right)(e)),vi.spyOn(c,"getTokenInfosPayload").mockResolvedValue((0,l.Left)(Error("error")));const r=await o.load(t);expect(r).toEqual([{type:a.ClearSignContextType.ERROR,error:new Error("error")},{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return a list of context responses when two erc20OfInterest are provided for two parameters",async()=>{const e=p({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken","toToken"],method:"multipleParams"}}),t=d(s.default,"multipleParams",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7"]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Right)(e));const r=await o.load(t);expect(r).toEqual(expect.arrayContaining([{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"}]))}),it("should return a list of context responses when one erc20OfInterest is an array",async()=>{const e=p({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken.0","fromToken.1","fromToken.2","fromToken.-1"],method:"arrayParam"}}),t=d(s.default,"arrayParam",[["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7","0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Right)(e));const r=await o.load(t);expect(r).toEqual([{type:a.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return an error when a token datasource returns an error",async()=>{const e=p({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),t=d(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Right)(e)),vi.spyOn(c,"getTokenInfosPayload").mockResolvedValue((0,l.Left)(new Error("error")));const r=await o.load(t);expect(r).toEqual([{type:a.ClearSignContextType.ERROR,error:new Error("error")},{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return an error when the abi is not conform",async()=>{const e=p({abi:[{fakeabi:"notworking"}],selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),t=d(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Right)(e));const r=await o.load(t);expect(r).toEqual([{type:a.ClearSignContextType.ERROR,error:new Error("[ContextModule] ExternalPluginContextLoader: Unable to parse abi")},{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should throw an error when the erc20OfInterest doest not exist in the transaction",async()=>{const e=p({abi:s.default,selectorDetails:{erc20OfInterest:["notFound"],method:"singleParam"}}),t=d(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Right)(e));const r=await o.load(t);expect(r).toEqual([{type:a.ClearSignContextType.ERROR,error:new Error("[ContextModule] ExternalPluginContextLoader: Unable to get address")}])}),it("should throw an error when an out-of-bounds element is present in erc20OfInterest",async()=>{const e=p({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken.3"],method:"arrayParam"}}),t=d(s.default,"arrayParam",[["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7","0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Right)(e));const r=await o.load(t);expect(r).toEqual([{type:a.ClearSignContextType.ERROR,error:new RangeError("out of result range")}])}),it("should return a list of context responses when one erc20OfInterest is a complex struct",async()=>{const e=p({abi:s.default,selectorDetails:{erc20OfInterest:["complexStruct.address1","complexStruct.param1.param2.0.param3.addresses.0","complexStruct.param1.param2.0.param3.addresses.1","complexStruct.param1.param2.0.param3.addresses.-1","complexStruct.param1.param2.1.param3.addresses.0","complexStruct.param1.param2.-1.param3.addresses.0"],method:"complexStructParam"}}),t=d(s.default,"complexStructParam",[{address1:"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",param1:{param2:[{param3:{addresses:["0xdAC17F958D2ee523a2206206994597C13D831ec7","0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"]}},{param3:{addresses:["0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]}}]}}]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Right)(e));const r=await o.load(t);expect(r).toEqual([{type:a.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return an error when datasource return a Left",async()=>{const e=d(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Left)(new Error("error")));const t=await o.load(e);expect(t).toEqual([{type:a.ClearSignContextType.ERROR,error:new Error("error")}])})})});
2
2
  //# sourceMappingURL=ExternalPluginContextLoader.test.js.map