@ledgerhq/context-module 0.0.0-test-attest-npmjs-x-20251125162751 → 0.0.0-test-new-attestation-20251203154737

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 (148) hide show
  1. package/lib/cjs/package.json +8 -8
  2. package/lib/cjs/src/DefaultContextModule.test.js.map +1 -1
  3. package/lib/cjs/src/di.js +1 -1
  4. package/lib/cjs/src/di.js.map +3 -3
  5. package/lib/cjs/src/index.js +1 -1
  6. package/lib/cjs/src/index.js.map +2 -2
  7. package/lib/cjs/src/shared/domain/ContextFieldLoader.js +1 -1
  8. package/lib/cjs/src/shared/domain/ContextFieldLoader.js.map +1 -1
  9. package/lib/cjs/src/shared/model/ClearSignContext.js +1 -1
  10. package/lib/cjs/src/shared/model/ClearSignContext.js.map +1 -1
  11. package/lib/cjs/src/shared/model/SolanaContextTypes.js +2 -0
  12. package/lib/cjs/src/shared/model/SolanaContextTypes.js.map +7 -0
  13. package/lib/cjs/src/shared/model/SolanaTransactionContext.js +1 -1
  14. package/lib/cjs/src/shared/model/SolanaTransactionContext.js.map +1 -1
  15. package/lib/cjs/src/solana/data/HttpSolanaOwnerInfoDataSource.js +1 -1
  16. package/lib/cjs/src/solana/data/HttpSolanaOwnerInfoDataSource.js.map +3 -3
  17. package/lib/cjs/src/solana/data/HttpSolanaOwnerInfoDataSource.test.js +1 -1
  18. package/lib/cjs/src/solana/data/HttpSolanaOwnerInfoDataSource.test.js.map +2 -2
  19. package/lib/cjs/src/solana/data/SolanaDataSource.js +1 -1
  20. package/lib/cjs/src/solana/data/SolanaDataSource.js.map +1 -1
  21. package/lib/cjs/src/solana/domain/DefaultSolanaContextLoader.js +1 -1
  22. package/lib/cjs/src/solana/domain/DefaultSolanaContextLoader.js.map +3 -3
  23. package/lib/cjs/src/solana/domain/DefaultSolanaContextLoader.test.js +1 -1
  24. package/lib/cjs/src/solana/domain/DefaultSolanaContextLoader.test.js.map +3 -3
  25. package/lib/cjs/src/solana/domain/solanaContextTypes.js +1 -1
  26. package/lib/cjs/src/solana/domain/solanaContextTypes.js.map +1 -1
  27. package/lib/cjs/src/solanaLifi/data/HttpSolanaLifiDataSource.js +2 -0
  28. package/lib/cjs/src/solanaLifi/data/HttpSolanaLifiDataSource.js.map +7 -0
  29. package/lib/cjs/src/solanaLifi/data/HttpSolanaLifiDataSource.test.js +2 -0
  30. package/lib/cjs/src/solanaLifi/data/HttpSolanaLifiDataSource.test.js.map +7 -0
  31. package/lib/cjs/src/solanaLifi/data/SolanaLifiDataSource.js +2 -0
  32. package/lib/cjs/src/solanaLifi/data/SolanaLifiDataSource.js.map +7 -0
  33. package/lib/cjs/src/solanaLifi/di/lifiModuleFactory.js +2 -0
  34. package/lib/cjs/src/solanaLifi/di/lifiModuleFactory.js.map +7 -0
  35. package/lib/cjs/src/solanaLifi/di/solanaLifiTypes.js +2 -0
  36. package/lib/cjs/src/solanaLifi/di/solanaLifiTypes.js.map +7 -0
  37. package/lib/cjs/src/solanaLifi/domain/SolanaLifiContextLoader.js +2 -0
  38. package/lib/cjs/src/solanaLifi/domain/SolanaLifiContextLoader.js.map +7 -0
  39. package/lib/cjs/src/solanaLifi/domain/SolanaLifiContextLoader.test.js +2 -0
  40. package/lib/cjs/src/solanaLifi/domain/SolanaLifiContextLoader.test.js.map +7 -0
  41. package/lib/cjs/src/solanaToken/data/HttpSolanaTokenDataSource.js +2 -0
  42. package/lib/cjs/src/solanaToken/data/HttpSolanaTokenDataSource.js.map +7 -0
  43. package/lib/cjs/src/solanaToken/data/HttpSolanaTokenDataSource.test.js +7 -0
  44. package/lib/cjs/src/solanaToken/data/HttpSolanaTokenDataSource.test.js.map +7 -0
  45. package/lib/cjs/src/solanaToken/data/SolanaTokenDataSource.js +2 -0
  46. package/lib/cjs/src/solanaToken/data/SolanaTokenDataSource.js.map +7 -0
  47. package/lib/cjs/src/solanaToken/di/solanaTokenTypes.js +2 -0
  48. package/lib/cjs/src/solanaToken/di/solanaTokenTypes.js.map +7 -0
  49. package/lib/cjs/src/solanaToken/di/tokenModuleFactory.js +2 -0
  50. package/lib/cjs/src/solanaToken/di/tokenModuleFactory.js.map +7 -0
  51. package/lib/cjs/src/solanaToken/domain/SolanaTokenContextLoader.js +2 -0
  52. package/lib/cjs/src/solanaToken/domain/SolanaTokenContextLoader.js.map +7 -0
  53. package/lib/cjs/src/solanaToken/domain/SolanaTokenContextLoader.test.js +2 -0
  54. package/lib/cjs/src/solanaToken/domain/SolanaTokenContextLoader.test.js.map +7 -0
  55. package/lib/esm/package.json +8 -8
  56. package/lib/esm/src/DefaultContextModule.test.js.map +1 -1
  57. package/lib/esm/src/di.js +1 -1
  58. package/lib/esm/src/di.js.map +3 -3
  59. package/lib/esm/src/index.js +1 -1
  60. package/lib/esm/src/index.js.map +2 -2
  61. package/lib/esm/src/shared/model/ClearSignContext.js +1 -1
  62. package/lib/esm/src/shared/model/ClearSignContext.js.map +1 -1
  63. package/lib/esm/src/shared/model/SolanaContextTypes.js +2 -0
  64. package/lib/esm/src/shared/model/SolanaContextTypes.js.map +7 -0
  65. package/lib/esm/src/solana/data/HttpSolanaOwnerInfoDataSource.js +1 -1
  66. package/lib/esm/src/solana/data/HttpSolanaOwnerInfoDataSource.js.map +3 -3
  67. package/lib/esm/src/solana/data/HttpSolanaOwnerInfoDataSource.test.js +1 -1
  68. package/lib/esm/src/solana/data/HttpSolanaOwnerInfoDataSource.test.js.map +2 -2
  69. package/lib/esm/src/solana/domain/DefaultSolanaContextLoader.js +1 -1
  70. package/lib/esm/src/solana/domain/DefaultSolanaContextLoader.js.map +3 -3
  71. package/lib/esm/src/solana/domain/DefaultSolanaContextLoader.test.js +1 -1
  72. package/lib/esm/src/solana/domain/DefaultSolanaContextLoader.test.js.map +3 -3
  73. package/lib/esm/src/solanaLifi/data/HttpSolanaLifiDataSource.js +2 -0
  74. package/lib/esm/src/solanaLifi/data/HttpSolanaLifiDataSource.js.map +7 -0
  75. package/lib/esm/src/solanaLifi/data/HttpSolanaLifiDataSource.test.js +2 -0
  76. package/lib/esm/src/solanaLifi/data/HttpSolanaLifiDataSource.test.js.map +7 -0
  77. package/lib/esm/src/solanaLifi/data/SolanaLifiDataSource.js +1 -0
  78. package/lib/esm/src/solanaLifi/data/SolanaLifiDataSource.js.map +7 -0
  79. package/lib/esm/src/solanaLifi/di/lifiModuleFactory.js +2 -0
  80. package/lib/esm/src/solanaLifi/di/lifiModuleFactory.js.map +7 -0
  81. package/lib/esm/src/solanaLifi/di/solanaLifiTypes.js +2 -0
  82. package/lib/esm/src/solanaLifi/di/solanaLifiTypes.js.map +7 -0
  83. package/lib/esm/src/solanaLifi/domain/SolanaLifiContextLoader.js +2 -0
  84. package/lib/esm/src/solanaLifi/domain/SolanaLifiContextLoader.js.map +7 -0
  85. package/lib/esm/src/solanaLifi/domain/SolanaLifiContextLoader.test.js +2 -0
  86. package/lib/esm/src/solanaLifi/domain/SolanaLifiContextLoader.test.js.map +7 -0
  87. package/lib/esm/src/solanaToken/data/HttpSolanaTokenDataSource.js +2 -0
  88. package/lib/esm/src/solanaToken/data/HttpSolanaTokenDataSource.js.map +7 -0
  89. package/lib/esm/src/solanaToken/data/HttpSolanaTokenDataSource.test.js +7 -0
  90. package/lib/esm/src/solanaToken/data/HttpSolanaTokenDataSource.test.js.map +7 -0
  91. package/lib/esm/src/solanaToken/data/SolanaTokenDataSource.js +1 -0
  92. package/lib/esm/src/solanaToken/data/SolanaTokenDataSource.js.map +7 -0
  93. package/lib/esm/src/solanaToken/di/solanaTokenTypes.js +2 -0
  94. package/lib/esm/src/solanaToken/di/solanaTokenTypes.js.map +7 -0
  95. package/lib/esm/src/solanaToken/di/tokenModuleFactory.js +2 -0
  96. package/lib/esm/src/solanaToken/di/tokenModuleFactory.js.map +7 -0
  97. package/lib/esm/src/solanaToken/domain/SolanaTokenContextLoader.js +2 -0
  98. package/lib/esm/src/solanaToken/domain/SolanaTokenContextLoader.js.map +7 -0
  99. package/lib/esm/src/solanaToken/domain/SolanaTokenContextLoader.test.js +2 -0
  100. package/lib/esm/src/solanaToken/domain/SolanaTokenContextLoader.test.js.map +7 -0
  101. package/lib/types/src/di.d.ts.map +1 -1
  102. package/lib/types/src/index.d.ts +2 -0
  103. package/lib/types/src/index.d.ts.map +1 -1
  104. package/lib/types/src/shared/domain/ContextFieldLoader.d.ts +14 -4
  105. package/lib/types/src/shared/domain/ContextFieldLoader.d.ts.map +1 -1
  106. package/lib/types/src/shared/model/ClearSignContext.d.ts +59 -32
  107. package/lib/types/src/shared/model/ClearSignContext.d.ts.map +1 -1
  108. package/lib/types/src/shared/model/SolanaContextTypes.d.ts +47 -0
  109. package/lib/types/src/shared/model/SolanaContextTypes.d.ts.map +1 -0
  110. package/lib/types/src/shared/model/SolanaTransactionContext.d.ts +2 -0
  111. package/lib/types/src/shared/model/SolanaTransactionContext.d.ts.map +1 -1
  112. package/lib/types/src/solana/data/HttpSolanaOwnerInfoDataSource.d.ts.map +1 -1
  113. package/lib/types/src/solana/data/SolanaDataSource.d.ts +1 -4
  114. package/lib/types/src/solana/data/SolanaDataSource.d.ts.map +1 -1
  115. package/lib/types/src/solana/domain/DefaultSolanaContextLoader.d.ts +5 -3
  116. package/lib/types/src/solana/domain/DefaultSolanaContextLoader.d.ts.map +1 -1
  117. package/lib/types/src/solana/domain/solanaContextTypes.d.ts +7 -5
  118. package/lib/types/src/solana/domain/solanaContextTypes.d.ts.map +1 -1
  119. package/lib/types/src/solanaLifi/data/HttpSolanaLifiDataSource.d.ts +9 -0
  120. package/lib/types/src/solanaLifi/data/HttpSolanaLifiDataSource.d.ts.map +1 -0
  121. package/lib/types/src/solanaLifi/data/HttpSolanaLifiDataSource.test.d.ts +2 -0
  122. package/lib/types/src/solanaLifi/data/HttpSolanaLifiDataSource.test.d.ts.map +1 -0
  123. package/lib/types/src/solanaLifi/data/SolanaLifiDataSource.d.ts +13 -0
  124. package/lib/types/src/solanaLifi/data/SolanaLifiDataSource.d.ts.map +1 -0
  125. package/lib/types/src/solanaLifi/di/lifiModuleFactory.d.ts +3 -0
  126. package/lib/types/src/solanaLifi/di/lifiModuleFactory.d.ts.map +1 -0
  127. package/lib/types/src/solanaLifi/di/solanaLifiTypes.d.ts +5 -0
  128. package/lib/types/src/solanaLifi/di/solanaLifiTypes.d.ts.map +1 -0
  129. package/lib/types/src/solanaLifi/domain/SolanaLifiContextLoader.d.ts +16 -0
  130. package/lib/types/src/solanaLifi/domain/SolanaLifiContextLoader.d.ts.map +1 -0
  131. package/lib/types/src/solanaLifi/domain/SolanaLifiContextLoader.test.d.ts +2 -0
  132. package/lib/types/src/solanaLifi/domain/SolanaLifiContextLoader.test.d.ts.map +1 -0
  133. package/lib/types/src/solanaToken/data/HttpSolanaTokenDataSource.d.ts +9 -0
  134. package/lib/types/src/solanaToken/data/HttpSolanaTokenDataSource.d.ts.map +1 -0
  135. package/lib/types/src/solanaToken/data/HttpSolanaTokenDataSource.test.d.ts +2 -0
  136. package/lib/types/src/solanaToken/data/HttpSolanaTokenDataSource.test.d.ts.map +1 -0
  137. package/lib/types/src/solanaToken/data/SolanaTokenDataSource.d.ts +44 -0
  138. package/lib/types/src/solanaToken/data/SolanaTokenDataSource.d.ts.map +1 -0
  139. package/lib/types/src/solanaToken/di/solanaTokenTypes.d.ts +5 -0
  140. package/lib/types/src/solanaToken/di/solanaTokenTypes.d.ts.map +1 -0
  141. package/lib/types/src/solanaToken/di/tokenModuleFactory.d.ts +3 -0
  142. package/lib/types/src/solanaToken/di/tokenModuleFactory.d.ts.map +1 -0
  143. package/lib/types/src/solanaToken/domain/SolanaTokenContextLoader.d.ts +22 -0
  144. package/lib/types/src/solanaToken/domain/SolanaTokenContextLoader.d.ts.map +1 -0
  145. package/lib/types/src/solanaToken/domain/SolanaTokenContextLoader.test.d.ts +2 -0
  146. package/lib/types/src/solanaToken/domain/SolanaTokenContextLoader.test.d.ts.map +1 -0
  147. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  148. package/package.json +8 -8
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/DefaultContextModule.test.ts"],
4
- "sourcesContent": ["import { type ContextModuleConfig } from \"./config/model/ContextModuleConfig\";\nimport { type ContextFieldLoader } from \"./shared/domain/ContextFieldLoader\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport {\n type ClearSignContext,\n ClearSignContextType,\n} from \"./shared/model/ClearSignContext\";\nimport { type TypedDataContext } from \"./shared/model/TypedDataContext\";\nimport type { TypedDataContextLoader } from \"./typed-data/domain/TypedDataContextLoader\";\nimport { DefaultContextModule } from \"./DefaultContextModule\";\n\nconst contextLoaderStubBuilder = (canHandle: boolean): ContextLoader => {\n return {\n load: vi.fn(),\n canHandle: vi\n .fn()\n .mockReturnValue(canHandle) as unknown as ContextLoader[\"canHandle\"],\n };\n};\n\nconst fieldLoaderStubBuilder = (): ContextFieldLoader => {\n return {\n canHandle: vi.fn(),\n loadField: vi.fn(),\n };\n};\n\ndescribe(\"DefaultContextModule\", () => {\n const typedDataLoader: TypedDataContextLoader = { load: vi.fn() };\n const defaultContextModuleConfig: ContextModuleConfig = {\n customLoaders: [],\n defaultLoaders: false,\n defaultFieldLoaders: false,\n customFieldLoaders: [],\n customTypedDataLoader: typedDataLoader,\n cal: {\n url: \"https://cal/v1\",\n mode: \"prod\",\n branch: \"main\",\n },\n web3checks: {\n url: \"https://web3checks/v3\",\n },\n metadataServiceDomain: {\n url: \"https://metadata.com\",\n },\n originToken: \"originToken\",\n };\n\n beforeEach(() => {\n vi.restoreAllMocks();\n });\n\n it(\"should initialize the context module with all the default loaders\", async () => {\n const contextModule = new DefaultContextModule(defaultContextModuleConfig);\n\n const res = await contextModule.getContexts({});\n\n expect(res).toEqual([]);\n });\n\n it(\"should return an empty array when no loaders\", async () => {\n const contextModule = new DefaultContextModule(defaultContextModuleConfig);\n\n const res = await contextModule.getContexts({});\n\n expect(res).toEqual([]);\n });\n\n it(\"should call all fetch method from metadata fetcher\", async () => {\n const loader = contextLoaderStubBuilder(true);\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader, loader],\n });\n\n await contextModule.getContexts({});\n\n expect(loader.canHandle).toHaveBeenCalledTimes(2);\n expect(loader.load).toHaveBeenCalledTimes(2);\n });\n\n it(\"should return an array of context response\", async () => {\n const loader = contextLoaderStubBuilder(true);\n const responses = [\n [{ type: \"provideERC20Info\", payload: \"payload1\" }],\n [\n { type: \"provideERC20Info\", payload: \"payload2\" },\n { type: \"plugin\", payload: \"payload3\" },\n ],\n ] as ClearSignContext[][];\n vi.spyOn(loader, \"load\")\n .mockResolvedValueOnce(responses[0]!)\n .mockResolvedValueOnce(responses[1]!);\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader, loader],\n });\n\n const res = await contextModule.getContexts({});\n\n expect(loader.canHandle).toHaveBeenCalledTimes(2);\n expect(loader.load).toHaveBeenCalledTimes(2);\n expect(res).toEqual(responses.flat());\n });\n\n it(\"should only call loaders that can handle the input\", async () => {\n const loader1 = contextLoaderStubBuilder(true);\n const loader2 = contextLoaderStubBuilder(true);\n\n vi.spyOn(loader1, \"canHandle\").mockReturnValue(true);\n vi.spyOn(loader2, \"canHandle\").mockReturnValue(false);\n vi.spyOn(loader1, \"load\").mockResolvedValue([\n { type: ClearSignContextType.TOKEN, payload: \"payload1\" },\n ]);\n vi.spyOn(loader2, \"load\").mockResolvedValue([\n { type: ClearSignContextType.NFT, payload: \"payload2\" },\n ]);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader1, loader2],\n });\n\n const testInput = { to: \"0x123\", selector: \"0xabc\" };\n const res = await contextModule.getContexts(testInput);\n\n expect(loader1.canHandle).toHaveBeenCalledWith(\n testInput,\n Object.values(ClearSignContextType),\n );\n expect(loader2.canHandle).toHaveBeenCalledWith(\n testInput,\n Object.values(ClearSignContextType),\n );\n expect(loader1.load).toHaveBeenCalledWith(testInput);\n expect(loader2.load).not.toHaveBeenCalled(); // Should not be called since canHandle returned false\n expect(res).toEqual([{ type: \"token\", payload: \"payload1\" }]);\n });\n\n it(\"should use expected types if provided\", async () => {\n const loader = contextLoaderStubBuilder(true);\n\n vi.spyOn(loader, \"canHandle\").mockReturnValue(true);\n\n vi.spyOn(loader, \"load\").mockResolvedValue([\n { type: ClearSignContextType.TOKEN, payload: \"payload1\" },\n ]);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader],\n });\n\n const testInput = { to: \"0x123\", selector: \"0xabc\" };\n await contextModule.getContexts(testInput, [ClearSignContextType.TOKEN]);\n\n expect(loader.canHandle).toHaveBeenCalledWith(testInput, [\n ClearSignContextType.TOKEN,\n ]);\n });\n\n it(\"should call the typed data loader\", async () => {\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customTypedDataLoader: typedDataLoader,\n });\n\n await contextModule.getTypedDataFilters({} as TypedDataContext);\n\n expect(typedDataLoader.load).toHaveBeenCalledTimes(1);\n });\n\n describe(\"getFieldContext\", () => {\n it(\"should return error when no loader can handle the field\", async () => {\n // GIVEN\n const fieldLoader = fieldLoaderStubBuilder();\n vi.spyOn(fieldLoader, \"canHandle\").mockReturnValue(false);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader],\n });\n\n const testField = { type: \"unknown\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader.loadField).not.toHaveBeenCalled();\n expect(result).toEqual({\n type: ClearSignContextType.ERROR,\n error: new Error(\n `Loader not found for field: ${testField} and expected type: ${ClearSignContextType.TOKEN}`,\n ),\n });\n });\n\n it(\"should return context when a loader can handle the field\", async () => {\n // GIVEN\n const fieldLoader = fieldLoaderStubBuilder();\n const mockContext: ClearSignContext = {\n type: ClearSignContextType.TOKEN,\n payload: \"test-payload\",\n };\n\n vi.spyOn(fieldLoader, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader, \"loadField\").mockResolvedValue(mockContext);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader],\n });\n\n const testField = { type: \"token\", address: \"0x123\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader.loadField).toHaveBeenCalledWith(testField);\n expect(result).toEqual(mockContext);\n });\n\n it(\"should return first context when multiple loaders can handle the field\", async () => {\n // GIVEN\n const fieldLoader1 = fieldLoaderStubBuilder();\n const fieldLoader2 = fieldLoaderStubBuilder();\n\n const mockContext1: ClearSignContext = {\n type: ClearSignContextType.TOKEN,\n payload: \"first-payload\",\n };\n const mockContext2: ClearSignContext = {\n type: ClearSignContextType.NFT,\n payload: \"second-payload\",\n };\n\n vi.spyOn(fieldLoader1, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader2, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader1, \"loadField\").mockResolvedValue(mockContext1);\n vi.spyOn(fieldLoader2, \"loadField\").mockResolvedValue(mockContext2);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader1, fieldLoader2],\n });\n\n const testField = { type: \"multi\", address: \"0x123\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader1.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader2.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader1.loadField).toHaveBeenCalledWith(testField);\n expect(fieldLoader2.loadField).not.toHaveBeenCalled();\n expect(result).toEqual(mockContext1); // Should return first context\n });\n\n it(\"should return second context when first context is an error\", async () => {\n // GIVEN\n const fieldLoader1 = fieldLoaderStubBuilder();\n const fieldLoader2 = fieldLoaderStubBuilder();\n const mockContext1: ClearSignContext = {\n type: ClearSignContextType.ERROR,\n error: new Error(\"first-error\"),\n };\n const mockContext2: ClearSignContext = {\n type: ClearSignContextType.TOKEN,\n payload: \"second-payload\",\n };\n vi.spyOn(fieldLoader1, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader2, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader1, \"loadField\").mockResolvedValue(mockContext1);\n vi.spyOn(fieldLoader2, \"loadField\").mockResolvedValue(mockContext2);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader1, fieldLoader2],\n });\n\n const testField = { type: \"error\", address: \"0x123\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader1.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader2.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader1.loadField).toHaveBeenCalledWith(testField);\n expect(fieldLoader2.loadField).toHaveBeenCalledWith(testField);\n expect(result).toEqual(mockContext2);\n });\n\n it(\"should handle loader rejection gracefully\", async () => {\n // GIVEN\n const fieldLoader = fieldLoaderStubBuilder();\n const loadError = new Error(\"Load field failed\");\n\n vi.spyOn(fieldLoader, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader, \"loadField\").mockRejectedValue(loadError);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader],\n });\n\n const testField = { type: \"error\", address: \"0x123\" };\n\n // WHEN & THEN\n await expect(\n contextModule.getFieldContext(testField, ClearSignContextType.TOKEN),\n ).rejects.toThrow(\"Load field failed\");\n\n expect(fieldLoader.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader.loadField).toHaveBeenCalledWith(testField);\n });\n });\n});\n"],
4
+ "sourcesContent": ["import { type ContextModuleConfig } from \"./config/model/ContextModuleConfig\";\nimport { type ContextFieldLoader } from \"./shared/domain/ContextFieldLoader\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport {\n type ClearSignContext,\n ClearSignContextType,\n} from \"./shared/model/ClearSignContext\";\nimport { type TypedDataContext } from \"./shared/model/TypedDataContext\";\nimport type { TypedDataContextLoader } from \"./typed-data/domain/TypedDataContextLoader\";\nimport { DefaultContextModule } from \"./DefaultContextModule\";\n\nconst contextLoaderStubBuilder = (canHandle: boolean): ContextLoader => {\n return {\n load: vi.fn(),\n canHandle: vi\n .fn()\n .mockReturnValue(canHandle) as unknown as ContextLoader[\"canHandle\"],\n };\n};\n\nconst fieldLoaderStubBuilder = (): ContextFieldLoader => {\n return {\n canHandle: vi.fn() as unknown as ContextFieldLoader[\"canHandle\"],\n loadField: vi.fn(),\n };\n};\n\ndescribe(\"DefaultContextModule\", () => {\n const typedDataLoader: TypedDataContextLoader = { load: vi.fn() };\n const defaultContextModuleConfig: ContextModuleConfig = {\n customLoaders: [],\n defaultLoaders: false,\n defaultFieldLoaders: false,\n customFieldLoaders: [],\n customTypedDataLoader: typedDataLoader,\n cal: {\n url: \"https://cal/v1\",\n mode: \"prod\",\n branch: \"main\",\n },\n web3checks: {\n url: \"https://web3checks/v3\",\n },\n metadataServiceDomain: {\n url: \"https://metadata.com\",\n },\n originToken: \"originToken\",\n };\n\n beforeEach(() => {\n vi.restoreAllMocks();\n });\n\n it(\"should initialize the context module with all the default loaders\", async () => {\n const contextModule = new DefaultContextModule(defaultContextModuleConfig);\n\n const res = await contextModule.getContexts({});\n\n expect(res).toEqual([]);\n });\n\n it(\"should return an empty array when no loaders\", async () => {\n const contextModule = new DefaultContextModule(defaultContextModuleConfig);\n\n const res = await contextModule.getContexts({});\n\n expect(res).toEqual([]);\n });\n\n it(\"should call all fetch method from metadata fetcher\", async () => {\n const loader = contextLoaderStubBuilder(true);\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader, loader],\n });\n\n await contextModule.getContexts({});\n\n expect(loader.canHandle).toHaveBeenCalledTimes(2);\n expect(loader.load).toHaveBeenCalledTimes(2);\n });\n\n it(\"should return an array of context response\", async () => {\n const loader = contextLoaderStubBuilder(true);\n const responses = [\n [{ type: \"provideERC20Info\", payload: \"payload1\" }],\n [\n { type: \"provideERC20Info\", payload: \"payload2\" },\n { type: \"plugin\", payload: \"payload3\" },\n ],\n ] as ClearSignContext[][];\n vi.spyOn(loader, \"load\")\n .mockResolvedValueOnce(responses[0]!)\n .mockResolvedValueOnce(responses[1]!);\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader, loader],\n });\n\n const res = await contextModule.getContexts({});\n\n expect(loader.canHandle).toHaveBeenCalledTimes(2);\n expect(loader.load).toHaveBeenCalledTimes(2);\n expect(res).toEqual(responses.flat());\n });\n\n it(\"should only call loaders that can handle the input\", async () => {\n const loader1 = contextLoaderStubBuilder(true);\n const loader2 = contextLoaderStubBuilder(true);\n\n vi.spyOn(loader1, \"canHandle\").mockReturnValue(true);\n vi.spyOn(loader2, \"canHandle\").mockReturnValue(false);\n vi.spyOn(loader1, \"load\").mockResolvedValue([\n { type: ClearSignContextType.TOKEN, payload: \"payload1\" },\n ]);\n vi.spyOn(loader2, \"load\").mockResolvedValue([\n { type: ClearSignContextType.NFT, payload: \"payload2\" },\n ]);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader1, loader2],\n });\n\n const testInput = { to: \"0x123\", selector: \"0xabc\" };\n const res = await contextModule.getContexts(testInput);\n\n expect(loader1.canHandle).toHaveBeenCalledWith(\n testInput,\n Object.values(ClearSignContextType),\n );\n expect(loader2.canHandle).toHaveBeenCalledWith(\n testInput,\n Object.values(ClearSignContextType),\n );\n expect(loader1.load).toHaveBeenCalledWith(testInput);\n expect(loader2.load).not.toHaveBeenCalled(); // Should not be called since canHandle returned false\n expect(res).toEqual([{ type: \"token\", payload: \"payload1\" }]);\n });\n\n it(\"should use expected types if provided\", async () => {\n const loader = contextLoaderStubBuilder(true);\n\n vi.spyOn(loader, \"canHandle\").mockReturnValue(true);\n\n vi.spyOn(loader, \"load\").mockResolvedValue([\n { type: ClearSignContextType.TOKEN, payload: \"payload1\" },\n ]);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader],\n });\n\n const testInput = { to: \"0x123\", selector: \"0xabc\" };\n await contextModule.getContexts(testInput, [ClearSignContextType.TOKEN]);\n\n expect(loader.canHandle).toHaveBeenCalledWith(testInput, [\n ClearSignContextType.TOKEN,\n ]);\n });\n\n it(\"should call the typed data loader\", async () => {\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customTypedDataLoader: typedDataLoader,\n });\n\n await contextModule.getTypedDataFilters({} as TypedDataContext);\n\n expect(typedDataLoader.load).toHaveBeenCalledTimes(1);\n });\n\n describe(\"getFieldContext\", () => {\n it(\"should return error when no loader can handle the field\", async () => {\n // GIVEN\n const fieldLoader = fieldLoaderStubBuilder();\n vi.spyOn(fieldLoader, \"canHandle\").mockReturnValue(false);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader],\n });\n\n const testField = { type: \"unknown\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader.loadField).not.toHaveBeenCalled();\n expect(result).toEqual({\n type: ClearSignContextType.ERROR,\n error: new Error(\n `Loader not found for field: ${testField} and expected type: ${ClearSignContextType.TOKEN}`,\n ),\n });\n });\n\n it(\"should return context when a loader can handle the field\", async () => {\n // GIVEN\n const fieldLoader = fieldLoaderStubBuilder();\n const mockContext: ClearSignContext = {\n type: ClearSignContextType.TOKEN,\n payload: \"test-payload\",\n };\n\n vi.spyOn(fieldLoader, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader, \"loadField\").mockResolvedValue(mockContext);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader],\n });\n\n const testField = { type: \"token\", address: \"0x123\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader.loadField).toHaveBeenCalledWith(testField);\n expect(result).toEqual(mockContext);\n });\n\n it(\"should return first context when multiple loaders can handle the field\", async () => {\n // GIVEN\n const fieldLoader1 = fieldLoaderStubBuilder();\n const fieldLoader2 = fieldLoaderStubBuilder();\n\n const mockContext1: ClearSignContext = {\n type: ClearSignContextType.TOKEN,\n payload: \"first-payload\",\n };\n const mockContext2: ClearSignContext = {\n type: ClearSignContextType.NFT,\n payload: \"second-payload\",\n };\n\n vi.spyOn(fieldLoader1, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader2, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader1, \"loadField\").mockResolvedValue(mockContext1);\n vi.spyOn(fieldLoader2, \"loadField\").mockResolvedValue(mockContext2);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader1, fieldLoader2],\n });\n\n const testField = { type: \"multi\", address: \"0x123\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader1.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader2.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader1.loadField).toHaveBeenCalledWith(testField);\n expect(fieldLoader2.loadField).not.toHaveBeenCalled();\n expect(result).toEqual(mockContext1); // Should return first context\n });\n\n it(\"should return second context when first context is an error\", async () => {\n // GIVEN\n const fieldLoader1 = fieldLoaderStubBuilder();\n const fieldLoader2 = fieldLoaderStubBuilder();\n const mockContext1: ClearSignContext = {\n type: ClearSignContextType.ERROR,\n error: new Error(\"first-error\"),\n };\n const mockContext2: ClearSignContext = {\n type: ClearSignContextType.TOKEN,\n payload: \"second-payload\",\n };\n vi.spyOn(fieldLoader1, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader2, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader1, \"loadField\").mockResolvedValue(mockContext1);\n vi.spyOn(fieldLoader2, \"loadField\").mockResolvedValue(mockContext2);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader1, fieldLoader2],\n });\n\n const testField = { type: \"error\", address: \"0x123\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader1.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader2.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader1.loadField).toHaveBeenCalledWith(testField);\n expect(fieldLoader2.loadField).toHaveBeenCalledWith(testField);\n expect(result).toEqual(mockContext2);\n });\n\n it(\"should handle loader rejection gracefully\", async () => {\n // GIVEN\n const fieldLoader = fieldLoaderStubBuilder();\n const loadError = new Error(\"Load field failed\");\n\n vi.spyOn(fieldLoader, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader, \"loadField\").mockRejectedValue(loadError);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader],\n });\n\n const testField = { type: \"error\", address: \"0x123\" };\n\n // WHEN & THEN\n await expect(\n contextModule.getFieldContext(testField, ClearSignContextType.TOKEN),\n ).rejects.toThrow(\"Load field failed\");\n\n expect(fieldLoader.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader.loadField).toHaveBeenCalledWith(testField);\n });\n });\n});\n"],
5
5
  "mappings": "AAGA,OAEE,wBAAAA,MACK,kCAGP,OAAS,wBAAAC,MAA4B,yBAErC,MAAMC,EAA4BC,IACzB,CACL,KAAM,GAAG,GAAG,EACZ,UAAW,GACR,GAAG,EACH,gBAAgBA,CAAS,CAC9B,GAGIC,EAAyB,KACtB,CACL,UAAW,GAAG,GAAG,EACjB,UAAW,GAAG,GAAG,CACnB,GAGF,SAAS,uBAAwB,IAAM,CACrC,MAAMC,EAA0C,CAAE,KAAM,GAAG,GAAG,CAAE,EAC1DC,EAAkD,CACtD,cAAe,CAAC,EAChB,eAAgB,GAChB,oBAAqB,GACrB,mBAAoB,CAAC,EACrB,sBAAuBD,EACvB,IAAK,CACH,IAAK,iBACL,KAAM,OACN,OAAQ,MACV,EACA,WAAY,CACV,IAAK,uBACP,EACA,sBAAuB,CACrB,IAAK,sBACP,EACA,YAAa,aACf,EAEA,WAAW,IAAM,CACf,GAAG,gBAAgB,CACrB,CAAC,EAED,GAAG,oEAAqE,SAAY,CAGlF,MAAME,EAAM,MAFU,IAAIN,EAAqBK,CAA0B,EAEzC,YAAY,CAAC,CAAC,EAE9C,OAAOC,CAAG,EAAE,QAAQ,CAAC,CAAC,CACxB,CAAC,EAED,GAAG,+CAAgD,SAAY,CAG7D,MAAMA,EAAM,MAFU,IAAIN,EAAqBK,CAA0B,EAEzC,YAAY,CAAC,CAAC,EAE9C,OAAOC,CAAG,EAAE,QAAQ,CAAC,CAAC,CACxB,CAAC,EAED,GAAG,qDAAsD,SAAY,CACnE,MAAMC,EAASN,EAAyB,EAAI,EAM5C,MALsB,IAAID,EA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Af,EAAqB,KACvB,EAGA,OAAOkB,EAAa,SAAS,EAAE,qBAC7BH,EACAf,EAAqB,KACvB,EACA,OAAOmB,EAAa,SAAS,EAAE,qBAC7BJ,EACAf,EAAqB,KACvB,EACA,OAAOkB,EAAa,SAAS,EAAE,qBAAqBH,CAAS,EAC7D,OAAOI,EAAa,SAAS,EAAE,qBAAqBJ,CAAS,EAC7D,OAAOC,CAAM,EAAE,QAAQK,CAAY,CACrC,CAAC,EAED,GAAG,4CAA6C,SAAY,CAE1D,MAAMP,EAAcV,EAAuB,EACrCkB,EAAY,IAAI,MAAM,mBAAmB,EAE/C,GAAG,MAAMR,EAAa,WAAW,EAAE,gBAAgB,EAAI,EACvD,GAAG,MAAMA,EAAa,WAAW,EAAE,kBAAkBQ,CAAS,EAE9D,MAAMV,EAAgB,IAAIX,EAAqB,CAC7C,GAAGK,EACH,mBAAoB,CAACQ,CAAW,CAClC,CAAC,EAEKC,EAAY,CAAE,KAAM,QAAS,QAAS,OAAQ,EAGpD,MAAM,OACJH,EAAc,gBAAgBG,EAAWf,EAAqB,KAAK,CACrE,EAAE,QAAQ,QAAQ,mBAAmB,EAErC,OAAOc,EAAY,SAAS,EAAE,qBAC5BC,EACAf,EAAqB,KACvB,EACA,OAAOc,EAAY,SAAS,EAAE,qBAAqBC,CAAS,CAC9D,CAAC,CACH,CAAC,CACH,CAAC",
