@ledgerhq/context-module 1.11.1 → 1.12.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.
Files changed (115) hide show
  1. package/lib/cjs/package.json +1 -1
  2. package/lib/cjs/src/ContextModuleBuilder.js +1 -1
  3. package/lib/cjs/src/ContextModuleBuilder.js.map +3 -3
  4. package/lib/cjs/src/ContextModuleBuilder.test.js +1 -1
  5. package/lib/cjs/src/ContextModuleBuilder.test.js.map +3 -3
  6. package/lib/cjs/src/DefaultContextModule.test.js +1 -1
  7. package/lib/cjs/src/DefaultContextModule.test.js.map +3 -3
  8. package/lib/cjs/src/config/di/configTypes.js +1 -1
  9. package/lib/cjs/src/config/di/configTypes.js.map +2 -2
  10. package/lib/cjs/src/config/model/ContextModuleBuildArgs.js +1 -1
  11. package/lib/cjs/src/config/model/ContextModuleBuildArgs.js.map +1 -1
  12. package/lib/cjs/src/config/model/ContextModuleConfig.js +1 -1
  13. package/lib/cjs/src/config/model/ContextModuleConfig.js.map +1 -1
  14. package/lib/cjs/src/di.js +1 -1
  15. package/lib/cjs/src/di.js.map +3 -3
  16. package/lib/cjs/src/shared/model/TypedDataClearSignContext.js +1 -1
  17. package/lib/cjs/src/shared/model/TypedDataClearSignContext.js.map +2 -2
  18. package/lib/cjs/src/shared/utils/NullLoggerPublisherService.js +2 -0
  19. package/lib/cjs/src/shared/utils/NullLoggerPublisherService.js.map +7 -0
  20. package/lib/cjs/src/shared/utils/NullLoggerPublisherService.test.js +2 -0
  21. package/lib/cjs/src/shared/utils/NullLoggerPublisherService.test.js.map +7 -0
  22. package/lib/cjs/src/solana/domain/DefaultSolanaContextLoader.js +1 -1
  23. package/lib/cjs/src/solana/domain/DefaultSolanaContextLoader.js.map +3 -3
  24. package/lib/cjs/src/solana/domain/DefaultSolanaContextLoader.test.js +1 -1
  25. package/lib/cjs/src/solana/domain/DefaultSolanaContextLoader.test.js.map +3 -3
  26. package/lib/cjs/src/solanaLifi/domain/SolanaLifiContextLoader.js +1 -1
  27. package/lib/cjs/src/solanaLifi/domain/SolanaLifiContextLoader.js.map +3 -3
  28. package/lib/cjs/src/solanaLifi/domain/SolanaLifiContextLoader.test.js +1 -1
  29. package/lib/cjs/src/solanaLifi/domain/SolanaLifiContextLoader.test.js.map +3 -3
  30. package/lib/cjs/src/solanaToken/domain/SolanaTokenContextLoader.js +1 -1
  31. package/lib/cjs/src/solanaToken/domain/SolanaTokenContextLoader.js.map +3 -3
  32. package/lib/cjs/src/solanaToken/domain/SolanaTokenContextLoader.test.js +1 -1
  33. package/lib/cjs/src/solanaToken/domain/SolanaTokenContextLoader.test.js.map +3 -3
  34. package/lib/cjs/src/token/domain/TokenContextFieldLoader.js +1 -1
  35. package/lib/cjs/src/token/domain/TokenContextFieldLoader.js.map +3 -3
  36. package/lib/cjs/src/token/domain/TokenContextFieldLoader.test.js +1 -1
  37. package/lib/cjs/src/token/domain/TokenContextFieldLoader.test.js.map +3 -3
  38. package/lib/cjs/src/typed-data/data/FiltersDto.js.map +1 -1
  39. package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.js +1 -1
  40. package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.js.map +2 -2
  41. package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.test.js +1 -1
  42. package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.test.js.map +2 -2
  43. package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.js +1 -1
  44. package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.js.map +3 -3
  45. package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.test.js +1 -1
  46. package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.test.js.map +2 -2
  47. package/lib/esm/package.json +1 -1
  48. package/lib/esm/src/ContextModuleBuilder.js +1 -1
  49. package/lib/esm/src/ContextModuleBuilder.js.map +3 -3
  50. package/lib/esm/src/ContextModuleBuilder.test.js +1 -1
  51. package/lib/esm/src/ContextModuleBuilder.test.js.map +3 -3
  52. package/lib/esm/src/DefaultContextModule.test.js +1 -1
  53. package/lib/esm/src/DefaultContextModule.test.js.map +3 -3
  54. package/lib/esm/src/config/di/configTypes.js +1 -1
  55. package/lib/esm/src/config/di/configTypes.js.map +2 -2
  56. package/lib/esm/src/di.js +1 -1
  57. package/lib/esm/src/di.js.map +3 -3
  58. package/lib/esm/src/shared/model/TypedDataClearSignContext.js.map +2 -2
  59. package/lib/esm/src/shared/utils/NullLoggerPublisherService.js +2 -0
  60. package/lib/esm/src/shared/utils/NullLoggerPublisherService.js.map +7 -0
  61. package/lib/esm/src/shared/utils/NullLoggerPublisherService.test.js +2 -0
  62. package/lib/esm/src/shared/utils/NullLoggerPublisherService.test.js.map +7 -0
  63. package/lib/esm/src/solana/domain/DefaultSolanaContextLoader.js +1 -1
  64. package/lib/esm/src/solana/domain/DefaultSolanaContextLoader.js.map +3 -3
  65. package/lib/esm/src/solana/domain/DefaultSolanaContextLoader.test.js +1 -1
  66. package/lib/esm/src/solana/domain/DefaultSolanaContextLoader.test.js.map +3 -3
  67. package/lib/esm/src/solanaLifi/domain/SolanaLifiContextLoader.js +1 -1
  68. package/lib/esm/src/solanaLifi/domain/SolanaLifiContextLoader.js.map +3 -3
  69. package/lib/esm/src/solanaLifi/domain/SolanaLifiContextLoader.test.js +1 -1
  70. package/lib/esm/src/solanaLifi/domain/SolanaLifiContextLoader.test.js.map +3 -3
  71. package/lib/esm/src/solanaToken/domain/SolanaTokenContextLoader.js +1 -1
  72. package/lib/esm/src/solanaToken/domain/SolanaTokenContextLoader.js.map +3 -3
  73. package/lib/esm/src/solanaToken/domain/SolanaTokenContextLoader.test.js +1 -1
  74. package/lib/esm/src/solanaToken/domain/SolanaTokenContextLoader.test.js.map +3 -3
  75. package/lib/esm/src/token/domain/TokenContextFieldLoader.js +1 -1
  76. package/lib/esm/src/token/domain/TokenContextFieldLoader.js.map +3 -3
  77. package/lib/esm/src/token/domain/TokenContextFieldLoader.test.js +1 -1
  78. package/lib/esm/src/token/domain/TokenContextFieldLoader.test.js.map +3 -3
  79. package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.js +1 -1
  80. package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.js.map +2 -2
  81. package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.test.js +1 -1
  82. package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.test.js.map +2 -2
  83. package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.js +1 -1
  84. package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.js.map +3 -3
  85. package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.test.js +1 -1
  86. package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.test.js.map +2 -2
  87. package/lib/types/src/ContextModuleBuilder.d.ts +9 -1
  88. package/lib/types/src/ContextModuleBuilder.d.ts.map +1 -1
  89. package/lib/types/src/config/di/configTypes.d.ts +1 -0
  90. package/lib/types/src/config/di/configTypes.d.ts.map +1 -1
  91. package/lib/types/src/config/model/ContextModuleBuildArgs.d.ts +2 -0
  92. package/lib/types/src/config/model/ContextModuleBuildArgs.d.ts.map +1 -1
  93. package/lib/types/src/config/model/ContextModuleConfig.d.ts +2 -0
  94. package/lib/types/src/config/model/ContextModuleConfig.d.ts.map +1 -1
  95. package/lib/types/src/di.d.ts.map +1 -1
  96. package/lib/types/src/shared/model/TypedDataClearSignContext.d.ts +2 -0
  97. package/lib/types/src/shared/model/TypedDataClearSignContext.d.ts.map +1 -1
  98. package/lib/types/src/shared/utils/NullLoggerPublisherService.d.ts +3 -0
  99. package/lib/types/src/shared/utils/NullLoggerPublisherService.d.ts.map +1 -0
  100. package/lib/types/src/shared/utils/NullLoggerPublisherService.test.d.ts +2 -0
  101. package/lib/types/src/shared/utils/NullLoggerPublisherService.test.d.ts.map +1 -0
  102. package/lib/types/src/solana/domain/DefaultSolanaContextLoader.d.ts +3 -1
  103. package/lib/types/src/solana/domain/DefaultSolanaContextLoader.d.ts.map +1 -1
  104. package/lib/types/src/solanaLifi/domain/SolanaLifiContextLoader.d.ts +3 -1
  105. package/lib/types/src/solanaLifi/domain/SolanaLifiContextLoader.d.ts.map +1 -1
  106. package/lib/types/src/solanaToken/domain/SolanaTokenContextLoader.d.ts +3 -2
  107. package/lib/types/src/solanaToken/domain/SolanaTokenContextLoader.d.ts.map +1 -1
  108. package/lib/types/src/token/domain/TokenContextFieldLoader.d.ts +5 -1
  109. package/lib/types/src/token/domain/TokenContextFieldLoader.d.ts.map +1 -1
  110. package/lib/types/src/typed-data/data/FiltersDto.d.ts +0 -4
  111. package/lib/types/src/typed-data/data/FiltersDto.d.ts.map +1 -1
  112. package/lib/types/src/typed-data/data/HttpTypedDataDataSource.test.d.ts.map +1 -1
  113. package/lib/types/src/typed-data/domain/DefaultTypedDataContextLoader.d.ts.map +1 -1
  114. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  115. package/package.json +5 -5
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/ContextModuleBuilder.ts"],
4
- "sourcesContent": ["import { 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 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};\n\nexport class ContextModuleBuilder {\n private config: ContextModuleConfig = DEFAULT_CONFIG;\n private originToken?: string;\n\n constructor({ originToken }: ContextModuleConstructorArgs = {}) {\n this.originToken = originToken;\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 * 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": "AAYA,OAAS,wBAAAA,MAA4B,yBAErC,MAAMC,EAAkB,kDAClBC,EAA0B,+CAC1BC,EAAkC,kCAE3BC,EAAsC,CACjD,IAAK,CACH,IAAKH,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,MACtB,EAEO,MAAME,CAAqB,CACxB,OAA8BD,EAC9B,YAER,YAAY,CAAE,YAAAE,CAAY,EAAkC,CAAC,EAAG,CAC9D,KAAK,YAAcA,CACrB,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,CAOA,OAAuB,CACrB,MAAMC,EAAS,CAAE,GAAG,KAAK,OAAQ,YAAa,KAAK,WAAY,EAC/D,OAAO,IAAIZ,EAAqBY,CAAM,CACxC,CACF",
6
- "names": ["DefaultContextModule", "DEFAULT_CAL_URL", "DEFAULT_WEB3_CHECKS_URL", "DEFAULT_METADATA_SERVICE_DOMAIN", "DEFAULT_CONFIG", "ContextModuleBuilder", "originToken", "loader", "calConfig", "metadataServiceConfig", "web3ChecksConfig", "datasourceConfig", "config"]
4
+ "sourcesContent": ["import { type LoggerPublisherService } from \"@ledgerhq/device-management-kit\";\n\nimport { type ContextModuleConstructorArgs } from \"./config/model/ContextModuleBuildArgs\";\nimport {\n type ContextModuleCalConfig,\n type ContextModuleConfig,\n type ContextModuleDatasourceConfig,\n type ContextModuleMetadataServiceConfig,\n type ContextModuleWeb3ChecksConfig,\n} from \"./config/model/ContextModuleConfig\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport { NullLoggerPublisherService } from \"./shared/utils/NullLoggerPublisherService\";\nimport { type SolanaContextLoader } from \"./solana/domain/SolanaContextLoader\";\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: NullLoggerPublisherService,\n};\n\nexport class ContextModuleBuilder {\n private config: ContextModuleConfig = DEFAULT_CONFIG;\n private originToken?: string;\n\n constructor({\n originToken,\n loggerFactory,\n }: ContextModuleConstructorArgs = {}) {\n this.originToken = originToken;\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 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": "AAWA,OAAS,8BAAAA,MAAkC,4CAI3C,OAAS,wBAAAC,MAA4B,yBAErC,MAAMC,EAAkB,kDAClBC,EAA0B,+CAC1BC,EAAkC,kCAE3BC,EAAsC,CACjD,IAAK,CACH,IAAKH,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,cAAeJ,CACjB,EAEO,MAAMM,CAAqB,CACxB,OAA8BD,EAC9B,YAER,YAAY,CACV,YAAAE,EACA,cAAAC,CACF,EAAkC,CAAC,EAAG,CACpC,KAAK,YAAcD,EAEfC,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,iBAAiBL,EAAwD,CACvE,YAAK,OAAO,cAAgBA,EACrB,IACT,CAOA,OAAuB,CACrB,MAAMM,EAAS,CAAE,GAAG,KAAK,OAAQ,YAAa,KAAK,WAAY,EAC/D,OAAO,IAAIb,EAAqBa,CAAM,CACxC,CACF",
6
+ "names": ["NullLoggerPublisherService", "DefaultContextModule", "DEFAULT_CAL_URL", "DEFAULT_WEB3_CHECKS_URL", "DEFAULT_METADATA_SERVICE_DOMAIN", "DEFAULT_CONFIG", "ContextModuleBuilder", "originToken", "loggerFactory", "loader", "calConfig", "metadataServiceConfig", "web3ChecksConfig", "datasourceConfig", "config"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{configTypes as s}from"./config/di/configTypes";import{ContextModuleBuilder as a}from"./ContextModuleBuilder";import{DefaultContextModule as u}from"./DefaultContextModule";describe("ContextModuleBuilder",()=>{const i={url:"https://cal/v1",mode:"prod",branch:"main"},r={url:"https://web3checks/v1"},c={originToken:"test"};beforeEach(()=>{vi.resetAllMocks()}),it("should return a default context module",()=>{const e=new a(c).build();expect(e).toBeInstanceOf(u)}),it("should return a custom context module",()=>{const n=new a(c),e={load:vi.fn(),canHandle:vi.fn()},t=n.removeDefaultLoaders().addLoader(e).build();expect(t).toBeInstanceOf(u)}),it("should return a custom context module with a custom typed data loader",()=>{const n=new a(c),e={load:vi.fn()},t=n.removeDefaultLoaders().addTypedDataLoader(e).build();expect(t).toBeInstanceOf(u),expect(t._typedDataLoader).toBe(e)}),it("should return a custom context module with a custom config",()=>{const e=new a(c).setCalConfig(i).setWeb3ChecksConfig(r).build(),t=e._container.get(s.Config);expect(e).toBeInstanceOf(u),expect(t.cal).toEqual(i),expect(t.web3checks).toEqual(r)}),it("should not throw an error if origin token is provided",()=>{const n=new a(c);expect(()=>n.build()).not.toThrow()}),describe("setMetadataServiceConfig",()=>{it("should set the metadata service configuration",()=>{const n=new a(c),e={url:"https://custom-metadata-service.com/v3"},t=n.setMetadataServiceConfig(e).build(),o=t._container.get(s.Config);expect(t).toBeInstanceOf(u),expect(o.metadataServiceDomain).toEqual(e)}),it("should override the default metadata service configuration",()=>{const n=new a(c),e={url:"https://override-metadata-service.com/v1"},o=n.setMetadataServiceConfig(e).build()._container.get(s.Config);expect(o.metadataServiceDomain.url).toBe(e.url),expect(o.metadataServiceDomain.url).not.toBe("https://nft.api.live.ledger.com/v2")})}),describe("setCalConfig",()=>{it("should set the CAL configuration",()=>{const n=new a(c),e={url:"https://custom-cal-service.com/v2",mode:"test",branch:"next"},t=n.setCalConfig(e).build(),o=t._container.get(s.Config);expect(t).toBeInstanceOf(u),expect(o.cal).toEqual(e)}),it("should override the default CAL configuration",()=>{const n=new a(c),e={url:"https://override-cal-service.com/v1",mode:"prod",branch:"demo"},o=n.setCalConfig(e).build()._container.get(s.Config);expect(o.cal.url).toBe(e.url),expect(o.cal.mode).toBe(e.mode),expect(o.cal.branch).toBe(e.branch),expect(o.cal.url).not.toBe("https://crypto-assets-service.api.ledger.com/v1")})}),describe("setWeb3ChecksConfig",()=>{it("should set the web3 checks configuration",()=>{const n=new a(c),e={url:"https://custom-web3checks-service.com/v4"},t=n.setWeb3ChecksConfig(e).build(),o=t._container.get(s.Config);expect(t).toBeInstanceOf(u),expect(o.web3checks).toEqual(e)}),it("should override the default web3 checks configuration",()=>{const n=new a(c),e={url:"https://override-web3checks-service.com/v2"},o=n.setWeb3ChecksConfig(e).build()._container.get(s.Config);expect(o.web3checks.url).toBe(e.url),expect(o.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 a(c),e={proxy:"safe"},t=n.setDatasourceConfig(e).build(),o=t._container.get(s.Config);expect(t).toBeInstanceOf(u),expect(o.datasource).toEqual(e),expect(o.datasource?.proxy).toBe("safe")}),it("should set the datasource configuration with default proxy",()=>{const n=new a(c),e={proxy:"default"},t=n.setDatasourceConfig(e).build(),o=t._container.get(s.Config);expect(t).toBeInstanceOf(u),expect(o.datasource).toEqual(e),expect(o.datasource?.proxy).toBe("default")}),it("should override the default datasource configuration",()=>{const n=new a(c),e={proxy:"safe"},o=n.setDatasourceConfig(e).build()._container.get(s.Config);expect(o.datasource?.proxy).toBe("safe"),expect(o.datasource).not.toBeUndefined()}),it("should set an empty datasource configuration",()=>{const n=new a(c),e={},t=n.setDatasourceConfig(e).build(),o=t._container.get(s.Config);expect(t).toBeInstanceOf(u),expect(o.datasource).toEqual(e),expect(o.datasource?.proxy).toBeUndefined()})})});
1
+ import{configTypes as s}from"./config/di/configTypes";import{ContextModuleBuilder as r}from"./ContextModuleBuilder";import{DefaultContextModule as a}from"./DefaultContextModule";describe("ContextModuleBuilder",()=>{const i={url:"https://cal/v1",mode:"prod",branch:"main"},u={url:"https://web3checks/v1"},c={originToken:"test"};beforeEach(()=>{vi.resetAllMocks()}),it("should return a default context module",()=>{const e=new r(c).build();expect(e).toBeInstanceOf(a)}),it("should return a custom context module",()=>{const t=new r(c),e={load:vi.fn(),canHandle:vi.fn()},o=t.removeDefaultLoaders().addLoader(e).build();expect(o).toBeInstanceOf(a)}),it("should return a custom context module with a custom typed data loader",()=>{const t=new r(c),e={load:vi.fn()},o=t.removeDefaultLoaders().addTypedDataLoader(e).build();expect(o).toBeInstanceOf(a),expect(o._typedDataLoader).toBe(e)}),it("should return a custom context module with a custom config",()=>{const e=new r(c).setCalConfig(i).setWeb3ChecksConfig(u).build(),o=e._container.get(s.Config);expect(e).toBeInstanceOf(a),expect(o.cal).toEqual(i),expect(o.web3checks).toEqual(u)}),it("should not throw an error if origin token is provided",()=>{const t=new r(c);expect(()=>t.build()).not.toThrow()}),describe("setMetadataServiceConfig",()=>{it("should set the metadata service configuration",()=>{const t=new r(c),e={url:"https://custom-metadata-service.com/v3"},o=t.setMetadataServiceConfig(e).build(),n=o._container.get(s.Config);expect(o).toBeInstanceOf(a),expect(n.metadataServiceDomain).toEqual(e)}),it("should override the default metadata service configuration",()=>{const t=new r(c),e={url:"https://override-metadata-service.com/v1"},n=t.setMetadataServiceConfig(e).build()._container.get(s.Config);expect(n.metadataServiceDomain.url).toBe(e.url),expect(n.metadataServiceDomain.url).not.toBe("https://nft.api.live.ledger.com/v2")})}),describe("setCalConfig",()=>{it("should set the CAL configuration",()=>{const t=new r(c),e={url:"https://custom-cal-service.com/v2",mode:"test",branch:"next"},o=t.setCalConfig(e).build(),n=o._container.get(s.Config);expect(o).toBeInstanceOf(a),expect(n.cal).toEqual(e)}),it("should override the default CAL configuration",()=>{const t=new r(c),e={url:"https://override-cal-service.com/v1",mode:"prod",branch:"demo"},n=t.setCalConfig(e).build()._container.get(s.Config);expect(n.cal.url).toBe(e.url),expect(n.cal.mode).toBe(e.mode),expect(n.cal.branch).toBe(e.branch),expect(n.cal.url).not.toBe("https://crypto-assets-service.api.ledger.com/v1")})}),describe("setWeb3ChecksConfig",()=>{it("should set the web3 checks configuration",()=>{const t=new r(c),e={url:"https://custom-web3checks-service.com/v4"},o=t.setWeb3ChecksConfig(e).build(),n=o._container.get(s.Config);expect(o).toBeInstanceOf(a),expect(n.web3checks).toEqual(e)}),it("should override the default web3 checks configuration",()=>{const t=new r(c),e={url:"https://override-web3checks-service.com/v2"},n=t.setWeb3ChecksConfig(e).build()._container.get(s.Config);expect(n.web3checks.url).toBe(e.url),expect(n.web3checks.url).not.toBe("https://web3checks-backend.api.ledger.com/v3")})}),describe("setDatasourceConfig",()=>{it("should set the datasource configuration with safe proxy",()=>{const t=new r(c),e={proxy:"safe"},o=t.setDatasourceConfig(e).build(),n=o._container.get(s.Config);expect(o).toBeInstanceOf(a),expect(n.datasource).toEqual(e),expect(n.datasource?.proxy).toBe("safe")}),it("should set the datasource configuration with default proxy",()=>{const t=new r(c),e={proxy:"default"},o=t.setDatasourceConfig(e).build(),n=o._container.get(s.Config);expect(o).toBeInstanceOf(a),expect(n.datasource).toEqual(e),expect(n.datasource?.proxy).toBe("default")}),it("should override the default datasource configuration",()=>{const t=new r(c),e={proxy:"safe"},n=t.setDatasourceConfig(e).build()._container.get(s.Config);expect(n.datasource?.proxy).toBe("safe"),expect(n.datasource).not.toBeUndefined()}),it("should set an empty datasource configuration",()=>{const t=new r(c),e={},o=t.setDatasourceConfig(e).build(),n=o._container.get(s.Config);expect(o).toBeInstanceOf(a),expect(n.datasource).toEqual(e),expect(n.datasource?.proxy).toBeUndefined()})}),describe("loggerFactory",()=>{it("should set the loggerFactory when provided in the constructor",()=>{const t=vi.fn(),o=new r({...c,loggerFactory:t}).build(),n=o._container.get(s.Config);expect(o).toBeInstanceOf(a),expect(n.loggerFactory).toBe(t)}),it("should set the loggerFactory via setLoggerFactory",()=>{const t=vi.fn(),o=new r(c).setLoggerFactory(t).build(),n=o._container.get(s.Config);expect(o).toBeInstanceOf(a),expect(n.loggerFactory).toBe(t)}),it("should override constructor loggerFactory with setLoggerFactory",()=>{const t=vi.fn(),e=vi.fn(),l=new r({...c,loggerFactory:t}).setLoggerFactory(e).build()._container.get(s.Config);expect(l.loggerFactory).toBe(e),expect(l.loggerFactory).not.toBe(t)})})});
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 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 { 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 defaultBuilderArgs: ContextModuleConstructorArgs = {\n originToken: \"test\",\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"],
5
- "mappings": "AAEA,OAAS,eAAAA,MAAmB,0BAS5B,OAAS,wBAAAC,MAA4B,yBACrC,OAAS,wBAAAC,MAA4B,yBAErC,SAAS,uBAAwB,IAAM,CACrC,MAAMC,EAA2C,CAC/C,IAAK,iBACL,KAAM,OACN,OAAQ,MACV,EACMC,EAA0B,CAC9B,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AA8D,IAAM,CACrE,MAAMF,EAAuB,IAAIN,EAAqBI,CAAkB,EAClEQ,EAAwD,CAC5D,MAAO,SACT,EAEMP,EAAMC,EACT,oBAAoBM,CAAsB,EAC1C,MAAM,EACHJ,EAAUH,EACd,WACA,IAAyBN,EAAY,MAAM,EAE7C,OAAOM,CAAG,EAAE,eAAeJ,CAAoB,EAC/C,OAAOO,EAAO,UAAU,EAAE,QAAQI,CAAsB,EACxD,OAAOJ,EAAO,YAAY,KAAK,EAAE,KAAK,SAAS,CACjD,CAAC,EAED,GAAG,uDAAwD,IAAM,CAC/D,MAAMF,EAAuB,IAAIN,EAAqBI,CAAkB,EAClEQ,EAAwD,CAC5D,MAAO,MACT,EAKMJ,EAHMF,EACT,oBAAoBM,CAAsB,EAC1C,MAAM,EAEP,WACA,IAAyBb,EAAY,MAAM,EAE7C,OAAOS,EAAO,YAAY,KAAK,EAAE,KAAK,MAAM,EAC5C,OAAOA,EAAO,UAAU,EAAE,IAAI,cAAc,CAC9C,CAAC,EAED,GAAG,+CAAgD,IAAM,CACvD,MAAMF,EAAuB,IAAIN,EAAqBI,CAAkB,EAClEQ,EAAwD,CAAC,EAEzDP,EAAMC,EACT,oBAAoBM,CAAsB,EAC1C,MAAM,EACHJ,EAAUH,EACd,WACA,IAAyBN,EAAY,MAAM,EAE7C,OAAOM,CAAG,EAAE,eAAeJ,CAAoB,EAC/C,OAAOO,EAAO,UAAU,EAAE,QAAQI,CAAsB,EACxD,OAAOJ,EAAO,YAAY,KAAK,EAAE,cAAc,CACjD,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["configTypes", "ContextModuleBuilder", "DefaultContextModule", "defaultCalConfig", "defaultWeb3ChecksConfig", "defaultBuilderArgs", "res", "contextModuleBuilder", "customLoader", "config", "customMetadataConfig", "customCalConfig", "customWeb3ChecksConfig", "customDatasourceConfig"]
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 { 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 defaultBuilderArgs: ContextModuleConstructorArgs = {\n originToken: \"test\",\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"],
5
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E,MAAMK,EAAyD,GAAG,GAAG,EAO/DR,EALuB,IAAIL,EAAqB,CACpD,GAAGI,EACH,cAAAS,CACF,CAAC,EAEgC,MAAM,EACjCL,EAAUH,EACd,WACA,IAAyBN,EAAY,MAAM,EAE7C,OAAOM,CAAG,EAAE,eAAeJ,CAAoB,EAC/C,OAAOO,EAAO,aAAa,EAAE,KAAKK,CAAa,CACjD,CAAC,EAED,GAAG,oDAAqD,IAAM,CAC5D,MAAMA,EAAyD,GAAG,GAAG,EAI/DR,EAFuB,IAAIL,EAAqBI,CAAkB,EAEvC,iBAAiBS,CAAa,EAAE,MAAM,EACjEL,EAAUH,EACd,WACA,IAAyBN,EAAY,MAAM,EAE7C,OAAOM,CAAG,EAAE,eAAeJ,CAAoB,EAC/C,OAAOO,EAAO,aAAa,EAAE,KAAKK,CAAa,CACjD,CAAC,EAED,GAAG,kEAAmE,IAAM,CAC1E,MAAMC,EACJ,GAAG,GAAG,EACFC,EACJ,GAAG,GAAG,EAUFP,EARuB,IAAIR,EAAqB,CACpD,GAAGI,EACH,cAAeU,CACjB,CAAC,EAGE,iBAAiBC,CAAqB,EACtC,MAAM,EAEP,WACA,IAAyBhB,EAAY,MAAM,EAE7C,OAAOS,EAAO,aAAa,EAAE,KAAKO,CAAqB,EACvD,OAAOP,EAAO,aAAa,EAAE,IAAI,KAAKM,CAAwB,CAChE,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["configTypes", "ContextModuleBuilder", "DefaultContextModule", "defaultCalConfig", "defaultWeb3ChecksConfig", "defaultBuilderArgs", "res", "contextModuleBuilder", "customLoader", "config", "customMetadataConfig", "customCalConfig", "customWeb3ChecksConfig", "customDatasourceConfig", "loggerFactory", "constructorLoggerFactory", "overrideLoggerFactory"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{ClearSignContextType as o}from"./shared/model/ClearSignContext";import{DefaultContextModule as d}from"./DefaultContextModule";const u=i=>({load:vi.fn(),canHandle:vi.fn().mockReturnValue(i)}),r=()=>({canHandle:vi.fn(),loadField:vi.fn()});describe("DefaultContextModule",()=>{const i={load:vi.fn()},l={customLoaders:[],defaultLoaders:!1,defaultFieldLoaders:!1,customFieldLoaders:[],customTypedDataLoader:i,cal:{url:"https://cal/v1",mode:"prod",branch:"main"},web3checks:{url:"https://web3checks/v3"},metadataServiceDomain:{url:"https://metadata.com"},originToken:"originToken"};beforeEach(()=>{vi.restoreAllMocks()}),it("should initialize the context module with all the default loaders",async()=>{const t=await new d(l).getContexts({});expect(t).toEqual([])}),it("should return an empty array when no loaders",async()=>{const t=await new d(l).getContexts({});expect(t).toEqual([])}),it("should call all fetch method from metadata fetcher",async()=>{const e=u(!0);await new d({...l,customLoaders:[e,e]}).getContexts({}),expect(e.canHandle).toHaveBeenCalledTimes(2),expect(e.load).toHaveBeenCalledTimes(2)}),it("should return an array of context response",async()=>{const e=u(!0),t=[[{type:"provideERC20Info",payload:"payload1"}],[{type:"provideERC20Info",payload:"payload2"},{type:"plugin",payload:"payload3"}]];vi.spyOn(e,"load").mockResolvedValueOnce(t[0]).mockResolvedValueOnce(t[1]);const a=await new d({...l,customLoaders:[e,e]}).getContexts({});expect(e.canHandle).toHaveBeenCalledTimes(2),expect(e.load).toHaveBeenCalledTimes(2),expect(a).toEqual(t.flat())}),it("should only call loaders that can handle the input",async()=>{const e=u(!0),t=u(!0);vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(t,"canHandle").mockReturnValue(!1),vi.spyOn(e,"load").mockResolvedValue([{type:o.TOKEN,payload:"payload1"}]),vi.spyOn(t,"load").mockResolvedValue([{type:o.NFT,payload:"payload2"}]);const n=new d({...l,customLoaders:[e,t]}),a={to:"0x123",selector:"0xabc"},s=await n.getContexts(a);expect(e.canHandle).toHaveBeenCalledWith(a,Object.values(o)),expect(t.canHandle).toHaveBeenCalledWith(a,Object.values(o)),expect(e.load).toHaveBeenCalledWith(a),expect(t.load).not.toHaveBeenCalled(),expect(s).toEqual([{type:"token",payload:"payload1"}])}),it("should use expected types if provided",async()=>{const e=u(!0);vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(e,"load").mockResolvedValue([{type:o.TOKEN,payload:"payload1"}]);const t=new d({...l,customLoaders:[e]}),n={to:"0x123",selector:"0xabc"};await t.getContexts(n,[o.TOKEN]),expect(e.canHandle).toHaveBeenCalledWith(n,[o.TOKEN])}),it("should call the typed data loader",async()=>{await new d({...l,customTypedDataLoader:i}).getTypedDataFilters({}),expect(i.load).toHaveBeenCalledTimes(1)}),describe("getFieldContext",()=>{it("should return error when no loader can handle the field",async()=>{const e=r();vi.spyOn(e,"canHandle").mockReturnValue(!1);const t=new d({...l,customFieldLoaders:[e]}),n={type:"unknown"},a=await t.getFieldContext(n,o.TOKEN);expect(e.canHandle).toHaveBeenCalledWith(n,o.TOKEN),expect(e.loadField).not.toHaveBeenCalled(),expect(a).toEqual({type:o.ERROR,error:new Error(`Loader not found for field: ${n} and expected type: ${o.TOKEN}`)})}),it("should return context when a loader can handle the field",async()=>{const e=r(),t={type:o.TOKEN,payload:"test-payload"};vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(e,"loadField").mockResolvedValue(t);const n=new d({...l,customFieldLoaders:[e]}),a={type:"token",address:"0x123"},s=await n.getFieldContext(a,o.TOKEN);expect(e.canHandle).toHaveBeenCalledWith(a,o.TOKEN),expect(e.loadField).toHaveBeenCalledWith(a),expect(s).toEqual(t)}),it("should return first context when multiple loaders can handle the field",async()=>{const e=r(),t=r(),n={type:o.TOKEN,payload:"first-payload"},a={type:o.NFT,payload:"second-payload"};vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(t,"canHandle").mockReturnValue(!0),vi.spyOn(e,"loadField").mockResolvedValue(n),vi.spyOn(t,"loadField").mockResolvedValue(a);const s=new d({...l,customFieldLoaders:[e,t]}),c={type:"multi",address:"0x123"},p=await s.getFieldContext(c,o.TOKEN);expect(e.canHandle).toHaveBeenCalledWith(c,o.TOKEN),expect(t.canHandle).toHaveBeenCalledWith(c,o.TOKEN),expect(e.loadField).toHaveBeenCalledWith(c),expect(t.loadField).not.toHaveBeenCalled(),expect(p).toEqual(n)}),it("should return second context when first context is an error",async()=>{const e=r(),t=r(),n={type:o.ERROR,error:new Error("first-error")},a={type:o.TOKEN,payload:"second-payload"};vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(t,"canHandle").mockReturnValue(!0),vi.spyOn(e,"loadField").mockResolvedValue(n),vi.spyOn(t,"loadField").mockResolvedValue(a);const s=new d({...l,customFieldLoaders:[e,t]}),c={type:"error",address:"0x123"},p=await s.getFieldContext(c,o.TOKEN);expect(e.canHandle).toHaveBeenCalledWith(c,o.TOKEN),expect(t.canHandle).toHaveBeenCalledWith(c,o.TOKEN),expect(e.loadField).toHaveBeenCalledWith(c),expect(t.loadField).toHaveBeenCalledWith(c),expect(p).toEqual(a)}),it("should handle loader rejection gracefully",async()=>{const e=r(),t=new Error("Load field failed");vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(e,"loadField").mockRejectedValue(t);const n=new d({...l,customFieldLoaders:[e]}),a={type:"error",address:"0x123"};await expect(n.getFieldContext(a,o.TOKEN)).rejects.toThrow("Load field failed"),expect(e.canHandle).toHaveBeenCalledWith(a,o.TOKEN),expect(e.loadField).toHaveBeenCalledWith(a)})})});
1
+ import{ClearSignContextType as o}from"./shared/model/ClearSignContext";import{NullLoggerPublisherService as x}from"./shared/utils/NullLoggerPublisherService";import{DefaultContextModule as d}from"./DefaultContextModule";const u=i=>({load:vi.fn(),canHandle:vi.fn().mockReturnValue(i)}),r=()=>({canHandle:vi.fn(),loadField:vi.fn()});describe("DefaultContextModule",()=>{const i={load:vi.fn()},l={customLoaders:[],defaultLoaders:!1,defaultFieldLoaders:!1,customFieldLoaders:[],customTypedDataLoader:i,cal:{url:"https://cal/v1",mode:"prod",branch:"main"},web3checks:{url:"https://web3checks/v3"},metadataServiceDomain:{url:"https://metadata.com"},originToken:"originToken",loggerFactory:x};beforeEach(()=>{vi.restoreAllMocks()}),it("should initialize the context module with all the default loaders",async()=>{const t=await new d(l).getContexts({});expect(t).toEqual([])}),it("should return an empty array when no loaders",async()=>{const t=await new d(l).getContexts({});expect(t).toEqual([])}),it("should call all fetch method from metadata fetcher",async()=>{const e=u(!0);await new d({...l,customLoaders:[e,e]}).getContexts({}),expect(e.canHandle).toHaveBeenCalledTimes(2),expect(e.load).toHaveBeenCalledTimes(2)}),it("should return an array of context response",async()=>{const e=u(!0),t=[[{type:"provideERC20Info",payload:"payload1"}],[{type:"provideERC20Info",payload:"payload2"},{type:"plugin",payload:"payload3"}]];vi.spyOn(e,"load").mockResolvedValueOnce(t[0]).mockResolvedValueOnce(t[1]);const a=await new d({...l,customLoaders:[e,e]}).getContexts({});expect(e.canHandle).toHaveBeenCalledTimes(2),expect(e.load).toHaveBeenCalledTimes(2),expect(a).toEqual(t.flat())}),it("should only call loaders that can handle the input",async()=>{const e=u(!0),t=u(!0);vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(t,"canHandle").mockReturnValue(!1),vi.spyOn(e,"load").mockResolvedValue([{type:o.TOKEN,payload:"payload1"}]),vi.spyOn(t,"load").mockResolvedValue([{type:o.NFT,payload:"payload2"}]);const n=new d({...l,customLoaders:[e,t]}),a={to:"0x123",selector:"0xabc"},s=await n.getContexts(a);expect(e.canHandle).toHaveBeenCalledWith(a,Object.values(o)),expect(t.canHandle).toHaveBeenCalledWith(a,Object.values(o)),expect(e.load).toHaveBeenCalledWith(a),expect(t.load).not.toHaveBeenCalled(),expect(s).toEqual([{type:"token",payload:"payload1"}])}),it("should use expected types if provided",async()=>{const e=u(!0);vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(e,"load").mockResolvedValue([{type:o.TOKEN,payload:"payload1"}]);const t=new d({...l,customLoaders:[e]}),n={to:"0x123",selector:"0xabc"};await t.getContexts(n,[o.TOKEN]),expect(e.canHandle).toHaveBeenCalledWith(n,[o.TOKEN])}),it("should call the typed data loader",async()=>{await new d({...l,customTypedDataLoader:i}).getTypedDataFilters({}),expect(i.load).toHaveBeenCalledTimes(1)}),describe("getFieldContext",()=>{it("should return error when no loader can handle the field",async()=>{const e=r();vi.spyOn(e,"canHandle").mockReturnValue(!1);const t=new d({...l,customFieldLoaders:[e]}),n={type:"unknown"},a=await t.getFieldContext(n,o.TOKEN);expect(e.canHandle).toHaveBeenCalledWith(n,o.TOKEN),expect(e.loadField).not.toHaveBeenCalled(),expect(a).toEqual({type:o.ERROR,error:new Error(`Loader not found for field: ${n} and expected type: ${o.TOKEN}`)})}),it("should return context when a loader can handle the field",async()=>{const e=r(),t={type:o.TOKEN,payload:"test-payload"};vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(e,"loadField").mockResolvedValue(t);const n=new d({...l,customFieldLoaders:[e]}),a={type:"token",address:"0x123"},s=await n.getFieldContext(a,o.TOKEN);expect(e.canHandle).toHaveBeenCalledWith(a,o.TOKEN),expect(e.loadField).toHaveBeenCalledWith(a),expect(s).toEqual(t)}),it("should return first context when multiple loaders can handle the field",async()=>{const e=r(),t=r(),n={type:o.TOKEN,payload:"first-payload"},a={type:o.NFT,payload:"second-payload"};vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(t,"canHandle").mockReturnValue(!0),vi.spyOn(e,"loadField").mockResolvedValue(n),vi.spyOn(t,"loadField").mockResolvedValue(a);const s=new d({...l,customFieldLoaders:[e,t]}),c={type:"multi",address:"0x123"},p=await s.getFieldContext(c,o.TOKEN);expect(e.canHandle).toHaveBeenCalledWith(c,o.TOKEN),expect(t.canHandle).toHaveBeenCalledWith(c,o.TOKEN),expect(e.loadField).toHaveBeenCalledWith(c),expect(t.loadField).not.toHaveBeenCalled(),expect(p).toEqual(n)}),it("should return second context when first context is an error",async()=>{const e=r(),t=r(),n={type:o.ERROR,error:new Error("first-error")},a={type:o.TOKEN,payload:"second-payload"};vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(t,"canHandle").mockReturnValue(!0),vi.spyOn(e,"loadField").mockResolvedValue(n),vi.spyOn(t,"loadField").mockResolvedValue(a);const s=new d({...l,customFieldLoaders:[e,t]}),c={type:"error",address:"0x123"},p=await s.getFieldContext(c,o.TOKEN);expect(e.canHandle).toHaveBeenCalledWith(c,o.TOKEN),expect(t.canHandle).toHaveBeenCalledWith(c,o.TOKEN),expect(e.loadField).toHaveBeenCalledWith(c),expect(t.loadField).toHaveBeenCalledWith(c),expect(p).toEqual(a)}),it("should handle loader rejection gracefully",async()=>{const e=r(),t=new Error("Load field failed");vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(e,"loadField").mockRejectedValue(t);const n=new d({...l,customFieldLoaders:[e]}),a={type:"error",address:"0x123"};await expect(n.getFieldContext(a,o.TOKEN)).rejects.toThrow("Load field failed"),expect(e.canHandle).toHaveBeenCalledWith(a,o.TOKEN),expect(e.loadField).toHaveBeenCalledWith(a)})})});
2
2
  //# sourceMappingURL=DefaultContextModule.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/DefaultContextModule.test.ts"],
4
- "sourcesContent": ["import { type ContextModuleConfig } from \"./config/model/ContextModuleConfig\";\nimport { type ContextFieldLoader } from \"./shared/domain/ContextFieldLoader\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport {\n type ClearSignContext,\n ClearSignContextType,\n} from \"./shared/model/ClearSignContext\";\nimport { type TypedDataContext } from \"./shared/model/TypedDataContext\";\nimport type { TypedDataContextLoader } from \"./typed-data/domain/TypedDataContextLoader\";\nimport { DefaultContextModule } from \"./DefaultContextModule\";\n\nconst contextLoaderStubBuilder = (canHandle: boolean): ContextLoader => {\n return {\n load: vi.fn(),\n canHandle: vi\n .fn()\n .mockReturnValue(canHandle) as unknown as ContextLoader[\"canHandle\"],\n };\n};\n\nconst fieldLoaderStubBuilder = (): ContextFieldLoader => {\n return {\n canHandle: vi.fn() as unknown as ContextFieldLoader[\"canHandle\"],\n loadField: vi.fn(),\n };\n};\n\ndescribe(\"DefaultContextModule\", () => {\n const typedDataLoader: TypedDataContextLoader = { load: vi.fn() };\n const defaultContextModuleConfig: ContextModuleConfig = {\n customLoaders: [],\n defaultLoaders: false,\n defaultFieldLoaders: false,\n customFieldLoaders: [],\n customTypedDataLoader: typedDataLoader,\n cal: {\n url: \"https://cal/v1\",\n mode: \"prod\",\n branch: \"main\",\n },\n web3checks: {\n url: \"https://web3checks/v3\",\n },\n metadataServiceDomain: {\n url: \"https://metadata.com\",\n },\n originToken: \"originToken\",\n };\n\n beforeEach(() => {\n vi.restoreAllMocks();\n });\n\n it(\"should initialize the context module with all the default loaders\", async () => {\n const contextModule = new DefaultContextModule(defaultContextModuleConfig);\n\n const res = await contextModule.getContexts({});\n\n expect(res).toEqual([]);\n });\n\n it(\"should return an empty array when no loaders\", async () => {\n const contextModule = new DefaultContextModule(defaultContextModuleConfig);\n\n const res = await contextModule.getContexts({});\n\n expect(res).toEqual([]);\n });\n\n it(\"should call all fetch method from metadata fetcher\", async () => {\n const loader = contextLoaderStubBuilder(true);\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader, loader],\n });\n\n await contextModule.getContexts({});\n\n expect(loader.canHandle).toHaveBeenCalledTimes(2);\n expect(loader.load).toHaveBeenCalledTimes(2);\n });\n\n it(\"should return an array of context response\", async () => {\n const loader = contextLoaderStubBuilder(true);\n const responses = [\n [{ type: \"provideERC20Info\", payload: \"payload1\" }],\n [\n { type: \"provideERC20Info\", payload: \"payload2\" },\n { type: \"plugin\", payload: \"payload3\" },\n ],\n ] as ClearSignContext[][];\n vi.spyOn(loader, \"load\")\n .mockResolvedValueOnce(responses[0]!)\n .mockResolvedValueOnce(responses[1]!);\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader, loader],\n });\n\n const res = await contextModule.getContexts({});\n\n expect(loader.canHandle).toHaveBeenCalledTimes(2);\n expect(loader.load).toHaveBeenCalledTimes(2);\n expect(res).toEqual(responses.flat());\n });\n\n it(\"should only call loaders that can handle the input\", async () => {\n const loader1 = contextLoaderStubBuilder(true);\n const loader2 = contextLoaderStubBuilder(true);\n\n vi.spyOn(loader1, \"canHandle\").mockReturnValue(true);\n vi.spyOn(loader2, \"canHandle\").mockReturnValue(false);\n vi.spyOn(loader1, \"load\").mockResolvedValue([\n { type: ClearSignContextType.TOKEN, payload: \"payload1\" },\n ]);\n vi.spyOn(loader2, \"load\").mockResolvedValue([\n { type: ClearSignContextType.NFT, payload: \"payload2\" },\n ]);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader1, loader2],\n });\n\n const testInput = { to: \"0x123\", selector: \"0xabc\" };\n const res = await contextModule.getContexts(testInput);\n\n expect(loader1.canHandle).toHaveBeenCalledWith(\n testInput,\n Object.values(ClearSignContextType),\n );\n expect(loader2.canHandle).toHaveBeenCalledWith(\n testInput,\n Object.values(ClearSignContextType),\n );\n expect(loader1.load).toHaveBeenCalledWith(testInput);\n expect(loader2.load).not.toHaveBeenCalled(); // Should not be called since canHandle returned false\n expect(res).toEqual([{ type: \"token\", payload: \"payload1\" }]);\n });\n\n it(\"should use expected types if provided\", async () => {\n const loader = contextLoaderStubBuilder(true);\n\n vi.spyOn(loader, \"canHandle\").mockReturnValue(true);\n\n vi.spyOn(loader, \"load\").mockResolvedValue([\n { type: ClearSignContextType.TOKEN, payload: \"payload1\" },\n ]);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader],\n });\n\n const testInput = { to: \"0x123\", selector: \"0xabc\" };\n await contextModule.getContexts(testInput, [ClearSignContextType.TOKEN]);\n\n expect(loader.canHandle).toHaveBeenCalledWith(testInput, [\n ClearSignContextType.TOKEN,\n ]);\n });\n\n it(\"should call the typed data loader\", async () => {\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customTypedDataLoader: typedDataLoader,\n });\n\n await contextModule.getTypedDataFilters({} as TypedDataContext);\n\n expect(typedDataLoader.load).toHaveBeenCalledTimes(1);\n });\n\n describe(\"getFieldContext\", () => {\n it(\"should return error when no loader can handle the field\", async () => {\n // GIVEN\n const fieldLoader = fieldLoaderStubBuilder();\n vi.spyOn(fieldLoader, \"canHandle\").mockReturnValue(false);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader],\n });\n\n const testField = { type: \"unknown\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader.loadField).not.toHaveBeenCalled();\n expect(result).toEqual({\n type: ClearSignContextType.ERROR,\n error: new Error(\n `Loader not found for field: ${testField} and expected type: ${ClearSignContextType.TOKEN}`,\n ),\n });\n });\n\n it(\"should return context when a loader can handle the field\", async () => {\n // GIVEN\n const fieldLoader = fieldLoaderStubBuilder();\n const mockContext: ClearSignContext = {\n type: ClearSignContextType.TOKEN,\n payload: \"test-payload\",\n };\n\n vi.spyOn(fieldLoader, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader, \"loadField\").mockResolvedValue(mockContext);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader],\n });\n\n const testField = { type: \"token\", address: \"0x123\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader.loadField).toHaveBeenCalledWith(testField);\n expect(result).toEqual(mockContext);\n });\n\n it(\"should return first context when multiple loaders can handle the field\", async () => {\n // GIVEN\n const fieldLoader1 = fieldLoaderStubBuilder();\n const fieldLoader2 = fieldLoaderStubBuilder();\n\n const mockContext1: ClearSignContext = {\n type: ClearSignContextType.TOKEN,\n payload: \"first-payload\",\n };\n const mockContext2: ClearSignContext = {\n type: ClearSignContextType.NFT,\n payload: \"second-payload\",\n };\n\n vi.spyOn(fieldLoader1, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader2, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader1, \"loadField\").mockResolvedValue(mockContext1);\n vi.spyOn(fieldLoader2, \"loadField\").mockResolvedValue(mockContext2);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader1, fieldLoader2],\n });\n\n const testField = { type: \"multi\", address: \"0x123\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader1.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader2.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader1.loadField).toHaveBeenCalledWith(testField);\n expect(fieldLoader2.loadField).not.toHaveBeenCalled();\n expect(result).toEqual(mockContext1); // Should return first context\n });\n\n it(\"should return second context when first context is an error\", async () => {\n // GIVEN\n const fieldLoader1 = fieldLoaderStubBuilder();\n const fieldLoader2 = fieldLoaderStubBuilder();\n const mockContext1: ClearSignContext = {\n type: ClearSignContextType.ERROR,\n error: new Error(\"first-error\"),\n };\n const mockContext2: ClearSignContext = {\n type: ClearSignContextType.TOKEN,\n payload: \"second-payload\",\n };\n vi.spyOn(fieldLoader1, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader2, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader1, \"loadField\").mockResolvedValue(mockContext1);\n vi.spyOn(fieldLoader2, \"loadField\").mockResolvedValue(mockContext2);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader1, fieldLoader2],\n });\n\n const testField = { type: \"error\", address: \"0x123\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader1.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader2.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader1.loadField).toHaveBeenCalledWith(testField);\n expect(fieldLoader2.loadField).toHaveBeenCalledWith(testField);\n expect(result).toEqual(mockContext2);\n });\n\n it(\"should handle loader rejection gracefully\", async () => {\n // GIVEN\n const fieldLoader = fieldLoaderStubBuilder();\n const loadError = new Error(\"Load field failed\");\n\n vi.spyOn(fieldLoader, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader, \"loadField\").mockRejectedValue(loadError);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader],\n });\n\n const testField = { type: \"error\", address: \"0x123\" };\n\n // WHEN & THEN\n await expect(\n contextModule.getFieldContext(testField, ClearSignContextType.TOKEN),\n ).rejects.toThrow(\"Load field failed\");\n\n expect(fieldLoader.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader.loadField).toHaveBeenCalledWith(testField);\n });\n });\n});\n"],
5
- "mappings": "AAGA,OAEE,wBAAAA,MACK,kCAGP,OAAS,wBAAAC,MAA4B,yBAErC,MAAMC,EAA4BC,IACzB,CACL,KAAM,GAAG,GAAG,EACZ,UAAW,GACR,GAAG,EACH,gBAAgBA,CAAS,CAC9B,GAGIC,EAAyB,KACtB,CACL,UAAW,GAAG,GAAG,EACjB,UAAW,GAAG,GAAG,CACnB,GAGF,SAAS,uBAAwB,IAAM,CACrC,MAAMC,EAA0C,CAAE,KAAM,GAAG,GAAG,CAAE,EAC1DC,EAAkD,CACtD,cAAe,CAAC,EAChB,eAAgB,GAChB,oBAAqB,GACrB,mBAAoB,CAAC,EACrB,sBAAuBD,EACvB,IAAK,CACH,IAAK,iBACL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,QAAQ,mBAAmB,EAErC,OAAOc,EAAY,SAAS,EAAE,qBAC5BC,EACAf,EAAqB,KACvB,EACA,OAAOc,EAAY,SAAS,EAAE,qBAAqBC,CAAS,CAC9D,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["ClearSignContextType", "DefaultContextModule", "contextLoaderStubBuilder", "canHandle", "fieldLoaderStubBuilder", "typedDataLoader", "defaultContextModuleConfig", "res", "loader", "responses", "loader1", "loader2", "contextModule", "testInput", "fieldLoader", "testField", "result", "mockContext", "fieldLoader1", "fieldLoader2", "mockContext1", "mockContext2", "loadError"]
4
+ "sourcesContent": ["import { type ContextModuleConfig } from \"./config/model/ContextModuleConfig\";\nimport { type ContextFieldLoader } from \"./shared/domain/ContextFieldLoader\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport {\n type ClearSignContext,\n ClearSignContextType,\n} from \"./shared/model/ClearSignContext\";\nimport { type TypedDataContext } from \"./shared/model/TypedDataContext\";\nimport { NullLoggerPublisherService } from \"./shared/utils/NullLoggerPublisherService\";\nimport type { TypedDataContextLoader } from \"./typed-data/domain/TypedDataContextLoader\";\nimport { DefaultContextModule } from \"./DefaultContextModule\";\n\nconst contextLoaderStubBuilder = (canHandle: boolean): ContextLoader => {\n return {\n load: vi.fn(),\n canHandle: vi\n .fn()\n .mockReturnValue(canHandle) as unknown as ContextLoader[\"canHandle\"],\n };\n};\n\nconst fieldLoaderStubBuilder = (): ContextFieldLoader => {\n return {\n canHandle: vi.fn() as unknown as ContextFieldLoader[\"canHandle\"],\n loadField: vi.fn(),\n };\n};\n\ndescribe(\"DefaultContextModule\", () => {\n const typedDataLoader: TypedDataContextLoader = { load: vi.fn() };\n const defaultContextModuleConfig: ContextModuleConfig = {\n customLoaders: [],\n defaultLoaders: false,\n defaultFieldLoaders: false,\n customFieldLoaders: [],\n customTypedDataLoader: typedDataLoader,\n cal: {\n url: \"https://cal/v1\",\n mode: \"prod\",\n branch: \"main\",\n },\n web3checks: {\n url: \"https://web3checks/v3\",\n },\n metadataServiceDomain: {\n url: \"https://metadata.com\",\n },\n originToken: \"originToken\",\n loggerFactory: NullLoggerPublisherService,\n };\n\n beforeEach(() => {\n vi.restoreAllMocks();\n });\n\n it(\"should initialize the context module with all the default loaders\", async () => {\n const contextModule = new DefaultContextModule(defaultContextModuleConfig);\n\n const res = await contextModule.getContexts({});\n\n expect(res).toEqual([]);\n });\n\n it(\"should return an empty array when no loaders\", async () => {\n const contextModule = new DefaultContextModule(defaultContextModuleConfig);\n\n const res = await contextModule.getContexts({});\n\n expect(res).toEqual([]);\n });\n\n it(\"should call all fetch method from metadata fetcher\", async () => {\n const loader = contextLoaderStubBuilder(true);\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader, loader],\n });\n\n await contextModule.getContexts({});\n\n expect(loader.canHandle).toHaveBeenCalledTimes(2);\n expect(loader.load).toHaveBeenCalledTimes(2);\n });\n\n it(\"should return an array of context response\", async () => {\n const loader = contextLoaderStubBuilder(true);\n const responses = [\n [{ type: \"provideERC20Info\", payload: \"payload1\" }],\n [\n { type: \"provideERC20Info\", payload: \"payload2\" },\n { type: \"plugin\", payload: \"payload3\" },\n ],\n ] as ClearSignContext[][];\n vi.spyOn(loader, \"load\")\n .mockResolvedValueOnce(responses[0]!)\n .mockResolvedValueOnce(responses[1]!);\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader, loader],\n });\n\n const res = await contextModule.getContexts({});\n\n expect(loader.canHandle).toHaveBeenCalledTimes(2);\n expect(loader.load).toHaveBeenCalledTimes(2);\n expect(res).toEqual(responses.flat());\n });\n\n it(\"should only call loaders that can handle the input\", async () => {\n const loader1 = contextLoaderStubBuilder(true);\n const loader2 = contextLoaderStubBuilder(true);\n\n vi.spyOn(loader1, \"canHandle\").mockReturnValue(true);\n vi.spyOn(loader2, \"canHandle\").mockReturnValue(false);\n vi.spyOn(loader1, \"load\").mockResolvedValue([\n { type: ClearSignContextType.TOKEN, payload: \"payload1\" },\n ]);\n vi.spyOn(loader2, \"load\").mockResolvedValue([\n { type: ClearSignContextType.NFT, payload: \"payload2\" },\n ]);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader1, loader2],\n });\n\n const testInput = { to: \"0x123\", selector: \"0xabc\" };\n const res = await contextModule.getContexts(testInput);\n\n expect(loader1.canHandle).toHaveBeenCalledWith(\n testInput,\n Object.values(ClearSignContextType),\n );\n expect(loader2.canHandle).toHaveBeenCalledWith(\n testInput,\n Object.values(ClearSignContextType),\n );\n expect(loader1.load).toHaveBeenCalledWith(testInput);\n expect(loader2.load).not.toHaveBeenCalled(); // Should not be called since canHandle returned false\n expect(res).toEqual([{ type: \"token\", payload: \"payload1\" }]);\n });\n\n it(\"should use expected types if provided\", async () => {\n const loader = contextLoaderStubBuilder(true);\n\n vi.spyOn(loader, \"canHandle\").mockReturnValue(true);\n\n vi.spyOn(loader, \"load\").mockResolvedValue([\n { type: ClearSignContextType.TOKEN, payload: \"payload1\" },\n ]);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader],\n });\n\n const testInput = { to: \"0x123\", selector: \"0xabc\" };\n await contextModule.getContexts(testInput, [ClearSignContextType.TOKEN]);\n\n expect(loader.canHandle).toHaveBeenCalledWith(testInput, [\n ClearSignContextType.TOKEN,\n ]);\n });\n\n it(\"should call the typed data loader\", async () => {\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customTypedDataLoader: typedDataLoader,\n });\n\n await contextModule.getTypedDataFilters({} as TypedDataContext);\n\n expect(typedDataLoader.load).toHaveBeenCalledTimes(1);\n });\n\n describe(\"getFieldContext\", () => {\n it(\"should return error when no loader can handle the field\", async () => {\n // GIVEN\n const fieldLoader = fieldLoaderStubBuilder();\n vi.spyOn(fieldLoader, \"canHandle\").mockReturnValue(false);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader],\n });\n\n const testField = { type: \"unknown\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader.loadField).not.toHaveBeenCalled();\n expect(result).toEqual({\n type: ClearSignContextType.ERROR,\n error: new Error(\n `Loader not found for field: ${testField} and expected type: ${ClearSignContextType.TOKEN}`,\n ),\n });\n });\n\n it(\"should return context when a loader can handle the field\", async () => {\n // GIVEN\n const fieldLoader = fieldLoaderStubBuilder();\n const mockContext: ClearSignContext = {\n type: ClearSignContextType.TOKEN,\n payload: \"test-payload\",\n };\n\n vi.spyOn(fieldLoader, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader, \"loadField\").mockResolvedValue(mockContext);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader],\n });\n\n const testField = { type: \"token\", address: \"0x123\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader.loadField).toHaveBeenCalledWith(testField);\n expect(result).toEqual(mockContext);\n });\n\n it(\"should return first context when multiple loaders can handle the field\", async () => {\n // GIVEN\n const fieldLoader1 = fieldLoaderStubBuilder();\n const fieldLoader2 = fieldLoaderStubBuilder();\n\n const mockContext1: ClearSignContext = {\n type: ClearSignContextType.TOKEN,\n payload: \"first-payload\",\n };\n const mockContext2: ClearSignContext = {\n type: ClearSignContextType.NFT,\n payload: \"second-payload\",\n };\n\n vi.spyOn(fieldLoader1, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader2, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader1, \"loadField\").mockResolvedValue(mockContext1);\n vi.spyOn(fieldLoader2, \"loadField\").mockResolvedValue(mockContext2);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader1, fieldLoader2],\n });\n\n const testField = { type: \"multi\", address: \"0x123\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader1.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader2.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader1.loadField).toHaveBeenCalledWith(testField);\n expect(fieldLoader2.loadField).not.toHaveBeenCalled();\n expect(result).toEqual(mockContext1); // Should return first context\n });\n\n it(\"should return second context when first context is an error\", async () => {\n // GIVEN\n const fieldLoader1 = fieldLoaderStubBuilder();\n const fieldLoader2 = fieldLoaderStubBuilder();\n const mockContext1: ClearSignContext = {\n type: ClearSignContextType.ERROR,\n error: new Error(\"first-error\"),\n };\n const mockContext2: ClearSignContext = {\n type: ClearSignContextType.TOKEN,\n payload: \"second-payload\",\n };\n vi.spyOn(fieldLoader1, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader2, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader1, \"loadField\").mockResolvedValue(mockContext1);\n vi.spyOn(fieldLoader2, \"loadField\").mockResolvedValue(mockContext2);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader1, fieldLoader2],\n });\n\n const testField = { type: \"error\", address: \"0x123\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader1.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader2.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader1.loadField).toHaveBeenCalledWith(testField);\n expect(fieldLoader2.loadField).toHaveBeenCalledWith(testField);\n expect(result).toEqual(mockContext2);\n });\n\n it(\"should handle loader rejection gracefully\", async () => {\n // GIVEN\n const fieldLoader = fieldLoaderStubBuilder();\n const loadError = new Error(\"Load field failed\");\n\n vi.spyOn(fieldLoader, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader, \"loadField\").mockRejectedValue(loadError);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader],\n });\n\n const testField = { type: \"error\", address: \"0x123\" };\n\n // WHEN & THEN\n await expect(\n contextModule.getFieldContext(testField, ClearSignContextType.TOKEN),\n ).rejects.toThrow(\"Load field failed\");\n\n expect(fieldLoader.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader.loadField).toHaveBeenCalledWith(testField);\n });\n });\n});\n"],
5
+ "mappings": "AAGA,OAEE,wBAAAA,MACK,kCAEP,OAAS,8BAAAC,MAAkC,4CAE3C,OAAS,wBAAAC,MAA4B,yBAErC,MAAMC,EAA4BC,IACzB,CACL,KAAM,GAAG,GAAG,EACZ,UAAW,GACR,GAAG,EACH,gBAAgBA,CAAS,CAC9B,GAGIC,EAAyB,KACtB,CACL,UAAW,GAAG,GAAG,EACjB,UAAW,GAAG,GAAG,CACnB,GAGF,SAAS,uBAAwB,IAAM,CACrC,MAAMC,EAA0C,CAAE,KAAM,GAAG,GAAG,CAAE,EAC1DC,EAAkD,CACtD,cAAe,CAAC,EAChB,eAAgB,GAChB,oBAAqB,GACrB,mBAAoB,CAAC,EACrB,sBAAuBD,EACvB,IAAK,CACH,IAAK,iBACL,KAAM,OACN,OAAQ,MACV,EACA,WAAY,CACV,IAAK,uBACP,EACA,sBAAuB,CACrB,IAAK,sBACP,EACA,YAAa,cACb,cAAeL,CACjB,EAEA,WAAW,IAAM,CACf,GAAG,gBAAgB,CACrB,CAAC,EAED,GAAG,oEAAqE,SAAY,CAGlF,MAAMO,EAAM,M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extType", "NullLoggerPublisherService", "DefaultContextModule", "contextLoaderStubBuilder", "canHandle", "fieldLoaderStubBuilder", "typedDataLoader", "defaultContextModuleConfig", "res", "loader", "responses", "loader1", "loader2", "contextModule", "testInput", "fieldLoader", "testField", "result", "mockContext", "fieldLoader1", "fieldLoader2", "mockContext1", "mockContext2", "loadError"]
7
7
  }
@@ -1,2 +1,2 @@
1
- const o={Config:Symbol.for("config"),OriginToken:Symbol.for("originToken")};export{o as configTypes};
1
+ const o={Config:Symbol.for("config"),OriginToken:Symbol.for("originToken"),ContextModuleLoggerFactory:Symbol.for("contextModuleLoggerFactory")};export{o as configTypes};
2
2
  //# sourceMappingURL=configTypes.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/config/di/configTypes.ts"],
4
- "sourcesContent": ["export const configTypes = {\n Config: Symbol.for(\"config\"),\n OriginToken: Symbol.for(\"originToken\"),\n};\n"],
5
- "mappings": "AAAO,MAAMA,EAAc,CACzB,OAAQ,OAAO,IAAI,QAAQ,EAC3B,YAAa,OAAO,IAAI,aAAa,CACvC",
4
+ "sourcesContent": ["export const configTypes = {\n Config: Symbol.for(\"config\"),\n OriginToken: Symbol.for(\"originToken\"),\n ContextModuleLoggerFactory: Symbol.for(\"contextModuleLoggerFactory\"),\n};\n"],
5
+ "mappings": "AAAO,MAAMA,EAAc,CACzB,OAAQ,OAAO,IAAI,QAAQ,EAC3B,YAAa,OAAO,IAAI,aAAa,EACrC,2BAA4B,OAAO,IAAI,4BAA4B,CACrE",
6
6
  "names": ["configTypes"]
7
7
  }
package/lib/esm/src/di.js CHANGED
@@ -1,2 +1,2 @@
1
- import{Container as t}from"inversify";import{calldataModuleFactory as a}from"./calldata/di/calldataModuleFactory";import{configModuleFactory as e}from"./config/di/configModuleFactory";import{dynamicNetworkModuleFactory as m}from"./dynamic-network/di/dynamicNetworkModuleFactory";import{externalPluginModuleFactory as n}from"./external-plugin/di/externalPluginModuleFactory";import{nftModuleFactory as i}from"./nft/di/nftModuleFactory";import{nanoPkiModuleFactory as l}from"./pki/di/pkiModuleFactory";import{proxyModuleFactory as c}from"./proxy/di/proxyModuleFactory";import{safeModuleFactory as f}from"./safe/di/safeModuleFactory";import{solanaContextModuleFactory as p}from"./solana/di/SolanaContextModuleFactory";import{solanaLifiModuleFactory as d}from"./solanaLifi/di/lifiModuleFactory";import{solanaTokenModuleFactory as u}from"./solanaToken/di/tokenModuleFactory";import{tokenModuleFactory as y}from"./token/di/tokenModuleFactory";import{transactionCheckModuleFactory as M}from"./transaction-check/di/transactionCheckModuleFactory";import{trustedNameModuleFactory as F}from"./trusted-name/di/trustedNameModuleFactory";import{typedDataModuleFactory as s}from"./typed-data/di/typedDataModuleFactory";import{uniswapModuleFactory as C}from"./uniswap/di/uniswapModuleFactory";const B=({config:o})=>{const r=new t;return r.loadSync(e(o),n(),m(),i(),c(o),f(),y(),a(),F(),s(),l(),C(),M(),p(),u(),d()),r};export{B as makeContainer};
1
+ import{Container as t}from"inversify";import{calldataModuleFactory as e}from"./calldata/di/calldataModuleFactory";import{configModuleFactory as a}from"./config/di/configModuleFactory";import{configTypes as m}from"./config/di/configTypes";import{dynamicNetworkModuleFactory as i}from"./dynamic-network/di/dynamicNetworkModuleFactory";import{externalPluginModuleFactory as n}from"./external-plugin/di/externalPluginModuleFactory";import{nftModuleFactory as l}from"./nft/di/nftModuleFactory";import{nanoPkiModuleFactory as c}from"./pki/di/pkiModuleFactory";import{proxyModuleFactory as p}from"./proxy/di/proxyModuleFactory";import{safeModuleFactory as y}from"./safe/di/safeModuleFactory";import{solanaContextModuleFactory as f}from"./solana/di/SolanaContextModuleFactory";import{solanaLifiModuleFactory as u}from"./solanaLifi/di/lifiModuleFactory";import{solanaTokenModuleFactory as d}from"./solanaToken/di/tokenModuleFactory";import{tokenModuleFactory as M}from"./token/di/tokenModuleFactory";import{transactionCheckModuleFactory as F}from"./transaction-check/di/transactionCheckModuleFactory";import{trustedNameModuleFactory as g}from"./trusted-name/di/trustedNameModuleFactory";import{typedDataModuleFactory as s}from"./typed-data/di/typedDataModuleFactory";import{uniswapModuleFactory as C}from"./uniswap/di/uniswapModuleFactory";const E=({config:o})=>{const r=new t;return o.loggerFactory&&r.bind(m.ContextModuleLoggerFactory).toConstantValue(o.loggerFactory),r.loadSync(a(o),n(),i(),l(),p(o),y(),M(),e(),g(),s(),c(),C(),F(),f(),d(),u()),r};export{E as makeContainer};
2
2
  //# sourceMappingURL=di.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/di.ts"],
4
- "sourcesContent": ["import { Container } from \"inversify\";\n\nimport { calldataModuleFactory } from \"@/calldata/di/calldataModuleFactory\";\nimport { configModuleFactory } from \"@/config/di/configModuleFactory\";\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { dynamicNetworkModuleFactory } from \"@/dynamic-network/di/dynamicNetworkModuleFactory\";\nimport { externalPluginModuleFactory } from \"@/external-plugin/di/externalPluginModuleFactory\";\nimport { nftModuleFactory } from \"@/nft/di/nftModuleFactory\";\nimport { nanoPkiModuleFactory } from \"@/pki/di/pkiModuleFactory\";\nimport { proxyModuleFactory } from \"@/proxy/di/proxyModuleFactory\";\nimport { safeModuleFactory } from \"@/safe/di/safeModuleFactory\";\nimport { solanaContextModuleFactory } from \"@/solana/di/SolanaContextModuleFactory\";\nimport { solanaLifiModuleFactory } from \"@/solanaLifi/di/lifiModuleFactory\";\nimport { solanaTokenModuleFactory } from \"@/solanaToken/di/tokenModuleFactory\";\nimport { tokenModuleFactory } from \"@/token/di/tokenModuleFactory\";\nimport { transactionCheckModuleFactory } from \"@/transaction-check/di/transactionCheckModuleFactory\";\nimport { trustedNameModuleFactory } from \"@/trusted-name/di/trustedNameModuleFactory\";\nimport { typedDataModuleFactory } from \"@/typed-data/di/typedDataModuleFactory\";\nimport { uniswapModuleFactory } from \"@/uniswap/di/uniswapModuleFactory\";\n\ntype MakeContainerArgs = {\n config: ContextModuleConfig;\n};\n\nexport const makeContainer = ({ config }: MakeContainerArgs) => {\n const container = new Container();\n\n container.loadSync(\n configModuleFactory(config),\n externalPluginModuleFactory(),\n dynamicNetworkModuleFactory(),\n nftModuleFactory(),\n proxyModuleFactory(config),\n safeModuleFactory(),\n tokenModuleFactory(),\n calldataModuleFactory(),\n trustedNameModuleFactory(),\n typedDataModuleFactory(),\n nanoPkiModuleFactory(),\n uniswapModuleFactory(),\n transactionCheckModuleFactory(),\n solanaContextModuleFactory(),\n solanaTokenModuleFactory(),\n solanaLifiModuleFactory(),\n );\n\n return container;\n};\n"],
5
- "mappings": "AAAA,OAAS,aAAAA,MAAiB,YAE1B,OAAS,yBAAAC,MAA6B,sCACtC,OAAS,uBAAAC,MAA2B,kCAEpC,OAAS,+BAAAC,MAAmC,mDAC5C,OAAS,+BAAAC,MAAmC,mDAC5C,OAAS,oBAAAC,MAAwB,4BACjC,OAAS,wBAAAC,MAA4B,4BACrC,OAAS,sBAAAC,MAA0B,gCACnC,OAAS,qBAAAC,MAAyB,8BAClC,OAAS,8BAAAC,MAAkC,yCAC3C,OAAS,2BAAAC,MAA+B,oCACxC,OAAS,4BAAAC,MAAgC,sCACzC,OAAS,sBAAAC,MAA0B,gCACnC,OAAS,iCAAAC,MAAqC,uDAC9C,OAAS,4BAAAC,MAAgC,6CACzC,OAAS,0BAAAC,MAA8B,yCACvC,OAAS,wBAAAC,MAA4B,oCAM9B,MAAMC,EAAgB,CAAC,CAAE,OAAAC,CAAO,IAAyB,CAC9D,MAAMC,EAAY,IAAInB,EAEtB,OAAAmB,EAAU,SACRjB,EAAoBgB,CAAM,EAC1Bd,EAA4B,EAC5BD,EAA4B,EAC5BE,EAAiB,EACjBE,EAAmBW,CAAM,EACzBV,EAAkB,EAClBI,EAAmB,EACnBX,EAAsB,EACtBa,EAAyB,EACzBC,EAAuB,EACvBT,EAAqB,EACrBU,EAAqB,EACrBH,EAA8B,EAC9BJ,EAA2B,EAC3BE,EAAyB,EACzBD,EAAwB,CAC1B,EAEOS,CACT",
6
- "names": ["Container", "calldataModuleFactory", "configModuleFactory", "dynamicNetworkModuleFactory", "externalPluginModuleFactory", "nftModuleFactory", "nanoPkiModuleFactory", "proxyModuleFactory", "safeModuleFactory", "solanaContextModuleFactory", "solanaLifiModuleFactory", "solanaTokenModuleFactory", "tokenModuleFactory", "transactionCheckModuleFactory", "trustedNameModuleFactory", "typedDataModuleFactory", "uniswapModuleFactory", "makeContainer", "config", "container"]
4
+ "sourcesContent": ["import { type LoggerPublisherService } from \"@ledgerhq/device-management-kit\";\nimport { Container } from \"inversify\";\n\nimport { calldataModuleFactory } from \"@/calldata/di/calldataModuleFactory\";\nimport { configModuleFactory } from \"@/config/di/configModuleFactory\";\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { dynamicNetworkModuleFactory } from \"@/dynamic-network/di/dynamicNetworkModuleFactory\";\nimport { externalPluginModuleFactory } from \"@/external-plugin/di/externalPluginModuleFactory\";\nimport { nftModuleFactory } from \"@/nft/di/nftModuleFactory\";\nimport { nanoPkiModuleFactory } from \"@/pki/di/pkiModuleFactory\";\nimport { proxyModuleFactory } from \"@/proxy/di/proxyModuleFactory\";\nimport { safeModuleFactory } from \"@/safe/di/safeModuleFactory\";\nimport { solanaContextModuleFactory } from \"@/solana/di/SolanaContextModuleFactory\";\nimport { solanaLifiModuleFactory } from \"@/solanaLifi/di/lifiModuleFactory\";\nimport { solanaTokenModuleFactory } from \"@/solanaToken/di/tokenModuleFactory\";\nimport { tokenModuleFactory } from \"@/token/di/tokenModuleFactory\";\nimport { transactionCheckModuleFactory } from \"@/transaction-check/di/transactionCheckModuleFactory\";\nimport { trustedNameModuleFactory } from \"@/trusted-name/di/trustedNameModuleFactory\";\nimport { typedDataModuleFactory } from \"@/typed-data/di/typedDataModuleFactory\";\nimport { uniswapModuleFactory } from \"@/uniswap/di/uniswapModuleFactory\";\n\ntype MakeContainerArgs = {\n config: ContextModuleConfig;\n};\n\nexport const makeContainer = ({ config }: MakeContainerArgs) => {\n const container = new Container();\n\n if (config.loggerFactory) {\n container\n .bind<\n (tag: string) => LoggerPublisherService\n >(configTypes.ContextModuleLoggerFactory)\n .toConstantValue(config.loggerFactory);\n }\n\n container.loadSync(\n configModuleFactory(config),\n externalPluginModuleFactory(),\n dynamicNetworkModuleFactory(),\n nftModuleFactory(),\n proxyModuleFactory(config),\n safeModuleFactory(),\n tokenModuleFactory(),\n calldataModuleFactory(),\n trustedNameModuleFactory(),\n typedDataModuleFactory(),\n nanoPkiModuleFactory(),\n uniswapModuleFactory(),\n transactionCheckModuleFactory(),\n solanaContextModuleFactory(),\n solanaTokenModuleFactory(),\n solanaLifiModuleFactory(),\n );\n\n return container;\n};\n"],
5
+ "mappings": "AACA,OAAS,aAAAA,MAAiB,YAE1B,OAAS,yBAAAC,MAA6B,sCACtC,OAAS,uBAAAC,MAA2B,kCACpC,OAAS,eAAAC,MAAmB,0BAE5B,OAAS,+BAAAC,MAAmC,mDAC5C,OAAS,+BAAAC,MAAmC,mDAC5C,OAAS,oBAAAC,MAAwB,4BACjC,OAAS,wBAAAC,MAA4B,4BACrC,OAAS,sBAAAC,MAA0B,gCACnC,OAAS,qBAAAC,MAAyB,8BAClC,OAAS,8BAAAC,MAAkC,yCAC3C,OAAS,2BAAAC,MAA+B,oCACxC,OAAS,4BAAAC,MAAgC,sCACzC,OAAS,sBAAAC,MAA0B,gCACnC,OAAS,iCAAAC,MAAqC,uDAC9C,OAAS,4BAAAC,MAAgC,6CACzC,OAAS,0BAAAC,MAA8B,yCACvC,OAAS,wBAAAC,MAA4B,oCAM9B,MAAMC,EAAgB,CAAC,CAAE,OAAAC,CAAO,IAAyB,CAC9D,MAAMC,EAAY,IAAIpB,EAEtB,OAAImB,EAAO,eACTC,EACG,KAECjB,EAAY,0BAA0B,EACvC,gBAAgBgB,EAAO,aAAa,EAGzCC,EAAU,SACRlB,EAAoBiB,CAAM,EAC1Bd,EAA4B,EAC5BD,EAA4B,EAC5BE,EAAiB,EACjBE,EAAmBW,CAAM,EACzBV,EAAkB,EAClBI,EAAmB,EACnBZ,EAAsB,EACtBc,EAAyB,EACzBC,EAAuB,EACvBT,EAAqB,EACrBU,EAAqB,EACrBH,EAA8B,EAC9BJ,EAA2B,EAC3BE,EAAyB,EACzBD,EAAwB,CAC1B,EAEOS,CACT",
6
+ "names": ["Container", "calldataModuleFactory", "configModuleFactory", "configTypes", "dynamicNetworkModuleFactory", "externalPluginModuleFactory", "nftModuleFactory", "nanoPkiModuleFactory", "proxyModuleFactory", "safeModuleFactory", "solanaContextModuleFactory", "solanaLifiModuleFactory", "solanaTokenModuleFactory", "tokenModuleFactory", "transactionCheckModuleFactory", "trustedNameModuleFactory", "typedDataModuleFactory", "uniswapModuleFactory", "makeContainer", "config", "container"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/shared/model/TypedDataClearSignContext.ts"],
4
- "sourcesContent": ["import type { HexaString } from \"@ledgerhq/device-management-kit\";\n\nimport {\n type ClearSignContextSuccess,\n type ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { type TransactionSubset } from \"@/shared/model/TransactionSubset\";\n\n// The general informations for a typed message\nexport type TypedDataMessageInfo = {\n displayName: string;\n filtersCount: number;\n signature: string;\n};\n\n// Token index and descriptor. Needed for tokens that are referenced by a typed message\nexport type TypedDataTokenIndex = number;\nexport type TypedDataToken = string;\n// Calldata index. Needed for calldatas that are referenced by a typed message\nexport type TypedDataCalldataIndex = number;\n// Special token index value when the referenced token is the verifying contract\nexport const VERIFYING_CONTRACT_TOKEN_INDEX = 255;\n\n// Typed message filters, to select fields to display, and provide formatting informations\nexport type TypedDataFilterPath = string;\nexport type TypedDataFilterWithToken = {\n type: \"amount\" | \"token\";\n displayName: string;\n tokenIndex: TypedDataTokenIndex;\n path: TypedDataFilterPath;\n signature: string;\n};\nexport type TypedDataFilterWithTrustedName = {\n type: \"trusted-name\";\n displayName: string;\n types: string[];\n sources: string[];\n typesAndSourcesPayload: string;\n path: TypedDataFilterPath;\n signature: string;\n};\nexport type TypedDataFilterCalldata = {\n type:\n | \"calldata-value\"\n | \"calldata-callee\"\n | \"calldata-chain-id\"\n | \"calldata-selector\"\n | \"calldata-amount\"\n | \"calldata-spender\";\n displayName: string;\n calldataIndex: TypedDataCalldataIndex;\n path: TypedDataFilterPath;\n signature: string;\n};\nexport type TypedDataFilter =\n | {\n type: \"datetime\" | \"raw\";\n displayName: string;\n path: TypedDataFilterPath;\n signature: string;\n }\n | TypedDataFilterWithToken\n | TypedDataFilterWithTrustedName\n | TypedDataFilterCalldata;\n\n// Calldata info when referenced by a typed message\nexport enum TypedDataCalldataParamPresence {\n None = \"none\",\n Present = \"present\",\n VerifyingContract = \"verifying_contract\",\n}\nexport type TypedDataFilterCalldataInfo = {\n displayName: string;\n calldataIndex: TypedDataCalldataIndex;\n valueFlag: boolean;\n calleeFlag: TypedDataCalldataParamPresence;\n chainIdFlag: boolean;\n selectorFlag: boolean;\n amountFlag: boolean;\n spenderFlag: TypedDataCalldataParamPresence;\n signature: string;\n};\nexport type TypedDataCalldataInfo = {\n filter: TypedDataFilterCalldataInfo;\n subset: TransactionSubset;\n};\n\n// Clear signing context for a typed message\nexport type TypedDataClearSignContextSuccess = {\n type: \"success\";\n messageInfo: TypedDataMessageInfo;\n filters: Record<TypedDataFilterPath, TypedDataFilter>;\n trustedNamesAddresses: Record<TypedDataFilterPath, HexaString>;\n tokens: Record<TypedDataTokenIndex, TypedDataToken>;\n calldatas: Record<TypedDataCalldataIndex, TypedDataCalldataInfo>;\n proxy?: ClearSignContextSuccess<ClearSignContextType.PROXY_INFO>;\n};\nexport type TypedDataClearSignContextError = {\n type: \"error\";\n error: Error;\n};\nexport type TypedDataClearSignContext =\n | TypedDataClearSignContextSuccess\n | TypedDataClearSignContextError;\n"],
5
- "mappings": "AAqBO,MAAMA,EAAiC,IA6CvC,IAAKC,OACVA,EAAA,KAAO,OACPA,EAAA,QAAU,UACVA,EAAA,kBAAoB,qBAHVA,OAAA",
4
+ "sourcesContent": ["import type { HexaString } from \"@ledgerhq/device-management-kit\";\n\nimport { type PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport {\n type ClearSignContextSuccess,\n type ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { type TransactionSubset } from \"@/shared/model/TransactionSubset\";\n\n// The general informations for a typed message\nexport type TypedDataMessageInfo = {\n displayName: string;\n filtersCount: number;\n signature: string;\n};\n\n// Token index and descriptor. Needed for tokens that are referenced by a typed message\nexport type TypedDataTokenIndex = number;\nexport type TypedDataToken = string;\n// Calldata index. Needed for calldatas that are referenced by a typed message\nexport type TypedDataCalldataIndex = number;\n// Special token index value when the referenced token is the verifying contract\nexport const VERIFYING_CONTRACT_TOKEN_INDEX = 255;\n\n// Typed message filters, to select fields to display, and provide formatting informations\nexport type TypedDataFilterPath = string;\nexport type TypedDataFilterWithToken = {\n type: \"amount\" | \"token\";\n displayName: string;\n tokenIndex: TypedDataTokenIndex;\n path: TypedDataFilterPath;\n signature: string;\n};\nexport type TypedDataFilterWithTrustedName = {\n type: \"trusted-name\";\n displayName: string;\n types: string[];\n sources: string[];\n typesAndSourcesPayload: string;\n path: TypedDataFilterPath;\n signature: string;\n};\nexport type TypedDataFilterCalldata = {\n type:\n | \"calldata-value\"\n | \"calldata-callee\"\n | \"calldata-chain-id\"\n | \"calldata-selector\"\n | \"calldata-amount\"\n | \"calldata-spender\";\n displayName: string;\n calldataIndex: TypedDataCalldataIndex;\n path: TypedDataFilterPath;\n signature: string;\n};\nexport type TypedDataFilter =\n | {\n type: \"datetime\" | \"raw\";\n displayName: string;\n path: TypedDataFilterPath;\n signature: string;\n }\n | TypedDataFilterWithToken\n | TypedDataFilterWithTrustedName\n | TypedDataFilterCalldata;\n\n// Calldata info when referenced by a typed message\nexport enum TypedDataCalldataParamPresence {\n None = \"none\",\n Present = \"present\",\n VerifyingContract = \"verifying_contract\",\n}\nexport type TypedDataFilterCalldataInfo = {\n displayName: string;\n calldataIndex: TypedDataCalldataIndex;\n valueFlag: boolean;\n calleeFlag: TypedDataCalldataParamPresence;\n chainIdFlag: boolean;\n selectorFlag: boolean;\n amountFlag: boolean;\n spenderFlag: TypedDataCalldataParamPresence;\n signature: string;\n};\nexport type TypedDataCalldataInfo = {\n filter: TypedDataFilterCalldataInfo;\n subset: TransactionSubset;\n};\n\n// Clear signing context for a typed message\nexport type TypedDataClearSignContextSuccess = {\n type: \"success\";\n messageInfo: TypedDataMessageInfo;\n filters: Record<TypedDataFilterPath, TypedDataFilter>;\n trustedNamesAddresses: Record<TypedDataFilterPath, HexaString>;\n tokens: Record<TypedDataTokenIndex, TypedDataToken>;\n calldatas: Record<TypedDataCalldataIndex, TypedDataCalldataInfo>;\n certificate?: PkiCertificate;\n proxy?: ClearSignContextSuccess<ClearSignContextType.PROXY_INFO>;\n};\nexport type TypedDataClearSignContextError = {\n type: \"error\";\n error: Error;\n};\nexport type TypedDataClearSignContext =\n | TypedDataClearSignContextSuccess\n | TypedDataClearSignContextError;\n"],
5
+ "mappings": "AAsBO,MAAMA,EAAiC,IA6CvC,IAAKC,OACVA,EAAA,KAAO,OACPA,EAAA,QAAU,UACVA,EAAA,kBAAoB,qBAHVA,OAAA",
6
6
  "names": ["VERIFYING_CONTRACT_TOKEN_INDEX", "TypedDataCalldataParamPresence"]
7
7
  }
@@ -0,0 +1,2 @@
1
+ const r=e=>({debug:()=>{},info:()=>{},warn:()=>{},error:()=>{},subscribers:[]});export{r as NullLoggerPublisherService};
2
+ //# sourceMappingURL=NullLoggerPublisherService.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/shared/utils/NullLoggerPublisherService.ts"],
4
+ "sourcesContent": ["import type { LoggerPublisherService } from \"@ledgerhq/device-management-kit\";\n\nexport const NullLoggerPublisherService: (\n tag: string,\n) => LoggerPublisherService = (_tag: string) => ({\n debug: () => {\n // no-op\n },\n info: () => {\n // no-op\n },\n warn: () => {\n // no-op\n },\n error: () => {\n // no-op\n },\n subscribers: [],\n});\n"],
5
+ "mappings": "AAEO,MAAMA,EAEkBC,IAAkB,CAC/C,MAAO,IAAM,CAEb,EACA,KAAM,IAAM,CAEZ,EACA,KAAM,IAAM,CAEZ,EACA,MAAO,IAAM,CAEb,EACA,YAAa,CAAC,CAChB",
6
+ "names": ["NullLoggerPublisherService", "_tag"]
7
+ }
@@ -0,0 +1,2 @@
1
+ import{describe as i,expect as o,it as t}from"vitest";import{NullLoggerPublisherService as r}from"./NullLoggerPublisherService";i("NullLoggerPublisherService",()=>{t("returns a LoggerPublisherService-like obj",()=>{const e=r("any-tag");o(e).toBeDefined(),o(typeof e.debug).toBe("function"),o(typeof e.info).toBe("function"),o(typeof e.warn).toBe("function"),o(typeof e.error).toBe("function"),o(Array.isArray(e.subscribers)).toBe(!0),o(e.subscribers).toHaveLength(0)}),t("methods are no-ops (do not throw)",()=>{const e=r("test");o(()=>e.debug("hello")).not.toThrow(),o(()=>e.info("hello")).not.toThrow(),o(()=>e.warn("hello")).not.toThrow(),o(()=>e.error("hello")).not.toThrow(),o(()=>e.debug("hello",{data:{a:1}})).not.toThrow()}),t("returns a new object per call (current implementation)",()=>{const e=r("x"),n=r("x");o(e).not.toBe(n)})});
2
+ //# sourceMappingURL=NullLoggerPublisherService.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/shared/utils/NullLoggerPublisherService.test.ts"],
4
+ "sourcesContent": ["import type { LoggerPublisherService } from \"@ledgerhq/device-management-kit\";\nimport { describe, expect, it } from \"vitest\";\n\nimport { NullLoggerPublisherService } from \"./NullLoggerPublisherService\";\n\ndescribe(\"NullLoggerPublisherService\", () => {\n it(\"returns a LoggerPublisherService-like obj\", () => {\n const logger = NullLoggerPublisherService(\n \"any-tag\",\n ) as LoggerPublisherService;\n\n expect(logger).toBeDefined();\n expect(typeof logger.debug).toBe(\"function\");\n expect(typeof logger.info).toBe(\"function\");\n expect(typeof logger.warn).toBe(\"function\");\n expect(typeof logger.error).toBe(\"function\");\n expect(Array.isArray(logger.subscribers)).toBe(true);\n expect(logger.subscribers).toHaveLength(0);\n });\n\n it(\"methods are no-ops (do not throw)\", () => {\n const logger = NullLoggerPublisherService(\"test\");\n\n expect(() => logger.debug(\"hello\")).not.toThrow();\n expect(() => logger.info(\"hello\")).not.toThrow();\n expect(() => logger.warn(\"hello\")).not.toThrow();\n expect(() => logger.error(\"hello\")).not.toThrow();\n\n expect(() => logger.debug(\"hello\", { data: { a: 1 } })).not.toThrow();\n });\n\n it(\"returns a new object per call (current implementation)\", () => {\n const logger1 = NullLoggerPublisherService(\"x\");\n const logger2 = NullLoggerPublisherService(\"x\");\n\n expect(logger1).not.toBe(logger2);\n });\n});\n"],
5
+ "mappings": "AACA,OAAS,YAAAA,EAAU,UAAAC,EAAQ,MAAAC,MAAU,SAErC,OAAS,8BAAAC,MAAkC,+BAE3CH,EAAS,6BAA8B,IAAM,CAC3CE,EAAG,4CAA6C,IAAM,CACpD,MAAME,EAASD,EACb,SACF,EAEAF,EAAOG,CAAM,EAAE,YAAY,EAC3BH,EAAO,OAAOG,EAAO,KAAK,EAAE,KAAK,UAAU,EAC3CH,EAAO,OAAOG,EAAO,IAAI,EAAE,KAAK,UAAU,EAC1CH,EAAO,OAAOG,EAAO,IAAI,EAAE,KAAK,UAAU,EAC1CH,EAAO,OAAOG,EAAO,KAAK,EAAE,KAAK,UAAU,EAC3CH,EAAO,MAAM,QAAQG,EAAO,WAAW,CAAC,EAAE,KAAK,EAAI,EACnDH,EAAOG,EAAO,WAAW,EAAE,aAAa,CAAC,CAC3C,CAAC,EAEDF,EAAG,oCAAqC,IAAM,CAC5C,MAAME,EAASD,EAA2B,MAAM,EAEhDF,EAAO,IAAMG,EAAO,MAAM,OAAO,CAAC,EAAE,IAAI,QAAQ,EAChDH,EAAO,IAAMG,EAAO,KAAK,OAAO,CAAC,EAAE,IAAI,QAAQ,EAC/CH,EAAO,IAAMG,EAAO,KAAK,OAAO,CAAC,EAAE,IAAI,QAAQ,EAC/CH,EAAO,IAAMG,EAAO,MAAM,OAAO,CAAC,EAAE,IAAI,QAAQ,EAEhDH,EAAO,IAAMG,EAAO,MAAM,QAAS,CAAE,KAAM,CAAE,EAAG,CAAE,CAAE,CAAC,CAAC,EAAE,IAAI,QAAQ,CACtE,CAAC,EAEDF,EAAG,yDAA0D,IAAM,CACjE,MAAMG,EAAUF,EAA2B,GAAG,EACxCG,EAAUH,EAA2B,GAAG,EAE9CF,EAAOI,CAAO,EAAE,IAAI,KAAKC,CAAO,CAClC,CAAC,CACH,CAAC",
6
+ "names": ["describe", "expect", "it", "NullLoggerPublisherService", "logger", "logger1", "logger2"]
7
+ }
@@ -1,2 +1,2 @@
1
- var T=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var f=(i,t,a,o)=>{for(var r=o>1?void 0:o?y(t,a):t,n=i.length-1,s;n>=0;n--)(s=i[n])&&(r=(o?s(t,a,r):s(r))||r);return o&&r&&T(t,a,r),r},d=(i,t)=>(a,o)=>t(a,o,i);import{inject as m,injectable as k}from"inversify";import{Left as C}from"purify-ts";import{pkiTypes as _}from"../../pki/di/pkiTypes";import{KeyUsage as P}from"../../pki/model/KeyUsage";import{SolanaContextTypes as p}from"../../shared/model/SolanaContextTypes";import{solanaContextTypes as v}from"../../solana/di/solanaContextTypes";import{solanaTokenTypes as x}from"../../solanaToken/di/solanaTokenTypes";let l=class{constructor(t,a,o){this._dataSource=t;this._certificateLoader=a;this._solanaTokenLoader=o}async load(t){const{deviceModelId:a}=t,o=await this._certificateLoader.loadCertificate({keyId:"domain_metadata_key",keyUsage:P.TrustedName,targetDevice:a});if(!o)return C(new Error("[ContextModule] DefaultSolanaContextLoader: trustedNamePKICertificate is missing"));const n=[{loader:this._solanaTokenLoader,expectedType:p.SOLANA_TOKEN}].map(({loader:e,expectedType:c})=>{if(e.canHandle(t,c))return e.loadField(t)}).filter(e=>e!==void 0),u=(await Promise.allSettled(n)).map(e=>e.status==="fulfilled"?e.value:void 0).filter(e=>e!==void 0).sort((e,c)=>{const L=e.type===p.SOLANA_TOKEN?0:1,S=c.type===p.SOLANA_TOKEN?0:1;return L-S});return(await this._dataSource.getOwnerInfo(t)).map(({tlvDescriptor:e})=>({trustedNamePKICertificate:o,tlvDescriptor:e,loadersResults:u}))}};l=f([k(),d(0,m(v.SolanaDataSource)),d(1,m(_.PkiCertificateLoader)),d(2,m(x.SolanaTokenContextLoader))],l);export{l as DefaultSolanaContextLoader};
1
+ var S=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var f=(i,e,a,o)=>{for(var r=o>1?void 0:o?y(e,a):e,n=i.length-1,d;n>=0;n--)(d=i[n])&&(r=(o?d(e,a,r):d(r))||r);return o&&r&&S(e,a,r),r},s=(i,e)=>(a,o)=>e(a,o,i);import{inject as l,injectable as T}from"inversify";import{Left as C}from"purify-ts";import{configTypes as k}from"../../config/di/configTypes";import{pkiTypes as v}from"../../pki/di/pkiTypes";import{KeyUsage as P}from"../../pki/model/KeyUsage";import{SolanaContextTypes as p}from"../../shared/model/SolanaContextTypes";import{solanaContextTypes as x}from"../../solana/di/solanaContextTypes";import{solanaTokenTypes as _}from"../../solanaToken/di/solanaTokenTypes";let c=class{constructor(e,a,o,r){this._dataSource=e;this._certificateLoader=a;this._solanaTokenLoader=o;this.logger=r("DefaultSolanaContextLoader")}logger;async load(e){this.logger.debug("[load] Loading solana context",{data:{input:e}});const{deviceModelId:a}=e,o=await this._certificateLoader.loadCertificate({keyId:"domain_metadata_key",keyUsage:P.TrustedName,targetDevice:a});if(!o)return C(new Error("[ContextModule] DefaultSolanaContextLoader: trustedNamePKICertificate is missing"));const n=[{loader:this._solanaTokenLoader,expectedType:p.SOLANA_TOKEN}].map(({loader:t,expectedType:m})=>{if(t.canHandle(e,m))return t.loadField(e)}).filter(t=>t!==void 0),u=(await Promise.allSettled(n)).map(t=>t.status==="fulfilled"?t.value:void 0).filter(t=>t!==void 0).sort((t,m)=>{const L=t.type===p.SOLANA_TOKEN?0:1,g=m.type===p.SOLANA_TOKEN?0:1;return L-g});return(await this._dataSource.getOwnerInfo(e)).map(({tlvDescriptor:t})=>({trustedNamePKICertificate:o,tlvDescriptor:t,loadersResults:u}))}};c=f([T(),s(0,l(x.SolanaDataSource)),s(1,l(v.PkiCertificateLoader)),s(2,l(_.SolanaTokenContextLoader)),s(3,l(k.ContextModuleLoggerFactory))],c);export{c as DefaultSolanaContextLoader};
2
2
  //# sourceMappingURL=DefaultSolanaContextLoader.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/solana/domain/DefaultSolanaContextLoader.ts"],
4
- "sourcesContent": ["import { inject, injectable } from \"inversify\";\nimport { Left } from \"purify-ts\";\n\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport {\n LoaderResult,\n SolanaContextTypes,\n} from \"@/shared/model/SolanaContextTypes\";\nimport { type SolanaDataSource } from \"@/solana/data/SolanaDataSource\";\nimport { solanaContextTypes } from \"@/solana/di/solanaContextTypes\";\n// import { lifiTypes } from \"@/solanaLifi/di/solanaLifiTypes\";\n// import { SolanaLifiContextLoader } from \"@/solanaLifi/domain/SolanaLifiContextLoader\";\nimport { solanaTokenTypes } from \"@/solanaToken/di/solanaTokenTypes\";\nimport { SolanaTokenContextLoader } from \"@/solanaToken/domain/SolanaTokenContextLoader\";\n\nimport { type SolanaContextLoader } from \"./SolanaContextLoader\";\nimport {\n SolanaTransactionContext,\n SolanaTransactionContextResult,\n} from \"./solanaContextTypes\";\n\n@injectable()\nexport class DefaultSolanaContextLoader implements SolanaContextLoader {\n constructor(\n @inject(solanaContextTypes.SolanaDataSource)\n private readonly _dataSource: SolanaDataSource,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n @inject(solanaTokenTypes.SolanaTokenContextLoader)\n private readonly _solanaTokenLoader: SolanaTokenContextLoader,\n // @inject(lifiTypes.SolanaLifiContextLoader)\n // private readonly _solanaLifiLoader: SolanaLifiContextLoader,\n ) {}\n\n async load(\n solanaContext: SolanaTransactionContext,\n ): Promise<SolanaTransactionContextResult> {\n const { deviceModelId } = solanaContext;\n\n const trustedNamePKICertificate =\n await this._certificateLoader.loadCertificate({\n keyId: \"domain_metadata_key\",\n keyUsage: KeyUsage.TrustedName,\n targetDevice: deviceModelId,\n });\n\n if (!trustedNamePKICertificate) {\n return Left(\n new Error(\n \"[ContextModule] DefaultSolanaContextLoader: trustedNamePKICertificate is missing\",\n ),\n );\n }\n\n const loaderEntries = [\n {\n loader: this._solanaTokenLoader,\n expectedType: SolanaContextTypes.SOLANA_TOKEN,\n },\n // TODO LIFI\n // Lifi loader currently disabled as WIP\n // {\n // loader: this._solanaLifiLoader,\n // expectedType: SolanaContextTypes.SOLANA_LIFI,\n // },\n ] as const;\n\n const loaderPromises: Promise<LoaderResult>[] = loaderEntries\n .map(({ loader, expectedType }) => {\n if (loader.canHandle(solanaContext, expectedType)) {\n return loader.loadField(solanaContext);\n }\n return undefined;\n })\n .filter((p): p is Promise<LoaderResult> => p !== undefined);\n\n const settledLoaders = await Promise.allSettled(loaderPromises);\n\n const loadersResults = settledLoaders\n .map((r) => (r.status === \"fulfilled\" ? r.value : undefined))\n .filter((v): v is LoaderResult => v !== undefined)\n // always sort with SOLANA_TOKEN first\n .sort((a, b) => {\n const A = a.type === SolanaContextTypes.SOLANA_TOKEN ? 0 : 1;\n const B = b.type === SolanaContextTypes.SOLANA_TOKEN ? 0 : 1;\n return A - B;\n });\n\n const tlvDescriptorEither =\n await this._dataSource.getOwnerInfo(solanaContext);\n\n return tlvDescriptorEither.map(({ tlvDescriptor }) => ({\n trustedNamePKICertificate,\n tlvDescriptor,\n loadersResults,\n }));\n }\n}\n"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AP,CACF,EAAE,CACJ,CACF,EA3Ead,EAANsB,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAmB,gBAAgB,GAE1CF,EAAA,EAAAC,EAAOE,EAAS,oBAAoB,GAEpCH,EAAA,EAAAC,EAAOG,EAAiB,wBAAwB,IANxC5B",
6
- "names": ["inject", "injectable", "Left", "pkiTypes", "KeyUsage", "SolanaContextTypes", "solanaContextTypes", "solanaTokenTypes", "DefaultSolanaContextLoader", "_dataSource", "_certificateLoader", "_solanaTokenLoader", "solanaContext", "deviceModelId", "trustedNamePKICertificate", "KeyUsage", "Left", "loaderPromises", "SolanaContextTypes", "loader", "expectedType", "p", "loadersResults", "r", "v", "a", "b", "A", "B", "tlvDescriptor", "__decorateClass", "injectable", "__decorateParam", "inject", "solanaContextTypes", "pkiTypes", "solanaTokenTypes"]
4
+ "sourcesContent": ["import { LoggerPublisherService } from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\nimport { Left } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport {\n LoaderResult,\n SolanaContextTypes,\n} from \"@/shared/model/SolanaContextTypes\";\nimport { type SolanaDataSource } from \"@/solana/data/SolanaDataSource\";\nimport { solanaContextTypes } from \"@/solana/di/solanaContextTypes\";\n// import { lifiTypes } from \"@/solanaLifi/di/solanaLifiTypes\";\n// import { SolanaLifiContextLoader } from \"@/solanaLifi/domain/SolanaLifiContextLoader\";\nimport { solanaTokenTypes } from \"@/solanaToken/di/solanaTokenTypes\";\nimport { SolanaTokenContextLoader } from \"@/solanaToken/domain/SolanaTokenContextLoader\";\n\nimport { type SolanaContextLoader } from \"./SolanaContextLoader\";\nimport {\n SolanaTransactionContext,\n SolanaTransactionContextResult,\n} from \"./solanaContextTypes\";\n\n@injectable()\nexport class DefaultSolanaContextLoader implements SolanaContextLoader {\n private logger: LoggerPublisherService;\n\n constructor(\n @inject(solanaContextTypes.SolanaDataSource)\n private readonly _dataSource: SolanaDataSource,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n @inject(solanaTokenTypes.SolanaTokenContextLoader)\n private readonly _solanaTokenLoader: SolanaTokenContextLoader,\n @inject(configTypes.ContextModuleLoggerFactory)\n loggerFactory: (tag: string) => LoggerPublisherService,\n // @inject(lifiTypes.SolanaLifiContextLoader)\n // private readonly _solanaLifiLoader: SolanaLifiContextLoader,\n ) {\n this.logger = loggerFactory(\"DefaultSolanaContextLoader\");\n }\n\n async load(\n solanaContext: SolanaTransactionContext,\n ): Promise<SolanaTransactionContextResult> {\n this.logger.debug(\"[load] Loading solana context\", {\n data: { input: solanaContext },\n });\n const { deviceModelId } = solanaContext;\n\n const trustedNamePKICertificate =\n await this._certificateLoader.loadCertificate({\n keyId: \"domain_metadata_key\",\n keyUsage: KeyUsage.TrustedName,\n targetDevice: deviceModelId,\n });\n\n if (!trustedNamePKICertificate) {\n return Left(\n new Error(\n \"[ContextModule] DefaultSolanaContextLoader: trustedNamePKICertificate is missing\",\n ),\n );\n }\n\n const loaderEntries = [\n {\n loader: this._solanaTokenLoader,\n expectedType: SolanaContextTypes.SOLANA_TOKEN,\n },\n // TODO LIFI\n // Lifi loader currently disabled as WIP\n // {\n // loader: this._solanaLifiLoader,\n // expectedType: SolanaContextTypes.SOLANA_LIFI,\n // },\n ] as const;\n\n const loaderPromises: Promise<LoaderResult>[] = loaderEntries\n .map(({ loader, expectedType }) => {\n if (loader.canHandle(solanaContext, expectedType)) {\n return loader.loadField(solanaContext);\n }\n return undefined;\n })\n .filter((p): p is Promise<LoaderResult> => p !== undefined);\n\n const settledLoaders = await Promise.allSettled(loaderPromises);\n\n const loadersResults = settledLoaders\n .map((r) => (r.status === \"fulfilled\" ? r.value : undefined))\n .filter((v): v is LoaderResult => v !== undefined)\n // always sort with SOLANA_TOKEN first\n .sort((a, b) => {\n const A = a.type === SolanaContextTypes.SOLANA_TOKEN ? 0 : 1;\n const B = b.type === SolanaContextTypes.SOLANA_TOKEN ? 0 : 1;\n return A - B;\n });\n\n const tlvDescriptorEither =\n await this._dataSource.getOwnerInfo(solanaContext);\n\n return tlvDescriptorEither.map(({ tlvDescriptor }) => ({\n trustedNamePKICertificate,\n tlvDescriptor,\n loadersResults,\n }));\n }\n}\n"],
5
+ "mappings": "iOACA,OAAS,UAAAA,EAAQ,cAAAC,MAAkB,YACnC,OAAS,QAAAC,MAAY,YAErB,OAAS,eAAAC,MAAmB,0BAC5B,OAAS,YAAAC,MAAgB,oBAEzB,OAAS,YAAAC,MAAgB,uBACzB,OAEE,sBAAAC,MACK,oCAEP,OAAS,sBAAAC,MAA0B,iCAGnC,OAAS,oBAAAC,MAAwB,oCAU1B,IAAMC,EAAN,KAAgE,CAGrE,YAEmBC,EAEAC,EAEAC,EAEjBC,EAGA,CATiB,iBAAAH,EAEA,wBAAAC,EAEA,wBAAAC,EAMjB,KAAK,OAASC,EAAc,4BAA4B,CAC1D,CAfQ,OAiBR,MAAM,KACJC,EACyC,CACzC,KAAK,OAAO,MAAM,gCAAiC,CACjD,KAAM,CAAE,MAAOA,CAAc,CAC/B,CAAC,EACD,KAAM,CAAE,cAAAC,CAAc,EAAID,EAEpBE,EACJ,MAAM,KAAK,mBAAmB,gBAAgB,CAC5C,MAAO,sBACP,SAAUC,EAAS,YACnB,aAAcF,CAChB,CAAC,EAEH,GAAI,CAACC,EACH,OAAOE,EACL,IAAI,MACF,kFACF,CACF,EAgBF,MAAMC,EAbgB,CACpB,CACE,OAAQ,KAAK,mBACb,aAAcC,EAAmB,YACnC,CAOF,EAGG,IAAI,CAAC,CAAE,OAAAC,EAAQ,aAAAC,CAAa,IAAM,CACjC,GAAID,EAAO,UAAUP,EAAeQ,CAAY,EAC9C,OAAOD,EAAO,UAAUP,CAAa,CAGzC,CAAC,EACA,OAAQS,GAAkCA,IAAM,MAAS,EAItDC,GAFiB,MAAM,QAAQ,WAAWL,CAAc,GAG3D,IAAKM,GAAOA,EAAE,SAAW,YAAcA,EAAE,MAAQ,MAAU,EAC3D,OAAQC,GAAyBA,IAAM,MAAS,EAEhD,KAAK,CAACC,EAAGC,IAAM,CACd,MAAMC,EAAIF,EAAE,OAASP,EAAmB,aAAe,EAAI,EACrDU,EAAIF,EAAE,OAASR,EAAmB,aAAe,EAAI,EAC3D,OAAOS,EAAIC,CACb,CAAC,EAKH,OAFE,MAAM,KAAK,YAAY,aAAahB,CAAa,GAExB,IAAI,CAAC,CAAE,cAAAiB,CAAc,KAAO,CACrD,0BAAAf,EACA,cAAAe,EACA,eAAAP,CACF,EAAE,CACJ,CACF,EApFaf,EAANuB,EAAA,CADNC,EAAW,EAKPC,EAAA,EAAAC,EAAOC,EAAmB,gBAAgB,GAE1CF,EAAA,EAAAC,EAAOE,EAAS,oBAAoB,GAEpCH,EAAA,EAAAC,EAAOG,EAAiB,wBAAwB,GAEhDJ,EAAA,EAAAC,EAAOI,EAAY,0BAA0B,IAVrC9B",
6
+ "names": ["inject", "injectable", "Left", "configTypes", "pkiTypes", "KeyUsage", "SolanaContextTypes", "solanaContextTypes", "solanaTokenTypes", "DefaultSolanaContextLoader", "_dataSource", "_certificateLoader", "_solanaTokenLoader", "loggerFactory", "solanaContext", "deviceModelId", "trustedNamePKICertificate", "KeyUsage", "Left", "loaderPromises", "SolanaContextTypes", "loader", "expectedType", "p", "loadersResults", "r", "v", "a", "b", "A", "B", "tlvDescriptor", "__decorateClass", "injectable", "__decorateParam", "inject", "solanaContextTypes", "pkiTypes", "solanaTokenTypes", "configTypes"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{DeviceModelId as y}from"@ledgerhq/device-management-kit";import{Left as m,Right as f}from"purify-ts";import{beforeEach as g,describe as p,expect as o,it as s,vi as t}from"vitest";import{KeyUsage as T}from"../../pki/model/KeyUsage";import{SolanaContextTypes as d}from"../../shared/model/SolanaContextTypes";import{SolanaTokenContextLoader as I}from"../../solanaToken/domain/SolanaTokenContextLoader";p("SolanaTokenContextLoader",()=>{let l,i;const c=new Uint8Array([240,202,204,26]),n={descriptor:{data:{symbol:"SOL",name:"Solana",decimals:9},signatures:{prod:"prod-sig",test:"test-sig"}}},k={tokenInternalId:"token-1",deviceModelId:y.FLEX};g(()=>{t.restoreAllMocks(),l={getTokenInfosPayload:t.fn()},i={loadCertificate:t.fn()}});const r=e=>{const a={cal:{mode:e}};return new I(l,a,i)};p("canHandle",()=>{s("returns true when tokenInternalId is provided",()=>{const e=r("prod");o(e.canHandle({tokenInternalId:"abc123"},d.SOLANA_TOKEN)).toBe(!0)}),s("returns false when tokenInternalId is missing or falsy",()=>{const e=r("prod");o(e.canHandle({tokenInternalId:""},d.SOLANA_TOKEN)).toBe(!1),o(e.canHandle({tokenInternalId:void 0},d.SOLANA_TOKEN)).toBe(!1),o(e.canHandle({},d.SOLANA_TOKEN)).toBe(!1)})}),p("loadField",()=>{s("returns an error when datasource returns Left(error) and still fetched certificate beforehand",async()=>{const e=r("prod"),a=new Error("datasource failed");t.spyOn(l,"getTokenInfosPayload").mockResolvedValue(m(a)),t.spyOn(i,"loadCertificate").mockResolvedValue({keyUsageNumber:0,payload:c});const u=await e.loadField(k);o(l.getTokenInfosPayload).toHaveBeenCalledWith({tokenInternalId:"token-1"}),o(i.loadCertificate).toHaveBeenCalledWith({keyId:"token_metadata_key",keyUsage:T.CoinMeta,targetDevice:k.deviceModelId}),o(u).toEqual({type:d.ERROR,error:a})}),s("returns SOLANA_TOKEN with prod signature by default (falsy mode), and includes certificate",async()=>{const e=r("");t.spyOn(l,"getTokenInfosPayload").mockResolvedValue(f(n)),t.spyOn(i,"loadCertificate").mockResolvedValue({keyUsageNumber:0,payload:c});const a=await e.loadField({...k,tokenInternalId:"token-2"});o(a).toEqual({type:d.SOLANA_TOKEN,payload:{solanaTokenDescriptor:{data:n.descriptor.data,signature:"prod-sig"}},certificate:{keyUsageNumber:0,payload:c}})}),s("returns SOLANA_TOKEN with signature matching config.cal.mode",async()=>{const e=r("test");t.spyOn(l,"getTokenInfosPayload").mockResolvedValue(f(n)),t.spyOn(i,"loadCertificate").mockResolvedValue({keyUsageNumber:1,payload:c});const a=await e.loadField({...k,tokenInternalId:"token-3"});o(a).toEqual({type:d.SOLANA_TOKEN,payload:{solanaTokenDescriptor:{data:n.descriptor.data,signature:"test-sig"}},certificate:{keyUsageNumber:1,payload:c}})}),s("works even if certificate loader returns undefined (certificate omitted)",async()=>{const e=r("prod");t.spyOn(l,"getTokenInfosPayload").mockResolvedValue(f(n)),t.spyOn(i,"loadCertificate").mockResolvedValue(void 0);const a=await e.loadField(k);o(a).toEqual({type:d.SOLANA_TOKEN,payload:{solanaTokenDescriptor:{data:n.descriptor.data,signature:"prod-sig"}},certificate:void 0})})}),p("pluckTokenData (private)",()=>{s("picks the signature for the configured mode",()=>{const e=r("test"),u=e.pluckTokenData.bind(e)(n);o(u).toEqual({solanaTokenDescriptor:{data:n.descriptor.data,signature:"test-sig"}})}),s("falls back to 'prod' when config.cal.mode is falsy",()=>{const a=r(void 0).pluckTokenData(n);o(a).toEqual({solanaTokenDescriptor:{data:n.descriptor.data,signature:"prod-sig"}})})})});
1
+ import{DeviceModelId as y}from"@ledgerhq/device-management-kit";import{Left as m,Right as f}from"purify-ts";import{beforeEach as g,describe as k,expect as o,it as s,vi as t}from"vitest";import{KeyUsage as T}from"../../pki/model/KeyUsage";import{SolanaContextTypes as d}from"../../shared/model/SolanaContextTypes";import{NullLoggerPublisherService as I}from"../../shared/utils/NullLoggerPublisherService";import{SolanaTokenContextLoader as O}from"../../solanaToken/domain/SolanaTokenContextLoader";k("SolanaTokenContextLoader",()=>{let l,i;const c=new Uint8Array([240,202,204,26]),n={descriptor:{data:{symbol:"SOL",name:"Solana",decimals:9},signatures:{prod:"prod-sig",test:"test-sig"}}},p={tokenInternalId:"token-1",deviceModelId:y.FLEX};g(()=>{t.restoreAllMocks(),l={getTokenInfosPayload:t.fn()},i={loadCertificate:t.fn()}});const r=e=>{const a={cal:{mode:e}};return new O(l,a,i,I)};k("canHandle",()=>{s("returns true when tokenInternalId is provided",()=>{const e=r("prod");o(e.canHandle({tokenInternalId:"abc123"},d.SOLANA_TOKEN)).toBe(!0)}),s("returns false when tokenInternalId is missing or falsy",()=>{const e=r("prod");o(e.canHandle({tokenInternalId:""},d.SOLANA_TOKEN)).toBe(!1),o(e.canHandle({tokenInternalId:void 0},d.SOLANA_TOKEN)).toBe(!1),o(e.canHandle({},d.SOLANA_TOKEN)).toBe(!1)})}),k("loadField",()=>{s("returns an error when datasource returns Left(error) and still fetched certificate beforehand",async()=>{const e=r("prod"),a=new Error("datasource failed");t.spyOn(l,"getTokenInfosPayload").mockResolvedValue(m(a)),t.spyOn(i,"loadCertificate").mockResolvedValue({keyUsageNumber:0,payload:c});const u=await e.loadField(p);o(l.getTokenInfosPayload).toHaveBeenCalledWith({tokenInternalId:"token-1"}),o(i.loadCertificate).toHaveBeenCalledWith({keyId:"token_metadata_key",keyUsage:T.CoinMeta,targetDevice:p.deviceModelId}),o(u).toEqual({type:d.ERROR,error:a})}),s("returns SOLANA_TOKEN with prod signature by default (falsy mode), and includes certificate",async()=>{const e=r("");t.spyOn(l,"getTokenInfosPayload").mockResolvedValue(f(n)),t.spyOn(i,"loadCertificate").mockResolvedValue({keyUsageNumber:0,payload:c});const a=await e.loadField({...p,tokenInternalId:"token-2"});o(a).toEqual({type:d.SOLANA_TOKEN,payload:{solanaTokenDescriptor:{data:n.descriptor.data,signature:"prod-sig"}},certificate:{keyUsageNumber:0,payload:c}})}),s("returns SOLANA_TOKEN with signature matching config.cal.mode",async()=>{const e=r("test");t.spyOn(l,"getTokenInfosPayload").mockResolvedValue(f(n)),t.spyOn(i,"loadCertificate").mockResolvedValue({keyUsageNumber:1,payload:c});const a=await e.loadField({...p,tokenInternalId:"token-3"});o(a).toEqual({type:d.SOLANA_TOKEN,payload:{solanaTokenDescriptor:{data:n.descriptor.data,signature:"test-sig"}},certificate:{keyUsageNumber:1,payload:c}})}),s("works even if certificate loader returns undefined (certificate omitted)",async()=>{const e=r("prod");t.spyOn(l,"getTokenInfosPayload").mockResolvedValue(f(n)),t.spyOn(i,"loadCertificate").mockResolvedValue(void 0);const a=await e.loadField(p);o(a).toEqual({type:d.SOLANA_TOKEN,payload:{solanaTokenDescriptor:{data:n.descriptor.data,signature:"prod-sig"}},certificate:void 0})})}),k("pluckTokenData (private)",()=>{s("picks the signature for the configured mode",()=>{const e=r("test"),u=e.pluckTokenData.bind(e)(n);o(u).toEqual({solanaTokenDescriptor:{data:n.descriptor.data,signature:"test-sig"}})}),s("falls back to 'prod' when config.cal.mode is falsy",()=>{const a=r(void 0).pluckTokenData(n);o(a).toEqual({solanaTokenDescriptor:{data:n.descriptor.data,signature:"prod-sig"}})})})});
2
2
  //# sourceMappingURL=DefaultSolanaContextLoader.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/solana/domain/DefaultSolanaContextLoader.test.ts"],
4
- "sourcesContent": ["/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\nimport { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\nimport { beforeEach, describe, expect, it, vi } from \"vitest\";\n\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport type { PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { SolanaContextTypes } from \"@/shared/model/SolanaContextTypes\";\nimport type { SolanaTransactionContext } from \"@/solana/domain/solanaContextTypes\";\nimport {\n type SolanaTokenDataSource,\n type TokenDataResponse,\n} from \"@/solanaToken/data/SolanaTokenDataSource\";\nimport { SolanaTokenContextLoader } from \"@/solanaToken/domain/SolanaTokenContextLoader\";\n\ndescribe(\"SolanaTokenContextLoader\", () => {\n let mockDataSource: SolanaTokenDataSource;\n let mockCertLoader: PkiCertificateLoader;\n\n const bytes = new Uint8Array([0xf0, 0xca, 0xcc, 0x1a]);\n\n const tokenDataResponse: TokenDataResponse = {\n descriptor: {\n data: { symbol: \"SOL\", name: \"Solana\", decimals: 9 } as any,\n signatures: {\n prod: \"prod-sig\",\n test: \"test-sig\",\n } as any,\n },\n } as any;\n\n const baseCtx = {\n tokenInternalId: \"token-1\",\n deviceModelId: DeviceModelId.FLEX,\n } as any;\n\n beforeEach(() => {\n vi.restoreAllMocks();\n\n mockDataSource = {\n getTokenInfosPayload: vi.fn(),\n } as unknown as SolanaTokenDataSource;\n\n mockCertLoader = {\n loadCertificate: vi.fn(),\n } as unknown as PkiCertificateLoader;\n });\n\n const makeLoader = (mode?: string) => {\n const config = { cal: { mode } } as unknown as ContextModuleConfig;\n return new SolanaTokenContextLoader(mockDataSource, config, mockCertLoader);\n };\n\n describe(\"canHandle\", () => {\n it(\"returns true when tokenInternalId is provided\", () => {\n const loader = makeLoader(\"prod\");\n\n expect(\n loader.canHandle(\n {\n tokenInternalId: \"abc123\",\n } as SolanaTransactionContext,\n SolanaContextTypes.SOLANA_TOKEN,\n ),\n ).toBe(true);\n });\n\n it(\"returns false when tokenInternalId is missing or falsy\", () => {\n const loader = makeLoader(\"prod\");\n\n expect(\n loader.canHandle(\n { tokenInternalId: \"\" } as any,\n SolanaContextTypes.SOLANA_TOKEN,\n ),\n ).toBe(false);\n expect(\n loader.canHandle(\n { tokenInternalId: undefined } as any,\n SolanaContextTypes.SOLANA_TOKEN,\n ),\n ).toBe(false);\n expect(loader.canHandle({} as any, SolanaContextTypes.SOLANA_TOKEN)).toBe(\n false,\n );\n });\n });\n\n describe(\"loadField\", () => {\n it(\"returns an error when datasource returns Left(error) and still fetched certificate beforehand\", async () => {\n const loader = makeLoader(\"prod\");\n const error = new Error(\"datasource failed\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(error),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 0,\n payload: bytes,\n });\n\n const result = await loader.loadField(baseCtx);\n\n expect(mockDataSource.getTokenInfosPayload).toHaveBeenCalledWith({\n tokenInternalId: \"token-1\",\n });\n expect(mockCertLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: \"token_metadata_key\",\n keyUsage: KeyUsage.CoinMeta,\n targetDevice: baseCtx.deviceModelId,\n });\n expect(result).toEqual({\n type: SolanaContextTypes.ERROR,\n error,\n });\n });\n\n it(\"returns SOLANA_TOKEN with prod signature by default (falsy mode), and includes certificate\", async () => {\n const loader = makeLoader(\"\"); // falsy -> default 'prod'\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 0,\n payload: bytes,\n });\n\n const result = await loader.loadField({\n ...baseCtx,\n tokenInternalId: \"token-2\",\n });\n\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_TOKEN,\n payload: {\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"prod-sig\",\n },\n },\n certificate: { keyUsageNumber: 0, payload: bytes },\n });\n });\n\n it(\"returns SOLANA_TOKEN with signature matching config.cal.mode\", async () => {\n const loader = makeLoader(\"test\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 1,\n payload: bytes,\n });\n\n const result = await loader.loadField({\n ...baseCtx,\n tokenInternalId: \"token-3\",\n });\n\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_TOKEN,\n payload: {\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"test-sig\",\n },\n },\n certificate: { keyUsageNumber: 1, payload: bytes },\n });\n });\n\n it(\"works even if certificate loader returns undefined (certificate omitted)\", async () => {\n const loader = makeLoader(\"prod\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue(undefined);\n\n const result = await loader.loadField(baseCtx);\n\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_TOKEN,\n payload: {\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"prod-sig\",\n },\n },\n certificate: undefined,\n });\n });\n });\n\n describe(\"pluckTokenData (private)\", () => {\n it(\"picks the signature for the configured mode\", () => {\n const loader = makeLoader(\"test\");\n const pluck = (loader as any).pluckTokenData.bind(loader);\n\n const result = pluck(tokenDataResponse);\n\n expect(result).toEqual({\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"test-sig\",\n },\n });\n });\n\n it(\"falls back to 'prod' when config.cal.mode is falsy\", () => {\n const loader = makeLoader(undefined as any);\n const result = (loader as any).pluckTokenData(tokenDataResponse);\n\n expect(result).toEqual({\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"prod-sig\",\n },\n });\n });\n });\n});\n"],
5
- "mappings": "AAIA,OAAS,iBAAAA,MAAqB,kCAC9B,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAC5B,OAAS,cAAAC,EAAY,YAAAC,EAAU,UAAAC,EAAQ,MAAAC,EAAI,MAAAC,MAAU,SAIrD,OAAS,YAAAC,MAAgB,uBACzB,OAAS,sBAAAC,MAA0B,oCAMnC,OAAS,4BAAAC,MAAgC,gDAEzCN,EAAS,2BAA4B,IAAM,CACzC,IAAIO,EACAC,EAEJ,MAAMC,EAAQ,IAAI,WAAW,CAAC,IAAM,IAAM,IAAM,EAAI,CAAC,EAE/CC,EAAuC,CAC3C,WAAY,CACV,KAAM,C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CACF,EACA,YAAa,CAAE,eAAgB,EAAG,QAASD,CAAM,CACnD,CAAC,CACH,CAAC,EAEDP,EAAG,2EAA4E,SAAY,CACzF,MAAMa,EAASH,EAAW,MAAM,EAEhCT,EAAG,MAAMI,EAAgB,sBAAsB,EAAE,kBAC/CT,EAAMY,CAAiB,CACzB,EACAP,EAAG,MAAMK,EAAgB,iBAAiB,EAAE,kBAAkB,MAAS,EAEvE,MAAMS,EAAS,MAAMF,EAAO,UAAUJ,CAAO,EAE7CV,EAAOgB,CAAM,EAAE,QAAQ,CACrB,KAAMZ,EAAmB,aACzB,QAAS,CACP,sBAAuB,CACrB,KAAMK,EAAkB,WAAW,KACnC,UAAW,UACb,CACF,EACA,YAAa,MACf,CAAC,CACH,CAAC,CACH,CAAC,EAEDV,EAAS,2BAA4B,IAAM,CACzCE,EAAG,8CAA+C,IAAM,CACtD,MAAMa,EAASH,EAAW,MAAM,EAG1BK,EAFSF,EAAe,eAAe,KAAKA,CAAM,EAEnCL,CAAiB,EAEtCT,EAAOgB,CAAM,EAAE,QAAQ,CACrB,sBAAuB,CACrB,KAAMP,EAAkB,WAAW,KACnC,UAAW,UACb,CACF,CAAC,CACH,CAAC,EAEDR,EAAG,qDAAsD,IAAM,CAE7D,MAAMe,EADSL,EAAW,MAAgB,EACX,eAAeF,CAAiB,EAE/DT,EAAOgB,CAAM,EAAE,QAAQ,CACrB,sBAAuB,CACrB,KAAMP,EAAkB,WAAW,KACnC,UAAW,UACb,CACF,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["DeviceModelId", "Left", "Right", "beforeEach", "describe", "expect", "it", "vi", "KeyUsage", "SolanaContextTypes", "SolanaTokenContextLoader", "mockDataSource", "mockCertLoader", "bytes", "tokenDataResponse", "baseCtx", "makeLoader", "mode", "config", "loader", "error", "result"]
4
+ "sourcesContent": ["/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\nimport { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\nimport { beforeEach, describe, expect, it, vi } from \"vitest\";\n\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport type { PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { SolanaContextTypes } from \"@/shared/model/SolanaContextTypes\";\nimport { NullLoggerPublisherService } from \"@/shared/utils/NullLoggerPublisherService\";\nimport type { SolanaTransactionContext } from \"@/solana/domain/solanaContextTypes\";\nimport {\n type SolanaTokenDataSource,\n type TokenDataResponse,\n} from \"@/solanaToken/data/SolanaTokenDataSource\";\nimport { SolanaTokenContextLoader } from \"@/solanaToken/domain/SolanaTokenContextLoader\";\n\ndescribe(\"SolanaTokenContextLoader\", () => {\n let mockDataSource: SolanaTokenDataSource;\n let mockCertLoader: PkiCertificateLoader;\n\n const bytes = new Uint8Array([0xf0, 0xca, 0xcc, 0x1a]);\n\n const tokenDataResponse: TokenDataResponse = {\n descriptor: {\n data: { symbol: \"SOL\", name: \"Solana\", decimals: 9 } as any,\n signatures: {\n prod: \"prod-sig\",\n test: \"test-sig\",\n } as any,\n },\n } as any;\n\n const baseCtx = {\n tokenInternalId: \"token-1\",\n deviceModelId: DeviceModelId.FLEX,\n } as any;\n\n beforeEach(() => {\n vi.restoreAllMocks();\n\n mockDataSource = {\n getTokenInfosPayload: vi.fn(),\n } as unknown as SolanaTokenDataSource;\n\n mockCertLoader = {\n loadCertificate: vi.fn(),\n } as unknown as PkiCertificateLoader;\n });\n\n const makeLoader = (mode?: string) => {\n const config = { cal: { mode } } as unknown as ContextModuleConfig;\n return new SolanaTokenContextLoader(\n mockDataSource,\n config,\n mockCertLoader,\n NullLoggerPublisherService,\n );\n };\n\n describe(\"canHandle\", () => {\n it(\"returns true when tokenInternalId is provided\", () => {\n const loader = makeLoader(\"prod\");\n\n expect(\n loader.canHandle(\n {\n tokenInternalId: \"abc123\",\n } as SolanaTransactionContext,\n SolanaContextTypes.SOLANA_TOKEN,\n ),\n ).toBe(true);\n });\n\n it(\"returns false when tokenInternalId is missing or falsy\", () => {\n const loader = makeLoader(\"prod\");\n\n expect(\n loader.canHandle(\n { tokenInternalId: \"\" } as any,\n SolanaContextTypes.SOLANA_TOKEN,\n ),\n ).toBe(false);\n expect(\n loader.canHandle(\n { tokenInternalId: undefined } as any,\n SolanaContextTypes.SOLANA_TOKEN,\n ),\n ).toBe(false);\n expect(loader.canHandle({} as any, SolanaContextTypes.SOLANA_TOKEN)).toBe(\n false,\n );\n });\n });\n\n describe(\"loadField\", () => {\n it(\"returns an error when datasource returns Left(error) and still fetched certificate beforehand\", async () => {\n const loader = makeLoader(\"prod\");\n const error = new Error(\"datasource failed\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(error),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 0,\n payload: bytes,\n });\n\n const result = await loader.loadField(baseCtx);\n\n expect(mockDataSource.getTokenInfosPayload).toHaveBeenCalledWith({\n tokenInternalId: \"token-1\",\n });\n expect(mockCertLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: \"token_metadata_key\",\n keyUsage: KeyUsage.CoinMeta,\n targetDevice: baseCtx.deviceModelId,\n });\n expect(result).toEqual({\n type: SolanaContextTypes.ERROR,\n error,\n });\n });\n\n it(\"returns SOLANA_TOKEN with prod signature by default (falsy mode), and includes certificate\", async () => {\n const loader = makeLoader(\"\"); // falsy -> default 'prod'\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 0,\n payload: bytes,\n });\n\n const result = await loader.loadField({\n ...baseCtx,\n tokenInternalId: \"token-2\",\n });\n\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_TOKEN,\n payload: {\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"prod-sig\",\n },\n },\n certificate: { keyUsageNumber: 0, payload: bytes },\n });\n });\n\n it(\"returns SOLANA_TOKEN with signature matching config.cal.mode\", async () => {\n const loader = makeLoader(\"test\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 1,\n payload: bytes,\n });\n\n const result = await loader.loadField({\n ...baseCtx,\n tokenInternalId: \"token-3\",\n });\n\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_TOKEN,\n payload: {\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"test-sig\",\n },\n },\n certificate: { keyUsageNumber: 1, payload: bytes },\n });\n });\n\n it(\"works even if certificate loader returns undefined (certificate omitted)\", async () => {\n const loader = makeLoader(\"prod\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue(undefined);\n\n const result = await loader.loadField(baseCtx);\n\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_TOKEN,\n payload: {\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"prod-sig\",\n },\n },\n certificate: undefined,\n });\n });\n });\n\n describe(\"pluckTokenData (private)\", () => {\n it(\"picks the signature for the configured mode\", () => {\n const loader = makeLoader(\"test\");\n const pluck = (loader as any).pluckTokenData.bind(loader);\n\n const result = pluck(tokenDataResponse);\n\n expect(result).toEqual({\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"test-sig\",\n },\n });\n });\n\n it(\"falls back to 'prod' when config.cal.mode is falsy\", () => {\n const loader = makeLoader(undefined as any);\n const result = (loader as any).pluckTokenData(tokenDataResponse);\n\n expect(result).toEqual({\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"prod-sig\",\n },\n });\n });\n });\n});\n"],
5
+ "mappings": "AAIA,OAAS,iBAAAA,MAAqB,kCAC9B,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAC5B,OAAS,cAAAC,EAAY,YAAAC,EAAU,UAAAC,EAAQ,MAAAC,EAAI,MAAAC,MAAU,SAIrD,OAAS,YAAAC,MAAgB,uBACzB,OAAS,sBAAAC,MAA0B,oCACnC,OAAS,8BAAAC,MAAkC,4CAM3C,OAAS,4BAAAC,MAAgC,gDAEzCP,EAAS,2BAA4B,IAAM,CACzC,IAAIQ,EACAC,EAEJ,MAAMC,EAAQ,IAAI,WAAW,CAAC,IAAM,IAAM,IAAM,EAAI,CAAC,EAE/CC,EAAuC,CAC3C,WAAY,CACV,KAAM,CAAE,OAAQ,MAAO,KAAM,SAAU,SAAU,CAAE,EACnD,WAAY,CACV,KAAM,WACN,KAAM,UACR,CACF,CACF,EAEMC,EAAU,CACd,gBAAiB,UACjB,cAAehB,EAAc,IAC/B,EAEAG,EAAW,IAAM,CACfI,EAAG,gBAAgB,EAEnBK,EAAiB,CACf,qBAAsBL,EAAG,GAAG,CAC9B,EAEAM,EAAiB,CACf,gBAAiBN,EAAG,GAAG,CACzB,CACF,CAAC,EAED,MAAMU,EAAcC,GAAkB,CACpC,MAAMC,EAAS,CAAE,IAAK,CAAE,KAAAD,CAAK,CAAE,EAC/B,OAAO,IAAIP,EACTC,EACAO,EACAN,EACAH,CACF,CACF,EAEAN,EAAS,YAAa,IAAM,CAC1BE,EAAG,gDAAiD,IAAM,CACxD,MAAMc,EAASH,EAAW,MAAM,EAEhCZ,EACEe,EAAO,UACL,CACE,gBAAiB,QACnB,EACAX,EAAmB,YACrB,CACF,EAAE,KAAK,EAAI,CACb,CAAC,EAEDH,EAAG,yDAA0D,IAAM,CACjE,MAAMc,EAASH,EAAW,MAA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,CACrB,KAAMP,EAAkB,WAAW,KACnC,UAAW,UACb,CACF,CAAC,CACH,CAAC,EAEDT,EAAG,qDAAsD,IAAM,CAE7D,MAAMgB,EADSL,EAAW,MAAgB,EACX,eAAeF,CAAiB,EAE/DV,EAAOiB,CAAM,EAAE,QAAQ,CACrB,sBAAuB,CACrB,KAAMP,EAAkB,WAAW,KACnC,UAAW,UACb,CACF,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["DeviceModelId", "Left", "Right", "beforeEach", "describe", "expect", "it", "vi", "KeyUsage", "SolanaContextTypes", "NullLoggerPublisherService", "SolanaTokenContextLoader", "mockDataSource", "mockCertLoader", "bytes", "tokenDataResponse", "baseCtx", "makeLoader", "mode", "config", "loader", "error", "result"]
7
7
  }