@ledgerhq/context-module 1.12.0 → 1.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/lib/cjs/package.json +1 -1
  2. package/lib/cjs/src/ContextModuleBuilder.js +1 -1
  3. package/lib/cjs/src/ContextModuleBuilder.js.map +3 -3
  4. package/lib/cjs/src/ContextModuleBuilder.test.js +1 -1
  5. package/lib/cjs/src/ContextModuleBuilder.test.js.map +3 -3
  6. package/lib/cjs/src/DefaultContextModule.test.js +1 -1
  7. package/lib/cjs/src/DefaultContextModule.test.js.map +3 -3
  8. package/lib/cjs/src/calldata/domain/CalldataContextLoader.js +1 -1
  9. package/lib/cjs/src/calldata/domain/CalldataContextLoader.js.map +3 -3
  10. package/lib/cjs/src/calldata/domain/CalldataContextLoader.test.js +1 -1
  11. package/lib/cjs/src/calldata/domain/CalldataContextLoader.test.js.map +3 -3
  12. package/lib/cjs/src/config/model/ContextModuleBuildArgs.js.map +1 -1
  13. package/lib/cjs/src/config/model/ContextModuleConfig.js +1 -1
  14. package/lib/cjs/src/config/model/ContextModuleConfig.js.map +1 -1
  15. package/lib/cjs/src/di.js +1 -1
  16. package/lib/cjs/src/di.js.map +2 -2
  17. package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.js +1 -1
  18. package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.js.map +3 -3
  19. package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js +1 -1
  20. package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js.map +3 -3
  21. package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.js +1 -1
  22. package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.js.map +3 -3
  23. package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.test.js +1 -1
  24. package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.test.js.map +3 -3
  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/solana/domain/DefaultSolanaContextLoader.js.map +1 -1
  30. package/lib/cjs/src/solana/domain/DefaultSolanaContextLoader.test.js +1 -1
  31. package/lib/cjs/src/solana/domain/DefaultSolanaContextLoader.test.js.map +3 -3
  32. package/lib/cjs/src/solanaLifi/domain/SolanaLifiContextLoader.test.js +1 -1
  33. package/lib/cjs/src/solanaLifi/domain/SolanaLifiContextLoader.test.js.map +3 -3
  34. package/lib/cjs/src/solanaToken/domain/SolanaTokenContextLoader.test.js +1 -1
  35. package/lib/cjs/src/solanaToken/domain/SolanaTokenContextLoader.test.js.map +3 -3
  36. package/lib/cjs/src/token/domain/TokenContextLoader.js +1 -1
  37. package/lib/cjs/src/token/domain/TokenContextLoader.js.map +3 -3
  38. package/lib/cjs/src/token/domain/TokenContextLoader.test.js +1 -1
  39. package/lib/cjs/src/token/domain/TokenContextLoader.test.js.map +3 -3
  40. package/lib/cjs/src/transaction-check/domain/TransactionCheckContextLoader.js +1 -1
  41. package/lib/cjs/src/transaction-check/domain/TransactionCheckContextLoader.js.map +3 -3
  42. package/lib/cjs/src/transaction-check/domain/TransactionCheckContextLoader.test.js +1 -1
  43. package/lib/cjs/src/transaction-check/domain/TransactionCheckContextLoader.test.js.map +3 -3
  44. package/lib/cjs/src/transaction-check/domain/TypedDataCheckContextLoader.js +1 -1
  45. package/lib/cjs/src/transaction-check/domain/TypedDataCheckContextLoader.js.map +3 -3
  46. package/lib/cjs/src/transaction-check/domain/TypedDataCheckContextLoader.test.js +1 -1
  47. package/lib/cjs/src/transaction-check/domain/TypedDataCheckContextLoader.test.js.map +3 -3
  48. package/lib/cjs/src/trusted-name/di/trustedNameModuleFactory.js +1 -1
  49. package/lib/cjs/src/trusted-name/di/trustedNameModuleFactory.js.map +3 -3
  50. package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.js +1 -1
  51. package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.js.map +3 -3
  52. package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.test.js +1 -1
  53. package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.test.js.map +3 -3
  54. package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.js +1 -1
  55. package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.js.map +3 -3
  56. package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.test.js +1 -1
  57. package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.test.js.map +3 -3
  58. package/lib/cjs/src/uniswap/domain/UniswapContextLoader.js +1 -1
  59. package/lib/cjs/src/uniswap/domain/UniswapContextLoader.js.map +3 -3
  60. package/lib/cjs/src/uniswap/domain/UniswapContextLoader.test.js +1 -1
  61. package/lib/cjs/src/uniswap/domain/UniswapContextLoader.test.js.map +3 -3
  62. package/lib/esm/package.json +1 -1
  63. package/lib/esm/src/ContextModuleBuilder.js +1 -1
  64. package/lib/esm/src/ContextModuleBuilder.js.map +3 -3
  65. package/lib/esm/src/ContextModuleBuilder.test.js +1 -1
  66. package/lib/esm/src/ContextModuleBuilder.test.js.map +3 -3
  67. package/lib/esm/src/DefaultContextModule.test.js +1 -1
  68. package/lib/esm/src/DefaultContextModule.test.js.map +3 -3
  69. package/lib/esm/src/calldata/domain/CalldataContextLoader.js +1 -1
  70. package/lib/esm/src/calldata/domain/CalldataContextLoader.js.map +3 -3
  71. package/lib/esm/src/calldata/domain/CalldataContextLoader.test.js +1 -1
  72. package/lib/esm/src/calldata/domain/CalldataContextLoader.test.js.map +3 -3
  73. package/lib/esm/src/di.js +1 -1
  74. package/lib/esm/src/di.js.map +2 -2
  75. package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.js +1 -1
  76. package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.js.map +3 -3
  77. package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js +1 -1
  78. package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js.map +3 -3
  79. package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.js +1 -1
  80. package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.js.map +3 -3
  81. package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.test.js +1 -1
  82. package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.test.js.map +3 -3
  83. package/lib/esm/src/nft/domain/NftContextLoader.js +1 -1
  84. package/lib/esm/src/nft/domain/NftContextLoader.js.map +3 -3
  85. package/lib/esm/src/nft/domain/NftContextLoader.test.js +1 -1
  86. package/lib/esm/src/nft/domain/NftContextLoader.test.js.map +3 -3
  87. package/lib/esm/src/solana/domain/DefaultSolanaContextLoader.js.map +1 -1
  88. package/lib/esm/src/solana/domain/DefaultSolanaContextLoader.test.js +1 -1
  89. package/lib/esm/src/solana/domain/DefaultSolanaContextLoader.test.js.map +3 -3
  90. package/lib/esm/src/solanaLifi/domain/SolanaLifiContextLoader.test.js +1 -1
  91. package/lib/esm/src/solanaLifi/domain/SolanaLifiContextLoader.test.js.map +3 -3
  92. package/lib/esm/src/solanaToken/domain/SolanaTokenContextLoader.test.js +1 -1
  93. package/lib/esm/src/solanaToken/domain/SolanaTokenContextLoader.test.js.map +3 -3
  94. package/lib/esm/src/token/domain/TokenContextLoader.js +1 -1
  95. package/lib/esm/src/token/domain/TokenContextLoader.js.map +3 -3
  96. package/lib/esm/src/token/domain/TokenContextLoader.test.js +1 -1
  97. package/lib/esm/src/token/domain/TokenContextLoader.test.js.map +3 -3
  98. package/lib/esm/src/transaction-check/domain/TransactionCheckContextLoader.js +1 -1
  99. package/lib/esm/src/transaction-check/domain/TransactionCheckContextLoader.js.map +3 -3
  100. package/lib/esm/src/transaction-check/domain/TransactionCheckContextLoader.test.js +1 -1
  101. package/lib/esm/src/transaction-check/domain/TransactionCheckContextLoader.test.js.map +3 -3
  102. package/lib/esm/src/transaction-check/domain/TypedDataCheckContextLoader.js +1 -1
  103. package/lib/esm/src/transaction-check/domain/TypedDataCheckContextLoader.js.map +3 -3
  104. package/lib/esm/src/transaction-check/domain/TypedDataCheckContextLoader.test.js +1 -1
  105. package/lib/esm/src/transaction-check/domain/TypedDataCheckContextLoader.test.js.map +3 -3
  106. package/lib/esm/src/trusted-name/di/trustedNameModuleFactory.js +1 -1
  107. package/lib/esm/src/trusted-name/di/trustedNameModuleFactory.js.map +3 -3
  108. package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.js +1 -1
  109. package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.js.map +3 -3
  110. package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.test.js +1 -1
  111. package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.test.js.map +3 -3
  112. package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.js +1 -1
  113. package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.js.map +3 -3
  114. package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.test.js +1 -1
  115. package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.test.js.map +3 -3
  116. package/lib/esm/src/uniswap/domain/UniswapContextLoader.js +1 -1
  117. package/lib/esm/src/uniswap/domain/UniswapContextLoader.js.map +3 -3
  118. package/lib/esm/src/uniswap/domain/UniswapContextLoader.test.js +1 -1
  119. package/lib/esm/src/uniswap/domain/UniswapContextLoader.test.js.map +3 -3
  120. package/lib/types/src/ContextModuleBuilder.d.ts +10 -3
  121. package/lib/types/src/ContextModuleBuilder.d.ts.map +1 -1
  122. package/lib/types/src/calldata/domain/CalldataContextLoader.d.ts +3 -2
  123. package/lib/types/src/calldata/domain/CalldataContextLoader.d.ts.map +1 -1
  124. package/lib/types/src/config/model/ContextModuleBuildArgs.d.ts +1 -1
  125. package/lib/types/src/config/model/ContextModuleBuildArgs.d.ts.map +1 -1
  126. package/lib/types/src/config/model/ContextModuleConfig.d.ts +2 -0
  127. package/lib/types/src/config/model/ContextModuleConfig.d.ts.map +1 -1
  128. package/lib/types/src/di.d.ts.map +1 -1
  129. package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.d.ts +3 -2
  130. package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.d.ts.map +1 -1
  131. package/lib/types/src/external-plugin/domain/ExternalPluginContextLoader.d.ts +3 -2
  132. package/lib/types/src/external-plugin/domain/ExternalPluginContextLoader.d.ts.map +1 -1
  133. package/lib/types/src/nft/domain/NftContextLoader.d.ts +3 -2
  134. package/lib/types/src/nft/domain/NftContextLoader.d.ts.map +1 -1
  135. package/lib/types/src/token/domain/TokenContextLoader.d.ts +3 -2
  136. package/lib/types/src/token/domain/TokenContextLoader.d.ts.map +1 -1
  137. package/lib/types/src/transaction-check/domain/TransactionCheckContextLoader.d.ts +3 -2
  138. package/lib/types/src/transaction-check/domain/TransactionCheckContextLoader.d.ts.map +1 -1
  139. package/lib/types/src/transaction-check/domain/TypedDataCheckContextLoader.d.ts +3 -2
  140. package/lib/types/src/transaction-check/domain/TypedDataCheckContextLoader.d.ts.map +1 -1
  141. package/lib/types/src/trusted-name/di/trustedNameModuleFactory.d.ts +2 -1
  142. package/lib/types/src/trusted-name/di/trustedNameModuleFactory.d.ts.map +1 -1
  143. package/lib/types/src/trusted-name/domain/TrustedNameContextLoader.d.ts +3 -2
  144. package/lib/types/src/trusted-name/domain/TrustedNameContextLoader.d.ts.map +1 -1
  145. package/lib/types/src/typed-data/domain/DefaultTypedDataContextLoader.d.ts +3 -1
  146. package/lib/types/src/typed-data/domain/DefaultTypedDataContextLoader.d.ts.map +1 -1
  147. package/lib/types/src/uniswap/domain/UniswapContextLoader.d.ts +3 -2
  148. package/lib/types/src/uniswap/domain/UniswapContextLoader.d.ts.map +1 -1
  149. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  150. package/package.json +5 -5
  151. package/lib/cjs/src/shared/utils/NullLoggerPublisherService.js +0 -2
  152. package/lib/cjs/src/shared/utils/NullLoggerPublisherService.js.map +0 -7
  153. package/lib/cjs/src/shared/utils/NullLoggerPublisherService.test.js +0 -2
  154. package/lib/cjs/src/shared/utils/NullLoggerPublisherService.test.js.map +0 -7
  155. package/lib/esm/src/shared/utils/NullLoggerPublisherService.js +0 -2
  156. package/lib/esm/src/shared/utils/NullLoggerPublisherService.js.map +0 -7
  157. package/lib/esm/src/shared/utils/NullLoggerPublisherService.test.js +0 -2
  158. package/lib/esm/src/shared/utils/NullLoggerPublisherService.test.js.map +0 -7
  159. package/lib/types/src/shared/utils/NullLoggerPublisherService.d.ts +0 -3
  160. package/lib/types/src/shared/utils/NullLoggerPublisherService.d.ts.map +0 -1
  161. package/lib/types/src/shared/utils/NullLoggerPublisherService.test.d.ts +0 -2
  162. package/lib/types/src/shared/utils/NullLoggerPublisherService.test.d.ts.map +0 -1
