@ledgerhq/context-module 1.8.0 → 1.9.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 (130) hide show
  1. package/lib/cjs/package.json +2 -2
  2. package/lib/cjs/src/DefaultContextModule.js +1 -1
  3. package/lib/cjs/src/DefaultContextModule.js.map +3 -3
  4. package/lib/cjs/src/di.js +1 -1
  5. package/lib/cjs/src/di.js.map +3 -3
  6. package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.js +1 -1
  7. package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.js.map +3 -3
  8. package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.test.js +1 -1
  9. package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.test.js.map +3 -3
  10. package/lib/cjs/src/pki/model/KeyUsage.js +1 -1
  11. package/lib/cjs/src/pki/model/KeyUsage.js.map +2 -2
  12. package/lib/cjs/src/safe/data/HttpSafeAccountDataSource.js +2 -0
  13. package/lib/cjs/src/safe/data/HttpSafeAccountDataSource.js.map +7 -0
  14. package/lib/cjs/src/safe/data/HttpSafeAccountDataSource.test.js +2 -0
  15. package/lib/cjs/src/safe/data/HttpSafeAccountDataSource.test.js.map +7 -0
  16. package/lib/cjs/src/safe/data/SafeAccountDataSource.js +2 -0
  17. package/lib/cjs/src/safe/data/SafeAccountDataSource.js.map +7 -0
  18. package/lib/cjs/src/safe/data/dto/SafeAccountDto.js +2 -0
  19. package/lib/cjs/src/safe/data/dto/SafeAccountDto.js.map +7 -0
  20. package/lib/cjs/src/safe/di/safeModuleFactory.js +2 -0
  21. package/lib/cjs/src/safe/di/safeModuleFactory.js.map +7 -0
  22. package/lib/cjs/src/safe/di/safeModuleFactory.test.js +2 -0
  23. package/lib/cjs/src/safe/di/safeModuleFactory.test.js.map +7 -0
  24. package/lib/cjs/src/safe/di/safeTypes.js +2 -0
  25. package/lib/cjs/src/safe/di/safeTypes.js.map +7 -0
  26. package/lib/cjs/src/safe/domain/SafeAddressLoader.js +2 -0
  27. package/lib/cjs/src/safe/domain/SafeAddressLoader.js.map +7 -0
  28. package/lib/cjs/src/safe/domain/SafeAddressLoader.test.js +2 -0
  29. package/lib/cjs/src/safe/domain/SafeAddressLoader.test.js.map +7 -0
  30. package/lib/cjs/src/shared/model/ClearSignContext.js +1 -1
  31. package/lib/cjs/src/shared/model/ClearSignContext.js.map +2 -2
  32. package/lib/cjs/src/shared/utils/KeyUsageMapper.js +1 -1
  33. package/lib/cjs/src/shared/utils/KeyUsageMapper.js.map +2 -2
  34. package/lib/cjs/src/shared/utils/KeyUsageMapper.test.js +1 -1
  35. package/lib/cjs/src/shared/utils/KeyUsageMapper.test.js.map +2 -2
  36. package/lib/cjs/src/token/data/HttpTokenDataSource.js +1 -1
  37. package/lib/cjs/src/token/data/HttpTokenDataSource.js.map +2 -2
  38. package/lib/cjs/src/token/data/HttpTokenDataSource.test.js +1 -1
  39. package/lib/cjs/src/token/data/HttpTokenDataSource.test.js.map +2 -2
  40. package/lib/cjs/src/uniswap/constants/uniswap.js +1 -1
  41. package/lib/cjs/src/uniswap/constants/uniswap.js.map +3 -3
  42. package/lib/cjs/src/uniswap/domain/UniswapContextLoader.js +1 -1
  43. package/lib/cjs/src/uniswap/domain/UniswapContextLoader.js.map +3 -3
  44. package/lib/cjs/src/uniswap/domain/UniswapContextLoader.test.js +1 -1
  45. package/lib/cjs/src/uniswap/domain/UniswapContextLoader.test.js.map +2 -2
  46. package/lib/esm/package.json +2 -2
  47. package/lib/esm/src/DefaultContextModule.js +1 -1
  48. package/lib/esm/src/DefaultContextModule.js.map +3 -3
  49. package/lib/esm/src/di.js +1 -1
  50. package/lib/esm/src/di.js.map +3 -3
  51. package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.js +1 -1
  52. package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.js.map +3 -3
  53. package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.test.js +1 -1
  54. package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.test.js.map +3 -3
  55. package/lib/esm/src/pki/model/KeyUsage.js +1 -1
  56. package/lib/esm/src/pki/model/KeyUsage.js.map +2 -2
  57. package/lib/esm/src/safe/data/HttpSafeAccountDataSource.js +2 -0
  58. package/lib/esm/src/safe/data/HttpSafeAccountDataSource.js.map +7 -0
  59. package/lib/esm/src/safe/data/HttpSafeAccountDataSource.test.js +2 -0
  60. package/lib/esm/src/safe/data/HttpSafeAccountDataSource.test.js.map +7 -0
  61. package/lib/esm/src/safe/data/SafeAccountDataSource.js +1 -0
  62. package/lib/esm/src/safe/data/SafeAccountDataSource.js.map +7 -0
  63. package/lib/esm/src/safe/data/dto/SafeAccountDto.js +1 -0
  64. package/lib/esm/src/safe/data/dto/SafeAccountDto.js.map +7 -0
  65. package/lib/esm/src/safe/di/safeModuleFactory.js +2 -0
  66. package/lib/esm/src/safe/di/safeModuleFactory.js.map +7 -0
  67. package/lib/esm/src/safe/di/safeModuleFactory.test.js +2 -0
  68. package/lib/esm/src/safe/di/safeModuleFactory.test.js.map +7 -0
  69. package/lib/esm/src/safe/di/safeTypes.js +2 -0
  70. package/lib/esm/src/safe/di/safeTypes.js.map +7 -0
  71. package/lib/esm/src/safe/domain/SafeAddressLoader.js +2 -0
  72. package/lib/esm/src/safe/domain/SafeAddressLoader.js.map +7 -0
  73. package/lib/esm/src/safe/domain/SafeAddressLoader.test.js +2 -0
  74. package/lib/esm/src/safe/domain/SafeAddressLoader.test.js.map +7 -0
  75. package/lib/esm/src/shared/model/ClearSignContext.js +1 -1
  76. package/lib/esm/src/shared/model/ClearSignContext.js.map +2 -2
  77. package/lib/esm/src/shared/utils/KeyUsageMapper.js +1 -1
  78. package/lib/esm/src/shared/utils/KeyUsageMapper.js.map +2 -2
  79. package/lib/esm/src/shared/utils/KeyUsageMapper.test.js +1 -1
  80. package/lib/esm/src/shared/utils/KeyUsageMapper.test.js.map +2 -2
  81. package/lib/esm/src/token/data/HttpTokenDataSource.js +1 -1
  82. package/lib/esm/src/token/data/HttpTokenDataSource.js.map +2 -2
  83. package/lib/esm/src/token/data/HttpTokenDataSource.test.js +1 -1
  84. package/lib/esm/src/token/data/HttpTokenDataSource.test.js.map +2 -2
  85. package/lib/esm/src/uniswap/constants/uniswap.js +1 -1
  86. package/lib/esm/src/uniswap/constants/uniswap.js.map +3 -3
  87. package/lib/esm/src/uniswap/domain/UniswapContextLoader.js +1 -1
  88. package/lib/esm/src/uniswap/domain/UniswapContextLoader.js.map +3 -3
  89. package/lib/esm/src/uniswap/domain/UniswapContextLoader.test.js +1 -1
  90. package/lib/esm/src/uniswap/domain/UniswapContextLoader.test.js.map +3 -3
  91. package/lib/types/src/DefaultContextModule.d.ts.map +1 -1
  92. package/lib/types/src/di.d.ts.map +1 -1
  93. package/lib/types/src/external-plugin/domain/ExternalPluginContextLoader.d.ts +9 -1
  94. package/lib/types/src/external-plugin/domain/ExternalPluginContextLoader.d.ts.map +1 -1
  95. package/lib/types/src/pki/model/KeyUsage.d.ts +2 -1
  96. package/lib/types/src/pki/model/KeyUsage.d.ts.map +1 -1
  97. package/lib/types/src/safe/data/HttpSafeAccountDataSource.d.ts +11 -0
  98. package/lib/types/src/safe/data/HttpSafeAccountDataSource.d.ts.map +1 -0
  99. package/lib/types/src/safe/data/HttpSafeAccountDataSource.test.d.ts +2 -0
  100. package/lib/types/src/safe/data/HttpSafeAccountDataSource.test.d.ts.map +1 -0
  101. package/lib/types/src/safe/data/SafeAccountDataSource.d.ts +20 -0
  102. package/lib/types/src/safe/data/SafeAccountDataSource.d.ts.map +1 -0
  103. package/lib/types/src/safe/data/dto/SafeAccountDto.d.ts +10 -0
  104. package/lib/types/src/safe/data/dto/SafeAccountDto.d.ts.map +1 -0
  105. package/lib/types/src/safe/di/safeModuleFactory.d.ts +3 -0
  106. package/lib/types/src/safe/di/safeModuleFactory.d.ts.map +1 -0
  107. package/lib/types/src/safe/di/safeModuleFactory.test.d.ts +2 -0
  108. package/lib/types/src/safe/di/safeModuleFactory.test.d.ts.map +1 -0
  109. package/lib/types/src/safe/di/safeTypes.d.ts +5 -0
  110. package/lib/types/src/safe/di/safeTypes.d.ts.map +1 -0
  111. package/lib/types/src/safe/domain/SafeAddressLoader.d.ts +19 -0
  112. package/lib/types/src/safe/domain/SafeAddressLoader.d.ts.map +1 -0
  113. package/lib/types/src/safe/domain/SafeAddressLoader.test.d.ts +2 -0
  114. package/lib/types/src/safe/domain/SafeAddressLoader.test.d.ts.map +1 -0
  115. package/lib/types/src/shared/model/ClearSignContext.d.ts +3 -1
  116. package/lib/types/src/shared/model/ClearSignContext.d.ts.map +1 -1
  117. package/lib/types/src/shared/utils/KeyUsageMapper.d.ts.map +1 -1
  118. package/lib/types/src/token/data/HttpTokenDataSource.d.ts.map +1 -1
  119. package/lib/types/src/uniswap/constants/uniswap.d.ts +0 -1
  120. package/lib/types/src/uniswap/constants/uniswap.d.ts.map +1 -1
  121. package/lib/types/src/uniswap/domain/UniswapContextLoader.d.ts +0 -8
  122. package/lib/types/src/uniswap/domain/UniswapContextLoader.d.ts.map +1 -1
  123. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  124. package/package.json +3 -3
  125. package/lib/cjs/src/uniswap/constants/plugin.js +0 -2
  126. package/lib/cjs/src/uniswap/constants/plugin.js.map +0 -7
  127. package/lib/esm/src/uniswap/constants/plugin.js +0 -2
  128. package/lib/esm/src/uniswap/constants/plugin.js.map +0 -7
  129. package/lib/types/src/uniswap/constants/plugin.d.ts +0 -3
  130. package/lib/types/src/uniswap/constants/plugin.d.ts.map +0 -1
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ledgerhq/context-module",
3
- "version": "1.8.0",
3
+ "version": "1.9.0",
4
4
  "private": false,
5
5
  "license": "Apache-2.0",
6
6
  "exports": {
@@ -53,6 +53,6 @@
53
53
  "reflect-metadata": "catalog:"
54
54
  },
55
55
  "peerDependencies": {
56
- "@ledgerhq/device-management-kit": "^0.9.0"
56
+ "@ledgerhq/device-management-kit": "workspace:*"
57
57
  }
58
58
  }
