@ledgerhq/context-module 0.0.0-ledger-button-20250808181454 → 0.0.0-ledger-button-20250821162931

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 (78) hide show
  1. package/lib/cjs/package.json +1 -1
  2. package/lib/cjs/src/ContextModuleBuilder.js +1 -1
  3. package/lib/cjs/src/ContextModuleBuilder.js.map +3 -3
  4. package/lib/cjs/src/ContextModuleBuilder.test.js +1 -1
  5. package/lib/cjs/src/ContextModuleBuilder.test.js.map +2 -2
  6. package/lib/cjs/src/DefaultContextModule.test.js +1 -1
  7. package/lib/cjs/src/DefaultContextModule.test.js.map +2 -2
  8. package/lib/cjs/src/config/model/ContextModuleConfig.js +1 -1
  9. package/lib/cjs/src/config/model/ContextModuleConfig.js.map +1 -1
  10. package/lib/cjs/src/nft/data/HttpNftDataSource.js +1 -1
  11. package/lib/cjs/src/nft/data/HttpNftDataSource.js.map +2 -2
  12. package/lib/cjs/src/nft/data/HttpNftDataSource.test.js +1 -1
  13. package/lib/cjs/src/nft/data/HttpNftDataSource.test.js.map +2 -2
  14. package/lib/cjs/src/shared/model/ClearSignContext.js +1 -1
  15. package/lib/cjs/src/shared/model/ClearSignContext.js.map +2 -2
  16. package/lib/cjs/src/solana/data/HttpSolanaOwnerInfoDataSource.js +1 -1
  17. package/lib/cjs/src/solana/data/HttpSolanaOwnerInfoDataSource.js.map +2 -2
  18. package/lib/cjs/src/solana/data/HttpSolanaOwnerInfoDataSource.test.js +1 -1
  19. package/lib/cjs/src/solana/data/HttpSolanaOwnerInfoDataSource.test.js.map +2 -2
  20. package/lib/cjs/src/transaction/data/HttpProxyDataSource.js +1 -1
  21. package/lib/cjs/src/transaction/data/HttpProxyDataSource.js.map +3 -3
  22. package/lib/cjs/src/transaction/data/HttpProxyDataSource.test.js +1 -1
  23. package/lib/cjs/src/transaction/data/HttpProxyDataSource.test.js.map +2 -2
  24. package/lib/cjs/src/transaction/data/dto/ProxyDelegateCallDto.js +1 -1
  25. package/lib/cjs/src/transaction/data/dto/ProxyDelegateCallDto.js.map +1 -1
  26. package/lib/cjs/src/transaction/domain/TransactionContextLoader.js +1 -1
  27. package/lib/cjs/src/transaction/domain/TransactionContextLoader.js.map +3 -3
  28. package/lib/cjs/src/transaction/domain/TransactionContextLoader.test.js +1 -1
  29. package/lib/cjs/src/transaction/domain/TransactionContextLoader.test.js.map +3 -3
  30. package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.js +1 -1
  31. package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.js.map +2 -2
  32. package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.test.js +1 -1
  33. package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.test.js.map +2 -2
  34. package/lib/cjs/src/uniswap/domain/UniswapContextLoader.js +1 -1
  35. package/lib/cjs/src/uniswap/domain/UniswapContextLoader.js.map +2 -2
  36. package/lib/esm/package.json +1 -1
  37. package/lib/esm/src/ContextModuleBuilder.js +1 -1
  38. package/lib/esm/src/ContextModuleBuilder.js.map +3 -3
  39. package/lib/esm/src/ContextModuleBuilder.test.js +1 -1
  40. package/lib/esm/src/ContextModuleBuilder.test.js.map +2 -2
  41. package/lib/esm/src/DefaultContextModule.test.js +1 -1
  42. package/lib/esm/src/DefaultContextModule.test.js.map +2 -2
  43. package/lib/esm/src/nft/data/HttpNftDataSource.js +1 -1
  44. package/lib/esm/src/nft/data/HttpNftDataSource.js.map +2 -2
  45. package/lib/esm/src/nft/data/HttpNftDataSource.test.js +1 -1
  46. package/lib/esm/src/nft/data/HttpNftDataSource.test.js.map +2 -2
  47. package/lib/esm/src/shared/model/ClearSignContext.js +1 -1
  48. package/lib/esm/src/shared/model/ClearSignContext.js.map +2 -2
  49. package/lib/esm/src/solana/data/HttpSolanaOwnerInfoDataSource.js +1 -1
  50. package/lib/esm/src/solana/data/HttpSolanaOwnerInfoDataSource.js.map +2 -2
  51. package/lib/esm/src/solana/data/HttpSolanaOwnerInfoDataSource.test.js +1 -1
  52. package/lib/esm/src/solana/data/HttpSolanaOwnerInfoDataSource.test.js.map +2 -2
  53. package/lib/esm/src/transaction/data/HttpProxyDataSource.js +1 -1
  54. package/lib/esm/src/transaction/data/HttpProxyDataSource.js.map +3 -3
  55. package/lib/esm/src/transaction/data/HttpProxyDataSource.test.js +1 -1
  56. package/lib/esm/src/transaction/data/HttpProxyDataSource.test.js.map +2 -2
  57. package/lib/esm/src/transaction/domain/TransactionContextLoader.js +1 -1
  58. package/lib/esm/src/transaction/domain/TransactionContextLoader.js.map +3 -3
  59. package/lib/esm/src/transaction/domain/TransactionContextLoader.test.js +1 -1
  60. package/lib/esm/src/transaction/domain/TransactionContextLoader.test.js.map +3 -3
  61. package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.js +1 -1
  62. package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.js.map +2 -2
  63. package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.test.js +1 -1
  64. package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.test.js.map +2 -2
  65. package/lib/esm/src/uniswap/domain/UniswapContextLoader.js +1 -1
  66. package/lib/esm/src/uniswap/domain/UniswapContextLoader.js.map +2 -2
  67. package/lib/types/src/config/model/ContextModuleConfig.d.ts +1 -1
  68. package/lib/types/src/config/model/ContextModuleConfig.d.ts.map +1 -1
  69. package/lib/types/src/shared/model/ClearSignContext.d.ts +1 -0
  70. package/lib/types/src/shared/model/ClearSignContext.d.ts.map +1 -1
  71. package/lib/types/src/transaction/data/HttpProxyDataSource.d.ts +2 -1
  72. package/lib/types/src/transaction/data/HttpProxyDataSource.d.ts.map +1 -1
  73. package/lib/types/src/transaction/data/dto/ProxyDelegateCallDto.d.ts +1 -1
  74. package/lib/types/src/transaction/data/dto/ProxyDelegateCallDto.d.ts.map +1 -1
  75. package/lib/types/src/transaction/domain/TransactionContextLoader.d.ts +5 -1
  76. package/lib/types/src/transaction/domain/TransactionContextLoader.d.ts.map +1 -1
  77. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  78. package/package.json +3 -3
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/solana/data/HttpSolanaOwnerInfoDataSource.ts"],
4
- "sourcesContent": ["import { hexaStringToBuffer } from \"@ledgerhq/device-management-kit\";\nimport axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport type { ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport {\n SolanaSPLOwnerInfo,\n type SolanaTransactionContext,\n} from \"@/solana/domain/solanaContextTypes\";\nimport PACKAGE from \"@root/package.json\";\n\nimport {\n HttpSolanaOwnerInfoDataSourceResult,\n SolanaDataSource,\n} from \"./SolanaDataSource\";\n\n@injectable()\nexport class HttpSolanaOwnerInfoDataSource implements SolanaDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n ) {\n if (!this.config.originToken) {\n throw new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: origin token is required\",\n );\n }\n }\n\n private isSolanaSPLOwnerInfo(data: {\n tokenAccount?: unknown;\n owner?: unknown;\n contract?: unknown;\n signedDescriptor?: unknown;\n }): data is SolanaSPLOwnerInfo {\n if (typeof data !== \"object\" || data === null) return false;\n return (\n typeof data.tokenAccount === \"string\" &&\n typeof data.owner === \"string\" &&\n typeof data.contract === \"string\" &&\n typeof data.signedDescriptor === \"string\"\n );\n }\n\n async fetchAddressMetadata(\n tokenAddress: string,\n challenge: string,\n ): Promise<Either<Error, SolanaSPLOwnerInfo>> {\n return await axios\n .request<SolanaSPLOwnerInfo>({\n method: \"GET\",\n url: `${this.config.metadataService.url}/solana/owner/${tokenAddress}?challenge=${challenge}`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n })\n .then((res) => {\n if (!this.isSolanaSPLOwnerInfo(res.data))\n return Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid fetchAddressMetadata response shape\",\n ),\n );\n return Right(res.data);\n })\n .catch(() =>\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to fetch address metadata\",\n ),\n ),\n );\n }\n\n async computeAddressMetadata(\n address: string,\n mintAddress: string,\n challenge: string,\n ): Promise<Either<Error, SolanaSPLOwnerInfo>> {\n return await axios\n .request<SolanaSPLOwnerInfo>({\n method: \"GET\",\n url: `${this.config.metadataService.url}/solana/computed-token-account/${address}/${mintAddress}?challenge=${challenge}`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n \"X-Ledger-Client-Origin\": this.config.originToken,\n },\n })\n .then((res) => {\n if (!this.isSolanaSPLOwnerInfo(res.data))\n return Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid computeAddressMetadata response shape\",\n ),\n );\n return Right(res.data);\n })\n .catch(() =>\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to compute address metadata\",\n ),\n ),\n );\n }\n\n async getOwnerInfo(\n context: SolanaTransactionContext,\n ): Promise<Either<Error, HttpSolanaOwnerInfoDataSourceResult>> {\n const { tokenAddress, challenge, createATA } = context;\n\n if (!challenge) {\n return Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: challenge is required\",\n ),\n );\n }\n\n let ownerInfoResult: Either<Error, SolanaSPLOwnerInfo>;\n\n if (tokenAddress) {\n ownerInfoResult = await this.fetchAddressMetadata(\n tokenAddress,\n challenge,\n );\n } else if (createATA?.address && createATA?.mintAddress) {\n ownerInfoResult = await this.computeAddressMetadata(\n createATA.address,\n createATA.mintAddress,\n challenge,\n );\n } else {\n return Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: either tokenAddress or valid createATA must be provided\",\n ),\n );\n }\n\n return ownerInfoResult.chain((ownerInfo) => {\n const descriptor = hexaStringToBuffer(ownerInfo.signedDescriptor);\n if (!descriptor) {\n return Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid base64 descriptor received\",\n ),\n );\n }\n return Right({\n descriptor,\n tokenAccount: ownerInfo.tokenAccount,\n owner: ownerInfo.owner,\n contract: ownerInfo.contract,\n });\n });\n }\n}\n"],
5
- "mappings": "iOAAA,OAAS,sBAAAA,MAA0B,kCACnC,OAAOC,MAAW,QAClB,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YACnC,OAAiB,QAAAC,EAAM,SAAAC,MAAa,YAEpC,OAAS,eAAAC,MAAmB,0BAE5B,OACE,gCAAAC,EACA,8BAAAC,MACK,gCAKP,OAAOC,MAAa,qBAQb,IAAMC,EAAN,KAAgE,CACrE,YAC+CC,EAC7C,CAD6C,YAAAA,EAE7C,GAAI,CAAC,KAAK,OAAO,YACf,MAAM,IAAI,MACR,2EACF,CAEJ,CAEQ,qBAAqBC,EAKE,CAC7B,OAAI,OAAOA,GAAS,UAAYA,IAAS,KAAa,GAEpD,OAAOA,EAAK,cAAiB,UAC7B,OAAOA,EAAK,OAAU,UACtB,OAAOA,EAAK,UAAa,UACzB,OAAOA,EAAK,kBAAqB,QAErC,CAEA,MAAM,qBACJC,EACAC,EAC4C,CAC5C,OAAO,MAAMC,EACV,QAA4B,CAC3B,OAAQ,MACR,IAAK,GAAG,KAAK,OAAO,gBAAgB,GAAG,iBAAiBF,CAAY,cAAcC,CAAS,GAC3F,QAAS,CACP,CAACE,CAA4B,EAAG,kBAAkBC,EAAQ,OAAO,GACjE,CAACC,CAA0B,EAAG,KAAK,OAAO,WAC5C,CACF,CAAC,EACA,KAAMC,GACA,KAAK,qBAAqBA,EAA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M,IAFjBxB",
4
+ "sourcesContent": ["import { hexaStringToBuffer } from \"@ledgerhq/device-management-kit\";\nimport axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport type { ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport {\n SolanaSPLOwnerInfo,\n type SolanaTransactionContext,\n} from \"@/solana/domain/solanaContextTypes\";\nimport PACKAGE from \"@root/package.json\";\n\nimport {\n HttpSolanaOwnerInfoDataSourceResult,\n SolanaDataSource,\n} from \"./SolanaDataSource\";\n\n@injectable()\nexport class HttpSolanaOwnerInfoDataSource implements SolanaDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n ) {\n if (!this.config.originToken) {\n throw new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: origin token is required\",\n );\n }\n }\n\n private isSolanaSPLOwnerInfo(data: {\n tokenAccount?: unknown;\n owner?: unknown;\n contract?: unknown;\n signedDescriptor?: unknown;\n }): data is SolanaSPLOwnerInfo {\n if (typeof data !== \"object\" || data === null) return false;\n return (\n typeof data.tokenAccount === \"string\" &&\n typeof data.owner === \"string\" &&\n typeof data.contract === \"string\" &&\n typeof data.signedDescriptor === \"string\"\n );\n }\n\n async fetchAddressMetadata(\n tokenAddress: string,\n challenge: string,\n ): Promise<Either<Error, SolanaSPLOwnerInfo>> {\n return await axios\n .request<SolanaSPLOwnerInfo>({\n method: \"GET\",\n url: `${this.config.metadataServiceDomain.url}/v2/solana/owner/${tokenAddress}?challenge=${challenge}`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n })\n .then((res) => {\n if (!this.isSolanaSPLOwnerInfo(res.data))\n return Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid fetchAddressMetadata response shape\",\n ),\n );\n return Right(res.data);\n })\n .catch(() =>\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to fetch address metadata\",\n ),\n ),\n );\n }\n\n async computeAddressMetadata(\n address: string,\n mintAddress: string,\n challenge: string,\n ): Promise<Either<Error, SolanaSPLOwnerInfo>> {\n return await axios\n .request<SolanaSPLOwnerInfo>({\n method: \"GET\",\n url: `${this.config.metadataServiceDomain.url}/v2/solana/computed-token-account/${address}/${mintAddress}?challenge=${challenge}`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n \"X-Ledger-Client-Origin\": this.config.originToken,\n },\n })\n .then((res) => {\n if (!this.isSolanaSPLOwnerInfo(res.data))\n return Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid computeAddressMetadata response shape\",\n ),\n );\n return Right(res.data);\n })\n .catch(() =>\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to compute address metadata\",\n ),\n ),\n );\n }\n\n async getOwnerInfo(\n context: SolanaTransactionContext,\n ): Promise<Either<Error, HttpSolanaOwnerInfoDataSourceResult>> {\n const { tokenAddress, challenge, createATA } = context;\n\n if (!challenge) {\n return Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: challenge is required\",\n ),\n );\n }\n\n let ownerInfoResult: Either<Error, SolanaSPLOwnerInfo>;\n\n if (tokenAddress) {\n ownerInfoResult = await this.fetchAddressMetadata(\n tokenAddress,\n challenge,\n );\n } else if (createATA?.address && createATA?.mintAddress) {\n ownerInfoResult = await this.computeAddressMetadata(\n createATA.address,\n createATA.mintAddress,\n challenge,\n );\n } else {\n return Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: either tokenAddress or valid createATA must be provided\",\n ),\n );\n }\n\n return ownerInfoResult.chain((ownerInfo) => {\n const descriptor = hexaStringToBuffer(ownerInfo.signedDescriptor);\n if (!descriptor) {\n return Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid base64 descriptor received\",\n ),\n );\n }\n return Right({\n descriptor,\n tokenAccount: ownerInfo.tokenAccount,\n owner: ownerInfo.owner,\n contract: ownerInfo.contract,\n });\n });\n }\n}\n"],
5
+ "mappings": "iOAAA,OAAS,sBAAAA,MAA0B,kCACnC,OAAOC,MAAW,QAClB,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YACnC,OAAiB,QAAAC,EAAM,SAAAC,MAAa,YAEpC,OAAS,eAAAC,MAAmB,0BAE5B,OACE,gCAAAC,EACA,8BAAAC,MACK,gCAKP,OAAOC,MAAa,qBAQb,IAAMC,EAAN,KAAgE,CACrE,YAC+CC,EAC7C,CAD6C,YAAAA,EAE7C,GAAI,CAAC,KAAK,OAAO,YACf,MAAM,IAAI,MACR,2EACF,CAEJ,CAEQ,qBAAqBC,EAKE,CAC7B,OAAI,OAAOA,GAAS,UAAYA,IAAS,KAAa,GAEpD,OAAOA,EAAK,cAAiB,UAC7B,OAAOA,EAAK,OAAU,UACtB,OAAOA,EAAK,UAAa,UACzB,OAAOA,EAAK,kBAAqB,QAErC,CAEA,MAAM,qBACJC,EACAC,EAC4C,CAC5C,OAAO,MAAMC,EACV,QAA4B,CAC3B,OAAQ,MACR,IAAK,GAAG,KAAK,OAAO,sBAAsB,GAAG,oBAAoBF,CAAY,cAAcC,CAAS,GACpG,QAAS,CACP,CAACE,CAA4B,EAAG,kBAAkBC,EAAQ,OAAO,GACjE,CAACC,CAA0B,EAAG,KAAK,OAAO,WAC5C,CACF,CAAC,EACA,KAAMC,GACA,KAAK,qBAAqBA,EAAI,IAAI,EAMhCC,EAAMD,EAAI,IAAI,EALZE,EACL,IAAI,MACF,8FACF,CACF,CAEH,EACA,MAAM,IACLA,EACE,IAAI,MACF,mFACF,CACF,CACF,CACJ,CAEA,MAAM,uBACJC,EACAC,EACAT,EAC4C,CAC5C,OAAO,MAAMC,EACV,QAA4B,CAC3B,OAAQ,MACR,IAAK,GAAG,KAAK,OAAO,sBAAsB,GAAG,qCAAqCO,CAAO,IAAIC,CAAW,cAAcT,CAAS,GAC/H,QAAS,CACP,CAACE,CAA4B,EAAG,kBAAkBC,EAAQ,OAAO,GACjE,yBAA0B,KAAK,OAAO,WACxC,CACF,CAAC,EACA,KAAME,GACA,KAAK,qBAAqBA,EAAI,IAAI,EAMhCC,EAAMD,EAAI,IAAI,EALZE,EACL,IAAI,MACF,gGACF,CACF,CAEH,EACA,MAAM,IACLA,EACE,IAAI,MACF,qFACF,CACF,CACF,CACJ,CAEA,MAAM,aACJG,EAC6D,CAC7D,KAAM,CAAE,aAAAX,EAAc,UAAAC,EAAW,UAAAW,CAAU,EAAID,EAE/C,GAAI,CAACV,EACH,OAAOO,EACL,IAAI,MACF,wEACF,CACF,EAGF,IAAIK,EAEJ,GAAIb,EACFa,EAAkB,MAAM,KAAK,qBAC3Bb,EACAC,CACF,UACSW,GAAW,SAAWA,GAAW,YAC1CC,EAAkB,MAAM,KAAK,uBAC3BD,EAAU,QACVA,EAAU,YACVX,CACF,MAEA,QAAOO,EACL,IAAI,MACF,0GACF,CACF,EAGF,OAAOK,EAAgB,MAAOC,GAAc,CAC1C,MAAMC,EAAaC,EAAmBF,EAAU,gBAAgB,EAChE,OAAKC,EAOER,EAAM,CACX,WAAAQ,EACA,aAAcD,EAAU,aACxB,MAAOA,EAAU,MACjB,SAAUA,EAAU,QACtB,CAAC,EAXQN,EACL,IAAI,MACF,qFACF,CACF,CAQJ,CAAC,CACH,CACF,EA5IaX,EAANoB,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAY,MAAM,IAFjBxB",
6
6
  "names": ["hexaStringToBuffer", "axios", "inject", "injectable", "Left", "Right", "configTypes", "LEDGER_CLIENT_VERSION_HEADER", "LEDGER_ORIGIN_TOKEN_HEADER", "PACKAGE", "HttpSolanaOwnerInfoDataSource", "config", "data", "tokenAddress", "challenge", "axios", "LEDGER_CLIENT_VERSION_HEADER", "PACKAGE", "LEDGER_ORIGIN_TOKEN_HEADER", "res", "Right", "Left", "address", "mintAddress", "context", "createATA", "ownerInfoResult", "ownerInfo", "descriptor", "hexaStringToBuffer", "__decorateClass", "injectable", "__decorateParam", "inject", "configTypes"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{DeviceModelId as r,hexaStringToBuffer as l}from"@ledgerhq/device-management-kit";import s from"axios";import{Left as c}from"purify-ts";import{LEDGER_CLIENT_VERSION_HEADER as u}from"../../shared/constant/HttpHeaders";import{HttpSolanaOwnerInfoDataSource as n}from"../../solana/data/HttpSolanaOwnerInfoDataSource";import m from"../../../package.json";vi.mock("axios");function f(o){const d=new TextEncoder().encode(o);return Array.from(d).map(e=>e.toString(16).padStart(2,"0")).join("")}describe("HttpSolanaOwnerInfoDataSource",()=>{const o={metadataService:{url:"https://some.doma.in"},originToken:"mock-origin-token"},i=f("mock-descriptor"),d={tokenAccount:"token-account",owner:"owner-address",contract:"contract-address",signedDescriptor:i};beforeEach(()=>{vi.resetAllMocks()}),it("should fetch address metadata via tokenAddress",async()=>{const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0};vi.spyOn(s,"request").mockResolvedValueOnce({data:d});const t=await new n(o).getOwnerInfo(e);expect(t.isRight()).toBe(!0),expect(t.extract()).toEqual({descriptor:l(i),tokenAccount:"token-account",owner:"owner-address",contract:"contract-address"})}),it("should compute address when tokenAddress is not provided",async()=>{const e={deviceModelId:r.FLEX,tokenAddress:void 0,challenge:"random",createATA:{address:"some-address",mintAddress:"some-mint"}};vi.spyOn(s,"request").mockResolvedValueOnce({data:d});const t=await new n(o).getOwnerInfo(e);expect(t.isRight()).toBe(!0),expect(t.extract().tokenAccount).toBe("token-account")}),it("should return an error if both tokenAddress and createATA are missing or invalid",async()=>{const e={deviceModelId:r.FLEX,tokenAddress:void 0,challenge:"random",createATA:void 0},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(c(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: either tokenAddress or valid createATA must be provided")))}),it("should return an error if challenge is missing",async()=>{const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:void 0,createATA:void 0},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(c(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: challenge is required")))}),it("should return an error if the descriptor is not valid base64",async()=>{vi.spyOn(s,"request").mockResolvedValueOnce({data:{...d,signedDescriptor:"!!!not-valid-base64!!!"}});const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(c(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid base64 descriptor received")))}),it("should return an error if the metadata request fails",async()=>{vi.spyOn(s,"request").mockRejectedValueOnce(new Error("Network error"));const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(c(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to fetch address metadata")))}),it("should return an error if axios request return wrong shape for fetchAddressMetadata",async()=>{vi.spyOn(s,"request").mockResolvedValueOnce({data:{wrong:"field"}});const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(c(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid fetchAddressMetadata response shape")))}),it("should return an error if axios request return wrong shape for computeAddressMetadata",async()=>{vi.spyOn(s,"request").mockResolvedValueOnce({data:{wrong:"field"}});const e={deviceModelId:r.FLEX,tokenAddress:void 0,challenge:"random",createATA:{address:"some-address",mintAddress:"some-mint"}},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(c(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid computeAddressMetadata response shape")))}),it("should throw if originToken is missing",()=>{expect(()=>{new n({...o,originToken:void 0})}).toThrow("[ContextModule] - HttpSolanaOwnerInfoDataSource: origin token is required")}),it("should call axios with correct headers",async()=>{const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},a=vi.spyOn(s,"request").mockResolvedValueOnce({data:d});await new n(o).getOwnerInfo(e),expect(a).toHaveBeenCalledWith(expect.objectContaining({headers:{[u]:`context-module/${m.version}`,"X-Ledger-Client-Origin":o.originToken}}))})});
