@ledgerhq/context-module 1.6.0 → 1.7.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 (165) 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 +2 -2
  6. package/lib/cjs/src/DefaultContextModule.js +1 -1
  7. package/lib/cjs/src/DefaultContextModule.js.map +3 -3
  8. package/lib/cjs/src/DefaultContextModule.test.js +1 -1
  9. package/lib/cjs/src/DefaultContextModule.test.js.map +2 -2
  10. package/lib/cjs/src/config/model/ContextModuleConfig.js +1 -1
  11. package/lib/cjs/src/config/model/ContextModuleConfig.js.map +1 -1
  12. package/lib/cjs/src/di.js +1 -1
  13. package/lib/cjs/src/di.js.map +3 -3
  14. package/lib/cjs/src/dynamic-network/data/DynamicNetworkDataSource.js +2 -0
  15. package/lib/cjs/src/dynamic-network/data/DynamicNetworkDataSource.js.map +7 -0
  16. package/lib/cjs/src/dynamic-network/data/HttpDynamicNetworkDataSource.js +2 -0
  17. package/lib/cjs/src/dynamic-network/data/HttpDynamicNetworkDataSource.js.map +7 -0
  18. package/lib/cjs/src/dynamic-network/data/HttpDynamicNetworkDataSource.test.js +2 -0
  19. package/lib/cjs/src/dynamic-network/data/HttpDynamicNetworkDataSource.test.js.map +7 -0
  20. package/lib/cjs/src/dynamic-network/data/dto/DynamicNetworkApiResponseDto.js +2 -0
  21. package/lib/cjs/src/dynamic-network/data/dto/DynamicNetworkApiResponseDto.js.map +7 -0
  22. package/lib/cjs/src/dynamic-network/di/dynamicNetworkModuleFactory.js +2 -0
  23. package/lib/cjs/src/dynamic-network/di/dynamicNetworkModuleFactory.js.map +7 -0
  24. package/lib/cjs/src/dynamic-network/di/dynamicNetworkTypes.js +2 -0
  25. package/lib/cjs/src/dynamic-network/di/dynamicNetworkTypes.js.map +7 -0
  26. package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.js +2 -0
  27. package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.js.map +7 -0
  28. package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js +2 -0
  29. package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js.map +7 -0
  30. package/lib/cjs/src/dynamic-network/model/DynamicNetworkConfiguration.js +2 -0
  31. package/lib/cjs/src/dynamic-network/model/DynamicNetworkConfiguration.js.map +7 -0
  32. package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.test.js +1 -1
  33. package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.test.js.map +2 -2
  34. package/lib/cjs/src/index.js +1 -1
  35. package/lib/cjs/src/index.js.map +2 -2
  36. package/lib/cjs/src/nft/data/HttpNftDataSource.js +1 -1
  37. package/lib/cjs/src/nft/data/HttpNftDataSource.js.map +2 -2
  38. package/lib/cjs/src/nft/data/HttpNftDataSource.test.js +1 -1
  39. package/lib/cjs/src/nft/data/HttpNftDataSource.test.js.map +2 -2
  40. package/lib/cjs/src/pki/domain/DefaultPkiCertificateLoader.js +1 -1
  41. package/lib/cjs/src/pki/domain/DefaultPkiCertificateLoader.js.map +3 -3
  42. package/lib/cjs/src/pki/domain/DefaultPkiCertificateLoader.test.js +1 -1
  43. package/lib/cjs/src/pki/domain/DefaultPkiCertificateLoader.test.js.map +3 -3
  44. package/lib/cjs/src/shared/model/ClearSignContext.js +1 -1
  45. package/lib/cjs/src/shared/model/ClearSignContext.js.map +2 -2
  46. package/lib/cjs/src/solana/data/HttpSolanaOwnerInfoDataSource.js +1 -1
  47. package/lib/cjs/src/solana/data/HttpSolanaOwnerInfoDataSource.js.map +2 -2
  48. package/lib/cjs/src/solana/data/HttpSolanaOwnerInfoDataSource.test.js +1 -1
  49. package/lib/cjs/src/solana/data/HttpSolanaOwnerInfoDataSource.test.js.map +2 -2
  50. package/lib/cjs/src/transaction/data/HttpProxyDataSource.js +1 -1
  51. package/lib/cjs/src/transaction/data/HttpProxyDataSource.js.map +3 -3
  52. package/lib/cjs/src/transaction/data/HttpProxyDataSource.test.js +1 -1
  53. package/lib/cjs/src/transaction/data/HttpProxyDataSource.test.js.map +2 -2
  54. package/lib/cjs/src/transaction/data/dto/ProxyDelegateCallDto.js +1 -1
  55. package/lib/cjs/src/transaction/data/dto/ProxyDelegateCallDto.js.map +1 -1
  56. package/lib/cjs/src/transaction/domain/TransactionContextLoader.js +1 -1
  57. package/lib/cjs/src/transaction/domain/TransactionContextLoader.js.map +3 -3
  58. package/lib/cjs/src/transaction/domain/TransactionContextLoader.test.js +1 -1
  59. package/lib/cjs/src/transaction/domain/TransactionContextLoader.test.js.map +3 -3
  60. package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.js +1 -1
  61. package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.js.map +2 -2
  62. package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.test.js +1 -1
  63. package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.test.js.map +2 -2
  64. package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.test.js +1 -1
  65. package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.test.js.map +2 -2
  66. package/lib/cjs/src/uniswap/domain/UniswapContextLoader.js +1 -1
  67. package/lib/cjs/src/uniswap/domain/UniswapContextLoader.js.map +2 -2
  68. package/lib/esm/package.json +1 -1
  69. package/lib/esm/src/ContextModuleBuilder.js +1 -1
  70. package/lib/esm/src/ContextModuleBuilder.js.map +3 -3
  71. package/lib/esm/src/ContextModuleBuilder.test.js +1 -1
  72. package/lib/esm/src/ContextModuleBuilder.test.js.map +2 -2
  73. package/lib/esm/src/DefaultContextModule.js +1 -1
  74. package/lib/esm/src/DefaultContextModule.js.map +3 -3
  75. package/lib/esm/src/DefaultContextModule.test.js +1 -1
  76. package/lib/esm/src/DefaultContextModule.test.js.map +2 -2
  77. package/lib/esm/src/di.js +1 -1
  78. package/lib/esm/src/di.js.map +3 -3
  79. package/lib/esm/src/dynamic-network/data/DynamicNetworkDataSource.js +1 -0
  80. package/lib/esm/src/dynamic-network/data/DynamicNetworkDataSource.js.map +7 -0
  81. package/lib/esm/src/dynamic-network/data/HttpDynamicNetworkDataSource.js +2 -0
  82. package/lib/esm/src/dynamic-network/data/HttpDynamicNetworkDataSource.js.map +7 -0
  83. package/lib/esm/src/dynamic-network/data/HttpDynamicNetworkDataSource.test.js +2 -0
  84. package/lib/esm/src/dynamic-network/data/HttpDynamicNetworkDataSource.test.js.map +7 -0
  85. package/lib/esm/src/dynamic-network/data/dto/DynamicNetworkApiResponseDto.js +1 -0
  86. package/lib/esm/src/dynamic-network/data/dto/DynamicNetworkApiResponseDto.js.map +7 -0
  87. package/lib/esm/src/dynamic-network/di/dynamicNetworkModuleFactory.js +2 -0
  88. package/lib/esm/src/dynamic-network/di/dynamicNetworkModuleFactory.js.map +7 -0
  89. package/lib/esm/src/dynamic-network/di/dynamicNetworkTypes.js +2 -0
  90. package/lib/esm/src/dynamic-network/di/dynamicNetworkTypes.js.map +7 -0
  91. package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.js +2 -0
  92. package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.js.map +7 -0
  93. package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js +2 -0
  94. package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js.map +7 -0
  95. package/lib/esm/src/dynamic-network/model/DynamicNetworkConfiguration.js +1 -0
  96. package/lib/esm/src/dynamic-network/model/DynamicNetworkConfiguration.js.map +7 -0
  97. package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.test.js +1 -1
  98. package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.test.js.map +2 -2
  99. package/lib/esm/src/index.js +1 -1
  100. package/lib/esm/src/index.js.map +2 -2
  101. package/lib/esm/src/nft/data/HttpNftDataSource.js +1 -1
  102. package/lib/esm/src/nft/data/HttpNftDataSource.js.map +2 -2
  103. package/lib/esm/src/nft/data/HttpNftDataSource.test.js +1 -1
  104. package/lib/esm/src/nft/data/HttpNftDataSource.test.js.map +2 -2
  105. package/lib/esm/src/pki/domain/DefaultPkiCertificateLoader.js +1 -1
  106. package/lib/esm/src/pki/domain/DefaultPkiCertificateLoader.js.map +3 -3
  107. package/lib/esm/src/pki/domain/DefaultPkiCertificateLoader.test.js +1 -1
  108. package/lib/esm/src/pki/domain/DefaultPkiCertificateLoader.test.js.map +3 -3
  109. package/lib/esm/src/shared/model/ClearSignContext.js +1 -1
  110. package/lib/esm/src/shared/model/ClearSignContext.js.map +2 -2
  111. package/lib/esm/src/solana/data/HttpSolanaOwnerInfoDataSource.js +1 -1
  112. package/lib/esm/src/solana/data/HttpSolanaOwnerInfoDataSource.js.map +2 -2
  113. package/lib/esm/src/solana/data/HttpSolanaOwnerInfoDataSource.test.js +1 -1
  114. package/lib/esm/src/solana/data/HttpSolanaOwnerInfoDataSource.test.js.map +2 -2
  115. package/lib/esm/src/transaction/data/HttpProxyDataSource.js +1 -1
  116. package/lib/esm/src/transaction/data/HttpProxyDataSource.js.map +3 -3
  117. package/lib/esm/src/transaction/data/HttpProxyDataSource.test.js +1 -1
  118. package/lib/esm/src/transaction/data/HttpProxyDataSource.test.js.map +2 -2
  119. package/lib/esm/src/transaction/domain/TransactionContextLoader.js +1 -1
  120. package/lib/esm/src/transaction/domain/TransactionContextLoader.js.map +3 -3
  121. package/lib/esm/src/transaction/domain/TransactionContextLoader.test.js +1 -1
  122. package/lib/esm/src/transaction/domain/TransactionContextLoader.test.js.map +3 -3
  123. package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.js +1 -1
  124. package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.js.map +2 -2
  125. package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.test.js +1 -1
  126. package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.test.js.map +2 -2
  127. package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.test.js +1 -1
  128. package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.test.js.map +2 -2
  129. package/lib/esm/src/uniswap/domain/UniswapContextLoader.js +1 -1
  130. package/lib/esm/src/uniswap/domain/UniswapContextLoader.js.map +2 -2
  131. package/lib/types/src/DefaultContextModule.d.ts.map +1 -1
  132. package/lib/types/src/config/model/ContextModuleConfig.d.ts +1 -1
  133. package/lib/types/src/config/model/ContextModuleConfig.d.ts.map +1 -1
  134. package/lib/types/src/di.d.ts.map +1 -1
  135. package/lib/types/src/dynamic-network/data/DynamicNetworkDataSource.d.ts +6 -0
  136. package/lib/types/src/dynamic-network/data/DynamicNetworkDataSource.d.ts.map +1 -0
  137. package/lib/types/src/dynamic-network/data/HttpDynamicNetworkDataSource.d.ts +13 -0
  138. package/lib/types/src/dynamic-network/data/HttpDynamicNetworkDataSource.d.ts.map +1 -0
  139. package/lib/types/src/dynamic-network/data/HttpDynamicNetworkDataSource.test.d.ts +2 -0
  140. package/lib/types/src/dynamic-network/data/HttpDynamicNetworkDataSource.test.d.ts.map +1 -0
  141. package/lib/types/src/dynamic-network/data/dto/DynamicNetworkApiResponseDto.d.ts +14 -0
  142. package/lib/types/src/dynamic-network/data/dto/DynamicNetworkApiResponseDto.d.ts.map +1 -0
  143. package/lib/types/src/dynamic-network/di/dynamicNetworkModuleFactory.d.ts +3 -0
  144. package/lib/types/src/dynamic-network/di/dynamicNetworkModuleFactory.d.ts.map +1 -0
  145. package/lib/types/src/dynamic-network/di/dynamicNetworkTypes.d.ts +5 -0
  146. package/lib/types/src/dynamic-network/di/dynamicNetworkTypes.d.ts.map +1 -0
  147. package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.d.ts +15 -0
  148. package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.d.ts.map +1 -0
  149. package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.test.d.ts +2 -0
  150. package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.test.d.ts.map +1 -0
  151. package/lib/types/src/dynamic-network/model/DynamicNetworkConfiguration.d.ts +16 -0
  152. package/lib/types/src/dynamic-network/model/DynamicNetworkConfiguration.d.ts.map +1 -0
  153. package/lib/types/src/index.d.ts +2 -0
  154. package/lib/types/src/index.d.ts.map +1 -1
  155. package/lib/types/src/pki/domain/DefaultPkiCertificateLoader.d.ts.map +1 -1
  156. package/lib/types/src/shared/model/ClearSignContext.d.ts +3 -0
  157. package/lib/types/src/shared/model/ClearSignContext.d.ts.map +1 -1
  158. package/lib/types/src/transaction/data/HttpProxyDataSource.d.ts +2 -1
  159. package/lib/types/src/transaction/data/HttpProxyDataSource.d.ts.map +1 -1
  160. package/lib/types/src/transaction/data/dto/ProxyDelegateCallDto.d.ts +1 -1
  161. package/lib/types/src/transaction/data/dto/ProxyDelegateCallDto.d.ts.map +1 -1
  162. package/lib/types/src/transaction/domain/TransactionContextLoader.d.ts +3 -1
  163. package/lib/types/src/transaction/domain/TransactionContextLoader.d.ts.map +1 -1
  164. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  165. package/package.json +4 -4
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/dynamic-network/domain/DynamicNetworkContextLoader.ts"],
4
+ "sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { type DynamicNetworkDataSource } from \"@/dynamic-network/data/DynamicNetworkDataSource\";\nimport { dynamicNetworkTypes } from \"@/dynamic-network/di/dynamicNetworkTypes\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport {\n TransactionContext,\n TransactionFieldContext,\n} from \"@/shared/model/TransactionContext\";\nimport { HexStringUtils } from \"@/shared/utils/HexStringUtils\";\n\nconst NETWORK_SIGNATURE_TAG = \"15\";\n\n@injectable()\nexport class DynamicNetworkContextLoader implements ContextLoader {\n private readonly _networkDataSource: DynamicNetworkDataSource;\n private readonly _config: ContextModuleConfig;\n private readonly _certificateLoader: PkiCertificateLoader;\n\n constructor(\n @inject(dynamicNetworkTypes.DynamicNetworkDataSource)\n networkDataSource: DynamicNetworkDataSource,\n @inject(configTypes.Config)\n config: ContextModuleConfig,\n @inject(pkiTypes.PkiCertificateLoader)\n certificateLoader: PkiCertificateLoader,\n ) {\n this._networkDataSource = networkDataSource;\n this._config = config;\n this._certificateLoader = certificateLoader;\n }\n\n async load(ctx: TransactionContext): Promise<ClearSignContext[]> {\n if (ctx.deviceModelId === DeviceModelId.NANO_S) return [];\n\n const result = await this._networkDataSource.getDynamicNetworkConfiguration(\n ctx.chainId,\n );\n\n // Fetch certificate for the network configuration upfront\n const certificate = await this._certificateLoader.loadCertificate({\n keyId: KeyId.CalNetwork,\n keyUsage: KeyUsage.Network,\n targetDevice: ctx.deviceModelId,\n });\n\n return result.caseOf({\n Left: () => [],\n Right: (configuration) => {\n const contexts: ClearSignContext[] = [];\n const descriptor = configuration.descriptors[ctx.deviceModelId];\n\n if (!descriptor) {\n return [];\n }\n\n const signature = descriptor.signatures[this._config.cal.mode];\n\n if (!signature) {\n return [];\n }\n\n const configPayload = HexStringUtils.appendSignatureToPayload(\n descriptor.data,\n signature,\n NETWORK_SIGNATURE_TAG,\n );\n\n contexts.push({\n type: ClearSignContextType.DYNAMIC_NETWORK,\n payload: configPayload,\n certificate,\n });\n\n // Add icon if available in the descriptor\n if (descriptor.icon) {\n // Icons don't need signatures appended\n contexts.push({\n type: ClearSignContextType.DYNAMIC_NETWORK_ICON,\n payload: descriptor.icon,\n });\n }\n\n return contexts;\n },\n });\n }\n\n // Dynamic network context doesn't support field-level loading\n loadField(_field: TransactionFieldContext): Promise<ClearSignContext | null> {\n return Promise.resolve(null);\n }\n}\n"],
5
+ "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAA8B,2CAC9BC,EAAmC,qBAEnCC,EAA4B,mCAG5BC,EAAoC,oDACpCC,EAAyB,6BAEzBC,EAAsB,6BACtBC,EAAyB,gCAEzBC,EAGO,2CAKPC,EAA+B,yCAE/B,MAAMC,EAAwB,KAGvB,IAAMC,EAAN,KAA2D,CAC/C,mBACA,QACA,mBAEjB,YAEEC,EAEAC,EAEAC,EACA,CACA,KAAK,mBAAqBF,EAC1B,KAAK,QAAUC,EACf,KAAK,mBAAqBC,CAC5B,CAEA,MAAM,KAAKC,EAAsD,CAC/D,GAAIA,EAAI,gBAAkB,gBAAc,OAAQ,MAAO,CAAC,EAExD,MAAMC,EAAS,MAAM,KAAK,mBAAmB,+BAC3CD,EAAI,OACN,EAGME,EAAc,MAAM,KAAK,mBAAmB,gBAAgB,CAChE,MAAO,QAAM,WACb,SAAU,WAAS,QACnB,aAAcF,EAAI,aACpB,CAAC,EAED,OAAOC,EAAO,OAAO,CACnB,KAAM,IAAM,CAAC,EACb,MAAQE,GAAkB,CACxB,MAAMC,EAA+B,CAAC,EAChCC,EAAaF,EAAc,YAAYH,EAAI,aAAa,EAE9D,GAAI,CAACK,EACH,MAAO,CAAC,EAGV,MAAMC,EAAYD,EAAW,WAAW,KAAK,QAAQ,IAAI,IAAI,EAE7D,GAAI,CAACC,EACH,MAAO,CAAC,EAGV,MAAMC,EAAgB,iBAAe,yBACnCF,EAAW,KACXC,EACAX,CACF,EAEA,OAAAS,EAAS,KAAK,CACZ,KAAM,uBAAqB,gBAC3B,QAASG,EACT,YAAAL,CACF,CAAC,EAGGG,EAAW,MAEbD,EAAS,KAAK,CACZ,KAAM,uBAAqB,qBAC3B,QAASC,EAAW,IACtB,CAAC,EAGID,CACT,CACF,CAAC,CACH,CAGA,UAAUI,EAAmE,CAC3E,OAAO,QAAQ,QAAQ,IAAI,CAC7B,CACF,EA9EaZ,EAANa,EAAA,IADN,cAAW,EAOPC,EAAA,eAAO,sBAAoB,wBAAwB,GAEnDA,EAAA,eAAO,cAAY,MAAM,GAEzBA,EAAA,eAAO,WAAS,oBAAoB,IAV5Bd",
6
+ "names": ["DynamicNetworkContextLoader_exports", "__export", "DynamicNetworkContextLoader", "__toCommonJS", "import_device_management_kit", "import_inversify", "import_configTypes", "import_dynamicNetworkTypes", "import_pkiTypes", "import_KeyId", "import_KeyUsage", "import_ClearSignContext", "import_HexStringUtils", "NETWORK_SIGNATURE_TAG", "DynamicNetworkContextLoader", "networkDataSource", "config", "certificateLoader", "ctx", "result", "certificate", "configuration", "contexts", "descriptor", "signature", "configPayload", "_field", "__decorateClass", "__decorateParam"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var e=require("@ledgerhq/device-management-kit"),n=require("purify-ts"),f=require("../../dynamic-network/domain/DynamicNetworkContextLoader"),m=require("../../pki/model/KeyId"),g=require("../../pki/model/KeyUsage"),d=require("../../shared/model/ClearSignContext");describe("DynamicNetworkContextLoader",()=>{const a={getDynamicNetworkConfiguration:vi.fn()},l={cal:{url:"https://crypto-assets-service.api.ledger.com",mode:"prod",branch:"main"},web3checks:{url:"https://web3checks.api.ledger.com"},metadataServiceDomain:{url:"https://metadata.api.ledger.com"},defaultLoaders:!0,customLoaders:[]},p={loadCertificate:vi.fn()},u={keyUsageNumber:1,payload:new Uint8Array([1,2,3])},c=new f.DynamicNetworkContextLoader(a,l,p),t=o=>({data:"",descriptorType:"",descriptorVersion:"",signatures:{prod:"",test:""},icon:void 0,...o});beforeEach(()=>{vi.restoreAllMocks(),vi.spyOn(p,"loadCertificate").mockResolvedValue(u)}),describe("load function",()=>{it("should return empty array when network data source returns error",async()=>{const o={chainId:1,deviceModelId:e.DeviceModelId.STAX,to:"0x123",data:"0x456",selector:"0x789"};vi.spyOn(a,"getDynamicNetworkConfiguration").mockResolvedValue((0,n.Left)(new Error("Network error")));const i=await c.load(o);expect(i).toEqual([]),expect(a.getDynamicNetworkConfiguration).toHaveBeenCalledWith(1)}),it("should return empty array when descriptor for device model is not found",async()=>{const o={chainId:1,deviceModelId:e.DeviceModelId.STAX,to:"0x123",data:"0x456",selector:"0x789"},i={id:"ethereum",descriptors:{[e.DeviceModelId.NANO_S]:t(),[e.DeviceModelId.NANO_SP]:t(),[e.DeviceModelId.NANO_X]:t(),[e.DeviceModelId.FLEX]:t({data:"0x0101",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"prod-sig",test:"test-sig"},icon:void 0})}};vi.spyOn(a,"getDynamicNetworkConfiguration").mockResolvedValue((0,n.Right)(i));const r=await c.load(o);expect(r).toEqual([])}),it("should return empty array when signature for mode is not found",async()=>{const o={chainId:1,deviceModelId:e.DeviceModelId.STAX,to:"0x123",data:"0x456",selector:"0x789"},i={id:"ethereum",descriptors:{[e.DeviceModelId.APEX]:t(),[e.DeviceModelId.NANO_S]:t(),[e.DeviceModelId.NANO_SP]:t(),[e.DeviceModelId.NANO_X]:t(),[e.DeviceModelId.FLEX]:t(),[e.DeviceModelId.STAX]:t({data:"0x0101",descriptorType:"network",descriptorVersion:"v1",signatures:{test:"test-sig"},icon:void 0})}};vi.spyOn(a,"getDynamicNetworkConfiguration").mockResolvedValue((0,n.Right)(i));const r=await c.load(o);expect(r).toEqual([])}),it("should return context with network configuration when all data is available",async()=>{const o={chainId:137,deviceModelId:e.DeviceModelId.STAX,to:"0x123",data:"0x456",selector:"0x789"},i={id:"polygon",descriptors:{[e.DeviceModelId.APEX]:t(),[e.DeviceModelId.NANO_S]:t(),[e.DeviceModelId.NANO_SP]:t(),[e.DeviceModelId.NANO_X]:t(),[e.DeviceModelId.FLEX]:t(),[e.DeviceModelId.STAX]:{data:"0x0101080201015101012308000000000000008952",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"3045022100cf42c039c16fc95dc97c09f15cdd93bed0e63ee45cf5c38c2b30bb8a3bc17f8d022053a96c9e51695c3c1c1a31f5cbf84bd6febadc97f4bb02bdc67cf3e24ad0c32d",test:"test-sig"},icon:void 0}}};vi.spyOn(a,"getDynamicNetworkConfiguration").mockResolvedValue((0,n.Right)(i));const r=await c.load(o);expect(r).toHaveLength(1),expect(r[0]).toMatchObject({type:d.ClearSignContextType.DYNAMIC_NETWORK,payload:expect.stringContaining("0x0101080201015101012308000000000000008952"),certificate:u}),expect(p.loadCertificate).toHaveBeenCalledWith({keyId:m.KeyId.CalNetwork,keyUsage:g.KeyUsage.Network,targetDevice:e.DeviceModelId.STAX})}),it("should include icon context when icon is available",async()=>{const o={chainId:1,deviceModelId:e.DeviceModelId.STAX,to:"0x123",data:"0x456",selector:"0x789"},i={id:"ethereum",descriptors:{[e.DeviceModelId.APEX]:t(),[e.DeviceModelId.NANO_S]:t(),[e.DeviceModelId.NANO_SP]:t(),[e.DeviceModelId.NANO_X]:t(),[e.DeviceModelId.FLEX]:t(),[e.DeviceModelId.STAX]:{data:"0x0101",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"prod-sig",test:"test-sig"},icon:"icon-hex-data"}}};vi.spyOn(a,"getDynamicNetworkConfiguration").mockResolvedValue((0,n.Right)(i));const r=await c.load(o);expect(r).toHaveLength(2),expect(r[0]).toMatchObject({type:d.ClearSignContextType.DYNAMIC_NETWORK,payload:expect.any(String),certificate:u}),expect(r[1]).toMatchObject({type:d.ClearSignContextType.DYNAMIC_NETWORK_ICON,payload:"icon-hex-data"})}),it("should handle multiple device models correctly",async()=>{const o={chainId:1,deviceModelId:e.DeviceModelId.FLEX,to:"0x123",data:"0x456",selector:"0x789"},i={id:"ethereum",descriptors:{[e.DeviceModelId.APEX]:t(),[e.DeviceModelId.NANO_S]:t(),[e.DeviceModelId.NANO_SP]:t(),[e.DeviceModelId.NANO_X]:t(),[e.DeviceModelId.FLEX]:{data:"0xFLEX",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"flex-prod-sig",test:"flex-test-sig"},icon:void 0},[e.DeviceModelId.STAX]:{data:"0xSTAX",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"stax-prod-sig",test:"stax-test-sig"},icon:void 0}}};vi.spyOn(a,"getDynamicNetworkConfiguration").mockResolvedValue((0,n.Right)(i));const r=await c.load(o);expect(r).toHaveLength(1);const s=r[0];s&&"payload"in s&&(expect(s.payload).toContain("0xFLEX"),expect(s.payload).toContain("flex-prod-sig"))}),it("should use test mode signature when configured",async()=>{const o=new f.DynamicNetworkContextLoader(a,{...l,cal:{...l.cal,mode:"test"}},p),i={chainId:1,deviceModelId:e.DeviceModelId.STAX,to:"0x123",data:"0x456",selector:"0x789"},r={id:"ethereum",descriptors:{[e.DeviceModelId.APEX]:t(),[e.DeviceModelId.NANO_S]:t(),[e.DeviceModelId.NANO_SP]:t(),[e.DeviceModelId.NANO_X]:t(),[e.DeviceModelId.FLEX]:t(),[e.DeviceModelId.STAX]:{data:"0x0101",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"prod-sig",test:"test-sig"},icon:void 0}}};vi.spyOn(a,"getDynamicNetworkConfiguration").mockResolvedValue((0,n.Right)(r));const s=await o.load(i);expect(s).toHaveLength(1);const y=s[0];y&&"payload"in y&&expect(y.payload).toContain("test-sig")})}),describe("loadField function",()=>{it("should always return null",async()=>{const o={type:d.ClearSignContextType.TOKEN,chainId:1,address:"0x123"},i=await c.loadField(o);expect(i).toBeNull()})})});
2
+ //# sourceMappingURL=DynamicNetworkContextLoader.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/dynamic-network/domain/DynamicNetworkContextLoader.test.ts"],
4
+ "sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { type DynamicNetworkDataSource } from \"@/dynamic-network/data/DynamicNetworkDataSource\";\nimport { DynamicNetworkContextLoader } from \"@/dynamic-network/domain/DynamicNetworkContextLoader\";\nimport {\n type DynamicNetworkConfiguration,\n type DynamicNetworkDescriptor,\n} from \"@/dynamic-network/model/DynamicNetworkConfiguration\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { type PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport {\n type TransactionContext,\n type TransactionFieldContext,\n} from \"@/shared/model/TransactionContext\";\n\ndescribe(\"DynamicNetworkContextLoader\", () => {\n const mockNetworkDataSource: DynamicNetworkDataSource = {\n getDynamicNetworkConfiguration: vi.fn(),\n };\n\n const mockConfig: ContextModuleConfig = {\n cal: {\n url: \"https://crypto-assets-service.api.ledger.com\",\n mode: \"prod\",\n branch: \"main\",\n },\n web3checks: {\n url: \"https://web3checks.api.ledger.com\",\n },\n metadataServiceDomain: {\n url: \"https://metadata.api.ledger.com\",\n },\n defaultLoaders: true,\n customLoaders: [],\n };\n\n const mockCertificateLoader: PkiCertificateLoader = {\n loadCertificate: vi.fn(),\n };\n\n const mockCertificate: PkiCertificate = {\n keyUsageNumber: 1,\n payload: new Uint8Array([0x01, 0x02, 0x03]),\n };\n\n const loader = new DynamicNetworkContextLoader(\n mockNetworkDataSource,\n mockConfig,\n mockCertificateLoader,\n );\n\n // Helper function to create a mock NetworkDescriptor\n const createMockDescriptor = (\n partial?: Partial<DynamicNetworkDescriptor>,\n ): DynamicNetworkDescriptor => ({\n data: \"\",\n descriptorType: \"\",\n descriptorVersion: \"\",\n signatures: {\n prod: \"\",\n test: \"\",\n },\n icon: undefined,\n ...partial,\n });\n\n beforeEach(() => {\n vi.restoreAllMocks();\n vi.spyOn(mockCertificateLoader, \"loadCertificate\").mockResolvedValue(\n mockCertificate,\n );\n });\n\n describe(\"load function\", () => {\n it(\"should return empty array when network data source returns error\", async () => {\n // GIVEN\n const transaction: TransactionContext = {\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n to: \"0x123\",\n data: \"0x456\",\n selector: \"0x789\",\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Left(new Error(\"Network error\")));\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n expect(\n mockNetworkDataSource.getDynamicNetworkConfiguration,\n ).toHaveBeenCalledWith(1);\n });\n\n it(\"should return empty array when descriptor for device model is not found\", async () => {\n // GIVEN\n const transaction: TransactionContext = {\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n to: \"0x123\",\n data: \"0x456\",\n selector: \"0x789\",\n };\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"ethereum\",\n descriptors: {\n [DeviceModelId.NANO_S]: createMockDescriptor(),\n [DeviceModelId.NANO_SP]: createMockDescriptor(),\n [DeviceModelId.NANO_X]: createMockDescriptor(),\n // STAX descriptor is intentionally missing\n [DeviceModelId.FLEX]: createMockDescriptor({\n data: \"0x0101\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"prod-sig\",\n test: \"test-sig\",\n },\n icon: undefined,\n }),\n } as Record<DeviceModelId, DynamicNetworkDescriptor>,\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return empty array when signature for mode is not found\", async () => {\n // GIVEN\n const transaction: TransactionContext = {\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n to: \"0x123\",\n data: \"0x456\",\n selector: \"0x789\",\n };\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"ethereum\",\n descriptors: {\n [DeviceModelId.APEX]: createMockDescriptor(),\n [DeviceModelId.NANO_S]: createMockDescriptor(),\n [DeviceModelId.NANO_SP]: createMockDescriptor(),\n [DeviceModelId.NANO_X]: createMockDescriptor(),\n [DeviceModelId.FLEX]: createMockDescriptor(),\n [DeviceModelId.STAX]: createMockDescriptor({\n data: \"0x0101\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n test: \"test-sig\",\n // Missing prod signature - intentionally partial\n } as { prod: string; test: string },\n icon: undefined,\n }),\n },\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return context with network configuration when all data is available\", async () => {\n // GIVEN\n const transaction: TransactionContext = {\n chainId: 137,\n deviceModelId: DeviceModelId.STAX,\n to: \"0x123\",\n data: \"0x456\",\n selector: \"0x789\",\n };\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"polygon\",\n descriptors: {\n [DeviceModelId.APEX]: createMockDescriptor(),\n [DeviceModelId.NANO_S]: createMockDescriptor(),\n [DeviceModelId.NANO_SP]: createMockDescriptor(),\n [DeviceModelId.NANO_X]: createMockDescriptor(),\n [DeviceModelId.FLEX]: createMockDescriptor(),\n [DeviceModelId.STAX]: {\n data: \"0x0101080201015101012308000000000000008952\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"3045022100cf42c039c16fc95dc97c09f15cdd93bed0e63ee45cf5c38c2b30bb8a3bc17f8d022053a96c9e51695c3c1c1a31f5cbf84bd6febadc97f4bb02bdc67cf3e24ad0c32d\",\n test: \"test-sig\",\n },\n icon: undefined,\n },\n },\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toHaveLength(1);\n expect(result[0]).toMatchObject({\n type: ClearSignContextType.DYNAMIC_NETWORK,\n payload: expect.stringContaining(\n \"0x0101080201015101012308000000000000008952\",\n ),\n certificate: mockCertificate,\n });\n expect(mockCertificateLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: KeyId.CalNetwork,\n keyUsage: KeyUsage.Network,\n targetDevice: DeviceModelId.STAX,\n });\n });\n\n it(\"should include icon context when icon is available\", async () => {\n // GIVEN\n const transaction: TransactionContext = {\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n to: \"0x123\",\n data: \"0x456\",\n selector: \"0x789\",\n };\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"ethereum\",\n descriptors: {\n [DeviceModelId.APEX]: createMockDescriptor(),\n [DeviceModelId.NANO_S]: createMockDescriptor(),\n [DeviceModelId.NANO_SP]: createMockDescriptor(),\n [DeviceModelId.NANO_X]: createMockDescriptor(),\n [DeviceModelId.FLEX]: createMockDescriptor(),\n [DeviceModelId.STAX]: {\n data: \"0x0101\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"prod-sig\",\n test: \"test-sig\",\n },\n icon: \"icon-hex-data\",\n },\n },\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toHaveLength(2);\n expect(result[0]).toMatchObject({\n type: ClearSignContextType.DYNAMIC_NETWORK,\n payload: expect.any(String),\n certificate: mockCertificate,\n });\n expect(result[1]).toMatchObject({\n type: ClearSignContextType.DYNAMIC_NETWORK_ICON,\n payload: \"icon-hex-data\",\n });\n });\n\n it(\"should handle multiple device models correctly\", async () => {\n // GIVEN\n const transaction: TransactionContext = {\n chainId: 1,\n deviceModelId: DeviceModelId.FLEX,\n to: \"0x123\",\n data: \"0x456\",\n selector: \"0x789\",\n };\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"ethereum\",\n descriptors: {\n [DeviceModelId.APEX]: createMockDescriptor(),\n [DeviceModelId.NANO_S]: createMockDescriptor(),\n [DeviceModelId.NANO_SP]: createMockDescriptor(),\n [DeviceModelId.NANO_X]: createMockDescriptor(),\n [DeviceModelId.FLEX]: {\n data: \"0xFLEX\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"flex-prod-sig\",\n test: \"flex-test-sig\",\n },\n icon: undefined,\n },\n [DeviceModelId.STAX]: {\n data: \"0xSTAX\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"stax-prod-sig\",\n test: \"stax-test-sig\",\n },\n icon: undefined,\n },\n },\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toHaveLength(1);\n const context = result[0];\n if (context && \"payload\" in context) {\n expect(context.payload).toContain(\"0xFLEX\");\n expect(context.payload).toContain(\"flex-prod-sig\");\n }\n });\n\n it(\"should use test mode signature when configured\", async () => {\n // GIVEN\n const testModeLoader = new DynamicNetworkContextLoader(\n mockNetworkDataSource,\n { ...mockConfig, cal: { ...mockConfig.cal, mode: \"test\" } },\n mockCertificateLoader,\n );\n const transaction: TransactionContext = {\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n to: \"0x123\",\n data: \"0x456\",\n selector: \"0x789\",\n };\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"ethereum\",\n descriptors: {\n [DeviceModelId.APEX]: createMockDescriptor(),\n [DeviceModelId.NANO_S]: createMockDescriptor(),\n [DeviceModelId.NANO_SP]: createMockDescriptor(),\n [DeviceModelId.NANO_X]: createMockDescriptor(),\n [DeviceModelId.FLEX]: createMockDescriptor(),\n [DeviceModelId.STAX]: {\n data: \"0x0101\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"prod-sig\",\n test: \"test-sig\",\n },\n icon: undefined,\n },\n },\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await testModeLoader.load(transaction);\n\n // THEN\n expect(result).toHaveLength(1);\n const context = result[0];\n if (context && \"payload\" in context) {\n expect(context.payload).toContain(\"test-sig\");\n }\n });\n });\n\n describe(\"loadField function\", () => {\n it(\"should always return null\", async () => {\n // GIVEN\n const field: TransactionFieldContext = {\n type: ClearSignContextType.TOKEN,\n chainId: 1,\n address: \"0x123\",\n };\n\n // WHEN\n const result = await loader.loadField(field);\n\n // THEN\n expect(result).toBeNull();\n });\n });\n});\n"],
5
+ "mappings": "aAAA,IAAAA,EAA8B,2CAC9BC,EAA4B,qBAI5BC,EAA4C,gEAM5CC,EAAsB,6BACtBC,EAAyB,gCAEzBC,EAAqC,2CAMrC,SAAS,8BAA+B,IAAM,CAC5C,MAAMC,EAAkD,CACtD,+BAAgC,GAAG,GAAG,CACxC,EAEMC,EAAkC,CACtC,IAAK,CACH,IAAK,+CACL,KAAM,OACN,OAAQ,MACV,EACA,WAAY,CACV,IAAK,mCACP,EACA,sBAAuB,CACrB,IAAK,iCACP,EACA,eAAgB,GAChB,cAAe,CAAC,CAClB,EAEMC,EAA8C,CAClD,gBAAiB,GAAG,GAAG,CACzB,EAEMC,EAAkC,CACtC,eAAgB,EAChB,QAAS,IAAI,WAAW,CAAC,EAAM,EAAM,CAAI,CAAC,CAC5C,EAEMC,EAAS,IAAI,8BACjBJ,EACAC,EACAC,CACF,EAGMG,EACJC,IAC8B,CAC9B,KAAM,GACN,eAAgB,GAChB,kBAAmB,GACnB,WAAY,CACV,KAAM,GACN,KAAM,EACR,EACA,KAAM,OACN,GAAGA,CACL,GAEA,WAAW,IAAM,CACf,GAAG,gBAAgB,EACnB,GAAG,MAAMJ,EAAuB,iBAAiB,EAAE,kBAC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E,qBAAkB,SAAMS,CAAa,CAAC,EAGxC,MAAMD,EAAS,MAAMG,EAAe,KAAKJ,CAAW,EAGpD,OAAOC,CAAM,EAAE,aAAa,CAAC,EAC7B,MAAME,EAAUF,EAAO,CAAC,EACpBE,GAAW,YAAaA,GAC1B,OAAOA,EAAQ,OAAO,EAAE,UAAU,UAAU,CAEhD,CAAC,CACH,CAAC,EAED,SAAS,qBAAsB,IAAM,CACnC,GAAG,4BAA6B,SAAY,CAE1C,MAAME,EAAiC,CACrC,KAAM,uBAAqB,MAC3B,QAAS,EACT,QAAS,OACX,EAGMJ,EAAS,MAAMJ,EAAO,UAAUQ,CAAK,EAG3C,OAAOJ,CAAM,EAAE,SAAS,CAC1B,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["import_device_management_kit", "import_purify_ts", "import_DynamicNetworkContextLoader", "import_KeyId", "import_KeyUsage", "import_ClearSignContext", "mockNetworkDataSource", "mockConfig", "mockCertificateLoader", "mockCertificate", "loader", "createMockDescriptor", "partial", "transaction", "result", "networkConfig", "context", "testModeLoader", "field"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var o=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var c=(e,r,n,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of d(r))!p.call(e,t)&&t!==n&&o(e,t,{get:()=>r[t],enumerable:!(i=s(r,t))||i.enumerable});return e};var g=e=>c(o({},"__esModule",{value:!0}),e);var a={};module.exports=g(a);
2
+ //# sourceMappingURL=DynamicNetworkConfiguration.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/dynamic-network/model/DynamicNetworkConfiguration.ts"],
4
+ "sourcesContent": ["import { type DeviceModelId } from \"@ledgerhq/device-management-kit\";\n\nexport type DynamicNetworkDescriptor = {\n descriptorType: string;\n descriptorVersion: string;\n data: string;\n signatures: {\n prod: string;\n test: string;\n };\n icon: string | undefined;\n};\n\nexport type DynamicNetworkConfiguration = {\n id: string;\n descriptors: Record<DeviceModelId, DynamicNetworkDescriptor>;\n};\n"],
5
+ "mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
6
+ "names": ["DynamicNetworkConfiguration_exports", "__toCommonJS"]
7
+ }
@@ -1,2 +1,2 @@
1
- "use strict";var u=Object.create;var i=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var b=(s,o,r,a)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of f(o))!D.call(s,e)&&e!==r&&i(s,e,{get:()=>o[e],enumerable:!(a=E(o,e))||a.enumerable});return s};var I=(s,o,r)=>(r=s!=null?u(x(s)):{},b(o||!s||!s.__esModule?i(r,"default",{value:s,enumerable:!0}):r,s));var m=require("ethers"),l=require("purify-ts"),n=I(require("@/external-plugin/__tests__/abi.json")),y=require("../../external-plugin/domain/ExternalPluginContextLoader"),t=require("../../shared/model/ClearSignContext");const d=({abi:s,selectorDetails:o})=>({abi:s,selectorDetails:{erc20OfInterest:[],method:"",plugin:"",serializedData:"123456",signature:"7890",...o}}),p=(s,o,r)=>{const e=new m.Interface(JSON.stringify(s)).encodeFunctionData(o,r);return{to:"0x0",data:e,selector:e.slice(0,10)}};describe("ExternalPluginContextLoader",()=>{const s={getTokenInfosPayload:vi.fn()},o={getDappInfos:vi.fn()},r=new y.ExternalPluginContextLoader(o,s);beforeEach(()=>{vi.clearAllMocks(),vi.spyOn(s,"getTokenInfosPayload").mockImplementation(({address:a})=>Promise.resolve((0,l.Right)(`payload-${a}`)))}),describe("load function",async()=>{it("should return an empty array if no destination address is provided",async()=>{const a={},e=()=>r.load(a);await expect(e()).resolves.toEqual([])}),it("should return an empty array if no data provided",async()=>{const a={to:"0x0",data:"0x",selector:"0x0"},e=await r.load(a);expect(e).toEqual([])}),it("should return an empty array if no dapp info is povided",async()=>{const a=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(void 0));const e=await r.load(a);expect(e).toEqual([])}),it("should return e plugin if no erc20OfInterest is provided",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:[],method:"singleParam"}}),e=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return a list of context responses when one erc20OfInterest is provided for a single parameter",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),e=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual(expect.arrayContaining([{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"}]))}),it("should return a context response with only set external plugin when one erc20OfInterest is provided for a single parameter but no payload is feched",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),e=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a)),vi.spyOn(s,"getTokenInfosPayload").mockResolvedValue((0,l.Left)(Error("error")));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.ERROR,error:new Error("error")},{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return a list of context responses when two erc20OfInterest are provided for two parameters",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["fromToken","toToken"],method:"multipleParams"}}),e=p(n.default,"multipleParams",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual(expect.arrayContaining([{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"}]))}),it("should return a list of context responses when one erc20OfInterest is an array",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["fromToken.0","fromToken.1","fromToken.2","fromToken.-1"],method:"arrayParam"}}),e=p(n.default,"arrayParam",[["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7","0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return an error when a token datasource returns an error",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),e=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a)),vi.spyOn(s,"getTokenInfosPayload").mockResolvedValue((0,l.Left)(new Error("error")));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.ERROR,error:new Error("error")},{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return an error when the abi is not conform",async()=>{const a=d({abi:[{fakeabi:"notworking"}],selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),e=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.ERROR,error:new Error("[ContextModule] ExternalPluginContextLoader: Unable to parse abi")},{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should throw an error when the erc20OfInterest doest not exist in the transaction",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["notFound"],method:"singleParam"}}),e=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.ERROR,error:new Error("[ContextModule] ExternalPluginContextLoader: Unable to get address")}])}),it("should throw an error when an out-of-bounds element is present in erc20OfInterest",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["fromToken.3"],method:"arrayParam"}}),e=p(n.default,"arrayParam",[["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7","0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.ERROR,error:new RangeError("out of result range")}])}),it("should return a list of context responses when one erc20OfInterest is a complex struct",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["complexStruct.address1","complexStruct.param1.param2.0.param3.addresses.0","complexStruct.param1.param2.0.param3.addresses.1","complexStruct.param1.param2.0.param3.addresses.-1","complexStruct.param1.param2.1.param3.addresses.0","complexStruct.param1.param2.-1.param3.addresses.0"],method:"complexStructParam"}}),e=p(n.default,"complexStructParam",[{address1:"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",param1:{param2:[{param3:{addresses:["0xdAC17F958D2ee523a2206206994597C13D831ec7","0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"]}},{param3:{addresses:["0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]}}]}}]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return an error when datasource return a Left",async()=>{const a=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Left)(new Error("error")));const e=await r.load(a);expect(e).toEqual([{type:t.ClearSignContextType.ERROR,error:new Error("error")}])}),it("should return an error when transaction data is not a valid hex string",async()=>{const a={to:"0x0",data:"notAHexString"},e=await r.load(a);expect(e).toEqual([{type:t.ClearSignContextType.ERROR,error:new Error("Invalid selector")}])})})});
1
+ "use strict";var y=Object.create;var i=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var b=(s,o,r,a)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of f(o))!D.call(s,e)&&e!==r&&i(s,e,{get:()=>o[e],enumerable:!(a=E(o,e))||a.enumerable});return s};var I=(s,o,r)=>(r=s!=null?y(x(s)):{},b(o||!s||!s.__esModule?i(r,"default",{value:s,enumerable:!0}):r,s));var m=require("ethers"),l=require("purify-ts"),n=I(require("@/external-plugin/__tests__/abi.json")),u=require("../../external-plugin/domain/ExternalPluginContextLoader"),t=require("../../shared/model/ClearSignContext");const d=({abi:s,selectorDetails:o})=>({abi:s,selectorDetails:{erc20OfInterest:[],method:"",plugin:"",serializedData:"123456",signature:"7890",...o}}),p=(s,o,r)=>{const e=new m.Interface(JSON.stringify(s)).encodeFunctionData(o,r);return{to:"0x0",data:e,selector:e.slice(0,10)}};describe("ExternalPluginContextLoader",()=>{const s={getTokenInfosPayload:vi.fn()},o={getDappInfos:vi.fn()},r=new u.ExternalPluginContextLoader(o,s);beforeEach(()=>{vi.clearAllMocks(),vi.spyOn(s,"getTokenInfosPayload").mockImplementation(({address:a})=>Promise.resolve((0,l.Right)(`payload-${a}`)))}),describe("load function",()=>{it("should return an empty array if no destination address is provided",async()=>{const a={},e=()=>r.load(a);await expect(e()).resolves.toEqual([])}),it("should return an empty array if no data provided",async()=>{const a={to:"0x0",data:"0x",selector:"0x0"},e=await r.load(a);expect(e).toEqual([])}),it("should return an empty array if no dapp info is povided",async()=>{const a=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(void 0));const e=await r.load(a);expect(e).toEqual([])}),it("should return e plugin if no erc20OfInterest is provided",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:[],method:"singleParam"}}),e=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return a list of context responses when one erc20OfInterest is provided for a single parameter",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),e=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual(expect.arrayContaining([{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"}]))}),it("should return a context response with only set external plugin when one erc20OfInterest is provided for a single parameter but no payload is feched",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),e=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a)),vi.spyOn(s,"getTokenInfosPayload").mockResolvedValue((0,l.Left)(Error("error")));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.ERROR,error:new Error("error")},{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return a list of context responses when two erc20OfInterest are provided for two parameters",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["fromToken","toToken"],method:"multipleParams"}}),e=p(n.default,"multipleParams",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual(expect.arrayContaining([{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"}]))}),it("should return a list of context responses when one erc20OfInterest is an array",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["fromToken.0","fromToken.1","fromToken.2","fromToken.-1"],method:"arrayParam"}}),e=p(n.default,"arrayParam",[["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7","0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return an error when a token datasource returns an error",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),e=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a)),vi.spyOn(s,"getTokenInfosPayload").mockResolvedValue((0,l.Left)(new Error("error")));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.ERROR,error:new Error("error")},{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return an error when the abi is not conform",async()=>{const a=d({abi:[{fakeabi:"notworking"}],selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),e=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.ERROR,error:new Error("[ContextModule] ExternalPluginContextLoader: Unable to parse abi")},{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should throw an error when the erc20OfInterest doest not exist in the transaction",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["notFound"],method:"singleParam"}}),e=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.ERROR,error:new Error("[ContextModule] ExternalPluginContextLoader: Unable to get address")}])}),it("should throw an error when an out-of-bounds element is present in erc20OfInterest",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["fromToken.3"],method:"arrayParam"}}),e=p(n.default,"arrayParam",[["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7","0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.ERROR,error:new RangeError("out of result range")}])}),it("should return a list of context responses when one erc20OfInterest is a complex struct",async()=>{const a=d({abi:n.default,selectorDetails:{erc20OfInterest:["complexStruct.address1","complexStruct.param1.param2.0.param3.addresses.0","complexStruct.param1.param2.0.param3.addresses.1","complexStruct.param1.param2.0.param3.addresses.-1","complexStruct.param1.param2.1.param3.addresses.0","complexStruct.param1.param2.-1.param3.addresses.0"],method:"complexStructParam"}}),e=p(n.default,"complexStructParam",[{address1:"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",param1:{param2:[{param3:{addresses:["0xdAC17F958D2ee523a2206206994597C13D831ec7","0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"]}},{param3:{addresses:["0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]}}]}}]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Right)(a));const c=await r.load(e);expect(c).toEqual([{type:t.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:t.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:t.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return an error when datasource return a Left",async()=>{const a=p(n.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,l.Left)(new Error("error")));const e=await r.load(a);expect(e).toEqual([{type:t.ClearSignContextType.ERROR,error:new Error("error")}])}),it("should return an error when transaction data is not a valid hex string",async()=>{const a={to:"0x0",data:"notAHexString"},e=await r.load(a);expect(e).toEqual([{type:t.ClearSignContextType.ERROR,error:new Error("Invalid selector")}])})})});
2
2
  //# sourceMappingURL=ExternalPluginContextLoader.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/external-plugin/domain/ExternalPluginContextLoader.test.ts"],
4
- "sourcesContent": ["import { Interface } from \"ethers\";\nimport { Left, Right } from \"purify-ts\";\n\nimport ABI from \"@/external-plugin/__tests__/abi.json\";\nimport { type ExternalPluginDataSource } from \"@/external-plugin/data/ExternalPluginDataSource\";\nimport { ExternalPluginContextLoader } from \"@/external-plugin/domain/ExternalPluginContextLoader\";\nimport { type DappInfos } from \"@/external-plugin/model/DappInfos\";\nimport { type SelectorDetails } from \"@/external-plugin/model/SelectorDetails\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport { type TransactionContext } from \"@/shared/model/TransactionContext\";\nimport { type TokenDataSource } from \"@/token/data/TokenDataSource\";\n\nconst dappInfosBuilder = ({\n abi,\n selectorDetails,\n}: {\n abi?: object[];\n selectorDetails?: Partial<SelectorDetails>;\n}) => {\n return {\n abi: abi,\n selectorDetails: {\n erc20OfInterest: [],\n method: \"\",\n plugin: \"\",\n serializedData: \"123456\",\n signature: \"7890\",\n ...selectorDetails,\n },\n } as DappInfos;\n};\n\nconst transactionBuilder = (\n abi: object,\n functionName: string,\n params: unknown[],\n): TransactionContext => {\n const contract = new Interface(JSON.stringify(abi));\n const data = contract.encodeFunctionData(functionName, params);\n return {\n to: \"0x0\",\n data,\n selector: data.slice(0, 10),\n } as TransactionContext;\n};\n\ndescribe(\"ExternalPluginContextLoader\", () => {\n const mockTokenDataSource: TokenDataSource = {\n getTokenInfosPayload: vi.fn(),\n };\n const mockExternalPluginDataSource: ExternalPluginDataSource = {\n getDappInfos: vi.fn(),\n };\n const loader = new ExternalPluginContextLoader(\n mockExternalPluginDataSource,\n mockTokenDataSource,\n );\n\n beforeEach(() => {\n vi.clearAllMocks();\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockImplementation(\n ({ address }) => Promise.resolve(Right(`payload-${address}`)),\n );\n });\n\n describe(\"load function\", async () => {\n it(\"should return an empty array if no destination address is provided\", async () => {\n // GIVEN\n const transaction = {} as TransactionContext;\n\n // WHEN\n const promise = () => loader.load(transaction);\n\n // THEN\n await expect(promise()).resolves.toEqual([]);\n });\n\n it(\"should return an empty array if no data provided\", async () => {\n // GIVEN\n const transaction = {\n to: \"0x0\",\n data: \"0x\",\n selector: \"0x0\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if no dapp info is povided\", async () => {\n // GIVEN\n const transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(undefined),\n );\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return e plugin if no erc20OfInterest is provided\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [],\n method: \"singleParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return a list of context responses when one erc20OfInterest is provided for a single parameter\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken\"],\n method: \"singleParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual(\n expect.arrayContaining([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n },\n ]),\n );\n });\n\n it(\"should return a context response with only set external plugin when one erc20OfInterest is provided for a single parameter but no payload is feched\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken\"],\n method: \"singleParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(Error(\"error\")),\n );\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return a list of context responses when two erc20OfInterest are provided for two parameters\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken\", \"toToken\"],\n method: \"multipleParams\",\n },\n });\n const transaction = transactionBuilder(ABI, \"multipleParams\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual(\n expect.arrayContaining([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n },\n ]),\n );\n });\n\n it(\"should return a list of context responses when one erc20OfInterest is an array\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\n \"fromToken.0\",\n \"fromToken.1\",\n \"fromToken.2\",\n \"fromToken.-1\",\n ],\n method: \"arrayParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"arrayParam\", [\n [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n \"0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n ],\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n },\n // fromToken.2\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n // fromToken.-1\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return an error when a token datasource returns an error\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken\"],\n method: \"singleParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(new Error(\"error\")),\n );\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return an error when the abi is not conform\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: [{ fakeabi: \"notworking\" }],\n selectorDetails: {\n erc20OfInterest: [\"fromToken\"],\n method: \"singleParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\n \"[ContextModule] ExternalPluginContextLoader: Unable to parse abi\",\n ),\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should throw an error when the erc20OfInterest doest not exist in the transaction\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"notFound\"],\n method: \"singleParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\n \"[ContextModule] ExternalPluginContextLoader: Unable to get address\",\n ),\n },\n ]);\n });\n\n it(\"should throw an error when an out-of-bounds element is present in erc20OfInterest\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken.3\"],\n method: \"arrayParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"arrayParam\", [\n [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n \"0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n ],\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new RangeError(\"out of result range\"),\n },\n ]);\n });\n\n it(\"should return a list of context responses when one erc20OfInterest is a complex struct\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\n \"complexStruct.address1\",\n \"complexStruct.param1.param2.0.param3.addresses.0\",\n \"complexStruct.param1.param2.0.param3.addresses.1\",\n \"complexStruct.param1.param2.0.param3.addresses.-1\",\n \"complexStruct.param1.param2.1.param3.addresses.0\",\n \"complexStruct.param1.param2.-1.param3.addresses.0\",\n ],\n method: \"complexStructParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"complexStructParam\", [\n {\n address1: \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n param1: {\n param2: [\n {\n param3: {\n addresses: [\n \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n \"0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE\",\n ],\n },\n },\n {\n param3: {\n addresses: [\"0xB8c77482e45F1F44dE1745F52C74426C631bDD52\"],\n },\n },\n ],\n },\n },\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return an error when datasource return a Left\", async () => {\n // GIVEN\n const transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Left(new Error(\"error\")),\n );\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n ]);\n });\n\n it(\"should return an error when transaction data is not a valid hex string\", async () => {\n // GIVEN\n const transaction = {\n to: \"0x0\",\n data: \"notAHexString\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Invalid selector\"),\n },\n ]);\n });\n });\n});\n"],
5
- "mappings": "wdAAA,IAAAA,EAA0B,kBAC1BC,EAA4B,qBAE5BC,EAAgB,mDAEhBC,EAA4C,gEAG5CC,EAAqC,2CAIrC,MAAMC,EAAmB,CAAC,CACxB,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AAW,CAAC,4CAA4C,CAC1D,CACF,CACF,CACF,CACF,CACF,CAAC,EACD,GAAG,MAAMN,EAA8B,cAAc,EAAE,qBACrD,SAAMO,CAAS,CACjB,EAGA,MAAMF,EAAS,MAAMJ,EAAO,KAAKE,CAAW,EAG5C,OAAOE,CAAM,EAAE,QAAQ,CACrB,CACE,KAAM,uBAAqB,MAC3B,QAAS,oDACX,EACA,CACE,KAAM,uBAAqB,MAC3B,QAAS,oDACX,EACA,CACE,KAAM,uBAAqB,MAC3B,QAAS,oDACX,EACA,CACE,KAAM,uBAAqB,MAC3B,QAAS,oDACX,EACA,CACE,KAAM,uBAAqB,MAC3B,QAAS,oDACX,EACA,CACE,KAAM,uBAAqB,MAC3B,QAAS,oDACX,EACA,CACE,KAAM,uBAAqB,gBAC3B,QAAS,YACX,CACF,CAAC,CACH,CAAC,EAED,GAAG,uDAAwD,SAAY,CAErE,MAAMF,EAAcR,EAAmB,EAAAW,QAAK,cAAe,CACzD,4CACF,CAAC,EACD,GAAG,MAAMN,EAA8B,cAAc,EAAE,qBACrD,QAAK,IAAI,MAAM,OAAO,CAAC,CACzB,EAGA,MAAMK,EAAS,MAAMJ,EAAO,KAAKE,CAAW,EAG5C,OAAOE,CAAM,EAAE,QAAQ,CACrB,CACE,KAAM,uBAAqB,MAC3B,MAAO,IAAI,MAAM,OAAO,CAC1B,CACF,CAAC,CACH,CAAC,EAED,GAAG,yEAA0E,SAAY,CAEvF,MAAMF,EAAc,CAClB,GAAI,MACJ,KAAM,eACR,EAGME,EAAS,MAAMJ,EAAO,KAAKE,CAAW,EAG5C,OAAOE,CAAM,EAAE,QAAQ,CACrB,CACE,KAAM,uBAAqB,MAC3B,MAAO,IAAI,MAAM,kBAAkB,CACrC,CACF,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
4
+ "sourcesContent": ["import { Interface } from \"ethers\";\nimport { Left, Right } from \"purify-ts\";\n\nimport ABI from \"@/external-plugin/__tests__/abi.json\";\nimport { type ExternalPluginDataSource } from \"@/external-plugin/data/ExternalPluginDataSource\";\nimport { ExternalPluginContextLoader } from \"@/external-plugin/domain/ExternalPluginContextLoader\";\nimport { type DappInfos } from \"@/external-plugin/model/DappInfos\";\nimport { type SelectorDetails } from \"@/external-plugin/model/SelectorDetails\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport { type TransactionContext } from \"@/shared/model/TransactionContext\";\nimport { type TokenDataSource } from \"@/token/data/TokenDataSource\";\n\nconst dappInfosBuilder = ({\n abi,\n selectorDetails,\n}: {\n abi?: object[];\n selectorDetails?: Partial<SelectorDetails>;\n}) => {\n return {\n abi: abi,\n selectorDetails: {\n erc20OfInterest: [],\n method: \"\",\n plugin: \"\",\n serializedData: \"123456\",\n signature: \"7890\",\n ...selectorDetails,\n },\n } as DappInfos;\n};\n\nconst transactionBuilder = (\n abi: object,\n functionName: string,\n params: unknown[],\n): TransactionContext => {\n const contract = new Interface(JSON.stringify(abi));\n const data = contract.encodeFunctionData(functionName, params);\n return {\n to: \"0x0\",\n data,\n selector: data.slice(0, 10),\n } as TransactionContext;\n};\n\ndescribe(\"ExternalPluginContextLoader\", () => {\n const mockTokenDataSource: TokenDataSource = {\n getTokenInfosPayload: vi.fn(),\n };\n const mockExternalPluginDataSource: ExternalPluginDataSource = {\n getDappInfos: vi.fn(),\n };\n const loader = new ExternalPluginContextLoader(\n mockExternalPluginDataSource,\n mockTokenDataSource,\n );\n\n beforeEach(() => {\n vi.clearAllMocks();\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockImplementation(\n ({ address }) => Promise.resolve(Right(`payload-${address}`)),\n );\n });\n\n describe(\"load function\", () => {\n it(\"should return an empty array if no destination address is provided\", async () => {\n // GIVEN\n const transaction = {} as TransactionContext;\n\n // WHEN\n const promise = () => loader.load(transaction);\n\n // THEN\n await expect(promise()).resolves.toEqual([]);\n });\n\n it(\"should return an empty array if no data provided\", async () => {\n // GIVEN\n const transaction = {\n to: \"0x0\",\n data: \"0x\",\n selector: \"0x0\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if no dapp info is povided\", async () => {\n // GIVEN\n const transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(undefined),\n );\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return e plugin if no erc20OfInterest is provided\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [],\n method: \"singleParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return a list of context responses when one erc20OfInterest is provided for a single parameter\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken\"],\n method: \"singleParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual(\n expect.arrayContaining([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n },\n ]),\n );\n });\n\n it(\"should return a context response with only set external plugin when one erc20OfInterest is provided for a single parameter but no payload is feched\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken\"],\n method: \"singleParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(Error(\"error\")),\n );\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return a list of context responses when two erc20OfInterest are provided for two parameters\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken\", \"toToken\"],\n method: \"multipleParams\",\n },\n });\n const transaction = transactionBuilder(ABI, \"multipleParams\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual(\n expect.arrayContaining([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n },\n ]),\n );\n });\n\n it(\"should return a list of context responses when one erc20OfInterest is an array\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\n \"fromToken.0\",\n \"fromToken.1\",\n \"fromToken.2\",\n \"fromToken.-1\",\n ],\n method: \"arrayParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"arrayParam\", [\n [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n \"0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n ],\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n },\n // fromToken.2\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n // fromToken.-1\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return an error when a token datasource returns an error\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken\"],\n method: \"singleParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(new Error(\"error\")),\n );\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return an error when the abi is not conform\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: [{ fakeabi: \"notworking\" }],\n selectorDetails: {\n erc20OfInterest: [\"fromToken\"],\n method: \"singleParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\n \"[ContextModule] ExternalPluginContextLoader: Unable to parse abi\",\n ),\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should throw an error when the erc20OfInterest doest not exist in the transaction\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"notFound\"],\n method: \"singleParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\n \"[ContextModule] ExternalPluginContextLoader: Unable to get address\",\n ),\n },\n ]);\n });\n\n it(\"should throw an error when an out-of-bounds element is present in erc20OfInterest\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken.3\"],\n method: \"arrayParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"arrayParam\", [\n [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n \"0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n ],\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new RangeError(\"out of result range\"),\n },\n ]);\n });\n\n it(\"should return a list of context responses when one erc20OfInterest is a complex struct\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\n \"complexStruct.address1\",\n \"complexStruct.param1.param2.0.param3.addresses.0\",\n \"complexStruct.param1.param2.0.param3.addresses.1\",\n \"complexStruct.param1.param2.0.param3.addresses.-1\",\n \"complexStruct.param1.param2.1.param3.addresses.0\",\n \"complexStruct.param1.param2.-1.param3.addresses.0\",\n ],\n method: \"complexStructParam\",\n },\n });\n const transaction = transactionBuilder(ABI, \"complexStructParam\", [\n {\n address1: \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n param1: {\n param2: [\n {\n param3: {\n addresses: [\n \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n \"0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE\",\n ],\n },\n },\n {\n param3: {\n addresses: [\"0xB8c77482e45F1F44dE1745F52C74426C631bDD52\"],\n },\n },\n ],\n },\n },\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return an error when datasource return a Left\", async () => {\n // GIVEN\n const transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Left(new Error(\"error\")),\n );\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n ]);\n });\n\n it(\"should return an error when transaction data is not a valid hex string\", async () => {\n // GIVEN\n const transaction = {\n to: \"0x0\",\n data: \"notAHexString\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Invalid selector\"),\n },\n ]);\n });\n });\n});\n"],
5
+ "mappings": "wdAAA,IAAAA,EAA0B,kBAC1BC,EAA4B,qBAE5BC,EAAgB,mDAEhBC,EAA4C,gEAG5CC,EAAqC,2CAIrC,MAAMC,EAAmB,CAAC,CACxB,IAAAC,EACA,gBAAAC,CACF,KAIS,CACL,I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CACF,CACF,CACF,CAAC,EACD,GAAG,MAAMN,EAA8B,cAAc,EAAE,qBACrD,SAAMO,CAAS,CACjB,EAGA,MAAMF,EAAS,MAAMJ,EAAO,KAAKE,CAAW,EAG5C,OAAOE,CAAM,EAAE,QAAQ,CACrB,CACE,KAAM,uBAAqB,MAC3B,QAAS,oDACX,EACA,CACE,KAAM,uBAAqB,MAC3B,QAAS,oDACX,EACA,CACE,KAAM,uBAAqB,MAC3B,QAAS,oDACX,EACA,CACE,KAAM,uBAAqB,MAC3B,QAAS,oDACX,EACA,CACE,KAAM,uBAAqB,MAC3B,QAAS,oDACX,EACA,CACE,KAAM,uBAAqB,MAC3B,QAAS,oDACX,EACA,CACE,KAAM,uBAAqB,gBAC3B,QAAS,YACX,CACF,CAAC,CACH,CAAC,EAED,GAAG,uDAAwD,SAAY,CAErE,MAAMF,EAAcR,EAAmB,EAAAW,QAAK,cAAe,CACzD,4CACF,CAAC,EACD,GAAG,MAAMN,EAA8B,cAAc,EAAE,qBACrD,QAAK,IAAI,MAAM,OAAO,CAAC,CACzB,EAGA,MAAMK,EAAS,MAAMJ,EAAO,KAAKE,CAAW,EAG5C,OAAOE,CAAM,EAAE,QAAQ,CACrB,CACE,KAAM,uBAAqB,MAC3B,MAAO,IAAI,MAAM,OAAO,CAC1B,CACF,CAAC,CACH,CAAC,EAED,GAAG,yEAA0E,SAAY,CAEvF,MAAMF,EAAc,CAClB,GAAI,MACJ,KAAM,eACR,EAGME,EAAS,MAAMJ,EAAO,KAAKE,CAAW,EAG5C,OAAOE,CAAM,EAAE,QAAQ,CACrB,CACE,KAAM,uBAAqB,MAC3B,MAAO,IAAI,MAAM,kBAAkB,CACrC,CACF,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
6
  "names": ["import_ethers", "import_purify_ts", "import_abi", "import_ExternalPluginContextLoader", "import_ClearSignContext", "dappInfosBuilder", "abi", "selectorDetails", "transactionBuilder", "functionName", "params", "data", "mockTokenDataSource", "mockExternalPluginDataSource", "loader", "address", "transaction", "promise", "result", "ABI", "dappInfos"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var a=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var t=(f,e,p,x)=>{if(e&&typeof e=="object"||typeof e=="function")for(let m of c(e))!d.call(f,m)&&m!==p&&a(f,m,{get:()=>e[m],enumerable:!(x=b(e,m))||x.enumerable});return f},r=(f,e,p)=>(t(f,e,"default"),p&&t(p,e,"default"));var g=f=>t(a({},"__esModule",{value:!0}),f);var o={};module.exports=g(o);r(o,require("./config/model/ContextModuleConfig"),module.exports);r(o,require("./ContextModule"),module.exports);r(o,require("./ContextModuleBuilder"),module.exports);r(o,require("./DefaultContextModule"),module.exports);r(o,require("./external-plugin/domain/ExternalPluginContextLoader"),module.exports);r(o,require("./nft/domain/NftContextLoader"),module.exports);r(o,require("./pki/domain/PkiCertificateLoader"),module.exports);r(o,require("./pki/model/KeyId"),module.exports);r(o,require("./pki/model/KeyUsage"),module.exports);r(o,require("./pki/model/PkiCertificate"),module.exports);r(o,require("./pki/model/PkiCertificateInfo"),module.exports);r(o,require("./shared/domain/ContextLoader"),module.exports);r(o,require("./shared/model/ClearSignContext"),module.exports);r(o,require("./shared/model/GenericPath"),module.exports);r(o,require("./shared/model/TransactionContext"),module.exports);r(o,require("./shared/model/TransactionSubset"),module.exports);r(o,require("./shared/model/TypedDataClearSignContext"),module.exports);r(o,require("./shared/model/TypedDataContext"),module.exports);r(o,require("./token/domain/TokenContextLoader"),module.exports);r(o,require("./trusted-name/domain/TrustedNameContextLoader"),module.exports);r(o,require("./web3-check/domain/Web3CheckContextLoader"),module.exports);r(o,require("./web3-check/domain/web3CheckTypes"),module.exports);0&&(module.exports={...require("./config/model/ContextModuleConfig"),...require("./ContextModule"),...require("./ContextModuleBuilder"),...require("./DefaultContextModule"),...require("./external-plugin/domain/ExternalPluginContextLoader"),...require("./nft/domain/NftContextLoader"),...require("./pki/domain/PkiCertificateLoader"),...require("./pki/model/KeyId"),...require("./pki/model/KeyUsage"),...require("./pki/model/PkiCertificate"),...require("./pki/model/PkiCertificateInfo"),...require("./shared/domain/ContextLoader"),...require("./shared/model/ClearSignContext"),...require("./shared/model/GenericPath"),...require("./shared/model/TransactionContext"),...require("./shared/model/TransactionSubset"),...require("./shared/model/TypedDataClearSignContext"),...require("./shared/model/TypedDataContext"),...require("./token/domain/TokenContextLoader"),...require("./trusted-name/domain/TrustedNameContextLoader"),...require("./web3-check/domain/Web3CheckContextLoader"),...require("./web3-check/domain/web3CheckTypes")});
1
+ "use strict";var a=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var t=(f,e,p,x)=>{if(e&&typeof e=="object"||typeof e=="function")for(let m of c(e))!d.call(f,m)&&m!==p&&a(f,m,{get:()=>e[m],enumerable:!(x=b(e,m))||x.enumerable});return f},r=(f,e,p)=>(t(f,e,"default"),p&&t(p,e,"default"));var g=f=>t(a({},"__esModule",{value:!0}),f);var o={};module.exports=g(o);r(o,require("./config/model/ContextModuleConfig"),module.exports);r(o,require("./ContextModule"),module.exports);r(o,require("./ContextModuleBuilder"),module.exports);r(o,require("./DefaultContextModule"),module.exports);r(o,require("./dynamic-network/domain/DynamicNetworkContextLoader"),module.exports);r(o,require("./dynamic-network/model/DynamicNetworkConfiguration"),module.exports);r(o,require("./external-plugin/domain/ExternalPluginContextLoader"),module.exports);r(o,require("./nft/domain/NftContextLoader"),module.exports);r(o,require("./pki/domain/PkiCertificateLoader"),module.exports);r(o,require("./pki/model/KeyId"),module.exports);r(o,require("./pki/model/KeyUsage"),module.exports);r(o,require("./pki/model/PkiCertificate"),module.exports);r(o,require("./pki/model/PkiCertificateInfo"),module.exports);r(o,require("./shared/domain/ContextLoader"),module.exports);r(o,require("./shared/model/ClearSignContext"),module.exports);r(o,require("./shared/model/GenericPath"),module.exports);r(o,require("./shared/model/TransactionContext"),module.exports);r(o,require("./shared/model/TransactionSubset"),module.exports);r(o,require("./shared/model/TypedDataClearSignContext"),module.exports);r(o,require("./shared/model/TypedDataContext"),module.exports);r(o,require("./token/domain/TokenContextLoader"),module.exports);r(o,require("./trusted-name/domain/TrustedNameContextLoader"),module.exports);r(o,require("./web3-check/domain/Web3CheckContextLoader"),module.exports);r(o,require("./web3-check/domain/web3CheckTypes"),module.exports);0&&(module.exports={...require("./config/model/ContextModuleConfig"),...require("./ContextModule"),...require("./ContextModuleBuilder"),...require("./DefaultContextModule"),...require("./dynamic-network/domain/DynamicNetworkContextLoader"),...require("./dynamic-network/model/DynamicNetworkConfiguration"),...require("./external-plugin/domain/ExternalPluginContextLoader"),...require("./nft/domain/NftContextLoader"),...require("./pki/domain/PkiCertificateLoader"),...require("./pki/model/KeyId"),...require("./pki/model/KeyUsage"),...require("./pki/model/PkiCertificate"),...require("./pki/model/PkiCertificateInfo"),...require("./shared/domain/ContextLoader"),...require("./shared/model/ClearSignContext"),...require("./shared/model/GenericPath"),...require("./shared/model/TransactionContext"),...require("./shared/model/TransactionSubset"),...require("./shared/model/TypedDataClearSignContext"),...require("./shared/model/TypedDataContext"),...require("./token/domain/TokenContextLoader"),...require("./trusted-name/domain/TrustedNameContextLoader"),...require("./web3-check/domain/Web3CheckContextLoader"),...require("./web3-check/domain/web3CheckTypes")});
2
2
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/index.ts"],
4
- "sourcesContent": ["export * from \"./config/model/ContextModuleConfig\";\nexport * from \"./ContextModule\";\nexport * from \"./ContextModuleBuilder\";\nexport * from \"./DefaultContextModule\";\nexport * from \"./external-plugin/domain/ExternalPluginContextLoader\";\nexport * from \"./nft/domain/NftContextLoader\";\nexport * from \"./pki/domain/PkiCertificateLoader\";\nexport * from \"./pki/model/KeyId\";\nexport * from \"./pki/model/KeyUsage\";\nexport * from \"./pki/model/PkiCertificate\";\nexport * from \"./pki/model/PkiCertificateInfo\";\nexport * from \"./shared/domain/ContextLoader\";\nexport * from \"./shared/model/ClearSignContext\";\nexport * from \"./shared/model/GenericPath\";\nexport * from \"./shared/model/TransactionContext\";\nexport * from \"./shared/model/TransactionSubset\";\nexport * from \"./shared/model/TypedDataClearSignContext\";\nexport * from \"./shared/model/TypedDataContext\";\nexport * from \"./token/domain/TokenContextLoader\";\nexport * from \"./trusted-name/domain/TrustedNameContextLoader\";\nexport * from \"./web3-check/domain/Web3CheckContextLoader\";\nexport * from \"./web3-check/domain/web3CheckTypes\";\n"],
5
- "mappings": "iaAAA,IAAAA,EAAA,kBAAAC,EAAAD,GAAAE,EAAAF,EAAc,8CAAd,gBACAE,EAAAF,EAAc,2BADd,gBAEAE,EAAAF,EAAc,kCAFd,gBAGAE,EAAAF,EAAc,kCAHd,gBAIAE,EAAAF,EAAc,gEAJd,gBAKAE,EAAAF,EAAc,yCALd,gBAMAE,EAAAF,EAAc,6CANd,gBAOAE,EAAAF,EAAc,6BAPd,gBAQAE,EAAAF,EAAc,gCARd,gBASAE,EAAAF,EAAc,sCATd,gBAUAE,EAAAF,EAAc,0CAVd,gBAWAE,EAAAF,EAAc,yCAXd,gBAYAE,EAAAF,EAAc,2CAZd,gBAaAE,EAAAF,EAAc,sCAbd,gBAcAE,EAAAF,EAAc,6CAdd,gBAeAE,EAAAF,EAAc,4CAfd,gBAgBAE,EAAAF,EAAc,oDAhBd,gBAiBAE,EAAAF,EAAc,2CAjBd,gBAkBAE,EAAAF,EAAc,6CAlBd,gBAmBAE,EAAAF,EAAc,0DAnBd,gBAoBAE,EAAAF,EAAc,sDApBd,gBAqBAE,EAAAF,EAAc,8CArBd",
4
+ "sourcesContent": ["export * from \"./config/model/ContextModuleConfig\";\nexport * from \"./ContextModule\";\nexport * from \"./ContextModuleBuilder\";\nexport * from \"./DefaultContextModule\";\nexport * from \"./dynamic-network/domain/DynamicNetworkContextLoader\";\nexport * from \"./dynamic-network/model/DynamicNetworkConfiguration\";\nexport * from \"./external-plugin/domain/ExternalPluginContextLoader\";\nexport * from \"./nft/domain/NftContextLoader\";\nexport * from \"./pki/domain/PkiCertificateLoader\";\nexport * from \"./pki/model/KeyId\";\nexport * from \"./pki/model/KeyUsage\";\nexport * from \"./pki/model/PkiCertificate\";\nexport * from \"./pki/model/PkiCertificateInfo\";\nexport * from \"./shared/domain/ContextLoader\";\nexport * from \"./shared/model/ClearSignContext\";\nexport * from \"./shared/model/GenericPath\";\nexport * from \"./shared/model/TransactionContext\";\nexport * from \"./shared/model/TransactionSubset\";\nexport * from \"./shared/model/TypedDataClearSignContext\";\nexport * from \"./shared/model/TypedDataContext\";\nexport * from \"./token/domain/TokenContextLoader\";\nexport * from \"./trusted-name/domain/TrustedNameContextLoader\";\nexport * from \"./web3-check/domain/Web3CheckContextLoader\";\nexport * from \"./web3-check/domain/web3CheckTypes\";\n"],
5
+ "mappings": "iaAAA,IAAAA,EAAA,kBAAAC,EAAAD,GAAAE,EAAAF,EAAc,8CAAd,gBACAE,EAAAF,EAAc,2BADd,gBAEAE,EAAAF,EAAc,kCAFd,gBAGAE,EAAAF,EAAc,kCAHd,gBAIAE,EAAAF,EAAc,gEAJd,gBAKAE,EAAAF,EAAc,+DALd,gBAMAE,EAAAF,EAAc,gEANd,gBAOAE,EAAAF,EAAc,yCAPd,gBAQAE,EAAAF,EAAc,6CARd,gBASAE,EAAAF,EAAc,6BATd,gBAUAE,EAAAF,EAAc,gCAVd,gBAWAE,EAAAF,EAAc,sCAXd,gBAYAE,EAAAF,EAAc,0CAZd,gBAaAE,EAAAF,EAAc,yCAbd,gBAcAE,EAAAF,EAAc,2CAdd,gBAeAE,EAAAF,EAAc,sCAfd,gBAgBAE,EAAAF,EAAc,6CAhBd,gBAiBAE,EAAAF,EAAc,4CAjBd,gBAkBAE,EAAAF,EAAc,oDAlBd,gBAmBAE,EAAAF,EAAc,2CAnBd,gBAoBAE,EAAAF,EAAc,6CApBd,gBAqBAE,EAAAF,EAAc,0DArBd,gBAsBAE,EAAAF,EAAc,sDAtBd,gBAuBAE,EAAAF,EAAc,8CAvBd",
6
6
  "names": ["src_exports", "__toCommonJS", "__reExport"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var x=Object.create;var s=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var G=Object.getPrototypeOf,N=Object.prototype.hasOwnProperty;var S=(e,t)=>{for(var o in t)s(e,o,{get:t[o],enumerable:!0})},g=(e,t,o,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of C(t))!N.call(e,r)&&r!==o&&s(e,r,{get:()=>t[r],enumerable:!(a=p(t,r))||a.enumerable});return e};var E=(e,t,o)=>(o=e!=null?x(G(e)):{},g(t||!e||!e.__esModule?s(o,"default",{value:e,enumerable:!0}):o,e)),$=e=>g(s({},"__esModule",{value:!0}),e),y=(e,t,o,a)=>{for(var r=a>1?void 0:a?p(t,o):t,c=e.length-1,d;c>=0;c--)(d=e[c])&&(r=(a?d(t,o,r):d(r))||r);return a&&r&&s(t,o,r),r},h=(e,t)=>(o,a)=>t(o,a,e);var _={};S(_,{HttpNftDataSource:()=>l});module.exports=$(_);var f=E(require("axios")),m=require("inversify"),n=require("purify-ts"),P=require("../../config/di/configTypes"),i=require("../../shared/constant/HttpHeaders"),u=E(require("../../../package.json"));let l=class{constructor(t){this.config=t}async getSetPluginPayload({chainId:t,address:o,selector:a}){try{const r=await f.default.request({method:"GET",url:`${this.config.metadataService.url}/ethereum/${t}/contracts/${o}/plugin-selector/${a}`,headers:{[i.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${u.default.version}`,[i.LEDGER_ORIGIN_TOKEN_HEADER]:this.config.originToken}});return r.data.payload?(0,n.Right)(r.data.payload):(0,n.Left)(new Error("[ContextModule] HttpNftDataSource: unexpected empty response"))}catch{return(0,n.Left)(new Error("[ContextModule] HttpNftDataSource: Failed to fetch set plugin payload"))}}async getNftInfosPayload({chainId:t,address:o}){try{const a=await f.default.request({method:"GET",url:`${this.config.metadataService.url}/ethereum/${t}/contracts/${o}`,headers:{[i.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${u.default.version}`,[i.LEDGER_ORIGIN_TOKEN_HEADER]:this.config.originToken}});return a.data.payload?(0,n.Right)(a.data.payload):(0,n.Left)(new Error("[ContextModule] HttpNftDataSource: no nft metadata"))}catch{return(0,n.Left)(new Error("[ContextModule] HttpNftDataSource: Failed to fetch nft informations"))}}};l=y([(0,m.injectable)(),h(0,(0,m.inject)(P.configTypes.Config))],l);0&&(module.exports={HttpNftDataSource});
1
+ "use strict";var x=Object.create;var s=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var G=Object.getPrototypeOf,N=Object.prototype.hasOwnProperty;var D=(e,t)=>{for(var o in t)s(e,o,{get:t[o],enumerable:!0})},g=(e,t,o,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of C(t))!N.call(e,r)&&r!==o&&s(e,r,{get:()=>t[r],enumerable:!(a=p(t,r))||a.enumerable});return e};var E=(e,t,o)=>(o=e!=null?x(G(e)):{},g(t||!e||!e.__esModule?s(o,"default",{value:e,enumerable:!0}):o,e)),S=e=>g(s({},"__esModule",{value:!0}),e),y=(e,t,o,a)=>{for(var r=a>1?void 0:a?p(t,o):t,c=e.length-1,d;c>=0;c--)(d=e[c])&&(r=(a?d(t,o,r):d(r))||r);return a&&r&&s(t,o,r),r},h=(e,t)=>(o,a)=>t(o,a,e);var $={};D($,{HttpNftDataSource:()=>m});module.exports=S($);var f=E(require("axios")),l=require("inversify"),n=require("purify-ts"),P=require("../../config/di/configTypes"),i=require("../../shared/constant/HttpHeaders"),u=E(require("../../../package.json"));let m=class{constructor(t){this.config=t}async getSetPluginPayload({chainId:t,address:o,selector:a}){try{const r=await f.default.request({method:"GET",url:`${this.config.metadataServiceDomain.url}/v1/ethereum/${t}/contracts/${o}/plugin-selector/${a}`,headers:{[i.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${u.default.version}`,[i.LEDGER_ORIGIN_TOKEN_HEADER]:this.config.originToken}});return r.data.payload?(0,n.Right)(r.data.payload):(0,n.Left)(new Error("[ContextModule] HttpNftDataSource: unexpected empty response"))}catch{return(0,n.Left)(new Error("[ContextModule] HttpNftDataSource: Failed to fetch set plugin payload"))}}async getNftInfosPayload({chainId:t,address:o}){try{const a=await f.default.request({method:"GET",url:`${this.config.metadataServiceDomain.url}/v1/ethereum/${t}/contracts/${o}`,headers:{[i.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${u.default.version}`,[i.LEDGER_ORIGIN_TOKEN_HEADER]:this.config.originToken}});return a.data.payload?(0,n.Right)(a.data.payload):(0,n.Left)(new Error("[ContextModule] HttpNftDataSource: no nft metadata"))}catch{return(0,n.Left)(new Error("[ContextModule] HttpNftDataSource: Failed to fetch nft informations"))}}};m=y([(0,l.injectable)(),h(0,(0,l.inject)(P.configTypes.Config))],m);0&&(module.exports={HttpNftDataSource});
2
2
  //# sourceMappingURL=HttpNftDataSource.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/nft/data/HttpNftDataSource.ts"],
4
- "sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n GetNftInformationsParams,\n GetSetPluginPayloadParams,\n NftDataSource,\n} from \"@/nft/data/NftDataSource\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport PACKAGE from \"@root/package.json\";\n\n@injectable()\nexport class HttpNftDataSource implements NftDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n ) {}\n\n public async getSetPluginPayload({\n chainId,\n address,\n selector,\n }: GetSetPluginPayloadParams): Promise<Either<Error, string>> {\n try {\n const response = await axios.request<{ payload: string }>({\n method: \"GET\",\n url: `${this.config.metadataService.url}/ethereum/${chainId}/contracts/${address}/plugin-selector/${selector}`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n\n return response.data.payload\n ? Right(response.data.payload)\n : Left(\n new Error(\n \"[ContextModule] HttpNftDataSource: unexpected empty response\",\n ),\n );\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] HttpNftDataSource: Failed to fetch set plugin payload\",\n ),\n );\n }\n }\n\n public async getNftInfosPayload({\n chainId,\n address,\n }: GetNftInformationsParams): Promise<Either<Error, string>> {\n try {\n const response = await axios.request<{ payload: string }>({\n method: \"GET\",\n url: `${this.config.metadataService.url}/ethereum/${chainId}/contracts/${address}`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n\n return response.data.payload\n ? Right(response.data.payload)\n : Left(new Error(\"[ContextModule] HttpNftDataSource: no nft metadata\"));\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] HttpNftDataSource: Failed to fetch nft informations\",\n ),\n );\n }\n }\n}\n"],
5
- "mappings": "qtBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkB,oBAClBC,EAAmC,qBACnCC,EAAoC,qBAEpCC,EAA4B,mCAO5BC,EAGO,yCACPC,EAAoB,iCAGb,IAAMC,EAAN,KAAiD,CACtD,YAC+CC,EAC7C,CAD6C,YAAAA,CAC5C,CAEH,MAAa,oBAAoB,CAC/B,QAAAC,EACA,QAAAC,EACA,SAAAC,CACF,EAA8D,CAC5D,GAAI,CACF,MAAMC,EAAW,MAAM,EAAAC,QAAM,QAA6B,CACxD,OAAQ,MACR,IAAK,GAAG,KAAK,OAAO,gBAAgB,GAAG,aAAaJ,CAAO,cAAcC,CAAO,oBAAoBC,CAAQ,GAC5G,QAAS,CACP,CAAC,8BAA4B,EAAG,kBAAkB,EAAAG,QAAQ,OAAO,GACjE,CAAC,4BAA0B,EAAG,KAAK,OAAO,WAC5C,CACF,CAAC,EAED,OAAOF,EAAS,KAAK,WACjB,SAAMA,EAAS,KAAK,OAAO,KAC3B,QACE,IAAI,MACF,8DACF,CACF,CACN,MAAiB,CACf,SAAO,QACL,IAAI,MACF,uEACF,CACF,CACF,CACF,CAEA,MAAa,mBAAmB,CAC9B,QAAAH,EACA,QAAAC,CACF,EAA6D,CAC3D,GAAI,CACF,MAAME,EAAW,MAAM,EAAAC,QAAM,QAA6B,CACxD,OAAQ,MACR,IAAK,GAAG,KAAK,OAAO,gBAAgB,GAAG,aAAaJ,CAAO,cAAcC,CAAO,GAChF,QAAS,CACP,CAAC,8BAA4B,EAAG,kBAAkB,EAAAI,QAAQ,OAAO,GACjE,CAAC,4BAA0B,EAAG,KAAK,OAAO,WAC5C,CACF,CAAC,EAED,OAAOF,EAAS,KAAK,WACjB,SAAMA,EAAS,KAAK,OAAO,KAC3B,QAAK,IAAI,MAAM,oDAAoD,CAAC,CAC1E,MAAiB,CACf,SAAO,QACL,IAAI,MACF,qEACF,CACF,CACF,CACF,CACF,EA7DaL,EAANQ,EAAA,IADN,cAAW,EAGPC,EAAA,eAAO,cAAY,MAAM,IAFjBT",
4
+ "sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n GetNftInformationsParams,\n GetSetPluginPayloadParams,\n NftDataSource,\n} from \"@/nft/data/NftDataSource\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport PACKAGE from \"@root/package.json\";\n\n@injectable()\nexport class HttpNftDataSource implements NftDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n ) {}\n\n public async getSetPluginPayload({\n chainId,\n address,\n selector,\n }: GetSetPluginPayloadParams): Promise<Either<Error, string>> {\n try {\n const response = await axios.request<{ payload: string }>({\n method: \"GET\",\n url: `${this.config.metadataServiceDomain.url}/v1/ethereum/${chainId}/contracts/${address}/plugin-selector/${selector}`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n\n return response.data.payload\n ? Right(response.data.payload)\n : Left(\n new Error(\n \"[ContextModule] HttpNftDataSource: unexpected empty response\",\n ),\n );\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] HttpNftDataSource: Failed to fetch set plugin payload\",\n ),\n );\n }\n }\n\n public async getNftInfosPayload({\n chainId,\n address,\n }: GetNftInformationsParams): Promise<Either<Error, string>> {\n try {\n const response = await axios.request<{ payload: string }>({\n method: \"GET\",\n url: `${this.config.metadataServiceDomain.url}/v1/ethereum/${chainId}/contracts/${address}`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n\n return response.data.payload\n ? Right(response.data.payload)\n : Left(new Error(\"[ContextModule] HttpNftDataSource: no nft metadata\"));\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] HttpNftDataSource: Failed to fetch nft informations\",\n ),\n );\n }\n }\n}\n"],
5
+ "mappings": "qtBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkB,oBAClBC,EAAmC,qBACnCC,EAAoC,qBAEpCC,EAA4B,mCAO5BC,EAGO,yCACPC,EAAoB,iCAGb,IAAMC,EAAN,KAAiD,CACtD,YAC+CC,EAC7C,CAD6C,YAAAA,CAC5C,CAEH,MAAa,oBAAoB,CAC/B,QAAAC,EACA,QAAAC,EACA,SAAAC,CACF,EAA8D,CAC5D,GAAI,CACF,MAAMC,EAAW,MAAM,EAAAC,QAAM,QAA6B,CACxD,OAAQ,MACR,IAAK,GAAG,KAAK,OAAO,sBAAsB,GAAG,gBAAgBJ,CAAO,cAAcC,CAAO,oBAAoBC,CAAQ,GACrH,QAAS,CACP,CAAC,8BAA4B,EAAG,kBAAkB,EAAAG,QAAQ,OAAO,GACjE,CAAC,4BAA0B,EAAG,KAAK,OAAO,WAC5C,CACF,CAAC,EAED,OAAOF,EAAS,KAAK,WACjB,SAAMA,EAAS,KAAK,OAAO,KAC3B,QACE,IAAI,MACF,8DACF,CACF,CACN,MAAiB,CACf,SAAO,QACL,IAAI,MACF,uEACF,CACF,CACF,CACF,CAEA,MAAa,mBAAmB,CAC9B,QAAAH,EACA,QAAAC,CACF,EAA6D,CAC3D,GAAI,CACF,MAAME,EAAW,MAAM,EAAAC,QAAM,QAA6B,CACxD,OAAQ,MACR,IAAK,GAAG,KAAK,OAAO,sBAAsB,GAAG,gBAAgBJ,CAAO,cAAcC,CAAO,GACzF,QAAS,CACP,CAAC,8BAA4B,EAAG,kBAAkB,EAAAI,QAAQ,OAAO,GACjE,CAAC,4BAA0B,EAAG,KAAK,OAAO,WAC5C,CACF,CAAC,EAED,OAAOF,EAAS,KAAK,WACjB,SAAMA,EAAS,KAAK,OAAO,KAC3B,QAAK,IAAI,MAAM,oDAAoD,CAAC,CAC1E,MAAiB,CACf,SAAO,QACL,IAAI,MACF,qEACF,CACF,CACF,CACF,CACF,EA7DaL,EAANQ,EAAA,IADN,cAAW,EAGPC,EAAA,eAAO,cAAY,MAAM,IAFjBT",
6
6
  "names": ["HttpNftDataSource_exports", "__export", "HttpNftDataSource", "__toCommonJS", "import_axios", "import_inversify", "import_purify_ts", "import_configTypes", "import_HttpHeaders", "import_package", "HttpNftDataSource", "config", "chainId", "address", "selector", "response", "axios", "PACKAGE", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var p=Object.create;var l=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var y=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var m=(t,e,o,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of h(e))!f.call(t,n)&&n!==o&&l(t,n,{get:()=>e[n],enumerable:!(i=x(e,n))||i.enumerable});return t};var c=(t,e,o)=>(o=t!=null?p(y(t)):{},m(e||!t||!t.__esModule?l(o,"default",{value:t,enumerable:!0}):o,t));var a=c(require("axios")),r=require("../../shared/constant/HttpHeaders"),d=c(require("../../../package.json")),u=require("./HttpNftDataSource");vi.mock("axios");const s={web3checks:{url:"web3checksUrl"},metadataService:{url:"https://nft.api.live.ledger.com/v1"},originToken:"originToken"};describe("HttpNftDataSource",()=>{let t;beforeAll(()=>{t=new u.HttpNftDataSource(s),vi.clearAllMocks()}),it("should call axios with the ledger client version and origin Token header",async()=>{const e=`context-module/${d.default.version}`,o=vi.fn(()=>Promise.resolve({data:[]}));vi.spyOn(a.default,"request").mockImplementation(o),await t.getNftInfosPayload({address:"0x00",chainId:1}),await t.getSetPluginPayload({address:"0x00",chainId:1,selector:"0x00"}),expect(o).toHaveBeenNthCalledWith(1,expect.objectContaining({headers:{[r.LEDGER_CLIENT_VERSION_HEADER]:e,[r.LEDGER_ORIGIN_TOKEN_HEADER]:s.originToken}})),expect(o).toHaveBeenNthCalledWith(2,expect.objectContaining({headers:{[r.LEDGER_CLIENT_VERSION_HEADER]:e,[r.LEDGER_ORIGIN_TOKEN_HEADER]:s.originToken}}))}),describe("getNftInfosPayload",()=>{it("should return an error when axios throws an error",async()=>{vi.spyOn(a.default,"request").mockRejectedValue(new Error("error"));const e=await t.getNftInfosPayload({address:"0x00",chainId:1});expect(e.extract()).toEqual(new Error("[ContextModule] HttpNftDataSource: Failed to fetch nft informations"))}),it("should return an error when the response is empty",async()=>{const e={data:{}};vi.spyOn(a.default,"request").mockResolvedValue(e);const o=await t.getNftInfosPayload({address:"0x00",chainId:1});expect(o.extract()).toEqual(new Error("[ContextModule] HttpNftDataSource: no nft metadata"))}),it("should return the payload",async()=>{const e={data:{payload:"payload"}};vi.spyOn(a.default,"request").mockResolvedValue(e);const o=await t.getNftInfosPayload({address:"0x00",chainId:1});expect(o.extract()).toEqual("payload")})}),describe("getSetPluginPayload",()=>{it("should return an error when axios throws an error",async()=>{vi.spyOn(a.default,"request").mockRejectedValue(new Error("error"));const e=await t.getSetPluginPayload({address:"0x00",chainId:1,selector:"0x00"});expect(e.extract()).toEqual(new Error("[ContextModule] HttpNftDataSource: Failed to fetch set plugin payload"))}),it("should return an error when the response is empty",async()=>{const e={data:{}};vi.spyOn(a.default,"request").mockResolvedValue(e);const o=await t.getSetPluginPayload({address:"0x00",chainId:1,selector:"0x00"});expect(o.extract()).toEqual(new Error("[ContextModule] HttpNftDataSource: unexpected empty response"))}),it("should return the payload",async()=>{const e={data:{payload:"payload"}};vi.spyOn(a.default,"request").mockResolvedValue(e);const o=await t.getSetPluginPayload({address:"0x00",chainId:1,selector:"0x00"});expect(o.extract()).toEqual("payload")})})});
1
+ "use strict";var p=Object.create;var l=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var y=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var m=(t,e,o,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of h(e))!f.call(t,n)&&n!==o&&l(t,n,{get:()=>e[n],enumerable:!(i=x(e,n))||i.enumerable});return t};var c=(t,e,o)=>(o=t!=null?p(y(t)):{},m(e||!t||!t.__esModule?l(o,"default",{value:t,enumerable:!0}):o,t));var a=c(require("axios")),r=require("../../shared/constant/HttpHeaders"),d=c(require("../../../package.json")),u=require("./HttpNftDataSource");vi.mock("axios");const s={web3checks:{url:"web3checksUrl"},metadataServiceDomain:{url:"https://nft.api.live.ledger.com"},originToken:"originToken"};describe("HttpNftDataSource",()=>{let t;beforeAll(()=>{t=new u.HttpNftDataSource(s),vi.clearAllMocks()}),it("should call axios with the ledger client version and origin Token header",async()=>{const e=`context-module/${d.default.version}`,o=vi.fn(()=>Promise.resolve({data:[]}));vi.spyOn(a.default,"request").mockImplementation(o),await t.getNftInfosPayload({address:"0x00",chainId:1}),await t.getSetPluginPayload({address:"0x00",chainId:1,selector:"0x00"}),expect(o).toHaveBeenNthCalledWith(1,expect.objectContaining({headers:{[r.LEDGER_CLIENT_VERSION_HEADER]:e,[r.LEDGER_ORIGIN_TOKEN_HEADER]:s.originToken}})),expect(o).toHaveBeenNthCalledWith(2,expect.objectContaining({headers:{[r.LEDGER_CLIENT_VERSION_HEADER]:e,[r.LEDGER_ORIGIN_TOKEN_HEADER]:s.originToken}}))}),describe("getNftInfosPayload",()=>{it("should return an error when axios throws an error",async()=>{vi.spyOn(a.default,"request").mockRejectedValue(new Error("error"));const e=await t.getNftInfosPayload({address:"0x00",chainId:1});expect(e.extract()).toEqual(new Error("[ContextModule] HttpNftDataSource: Failed to fetch nft informations"))}),it("should return an error when the response is empty",async()=>{const e={data:{}};vi.spyOn(a.default,"request").mockResolvedValue(e);const o=await t.getNftInfosPayload({address:"0x00",chainId:1});expect(o.extract()).toEqual(new Error("[ContextModule] HttpNftDataSource: no nft metadata"))}),it("should return the payload",async()=>{const e={data:{payload:"payload"}};vi.spyOn(a.default,"request").mockResolvedValue(e);const o=await t.getNftInfosPayload({address:"0x00",chainId:1});expect(o.extract()).toEqual("payload")})}),describe("getSetPluginPayload",()=>{it("should return an error when axios throws an error",async()=>{vi.spyOn(a.default,"request").mockRejectedValue(new Error("error"));const e=await t.getSetPluginPayload({address:"0x00",chainId:1,selector:"0x00"});expect(e.extract()).toEqual(new Error("[ContextModule] HttpNftDataSource: Failed to fetch set plugin payload"))}),it("should return an error when the response is empty",async()=>{const e={data:{}};vi.spyOn(a.default,"request").mockResolvedValue(e);const o=await t.getSetPluginPayload({address:"0x00",chainId:1,selector:"0x00"});expect(o.extract()).toEqual(new Error("[ContextModule] HttpNftDataSource: unexpected empty response"))}),it("should return the payload",async()=>{const e={data:{payload:"payload"}};vi.spyOn(a.default,"request").mockResolvedValue(e);const o=await t.getSetPluginPayload({address:"0x00",chainId:1,selector:"0x00"});expect(o.extract()).toEqual("payload")})})});
2
2
  //# sourceMappingURL=HttpNftDataSource.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/nft/data/HttpNftDataSource.test.ts"],
4
- "sourcesContent": ["import axios from \"axios\";\n\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport PACKAGE from \"@root/package.json\";\n\nimport { HttpNftDataSource } from \"./HttpNftDataSource\";\nimport { type NftDataSource } from \"./NftDataSource\";\n\nvi.mock(\"axios\");\n\nconst config = {\n web3checks: {\n url: \"web3checksUrl\",\n },\n metadataService: {\n url: \"https://nft.api.live.ledger.com/v1\",\n },\n originToken: \"originToken\",\n} as ContextModuleConfig;\ndescribe(\"HttpNftDataSource\", () => {\n let datasource: NftDataSource;\n\n beforeAll(() => {\n datasource = new HttpNftDataSource(config);\n vi.clearAllMocks();\n });\n\n it(\"should call axios with the ledger client version and origin Token header\", async () => {\n // GIVEN\n const version = `context-module/${PACKAGE.version}`;\n const requestSpy = vi.fn(() => Promise.resolve({ data: [] }));\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n // WHEN\n await datasource.getNftInfosPayload({ address: \"0x00\", chainId: 1 });\n await datasource.getSetPluginPayload({\n address: \"0x00\",\n chainId: 1,\n selector: \"0x00\",\n });\n\n // THEN\n expect(requestSpy).toHaveBeenNthCalledWith(\n 1,\n expect.objectContaining({\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: version,\n [LEDGER_ORIGIN_TOKEN_HEADER]: config.originToken,\n },\n }),\n );\n expect(requestSpy).toHaveBeenNthCalledWith(\n 2,\n expect.objectContaining({\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: version,\n [LEDGER_ORIGIN_TOKEN_HEADER]: config.originToken,\n },\n }),\n );\n });\n\n describe(\"getNftInfosPayload\", () => {\n it(\"should return an error when axios throws an error\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockRejectedValue(new Error(\"error\"));\n\n // WHEN\n const result = await datasource.getNftInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result.extract()).toEqual(\n new Error(\n \"[ContextModule] HttpNftDataSource: Failed to fetch nft informations\",\n ),\n );\n });\n\n it(\"should return an error when the response is empty\", async () => {\n // GIVEN\n const response = { data: {} };\n vi.spyOn(axios, \"request\").mockResolvedValue(response);\n\n // WHEN\n const result = await datasource.getNftInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result.extract()).toEqual(\n new Error(\"[ContextModule] HttpNftDataSource: no nft metadata\"),\n );\n });\n\n it(\"should return the payload\", async () => {\n // GIVEN\n const response = { data: { payload: \"payload\" } };\n vi.spyOn(axios, \"request\").mockResolvedValue(response);\n\n // WHEN\n const result = await datasource.getNftInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result.extract()).toEqual(\"payload\");\n });\n });\n\n describe(\"getSetPluginPayload\", () => {\n it(\"should return an error when axios throws an error\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockRejectedValue(new Error(\"error\"));\n\n // WHEN\n const result = await datasource.getSetPluginPayload({\n address: \"0x00\",\n chainId: 1,\n selector: \"0x00\",\n });\n\n // THEN\n expect(result.extract()).toEqual(\n new Error(\n \"[ContextModule] HttpNftDataSource: Failed to fetch set plugin payload\",\n ),\n );\n });\n\n it(\"should return an error when the response is empty\", async () => {\n // GIVEN\n const response = { data: {} };\n vi.spyOn(axios, \"request\").mockResolvedValue(response);\n\n // WHEN\n const result = await datasource.getSetPluginPayload({\n address: \"0x00\",\n chainId: 1,\n selector: \"0x00\",\n });\n\n // THEN\n expect(result.extract()).toEqual(\n new Error(\n \"[ContextModule] HttpNftDataSource: unexpected empty response\",\n ),\n );\n });\n\n it(\"should return the payload\", async () => {\n // GIVEN\n const response = { data: { payload: \"payload\" } };\n vi.spyOn(axios, \"request\").mockResolvedValue(response);\n\n // WHEN\n const result = await datasource.getSetPluginPayload({\n address: \"0x00\",\n chainId: 1,\n selector: \"0x00\",\n });\n\n // THEN\n expect(result.extract()).toEqual(\"payload\");\n });\n });\n});\n"],
5
- "mappings": "wdAAA,IAAAA,EAAkB,oBAGlBC,EAGO,yCACPC,EAAoB,iCAEpBC,EAAkC,+BAGlC,GAAG,KAAK,OAAO,EAEf,MAAMC,EAAS,CACb,WAAY,CACV,IAAK,eACP,EACA,gBAAiB,CACf,IAAK,oCACP,EACA,YAAa,aACf,EACA,SAAS,oBAAqB,IAAM,CAClC,IAAIC,EAEJ,UAAU,IAAM,CACdA,EAAa,IAAI,oBAAkBD,CAAM,EACzC,GAAG,cAAc,CACnB,CAAC,EAED,GAAG,2EAA4E,SAAY,CAEzF,MAAME,EAAU,kBAAkB,EAAAC,QAAQ,OAAO,GAC3CC,EAAa,GAAG,GAAG,IAAM,QAAQ,QAAQ,CAAE,KAAM,CAAC,CAAE,CAAC,CAAC,EAC5D,GAAG,MAAM,EAAAC,QAAO,SAAS,EAAE,mBAAmBD,CAAU,EAGxD,MAAMH,EAAW,mBAAmB,CAAE,QAAS,OAAQ,QAAS,CAAE,CAAC,EACnE,MAAMA,EAAW,oBAAoB,CACnC,QAAS,OACT,QAAS,EACT,SAAU,MACZ,CAAC,EAGD,OAAOG,CAAU,EAAE,wBACjB,EACA,OAAO,iBAAiB,CACtB,QAAS,CACP,CAAC,8BAA4B,EAAGF,EAChC,CAAC,4BAA0B,EAAGF,EAAO,WACvC,CACF,CAAC,CACH,EACA,OAAOI,CAAU,E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,CAAC,EAAE,QACvB,IAAI,MACF,uEACF,CACF,CACF,CAAC,EAED,GAAG,oDAAqD,SAAY,CAElE,MAAMC,EAAW,CAAE,KAAM,CAAC,CAAE,EAC5B,GAAG,MAAM,EAAAF,QAAO,SAAS,EAAE,kBAAkBE,CAAQ,EAGrD,MAAMD,EAAS,MAAML,EAAW,oBAAoB,CAClD,QAAS,OACT,QAAS,EACT,SAAU,MACZ,CAAC,EAGD,OAAOK,EAAO,QAAQ,CAAC,EAAE,QACvB,IAAI,MACF,8DACF,CACF,CACF,CAAC,EAED,GAAG,4BAA6B,SAAY,CAE1C,MAAMC,EAAW,CAAE,KAAM,CAAE,QAAS,SAAU,CAAE,EAChD,GAAG,MAAM,EAAAF,QAAO,SAAS,EAAE,kBAAkBE,CAAQ,EAGrD,MAAMD,EAAS,MAAML,EAAW,oBAAoB,CAClD,QAAS,OACT,QAAS,EACT,SAAU,MACZ,CAAC,EAGD,OAAOK,EAAO,QAAQ,CAAC,EAAE,QAAQ,SAAS,CAC5C,CAAC,CACH,CAAC,CACH,CAAC",
4
+ "sourcesContent": ["import axios from \"axios\";\n\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport PACKAGE from \"@root/package.json\";\n\nimport { HttpNftDataSource } from \"./HttpNftDataSource\";\nimport { type NftDataSource } from \"./NftDataSource\";\n\nvi.mock(\"axios\");\n\nconst config = {\n web3checks: {\n url: \"web3checksUrl\",\n },\n metadataServiceDomain: {\n url: \"https://nft.api.live.ledger.com\",\n },\n originToken: \"originToken\",\n} as ContextModuleConfig;\ndescribe(\"HttpNftDataSource\", () => {\n let datasource: NftDataSource;\n\n beforeAll(() => {\n datasource = new HttpNftDataSource(config);\n vi.clearAllMocks();\n });\n\n it(\"should call axios with the ledger client version and origin Token header\", async () => {\n // GIVEN\n const version = `context-module/${PACKAGE.version}`;\n const requestSpy = vi.fn(() => Promise.resolve({ data: [] }));\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n // WHEN\n await datasource.getNftInfosPayload({ address: \"0x00\", chainId: 1 });\n await datasource.getSetPluginPayload({\n address: \"0x00\",\n chainId: 1,\n selector: \"0x00\",\n });\n\n // THEN\n expect(requestSpy).toHaveBeenNthCalledWith(\n 1,\n expect.objectContaining({\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: version,\n [LEDGER_ORIGIN_TOKEN_HEADER]: config.originToken,\n },\n }),\n );\n expect(requestSpy).toHaveBeenNthCalledWith(\n 2,\n expect.objectContaining({\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: version,\n [LEDGER_ORIGIN_TOKEN_HEADER]: config.originToken,\n },\n }),\n );\n });\n\n describe(\"getNftInfosPayload\", () => {\n it(\"should return an error when axios throws an error\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockRejectedValue(new Error(\"error\"));\n\n // WHEN\n const result = await datasource.getNftInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result.extract()).toEqual(\n new Error(\n \"[ContextModule] HttpNftDataSource: Failed to fetch nft informations\",\n ),\n );\n });\n\n it(\"should return an error when the response is empty\", async () => {\n // GIVEN\n const response = { data: {} };\n vi.spyOn(axios, \"request\").mockResolvedValue(response);\n\n // WHEN\n const result = await datasource.getNftInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result.extract()).toEqual(\n new Error(\"[ContextModule] HttpNftDataSource: no nft metadata\"),\n );\n });\n\n it(\"should return the payload\", async () => {\n // GIVEN\n const response = { data: { payload: \"payload\" } };\n vi.spyOn(axios, \"request\").mockResolvedValue(response);\n\n // WHEN\n const result = await datasource.getNftInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result.extract()).toEqual(\"payload\");\n });\n });\n\n describe(\"getSetPluginPayload\", () => {\n it(\"should return an error when axios throws an error\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockRejectedValue(new Error(\"error\"));\n\n // WHEN\n const result = await datasource.getSetPluginPayload({\n address: \"0x00\",\n chainId: 1,\n selector: \"0x00\",\n });\n\n // THEN\n expect(result.extract()).toEqual(\n new Error(\n \"[ContextModule] HttpNftDataSource: Failed to fetch set plugin payload\",\n ),\n );\n });\n\n it(\"should return an error when the response is empty\", async () => {\n // GIVEN\n const response = { data: {} };\n vi.spyOn(axios, \"request\").mockResolvedValue(response);\n\n // WHEN\n const result = await datasource.getSetPluginPayload({\n address: \"0x00\",\n chainId: 1,\n selector: \"0x00\",\n });\n\n // THEN\n expect(result.extract()).toEqual(\n new Error(\n \"[ContextModule] HttpNftDataSource: unexpected empty response\",\n ),\n );\n });\n\n it(\"should return the payload\", async () => {\n // GIVEN\n const response = { data: { payload: \"payload\" } };\n vi.spyOn(axios, \"request\").mockResolvedValue(response);\n\n // WHEN\n const result = await datasource.getSetPluginPayload({\n address: \"0x00\",\n chainId: 1,\n selector: \"0x00\",\n });\n\n // THEN\n expect(result.extract()).toEqual(\"payload\");\n });\n });\n});\n"],
5
+ "mappings": "wdAAA,IAAAA,EAAkB,oBAGlBC,EAGO,yCACPC,EAAoB,iCAEpBC,EAAkC,+BAGlC,GAAG,KAAK,OAAO,EAEf,MAAMC,EAAS,CACb,WAAY,CACV,IAAK,eACP,EACA,sBAAuB,CACrB,IAAK,iCACP,EACA,YAAa,aACf,EACA,SAAS,oBAAqB,IAAM,CAClC,IAAIC,EAEJ,UAAU,IAAM,CACdA,EAAa,IAAI,oBAAkBD,CAAM,EACzC,GAAG,cAAc,CACnB,CAAC,EAED,GAAG,2EAA4E,SAAY,CAEzF,MAAME,EAAU,kBAAkB,EAAAC,QAAQ,OAAO,GAC3CC,EAAa,GAAG,GAAG,IAAM,QAAQ,QAAQ,CAAE,KAAM,CAAC,CAAE,CAAC,CAAC,EAC5D,GAAG,MAAM,EAAAC,QAAO,SAAS,EAAE,mBAAmBD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GD,OAAOK,EAAO,QAAQ,CAAC,EAAE,QAAQ,SAAS,CAC5C,CAAC,CACH,CAAC,EAED,SAAS,sBAAuB,IAAM,CACpC,GAAG,oDAAqD,SAAY,CAElE,GAAG,MAAM,EAAAD,QAAO,SAAS,EAAE,kBAAkB,IAAI,MAAM,OAAO,CAAC,EAG/D,MAAMC,EAAS,MAAML,EAAW,oBAAoB,CAClD,QAAS,OACT,QAAS,EACT,SAAU,MACZ,CAAC,EAGD,OAAOK,EAAO,QAAQ,CAAC,EAAE,QACvB,IAAI,MACF,uEACF,CACF,CACF,CAAC,EAED,GAAG,oDAAqD,SAAY,CAElE,MAAMC,EAAW,CAAE,KAAM,CAAC,CAAE,EAC5B,GAAG,MAAM,EAAAF,QAAO,SAAS,EAAE,kBAAkBE,CAAQ,EAGrD,MAAMD,EAAS,MAAML,EAAW,oBAAoB,CAClD,QAAS,OACT,QAAS,EACT,SAAU,MACZ,CAAC,EAGD,OAAOK,EAAO,QAAQ,CAAC,EAAE,QACvB,IAAI,MACF,8DACF,CACF,CACF,CAAC,EAED,GAAG,4BAA6B,SAAY,CAE1C,MAAMC,EAAW,CAAE,KAAM,CAAE,QAAS,SAAU,CAAE,EAChD,GAAG,MAAM,EAAAF,QAAO,SAAS,EAAE,kBAAkBE,CAAQ,EAGrD,MAAMD,EAAS,MAAML,EAAW,oBAAoB,CAClD,QAAS,OACT,QAAS,EACT,SAAU,MACZ,CAAC,EAGD,OAAOK,EAAO,QAAQ,CAAC,EAAE,QAAQ,SAAS,CAC5C,CAAC,CACH,CAAC,CACH,CAAC",
6
6
  "names": ["import_axios", "import_HttpHeaders", "import_package", "import_HttpNftDataSource", "config", "datasource", "version", "PACKAGE", "requestSpy", "axios", "result", "response"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var o=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var u=(e,t)=>{for(var a in t)o(e,a,{get:t[a],enumerable:!0})},d=(e,t,a,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of P(t))!S.call(e,r)&&r!==a&&o(e,r,{get:()=>t[r],enumerable:!(i=p(t,r))||i.enumerable});return e};var h=e=>d(o({},"__esModule",{value:!0}),e),s=(e,t,a,i)=>{for(var r=i>1?void 0:i?p(t,a):t,m=e.length-1,n;m>=0;m--)(n=e[m])&&(r=(i?n(t,a,r):n(r))||r);return i&&r&&o(t,a,r),r},C=(e,t)=>(a,i)=>t(a,i,e);var y={};u(y,{DefaultPkiCertificateLoader:()=>c});module.exports=h(y);var f=require("inversify"),k=require("../../pki/di/pkiTypes");let c=class{_dataSource;constructor(t){this._dataSource=t}async loadCertificate(t){return(await this._dataSource.fetchCertificate(t)).caseOf({Right:i=>i,Left:i=>{throw i instanceof Error?i:new Error(String(i))}})}};c=s([(0,f.injectable)(),C(0,(0,f.inject)(k.pkiTypes.PkiCertificateDataSource))],c);0&&(module.exports={DefaultPkiCertificateLoader});
1
+ "use strict";var o=Object.defineProperty;var n=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var P=Object.prototype.hasOwnProperty;var d=(i,t)=>{for(var r in t)o(i,r,{get:t[r],enumerable:!0})},S=(i,t,r,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of k(t))!P.call(i,e)&&e!==r&&o(i,e,{get:()=>t[e],enumerable:!(a=n(t,e))||a.enumerable});return i};var y=i=>S(o({},"__esModule",{value:!0}),i),s=(i,t,r,a)=>{for(var e=a>1?void 0:a?n(t,r):t,m=i.length-1,p;m>=0;m--)(p=i[m])&&(e=(a?p(t,r,e):p(e))||e);return a&&e&&o(t,r,e),e},u=(i,t)=>(r,a)=>t(r,a,i);var h={};d(h,{DefaultPkiCertificateLoader:()=>c});module.exports=y(h);var f=require("inversify"),C=require("../../pki/di/pkiTypes");let c=class{_dataSource;constructor(t){this._dataSource=t}async loadCertificate(t){return(await this._dataSource.fetchCertificate(t)).orDefault(void 0)}};c=s([(0,f.injectable)(),u(0,(0,f.inject)(C.pkiTypes.PkiCertificateDataSource))],c);0&&(module.exports={DefaultPkiCertificateLoader});
2
2
  //# sourceMappingURL=DefaultPkiCertificateLoader.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/pki/domain/DefaultPkiCertificateLoader.ts"],
4
- "sourcesContent": ["import { inject, injectable } from \"inversify\";\n\nimport { type PkiCertificateDataSource } from \"@/pki/data/PkiCertificateDataSource\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { type PkiCertificateInfo } from \"@/pki/model/PkiCertificateInfo\";\n\nimport { PkiCertificateLoader } from \"./PkiCertificateLoader\";\n\n@injectable()\nexport class DefaultPkiCertificateLoader implements PkiCertificateLoader {\n private _dataSource: PkiCertificateDataSource;\n\n constructor(\n @inject(pkiTypes.PkiCertificateDataSource)\n dataSource: PkiCertificateDataSource,\n ) {\n this._dataSource = dataSource;\n }\n\n async loadCertificate(\n certificateInfos: PkiCertificateInfo,\n ): Promise<PkiCertificate | undefined> {\n const certificate =\n await this._dataSource.fetchCertificate(certificateInfos);\n\n return certificate.caseOf({\n Right: (cert) => cert,\n Left: (err) => {\n throw err instanceof Error ? err : new Error(String(err));\n },\n });\n }\n}\n"],
5
- "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAmC,qBAGnCC,EAAyB,6BAOlB,IAAMC,EAAN,KAAkE,CAC/D,YAER,YAEEC,EACA,CACA,KAAK,YAAcA,CACrB,CAEA,MAAM,gBACJC,EACqC,CAIrC,OAFE,MAAM,KAAK,YAAY,iBAAiBA,CAAgB,GAEvC,OAAO,CACxB,MAAQC,GAASA,EACjB,KAAOC,GAAQ,CACb,MAAMA,aAAe,MAAQA,EAAM,IAAI,MAAM,OAAOA,CAAG,CAAC,CAC1D,CACF,CAAC,CACH,CACF,EAvBaJ,EAANK,EAAA,IADN,cAAW,EAKPC,EAAA,eAAO,WAAS,wBAAwB,IAJhCN",
6
- "names": ["DefaultPkiCertificateLoader_exports", "__export", "DefaultPkiCertificateLoader", "__toCommonJS", "import_inversify", "import_pkiTypes", "DefaultPkiCertificateLoader", "dataSource", "certificateInfos", "cert", "err", "__decorateClass", "__decorateParam"]
4
+ "sourcesContent": ["import { inject, injectable } from \"inversify\";\n\nimport { type PkiCertificateDataSource } from \"@/pki/data/PkiCertificateDataSource\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { type PkiCertificateInfo } from \"@/pki/model/PkiCertificateInfo\";\n\nimport { PkiCertificateLoader } from \"./PkiCertificateLoader\";\n\n@injectable()\nexport class DefaultPkiCertificateLoader implements PkiCertificateLoader {\n private _dataSource: PkiCertificateDataSource;\n\n constructor(\n @inject(pkiTypes.PkiCertificateDataSource)\n dataSource: PkiCertificateDataSource,\n ) {\n this._dataSource = dataSource;\n }\n\n async loadCertificate(\n certificateInfos: PkiCertificateInfo,\n ): Promise<PkiCertificate | undefined> {\n const certificate =\n await this._dataSource.fetchCertificate(certificateInfos);\n\n // TODO add logs error with certificate.left()\n return certificate.orDefault(undefined);\n }\n}\n"],
5
+ "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAmC,qBAGnCC,EAAyB,6BAOlB,IAAMC,EAAN,KAAkE,CAC/D,YAER,YAEEC,EACA,CACA,KAAK,YAAcA,CACrB,CAEA,MAAM,gBACJC,EACqC,CAKrC,OAHE,MAAM,KAAK,YAAY,iBAAiBA,CAAgB,GAGvC,UAAU,MAAS,CACxC,CACF,EAnBaF,EAANG,EAAA,IADN,cAAW,EAKPC,EAAA,eAAO,WAAS,wBAAwB,IAJhCJ",
6
+ "names": ["DefaultPkiCertificateLoader_exports", "__export", "DefaultPkiCertificateLoader", "__toCommonJS", "import_inversify", "import_pkiTypes", "DefaultPkiCertificateLoader", "dataSource", "certificateInfos", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var r=require("purify-ts"),i=require("../../pki/domain/DefaultPkiCertificateLoader"),o=require("../../pki/model/KeyId"),c=require("../../pki/model/KeyUsage");describe("DefaultPkiCertificateLoader",()=>{describe("loadCertificate",()=>{it("should call loadCertificate",async()=>{const e={targetDevice:"targetDevice",keyUsage:c.KeyUsage.Calldata,keyId:o.KeyId.CalNetwork},t={keyUsageNumber:11,payload:new Uint8Array([1,2,3,4,21,4,5,6,7,8])},a={fetchCertificate:vi.fn().mockResolvedValue((0,r.Right)(t))},l=await new i.DefaultPkiCertificateLoader(a).loadCertificate(e);expect(l).toEqual(t),expect(a.fetchCertificate).toHaveBeenCalledWith(e)}),it("throws when the data source returns a Left(error)",async()=>{const e={targetDevice:"targetDevice",keyUsage:c.KeyUsage.Calldata,keyId:o.KeyId.CalNetwork},t=new Error("failed"),a={fetchCertificate:vi.fn().mockResolvedValue((0,r.Left)(t))},f=new i.DefaultPkiCertificateLoader(a);await expect(f.loadCertificate(e)).rejects.toThrow(t),expect(a.fetchCertificate).toHaveBeenCalledWith(e)})})});
1
+ "use strict";var i=require("purify-ts"),o=require("../../pki/domain/DefaultPkiCertificateLoader"),c=require("../../pki/model/KeyId"),f=require("../../pki/model/KeyUsage");describe("DefaultPkiCertificateLoader",()=>{describe("loadCertificate",()=>{it("should call loadCertificate",async()=>{const e={targetDevice:"targetDevice",keyUsage:f.KeyUsage.Calldata,keyId:c.KeyId.CalNetwork},a={keyUsageNumber:11,payload:new Uint8Array([1,2,3,4,21,4,5,6,7,8])},t={fetchCertificate:vi.fn().mockResolvedValue((0,i.Right)(a))},r=await new o.DefaultPkiCertificateLoader(t).loadCertificate(e);expect(r).toEqual(a),expect(t.fetchCertificate).toHaveBeenCalledWith(e)}),it("Returns undefined when the data source returns a Left(error)",async()=>{const e={targetDevice:"targetDevice",keyUsage:f.KeyUsage.Calldata,keyId:c.KeyId.CalNetwork},a=new Error("failed"),t={fetchCertificate:vi.fn().mockResolvedValue((0,i.Left)(a))},r=await new o.DefaultPkiCertificateLoader(t).loadCertificate(e);expect(r).toBeUndefined(),expect(t.fetchCertificate).toHaveBeenCalledWith(e)})})});
2
2
  //# sourceMappingURL=DefaultPkiCertificateLoader.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/pki/domain/DefaultPkiCertificateLoader.test.ts"],
4
- "sourcesContent": ["import { Left, Right } from \"purify-ts\";\n\nimport { DefaultPkiCertificateLoader } from \"@/pki/domain/DefaultPkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { type PkiCertificateInfo } from \"@/pki/model/PkiCertificateInfo\";\n\ndescribe(\"DefaultPkiCertificateLoader\", () => {\n describe(\"loadCertificate\", () => {\n it(\"should call loadCertificate\", async () => {\n // GIVEN\n const certificateInfos: PkiCertificateInfo = {\n targetDevice: \"targetDevice\",\n keyUsage: KeyUsage.Calldata,\n keyId: KeyId.CalNetwork,\n };\n const certificate = {\n keyUsageNumber: 11,\n payload: new Uint8Array([\n 0x01, 0x02, 0x03, 0x04, 0x15, 0x04, 0x05, 0x06, 0x07, 0x08,\n ]),\n };\n const dataSource = {\n fetchCertificate: vi.fn().mockResolvedValue(Right(certificate)),\n };\n\n // WHEN\n const loader = new DefaultPkiCertificateLoader(dataSource);\n const result = await loader.loadCertificate(certificateInfos);\n\n // THEN\n expect(result).toEqual(certificate);\n expect(dataSource.fetchCertificate).toHaveBeenCalledWith(\n certificateInfos,\n );\n });\n\n it(\"throws when the data source returns a Left(error)\", async () => {\n // given\n const certificateInfos: PkiCertificateInfo = {\n targetDevice: \"targetDevice\",\n keyUsage: KeyUsage.Calldata,\n keyId: KeyId.CalNetwork,\n };\n const fetchError = new Error(\"failed\");\n const dataSource = {\n fetchCertificate: vi.fn().mockResolvedValue(Left(fetchError)),\n };\n const loader = new DefaultPkiCertificateLoader(dataSource);\n\n // when / then\n await expect(loader.loadCertificate(certificateInfos)).rejects.toThrow(\n fetchError,\n );\n expect(dataSource.fetchCertificate).toHaveBeenCalledWith(\n certificateInfos,\n );\n });\n });\n});\n"],
5
- "mappings": "aAAA,IAAAA,EAA4B,qBAE5BC,EAA4C,oDAC5CC,EAAsB,6BACtBC,EAAyB,gCAGzB,SAAS,8BAA+B,IAAM,CAC5C,SAAS,kBAAmB,IAAM,CAChC,GAAG,8BAA+B,SAAY,CAE5C,MAAMC,EAAuC,CAC3C,aAAc,eACd,SAAU,WAAS,SACnB,MAAO,QAAM,UACf,EACMC,EAAc,CAClB,eAAgB,GAChB,QAAS,IAAI,WAAW,CACtB,EAAM,EAAM,EAAM,EAAM,GAAM,EAAM,EAAM,EAAM,EAAM,CACxD,CAAC,CACH,EACMC,EAAa,CACjB,iBAAkB,GAAG,GAAG,EAAE,qBAAkB,SAAMD,CAAW,CAAC,CAChE,EAIME,EAAS,MADA,IAAI,8BAA4BD,CAAU,EAC7B,gBAAgBF,CAAgB,EAG5D,OAAOG,CAAM,EAAE,QAAQF,CAAW,EAClC,OAAOC,EAAW,gBAAgB,EAAE,qBAClCF,CACF,CACF,CAAC,EAED,GAAG,oDAAqD,SAAY,CAElE,MAAMA,EAAuC,CAC3C,aAAc,eACd,SAAU,WAAS,SACnB,MAAO,QAAM,UACf,EACMI,EAAa,IAAI,MAAM,QAAQ,EAC/BF,EAAa,CACjB,iBAAkB,GAAG,GAAG,EAAE,qBAAkB,QAAKE,CAAU,CAAC,CAC9D,EACMC,EAAS,IAAI,8BAA4BH,CAAU,EAGzD,MAAM,OAAOG,EAAO,gBAAgBL,CAAgB,CAAC,EAAE,QAAQ,QAC7DI,CACF,EACA,OAAOF,EAAW,gBAAgB,EAAE,qBAClCF,CACF,CACF,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["import_purify_ts", "import_DefaultPkiCertificateLoader", "import_KeyId", "import_KeyUsage", "certificateInfos", "certificate", "dataSource", "result", "fetchError", "loader"]
4
+ "sourcesContent": ["import { Left, Right } from \"purify-ts\";\n\nimport { DefaultPkiCertificateLoader } from \"@/pki/domain/DefaultPkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { type PkiCertificateInfo } from \"@/pki/model/PkiCertificateInfo\";\n\ndescribe(\"DefaultPkiCertificateLoader\", () => {\n describe(\"loadCertificate\", () => {\n it(\"should call loadCertificate\", async () => {\n // GIVEN\n const certificateInfos: PkiCertificateInfo = {\n targetDevice: \"targetDevice\",\n keyUsage: KeyUsage.Calldata,\n keyId: KeyId.CalNetwork,\n };\n const certificate = {\n keyUsageNumber: 11,\n payload: new Uint8Array([\n 0x01, 0x02, 0x03, 0x04, 0x15, 0x04, 0x05, 0x06, 0x07, 0x08,\n ]),\n };\n const dataSource = {\n fetchCertificate: vi.fn().mockResolvedValue(Right(certificate)),\n };\n\n // WHEN\n const loader = new DefaultPkiCertificateLoader(dataSource);\n const result = await loader.loadCertificate(certificateInfos);\n\n // THEN\n expect(result).toEqual(certificate);\n expect(dataSource.fetchCertificate).toHaveBeenCalledWith(\n certificateInfos,\n );\n });\n\n it(\"Returns undefined when the data source returns a Left(error)\", async () => {\n // given\n const certificateInfos: PkiCertificateInfo = {\n targetDevice: \"targetDevice\",\n keyUsage: KeyUsage.Calldata,\n keyId: KeyId.CalNetwork,\n };\n const fetchError = new Error(\"failed\");\n const dataSource = {\n fetchCertificate: vi.fn().mockResolvedValue(Left(fetchError)),\n };\n const loader = new DefaultPkiCertificateLoader(dataSource);\n\n // when / then\n const result = await loader.loadCertificate(certificateInfos);\n expect(result).toBeUndefined();\n expect(dataSource.fetchCertificate).toHaveBeenCalledWith(\n certificateInfos,\n );\n });\n });\n});\n"],
5
+ "mappings": "aAAA,IAAAA,EAA4B,qBAE5BC,EAA4C,oDAC5CC,EAAsB,6BACtBC,EAAyB,gCAGzB,SAAS,8BAA+B,IAAM,CAC5C,SAAS,kBAAmB,IAAM,CAChC,GAAG,8BAA+B,SAAY,CAE5C,MAAMC,EAAuC,CAC3C,aAAc,eACd,SAAU,WAAS,SACnB,MAAO,QAAM,UACf,EACMC,EAAc,CAClB,eAAgB,GAChB,QAAS,IAAI,WAAW,CACtB,EAAM,EAAM,EAAM,EAAM,GAAM,EAAM,EAAM,EAAM,EAAM,CACxD,CAAC,CACH,EACMC,EAAa,CACjB,iBAAkB,GAAG,GAAG,EAAE,qBAAkB,SAAMD,CAAW,CAAC,CAChE,EAIME,EAAS,MADA,IAAI,8BAA4BD,CAAU,EAC7B,gBAAgBF,CAAgB,EAG5D,OAAOG,CAAM,EAAE,QAAQF,CAAW,EAClC,OAAOC,EAAW,gBAAgB,EAAE,qBAClCF,CACF,CACF,CAAC,EAED,GAAG,+DAAgE,SAAY,CAE7E,MAAMA,EAAuC,CAC3C,aAAc,eACd,SAAU,WAAS,SACnB,MAAO,QAAM,UACf,EACMI,EAAa,IAAI,MAAM,QAAQ,EAC/BF,EAAa,CACjB,iBAAkB,GAAG,GAAG,EAAE,qBAAkB,QAAKE,CAAU,CAAC,CAC9D,EAIMD,EAAS,MAHA,IAAI,8BAA4BD,CAAU,EAG7B,gBAAgBF,CAAgB,EAC5D,OAAOG,CAAM,EAAE,cAAc,EAC7B,OAAOD,EAAW,gBAAgB,EAAE,qBAClCF,CACF,CACF,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["import_purify_ts", "import_DefaultPkiCertificateLoader", "import_KeyId", "import_KeyUsage", "certificateInfos", "certificate", "dataSource", "result", "fetchError"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var a=Object.defineProperty;var o=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var c=(r,t)=>{for(var i in t)a(r,i,{get:t[i],enumerable:!0})},l=(r,t,i,p)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of y(t))!T.call(r,n)&&n!==i&&a(r,n,{get:()=>t[n],enumerable:!(p=o(t,n))||p.enumerable});return r};var x=r=>l(a({},"__esModule",{value:!0}),r);var E={};c(E,{ClearSignContextType:()=>C});module.exports=x(E);var C=(e=>(e.TOKEN="token",e.NFT="nft",e.TRUSTED_NAME="trustedName",e.PLUGIN="plugin",e.EXTERNAL_PLUGIN="externalPlugin",e.TRANSACTION_INFO="transactionInfo",e.ENUM="enum",e.TRANSACTION_FIELD_DESCRIPTION="transactionFieldDescription",e.WEB3_CHECK="web3Check",e.ERROR="error",e))(C||{});0&&(module.exports={ClearSignContextType});
1
+ "use strict";var a=Object.defineProperty;var o=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var E=(r,t)=>{for(var i in t)a(r,i,{get:t[i],enumerable:!0})},T=(r,t,i,p)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of c(t))!y.call(r,n)&&n!==i&&a(r,n,{get:()=>t[n],enumerable:!(p=o(t,n))||p.enumerable});return r};var l=r=>T(a({},"__esModule",{value:!0}),r);var x={};E(x,{ClearSignContextType:()=>C});module.exports=l(x);var C=(e=>(e.TOKEN="token",e.NFT="nft",e.TRUSTED_NAME="trustedName",e.PLUGIN="plugin",e.EXTERNAL_PLUGIN="externalPlugin",e.TRANSACTION_INFO="transactionInfo",e.PROXY_DELEGATE_CALL="proxyDelegateCall",e.ENUM="enum",e.TRANSACTION_FIELD_DESCRIPTION="transactionFieldDescription",e.WEB3_CHECK="web3Check",e.DYNAMIC_NETWORK="dynamicNetwork",e.DYNAMIC_NETWORK_ICON="dynamicNetworkIcon",e.ERROR="error",e))(C||{});0&&(module.exports={ClearSignContextType});
2
2
  //# sourceMappingURL=ClearSignContext.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/shared/model/ClearSignContext.ts"],