6
6
  "names": ["ClearSignContextType", "DefaultContextModule", "contextLoaderStubBuilder", "canHandle", "fieldLoaderStubBuilder", "typedDataLoader", "defaultContextModuleConfig", "res", "loader", "responses", "loader1", "loader2", "contextModule", "testInput", "fieldLoader", "testField", "result", "mockContext", "fieldLoader1", "fieldLoader2", "mockContext1", "mockContext2", "loadError"]
7
7
  }
package/lib/esm/src/di.js CHANGED
@@ -1,2 +1,2 @@
1
- import{Container as t}from"inversify";import{calldataModuleFactory as e}from"./calldata/di/calldataModuleFactory";import{configModuleFactory as a}from"./config/di/configModuleFactory";import{dynamicNetworkModuleFactory as m}from"./dynamic-network/di/dynamicNetworkModuleFactory";import{externalPluginModuleFactory as n}from"./external-plugin/di/externalPluginModuleFactory";import{nftModuleFactory as i}from"./nft/di/nftModuleFactory";import{nanoPkiModuleFactory as c}from"./pki/di/pkiModuleFactory";import{proxyModuleFactory as l}from"./proxy/di/proxyModuleFactory";import{safeModuleFactory as p}from"./safe/di/safeModuleFactory";import{solanaContextModuleFactory as d}from"./solana/di/SolanaContextModuleFactory";import{tokenModuleFactory as f}from"./token/di/tokenModuleFactory";import{transactionCheckModuleFactory as u}from"./transaction-check/di/transactionCheckModuleFactory";import{trustedNameModuleFactory as y}from"./trusted-name/di/trustedNameModuleFactory";import{typedDataModuleFactory as M}from"./typed-data/di/typedDataModuleFactory";import{uniswapModuleFactory as F}from"./uniswap/di/uniswapModuleFactory";const v=({config:o})=>{const r=new t;return r.loadSync(a(o),n(),m(),i(),l(o),p(),f(),e(),y(),M(),c(),F(),u(),d()),r};export{v as makeContainer};
1
+ import{Container as t}from"inversify";import{calldataModuleFactory as a}from"./calldata/di/calldataModuleFactory";import{configModuleFactory as e}from"./config/di/configModuleFactory";import{dynamicNetworkModuleFactory as m}from"./dynamic-network/di/dynamicNetworkModuleFactory";import{externalPluginModuleFactory as n}from"./external-plugin/di/externalPluginModuleFactory";import{nftModuleFactory as i}from"./nft/di/nftModuleFactory";import{nanoPkiModuleFactory as l}from"./pki/di/pkiModuleFactory";import{proxyModuleFactory as c}from"./proxy/di/proxyModuleFactory";import{safeModuleFactory as f}from"./safe/di/safeModuleFactory";import{solanaContextModuleFactory as p}from"./solana/di/SolanaContextModuleFactory";import{solanaLifiModuleFactory as d}from"./solanaLifi/di/lifiModuleFactory";import{solanaTokenModuleFactory as u}from"./solanaToken/di/tokenModuleFactory";import{tokenModuleFactory as y}from"./token/di/tokenModuleFactory";import{transactionCheckModuleFactory as M}from"./transaction-check/di/transactionCheckModuleFactory";import{trustedNameModuleFactory as F}from"./trusted-name/di/trustedNameModuleFactory";import{typedDataModuleFactory as s}from"./typed-data/di/typedDataModuleFactory";import{uniswapModuleFactory as C}from"./uniswap/di/uniswapModuleFactory";const B=({config:o})=>{const r=new t;return r.loadSync(e(o),n(),m(),i(),c(o),f(),y(),a(),F(),s(),l(),C(),M(),p(),u(),d()),r};export{B as makeContainer};
2
2
  //# sourceMappingURL=di.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/di.ts"],