1
+ import{DeviceModelId as r,hexaStringToBuffer as l}from"@ledgerhq/device-management-kit";import s from"axios";import{Left as c}from"purify-ts";import{LEDGER_CLIENT_VERSION_HEADER as u}from"../../shared/constant/HttpHeaders";import{HttpSolanaOwnerInfoDataSource as n}from"../../solana/data/HttpSolanaOwnerInfoDataSource";import m from"../../../package.json";vi.mock("axios");function f(o){const d=new TextEncoder().encode(o);return Array.from(d).map(e=>e.toString(16).padStart(2,"0")).join("")}describe("HttpSolanaOwnerInfoDataSource",()=>{const o={metadataServiceDomain:{url:"https://some.doma.in"},originToken:"mock-origin-token"},i=f("mock-descriptor"),d={tokenAccount:"token-account",owner:"owner-address",contract:"contract-address",signedDescriptor:i};beforeEach(()=>{vi.resetAllMocks()}),it("should fetch address metadata via tokenAddress",async()=>{const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0};vi.spyOn(s,"request").mockResolvedValueOnce({data:d});const t=await new n(o).getOwnerInfo(e);expect(t.isRight()).toBe(!0),expect(t.extract()).toEqual({descriptor:l(i),tokenAccount:"token-account",owner:"owner-address",contract:"contract-address"})}),it("should compute address when tokenAddress is not provided",async()=>{const e={deviceModelId:r.FLEX,tokenAddress:void 0,challenge:"random",createATA:{address:"some-address",mintAddress:"some-mint"}};vi.spyOn(s,"request").mockResolvedValueOnce({data:d});const t=await new n(o).getOwnerInfo(e);expect(t.isRight()).toBe(!0),expect(t.extract().tokenAccount).toBe("token-account")}),it("should return an error if both tokenAddress and createATA are missing or invalid",async()=>{const e={deviceModelId:r.FLEX,tokenAddress:void 0,challenge:"random",createATA:void 0},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(c(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: either tokenAddress or valid createATA must be provided")))}),it("should return an error if challenge is missing",async()=>{const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:void 0,createATA:void 0},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(c(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: challenge is required")))}),it("should return an error if the descriptor is not valid base64",async()=>{vi.spyOn(s,"request").mockResolvedValueOnce({data:{...d,signedDescriptor:"!!!not-valid-base64!!!"}});const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(c(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid base64 descriptor received")))}),it("should return an error if the metadata request fails",async()=>{vi.spyOn(s,"request").mockRejectedValueOnce(new Error("Network error"));const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(c(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to fetch address metadata")))}),it("should return an error if axios request return wrong shape for fetchAddressMetadata",async()=>{vi.spyOn(s,"request").mockResolvedValueOnce({data:{wrong:"field"}});const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(c(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid fetchAddressMetadata response shape")))}),it("should return an error if axios request return wrong shape for computeAddressMetadata",async()=>{vi.spyOn(s,"request").mockResolvedValueOnce({data:{wrong:"field"}});const e={deviceModelId:r.FLEX,tokenAddress:void 0,challenge:"random",createATA:{address:"some-address",mintAddress:"some-mint"}},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(c(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid computeAddressMetadata response shape")))}),it("should throw if originToken is missing",()=>{expect(()=>{new n({...o,originToken:void 0})}).toThrow("[ContextModule] - HttpSolanaOwnerInfoDataSource: origin token is required")}),it("should call axios with correct headers",async()=>{const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},a=vi.spyOn(s,"request").mockResolvedValueOnce({data:d});await new n(o).getOwnerInfo(e),expect(a).toHaveBeenCalledWith(expect.objectContaining({headers:{[u]:`context-module/${m.version}`,"X-Ledger-Client-Origin":o.originToken}}))})});
2
2
  //# sourceMappingURL=HttpSolanaOwnerInfoDataSource.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/solana/data/HttpSolanaOwnerInfoDataSource.test.ts"],
4
- "sourcesContent": ["/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n DeviceModelId,\n hexaStringToBuffer,\n} from \"@ledgerhq/device-management-kit\";\nimport axios from \"axios\";\nimport { Left } from \"purify-ts\";\n\nimport type { ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { LEDGER_CLIENT_VERSION_HEADER } from \"@/shared/constant/HttpHeaders\";\nimport { HttpSolanaOwnerInfoDataSource } from \"@/solana/data/HttpSolanaOwnerInfoDataSource\";\nimport type { SolanaTransactionContext } from \"@/solana/domain/solanaContextTypes\";\nimport PACKAGE from \"@root/package.json\";\n\nvi.mock(\"axios\");\n\nfunction stringToHex(str: string): string {\n const encoder = new TextEncoder();\n const bytes = encoder.encode(str); // Uint8Array\n return Array.from(bytes)\n .map((byte) => byte.toString(16).padStart(2, \"0\"))\n .join(\"\");\n}\n\ndescribe(\"HttpSolanaOwnerInfoDataSource\", () => {\n const config = {\n metadataService: { url: \"https://some.doma.in\" },\n originToken: \"mock-origin-token\",\n } as ContextModuleConfig;\n\n const signedDescriptorHex = stringToHex(\"mock-descriptor\");\n const responseData = {\n tokenAccount: \"token-account\",\n owner: \"owner-address\",\n contract: \"contract-address\",\n signedDescriptor: signedDescriptorHex,\n };\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n it(\"should fetch address metadata via tokenAddress\", async () => {\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({ data: responseData });\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result.isRight()).toBe(true);\n expect(result.extract()).toEqual({\n descriptor: hexaStringToBuffer(signedDescriptorHex),\n tokenAccount: \"token-account\",\n owner: \"owner-address\",\n contract: \"contract-address\",\n });\n });\n\n it(\"should compute address when tokenAddress is not provided\", async () => {\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: undefined,\n challenge: \"random\",\n createATA: {\n address: \"some-address\",\n mintAddress: \"some-mint\",\n },\n };\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({ data: responseData });\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result.isRight()).toBe(true);\n expect((result.extract() as any).tokenAccount).toBe(\"token-account\");\n });\n\n it(\"should return an error if both tokenAddress and createATA are missing or invalid\", async () => {\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: undefined,\n challenge: \"random\",\n createATA: undefined,\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: either tokenAddress or valid createATA must be provided\",\n ),\n ),\n );\n });\n\n it(\"should return an error if challenge is missing\", async () => {\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: undefined,\n createATA: undefined,\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: challenge is required\",\n ),\n ),\n );\n });\n\n it(\"should return an error if the descriptor is not valid base64\", async () => {\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({\n data: { ...responseData, signedDescriptor: \"!!!not-valid-base64!!!\" },\n });\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid base64 descriptor received\",\n ),\n ),\n );\n });\n\n it(\"should return an error if the metadata request fails\", async () => {\n vi.spyOn(axios, \"request\").mockRejectedValueOnce(\n new Error(\"Network error\"),\n );\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to fetch address metadata\",\n ),\n ),\n );\n });\n\n it(\"should return an error if axios request return wrong shape for fetchAddressMetadata\", async () => {\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({\n data: { wrong: \"field\" },\n });\n\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid fetchAddressMetadata response shape\",\n ),\n ),\n );\n });\n\n it(\"should return an error if axios request return wrong shape for computeAddressMetadata\", async () => {\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({\n data: { wrong: \"field\" },\n });\n\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: undefined,\n challenge: \"random\",\n createATA: {\n address: \"some-address\",\n mintAddress: \"some-mint\",\n },\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid computeAddressMetadata response shape\",\n ),\n ),\n );\n });\n\n it(\"should throw if originToken is missing\", () => {\n expect(() => {\n new HttpSolanaOwnerInfoDataSource({\n ...config,\n originToken: undefined,\n } as any);\n }).toThrow(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: origin token is required\",\n );\n });\n\n it(\"should call axios with correct headers\", async () => {\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n const spy = vi\n .spyOn(axios, \"request\")\n .mockResolvedValueOnce({ data: responseData });\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n await dataSource.getOwnerInfo(context);\n\n expect(spy).toHaveBeenCalledWith(\n expect.objectContaining({\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n \"X-Ledger-Client-Origin\": config.originToken,\n },\n }),\n );\n });\n});\n"],
5
- "mappings": "AAEA,OACE,iBAAAA,EACA,sBAAAC,MACK,kCACP,OAAOC,MAAW,QAClB,OAAS,QAAAC,MAAY,YAGrB,OAAS,gCAAAC,MAAoC,gCAC7C,OAAS,iCAAAC,MAAqC,8CAE9C,OAAOC,MAAa,qBAEpB,GAAG,KAAK,OAAO,EAEf,SAASC,EAAYC,EAAqB,CAExC,MAAM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AC,EAED,MAAMY,EAAoC,CACxC,cAAed,EAAc,KAC7B,aAAc,aACd,UAAW,SACX,UAAW,MACb,EAGMe,EAAS,MADI,IAAIV,EAA8BM,CAAM,EAC3B,aAAaG,CAAO,EAEpD,OAAOC,CAAM,EAAE,QACbZ,EACE,IAAI,MACF,8FACF,CACF,CACF,CACF,CAAC,EAED,GAAG,wFAAyF,SAAY,CACtG,GAAG,MAAMD,EAAO,SAAS,EAAE,sBAAsB,CAC/C,KAAM,CAAE,MAAO,OAAQ,CACzB,CAAC,EAED,MAAMY,EAAoC,CACxC,cAAed,EAAc,KAC7B,aAAc,OACd,UAAW,SACX,UAAW,CACT,QAAS,eACT,YAAa,WACf,CACF,EAGMe,EAAS,MADI,IAAIV,EAA8BM,CAAM,EAC3B,aAAaG,CAAO,EAEpD,OAAOC,CAAM,EAAE,QACbZ,EACE,IAAI,MACF,gGACF,CACF,CACF,CACF,CAAC,EAED,GAAG,yCAA0C,IAAM,CACjD,OAAO,IAAM,CACX,IAAIE,EAA8B,CAChC,GAAGM,EACH,YAAa,MACf,CAAQ,CACV,CAAC,EAAE,QACD,2EACF,CACF,CAAC,EAED,GAAG,yCAA0C,SAAY,CACvD,MAAMG,EAAoC,CACxC,cAAed,EAAc,KAC7B,aAAc,aACd,UAAW,SACX,UAAW,MACb,EACMgB,EAAM,GACT,MAAMd,EAAO,SAAS,EACtB,sBAAsB,CAAE,KAAMW,CAAa,CAAC,EAG/C,MADmB,IAAIR,EAA8BM,CAAM,EAC1C,aAAaG,CAAO,EAErC,OAAOE,CAAG,EAAE,qBACV,OAAO,iBAAiB,CACtB,QAAS,CACP,CAACZ,CAA4B,EAAG,kBAAkBE,EAAQ,OAAO,GACjE,yBAA0BK,EAAO,WACnC,CACF,CAAC,CACH,CACF,CAAC,CACH,CAAC",
4
+ "sourcesContent": ["/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n DeviceModelId,\n hexaStringToBuffer,\n} from \"@ledgerhq/device-management-kit\";\nimport axios from \"axios\";\nimport { Left } from \"purify-ts\";\n\nimport type { ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { LEDGER_CLIENT_VERSION_HEADER } from \"@/shared/constant/HttpHeaders\";\nimport { HttpSolanaOwnerInfoDataSource } from \"@/solana/data/HttpSolanaOwnerInfoDataSource\";\nimport type { SolanaTransactionContext } from \"@/solana/domain/solanaContextTypes\";\nimport PACKAGE from \"@root/package.json\";\n\nvi.mock(\"axios\");\n\nfunction stringToHex(str: string): string {\n const encoder = new TextEncoder();\n const bytes = encoder.encode(str); // Uint8Array\n return Array.from(bytes)\n .map((byte) => byte.toString(16).padStart(2, \"0\"))\n .join(\"\");\n}\n\ndescribe(\"HttpSolanaOwnerInfoDataSource\", () => {\n const config = {\n metadataServiceDomain: { url: \"https://some.doma.in\" },\n originToken: \"mock-origin-token\",\n } as ContextModuleConfig;\n\n const signedDescriptorHex = stringToHex(\"mock-descriptor\");\n const responseData = {\n tokenAccount: \"token-account\",\n owner: \"owner-address\",\n contract: \"contract-address\",\n signedDescriptor: signedDescriptorHex,\n };\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n it(\"should fetch address metadata via tokenAddress\", async () => {\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({ data: responseData });\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result.isRight()).toBe(true);\n expect(result.extract()).toEqual({\n descriptor: hexaStringToBuffer(signedDescriptorHex),\n tokenAccount: \"token-account\",\n owner: \"owner-address\",\n contract: \"contract-address\",\n });\n });\n\n it(\"should compute address when tokenAddress is not provided\", async () => {\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: undefined,\n challenge: \"random\",\n createATA: {\n address: \"some-address\",\n mintAddress: \"some-mint\",\n },\n };\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({ data: responseData });\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result.isRight()).toBe(true);\n expect((result.extract() as any).tokenAccount).toBe(\"token-account\");\n });\n\n it(\"should return an error if both tokenAddress and createATA are missing or invalid\", async () => {\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: undefined,\n challenge: \"random\",\n createATA: undefined,\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: either tokenAddress or valid createATA must be provided\",\n ),\n ),\n );\n });\n\n it(\"should return an error if challenge is missing\", async () => {\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: undefined,\n createATA: undefined,\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: challenge is required\",\n ),\n ),\n );\n });\n\n it(\"should return an error if the descriptor is not valid base64\", async () => {\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({\n data: { ...responseData, signedDescriptor: \"!!!not-valid-base64!!!\" },\n });\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid base64 descriptor received\",\n ),\n ),\n );\n });\n\n it(\"should return an error if the metadata request fails\", async () => {\n vi.spyOn(axios, \"request\").mockRejectedValueOnce(\n new Error(\"Network error\"),\n );\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to fetch address metadata\",\n ),\n ),\n );\n });\n\n it(\"should return an error if axios request return wrong shape for fetchAddressMetadata\", async () => {\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({\n data: { wrong: \"field\" },\n });\n\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid fetchAddressMetadata response shape\",\n ),\n ),\n );\n });\n\n it(\"should return an error if axios request return wrong shape for computeAddressMetadata\", async () => {\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({\n data: { wrong: \"field\" },\n });\n\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: undefined,\n challenge: \"random\",\n createATA: {\n address: \"some-address\",\n mintAddress: \"some-mint\",\n },\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid computeAddressMetadata response shape\",\n ),\n ),\n );\n });\n\n it(\"should throw if originToken is missing\", () => {\n expect(() => {\n new HttpSolanaOwnerInfoDataSource({\n ...config,\n originToken: undefined,\n } as any);\n }).toThrow(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: origin token is required\",\n );\n });\n\n it(\"should call axios with correct headers\", async () => {\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n const spy = vi\n .spyOn(axios, \"request\")\n .mockResolvedValueOnce({ data: responseData });\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n await dataSource.getOwnerInfo(context);\n\n expect(spy).toHaveBeenCalledWith(\n expect.objectContaining({\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n \"X-Ledger-Client-Origin\": config.originToken,\n },\n }),\n );\n });\n});\n"],
5
+ "mappings": "AAEA,OACE,iBAAAA,EACA,sBAAAC,MACK,kCACP,OAAOC,MAAW,QAClB,OAAS,QAAAC,MAAY,YAGrB,OAAS,gCAAAC,MAAoC,gCAC7C,OAAS,iCAAAC,MAAqC,8CAE9C,OAAOC,MAAa,qBAEpB,GAAG,KAAK,OAAO,EAEf,SAASC,EAAYC,EAAqB,CAExC,MAAMC,EADU,IAAI,YAAY,EACV,OAAOD,CAAG,EAChC,OAAO,MAAM,KAAKC,CAAK,EACpB,IAAKC,GAASA,EAAK,SAAS,EAAE,EAAE,SAAS,EAAG,GAAG,CAAC,EAChD,KAAK,EAAE,CACZ,CAEA,SAAS,gCAAiC,IAAM,CAC9C,MAAMC,EAAS,CACb,sBAAuB,CAAE,IAAK,sBAAuB,EACrD,YAAa,mBACf,EAEMC,EAAsBL,EAAY,iBAAiB,EACnDM,EAAe,CACnB,aAAc,gBACd,MAAO,gBACP,SAAU,mBACV,iBAAkBD,CACpB,EAEA,WAAW,IAAM,CACf,GAAG,cAAc,CACnB,CAAC,EAED,GAAG,iDAAkD,SAAY,CAC/D,MAAME,EAAoC,CACxC,cAAed,EAAc,KAC7B,aAAc,aACd,UAAW,SACX,UAAW,MACb,EACA,GAAG,MAAME,EAAO,SAAS,EAAE,sBAAsB,CAAE,KAAMW,CAAa,CAAC,EAGvE,MAAME,EAAS,MADI,IAAIV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AAM,CACX,IAAIE,EAA8B,CAChC,GAAGM,EACH,YAAa,MACf,CAAQ,CACV,CAAC,EAAE,QACD,2EACF,CACF,CAAC,EAED,GAAG,yCAA0C,SAAY,CACvD,MAAMG,EAAoC,CACxC,cAAed,EAAc,KAC7B,aAAc,aACd,UAAW,SACX,UAAW,MACb,EACMgB,EAAM,GACT,MAAMd,EAAO,SAAS,EACtB,sBAAsB,CAAE,KAAMW,CAAa,CAAC,EAG/C,MADmB,IAAIR,EAA8BM,CAAM,EAC1C,aAAaG,CAAO,EAErC,OAAOE,CAAG,EAAE,qBACV,OAAO,iBAAiB,CACtB,QAAS,CACP,CAACZ,CAA4B,EAAG,kBAAkBE,EAAQ,OAAO,GACjE,yBAA0BK,EAAO,WACnC,CACF,CAAC,CACH,CACF,CAAC,CACH,CAAC",
6
6
  "names": ["DeviceModelId", "hexaStringToBuffer", "axios", "Left", "LEDGER_CLIENT_VERSION_HEADER", "HttpSolanaOwnerInfoDataSource", "PACKAGE", "stringToHex", "str", "bytes", "byte", "config", "signedDescriptorHex", "responseData", "context", "result", "spy"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var P=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var l=(a,e,o,r)=>{for(var t=r>1?void 0:r?f(e,o):e,i=a.length-1,d;i>=0;i--)(d=a[i])&&(t=(r?d(e,o,t):d(t))||t);return r&&t&&P(e,o,t),t},m=(a,e)=>(o,r)=>e(o,r,a);import p from"axios";import{inject as D,injectable as u}from"inversify";import{Left as n,Right as y}from"purify-ts";import{configTypes as C}from"../../config/di/configTypes";import{LEDGER_CLIENT_VERSION_HEADER as x,LEDGER_ORIGIN_TOKEN_HEADER as g}from"../../shared/constant/HttpHeaders";import c from"../../../package.json";let s=class{constructor(e){this.config=e}async getProxyDelegateCall({proxyAddress:e,calldata:o,chainId:r}){let t;try{t=(await p.request({method:"POST",url:`${this.config.metadataService.url}/ethereum/${r}/contract/proxy/delegate`,headers:{[x]:`context-module/${c.version}`,[g]:this.config.originToken},data:{proxy:e,data:o}})).data}catch{return n(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy"))}return t?this.isProxyDelegateCallDto(t)?y(t):n(new Error(`[ContextModule] HttpProxyDataSource: Invalid proxy delegate call response format for proxy ${e} on chain ${r}`)):n(new Error(`[ContextModule] HttpProxyDataSource: No data received for proxy ${e} on chain ${r}`))}async getProxyImplementationAddress({proxyAddress:e,chainId:o}){let r;try{r=(await p.request({method:"GET",url:`${this.config.metadataService.url}/ethereum/${o}/contract/proxy/${e}`,headers:{[x]:`context-module/${c.version}`,[g]:this.config.originToken}})).data}catch{return n(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch implementation address"))}return r?this.isProxyImplementationAddressDto(r)?y({implementationAddress:r.implementationAddress}):n(new Error(`[ContextModule] HttpProxyDataSource: Invalid proxy implementation address response format for proxy ${e} on chain ${o}`)):n(new Error(`[ContextModule] HttpProxyDataSource: No data received for proxy ${e} on chain ${o}`))}isProxyDelegateCallDto(e){return typeof e=="object"&&e!==null&&"delegateAddresses"in e&&"signedDescriptor"in e&&Array.isArray(e.delegateAddresses)&&e.delegateAddresses.every(o=>typeof o=="string")&&typeof e.signedDescriptor=="string"}isProxyImplementationAddressDto(e){return typeof e=="object"&&e!==null&&"proxyAddress"in e&&"implementationAddress"in e&&"standard"in e&&typeof e.proxyAddress=="string"&&typeof e.implementationAddress=="string"&&typeof e.standard=="string"&&e.standard.length>0}};s=l([u(),m(0,D(C.Config))],s);export{s as HttpProxyDataSource};