4
- "sourcesContent": ["import { type PkiCertificate } from \"@/pki/model/PkiCertificate\";\n\nimport { type GenericPath } from \"./GenericPath\";\n\nexport enum ClearSignContextType {\n TOKEN = \"token\",\n NFT = \"nft\",\n TRUSTED_NAME = \"trustedName\",\n PLUGIN = \"plugin\",\n EXTERNAL_PLUGIN = \"externalPlugin\",\n TRANSACTION_INFO = \"transactionInfo\",\n ENUM = \"enum\",\n TRANSACTION_FIELD_DESCRIPTION = \"transactionFieldDescription\",\n WEB3_CHECK = \"web3Check\",\n ERROR = \"error\",\n}\n\nexport type ClearSignContextReferenceType =\n | ClearSignContextType.TOKEN\n | ClearSignContextType.NFT\n | ClearSignContextType.ENUM\n | ClearSignContextType.TRUSTED_NAME;\n\nexport type ClearSignContextReference<\n Type extends ClearSignContextReferenceType = ClearSignContextReferenceType,\n> = Type extends ClearSignContextType.ENUM\n ? {\n type: ClearSignContextType.ENUM;\n valuePath: GenericPath;\n id: number; // enum id to reference\n }\n : Type extends ClearSignContextType.TRUSTED_NAME\n ? {\n type: ClearSignContextType.TRUSTED_NAME;\n valuePath: GenericPath;\n types: string[];\n sources: string[];\n }\n :\n | {\n type: Type;\n valuePath: GenericPath;\n value?: never;\n }\n | {\n type: Type;\n valuePath?: never;\n value: string;\n };\n\nexport type ClearSignContextSuccessType = Exclude<\n ClearSignContextType,\n ClearSignContextType.ERROR\n>;\n\n// NOTE: this is a union of all possible success types\n// There is currently two types of success:\n// - ENUM: which is a special case, we need to handle it differently\n// because we don't want to send the whole enum\n// but only the parts that are needed.\n// - id: the enum id to reference\n// - payload: the payload to send with a provideEnum command\n// - name: the name of the enum to be displayed on the device\n// - value: the value of the enum to be retrieved from the transaction\n// - All other types\n// - payload: the payload to send with a provide command\n// - reference: the reference to the value to be retrieved from the transaction\nexport type ClearSignContextSuccess<\n Type extends ClearSignContextSuccessType = ClearSignContextSuccessType,\n> = Type extends ClearSignContextType.ENUM\n ? {\n type: ClearSignContextType.ENUM;\n id: number;\n payload: string;\n value: number;\n certificate?: PkiCertificate;\n }\n : {\n type: Exclude<\n ClearSignContextType,\n ClearSignContextType.ENUM | ClearSignContextType.ERROR\n >;\n payload: string;\n reference?: ClearSignContextReference;\n certificate?: PkiCertificate;\n };\n\nexport type ClearSignContextError = {\n type: ClearSignContextType.ERROR;\n error: Error;\n};\n\nexport type ClearSignContext = ClearSignContextSuccess | ClearSignContextError;\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,IAAA,eAAAC,EAAAH,GAIO,IAAKE,OACVA,EAAA,MAAQ,QACRA,EAAA,IAAM,MACNA,EAAA,aAAe,cACfA,EAAA,OAAS,SACTA,EAAA,gBAAkB,iBAClBA,EAAA,iBAAmB,kBACnBA,EAAA,KAAO,OACPA,EAAA,8BAAgC,8BAChCA,EAAA,WAAa,YACbA,EAAA,MAAQ,QAVEA,OAAA",
4
+ "sourcesContent": ["import { type PkiCertificate } from \"@/pki/model/PkiCertificate\";\n\nimport { type GenericPath } from \"./GenericPath\";\n\nexport enum ClearSignContextType {\n TOKEN = \"token\",\n NFT = \"nft\",\n TRUSTED_NAME = \"trustedName\",\n PLUGIN = \"plugin\",\n EXTERNAL_PLUGIN = \"externalPlugin\",\n TRANSACTION_INFO = \"transactionInfo\",\n PROXY_DELEGATE_CALL = \"proxyDelegateCall\",\n ENUM = \"enum\",\n TRANSACTION_FIELD_DESCRIPTION = \"transactionFieldDescription\",\n WEB3_CHECK = \"web3Check\",\n DYNAMIC_NETWORK = \"dynamicNetwork\",\n DYNAMIC_NETWORK_ICON = \"dynamicNetworkIcon\",\n ERROR = \"error\",\n}\n\nexport type ClearSignContextReferenceType =\n | ClearSignContextType.TOKEN\n | ClearSignContextType.NFT\n | ClearSignContextType.ENUM\n | ClearSignContextType.TRUSTED_NAME;\n\nexport type ClearSignContextReference<\n Type extends ClearSignContextReferenceType = ClearSignContextReferenceType,\n> = Type extends ClearSignContextType.ENUM\n ? {\n type: ClearSignContextType.ENUM;\n valuePath: GenericPath;\n id: number; // enum id to reference\n }\n : Type extends ClearSignContextType.TRUSTED_NAME\n ? {\n type: ClearSignContextType.TRUSTED_NAME;\n valuePath: GenericPath;\n types: string[];\n sources: string[];\n }\n :\n | {\n type: Type;\n valuePath: GenericPath;\n value?: never;\n }\n | {\n type: Type;\n valuePath?: never;\n value: string;\n };\n\nexport type ClearSignContextSuccessType = Exclude<\n ClearSignContextType,\n ClearSignContextType.ERROR\n>;\n\n// NOTE: this is a union of all possible success types\n// There is currently two types of success:\n// - ENUM: which is a special case, we need to handle it differently\n// because we don't want to send the whole enum\n// but only the parts that are needed.\n// - id: the enum id to reference\n// - payload: the payload to send with a provideEnum command\n// - name: the name of the enum to be displayed on the device\n// - value: the value of the enum to be retrieved from the transaction\n// - All other types\n// - payload: the payload to send with a provide command\n// - reference: the reference to the value to be retrieved from the transaction\nexport type ClearSignContextSuccess<\n Type extends ClearSignContextSuccessType = ClearSignContextSuccessType,\n> = Type extends ClearSignContextType.ENUM\n ? {\n type: ClearSignContextType.ENUM;\n id: number;\n payload: string;\n value: number;\n certificate?: PkiCertificate;\n }\n : {\n type: Exclude<\n ClearSignContextType,\n ClearSignContextType.ENUM | ClearSignContextType.ERROR\n >;\n payload: string;\n reference?: ClearSignContextReference;\n certificate?: PkiCertificate;\n };\n\nexport type ClearSignContextError = {\n type: ClearSignContextType.ERROR;\n error: Error;\n};\n\nexport type ClearSignContext = ClearSignContextSuccess | ClearSignContextError;\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,IAAA,eAAAC,EAAAH,GAIO,IAAKE,OACVA,EAAA,MAAQ,QACRA,EAAA,IAAM,MACNA,EAAA,aAAe,cACfA,EAAA,OAAS,SACTA,EAAA,gBAAkB,iBAClBA,EAAA,iBAAmB,kBACnBA,EAAA,oBAAsB,oBACtBA,EAAA,KAAO,OACPA,EAAA,8BAAgC,8BAChCA,EAAA,WAAa,YACbA,EAAA,gBAAkB,iBAClBA,EAAA,qBAAuB,qBACvBA,EAAA,MAAQ,QAbEA,OAAA",
6
6
  "names": ["ClearSignContext_exports", "__export", "ClearSignContextType", "__toCommonJS"]
7
7
  }