@ledgerhq/context-module 0.0.0-multisig-2-20250922095845 → 0.0.0-multisig-20250925175241
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/src/ContextModule.js +1 -1
- package/lib/cjs/src/ContextModule.js.map +1 -1
- package/lib/cjs/src/ContextModuleBuilder.test.js +1 -1
- package/lib/cjs/src/ContextModuleBuilder.test.js.map +2 -2
- package/lib/cjs/src/DefaultContextModule.js +1 -1
- package/lib/cjs/src/DefaultContextModule.js.map +3 -3
- package/lib/cjs/src/DefaultContextModule.test.js +1 -1
- package/lib/cjs/src/DefaultContextModule.test.js.map +3 -3
- package/lib/cjs/src/calldata/data/HttpCalldataDescriptorDataSource.js +1 -1
- package/lib/cjs/src/calldata/data/HttpCalldataDescriptorDataSource.js.map +3 -3
- package/lib/cjs/src/calldata/domain/CalldataContextLoader.js +1 -1
- package/lib/cjs/src/calldata/domain/CalldataContextLoader.js.map +3 -3
- package/lib/cjs/src/calldata/domain/CalldataContextLoader.test.js +1 -1
- package/lib/cjs/src/calldata/domain/CalldataContextLoader.test.js.map +3 -3
- package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.js +1 -1
- package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.js.map +3 -3
- package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js +1 -1
- package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js.map +3 -3
- package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.js +1 -1
- package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.js.map +3 -3
- package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.test.js +1 -1
- package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.test.js.map +3 -3
- package/lib/cjs/src/index.js +1 -1
- package/lib/cjs/src/index.js.map +2 -2
- package/lib/cjs/src/nft/domain/NftContextLoader.js +1 -1
- package/lib/cjs/src/nft/domain/NftContextLoader.js.map +3 -3
- package/lib/cjs/src/nft/domain/NftContextLoader.test.js +1 -1
- package/lib/cjs/src/nft/domain/NftContextLoader.test.js.map +3 -3
- package/lib/cjs/src/pki/model/PkiCertificateInfo.js +1 -1
- package/lib/cjs/src/pki/model/PkiCertificateInfo.js.map +1 -1
- package/lib/cjs/src/proxy/data/HttpProxyDataSource.js +1 -1
- package/lib/cjs/src/proxy/data/HttpProxyDataSource.js.map +3 -3
- package/lib/cjs/src/proxy/data/HttpProxyDataSource.test.js +1 -1
- package/lib/cjs/src/proxy/data/HttpProxyDataSource.test.js.map +3 -3
- package/lib/cjs/src/proxy/data/HttpSafeProxyDataSource.js +1 -1
- package/lib/cjs/src/proxy/data/HttpSafeProxyDataSource.js.map +2 -2
- package/lib/cjs/src/proxy/data/HttpSafeProxyDataSource.test.js +1 -1
- package/lib/cjs/src/proxy/data/HttpSafeProxyDataSource.test.js.map +2 -2
- package/lib/cjs/src/proxy/data/ProxyDataSource.js +1 -1
- package/lib/cjs/src/proxy/data/ProxyDataSource.js.map +1 -1
- package/lib/cjs/src/proxy/data/dto/SafeProxyImplementationAddressDto.js +1 -1
- package/lib/cjs/src/proxy/data/dto/SafeProxyImplementationAddressDto.js.map +1 -1
- package/lib/cjs/src/proxy/domain/ProxyContextFieldLoader.js +1 -1
- package/lib/cjs/src/proxy/domain/ProxyContextFieldLoader.js.map +3 -3
- package/lib/cjs/src/proxy/domain/ProxyContextFieldLoader.test.js +1 -1
- package/lib/cjs/src/proxy/domain/ProxyContextFieldLoader.test.js.map +2 -2
- package/lib/cjs/src/proxy/model/ProxyDelegateCall.js +1 -1
- package/lib/cjs/src/proxy/model/ProxyDelegateCall.js.map +1 -1
- package/lib/cjs/src/shared/domain/ContextLoader.js +1 -1
- package/lib/cjs/src/shared/domain/ContextLoader.js.map +1 -1
- package/lib/cjs/src/shared/utils/KeyUsageMapper.js +1 -1
- package/lib/cjs/src/shared/utils/KeyUsageMapper.js.map +2 -2
- package/lib/cjs/src/token/domain/TokenContextLoader.js +1 -1
- package/lib/cjs/src/token/domain/TokenContextLoader.js.map +3 -3
- package/lib/cjs/src/token/domain/TokenContextLoader.test.js +1 -1
- package/lib/cjs/src/token/domain/TokenContextLoader.test.js.map +3 -3
- package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.js +1 -1
- package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.js.map +3 -3
- package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.test.js +1 -1
- package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.test.js.map +3 -3
- package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.js +1 -1
- package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.js.map +2 -2
- package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.js +1 -1
- package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.js.map +3 -3
- package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.test.js +1 -1
- package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.test.js.map +2 -2
- package/lib/cjs/src/uniswap/domain/UniswapContextLoader.js +1 -1
- package/lib/cjs/src/uniswap/domain/UniswapContextLoader.js.map +3 -3
- package/lib/cjs/src/uniswap/domain/UniswapContextLoader.test.js +1 -1
- package/lib/cjs/src/uniswap/domain/UniswapContextLoader.test.js.map +3 -3
- package/lib/esm/src/ContextModuleBuilder.test.js +1 -1
- package/lib/esm/src/ContextModuleBuilder.test.js.map +2 -2
- package/lib/esm/src/DefaultContextModule.js +1 -1
- package/lib/esm/src/DefaultContextModule.js.map +3 -3
- package/lib/esm/src/DefaultContextModule.test.js +1 -1
- package/lib/esm/src/DefaultContextModule.test.js.map +3 -3
- package/lib/esm/src/calldata/data/HttpCalldataDescriptorDataSource.js +1 -1
- package/lib/esm/src/calldata/data/HttpCalldataDescriptorDataSource.js.map +3 -3
- package/lib/esm/src/calldata/domain/CalldataContextLoader.js +1 -1
- package/lib/esm/src/calldata/domain/CalldataContextLoader.js.map +3 -3
- package/lib/esm/src/calldata/domain/CalldataContextLoader.test.js +1 -1
- package/lib/esm/src/calldata/domain/CalldataContextLoader.test.js.map +3 -3
- package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.js +1 -1
- package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.js.map +3 -3
- package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js +1 -1
- package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js.map +3 -3
- package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.js +1 -1
- package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.js.map +3 -3
- package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.test.js +1 -1
- package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.test.js.map +3 -3
- package/lib/esm/src/index.js +1 -1
- package/lib/esm/src/index.js.map +2 -2
- package/lib/esm/src/nft/domain/NftContextLoader.js +1 -1
- package/lib/esm/src/nft/domain/NftContextLoader.js.map +3 -3
- package/lib/esm/src/nft/domain/NftContextLoader.test.js +1 -1
- package/lib/esm/src/nft/domain/NftContextLoader.test.js.map +3 -3
- package/lib/esm/src/proxy/data/HttpProxyDataSource.js +1 -1
- package/lib/esm/src/proxy/data/HttpProxyDataSource.js.map +3 -3
- package/lib/esm/src/proxy/data/HttpProxyDataSource.test.js +1 -1
- package/lib/esm/src/proxy/data/HttpProxyDataSource.test.js.map +3 -3
- package/lib/esm/src/proxy/data/HttpSafeProxyDataSource.js +1 -1
- package/lib/esm/src/proxy/data/HttpSafeProxyDataSource.js.map +2 -2
- package/lib/esm/src/proxy/data/HttpSafeProxyDataSource.test.js +1 -1
- package/lib/esm/src/proxy/data/HttpSafeProxyDataSource.test.js.map +2 -2
- package/lib/esm/src/proxy/domain/ProxyContextFieldLoader.js +1 -1
- package/lib/esm/src/proxy/domain/ProxyContextFieldLoader.js.map +3 -3
- package/lib/esm/src/proxy/domain/ProxyContextFieldLoader.test.js +1 -1
- package/lib/esm/src/proxy/domain/ProxyContextFieldLoader.test.js.map +2 -2
- package/lib/esm/src/shared/utils/KeyUsageMapper.js +1 -1
- package/lib/esm/src/shared/utils/KeyUsageMapper.js.map +2 -2
- package/lib/esm/src/token/domain/TokenContextLoader.js +1 -1
- package/lib/esm/src/token/domain/TokenContextLoader.js.map +3 -3
- package/lib/esm/src/token/domain/TokenContextLoader.test.js +1 -1
- package/lib/esm/src/token/domain/TokenContextLoader.test.js.map +3 -3
- package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.js +1 -1
- package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.js.map +3 -3
- package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.test.js +1 -1
- package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.test.js.map +3 -3
- package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.js +1 -1
- package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.js.map +2 -2
- package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.js +1 -1
- package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.js.map +3 -3
- package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.test.js +1 -1
- package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.test.js.map +2 -2
- package/lib/esm/src/uniswap/domain/UniswapContextLoader.js +1 -1
- package/lib/esm/src/uniswap/domain/UniswapContextLoader.js.map +3 -3
- package/lib/esm/src/uniswap/domain/UniswapContextLoader.test.js +1 -1
- package/lib/esm/src/uniswap/domain/UniswapContextLoader.test.js.map +3 -3
- package/lib/types/src/ContextModule.d.ts +1 -2
- package/lib/types/src/ContextModule.d.ts.map +1 -1
- package/lib/types/src/DefaultContextModule.d.ts +1 -2
- package/lib/types/src/DefaultContextModule.d.ts.map +1 -1
- package/lib/types/src/calldata/data/HttpCalldataDescriptorDataSource.d.ts.map +1 -1
- package/lib/types/src/calldata/domain/CalldataContextLoader.d.ts +12 -4
- package/lib/types/src/calldata/domain/CalldataContextLoader.d.ts.map +1 -1
- package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.d.ts +9 -4
- package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.d.ts.map +1 -1
- package/lib/types/src/external-plugin/domain/ExternalPluginContextLoader.d.ts +11 -4
- package/lib/types/src/external-plugin/domain/ExternalPluginContextLoader.d.ts.map +1 -1
- package/lib/types/src/index.d.ts +0 -1
- package/lib/types/src/index.d.ts.map +1 -1
- package/lib/types/src/nft/domain/NftContextLoader.d.ts +10 -4
- package/lib/types/src/nft/domain/NftContextLoader.d.ts.map +1 -1
- package/lib/types/src/pki/model/PkiCertificateInfo.d.ts +1 -2
- package/lib/types/src/pki/model/PkiCertificateInfo.d.ts.map +1 -1
- package/lib/types/src/proxy/data/HttpProxyDataSource.d.ts.map +1 -1
- package/lib/types/src/proxy/data/HttpSafeProxyDataSource.d.ts.map +1 -1
- package/lib/types/src/proxy/data/ProxyDataSource.d.ts +2 -0
- package/lib/types/src/proxy/data/ProxyDataSource.d.ts.map +1 -1
- package/lib/types/src/proxy/data/dto/SafeProxyImplementationAddressDto.d.ts +2 -0
- package/lib/types/src/proxy/data/dto/SafeProxyImplementationAddressDto.d.ts.map +1 -1
- package/lib/types/src/proxy/domain/ProxyContextFieldLoader.d.ts.map +1 -1
- package/lib/types/src/proxy/model/ProxyDelegateCall.d.ts +2 -0
- package/lib/types/src/proxy/model/ProxyDelegateCall.d.ts.map +1 -1
- package/lib/types/src/shared/domain/ContextLoader.d.ts +13 -4
- package/lib/types/src/shared/domain/ContextLoader.d.ts.map +1 -1
- package/lib/types/src/shared/utils/KeyUsageMapper.d.ts +1 -2
- package/lib/types/src/shared/utils/KeyUsageMapper.d.ts.map +1 -1
- package/lib/types/src/token/domain/TokenContextLoader.d.ts +10 -4
- package/lib/types/src/token/domain/TokenContextLoader.d.ts.map +1 -1
- package/lib/types/src/trusted-name/domain/TrustedNameContextLoader.d.ts +9 -4
- package/lib/types/src/trusted-name/domain/TrustedNameContextLoader.d.ts.map +1 -1
- package/lib/types/src/typed-data/data/HttpTypedDataDataSource.d.ts.map +1 -1
- package/lib/types/src/typed-data/domain/DefaultTypedDataContextLoader.d.ts.map +1 -1
- package/lib/types/src/uniswap/domain/UniswapContextLoader.d.ts +11 -4
- package/lib/types/src/uniswap/domain/UniswapContextLoader.d.ts.map +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +6 -6
- package/lib/cjs/src/shared/model/TransactionContext.js +0 -2
- package/lib/cjs/src/shared/model/TransactionContext.js.map +0 -7
- package/lib/esm/src/shared/model/TransactionContext.js +0 -1
- package/lib/esm/src/shared/model/TransactionContext.js.map +0 -7
- package/lib/types/src/shared/model/TransactionContext.d.ts +0 -8
- package/lib/types/src/shared/model/TransactionContext.d.ts.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/DefaultContextModule.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type ContextModuleConfig } from \"./config/model/ContextModuleConfig\";\nimport { type ContextFieldLoader } from \"./shared/domain/ContextFieldLoader\";\nimport {\n type ClearSignContext,\n ClearSignContextType,\n} from \"./shared/model/ClearSignContext\";\nimport { type TransactionContext } from \"./shared/model/TransactionContext\";\nimport { type TypedDataContext } from \"./shared/model/TypedDataContext\";\nimport type { TypedDataContextLoader } from \"./typed-data/domain/TypedDataContextLoader\";\nimport { DefaultContextModule } from \"./DefaultContextModule\";\n\nconst contextLoaderStubBuilder = () => {\n return { load: vi.fn(), loadField: vi.fn() };\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({} as TransactionContext);\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({} as TransactionContext);\n\n expect(res).toEqual([]);\n });\n\n it(\"should call all fetch method from metadata fetcher\", async () => {\n const loader = contextLoaderStubBuilder();\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader, loader],\n });\n\n await contextModule.getContexts({} as TransactionContext);\n\n expect(loader.load).toHaveBeenCalledTimes(2);\n });\n\n it(\"should return an array of context response\", async () => {\n const loader = contextLoaderStubBuilder();\n const responses = [\n [{ type: \"provideERC20Info\", payload: \"payload1\" }],\n [\n { type: \"provideERC20Info\", payload: \"payload2\" },\n { type: \"plugin\", payload: \"payload3\" },\n ],\n ];\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({} as TransactionContext);\n\n expect(loader.load).toHaveBeenCalledTimes(2);\n expect(res).toEqual(responses.flat());\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 it(\"should return a web3 check context\", async () => {\n const loader = contextLoaderStubBuilder();\n vi.spyOn(loader, \"load\").mockResolvedValueOnce(\n Right({ descriptor: \"payload\" }),\n );\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [],\n customWeb3CheckLoader: loader,\n });\n\n const res = await contextModule.getWeb3Checks({\n deviceModelId: DeviceModelId.FLEX,\n from: \"from\",\n rawTx: \"rawTx\",\n chainId: 1,\n });\n\n expect(loader.load).toHaveBeenCalledTimes(1);\n expect(res).toEqual({ type: \"web3Check\", payload: \"payload\" });\n });\n\n it(\"should return null if no web3 check context\", async () => {\n const loader = contextLoaderStubBuilder();\n vi.spyOn(loader, \"load\").mockResolvedValue(Left(new Error(\"error\")));\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [],\n customWeb3CheckLoader: loader,\n });\n\n const res = await contextModule.getWeb3Checks({\n deviceModelId: DeviceModelId.FLEX,\n from: \"from\",\n rawTx: \"rawTx\",\n chainId: 1,\n });\n\n expect(loader.load).toHaveBeenCalledTimes(1);\n expect(res).toBeNull();\n });\n\n it(\"should throw an error if origin token is not provided\", () => {\n expect(\n () =>\n new DefaultContextModule({\n ...defaultContextModuleConfig,\n originToken: undefined,\n }),\n ).toThrow(\"Origin token is required\");\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
|
-
"mappings": "AAAA,OAAS,iBAAAA,MAAqB,kCAC9B,OAAS,QAAAC,EAAM,SAAAC,MAAa,
|
|
6
|
-
"names": ["DeviceModelId", "Left", "Right", "ClearSignContextType", "DefaultContextModule", "contextLoaderStubBuilder", "fieldLoaderStubBuilder", "typedDataLoader", "defaultContextModuleConfig", "res", "loader", "responses", "
|
|
4
|
+
"sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { 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 it(\"should return a web3 check context\", async () => {\n const loader = { load: vi.fn() }; // Web3CheckLoader doesn't use ContextLoader interface\n vi.spyOn(loader, \"load\").mockResolvedValueOnce(\n Right({ descriptor: \"payload\" }),\n );\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [],\n customWeb3CheckLoader: loader,\n });\n\n const res = await contextModule.getWeb3Checks({\n deviceModelId: DeviceModelId.FLEX,\n from: \"from\",\n rawTx: \"rawTx\",\n chainId: 1,\n });\n\n expect(loader.load).toHaveBeenCalledTimes(1);\n expect(res).toEqual({ type: \"web3Check\", payload: \"payload\" });\n });\n\n it(\"should return null if no web3 check context\", async () => {\n const loader = { load: vi.fn() }; // Web3CheckLoader doesn't use ContextLoader interface\n vi.spyOn(loader, \"load\").mockResolvedValue(Left(new Error(\"error\")));\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [],\n customWeb3CheckLoader: loader,\n });\n\n const res = await contextModule.getWeb3Checks({\n deviceModelId: DeviceModelId.FLEX,\n from: \"from\",\n rawTx: \"rawTx\",\n chainId: 1,\n });\n\n expect(loader.load).toHaveBeenCalledTimes(1);\n expect(res).toBeNull();\n });\n\n it(\"should throw an error if origin token is not provided\", () => {\n expect(\n () =>\n new DefaultContextModule({\n ...defaultContextModuleConfig,\n originToken: undefined,\n }),\n ).toThrow(\"Origin token is required\");\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
|
+
"mappings": "AAAA,OAAS,iBAAAA,MAAqB,kCAC9B,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAK5B,OAEE,wBAAAC,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,CAA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,EAG9CC,EAAS,MAAMJ,EAAc,gBACjCG,EACAf,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
|
+
"names": ["DeviceModelId", "Left", "Right", "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
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var I=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var h=(l,e,t,r)=>{for(var i=r>1?void 0:r?S(e,t):e,n=l.length-1,o;n>=0;n--)(o=l[n])&&(i=(r?o(e,t,i):o(i))||i);return r&&i&&I(e,t,i),i},
|
|
1
|
+
var I=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var h=(l,e,t,r)=>{for(var i=r>1?void 0:r?S(e,t):e,n=l.length-1,o;n>=0;n--)(o=l[n])&&(i=(r?o(e,t,i):o(i))||i);return r&&i&&I(e,t,i),i},y=(l,e)=>(t,r)=>e(t,r,l);import M from"axios";import{inject as m,injectable as R}from"inversify";import{Left as c,Right as L}from"purify-ts";import{configTypes as x}from"../../config/di/configTypes";import{pkiTypes as O}from"../../pki/di/pkiTypes";import{KeyId as F}from"../../pki/model/KeyId";import{KeyUsage as G}from"../../pki/model/KeyUsage";import{LEDGER_CLIENT_VERSION_HEADER as k,LEDGER_ORIGIN_TOKEN_HEADER as U}from"../../shared/constant/HttpHeaders";import{ClearSignContextReferenceType as a,ClearSignContextType as f}from"../../shared/model/ClearSignContext";import{INFO_SIGNATURE_TAG as D}from"../../shared/model/SignatureTags";import{HexStringUtils as E}from"../../shared/utils/HexStringUtils";import j from"../../../package.json";let u=class{constructor(e,t,r){this.config=e;this._certificateLoader=t;this.endpoint=r}async getCalldataDescriptors({chainId:e,address:t,selector:r,deviceModelId:i}){let n;try{n=(await M.request({method:"GET",url:`${this.config.cal.url}/${this.endpoint}`,params:{output:"descriptors_calldata",chain_id:e,contracts:t,contract_address:t,ref:`branch:${this.config.cal.branch}`},headers:{[k]:`context-module/${j.version}`,[U]:this.config.originToken}})).data}catch(o){return c(new Error(`[ContextModule] HttpCalldataDescriptorDataSource: Failed to fetch calldata descriptors: ${o}`))}if(!Array.isArray(n))return c(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Response is not an array"));if(n.length===0)return c(new Error(`[ContextModule] HttpCalldataDescriptorDataSource: No data for contract ${t} and selector ${r}`));for(const o of n){t=t.toLowerCase(),r=`0x${r.slice(2).toLowerCase()}`;const s=o.descriptors_calldata?.[t]?.[r];if(!s||!this.isCalldataDescriptorV1(s,this.config.cal.mode))continue;const V=s.transaction_info.descriptor.data,T=s.transaction_info.descriptor.signatures[this.config.cal.mode],g={targetDevice:i,keyUsage:G.Calldata,keyId:F.CalCalldataKey},C=await this._certificateLoader.loadCertificate(g),A={type:f.TRANSACTION_INFO,payload:E.appendSignatureToPayload(V,T,D),certificate:C},d=[];for(const[p,b]of Object.entries(s.enums))for(const[v,{data:P,signatures:N}]of Object.entries(b))d.push({type:f.ENUM,id:Number(p),value:Number(v),payload:E.appendSignatureToPayload(P,N[this.config.cal.mode],D),certificate:C});const _=s.fields.map(p=>({type:f.TRANSACTION_FIELD_DESCRIPTION,payload:p.descriptor,reference:this.getReference(p.param)}));return L([A,...d,..._])}return c(new Error(`[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract ${t} and selector ${r}`))}getReference(e){if(e.type==="TOKEN_AMOUNT"&&e.token!==void 0&&e.token.type==="path")return{type:a.TOKEN,valuePath:this.toGenericPath(e.token.binary_path)};if(e.type==="TOKEN_AMOUNT"&&e.token!==void 0&&e.token.type==="constant")return{type:a.TOKEN,value:e.token.value};if(e.type==="NFT"&&e.collection.type==="path")return{type:a.NFT,valuePath:this.toGenericPath(e.collection.binary_path)};if(e.type==="NFT"&&e.collection.type==="constant")return{type:a.NFT,value:e.collection.value};if(e.type==="TRUSTED_NAME"&&e.value.type==="path")return{type:a.TRUSTED_NAME,valuePath:this.toGenericPath(e.value.binary_path),types:e.types,sources:e.sources};if(e.type==="ENUM"&&e.value.type==="path")return{type:a.ENUM,valuePath:this.toGenericPath(e.value.binary_path),id:e.id};if(e.type==="CALLDATA"&&e.value.type==="path"&&e.callee.type==="path")return{type:a.CALLDATA,valuePath:this.toGenericPath(e.value.binary_path),callee:this.toGenericPath(e.callee.binary_path),selector:e.selector?.type==="path"?this.toGenericPath(e.selector.binary_path):void 0,amount:e.amount?.type==="path"?this.toGenericPath(e.amount.binary_path):void 0,spender:e.spender?.type==="path"?this.toGenericPath(e.spender.binary_path):void 0,chainId:e.chainId?.type==="path"?this.toGenericPath(e.chainId.binary_path):void 0}}toGenericPath(e){return e.type==="CONTAINER"?e.value:e.elements.map(t=>{if(t.type==="ARRAY"){const{weight:r,...i}=t;return{itemSize:r,...i}}else if(t.type==="LEAF"){const{leaf_type:r,...i}=t;return{leafType:r,...i}}return t})}isCalldataDescriptorV1(e,t){return typeof e=="object"&&e.type==="calldata"&&e.version==="v1"&&this.isTransactionInfoV1(e.transaction_info,t)&&this.isEnumV1(e.enums,t)&&Array.isArray(e.fields)&&e.fields.every(r=>this.isFieldV1(r))}isTransactionInfoV1(e,t){return typeof e=="object"&&typeof e.descriptor=="object"&&typeof e.descriptor.data=="string"&&typeof e.descriptor.signatures=="object"&&typeof e.descriptor.signatures[t]=="string"}isEnumV1(e,t){return typeof e=="object"&&Object.entries(e).every(([r,i])=>typeof r=="string"&&typeof i=="object"&&Object.entries(i).every(([n,o])=>typeof n=="string"&&typeof o=="object"&&typeof o.data=="string"&&o.signatures!==void 0&&this.isCalldataSignatures(o.signatures,t)))}isCalldataSignatures(e,t){return typeof e=="object"&&typeof e[t]=="string"}isFieldV1(e){return typeof e=="object"&&typeof e.descriptor=="string"&&typeof e.param=="object"&&typeof e.param.value=="object"&&this.isDescriptorValueV1(e.param.value)&&(e.param.type==="RAW"||e.param.type==="AMOUNT"||e.param.type==="DATETIME"||e.param.type==="DURATION"||e.param.type==="UNIT"||e.param.type==="ENUM"||e.param.type==="NFT"&&this.isDescriptorValueV1(e.param.collection)||e.param.type==="TOKEN_AMOUNT"&&(e.param.token===void 0||this.isDescriptorValueV1(e.param.token))||e.param.type==="TRUSTED_NAME"&&Array.isArray(e.param.types)&&Array.isArray(e.param.sources)&&e.param.types.every(t=>typeof t=="string")&&e.param.sources.every(t=>typeof t=="string")||e.param.type==="CALLDATA"&&this.isDescriptorValueV1(e.param.value)&&this.isDescriptorValueV1(e.param.callee)&&(e.param.selector===void 0||this.isDescriptorValueV1(e.param.selector))&&(e.param.amount===void 0||this.isDescriptorValueV1(e.param.amount))&&(e.param.spender===void 0||this.isDescriptorValueV1(e.param.spender))&&(e.param.chainId===void 0||this.isDescriptorValueV1(e.param.chainId)))}isDescriptorValueV1(e){return typeof e=="object"&&typeof e.type_family=="string"&&["UINT","INT","UFIXED","FIXED","ADDRESS","BOOL","BYTES","STRING"].includes(e.type_family)&&(typeof e.type_size>"u"||typeof e.type_size=="number")&&(e.type==="path"&&this.isCalldataDescriptorValueBinaryPathV1(e)||e.type==="constant"&&this.isCalldataDescriptorValueConstantV1(e))}isCalldataDescriptorValueConstantV1(e){return typeof e=="object"&&e.type==="constant"&&typeof e.value=="string"}isCalldataDescriptorValueBinaryPathV1(e){return typeof e=="object"&&(e.type==="path"&&e.binary_path.type==="CONTAINER"&&["FROM","TO","VALUE"].includes(e.binary_path.value)||e.binary_path.type==="DATA"&&Array.isArray(e.binary_path.elements)&&e.binary_path.elements.every(t=>this.isPathElementV1(t)))}isPathElementV1(e){return typeof e=="object"&&(e.type==="REF"||e.type==="TUPLE"&&typeof e.offset=="number"||e.type==="ARRAY"&&typeof e.weight=="number"&&(typeof e.start>"u"||typeof e.start=="number")&&(typeof e.end>"u"||typeof e.end=="number")||e.type==="LEAF"&&typeof e.leaf_type=="string"&&["ARRAY_LEAF","TUPLE_LEAF","STATIC_LEAF","DYNAMIC_LEAF"].includes(e.leaf_type)||e.type==="SLICE"&&(typeof e.start>"u"||typeof e.start=="number")&&(typeof e.end>"u"||typeof e.end=="number"))}};u=h([R(),y(0,m(x.Config)),y(1,m(O.PkiCertificateLoader))],u);export{u as HttpCalldataDescriptorDataSource};
|
|
2
2
|
//# sourceMappingURL=HttpCalldataDescriptorDataSource.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/calldata/data/HttpCalldataDescriptorDataSource.ts"],
|
|
4
|
-
"sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport {\n type ContextModuleCalMode,\n type ContextModuleConfig,\n} from \"@/config/model/ContextModuleConfig\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { PkiCertificateInfo } from \"@/pki/model/PkiCertificateInfo\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport {\n ClearSignContextReference,\n ClearSignContextReferenceType,\n ClearSignContextSuccess,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { GenericPath } from \"@/shared/model/GenericPath\";\nimport { INFO_SIGNATURE_TAG } from \"@/shared/model/SignatureTags\";\nimport { HexStringUtils } from \"@/shared/utils/HexStringUtils\";\nimport PACKAGE from \"@root/package.json\";\n\nimport {\n CalldataDescriptor,\n CalldataDescriptorContainerPathV1,\n CalldataDescriptorParam,\n CalldataDescriptorPathElementsV1,\n CalldataDescriptorPathElementV1,\n CalldataDescriptorV1,\n CalldataDescriptorValueBinaryPathV1,\n CalldataDescriptorValueConstantV1,\n CalldataDescriptorValueV1,\n CalldataDto,\n CalldataEnumV1,\n CalldataFieldV1,\n CalldataSignatures,\n CalldataTransactionDescriptor,\n CalldataTransactionInfoV1,\n} from \"./dto/CalldataDto\";\nimport {\n CalldataDescriptorDataSource,\n GetCalldataDescriptorsParams,\n} from \"./CalldataDescriptorDataSource\";\n\n@injectable()\nexport class HttpCalldataDescriptorDataSource\n implements CalldataDescriptorDataSource\n{\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n private readonly endpoint: string,\n ) {}\n\n public async getCalldataDescriptors({\n chainId,\n address,\n selector,\n deviceModelId,\n }: GetCalldataDescriptorsParams): Promise<\n Either<Error, ClearSignContextSuccess[]>\n > {\n let dto: CalldataDto[] | undefined;\n try {\n const url =\n this.endpoint === \"dapps\"\n ? \"https://crypto-assets-service.api.ledger.com/v1\"\n : \"https://crypto-assets-service.api.ledger-test.com/v1\";\n const response = await axios.request<CalldataDto[]>({\n method: \"GET\",\n url: `${url}/${this.endpoint}`,\n params: {\n output: \"descriptors_calldata\",\n chain_id: chainId,\n contracts: address, // used for dapps\n contract_address: address, // used for tokens\n // TODO revert to branch\n ref: `commit:c9227c39e225932796e87ef4c9eb84f647e16150`,\n },\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n dto = response.data;\n } catch (error) {\n return Left(\n new Error(\n `[ContextModule] HttpCalldataDescriptorDataSource: Failed to fetch calldata descriptors: ${error}`,\n ),\n );\n }\n\n if (!Array.isArray(dto)) {\n return Left(\n new Error(\n `[ContextModule] HttpCalldataDescriptorDataSource: Response is not an array`,\n ),\n );\n }\n\n if (dto.length === 0) {\n return Left(\n new Error(\n `[ContextModule] HttpCalldataDescriptorDataSource: No data for contract ${address} and selector ${selector}`,\n ),\n );\n }\n\n for (const calldata of dto) {\n // Normalize the address and selector\n address = address.toLowerCase();\n selector = `0x${selector.slice(2).toLowerCase()}`;\n const calldataDescriptor =\n calldata.descriptors_calldata?.[address]?.[selector];\n\n if (\n !calldataDescriptor ||\n !this.isCalldataDescriptorV1(calldataDescriptor, this.config.cal.mode)\n ) {\n continue;\n }\n\n const infoData = calldataDescriptor.transaction_info.descriptor.data;\n const infoSignature =\n calldataDescriptor.transaction_info.descriptor.signatures[\n this.config.cal.mode\n ];\n\n const certificateInfos: PkiCertificateInfo = {\n targetDevice: deviceModelId,\n keyUsage: KeyUsage.Calldata,\n keyId: KeyId.CalCalldataKey,\n };\n const certificate: PkiCertificate | undefined =\n await this._certificateLoader.loadCertificate(certificateInfos);\n\n const info: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: HexStringUtils.appendSignatureToPayload(\n infoData,\n infoSignature,\n INFO_SIGNATURE_TAG,\n ),\n certificate,\n };\n\n const enums: ClearSignContextSuccess[] = [];\n for (const [id, values] of Object.entries(calldataDescriptor.enums)) {\n for (const [\n value,\n { data, signatures },\n ] of Object.entries<CalldataTransactionDescriptor>(values)) {\n enums.push({\n type: ClearSignContextType.ENUM,\n id: Number(id),\n value: Number(value),\n payload: HexStringUtils.appendSignatureToPayload(\n data,\n signatures[this.config.cal.mode]!,\n INFO_SIGNATURE_TAG,\n ),\n certificate,\n });\n }\n }\n\n const fields: ClearSignContextSuccess[] = calldataDescriptor.fields.map(\n (field) => ({\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: field.descriptor,\n reference: this.getReference(field.param),\n }),\n );\n return Right([info, ...enums, ...fields]);\n }\n\n return Left(\n new Error(\n `[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract ${address} and selector ${selector}`,\n ),\n );\n }\n\n private getReference(\n param: CalldataDescriptorParam,\n ): ClearSignContextReference | undefined {\n if (\n param.type === \"TOKEN_AMOUNT\" &&\n param.token !== undefined &&\n param.token.type === \"path\"\n ) {\n return {\n type: ClearSignContextReferenceType.TOKEN,\n valuePath: this.toGenericPath(param.token.binary_path),\n };\n } else if (\n param.type === \"TOKEN_AMOUNT\" &&\n param.token !== undefined &&\n param.token.type === \"constant\"\n ) {\n return {\n type: ClearSignContextReferenceType.TOKEN,\n value: param.token.value,\n };\n } else if (param.type === \"NFT\" && param.collection.type === \"path\") {\n return {\n type: ClearSignContextReferenceType.NFT,\n valuePath: this.toGenericPath(param.collection.binary_path),\n };\n } else if (param.type === \"NFT\" && param.collection.type === \"constant\") {\n return {\n type: ClearSignContextReferenceType.NFT,\n value: param.collection.value,\n };\n } else if (param.type === \"TRUSTED_NAME\" && param.value.type === \"path\") {\n return {\n type: ClearSignContextReferenceType.TRUSTED_NAME,\n valuePath: this.toGenericPath(param.value.binary_path),\n types: param.types,\n sources: param.sources,\n };\n } else if (param.type === \"ENUM\" && param.value.type === \"path\") {\n return {\n type: ClearSignContextReferenceType.ENUM,\n valuePath: this.toGenericPath(param.value.binary_path),\n id: param.id,\n };\n } else if (\n param.type === \"CALLDATA\" &&\n param.value.type === \"path\" &&\n param.callee.type === \"path\"\n ) {\n return {\n type: ClearSignContextReferenceType.CALLDATA,\n valuePath: this.toGenericPath(param.value.binary_path),\n callee: this.toGenericPath(param.callee.binary_path),\n selector:\n param.selector?.type === \"path\"\n ? this.toGenericPath(param.selector.binary_path)\n : undefined,\n amount:\n param.amount?.type === \"path\"\n ? this.toGenericPath(param.amount.binary_path)\n : undefined,\n spender:\n param.spender?.type === \"path\"\n ? this.toGenericPath(param.spender.binary_path)\n : undefined,\n chainId:\n param.chainId?.type === \"path\"\n ? this.toGenericPath(param.chainId.binary_path)\n : undefined,\n };\n }\n return undefined;\n }\n\n private toGenericPath(\n path: CalldataDescriptorContainerPathV1 | CalldataDescriptorPathElementsV1,\n ): GenericPath {\n if (path.type === \"CONTAINER\") {\n return path.value;\n }\n return path.elements.map((element) => {\n if (element.type === \"ARRAY\") {\n const { weight: itemSize, ...rest } = element;\n return {\n itemSize,\n ...rest,\n };\n } else if (element.type === \"LEAF\") {\n const { leaf_type: leafType, ...rest } = element;\n return {\n leafType,\n ...rest,\n };\n }\n return element;\n });\n }\n\n private isCalldataDescriptorV1(\n data: CalldataDescriptor,\n mode: ContextModuleCalMode,\n ): data is CalldataDescriptorV1 & {\n transaction_info: {\n descriptor: {\n signatures: { [_key in ContextModuleCalMode]: string };\n };\n };\n } {\n return (\n typeof data === \"object\" &&\n data.type === \"calldata\" &&\n data.version === \"v1\" &&\n this.isTransactionInfoV1(data.transaction_info, mode) &&\n this.isEnumV1(data.enums, mode) &&\n Array.isArray(data.fields) &&\n data.fields.every((f) => this.isFieldV1(f))\n );\n }\n\n private isTransactionInfoV1(\n data: CalldataTransactionInfoV1,\n mode: ContextModuleCalMode,\n ): data is CalldataTransactionInfoV1 & {\n descriptor: {\n signatures: { [_key in ContextModuleCalMode]: string };\n };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.descriptor === \"object\" &&\n typeof data.descriptor.data === \"string\" &&\n typeof data.descriptor.signatures === \"object\" &&\n typeof data.descriptor.signatures[mode] === \"string\"\n );\n }\n\n private isEnumV1(\n calldata: CalldataEnumV1,\n mode: ContextModuleCalMode,\n ): calldata is CalldataEnumV1 {\n return (\n typeof calldata === \"object\" &&\n Object.entries(calldata).every(\n ([id, values]) =>\n typeof id === \"string\" &&\n typeof values === \"object\" &&\n Object.entries<CalldataTransactionDescriptor>(values).every(\n ([value, obj]) =>\n typeof value === \"string\" &&\n typeof obj === \"object\" &&\n typeof obj.data === \"string\" &&\n obj.signatures !== undefined &&\n this.isCalldataSignatures(obj.signatures, mode),\n ),\n )\n );\n }\n\n private isCalldataSignatures(\n data: CalldataSignatures,\n mode: ContextModuleCalMode,\n ): data is CalldataSignatures & { [_key in ContextModuleCalMode]: string } {\n return typeof data === \"object\" && typeof data[mode] === \"string\";\n }\n\n private isFieldV1(data: CalldataFieldV1): boolean {\n return (\n typeof data === \"object\" &&\n typeof data.descriptor === \"string\" &&\n typeof data.param === \"object\" &&\n typeof data.param.value === \"object\" &&\n this.isDescriptorValueV1(data.param.value) &&\n (data.param.type === \"RAW\" ||\n data.param.type === \"AMOUNT\" ||\n data.param.type === \"DATETIME\" ||\n data.param.type === \"DURATION\" ||\n data.param.type === \"UNIT\" ||\n data.param.type === \"ENUM\" ||\n (data.param.type === \"NFT\" &&\n this.isDescriptorValueV1(data.param.collection)) ||\n (data.param.type === \"TOKEN_AMOUNT\" &&\n (data.param.token === undefined ||\n this.isDescriptorValueV1(data.param.token))) ||\n (data.param.type === \"TRUSTED_NAME\" &&\n Array.isArray(data.param.types) &&\n Array.isArray(data.param.sources) &&\n data.param.types.every((t) => typeof t === \"string\") &&\n data.param.sources.every((t) => typeof t === \"string\")) ||\n (data.param.type === \"CALLDATA\" &&\n this.isDescriptorValueV1(data.param.value) &&\n this.isDescriptorValueV1(data.param.callee) &&\n (data.param.selector === undefined ||\n this.isDescriptorValueV1(data.param.selector)) &&\n (data.param.amount === undefined ||\n this.isDescriptorValueV1(data.param.amount)) &&\n (data.param.spender === undefined ||\n this.isDescriptorValueV1(data.param.spender)) &&\n (data.param.chainId === undefined ||\n this.isDescriptorValueV1(data.param.chainId))))\n );\n }\n\n private isDescriptorValueV1(data: CalldataDescriptorValueV1): boolean {\n return (\n typeof data === \"object\" &&\n typeof data.type_family === \"string\" &&\n [\n \"UINT\",\n \"INT\",\n \"UFIXED\",\n \"FIXED\",\n \"ADDRESS\",\n \"BOOL\",\n \"BYTES\",\n \"STRING\",\n ].includes(data.type_family) &&\n (typeof data.type_size === \"undefined\" ||\n typeof data.type_size === \"number\") &&\n ((data.type === \"path\" &&\n this.isCalldataDescriptorValueBinaryPathV1(data)) ||\n (data.type === \"constant\" &&\n this.isCalldataDescriptorValueConstantV1(data)))\n );\n }\n\n private isCalldataDescriptorValueConstantV1(\n data: CalldataDescriptorValueConstantV1,\n ): boolean {\n return (\n typeof data === \"object\" &&\n data.type === \"constant\" &&\n typeof data.value === \"string\"\n );\n }\n\n private isCalldataDescriptorValueBinaryPathV1(\n data: CalldataDescriptorValueBinaryPathV1,\n ): boolean {\n return (\n typeof data === \"object\" &&\n ((data.type === \"path\" &&\n data.binary_path.type === \"CONTAINER\" &&\n [\"FROM\", \"TO\", \"VALUE\"].includes(data.binary_path.value)) ||\n (data.binary_path.type === \"DATA\" &&\n Array.isArray(data.binary_path.elements) &&\n data.binary_path.elements.every((e) => this.isPathElementV1(e))))\n );\n }\n\n private isPathElementV1(data: CalldataDescriptorPathElementV1): boolean {\n return (\n typeof data === \"object\" &&\n (data.type === \"REF\" ||\n (data.type === \"TUPLE\" && typeof data.offset === \"number\") ||\n (data.type === \"ARRAY\" &&\n typeof data.weight === \"number\" &&\n (typeof data.start === \"undefined\" ||\n typeof data.start === \"number\") &&\n (typeof data.end === \"undefined\" || typeof data.end === \"number\")) ||\n (data.type === \"LEAF\" &&\n typeof data.leaf_type === \"string\" &&\n [\"ARRAY_LEAF\", \"TUPLE_LEAF\", \"STATIC_LEAF\", \"DYNAMIC_LEAF\"].includes(\n data.leaf_type,\n )) ||\n (data.type === \"SLICE\" &&\n (typeof data.start === \"undefined\" ||\n typeof data.start === \"number\") &&\n (typeof data.end === \"undefined\" || typeof data.end === \"number\")))\n );\n }\n}\n"],
|
|
5
|
-
"mappings": "iOAAA,OAAOA,MAAW,QAClB,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YACnC,OAAiB,QAAAC,EAAM,SAAAC,MAAa,YAEpC,OAAS,eAAAC,MAAmB,0BAK5B,OAAS,YAAAC,MAAgB,oBAEzB,OAAS,SAAAC,MAAa,oBACtB,OAAS,YAAAC,MAAgB,uBAGzB,OACE,gCAAAC,EACA,8BAAAC,MACK,gCACP,OAEE,iCAAAC,EAEA,wBAAAC,MACK,kCAEP,OAAS,sBAAAC,MAA0B,+BACnC,OAAS,kBAAAC,MAAsB,gCAC/B,OAAOC,MAAa,qBAyBb,IAAMC,EAAN,KAEP,CACE,YAC+CC,EAE5BC,EACAC,EACjB,CAJ6C,YAAAF,EAE5B,wBAAAC,EACA,cAAAC,CAChB,CAEH,MAAa,uBAAuB,CAClC,QAAAC,EACA,QAAAC,EACA,SAAAC,EACA,cAAAC,CACF,EAEE,CACA,IAAIC,EACJ,GAAI,
|
|
6
|
-
"names": ["axios", "inject", "injectable", "Left", "Right", "configTypes", "pkiTypes", "KeyId", "KeyUsage", "LEDGER_CLIENT_VERSION_HEADER", "LEDGER_ORIGIN_TOKEN_HEADER", "ClearSignContextReferenceType", "ClearSignContextType", "INFO_SIGNATURE_TAG", "HexStringUtils", "PACKAGE", "HttpCalldataDescriptorDataSource", "config", "_certificateLoader", "endpoint", "chainId", "address", "selector", "deviceModelId", "dto", "
|
|
4
|
+
"sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport {\n type ContextModuleCalMode,\n type ContextModuleConfig,\n} from \"@/config/model/ContextModuleConfig\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { PkiCertificateInfo } from \"@/pki/model/PkiCertificateInfo\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport {\n ClearSignContextReference,\n ClearSignContextReferenceType,\n ClearSignContextSuccess,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { GenericPath } from \"@/shared/model/GenericPath\";\nimport { INFO_SIGNATURE_TAG } from \"@/shared/model/SignatureTags\";\nimport { HexStringUtils } from \"@/shared/utils/HexStringUtils\";\nimport PACKAGE from \"@root/package.json\";\n\nimport {\n CalldataDescriptor,\n CalldataDescriptorContainerPathV1,\n CalldataDescriptorParam,\n CalldataDescriptorPathElementsV1,\n CalldataDescriptorPathElementV1,\n CalldataDescriptorV1,\n CalldataDescriptorValueBinaryPathV1,\n CalldataDescriptorValueConstantV1,\n CalldataDescriptorValueV1,\n CalldataDto,\n CalldataEnumV1,\n CalldataFieldV1,\n CalldataSignatures,\n CalldataTransactionDescriptor,\n CalldataTransactionInfoV1,\n} from \"./dto/CalldataDto\";\nimport {\n CalldataDescriptorDataSource,\n GetCalldataDescriptorsParams,\n} from \"./CalldataDescriptorDataSource\";\n\n@injectable()\nexport class HttpCalldataDescriptorDataSource\n implements CalldataDescriptorDataSource\n{\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n private readonly endpoint: string,\n ) {}\n\n public async getCalldataDescriptors({\n chainId,\n address,\n selector,\n deviceModelId,\n }: GetCalldataDescriptorsParams): Promise<\n Either<Error, ClearSignContextSuccess[]>\n > {\n let dto: CalldataDto[] | undefined;\n try {\n const response = await axios.request<CalldataDto[]>({\n method: \"GET\",\n url: `${this.config.cal.url}/${this.endpoint}`,\n params: {\n output: \"descriptors_calldata\",\n chain_id: chainId,\n contracts: address, // used for dapps\n contract_address: address, // used for tokens\n ref: `branch:${this.config.cal.branch}`,\n },\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n dto = response.data;\n } catch (error) {\n return Left(\n new Error(\n `[ContextModule] HttpCalldataDescriptorDataSource: Failed to fetch calldata descriptors: ${error}`,\n ),\n );\n }\n\n if (!Array.isArray(dto)) {\n return Left(\n new Error(\n `[ContextModule] HttpCalldataDescriptorDataSource: Response is not an array`,\n ),\n );\n }\n\n if (dto.length === 0) {\n return Left(\n new Error(\n `[ContextModule] HttpCalldataDescriptorDataSource: No data for contract ${address} and selector ${selector}`,\n ),\n );\n }\n\n for (const calldata of dto) {\n // Normalize the address and selector\n address = address.toLowerCase();\n selector = `0x${selector.slice(2).toLowerCase()}`;\n const calldataDescriptor =\n calldata.descriptors_calldata?.[address]?.[selector];\n\n if (\n !calldataDescriptor ||\n !this.isCalldataDescriptorV1(calldataDescriptor, this.config.cal.mode)\n ) {\n continue;\n }\n\n const infoData = calldataDescriptor.transaction_info.descriptor.data;\n const infoSignature =\n calldataDescriptor.transaction_info.descriptor.signatures[\n this.config.cal.mode\n ];\n\n const certificateInfos: PkiCertificateInfo = {\n targetDevice: deviceModelId,\n keyUsage: KeyUsage.Calldata,\n keyId: KeyId.CalCalldataKey,\n };\n const certificate: PkiCertificate | undefined =\n await this._certificateLoader.loadCertificate(certificateInfos);\n\n const info: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: HexStringUtils.appendSignatureToPayload(\n infoData,\n infoSignature,\n INFO_SIGNATURE_TAG,\n ),\n certificate,\n };\n\n const enums: ClearSignContextSuccess[] = [];\n for (const [id, values] of Object.entries(calldataDescriptor.enums)) {\n for (const [\n value,\n { data, signatures },\n ] of Object.entries<CalldataTransactionDescriptor>(values)) {\n enums.push({\n type: ClearSignContextType.ENUM,\n id: Number(id),\n value: Number(value),\n payload: HexStringUtils.appendSignatureToPayload(\n data,\n signatures[this.config.cal.mode]!,\n INFO_SIGNATURE_TAG,\n ),\n certificate,\n });\n }\n }\n\n const fields: ClearSignContextSuccess[] = calldataDescriptor.fields.map(\n (field) => ({\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: field.descriptor,\n reference: this.getReference(field.param),\n }),\n );\n return Right([info, ...enums, ...fields]);\n }\n\n return Left(\n new Error(\n `[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract ${address} and selector ${selector}`,\n ),\n );\n }\n\n private getReference(\n param: CalldataDescriptorParam,\n ): ClearSignContextReference | undefined {\n if (\n param.type === \"TOKEN_AMOUNT\" &&\n param.token !== undefined &&\n param.token.type === \"path\"\n ) {\n return {\n type: ClearSignContextReferenceType.TOKEN,\n valuePath: this.toGenericPath(param.token.binary_path),\n };\n } else if (\n param.type === \"TOKEN_AMOUNT\" &&\n param.token !== undefined &&\n param.token.type === \"constant\"\n ) {\n return {\n type: ClearSignContextReferenceType.TOKEN,\n value: param.token.value,\n };\n } else if (param.type === \"NFT\" && param.collection.type === \"path\") {\n return {\n type: ClearSignContextReferenceType.NFT,\n valuePath: this.toGenericPath(param.collection.binary_path),\n };\n } else if (param.type === \"NFT\" && param.collection.type === \"constant\") {\n return {\n type: ClearSignContextReferenceType.NFT,\n value: param.collection.value,\n };\n } else if (param.type === \"TRUSTED_NAME\" && param.value.type === \"path\") {\n return {\n type: ClearSignContextReferenceType.TRUSTED_NAME,\n valuePath: this.toGenericPath(param.value.binary_path),\n types: param.types,\n sources: param.sources,\n };\n } else if (param.type === \"ENUM\" && param.value.type === \"path\") {\n return {\n type: ClearSignContextReferenceType.ENUM,\n valuePath: this.toGenericPath(param.value.binary_path),\n id: param.id,\n };\n } else if (\n param.type === \"CALLDATA\" &&\n param.value.type === \"path\" &&\n param.callee.type === \"path\"\n ) {\n return {\n type: ClearSignContextReferenceType.CALLDATA,\n valuePath: this.toGenericPath(param.value.binary_path),\n callee: this.toGenericPath(param.callee.binary_path),\n selector:\n param.selector?.type === \"path\"\n ? this.toGenericPath(param.selector.binary_path)\n : undefined,\n amount:\n param.amount?.type === \"path\"\n ? this.toGenericPath(param.amount.binary_path)\n : undefined,\n spender:\n param.spender?.type === \"path\"\n ? this.toGenericPath(param.spender.binary_path)\n : undefined,\n chainId:\n param.chainId?.type === \"path\"\n ? this.toGenericPath(param.chainId.binary_path)\n : undefined,\n };\n }\n return undefined;\n }\n\n private toGenericPath(\n path: CalldataDescriptorContainerPathV1 | CalldataDescriptorPathElementsV1,\n ): GenericPath {\n if (path.type === \"CONTAINER\") {\n return path.value;\n }\n return path.elements.map((element) => {\n if (element.type === \"ARRAY\") {\n const { weight: itemSize, ...rest } = element;\n return {\n itemSize,\n ...rest,\n };\n } else if (element.type === \"LEAF\") {\n const { leaf_type: leafType, ...rest } = element;\n return {\n leafType,\n ...rest,\n };\n }\n return element;\n });\n }\n\n private isCalldataDescriptorV1(\n data: CalldataDescriptor,\n mode: ContextModuleCalMode,\n ): data is CalldataDescriptorV1 & {\n transaction_info: {\n descriptor: {\n signatures: { [_key in ContextModuleCalMode]: string };\n };\n };\n } {\n return (\n typeof data === \"object\" &&\n data.type === \"calldata\" &&\n data.version === \"v1\" &&\n this.isTransactionInfoV1(data.transaction_info, mode) &&\n this.isEnumV1(data.enums, mode) &&\n Array.isArray(data.fields) &&\n data.fields.every((f) => this.isFieldV1(f))\n );\n }\n\n private isTransactionInfoV1(\n data: CalldataTransactionInfoV1,\n mode: ContextModuleCalMode,\n ): data is CalldataTransactionInfoV1 & {\n descriptor: {\n signatures: { [_key in ContextModuleCalMode]: string };\n };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.descriptor === \"object\" &&\n typeof data.descriptor.data === \"string\" &&\n typeof data.descriptor.signatures === \"object\" &&\n typeof data.descriptor.signatures[mode] === \"string\"\n );\n }\n\n private isEnumV1(\n calldata: CalldataEnumV1,\n mode: ContextModuleCalMode,\n ): calldata is CalldataEnumV1 {\n return (\n typeof calldata === \"object\" &&\n Object.entries(calldata).every(\n ([id, values]) =>\n typeof id === \"string\" &&\n typeof values === \"object\" &&\n Object.entries<CalldataTransactionDescriptor>(values).every(\n ([value, obj]) =>\n typeof value === \"string\" &&\n typeof obj === \"object\" &&\n typeof obj.data === \"string\" &&\n obj.signatures !== undefined &&\n this.isCalldataSignatures(obj.signatures, mode),\n ),\n )\n );\n }\n\n private isCalldataSignatures(\n data: CalldataSignatures,\n mode: ContextModuleCalMode,\n ): data is CalldataSignatures & { [_key in ContextModuleCalMode]: string } {\n return typeof data === \"object\" && typeof data[mode] === \"string\";\n }\n\n private isFieldV1(data: CalldataFieldV1): boolean {\n return (\n typeof data === \"object\" &&\n typeof data.descriptor === \"string\" &&\n typeof data.param === \"object\" &&\n typeof data.param.value === \"object\" &&\n this.isDescriptorValueV1(data.param.value) &&\n (data.param.type === \"RAW\" ||\n data.param.type === \"AMOUNT\" ||\n data.param.type === \"DATETIME\" ||\n data.param.type === \"DURATION\" ||\n data.param.type === \"UNIT\" ||\n data.param.type === \"ENUM\" ||\n (data.param.type === \"NFT\" &&\n this.isDescriptorValueV1(data.param.collection)) ||\n (data.param.type === \"TOKEN_AMOUNT\" &&\n (data.param.token === undefined ||\n this.isDescriptorValueV1(data.param.token))) ||\n (data.param.type === \"TRUSTED_NAME\" &&\n Array.isArray(data.param.types) &&\n Array.isArray(data.param.sources) &&\n data.param.types.every((t) => typeof t === \"string\") &&\n data.param.sources.every((t) => typeof t === \"string\")) ||\n (data.param.type === \"CALLDATA\" &&\n this.isDescriptorValueV1(data.param.value) &&\n this.isDescriptorValueV1(data.param.callee) &&\n (data.param.selector === undefined ||\n this.isDescriptorValueV1(data.param.selector)) &&\n (data.param.amount === undefined ||\n this.isDescriptorValueV1(data.param.amount)) &&\n (data.param.spender === undefined ||\n this.isDescriptorValueV1(data.param.spender)) &&\n (data.param.chainId === undefined ||\n this.isDescriptorValueV1(data.param.chainId))))\n );\n }\n\n private isDescriptorValueV1(data: CalldataDescriptorValueV1): boolean {\n return (\n typeof data === \"object\" &&\n typeof data.type_family === \"string\" &&\n [\n \"UINT\",\n \"INT\",\n \"UFIXED\",\n \"FIXED\",\n \"ADDRESS\",\n \"BOOL\",\n \"BYTES\",\n \"STRING\",\n ].includes(data.type_family) &&\n (typeof data.type_size === \"undefined\" ||\n typeof data.type_size === \"number\") &&\n ((data.type === \"path\" &&\n this.isCalldataDescriptorValueBinaryPathV1(data)) ||\n (data.type === \"constant\" &&\n this.isCalldataDescriptorValueConstantV1(data)))\n );\n }\n\n private isCalldataDescriptorValueConstantV1(\n data: CalldataDescriptorValueConstantV1,\n ): boolean {\n return (\n typeof data === \"object\" &&\n data.type === \"constant\" &&\n typeof data.value === \"string\"\n );\n }\n\n private isCalldataDescriptorValueBinaryPathV1(\n data: CalldataDescriptorValueBinaryPathV1,\n ): boolean {\n return (\n typeof data === \"object\" &&\n ((data.type === \"path\" &&\n data.binary_path.type === \"CONTAINER\" &&\n [\"FROM\", \"TO\", \"VALUE\"].includes(data.binary_path.value)) ||\n (data.binary_path.type === \"DATA\" &&\n Array.isArray(data.binary_path.elements) &&\n data.binary_path.elements.every((e) => this.isPathElementV1(e))))\n );\n }\n\n private isPathElementV1(data: CalldataDescriptorPathElementV1): boolean {\n return (\n typeof data === \"object\" &&\n (data.type === \"REF\" ||\n (data.type === \"TUPLE\" && typeof data.offset === \"number\") ||\n (data.type === \"ARRAY\" &&\n typeof data.weight === \"number\" &&\n (typeof data.start === \"undefined\" ||\n typeof data.start === \"number\") &&\n (typeof data.end === \"undefined\" || typeof data.end === \"number\")) ||\n (data.type === \"LEAF\" &&\n typeof data.leaf_type === \"string\" &&\n [\"ARRAY_LEAF\", \"TUPLE_LEAF\", \"STATIC_LEAF\", \"DYNAMIC_LEAF\"].includes(\n data.leaf_type,\n )) ||\n (data.type === \"SLICE\" &&\n (typeof data.start === \"undefined\" ||\n typeof data.start === \"number\") &&\n (typeof data.end === \"undefined\" || typeof data.end === \"number\")))\n );\n }\n}\n"],
|
|
5
|
+
"mappings": "iOAAA,OAAOA,MAAW,QAClB,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YACnC,OAAiB,QAAAC,EAAM,SAAAC,MAAa,YAEpC,OAAS,eAAAC,MAAmB,0BAK5B,OAAS,YAAAC,MAAgB,oBAEzB,OAAS,SAAAC,MAAa,oBACtB,OAAS,YAAAC,MAAgB,uBAGzB,OACE,gCAAAC,EACA,8BAAAC,MACK,gCACP,OAEE,iCAAAC,EAEA,wBAAAC,MACK,kCAEP,OAAS,sBAAAC,MAA0B,+BACnC,OAAS,kBAAAC,MAAsB,gCAC/B,OAAOC,MAAa,qBAyBb,IAAMC,EAAN,KAEP,CACE,YAC+CC,EAE5BC,EACAC,EACjB,CAJ6C,YAAAF,EAE5B,wBAAAC,EACA,cAAAC,CAChB,CAEH,MAAa,uBAAuB,CAClC,QAAAC,EACA,QAAAC,EACA,SAAAC,EACA,cAAAC,CACF,EAEE,CACA,IAAIC,EACJ,GAAI,CAgBFA,GAfiB,MAAMC,EAAM,QAAuB,CAClD,OAAQ,MACR,IAAK,GAAG,KAAK,OAAO,IAAI,GAAG,IAAI,KAAK,QAAQ,GAC5C,OAAQ,CACN,OAAQ,uBACR,SAAUL,EACV,UAAWC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AOA,EAAK,QAAW,UAChDA,EAAK,OAAS,SACb,OAAOA,EAAK,QAAW,WACtB,OAAOA,EAAK,MAAU,KACrB,OAAOA,EAAK,OAAU,YACvB,OAAOA,EAAK,IAAQ,KAAe,OAAOA,EAAK,KAAQ,WACzDA,EAAK,OAAS,QACb,OAAOA,EAAK,WAAc,UAC1B,CAAC,aAAc,aAAc,cAAe,cAAc,EAAE,SAC1DA,EAAK,SACP,GACDA,EAAK,OAAS,UACZ,OAAOA,EAAK,MAAU,KACrB,OAAOA,EAAK,OAAU,YACvB,OAAOA,EAAK,IAAQ,KAAe,OAAOA,EAAK,KAAQ,UAEhE,CACF,EArZa/B,EAAN+C,EAAA,CADNC,EAAW,EAKPC,EAAA,EAAAC,EAAOC,EAAY,MAAM,GACzBF,EAAA,EAAAC,EAAOE,EAAS,oBAAoB,IAL5BpD",
|
|
6
|
+
"names": ["axios", "inject", "injectable", "Left", "Right", "configTypes", "pkiTypes", "KeyId", "KeyUsage", "LEDGER_CLIENT_VERSION_HEADER", "LEDGER_ORIGIN_TOKEN_HEADER", "ClearSignContextReferenceType", "ClearSignContextType", "INFO_SIGNATURE_TAG", "HexStringUtils", "PACKAGE", "HttpCalldataDescriptorDataSource", "config", "_certificateLoader", "endpoint", "chainId", "address", "selector", "deviceModelId", "dto", "axios", "LEDGER_CLIENT_VERSION_HEADER", "PACKAGE", "LEDGER_ORIGIN_TOKEN_HEADER", "error", "Left", "calldata", "calldataDescriptor", "infoData", "infoSignature", "certificateInfos", "KeyUsage", "KeyId", "certificate", "info", "ClearSignContextType", "HexStringUtils", "INFO_SIGNATURE_TAG", "enums", "id", "values", "value", "data", "signatures", "fields", "field", "Right", "param", "ClearSignContextReferenceType", "path", "element", "itemSize", "rest", "leafType", "mode", "f", "obj", "e", "__decorateClass", "injectable", "__decorateParam", "inject", "configTypes", "pkiTypes"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var g=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var S=(d,e,t,a)=>{for(var r=a>1?void 0:a?I(e,t):e,o=d.length-1,n;o>=0;o--)(n=d[o])&&(r=(a?n(e,t,r):n(r))||r);return a&&r&&g(e,t,r),r},i=(d,e)=>(t,a)=>e(t,a,d);import{DeviceModelId as P,isHexaString as C}from"@ledgerhq/device-management-kit";import{inject as y,injectable as M}from"inversify";import{MaybeAsync as D}from"purify-ts";import{calldataTypes as m}from"../../calldata/di/calldataTypes";import{proxyTypes as h}from"../../proxy/di/proxyTypes";import{ClearSignContextType as c}from"../../shared/model/ClearSignContext";const f=[c.TRANSACTION_INFO,c.TRANSACTION_FIELD_DESCRIPTION,c.PROXY_INFO,c.ENUM];let p=class{constructor(e,t,a){this.dappDataSource=e;this.tokenDataSource=t;this.proxyDataSource=a}canHandle(e,t){return typeof e=="object"&&e!==null&&"to"in e&&"data"in e&&"selector"in e&&"chainId"in e&&"deviceModelId"in e&&e.deviceModelId!==void 0&&e.deviceModelId!==P.NANO_S&&typeof e.chainId=="number"&&C(e.to)&&e.to!=="0x"&&C(e.data)&&C(e.selector)&&e.selector!=="0x"&&f.every(a=>t.includes(a))}async load(e){const{to:t,data:a,selector:r,chainId:o,deviceModelId:n}=e,s={address:t,chainId:o,selector:r,deviceModelId:n,data:a};return this._getContexts(s,this.dappDataSource).alt(this._getContexts(s,this.tokenDataSource)).alt(this._getContextsWithProxy(s,this.dappDataSource)).orDefault([{type:c.ERROR,error:new Error("[ContextModule] CalldataContextLoader: No calldata contexts found")}])}_getContexts({address:e,chainId:t,selector:a,deviceModelId:r},o){return D(async({liftMaybe:n})=>{const s=await o.getCalldataDescriptors({deviceModelId:r,address:e,chainId:t,selector:a});return n(s.toMaybe().filter(l=>l.length>0))})}_getContextsWithProxy({address:e,chainId:t,selector:a,deviceModelId:r,data:o},n){return D(async({liftMaybe:l})=>{const x=await this.proxyDataSource.getProxyImplementationAddress({calldata:o,proxyAddress:e,chainId:t,challenge:""});return l(x.toMaybe())}).map(({implementationAddress:l})=>{const x={address:l,chainId:t,selector:a,deviceModelId:r,data:o};return this._getContexts(x,n).map(u=>[{type:c.PROXY_INFO,payload:"0x"},...u])}).join()}};p=S([M(),i(0,y(m.DappCalldataDescriptorDataSource)),i(1,y(m.TokenCalldataDescriptorDataSource)),i(2,y(h.ProxyDataSource))],p);export{p as CalldataContextLoader};
|
|
2
2
|
//# sourceMappingURL=CalldataContextLoader.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/calldata/domain/CalldataContextLoader.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n DeviceModelId,\n HexaString,\n isHexaString,\n} from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\nimport { MaybeAsync } from \"purify-ts\";\n\nimport type { CalldataDescriptorDataSource } from \"@/calldata/data/CalldataDescriptorDataSource\";\nimport { calldataTypes } from \"@/calldata/di/calldataTypes\";\nimport type { ProxyDataSource } from \"@/proxy/data/ProxyDataSource\";\nimport { proxyTypes } from \"@/proxy/di/proxyTypes\";\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\
|
|
5
|
-
"mappings": "iOAAA,OACE,iBAAAA,EAEA,gBAAAC,MACK,kCACP,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YACnC,OAAS,cAAAC,MAAkB,YAG3B,OAAS,iBAAAC,MAAqB,8BAE9B,OAAS,cAAAC,MAAkB,wBAE3B,OAEE,wBAAAC,MACK,
|
|
6
|
-
"names": ["DeviceModelId", "isHexaString", "inject", "injectable", "MaybeAsync", "calldataTypes", "proxyTypes", "ClearSignContextType", "CalldataContextLoader", "dappDataSource", "tokenDataSource", "proxyDataSource", "
|
|
4
|
+
"sourcesContent": ["import {\n DeviceModelId,\n HexaString,\n isHexaString,\n} from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\nimport { MaybeAsync } from \"purify-ts\";\n\nimport type { CalldataDescriptorDataSource } from \"@/calldata/data/CalldataDescriptorDataSource\";\nimport { calldataTypes } from \"@/calldata/di/calldataTypes\";\nimport type { ProxyDataSource } from \"@/proxy/data/ProxyDataSource\";\nimport { proxyTypes } from \"@/proxy/di/proxyTypes\";\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\n\nexport type CalldataContextInput = {\n to: HexaString;\n data: HexaString;\n selector: HexaString;\n chainId: number;\n deviceModelId: DeviceModelId;\n};\n\ntype GetContextsParams = {\n address: string;\n chainId: number;\n data: string;\n selector: HexaString;\n deviceModelId: DeviceModelId;\n};\n\nconst SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.TRANSACTION_INFO,\n ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n ClearSignContextType.PROXY_INFO,\n ClearSignContextType.ENUM,\n];\n\n@injectable()\nexport class CalldataContextLoader\n implements ContextLoader<CalldataContextInput>\n{\n constructor(\n @inject(calldataTypes.DappCalldataDescriptorDataSource)\n private dappDataSource: CalldataDescriptorDataSource,\n @inject(calldataTypes.TokenCalldataDescriptorDataSource)\n private tokenDataSource: CalldataDescriptorDataSource,\n @inject(proxyTypes.ProxyDataSource)\n private proxyDataSource: ProxyDataSource,\n ) {}\n\n canHandle(\n input: unknown,\n expectedTypes: ClearSignContextType[],\n ): input is CalldataContextInput {\n return (\n typeof input === \"object\" &&\n input !== null &&\n \"to\" in input &&\n \"data\" in input &&\n \"selector\" in input &&\n \"chainId\" in input &&\n \"deviceModelId\" in input &&\n input.deviceModelId !== undefined &&\n input.deviceModelId !== DeviceModelId.NANO_S &&\n typeof input.chainId === \"number\" &&\n isHexaString(input.to) &&\n input.to !== \"0x\" &&\n isHexaString(input.data) &&\n isHexaString(input.selector) &&\n input.selector !== \"0x\" &&\n SUPPORTED_TYPES.every((type) => expectedTypes.includes(type))\n );\n }\n\n async load(input: CalldataContextInput): Promise<ClearSignContext[]> {\n const { to, data, selector, chainId, deviceModelId } = input;\n\n const param: GetContextsParams = {\n address: to,\n chainId,\n selector,\n deviceModelId,\n data,\n };\n\n return this._getContexts(param, this.dappDataSource)\n .alt(this._getContexts(param, this.tokenDataSource))\n .alt(this._getContextsWithProxy(param, this.dappDataSource))\n .orDefault([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\n \"[ContextModule] CalldataContextLoader: No calldata contexts found\",\n ),\n },\n ]);\n }\n\n private _getContexts(\n { address, chainId, selector, deviceModelId }: GetContextsParams,\n datasource: CalldataDescriptorDataSource,\n ): MaybeAsync<ClearSignContext[]> {\n return MaybeAsync(async ({ liftMaybe }) => {\n const result = await datasource.getCalldataDescriptors({\n deviceModelId,\n address,\n chainId,\n selector,\n });\n\n return liftMaybe(result.toMaybe().filter((ctxs) => ctxs.length > 0));\n });\n }\n\n private _getContextsWithProxy(\n { address, chainId, selector, deviceModelId, data }: GetContextsParams,\n datasource: CalldataDescriptorDataSource,\n ): MaybeAsync<ClearSignContext[]> {\n const proxyAddress = MaybeAsync(async ({ liftMaybe }) => {\n const result = await this.proxyDataSource.getProxyImplementationAddress({\n calldata: data,\n proxyAddress: address,\n chainId,\n challenge: \"\",\n });\n return liftMaybe(result.toMaybe());\n });\n\n return proxyAddress\n .map<MaybeAsync<ClearSignContext[]>>(({ implementationAddress }) => {\n const params = {\n address: implementationAddress,\n chainId,\n selector,\n deviceModelId,\n data,\n };\n return this._getContexts(params, datasource).map((contexts) => [\n // Add a proxy info context to the list of contexts\n // to specify that the proxy info should be refetched during the provide step\n {\n type: ClearSignContextType.PROXY_INFO,\n payload: \"0x\",\n },\n ...contexts,\n ]);\n })\n .join(); // join the two MaybeAsyncs\n }\n}\n"],
|
|
5
|
+
"mappings": "iOAAA,OACE,iBAAAA,EAEA,gBAAAC,MACK,kCACP,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YAC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AE,UAAAC,CAAU,IAAM,CACzC,MAAMC,EAAS,MAAMH,EAAW,uBAAuB,CACrD,cAAAH,EACA,QAAAE,EACA,QAAAH,EACA,SAAAD,CACF,CAAC,EAED,OAAOO,EAAUC,EAAO,QAAQ,EAAE,OAAQC,GAASA,EAAK,OAAS,CAAC,CAAC,CACrE,CAAC,CACH,CAEQ,sBACN,CAAE,QAAAL,EAAS,QAAAH,EAAS,SAAAD,EAAU,cAAAE,EAAe,KAAAH,CAAK,EAClDM,EACgC,CAWhC,OAVqBC,EAAW,MAAO,CAAE,UAAAC,CAAU,IAAM,CACvD,MAAMC,EAAS,MAAM,KAAK,gBAAgB,8BAA8B,CACtE,SAAUT,EACV,aAAcK,EACd,QAAAH,EACA,UAAW,EACb,CAAC,EACD,OAAOM,EAAUC,EAAO,QAAQ,CAAC,CACnC,CAAC,EAGE,IAAoC,CAAC,CAAE,sBAAAE,CAAsB,IAAM,CAClE,MAAMC,EAAS,CACb,QAASD,EACT,QAAAT,EACA,SAAAD,EACA,cAAAE,EACA,KAAAH,CACF,EACA,OAAO,KAAK,aAAaY,EAAQN,CAAU,EAAE,IAAKO,GAAa,CAG7D,CACE,KAAMxB,EAAqB,WAC3B,QAAS,IACX,EACA,GAAGwB,CACL,CAAC,CACH,CAAC,EACA,KAAK,CACV,CACF,EA/GavB,EAANwB,EAAA,CADNC,EAAW,EAKPC,EAAA,EAAAC,EAAOC,EAAc,gCAAgC,GAErDF,EAAA,EAAAC,EAAOC,EAAc,iCAAiC,GAEtDF,EAAA,EAAAC,EAAOE,EAAW,eAAe,IARzB7B",
|
|
6
|
+
"names": ["DeviceModelId", "isHexaString", "inject", "injectable", "MaybeAsync", "calldataTypes", "proxyTypes", "ClearSignContextType", "SUPPORTED_TYPES", "ClearSignContextType", "CalldataContextLoader", "dappDataSource", "tokenDataSource", "proxyDataSource", "input", "expectedTypes", "DeviceModelId", "isHexaString", "type", "to", "data", "selector", "chainId", "deviceModelId", "param", "address", "datasource", "MaybeAsync", "liftMaybe", "result", "ctxs", "implementationAddress", "params", "contexts", "__decorateClass", "injectable", "__decorateParam", "inject", "calldataTypes", "proxyTypes"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{DeviceModelId as
|
|
1
|
+
import{DeviceModelId as l}from"@ledgerhq/device-management-kit";import{Left as s,Right as n}from"purify-ts";import{CalldataContextLoader as f}from"../../calldata/domain/CalldataContextLoader";import{ClearSignContextType as a}from"../../shared/model/ClearSignContext";describe("CalldataContextLoader",()=>{const r=vi.fn(),d=vi.fn(),p=vi.fn(),u={getCalldataDescriptors:d},x={getCalldataDescriptors:p},I={getProxyImplementationAddress:r},o=new f(u,x,I),c=[a.TRANSACTION_INFO,a.TRANSACTION_FIELD_DESCRIPTION,a.PROXY_INFO,a.ENUM];beforeEach(()=>{vi.resetAllMocks()}),describe("canHandle function",()=>{const e={to:"0x1234567890123456789012345678901234567890",data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302",chainId:1,deviceModelId:l.NANO_X};it("should return true for valid input",()=>{expect(o.canHandle(e,c)).toBe(!0)}),it("should return false for invalid expected type",()=>{expect(o.canHandle(e,[a.TOKEN])).toBe(!1),expect(o.canHandle(e,[a.NFT])).toBe(!1),expect(o.canHandle(e,[a.PROXY_INFO])).toBe(!1),expect(o.canHandle(e,[a.ENUM])).toBe(!1),expect(o.canHandle(e,[a.TRANSACTION_INFO])).toBe(!1)}),it.each([[null,"null input"],[void 0,"undefined input"],[{},"empty object"],["string","string input"],[123,"number input"]])("should return false for %s",(t,i)=>{expect(o.canHandle(t,c)).toBe(!1)}),it.each([[{...e,to:void 0},"missing to"],[{...e,data:void 0},"missing data"],[{...e,selector:void 0},"missing selector"],[{...e,chainId:void 0},"missing chainId"],[{...e,deviceModelId:void 0},"missing deviceModelId"]])("should return false for %s",(t,i)=>{expect(o.canHandle(t,c)).toBe(!1)}),it.each([[{...e,to:"invalid-hex"},"invalid to hex"],[{...e,to:"0x"},"empty to hex"],[{...e,data:"invalid-hex"},"invalid data hex"],[{...e,selector:"invalid-hex"},"invalid selector hex"],[{...e,selector:"0x"},"empty selector hex"]])("should return false for %s",(t,i)=>{expect(o.canHandle(t,c)).toBe(!1)}),it.each([[{...e,chainId:"1"},"string chainId"],[{...e,chainId:null},"null chainId"],[{...e,deviceModelId:l.NANO_S},"deviceModelId is NANO_S"]])("should return false for %s",(t,i)=>{expect(o.canHandle(t,c)).toBe(!1)})}),it("should return an error if data source fails",async()=>{r.mockResolvedValue(s(new Error("data source error"))),d.mockResolvedValue(s(new Error("data source error")));const e={to:"0x1234567890123456789012345678901234567890",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302",deviceModelId:l.NANO_X},t=await o.load(e);expect(d).toHaveBeenCalledWith({address:"0x1234567890123456789012345678901234567890",chainId:3,selector:"0xaf68b302",deviceModelId:l.NANO_X}),expect(t).toEqual([{type:a.ERROR,error:new Error("[ContextModule] CalldataContextLoader: No calldata contexts found")}])}),it("should return the contexts on success",async()=>{d.mockResolvedValue(n([{type:a.TRANSACTION_INFO,payload:"1234567890"},{type:a.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),r.mockResolvedValue(s(new Error("data source error")));const e={to:"0x1234567890123456789012345678901234567890",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302",deviceModelId:l.NANO_X},t=await o.load(e);expect(t).toEqual([{type:a.TRANSACTION_INFO,payload:"1234567890"},{type:a.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])}),it("should return the proxy delegate call context on success",async()=>{d.mockResolvedValueOnce(n([])),d.mockResolvedValue(n([{type:a.TRANSACTION_INFO,payload:"1234567890"},{type:a.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),r.mockResolvedValue(n({implementationAddress:"0x1234567890abcdef",signedDescriptor:"0x1234567890abcdef"}));const e={to:"0x1234567890123456789012345678901234567890",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302",deviceModelId:l.NANO_X},t=await o.load(e);expect(t).toEqual([{type:a.PROXY_INFO,payload:"0x"},{type:a.TRANSACTION_INFO,payload:"1234567890"},{type:a.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])}),it("should return an error when proxy delegate call succeeds but transaction descriptors for resolved address fail",async()=>{d.mockResolvedValueOnce(n([])),d.mockResolvedValueOnce(s(new Error("data source error"))),r.mockResolvedValue(n({implementationAddress:"0xResolvedAddress",signedDescriptor:"0x1234567890abcdef"}));const e={to:"0x1234567890123456789012345678901234567890",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302",deviceModelId:l.NANO_X},t=await o.load(e);expect(d).toHaveBeenCalledTimes(2),expect(d).toHaveBeenNthCalledWith(2,{address:"0xResolvedAddress",chainId:3,selector:"0xaf68b302",deviceModelId:l.NANO_X}),expect(t).toEqual([{type:a.ERROR,error:new Error("[ContextModule] CalldataContextLoader: No calldata contexts found")}])})});
|
|
2
2
|
//# sourceMappingURL=CalldataContextLoader.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/calldata/domain/CalldataContextLoader.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport type { CalldataDescriptorDataSource } from \"@/calldata/data/CalldataDescriptorDataSource\";\nimport { CalldataContextLoader
|
|
5
|
-
"mappings": "AAAA,OAAS,iBAAAA,MAAqB,kCAC9B,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAG5B,
|
|
6
|
-
"names": ["DeviceModelId", "Left", "Right", "CalldataContextLoader", "ClearSignContextType", "getProxyImplementationAddress", "getDappDescriptorsMock", "getTokenDescriptorsMock", "mockDappDataSource", "mockTokenDataSource", "mockProxyDatasource", "loader", "
|
|
4
|
+
"sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport type { CalldataDescriptorDataSource } from \"@/calldata/data/CalldataDescriptorDataSource\";\nimport {\n type CalldataContextInput,\n CalldataContextLoader,\n} from \"@/calldata/domain/CalldataContextLoader\";\nimport type { ProxyDataSource } from \"@/proxy/data/ProxyDataSource\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\n\ndescribe(\"CalldataContextLoader\", () => {\n const getProxyImplementationAddress = vi.fn();\n const getDappDescriptorsMock = vi.fn();\n const getTokenDescriptorsMock = vi.fn();\n const mockDappDataSource: CalldataDescriptorDataSource = {\n getCalldataDescriptors: getDappDescriptorsMock,\n };\n const mockTokenDataSource: CalldataDescriptorDataSource = {\n getCalldataDescriptors: getTokenDescriptorsMock,\n };\n const mockProxyDatasource: ProxyDataSource = {\n getProxyImplementationAddress: getProxyImplementationAddress,\n };\n const loader = new CalldataContextLoader(\n mockDappDataSource,\n mockTokenDataSource,\n mockProxyDatasource,\n );\n const SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.TRANSACTION_INFO,\n ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n ClearSignContextType.PROXY_INFO,\n ClearSignContextType.ENUM,\n ];\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n describe(\"canHandle function\", () => {\n const validInput: CalldataContextInput = {\n to: \"0x1234567890123456789012345678901234567890\",\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n chainId: 1,\n deviceModelId: DeviceModelId.NANO_X,\n };\n\n it(\"should return true for valid input\", () => {\n expect(loader.canHandle(validInput, SUPPORTED_TYPES)).toBe(true);\n });\n\n it(\"should return false for invalid expected type\", () => {\n expect(loader.canHandle(validInput, [ClearSignContextType.TOKEN])).toBe(\n false,\n );\n expect(loader.canHandle(validInput, [ClearSignContextType.NFT])).toBe(\n false,\n );\n expect(\n loader.canHandle(validInput, [ClearSignContextType.PROXY_INFO]),\n ).toBe(false);\n expect(loader.canHandle(validInput, [ClearSignContextType.ENUM])).toBe(\n false,\n );\n expect(\n loader.canHandle(validInput, [ClearSignContextType.TRANSACTION_INFO]),\n ).toBe(false);\n });\n\n it.each([\n [null, \"null input\"],\n [undefined, \"undefined input\"],\n [{}, \"empty object\"],\n [\"string\", \"string input\"],\n [123, \"number input\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, SUPPORTED_TYPES)).toBe(false);\n });\n\n it.each([\n [{ ...validInput, to: undefined }, \"missing to\"],\n [{ ...validInput, data: undefined }, \"missing data\"],\n [{ ...validInput, selector: undefined }, \"missing selector\"],\n [{ ...validInput, chainId: undefined }, \"missing chainId\"],\n [{ ...validInput, deviceModelId: undefined }, \"missing deviceModelId\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, SUPPORTED_TYPES)).toBe(false);\n });\n\n it.each([\n [{ ...validInput, to: \"invalid-hex\" }, \"invalid to hex\"],\n [{ ...validInput, to: \"0x\" }, \"empty to hex\"],\n [{ ...validInput, data: \"invalid-hex\" }, \"invalid data hex\"],\n [{ ...validInput, selector: \"invalid-hex\" }, \"invalid selector hex\"],\n [{ ...validInput, selector: \"0x\" }, \"empty selector hex\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, SUPPORTED_TYPES)).toBe(false);\n });\n\n it.each([\n [{ ...validInput, chainId: \"1\" }, \"string chainId\"],\n [{ ...validInput, chainId: null }, \"null chainId\"],\n [\n { ...validInput, deviceModelId: DeviceModelId.NANO_S },\n \"deviceModelId is NANO_S\",\n ],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, SUPPORTED_TYPES)).toBe(false);\n });\n });\n\n it(\"should return an error if data source fails\", async () => {\n // GIVEN\n getProxyImplementationAddress.mockResolvedValue(\n Left(new Error(\"data source error\")),\n );\n getDappDescriptorsMock.mockResolvedValue(\n Left(new Error(\"data source error\")),\n );\n const input = {\n to: \"0x1234567890123456789012345678901234567890\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n deviceModelId: DeviceModelId.NANO_X,\n } as CalldataContextInput;\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(getDappDescriptorsMock).toHaveBeenCalledWith({\n address: \"0x1234567890123456789012345678901234567890\",\n chainId: 3,\n selector: \"0xaf68b302\",\n deviceModelId: DeviceModelId.NANO_X,\n });\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\n \"[ContextModule] CalldataContextLoader: No calldata contexts found\",\n ),\n },\n ]);\n });\n\n it(\"should return the contexts on success\", async () => {\n // GIVEN\n getDappDescriptorsMock.mockResolvedValue(\n Right([\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]),\n );\n getProxyImplementationAddress.mockResolvedValue(\n Left(new Error(\"data source error\")),\n );\n const input = {\n to: \"0x1234567890123456789012345678901234567890\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n deviceModelId: DeviceModelId.NANO_X,\n } as CalldataContextInput;\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]);\n });\n\n it(\"should return the proxy delegate call context on success\", async () => {\n // GIVEN\n getDappDescriptorsMock.mockResolvedValueOnce(Right([])); // No transaction descriptors found for the first call\n getDappDescriptorsMock.mockResolvedValue(\n Right([\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]),\n );\n getProxyImplementationAddress.mockResolvedValue(\n Right({\n implementationAddress: \"0x1234567890abcdef\",\n signedDescriptor: \"0x1234567890abcdef\",\n }),\n );\n const input = {\n to: \"0x1234567890123456789012345678901234567890\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n deviceModelId: DeviceModelId.NANO_X,\n } as CalldataContextInput;\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.PROXY_INFO,\n payload: \"0x\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]);\n });\n\n it(\"should return an error when proxy delegate call succeeds but transaction descriptors for resolved address fail\", async () => {\n // GIVEN\n getDappDescriptorsMock.mockResolvedValueOnce(Right([])); // No transaction descriptors found for the first call\n getDappDescriptorsMock.mockResolvedValueOnce(\n Left(new Error(\"data source error\")),\n ); // Second call fails\n getProxyImplementationAddress.mockResolvedValue(\n Right({\n implementationAddress: \"0xResolvedAddress\",\n signedDescriptor: \"0x1234567890abcdef\",\n }),\n );\n const input = {\n to: \"0x1234567890123456789012345678901234567890\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n deviceModelId: DeviceModelId.NANO_X,\n } as CalldataContextInput;\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(getDappDescriptorsMock).toHaveBeenCalledTimes(2);\n expect(getDappDescriptorsMock).toHaveBeenNthCalledWith(2, {\n address: \"0xResolvedAddress\",\n chainId: 3,\n selector: \"0xaf68b302\",\n deviceModelId: DeviceModelId.NANO_X,\n });\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\n \"[ContextModule] CalldataContextLoader: No calldata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viceModelId", "Left", "Right", "CalldataContextLoader", "ClearSignContextType", "getProxyImplementationAddress", "getDappDescriptorsMock", "getTokenDescriptorsMock", "mockDappDataSource", "mockTokenDataSource", "mockProxyDatasource", "loader", "SUPPORTED_TYPES", "validInput", "input", "_description", "result"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var u=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var C=(i,e,o,t)=>{for(var r=t>1?void 0:t?g(e,o):e,n=i.length-1,a;n>=0;n--)(a=i[n])&&(r=(t?a(e,o,r):a(r))||r);return t&&r&&u(e,o,r),r},d=(i,e)=>(o,t)=>e(o,t,i);import{DeviceModelId as I}from"@ledgerhq/device-management-kit";import{inject as m,injectable as N}from"inversify";import{configTypes as D}from"../../config/di/configTypes";import{dynamicNetworkTypes as k}from"../../dynamic-network/di/dynamicNetworkTypes";import{pkiTypes as S}from"../../pki/di/pkiTypes";import{KeyId as _}from"../../pki/model/KeyId";import{KeyUsage as x}from"../../pki/model/KeyUsage";import{ClearSignContextType as f}from"../../shared/model/ClearSignContext";import{HexStringUtils as T}from"../../shared/utils/HexStringUtils";const w="15",M=[f.DYNAMIC_NETWORK,f.DYNAMIC_NETWORK_ICON];let p=class{_networkDataSource;_config;_certificateLoader;constructor(e,o,t){this._networkDataSource=e,this._config=o,this._certificateLoader=t}canHandle(e,o){return typeof e=="object"&&e!==null&&"chainId"in e&&"deviceModelId"in e&&e.deviceModelId!==void 0&&e.deviceModelId!==I.NANO_S&&typeof e.chainId=="number"&&M.every(t=>o.includes(t))}async load(e){const{chainId:o,deviceModelId:t}=e,r=await this._networkDataSource.getDynamicNetworkConfiguration(o),n=await this._certificateLoader.loadCertificate({keyId:_.CalNetwork,keyUsage:x.Network,targetDevice:t});return r.caseOf({Left:()=>[],Right:a=>{const s=[],c=a.descriptors[t];if(!c)return[];const l=c.signatures[this._config.cal.mode];if(!l)return[];const y=T.appendSignatureToPayload(c.data,l,w);return s.push({type:f.DYNAMIC_NETWORK,payload:y,certificate:n}),c.icon&&s.push({type:f.DYNAMIC_NETWORK_ICON,payload:c.icon}),s}})}};p=C([N(),d(0,m(k.DynamicNetworkDataSource)),d(1,m(D.Config)),d(2,m(S.PkiCertificateLoader))],p);export{p as DynamicNetworkContextLoader};
|
|
2
2
|
//# sourceMappingURL=DynamicNetworkContextLoader.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/dynamic-network/domain/DynamicNetworkContextLoader.ts"],
|
|
4
|
-
"sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { type DynamicNetworkDataSource } from \"@/dynamic-network/data/DynamicNetworkDataSource\";\nimport { dynamicNetworkTypes } from \"@/dynamic-network/di/dynamicNetworkTypes\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport {
|
|
5
|
-
"mappings": "iOAAA,OAAS,iBAAAA,MAAqB,kCAC9B,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YAEnC,OAAS,eAAAC,MAAmB,0BAG5B,OAAS,uBAAAC,MAA2B,2CACpC,OAAS,YAAAC,MAAgB,oBAEzB,OAAS,SAAAC,MAAa,oBACtB,OAAS,YAAAC,MAAgB,uBAEzB,OAEE,wBAAAC,MACK,
|
|
6
|
-
"names": ["DeviceModelId", "inject", "injectable", "configTypes", "dynamicNetworkTypes", "pkiTypes", "KeyId", "KeyUsage", "ClearSignContextType", "HexStringUtils", "NETWORK_SIGNATURE_TAG", "DynamicNetworkContextLoader", "networkDataSource", "config", "certificateLoader", "
|
|
4
|
+
"sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { type DynamicNetworkDataSource } from \"@/dynamic-network/data/DynamicNetworkDataSource\";\nimport { dynamicNetworkTypes } from \"@/dynamic-network/di/dynamicNetworkTypes\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { HexStringUtils } from \"@/shared/utils/HexStringUtils\";\n\nexport type DynamicNetworkContextInput = {\n chainId: number;\n deviceModelId: DeviceModelId;\n};\n\nconst NETWORK_SIGNATURE_TAG = \"15\";\n\nconst SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.DYNAMIC_NETWORK,\n ClearSignContextType.DYNAMIC_NETWORK_ICON,\n];\n\n@injectable()\nexport class DynamicNetworkContextLoader\n implements ContextLoader<DynamicNetworkContextInput>\n{\n private readonly _networkDataSource: DynamicNetworkDataSource;\n private readonly _config: ContextModuleConfig;\n private readonly _certificateLoader: PkiCertificateLoader;\n\n constructor(\n @inject(dynamicNetworkTypes.DynamicNetworkDataSource)\n networkDataSource: DynamicNetworkDataSource,\n @inject(configTypes.Config)\n config: ContextModuleConfig,\n @inject(pkiTypes.PkiCertificateLoader)\n certificateLoader: PkiCertificateLoader,\n ) {\n this._networkDataSource = networkDataSource;\n this._config = config;\n this._certificateLoader = certificateLoader;\n }\n\n canHandle(\n input: unknown,\n expectedTypes: ClearSignContextType[],\n ): input is DynamicNetworkContextInput {\n return (\n typeof input === \"object\" &&\n input !== null &&\n \"chainId\" in input &&\n \"deviceModelId\" in input &&\n input.deviceModelId !== undefined &&\n input.deviceModelId !== DeviceModelId.NANO_S &&\n typeof input.chainId === \"number\" &&\n SUPPORTED_TYPES.every((type) => expectedTypes.includes(type))\n );\n }\n\n async load(input: DynamicNetworkContextInput): Promise<ClearSignContext[]> {\n const { chainId, deviceModelId } = input;\n\n const result =\n await this._networkDataSource.getDynamicNetworkConfiguration(chainId);\n\n // Fetch certificate for the network configuration upfront\n const certificate = await this._certificateLoader.loadCertificate({\n keyId: KeyId.CalNetwork,\n keyUsage: KeyUsage.Network,\n targetDevice: deviceModelId,\n });\n\n return result.caseOf({\n Left: () => [],\n Right: (configuration) => {\n const contexts: ClearSignContext[] = [];\n const descriptor = configuration.descriptors[deviceModelId];\n\n if (!descriptor) {\n return [];\n }\n\n const signature = descriptor.signatures[this._config.cal.mode];\n\n if (!signature) {\n return [];\n }\n\n const configPayload = HexStringUtils.appendSignatureToPayload(\n descriptor.data,\n signature,\n NETWORK_SIGNATURE_TAG,\n );\n\n contexts.push({\n type: ClearSignContextType.DYNAMIC_NETWORK,\n payload: configPayload,\n certificate,\n });\n\n // Add icon if available in the descriptor\n if (descriptor.icon) {\n // Icons don't need signatures appended\n contexts.push({\n type: ClearSignContextType.DYNAMIC_NETWORK_ICON,\n payload: descriptor.icon,\n });\n }\n\n return contexts;\n },\n });\n }\n}\n"],
|
|
5
|
+
"mappings": "iOAAA,OAAS,iBAAAA,MAAqB,kCAC9B,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YAEnC,OAAS,eAAAC,MAAmB,0BAG5B,OAAS,uBAAAC,MAA2B,2CACpC,OAAS,YAAAC,MAAgB,oBAEzB,OAAS,SAAAC,MAAa,oBACtB,OAAS,YAAAC,MAAgB,uBAEzB,OAEE,wBAAAC,MACK,kCACP,OAAS,kBAAAC,MAAs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EAAW,EASPC,EAAA,EAAAC,EAAOC,EAAoB,wBAAwB,GAEnDF,EAAA,EAAAC,EAAOE,EAAY,MAAM,GAEzBH,EAAA,EAAAC,EAAOG,EAAS,oBAAoB,IAZ5B1B",
|
|
6
|
+
"names": ["DeviceModelId", "inject", "injectable", "configTypes", "dynamicNetworkTypes", "pkiTypes", "KeyId", "KeyUsage", "ClearSignContextType", "HexStringUtils", "NETWORK_SIGNATURE_TAG", "SUPPORTED_TYPES", "ClearSignContextType", "DynamicNetworkContextLoader", "networkDataSource", "config", "certificateLoader", "input", "expectedTypes", "DeviceModelId", "type", "chainId", "deviceModelId", "result", "certificate", "KeyId", "KeyUsage", "configuration", "contexts", "descriptor", "signature", "configPayload", "HexStringUtils", "__decorateClass", "injectable", "__decorateParam", "inject", "dynamicNetworkTypes", "configTypes", "pkiTypes"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{DeviceModelId as e}from"@ledgerhq/device-management-kit";import{Left as
|
|
1
|
+
import{DeviceModelId as e}from"@ledgerhq/device-management-kit";import{Left as y,Right as s}from"purify-ts";import{DynamicNetworkContextLoader as f}from"../../dynamic-network/domain/DynamicNetworkContextLoader";import{KeyId as m}from"../../pki/model/KeyId";import{KeyUsage as g}from"../../pki/model/KeyUsage";import{ClearSignContextType as r}from"../../shared/model/ClearSignContext";describe("DynamicNetworkContextLoader",()=>{const c={getDynamicNetworkConfiguration:vi.fn()},l={cal:{url:"https://crypto-assets-service.api.ledger.com",mode:"prod",branch:"main"}},p={loadCertificate:vi.fn()},u={keyUsageNumber:1,payload:new Uint8Array([1,2,3])},a=new f(c,l,p),t=o=>({data:"",descriptorType:"",descriptorVersion:"",signatures:{prod:"",test:""},icon:void 0,...o});beforeEach(()=>{vi.restoreAllMocks(),vi.spyOn(p,"loadCertificate").mockResolvedValue(u)}),describe("canHandle function",()=>{const o={chainId:1,deviceModelId:e.STAX};it("should return true for valid input",()=>{expect(a.canHandle(o,[r.DYNAMIC_NETWORK,r.DYNAMIC_NETWORK_ICON])).toBe(!0)}),it("should return false for invalid expected type",()=>{expect(a.canHandle(o,[r.TOKEN])).toBe(!1),expect(a.canHandle(o,[r.DYNAMIC_NETWORK])).toBe(!1),expect(a.canHandle(o,[r.DYNAMIC_NETWORK_ICON])).toBe(!1)}),it.each([[null,"null input"],[void 0,"undefined input"],[{},"empty object"],["string","string input"],[123,"number input"]])("should return false for %s",(n,i)=>{expect(a.canHandle(n,[r.DYNAMIC_NETWORK,r.DYNAMIC_NETWORK_ICON])).toBe(!1)}),it.each([[{...o,chainId:void 0},"missing chainId"],[{...o,deviceModelId:void 0},"missing deviceModelId"]])("should return false for %s",(n,i)=>{expect(a.canHandle(n,[r.DYNAMIC_NETWORK,r.DYNAMIC_NETWORK_ICON])).toBe(!1)}),it.each([[{...o,chainId:"1"},"string chainId"],[{...o,chainId:null},"null chainId"],[{...o,deviceModelId:e.NANO_S},"NANO_S deviceModelId"]])("should return false for %s",(n,i)=>{expect(a.canHandle(n,[r.DYNAMIC_NETWORK,r.DYNAMIC_NETWORK_ICON])).toBe(!1)})}),describe("load function",()=>{it("should return empty array when network data source returns error",async()=>{const o={chainId:1,deviceModelId:e.STAX};vi.spyOn(c,"getDynamicNetworkConfiguration").mockResolvedValue(y(new Error("Network error")));const n=await a.load(o);expect(n).toEqual([]),expect(c.getDynamicNetworkConfiguration).toHaveBeenCalledWith(1)}),it("should return empty array when descriptor for device model is not found",async()=>{const o={chainId:1,deviceModelId:e.STAX},n={id:"ethereum",descriptors:{[e.NANO_S]:t(),[e.NANO_SP]:t(),[e.NANO_X]:t(),[e.FLEX]:t({data:"0x0101",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"prod-sig",test:"test-sig"},icon:void 0})}};vi.spyOn(c,"getDynamicNetworkConfiguration").mockResolvedValue(s(n));const i=await a.load(o);expect(i).toEqual([])}),it("should return empty array when signature for mode is not found",async()=>{const o={chainId:1,deviceModelId:e.STAX},n={id:"ethereum",descriptors:{[e.APEX]:t(),[e.NANO_S]:t(),[e.NANO_SP]:t(),[e.NANO_X]:t(),[e.FLEX]:t(),[e.STAX]:t({data:"0x0101",descriptorType:"network",descriptorVersion:"v1",signatures:{test:"test-sig"},icon:void 0})}};vi.spyOn(c,"getDynamicNetworkConfiguration").mockResolvedValue(s(n));const i=await a.load(o);expect(i).toEqual([])}),it("should return context with network configuration when all data is available",async()=>{const o={chainId:137,deviceModelId:e.STAX},n={id:"polygon",descriptors:{[e.APEX]:t(),[e.NANO_S]:t(),[e.NANO_SP]:t(),[e.NANO_X]:t(),[e.FLEX]:t(),[e.STAX]:{data:"0x0101080201015101012308000000000000008952",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"3045022100cf42c039c16fc95dc97c09f15cdd93bed0e63ee45cf5c38c2b30bb8a3bc17f8d022053a96c9e51695c3c1c1a31f5cbf84bd6febadc97f4bb02bdc67cf3e24ad0c32d",test:"test-sig"},icon:void 0}}};vi.spyOn(c,"getDynamicNetworkConfiguration").mockResolvedValue(s(n));const i=await a.load(o);expect(i).toHaveLength(1),expect(i[0]).toMatchObject({type:r.DYNAMIC_NETWORK,payload:expect.stringContaining("0x0101080201015101012308000000000000008952"),certificate:u}),expect(p.loadCertificate).toHaveBeenCalledWith({keyId:m.CalNetwork,keyUsage:g.Network,targetDevice:e.STAX})}),it("should include icon context when icon is available",async()=>{const o={chainId:1,deviceModelId:e.STAX},n={id:"ethereum",descriptors:{[e.APEX]:t(),[e.NANO_S]:t(),[e.NANO_SP]:t(),[e.NANO_X]:t(),[e.FLEX]:t(),[e.STAX]:{data:"0x0101",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"prod-sig",test:"test-sig"},icon:"icon-hex-data"}}};vi.spyOn(c,"getDynamicNetworkConfiguration").mockResolvedValue(s(n));const i=await a.load(o);expect(i).toHaveLength(2),expect(i[0]).toMatchObject({type:r.DYNAMIC_NETWORK,payload:expect.any(String),certificate:u}),expect(i[1]).toMatchObject({type:r.DYNAMIC_NETWORK_ICON,payload:"icon-hex-data"})}),it("should handle multiple device models correctly",async()=>{const o={chainId:1,deviceModelId:e.FLEX},n={id:"ethereum",descriptors:{[e.APEX]:t(),[e.NANO_S]:t(),[e.NANO_SP]:t(),[e.NANO_X]:t(),[e.FLEX]:{data:"0xFLEX",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"flex-prod-sig",test:"flex-test-sig"},icon:void 0},[e.STAX]:{data:"0xSTAX",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"stax-prod-sig",test:"stax-test-sig"},icon:void 0}}};vi.spyOn(c,"getDynamicNetworkConfiguration").mockResolvedValue(s(n));const i=await a.load(o);expect(i).toHaveLength(1);const d=i[0];d&&"payload"in d&&(expect(d.payload).toContain("0xFLEX"),expect(d.payload).toContain("flex-prod-sig"))}),it("should use test mode signature when configured",async()=>{const o=new f(c,{...l,cal:{...l.cal,mode:"test"}},p),n={chainId:1,deviceModelId:e.STAX},i={id:"ethereum",descriptors:{[e.APEX]:t(),[e.NANO_S]:t(),[e.NANO_SP]:t(),[e.NANO_X]:t(),[e.FLEX]:t(),[e.STAX]:{data:"0x0101",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"prod-sig",test:"test-sig"},icon:void 0}}};vi.spyOn(c,"getDynamicNetworkConfiguration").mockResolvedValue(s(i));const d=await o.load(n);expect(d).toHaveLength(1);const N=d[0];N&&"payload"in N&&expect(N.payload).toContain("test-sig")})})});
|
|
2
2
|
//# sourceMappingURL=DynamicNetworkContextLoader.test.js.map
|