@ledgerhq/context-module 1.13.0 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/dynamic-network/data/HttpDynamicNetworkDataSource.js +1 -1
- package/lib/cjs/src/dynamic-network/data/HttpDynamicNetworkDataSource.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/signing-tracker/data/SigningTrackerDataSource.js +2 -0
- package/lib/cjs/src/signing-tracker/data/SigningTrackerDataSource.js.map +7 -0
- 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/dynamic-network/data/HttpDynamicNetworkDataSource.js +1 -1
- package/lib/esm/src/dynamic-network/data/HttpDynamicNetworkDataSource.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/signing-tracker/data/SigningTrackerDataSource.js +1 -0
- package/lib/esm/src/signing-tracker/data/SigningTrackerDataSource.js.map +7 -0
- 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/dynamic-network/data/HttpDynamicNetworkDataSource.d.ts.map +1 -1
- package/lib/types/src/signing-tracker/data/SigningTrackerDataSource.d.ts +40 -0
- package/lib/types/src/signing-tracker/data/SigningTrackerDataSource.d.ts.map +1 -0
- 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": "1.
|
|
61
|
+
"version": "1.14.0"
|
|
62
62
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var i=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var l=(t,e)=>{for(var o in e)i(t,o,{get:e[o],enumerable:!0})},C=(t,e,o,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of u(e))!g.call(t,a)&&a!==o&&i(t,a,{get:()=>e[a],enumerable:!(n=c(e,a))||n.enumerable});return t};var f=t=>C(i({},"__esModule",{value:!0}),t);var x={};l(x,{ContextModuleBuilder:()=>L,DEFAULT_CONFIG:()=>r});module.exports=f(x);var s=require("@ledgerhq/device-management-kit"),d=require("./DefaultContextModule");const 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:s.noopLoggerFactory};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 d.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 {
|
|
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 {\n type LoggerPublisherService,\n noopLoggerFactory,\n} 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 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: noopLoggerFactory,\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,GAAA,IAAAK,EAGO,2CAePC,EAAqC,kCAErC,MAAMC,EAAkB,kDAClBC,EAA0B,+CAC1BC,EAAkC,kCAE3BN,EAAsC,CACjD,IAAK,CACH,IAAKI,EACL,KAAM,OACN,OAAQ,MACV,EACA,WAAY,CACV,IAAKC,CACP,EACA,sBAAuB,CACrB,IAAKC,CACP,EACA,eAAgB,GAChB,cAAe,CAAC,EAChB,oBAAqB,GACrB,mBAAoB,CAAC,EACrB,sBAAuB,OACvB,mBAAoB,OACpB,cAAe,mBACjB,EAEO,MAAMP,CAAqB,CACxB,OACA,YAER,YAAY,CAAE,YAAAQ,EAAa,cAAAC,CAAc,EAAiC,CACxE,KAAK,YAAcD,EAEnB,KAAK,OAAS,CACZ,GAAGP,EACH,IAAK,CAAE,GAAGA,EAAe,GAAI,EAC7B,WAAY,CAAE,GAAGA,EAAe,UAAW,EAC3C,sBAAuB,CAAE,GAAGA,EAAe,qBAAsB,EACjE,cAAe,CAAC,GAAGA,EAAe,aAAa,EAC/C,mBAAoB,CAAC,GAAGA,EAAe,kBAAkB,CAC3D,EACIQ,IACF,KAAK,OAAO,cAAgBA,EAEhC,CAOA,sBAAuB,CACrB,YAAK,OAAO,eAAiB,GACtB,IACT,CAQA,UAAUC,EAAuB,CAC/B,YAAK,OAAO,cAAc,KAAKA,CAAM,EAC9B,IACT,CAQA,mBAAmBA,EAAgC,CACjD,YAAK,OAAO,sBAAwBA,EAC7B,IACT,CAQA,gBAAgBA,EAA6B,CAC3C,YAAK,OAAO,mBAAqBA,EAC1B,IACT,CAQA,aAAaC,EAAmC,CAC9C,YAAK,OAAO,IAAMA,EACX,IACT,CAQA,yBACEC,EACA,CACA,YAAK,OAAO,sBAAwBA,EAC7B,IACT,CAQA,oBAAoBC,EAAiD,CACnE,YAAK,OAAO,WAAaA,EAClB,IACT,CAQA,oBAAoBC,EAAiD,CACnE,YAAK,OAAO,WAAaA,EAClB,IACT,CAQA,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,IAAI,uBAAqBA,CAAM,CACxC,CACF",
|
|
6
|
+
"names": ["ContextModuleBuilder_exports", "__export", "ContextModuleBuilder", "DEFAULT_CONFIG", "__toCommonJS", "import_device_management_kit", "import_DefaultContextModule", "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,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,EACZ,KAAM,GAAG,GAAG,EACZ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rE,MAAMF,EAAuB,IAAI,uBAAqBF,CAAkB,EAClEQ,EAAwD,CAC5D,MAAO,SACT,EAEMP,EAAMC,EACT,oBAAoBM,CAAsB,EAC1C,MAAM,EACHJ,EAAUH,EACd,WACA,IAAyB,cAAY,MAAM,EAE7C,OAAOA,CAAG,EAAE,eAAe,sBAAoB,EAC/C,OAAOG,EAAO,UAAU,EAAE,QAAQI,CAAsB,EACxD,OAAOJ,EAAO,YAAY,KAAK,EAAE,KAAK,SAAS,CACjD,CAAC,EAED,GAAG,uDAAwD,IAAM,CAC/D,MAAMF,EAAuB,IAAI,uBAAqBF,CAAkB,EAClEQ,EAAwD,CAC5D,MAAO,MACT,EAKMJ,EAHMF,EACT,oBAAoBM,CAAsB,EAC1C,MAAM,EAEP,WACA,IAAyB,cAAY,MAAM,EAE7C,OAAOJ,EAAO,YAAY,KAAK,EAAE,KAAK,MAAM,EAC5C,OAAOA,EAAO,UAAU,EAAE,IAAI,cAAc,CAC9C,CAAC,EAED,GAAG,+CAAgD,IAAM,CACvD,MAAMF,EAAuB,IAAI,uBAAqBF,CAAkB,EAClEQ,EAAwD,CAAC,EAEzDP,EAAMC,EACT,oBAAoBM,CAAsB,EAC1C,MAAM,EACHJ,EAAUH,EACd,WACA,IAAyB,cAAY,MAAM,EAE7C,OAAOA,CAAG,EAAE,eAAe,sBAAoB,EAC/C,OAAOG,EAAO,UAAU,EAAE,QAAQI,CAAsB,EACxD,OAAOJ,EAAO,YAAY,KAAK,EAAE,cAAc,CACjD,CAAC,CACH,CAAC,EAED,SAAS,gBAAiB,IAAM,CAC9B,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,EACZ,KAAM,GAAG,GAAG,EACZ,MAAO,GAAG,GAAG,EACb,YAAa,CAAC,CAChB,EAKA,EAEA,WAAW,IAAM,CACf,GAAG,cAAc,CACnB,CAAC,EAED,GAAG,yCAA0C,IAAM,CAGjD,MAAMC,EAFuB,IAAI,uBAAqBD,CAAkB,EAEvC,MAAM,EAEvC,OAAOC,CAAG,EAAE,eAAe,sBAAoB,CACjD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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 E=Object.create;var f=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,A=Object.prototype.hasOwnProperty;var _=(t,r)=>{for(var o in r)f(t,o,{get:r[o],enumerable:!0})},m=(t,r,o,e)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of R(r))!A.call(t,i)&&i!==o&&f(t,i,{get:()=>r[i],enumerable:!(e=d(r,i))||e.enumerable});return t};var g=(t,r,o)=>(o=t!=null?E(C(t)):{},m(r||!t||!t.__esModule?f(o,"default",{value:t,enumerable:!0}):o,t)),h=t=>m(f({},"__esModule",{value:!0}),t),y=(t,r,o,e)=>{for(var i=e>1?void 0:e?d(r,o):r,n=t.length-1,a;n>=0;n--)(a=t[n])&&(i=(e?a(r,o,i):a(i))||i);return e&&i&&f(r,o,i),i},l=(t,r)=>(o,e)=>r(o,e,t);var x={};_(x,{HttpDynamicNetworkDataSource:()=>p});module.exports=h(x);var s=require("@ledgerhq/device-management-kit"),D=g(require("axios")),u=require("inversify"),c=require("purify-ts"),w=require("../../config/di/configTypes"),N=require("../../shared/constant/HttpHeaders"),k=g(require("../../../package.json"));const v={nanos:s.DeviceModelId.NANO_S,nanosp:s.DeviceModelId.NANO_SP,nanox:s.DeviceModelId.NANO_X,stax:s.DeviceModelId.STAX,flex:s.DeviceModelId.FLEX,apexp:s.DeviceModelId.APEX};let p=class{constructor(r){this.config=r}async getDynamicNetworkConfiguration(r){let o;try{o=(await D.default.get(`${this.config.cal.url}/networks?output=id,descriptors,icons&chain_id=${r}`,{headers:{[N.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${k.default.version}`}})).data}catch(n){return(0,c.Left)(n instanceof Error?n:new Error("Failed to fetch network configuration"))}const e=o?.[0];if(!e)return(0,c.Left)(new Error(`Network configuration not found for chain ID: ${r}`));if(!this.isValidNetworkData(e))return(0,c.Left)(new Error(`Invalid network configuration response for chain ID: ${r}`));const i=this.transformToNetworkConfiguration(e);return(0,c.Right)(i)}isValidNetworkData(r){if(!r||typeof r!="object")return!1;const o=r;if(typeof o.id!="string"||!o.descriptors||typeof o.descriptors!="object")return!1;for(const e of Object.values(o.descriptors))if(!this.isValidDescriptor(e))return!1;return!(o.icons&&typeof o.icons!="object")}isValidDescriptor(r){if(!r||typeof r!="object")return!1;const o=r;if(typeof o.data!="string"||typeof o.descriptorType!="string"||typeof o.descriptorVersion!="string"||!o.signatures||typeof o.signatures!="object")return!1;const e=o.signatures;return!(typeof e.prod!="string"||typeof e.test!="string")}transformToNetworkConfiguration(r){const o=Object.entries(r.descriptors).reduce((e,[i,n])=>{const a=v[i.toLowerCase()];return a===void 0||(e[a]={descriptorType:n.descriptorType,descriptorVersion:n.descriptorVersion,data:n.data,signatures:n.signatures,icon:r.icons?.[i]}),e},{});return{id:r.id,descriptors:o}}};p=y([(0,u.injectable)(),l(0,(0,u.inject)(w.configTypes.Config))],p);0&&(module.exports={HttpDynamicNetworkDataSource});
|
|
2
2
|
//# sourceMappingURL=HttpDynamicNetworkDataSource.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/dynamic-network/data/HttpDynamicNetworkDataSource.ts"],
|
|
4
|
-
"sourcesContent": ["import {
|
|
5
|
-
"mappings": "qtBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kCAAAE,IAAA,eAAAC,EAAAH,
|
|
6
|
-
"names": ["HttpDynamicNetworkDataSource_exports", "__export", "HttpDynamicNetworkDataSource", "__toCommonJS", "import_axios", "import_inversify", "import_purify_ts", "import_configTypes", "import_HttpHeaders", "import_package", "HttpDynamicNetworkDataSource", "config", "chainId", "response", "axios", "PACKAGE", "error", "networkData", "configuration", "data", "obj", "descriptor", "desc", "signatures", "descriptors", "acc", "
|
|
4
|
+
"sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n type DynamicNetworkConfiguration,\n type DynamicNetworkDescriptor,\n} from \"@/dynamic-network/model/DynamicNetworkConfiguration\";\nimport { LEDGER_CLIENT_VERSION_HEADER } from \"@/shared/constant/HttpHeaders\";\nimport PACKAGE from \"@root/package.json\";\n\nimport { type DynamicNetworkApiResponseDto } from \"./dto/DynamicNetworkApiResponseDto\";\nimport { type DynamicNetworkDataSource } from \"./DynamicNetworkDataSource\";\n\n/** Maps lowercase device model keys from the API to DeviceModelId */\nconst LOWERCASE_KEY_TO_DEVICE_MODEL_ID: Record<string, DeviceModelId> = {\n nanos: DeviceModelId.NANO_S,\n nanosp: DeviceModelId.NANO_SP,\n nanox: DeviceModelId.NANO_X,\n stax: DeviceModelId.STAX,\n flex: DeviceModelId.FLEX,\n apexp: DeviceModelId.APEX,\n};\n\n@injectable()\nexport class HttpDynamicNetworkDataSource implements DynamicNetworkDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n ) {}\n\n async getDynamicNetworkConfiguration(\n chainId: number,\n ): Promise<Either<Error, DynamicNetworkConfiguration>> {\n let response: DynamicNetworkApiResponseDto;\n\n try {\n const axiosResponse = await axios.get<DynamicNetworkApiResponseDto>(\n `${this.config.cal.url}/networks?output=id,descriptors,icons&chain_id=${chainId}`,\n {\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n },\n },\n );\n response = axiosResponse.data;\n } catch (error) {\n return Left(\n error instanceof Error\n ? error\n : new Error(\"Failed to fetch network configuration\"),\n );\n }\n\n const networkData = response?.[0];\n if (!networkData) {\n return Left(\n new Error(`Network configuration not found for chain ID: ${chainId}`),\n );\n }\n\n // Validate response structure\n if (!this.isValidNetworkData(networkData)) {\n return Left(\n new Error(\n `Invalid network configuration response for chain ID: ${chainId}`,\n ),\n );\n }\n\n const configuration = this.transformToNetworkConfiguration(networkData);\n return Right(configuration);\n }\n\n private isValidNetworkData(\n data: unknown,\n ): data is DynamicNetworkApiResponseDto[0] {\n if (!data || typeof data !== \"object\") {\n return false;\n }\n\n const obj = data as Record<string, unknown>;\n\n // Check required fields\n if (typeof obj[\"id\"] !== \"string\") {\n return false;\n }\n\n // Check descriptors structure\n if (!obj[\"descriptors\"] || typeof obj[\"descriptors\"] !== \"object\") {\n return false;\n }\n\n // Validate each descriptor\n for (const descriptor of Object.values(obj[\"descriptors\"])) {\n if (!this.isValidDescriptor(descriptor)) {\n return false;\n }\n }\n\n // Icons are optional but if present, should be an object\n if (obj[\"icons\"] && typeof obj[\"icons\"] !== \"object\") {\n return false;\n }\n\n return true;\n }\n\n private isValidDescriptor(\n descriptor: unknown,\n ): descriptor is DynamicNetworkApiResponseDto[0][\"descriptors\"][string] {\n if (!descriptor || typeof descriptor !== \"object\") {\n return false;\n }\n\n const desc = descriptor as Record<string, unknown>;\n\n // Check required descriptor fields\n if (\n typeof desc[\"data\"] !== \"string\" ||\n typeof desc[\"descriptorType\"] !== \"string\" ||\n typeof desc[\"descriptorVersion\"] !== \"string\"\n ) {\n return false;\n }\n\n // Check signatures structure\n if (!desc[\"signatures\"] || typeof desc[\"signatures\"] !== \"object\") {\n return false;\n }\n\n const signatures = desc[\"signatures\"] as Record<string, unknown>;\n if (\n typeof signatures[\"prod\"] !== \"string\" ||\n typeof signatures[\"test\"] !== \"string\"\n ) {\n return false;\n }\n\n return true;\n }\n\n private transformToNetworkConfiguration(\n networkData: DynamicNetworkApiResponseDto[0],\n ): DynamicNetworkConfiguration {\n const descriptors = Object.entries(networkData.descriptors).reduce(\n (acc, [apiKey, descriptor]) => {\n const deviceModelId =\n LOWERCASE_KEY_TO_DEVICE_MODEL_ID[apiKey.toLowerCase()];\n if (deviceModelId === undefined) {\n return acc;\n }\n acc[deviceModelId] = {\n descriptorType: descriptor.descriptorType,\n descriptorVersion: descriptor.descriptorVersion,\n data: descriptor.data,\n signatures: descriptor.signatures,\n icon: networkData.icons?.[apiKey],\n };\n return acc;\n },\n {} as Record<DeviceModelId, DynamicNetworkDescriptor>,\n );\n\n return {\n id: networkData.id,\n descriptors,\n };\n }\n}\n"],
|
|
5
|
+
"mappings": "qtBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAA8B,2CAC9BC,EAAkB,oBAClBC,EAAmC,qBACnCC,EAAoC,qBAEpCC,EAA4B,mCAM5BC,EAA6C,yCAC7CC,EAAoB,iCAMpB,MAAMC,EAAkE,CACtE,MAAO,gBAAc,OACrB,OAAQ,gBAAc,QACtB,MAAO,gBAAc,OACrB,KAAM,gBAAc,KACpB,KAAM,gBAAc,KACpB,MAAO,gBAAc,IACvB,EAGO,IAAMC,EAAN,KAAuE,CAC5E,YAC+CC,EAC7C,CAD6C,YAAAA,CAC5C,CAEH,MAAM,+BACJC,EACqD,CACrD,IAAIC,EAEJ,GAAI,CASFA,GARsB,MAAM,EAAAC,QAAM,IAChC,GAAG,KAAK,OAAO,IAAI,GAAG,kDAAkDF,CAAO,GAC/E,CACE,QAAS,CACP,CAAC,8BAA4B,EAAG,kBAAkB,EAAAG,QAAQ,OAAO,EACnE,CACF,CACF,GACyB,IAC3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I,CACnB,eAAgBN,EAAW,eAC3B,kBAAmBA,EAAW,kBAC9B,KAAMA,EAAW,KACjB,WAAYA,EAAW,WACvB,KAAMJ,EAAY,QAAQS,CAAM,CAClC,GACOD,CACT,EACA,CAAC,CACH,EAEA,MAAO,CACL,GAAIR,EAAY,GAChB,YAAAO,CACF,CACF,CACF,EA/Iad,EAANkB,EAAA,IADN,cAAW,EAGPC,EAAA,eAAO,cAAY,MAAM,IAFjBnB",
|
|
6
|
+
"names": ["HttpDynamicNetworkDataSource_exports", "__export", "HttpDynamicNetworkDataSource", "__toCommonJS", "import_device_management_kit", "import_axios", "import_inversify", "import_purify_ts", "import_configTypes", "import_HttpHeaders", "import_package", "LOWERCASE_KEY_TO_DEVICE_MODEL_ID", "HttpDynamicNetworkDataSource", "config", "chainId", "response", "axios", "PACKAGE", "error", "networkData", "configuration", "data", "obj", "descriptor", "desc", "signatures", "descriptors", "acc", "apiKey", "deviceModelId", "__decorateClass", "__decorateParam"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var i=require("@ledgerhq/device-management-kit"),s=require("purify-ts"),m=require("../../dynamic-network/domain/DynamicNetworkContextLoader"),g=require("../../pki/model/KeyId"),k=require("../../pki/model/KeyUsage"),r=require("../../shared/model/ClearSignContext");const N=()=>({debug:vi.fn(),info:vi.fn(),warn:vi.fn(),error:vi.fn(),subscribers:[]});describe("DynamicNetworkContextLoader",()=>{const d={getDynamicNetworkConfiguration:vi.fn()},f={cal:{url:"https://crypto-assets-service.api.ledger.com",mode:"prod",branch:"main"}},u={loadCertificate:vi.fn()},y={keyUsageNumber:1,payload:new Uint8Array([1,2,3])},a=new m.DynamicNetworkContextLoader(d,f,u,N),c=e=>({data:"",descriptorType:"",descriptorVersion:"",signatures:{prod:"",test:""},icon:void 0,...e}),l=(e={})=>({[i.DeviceModelId.NANO_S]:c(),[i.DeviceModelId.NANO_SP]:c(),[i.DeviceModelId.NANO_X]:c(),[i.DeviceModelId.STAX]:c(),[i.DeviceModelId.FLEX]:c(),[i.DeviceModelId.APEX]:c(),...e});beforeEach(()=>{vi.restoreAllMocks(),vi.spyOn(u,"loadCertificate").mockResolvedValue(y)}),describe("canHandle function",()=>{const e={chainId:1,deviceModelId:i.DeviceModelId.STAX};it("should return true for valid input",()=>{expect(a.canHandle(e,[r.ClearSignContextType.DYNAMIC_NETWORK,r.ClearSignContextType.DYNAMIC_NETWORK_ICON])).toBe(!0)}),it("should return false for invalid expected type",()=>{expect(a.canHandle(e,[r.ClearSignContextType.TOKEN])).toBe(!1),expect(a.canHandle(e,[r.ClearSignContextType.DYNAMIC_NETWORK])).toBe(!1),expect(a.canHandle(e,[r.ClearSignContextType.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",(o,t)=>{expect(a.canHandle(o,[r.ClearSignContextType.DYNAMIC_NETWORK,r.ClearSignContextType.DYNAMIC_NETWORK_ICON])).toBe(!1)}),it.each([[{...e,chainId:void 0},"missing chainId"],[{...e,deviceModelId:void 0},"missing deviceModelId"]])("should return false for %s",(o,t)=>{expect(a.canHandle(o,[r.ClearSignContextType.DYNAMIC_NETWORK,r.ClearSignContextType.DYNAMIC_NETWORK_ICON])).toBe(!1)}),it.each([[{...e,chainId:"1"},"string chainId"],[{...e,chainId:null},"null chainId"],[{...e,deviceModelId:i.DeviceModelId.NANO_S},"NANO_S deviceModelId"]])("should return false for %s",(o,t)=>{expect(a.canHandle(o,[r.ClearSignContextType.DYNAMIC_NETWORK,r.ClearSignContextType.DYNAMIC_NETWORK_ICON])).toBe(!1)})}),describe("load function",()=>{it("should return empty array when network data source returns error",async()=>{const e={chainId:1,deviceModelId:i.DeviceModelId.STAX};vi.spyOn(d,"getDynamicNetworkConfiguration").mockResolvedValue((0,s.Left)(new Error("Network error")));const o=await a.load(e);expect(o).toEqual([]),expect(d.getDynamicNetworkConfiguration).toHaveBeenCalledWith(1)}),it("should return empty array when descriptor for device model is not found",async()=>{const e={chainId:1,deviceModelId:i.DeviceModelId.STAX},t={id:"ethereum",descriptors:l({flex:c({data:"0x0101",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"prod-sig",test:"test-sig"},icon:void 0}),stax:void 0})};vi.spyOn(d,"getDynamicNetworkConfiguration").mockResolvedValue((0,s.Right)(t));const n=await a.load(e);expect(n).toEqual([])}),it("should return empty array when signature for mode is not found",async()=>{const e={chainId:1,deviceModelId:i.DeviceModelId.STAX},o={id:"ethereum",descriptors:l({stax:c({data:"0x0101",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"",test:"test-sig"},icon:void 0})})};vi.spyOn(d,"getDynamicNetworkConfiguration").mockResolvedValue((0,s.Right)(o));const t=await a.load(e);expect(t).toEqual([])}),it("should return context with network configuration when all data is available",async()=>{const e={chainId:137,deviceModelId:i.DeviceModelId.STAX},o={id:"polygon",descriptors:l({stax:c({data:"0x0101080201015101012308000000000000008952",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"3045022100cf42c039c16fc95dc97c09f15cdd93bed0e63ee45cf5c38c2b30bb8a3bc17f8d022053a96c9e51695c3c1c1a31f5cbf84bd6febadc97f4bb02bdc67cf3e24ad0c32d",test:"test-sig"},icon:void 0})})};vi.spyOn(d,"getDynamicNetworkConfiguration").mockResolvedValue((0,s.Right)(o));const t=await a.load(e);expect(t).toHaveLength(1),expect(t[0]).toMatchObject({type:r.ClearSignContextType.DYNAMIC_NETWORK,certificate:y});const n=t[0];n&&"payload"in n&&expect(n.payload).toContain("0x0101080201015101012308000000000000008952"),expect(u.loadCertificate).toHaveBeenCalledWith({keyId:g.KeyId.CalNetwork,keyUsage:k.KeyUsage.Network,targetDevice:i.DeviceModelId.STAX})}),it("should include icon context when icon is available",async()=>{const e={chainId:1,deviceModelId:i.DeviceModelId.STAX},o={id:"ethereum",descriptors:l({stax:c({data:"0x0101",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"prod-sig",test:"test-sig"},icon:"icon-hex-data"})})};vi.spyOn(d,"getDynamicNetworkConfiguration").mockResolvedValue((0,s.Right)(o));const t=await a.load(e);expect(t).toHaveLength(2),expect(t[0]).toMatchObject({type:r.ClearSignContextType.DYNAMIC_NETWORK,certificate:y});const n=t[0];n&&"payload"in n&&expect(n.payload).toEqual(expect.any(String)),expect(t[1]).toMatchObject({type:r.ClearSignContextType.DYNAMIC_NETWORK_ICON});const p=t[1];p&&"payload"in p&&expect(p.payload).toBe("icon-hex-data")}),it("should handle multiple device models correctly",async()=>{const e={chainId:1,deviceModelId:i.DeviceModelId.FLEX},o={id:"ethereum",descriptors:l({flex:c({data:"0xFLEX",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"flex-prod-sig",test:"flex-test-sig"},icon:void 0}),stax:c({data:"0xSTAX",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"stax-prod-sig",test:"stax-test-sig"},icon:void 0})})};vi.spyOn(d,"getDynamicNetworkConfiguration").mockResolvedValue((0,s.Right)(o));const t=await a.load(e);expect(t).toHaveLength(1);const n=t[0];n&&"payload"in n&&(expect(n.payload).toContain("0xFLEX"),expect(n.payload).toContain("flex-prod-sig"))}),it("should use test mode signature when configured",async()=>{const e=new m.DynamicNetworkContextLoader(d,{...f,cal:{...f.cal,mode:"test"}},u,N),o={chainId:1,deviceModelId:i.DeviceModelId.STAX},t={id:"ethereum",descriptors:l({stax:c({data:"0x0101",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"prod-sig",test:"test-sig"},icon:void 0})})};vi.spyOn(d,"getDynamicNetworkConfiguration").mockResolvedValue((0,s.Right)(t));const n=await e.load(o);expect(n).toHaveLength(1);const p=n[0];p&&"payload"in p&&expect(p.payload).toContain("test-sig")})})});
|
|
2
2
|
//# sourceMappingURL=DynamicNetworkContextLoader.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/dynamic-network/domain/DynamicNetworkContextLoader.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 DynamicNetworkDataSource } from \"@/dynamic-network/data/DynamicNetworkDataSource\";\nimport {\n type DynamicNetworkContextInput,\n DynamicNetworkContextLoader,\n} from \"@/dynamic-network/domain/DynamicNetworkContextLoader\";\nimport {\n type DynamicNetworkConfiguration,\n type DynamicNetworkDescriptor,\n} from \"@/dynamic-network/model/DynamicNetworkConfiguration\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { type PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\n\nconst mockLoggerFactory = () => ({\n debug: vi.fn(),\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n subscribers: [],\n});\n\ndescribe(\"DynamicNetworkContextLoader\", () => {\n const mockNetworkDataSource: DynamicNetworkDataSource = {\n getDynamicNetworkConfiguration: vi.fn(),\n };\n\n const mockConfig = {\n cal: {\n url: \"https://crypto-assets-service.api.ledger.com\",\n mode: \"prod\",\n branch: \"main\",\n },\n } as ContextModuleConfig;\n\n const mockCertificateLoader: PkiCertificateLoader = {\n loadCertificate: vi.fn(),\n };\n\n const mockCertificate: PkiCertificate = {\n keyUsageNumber: 1,\n payload: new Uint8Array([0x01, 0x02, 0x03]),\n };\n\n const loader = new DynamicNetworkContextLoader(\n mockNetworkDataSource,\n mockConfig,\n mockCertificateLoader,\n mockLoggerFactory,\n );\n\n // Helper function to create a mock NetworkDescriptor\n const createMockDescriptor = (\n partial?: Partial<DynamicNetworkDescriptor>,\n ): DynamicNetworkDescriptor => ({\n data: \"\",\n descriptorType: \"\",\n descriptorVersion: \"\",\n signatures: {\n prod: \"\",\n test: \"\",\n },\n icon: undefined,\n ...partial,\n });\n\n beforeEach(() => {\n vi.restoreAllMocks();\n vi.spyOn(mockCertificateLoader, \"loadCertificate\").mockResolvedValue(\n mockCertificate,\n );\n });\n\n describe(\"canHandle function\", () => {\n const validInput: DynamicNetworkContextInput = {\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n };\n\n it(\"should return true for valid input\", () => {\n expect(\n loader.canHandle(validInput, [\n ClearSignContextType.DYNAMIC_NETWORK,\n ClearSignContextType.DYNAMIC_NETWORK_ICON,\n ]),\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 expect(\n loader.canHandle(validInput, [ClearSignContextType.DYNAMIC_NETWORK]),\n ).toBe(false);\n expect(\n loader.canHandle(validInput, [\n ClearSignContextType.DYNAMIC_NETWORK_ICON,\n ]),\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(\n loader.canHandle(input, [\n ClearSignContextType.DYNAMIC_NETWORK,\n ClearSignContextType.DYNAMIC_NETWORK_ICON,\n ]),\n ).toBe(false);\n });\n\n it.each([\n [{ ...validInput, chainId: undefined }, \"missing chainId\"],\n [{ ...validInput, deviceModelId: undefined }, \"missing deviceModelId\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(\n loader.canHandle(input, [\n ClearSignContextType.DYNAMIC_NETWORK,\n ClearSignContextType.DYNAMIC_NETWORK_ICON,\n ]),\n ).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 \"NANO_S deviceModelId\",\n ],\n ])(\"should return false for %s\", (input, _description) => {\n expect(\n loader.canHandle(input, [\n ClearSignContextType.DYNAMIC_NETWORK,\n ClearSignContextType.DYNAMIC_NETWORK_ICON,\n ]),\n ).toBe(false);\n });\n });\n\n describe(\"load function\", () => {\n it(\"should return empty array when network data source returns error\", async () => {\n // GIVEN\n const input: DynamicNetworkContextInput = {\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Left(new Error(\"Network error\")));\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([]);\n expect(\n mockNetworkDataSource.getDynamicNetworkConfiguration,\n ).toHaveBeenCalledWith(1);\n });\n\n it(\"should return empty array when descriptor for device model is not found\", async () => {\n // GIVEN\n const input: DynamicNetworkContextInput = {\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n };\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"ethereum\",\n descriptors: {\n [DeviceModelId.NANO_S]: createMockDescriptor(),\n [DeviceModelId.NANO_SP]: createMockDescriptor(),\n [DeviceModelId.NANO_X]: createMockDescriptor(),\n // STAX descriptor is intentionally missing\n [DeviceModelId.FLEX]: createMockDescriptor({\n data: \"0x0101\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"prod-sig\",\n test: \"test-sig\",\n },\n icon: undefined,\n }),\n } as Record<DeviceModelId, DynamicNetworkDescriptor>,\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return empty array when signature for mode is not found\", async () => {\n // GIVEN\n const input: DynamicNetworkContextInput = {\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n };\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"ethereum\",\n descriptors: {\n [DeviceModelId.APEX]: createMockDescriptor(),\n [DeviceModelId.NANO_S]: createMockDescriptor(),\n [DeviceModelId.NANO_SP]: createMockDescriptor(),\n [DeviceModelId.NANO_X]: createMockDescriptor(),\n [DeviceModelId.FLEX]: createMockDescriptor(),\n [DeviceModelId.STAX]: createMockDescriptor({\n data: \"0x0101\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n test: \"test-sig\",\n // Missing prod signature - intentionally partial\n } as { prod: string; test: string },\n icon: undefined,\n }),\n },\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return context with network configuration when all data is available\", async () => {\n // GIVEN\n const input: DynamicNetworkContextInput = {\n chainId: 137,\n deviceModelId: DeviceModelId.STAX,\n };\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"polygon\",\n descriptors: {\n [DeviceModelId.APEX]: createMockDescriptor(),\n [DeviceModelId.NANO_S]: createMockDescriptor(),\n [DeviceModelId.NANO_SP]: createMockDescriptor(),\n [DeviceModelId.NANO_X]: createMockDescriptor(),\n [DeviceModelId.FLEX]: createMockDescriptor(),\n [DeviceModelId.STAX]: {\n data: \"0x0101080201015101012308000000000000008952\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"3045022100cf42c039c16fc95dc97c09f15cdd93bed0e63ee45cf5c38c2b30bb8a3bc17f8d022053a96c9e51695c3c1c1a31f5cbf84bd6febadc97f4bb02bdc67cf3e24ad0c32d\",\n test: \"test-sig\",\n },\n icon: undefined,\n },\n },\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toHaveLength(1);\n expect(result[0]).toMatchObject({\n type: ClearSignContextType.DYNAMIC_NETWORK,\n payload: expect.stringContaining(\n \"0x0101080201015101012308000000000000008952\",\n ),\n certificate: mockCertificate,\n });\n expect(mockCertificateLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: KeyId.CalNetwork,\n keyUsage: KeyUsage.Network,\n targetDevice: DeviceModelId.STAX,\n });\n });\n\n it(\"should include icon context when icon is available\", async () => {\n // GIVEN\n const input: DynamicNetworkContextInput = {\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n };\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"ethereum\",\n descriptors: {\n [DeviceModelId.APEX]: createMockDescriptor(),\n [DeviceModelId.NANO_S]: createMockDescriptor(),\n [DeviceModelId.NANO_SP]: createMockDescriptor(),\n [DeviceModelId.NANO_X]: createMockDescriptor(),\n [DeviceModelId.FLEX]: createMockDescriptor(),\n [DeviceModelId.STAX]: {\n data: \"0x0101\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"prod-sig\",\n test: \"test-sig\",\n },\n icon: \"icon-hex-data\",\n },\n },\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toHaveLength(2);\n expect(result[0]).toMatchObject({\n type: ClearSignContextType.DYNAMIC_NETWORK,\n payload: expect.any(String),\n certificate: mockCertificate,\n });\n expect(result[1]).toMatchObject({\n type: ClearSignContextType.DYNAMIC_NETWORK_ICON,\n payload: \"icon-hex-data\",\n });\n });\n\n it(\"should handle multiple device models correctly\", async () => {\n // GIVEN\n const input: DynamicNetworkContextInput = {\n chainId: 1,\n deviceModelId: DeviceModelId.FLEX,\n };\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"ethereum\",\n descriptors: {\n [DeviceModelId.APEX]: createMockDescriptor(),\n [DeviceModelId.NANO_S]: createMockDescriptor(),\n [DeviceModelId.NANO_SP]: createMockDescriptor(),\n [DeviceModelId.NANO_X]: createMockDescriptor(),\n [DeviceModelId.FLEX]: {\n data: \"0xFLEX\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"flex-prod-sig\",\n test: \"flex-test-sig\",\n },\n icon: undefined,\n },\n [DeviceModelId.STAX]: {\n data: \"0xSTAX\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"stax-prod-sig\",\n test: \"stax-test-sig\",\n },\n icon: undefined,\n },\n },\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toHaveLength(1);\n const context = result[0];\n if (context && \"payload\" in context) {\n expect(context.payload).toContain(\"0xFLEX\");\n expect(context.payload).toContain(\"flex-prod-sig\");\n }\n });\n\n it(\"should use test mode signature when configured\", async () => {\n // GIVEN\n const testModeLoader = new DynamicNetworkContextLoader(\n mockNetworkDataSource,\n { ...mockConfig, cal: { ...mockConfig.cal, mode: \"test\" } },\n mockCertificateLoader,\n mockLoggerFactory,\n );\n const input: DynamicNetworkContextInput = {\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n };\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"ethereum\",\n descriptors: {\n [DeviceModelId.APEX]: createMockDescriptor(),\n [DeviceModelId.NANO_S]: createMockDescriptor(),\n [DeviceModelId.NANO_SP]: createMockDescriptor(),\n [DeviceModelId.NANO_X]: createMockDescriptor(),\n [DeviceModelId.FLEX]: createMockDescriptor(),\n [DeviceModelId.STAX]: {\n data: \"0x0101\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"prod-sig\",\n test: \"test-sig\",\n },\n icon: undefined,\n },\n },\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await testModeLoader.load(input);\n\n // THEN\n expect(result).toHaveLength(1);\n const context = result[0];\n if (context && \"payload\" in context) {\n expect(context.payload).toContain(\"test-sig\");\n }\n });\n });\n});\n"],
|
|
5
|
-
"mappings": "aAAA,IAAAA,EAA8B,2CAC9BC,EAA4B,qBAI5BC,EAGO,gEAMPC,EAAsB,6BACtBC,EAAyB,gCAEzBC,EAAqC,2CAErC,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,8BAA+B,IAAM,CAC5C,MAAMC,EAAkD,CACtD,+BAAgC,GAAG,GAAG,CACxC,EAEMC,EAAa,CACjB,IAAK,CACH,IAAK,+CACL,KAAM,OACN,OAAQ,MACV,CACF,EAEMC,EAA8C,CAClD,gBAAiB,GAAG,GAAG,CACzB,EAEMC,EAAkC,CACtC,eAAgB,EAChB,QAAS,IAAI,WAAW,CAAC,EAAM,EAAM,CAAI,CAAC,CAC5C,EAEMC,EAAS,IAAI,8BACjBJ,EACAC,EACAC,EACAH,CACF,EAGMM,EACJC,IAC8B,CAC9B,KAAM,GACN,eAAgB,GAChB,kBAAmB,GACnB,WAAY,CACV,KAAM,GACN,KAAM,EACR,EACA,KAAM,OACN,GAAGA,CACL,GAEA,WAAW,IAAM,CACf,GAAG,gBAAgB,EACnB,GAAG,
|
|
6
|
-
"names": ["import_device_management_kit", "import_purify_ts", "import_DynamicNetworkContextLoader", "import_KeyId", "import_KeyUsage", "import_ClearSignContext", "mockLoggerFactory", "mockNetworkDataSource", "mockConfig", "mockCertificateLoader", "mockCertificate", "loader", "createMockDescriptor", "partial", "validInput", "input", "_description", "result", "networkConfig", "context", "testModeLoader"]
|
|
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 DynamicNetworkDataSource } from \"@/dynamic-network/data/DynamicNetworkDataSource\";\nimport {\n type DynamicNetworkContextInput,\n DynamicNetworkContextLoader,\n} from \"@/dynamic-network/domain/DynamicNetworkContextLoader\";\nimport {\n type DynamicNetworkConfiguration,\n type DynamicNetworkDescriptor,\n} from \"@/dynamic-network/model/DynamicNetworkConfiguration\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { type PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\n\nconst mockLoggerFactory = () => ({\n debug: vi.fn(),\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n subscribers: [],\n});\n\ndescribe(\"DynamicNetworkContextLoader\", () => {\n const mockNetworkDataSource: DynamicNetworkDataSource = {\n getDynamicNetworkConfiguration: vi.fn(),\n };\n\n const mockConfig = {\n cal: {\n url: \"https://crypto-assets-service.api.ledger.com\",\n mode: \"prod\",\n branch: \"main\",\n },\n } as ContextModuleConfig;\n\n const mockCertificateLoader: PkiCertificateLoader = {\n loadCertificate: vi.fn(),\n };\n\n const mockCertificate: PkiCertificate = {\n keyUsageNumber: 1,\n payload: new Uint8Array([0x01, 0x02, 0x03]),\n };\n\n const loader = new DynamicNetworkContextLoader(\n mockNetworkDataSource,\n mockConfig,\n mockCertificateLoader,\n mockLoggerFactory,\n );\n\n // Helper function to create a mock NetworkDescriptor\n const createMockDescriptor = (\n partial?: Partial<DynamicNetworkDescriptor>,\n ): DynamicNetworkDescriptor => ({\n data: \"\",\n descriptorType: \"\",\n descriptorVersion: \"\",\n signatures: {\n prod: \"\",\n test: \"\",\n },\n icon: undefined,\n ...partial,\n });\n\n const createMockDescriptors = (\n overrides: Partial<Record<DeviceModelId, DynamicNetworkDescriptor>> = {},\n ): Record<DeviceModelId, DynamicNetworkDescriptor> => ({\n [DeviceModelId.NANO_S]: createMockDescriptor(),\n [DeviceModelId.NANO_SP]: createMockDescriptor(),\n [DeviceModelId.NANO_X]: createMockDescriptor(),\n [DeviceModelId.STAX]: createMockDescriptor(),\n [DeviceModelId.FLEX]: createMockDescriptor(),\n [DeviceModelId.APEX]: createMockDescriptor(),\n ...overrides,\n });\n\n beforeEach(() => {\n vi.restoreAllMocks();\n vi.spyOn(mockCertificateLoader, \"loadCertificate\").mockResolvedValue(\n mockCertificate,\n );\n });\n\n describe(\"canHandle function\", () => {\n const validInput: DynamicNetworkContextInput = {\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n };\n\n it(\"should return true for valid input\", () => {\n expect(\n loader.canHandle(validInput, [\n ClearSignContextType.DYNAMIC_NETWORK,\n ClearSignContextType.DYNAMIC_NETWORK_ICON,\n ]),\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 expect(\n loader.canHandle(validInput, [ClearSignContextType.DYNAMIC_NETWORK]),\n ).toBe(false);\n expect(\n loader.canHandle(validInput, [\n ClearSignContextType.DYNAMIC_NETWORK_ICON,\n ]),\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(\n loader.canHandle(input, [\n ClearSignContextType.DYNAMIC_NETWORK,\n ClearSignContextType.DYNAMIC_NETWORK_ICON,\n ]),\n ).toBe(false);\n });\n\n it.each([\n [{ ...validInput, chainId: undefined }, \"missing chainId\"],\n [{ ...validInput, deviceModelId: undefined }, \"missing deviceModelId\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(\n loader.canHandle(input, [\n ClearSignContextType.DYNAMIC_NETWORK,\n ClearSignContextType.DYNAMIC_NETWORK_ICON,\n ]),\n ).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 \"NANO_S deviceModelId\",\n ],\n ])(\"should return false for %s\", (input, _description) => {\n expect(\n loader.canHandle(input, [\n ClearSignContextType.DYNAMIC_NETWORK,\n ClearSignContextType.DYNAMIC_NETWORK_ICON,\n ]),\n ).toBe(false);\n });\n });\n\n describe(\"load function\", () => {\n it(\"should return empty array when network data source returns error\", async () => {\n // GIVEN\n const input: DynamicNetworkContextInput = {\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Left(new Error(\"Network error\")));\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([]);\n expect(\n mockNetworkDataSource.getDynamicNetworkConfiguration,\n ).toHaveBeenCalledWith(1);\n });\n\n it(\"should return empty array when descriptor for device model is not found\", async () => {\n // GIVEN\n const input: DynamicNetworkContextInput = {\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n };\n const descriptors = createMockDescriptors({\n flex: createMockDescriptor({\n data: \"0x0101\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"prod-sig\",\n test: \"test-sig\",\n },\n icon: undefined,\n }),\n stax: undefined as unknown as DynamicNetworkDescriptor,\n });\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"ethereum\",\n descriptors,\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return empty array when signature for mode is not found\", async () => {\n // GIVEN\n const input: DynamicNetworkContextInput = {\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n };\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"ethereum\",\n descriptors: createMockDescriptors({\n stax: createMockDescriptor({\n data: \"0x0101\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"\",\n test: \"test-sig\",\n },\n icon: undefined,\n }),\n }),\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return context with network configuration when all data is available\", async () => {\n // GIVEN\n const input: DynamicNetworkContextInput = {\n chainId: 137,\n deviceModelId: DeviceModelId.STAX,\n };\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"polygon\",\n descriptors: createMockDescriptors({\n stax: createMockDescriptor({\n data: \"0x0101080201015101012308000000000000008952\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"3045022100cf42c039c16fc95dc97c09f15cdd93bed0e63ee45cf5c38c2b30bb8a3bc17f8d022053a96c9e51695c3c1c1a31f5cbf84bd6febadc97f4bb02bdc67cf3e24ad0c32d\",\n test: \"test-sig\",\n },\n icon: undefined,\n }),\n }),\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toHaveLength(1);\n expect(result[0]).toMatchObject({\n type: ClearSignContextType.DYNAMIC_NETWORK,\n certificate: mockCertificate,\n });\n const context = result[0];\n if (context && \"payload\" in context) {\n expect(context.payload).toContain(\n \"0x0101080201015101012308000000000000008952\",\n );\n }\n expect(mockCertificateLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: KeyId.CalNetwork,\n keyUsage: KeyUsage.Network,\n targetDevice: DeviceModelId.STAX,\n });\n });\n\n it(\"should include icon context when icon is available\", async () => {\n // GIVEN\n const input: DynamicNetworkContextInput = {\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n };\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"ethereum\",\n descriptors: createMockDescriptors({\n stax: createMockDescriptor({\n data: \"0x0101\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"prod-sig\",\n test: \"test-sig\",\n },\n icon: \"icon-hex-data\",\n }),\n }),\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toHaveLength(2);\n expect(result[0]).toMatchObject({\n type: ClearSignContextType.DYNAMIC_NETWORK,\n certificate: mockCertificate,\n });\n const networkContext = result[0];\n if (networkContext && \"payload\" in networkContext) {\n expect(networkContext.payload).toEqual(expect.any(String));\n }\n expect(result[1]).toMatchObject({\n type: ClearSignContextType.DYNAMIC_NETWORK_ICON,\n });\n const iconContext = result[1];\n if (iconContext && \"payload\" in iconContext) {\n expect(iconContext.payload).toBe(\"icon-hex-data\");\n }\n });\n\n it(\"should handle multiple device models correctly\", async () => {\n // GIVEN\n const input: DynamicNetworkContextInput = {\n chainId: 1,\n deviceModelId: DeviceModelId.FLEX,\n };\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"ethereum\",\n descriptors: createMockDescriptors({\n flex: createMockDescriptor({\n data: \"0xFLEX\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"flex-prod-sig\",\n test: \"flex-test-sig\",\n },\n icon: undefined,\n }),\n stax: createMockDescriptor({\n data: \"0xSTAX\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"stax-prod-sig\",\n test: \"stax-test-sig\",\n },\n icon: undefined,\n }),\n }),\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toHaveLength(1);\n const context = result[0];\n if (context && \"payload\" in context) {\n expect(context.payload).toContain(\"0xFLEX\");\n expect(context.payload).toContain(\"flex-prod-sig\");\n }\n });\n\n it(\"should use test mode signature when configured\", async () => {\n // GIVEN\n const testModeLoader = new DynamicNetworkContextLoader(\n mockNetworkDataSource,\n { ...mockConfig, cal: { ...mockConfig.cal, mode: \"test\" } },\n mockCertificateLoader,\n mockLoggerFactory,\n );\n const input: DynamicNetworkContextInput = {\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n };\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"ethereum\",\n descriptors: createMockDescriptors({\n stax: createMockDescriptor({\n data: \"0x0101\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"prod-sig\",\n test: \"test-sig\",\n },\n icon: undefined,\n }),\n }),\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await testModeLoader.load(input);\n\n // THEN\n expect(result).toHaveLength(1);\n const context = result[0];\n if (context && \"payload\" in context) {\n expect(context.payload).toContain(\"test-sig\");\n }\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "aAAA,IAAAA,EAA8B,2CAC9BC,EAA4B,qBAI5BC,EAGO,gEAMPC,EAAsB,6BACtBC,EAAyB,gCAEzBC,EAAqC,2CAErC,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,8BAA+B,IAAM,CAC5C,MAAMC,EAAkD,CACtD,+BAAgC,GAAG,GAAG,CACxC,EAEMC,EAAa,CACjB,IAAK,CACH,IAAK,+CACL,KAAM,OACN,OAAQ,MACV,CACF,EAEMC,EAA8C,CAClD,gBAAiB,GAAG,GAAG,CACzB,EAEMC,EAAkC,CACtC,eAAgB,EAChB,QAAS,IAAI,WAAW,CAAC,EAAM,EAAM,CAAI,CAAC,CAC5C,EAEMC,EAAS,IAAI,8BACjBJ,EACAC,EACA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ChB,kBAAmB,KACnB,WAAY,CACV,KAAM,gBACN,KAAM,eACR,EACA,KAAM,MACR,CAAC,EACD,KAAMA,EAAqB,CACzB,KAAM,SACN,eAAgB,UAChB,kBAAmB,KACnB,WAAY,CACV,KAAM,gBACN,KAAM,eACR,EACA,KAAM,MACR,CAAC,CACH,CAAC,CACH,EACA,GAAG,MACDL,EACA,gCACF,EAAE,qBAAkB,SAAMa,CAAa,CAAC,EAGxC,MAAMD,EAAS,MAAMR,EAAO,KAAKM,CAAK,EAGtC,OAAOE,CAAM,EAAE,aAAa,CAAC,EAC7B,MAAME,EAAUF,EAAO,CAAC,EACpBE,GAAW,YAAaA,IAC1B,OAAOA,EAAQ,OAAO,EAAE,UAAU,QAAQ,EAC1C,OAAOA,EAAQ,OAAO,EAAE,UAAU,eAAe,EAErD,CAAC,EAED,GAAG,iDAAkD,SAAY,CAE/D,MAAMG,EAAiB,IAAI,8BACzBjB,EACA,CAAE,GAAGC,EAAY,IAAK,CAAE,GAAGA,EAAW,IAAK,KAAM,MAAO,CAAE,EAC1DC,EACAH,CACF,EACMW,EAAoC,CACxC,QAAS,EACT,cAAe,gBAAc,IAC/B,EACMG,EAA6C,CACjD,GAAI,WACJ,YAAaN,EAAsB,CACjC,KAAMF,EAAqB,CACzB,KAAM,SACN,eAAgB,UAChB,kBAAmB,KACnB,WAAY,CACV,KAAM,WACN,KAAM,UACR,EACA,KAAM,MACR,CAAC,CACH,CAAC,CACH,EACA,GAAG,MACDL,EACA,gCACF,EAAE,qBAAkB,SAAMa,CAAa,CAAC,EAGxC,MAAMD,EAAS,MAAMK,EAAe,KAAKP,CAAK,EAG9C,OAAOE,CAAM,EAAE,aAAa,CAAC,EAC7B,MAAME,EAAUF,EAAO,CAAC,EACpBE,GAAW,YAAaA,GAC1B,OAAOA,EAAQ,OAAO,EAAE,UAAU,UAAU,CAEhD,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["import_device_management_kit", "import_purify_ts", "import_DynamicNetworkContextLoader", "import_KeyId", "import_KeyUsage", "import_ClearSignContext", "mockLoggerFactory", "mockNetworkDataSource", "mockConfig", "mockCertificateLoader", "mockCertificate", "loader", "createMockDescriptor", "partial", "createMockDescriptors", "overrides", "validInput", "input", "_description", "result", "networkConfig", "context", "networkContext", "iconContext", "testModeLoader"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var o=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var p=(n,r,t,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let e of g(r))!c.call(n,e)&&e!==t&&o(n,e,{get:()=>r[e],enumerable:!(i=a(r,e))||i.enumerable});return n};var s=n=>p(o({},"__esModule",{value:!0}),n);var S={};module.exports=s(S);
|
|
2
|
+
//# sourceMappingURL=SigningTrackerDataSource.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/signing-tracker/data/SigningTrackerDataSource.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Data source for tracking signing events.\n *\n * Implement this interface to POST signing context to an external API\n * for blind-signing tracking or auditing purposes.\n *\n * The `reportSigningContext` method is called just before the device\n * signature request, after contexts have been provided to the device,\n * when the blind-sign status is known.\n *\n * @example\n * ```ts\n * const myTracker: SigningTrackerDataSource = {\n * reportSigningContext: async (params) => {\n * await fetch(\"https://my-api.example.com/signing-events\", {\n * method: \"POST\",\n * headers: { \"Content-Type\": \"application/json\" },\n * body: JSON.stringify(params),\n * });\n * },\n * };\n *\n * const contextModule = new ContextModuleBuilder({ ... })\n * .setSigningTrackerDataSource(myTracker)\n * .build();\n * ```\n */\nexport interface SigningTrackerDataSource {\n /**\n * Report signing context to an external API.\n *\n * Called with the full signing context info (including `isBlindSign`\n * status) just before the signature is requested from the device.\n *\n * @param params - The signing context info. Shape varies by signer\n * (ETH vs Solana) but always contains `signatureId` and `isBlindSign`.\n */\n reportSigningContext(params: Record<string, unknown>): Promise<void>;\n}\n"],
|
|
5
|
+
"mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
|
|
6
|
+
"names": ["SigningTrackerDataSource_exports", "__toCommonJS"]
|
|
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
|
}
|