package/lib/cjs/src/di.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var a=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var S=(r,o)=>{for(var e in o)a(r,e,{get:o[e],enumerable:!0})},v=(r,o,e,m)=>{if(o&&typeof o=="object"||typeof o=="function")for(let t of h(o))!w.call(r,t)&&t!==e&&a(r,t,{get:()=>o[t],enumerable:!(m=b(o,t))||m.enumerable});return r};var A=r=>v(a({},"__esModule",{value:!0}),r);var T={};S(T,{makeContainer:()=>N});module.exports=A(T);var i=require("inversify"),n=require("./calldata/di/calldataModuleFactory"),l=require("./config/di/configModuleFactory"),c=require("./config/di/configTypes"),p=require("./dynamic-network/di/dynamicNetworkModuleFactory"),y=require("./external-plugin/di/externalPluginModuleFactory"),f=require("./nft/di/nftModuleFactory"),u=require("./pki/di/pkiModuleFactory"),d=require("./proxy/di/proxyModuleFactory"),M=require("./safe/di/safeModuleFactory"),F=require("./solana/di/SolanaContextModuleFactory"),g=require("./solanaLifi/di/lifiModuleFactory"),s=require("./solanaToken/di/tokenModuleFactory"),C=require("./token/di/tokenModuleFactory"),k=require("./transaction-check/di/transactionCheckModuleFactory"),x=require("./trusted-name/di/trustedNameModuleFactory"),L=require("./typed-data/di/typedDataModuleFactory"),P=require("./uniswap/di/uniswapModuleFactory");const N=({config:r})=>{const o=new i.Container;return r.loggerFactory&&o.bind(c.configTypes.ContextModuleLoggerFactory).toConstantValue(r.loggerFactory),o.loadSync((0,l.configModuleFactory)(r),(0,y.externalPluginModuleFactory)(),(0,p.dynamicNetworkModuleFactory)(),(0,f.nftModuleFactory)(),(0,d.proxyModuleFactory)(r),(0,M.safeModuleFactory)(),(0,C.tokenModuleFactory)(),(0,n.calldataModuleFactory)(),(0,x.trustedNameModuleFactory)(),(0,L.typedDataModuleFactory)(),(0,u.nanoPkiModuleFactory)(),(0,P.uniswapModuleFactory)(),(0,k.transactionCheckModuleFactory)(),(0,F.solanaContextModuleFactory)(),(0,s.solanaTokenModuleFactory)(),(0,g.solanaLifiModuleFactory)()),o};0&&(module.exports={makeContainer});
1
+ "use strict";var a=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var S=(r,o)=>{for(var e in o)a(r,e,{get:o[e],enumerable:!0})},v=(r,o,e,m)=>{if(o&&typeof o=="object"||typeof o=="function")for(let t of h(o))!w.call(r,t)&&t!==e&&a(r,t,{get:()=>o[t],enumerable:!(m=b(o,t))||m.enumerable});return r};var A=r=>v(a({},"__esModule",{value:!0}),r);var T={};S(T,{makeContainer:()=>N});module.exports=A(T);var i=require("inversify"),n=require("./calldata/di/calldataModuleFactory"),l=require("./config/di/configModuleFactory"),c=require("./config/di/configTypes"),p=require("./dynamic-network/di/dynamicNetworkModuleFactory"),u=require("./external-plugin/di/externalPluginModuleFactory"),y=require("./nft/di/nftModuleFactory"),d=require("./pki/di/pkiModuleFactory"),f=require("./proxy/di/proxyModuleFactory"),M=require("./safe/di/safeModuleFactory"),F=require("./solana/di/SolanaContextModuleFactory"),s=require("./solanaLifi/di/lifiModuleFactory"),g=require("./solanaToken/di/tokenModuleFactory"),C=require("./token/di/tokenModuleFactory"),k=require("./transaction-check/di/transactionCheckModuleFactory"),x=require("./trusted-name/di/trustedNameModuleFactory"),L=require("./typed-data/di/typedDataModuleFactory"),P=require("./uniswap/di/uniswapModuleFactory");const N=({config:r})=>{const o=new i.Container;return o.bind(c.configTypes.ContextModuleLoggerFactory).toConstantValue(r.loggerFactory),o.loadSync((0,l.configModuleFactory)(r),(0,u.externalPluginModuleFactory)(),(0,p.dynamicNetworkModuleFactory)(),(0,y.nftModuleFactory)(),(0,f.proxyModuleFactory)(r),(0,M.safeModuleFactory)(),(0,C.tokenModuleFactory)(),(0,n.calldataModuleFactory)(),(0,x.trustedNameModuleFactory)(r),(0,L.typedDataModuleFactory)(),(0,d.nanoPkiModuleFactory)(),(0,P.uniswapModuleFactory)(),(0,k.transactionCheckModuleFactory)(),(0,F.solanaContextModuleFactory)(),(0,g.solanaTokenModuleFactory)(),(0,s.solanaLifiModuleFactory)()),o};0&&(module.exports={makeContainer});
2
2
  //# sourceMappingURL=di.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/di.ts"],
