@ledgerhq/context-module 0.0.0-develop-20260204001157 → 0.0.0-develop-20260206001140
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/package.json +1 -1
- package/lib/cjs/src/ContextModuleBuilder.js +1 -1
- package/lib/cjs/src/ContextModuleBuilder.js.map +3 -3
- package/lib/cjs/src/ContextModuleBuilder.test.js +1 -1
- package/lib/cjs/src/ContextModuleBuilder.test.js.map +3 -3
- package/lib/cjs/src/config/model/ContextModuleBuildArgs.js.map +1 -1
- 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 +2 -2
- package/lib/esm/package.json +1 -1
- package/lib/esm/src/ContextModuleBuilder.js +1 -1
- package/lib/esm/src/ContextModuleBuilder.js.map +3 -3
- package/lib/esm/src/ContextModuleBuilder.test.js +1 -1
- package/lib/esm/src/ContextModuleBuilder.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 +2 -2
- package/lib/types/src/ContextModuleBuilder.d.ts +2 -1
- package/lib/types/src/ContextModuleBuilder.d.ts.map +1 -1
- package/lib/types/src/config/model/ContextModuleBuildArgs.d.ts +1 -1
- package/lib/types/src/config/model/ContextModuleBuildArgs.d.ts.map +1 -1
- package/lib/types/src/trusted-name/domain/TrustedNameContextLoader.d.ts +3 -5
- package/lib/types/src/trusted-name/domain/TrustedNameContextLoader.d.ts.map +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +6 -6
package/lib/cjs/package.json
CHANGED
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"watch:builds": "pnpm ldmk-tool watch --entryPoints index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
|
|
59
59
|
"watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\""
|
|
60
60
|
},
|
|
61
|
-
"version": "0.0.0-develop-
|
|
61
|
+
"version": "0.0.0-develop-20260206001140"
|
|
62
62
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var i=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var g=(t,e)=>{for(var o in e)i(t,o,{get:e[o],enumerable:!0})},l=(t,e,o,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of d(e))!u.call(t,a)&&a!==o&&i(t,a,{get:()=>e[a],enumerable:!(n=c(e,a))||n.enumerable});return t};var C=t=>l(i({},"__esModule",{value:!0}),t);var x={};g(x,{ContextModuleBuilder:()=>L,DEFAULT_CONFIG:()=>r});module.exports=C(x);var s=require("./DefaultContextModule");const f=t=>({debug:()=>{},info:()=>{},warn:()=>{},error:()=>{},subscribers:[]}),m="https://crypto-assets-service.api.ledger.com/v1",h="https://web3checks-backend.api.ledger.com/v3",p="https://nft.api.live.ledger.com",r={cal:{url:m,mode:"prod",branch:"main"},web3checks:{url:h},metadataServiceDomain:{url:p},defaultLoaders:!0,customLoaders:[],defaultFieldLoaders:!0,customFieldLoaders:[],customTypedDataLoader:void 0,customSolanaLoader:void 0,loggerFactory:f};class L{config;originToken;constructor({originToken:e,loggerFactory:o}){this.originToken=e,this.config={...r,cal:{...r.cal},web3checks:{...r.web3checks},metadataServiceDomain:{...r.metadataServiceDomain},customLoaders:[...r.customLoaders],customFieldLoaders:[...r.customFieldLoaders]},o&&(this.config.loggerFactory=o)}removeDefaultLoaders(){return this.config.defaultLoaders=!1,this}addLoader(e){return this.config.customLoaders.push(e),this}addTypedDataLoader(e){return this.config.customTypedDataLoader=e,this}addSolanaLoader(e){return this.config.customSolanaLoader=e,this}setCalConfig(e){return this.config.cal=e,this}setMetadataServiceConfig(e){return this.config.metadataServiceDomain=e,this}setWeb3ChecksConfig(e){return this.config.web3checks=e,this}setDatasourceConfig(e){return this.config.datasource=e,this}setTrustedNameDataSource(e){return this.config.customTrustedNameDataSource=e,this}setLoggerFactory(e){return this.config.loggerFactory=e,this}build(){const e={...this.config,originToken:this.originToken};return new s.DefaultContextModule(e)}}0&&(module.exports={ContextModuleBuilder,DEFAULT_CONFIG});
|
|
2
2
|
//# sourceMappingURL=ContextModuleBuilder.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/ContextModuleBuilder.ts"],
|
|
4
|
-
"sourcesContent": ["import { type LoggerPublisherService } from \"@ledgerhq/device-management-kit\";\n\nimport { type ContextModuleConstructorArgs } from \"./config/model/ContextModuleBuildArgs\";\nimport {\n type ContextModuleCalConfig,\n type ContextModuleConfig,\n type ContextModuleDatasourceConfig,\n type ContextModuleMetadataServiceConfig,\n type ContextModuleWeb3ChecksConfig,\n} from \"./config/model/ContextModuleConfig\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport { type SolanaContextLoader } from \"./solana/domain/SolanaContextLoader\";\nimport { type TrustedNameDataSource } from \"./trusted-name/data/TrustedNameDataSource\";\nimport { type TypedDataContextLoader } from \"./typed-data/domain/TypedDataContextLoader\";\nimport { type ContextModule } from \"./ContextModule\";\nimport { DefaultContextModule } from \"./DefaultContextModule\";\n\nconst DEFAULT_CAL_URL = \"https://crypto-assets-service.api.ledger.com/v1\";\nconst DEFAULT_WEB3_CHECKS_URL = \"https://web3checks-backend.api.ledger.com/v3\";\nconst DEFAULT_METADATA_SERVICE_DOMAIN = \"https://nft.api.live.ledger.com\";\n\nexport class ContextModuleBuilder {\n private config: ContextModuleConfig;\n private originToken?: string;\n\n constructor({ originToken, loggerFactory }: ContextModuleConstructorArgs) {\n this.originToken = originToken;\n\n this.config = {\n cal: {
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,IAAA,eAAAC,
|
|
6
|
-
"names": ["ContextModuleBuilder_exports", "__export", "ContextModuleBuilder", "__toCommonJS", "import_DefaultContextModule", "DEFAULT_CAL_URL", "DEFAULT_WEB3_CHECKS_URL", "DEFAULT_METADATA_SERVICE_DOMAIN", "originToken", "loggerFactory", "loader", "calConfig", "metadataServiceConfig", "web3ChecksConfig", "datasourceConfig", "dataSource", "config"]
|
|
4
|
+
"sourcesContent": ["import { type LoggerPublisherService } from \"@ledgerhq/device-management-kit\";\n\nimport { type ContextModuleConstructorArgs } from \"./config/model/ContextModuleBuildArgs\";\nimport {\n type ContextModuleCalConfig,\n type ContextModuleConfig,\n type ContextModuleDatasourceConfig,\n type ContextModuleMetadataServiceConfig,\n type ContextModuleWeb3ChecksConfig,\n} from \"./config/model/ContextModuleConfig\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport { type SolanaContextLoader } from \"./solana/domain/SolanaContextLoader\";\nimport { type TrustedNameDataSource } from \"./trusted-name/data/TrustedNameDataSource\";\nimport { type TypedDataContextLoader } from \"./typed-data/domain/TypedDataContextLoader\";\nimport { type ContextModule } from \"./ContextModule\";\nimport { DefaultContextModule } from \"./DefaultContextModule\";\n\nconst emptyLoggerFactory = (_tag: string): LoggerPublisherService => ({\n debug: () => {},\n info: () => {},\n warn: () => {},\n error: () => {},\n subscribers: [],\n});\n\nconst DEFAULT_CAL_URL = \"https://crypto-assets-service.api.ledger.com/v1\";\nconst DEFAULT_WEB3_CHECKS_URL = \"https://web3checks-backend.api.ledger.com/v3\";\nconst DEFAULT_METADATA_SERVICE_DOMAIN = \"https://nft.api.live.ledger.com\";\n\nexport const DEFAULT_CONFIG: ContextModuleConfig = {\n cal: {\n url: DEFAULT_CAL_URL,\n mode: \"prod\",\n branch: \"main\",\n },\n web3checks: {\n url: DEFAULT_WEB3_CHECKS_URL,\n },\n metadataServiceDomain: {\n url: DEFAULT_METADATA_SERVICE_DOMAIN,\n },\n defaultLoaders: true,\n customLoaders: [],\n defaultFieldLoaders: true,\n customFieldLoaders: [],\n customTypedDataLoader: undefined,\n customSolanaLoader: undefined,\n loggerFactory: emptyLoggerFactory,\n};\n\nexport class ContextModuleBuilder {\n private config: ContextModuleConfig;\n private originToken?: string;\n\n constructor({ originToken, loggerFactory }: ContextModuleConstructorArgs) {\n this.originToken = originToken;\n\n this.config = {\n ...DEFAULT_CONFIG,\n cal: { ...DEFAULT_CONFIG.cal },\n web3checks: { ...DEFAULT_CONFIG.web3checks },\n metadataServiceDomain: { ...DEFAULT_CONFIG.metadataServiceDomain },\n customLoaders: [...DEFAULT_CONFIG.customLoaders],\n customFieldLoaders: [...DEFAULT_CONFIG.customFieldLoaders],\n };\n if (loggerFactory) {\n this.config.loggerFactory = loggerFactory;\n }\n }\n\n /**\n * Remove default loaders from the list of loaders\n *\n * @returns this\n */\n removeDefaultLoaders() {\n this.config.defaultLoaders = false;\n return this;\n }\n\n /**\n * Add a custom loader to the list of loaders\n *\n * @param loader loader to add to the list of loaders\n * @returns this\n */\n addLoader(loader: ContextLoader) {\n this.config.customLoaders.push(loader);\n return this;\n }\n\n /**\n * Replace the default loader for typed data clear signing contexts\n *\n * @param loader loader to use for typed data clear signing contexts\n * @returns this\n */\n addTypedDataLoader(loader: TypedDataContextLoader) {\n this.config.customTypedDataLoader = loader;\n return this;\n }\n\n /**\n * Replace the default loader for Solana context\n *\n * @param loader loader to use for Solana context\n * @returns this\n */\n addSolanaLoader(loader: SolanaContextLoader) {\n this.config.customSolanaLoader = loader;\n return this;\n }\n\n /**\n * Add a custom CAL configuration\n *\n * @param calConfig\n * @returns this\n */\n setCalConfig(calConfig: ContextModuleCalConfig) {\n this.config.cal = calConfig;\n return this;\n }\n\n /**\n * Add a custom metadata service configuration\n *\n * @param metadataServiceConfig\n * @returns this\n */\n setMetadataServiceConfig(\n metadataServiceConfig: ContextModuleMetadataServiceConfig,\n ) {\n this.config.metadataServiceDomain = metadataServiceConfig;\n return this;\n }\n\n /**\n * Add a custom web3 checks configuration\n *\n * @param web3ChecksConfig\n * @returns this\n */\n setWeb3ChecksConfig(web3ChecksConfig: ContextModuleWeb3ChecksConfig) {\n this.config.web3checks = web3ChecksConfig;\n return this;\n }\n\n /**\n * Add datasource configuration\n *\n * @param datasourceConfig\n * @returns this\n */\n setDatasourceConfig(datasourceConfig: ContextModuleDatasourceConfig) {\n this.config.datasource = datasourceConfig;\n return this;\n }\n\n /**\n * Set a custom trusted name data source\n *\n * @param dataSource data source to use for trusted name resolution\n * @returns this\n */\n setTrustedNameDataSource(dataSource: TrustedNameDataSource) {\n this.config.customTrustedNameDataSource = dataSource;\n return this;\n }\n\n /**\n * Set a custom logger factory\n *\n * @param loggerFactory\n * @returns this\n */\n setLoggerFactory(loggerFactory: (tag: string) => LoggerPublisherService) {\n this.config.loggerFactory = loggerFactory;\n return this;\n }\n\n /**\n * Build the context module\n *\n * @returns the context module\n */\n build(): ContextModule {\n const config = { ...this.config, originToken: this.originToken };\n return new DefaultContextModule(config);\n }\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,EAAA,mBAAAC,IAAA,eAAAC,EAAAJ,GAeA,IAAAK,EAAqC,kCAErC,MAAMC,EAAsBC,IAA0C,CACpE,MAAO,IAAM,CAAC,EACd,KAAM,IAAM,CAAC,EACb,KAAM,IAAM,CAAC,EACb,MAAO,IAAM,CAAC,EACd,YAAa,CAAC,CAChB,GAEMC,EAAkB,kDAClBC,EAA0B,+CAC1BC,EAAkC,kCAE3BP,EAAsC,CACjD,IAAK,CACH,IAAKK,EACL,KAAM,OACN,OAAQ,MACV,EACA,WAAY,CACV,IAAKC,CACP,EACA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,CACxC,CACF",
|
|
6
|
+
"names": ["ContextModuleBuilder_exports", "__export", "ContextModuleBuilder", "DEFAULT_CONFIG", "__toCommonJS", "import_DefaultContextModule", "emptyLoggerFactory", "_tag", "DEFAULT_CAL_URL", "DEFAULT_WEB3_CHECKS_URL", "DEFAULT_METADATA_SERVICE_DOMAIN", "originToken", "loggerFactory", "loader", "calConfig", "metadataServiceConfig", "web3ChecksConfig", "datasourceConfig", "dataSource", "config"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var a=require("./config/di/configTypes"),g=require("./trusted-name/data/HttpTrustedNameDataSource"),u=require("./trusted-name/di/trustedNameTypes"),c=require("./ContextModuleBuilder"),s=require("./DefaultContextModule");describe("ContextModuleBuilder",()=>{const i={url:"https://cal/v1",mode:"prod",branch:"main"},d={url:"https://web3checks/v1"},r={originToken:"test",loggerFactory:()=>({debug:vi.fn(),info:vi.fn(),warn:vi.fn(),error:vi.fn(),subscribers:[]})};beforeEach(()=>{vi.resetAllMocks()}),it("should return a default context module",()=>{const e=new c.ContextModuleBuilder(r).build();expect(e).toBeInstanceOf(s.DefaultContextModule)}),it("should return a custom context module",()=>{const n=new c.ContextModuleBuilder(r),e={load:vi.fn(),canHandle:vi.fn()},o=n.removeDefaultLoaders().addLoader(e).build();expect(o).toBeInstanceOf(s.DefaultContextModule)}),it("should return a custom context module with a custom typed data loader",()=>{const n=new c.ContextModuleBuilder(r),e={load:vi.fn()},o=n.removeDefaultLoaders().addTypedDataLoader(e).build();expect(o).toBeInstanceOf(s.DefaultContextModule),expect(o._typedDataLoader).toBe(e)}),it("should return a custom context module with a custom config",()=>{const e=new c.ContextModuleBuilder(r).setCalConfig(i).setWeb3ChecksConfig(d).build(),o=e._container.get(a.configTypes.Config);expect(e).toBeInstanceOf(s.DefaultContextModule),expect(o.cal).toEqual(i),expect(o.web3checks).toEqual(d)}),it("should not throw an error if origin token is provided",()=>{const n=new c.ContextModuleBuilder(r);expect(()=>n.build()).not.toThrow()}),describe("setMetadataServiceConfig",()=>{it("should set the metadata service configuration",()=>{const n=new c.ContextModuleBuilder(r),e={url:"https://custom-metadata-service.com/v3"},o=n.setMetadataServiceConfig(e).build(),t=o._container.get(a.configTypes.Config);expect(o).toBeInstanceOf(s.DefaultContextModule),expect(t.metadataServiceDomain).toEqual(e)}),it("should override the default metadata service configuration",()=>{const n=new c.ContextModuleBuilder(r),e={url:"https://override-metadata-service.com/v1"},t=n.setMetadataServiceConfig(e).build()._container.get(a.configTypes.Config);expect(t.metadataServiceDomain.url).toBe(e.url),expect(t.metadataServiceDomain.url).not.toBe("https://nft.api.live.ledger.com/v2")})}),describe("setCalConfig",()=>{it("should set the CAL configuration",()=>{const n=new c.ContextModuleBuilder(r),e={url:"https://custom-cal-service.com/v2",mode:"test",branch:"next"},o=n.setCalConfig(e).build(),t=o._container.get(a.configTypes.Config);expect(o).toBeInstanceOf(s.DefaultContextModule),expect(t.cal).toEqual(e)}),it("should override the default CAL configuration",()=>{const n=new c.ContextModuleBuilder(r),e={url:"https://override-cal-service.com/v1",mode:"prod",branch:"demo"},t=n.setCalConfig(e).build()._container.get(a.configTypes.Config);expect(t.cal.url).toBe(e.url),expect(t.cal.mode).toBe(e.mode),expect(t.cal.branch).toBe(e.branch),expect(t.cal.url).not.toBe("https://crypto-assets-service.api.ledger.com/v1")})}),describe("setWeb3ChecksConfig",()=>{it("should set the web3 checks configuration",()=>{const n=new c.ContextModuleBuilder(r),e={url:"https://custom-web3checks-service.com/v4"},o=n.setWeb3ChecksConfig(e).build(),t=o._container.get(a.configTypes.Config);expect(o).toBeInstanceOf(s.DefaultContextModule),expect(t.web3checks).toEqual(e)}),it("should override the default web3 checks configuration",()=>{const n=new c.ContextModuleBuilder(r),e={url:"https://override-web3checks-service.com/v2"},t=n.setWeb3ChecksConfig(e).build()._container.get(a.configTypes.Config);expect(t.web3checks.url).toBe(e.url),expect(t.web3checks.url).not.toBe("https://web3checks-backend.api.ledger.com/v3")})}),describe("setDatasourceConfig",()=>{it("should set the datasource configuration with safe proxy",()=>{const n=new c.ContextModuleBuilder(r),e={proxy:"safe"},o=n.setDatasourceConfig(e).build(),t=o._container.get(a.configTypes.Config);expect(o).toBeInstanceOf(s.DefaultContextModule),expect(t.datasource).toEqual(e),expect(t.datasource?.proxy).toBe("safe")}),it("should set the datasource configuration with default proxy",()=>{const n=new c.ContextModuleBuilder(r),e={proxy:"default"},o=n.setDatasourceConfig(e).build(),t=o._container.get(a.configTypes.Config);expect(o).toBeInstanceOf(s.DefaultContextModule),expect(t.datasource).toEqual(e),expect(t.datasource?.proxy).toBe("default")}),it("should override the default datasource configuration",()=>{const n=new c.ContextModuleBuilder(r),e={proxy:"safe"},t=n.setDatasourceConfig(e).build()._container.get(a.configTypes.Config);expect(t.datasource?.proxy).toBe("safe"),expect(t.datasource).not.toBeUndefined()}),it("should set an empty datasource configuration",()=>{const n=new c.ContextModuleBuilder(r),e={},o=n.setDatasourceConfig(e).build(),t=o._container.get(a.configTypes.Config);expect(o).toBeInstanceOf(s.DefaultContextModule),expect(t.datasource).toEqual(e),expect(t.datasource?.proxy).toBeUndefined()})}),describe("loggerFactory",()=>{it("should use the default empty logger when loggerFactory is not provided",()=>{const e=new c.ContextModuleBuilder({originToken:"test"}).build(),o=e._container.get(a.configTypes.Config);expect(e).toBeInstanceOf(s.DefaultContextModule),expect(o.loggerFactory).toBeDefined();const t=o.loggerFactory("test");expect(t.debug).toBeDefined(),expect(t.info).toBeDefined(),expect(t.warn).toBeDefined(),expect(t.error).toBeDefined(),expect(t.subscribers).toEqual([]),expect(()=>t.debug("test")).not.toThrow(),expect(()=>t.info("test")).not.toThrow(),expect(()=>t.warn("test")).not.toThrow(),expect(()=>t.error("test")).not.toThrow()}),it("should set the loggerFactory when provided in the constructor",()=>{const n=vi.fn(),o=new c.ContextModuleBuilder({...r,loggerFactory:n}).build(),t=o._container.get(a.configTypes.Config);expect(o).toBeInstanceOf(s.DefaultContextModule),expect(t.loggerFactory).toBe(n)}),it("should set the loggerFactory via setLoggerFactory",()=>{const n=vi.fn(),o=new c.ContextModuleBuilder(r).setLoggerFactory(n).build(),t=o._container.get(a.configTypes.Config);expect(o).toBeInstanceOf(s.DefaultContextModule),expect(t.loggerFactory).toBe(n)}),it("should override constructor loggerFactory with setLoggerFactory",()=>{const n=vi.fn(),e=vi.fn(),l=new c.ContextModuleBuilder({...r,loggerFactory:n}).setLoggerFactory(e).build()._container.get(a.configTypes.Config);expect(l.loggerFactory).toBe(e),expect(l.loggerFactory).not.toBe(n)})}),describe("setTrustedNameDataSource",()=>{it("should set a custom trusted name data source",()=>{const n=new c.ContextModuleBuilder(r),e={getDomainNamePayload:vi.fn(),getTrustedNamePayload:vi.fn()},o=n.setTrustedNameDataSource(e).build(),t=o._container.get(a.configTypes.Config);expect(o).toBeInstanceOf(s.DefaultContextModule),expect(t.customTrustedNameDataSource).toBe(e)}),it("should inject the custom data source into the container",()=>{const n=new c.ContextModuleBuilder(r),e={getDomainNamePayload:vi.fn(),getTrustedNamePayload:vi.fn()},t=n.setTrustedNameDataSource(e).build()._container.get(u.trustedNameTypes.TrustedNameDataSource);expect(t).toBe(e)}),it("should use HttpTrustedNameDataSource when no custom data source is set",()=>{const e=new c.ContextModuleBuilder(r).build(),o=e._container.get(u.trustedNameTypes.TrustedNameDataSource);expect(e).toBeInstanceOf(s.DefaultContextModule),expect(o).toBeInstanceOf(g.HttpTrustedNameDataSource)})})});
|
|
2
2
|
//# sourceMappingURL=ContextModuleBuilder.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/ContextModuleBuilder.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { type LoggerPublisherService } from \"@ledgerhq/device-management-kit\";\nimport { type Container } from \"inversify\";\n\nimport { configTypes } from \"./config/di/configTypes\";\nimport { type ContextModuleConstructorArgs } from \"./config/model/ContextModuleBuildArgs\";\nimport {\n type ContextModuleCalConfig,\n type ContextModuleConfig,\n type ContextModuleDatasourceConfig,\n type ContextModuleMetadataServiceConfig,\n} from \"./config/model/ContextModuleConfig\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport { HttpTrustedNameDataSource } from \"./trusted-name/data/HttpTrustedNameDataSource\";\nimport { type TrustedNameDataSource } from \"./trusted-name/data/TrustedNameDataSource\";\nimport { trustedNameTypes } from \"./trusted-name/di/trustedNameTypes\";\nimport { ContextModuleBuilder } from \"./ContextModuleBuilder\";\nimport { DefaultContextModule } from \"./DefaultContextModule\";\n\ndescribe(\"ContextModuleBuilder\", () => {\n const defaultCalConfig: ContextModuleCalConfig = {\n url: \"https://cal/v1\",\n mode: \"prod\",\n branch: \"main\",\n };\n const defaultWeb3ChecksConfig = {\n url: \"https://web3checks/v1\",\n };\n const mockLoggerFactory = () => ({\n debug: vi.fn(),\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n subscribers: [],\n });\n\n const defaultBuilderArgs: ContextModuleConstructorArgs = {\n originToken: \"test\",\n loggerFactory: mockLoggerFactory,\n };\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n it(\"should return a default context module\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n\n const res = contextModuleBuilder.build();\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n });\n\n it(\"should return a custom context module\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customLoader: ContextLoader = {\n load: vi.fn(),\n canHandle: vi.fn() as unknown as ContextLoader[\"canHandle\"],\n };\n\n const res = contextModuleBuilder\n .removeDefaultLoaders()\n .addLoader(customLoader)\n .build();\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n });\n\n it(\"should return a custom context module with a custom typed data loader\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customLoader = { load: vi.fn() };\n\n const res = contextModuleBuilder\n .removeDefaultLoaders()\n .addTypedDataLoader(customLoader)\n .build();\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n // @ts-expect-error _typedDataLoader is private\n expect(res[\"_typedDataLoader\"]).toBe(customLoader);\n });\n\n it(\"should return a custom context module with a custom config\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n\n const res = contextModuleBuilder\n .setCalConfig(defaultCalConfig)\n .setWeb3ChecksConfig(defaultWeb3ChecksConfig)\n .build();\n // @ts-expect-error _container is private\n const config = (res[\"_container\"] as Container).get<ContextModuleConfig>(\n configTypes.Config,\n );\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.cal).toEqual(defaultCalConfig);\n expect(config.web3checks).toEqual(defaultWeb3ChecksConfig);\n });\n\n it(\"should not throw an error if origin token is provided\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n\n expect(() => contextModuleBuilder.build()).not.toThrow();\n });\n\n describe(\"setMetadataServiceConfig\", () => {\n it(\"should set the metadata service configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customMetadataConfig: ContextModuleMetadataServiceConfig = {\n url: \"https://custom-metadata-service.com/v3\",\n };\n\n const res = contextModuleBuilder\n .setMetadataServiceConfig(customMetadataConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.metadataServiceDomain).toEqual(customMetadataConfig);\n });\n\n it(\"should override the default metadata service configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customMetadataConfig: ContextModuleMetadataServiceConfig = {\n url: \"https://override-metadata-service.com/v1\",\n };\n\n const res = contextModuleBuilder\n .setMetadataServiceConfig(customMetadataConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(config.metadataServiceDomain.url).toBe(customMetadataConfig.url);\n expect(config.metadataServiceDomain.url).not.toBe(\n \"https://nft.api.live.ledger.com/v2\",\n );\n });\n });\n\n describe(\"setCalConfig\", () => {\n it(\"should set the CAL configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customCalConfig: ContextModuleCalConfig = {\n url: \"https://custom-cal-service.com/v2\",\n mode: \"test\",\n branch: \"next\",\n };\n\n const res = contextModuleBuilder.setCalConfig(customCalConfig).build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.cal).toEqual(customCalConfig);\n });\n\n it(\"should override the default CAL configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customCalConfig: ContextModuleCalConfig = {\n url: \"https://override-cal-service.com/v1\",\n mode: \"prod\",\n branch: \"demo\",\n };\n\n const res = contextModuleBuilder.setCalConfig(customCalConfig).build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(config.cal.url).toBe(customCalConfig.url);\n expect(config.cal.mode).toBe(customCalConfig.mode);\n expect(config.cal.branch).toBe(customCalConfig.branch);\n expect(config.cal.url).not.toBe(\n \"https://crypto-assets-service.api.ledger.com/v1\",\n );\n });\n });\n\n describe(\"setWeb3ChecksConfig\", () => {\n it(\"should set the web3 checks configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customWeb3ChecksConfig = {\n url: \"https://custom-web3checks-service.com/v4\",\n };\n\n const res = contextModuleBuilder\n .setWeb3ChecksConfig(customWeb3ChecksConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.web3checks).toEqual(customWeb3ChecksConfig);\n });\n\n it(\"should override the default web3 checks configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customWeb3ChecksConfig = {\n url: \"https://override-web3checks-service.com/v2\",\n };\n\n const res = contextModuleBuilder\n .setWeb3ChecksConfig(customWeb3ChecksConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(config.web3checks.url).toBe(customWeb3ChecksConfig.url);\n expect(config.web3checks.url).not.toBe(\n \"https://web3checks-backend.api.ledger.com/v3\",\n );\n });\n });\n\n describe(\"setDatasourceConfig\", () => {\n it(\"should set the datasource configuration with safe proxy\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customDatasourceConfig: ContextModuleDatasourceConfig = {\n proxy: \"safe\",\n };\n\n const res = contextModuleBuilder\n .setDatasourceConfig(customDatasourceConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.datasource).toEqual(customDatasourceConfig);\n expect(config.datasource?.proxy).toBe(\"safe\");\n });\n\n it(\"should set the datasource configuration with default proxy\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customDatasourceConfig: ContextModuleDatasourceConfig = {\n proxy: \"default\",\n };\n\n const res = contextModuleBuilder\n .setDatasourceConfig(customDatasourceConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.datasource).toEqual(customDatasourceConfig);\n expect(config.datasource?.proxy).toBe(\"default\");\n });\n\n it(\"should override the default datasource configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customDatasourceConfig: ContextModuleDatasourceConfig = {\n proxy: \"safe\",\n };\n\n const res = contextModuleBuilder\n .setDatasourceConfig(customDatasourceConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(config.datasource?.proxy).toBe(\"safe\");\n expect(config.datasource).not.toBeUndefined();\n });\n\n it(\"should set an empty datasource configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customDatasourceConfig: ContextModuleDatasourceConfig = {};\n\n const res = contextModuleBuilder\n .setDatasourceConfig(customDatasourceConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.datasource).toEqual(customDatasourceConfig);\n expect(config.datasource?.proxy).toBeUndefined();\n });\n });\n\n describe(\"loggerFactory\", () => {\n it(\"should set the loggerFactory when provided in the constructor\", () => {\n const loggerFactory: (tag: string) => LoggerPublisherService = vi.fn();\n\n const contextModuleBuilder = new ContextModuleBuilder({\n ...defaultBuilderArgs,\n loggerFactory,\n });\n\n const res = contextModuleBuilder.build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.loggerFactory).toBe(loggerFactory);\n });\n\n it(\"should set the loggerFactory via setLoggerFactory\", () => {\n const loggerFactory: (tag: string) => LoggerPublisherService = vi.fn();\n\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n\n const res = contextModuleBuilder.setLoggerFactory(loggerFactory).build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.loggerFactory).toBe(loggerFactory);\n });\n\n it(\"should override constructor loggerFactory with setLoggerFactory\", () => {\n const constructorLoggerFactory: (tag: string) => LoggerPublisherService =\n vi.fn();\n const overrideLoggerFactory: (tag: string) => LoggerPublisherService =\n vi.fn();\n\n const contextModuleBuilder = new ContextModuleBuilder({\n ...defaultBuilderArgs,\n loggerFactory: constructorLoggerFactory,\n });\n\n const res = contextModuleBuilder\n .setLoggerFactory(overrideLoggerFactory)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(config.loggerFactory).toBe(overrideLoggerFactory);\n expect(config.loggerFactory).not.toBe(constructorLoggerFactory);\n });\n });\n\n describe(\"setTrustedNameDataSource\", () => {\n it(\"should set a custom trusted name data source\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customDataSource: TrustedNameDataSource = {\n getDomainNamePayload: vi.fn(),\n getTrustedNamePayload: vi.fn(),\n };\n\n const res = contextModuleBuilder\n .setTrustedNameDataSource(customDataSource)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.customTrustedNameDataSource).toBe(customDataSource);\n });\n\n it(\"should inject the custom data source into the container\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customDataSource: TrustedNameDataSource = {\n getDomainNamePayload: vi.fn(),\n getTrustedNamePayload: vi.fn(),\n };\n\n const res = contextModuleBuilder\n .setTrustedNameDataSource(customDataSource)\n .build();\n const injectedDataSource = (res as DefaultContextModule)[\n \"_container\"\n ].get<TrustedNameDataSource>(trustedNameTypes.TrustedNameDataSource);\n\n expect(injectedDataSource).toBe(customDataSource);\n });\n\n it(\"should use HttpTrustedNameDataSource when no custom data source is set\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n\n const res = contextModuleBuilder.build();\n const injectedDataSource = (res as DefaultContextModule)[\n \"_container\"\n ].get<TrustedNameDataSource>(trustedNameTypes.TrustedNameDataSource);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(injectedDataSource).toBeInstanceOf(HttpTrustedNameDataSource);\n });\n });\n});\n"],
|
|
5
|
-
"mappings": "aAGA,IAAAA,EAA4B,mCAS5BC,EAA0C,yDAE1CC,EAAiC,8CACjCC,EAAqC,kCACrCC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B,GAAG,gEAAiE,IAAM,CACxE,
|
|
6
|
-
"names": ["import_configTypes", "import_HttpTrustedNameDataSource", "import_trustedNameTypes", "import_ContextModuleBuilder", "import_DefaultContextModule", "defaultCalConfig", "defaultWeb3ChecksConfig", "defaultBuilderArgs", "res", "contextModuleBuilder", "customLoader", "config", "customMetadataConfig", "customCalConfig", "customWeb3ChecksConfig", "customDatasourceConfig", "loggerFactory", "constructorLoggerFactory", "overrideLoggerFactory", "customDataSource", "injectedDataSource"]
|
|
4
|
+
"sourcesContent": ["import { type LoggerPublisherService } from \"@ledgerhq/device-management-kit\";\nimport { type Container } from \"inversify\";\n\nimport { configTypes } from \"./config/di/configTypes\";\nimport { type ContextModuleConstructorArgs } from \"./config/model/ContextModuleBuildArgs\";\nimport {\n type ContextModuleCalConfig,\n type ContextModuleConfig,\n type ContextModuleDatasourceConfig,\n type ContextModuleMetadataServiceConfig,\n} from \"./config/model/ContextModuleConfig\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport { HttpTrustedNameDataSource } from \"./trusted-name/data/HttpTrustedNameDataSource\";\nimport { type TrustedNameDataSource } from \"./trusted-name/data/TrustedNameDataSource\";\nimport { trustedNameTypes } from \"./trusted-name/di/trustedNameTypes\";\nimport { ContextModuleBuilder } from \"./ContextModuleBuilder\";\nimport { DefaultContextModule } from \"./DefaultContextModule\";\n\ndescribe(\"ContextModuleBuilder\", () => {\n const defaultCalConfig: ContextModuleCalConfig = {\n url: \"https://cal/v1\",\n mode: \"prod\",\n branch: \"main\",\n };\n const defaultWeb3ChecksConfig = {\n url: \"https://web3checks/v1\",\n };\n const mockLoggerFactory = () => ({\n debug: vi.fn(),\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n subscribers: [],\n });\n\n const defaultBuilderArgs: ContextModuleConstructorArgs = {\n originToken: \"test\",\n loggerFactory: mockLoggerFactory,\n };\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n it(\"should return a default context module\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n\n const res = contextModuleBuilder.build();\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n });\n\n it(\"should return a custom context module\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customLoader: ContextLoader = {\n load: vi.fn(),\n canHandle: vi.fn() as unknown as ContextLoader[\"canHandle\"],\n };\n\n const res = contextModuleBuilder\n .removeDefaultLoaders()\n .addLoader(customLoader)\n .build();\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n });\n\n it(\"should return a custom context module with a custom typed data loader\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customLoader = { load: vi.fn() };\n\n const res = contextModuleBuilder\n .removeDefaultLoaders()\n .addTypedDataLoader(customLoader)\n .build();\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n // @ts-expect-error _typedDataLoader is private\n expect(res[\"_typedDataLoader\"]).toBe(customLoader);\n });\n\n it(\"should return a custom context module with a custom config\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n\n const res = contextModuleBuilder\n .setCalConfig(defaultCalConfig)\n .setWeb3ChecksConfig(defaultWeb3ChecksConfig)\n .build();\n // @ts-expect-error _container is private\n const config = (res[\"_container\"] as Container).get<ContextModuleConfig>(\n configTypes.Config,\n );\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.cal).toEqual(defaultCalConfig);\n expect(config.web3checks).toEqual(defaultWeb3ChecksConfig);\n });\n\n it(\"should not throw an error if origin token is provided\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n\n expect(() => contextModuleBuilder.build()).not.toThrow();\n });\n\n describe(\"setMetadataServiceConfig\", () => {\n it(\"should set the metadata service configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customMetadataConfig: ContextModuleMetadataServiceConfig = {\n url: \"https://custom-metadata-service.com/v3\",\n };\n\n const res = contextModuleBuilder\n .setMetadataServiceConfig(customMetadataConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.metadataServiceDomain).toEqual(customMetadataConfig);\n });\n\n it(\"should override the default metadata service configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customMetadataConfig: ContextModuleMetadataServiceConfig = {\n url: \"https://override-metadata-service.com/v1\",\n };\n\n const res = contextModuleBuilder\n .setMetadataServiceConfig(customMetadataConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(config.metadataServiceDomain.url).toBe(customMetadataConfig.url);\n expect(config.metadataServiceDomain.url).not.toBe(\n \"https://nft.api.live.ledger.com/v2\",\n );\n });\n });\n\n describe(\"setCalConfig\", () => {\n it(\"should set the CAL configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customCalConfig: ContextModuleCalConfig = {\n url: \"https://custom-cal-service.com/v2\",\n mode: \"test\",\n branch: \"next\",\n };\n\n const res = contextModuleBuilder.setCalConfig(customCalConfig).build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.cal).toEqual(customCalConfig);\n });\n\n it(\"should override the default CAL configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customCalConfig: ContextModuleCalConfig = {\n url: \"https://override-cal-service.com/v1\",\n mode: \"prod\",\n branch: \"demo\",\n };\n\n const res = contextModuleBuilder.setCalConfig(customCalConfig).build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(config.cal.url).toBe(customCalConfig.url);\n expect(config.cal.mode).toBe(customCalConfig.mode);\n expect(config.cal.branch).toBe(customCalConfig.branch);\n expect(config.cal.url).not.toBe(\n \"https://crypto-assets-service.api.ledger.com/v1\",\n );\n });\n });\n\n describe(\"setWeb3ChecksConfig\", () => {\n it(\"should set the web3 checks configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customWeb3ChecksConfig = {\n url: \"https://custom-web3checks-service.com/v4\",\n };\n\n const res = contextModuleBuilder\n .setWeb3ChecksConfig(customWeb3ChecksConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.web3checks).toEqual(customWeb3ChecksConfig);\n });\n\n it(\"should override the default web3 checks configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customWeb3ChecksConfig = {\n url: \"https://override-web3checks-service.com/v2\",\n };\n\n const res = contextModuleBuilder\n .setWeb3ChecksConfig(customWeb3ChecksConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(config.web3checks.url).toBe(customWeb3ChecksConfig.url);\n expect(config.web3checks.url).not.toBe(\n \"https://web3checks-backend.api.ledger.com/v3\",\n );\n });\n });\n\n describe(\"setDatasourceConfig\", () => {\n it(\"should set the datasource configuration with safe proxy\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customDatasourceConfig: ContextModuleDatasourceConfig = {\n proxy: \"safe\",\n };\n\n const res = contextModuleBuilder\n .setDatasourceConfig(customDatasourceConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.datasource).toEqual(customDatasourceConfig);\n expect(config.datasource?.proxy).toBe(\"safe\");\n });\n\n it(\"should set the datasource configuration with default proxy\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customDatasourceConfig: ContextModuleDatasourceConfig = {\n proxy: \"default\",\n };\n\n const res = contextModuleBuilder\n .setDatasourceConfig(customDatasourceConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.datasource).toEqual(customDatasourceConfig);\n expect(config.datasource?.proxy).toBe(\"default\");\n });\n\n it(\"should override the default datasource configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customDatasourceConfig: ContextModuleDatasourceConfig = {\n proxy: \"safe\",\n };\n\n const res = contextModuleBuilder\n .setDatasourceConfig(customDatasourceConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(config.datasource?.proxy).toBe(\"safe\");\n expect(config.datasource).not.toBeUndefined();\n });\n\n it(\"should set an empty datasource configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customDatasourceConfig: ContextModuleDatasourceConfig = {};\n\n const res = contextModuleBuilder\n .setDatasourceConfig(customDatasourceConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.datasource).toEqual(customDatasourceConfig);\n expect(config.datasource?.proxy).toBeUndefined();\n });\n });\n\n describe(\"loggerFactory\", () => {\n it(\"should use the default empty logger when loggerFactory is not provided\", () => {\n const contextModuleBuilder = new ContextModuleBuilder({\n originToken: \"test\",\n });\n\n const res = contextModuleBuilder.build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.loggerFactory).toBeDefined();\n\n // Verify the default logger has empty implementations\n const logger = config.loggerFactory(\"test\");\n expect(logger.debug).toBeDefined();\n expect(logger.info).toBeDefined();\n expect(logger.warn).toBeDefined();\n expect(logger.error).toBeDefined();\n expect(logger.subscribers).toEqual([]);\n\n // Verify the empty logger functions don't throw\n expect(() => logger.debug(\"test\")).not.toThrow();\n expect(() => logger.info(\"test\")).not.toThrow();\n expect(() => logger.warn(\"test\")).not.toThrow();\n expect(() => logger.error(\"test\")).not.toThrow();\n });\n\n it(\"should set the loggerFactory when provided in the constructor\", () => {\n const loggerFactory: (tag: string) => LoggerPublisherService = vi.fn();\n\n const contextModuleBuilder = new ContextModuleBuilder({\n ...defaultBuilderArgs,\n loggerFactory,\n });\n\n const res = contextModuleBuilder.build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.loggerFactory).toBe(loggerFactory);\n });\n\n it(\"should set the loggerFactory via setLoggerFactory\", () => {\n const loggerFactory: (tag: string) => LoggerPublisherService = vi.fn();\n\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n\n const res = contextModuleBuilder.setLoggerFactory(loggerFactory).build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.loggerFactory).toBe(loggerFactory);\n });\n\n it(\"should override constructor loggerFactory with setLoggerFactory\", () => {\n const constructorLoggerFactory: (tag: string) => LoggerPublisherService =\n vi.fn();\n const overrideLoggerFactory: (tag: string) => LoggerPublisherService =\n vi.fn();\n\n const contextModuleBuilder = new ContextModuleBuilder({\n ...defaultBuilderArgs,\n loggerFactory: constructorLoggerFactory,\n });\n\n const res = contextModuleBuilder\n .setLoggerFactory(overrideLoggerFactory)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(config.loggerFactory).toBe(overrideLoggerFactory);\n expect(config.loggerFactory).not.toBe(constructorLoggerFactory);\n });\n });\n\n describe(\"setTrustedNameDataSource\", () => {\n it(\"should set a custom trusted name data source\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customDataSource: TrustedNameDataSource = {\n getDomainNamePayload: vi.fn(),\n getTrustedNamePayload: vi.fn(),\n };\n\n const res = contextModuleBuilder\n .setTrustedNameDataSource(customDataSource)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.customTrustedNameDataSource).toBe(customDataSource);\n });\n\n it(\"should inject the custom data source into the container\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customDataSource: TrustedNameDataSource = {\n getDomainNamePayload: vi.fn(),\n getTrustedNamePayload: vi.fn(),\n };\n\n const res = contextModuleBuilder\n .setTrustedNameDataSource(customDataSource)\n .build();\n const injectedDataSource = (res as DefaultContextModule)[\n \"_container\"\n ].get<TrustedNameDataSource>(trustedNameTypes.TrustedNameDataSource);\n\n expect(injectedDataSource).toBe(customDataSource);\n });\n\n it(\"should use HttpTrustedNameDataSource when no custom data source is set\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n\n const res = contextModuleBuilder.build();\n const injectedDataSource = (res as DefaultContextModule)[\n \"_container\"\n ].get<TrustedNameDataSource>(trustedNameTypes.TrustedNameDataSource);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(injectedDataSource).toBeInstanceOf(HttpTrustedNameDataSource);\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "aAGA,IAAAA,EAA4B,mCAS5BC,EAA0C,yDAE1CC,EAAiC,8CACjCC,EAAqC,kCACrCC,EAAqC,kCAErC,SAAS,uBAAwB,IAAM,CACrC,MAAMC,EAA2C,CAC/C,IAAK,iBACL,KAAM,OACN,OAAQ,MACV,EACMC,EAA0B,CAC9B,IAAK,uBACP,EASMC,EAAmD,CACvD,YAAa,OACb,cAVwB,KAAO,CAC/B,MAAO,GAAG,GAAG,EACb,KAAM,GAAG,GAAG,E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AM,EAEP,WACA,IAAyB,cAAY,MAAM,EAE7C,OAAOR,EAAO,aAAa,EAAE,KAAKQ,CAAqB,EACvD,OAAOR,EAAO,aAAa,EAAE,IAAI,KAAKO,CAAwB,CAChE,CAAC,CACH,CAAC,EAED,SAAS,2BAA4B,IAAM,CACzC,GAAG,+CAAgD,IAAM,CACvD,MAAMT,EAAuB,IAAI,uBAAqBF,CAAkB,EAClEa,EAA0C,CAC9C,qBAAsB,GAAG,GAAG,EAC5B,sBAAuB,GAAG,GAAG,CAC/B,EAEMZ,EAAMC,EACT,yBAAyBW,CAAgB,EACzC,MAAM,EACHT,EAAUH,EACd,WACA,IAAyB,cAAY,MAAM,EAE7C,OAAOA,CAAG,EAAE,eAAe,sBAAoB,EAC/C,OAAOG,EAAO,2BAA2B,EAAE,KAAKS,CAAgB,CAClE,CAAC,EAED,GAAG,0DAA2D,IAAM,CAClE,MAAMX,EAAuB,IAAI,uBAAqBF,CAAkB,EAClEa,EAA0C,CAC9C,qBAAsB,GAAG,GAAG,EAC5B,sBAAuB,GAAG,GAAG,CAC/B,EAKMC,EAHMZ,EACT,yBAAyBW,CAAgB,EACzC,MAAM,EAEP,WACA,IAA2B,mBAAiB,qBAAqB,EAEnE,OAAOC,CAAkB,EAAE,KAAKD,CAAgB,CAClD,CAAC,EAED,GAAG,yEAA0E,IAAM,CAGjF,MAAMZ,EAFuB,IAAI,uBAAqBD,CAAkB,EAEvC,MAAM,EACjCc,EAAsBb,EAC1B,WACA,IAA2B,mBAAiB,qBAAqB,EAEnE,OAAOA,CAAG,EAAE,eAAe,sBAAoB,EAC/C,OAAOa,CAAkB,EAAE,eAAe,2BAAyB,CACrE,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["import_configTypes", "import_HttpTrustedNameDataSource", "import_trustedNameTypes", "import_ContextModuleBuilder", "import_DefaultContextModule", "defaultCalConfig", "defaultWeb3ChecksConfig", "defaultBuilderArgs", "res", "contextModuleBuilder", "customLoader", "config", "customMetadataConfig", "customCalConfig", "customWeb3ChecksConfig", "customDatasourceConfig", "logger", "loggerFactory", "constructorLoggerFactory", "overrideLoggerFactory", "customDataSource", "injectedDataSource"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/config/model/ContextModuleBuildArgs.ts"],
|
|
4
|
-
"sourcesContent": ["import { type LoggerPublisherService } from \"@ledgerhq/device-management-kit\";\n\nexport type ContextModuleConstructorArgs = {\n originToken?: string;\n loggerFactory
|
|
4
|
+
"sourcesContent": ["import { type LoggerPublisherService } from \"@ledgerhq/device-management-kit\";\n\nexport type ContextModuleConstructorArgs = {\n originToken?: string;\n loggerFactory?: (tag: string) => LoggerPublisherService;\n};\n"],
|
|
5
5
|
"mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
|
|
6
6
|
"names": ["ContextModuleBuildArgs_exports", "__toCommonJS"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var s=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var x=(a,e)=>{for(var r in e)s(a,r,{get:e[r],enumerable:!0})},I=(a,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of S(e))!T.call(a,o)&&o!==r&&s(a,o,{get:()=>e[o],enumerable:!(t=g(e,o))||t.enumerable});return a};var h=a=>I(s({},"__esModule",{value:!0}),a),u=(a,e,r,t)=>{for(var o=t>1?void 0:t?g(e,r):e,d=a.length-1,n;d>=0;d--)(n=a[d])&&(o=(t?n(e,r,o):n(o))||o);return t&&o&&s(e,r,o),o},l=(a,e)=>(r,t)=>e(r,t,a);var P={};x(P,{TrustedNameContextLoader:()=>c});module.exports=h(P);var p=require("@ledgerhq/device-management-kit"),i=require("inversify"),f=require("../../config/di/configTypes"),C=require("../../pki/di/pkiTypes"),m=require("../../shared/model/ClearSignContext"),y=require("../../trusted-name/di/trustedNameTypes");const v=[m.ClearSignContextType.TRUSTED_NAME];let c=class{constructor(e,r,t){this._dataSource=e;this._certificateLoader=r;this.logger=t("TrustedNameContextLoader")}logger;canHandle(e,r){return typeof e=="object"&&e!==null&&"chainId"in e&&e.chainId!==void 0&&typeof e.chainId=="number"&&"to"in e&&e.to!==void 0&&(0,p.isHexaString)(e.to)&&e.to!=="0x"&&"deviceModelId"in e&&e.deviceModelId!==void 0&&v.every(t=>r.includes(t))}async load(e){const r=await this._dataSource.getTrustedNamePayload({chainId:e.chainId,address:e.to,challenge:"",types:["eoa"],sources:["ens"]});return this.logger.debug("[ContextModule]: load result",{data:{payload:r}}),await r.caseOf({Left:t=>Promise.resolve([{type:m.ClearSignContextType.ERROR,error:t}]),Right:async({data:t,keyId:o,keyUsage:d})=>{const n=await this._certificateLoader.loadCertificate({keyId:o,keyUsage:d,targetDevice:e.deviceModelId});return[{type:m.ClearSignContextType.TRUSTED_NAME,payload:t,certificate:n}]}})}};c=u([(0,i.injectable)(),l(0,(0,i.inject)(y.trustedNameTypes.TrustedNameDataSource)),l(1,(0,i.inject)(C.pkiTypes.PkiCertificateLoader)),l(2,(0,i.inject)(f.configTypes.ContextModuleLoggerFactory))],c);0&&(module.exports={TrustedNameContextLoader});
|
|
2
2
|
//# sourceMappingURL=TrustedNameContextLoader.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/trusted-name/domain/TrustedNameContextLoader.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n DeviceModelId,\n LoggerPublisherService,\n} from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport type { TrustedNameDataSource } from \"@/trusted-name/data/TrustedNameDataSource\";\nimport { trustedNameTypes } from \"@/trusted-name/di/trustedNameTypes\";\n\nexport type TrustedNameContextInput = {\n chainId: number;\n
|
|
5
|
-
"mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,8BAAAE,IAAA,eAAAC,EAAAH,
|
|
6
|
-
"names": ["TrustedNameContextLoader_exports", "__export", "TrustedNameContextLoader", "__toCommonJS", "import_inversify", "import_configTypes", "import_pkiTypes", "import_ClearSignContext", "import_trustedNameTypes", "SUPPORTED_TYPES", "TrustedNameContextLoader", "
|
|
4
|
+
"sourcesContent": ["import {\n DeviceModelId,\n isHexaString,\n LoggerPublisherService,\n} from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport type { TrustedNameDataSource } from \"@/trusted-name/data/TrustedNameDataSource\";\nimport { trustedNameTypes } from \"@/trusted-name/di/trustedNameTypes\";\n\nexport type TrustedNameContextInput = {\n chainId: number;\n to: string;\n deviceModelId: DeviceModelId;\n};\n\nconst SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.TRUSTED_NAME,\n];\n\n@injectable()\nexport class TrustedNameContextLoader\n implements ContextLoader<TrustedNameContextInput>\n{\n private logger: LoggerPublisherService;\n\n constructor(\n @inject(trustedNameTypes.TrustedNameDataSource)\n private _dataSource: TrustedNameDataSource,\n @inject(pkiTypes.PkiCertificateLoader)\n private _certificateLoader: PkiCertificateLoader,\n @inject(configTypes.ContextModuleLoggerFactory)\n loggerFactory: (tag: string) => LoggerPublisherService,\n ) {\n this.logger = loggerFactory(\"TrustedNameContextLoader\");\n }\n\n canHandle(\n input: unknown,\n expectedTypes: ClearSignContextType[],\n ): input is TrustedNameContextInput {\n return (\n typeof input === \"object\" &&\n input !== null &&\n \"chainId\" in input &&\n input.chainId !== undefined &&\n typeof input.chainId === \"number\" &&\n \"to\" in input &&\n input.to !== undefined &&\n isHexaString(input.to) &&\n input.to !== \"0x\" &&\n \"deviceModelId\" in input &&\n input.deviceModelId !== undefined &&\n SUPPORTED_TYPES.every((type) => expectedTypes.includes(type))\n );\n }\n\n async load(input: TrustedNameContextInput): Promise<ClearSignContext[]> {\n const payload = await this._dataSource.getTrustedNamePayload({\n chainId: input.chainId,\n address: input.to,\n challenge: \"\", // use empty challenge for trusted name context loader as it will be re fetched during the provide step\n types: [\"eoa\"],\n sources: [\"ens\"],\n });\n\n this.logger.debug(\"[ContextModule]: load result\", { data: { payload } });\n\n return await payload.caseOf({\n Left: (error): Promise<ClearSignContext[]> =>\n Promise.resolve([{ type: ClearSignContextType.ERROR, error }]),\n Right: async ({ data, keyId, keyUsage }): Promise<ClearSignContext[]> => {\n const certificate = await this._certificateLoader.loadCertificate({\n keyId,\n keyUsage,\n targetDevice: input.deviceModelId,\n });\n return [\n {\n type: ClearSignContextType.TRUSTED_NAME,\n payload: data,\n certificate,\n },\n ];\n },\n });\n }\n}\n"],
|
|
5
|
+
"mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,8BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAIO,2CACPC,EAAmC,qBAEnCC,EAA4B,mCAC5BC,EAAyB,6BAGzBC,EAGO,2CAEPC,EAAiC,8CAQjC,MAAMC,EAA0C,CAC9C,uBAAqB,YACvB,EAGO,IAAMC,EAAN,KAEP,CAGE,YAEUC,EAEAC,EAERC,EACA,CALQ,iBAAAF,EAEA,wBAAAC,EAIR,KAAK,OAASC,EAAc,0BAA0B,CACxD,CAXQ,OAaR,UACEC,EACAC,EACkC,CAClC,OACE,OAAOD,GAAU,UACjBA,IAAU,MACV,YAAaA,GACbA,EAAM,UAAY,QAClB,OAAOA,EAAM,SAAY,UACzB,OAAQA,GACRA,EAAM,KAAO,WACb,gBAAaA,EAAM,EAAE,GACrBA,EAAM,KAAO,MACb,kBAAmBA,GACnBA,EAAM,gBAAkB,QACxBL,EAAgB,MAAOO,GAASD,EAAc,SAASC,CAAI,CAAC,CAEhE,CAEA,MAAM,KAAKF,EAA6D,CACtE,MAAMG,EAAU,MAAM,KAAK,YAAY,sBAAsB,CAC3D,QAASH,EAAM,QACf,QAASA,EAAM,GACf,UAAW,GACX,MAAO,CAAC,KAAK,EACb,QAAS,CAAC,KAAK,CACjB,CAAC,EAED,YAAK,OAAO,MAAM,+BAAgC,CAAE,KAAM,CAAE,QAAAG,CAAQ,CAAE,CAAC,EAEhE,MAAMA,EAAQ,OAAO,CAC1B,KAAOC,GACL,QAAQ,QAAQ,CAAC,CAAE,KAAM,uBAAqB,MAAO,MAAAA,CAAM,CAAC,CAAC,EAC/D,MAAO,MAAO,CAAE,KAAAC,EAAM,MAAAC,EAAO,SAAAC,CAAS,IAAmC,CACvE,MAAMC,EAAc,MAAM,KAAK,mBAAmB,gBAAgB,CAChE,MAAAF,EACA,SAAAC,EACA,aAAcP,EAAM,aACtB,CAAC,EACD,MAAO,CACL,CACE,KAAM,uBAAqB,aAC3B,QAASK,EACT,YAAAG,CACF,CACF,CACF,CACF,CAAC,CACH,CACF,EAlEaZ,EAANa,EAAA,IADN,cAAW,EAOPC,EAAA,eAAO,mBAAiB,qBAAqB,GAE7CA,EAAA,eAAO,WAAS,oBAAoB,GAEpCA,EAAA,eAAO,cAAY,0BAA0B,IAVrCd",
|
|
6
|
+
"names": ["TrustedNameContextLoader_exports", "__export", "TrustedNameContextLoader", "__toCommonJS", "import_device_management_kit", "import_inversify", "import_configTypes", "import_pkiTypes", "import_ClearSignContext", "import_trustedNameTypes", "SUPPORTED_TYPES", "TrustedNameContextLoader", "_dataSource", "_certificateLoader", "loggerFactory", "input", "expectedTypes", "type", "payload", "error", "data", "keyId", "keyUsage", "certificate", "__decorateClass", "__decorateParam"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var d=require("@ledgerhq/device-management-kit"),r=require("purify-ts"),a=require("../../shared/model/ClearSignContext"),l=require("../../trusted-name/domain/TrustedNameContextLoader");const u=()=>({debug:vi.fn(),info:vi.fn(),warn:vi.fn(),error:vi.fn(),subscribers:[]});describe("TrustedNameContextLoader",()=>{const n={getDomainNamePayload:vi.fn(),getTrustedNamePayload:vi.fn()},i={loadCertificate:vi.fn()},o=new l.TrustedNameContextLoader(n,i,u),c={keyUsageNumber:1,payload:new Uint8Array([1,2,3,4])};beforeEach(()=>{vi.restoreAllMocks(),vi.spyOn(n,"getTrustedNamePayload").mockResolvedValue((0,r.Right)({data:"payload",keyId:"testKeyId",keyUsage:"testKeyUsage"}))}),describe("canHandle function",()=>{const e={chainId:1,to:"0x1234567890abcdef1234567890abcdef12345678",deviceModelId:d.DeviceModelId.STAX};it("should return true for valid input",()=>{expect(o.canHandle(e,[a.ClearSignContextType.TRUSTED_NAME])).toBe(!0)}),it("should return false for invalid expected type",()=>{expect(o.canHandle(e,[a.ClearSignContextType.TOKEN])).toBe(!1)}),it.each([[null,"null input"],[void 0,"undefined input"],[{},"empty object"],["string","string input"],[123,"number input"]])("should return false for %s",(t,s)=>{expect(o.canHandle(t,[a.ClearSignContextType.TRUSTED_NAME])).toBe(!1)}),it.each([[{...e,chainId:void 0},"missing chainId"],[{...e,to:void 0},"missing to"],[{...e,deviceModelId:void 0},"missing device model"]])("should return false for %s",(t,s)=>{expect(o.canHandle(t,[a.ClearSignContextType.TRUSTED_NAME])).toBe(!1)}),it.each([[{...e,to:"0x"},"empty to address (0x)"],[{...e,to:"not-hex"},"non-hex to address"],[{...e,chainId:"1"},"string chainId"],[{...e,chainId:null},"null chainId"]])("should return false for %s",(t,s)=>{expect(o.canHandle(t,[a.ClearSignContextType.TRUSTED_NAME])).toBe(!1)})}),describe("load function",()=>{it("should return a payload",async()=>{vi.spyOn(i,"loadCertificate").mockResolvedValue(c);const e={chainId:1,to:"0x1234567890abcdef1234567890abcdef12345678",deviceModelId:d.DeviceModelId.STAX},t=await o.load(e);expect(n.getTrustedNamePayload).toHaveBeenCalledWith({chainId:1,address:"0x1234567890abcdef1234567890abcdef12345678",challenge:"",types:["eoa"],sources:["ens"]}),expect(i.loadCertificate).toHaveBeenCalledWith({keyId:"testKeyId",keyUsage:"testKeyUsage",targetDevice:d.DeviceModelId.STAX}),expect(t).toEqual([{type:a.ClearSignContextType.TRUSTED_NAME,payload:"payload",certificate:c}])}),it("should return an error when unable to fetch the datasource",async()=>{const e={chainId:1,to:"0x1234567890abcdef1234567890abcdef12345678",deviceModelId:d.DeviceModelId.STAX};vi.spyOn(n,"getTrustedNamePayload").mockResolvedValue((0,r.Left)(new Error("error")));const t=await o.load(e);expect(t).toEqual([{type:a.ClearSignContextType.ERROR,error:new Error("error")}])})})});
|
|
2
2
|
//# sourceMappingURL=TrustedNameContextLoader.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/trusted-name/domain/TrustedNameContextLoader.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { type PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport { type TrustedNameDataSource } from \"@/trusted-name/data/TrustedNameDataSource\";\nimport {\n type TrustedNameContextInput,\n TrustedNameContextLoader,\n} from \"@/trusted-name/domain/TrustedNameContextLoader\";\n\nconst mockLoggerFactory = () => ({\n debug: vi.fn(),\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n subscribers: [],\n});\n\ndescribe(\"TrustedNameContextLoader\", () => {\n const mockTrustedNameDataSource: TrustedNameDataSource = {\n getDomainNamePayload: vi.fn(),\n getTrustedNamePayload: vi.fn(),\n };\n const mockCertificateLoader: PkiCertificateLoader = {\n loadCertificate: vi.fn(),\n };\n const loader = new TrustedNameContextLoader(\n mockTrustedNameDataSource,\n mockCertificateLoader,\n mockLoggerFactory,\n );\n\n const mockCertificate: PkiCertificate = {\n keyUsageNumber: 1,\n payload: new Uint8Array([1, 2, 3, 4]),\n };\n\n beforeEach(() => {\n vi.restoreAllMocks();\n vi.spyOn(\n mockTrustedNameDataSource,\n \"
|
|
5
|
-
"mappings": "aAAA,IAAAA,EAA8B,2CAC9BC,EAA4B,qBAI5BC,EAAqC,2CAErCC,EAGO,0DAEP,MAAMC,EAAoB,KAAO,CAC/B,MAAO,GAAG,GAAG,EACb,KAAM,GAAG,GAAG,EACZ,KAAM,GAAG,GAAG,EACZ,MAAO,GAAG,GAAG,EACb,YAAa,CAAC,CAChB,GAEA,SAAS,2BAA4B,IAAM,CACzC,MAAMC,EAAmD,CACvD,qBAAsB,GAAG,GAAG,EAC5B,sBAAuB,GAAG,GAAG,CAC/B,EACMC,EAA8C,CAClD,gBAAiB,GAAG,GAAG,CACzB,EACMC,EAAS,IAAI,2BACjBF,EACAC,EACAF,CACF,EAEMI,EAAkC,CACtC,eAAgB,EAChB,QAAS,IAAI,WAAW,CAAC,EAAG,EAAG,EAAG,CAAC,CAAC,CACtC,EAEA,WAAW,IAAM,CACf,GAAG,gBAAgB,EACnB,GAAG,MACDH,EACA,
|
|
4
|
+
"sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { type PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport { type TrustedNameDataSource } from \"@/trusted-name/data/TrustedNameDataSource\";\nimport {\n type TrustedNameContextInput,\n TrustedNameContextLoader,\n} from \"@/trusted-name/domain/TrustedNameContextLoader\";\n\nconst mockLoggerFactory = () => ({\n debug: vi.fn(),\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n subscribers: [],\n});\n\ndescribe(\"TrustedNameContextLoader\", () => {\n const mockTrustedNameDataSource: TrustedNameDataSource = {\n getDomainNamePayload: vi.fn(),\n getTrustedNamePayload: vi.fn(),\n };\n const mockCertificateLoader: PkiCertificateLoader = {\n loadCertificate: vi.fn(),\n };\n const loader = new TrustedNameContextLoader(\n mockTrustedNameDataSource,\n mockCertificateLoader,\n mockLoggerFactory,\n );\n\n const mockCertificate: PkiCertificate = {\n keyUsageNumber: 1,\n payload: new Uint8Array([1, 2, 3, 4]),\n };\n\n beforeEach(() => {\n vi.restoreAllMocks();\n vi.spyOn(\n mockTrustedNameDataSource,\n \"getTrustedNamePayload\",\n ).mockResolvedValue(\n Right({\n data: \"payload\",\n keyId: \"testKeyId\",\n keyUsage: \"testKeyUsage\",\n }),\n );\n });\n\n describe(\"canHandle function\", () => {\n const validInput: TrustedNameContextInput = {\n chainId: 1,\n to: \"0x1234567890abcdef1234567890abcdef12345678\",\n deviceModelId: DeviceModelId.STAX,\n };\n\n it(\"should return true for valid input\", () => {\n expect(\n loader.canHandle(validInput, [ClearSignContextType.TRUSTED_NAME]),\n ).toBe(true);\n });\n\n it(\"should return false for invalid expected type\", () => {\n expect(loader.canHandle(validInput, [ClearSignContextType.TOKEN])).toBe(\n false,\n );\n });\n\n it.each([\n [null, \"null input\"],\n [undefined, \"undefined input\"],\n [{}, \"empty object\"],\n [\"string\", \"string input\"],\n [123, \"number input\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, [ClearSignContextType.TRUSTED_NAME])).toBe(\n false,\n );\n });\n\n it.each([\n [{ ...validInput, chainId: undefined }, \"missing chainId\"],\n [{ ...validInput, to: undefined }, \"missing to\"],\n [{ ...validInput, deviceModelId: undefined }, \"missing device model\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, [ClearSignContextType.TRUSTED_NAME])).toBe(\n false,\n );\n });\n\n it.each([\n [{ ...validInput, to: \"0x\" }, \"empty to address (0x)\"],\n [{ ...validInput, to: \"not-hex\" }, \"non-hex to address\"],\n [{ ...validInput, chainId: \"1\" }, \"string chainId\"],\n [{ ...validInput, chainId: null }, \"null chainId\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, [ClearSignContextType.TRUSTED_NAME])).toBe(\n false,\n );\n });\n });\n\n describe(\"load function\", () => {\n it(\"should return a payload\", async () => {\n vi.spyOn(mockCertificateLoader, \"loadCertificate\").mockResolvedValue(\n mockCertificate,\n );\n const input: TrustedNameContextInput = {\n chainId: 1,\n to: \"0x1234567890abcdef1234567890abcdef12345678\",\n deviceModelId: DeviceModelId.STAX,\n };\n\n const result = await loader.load(input);\n\n expect(\n mockTrustedNameDataSource.getTrustedNamePayload,\n ).toHaveBeenCalledWith({\n chainId: 1,\n address: \"0x1234567890abcdef1234567890abcdef12345678\",\n challenge: \"\",\n types: [\"eoa\"],\n sources: [\"ens\"],\n });\n expect(mockCertificateLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: \"testKeyId\",\n keyUsage: \"testKeyUsage\",\n targetDevice: DeviceModelId.STAX,\n });\n expect(result).toEqual([\n {\n type: ClearSignContextType.TRUSTED_NAME,\n payload: \"payload\",\n certificate: mockCertificate,\n },\n ]);\n });\n\n it(\"should return an error when unable to fetch the datasource\", async () => {\n // GIVEN\n const input: TrustedNameContextInput = {\n chainId: 1,\n to: \"0x1234567890abcdef1234567890abcdef12345678\",\n deviceModelId: DeviceModelId.STAX,\n };\n\n // WHEN\n vi.spyOn(\n mockTrustedNameDataSource,\n \"getTrustedNamePayload\",\n ).mockResolvedValue(Left(new Error(\"error\")));\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n { type: ClearSignContextType.ERROR, error: new Error(\"error\") },\n ]);\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "aAAA,IAAAA,EAA8B,2CAC9BC,EAA4B,qBAI5BC,EAAqC,2CAErCC,EAGO,0DAEP,MAAMC,EAAoB,KAAO,CAC/B,MAAO,GAAG,GAAG,EACb,KAAM,GAAG,GAAG,EACZ,KAAM,GAAG,GAAG,EACZ,MAAO,GAAG,GAAG,EACb,YAAa,CAAC,CAChB,GAEA,SAAS,2BAA4B,IAAM,CACzC,MAAMC,EAAmD,CACvD,qBAAsB,GAAG,GAAG,EAC5B,sBAAuB,GAAG,GAAG,CAC/B,EACMC,EAA8C,CAClD,gBAAiB,GAAG,GAAG,CACzB,EACMC,EAAS,IAAI,2BACjBF,EACAC,EACAF,CACF,EAEMI,EAAkC,CACtC,eAAgB,EAChB,QAAS,IAAI,WAAW,CAAC,EAAG,EAAG,EAAG,CAAC,CAAC,CACtC,EAEA,WAAW,IAAM,CACf,GAAG,gBAAgB,EACnB,GAAG,MACDH,EACA,uBACF,EAAE,qBACA,SAAM,CACJ,KAAM,UACN,MAAO,YACP,SAAU,cACZ,CAAC,CACH,CACF,CAAC,EAED,SAAS,qBAAsB,IAAM,CACnC,MAAMI,EAAsC,CAC1C,QAAS,EACT,GAAI,6CACJ,cAAe,gBAAc,IAC/B,EAEA,GAAG,qCAAsC,IAAM,CAC7C,OACEF,EAAO,UAAUE,EAAY,CAAC,uBAAqB,YAAY,CAAC,CAClE,EAAE,KAAK,EAAI,CACb,CAAC,EAED,GAAG,gDAAiD,IAAM,CACxD,OAAOF,EAAO,UAAUE,EAAY,CAAC,uBAAqB,KAAK,CAAC,CAAC,EAAE,KACjE,EACF,CACF,CAAC,EAED,GAAG,KAAK,CACN,CAAC,KAAM,YAAY,EACnB,CAAC,OAAW,iBAAiB,EAC7B,CAAC,CAAC,EAAG,cAAc,EACnB,CAAC,SAAU,cAAc,EACzB,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,EACD,OAAOC,EAAsB,eAAe,EAAE,qBAAqB,CACjE,MAAO,YACP,SAAU,eACV,aAAc,gBAAc,IAC9B,CAAC,EACD,OAAOM,CAAM,EAAE,QAAQ,CACrB,CACE,KAAM,uBAAqB,aAC3B,QAAS,UACT,YAAaJ,CACf,CACF,CAAC,CACH,CAAC,EAED,GAAG,6DAA8D,SAAY,CAE3E,MAAME,EAAiC,CACrC,QAAS,EACT,GAAI,6CACJ,cAAe,gBAAc,IAC/B,EAGA,GAAG,MACDL,EACA,uBACF,EAAE,qBAAkB,QAAK,IAAI,MAAM,OAAO,CAAC,CAAC,EAC5C,MAAMO,EAAS,MAAML,EAAO,KAAKG,CAAK,EAGtC,OAAOE,CAAM,EAAE,QAAQ,CACrB,CAAE,KAAM,uBAAqB,MAAO,MAAO,IAAI,MAAM,OAAO,CAAE,CAChE,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
6
|
"names": ["import_device_management_kit", "import_purify_ts", "import_ClearSignContext", "import_TrustedNameContextLoader", "mockLoggerFactory", "mockTrustedNameDataSource", "mockCertificateLoader", "loader", "mockCertificate", "validInput", "input", "_description", "result"]
|
|
7
7
|
}
|
package/lib/esm/package.json
CHANGED
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"watch:builds": "pnpm ldmk-tool watch --entryPoints index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
|
|
59
59
|
"watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\""
|
|
60
60
|
},
|
|
61
|
-
"version": "0.0.0-develop-
|
|
61
|
+
"version": "0.0.0-develop-20260206001140"
|
|
62
62
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{DefaultContextModule as
|
|
1
|
+
import{DefaultContextModule as a}from"./DefaultContextModule";const i=r=>({debug:()=>{},info:()=>{},warn:()=>{},error:()=>{},subscribers:[]}),n="https://crypto-assets-service.api.ledger.com/v1",s="https://web3checks-backend.api.ledger.com/v3",c="https://nft.api.live.ledger.com",t={cal:{url:n,mode:"prod",branch:"main"},web3checks:{url:s},metadataServiceDomain:{url:c},defaultLoaders:!0,customLoaders:[],defaultFieldLoaders:!0,customFieldLoaders:[],customTypedDataLoader:void 0,customSolanaLoader:void 0,loggerFactory:i};class u{config;originToken;constructor({originToken:e,loggerFactory:o}){this.originToken=e,this.config={...t,cal:{...t.cal},web3checks:{...t.web3checks},metadataServiceDomain:{...t.metadataServiceDomain},customLoaders:[...t.customLoaders],customFieldLoaders:[...t.customFieldLoaders]},o&&(this.config.loggerFactory=o)}removeDefaultLoaders(){return this.config.defaultLoaders=!1,this}addLoader(e){return this.config.customLoaders.push(e),this}addTypedDataLoader(e){return this.config.customTypedDataLoader=e,this}addSolanaLoader(e){return this.config.customSolanaLoader=e,this}setCalConfig(e){return this.config.cal=e,this}setMetadataServiceConfig(e){return this.config.metadataServiceDomain=e,this}setWeb3ChecksConfig(e){return this.config.web3checks=e,this}setDatasourceConfig(e){return this.config.datasource=e,this}setTrustedNameDataSource(e){return this.config.customTrustedNameDataSource=e,this}setLoggerFactory(e){return this.config.loggerFactory=e,this}build(){const e={...this.config,originToken:this.originToken};return new a(e)}}export{u as ContextModuleBuilder,t as DEFAULT_CONFIG};
|
|
2
2
|
//# sourceMappingURL=ContextModuleBuilder.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/ContextModuleBuilder.ts"],
|
|
4
|
-
"sourcesContent": ["import { type LoggerPublisherService } from \"@ledgerhq/device-management-kit\";\n\nimport { type ContextModuleConstructorArgs } from \"./config/model/ContextModuleBuildArgs\";\nimport {\n type ContextModuleCalConfig,\n type ContextModuleConfig,\n type ContextModuleDatasourceConfig,\n type ContextModuleMetadataServiceConfig,\n type ContextModuleWeb3ChecksConfig,\n} from \"./config/model/ContextModuleConfig\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport { type SolanaContextLoader } from \"./solana/domain/SolanaContextLoader\";\nimport { type TrustedNameDataSource } from \"./trusted-name/data/TrustedNameDataSource\";\nimport { type TypedDataContextLoader } from \"./typed-data/domain/TypedDataContextLoader\";\nimport { type ContextModule } from \"./ContextModule\";\nimport { DefaultContextModule } from \"./DefaultContextModule\";\n\nconst DEFAULT_CAL_URL = \"https://crypto-assets-service.api.ledger.com/v1\";\nconst DEFAULT_WEB3_CHECKS_URL = \"https://web3checks-backend.api.ledger.com/v3\";\nconst DEFAULT_METADATA_SERVICE_DOMAIN = \"https://nft.api.live.ledger.com\";\n\nexport class ContextModuleBuilder {\n private config: ContextModuleConfig;\n private originToken?: string;\n\n constructor({ originToken, loggerFactory }: ContextModuleConstructorArgs) {\n this.originToken = originToken;\n\n this.config = {\n cal: {
|
|
5
|
-
"mappings": "AAeA,OAAS,wBAAAA,MAA4B,yBAErC,MAAMC,
|
|
6
|
-
"names": ["DefaultContextModule", "DEFAULT_CAL_URL", "DEFAULT_WEB3_CHECKS_URL", "DEFAULT_METADATA_SERVICE_DOMAIN", "ContextModuleBuilder", "originToken", "loggerFactory", "loader", "calConfig", "metadataServiceConfig", "web3ChecksConfig", "datasourceConfig", "dataSource", "config"]
|
|
4
|
+
"sourcesContent": ["import { type LoggerPublisherService } from \"@ledgerhq/device-management-kit\";\n\nimport { type ContextModuleConstructorArgs } from \"./config/model/ContextModuleBuildArgs\";\nimport {\n type ContextModuleCalConfig,\n type ContextModuleConfig,\n type ContextModuleDatasourceConfig,\n type ContextModuleMetadataServiceConfig,\n type ContextModuleWeb3ChecksConfig,\n} from \"./config/model/ContextModuleConfig\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport { type SolanaContextLoader } from \"./solana/domain/SolanaContextLoader\";\nimport { type TrustedNameDataSource } from \"./trusted-name/data/TrustedNameDataSource\";\nimport { type TypedDataContextLoader } from \"./typed-data/domain/TypedDataContextLoader\";\nimport { type ContextModule } from \"./ContextModule\";\nimport { DefaultContextModule } from \"./DefaultContextModule\";\n\nconst emptyLoggerFactory = (_tag: string): LoggerPublisherService => ({\n debug: () => {},\n info: () => {},\n warn: () => {},\n error: () => {},\n subscribers: [],\n});\n\nconst DEFAULT_CAL_URL = \"https://crypto-assets-service.api.ledger.com/v1\";\nconst DEFAULT_WEB3_CHECKS_URL = \"https://web3checks-backend.api.ledger.com/v3\";\nconst DEFAULT_METADATA_SERVICE_DOMAIN = \"https://nft.api.live.ledger.com\";\n\nexport const DEFAULT_CONFIG: ContextModuleConfig = {\n cal: {\n url: DEFAULT_CAL_URL,\n mode: \"prod\",\n branch: \"main\",\n },\n web3checks: {\n url: DEFAULT_WEB3_CHECKS_URL,\n },\n metadataServiceDomain: {\n url: DEFAULT_METADATA_SERVICE_DOMAIN,\n },\n defaultLoaders: true,\n customLoaders: [],\n defaultFieldLoaders: true,\n customFieldLoaders: [],\n customTypedDataLoader: undefined,\n customSolanaLoader: undefined,\n loggerFactory: emptyLoggerFactory,\n};\n\nexport class ContextModuleBuilder {\n private config: ContextModuleConfig;\n private originToken?: string;\n\n constructor({ originToken, loggerFactory }: ContextModuleConstructorArgs) {\n this.originToken = originToken;\n\n this.config = {\n ...DEFAULT_CONFIG,\n cal: { ...DEFAULT_CONFIG.cal },\n web3checks: { ...DEFAULT_CONFIG.web3checks },\n metadataServiceDomain: { ...DEFAULT_CONFIG.metadataServiceDomain },\n customLoaders: [...DEFAULT_CONFIG.customLoaders],\n customFieldLoaders: [...DEFAULT_CONFIG.customFieldLoaders],\n };\n if (loggerFactory) {\n this.config.loggerFactory = loggerFactory;\n }\n }\n\n /**\n * Remove default loaders from the list of loaders\n *\n * @returns this\n */\n removeDefaultLoaders() {\n this.config.defaultLoaders = false;\n return this;\n }\n\n /**\n * Add a custom loader to the list of loaders\n *\n * @param loader loader to add to the list of loaders\n * @returns this\n */\n addLoader(loader: ContextLoader) {\n this.config.customLoaders.push(loader);\n return this;\n }\n\n /**\n * Replace the default loader for typed data clear signing contexts\n *\n * @param loader loader to use for typed data clear signing contexts\n * @returns this\n */\n addTypedDataLoader(loader: TypedDataContextLoader) {\n this.config.customTypedDataLoader = loader;\n return this;\n }\n\n /**\n * Replace the default loader for Solana context\n *\n * @param loader loader to use for Solana context\n * @returns this\n */\n addSolanaLoader(loader: SolanaContextLoader) {\n this.config.customSolanaLoader = loader;\n return this;\n }\n\n /**\n * Add a custom CAL configuration\n *\n * @param calConfig\n * @returns this\n */\n setCalConfig(calConfig: ContextModuleCalConfig) {\n this.config.cal = calConfig;\n return this;\n }\n\n /**\n * Add a custom metadata service configuration\n *\n * @param metadataServiceConfig\n * @returns this\n */\n setMetadataServiceConfig(\n metadataServiceConfig: ContextModuleMetadataServiceConfig,\n ) {\n this.config.metadataServiceDomain = metadataServiceConfig;\n return this;\n }\n\n /**\n * Add a custom web3 checks configuration\n *\n * @param web3ChecksConfig\n * @returns this\n */\n setWeb3ChecksConfig(web3ChecksConfig: ContextModuleWeb3ChecksConfig) {\n this.config.web3checks = web3ChecksConfig;\n return this;\n }\n\n /**\n * Add datasource configuration\n *\n * @param datasourceConfig\n * @returns this\n */\n setDatasourceConfig(datasourceConfig: ContextModuleDatasourceConfig) {\n this.config.datasource = datasourceConfig;\n return this;\n }\n\n /**\n * Set a custom trusted name data source\n *\n * @param dataSource data source to use for trusted name resolution\n * @returns this\n */\n setTrustedNameDataSource(dataSource: TrustedNameDataSource) {\n this.config.customTrustedNameDataSource = dataSource;\n return this;\n }\n\n /**\n * Set a custom logger factory\n *\n * @param loggerFactory\n * @returns this\n */\n setLoggerFactory(loggerFactory: (tag: string) => LoggerPublisherService) {\n this.config.loggerFactory = loggerFactory;\n return this;\n }\n\n /**\n * Build the context module\n *\n * @returns the context module\n */\n build(): ContextModule {\n const config = { ...this.config, originToken: this.originToken };\n return new DefaultContextModule(config);\n }\n}\n"],
|
|
5
|
+
"mappings": "AAeA,OAAS,wBAAAA,MAA4B,yBAErC,MAAMC,EAAsBC,IAA0C,CACpE,MAAO,IAAM,CAAC,EACd,KAAM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,yBAAyBC,EAAmC,CAC1D,YAAK,OAAO,4BAA8BA,EACnC,IACT,CAQA,iBAAiBN,EAAwD,CACvE,YAAK,OAAO,cAAgBA,EACrB,IACT,CAOA,OAAuB,CACrB,MAAMO,EAAS,CAAE,GAAG,KAAK,OAAQ,YAAa,KAAK,WAAY,EAC/D,OAAO,IAAIhB,EAAqBgB,CAAM,CACxC,CACF",
|
|
6
|
+
"names": ["DefaultContextModule", "emptyLoggerFactory", "_tag", "DEFAULT_CAL_URL", "DEFAULT_WEB3_CHECKS_URL", "DEFAULT_METADATA_SERVICE_DOMAIN", "DEFAULT_CONFIG", "ContextModuleBuilder", "originToken", "loggerFactory", "loader", "calConfig", "metadataServiceConfig", "web3ChecksConfig", "datasourceConfig", "dataSource", "config"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{configTypes as
|
|
1
|
+
import{configTypes as a}from"./config/di/configTypes";import{HttpTrustedNameDataSource as g}from"./trusted-name/data/HttpTrustedNameDataSource";import{trustedNameTypes as l}from"./trusted-name/di/trustedNameTypes";import{ContextModuleBuilder as c}from"./ContextModuleBuilder";import{DefaultContextModule as s}from"./DefaultContextModule";describe("ContextModuleBuilder",()=>{const u={url:"https://cal/v1",mode:"prod",branch:"main"},i={url:"https://web3checks/v1"},r={originToken:"test",loggerFactory:()=>({debug:vi.fn(),info:vi.fn(),warn:vi.fn(),error:vi.fn(),subscribers:[]})};beforeEach(()=>{vi.resetAllMocks()}),it("should return a default context module",()=>{const e=new c(r).build();expect(e).toBeInstanceOf(s)}),it("should return a custom context module",()=>{const n=new c(r),e={load:vi.fn(),canHandle:vi.fn()},o=n.removeDefaultLoaders().addLoader(e).build();expect(o).toBeInstanceOf(s)}),it("should return a custom context module with a custom typed data loader",()=>{const n=new c(r),e={load:vi.fn()},o=n.removeDefaultLoaders().addTypedDataLoader(e).build();expect(o).toBeInstanceOf(s),expect(o._typedDataLoader).toBe(e)}),it("should return a custom context module with a custom config",()=>{const e=new c(r).setCalConfig(u).setWeb3ChecksConfig(i).build(),o=e._container.get(a.Config);expect(e).toBeInstanceOf(s),expect(o.cal).toEqual(u),expect(o.web3checks).toEqual(i)}),it("should not throw an error if origin token is provided",()=>{const n=new c(r);expect(()=>n.build()).not.toThrow()}),describe("setMetadataServiceConfig",()=>{it("should set the metadata service configuration",()=>{const n=new c(r),e={url:"https://custom-metadata-service.com/v3"},o=n.setMetadataServiceConfig(e).build(),t=o._container.get(a.Config);expect(o).toBeInstanceOf(s),expect(t.metadataServiceDomain).toEqual(e)}),it("should override the default metadata service configuration",()=>{const n=new c(r),e={url:"https://override-metadata-service.com/v1"},t=n.setMetadataServiceConfig(e).build()._container.get(a.Config);expect(t.metadataServiceDomain.url).toBe(e.url),expect(t.metadataServiceDomain.url).not.toBe("https://nft.api.live.ledger.com/v2")})}),describe("setCalConfig",()=>{it("should set the CAL configuration",()=>{const n=new c(r),e={url:"https://custom-cal-service.com/v2",mode:"test",branch:"next"},o=n.setCalConfig(e).build(),t=o._container.get(a.Config);expect(o).toBeInstanceOf(s),expect(t.cal).toEqual(e)}),it("should override the default CAL configuration",()=>{const n=new c(r),e={url:"https://override-cal-service.com/v1",mode:"prod",branch:"demo"},t=n.setCalConfig(e).build()._container.get(a.Config);expect(t.cal.url).toBe(e.url),expect(t.cal.mode).toBe(e.mode),expect(t.cal.branch).toBe(e.branch),expect(t.cal.url).not.toBe("https://crypto-assets-service.api.ledger.com/v1")})}),describe("setWeb3ChecksConfig",()=>{it("should set the web3 checks configuration",()=>{const n=new c(r),e={url:"https://custom-web3checks-service.com/v4"},o=n.setWeb3ChecksConfig(e).build(),t=o._container.get(a.Config);expect(o).toBeInstanceOf(s),expect(t.web3checks).toEqual(e)}),it("should override the default web3 checks configuration",()=>{const n=new c(r),e={url:"https://override-web3checks-service.com/v2"},t=n.setWeb3ChecksConfig(e).build()._container.get(a.Config);expect(t.web3checks.url).toBe(e.url),expect(t.web3checks.url).not.toBe("https://web3checks-backend.api.ledger.com/v3")})}),describe("setDatasourceConfig",()=>{it("should set the datasource configuration with safe proxy",()=>{const n=new c(r),e={proxy:"safe"},o=n.setDatasourceConfig(e).build(),t=o._container.get(a.Config);expect(o).toBeInstanceOf(s),expect(t.datasource).toEqual(e),expect(t.datasource?.proxy).toBe("safe")}),it("should set the datasource configuration with default proxy",()=>{const n=new c(r),e={proxy:"default"},o=n.setDatasourceConfig(e).build(),t=o._container.get(a.Config);expect(o).toBeInstanceOf(s),expect(t.datasource).toEqual(e),expect(t.datasource?.proxy).toBe("default")}),it("should override the default datasource configuration",()=>{const n=new c(r),e={proxy:"safe"},t=n.setDatasourceConfig(e).build()._container.get(a.Config);expect(t.datasource?.proxy).toBe("safe"),expect(t.datasource).not.toBeUndefined()}),it("should set an empty datasource configuration",()=>{const n=new c(r),e={},o=n.setDatasourceConfig(e).build(),t=o._container.get(a.Config);expect(o).toBeInstanceOf(s),expect(t.datasource).toEqual(e),expect(t.datasource?.proxy).toBeUndefined()})}),describe("loggerFactory",()=>{it("should use the default empty logger when loggerFactory is not provided",()=>{const e=new c({originToken:"test"}).build(),o=e._container.get(a.Config);expect(e).toBeInstanceOf(s),expect(o.loggerFactory).toBeDefined();const t=o.loggerFactory("test");expect(t.debug).toBeDefined(),expect(t.info).toBeDefined(),expect(t.warn).toBeDefined(),expect(t.error).toBeDefined(),expect(t.subscribers).toEqual([]),expect(()=>t.debug("test")).not.toThrow(),expect(()=>t.info("test")).not.toThrow(),expect(()=>t.warn("test")).not.toThrow(),expect(()=>t.error("test")).not.toThrow()}),it("should set the loggerFactory when provided in the constructor",()=>{const n=vi.fn(),o=new c({...r,loggerFactory:n}).build(),t=o._container.get(a.Config);expect(o).toBeInstanceOf(s),expect(t.loggerFactory).toBe(n)}),it("should set the loggerFactory via setLoggerFactory",()=>{const n=vi.fn(),o=new c(r).setLoggerFactory(n).build(),t=o._container.get(a.Config);expect(o).toBeInstanceOf(s),expect(t.loggerFactory).toBe(n)}),it("should override constructor loggerFactory with setLoggerFactory",()=>{const n=vi.fn(),e=vi.fn(),d=new c({...r,loggerFactory:n}).setLoggerFactory(e).build()._container.get(a.Config);expect(d.loggerFactory).toBe(e),expect(d.loggerFactory).not.toBe(n)})}),describe("setTrustedNameDataSource",()=>{it("should set a custom trusted name data source",()=>{const n=new c(r),e={getDomainNamePayload:vi.fn(),getTrustedNamePayload:vi.fn()},o=n.setTrustedNameDataSource(e).build(),t=o._container.get(a.Config);expect(o).toBeInstanceOf(s),expect(t.customTrustedNameDataSource).toBe(e)}),it("should inject the custom data source into the container",()=>{const n=new c(r),e={getDomainNamePayload:vi.fn(),getTrustedNamePayload:vi.fn()},t=n.setTrustedNameDataSource(e).build()._container.get(l.TrustedNameDataSource);expect(t).toBe(e)}),it("should use HttpTrustedNameDataSource when no custom data source is set",()=>{const e=new c(r).build(),o=e._container.get(l.TrustedNameDataSource);expect(e).toBeInstanceOf(s),expect(o).toBeInstanceOf(g)})})});
|
|
2
2
|
//# sourceMappingURL=ContextModuleBuilder.test.js.map
|