@ledgerhq/context-module 0.0.0-multisig-2-20250922093851 → 0.0.0-multisig-20250925175241

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 (174) hide show
  1. package/lib/cjs/src/ContextModule.js +1 -1
  2. package/lib/cjs/src/ContextModule.js.map +1 -1
  3. package/lib/cjs/src/ContextModuleBuilder.test.js +1 -1
  4. package/lib/cjs/src/ContextModuleBuilder.test.js.map +2 -2
  5. package/lib/cjs/src/DefaultContextModule.js +1 -1
  6. package/lib/cjs/src/DefaultContextModule.js.map +3 -3
  7. package/lib/cjs/src/DefaultContextModule.test.js +1 -1
  8. package/lib/cjs/src/DefaultContextModule.test.js.map +3 -3
  9. package/lib/cjs/src/calldata/data/HttpCalldataDescriptorDataSource.js +1 -1
  10. package/lib/cjs/src/calldata/data/HttpCalldataDescriptorDataSource.js.map +3 -3
  11. package/lib/cjs/src/calldata/domain/CalldataContextLoader.js +1 -1
  12. package/lib/cjs/src/calldata/domain/CalldataContextLoader.js.map +3 -3
  13. package/lib/cjs/src/calldata/domain/CalldataContextLoader.test.js +1 -1
  14. package/lib/cjs/src/calldata/domain/CalldataContextLoader.test.js.map +3 -3
  15. package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.js +1 -1
  16. package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.js.map +3 -3
  17. package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js +1 -1
  18. package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js.map +3 -3
  19. package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.js +1 -1
  20. package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.js.map +3 -3
  21. package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.test.js +1 -1
  22. package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.test.js.map +3 -3
  23. package/lib/cjs/src/index.js +1 -1
  24. package/lib/cjs/src/index.js.map +2 -2
  25. package/lib/cjs/src/nft/domain/NftContextLoader.js +1 -1
  26. package/lib/cjs/src/nft/domain/NftContextLoader.js.map +3 -3
  27. package/lib/cjs/src/nft/domain/NftContextLoader.test.js +1 -1
  28. package/lib/cjs/src/nft/domain/NftContextLoader.test.js.map +3 -3
  29. package/lib/cjs/src/pki/model/PkiCertificateInfo.js +1 -1
  30. package/lib/cjs/src/pki/model/PkiCertificateInfo.js.map +1 -1
  31. package/lib/cjs/src/proxy/data/HttpProxyDataSource.js +1 -1
  32. package/lib/cjs/src/proxy/data/HttpProxyDataSource.js.map +3 -3
  33. package/lib/cjs/src/proxy/data/HttpProxyDataSource.test.js +1 -1
  34. package/lib/cjs/src/proxy/data/HttpProxyDataSource.test.js.map +3 -3
  35. package/lib/cjs/src/proxy/data/HttpSafeProxyDataSource.js +1 -1
  36. package/lib/cjs/src/proxy/data/HttpSafeProxyDataSource.js.map +2 -2
  37. package/lib/cjs/src/proxy/data/HttpSafeProxyDataSource.test.js +1 -1
  38. package/lib/cjs/src/proxy/data/HttpSafeProxyDataSource.test.js.map +2 -2
  39. package/lib/cjs/src/proxy/data/ProxyDataSource.js +1 -1
  40. package/lib/cjs/src/proxy/data/ProxyDataSource.js.map +1 -1
  41. package/lib/cjs/src/proxy/data/dto/SafeProxyImplementationAddressDto.js +1 -1
  42. package/lib/cjs/src/proxy/data/dto/SafeProxyImplementationAddressDto.js.map +1 -1
  43. package/lib/cjs/src/proxy/domain/ProxyContextFieldLoader.js +1 -1
  44. package/lib/cjs/src/proxy/domain/ProxyContextFieldLoader.js.map +3 -3
  45. package/lib/cjs/src/proxy/domain/ProxyContextFieldLoader.test.js +1 -1
  46. package/lib/cjs/src/proxy/domain/ProxyContextFieldLoader.test.js.map +2 -2
  47. package/lib/cjs/src/proxy/model/ProxyDelegateCall.js +1 -1
  48. package/lib/cjs/src/proxy/model/ProxyDelegateCall.js.map +1 -1
  49. package/lib/cjs/src/shared/domain/ContextLoader.js +1 -1
  50. package/lib/cjs/src/shared/domain/ContextLoader.js.map +1 -1
  51. package/lib/cjs/src/shared/utils/KeyUsageMapper.js +1 -1
  52. package/lib/cjs/src/shared/utils/KeyUsageMapper.js.map +2 -2
  53. package/lib/cjs/src/token/domain/TokenContextLoader.js +1 -1
  54. package/lib/cjs/src/token/domain/TokenContextLoader.js.map +3 -3
  55. package/lib/cjs/src/token/domain/TokenContextLoader.test.js +1 -1
  56. package/lib/cjs/src/token/domain/TokenContextLoader.test.js.map +3 -3
  57. package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.js +1 -1
  58. package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.js.map +3 -3
  59. package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.test.js +1 -1
  60. package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.test.js.map +3 -3
  61. package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.js +1 -1
  62. package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.js.map +2 -2
  63. package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.js +1 -1
  64. package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.js.map +3 -3
  65. package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.test.js +1 -1
  66. package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.test.js.map +2 -2
  67. package/lib/cjs/src/uniswap/domain/UniswapContextLoader.js +1 -1
  68. package/lib/cjs/src/uniswap/domain/UniswapContextLoader.js.map +3 -3
  69. package/lib/cjs/src/uniswap/domain/UniswapContextLoader.test.js +1 -1
  70. package/lib/cjs/src/uniswap/domain/UniswapContextLoader.test.js.map +3 -3
  71. package/lib/esm/src/ContextModuleBuilder.test.js +1 -1
  72. package/lib/esm/src/ContextModuleBuilder.test.js.map +2 -2
  73. package/lib/esm/src/DefaultContextModule.js +1 -1
  74. package/lib/esm/src/DefaultContextModule.js.map +3 -3
  75. package/lib/esm/src/DefaultContextModule.test.js +1 -1
  76. package/lib/esm/src/DefaultContextModule.test.js.map +3 -3
  77. package/lib/esm/src/calldata/data/HttpCalldataDescriptorDataSource.js +1 -1
  78. package/lib/esm/src/calldata/data/HttpCalldataDescriptorDataSource.js.map +3 -3
  79. package/lib/esm/src/calldata/domain/CalldataContextLoader.js +1 -1
  80. package/lib/esm/src/calldata/domain/CalldataContextLoader.js.map +3 -3
  81. package/lib/esm/src/calldata/domain/CalldataContextLoader.test.js +1 -1
  82. package/lib/esm/src/calldata/domain/CalldataContextLoader.test.js.map +3 -3
  83. package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.js +1 -1
  84. package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.js.map +3 -3
  85. package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js +1 -1
  86. package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js.map +3 -3
  87. package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.js +1 -1
  88. package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.js.map +3 -3
  89. package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.test.js +1 -1
  90. package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.test.js.map +3 -3
  91. package/lib/esm/src/index.js +1 -1
  92. package/lib/esm/src/index.js.map +2 -2
  93. package/lib/esm/src/nft/domain/NftContextLoader.js +1 -1
  94. package/lib/esm/src/nft/domain/NftContextLoader.js.map +3 -3
  95. package/lib/esm/src/nft/domain/NftContextLoader.test.js +1 -1
  96. package/lib/esm/src/nft/domain/NftContextLoader.test.js.map +3 -3
  97. package/lib/esm/src/proxy/data/HttpProxyDataSource.js +1 -1
  98. package/lib/esm/src/proxy/data/HttpProxyDataSource.js.map +3 -3
  99. package/lib/esm/src/proxy/data/HttpProxyDataSource.test.js +1 -1
  100. package/lib/esm/src/proxy/data/HttpProxyDataSource.test.js.map +3 -3
  101. package/lib/esm/src/proxy/data/HttpSafeProxyDataSource.js +1 -1
  102. package/lib/esm/src/proxy/data/HttpSafeProxyDataSource.js.map +2 -2
  103. package/lib/esm/src/proxy/data/HttpSafeProxyDataSource.test.js +1 -1
  104. package/lib/esm/src/proxy/data/HttpSafeProxyDataSource.test.js.map +2 -2
  105. package/lib/esm/src/proxy/domain/ProxyContextFieldLoader.js +1 -1
  106. package/lib/esm/src/proxy/domain/ProxyContextFieldLoader.js.map +3 -3
  107. package/lib/esm/src/proxy/domain/ProxyContextFieldLoader.test.js +1 -1
  108. package/lib/esm/src/proxy/domain/ProxyContextFieldLoader.test.js.map +2 -2
  109. package/lib/esm/src/shared/utils/KeyUsageMapper.js +1 -1
  110. package/lib/esm/src/shared/utils/KeyUsageMapper.js.map +2 -2
  111. package/lib/esm/src/token/domain/TokenContextLoader.js +1 -1
  112. package/lib/esm/src/token/domain/TokenContextLoader.js.map +3 -3
  113. package/lib/esm/src/token/domain/TokenContextLoader.test.js +1 -1
  114. package/lib/esm/src/token/domain/TokenContextLoader.test.js.map +3 -3
  115. package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.js +1 -1
  116. package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.js.map +3 -3
  117. package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.test.js +1 -1
  118. package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.test.js.map +3 -3
  119. package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.js +1 -1
  120. package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.js.map +2 -2
  121. package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.js +1 -1
  122. package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.js.map +3 -3
  123. package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.test.js +1 -1
  124. package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.test.js.map +2 -2
  125. package/lib/esm/src/uniswap/domain/UniswapContextLoader.js +1 -1
  126. package/lib/esm/src/uniswap/domain/UniswapContextLoader.js.map +3 -3
  127. package/lib/esm/src/uniswap/domain/UniswapContextLoader.test.js +1 -1
  128. package/lib/esm/src/uniswap/domain/UniswapContextLoader.test.js.map +3 -3
  129. package/lib/types/src/ContextModule.d.ts +1 -2
  130. package/lib/types/src/ContextModule.d.ts.map +1 -1
  131. package/lib/types/src/DefaultContextModule.d.ts +1 -2
  132. package/lib/types/src/DefaultContextModule.d.ts.map +1 -1
  133. package/lib/types/src/calldata/data/HttpCalldataDescriptorDataSource.d.ts.map +1 -1
  134. package/lib/types/src/calldata/domain/CalldataContextLoader.d.ts +12 -4
  135. package/lib/types/src/calldata/domain/CalldataContextLoader.d.ts.map +1 -1
  136. package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.d.ts +9 -4
  137. package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.d.ts.map +1 -1
  138. package/lib/types/src/external-plugin/domain/ExternalPluginContextLoader.d.ts +11 -4
  139. package/lib/types/src/external-plugin/domain/ExternalPluginContextLoader.d.ts.map +1 -1
  140. package/lib/types/src/index.d.ts +0 -1
  141. package/lib/types/src/index.d.ts.map +1 -1
  142. package/lib/types/src/nft/domain/NftContextLoader.d.ts +10 -4
  143. package/lib/types/src/nft/domain/NftContextLoader.d.ts.map +1 -1
  144. package/lib/types/src/pki/model/PkiCertificateInfo.d.ts +1 -2
  145. package/lib/types/src/pki/model/PkiCertificateInfo.d.ts.map +1 -1
  146. package/lib/types/src/proxy/data/HttpProxyDataSource.d.ts.map +1 -1
  147. package/lib/types/src/proxy/data/HttpSafeProxyDataSource.d.ts.map +1 -1
  148. package/lib/types/src/proxy/data/ProxyDataSource.d.ts +2 -0
  149. package/lib/types/src/proxy/data/ProxyDataSource.d.ts.map +1 -1
  150. package/lib/types/src/proxy/data/dto/SafeProxyImplementationAddressDto.d.ts +2 -0
  151. package/lib/types/src/proxy/data/dto/SafeProxyImplementationAddressDto.d.ts.map +1 -1
  152. package/lib/types/src/proxy/domain/ProxyContextFieldLoader.d.ts.map +1 -1
  153. package/lib/types/src/proxy/model/ProxyDelegateCall.d.ts +2 -0
  154. package/lib/types/src/proxy/model/ProxyDelegateCall.d.ts.map +1 -1
  155. package/lib/types/src/shared/domain/ContextLoader.d.ts +13 -4
  156. package/lib/types/src/shared/domain/ContextLoader.d.ts.map +1 -1
  157. package/lib/types/src/shared/utils/KeyUsageMapper.d.ts +1 -2
  158. package/lib/types/src/shared/utils/KeyUsageMapper.d.ts.map +1 -1
  159. package/lib/types/src/token/domain/TokenContextLoader.d.ts +10 -4
  160. package/lib/types/src/token/domain/TokenContextLoader.d.ts.map +1 -1
  161. package/lib/types/src/trusted-name/domain/TrustedNameContextLoader.d.ts +9 -4
  162. package/lib/types/src/trusted-name/domain/TrustedNameContextLoader.d.ts.map +1 -1
  163. package/lib/types/src/typed-data/data/HttpTypedDataDataSource.d.ts.map +1 -1
  164. package/lib/types/src/typed-data/domain/DefaultTypedDataContextLoader.d.ts.map +1 -1
  165. package/lib/types/src/uniswap/domain/UniswapContextLoader.d.ts +11 -4
  166. package/lib/types/src/uniswap/domain/UniswapContextLoader.d.ts.map +1 -1
  167. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  168. package/package.json +5 -5
  169. package/lib/cjs/src/shared/model/TransactionContext.js +0 -2
  170. package/lib/cjs/src/shared/model/TransactionContext.js.map +0 -7
  171. package/lib/esm/src/shared/model/TransactionContext.js +0 -1
  172. package/lib/esm/src/shared/model/TransactionContext.js.map +0 -7
  173. package/lib/types/src/shared/model/TransactionContext.d.ts +0 -8
  174. package/lib/types/src/shared/model/TransactionContext.d.ts.map +0 -1
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/proxy/domain/ProxyContextFieldLoader.test.ts"],
4
- "sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { type PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { type ProxyDataSource } from \"@/proxy/data/ProxyDataSource\";\nimport { ProxyContextFieldLoader } from \"@/proxy/domain/ProxyContextFieldLoader\";\nimport { type ProxyDelegateCall } from \"@/proxy/model/ProxyDelegateCall\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\n\ndescribe(\"ProxyContextFieldLoader\", () => {\n const mockProxyDataSource: ProxyDataSource = {\n getProxyImplementationAddress: vi.fn(),\n };\n const mockCertificateLoader: PkiCertificateLoader = {\n loadCertificate: vi.fn(),\n };\n const proxyContextFieldLoader = new ProxyContextFieldLoader(\n mockProxyDataSource,\n mockCertificateLoader,\n );\n\n const mockTransactionField = {\n chainId: 1,\n proxyAddress: \"0x1234567890abcdef\",\n calldata: \"0xabcdef1234567890\",\n challenge: \"test-challenge\",\n deviceModelId: DeviceModelId.STAX,\n };\n\n const mockProxyDelegateCall: ProxyDelegateCall = {\n implementationAddress: \"0x987654321fedcba0\",\n signedDescriptor: \"0x123456789abcdef0\",\n };\n\n const mockCertificate: PkiCertificate = {\n keyUsageNumber: 1,\n payload: new Uint8Array([1, 2, 3, 4]),\n };\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n describe(\"canHandle\", () => {\n it(\"should return true for valid proxy field\", () => {\n // GIVEN\n const validField = {\n chainId: 1,\n proxyAddress: \"0x1234567890abcdef\",\n calldata: \"0xabcdef1234567890\",\n challenge: \"test-challenge\",\n deviceModelId: DeviceModelId.STAX,\n };\n\n // THEN\n expect(\n proxyContextFieldLoader.canHandle(\n validField,\n ClearSignContextType.PROXY_INFO,\n ),\n ).toBe(true);\n });\n\n describe(\"should return false for invalid fields\", () => {\n const invalidFields = [\n { name: \"null\", value: null },\n { name: \"undefined\", value: undefined },\n { name: \"string\", value: \"invalid\" },\n { name: \"number\", value: 123 },\n { name: \"boolean\", value: true },\n { name: \"array\", value: [] },\n { name: \"empty object\", value: {} },\n {\n name: \"object missing chainId\",\n value: {\n proxyAddress: \"0x123\",\n calldata: \"0xabc\",\n challenge: \"test\",\n deviceModelId: DeviceModelId.STAX,\n },\n },\n {\n name: \"object missing proxyAddress\",\n value: {\n chainId: 1,\n calldata: \"0xabc\",\n challenge: \"test\",\n deviceModelId: DeviceModelId.STAX,\n },\n },\n {\n name: \"object missing calldata\",\n value: {\n chainId: 1,\n proxyAddress: \"0x123\",\n challenge: \"test\",\n deviceModelId: DeviceModelId.STAX,\n },\n },\n {\n name: \"object missing challenge\",\n value: {\n chainId: 1,\n proxyAddress: \"0x123\",\n calldata: \"0xabc\",\n deviceModelId: DeviceModelId.STAX,\n },\n },\n {\n name: \"object missing deviceModelId\",\n value: {\n chainId: 1,\n proxyAddress: \"0x123\",\n calldata: \"0xabc\",\n challenge: \"test\",\n },\n },\n ];\n\n test.each(invalidFields)(\"$name\", ({ value }) => {\n expect(\n proxyContextFieldLoader.canHandle(\n value,\n ClearSignContextType.PROXY_INFO,\n ),\n ).toBe(false);\n });\n });\n\n it(\"should return false for invalid expected type\", () => {\n expect(\n proxyContextFieldLoader.canHandle(\n mockTransactionField,\n ClearSignContextType.TOKEN,\n ),\n ).toBe(false);\n });\n });\n\n describe(\"loadField\", () => {\n it(\"should return error context when proxy data source fails\", async () => {\n // GIVEN\n const error = new Error(\"Proxy data source error\");\n vi.spyOn(\n mockProxyDataSource,\n \"getProxyImplementationAddress\",\n ).mockResolvedValue(Left(error));\n\n // WHEN\n const result =\n await proxyContextFieldLoader.loadField(mockTransactionField);\n\n // THEN\n expect(\n mockProxyDataSource.getProxyImplementationAddress,\n ).toHaveBeenCalledWith({\n calldata: mockTransactionField.calldata,\n proxyAddress: mockTransactionField.proxyAddress,\n chainId: mockTransactionField.chainId,\n challenge: mockTransactionField.challenge,\n });\n expect(result).toEqual({\n type: ClearSignContextType.ERROR,\n error: error,\n });\n expect(mockCertificateLoader.loadCertificate).not.toHaveBeenCalled();\n });\n\n it(\"should return proxy delegate call context when successful\", async () => {\n // GIVEN\n vi.spyOn(\n mockProxyDataSource,\n \"getProxyImplementationAddress\",\n ).mockResolvedValue(Right(mockProxyDelegateCall));\n vi.spyOn(mockCertificateLoader, \"loadCertificate\").mockResolvedValue(\n mockCertificate,\n );\n\n // WHEN\n const result =\n await proxyContextFieldLoader.loadField(mockTransactionField);\n\n // THEN\n expect(\n mockProxyDataSource.getProxyImplementationAddress,\n ).toHaveBeenCalledWith({\n calldata: mockTransactionField.calldata,\n proxyAddress: mockTransactionField.proxyAddress,\n chainId: mockTransactionField.chainId,\n challenge: mockTransactionField.challenge,\n });\n expect(mockCertificateLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: KeyId.CalCalldataKey,\n keyUsage: KeyUsage.Calldata,\n targetDevice: mockTransactionField.deviceModelId,\n });\n expect(result).toEqual({\n type: ClearSignContextType.PROXY_INFO,\n payload: mockProxyDelegateCall.signedDescriptor,\n certificate: mockCertificate,\n });\n });\n\n it(\"should return proxy delegate call context with undefined certificate when certificate loading returns undefined\", async () => {\n // GIVEN\n vi.spyOn(\n mockProxyDataSource,\n \"getProxyImplementationAddress\",\n ).mockResolvedValue(Right(mockProxyDelegateCall));\n vi.spyOn(mockCertificateLoader, \"loadCertificate\").mockResolvedValue(\n undefined,\n );\n\n // WHEN\n const result =\n await proxyContextFieldLoader.loadField(mockTransactionField);\n\n // THEN\n expect(\n mockProxyDataSource.getProxyImplementationAddress,\n ).toHaveBeenCalledWith({\n calldata: mockTransactionField.calldata,\n proxyAddress: mockTransactionField.proxyAddress,\n chainId: mockTransactionField.chainId,\n challenge: mockTransactionField.challenge,\n });\n expect(mockCertificateLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: KeyId.CalCalldataKey,\n keyUsage: KeyUsage.Calldata,\n targetDevice: mockTransactionField.deviceModelId,\n });\n expect(result).toEqual({\n type: ClearSignContextType.PROXY_INFO,\n payload: mockProxyDelegateCall.signedDescriptor,\n certificate: undefined,\n });\n });\n\n it(\"should handle different device model IDs correctly\", async () => {\n // GIVEN\n const nanoXField = {\n ...mockTransactionField,\n deviceModelId: DeviceModelId.NANO_X,\n };\n vi.spyOn(\n mockProxyDataSource,\n \"getProxyImplementationAddress\",\n ).mockResolvedValue(Right(mockProxyDelegateCall));\n vi.spyOn(mockCertificateLoader, \"loadCertificate\").mockResolvedValue(\n mockCertificate,\n );\n\n // WHEN\n const result = await proxyContextFieldLoader.loadField(nanoXField);\n\n // THEN\n expect(mockCertificateLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: KeyId.CalCalldataKey,\n keyUsage: KeyUsage.Calldata,\n targetDevice: DeviceModelId.NANO_X,\n });\n expect(result).toEqual({\n type: ClearSignContextType.PROXY_INFO,\n payload: mockProxyDelegateCall.signedDescriptor,\n certificate: mockCertificate,\n });\n });\n\n it(\"should handle different chain IDs and addresses correctly\", async () => {\n // GIVEN\n const customField = {\n ...mockTransactionField,\n chainId: 137,\n proxyAddress: \"0xdeadbeef\",\n calldata: \"0xcafebabe\",\n challenge: \"custom-challenge\",\n };\n vi.spyOn(\n mockProxyDataSource,\n \"getProxyImplementationAddress\",\n ).mockResolvedValue(Right(mockProxyDelegateCall));\n vi.spyOn(mockCertificateLoader, \"loadCertificate\").mockResolvedValue(\n mockCertificate,\n );\n\n // WHEN\n const result = await proxyContextFieldLoader.loadField(customField);\n\n // THEN\n expect(\n mockProxyDataSource.getProxyImplementationAddress,\n ).toHaveBeenCalledWith({\n calldata: \"0xcafebabe\",\n proxyAddress: \"0xdeadbeef\",\n chainId: 137,\n challenge: \"custom-challenge\",\n });\n expect(result).toEqual({\n type: ClearSignContextType.PROXY_INFO,\n payload: mockProxyDelegateCall.signedDescriptor,\n certificate: mockCertificate,\n });\n });\n\n it(\"should handle certificate loading failure gracefully\", async () => {\n // GIVEN\n vi.spyOn(\n mockProxyDataSource,\n \"getProxyImplementationAddress\",\n ).mockResolvedValue(Right(mockProxyDelegateCall));\n vi.spyOn(mockCertificateLoader, \"loadCertificate\").mockRejectedValue(\n new Error(\"Certificate loading failed\"),\n );\n\n // WHEN & THEN\n await expect(\n proxyContextFieldLoader.loadField(mockTransactionField),\n ).rejects.toThrow(\"Certificate loading failed\");\n\n expect(\n mockProxyDataSource.getProxyImplementationAddress,\n ).toHaveBeenCalled();\n expect(mockCertificateLoader.loadCertificate).toHaveBeenCalled();\n });\n\n it(\"should preserve error message from proxy data source\", async () => {\n // GIVEN\n const specificError = new Error(\"Network timeout error\");\n vi.spyOn(\n mockProxyDataSource,\n \"getProxyImplementationAddress\",\n ).mockResolvedValue(Left(specificError));\n\n // WHEN\n const result =\n await proxyContextFieldLoader.loadField(mockTransactionField);\n\n // THEN\n expect(result).toEqual({\n type: ClearSignContextType.ERROR,\n error: specificError,\n });\n });\n\n it(\"should handle empty signed descriptor\", async () => {\n // GIVEN\n const proxyCallWithEmptyDescriptor = {\n ...mockProxyDelegateCall,\n signedDescriptor: \"\",\n };\n vi.spyOn(\n mockProxyDataSource,\n \"getProxyImplementationAddress\",\n ).mockResolvedValue(Right(proxyCallWithEmptyDescriptor));\n vi.spyOn(mockCertificateLoader, \"loadCertificate\").mockResolvedValue(\n mockCertificate,\n );\n\n // WHEN\n const result =\n await proxyContextFieldLoader.loadField(mockTransactionField);\n\n // THEN\n expect(result).toEqual({\n type: ClearSignContextType.PROXY_INFO,\n payload: \"\",\n certificate: mockCertificate,\n });\n });\n });\n});\n"],
5
- "mappings": "AAAA,OAAS,iBAAAA,MAAqB,kCAC9B,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAG5B,OAAS,SAAAC,MAAa,oBACtB,OAAS,YAAAC,MAAgB,uBAGzB,OAAS,2BAAAC,MAA+B,yCAExC,OAAS,wBAAAC,MAA4B,kCAErC,SAAS,0BAA2B,IAAM,CACxC,MAAMC,EAAuC,CAC3C,8BAA+B,GAAG,GAAG,CACvC,EACMC,EAA8C,CAClD,gBAAiB,GAAG,GAAG,CACzB,EACMC,EAA0B,IAAIJ,EAClCE,EACAC,C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AoB,EAG9D,OAAOO,CAAM,EAAE,QAAQ,CACrB,KAAMX,EAAqB,WAC3B,QAAS,GACT,YAAaM,CACf,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
4
+ "sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { type PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { type ProxyDataSource } from \"@/proxy/data/ProxyDataSource\";\nimport { ProxyContextFieldLoader } from \"@/proxy/domain/ProxyContextFieldLoader\";\nimport { type ProxyDelegateCall } from \"@/proxy/model/ProxyDelegateCall\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\n\ndescribe(\"ProxyContextFieldLoader\", () => {\n const mockProxyDataSource: ProxyDataSource = {\n getProxyImplementationAddress: vi.fn(),\n };\n const mockCertificateLoader: PkiCertificateLoader = {\n loadCertificate: vi.fn(),\n };\n const proxyContextFieldLoader = new ProxyContextFieldLoader(\n mockProxyDataSource,\n mockCertificateLoader,\n );\n\n const mockTransactionField = {\n chainId: 1,\n proxyAddress: \"0x1234567890abcdef\",\n calldata: \"0xabcdef1234567890\",\n challenge: \"test-challenge\",\n deviceModelId: DeviceModelId.STAX,\n };\n\n const mockProxyDelegateCall: ProxyDelegateCall = {\n implementationAddress: \"0x987654321fedcba0\",\n signedDescriptor: \"0x123456789abcdef0\",\n keyId: KeyId.CalCalldataKey,\n keyUsage: KeyUsage.Calldata,\n };\n\n const mockCertificate: PkiCertificate = {\n keyUsageNumber: 1,\n payload: new Uint8Array([1, 2, 3, 4]),\n };\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n describe(\"canHandle\", () => {\n it(\"should return true for valid proxy field\", () => {\n // GIVEN\n const validField = {\n chainId: 1,\n proxyAddress: \"0x1234567890abcdef\",\n calldata: \"0xabcdef1234567890\",\n challenge: \"test-challenge\",\n deviceModelId: DeviceModelId.STAX,\n };\n\n // THEN\n expect(\n proxyContextFieldLoader.canHandle(\n validField,\n ClearSignContextType.PROXY_INFO,\n ),\n ).toBe(true);\n });\n\n describe(\"should return false for invalid fields\", () => {\n const invalidFields = [\n { name: \"null\", value: null },\n { name: \"undefined\", value: undefined },\n { name: \"string\", value: \"invalid\" },\n { name: \"number\", value: 123 },\n { name: \"boolean\", value: true },\n { name: \"array\", value: [] },\n { name: \"empty object\", value: {} },\n {\n name: \"object missing chainId\",\n value: {\n proxyAddress: \"0x123\",\n calldata: \"0xabc\",\n challenge: \"test\",\n deviceModelId: DeviceModelId.STAX,\n },\n },\n {\n name: \"object missing proxyAddress\",\n value: {\n chainId: 1,\n calldata: \"0xabc\",\n challenge: \"test\",\n deviceModelId: DeviceModelId.STAX,\n },\n },\n {\n name: \"object missing calldata\",\n value: {\n chainId: 1,\n proxyAddress: \"0x123\",\n challenge: \"test\",\n deviceModelId: DeviceModelId.STAX,\n },\n },\n {\n name: \"object missing challenge\",\n value: {\n chainId: 1,\n proxyAddress: \"0x123\",\n calldata: \"0xabc\",\n deviceModelId: DeviceModelId.STAX,\n },\n },\n {\n name: \"object missing deviceModelId\",\n value: {\n chainId: 1,\n proxyAddress: \"0x123\",\n calldata: \"0xabc\",\n challenge: \"test\",\n },\n },\n ];\n\n test.each(invalidFields)(\"$name\", ({ value }) => {\n expect(\n proxyContextFieldLoader.canHandle(\n value,\n ClearSignContextType.PROXY_INFO,\n ),\n ).toBe(false);\n });\n });\n\n it(\"should return false for invalid expected type\", () => {\n expect(\n proxyContextFieldLoader.canHandle(\n mockTransactionField,\n ClearSignContextType.TOKEN,\n ),\n ).toBe(false);\n });\n });\n\n describe(\"loadField\", () => {\n it(\"should return error context when proxy data source fails\", async () => {\n // GIVEN\n const error = new Error(\"Proxy data source error\");\n vi.spyOn(\n mockProxyDataSource,\n \"getProxyImplementationAddress\",\n ).mockResolvedValue(Left(error));\n\n // WHEN\n const result =\n await proxyContextFieldLoader.loadField(mockTransactionField);\n\n // THEN\n expect(\n mockProxyDataSource.getProxyImplementationAddress,\n ).toHaveBeenCalledWith({\n calldata: mockTransactionField.calldata,\n proxyAddress: mockTransactionField.proxyAddress,\n chainId: mockTransactionField.chainId,\n challenge: mockTransactionField.challenge,\n });\n expect(result).toEqual({\n type: ClearSignContextType.ERROR,\n error: error,\n });\n expect(mockCertificateLoader.loadCertificate).not.toHaveBeenCalled();\n });\n\n it(\"should return proxy delegate call context when successful\", async () => {\n // GIVEN\n vi.spyOn(\n mockProxyDataSource,\n \"getProxyImplementationAddress\",\n ).mockResolvedValue(Right(mockProxyDelegateCall));\n vi.spyOn(mockCertificateLoader, \"loadCertificate\").mockResolvedValue(\n mockCertificate,\n );\n\n // WHEN\n const result =\n await proxyContextFieldLoader.loadField(mockTransactionField);\n\n // THEN\n expect(\n mockProxyDataSource.getProxyImplementationAddress,\n ).toHaveBeenCalledWith({\n calldata: mockTransactionField.calldata,\n proxyAddress: mockTransactionField.proxyAddress,\n chainId: mockTransactionField.chainId,\n challenge: mockTransactionField.challenge,\n });\n expect(mockCertificateLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: KeyId.CalCalldataKey,\n keyUsage: KeyUsage.Calldata,\n targetDevice: mockTransactionField.deviceModelId,\n });\n expect(result).toEqual({\n type: ClearSignContextType.PROXY_INFO,\n payload: mockProxyDelegateCall.signedDescriptor,\n certificate: mockCertificate,\n });\n });\n\n it(\"should return proxy delegate call context with undefined certificate when certificate loading returns undefined\", async () => {\n // GIVEN\n vi.spyOn(\n mockProxyDataSource,\n \"getProxyImplementationAddress\",\n ).mockResolvedValue(Right(mockProxyDelegateCall));\n vi.spyOn(mockCertificateLoader, \"loadCertificate\").mockResolvedValue(\n undefined,\n );\n\n // WHEN\n const result =\n await proxyContextFieldLoader.loadField(mockTransactionField);\n\n // THEN\n expect(\n mockProxyDataSource.getProxyImplementationAddress,\n ).toHaveBeenCalledWith({\n calldata: mockTransactionField.calldata,\n proxyAddress: mockTransactionField.proxyAddress,\n chainId: mockTransactionField.chainId,\n challenge: mockTransactionField.challenge,\n });\n expect(mockCertificateLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: KeyId.CalCalldataKey,\n keyUsage: KeyUsage.Calldata,\n targetDevice: mockTransactionField.deviceModelId,\n });\n expect(result).toEqual({\n type: ClearSignContextType.PROXY_INFO,\n payload: mockProxyDelegateCall.signedDescriptor,\n certificate: undefined,\n });\n });\n\n it(\"should handle different device model IDs correctly\", async () => {\n // GIVEN\n const nanoXField = {\n ...mockTransactionField,\n deviceModelId: DeviceModelId.NANO_X,\n };\n vi.spyOn(\n mockProxyDataSource,\n \"getProxyImplementationAddress\",\n ).mockResolvedValue(Right(mockProxyDelegateCall));\n vi.spyOn(mockCertificateLoader, \"loadCertificate\").mockResolvedValue(\n mockCertificate,\n );\n\n // WHEN\n const result = await proxyContextFieldLoader.loadField(nanoXField);\n\n // THEN\n expect(mockCertificateLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: KeyId.CalCalldataKey,\n keyUsage: KeyUsage.Calldata,\n targetDevice: DeviceModelId.NANO_X,\n });\n expect(result).toEqual({\n type: ClearSignContextType.PROXY_INFO,\n payload: mockProxyDelegateCall.signedDescriptor,\n certificate: mockCertificate,\n });\n });\n\n it(\"should handle different chain IDs and addresses correctly\", async () => {\n // GIVEN\n const customField = {\n ...mockTransactionField,\n chainId: 137,\n proxyAddress: \"0xdeadbeef\",\n calldata: \"0xcafebabe\",\n challenge: \"custom-challenge\",\n };\n vi.spyOn(\n mockProxyDataSource,\n \"getProxyImplementationAddress\",\n ).mockResolvedValue(Right(mockProxyDelegateCall));\n vi.spyOn(mockCertificateLoader, \"loadCertificate\").mockResolvedValue(\n mockCertificate,\n );\n\n // WHEN\n const result = await proxyContextFieldLoader.loadField(customField);\n\n // THEN\n expect(\n mockProxyDataSource.getProxyImplementationAddress,\n ).toHaveBeenCalledWith({\n calldata: \"0xcafebabe\",\n proxyAddress: \"0xdeadbeef\",\n chainId: 137,\n challenge: \"custom-challenge\",\n });\n expect(result).toEqual({\n type: ClearSignContextType.PROXY_INFO,\n payload: mockProxyDelegateCall.signedDescriptor,\n certificate: mockCertificate,\n });\n });\n\n it(\"should handle certificate loading failure gracefully\", async () => {\n // GIVEN\n vi.spyOn(\n mockProxyDataSource,\n \"getProxyImplementationAddress\",\n ).mockResolvedValue(Right(mockProxyDelegateCall));\n vi.spyOn(mockCertificateLoader, \"loadCertificate\").mockRejectedValue(\n new Error(\"Certificate loading failed\"),\n );\n\n // WHEN & THEN\n await expect(\n proxyContextFieldLoader.loadField(mockTransactionField),\n ).rejects.toThrow(\"Certificate loading failed\");\n\n expect(\n mockProxyDataSource.getProxyImplementationAddress,\n ).toHaveBeenCalled();\n expect(mockCertificateLoader.loadCertificate).toHaveBeenCalled();\n });\n\n it(\"should preserve error message from proxy data source\", async () => {\n // GIVEN\n const specificError = new Error(\"Network timeout error\");\n vi.spyOn(\n mockProxyDataSource,\n \"getProxyImplementationAddress\",\n ).mockResolvedValue(Left(specificError));\n\n // WHEN\n const result =\n await proxyContextFieldLoader.loadField(mockTransactionField);\n\n // THEN\n expect(result).toEqual({\n type: ClearSignContextType.ERROR,\n error: specificError,\n });\n });\n\n it(\"should handle empty signed descriptor\", async () => {\n // GIVEN\n const proxyCallWithEmptyDescriptor = {\n ...mockProxyDelegateCall,\n signedDescriptor: \"\",\n };\n vi.spyOn(\n mockProxyDataSource,\n \"getProxyImplementationAddress\",\n ).mockResolvedValue(Right(proxyCallWithEmptyDescriptor));\n vi.spyOn(mockCertificateLoader, \"loadCertificate\").mockResolvedValue(\n mockCertificate,\n );\n\n // WHEN\n const result =\n await proxyContextFieldLoader.loadField(mockTransactionField);\n\n // THEN\n expect(result).toEqual({\n type: ClearSignContextType.PROXY_INFO,\n payload: \"\",\n certificate: mockCertificate,\n });\n });\n });\n});\n"],
5
+ "mappings": "AAAA,OAAS,iBAAAA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,MAAMR,EAAwB,UAAUC,CAAoB,EAG9D,OAAOO,CAAM,EAAE,QAAQ,CACrB,KAAMX,EAAqB,MAC3B,MAAOc,CACT,CAAC,CACH,CAAC,EAED,GAAG,wCAAyC,SAAY,CAEtD,MAAMC,EAA+B,CACnC,GAAGV,EACH,iBAAkB,EACpB,EACA,GAAG,MACDJ,EACA,+BACF,EAAE,kBAAkBL,EAAMmB,CAA4B,CAAC,EACvD,GAAG,MAAMb,EAAuB,iBAAiB,EAAE,kBACjDI,CACF,EAGA,MAAMK,EACJ,MAAMR,EAAwB,UAAUC,CAAoB,EAG9D,OAAOO,CAAM,EAAE,QAAQ,CACrB,KAAMX,EAAqB,WAC3B,QAAS,GACT,YAAaM,CACf,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
6
  "names": ["DeviceModelId", "Left", "Right", "KeyId", "KeyUsage", "ProxyContextFieldLoader", "ClearSignContextType", "mockProxyDataSource", "mockCertificateLoader", "proxyContextFieldLoader", "mockTransactionField", "mockProxyDelegateCall", "mockCertificate", "validField", "invalidFields", "value", "error", "result", "nanoXField", "customField", "specificError", "proxyCallWithEmptyDescriptor"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{KeyUsage as e}from"../../pki/model/KeyUsage";class s{static keyUsageMap=new Map([[e.GenuineCheck,1],[e.ExchangePayload,2],[e.NftMeta,3],[e.TrustedName,4],[e.BackupProvider,5],[e.ProtectOrchestrator,6],[e.PluginMeta,7],[e.CoinMeta,8],[e.SeedIdAuth,9],[e.TxSimulationSigner,10],[e.Calldata,11],[e.Network,12]]);static mapKeyUsageForFirmware(a){return this.keyUsageMap.get(a)??-1}}export{s as KeyUsageMapper};
1
+ import{KeyUsage as e}from"../../pki/model/KeyUsage";class s{static keyUsageMap=new Map([[e.GenuineCheck,1],[e.ExchangePayload,2],[e.NftMeta,3],[e.TrustedName,4],[e.BackupProvider,5],[e.ProtectOrchestrator,6],[e.PluginMeta,7],[e.CoinMeta,8],[e.SeedIdAuth,9],[e.TxSimulationSigner,10],[e.Calldata,11],[e.Network,12]]);static mapKeyUsageForFirmware(a){return Object.values(e).includes(a)?this.keyUsageMap.get(a)??-1:-1}}export{s as KeyUsageMapper};
2
2
  //# sourceMappingURL=KeyUsageMapper.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/shared/utils/KeyUsageMapper.ts"],
4
- "sourcesContent": ["import { KeyUsage } from \"@/pki/model/KeyUsage\";\n\nexport class KeyUsageMapper {\n private static keyUsageMap = new Map<KeyUsage, number>([\n [KeyUsage.GenuineCheck, 1],\n [KeyUsage.ExchangePayload, 2],\n [KeyUsage.NftMeta, 3],\n [KeyUsage.TrustedName, 4],\n [KeyUsage.BackupProvider, 5],\n [KeyUsage.ProtectOrchestrator, 6],\n [KeyUsage.PluginMeta, 7],\n [KeyUsage.CoinMeta, 8],\n [KeyUsage.SeedIdAuth, 9],\n [KeyUsage.TxSimulationSigner, 10],\n [KeyUsage.Calldata, 11],\n [KeyUsage.Network, 12],\n ]);\n\n static mapKeyUsageForFirmware(keyUsage: KeyUsage): number {\n return this.keyUsageMap.get(keyUsage as KeyUsage) ?? -1;\n }\n}\n"],
5
- "mappings": "AAAA,OAAS,YAAAA,MAAgB,uBAElB,MAAMC,CAAe,CAC1B,OAAe,YAAc,IAAI,IAAsB,CACrD,CAACD,EAAS,aAAc,CAAC,EACzB,CAACA,EAAS,gBAAiB,CAAC,EAC5B,CAACA,EAAS,QAAS,CAAC,EACpB,CAACA,EAAS,YAAa,CAAC,EACxB,CAACA,EAAS,eAAgB,CAAC,EAC3B,CAACA,EAAS,oBAAqB,CAAC,EAChC,CAACA,EAAS,WAAY,CAAC,EACvB,CAACA,EAAS,SAAU,CAAC,EACrB,CAACA,EAAS,WAAY,CAAC,EACvB,CAACA,EAAS,mBAAoB,EAAE,EAChC,CAACA,EAAS,SAAU,EAAE,EACtB,CAACA,EAAS,QAAS,EAAE,CACvB,CAAC,EAED,OAAO,uBAAuBE,EAA4B,CACxD,OAAO,KAAK,YAAY,IAAIA,CAAoB,GAAK,EACvD,CACF",
4
+ "sourcesContent": ["import { KeyUsage } from \"@/pki/model/KeyUsage\";\n\nexport class KeyUsageMapper {\n private static keyUsageMap = new Map<KeyUsage, number>([\n [KeyUsage.GenuineCheck, 1],\n [KeyUsage.ExchangePayload, 2],\n [KeyUsage.NftMeta, 3],\n [KeyUsage.TrustedName, 4],\n [KeyUsage.BackupProvider, 5],\n [KeyUsage.ProtectOrchestrator, 6],\n [KeyUsage.PluginMeta, 7],\n [KeyUsage.CoinMeta, 8],\n [KeyUsage.SeedIdAuth, 9],\n [KeyUsage.TxSimulationSigner, 10],\n [KeyUsage.Calldata, 11],\n [KeyUsage.Network, 12],\n ]);\n\n static mapKeyUsageForFirmware(keyUsage: string): number {\n if (Object.values(KeyUsage).includes(keyUsage as KeyUsage)) {\n return this.keyUsageMap.get(keyUsage as KeyUsage) ?? -1;\n }\n return -1;\n }\n}\n"],
5
+ "mappings": "AAAA,OAAS,YAAAA,MAAgB,uBAElB,MAAMC,CAAe,CAC1B,OAAe,YAAc,IAAI,IAAsB,CACrD,CAACD,EAAS,aAAc,CAAC,EACzB,CAACA,EAAS,gBAAiB,CAAC,EAC5B,CAACA,EAAS,QAAS,CAAC,EACpB,CAACA,EAAS,YAAa,CAAC,EACxB,CAACA,EAAS,eAAgB,CAAC,EAC3B,CAACA,EAAS,oBAAqB,CAAC,EAChC,CAACA,EAAS,WAAY,CAAC,EACvB,CAACA,EAAS,SAAU,CAAC,EACrB,CAACA,EAAS,WAAY,CAAC,EACvB,CAACA,EAAS,mBAAoB,EAAE,EAChC,CAACA,EAAS,SAAU,EAAE,EACtB,CAACA,EAAS,QAAS,EAAE,CACvB,CAAC,EAED,OAAO,uBAAuBE,EAA0B,CACtD,OAAI,OAAO,OAAOF,CAAQ,EAAE,SAASE,CAAoB,EAChD,KAAK,YAAY,IAAIA,CAAoB,GAAK,GAEhD,EACT,CACF",
6
6
  "names": ["KeyUsage", "KeyUsageMapper", "keyUsage"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var m=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var p=(n,e,t,r)=>{for(var o=r>1?void 0:r?S(e,t):e,i=n.length-1,a;i>=0;i--)(a=n[i])&&(o=(r?a(e,t,o):a(o))||o);return r&&o&&m(e,t,o),o},l=(n,e)=>(t,r)=>e(t,r,n);import{isHexaString as d}from"@ledgerhq/device-management-kit";import{inject as f,injectable as x}from"inversify";import{ClearSignContextType as s}from"../../shared/model/ClearSignContext";import{tokenTypes as g}from"../../token/di/tokenTypes";var u=(t=>(t.Approve="0x095ea7b3",t.Transfer="0xa9059cbb",t))(u||{});const y=Object.values(u);let c=class{_dataSource;constructor(e){this._dataSource=e}async load(e){const{to:t,selector:r,chainId:o}=e;return t?d(r)?this.isSelectorSupported(r)?[(await this._dataSource.getTokenInfosPayload({address:t,chainId:o})).caseOf({Left:a=>({type:s.ERROR,error:a}),Right:a=>({type:s.TOKEN,payload:a})})]:[]:[{type:s.ERROR,error:new Error("Invalid selector")}]:[]}isSelectorSupported(e){return Object.values(y).includes(e)}};c=p([x(),l(0,f(g.TokenDataSource))],c);export{u as ERC20_SUPPORTED_SELECTORS,c as TokenContextLoader};
1
+ var d=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var l=(a,e,t,o)=>{for(var r=o>1?void 0:o?u(e,t):e,n=a.length-1,i;n>=0;n--)(i=a[n])&&(r=(o?i(e,t,r):i(r))||r);return o&&r&&d(e,t,r),r},p=(a,e)=>(t,o)=>e(t,o,a);import{isHexaString as S}from"@ledgerhq/device-management-kit";import{inject as m,injectable as y}from"inversify";import{ClearSignContextType as s}from"../../shared/model/ClearSignContext";import{tokenTypes as g}from"../../token/di/tokenTypes";var x=(t=>(t.Approve="0x095ea7b3",t.Transfer="0xa9059cbb",t))(x||{});const C=Object.values(x),T=[s.TOKEN];let c=class{_dataSource;constructor(e){this._dataSource=e}canHandle(e,t){return typeof e=="object"&&e!==null&&"to"in e&&"selector"in e&&"chainId"in e&&typeof e.chainId=="number"&&S(e.to)&&e.to!=="0x"&&S(e.selector)&&this.isSelectorSupported(e.selector)&&T.every(o=>t.includes(o))}async load(e){const{to:t,chainId:o}=e;return[(await this._dataSource.getTokenInfosPayload({address:t,chainId:o})).caseOf({Left:n=>({type:s.ERROR,error:n}),Right:n=>({type:s.TOKEN,payload:n})})]}isSelectorSupported(e){return Object.values(C).includes(e)}};c=l([y(),p(0,m(g.TokenDataSource))],c);export{x as ERC20_SUPPORTED_SELECTORS,c as TokenContextLoader};
2
2
  //# sourceMappingURL=TokenContextLoader.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/token/domain/TokenContextLoader.ts"],
4
- "sourcesContent": ["import { HexaString, 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 { TokenDataSource } from \"@/token/data/TokenDataSource\";\nimport { tokenTypes } from \"@/token/di/tokenTypes\";\n\nexport enum ERC20_SUPPORTED_SELECTORS {\n Approve = \"0x095ea7b3\",\n Transfer = \"0xa9059cbb\",\n}\n\nconst SUPPORTED_SELECTORS: HexaString[] = Object.values(\n ERC20_SUPPORTED_SELECTORS,\n);\n\n@injectable()\nexport class TokenContextLoader implements ContextLoader {\n private _dataSource: TokenDataSource;\n\n constructor(@inject(tokenTypes.TokenDataSource) dataSource: TokenDataSource) {\n this._dataSource = dataSource;\n }\n\n async load(ctx: TransactionContext): Promise<ClearSignContext[]> {\n const { to, selector, chainId } = ctx;\n if (!to) {\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 if (!this.isSelectorSupported(selector)) {\n return [];\n }\n\n const payload = await this._dataSource.getTokenInfosPayload({\n address: to,\n chainId,\n });\n\n return [\n payload.caseOf({\n Left: (error): ClearSignContext => ({\n type: ClearSignContextType.ERROR,\n error,\n }),\n Right: (value): ClearSignContext => ({\n type: ClearSignContextType.TOKEN,\n payload: value,\n }),\n }),\n ];\n }\n\n private isSelectorSupported(selector: HexaString) {\n return Object.values(SUPPORTED_SELECTORS).includes(selector);\n }\n}\n"],
5
- "mappings": "iOAAA,OAAqB,gBAAAA,MAAoB,kCACzC,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YAGnC,OAEE,wBAAAC,MACK,kCAGP,OAAS,cAAAC,MAAkB,wBAEpB,IAAKC,OACVA,EAAA,QAAU,aACVA,EAAA,SAAW,aAFDA,OAAA,IAKZ,MAAMC,EAAoC,OAAO,OAC/CD,CACF,EAGO,IAAME,EAAN,KAAkD,CAC/C,YAER,YAAgDC,EAA6B,CAC3E,KAAK,YAAcA,CACrB,CAEA,MAAM,KAAKC,EAAsD,CAC/D,KAAM,CAAE,GAAAC,EAAI,SAAAC,EAAU,QAAAC,CAAQ,EAAIH,EAClC,OAAKC,EAIAG,EAAaF,CAAQ,EASrB,KAAK,oBAAoBA,CAAQ,EAS/B,EALS,MAAM,KAAK,YAAY,qBAAqB,CAC1D,QAASD,EACT,QAAAE,CACF,CAAC,GAGS,OAAO,CACb,KAAOE,IAA6B,CAClC,KAAMC,EAAqB,MAC3B,MAAAD,CACF,GACA,MAAQE,IAA6B,CACnC,KAAMD,EAAqB,MAC3B,QAASC,CACX,EACF,CAAC,CACH,EAnBS,CAAC,EATD,CACL,CACE,KAAMD,EAAqB,MAC3B,MAAO,IAAI,MAAM,kBAAkB,CACrC,CACF,EATO,CAAC,CAiCZ,CAEQ,oBAAoBJ,EAAsB,CAChD,OAAO,OAAO,OAAOL,CAAmB,EAAE,SAASK,CAAQ,CAC7D,CACF,EAhDaJ,EAANU,EAAA,CADNC,EAAW,EAIGC,EAAA,EAAAC,EAAOC,EAAW,eAAe,IAHnCd",
6
- "names": ["isHexaString", "inject", "injectable", "ClearSignContextType", "tokenTypes", "ERC20_SUPPORTED_SELECTORS", "SUPPORTED_SELECTORS", "TokenContextLoader", "dataSource", "ctx", "to", "selector", "chainId", "isHexaString", "error", "ClearSignContextType", "value", "__decorateClass", "injectable", "__decorateParam", "inject", "tokenTypes"]
4
+ "sourcesContent": ["import { HexaString, 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 type { TokenDataSource } from \"@/token/data/TokenDataSource\";\nimport { tokenTypes } from \"@/token/di/tokenTypes\";\n\nexport enum ERC20_SUPPORTED_SELECTORS {\n Approve = \"0x095ea7b3\",\n Transfer = \"0xa9059cbb\",\n}\n\nconst SUPPORTED_SELECTORS: HexaString[] = Object.values(\n ERC20_SUPPORTED_SELECTORS,\n);\n\nconst SUPPORTED_TYPES: ClearSignContextType[] = [ClearSignContextType.TOKEN];\n\nexport type TokenContextInput = {\n to: HexaString;\n selector: HexaString;\n chainId: number;\n};\n\n@injectable()\nexport class TokenContextLoader implements ContextLoader<TokenContextInput> {\n private _dataSource: TokenDataSource;\n\n constructor(@inject(tokenTypes.TokenDataSource) dataSource: TokenDataSource) {\n this._dataSource = dataSource;\n }\n\n canHandle(\n input: unknown,\n expectedTypes: ClearSignContextType[],\n ): input is TokenContextInput {\n return (\n typeof input === \"object\" &&\n input !== null &&\n \"to\" in input &&\n \"selector\" in input &&\n \"chainId\" in input &&\n typeof input.chainId === \"number\" &&\n isHexaString(input.to) &&\n input.to !== \"0x\" &&\n isHexaString(input.selector) &&\n this.isSelectorSupported(input.selector) &&\n SUPPORTED_TYPES.every((type) => expectedTypes.includes(type))\n );\n }\n\n async load(input: TokenContextInput): Promise<ClearSignContext[]> {\n const { to, chainId } = input;\n\n const payload = await this._dataSource.getTokenInfosPayload({\n address: to,\n chainId,\n });\n\n return [\n payload.caseOf({\n Left: (error): ClearSignContext => ({\n type: ClearSignContextType.ERROR,\n error,\n }),\n Right: (value): ClearSignContext => ({\n type: ClearSignContextType.TOKEN,\n payload: value,\n }),\n }),\n ];\n }\n\n private isSelectorSupported(selector: HexaString) {\n return Object.values(SUPPORTED_SELECTORS).includes(selector);\n }\n}\n"],
5
+ "mappings": "iOAAA,OAAqB,gBAAAA,MAAoB,kCACzC,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YAGnC,OAEE,wBAAAC,MACK,kCAEP,OAAS,cAAAC,MAAkB,wBAEpB,IAAKC,OACVA,EAAA,QAAU,aACVA,EAAA,SAAW,aAFDA,OAAA,IAKZ,MAAMC,EAAoC,OAAO,OAC/CD,CACF,EAEME,EAA0C,CAACC,EAAqB,KAAK,EASpE,IAAMC,EAAN,KAAqE,CAClE,YAER,YAAgDC,EAA6B,CAC3E,KAAK,YAAcA,CACrB,CAEA,UACEC,EACAC,EAC4B,CAC5B,OACE,OAAOD,GAAU,UACjBA,IAAU,MACV,OAAQA,GACR,aAAcA,GACd,YAAaA,GACb,OAAOA,EAAM,SAAY,UACzBE,EAAaF,EAAM,EAAE,GACrBA,EAAM,KAAO,MACbE,EAAaF,EAAM,QAAQ,GAC3B,KAAK,oBAAoBA,EAAM,QAAQ,GACvCJ,EAAgB,MAAOO,GAASF,EAAc,SAASE,CAAI,CAAC,CAEhE,CAEA,MAAM,KAAKH,EAAuD,CAChE,KAAM,CAAE,GAAAI,EAAI,QAAAC,CAAQ,EAAIL,EAOxB,MAAO,EALS,MAAM,KAAK,YAAY,qBAAqB,CAC1D,QAASI,EACT,QAAAC,CACF,CAAC,GAGS,OAAO,CACb,KAAOC,IAA6B,CAClC,KAAMT,EAAqB,MAC3B,MAAAS,CACF,GACA,MAAQC,IAA6B,CACnC,KAAMV,EAAqB,MAC3B,QAASU,CACX,EACF,CAAC,CACH,CACF,CAEQ,oBAAoBC,EAAsB,CAChD,OAAO,OAAO,OAAOb,CAAmB,EAAE,SAASa,CAAQ,CAC7D,CACF,EAnDaV,EAANW,EAAA,CADNC,EAAW,EAIGC,EAAA,EAAAC,EAAOC,EAAW,eAAe,IAHnCf",
6
+ "names": ["isHexaString", "inject", "injectable", "ClearSignContextType", "tokenTypes", "ERC20_SUPPORTED_SELECTORS", "SUPPORTED_SELECTORS", "SUPPORTED_TYPES", "ClearSignContextType", "TokenContextLoader", "dataSource", "input", "expectedTypes", "isHexaString", "type", "to", "chainId", "error", "value", "selector", "__decorateClass", "injectable", "__decorateParam", "inject", "tokenTypes"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{Left as n,Right as s}from"purify-ts";import{ClearSignContextType as r}from"../../shared/model/ClearSignContext";import{TokenContextLoader as c}from"../../token/domain/TokenContextLoader";describe("TokenContextLoader",()=>{const t={getTokenInfosPayload:vi.fn()},a=new c(t);beforeEach(()=>{vi.restoreAllMocks(),vi.spyOn(t,"getTokenInfosPayload").mockImplementation(({address:e})=>Promise.resolve(s(`payload-${e}`)))}),describe("load function",()=>{it("should return an empty array if transaction dest is undefined",async()=>{const e={to:void 0},o=await a.load(e);expect(o).toEqual([])}),it("should return an error when datasource returns an error",async()=>{const e={to:"0xdAC17F958D2ee523a2206206994597C13D831ec7",chainId:1,selector:"0x095ea7b3"};vi.spyOn(t,"getTokenInfosPayload").mockResolvedValue(n(new Error("error")));const o=await a.load(e);expect(o).toEqual([{type:r.ERROR,error:new Error("error")}])}),it("should return a correct response",async()=>{const e={to:"0xdAC17F958D2ee523a2206206994597C13D831ec7",chainId:1,selector:"0x095ea7b3"},o=await a.load(e);expect(o).toEqual([{type:r.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"}])})})});
1
+ import{Left as i,Right as c}from"purify-ts";import{ClearSignContextType as o}from"../../shared/model/ClearSignContext";import{TokenContextLoader as l}from"../../token/domain/TokenContextLoader";describe("TokenContextLoader",()=>{const a={getTokenInfosPayload:vi.fn()},t=new l(a);beforeEach(()=>{vi.restoreAllMocks(),vi.spyOn(a,"getTokenInfosPayload").mockImplementation(({address:e})=>Promise.resolve(c(`payload-${e}`)))}),describe("canHandle function",()=>{const e={to:"0xdAC17F958D2ee523a2206206994597C13D831ec7",selector:"0x095ea7b3",chainId:1};it("should return true for valid input",()=>{expect(t.canHandle(e,[o.TOKEN])).toBe(!0)}),it("should return false for invalid expected type",()=>{expect(t.canHandle(e,[o.NFT])).toBe(!1)}),it.each([[null,"null input"],[void 0,"undefined input"],[{},"empty object"],["string","string input"],[123,"number input"]])("should return false for %s",(n,r)=>{expect(t.canHandle(n,[o.TOKEN])).toBe(!1)}),it.each([[{...e,to:void 0},"missing to"],[{...e,selector:void 0},"missing selector"],[{...e,chainId:void 0},"missing chainId"]])("should return false for %s",(n,r)=>{expect(t.canHandle(n,[o.TOKEN])).toBe(!1)}),it.each([[{...e,to:"invalid-hex"},"invalid to hex"],[{...e,to:"0x"},"empty to hex"],[{...e,to:"not-hex-at-all"},"non-hex to"],[{...e,selector:"invalid-hex"},"invalid selector hex"],[{...e,selector:"0x"},"empty selector hex"],[{...e,selector:"not-hex-at-all"},"non-hex selector"]])("should return false for %s",(n,r)=>{expect(t.canHandle(n,[o.TOKEN])).toBe(!1)}),it.each([[{...e,chainId:"1"},"string chainId"],[{...e,chainId:null},"null chainId"],[{...e,chainId:void 0},"undefined chainId"]])("should return false for %s",(n,r)=>{expect(t.canHandle(n,[o.TOKEN])).toBe(!1)})}),describe("load function",()=>{it("should return an error when datasource returns an error",async()=>{const e={to:"0xdAC17F958D2ee523a2206206994597C13D831ec7",chainId:1,selector:"0x095ea7b3"};vi.spyOn(a,"getTokenInfosPayload").mockResolvedValue(i(new Error("error")));const n=await t.load(e);expect(n).toEqual([{type:o.ERROR,error:new Error("error")}])}),it("should return a correct response",async()=>{const e={to:"0xdAC17F958D2ee523a2206206994597C13D831ec7",chainId:1,selector:"0x095ea7b3"},n=await t.load(e);expect(n).toEqual([{type:o.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"}])})})});
2
2
  //# sourceMappingURL=TokenContextLoader.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/token/domain/TokenContextLoader.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 TokenDataSource } from \"@/token/data/TokenDataSource\";\nimport { TokenContextLoader } from \"@/token/domain/TokenContextLoader\";\n\ndescribe(\"TokenContextLoader\", () => {\n const mockTokenDataSource: TokenDataSource = {\n getTokenInfosPayload: vi.fn(),\n };\n const loader = new TokenContextLoader(mockTokenDataSource);\n\n beforeEach(() => {\n vi.restoreAllMocks();\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockImplementation(\n ({ address }) => Promise.resolve(Right(`payload-${address}`)),\n );\n });\n\n describe(\"load function\", () => {\n it(\"should return an empty array if transaction dest is undefined\", async () => {\n // GIVEN\n const transaction = { to: undefined } 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 when datasource returns an error\", async () => {\n // GIVEN\n const transaction = {\n to: \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n chainId: 1,\n selector: \"0x095ea7b3\",\n } as TransactionContext;\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(new Error(\"error\")),\n );\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n { type: ClearSignContextType.ERROR, error: new Error(\"error\") },\n ]);\n });\n\n it(\"should return a correct response\", async () => {\n // GIVEN\n const transaction = {\n to: \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n chainId: 1,\n selector: \"0x095ea7b3\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n },\n ]);\n });\n });\n});\n"],
5
- "mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAE5B,OAAS,wBAAAC,MAA4B,kCAGrC,OAAS,sBAAAC,MAA0B,oCAEnC,SAAS,qBAAsB,IAAM,CACnC,MAAMC,EAAuC,CAC3C,qBAAsB,GAAG,GAAG,CAC9B,EACMC,EAAS,IAAIF,EAAmBC,CAAmB,EAEzD,WAAW,IAAM,CACf,GAAG,gBAAgB,EACnB,GAAG,MAAMA,EAAqB,sBAAsB,EAAE,mBACpD,CAAC,CAAE,QAAAE,CAAQ,IAAM,QAAQ,QAAQL,EAAM,WAAWK,CAAO,EAAE,CAAC,CAC9D,CACF,CAAC,EAED,SAAS,gBAAiB,IAAM,CAC9B,GAAG,gEAAiE,SAAY,CAE9E,MAAMC,EAAc,CAAE,GAAI,MAAU,EAG9BC,EAAS,MAAMH,EAAO,KAAKE,CAAW,EAG5C,OAAOC,CAAM,EAAE,QAAQ,CAAC,CAAC,CAC3B,CAAC,EAED,GAAG,0DAA2D,SAAY,CAExE,MAAMD,EAAc,CAClB,GAAI,6CACJ,QAAS,EACT,SAAU,YACZ,EACA,GAAG,MAAMH,EAAqB,sBAAsB,EAAE,kBACpDJ,EAAK,IAAI,MAAM,OAAO,CAAC,CACzB,EAGA,MAAMQ,EAAS,MAAMH,EAAO,KAAKE,CAAW,EAG5C,OAAOC,CAAM,EAAE,QAAQ,CACrB,CAAE,KAAMN,EAAqB,MAAO,MAAO,IAAI,MAAM,OAAO,CAAE,CAChE,CAAC,CACH,CAAC,EAED,GAAG,mCAAoC,SAAY,CAEjD,MAAMK,EAAc,CAClB,GAAI,6CACJ,QAAS,EACT,SAAU,YACZ,EAGMC,EAAS,MAAMH,EAAO,KAAKE,CAAW,EAG5C,OAAOC,CAAM,EAAE,QAAQ,CACrB,CACE,KAAMN,EAAqB,MAC3B,QAAS,oDACX,CACF,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["Left", "Right", "ClearSignContextType", "TokenContextLoader", "mockTokenDataSource", "loader", "address", "transaction", "result"]
4
+ "sourcesContent": ["import { Left, Right } from \"purify-ts\";\n\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport { type TokenDataSource } from \"@/token/data/TokenDataSource\";\nimport {\n type TokenContextInput,\n TokenContextLoader,\n} from \"@/token/domain/TokenContextLoader\";\n\ndescribe(\"TokenContextLoader\", () => {\n const mockTokenDataSource: TokenDataSource = {\n getTokenInfosPayload: vi.fn(),\n };\n const loader = new TokenContextLoader(mockTokenDataSource);\n\n beforeEach(() => {\n vi.restoreAllMocks();\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockImplementation(\n ({ address }) => Promise.resolve(Right(`payload-${address}`)),\n );\n });\n\n describe(\"canHandle function\", () => {\n const validInput: TokenContextInput = {\n to: \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n selector: \"0x095ea7b3\",\n chainId: 1,\n };\n\n it(\"should return true for valid input\", () => {\n expect(loader.canHandle(validInput, [ClearSignContextType.TOKEN])).toBe(\n true,\n );\n });\n\n it(\"should return false for invalid expected type\", () => {\n expect(loader.canHandle(validInput, [ClearSignContextType.NFT])).toBe(\n false,\n );\n });\n\n it.each([\n [null, \"null input\"],\n [undefined, \"undefined input\"],\n [{}, \"empty object\"],\n [\"string\", \"string input\"],\n [123, \"number input\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, [ClearSignContextType.TOKEN])).toBe(false);\n });\n\n it.each([\n [{ ...validInput, to: undefined }, \"missing to\"],\n [{ ...validInput, selector: undefined }, \"missing selector\"],\n [{ ...validInput, chainId: undefined }, \"missing chainId\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, [ClearSignContextType.TOKEN])).toBe(false);\n });\n\n it.each([\n [{ ...validInput, to: \"invalid-hex\" }, \"invalid to hex\"],\n [{ ...validInput, to: \"0x\" }, \"empty to hex\"],\n [{ ...validInput, to: \"not-hex-at-all\" }, \"non-hex to\"],\n [{ ...validInput, selector: \"invalid-hex\" }, \"invalid selector hex\"],\n [{ ...validInput, selector: \"0x\" }, \"empty selector hex\"],\n [{ ...validInput, selector: \"not-hex-at-all\" }, \"non-hex selector\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, [ClearSignContextType.TOKEN])).toBe(false);\n });\n\n it.each([\n [{ ...validInput, chainId: \"1\" }, \"string chainId\"],\n [{ ...validInput, chainId: null }, \"null chainId\"],\n [{ ...validInput, chainId: undefined }, \"undefined chainId\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, [ClearSignContextType.TOKEN])).toBe(false);\n });\n });\n\n describe(\"load function\", () => {\n it(\"should return an error when datasource returns an error\", async () => {\n // GIVEN\n const input: TokenContextInput = {\n to: \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n chainId: 1,\n selector: \"0x095ea7b3\",\n };\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(new Error(\"error\")),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n { type: ClearSignContextType.ERROR, error: new Error(\"error\") },\n ]);\n });\n\n it(\"should return a correct response\", async () => {\n // GIVEN\n const input: TokenContextInput = {\n to: \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n chainId: 1,\n selector: \"0x095ea7b3\",\n };\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n },\n ]);\n });\n });\n});\n"],
5
+ "mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAE5B,OAAS,wBAAAC,MAA4B,kCAErC,OAEE,sBAAAC,MACK,oC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GAAG,mCAAoC,SAAY,CAEjD,MAAMM,EAA2B,CAC/B,GAAI,6CACJ,QAAS,EACT,SAAU,YACZ,EAGME,EAAS,MAAML,EAAO,KAAKG,CAAK,EAGtC,OAAOE,CAAM,EAAE,QAAQ,CACrB,CACE,KAAMR,EAAqB,MAC3B,QAAS,oDACX,CACF,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["Left", "Right", "ClearSignContextType", "TokenContextLoader", "mockTokenDataSource", "loader", "address", "validInput", "input", "_description", "result"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var d=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var m=(n,t,r,e)=>{for(var a=e>1?void 0:e?p(t,r):t,i=n.length-1,o;i>=0;i--)(o=n[i])&&(a=(e?o(t,r,a):o(a))||a);return e&&a&&d(t,r,a),a},c=(n,t)=>(r,e)=>t(r,e,n);import{inject as u,injectable as S}from"inversify";import{ClearSignContextType as l}from"../../shared/model/ClearSignContext";import{trustedNameTypes as g}from"../../trusted-name/di/trustedNameTypes";let s=class{_dataSource;constructor(t){this._dataSource=t}async load(t){const{chainId:r,domain:e,challenge:a}=t;return!e||!a?[]:this.isDomainValid(e)?[(await this._dataSource.getDomainNamePayload({chainId:r,domain:e,challenge:a})).caseOf({Left:o=>({type:l.ERROR,error:o}),Right:o=>({type:l.TRUSTED_NAME,payload:o})})]:[{type:l.ERROR,error:new Error("[ContextModule] TrustedNameLoader: invalid domain")}]}isDomainValid(t){const r=t.length>0&&Number(t.length)<30,e=new RegExp("^[a-zA-Z0-9\\-\\_\\.]+$").test(t);return r&&e}};s=m([S(),c(0,u(g.TrustedNameDataSource))],s);export{s as TrustedNameContextLoader};
1
+ var m=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var d=(o,e,a,t)=>{for(var n=t>1?void 0:t?g(e,a):e,i=o.length-1,r;i>=0;i--)(r=o[i])&&(n=(t?r(e,a,n):r(n))||n);return t&&n&&m(e,a,n),n},c=(o,e)=>(a,t)=>e(a,t,o);import{inject as u,injectable as p}from"inversify";import{ClearSignContextType as s}from"../../shared/model/ClearSignContext";import{trustedNameTypes as y}from"../../trusted-name/di/trustedNameTypes";const h=[s.TRUSTED_NAME];let l=class{_dataSource;constructor(e){this._dataSource=e}canHandle(e,a){return typeof e=="object"&&e!==null&&"chainId"in e&&"domain"in e&&"challenge"in e&&typeof e.chainId=="number"&&typeof e.domain=="string"&&e.domain.length>0&&typeof e.challenge=="string"&&e.challenge.length>0&&h.every(t=>a.includes(t))}async load(e){const{chainId:a,domain:t,challenge:n}=e;return this.isDomainValid(t)?[(await this._dataSource.getDomainNamePayload({chainId:a,domain:t,challenge:n})).caseOf({Left:r=>({type:s.ERROR,error:r}),Right:r=>({type:s.TRUSTED_NAME,payload:r})})]:[{type:s.ERROR,error:new Error("[ContextModule] TrustedNameLoader: invalid domain")}]}isDomainValid(e){const a=e.length>0&&Number(e.length)<30,t=new RegExp("^[a-zA-Z0-9\\-\\_\\.]+$").test(e);return a&&t}};l=d([p(),c(0,u(y.TrustedNameDataSource))],l);export{l as TrustedNameContextLoader};
2
2
  //# sourceMappingURL=TrustedNameContextLoader.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/trusted-name/domain/TrustedNameContextLoader.ts"],
4
- "sourcesContent": ["import { 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 { TrustedNameDataSource } from \"@/trusted-name/data/TrustedNameDataSource\";\nimport { trustedNameTypes } from \"@/trusted-name/di/trustedNameTypes\";\n\n@injectable()\nexport class TrustedNameContextLoader implements ContextLoader {\n private _dataSource: TrustedNameDataSource;\n\n constructor(\n @inject(trustedNameTypes.TrustedNameDataSource)\n dataSource: TrustedNameDataSource,\n ) {\n this._dataSource = dataSource;\n }\n\n async load(ctx: TransactionContext): Promise<ClearSignContext[]> {\n const { chainId, domain, challenge } = ctx;\n\n if (!domain || !challenge) {\n return [];\n }\n\n if (!this.isDomainValid(domain)) {\n return [\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"[ContextModule] TrustedNameLoader: invalid domain\"),\n },\n ];\n }\n\n const payload = await this._dataSource.getDomainNamePayload({\n chainId,\n domain,\n challenge,\n });\n\n return [\n payload.caseOf({\n Left: (error): ClearSignContext => ({\n type: ClearSignContextType.ERROR,\n error: error,\n }),\n Right: (value): ClearSignContext => ({\n type: ClearSignContextType.TRUSTED_NAME,\n payload: value,\n }),\n }),\n ];\n }\n\n private isDomainValid(domain: string) {\n const lengthIsValid = domain.length > 0 && Number(domain.length) < 30;\n const containsOnlyValidChars = new RegExp(\"^[a-zA-Z0-9\\\\-\\\\_\\\\.]+$\").test(\n domain,\n );\n\n return lengthIsValid && containsOnlyValidChars;\n }\n}\n"],
5
- "mappings": "iOAAA,OAAS,UAAAA,EAAQ,cAAAC,MAAkB,YAGnC,OAEE,wBAAAC,MACK,kCAGP,OAAS,oBAAAC,MAAwB,qCAG1B,IAAMC,EAAN,KAAwD,CACrD,YAER,YAEEC,EACA,CACA,KAAK,YAAcA,CACrB,CAEA,MAAM,KAAKC,EAAsD,CAC/D,KAAM,CAAE,QAAAC,EAAS,OAAAC,EAAQ,UAAAC,CAAU,EAAIH,EAEvC,MAAI,CAACE,GAAU,CAACC,EACP,CAAC,EAGL,KAAK,cAAcD,CAAM,EAevB,EANS,MAAM,KAAK,YAAY,qBAAqB,CAC1D,QAAAD,EACA,OAAAC,EACA,UAAAC,CACF,CAAC,GAGS,OAAO,CACb,KAAOC,IAA6B,CAClC,KAAMC,EAAqB,MAC3B,MAAOD,CACT,GACA,MAAQE,IAA6B,CACnC,KAAMD,EAAqB,aAC3B,QAASC,CACX,EACF,CAAC,CACH,EAzBS,CACL,CACE,KAAMD,EAAqB,MAC3B,MAAO,IAAI,MAAM,mDAAmD,CACtE,CACF,CAqBJ,CAEQ,cAAcH,EAAgB,CACpC,MAAMK,EAAgBL,EAAO,OAAS,GAAK,OAAOA,EAAO,MAAM,EAAI,GAC7DM,EAAyB,IAAI,OAAO,yBAAyB,EAAE,KACnEN,CACF,EAEA,OAAOK,GAAiBC,CAC1B,CACF,EAtDaV,EAANW,EAAA,CADNC,EAAW,EAKPC,EAAA,EAAAC,EAAOC,EAAiB,qBAAqB,IAJrCf",
6
- "names": ["inject", "injectable", "ClearSignContextType", "trustedNameTypes", "TrustedNameContextLoader", "dataSource", "ctx", "chainId", "domain", "challenge", "error", "ClearSignContextType", "value", "lengthIsValid", "containsOnlyValidChars", "__decorateClass", "injectable", "__decorateParam", "inject", "trustedNameTypes"]
4
+ "sourcesContent": ["import { inject, injectable } from \"inversify\";\n\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport type { TrustedNameDataSource } from \"@/trusted-name/data/TrustedNameDataSource\";\nimport { trustedNameTypes } from \"@/trusted-name/di/trustedNameTypes\";\n\nexport type TrustedNameContextInput = {\n chainId: number;\n domain: string;\n challenge: string;\n};\n\nconst SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.TRUSTED_NAME,\n];\n\n@injectable()\nexport class TrustedNameContextLoader\n implements ContextLoader<TrustedNameContextInput>\n{\n private _dataSource: TrustedNameDataSource;\n\n constructor(\n @inject(trustedNameTypes.TrustedNameDataSource)\n dataSource: TrustedNameDataSource,\n ) {\n this._dataSource = dataSource;\n }\n\n canHandle(\n input: unknown,\n expectedTypes: ClearSignContextType[],\n ): input is TrustedNameContextInput {\n return (\n typeof input === \"object\" &&\n input !== null &&\n \"chainId\" in input &&\n \"domain\" in input &&\n \"challenge\" in input &&\n typeof input.chainId === \"number\" &&\n typeof input.domain === \"string\" &&\n input.domain.length > 0 &&\n typeof input.challenge === \"string\" &&\n input.challenge.length > 0 &&\n SUPPORTED_TYPES.every((type) => expectedTypes.includes(type))\n );\n }\n\n async load(input: TrustedNameContextInput): Promise<ClearSignContext[]> {\n const { chainId, domain, challenge } = input;\n\n if (!this.isDomainValid(domain)) {\n return [\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"[ContextModule] TrustedNameLoader: invalid domain\"),\n },\n ];\n }\n\n const payload = await this._dataSource.getDomainNamePayload({\n chainId,\n domain,\n challenge,\n });\n\n return [\n payload.caseOf({\n Left: (error): ClearSignContext => ({\n type: ClearSignContextType.ERROR,\n error: error,\n }),\n Right: (value): ClearSignContext => ({\n type: ClearSignContextType.TRUSTED_NAME,\n payload: value,\n }),\n }),\n ];\n }\n\n private isDomainValid(domain: string) {\n const lengthIsValid = domain.length > 0 && Number(domain.length) < 30;\n const containsOnlyValidChars = new RegExp(\"^[a-zA-Z0-9\\\\-\\\\_\\\\.]+$\").test(\n domain,\n );\n\n return lengthIsValid && containsOnlyValidChars;\n }\n}\n"],
5
+ "mappings": "iOAAA,OAAS,UAAAA,EAAQ,cAAAC,MAAkB,YAGnC,OAEE,wBAAAC,MACK,kCAEP,OAAS,oBAAAC,MAAwB,qCAQjC,MAAMC,EAA0C,CAC9CC,EAAqB,YACvB,EAGO,IAAMC,EAAN,KAEP,CACU,YAER,YAEEC,EACA,CACA,KAAK,YAAcA,CACrB,CAEA,UACEC,EACAC,EACkC,CAClC,OACE,OAAOD,GAAU,UACjBA,IAAU,MACV,YAAaA,GACb,WAAYA,GACZ,cAAeA,GACf,OAAOA,EAAM,SAAY,UACzB,OAAOA,EAAM,QAAW,UACxBA,EAAM,OAAO,OAAS,GACtB,OAAOA,EAAM,WAAc,UAC3BA,EAAM,UAAU,OAAS,GACzBJ,EAAgB,MAAOM,GAASD,EAAc,SAASC,CAAI,CAAC,CAEhE,CAEA,MAAM,KAAKF,EAA6D,CACtE,KAAM,CAAE,QAAAG,EAAS,OAAAC,EAAQ,UAAAC,CAAU,EAAIL,EAEvC,OAAK,KAAK,cAAcI,CAAM,EAevB,EANS,MAAM,KAAK,YAAY,qBAAqB,CAC1D,QAAAD,EACA,OAAAC,EACA,UAAAC,CACF,CAAC,GAGS,OAAO,CACb,KAAOC,IAA6B,CAClC,KAAMT,EAAqB,MAC3B,MAAOS,CACT,GACA,MAAQC,IAA6B,CACnC,KAAMV,EAAqB,aAC3B,QAASU,CACX,EACF,CAAC,CACH,EAzBS,CACL,CACE,KAAMV,EAAqB,MAC3B,MAAO,IAAI,MAAM,mDAAmD,CACtE,CACF,CAqBJ,CAEQ,cAAcO,EAAgB,CACpC,MAAMI,EAAgBJ,EAAO,OAAS,GAAK,OAAOA,EAAO,MAAM,EAAI,GAC7DK,EAAyB,IAAI,OAAO,yBAAyB,EAAE,KACnEL,CACF,EAEA,OAAOI,GAAiBC,CAC1B,CACF,EAvEaX,EAANY,EAAA,CADNC,EAAW,EAOPC,EAAA,EAAAC,EAAOC,EAAiB,qBAAqB,IANrChB",
6
+ "names": ["inject", "injectable", "ClearSignContextType", "trustedNameTypes", "SUPPORTED_TYPES", "ClearSignContextType", "TrustedNameContextLoader", "dataSource", "input", "expectedTypes", "type", "chainId", "domain", "challenge", "error", "value", "lengthIsValid", "containsOnlyValidChars", "__decorateClass", "injectable", "__decorateParam", "inject", "trustedNameTypes"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{Left as l,Right as s}from"purify-ts";import{ClearSignContextType as r}from"../../shared/model/ClearSignContext";import{TrustedNameContextLoader as n}from"../../trusted-name/domain/TrustedNameContextLoader";describe("TrustedNameContextLoader",()=>{const o={getDomainNamePayload:vi.fn(),getTrustedNamePayload:vi.fn()};beforeEach(()=>{vi.restoreAllMocks(),vi.spyOn(o,"getDomainNamePayload").mockResolvedValue(s("payload"))}),describe("load function",()=>{it("should return an empty array when no domain or registry",async()=>{const e={},t=new n(o),a=()=>t.load(e);await expect(a()).resolves.toEqual([])}),it("should return an error when domain > max length",async()=>{const e={domain:"maxlength-maxlength-maxlength-maxlength-maxlength-maxlength",challenge:"challenge"},a=await new n(o).load(e);expect(a).toEqual([{type:r.ERROR,error:new Error("[ContextModule] TrustedNameLoader: invalid domain")}])}),it("should return an error when domain is not valid",async()=>{const e={domain:"hello\u{1F44B}",challenge:"challenge"},a=await new n(o).load(e);expect(a).toEqual([{type:r.ERROR,error:new Error("[ContextModule] TrustedNameLoader: invalid domain")}])}),it("should return a payload",async()=>{const e={domain:"hello.eth",challenge:"challenge"},a=await new n(o).load(e);expect(a).toEqual([{type:r.TRUSTED_NAME,payload:"payload"}])}),it("should return an error when unable to fetch the datasource",async()=>{const e={domain:"hello.eth",challenge:"challenge"};vi.spyOn(o,"getDomainNamePayload").mockResolvedValue(l(new Error("error")));const a=await new n(o).load(e);expect(a).toEqual([{type:r.ERROR,error:new Error("error")}])}),it("should return an empty array when no challenge",async()=>{const e={domain:"hello.eth",challenge:void 0},a=await new n(o).load(e);expect(a).toEqual([])})})});
1
+ import{Left as r,Right as d}from"purify-ts";import{ClearSignContextType as a}from"../../shared/model/ClearSignContext";import{TrustedNameContextLoader as i}from"../../trusted-name/domain/TrustedNameContextLoader";describe("TrustedNameContextLoader",()=>{const o={getDomainNamePayload:vi.fn(),getTrustedNamePayload:vi.fn()},t=new i(o);beforeEach(()=>{vi.restoreAllMocks(),vi.spyOn(o,"getDomainNamePayload").mockResolvedValue(d("payload"))}),describe("canHandle function",()=>{const e={chainId:1,domain:"hello.eth",challenge:"challenge"};it("should return true for valid input",()=>{expect(t.canHandle(e,[a.TRUSTED_NAME])).toBe(!0)}),it("should return false for invalid expected type",()=>{expect(t.canHandle(e,[a.TOKEN])).toBe(!1)}),it.each([[null,"null input"],[void 0,"undefined input"],[{},"empty object"],["string","string input"],[123,"number input"]])("should return false for %s",(n,l)=>{expect(t.canHandle(n,[a.TRUSTED_NAME])).toBe(!1)}),it.each([[{...e,chainId:void 0},"missing chainId"],[{...e,domain:void 0},"missing domain"],[{...e,challenge:void 0},"missing challenge"]])("should return false for %s",(n,l)=>{expect(t.canHandle(n,[a.TRUSTED_NAME])).toBe(!1)}),it.each([[{...e,domain:""},"empty domain"],[{...e,challenge:""},"empty challenge"],[{...e,chainId:"1"},"string chainId"],[{...e,chainId:null},"null chainId"],[{...e,domain:123},"numeric domain"],[{...e,challenge:123},"numeric challenge"]])("should return false for %s",(n,l)=>{expect(t.canHandle(n,[a.TRUSTED_NAME])).toBe(!1)})}),describe("load function",()=>{it("should return an error when domain > max length",async()=>{const e={chainId:1,domain:"maxlength-maxlength-maxlength-maxlength-maxlength-maxlength",challenge:"challenge"},n=await t.load(e);expect(n).toEqual([{type:a.ERROR,error:new Error("[ContextModule] TrustedNameLoader: invalid domain")}])}),it("should return an error when domain is not valid",async()=>{const e={chainId:1,domain:"hello\u{1F44B}",challenge:"challenge"},n=await t.load(e);expect(n).toEqual([{type:a.ERROR,error:new Error("[ContextModule] TrustedNameLoader: invalid domain")}])}),it("should return a payload",async()=>{const e={chainId:1,domain:"hello.eth",challenge:"challenge"},n=await t.load(e);expect(n).toEqual([{type:a.TRUSTED_NAME,payload:"payload"}])}),it("should return an error when unable to fetch the datasource",async()=>{const e={chainId:1,domain:"hello.eth",challenge:"challenge"};vi.spyOn(o,"getDomainNamePayload").mockResolvedValue(r(new Error("error")));const n=await t.load(e);expect(n).toEqual([{type:a.ERROR,error:new Error("error")}])})})});
2
2
  //# sourceMappingURL=TrustedNameContextLoader.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/trusted-name/domain/TrustedNameContextLoader.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 TrustedNameDataSource } from \"@/trusted-name/data/TrustedNameDataSource\";\nimport { TrustedNameContextLoader } from \"@/trusted-name/domain/TrustedNameContextLoader\";\n\ndescribe(\"TrustedNameContextLoader\", () => {\n const mockTrustedNameDataSource: TrustedNameDataSource = {\n getDomainNamePayload: vi.fn(),\n getTrustedNamePayload: vi.fn(),\n };\n\n beforeEach(() => {\n vi.restoreAllMocks();\n vi.spyOn(\n mockTrustedNameDataSource,\n \"getDomainNamePayload\",\n ).mockResolvedValue(Right(\"payload\"));\n });\n\n describe(\"load function\", () => {\n it(\"should return an empty array when no domain or registry\", async () => {\n const transaction = {} as TransactionContext;\n const loader = new TrustedNameContextLoader(mockTrustedNameDataSource);\n const promise = () => loader.load(transaction);\n\n await expect(promise()).resolves.toEqual([]);\n });\n\n it(\"should return an error when domain > max length\", async () => {\n const transaction = {\n domain: \"maxlength-maxlength-maxlength-maxlength-maxlength-maxlength\",\n challenge: \"challenge\",\n } as TransactionContext;\n\n const loader = new TrustedNameContextLoader(mockTrustedNameDataSource);\n const result = await loader.load(transaction);\n\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"[ContextModule] TrustedNameLoader: invalid domain\"),\n },\n ]);\n });\n\n it(\"should return an error when domain is not valid\", async () => {\n const transaction = {\n domain: \"hello\uD83D\uDC4B\",\n challenge: \"challenge\",\n } as TransactionContext;\n\n const loader = new TrustedNameContextLoader(mockTrustedNameDataSource);\n const result = await loader.load(transaction);\n\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"[ContextModule] TrustedNameLoader: invalid domain\"),\n },\n ]);\n });\n\n it(\"should return a payload\", async () => {\n const transaction = {\n domain: \"hello.eth\",\n challenge: \"challenge\",\n } as TransactionContext;\n\n const loader = new TrustedNameContextLoader(mockTrustedNameDataSource);\n const result = await loader.load(transaction);\n\n expect(result).toEqual([\n {\n type: ClearSignContextType.TRUSTED_NAME,\n payload: \"payload\",\n },\n ]);\n });\n\n it(\"should return an error when unable to fetch the datasource\", async () => {\n // GIVEN\n const transaction = {\n domain: \"hello.eth\",\n challenge: \"challenge\",\n } as TransactionContext;\n\n // WHEN\n vi.spyOn(\n mockTrustedNameDataSource,\n \"getDomainNamePayload\",\n ).mockResolvedValue(Left(new Error(\"error\")));\n const loader = new TrustedNameContextLoader(mockTrustedNameDataSource);\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n { type: ClearSignContextType.ERROR, error: new Error(\"error\") },\n ]);\n });\n\n it(\"should return an empty array when no challenge\", async () => {\n // GIVEN\n const transaction = {\n domain: \"hello.eth\",\n challenge: undefined,\n } as TransactionContext;\n\n // WHEN\n const loader = new TrustedNameContextLoader(mockTrustedNameDataSource);\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n });\n});\n"],
5
- "mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAE5B,OAAS,wBAAAC,MAA4B,kCAGrC,OAAS,4BAAAC,MAAgC,iDAEzC,SAAS,2BAA4B,IAAM,CACzC,MAAMC,EAAmD,CACvD,qBAAsB,GAAG,GAAG,EAC5B,sBAAuB,GAAG,GAAG,CAC/B,EAEA,WAAW,IAAM,CACf,GAAG,gBAAgB,EACnB,GAAG,MACDA,EACA,sBACF,EAAE,kBAAkBH,EAAM,SAAS,CAAC,CACtC,CAAC,EAED,SAAS,gBAAiB,IAAM,CAC9B,GAAG,0DAA2D,SAAY,CACxE,MAAMI,EAAc,CAAC,EACfC,EAAS,IAAIH,EAAyBC,CAAyB,EAC/DG,EAAU,IAAMD,EAAO,KAAKD,CAAW,EAE7C,MAAM,OAAOE,EAAQ,CAAC,EAAE,SAAS,QAAQ,CAAC,CAAC,CAC7C,CAAC,EAED,GAAG,kDAAmD,SAAY,CAChE,MAAMF,EAAc,CAClB,OAAQ,8DACR,UAAW,WACb,EAGMG,EAAS,MADA,IAAIL,EAAyBC,CAAyB,EACzC,KAAKC,CAAW,EAE5C,OAAOG,CAAM,EAAE,QAAQ,CACrB,CACE,KAAMN,EAAqB,MAC3B,MAAO,IAAI,MAAM,mDAAmD,CACtE,CACF,CAAC,CACH,CAAC,EAED,GAAG,kDAAmD,SAAY,CAChE,MAAMG,EAAc,CAClB,OAAQ,iBACR,UAAW,WACb,EAGMG,EAAS,MADA,IAAIL,EAAyBC,CAAyB,EACzC,KAAKC,CAAW,EAE5C,OAAOG,CAAM,EAAE,QAAQ,CACrB,CACE,KAAMN,EAAqB,MAC3B,MAAO,IAAI,MAAM,mDAAmD,CACtE,CACF,CAAC,CACH,CAAC,EAED,GAAG,0BAA2B,SAAY,CACxC,MAAMG,EAAc,CAClB,OAAQ,YACR,UAAW,WACb,EAGMG,EAAS,MADA,IAAIL,EAAyBC,CAAyB,EACzC,KAAKC,CAAW,EAE5C,OAAOG,CAAM,EAAE,QAAQ,CACrB,CACE,KAAMN,EAAqB,aAC3B,QAAS,SACX,CACF,CAAC,CACH,CAAC,EAED,GAAG,6DAA8D,SAAY,CAE3E,MAAMG,EAAc,CAClB,OAAQ,YACR,UAAW,WACb,EAGA,GAAG,MACDD,EACA,sBACF,EAAE,kBAAkBJ,EAAK,IAAI,MAAM,OAAO,CAAC,CAAC,EAE5C,MAAMQ,EAAS,MADA,IAAIL,EAAyBC,CAAyB,EACzC,KAAKC,CAAW,EAG5C,OAAOG,CAAM,EAAE,QAAQ,CACrB,CAAE,KAAMN,EAAqB,MAAO,MAAO,IAAI,MAAM,OAAO,CAAE,CAChE,CAAC,CACH,CAAC,EAED,GAAG,iDAAkD,SAAY,CAE/D,MAAMG,EAAc,CAClB,OAAQ,YACR,UAAW,MACb,EAIMG,EAAS,MADA,IAAIL,EAAyBC,CAAyB,EACzC,KAAKC,CAAW,EAG5C,OAAOG,CAAM,EAAE,QAAQ,CAAC,CAAC,CAC3B,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["Left", "Right", "ClearSignContextType", "TrustedNameContextLoader", "mockTrustedNameDataSource", "transaction", "loader", "promise", "result"]
4
+ "sourcesContent": ["import { Left, Right } from \"purify-ts\";\n\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport { type TrustedNameDataSource } from \"@/trusted-name/data/TrustedNameDataSource\";\nimport {\n type TrustedNameContextInput,\n TrustedNameContextLoader,\n} from \"@/trusted-name/domain/TrustedNameContextLoader\";\n\ndescribe(\"TrustedNameContextLoader\", () => {\n const mockTrustedNameDataSource: TrustedNameDataSource = {\n getDomainNamePayload: vi.fn(),\n getTrustedNamePayload: vi.fn(),\n };\n const loader = new TrustedNameContextLoader(mockTrustedNameDataSource);\n\n beforeEach(() => {\n vi.restoreAllMocks();\n vi.spyOn(\n mockTrustedNameDataSource,\n \"getDomainNamePayload\",\n ).mockResolvedValue(Right(\"payload\"));\n });\n\n describe(\"canHandle function\", () => {\n const validInput: TrustedNameContextInput = {\n chainId: 1,\n domain: \"hello.eth\",\n challenge: \"challenge\",\n };\n\n it(\"should return true for valid input\", () => {\n expect(\n loader.canHandle(validInput, [ClearSignContextType.TRUSTED_NAME]),\n ).toBe(true);\n });\n\n it(\"should return false for invalid expected type\", () => {\n expect(loader.canHandle(validInput, [ClearSignContextType.TOKEN])).toBe(\n false,\n );\n });\n\n it.each([\n [null, \"null input\"],\n [undefined, \"undefined input\"],\n [{}, \"empty object\"],\n [\"string\", \"string input\"],\n [123, \"number input\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, [ClearSignContextType.TRUSTED_NAME])).toBe(\n false,\n );\n });\n\n it.each([\n [{ ...validInput, chainId: undefined }, \"missing chainId\"],\n [{ ...validInput, domain: undefined }, \"missing domain\"],\n [{ ...validInput, challenge: undefined }, \"missing challenge\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, [ClearSignContextType.TRUSTED_NAME])).toBe(\n false,\n );\n });\n\n it.each([\n [{ ...validInput, domain: \"\" }, \"empty domain\"],\n [{ ...validInput, challenge: \"\" }, \"empty challenge\"],\n [{ ...validInput, chainId: \"1\" }, \"string chainId\"],\n [{ ...validInput, chainId: null }, \"null chainId\"],\n [{ ...validInput, domain: 123 }, \"numeric domain\"],\n [{ ...validInput, challenge: 123 }, \"numeric challenge\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, [ClearSignContextType.TRUSTED_NAME])).toBe(\n false,\n );\n });\n });\n\n describe(\"load function\", () => {\n it(\"should return an error when domain > max length\", async () => {\n const input: TrustedNameContextInput = {\n chainId: 1,\n domain: \"maxlength-maxlength-maxlength-maxlength-maxlength-maxlength\",\n challenge: \"challenge\",\n };\n\n const result = await loader.load(input);\n\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"[ContextModule] TrustedNameLoader: invalid domain\"),\n },\n ]);\n });\n\n it(\"should return an error when domain is not valid\", async () => {\n const input: TrustedNameContextInput = {\n chainId: 1,\n domain: \"hello\uD83D\uDC4B\",\n challenge: \"challenge\",\n };\n\n const result = await loader.load(input);\n\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"[ContextModule] TrustedNameLoader: invalid domain\"),\n },\n ]);\n });\n\n it(\"should return a payload\", async () => {\n const input: TrustedNameContextInput = {\n chainId: 1,\n domain: \"hello.eth\",\n challenge: \"challenge\",\n };\n\n const result = await loader.load(input);\n\n expect(result).toEqual([\n {\n type: ClearSignContextType.TRUSTED_NAME,\n payload: \"payload\",\n },\n ]);\n });\n\n it(\"should return an error when unable to fetch the datasource\", async () => {\n // GIVEN\n const input: TrustedNameContextInput = {\n chainId: 1,\n domain: \"hello.eth\",\n challenge: \"challenge\",\n };\n\n // WHEN\n vi.spyOn(\n mockTrustedNameDataSource,\n \"getDomainNamePayload\",\n ).mockResolvedValue(Left(new Error(\"error\")));\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n { type: ClearSignContextType.ERROR, error: new Error(\"error\") },\n ]);\n });\n });\n});\n"],
5
+ "mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAE5B,OAAS,wBAAAC,MAA4B,kCAErC,OAEE,4BAAAC,MACK,iDAEP,SAAS,2BAA4B,IAAM,CACzC,MAAMC,EAAmD,CACvD,qBAAsB,GAAG,GAAG,EAC5B,sBAAuB,GAAG,GAAG,CAC/B,EACMC,EAAS,IAAIF,EAAy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,OAAO,CAAC,CAAC,EAC5C,MAAMS,EAAS,MAAMJ,EAAO,KAAKE,CAAK,EAGtC,OAAOE,CAAM,EAAE,QAAQ,CACrB,CAAE,KAAMP,EAAqB,MAAO,MAAO,IAAI,MAAM,OAAO,CAAE,CAChE,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["Left", "Right", "ClearSignContextType", "TrustedNameContextLoader", "mockTrustedNameDataSource", "loader", "validInput", "input", "_description", "result"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var _=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var m=(c,e,n,i)=>{for(var o=i>1?void 0:i?h(e,n):e,r=c.length-1,s;r>=0;r--)(s=c[r])&&(o=(i?s(e,n,o):s(o))||o);return i&&o&&_(e,n,o),o},g=(c,e)=>(n,i)=>e(n,i,c);import C from"axios";import I from"crypto-js/sha224";import{inject as F,injectable as x}from"inversify";import{Left as p,Right as M}from"purify-ts";import{configTypes as D}from"../../config/di/configTypes";import{LEDGER_CLIENT_VERSION_HEADER as T,LEDGER_ORIGIN_TOKEN_HEADER as b}from"../../shared/constant/HttpHeaders";import{TypedDataCalldataParamPresence as u}from"../../shared/model/TypedDataClearSignContext";import v from"../../../package.json";let d=class{constructor(e){this.config=e}async getTypedDataFilters({chainId:e,address:n,schema:i,version:o}){let r;try{const s=await C.request({method:"GET",url:`${this.config.cal.url}/dapps`,params:{contracts:n,chain_id:e,output:"descriptors_eip712",descriptors_eip712_version:o,descriptors_eip712:"<set>",ref:"commit:fbc6fc39e2c335545c726a972b9d366a69944ed0"},headers:{[T]:`context-module/${v.version}`,[b]:this.config.originToken}}),a=I(JSON.stringify(this.sortTypes(i)).replace(" ","")).toString();n=n.toLowerCase();const f=s.data?.[0]?.descriptors_eip712?.[n]?.[a];if(!f)return p(new Error(`[ContextModule] HttpTypedDataDataSource: no typed data filters for address ${n} on chain ${e} for schema ${a}`));if(!f.schema||!Array.isArray(f.instructions))return p(new Error(`[ContextModule] HttpTypedDataDataSource: no message info for address ${n} on chain ${e} for schema ${a}`));const l=[],y={};for(const t of f.instructions)if(this.isInstructionContractInfo(t,this.config.cal.mode))r={displayName:t.display_name,signature:t.signatures[this.config.cal.mode],filtersCount:t.field_mappers_count};else if(o==="v1"&&this.isInstructionFieldV1(t,this.config.cal.mode))l.push({type:"raw",displayName:t.display_name,path:t.field_path,signature:t.signatures[this.config.cal.mode]});else if(this.isInstructionFieldV2(t,this.config.cal.mode))l.push({type:t.format,displayName:t.display_name,path:t.field_path,signature:t.signatures[this.config.cal.mode]});else if(this.isInstructionFieldV2WithCoinRef(t,this.config.cal.mode))l.push({type:t.format,displayName:t.display_name,path:t.field_path,signature:t.signatures[this.config.cal.mode],tokenIndex:t.coin_ref});else if(this.isInstructionFieldV2WithName(t,this.config.cal.mode))l.push({type:t.format,displayName:t.display_name,path:t.field_path,signature:t.signatures[this.config.cal.mode],types:t.name_types,sources:t.name_sources,typesAndSourcesPayload:this.formatTrustedNameTypesAndSources(t)});else if(this.isInstructionCalldataInfo(t,this.config.cal.mode))y[t.calldata_index]={displayName:t.display_name,calldataIndex:t.calldata_index,valueFlag:t.value_filter_flag,calleeFlag:this.convertCalldataPresenceFlag(t.callee_filter_flag),amountFlag:t.amount_filter_flag,spenderFlag:this.convertCalldataPresenceFlag(t.spender_filter_flag),chainIdFlag:t.chain_id_filter_flag,selectorFlag:t.selector_filter_flag,signature:t.signatures[this.config.cal.mode]};else if(this.isInstructionFieldV2Calldata(t,this.config.cal.mode))l.push({type:t.format,displayName:t.display_name,path:t.field_path,signature:t.signatures[this.config.cal.mode],calldataIndex:t.calldata_index});else return p(new Error(`[ContextModule] HttpTypedDataDataSource: invalid typed data field for address ${n} on chain ${e} for schema ${a}`));return r?M({messageInfo:r,filters:l,calldatasInfos:y}):p(new Error(`[ContextModule] HttpTypedDataDataSource: no message info for address ${n} on chain ${e} for schema ${a}`))}catch{return p(new Error("[ContextModule] HttpTypedDataDataSource: Failed to fetch typed data informations"))}}convertCalldataPresenceFlag(e){switch(e){case"none":return u.None;case"present":return u.Present;case"verifying_contract":return u.VerifyingContract;default:{const n=e;throw new Error(`Unhandled flag: ${n}`)}}}formatTrustedNameTypesAndSources(e){const n=e.name_types.length,i=e.name_sources.length,o=e.descriptor.slice((n+i)*2*-1,i*2*-1),r=e.descriptor.slice(i*2*-1),s=n.toString(16).padStart(2,"0"),a=i.toString(16).padStart(2,"0");return s+o+a+r}isInstructionFieldV1(e,n){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_path=="string"&&typeof e.signatures=="object"&&typeof e.signatures[n]=="string"}isInstructionFieldV2(e,n){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_path=="string"&&typeof e.signatures=="object"&&typeof e.signatures[n]=="string"&&typeof e.format=="string"&&["raw","datetime"].includes(e.format)&&e.coin_ref===void 0}isInstructionFieldV2WithCoinRef(e,n){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_path=="string"&&typeof e.signatures=="object"&&typeof e.signatures[n]=="string"&&typeof e.format=="string"&&["token","amount"].includes(e.format)&&typeof e.coin_ref=="number"}isInstructionFieldV2WithName(e,n){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_path=="string"&&typeof e.signatures=="object"&&typeof e.signatures[n]=="string"&&typeof e.format=="string"&&e.format==="trusted-name"&&e.coin_ref===void 0&&Array.isArray(e.name_types)&&Array.isArray(e.name_sources)&&e.name_types.every(i=>typeof i=="string")&&e.name_sources.every(i=>typeof i=="string")}isInstructionContractInfo(e,n){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_mappers_count=="number"&&typeof e.signatures=="object"&&typeof e.signatures[n]=="string"&&e.field_path===void 0}isInstructionCalldataInfo(e,n){return typeof e=="object"&&typeof e.type=="string"&&e.type==="calldata"&&typeof e.display_name=="string"&&typeof e.calldata_index=="number"&&typeof e.value_filter_flag=="boolean"&&typeof e.chain_id_filter_flag=="boolean"&&typeof e.selector_filter_flag=="boolean"&&typeof e.amount_filter_flag=="boolean"&&["none","present","verifying_contract"].includes(e.callee_filter_flag)&&["none","present","verifying_contract"].includes(e.spender_filter_flag)&&typeof e.signatures=="object"&&typeof e.signatures[n]=="string"}isInstructionFieldV2Calldata(e,n){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_path=="string"&&typeof e.signatures=="object"&&typeof e.signatures[n]=="string"&&typeof e.format=="string"&&["calldata-value","calldata-callee","calldata-chain-id","calldata-selector","calldata-amount","calldata-spender"].includes(e.format)&&typeof e.calldata_index=="number"}sortTypes(e){return Object.fromEntries(Object.entries(e).sort(([n],[i])=>n.localeCompare(i)).map(([n,i])=>[n,i.map(o=>({name:o.name,type:o.type}))]))}};d=m([x(),g(0,F(D.Config))],d);export{d as HttpTypedDataDataSource};
1
+ var _=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var m=(c,e,n,i)=>{for(var o=i>1?void 0:i?h(e,n):e,r=c.length-1,s;r>=0;r--)(s=c[r])&&(o=(i?s(e,n,o):s(o))||o);return i&&o&&_(e,n,o),o},g=(c,e)=>(n,i)=>e(n,i,c);import C from"axios";import I from"crypto-js/sha224";import{inject as F,injectable as x}from"inversify";import{Left as p,Right as M}from"purify-ts";import{configTypes as D}from"../../config/di/configTypes";import{LEDGER_CLIENT_VERSION_HEADER as T,LEDGER_ORIGIN_TOKEN_HEADER as b}from"../../shared/constant/HttpHeaders";import{TypedDataCalldataParamPresence as u}from"../../shared/model/TypedDataClearSignContext";import v from"../../../package.json";let d=class{constructor(e){this.config=e}async getTypedDataFilters({chainId:e,address:n,schema:i,version:o}){let r;try{const s=await C.request({method:"GET",url:`${this.config.cal.url}/dapps`,params:{contracts:n,chain_id:e,output:"descriptors_eip712",descriptors_eip712_version:o,descriptors_eip712:"<set>",ref:`branch:${this.config.cal.branch}`},headers:{[T]:`context-module/${v.version}`,[b]:this.config.originToken}}),a=I(JSON.stringify(this.sortTypes(i)).replace(" ","")).toString();n=n.toLowerCase();const f=s.data?.[0]?.descriptors_eip712?.[n]?.[a];if(!f)return p(new Error(`[ContextModule] HttpTypedDataDataSource: no typed data filters for address ${n} on chain ${e} for schema ${a}`));if(!f.schema||!Array.isArray(f.instructions))return p(new Error(`[ContextModule] HttpTypedDataDataSource: no message info for address ${n} on chain ${e} for schema ${a}`));const l=[],y={};for(const t of f.instructions)if(this.isInstructionContractInfo(t,this.config.cal.mode))r={displayName:t.display_name,signature:t.signatures[this.config.cal.mode],filtersCount:t.field_mappers_count};else if(o==="v1"&&this.isInstructionFieldV1(t,this.config.cal.mode))l.push({type:"raw",displayName:t.display_name,path:t.field_path,signature:t.signatures[this.config.cal.mode]});else if(this.isInstructionFieldV2(t,this.config.cal.mode))l.push({type:t.format,displayName:t.display_name,path:t.field_path,signature:t.signatures[this.config.cal.mode]});else if(this.isInstructionFieldV2WithCoinRef(t,this.config.cal.mode))l.push({type:t.format,displayName:t.display_name,path:t.field_path,signature:t.signatures[this.config.cal.mode],tokenIndex:t.coin_ref});else if(this.isInstructionFieldV2WithName(t,this.config.cal.mode))l.push({type:t.format,displayName:t.display_name,path:t.field_path,signature:t.signatures[this.config.cal.mode],types:t.name_types,sources:t.name_sources,typesAndSourcesPayload:this.formatTrustedNameTypesAndSources(t)});else if(this.isInstructionCalldataInfo(t,this.config.cal.mode))y[t.calldata_index]={displayName:t.display_name,calldataIndex:t.calldata_index,valueFlag:t.value_filter_flag,calleeFlag:this.convertCalldataPresenceFlag(t.callee_filter_flag),amountFlag:t.amount_filter_flag,spenderFlag:this.convertCalldataPresenceFlag(t.spender_filter_flag),chainIdFlag:t.chain_id_filter_flag,selectorFlag:t.selector_filter_flag,signature:t.signatures[this.config.cal.mode]};else if(this.isInstructionFieldV2Calldata(t,this.config.cal.mode))l.push({type:t.format,displayName:t.display_name,path:t.field_path,signature:t.signatures[this.config.cal.mode],calldataIndex:t.calldata_index});else return p(new Error(`[ContextModule] HttpTypedDataDataSource: invalid typed data field for address ${n} on chain ${e} for schema ${a}`));return r?M({messageInfo:r,filters:l,calldatasInfos:y}):p(new Error(`[ContextModule] HttpTypedDataDataSource: no message info for address ${n} on chain ${e} for schema ${a}`))}catch{return p(new Error("[ContextModule] HttpTypedDataDataSource: Failed to fetch typed data informations"))}}convertCalldataPresenceFlag(e){switch(e){case"none":return u.None;case"present":return u.Present;case"verifying_contract":return u.VerifyingContract;default:{const n=e;throw new Error(`Unhandled flag: ${n}`)}}}formatTrustedNameTypesAndSources(e){const n=e.name_types.length,i=e.name_sources.length,o=e.descriptor.slice((n+i)*2*-1,i*2*-1),r=e.descriptor.slice(i*2*-1),s=n.toString(16).padStart(2,"0"),a=i.toString(16).padStart(2,"0");return s+o+a+r}isInstructionFieldV1(e,n){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_path=="string"&&typeof e.signatures=="object"&&typeof e.signatures[n]=="string"}isInstructionFieldV2(e,n){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_path=="string"&&typeof e.signatures=="object"&&typeof e.signatures[n]=="string"&&typeof e.format=="string"&&["raw","datetime"].includes(e.format)&&e.coin_ref===void 0}isInstructionFieldV2WithCoinRef(e,n){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_path=="string"&&typeof e.signatures=="object"&&typeof e.signatures[n]=="string"&&typeof e.format=="string"&&["token","amount"].includes(e.format)&&typeof e.coin_ref=="number"}isInstructionFieldV2WithName(e,n){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_path=="string"&&typeof e.signatures=="object"&&typeof e.signatures[n]=="string"&&typeof e.format=="string"&&e.format==="trusted-name"&&e.coin_ref===void 0&&Array.isArray(e.name_types)&&Array.isArray(e.name_sources)&&e.name_types.every(i=>typeof i=="string")&&e.name_sources.every(i=>typeof i=="string")}isInstructionContractInfo(e,n){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_mappers_count=="number"&&typeof e.signatures=="object"&&typeof e.signatures[n]=="string"&&e.field_path===void 0}isInstructionCalldataInfo(e,n){return typeof e=="object"&&typeof e.type=="string"&&e.type==="calldata"&&typeof e.display_name=="string"&&typeof e.calldata_index=="number"&&typeof e.value_filter_flag=="boolean"&&typeof e.chain_id_filter_flag=="boolean"&&typeof e.selector_filter_flag=="boolean"&&typeof e.amount_filter_flag=="boolean"&&["none","present","verifying_contract"].includes(e.callee_filter_flag)&&["none","present","verifying_contract"].includes(e.spender_filter_flag)&&typeof e.signatures=="object"&&typeof e.signatures[n]=="string"}isInstructionFieldV2Calldata(e,n){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_path=="string"&&typeof e.signatures=="object"&&typeof e.signatures[n]=="string"&&typeof e.format=="string"&&["calldata-value","calldata-callee","calldata-chain-id","calldata-selector","calldata-amount","calldata-spender"].includes(e.format)&&typeof e.calldata_index=="number"}sortTypes(e){return Object.fromEntries(Object.entries(e).sort(([n],[i])=>n.localeCompare(i)).map(([n,i])=>[n,i.map(o=>({name:o.name,type:o.type}))]))}};d=m([x(),g(0,F(D.Config))],d);export{d as HttpTypedDataDataSource};
2
2
  //# sourceMappingURL=HttpTypedDataDataSource.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/typed-data/data/HttpTypedDataDataSource.ts"],
4
- "sourcesContent": ["import axios from \"axios\";\nimport SHA224 from \"crypto-js/sha224\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport type {\n ContextModuleCalMode,\n ContextModuleConfig,\n} from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport type {\n TypedDataCalldataIndex,\n TypedDataFilter,\n TypedDataFilterCalldataInfo,\n TypedDataMessageInfo,\n} from \"@/shared/model/TypedDataClearSignContext\";\nimport { TypedDataCalldataParamPresence } from \"@/shared/model/TypedDataClearSignContext\";\nimport type { TypedDataSchema } from \"@/shared/model/TypedDataContext\";\nimport PACKAGE from \"@root/package.json\";\n\nimport type {\n FiltersDto,\n InstructionCalldataInfo,\n InstructionCalldataParamPresence,\n InstructionContractInfo,\n InstructionField,\n InstructionFieldV1,\n InstructionFieldV2,\n InstructionFieldV2Calldata,\n InstructionFieldV2WithCoinRef,\n InstructionFieldV2WithName,\n} from \"./FiltersDto\";\nimport {\n GetTypedDataFiltersParams,\n GetTypedDataFiltersResult,\n TypedDataDataSource,\n} from \"./TypedDataDataSource\";\n\n@injectable()\nexport class HttpTypedDataDataSource implements TypedDataDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n ) {}\n\n public async getTypedDataFilters({\n chainId,\n address,\n schema,\n version,\n }: GetTypedDataFiltersParams): Promise<\n Either<Error, GetTypedDataFiltersResult>\n > {\n let messageInfo: TypedDataMessageInfo | undefined = undefined;\n\n try {\n const response = await axios.request<FiltersDto[]>({\n method: \"GET\",\n url: `${this.config.cal.url}/dapps`,\n params: {\n contracts: address,\n chain_id: chainId,\n output: \"descriptors_eip712\",\n descriptors_eip712_version: version,\n descriptors_eip712: \"<set>\",\n // TODO revert to branch\n ref: `commit:fbc6fc39e2c335545c726a972b9d366a69944ed0`,\n },\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n\n // Try to get the filters JSON descriptor, from address and schema hash\n const schemaHash = SHA224(\n JSON.stringify(this.sortTypes(schema)).replace(\" \", \"\"),\n ).toString();\n address = address.toLowerCase();\n const filtersJson =\n response.data?.[0]?.descriptors_eip712?.[address]?.[schemaHash];\n if (!filtersJson) {\n return Left(\n new Error(\n `[ContextModule] HttpTypedDataDataSource: no typed data filters for address ${address} on chain ${chainId} for schema ${schemaHash}`,\n ),\n );\n }\n\n // Parse the message type, if available\n if (!filtersJson.schema || !Array.isArray(filtersJson.instructions)) {\n return Left(\n new Error(\n `[ContextModule] HttpTypedDataDataSource: no message info for address ${address} on chain ${chainId} for schema ${schemaHash}`,\n ),\n );\n }\n\n // Parse all the filters\n const filters: TypedDataFilter[] = [];\n const calldatasInfos: Record<\n TypedDataCalldataIndex,\n TypedDataFilterCalldataInfo\n > = {};\n for (const field of filtersJson.instructions) {\n if (this.isInstructionContractInfo(field, this.config.cal.mode)) {\n messageInfo = {\n displayName: field.display_name,\n signature: field.signatures[this.config.cal.mode],\n filtersCount: field.field_mappers_count,\n };\n } else if (\n version === \"v1\" &&\n this.isInstructionFieldV1(field, this.config.cal.mode)\n ) {\n filters.push({\n type: \"raw\",\n displayName: field.display_name,\n path: field.field_path,\n signature: field.signatures[this.config.cal.mode],\n });\n } else if (this.isInstructionFieldV2(field, this.config.cal.mode)) {\n filters.push({\n type: field.format,\n displayName: field.display_name,\n path: field.field_path,\n signature: field.signatures[this.config.cal.mode],\n });\n } else if (\n this.isInstructionFieldV2WithCoinRef(field, this.config.cal.mode)\n ) {\n filters.push({\n type: field.format,\n displayName: field.display_name,\n path: field.field_path,\n signature: field.signatures[this.config.cal.mode],\n tokenIndex: field.coin_ref,\n });\n } else if (\n this.isInstructionFieldV2WithName(field, this.config.cal.mode)\n ) {\n filters.push({\n type: field.format,\n displayName: field.display_name,\n path: field.field_path,\n signature: field.signatures[this.config.cal.mode],\n types: field.name_types,\n sources: field.name_sources,\n typesAndSourcesPayload:\n this.formatTrustedNameTypesAndSources(field),\n });\n } else if (\n this.isInstructionCalldataInfo(field, this.config.cal.mode)\n ) {\n calldatasInfos[field.calldata_index] = {\n displayName: field.display_name,\n calldataIndex: field.calldata_index,\n valueFlag: field.value_filter_flag,\n calleeFlag: this.convertCalldataPresenceFlag(\n field.callee_filter_flag,\n ),\n amountFlag: field.amount_filter_flag,\n spenderFlag: this.convertCalldataPresenceFlag(\n field.spender_filter_flag,\n ),\n chainIdFlag: field.chain_id_filter_flag,\n selectorFlag: field.selector_filter_flag,\n signature: field.signatures[this.config.cal.mode],\n };\n } else if (\n this.isInstructionFieldV2Calldata(field, this.config.cal.mode)\n ) {\n filters.push({\n type: field.format,\n displayName: field.display_name,\n path: field.field_path,\n signature: field.signatures[this.config.cal.mode],\n calldataIndex: field.calldata_index,\n });\n } else {\n return Left(\n new Error(\n `[ContextModule] HttpTypedDataDataSource: invalid typed data field for address ${address} on chain ${chainId} for schema ${schemaHash}`,\n ),\n );\n }\n }\n\n if (!messageInfo) {\n return Left(\n new Error(\n `[ContextModule] HttpTypedDataDataSource: no message info for address ${address} on chain ${chainId} for schema ${schemaHash}`,\n ),\n );\n }\n\n return Right({ messageInfo, filters, calldatasInfos });\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] HttpTypedDataDataSource: Failed to fetch typed data informations\",\n ),\n );\n }\n }\n\n private convertCalldataPresenceFlag(\n flag: InstructionCalldataParamPresence,\n ): TypedDataCalldataParamPresence {\n switch (flag) {\n case \"none\":\n return TypedDataCalldataParamPresence.None;\n case \"present\":\n return TypedDataCalldataParamPresence.Present;\n case \"verifying_contract\":\n return TypedDataCalldataParamPresence.VerifyingContract;\n default: {\n const uncoveredFlag: never = flag;\n throw new Error(`Unhandled flag: ${uncoveredFlag}`);\n }\n }\n }\n\n private formatTrustedNameTypesAndSources(\n field: InstructionFieldV2WithName,\n ): string {\n // Get number of types and sources\n const typesCount = field.name_types.length;\n const sourcesCount = field.name_sources.length;\n\n // Extract types and sources from the descriptor\n const types = field.descriptor.slice(\n (typesCount + sourcesCount) * 2 * -1,\n sourcesCount * 2 * -1,\n );\n const sources = field.descriptor.slice(sourcesCount * 2 * -1);\n\n // Convert counts into hex strings\n const typesCountHex = typesCount.toString(16).padStart(2, \"0\");\n const sourcesCountHex = sourcesCount.toString(16).padStart(2, \"0\");\n\n // Return the payload\n return typesCountHex + types + sourcesCountHex + sources;\n }\n\n private isInstructionFieldV1(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionFieldV1 & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n // NOTE: Currently the backend return the same structure for V1 and V2,\n // so we can't distinguish them here, but we can still check the required fields\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_path === \"string\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\"\n );\n }\n\n private isInstructionFieldV2(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionFieldV2 & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_path === \"string\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\" &&\n typeof data.format === \"string\" &&\n [\"raw\", \"datetime\"].includes(data.format) &&\n data.coin_ref === undefined\n );\n }\n\n private isInstructionFieldV2WithCoinRef(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionFieldV2WithCoinRef & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_path === \"string\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\" &&\n typeof data.format === \"string\" &&\n [\"token\", \"amount\"].includes(data.format) &&\n typeof data.coin_ref === \"number\"\n );\n }\n\n private isInstructionFieldV2WithName(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionFieldV2WithName & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_path === \"string\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\" &&\n typeof data.format === \"string\" &&\n data.format === \"trusted-name\" &&\n data.coin_ref === undefined &&\n Array.isArray(data.name_types) &&\n Array.isArray(data.name_sources) &&\n data.name_types.every((t) => typeof t === \"string\") &&\n data.name_sources.every((s) => typeof s === \"string\")\n );\n }\n\n private isInstructionContractInfo(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionContractInfo & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_mappers_count === \"number\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\" &&\n data.field_path === undefined\n );\n }\n\n private isInstructionCalldataInfo(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionCalldataInfo & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.type === \"string\" &&\n data.type === \"calldata\" &&\n typeof data.display_name === \"string\" &&\n typeof data.calldata_index === \"number\" &&\n typeof data.value_filter_flag === \"boolean\" &&\n typeof data.chain_id_filter_flag === \"boolean\" &&\n typeof data.selector_filter_flag === \"boolean\" &&\n typeof data.amount_filter_flag === \"boolean\" &&\n [\"none\", \"present\", \"verifying_contract\"].includes(\n data.callee_filter_flag,\n ) &&\n [\"none\", \"present\", \"verifying_contract\"].includes(\n data.spender_filter_flag,\n ) &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\"\n );\n }\n\n private isInstructionFieldV2Calldata(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionFieldV2Calldata & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_path === \"string\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\" &&\n typeof data.format === \"string\" &&\n [\n \"calldata-value\",\n \"calldata-callee\",\n \"calldata-chain-id\",\n \"calldata-selector\",\n \"calldata-amount\",\n \"calldata-spender\",\n ].includes(data.format) &&\n typeof data.calldata_index === \"number\"\n );\n }\n\n private sortTypes(types: TypedDataSchema): TypedDataSchema {\n return Object.fromEntries(\n Object.entries(types)\n .sort(([aKey], [bKey]) => aKey.localeCompare(bKey))\n .map(([key, value]) => [\n key,\n value.map((v) => ({ name: v.name, type: v.type })),\n ]),\n );\n }\n}\n"],
5
- "mappings": "iOAAA,O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C",
4
+ "sourcesContent": ["import axios from \"axios\";\nimport SHA224 from \"crypto-js/sha224\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport type {\n ContextModuleCalMode,\n ContextModuleConfig,\n} from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport type {\n TypedDataCalldataIndex,\n TypedDataFilter,\n TypedDataFilterCalldataInfo,\n TypedDataMessageInfo,\n} from \"@/shared/model/TypedDataClearSignContext\";\nimport { TypedDataCalldataParamPresence } from \"@/shared/model/TypedDataClearSignContext\";\nimport type { TypedDataSchema } from \"@/shared/model/TypedDataContext\";\nimport PACKAGE from \"@root/package.json\";\n\nimport type {\n FiltersDto,\n InstructionCalldataInfo,\n InstructionCalldataParamPresence,\n InstructionContractInfo,\n InstructionField,\n InstructionFieldV1,\n InstructionFieldV2,\n InstructionFieldV2Calldata,\n InstructionFieldV2WithCoinRef,\n InstructionFieldV2WithName,\n} from \"./FiltersDto\";\nimport {\n GetTypedDataFiltersParams,\n GetTypedDataFiltersResult,\n TypedDataDataSource,\n} from \"./TypedDataDataSource\";\n\n@injectable()\nexport class HttpTypedDataDataSource implements TypedDataDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n ) {}\n\n public async getTypedDataFilters({\n chainId,\n address,\n schema,\n version,\n }: GetTypedDataFiltersParams): Promise<\n Either<Error, GetTypedDataFiltersResult>\n > {\n let messageInfo: TypedDataMessageInfo | undefined = undefined;\n\n try {\n const response = await axios.request<FiltersDto[]>({\n method: \"GET\",\n url: `${this.config.cal.url}/dapps`,\n params: {\n contracts: address,\n chain_id: chainId,\n output: \"descriptors_eip712\",\n descriptors_eip712_version: version,\n descriptors_eip712: \"<set>\",\n ref: `branch:${this.config.cal.branch}`,\n },\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n\n // Try to get the filters JSON descriptor, from address and schema hash\n const schemaHash = SHA224(\n JSON.stringify(this.sortTypes(schema)).replace(\" \", \"\"),\n ).toString();\n address = address.toLowerCase();\n const filtersJson =\n response.data?.[0]?.descriptors_eip712?.[address]?.[schemaHash];\n if (!filtersJson) {\n return Left(\n new Error(\n `[ContextModule] HttpTypedDataDataSource: no typed data filters for address ${address} on chain ${chainId} for schema ${schemaHash}`,\n ),\n );\n }\n\n // Parse the message type, if available\n if (!filtersJson.schema || !Array.isArray(filtersJson.instructions)) {\n return Left(\n new Error(\n `[ContextModule] HttpTypedDataDataSource: no message info for address ${address} on chain ${chainId} for schema ${schemaHash}`,\n ),\n );\n }\n\n // Parse all the filters\n const filters: TypedDataFilter[] = [];\n const calldatasInfos: Record<\n TypedDataCalldataIndex,\n TypedDataFilterCalldataInfo\n > = {};\n for (const field of filtersJson.instructions) {\n if (this.isInstructionContractInfo(field, this.config.cal.mode)) {\n messageInfo = {\n displayName: field.display_name,\n signature: field.signatures[this.config.cal.mode],\n filtersCount: field.field_mappers_count,\n };\n } else if (\n version === \"v1\" &&\n this.isInstructionFieldV1(field, this.config.cal.mode)\n ) {\n filters.push({\n type: \"raw\",\n displayName: field.display_name,\n path: field.field_path,\n signature: field.signatures[this.config.cal.mode],\n });\n } else if (this.isInstructionFieldV2(field, this.config.cal.mode)) {\n filters.push({\n type: field.format,\n displayName: field.display_name,\n path: field.field_path,\n signature: field.signatures[this.config.cal.mode],\n });\n } else if (\n this.isInstructionFieldV2WithCoinRef(field, this.config.cal.mode)\n ) {\n filters.push({\n type: field.format,\n displayName: field.display_name,\n path: field.field_path,\n signature: field.signatures[this.config.cal.mode],\n tokenIndex: field.coin_ref,\n });\n } else if (\n this.isInstructionFieldV2WithName(field, this.config.cal.mode)\n ) {\n filters.push({\n type: field.format,\n displayName: field.display_name,\n path: field.field_path,\n signature: field.signatures[this.config.cal.mode],\n types: field.name_types,\n sources: field.name_sources,\n typesAndSourcesPayload:\n this.formatTrustedNameTypesAndSources(field),\n });\n } else if (\n this.isInstructionCalldataInfo(field, this.config.cal.mode)\n ) {\n calldatasInfos[field.calldata_index] = {\n displayName: field.display_name,\n calldataIndex: field.calldata_index,\n valueFlag: field.value_filter_flag,\n calleeFlag: this.convertCalldataPresenceFlag(\n field.callee_filter_flag,\n ),\n amountFlag: field.amount_filter_flag,\n spenderFlag: this.convertCalldataPresenceFlag(\n field.spender_filter_flag,\n ),\n chainIdFlag: field.chain_id_filter_flag,\n selectorFlag: field.selector_filter_flag,\n signature: field.signatures[this.config.cal.mode],\n };\n } else if (\n this.isInstructionFieldV2Calldata(field, this.config.cal.mode)\n ) {\n filters.push({\n type: field.format,\n displayName: field.display_name,\n path: field.field_path,\n signature: field.signatures[this.config.cal.mode],\n calldataIndex: field.calldata_index,\n });\n } else {\n return Left(\n new Error(\n `[ContextModule] HttpTypedDataDataSource: invalid typed data field for address ${address} on chain ${chainId} for schema ${schemaHash}`,\n ),\n );\n }\n }\n\n if (!messageInfo) {\n return Left(\n new Error(\n `[ContextModule] HttpTypedDataDataSource: no message info for address ${address} on chain ${chainId} for schema ${schemaHash}`,\n ),\n );\n }\n\n return Right({ messageInfo, filters, calldatasInfos });\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] HttpTypedDataDataSource: Failed to fetch typed data informations\",\n ),\n );\n }\n }\n\n private convertCalldataPresenceFlag(\n flag: InstructionCalldataParamPresence,\n ): TypedDataCalldataParamPresence {\n switch (flag) {\n case \"none\":\n return TypedDataCalldataParamPresence.None;\n case \"present\":\n return TypedDataCalldataParamPresence.Present;\n case \"verifying_contract\":\n return TypedDataCalldataParamPresence.VerifyingContract;\n default: {\n const uncoveredFlag: never = flag;\n throw new Error(`Unhandled flag: ${uncoveredFlag}`);\n }\n }\n }\n\n private formatTrustedNameTypesAndSources(\n field: InstructionFieldV2WithName,\n ): string {\n // Get number of types and sources\n const typesCount = field.name_types.length;\n const sourcesCount = field.name_sources.length;\n\n // Extract types and sources from the descriptor\n const types = field.descriptor.slice(\n (typesCount + sourcesCount) * 2 * -1,\n sourcesCount * 2 * -1,\n );\n const sources = field.descriptor.slice(sourcesCount * 2 * -1);\n\n // Convert counts into hex strings\n const typesCountHex = typesCount.toString(16).padStart(2, \"0\");\n const sourcesCountHex = sourcesCount.toString(16).padStart(2, \"0\");\n\n // Return the payload\n return typesCountHex + types + sourcesCountHex + sources;\n }\n\n private isInstructionFieldV1(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionFieldV1 & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n // NOTE: Currently the backend return the same structure for V1 and V2,\n // so we can't distinguish them here, but we can still check the required fields\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_path === \"string\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\"\n );\n }\n\n private isInstructionFieldV2(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionFieldV2 & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_path === \"string\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\" &&\n typeof data.format === \"string\" &&\n [\"raw\", \"datetime\"].includes(data.format) &&\n data.coin_ref === undefined\n );\n }\n\n private isInstructionFieldV2WithCoinRef(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionFieldV2WithCoinRef & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_path === \"string\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\" &&\n typeof data.format === \"string\" &&\n [\"token\", \"amount\"].includes(data.format) &&\n typeof data.coin_ref === \"number\"\n );\n }\n\n private isInstructionFieldV2WithName(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionFieldV2WithName & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_path === \"string\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\" &&\n typeof data.format === \"string\" &&\n data.format === \"trusted-name\" &&\n data.coin_ref === undefined &&\n Array.isArray(data.name_types) &&\n Array.isArray(data.name_sources) &&\n data.name_types.every((t) => typeof t === \"string\") &&\n data.name_sources.every((s) => typeof s === \"string\")\n );\n }\n\n private isInstructionContractInfo(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionContractInfo & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_mappers_count === \"number\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\" &&\n data.field_path === undefined\n );\n }\n\n private isInstructionCalldataInfo(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionCalldataInfo & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.type === \"string\" &&\n data.type === \"calldata\" &&\n typeof data.display_name === \"string\" &&\n typeof data.calldata_index === \"number\" &&\n typeof data.value_filter_flag === \"boolean\" &&\n typeof data.chain_id_filter_flag === \"boolean\" &&\n typeof data.selector_filter_flag === \"boolean\" &&\n typeof data.amount_filter_flag === \"boolean\" &&\n [\"none\", \"present\", \"verifying_contract\"].includes(\n data.callee_filter_flag,\n ) &&\n [\"none\", \"present\", \"verifying_contract\"].includes(\n data.spender_filter_flag,\n ) &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\"\n );\n }\n\n private isInstructionFieldV2Calldata(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionFieldV2Calldata & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_path === \"string\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\" &&\n typeof data.format === \"string\" &&\n [\n \"calldata-value\",\n \"calldata-callee\",\n \"calldata-chain-id\",\n \"calldata-selector\",\n \"calldata-amount\",\n \"calldata-spender\",\n ].includes(data.format) &&\n typeof data.calldata_index === \"number\"\n );\n }\n\n private sortTypes(types: TypedDataSchema): TypedDataSchema {\n return Object.fromEntries(\n Object.entries(types)\n .sort(([aKey], [bKey]) => aKey.localeCompare(bKey))\n .map(([key, value]) => [\n key,\n value.map((v) => ({ name: v.name, type: v.type })),\n ]),\n );\n }\n}\n"],
5
+ "mappings": "iOAAA,OAAOA,MAAW,QAClB,OAAOC,MAAY,mBACnB,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YACnC,OAAiB,QAAAC,EAAM,SAAAC,MAAa,YAEpC,OAAS,eAAAC,MAAmB,0BAK5B,OACE,gCAAAC,EACA,8BAAAC,MACK,gCAOP,OAAS,kCAAAC,MAAsC,2CAE/C,OAAOC,MAAa,qBAqBb,IAAMC,EAAN,KAA6D,CAClE,YAC+CC,EAC7C,CAD6C,YAAAA,CAC5C,CAEH,MAAa,oBAAoB,CAC/B,QAAAC,EACA,QAAAC,EACA,OAAAC,EACA,QAAAC,CACF,EAEE,CACA,IAAIC,EAEJ,GAAI,CACF,MAAMC,EAAW,MAAMC,EAAM,QAAsB,CACjD,OAAQ,MACR,IAAK,GAAG,KAAK,OAAO,IAAI,GAAG,SAC3B,OAAQ,CACN,UAAWL,EACX,SAAUD,EACV,OAAQ,qBACR,2BAA4BG,EAC5B,mBAAoB,QACpB,IAAK,UAAU,KAAK,OAAO,IAAI,MAAM,EACvC,EACA,QAAS,CACP,CAACI,CAA4B,EAAG,kBAAkBC,EAAQ,OAAO,GACjE,CAACC,CAA0B,EAAG,KAAK,OAAO,WAC5C,CACF,CAAC,EAGKC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C,OAAOD,EAAK,QAAW,UACvB,CACE,iBACA,kBACA,oBACA,oBACA,kBACA,kBACF,EAAE,SAASA,EAAK,MAAM,GACtB,OAAOA,EAAK,gBAAmB,QAEnC,CAEQ,UAAUJ,EAAyC,CACzD,OAAO,OAAO,YACZ,OAAO,QAAQA,CAAK,EACjB,KAAK,CAAC,CAACQ,CAAI,EAAG,CAACC,CAAI,IAAMD,EAAK,cAAcC,CAAI,CAAC,EACjD,IAAI,CAAC,CAACC,EAAKC,CAAK,IAAM,CACrBD,EACAC,EAAM,IAAKC,IAAO,CAAE,KAAMA,EAAE,KAAM,KAAMA,EAAE,IAAK,EAAE,CACnD,CAAC,CACL,CACF,CACF,EArWarC,EAANsC,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAY,MAAM,IAFjB1C",
6
6
  "names": ["axios", "SHA224", "inject", "injectable", "Left", "Right", "configTypes", "LEDGER_CLIENT_VERSION_HEADER", "LEDGER_ORIGIN_TOKEN_HEADER", "TypedDataCalldataParamPresence", "PACKAGE", "HttpTypedDataDataSource", "config", "chainId", "address", "schema", "version", "messageInfo", "response", "axios", "LEDGER_CLIENT_VERSION_HEADER", "PACKAGE", "LEDGER_ORIGIN_TOKEN_HEADER", "schemaHash", "SHA224", "filtersJson", "Left", "filters", "calldatasInfos", "field", "Right", "flag", "TypedDataCalldataParamPresence", "uncoveredFlag", "typesCount", "sourcesCount", "types", "sources", "typesCountHex", "sourcesCountHex", "data", "mode", "t", "s", "aKey", "bKey", "key", "value", "v", "__decorateClass", "injectable", "__decorateParam", "inject", "configTypes"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var S=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var m=(c,e,r,t)=>{for(var a=t>1?void 0:t?D(e,r):e,n=c.length-1,o;n>=0;n--)(o=c[n])&&(a=(t?o(e,r,a):o(a))||a);return t&&a&&S(e,r,a),a},p=(c,e)=>(r,t)=>e(r,t,c);import{bufferToHexaString as h}from"@ledgerhq/device-management-kit";import{inject as y,injectable as I}from"inversify";import{pkiTypes as k}from"../../pki/di/pkiTypes";import{KeyId as P}from"../../pki/model/KeyId";import{KeyUsage as F}from"../../pki/model/KeyUsage";import{proxyTypes as A}from"../../proxy/di/proxyTypes";import{ClearSignContextType as R}from"../../shared/model/ClearSignContext";import{TypedDataCalldataParamPresence as H,VERIFYING_CONTRACT_TOKEN_INDEX as N}from"../../shared/model/TypedDataClearSignContext";import{tokenTypes as _}from"../../token/di/tokenTypes";import{typedDataTypes as w}from"../../typed-data/di/typedDataTypes";let u=class{constructor(e,r,t,a){this.dataSource=e;this.tokenDataSource=r;this.proxyDataSource=t;this._certificateLoader=a}async load(e){let r,t=await this.dataSource.getTypedDataFilters({address:e.verifyingContract,chainId:e.chainId,version:e.version,schema:e.schema});if(t.isLeft()){const{resolvedAddress:i,context:s}=await this.resolveProxy(e);if(s!==void 0&&(r=s,t=await this.dataSource.getTypedDataFilters({address:i,chainId:e.chainId,version:e.version,schema:e.schema})),t.isLeft())return{type:"error",error:t.extract()}}const{messageInfo:a,filters:n,calldatasInfos:o}=t.unsafeCoerce(),d=n.reduce((i,s)=>(i[s.path]=s,i),{});return{type:"success",messageInfo:a,filters:d,trustedNamesAddresses:this.extractTrustedNames(n,e),tokens:await this.extractTokens(n,e),calldatas:this.extractCalldatas(n,o,e),proxy:r}}async resolveProxy(e){const r=await this.proxyDataSource.getProxyImplementationAddress({calldata:"0x",proxyAddress:e.verifyingContract,chainId:e.chainId,challenge:e.challenge??""});if(r.isLeft())return{resolvedAddress:e.verifyingContract,context:void 0};const t=await this._certificateLoader.loadCertificate({keyId:P.CalCalldataKey,keyUsage:F.Calldata,targetDevice:e.deviceModelId}),a=r.unsafeCoerce();return{resolvedAddress:a.implementationAddress,context:{type:R.PROXY_INFO,payload:a.signedDescriptor,certificate:t}}}extractTrustedNames(e,r){return e.filter(t=>t.type==="trusted-name").reduce((t,a)=>{const n=r.fieldsValues.filter(o=>o.path===a.path);if(n.length!==0){const o=n[0],d=this.convertAddressToHexaString(o.value);t[a.path]=d}return t},{})}async extractTokens(e,r){const t={};for(const a of e){if(a.type!=="token"&&a.type!=="amount")continue;const n=a.tokenIndex;if(t[n]===void 0){if(a.type==="token"){const o=r.fieldsValues.filter(s=>s.path===a.path);if(o.length===0)continue;const d=o[0],i=this.convertAddressToHexaString(d.value);if(o.every(s=>this.convertAddressToHexaString(s.value)===i)){const s=r.chainId;(await this.tokenDataSource.getTokenInfosPayload({address:i,chainId:s})).ifRight(f=>{t[n]=f})}}else if(a.type==="amount"&&n===N){const o=r.verifyingContract,d=r.chainId;(await this.tokenDataSource.getTokenInfosPayload({address:o,chainId:d})).ifRight(s=>{t[n]=s})}}}return t}extractCalldatas(e,r,t){const a=e.reduce((o,d)=>{if(d.type==="calldata-value"||d.type==="calldata-callee"||d.type==="calldata-chain-id"||d.type==="calldata-selector"||d.type==="calldata-amount"||d.type==="calldata-spender"){const i=o[d.calldataIndex];i===void 0?o[d.calldataIndex]=[d]:i.push(d)}return o},{}),n={};for(const o in r){const d=r[o],i=a[o];if(!i)continue;const s=this.extractHexaString(i.find(l=>l.type==="calldata-value"),t,"0x"),T=this.extractHexaString(i.find(l=>l.type==="calldata-selector"),t,s.slice(0,10)),f=this.extractAddress(i.find(l=>l.type==="calldata-callee"),t,d.calleeFlag),g=this.extractAddress(i.find(l=>l.type==="calldata-spender"),t,d.spenderFlag),C=this.extractBigint(i.find(l=>l.type==="calldata-amount"),t,void 0),x=this.extractBigint(i.find(l=>l.type==="calldata-chain-id"),t,void 0),v=x!==void 0&&x<Number.MAX_SAFE_INTEGER?Number(x):t.chainId;n[o]={filter:d,subset:{chainId:v,data:s,selector:T,to:f,value:C,from:g}}}return n}extractHexaString(e,r,t){if(e!==void 0){const a=r.fieldsValues.filter(n=>n.path===e.path);if(a.length!==0)return h(a[0].value)}return t}extractAddress(e,r,t,a){if(t===H.VerifyingContract)return r.verifyingContract;if(e!==void 0){const n=r.fieldsValues.filter(o=>o.path===e.path);if(n.length!==0)return this.convertAddressToHexaString(n[0].value)}return a}extractBigint(e,r,t){if(e!==void 0){const a=r.fieldsValues.filter(n=>n.path===e.path);if(a.length!==0)return BigInt(h(a[0].value))}return t}convertAddressToHexaString(e){return`0x${Array.from(e,r=>r.toString(16).padStart(2,"0")).join("").padStart(40,"0")}`}};u=m([I(),p(0,y(w.TypedDataDataSource)),p(1,y(_.TokenDataSource)),p(2,y(A.ProxyDataSource)),p(3,y(k.PkiCertificateLoader))],u);export{u as DefaultTypedDataContextLoader};
1
+ var S=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var h=(l,e,r,t)=>{for(var a=t>1?void 0:t?D(e,r):e,n=l.length-1,o;n>=0;n--)(o=l[n])&&(a=(t?o(e,r,a):o(a))||a);return t&&a&&S(e,r,a),a},p=(l,e)=>(r,t)=>e(r,t,l);import{bufferToHexaString as m}from"@ledgerhq/device-management-kit";import{inject as y,injectable as I}from"inversify";import{pkiTypes as k}from"../../pki/di/pkiTypes";import{proxyTypes as P}from"../../proxy/di/proxyTypes";import{ClearSignContextType as F}from"../../shared/model/ClearSignContext";import{TypedDataCalldataParamPresence as A,VERIFYING_CONTRACT_TOKEN_INDEX as R}from"../../shared/model/TypedDataClearSignContext";import{tokenTypes as H}from"../../token/di/tokenTypes";import{typedDataTypes as N}from"../../typed-data/di/typedDataTypes";let u=class{constructor(e,r,t,a){this.dataSource=e;this.tokenDataSource=r;this.proxyDataSource=t;this._certificateLoader=a}async load(e){let r,t=await this.dataSource.getTypedDataFilters({address:e.verifyingContract,chainId:e.chainId,version:e.version,schema:e.schema});if(t.isLeft()){const{resolvedAddress:i,context:s}=await this.resolveProxy(e);if(s!==void 0&&(r=s,t=await this.dataSource.getTypedDataFilters({address:i,chainId:e.chainId,version:e.version,schema:e.schema})),t.isLeft())return{type:"error",error:t.extract()}}const{messageInfo:a,filters:n,calldatasInfos:o}=t.unsafeCoerce(),d=n.reduce((i,s)=>(i[s.path]=s,i),{});return{type:"success",messageInfo:a,filters:d,trustedNamesAddresses:this.extractTrustedNames(n,e),tokens:await this.extractTokens(n,e),calldatas:this.extractCalldatas(n,o,e),proxy:r}}async resolveProxy(e){const r=await this.proxyDataSource.getProxyImplementationAddress({calldata:"0x",proxyAddress:e.verifyingContract,chainId:e.chainId,challenge:e.challenge??""});if(r.isLeft())return{resolvedAddress:e.verifyingContract,context:void 0};const t=r.unsafeCoerce(),a=await this._certificateLoader.loadCertificate({keyId:t.keyId,keyUsage:t.keyUsage,targetDevice:e.deviceModelId});return{resolvedAddress:t.implementationAddress,context:{type:F.PROXY_INFO,payload:t.signedDescriptor,certificate:a}}}extractTrustedNames(e,r){return e.filter(t=>t.type==="trusted-name").reduce((t,a)=>{const n=r.fieldsValues.filter(o=>o.path===a.path);if(n.length!==0){const o=n[0],d=this.convertAddressToHexaString(o.value);t[a.path]=d}return t},{})}async extractTokens(e,r){const t={};for(const a of e){if(a.type!=="token"&&a.type!=="amount")continue;const n=a.tokenIndex;if(t[n]===void 0){if(a.type==="token"){const o=r.fieldsValues.filter(s=>s.path===a.path);if(o.length===0)continue;const d=o[0],i=this.convertAddressToHexaString(d.value);if(o.every(s=>this.convertAddressToHexaString(s.value)===i)){const s=r.chainId;(await this.tokenDataSource.getTokenInfosPayload({address:i,chainId:s})).ifRight(f=>{t[n]=f})}}else if(a.type==="amount"&&n===R){const o=r.verifyingContract,d=r.chainId;(await this.tokenDataSource.getTokenInfosPayload({address:o,chainId:d})).ifRight(s=>{t[n]=s})}}}return t}extractCalldatas(e,r,t){const a=e.reduce((o,d)=>{if(d.type==="calldata-value"||d.type==="calldata-callee"||d.type==="calldata-chain-id"||d.type==="calldata-selector"||d.type==="calldata-amount"||d.type==="calldata-spender"){const i=o[d.calldataIndex];i===void 0?o[d.calldataIndex]=[d]:i.push(d)}return o},{}),n={};for(const o in r){const d=r[o],i=a[o];if(!i)continue;const s=this.extractHexaString(i.find(c=>c.type==="calldata-value"),t,"0x"),T=this.extractHexaString(i.find(c=>c.type==="calldata-selector"),t,s.slice(0,10)),f=this.extractAddress(i.find(c=>c.type==="calldata-callee"),t,d.calleeFlag),g=this.extractAddress(i.find(c=>c.type==="calldata-spender"),t,d.spenderFlag),C=this.extractBigint(i.find(c=>c.type==="calldata-amount"),t,void 0),x=this.extractBigint(i.find(c=>c.type==="calldata-chain-id"),t,void 0),v=x!==void 0&&x<Number.MAX_SAFE_INTEGER?Number(x):t.chainId;n[o]={filter:d,subset:{chainId:v,data:s,selector:T,to:f,value:C,from:g}}}return n}extractHexaString(e,r,t){if(e!==void 0){const a=r.fieldsValues.filter(n=>n.path===e.path);if(a.length!==0)return m(a[0].value)}return t}extractAddress(e,r,t,a){if(t===A.VerifyingContract)return r.verifyingContract;if(e!==void 0){const n=r.fieldsValues.filter(o=>o.path===e.path);if(n.length!==0)return this.convertAddressToHexaString(n[0].value)}return a}extractBigint(e,r,t){if(e!==void 0){const a=r.fieldsValues.filter(n=>n.path===e.path);if(a.length!==0)return BigInt(m(a[0].value))}return t}convertAddressToHexaString(e){return`0x${Array.from(e,r=>r.toString(16).padStart(2,"0")).join("").padStart(40,"0")}`}};u=h([I(),p(0,y(N.TypedDataDataSource)),p(1,y(H.TokenDataSource)),p(2,y(P.ProxyDataSource)),p(3,y(k.PkiCertificateLoader))],u);export{u as DefaultTypedDataContextLoader};
2
2
  //# sourceMappingURL=DefaultTypedDataContextLoader.js.map