@ledgerhq/context-module 1.11.1 → 1.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (200) hide show
  1. package/lib/cjs/package.json +1 -1
  2. package/lib/cjs/src/ContextModuleBuilder.js +1 -1
  3. package/lib/cjs/src/ContextModuleBuilder.js.map +3 -3
  4. package/lib/cjs/src/ContextModuleBuilder.test.js +1 -1
  5. package/lib/cjs/src/ContextModuleBuilder.test.js.map +3 -3
  6. package/lib/cjs/src/DefaultContextModule.test.js +1 -1
  7. package/lib/cjs/src/DefaultContextModule.test.js.map +3 -3
  8. package/lib/cjs/src/calldata/domain/CalldataContextLoader.js +1 -1
  9. package/lib/cjs/src/calldata/domain/CalldataContextLoader.js.map +3 -3
  10. package/lib/cjs/src/calldata/domain/CalldataContextLoader.test.js +1 -1
  11. package/lib/cjs/src/calldata/domain/CalldataContextLoader.test.js.map +3 -3
  12. package/lib/cjs/src/config/di/configTypes.js +1 -1
  13. package/lib/cjs/src/config/di/configTypes.js.map +2 -2
  14. package/lib/cjs/src/config/model/ContextModuleBuildArgs.js +1 -1
  15. package/lib/cjs/src/config/model/ContextModuleBuildArgs.js.map +1 -1
  16. package/lib/cjs/src/config/model/ContextModuleConfig.js +1 -1
  17. package/lib/cjs/src/config/model/ContextModuleConfig.js.map +1 -1
  18. package/lib/cjs/src/di.js +1 -1
  19. package/lib/cjs/src/di.js.map +3 -3
  20. package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.js +1 -1
  21. package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.js.map +3 -3
  22. package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js +1 -1
  23. package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js.map +3 -3
  24. package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.js +1 -1
  25. package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.js.map +3 -3
  26. package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.test.js +1 -1
  27. package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.test.js.map +3 -3
  28. package/lib/cjs/src/nft/domain/NftContextLoader.js +1 -1
  29. package/lib/cjs/src/nft/domain/NftContextLoader.js.map +3 -3
  30. package/lib/cjs/src/nft/domain/NftContextLoader.test.js +1 -1
  31. package/lib/cjs/src/nft/domain/NftContextLoader.test.js.map +3 -3
  32. package/lib/cjs/src/shared/model/TypedDataClearSignContext.js +1 -1
  33. package/lib/cjs/src/shared/model/TypedDataClearSignContext.js.map +2 -2
  34. package/lib/cjs/src/solana/domain/DefaultSolanaContextLoader.js +1 -1
  35. package/lib/cjs/src/solana/domain/DefaultSolanaContextLoader.js.map +3 -3
  36. package/lib/cjs/src/solana/domain/DefaultSolanaContextLoader.test.js +1 -1
  37. package/lib/cjs/src/solana/domain/DefaultSolanaContextLoader.test.js.map +3 -3
  38. package/lib/cjs/src/solanaLifi/domain/SolanaLifiContextLoader.js +1 -1
  39. package/lib/cjs/src/solanaLifi/domain/SolanaLifiContextLoader.js.map +3 -3
  40. package/lib/cjs/src/solanaLifi/domain/SolanaLifiContextLoader.test.js +1 -1
  41. package/lib/cjs/src/solanaLifi/domain/SolanaLifiContextLoader.test.js.map +3 -3
  42. package/lib/cjs/src/solanaToken/domain/SolanaTokenContextLoader.js +1 -1
  43. package/lib/cjs/src/solanaToken/domain/SolanaTokenContextLoader.js.map +3 -3
  44. package/lib/cjs/src/solanaToken/domain/SolanaTokenContextLoader.test.js +1 -1
  45. package/lib/cjs/src/solanaToken/domain/SolanaTokenContextLoader.test.js.map +3 -3
  46. package/lib/cjs/src/token/domain/TokenContextFieldLoader.js +1 -1
  47. package/lib/cjs/src/token/domain/TokenContextFieldLoader.js.map +3 -3
  48. package/lib/cjs/src/token/domain/TokenContextFieldLoader.test.js +1 -1
  49. package/lib/cjs/src/token/domain/TokenContextFieldLoader.test.js.map +3 -3
  50. package/lib/cjs/src/token/domain/TokenContextLoader.js +1 -1
  51. package/lib/cjs/src/token/domain/TokenContextLoader.js.map +3 -3
  52. package/lib/cjs/src/token/domain/TokenContextLoader.test.js +1 -1
  53. package/lib/cjs/src/token/domain/TokenContextLoader.test.js.map +3 -3
  54. package/lib/cjs/src/transaction-check/domain/TransactionCheckContextLoader.js +1 -1
  55. package/lib/cjs/src/transaction-check/domain/TransactionCheckContextLoader.js.map +3 -3
  56. package/lib/cjs/src/transaction-check/domain/TransactionCheckContextLoader.test.js +1 -1
  57. package/lib/cjs/src/transaction-check/domain/TransactionCheckContextLoader.test.js.map +3 -3
  58. package/lib/cjs/src/transaction-check/domain/TypedDataCheckContextLoader.js +1 -1
  59. package/lib/cjs/src/transaction-check/domain/TypedDataCheckContextLoader.js.map +3 -3
  60. package/lib/cjs/src/transaction-check/domain/TypedDataCheckContextLoader.test.js +1 -1
  61. package/lib/cjs/src/transaction-check/domain/TypedDataCheckContextLoader.test.js.map +3 -3
  62. package/lib/cjs/src/trusted-name/di/trustedNameModuleFactory.js +1 -1
  63. package/lib/cjs/src/trusted-name/di/trustedNameModuleFactory.js.map +3 -3
  64. package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.js +1 -1
  65. package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.js.map +3 -3
  66. package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.test.js +1 -1
  67. package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.test.js.map +3 -3
  68. package/lib/cjs/src/typed-data/data/FiltersDto.js.map +1 -1
  69. package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.js +1 -1
  70. package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.js.map +2 -2
  71. package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.test.js +1 -1
  72. package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.test.js.map +2 -2
  73. package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.js +1 -1
  74. package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.js.map +3 -3
  75. package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.test.js +1 -1
  76. package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.test.js.map +3 -3
  77. package/lib/cjs/src/uniswap/domain/UniswapContextLoader.js +1 -1
  78. package/lib/cjs/src/uniswap/domain/UniswapContextLoader.js.map +3 -3
  79. package/lib/cjs/src/uniswap/domain/UniswapContextLoader.test.js +1 -1
  80. package/lib/cjs/src/uniswap/domain/UniswapContextLoader.test.js.map +3 -3
  81. package/lib/esm/package.json +1 -1
  82. package/lib/esm/src/ContextModuleBuilder.js +1 -1
  83. package/lib/esm/src/ContextModuleBuilder.js.map +3 -3
  84. package/lib/esm/src/ContextModuleBuilder.test.js +1 -1
  85. package/lib/esm/src/ContextModuleBuilder.test.js.map +3 -3
  86. package/lib/esm/src/DefaultContextModule.test.js +1 -1
  87. package/lib/esm/src/DefaultContextModule.test.js.map +3 -3
  88. package/lib/esm/src/calldata/domain/CalldataContextLoader.js +1 -1
  89. package/lib/esm/src/calldata/domain/CalldataContextLoader.js.map +3 -3
  90. package/lib/esm/src/calldata/domain/CalldataContextLoader.test.js +1 -1
  91. package/lib/esm/src/calldata/domain/CalldataContextLoader.test.js.map +3 -3
  92. package/lib/esm/src/config/di/configTypes.js +1 -1
  93. package/lib/esm/src/config/di/configTypes.js.map +2 -2
  94. package/lib/esm/src/di.js +1 -1
  95. package/lib/esm/src/di.js.map +3 -3
  96. package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.js +1 -1
  97. package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.js.map +3 -3
  98. package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js +1 -1
  99. package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js.map +3 -3
  100. package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.js +1 -1
  101. package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.js.map +3 -3
  102. package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.test.js +1 -1
  103. package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.test.js.map +3 -3
  104. package/lib/esm/src/nft/domain/NftContextLoader.js +1 -1
  105. package/lib/esm/src/nft/domain/NftContextLoader.js.map +3 -3
  106. package/lib/esm/src/nft/domain/NftContextLoader.test.js +1 -1
  107. package/lib/esm/src/nft/domain/NftContextLoader.test.js.map +3 -3
  108. package/lib/esm/src/shared/model/TypedDataClearSignContext.js.map +2 -2
  109. package/lib/esm/src/solana/domain/DefaultSolanaContextLoader.js +1 -1
  110. package/lib/esm/src/solana/domain/DefaultSolanaContextLoader.js.map +3 -3
  111. package/lib/esm/src/solana/domain/DefaultSolanaContextLoader.test.js +1 -1
  112. package/lib/esm/src/solana/domain/DefaultSolanaContextLoader.test.js.map +3 -3
  113. package/lib/esm/src/solanaLifi/domain/SolanaLifiContextLoader.js +1 -1
  114. package/lib/esm/src/solanaLifi/domain/SolanaLifiContextLoader.js.map +3 -3
  115. package/lib/esm/src/solanaLifi/domain/SolanaLifiContextLoader.test.js +1 -1
  116. package/lib/esm/src/solanaLifi/domain/SolanaLifiContextLoader.test.js.map +3 -3
  117. package/lib/esm/src/solanaToken/domain/SolanaTokenContextLoader.js +1 -1
  118. package/lib/esm/src/solanaToken/domain/SolanaTokenContextLoader.js.map +3 -3
  119. package/lib/esm/src/solanaToken/domain/SolanaTokenContextLoader.test.js +1 -1
  120. package/lib/esm/src/solanaToken/domain/SolanaTokenContextLoader.test.js.map +3 -3
  121. package/lib/esm/src/token/domain/TokenContextFieldLoader.js +1 -1
  122. package/lib/esm/src/token/domain/TokenContextFieldLoader.js.map +3 -3
  123. package/lib/esm/src/token/domain/TokenContextFieldLoader.test.js +1 -1
  124. package/lib/esm/src/token/domain/TokenContextFieldLoader.test.js.map +3 -3
  125. package/lib/esm/src/token/domain/TokenContextLoader.js +1 -1
  126. package/lib/esm/src/token/domain/TokenContextLoader.js.map +3 -3
  127. package/lib/esm/src/token/domain/TokenContextLoader.test.js +1 -1
  128. package/lib/esm/src/token/domain/TokenContextLoader.test.js.map +3 -3
  129. package/lib/esm/src/transaction-check/domain/TransactionCheckContextLoader.js +1 -1
  130. package/lib/esm/src/transaction-check/domain/TransactionCheckContextLoader.js.map +3 -3
  131. package/lib/esm/src/transaction-check/domain/TransactionCheckContextLoader.test.js +1 -1
  132. package/lib/esm/src/transaction-check/domain/TransactionCheckContextLoader.test.js.map +3 -3
  133. package/lib/esm/src/transaction-check/domain/TypedDataCheckContextLoader.js +1 -1
  134. package/lib/esm/src/transaction-check/domain/TypedDataCheckContextLoader.js.map +3 -3
  135. package/lib/esm/src/transaction-check/domain/TypedDataCheckContextLoader.test.js +1 -1
  136. package/lib/esm/src/transaction-check/domain/TypedDataCheckContextLoader.test.js.map +3 -3
  137. package/lib/esm/src/trusted-name/di/trustedNameModuleFactory.js +1 -1
  138. package/lib/esm/src/trusted-name/di/trustedNameModuleFactory.js.map +3 -3
  139. package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.js +1 -1
  140. package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.js.map +3 -3
  141. package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.test.js +1 -1
  142. package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.test.js.map +3 -3
  143. package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.js +1 -1
  144. package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.js.map +2 -2
  145. package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.test.js +1 -1
  146. package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.test.js.map +2 -2
  147. package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.js +1 -1
  148. package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.js.map +3 -3
  149. package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.test.js +1 -1
  150. package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.test.js.map +3 -3
  151. package/lib/esm/src/uniswap/domain/UniswapContextLoader.js +1 -1
  152. package/lib/esm/src/uniswap/domain/UniswapContextLoader.js.map +3 -3
  153. package/lib/esm/src/uniswap/domain/UniswapContextLoader.test.js +1 -1
  154. package/lib/esm/src/uniswap/domain/UniswapContextLoader.test.js.map +3 -3
  155. package/lib/types/src/ContextModuleBuilder.d.ts +18 -3
  156. package/lib/types/src/ContextModuleBuilder.d.ts.map +1 -1
  157. package/lib/types/src/calldata/domain/CalldataContextLoader.d.ts +3 -2
  158. package/lib/types/src/calldata/domain/CalldataContextLoader.d.ts.map +1 -1
  159. package/lib/types/src/config/di/configTypes.d.ts +1 -0
  160. package/lib/types/src/config/di/configTypes.d.ts.map +1 -1
  161. package/lib/types/src/config/model/ContextModuleBuildArgs.d.ts +2 -0
  162. package/lib/types/src/config/model/ContextModuleBuildArgs.d.ts.map +1 -1
  163. package/lib/types/src/config/model/ContextModuleConfig.d.ts +4 -0
  164. package/lib/types/src/config/model/ContextModuleConfig.d.ts.map +1 -1
  165. package/lib/types/src/di.d.ts.map +1 -1
  166. package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.d.ts +3 -2
  167. package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.d.ts.map +1 -1
  168. package/lib/types/src/external-plugin/domain/ExternalPluginContextLoader.d.ts +3 -2
  169. package/lib/types/src/external-plugin/domain/ExternalPluginContextLoader.d.ts.map +1 -1
  170. package/lib/types/src/nft/domain/NftContextLoader.d.ts +3 -2
  171. package/lib/types/src/nft/domain/NftContextLoader.d.ts.map +1 -1
  172. package/lib/types/src/shared/model/TypedDataClearSignContext.d.ts +2 -0
  173. package/lib/types/src/shared/model/TypedDataClearSignContext.d.ts.map +1 -1
  174. package/lib/types/src/solana/domain/DefaultSolanaContextLoader.d.ts +3 -1
  175. package/lib/types/src/solana/domain/DefaultSolanaContextLoader.d.ts.map +1 -1
  176. package/lib/types/src/solanaLifi/domain/SolanaLifiContextLoader.d.ts +3 -1
  177. package/lib/types/src/solanaLifi/domain/SolanaLifiContextLoader.d.ts.map +1 -1
  178. package/lib/types/src/solanaToken/domain/SolanaTokenContextLoader.d.ts +3 -2
  179. package/lib/types/src/solanaToken/domain/SolanaTokenContextLoader.d.ts.map +1 -1
  180. package/lib/types/src/token/domain/TokenContextFieldLoader.d.ts +5 -1
  181. package/lib/types/src/token/domain/TokenContextFieldLoader.d.ts.map +1 -1
  182. package/lib/types/src/token/domain/TokenContextLoader.d.ts +3 -2
  183. package/lib/types/src/token/domain/TokenContextLoader.d.ts.map +1 -1
  184. package/lib/types/src/transaction-check/domain/TransactionCheckContextLoader.d.ts +3 -2
  185. package/lib/types/src/transaction-check/domain/TransactionCheckContextLoader.d.ts.map +1 -1
  186. package/lib/types/src/transaction-check/domain/TypedDataCheckContextLoader.d.ts +3 -2
  187. package/lib/types/src/transaction-check/domain/TypedDataCheckContextLoader.d.ts.map +1 -1
  188. package/lib/types/src/trusted-name/di/trustedNameModuleFactory.d.ts +2 -1
  189. package/lib/types/src/trusted-name/di/trustedNameModuleFactory.d.ts.map +1 -1
  190. package/lib/types/src/trusted-name/domain/TrustedNameContextLoader.d.ts +3 -2
  191. package/lib/types/src/trusted-name/domain/TrustedNameContextLoader.d.ts.map +1 -1
  192. package/lib/types/src/typed-data/data/FiltersDto.d.ts +0 -4
  193. package/lib/types/src/typed-data/data/FiltersDto.d.ts.map +1 -1
  194. package/lib/types/src/typed-data/data/HttpTypedDataDataSource.test.d.ts.map +1 -1
  195. package/lib/types/src/typed-data/domain/DefaultTypedDataContextLoader.d.ts +3 -1
  196. package/lib/types/src/typed-data/domain/DefaultTypedDataContextLoader.d.ts.map +1 -1
  197. package/lib/types/src/uniswap/domain/UniswapContextLoader.d.ts +3 -2
  198. package/lib/types/src/uniswap/domain/UniswapContextLoader.d.ts.map +1 -1
  199. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  200. package/package.json +3 -3
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/solana/domain/DefaultSolanaContextLoader.test.ts"],
4
- "sourcesContent": ["/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\nimport { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\nimport { beforeEach, describe, expect, it, vi } from \"vitest\";\n\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport type { PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { SolanaContextTypes } from \"@/shared/model/SolanaContextTypes\";\nimport type { SolanaTransactionContext } from \"@/solana/domain/solanaContextTypes\";\nimport {\n type SolanaTokenDataSource,\n type TokenDataResponse,\n} from \"@/solanaToken/data/SolanaTokenDataSource\";\nimport { SolanaTokenContextLoader } from \"@/solanaToken/domain/SolanaTokenContextLoader\";\n\ndescribe(\"SolanaTokenContextLoader\", () => {\n let mockDataSource: SolanaTokenDataSource;\n let mockCertLoader: PkiCertificateLoader;\n\n const bytes = new Uint8Array([0xf0, 0xca, 0xcc, 0x1a]);\n\n const tokenDataResponse: TokenDataResponse = {\n descriptor: {\n data: { symbol: \"SOL\", name: \"Solana\", decimals: 9 } as any,\n signatures: {\n prod: \"prod-sig\",\n test: \"test-sig\",\n } as any,\n },\n } as any;\n\n const baseCtx = {\n tokenInternalId: \"token-1\",\n deviceModelId: DeviceModelId.FLEX,\n } as any;\n\n beforeEach(() => {\n vi.restoreAllMocks();\n\n mockDataSource = {\n getTokenInfosPayload: vi.fn(),\n } as unknown as SolanaTokenDataSource;\n\n mockCertLoader = {\n loadCertificate: vi.fn(),\n } as unknown as PkiCertificateLoader;\n });\n\n const makeLoader = (mode?: string) => {\n const config = { cal: { mode } } as unknown as ContextModuleConfig;\n return new SolanaTokenContextLoader(mockDataSource, config, mockCertLoader);\n };\n\n describe(\"canHandle\", () => {\n it(\"returns true when tokenInternalId is provided\", () => {\n const loader = makeLoader(\"prod\");\n\n expect(\n loader.canHandle(\n {\n tokenInternalId: \"abc123\",\n } as SolanaTransactionContext,\n SolanaContextTypes.SOLANA_TOKEN,\n ),\n ).toBe(true);\n });\n\n it(\"returns false when tokenInternalId is missing or falsy\", () => {\n const loader = makeLoader(\"prod\");\n\n expect(\n loader.canHandle(\n { tokenInternalId: \"\" } as any,\n SolanaContextTypes.SOLANA_TOKEN,\n ),\n ).toBe(false);\n expect(\n loader.canHandle(\n { tokenInternalId: undefined } as any,\n SolanaContextTypes.SOLANA_TOKEN,\n ),\n ).toBe(false);\n expect(loader.canHandle({} as any, SolanaContextTypes.SOLANA_TOKEN)).toBe(\n false,\n );\n });\n });\n\n describe(\"loadField\", () => {\n it(\"returns an error when datasource returns Left(error) and still fetched certificate beforehand\", async () => {\n const loader = makeLoader(\"prod\");\n const error = new Error(\"datasource failed\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(error),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 0,\n payload: bytes,\n });\n\n const result = await loader.loadField(baseCtx);\n\n expect(mockDataSource.getTokenInfosPayload).toHaveBeenCalledWith({\n tokenInternalId: \"token-1\",\n });\n expect(mockCertLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: \"token_metadata_key\",\n keyUsage: KeyUsage.CoinMeta,\n targetDevice: baseCtx.deviceModelId,\n });\n expect(result).toEqual({\n type: SolanaContextTypes.ERROR,\n error,\n });\n });\n\n it(\"returns SOLANA_TOKEN with prod signature by default (falsy mode), and includes certificate\", async () => {\n const loader = makeLoader(\"\"); // falsy -> default 'prod'\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 0,\n payload: bytes,\n });\n\n const result = await loader.loadField({\n ...baseCtx,\n tokenInternalId: \"token-2\",\n });\n\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_TOKEN,\n payload: {\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"prod-sig\",\n },\n },\n certificate: { keyUsageNumber: 0, payload: bytes },\n });\n });\n\n it(\"returns SOLANA_TOKEN with signature matching config.cal.mode\", async () => {\n const loader = makeLoader(\"test\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 1,\n payload: bytes,\n });\n\n const result = await loader.loadField({\n ...baseCtx,\n tokenInternalId: \"token-3\",\n });\n\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_TOKEN,\n payload: {\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"test-sig\",\n },\n },\n certificate: { keyUsageNumber: 1, payload: bytes },\n });\n });\n\n it(\"works even if certificate loader returns undefined (certificate omitted)\", async () => {\n const loader = makeLoader(\"prod\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue(undefined);\n\n const result = await loader.loadField(baseCtx);\n\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_TOKEN,\n payload: {\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"prod-sig\",\n },\n },\n certificate: undefined,\n });\n });\n });\n\n describe(\"pluckTokenData (private)\", () => {\n it(\"picks the signature for the configured mode\", () => {\n const loader = makeLoader(\"test\");\n const pluck = (loader as any).pluckTokenData.bind(loader);\n\n const result = pluck(tokenDataResponse);\n\n expect(result).toEqual({\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"test-sig\",\n },\n });\n });\n\n it(\"falls back to 'prod' when config.cal.mode is falsy\", () => {\n const loader = makeLoader(undefined as any);\n const result = (loader as any).pluckTokenData(tokenDataResponse);\n\n expect(result).toEqual({\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"prod-sig\",\n },\n });\n });\n });\n});\n"],
5
- "mappings": "AAIA,OAAS,iBAAAA,MAAqB,kCAC9B,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAC5B,OAAS,cAAAC,EAAY,YAAAC,EAAU,UAAAC,EAAQ,MAAAC,EAAI,MAAAC,MAAU,SAIrD,OAAS,YAAAC,MAAgB,uBACzB,OAAS,sBAAAC,MAA0B,oCAMnC,OAAS,4BAAAC,MAAgC,gDAEzCN,EAAS,2BAA4B,IAAM,CACzC,IAAIO,EACAC,EAEJ,MAAMC,EAAQ,IAAI,WAAW,CAAC,IAAM,IAAM,IAAM,EAAI,CAAC,EAE/CC,EAAuC,CAC3C,WAAY,CACV,KAAM,CAAE,OAAQ,MAAO,KAAM,SAAU,SAAU,CAAE,EACnD,WAAY,CACV,KAAM,WACN,KAAM,UACR,CACF,CACF,EAEMC,EAAU,CACd,gBAAiB,UACjB,cAAef,EAAc,IAC/B,EAEAG,EAAW,IAAM,CACfI,EAAG,gBAAgB,EAEnBI,EAAiB,CACf,qBAAsBJ,EAAG,GAAG,CAC9B,EAEAK,EAAiB,CACf,gBAAiBL,EAAG,GAAG,CACzB,CACF,CAAC,EAED,MAAMS,EAAcC,GAAkB,CACpC,MAAMC,EAAS,CAAE,IAAK,CAAE,KAAAD,CAAK,CAAE,EAC/B,OAAO,IAAIP,EAAyBC,EAAgBO,EAAQN,CAAc,CAC5E,EAEAR,EAAS,YAAa,IAAM,CAC1BE,EAAG,gDAAiD,IAAM,CACxD,MAAMa,EAASH,EAAW,MAAM,EAEhCX,EACEc,EAAO,UACL,CACE,gBAAiB,QACnB,EACAV,EAAmB,YACrB,CACF,EAAE,KAA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KAAKA,CAAM,EAEnCL,CAAiB,EAEtCT,EAAOgB,CAAM,EAAE,QAAQ,CACrB,sBAAuB,CACrB,KAAMP,EAAkB,WAAW,KACnC,UAAW,UACb,CACF,CAAC,CACH,CAAC,EAEDR,EAAG,qDAAsD,IAAM,CAE7D,MAAMe,EADSL,EAAW,MAAgB,EACX,eAAeF,CAAiB,EAE/DT,EAAOgB,CAAM,EAAE,QAAQ,CACrB,sBAAuB,CACrB,KAAMP,EAAkB,WAAW,KACnC,UAAW,UACb,CACF,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["DeviceModelId", "Left", "Right", "beforeEach", "describe", "expect", "it", "vi", "KeyUsage", "SolanaContextTypes", "SolanaTokenContextLoader", "mockDataSource", "mockCertLoader", "bytes", "tokenDataResponse", "baseCtx", "makeLoader", "mode", "config", "loader", "error", "result"]
4
+ "sourcesContent": ["/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\nimport { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\nimport { beforeEach, describe, expect, it, vi } from \"vitest\";\n\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport type { PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { SolanaContextTypes } from \"@/shared/model/SolanaContextTypes\";\nimport type { SolanaTransactionContext } from \"@/solana/domain/solanaContextTypes\";\nimport {\n type SolanaTokenDataSource,\n type TokenDataResponse,\n} from \"@/solanaToken/data/SolanaTokenDataSource\";\nimport { SolanaTokenContextLoader } from \"@/solanaToken/domain/SolanaTokenContextLoader\";\n\nconst mockLoggerFactory = () => ({\n debug: vi.fn(),\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n subscribers: [],\n});\n\ndescribe(\"SolanaTokenContextLoader\", () => {\n let mockDataSource: SolanaTokenDataSource;\n let mockCertLoader: PkiCertificateLoader;\n\n const bytes = new Uint8Array([0xf0, 0xca, 0xcc, 0x1a]);\n\n const tokenDataResponse: TokenDataResponse = {\n descriptor: {\n data: { symbol: \"SOL\", name: \"Solana\", decimals: 9 } as any,\n signatures: {\n prod: \"prod-sig\",\n test: \"test-sig\",\n } as any,\n },\n } as any;\n\n const baseCtx = {\n tokenInternalId: \"token-1\",\n deviceModelId: DeviceModelId.FLEX,\n } as any;\n\n beforeEach(() => {\n vi.restoreAllMocks();\n\n mockDataSource = {\n getTokenInfosPayload: vi.fn(),\n } as unknown as SolanaTokenDataSource;\n\n mockCertLoader = {\n loadCertificate: vi.fn(),\n } as unknown as PkiCertificateLoader;\n });\n\n const makeLoader = (mode?: string) => {\n const config = { cal: { mode } } as unknown as ContextModuleConfig;\n return new SolanaTokenContextLoader(\n mockDataSource,\n config,\n mockCertLoader,\n mockLoggerFactory,\n );\n };\n\n describe(\"canHandle\", () => {\n it(\"returns true when tokenInternalId is provided\", () => {\n const loader = makeLoader(\"prod\");\n\n expect(\n loader.canHandle(\n {\n tokenInternalId: \"abc123\",\n } as SolanaTransactionContext,\n SolanaContextTypes.SOLANA_TOKEN,\n ),\n ).toBe(true);\n });\n\n it(\"returns false when tokenInternalId is missing or falsy\", () => {\n const loader = makeLoader(\"prod\");\n\n expect(\n loader.canHandle(\n { tokenInternalId: \"\" } as any,\n SolanaContextTypes.SOLANA_TOKEN,\n ),\n ).toBe(false);\n expect(\n loader.canHandle(\n { tokenInternalId: undefined } as any,\n SolanaContextTypes.SOLANA_TOKEN,\n ),\n ).toBe(false);\n expect(loader.canHandle({} as any, SolanaContextTypes.SOLANA_TOKEN)).toBe(\n false,\n );\n });\n });\n\n describe(\"loadField\", () => {\n it(\"returns an error when datasource returns Left(error) and still fetched certificate beforehand\", async () => {\n const loader = makeLoader(\"prod\");\n const error = new Error(\"datasource failed\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(error),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 0,\n payload: bytes,\n });\n\n const result = await loader.loadField(baseCtx);\n\n expect(mockDataSource.getTokenInfosPayload).toHaveBeenCalledWith({\n tokenInternalId: \"token-1\",\n });\n expect(mockCertLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: \"token_metadata_key\",\n keyUsage: KeyUsage.CoinMeta,\n targetDevice: baseCtx.deviceModelId,\n });\n expect(result).toEqual({\n type: SolanaContextTypes.ERROR,\n error,\n });\n });\n\n it(\"returns SOLANA_TOKEN with prod signature by default (falsy mode), and includes certificate\", async () => {\n const loader = makeLoader(\"\"); // falsy -> default 'prod'\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 0,\n payload: bytes,\n });\n\n const result = await loader.loadField({\n ...baseCtx,\n tokenInternalId: \"token-2\",\n });\n\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_TOKEN,\n payload: {\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"prod-sig\",\n },\n },\n certificate: { keyUsageNumber: 0, payload: bytes },\n });\n });\n\n it(\"returns SOLANA_TOKEN with signature matching config.cal.mode\", async () => {\n const loader = makeLoader(\"test\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 1,\n payload: bytes,\n });\n\n const result = await loader.loadField({\n ...baseCtx,\n tokenInternalId: \"token-3\",\n });\n\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_TOKEN,\n payload: {\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"test-sig\",\n },\n },\n certificate: { keyUsageNumber: 1, payload: bytes },\n });\n });\n\n it(\"works even if certificate loader returns undefined (certificate omitted)\", async () => {\n const loader = makeLoader(\"prod\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue(undefined);\n\n const result = await loader.loadField(baseCtx);\n\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_TOKEN,\n payload: {\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"prod-sig\",\n },\n },\n certificate: undefined,\n });\n });\n });\n\n describe(\"pluckTokenData (private)\", () => {\n it(\"picks the signature for the configured mode\", () => {\n const loader = makeLoader(\"test\");\n const pluck = (loader as any).pluckTokenData.bind(loader);\n\n const result = pluck(tokenDataResponse);\n\n expect(result).toEqual({\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"test-sig\",\n },\n });\n });\n\n it(\"falls back to 'prod' when config.cal.mode is falsy\", () => {\n const loader = makeLoader(undefined as any);\n const result = (loader as any).pluckTokenData(tokenDataResponse);\n\n expect(result).toEqual({\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"prod-sig\",\n },\n });\n });\n });\n});\n"],
5
+ "mappings": "AAIA,OAAS,iBAAAA,MAAqB,kCAC9B,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAC5B,OAAS,cAAAC,EAAY,YAAAC,EAAU,UAAAC,EAAQ,MAAAC,EAAI,MAAAC,MAAU,SAIrD,OAAS,YAAAC,MAAgB,uBACzB,OAAS,sBAAAC,MAA0B,oCAMnC,OAAS,4BAAAC,MAAgC,gDAEzC,MAAMC,EAAoB,KAAO,CAC/B,MAAOJ,EAAG,GAAG,EACb,KAAMA,EAAG,GAAG,EACZ,KAAMA,EAAG,GAAG,EACZ,MAAOA,EAAG,GAAG,EACb,YAAa,CAAC,CAChB,GAEAH,EAAS,2BAA4B,IA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,CAAC,EAEDX,EAAOiB,CAAM,EAAE,QAAQ,CACrB,KAAMb,EAAmB,aACzB,QAAS,CACP,sBAAuB,CACrB,KAAMM,EAAkB,WAAW,KACnC,UAAW,UACb,CACF,EACA,YAAa,CAAE,eAAgB,EAAG,QAASD,CAAM,CACnD,CAAC,CACH,CAAC,EAEDR,EAAG,2EAA4E,SAAY,CACzF,MAAMc,EAASH,EAAW,MAAM,EAEhCV,EAAG,MAAMK,EAAgB,sBAAsB,EAAE,kBAC/CV,EAAMa,CAAiB,CACzB,EACAR,EAAG,MAAMM,EAAgB,iBAAiB,EAAE,kBAAkB,MAAS,EAEvE,MAAMS,EAAS,MAAMF,EAAO,UAAUJ,CAAO,EAE7CX,EAAOiB,CAAM,EAAE,QAAQ,CACrB,KAAMb,EAAmB,aACzB,QAAS,CACP,sBAAuB,CACrB,KAAMM,EAAkB,WAAW,KACnC,UAAW,UACb,CACF,EACA,YAAa,MACf,CAAC,CACH,CAAC,CACH,CAAC,EAEDX,EAAS,2BAA4B,IAAM,CACzCE,EAAG,8CAA+C,IAAM,CACtD,MAAMc,EAASH,EAAW,MAAM,EAG1BK,EAFSF,EAAe,eAAe,KAAKA,CAAM,EAEnCL,CAAiB,EAEtCV,EAAOiB,CAAM,EAAE,QAAQ,CACrB,sBAAuB,CACrB,KAAMP,EAAkB,WAAW,KACnC,UAAW,UACb,CACF,CAAC,CACH,CAAC,EAEDT,EAAG,qDAAsD,IAAM,CAE7D,MAAMgB,EADSL,EAAW,MAAgB,EACX,eAAeF,CAAiB,EAE/DV,EAAOiB,CAAM,EAAE,QAAQ,CACrB,sBAAuB,CACrB,KAAMP,EAAkB,WAAW,KACnC,UAAW,UACb,CACF,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["DeviceModelId", "Left", "Right", "beforeEach", "describe", "expect", "it", "vi", "KeyUsage", "SolanaContextTypes", "SolanaTokenContextLoader", "mockLoggerFactory", "mockDataSource", "mockCertLoader", "bytes", "tokenDataResponse", "baseCtx", "makeLoader", "mode", "config", "loader", "error", "result"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var u=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var p=(o,t,n,e)=>{for(var a=e>1?void 0:e?S(t,n):t,r=o.length-1,l;r>=0;r--)(l=o[r])&&(a=(e?l(t,n,a):l(a))||a);return e&&a&&u(t,n,a),a},c=(o,t)=>(n,e)=>t(n,e,o);import{inject as f,injectable as m}from"inversify";import{SolanaContextTypes as s}from"../../shared/model/SolanaContextTypes";import{lifiTypes as d}from"../../solanaLifi/di/solanaLifiTypes";let i=class{constructor(t){this.dataSource=t}canHandle(t,n){if(n!==s.SOLANA_LIFI)return!1;if(typeof t=="object"&&t!==null&&"templateId"in t){const e=t.templateId;return typeof e=="string"&&e.length>0}return!1}async loadField(t){const{templateId:n}=t;return(await this.dataSource.getTransactionDescriptorsPayload({templateId:n})).caseOf({Left:a=>({type:s.ERROR,error:a}),Right:a=>({type:s.SOLANA_LIFI,payload:this.pluckTransactionData(a)})})}pluckTransactionData(t){return{...t.descriptors}}};i=p([m(),c(0,f(d.SolanaLifiDataSource))],i);export{i as SolanaLifiContextLoader};
1
+ var u=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var c=(i,t,e,o)=>{for(var a=o>1?void 0:o?f(t,e):t,r=i.length-1,l;r>=0;r--)(l=i[r])&&(a=(o?l(t,e,a):l(a))||a);return o&&a&&u(t,e,a),a},s=(i,t)=>(e,o)=>t(e,o,i);import{inject as d,injectable as g}from"inversify";import{configTypes as S}from"../../config/di/configTypes";import{SolanaContextTypes as p}from"../../shared/model/SolanaContextTypes";import{lifiTypes as m}from"../../solanaLifi/di/solanaLifiTypes";let n=class{constructor(t,e){this.dataSource=t;this.logger=e("SolanaLifiContextLoader")}logger;canHandle(t,e){if(e!==p.SOLANA_LIFI)return!1;if(typeof t=="object"&&t!==null&&"templateId"in t){const o=t.templateId;return typeof o=="string"&&o.length>0}return!1}async loadField(t){this.logger.debug("[loadField] Loading solana Lifi context",{data:{input:t}});const{templateId:e}=t;return(await this.dataSource.getTransactionDescriptorsPayload({templateId:e})).caseOf({Left:a=>(this.logger.error("[loadField] Error loading solana Lifi context",{data:{error:a}}),{type:p.ERROR,error:a}),Right:a=>(this.logger.debug("[loadField] Successfully loaded solana Lifi context",{data:{payload:this.pluckTransactionData(a)}}),{type:p.SOLANA_LIFI,payload:this.pluckTransactionData(a)})})}pluckTransactionData(t){return{...t.descriptors}}};n=c([g(),s(0,d(m.SolanaLifiDataSource)),s(1,d(S.ContextModuleLoggerFactory))],n);export{n as SolanaLifiContextLoader};
2
2
  //# sourceMappingURL=SolanaLifiContextLoader.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/solanaLifi/domain/SolanaLifiContextLoader.ts"],