@@ -1,2 +1,2 @@
1
- "use strict";var s=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var S=(r,e)=>{for(var t in e)s(r,t,{get:e[t],enumerable:!0})},b=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of D(e))!k.call(r,a)&&a!==t&&s(r,a,{get:()=>e[a],enumerable:!(o=T(e,a))||o.enumerable});return r};var w=r=>b(s({},"__esModule",{value:!0}),r);var W={};S(W,{DefaultContextModule:()=>F});module.exports=w(W);var c=require("purify-ts"),x=require("./calldata/di/calldataTypes"),m=require("./dynamic-network/di/dynamicNetworkTypes"),C=require("./trusted-name/di/trustedNameTypes"),L=require("./external-plugin/di/externalPluginTypes"),l=require("./nft/di/nftTypes"),y=require("./proxy/di/proxyTypes"),n=require("./shared/model/ClearSignContext"),u=require("./solana/di/solanaContextTypes"),p=require("./token/di/tokenTypes"),f=require("./typed-data/di/typedDataTypes"),h=require("./uniswap/di/uniswapTypes"),_=require("./web3-check/di/web3CheckTypes"),g=require("./di");class F{_container;_loaders;_typedDataLoader;_web3CheckLoader;_solanaLoader;_fieldLoaders;constructor(e){this._container=(0,g.makeContainer)({config:e}),this._loaders=e.defaultLoaders?this._getDefaultLoaders():[],this._loaders.push(...e.customLoaders),this._fieldLoaders=e.defaultFieldLoaders?this._getDefaultFieldLoaders():[],this._fieldLoaders.push(...e.customFieldLoaders),this._typedDataLoader=e.customTypedDataLoader??this._getDefaultTypedDataLoader(),this._web3CheckLoader=e.customWeb3CheckLoader??this._getWeb3CheckLoader(),this._solanaLoader=e.customSolanaLoader??this._getSolanaLoader()}_getDefaultFieldLoaders(){return[this._container.get(l.nftTypes.NftContextFieldLoader),this._container.get(p.tokenTypes.TokenContextFieldLoader),this._container.get(C.trustedNameTypes.TrustedNameContextFieldLoader),this._container.get(y.proxyTypes.ProxyContextFieldLoader)]}_getDefaultLoaders(){return[this._container.get(L.externalPluginTypes.ExternalPluginContextLoader),this._container.get(C.trustedNameTypes.TrustedNameContextLoader),this._container.get(l.nftTypes.NftContextLoader),this._container.get(p.tokenTypes.TokenContextLoader),this._container.get(x.calldataTypes.CalldataContextLoader),this._container.get(h.uniswapTypes.UniswapContextLoader),this._container.get(m.dynamicNetworkTypes.DynamicNetworkContextLoader)]}_getDefaultTypedDataLoader(){return this._container.get(f.typedDataTypes.TypedDataContextLoader)}_getWeb3CheckLoader(){return this._container.get(_.web3CheckTypes.Web3CheckContextLoader)}_getSolanaLoader(){try{return this._container.get(u.solanaContextTypes.SolanaContextLoader)}catch{return{load:async e=>(0,c.Left)(new Error("[ContextModule] - DefaultContextModule: no SolanaContextLoader bound"))}}}async getContexts(e,t){const o=Object.values(n.ClearSignContextType),i=this._loaders.filter(d=>d.canHandle(e,t??o)).map(d=>d.load(e));return(await Promise.all(i)).flat()}async getFieldContext(e,t){const o=this._fieldLoaders.filter(a=>a.canHandle(e,t));if(o.length===0)return Promise.resolve({type:n.ClearSignContextType.ERROR,error:new Error(`Loader not found for field: ${e} and expected type: ${t}`)});for(const a of o){const i=await a.loadField(e);if(i.type!==n.ClearSignContextType.ERROR)return i}return{type:n.ClearSignContextType.ERROR,error:new Error(`Loader not found for field: ${e} and expected type: ${t}`)}}async getTypedDataFilters(e){return this._typedDataLoader.load(e)}async getWeb3Checks(e){return(await this._web3CheckLoader.load(e)).caseOf({Right:o=>({type:n.ClearSignContextType.WEB3_CHECK,payload:o.descriptor,certificate:o.certificate}),Left:()=>null})}async getSolanaContext(e){return await this._solanaLoader.load(e)}}0&&(module.exports={DefaultContextModule});
1
+ "use strict";var s=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var k=(r,e)=>{for(var t in e)s(r,t,{get:e[t],enumerable:!0})},b=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of D(e))!S.call(r,a)&&a!==t&&s(r,a,{get:()=>e[a],enumerable:!(o=T(e,a))||o.enumerable});return r};var w=r=>b(s({},"__esModule",{value:!0}),r);var W={};k(W,{DefaultContextModule:()=>F});module.exports=w(W);var c=require("purify-ts"),x=require("./calldata/di/calldataTypes"),m=require("./dynamic-network/di/dynamicNetworkTypes"),l=require("./trusted-name/di/trustedNameTypes"),L=require("./external-plugin/di/externalPluginTypes"),C=require("./nft/di/nftTypes"),y=require("./proxy/di/proxyTypes"),f=require("./safe/di/safeTypes"),n=require("./shared/model/ClearSignContext"),u=require("./solana/di/solanaContextTypes"),p=require("./token/di/tokenTypes"),h=require("./typed-data/di/typedDataTypes"),_=require("./web3-check/di/web3CheckTypes"),g=require("./di");class F{_container;_loaders;_typedDataLoader;_web3CheckLoader;_solanaLoader;_fieldLoaders;constructor(e){this._container=(0,g.makeContainer)({config:e}),this._loaders=e.defaultLoaders?this._getDefaultLoaders():[],this._loaders.push(...e.customLoaders),this._fieldLoaders=e.defaultFieldLoaders?this._getDefaultFieldLoaders():[],this._fieldLoaders.push(...e.customFieldLoaders),this._typedDataLoader=e.customTypedDataLoader??this._getDefaultTypedDataLoader(),this._web3CheckLoader=e.customWeb3CheckLoader??this._getWeb3CheckLoader(),this._solanaLoader=e.customSolanaLoader??this._getSolanaLoader()}_getDefaultFieldLoaders(){return[this._container.get(C.nftTypes.NftContextFieldLoader),this._container.get(p.tokenTypes.TokenContextFieldLoader),this._container.get(l.trustedNameTypes.TrustedNameContextFieldLoader),this._container.get(y.proxyTypes.ProxyContextFieldLoader)]}_getDefaultLoaders(){return[this._container.get(L.externalPluginTypes.ExternalPluginContextLoader),this._container.get(l.trustedNameTypes.TrustedNameContextLoader),this._container.get(C.nftTypes.NftContextLoader),this._container.get(p.tokenTypes.TokenContextLoader),this._container.get(x.calldataTypes.CalldataContextLoader),this._container.get(m.dynamicNetworkTypes.DynamicNetworkContextLoader),this._container.get(f.safeTypes.SafeAddressLoader)]}_getDefaultTypedDataLoader(){return this._container.get(h.typedDataTypes.TypedDataContextLoader)}_getWeb3CheckLoader(){return this._container.get(_.web3CheckTypes.Web3CheckContextLoader)}_getSolanaLoader(){try{return this._container.get(u.solanaContextTypes.SolanaContextLoader)}catch{return{load:async e=>(0,c.Left)(new Error("[ContextModule] - DefaultContextModule: no SolanaContextLoader bound"))}}}async getContexts(e,t){const o=Object.values(n.ClearSignContextType),d=this._loaders.filter(i=>i.canHandle(e,t??o)).map(i=>i.load(e));return(await Promise.all(d)).flat()}async getFieldContext(e,t){const o=this._fieldLoaders.filter(a=>a.canHandle(e,t));if(o.length===0)return Promise.resolve({type:n.ClearSignContextType.ERROR,error:new Error(`Loader not found for field: ${e} and expected type: ${t}`)});for(const a of o){const d=await a.loadField(e);if(d.type!==n.ClearSignContextType.ERROR)return d}return{type:n.ClearSignContextType.ERROR,error:new Error(`Loader not found for field: ${e} and expected type: ${t}`)}}async getTypedDataFilters(e){return this._typedDataLoader.load(e)}async getWeb3Checks(e){return(await this._web3CheckLoader.load(e)).caseOf({Right:o=>({type:n.ClearSignContextType.WEB3_CHECK,payload:o.descriptor,certificate:o.certificate}),Left:()=>null})}async getSolanaContext(e){return await this._solanaLoader.load(e)}}0&&(module.exports={DefaultContextModule});
2
2
  //# sourceMappingURL=DefaultContextModule.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/DefaultContextModule.ts"],