4
- "sourcesContent": ["import { Container } from \"inversify\";\n\nimport { calldataModuleFactory } from \"@/calldata/di/calldataModuleFactory\";\nimport { configModuleFactory } from \"@/config/di/configModuleFactory\";\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { dynamicNetworkModuleFactory } from \"@/dynamic-network/di/dynamicNetworkModuleFactory\";\nimport { externalPluginModuleFactory } from \"@/external-plugin/di/externalPluginModuleFactory\";\nimport { nftModuleFactory } from \"@/nft/di/nftModuleFactory\";\nimport { nanoPkiModuleFactory } from \"@/pki/di/pkiModuleFactory\";\nimport { proxyModuleFactory } from \"@/proxy/di/proxyModuleFactory\";\nimport { safeModuleFactory } from \"@/safe/di/safeModuleFactory\";\nimport { solanaContextModuleFactory } from \"@/solana/di/SolanaContextModuleFactory\";\nimport { tokenModuleFactory } from \"@/token/di/tokenModuleFactory\";\nimport { transactionCheckModuleFactory } from \"@/transaction-check/di/transactionCheckModuleFactory\";\nimport { trustedNameModuleFactory } from \"@/trusted-name/di/trustedNameModuleFactory\";\nimport { typedDataModuleFactory } from \"@/typed-data/di/typedDataModuleFactory\";\nimport { uniswapModuleFactory } from \"@/uniswap/di/uniswapModuleFactory\";\n\ntype MakeContainerArgs = {\n config: ContextModuleConfig;\n};\n\nexport const makeContainer = ({ config }: MakeContainerArgs) => {\n const container = new Container();\n\n container.loadSync(\n configModuleFactory(config),\n externalPluginModuleFactory(),\n dynamicNetworkModuleFactory(),\n nftModuleFactory(),\n proxyModuleFactory(config),\n safeModuleFactory(),\n tokenModuleFactory(),\n calldataModuleFactory(),\n trustedNameModuleFactory(),\n typedDataModuleFactory(),\n nanoPkiModuleFactory(),\n uniswapModuleFactory(),\n transactionCheckModuleFactory(),\n solanaContextModuleFactory(),\n );\n\n return container;\n};\n"],
5
- "mappings": "AAAA,OAAS,aAAAA,MAAiB,YAE1B,OAAS,yBAAAC,MAA6B,sCACtC,OAAS,uBAAAC,MAA2B,kCAEpC,OAAS,+BAAAC,MAAmC,mDAC5C,OAAS,+BAAAC,MAAmC,mDAC5C,OAAS,oBAAAC,MAAwB,4BACjC,OAAS,wBAAAC,MAA4B,4BACrC,OAAS,sBAAAC,MAA0B,gCACnC,OAAS,qBAAAC,MAAyB,8BAClC,OAAS,8BAAAC,MAAkC,yCAC3C,OAAS,sBAAAC,MAA0B,gCACnC,OAAS,iCAAAC,MAAqC,uDAC9C,OAAS,4BAAAC,MAAgC,6CACzC,OAAS,0BAAAC,MAA8B,yCACvC,OAAS,wBAAAC,MAA4B,oCAM9B,MAAMC,EAAgB,CAAC,CAAE,OAAAC,CAAO,IAAyB,CAC9D,MAAMC,EAAY,IAAIjB,EAEtB,OAAAiB,EAAU,SACRf,EAAoBc,CAAM,EAC1BZ,EAA4B,EAC5BD,EAA4B,EAC5BE,EAAiB,EACjBE,EAAmBS,CAAM,EACzBR,EAAkB,EAClBE,EAAmB,EACnBT,EAAsB,EACtBW,EAAyB,EACzBC,EAAuB,EACvBP,EAAqB,EACrBQ,EAAqB,EACrBH,EAA8B,EAC9BF,EAA2B,CAC7B,EAEOQ,CACT",
6
- "names": ["Container", "calldataModuleFactory", "configModuleFactory", "dynamicNetworkModuleFactory", "externalPluginModuleFactory", "nftModuleFactory", "nanoPkiModuleFactory", "proxyModuleFactory", "safeModuleFactory", "solanaContextModuleFactory", "tokenModuleFactory", "transactionCheckModuleFactory", "trustedNameModuleFactory", "typedDataModuleFactory", "uniswapModuleFactory", "makeContainer", "config", "container"]
4
+ "sourcesContent": ["import { Container } from \"inversify\";\n\nimport { calldataModuleFactory } from \"@/calldata/di/calldataModuleFactory\";\nimport { configModuleFactory } from \"@/config/di/configModuleFactory\";\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { dynamicNetworkModuleFactory } from \"@/dynamic-network/di/dynamicNetworkModuleFactory\";\nimport { externalPluginModuleFactory } from \"@/external-plugin/di/externalPluginModuleFactory\";\nimport { nftModuleFactory } from \"@/nft/di/nftModuleFactory\";\nimport { nanoPkiModuleFactory } from \"@/pki/di/pkiModuleFactory\";\nimport { proxyModuleFactory } from \"@/proxy/di/proxyModuleFactory\";\nimport { safeModuleFactory } from \"@/safe/di/safeModuleFactory\";\nimport { solanaContextModuleFactory } from \"@/solana/di/SolanaContextModuleFactory\";\nimport { solanaLifiModuleFactory } from \"@/solanaLifi/di/lifiModuleFactory\";\nimport { solanaTokenModuleFactory } from \"@/solanaToken/di/tokenModuleFactory\";\nimport { tokenModuleFactory } from \"@/token/di/tokenModuleFactory\";\nimport { transactionCheckModuleFactory } from \"@/transaction-check/di/transactionCheckModuleFactory\";\nimport { trustedNameModuleFactory } from \"@/trusted-name/di/trustedNameModuleFactory\";\nimport { typedDataModuleFactory } from \"@/typed-data/di/typedDataModuleFactory\";\nimport { uniswapModuleFactory } from \"@/uniswap/di/uniswapModuleFactory\";\n\ntype MakeContainerArgs = {\n config: ContextModuleConfig;\n};\n\nexport const makeContainer = ({ config }: MakeContainerArgs) => {\n const container = new Container();\n\n container.loadSync(\n configModuleFactory(config),\n externalPluginModuleFactory(),\n dynamicNetworkModuleFactory(),\n nftModuleFactory(),\n proxyModuleFactory(config),\n safeModuleFactory(),\n tokenModuleFactory(),\n calldataModuleFactory(),\n trustedNameModuleFactory(),\n typedDataModuleFactory(),\n nanoPkiModuleFactory(),\n uniswapModuleFactory(),\n transactionCheckModuleFactory(),\n solanaContextModuleFactory(),\n solanaTokenModuleFactory(),\n solanaLifiModuleFactory(),\n );\n\n return container;\n};\n"],
5
+ "mappings": "AAAA,OAAS,aAAAA,MAAiB,YAE1B,OAAS,yBAAAC,MAA6B,sCACtC,OAAS,uBAAAC,MAA2B,kCAEpC,OAAS,+BAAAC,MAAmC,mDAC5C,OAAS,+BAAAC,MAAmC,mDAC5C,OAAS,oBAAAC,MAAwB,4BACjC,OAAS,wBAAAC,MAA4B,4BACrC,OAAS,sBAAAC,MAA0B,gCACnC,OAAS,qBAAAC,MAAyB,8BAClC,OAAS,8BAAAC,MAAkC,yCAC3C,OAAS,2BAAAC,MAA+B,oCACxC,OAAS,4BAAAC,MAAgC,sCACzC,OAAS,sBAAAC,MAA0B,gCACnC,OAAS,iCAAAC,MAAqC,uDAC9C,OAAS,4BAAAC,MAAgC,6CACzC,OAAS,0BAAAC,MAA8B,yCACvC,OAAS,wBAAAC,MAA4B,oCAM9B,MAAMC,EAAgB,CAAC,CAAE,OAAAC,CAAO,IAAyB,CAC9D,MAAMC,EAAY,IAAInB,EAEtB,OAAAmB,EAAU,SACRjB,EAAoBgB,CAAM,EAC1Bd,EAA4B,EAC5BD,EAA4B,EAC5BE,EAAiB,EACjBE,EAAmBW,CAAM,EACzBV,EAAkB,EAClBI,EAAmB,EACnBX,EAAsB,EACtBa,EAAyB,EACzBC,EAAuB,EACvBT,EAAqB,EACrBU,EAAqB,EACrBH,EAA8B,EAC9BJ,EAA2B,EAC3BE,EAAyB,EACzBD,EAAwB,CAC1B,EAEOS,CACT",
6
+ "names": ["Container", "calldataModuleFactory", "configModuleFactory", "dynamicNetworkModuleFactory", "externalPluginModuleFactory", "nftModuleFactory", "nanoPkiModuleFactory", "proxyModuleFactory", "safeModuleFactory", "solanaContextModuleFactory", "solanaLifiModuleFactory", "solanaTokenModuleFactory", "tokenModuleFactory", "transactionCheckModuleFactory", "trustedNameModuleFactory", "typedDataModuleFactory", "uniswapModuleFactory", "makeContainer", "config", "container"]
7
7
  }