4
- "sourcesContent": ["import { inject, injectable } from \"inversify\";\n\nimport { ContextFieldLoader } from \"@/shared/domain/ContextFieldLoader\";\nimport {\n SolanaContextTypes,\n SolanaLifiContextResult,\n SolanaTransactionDescriptorList,\n} from \"@/shared/model/SolanaContextTypes\";\nimport { SolanaTransactionContext } from \"@/solana/domain/solanaContextTypes\";\nimport {\n GetTransactionDescriptorsResponse,\n type SolanaLifiDataSource,\n} from \"@/solanaLifi/data/SolanaLifiDataSource\";\nimport { lifiTypes } from \"@/solanaLifi/di/solanaLifiTypes\";\n\ntype SolanaLifiFieldInput = SolanaTransactionContext & {\n templateId: string;\n};\n\n@injectable()\nexport class SolanaLifiContextLoader\n implements\n ContextFieldLoader<\n SolanaLifiFieldInput,\n SolanaContextTypes,\n SolanaLifiContextResult\n >\n{\n constructor(\n @inject(lifiTypes.SolanaLifiDataSource)\n private readonly dataSource: SolanaLifiDataSource,\n ) {}\n\n public canHandle(\n field: unknown,\n expectedType: SolanaContextTypes,\n ): field is SolanaLifiFieldInput {\n if (expectedType !== SolanaContextTypes.SOLANA_LIFI) return false;\n\n if (typeof field === \"object\" && field !== null && \"templateId\" in field) {\n const templateId = (field as { templateId: unknown }).templateId;\n return typeof templateId === \"string\" && templateId.length > 0;\n }\n\n return false;\n }\n\n public async loadField(\n solanaTokenContextInput: SolanaLifiFieldInput,\n ): Promise<SolanaLifiContextResult> {\n const { templateId } = solanaTokenContextInput;\n\n const payload = await this.dataSource.getTransactionDescriptorsPayload({\n templateId,\n });\n\n return payload.caseOf({\n Left: (error): SolanaLifiContextResult => ({\n type: SolanaContextTypes.ERROR,\n error,\n }),\n Right: (value): SolanaLifiContextResult => ({\n type: SolanaContextTypes.SOLANA_LIFI,\n payload: this.pluckTransactionData(value),\n }),\n });\n }\n\n private pluckTransactionData(\n tokenData: GetTransactionDescriptorsResponse,\n ): SolanaTransactionDescriptorList {\n return {\n ...tokenData.descriptors,\n };\n }\n}\n"],
5
- "mappings": "iOAAA,OAAS,UAAAA,EAAQ,cAAAC,MAAkB,YAGnC,OACE,sBAAAC,MAGK,oCAMP,OAAS,aAAAC,MAAiB,kCAOnB,IAAMC,EAAN,KAOP,CACE,YAEmBC,EACjB,CADiB,gBAAAA,CAChB,CAEI,UACLC,EACAC,EAC+B,CAC/B,GAAIA,IAAiBC,EAAmB,YAAa,MAAO,GAE5D,GAAI,OAAOF,GAAU,UAAYA,IAAU,MAAQ,eAAgBA,EAAO,CACxE,MAAMG,EAAcH,EAAkC,WACtD,OAAO,OAAOG,GAAe,UAAYA,EAAW,OAAS,CAC/D,CAEA,MAAO,EACT,CAEA,MAAa,UACXC,EACkC,CAClC,KAAM,CAAE,WAAAD,CAAW,EAAIC,EAMvB,OAJgB,MAAM,KAAK,WAAW,iCAAiC,CACrE,WAAAD,CACF,CAAC,GAEc,OAAO,CACpB,KAAOE,IAAoC,CACzC,KAAMH,EAAmB,MACzB,MAAAG,CACF,GACA,MAAQC,IAAoC,CAC1C,KAAMJ,EAAmB,YACzB,QAAS,KAAK,qBAAqBI,CAAK,CAC1C,EACF,CAAC,CACH,CAEQ,qBACNC,EACiC,CACjC,MAAO,CACL,GAAGA,EAAU,WACf,CACF,CACF,EAvDaT,EAANU,EAAA,CADNC,EAAW,EAUPC,EAAA,EAAAC,EAAOC,EAAU,oBAAoB,IAT7Bd",
6
- "names": ["inject", "injectable", "SolanaContextTypes", "lifiTypes", "SolanaLifiContextLoader", "dataSource", "field", "expectedType", "SolanaContextTypes", "templateId", "solanaTokenContextInput", "error", "value", "tokenData", "__decorateClass", "injectable", "__decorateParam", "inject", "lifiTypes"]
4
+ "sourcesContent": ["import { LoggerPublisherService } from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { ContextFieldLoader } from \"@/shared/domain/ContextFieldLoader\";\nimport {\n SolanaContextTypes,\n SolanaLifiContextResult,\n SolanaTransactionDescriptorList,\n} from \"@/shared/model/SolanaContextTypes\";\nimport { SolanaTransactionContext } from \"@/solana/domain/solanaContextTypes\";\nimport {\n GetTransactionDescriptorsResponse,\n type SolanaLifiDataSource,\n} from \"@/solanaLifi/data/SolanaLifiDataSource\";\nimport { lifiTypes } from \"@/solanaLifi/di/solanaLifiTypes\";\n\ntype SolanaLifiFieldInput = SolanaTransactionContext & {\n templateId: string;\n};\n\n@injectable()\nexport class SolanaLifiContextLoader\n implements\n ContextFieldLoader<\n SolanaLifiFieldInput,\n SolanaContextTypes,\n SolanaLifiContextResult\n >\n{\n private logger: LoggerPublisherService;\n\n constructor(\n @inject(lifiTypes.SolanaLifiDataSource)\n private readonly dataSource: SolanaLifiDataSource,\n @inject(configTypes.ContextModuleLoggerFactory)\n loggerFactory: (tag: string) => LoggerPublisherService,\n ) {\n this.logger = loggerFactory(\"SolanaLifiContextLoader\");\n }\n\n public canHandle(\n field: unknown,\n expectedType: SolanaContextTypes,\n ): field is SolanaLifiFieldInput {\n if (expectedType !== SolanaContextTypes.SOLANA_LIFI) return false;\n\n if (typeof field === \"object\" && field !== null && \"templateId\" in field) {\n const templateId = (field as { templateId: unknown }).templateId;\n return typeof templateId === \"string\" && templateId.length > 0;\n }\n\n return false;\n }\n\n public async loadField(\n solanaTokenContextInput: SolanaLifiFieldInput,\n ): Promise<SolanaLifiContextResult> {\n this.logger.debug(\"[loadField] Loading solana Lifi context\", {\n data: { input: solanaTokenContextInput },\n });\n const { templateId } = solanaTokenContextInput;\n\n const payload = await this.dataSource.getTransactionDescriptorsPayload({\n templateId,\n });\n\n return payload.caseOf({\n Left: (error): SolanaLifiContextResult => {\n this.logger.error(\"[loadField] Error loading solana Lifi context\", {\n data: { error },\n });\n\n return {\n type: SolanaContextTypes.ERROR,\n error,\n };\n },\n Right: (value): SolanaLifiContextResult => {\n this.logger.debug(\n \"[loadField] Successfully loaded solana Lifi context\",\n {\n data: { payload: this.pluckTransactionData(value) },\n },\n );\n\n return {\n type: SolanaContextTypes.SOLANA_LIFI,\n payload: this.pluckTransactionData(value),\n };\n },\n });\n }\n\n private pluckTransactionData(\n tokenData: GetTransactionDescriptorsResponse,\n ): SolanaTransactionDescriptorList {\n return {\n ...tokenData.descriptors,\n };\n }\n}\n"],
5
+ "mappings": "iOACA,OAAS,UAAAA,EAAQ,cAAAC,MAAkB,YAEnC,OAAS,eAAAC,MAAmB,0BAE5B,OACE,sBAAAC,MAGK,oCAMP,OAAS,aAAAC,MAAiB,kCAOnB,IAAMC,EAAN,KAOP,CAGE,YAEmBC,EAEjBC,EACA,CAHiB,gBAAAD,EAIjB,KAAK,OAASC,EAAc,yBAAyB,CACvD,CATQ,OAWD,UACLC,EACAC,EAC+B,CAC/B,GAAIA,IAAiBC,EAAmB,YAAa,MAAO,GAE5D,GAAI,OAAOF,GAAU,UAAYA,IAAU,MAAQ,eAAgBA,EAAO,CACxE,MAAMG,EAAcH,EAAkC,WACtD,OAAO,OAAOG,GAAe,UAAYA,EAAW,OAAS,CAC/D,CAEA,MAAO,EACT,CAEA,MAAa,UACXC,EACkC,CAClC,KAAK,OAAO,MAAM,0CAA2C,CAC3D,KAAM,CAAE,MAAOA,CAAwB,CACzC,CAAC,EACD,KAAM,CAAE,WAAAD,CAAW,EAAIC,EAMvB,OAJgB,MAAM,KAAK,WAAW,iCAAiC,CACrE,WAAAD,CACF,CAAC,GAEc,OAAO,CACpB,KAAOE,IACL,KAAK,OAAO,MAAM,gDAAiD,CACjE,KAAM,CAAE,MAAAA,CAAM,CAChB,CAAC,EAEM,CACL,KAAMH,EAAmB,MACzB,MAAAG,CACF,GAEF,MAAQC,IACN,KAAK,OAAO,MACV,sDACA,CACE,KAAM,CAAE,QAAS,KAAK,qBAAqBA,CAAK,CAAE,CACpD,CACF,EAEO,CACL,KAAMJ,EAAmB,YACzB,QAAS,KAAK,qBAAqBI,CAAK,CAC1C,EAEJ,CAAC,CACH,CAEQ,qBACNC,EACiC,CACjC,MAAO,CACL,GAAGA,EAAU,WACf,CACF,CACF,EA/EaV,EAANW,EAAA,CADNC,EAAW,EAYPC,EAAA,EAAAC,EAAOC,EAAU,oBAAoB,GAErCF,EAAA,EAAAC,EAAOE,EAAY,0BAA0B,IAbrChB",
6
+ "names": ["inject", "injectable", "configTypes", "SolanaContextTypes", "lifiTypes", "SolanaLifiContextLoader", "dataSource", "loggerFactory", "field", "expectedType", "SolanaContextTypes", "templateId", "solanaTokenContextInput", "error", "value", "tokenData", "__decorateClass", "injectable", "__decorateParam", "inject", "lifiTypes", "configTypes"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{Left as m,Right as y}from"purify-ts";import{beforeEach as I,describe as c,expect as e,it as l,vi as i}from"vitest";import{SolanaContextTypes as o}from"../../shared/model/SolanaContextTypes";import{SolanaLifiContextLoader as L}from"./SolanaLifiContextLoader";c("SolanaLifiContextLoader",()=>{let t;const d={swap:{programId:"SomeProgram",accounts:[],data:"abc123"},bridge:{programId:"AnotherProgram",accounts:[],data:"def456"}},p={descriptors:d};I(()=>{i.restoreAllMocks(),t={getTransactionDescriptorsPayload:i.fn()}});const r=()=>new L(t);c("canHandle",()=>{l("returns true when templateId is provided",()=>{const a=r();e(a.canHandle({templateId:"tpl-123",deviceModelId:"nanoS"},o.SOLANA_LIFI)).toBe(!0)}),l("returns false when templateId is missing or falsy",()=>{const a=r();e(a.canHandle({templateId:""},o.SOLANA_LIFI)).toBe(!1),e(a.canHandle({templateId:void 0},o.SOLANA_LIFI)).toBe(!1),e(a.canHandle({},o.SOLANA_LIFI)).toBe(!1)})}),c("loadField",()=>{l("returns an error when datasource returns Left(error)",async()=>{const a=r(),n=new Error("boom");i.spyOn(t,"getTransactionDescriptorsPayload").mockResolvedValue(m(n));const s={templateId:"tpl-err",deviceModelId:"nanoS"},u=await a.loadField(s);e(t.getTransactionDescriptorsPayload).toHaveBeenCalledWith({templateId:"tpl-err"}),e(u).toEqual({type:o.ERROR,error:n})}),l("returns SOLANA_LIFI with plucked descriptors when datasource returns Right(value)",async()=>{const a=r();i.spyOn(t,"getTransactionDescriptorsPayload").mockResolvedValue(y(p));const n={templateId:"tpl-ok",deviceModelId:"nanoS"},s=await a.loadField(n);e(t.getTransactionDescriptorsPayload).toHaveBeenCalledWith({templateId:"tpl-ok"}),e(s).toEqual({type:o.SOLANA_LIFI,payload:d})})}),c("pluckTransactionData (private)",()=>{l("simply returns the descriptors object from the response",()=>{const a=r(),s=a.pluckTransactionData.bind(a)(p);e(s).toEqual(d)})})});
1
+ import{Left as m,Right as y}from"purify-ts";import{beforeEach as f,describe as i,expect as e,it as l,vi as t}from"vitest";import{SolanaContextTypes as r}from"../../shared/model/SolanaContextTypes";import{SolanaLifiContextLoader as I}from"./SolanaLifiContextLoader";const L=()=>({debug:t.fn(),info:t.fn(),warn:t.fn(),error:t.fn(),subscribers:[]});i("SolanaLifiContextLoader",()=>{let o;const d={swap:{programId:"SomeProgram",accounts:[],data:"abc123"},bridge:{programId:"AnotherProgram",accounts:[],data:"def456"}},p={descriptors:d};f(()=>{t.restoreAllMocks(),o={getTransactionDescriptorsPayload:t.fn()}});const n=()=>new I(o,L);i("canHandle",()=>{l("returns true when templateId is provided",()=>{const a=n();e(a.canHandle({templateId:"tpl-123",deviceModelId:"nanoS"},r.SOLANA_LIFI)).toBe(!0)}),l("returns false when templateId is missing or falsy",()=>{const a=n();e(a.canHandle({templateId:""},r.SOLANA_LIFI)).toBe(!1),e(a.canHandle({templateId:void 0},r.SOLANA_LIFI)).toBe(!1),e(a.canHandle({},r.SOLANA_LIFI)).toBe(!1)})}),i("loadField",()=>{l("returns an error when datasource returns Left(error)",async()=>{const a=n(),s=new Error("boom");t.spyOn(o,"getTransactionDescriptorsPayload").mockResolvedValue(m(s));const c={templateId:"tpl-err",deviceModelId:"nanoS"},u=await a.loadField(c);e(o.getTransactionDescriptorsPayload).toHaveBeenCalledWith({templateId:"tpl-err"}),e(u).toEqual({type:r.ERROR,error:s})}),l("returns SOLANA_LIFI with plucked descriptors when datasource returns Right(value)",async()=>{const a=n();t.spyOn(o,"getTransactionDescriptorsPayload").mockResolvedValue(y(p));const s={templateId:"tpl-ok",deviceModelId:"nanoS"},c=await a.loadField(s);e(o.getTransactionDescriptorsPayload).toHaveBeenCalledWith({templateId:"tpl-ok"}),e(c).toEqual({type:r.SOLANA_LIFI,payload:d})})}),i("pluckTransactionData (private)",()=>{l("simply returns the descriptors object from the response",()=>{const a=n(),c=a.pluckTransactionData.bind(a)(p);e(c).toEqual(d)})})});
2
2
  //# sourceMappingURL=SolanaLifiContextLoader.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/solanaLifi/domain/SolanaLifiContextLoader.test.ts"],
4
- "sourcesContent": ["/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\nimport { Left, Right } from \"purify-ts\";\nimport { beforeEach, describe, expect, it, vi } from \"vitest\";\n\nimport {\n SolanaContextTypes,\n type SolanaTransactionDescriptorList,\n} from \"@/shared/model/SolanaContextTypes\";\nimport {\n type GetTransactionDescriptorsResponse,\n type SolanaLifiDataSource,\n} from \"@/solanaLifi/data/SolanaLifiDataSource\";\n\nimport { SolanaLifiContextLoader } from \"./SolanaLifiContextLoader\";\n\ndescribe(\"SolanaLifiContextLoader\", () => {\n let mockDataSource: SolanaLifiDataSource;\n\n const descriptors: SolanaTransactionDescriptorList = {\n // Shape not important for the loader: it's plucked verbatim\n swap: { programId: \"SomeProgram\", accounts: [], data: \"abc123\" } as any,\n bridge: {\n programId: \"AnotherProgram\",\n accounts: [],\n data: \"def456\",\n } as any,\n };\n\n const txDescriptorsResponse: GetTransactionDescriptorsResponse = {\n descriptors,\n } as any;\n\n beforeEach(() => {\n vi.restoreAllMocks();\n mockDataSource = {\n getTransactionDescriptorsPayload: vi.fn(),\n } as unknown as SolanaLifiDataSource;\n });\n\n const makeLoader = () => new SolanaLifiContextLoader(mockDataSource);\n\n describe(\"canHandle\", () => {\n it(\"returns true when templateId is provided\", () => {\n const loader = makeLoader();\n\n expect(\n loader.canHandle(\n {\n templateId: \"tpl-123\",\n deviceModelId: \"nanoS\" as any,\n },\n SolanaContextTypes.SOLANA_LIFI,\n ),\n ).toBe(true);\n });\n\n it(\"returns false when templateId is missing or falsy\", () => {\n const loader = makeLoader();\n\n expect(\n loader.canHandle(\n { templateId: \"\" } as any,\n SolanaContextTypes.SOLANA_LIFI,\n ),\n ).toBe(false);\n expect(\n loader.canHandle(\n { templateId: undefined } as any,\n SolanaContextTypes.SOLANA_LIFI,\n ),\n ).toBe(false);\n expect(loader.canHandle({} as any, SolanaContextTypes.SOLANA_LIFI)).toBe(\n false,\n );\n });\n });\n\n describe(\"loadField\", () => {\n it(\"returns an error when datasource returns Left(error)\", async () => {\n const loader = makeLoader();\n const error = new Error(\"boom\");\n vi.spyOn(\n mockDataSource,\n \"getTransactionDescriptorsPayload\",\n ).mockResolvedValue(Left(error));\n const input = { templateId: \"tpl-err\", deviceModelId: \"nanoS\" as any };\n const result = await loader.loadField(input);\n\n expect(\n mockDataSource.getTransactionDescriptorsPayload,\n ).toHaveBeenCalledWith({\n templateId: \"tpl-err\",\n });\n expect(result).toEqual({\n type: SolanaContextTypes.ERROR,\n error,\n });\n });\n\n it(\"returns SOLANA_LIFI with plucked descriptors when datasource returns Right(value)\", async () => {\n const loader = makeLoader();\n vi.spyOn(\n mockDataSource,\n \"getTransactionDescriptorsPayload\",\n ).mockResolvedValue(Right(txDescriptorsResponse));\n const input = { templateId: \"tpl-ok\", deviceModelId: \"nanoS\" as any };\n const result = await loader.loadField(input);\n\n expect(\n mockDataSource.getTransactionDescriptorsPayload,\n ).toHaveBeenCalledWith({\n templateId: \"tpl-ok\",\n });\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_LIFI,\n payload: descriptors,\n });\n });\n });\n\n describe(\"pluckTransactionData (private)\", () => {\n it(\"simply returns the descriptors object from the response\", () => {\n const loader = makeLoader();\n const pluck = (loader as any).pluckTransactionData.bind(loader);\n\n const result = pluck(txDescriptorsResponse);\n\n expect(result).toEqual(descriptors);\n });\n });\n});\n"],
5
- "mappings": "AAIA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAC5B,OAAS,cAAAC,EAAY,YAAAC,EAAU,UAAAC,EAAQ,MAAAC,EAAI,MAAAC,MAAU,SAErD,OACE,sBAAAC,MAEK,oCAMP,OAAS,2BAAAC,MAA+B,4BAExCL,EAAS,0BAA2B,IAAM,CACxC,IAAIM,EAEJ,MAAMC,EAA+C,CAEnD,KAAM,CAAE,UAAW,cAAe,SAAU,CAAC,EAAG,KAAM,QAAS,EAC/D,OAAQ,CACN,UAAW,iBACX,SAAU,CAAC,EACX,KAAM,QACR,CACF,EAEMC,EAA2D,CAC/D,YAAAD,CACF,EAEAR,EAAW,IAAM,CACfI,EAAG,gBAAgB,EACnBG,EAAiB,CACf,iCAAkCH,EAAG,GAAG,CAC1C,CACF,CAAC,EAED,MAAMM,EAAa,IAAM,IAAIJ,EAAwBC,CAAc,EAEnEN,EAAS,YAAa,IAAM,CAC1BE,EAAG,2CAA4C,IAAM,CACnD,MAAMQ,EAASD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C,EAEDP,EAAS,iCAAkC,IAAM,CAC/CE,EAAG,0DAA2D,IAAM,CAClE,MAAMQ,EAASD,EAAW,EAGpBI,EAFSH,EAAe,qBAAqB,KAAKA,CAAM,EAEzCF,CAAqB,EAE1CP,EAAOY,CAAM,EAAE,QAAQN,CAAW,CACpC,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["Left", "Right", "beforeEach", "describe", "expect", "it", "vi", "SolanaContextTypes", "SolanaLifiContextLoader", "mockDataSource", "descriptors", "txDescriptorsResponse", "makeLoader", "loader", "error", "input", "result"]
4
+ "sourcesContent": ["/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\nimport { Left, Right } from \"purify-ts\";\nimport { beforeEach, describe, expect, it, vi } from \"vitest\";\n\nimport {\n SolanaContextTypes,\n type SolanaTransactionDescriptorList,\n} from \"@/shared/model/SolanaContextTypes\";\nimport {\n type GetTransactionDescriptorsResponse,\n type SolanaLifiDataSource,\n} from \"@/solanaLifi/data/SolanaLifiDataSource\";\n\nimport { SolanaLifiContextLoader } from \"./SolanaLifiContextLoader\";\n\nconst mockLoggerFactory = () => ({\n debug: vi.fn(),\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n subscribers: [],\n});\n\ndescribe(\"SolanaLifiContextLoader\", () => {\n let mockDataSource: SolanaLifiDataSource;\n\n const descriptors: SolanaTransactionDescriptorList = {\n // Shape not important for the loader: it's plucked verbatim\n swap: { programId: \"SomeProgram\", accounts: [], data: \"abc123\" } as any,\n bridge: {\n programId: \"AnotherProgram\",\n accounts: [],\n data: \"def456\",\n } as any,\n };\n\n const txDescriptorsResponse: GetTransactionDescriptorsResponse = {\n descriptors,\n } as any;\n\n beforeEach(() => {\n vi.restoreAllMocks();\n mockDataSource = {\n getTransactionDescriptorsPayload: vi.fn(),\n } as unknown as SolanaLifiDataSource;\n });\n\n const makeLoader = () =>\n new SolanaLifiContextLoader(mockDataSource, mockLoggerFactory);\n\n describe(\"canHandle\", () => {\n it(\"returns true when templateId is provided\", () => {\n const loader = makeLoader();\n\n expect(\n loader.canHandle(\n {\n templateId: \"tpl-123\",\n deviceModelId: \"nanoS\" as any,\n },\n SolanaContextTypes.SOLANA_LIFI,\n ),\n ).toBe(true);\n });\n\n it(\"returns false when templateId is missing or falsy\", () => {\n const loader = makeLoader();\n\n expect(\n loader.canHandle(\n { templateId: \"\" } as any,\n SolanaContextTypes.SOLANA_LIFI,\n ),\n ).toBe(false);\n expect(\n loader.canHandle(\n { templateId: undefined } as any,\n SolanaContextTypes.SOLANA_LIFI,\n ),\n ).toBe(false);\n expect(loader.canHandle({} as any, SolanaContextTypes.SOLANA_LIFI)).toBe(\n false,\n );\n });\n });\n\n describe(\"loadField\", () => {\n it(\"returns an error when datasource returns Left(error)\", async () => {\n const loader = makeLoader();\n const error = new Error(\"boom\");\n vi.spyOn(\n mockDataSource,\n \"getTransactionDescriptorsPayload\",\n ).mockResolvedValue(Left(error));\n const input = { templateId: \"tpl-err\", deviceModelId: \"nanoS\" as any };\n const result = await loader.loadField(input);\n\n expect(\n mockDataSource.getTransactionDescriptorsPayload,\n ).toHaveBeenCalledWith({\n templateId: \"tpl-err\",\n });\n expect(result).toEqual({\n type: SolanaContextTypes.ERROR,\n error,\n });\n });\n\n it(\"returns SOLANA_LIFI with plucked descriptors when datasource returns Right(value)\", async () => {\n const loader = makeLoader();\n vi.spyOn(\n mockDataSource,\n \"getTransactionDescriptorsPayload\",\n ).mockResolvedValue(Right(txDescriptorsResponse));\n const input = { templateId: \"tpl-ok\", deviceModelId: \"nanoS\" as any };\n const result = await loader.loadField(input);\n\n expect(\n mockDataSource.getTransactionDescriptorsPayload,\n ).toHaveBeenCalledWith({\n templateId: \"tpl-ok\",\n });\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_LIFI,\n payload: descriptors,\n });\n });\n });\n\n describe(\"pluckTransactionData (private)\", () => {\n it(\"simply returns the descriptors object from the response\", () => {\n const loader = makeLoader();\n const pluck = (loader as any).pluckTransactionData.bind(loader);\n\n const result = pluck(txDescriptorsResponse);\n\n expect(result).toEqual(descriptors);\n });\n });\n});\n"],
5
+ "mappings": "AAIA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAC5B,OAAS,cAAAC,EAAY,YAAAC,EAAU,UAAAC,EAAQ,MAAAC,EAAI,MAAAC,MAAU,SAErD,OACE,sBAAAC,MAEK,oCAMP,OAAS,2BAAAC,MAA+B,4BAExC,MAAMC,EAAoB,KAAO,CAC/B,MAAOH,EAAG,GAAG,EACb,KAAMA,EAAG,GAAG,EACZ,KAAMA,EAAG,GAAG,EACZ,MAAOA,EAAG,GAAG,EACb,YAAa,CAAC,CAChB,GAEAH,EAAS,0BAA2B,IAAM,CACxC,IAAIO,EAEJ,MAAMC,EAA+C,CAEnD,KAAM,CAAE,UAAW,cAAe,SAAU,CAAC,EAAG,KAAM,QAAS,EAC/D,OAAQ,CACN,UAAW,iBACX,SAAU,CAAC,EACX,KAAM,QACR,CACF,EAEMC,EAA2D,CAC/D,YAAAD,CACF,EAEAT,EAAW,IAAM,CACfI,EAAG,gBAAgB,EACnBI,EAAiB,CACf,iCAAkCJ,EAAG,GAAG,CAC1C,CACF,CAAC,EAED,MAAMO,EAAa,IACjB,IAAIL,EAAwBE,EAAgBD,CAAiB,EAE/DN,EAAS,YAAa,IAAM,CAC1BE,EAAG,2CAA4C,IAAM,CACnD,MAAMS,EAASD,EAAW,EAE1BT,EACEU,EAAO,UACL,CACE,WAAY,UACZ,cAAe,OACjB,EACAP,EAAmB,WACrB,CACF,EAAE,KAAK,EAAI,CACb,CAAC,EAEDF,EAAG,oDAAqD,IAAM,CAC5D,MAAMS,EAASD,EAAW,EAE1BT,EACEU,EAAO,UACL,CAAE,WAAY,EAAG,EACjBP,EAAmB,WACrB,CACF,EAAE,KAAK,EAAK,EACZH,EACEU,EAAO,UAC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extTypes", "SolanaLifiContextLoader", "mockLoggerFactory", "mockDataSource", "descriptors", "txDescriptorsResponse", "makeLoader", "loader", "error", "input", "result"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var k=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var d=(i,e,t,o)=>{for(var a=o>1?void 0:o?f(e,t):e,r=i.length-1,n;r>=0;r--)(n=i[r])&&(a=(o?n(e,t,a):n(a))||a);return o&&a&&k(e,t,a),a},l=(i,e)=>(t,o)=>e(t,o,i);import{inject as s,injectable as u}from"inversify";import{configTypes as m}from"../../config/di/configTypes";import{pkiTypes as T}from"../../pki/di/pkiTypes";import{KeyUsage as y}from"../../pki/model/KeyUsage";import{SolanaContextTypes as c}from"../../shared/model/SolanaContextTypes";import{solanaTokenTypes as S}from"../../solanaToken/di/solanaTokenTypes";let p=class{constructor(e,t,o){this.dataSource=e;this.config=t;this._certificateLoader=o}canHandle(e,t){if(t!==c.SOLANA_TOKEN||typeof e!="object"||e===null||!("tokenInternalId"in e))return!1;const o=e.tokenInternalId;return typeof o=="string"&&o.length>0}async loadField(e){const{tokenInternalId:t,deviceModelId:o}=e,a=await this.dataSource.getTokenInfosPayload({tokenInternalId:t}),r=await this._certificateLoader.loadCertificate({keyId:"token_metadata_key",keyUsage:y.CoinMeta,targetDevice:o});return a.caseOf({Left:n=>({type:c.ERROR,error:n}),Right:n=>({type:c.SOLANA_TOKEN,payload:this.pluckTokenData(n),certificate:r})})}pluckTokenData(e){const t=this.config.cal.mode||"prod";return{solanaTokenDescriptor:{data:e.descriptor.data,signature:e.descriptor.signatures[t]}}}};p=d([u(),l(0,s(S.SolanaTokenDataSource)),l(1,s(m.Config)),l(2,s(T.PkiCertificateLoader))],p);export{p as SolanaTokenContextLoader};
1
+ var k=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var p=(i,e,t,o)=>{for(var a=o>1?void 0:o?g(e,t):e,r=i.length-1,n;r>=0;r--)(n=i[r])&&(a=(o?n(e,t,a):n(a))||a);return o&&a&&k(e,t,a),a},l=(i,e)=>(t,o)=>e(t,o,i);import{inject as d,injectable as f}from"inversify";import{configTypes as u}from"../../config/di/configTypes";import{pkiTypes as m}from"../../pki/di/pkiTypes";import{KeyUsage as y}from"../../pki/model/KeyUsage";import{SolanaContextTypes as c}from"../../shared/model/SolanaContextTypes";import{solanaTokenTypes as T}from"../../solanaToken/di/solanaTokenTypes";let s=class{constructor(e,t,o,a){this.dataSource=e;this.config=t;this._certificateLoader=o;this.logger=a("SolanaTokenContextLoader")}logger;canHandle(e,t){if(t!==c.SOLANA_TOKEN||typeof e!="object"||e===null||!("tokenInternalId"in e))return!1;const o=e.tokenInternalId;return typeof o=="string"&&o.length>0}async loadField(e){this.logger.debug("[loadField] Loading solana token context",{data:{input:e}});const{tokenInternalId:t,deviceModelId:o}=e,a=await this.dataSource.getTokenInfosPayload({tokenInternalId:t}),r=await this._certificateLoader.loadCertificate({keyId:"token_metadata_key",keyUsage:y.CoinMeta,targetDevice:o});return a.caseOf({Left:n=>(this.logger.error("[loadField] Error loading solana token context",{data:{error:n}}),{type:c.ERROR,error:n}),Right:n=>(this.logger.debug("[loadField] Successfully loaded solana token context",{data:{payload:this.pluckTokenData(n),certificate:r}}),{type:c.SOLANA_TOKEN,payload:this.pluckTokenData(n),certificate:r})})}pluckTokenData(e){const t=this.config.cal.mode||"prod";return{solanaTokenDescriptor:{data:e.descriptor.data,signature:e.descriptor.signatures[t]}}}};s=p([f(),l(0,d(T.SolanaTokenDataSource)),l(1,d(u.Config)),l(2,d(m.PkiCertificateLoader)),l(3,d(u.ContextModuleLoggerFactory))],s);export{s as SolanaTokenContextLoader};
2
2
  //# sourceMappingURL=SolanaTokenContextLoader.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/solanaToken/domain/SolanaTokenContextLoader.ts"],
4
- "sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { ContextFieldLoader } from \"@/shared/domain/ContextFieldLoader\";\nimport {\n SolanaContextTypes,\n SolanaTokenContextResult,\n SolanaTokenData,\n} from \"@/shared/model/SolanaContextTypes\";\nimport { SolanaTransactionContext } from \"@/solana/domain/solanaContextTypes\";\nimport {\n type SolanaTokenDataSource,\n type TokenDataResponse,\n} from \"@/solanaToken/data/SolanaTokenDataSource\";\nimport { solanaTokenTypes } from \"@/solanaToken/di/solanaTokenTypes\";\n\ntype SolanaTokenFieldInput = SolanaTransactionContext & {\n deviceModelId: DeviceModelId;\n tokenInternalId: string;\n};\n\n@injectable()\nexport class SolanaTokenContextLoader\n implements\n ContextFieldLoader<\n SolanaTokenFieldInput,\n SolanaContextTypes,\n SolanaTokenContextResult\n >\n{\n constructor(\n @inject(solanaTokenTypes.SolanaTokenDataSource)\n private readonly dataSource: SolanaTokenDataSource,\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n ) {}\n\n public canHandle(\n field: unknown,\n expectedType: SolanaContextTypes,\n ): field is SolanaTokenFieldInput {\n if (expectedType !== SolanaContextTypes.SOLANA_TOKEN) {\n return false;\n }\n\n if (\n typeof field !== \"object\" ||\n field === null ||\n !(\"tokenInternalId\" in field)\n ) {\n return false;\n }\n\n const tokenInternalId = (field as { tokenInternalId: unknown })\n .tokenInternalId;\n\n return typeof tokenInternalId === \"string\" && tokenInternalId.length > 0;\n }\n\n public async loadField(\n solanaTokenContextInput: SolanaTokenFieldInput,\n ): Promise<SolanaTokenContextResult> {\n const { tokenInternalId, deviceModelId } = solanaTokenContextInput;\n\n const payload = await this.dataSource.getTokenInfosPayload({\n tokenInternalId,\n });\n\n const certificate: PkiCertificate | undefined =\n await this._certificateLoader.loadCertificate({\n keyId: \"token_metadata_key\",\n keyUsage: KeyUsage.CoinMeta,\n targetDevice: deviceModelId,\n });\n\n return payload.caseOf({\n Left: (error): SolanaTokenContextResult => ({\n type: SolanaContextTypes.ERROR,\n error,\n }),\n Right: (value): SolanaTokenContextResult => ({\n type: SolanaContextTypes.SOLANA_TOKEN,\n payload: this.pluckTokenData(value),\n certificate,\n }),\n });\n }\n\n private pluckTokenData(tokenData: TokenDataResponse): SolanaTokenData {\n const signatureKind = this.config.cal.mode || \"prod\";\n return {\n solanaTokenDescriptor: {\n data: tokenData.descriptor.data,\n signature: tokenData.descriptor.signatures[signatureKind],\n },\n };\n }\n}\n"],
5
- "mappings": "iOACA,OAAS,UAAAA,EAAQ,cAAAC,MAAkB,YAEnC,OAAS,eAAAC,MAAmB,0BAE5B,OAAS,YAAAC,MAAgB,oBAEzB,OAAS,YAAAC,MAAgB,uBAGzB,OACE,sBAAAC,MAGK,oCAMP,OAAS,oBAAAC,MAAwB,oCAQ1B,IAAMC,EAAN,KAOP,CACE,YAEmBC,EAC4BC,EAE5BC,EACjB,CAJiB,gBAAAF,EAC4B,YAAAC,EAE5B,wBAAAC,CAChB,CAEI,UACLC,EACAC,EACgC,CAKhC,GAJIA,IAAiBC,EAAmB,cAKtC,OAAOF,GAAU,UACjBA,IAAU,MACV,EAAE,oBAAqBA,GAEvB,MAAO,GAGT,MAAMG,EAAmBH,EACtB,gBAEH,OAAO,OAAOG,GAAoB,UAAYA,EAAgB,OAAS,CACzE,CAEA,MAAa,UACXC,EACmC,CACnC,KAAM,CAAE,gBAAAD,EAAiB,cAAAE,CAAc,EAAID,EAErCE,EAAU,MAAM,KAAK,WAAW,qBAAqB,CACzD,gBAAAH,CACF,CAAC,EAEKI,EACJ,MAAM,KAAK,mBAAmB,gBAAgB,CAC5C,MAAO,qBACP,SAAUC,EAAS,SACnB,aAAcH,CAChB,CAAC,EAEH,OAAOC,EAAQ,OAAO,CACpB,KAAOG,IAAqC,CAC1C,KAAMP,EAAmB,MACzB,MAAAO,CACF,GACA,MAAQC,IAAqC,CAC3C,KAAMR,EAAmB,aACzB,QAAS,KAAK,eAAeQ,CAAK,EAClC,YAAAH,CACF,EACF,CAAC,CACH,CAEQ,eAAeI,EAA+C,CACpE,MAAMC,EAAgB,KAAK,OAAO,IAAI,MAAQ,OAC9C,MAAO,CACL,sBAAuB,CACrB,KAAMD,EAAU,WAAW,KAC3B,UAAWA,EAAU,WAAW,WAAWC,CAAa,CAC1D,CACF,CACF,CACF,EA5EahB,EAANiB,EAAA,CADNC,EAAW,EAUPC,EAAA,EAAAC,EAAOC,EAAiB,qBAAqB,GAE7CF,EAAA,EAAAC,EAAOE,EAAY,MAAM,GACzBH,EAAA,EAAAC,EAAOG,EAAS,oBAAoB,IAZ5BvB",
6
- "names": ["inject", "injectable", "configTypes", "pkiTypes", "KeyUsage", "SolanaContextTypes", "solanaTokenTypes", "SolanaTokenContextLoader", "dataSource", "config", "_certificateLoader", "field", "expectedType", "SolanaContextTypes", "tokenInternalId", "solanaTokenContextInput", "deviceModelId", "payload", "certificate", "KeyUsage", "error", "value", "tokenData", "signatureKind", "__decorateClass", "injectable", "__decorateParam", "inject", "solanaTokenTypes", "configTypes", "pkiTypes"]
4
+ "sourcesContent": ["import {\n DeviceModelId,\n LoggerPublisherService,\n} from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { ContextFieldLoader } from \"@/shared/domain/ContextFieldLoader\";\nimport {\n SolanaContextTypes,\n SolanaTokenContextResult,\n SolanaTokenData,\n} from \"@/shared/model/SolanaContextTypes\";\nimport { SolanaTransactionContext } from \"@/solana/domain/solanaContextTypes\";\nimport {\n type SolanaTokenDataSource,\n type TokenDataResponse,\n} from \"@/solanaToken/data/SolanaTokenDataSource\";\nimport { solanaTokenTypes } from \"@/solanaToken/di/solanaTokenTypes\";\n\ntype SolanaTokenFieldInput = SolanaTransactionContext & {\n deviceModelId: DeviceModelId;\n tokenInternalId: string;\n};\n\n@injectable()\nexport class SolanaTokenContextLoader\n implements\n ContextFieldLoader<\n SolanaTokenFieldInput,\n SolanaContextTypes,\n SolanaTokenContextResult\n >\n{\n private logger: LoggerPublisherService;\n\n constructor(\n @inject(solanaTokenTypes.SolanaTokenDataSource)\n private readonly dataSource: SolanaTokenDataSource,\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n @inject(configTypes.ContextModuleLoggerFactory)\n loggerFactory: (tag: string) => LoggerPublisherService,\n ) {\n this.logger = loggerFactory(\"SolanaTokenContextLoader\");\n }\n\n public canHandle(\n field: unknown,\n expectedType: SolanaContextTypes,\n ): field is SolanaTokenFieldInput {\n if (expectedType !== SolanaContextTypes.SOLANA_TOKEN) {\n return false;\n }\n\n if (\n typeof field !== \"object\" ||\n field === null ||\n !(\"tokenInternalId\" in field)\n ) {\n return false;\n }\n\n const tokenInternalId = (field as { tokenInternalId: unknown })\n .tokenInternalId;\n\n return typeof tokenInternalId === \"string\" && tokenInternalId.length > 0;\n }\n\n public async loadField(\n solanaTokenContextInput: SolanaTokenFieldInput,\n ): Promise<SolanaTokenContextResult> {\n this.logger.debug(\"[loadField] Loading solana token context\", {\n data: { input: solanaTokenContextInput },\n });\n const { tokenInternalId, deviceModelId } = solanaTokenContextInput;\n\n const payload = await this.dataSource.getTokenInfosPayload({\n tokenInternalId,\n });\n\n const certificate: PkiCertificate | undefined =\n await this._certificateLoader.loadCertificate({\n keyId: \"token_metadata_key\",\n keyUsage: KeyUsage.CoinMeta,\n targetDevice: deviceModelId,\n });\n\n return payload.caseOf({\n Left: (error): SolanaTokenContextResult => {\n this.logger.error(\"[loadField] Error loading solana token context\", {\n data: { error },\n });\n\n return {\n type: SolanaContextTypes.ERROR,\n error,\n };\n },\n Right: (value): SolanaTokenContextResult => {\n this.logger.debug(\n \"[loadField] Successfully loaded solana token context\",\n {\n data: { payload: this.pluckTokenData(value), certificate },\n },\n );\n\n return {\n type: SolanaContextTypes.SOLANA_TOKEN,\n payload: this.pluckTokenData(value),\n certificate,\n };\n },\n });\n }\n\n private pluckTokenData(tokenData: TokenDataResponse): SolanaTokenData {\n const signatureKind = this.config.cal.mode || \"prod\";\n return {\n solanaTokenDescriptor: {\n data: tokenData.descriptor.data,\n signature: tokenData.descriptor.signatures[signatureKind],\n },\n };\n }\n}\n"],
5
+ "mappings": "iOAIA,OAAS,UAAAA,EAAQ,cAAAC,MAAkB,YAEnC,OAAS,eAAAC,MAAmB,0BAE5B,OAAS,YAAAC,MAAgB,oBAEzB,OAAS,YAAAC,MAAgB,uBAGzB,OACE,sBAAAC,MAGK,oCAMP,OAAS,oBAAAC,MAAwB,oCAQ1B,IAAMC,EAAN,KAOP,CAGE,YAEmBC,EAC4BC,EAE5BC,EAEjBC,EACA,CANiB,gBAAAH,EAC4B,YAAAC,EAE5B,wBAAAC,EAIjB,KAAK,OAASC,EAAc,0BAA0B,CACxD,CAZQ,OAcD,UACLC,EACAC,EACgC,CAKhC,GAJIA,IAAiBC,EAAmB,cAKtC,OAAOF,GAAU,UACjBA,IAAU,MACV,EAAE,oBAAqBA,GAEvB,MAAO,GAGT,MAAMG,EAAmBH,EACtB,gBAEH,OAAO,OAAOG,GAAoB,UAAYA,EAAgB,OAAS,CACzE,CAEA,MAAa,UACXC,EACmC,CACnC,KAAK,OAAO,MAAM,2CAA4C,CAC5D,KAAM,CAAE,MAAOA,CAAwB,CACzC,CAAC,EACD,KAAM,CAAE,gBAAAD,EAAiB,cAAAE,CAAc,EAAID,EAErCE,EAAU,MAAM,KAAK,WAAW,qBAAqB,CACzD,gBAAAH,CACF,CAAC,EAEKI,EACJ,MAAM,KAAK,mBAAmB,gBAAgB,CAC5C,MAAO,qBACP,SAAUC,EAAS,SACnB,aAAcH,CAChB,CAAC,EAEH,OAAOC,EAAQ,OAAO,CACpB,KAAOG,IACL,KAAK,OAAO,MAAM,iDAAkD,CAClE,KAAM,CAAE,MAAAA,CAAM,CAChB,CAAC,EAEM,CACL,KAAMP,EAAmB,MACzB,MAAAO,CACF,GAEF,MAAQC,IACN,KAAK,OAAO,MACV,uDACA,CACE,KAAM,CAAE,QAAS,KAAK,eAAeA,CAAK,EAAG,YAAAH,CAAY,CAC3D,CACF,EAEO,CACL,KAAML,EAAmB,aACzB,QAAS,KAAK,eAAeQ,CAAK,EAClC,YAAAH,CACF,EAEJ,CAAC,CACH,CAEQ,eAAeI,EAA+C,CACpE,MAAMC,EAAgB,KAAK,OAAO,IAAI,MAAQ,OAC9C,MAAO,CACL,sBAAuB,CACrB,KAAMD,EAAU,WAAW,KAC3B,UAAWA,EAAU,WAAW,WAAWC,CAAa,CAC1D,CACF,CACF,CACF,EApGajB,EAANkB,EAAA,CADNC,EAAW,EAYPC,EAAA,EAAAC,EAAOC,EAAiB,qBAAqB,GAE7CF,EAAA,EAAAC,EAAOE,EAAY,MAAM,GACzBH,EAAA,EAAAC,EAAOG,EAAS,oBAAoB,GAEpCJ,EAAA,EAAAC,EAAOE,EAAY,0BAA0B,IAhBrCvB",
6
+ "names": ["inject", "injectable", "configTypes", "pkiTypes", "KeyUsage", "SolanaContextTypes", "solanaTokenTypes", "SolanaTokenContextLoader", "dataSource", "config", "_certificateLoader", "loggerFactory", "field", "expectedType", "SolanaContextTypes", "tokenInternalId", "solanaTokenContextInput", "deviceModelId", "payload", "certificate", "KeyUsage", "error", "value", "tokenData", "signatureKind", "__decorateClass", "injectable", "__decorateParam", "inject", "solanaTokenTypes", "configTypes", "pkiTypes"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{DeviceModelId as y}from"@ledgerhq/device-management-kit";import{Left as m,Right as f}from"purify-ts";import{beforeEach as g,describe as p,expect as o,it as s,vi as t}from"vitest";import{KeyUsage as T}from"../../pki/model/KeyUsage";import{SolanaContextTypes as d}from"../../shared/model/SolanaContextTypes";import{SolanaTokenContextLoader as I}from"./SolanaTokenContextLoader";p("SolanaTokenContextLoader",()=>{let l,i;const c=new Uint8Array([240,202,204,26]),n={descriptor:{data:{symbol:"SOL",name:"Solana",decimals:9},signatures:{prod:"prod-sig",test:"test-sig"}}},k={tokenInternalId:"token-1",deviceModelId:y.FLEX};g(()=>{t.restoreAllMocks(),l={getTokenInfosPayload:t.fn()},i={loadCertificate:t.fn()}});const r=e=>{const a={cal:{mode:e}};return new I(l,a,i)};p("canHandle",()=>{s("returns true when tokenInternalId is provided",()=>{const e=r("prod");o(e.canHandle({tokenInternalId:"abc123"},d.SOLANA_TOKEN)).toBe(!0)}),s("returns false when tokenInternalId is missing or falsy",()=>{const e=r("prod");o(e.canHandle({tokenInternalId:""},d.SOLANA_TOKEN)).toBe(!1),o(e.canHandle({tokenInternalId:void 0},d.SOLANA_TOKEN)).toBe(!1),o(e.canHandle({},d.SOLANA_TOKEN)).toBe(!1)})}),p("loadField",()=>{s("returns an error when datasource returns Left(error) (certificate still retrieved)",async()=>{const e=r("prod"),a=new Error("datasource failed");t.spyOn(l,"getTokenInfosPayload").mockResolvedValue(m(a)),t.spyOn(i,"loadCertificate").mockResolvedValue({keyUsageNumber:0,payload:c});const u=await e.loadField(k);o(l.getTokenInfosPayload).toHaveBeenCalledWith({tokenInternalId:"token-1"}),o(i.loadCertificate).toHaveBeenCalledWith({keyId:"token_metadata_key",keyUsage:T.CoinMeta,targetDevice:k.deviceModelId}),o(u).toEqual({type:d.ERROR,error:a})}),s("returns SOLANA_TOKEN with prod signature by default (falsy mode) and includes certificate",async()=>{const e=r("");t.spyOn(l,"getTokenInfosPayload").mockResolvedValue(f(n)),t.spyOn(i,"loadCertificate").mockResolvedValue({keyUsageNumber:0,payload:c});const a=await e.loadField({...k,tokenInternalId:"token-2"});o(a).toEqual({type:d.SOLANA_TOKEN,payload:{solanaTokenDescriptor:{data:n.descriptor.data,signature:"prod-sig"}},certificate:{keyUsageNumber:0,payload:c}})}),s("returns SOLANA_TOKEN with signature matching config.cal.mode",async()=>{const e=r("test");t.spyOn(l,"getTokenInfosPayload").mockResolvedValue(f(n)),t.spyOn(i,"loadCertificate").mockResolvedValue({keyUsageNumber:1,payload:c});const a=await e.loadField({...k,tokenInternalId:"token-3"});o(a).toEqual({type:d.SOLANA_TOKEN,payload:{solanaTokenDescriptor:{data:n.descriptor.data,signature:"test-sig"}},certificate:{keyUsageNumber:1,payload:c}})}),s("works even if certificate loader returns undefined (certificate omitted)",async()=>{const e=r("prod");t.spyOn(l,"getTokenInfosPayload").mockResolvedValue(f(n)),t.spyOn(i,"loadCertificate").mockResolvedValue(void 0);const a=await e.loadField(k);o(a).toEqual({type:d.SOLANA_TOKEN,payload:{solanaTokenDescriptor:{data:n.descriptor.data,signature:"prod-sig"}},certificate:void 0})})}),p("pluckTokenData (private)",()=>{s("picks the signature for the configured mode",()=>{const e=r("test"),u=e.pluckTokenData.bind(e)(n);o(u).toEqual({solanaTokenDescriptor:{data:n.descriptor.data,signature:"test-sig"}})}),s("falls back to 'prod' when config.cal.mode is falsy",()=>{const a=r(void 0).pluckTokenData(n);o(a).toEqual({solanaTokenDescriptor:{data:n.descriptor.data,signature:"prod-sig"}})})})});
1
+ import{DeviceModelId as y}from"@ledgerhq/device-management-kit";import{Left as m,Right as f}from"purify-ts";import{beforeEach as g,describe as p,expect as t,it as s,vi as a}from"vitest";import{KeyUsage as T}from"../../pki/model/KeyUsage";import{SolanaContextTypes as d}from"../../shared/model/SolanaContextTypes";import{SolanaTokenContextLoader as I}from"./SolanaTokenContextLoader";const O=()=>({debug:a.fn(),info:a.fn(),warn:a.fn(),error:a.fn(),subscribers:[]});p("SolanaTokenContextLoader",()=>{let l,i;const c=new Uint8Array([240,202,204,26]),n={descriptor:{data:{symbol:"SOL",name:"Solana",decimals:9},signatures:{prod:"prod-sig",test:"test-sig"}}},k={tokenInternalId:"token-1",deviceModelId:y.FLEX};g(()=>{a.restoreAllMocks(),l={getTokenInfosPayload:a.fn()},i={loadCertificate:a.fn()}});const r=e=>{const o={cal:{mode:e}};return new I(l,o,i,O)};p("canHandle",()=>{s("returns true when tokenInternalId is provided",()=>{const e=r("prod");t(e.canHandle({tokenInternalId:"abc123"},d.SOLANA_TOKEN)).toBe(!0)}),s("returns false when tokenInternalId is missing or falsy",()=>{const e=r("prod");t(e.canHandle({tokenInternalId:""},d.SOLANA_TOKEN)).toBe(!1),t(e.canHandle({tokenInternalId:void 0},d.SOLANA_TOKEN)).toBe(!1),t(e.canHandle({},d.SOLANA_TOKEN)).toBe(!1)})}),p("loadField",()=>{s("returns an error when datasource returns Left(error) (certificate still retrieved)",async()=>{const e=r("prod"),o=new Error("datasource failed");a.spyOn(l,"getTokenInfosPayload").mockResolvedValue(m(o)),a.spyOn(i,"loadCertificate").mockResolvedValue({keyUsageNumber:0,payload:c});const u=await e.loadField(k);t(l.getTokenInfosPayload).toHaveBeenCalledWith({tokenInternalId:"token-1"}),t(i.loadCertificate).toHaveBeenCalledWith({keyId:"token_metadata_key",keyUsage:T.CoinMeta,targetDevice:k.deviceModelId}),t(u).toEqual({type:d.ERROR,error:o})}),s("returns SOLANA_TOKEN with prod signature by default (falsy mode) and includes certificate",async()=>{const e=r("");a.spyOn(l,"getTokenInfosPayload").mockResolvedValue(f(n)),a.spyOn(i,"loadCertificate").mockResolvedValue({keyUsageNumber:0,payload:c});const o=await e.loadField({...k,tokenInternalId:"token-2"});t(o).toEqual({type:d.SOLANA_TOKEN,payload:{solanaTokenDescriptor:{data:n.descriptor.data,signature:"prod-sig"}},certificate:{keyUsageNumber:0,payload:c}})}),s("returns SOLANA_TOKEN with signature matching config.cal.mode",async()=>{const e=r("test");a.spyOn(l,"getTokenInfosPayload").mockResolvedValue(f(n)),a.spyOn(i,"loadCertificate").mockResolvedValue({keyUsageNumber:1,payload:c});const o=await e.loadField({...k,tokenInternalId:"token-3"});t(o).toEqual({type:d.SOLANA_TOKEN,payload:{solanaTokenDescriptor:{data:n.descriptor.data,signature:"test-sig"}},certificate:{keyUsageNumber:1,payload:c}})}),s("works even if certificate loader returns undefined (certificate omitted)",async()=>{const e=r("prod");a.spyOn(l,"getTokenInfosPayload").mockResolvedValue(f(n)),a.spyOn(i,"loadCertificate").mockResolvedValue(void 0);const o=await e.loadField(k);t(o).toEqual({type:d.SOLANA_TOKEN,payload:{solanaTokenDescriptor:{data:n.descriptor.data,signature:"prod-sig"}},certificate:void 0})})}),p("pluckTokenData (private)",()=>{s("picks the signature for the configured mode",()=>{const e=r("test"),u=e.pluckTokenData.bind(e)(n);t(u).toEqual({solanaTokenDescriptor:{data:n.descriptor.data,signature:"test-sig"}})}),s("falls back to 'prod' when config.cal.mode is falsy",()=>{const o=r(void 0).pluckTokenData(n);t(o).toEqual({solanaTokenDescriptor:{data:n.descriptor.data,signature:"prod-sig"}})})})});
2
2
  //# sourceMappingURL=SolanaTokenContextLoader.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/solanaToken/domain/SolanaTokenContextLoader.test.ts"],
4
- "sourcesContent": ["/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\nimport { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\nimport { beforeEach, describe, expect, it, vi } from \"vitest\";\n\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport type { PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { SolanaContextTypes } from \"@/shared/model/SolanaContextTypes\";\nimport type { SolanaTransactionContext } from \"@/solana/domain/solanaContextTypes\";\nimport {\n type SolanaTokenDataSource,\n type TokenDataResponse,\n} from \"@/solanaToken/data/SolanaTokenDataSource\";\n\nimport { SolanaTokenContextLoader } from \"./SolanaTokenContextLoader\";\n\ndescribe(\"SolanaTokenContextLoader\", () => {\n let mockDataSource: SolanaTokenDataSource;\n let mockCertLoader: PkiCertificateLoader;\n\n const bytes = new Uint8Array([0xf0, 0xca, 0xcc, 0x1a]);\n\n const tokenDataResponse: TokenDataResponse = {\n descriptor: {\n // The loader just forwards this; exact shape isn't important for the test\n data: { symbol: \"SOL\", name: \"Solana\", decimals: 9 } as any,\n signatures: {\n prod: \"prod-sig\",\n test: \"test-sig\",\n } as any,\n },\n } as any;\n\n const baseCtx = {\n tokenInternalId: \"token-1\",\n deviceModelId: DeviceModelId.FLEX,\n };\n\n beforeEach(() => {\n vi.restoreAllMocks();\n\n mockDataSource = {\n getTokenInfosPayload: vi.fn(),\n } as unknown as SolanaTokenDataSource;\n\n mockCertLoader = {\n loadCertificate: vi.fn(),\n } as unknown as PkiCertificateLoader;\n });\n\n const makeLoader = (mode?: string) => {\n const config = { cal: { mode } } as unknown as ContextModuleConfig;\n return new SolanaTokenContextLoader(mockDataSource, config, mockCertLoader);\n };\n\n describe(\"canHandle\", () => {\n it(\"returns true when tokenInternalId is provided\", () => {\n const loader = makeLoader(\"prod\");\n\n expect(\n loader.canHandle(\n {\n tokenInternalId: \"abc123\",\n } as SolanaTransactionContext,\n SolanaContextTypes.SOLANA_TOKEN,\n ),\n ).toBe(true);\n });\n\n it(\"returns false when tokenInternalId is missing or falsy\", () => {\n const loader = makeLoader(\"prod\");\n\n expect(\n loader.canHandle(\n { tokenInternalId: \"\" } as any,\n SolanaContextTypes.SOLANA_TOKEN,\n ),\n ).toBe(false);\n expect(\n loader.canHandle(\n { tokenInternalId: undefined } as any,\n SolanaContextTypes.SOLANA_TOKEN,\n ),\n ).toBe(false);\n expect(loader.canHandle({} as any, SolanaContextTypes.SOLANA_TOKEN)).toBe(\n false,\n );\n });\n });\n\n describe(\"loadField\", () => {\n it(\"returns an error when datasource returns Left(error) (certificate still retrieved)\", async () => {\n const loader = makeLoader(\"prod\");\n const error = new Error(\"datasource failed\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(error),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 0,\n payload: bytes,\n });\n\n const result = await loader.loadField(baseCtx);\n\n expect(mockDataSource.getTokenInfosPayload).toHaveBeenCalledWith({\n tokenInternalId: \"token-1\",\n });\n expect(mockCertLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: \"token_metadata_key\",\n keyUsage: KeyUsage.CoinMeta,\n targetDevice: baseCtx.deviceModelId,\n });\n expect(result).toEqual({\n type: SolanaContextTypes.ERROR,\n error,\n });\n });\n\n it(\"returns SOLANA_TOKEN with prod signature by default (falsy mode) and includes certificate\", async () => {\n const loader = makeLoader(\"\"); // falsy -> default 'prod'\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 0,\n payload: bytes,\n });\n\n const result = await loader.loadField({\n ...baseCtx,\n tokenInternalId: \"token-2\",\n });\n\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_TOKEN,\n payload: {\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"prod-sig\",\n },\n },\n certificate: { keyUsageNumber: 0, payload: bytes },\n });\n });\n\n it(\"returns SOLANA_TOKEN with signature matching config.cal.mode\", async () => {\n const loader = makeLoader(\"test\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 1,\n payload: bytes,\n });\n\n const result = await loader.loadField({\n ...baseCtx,\n tokenInternalId: \"token-3\",\n });\n\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_TOKEN,\n payload: {\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"test-sig\",\n },\n },\n certificate: { keyUsageNumber: 1, payload: bytes },\n });\n });\n\n it(\"works even if certificate loader returns undefined (certificate omitted)\", async () => {\n const loader = makeLoader(\"prod\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue(undefined);\n\n const result = await loader.loadField(baseCtx);\n\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_TOKEN,\n payload: {\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"prod-sig\",\n },\n },\n certificate: undefined,\n });\n });\n });\n\n describe(\"pluckTokenData (private)\", () => {\n it(\"picks the signature for the configured mode\", () => {\n const loader = makeLoader(\"test\");\n const pluck = (loader as any).pluckTokenData.bind(loader);\n\n const result = pluck(tokenDataResponse);\n\n expect(result).toEqual({\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"test-sig\",\n },\n });\n });\n\n it(\"falls back to 'prod' when config.cal.mode is falsy\", () => {\n const loader = makeLoader(undefined as any);\n const result = (loader as any).pluckTokenData(tokenDataResponse);\n\n expect(result).toEqual({\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"prod-sig\",\n },\n });\n });\n });\n});\n"],
5
- "mappings": "AAIA,OAAS,iBAAAA,MAAqB,kCAC9B,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAC5B,OAAS,cAAAC,EAAY,YAAAC,EAAU,UAAAC,EAAQ,MAAAC,EAAI,MAAAC,MAAU,SAIrD,OAAS,YAA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ect", "it", "vi", "KeyUsage", "SolanaContextTypes", "SolanaTokenContextLoader", "mockDataSource", "mockCertLoader", "bytes", "tokenDataResponse", "baseCtx", "makeLoader", "mode", "config", "loader", "error", "result"]
4
+ "sourcesContent": ["/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\nimport { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\nimport { beforeEach, describe, expect, it, vi } from \"vitest\";\n\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport type { PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { SolanaContextTypes } from \"@/shared/model/SolanaContextTypes\";\nimport type { SolanaTransactionContext } from \"@/solana/domain/solanaContextTypes\";\nimport {\n type SolanaTokenDataSource,\n type TokenDataResponse,\n} from \"@/solanaToken/data/SolanaTokenDataSource\";\n\nimport { SolanaTokenContextLoader } from \"./SolanaTokenContextLoader\";\n\nconst mockLoggerFactory = () => ({\n debug: vi.fn(),\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n subscribers: [],\n});\n\ndescribe(\"SolanaTokenContextLoader\", () => {\n let mockDataSource: SolanaTokenDataSource;\n let mockCertLoader: PkiCertificateLoader;\n\n const bytes = new Uint8Array([0xf0, 0xca, 0xcc, 0x1a]);\n\n const tokenDataResponse: TokenDataResponse = {\n descriptor: {\n // The loader just forwards this; exact shape isn't important for the test\n data: { symbol: \"SOL\", name: \"Solana\", decimals: 9 } as any,\n signatures: {\n prod: \"prod-sig\",\n test: \"test-sig\",\n } as any,\n },\n } as any;\n\n const baseCtx = {\n tokenInternalId: \"token-1\",\n deviceModelId: DeviceModelId.FLEX,\n };\n\n beforeEach(() => {\n vi.restoreAllMocks();\n\n mockDataSource = {\n getTokenInfosPayload: vi.fn(),\n } as unknown as SolanaTokenDataSource;\n\n mockCertLoader = {\n loadCertificate: vi.fn(),\n } as unknown as PkiCertificateLoader;\n });\n\n const makeLoader = (mode?: string) => {\n const config = { cal: { mode } } as unknown as ContextModuleConfig;\n return new SolanaTokenContextLoader(\n mockDataSource,\n config,\n mockCertLoader,\n mockLoggerFactory,\n );\n };\n\n describe(\"canHandle\", () => {\n it(\"returns true when tokenInternalId is provided\", () => {\n const loader = makeLoader(\"prod\");\n\n expect(\n loader.canHandle(\n {\n tokenInternalId: \"abc123\",\n } as SolanaTransactionContext,\n SolanaContextTypes.SOLANA_TOKEN,\n ),\n ).toBe(true);\n });\n\n it(\"returns false when tokenInternalId is missing or falsy\", () => {\n const loader = makeLoader(\"prod\");\n\n expect(\n loader.canHandle(\n { tokenInternalId: \"\" } as any,\n SolanaContextTypes.SOLANA_TOKEN,\n ),\n ).toBe(false);\n expect(\n loader.canHandle(\n { tokenInternalId: undefined } as any,\n SolanaContextTypes.SOLANA_TOKEN,\n ),\n ).toBe(false);\n expect(loader.canHandle({} as any, SolanaContextTypes.SOLANA_TOKEN)).toBe(\n false,\n );\n });\n });\n\n describe(\"loadField\", () => {\n it(\"returns an error when datasource returns Left(error) (certificate still retrieved)\", async () => {\n const loader = makeLoader(\"prod\");\n const error = new Error(\"datasource failed\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(error),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 0,\n payload: bytes,\n });\n\n const result = await loader.loadField(baseCtx);\n\n expect(mockDataSource.getTokenInfosPayload).toHaveBeenCalledWith({\n tokenInternalId: \"token-1\",\n });\n expect(mockCertLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: \"token_metadata_key\",\n keyUsage: KeyUsage.CoinMeta,\n targetDevice: baseCtx.deviceModelId,\n });\n expect(result).toEqual({\n type: SolanaContextTypes.ERROR,\n error,\n });\n });\n\n it(\"returns SOLANA_TOKEN with prod signature by default (falsy mode) and includes certificate\", async () => {\n const loader = makeLoader(\"\"); // falsy -> default 'prod'\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 0,\n payload: bytes,\n });\n\n const result = await loader.loadField({\n ...baseCtx,\n tokenInternalId: \"token-2\",\n });\n\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_TOKEN,\n payload: {\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"prod-sig\",\n },\n },\n certificate: { keyUsageNumber: 0, payload: bytes },\n });\n });\n\n it(\"returns SOLANA_TOKEN with signature matching config.cal.mode\", async () => {\n const loader = makeLoader(\"test\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 1,\n payload: bytes,\n });\n\n const result = await loader.loadField({\n ...baseCtx,\n tokenInternalId: \"token-3\",\n });\n\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_TOKEN,\n payload: {\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"test-sig\",\n },\n },\n certificate: { keyUsageNumber: 1, payload: bytes },\n });\n });\n\n it(\"works even if certificate loader returns undefined (certificate omitted)\", async () => {\n const loader = makeLoader(\"prod\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue(undefined);\n\n const result = await loader.loadField(baseCtx);\n\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_TOKEN,\n payload: {\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"prod-sig\",\n },\n },\n certificate: undefined,\n });\n });\n });\n\n describe(\"pluckTokenData (private)\", () => {\n it(\"picks the signature for the configured mode\", () => {\n const loader = makeLoader(\"test\");\n const pluck = (loader as any).pluckTokenData.bind(loader);\n\n const result = pluck(tokenDataResponse);\n\n expect(result).toEqual({\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"test-sig\",\n },\n });\n });\n\n it(\"falls back to 'prod' when config.cal.mode is falsy\", () => {\n const loader = makeLoader(undefined as any);\n const result = (loader as any).pluckTokenData(tokenDataResponse);\n\n expect(result).toEqual({\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"prod-sig\",\n },\n });\n });\n });\n});\n"],
5
+ "mappings": "AAIA,OAAS,iBAAAA,MAAqB,kCAC9B,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAC5B,OAAS,cAAAC,EAAY,YAAAC,EAAU,UAAAC,EAAQ,MAAAC,EAAI,MAAAC,MAAU,SAIrD,OAAS,YAAAC,MAAgB,uBACzB,OAAS,sBAAAC,MAA0B,oCAOnC,OAAS,4BAAAC,MAAgC,6BAEzC,MAAMC,EAAoB,KAAO,CAC/B,MAAOJ,EAAG,GAAG,EACb,KAAMA,EAAG,GAAG,EACZ,KAAMA,EAAG,GAAG,EACZ,MAAOA,EAAG,GAAG,EACb,YAAa,CAAC,CAChB,GAEAH,EAAS,2BAA4B,IAAM,CACzC,IAAIQ,EACAC,EAEJ,MAAMC,EAAQ,IAAI,WAAW,CAAC,IAAM,IAAM,IAAM,EAAI,CAAC,EAE/CC,EAAuC,CAC3C,WAAY,CAEV,KAAM,CAAE,OAAQ,MAAO,KAAM,SAAU,SAAU,CAAE,EACnD,WAAY,CACV,KAAM,WACN,KAAM,UACR,CACF,CACF,EAEMC,EAAU,CACd,gBAAiB,UACjB,cAAehB,EAAc,IAC/B,EAEAG,EAAW,IAAM,CACfI,EAAG,gBAAgB,EAEnBK,EAAiB,CACf,qBAAsBL,EAAG,GAAG,CAC9B,EAEAM,EAAiB,CACf,gBAAiBN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MAAMS,EAAS,MAAMF,EAAO,UAAUJ,CAAO,EAE7CX,EAAOiB,CAAM,EAAE,QAAQ,CACrB,KAAMb,EAAmB,aACzB,QAAS,CACP,sBAAuB,CACrB,KAAMM,EAAkB,WAAW,KACnC,UAAW,UACb,CACF,EACA,YAAa,MACf,CAAC,CACH,CAAC,CACH,CAAC,EAEDX,EAAS,2BAA4B,IAAM,CACzCE,EAAG,8CAA+C,IAAM,CACtD,MAAMc,EAASH,EAAW,MAAM,EAG1BK,EAFSF,EAAe,eAAe,KAAKA,CAAM,EAEnCL,CAAiB,EAEtCV,EAAOiB,CAAM,EAAE,QAAQ,CACrB,sBAAuB,CACrB,KAAMP,EAAkB,WAAW,KACnC,UAAW,UACb,CACF,CAAC,CACH,CAAC,EAEDT,EAAG,qDAAsD,IAAM,CAE7D,MAAMgB,EADSL,EAAW,MAAgB,EACX,eAAeF,CAAiB,EAE/DV,EAAOiB,CAAM,EAAE,QAAQ,CACrB,sBAAuB,CACrB,KAAMP,EAAkB,WAAW,KACnC,UAAW,UACb,CACF,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["DeviceModelId", "Left", "Right", "beforeEach", "describe", "expect", "it", "vi", "KeyUsage", "SolanaContextTypes", "SolanaTokenContextLoader", "mockLoggerFactory", "mockDataSource", "mockCertLoader", "bytes", "tokenDataResponse", "baseCtx", "makeLoader", "mode", "config", "loader", "error", "result"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var c=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var l=(o,e,a,t)=>{for(var n=t>1?void 0:t?y(e,a):e,i=o.length-1,d;i>=0;i--)(d=o[i])&&(n=(t?d(e,a,n):d(n))||n);return t&&n&&c(e,a,n),n},s=(o,e)=>(a,t)=>e(a,t,o);import{inject as m,injectable as u}from"inversify";import{ClearSignContextType as p}from"../../shared/model/ClearSignContext";import{tokenTypes as C}from"../../token/di/tokenTypes";let r=class{constructor(e){this._dataSource=e}canHandle(e,a){return a===p.TOKEN&&typeof e=="object"&&e!==null&&"chainId"in e&&"address"in e}async loadField(e){return(await this._dataSource.getTokenInfosPayload({address:e.address,chainId:e.chainId})).caseOf({Left:t=>({type:p.ERROR,error:t}),Right:t=>({type:p.TOKEN,payload:t})})}};r=l([u(),s(0,m(C.TokenDataSource))],r);export{r as TokenContextFieldLoader};
1
+ var m=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var l=(i,e,o,a)=>{for(var t=a>1?void 0:a?f(e,o):e,d=i.length-1,n;d>=0;d--)(n=i[d])&&(t=(a?n(e,o,t):n(t))||t);return a&&t&&m(e,o,t),t},c=(i,e)=>(o,a)=>e(o,a,i);import{inject as s,injectable as y}from"inversify";import{pkiTypes as I}from"../../pki/di/pkiTypes";import{KeyId as C}from"../../pki/model/KeyId";import{KeyUsage as k}from"../../pki/model/KeyUsage";import{ClearSignContextType as p}from"../../shared/model/ClearSignContext";import{tokenTypes as g}from"../../token/di/tokenTypes";let r=class{constructor(e,o){this._dataSource=e;this._certificateLoader=o}canHandle(e,o){return o===p.TOKEN&&typeof e=="object"&&e!==null&&"chainId"in e&&"address"in e&&"deviceModelId"in e&&e.deviceModelId!==void 0}async loadField(e){const o=await this._dataSource.getTokenInfosPayload({address:e.address,chainId:e.chainId}),a=await this._certificateLoader.loadCertificate({keyId:C.Erc20MetadataKey,keyUsage:k.CoinMeta,targetDevice:e.deviceModelId});return o.caseOf({Left:t=>({type:p.ERROR,error:t}),Right:t=>({type:p.TOKEN,payload:t,certificate:a})})}};r=l([y(),c(0,s(g.TokenDataSource)),c(1,s(I.PkiCertificateLoader))],r);export{r as TokenContextFieldLoader};
2
2
  //# sourceMappingURL=TokenContextFieldLoader.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/token/domain/TokenContextFieldLoader.ts"],
