@ledgerhq/context-module 0.0.0-ledger-button-20250808091712 → 0.0.0-ledger-button-20250821135213

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 +5 -5
@@ -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": "wdAEA,IAAAA,EAGO,2CACPC,EAAkB,oBAClBC,EAAqB,qBAGrBC,EAA6C,yCAC7CC,EAA8C,uDAE9CC,EAAoB,iCAEpB,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,gBAAiB,CAAE,IAAK,sBAAuB,EAC/C,YAAa,mBACf,EAEMC,EAAsBL,EAAY,iBAAiB,EACnDM,EAAe,CACnB,aAAc,gBACd,MAAO,gBACP,SAAU,mBACV,iBAAkBD,CACpB,EAEA,WAAW,IAAM,CACf,GAAG,cAAc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,gBAAc,KAC7B,aAAc,OACd,UAAW,SACX,UAAW,CACT,QAAS,eACT,YAAa,WACf,CACF,EAGME,EAAS,MADI,IAAI,gCAA8BL,CAAM,EAC3B,aAAaG,CAAO,EAEpD,OAAOE,CAAM,EAAE,WACb,QACE,IAAI,MACF,gGACF,CACF,CACF,CACF,CAAC,EAED,GAAG,yCAA0C,IAAM,CACjD,OAAO,IAAM,CACX,IAAI,gCAA8B,CAChC,GAAGL,EACH,YAAa,MACf,CAAQ,CACV,CAAC,EAAE,QACD,2EACF,CACF,CAAC,EAED,GAAG,yCAA0C,SAAY,CACvD,MAAMG,EAAoC,CACxC,cAAe,gBAAc,KAC7B,aAAc,aACd,UAAW,SACX,UAAW,MACb,EACMG,EAAM,GACT,MAAM,EAAAF,QAAO,SAAS,EACtB,sBAAsB,CAAE,KAAMF,CAAa,CAAC,EAG/C,MADmB,IAAI,gCAA8BF,CAAM,EAC1C,aAAaG,CAAO,EAErC,OAAOG,CAAG,EAAE,qBACV,OAAO,iBAAiB,CACtB,QAAS,CACP,CAAC,8BAA4B,EAAG,kBAAkB,EAAAC,QAAQ,OAAO,GACjE,yBAA0BP,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\":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B,CACtB,QAAS,CACP,CAAC,8BAA4B,EAAG,kBAAkB,EAAAC,QAAQ,OAAO,GACjE,yBAA0BP,EAAO,WACnC,CACF,CAAC,CACH,CACF,CAAC,CACH,CAAC",
6
6
  "names": ["import_device_management_kit", "import_axios", "import_purify_ts", "import_HttpHeaders", "import_HttpSolanaOwnerInfoDataSource", "import_package", "stringToHex", "str", "bytes", "byte", "config", "signedDescriptorHex", "responseData", "context", "axios", "result", "spy", "PACKAGE"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var C=Object.create;var d=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var A=Object.getPrototypeOf,h=Object.prototype.hasOwnProperty;var I=(t,e)=>{for(var r in e)d(t,r,{get:e[r],enumerable:!0})},c=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of E(e))!h.call(t,o)&&o!==r&&d(t,o,{get:()=>e[o],enumerable:!(n=g(e,o))||n.enumerable});return t};var P=(t,e,r)=>(r=t!=null?C(A(t)):{},c(e||!t||!t.__esModule?d(r,"default",{value:t,enumerable:!0}):r,t)),$=t=>c(d({},"__esModule",{value:!0}),t),f=(t,e,r,n)=>{for(var o=n>1?void 0:n?g(e,r):e,s=t.length-1,p;s>=0;s--)(p=t[s])&&(o=(n?p(e,r,o):p(o))||o);return n&&o&&d(e,r,o),o},D=(t,e)=>(r,n)=>e(r,n,t);var G={};I(G,{HttpProxyDataSource:()=>l});module.exports=$(G);var y=P(require("axios")),m=require("inversify"),a=require("purify-ts"),u=require("../../config/di/configTypes"),i=require("../../shared/constant/HttpHeaders"),x=P(require("../../../package.json"));let l=class{constructor(e){this.config=e}async getProxyDelegateCall({proxyAddress:e,calldata:r,chainId:n}){let o;try{o=(await y.default.request({method:"POST",url:`${this.config.metadataService.url}/ethereum/${n}/contract/proxy/delegate`,headers:{[i.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${x.default.version}`,[i.LEDGER_ORIGIN_TOKEN_HEADER]:this.config.originToken},data:{proxy:e,data:r}})).data}catch{return(0,a.Left)(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy"))}return o?this.isProxyDelegateCallDto(o)?(0,a.Right)(o):(0,a.Left)(new Error(`[ContextModule] HttpProxyDataSource: Invalid proxy delegate call response format for proxy ${e} on chain ${n}`)):(0,a.Left)(new Error(`[ContextModule] HttpProxyDataSource: No data received for proxy ${e} on chain ${n}`))}async getProxyImplementationAddress({proxyAddress:e,chainId:r}){let n;try{n=(await y.default.request({method:"GET",url:`${this.config.metadataService.url}/ethereum/${r}/contract/proxy/${e}`,headers:{[i.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${x.default.version}`,[i.LEDGER_ORIGIN_TOKEN_HEADER]:this.config.originToken}})).data}catch{return(0,a.Left)(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch implementation address"))}return n?this.isProxyImplementationAddressDto(n)?(0,a.Right)({implementationAddress:n.implementationAddress}):(0,a.Left)(new Error(`[ContextModule] HttpProxyDataSource: Invalid proxy implementation address response format for proxy ${e} on chain ${r}`)):(0,a.Left)(new Error(`[ContextModule] HttpProxyDataSource: No data received for proxy ${e} on chain ${r}`))}isProxyDelegateCallDto(e){return typeof e=="object"&&e!==null&&"delegateAddresses"in e&&"signedDescriptor"in e&&Array.isArray(e.delegateAddresses)&&e.delegateAddresses.every(r=>typeof r=="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}};l=f([(0,m.injectable)(),D(0,(0,m.inject)(u.configTypes.Config))],l);0&&(module.exports={HttpProxyDataSource});
1
+ "use strict";var E=Object.create;var l=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var h=Object.getPrototypeOf,A=Object.prototype.hasOwnProperty;var I=(t,e)=>{for(var r in e)l(t,r,{get:e[r],enumerable:!0})},g=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of C(e))!A.call(t,n)&&n!==r&&l(t,n,{get:()=>e[n],enumerable:!(o=c(e,n))||o.enumerable});return t};var P=(t,e,r)=>(r=t!=null?E(h(t)):{},g(e||!t||!t.__esModule?l(r,"default",{value:t,enumerable:!0}):r,t)),$=t=>g(l({},"__esModule",{value:!0}),t),f=(t,e,r,o)=>{for(var n=o>1?void 0:o?c(e,r):e,i=t.length-1,d;i>=0;i--)(d=t[i])&&(n=(o?d(e,r,n):d(n))||n);return o&&n&&l(e,r,n),n},D=(t,e)=>(r,o)=>e(r,o,t);var G={};I(G,{HttpProxyDataSource:()=>m});module.exports=$(G);var y=P(require("axios")),p=require("inversify"),a=require("purify-ts"),u=require("../../config/di/configTypes"),s=require("../../shared/constant/HttpHeaders"),x=P(require("../../../package.json"));let m=class{constructor(e){this.config=e}async getProxyDelegateCall({proxyAddress:e,calldata:r,chainId:o,challenge:n}){let i;try{i=(await y.default.request({method:"POST",url:`${this.config.metadataServiceDomain.url}/v1/ethereum/${o}/contract/proxy/delegate`,headers:{[s.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${x.default.version}`,[s.LEDGER_ORIGIN_TOKEN_HEADER]:this.config.originToken},data:{proxy:e,data:r,challenge:n}})).data}catch{return(0,a.Left)(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy"))}return i?this.isProxyDelegateCallDto(i)?(0,a.Right)({delegateAddresses:i.addresses,signedDescriptor:i.signedDescriptor}):(0,a.Left)(new Error(`[ContextModule] HttpProxyDataSource: Invalid proxy delegate call response format for proxy ${e} on chain ${o}`)):(0,a.Left)(new Error(`[ContextModule] HttpProxyDataSource: No data received for proxy ${e} on chain ${o}`))}async getProxyImplementationAddress({proxyAddress:e,chainId:r}){let o;try{o=(await y.default.request({method:"GET",url:`${this.config.metadataServiceDomain.url}/v1/ethereum/${r}/contract/proxy/${e}`,headers:{[s.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${x.default.version}`,[s.LEDGER_ORIGIN_TOKEN_HEADER]:this.config.originToken}})).data}catch{return(0,a.Left)(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch implementation address"))}return o?this.isProxyImplementationAddressDto(o)?(0,a.Right)({implementationAddress:o.implementationAddress}):(0,a.Left)(new Error(`[ContextModule] HttpProxyDataSource: Invalid proxy implementation address response format for proxy ${e} on chain ${r}`)):(0,a.Left)(new Error(`[ContextModule] HttpProxyDataSource: No data received for proxy ${e} on chain ${r}`))}isProxyDelegateCallDto(e){return typeof e=="object"&&e!==null&&"addresses"in e&&"signedDescriptor"in e&&Array.isArray(e.addresses)&&e.addresses.every(r=>typeof r=="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}};m=f([(0,p.injectable)(),D(0,(0,p.inject)(u.configTypes.Config))],m);0&&(module.exports={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": "qtBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,yBAAAE,IAAA,eAAAC,EA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AG,KAQtC,SAAM,CAAE,sBAAuBA,EAAI,qBAAsB,CAAC,KAPxD,QACL,IAAI,MACF,uGAAuGH,CAAY,aAAaE,CAAO,EACzI,CACF,KAZO,QACL,IAAI,MACF,mEAAmEF,CAAY,aAAaE,CAAO,EACrG,CACF,CAYJ,CAKQ,uBACNI,EAC+B,CAC/B,OACE,OAAOA,GAAU,UACjBA,IAAU,MACV,sBAAuBA,GACvB,qBAAsBA,GACtB,MAAM,QAAQA,EAAM,iBAAiB,GACrCA,EAAM,kBAAkB,MAAOC,GAAY,OAAOA,GAAY,QAAQ,GACtE,OAAOD,EAAM,kBAAqB,QAEtC,CAKQ,gCACNA,EACwC,CACxC,OACE,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,EAnIaR,EAANU,EAAA,IADN,cAAW,EAGPC,EAAA,eAAO,cAAY,MAAM,IAFjBX",
6
- "names": ["HttpProxyDataSource_exports", "__export", "HttpProxyDataSource", "__toCommonJS", "import_axios", "import_inversify", "import_purify_ts", "import_configTypes", "import_HttpHeaders", "import_package", "HttpProxyDataSource", "config", "proxyAddress", "calldata", "chainId", "dto", "axios", "PACKAGE", "value", "address", "__decorateClass", "__decorateParam"]
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.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A4B,EAAG,kBAAkB,EAAAM,QAAQ,OAAO,GACjE,CAAC,4BAA0B,EAAG,KAAK,OAAO,WAC5C,CACF,CAAC,GACc,IACjB,MAAiB,CACf,SAAO,QACL,IAAI,MACF,6EACF,CACF,CACF,CAEA,OAAKF,EAQA,KAAK,gCAAgCA,CAAG,KAQtC,SAAM,CAAE,sBAAuBA,EAAI,qBAAsB,CAAC,KAPxD,QACL,IAAI,MACF,uGAAuGJ,CAAY,aAAaE,CAAO,EACzI,CACF,KAZO,QACL,IAAI,MACF,mEAAmEF,CAAY,aAAaE,CAAO,EACrG,CACF,CAYJ,CAKQ,uBACNK,EAC+B,CAC/B,OACE,OAAOA,GAAU,UACjBA,IAAU,MACV,cAAeA,GACf,qBAAsBA,GACtB,MAAM,QAAQA,EAAM,SAAS,GAC7BA,EAAM,UAAU,MAAOC,GAAY,OAAOA,GAAY,QAAQ,GAC9D,OAAOD,EAAM,kBAAqB,QAEtC,CAKQ,gCACNA,EACwC,CACxC,OACE,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,EAxIaT,EAANW,EAAA,IADN,cAAW,EAGPC,EAAA,eAAO,cAAY,MAAM,IAFjBZ",
6
+ "names": ["HttpProxyDataSource_exports", "__export", "HttpProxyDataSource", "__toCommonJS", "import_axios", "import_inversify", "import_purify_ts", "import_configTypes", "import_HttpHeaders", "import_package", "HttpProxyDataSource", "config", "proxyAddress", "calldata", "chainId", "challenge", "dto", "axios", "PACKAGE", "value", "address", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var f=Object.create;var m=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,P=Object.prototype.hasOwnProperty;var C=(o,t,r,d)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of v(t))!P.call(o,n)&&n!==r&&m(o,n,{get:()=>t[n],enumerable:!(d=h(t,n))||d.enumerable});return o};var x=(o,t,r)=>(r=o!=null?f(g(o)):{},C(t||!o||!o.__esModule?m(r,"default",{value:o,enumerable:!0}):r,o));var a=x(require("axios")),s=require("purify-ts"),c=require("../../shared/constant/HttpHeaders"),p=x(require("../../../package.json")),u=require("./HttpProxyDataSource");vi.mock("axios");describe("HttpProxyDataSource",()=>{const o={web3checks:{url:"web3checksUrl"},originToken:"originToken"};let t;const r={proxyAddress:"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0",calldata:"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000",chainId:1},d={proxyAddress:"0xee6a57ec80ea46401049e92587e52f5ec1c24785",chainId:1},n={delegateAddresses:["0xd9db270c1b5e3bd161e8c8503c55ceabee709552"],signedDescriptor:"0x1234567890abcdef"},y={implementationAddress:"0x91ae842a5ffd8d12023116943e72a606179294f3"},l={implementationAddress:"0x91ae842a5ffd8d12023116943e72a606179294f3",proxyAddress:"0xee6a57ec80ea46401049e92587e52f5ec1c24785",standard:"proxy"};beforeEach(()=>{vi.clearAllMocks(),t=new u.HttpProxyDataSource({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/${p.default.version}`,i=vi.fn(()=>Promise.resolve({data:n}));vi.spyOn(a.default,"request").mockImplementation(i),await t.getProxyDelegateCall(r),expect(i).toHaveBeenCalledWith(expect.objectContaining({headers:{[c.LEDGER_CLIENT_VERSION_HEADER]:e,[c.LEDGER_ORIGIN_TOKEN_HEADER]:o.originToken}}))}),it("should return the delegate proxy response on success",async()=>{vi.spyOn(a.default,"request").mockResolvedValue({data:n});const e=await t.getProxyDelegateCall(r);expect(e).toEqual((0,s.Right)(n))}),it("should return an error when axios throws an error",async()=>{vi.spyOn(a.default,"request").mockRejectedValue(new Error("fail"));const e=await t.getProxyDelegateCall(r);expect(e).toEqual((0,s.Left)(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy")))}),it("should return an error if response shape is invalid",async()=>{vi.spyOn(a.default,"request").mockResolvedValue({data:{foo:"bar"}});const e=await t.getProxyDelegateCall(r);expect(e).toEqual((0,s.Left)(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:n}));vi.spyOn(a.default,"request").mockImplementation(e);const i={proxyAddress:"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0",calldata:"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000",chainId:137};await t.getProxyDelegateCall(i),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.default,"request").mockResolvedValue({data:void 0});const e=await t.getProxyDelegateCall(r);expect(e).toEqual((0,s.Left)(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/${p.default.version}`,i=vi.fn(()=>Promise.resolve({data:l}));vi.spyOn(a.default,"request").mockImplementation(i),await t.getProxyImplementationAddress(d),expect(i).toHaveBeenCalledWith(expect.objectContaining({headers:{[c.LEDGER_CLIENT_VERSION_HEADER]:e,[c.LEDGER_ORIGIN_TOKEN_HEADER]:o.originToken}}))}),it("should make a GET request to the correct URL",async()=>{const e=vi.fn(()=>Promise.resolve({data:l}));vi.spyOn(a.default,"request").mockImplementation(e),await t.getProxyImplementationAddress(d),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:l}));vi.spyOn(a.default,"request").mockImplementation(e);const i={proxyAddress:"0xee6a57ec80ea46401049e92587e52f5ec1c24785",chainId:137};await t.getProxyImplementationAddress(i),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.default,"request").mockResolvedValue({data:l});const e=await t.getProxyImplementationAddress(d);expect(e).toEqual((0,s.Right)(y))}),it("should return an error when axios throws an error",async()=>{vi.spyOn(a.default,"request").mockRejectedValue(new Error("network error"));const e=await t.getProxyImplementationAddress(d);expect(e).toEqual((0,s.Left)(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch implementation address")))}),it("should return an error if response shape is invalid",async()=>{vi.spyOn(a.default,"request").mockResolvedValue({data:{invalid:"data"}});const e=await t.getProxyImplementationAddress(d);expect(e).toEqual((0,s.Left)(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.default,"request").mockResolvedValue({data:void 0});const e=await t.getProxyImplementationAddress(d);expect(e).toEqual((0,s.Left)(new Error("[ContextModule] HttpProxyDataSource: No data received for proxy 0xee6a57ec80ea46401049e92587e52f5ec1c24785 on chain 1")))})})});
1
+ "use strict";var f=Object.create;var m=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var v=Object.getPrototypeOf,P=Object.prototype.hasOwnProperty;var C=(o,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let d of g(t))!P.call(o,d)&&d!==r&&m(o,d,{get:()=>t[d],enumerable:!(s=h(t,d))||s.enumerable});return o};var x=(o,t,r)=>(r=o!=null?f(v(o)):{},C(t||!o||!o.__esModule?m(r,"default",{value:o,enumerable:!0}):r,o));var a=x(require("axios")),n=require("purify-ts"),c=require("../../shared/constant/HttpHeaders"),p=x(require("../../../package.json")),u=require("./HttpProxyDataSource");vi.mock("axios");describe("HttpProxyDataSource",()=>{const o={web3checks:{url:"web3checksUrl"},originToken:"originToken"};let t;const r={proxyAddress:"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0",calldata:"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000",chainId:1,challenge:"0x1234567890abcdef"},s={proxyAddress:"0xee6a57ec80ea46401049e92587e52f5ec1c24785",chainId:1},d={addresses:["0xd9db270c1b5e3bd161e8c8503c55ceabee709552"],signedDescriptor:"0x1234567890abcdef"},y={implementationAddress:"0x91ae842a5ffd8d12023116943e72a606179294f3"},l={implementationAddress:"0x91ae842a5ffd8d12023116943e72a606179294f3",proxyAddress:"0xee6a57ec80ea46401049e92587e52f5ec1c24785",standard:"proxy"};beforeEach(()=>{vi.clearAllMocks(),t=new u.HttpProxyDataSource({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/${p.default.version}`,i=vi.fn(()=>Promise.resolve({data:d}));vi.spyOn(a.default,"request").mockImplementation(i),await t.getProxyDelegateCall(r),expect(i).toHaveBeenCalledWith(expect.objectContaining({headers:{[c.LEDGER_CLIENT_VERSION_HEADER]:e,[c.LEDGER_ORIGIN_TOKEN_HEADER]:o.originToken}}))}),it("should return the delegate proxy response on success",async()=>{vi.spyOn(a.default,"request").mockResolvedValue({data:d});const e=await t.getProxyDelegateCall(r);expect(e).toEqual((0,n.Right)({delegateAddresses:["0xd9db270c1b5e3bd161e8c8503c55ceabee709552"],signedDescriptor:"0x1234567890abcdef"}))}),it("should return an error when axios throws an error",async()=>{vi.spyOn(a.default,"request").mockRejectedValue(new Error("fail"));const e=await t.getProxyDelegateCall(r);expect(e).toEqual((0,n.Left)(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy")))}),it("should return an error if response shape is invalid",async()=>{vi.spyOn(a.default,"request").mockResolvedValue({data:{foo:"bar"}});const e=await t.getProxyDelegateCall(r);expect(e).toEqual((0,n.Left)(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.default,"request").mockImplementation(e);const i={proxyAddress:"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0",calldata:"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000",chainId:137,challenge:"0x1234567890abcdef"};await t.getProxyDelegateCall(i),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.default,"request").mockResolvedValue({data:void 0});const e=await t.getProxyDelegateCall(r);expect(e).toEqual((0,n.Left)(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/${p.default.version}`,i=vi.fn(()=>Promise.resolve({data:l}));vi.spyOn(a.default,"request").mockImplementation(i),await t.getProxyImplementationAddress(s),expect(i).toHaveBeenCalledWith(expect.objectContaining({headers:{[c.LEDGER_CLIENT_VERSION_HEADER]:e,[c.LEDGER_ORIGIN_TOKEN_HEADER]:o.originToken}}))}),it("should make a GET request to the correct URL",async()=>{const e=vi.fn(()=>Promise.resolve({data:l}));vi.spyOn(a.default,"request").mockImplementation(e),await t.getProxyImplementationAddress(s),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:l}));vi.spyOn(a.default,"request").mockImplementation(e);const i={proxyAddress:"0xee6a57ec80ea46401049e92587e52f5ec1c24785",chainId:137};await t.getProxyImplementationAddress(i),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.default,"request").mockResolvedValue({data:l});const e=await t.getProxyImplementationAddress(s);expect(e).toEqual((0,n.Right)(y))}),it("should return an error when axios throws an error",async()=>{vi.spyOn(a.default,"request").mockRejectedValue(new Error("network error"));const e=await t.getProxyImplementationAddress(s);expect(e).toEqual((0,n.Left)(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch implementation address")))}),it("should return an error if response shape is invalid",async()=>{vi.spyOn(a.default,"request").mockResolvedValue({data:{invalid:"data"}});const e=await t.getProxyImplementationAddress(s);expect(e).toEqual((0,n.Left)(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.default,"request").mockResolvedValue({data:void 0});const e=await t.getProxyImplementationAddress(s);expect(e).toEqual((0,n.Left)(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": "wdAAA,IAAAA,EAAkB,oBAClBC,EAA4B,qBAG5BC,EAGO,yCAGPC,EAAoB,iCAQpBC,EAAoC,iCAEpC,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,IA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,OAAOQ,CAAM,EAAE,WACb,QACE,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": "wdAAA,IAAAA,EAAkB,oBAClBC,EAA4B,qBAG5BC,EAGO,yCAEPC,EAAoB,iCASpBC,EAAoC,iCAEpC,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,IAAI,sBAAoB,CACnC,sBAAuB,CACrB,IAAK,iCACP,EACA,YAAa,aACf,CAAwB,CAC1B,CAAC,EAED,SAAS,mBAAoB,IAAM,CACjC,GAAG,0DAA2D,SAAY,CAExE,MAAMM,EAAU,kBAAkB,EAAAC,QAAQ,OAAO,GAC3CC,EAAa,GAAG,GAAG,IACvB,QAAQ,QAAQ,CAAE,KAAML,CAAsB,CAAC,CACjD,EACA,GAAG,MAAM,EAAAM,QAAO,SAAS,EAAE,mBAAmBD,CAAU,EAGxD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GA,MAAMX,EAAW,8BACfW,CACF,EAGA,OAAOH,CAAU,EAAE,qBACjB,OAAO,iBAAiB,CACtB,OAAQ,MACR,IAAK,2GACP,CAAC,CACH,CACF,CAAC,EAED,GAAG,+DAAgE,SAAY,CAE7E,GAAG,MAAM,EAAAC,QAAO,SAAS,EAAE,kBAAkB,CAC3C,KAAMJ,CACR,CAAC,EAGD,MAAMK,EAAS,MAAMV,EAAW,8BAC9BE,CACF,EAGA,OAAOQ,CAAM,EAAE,WAAQ,SAAMN,CAA6B,CAAC,CAC7D,CAAC,EAED,GAAG,oDAAqD,SAAY,CAElE,GAAG,MAAM,EAAAK,QAAO,SAAS,EAAE,kBAAkB,IAAI,MAAM,eAAe,CAAC,EAGvE,MAAMC,EAAS,MAAMV,EAAW,8BAC9BE,CACF,EAGA,OAAOQ,CAAM,EAAE,WACb,QACE,IAAI,MACF,6EACF,CACF,CACF,CACF,CAAC,EAED,GAAG,sDAAuD,SAAY,CAEpE,GAAG,MAAM,EAAAD,QAAO,SAAS,EAAE,kBAAkB,CAC3C,KAAM,CAAE,QAAS,MAAO,CAC1B,CAAC,EAGD,MAAMC,EAAS,MAAMV,EAAW,8BAC9BE,CACF,EAGA,OAAOQ,CAAM,EAAE,WACb,QACE,IAAI,MACF,2JACF,CACF,CACF,CACF,CAAC,EAED,GAAG,4DAA6D,SAAY,CAE1E,GAAG,MAAM,EAAAD,QAAO,SAAS,EAAE,kBAAkB,CAC3C,KAAM,MACR,CAAC,EAGD,MAAMC,EAAS,MAAMV,EAAW,8BAC9BE,CACF,EAGA,OAAOQ,CAAM,EAAE,WACb,QACE,IAAI,MACF,uHACF,CACF,CACF,CACF,CAAC,CACH,CAAC,CACH,CAAC",
6
6
  "names": ["import_axios", "import_purify_ts", "import_HttpHeaders", "import_package", "import_HttpProxyDataSource", "config", "datasource", "defaultParams", "defaultImplementAddressParams", "delegateProxyResponse", "implementationAddressResponse", "implementationAddressDto", "version", "PACKAGE", "requestSpy", "axios", "result", "paramsWithDifferentChainId"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var g=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var o=Object.prototype.hasOwnProperty;var a=(t,e,d,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of l(e))!o.call(t,r)&&r!==d&&g(t,r,{get:()=>e[r],enumerable:!(s=i(e,r))||s.enumerable});return t};var n=t=>a(g({},"__esModule",{value:!0}),t);var p={};module.exports=n(p);
1
+ "use strict";var g=Object.defineProperty;var o=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var l=(r,e,i,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of a(e))!d.call(r,s)&&s!==i&&g(r,s,{get:()=>e[s],enumerable:!(t=o(e,s))||t.enumerable});return r};var n=r=>l(g({},"__esModule",{value:!0}),r);var p={};module.exports=n(p);
2
2
  //# sourceMappingURL=ProxyDelegateCallDto.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/transaction/data/dto/ProxyDelegateCallDto.ts"],
4
- "sourcesContent": ["export type ProxyDelegateCallDto = {\n delegateAddresses: string[];\n signedDescriptor: string;\n};\n"],
4
+ "sourcesContent": ["export type ProxyDelegateCallDto = {\n addresses: string[];\n signedDescriptor: string;\n};\n"],
5
5
  "mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
6
6
  "names": ["ProxyDelegateCallDto_exports", "__toCommonJS"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var s=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var D=(e,t)=>{for(var a in t)s(e,a,{get:t[a],enumerable:!0})},R=(e,t,a,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of x(t))!g.call(e,r)&&r!==a&&s(e,r,{get:()=>t[r],enumerable:!(o=u(t,r))||o.enumerable});return e};var y=e=>R(s({},"__esModule",{value:!0}),e),f=(e,t,a,o)=>{for(var r=o>1?void 0:o?u(t,a):t,n=e.length-1,i;n>=0;n--)(i=e[n])&&(r=(o?i(t,a,r):i(r))||r);return o&&r&&s(t,a,r),r},S=(e,t)=>(a,o)=>t(a,o,e);var T={};D(T,{TransactionContextLoader:()=>c});module.exports=y(T);var d=require("@ledgerhq/device-management-kit"),m=require("inversify"),l=require("../../shared/model/ClearSignContext"),C=require("../../transaction/di/transactionTypes");let c=class{constructor(t){this.transactionDataSource=t}async load(t){const{to:a,data:o,selector:r,chainId:n,deviceModelId:i}=t;return a===void 0||o==="0x"?[]:(0,d.isHexaString)(r)?(await this.transactionDataSource.getTransactionDescriptors({deviceModelId:i,address:a,chainId:n,selector:r})).caseOf({Left:p=>[{type:l.ClearSignContextType.ERROR,error:p}],Right:p=>p}):[{type:l.ClearSignContextType.ERROR,error:new Error("Invalid selector")}]}};c=f([(0,m.injectable)(),S(0,(0,m.inject)(C.transactionTypes.TransactionDataSource))],c);0&&(module.exports={TransactionContextLoader});
1
+ "use strict";var l=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var I=(a,e)=>{for(var t in e)l(a,t,{get:e[t],enumerable:!0})},O=(a,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of A(e))!E.call(a,r)&&r!==t&&l(a,r,{get:()=>e[r],enumerable:!(i=y(e,r))||i.enumerable});return a};var w=a=>O(l({},"__esModule",{value:!0}),a),u=(a,e,t,i)=>{for(var r=i>1?void 0:i?y(e,t):e,n=a.length-1,s;n>=0;n--)(s=a[n])&&(r=(i?s(e,t,r):s(r))||r);return i&&r&&l(e,t,r),r},f=(a,e)=>(t,i)=>e(t,i,a);var K={};I(K,{TransactionContextLoader:()=>d});module.exports=w(K);var x=require("@ledgerhq/device-management-kit"),c=require("inversify"),D=require("../../pki/di/pkiTypes"),S=require("../../pki/model/KeyId"),P=require("../../pki/model/KeyUsage"),p=require("../../shared/model/ClearSignContext"),C=require("../../transaction/di/transactionTypes");let d=class{constructor(e,t,i){this.transactionDataSource=e;this.proxyDataSource=t;this.certificateLoader=i}async load(e){const{to:t,data:i,selector:r,chainId:n,deviceModelId:s,challenge:k}=e;if(t===void 0||i==="0x")return[];if(!(0,x.isHexaString)(r))return[{type:p.ClearSignContextType.ERROR,error:new Error("Invalid selector")}];const L=await this.proxyDataSource.getProxyDelegateCall({calldata:i,proxyAddress:t,chainId:n,challenge:k||""}),[R,m]=L.caseOf({Left:()=>[t,void 0],Right:o=>[o.delegateAddresses.find(T=>T===t)||o.delegateAddresses[0],o.signedDescriptor]});let g;m&&(g=await this.certificateLoader.loadCertificate({keyId:S.KeyId.CalCalldataKey,keyUsage:P.KeyUsage.Calldata,targetDevice:e.deviceModelId}));const h=m?[{type:p.ClearSignContextType.PROXY_DELEGATE_CALL,payload:m,certificate:g}]:[],v=(await this.transactionDataSource.getTransactionDescriptors({deviceModelId:s,address:R,chainId:n,selector:r})).caseOf({Left:o=>[{type:p.ClearSignContextType.ERROR,error:o}],Right:o=>o});return[...h,...v]}};d=u([(0,c.injectable)(),f(0,(0,c.inject)(C.transactionTypes.TransactionDataSource)),f(1,(0,c.inject)(C.transactionTypes.ProxyDataSource)),f(2,(0,c.inject)(D.pkiTypes.PkiCertificateLoader))],d);0&&(module.exports={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": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,8BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAA6B,2CAC7BC,EAAmC,qBAGnCC,EAGO,2CAGPC,EAAiC,6CAG1B,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,KAGL,gBAAaC,CAAQ,GASX,MAAM,KAAK,sBAAsB,0BAA0B,CACxE,cAAAE,EACA,QAASJ,EACT,QAAAG,EACA,SAAAD,CACF,CAAC,GAEa,OAAO,CACnB,KAAOG,GAA8B,CACnC,CACE,KAAM,uBAAqB,MAC3B,MAAAA,CACF,CACF,EACA,MAAQC,GAAiCA,CAC3C,CAAC,EAvBQ,CACL,CACE,KAAM,uBAAqB,MAC3B,MAAO,IAAI,MAAM,kBAAkB,CACrC,CACF,CAmBJ,CACF,EAtCaT,EAANU,EAAA,IADN,cAAW,EAGPC,EAAA,eAAO,mBAAiB,qBAAqB,IAFrCX",
6
- "names": ["TransactionContextLoader_exports", "__export", "TransactionContextLoader", "__toCommonJS", "import_device_management_kit", "import_inversify", "import_ClearSignContext", "import_transactionTypes", "TransactionContextLoader", "transactionDataSource", "ctx", "to", "data", "selector", "chainId", "deviceModelId", "error", "contexts", "__decorateClass", "__decorateParam"]
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": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,8BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAA6B,2CAC7BC,EAAmC,qBAEnCC,EAAyB,6BAEzBC,EAAsB,6BACtBC,EAAyB,gCAGzBC,EAGO,2CAIPC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mB,CAC7D,CACF,EA5FalB,EAANqB,EAAA,IADN,cAAW,EAGPC,EAAA,eAAO,mBAAiB,qBAAqB,GAE7CA,EAAA,eAAO,mBAAiB,eAAe,GAEvCA,EAAA,eAAO,WAAS,oBAAoB,IAN5BtB",
6
+ "names": ["TransactionContextLoader_exports", "__export", "TransactionContextLoader", "__toCommonJS", "import_device_management_kit", "import_inversify", "import_pkiTypes", "import_KeyId", "import_KeyUsage", "import_ClearSignContext", "import_transactionTypes", "TransactionContextLoader", "transactionDataSource", "proxyDataSource", "certificateLoader", "ctx", "to", "data", "selector", "chainId", "deviceModelId", "challenge", "proxyDelegateCall", "resolvedAddress", "proxyDelegateCallDescriptor", "proxyData", "address", "certificate", "proxyDelegateCallContext", "transactionContexts", "error", "contexts", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var n=require("purify-ts"),o=require("../../shared/model/ClearSignContext"),s=require("../../transaction/domain/TransactionContextLoader");describe("TransactionContextLoader",()=>{const r=vi.fn(),c={getTransactionDescriptors:r},e=new s.TransactionContextLoader(c);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.ClearSignContextType.ERROR,error:new Error("Invalid selector")}])}),it("should return an error if data source fails",async()=>{r.mockResolvedValue((0,n.Left)(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.ClearSignContextType.ERROR,error:new Error("data source error")}])}),it("should return the contexts on success",async()=>{r.mockResolvedValue((0,n.Right)([{type:o.ClearSignContextType.TRANSACTION_INFO,payload:"1234567890"},{type:o.ClearSignContextType.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.ClearSignContextType.TRANSACTION_INFO,payload:"1234567890"},{type:o.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])})});
1
+ "use strict";var o=require("purify-ts"),e=require("../../shared/model/ClearSignContext"),c=require("../../transaction/domain/TransactionContextLoader");describe("TransactionContextLoader",()=>{const s=vi.fn(),n=vi.fn(),d={getTransactionDescriptors:s},l={getProxyDelegateCall:n,getProxyImplementationAddress:vi.fn()},i={loadCertificate:vi.fn()},r=new c.TransactionContextLoader(d,l,i);beforeEach(()=>{vi.resetAllMocks()}),it("should return an empty array if no destination address is provided",async()=>{const a={},t=await r.load(a);expect(t).toEqual([])}),it("should return an empty array if no data provided",async()=>{const a={to:"0x0",data:"0x"},t=await r.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 r.load(a);expect(t).toEqual([{type:e.ClearSignContextType.ERROR,error:new Error("Invalid selector")}])}),it("should return an error if data source fails",async()=>{n.mockResolvedValue((0,o.Left)(new Error("data source error"))),s.mockResolvedValue((0,o.Left)(new Error("data source error")));const a={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await r.load(a);expect(s).toHaveBeenCalledWith({address:"0x7",chainId:3,selector:"0xaf68b302"}),expect(t).toEqual([{type:e.ClearSignContextType.ERROR,error:new Error("data source error")}])}),it("should return the contexts on success",async()=>{s.mockResolvedValue((0,o.Right)([{type:e.ClearSignContextType.TRANSACTION_INFO,payload:"1234567890"},{type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),n.mockResolvedValue((0,o.Left)(new Error("data source error")));const a={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await r.load(a);expect(t).toEqual([{type:e.ClearSignContextType.TRANSACTION_INFO,payload:"1234567890"},{type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])}),it("should return the proxy delegate call context on success",async()=>{s.mockResolvedValue((0,o.Right)([{type:e.ClearSignContextType.TRANSACTION_INFO,payload:"1234567890"},{type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),n.mockResolvedValue((0,o.Right)({delegateAddresses:["0x7"],signedDescriptor:"0x1234567890abcdef"}));const a={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await r.load(a);expect(t).toEqual([{type:e.ClearSignContextType.PROXY_DELEGATE_CALL,payload:"0x1234567890abcdef"},{type:e.ClearSignContextType.TRANSACTION_INFO,payload:"1234567890"},{type:e.ClearSignContextType.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()=>{s.mockResolvedValue((0,o.Right)([{type:e.ClearSignContextType.TRANSACTION_INFO,payload:"1234567890"},{type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),n.mockResolvedValue((0,o.Right)({delegateAddresses:["0x7","0x8"],signedDescriptor:"0x1234567890abcdef"}));const a={to:"0x8",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await r.load(a);expect(t).toEqual([{type:e.ClearSignContextType.PROXY_DELEGATE_CALL,payload:"0x1234567890abcdef"},{type:e.ClearSignContextType.TRANSACTION_INFO,payload:"1234567890"},{type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])}),it("should return the proxy delegate call context if the transaction.to is not in the delegate addresses",async()=>{s.mockResolvedValue((0,o.Right)([{type:e.ClearSignContextType.TRANSACTION_INFO,payload:"1234567890"},{type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),n.mockResolvedValue((0,o.Right)({delegateAddresses:["0x8"],signedDescriptor:"0x1234567890abcdef"}));const a={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await r.load(a);expect(t).toEqual([{type:e.ClearSignContextType.PROXY_DELEGATE_CALL,payload:"0x1234567890abcdef"},{type:e.ClearSignContextType.TRANSACTION_INFO,payload:"1234567890"},{type:e.ClearSignContextType.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,IA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AA8B,qBAC5B,SAAM,CACJ,CACE,KAAM,uBAAqB,iBAC3B,QAAS,YACX,EACA,CACE,KAAM,uBAAqB,8BAC3B,QAAS,UACX,CACF,CAAC,CACH,EACA,MAAMG,EAAc,CAClB,GAAI,MACJ,QAAS,EACT,KAAM,yEACN,SAAU,YACZ,EAGMC,EAAS,MAAMF,EAAO,KAAKC,CAAW,EAG5C,OAAOC,CAAM,EAAE,QAAQ,CACrB,CACE,KAAM,uBAAqB,iBAC3B,QAAS,YACX,EACA,CACE,KAAM,uBAAqB,8BAC3B,QAAS,UACX,CACF,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["import_purify_ts", "import_ClearSignContext", "import_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,IAAAA,EAA4B,qBAG5BC,EAAqC,2CAIrCC,EAAyC,yDAEzC,SAAS,2BAA4B,IAAM,CACzC,MAAMC,EAAgC,GAAG,GAAG,EACtCC,EAA2B,GAAG,GAAG,EACjCC,EAAmD,CACvD,0BAA2BF,CAC7B,EACMG,EAAuC,CAC3C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AC,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,KAAM,uBAAqB,oBAC3B,QAAS,oBACX,EACA,CACE,KAAM,uBAAqB,iBAC3B,QAAS,YACX,EACA,CACE,KAAM,uBAAqB,8BAC3B,QAAS,UACX,CACF,CAAC,CACH,CAAC,EAED,GAAG,uGAAwG,SAAY,CAErHP,EAA8B,qBAC5B,SAAM,CACJ,CACE,KAAM,uBAAqB,iBAC3B,QAAS,YACX,EACA,CACE,KAAM,uBAAqB,8BAC3B,QAAS,UACX,CACF,CAAC,CACH,EACAC,EAAyB,qBACvB,SAAM,CACJ,kBAAmB,CAAC,KAAK,EACzB,iBAAkB,oBACpB,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,KAAM,uBAAqB,oBAC3B,QAAS,oBACX,EACA,CACE,KAAM,uBAAqB,iBAC3B,QAAS,YACX,EACA,CACE,KAAM,uBAAqB,8BAC3B,QAAS,UACX,CACF,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["import_purify_ts", "import_ClearSignContext", "import_TransactionContextLoader", "getTransactionDescriptorsMock", "getProxyDelegateCallMock", "mockTransactionDataSource", "mockProxyDatasource", "mockCertificateLoader", "loader", "transaction", "result"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var x=Object.create;var c=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,P=Object.prototype.hasOwnProperty;var I=(o,e)=>{for(var t in e)c(o,t,{get:e[t],enumerable:!0})},D=(o,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of G(e))!P.call(o,r)&&r!==t&&c(o,r,{get:()=>e[r],enumerable:!(a=E(e,r))||a.enumerable});return o};var N=(o,e,t)=>(t=o!=null?x(_(o)):{},D(e||!o||!o.__esModule?c(t,"default",{value:o,enumerable:!0}):t,o)),v=o=>D(c({},"__esModule",{value:!0}),o),T=(o,e,t,a)=>{for(var r=a>1?void 0:a?E(e,t):e,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(a?s(e,t,r):s(r))||r);return a&&r&&c(e,t,r),r},$=(o,e)=>(t,a)=>e(t,a,o);var w={};I(w,{HttpTrustedNameDataSource:()=>u});module.exports=v(w);var f=N(require("axios")),g=require("inversify"),n=require("purify-ts"),y=require("../../config/di/configTypes"),m=require("../../shared/constant/HttpHeaders"),l=N(require("../../../package.json"));let u=class{constructor(e){this.config=e}async getDomainNamePayload({chainId:e,domain:t,challenge:a}){try{const s=await f.default.request({method:"GET",url:`${this.config.metadataService.url}/names/ethereum/${e}/forward/${t}?types=eoa&sources=ens&challenge=${a}`,headers:{[m.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${l.default.version}`,[m.LEDGER_ORIGIN_TOKEN_HEADER]:this.config.originToken}});return s.data.signedDescriptor?.data?(0,n.Right)(s.data.signedDescriptor.data):(0,n.Left)(new Error("[ContextModule] HttpTrustedNameDataSource: error getting domain payload"))}catch{return(0,n.Left)(new Error("[ContextModule] HttpTrustedNameDataSource: Failed to fetch domain name"))}}async getTrustedNamePayload({chainId:e,address:t,challenge:a,sources:r,types:i}){try{r=r.filter(h=>h==="ens"||h==="crypto_asset_list");const d=(await f.default.request({method:"GET",url:`${this.config.metadataService.url}/names/ethereum/${e}/reverse/${t}?types=${i.join(",")}&sources=${r.join(",")}&challenge=${a}`,headers:{[m.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${l.default.version}`,[m.LEDGER_ORIGIN_TOKEN_HEADER]:this.config.originToken}})).data;if(!d?.signedDescriptor?.data)return(0,n.Left)(new Error(`[ContextModule] HttpTrustedNameDataSource: no trusted name metadata for address ${t}`));const p=d.signedDescriptor.data;if(!d.signedDescriptor.signatures||typeof d.signedDescriptor.signatures[this.config.cal.mode]!="string")return(0,n.Right)(p);const C=d.signedDescriptor.signatures[this.config.cal.mode];return(0,n.Right)(this.formatTrustedName(p,C))}catch{return(0,n.Left)(new Error("[ContextModule] HttpTrustedNameDataSource: Failed to fetch trusted name"))}}formatTrustedName(e,t){t.length%2!==0&&(t="0"+t);const a="15",r=(t.length/2).toString(16);return`${e}${a}${r}${t}`}};u=T([(0,g.injectable)(),$(0,(0,g.inject)(y.configTypes.Config))],u);0&&(module.exports={HttpTrustedNameDataSource});
1
+ "use strict";var x=Object.create;var c=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty;var P=(o,e)=>{for(var t in e)c(o,t,{get:e[t],enumerable:!0})},D=(o,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of G(e))!v.call(o,r)&&r!==t&&c(o,r,{get:()=>e[r],enumerable:!(a=E(e,r))||a.enumerable});return o};var N=(o,e,t)=>(t=o!=null?x(_(o)):{},D(e||!o||!o.__esModule?c(t,"default",{value:o,enumerable:!0}):t,o)),I=o=>D(c({},"__esModule",{value:!0}),o),T=(o,e,t,a)=>{for(var r=a>1?void 0:a?E(e,t):e,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(a?s(e,t,r):s(r))||r);return a&&r&&c(e,t,r),r},$=(o,e)=>(t,a)=>e(t,a,o);var w={};P(w,{HttpTrustedNameDataSource:()=>u});module.exports=I(w);var f=N(require("axios")),g=require("inversify"),n=require("purify-ts"),y=require("../../config/di/configTypes"),m=require("../../shared/constant/HttpHeaders"),l=N(require("../../../package.json"));let u=class{constructor(e){this.config=e}async getDomainNamePayload({chainId:e,domain:t,challenge:a}){try{const s=await f.default.request({method:"GET",url:`${this.config.metadataServiceDomain.url}/v1/names/ethereum/${e}/forward/${t}?types=eoa&sources=ens&challenge=${a}`,headers:{[m.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${l.default.version}`,[m.LEDGER_ORIGIN_TOKEN_HEADER]:this.config.originToken}});return s.data.signedDescriptor?.data?(0,n.Right)(s.data.signedDescriptor.data):(0,n.Left)(new Error("[ContextModule] HttpTrustedNameDataSource: error getting domain payload"))}catch{return(0,n.Left)(new Error("[ContextModule] HttpTrustedNameDataSource: Failed to fetch domain name"))}}async getTrustedNamePayload({chainId:e,address:t,challenge:a,sources:r,types:i}){try{r=r.filter(h=>h==="ens"||h==="crypto_asset_list");const d=(await f.default.request({method:"GET",url:`${this.config.metadataServiceDomain.url}/v1/names/ethereum/${e}/reverse/${t}?types=${i.join(",")}&sources=${r.join(",")}&challenge=${a}`,headers:{[m.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${l.default.version}`,[m.LEDGER_ORIGIN_TOKEN_HEADER]:this.config.originToken}})).data;if(!d?.signedDescriptor?.data)return(0,n.Left)(new Error(`[ContextModule] HttpTrustedNameDataSource: no trusted name metadata for address ${t}`));const p=d.signedDescriptor.data;if(!d.signedDescriptor.signatures||typeof d.signedDescriptor.signatures[this.config.cal.mode]!="string")return(0,n.Right)(p);const C=d.signedDescriptor.signatures[this.config.cal.mode];return(0,n.Right)(this.formatTrustedName(p,C))}catch{return(0,n.Left)(new Error("[ContextModule] HttpTrustedNameDataSource: Failed to fetch trusted name"))}}formatTrustedName(e,t){t.length%2!==0&&(t="0"+t);const a="15",r=(t.length/2).toString(16);return`${e}${a}${r}${t}`}};u=T([(0,g.injectable)(),$(0,(0,g.inject)(y.configTypes.Config))],u);0&&(module.exports={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": "qtBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,+BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkB,oBAClBC,EAAmC,qBACnCC,EAAoC,qBAEpCC,EAA4B,mCAE5BC,EAGO,yCAMPC,EAAoB,iCAKb,IAAMC,EAAN,KAAiE,CACtE,YAC+CC,EAC7C,CAD6C,YAAAA,CAC5C,CAEH,MAAa,qBAAqB,CAChC,QAAAC,EACA,OAAAC,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B,MAAMC,EACJF,EAAY,iBAAiB,WAAW,KAAK,OAAO,IAAI,IAAI,EAC9D,SAAO,SAAM,KAAK,kBAAkBC,EAASC,CAAS,CAAC,CACzD,MAAiB,CACf,SAAO,QACL,IAAI,MACF,yEACF,CACF,CACF,CACF,CAEQ,kBAAkBD,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,EAtGad,EAANiB,EAAA,IADN,cAAW,EAGPC,EAAA,eAAO,cAAY,MAAM,IAFjBlB",
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": "qtBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,+BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkB,oBAClBC,EAAmC,qBACnCC,EAAoC,qBAEpCC,EAA4B,mCAE5BC,EAGO,yCAMPC,EAAoB,iCAKb,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,MAAM,EAAAC,QAAM,QAAwB,CACnD,OAAQ,MACR,IAAK,GAAG,KAAK,OAAO,sBAAsB,GAAG,sBAAsBJ,CAAO,YAAYC,CAAM,oCAA8CC,CAAS,GACnJ,QAAS,CACP,CAAC,8BAA4B,EAAG,kBAAkB,EAAAG,QAAQ,OAAO,GACjE,CAAC,4BAA0B,EAAG,KAAK,OAAO,WAC5C,CACF,CAAC,EAED,OAAOF,EAAS,KAAK,kBAAkB,QACnC,SAAMA,EAAS,KAAK,iBAAiB,IAAI,KACzC,QACE,IAAI,MACF,yEACF,CACF,CACN,MAAiB,CACf,SAAO,QACL,IAAI,MACF,wEACF,CACF,CACF,CACF,CAEA,MAAa,sBAAsB,CACjC,QAAAH,EACA,QAAAM,EACA,UAAAJ,EACA,QAAAK,EACA,MAAAC,CACF,EAA8D,CAC5D,GAAI,CAIFD,EAAUA,EAAQ,OACfE,GAAWA,IAAW,OAASA,IAAW,mBAC7C,EASA,MAAMC,GARW,MAAM,EAAAN,QAAM,QAAwB,CACnD,OAAQ,MACR,IAAK,GAAG,KAAK,OAAO,sBAAsB,GAAG,sBAAsBJ,CAAO,YAAYM,CAAO,UAAUE,EAAM,KAAK,GAAG,CAAC,YAAYD,EAAQ,KAAK,GAAG,CAAC,cAAcL,CAAS,GAC1K,QAAS,CACP,CAAC,8BAA4B,EAAG,kBAAkB,EAAAG,QAAQ,OAAO,GACjE,CAAC,4BAA0B,EAAG,KAAK,OAAO,WAC5C,CACF,CAAC,GAC4B,KAC7B,GAAI,CAACK,GAAa,kBAAkB,KAClC,SAAO,QACL,IAAI,MACF,mFAAmFJ,CAAO,EAC5F,CACF,EAEF,MAAMK,EAAUD,EAAY,iBAAiB,KAE7C,GACE,CAACA,EAAY,iBAAiB,YAC9B,OAAOA,EAAY,iBAAiB,WAAW,KAAK,OAAO,IAAI,IAAI,GACjE,SAIF,SAAO,SAAMC,CAAO,EAGtB,MAAMC,EACJF,EAAY,iBAAiB,WAAW,KAAK,OAAO,IAAI,IAAI,EAC9D,SAAO,SAAM,KAAK,kBAAkBC,EAASC,CAAS,CAAC,CACzD,MAAiB,CACf,SAAO,QACL,IAAI,MACF,yEACF,CACF,CACF,CACF,CAEQ,kBAAkBD,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,EAtGad,EAANiB,EAAA,IADN,cAAW,EAGPC,EAAA,eAAO,cAAY,MAAM,IAFjBlB",
6
6
  "names": ["HttpTrustedNameDataSource_exports", "__export", "HttpTrustedNameDataSource", "__toCommonJS", "import_axios", "import_inversify", "import_purify_ts", "import_configTypes", "import_HttpHeaders", "import_package", "HttpTrustedNameDataSource", "config", "chainId", "domain", "challenge", "response", "axios", "PACKAGE", "address", "sources", "types", "source", "trustedName", "payload", "signature", "signatureTag", "signatureLength", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var m=Object.create;var c=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty;var x=(a,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of y(e))!v.call(a,n)&&n!==t&&c(a,n,{get:()=>e[n],enumerable:!(i=h(e,n))||i.enumerable});return a};var u=(a,e,t)=>(t=a!=null?m(g(a)):{},x(e||!a||!a.__esModule?c(t,"default",{value:a,enumerable:!0}):t,a));var o=u(require("axios")),r=require("purify-ts"),s=require("../../shared/constant/HttpHeaders"),p=require("../../trusted-name/data/HttpTrustedNameDataSource"),d=u(require("../../../package.json"));vi.mock("axios");const l={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 a;beforeAll(()=>{a=new p.HttpTrustedNameDataSource(l),vi.clearAllMocks()}),describe("getDomainNamePayload",()=>{it("should call axios with the correct url and ledger client version header",async()=>{const e=`context-module/${d.default.version}`,t=vi.fn(()=>Promise.resolve({data:[]}));vi.spyOn(o.default,"request").mockImplementation(t),await a.getDomainNamePayload({chainId:137,challenge:"9876",domain:"hello.eth"}),expect(t).toHaveBeenCalledWith(expect.objectContaining({url:"https://nft.api.live.ledger.com/v2/names/ethereum/137/forward/hello.eth?types=eoa&sources=ens&challenge=9876",headers:{[s.LEDGER_CLIENT_VERSION_HEADER]:e,[s.LEDGER_ORIGIN_TOKEN_HEADER]:l.originToken}}))}),it("should throw an error when axios throws an error",async()=>{vi.spyOn(o.default,"request").mockRejectedValue(new Error);const e=await a.getDomainNamePayload({chainId:137,challenge:"",domain:"hello.eth"});expect(e).toEqual((0,r.Left)(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.default,"request").mockResolvedValue(e);const t=await a.getDomainNamePayload({chainId:137,challenge:"",domain:"hello.eth"});expect(t).toEqual((0,r.Left)(new Error("[ContextModule] HttpTrustedNameDataSource: error getting domain payload")))}),it("should return a payload",async()=>{const e={data:{signedDescriptor:{data:"payload"}}};vi.spyOn(o.default,"request").mockResolvedValue(e);const t=await a.getDomainNamePayload({chainId:137,challenge:"challenge",domain:"hello.eth"});expect(t).toEqual((0,r.Right)("payload"))})}),describe("getTrustedNamePayload",()=>{it("should call axios with the correct url and ledger client version header",async()=>{const e=`context-module/${d.default.version}`,t=vi.fn(()=>Promise.resolve({data:[]}));vi.spyOn(o.default,"request").mockImplementation(t),await a.getTrustedNamePayload({chainId:137,address:"0x1234",challenge:"5678",sources:["ens","crypto_asset_list"],types:["eoa"]}),expect(t).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:{[s.LEDGER_CLIENT_VERSION_HEADER]:e,[s.LEDGER_ORIGIN_TOKEN_HEADER]:l.originToken}}))}),it("should throw an error when axios throws an error",async()=>{vi.spyOn(o.default,"request").mockRejectedValue(new Error);const e=await a.getTrustedNamePayload({chainId:137,address:"0x1234",challenge:"",sources:["ens"],types:["eoa"]});expect(e).toEqual((0,r.Left)(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.default,"request").mockResolvedValue(e);const t=await a.getTrustedNamePayload({chainId:137,address:"0x1234",challenge:"",sources:["ens"],types:["eoa"]});expect(t).toEqual((0,r.Left)(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.default,"request").mockResolvedValue(e);const t=await a.getTrustedNamePayload({chainId:137,address:"0x1234",challenge:"",sources:["ens"],types:["eoa"]});expect(t).toEqual((0,r.Right)("payload"))}),it("should return a payload with a signature",async()=>{const e={data:{signedDescriptor:{data:"payload",signatures:{prod:"12345"}}}};vi.spyOn(o.default,"request").mockResolvedValue(e);const t=await a.getTrustedNamePayload({chainId:137,address:"0x1234",challenge:"",sources:["ens"],types:["eoa"]});expect(t).toEqual((0,r.Right)("payload153012345"))})})});
1
+ "use strict";var m=Object.create;var c=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty;var x=(a,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of y(e))!v.call(a,n)&&n!==t&&c(a,n,{get:()=>e[n],enumerable:!(i=h(e,n))||i.enumerable});return a};var u=(a,e,t)=>(t=a!=null?m(g(a)):{},x(e||!a||!a.__esModule?c(t,"default",{value:a,enumerable:!0}):t,a));var o=u(require("axios")),r=require("purify-ts"),s=require("../../shared/constant/HttpHeaders"),p=require("../../trusted-name/data/HttpTrustedNameDataSource"),d=u(require("../../../package.json"));vi.mock("axios");const l={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 a;beforeAll(()=>{a=new p.HttpTrustedNameDataSource(l),vi.clearAllMocks()}),describe("getDomainNamePayload",()=>{it("should call axios with the correct url and ledger client version header",async()=>{const e=`context-module/${d.default.version}`,t=vi.fn(()=>Promise.resolve({data:[]}));vi.spyOn(o.default,"request").mockImplementation(t),await a.getDomainNamePayload({chainId:137,challenge:"9876",domain:"hello.eth"}),expect(t).toHaveBeenCalledWith(expect.objectContaining({url:"https://nft.api.live.ledger.com/v1/names/ethereum/137/forward/hello.eth?types=eoa&sources=ens&challenge=9876",headers:{[s.LEDGER_CLIENT_VERSION_HEADER]:e,[s.LEDGER_ORIGIN_TOKEN_HEADER]:l.originToken}}))}),it("should throw an error when axios throws an error",async()=>{vi.spyOn(o.default,"request").mockRejectedValue(new Error);const e=await a.getDomainNamePayload({chainId:137,challenge:"",domain:"hello.eth"});expect(e).toEqual((0,r.Left)(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.default,"request").mockResolvedValue(e);const t=await a.getDomainNamePayload({chainId:137,challenge:"",domain:"hello.eth"});expect(t).toEqual((0,r.Left)(new Error("[ContextModule] HttpTrustedNameDataSource: error getting domain payload")))}),it("should return a payload",async()=>{const e={data:{signedDescriptor:{data:"payload"}}};vi.spyOn(o.default,"request").mockResolvedValue(e);const t=await a.getDomainNamePayload({chainId:137,challenge:"challenge",domain:"hello.eth"});expect(t).toEqual((0,r.Right)("payload"))})}),describe("getTrustedNamePayload",()=>{it("should call axios with the correct url and ledger client version header",async()=>{const e=`context-module/${d.default.version}`,t=vi.fn(()=>Promise.resolve({data:[]}));vi.spyOn(o.default,"request").mockImplementation(t),await a.getTrustedNamePayload({chainId:137,address:"0x1234",challenge:"5678",sources:["ens","crypto_asset_list"],types:["eoa"]}),expect(t).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:{[s.LEDGER_CLIENT_VERSION_HEADER]:e,[s.LEDGER_ORIGIN_TOKEN_HEADER]:l.originToken}}))}),it("should throw an error when axios throws an error",async()=>{vi.spyOn(o.default,"request").mockRejectedValue(new Error);const e=await a.getTrustedNamePayload({chainId:137,address:"0x1234",challenge:"",sources:["ens"],types:["eoa"]});expect(e).toEqual((0,r.Left)(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.default,"request").mockResolvedValue(e);const t=await a.getTrustedNamePayload({chainId:137,address:"0x1234",challenge:"",sources:["ens"],types:["eoa"]});expect(t).toEqual((0,r.Left)(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.default,"request").mockResolvedValue(e);const t=await a.getTrustedNamePayload({chainId:137,address:"0x1234",challenge:"",sources:["ens"],types:["eoa"]});expect(t).toEqual((0,r.Right)("payload"))}),it("should return a payload with a signature",async()=>{const e={data:{signedDescriptor:{data:"payload",signatures:{prod:"12345"}}}};vi.spyOn(o.default,"request").mockResolvedValue(e);const t=await a.getTrustedNamePayload({chainId:137,address:"0x1234",challenge:"",sources:["ens"],types:["eoa"]});expect(t).toEqual((0,r.Right)("payload153012345"))})})});
2
2
  //# sourceMappingURL=HttpTrustedNameDataSource.test.js.map