1
+ var P=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var l=(i,e,t,r)=>{for(var o=r>1?void 0:r?f(e,t):e,n=i.length-1,s;n>=0;n--)(s=i[n])&&(o=(r?s(e,t,o):s(o))||o);return r&&o&&P(e,t,o),o},m=(i,e)=>(t,r)=>e(t,r,i);import p from"axios";import{inject as D,injectable as u}from"inversify";import{Left as a,Right as y}from"purify-ts";import{configTypes as E}from"../../config/di/configTypes";import{LEDGER_CLIENT_VERSION_HEADER as x,LEDGER_ORIGIN_TOKEN_HEADER as c}from"../../shared/constant/HttpHeaders";import g from"../../../package.json";let d=class{constructor(e){this.config=e}async getProxyDelegateCall({proxyAddress:e,calldata:t,chainId:r,challenge:o}){let n;try{n=(await p.request({method:"POST",url:`${this.config.metadataServiceDomain.url}/v1/ethereum/${r}/contract/proxy/delegate`,headers:{[x]:`context-module/${g.version}`,[c]:this.config.originToken},data:{proxy:e,data:t,challenge:o}})).data}catch{return a(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy"))}return n?this.isProxyDelegateCallDto(n)?y({delegateAddresses:n.addresses,signedDescriptor:n.signedDescriptor}):a(new Error(`[ContextModule] HttpProxyDataSource: Invalid proxy delegate call response format for proxy ${e} on chain ${r}`)):a(new Error(`[ContextModule] HttpProxyDataSource: No data received for proxy ${e} on chain ${r}`))}async getProxyImplementationAddress({proxyAddress:e,chainId:t}){let r;try{r=(await p.request({method:"GET",url:`${this.config.metadataServiceDomain.url}/v1/ethereum/${t}/contract/proxy/${e}`,headers:{[x]:`context-module/${g.version}`,[c]:this.config.originToken}})).data}catch{return a(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch implementation address"))}return r?this.isProxyImplementationAddressDto(r)?y({implementationAddress:r.implementationAddress}):a(new Error(`[ContextModule] HttpProxyDataSource: Invalid proxy implementation address response format for proxy ${e} on chain ${t}`)):a(new Error(`[ContextModule] HttpProxyDataSource: No data received for proxy ${e} on chain ${t}`))}isProxyDelegateCallDto(e){return typeof e=="object"&&e!==null&&"addresses"in e&&"signedDescriptor"in e&&Array.isArray(e.addresses)&&e.addresses.every(t=>typeof t=="string")&&typeof e.signedDescriptor=="string"}isProxyImplementationAddressDto(e){return typeof e=="object"&&e!==null&&"proxyAddress"in e&&"implementationAddress"in e&&"standard"in e&&typeof e.proxyAddress=="string"&&typeof e.implementationAddress=="string"&&typeof e.standard=="string"&&e.standard.length>0}};d=l([u(),m(0,D(E.Config))],d);export{d as HttpProxyDataSource};
2
2
  //# sourceMappingURL=HttpProxyDataSource.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/transaction/data/HttpProxyDataSource.ts"],