4
- "sourcesContent": ["import { inject, injectable } from \"inversify\";\n\nimport { type ContextFieldLoader } from \"@/shared/domain/ContextFieldLoader\";\nimport {\n type ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { type TokenDataSource } from \"@/token/data/TokenDataSource\";\nimport { tokenTypes } from \"@/token/di/tokenTypes\";\n\nexport type TokenFieldInput = {\n chainId: number;\n address: string;\n};\n\n@injectable()\nexport class TokenContextFieldLoader\n implements ContextFieldLoader<TokenFieldInput>\n{\n constructor(\n @inject(tokenTypes.TokenDataSource) private _dataSource: TokenDataSource,\n ) {}\n\n canHandle(\n input: unknown,\n expectedType: ClearSignContextType,\n ): input is TokenFieldInput {\n return (\n expectedType === ClearSignContextType.TOKEN &&\n typeof input === \"object\" &&\n input !== null &&\n \"chainId\" in input &&\n \"address\" in input\n );\n }\n\n async loadField(input: TokenFieldInput): Promise<ClearSignContext> {\n const payload = await this._dataSource.getTokenInfosPayload({\n address: input.address,\n chainId: input.chainId,\n });\n return 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"],
5
- "mappings": "iOAAA,OAAS,UAAAA,EAAQ,cAAAC,MAAkB,YAGnC,OAEE,wBAAAC,MACK,kCAEP,OAAS,cAAAC,MAAkB,wBAQpB,IAAMC,EAAN,KAEP,CACE,YAC8CC,EAC5C,CAD4C,iBAAAA,CAC3C,CAEH,UACEC,EACAC,EAC0B,CAC1B,OACEA,IAAiBC,EAAqB,OACtC,OAAOF,GAAU,UACjBA,IAAU,MACV,YAAaA,GACb,YAAaA,CAEjB,CAEA,MAAM,UAAUA,EAAmD,CAKjE,OAJgB,MAAM,KAAK,YAAY,qBAAqB,CAC1D,QAASA,EAAM,QACf,QAASA,EAAM,OACjB,CAAC,GACc,OAAO,CACpB,KAAOG,IAA6B,CAClC,KAAMD,EAAqB,MAC3B,MAAAC,CACF,GACA,MAAQC,IAA6B,CACnC,KAAMF,EAAqB,MAC3B,QAASE,CACX,EACF,CAAC,CACH,CACF,EApCaN,EAANO,EAAA,CADNC,EAAW,EAKPC,EAAA,EAAAC,EAAOC,EAAW,eAAe,IAJzBX",
6
- "names": ["inject", "injectable", "ClearSignContextType", "tokenTypes", "TokenContextFieldLoader", "_dataSource", "input", "expectedType", "ClearSignContextType", "error", "value", "__decorateClass", "injectable", "__decorateParam", "inject", "tokenTypes"]
4
+ "sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { type ContextFieldLoader } from \"@/shared/domain/ContextFieldLoader\";\nimport {\n type ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { type TokenDataSource } from \"@/token/data/TokenDataSource\";\nimport { tokenTypes } from \"@/token/di/tokenTypes\";\n\nexport type TokenFieldInput = {\n chainId: number;\n address: string;\n deviceModelId: DeviceModelId;\n};\n\n@injectable()\nexport class TokenContextFieldLoader\n implements ContextFieldLoader<TokenFieldInput>\n{\n constructor(\n @inject(tokenTypes.TokenDataSource) private _dataSource: TokenDataSource,\n @inject(pkiTypes.PkiCertificateLoader)\n private _certificateLoader: PkiCertificateLoader,\n ) {}\n\n canHandle(\n input: unknown,\n expectedType: ClearSignContextType,\n ): input is TokenFieldInput {\n return (\n expectedType === ClearSignContextType.TOKEN &&\n typeof input === \"object\" &&\n input !== null &&\n \"chainId\" in input &&\n \"address\" in input &&\n \"deviceModelId\" in input &&\n input.deviceModelId !== undefined\n );\n }\n\n async loadField(input: TokenFieldInput): Promise<ClearSignContext> {\n const payload = await this._dataSource.getTokenInfosPayload({\n address: input.address,\n chainId: input.chainId,\n });\n\n // Try to fetch the certificate if available\n const certificate = await this._certificateLoader.loadCertificate({\n keyId: KeyId.Erc20MetadataKey,\n keyUsage: KeyUsage.CoinMeta,\n targetDevice: input.deviceModelId,\n });\n\n return 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 certificate,\n }),\n });\n }\n}\n"],
5
+ "mappings": "iOACA,OAAS,UAAAA,EAAQ,cAAAC,MAAkB,YAEnC,OAAS,YAAAC,MAAgB,oBAEzB,OAAS,SAAAC,MAAa,oBACtB,OAAS,YAAAC,MAAgB,uBAEzB,OAEE,wBAAAC,MACK,kCAEP,OAAS,cAAAC,MAAkB,wBASpB,IAAMC,EAAN,KAEP,CACE,YAC8CC,EAEpCC,EACR,CAH4C,iBAAAD,EAEpC,wBAAAC,CACP,CAEH,UACEC,EACAC,EAC0B,CAC1B,OACEA,IAAiBC,EAAqB,OACtC,OAAOF,GAAU,UACjBA,IAAU,MACV,YAAaA,GACb,YAAaA,GACb,kBAAmBA,GACnBA,EAAM,gBAAkB,MAE5B,CAEA,MAAM,UAAUA,EAAmD,CACjE,MAAMG,EAAU,MAAM,KAAK,YAAY,qBAAqB,CAC1D,QAASH,EAAM,QACf,QAASA,EAAM,OACjB,CAAC,EAGKI,EAAc,MAAM,KAAK,mBAAmB,gBAAgB,CAChE,MAAOC,EAAM,iBACb,SAAUC,EAAS,SACnB,aAAcN,EAAM,aACtB,CAAC,EAED,OAAOG,EAAQ,OAAO,CACpB,KAAOI,IAA6B,CAClC,KAAML,EAAqB,MAC3B,MAAAK,CACF,GACA,MAAQC,IAA6B,CACnC,KAAMN,EAAqB,MAC3B,QAASM,EACT,YAAAJ,CACF,EACF,CAAC,CACH,CACF,EAjDaP,EAANY,EAAA,CADNC,EAAW,EAKPC,EAAA,EAAAC,EAAOC,EAAW,eAAe,GACjCF,EAAA,EAAAC,EAAOE,EAAS,oBAAoB,IAL5BjB",
6
+ "names": ["inject", "injectable", "pkiTypes", "KeyId", "KeyUsage", "ClearSignContextType", "tokenTypes", "TokenContextFieldLoader", "_dataSource", "_certificateLoader", "input", "expectedType", "ClearSignContextType", "payload", "certificate", "KeyId", "KeyUsage", "error", "value", "__decorateClass", "injectable", "__decorateParam", "inject", "tokenTypes", "pkiTypes"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{Left as r,Right as l}from"purify-ts";import{ClearSignContextType as d}from"../../shared/model/ClearSignContext";import{TokenContextFieldLoader as i}from"../../token/domain/TokenContextFieldLoader";describe("TokenContextFieldLoader",()=>{const o={getTokenInfosPayload:vi.fn()},t=new i(o),a={kind:"TOKEN",chainId:1,address:"0x1234567890abcdef"},s="0x123456789abcdef0";beforeEach(()=>{vi.resetAllMocks()}),describe("canHandle",()=>{it("should return true for valid token field",()=>{const e={kind:"TOKEN",chainId:1,address:"0x1234567890abcdef"};expect(t.canHandle(e,d.TOKEN)).toBe(!0)}),describe("should return false for invalid fields",()=>{const e=[{name:"null",value:null},{name:"undefined",value:void 0},{name:"string",value:"invalid"},{name:"number",value:123},{name:"boolean",value:!0},{name:"array",value:[]},{name:"empty object",value:{}},{name:"object missing chainId",value:{kind:"TOKEN",address:"0x123"}},{name:"object missing address",value:{kind:"TOKEN",chainId:1}}];test.each(e)("$name",({value:n})=>{expect(t.canHandle(n,d.TOKEN)).toBe(!1)})}),it("should return false for invalid expected type",()=>{expect(t.canHandle(a,d.NFT)).toBe(!1)})}),describe("loadField",()=>{it("should return error context when token data source fails",async()=>{const e=new Error("Token data source error");vi.spyOn(o,"getTokenInfosPayload").mockResolvedValue(r(e));const n=await t.loadField(a);expect(o.getTokenInfosPayload).toHaveBeenCalledWith({address:a.address,chainId:a.chainId}),expect(n).toEqual({type:d.ERROR,error:e})}),it("should return token context when successful",async()=>{vi.spyOn(o,"getTokenInfosPayload").mockResolvedValue(l(s));const e=await t.loadField(a);expect(o.getTokenInfosPayload).toHaveBeenCalledWith({address:a.address,chainId:a.chainId}),expect(e).toEqual({type:d.TOKEN,payload:s})}),it("should handle different chain IDs and addresses correctly",async()=>{const e={...a,chainId:137,address:"0xdeadbeef"};vi.spyOn(o,"getTokenInfosPayload").mockResolvedValue(l(s));const n=await t.loadField(e);expect(o.getTokenInfosPayload).toHaveBeenCalledWith({address:"0xdeadbeef",chainId:137}),expect(n).toEqual({type:d.TOKEN,payload:s})}),it("should preserve error message from token data source",async()=>{const e=new Error("Network timeout error");vi.spyOn(o,"getTokenInfosPayload").mockResolvedValue(r(e));const n=await t.loadField(a);expect(n).toEqual({type:d.ERROR,error:e})}),it("should handle empty token payload",async()=>{const e="";vi.spyOn(o,"getTokenInfosPayload").mockResolvedValue(l(e));const n=await t.loadField(a);expect(n).toEqual({type:d.TOKEN,payload:e})})})});
1
+ import{DeviceModelId as s}from"@ledgerhq/device-management-kit";import{Left as c,Right as i}from"purify-ts";import{ClearSignContextType as n}from"../../shared/model/ClearSignContext";import{TokenContextFieldLoader as f}from"../../token/domain/TokenContextFieldLoader";describe("TokenContextFieldLoader",()=>{const o={getTokenInfosPayload:vi.fn()},r=vi.fn(),u={loadCertificate:r},d=new f(o,u),a={kind:"TOKEN",chainId:1,address:"0x1234567890abcdef",deviceModelId:s.STAX},l="0x123456789abcdef0";beforeEach(()=>{vi.resetAllMocks()}),describe("canHandle",()=>{it("should return true for valid token field",()=>{const e={kind:"TOKEN",chainId:1,address:"0x1234567890abcdef",deviceModelId:s.STAX};expect(d.canHandle(e,n.TOKEN)).toBe(!0)}),describe("should return false for invalid fields",()=>{const e=[{name:"null",value:null},{name:"undefined",value:void 0},{name:"string",value:"invalid"},{name:"number",value:123},{name:"boolean",value:!0},{name:"array",value:[]},{name:"empty object",value:{}},{name:"object missing chainId",value:{kind:"TOKEN",address:"0x123",deviceModelId:s.STAX}},{name:"object missing address",value:{kind:"TOKEN",chainId:1,deviceModelId:s.STAX}},{name:"object missing deviceModelId",value:{kind:"TOKEN",chainId:1,address:"0x123"}}];test.each(e)("$name",({value:t})=>{expect(d.canHandle(t,n.TOKEN)).toBe(!1)})}),it("should return false for invalid expected type",()=>{expect(d.canHandle(a,n.NFT)).toBe(!1)})}),describe("loadField",()=>{it("should return error context when token data source fails",async()=>{const e=new Error("Token data source error");vi.spyOn(o,"getTokenInfosPayload").mockResolvedValue(c(e));const t=await d.loadField(a);expect(o.getTokenInfosPayload).toHaveBeenCalledWith({address:a.address,chainId:a.chainId}),expect(t).toEqual({type:n.ERROR,error:e})}),it("should return token context when successful",async()=>{vi.spyOn(o,"getTokenInfosPayload").mockResolvedValue(i(l)),r.mockResolvedValue(void 0);const e=await d.loadField(a);expect(o.getTokenInfosPayload).toHaveBeenCalledWith({address:a.address,chainId:a.chainId}),expect(e).toEqual({type:n.TOKEN,payload:l})}),it("should return token context with certificate when successful",async()=>{vi.spyOn(o,"getTokenInfosPayload").mockResolvedValue(i(l)),r.mockResolvedValueOnce({keyUsageNumber:1,payload:new Uint8Array([1,2,3,4])});const e=await d.loadField(a);expect(o.getTokenInfosPayload).toHaveBeenCalledWith({address:a.address,chainId:a.chainId}),expect(e).toEqual({type:n.TOKEN,payload:l,certificate:{keyUsageNumber:1,payload:new Uint8Array([1,2,3,4])}})}),it("should handle different chain IDs and addresses correctly",async()=>{const e={...a,chainId:137,address:"0xdeadbeef"};vi.spyOn(o,"getTokenInfosPayload").mockResolvedValue(i(l));const t=await d.loadField(e);expect(o.getTokenInfosPayload).toHaveBeenCalledWith({address:"0xdeadbeef",chainId:137}),expect(t).toEqual({type:n.TOKEN,payload:l})}),it("should preserve error message from token data source",async()=>{const e=new Error("Network timeout error");vi.spyOn(o,"getTokenInfosPayload").mockResolvedValue(c(e));const t=await d.loadField(a);expect(t).toEqual({type:n.ERROR,error:e})}),it("should handle empty token payload",async()=>{const e="";vi.spyOn(o,"getTokenInfosPayload").mockResolvedValue(i(e));const t=await d.loadField(a);expect(t).toEqual({type:n.TOKEN,payload:e})})})});
2
2
  //# sourceMappingURL=TokenContextFieldLoader.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/token/domain/TokenContextFieldLoader.test.ts"],
4
- "sourcesContent": ["import { Left, Right } from \"purify-ts\";\n\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport { type TokenDataSource } from \"@/token/data/TokenDataSource\";\nimport { TokenContextFieldLoader } from \"@/token/domain/TokenContextFieldLoader\";\n\ndescribe(\"TokenContextFieldLoader\", () => {\n const mockTokenDataSource: TokenDataSource = {\n getTokenInfosPayload: vi.fn(),\n };\n const tokenContextFieldLoader = new TokenContextFieldLoader(\n mockTokenDataSource,\n );\n\n const mockTransactionField = {\n kind: \"TOKEN\",\n chainId: 1,\n address: \"0x1234567890abcdef\",\n };\n\n const mockTokenPayload = \"0x123456789abcdef0\";\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n describe(\"canHandle\", () => {\n it(\"should return true for valid token field\", () => {\n // GIVEN\n const validField = {\n kind: \"TOKEN\",\n chainId: 1,\n address: \"0x1234567890abcdef\",\n };\n\n // THEN\n expect(\n tokenContextFieldLoader.canHandle(\n validField,\n ClearSignContextType.TOKEN,\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: { kind: \"TOKEN\", address: \"0x123\" },\n },\n {\n name: \"object missing address\",\n value: { kind: \"TOKEN\", chainId: 1 },\n },\n ];\n\n test.each(invalidFields)(\"$name\", ({ value }) => {\n expect(\n tokenContextFieldLoader.canHandle(value, ClearSignContextType.TOKEN),\n ).toBe(false);\n });\n });\n\n it(\"should return false for invalid expected type\", () => {\n expect(\n tokenContextFieldLoader.canHandle(\n mockTransactionField,\n ClearSignContextType.NFT,\n ),\n ).toBe(false);\n });\n });\n\n describe(\"loadField\", () => {\n it(\"should return error context when token data source fails\", async () => {\n // GIVEN\n const error = new Error(\"Token data source error\");\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(error),\n );\n\n // WHEN\n const result =\n await tokenContextFieldLoader.loadField(mockTransactionField);\n\n // THEN\n expect(mockTokenDataSource.getTokenInfosPayload).toHaveBeenCalledWith({\n address: mockTransactionField.address,\n chainId: mockTransactionField.chainId,\n });\n expect(result).toEqual({\n type: ClearSignContextType.ERROR,\n error: error,\n });\n });\n\n it(\"should return token context when successful\", async () => {\n // GIVEN\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(mockTokenPayload),\n );\n\n // WHEN\n const result =\n await tokenContextFieldLoader.loadField(mockTransactionField);\n\n // THEN\n expect(mockTokenDataSource.getTokenInfosPayload).toHaveBeenCalledWith({\n address: mockTransactionField.address,\n chainId: mockTransactionField.chainId,\n });\n expect(result).toEqual({\n type: ClearSignContextType.TOKEN,\n payload: mockTokenPayload,\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 address: \"0xdeadbeef\",\n };\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(mockTokenPayload),\n );\n\n // WHEN\n const result = await tokenContextFieldLoader.loadField(customField);\n\n // THEN\n expect(mockTokenDataSource.getTokenInfosPayload).toHaveBeenCalledWith({\n address: \"0xdeadbeef\",\n chainId: 137,\n });\n expect(result).toEqual({\n type: ClearSignContextType.TOKEN,\n payload: mockTokenPayload,\n });\n });\n\n it(\"should preserve error message from token data source\", async () => {\n // GIVEN\n const specificError = new Error(\"Network timeout error\");\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(specificError),\n );\n\n // WHEN\n const result =\n await tokenContextFieldLoader.loadField(mockTransactionField);\n\n // THEN\n expect(result).toEqual({\n type: ClearSignContextType.ERROR,\n error: specificError,\n });\n });\n\n it(\"should handle empty token payload\", async () => {\n // GIVEN\n const emptyPayload = \"\";\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(emptyPayload),\n );\n\n // WHEN\n const result =\n await tokenContextFieldLoader.loadField(mockTransactionField);\n\n // THEN\n expect(result).toEqual({\n type: ClearSignContextType.TOKEN,\n payload: emptyPayload,\n });\n });\n });\n});\n"],
5
- "mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAE5B,OAAS,wBAAAC,MAA4B,kCAErC,OAAS,2BAAAC,MAA+B,yCAExC,SAAS,0BAA2B,IAAM,CACxC,MAAMC,EAAuC,CAC3C,qBAAsB,GAAG,GAAG,CAC9B,EACMC,EAA0B,IAAIF,EAClCC,CACF,EAEME,EAAuB,CAC3B,KAAM,QACN,QAAS,EACT,QAAS,oBACX,EAEMC,EAAmB,qBAEzB,WAAW,IAAM,CACf,GAAG,cAAc,CACnB,CAAC,EAED,SAAS,YAAa,IAAM,CAC1B,GAAG,2CAA4C,IAAM,CAEnD,MAAMC,EAAa,CACjB,KAAM,QACN,QAAS,EACT,QAAS,oBACX,EAGA,OACEH,EAAwB,UACtBG,EACAN,EAAqB,KACvB,CACF,EAAE,KAAK,EAAI,CACb,CAAC,EAED,SAAS,yCAA0C,IAAM,CACvD,MAAMO,EAAgB,CACpB,CAAE,KAAM,OAAQ,MAAO,IAAK,EAC5B,CAAE,KAAM,YAAa,MAAO,MAAU,EACtC,CAAE,KAAM,SAAU,MAAO,SAAU,EACnC,CAAE,KAAM,SAAU,MAAO,GAAI,EAC7B,CAAE,KAAM,UAAW,MAAO,EAAK,EAC/B,CAAE,KAAM,QAAS,MAAO,CAAC,CAAE,EAC3B,CAAE,KAAM,eAAgB,MAAO,CAAC,CAAE,EAClC,CACE,KAAM,yBACN,MAAO,CAAE,KAAM,QAAS,QAAS,OAAQ,CAC3C,EACA,CACE,KAAM,yBACN,MAAO,CAAE,KAAM,QAAS,QAAS,CAAE,CACrC,CACF,EAEA,KAAK,KAAKA,CA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QAAS,aACT,QAAS,GACX,CAAC,EACD,OAAOQ,CAAM,EAAE,QAAQ,CACrB,KAAMV,EAAqB,MAC3B,QAASK,CACX,CAAC,CACH,CAAC,EAED,GAAG,uDAAwD,SAAY,CAErE,MAAMO,EAAgB,IAAI,MAAM,uBAAuB,EACvD,GAAG,MAAMV,EAAqB,sBAAsB,EAAE,kBACpDJ,EAAKc,CAAa,CACpB,EAGA,MAAMF,EACJ,MAAMP,EAAwB,UAAUC,CAAoB,EAG9D,OAAOM,CAAM,EAAE,QAAQ,CACrB,KAAMV,EAAqB,MAC3B,MAAOY,CACT,CAAC,CACH,CAAC,EAED,GAAG,oCAAqC,SAAY,CAElD,MAAMC,EAAe,GACrB,GAAG,MAAMX,EAAqB,sBAAsB,EAAE,kBACpDH,EAAMc,CAAY,CACpB,EAGA,MAAMH,EACJ,MAAMP,EAAwB,UAAUC,CAAoB,EAG9D,OAAOM,CAAM,EAAE,QAAQ,CACrB,KAAMV,EAAqB,MAC3B,QAASa,CACX,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["Left", "Right", "ClearSignContextType", "TokenContextFieldLoader", "mockTokenDataSource", "tokenContextFieldLoader", "mockTransactionField", "mockTokenPayload", "validField", "invalidFields", "value", "error", "result", "customField", "specificError", "emptyPayload"]
4
+ "sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport { type TokenDataSource } from \"@/token/data/TokenDataSource\";\nimport { TokenContextFieldLoader } from \"@/token/domain/TokenContextFieldLoader\";\n\ndescribe(\"TokenContextFieldLoader\", () => {\n const mockTokenDataSource: TokenDataSource = {\n getTokenInfosPayload: vi.fn(),\n };\n const loadCertificateMock = vi.fn();\n const mockCertificateLoader: PkiCertificateLoader = {\n loadCertificate: loadCertificateMock,\n };\n const tokenContextFieldLoader = new TokenContextFieldLoader(\n mockTokenDataSource,\n mockCertificateLoader,\n );\n\n const mockTransactionField = {\n kind: \"TOKEN\",\n chainId: 1,\n address: \"0x1234567890abcdef\",\n deviceModelId: DeviceModelId.STAX,\n };\n\n const mockTokenPayload = \"0x123456789abcdef0\";\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n describe(\"canHandle\", () => {\n it(\"should return true for valid token field\", () => {\n // GIVEN\n const validField = {\n kind: \"TOKEN\",\n chainId: 1,\n address: \"0x1234567890abcdef\",\n deviceModelId: DeviceModelId.STAX,\n };\n\n // THEN\n expect(\n tokenContextFieldLoader.canHandle(\n validField,\n ClearSignContextType.TOKEN,\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 kind: \"TOKEN\",\n address: \"0x123\",\n deviceModelId: DeviceModelId.STAX,\n },\n },\n {\n name: \"object missing address\",\n value: {\n kind: \"TOKEN\",\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n },\n },\n {\n name: \"object missing deviceModelId\",\n value: { kind: \"TOKEN\", chainId: 1, address: \"0x123\" },\n },\n ];\n\n test.each(invalidFields)(\"$name\", ({ value }) => {\n expect(\n tokenContextFieldLoader.canHandle(value, ClearSignContextType.TOKEN),\n ).toBe(false);\n });\n });\n\n it(\"should return false for invalid expected type\", () => {\n expect(\n tokenContextFieldLoader.canHandle(\n mockTransactionField,\n ClearSignContextType.NFT,\n ),\n ).toBe(false);\n });\n });\n\n describe(\"loadField\", () => {\n it(\"should return error context when token data source fails\", async () => {\n // GIVEN\n const error = new Error(\"Token data source error\");\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(error),\n );\n\n // WHEN\n const result =\n await tokenContextFieldLoader.loadField(mockTransactionField);\n\n // THEN\n expect(mockTokenDataSource.getTokenInfosPayload).toHaveBeenCalledWith({\n address: mockTransactionField.address,\n chainId: mockTransactionField.chainId,\n });\n expect(result).toEqual({\n type: ClearSignContextType.ERROR,\n error: error,\n });\n });\n\n it(\"should return token context when successful\", async () => {\n // GIVEN\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(mockTokenPayload),\n );\n loadCertificateMock.mockResolvedValue(undefined);\n\n // WHEN\n const result =\n await tokenContextFieldLoader.loadField(mockTransactionField);\n\n // THEN\n expect(mockTokenDataSource.getTokenInfosPayload).toHaveBeenCalledWith({\n address: mockTransactionField.address,\n chainId: mockTransactionField.chainId,\n });\n expect(result).toEqual({\n type: ClearSignContextType.TOKEN,\n payload: mockTokenPayload,\n });\n });\n\n it(\"should return token context with certificate when successful\", async () => {\n // GIVEN\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(mockTokenPayload),\n );\n loadCertificateMock.mockResolvedValueOnce({\n keyUsageNumber: 1,\n payload: new Uint8Array([1, 2, 3, 4]),\n });\n\n // WHEN\n const result =\n await tokenContextFieldLoader.loadField(mockTransactionField);\n\n // THEN\n expect(mockTokenDataSource.getTokenInfosPayload).toHaveBeenCalledWith({\n address: mockTransactionField.address,\n chainId: mockTransactionField.chainId,\n });\n expect(result).toEqual({\n type: ClearSignContextType.TOKEN,\n payload: mockTokenPayload,\n certificate: {\n keyUsageNumber: 1,\n payload: new Uint8Array([1, 2, 3, 4]),\n },\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 address: \"0xdeadbeef\",\n };\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(mockTokenPayload),\n );\n\n // WHEN\n const result = await tokenContextFieldLoader.loadField(customField);\n\n // THEN\n expect(mockTokenDataSource.getTokenInfosPayload).toHaveBeenCalledWith({\n address: \"0xdeadbeef\",\n chainId: 137,\n });\n expect(result).toEqual({\n type: ClearSignContextType.TOKEN,\n payload: mockTokenPayload,\n });\n });\n\n it(\"should preserve error message from token data source\", async () => {\n // GIVEN\n const specificError = new Error(\"Network timeout error\");\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(specificError),\n );\n\n // WHEN\n const result =\n await tokenContextFieldLoader.loadField(mockTransactionField);\n\n // THEN\n expect(result).toEqual({\n type: ClearSignContextType.ERROR,\n error: specificError,\n });\n });\n\n it(\"should handle empty token payload\", async () => {\n // GIVEN\n const emptyPayload = \"\";\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(emptyPayload),\n );\n\n // WHEN\n const result =\n await tokenContextFieldLoader.loadField(mockTransactionField);\n\n // THEN\n expect(result).toEqual({\n type: ClearSignContextType.TOKEN,\n payload: emptyPayload,\n });\n });\n });\n});\n"],
5
+ "mappings": "AAAA,OAAS,iBAAAA,MAAqB,kCAC9B,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAG5B,OAAS,wBAAAC,MAA4B,kCAErC,OAAS,2BAAAC,MAA+B,yCAExC,SAAS,0BAA2B,IAAM,CACxC,MAAMC,EAAuC,CAC3C,qBAAsB,GAAG,GAAG,CAC9B,EACMC,EAAsB,GAAG,GAAG,EAC5BC,EAA8C,CAClD,gBAAiBD,CACnB,EACME,EAA0B,IAAIJ,EAClCC,EACAE,CACF,EAEME,EAAuB,CAC3B,KAAM,QACN,QAAS,EACT,QAAS,qBACT,cAAeT,EAAc,IAC/B,EAEMU,EAAmB,qBAEzB,WAAW,IAAM,CACf,GAAG,cAAc,CACnB,CAAC,EAED,SAAS,YAAa,IAAM,CAC1B,GAAG,2CAA4C,IAAM,CAEnD,MAAMC,EAAa,CACjB,KAAM,QACN,QAAS,EACT,QAAS,qBACT,cAAeX,EAAc,IAC/B,EAGA,OAC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AS,GACX,CAAC,EACD,OAAOU,CAAM,EAAE,QAAQ,CACrB,KAAMZ,EAAqB,MAC3B,QAASO,CACX,CAAC,CACH,CAAC,EAED,GAAG,uDAAwD,SAAY,CAErE,MAAMO,EAAgB,IAAI,MAAM,uBAAuB,EACvD,GAAG,MAAMZ,EAAqB,sBAAsB,EAAE,kBACpDJ,EAAKgB,CAAa,CACpB,EAGA,MAAMF,EACJ,MAAMP,EAAwB,UAAUC,CAAoB,EAG9D,OAAOM,CAAM,EAAE,QAAQ,CACrB,KAAMZ,EAAqB,MAC3B,MAAOc,CACT,CAAC,CACH,CAAC,EAED,GAAG,oCAAqC,SAAY,CAElD,MAAMC,EAAe,GACrB,GAAG,MAAMb,EAAqB,sBAAsB,EAAE,kBACpDH,EAAMgB,CAAY,CACpB,EAGA,MAAMH,EACJ,MAAMP,EAAwB,UAAUC,CAAoB,EAG9D,OAAOM,CAAM,EAAE,QAAQ,CACrB,KAAMZ,EAAqB,MAC3B,QAASe,CACX,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["DeviceModelId", "Left", "Right", "ClearSignContextType", "TokenContextFieldLoader", "mockTokenDataSource", "loadCertificateMock", "mockCertificateLoader", "tokenContextFieldLoader", "mockTransactionField", "mockTokenPayload", "validField", "invalidFields", "value", "error", "result", "customField", "specificError", "emptyPayload"]
7
7
  }