@@ -1,2 +1,2 @@
1
- export*from"./calldata/data/CalldataDescriptorDataSource";export*from"./calldata/data/HttpCalldataDescriptorDataSource";export*from"./calldata/domain/CalldataContextLoader";export*from"./config/model/ContextModuleConfig";export*from"./ContextModule";export*from"./ContextModuleBuilder";export*from"./DefaultContextModule";export*from"./dynamic-network/data/DynamicNetworkDataSource";export*from"./dynamic-network/data/HttpDynamicNetworkDataSource";export*from"./dynamic-network/domain/DynamicNetworkContextLoader";export*from"./dynamic-network/model/DynamicNetworkConfiguration";export*from"./external-plugin/data/ExternalPluginDataSource";export*from"./external-plugin/data/HttpExternalPluginDataSource";export*from"./external-plugin/domain/ExternalPluginContextLoader";export*from"./nft/data/HttpNftDataSource";export*from"./nft/data/NftDataSource";export*from"./nft/domain/NftContextFieldLoader";export*from"./nft/domain/NftContextLoader";export*from"./pki/data/HttpPkiCertificateDataSource";export*from"./pki/data/PkiCertificateDataSource";export*from"./pki/domain/DefaultPkiCertificateLoader";export*from"./pki/domain/PkiCertificateLoader";export*from"./pki/model/KeyId";export*from"./pki/model/KeyUsage";export*from"./pki/model/PkiCertificate";export*from"./pki/model/PkiCertificateInfo";export*from"./proxy/data/HttpProxyDataSource";export*from"./proxy/data/HttpSafeProxyDataSource";export*from"./proxy/data/ProxyDataSource";export*from"./proxy/domain/ProxyContextFieldLoader";export*from"./shared/domain/ContextFieldLoader";export*from"./shared/domain/ContextLoader";export*from"./shared/model/ClearSignContext";export*from"./shared/model/GenericPath";export*from"./shared/model/TransactionSubset";export*from"./shared/model/TypedDataClearSignContext";export*from"./shared/model/TypedDataContext";export*from"./solana/data/HttpSolanaOwnerInfoDataSource";export*from"./solana/data/SolanaDataSource";export*from"./solana/domain/DefaultSolanaContextLoader";export*from"./solana/domain/SolanaContextLoader";export*from"./token/data/HttpTokenDataSource";export*from"./token/data/TokenDataSource";export*from"./token/domain/TokenContextFieldLoader";export*from"./token/domain/TokenContextLoader";export*from"./trusted-name/data/HttpTrustedNameDataSource";export*from"./trusted-name/data/TrustedNameDataSource";export*from"./trusted-name/domain/TrustedNameContextFieldLoader";export*from"./trusted-name/domain/TrustedNameContextLoader";export*from"./typed-data/data/HttpTypedDataDataSource";export*from"./typed-data/data/TypedDataDataSource";export*from"./typed-data/domain/DefaultTypedDataContextLoader";export*from"./typed-data/domain/TypedDataContextLoader";export*from"./uniswap/data/AbiDecoderDataSource";export*from"./uniswap/data/CommandDecoderDataSource";export*from"./uniswap/data/DefaultCommandDecoderDataSource";export*from"./uniswap/data/EthersAbiDecoderDataSource";export*from"./uniswap/domain/UniswapContextLoader";
1
+ export*from"./calldata/data/CalldataDescriptorDataSource";export*from"./calldata/data/HttpCalldataDescriptorDataSource";export*from"./calldata/domain/CalldataContextLoader";export*from"./config/model/ContextModuleConfig";export*from"./ContextModule";export*from"./ContextModuleBuilder";export*from"./DefaultContextModule";export*from"./dynamic-network/data/DynamicNetworkDataSource";export*from"./dynamic-network/data/HttpDynamicNetworkDataSource";export*from"./dynamic-network/domain/DynamicNetworkContextLoader";export*from"./dynamic-network/model/DynamicNetworkConfiguration";export*from"./external-plugin/data/ExternalPluginDataSource";export*from"./external-plugin/data/HttpExternalPluginDataSource";export*from"./external-plugin/domain/ExternalPluginContextLoader";export*from"./nft/data/HttpNftDataSource";export*from"./nft/data/NftDataSource";export*from"./nft/domain/NftContextFieldLoader";export*from"./nft/domain/NftContextLoader";export*from"./pki/data/HttpPkiCertificateDataSource";export*from"./pki/data/PkiCertificateDataSource";export*from"./pki/domain/DefaultPkiCertificateLoader";export*from"./pki/domain/PkiCertificateLoader";export*from"./pki/model/KeyId";export*from"./pki/model/KeyUsage";export*from"./pki/model/PkiCertificate";export*from"./pki/model/PkiCertificateInfo";export*from"./proxy/data/HttpProxyDataSource";export*from"./proxy/data/HttpSafeProxyDataSource";export*from"./proxy/data/ProxyDataSource";export*from"./proxy/domain/ProxyContextFieldLoader";export*from"./shared/domain/ContextFieldLoader";export*from"./shared/domain/ContextLoader";export*from"./shared/model/ClearSignContext";export*from"./shared/model/GenericPath";export*from"./shared/model/SolanaContextTypes";export*from"./shared/model/TransactionSubset";export*from"./shared/model/TypedDataClearSignContext";export*from"./shared/model/TypedDataContext";export*from"./solana/data/HttpSolanaOwnerInfoDataSource";export*from"./solana/data/SolanaDataSource";export*from"./solana/domain/DefaultSolanaContextLoader";export*from"./solana/domain/SolanaContextLoader";export*from"./solana/domain/solanaContextTypes";export*from"./token/data/HttpTokenDataSource";export*from"./token/data/TokenDataSource";export*from"./token/domain/TokenContextFieldLoader";export*from"./token/domain/TokenContextLoader";export*from"./trusted-name/data/HttpTrustedNameDataSource";export*from"./trusted-name/data/TrustedNameDataSource";export*from"./trusted-name/domain/TrustedNameContextFieldLoader";export*from"./trusted-name/domain/TrustedNameContextLoader";export*from"./typed-data/data/HttpTypedDataDataSource";export*from"./typed-data/data/TypedDataDataSource";export*from"./typed-data/domain/DefaultTypedDataContextLoader";export*from"./typed-data/domain/TypedDataContextLoader";export*from"./uniswap/data/AbiDecoderDataSource";export*from"./uniswap/data/CommandDecoderDataSource";export*from"./uniswap/data/DefaultCommandDecoderDataSource";export*from"./uniswap/data/EthersAbiDecoderDataSource";export*from"./uniswap/domain/UniswapContextLoader";
2
2
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/index.ts"],
4
- "sourcesContent": ["export * from \"./calldata/data/CalldataDescriptorDataSource\";\nexport * from \"./calldata/data/HttpCalldataDescriptorDataSource\";\nexport * from \"./calldata/domain/CalldataContextLoader\";\nexport * from \"./config/model/ContextModuleConfig\";\nexport * from \"./ContextModule\";\nexport * from \"./ContextModuleBuilder\";\nexport * from \"./DefaultContextModule\";\nexport * from \"./dynamic-network/data/DynamicNetworkDataSource\";\nexport * from \"./dynamic-network/data/HttpDynamicNetworkDataSource\";\nexport * from \"./dynamic-network/domain/DynamicNetworkContextLoader\";\nexport * from \"./dynamic-network/model/DynamicNetworkConfiguration\";\nexport * from \"./external-plugin/data/ExternalPluginDataSource\";\nexport * from \"./external-plugin/data/HttpExternalPluginDataSource\";\nexport * from \"./external-plugin/domain/ExternalPluginContextLoader\";\nexport * from \"./nft/data/HttpNftDataSource\";\nexport * from \"./nft/data/NftDataSource\";\nexport * from \"./nft/domain/NftContextFieldLoader\";\nexport * from \"./nft/domain/NftContextLoader\";\nexport * from \"./pki/data/HttpPkiCertificateDataSource\";\nexport * from \"./pki/data/PkiCertificateDataSource\";\nexport * from \"./pki/domain/DefaultPkiCertificateLoader\";\nexport * from \"./pki/domain/PkiCertificateLoader\";\nexport * from \"./pki/model/KeyId\";\nexport * from \"./pki/model/KeyUsage\";\nexport * from \"./pki/model/PkiCertificate\";\nexport * from \"./pki/model/PkiCertificateInfo\";\nexport * from \"./proxy/data/HttpProxyDataSource\";\nexport * from \"./proxy/data/HttpSafeProxyDataSource\";\nexport * from \"./proxy/data/ProxyDataSource\";\nexport * from \"./proxy/domain/ProxyContextFieldLoader\";\nexport * from \"./shared/domain/ContextFieldLoader\";\nexport * from \"./shared/domain/ContextLoader\";\nexport * from \"./shared/model/ClearSignContext\";\nexport * from \"./shared/model/GenericPath\";\nexport * from \"./shared/model/TransactionSubset\";\nexport * from \"./shared/model/TypedDataClearSignContext\";\nexport * from \"./shared/model/TypedDataContext\";\nexport * from \"./solana/data/HttpSolanaOwnerInfoDataSource\";\nexport * from \"./solana/data/SolanaDataSource\";\nexport * from \"./solana/domain/DefaultSolanaContextLoader\";\nexport * from \"./solana/domain/SolanaContextLoader\";\nexport * from \"./token/data/HttpTokenDataSource\";\nexport * from \"./token/data/TokenDataSource\";\nexport * from \"./token/domain/TokenContextFieldLoader\";\nexport * from \"./token/domain/TokenContextLoader\";\nexport * from \"./trusted-name/data/HttpTrustedNameDataSource\";\nexport * from \"./trusted-name/data/TrustedNameDataSource\";\nexport * from \"./trusted-name/domain/TrustedNameContextFieldLoader\";\nexport * from \"./trusted-name/domain/TrustedNameContextLoader\";\nexport * from \"./typed-data/data/HttpTypedDataDataSource\";\nexport * from \"./typed-data/data/TypedDataDataSource\";\nexport * from \"./typed-data/domain/DefaultTypedDataContextLoader\";\nexport * from \"./typed-data/domain/TypedDataContextLoader\";\nexport * from \"./uniswap/data/AbiDecoderDataSource\";\nexport * from \"./uniswap/data/CommandDecoderDataSource\";\nexport * from \"./uniswap/data/DefaultCommandDecoderDataSource\";\nexport * from \"./uniswap/data/EthersAbiDecoderDataSource\";\nexport * from \"./uniswap/domain/UniswapContextLoader\";\n"],
5
- "mappings": "AAAA,WAAc,+CACd,WAAc,mDACd,WAAc,0CACd,WAAc,qCACd,WAAc,kBACd,WAAc,yBACd,WAAc,yBACd,WAAc,kDACd,WAAc,sDACd,WAAc,uDACd,WAAc,sDACd,WAAc,kDACd,WAAc,sDACd,WAAc,uDACd,WAAc,+BACd,WAAc,2BACd,WAAc,qCACd,WAAc,gCACd,WAAc,0CACd,WAAc,sCACd,WAAc,2CACd,WAAc,oCACd,WAAc,oBACd,WAAc,uBACd,WAAc,6BACd,WAAc,iCACd,WAAc,mCACd,WAAc,uCACd,WAAc,+BACd,WAAc,yCACd,WAAc,qCACd,WAAc,gCACd,WAAc,kCACd,WAAc,6BACd,WAAc,mCACd,WAAc,2CACd,WAAc,kCACd,WAAc,8CACd,WAAc,iCACd,WAAc,6CACd,WAAc,sCACd,WAAc,mCACd,WAAc,+BACd,WAAc,yCACd,WAAc,oCACd,WAAc,gDACd,WAAc,4CACd,WAAc,sDACd,WAAc,iDACd,WAAc,4CACd,WAAc,wCACd,WAAc,oDACd,WAAc,6CACd,WAAc,sCACd,WAAc,0CACd,WAAc,iDACd,WAAc,4CACd,WAAc",
4
+ "sourcesContent": ["export * from \"./calldata/data/CalldataDescriptorDataSource\";\nexport * from \"./calldata/data/HttpCalldataDescriptorDataSource\";\nexport * from \"./calldata/domain/CalldataContextLoader\";\nexport * from \"./config/model/ContextModuleConfig\";\nexport * from \"./ContextModule\";\nexport * from \"./ContextModuleBuilder\";\nexport * from \"./DefaultContextModule\";\nexport * from \"./dynamic-network/data/DynamicNetworkDataSource\";\nexport * from \"./dynamic-network/data/HttpDynamicNetworkDataSource\";\nexport * from \"./dynamic-network/domain/DynamicNetworkContextLoader\";\nexport * from \"./dynamic-network/model/DynamicNetworkConfiguration\";\nexport * from \"./external-plugin/data/ExternalPluginDataSource\";\nexport * from \"./external-plugin/data/HttpExternalPluginDataSource\";\nexport * from \"./external-plugin/domain/ExternalPluginContextLoader\";\nexport * from \"./nft/data/HttpNftDataSource\";\nexport * from \"./nft/data/NftDataSource\";\nexport * from \"./nft/domain/NftContextFieldLoader\";\nexport * from \"./nft/domain/NftContextLoader\";\nexport * from \"./pki/data/HttpPkiCertificateDataSource\";\nexport * from \"./pki/data/PkiCertificateDataSource\";\nexport * from \"./pki/domain/DefaultPkiCertificateLoader\";\nexport * from \"./pki/domain/PkiCertificateLoader\";\nexport * from \"./pki/model/KeyId\";\nexport * from \"./pki/model/KeyUsage\";\nexport * from \"./pki/model/PkiCertificate\";\nexport * from \"./pki/model/PkiCertificateInfo\";\nexport * from \"./proxy/data/HttpProxyDataSource\";\nexport * from \"./proxy/data/HttpSafeProxyDataSource\";\nexport * from \"./proxy/data/ProxyDataSource\";\nexport * from \"./proxy/domain/ProxyContextFieldLoader\";\nexport * from \"./shared/domain/ContextFieldLoader\";\nexport * from \"./shared/domain/ContextLoader\";\nexport * from \"./shared/model/ClearSignContext\";\nexport * from \"./shared/model/GenericPath\";\nexport * from \"./shared/model/SolanaContextTypes\";\nexport * from \"./shared/model/TransactionSubset\";\nexport * from \"./shared/model/TypedDataClearSignContext\";\nexport * from \"./shared/model/TypedDataContext\";\nexport * from \"./solana/data/HttpSolanaOwnerInfoDataSource\";\nexport * from \"./solana/data/SolanaDataSource\";\nexport * from \"./solana/domain/DefaultSolanaContextLoader\";\nexport * from \"./solana/domain/SolanaContextLoader\";\nexport * from \"./solana/domain/solanaContextTypes\";\nexport * from \"./token/data/HttpTokenDataSource\";\nexport * from \"./token/data/TokenDataSource\";\nexport * from \"./token/domain/TokenContextFieldLoader\";\nexport * from \"./token/domain/TokenContextLoader\";\nexport * from \"./trusted-name/data/HttpTrustedNameDataSource\";\nexport * from \"./trusted-name/data/TrustedNameDataSource\";\nexport * from \"./trusted-name/domain/TrustedNameContextFieldLoader\";\nexport * from \"./trusted-name/domain/TrustedNameContextLoader\";\nexport * from \"./typed-data/data/HttpTypedDataDataSource\";\nexport * from \"./typed-data/data/TypedDataDataSource\";\nexport * from \"./typed-data/domain/DefaultTypedDataContextLoader\";\nexport * from \"./typed-data/domain/TypedDataContextLoader\";\nexport * from \"./uniswap/data/AbiDecoderDataSource\";\nexport * from \"./uniswap/data/CommandDecoderDataSource\";\nexport * from \"./uniswap/data/DefaultCommandDecoderDataSource\";\nexport * from \"./uniswap/data/EthersAbiDecoderDataSource\";\nexport * from \"./uniswap/domain/UniswapContextLoader\";\n"],
5
+ "mappings": "AAAA,WAAc,+CACd,WAAc,mDACd,WAAc,0CACd,WAAc,qCACd,WAAc,kBACd,WAAc,yBACd,WAAc,yBACd,WAAc,kDACd,WAAc,sDACd,WAAc,uDACd,WAAc,sDACd,WAAc,kDACd,WAAc,sDACd,WAAc,uDACd,WAAc,+BACd,WAAc,2BACd,WAAc,qCACd,WAAc,gCACd,WAAc,0CACd,WAAc,sCACd,WAAc,2CACd,WAAc,oCACd,WAAc,oBACd,WAAc,uBACd,WAAc,6BACd,WAAc,iCACd,WAAc,mCACd,WAAc,uCACd,WAAc,+BACd,WAAc,yCACd,WAAc,qCACd,WAAc,gCACd,WAAc,kCACd,WAAc,6BACd,WAAc,oCACd,WAAc,mCACd,WAAc,2CACd,WAAc,kCACd,WAAc,8CACd,WAAc,iCACd,WAAc,6CACd,WAAc,sCACd,WAAc,qCACd,WAAc,mCACd,WAAc,+BACd,WAAc,yCACd,WAAc,oCACd,WAAc,gDACd,WAAc,4CACd,WAAc,sDACd,WAAc,iDACd,WAAc,4CACd,WAAc,wCACd,WAAc,oDACd,WAAc,6CACd,WAAc,sCACd,WAAc,0CACd,WAAc,iDACd,WAAc,4CACd,WAAc",
6
6
  "names": []
7
7
  }
@@ -1,2 +1,2 @@
1
- var r=(e=>(e.TOKEN="token",e.NFT="nft",e.TRUSTED_NAME="trustedName",e.PLUGIN="plugin",e.EXTERNAL_PLUGIN="externalPlugin",e.TRANSACTION_INFO="transactionInfo",e.PROXY_INFO="proxyInfo",e.ENUM="enum",e.TRANSACTION_FIELD_DESCRIPTION="transactionFieldDescription",e.TRANSACTION_CHECK="transactionCheck",e.DYNAMIC_NETWORK="dynamicNetwork",e.DYNAMIC_NETWORK_ICON="dynamicNetworkIcon",e.ERROR="error",e.SAFE="safe",e.SIGNER="signer",e))(r||{}),n=(t=>(t.TOKEN="token",t.NFT="nft",t.TRUSTED_NAME="trustedName",t.ENUM="enum",t.CALLDATA="calldata",t))(n||{});export{n as ClearSignContextReferenceType,r as ClearSignContextType};
1
+ var n=(e=>(e.TOKEN="token",e.NFT="nft",e.TRUSTED_NAME="trustedName",e.PLUGIN="plugin",e.EXTERNAL_PLUGIN="externalPlugin",e.TRANSACTION_INFO="transactionInfo",e.PROXY_INFO="proxyInfo",e.ENUM="enum",e.TRANSACTION_FIELD_DESCRIPTION="transactionFieldDescription",e.TRANSACTION_CHECK="transactionCheck",e.DYNAMIC_NETWORK="dynamicNetwork",e.DYNAMIC_NETWORK_ICON="dynamicNetworkIcon",e.ERROR="error",e.SAFE="safe",e.SIGNER="signer",e))(n||{}),r=(t=>(t.TOKEN="token",t.NFT="nft",t.TRUSTED_NAME="trustedName",t.ENUM="enum",t.CALLDATA="calldata",t))(r||{});export{r as ClearSignContextReferenceType,n as ClearSignContextType};
2
2
  //# sourceMappingURL=ClearSignContext.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/shared/model/ClearSignContext.ts"],