4
- "sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport { type ProxyDelegateCall } from \"@/transaction/model/ProxyDelegateCall\";\nimport { type ProxyImplementationAddress } from \"@/transaction/model/ProxyImplementationAddress\";\nimport PACKAGE from \"@root/package.json\";\n\nimport { type ProxyDelegateCallDto } from \"./dto/ProxyDelegateCallDto\";\nimport { type ProxyImplementationAddressDto } from \"./dto/ProxyImplementationAddressDto\";\n\nexport type GetProxyDelegateCallParam = {\n proxyAddress: string;\n calldata: string;\n chainId: number;\n};\n\nexport type GetProxyImplementationAddressParam = {\n proxyAddress: string;\n chainId: number;\n};\n\nexport interface ProxyDataSource {\n getProxyDelegateCall(\n params: GetProxyDelegateCallParam,\n ): Promise<Either<Error, ProxyDelegateCall>>;\n getProxyImplementationAddress(\n params: GetProxyImplementationAddressParam,\n ): Promise<Either<Error, ProxyImplementationAddress>>;\n}\n\n@injectable()\nexport class HttpProxyDataSource implements ProxyDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n ) {}\n\n public async getProxyDelegateCall({\n proxyAddress,\n calldata,\n chainId,\n }: GetProxyDelegateCallParam): Promise<Either<Error, ProxyDelegateCall>> {\n let dto: ProxyDelegateCallDto | undefined;\n try {\n const response = await axios.request<ProxyDelegateCallDto>({\n method: \"POST\",\n url: `${this.config.metadataService.url}/ethereum/${chainId}/contract/proxy/delegate`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n data: {\n proxy: proxyAddress,\n data: calldata,\n },\n });\n dto = response.data;\n } catch (_error) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy`,\n ),\n );\n }\n\n if (!dto) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: No data received for proxy ${proxyAddress} on chain ${chainId}`,\n ),\n );\n }\n\n if (!this.isProxyDelegateCallDto(dto)) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: Invalid proxy delegate call response format for proxy ${proxyAddress} on chain ${chainId}`,\n ),\n );\n }\n\n return Right(dto as ProxyDelegateCall);\n }\n\n public async getProxyImplementationAddress({\n proxyAddress,\n chainId,\n }: GetProxyImplementationAddressParam): Promise<\n Either<Error, ProxyImplementationAddress>\n > {\n let dto: ProxyImplementationAddressDto | undefined;\n try {\n const response = await axios.request<ProxyImplementationAddressDto>({\n method: \"GET\",\n url: `${this.config.metadataService.url}/ethereum/${chainId}/contract/proxy/${proxyAddress}`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n dto = response.data;\n } catch (_error) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: Failed to fetch implementation address`,\n ),\n );\n }\n\n if (!dto) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: No data received for proxy ${proxyAddress} on chain ${chainId}`,\n ),\n );\n }\n\n if (!this.isProxyImplementationAddressDto(dto)) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: Invalid proxy implementation address response format for proxy ${proxyAddress} on chain ${chainId}`,\n ),\n );\n }\n\n return Right({ implementationAddress: dto.implementationAddress });\n }\n\n /**\n * Type guard to validate ProxyDelegateCallDto\n */\n private isProxyDelegateCallDto(\n value: unknown,\n ): value is ProxyDelegateCallDto {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"delegateAddresses\" in value &&\n \"signedDescriptor\" in value &&\n Array.isArray(value.delegateAddresses) &&\n value.delegateAddresses.every((address) => typeof address === \"string\") &&\n typeof value.signedDescriptor === \"string\"\n );\n }\n\n /**\n * Type guard to validate ProxyImplementationAddressDto\n */\n private isProxyImplementationAddressDto(\n value: unknown,\n ): value is ProxyImplementationAddressDto {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"proxyAddress\" in value &&\n \"implementationAddress\" in value &&\n \"standard\" in value &&\n typeof value.proxyAddress === \"string\" &&\n typeof value.implementationAddress === \"string\" &&\n typeof value.standard === \"string\" &&\n value.standard.length > 0\n );\n }\n}\n"],
5
- "mappings": "iOAAA,OAAOA,MAAW,QAClB,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YACnC,OAAiB,QAAAC,EAAM,SAAAC,MAAa,YAEpC,OAAS,eAAAC,MAAmB,0BAE5B,OACE,gCAAAC,EACA,8BAAAC,MACK,gCAGP,OAAOC,MAAa,qBA0Bb,IAAMC,EAAN,KAAqD,CAC1D,YAC+CC,EAC7C,CAD6C,YAAAA,CAC5C,CAEH,MAAa,qBAAqB,CAChC,aAAAC,EACA,SAAAC,EACA,QAAAC,CACF,EAAyE,CACvE,IAAIC,EACJ,GAAI,CAaFA,GAZiB,MAAMC,EAAM,QAA8B,CACzD,OAAQ,OACR,IAAK,GAAG,KAAK,OAAO,gBAAgB,GAAG,aAAaF,CAAO,2BAC3D,QAAS,CACP,CAACG,CAA4B,EAAG,kBAAkBC,EAAQ,OAAO,GACjE,CAACC,CAA0B,EAAG,KAAK,OAAO,WAC5C,EACA,KAAM,CACJ,MAAOP,EACP,KAAMC,CACR,CACF,CAAC,GACc,IACjB,MAAiB,CACf,OAAOO,EACL,IAAI,MACF,qEACF,CACF,CACF,CAEA,OAAKL,EAQA,KAAK,uBAAuBA,CAAG,EAQ7BM,EAAMN,CAAwB,EAP5BK,EACL,IAAI,MAC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- "names": ["axios", "inject", "injectable", "Left", "Right", "configTypes", "LEDGER_CLIENT_VERSION_HEADER", "LEDGER_ORIGIN_TOKEN_HEADER", "PACKAGE", "HttpProxyDataSource", "config", "proxyAddress", "calldata", "chainId", "dto", "axios", "LEDGER_CLIENT_VERSION_HEADER", "PACKAGE", "LEDGER_ORIGIN_TOKEN_HEADER", "Left", "Right", "value", "address", "__decorateClass", "injectable", "__decorateParam", "inject", "configTypes"]
4
+ "sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport { type ProxyDelegateCall } from \"@/transaction/model/ProxyDelegateCall\";\nimport { type ProxyImplementationAddress } from \"@/transaction/model/ProxyImplementationAddress\";\nimport PACKAGE from \"@root/package.json\";\n\nimport { type ProxyDelegateCallDto } from \"./dto/ProxyDelegateCallDto\";\nimport { type ProxyImplementationAddressDto } from \"./dto/ProxyImplementationAddressDto\";\n\nexport type GetProxyDelegateCallParam = {\n proxyAddress: string;\n calldata: string;\n chainId: number;\n challenge: string;\n};\n\nexport type GetProxyImplementationAddressParam = {\n proxyAddress: string;\n chainId: number;\n};\n\nexport interface ProxyDataSource {\n getProxyDelegateCall(\n params: GetProxyDelegateCallParam,\n ): Promise<Either<Error, ProxyDelegateCall>>;\n getProxyImplementationAddress(\n params: GetProxyImplementationAddressParam,\n ): Promise<Either<Error, ProxyImplementationAddress>>;\n}\n\n@injectable()\nexport class HttpProxyDataSource implements ProxyDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n ) {}\n\n public async getProxyDelegateCall({\n proxyAddress,\n calldata,\n chainId,\n challenge,\n }: GetProxyDelegateCallParam): Promise<Either<Error, ProxyDelegateCall>> {\n let dto: ProxyDelegateCallDto | undefined;\n try {\n const response = await axios.request<ProxyDelegateCallDto>({\n method: \"POST\",\n url: `${this.config.metadataServiceDomain.url}/v1/ethereum/${chainId}/contract/proxy/delegate`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n data: {\n proxy: proxyAddress,\n data: calldata,\n challenge,\n },\n });\n dto = response.data;\n } catch (_error) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy`,\n ),\n );\n }\n\n if (!dto) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: No data received for proxy ${proxyAddress} on chain ${chainId}`,\n ),\n );\n }\n\n if (!this.isProxyDelegateCallDto(dto)) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: Invalid proxy delegate call response format for proxy ${proxyAddress} on chain ${chainId}`,\n ),\n );\n }\n\n return Right({\n delegateAddresses: dto.addresses,\n signedDescriptor: dto.signedDescriptor,\n });\n }\n\n public async getProxyImplementationAddress({\n proxyAddress,\n chainId,\n }: GetProxyImplementationAddressParam): Promise<\n Either<Error, ProxyImplementationAddress>\n > {\n let dto: ProxyImplementationAddressDto | undefined;\n try {\n const response = await axios.request<ProxyImplementationAddressDto>({\n method: \"GET\",\n url: `${this.config.metadataServiceDomain.url}/v1/ethereum/${chainId}/contract/proxy/${proxyAddress}`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n dto = response.data;\n } catch (_error) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: Failed to fetch implementation address`,\n ),\n );\n }\n\n if (!dto) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: No data received for proxy ${proxyAddress} on chain ${chainId}`,\n ),\n );\n }\n\n if (!this.isProxyImplementationAddressDto(dto)) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: Invalid proxy implementation address response format for proxy ${proxyAddress} on chain ${chainId}`,\n ),\n );\n }\n\n return Right({ implementationAddress: dto.implementationAddress });\n }\n\n /**\n * Type guard to validate ProxyDelegateCallDto\n */\n private isProxyDelegateCallDto(\n value: unknown,\n ): value is ProxyDelegateCallDto {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"addresses\" in value &&\n \"signedDescriptor\" in value &&\n Array.isArray(value.addresses) &&\n value.addresses.every((address) => typeof address === \"string\") &&\n typeof value.signedDescriptor === \"string\"\n );\n }\n\n /**\n * Type guard to validate ProxyImplementationAddressDto\n */\n private isProxyImplementationAddressDto(\n value: unknown,\n ): value is ProxyImplementationAddressDto {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"proxyAddress\" in value &&\n \"implementationAddress\" in value &&\n \"standard\" in value &&\n typeof value.proxyAddress === \"string\" &&\n typeof value.implementationAddress === \"string\" &&\n typeof value.standard === \"string\" &&\n value.standard.length > 0\n );\n }\n}\n"],
5
+ "mappings": "iOAAA,OAAOA,MAAW,QAClB,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YACnC,OAAiB,QAAAC,EAAM,SAAAC,MAAa,YAEpC,OAAS,eAAAC,MAAmB,0BAE5B,OACE,gCAAAC,EACA,8BAAAC,MACK,gCAGP,OAAOC,MAAa,qBA2Bb,IAAMC,EAAN,KAAqD,CAC1D,YAC+CC,EAC7C,CAD6C,YAAAA,CAC5C,CAEH,MAAa,qBAAqB,CAChC,aAAAC,EACA,SAAAC,EACA,QAAAC,EACA,UAAAC,CACF,EAAyE,CACvE,IAAIC,EACJ,GAAI,CAcFA,GAbiB,MAAMC,EAAM,QAA8B,CACzD,OAAQ,OACR,IAAK,GAAG,KAAK,OAAO,sBAAsB,GAAG,gBAAgBH,CAAO,2BACpE,QAAS,CACP,CAACI,CAA4B,EAAG,kBAAkBC,EAAQ,OAAO,GACjE,CAACC,CAA0B,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,OAAOA,GAAU,UACjBA,IAAU,MACV,iBAAkBA,GAClB,0BAA2BA,GAC3B,aAAcA,GACd,OAAOA,EAAM,cAAiB,UAC9B,OAAOA,EAAM,uBAA0B,UACvC,OAAOA,EAAM,UAAa,UAC1BA,EAAM,SAAS,OAAS,CAE5B,CACF,EAxIab,EAANe,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAY,MAAM,IAFjBnB",
6
+ "names": ["axios", "inject", "injectable", "Left", "Right", "configTypes", "LEDGER_CLIENT_VERSION_HEADER", "LEDGER_ORIGIN_TOKEN_HEADER", "PACKAGE", "HttpProxyDataSource", "config", "proxyAddress", "calldata", "chainId", "challenge", "dto", "axios", "LEDGER_CLIENT_VERSION_HEADER", "PACKAGE", "LEDGER_ORIGIN_TOKEN_HEADER", "Left", "Right", "value", "address", "__decorateClass", "injectable", "__decorateParam", "inject", "configTypes"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import a from"axios";import{Left as n,Right as l}from"purify-ts";import{LEDGER_CLIENT_VERSION_HEADER as p,LEDGER_ORIGIN_TOKEN_HEADER as m}from"../../shared/constant/HttpHeaders";import x from"../../../package.json";import{HttpProxyDataSource as y}from"./HttpProxyDataSource";vi.mock("axios");describe("HttpProxyDataSource",()=>{const c={web3checks:{url:"web3checksUrl"},originToken:"originToken"};let t;const s={proxyAddress:"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0",calldata:"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000",chainId:1},r={proxyAddress:"0xee6a57ec80ea46401049e92587e52f5ec1c24785",chainId:1},d={delegateAddresses:["0xd9db270c1b5e3bd161e8c8503c55ceabee709552"],signedDescriptor:"0x1234567890abcdef"},u={implementationAddress:"0x91ae842a5ffd8d12023116943e72a606179294f3"},i={implementationAddress:"0x91ae842a5ffd8d12023116943e72a606179294f3",proxyAddress:"0xee6a57ec80ea46401049e92587e52f5ec1c24785",standard:"proxy"};beforeEach(()=>{vi.clearAllMocks(),t=new y({metadataService:{url:"https://nft.api.live.ledger.com/v2"},originToken:"originToken"})}),describe("getDelegateProxy",()=>{it("should call axios with the ledger client version header",async()=>{const e=`context-module/${x.version}`,o=vi.fn(()=>Promise.resolve({data:d}));vi.spyOn(a,"request").mockImplementation(o),await t.getProxyDelegateCall(s),expect(o).toHaveBeenCalledWith(expect.objectContaining({headers:{[p]:e,[m]:c.originToken}}))}),it("should return the delegate proxy response on success",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:d});const e=await t.getProxyDelegateCall(s);expect(e).toEqual(l(d))}),it("should return an error when axios throws an error",async()=>{vi.spyOn(a,"request").mockRejectedValue(new Error("fail"));const e=await t.getProxyDelegateCall(s);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy")))}),it("should return an error if response shape is invalid",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:{foo:"bar"}});const e=await t.getProxyDelegateCall(s);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: Invalid proxy delegate call response format for proxy 0x72CBdEaAdddD14Ec95b92995933CeC69566650f0 on chain 1")))}),it("should use the provided chainId in the URL",async()=>{const e=vi.fn(()=>Promise.resolve({data:d}));vi.spyOn(a,"request").mockImplementation(e);const o={proxyAddress:"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0",calldata:"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000",chainId:137};await t.getProxyDelegateCall(o),expect(e).toHaveBeenCalledWith(expect.objectContaining({method:"POST",url:"https://nft.api.live.ledger.com/v2/ethereum/137/contract/proxy/delegate"}))}),it("should return an error if no dto is returned from the api",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:void 0});const e=await t.getProxyDelegateCall(s);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: No data received for proxy 0x72CBdEaAdddD14Ec95b92995933CeC69566650f0 on chain 1")))})}),describe("getImplementAddress",()=>{it("should call axios with the ledger client version header",async()=>{const e=`context-module/${x.version}`,o=vi.fn(()=>Promise.resolve({data:i}));vi.spyOn(a,"request").mockImplementation(o),await t.getProxyImplementationAddress(r),expect(o).toHaveBeenCalledWith(expect.objectContaining({headers:{[p]:e,[m]:c.originToken}}))}),it("should make a GET request to the correct URL",async()=>{const e=vi.fn(()=>Promise.resolve({data:i}));vi.spyOn(a,"request").mockImplementation(e),await t.getProxyImplementationAddress(r),expect(e).toHaveBeenCalledWith(expect.objectContaining({method:"GET",url:"https://nft.api.live.ledger.com/v2/ethereum/1/contract/proxy/0xee6a57ec80ea46401049e92587e52f5ec1c24785"}))}),it("should use the provided chainId in the URL",async()=>{const e=vi.fn(()=>Promise.resolve({data:i}));vi.spyOn(a,"request").mockImplementation(e);const o={proxyAddress:"0xee6a57ec80ea46401049e92587e52f5ec1c24785",chainId:137};await t.getProxyImplementationAddress(o),expect(e).toHaveBeenCalledWith(expect.objectContaining({method:"GET",url:"https://nft.api.live.ledger.com/v2/ethereum/137/contract/proxy/0xee6a57ec80ea46401049e92587e52f5ec1c24785"}))}),it("should return the implementation address response on success",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:i});const e=await t.getProxyImplementationAddress(r);expect(e).toEqual(l(u))}),it("should return an error when axios throws an error",async()=>{vi.spyOn(a,"request").mockRejectedValue(new Error("network error"));const e=await t.getProxyImplementationAddress(r);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch implementation address")))}),it("should return an error if response shape is invalid",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:{invalid:"data"}});const e=await t.getProxyImplementationAddress(r);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: Invalid proxy implementation address response format for proxy 0xee6a57ec80ea46401049e92587e52f5ec1c24785 on chain 1")))}),it("should return an error if no dto is returned from the api",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:void 0});const e=await t.getProxyImplementationAddress(r);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: No data received for proxy 0xee6a57ec80ea46401049e92587e52f5ec1c24785 on chain 1")))})})});
1
+ import a from"axios";import{Left as n,Right as l}from"purify-ts";import{LEDGER_CLIENT_VERSION_HEADER as p,LEDGER_ORIGIN_TOKEN_HEADER as m}from"../../shared/constant/HttpHeaders";import x from"../../../package.json";import{HttpProxyDataSource as y}from"./HttpProxyDataSource";vi.mock("axios");describe("HttpProxyDataSource",()=>{const c={web3checks:{url:"web3checksUrl"},originToken:"originToken"};let t;const s={proxyAddress:"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0",calldata:"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000",chainId:1,challenge:"0x1234567890abcdef"},r={proxyAddress:"0xee6a57ec80ea46401049e92587e52f5ec1c24785",chainId:1},i={addresses:["0xd9db270c1b5e3bd161e8c8503c55ceabee709552"],signedDescriptor:"0x1234567890abcdef"},u={implementationAddress:"0x91ae842a5ffd8d12023116943e72a606179294f3"},d={implementationAddress:"0x91ae842a5ffd8d12023116943e72a606179294f3",proxyAddress:"0xee6a57ec80ea46401049e92587e52f5ec1c24785",standard:"proxy"};beforeEach(()=>{vi.clearAllMocks(),t=new y({metadataServiceDomain:{url:"https://nft.api.live.ledger.com"},originToken:"originToken"})}),describe("getDelegateProxy",()=>{it("should call axios with the ledger client version header",async()=>{const e=`context-module/${x.version}`,o=vi.fn(()=>Promise.resolve({data:i}));vi.spyOn(a,"request").mockImplementation(o),await t.getProxyDelegateCall(s),expect(o).toHaveBeenCalledWith(expect.objectContaining({headers:{[p]:e,[m]:c.originToken}}))}),it("should return the delegate proxy response on success",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:i});const e=await t.getProxyDelegateCall(s);expect(e).toEqual(l({delegateAddresses:["0xd9db270c1b5e3bd161e8c8503c55ceabee709552"],signedDescriptor:"0x1234567890abcdef"}))}),it("should return an error when axios throws an error",async()=>{vi.spyOn(a,"request").mockRejectedValue(new Error("fail"));const e=await t.getProxyDelegateCall(s);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy")))}),it("should return an error if response shape is invalid",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:{foo:"bar"}});const e=await t.getProxyDelegateCall(s);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: Invalid proxy delegate call response format for proxy 0x72CBdEaAdddD14Ec95b92995933CeC69566650f0 on chain 1")))}),it("should use the provided chainId in the URL",async()=>{const e=vi.fn(()=>Promise.resolve({data:i}));vi.spyOn(a,"request").mockImplementation(e);const o={proxyAddress:"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0",calldata:"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000",chainId:137,challenge:"0x1234567890abcdef"};await t.getProxyDelegateCall(o),expect(e).toHaveBeenCalledWith(expect.objectContaining({method:"POST",url:"https://nft.api.live.ledger.com/v1/ethereum/137/contract/proxy/delegate"}))}),it("should return an error if no dto is returned from the api",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:void 0});const e=await t.getProxyDelegateCall(s);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: No data received for proxy 0x72CBdEaAdddD14Ec95b92995933CeC69566650f0 on chain 1")))})}),describe("getImplementAddress",()=>{it("should call axios with the ledger client version header",async()=>{const e=`context-module/${x.version}`,o=vi.fn(()=>Promise.resolve({data:d}));vi.spyOn(a,"request").mockImplementation(o),await t.getProxyImplementationAddress(r),expect(o).toHaveBeenCalledWith(expect.objectContaining({headers:{[p]:e,[m]:c.originToken}}))}),it("should make a GET request to the correct URL",async()=>{const e=vi.fn(()=>Promise.resolve({data:d}));vi.spyOn(a,"request").mockImplementation(e),await t.getProxyImplementationAddress(r),expect(e).toHaveBeenCalledWith(expect.objectContaining({method:"GET",url:"https://nft.api.live.ledger.com/v1/ethereum/1/contract/proxy/0xee6a57ec80ea46401049e92587e52f5ec1c24785"}))}),it("should use the provided chainId in the URL",async()=>{const e=vi.fn(()=>Promise.resolve({data:d}));vi.spyOn(a,"request").mockImplementation(e);const o={proxyAddress:"0xee6a57ec80ea46401049e92587e52f5ec1c24785",chainId:137};await t.getProxyImplementationAddress(o),expect(e).toHaveBeenCalledWith(expect.objectContaining({method:"GET",url:"https://nft.api.live.ledger.com/v1/ethereum/137/contract/proxy/0xee6a57ec80ea46401049e92587e52f5ec1c24785"}))}),it("should return the implementation address response on success",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:d});const e=await t.getProxyImplementationAddress(r);expect(e).toEqual(l(u))}),it("should return an error when axios throws an error",async()=>{vi.spyOn(a,"request").mockRejectedValue(new Error("network error"));const e=await t.getProxyImplementationAddress(r);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch implementation address")))}),it("should return an error if response shape is invalid",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:{invalid:"data"}});const e=await t.getProxyImplementationAddress(r);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: Invalid proxy implementation address response format for proxy 0xee6a57ec80ea46401049e92587e52f5ec1c24785 on chain 1")))}),it("should return an error if no dto is returned from the api",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:void 0});const e=await t.getProxyImplementationAddress(r);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: No data received for proxy 0xee6a57ec80ea46401049e92587e52f5ec1c24785 on chain 1")))})})});
2
2
  //# sourceMappingURL=HttpProxyDataSource.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/transaction/data/HttpProxyDataSource.test.ts"],