@@ -1,2 +1,2 @@
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};
1
+ var d=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var g=(i,e,t,o)=>{for(var r=o>1?void 0:o?x(e,t):e,n=i.length-1,a;n>=0;n--)(a=i[n])&&(r=(o?a(e,t,r):a(r))||r);return o&&r&&d(e,t,r),r},s=(i,e)=>(t,o)=>e(t,o,i);import{isHexaString as p}from"@ledgerhq/device-management-kit";import{inject as S,injectable as m}from"inversify";import{configTypes as y}from"../../config/di/configTypes";import{ClearSignContextType as l}from"../../shared/model/ClearSignContext";import{tokenTypes as C}from"../../token/di/tokenTypes";var u=(t=>(t.Approve="0x095ea7b3",t.Transfer="0xa9059cbb",t))(u||{});const T=Object.values(u),f=[l.TOKEN];let c=class{_dataSource;logger;constructor(e,t){this._dataSource=e,this.logger=t("TokenContextLoader")}canHandle(e,t){return typeof e=="object"&&e!==null&&"to"in e&&"selector"in e&&"chainId"in e&&typeof e.chainId=="number"&&p(e.to)&&e.to!=="0x"&&p(e.selector)&&this.isSelectorSupported(e.selector)&&f.every(o=>t.includes(o))}async load(e){const{to:t,chainId:o}=e,n=[(await this._dataSource.getTokenInfosPayload({address:t,chainId:o})).caseOf({Left:a=>({type:l.ERROR,error:a}),Right:a=>({type:l.TOKEN,payload:a})})];return this.logger.debug("load result",{data:{result:n}}),n}isSelectorSupported(e){return Object.values(T).includes(e)}};c=g([m(),s(0,S(C.TokenDataSource)),s(1,S(y.ContextModuleLoggerFactory))],c);export{u 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 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"]
4
+ "sourcesContent": ["import {\n HexaString,\n isHexaString,\n LoggerPublisherService,\n} from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\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 private logger: LoggerPublisherService;\n\n constructor(\n @inject(tokenTypes.TokenDataSource) dataSource: TokenDataSource,\n @inject(configTypes.ContextModuleLoggerFactory)\n loggerFactory: (tag: string) => LoggerPublisherService,\n ) {\n this._dataSource = dataSource;\n this.logger = loggerFactory(\"TokenContextLoader\");\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 const result = [\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 this.logger.debug(\"load result\", { data: { result } });\n return result;\n }\n\n private isSelectorSupported(selector: HexaString) {\n return Object.values(SUPPORTED_SELECTORS).includes(selector);\n }\n}\n"],
5
+ "mappings": "iOAAA,OAEE,gBAAAA,MAEK,kCACP,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YAEnC,OAAS,eAAAC,MAAmB,0BAE5B,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,YACA,OAER,YACsCC,EAEpCC,EACA,CACA,KAAK,YAAcD,EACnB,KAAK,OAASC,EAAc,oBAAoB,CAClD,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,GACvCL,EAAgB,MAAOQ,GAASF,EAAc,SAASE,CAAI,CAAC,CAEhE,CAEA,MAAM,KAAKH,EAAuD,CAChE,KAAM,CAAE,GAAAI,EAAI,QAAAC,CAAQ,EAAIL,EAOlBM,EAAS,EALC,MAAM,KAAK,YAAY,qBAAqB,CAC1D,QAASF,EACT,QAAAC,CACF,CAAC,GAGS,OAAO,CACb,KAAOE,IAA6B,CAClC,KAAMX,EAAqB,MAC3B,MAAAW,CACF,GACA,MAAQC,IAA6B,CACnC,KAAMZ,EAAqB,MAC3B,QAASY,CACX,EACF,CAAC,CACH,EAEA,YAAK,OAAO,MAAM,cAAe,CAAE,KAAM,CAAE,OAAAF,CAAO,CAAE,CAAC,EAC9CA,CACT,CAEQ,oBAAoBG,EAAsB,CAChD,OAAO,OAAO,OAAOf,CAAmB,EAAE,SAASe,CAAQ,CAC7D,CACF,EA5DaZ,EAANa,EAAA,CADNC,EAAW,EAMPC,EAAA,EAAAC,EAAOC,EAAW,eAAe,GACjCF,EAAA,EAAAC,EAAOE,EAAY,0BAA0B,IANrClB",
6
+ "names": ["isHexaString", "inject", "injectable", "configTypes", "ClearSignContextType", "tokenTypes", "ERC20_SUPPORTED_SELECTORS", "SUPPORTED_SELECTORS", "SUPPORTED_TYPES", "ClearSignContextType", "TokenContextLoader", "dataSource", "loggerFactory", "input", "expectedTypes", "isHexaString", "type", "to", "chainId", "result", "error", "value", "selector", "__decorateClass", "injectable", "__decorateParam", "inject", "tokenTypes", "configTypes"]
7
7
  }