4
- "sourcesContent": ["import { type PkiCertificate } from \"@/pki/model/PkiCertificate\";\n\nimport { type GenericPath } from \"./GenericPath\";\n\nexport enum ClearSignContextType {\n TOKEN = \"token\",\n NFT = \"nft\",\n TRUSTED_NAME = \"trustedName\",\n PLUGIN = \"plugin\",\n EXTERNAL_PLUGIN = \"externalPlugin\",\n TRANSACTION_INFO = \"transactionInfo\",\n PROXY_INFO = \"proxyInfo\",\n ENUM = \"enum\",\n TRANSACTION_FIELD_DESCRIPTION = \"transactionFieldDescription\",\n TRANSACTION_CHECK = \"transactionCheck\",\n DYNAMIC_NETWORK = \"dynamicNetwork\",\n DYNAMIC_NETWORK_ICON = \"dynamicNetworkIcon\",\n ERROR = \"error\",\n SAFE = \"safe\",\n SIGNER = \"signer\",\n}\n\nexport enum ClearSignContextReferenceType {\n TOKEN = ClearSignContextType.TOKEN,\n NFT = ClearSignContextType.NFT,\n TRUSTED_NAME = ClearSignContextType.TRUSTED_NAME,\n ENUM = ClearSignContextType.ENUM,\n CALLDATA = \"calldata\",\n}\n\nexport type ClearSignContextReference<\n Type extends ClearSignContextReferenceType = ClearSignContextReferenceType,\n> = Type extends ClearSignContextReferenceType.ENUM\n ? {\n type: ClearSignContextReferenceType.ENUM;\n valuePath: GenericPath;\n id: number; // enum id to reference\n }\n : Type extends ClearSignContextReferenceType.TRUSTED_NAME\n ? {\n type: ClearSignContextReferenceType.TRUSTED_NAME;\n valuePath: GenericPath;\n types: string[];\n sources: string[];\n }\n : Type extends ClearSignContextReferenceType.CALLDATA\n ? {\n type: ClearSignContextReferenceType.CALLDATA;\n callee: GenericPath;\n valuePath: GenericPath;\n selector?: GenericPath;\n amount?: GenericPath;\n spender?: GenericPath;\n chainId?: GenericPath;\n }\n :\n | {\n type: Type;\n valuePath: GenericPath;\n value?: never;\n }\n | {\n type: Type;\n valuePath?: never;\n value: string;\n };\n\nexport type ClearSignContextSuccessType = Exclude<\n ClearSignContextType,\n ClearSignContextType.ERROR\n>;\n\nexport type ClearSignContextSuccess<\n T extends Exclude<\n ClearSignContextType,\n ClearSignContextType.ERROR\n > = ClearSignContextSuccessType,\n> = T extends ClearSignContextType.ENUM\n ? {\n type: ClearSignContextType.ENUM;\n id: number;\n payload: string;\n value: number;\n certificate?: PkiCertificate;\n }\n : T extends ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION\n ? {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION;\n payload: string;\n reference?: ClearSignContextReference;\n certificate?: PkiCertificate;\n }\n : {\n type: T;\n payload: string;\n certificate?: PkiCertificate;\n };\n\nexport type ClearSignContextError = {\n type: ClearSignContextType.ERROR;\n error: Error;\n};\n\nexport type ClearSignContext = ClearSignContextSuccess | ClearSignContextError;\n"],
4
+ "sourcesContent": ["import { type PkiCertificate } from \"@/pki/model/PkiCertificate\";\n\nimport { type GenericPath } from \"./GenericPath\";\n\nexport enum ClearSignContextType {\n TOKEN = \"token\",\n NFT = \"nft\",\n TRUSTED_NAME = \"trustedName\",\n PLUGIN = \"plugin\",\n EXTERNAL_PLUGIN = \"externalPlugin\",\n TRANSACTION_INFO = \"transactionInfo\",\n PROXY_INFO = \"proxyInfo\",\n ENUM = \"enum\",\n TRANSACTION_FIELD_DESCRIPTION = \"transactionFieldDescription\",\n TRANSACTION_CHECK = \"transactionCheck\",\n DYNAMIC_NETWORK = \"dynamicNetwork\",\n DYNAMIC_NETWORK_ICON = \"dynamicNetworkIcon\",\n ERROR = \"error\",\n SAFE = \"safe\",\n SIGNER = \"signer\",\n}\n\nexport enum ClearSignContextReferenceType {\n TOKEN = ClearSignContextType.TOKEN,\n NFT = ClearSignContextType.NFT,\n TRUSTED_NAME = ClearSignContextType.TRUSTED_NAME,\n ENUM = ClearSignContextType.ENUM,\n CALLDATA = \"calldata\",\n}\n\ntype PathOnly = {\n valuePath: GenericPath;\n value?: never;\n callee?: GenericPath;\n selector?: GenericPath;\n amount?: GenericPath;\n spender?: GenericPath;\n chainId?: GenericPath;\n};\n\ntype ValueOnly = {\n value: string;\n valuePath?: never;\n};\n\ntype PathOrValue = PathOnly | ValueOnly;\n\n// per-type payloads for references\ntype ClearSignContextReferencePayloads = {\n [ClearSignContextReferenceType.ENUM]: {\n valuePath: GenericPath;\n id: number; // enum id to reference\n };\n [ClearSignContextReferenceType.TRUSTED_NAME]: {\n valuePath: GenericPath;\n types: string[];\n sources: string[];\n };\n [ClearSignContextReferenceType.CALLDATA]: {\n callee: GenericPath;\n valuePath: GenericPath;\n selector?: GenericPath;\n amount?: GenericPath;\n spender?: GenericPath;\n chainId?: GenericPath;\n };\n [ClearSignContextReferenceType.TOKEN]: PathOrValue;\n [ClearSignContextReferenceType.NFT]: PathOrValue;\n};\n\n// discriminated union of all reference shapes, built from the payload map\ntype ClearSignContextReferenceUnion = {\n [T in ClearSignContextReferenceType]: {\n type: T;\n } & ClearSignContextReferencePayloads[T];\n}[ClearSignContextReferenceType];\n\nexport type ClearSignContextReference<\n T extends ClearSignContextReferenceType = ClearSignContextReferenceType,\n> = Extract<ClearSignContextReferenceUnion, { type: T }>;\n\nexport type ClearSignContextSuccessType = Exclude<\n ClearSignContextType,\n ClearSignContextType.ERROR\n>;\n\n// base payload shared by most success contexts\ntype ClearSignContextSuccessBase = {\n payload: string;\n certificate?: PkiCertificate;\n};\n\n// map from ClearSign success type to payload\ntype ClearSignContextSuccessPayloadsBase = {\n [K in ClearSignContextSuccessType]: ClearSignContextSuccessBase;\n};\n\n// special cases overrides for certain context types\ntype ClearSignContextSuccessPayloadOverrides = {\n [ClearSignContextType.ENUM]: ClearSignContextSuccessBase & {\n id: number;\n value: number;\n };\n [ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION]: ClearSignContextSuccessBase & {\n reference?: ClearSignContextReference;\n };\n};\n\ntype ClearSignContextSuccessPayloads = Omit<\n ClearSignContextSuccessPayloadsBase,\n ClearSignContextType.ENUM | ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION\n> &\n ClearSignContextSuccessPayloadOverrides;\n\n// union of all success contexts, built from the payload map.\ntype ClearSignContextSuccessUnion = {\n [T in ClearSignContextSuccessType]: {\n type: T;\n } & ClearSignContextSuccessPayloads[T];\n}[ClearSignContextSuccessType];\n\nexport type ClearSignContextSuccess<\n T extends ClearSignContextSuccessType = ClearSignContextSuccessType,\n> = Extract<ClearSignContextSuccessUnion, { type: T }>;\n\nexport type ClearSignContextError = {\n type: ClearSignContextType.ERROR;\n error: Error;\n};\n\nexport type ClearSignContext = ClearSignContextSuccess | ClearSignContextError;\n"],
5
5
  "mappings": "AAIO,IAAKA,OACVA,EAAA,MAAQ,QACRA,EAAA,IAAM,MACNA,EAAA,aAAe,cACfA,EAAA,OAAS,SACTA,EAAA,gBAAkB,iBAClBA,EAAA,iBAAmB,kBACnBA,EAAA,WAAa,YACbA,EAAA,KAAO,OACPA,EAAA,8BAAgC,8BAChCA,EAAA,kBAAoB,mBACpBA,EAAA,gBAAkB,iBAClBA,EAAA,qBAAuB,qBACvBA,EAAA,MAAQ,QACRA,EAAA,KAAO,OACPA,EAAA,OAAS,SAfCA,OAAA,IAkBAC,OACVA,EAAA,MAAQ,QACRA,EAAA,IAAM,MACNA,EAAA,aAAe,cACfA,EAAA,KAAO,OACPA,EAAA,SAAW,WALDA,OAAA",
6
6
  "names": ["ClearSignContextType", "ClearSignContextReferenceType"]
7
7
  }
@@ -0,0 +1,2 @@
1
+ var e=(t=>(t.SOLANA_TOKEN="solanaToken",t.SOLANA_LIFI="solanaLifi",t.ERROR="error",t))(e||{});export{e as SolanaContextTypes};
2
+ //# sourceMappingURL=SolanaContextTypes.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/shared/model/SolanaContextTypes.ts"],
4
+ "sourcesContent": ["import type { PkiCertificate } from \"@/pki/model/PkiCertificate\";\n\nexport enum SolanaContextTypes {\n SOLANA_TOKEN = \"solanaToken\",\n SOLANA_LIFI = \"solanaLifi\",\n ERROR = \"error\",\n}\n\nexport type SolanaTransactionDescriptor = {\n data: string;\n descriptorType: string;\n descriptorVersion: string;\n signatures: {\n prod?: string;\n test?: string;\n };\n};\n\nexport type SolanaTransactionDescriptorList = Record<\n string,\n SolanaTransactionDescriptor\n>;\n\nexport type SolanaTokenData = {\n solanaTokenDescriptor: {\n data: string;\n signature: string;\n };\n};\n\nexport type SolanaContextSuccessType = Exclude<\n SolanaContextTypes,\n SolanaContextTypes.ERROR\n>;\n\n// map from Solana success type to payload\ntype SolanaContextSuccessPayloads = {\n [SolanaContextTypes.SOLANA_TOKEN]: {\n payload: SolanaTokenData;\n certificate?: PkiCertificate;\n };\n [SolanaContextTypes.SOLANA_LIFI]: {\n payload: SolanaTransactionDescriptorList;\n };\n};\n\nexport type SolanaContextSuccess<\n T extends SolanaContextSuccessType = SolanaContextSuccessType,\n> = {\n type: T;\n} & SolanaContextSuccessPayloads[T];\n\nexport type SolanaContextError = {\n type: SolanaContextTypes.ERROR;\n error: Error;\n};\n\nexport type SolanaContext = SolanaContextSuccess | SolanaContextError;\n\nexport type SolanaTokenContextSuccess =\n SolanaContextSuccess<SolanaContextTypes.SOLANA_TOKEN>;\n\nexport type SolanaLifiContextSuccess =\n SolanaContextSuccess<SolanaContextTypes.SOLANA_LIFI>;\n\nexport type SolanaTokenContextResult =\n | SolanaTokenContextSuccess\n | SolanaContextError;\n\nexport type SolanaLifiContextResult =\n | SolanaLifiContextSuccess\n | SolanaContextError;\n\n// TODO LIFI\nexport type LoaderResult = SolanaTokenContextResult; //| SolanaLifiContextResult;\n"],
5
+ "mappings": "AAEO,IAAKA,OACVA,EAAA,aAAe,cACfA,EAAA,YAAc,aACdA,EAAA,MAAQ,QAHEA,OAAA",
6
+ "names": ["SolanaContextTypes"]
7
+ }
@@ -1,2 +1,2 @@
1
- var w=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var u=(s,e,o,t)=>{for(var r=t>1?void 0:t?g(e,o):e,a=s.length-1,n;a>=0;a--)(n=s[a])&&(r=(t?n(e,o,r):n(r))||r);return t&&r&&w(e,o,r),r},f=(s,e)=>(o,t)=>e(o,t,s);import{hexaStringToBuffer as h}from"@ledgerhq/device-management-kit";import m from"axios";import{inject as E,injectable as A}from"inversify";import{Left as i,Right as d}from"purify-ts";import{configTypes as O}from"../../config/di/configTypes";import{LEDGER_CLIENT_VERSION_HEADER as p,LEDGER_ORIGIN_TOKEN_HEADER as C}from"../../shared/constant/HttpHeaders";import S from"../../../package.json";let c=class{constructor(e){this.config=e;if(!this.config.originToken)throw new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: origin token is required")}isSolanaSPLOwnerInfo(e){return typeof e!="object"||e===null?!1:typeof e.tokenAccount=="string"&&typeof e.owner=="string"&&typeof e.contract=="string"&&typeof e.signedDescriptor=="string"}async fetchAddressMetadata(e,o){return await m.request({method:"GET",url:`${this.config.metadataServiceDomain.url}/v2/solana/owner/${e}?challenge=${o}`,headers:{[p]:`context-module/${S.version}`,[C]:this.config.originToken}}).then(t=>this.isSolanaSPLOwnerInfo(t.data)?d(t.data):i(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid fetchAddressMetadata response shape"))).catch(()=>i(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to fetch address metadata")))}async computeAddressMetadata(e,o,t){return await m.request({method:"GET",url:`${this.config.metadataServiceDomain.url}/v2/solana/computed-token-account/${e}/${o}?challenge=${t}`,headers:{[p]:`context-module/${S.version}`,"X-Ledger-Client-Origin":this.config.originToken}}).then(r=>this.isSolanaSPLOwnerInfo(r.data)?d(r.data):i(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid computeAddressMetadata response shape"))).catch(()=>i(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to compute address metadata")))}async getOwnerInfo(e){const{tokenAddress:o,challenge:t,createATA:r}=e;if(!t)return i(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: challenge is required"));let a;if(o)a=await this.fetchAddressMetadata(o,t);else if(r?.address&&r?.mintAddress)a=await this.computeAddressMetadata(r.address,r.mintAddress,t);else return i(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: either tokenAddress or valid createATA must be provided"));return a.chain(n=>{const l=h(n.signedDescriptor);return l?d({descriptor:l,tokenAccount:n.tokenAccount,owner:n.owner,contract:n.contract}):i(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid base64 descriptor received"))})}};c=u([A(),f(0,E(O.Config))],c);export{c as HttpSolanaOwnerInfoDataSource};
1
+ var w=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var f=(i,e,o,t)=>{for(var r=t>1?void 0:t?g(e,o):e,n=i.length-1,s;n>=0;n--)(s=i[n])&&(r=(t?s(e,o,r):s(r))||r);return t&&r&&w(e,o,r),r},u=(i,e)=>(o,t)=>e(o,t,i);import{hexaStringToBuffer as h}from"@ledgerhq/device-management-kit";import m from"axios";import{inject as E,injectable as I}from"inversify";import{Left as a,Right as l}from"purify-ts";import{configTypes as O}from"../../config/di/configTypes";import{LEDGER_CLIENT_VERSION_HEADER as p,LEDGER_ORIGIN_TOKEN_HEADER as A}from"../../shared/constant/HttpHeaders";import S from"../../../package.json";let d=class{constructor(e){this.config=e;if(!this.config.originToken)throw new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: origin token is required")}isSolanaSPLOwnerInfo(e){return typeof e!="object"||e===null?!1:typeof e.tokenAccount=="string"&&typeof e.owner=="string"&&typeof e.contract=="string"&&typeof e.signedDescriptor=="string"}async fetchAddressMetadata(e,o){return await m.request({method:"GET",url:`${this.config.metadataServiceDomain.url}/v2/solana/owner/${e}?challenge=${o}`,headers:{[p]:`context-module/${S.version}`,[A]:this.config.originToken}}).then(t=>this.isSolanaSPLOwnerInfo(t.data)?l(t.data):a(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid fetchAddressMetadata response shape"))).catch(()=>a(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to fetch address metadata")))}async computeAddressMetadata(e,o,t){return await m.request({method:"GET",url:`${this.config.metadataServiceDomain.url}/v2/solana/computed-token-account/${e}/${o}?challenge=${t}`,headers:{[p]:`context-module/${S.version}`,"X-Ledger-Client-Origin":this.config.originToken}}).then(r=>this.isSolanaSPLOwnerInfo(r.data)?l(r.data):a(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid computeAddressMetadata response shape"))).catch(()=>a(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to compute address metadata")))}async getOwnerInfo(e){const{tokenAddress:o,challenge:t,createATA:r}=e;if(!t)return a(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: challenge is required"));let n;if(o)n=await this.fetchAddressMetadata(o,t);else if(r?.address&&r?.mintAddress)n=await this.computeAddressMetadata(r.address,r.mintAddress,t);else return a(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: either tokenAddress or valid createATA must be provided"));return n.chain(s=>{const c=h(s.signedDescriptor);return c?l({tlvDescriptor:c}):a(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid base64 tlvDescriptor received"))})}};d=f([I(),u(0,E(O.Config))],d);export{d as HttpSolanaOwnerInfoDataSource};
2
2
  //# sourceMappingURL=HttpSolanaOwnerInfoDataSource.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/solana/data/HttpSolanaOwnerInfoDataSource.ts"],