4
- "sourcesContent": ["import axios from \"axios\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport type { ProxyDelegateCall } from \"@/transaction/model/ProxyDelegateCall\";\nimport type { ProxyImplementationAddress } from \"@/transaction/model/ProxyImplementationAddress\";\nimport PACKAGE from \"@root/package.json\";\n\nimport { type ProxyImplementationAddressDto } from \"./dto/ProxyImplementationAddressDto\";\nimport type {\n GetProxyDelegateCallParam,\n GetProxyImplementationAddressParam,\n ProxyDataSource,\n} from \"./HttpProxyDataSource\";\nimport { HttpProxyDataSource } from \"./HttpProxyDataSource\";\n\nvi.mock(\"axios\");\n\ndescribe(\"HttpProxyDataSource\", () => {\n const config = {\n web3checks: {\n url: \"web3checksUrl\",\n },\n originToken: \"originToken\",\n } as ContextModuleConfig;\n\n let datasource: ProxyDataSource;\n const defaultParams: GetProxyDelegateCallParam = {\n proxyAddress: \"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0\",\n calldata:\n \"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000\",\n chainId: 1,\n };\n const defaultImplementAddressParams: GetProxyImplementationAddressParam = {\n proxyAddress: \"0xee6a57ec80ea46401049e92587e52f5ec1c24785\",\n chainId: 1,\n };\n const delegateProxyResponse: ProxyDelegateCall = {\n delegateAddresses: [\"0xd9db270c1b5e3bd161e8c8503c55ceabee709552\"],\n signedDescriptor: \"0x1234567890abcdef\",\n };\n const implementationAddressResponse: ProxyImplementationAddress = {\n implementationAddress: \"0x91ae842a5ffd8d12023116943e72a606179294f3\",\n };\n const implementationAddressDto: ProxyImplementationAddressDto = {\n implementationAddress: \"0x91ae842a5ffd8d12023116943e72a606179294f3\",\n proxyAddress: \"0xee6a57ec80ea46401049e92587e52f5ec1c24785\",\n standard: \"proxy\",\n };\n\n beforeEach(() => {\n vi.clearAllMocks();\n datasource = new HttpProxyDataSource({\n metadataService: {\n url: \"https://nft.api.live.ledger.com/v2\",\n },\n originToken: \"originToken\",\n } as ContextModuleConfig);\n });\n\n describe(\"getDelegateProxy\", () => {\n it(\"should call axios with the ledger client version header\", async () => {\n // GIVEN\n const version = `context-module/${PACKAGE.version}`;\n const requestSpy = vi.fn(() =>\n Promise.resolve({ data: delegateProxyResponse }),\n );\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n // WHEN\n await datasource.getProxyDelegateCall(defaultParams);\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: version,\n [LEDGER_ORIGIN_TOKEN_HEADER]: config.originToken,\n },\n }),\n );\n });\n\n it(\"should return the delegate proxy response on success\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({\n data: delegateProxyResponse,\n });\n\n // WHEN\n const result = await datasource.getProxyDelegateCall(defaultParams);\n\n // THEN\n expect(result).toEqual(Right(delegateProxyResponse));\n });\n\n it(\"should return an error when axios throws an error\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockRejectedValue(new Error(\"fail\"));\n\n // WHEN\n const result = await datasource.getProxyDelegateCall(defaultParams);\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy\",\n ),\n ),\n );\n });\n\n it(\"should return an error if response shape is invalid\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({ data: { foo: \"bar\" } });\n\n // WHEN\n const result = await datasource.getProxyDelegateCall(defaultParams);\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: Invalid proxy delegate call response format for proxy 0x72CBdEaAdddD14Ec95b92995933CeC69566650f0 on chain 1\",\n ),\n ),\n );\n });\n\n it(\"should use the provided chainId in the URL\", async () => {\n // GIVEN\n const requestSpy = vi.fn(() =>\n Promise.resolve({ data: delegateProxyResponse }),\n );\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n const paramsWithDifferentChainId: GetProxyDelegateCallParam = {\n proxyAddress: \"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0\",\n calldata:\n \"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000\",\n chainId: 137, // Polygon\n };\n\n // WHEN\n await datasource.getProxyDelegateCall(paramsWithDifferentChainId);\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n method: \"POST\",\n url: \"https://nft.api.live.ledger.com/v2/ethereum/137/contract/proxy/delegate\",\n }),\n );\n });\n\n it(\"should return an error if no dto is returned from the api\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({\n data: undefined,\n });\n\n // WHEN\n const result = await datasource.getProxyDelegateCall(defaultParams);\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: No data received for proxy 0x72CBdEaAdddD14Ec95b92995933CeC69566650f0 on chain 1\",\n ),\n ),\n );\n });\n });\n\n describe(\"getImplementAddress\", () => {\n it(\"should call axios with the ledger client version header\", async () => {\n // GIVEN\n const version = `context-module/${PACKAGE.version}`;\n const requestSpy = vi.fn(() =>\n Promise.resolve({ data: implementationAddressDto }),\n );\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n // WHEN\n await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: version,\n [LEDGER_ORIGIN_TOKEN_HEADER]: config.originToken,\n },\n }),\n );\n });\n\n it(\"should make a GET request to the correct URL\", async () => {\n // GIVEN\n const requestSpy = vi.fn(() =>\n Promise.resolve({ data: implementationAddressDto }),\n );\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n // WHEN\n await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n method: \"GET\",\n url: \"https://nft.api.live.ledger.com/v2/ethereum/1/contract/proxy/0xee6a57ec80ea46401049e92587e52f5ec1c24785\",\n }),\n );\n });\n\n it(\"should use the provided chainId in the URL\", async () => {\n // GIVEN\n const requestSpy = vi.fn(() =>\n Promise.resolve({ data: implementationAddressDto }),\n );\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n const paramsWithDifferentChainId: GetProxyImplementationAddressParam = {\n proxyAddress: \"0xee6a57ec80ea46401049e92587e52f5ec1c24785\",\n chainId: 137, // Polygon\n };\n\n // WHEN\n await datasource.getProxyImplementationAddress(\n paramsWithDifferentChainId,\n );\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n method: \"GET\",\n url: \"https://nft.api.live.ledger.com/v2/ethereum/137/contract/proxy/0xee6a57ec80ea46401049e92587e52f5ec1c24785\",\n }),\n );\n });\n\n it(\"should return the implementation address response on success\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({\n data: implementationAddressDto,\n });\n\n // WHEN\n const result = await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(result).toEqual(Right(implementationAddressResponse));\n });\n\n it(\"should return an error when axios throws an error\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockRejectedValue(new Error(\"network error\"));\n\n // WHEN\n const result = await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: Failed to fetch implementation address\",\n ),\n ),\n );\n });\n\n it(\"should return an error if response shape is invalid\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({\n data: { invalid: \"data\" },\n });\n\n // WHEN\n const result = await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: Invalid proxy implementation address response format for proxy 0xee6a57ec80ea46401049e92587e52f5ec1c24785 on chain 1\",\n ),\n ),\n );\n });\n\n it(\"should return an error if no dto is returned from the api\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({\n data: undefined,\n });\n\n // WHEN\n const result = await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: No data received for proxy 0xee6a57ec80ea46401049e92587e52f5ec1c24785 on chain 1\",\n ),\n ),\n );\n });\n });\n});\n"],
5
- "mappings": "AAAA,OAAOA,MAAW,QAClB,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAG5B,OACE,gCAAAC,EACA,8BAAAC,MACK,gCAGP,OAAOC,MAAa,qBAQpB,OAAS,uBAAAC,MAA2B,wBAEpC,GAAG,KAAK,OAAO,EAEf,SAAS,sBAAuB,IAAM,CACpC,MAAMC,EAAS,CACb,WAAY,CACV,IAAK,eACP,EACA,YAAa,aACf,EAEA,IAAIC,EACJ,MAAMC,EAA2C,CAC/C,aAAc,6CACd,SACE,0oCACF,QAAS,CACX,EACMC,EAAoE,CACxE,aAAc,6CACd,QAAS,CACX,EACMC,EAA2C,CAC/C,kBAAmB,CAAC,4CAA4C,EAChE,iBAAkB,oBACpB,EACMC,EAA4D,CAChE,sBAAuB,4CACzB,EACMC,EAA0D,CAC9D,sBAAuB,6CACvB,aAAc,6CACd,SAAU,OACZ,EAEA,WAAW,IAAM,CACf,GAAG,cAAc,EACjBL,EAAa,IAAIF,EAAoB,CACnC,gBAAiB,CACf,IAAK,oCACP,EACA,YAAa,aACf,CAAwB,CAC1B,CAAC,EAED,SAAS,mBAAoB,IAAM,CACjC,GAAG,0DAA2D,SAAY,CAExE,MAAMQ,EAAU,kBAAkBT,E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,MAAME,EAAiE,CACrE,aAAc,6CACd,QAAS,GACX,EAGA,MAAMT,EAAW,8BACfS,CACF,EAGA,OAAOF,CAAU,EAAE,qBACjB,OAAO,iBAAiB,CACtB,OAAQ,MACR,IAAK,2GACP,CAAC,CACH,CACF,CAAC,EAED,GAAG,+DAAgE,SAAY,CAE7E,GAAG,MAAMf,EAAO,SAAS,EAAE,kBAAkB,CAC3C,KAAMa,CACR,CAAC,EAGD,MAAMG,EAAS,MAAMR,EAAW,8BAC9BE,CACF,EAGA,OAAOM,CAAM,EAAE,QAAQd,EAAMU,CAA6B,CAAC,CAC7D,CAAC,EAED,GAAG,oDAAqD,SAAY,CAElE,GAAG,MAAMZ,EAAO,SAAS,EAAE,kBAAkB,IAAI,MAAM,eAAe,CAAC,EAGvE,MAAMgB,EAAS,MAAMR,EAAW,8BAC9BE,CACF,EAGA,OAAOM,CAAM,EAAE,QACbf,EACE,IAAI,MACF,6EACF,CACF,CACF,CACF,CAAC,EAED,GAAG,sDAAuD,SAAY,CAEpE,GAAG,MAAMD,EAAO,SAAS,EAAE,kBAAkB,CAC3C,KAAM,CAAE,QAAS,MAAO,CAC1B,CAAC,EAGD,MAAMgB,EAAS,MAAMR,EAAW,8BAC9BE,CACF,EAGA,OAAOM,CAAM,EAAE,QACbf,EACE,IAAI,MACF,2JACF,CACF,CACF,CACF,CAAC,EAED,GAAG,4DAA6D,SAAY,CAE1E,GAAG,MAAMD,EAAO,SAAS,EAAE,kBAAkB,CAC3C,KAAM,MACR,CAAC,EAGD,MAAMgB,EAAS,MAAMR,EAAW,8BAC9BE,CACF,EAGA,OAAOM,CAAM,EAAE,QACbf,EACE,IAAI,MACF,uHACF,CACF,CACF,CACF,CAAC,CACH,CAAC,CACH,CAAC",
4
+ "sourcesContent": ["import axios from \"axios\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport type { ProxyImplementationAddress } from \"@/transaction/model/ProxyImplementationAddress\";\nimport PACKAGE from \"@root/package.json\";\n\nimport { type ProxyDelegateCallDto } from \"./dto/ProxyDelegateCallDto\";\nimport { type ProxyImplementationAddressDto } from \"./dto/ProxyImplementationAddressDto\";\nimport type {\n GetProxyDelegateCallParam,\n GetProxyImplementationAddressParam,\n ProxyDataSource,\n} from \"./HttpProxyDataSource\";\nimport { HttpProxyDataSource } from \"./HttpProxyDataSource\";\n\nvi.mock(\"axios\");\n\ndescribe(\"HttpProxyDataSource\", () => {\n const config = {\n web3checks: {\n url: \"web3checksUrl\",\n },\n originToken: \"originToken\",\n } as ContextModuleConfig;\n\n let datasource: ProxyDataSource;\n const defaultParams: GetProxyDelegateCallParam = {\n proxyAddress: \"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0\",\n calldata:\n \"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000\",\n chainId: 1,\n challenge: \"0x1234567890abcdef\",\n };\n const defaultImplementAddressParams: GetProxyImplementationAddressParam = {\n proxyAddress: \"0xee6a57ec80ea46401049e92587e52f5ec1c24785\",\n chainId: 1,\n };\n const delegateProxyResponse: ProxyDelegateCallDto = {\n addresses: [\"0xd9db270c1b5e3bd161e8c8503c55ceabee709552\"],\n signedDescriptor: \"0x1234567890abcdef\",\n };\n const implementationAddressResponse: ProxyImplementationAddress = {\n implementationAddress: \"0x91ae842a5ffd8d12023116943e72a606179294f3\",\n };\n const implementationAddressDto: ProxyImplementationAddressDto = {\n implementationAddress: \"0x91ae842a5ffd8d12023116943e72a606179294f3\",\n proxyAddress: \"0xee6a57ec80ea46401049e92587e52f5ec1c24785\",\n standard: \"proxy\",\n };\n\n beforeEach(() => {\n vi.clearAllMocks();\n datasource = new HttpProxyDataSource({\n metadataServiceDomain: {\n url: \"https://nft.api.live.ledger.com\",\n },\n originToken: \"originToken\",\n } as ContextModuleConfig);\n });\n\n describe(\"getDelegateProxy\", () => {\n it(\"should call axios with the ledger client version header\", async () => {\n // GIVEN\n const version = `context-module/${PACKAGE.version}`;\n const requestSpy = vi.fn(() =>\n Promise.resolve({ data: delegateProxyResponse }),\n );\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n // WHEN\n await datasource.getProxyDelegateCall(defaultParams);\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: version,\n [LEDGER_ORIGIN_TOKEN_HEADER]: config.originToken,\n },\n }),\n );\n });\n\n it(\"should return the delegate proxy response on success\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({\n data: delegateProxyResponse,\n });\n\n // WHEN\n const result = await datasource.getProxyDelegateCall(defaultParams);\n\n // THEN\n expect(result).toEqual(\n Right({\n delegateAddresses: [\"0xd9db270c1b5e3bd161e8c8503c55ceabee709552\"],\n signedDescriptor: \"0x1234567890abcdef\",\n }),\n );\n });\n\n it(\"should return an error when axios throws an error\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockRejectedValue(new Error(\"fail\"));\n\n // WHEN\n const result = await datasource.getProxyDelegateCall(defaultParams);\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy\",\n ),\n ),\n );\n });\n\n it(\"should return an error if response shape is invalid\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({ data: { foo: \"bar\" } });\n\n // WHEN\n const result = await datasource.getProxyDelegateCall(defaultParams);\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: Invalid proxy delegate call response format for proxy 0x72CBdEaAdddD14Ec95b92995933CeC69566650f0 on chain 1\",\n ),\n ),\n );\n });\n\n it(\"should use the provided chainId in the URL\", async () => {\n // GIVEN\n const requestSpy = vi.fn(() =>\n Promise.resolve({ data: delegateProxyResponse }),\n );\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n const paramsWithDifferentChainId: GetProxyDelegateCallParam = {\n proxyAddress: \"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0\",\n calldata:\n \"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000\",\n chainId: 137, // Polygon\n challenge: \"0x1234567890abcdef\",\n };\n\n // WHEN\n await datasource.getProxyDelegateCall(paramsWithDifferentChainId);\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n method: \"POST\",\n url: \"https://nft.api.live.ledger.com/v1/ethereum/137/contract/proxy/delegate\",\n }),\n );\n });\n\n it(\"should return an error if no dto is returned from the api\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({\n data: undefined,\n });\n\n // WHEN\n const result = await datasource.getProxyDelegateCall(defaultParams);\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: No data received for proxy 0x72CBdEaAdddD14Ec95b92995933CeC69566650f0 on chain 1\",\n ),\n ),\n );\n });\n });\n\n describe(\"getImplementAddress\", () => {\n it(\"should call axios with the ledger client version header\", async () => {\n // GIVEN\n const version = `context-module/${PACKAGE.version}`;\n const requestSpy = vi.fn(() =>\n Promise.resolve({ data: implementationAddressDto }),\n );\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n // WHEN\n await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: version,\n [LEDGER_ORIGIN_TOKEN_HEADER]: config.originToken,\n },\n }),\n );\n });\n\n it(\"should make a GET request to the correct URL\", async () => {\n // GIVEN\n const requestSpy = vi.fn(() =>\n Promise.resolve({ data: implementationAddressDto }),\n );\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n // WHEN\n await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n method: \"GET\",\n url: \"https://nft.api.live.ledger.com/v1/ethereum/1/contract/proxy/0xee6a57ec80ea46401049e92587e52f5ec1c24785\",\n }),\n );\n });\n\n it(\"should use the provided chainId in the URL\", async () => {\n // GIVEN\n const requestSpy = vi.fn(() =>\n Promise.resolve({ data: implementationAddressDto }),\n );\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n const paramsWithDifferentChainId: GetProxyImplementationAddressParam = {\n proxyAddress: \"0xee6a57ec80ea46401049e92587e52f5ec1c24785\",\n chainId: 137, // Polygon\n };\n\n // WHEN\n await datasource.getProxyImplementationAddress(\n paramsWithDifferentChainId,\n );\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n method: \"GET\",\n url: \"https://nft.api.live.ledger.com/v1/ethereum/137/contract/proxy/0xee6a57ec80ea46401049e92587e52f5ec1c24785\",\n }),\n );\n });\n\n it(\"should return the implementation address response on success\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({\n data: implementationAddressDto,\n });\n\n // WHEN\n const result = await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(result).toEqual(Right(implementationAddressResponse));\n });\n\n it(\"should return an error when axios throws an error\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockRejectedValue(new Error(\"network error\"));\n\n // WHEN\n const result = await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: Failed to fetch implementation address\",\n ),\n ),\n );\n });\n\n it(\"should return an error if response shape is invalid\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({\n data: { invalid: \"data\" },\n });\n\n // WHEN\n const result = await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: Invalid proxy implementation address response format for proxy 0xee6a57ec80ea46401049e92587e52f5ec1c24785 on chain 1\",\n ),\n ),\n );\n });\n\n it(\"should return an error if no dto is returned from the api\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({\n data: undefined,\n });\n\n // WHEN\n const result = await datasource.getProxyImplementationAddress(\n defaultImplementAddressParams,\n );\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpProxyDataSource: No data received for proxy 0xee6a57ec80ea46401049e92587e52f5ec1c24785 on chain 1\",\n ),\n ),\n );\n });\n });\n});\n"],
5
+ "mappings": "AAAA,OAAOA,MAAW,QAClB,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAG5B,OACE,gCAAAC,EACA,8BAAAC,MACK,gCAEP,OAAOC,MAAa,qBASpB,OAAS,uBAAAC,MAA2B,wBAEpC,GAAG,KAAK,OAAO,EAEf,SAAS,sBAAuB,IAAM,CACpC,MAAMC,EAAS,CACb,WAAY,CACV,IAAK,eACP,EACA,YAAa,aACf,EAEA,IAAIC,EACJ,MAAMC,EAA2C,CAC/C,aAAc,6CACd,SACE,0oCACF,QAAS,EACT,UAAW,oBACb,EACMC,EAAoE,CACxE,aAAc,6CACd,QAAS,CACX,EACMC,EAA8C,CAClD,UAAW,CAAC,4CAA4C,EACxD,iBAAkB,oBACpB,EACMC,EAA4D,CAChE,sBAAuB,4CACzB,EACMC,EAA0D,CAC9D,sBAAuB,6CACvB,aAAc,6CACd,SAAU,OACZ,EAEA,WAAW,IAAM,CACf,GAAG,cAAc,EACjBL,EAAa,IAAIF,EAAoB,CACnC,sBAAuB,CACrB,IAAK,iCACP,EACA,YAAa,aACf,CAAwB,CAC1B,CAAC,EAED,SAAS,mBAAoB,IAAM,CACjC,GAAG,0DAA2D,SAAY,CAExE,MAAMQ,EAAU,kBAAkBT,EAAQ,OAAO,GAC3CU,EAAa,GAAG,GAAG,IACvB,QAAQ,QAAQ,CAAE,KAAMJ,CAAsB,CAAC,CACjD,EACA,GAAG,MAAMX,EAAO,SAAS,EAAE,mBAAmBe,CAAU,EAGxD,MAAMP,EAAW,qBAAqBC,CAAa,EAGnD,OAAOM,CAAU,EAAE,qBACjB,OAAO,iBAAiB,CACtB,QAAS,CACP,CAACZ,CAA4B,EAAGW,EAChC,CAACV,CAA0B,EAAGG,EAAO,WACvC,CACF,CAAC,CACH,CACF,CAAC,EAED,GA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,EAAS,MAAMR,EAAW,8BAC9BE,CACF,EAGA,OAAOM,CAAM,EAAE,QAAQd,EAAMU,CAA6B,CAAC,CAC7D,CAAC,EAED,GAAG,oDAAqD,SAAY,CAElE,GAAG,MAAMZ,EAAO,SAAS,EAAE,kBAAkB,IAAI,MAAM,eAAe,CAAC,EAGvE,MAAMgB,EAAS,MAAMR,EAAW,8BAC9BE,CACF,EAGA,OAAOM,CAAM,EAAE,QACbf,EACE,IAAI,MACF,6EACF,CACF,CACF,CACF,CAAC,EAED,GAAG,sDAAuD,SAAY,CAEpE,GAAG,MAAMD,EAAO,SAAS,EAAE,kBAAkB,CAC3C,KAAM,CAAE,QAAS,MAAO,CAC1B,CAAC,EAGD,MAAMgB,EAAS,MAAMR,EAAW,8BAC9BE,CACF,EAGA,OAAOM,CAAM,EAAE,QACbf,EACE,IAAI,MACF,2JACF,CACF,CACF,CACF,CAAC,EAED,GAAG,4DAA6D,SAAY,CAE1E,GAAG,MAAMD,EAAO,SAAS,EAAE,kBAAkB,CAC3C,KAAM,MACR,CAAC,EAGD,MAAMgB,EAAS,MAAMR,EAAW,8BAC9BE,CACF,EAGA,OAAOM,CAAM,EAAE,QACbf,EACE,IAAI,MACF,uHACF,CACF,CACF,CACF,CAAC,CACH,CAAC,CACH,CAAC",
6
6
  "names": ["axios", "Left", "Right", "LEDGER_CLIENT_VERSION_HEADER", "LEDGER_ORIGIN_TOKEN_HEADER", "PACKAGE", "HttpProxyDataSource", "config", "datasource", "defaultParams", "defaultImplementAddressParams", "delegateProxyResponse", "implementationAddressResponse", "implementationAddressDto", "version", "requestSpy", "result", "paramsWithDifferentChainId"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var u=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var m=(o,r,e,a)=>{for(var t=a>1?void 0:a?f(r,e):r,n=o.length-1,i;n>=0;n--)(i=o[n])&&(t=(a?i(r,e,t):i(t))||t);return a&&t&&u(r,e,t),t},p=(o,r)=>(e,a)=>r(e,a,o);import{isHexaString as S}from"@ledgerhq/device-management-kit";import{inject as d,injectable as C}from"inversify";import{ClearSignContextType as l}from"../../shared/model/ClearSignContext";import{transactionTypes as x}from"../../transaction/di/transactionTypes";let c=class{constructor(r){this.transactionDataSource=r}async load(r){const{to:e,data:a,selector:t,chainId:n,deviceModelId:i}=r;return e===void 0||a==="0x"?[]:S(t)?(await this.transactionDataSource.getTransactionDescriptors({deviceModelId:i,address:e,chainId:n,selector:t})).caseOf({Left:s=>[{type:l.ERROR,error:s}],Right:s=>s}):[{type:l.ERROR,error:new Error("Invalid selector")}]}};c=m([C(),p(0,d(x.TransactionDataSource))],c);export{c as TransactionContextLoader};
1
+ var k=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var C=(n,t,e,r)=>{for(var a=r>1?void 0:r?L(t,e):t,o=n.length-1,c;o>=0;o--)(c=n[o])&&(a=(r?c(t,e,a):c(a))||a);return r&&a&&k(t,e,a),a},s=(n,t)=>(e,r)=>t(e,r,n);import{isHexaString as R}from"@ledgerhq/device-management-kit";import{inject as f,injectable as h}from"inversify";import{pkiTypes as v}from"../../pki/di/pkiTypes";import{KeyId as T}from"../../pki/model/KeyId";import{KeyUsage as A}from"../../pki/model/KeyUsage";import{ClearSignContextType as p}from"../../shared/model/ClearSignContext";import{transactionTypes as g}from"../../transaction/di/transactionTypes";let d=class{constructor(t,e,r){this.transactionDataSource=t;this.proxyDataSource=e;this.certificateLoader=r}async load(t){const{to:e,data:r,selector:a,chainId:o,deviceModelId:c,challenge:y}=t;if(e===void 0||r==="0x")return[];if(!R(a))return[{type:p.ERROR,error:new Error("Invalid selector")}];const u=await this.proxyDataSource.getProxyDelegateCall({calldata:r,proxyAddress:e,chainId:o,challenge:y||""}),[x,l]=u.caseOf({Left:()=>[e,void 0],Right:i=>[i.delegateAddresses.find(P=>P===e)||i.delegateAddresses[0],i.signedDescriptor]});let m;l&&(m=await this.certificateLoader.loadCertificate({keyId:T.CalCalldataKey,keyUsage:A.Calldata,targetDevice:t.deviceModelId}));const D=l?[{type:p.PROXY_DELEGATE_CALL,payload:l,certificate:m}]:[],S=(await this.transactionDataSource.getTransactionDescriptors({deviceModelId:c,address:x,chainId:o,selector:a})).caseOf({Left:i=>[{type:p.ERROR,error:i}],Right:i=>i});return[...D,...S]}};d=C([h(),s(0,f(g.TransactionDataSource)),s(1,f(g.ProxyDataSource)),s(2,f(v.PkiCertificateLoader))],d);export{d as TransactionContextLoader};
2
2
  //# sourceMappingURL=TransactionContextLoader.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/transaction/domain/TransactionContextLoader.ts"],
4
- "sourcesContent": ["import { isHexaString } from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { TransactionContext } from \"@/shared/model/TransactionContext\";\nimport type { TransactionDataSource } from \"@/transaction/data/TransactionDataSource\";\nimport { transactionTypes } from \"@/transaction/di/transactionTypes\";\n\n@injectable()\nexport class TransactionContextLoader implements ContextLoader {\n constructor(\n @inject(transactionTypes.TransactionDataSource)\n private transactionDataSource: TransactionDataSource,\n ) {}\n\n async load(ctx: TransactionContext): Promise<ClearSignContext[]> {\n const { to, data, selector, chainId, deviceModelId } = ctx;\n if (to === undefined || data === \"0x\") {\n return [];\n }\n\n if (!isHexaString(selector)) {\n return [\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Invalid selector\"),\n },\n ];\n }\n\n const result = await this.transactionDataSource.getTransactionDescriptors({\n deviceModelId,\n address: to,\n chainId,\n selector,\n });\n\n return result.caseOf({\n Left: (error): ClearSignContext[] => [\n {\n type: ClearSignContextType.ERROR,\n error,\n },\n ],\n Right: (contexts): ClearSignContext[] => contexts,\n });\n }\n}\n"],
5
- "mappings": "iOAAA,OAAS,gBAAAA,MAAoB,kCAC7B,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YAGnC,OAEE,wBAAAC,MACK,kCAGP,OAAS,oBAAAC,MAAwB,oCAG1B,IAAMC,EAAN,KAAwD,CAC7D,YAEUC,EACR,CADQ,2BAAAA,CACP,CAEH,MAAM,KAAKC,EAAsD,CAC/D,KAAM,CAAE,GAAAC,EAAI,KAAAC,EAAM,SAAAC,EAAU,QAAAC,EAAS,cAAAC,CAAc,EAAIL,EACvD,OAAIC,IAAO,QAAaC,IAAS,KACxB,CAAC,EAGLI,EAAaH,CAAQ,GASX,MAAM,KAAK,sBAAsB,0BAA0B,CACxE,cAAAE,EACA,QAASJ,EACT,QAAAG,EACA,SAAAD,CACF,CAAC,GAEa,OAAO,CACnB,KAAOI,GAA8B,CACnC,CACE,KAAMC,EAAqB,MAC3B,MAAAD,CACF,CACF,EACA,MAAQE,GAAiCA,CAC3C,CAAC,EAvBQ,CACL,CACE,KAAMD,EAAqB,MAC3B,MAAO,IAAI,MAAM,kBAAkB,CACrC,CACF,CAmBJ,CACF,EAtCaV,EAANY,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAiB,qBAAqB,IAFrChB",
6
- "names": ["isHexaString", "inject", "injectable", "ClearSignContextType", "transactionTypes", "TransactionContextLoader", "transactionDataSource", "ctx", "to", "data", "selector", "chainId", "deviceModelId", "isHexaString", "error", "ClearSignContextType", "contexts", "__decorateClass", "injectable", "__decorateParam", "inject", "transactionTypes"]
4
+ "sourcesContent": ["import { isHexaString } from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport type { PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { TransactionContext } from \"@/shared/model/TransactionContext\";\nimport type { ProxyDataSource } from \"@/transaction/data/HttpProxyDataSource\";\nimport type { TransactionDataSource } from \"@/transaction/data/TransactionDataSource\";\nimport { transactionTypes } from \"@/transaction/di/transactionTypes\";\nimport { ProxyDelegateCall } from \"@/transaction/model/ProxyDelegateCall\";\n\n@injectable()\nexport class TransactionContextLoader implements ContextLoader {\n constructor(\n @inject(transactionTypes.TransactionDataSource)\n private transactionDataSource: TransactionDataSource,\n @inject(transactionTypes.ProxyDataSource)\n private proxyDataSource: ProxyDataSource,\n @inject(pkiTypes.PkiCertificateLoader)\n private certificateLoader: PkiCertificateLoader,\n ) {}\n\n async load(ctx: TransactionContext): Promise<ClearSignContext[]> {\n const { to, data, selector, chainId, deviceModelId, challenge } = ctx;\n if (to === undefined || data === \"0x\") {\n return [];\n }\n\n if (!isHexaString(selector)) {\n return [\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Invalid selector\"),\n },\n ];\n }\n\n const proxyDelegateCall = await this.proxyDataSource.getProxyDelegateCall({\n calldata: data,\n proxyAddress: to,\n chainId,\n challenge: challenge || \"\",\n });\n\n // get the resolved address from the list of delegate addresses\n // if the transaction.to is not in the list of delegate addresses,\n // return the first element as the resolved address,\n // and undefined as the proxy delegate call descriptor\n // if the transaction.to is in the list of delegate addresses,\n // return the transaction.to as the resolved address,\n // and the proxy delegate call descriptor\n const [resolvedAddress, proxyDelegateCallDescriptor]: [\n string,\n string | undefined,\n ] = proxyDelegateCall.caseOf({\n Left: () => [to!, undefined],\n Right: (proxyData: ProxyDelegateCall): [string, string | undefined] => {\n return [\n proxyData.delegateAddresses.find((address) => address === to) ||\n proxyData.delegateAddresses[0]!,\n proxyData.signedDescriptor,\n ];\n },\n });\n\n let certificate: PkiCertificate | undefined = undefined;\n if (proxyDelegateCallDescriptor) {\n certificate = await this.certificateLoader.loadCertificate({\n keyId: KeyId.CalCalldataKey,\n keyUsage: KeyUsage.Calldata,\n targetDevice: ctx.deviceModelId,\n });\n }\n\n const proxyDelegateCallContext: ClearSignContext[] =\n proxyDelegateCallDescriptor\n ? [\n {\n type: ClearSignContextType.PROXY_DELEGATE_CALL,\n payload: proxyDelegateCallDescriptor,\n certificate: certificate,\n },\n ]\n : [];\n\n const transactionContexts = (\n await this.transactionDataSource.getTransactionDescriptors({\n deviceModelId,\n address: resolvedAddress,\n chainId,\n selector,\n })\n ).caseOf({\n Left: (error): ClearSignContext[] => [\n {\n type: ClearSignContextType.ERROR,\n error,\n },\n ],\n Right: (contexts): ClearSignContext[] => contexts,\n });\n\n return [...proxyDelegateCallContext, ...transactionContexts];\n }\n}\n"],
5
+ "mappings": "iOAAA,OAAS,gBAAAA,MAAoB,kCAC7B,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YAEnC,OAAS,YAAAC,MAAgB,oBAEzB,OAAS,SAAAC,MAAa,oBACtB,OAAS,YAAAC,MAAgB,uBAGzB,OAEE,wBAAAC,MACK,kCAIP,OAAS,oBAAAC,MAAwB,oCAI1B,IAAMC,EAAN,KAAwD,CAC7D,YAEUC,EAEAC,EAEAC,EACR,CALQ,2BAAAF,EAEA,qBAAAC,EAEA,uBAAAC,CACP,CAEH,MAAM,KAAKC,EAAsD,CAC/D,KAAM,CAAE,GAAAC,EAAI,KAAAC,EAAM,SAAAC,EAAU,QAAAC,EAAS,cAAAC,EAAe,UAAAC,CAAU,EAAIN,EAClE,GAAIC,IAAO,QAAaC,IAAS,KAC/B,MAAO,CAAC,EAGV,GAAI,CAACK,EAAaJ,CAAQ,EACxB,MAAO,CACL,CACE,KAAMK,EAAqB,MAC3B,MAAO,IAAI,MAAM,kBAAkB,CACrC,CACF,EAGF,MAAMC,EAAoB,MAAM,KAAK,gBAAgB,qBAAqB,CACxE,SAAUP,EACV,aAAcD,EACd,QAAAG,EACA,UAAWE,GAAa,EAC1B,CAAC,EASK,CAACI,EAAiBC,CAA2B,EAG/CF,EAAkB,OAAO,CAC3B,KAAM,IAAM,CAACR,EAAK,MAAS,EAC3B,MAAQW,GACC,CACLA,EAAU,kBAAkB,KAAMC,GAAYA,IAAYZ,CAAE,GAC1DW,EAAU,kBAAkB,CAAC,EAC/BA,EAAU,gBACZ,CAEJ,CAAC,EAED,IAAIE,EACAH,IACFG,EAAc,MAAM,KAAK,kBAAkB,gBAAgB,CACzD,MAAOC,EAAM,eACb,SAAUC,EAAS,SACnB,aAAchB,EAAI,aACpB,CAAC,GAGH,MAAMiB,EACJN,EACI,CACE,CACE,KAAMH,EAAqB,oBAC3B,QAASG,EACT,YAAaG,CACf,CACF,EACA,CAAC,EAEDI,GACJ,MAAM,KAAK,sBAAsB,0BAA0B,CACzD,cAAAb,EACA,QAASK,EACT,QAAAN,EACA,SAAAD,CACF,CAAC,GACD,OAAO,CACP,KAAOgB,GAA8B,CACnC,CACE,KAAMX,EAAqB,MAC3B,MAAAW,CACF,CACF,EACA,MAAQC,GAAiCA,CAC3C,CAAC,EAED,MAAO,CAAC,GAAGH,EAA0B,GAAGC,CAAmB,CAC7D,CACF,EA5FatB,EAANyB,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAiB,qBAAqB,GAE7CF,EAAA,EAAAC,EAAOC,EAAiB,eAAe,GAEvCF,EAAA,EAAAC,EAAOE,EAAS,oBAAoB,IAN5B9B",
6
+ "names": ["isHexaString", "inject", "injectable", "pkiTypes", "KeyId", "KeyUsage", "ClearSignContextType", "transactionTypes", "TransactionContextLoader", "transactionDataSource", "proxyDataSource", "certificateLoader", "ctx", "to", "data", "selector", "chainId", "deviceModelId", "challenge", "isHexaString", "ClearSignContextType", "proxyDelegateCall", "resolvedAddress", "proxyDelegateCallDescriptor", "proxyData", "address", "certificate", "KeyId", "KeyUsage", "proxyDelegateCallContext", "transactionContexts", "error", "contexts", "__decorateClass", "injectable", "__decorateParam", "inject", "transactionTypes", "pkiTypes"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{Left as s,Right as c}from"purify-ts";import{ClearSignContextType as o}from"../../shared/model/ClearSignContext";import{TransactionContextLoader as i}from"../../transaction/domain/TransactionContextLoader";describe("TransactionContextLoader",()=>{const r=vi.fn(),n={getTransactionDescriptors:r},e=new i(n);beforeEach(()=>{vi.clearAllMocks()}),it("should return an empty array if no destination address is provided",async()=>{const a={},t=await e.load(a);expect(t).toEqual([])}),it("should return an empty array if no data provided",async()=>{const a={to:"0x0",data:"0x"},t=await e.load(a);expect(t).toEqual([])}),it("should return an error if selector is invalid",async()=>{const a={to:"0x7",chainId:3,data:"0xzf68b302000000000000000000000000000000000000000000000000000000000002"},t=await e.load(a);expect(t).toEqual([{type:o.ERROR,error:new Error("Invalid selector")}])}),it("should return an error if data source fails",async()=>{r.mockResolvedValue(s(new Error("data source error")));const a={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await e.load(a);expect(r).toHaveBeenCalledWith({address:"0x7",chainId:3,selector:"0xaf68b302"}),expect(t).toEqual([{type:o.ERROR,error:new Error("data source error")}])}),it("should return the contexts on success",async()=>{r.mockResolvedValue(c([{type:o.TRANSACTION_INFO,payload:"1234567890"},{type:o.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}]));const a={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await e.load(a);expect(t).toEqual([{type:o.TRANSACTION_INFO,payload:"1234567890"},{type:o.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])})});
1
+ import{Left as c,Right as s}from"purify-ts";import{ClearSignContextType as e}from"../../shared/model/ClearSignContext";import{TransactionContextLoader as p}from"../../transaction/domain/TransactionContextLoader";describe("TransactionContextLoader",()=>{const r=vi.fn(),n=vi.fn(),d={getTransactionDescriptors:r},l={getProxyDelegateCall:n,getProxyImplementationAddress:vi.fn()},i={loadCertificate:vi.fn()},o=new p(d,l,i);beforeEach(()=>{vi.resetAllMocks()}),it("should return an empty array if no destination address is provided",async()=>{const a={},t=await o.load(a);expect(t).toEqual([])}),it("should return an empty array if no data provided",async()=>{const a={to:"0x0",data:"0x"},t=await o.load(a);expect(t).toEqual([])}),it("should return an error if selector is invalid",async()=>{const a={to:"0x7",chainId:3,data:"0xzf68b302000000000000000000000000000000000000000000000000000000000002"},t=await o.load(a);expect(t).toEqual([{type:e.ERROR,error:new Error("Invalid selector")}])}),it("should return an error if data source fails",async()=>{n.mockResolvedValue(c(new Error("data source error"))),r.mockResolvedValue(c(new Error("data source error")));const a={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await o.load(a);expect(r).toHaveBeenCalledWith({address:"0x7",chainId:3,selector:"0xaf68b302"}),expect(t).toEqual([{type:e.ERROR,error:new Error("data source error")}])}),it("should return the contexts on success",async()=>{r.mockResolvedValue(s([{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),n.mockResolvedValue(c(new Error("data source error")));const a={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await o.load(a);expect(t).toEqual([{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])}),it("should return the proxy delegate call context on success",async()=>{r.mockResolvedValue(s([{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),n.mockResolvedValue(s({delegateAddresses:["0x7"],signedDescriptor:"0x1234567890abcdef"}));const a={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await o.load(a);expect(t).toEqual([{type:e.PROXY_DELEGATE_CALL,payload:"0x1234567890abcdef"},{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])}),it("should return the proxy delegate call context if the transaction.to is in the delegate addresses and the transaction.to is not the first element",async()=>{r.mockResolvedValue(s([{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),n.mockResolvedValue(s({delegateAddresses:["0x7","0x8"],signedDescriptor:"0x1234567890abcdef"}));const a={to:"0x8",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await o.load(a);expect(t).toEqual([{type:e.PROXY_DELEGATE_CALL,payload:"0x1234567890abcdef"},{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])}),it("should return the proxy delegate call context if the transaction.to is not in the delegate addresses",async()=>{r.mockResolvedValue(s([{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),n.mockResolvedValue(s({delegateAddresses:["0x8"],signedDescriptor:"0x1234567890abcdef"}));const a={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await o.load(a);expect(t).toEqual([{type:e.PROXY_DELEGATE_CALL,payload:"0x1234567890abcdef"},{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])})});
2
2
  //# sourceMappingURL=TransactionContextLoader.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/transaction/domain/TransactionContextLoader.test.ts"],
4
- "sourcesContent": ["import { Left, Right } from \"purify-ts\";\n\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport type { TransactionContext } from \"@/shared/model/TransactionContext\";\nimport type { TransactionDataSource } from \"@/transaction/data/TransactionDataSource\";\nimport { TransactionContextLoader } from \"@/transaction/domain/TransactionContextLoader\";\n\ndescribe(\"TransactionContextLoader\", () => {\n const getTransactionDescriptorsMock = vi.fn();\n const mockTransactionDataSource: TransactionDataSource = {\n getTransactionDescriptors: getTransactionDescriptorsMock,\n };\n const loader = new TransactionContextLoader(mockTransactionDataSource);\n\n beforeEach(() => {\n vi.clearAllMocks();\n });\n\n it(\"should return an empty array if no destination address is provided\", async () => {\n // GIVEN\n const transaction = {} as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if no data provided\", async () => {\n // GIVEN\n const transaction = { to: \"0x0\", data: \"0x\" } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an error if selector is invalid\", async () => {\n // GIVEN\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xzf68b302000000000000000000000000000000000000000000000000000000000002\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Invalid selector\"),\n },\n ]);\n });\n\n it(\"should return an error if data source fails\", async () => {\n // GIVEN\n getTransactionDescriptorsMock.mockResolvedValue(\n Left(new Error(\"data source error\")),\n );\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(getTransactionDescriptorsMock).toHaveBeenCalledWith({\n address: \"0x7\",\n chainId: 3,\n selector: \"0xaf68b302\",\n });\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"data source error\"),\n },\n ]);\n });\n\n it(\"should return the contexts on success\", async () => {\n // GIVEN\n getTransactionDescriptorsMock.mockResolvedValue(\n Right([\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]),\n );\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]);\n });\n});\n"],
5
- "mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAE5B,OAAS,wBAAAC,MAA4B,kCAGrC,OAAS,4BAAAC,MAAgC,gDAEzC,SAAS,2BAA4B,IAAM,CACzC,MAAMC,EAAgC,GAAG,GAAG,EACtCC,EAAmD,CACvD,0BAA2BD,CAC7B,EACME,EAAS,IAAIH,EAAyBE,CAAyB,EAErE,WAAW,IAAM,CACf,GAAG,cAAc,CACnB,CAAC,EAED,GAAG,qEAAsE,SAAY,CAEnF,MAAME,EAAc,CAAC,EAGfC,EAAS,MAAMF,EAAO,KAAKC,CAAW,EAG5C,OAAOC,CAAM,EAAE,QAAQ,CAAC,CAAC,CAC3B,CAAC,EAED,GAAG,mDAAoD,SAAY,CAEjE,MAAMD,EAAc,CAAE,GAAI,MAAO,KAAM,IAAK,EAGtCC,EAAS,MAAMF,EAAO,KAAKC,CAAW,EAG5C,OAAOC,CAAM,EAAE,QAAQ,CAAC,CAAC,CAC3B,CAAC,EAED,GAAG,gDAAiD,SAAY,CAE9D,MAAMD,EAAc,CAClB,GAAI,MACJ,QAAS,EACT,KAAM,wEACR,EAGMC,EAAS,MAAMF,EAAO,KAAKC,CAAW,EAG5C,OAAOC,CAAM,EAAE,QAAQ,CACrB,CACE,KAAMN,EAAqB,MAC3B,MAAO,IAAI,MAAM,kBAAkB,CACrC,CACF,CAAC,CACH,CAAC,EAED,GAAG,8CAA+C,SAAY,CAE5DE,EAA8B,kBAC5BJ,EAAK,IAAI,MAAM,mBAAmB,CAAC,CACrC,EACA,MAAMO,EAAc,CAClB,GAAI,MACJ,QAAS,EACT,KAAM,yEACN,SAAU,YACZ,EAGMC,EAAS,MAAMF,EAAO,KAAKC,CAAW,EAG5C,OAAOH,CAA6B,EAAE,qBAAqB,CACzD,QAAS,MACT,QAAS,EACT,SAAU,YACZ,CAAC,EACD,OAAOI,CAAM,EAAE,QAAQ,CACrB,CACE,KAAMN,EAAqB,MAC3B,MAAO,IAAI,MAAM,mBAAmB,CACtC,CACF,CAAC,CACH,CAAC,EAED,GAAG,wCAAyC,SAAY,CAEtDE,EAA8B,kBAC5BH,EAAM,CACJ,CACE,KAAMC,EAAqB,iBAC3B,QAAS,YACX,EACA,CACE,KAAMA,EAAqB,8BAC3B,QAAS,UACX,CACF,CAAC,CACH,EACA,MAAMK,EAAc,CAClB,GAAI,MACJ,QAAS,EACT,KAAM,yEACN,SAAU,YACZ,EAGMC,EAAS,MAAMF,EAAO,KAAKC,CAAW,EAG5C,OAAOC,CAAM,EAAE,QAAQ,CACrB,CACE,KAAMN,EAAqB,iBAC3B,QAAS,YACX,EACA,CACE,KAAMA,EAAqB,8BAC3B,QAAS,UACX,CACF,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["Left", "Right", "ClearSignContextType", "TransactionContextLoader", "getTransactionDescriptorsMock", "mockTransactionDataSource", "loader", "transaction", "result"]
4
+ "sourcesContent": ["import { Left, Right } from \"purify-ts\";\n\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport type { TransactionContext } from \"@/shared/model/TransactionContext\";\nimport { type ProxyDataSource } from \"@/transaction/data/HttpProxyDataSource\";\nimport type { TransactionDataSource } from \"@/transaction/data/TransactionDataSource\";\nimport { TransactionContextLoader } from \"@/transaction/domain/TransactionContextLoader\";\n\ndescribe(\"TransactionContextLoader\", () => {\n const getTransactionDescriptorsMock = vi.fn();\n const getProxyDelegateCallMock = vi.fn();\n const mockTransactionDataSource: TransactionDataSource = {\n getTransactionDescriptors: getTransactionDescriptorsMock,\n };\n const mockProxyDatasource: ProxyDataSource = {\n getProxyDelegateCall: getProxyDelegateCallMock,\n getProxyImplementationAddress: vi.fn(),\n };\n const mockCertificateLoader: PkiCertificateLoader = {\n loadCertificate: vi.fn(),\n };\n const loader = new TransactionContextLoader(\n mockTransactionDataSource,\n mockProxyDatasource,\n mockCertificateLoader,\n );\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n it(\"should return an empty array if no destination address is provided\", async () => {\n // GIVEN\n const transaction = {} as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if no data provided\", async () => {\n // GIVEN\n const transaction = { to: \"0x0\", data: \"0x\" } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an error if selector is invalid\", async () => {\n // GIVEN\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xzf68b302000000000000000000000000000000000000000000000000000000000002\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Invalid selector\"),\n },\n ]);\n });\n\n it(\"should return an error if data source fails\", async () => {\n // GIVEN\n getProxyDelegateCallMock.mockResolvedValue(\n Left(new Error(\"data source error\")),\n );\n getTransactionDescriptorsMock.mockResolvedValue(\n Left(new Error(\"data source error\")),\n );\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(getTransactionDescriptorsMock).toHaveBeenCalledWith({\n address: \"0x7\",\n chainId: 3,\n selector: \"0xaf68b302\",\n });\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"data source error\"),\n },\n ]);\n });\n\n it(\"should return the contexts on success\", async () => {\n // GIVEN\n getTransactionDescriptorsMock.mockResolvedValue(\n Right([\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]),\n );\n getProxyDelegateCallMock.mockResolvedValue(\n Left(new Error(\"data source error\")),\n );\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]);\n });\n\n it(\"should return the proxy delegate call context on success\", async () => {\n // GIVEN\n getTransactionDescriptorsMock.mockResolvedValue(\n Right([\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]),\n );\n getProxyDelegateCallMock.mockResolvedValue(\n Right({\n delegateAddresses: [\"0x7\"],\n signedDescriptor: \"0x1234567890abcdef\",\n }),\n );\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.PROXY_DELEGATE_CALL,\n payload: \"0x1234567890abcdef\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]);\n });\n\n it(\"should return the proxy delegate call context if the transaction.to is in the delegate addresses and the transaction.to is not the first element\", async () => {\n // GIVEN\n getTransactionDescriptorsMock.mockResolvedValue(\n Right([\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]),\n );\n getProxyDelegateCallMock.mockResolvedValue(\n Right({\n delegateAddresses: [\"0x7\", \"0x8\"],\n signedDescriptor: \"0x1234567890abcdef\",\n }),\n );\n const transaction = {\n to: \"0x8\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.PROXY_DELEGATE_CALL,\n payload: \"0x1234567890abcdef\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]);\n });\n\n it(\"should return the proxy delegate call context if the transaction.to is not in the delegate addresses\", async () => {\n // GIVEN\n getTransactionDescriptorsMock.mockResolvedValue(\n Right([\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]),\n );\n getProxyDelegateCallMock.mockResolvedValue(\n Right({\n delegateAddresses: [\"0x8\"],\n signedDescriptor: \"0x1234567890abcdef\",\n }),\n );\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.PROXY_DELEGATE_CALL,\n payload: \"0x1234567890abcdef\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]);\n });\n});\n"],
5
+ "mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAG5B,OAAS,wBAAAC,MAA4B,kCAIrC,OAAS,4BAAAC,MAAgC,gDAEzC,SAAS,2BAA4B,IAAM,CACzC,MAAMC,EAAgC,GAAG,GAAG,EACtCC,EAA2B,GAAG,GAAG,EACjCC,EAAmD,CACvD,0BAA2BF,CAC7B,EACMG,EAAuC,CAC3C,qBAAsBF,EACtB,8BAA+B,GAAG,GAAG,CACvC,EACMG,EAA8C,CAClD,gBAAiB,GAAG,GAAG,CACzB,EACMC,EAAS,IAAIN,EACjBG,EACAC,EACAC,CACF,EAEA,WAAW,IAAM,CACf,GAAG,cAAc,CACnB,CAAC,EAED,GAAG,qEAAsE,SAAY,CAEnF,MAAME,EAAc,CAAC,EAGfC,EAAS,MAAMF,EAAO,KAAKC,CAAW,EAG5C,OAAOC,CAAM,EAAE,QAAQ,CAAC,CAAC,CAC3B,CAAC,EAED,GAAG,mDAAoD,SAAY,CAEjE,MAAMD,EAAc,CAAE,GAAI,MAAO,KAAM,IAAK,EAGtCC,EAAS,MAAMF,EAAO,KAAKC,CAAW,EAG5C,OAAOC,CAAM,EAAE,QAAQ,CAAC,CAAC,CAC3B,CAAC,EAED,GAAG,gDAAiD,SAAY,CAE9D,MAAMD,EAAc,CAClB,GAAI,MACJ,QAAS,EACT,KAAM,wEACR,EAGMC,EAAS,MAAMF,EAAO,KAAKC,CAAW,EAG5C,OAAOC,CAAM,EAAE,QAAQ,CACrB,CACE,KAAMT,EAAqB,MAC3B,MAAO,IAAI,MAAM,kBAAkB,CACrC,CACF,CAAC,CACH,CAAC,EAED,GAAG,8CAA+C,SAAY,CAE5DG,EAAyB,kBACvBL,EAAK,IAAI,MA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A,EAAqB,8BAC3B,QAAS,UACX,CACF,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["Left", "Right", "ClearSignContextType", "TransactionContextLoader", "getTransactionDescriptorsMock", "getProxyDelegateCallMock", "mockTransactionDataSource", "mockProxyDatasource", "mockCertificateLoader", "loader", "transaction", "result"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var T=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var f=(s,r,e,o)=>{for(var t=o>1?void 0:o?$(r,e):r,n=s.length-1,a;n>=0;n--)(a=s[n])&&(t=(o?a(r,e,t):a(t))||t);return o&&t&&T(r,e,t),t},l=(s,r)=>(e,o)=>r(e,o,s);import p from"axios";import{inject as y,injectable as C}from"inversify";import{Left as m,Right as c}from"purify-ts";import{configTypes as x}from"../../config/di/configTypes";import{LEDGER_CLIENT_VERSION_HEADER as h,LEDGER_ORIGIN_TOKEN_HEADER as E}from"../../shared/constant/HttpHeaders";import D from"../../../package.json";let d=class{constructor(r){this.config=r}async getDomainNamePayload({chainId:r,domain:e,challenge:o}){try{const a=await p.request({method:"GET",url:`${this.config.metadataService.url}/names/ethereum/${r}/forward/${e}?types=eoa&sources=ens&challenge=${o}`,headers:{[h]:`context-module/${D.version}`,[E]:this.config.originToken}});return a.data.signedDescriptor?.data?c(a.data.signedDescriptor.data):m(new Error("[ContextModule] HttpTrustedNameDataSource: error getting domain payload"))}catch{return m(new Error("[ContextModule] HttpTrustedNameDataSource: Failed to fetch domain name"))}}async getTrustedNamePayload({chainId:r,address:e,challenge:o,sources:t,types:n}){try{t=t.filter(g=>g==="ens"||g==="crypto_asset_list");const i=(await p.request({method:"GET",url:`${this.config.metadataService.url}/names/ethereum/${r}/reverse/${e}?types=${n.join(",")}&sources=${t.join(",")}&challenge=${o}`,headers:{[h]:`context-module/${D.version}`,[E]:this.config.originToken}})).data;if(!i?.signedDescriptor?.data)return m(new Error(`[ContextModule] HttpTrustedNameDataSource: no trusted name metadata for address ${e}`));const u=i.signedDescriptor.data;if(!i.signedDescriptor.signatures||typeof i.signedDescriptor.signatures[this.config.cal.mode]!="string")return c(u);const N=i.signedDescriptor.signatures[this.config.cal.mode];return c(this.formatTrustedName(u,N))}catch{return m(new Error("[ContextModule] HttpTrustedNameDataSource: Failed to fetch trusted name"))}}formatTrustedName(r,e){e.length%2!==0&&(e="0"+e);const o="15",t=(e.length/2).toString(16);return`${r}${o}${t}${e}`}};d=f([C(),l(0,y(x.Config))],d);export{d as HttpTrustedNameDataSource};
1
+ var T=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var f=(s,r,e,o)=>{for(var t=o>1?void 0:o?$(r,e):r,n=s.length-1,a;n>=0;n--)(a=s[n])&&(t=(o?a(r,e,t):a(t))||t);return o&&t&&T(r,e,t),t},l=(s,r)=>(e,o)=>r(e,o,s);import p from"axios";import{inject as y,injectable as C}from"inversify";import{Left as m,Right as c}from"purify-ts";import{configTypes as x}from"../../config/di/configTypes";import{LEDGER_CLIENT_VERSION_HEADER as h,LEDGER_ORIGIN_TOKEN_HEADER as E}from"../../shared/constant/HttpHeaders";import D from"../../../package.json";let d=class{constructor(r){this.config=r}async getDomainNamePayload({chainId:r,domain:e,challenge:o}){try{const a=await p.request({method:"GET",url:`${this.config.metadataServiceDomain.url}/v1/names/ethereum/${r}/forward/${e}?types=eoa&sources=ens&challenge=${o}`,headers:{[h]:`context-module/${D.version}`,[E]:this.config.originToken}});return a.data.signedDescriptor?.data?c(a.data.signedDescriptor.data):m(new Error("[ContextModule] HttpTrustedNameDataSource: error getting domain payload"))}catch{return m(new Error("[ContextModule] HttpTrustedNameDataSource: Failed to fetch domain name"))}}async getTrustedNamePayload({chainId:r,address:e,challenge:o,sources:t,types:n}){try{t=t.filter(g=>g==="ens"||g==="crypto_asset_list");const i=(await p.request({method:"GET",url:`${this.config.metadataServiceDomain.url}/v1/names/ethereum/${r}/reverse/${e}?types=${n.join(",")}&sources=${t.join(",")}&challenge=${o}`,headers:{[h]:`context-module/${D.version}`,[E]:this.config.originToken}})).data;if(!i?.signedDescriptor?.data)return m(new Error(`[ContextModule] HttpTrustedNameDataSource: no trusted name metadata for address ${e}`));const u=i.signedDescriptor.data;if(!i.signedDescriptor.signatures||typeof i.signedDescriptor.signatures[this.config.cal.mode]!="string")return c(u);const N=i.signedDescriptor.signatures[this.config.cal.mode];return c(this.formatTrustedName(u,N))}catch{return m(new Error("[ContextModule] HttpTrustedNameDataSource: Failed to fetch trusted name"))}}formatTrustedName(r,e){e.length%2!==0&&(e="0"+e);const o="15",t=(e.length/2).toString(16);return`${r}${o}${t}${e}`}};d=f([C(),l(0,y(x.Config))],d);export{d as HttpTrustedNameDataSource};
2
2
  //# sourceMappingURL=HttpTrustedNameDataSource.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/trusted-name/data/HttpTrustedNameDataSource.ts"],
4
- "sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport type { ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport {\n GetDomainNameInfosParams,\n GetTrustedNameInfosParams,\n TrustedNameDataSource,\n} from \"@/trusted-name/data/TrustedNameDataSource\";\nimport PACKAGE from \"@root/package.json\";\n\nimport { TrustedNameDto } from \"./TrustedNameDto\";\n\n@injectable()\nexport class HttpTrustedNameDataSource implements TrustedNameDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n ) {}\n\n public async getDomainNamePayload({\n chainId,\n domain,\n challenge,\n }: GetDomainNameInfosParams): Promise<Either<Error, string>> {\n try {\n const type = \"eoa\"; // Externally owned account\n const source = \"ens\"; // Ethereum name service\n const response = await axios.request<TrustedNameDto>({\n method: \"GET\",\n url: `${this.config.metadataService.url}/names/ethereum/${chainId}/forward/${domain}?types=${type}&sources=${source}&challenge=${challenge}`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n\n return response.data.signedDescriptor?.data\n ? Right(response.data.signedDescriptor.data)\n : Left(\n new Error(\n \"[ContextModule] HttpTrustedNameDataSource: error getting domain payload\",\n ),\n );\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] HttpTrustedNameDataSource: Failed to fetch domain name\",\n ),\n );\n }\n }\n\n public async getTrustedNamePayload({\n chainId,\n address,\n challenge,\n sources,\n types,\n }: GetTrustedNameInfosParams): Promise<Either<Error, string>> {\n try {\n // TODO remove that filtering once https://ledgerhq.atlassian.net/browse/BACK-8075 is done\n // For now we have to filter or trusted names won't work with the generic parser, because transaction\n // fields descriptors can contain unsupported sources.\n sources = sources.filter(\n (source) => source === \"ens\" || source === \"crypto_asset_list\",\n );\n const response = await axios.request<TrustedNameDto>({\n method: \"GET\",\n url: `${this.config.metadataService.url}/names/ethereum/${chainId}/reverse/${address}?types=${types.join(\",\")}&sources=${sources.join(\",\")}&challenge=${challenge}`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n const trustedName = response.data;\n if (!trustedName?.signedDescriptor?.data) {\n return Left(\n new Error(\n `[ContextModule] HttpTrustedNameDataSource: no trusted name metadata for address ${address}`,\n ),\n );\n }\n const payload = trustedName.signedDescriptor.data;\n\n if (\n !trustedName.signedDescriptor.signatures ||\n typeof trustedName.signedDescriptor.signatures[this.config.cal.mode] !==\n \"string\"\n ) {\n // If we have no separated signature but a valid descriptor, it may mean the descriptor was\n // signed on-the-fly for dynamic sources such as ens\n return Right(payload);\n }\n\n const signature =\n trustedName.signedDescriptor.signatures[this.config.cal.mode]!;\n return Right(this.formatTrustedName(payload, signature));\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] HttpTrustedNameDataSource: Failed to fetch trusted name\",\n ),\n );\n }\n }\n\n private formatTrustedName(payload: string, signature: string): string {\n // Ensure correct padding\n if (signature.length % 2 !== 0) {\n signature = \"0\" + signature;\n }\n // TLV encoding as according to trusted name documentation\n const signatureTag = \"15\";\n const signatureLength = (signature.length / 2).toString(16);\n return `${payload}${signatureTag}${signatureLength}${signature}`;\n }\n}\n"],
5
- "mappings": "iOAAA,OAAOA,MAAW,QAClB,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YACnC,OAAiB,QAAAC,EAAM,SAAAC,MAAa,YAEpC,OAAS,eAAAC,MAAmB,0BAE5B,OACE,gCAAAC,EACA,8BAAAC,MACK,gCAMP,OAAOC,MAAa,qBAKb,IAAMC,EAAN,KAAiE,CACtE,YAC+CC,EAC7C,CAD6C,YAAAA,CAC5C,CAEH,MAAa,qBAAqB,CAChC,QAAAC,EACA,OAAAC,EACA,UAAAC,CACF,EAA6D,CAC3D,GAAI,CAGF,MAAMC,EAAW,MAAMC,EAAM,QAAwB,CACnD,OAAQ,MACR,IAAK,GAAG,KAAK,OAAO,gBAAgB,GAAG,mBAAmBJ,CAAO,YAAYC,CAAM,oCAA8CC,CAAS,GAC1I,QAAS,CACP,CAACG,CAA4B,EAAG,kBAAkBC,EAAQ,OAAO,GACjE,CAACC,CAA0B,EAAG,KAAK,OAAO,WAC5C,CACF,CAAC,EAED,OAAOJ,EAAS,KAAK,kBAAkB,KACnCK,EAAML,EAAS,KAAK,iBAAiB,IAAI,EACzCM,EACE,IAAI,MACF,yEACF,CACF,CACN,MAAiB,CACf,OAAOA,EACL,IAAI,MACF,wEACF,CACF,CACF,CACF,CAEA,MAAa,sBAAsB,CACjC,QAAAT,EACA,QAAAU,EACA,UAAAR,EACA,QAAAS,EACA,MAAAC,CACF,EAA8D,CAC5D,GAAI,CAIFD,EAAUA,EAAQ,OACfE,GAAWA,IAAW,OAASA,IAAW,mBAC7C,EASA,MAAMC,GARW,MAAMV,EAAM,QAAwB,CACnD,OAAQ,MACR,IAAK,GAAG,KAAK,OAAO,gBAAgB,GAAG,mBAAmBJ,CAAO,YAAYU,CAAO,UAAUE,EAAM,KAAK,GAAG,CAAC,YAAYD,EAAQ,KAAK,GAAG,CAAC,cAAcT,CAAS,GACjK,QAAS,CACP,CAACG,CAA4B,EAAG,kBAAkBC,EAAQ,OAAO,GACjE,CAACC,CAA0B,EAAG,KAAK,OAAO,WAC5C,CACF,CAAC,GAC4B,KAC7B,GAAI,CAACO,GAAa,kBAAkB,KAClC,OAAOL,EACL,IAAI,MACF,mFAAmFC,CAAO,EAC5F,CACF,EAEF,MAAMK,EAAUD,EAAY,iBAAiB,KAE7C,GACE,CAACA,EAAY,iBAAiB,YAC9B,OAAOA,EAAY,iBAAiB,WAAW,KAAK,OAAO,IAAI,IAAI,GACjE,SAIF,OAAON,EAAMO,CAAO,EAGtB,MAAMC,EACJF,EAAY,iBAAiB,WAAW,KAAK,OAAO,IAAI,IAAI,EAC9D,OAAON,EAAM,KAAK,kBAAkBO,EAASC,CAAS,CAAC,CACzD,MAAiB,CACf,OAAOP,EACL,IAAI,MACF,yEACF,CACF,CACF,CACF,CAEQ,kBAAkBM,EAAiBC,EAA2B,CAEhEA,EAAU,OAAS,IAAM,IAC3BA,EAAY,IAAMA,GAGpB,MAAMC,EAAe,KACfC,GAAmBF,EAAU,OAAS,GAAG,SAAS,EAAE,EAC1D,MAAO,GAAGD,CAAO,GAAGE,CAAY,GAAGC,CAAe,GAAGF,CAAS,EAChE,CACF,EAtGalB,EAANqB,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAY,MAAM,IAFjBzB",
4
+ "sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport type { ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport {\n GetDomainNameInfosParams,\n GetTrustedNameInfosParams,\n TrustedNameDataSource,\n} from \"@/trusted-name/data/TrustedNameDataSource\";\nimport PACKAGE from \"@root/package.json\";\n\nimport { TrustedNameDto } from \"./TrustedNameDto\";\n\n@injectable()\nexport class HttpTrustedNameDataSource implements TrustedNameDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n ) {}\n\n public async getDomainNamePayload({\n chainId,\n domain,\n challenge,\n }: GetDomainNameInfosParams): Promise<Either<Error, string>> {\n try {\n const type = \"eoa\"; // Externally owned account\n const source = \"ens\"; // Ethereum name service\n const response = await axios.request<TrustedNameDto>({\n method: \"GET\",\n url: `${this.config.metadataServiceDomain.url}/v1/names/ethereum/${chainId}/forward/${domain}?types=${type}&sources=${source}&challenge=${challenge}`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n\n return response.data.signedDescriptor?.data\n ? Right(response.data.signedDescriptor.data)\n : Left(\n new Error(\n \"[ContextModule] HttpTrustedNameDataSource: error getting domain payload\",\n ),\n );\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] HttpTrustedNameDataSource: Failed to fetch domain name\",\n ),\n );\n }\n }\n\n public async getTrustedNamePayload({\n chainId,\n address,\n challenge,\n sources,\n types,\n }: GetTrustedNameInfosParams): Promise<Either<Error, string>> {\n try {\n // TODO remove that filtering once https://ledgerhq.atlassian.net/browse/BACK-8075 is done\n // For now we have to filter or trusted names won't work with the generic parser, because transaction\n // fields descriptors can contain unsupported sources.\n sources = sources.filter(\n (source) => source === \"ens\" || source === \"crypto_asset_list\",\n );\n const response = await axios.request<TrustedNameDto>({\n method: \"GET\",\n url: `${this.config.metadataServiceDomain.url}/v1/names/ethereum/${chainId}/reverse/${address}?types=${types.join(\",\")}&sources=${sources.join(\",\")}&challenge=${challenge}`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n const trustedName = response.data;\n if (!trustedName?.signedDescriptor?.data) {\n return Left(\n new Error(\n `[ContextModule] HttpTrustedNameDataSource: no trusted name metadata for address ${address}`,\n ),\n );\n }\n const payload = trustedName.signedDescriptor.data;\n\n if (\n !trustedName.signedDescriptor.signatures ||\n typeof trustedName.signedDescriptor.signatures[this.config.cal.mode] !==\n \"string\"\n ) {\n // If we have no separated signature but a valid descriptor, it may mean the descriptor was\n // signed on-the-fly for dynamic sources such as ens\n return Right(payload);\n }\n\n const signature =\n trustedName.signedDescriptor.signatures[this.config.cal.mode]!;\n return Right(this.formatTrustedName(payload, signature));\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] HttpTrustedNameDataSource: Failed to fetch trusted name\",\n ),\n );\n }\n }\n\n private formatTrustedName(payload: string, signature: string): string {\n // Ensure correct padding\n if (signature.length % 2 !== 0) {\n signature = \"0\" + signature;\n }\n // TLV encoding as according to trusted name documentation\n const signatureTag = \"15\";\n const signatureLength = (signature.length / 2).toString(16);\n return `${payload}${signatureTag}${signatureLength}${signature}`;\n }\n}\n"],
5
+ "mappings": "iOAAA,OAAOA,MAAW,QAClB,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YACnC,OAAiB,QAAAC,EAAM,SAAAC,MAAa,YAEpC,OAAS,eAAAC,MAAmB,0BAE5B,OACE,gCAAAC,EACA,8BAAAC,MACK,gCAMP,OAAOC,MAAa,qBAKb,IAAMC,EAAN,KAAiE,CACtE,YAC+CC,EAC7C,CAD6C,YAAAA,CAC5C,CAEH,MAAa,qBAAqB,CAChC,QAAAC,EACA,OAAAC,EACA,UAAAC,CACF,EAA6D,CAC3D,GAAI,CAGF,MAAMC,EAAW,MAAMC,EAAM,QAAwB,CAC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S,CAAC,CACzD,MAAiB,CACf,OAAOP,EACL,IAAI,MACF,yEACF,CACF,CACF,CACF,CAEQ,kBAAkBM,EAAiBC,EAA2B,CAEhEA,EAAU,OAAS,IAAM,IAC3BA,EAAY,IAAMA,GAGpB,MAAMC,EAAe,KACfC,GAAmBF,EAAU,OAAS,GAAG,SAAS,EAAE,EAC1D,MAAO,GAAGD,CAAO,GAAGE,CAAY,GAAGC,CAAe,GAAGF,CAAS,EAChE,CACF,EAtGalB,EAANqB,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAY,MAAM,IAFjBzB",
6
6
  "names": ["axios", "inject", "injectable", "Left", "Right", "configTypes", "LEDGER_CLIENT_VERSION_HEADER", "LEDGER_ORIGIN_TOKEN_HEADER", "PACKAGE", "HttpTrustedNameDataSource", "config", "chainId", "domain", "challenge", "response", "axios", "LEDGER_CLIENT_VERSION_HEADER", "PACKAGE", "LEDGER_ORIGIN_TOKEN_HEADER", "Right", "Left", "address", "sources", "types", "source", "trustedName", "payload", "signature", "signatureTag", "signatureLength", "__decorateClass", "injectable", "__decorateParam", "inject", "configTypes"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import o from"axios";import{Left as r,Right as s}from"purify-ts";import{LEDGER_CLIENT_VERSION_HEADER as l,LEDGER_ORIGIN_TOKEN_HEADER as d}from"../../shared/constant/HttpHeaders";import{HttpTrustedNameDataSource as c}from"../../trusted-name/data/HttpTrustedNameDataSource";import i from"../../../package.json";vi.mock("axios");const n={cal:{url:"https://crypto-assets-service.api.ledger.com/v1",mode:"prod",branch:"main"},metadataService:{url:"https://nft.api.live.ledger.com/v2"},originToken:"originToken"};describe("HttpTrustedNameDataSource",()=>{let t;beforeAll(()=>{t=new c(n),vi.clearAllMocks()}),describe("getDomainNamePayload",()=>{it("should call axios with the correct url and ledger client version header",async()=>{const e=`context-module/${i.version}`,a=vi.fn(()=>Promise.resolve({data:[]}));vi.spyOn(o,"request").mockImplementation(a),await t.getDomainNamePayload({chainId:137,challenge:"9876",domain:"hello.eth"}),expect(a).toHaveBeenCalledWith(expect.objectContaining({url:"https://nft.api.live.ledger.com/v2/names/ethereum/137/forward/hello.eth?types=eoa&sources=ens&challenge=9876",headers:{[l]:e,[d]:n.originToken}}))}),it("should throw an error when axios throws an error",async()=>{vi.spyOn(o,"request").mockRejectedValue(new Error);const e=await t.getDomainNamePayload({chainId:137,challenge:"",domain:"hello.eth"});expect(e).toEqual(r(new Error("[ContextModule] HttpTrustedNameDataSource: Failed to fetch domain name")))}),it("should return an error when no payload is returned",async()=>{const e={data:{test:""}};vi.spyOn(o,"request").mockResolvedValue(e);const a=await t.getDomainNamePayload({chainId:137,challenge:"",domain:"hello.eth"});expect(a).toEqual(r(new Error("[ContextModule] HttpTrustedNameDataSource: error getting domain payload")))}),it("should return a payload",async()=>{const e={data:{signedDescriptor:{data:"payload"}}};vi.spyOn(o,"request").mockResolvedValue(e);const a=await t.getDomainNamePayload({chainId:137,challenge:"challenge",domain:"hello.eth"});expect(a).toEqual(s("payload"))})}),describe("getTrustedNamePayload",()=>{it("should call axios with the correct url and ledger client version header",async()=>{const e=`context-module/${i.version}`,a=vi.fn(()=>Promise.resolve({data:[]}));vi.spyOn(o,"request").mockImplementation(a),await t.getTrustedNamePayload({chainId:137,address:"0x1234",challenge:"5678",sources:["ens","crypto_asset_list"],types:["eoa"]}),expect(a).toHaveBeenCalledWith(expect.objectContaining({url:"https://nft.api.live.ledger.com/v2/names/ethereum/137/reverse/0x1234?types=eoa&sources=ens,crypto_asset_list&challenge=5678",headers:{[l]:e,[d]:n.originToken}}))}),it("should throw an error when axios throws an error",async()=>{vi.spyOn(o,"request").mockRejectedValue(new Error);const e=await t.getTrustedNamePayload({chainId:137,address:"0x1234",challenge:"",sources:["ens"],types:["eoa"]});expect(e).toEqual(r(new Error("[ContextModule] HttpTrustedNameDataSource: Failed to fetch trusted name")))}),it("should return an error when no payload is returned",async()=>{const e={data:{test:""}};vi.spyOn(o,"request").mockResolvedValue(e);const a=await t.getTrustedNamePayload({chainId:137,address:"0x1234",challenge:"",sources:["ens"],types:["eoa"]});expect(a).toEqual(r(new Error("[ContextModule] HttpTrustedNameDataSource: no trusted name metadata for address 0x1234")))}),it("should return a payload",async()=>{const e={data:{signedDescriptor:{data:"payload"}}};vi.spyOn(o,"request").mockResolvedValue(e);const a=await t.getTrustedNamePayload({chainId:137,address:"0x1234",challenge:"",sources:["ens"],types:["eoa"]});expect(a).toEqual(s("payload"))}),it("should return a payload with a signature",async()=>{const e={data:{signedDescriptor:{data:"payload",signatures:{prod:"12345"}}}};vi.spyOn(o,"request").mockResolvedValue(e);const a=await t.getTrustedNamePayload({chainId:137,address:"0x1234",challenge:"",sources:["ens"],types:["eoa"]});expect(a).toEqual(s("payload153012345"))})})});
1
+ import o from"axios";import{Left as r,Right as s}from"purify-ts";import{LEDGER_CLIENT_VERSION_HEADER as l,LEDGER_ORIGIN_TOKEN_HEADER as d}from"../../shared/constant/HttpHeaders";import{HttpTrustedNameDataSource as c}from"../../trusted-name/data/HttpTrustedNameDataSource";import i from"../../../package.json";vi.mock("axios");const n={cal:{url:"https://crypto-assets-service.api.ledger.com/v1",mode:"prod",branch:"main"},metadataServiceDomain:{url:"https://nft.api.live.ledger.com"},originToken:"originToken"};describe("HttpTrustedNameDataSource",()=>{let t;beforeAll(()=>{t=new c(n),vi.clearAllMocks()}),describe("getDomainNamePayload",()=>{it("should call axios with the correct url and ledger client version header",async()=>{const e=`context-module/${i.version}`,a=vi.fn(()=>Promise.resolve({data:[]}));vi.spyOn(o,"request").mockImplementation(a),await t.getDomainNamePayload({chainId:137,challenge:"9876",domain:"hello.eth"}),expect(a).toHaveBeenCalledWith(expect.objectContaining({url:"https://nft.api.live.ledger.com/v1/names/ethereum/137/forward/hello.eth?types=eoa&sources=ens&challenge=9876",headers:{[l]:e,[d]:n.originToken}}))}),it("should throw an error when axios throws an error",async()=>{vi.spyOn(o,"request").mockRejectedValue(new Error);const e=await t.getDomainNamePayload({chainId:137,challenge:"",domain:"hello.eth"});expect(e).toEqual(r(new Error("[ContextModule] HttpTrustedNameDataSource: Failed to fetch domain name")))}),it("should return an error when no payload is returned",async()=>{const e={data:{test:""}};vi.spyOn(o,"request").mockResolvedValue(e);const a=await t.getDomainNamePayload({chainId:137,challenge:"",domain:"hello.eth"});expect(a).toEqual(r(new Error("[ContextModule] HttpTrustedNameDataSource: error getting domain payload")))}),it("should return a payload",async()=>{const e={data:{signedDescriptor:{data:"payload"}}};vi.spyOn(o,"request").mockResolvedValue(e);const a=await t.getDomainNamePayload({chainId:137,challenge:"challenge",domain:"hello.eth"});expect(a).toEqual(s("payload"))})}),describe("getTrustedNamePayload",()=>{it("should call axios with the correct url and ledger client version header",async()=>{const e=`context-module/${i.version}`,a=vi.fn(()=>Promise.resolve({data:[]}));vi.spyOn(o,"request").mockImplementation(a),await t.getTrustedNamePayload({chainId:137,address:"0x1234",challenge:"5678",sources:["ens","crypto_asset_list"],types:["eoa"]}),expect(a).toHaveBeenCalledWith(expect.objectContaining({url:"https://nft.api.live.ledger.com/v1/names/ethereum/137/reverse/0x1234?types=eoa&sources=ens,crypto_asset_list&challenge=5678",headers:{[l]:e,[d]:n.originToken}}))}),it("should throw an error when axios throws an error",async()=>{vi.spyOn(o,"request").mockRejectedValue(new Error);const e=await t.getTrustedNamePayload({chainId:137,address:"0x1234",challenge:"",sources:["ens"],types:["eoa"]});expect(e).toEqual(r(new Error("[ContextModule] HttpTrustedNameDataSource: Failed to fetch trusted name")))}),it("should return an error when no payload is returned",async()=>{const e={data:{test:""}};vi.spyOn(o,"request").mockResolvedValue(e);const a=await t.getTrustedNamePayload({chainId:137,address:"0x1234",challenge:"",sources:["ens"],types:["eoa"]});expect(a).toEqual(r(new Error("[ContextModule] HttpTrustedNameDataSource: no trusted name metadata for address 0x1234")))}),it("should return a payload",async()=>{const e={data:{signedDescriptor:{data:"payload"}}};vi.spyOn(o,"request").mockResolvedValue(e);const a=await t.getTrustedNamePayload({chainId:137,address:"0x1234",challenge:"",sources:["ens"],types:["eoa"]});expect(a).toEqual(s("payload"))}),it("should return a payload with a signature",async()=>{const e={data:{signedDescriptor:{data:"payload",signatures:{prod:"12345"}}}};vi.spyOn(o,"request").mockResolvedValue(e);const a=await t.getTrustedNamePayload({chainId:137,address:"0x1234",challenge:"",sources:["ens"],types:["eoa"]});expect(a).toEqual(s("payload153012345"))})})});
2
2
  //# sourceMappingURL=HttpTrustedNameDataSource.test.js.map