@@ -1,2 +1,2 @@
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"}])})})});
1
+ import{Left as i,Right as c}from"purify-ts";import{ClearSignContextType as o}from"../../shared/model/ClearSignContext";import{TokenContextLoader as s}from"../../token/domain/TokenContextLoader";const l=()=>({debug:vi.fn(),info:vi.fn(),warn:vi.fn(),error:vi.fn(),subscribers:[]});describe("TokenContextLoader",()=>{const r={getTokenInfosPayload:vi.fn()},t=new s(r,l);beforeEach(()=>{vi.restoreAllMocks(),vi.spyOn(r,"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,a)=>{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,a)=>{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,a)=>{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,a)=>{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(r,"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 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: Cl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I,MAAM,OAAO,CAAC,CACzB,EAGA,MAAMU,EAAS,MAAML,EAAO,KAAKG,CAAK,EAGtC,OAAOE,CAAM,EAAE,QAAQ,CACrB,CAAE,KAAMR,EAAqB,MAAO,MAAO,IAAI,MAAM,OAAO,CAAE,CAChE,CAAC,CACH,CAAC,EAED,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"]
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\nconst mockLoggerFactory = () => ({\n debug: vi.fn(),\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n subscribers: [],\n});\n\ndescribe(\"TokenContextLoader\", () => {\n const mockTokenDataSource: TokenDataSource = {\n getTokenInfosPayload: vi.fn(),\n };\n const loader = new TokenContextLoader(mockTokenDataSource, mockLoggerFactory);\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,oCAEP,MAAMC,EAAoB,KAAO,CAC/B,MAAO,GAAG,GAAG,EACb,KAAM,GAAG,GAAG,EACZ,KAAM,GAAG,GAAG,EACZ,MAAO,GAAG,GAAG,EACb,YAAa,CAAC,CAChB,GAEA,SAAS,qBAAsB,IAAM,CACnC,MAAMC,EAAuC,CAC3C,qBAAsB,GAAG,GAAG,CAC9B,EACMC,EAAS,IAAIH,EAAmBE,EAAqBD,CAAiB,EAE5E,WAAW,IAAM,CACf,GAAG,gBAAgB,EACnB,GAAG,MAAMC,EAAqB,sBAAsB,EAAE,mBACpD,CAAC,CAAE,QAAAE,CAAQ,IAAM,QAAQ,QAAQN,EAAM,WAAWM,CAAO,EAAE,CAAC,CAC9D,CACF,CAAC,EAED,SAAS,qBAAsB,IAAM,CACnC,MAAMC,EAAgC,CACpC,GAAI,6CACJ,SAAU,aACV,QAAS,CACX,EAEA,GAAG,qCAAsC,IAAM,CAC7C,OAAOF,EAAO,UAAUE,EAAY,CAACN,EAAqB,KAAK,CAAC,CAAC,EAAE,KACjE,EACF,CACF,CAAC,EAED,GAAG,gDAAiD,IAAM,CACxD,OAAOI,EAAO,UAAUE,EAAY,CAACN,EAAqB,GAAG,CAAC,CAAC,EAAE,KAC/D,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AE,GAAGA,EAAY,QAAS,IAAK,EAAG,cAAc,EACjD,CAAC,CAAE,GAAGA,EAAY,QAAS,MAAU,EAAG,mBAAmB,CAC7D,CAAC,EAAE,6BAA8B,CAACC,EAAOC,IAAiB,CACxD,OAAOJ,EAAO,UAAUG,EAAO,CAACP,EAAqB,KAAK,CAAC,CAAC,EAAE,KAAK,EAAK,CAC1E,CAAC,CACH,CAAC,EAED,SAAS,gBAAiB,IAAM,CAC9B,GAAG,0DAA2D,SAAY,CAExE,MAAMO,EAA2B,CAC/B,GAAI,6CACJ,QAAS,EACT,SAAU,YACZ,EACA,GAAG,MAAMJ,EAAqB,sBAAsB,EAAE,kBACpDL,EAAK,IAAI,MAAM,OAAO,CAAC,CACzB,EAGA,MAAMW,EAAS,MAAML,EAAO,KAAKG,CAAK,EAGtC,OAAOE,CAAM,EAAE,QAAQ,CACrB,CAAE,KAAMT,EAAqB,MAAO,MAAO,IAAI,MAAM,OAAO,CAAE,CAChE,CAAC,CACH,CAAC,EAED,GAAG,mCAAoC,SAAY,CAEjD,MAAMO,EAA2B,CAC/B,GAAI,6CACJ,QAAS,EACT,SAAU,YACZ,EAGME,EAAS,MAAML,EAAO,KAAKG,CAAK,EAGtC,OAAOE,CAAM,EAAE,QAAQ,CACrB,CACE,KAAMT,EAAqB,MAC3B,QAAS,oDACX,CACF,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["Left", "Right", "ClearSignContextType", "TokenContextLoader", "mockLoggerFactory", "mockTokenDataSource", "loader", "address", "validInput", "input", "_description", "result"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var p=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var C=(n,e,t,o)=>{for(var r=o>1?void 0:o?I(e,t):e,a=n.length-1,i;a>=0;a--)(i=n[a])&&(r=(o?i(e,t,r):i(r))||r);return o&&r&&p(e,t,r),r},s=(n,e)=>(t,o)=>e(t,o,n);import{bufferToHexaString as S,DeviceModelId as h,isHexaString as m}from"@ledgerhq/device-management-kit";import{inject as l,injectable as x}from"inversify";import{pkiTypes as T}from"../../pki/di/pkiTypes";import{KeyUsage as k}from"../../pki/model/KeyUsage";import{ClearSignContextType as f}from"../../shared/model/ClearSignContext";import{transactionCheckTypes as g}from"../../transaction-check/di/transactionCheckTypes";const u=[f.TRANSACTION_CHECK];let d=class{constructor(e,t){this.transactionCheckDataSource=e;this.certificateLoader=t}canHandle(e,t){return typeof e=="object"&&e!==null&&"from"in e&&e.from!==void 0&&m(e.from)&&"chainId"in e&&e.chainId!==void 0&&typeof e.chainId=="number"&&"transaction"in e&&e.transaction!==void 0&&"deviceModelId"in e&&e.deviceModelId!==void 0&&e.deviceModelId!==h.NANO_S&&typeof e.chainId=="number"&&m(e.from)&&e.from!=="0x"&&u.every(r=>t.includes(r))}async load(e){const{from:t,chainId:o,transaction:r}=e,a=S(r);return!t||!a?[]:[await(await this.transactionCheckDataSource.getTransactionCheck({chainId:o,rawTx:a,from:t})).caseOf({Left:c=>Promise.resolve({type:f.ERROR,error:c}),Right:async c=>{const y=await this.certificateLoader.loadCertificate({keyId:c.publicKeyId,keyUsage:k.TxSimulationSigner,targetDevice:e.deviceModelId});return{type:f.TRANSACTION_CHECK,payload:c.descriptor,certificate:y}}})]}};d=C([x(),s(0,l(g.TransactionCheckDataSource)),s(1,l(T.PkiCertificateLoader))],d);export{d as TransactionCheckContextLoader};
1
+ var u=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var g=(i,e,t,r)=>{for(var o=r>1?void 0:r?p(e,t):e,a=i.length-1,n;a>=0;a--)(n=i[a])&&(o=(r?n(e,t,o):n(o))||o);return r&&o&&u(e,t,o),o},s=(i,e)=>(t,r)=>e(t,r,i);import{bufferToHexaString as y,DeviceModelId as S,isHexaString as m}from"@ledgerhq/device-management-kit";import{inject as l,injectable as x}from"inversify";import{configTypes as I}from"../../config/di/configTypes";import{pkiTypes as T}from"../../pki/di/pkiTypes";import{KeyUsage as k}from"../../pki/model/KeyUsage";import{ClearSignContextType as C}from"../../shared/model/ClearSignContext";import{transactionCheckTypes as v}from"../../transaction-check/di/transactionCheckTypes";const b=[C.TRANSACTION_CHECK];let d=class{constructor(e,t,r){this.transactionCheckDataSource=e;this.certificateLoader=t;this.logger=r("TransactionCheckContextLoader")}logger;canHandle(e,t){return typeof e=="object"&&e!==null&&"from"in e&&e.from!==void 0&&m(e.from)&&"chainId"in e&&e.chainId!==void 0&&typeof e.chainId=="number"&&"transaction"in e&&e.transaction!==void 0&&"deviceModelId"in e&&e.deviceModelId!==void 0&&e.deviceModelId!==S.NANO_S&&typeof e.chainId=="number"&&m(e.from)&&e.from!=="0x"&&b.every(o=>t.includes(o))}async load(e){const{from:t,chainId:r,transaction:o}=e,a=y(o);if(!t||!a)return this.logger.debug("load result",{data:{result:[]}}),[];const f=[await(await this.transactionCheckDataSource.getTransactionCheck({chainId:r,rawTx:a,from:t})).caseOf({Left:c=>Promise.resolve({type:C.ERROR,error:c}),Right:async c=>{const h=await this.certificateLoader.loadCertificate({keyId:c.publicKeyId,keyUsage:k.TxSimulationSigner,targetDevice:e.deviceModelId});return{type:C.TRANSACTION_CHECK,payload:c.descriptor,certificate:h}}})];return this.logger.debug("load result",{data:{result:f}}),f}};d=g([x(),s(0,l(v.TransactionCheckDataSource)),s(1,l(T.PkiCertificateLoader)),s(2,l(I.ContextModuleLoggerFactory))],d);export{d as TransactionCheckContextLoader};
2
2
  //# sourceMappingURL=TransactionCheckContextLoader.js.map