@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,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
- "mappings": "iOAAA,OAAqB,gBAAAA,MAAoB,kCACzC,OAAiB,aAAAC,MAAiB,SAClC,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YACnC,OAAiB,eAAAC,EAAa,QAAAC,EAAM,SAAAC,MAAa,YAGjD,OAAS,uBAAAC,MAA2B,2CAEpC,OAEE,wBAAAC,MACK,kCAEP,OAAS,cAAAC,MAAkB,wBAS3B,MAAMC,EAA0C,CAC9CC,EAAqB,gBACrBA,EAAqB,KACvB,EAGO,IAAMC,EAAN,KAEP,CACU,0BACA,iBAER,YAEEC,EACoCC,EACpC,CACA,KAAK,0BAA4BD,EACjC,KAAK,iBAAmBC,CAC1B,CAEA,UACEC,EACAC,EACqC,CACrC,OACE,OAAOD,GAAU,UACjBA,IAAU,MACV,OAAQA,GACR,SAAUA,GACV,aAAcA,GACd,YAAaA,GACb,OAAOA,EAAM,SAAY,UACzBE,EAAaF,EAAM,EA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tB,EAAqB,MAAO,MAAAsB,CAAM,CAAC,EAC7D,MAAQE,GAAaA,CACvB,CAAC,CACH,CAEQ,gBACNpB,EACAgB,EACAH,EACA,CACA,MAAMQ,EAAU,KAAK,mBAAmBL,EAAWH,CAAe,EAElE,OAAOJ,EAA2B,CAAC,CAAE,YAAAa,CAAY,IAC/CA,EACE,KAAK,iBAAiB,qBAAqB,CACzC,QAAAD,EACA,QAASrB,EAAM,OACjB,CAAC,CACH,CACF,CACF,CAEQ,mBACNuB,EACAC,EACAnB,EAC8B,CAC9B,GAAI,CACF,MAAMoB,EAAoB,IAAIC,EAAUH,CAAG,EAC3C,OAAOI,EAAMF,EAAkB,mBAAmBD,EAAQnB,CAAI,CAAC,CACjE,MAAiB,CACf,OAAOuB,EACL,IAAI,MACF,kEACF,CACF,CACF,CACF,CAEQ,mBACNC,EACAhB,EACY,CAGZ,IAAIiB,EAAajB,EACjB,UAAWkB,KAAOF,EAAK,MAAM,GAAG,EAG1BE,IAAQ,KAEVD,EAAQA,EAAMA,EAAM,OAAS,CAAC,EAK9BA,EAAQA,EAAMC,CAAG,EAIrB,GAAI,CAAC7B,EAAa4B,CAAK,EACrB,MAAM,IAAI,MACR,oEACF,EAGF,OAAOA,CACT,CACF,EA5KajC,EAANmC,EAAA,CADNC,EAAW,EAQPC,EAAA,EAAAC,EAAOC,EAAoB,wBAAwB,GAEnDF,EAAA,EAAAC,EAAOE,EAAW,eAAe,IATzBxC",
6
- "names": ["isHexaString", "Interface", "inject", "injectable", "EitherAsync", "Left", "Right", "externalPluginTypes", "ClearSignContextType", "tokenTypes", "SUPPORTED_TYPES", "ClearSignContextType", "ExternalPluginContextLoader", "externalPluginDataSource", "tokenDataSource", "input", "expectedTypes", "isHexaString", "type", "to", "data", "selector", "chainId", "eitherDappInfos", "EitherAsync", "liftEither", "dappInfos", "externalPluginContext", "decodedCallData", "extractedDecodedCallData", "promises", "erc20Path", "eitherToken", "error", "payload", "contexts", "address", "fromPromise", "abi", "method", "contractInterface", "Interface", "Right", "Left", "path", "value", "key", "__decorateClass", "injectable", "__decorateParam", "inject", "externalPluginTypes", "tokenTypes"]
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 }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AC8B,CAC9B,GAAI,CACF,MAAMsB,EAAoB,IAAIC,EAAUH,CAAG,EAC3C,OAAOI,EAAMF,EAAkB,mBAAmBD,EAAQrB,CAAI,CAAC,CACjE,MAAiB,CACf,OAAOyB,EACL,IAAI,MACF,kEACF,CACF,CACF,CACF,CAEQ,mBACNC,EACAhB,EACY,CAGZ,IAAIiB,EAAajB,EACjB,UAAWkB,KAAOF,EAAK,MAAM,GAAG,EAG1BE,IAAQ,KAEVD,EAAQA,EAAMA,EAAM,OAAS,CAAC,EAK9BA,EAAQA,EAAMC,CAAG,EAIrB,GAAI,CAAC/B,EAAa8B,CAAK,EACrB,MAAM,IAAI,MACR,oEACF,EAGF,OAAOA,CACT,CACF,EA5LapC,EAANsC,EAAA,CADNC,EAAW,EAUPC,EAAA,EAAAC,EAAOC,EAAoB,wBAAwB,GAEnDF,EAAA,EAAAC,EAAOE,EAAW,eAAe,GAEjCH,EAAA,EAAAC,EAAOG,EAAa,oBAAoB,IAbhC5C",
6
+ "names": ["isHexaString", "Interface", "inject", "injectable", "EitherAsync", "Left", "Right", "externalPluginTypes", "ClearSignContextType", "tokenTypes", "uniswapTypes", "SUPPORTED_TYPES", "ClearSignContextType", "ExternalPluginContextLoader", "_externalPluginDataSource", "_tokenDataSource", "_uniswapLoader", "input", "expectedTypes", "isHexaString", "type", "to", "data", "selector", "chainId", "eitherDappInfos", "EitherAsync", "liftEither", "dappInfos", "externalPluginContext", "customLoader", "tokens", "decodedCallData", "extractedDecodedCallData", "promises", "erc20Path", "eitherToken", "error", "payload", "contexts", "address", "fromPromise", "abi", "method", "contractInterface", "Interface", "Right", "Left", "path", "value", "key", "__decorateClass", "injectable", "__decorateParam", "inject", "externalPluginTypes", "tokenTypes", "uniswapTypes"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{Interface as u}from"ethers";import{Left as i,Right as c}from"purify-ts";import r from"@/external-plugin/__tests__/abi.json";import{ExternalPluginContextLoader as E}from"../../external-plugin/domain/ExternalPluginContextLoader";import{ClearSignContextType as a}from"../../shared/model/ClearSignContext";const d=({abi:p,selectorDetails:s})=>({abi:p,selectorDetails:{erc20OfInterest:[],method:"",plugin:"",serializedData:"123456",signature:"7890",...s}}),l=(p,s,n)=>{const t=new u(JSON.stringify(p)).encodeFunctionData(s,n);return{to:"0x0",data:t,selector:t.slice(0,10),chainId:1}};describe("ExternalPluginContextLoader",()=>{const p={getTokenInfosPayload:vi.fn()},s={getDappInfos:vi.fn()},n=new E(s,p);beforeEach(()=>{vi.clearAllMocks(),vi.spyOn(p,"getTokenInfosPayload").mockImplementation(({address:e})=>Promise.resolve(c(`payload-${e}`)))}),describe("canHandle function",()=>{const e={to:"0x1234567890123456789012345678901234567890",data:"0x095ea7b30000000000000000000000001234567890123456789012345678901234567890",selector:"0x095ea7b3",chainId:1};it("should return true for valid input",()=>{expect(n.canHandle(e,[a.EXTERNAL_PLUGIN,a.TOKEN])).toBe(!0)}),it("should return false for invalid expected type",()=>{expect(n.canHandle(e,[a.NFT])).toBe(!1),expect(n.canHandle(e,[a.TOKEN])).toBe(!1),expect(n.canHandle(e,[a.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,o)=>{expect(n.canHandle(t,[a.EXTERNAL_PLUGIN,a.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,o)=>{expect(n.canHandle(t,[a.EXTERNAL_PLUGIN,a.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,o)=>{expect(n.canHandle(t,[a.EXTERNAL_PLUGIN,a.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,o)=>{expect(n.canHandle(t,[a.EXTERNAL_PLUGIN,a.TOKEN])).toBe(!1)})}),describe("load function",()=>{it("should return an empty array if no dapp info is provided",async()=>{const e=l(r,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(s,"getDappInfos").mockResolvedValue(c(void 0));const t=await n.load(e);expect(t).toEqual([])}),it("should return e plugin if no erc20OfInterest is provided",async()=>{const e=d({abi:r,selectorDetails:{erc20OfInterest:[],method:"singleParam"}}),t=l(r,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(s,"getDappInfos").mockResolvedValue(c(e));const o=await n.load(t);expect(o).toEqual([{type:a.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return a list of context responses when one erc20OfInterest is provided for a single parameter",async()=>{const e=d({abi:r,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),t=l(r,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(s,"getDappInfos").mockResolvedValue(c(e));const o=await n.load(t);expect(o).toEqual(expect.arrayContaining([{type:a.EXTERNAL_PLUGIN,payload:"1234567890"},{type:a.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=d({abi:r,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),t=l(r,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(s,"getDappInfos").mockResolvedValue(c(e)),vi.spyOn(p,"getTokenInfosPayload").mockResolvedValue(i(Error("error")));const o=await n.load(t);expect(o).toEqual([{type:a.ERROR,error:new Error("error")},{type:a.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return a list of context responses when two erc20OfInterest are provided for two parameters",async()=>{const e=d({abi:r,selectorDetails:{erc20OfInterest:["fromToken","toToken"],method:"multipleParams"}}),t=l(r,"multipleParams",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7"]);vi.spyOn(s,"getDappInfos").mockResolvedValue(c(e));const o=await n.load(t);expect(o).toEqual(expect.arrayContaining([{type:a.EXTERNAL_PLUGIN,payload:"1234567890"},{type:a.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:a.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"}]))}),it("should return a list of context responses when one erc20OfInterest is an array",async()=>{const e=d({abi:r,selectorDetails:{erc20OfInterest:["fromToken.0","fromToken.1","fromToken.2","fromToken.-1"],method:"arrayParam"}}),t=l(r,"arrayParam",[["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7","0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]]);vi.spyOn(s,"getDappInfos").mockResolvedValue(c(e));const o=await n.load(t);expect(o).toEqual([{type:a.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:a.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"},{type:a.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:a.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:a.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return an error when a token datasource returns an error",async()=>{const e=d({abi:r,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),t=l(r,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(s,"getDappInfos").mockResolvedValue(c(e)),vi.spyOn(p,"getTokenInfosPayload").mockResolvedValue(i(new Error("error")));const o=await n.load(t);expect(o).toEqual([{type:a.ERROR,error:new Error("error")},{type:a.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return an error when the abi is not conform",async()=>{const e=d({abi:[{fakeabi:"notworking"}],selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),t=l(r,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(s,"getDappInfos").mockResolvedValue(c(e));const o=await n.load(t);expect(o).toEqual([{type:a.ERROR,error:new Error("[ContextModule] ExternalPluginContextLoader: Unable to parse abi")},{type:a.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should throw an error when the erc20OfInterest doest not exist in the transaction",async()=>{const e=d({abi:r,selectorDetails:{erc20OfInterest:["notFound"],method:"singleParam"}}),t=l(r,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(s,"getDappInfos").mockResolvedValue(c(e));const o=await n.load(t);expect(o).toEqual([{type:a.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=d({abi:r,selectorDetails:{erc20OfInterest:["fromToken.3"],method:"arrayParam"}}),t=l(r,"arrayParam",[["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7","0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]]);vi.spyOn(s,"getDappInfos").mockResolvedValue(c(e));const o=await n.load(t);expect(o).toEqual([{type:a.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=d({abi:r,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=l(r,"complexStructParam",[{address1:"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",param1:{param2:[{param3:{addresses:["0xdAC17F958D2ee523a2206206994597C13D831ec7","0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"]}},{param3:{addresses:["0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]}}]}}]);vi.spyOn(s,"getDappInfos").mockResolvedValue(c(e));const o=await n.load(t);expect(o).toEqual([{type:a.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:a.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"},{type:a.TOKEN,payload:"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"},{type:a.TOKEN,payload:"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"},{type:a.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:a.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:a.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return an error when datasource return a Left",async()=>{const e=l(r,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(s,"getDappInfos").mockResolvedValue(i(new Error("error")));const t=await n.load(e);expect(t).toEqual([{type:a.ERROR,error:new Error("error")}])})})});
1
+ import{Interface as E}from"ethers";import{Left as u,Right as l}from"purify-ts";import n from"@/external-plugin/__tests__/abi.json";import{ExternalPluginContextLoader as m}from"../../external-plugin/domain/ExternalPluginContextLoader";import{ClearSignContextType as a}from"../../shared/model/ClearSignContext";const p=({abi:i,selectorDetails:s})=>({abi:i,selectorDetails:{erc20OfInterest:[],method:"",plugin:"",serializedData:"123456",signature:"7890",...s}}),c=(i,s,d)=>{const e=new E(JSON.stringify(i)).encodeFunctionData(s,d);return{to:"0x0",data:e,selector:e.slice(0,10),chainId:1}};describe("ExternalPluginContextLoader",()=>{const i={getTokenInfosPayload:vi.fn()},s={getDappInfos:vi.fn()},d={canHandle:vi.fn(),load:vi.fn()},r=new m(s,i,d);beforeEach(()=>{vi.clearAllMocks(),vi.spyOn(i,"getTokenInfosPayload").mockImplementation(({address:e})=>Promise.resolve(l(`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.EXTERNAL_PLUGIN,a.TOKEN])).toBe(!0)}),it("should return false for invalid expected type",()=>{expect(r.canHandle(e,[a.NFT])).toBe(!1),expect(r.canHandle(e,[a.TOKEN])).toBe(!1),expect(r.canHandle(e,[a.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,o)=>{expect(r.canHandle(t,[a.EXTERNAL_PLUGIN,a.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,o)=>{expect(r.canHandle(t,[a.EXTERNAL_PLUGIN,a.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,o)=>{expect(r.canHandle(t,[a.EXTERNAL_PLUGIN,a.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,o)=>{expect(r.canHandle(t,[a.EXTERNAL_PLUGIN,a.TOKEN])).toBe(!1)})}),describe("load function",()=>{it("should return an empty array if no dapp info is provided",async()=>{const e=c(n,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(s,"getDappInfos").mockResolvedValue(l(void 0));const t=await r.load(e);expect(t).toEqual([])}),it("should return e plugin if no erc20OfInterest is provided",async()=>{const e=p({abi:n,selectorDetails:{erc20OfInterest:[],method:"singleParam",plugin:"TestPlugin"}}),t=c(n,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(s,"getDappInfos").mockResolvedValue(l(e));const o=await r.load(t);expect(d.canHandle).not.toHaveBeenCalled(),expect(o).toEqual([{type:a.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:n,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam",plugin:"TestPlugin"}}),t=c(n,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(s,"getDappInfos").mockResolvedValue(l(e));const o=await r.load(t);expect(d.canHandle).not.toHaveBeenCalled(),expect(o).toEqual(expect.arrayContaining([{type:a.EXTERNAL_PLUGIN,payload:"1234567890"},{type:a.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:n,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),t=c(n,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(s,"getDappInfos").mockResolvedValue(l(e)),vi.spyOn(i,"getTokenInfosPayload").mockResolvedValue(u(Error("error")));const o=await r.load(t);expect(d.canHandle).not.toHaveBeenCalled(),expect(o).toEqual([{type:a.ERROR,error:new Error("error")},{type:a.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:n,selectorDetails:{erc20OfInterest:["fromToken","toToken"],method:"multipleParams"}}),t=c(n,"multipleParams",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7"]);vi.spyOn(s,"getDappInfos").mockResolvedValue(l(e));const o=await r.load(t);expect(o).toEqual(expect.arrayContaining([{type:a.EXTERNAL_PLUGIN,payload:"1234567890"},{type:a.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:a.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"}]))}),it("should return a list of context responses when one erc20OfInterest is an array",async()=>{const e=p({abi:n,selectorDetails:{erc20OfInterest:["fromToken.0","fromToken.1","fromToken.2","fromToken.-1"],method:"arrayParam"}}),t=c(n,"arrayParam",[["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7","0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]]);vi.spyOn(s,"getDappInfos").mockResolvedValue(l(e));const o=await r.load(t);expect(o).toEqual([{type:a.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:a.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"},{type:a.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:a.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:a.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return an error when a token datasource returns an error",async()=>{const e=p({abi:n,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),t=c(n,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(s,"getDappInfos").mockResolvedValue(l(e)),vi.spyOn(i,"getTokenInfosPayload").mockResolvedValue(u(new Error("error")));const o=await r.load(t);expect(o).toEqual([{type:a.ERROR,error:new Error("error")},{type:a.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=c(n,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(s,"getDappInfos").mockResolvedValue(l(e));const o=await r.load(t);expect(o).toEqual([{type:a.ERROR,error:new Error("[ContextModule] ExternalPluginContextLoader: Unable to parse abi")},{type:a.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should throw an error when the erc20OfInterest doest not exist in the transaction",async()=>{const e=p({abi:n,selectorDetails:{erc20OfInterest:["notFound"],method:"singleParam"}}),t=c(n,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(s,"getDappInfos").mockResolvedValue(l(e));const o=await r.load(t);expect(o).toEqual([{type:a.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:n,selectorDetails:{erc20OfInterest:["fromToken.3"],method:"arrayParam"}}),t=c(n,"arrayParam",[["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7","0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]]);vi.spyOn(s,"getDappInfos").mockResolvedValue(l(e));const o=await r.load(t);expect(o).toEqual([{type:a.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:n,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=c(n,"complexStructParam",[{address1:"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",param1:{param2:[{param3:{addresses:["0xdAC17F958D2ee523a2206206994597C13D831ec7","0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"]}},{param3:{addresses:["0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]}}]}}]);vi.spyOn(s,"getDappInfos").mockResolvedValue(l(e));const o=await r.load(t);expect(o).toEqual([{type:a.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:a.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"},{type:a.TOKEN,payload:"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"},{type:a.TOKEN,payload:"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"},{type:a.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:a.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:a.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return a plugin with Uniswap not being able to load token",async()=>{const e=p({abi:n,selectorDetails:{erc20OfInterest:[],method:"singleParam",plugin:"Uniswap"}}),t=c(n,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(s,"getDappInfos").mockResolvedValue(l(e)),vi.spyOn(d,"canHandle").mockReturnValueOnce(!1);const o=await r.load(t);expect(d.canHandle).toHaveBeenCalled(),expect(d.load).not.toHaveBeenCalled(),expect(o).toEqual([{type:a.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return a plugin with Uniswap extracted tokens",async()=>{const e=p({abi:n,selectorDetails:{erc20OfInterest:[],method:"singleParam",plugin:"Uniswap"}}),t=c(n,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(s,"getDappInfos").mockResolvedValue(l(e)),vi.spyOn(d,"canHandle").mockReturnValueOnce(!0),vi.spyOn(d,"load").mockResolvedValue([{type:a.TOKEN,payload:"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"},{type:a.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"}]);const o=await r.load(t);expect(d.canHandle).toHaveBeenCalled(),expect(d.load).toHaveBeenCalled(),expect(o).toEqual([{type:a.EXTERNAL_PLUGIN,payload:"1234567890"},{type:a.TOKEN,payload:"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"},{type:a.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"}])}),it("should return an error when datasource return a Left",async()=>{const e=c(n,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(s,"getDappInfos").mockResolvedValue(u(new Error("error")));const t=await r.load(e);expect(t).toEqual([{type:a.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": "AAAA,OAAS,aAAAA,MAAiB,SAC1B,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAE5B,OAAOC,MAAS,uCAEhB,OAEE,+BAAAC,MACK,uDAGP,OAAS,wBAAAC,MAA4B,kCAGrC,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,IAAIZ,EAAU,KAAK,UAAUO,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,IAAIX,EACjBU,EACAD,CACF,EAEA,WAAW,IAAM,CACf,GAAG,cAAc,EACjB,GAAG,MAAMA,EAAqB,s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,CAAK,EAGtC,OAAOE,CAAM,EAAE,QAAQ,CACrB,CACE,KAAMf,EAAqB,MAC3B,QAAS,oDACX,EACA,CACE,KAAMA,EAAqB,MAC3B,QAAS,oDACX,EACA,CACE,KAAMA,EAAqB,MAC3B,QAAS,oDACX,EACA,CACE,KAAMA,EAAqB,MAC3B,QAAS,oDACX,EACA,CACE,KAAMA,EAAqB,MAC3B,QAAS,oDACX,EACA,CACE,KAAMA,EAAqB,MAC3B,QAAS,oDACX,EACA,CACE,KAAMA,EAAqB,gBAC3B,QAAS,YACX,CACF,CAAC,CACH,CAAC,EAED,GAAG,uDAAwD,SAAY,CAErE,MAAMa,EAAQT,EAAaN,EAAK,cAAe,CAC7C,4CACF,CAAC,EACD,GAAG,MAAMW,EAA8B,cAAc,EAAE,kBACrDb,EAAK,IAAI,MAAM,OAAO,CAAC,CACzB,EAGA,MAAMmB,EAAS,MAAML,EAAO,KAAKG,CAAK,EAGtC,OAAOE,CAAM,EAAE,QAAQ,CACrB,CACE,KAAMf,EAAqB,MAC3B,MAAO,IAAI,MAAM,OAAO,CAC1B,CACF,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["Interface", "Left", "Right", "ABI", "ExternalPluginContextLoader", "ClearSignContextType", "dappInfosBuilder", "abi", "selectorDetails", "inputBuilder", "functionName", "params", "data", "mockTokenDataSource", "mockExternalPluginDataSource", "loader", "address", "validInput", "input", "_description", "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": "AAAA,OAAS,aAAAA,MAAiB,SAC1B,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAE5B,OAAOC,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EAAE,iBAAiB,EAChD,OAAOM,CAAM,EAAE,QAAQ,CACrB,CACE,KAAMhB,EAAqB,gBAC3B,QAAS,YACX,EACA,CACE,KAAMA,EAAqB,MAC3B,QAAS,oDACX,EACA,CACE,KAAMA,EAAqB,MAC3B,QAAS,oDACX,CACF,CAAC,CACH,CAAC,EAED,GAAG,uDAAwD,SAAY,CAErE,MAAMc,EAAQV,EAAaN,EAAK,cAAe,CAC7C,4CACF,CAAC,EACD,GAAG,MAAMW,EAA8B,cAAc,EAAE,kBACrDb,EAAK,IAAI,MAAM,OAAO,CAAC,CACzB,EAGA,MAAMoB,EAAS,MAAML,EAAO,KAAKG,CAAK,EAGtC,OAAOE,CAAM,EAAE,QAAQ,CACrB,CACE,KAAMhB,EAAqB,MAC3B,MAAO,IAAI,MAAM,OAAO,CAC1B,CACF,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["Interface", "Left", "Right", "ABI", "ExternalPluginContextLoader", "ClearSignContextType", "dappInfosBuilder", "abi", "selectorDetails", "inputBuilder", "functionName", "params", "data", "mockTokenDataSource", "mockExternalPluginDataSource", "mockUniswapLoader", "loader", "address", "validInput", "input", "_description", "result", "dappInfos"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var r=(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))(r||{});export{r as KeyUsage};
1
+ var r=(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))(r||{});export{r as 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": "AAAO,IAAKA,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": "AAAO,IAAKA,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"]
7
7
  }
@@ -0,0 +1,2 @@
1
+ var D=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var p=(s,e,o,r)=>{for(var t=r>1?void 0:r?d(e,o):e,c=s.length-1,n;c>=0;c--)(n=s[c])&&(t=(r?n(e,o,t):n(t))||t);return r&&t&&D(e,o,t),t},f=(s,e)=>(o,r)=>e(o,r,s);import u from"axios";import{inject as g}from"inversify";import{Left as a,Right as m}from"purify-ts";import{configTypes as y}from"../../config/di/configTypes";import{LEDGER_CLIENT_VERSION_HEADER as S,LEDGER_ORIGIN_TOKEN_HEADER as E}from"../../shared/constant/HttpHeaders";import k from"../../../package.json";let i=class{constructor(e){this.config=e}async getDescriptors({safeContractAddress:e,chainId:o,challenge:r}){try{const t=await u.request({method:"GET",url:`${this.config.metadataServiceDomain.url}/v2/ethereum/${o}/safe/account/${e}`,params:{challenge:r},headers:{[S]:`context-module/${k.version}`,[E]:this.config.originToken}});return t.data?this.isSafeAccountDto(t.data)?m({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}}):a(new Error("[ContextModule] HttpSafeAccountDataSource: invalid safe account response format")):a(new Error("[ContextModule] HttpSafeAccountDataSource: unexpected empty response"))}catch{return a(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"}};i=p([f(0,g(y.Config))],i);export{i as 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": "iOAAA,OAAOA,MAAW,QAClB,OAAS,UAAAC,MAAc,YACvB,OAAsB,QAAAC,EAAM,SAAAC,MAAa,YAEzC,OAAS,eAAAC,MAAmB,0BAE5B,OACE,gCAAAC,EACA,8BAAAC,MACK,gCACP,OAAOC,MAAa,qBASb,IAAMC,EAAN,KAAiE,CACtE,YAC+CC,EAC7C,CAD6C,YAAAA,CAC5C,CAEH,MAAM,eAAe,CACnB,oBAAAC,EACA,QAAAC,EACA,UAAAC,CACF,EAAyE,CACv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ios", "inject", "Left", "Right", "configTypes", "LEDGER_CLIENT_VERSION_HEADER", "LEDGER_ORIGIN_TOKEN_HEADER", "PACKAGE", "HttpSafeAccountDataSource", "config", "safeContractAddress", "chainId", "challenge", "response", "axios", "LEDGER_CLIENT_VERSION_HEADER", "PACKAGE", "LEDGER_ORIGIN_TOKEN_HEADER", "Right", "Left", "value", "__decorateClass", "__decorateParam", "inject", "configTypes"]
7
+ }
@@ -0,0 +1,2 @@
1
+ import s from"axios";import{Left as n,Right as i}from"purify-ts";import{HttpSafeAccountDataSource as a}from"../../safe/data/HttpSafeAccountDataSource";import{LEDGER_CLIENT_VERSION_HEADER as l,LEDGER_ORIGIN_TOKEN_HEADER as d}from"../../shared/constant/HttpHeaders";import p from"../../../package.json";vi.mock("axios");describe("HttpSafeAccountDataSource",()=>{const o={metadataServiceDomain:{url:"https://metadata.ledger.com"},originToken:"test-origin-token"},c={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(s,"request").mockResolvedValue({status:200,data:c});const t=await new a(o).getDescriptors(e);expect(s.request).toHaveBeenCalledWith({method:"GET",url:"https://metadata.ledger.com/v2/ethereum/1/safe/account/0x1234567890123456789012345678901234567890",params:{challenge:"0xabcdef"},headers:{[l]:`context-module/${p.version}`,[d]:"test-origin-token"}}),expect(t).toEqual(i({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(s,"request").mockResolvedValue({status:200,data:c}),await new a(o).getDescriptors(e),expect(s.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(s,"request").mockResolvedValue({status:200,data:c}),await new a(o).getDescriptors(e),expect(s.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(s,"request").mockResolvedValue({status:200,data:c}),await new a(o).getDescriptors(e),expect(s.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(s,"request").mockResolvedValue({status:200,data:null});const t=await new a(o).getDescriptors(e);expect(t).toEqual(n(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(s,"request").mockResolvedValue({status:200,data:void 0});const t=await new a(o).getDescriptors(e);expect(t).toEqual(n(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(s,"request").mockResolvedValue({status:200,data:{signersDescriptor:c.signersDescriptor}});const t=await new a(o).getDescriptors(e);expect(t).toEqual(n(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(s,"request").mockResolvedValue({status:200,data:{accountDescriptor:c.accountDescriptor}});const t=await new a(o).getDescriptors(e);expect(t).toEqual(n(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(s,"request").mockResolvedValue({status:200,data:{accountDescriptor:{keyId:"account-key-id",keyUsage:"account-key-usage"},signersDescriptor:c.signersDescriptor}});const t=await new a(o).getDescriptors(e);expect(t).toEqual(n(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(s,"request").mockResolvedValue({status:200,data:{accountDescriptor:{signedDescriptor:"account-signed-descriptor-data",keyUsage:"account-key-usage"},signersDescriptor:c.signersDescriptor}});const t=await new a(o).getDescriptors(e);expect(t).toEqual(n(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(s,"request").mockResolvedValue({status:200,data:{accountDescriptor:{signedDescriptor:"account-signed-descriptor-data",keyId:"account-key-id"},signersDescriptor:c.signersDescriptor}});const t=await new a(o).getDescriptors(e);expect(t).toEqual(n(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(s,"request").mockResolvedValue({status:200,data:{accountDescriptor:c.accountDescriptor,signersDescriptor:{signedDescriptor:"signers-signed-descriptor-data",keyId:123,keyUsage:"signers-key-usage"}}});const t=await new a(o).getDescriptors(e);expect(t).toEqual(n(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(s,"request").mockResolvedValue({status:200,data:{accountDescriptor:"invalid-string",signersDescriptor:c.signersDescriptor}});const t=await new a(o).getDescriptors(e);expect(t).toEqual(n(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(s,"request").mockResolvedValue({status:200,data:{accountDescriptor:c.accountDescriptor,signersDescriptor:null}});const t=await new a(o).getDescriptors(e);expect(t).toEqual(n(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(s,"request").mockRejectedValue(new Error("Network error"));const t=await new a(o).getDescriptors(e);expect(t).toEqual(n(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(s,"request").mockRejectedValue(new Error("timeout"));const t=await new a(o).getDescriptors(e);expect(t).toEqual(n(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(s,"request").mockResolvedValue({status:200,data:{accountDescriptor:{signedDescriptor:"",keyId:"",keyUsage:""},signersDescriptor:{signedDescriptor:"",keyId:"",keyUsage:""}}});const t=await new a(o).getDescriptors(e);expect(t).toEqual(i({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(s,"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 u=await new a(o).getDescriptors(t);expect(u).toEqual(i({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(s,"request").mockResolvedValue({status:200,data:c}),await new a(e).getDescriptors(t),expect(s.request).toHaveBeenCalledWith(expect.objectContaining({headers:expect.objectContaining({[d]:"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(s,"request").mockResolvedValue({status:200,data:c}),await new a(e).getDescriptors(t),expect(s.request).toHaveBeenCalledWith(expect.objectContaining({url:"https://custom-metadata.example.com/v2/ethereum/1/safe/account/0x1234567890123456789012345678901234567890"}))})})});
2
+ //# sourceMappingURL=HttpSafeAccountDataSource.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/safe/data/HttpSafeAccountDataSource.test.ts"],
4
+ "sourcesContent": ["import { type HexaString } from \"@ledgerhq/device-management-kit\";\nimport axios from \"axios\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { HttpSafeAccountDataSource } from \"@/safe/data/HttpSafeAccountDataSource\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport PACKAGE from \"@root/package.json\";\n\nvi.mock(\"axios\");\n\ndescribe(\"HttpSafeAccountDataSource\", () => {\n const config: ContextModuleConfig = {\n metadataServiceDomain: {\n url: \"https://metadata.ledger.com\",\n },\n originToken: \"test-origin-token\",\n } as ContextModuleConfig;\n\n const validSafeAccountDto = {\n accountDescriptor: {\n signedDescriptor: \"account-signed-descriptor-data\",\n keyId: \"account-key-id\",\n keyUsage: \"account-key-usage\",\n },\n signersDescriptor: {\n signedDescriptor: \"signers-signed-descriptor-data\",\n keyId: \"signers-key-id\",\n keyUsage: \"signers-key-usage\",\n },\n };\n\n const validsafeContractAddress: HexaString =\n \"0x1234567890123456789012345678901234567890\";\n\n beforeEach(() => {\n vi.clearAllMocks();\n });\n\n describe(\"getDescriptors\", () => {\n it(\"should return safe account descriptors on successful request\", async () => {\n // GIVEN\n const params = {\n safeContractAddress: validsafeContractAddress,\n chainId: 1,\n challenge: \"0xabcdef\",\n };\n vi.spyOn(axios, \"request\").mockResolvedValue({\n status: 200,\n data: validSafeAccountDto,\n });\n\n // WHEN\n const result = await new HttpSafeAccountDataSource(config).getDescriptors(\n params,\n );\n\n // THEN\n expect(axios.request).toHaveBeenCalledWith({\n method: \"GET\",\n url: \"https://metadata.ledger.com/v2/ethereum/1/safe/account/0x1234567890123456789012345678901234567890\",\n params: {\n challenge: \"0xabcdef\",\n },\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: \"test-origin-token\",\n },\n });\n expect(result).toEqual(\n Right({\n account: {\n signedDescriptor: \"account-signed-descriptor-data\",\n keyId: \"account-key-id\",\n keyUsage: \"account-key-usage\",\n },\n signers: {\n signedDescriptor: \"signers-signed-descriptor-data\",\n keyId: \"signers-key-id\",\n keyUsage: \"signers-key-usage\",\n },\n }),\n );\n });\n\n it(\"should work with different chain IDs\", async () => {\n // GIVEN\n const params = {\n safeContractAddress: validsafeContractAddress,\n chainId: 137, // Polygon\n challenge: \"0xabcdef\",\n };\n vi.spyOn(axios, \"request\").mockResolvedValue({\n status: 200,\n data: validSafeAccountDto,\n });\n\n // WHEN\n await new HttpSafeAccountDataSource(config).getDescriptors(params);\n\n // THEN\n expect(axios.request).toHaveBeenCalledWith(\n expect.objectContaining({\n url: \"https://metadata.ledger.com/v2/ethereum/137/safe/account/0x1234567890123456789012345678901234567890\",\n }),\n );\n });\n\n it(\"should work with different safe addresses\", async () => {\n // GIVEN\n const params = {\n safeContractAddress:\n \"0xabcdefabcdefabcdefabcdefabcdefabcdefabcd\" as HexaString,\n chainId: 1,\n challenge: \"0xabcdef\",\n };\n vi.spyOn(axios, \"request\").mockResolvedValue({\n status: 200,\n data: validSafeAccountDto,\n });\n\n // WHEN\n await new HttpSafeAccountDataSource(config).getDescriptors(params);\n\n // THEN\n expect(axios.request).toHaveBeenCalledWith(\n expect.objectContaining({\n url: \"https://metadata.ledger.com/v2/ethereum/1/safe/account/0xabcdefabcdefabcdefabcdefabcdefabcdefabcd\",\n }),\n );\n });\n\n it(\"should work with different challenges\", async () => {\n // GIVEN\n const params = {\n safeContractAddress: validsafeContractAddress,\n chainId: 1,\n challenge: \"0x123456789\",\n };\n vi.spyOn(axios, \"request\").mockResolvedValue({\n status: 200,\n data: validSafeAccountDto,\n });\n\n // WHEN\n await new HttpSafeAccountDataSource(config).getDescriptors(params);\n\n // THEN\n expect(axios.request).toHaveBeenCalledWith(\n expect.objectContaining({\n params: {\n challenge: \"0x123456789\",\n },\n }),\n );\n });\n\n it(\"should return error when response data is empty\", async () => {\n // GIVEN\n const params = {\n safeContractAddress: validsafeContractAddress,\n chainId: 1,\n challenge: \"0xabcdef\",\n };\n vi.spyOn(axios, \"request\").mockResolvedValue({\n status: 200,\n data: null,\n });\n\n // WHEN\n const result = await new HttpSafeAccountDataSource(config).getDescriptors(\n params,\n );\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpSafeAccountDataSource: unexpected empty response\",\n ),\n ),\n );\n });\n\n it(\"should return error when response data is undefined\", async () => {\n // GIVEN\n const params = {\n safeContractAddress: validsafeContractAddress,\n chainId: 1,\n challenge: \"0xabcdef\",\n };\n vi.spyOn(axios, \"request\").mockResolvedValue({\n status: 200,\n data: undefined,\n });\n\n // WHEN\n const result = await new HttpSafeAccountDataSource(config).getDescriptors(\n params,\n );\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpSafeAccountDataSource: unexpected empty response\",\n ),\n ),\n );\n });\n\n it(\"should return error when accountDescriptor is missing\", async () => {\n // GIVEN\n const params = {\n safeContractAddress: validsafeContractAddress,\n chainId: 1,\n challenge: \"0xabcdef\",\n };\n vi.spyOn(axios, \"request\").mockResolvedValue({\n status: 200,\n data: {\n signersDescriptor: validSafeAccountDto.signersDescriptor,\n },\n });\n\n // WHEN\n const result = await new HttpSafeAccountDataSource(config).getDescriptors(\n params,\n );\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpSafeAccountDataSource: invalid safe account response format\",\n ),\n ),\n );\n });\n\n it(\"should return error when signersDescriptor is missing\", async () => {\n // GIVEN\n const params = {\n safeContractAddress: validsafeContractAddress,\n chainId: 1,\n challenge: \"0xabcdef\",\n };\n vi.spyOn(axios, \"request\").mockResolvedValue({\n status: 200,\n data: {\n accountDescriptor: validSafeAccountDto.accountDescriptor,\n },\n });\n\n // WHEN\n const result = await new HttpSafeAccountDataSource(config).getDescriptors(\n params,\n );\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpSafeAccountDataSource: invalid safe account response format\",\n ),\n ),\n );\n });\n\n it(\"should return error when accountDescriptor.signedDescriptor is missing\", async () => {\n // GIVEN\n const params = {\n safeContractAddress: validsafeContractAddress,\n chainId: 1,\n challenge: \"0xabcdef\",\n };\n vi.spyOn(axios, \"request\").mockResolvedValue({\n status: 200,\n data: {\n accountDescriptor: {\n keyId: \"account-key-id\",\n keyUsage: \"account-key-usage\",\n },\n signersDescriptor: validSafeAccountDto.signersDescriptor,\n },\n });\n\n // WHEN\n const result = await new HttpSafeAccountDataSource(config).getDescriptors(\n params,\n );\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpSafeAccountDataSource: invalid safe account response format\",\n ),\n ),\n );\n });\n\n it(\"should return error when accountDescriptor.keyId is missing\", async () => {\n // GIVEN\n const params = {\n safeContractAddress: validsafeContractAddress,\n chainId: 1,\n challenge: \"0xabcdef\",\n };\n vi.spyOn(axios, \"request\").mockResolvedValue({\n status: 200,\n data: {\n accountDescriptor: {\n signedDescriptor: \"account-signed-descriptor-data\",\n keyUsage: \"account-key-usage\",\n },\n signersDescriptor: validSafeAccountDto.signersDescriptor,\n },\n });\n\n // WHEN\n const result = await new HttpSafeAccountDataSource(config).getDescriptors(\n params,\n );\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpSafeAccountDataSource: invalid safe account response format\",\n ),\n ),\n );\n });\n\n it(\"should return error when accountDescriptor.keyUsage is missing\", async () => {\n // GIVEN\n const params = {\n safeContractAddress: validsafeContractAddress,\n chainId: 1,\n challenge: \"0xabcdef\",\n };\n vi.spyOn(axios, \"request\").mockResolvedValue({\n status: 200,\n data: {\n accountDescriptor: {\n signedDescriptor: \"account-signed-descriptor-data\",\n keyId: \"account-key-id\",\n },\n signersDescriptor: validSafeAccountDto.signersDescriptor,\n },\n });\n\n // WHEN\n const result = await new HttpSafeAccountDataSource(config).getDescriptors(\n params,\n );\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpSafeAccountDataSource: invalid safe account response format\",\n ),\n ),\n );\n });\n\n it(\"should return error when signersDescriptor fields are invalid\", async () => {\n // GIVEN\n const params = {\n safeContractAddress: validsafeContractAddress,\n chainId: 1,\n challenge: \"0xabcdef\",\n };\n vi.spyOn(axios, \"request\").mockResolvedValue({\n status: 200,\n data: {\n accountDescriptor: validSafeAccountDto.accountDescriptor,\n signersDescriptor: {\n signedDescriptor: \"signers-signed-descriptor-data\",\n keyId: 123, // wrong type\n keyUsage: \"signers-key-usage\",\n },\n },\n });\n\n // WHEN\n const result = await new HttpSafeAccountDataSource(config).getDescriptors(\n params,\n );\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpSafeAccountDataSource: invalid safe account response format\",\n ),\n ),\n );\n });\n\n it(\"should return error when accountDescriptor is not an object\", async () => {\n // GIVEN\n const params = {\n safeContractAddress: validsafeContractAddress,\n chainId: 1,\n challenge: \"0xabcdef\",\n };\n vi.spyOn(axios, \"request\").mockResolvedValue({\n status: 200,\n data: {\n accountDescriptor: \"invalid-string\",\n signersDescriptor: validSafeAccountDto.signersDescriptor,\n },\n });\n\n // WHEN\n const result = await new HttpSafeAccountDataSource(config).getDescriptors(\n params,\n );\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpSafeAccountDataSource: invalid safe account response format\",\n ),\n ),\n );\n });\n\n it(\"should return error when signersDescriptor is not an object\", async () => {\n // GIVEN\n const params = {\n safeContractAddress: validsafeContractAddress,\n chainId: 1,\n challenge: \"0xabcdef\",\n };\n vi.spyOn(axios, \"request\").mockResolvedValue({\n status: 200,\n data: {\n accountDescriptor: validSafeAccountDto.accountDescriptor,\n signersDescriptor: null,\n },\n });\n\n // WHEN\n const result = await new HttpSafeAccountDataSource(config).getDescriptors(\n params,\n );\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpSafeAccountDataSource: invalid safe account response format\",\n ),\n ),\n );\n });\n\n it(\"should return error when axios request fails\", async () => {\n // GIVEN\n const params = {\n safeContractAddress: validsafeContractAddress,\n chainId: 1,\n challenge: \"0xabcdef\",\n };\n vi.spyOn(axios, \"request\").mockRejectedValue(new Error(\"Network error\"));\n\n // WHEN\n const result = await new HttpSafeAccountDataSource(config).getDescriptors(\n params,\n );\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpSafeAccountDataSource: Failed to fetch safe account descriptors\",\n ),\n ),\n );\n });\n\n it(\"should return error when axios throws an exception\", async () => {\n // GIVEN\n const params = {\n safeContractAddress: validsafeContractAddress,\n chainId: 1,\n challenge: \"0xabcdef\",\n };\n vi.spyOn(axios, \"request\").mockRejectedValue(new Error(\"timeout\"));\n\n // WHEN\n const result = await new HttpSafeAccountDataSource(config).getDescriptors(\n params,\n );\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpSafeAccountDataSource: Failed to fetch safe account descriptors\",\n ),\n ),\n );\n });\n\n it(\"should handle empty string values in descriptors\", async () => {\n // GIVEN\n const params = {\n safeContractAddress: validsafeContractAddress,\n chainId: 1,\n challenge: \"0xabcdef\",\n };\n vi.spyOn(axios, \"request\").mockResolvedValue({\n status: 200,\n data: {\n accountDescriptor: {\n signedDescriptor: \"\",\n keyId: \"\",\n keyUsage: \"\",\n },\n signersDescriptor: {\n signedDescriptor: \"\",\n keyId: \"\",\n keyUsage: \"\",\n },\n },\n });\n\n // WHEN\n const result = await new HttpSafeAccountDataSource(config).getDescriptors(\n params,\n );\n\n // THEN\n expect(result).toEqual(\n Right({\n account: {\n signedDescriptor: \"\",\n keyId: \"\",\n keyUsage: \"\",\n },\n signers: {\n signedDescriptor: \"\",\n keyId: \"\",\n keyUsage: \"\",\n },\n }),\n );\n });\n\n it(\"should correctly parse response with long descriptor values\", async () => {\n // GIVEN\n const longValue = \"a\".repeat(1000);\n const params = {\n safeContractAddress: validsafeContractAddress,\n chainId: 1,\n challenge: \"0xabcdef\",\n };\n vi.spyOn(axios, \"request\").mockResolvedValue({\n status: 200,\n data: {\n accountDescriptor: {\n signedDescriptor: longValue,\n keyId: \"account-key-id\",\n keyUsage: \"account-key-usage\",\n },\n signersDescriptor: {\n signedDescriptor: longValue,\n keyId: \"signers-key-id\",\n keyUsage: \"signers-key-usage\",\n },\n },\n });\n\n // WHEN\n const result = await new HttpSafeAccountDataSource(config).getDescriptors(\n params,\n );\n\n // THEN\n expect(result).toEqual(\n Right({\n account: {\n signedDescriptor: longValue,\n keyId: \"account-key-id\",\n keyUsage: \"account-key-usage\",\n },\n signers: {\n signedDescriptor: longValue,\n keyId: \"signers-key-id\",\n keyUsage: \"signers-key-usage\",\n },\n }),\n );\n });\n\n it(\"should use correct origin token from config\", async () => {\n // GIVEN\n const customConfig: ContextModuleConfig = {\n metadataServiceDomain: {\n url: \"https://metadata.ledger.com\",\n },\n originToken: \"custom-origin-token\",\n } as ContextModuleConfig;\n const params = {\n safeContractAddress: validsafeContractAddress,\n chainId: 1,\n challenge: \"0xabcdef\",\n };\n vi.spyOn(axios, \"request\").mockResolvedValue({\n status: 200,\n data: validSafeAccountDto,\n });\n\n // WHEN\n await new HttpSafeAccountDataSource(customConfig).getDescriptors(params);\n\n // THEN\n expect(axios.request).toHaveBeenCalledWith(\n expect.objectContaining({\n headers: expect.objectContaining({\n [LEDGER_ORIGIN_TOKEN_HEADER]: \"custom-origin-token\",\n }),\n }),\n );\n });\n\n it(\"should use correct metadata service URL from config\", async () => {\n // GIVEN\n const customConfig: ContextModuleConfig = {\n metadataServiceDomain: {\n url: \"https://custom-metadata.example.com\",\n },\n originToken: \"test-token\",\n } as ContextModuleConfig;\n const params = {\n safeContractAddress: validsafeContractAddress,\n chainId: 1,\n challenge: \"0xabcdef\",\n };\n vi.spyOn(axios, \"request\").mockResolvedValue({\n status: 200,\n data: validSafeAccountDto,\n });\n\n // WHEN\n await new HttpSafeAccountDataSource(customConfig).getDescriptors(params);\n\n // THEN\n expect(axios.request).toHaveBeenCalledWith(\n expect.objectContaining({\n url: \"https://custom-metadata.example.com/v2/ethereum/1/safe/account/0x1234567890123456789012345678901234567890\",\n }),\n );\n });\n });\n});\n"],
5
+ "mappings": "AACA,OAAOA,MAAW,QAClB,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAG5B,OAAS,6BAAAC,MAAiC,wCAC1C,OACE,gCAAAC,EACA,8BAAAC,MACK,gCACP,OAAOC,MAAa,qBAEpB,GAAG,KAAK,OAAO,EAEf,SAAS,4BAA6B,IAAM,CAC1C,MAAMC,EAA8B,CAClC,sBAAuB,CACrB,IAAK,6BACP,EACA,YAAa,mBACf,EAEMC,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B,CAC/B,CAACK,CAA0B,EAAG,qBAChC,CAAC,CACH,CAAC,CACH,CACF,CAAC,EAED,GAAG,sDAAuD,SAAY,CAEpE,MAAMQ,EAAoC,CACxC,sBAAuB,CACrB,IAAK,qCACP,EACA,YAAa,YACf,EACMH,EAAS,CACb,oBAAqBD,EACrB,QAAS,EACT,UAAW,UACb,EACA,GAAG,MAAMT,EAAO,SAAS,EAAE,kBAAkB,CAC3C,OAAQ,IACR,KAAMQ,CACR,CAAC,EAGD,MAAM,IAAIL,EAA0BU,CAAY,EAAE,eAAeH,CAAM,EAGvE,OAAOV,EAAM,OAAO,EAAE,qBACpB,OAAO,iBAAiB,CACtB,IAAK,2GACP,CAAC,CACH,CACF,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["axios", "Left", "Right", "HttpSafeAccountDataSource", "LEDGER_CLIENT_VERSION_HEADER", "LEDGER_ORIGIN_TOKEN_HEADER", "PACKAGE", "config", "validSafeAccountDto", "validsafeContractAddress", "params", "result", "longValue", "customConfig"]
7
+ }
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=SafeAccountDataSource.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=SafeAccountDto.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ import{ContainerModule as r}from"inversify";import{HttpSafeAccountDataSource as t}from"../../safe/data/HttpSafeAccountDataSource";import{SafeAddressLoader as a}from"../../safe/domain/SafeAddressLoader";import{safeTypes as e}from"./safeTypes";const p=()=>new r(({bind:o})=>{o(e.SafeAddressDataSource).to(t),o(e.SafeAddressLoader).to(a)});export{p as safeModuleFactory};
2
+ //# sourceMappingURL=safeModuleFactory.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/safe/di/safeModuleFactory.ts"],
4
+ "sourcesContent": ["import { ContainerModule } from \"inversify\";\n\nimport { HttpSafeAccountDataSource } from \"@/safe/data/HttpSafeAccountDataSource\";\nimport { SafeAddressLoader } from \"@/safe/domain/SafeAddressLoader\";\n\nimport { safeTypes } from \"./safeTypes\";\n\nexport const safeModuleFactory = () =>\n new ContainerModule(({ bind }) => {\n bind(safeTypes.SafeAddressDataSource).to(HttpSafeAccountDataSource);\n bind(safeTypes.SafeAddressLoader).to(SafeAddressLoader);\n });\n"],
5
+ "mappings": "AAAA,OAAS,mBAAAA,MAAuB,YAEhC,OAAS,6BAAAC,MAAiC,wCAC1C,OAAS,qBAAAC,MAAyB,kCAElC,OAAS,aAAAC,MAAiB,cAEnB,MAAMC,EAAoB,IAC/B,IAAIJ,EAAgB,CAAC,CAAE,KAAAK,CAAK,IAAM,CAChCA,EAAKF,EAAU,qBAAqB,EAAE,GAAGF,CAAyB,EAClEI,EAAKF,EAAU,iBAAiB,EAAE,GAAGD,CAAiB,CACxD,CAAC",
6
+ "names": ["ContainerModule", "HttpSafeAccountDataSource", "SafeAddressLoader", "safeTypes", "safeModuleFactory", "bind"]
7
+ }
@@ -0,0 +1,2 @@
1
+ import{describe as e,it as o}from"vitest";import{safeModuleFactory as d}from"./safeModuleFactory";e("safeModuleFactory",()=>{o("should be defined",()=>{expect(d).toBeDefined()})});
2
+ //# sourceMappingURL=safeModuleFactory.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/safe/di/safeModuleFactory.test.ts"],
4
+ "sourcesContent": ["import { describe, it } from \"vitest\";\n\nimport { safeModuleFactory } from \"./safeModuleFactory\";\n\ndescribe(\"safeModuleFactory\", () => {\n it(\"should be defined\", () => {\n expect(safeModuleFactory).toBeDefined();\n });\n});\n"],
5
+ "mappings": "AAAA,OAAS,YAAAA,EAAU,MAAAC,MAAU,SAE7B,OAAS,qBAAAC,MAAyB,sBAElCF,EAAS,oBAAqB,IAAM,CAClCC,EAAG,oBAAqB,IAAM,CAC5B,OAAOC,CAAiB,EAAE,YAAY,CACxC,CAAC,CACH,CAAC",
6
+ "names": ["describe", "it", "safeModuleFactory"]
7
+ }
@@ -0,0 +1,2 @@
1
+ const e={SafeAddressDataSource:Symbol.for("SafeAddressDataSource"),SafeAddressLoader:Symbol.for("SafeAddressLoader")};export{e as safeTypes};
2
+ //# sourceMappingURL=safeTypes.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/safe/di/safeTypes.ts"],
4
+ "sourcesContent": ["export const safeTypes = {\n SafeAddressDataSource: Symbol.for(\"SafeAddressDataSource\"),\n SafeAddressLoader: Symbol.for(\"SafeAddressLoader\"),\n};\n"],
5
+ "mappings": "AAAO,MAAMA,EAAY,CACvB,sBAAuB,OAAO,IAAI,uBAAuB,EACzD,kBAAmB,OAAO,IAAI,mBAAmB,CACnD",
6
+ "names": ["safeTypes"]
7
+ }
@@ -0,0 +1,2 @@
1
+ var y=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var l=(i,e,a,t)=>{for(var r=t>1?void 0:t?C(e,a):e,c=i.length-1,o;c>=0;c--)(o=i[c])&&(r=(t?o(e,a,r):o(r))||r);return t&&r&&y(e,a,r),r},f=(i,e)=>(a,t)=>e(a,t,i);import{isHexaString as S}from"@ledgerhq/device-management-kit";import{inject as p,injectable as g}from"inversify";import{pkiTypes as m}from"../../pki/di/pkiTypes";import{safeTypes as x}from"../../safe/di/safeTypes";import{ClearSignContextType as n}from"../../shared/model/ClearSignContext";const I=[n.SAFE,n.SIGNER];let s=class{constructor(e,a){this._dataSource=e;this._certificateLoader=a}canHandle(e,a){return a.every(t=>I.includes(t))&&typeof e=="object"&&e!==null&&"safeContractAddress"in e&&S(e.safeContractAddress)&&e.safeContractAddress!=="0x"&&"chainId"in e&&typeof e.chainId=="number"&&"deviceModelId"in e&&e.deviceModelId!==void 0&&"challenge"in e&&typeof e.challenge=="string"&&e.challenge.length>0}async load({safeContractAddress:e,chainId:a,deviceModelId:t,challenge:r}){return(await this._dataSource.getDescriptors({safeContractAddress:e,chainId:a,challenge:r})).caseOf({Left:o=>Promise.resolve([{type:n.ERROR,error:o}]),Right:async({account:o,signers:d})=>[{type:n.SAFE,payload:o.signedDescriptor,certificate:await this._certificateLoader.loadCertificate({keyId:o.keyId,keyUsage:o.keyUsage,targetDevice:t})},{type:n.SIGNER,payload:d.signedDescriptor,certificate:await this._certificateLoader.loadCertificate({keyId:d.keyId,keyUsage:d.keyUsage,targetDevice:t})}]})}};s=l([g(),f(0,p(x.SafeAddressDataSource)),f(1,p(m.PkiCertificateLoader))],s);export{s as SafeAddressLoader};
2
+ //# sourceMappingURL=SafeAddressLoader.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/safe/domain/SafeAddressLoader.ts"],
4
+ "sourcesContent": ["import {\n DeviceModelId,\n HexaString,\n isHexaString,\n} from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport type {\n GetSafeAccountResponse,\n SafeAccountDataSource,\n} from \"@/safe/data/SafeAccountDataSource\";\nimport { safeTypes } from \"@/safe/di/safeTypes\";\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\n\nexport type SafeAddressContextInput = {\n safeContractAddress: HexaString;\n chainId: number;\n deviceModelId: DeviceModelId;\n challenge: string;\n};\n\nconst SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.SAFE,\n ClearSignContextType.SIGNER,\n];\n\n@injectable()\nexport class SafeAddressLoader\n implements ContextLoader<SafeAddressContextInput>\n{\n constructor(\n @inject(safeTypes.SafeAddressDataSource)\n private readonly _dataSource: SafeAccountDataSource,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n ) {}\n\n canHandle(\n input: unknown,\n expectedTypes: ClearSignContextType[],\n ): input is SafeAddressContextInput {\n return (\n expectedTypes.every((type) => SUPPORTED_TYPES.includes(type)) &&\n typeof input === \"object\" &&\n input !== null &&\n \"safeContractAddress\" in input &&\n isHexaString(input.safeContractAddress) &&\n input.safeContractAddress !== \"0x\" &&\n \"chainId\" in input &&\n typeof input.chainId === \"number\" &&\n \"deviceModelId\" in input &&\n input.deviceModelId !== undefined &&\n \"challenge\" in input &&\n typeof input.challenge === \"string\" &&\n input.challenge.length > 0\n );\n }\n\n async load({\n safeContractAddress,\n chainId,\n deviceModelId,\n challenge,\n }: SafeAddressContextInput): Promise<ClearSignContext[]> {\n const descriptors = await this._dataSource.getDescriptors({\n safeContractAddress,\n chainId,\n challenge,\n });\n\n return descriptors.caseOf({\n Left: (error): Promise<ClearSignContext[]> =>\n Promise.resolve([\n {\n type: ClearSignContextType.ERROR,\n error,\n },\n ]),\n Right: async ({\n account,\n signers,\n }: GetSafeAccountResponse): Promise<ClearSignContext[]> => [\n {\n type: ClearSignContextType.SAFE,\n payload: account.signedDescriptor,\n certificate: await this._certificateLoader.loadCertificate({\n keyId: account.keyId,\n keyUsage: account.keyUsage,\n targetDevice: deviceModelId,\n }),\n },\n {\n type: ClearSignContextType.SIGNER,\n payload: signers.signedDescriptor,\n certificate: await this._certificateLoader.loadCertificate({\n keyId: signers.keyId,\n keyUsage: signers.keyUsage,\n targetDevice: deviceModelId,\n }),\n },\n ],\n });\n }\n}\n"],
5
+ "mappings": "iOAAA,OAGE,gBAAAA,MACK,kCACP,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YAEnC,OAAS,YAAAC,MAAgB,oBAMzB,OAAS,aAAAC,MAAiB,sBAE1B,OAEE,wBAAAC,MACK,kCASP,MAAMC,EAA0C,CAC9CC,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6
+ "names": ["isHexaString", "inject", "injectable", "pkiTypes", "safeTypes", "ClearSignContextType", "SUPPORTED_TYPES", "ClearSignContextType", "SafeAddressLoader", "_dataSource", "_certificateLoader", "input", "expectedTypes", "type", "isHexaString", "safeContractAddress", "chainId", "deviceModelId", "challenge", "error", "account", "signers", "__decorateClass", "injectable", "__decorateParam", "inject", "safeTypes", "pkiTypes"]
7
+ }
@@ -0,0 +1,2 @@
1
+ import{DeviceModelId as o}from"@ledgerhq/device-management-kit";import{Left as u,Right as r}from"purify-ts";import{SafeAddressLoader as f}from"../../safe/domain/SafeAddressLoader";import{ClearSignContextType as e}from"../../shared/model/ClearSignContext";describe("SafeAddressLoader",()=>{const n={getDescriptors:vi.fn()},d={loadCertificate:vi.fn()},s=new f(n,d),l={keyUsageNumber:1,payload:new Uint8Array([1,2,3])},i={account:{signedDescriptor:"safe-descriptor-payload",keyId:"safe-key-id",keyUsage:"safe-key-usage"},signers:{signedDescriptor:"signers-descriptor-payload",keyId:"signers-key-id",keyUsage:"signers-key-usage"}};beforeEach(()=>{vi.clearAllMocks(),vi.spyOn(d,"loadCertificate").mockResolvedValue(l)}),describe("canHandle function",()=>{const t={safeContractAddress:"0x1234567890123456789012345678901234567890",chainId:1,deviceModelId:o.FLEX,challenge:"0xabcdef"};it("should return true for valid input with SAFE and SIGNER types",()=>{expect(s.canHandle(t,[e.SAFE,e.SIGNER])).toBe(!0)}),it("should return true when expected types are subset of SAFE and SIGNER",()=>{expect(s.canHandle(t,[e.SAFE])).toBe(!0),expect(s.canHandle(t,[e.SIGNER])).toBe(!0)}),it("should return false when expected types include unsupported types",()=>{expect(s.canHandle(t,[e.TOKEN])).toBe(!1),expect(s.canHandle(t,[e.NFT])).toBe(!1)}),it("should return false when expected types include other types besides SAFE and SIGNER",()=>{expect(s.canHandle(t,[e.SAFE,e.SIGNER,e.TOKEN])).toBe(!1)}),it.each([[null,"null input"],[void 0,"undefined input"],[{},"empty object"],["string","string input"],[123,"number input"],[[],"array input"]])("should return false for %s",(a,c)=>{expect(s.canHandle(a,[e.SAFE,e.SIGNER])).toBe(!1)}),it.each([[{...t,safeContractAddress:void 0},"missing safeContractAddress"],[{...t,chainId:void 0},"missing chainId"],[{...t,deviceModelId:void 0},"missing deviceModelId"],[{...t,challenge:void 0},"missing challenge"]])("should return false for %s",(a,c)=>{expect(s.canHandle(a,[e.SAFE,e.SIGNER])).toBe(!1)}),it.each([[{...t,safeContractAddress:"invalid-hex"},"invalid safeContractAddress hex"],[{...t,safeContractAddress:"0x"},"empty safeContractAddress (0x)"],[{...t,safeContractAddress:"not-hex"},"non-hex safeContractAddress"],[{...t,safeContractAddress:123},"number safeContractAddress"]])("should return false for %s",(a,c)=>{expect(s.canHandle(a,[e.SAFE,e.SIGNER])).toBe(!1)}),it.each([[{...t,chainId:"1"},"string chainId"],[{...t,chainId:null},"null chainId"],[{...t,chainId:void 0},"undefined chainId"]])("should return false for %s",(a,c)=>{expect(s.canHandle(a,[e.SAFE,e.SIGNER])).toBe(!1)}),it.each([[{...t,challenge:""},"empty challenge string"],[{...t,challenge:123},"number challenge"],[{...t,challenge:null},"null challenge"]])("should return false for %s",(a,c)=>{expect(s.canHandle(a,[e.SAFE,e.SIGNER])).toBe(!1)}),it("should return true for different device models",()=>{expect(s.canHandle({...t,deviceModelId:o.NANO_S},[e.SAFE,e.SIGNER])).toBe(!0),expect(s.canHandle({...t,deviceModelId:o.NANO_SP},[e.SAFE,e.SIGNER])).toBe(!0),expect(s.canHandle({...t,deviceModelId:o.NANO_X},[e.SAFE,e.SIGNER])).toBe(!0),expect(s.canHandle({...t,deviceModelId:o.STAX},[e.SAFE,e.SIGNER])).toBe(!0),expect(s.canHandle({...t,deviceModelId:o.FLEX},[e.SAFE,e.SIGNER])).toBe(!0)}),it("should return true for different chain IDs",()=>{expect(s.canHandle({...t,chainId:1},[e.SAFE,e.SIGNER])).toBe(!0),expect(s.canHandle({...t,chainId:137},[e.SAFE,e.SIGNER])).toBe(!0),expect(s.canHandle({...t,chainId:10},[e.SAFE,e.SIGNER])).toBe(!0)})}),describe("load function",()=>{const t={safeContractAddress:"0x1234567890123456789012345678901234567890",chainId:1,deviceModelId:o.FLEX,challenge:"0xabcdef"};it("should return SAFE and SIGNER contexts with certificates",async()=>{vi.spyOn(n,"getDescriptors").mockResolvedValue(r(i));const a=await s.load(t);expect(n.getDescriptors).toHaveBeenCalledWith({safeContractAddress:"0x1234567890123456789012345678901234567890",chainId:1,challenge:"0xabcdef"}),expect(d.loadCertificate).toHaveBeenCalledTimes(2),expect(d.loadCertificate).toHaveBeenNthCalledWith(1,{keyId:"safe-key-id",keyUsage:"safe-key-usage",targetDevice:o.FLEX}),expect(d.loadCertificate).toHaveBeenNthCalledWith(2,{keyId:"signers-key-id",keyUsage:"signers-key-usage",targetDevice:o.FLEX}),expect(a).toEqual([{type:e.SAFE,payload:"safe-descriptor-payload",certificate:l},{type:e.SIGNER,payload:"signers-descriptor-payload",certificate:l}])}),it("should return SAFE and SIGNER contexts without certificates when loadCertificate returns undefined",async()=>{vi.spyOn(n,"getDescriptors").mockResolvedValue(r(i)),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const a=await s.load(t);expect(a).toEqual([{type:e.SAFE,payload:"safe-descriptor-payload",certificate:void 0},{type:e.SIGNER,payload:"signers-descriptor-payload",certificate:void 0}])}),it("should return ERROR context when data source returns Left",async()=>{const a=new Error("Failed to get safe account descriptors");vi.spyOn(n,"getDescriptors").mockResolvedValue(u(a));const c=await s.load(t);expect(c).toEqual([{type:e.ERROR,error:a}]),expect(d.loadCertificate).not.toHaveBeenCalled()}),it("should work with different device models",async()=>{const a={...t,deviceModelId:o.NANO_S};vi.spyOn(n,"getDescriptors").mockResolvedValue(r(i));const c=await s.load(a);expect(d.loadCertificate).toHaveBeenCalledWith(expect.objectContaining({targetDevice:o.NANO_S})),expect(c).toHaveLength(2),expect(c[0]?.type).toBe(e.SAFE),expect(c[1]?.type).toBe(e.SIGNER)}),it("should work with different chain IDs",async()=>{const a={...t,chainId:137};vi.spyOn(n,"getDescriptors").mockResolvedValue(r(i)),await s.load(a),expect(n.getDescriptors).toHaveBeenCalledWith(expect.objectContaining({chainId:137}))}),it("should work with different safe addresses",async()=>{const a={...t,safeContractAddress:"0xabcdefabcdefabcdefabcdefabcdefabcdefabcd"};vi.spyOn(n,"getDescriptors").mockResolvedValue(r(i)),await s.load(a),expect(n.getDescriptors).toHaveBeenCalledWith(expect.objectContaining({safeContractAddress:"0xabcdefabcdefabcdefabcdefabcdefabcdefabcd"}))}),it("should handle different certificate data for account and signers",async()=>{const a={keyUsageNumber:1,payload:new Uint8Array([1,2,3])},c={keyUsageNumber:2,payload:new Uint8Array([4,5,6])};vi.spyOn(n,"getDescriptors").mockResolvedValue(r(i)),vi.spyOn(d,"loadCertificate").mockResolvedValueOnce(a).mockResolvedValueOnce(c);const p=await s.load(t);expect(p).toEqual([{type:e.SAFE,payload:"safe-descriptor-payload",certificate:a},{type:e.SIGNER,payload:"signers-descriptor-payload",certificate:c}])}),it("should handle empty descriptor payloads",async()=>{const a={account:{signedDescriptor:"",keyId:"key-id",keyUsage:"key-usage"},signers:{signedDescriptor:"",keyId:"key-id",keyUsage:"key-usage"}};vi.spyOn(n,"getDescriptors").mockResolvedValue(r(a));const c=await s.load(t);expect(c).toEqual([{type:e.SAFE,payload:"",certificate:l},{type:e.SIGNER,payload:"",certificate:l}])}),it("should handle long descriptor payloads",async()=>{const a="a".repeat(1e3),c={account:{signedDescriptor:a,keyId:"key-id",keyUsage:"key-usage"},signers:{signedDescriptor:a,keyId:"key-id",keyUsage:"key-usage"}};vi.spyOn(n,"getDescriptors").mockResolvedValue(r(c));const p=await s.load(t);expect(p[0].payload).toBe(a),expect(p[1].payload).toBe(a)}),it("should handle data source errors gracefully",async()=>{const a=new Error("Network error");vi.spyOn(n,"getDescriptors").mockResolvedValue(u(a));const c=await s.load(t);expect(c).toEqual([{type:e.ERROR,error:new Error("Network error")}])})})});
2
+ //# sourceMappingURL=SafeAddressLoader.test.js.map