4
- "sourcesContent": ["import { type LoggerPublisherService } from \"@ledgerhq/device-management-kit\";\nimport { Container } from \"inversify\";\n\nimport { calldataModuleFactory } from \"@/calldata/di/calldataModuleFactory\";\nimport { configModuleFactory } from \"@/config/di/configModuleFactory\";\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { dynamicNetworkModuleFactory } from \"@/dynamic-network/di/dynamicNetworkModuleFactory\";\nimport { externalPluginModuleFactory } from \"@/external-plugin/di/externalPluginModuleFactory\";\nimport { nftModuleFactory } from \"@/nft/di/nftModuleFactory\";\nimport { nanoPkiModuleFactory } from \"@/pki/di/pkiModuleFactory\";\nimport { proxyModuleFactory } from \"@/proxy/di/proxyModuleFactory\";\nimport { safeModuleFactory } from \"@/safe/di/safeModuleFactory\";\nimport { solanaContextModuleFactory } from \"@/solana/di/SolanaContextModuleFactory\";\nimport { solanaLifiModuleFactory } from \"@/solanaLifi/di/lifiModuleFactory\";\nimport { solanaTokenModuleFactory } from \"@/solanaToken/di/tokenModuleFactory\";\nimport { tokenModuleFactory } from \"@/token/di/tokenModuleFactory\";\nimport { transactionCheckModuleFactory } from \"@/transaction-check/di/transactionCheckModuleFactory\";\nimport { trustedNameModuleFactory } from \"@/trusted-name/di/trustedNameModuleFactory\";\nimport { typedDataModuleFactory } from \"@/typed-data/di/typedDataModuleFactory\";\nimport { uniswapModuleFactory } from \"@/uniswap/di/uniswapModuleFactory\";\n\ntype MakeContainerArgs = {\n config: ContextModuleConfig;\n};\n\nexport const makeContainer = ({ config }: MakeContainerArgs) => {\n const container = new Container();\n\n if (config.loggerFactory) {\n container\n .bind<\n (tag: string) => LoggerPublisherService\n >(configTypes.ContextModuleLoggerFactory)\n .toConstantValue(config.loggerFactory);\n }\n\n container.loadSync(\n configModuleFactory(config),\n externalPluginModuleFactory(),\n dynamicNetworkModuleFactory(),\n nftModuleFactory(),\n proxyModuleFactory(config),\n safeModuleFactory(),\n tokenModuleFactory(),\n calldataModuleFactory(),\n trustedNameModuleFactory(),\n typedDataModuleFactory(),\n nanoPkiModuleFactory(),\n uniswapModuleFactory(),\n transactionCheckModuleFactory(),\n solanaContextModuleFactory(),\n solanaTokenModuleFactory(),\n solanaLifiModuleFactory(),\n );\n\n return container;\n};\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,IAAA,eAAAC,EAAAH,GACA,IAAAI,EAA0B,qBAE1BC,EAAsC,+CACtCC,EAAoC,2CACpCC,EAA4B,mCAE5BC,EAA4C,4DAC5CC,EAA4C,4DAC5CC,EAAiC,qCACjCC,EAAqC,qCACrCC,EAAmC,yCACnCC,EAAkC,uCAClCC,EAA2C,kDAC3CC,EAAwC,6CACxCC,EAAyC,+CACzCA,EAAmC,yCACnCC,EAA8C,gEAC9CC,EAAyC,sDACzCC,EAAuC,kDACvCC,EAAqC,6CAM9B,MAAMlB,EAAgB,CAAC,CAAE,OAAAmB,CAAO,IAAyB,CAC9D,MAAMC,EAAY,IAAI,YAEtB,OAAID,EAAO,eACTC,EACG,KAEC,cAAY,0BAA0B,EACvC,gBAAgBD,EAAO,aAAa,EAGzCC,EAAU,YACR,uBAAoBD,CAAM,KAC1B,+BAA4B,KAC5B,+BAA4B,KAC5B,oBAAiB,KACjB,sBAAmBA,CAAM,KACzB,qBAAkB,KAClB,sBAAmB,KACnB,yBAAsB,KACtB,4BAAyB,KACzB,0BAAuB,KACvB,wBAAqB,KACrB,wBAAqB,KACrB,iCAA8B,KAC9B,8BAA2B,KAC3B,4BAAyB,KACzB,2BAAwB,CAC1B,EAEOC,CACT",
4
+ "sourcesContent": ["import { type LoggerPublisherService } from \"@ledgerhq/device-management-kit\";\nimport { Container } from \"inversify\";\n\nimport { calldataModuleFactory } from \"@/calldata/di/calldataModuleFactory\";\nimport { configModuleFactory } from \"@/config/di/configModuleFactory\";\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { dynamicNetworkModuleFactory } from \"@/dynamic-network/di/dynamicNetworkModuleFactory\";\nimport { externalPluginModuleFactory } from \"@/external-plugin/di/externalPluginModuleFactory\";\nimport { nftModuleFactory } from \"@/nft/di/nftModuleFactory\";\nimport { nanoPkiModuleFactory } from \"@/pki/di/pkiModuleFactory\";\nimport { proxyModuleFactory } from \"@/proxy/di/proxyModuleFactory\";\nimport { safeModuleFactory } from \"@/safe/di/safeModuleFactory\";\nimport { solanaContextModuleFactory } from \"@/solana/di/SolanaContextModuleFactory\";\nimport { solanaLifiModuleFactory } from \"@/solanaLifi/di/lifiModuleFactory\";\nimport { solanaTokenModuleFactory } from \"@/solanaToken/di/tokenModuleFactory\";\nimport { tokenModuleFactory } from \"@/token/di/tokenModuleFactory\";\nimport { transactionCheckModuleFactory } from \"@/transaction-check/di/transactionCheckModuleFactory\";\nimport { trustedNameModuleFactory } from \"@/trusted-name/di/trustedNameModuleFactory\";\nimport { typedDataModuleFactory } from \"@/typed-data/di/typedDataModuleFactory\";\nimport { uniswapModuleFactory } from \"@/uniswap/di/uniswapModuleFactory\";\n\ntype MakeContainerArgs = {\n config: ContextModuleConfig;\n};\n\nexport const makeContainer = ({ config }: MakeContainerArgs) => {\n const container = new Container();\n\n container\n .bind<\n (tag: string) => LoggerPublisherService\n >(configTypes.ContextModuleLoggerFactory)\n .toConstantValue(config.loggerFactory);\n\n container.loadSync(\n configModuleFactory(config),\n externalPluginModuleFactory(),\n dynamicNetworkModuleFactory(),\n nftModuleFactory(),\n proxyModuleFactory(config),\n safeModuleFactory(),\n tokenModuleFactory(),\n calldataModuleFactory(),\n trustedNameModuleFactory(config),\n typedDataModuleFactory(),\n nanoPkiModuleFactory(),\n uniswapModuleFactory(),\n transactionCheckModuleFactory(),\n solanaContextModuleFactory(),\n solanaTokenModuleFactory(),\n solanaLifiModuleFactory(),\n );\n\n return container;\n};\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,IAAA,eAAAC,EAAAH,GACA,IAAAI,EAA0B,qBAE1BC,EAAsC,+CACtCC,EAAoC,2CACpCC,EAA4B,mCAE5BC,EAA4C,4DAC5CC,EAA4C,4DAC5CC,EAAiC,qCACjCC,EAAqC,qCACrCC,EAAmC,yCACnCC,EAAkC,uCAClCC,EAA2C,kDAC3CC,EAAwC,6CACxCC,EAAyC,+CACzCA,EAAmC,yCACnCC,EAA8C,gEAC9CC,EAAyC,sDACzCC,EAAuC,kDACvCC,EAAqC,6CAM9B,MAAMlB,EAAgB,CAAC,CAAE,OAAAmB,CAAO,IAAyB,CAC9D,MAAMC,EAAY,IAAI,YAEtB,OAAAA,EACG,KAEC,cAAY,0BAA0B,EACvC,gBAAgBD,EAAO,aAAa,EAEvCC,EAAU,YACR,uBAAoBD,CAAM,KAC1B,+BAA4B,KAC5B,+BAA4B,KAC5B,oBAAiB,KACjB,sBAAmBA,CAAM,KACzB,qBAAkB,KAClB,sBAAmB,KACnB,yBAAsB,KACtB,4BAAyBA,CAAM,KAC/B,0BAAuB,KACvB,wBAAqB,KACrB,wBAAqB,KACrB,iCAA8B,KAC9B,8BAA2B,KAC3B,4BAAyB,KACzB,2BAAwB,CAC1B,EAEOC,CACT",
6
6
  "names": ["di_exports", "__export", "makeContainer", "__toCommonJS", "import_inversify", "import_calldataModuleFactory", "import_configModuleFactory", "import_configTypes", "import_dynamicNetworkModuleFactory", "import_externalPluginModuleFactory", "import_nftModuleFactory", "import_pkiModuleFactory", "import_proxyModuleFactory", "import_safeModuleFactory", "import_SolanaContextModuleFactory", "import_lifiModuleFactory", "import_tokenModuleFactory", "import_transactionCheckModuleFactory", "import_trustedNameModuleFactory", "import_typedDataModuleFactory", "import_uniswapModuleFactory", "config", "container"]
7
7
  }
@@ -1,2 +1,2 @@
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});
1
+ "use strict";var p=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var T=(i,e)=>{for(var o in e)p(i,o,{get:e[o],enumerable:!0})},M=(i,e,o,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of w(e))!v.call(i,t)&&t!==o&&p(i,t,{get:()=>e[t],enumerable:!(r=y(e,t))||r.enumerable});return i};var P=i=>M(p({},"__esModule",{value:!0}),i),u=(i,e,o,r)=>{for(var t=r>1?void 0:r?y(e,o):e,c=i.length-1,n;c>=0;c--)(n=i[c])&&(t=(r?n(e,o,t):n(t))||t);return r&&t&&p(e,o,t),t},s=(i,e)=>(o,r)=>e(o,r,i);var b={};T(b,{DynamicNetworkContextLoader:()=>l});module.exports=P(b);var I=require("@ledgerhq/device-management-kit"),a=require("inversify"),m=require("../../config/di/configTypes"),N=require("../../dynamic-network/di/dynamicNetworkTypes"),k=require("../../pki/di/pkiTypes"),D=require("../../pki/model/KeyId"),S=require("../../pki/model/KeyUsage"),g=require("../../shared/model/ClearSignContext"),_=require("../../shared/utils/HexStringUtils");const L="15",O=[g.ClearSignContextType.DYNAMIC_NETWORK,g.ClearSignContextType.DYNAMIC_NETWORK_ICON];let l=class{_networkDataSource;_config;_certificateLoader;logger;constructor(e,o,r,t){this._networkDataSource=e,this._config=o,this._certificateLoader=r,this.logger=t("DynamicNetworkContextLoader")}canHandle(e,o){return typeof e=="object"&&e!==null&&"chainId"in e&&"deviceModelId"in e&&e.deviceModelId!==void 0&&e.deviceModelId!==I.DeviceModelId.NANO_S&&typeof e.chainId=="number"&&O.every(r=>o.includes(r))}async load(e){const{chainId:o,deviceModelId:r}=e,t=await this._networkDataSource.getDynamicNetworkConfiguration(o),c=await this._certificateLoader.loadCertificate({keyId:D.KeyId.CalNetwork,keyUsage:S.KeyUsage.Network,targetDevice:r}),n=t.caseOf({Left:()=>[],Right:h=>{const f=[],d=h.descriptors[r];if(!d)return[];const C=d.signatures[this._config.cal.mode];if(!C)return[];const x=_.HexStringUtils.appendSignatureToPayload(d.data,C,L);return f.push({type:g.ClearSignContextType.DYNAMIC_NETWORK,payload:x,certificate:c}),d.icon&&f.push({type:g.ClearSignContextType.DYNAMIC_NETWORK_ICON,payload:d.icon}),f}});return this.logger.debug("load result",{data:{result:n}}),n}};l=u([(0,a.injectable)(),s(0,(0,a.inject)(N.dynamicNetworkTypes.DynamicNetworkDataSource)),s(1,(0,a.inject)(m.configTypes.Config)),s(2,(0,a.inject)(k.pkiTypes.PkiCertificateLoader)),s(3,(0,a.inject)(m.configTypes.ContextModuleLoggerFactory))],l);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 { 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"],
5
- "mappings": "okBAAA,IAAAA,EAAA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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"]
4
+ "sourcesContent": ["import {\n DeviceModelId,\n LoggerPublisherService,\n} 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 private logger: LoggerPublisherService;\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 @inject(configTypes.ContextModuleLoggerFactory)\n loggerFactory: (tag: string) => LoggerPublisherService,\n ) {\n this._networkDataSource = networkDataSource;\n this._config = config;\n this._certificateLoader = certificateLoader;\n this.logger = loggerFactory(\"DynamicNetworkContextLoader\");\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 networkConfig =\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 const result = networkConfig.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 this.logger.debug(\"load result\", { data: { result } });\n return result;\n }\n}\n"],
5
+ "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAGO,2CACPC,EAAmC,qBAEnCC,EAA4B,mCAG5BC,EAAoC,oDACpCC,EAAyB,6BAEzBC,EAAsB,6BACtBC,EAAyB,gCAEzBC,EAGO,2CACPC,EAA+B,yCAO/B,MAAMC,EAAwB,KAExBC,EAA0C,CAC9C,uBAAqB,gBACrB,uBAAqB,oBACvB,EAGO,IAAMC,EAAN,KAEP,CACmB,mBACA,QACA,mBACT,OAER,YAEEC,EAEAC,EAEAC,EAEAC,EACA,CACA,KAAK,mBAAqBH,EAC1B,KAAK,QAAUC,EACf,KAAK,mBAAqBC,EAC1B,KAAK,OAASC,EAAc,6BAA6B,CAC3D,CAEA,UACEC,EACAC,EACqC,CACrC,OACE,OAAOD,GAAU,UACjBA,IAAU,MACV,YAAaA,GACb,kBAAmBA,GACnBA,EAAM,gBAAkB,QACxBA,EAAM,gBAAkB,gBAAc,QACtC,OAAOA,EAAM,SAAY,UACzBN,EAAgB,MAAOQ,GAASD,EAAc,SAASC,CAAI,CAAC,CAEhE,CAEA,MAAM,KAAKF,EAAgE,CACzE,KAAM,CAAE,QAAAG,EAAS,cAAAC,CAAc,EAAIJ,EAE7BK,EACJ,MAAM,KAAK,mBAAmB,+BAA+BF,CAAO,EAGhEG,EAAc,MAAM,KAAK,mBAAmB,gBAAgB,CAChE,MAAO,QAAM,WACb,SAAU,WAAS,QACnB,aAAcF,CAChB,CAAC,EAEKG,EAASF,EAAc,OAAO,CAClC,KAAM,IAAM,CAAC,EACb,MAAQG,GAAkB,CACxB,MAAMC,EAA+B,CAAC,EAChCC,EAAaF,EAAc,YAAYJ,CAAa,EAE1D,GAAI,CAACM,EACH,MAAO,CAAC,EAGV,MAAMC,EAAYD,EAAW,WAAW,KAAK,QAAQ,IAAI,IAAI,EAE7D,GAAI,CAACC,EACH,MAAO,CAAC,EAGV,MAAMC,EAAgB,iBAAe,yBACnCF,EAAW,KACXC,EACAlB,CACF,EAEA,OAAAgB,EAAS,KAAK,CACZ,KAAM,uBAAqB,gBAC3B,QAASG,EACT,YAAAN,CACF,CAAC,EAGGI,EAAW,MAEbD,EAAS,KAAK,CACZ,KAAM,uBAAqB,qBAC3B,QAASC,EAAW,IACtB,CAAC,EAGID,CACT,CACF,CAAC,EAED,YAAK,OAAO,MAAM,cAAe,CAAE,KAAM,CAAE,OAAAF,CAAO,CAAE,CAAC,EAC9CA,CACT,CACF,EAjGaZ,EAANkB,EAAA,IADN,cAAW,EAUPC,EAAA,eAAO,sBAAoB,wBAAwB,GAEnDA,EAAA,eAAO,cAAY,MAAM,GAEzBA,EAAA,eAAO,WAAS,oBAAoB,GAEpCA,EAAA,eAAO,cAAY,0BAA0B,IAfrCnB",
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", "loggerFactory", "input", "expectedTypes", "type", "chainId", "deviceModelId", "networkConfig", "certificate", "result", "configuration", "contexts", "descriptor", "signature", "configPayload", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -1,2 +1,2 @@
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")})})});
1
+ "use strict";var e=require("@ledgerhq/device-management-kit"),d=require("purify-ts"),f=require("../../dynamic-network/domain/DynamicNetworkContextLoader"),m=require("../../pki/model/KeyId"),g=require("../../pki/model/KeyUsage"),r=require("../../shared/model/ClearSignContext");const y=()=>({debug:vi.fn(),info:vi.fn(),warn:vi.fn(),error:vi.fn(),subscribers:[]});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,y),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: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},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,y),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 {\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,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B,UAChB,kBAAmB,KACnB,WAAY,CACV,KAAM,WACN,KAAM,UACR,EACA,KAAM,MACR,CACF,CACF,EACA,GAAG,MACDL,EACA,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"]
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\nconst mockLoggerFactory = () => ({\n debug: vi.fn(),\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n subscribers: [],\n});\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 mockLoggerFactory,\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 mockLoggerFactory,\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,MAAMC,EAAoB,KAAO,CAC/B,MAAO,GAAG,GAAG,EACb,KAAM,GAAG,GAAG,EACZ,KAAM,GAAG,GAAG,EACZ,MAAO,GAAG,GAAG,EACb,YAAa,CAAC,CAChB,GAEA,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,EACAH,CACF,EAGMM,EACJC,IAC8B,CAC9B,KAAM,GACN,eAAgB,GAChB,kBAAmB,GACn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AgB,UAChB,kBAAmB,KACnB,WAAY,CACV,KAAM,WACN,KAAM,UACR,EACA,KAAM,MACR,CACF,CACF,EACA,GAAG,MACDL,EACA,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", "mockLoggerFactory", "mockNetworkDataSource", "mockConfig", "mockCertificateLoader", "mockCertificate", "loader", "createMockDescriptor", "partial", "validInput", "input", "_description", "result", "networkConfig", "context", "testModeLoader"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var m=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var b=(n,e)=>{for(var r in e)m(n,r,{get:e[r],enumerable:!0})},H=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of w(e))!_.call(n,a)&&a!==r&&m(n,a,{get:()=>e[a],enumerable:!(t=P(e,a))||t.enumerable});return n};var O=n=>H(m({},"__esModule",{value:!0}),n),E=(n,e,r,t)=>{for(var a=t>1?void 0:t?P(e,r):e,s=n.length-1,d;s>=0;s--)(d=n[s])&&(a=(t?d(e,r,a):d(a))||a);return t&&a&&m(e,r,a),a},C=(n,e)=>(r,t)=>e(r,t,n);var v={};b(v,{ExternalPluginContextLoader:()=>p});module.exports=O(v);var g=require("@ledgerhq/device-management-kit"),D=require("ethers"),c=require("inversify"),l=require("purify-ts"),I=require("../../external-plugin/di/externalPluginTypes"),o=require("../../shared/model/ClearSignContext"),T=require("../../token/di/tokenTypes"),L=require("../../uniswap/di/uniswapTypes");const U=[o.ClearSignContextType.EXTERNAL_PLUGIN,o.ClearSignContextType.TOKEN];let p=class{constructor(e,r,t){this._externalPluginDataSource=e;this._tokenDataSource=r;this._uniswapLoader=t;this._customPluginLoaders={Uniswap:this._uniswapLoader}}_customPluginLoaders;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"&&U.every(t=>r.includes(t))}async load(e){const{to:r,data:t,selector:a,chainId:s}=e,d=await this._externalPluginDataSource.getDappInfos({address:r,chainId:s,selector:a});return(0,l.EitherAsync)(async({liftEither:u})=>{const i=await u(d);if(!i)return[];const f={type:o.ClearSignContextType.EXTERNAL_PLUGIN,payload:i.selectorDetails.serializedData.concat(i.selectorDetails.signature)},h=this._customPluginLoaders[i.selectorDetails.plugin];if(h!==void 0&&h.canHandle(e,[o.ClearSignContextType.TOKEN])){const x=await h.load(e);return[f,...x]}const y=this.getDecodedCallData(i.abi,i.selectorDetails.method,t);if(y.isLeft())return[{type:o.ClearSignContextType.ERROR,error:y.extract()},f];const R=y.extract(),k=i.selectorDetails.erc20OfInterest.map(async x=>this.getTokenPayload(e,x,R));return[...(await Promise.all(k)).map(x=>x.caseOf({Left:S=>({type:o.ClearSignContextType.ERROR,error:S}),Right:S=>({type:o.ClearSignContextType.TOKEN,payload:S})})),f]}).caseOf({Left:u=>[{type:o.ClearSignContextType.ERROR,error:u}],Right:u=>u})}getTokenPayload(e,r,t){const a=this.getAddressFromPath(r,t);return(0,l.EitherAsync)(({fromPromise:s})=>s(this._tokenDataSource.getTokenInfosPayload({address:a,chainId:e.chainId})))}getDecodedCallData(e,r,t){try{const a=new D.Interface(e);return(0,l.Right)(a.decodeFunctionData(r,t))}catch{return(0,l.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}};p=E([(0,c.injectable)(),C(0,(0,c.inject)(I.externalPluginTypes.ExternalPluginDataSource)),C(1,(0,c.inject)(T.tokenTypes.TokenDataSource)),C(2,(0,c.inject)(L.uniswapTypes.UniswapContextLoader))],p);0&&(module.exports={ExternalPluginContextLoader});
1
+ "use strict";var C=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var H=(o,e)=>{for(var a in e)C(o,a,{get:e[a],enumerable:!0})},O=(o,e,a,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of v(e))!_.call(o,r)&&r!==a&&C(o,r,{get:()=>e[r],enumerable:!(t=E(e,r))||t.enumerable});return o};var U=o=>O(C({},"__esModule",{value:!0}),o),D=(o,e,a,t)=>{for(var r=t>1?void 0:t?E(e,a):e,i=o.length-1,g;i>=0;i--)(g=o[i])&&(r=(t?g(e,a,r):g(r))||r);return t&&r&&C(e,a,r),r},x=(o,e)=>(a,t)=>e(a,t,o);var A={};H(A,{ExternalPluginContextLoader:()=>m});module.exports=U(A);var p=require("@ledgerhq/device-management-kit"),L=require("ethers"),l=require("inversify"),c=require("purify-ts"),I=require("../../config/di/configTypes"),T=require("../../external-plugin/di/externalPluginTypes"),n=require("../../shared/model/ClearSignContext"),R=require("../../token/di/tokenTypes"),w=require("../../uniswap/di/uniswapTypes");const N=[n.ClearSignContextType.EXTERNAL_PLUGIN,n.ClearSignContextType.TOKEN];let m=class{constructor(e,a,t,r){this._externalPluginDataSource=e;this._tokenDataSource=a;this._uniswapLoader=t;this._customPluginLoaders={Uniswap:this._uniswapLoader},this.logger=r("ExternalPluginContextLoader")}_customPluginLoaders;logger;canHandle(e,a){return typeof e=="object"&&e!==null&&"to"in e&&"data"in e&&"selector"in e&&"chainId"in e&&typeof e.chainId=="number"&&(0,p.isHexaString)(e.to)&&e.to!=="0x"&&(0,p.isHexaString)(e.data)&&e.data!=="0x"&&(0,p.isHexaString)(e.selector)&&e.selector!=="0x"&&N.every(t=>a.includes(t))}async load(e){const{to:a,data:t,selector:r,chainId:i}=e,g=await this._externalPluginDataSource.getDappInfos({address:a,chainId:i,selector:r}),y=await(0,c.EitherAsync)(async({liftEither:d})=>{const s=await d(g);if(!s)return[];const h={type:n.ClearSignContextType.EXTERNAL_PLUGIN,payload:s.selectorDetails.serializedData.concat(s.selectorDetails.signature)},f=this._customPluginLoaders[s.selectorDetails.plugin];if(f!==void 0&&f.canHandle(e,[n.ClearSignContextType.TOKEN])){const u=await f.load(e);return[h,...u]}const P=this.getDecodedCallData(s.abi,s.selectorDetails.method,t);if(P.isLeft())return[{type:n.ClearSignContextType.ERROR,error:P.extract()},h];const k=P.extract(),b=s.selectorDetails.erc20OfInterest.map(async u=>this.getTokenPayload(e,u,k));return[...(await Promise.all(b)).map(u=>u.caseOf({Left:S=>({type:n.ClearSignContextType.ERROR,error:S}),Right:S=>({type:n.ClearSignContextType.TOKEN,payload:S})})),h]}).caseOf({Left:d=>[{type:n.ClearSignContextType.ERROR,error:d}],Right:d=>d});return this.logger.debug("load result",{data:{result:y}}),y}getTokenPayload(e,a,t){const r=this.getAddressFromPath(a,t);return(0,c.EitherAsync)(({fromPromise:i})=>i(this._tokenDataSource.getTokenInfosPayload({address:r,chainId:e.chainId})))}getDecodedCallData(e,a,t){try{const r=new L.Interface(e);return(0,c.Right)(r.decodeFunctionData(a,t))}catch{return(0,c.Left)(new Error("[ContextModule] ExternalPluginContextLoader: Unable to parse abi"))}}getAddressFromPath(e,a){let t=a;for(const r of e.split("."))r==="-1"?t=t[t.length-1]:t=t[r];if(!(0,p.isHexaString)(t))throw new Error("[ContextModule] ExternalPluginContextLoader: Unable to get address");return t}};m=D([(0,l.injectable)(),x(0,(0,l.inject)(T.externalPluginTypes.ExternalPluginDataSource)),x(1,(0,l.inject)(R.tokenTypes.TokenDataSource)),x(2,(0,l.inject)(w.uniswapTypes.UniswapContextLoader)),x(3,(0,l.inject)(I.configTypes.ContextModuleLoggerFactory))],m);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 type { TokenDataSource } from \"@/token/data/TokenDataSource\";\nimport { tokenTypes } from \"@/token/di/tokenTypes\";\nimport { uniswapTypes } from \"@/uniswap/di/uniswapTypes\";\nimport type { UniswapContextLoader } from \"@/uniswap/domain/UniswapContextLoader\";\n\nexport type ExternalPluginContextInput = {\n to: HexaString;\n data: HexaString;\n selector: HexaString;\n chainId: number;\n};\n\nexport type ExternalPluginTokensInput = {\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 _customPluginLoaders: Record<\n string,\n ContextLoader<ExternalPluginTokensInput>\n >;\n\n constructor(\n @inject(externalPluginTypes.ExternalPluginDataSource)\n private _externalPluginDataSource: ExternalPluginDataSource,\n @inject(tokenTypes.TokenDataSource)\n private _tokenDataSource: TokenDataSource,\n @inject(uniswapTypes.UniswapContextLoader)\n private _uniswapLoader: UniswapContextLoader,\n ) {\n this._customPluginLoaders = {\n Uniswap: this._uniswapLoader,\n };\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 customLoader =\n this._customPluginLoaders[dappInfos.selectorDetails.plugin];\n if (\n customLoader !== undefined &&\n customLoader.canHandle(input, [ClearSignContextType.TOKEN])\n ) {\n const tokens = await customLoader.load(input);\n return [externalPluginContext, ...tokens];\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,iCAC3BC,EAA6B,qCAgB7B,MAAMC,EAA0C,CAC9C,uBAAqB,gBACrB,uBAAqB,KACvB,EAGO,IAAMC,EAAN,KAEP,CAME,YAEUC,EAEAC,EAEAC,EACR,CALQ,+BAAAF,EAEA,sBAAAC,EAEA,oBAAAC,EAER,KAAK,qBAAuB,CAC1B,QAAS,KAAK,cAChB,CACF,CAhBQ,qBAkBR,UACEC,EACAC,EACqC,CACrC,OACE,OAAOD,GAAU,UACjBA,IAAU,MACV,OAAQA,GACR,SAAUA,GACV,aAAcA,GACd,YAAaA,GACb,OAAOA,EAAM,SAAY,aACzB,gBAAaA,EAAM,EAAE,GACrBA,EAAM,KAAO,SACb,gBAAaA,EAAM,IAAI,GACvBA,EAAM,OAAS,SACf,gBAAaA,EAAM,QAAQ,GAC3BA,EAAM,WAAa,MACnBL,EAAgB,MAAOO,GAASD,EAAc,SAASC,CAAI,CAAC,CAEhE,CAEA,MAAM,KAAKF,EAAgE,CACzE,KAAM,CAAE,GAAAG,EAAI,KAAAC,EAAM,SAAAC,EAAU,QAAAC,CAAQ,EAAIN,EAElCO,EAAkB,MAAM,KAAK,0BAA0B,aAAa,CACxE,QAASJ,EACT,QAAAG,EACA,SAAAD,CACF,CAAC,EAED,SAAO,eAAuC,MAAO,CAA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,CAAE,YAAAS,CAAY,IAC/CA,EACE,KAAK,iBAAiB,qBAAqB,CACzC,QAAAD,EACA,QAASrB,EAAM,OACjB,CAAC,CACH,CACF,CACF,CAEQ,mBACNuB,EACAC,EACApB,EAC8B,CAC9B,GAAI,CACF,MAAMqB,EAAoB,IAAI,YAAUF,CAAG,EAC3C,SAAO,SAAME,EAAkB,mBAAmBD,EAAQpB,CAAI,CAAC,CACjE,MAAiB,CACf,SAAO,QACL,IAAI,MACF,kEACF,CACF,CACF,CACF,CAEQ,mBACNsB,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,EA5La/B,EAANiC,EAAA,IADN,cAAW,EAUPC,EAAA,eAAO,sBAAoB,wBAAwB,GAEnDA,EAAA,eAAO,aAAW,eAAe,GAEjCA,EAAA,eAAO,eAAa,oBAAoB,IAbhClC",
6
- "names": ["ExternalPluginContextLoader_exports", "__export", "ExternalPluginContextLoader", "__toCommonJS", "import_device_management_kit", "import_ethers", "import_inversify", "import_purify_ts", "import_externalPluginTypes", "import_ClearSignContext", "import_tokenTypes", "import_uniswapTypes", "SUPPORTED_TYPES", "ExternalPluginContextLoader", "_externalPluginDataSource", "_tokenDataSource", "_uniswapLoader", "input", "expectedTypes", "type", "to", "data", "selector", "chainId", "eitherDappInfos", "liftEither", "dappInfos", "externalPluginContext", "customLoader", "tokens", "decodedCallData", "extractedDecodedCallData", "promises", "erc20Path", "eitherToken", "error", "payload", "contexts", "address", "fromPromise", "abi", "method", "contractInterface", "path", "value", "key", "__decorateClass", "__decorateParam"]
4
+ "sourcesContent": ["import {\n HexaString,\n isHexaString,\n LoggerPublisherService,\n} 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 { configTypes } from \"@/config/di/configTypes\";\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\";\nimport { uniswapTypes } from \"@/uniswap/di/uniswapTypes\";\nimport type { UniswapContextLoader } from \"@/uniswap/domain/UniswapContextLoader\";\n\nexport type ExternalPluginContextInput = {\n to: HexaString;\n data: HexaString;\n selector: HexaString;\n chainId: number;\n};\n\nexport type ExternalPluginTokensInput = {\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 _customPluginLoaders: Record<\n string,\n ContextLoader<ExternalPluginTokensInput>\n >;\n private logger: LoggerPublisherService;\n\n constructor(\n @inject(externalPluginTypes.ExternalPluginDataSource)\n private _externalPluginDataSource: ExternalPluginDataSource,\n @inject(tokenTypes.TokenDataSource)\n private _tokenDataSource: TokenDataSource,\n @inject(uniswapTypes.UniswapContextLoader)\n private _uniswapLoader: UniswapContextLoader,\n @inject(configTypes.ContextModuleLoggerFactory)\n loggerFactory: (tag: string) => LoggerPublisherService,\n ) {\n this._customPluginLoaders = {\n Uniswap: this._uniswapLoader,\n };\n this.logger = loggerFactory(\"ExternalPluginContextLoader\");\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 const result = await EitherAsync<Error, ClearSignContext[]>(\n 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 customLoader =\n this._customPluginLoaders[dappInfos.selectorDetails.plugin];\n if (\n customLoader !== undefined &&\n customLoader.canHandle(input, [ClearSignContextType.TOKEN])\n ) {\n const tokens = await customLoader.load(input);\n return [externalPluginContext, ...tokens];\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 },\n ).caseOf<ClearSignContext[]>({\n // parse all errors into ClearSignContext\n Left: (error) => [{ type: ClearSignContextType.ERROR, error }],\n Right: (contexts) => contexts,\n });\n\n this.logger.debug(\"load result\", { data: { result } });\n return result;\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,EAIO,2CACPC,EAAkC,kBAClCC,EAAmC,qBACnCC,EAAiD,qBAEjDC,EAA4B,mCAE5BC,EAAoC,oDAEpCC,EAGO,2CAEPC,EAA2B,iCAC3BC,EAA6B,qCAgB7B,MAAMC,EAA0C,CAC9C,uBAAqB,gBACrB,uBAAqB,KACvB,EAGO,IAAMC,EAAN,KAEP,CAOE,YAEUC,EAEAC,EAEAC,EAERC,EACA,CAPQ,+BAAAH,EAEA,sBAAAC,EAEA,oBAAAC,EAIR,KAAK,qBAAuB,CAC1B,QAAS,KAAK,cAChB,EACA,KAAK,OAASC,EAAc,6BAA6B,CAC3D,CApBQ,qBAIA,OAkBR,UACEC,EACAC,EACqC,CACrC,OACE,OAAOD,GAAU,UACjBA,IAAU,MACV,OAAQA,GACR,SAAUA,GACV,aAAcA,GACd,YAAaA,GACb,OAAOA,EAAM,SAAY,aACzB,gBAAaA,EAAM,EAAE,GACrBA,EAAM,KAAO,SACb,gBAAaA,EAAM,IAAI,GACvBA,EAAM,OAAS,SACf,gBAAaA,EAAM,QAAQ,GAC3BA,EAAM,WAAa,MACnBN,EAAgB,MAAOQ,GAASD,EAAc,SAASC,CAAI,CAAC,CAEhE,CAEA,MAAM,KAAKF,EAAgE,CACzE,KAAM,CAAE,GAAAG,EAAI,KAAAC,EAAM,SAAAC,EAAU,QAAAC,CAAQ,EAAIN,EAElCO,EAAkB,MAAM,KAAK,0BAA0B,aAAa,CACxE,QAASJ,EACT,QAAAG,EACA,SAAAD,CACF,CAAC,EAEKG,EAAS,QAAM,eACnB,MAAO,CAAE,WAAAC,CAAW,IAAM,CACxB,MAAMC,EAAY,MAAMD,EAAWF,CAAe,EAIlD,GAAI,CAACG,EACH,MAAO,CAAC,E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Y,IAC/CA,EACE,KAAK,iBAAiB,qBAAqB,CACzC,QAAAD,EACA,QAAStB,EAAM,OACjB,CAAC,CACH,CACF,CACF,CAEQ,mBACNwB,EACAC,EACArB,EAC8B,CAC9B,GAAI,CACF,MAAMsB,EAAoB,IAAI,YAAUF,CAAG,EAC3C,SAAO,SAAME,EAAkB,mBAAmBD,EAAQrB,CAAI,CAAC,CACjE,MAAiB,CACf,SAAO,QACL,IAAI,MACF,kEACF,CACF,CACF,CACF,CAEQ,mBACNuB,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,EArMajC,EAANmC,EAAA,IADN,cAAW,EAWPC,EAAA,eAAO,sBAAoB,wBAAwB,GAEnDA,EAAA,eAAO,aAAW,eAAe,GAEjCA,EAAA,eAAO,eAAa,oBAAoB,GAExCA,EAAA,eAAO,cAAY,0BAA0B,IAhBrCpC",
6
+ "names": ["ExternalPluginContextLoader_exports", "__export", "ExternalPluginContextLoader", "__toCommonJS", "import_device_management_kit", "import_ethers", "import_inversify", "import_purify_ts", "import_configTypes", "import_externalPluginTypes", "import_ClearSignContext", "import_tokenTypes", "import_uniswapTypes", "SUPPORTED_TYPES", "ExternalPluginContextLoader", "_externalPluginDataSource", "_tokenDataSource", "_uniswapLoader", "loggerFactory", "input", "expectedTypes", "type", "to", "data", "selector", "chainId", "eitherDappInfos", "result", "liftEither", "dappInfos", "externalPluginContext", "customLoader", "tokens", "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 u=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var I=(l,o,c,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of x(o))!D.call(l,e)&&e!==c&&u(l,e,{get:()=>o[e],enumerable:!(r=f(o,e))||r.enumerable});return l};var g=(l,o,c)=>(c=l!=null?y(b(l)):{},I(o||!l||!l.__esModule?u(c,"default",{value:l,enumerable:!0}):c,l));var E=require("ethers"),d=require("purify-ts"),s=g(require("@/external-plugin/__tests__/abi.json")),m=require("../../external-plugin/domain/ExternalPluginContextLoader"),a=require("../../shared/model/ClearSignContext");const i=({abi:l,selectorDetails:o})=>({abi:l,selectorDetails:{erc20OfInterest:[],method:"",plugin:"",serializedData:"123456",signature:"7890",...o}}),p=(l,o,c)=>{const e=new E.Interface(JSON.stringify(l)).encodeFunctionData(o,c);return{to:"0x0",data:e,selector:e.slice(0,10),chainId:1}};describe("ExternalPluginContextLoader",()=>{const l={getTokenInfosPayload:vi.fn()},o={getDappInfos:vi.fn()},c={canHandle:vi.fn(),load:vi.fn()},r=new m.ExternalPluginContextLoader(o,l,c);beforeEach(()=>{vi.clearAllMocks(),vi.spyOn(l,"getTokenInfosPayload").mockImplementation(({address:e})=>Promise.resolve((0,d.Right)(`payload-${e}`)))}),describe("canHandle function",()=>{const e={to:"0x1234567890123456789012345678901234567890",data:"0x095ea7b30000000000000000000000001234567890123456789012345678901234567890",selector:"0x095ea7b3",chainId:1};it("should return true for valid input",()=>{expect(r.canHandle(e,[a.ClearSignContextType.EXTERNAL_PLUGIN,a.ClearSignContextType.TOKEN])).toBe(!0)}),it("should return false for invalid expected type",()=>{expect(r.canHandle(e,[a.ClearSignContextType.NFT])).toBe(!1),expect(r.canHandle(e,[a.ClearSignContextType.TOKEN])).toBe(!1),expect(r.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,n)=>{expect(r.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,n)=>{expect(r.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,n)=>{expect(r.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,n)=>{expect(r.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=p(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(void 0));const t=await r.load(e);expect(t).toEqual([])}),it("should return e plugin if no erc20OfInterest is provided",async()=>{const e=i({abi:s.default,selectorDetails:{erc20OfInterest:[],method:"singleParam",plugin:"TestPlugin"}}),t=p(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e));const n=await r.load(t);expect(c.canHandle).not.toHaveBeenCalled(),expect(n).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=i({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam",plugin:"TestPlugin"}}),t=p(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e));const n=await r.load(t);expect(c.canHandle).not.toHaveBeenCalled(),expect(n).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=i({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),t=p(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e)),vi.spyOn(l,"getTokenInfosPayload").mockResolvedValue((0,d.Left)(Error("error")));const n=await r.load(t);expect(c.canHandle).not.toHaveBeenCalled(),expect(n).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=i({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken","toToken"],method:"multipleParams"}}),t=p(s.default,"multipleParams",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e));const n=await r.load(t);expect(n).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=i({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken.0","fromToken.1","fromToken.2","fromToken.-1"],method:"arrayParam"}}),t=p(s.default,"arrayParam",[["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7","0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e));const n=await r.load(t);expect(n).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=i({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),t=p(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e)),vi.spyOn(l,"getTokenInfosPayload").mockResolvedValue((0,d.Left)(new Error("error")));const n=await r.load(t);expect(n).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=i({abi:[{fakeabi:"notworking"}],selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),t=p(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e));const n=await r.load(t);expect(n).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=i({abi:s.default,selectorDetails:{erc20OfInterest:["notFound"],method:"singleParam"}}),t=p(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e));const n=await r.load(t);expect(n).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=i({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken.3"],method:"arrayParam"}}),t=p(s.default,"arrayParam",[["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7","0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e));const n=await r.load(t);expect(n).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=i({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=p(s.default,"complexStructParam",[{address1:"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",param1:{param2:[{param3:{addresses:["0xdAC17F958D2ee523a2206206994597C13D831ec7","0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"]}},{param3:{addresses:["0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]}}]}}]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e));const n=await r.load(t);expect(n).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 a plugin with Uniswap not being able to load token",async()=>{const e=i({abi:s.default,selectorDetails:{erc20OfInterest:[],method:"singleParam",plugin:"Uniswap"}}),t=p(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e)),vi.spyOn(c,"canHandle").mockReturnValueOnce(!1);const n=await r.load(t);expect(c.canHandle).toHaveBeenCalled(),expect(c.load).not.toHaveBeenCalled(),expect(n).toEqual([{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return a plugin with Uniswap extracted tokens",async()=>{const e=i({abi:s.default,selectorDetails:{erc20OfInterest:[],method:"singleParam",plugin:"Uniswap"}}),t=p(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e)),vi.spyOn(c,"canHandle").mockReturnValueOnce(!0),vi.spyOn(c,"load").mockResolvedValue([{type:a.ClearSignContextType.TOKEN,payload:"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"}]);const n=await r.load(t);expect(c.canHandle).toHaveBeenCalled(),expect(c.load).toHaveBeenCalled(),expect(n).toEqual([{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"}])}),it("should return an error when datasource return a Left",async()=>{const e=p(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Left)(new Error("error")));const t=await r.load(e);expect(t).toEqual([{type:a.ClearSignContextType.ERROR,error:new Error("error")}])})})});
1
+ "use strict";var y=Object.create;var u=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var I=(l,o,c,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of x(o))!D.call(l,e)&&e!==c&&u(l,e,{get:()=>o[e],enumerable:!(r=f(o,e))||r.enumerable});return l};var g=(l,o,c)=>(c=l!=null?y(b(l)):{},I(o||!l||!l.__esModule?u(c,"default",{value:l,enumerable:!0}):c,l));var E=require("ethers"),d=require("purify-ts"),s=g(require("@/external-plugin/__tests__/abi.json")),m=require("../../external-plugin/domain/ExternalPluginContextLoader"),a=require("../../shared/model/ClearSignContext");const h=()=>({debug:vi.fn(),info:vi.fn(),warn:vi.fn(),error:vi.fn(),subscribers:[]}),i=({abi:l,selectorDetails:o})=>({abi:l,selectorDetails:{erc20OfInterest:[],method:"",plugin:"",serializedData:"123456",signature:"7890",...o}}),p=(l,o,c)=>{const e=new E.Interface(JSON.stringify(l)).encodeFunctionData(o,c);return{to:"0x0",data:e,selector:e.slice(0,10),chainId:1}};describe("ExternalPluginContextLoader",()=>{const l={getTokenInfosPayload:vi.fn()},o={getDappInfos:vi.fn()},c={canHandle:vi.fn(),load:vi.fn()},r=new m.ExternalPluginContextLoader(o,l,c,h);beforeEach(()=>{vi.clearAllMocks(),vi.spyOn(l,"getTokenInfosPayload").mockImplementation(({address:e})=>Promise.resolve((0,d.Right)(`payload-${e}`)))}),describe("canHandle function",()=>{const e={to:"0x1234567890123456789012345678901234567890",data:"0x095ea7b30000000000000000000000001234567890123456789012345678901234567890",selector:"0x095ea7b3",chainId:1};it("should return true for valid input",()=>{expect(r.canHandle(e,[a.ClearSignContextType.EXTERNAL_PLUGIN,a.ClearSignContextType.TOKEN])).toBe(!0)}),it("should return false for invalid expected type",()=>{expect(r.canHandle(e,[a.ClearSignContextType.NFT])).toBe(!1),expect(r.canHandle(e,[a.ClearSignContextType.TOKEN])).toBe(!1),expect(r.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,n)=>{expect(r.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,n)=>{expect(r.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,n)=>{expect(r.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,n)=>{expect(r.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=p(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(void 0));const t=await r.load(e);expect(t).toEqual([])}),it("should return e plugin if no erc20OfInterest is provided",async()=>{const e=i({abi:s.default,selectorDetails:{erc20OfInterest:[],method:"singleParam",plugin:"TestPlugin"}}),t=p(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e));const n=await r.load(t);expect(c.canHandle).not.toHaveBeenCalled(),expect(n).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=i({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam",plugin:"TestPlugin"}}),t=p(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e));const n=await r.load(t);expect(c.canHandle).not.toHaveBeenCalled(),expect(n).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=i({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),t=p(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e)),vi.spyOn(l,"getTokenInfosPayload").mockResolvedValue((0,d.Left)(Error("error")));const n=await r.load(t);expect(c.canHandle).not.toHaveBeenCalled(),expect(n).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=i({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken","toToken"],method:"multipleParams"}}),t=p(s.default,"multipleParams",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e));const n=await r.load(t);expect(n).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=i({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken.0","fromToken.1","fromToken.2","fromToken.-1"],method:"arrayParam"}}),t=p(s.default,"arrayParam",[["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7","0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e));const n=await r.load(t);expect(n).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=i({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),t=p(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e)),vi.spyOn(l,"getTokenInfosPayload").mockResolvedValue((0,d.Left)(new Error("error")));const n=await r.load(t);expect(n).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=i({abi:[{fakeabi:"notworking"}],selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),t=p(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e));const n=await r.load(t);expect(n).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=i({abi:s.default,selectorDetails:{erc20OfInterest:["notFound"],method:"singleParam"}}),t=p(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e));const n=await r.load(t);expect(n).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=i({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken.3"],method:"arrayParam"}}),t=p(s.default,"arrayParam",[["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7","0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e));const n=await r.load(t);expect(n).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=i({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=p(s.default,"complexStructParam",[{address1:"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",param1:{param2:[{param3:{addresses:["0xdAC17F958D2ee523a2206206994597C13D831ec7","0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"]}},{param3:{addresses:["0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]}}]}}]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e));const n=await r.load(t);expect(n).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 a plugin with Uniswap not being able to load token",async()=>{const e=i({abi:s.default,selectorDetails:{erc20OfInterest:[],method:"singleParam",plugin:"Uniswap"}}),t=p(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e)),vi.spyOn(c,"canHandle").mockReturnValueOnce(!1);const n=await r.load(t);expect(c.canHandle).toHaveBeenCalled(),expect(c.load).not.toHaveBeenCalled(),expect(n).toEqual([{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return a plugin with Uniswap extracted tokens",async()=>{const e=i({abi:s.default,selectorDetails:{erc20OfInterest:[],method:"singleParam",plugin:"Uniswap"}}),t=p(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e)),vi.spyOn(c,"canHandle").mockReturnValueOnce(!0),vi.spyOn(c,"load").mockResolvedValue([{type:a.ClearSignContextType.TOKEN,payload:"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"}]);const n=await r.load(t);expect(c.canHandle).toHaveBeenCalled(),expect(c.load).toHaveBeenCalled(),expect(n).toEqual([{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"}])}),it("should return an error when datasource return a Left",async()=>{const e=p(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Left)(new Error("error")));const t=await r.load(e);expect(t).toEqual([{type:a.ClearSignContextType.ERROR,error:new Error("error")}])})})});
2
2
  //# sourceMappingURL=ExternalPluginContextLoader.test.js.map