4
- "sourcesContent": ["import { hexaStringToBuffer } from \"@ledgerhq/device-management-kit\";\nimport axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport type { ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport {\n SolanaSPLOwnerInfo,\n type SolanaTransactionContext,\n} from \"@/solana/domain/solanaContextTypes\";\nimport PACKAGE from \"@root/package.json\";\n\nimport {\n HttpSolanaOwnerInfoDataSourceResult,\n SolanaDataSource,\n} from \"./SolanaDataSource\";\n\n@injectable()\nexport class HttpSolanaOwnerInfoDataSource implements SolanaDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n ) {\n if (!this.config.originToken) {\n throw new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: origin token is required\",\n );\n }\n }\n\n private isSolanaSPLOwnerInfo(data: {\n tokenAccount?: unknown;\n owner?: unknown;\n contract?: unknown;\n signedDescriptor?: unknown;\n }): data is SolanaSPLOwnerInfo {\n if (typeof data !== \"object\" || data === null) return false;\n return (\n typeof data.tokenAccount === \"string\" &&\n typeof data.owner === \"string\" &&\n typeof data.contract === \"string\" &&\n typeof data.signedDescriptor === \"string\"\n );\n }\n\n async fetchAddressMetadata(\n tokenAddress: string,\n challenge: string,\n ): Promise<Either<Error, SolanaSPLOwnerInfo>> {\n return await axios\n .request<SolanaSPLOwnerInfo>({\n method: \"GET\",\n url: `${this.config.metadataServiceDomain.url}/v2/solana/owner/${tokenAddress}?challenge=${challenge}`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n })\n .then((res) => {\n if (!this.isSolanaSPLOwnerInfo(res.data))\n return Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid fetchAddressMetadata response shape\",\n ),\n );\n return Right(res.data);\n })\n .catch(() =>\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to fetch address metadata\",\n ),\n ),\n );\n }\n\n async computeAddressMetadata(\n address: string,\n mintAddress: string,\n challenge: string,\n ): Promise<Either<Error, SolanaSPLOwnerInfo>> {\n return await axios\n .request<SolanaSPLOwnerInfo>({\n method: \"GET\",\n url: `${this.config.metadataServiceDomain.url}/v2/solana/computed-token-account/${address}/${mintAddress}?challenge=${challenge}`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n \"X-Ledger-Client-Origin\": this.config.originToken,\n },\n })\n .then((res) => {\n if (!this.isSolanaSPLOwnerInfo(res.data))\n return Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid computeAddressMetadata response shape\",\n ),\n );\n return Right(res.data);\n })\n .catch(() =>\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to compute address metadata\",\n ),\n ),\n );\n }\n\n async getOwnerInfo(\n context: SolanaTransactionContext,\n ): Promise<Either<Error, HttpSolanaOwnerInfoDataSourceResult>> {\n const { tokenAddress, challenge, createATA } = context;\n\n if (!challenge) {\n return Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: challenge is required\",\n ),\n );\n }\n\n let ownerInfoResult: Either<Error, SolanaSPLOwnerInfo>;\n\n if (tokenAddress) {\n ownerInfoResult = await this.fetchAddressMetadata(\n tokenAddress,\n challenge,\n );\n } else if (createATA?.address && createATA?.mintAddress) {\n ownerInfoResult = await this.computeAddressMetadata(\n createATA.address,\n createATA.mintAddress,\n challenge,\n );\n } else {\n return Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: either tokenAddress or valid createATA must be provided\",\n ),\n );\n }\n\n return ownerInfoResult.chain((ownerInfo) => {\n const descriptor = hexaStringToBuffer(ownerInfo.signedDescriptor);\n if (!descriptor) {\n return Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid base64 descriptor received\",\n ),\n );\n }\n return Right({\n descriptor,\n tokenAccount: ownerInfo.tokenAccount,\n owner: ownerInfo.owner,\n contract: ownerInfo.contract,\n });\n });\n }\n}\n"],
5
- "mappings": "iOAAA,OAAS,sBAAAA,MAA0B,kCACnC,OAAOC,MAAW,QAClB,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YACnC,OAAiB,QAAAC,EAAM,SAAAC,MAAa,YAEpC,OAAS,eAAAC,MAAmB,0BAE5B,OACE,gCAAAC,EACA,8BAAAC,MACK,gCAKP,OAAOC,MAAa,qBAQb,IAAMC,EAAN,KAAgE,CACrE,YAC+CC,EAC7C,CAD6C,YAAAA,EAE7C,GAAI,CAAC,KAAK,OAAO,YACf,MAAM,IAAI,MACR,2EACF,CAEJ,CAEQ,qBAAqB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AAK,qBAC3Bb,EACAC,CACF,UACSW,GAAW,SAAWA,GAAW,YAC1CC,EAAkB,MAAM,KAAK,uBAC3BD,EAAU,QACVA,EAAU,YACVX,CACF,MAEA,QAAOO,EACL,IAAI,MACF,0GACF,CACF,EAGF,OAAOK,EAAgB,MAAOC,GAAc,CAC1C,MAAMC,EAAaC,EAAmBF,EAAU,gBAAgB,EAChE,OAAKC,EAOER,EAAM,CACX,WAAAQ,EACA,aAAcD,EAAU,aACxB,MAAOA,EAAU,MACjB,SAAUA,EAAU,QACtB,CAAC,EAXQN,EACL,IAAI,MACF,qFACF,CACF,CAQJ,CAAC,CACH,CACF,EA5IaX,EAANoB,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAY,MAAM,IAFjBxB",
6
- "names": ["hexaStringToBuffer", "axios", "inject", "injectable", "Left", "Right", "configTypes", "LEDGER_CLIENT_VERSION_HEADER", "LEDGER_ORIGIN_TOKEN_HEADER", "PACKAGE", "HttpSolanaOwnerInfoDataSource", "config", "data", "tokenAddress", "challenge", "axios", "LEDGER_CLIENT_VERSION_HEADER", "PACKAGE", "LEDGER_ORIGIN_TOKEN_HEADER", "res", "Right", "Left", "address", "mintAddress", "context", "createATA", "ownerInfoResult", "ownerInfo", "descriptor", "hexaStringToBuffer", "__decorateClass", "injectable", "__decorateParam", "inject", "configTypes"]
4
+ "sourcesContent": ["import { hexaStringToBuffer } from \"@ledgerhq/device-management-kit\";\nimport axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport type { ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport {\n SolanaSPLOwnerInfo,\n type SolanaTransactionContext,\n} from \"@/solana/domain/solanaContextTypes\";\nimport PACKAGE from \"@root/package.json\";\n\nimport {\n HttpSolanaOwnerInfoDataSourceResult,\n SolanaDataSource,\n} from \"./SolanaDataSource\";\n\n@injectable()\nexport class HttpSolanaOwnerInfoDataSource implements SolanaDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n ) {\n if (!this.config.originToken) {\n throw new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: origin token is required\",\n );\n }\n }\n\n private isSolanaSPLOwnerInfo(data: {\n tokenAccount?: unknown;\n owner?: unknown;\n contract?: unknown;\n signedDescriptor?: unknown;\n }): data is SolanaSPLOwnerInfo {\n if (typeof data !== \"object\" || data === null) return false;\n return (\n typeof data.tokenAccount === \"string\" &&\n typeof data.owner === \"string\" &&\n typeof data.contract === \"string\" &&\n typeof data.signedDescriptor === \"string\"\n );\n }\n\n async fetchAddressMetadata(\n tokenAddress: string,\n challenge: string,\n ): Promise<Either<Error, SolanaSPLOwnerInfo>> {\n return await axios\n .request<SolanaSPLOwnerInfo>({\n method: \"GET\",\n url: `${this.config.metadataServiceDomain.url}/v2/solana/owner/${tokenAddress}?challenge=${challenge}`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n })\n .then((res) => {\n if (!this.isSolanaSPLOwnerInfo(res.data))\n return Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid fetchAddressMetadata response shape\",\n ),\n );\n return Right(res.data);\n })\n .catch(() =>\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to fetch address metadata\",\n ),\n ),\n );\n }\n\n async computeAddressMetadata(\n address: string,\n mintAddress: string,\n challenge: string,\n ): Promise<Either<Error, SolanaSPLOwnerInfo>> {\n return await axios\n .request<SolanaSPLOwnerInfo>({\n method: \"GET\",\n url: `${this.config.metadataServiceDomain.url}/v2/solana/computed-token-account/${address}/${mintAddress}?challenge=${challenge}`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n \"X-Ledger-Client-Origin\": this.config.originToken,\n },\n })\n .then((res) => {\n if (!this.isSolanaSPLOwnerInfo(res.data))\n return Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid computeAddressMetadata response shape\",\n ),\n );\n return Right(res.data);\n })\n .catch(() =>\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to compute address metadata\",\n ),\n ),\n );\n }\n\n async getOwnerInfo(\n context: SolanaTransactionContext,\n ): Promise<Either<Error, HttpSolanaOwnerInfoDataSourceResult>> {\n const { tokenAddress, challenge, createATA } = context;\n\n if (!challenge) {\n return Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: challenge is required\",\n ),\n );\n }\n\n let ownerInfoResult: Either<Error, SolanaSPLOwnerInfo>;\n\n if (tokenAddress) {\n ownerInfoResult = await this.fetchAddressMetadata(\n tokenAddress,\n challenge,\n );\n } else if (createATA?.address && createATA?.mintAddress) {\n ownerInfoResult = await this.computeAddressMetadata(\n createATA.address,\n createATA.mintAddress,\n challenge,\n );\n } else {\n return Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: either tokenAddress or valid createATA must be provided\",\n ),\n );\n }\n\n return ownerInfoResult.chain((ownerInfo) => {\n const tlvDescriptor = hexaStringToBuffer(ownerInfo.signedDescriptor);\n if (!tlvDescriptor) {\n return Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid base64 tlvDescriptor received\",\n ),\n );\n }\n return Right({\n tlvDescriptor,\n });\n });\n }\n}\n"],
5
+ "mappings": "iOAAA,OAAS,sBAAAA,MAA0B,kCACnC,OAAOC,MAAW,QAClB,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YACnC,OAAiB,QAAAC,EAAM,SAAAC,MAAa,YAEpC,OAAS,eAAAC,MAAmB,0BAE5B,OACE,gCAAAC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aACJG,EAC6D,CAC7D,KAAM,CAAE,aAAAX,EAAc,UAAAC,EAAW,UAAAW,CAAU,EAAID,EAE/C,GAAI,CAACV,EACH,OAAOO,EACL,IAAI,MACF,wEACF,CACF,EAGF,IAAIK,EAEJ,GAAIb,EACFa,EAAkB,MAAM,KAAK,qBAC3Bb,EACAC,CACF,UACSW,GAAW,SAAWA,GAAW,YAC1CC,EAAkB,MAAM,KAAK,uBAC3BD,EAAU,QACVA,EAAU,YACVX,CACF,MAEA,QAAOO,EACL,IAAI,MACF,0GACF,CACF,EAGF,OAAOK,EAAgB,MAAOC,GAAc,CAC1C,MAAMC,EAAgBC,EAAmBF,EAAU,gBAAgB,EACnE,OAAKC,EAOER,EAAM,CACX,cAAAQ,CACF,CAAC,EARQP,EACL,IAAI,MACF,wFACF,CACF,CAKJ,CAAC,CACH,CACF,EAzIaX,EAANoB,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAY,MAAM,IAFjBxB",
6
+ "names": ["hexaStringToBuffer", "axios", "inject", "injectable", "Left", "Right", "configTypes", "LEDGER_CLIENT_VERSION_HEADER", "LEDGER_ORIGIN_TOKEN_HEADER", "PACKAGE", "HttpSolanaOwnerInfoDataSource", "config", "data", "tokenAddress", "challenge", "axios", "LEDGER_CLIENT_VERSION_HEADER", "PACKAGE", "LEDGER_ORIGIN_TOKEN_HEADER", "res", "Right", "Left", "address", "mintAddress", "context", "createATA", "ownerInfoResult", "ownerInfo", "tlvDescriptor", "hexaStringToBuffer", "__decorateClass", "injectable", "__decorateParam", "inject", "configTypes"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{DeviceModelId as r,hexaStringToBuffer as l}from"@ledgerhq/device-management-kit";import s from"axios";import{Left as c}from"purify-ts";import{LEDGER_CLIENT_VERSION_HEADER as u}from"../../shared/constant/HttpHeaders";import{HttpSolanaOwnerInfoDataSource as n}from"../../solana/data/HttpSolanaOwnerInfoDataSource";import m from"../../../package.json";vi.mock("axios");function f(o){const d=new TextEncoder().encode(o);return Array.from(d).map(e=>e.toString(16).padStart(2,"0")).join("")}describe("HttpSolanaOwnerInfoDataSource",()=>{const o={metadataServiceDomain:{url:"https://some.doma.in"},originToken:"mock-origin-token"},i=f("mock-descriptor"),d={tokenAccount:"token-account",owner:"owner-address",contract:"contract-address",signedDescriptor:i};beforeEach(()=>{vi.resetAllMocks()}),it("should fetch address metadata via tokenAddress",async()=>{const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0};vi.spyOn(s,"request").mockResolvedValueOnce({data:d});const t=await new n(o).getOwnerInfo(e);expect(t.isRight()).toBe(!0),expect(t.extract()).toEqual({descriptor:l(i),tokenAccount:"token-account",owner:"owner-address",contract:"contract-address"})}),it("should compute address when tokenAddress is not provided",async()=>{const e={deviceModelId:r.FLEX,tokenAddress:void 0,challenge:"random",createATA:{address:"some-address",mintAddress:"some-mint"}};vi.spyOn(s,"request").mockResolvedValueOnce({data:d});const t=await new n(o).getOwnerInfo(e);expect(t.isRight()).toBe(!0),expect(t.extract().tokenAccount).toBe("token-account")}),it("should return an error if both tokenAddress and createATA are missing or invalid",async()=>{const e={deviceModelId:r.FLEX,tokenAddress:void 0,challenge:"random",createATA:void 0},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(c(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: either tokenAddress or valid createATA must be provided")))}),it("should return an error if challenge is missing",async()=>{const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:void 0,createATA:void 0},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(c(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: challenge is required")))}),it("should return an error if the descriptor is not valid base64",async()=>{vi.spyOn(s,"request").mockResolvedValueOnce({data:{...d,signedDescriptor:"!!!not-valid-base64!!!"}});const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(c(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid base64 descriptor received")))}),it("should return an error if the metadata request fails",async()=>{vi.spyOn(s,"request").mockRejectedValueOnce(new Error("Network error"));const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(c(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to fetch address metadata")))}),it("should return an error if axios request return wrong shape for fetchAddressMetadata",async()=>{vi.spyOn(s,"request").mockResolvedValueOnce({data:{wrong:"field"}});const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(c(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid fetchAddressMetadata response shape")))}),it("should return an error if axios request return wrong shape for computeAddressMetadata",async()=>{vi.spyOn(s,"request").mockResolvedValueOnce({data:{wrong:"field"}});const e={deviceModelId:r.FLEX,tokenAddress:void 0,challenge:"random",createATA:{address:"some-address",mintAddress:"some-mint"}},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(c(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid computeAddressMetadata response shape")))}),it("should throw if originToken is missing",()=>{expect(()=>{new n({...o,originToken:void 0})}).toThrow("[ContextModule] - HttpSolanaOwnerInfoDataSource: origin token is required")}),it("should call axios with correct headers",async()=>{const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},a=vi.spyOn(s,"request").mockResolvedValueOnce({data:d});await new n(o).getOwnerInfo(e),expect(a).toHaveBeenCalledWith(expect.objectContaining({headers:{[u]:`context-module/${m.version}`,"X-Ledger-Client-Origin":o.originToken}}))})});
1
+ import{DeviceModelId as r,hexaStringToBuffer as l}from"@ledgerhq/device-management-kit";import s from"axios";import{Left as d}from"purify-ts";import{LEDGER_CLIENT_VERSION_HEADER as u}from"../../shared/constant/HttpHeaders";import{HttpSolanaOwnerInfoDataSource as n}from"../../solana/data/HttpSolanaOwnerInfoDataSource";import f from"../../../package.json";vi.mock("axios");function m(o){const c=new TextEncoder().encode(o);return Array.from(c).map(e=>e.toString(16).padStart(2,"0")).join("")}describe("HttpSolanaOwnerInfoDataSource",()=>{const o={metadataServiceDomain:{url:"https://some.doma.in"},originToken:"mock-origin-token"},i=m("mock-descriptor"),c={tokenAccount:"token-account",owner:"owner-address",contract:"contract-address",signedDescriptor:i};beforeEach(()=>{vi.resetAllMocks()}),it("should fetch address metadata via tokenAddress",async()=>{const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0};vi.spyOn(s,"request").mockResolvedValueOnce({data:c});const t=await new n(o).getOwnerInfo(e);expect(t.isRight()).toBe(!0),expect(t.extract()).toEqual({tlvDescriptor:l(i)})}),it("should return an error if both tokenAddress and createATA are missing or invalid",async()=>{const e={deviceModelId:r.FLEX,tokenAddress:void 0,challenge:"random",createATA:void 0},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(d(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: either tokenAddress or valid createATA must be provided")))}),it("should return an error if challenge is missing",async()=>{const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:void 0,createATA:void 0},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(d(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: challenge is required")))}),it("should return an error if the descriptor is not valid base64",async()=>{vi.spyOn(s,"request").mockResolvedValueOnce({data:{...c,signedDescriptor:"!!!not-valid-base64!!!"}});const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(d(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid base64 tlvDescriptor received")))}),it("should return an error if the metadata request fails",async()=>{vi.spyOn(s,"request").mockRejectedValueOnce(new Error("Network error"));const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(d(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to fetch address metadata")))}),it("should return an error if axios request return wrong shape for fetchAddressMetadata",async()=>{vi.spyOn(s,"request").mockResolvedValueOnce({data:{wrong:"field"}});const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(d(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid fetchAddressMetadata response shape")))}),it("should return an error if axios request return wrong shape for computeAddressMetadata",async()=>{vi.spyOn(s,"request").mockResolvedValueOnce({data:{wrong:"field"}});const e={deviceModelId:r.FLEX,tokenAddress:void 0,challenge:"random",createATA:{address:"some-address",mintAddress:"some-mint"}},t=await new n(o).getOwnerInfo(e);expect(t).toEqual(d(new Error("[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid computeAddressMetadata response shape")))}),it("should throw if originToken is missing",()=>{expect(()=>{new n({...o,originToken:void 0})}).toThrow("[ContextModule] - HttpSolanaOwnerInfoDataSource: origin token is required")}),it("should call axios with correct headers",async()=>{const e={deviceModelId:r.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},a=vi.spyOn(s,"request").mockResolvedValueOnce({data:c});await new n(o).getOwnerInfo(e),expect(a).toHaveBeenCalledWith(expect.objectContaining({headers:{[u]:`context-module/${f.version}`,"X-Ledger-Client-Origin":o.originToken}}))})});
2
2
  //# sourceMappingURL=HttpSolanaOwnerInfoDataSource.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/solana/data/HttpSolanaOwnerInfoDataSource.test.ts"],
4
- "sourcesContent": ["/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n DeviceModelId,\n hexaStringToBuffer,\n} from \"@ledgerhq/device-management-kit\";\nimport axios from \"axios\";\nimport { Left } from \"purify-ts\";\n\nimport type { ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { LEDGER_CLIENT_VERSION_HEADER } from \"@/shared/constant/HttpHeaders\";\nimport { HttpSolanaOwnerInfoDataSource } from \"@/solana/data/HttpSolanaOwnerInfoDataSource\";\nimport type { SolanaTransactionContext } from \"@/solana/domain/solanaContextTypes\";\nimport PACKAGE from \"@root/package.json\";\n\nvi.mock(\"axios\");\n\nfunction stringToHex(str: string): string {\n const encoder = new TextEncoder();\n const bytes = encoder.encode(str); // Uint8Array\n return Array.from(bytes)\n .map((byte) => byte.toString(16).padStart(2, \"0\"))\n .join(\"\");\n}\n\ndescribe(\"HttpSolanaOwnerInfoDataSource\", () => {\n const config = {\n metadataServiceDomain: { url: \"https://some.doma.in\" },\n originToken: \"mock-origin-token\",\n } as ContextModuleConfig;\n\n const signedDescriptorHex = stringToHex(\"mock-descriptor\");\n const responseData = {\n tokenAccount: \"token-account\",\n owner: \"owner-address\",\n contract: \"contract-address\",\n signedDescriptor: signedDescriptorHex,\n };\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n it(\"should fetch address metadata via tokenAddress\", async () => {\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({ data: responseData });\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result.isRight()).toBe(true);\n expect(result.extract()).toEqual({\n descriptor: hexaStringToBuffer(signedDescriptorHex),\n tokenAccount: \"token-account\",\n owner: \"owner-address\",\n contract: \"contract-address\",\n });\n });\n\n it(\"should compute address when tokenAddress is not provided\", async () => {\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: undefined,\n challenge: \"random\",\n createATA: {\n address: \"some-address\",\n mintAddress: \"some-mint\",\n },\n };\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({ data: responseData });\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result.isRight()).toBe(true);\n expect((result.extract() as any).tokenAccount).toBe(\"token-account\");\n });\n\n it(\"should return an error if both tokenAddress and createATA are missing or invalid\", async () => {\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: undefined,\n challenge: \"random\",\n createATA: undefined,\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: either tokenAddress or valid createATA must be provided\",\n ),\n ),\n );\n });\n\n it(\"should return an error if challenge is missing\", async () => {\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: undefined,\n createATA: undefined,\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: challenge is required\",\n ),\n ),\n );\n });\n\n it(\"should return an error if the descriptor is not valid base64\", async () => {\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({\n data: { ...responseData, signedDescriptor: \"!!!not-valid-base64!!!\" },\n });\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid base64 descriptor received\",\n ),\n ),\n );\n });\n\n it(\"should return an error if the metadata request fails\", async () => {\n vi.spyOn(axios, \"request\").mockRejectedValueOnce(\n new Error(\"Network error\"),\n );\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to fetch address metadata\",\n ),\n ),\n );\n });\n\n it(\"should return an error if axios request return wrong shape for fetchAddressMetadata\", async () => {\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({\n data: { wrong: \"field\" },\n });\n\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid fetchAddressMetadata response shape\",\n ),\n ),\n );\n });\n\n it(\"should return an error if axios request return wrong shape for computeAddressMetadata\", async () => {\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({\n data: { wrong: \"field\" },\n });\n\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: undefined,\n challenge: \"random\",\n createATA: {\n address: \"some-address\",\n mintAddress: \"some-mint\",\n },\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid computeAddressMetadata response shape\",\n ),\n ),\n );\n });\n\n it(\"should throw if originToken is missing\", () => {\n expect(() => {\n new HttpSolanaOwnerInfoDataSource({\n ...config,\n originToken: undefined,\n } as any);\n }).toThrow(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: origin token is required\",\n );\n });\n\n it(\"should call axios with correct headers\", async () => {\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n const spy = vi\n .spyOn(axios, \"request\")\n .mockResolvedValueOnce({ data: responseData });\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n await dataSource.getOwnerInfo(context);\n\n expect(spy).toHaveBeenCalledWith(\n expect.objectContaining({\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n \"X-Ledger-Client-Origin\": config.originToken,\n },\n }),\n );\n });\n});\n"],
5
- "mappings": "AAEA,OACE,iBAAAA,EACA,sBAAAC,MACK,kCACP,OAAOC,MAAW,QAClB,OAAS,QAAAC,MAAY,YAGrB,OAAS,gCAAAC,MAAoC,gCAC7C,OAAS,iCAAAC,MAAqC,8CAE9C,OAAOC,MAAa,qBAEpB,GAAG,KAAK,OAAO,EAEf,SAASC,EAAYC,EAAqB,CAExC,MAAMC,EADU,IAAI,YAAY,EACV,OAAOD,CAAG,EAChC,OAAO,MAAM,KAAKC,CAAK,EACpB,IAAKC,GAASA,EAAK,SAAS,EAAE,EAAE,SAAS,EAAG,GAAG,CAAC,EAChD,KAAK,EAAE,CACZ,CAEA,SAAS,gCAAiC,IAAM,CAC9C,MAAMC,EAAS,CACb,sBAAuB,CAAE,IAAK,sBAAuB,EACrD,YAAa,mBACf,EAEMC,EAAsBL,EAAY,iBAAiB,EACnDM,EAAe,CACnB,aAAc,gBACd,MAAO,gBACP,SAAU,mBACV,iBAAkBD,CACpB,EAEA,WAAW,IAAM,CACf,GAAG,cAAc,CACnB,CAAC,EAED,GAAG,iDAAkD,SAAY,CAC/D,MAAME,EAAoC,CACxC,cAAed,EAAc,KAC7B,aAAc,aACd,UAAW,SACX,UAAW,MACb,EACA,GAAG,MAAME,EAAO,SAAS,EAAE,sBAAsB,CAAE,KAAMW,CAAa,CAAC,EAGvE,MAAME,EAAS,MADI,IAAIV,EAA8BM,CAAM,EAC3B,aAAaG,CAAO,EAEpD,OAAOC,EAAO,QAAQ,CAAC,EAAE,KAAK,EAAI,EAClC,OAAOA,EAAO,QAAQ,CA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,SAAY,CACvD,MAAMG,EAAoC,CACxC,cAAed,EAAc,KAC7B,aAAc,aACd,UAAW,SACX,UAAW,MACb,EACMgB,EAAM,GACT,MAAMd,EAAO,SAAS,EACtB,sBAAsB,CAAE,KAAMW,CAAa,CAAC,EAG/C,MADmB,IAAIR,EAA8BM,CAAM,EAC1C,aAAaG,CAAO,EAErC,OAAOE,CAAG,EAAE,qBACV,OAAO,iBAAiB,CACtB,QAAS,CACP,CAACZ,CAA4B,EAAG,kBAAkBE,EAAQ,OAAO,GACjE,yBAA0BK,EAAO,WACnC,CACF,CAAC,CACH,CACF,CAAC,CACH,CAAC",
4
+ "sourcesContent": ["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n DeviceModelId,\n hexaStringToBuffer,\n} from \"@ledgerhq/device-management-kit\";\nimport axios from \"axios\";\nimport { Left } from \"purify-ts\";\n\nimport type { ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { LEDGER_CLIENT_VERSION_HEADER } from \"@/shared/constant/HttpHeaders\";\nimport { HttpSolanaOwnerInfoDataSource } from \"@/solana/data/HttpSolanaOwnerInfoDataSource\";\nimport type { SolanaTransactionContext } from \"@/solana/domain/solanaContextTypes\";\nimport PACKAGE from \"@root/package.json\";\n\nvi.mock(\"axios\");\n\nfunction stringToHex(str: string): string {\n const encoder = new TextEncoder();\n const bytes = encoder.encode(str); // Uint8Array\n return Array.from(bytes)\n .map((byte) => byte.toString(16).padStart(2, \"0\"))\n .join(\"\");\n}\n\ndescribe(\"HttpSolanaOwnerInfoDataSource\", () => {\n const config = {\n metadataServiceDomain: { url: \"https://some.doma.in\" },\n originToken: \"mock-origin-token\",\n } as ContextModuleConfig;\n\n const signedDescriptorHex = stringToHex(\"mock-descriptor\");\n const responseData = {\n tokenAccount: \"token-account\",\n owner: \"owner-address\",\n contract: \"contract-address\",\n signedDescriptor: signedDescriptorHex,\n };\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n it(\"should fetch address metadata via tokenAddress\", async () => {\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({ data: responseData });\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result.isRight()).toBe(true);\n expect(result.extract()).toEqual({\n tlvDescriptor: hexaStringToBuffer(signedDescriptorHex),\n });\n });\n\n it(\"should return an error if both tokenAddress and createATA are missing or invalid\", async () => {\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: undefined,\n challenge: \"random\",\n createATA: undefined,\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: either tokenAddress or valid createATA must be provided\",\n ),\n ),\n );\n });\n\n it(\"should return an error if challenge is missing\", async () => {\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: undefined,\n createATA: undefined,\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: challenge is required\",\n ),\n ),\n );\n });\n\n it(\"should return an error if the descriptor is not valid base64\", async () => {\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({\n data: { ...responseData, signedDescriptor: \"!!!not-valid-base64!!!\" },\n });\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid base64 tlvDescriptor received\",\n ),\n ),\n );\n });\n\n it(\"should return an error if the metadata request fails\", async () => {\n vi.spyOn(axios, \"request\").mockRejectedValueOnce(\n new Error(\"Network error\"),\n );\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: Failed to fetch address metadata\",\n ),\n ),\n );\n });\n\n it(\"should return an error if axios request return wrong shape for fetchAddressMetadata\", async () => {\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({\n data: { wrong: \"field\" },\n });\n\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid fetchAddressMetadata response shape\",\n ),\n ),\n );\n });\n\n it(\"should return an error if axios request return wrong shape for computeAddressMetadata\", async () => {\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({\n data: { wrong: \"field\" },\n });\n\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: undefined,\n challenge: \"random\",\n createATA: {\n address: \"some-address\",\n mintAddress: \"some-mint\",\n },\n };\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: invalid computeAddressMetadata response shape\",\n ),\n ),\n );\n });\n\n it(\"should throw if originToken is missing\", () => {\n expect(() => {\n new HttpSolanaOwnerInfoDataSource({\n ...config,\n originToken: undefined,\n } as any);\n }).toThrow(\n \"[ContextModule] - HttpSolanaOwnerInfoDataSource: origin token is required\",\n );\n });\n\n it(\"should call axios with correct headers\", async () => {\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n const spy = vi\n .spyOn(axios, \"request\")\n .mockResolvedValueOnce({ data: responseData });\n\n const dataSource = new HttpSolanaOwnerInfoDataSource(config);\n await dataSource.getOwnerInfo(context);\n\n expect(spy).toHaveBeenCalledWith(\n expect.objectContaining({\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n \"X-Ledger-Client-Origin\": config.originToken,\n },\n }),\n );\n });\n});\n"],
5
+ "mappings": "AACA,OACE,iBAAAA,EACA,sBAAAC,MACK,kCACP,OAAOC,MAAW,QAClB,OAAS,QAAAC,MAAY,YAGrB,OAAS,gCAAAC,MAAoC,gCAC7C,OAAS,iCAAAC,MAAqC,8CAE9C,OAAOC,MAAa,qBAEpB,GAAG,KAAK,OAAO,EAEf,SAASC,EAAYC,EAAqB,CAExC,MAAMC,EADU,IAAI,YAAY,EACV,OAAOD,CAAG,EAChC,OAAO,MAAM,KAAKC,CAAK,EACpB,IAAKC,GAASA,EAAK,SAAS,EAAE,EAAE,SAAS,EAAG,GAAG,CAAC,EAChD,KAAK,EAAE,CACZ,CAEA,SAAS,gCAAiC,IAAM,CAC9C,MAAMC,EAAS,CACb,sBAAuB,CAAE,IAAK,sBAAuB,EACrD,YAAa,mBACf,EAEMC,EAAsBL,EAAY,iBAAiB,EACnDM,EAAe,CACnB,aAAc,gBACd,MAAO,gBACP,SAAU,mBACV,iBAAkBD,CACpB,EAEA,WAAW,IAAM,CACf,GAAG,cAAc,CACnB,CAAC,EAED,GAAG,iDAAkD,SAAY,CAC/D,MAAME,EAAoC,CACxC,cAAed,EAAc,KAC7B,aAAc,aACd,UAAW,SACX,UAAW,MACb,EACA,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AAO,EAErC,OAAOE,CAAG,EAAE,qBACV,OAAO,iBAAiB,CACtB,QAAS,CACP,CAACZ,CAA4B,EAAG,kBAAkBE,EAAQ,OAAO,GACjE,yBAA0BK,EAAO,WACnC,CACF,CAAC,CACH,CACF,CAAC,CACH,CAAC",
6
6
  "names": ["DeviceModelId", "hexaStringToBuffer", "axios", "Left", "LEDGER_CLIENT_VERSION_HEADER", "HttpSolanaOwnerInfoDataSource", "PACKAGE", "stringToHex", "str", "bytes", "byte", "config", "signedDescriptorHex", "responseData", "context", "result", "spy"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var f=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var s=(r,e,t,o)=>{for(var a=o>1?void 0:o?p(e,t):e,i=r.length-1,n;i>=0;i--)(n=r[i])&&(a=(o?n(e,t,a):n(a))||a);return o&&a&&f(e,t,a),a},m=(r,e)=>(t,o)=>e(t,o,r);import{inject as d,injectable as l}from"inversify";import{Left as S}from"purify-ts";import{pkiTypes as u}from"../../pki/di/pkiTypes";import{KeyUsage as y}from"../../pki/model/KeyUsage";import{solanaContextTypes as C}from"../../solana/di/solanaContextTypes";let c=class{constructor(e,t){this._certificateLoader=t;this._dataSource=e}_dataSource;async load(e){const t=await this._certificateLoader.loadCertificate({keyId:"domain_metadata_key",keyUsage:y.TrustedName,targetDevice:e.deviceModelId});return t?(await this._dataSource.getOwnerInfo(e)).map(({descriptor:o,tokenAccount:a,owner:i,contract:n})=>({descriptor:o,tokenAccount:a,owner:i,contract:n,certificate:t})):S(new Error("[ContextModule] - DefaultSolanaContextLoader: CAL certificate is undefined"))}};c=s([l(),m(0,d(C.SolanaDataSource)),m(1,d(u.PkiCertificateLoader))],c);export{c as DefaultSolanaContextLoader};
1
+ var T=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var f=(i,t,a,o)=>{for(var r=o>1?void 0:o?y(t,a):t,n=i.length-1,s;n>=0;n--)(s=i[n])&&(r=(o?s(t,a,r):s(r))||r);return o&&r&&T(t,a,r),r},d=(i,t)=>(a,o)=>t(a,o,i);import{inject as m,injectable as k}from"inversify";import{Left as C}from"purify-ts";import{pkiTypes as _}from"../../pki/di/pkiTypes";import{KeyUsage as P}from"../../pki/model/KeyUsage";import{SolanaContextTypes as p}from"../../shared/model/SolanaContextTypes";import{solanaContextTypes as v}from"../../solana/di/solanaContextTypes";import{solanaTokenTypes as x}from"../../solanaToken/di/solanaTokenTypes";let l=class{constructor(t,a,o){this._dataSource=t;this._certificateLoader=a;this._solanaTokenLoader=o}async load(t){const{deviceModelId:a}=t,o=await this._certificateLoader.loadCertificate({keyId:"domain_metadata_key",keyUsage:P.TrustedName,targetDevice:a});if(!o)return C(new Error("[ContextModule] DefaultSolanaContextLoader: trustedNamePKICertificate is missing"));const n=[{loader:this._solanaTokenLoader,expectedType:p.SOLANA_TOKEN}].map(({loader:e,expectedType:c})=>{if(e.canHandle(t,c))return e.loadField(t)}).filter(e=>e!==void 0),u=(await Promise.allSettled(n)).map(e=>e.status==="fulfilled"?e.value:void 0).filter(e=>e!==void 0).sort((e,c)=>{const L=e.type===p.SOLANA_TOKEN?0:1,S=c.type===p.SOLANA_TOKEN?0:1;return L-S});return(await this._dataSource.getOwnerInfo(t)).map(({tlvDescriptor:e})=>({trustedNamePKICertificate:o,tlvDescriptor:e,loadersResults:u}))}};l=f([k(),d(0,m(v.SolanaDataSource)),d(1,m(_.PkiCertificateLoader)),d(2,m(x.SolanaTokenContextLoader))],l);export{l as DefaultSolanaContextLoader};
2
2
  //# sourceMappingURL=DefaultSolanaContextLoader.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/solana/domain/DefaultSolanaContextLoader.ts"],
4
- "sourcesContent": ["import { inject, injectable } from \"inversify\";\nimport { Left } from \"purify-ts\";\n\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { type SolanaDataSource } from \"@/solana/data/SolanaDataSource\";\nimport { solanaContextTypes } from \"@/solana/di/solanaContextTypes\";\n\nimport { SolanaContextLoader } from \"./SolanaContextLoader\";\nimport {\n SolanaTransactionContext,\n SolanaTransactionContextResult,\n} from \"./solanaContextTypes\";\n\n@injectable()\nexport class DefaultSolanaContextLoader implements SolanaContextLoader {\n private _dataSource: SolanaDataSource;\n\n constructor(\n @inject(solanaContextTypes.SolanaDataSource)\n dataSource: SolanaDataSource,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n ) {\n this._dataSource = dataSource;\n }\n\n async load(\n solanaContext: SolanaTransactionContext,\n ): Promise<SolanaTransactionContextResult> {\n // load the CAL certificate\n const certificate = await this._certificateLoader.loadCertificate({\n keyId: \"domain_metadata_key\",\n keyUsage: KeyUsage.TrustedName,\n targetDevice: solanaContext.deviceModelId,\n });\n if (!certificate) {\n return Left(\n new Error(\n \"[ContextModule] - DefaultSolanaContextLoader: CAL certificate is undefined\",\n ),\n );\n }\n\n // fetch the Solana context\n return (await this._dataSource.getOwnerInfo(solanaContext)).map(\n ({ descriptor, tokenAccount, owner, contract }) => ({\n descriptor,\n tokenAccount,\n owner,\n contract,\n certificate,\n }),\n );\n }\n}\n"],
5
- "mappings": "iOAAA,OAAS,UAAAA,EAAQ,cAAAC,MAAkB,YACnC,OAAS,QAAAC,MAAY,YAErB,OAAS,YAAAC,MAAgB,oBAEzB,OAAS,YAAAC,MAAgB,uBAEzB,OAAS,sBAAAC,MAA0B,iCAS5B,IAAMC,EAAN,KAAgE,CAGrE,YAEEC,EAEiBC,EACjB,CADiB,wBAAAA,EAEjB,KAAK,YAAcD,CACrB,CATQ,YAWR,MAAM,KACJE,EACyC,CAEzC,MAAMC,EAAc,MAAM,KAAK,mBAAmB,gBAAgB,CAChE,MAAO,sBACP,SAAUC,EAAS,YACnB,aAAcF,EAAc,aAC9B,CAAC,EACD,OAAKC,GASG,MAAM,KAAK,YAAY,aAAaD,CAAa,GAAG,IAC1D,CAAC,CAAE,WAAAG,EAAY,aAAAC,EAAc,MAAAC,EAAO,SAAAC,CAAS,KAAO,CAClD,WAAAH,EACA,aAAAC,EACA,MAAAC,EACA,SAAAC,EACA,YAAAL,CACF,EACF,EAhBSM,EACL,IAAI,MACF,4EACF,CACF,CAaJ,CACF,EAxCaV,EAANW,EAAA,CADNC,EAAW,EAKPC,EAAA,EAAAC,EAAOC,EAAmB,gBAAgB,GAE1CF,EAAA,EAAAC,EAAOE,EAAS,oBAAoB,IAN5BhB",
6
- "names": ["inject", "injectable", "Left", "pkiTypes", "KeyUsage", "solanaContextTypes", "DefaultSolanaContextLoader", "dataSource", "_certificateLoader", "solanaContext", "certificate", "KeyUsage", "descriptor", "tokenAccount", "owner", "contract", "Left", "__decorateClass", "injectable", "__decorateParam", "inject", "solanaContextTypes", "pkiTypes"]
4
+ "sourcesContent": ["import { inject, injectable } from \"inversify\";\nimport { Left } from \"purify-ts\";\n\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport {\n LoaderResult,\n SolanaContextTypes,\n} from \"@/shared/model/SolanaContextTypes\";\nimport { type SolanaDataSource } from \"@/solana/data/SolanaDataSource\";\nimport { solanaContextTypes } from \"@/solana/di/solanaContextTypes\";\n// import { lifiTypes } from \"@/solanaLifi/di/solanaLifiTypes\";\n// import { SolanaLifiContextLoader } from \"@/solanaLifi/domain/SolanaLifiContextLoader\";\nimport { solanaTokenTypes } from \"@/solanaToken/di/solanaTokenTypes\";\nimport { SolanaTokenContextLoader } from \"@/solanaToken/domain/SolanaTokenContextLoader\";\n\nimport { type SolanaContextLoader } from \"./SolanaContextLoader\";\nimport {\n SolanaTransactionContext,\n SolanaTransactionContextResult,\n} from \"./solanaContextTypes\";\n\n@injectable()\nexport class DefaultSolanaContextLoader implements SolanaContextLoader {\n constructor(\n @inject(solanaContextTypes.SolanaDataSource)\n private readonly _dataSource: SolanaDataSource,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n @inject(solanaTokenTypes.SolanaTokenContextLoader)\n private readonly _solanaTokenLoader: SolanaTokenContextLoader,\n // @inject(lifiTypes.SolanaLifiContextLoader)\n // private readonly _solanaLifiLoader: SolanaLifiContextLoader,\n ) {}\n\n async load(\n solanaContext: SolanaTransactionContext,\n ): Promise<SolanaTransactionContextResult> {\n const { deviceModelId } = solanaContext;\n\n const trustedNamePKICertificate =\n await this._certificateLoader.loadCertificate({\n keyId: \"domain_metadata_key\",\n keyUsage: KeyUsage.TrustedName,\n targetDevice: deviceModelId,\n });\n\n if (!trustedNamePKICertificate) {\n return Left(\n new Error(\n \"[ContextModule] DefaultSolanaContextLoader: trustedNamePKICertificate is missing\",\n ),\n );\n }\n\n const loaderEntries = [\n {\n loader: this._solanaTokenLoader,\n expectedType: SolanaContextTypes.SOLANA_TOKEN,\n },\n // TODO LIFI\n // Lifi loader currently disabled as WIP\n // {\n // loader: this._solanaLifiLoader,\n // expectedType: SolanaContextTypes.SOLANA_LIFI,\n // },\n ] as const;\n\n const loaderPromises: Promise<LoaderResult>[] = loaderEntries\n .map(({ loader, expectedType }) => {\n if (loader.canHandle(solanaContext, expectedType)) {\n return loader.loadField(solanaContext);\n }\n return undefined;\n })\n .filter((p): p is Promise<LoaderResult> => p !== undefined);\n\n const settledLoaders = await Promise.allSettled(loaderPromises);\n\n const loadersResults = settledLoaders\n .map((r) => (r.status === \"fulfilled\" ? r.value : undefined))\n .filter((v): v is LoaderResult => v !== undefined)\n // always sort with SOLANA_TOKEN first\n .sort((a, b) => {\n const A = a.type === SolanaContextTypes.SOLANA_TOKEN ? 0 : 1;\n const B = b.type === SolanaContextTypes.SOLANA_TOKEN ? 0 : 1;\n return A - B;\n });\n\n const tlvDescriptorEither =\n await this._dataSource.getOwnerInfo(solanaContext);\n\n return t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ahB,CAAa,GAExB,IAAI,CAAC,CAAE,cAAAiB,CAAc,KAAO,CACrD,0BAAAf,EACA,cAAAe,EACA,eAAAP,CACF,EAAE,CACJ,CACF,EA3Ead,EAANsB,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAmB,gBAAgB,GAE1CF,EAAA,EAAAC,EAAOE,EAAS,oBAAoB,GAEpCH,EAAA,EAAAC,EAAOG,EAAiB,wBAAwB,IANxC5B",
6
+ "names": ["inject", "injectable", "Left", "pkiTypes", "KeyUsage", "SolanaContextTypes", "solanaContextTypes", "solanaTokenTypes", "DefaultSolanaContextLoader", "_dataSource", "_certificateLoader", "_solanaTokenLoader", "solanaContext", "deviceModelId", "trustedNamePKICertificate", "KeyUsage", "Left", "loaderPromises", "SolanaContextTypes", "loader", "expectedType", "p", "loadersResults", "r", "v", "a", "b", "A", "B", "tlvDescriptor", "__decorateClass", "injectable", "__decorateParam", "inject", "solanaContextTypes", "pkiTypes", "solanaTokenTypes"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{DeviceModelId as i}from"@ledgerhq/device-management-kit";import{Left as d,Right as l}from"purify-ts";import{KeyUsage as s}from"../../pki/model/KeyUsage";import{DefaultSolanaContextLoader as f}from"../../solana/domain/DefaultSolanaContextLoader";describe("DefaultSolanaContextLoader",()=>{let a,e,r;const o={deviceModelId:i.FLEX,tokenAddress:"token-addr",challenge:"challenge-str"},n={descriptor:"cert-desc",signature:"cert-sig",keyUsageNumber:0,payload:new Uint8Array};beforeEach(()=>{vi.resetAllMocks(),a={getOwnerInfo:vi.fn()},e={loadCertificate:vi.fn()},r=new f(a,e)}),it("should call dataSource.getSolanaContext and certificateLoader.loadCertificate with correct args",async()=>{e.loadCertificate.mockResolvedValue(n),a.getOwnerInfo.mockResolvedValue(l({descriptor:Buffer.from("d"),tokenAccount:"tkn",owner:"own",contract:"ctr"})),await r.load(o),expect(e.loadCertificate).toHaveBeenCalledWith({keyId:"domain_metadata_key",keyUsage:s.TrustedName,targetDevice:o.deviceModelId}),expect(a.getOwnerInfo).toHaveBeenCalledWith(o)}),it("should return Left if certificate loader returns undefined",async()=>{e.loadCertificate.mockResolvedValue(void 0);const t=await r.load(o);expect(t).toEqual(d(new Error("[ContextModule] - DefaultSolanaContextLoader: CAL certificate is undefined")))}),it("should propagate Left from dataSource.getSolanaContext",async()=>{e.loadCertificate.mockResolvedValue(n);const t=new Error("DS failure");a.getOwnerInfo.mockResolvedValue(d(t));const c=await r.load(o);expect(c).toEqual(d(t))}),it("should return Right with merged data and certificate on success",async()=>{e.loadCertificate.mockResolvedValue(n);const t={descriptor:Buffer.from("dd"),tokenAccount:"tokenAcct",owner:"ownerAddr",contract:"contractAddr",certificate:n};a.getOwnerInfo.mockResolvedValue(l(t));const c=await r.load(o);expect(c.isRight()).toBe(!0),expect(c.extract()).toEqual({...t,certificate:n})})});
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"../../solanaToken/domain/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) and still fetched certificate beforehand",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"}})})})});
2
2
  //# sourceMappingURL=DefaultSolanaContextLoader.test.js.map
@@ -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-explicit-any */\nimport { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { DefaultSolanaContextLoader } from \"@/solana/domain/DefaultSolanaContextLoader\";\nimport type {\n SolanaTransactionContext,\n SolanaTransactionContextResultSuccess,\n} from \"@/solana/domain/solanaContextTypes\";\n\ndescribe(\"DefaultSolanaContextLoader\", () => {\n let mockDataSource: {\n getOwnerInfo: any;\n };\n let mockCertLoader: {\n loadCertificate: any;\n };\n let loader: DefaultSolanaContextLoader;\n\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"token-addr\",\n challenge: \"challenge-str\",\n } as any;\n\n const fakeCert = {\n descriptor: \"cert-desc\",\n signature: \"cert-sig\",\n keyUsageNumber: 0,\n payload: new Uint8Array(),\n };\n\n beforeEach(() => {\n vi.resetAllMocks();\n mockDataSource = {\n getOwnerInfo: vi.fn(),\n };\n mockCertLoader = {\n loadCertificate: vi.fn(),\n };\n\n loader = new DefaultSolanaContextLoader(\n mockDataSource as any,\n mockCertLoader as any,\n );\n });\n\n it(\"should call dataSource.getSolanaContext and certificateLoader.loadCertificate with correct args\", async () => {\n // given\n mockCertLoader.loadCertificate.mockResolvedValue(fakeCert);\n mockDataSource.getOwnerInfo.mockResolvedValue(\n Right({\n descriptor: Buffer.from(\"d\"),\n tokenAccount: \"tkn\",\n owner: \"own\",\n contract: \"ctr\",\n }),\n );\n\n // when\n await loader.load(context);\n\n // then\n expect(mockCertLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: \"domain_metadata_key\",\n keyUsage: KeyUsage.TrustedName,\n targetDevice: context.deviceModelId,\n });\n expect(mockDataSource.getOwnerInfo).toHaveBeenCalledWith(context);\n });\n\n it(\"should return Left if certificate loader returns undefined\", async () => {\n mockCertLoader.loadCertificate.mockResolvedValue(undefined);\n\n const result = await loader.load(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - DefaultSolanaContextLoader: CAL certificate is undefined\",\n ),\n ),\n );\n });\n\n it(\"should propagate Left from dataSource.getSolanaContext\", async () => {\n mockCertLoader.loadCertificate.mockResolvedValue(fakeCert);\n const dsError = new Error(\"DS failure\");\n mockDataSource.getOwnerInfo.mockResolvedValue(Left(dsError));\n\n const result = await loader.load(context);\n\n expect(result).toEqual(Left(dsError));\n });\n\n it(\"should return Right with merged data and certificate on success\", async () => {\n mockCertLoader.loadCertificate.mockResolvedValue(fakeCert);\n\n const dsPayload: SolanaTransactionContextResultSuccess = {\n descriptor: Buffer.from(\"dd\"),\n tokenAccount: \"tokenAcct\",\n owner: \"ownerAddr\",\n contract: \"contractAddr\",\n certificate: fakeCert,\n };\n mockDataSource.getOwnerInfo.mockResolvedValue(Right(dsPayload));\n\n const result = await loader.load(context);\n\n expect(result.isRight()).toBe(true);\n expect(result.extract()).toEqual({\n ...dsPayload,\n certificate: fakeCert,\n });\n });\n});\n"],
5
- "mappings": "AACA,OAAS,iBAAAA,MAAqB,kCAC9B,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAE5B,OAAS,YAAAC,MAAgB,uBACzB,OAAS,8BAAAC,MAAkC,6CAM3C,SAAS,6BAA8B,IAAM,CAC3C,IAAIC,EAGAC,EAGAC,EAEJ,MAAMC,E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I,EAC5B,aAAc,YACd,MAAO,YACP,SAAU,eACV,YAAaH,CACf,EACAJ,EAAe,aAAa,kBAAkBH,EAAMU,CAAS,CAAC,EAE9D,MAAMF,EAAS,MAAMH,EAAO,KAAKC,CAAO,EAExC,OAAOE,EAAO,QAAQ,CAAC,EAAE,KAAK,EAAI,EAClC,OAAOA,EAAO,QAAQ,CAAC,EAAE,QAAQ,CAC/B,GAAGE,EACH,YAAaH,CACf,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["DeviceModelId", "Left", "Right", "KeyUsage", "DefaultSolanaContextLoader", "mockDataSource", "mockCertLoader", "loader", "context", "fakeCert", "result", "dsError", "dsPayload"]
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,gB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AS,EAEvE,MAAMS,EAAS,MAAMF,EAAO,UAAUJ,CAAO,EAE7CV,EAAOgB,CAAM,EAAE,QAAQ,CACrB,KAAMZ,EAAmB,aACzB,QAAS,CACP,sBAAuB,CACrB,KAAMK,EAAkB,WAAW,KACnC,UAAW,UACb,CACF,EACA,YAAa,MACf,CAAC,CACH,CAAC,CACH,CAAC,EAEDV,EAAS,2BAA4B,IAAM,CACzCE,EAAG,8CAA+C,IAAM,CACtD,MAAMa,EAASH,EAAW,MAAM,EAG1BK,EAFSF,EAAe,eAAe,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"]
7
7
  }
@@ -0,0 +1,2 @@
1
+ var f=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var c=(i,t,r,e)=>{for(var o=e>1?void 0:e?d(t,r):t,n=i.length-1,a;n>=0;n--)(a=i[n])&&(o=(e?a(t,r,o):a(o))||o);return e&&o&&f(t,r,o),o},p=(i,t)=>(r,e)=>t(r,e,i);import l from"axios";import{inject as u,injectable as E}from"inversify";import{Left as m,Right as h}from"purify-ts";import{configTypes as g}from"../../config/di/configTypes";import{LEDGER_CLIENT_VERSION_HEADER as C}from"../../shared/constant/HttpHeaders";import D from"../../../package.json";let s=class{constructor(t){this.config=t}async getTransactionDescriptorsPayload({templateId:t}){try{const{data:r}=await l.request({method:"GET",url:`${this.config.cal.url}/swap_templates`,params:{template_id:t,output:"id,chain_id,instructions,descriptors",ref:"ref=commit:866b6e7633a7a806fab7f9941bcc3df7ee640784"},headers:{[C]:`context-module/${D.version}`}});return!r||r.length===0||!r[0]?m(new Error(`[ContextModule] HttpSolanaLifiDataSource: no transaction descriptors for id ${t}`)):h(r[0])}catch{return m(new Error("[ContextModule] HttpSolanaLifiDataSource: Failed to fetch transaction descriptors"))}}};s=c([E(),p(0,u(g.Config))],s);export{s as HttpSolanaLifiDataSource};
2
+ //# sourceMappingURL=HttpSolanaLifiDataSource.js.map