@ledgerhq/context-module 0.0.0-develop-20260211001836 → 0.0.0-develop-20260212001325
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/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/esm/package.json +1 -1
- 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/types/src/dynamic-network/data/HttpDynamicNetworkDataSource.d.ts.map +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +5 -5
package/lib/cjs/package.json
CHANGED
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"watch:builds": "pnpm ldmk-tool watch --entryPoints index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
|
|
59
59
|
"watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\""
|
|
60
60
|
},
|
|
61
|
-
"version": "0.0.0-develop-
|
|
61
|
+
"version": "0.0.0-develop-20260212001325"
|
|
62
62
|
}
|
|
@@ -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}\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OD,EAAI,WAAc,EACvD,GAAI,CAAC,KAAK,kBAAkBC,CAAU,EACpC,MAAO,GAKX,MAAI,EAAAD,EAAI,OAAY,OAAOA,EAAI,OAAa,SAK9C,CAEQ,kBACNC,EACsE,CACtE,GAAI,CAACA,GAAc,OAAOA,GAAe,SACvC,MAAO,GAGT,MAAMC,EAAOD,EAYb,GARE,OAAOC,EAAK,MAAY,UACxB,OAAOA,EAAK,gBAAsB,UAClC,OAAOA,EAAK,mBAAyB,UAMnC,CAACA,EAAK,YAAiB,OAAOA,EAAK,YAAkB,SACvD,MAAO,GAGT,MAAMC,EAAaD,EAAK,WACxB,MACE,SAAOC,EAAW,MAAY,UAC9B,OAAOA,EAAW,MAAY,SAMlC,CAEQ,gCACNN,EAC6B,CAC7B,MAAMO,EAAc,OAAO,QAAQP,EAAY,WAAW,EAAE,OAC1D,CAACQ,EAAK,CAACC,EAAQL,CAAU,IAAM,CAC7B,MAAMM,EACJlB,EAAiCiB,EAAO,YAAY,CAAC,EACvD,OAAIC,IAAkB,SAGtBF,EAAIE,CAAa,EAAI,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,EACAC,EACAH,CACF,EAGMM,EACJC,IAC8B,CAC9B,KAAM,GACN,eAAgB,GAChB,kBAAmB,GACnB,WAAY,CACV,KAAM,GACN,KAAM,EACR,EACA,KAAM,OACN,GAAGA,CACL,GAEMC,EAAwB,CAC5BC,EAAsE,CAAC,KAClB,CACrD,CAAC,gBAAc,MAAM,EAAGH,EAAqB,EAC7C,CAAC,gBAAc,OAAO,EAAGA,EAAqB,EAC9C,CAAC,gBAAc,MAAM,EAAGA,EAAqB,EAC7C,CAAC,gBAAc,IAAI,EAAGA,EAAqB,EAC3C,CAAC,gBAAc,IAAI,EAAGA,EAAqB,EAC3C,CAAC,gBAAc,IAAI,EAAGA,EAAqB,EAC3C,GAAGG,CACL,GAEA,WAAW,IAAM,CACf,GAAG,gBAAgB,EACnB,GAAG,MAAMN,EAAuB,iBAAiB,EAAE,kBACjDC,CACF,CACF,CAAC,EAED,SAAS,qBAAsB,I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ACzBjB,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
|
}
|
package/lib/esm/package.json
CHANGED
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"watch:builds": "pnpm ldmk-tool watch --entryPoints index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
|
|
59
59
|
"watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\""
|
|
60
60
|
},
|
|
61
|
-
"version": "0.0.0-develop-
|
|
61
|
+
"version": "0.0.0-develop-20260212001325"
|
|
62
62
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var d=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var p=(a,o,r,e)=>{for(var t=e>1?void 0:e?m(o,r):o,i=a.length-1,n;i>=0;i--)(n=a[i])&&(t=(e?n(o,r,t):n(t))||t);return e&&t&&d(o,r,t),t},u=(a,o)=>(r,e)=>o(r,e,a);import{DeviceModelId as s}from"@ledgerhq/device-management-kit";import g from"axios";import{inject as y,injectable as l}from"inversify";import{Left as f,Right as D}from"purify-ts";import{configTypes as w}from"../../config/di/configTypes";import{LEDGER_CLIENT_VERSION_HEADER as N}from"../../shared/constant/HttpHeaders";import k from"../../../package.json";const E={nanos:s.NANO_S,nanosp:s.NANO_SP,nanox:s.NANO_X,stax:s.STAX,flex:s.FLEX,apexp:s.APEX};let c=class{constructor(o){this.config=o}async getDynamicNetworkConfiguration(o){let r;try{r=(await g.get(`${this.config.cal.url}/networks?output=id,descriptors,icons&chain_id=${o}`,{headers:{[N]:`context-module/${k.version}`}})).data}catch(i){return f(i instanceof Error?i:new Error("Failed to fetch network configuration"))}const e=r?.[0];if(!e)return f(new Error(`Network configuration not found for chain ID: ${o}`));if(!this.isValidNetworkData(e))return f(new Error(`Invalid network configuration response for chain ID: ${o}`));const t=this.transformToNetworkConfiguration(e);return D(t)}isValidNetworkData(o){if(!o||typeof o!="object")return!1;const r=o;if(typeof r.id!="string"||!r.descriptors||typeof r.descriptors!="object")return!1;for(const e of Object.values(r.descriptors))if(!this.isValidDescriptor(e))return!1;return!(r.icons&&typeof r.icons!="object")}isValidDescriptor(o){if(!o||typeof o!="object")return!1;const r=o;if(typeof r.data!="string"||typeof r.descriptorType!="string"||typeof r.descriptorVersion!="string"||!r.signatures||typeof r.signatures!="object")return!1;const e=r.signatures;return!(typeof e.prod!="string"||typeof e.test!="string")}transformToNetworkConfiguration(o){const r=Object.entries(o.descriptors).reduce((e,[t,i])=>{const n=E[t.toLowerCase()];return n===void 0||(e[n]={descriptorType:i.descriptorType,descriptorVersion:i.descriptorVersion,data:i.data,signatures:i.signatures,icon:o.icons?.[t]}),e},{});return{id:o.id,descriptors:r}}};c=p([l(),u(0,y(w.Config))],c);export{c as 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": "
|
|
6
|
-
"names": ["axios", "inject", "injectable", "Left", "Right", "configTypes", "LEDGER_CLIENT_VERSION_HEADER", "PACKAGE", "HttpDynamicNetworkDataSource", "config", "chainId", "response", "axios", "LEDGER_CLIENT_VERSION_HEADER", "PACKAGE", "error", "Left", "networkData", "configuration", "Right", "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": "iOAAA,OAAS,iBAAAA,MAAqB,kCAC9B,OAAOC,MAAW,QAClB,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YACnC,OAAiB,QAAAC,EAAM,SAAAC,MAAa,YAEpC,OAAS,eAAAC,MAAmB,0BAM5B,OAAS,gCAAAC,MAAoC,gCAC7C,OAAOC,MAAa,qBAMpB,MAAMC,EAAkE,CACtE,MAAOC,EAAc,OACrB,OAAQA,EAAc,QACtB,MAAOA,EAAc,OACrB,KAAMA,EAAc,KACpB,KAAMA,EAAc,KACpB,MAAOA,EAAc,IACvB,EAGO,IAAMC,EAAN,KAAuE,CAC5E,YAC+CC,EAC7C,CA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B,OAAOA,EAAW,MAAY,SAMlC,CAEQ,gCACNP,EAC6B,CAC7B,MAAMQ,EAAc,OAAO,QAAQR,EAAY,WAAW,EAAE,OAC1D,CAACS,EAAK,CAACC,EAAQL,CAAU,IAAM,CAC7B,MAAMM,EACJtB,EAAiCqB,EAAO,YAAY,CAAC,EACvD,OAAIC,IAAkB,SAGtBF,EAAIE,CAAa,EAAI,CACnB,eAAgBN,EAAW,eAC3B,kBAAmBA,EAAW,kBAC9B,KAAMA,EAAW,KACjB,WAAYA,EAAW,WACvB,KAAML,EAAY,QAAQU,CAAM,CAClC,GACOD,CACT,EACA,CAAC,CACH,EAEA,MAAO,CACL,GAAIT,EAAY,GAChB,YAAAQ,CACF,CACF,CACF,EA/IajB,EAANqB,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAY,MAAM,IAFjBzB",
|
|
6
|
+
"names": ["DeviceModelId", "axios", "inject", "injectable", "Left", "Right", "configTypes", "LEDGER_CLIENT_VERSION_HEADER", "PACKAGE", "LOWERCASE_KEY_TO_DEVICE_MODEL_ID", "DeviceModelId", "HttpDynamicNetworkDataSource", "config", "chainId", "response", "axios", "LEDGER_CLIENT_VERSION_HEADER", "PACKAGE", "error", "Left", "networkData", "configuration", "Right", "data", "obj", "descriptor", "desc", "signatures", "descriptors", "acc", "apiKey", "deviceModelId", "__decorateClass", "injectable", "__decorateParam", "inject", "configTypes"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{DeviceModelId as
|
|
1
|
+
import{DeviceModelId as i}from"@ledgerhq/device-management-kit";import{Left as g,Right as l}from"purify-ts";import{DynamicNetworkContextLoader as m}from"../../dynamic-network/domain/DynamicNetworkContextLoader";import{KeyId as k}from"../../pki/model/KeyId";import{KeyUsage as C}from"../../pki/model/KeyUsage";import{ClearSignContextType as r}from"../../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(d,f,u,N),c=e=>({data:"",descriptorType:"",descriptorVersion:"",signatures:{prod:"",test:""},icon:void 0,...e}),p=(e={})=>({[i.NANO_S]:c(),[i.NANO_SP]:c(),[i.NANO_X]:c(),[i.STAX]:c(),[i.FLEX]:c(),[i.APEX]:c(),...e});beforeEach(()=>{vi.restoreAllMocks(),vi.spyOn(u,"loadCertificate").mockResolvedValue(y)}),describe("canHandle function",()=>{const e={chainId:1,deviceModelId:i.STAX};it("should return true for valid input",()=>{expect(a.canHandle(e,[r.DYNAMIC_NETWORK,r.DYNAMIC_NETWORK_ICON])).toBe(!0)}),it("should return false for invalid expected type",()=>{expect(a.canHandle(e,[r.TOKEN])).toBe(!1),expect(a.canHandle(e,[r.DYNAMIC_NETWORK])).toBe(!1),expect(a.canHandle(e,[r.DYNAMIC_NETWORK_ICON])).toBe(!1)}),it.each([[null,"null input"],[void 0,"undefined input"],[{},"empty object"],["string","string input"],[123,"number input"]])("should return false for %s",(o,t)=>{expect(a.canHandle(o,[r.DYNAMIC_NETWORK,r.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.DYNAMIC_NETWORK,r.DYNAMIC_NETWORK_ICON])).toBe(!1)}),it.each([[{...e,chainId:"1"},"string chainId"],[{...e,chainId:null},"null chainId"],[{...e,deviceModelId:i.NANO_S},"NANO_S deviceModelId"]])("should return false for %s",(o,t)=>{expect(a.canHandle(o,[r.DYNAMIC_NETWORK,r.DYNAMIC_NETWORK_ICON])).toBe(!1)})}),describe("load function",()=>{it("should return empty array when network data source returns error",async()=>{const e={chainId:1,deviceModelId:i.STAX};vi.spyOn(d,"getDynamicNetworkConfiguration").mockResolvedValue(g(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.STAX},t={id:"ethereum",descriptors:p({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(l(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.STAX},o={id:"ethereum",descriptors:p({stax:c({data:"0x0101",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"",test:"test-sig"},icon:void 0})})};vi.spyOn(d,"getDynamicNetworkConfiguration").mockResolvedValue(l(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.STAX},o={id:"polygon",descriptors:p({stax:c({data:"0x0101080201015101012308000000000000008952",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"3045022100cf42c039c16fc95dc97c09f15cdd93bed0e63ee45cf5c38c2b30bb8a3bc17f8d022053a96c9e51695c3c1c1a31f5cbf84bd6febadc97f4bb02bdc67cf3e24ad0c32d",test:"test-sig"},icon:void 0})})};vi.spyOn(d,"getDynamicNetworkConfiguration").mockResolvedValue(l(o));const t=await a.load(e);expect(t).toHaveLength(1),expect(t[0]).toMatchObject({type:r.DYNAMIC_NETWORK,certificate:y});const n=t[0];n&&"payload"in n&&expect(n.payload).toContain("0x0101080201015101012308000000000000008952"),expect(u.loadCertificate).toHaveBeenCalledWith({keyId:k.CalNetwork,keyUsage:C.Network,targetDevice:i.STAX})}),it("should include icon context when icon is available",async()=>{const e={chainId:1,deviceModelId:i.STAX},o={id:"ethereum",descriptors:p({stax:c({data:"0x0101",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"prod-sig",test:"test-sig"},icon:"icon-hex-data"})})};vi.spyOn(d,"getDynamicNetworkConfiguration").mockResolvedValue(l(o));const t=await a.load(e);expect(t).toHaveLength(2),expect(t[0]).toMatchObject({type:r.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.DYNAMIC_NETWORK_ICON});const s=t[1];s&&"payload"in s&&expect(s.payload).toBe("icon-hex-data")}),it("should handle multiple device models correctly",async()=>{const e={chainId:1,deviceModelId:i.FLEX},o={id:"ethereum",descriptors:p({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(l(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(d,{...f,cal:{...f.cal,mode:"test"}},u,N),o={chainId:1,deviceModelId:i.STAX},t={id:"ethereum",descriptors:p({stax:c({data:"0x0101",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"prod-sig",test:"test-sig"},icon:void 0})})};vi.spyOn(d,"getDynamicNetworkConfiguration").mockResolvedValue(l(t));const n=await e.load(o);expect(n).toHaveLength(1);const s=n[0];s&&"payload"in s&&expect(s.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,OAAS,iBAAAA,MAAqB,kCAC9B,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAI5B,OAEE,+BAAAC,MACK,uDAMP,OAAS,SAAAC,MAAa,oBACtB,OAAS,YAAAC,MAAgB,uBAEzB,OAAS,wBAAAC,MAA4B,kCAErC,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,IAAIT,EACjBK,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": ["DeviceModelId", "Left", "Right", "DynamicNetworkContextLoader", "KeyId", "KeyUsage", "ClearSignContextType", "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,OAAS,iBAAAA,MAAqB,kCAC9B,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAI5B,OAEE,+BAAAC,MACK,uDAMP,OAAS,SAAAC,MAAa,oBACtB,OAAS,YAAAC,MAAgB,uBAEzB,OAAS,wBAAAC,MAA4B,kCAErC,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,WAA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UAAU,UAAU,CAEhD,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["DeviceModelId", "Left", "Right", "DynamicNetworkContextLoader", "KeyId", "KeyUsage", "ClearSignContextType", "mockLoggerFactory", "mockNetworkDataSource", "mockConfig", "mockCertificateLoader", "mockCertificate", "loader", "createMockDescriptor", "partial", "createMockDescriptors", "overrides", "validInput", "input", "_description", "result", "networkConfig", "context", "networkContext", "iconContext", "testModeLoader"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpDynamicNetworkDataSource.d.ts","sourceRoot":"","sources":["../../../../../src/dynamic-network/data/HttpDynamicNetworkDataSource.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAe,MAAM,WAAW,CAAC;AAGhD,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAC9E,OAAO,EACL,KAAK,2BAA2B,EAEjC,MAAM,qDAAqD,CAAC;AAK7D,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"HttpDynamicNetworkDataSource.d.ts","sourceRoot":"","sources":["../../../../../src/dynamic-network/data/HttpDynamicNetworkDataSource.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAe,MAAM,WAAW,CAAC;AAGhD,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAC9E,OAAO,EACL,KAAK,2BAA2B,EAEjC,MAAM,qDAAqD,CAAC;AAK7D,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAY3E,qBACa,4BAA6B,YAAW,wBAAwB;IAE7C,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,mBAAmB;IAGpE,8BAA8B,CAClC,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,2BAA2B,CAAC,CAAC;IAyCtD,OAAO,CAAC,kBAAkB;IAkC1B,OAAO,CAAC,iBAAiB;IAkCzB,OAAO,CAAC,+BAA+B;CA2BxC"}
|