4
- "sourcesContent": ["import { type Container } from \"inversify\";\nimport { Left } from \"purify-ts\";\n\nimport { calldataTypes } from \"@/calldata/di/calldataTypes\";\nimport { dynamicNetworkTypes } from \"@/dynamic-network/di/dynamicNetworkTypes\";\nimport type { TypedDataClearSignContext } from \"@/shared/model/TypedDataClearSignContext\";\nimport type { TypedDataContext } from \"@/shared/model/TypedDataContext\";\nimport { trustedNameTypes } from \"@/trusted-name/di/trustedNameTypes\";\n\nimport { type ContextModuleConfig } from \"./config/model/ContextModuleConfig\";\nimport { externalPluginTypes } from \"./external-plugin/di/externalPluginTypes\";\nimport { nftTypes } from \"./nft/di/nftTypes\";\nimport { proxyTypes } from \"./proxy/di/proxyTypes\";\nimport { type ContextFieldLoader } from \"./shared/domain/ContextFieldLoader\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport {\n type ClearSignContext,\n type ClearSignContextSuccess,\n ClearSignContextType,\n} from \"./shared/model/ClearSignContext\";\nimport { type SolanaTransactionContext } from \"./shared/model/SolanaTransactionContext\";\nimport { solanaContextTypes } from \"./solana/di/solanaContextTypes\";\nimport { type SolanaContextLoader } from \"./solana/domain/SolanaContextLoader\";\nimport { type SolanaTransactionContextResult } from \"./solana/domain/solanaContextTypes\";\nimport { tokenTypes } from \"./token/di/tokenTypes\";\nimport { typedDataTypes } from \"./typed-data/di/typedDataTypes\";\nimport type { TypedDataContextLoader } from \"./typed-data/domain/TypedDataContextLoader\";\nimport { uniswapTypes } from \"./uniswap/di/uniswapTypes\";\nimport { web3CheckTypes } from \"./web3-check/di/web3CheckTypes\";\nimport { type Web3CheckContextLoader } from \"./web3-check/domain/Web3CheckContextLoader\";\nimport {\n type Web3CheckContext,\n type Web3Checks,\n} from \"./web3-check/domain/web3CheckTypes\";\nimport { type ContextModule } from \"./ContextModule\";\nimport { makeContainer } from \"./di\";\n\nexport class DefaultContextModule implements ContextModule {\n private _container: Container;\n private _loaders: ContextLoader<unknown>[];\n private _typedDataLoader: TypedDataContextLoader;\n private _web3CheckLoader: Web3CheckContextLoader;\n private _solanaLoader: SolanaContextLoader;\n private _fieldLoaders: ContextFieldLoader<unknown>[];\n\n constructor(args: ContextModuleConfig) {\n this._container = makeContainer({ config: args });\n\n this._loaders = args.defaultLoaders ? this._getDefaultLoaders() : [];\n this._loaders.push(...args.customLoaders);\n\n this._fieldLoaders = args.defaultFieldLoaders\n ? this._getDefaultFieldLoaders()\n : [];\n this._fieldLoaders.push(...args.customFieldLoaders);\n\n this._typedDataLoader =\n args.customTypedDataLoader ?? this._getDefaultTypedDataLoader();\n this._web3CheckLoader =\n args.customWeb3CheckLoader ?? this._getWeb3CheckLoader();\n this._solanaLoader = args.customSolanaLoader ?? this._getSolanaLoader();\n }\n\n private _getDefaultFieldLoaders(): ContextFieldLoader[] {\n return [\n this._container.get<ContextFieldLoader>(nftTypes.NftContextFieldLoader),\n this._container.get<ContextFieldLoader>(\n tokenTypes.TokenContextFieldLoader,\n ),\n this._container.get<ContextFieldLoader>(\n trustedNameTypes.TrustedNameContextFieldLoader,\n ),\n this._container.get<ContextFieldLoader>(\n proxyTypes.ProxyContextFieldLoader,\n ),\n ];\n }\n\n private _getDefaultLoaders(): ContextLoader<unknown>[] {\n return [\n this._container.get<ContextLoader>(\n externalPluginTypes.ExternalPluginContextLoader,\n ),\n this._container.get<ContextLoader>(\n trustedNameTypes.TrustedNameContextLoader,\n ),\n this._container.get<ContextLoader>(nftTypes.NftContextLoader),\n this._container.get<ContextLoader>(tokenTypes.TokenContextLoader),\n this._container.get<ContextLoader>(calldataTypes.CalldataContextLoader),\n this._container.get<ContextLoader>(uniswapTypes.UniswapContextLoader),\n this._container.get<ContextLoader>(\n dynamicNetworkTypes.DynamicNetworkContextLoader,\n ),\n ];\n }\n\n private _getDefaultTypedDataLoader(): TypedDataContextLoader {\n return this._container.get<TypedDataContextLoader>(\n typedDataTypes.TypedDataContextLoader,\n );\n }\n\n private _getWeb3CheckLoader(): Web3CheckContextLoader {\n return this._container.get<Web3CheckContextLoader>(\n web3CheckTypes.Web3CheckContextLoader,\n );\n }\n\n private _getSolanaLoader(): SolanaContextLoader {\n try {\n return this._container.get<SolanaContextLoader>(\n solanaContextTypes.SolanaContextLoader,\n );\n } catch {\n return {\n load: async (_ctx) =>\n Left(\n new Error(\n \"[ContextModule] - DefaultContextModule: no SolanaContextLoader bound\",\n ),\n ),\n };\n }\n }\n\n public async getContexts(\n input: unknown,\n expectedTypes?: ClearSignContextType[],\n ): Promise<ClearSignContext[]> {\n const allContextTypes = Object.values(ClearSignContextType);\n const loaders = this._loaders.filter((l) =>\n l.canHandle(input, expectedTypes ?? allContextTypes),\n );\n const promises = loaders.map((fetcher) => fetcher.load(input));\n const responses = await Promise.all(promises);\n return responses.flat();\n }\n\n public async getFieldContext<TInput>(\n field: TInput,\n expectedType: ClearSignContextType,\n ): Promise<ClearSignContext> {\n const loaders = this._fieldLoaders.filter((l) =>\n l.canHandle(field, expectedType),\n );\n if (loaders.length === 0) {\n return Promise.resolve({\n type: ClearSignContextType.ERROR,\n error: new Error(\n `Loader not found for field: ${field} and expected type: ${expectedType}`,\n ),\n });\n }\n\n for (const loader of loaders) {\n const context = await loader.loadField(field);\n if (context.type !== ClearSignContextType.ERROR) {\n return context;\n }\n }\n\n return {\n type: ClearSignContextType.ERROR,\n error: new Error(\n `Loader not found for field: ${field} and expected type: ${expectedType}`,\n ),\n };\n }\n\n public async getTypedDataFilters(\n typedData: TypedDataContext,\n ): Promise<TypedDataClearSignContext> {\n return this._typedDataLoader.load(typedData);\n }\n\n public async getWeb3Checks(\n transactionContext: Web3CheckContext,\n ): Promise<ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK> | null> {\n const web3Checks = await this._web3CheckLoader.load(transactionContext);\n\n return web3Checks.caseOf({\n Right: (checks: Web3Checks) => ({\n type: ClearSignContextType.WEB3_CHECK,\n payload: checks.descriptor,\n certificate: checks.certificate,\n }),\n Left: () => null,\n });\n }\n\n public async getSolanaContext(\n transactionContext: SolanaTransactionContext,\n ): Promise<SolanaTransactionContextResult> {\n return await this._solanaLoader.load(transactionContext);\n }\n}\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,IAAA,eAAAC,EAAAH,GACA,IAAAI,EAAqB,qBAErBC,EAA8B,uCAC9BC,EAAoC,oDAGpCC,EAAiC,8CAGjCC,EAAoC,oDACpCC,EAAyB,6BACzBC,EAA2B,iCAG3BC,EAIO,2CAEPC,EAAmC,0CAGnCC,EAA2B,iCAC3BC,EAA+B,0CAE/BC,EAA6B,qCAC7BC,EAA+B,0C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MAAOC,MACX,QACE,IAAI,MACF,sEACF,CACF,CACJ,CACF,CACF,CAEA,MAAa,YACXC,EACAC,EAC6B,CAC7B,MAAMC,EAAkB,OAAO,OAAO,sBAAoB,EAIpDC,EAHU,KAAK,SAAS,OAAQC,GACpCA,EAAE,UAAUJ,EAAOC,GAAiBC,CAAe,CACrD,EACyB,IAAKG,GAAYA,EAAQ,KAAKL,CAAK,CAAC,EAE7D,OADkB,MAAM,QAAQ,IAAIG,CAAQ,GAC3B,KAAK,CACxB,CAEA,MAAa,gBACXG,EACAC,EAC2B,CAC3B,MAAMC,EAAU,KAAK,cAAc,OAAQJ,GACzCA,EAAE,UAAUE,EAAOC,CAAY,CACjC,EACA,GAAIC,EAAQ,SAAW,EACrB,OAAO,QAAQ,QAAQ,CACrB,KAAM,uBAAqB,MAC3B,MAAO,IAAI,MACT,+BAA+BF,CAAK,uBAAuBC,CAAY,EACzE,CACF,CAAC,EAGH,UAAWE,KAAUD,EAAS,CAC5B,MAAME,EAAU,MAAMD,EAAO,UAAUH,CAAK,EAC5C,GAAII,EAAQ,OAAS,uBAAqB,MACxC,OAAOA,CAEX,CAEA,MAAO,CACL,KAAM,uBAAqB,MAC3B,MAAO,IAAI,MACT,+BAA+BJ,CAAK,uBAAuBC,CAAY,EACzE,CACF,CACF,CAEA,MAAa,oBACXI,EACoC,CACpC,OAAO,KAAK,iBAAiB,KAAKA,CAAS,CAC7C,CAEA,MAAa,cACXC,EAC0E,CAG1E,OAFmB,MAAM,KAAK,iBAAiB,KAAKA,CAAkB,GAEpD,OAAO,CACvB,MAAQC,IAAwB,CAC9B,KAAM,uBAAqB,WAC3B,QAASA,EAAO,WAChB,YAAaA,EAAO,WACtB,GACA,KAAM,IAAM,IACd,CAAC,CACH,CAEA,MAAa,iBACXD,EACyC,CACzC,OAAO,MAAM,KAAK,cAAc,KAAKA,CAAkB,CACzD,CACF",
6
- "names": ["DefaultContextModule_exports", "__export", "DefaultContextModule", "__toCommonJS", "import_purify_ts", "import_calldataTypes", "import_dynamicNetworkTypes", "import_trustedNameTypes", "import_externalPluginTypes", "import_nftTypes", "import_proxyTypes", "import_ClearSignContext", "import_solanaContextTypes", "import_tokenTypes", "import_typedDataTypes", "import_uniswapTypes", "import_web3CheckTypes", "import_di", "args", "_ctx", "input", "expectedTypes", "allContextTypes", "promises", "l", "fetcher", "field", "expectedType", "loaders", "loader", "context", "typedData", "transactionContext", "checks"]
4
+ "sourcesContent": ["import { type Container } from \"inversify\";\nimport { Left } from \"purify-ts\";\n\nimport { calldataTypes } from \"@/calldata/di/calldataTypes\";\nimport { dynamicNetworkTypes } from \"@/dynamic-network/di/dynamicNetworkTypes\";\nimport type { TypedDataClearSignContext } from \"@/shared/model/TypedDataClearSignContext\";\nimport type { TypedDataContext } from \"@/shared/model/TypedDataContext\";\nimport { trustedNameTypes } from \"@/trusted-name/di/trustedNameTypes\";\n\nimport { type ContextModuleConfig } from \"./config/model/ContextModuleConfig\";\nimport { externalPluginTypes } from \"./external-plugin/di/externalPluginTypes\";\nimport { nftTypes } from \"./nft/di/nftTypes\";\nimport { proxyTypes } from \"./proxy/di/proxyTypes\";\nimport { safeTypes } from \"./safe/di/safeTypes\";\nimport { type ContextFieldLoader } from \"./shared/domain/ContextFieldLoader\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport {\n type ClearSignContext,\n type ClearSignContextSuccess,\n ClearSignContextType,\n} from \"./shared/model/ClearSignContext\";\nimport { type SolanaTransactionContext } from \"./shared/model/SolanaTransactionContext\";\nimport { solanaContextTypes } from \"./solana/di/solanaContextTypes\";\nimport { type SolanaContextLoader } from \"./solana/domain/SolanaContextLoader\";\nimport { type SolanaTransactionContextResult } from \"./solana/domain/solanaContextTypes\";\nimport { tokenTypes } from \"./token/di/tokenTypes\";\nimport { typedDataTypes } from \"./typed-data/di/typedDataTypes\";\nimport type { TypedDataContextLoader } from \"./typed-data/domain/TypedDataContextLoader\";\nimport { web3CheckTypes } from \"./web3-check/di/web3CheckTypes\";\nimport { type Web3CheckContextLoader } from \"./web3-check/domain/Web3CheckContextLoader\";\nimport {\n type Web3CheckContext,\n type Web3Checks,\n} from \"./web3-check/domain/web3CheckTypes\";\nimport { type ContextModule } from \"./ContextModule\";\nimport { makeContainer } from \"./di\";\n\nexport class DefaultContextModule implements ContextModule {\n private _container: Container;\n private _loaders: ContextLoader<unknown>[];\n private _typedDataLoader: TypedDataContextLoader;\n private _web3CheckLoader: Web3CheckContextLoader;\n private _solanaLoader: SolanaContextLoader;\n private _fieldLoaders: ContextFieldLoader<unknown>[];\n\n constructor(args: ContextModuleConfig) {\n this._container = makeContainer({ config: args });\n\n this._loaders = args.defaultLoaders ? this._getDefaultLoaders() : [];\n this._loaders.push(...args.customLoaders);\n\n this._fieldLoaders = args.defaultFieldLoaders\n ? this._getDefaultFieldLoaders()\n : [];\n this._fieldLoaders.push(...args.customFieldLoaders);\n\n this._typedDataLoader =\n args.customTypedDataLoader ?? this._getDefaultTypedDataLoader();\n this._web3CheckLoader =\n args.customWeb3CheckLoader ?? this._getWeb3CheckLoader();\n this._solanaLoader = args.customSolanaLoader ?? this._getSolanaLoader();\n }\n\n private _getDefaultFieldLoaders(): ContextFieldLoader[] {\n return [\n this._container.get<ContextFieldLoader>(nftTypes.NftContextFieldLoader),\n this._container.get<ContextFieldLoader>(\n tokenTypes.TokenContextFieldLoader,\n ),\n this._container.get<ContextFieldLoader>(\n trustedNameTypes.TrustedNameContextFieldLoader,\n ),\n this._container.get<ContextFieldLoader>(\n proxyTypes.ProxyContextFieldLoader,\n ),\n ];\n }\n\n private _getDefaultLoaders(): ContextLoader<unknown>[] {\n return [\n this._container.get<ContextLoader>(\n externalPluginTypes.ExternalPluginContextLoader,\n ),\n this._container.get<ContextLoader>(\n trustedNameTypes.TrustedNameContextLoader,\n ),\n this._container.get<ContextLoader>(nftTypes.NftContextLoader),\n this._container.get<ContextLoader>(tokenTypes.TokenContextLoader),\n this._container.get<ContextLoader>(calldataTypes.CalldataContextLoader),\n this._container.get<ContextLoader>(\n dynamicNetworkTypes.DynamicNetworkContextLoader,\n ),\n this._container.get<ContextLoader>(safeTypes.SafeAddressLoader),\n ];\n }\n\n private _getDefaultTypedDataLoader(): TypedDataContextLoader {\n return this._container.get<TypedDataContextLoader>(\n typedDataTypes.TypedDataContextLoader,\n );\n }\n\n private _getWeb3CheckLoader(): Web3CheckContextLoader {\n return this._container.get<Web3CheckContextLoader>(\n web3CheckTypes.Web3CheckContextLoader,\n );\n }\n\n private _getSolanaLoader(): SolanaContextLoader {\n try {\n return this._container.get<SolanaContextLoader>(\n solanaContextTypes.SolanaContextLoader,\n );\n } catch {\n return {\n load: async (_ctx) =>\n Left(\n new Error(\n \"[ContextModule] - DefaultContextModule: no SolanaContextLoader bound\",\n ),\n ),\n };\n }\n }\n\n public async getContexts(\n input: unknown,\n expectedTypes?: ClearSignContextType[],\n ): Promise<ClearSignContext[]> {\n const allContextTypes = Object.values(ClearSignContextType);\n const loaders = this._loaders.filter((l) =>\n l.canHandle(input, expectedTypes ?? allContextTypes),\n );\n const promises = loaders.map((fetcher) => fetcher.load(input));\n const responses = await Promise.all(promises);\n return responses.flat();\n }\n\n public async getFieldContext<TInput>(\n field: TInput,\n expectedType: ClearSignContextType,\n ): Promise<ClearSignContext> {\n const loaders = this._fieldLoaders.filter((l) =>\n l.canHandle(field, expectedType),\n );\n if (loaders.length === 0) {\n return Promise.resolve({\n type: ClearSignContextType.ERROR,\n error: new Error(\n `Loader not found for field: ${field} and expected type: ${expectedType}`,\n ),\n });\n }\n\n for (const loader of loaders) {\n const context = await loader.loadField(field);\n if (context.type !== ClearSignContextType.ERROR) {\n return context;\n }\n }\n\n return {\n type: ClearSignContextType.ERROR,\n error: new Error(\n `Loader not found for field: ${field} and expected type: ${expectedType}`,\n ),\n };\n }\n\n public async getTypedDataFilters(\n typedData: TypedDataContext,\n ): Promise<TypedDataClearSignContext> {\n return this._typedDataLoader.load(typedData);\n }\n\n public async getWeb3Checks(\n transactionContext: Web3CheckContext,\n ): Promise<ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK> | null> {\n const web3Checks = await this._web3CheckLoader.load(transactionContext);\n\n return web3Checks.caseOf({\n Right: (checks: Web3Checks) => ({\n type: ClearSignContextType.WEB3_CHECK,\n payload: checks.descriptor,\n certificate: checks.certificate,\n }),\n Left: () => null,\n });\n }\n\n public async getSolanaContext(\n transactionContext: SolanaTransactionContext,\n ): Promise<SolanaTransactionContextResult> {\n return await this._solanaLoader.load(transactionContext);\n }\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,IAAA,eAAAC,EAAAH,GACA,IAAAI,EAAqB,qBAErBC,EAA8B,uCAC9BC,EAAoC,oDAGpCC,EAAiC,8CAGjCC,EAAoC,oDACpCC,EAAyB,6BACzBC,EAA2B,iCAC3BC,EAA0B,+BAG1BC,EAIO,2CAEPC,EAAmC,0CAGnCC,EAA2B,iCAC3BC,EAA+B,0CAE/BC,EAA+B,0CAO/BC,EAA8B,gBAEvB,MAAMf,CAA8C,CACjD,WACA,SACA,iBACA,iBACA,cACA,cAER,YAAYgB,EAA2B,CACrC,KAAK,cAAa,iBAAc,CAAE,OAAQA,CAAK,CAAC,EAEhD,KAAK,SAAWA,EAAK,eAAiB,KAAK,mBAAmB,EAAI,CAAC,EACnE,KAAK,SAAS,KAAK,GAAGA,EAAK,aAAa,EAExC,KAAK,cAAgBA,EAAK,oBACtB,KAAK,wBAAwB,EAC7B,CAAC,EACL,KAAK,cAAc,KAAK,GAAGA,EAAK,kBAAkB,EAElD,KAAK,iBACHA,EAAK,uBAAyB,KAAK,2BAA2B,EAChE,KAAK,iBACHA,EAAK,uBAAyB,KAAK,oBAAoB,EACzD,KAAK,cAAgBA,EAAK,oBAAsB,KAAK,iBAAiB,CACxE,CAEQ,yBAAgD,CACtD,MAAO,CACL,KAAK,WAAW,IAAwB,WAAS,qBAAqB,EACtE,KAAK,WAAW,IACd,aAAW,uBACb,EACA,KAAK,WAAW,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,MAAMD,EAAO,UAAUH,CAAK,EAC5C,GAAII,EAAQ,OAAS,uBAAqB,MACxC,OAAOA,CAEX,CAEA,MAAO,CACL,KAAM,uBAAqB,MAC3B,MAAO,IAAI,MACT,+BAA+BJ,CAAK,uBAAuBC,CAAY,EACzE,CACF,CACF,CAEA,MAAa,oBACXI,EACoC,CACpC,OAAO,KAAK,iBAAiB,KAAKA,CAAS,CAC7C,CAEA,MAAa,cACXC,EAC0E,CAG1E,OAFmB,MAAM,KAAK,iBAAiB,KAAKA,CAAkB,GAEpD,OAAO,CACvB,MAAQC,IAAwB,CAC9B,KAAM,uBAAqB,WAC3B,QAASA,EAAO,WAChB,YAAaA,EAAO,WACtB,GACA,KAAM,IAAM,IACd,CAAC,CACH,CAEA,MAAa,iBACXD,EACyC,CACzC,OAAO,MAAM,KAAK,cAAc,KAAKA,CAAkB,CACzD,CACF",
6
+ "names": ["DefaultContextModule_exports", "__export", "DefaultContextModule", "__toCommonJS", "import_purify_ts", "import_calldataTypes", "import_dynamicNetworkTypes", "import_trustedNameTypes", "import_externalPluginTypes", "import_nftTypes", "import_proxyTypes", "import_safeTypes", "import_ClearSignContext", "import_solanaContextTypes", "import_tokenTypes", "import_typedDataTypes", "import_web3CheckTypes", "import_di", "args", "_ctx", "input", "expectedTypes", "allContextTypes", "promises", "l", "fetcher", "field", "expectedType", "loaders", "loader", "context", "typedData", "transactionContext", "checks"]
7
7
  }
package/lib/cjs/src/di.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var a=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var A=(r,o)=>{for(var e in o)a(r,e,{get:o[e],enumerable:!0})},N=(r,o,e,m)=>{if(o&&typeof o=="object"||typeof o=="function")for(let t of x(o))!w.call(r,t)&&t!==e&&a(r,t,{get:()=>o[t],enumerable:!(m=g(o,t))||m.enumerable});return r};var P=r=>N(a({},"__esModule",{value:!0}),r);var h={};A(h,{makeContainer:()=>b});module.exports=P(h);var n=require("inversify"),i=require("./calldata/di/calldataModuleFactory"),c=require("./config/di/configModuleFactory"),l=require("./dynamic-network/di/dynamicNetworkModuleFactory"),p=require("./external-plugin/di/externalPluginModuleFactory"),d=require("./nft/di/nftModuleFactory"),f=require("./pki/di/pkiModuleFactory"),u=require("./proxy/di/proxyModuleFactory"),y=require("./solana/di/SolanaContextModuleFactory"),M=require("./token/di/tokenModuleFactory"),F=require("./trusted-name/di/trustedNameModuleFactory"),C=require("./typed-data/di/typedDataModuleFactory"),k=require("./uniswap/di/uniswapModuleFactory"),s=require("./web3-check/di/web3CheckModuleFactory");const b=({config:r})=>{const o=new n.Container;return o.loadSync((0,c.configModuleFactory)(r),(0,p.externalPluginModuleFactory)(),(0,l.dynamicNetworkModuleFactory)(),(0,d.nftModuleFactory)(),(0,u.proxyModuleFactory)(r),(0,M.tokenModuleFactory)(),(0,i.calldataModuleFactory)(),(0,F.trustedNameModuleFactory)(),(0,C.typedDataModuleFactory)(),(0,f.nanoPkiModuleFactory)(),(0,k.uniswapModuleFactory)(),(0,s.web3CheckModuleFactory)(),(0,y.solanaContextModuleFactory)()),o};0&&(module.exports={makeContainer});
1
+ "use strict";var a=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var N=(r,o)=>{for(var e in o)a(r,e,{get:o[e],enumerable:!0})},P=(r,o,e,m)=>{if(o&&typeof o=="object"||typeof o=="function")for(let t of w(o))!A.call(r,t)&&t!==e&&a(r,t,{get:()=>o[t],enumerable:!(m=x(o,t))||m.enumerable});return r};var b=r=>P(a({},"__esModule",{value:!0}),r);var D={};N(D,{makeContainer:()=>h});module.exports=b(D);var n=require("inversify"),i=require("./calldata/di/calldataModuleFactory"),c=require("./config/di/configModuleFactory"),l=require("./dynamic-network/di/dynamicNetworkModuleFactory"),p=require("./external-plugin/di/externalPluginModuleFactory"),d=require("./nft/di/nftModuleFactory"),f=require("./pki/di/pkiModuleFactory"),u=require("./proxy/di/proxyModuleFactory"),y=require("./safe/di/safeModuleFactory"),M=require("./solana/di/SolanaContextModuleFactory"),F=require("./token/di/tokenModuleFactory"),C=require("./trusted-name/di/trustedNameModuleFactory"),s=require("./typed-data/di/typedDataModuleFactory"),k=require("./uniswap/di/uniswapModuleFactory"),g=require("./web3-check/di/web3CheckModuleFactory");const h=({config:r})=>{const o=new n.Container;return o.loadSync((0,c.configModuleFactory)(r),(0,p.externalPluginModuleFactory)(),(0,l.dynamicNetworkModuleFactory)(),(0,d.nftModuleFactory)(),(0,u.proxyModuleFactory)(r),(0,y.safeModuleFactory)(),(0,F.tokenModuleFactory)(),(0,i.calldataModuleFactory)(),(0,C.trustedNameModuleFactory)(),(0,s.typedDataModuleFactory)(),(0,f.nanoPkiModuleFactory)(),(0,k.uniswapModuleFactory)(),(0,g.web3CheckModuleFactory)(),(0,M.solanaContextModuleFactory)()),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 { Container } from \"inversify\";\n\nimport { calldataModuleFactory } from \"@/calldata/di/calldataModuleFactory\";\nimport { configModuleFactory } from \"@/config/di/configModuleFactory\";\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 { solanaContextModuleFactory } from \"@/solana/di/SolanaContextModuleFactory\";\nimport { tokenModuleFactory } from \"@/token/di/tokenModuleFactory\";\nimport { trustedNameModuleFactory } from \"@/trusted-name/di/trustedNameModuleFactory\";\nimport { typedDataModuleFactory } from \"@/typed-data/di/typedDataModuleFactory\";\nimport { uniswapModuleFactory } from \"@/uniswap/di/uniswapModuleFactory\";\nimport { web3CheckModuleFactory } from \"@/web3-check/di/web3CheckModuleFactory\";\n\ntype MakeContainerArgs = {\n config: ContextModuleConfig;\n};\n\nexport const makeContainer = ({ config }: MakeContainerArgs) => {\n const container = new Container();\n\n container.loadSync(\n configModuleFactory(config),\n externalPluginModuleFactory(),\n dynamicNetworkModuleFactory(),\n nftModuleFactory(),\n proxyModuleFactory(config),\n tokenModuleFactory(),\n calldataModuleFactory(),\n trustedNameModuleFactory(),\n typedDataModuleFactory(),\n nanoPkiModuleFactory(),\n uniswapModuleFactory(),\n web3CheckModuleFactory(),\n solanaContextModuleFactory(),\n );\n\n return container;\n};\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAA0B,qBAE1BC,EAAsC,+CACtCC,EAAoC,2CAEpCC,EAA4C,4DAC5CC,EAA4C,4DAC5CC,EAAiC,qCACjCC,EAAqC,qCACrCC,EAAmC,yCACnCC,EAA2C,kDAC3CC,EAAmC,yCACnCC,EAAyC,sDACzCC,EAAuC,kDACvCC,EAAqC,6CACrCC,EAAuC,kDAMhC,MAAMf,EAAgB,CAAC,CAAE,OAAAgB,CAAO,IAAyB,CAC9D,MAAMC,EAAY,IAAI,YAEtB,OAAAA,EAAU,YACR,uBAAoBD,CAAM,KAC1B,+BAA4B,KAC5B,+BAA4B,KAC5B,oBAAiB,KACjB,sBAAmBA,CAAM,KACzB,sBAAmB,KACnB,yBAAsB,KACtB,4BAAyB,KACzB,0BAAuB,KACvB,wBAAqB,KACrB,wBAAqB,KACrB,0BAAuB,KACvB,8BAA2B,CAC7B,EAEOC,CACT",
6
- "names": ["di_exports", "__export", "makeContainer", "__toCommonJS", "import_inversify", "import_calldataModuleFactory", "import_configModuleFactory", "import_dynamicNetworkModuleFactory", "import_externalPluginModuleFactory", "import_nftModuleFactory", "import_pkiModuleFactory", "import_proxyModuleFactory", "import_SolanaContextModuleFactory", "import_tokenModuleFactory", "import_trustedNameModuleFactory", "import_typedDataModuleFactory", "import_uniswapModuleFactory", "import_web3CheckModuleFactory", "config", "container"]
4
+ "sourcesContent": ["import { Container } from \"inversify\";\n\nimport { calldataModuleFactory } from \"@/calldata/di/calldataModuleFactory\";\nimport { configModuleFactory } from \"@/config/di/configModuleFactory\";\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 { tokenModuleFactory } from \"@/token/di/tokenModuleFactory\";\nimport { trustedNameModuleFactory } from \"@/trusted-name/di/trustedNameModuleFactory\";\nimport { typedDataModuleFactory } from \"@/typed-data/di/typedDataModuleFactory\";\nimport { uniswapModuleFactory } from \"@/uniswap/di/uniswapModuleFactory\";\nimport { web3CheckModuleFactory } from \"@/web3-check/di/web3CheckModuleFactory\";\n\ntype MakeContainerArgs = {\n config: ContextModuleConfig;\n};\n\nexport const makeContainer = ({ config }: MakeContainerArgs) => {\n const container = new Container();\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 web3CheckModuleFactory(),\n solanaContextModuleFactory(),\n );\n\n return container;\n};\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAA0B,qBAE1BC,EAAsC,+CACtCC,EAAoC,2CAEpCC,EAA4C,4DAC5CC,EAA4C,4DAC5CC,EAAiC,qCACjCC,EAAqC,qCACrCC,EAAmC,yCACnCC,EAAkC,uCAClCC,EAA2C,kDAC3CC,EAAmC,yCACnCC,EAAyC,sDACzCC,EAAuC,kDACvCC,EAAqC,6CACrCC,EAAuC,kDAMhC,MAAMhB,EAAgB,CAAC,CAAE,OAAAiB,CAAO,IAAyB,CAC9D,MAAMC,EAAY,IAAI,YAEtB,OAAAA,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,0BAAuB,KACvB,8BAA2B,CAC7B,EAEOC,CACT",
6
+ "names": ["di_exports", "__export", "makeContainer", "__toCommonJS", "import_inversify", "import_calldataModuleFactory", "import_configModuleFactory", "import_dynamicNetworkModuleFactory", "import_externalPluginModuleFactory", "import_nftModuleFactory", "import_pkiModuleFactory", "import_proxyModuleFactory", "import_safeModuleFactory", "import_SolanaContextModuleFactory", "import_tokenModuleFactory", "import_trustedNameModuleFactory", "import_typedDataModuleFactory", "import_uniswapModuleFactory", "import_web3CheckModuleFactory", "config", "container"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var p=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var b=(n,e)=>{for(var r in e)p(n,r,{get:e[r],enumerable:!0})},L=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of k(e))!_.call(n,a)&&a!==r&&p(n,a,{get:()=>e[a],enumerable:!(t=h(e,a))||t.enumerable});return n};var O=n=>L(p({},"__esModule",{value:!0}),n),y=(n,e,r,t)=>{for(var a=t>1?void 0:t?h(e,r):e,s=n.length-1,c;s>=0;s--)(c=n[s])&&(a=(t?c(e,r,a):c(a))||a);return t&&a&&p(e,r,a),a},D=(n,e)=>(r,t)=>e(r,t,n);var v={};b(v,{ExternalPluginContextLoader:()=>x});module.exports=O(v);var g=require("@ledgerhq/device-management-kit"),E=require("ethers"),u=require("inversify"),i=require("purify-ts"),P=require("../../external-plugin/di/externalPluginTypes"),o=require("../../shared/model/ClearSignContext"),I=require("../../token/di/tokenTypes");const w=[o.ClearSignContextType.EXTERNAL_PLUGIN,o.ClearSignContextType.TOKEN];let x=class{_externalPluginDataSource;_tokenDataSource;constructor(e,r){this._externalPluginDataSource=e,this._tokenDataSource=r}canHandle(e,r){return typeof e=="object"&&e!==null&&"to"in e&&"data"in e&&"selector"in e&&"chainId"in e&&typeof e.chainId=="number"&&(0,g.isHexaString)(e.to)&&e.to!=="0x"&&(0,g.isHexaString)(e.data)&&e.data!=="0x"&&(0,g.isHexaString)(e.selector)&&e.selector!=="0x"&&w.every(t=>r.includes(t))}async load(e){const{to:r,data:t,selector:a,chainId:s}=e,c=await this._externalPluginDataSource.getDappInfos({address:r,chainId:s,selector:a});return(0,i.EitherAsync)(async({liftEither:d})=>{const l=await d(c);if(!l)return[];const f={type:o.ClearSignContextType.EXTERNAL_PLUGIN,payload:l.selectorDetails.serializedData.concat(l.selectorDetails.signature)},S=this.getDecodedCallData(l.abi,l.selectorDetails.method,t);if(S.isLeft())return[{type:o.ClearSignContextType.ERROR,error:S.extract()},f];const R=S.extract(),T=l.selectorDetails.erc20OfInterest.map(async C=>this.getTokenPayload(e,C,R));return[...(await Promise.all(T)).map(C=>C.caseOf({Left:m=>({type:o.ClearSignContextType.ERROR,error:m}),Right:m=>({type:o.ClearSignContextType.TOKEN,payload:m})})),f]}).caseOf({Left:d=>[{type:o.ClearSignContextType.ERROR,error:d}],Right:d=>d})}getTokenPayload(e,r,t){const a=this.getAddressFromPath(r,t);return(0,i.EitherAsync)(({fromPromise:s})=>s(this._tokenDataSource.getTokenInfosPayload({address:a,chainId:e.chainId})))}getDecodedCallData(e,r,t){try{const a=new E.Interface(e);return(0,i.Right)(a.decodeFunctionData(r,t))}catch{return(0,i.Left)(new Error("[ContextModule] ExternalPluginContextLoader: Unable to parse abi"))}}getAddressFromPath(e,r){let t=r;for(const a of e.split("."))a==="-1"?t=t[t.length-1]:t=t[a];if(!(0,g.isHexaString)(t))throw new Error("[ContextModule] ExternalPluginContextLoader: Unable to get address");return t}};x=y([(0,u.injectable)(),D(0,(0,u.inject)(P.externalPluginTypes.ExternalPluginDataSource)),D(1,(0,u.inject)(I.tokenTypes.TokenDataSource))],x);0&&(module.exports={ExternalPluginContextLoader});
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});
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\";\n\nexport type ExternalPluginContextInput = {\n to: HexaString;\n data: HexaString;\n selector: HexaString;\n chainId: number;\n};\n\nconst SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.EXTERNAL_PLUGIN,\n ClearSignContextType.TOKEN,\n];\n\n@injectable()\nexport class ExternalPluginContextLoader\n implements ContextLoader<ExternalPluginContextInput>\n{\n private _externalPluginDataSource: ExternalPluginDataSource;\n private _tokenDataSource: TokenDataSource;\n\n constructor(\n @inject(externalPluginTypes.ExternalPluginDataSource)\n externalPluginDataSource: ExternalPluginDataSource,\n @inject(tokenTypes.TokenDataSource) tokenDataSource: TokenDataSource,\n ) {\n this._externalPluginDataSource = externalPluginDataSource;\n this._tokenDataSource = tokenDataSource;\n }\n\n canHandle(\n input: unknown,\n expectedTypes: ClearSignContextType[],\n ): input is ExternalPluginContextInput {\n return (\n typeof input === \"object\" &&\n input !== null &&\n \"to\" in input &&\n \"data\" in input &&\n \"selector\" in input &&\n \"chainId\" in input &&\n typeof input.chainId === \"number\" &&\n isHexaString(input.to) &&\n input.to !== \"0x\" &&\n isHexaString(input.data) &&\n input.data !== \"0x\" && // non empty data\n isHexaString(input.selector) &&\n input.selector !== \"0x\" &&\n SUPPORTED_TYPES.every((type) => expectedTypes.includes(type))\n );\n }\n\n async load(input: ExternalPluginContextInput): Promise<ClearSignContext[]> {\n const { to, data, selector, chainId } = input;\n\n const eitherDappInfos = await this._externalPluginDataSource.getDappInfos({\n address: to,\n chainId,\n selector,\n });\n\n return EitherAsync<Error, ClearSignContext[]>(async ({ liftEither }) => {\n const dappInfos = await liftEither(eitherDappInfos);\n\n // if the dappInfos is null, return an empty array\n // this means that the selector is not a known selector\n if (!dappInfos) {\n return [];\n }\n\n const externalPluginContext: ClearSignContext = {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: dappInfos.selectorDetails.serializedData.concat(\n dappInfos.selectorDetails.signature,\n ),\n };\n\n const decodedCallData = this.getDecodedCallData(\n dappInfos.abi,\n dappInfos.selectorDetails.method,\n data,\n );\n\n // if the call data cannot be decoded, return the error\n // but also the externalPluginContext because it is still valid\n if (decodedCallData.isLeft()) {\n return [\n {\n type: ClearSignContextType.ERROR,\n error: decodedCallData.extract(),\n },\n externalPluginContext,\n ];\n }\n\n // decodedCallData is a Right so we can extract it safely\n const extractedDecodedCallData =\n decodedCallData.extract() as ethers.Result;\n\n // get the token payload for each erc20OfInterest\n // and return the payload or the error\n const promises = dappInfos.selectorDetails.erc20OfInterest.map(\n async (erc20Path) =>\n this.getTokenPayload(input, erc20Path, extractedDecodedCallData),\n );\n\n const tokensPayload = await Promise.all(promises);\n\n // map the payload or the error to a ClearSignContext\n const contexts: ClearSignContext[] = tokensPayload.map((eitherToken) =>\n eitherToken.caseOf<ClearSignContext>({\n Left: (error) => ({ type: ClearSignContextType.ERROR, error }),\n Right: (payload) => ({ type: ClearSignContextType.TOKEN, payload }),\n }),\n );\n\n return [...contexts, externalPluginContext];\n }).caseOf<ClearSignContext[]>({\n // parse all errors into ClearSignContext\n Left: (error) => [{ type: ClearSignContextType.ERROR, error }],\n Right: (contexts) => contexts,\n });\n }\n\n private getTokenPayload(\n input: ExternalPluginContextInput,\n erc20Path: string,\n decodedCallData: ethers.Result,\n ) {\n const address = this.getAddressFromPath(erc20Path, decodedCallData);\n\n return EitherAsync<Error, string>(({ fromPromise }) =>\n fromPromise(\n this._tokenDataSource.getTokenInfosPayload({\n address,\n chainId: input.chainId,\n }),\n ),\n );\n }\n\n private getDecodedCallData(\n abi: object[],\n method: string,\n data: string,\n ): Either<Error, ethers.Result> {\n try {\n const contractInterface = new Interface(abi);\n return Right(contractInterface.decodeFunctionData(method, data));\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] ExternalPluginContextLoader: Unable to parse abi\",\n ),\n );\n }\n }\n\n private getAddressFromPath(\n path: string,\n decodedCallData: ethers.Result,\n ): HexaString {\n // ethers.Result is a record string, any\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let value: any = decodedCallData;\n for (const key of path.split(\".\")) {\n // In Solidity, a struct cannot begin with a number\n // Additionally, when we use -1, it signifies the last element of the array.\n if (key === \"-1\") {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n value = value[value.length - 1];\n } else {\n // This access can throw a RangeError error in case of an invalid key\n // but is correctly caught by the liftEither above\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n value = value[key];\n }\n }\n\n if (!isHexaString(value)) {\n throw new Error(\n \"[ContextModule] ExternalPluginContextLoader: Unable to get address\",\n );\n }\n\n return value;\n }\n}\n"],
5
-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EACF,EAGF,OAAOA,CACT,CACF,EA5Ka5B,EAAN8B,EAAA,IADN,cAAW,EAQPC,EAAA,eAAO,sBAAoB,wBAAwB,GAEnDA,EAAA,eAAO,aAAW,eAAe,IATzB/B",
6
- "names": ["ExternalPluginContextLoader_exports", "__export", "ExternalPluginContextLoader", "__toCommonJS", "import_device_management_kit", "import_ethers", "import_inversify", "import_purify_ts", "import_externalPluginTypes", "import_ClearSignContext", "import_tokenTypes", "SUPPORTED_TYPES", "ExternalPluginContextLoader", "externalPluginDataSource", "tokenDataSource", "input", "expectedTypes", "type", "to", "data", "selector", "chainId", "eitherDappInfos", "liftEither", "dappInfos", "externalPluginContext", "decodedCallData", "extractedDecodedCallData", "promises", "erc20Path", "eitherToken", "error", "payload", "contexts", "address", "fromPromise", "abi", "method", "contractInterface", "path", "value", "key", "__decorateClass", "__decorateParam"]
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,C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AE,OAA2B,CAE5B,KAAOQ,GAAU,CAAC,CAAE,KAAM,uBAAqB,MAAO,MAAAA,CAAM,CAAC,EAC7D,MAAQE,GAAaA,CACvB,CAAC,CACH,CAEQ,gBACNpB,EACAgB,EACAH,EACA,CACA,MAAMQ,EAAU,KAAK,mBAAmBL,EAAWH,CAAe,EAElE,SAAO,eAA2B,CAAC,CAAE,YAAAS,CAAY,IAC/CA,EACE,KAAK,iBAAiB,qBAAqB,CACzC,QAAAD,EACA,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"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var m=Object.create;var i=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var D=(c,n,o,e)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of y(n))!b.call(c,t)&&t!==o&&i(c,t,{get:()=>n[t],enumerable:!(e=f(n,t))||e.enumerable});return c};var I=(c,n,o)=>(o=c!=null?m(x(c)):{},D(n||!c||!c.__esModule?i(o,"default",{value:c,enumerable:!0}):o,c));var u=require("ethers"),l=require("purify-ts"),s=I(require("@/external-plugin/__tests__/abi.json")),E=require("../../external-plugin/domain/ExternalPluginContextLoader"),a=require("../../shared/model/ClearSignContext");const p=({abi:c,selectorDetails:n})=>({abi:c,selectorDetails:{erc20OfInterest:[],method:"",plugin:"",serializedData:"123456",signature:"7890",...n}}),d=(c,n,o)=>{const t=new u.Interface(JSON.stringify(c)).encodeFunctionData(n,o);return{to:"0x0",data:t,selector:t.slice(0,10),chainId:1}};describe("ExternalPluginContextLoader",()=>{const c={getTokenInfosPayload:vi.fn()},n={getDappInfos:vi.fn()},o=new E.ExternalPluginContextLoader(n,c);beforeEach(()=>{vi.clearAllMocks(),vi.spyOn(c,"getTokenInfosPayload").mockImplementation(({address:e})=>Promise.resolve((0,l.Right)(`payload-${e}`)))}),describe("canHandle function",()=>{const e={to:"0x1234567890123456789012345678901234567890",data:"0x095ea7b30000000000000000000000001234567890123456789012345678901234567890",selector:"0x095ea7b3",chainId:1};it("should return true for valid input",()=>{expect(o.canHandle(e,[a.ClearSignContextType.EXTERNAL_PLUGIN,a.ClearSignContextType.TOKEN])).toBe(!0)}),it("should return false for invalid expected type",()=>{expect(o.canHandle(e,[a.ClearSignContextType.NFT])).toBe(!1),expect(o.canHandle(e,[a.ClearSignContextType.TOKEN])).toBe(!1),expect(o.canHandle(e,[a.ClearSignContextType.EXTERNAL_PLUGIN])).toBe(!1)}),it.each([[null,"null input"],[void 0,"undefined input"],[{},"empty object"],["string","string input"],[123,"number input"]])("should return false for %s",(t,r)=>{expect(o.canHandle(t,[a.ClearSignContextType.EXTERNAL_PLUGIN,a.ClearSignContextType.TOKEN])).toBe(!1)}),it.each([[{...e,to:void 0},"missing to"],[{...e,data:void 0},"missing data"],[{...e,selector:void 0},"missing selector"],[{...e,chainId:void 0},"missing chainId"]])("should return false for %s",(t,r)=>{expect(o.canHandle(t,[a.ClearSignContextType.EXTERNAL_PLUGIN,a.ClearSignContextType.TOKEN])).toBe(!1)}),it.each([[{...e,to:"invalid-hex"},"invalid to hex"],[{...e,to:"0x"},"empty to hex"],[{...e,data:"invalid-hex"},"invalid data hex"],[{...e,data:"0x"},"empty data (0x)"],[{...e,selector:"invalid-hex"},"invalid selector hex"],[{...e,selector:"0x"},"empty selector hex"]])("should return false for %s",(t,r)=>{expect(o.canHandle(t,[a.ClearSignContextType.EXTERNAL_PLUGIN,a.ClearSignContextType.TOKEN])).toBe(!1)}),it.each([[{...e,chainId:"1"},"string chainId"],[{...e,chainId:null},"null chainId"],[{...e,chainId:void 0},"undefined chainId"]])("should return false for %s",(t,r)=>{expect(o.canHandle(t,[a.ClearSignContextType.EXTERNAL_PLUGIN,a.ClearSignContextType.TOKEN])).toBe(!1)})}),describe("load function",()=>{it("should return an empty array if no dapp info is provided",async()=>{const e=d(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Right)(void 0));const t=await o.load(e);expect(t).toEqual([])}),it("should return e plugin if no erc20OfInterest is provided",async()=>{const e=p({abi:s.default,selectorDetails:{erc20OfInterest:[],method:"singleParam"}}),t=d(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Right)(e));const r=await o.load(t);expect(r).toEqual([{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return a list of context responses when one erc20OfInterest is provided for a single parameter",async()=>{const e=p({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),t=d(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Right)(e));const r=await o.load(t);expect(r).toEqual(expect.arrayContaining([{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"}]))}),it("should return a context response with only set external plugin when one erc20OfInterest is provided for a single parameter but no payload is feched",async()=>{const e=p({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),t=d(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Right)(e)),vi.spyOn(c,"getTokenInfosPayload").mockResolvedValue((0,l.Left)(Error("error")));const r=await o.load(t);expect(r).toEqual([{type:a.ClearSignContextType.ERROR,error:new Error("error")},{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return a list of context responses when two erc20OfInterest are provided for two parameters",async()=>{const e=p({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken","toToken"],method:"multipleParams"}}),t=d(s.default,"multipleParams",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7"]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Right)(e));const r=await o.load(t);expect(r).toEqual(expect.arrayContaining([{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"}]))}),it("should return a list of context responses when one erc20OfInterest is an array",async()=>{const e=p({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken.0","fromToken.1","fromToken.2","fromToken.-1"],method:"arrayParam"}}),t=d(s.default,"arrayParam",[["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7","0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Right)(e));const r=await o.load(t);expect(r).toEqual([{type:a.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return an error when a token datasource returns an error",async()=>{const e=p({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),t=d(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Right)(e)),vi.spyOn(c,"getTokenInfosPayload").mockResolvedValue((0,l.Left)(new Error("error")));const r=await o.load(t);expect(r).toEqual([{type:a.ClearSignContextType.ERROR,error:new Error("error")},{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return an error when the abi is not conform",async()=>{const e=p({abi:[{fakeabi:"notworking"}],selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),t=d(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Right)(e));const r=await o.load(t);expect(r).toEqual([{type:a.ClearSignContextType.ERROR,error:new Error("[ContextModule] ExternalPluginContextLoader: Unable to parse abi")},{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should throw an error when the erc20OfInterest doest not exist in the transaction",async()=>{const e=p({abi:s.default,selectorDetails:{erc20OfInterest:["notFound"],method:"singleParam"}}),t=d(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Right)(e));const r=await o.load(t);expect(r).toEqual([{type:a.ClearSignContextType.ERROR,error:new Error("[ContextModule] ExternalPluginContextLoader: Unable to get address")}])}),it("should throw an error when an out-of-bounds element is present in erc20OfInterest",async()=>{const e=p({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken.3"],method:"arrayParam"}}),t=d(s.default,"arrayParam",[["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7","0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Right)(e));const r=await o.load(t);expect(r).toEqual([{type:a.ClearSignContextType.ERROR,error:new RangeError("out of result range")}])}),it("should return a list of context responses when one erc20OfInterest is a complex struct",async()=>{const e=p({abi:s.default,selectorDetails:{erc20OfInterest:["complexStruct.address1","complexStruct.param1.param2.0.param3.addresses.0","complexStruct.param1.param2.0.param3.addresses.1","complexStruct.param1.param2.0.param3.addresses.-1","complexStruct.param1.param2.1.param3.addresses.0","complexStruct.param1.param2.-1.param3.addresses.0"],method:"complexStructParam"}}),t=d(s.default,"complexStructParam",[{address1:"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",param1:{param2:[{param3:{addresses:["0xdAC17F958D2ee523a2206206994597C13D831ec7","0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"]}},{param3:{addresses:["0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]}}]}}]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Right)(e));const r=await o.load(t);expect(r).toEqual([{type:a.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return an error when datasource return a Left",async()=>{const e=d(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Left)(new Error("error")));const t=await o.load(e);expect(t).toEqual([{type:a.ClearSignContextType.ERROR,error:new Error("error")}])})})});
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")}])})})});
2
2
  //# sourceMappingURL=ExternalPluginContextLoader.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/external-plugin/domain/ExternalPluginContextLoader.test.ts"],
4
- "sourcesContent": ["import { Interface } from \"ethers\";\nimport { Left, Right } from \"purify-ts\";\n\nimport ABI from \"@/external-plugin/__tests__/abi.json\";\nimport { type ExternalPluginDataSource } from \"@/external-plugin/data/ExternalPluginDataSource\";\nimport {\n type ExternalPluginContextInput,\n ExternalPluginContextLoader,\n} from \"@/external-plugin/domain/ExternalPluginContextLoader\";\nimport { type DappInfos } from \"@/external-plugin/model/DappInfos\";\nimport { type SelectorDetails } from \"@/external-plugin/model/SelectorDetails\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport { type TokenDataSource } from \"@/token/data/TokenDataSource\";\n\nconst dappInfosBuilder = ({\n abi,\n selectorDetails,\n}: {\n abi?: object[];\n selectorDetails?: Partial<SelectorDetails>;\n}) => {\n return {\n abi: abi,\n selectorDetails: {\n erc20OfInterest: [],\n method: \"\",\n plugin: \"\",\n serializedData: \"123456\",\n signature: \"7890\",\n ...selectorDetails,\n },\n } as DappInfos;\n};\n\nconst inputBuilder = (\n abi: object,\n functionName: string,\n params: unknown[],\n): ExternalPluginContextInput => {\n const contract = new Interface(JSON.stringify(abi));\n const data = contract.encodeFunctionData(functionName, params);\n return {\n to: \"0x0\",\n data: data as `0x${string}`,\n selector: data.slice(0, 10) as `0x${string}`,\n chainId: 1,\n };\n};\n\ndescribe(\"ExternalPluginContextLoader\", () => {\n const mockTokenDataSource: TokenDataSource = {\n getTokenInfosPayload: vi.fn(),\n };\n const mockExternalPluginDataSource: ExternalPluginDataSource = {\n getDappInfos: vi.fn(),\n };\n const loader = new ExternalPluginContextLoader(\n mockExternalPluginDataSource,\n mockTokenDataSource,\n );\n\n beforeEach(() => {\n vi.clearAllMocks();\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockImplementation(\n ({ address }) => Promise.resolve(Right(`payload-${address}`)),\n );\n });\n\n describe(\"canHandle function\", () => {\n const validInput: ExternalPluginContextInput = {\n to: \"0x1234567890123456789012345678901234567890\",\n data: \"0x095ea7b30000000000000000000000001234567890123456789012345678901234567890\",\n selector: \"0x095ea7b3\",\n chainId: 1,\n };\n\n it(\"should return true for valid input\", () => {\n expect(\n loader.canHandle(validInput, [\n ClearSignContextType.EXTERNAL_PLUGIN,\n ClearSignContextType.TOKEN,\n ]),\n ).toBe(true);\n });\n\n it(\"should return false for invalid expected type\", () => {\n expect(loader.canHandle(validInput, [ClearSignContextType.NFT])).toBe(\n false,\n );\n expect(loader.canHandle(validInput, [ClearSignContextType.TOKEN])).toBe(\n false,\n );\n expect(\n loader.canHandle(validInput, [ClearSignContextType.EXTERNAL_PLUGIN]),\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.EXTERNAL_PLUGIN,\n ClearSignContextType.TOKEN,\n ]),\n ).toBe(false);\n });\n\n it.each([\n [{ ...validInput, to: undefined }, \"missing to\"],\n [{ ...validInput, data: undefined }, \"missing data\"],\n [{ ...validInput, selector: undefined }, \"missing selector\"],\n [{ ...validInput, chainId: undefined }, \"missing chainId\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(\n loader.canHandle(input, [\n ClearSignContextType.EXTERNAL_PLUGIN,\n ClearSignContextType.TOKEN,\n ]),\n ).toBe(false);\n });\n\n it.each([\n [{ ...validInput, to: \"invalid-hex\" }, \"invalid to hex\"],\n [{ ...validInput, to: \"0x\" }, \"empty to hex\"],\n [{ ...validInput, data: \"invalid-hex\" }, \"invalid data hex\"],\n [{ ...validInput, data: \"0x\" }, \"empty data (0x)\"],\n [{ ...validInput, selector: \"invalid-hex\" }, \"invalid selector hex\"],\n [{ ...validInput, selector: \"0x\" }, \"empty selector hex\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(\n loader.canHandle(input, [\n ClearSignContextType.EXTERNAL_PLUGIN,\n ClearSignContextType.TOKEN,\n ]),\n ).toBe(false);\n });\n\n it.each([\n [{ ...validInput, chainId: \"1\" }, \"string chainId\"],\n [{ ...validInput, chainId: null }, \"null chainId\"],\n [{ ...validInput, chainId: undefined }, \"undefined chainId\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(\n loader.canHandle(input, [\n ClearSignContextType.EXTERNAL_PLUGIN,\n ClearSignContextType.TOKEN,\n ]),\n ).toBe(false);\n });\n });\n\n describe(\"load function\", () => {\n it(\"should return an empty array if no dapp info is provided\", async () => {\n // GIVEN\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(undefined),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return e plugin if no erc20OfInterest is provided\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [],\n method: \"singleParam\",\n },\n });\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return a list of context responses when one erc20OfInterest is provided for a single parameter\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken\"],\n method: \"singleParam\",\n },\n });\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual(\n expect.arrayContaining([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n },\n ]),\n );\n });\n\n 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 () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken\"],\n method: \"singleParam\",\n },\n });\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(Error(\"error\")),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return a list of context responses when two erc20OfInterest are provided for two parameters\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken\", \"toToken\"],\n method: \"multipleParams\",\n },\n });\n const input = inputBuilder(ABI, \"multipleParams\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual(\n expect.arrayContaining([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n },\n ]),\n );\n });\n\n it(\"should return a list of context responses when one erc20OfInterest is an array\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\n \"fromToken.0\",\n \"fromToken.1\",\n \"fromToken.2\",\n \"fromToken.-1\",\n ],\n method: \"arrayParam\",\n },\n });\n const input = inputBuilder(ABI, \"arrayParam\", [\n [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n \"0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n ],\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n },\n // fromToken.2\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n // fromToken.-1\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return an error when a token datasource returns an error\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken\"],\n method: \"singleParam\",\n },\n });\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(new Error(\"error\")),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return an error when the abi is not conform\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: [{ fakeabi: \"notworking\" }],\n selectorDetails: {\n erc20OfInterest: [\"fromToken\"],\n method: \"singleParam\",\n },\n });\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\n \"[ContextModule] ExternalPluginContextLoader: Unable to parse abi\",\n ),\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should throw an error when the erc20OfInterest doest not exist in the transaction\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"notFound\"],\n method: \"singleParam\",\n },\n });\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\n \"[ContextModule] ExternalPluginContextLoader: Unable to get address\",\n ),\n },\n ]);\n });\n\n it(\"should throw an error when an out-of-bounds element is present in erc20OfInterest\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken.3\"],\n method: \"arrayParam\",\n },\n });\n const input = inputBuilder(ABI, \"arrayParam\", [\n [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n \"0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n ],\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new RangeError(\"out of result range\"),\n },\n ]);\n });\n\n it(\"should return a list of context responses when one erc20OfInterest is a complex struct\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\n \"complexStruct.address1\",\n \"complexStruct.param1.param2.0.param3.addresses.0\",\n \"complexStruct.param1.param2.0.param3.addresses.1\",\n \"complexStruct.param1.param2.0.param3.addresses.-1\",\n \"complexStruct.param1.param2.1.param3.addresses.0\",\n \"complexStruct.param1.param2.-1.param3.addresses.0\",\n ],\n method: \"complexStructParam\",\n },\n });\n const input = inputBuilder(ABI, \"complexStructParam\", [\n {\n address1: \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n param1: {\n param2: [\n {\n param3: {\n addresses: [\n \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n \"0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE\",\n ],\n },\n },\n {\n param3: {\n addresses: [\"0xB8c77482e45F1F44dE1745F52C74426C631bDD52\"],\n },\n },\n ],\n },\n },\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return an error when datasource return a Left\", async () => {\n // GIVEN\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Left(new Error(\"error\")),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n ]);\n });\n });\n});\n"],
5
- "mappings": "wdAAA,IAAAA,EAA0B,kBAC1BC,EAA4B,qBAE5BC,EAAgB,mDAEhBC,EAGO,gEAGPC,EAAqC,2CAGrC,MAAMC,EAAmB,CAAC,CACxB,IAAAC,EACA,gBAAAC,CACF,KAIS,CACL,IAAKD,EACL,gBAAiB,CACf,gBAAiB,CAAC,EAClB,OAAQ,GACR,OAAQ,GACR,eAAgB,SAChB,UAAW,OACX,GAAGC,CACL,CACF,GAGIC,EAAe,CACnBF,EACAG,EACAC,IAC+B,CAE/B,MAAMC,EADW,IAAI,YAAU,KAAK,UAAUL,CAAG,CAAC,EAC5B,mBAAmBG,EAAcC,CAAM,EAC7D,MAAO,CACL,GAAI,MACJ,KAAMC,EACN,SAAUA,EAAK,MAAM,EAAG,EAAE,EAC1B,QAAS,CACX,CACF,EAEA,SAAS,8BAA+B,IAAM,CAC5C,MAAMC,EAAuC,CAC3C,qBAAsB,GAAG,GAAG,CAC9B,EACMC,EAAyD,CAC7D,aAAc,GAAG,GAAG,CACtB,EACMC,EAAS,IAAI,8BACjBD,EACAD,CACF,EAEA,WAAW,IAAM,CACf,GAAG,cAAc,EACjB,GAAG,MAAMA,EAAqB,sBAAsB,EAAE,mBACpD,CAAC,CAAE,QAAAG,CAAQ,IAAM,QAAQ,WAAQ,SAAM,WAAWA,CAAO,EAAE,CAAC,CAC9D,CACF,CAAC,EAED,SAAS,qBAAsB,IAAM,CACnC,MAAMC,EAAyC,CAC7C,GAAI,6CACJ,KAAM,6EACN,SAAU,aACV,QAAS,CACX,EAEA,GAAG,qCAAsC,IAAM,CAC7C,OACEF,EAAO,UAAUE,EAAY,CAC3B,uBAAqB,gBACrB,uBAAqB,KACvB,CAAC,CACH,EAAE,KAAK,EAAI,CACb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B,QAAS,oDACX,EACA,CACE,KAAM,uBAAqB,MAC3B,QAAS,oDACX,EACA,CACE,KAAM,uBAAqB,gBAC3B,QAAS,YACX,CACF,CAAC,CACH,CAAC,EAED,GAAG,uDAAwD,SAAY,CAErE,MAAMH,EAAQT,EAAa,EAAAW,QAAK,cAAe,CAC7C,4CACF,CAAC,EACD,GAAG,MAAMN,EAA8B,cAAc,EAAE,qBACrD,QAAK,IAAI,MAAM,OAAO,CAAC,CACzB,EAGA,MAAMO,EAAS,MAAMN,EAAO,KAAKG,CAAK,EAGtC,OAAOG,CAAM,EAAE,QAAQ,CACrB,CACE,KAAM,uBAAqB,MAC3B,MAAO,IAAI,MAAM,OAAO,CAC1B,CACF,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["import_ethers", "import_purify_ts", "import_abi", "import_ExternalPluginContextLoader", "import_ClearSignContext", "dappInfosBuilder", "abi", "selectorDetails", "inputBuilder", "functionName", "params", "data", "mockTokenDataSource", "mockExternalPluginDataSource", "loader", "address", "validInput", "input", "_description", "ABI", "result", "dappInfos"]
4
+ "sourcesContent": ["import { Interface } from \"ethers\";\nimport { Left, Right } from \"purify-ts\";\n\nimport ABI from \"@/external-plugin/__tests__/abi.json\";\nimport { type ExternalPluginDataSource } from \"@/external-plugin/data/ExternalPluginDataSource\";\nimport {\n type ExternalPluginContextInput,\n ExternalPluginContextLoader,\n} from \"@/external-plugin/domain/ExternalPluginContextLoader\";\nimport { type DappInfos } from \"@/external-plugin/model/DappInfos\";\nimport { type SelectorDetails } from \"@/external-plugin/model/SelectorDetails\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport { type TokenDataSource } from \"@/token/data/TokenDataSource\";\nimport { type UniswapContextLoader } from \"@/uniswap/domain/UniswapContextLoader\";\n\nconst dappInfosBuilder = ({\n abi,\n selectorDetails,\n}: {\n abi?: object[];\n selectorDetails?: Partial<SelectorDetails>;\n}) => {\n return {\n abi: abi,\n selectorDetails: {\n erc20OfInterest: [],\n method: \"\",\n plugin: \"\",\n serializedData: \"123456\",\n signature: \"7890\",\n ...selectorDetails,\n },\n } as DappInfos;\n};\n\nconst inputBuilder = (\n abi: object,\n functionName: string,\n params: unknown[],\n): ExternalPluginContextInput => {\n const contract = new Interface(JSON.stringify(abi));\n const data = contract.encodeFunctionData(functionName, params);\n return {\n to: \"0x0\",\n data: data as `0x${string}`,\n selector: data.slice(0, 10) as `0x${string}`,\n chainId: 1,\n };\n};\n\ndescribe(\"ExternalPluginContextLoader\", () => {\n const mockTokenDataSource: TokenDataSource = {\n getTokenInfosPayload: vi.fn(),\n };\n const mockExternalPluginDataSource: ExternalPluginDataSource = {\n getDappInfos: vi.fn(),\n };\n const mockUniswapLoader: UniswapContextLoader = {\n canHandle: vi.fn(),\n load: vi.fn(),\n } as unknown as UniswapContextLoader;\n const loader = new ExternalPluginContextLoader(\n mockExternalPluginDataSource,\n mockTokenDataSource,\n mockUniswapLoader,\n );\n\n beforeEach(() => {\n vi.clearAllMocks();\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockImplementation(\n ({ address }) => Promise.resolve(Right(`payload-${address}`)),\n );\n });\n\n describe(\"canHandle function\", () => {\n const validInput: ExternalPluginContextInput = {\n to: \"0x1234567890123456789012345678901234567890\",\n data: \"0x095ea7b30000000000000000000000001234567890123456789012345678901234567890\",\n selector: \"0x095ea7b3\",\n chainId: 1,\n };\n\n it(\"should return true for valid input\", () => {\n expect(\n loader.canHandle(validInput, [\n ClearSignContextType.EXTERNAL_PLUGIN,\n ClearSignContextType.TOKEN,\n ]),\n ).toBe(true);\n });\n\n it(\"should return false for invalid expected type\", () => {\n expect(loader.canHandle(validInput, [ClearSignContextType.NFT])).toBe(\n false,\n );\n expect(loader.canHandle(validInput, [ClearSignContextType.TOKEN])).toBe(\n false,\n );\n expect(\n loader.canHandle(validInput, [ClearSignContextType.EXTERNAL_PLUGIN]),\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.EXTERNAL_PLUGIN,\n ClearSignContextType.TOKEN,\n ]),\n ).toBe(false);\n });\n\n it.each([\n [{ ...validInput, to: undefined }, \"missing to\"],\n [{ ...validInput, data: undefined }, \"missing data\"],\n [{ ...validInput, selector: undefined }, \"missing selector\"],\n [{ ...validInput, chainId: undefined }, \"missing chainId\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(\n loader.canHandle(input, [\n ClearSignContextType.EXTERNAL_PLUGIN,\n ClearSignContextType.TOKEN,\n ]),\n ).toBe(false);\n });\n\n it.each([\n [{ ...validInput, to: \"invalid-hex\" }, \"invalid to hex\"],\n [{ ...validInput, to: \"0x\" }, \"empty to hex\"],\n [{ ...validInput, data: \"invalid-hex\" }, \"invalid data hex\"],\n [{ ...validInput, data: \"0x\" }, \"empty data (0x)\"],\n [{ ...validInput, selector: \"invalid-hex\" }, \"invalid selector hex\"],\n [{ ...validInput, selector: \"0x\" }, \"empty selector hex\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(\n loader.canHandle(input, [\n ClearSignContextType.EXTERNAL_PLUGIN,\n ClearSignContextType.TOKEN,\n ]),\n ).toBe(false);\n });\n\n it.each([\n [{ ...validInput, chainId: \"1\" }, \"string chainId\"],\n [{ ...validInput, chainId: null }, \"null chainId\"],\n [{ ...validInput, chainId: undefined }, \"undefined chainId\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(\n loader.canHandle(input, [\n ClearSignContextType.EXTERNAL_PLUGIN,\n ClearSignContextType.TOKEN,\n ]),\n ).toBe(false);\n });\n });\n\n describe(\"load function\", () => {\n it(\"should return an empty array if no dapp info is provided\", async () => {\n // GIVEN\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(undefined),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return e plugin if no erc20OfInterest is provided\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [],\n method: \"singleParam\",\n plugin: \"TestPlugin\",\n },\n });\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(mockUniswapLoader.canHandle).not.toHaveBeenCalled();\n expect(result).toEqual([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return a list of context responses when one erc20OfInterest is provided for a single parameter\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken\"],\n method: \"singleParam\",\n plugin: \"TestPlugin\",\n },\n });\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(mockUniswapLoader.canHandle).not.toHaveBeenCalled();\n expect(result).toEqual(\n expect.arrayContaining([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n },\n ]),\n );\n });\n\n 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 () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken\"],\n method: \"singleParam\",\n },\n });\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(Error(\"error\")),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(mockUniswapLoader.canHandle).not.toHaveBeenCalled();\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return a list of context responses when two erc20OfInterest are provided for two parameters\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken\", \"toToken\"],\n method: \"multipleParams\",\n },\n });\n const input = inputBuilder(ABI, \"multipleParams\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual(\n expect.arrayContaining([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n },\n ]),\n );\n });\n\n it(\"should return a list of context responses when one erc20OfInterest is an array\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\n \"fromToken.0\",\n \"fromToken.1\",\n \"fromToken.2\",\n \"fromToken.-1\",\n ],\n method: \"arrayParam\",\n },\n });\n const input = inputBuilder(ABI, \"arrayParam\", [\n [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n \"0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n ],\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n },\n // fromToken.2\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n // fromToken.-1\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return an error when a token datasource returns an error\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken\"],\n method: \"singleParam\",\n },\n });\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(new Error(\"error\")),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return an error when the abi is not conform\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: [{ fakeabi: \"notworking\" }],\n selectorDetails: {\n erc20OfInterest: [\"fromToken\"],\n method: \"singleParam\",\n },\n });\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\n \"[ContextModule] ExternalPluginContextLoader: Unable to parse abi\",\n ),\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should throw an error when the erc20OfInterest doest not exist in the transaction\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"notFound\"],\n method: \"singleParam\",\n },\n });\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\n \"[ContextModule] ExternalPluginContextLoader: Unable to get address\",\n ),\n },\n ]);\n });\n\n it(\"should throw an error when an out-of-bounds element is present in erc20OfInterest\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken.3\"],\n method: \"arrayParam\",\n },\n });\n const input = inputBuilder(ABI, \"arrayParam\", [\n [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n \"0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n ],\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new RangeError(\"out of result range\"),\n },\n ]);\n });\n\n it(\"should return a list of context responses when one erc20OfInterest is a complex struct\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\n \"complexStruct.address1\",\n \"complexStruct.param1.param2.0.param3.addresses.0\",\n \"complexStruct.param1.param2.0.param3.addresses.1\",\n \"complexStruct.param1.param2.0.param3.addresses.-1\",\n \"complexStruct.param1.param2.1.param3.addresses.0\",\n \"complexStruct.param1.param2.-1.param3.addresses.0\",\n ],\n method: \"complexStructParam\",\n },\n });\n const input = inputBuilder(ABI, \"complexStructParam\", [\n {\n address1: \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n param1: {\n param2: [\n {\n param3: {\n addresses: [\n \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n \"0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE\",\n ],\n },\n },\n {\n param3: {\n addresses: [\"0xB8c77482e45F1F44dE1745F52C74426C631bDD52\"],\n },\n },\n ],\n },\n },\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return a plugin with Uniswap not being able to load token\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [],\n method: \"singleParam\",\n plugin: \"Uniswap\",\n },\n });\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n vi.spyOn(mockUniswapLoader, \"canHandle\").mockReturnValueOnce(false);\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(mockUniswapLoader.canHandle).toHaveBeenCalled();\n expect(mockUniswapLoader.load).not.toHaveBeenCalled();\n expect(result).toEqual([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return a plugin with Uniswap extracted tokens\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [],\n method: \"singleParam\",\n plugin: \"Uniswap\",\n },\n });\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n vi.spyOn(mockUniswapLoader, \"canHandle\").mockReturnValueOnce(true);\n vi.spyOn(mockUniswapLoader, \"load\").mockResolvedValue([\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n ]);\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(mockUniswapLoader.canHandle).toHaveBeenCalled();\n expect(mockUniswapLoader.load).toHaveBeenCalled();\n expect(result).toEqual([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n ]);\n });\n\n it(\"should return an error when datasource return a Left\", async () => {\n // GIVEN\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Left(new Error(\"error\")),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n ]);\n });\n });\n});\n"],
5
+ "mappings": "wdAAA,IAAAA,EAA0B,kBAC1BC,EAA4B,qBAE5BC,EAAgB,mDAEhBC,EAGO,gEAGPC,EAAqC,2CAIrC,MAAMC,EAAmB,CAAC,CACxB,IAAAC,EACA,gBAAAC,CACF,KAIS,CACL,IAAKD,EACL,gBAAiB,CACf,gBAAiB,CAAC,EAClB,OAAQ,GACR,OAAQ,GACR,eAAgB,SAChB,UAAW,OACX,GAAGC,CACL,CACF,GAGIC,EAAe,CACnBF,EACAG,EACAC,IAC+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D,SAAY,CAErE,MAAMH,EAAQV,EAAa,EAAAY,QAAK,cAAe,CAC7C,4CACF,CAAC,EACD,GAAG,MAAMP,EAA8B,cAAc,EAAE,qBACrD,QAAK,IAAI,MAAM,OAAO,CAAC,CACzB,EAGA,MAAMQ,EAAS,MAAMN,EAAO,KAAKG,CAAK,EAGtC,OAAOG,CAAM,EAAE,QAAQ,CACrB,CACE,KAAM,uBAAqB,MAC3B,MAAO,IAAI,MAAM,OAAO,CAC1B,CACF,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["import_ethers", "import_purify_ts", "import_abi", "import_ExternalPluginContextLoader", "import_ClearSignContext", "dappInfosBuilder", "abi", "selectorDetails", "inputBuilder", "functionName", "params", "data", "mockTokenDataSource", "mockExternalPluginDataSource", "mockUniswapLoader", "loader", "address", "validInput", "input", "_description", "ABI", "result", "dappInfos"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var i=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var e=Object.prototype.hasOwnProperty;var l=(n,r)=>{for(var a in r)i(n,a,{get:r[a],enumerable:!0})},h=(n,r,a,c)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of _(r))!e.call(n,o)&&o!==a&&i(n,o,{get:()=>r[o],enumerable:!(c=d(r,o))||c.enumerable});return n};var m=n=>h(i({},"__esModule",{value:!0}),n);var p={};l(p,{KeyUsage:()=>u});module.exports=m(p);var u=(t=>(t.GenuineCheck="genuine_check",t.ExchangePayload="exchange_payload",t.NftMeta="nft_meta",t.TrustedName="trusted_name",t.BackupProvider="backup_provider",t.ProtectOrchestrator="protect_orchestrator",t.PluginMeta="plugin_meta",t.CoinMeta="coin_meta",t.SeedIdAuth="seed_id_auth",t.TxSimulationSigner="tx_simu_signer",t.Calldata="calldata",t.Network="network",t))(u||{});0&&(module.exports={KeyUsage});
1
+ "use strict";var u=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var e=(i,r)=>{for(var o in r)u(i,o,{get:r[o],enumerable:!0})},m=(i,r,o,a)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of d(r))!l.call(i,n)&&n!==o&&u(i,n,{get:()=>r[n],enumerable:!(a=_(r,n))||a.enumerable});return i};var h=i=>m(u({},"__esModule",{value:!0}),i);var p={};e(p,{KeyUsage:()=>c});module.exports=h(p);var c=(t=>(t.GenuineCheck="genuine_check",t.ExchangePayload="exchange_payload",t.NftMeta="nft_meta",t.TrustedName="trusted_name",t.BackupProvider="backup_provider",t.ProtectOrchestrator="protect_orchestrator",t.PluginMeta="plugin_meta",t.CoinMeta="coin_meta",t.SeedIdAuth="seed_id_auth",t.TxSimulationSigner="tx_simu_signer",t.Calldata="calldata",t.Network="network",t.LESMultisig="les_multisig",t))(c||{});0&&(module.exports={KeyUsage});
2
2
  //# sourceMappingURL=KeyUsage.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/pki/model/KeyUsage.ts"],
4
- "sourcesContent": ["export enum KeyUsage {\n GenuineCheck = \"genuine_check\",\n ExchangePayload = \"exchange_payload\",\n NftMeta = \"nft_meta\",\n TrustedName = \"trusted_name\",\n BackupProvider = \"backup_provider\",\n ProtectOrchestrator = \"protect_orchestrator\",\n PluginMeta = \"plugin_meta\",\n CoinMeta = \"coin_meta\",\n SeedIdAuth = \"seed_id_auth\",\n TxSimulationSigner = \"tx_simu_signer\",\n Calldata = \"calldata\",\n Network = \"network\",\n}\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,cAAAE,IAAA,eAAAC,EAAAH,GAAO,IAAKE,OACVA,EAAA,aAAe,gBACfA,EAAA,gBAAkB,mBAClBA,EAAA,QAAU,WACVA,EAAA,YAAc,eACdA,EAAA,eAAiB,kBACjBA,EAAA,oBAAsB,uBACtBA,EAAA,WAAa,cACbA,EAAA,SAAW,YACXA,EAAA,WAAa,eACbA,EAAA,mBAAqB,iBACrBA,EAAA,SAAW,WACXA,EAAA,QAAU,UAZAA,OAAA",
4
+ "sourcesContent": ["export enum KeyUsage {\n GenuineCheck = \"genuine_check\",\n ExchangePayload = \"exchange_payload\",\n NftMeta = \"nft_meta\",\n TrustedName = \"trusted_name\",\n BackupProvider = \"backup_provider\",\n ProtectOrchestrator = \"protect_orchestrator\",\n PluginMeta = \"plugin_meta\",\n CoinMeta = \"coin_meta\",\n SeedIdAuth = \"seed_id_auth\",\n TxSimulationSigner = \"tx_simu_signer\",\n Calldata = \"calldata\",\n Network = \"network\",\n LESMultisig = \"les_multisig\",\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,cAAAE,IAAA,eAAAC,EAAAH,GAAO,IAAKE,OACVA,EAAA,aAAe,gBACfA,EAAA,gBAAkB,mBAClBA,EAAA,QAAU,WACVA,EAAA,YAAc,eACdA,EAAA,eAAiB,kBACjBA,EAAA,oBAAsB,uBACtBA,EAAA,WAAa,cACbA,EAAA,SAAW,YACXA,EAAA,WAAa,eACbA,EAAA,mBAAqB,iBACrBA,EAAA,SAAW,WACXA,EAAA,QAAU,UACVA,EAAA,YAAc,eAbJA,OAAA",
6
6
  "names": ["KeyUsage_exports", "__export", "KeyUsage", "__toCommonJS"]
7
7
  }
@@ -0,0 +1,2 @@
1
+ "use strict";var A=Object.create;var c=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty;var x=(r,e)=>{for(var o in e)c(r,o,{get:e[o],enumerable:!0})},d=(r,e,o,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of h(e))!I.call(r,t)&&t!==o&&c(r,t,{get:()=>e[t],enumerable:!(s=D(e,t))||s.enumerable});return r};var u=(r,e,o)=>(o=r!=null?A(C(r)):{},d(e||!r||!r.__esModule?c(o,"default",{value:r,enumerable:!0}):o,r)),G=r=>d(c({},"__esModule",{value:!0}),r),g=(r,e,o,s)=>{for(var t=s>1?void 0:s?D(e,o):e,p=r.length-1,f;p>=0;p--)(f=r[p])&&(t=(s?f(e,o,t):f(t))||t);return s&&t&&c(e,o,t),t},m=(r,e)=>(o,s)=>e(o,s,r);var R={};x(R,{HttpSafeAccountDataSource:()=>n});module.exports=G(R);var y=u(require("axios")),S=require("inversify"),i=require("purify-ts"),E=require("../../config/di/configTypes"),a=require("../../shared/constant/HttpHeaders"),k=u(require("../../../package.json"));let n=class{constructor(e){this.config=e}async getDescriptors({safeContractAddress:e,chainId:o,challenge:s}){try{const t=await y.default.request({method:"GET",url:`${this.config.metadataServiceDomain.url}/v2/ethereum/${o}/safe/account/${e}`,params:{challenge:s},headers:{[a.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${k.default.version}`,[a.LEDGER_ORIGIN_TOKEN_HEADER]:this.config.originToken}});return t.data?this.isSafeAccountDto(t.data)?(0,i.Right)({account:{signedDescriptor:t.data.accountDescriptor.signedDescriptor,keyId:t.data.accountDescriptor.keyId,keyUsage:t.data.accountDescriptor.keyUsage},signers:{signedDescriptor:t.data.signersDescriptor.signedDescriptor,keyId:t.data.signersDescriptor.keyId,keyUsage:t.data.signersDescriptor.keyUsage}}):(0,i.Left)(new Error("[ContextModule] HttpSafeAccountDataSource: invalid safe account response format")):(0,i.Left)(new Error("[ContextModule] HttpSafeAccountDataSource: unexpected empty response"))}catch{return(0,i.Left)(new Error("[ContextModule] HttpSafeAccountDataSource: Failed to fetch safe account descriptors"))}}isSafeAccountDto(e){return typeof e=="object"&&e!==null&&"accountDescriptor"in e&&"signersDescriptor"in e&&typeof e.accountDescriptor=="object"&&typeof e.signersDescriptor=="object"&&this.isSafeDescriptorDto(e.accountDescriptor)&&this.isSafeDescriptorDto(e.signersDescriptor)}isSafeDescriptorDto(e){return typeof e=="object"&&e!==null&&"signedDescriptor"in e&&"keyId"in e&&"keyUsage"in e&&typeof e.signedDescriptor=="string"&&typeof e.keyId=="string"&&typeof e.keyUsage=="string"}};n=g([m(0,(0,S.inject)(E.configTypes.Config))],n);0&&(module.exports={HttpSafeAccountDataSource});
2
+ //# sourceMappingURL=HttpSafeAccountDataSource.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/safe/data/HttpSafeAccountDataSource.ts"],
4
+ "sourcesContent": ["import axios from \"axios\";\nimport { inject } from \"inversify\";\nimport { type Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport PACKAGE from \"@root/package.json\";\n\nimport { SafeAccountDto, SafeDescriptorDto } from \"./dto/SafeAccountDto\";\nimport {\n type GetSafeAccountParams,\n type GetSafeAccountResponse,\n type SafeAccountDataSource,\n} from \"./SafeAccountDataSource\";\n\nexport class HttpSafeAccountDataSource implements SafeAccountDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n ) {}\n\n async getDescriptors({\n safeContractAddress,\n chainId,\n challenge,\n }: GetSafeAccountParams): Promise<Either<Error, GetSafeAccountResponse>> {\n try {\n const response = await axios.request<SafeAccountDto>({\n method: \"GET\",\n url: `${this.config.metadataServiceDomain.url}/v2/ethereum/${chainId}/safe/account/${safeContractAddress}`,\n params: {\n challenge,\n },\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n\n if (!response.data) {\n return Left(\n new Error(\n \"[ContextModule] HttpSafeAccountDataSource: unexpected empty response\",\n ),\n );\n }\n\n if (!this.isSafeAccountDto(response.data)) {\n return Left(\n new Error(\n \"[ContextModule] HttpSafeAccountDataSource: invalid safe account response format\",\n ),\n );\n }\n\n return Right({\n account: {\n signedDescriptor: response.data.accountDescriptor.signedDescriptor,\n keyId: response.data.accountDescriptor.keyId,\n keyUsage: response.data.accountDescriptor.keyUsage,\n },\n signers: {\n signedDescriptor: response.data.signersDescriptor.signedDescriptor,\n keyId: response.data.signersDescriptor.keyId,\n keyUsage: response.data.signersDescriptor.keyUsage,\n },\n });\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] HttpSafeAccountDataSource: Failed to fetch safe account descriptors\",\n ),\n );\n }\n }\n\n private isSafeAccountDto(value: unknown): value is SafeAccountDto {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"accountDescriptor\" in value &&\n \"signersDescriptor\" in value &&\n typeof value.accountDescriptor === \"object\" &&\n typeof value.signersDescriptor === \"object\" &&\n this.isSafeDescriptorDto(value.accountDescriptor) &&\n this.isSafeDescriptorDto(value.signersDescriptor)\n );\n }\n\n private isSafeDescriptorDto(value: unknown): value is SafeDescriptorDto {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"signedDescriptor\" in value &&\n \"keyId\" in value &&\n \"keyUsage\" in value &&\n typeof value.signedDescriptor === \"string\" &&\n typeof value.keyId === \"string\" &&\n typeof value.keyUsage === \"string\"\n );\n }\n}\n"],
5
+ "mappings": "qtBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,+BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkB,oBAClBC,EAAuB,qBACvBC,EAAyC,qBAEzCC,EAA4B,mCAE5BC,EAGO,yCACPC,EAAoB,iCASb,IAAMC,EAAN,KAAiE,CACtE,YAC+CC,EAC7C,CAD6C,YAAAA,CAC5C,CAEH,MAAM,eAAe,CACnB,oBAAAC,EACA,QAAAC,EACA,UAAAC,CACF,EAAyE,CACvE,GAAI,CACF,MAAMC,EAAW,MAAM,EAAAC,QAAM,QAAwB,CACnD,OAAQ,MACR,IAAK,GAAG,KAAK,OAAO,sBAAsB,GAAG,gBAAgBH,CAAO,iBAAiBD,CAAmB,GACxG,OAAQ,CACN,UAAAE,CACF,EACA,QAAS,CACP,CAAC,8BAA4B,EAAG,kBAAkB,EAAAG,QAAQ,OAAO,GACjE,CAAC,4BAA0B,EAAG,KAAK,OAAO,WAC5C,CACF,CAAC,EAED,OAAKF,EAAS,KAQT,KAAK,iBAAiBA,EAAS,IAAI,KAQjC,SAAM,CACX,QAAS,CACP,iBAAkBA,EAAS,KAAK,kBAAkB,iBAClD,MAAOA,EAAS,KAAK,kBAAkB,MACvC,SAAUA,EAAS,KAAK,kBAAkB,QAC5C,EACA,QAAS,CACP,iBAAkBA,EAAS,KAAK,kBAAkB,iBAClD,MAAOA,EAAS,KAAK,kBAAkB,MACvC,SAAUA,EAAS,KAAK,kBAAkB,QAC5C,CACF,CAAC,KAlBQ,QACL,IAAI,MACF,iFACF,CACF,KAZO,QACL,IAAI,MACF,sEACF,CACF,CAuBJ,MAAiB,CACf,SAAO,QACL,IAAI,MACF,qFACF,CACF,CACF,CACF,CAEQ,iBAAiBG,EAAyC,CAChE,OACE,OAAOA,GAAU,UACjBA,IAAU,MACV,sBAAuBA,GACvB,sBAAuBA,GACvB,OAAOA,EAAM,mBAAsB,UACnC,OAAOA,EAAM,mBAAsB,UACnC,KAAK,oBAAoBA,EAAM,iBAAiB,GAChD,KAAK,oBAAoBA,EAAM,iBAAiB,CAEpD,CAEQ,oBAAoBA,EAA4C,CACtE,OACE,OAAOA,GAAU,UACjBA,IAAU,MACV,qBAAsBA,GACtB,UAAWA,GACX,aAAcA,GACd,OAAOA,EAAM,kBAAqB,UAClC,OAAOA,EAAM,OAAU,UACvB,OAAOA,EAAM,UAAa,QAE9B,CACF,EArFaR,EAANS,EAAA,CAEFC,EAAA,eAAO,cAAY,MAAM,IAFjBV",
6
+ "names": ["HttpSafeAccountDataSource_exports", "__export", "HttpSafeAccountDataSource", "__toCommonJS", "import_axios", "import_inversify", "import_purify_ts", "import_configTypes", "import_HttpHeaders", "import_package", "HttpSafeAccountDataSource", "config", "safeContractAddress", "chainId", "challenge", "response", "axios", "PACKAGE", "value", "__decorateClass", "__decorateParam"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var g=Object.create;var d=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var h=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var D=(s,o,r,e)=>{if(o&&typeof o=="object"||typeof o=="function")for(let t of m(o))!y.call(s,t)&&t!==r&&d(s,t,{get:()=>o[t],enumerable:!(e=f(o,t))||e.enumerable});return s};var u=(s,o,r)=>(r=s!=null?g(h(s)):{},D(o||!s||!s.__esModule?d(r,"default",{value:s,enumerable:!0}):r,s));var a=u(require("axios")),n=require("purify-ts"),c=require("../../safe/data/HttpSafeAccountDataSource"),i=require("../../shared/constant/HttpHeaders"),l=u(require("../../../package.json"));vi.mock("axios");describe("HttpSafeAccountDataSource",()=>{const s={metadataServiceDomain:{url:"https://metadata.ledger.com"},originToken:"test-origin-token"},o={accountDescriptor:{signedDescriptor:"account-signed-descriptor-data",keyId:"account-key-id",keyUsage:"account-key-usage"},signersDescriptor:{signedDescriptor:"signers-signed-descriptor-data",keyId:"signers-key-id",keyUsage:"signers-key-usage"}},r="0x1234567890123456789012345678901234567890";beforeEach(()=>{vi.clearAllMocks()}),describe("getDescriptors",()=>{it("should return safe account descriptors on successful request",async()=>{const e={safeContractAddress:r,chainId:1,challenge:"0xabcdef"};vi.spyOn(a.default,"request").mockResolvedValue({status:200,data:o});const t=await new c.HttpSafeAccountDataSource(s).getDescriptors(e);expect(a.default.request).toHaveBeenCalledWith({method:"GET",url:"https://metadata.ledger.com/v2/ethereum/1/safe/account/0x1234567890123456789012345678901234567890",params:{challenge:"0xabcdef"},headers:{[i.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${l.default.version}`,[i.LEDGER_ORIGIN_TOKEN_HEADER]:"test-origin-token"}}),expect(t).toEqual((0,n.Right)({account:{signedDescriptor:"account-signed-descriptor-data",keyId:"account-key-id",keyUsage:"account-key-usage"},signers:{signedDescriptor:"signers-signed-descriptor-data",keyId:"signers-key-id",keyUsage:"signers-key-usage"}}))}),it("should work with different chain IDs",async()=>{const e={safeContractAddress:r,chainId:137,challenge:"0xabcdef"};vi.spyOn(a.default,"request").mockResolvedValue({status:200,data:o}),await new c.HttpSafeAccountDataSource(s).getDescriptors(e),expect(a.default.request).toHaveBeenCalledWith(expect.objectContaining({url:"https://metadata.ledger.com/v2/ethereum/137/safe/account/0x1234567890123456789012345678901234567890"}))}),it("should work with different safe addresses",async()=>{const e={safeContractAddress:"0xabcdefabcdefabcdefabcdefabcdefabcdefabcd",chainId:1,challenge:"0xabcdef"};vi.spyOn(a.default,"request").mockResolvedValue({status:200,data:o}),await new c.HttpSafeAccountDataSource(s).getDescriptors(e),expect(a.default.request).toHaveBeenCalledWith(expect.objectContaining({url:"https://metadata.ledger.com/v2/ethereum/1/safe/account/0xabcdefabcdefabcdefabcdefabcdefabcdefabcd"}))}),it("should work with different challenges",async()=>{const e={safeContractAddress:r,chainId:1,challenge:"0x123456789"};vi.spyOn(a.default,"request").mockResolvedValue({status:200,data:o}),await new c.HttpSafeAccountDataSource(s).getDescriptors(e),expect(a.default.request).toHaveBeenCalledWith(expect.objectContaining({params:{challenge:"0x123456789"}}))}),it("should return error when response data is empty",async()=>{const e={safeContractAddress:r,chainId:1,challenge:"0xabcdef"};vi.spyOn(a.default,"request").mockResolvedValue({status:200,data:null});const t=await new c.HttpSafeAccountDataSource(s).getDescriptors(e);expect(t).toEqual((0,n.Left)(new Error("[ContextModule] HttpSafeAccountDataSource: unexpected empty response")))}),it("should return error when response data is undefined",async()=>{const e={safeContractAddress:r,chainId:1,challenge:"0xabcdef"};vi.spyOn(a.default,"request").mockResolvedValue({status:200,data:void 0});const t=await new c.HttpSafeAccountDataSource(s).getDescriptors(e);expect(t).toEqual((0,n.Left)(new Error("[ContextModule] HttpSafeAccountDataSource: unexpected empty response")))}),it("should return error when accountDescriptor is missing",async()=>{const e={safeContractAddress:r,chainId:1,challenge:"0xabcdef"};vi.spyOn(a.default,"request").mockResolvedValue({status:200,data:{signersDescriptor:o.signersDescriptor}});const t=await new c.HttpSafeAccountDataSource(s).getDescriptors(e);expect(t).toEqual((0,n.Left)(new Error("[ContextModule] HttpSafeAccountDataSource: invalid safe account response format")))}),it("should return error when signersDescriptor is missing",async()=>{const e={safeContractAddress:r,chainId:1,challenge:"0xabcdef"};vi.spyOn(a.default,"request").mockResolvedValue({status:200,data:{accountDescriptor:o.accountDescriptor}});const t=await new c.HttpSafeAccountDataSource(s).getDescriptors(e);expect(t).toEqual((0,n.Left)(new Error("[ContextModule] HttpSafeAccountDataSource: invalid safe account response format")))}),it("should return error when accountDescriptor.signedDescriptor is missing",async()=>{const e={safeContractAddress:r,chainId:1,challenge:"0xabcdef"};vi.spyOn(a.default,"request").mockResolvedValue({status:200,data:{accountDescriptor:{keyId:"account-key-id",keyUsage:"account-key-usage"},signersDescriptor:o.signersDescriptor}});const t=await new c.HttpSafeAccountDataSource(s).getDescriptors(e);expect(t).toEqual((0,n.Left)(new Error("[ContextModule] HttpSafeAccountDataSource: invalid safe account response format")))}),it("should return error when accountDescriptor.keyId is missing",async()=>{const e={safeContractAddress:r,chainId:1,challenge:"0xabcdef"};vi.spyOn(a.default,"request").mockResolvedValue({status:200,data:{accountDescriptor:{signedDescriptor:"account-signed-descriptor-data",keyUsage:"account-key-usage"},signersDescriptor:o.signersDescriptor}});const t=await new c.HttpSafeAccountDataSource(s).getDescriptors(e);expect(t).toEqual((0,n.Left)(new Error("[ContextModule] HttpSafeAccountDataSource: invalid safe account response format")))}),it("should return error when accountDescriptor.keyUsage is missing",async()=>{const e={safeContractAddress:r,chainId:1,challenge:"0xabcdef"};vi.spyOn(a.default,"request").mockResolvedValue({status:200,data:{accountDescriptor:{signedDescriptor:"account-signed-descriptor-data",keyId:"account-key-id"},signersDescriptor:o.signersDescriptor}});const t=await new c.HttpSafeAccountDataSource(s).getDescriptors(e);expect(t).toEqual((0,n.Left)(new Error("[ContextModule] HttpSafeAccountDataSource: invalid safe account response format")))}),it("should return error when signersDescriptor fields are invalid",async()=>{const e={safeContractAddress:r,chainId:1,challenge:"0xabcdef"};vi.spyOn(a.default,"request").mockResolvedValue({status:200,data:{accountDescriptor:o.accountDescriptor,signersDescriptor:{signedDescriptor:"signers-signed-descriptor-data",keyId:123,keyUsage:"signers-key-usage"}}});const t=await new c.HttpSafeAccountDataSource(s).getDescriptors(e);expect(t).toEqual((0,n.Left)(new Error("[ContextModule] HttpSafeAccountDataSource: invalid safe account response format")))}),it("should return error when accountDescriptor is not an object",async()=>{const e={safeContractAddress:r,chainId:1,challenge:"0xabcdef"};vi.spyOn(a.default,"request").mockResolvedValue({status:200,data:{accountDescriptor:"invalid-string",signersDescriptor:o.signersDescriptor}});const t=await new c.HttpSafeAccountDataSource(s).getDescriptors(e);expect(t).toEqual((0,n.Left)(new Error("[ContextModule] HttpSafeAccountDataSource: invalid safe account response format")))}),it("should return error when signersDescriptor is not an object",async()=>{const e={safeContractAddress:r,chainId:1,challenge:"0xabcdef"};vi.spyOn(a.default,"request").mockResolvedValue({status:200,data:{accountDescriptor:o.accountDescriptor,signersDescriptor:null}});const t=await new c.HttpSafeAccountDataSource(s).getDescriptors(e);expect(t).toEqual((0,n.Left)(new Error("[ContextModule] HttpSafeAccountDataSource: invalid safe account response format")))}),it("should return error when axios request fails",async()=>{const e={safeContractAddress:r,chainId:1,challenge:"0xabcdef"};vi.spyOn(a.default,"request").mockRejectedValue(new Error("Network error"));const t=await new c.HttpSafeAccountDataSource(s).getDescriptors(e);expect(t).toEqual((0,n.Left)(new Error("[ContextModule] HttpSafeAccountDataSource: Failed to fetch safe account descriptors")))}),it("should return error when axios throws an exception",async()=>{const e={safeContractAddress:r,chainId:1,challenge:"0xabcdef"};vi.spyOn(a.default,"request").mockRejectedValue(new Error("timeout"));const t=await new c.HttpSafeAccountDataSource(s).getDescriptors(e);expect(t).toEqual((0,n.Left)(new Error("[ContextModule] HttpSafeAccountDataSource: Failed to fetch safe account descriptors")))}),it("should handle empty string values in descriptors",async()=>{const e={safeContractAddress:r,chainId:1,challenge:"0xabcdef"};vi.spyOn(a.default,"request").mockResolvedValue({status:200,data:{accountDescriptor:{signedDescriptor:"",keyId:"",keyUsage:""},signersDescriptor:{signedDescriptor:"",keyId:"",keyUsage:""}}});const t=await new c.HttpSafeAccountDataSource(s).getDescriptors(e);expect(t).toEqual((0,n.Right)({account:{signedDescriptor:"",keyId:"",keyUsage:""},signers:{signedDescriptor:"",keyId:"",keyUsage:""}}))}),it("should correctly parse response with long descriptor values",async()=>{const e="a".repeat(1e3),t={safeContractAddress:r,chainId:1,challenge:"0xabcdef"};vi.spyOn(a.default,"request").mockResolvedValue({status:200,data:{accountDescriptor:{signedDescriptor:e,keyId:"account-key-id",keyUsage:"account-key-usage"},signersDescriptor:{signedDescriptor:e,keyId:"signers-key-id",keyUsage:"signers-key-usage"}}});const p=await new c.HttpSafeAccountDataSource(s).getDescriptors(t);expect(p).toEqual((0,n.Right)({account:{signedDescriptor:e,keyId:"account-key-id",keyUsage:"account-key-usage"},signers:{signedDescriptor:e,keyId:"signers-key-id",keyUsage:"signers-key-usage"}}))}),it("should use correct origin token from config",async()=>{const e={metadataServiceDomain:{url:"https://metadata.ledger.com"},originToken:"custom-origin-token"},t={safeContractAddress:r,chainId:1,challenge:"0xabcdef"};vi.spyOn(a.default,"request").mockResolvedValue({status:200,data:o}),await new c.HttpSafeAccountDataSource(e).getDescriptors(t),expect(a.default.request).toHaveBeenCalledWith(expect.objectContaining({headers:expect.objectContaining({[i.LEDGER_ORIGIN_TOKEN_HEADER]:"custom-origin-token"})}))}),it("should use correct metadata service URL from config",async()=>{const e={metadataServiceDomain:{url:"https://custom-metadata.example.com"},originToken:"test-token"},t={safeContractAddress:r,chainId:1,challenge:"0xabcdef"};vi.spyOn(a.default,"request").mockResolvedValue({status:200,data:o}),await new c.HttpSafeAccountDataSource(e).getDescriptors(t),expect(a.default.request).toHaveBeenCalledWith(expect.objectContaining({url:"https://custom-metadata.example.com/v2/ethereum/1/safe/account/0x1234567890123456789012345678901234567890"}))})})});
2
+ //# sourceMappingURL=HttpSafeAccountDataSource.test.js.map