@ledgerhq/context-module 2.2.0 → 2.3.1

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 (149) 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 +2 -2
  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/modules/ethereum/calldata/data/HttpCalldataDescriptorDataSource.test.js +1 -1
  7. package/lib/cjs/src/modules/ethereum/calldata/data/HttpCalldataDescriptorDataSource.test.js.map +2 -2
  8. package/lib/cjs/src/modules/ethereum/dynamic-network/data/HttpDynamicNetworkDataSource.test.js +1 -1
  9. package/lib/cjs/src/modules/ethereum/dynamic-network/data/HttpDynamicNetworkDataSource.test.js.map +2 -2
  10. package/lib/cjs/src/modules/ethereum/dynamic-network/domain/DynamicNetworkContextLoader.test.js +1 -1
  11. package/lib/cjs/src/modules/ethereum/dynamic-network/domain/DynamicNetworkContextLoader.test.js.map +2 -2
  12. package/lib/cjs/src/modules/ethereum/external-plugin/data/HttpExternalPluginDataSource.test.js +1 -1
  13. package/lib/cjs/src/modules/ethereum/external-plugin/data/HttpExternalPluginDataSource.test.js.map +2 -2
  14. package/lib/cjs/src/modules/ethereum/gated-signing/data/HttpGatedDescriptorDataSource.test.js +1 -1
  15. package/lib/cjs/src/modules/ethereum/gated-signing/data/HttpGatedDescriptorDataSource.test.js.map +2 -2
  16. package/lib/cjs/src/modules/ethereum/token/data/HttpTokenDataSource.test.js +1 -1
  17. package/lib/cjs/src/modules/ethereum/token/data/HttpTokenDataSource.test.js.map +2 -2
  18. package/lib/cjs/src/modules/ethereum/trusted-name/data/HttpTrustedNameDataSource.test.js +1 -1
  19. package/lib/cjs/src/modules/ethereum/trusted-name/data/HttpTrustedNameDataSource.test.js.map +2 -2
  20. package/lib/cjs/src/modules/ethereum/typed-data/data/HttpTypedDataDataSource.test.js +1 -1
  21. package/lib/cjs/src/modules/ethereum/typed-data/data/HttpTypedDataDataSource.test.js.map +2 -2
  22. package/lib/cjs/src/modules/solana/alt-resolution/data/HttpAltResolutionDataSource.js +1 -1
  23. package/lib/cjs/src/modules/solana/alt-resolution/data/HttpAltResolutionDataSource.js.map +1 -1
  24. package/lib/cjs/src/modules/solana/enum-variant/domain/EnumVariantContextLoader.js +1 -1
  25. package/lib/cjs/src/modules/solana/enum-variant/domain/EnumVariantContextLoader.js.map +2 -2
  26. package/lib/cjs/src/modules/solana/enum-variant/domain/EnumVariantContextLoader.test.js +1 -1
  27. package/lib/cjs/src/modules/solana/enum-variant/domain/EnumVariantContextLoader.test.js.map +2 -2
  28. package/lib/cjs/src/modules/solana/instruction-info/data/HttpInstructionInfoDataSource.js +1 -1
  29. package/lib/cjs/src/modules/solana/instruction-info/data/HttpInstructionInfoDataSource.js.map +3 -3
  30. package/lib/cjs/src/modules/solana/instruction-info/data/HttpInstructionInfoDataSource.test.js +1 -1
  31. package/lib/cjs/src/modules/solana/instruction-info/data/HttpInstructionInfoDataSource.test.js.map +3 -3
  32. package/lib/cjs/src/modules/solana/instruction-info/data/InstructionInfoDto.js +1 -1
  33. package/lib/cjs/src/modules/solana/instruction-info/data/InstructionInfoDto.js.map +3 -3
  34. package/lib/cjs/src/modules/solana/instruction-info/data/InstructionInfoMapper.js +1 -1
  35. package/lib/cjs/src/modules/solana/instruction-info/data/InstructionInfoMapper.js.map +3 -3
  36. package/lib/cjs/src/modules/solana/instruction-info/data/InstructionInfoMapper.test.js +1 -1
  37. package/lib/cjs/src/modules/solana/instruction-info/data/InstructionInfoMapper.test.js.map +2 -2
  38. package/lib/cjs/src/modules/solana/instruction-info/domain/InstructionInfoContextLoader.js +1 -1
  39. package/lib/cjs/src/modules/solana/instruction-info/domain/InstructionInfoContextLoader.js.map +2 -2
  40. package/lib/cjs/src/modules/solana/lifi/data/HttpLifiDataSource.test.js +1 -1
  41. package/lib/cjs/src/modules/solana/lifi/data/HttpLifiDataSource.test.js.map +2 -2
  42. package/lib/cjs/src/modules/solana/lifi/domain/LifiContextLoader.js +1 -1
  43. package/lib/cjs/src/modules/solana/lifi/domain/LifiContextLoader.js.map +3 -3
  44. package/lib/cjs/src/modules/solana/lifi/domain/LifiContextLoader.test.js +1 -1
  45. package/lib/cjs/src/modules/solana/lifi/domain/LifiContextLoader.test.js.map +3 -3
  46. package/lib/cjs/src/modules/solana/model/SolanaContextTypes.js.map +1 -1
  47. package/lib/cjs/src/modules/solana/model/SolanaPayloads.js.map +2 -2
  48. package/lib/cjs/src/modules/solana/owner-info/data/HttpOwnerInfoDataSource.js +1 -1
  49. package/lib/cjs/src/modules/solana/owner-info/data/HttpOwnerInfoDataSource.js.map +2 -2
  50. package/lib/cjs/src/modules/solana/owner-info/data/HttpOwnerInfoDataSource.test.js +1 -1
  51. package/lib/cjs/src/modules/solana/owner-info/data/HttpOwnerInfoDataSource.test.js.map +2 -2
  52. package/lib/cjs/src/modules/solana/token/data/HttpTokenDataSource.test.js +2 -2
  53. package/lib/cjs/src/modules/solana/token/data/HttpTokenDataSource.test.js.map +2 -2
  54. package/lib/cjs/src/modules/solana/token-account-state/data/HttpTokenAccountStateDataSource.js +1 -1
  55. package/lib/cjs/src/modules/solana/token-account-state/data/HttpTokenAccountStateDataSource.js.map +1 -1
  56. package/lib/cjs/src/modules/solana/token-info/data/HttpTokenInfoDataSource.test.js +1 -1
  57. package/lib/cjs/src/modules/solana/token-info/data/HttpTokenInfoDataSource.test.js.map +2 -2
  58. package/lib/cjs/src/modules/solana/token-info/domain/TokenInfoContextLoader.test.js +1 -1
  59. package/lib/cjs/src/modules/solana/token-info/domain/TokenInfoContextLoader.test.js.map +2 -2
  60. package/lib/cjs/src/modules/solana/trusted-name/data/HttpTrustedNameDataSource.js +1 -1
  61. package/lib/cjs/src/modules/solana/trusted-name/data/HttpTrustedNameDataSource.js.map +3 -3
  62. package/lib/cjs/src/modules/solana/trusted-name/data/HttpTrustedNameDataSource.test.js +1 -1
  63. package/lib/cjs/src/modules/solana/trusted-name/data/HttpTrustedNameDataSource.test.js.map +3 -3
  64. package/lib/cjs/src/modules/solana/trusted-name/domain/TrustedNameContextLoader.js +1 -1
  65. package/lib/cjs/src/modules/solana/trusted-name/domain/TrustedNameContextLoader.js.map +3 -3
  66. package/lib/cjs/src/modules/solana/trusted-name/domain/TrustedNameContextLoader.test.js +1 -1
  67. package/lib/cjs/src/modules/solana/trusted-name/domain/TrustedNameContextLoader.test.js.map +3 -3
  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 +2 -2
  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/modules/ethereum/calldata/data/HttpCalldataDescriptorDataSource.test.js +1 -1
  74. package/lib/esm/src/modules/ethereum/calldata/data/HttpCalldataDescriptorDataSource.test.js.map +2 -2
  75. package/lib/esm/src/modules/ethereum/dynamic-network/data/HttpDynamicNetworkDataSource.test.js +1 -1
  76. package/lib/esm/src/modules/ethereum/dynamic-network/data/HttpDynamicNetworkDataSource.test.js.map +2 -2
  77. package/lib/esm/src/modules/ethereum/dynamic-network/domain/DynamicNetworkContextLoader.test.js +1 -1
  78. package/lib/esm/src/modules/ethereum/dynamic-network/domain/DynamicNetworkContextLoader.test.js.map +2 -2
  79. package/lib/esm/src/modules/ethereum/external-plugin/data/HttpExternalPluginDataSource.test.js +1 -1
  80. package/lib/esm/src/modules/ethereum/external-plugin/data/HttpExternalPluginDataSource.test.js.map +2 -2
  81. package/lib/esm/src/modules/ethereum/gated-signing/data/HttpGatedDescriptorDataSource.test.js +1 -1
  82. package/lib/esm/src/modules/ethereum/gated-signing/data/HttpGatedDescriptorDataSource.test.js.map +2 -2
  83. package/lib/esm/src/modules/ethereum/token/data/HttpTokenDataSource.test.js +1 -1
  84. package/lib/esm/src/modules/ethereum/token/data/HttpTokenDataSource.test.js.map +2 -2
  85. package/lib/esm/src/modules/ethereum/trusted-name/data/HttpTrustedNameDataSource.test.js +1 -1
  86. package/lib/esm/src/modules/ethereum/trusted-name/data/HttpTrustedNameDataSource.test.js.map +2 -2
  87. package/lib/esm/src/modules/ethereum/typed-data/data/HttpTypedDataDataSource.test.js +1 -1
  88. package/lib/esm/src/modules/ethereum/typed-data/data/HttpTypedDataDataSource.test.js.map +2 -2
  89. package/lib/esm/src/modules/solana/alt-resolution/data/HttpAltResolutionDataSource.js +1 -1
  90. package/lib/esm/src/modules/solana/alt-resolution/data/HttpAltResolutionDataSource.js.map +1 -1
  91. package/lib/esm/src/modules/solana/enum-variant/domain/EnumVariantContextLoader.js +1 -1
  92. package/lib/esm/src/modules/solana/enum-variant/domain/EnumVariantContextLoader.js.map +2 -2
  93. package/lib/esm/src/modules/solana/enum-variant/domain/EnumVariantContextLoader.test.js +1 -1
  94. package/lib/esm/src/modules/solana/enum-variant/domain/EnumVariantContextLoader.test.js.map +2 -2
  95. package/lib/esm/src/modules/solana/instruction-info/data/HttpInstructionInfoDataSource.js +1 -1
  96. package/lib/esm/src/modules/solana/instruction-info/data/HttpInstructionInfoDataSource.js.map +3 -3
  97. package/lib/esm/src/modules/solana/instruction-info/data/HttpInstructionInfoDataSource.test.js +1 -1
  98. package/lib/esm/src/modules/solana/instruction-info/data/HttpInstructionInfoDataSource.test.js.map +3 -3
  99. package/lib/esm/src/modules/solana/instruction-info/data/InstructionInfoDto.js +1 -1
  100. package/lib/esm/src/modules/solana/instruction-info/data/InstructionInfoDto.js.map +3 -3
  101. package/lib/esm/src/modules/solana/instruction-info/data/InstructionInfoMapper.js +1 -1
  102. package/lib/esm/src/modules/solana/instruction-info/data/InstructionInfoMapper.js.map +3 -3
  103. package/lib/esm/src/modules/solana/instruction-info/data/InstructionInfoMapper.test.js +1 -1
  104. package/lib/esm/src/modules/solana/instruction-info/data/InstructionInfoMapper.test.js.map +2 -2
  105. package/lib/esm/src/modules/solana/instruction-info/domain/InstructionInfoContextLoader.js +1 -1
  106. package/lib/esm/src/modules/solana/instruction-info/domain/InstructionInfoContextLoader.js.map +2 -2
  107. package/lib/esm/src/modules/solana/lifi/data/HttpLifiDataSource.test.js +1 -1
  108. package/lib/esm/src/modules/solana/lifi/data/HttpLifiDataSource.test.js.map +2 -2
  109. package/lib/esm/src/modules/solana/lifi/domain/LifiContextLoader.js +1 -1
  110. package/lib/esm/src/modules/solana/lifi/domain/LifiContextLoader.js.map +3 -3
  111. package/lib/esm/src/modules/solana/lifi/domain/LifiContextLoader.test.js +1 -1
  112. package/lib/esm/src/modules/solana/lifi/domain/LifiContextLoader.test.js.map +3 -3
  113. package/lib/esm/src/modules/solana/model/SolanaPayloads.js.map +2 -2
  114. package/lib/esm/src/modules/solana/owner-info/data/HttpOwnerInfoDataSource.js +1 -1
  115. package/lib/esm/src/modules/solana/owner-info/data/HttpOwnerInfoDataSource.js.map +2 -2
  116. package/lib/esm/src/modules/solana/owner-info/data/HttpOwnerInfoDataSource.test.js +1 -1
  117. package/lib/esm/src/modules/solana/owner-info/data/HttpOwnerInfoDataSource.test.js.map +2 -2
  118. package/lib/esm/src/modules/solana/token/data/HttpTokenDataSource.test.js +2 -2
  119. package/lib/esm/src/modules/solana/token/data/HttpTokenDataSource.test.js.map +2 -2
  120. package/lib/esm/src/modules/solana/token-account-state/data/HttpTokenAccountStateDataSource.js +1 -1
  121. package/lib/esm/src/modules/solana/token-account-state/data/HttpTokenAccountStateDataSource.js.map +1 -1
  122. package/lib/esm/src/modules/solana/token-info/data/HttpTokenInfoDataSource.test.js +1 -1
  123. package/lib/esm/src/modules/solana/token-info/data/HttpTokenInfoDataSource.test.js.map +2 -2
  124. package/lib/esm/src/modules/solana/token-info/domain/TokenInfoContextLoader.test.js +1 -1
  125. package/lib/esm/src/modules/solana/token-info/domain/TokenInfoContextLoader.test.js.map +2 -2
  126. package/lib/esm/src/modules/solana/trusted-name/data/HttpTrustedNameDataSource.js +1 -1
  127. package/lib/esm/src/modules/solana/trusted-name/data/HttpTrustedNameDataSource.js.map +3 -3
  128. package/lib/esm/src/modules/solana/trusted-name/data/HttpTrustedNameDataSource.test.js +1 -1
  129. package/lib/esm/src/modules/solana/trusted-name/data/HttpTrustedNameDataSource.test.js.map +3 -3
  130. package/lib/esm/src/modules/solana/trusted-name/domain/TrustedNameContextLoader.js +1 -1
  131. package/lib/esm/src/modules/solana/trusted-name/domain/TrustedNameContextLoader.js.map +3 -3
  132. package/lib/esm/src/modules/solana/trusted-name/domain/TrustedNameContextLoader.test.js +1 -1
  133. package/lib/esm/src/modules/solana/trusted-name/domain/TrustedNameContextLoader.test.js.map +3 -3
  134. package/lib/types/src/ContextModuleBuilder.d.ts.map +1 -1
  135. package/lib/types/src/modules/solana/instruction-info/data/HttpInstructionInfoDataSource.d.ts.map +1 -1
  136. package/lib/types/src/modules/solana/instruction-info/data/InstructionInfoDto.d.ts +50 -56
  137. package/lib/types/src/modules/solana/instruction-info/data/InstructionInfoDto.d.ts.map +1 -1
  138. package/lib/types/src/modules/solana/instruction-info/data/InstructionInfoMapper.d.ts +4 -1
  139. package/lib/types/src/modules/solana/instruction-info/data/InstructionInfoMapper.d.ts.map +1 -1
  140. package/lib/types/src/modules/solana/lifi/domain/LifiContextLoader.d.ts.map +1 -1
  141. package/lib/types/src/modules/solana/model/SolanaContextTypes.d.ts +5 -1
  142. package/lib/types/src/modules/solana/model/SolanaContextTypes.d.ts.map +1 -1
  143. package/lib/types/src/modules/solana/model/SolanaPayloads.d.ts +6 -6
  144. package/lib/types/src/modules/solana/model/SolanaPayloads.d.ts.map +1 -1
  145. package/lib/types/src/modules/solana/owner-info/data/HttpOwnerInfoDataSource.d.ts.map +1 -1
  146. package/lib/types/src/modules/solana/trusted-name/data/HttpTrustedNameDataSource.d.ts.map +1 -1
  147. package/lib/types/src/modules/solana/trusted-name/domain/TrustedNameContextLoader.d.ts.map +1 -1
  148. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  149. package/package.json +2 -2
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/modules/solana/instruction-info/domain/InstructionInfoContextLoader.ts"],
4
- "sourcesContent": ["import {\n type DeviceModelId,\n type LoggerPublisherService,\n} from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\nimport { array, Codec, optional, string } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { pkiTypes } from \"@/modules/multichain/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/modules/multichain/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/modules/multichain/pki/model/KeyId\";\nimport { KeyUsage } from \"@/modules/multichain/pki/model/KeyUsage\";\nimport { type InstructionInfoDataSource } from \"@/modules/solana/instruction-info/data/InstructionInfoDataSource\";\nimport { instructionInfoTypes } from \"@/modules/solana/instruction-info/di/instructionInfoTypes\";\nimport { type ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n type ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { loadCertificateResult } from \"@/shared/utils/certificateResult\";\nimport { deviceModelIdCodec } from \"@/shared/utils/deviceModelIdCodec\";\n\nconst SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.SOLANA_INSTRUCTION_INFO,\n];\n\nconst NETWORK_DEFAULT = \"solana-mainnet\";\n\n/**\n * Per-instruction reference the caller provides for the TX it wants to\n * clear-sign. Discriminator is optional: when omitted, the loader emits\n * every descriptor CAL returns for that `programId`. When present, the\n * loader filters down to descriptors whose `discriminator` matches.\n */\nexport type SolanaInstructionRef = {\n programId: string;\n discriminator?: string;\n};\n\nexport type SolanaInstructionInfoContextInput = {\n deviceModelId: DeviceModelId;\n instructions: SolanaInstructionRef[];\n network?: string;\n};\n\nconst instructionRefCodec = Codec.interface({\n programId: string,\n discriminator: optional(string),\n});\n\nconst solanaInstructionInfoInputCodec = Codec.interface({\n deviceModelId: deviceModelIdCodec,\n instructions: array(instructionRefCodec),\n network: optional(string),\n});\n\n/**\n * Emits SOLANA_INSTRUCTION_INFO contexts for the requested instructions.\n * Enum-variant emission lives in the sibling {@link EnumVariantContextLoader}.\n */\n@injectable()\nexport class InstructionInfoContextLoader\n implements ContextLoader<SolanaInstructionInfoContextInput>\n{\n private readonly logger: LoggerPublisherService;\n\n constructor(\n @inject(instructionInfoTypes.InstructionInfoDataSource)\n private readonly dataSource: InstructionInfoDataSource,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly certificateLoader: PkiCertificateLoader,\n @inject(configTypes.ContextModuleLoggerFactory)\n loggerFactory: (tag: string) => LoggerPublisherService,\n ) {\n this.logger = loggerFactory(\"InstructionInfoContextLoader\");\n }\n\n public canHandle(\n input: unknown,\n expectedTypes: ClearSignContextType[],\n ): input is SolanaInstructionInfoContextInput {\n if (!SUPPORTED_TYPES.every((t) => expectedTypes.includes(t))) {\n return false;\n }\n return solanaInstructionInfoInputCodec.decode(input).caseOf({\n Left: () => false,\n Right: ({ instructions }) =>\n instructions.length > 0 &&\n instructions.every((ix) => ix.programId.length > 0),\n });\n }\n\n public async load(\n input: SolanaInstructionInfoContextInput,\n ): Promise<ClearSignContext[]> {\n const network = input.network || NETWORK_DEFAULT;\n const distinctProgramIds = Array.from(\n new Set(input.instructions.map((ix) => ix.programId)),\n );\n\n this.logger.debug(\"[load] Fetching instruction descriptors\", {\n data: {\n network,\n programCount: distinctProgramIds.length,\n instructionCount: input.instructions.length,\n },\n });\n\n // Run cert load in parallel with CAL fetches \u2014 neither depends on the\n // other. The tagged-Result wrapper lets us preserve the data fetches\n // if cert fails so we can surface a per-program ERROR rather than\n // silently dropping them.\n const certPromise = loadCertificateResult(this.certificateLoader, {\n keyId: KeyId.TokenMetadataKey,\n keyUsage: KeyUsage.CoinMeta,\n targetDevice: input.deviceModelId,\n });\n\n // One CAL call per program, fanned out in parallel.\n const dataPromise = Promise.all(\n distinctProgramIds.map(async (programId) => ({\n programId,\n either: await this.dataSource.getInstructionInfo({\n programId,\n network,\n }),\n })),\n );\n\n const [certResult, results] = await Promise.all([certPromise, dataPromise]);\n\n if (!certResult.ok || !certResult.value) {\n const error = certResult.ok\n ? new Error(\n \"[ContextModule] InstructionInfoContextLoader: certificate is missing\",\n )\n : certResult.error;\n this.logger.warn(\"[load] INSTRUCTION_INFO certificate unavailable\", {\n data: { error: error.message },\n });\n return distinctProgramIds.map(() => ({\n type: ClearSignContextType.ERROR,\n error,\n }));\n }\n const certificate = certResult.value;\n\n const contexts: ClearSignContext[] = [];\n\n for (const { programId, either } of results) {\n either.caseOf<void>({\n Left: (err) => {\n this.logger.warn(\n \"[load] Failed to fetch instruction descriptors for program\",\n { data: { programId, error: err.message } },\n );\n contexts.push({\n type: ClearSignContextType.ERROR,\n error: err,\n });\n },\n Right: (value) => {\n const wantedDiscriminators = this.collectWantedDiscriminators(\n programId,\n input.instructions,\n );\n\n for (const [discriminator, result] of Object.entries(\n value.descriptors,\n )) {\n if (\n wantedDiscriminators !== null &&\n !wantedDiscriminators.has(discriminator)\n ) {\n continue;\n }\n contexts.push(\n result.caseOf<ClearSignContext>({\n Left: (error) => {\n this.logger.warn(\"[load] INSTRUCTION_INFO descriptor error\", {\n data: { programId, discriminator, error: error.message },\n });\n return { type: ClearSignContextType.ERROR, error };\n },\n Right: (payload) => ({\n type: ClearSignContextType.SOLANA_INSTRUCTION_INFO,\n payload,\n certificate,\n }),\n }),\n );\n }\n },\n });\n }\n\n this.logger.debug(\"[load] Emitted contexts\", {\n data: { count: contexts.length },\n });\n\n return contexts;\n }\n\n /**\n * Returns the set of discriminators the caller has explicitly asked\n * about for this `programId`, or `null` when the caller wants every\n * descriptor CAL has for the program.\n */\n private collectWantedDiscriminators(\n programId: string,\n instructions: SolanaInstructionRef[],\n ): Set<string> | null {\n const set = new Set<string>();\n let hasUnconstrained = false;\n for (const ix of instructions) {\n if (ix.programId !== programId) continue;\n if (ix.discriminator === undefined) {\n hasUnconstrained = true;\n } else {\n set.add(ix.discriminator);\n }\n }\n return hasUnconstrained ? null : set;\n }\n}\n"],
5
- "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kCAAAE,IAAA,eAAAC,EAAAH,GAIA,IAAAI,EAAmC,qBACnCC,EAA+C,qBAE/CC,EAA4B,mCAC5BC,EAAyB,gDAEzBC,EAAsB,gDACtBC,EAAyB,mDAEzBC,EAAqC,qEAErCC,EAGO,2CACPC,EAAsC,4CACtCC,EAAmC,6CAEnC,MAAMC,EAA0C,CAC9C,uBAAqB,uBACvB,EAEMC,EAAkB,iBAmBlBC,EAAsB,QAAM,UAAU,CAC1C,UAAW,SACX,iBAAe,YAAS,QAAM,CAChC,CAAC,EAEKC,EAAkC,QAAM,UAAU,CACtD,cAAe,qBACf,gBAAc,SAAMD,CAAmB,EACvC,WAAS,YAAS,QAAM,CAC1B,CAAC,EAOM,IAAME,EAAN,KAEP,CAGE,YAEmBC,EAEAC,EAEjBC,EACA,CALiB,gBAAAF,EAEA,uBAAAC,EAIjB,KAAK,OAASC,EAAc,8BAA8B,CAC5D,CAXiB,OAaV,UACLC,EACAC,EAC4C,CAC5C,OAAKT,EAAgB,MAAOU,GAAMD,EAAc,SAASC,CAAC,CAAC,EAGpDP,EAAgC,OAAOK,CAAK,EAAE,OAAO,CAC1D,KAAM,IAAM,GACZ,MAAO,CAAC,CAAE,aAAAG,CAAa,IACrBA,EAAa,OAAS,GACtBA,EAAa,MAAOC,GAAOA,EAAG,UAAU,OAAS,CAAC,CACtD,CAAC,EAPQ,EAQX,CAEA,MAAa,KACXJ,EAC6B,CAC7B,MAAMK,EAAUL,EAAM,SAAWP,EAC3Ba,EAAqB,MAAM,KAC/B,IAAI,IAAIN,EAAM,aAAa,IAAKI,GAAOA,EAAG,SAAS,CAAC,CACtD,EAEA,KAAK,OAAO,MAAM,0CAA2C,CAC3D,KAAM,CACJ,QAAAC,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KAAK,2CAA4C,CAC3D,KAAM,CAAE,UAAAH,EAAW,cAAAU,EAAe,MAAOP,EAAM,OAAQ,CACzD,CAAC,EACM,CAAE,KAAM,uBAAqB,MAAO,MAAAA,CAAM,GAEnD,MAAQS,IAAa,CACnB,KAAM,uBAAqB,wBAC3B,QAAAA,EACA,YAAAR,CACF,EACF,CAAC,CACH,CAEJ,CACF,CAAC,EAGH,YAAK,OAAO,MAAM,0BAA2B,CAC3C,KAAM,CAAE,MAAOC,EAAS,MAAO,CACjC,CAAC,EAEMA,CACT,CAOQ,4BACNL,EACAN,EACoB,CACpB,MAAMmB,EAAM,IAAI,IAChB,IAAIC,EAAmB,GACvB,UAAWnB,KAAMD,EACXC,EAAG,YAAcK,IACjBL,EAAG,gBAAkB,OACvBmB,EAAmB,GAEnBD,EAAI,IAAIlB,EAAG,aAAa,GAG5B,OAAOmB,EAAmB,KAAOD,CACnC,CACF,EAnKa1B,EAAN4B,EAAA,IADN,cAAW,EAOPC,EAAA,eAAO,uBAAqB,yBAAyB,GAErDA,EAAA,eAAO,WAAS,oBAAoB,GAEpCA,EAAA,eAAO,cAAY,0BAA0B,IAVrC7B",
4
+ "sourcesContent": ["import {\n type DeviceModelId,\n type LoggerPublisherService,\n} from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\nimport { array, Codec, optional, string } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { pkiTypes } from \"@/modules/multichain/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/modules/multichain/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/modules/multichain/pki/model/KeyId\";\nimport { KeyUsage } from \"@/modules/multichain/pki/model/KeyUsage\";\nimport { type InstructionInfoDataSource } from \"@/modules/solana/instruction-info/data/InstructionInfoDataSource\";\nimport { instructionInfoTypes } from \"@/modules/solana/instruction-info/di/instructionInfoTypes\";\nimport { type ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n type ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { loadCertificateResult } from \"@/shared/utils/certificateResult\";\nimport { deviceModelIdCodec } from \"@/shared/utils/deviceModelIdCodec\";\n\nconst SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.SOLANA_INSTRUCTION_INFO,\n];\n\nconst NETWORK_DEFAULT = \"solana-mainnet\";\n\n/**\n * Per-instruction reference the caller provides for the TX it wants to\n * clear-sign. Discriminator is optional: when omitted, the loader emits\n * every descriptor CAL returns for that `programId`. When present, the\n * loader filters down to descriptors whose `discriminator` matches.\n */\nexport type SolanaInstructionRef = {\n programId: string;\n discriminator?: string;\n};\n\nexport type SolanaInstructionInfoContextInput = {\n deviceModelId: DeviceModelId;\n instructions: SolanaInstructionRef[];\n network?: string;\n};\n\nconst instructionRefCodec = Codec.interface({\n programId: string,\n discriminator: optional(string),\n});\n\nconst solanaInstructionInfoInputCodec = Codec.interface({\n deviceModelId: deviceModelIdCodec,\n instructions: array(instructionRefCodec),\n network: optional(string),\n});\n\n/**\n * Emits SOLANA_INSTRUCTION_INFO contexts for the requested instructions.\n * Enum-variant emission lives in the sibling {@link EnumVariantContextLoader}.\n */\n@injectable()\nexport class InstructionInfoContextLoader\n implements ContextLoader<SolanaInstructionInfoContextInput>\n{\n private readonly logger: LoggerPublisherService;\n\n constructor(\n @inject(instructionInfoTypes.InstructionInfoDataSource)\n private readonly dataSource: InstructionInfoDataSource,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly certificateLoader: PkiCertificateLoader,\n @inject(configTypes.ContextModuleLoggerFactory)\n loggerFactory: (tag: string) => LoggerPublisherService,\n ) {\n this.logger = loggerFactory(\"InstructionInfoContextLoader\");\n }\n\n public canHandle(\n input: unknown,\n expectedTypes: ClearSignContextType[],\n ): input is SolanaInstructionInfoContextInput {\n if (!SUPPORTED_TYPES.every((t) => expectedTypes.includes(t))) {\n return false;\n }\n return solanaInstructionInfoInputCodec.decode(input).caseOf({\n Left: () => false,\n Right: ({ instructions }) =>\n instructions.length > 0 &&\n instructions.every((ix) => ix.programId.length > 0),\n });\n }\n\n public async load(\n input: SolanaInstructionInfoContextInput,\n ): Promise<ClearSignContext[]> {\n const network = input.network || NETWORK_DEFAULT;\n const distinctProgramIds = Array.from(\n new Set(input.instructions.map((ix) => ix.programId)),\n );\n\n this.logger.debug(\"[load] Fetching instruction descriptors\", {\n data: {\n network,\n programCount: distinctProgramIds.length,\n instructionCount: input.instructions.length,\n },\n });\n\n // Run cert load in parallel with CAL fetches \u2014 neither depends on the\n // other. The tagged-Result wrapper lets us preserve the data fetches\n // if cert fails so we can surface a per-program ERROR rather than\n // silently dropping them.\n const certPromise = loadCertificateResult(this.certificateLoader, {\n keyId: KeyId.CalCalldataKey,\n keyUsage: KeyUsage.Calldata,\n targetDevice: input.deviceModelId,\n });\n\n // One CAL call per program, fanned out in parallel.\n const dataPromise = Promise.all(\n distinctProgramIds.map(async (programId) => ({\n programId,\n either: await this.dataSource.getInstructionInfo({\n programId,\n network,\n }),\n })),\n );\n\n const [certResult, results] = await Promise.all([certPromise, dataPromise]);\n\n if (!certResult.ok || !certResult.value) {\n const error = certResult.ok\n ? new Error(\n \"[ContextModule] InstructionInfoContextLoader: certificate is missing\",\n )\n : certResult.error;\n this.logger.warn(\"[load] INSTRUCTION_INFO certificate unavailable\", {\n data: { error: error.message },\n });\n return distinctProgramIds.map(() => ({\n type: ClearSignContextType.ERROR,\n error,\n }));\n }\n const certificate = certResult.value;\n\n const contexts: ClearSignContext[] = [];\n\n for (const { programId, either } of results) {\n either.caseOf<void>({\n Left: (err) => {\n this.logger.warn(\n \"[load] Failed to fetch instruction descriptors for program\",\n { data: { programId, error: err.message } },\n );\n contexts.push({\n type: ClearSignContextType.ERROR,\n error: err,\n });\n },\n Right: (value) => {\n const wantedDiscriminators = this.collectWantedDiscriminators(\n programId,\n input.instructions,\n );\n\n for (const [discriminator, result] of Object.entries(\n value.descriptors,\n )) {\n if (\n wantedDiscriminators !== null &&\n !wantedDiscriminators.has(discriminator)\n ) {\n continue;\n }\n contexts.push(\n result.caseOf<ClearSignContext>({\n Left: (error) => {\n this.logger.warn(\"[load] INSTRUCTION_INFO descriptor error\", {\n data: { programId, discriminator, error: error.message },\n });\n return { type: ClearSignContextType.ERROR, error };\n },\n Right: (payload) => ({\n type: ClearSignContextType.SOLANA_INSTRUCTION_INFO,\n payload,\n certificate,\n }),\n }),\n );\n }\n },\n });\n }\n\n this.logger.debug(\"[load] Emitted contexts\", {\n data: { count: contexts.length },\n });\n\n return contexts;\n }\n\n /**\n * Returns the set of discriminators the caller has explicitly asked\n * about for this `programId`, or `null` when the caller wants every\n * descriptor CAL has for the program.\n */\n private collectWantedDiscriminators(\n programId: string,\n instructions: SolanaInstructionRef[],\n ): Set<string> | null {\n const set = new Set<string>();\n let hasUnconstrained = false;\n for (const ix of instructions) {\n if (ix.programId !== programId) continue;\n if (ix.discriminator === undefined) {\n hasUnconstrained = true;\n } else {\n set.add(ix.discriminator);\n }\n }\n return hasUnconstrained ? null : set;\n }\n}\n"],
5
+ "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kCAAAE,IAAA,eAAAC,EAAAH,GAIA,IAAAI,EAAmC,qBACnCC,EAA+C,qBAE/CC,EAA4B,mCAC5BC,EAAyB,gDAEzBC,EAAsB,gDACtBC,EAAyB,mDAEzBC,EAAqC,qEAErCC,EAGO,2CACPC,EAAsC,4CACtCC,EAAmC,6CAEnC,MAAMC,EAA0C,CAC9C,uBAAqB,uBACvB,EAEMC,EAAkB,iBAmBlBC,EAAsB,QAAM,UAAU,CAC1C,UAAW,SACX,iBAAe,YAAS,QAAM,CAChC,CAAC,EAEKC,EAAkC,QAAM,UAAU,CACtD,cAAe,qBACf,gBAAc,SAAMD,CAAmB,EACvC,WAAS,YAAS,QAAM,CAC1B,CAAC,EAOM,IAAME,EAAN,KAEP,CAGE,YAEmBC,EAEAC,EAEjBC,EACA,CALiB,gBAAAF,EAEA,uBAAA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O,cAAY,0BAA0B,IAVrC7B",
6
6
  "names": ["InstructionInfoContextLoader_exports", "__export", "InstructionInfoContextLoader", "__toCommonJS", "import_inversify", "import_purify_ts", "import_configTypes", "import_pkiTypes", "import_KeyId", "import_KeyUsage", "import_instructionInfoTypes", "import_ClearSignContext", "import_certificateResult", "import_deviceModelIdCodec", "SUPPORTED_TYPES", "NETWORK_DEFAULT", "instructionRefCodec", "solanaInstructionInfoInputCodec", "InstructionInfoContextLoader", "dataSource", "certificateLoader", "loggerFactory", "input", "expectedTypes", "t", "instructions", "ix", "network", "distinctProgramIds", "certPromise", "dataPromise", "programId", "certResult", "results", "error", "certificate", "contexts", "either", "err", "value", "wantedDiscriminators", "discriminator", "result", "payload", "set", "hasUnconstrained", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var n=require("purify-ts"),t=require("vitest"),s=require("./HttpLifiDataSource");const l=()=>({debug:t.vi.fn(),info:t.vi.fn(),warn:t.vi.fn(),error:t.vi.fn(),subscribers:[]});(0,t.describe)("HttpLifiDataSource",()=>{let a,e;const o="tpl-123",i={cal:{url:"https://crypto-assets-service.api.ledger.com/v1",mode:"prod",branch:"main"}};(0,t.beforeEach)(()=>{t.vi.clearAllMocks(),e={get:t.vi.fn()},a=new s.HttpLifiDataSource(i,l,e)}),(0,t.it)("should call the network client with the expected URL and params",async()=>{e.get.mockResolvedValue([]),await a.getTransactionDescriptorsPayload({templateId:o}),(0,t.expect)(e.get).toHaveBeenCalledTimes(1),(0,t.expect)(e.get).toHaveBeenCalledWith("https://crypto-assets-service.api.ledger.com/v1/swap_templates",{params:{template_id:o,output:"id,chain_id,instructions,descriptors"}})}),(0,t.it)("should return Right(data[0]) when the network client responds with a non-empty array",async()=>{const r={descriptors:{swap:{programId:"SwapProgram",accounts:[],data:"abcd"}}};e.get.mockResolvedValue([r]);const c=await a.getTransactionDescriptorsPayload({templateId:o});(0,t.expect)(c).toEqual((0,n.Right)(r))}),(0,t.it)("should return an error when data is undefined",async()=>{e.get.mockResolvedValue(null);const r=await a.getTransactionDescriptorsPayload({templateId:o});(0,t.expect)(r).toEqual((0,n.Left)(new Error(`[ContextModule] HttpLifiDataSource: no transaction descriptors for id ${o}`)))}),(0,t.it)("should return an error when data array is empty",async()=>{e.get.mockResolvedValue([]);const r=await a.getTransactionDescriptorsPayload({templateId:o});(0,t.expect)(r).toEqual((0,n.Left)(new Error(`[ContextModule] HttpLifiDataSource: no transaction descriptors for id ${o}`)))}),(0,t.it)("should return an error when first element is falsy",async()=>{e.get.mockResolvedValue([null]);const r=await a.getTransactionDescriptorsPayload({templateId:o});(0,t.expect)(r).toEqual((0,n.Left)(new Error(`[ContextModule] HttpLifiDataSource: no transaction descriptors for id ${o}`)))}),(0,t.it)("should return an error when the network client throws",async()=>{e.get.mockRejectedValue(new Error("network"));const r=await a.getTransactionDescriptorsPayload({templateId:o});(0,t.expect)(r).toEqual((0,n.Left)(new Error("[ContextModule] HttpLifiDataSource: Failed to fetch transaction descriptors")))})});
1
+ "use strict";var n=require("purify-ts"),t=require("vitest"),s=require("./HttpLifiDataSource");const l=()=>({debug:t.vi.fn(),info:t.vi.fn(),warn:t.vi.fn(),error:t.vi.fn(),subscribers:[]});(0,t.describe)("HttpLifiDataSource",()=>{let a,e;const o="tpl-123",i={cal:{url:"https://global.api.prd.ledger.com/cal/v1",mode:"prod",branch:"main"}};(0,t.beforeEach)(()=>{t.vi.clearAllMocks(),e={get:t.vi.fn()},a=new s.HttpLifiDataSource(i,l,e)}),(0,t.it)("should call the network client with the expected URL and params",async()=>{e.get.mockResolvedValue([]),await a.getTransactionDescriptorsPayload({templateId:o}),(0,t.expect)(e.get).toHaveBeenCalledTimes(1),(0,t.expect)(e.get).toHaveBeenCalledWith("https://global.api.prd.ledger.com/cal/v1/swap_templates",{params:{template_id:o,output:"id,chain_id,instructions,descriptors"}})}),(0,t.it)("should return Right(data[0]) when the network client responds with a non-empty array",async()=>{const r={descriptors:{swap:{programId:"SwapProgram",accounts:[],data:"abcd"}}};e.get.mockResolvedValue([r]);const c=await a.getTransactionDescriptorsPayload({templateId:o});(0,t.expect)(c).toEqual((0,n.Right)(r))}),(0,t.it)("should return an error when data is undefined",async()=>{e.get.mockResolvedValue(null);const r=await a.getTransactionDescriptorsPayload({templateId:o});(0,t.expect)(r).toEqual((0,n.Left)(new Error(`[ContextModule] HttpLifiDataSource: no transaction descriptors for id ${o}`)))}),(0,t.it)("should return an error when data array is empty",async()=>{e.get.mockResolvedValue([]);const r=await a.getTransactionDescriptorsPayload({templateId:o});(0,t.expect)(r).toEqual((0,n.Left)(new Error(`[ContextModule] HttpLifiDataSource: no transaction descriptors for id ${o}`)))}),(0,t.it)("should return an error when first element is falsy",async()=>{e.get.mockResolvedValue([null]);const r=await a.getTransactionDescriptorsPayload({templateId:o});(0,t.expect)(r).toEqual((0,n.Left)(new Error(`[ContextModule] HttpLifiDataSource: no transaction descriptors for id ${o}`)))}),(0,t.it)("should return an error when the network client throws",async()=>{e.get.mockRejectedValue(new Error("network"));const r=await a.getTransactionDescriptorsPayload({templateId:o});(0,t.expect)(r).toEqual((0,n.Left)(new Error("[ContextModule] HttpLifiDataSource: Failed to fetch transaction descriptors")))})});
2
2
  //# sourceMappingURL=HttpLifiDataSource.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/modules/solana/lifi/data/HttpLifiDataSource.test.ts"],
4
- "sourcesContent": ["/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\nimport { type DmkNetworkClient } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\nimport { beforeEach, describe, expect, it, vi } from \"vitest\";\n\nimport { type ContextModuleServiceConfig } from \"@/config/model/ContextModuleConfig\";\n\nimport { HttpLifiDataSource } from \"./HttpLifiDataSource\";\nimport {\n type GetTransactionDescriptorsResponse,\n type LifiDataSource,\n} from \"./LifiDataSource\";\n\nconst mockLoggerFactory = () => ({\n debug: vi.fn(),\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n subscribers: [],\n});\n\ndescribe(\"HttpLifiDataSource\", () => {\n let datasource: LifiDataSource;\n let httpMock: { get: ReturnType<typeof vi.fn> };\n const templateId = \"tpl-123\";\n const config: ContextModuleServiceConfig = {\n cal: {\n url: \"https://crypto-assets-service.api.ledger.com/v1\",\n mode: \"prod\",\n branch: \"main\",\n },\n } as ContextModuleServiceConfig;\n\n beforeEach(() => {\n vi.clearAllMocks();\n httpMock = { get: vi.fn() };\n datasource = new HttpLifiDataSource(\n config,\n mockLoggerFactory,\n httpMock as unknown as DmkNetworkClient,\n );\n });\n\n it(\"should call the network client with the expected URL and params\", async () => {\n // given\n httpMock.get.mockResolvedValue([]);\n\n // when\n await datasource.getTransactionDescriptorsPayload({ templateId });\n\n // then\n expect(httpMock.get).toHaveBeenCalledTimes(1);\n expect(httpMock.get).toHaveBeenCalledWith(\n \"https://crypto-assets-service.api.ledger.com/v1/swap_templates\",\n {\n params: {\n template_id: templateId,\n output: \"id,chain_id,instructions,descriptors\",\n },\n },\n );\n });\n\n it(\"should return Right(data[0]) when the network client responds with a non-empty array\", async () => {\n // given\n const response0: GetTransactionDescriptorsResponse = {\n descriptors: {\n swap: { programId: \"SwapProgram\", accounts: [], data: \"abcd\" } as any,\n },\n } as any;\n\n httpMock.get.mockResolvedValue([response0]);\n\n // when\n const result = await datasource.getTransactionDescriptorsPayload({\n templateId,\n });\n\n // then\n expect(result).toEqual(Right(response0));\n });\n\n it(\"should return an error when data is undefined\", async () => {\n // given\n httpMock.get.mockResolvedValue(null);\n\n // when\n const result = await datasource.getTransactionDescriptorsPayload({\n templateId,\n });\n\n // then\n expect(result).toEqual(\n Left(\n new Error(\n `[ContextModule] HttpLifiDataSource: no transaction descriptors for id ${templateId}`,\n ),\n ),\n );\n });\n\n it(\"should return an error when data array is empty\", async () => {\n // given\n httpMock.get.mockResolvedValue([]);\n\n // when\n const result = await datasource.getTransactionDescriptorsPayload({\n templateId,\n });\n\n // then\n expect(result).toEqual(\n Left(\n new Error(\n `[ContextModule] HttpLifiDataSource: no transaction descriptors for id ${templateId}`,\n ),\n ),\n );\n });\n\n it(\"should return an error when first element is falsy\", async () => {\n // given\n httpMock.get.mockResolvedValue([null]);\n\n // when\n const result = await datasource.getTransactionDescriptorsPayload({\n templateId,\n });\n\n // then\n expect(result).toEqual(\n Left(\n new Error(\n `[ContextModule] HttpLifiDataSource: no transaction descriptors for id ${templateId}`,\n ),\n ),\n );\n });\n\n it(\"should return an error when the network client throws\", async () => {\n // given\n httpMock.get.mockRejectedValue(new Error(\"network\"));\n\n // when\n const result = await datasource.getTransactionDescriptorsPayload({\n templateId,\n });\n\n // then\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpLifiDataSource: Failed to fetch transaction descriptors\",\n ),\n ),\n );\n });\n});\n"],
5
- "mappings": "aAGA,IAAAA,EAA4B,qBAC5BC,EAAqD,kBAIrDC,EAAmC,gCAMnC,MAAMC,EAAoB,KAAO,CAC/B,MAAO,KAAG,GAAG,EACb,KAAM,KAAG,GAAG,EACZ,KAAM,KAAG,GAAG,EACZ,MAAO,KAAG,GAAG,EACb,YAAa,CAAC,CAChB,MAEA,YAAS,qBAAsB,IAAM,CACnC,IAAIC,EACAC,EACJ,MAAMC,EAAa,UACbC,EAAqC,CACzC,IAAK,CACH,IAAK,kDACL,KAAM,OACN,OAAQ,MACV,CACF,KAEA,cAAW,IAAM,CACf,KAAG,cAAc,EACjBF,EAAW,CAAE,IAAK,KAAG,GAAG,CAAE,EAC1BD,EAAa,IAAI,qBACfG,EACAJ,EACAE,CACF,CACF,CAAC,KAED,MAAG,kEAAmE,SAAY,CAEhFA,EAAS,IAAI,kBAAkB,CAAC,CAAC,EAGjC,MAAMD,EAAW,iCAAiC,CAAE,WAAAE,CAAW,CAAC,KAGhE,UAAOD,EAAS,GAAG,EAAE,sBAAsB,CAAC,KAC5C,UAAOA,EAA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AI,MACF,6EACF,CACF,CACF,CACF,CAAC,CACH,CAAC",
4
+ "sourcesContent": ["/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\nimport { type DmkNetworkClient } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\nimport { beforeEach, describe, expect, it, vi } from \"vitest\";\n\nimport { type ContextModuleServiceConfig } from \"@/config/model/ContextModuleConfig\";\n\nimport { HttpLifiDataSource } from \"./HttpLifiDataSource\";\nimport {\n type GetTransactionDescriptorsResponse,\n type LifiDataSource,\n} from \"./LifiDataSource\";\n\nconst mockLoggerFactory = () => ({\n debug: vi.fn(),\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n subscribers: [],\n});\n\ndescribe(\"HttpLifiDataSource\", () => {\n let datasource: LifiDataSource;\n let httpMock: { get: ReturnType<typeof vi.fn> };\n const templateId = \"tpl-123\";\n const config: ContextModuleServiceConfig = {\n cal: {\n url: \"https://global.api.prd.ledger.com/cal/v1\",\n mode: \"prod\",\n branch: \"main\",\n },\n } as ContextModuleServiceConfig;\n\n beforeEach(() => {\n vi.clearAllMocks();\n httpMock = { get: vi.fn() };\n datasource = new HttpLifiDataSource(\n config,\n mockLoggerFactory,\n httpMock as unknown as DmkNetworkClient,\n );\n });\n\n it(\"should call the network client with the expected URL and params\", async () => {\n // given\n httpMock.get.mockResolvedValue([]);\n\n // when\n await datasource.getTransactionDescriptorsPayload({ templateId });\n\n // then\n expect(httpMock.get).toHaveBeenCalledTimes(1);\n expect(httpMock.get).toHaveBeenCalledWith(\n \"https://global.api.prd.ledger.com/cal/v1/swap_templates\",\n {\n params: {\n template_id: templateId,\n output: \"id,chain_id,instructions,descriptors\",\n },\n },\n );\n });\n\n it(\"should return Right(data[0]) when the network client responds with a non-empty array\", async () => {\n // given\n const response0: GetTransactionDescriptorsResponse = {\n descriptors: {\n swap: { programId: \"SwapProgram\", accounts: [], data: \"abcd\" } as any,\n },\n } as any;\n\n httpMock.get.mockResolvedValue([response0]);\n\n // when\n const result = await datasource.getTransactionDescriptorsPayload({\n templateId,\n });\n\n // then\n expect(result).toEqual(Right(response0));\n });\n\n it(\"should return an error when data is undefined\", async () => {\n // given\n httpMock.get.mockResolvedValue(null);\n\n // when\n const result = await datasource.getTransactionDescriptorsPayload({\n templateId,\n });\n\n // then\n expect(result).toEqual(\n Left(\n new Error(\n `[ContextModule] HttpLifiDataSource: no transaction descriptors for id ${templateId}`,\n ),\n ),\n );\n });\n\n it(\"should return an error when data array is empty\", async () => {\n // given\n httpMock.get.mockResolvedValue([]);\n\n // when\n const result = await datasource.getTransactionDescriptorsPayload({\n templateId,\n });\n\n // then\n expect(result).toEqual(\n Left(\n new Error(\n `[ContextModule] HttpLifiDataSource: no transaction descriptors for id ${templateId}`,\n ),\n ),\n );\n });\n\n it(\"should return an error when first element is falsy\", async () => {\n // given\n httpMock.get.mockResolvedValue([null]);\n\n // when\n const result = await datasource.getTransactionDescriptorsPayload({\n templateId,\n });\n\n // then\n expect(result).toEqual(\n Left(\n new Error(\n `[ContextModule] HttpLifiDataSource: no transaction descriptors for id ${templateId}`,\n ),\n ),\n );\n });\n\n it(\"should return an error when the network client throws\", async () => {\n // given\n httpMock.get.mockRejectedValue(new Error(\"network\"));\n\n // when\n const result = await datasource.getTransactionDescriptorsPayload({\n templateId,\n });\n\n // then\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpLifiDataSource: Failed to fetch transaction descriptors\",\n ),\n ),\n );\n });\n});\n"],
5
+ "mappings": "aAGA,IAAAA,EAA4B,qBAC5BC,EAAqD,kBAIrDC,EAAmC,gCAMnC,MAAMC,EAAoB,KAAO,CAC/B,MAAO,KAAG,GAAG,EACb,KAAM,KAAG,GAAG,EACZ,KAAM,KAAG,GAAG,EACZ,MAAO,KAAG,GAAG,EACb,YAAa,CAAC,CAChB,MAEA,YAAS,qBAAsB,IAAM,CACnC,IAAIC,EACAC,EACJ,MAAMC,EAAa,U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D,SAAY,CAEnED,EAAS,IAAI,kBAAkB,CAAC,IAAI,CAAC,EAGrC,MAAMI,EAAS,MAAML,EAAW,iCAAiC,CAC/D,WAAAE,CACF,CAAC,KAGD,UAAOG,CAAM,EAAE,WACb,QACE,IAAI,MACF,yEAAyEH,CAAU,EACrF,CACF,CACF,CACF,CAAC,KAED,MAAG,wDAAyD,SAAY,CAEtED,EAAS,IAAI,kBAAkB,IAAI,MAAM,SAAS,CAAC,EAGnD,MAAMI,EAAS,MAAML,EAAW,iCAAiC,CAC/D,WAAAE,CACF,CAAC,KAGD,UAAOG,CAAM,EAAE,WACb,QACE,IAAI,MACF,6EACF,CACF,CACF,CACF,CAAC,CACH,CAAC",
6
6
  "names": ["import_purify_ts", "import_vitest", "import_HttpLifiDataSource", "mockLoggerFactory", "datasource", "httpMock", "templateId", "config", "response0", "result"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var p=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var I=(i,t)=>{for(var a in t)p(i,a,{get:t[a],enumerable:!0})},T=(i,t,a,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of L(t))!h.call(i,e)&&e!==a&&p(i,e,{get:()=>t[e],enumerable:!(r=m(t,e))||r.enumerable});return i};var _=i=>T(p({},"__esModule",{value:!0}),i),f=(i,t,a,r)=>{for(var e=r>1?void 0:r?m(t,a):t,o=i.length-1,n;o>=0;o--)(n=i[o])&&(e=(r?n(t,a,e):n(e))||e);return r&&e&&p(t,a,e),e},d=(i,t)=>(a,r)=>t(a,r,i);var P={};I(P,{LifiContextLoader:()=>l});module.exports=_(P);var c=require("inversify"),u=require("../../../../config/di/configTypes"),y=require("../../../../modules/multichain/pki/di/pkiTypes"),S=require("../../../../modules/multichain/pki/model/KeyId"),C=require("../../../../modules/multichain/pki/model/KeyUsage"),x=require("../../../../modules/solana/lifi/di/lifiTypes"),s=require("../../../../shared/model/ClearSignContext");const b=[s.ClearSignContextType.SOLANA_LIFI];let l=class{constructor(t,a,r,e){this.dataSource=t;this.config=a;this._certificateLoader=r;this.logger=e("LifiContextLoader")}logger;canHandle(t,a){if(!b.every(r=>a.includes(r)))return this.logger.debug("[canHandle] Skipping, expected type does not match",{data:{expectedTypes:a,required:s.ClearSignContextType.SOLANA_LIFI}}),!1;if(typeof t=="object"&&t!==null&&"templateId"in t){const r=t.templateId,e=typeof r=="string"&&r.length>0;return this.logger.debug("[canHandle] Field validation result",{data:{templateId:r,isValid:e}}),e}return this.logger.debug("[canHandle] Field does not contain a valid templateId",{data:{input:t}}),!1}async load(t){this.logger.debug("[load] Loading solana Lifi context",{data:{input:t}});const a=await this._loadInternal(t);if(a.type===s.ClearSignContextType.ERROR)return[{type:s.ClearSignContextType.ERROR,error:a.error}];const r=a;return[{type:s.ClearSignContextType.SOLANA_LIFI,payload:r.payload,certificate:r.certificate}]}async _loadInternal(t){this.logger.debug("[_loadInternal] Loading solana Lifi context",{data:{input:t}});const{templateId:a,deviceModelId:r}=t;if(!a)return{type:s.ClearSignContextType.ERROR,error:new Error("[ContextModule] LifiContextLoader: templateId is missing")};const e=await this.dataSource.getTransactionDescriptorsPayload({templateId:a}),o=await this._certificateLoader.loadCertificate({keyId:S.KeyId.SwapTemplateKey,keyUsage:C.KeyUsage.SwapTemplate,targetDevice:r});return e.caseOf({Left:n=>(this.logger.error("[_loadInternal] Error loading solana Lifi context",{data:{error:n}}),{type:s.ClearSignContextType.ERROR,error:n}),Right:n=>{const g=this.buildPayload(n);return this.logger.debug("[_loadInternal] Successfully loaded solana Lifi context",{data:{descriptors:g.descriptors,instructionsCount:g.instructions.length,certificate:o}}),{type:s.ClearSignContextType.SOLANA_LIFI,payload:g,certificate:o}}})}buildPayload(t){return{descriptors:this.pluckTransactionData(t),instructions:this.extractInstructionsMeta(t)}}pluckTransactionData(t){const a=this.config.cal.mode||"prod",r={},e=t.descriptors??[];this.logger.debug("[pluckTransactionData] Processing descriptors",{data:{descriptorsCount:e.length,signatureKind:a}});for(const o of e){const n=`${o.program_id}:${o.discriminator_hex??""}`;r[n]={data:o.descriptor.data,descriptorType:o.descriptor.descriptorType,descriptorVersion:o.descriptor.descriptorVersion,signature:o.descriptor.signatures[a]??""},this.logger.debug("[pluckTransactionData] Mapped program descriptor",{data:{programId:o.program_id,discriminatorHex:o.discriminator_hex??"",key:n}})}return this.logger.debug("[pluckTransactionData] Completed processing",{data:{outputKeys:Object.keys(r)}}),r}extractInstructionsMeta(t){const a=t.instructions??[];this.logger.debug("[extractInstructionsMeta] Extracting instructions metadata",{data:{instructionsCount:a.length}});const r=a.map(e=>({program_id:e.program_id,...e.discriminator_hex!==void 0&&{discriminator_hex:e.discriminator_hex}}));return this.logger.debug("[extractInstructionsMeta] Completed extracting instructions metadata",{data:{meta:r.map(e=>({programId:e.program_id,discriminatorHex:e.discriminator_hex}))}}),r}};l=f([(0,c.injectable)(),d(0,(0,c.inject)(x.lifiTypes.LifiDataSource)),d(1,(0,c.inject)(u.configTypes.Config)),d(2,(0,c.inject)(y.pkiTypes.PkiCertificateLoader)),d(3,(0,c.inject)(u.configTypes.ContextModuleLoggerFactory))],l);0&&(module.exports={LifiContextLoader});
1
+ "use strict";var g=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var _=(i,t)=>{for(var r in t)g(i,r,{get:t[r],enumerable:!0})},I=(i,t,r,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of x(t))!L.call(i,e)&&e!==r&&g(i,e,{get:()=>t[e],enumerable:!(a=m(t,e))||a.enumerable});return i};var T=i=>I(g({},"__esModule",{value:!0}),i),f=(i,t,r,a)=>{for(var e=a>1?void 0:a?m(t,r):t,o=i.length-1,n;o>=0;o--)(n=i[o])&&(e=(a?n(t,r,e):n(e))||e);return a&&e&&g(t,r,e),e},p=(i,t)=>(r,a)=>t(r,a,i);var P={};_(P,{LifiContextLoader:()=>l});module.exports=T(P);var c=require("inversify"),u=require("../../../../config/di/configTypes"),y=require("../../../../modules/multichain/pki/di/pkiTypes"),S=require("../../../../modules/multichain/pki/model/KeyId"),C=require("../../../../modules/multichain/pki/model/KeyUsage"),h=require("../../../../modules/solana/lifi/di/lifiTypes"),s=require("../../../../shared/model/ClearSignContext");const b=[s.ClearSignContextType.SOLANA_LIFI];let l=class{constructor(t,r,a,e){this.dataSource=t;this.config=r;this._certificateLoader=a;this.logger=e("LifiContextLoader")}logger;canHandle(t,r){if(!b.every(a=>r.includes(a)))return this.logger.debug("[canHandle] Skipping, expected type does not match",{data:{expectedTypes:r,required:s.ClearSignContextType.SOLANA_LIFI}}),!1;if(typeof t=="object"&&t!==null&&"templateId"in t){const a=t.templateId,e=typeof a=="string"&&a.length>0;return this.logger.debug("[canHandle] Field validation result",{data:{templateId:a,isValid:e}}),e}return this.logger.debug("[canHandle] Field does not contain a valid templateId",{data:{input:t}}),!1}async load(t){this.logger.debug("[load] Loading solana Lifi context",{data:{input:t}});const r=await this._loadInternal(t);if(r.type===s.ClearSignContextType.ERROR)return[{type:s.ClearSignContextType.ERROR,error:r.error}];const a=r;return[{type:s.ClearSignContextType.SOLANA_LIFI,payload:a.payload,certificate:a.certificate}]}async _loadInternal(t){this.logger.debug("[_loadInternal] Loading solana Lifi context",{data:{input:t}});const{templateId:r,deviceModelId:a}=t;if(!r)return{type:s.ClearSignContextType.ERROR,error:new Error("[ContextModule] LifiContextLoader: templateId is missing")};const e=await this.dataSource.getTransactionDescriptorsPayload({templateId:r}),o=await this._certificateLoader.loadCertificate({keyId:S.KeyId.SwapTemplateKey,keyUsage:C.KeyUsage.SwapTemplate,targetDevice:a});return e.caseOf({Left:n=>(this.logger.error("[_loadInternal] Error loading solana Lifi context",{data:{error:n}}),{type:s.ClearSignContextType.ERROR,error:n}),Right:n=>{const d=this.buildPayload(n);return this.logger.debug("[_loadInternal] Successfully loaded solana Lifi context",{data:{descriptors:d.descriptors,instructionsCount:d.instructions.length,certificate:o}}),{type:s.ClearSignContextType.SOLANA_LIFI,payload:d,certificate:o}}})}buildPayload(t){return{descriptors:this.pluckTransactionData(t),instructions:this.extractInstructionsMeta(t)}}pluckTransactionData(t){const r=this.config.cal.mode||"prod",a={},e=t.descriptors??[];this.logger.debug("[pluckTransactionData] Processing descriptors",{data:{descriptorsCount:e.length,signatureKind:r}});for(const o of e){const n=`${o.program_id}:${o.discriminator_hex??""}`,d={data:o.descriptor.data,descriptorType:o.descriptor.descriptorType,descriptorVersion:o.descriptor.descriptorVersion,signature:o.descriptor.signatures[r]??"",...o.has_basis_point!==void 0&&{has_basis_point:o.has_basis_point}};(a[n]??=[]).push(d),this.logger.debug("[pluckTransactionData] Mapped program descriptor",{data:{programId:o.program_id,discriminatorHex:o.discriminator_hex??"",key:n}})}return this.logger.debug("[pluckTransactionData] Completed processing",{data:{outputKeys:Object.keys(a)}}),a}extractInstructionsMeta(t){const r=t.instructions??[];this.logger.debug("[extractInstructionsMeta] Extracting instructions metadata",{data:{instructionsCount:r.length}});const a=r.map(e=>({program_id:e.program_id,...e.discriminator_hex!==void 0&&{discriminator_hex:e.discriminator_hex},...e.amount!==void 0&&{has_basis_point:e.amount.capped_bps!==void 0}}));return this.logger.debug("[extractInstructionsMeta] Completed extracting instructions metadata",{data:{meta:a.map(e=>({programId:e.program_id,discriminatorHex:e.discriminator_hex}))}}),a}};l=f([(0,c.injectable)(),p(0,(0,c.inject)(h.lifiTypes.LifiDataSource)),p(1,(0,c.inject)(u.configTypes.Config)),p(2,(0,c.inject)(y.pkiTypes.PkiCertificateLoader)),p(3,(0,c.inject)(u.configTypes.ContextModuleLoggerFactory))],l);0&&(module.exports={LifiContextLoader});
2
2
  //# sourceMappingURL=LifiContextLoader.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/modules/solana/lifi/domain/LifiContextLoader.ts"],
4
- "sourcesContent": ["import { LoggerPublisherService } from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleServiceConfig } from \"@/config/model/ContextModuleConfig\";\nimport { pkiTypes } from \"@/modules/multichain/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/modules/multichain/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/modules/multichain/pki/model/KeyId\";\nimport { KeyUsage } from \"@/modules/multichain/pki/model/KeyUsage\";\nimport { type PkiCertificate } from \"@/modules/multichain/pki/model/PkiCertificate\";\nimport {\n GetTransactionDescriptorsResponse,\n type LifiDataSource,\n} from \"@/modules/solana/lifi/data/LifiDataSource\";\nimport { lifiTypes } from \"@/modules/solana/lifi/di/lifiTypes\";\nimport {\n type SolanaContextError,\n type SolanaLifiContextSuccess,\n type SolanaTransactionDescriptorList,\n} from \"@/modules/solana/model/SolanaContextTypes\";\nimport {\n type SolanaLifiInstructionMeta,\n type SolanaLifiPayload,\n} from \"@/modules/solana/model/SolanaPayloads\";\nimport { type SolanaTransactionContext } from \"@/modules/solana/model/SolanaTransactionContext\";\nimport { type ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n type ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\n\nconst SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.SOLANA_LIFI,\n];\n\n@injectable()\nexport class LifiContextLoader\n implements ContextLoader<SolanaTransactionContext>\n{\n private logger: LoggerPublisherService;\n\n constructor(\n @inject(lifiTypes.LifiDataSource)\n private readonly dataSource: LifiDataSource,\n @inject(configTypes.Config)\n private readonly config: ContextModuleServiceConfig,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n @inject(configTypes.ContextModuleLoggerFactory)\n loggerFactory: (tag: string) => LoggerPublisherService,\n ) {\n this.logger = loggerFactory(\"LifiContextLoader\");\n }\n\n public canHandle(\n input: unknown,\n expectedTypes: ClearSignContextType[],\n ): input is SolanaTransactionContext {\n if (!SUPPORTED_TYPES.every((t) => expectedTypes.includes(t))) {\n this.logger.debug(\"[canHandle] Skipping, expected type does not match\", {\n data: { expectedTypes, required: ClearSignContextType.SOLANA_LIFI },\n });\n return false;\n }\n\n if (typeof input === \"object\" && input !== null && \"templateId\" in input) {\n const templateId = (input as { templateId: unknown }).templateId;\n const isValid = typeof templateId === \"string\" && templateId.length > 0;\n this.logger.debug(\"[canHandle] Field validation result\", {\n data: { templateId, isValid },\n });\n return isValid;\n }\n\n this.logger.debug(\"[canHandle] Field does not contain a valid templateId\", {\n data: { input },\n });\n return false;\n }\n\n public async load(\n solanaLifiContextInput: SolanaTransactionContext,\n ): Promise<ClearSignContext[]> {\n this.logger.debug(\"[load] Loading solana Lifi context\", {\n data: { input: solanaLifiContextInput },\n });\n const result = await this._loadInternal(solanaLifiContextInput);\n if (result.type === ClearSignContextType.ERROR) {\n return [{ type: ClearSignContextType.ERROR, error: result.error }];\n }\n const r = result as SolanaLifiContextSuccess;\n return [\n {\n type: ClearSignContextType.SOLANA_LIFI,\n payload: r.payload,\n certificate: r.certificate,\n },\n ];\n }\n\n private async _loadInternal(\n solanaLifiContextInput: SolanaTransactionContext,\n ): Promise<SolanaLifiContextSuccess | SolanaContextError> {\n this.logger.debug(\"[_loadInternal] Loading solana Lifi context\", {\n data: { input: solanaLifiContextInput },\n });\n const { templateId, deviceModelId } = solanaLifiContextInput;\n\n if (!templateId) {\n return {\n type: ClearSignContextType.ERROR,\n error: new Error(\n \"[ContextModule] LifiContextLoader: templateId is missing\",\n ),\n };\n }\n\n const payload = await this.dataSource.getTransactionDescriptorsPayload({\n templateId,\n });\n\n const certificate: PkiCertificate | undefined =\n await this._certificateLoader.loadCertificate({\n keyId: KeyId.SwapTemplateKey,\n keyUsage: KeyUsage.SwapTemplate,\n targetDevice: deviceModelId,\n });\n\n return payload.caseOf({\n Left: (error): SolanaLifiContextSuccess | SolanaContextError => {\n this.logger.error(\"[_loadInternal] Error loading solana Lifi context\", {\n data: { error },\n });\n\n return {\n type: ClearSignContextType.ERROR,\n error,\n };\n },\n Right: (value): SolanaLifiContextSuccess | SolanaContextError => {\n const lifiPayload = this.buildPayload(value);\n this.logger.debug(\n \"[_loadInternal] Successfully loaded solana Lifi context\",\n {\n data: {\n descriptors: lifiPayload.descriptors,\n instructionsCount: lifiPayload.instructions.length,\n certificate,\n },\n },\n );\n\n return {\n type: ClearSignContextType.SOLANA_LIFI,\n payload: lifiPayload,\n certificate,\n };\n },\n });\n }\n\n private buildPayload(\n response: GetTransactionDescriptorsResponse,\n ): SolanaLifiPayload {\n return {\n descriptors: this.pluckTransactionData(response),\n instructions: this.extractInstructionsMeta(response),\n };\n }\n\n private pluckTransactionData(\n tokenData: GetTransactionDescriptorsResponse,\n ): SolanaTransactionDescriptorList {\n const signatureKind = this.config.cal.mode || \"prod\";\n const output: SolanaTransactionDescriptorList = {};\n const descriptors = tokenData.descriptors ?? [];\n\n this.logger.debug(\"[pluckTransactionData] Processing descriptors\", {\n data: { descriptorsCount: descriptors.length, signatureKind },\n });\n\n for (const item of descriptors) {\n const key = `${item.program_id}:${item.discriminator_hex ?? \"\"}`;\n output[key] = {\n data: item.descriptor.data,\n descriptorType: item.descriptor.descriptorType,\n descriptorVersion: item.descriptor.descriptorVersion,\n signature: item.descriptor.signatures[signatureKind] ?? \"\",\n };\n this.logger.debug(\"[pluckTransactionData] Mapped program descriptor\", {\n data: {\n programId: item.program_id,\n discriminatorHex: item.discriminator_hex ?? \"\",\n key,\n },\n });\n }\n\n this.logger.debug(\"[pluckTransactionData] Completed processing\", {\n data: { outputKeys: Object.keys(output) },\n });\n\n return output;\n }\n\n private extractInstructionsMeta(\n response: GetTransactionDescriptorsResponse,\n ): SolanaLifiInstructionMeta[] {\n const instructions = response.instructions ?? [];\n\n this.logger.debug(\n \"[extractInstructionsMeta] Extracting instructions metadata\",\n {\n data: { instructionsCount: instructions.length },\n },\n );\n\n const meta = instructions.map((ix) => ({\n program_id: ix.program_id,\n ...(ix.discriminator_hex !== undefined && {\n discriminator_hex: ix.discriminator_hex,\n }),\n }));\n\n this.logger.debug(\n \"[extractInstructionsMeta] Completed extracting instructions metadata\",\n {\n data: {\n meta: meta.map((m) => ({\n programId: m.program_id,\n discriminatorHex: m.discriminator_hex,\n })),\n },\n },\n );\n\n return meta;\n }\n}\n"],
5
- "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,IAAA,eAAAC,EAAAH,GACA,IAAAI,EAAmC,qBAEnCC,EAA4B,mCAE5BC,EAAyB,gDAEzBC,EAAsB,gDACtBC,EAAyB,mDAMzBC,EAA0B,8CAY1BC,EAGO,2CAEP,MAAMC,EAA0C,CAC9C,uBAAqB,WACvB,EAGO,IAAMC,EAAN,KAEP,CAGE,YAEmBC,EAEAC,EAEAC,EAEjBC,EACA,CAPiB,gBAAAH,EAEA,YAAAC,EAEA,wBAAAC,EAIjB,KAAK,OAASC,EAAc,mBAAmB,CACjD,CAbQ,OAeD,UACLC,EACAC,EACmC,CACnC,GAAI,CAACP,EAAgB,MAAOQ,GAAMD,EAAc,SAASC,CAAC,CAAC,EACzD,YAAK,OAAO,MAAM,qDAAsD,CACtE,KAAM,CAAE,cAAAD,EAAe,SAAU,uBAAqB,WAAY,CACpE,CAAC,EACM,GAGT,GAAI,OAAOD,GAAU,UAAYA,IAAU,MAAQ,eAAgBA,EAAO,CACxE,MAAMG,EAAcH,EAAkC,WAChDI,EAAU,OAAOD,GAAe,UAAYA,EAAW,OAAS,EACtE,YAAK,OAAO,MAAM,sCAAuC,CACvD,KAAM,CAAE,WAAAA,EAAY,QAAAC,CAAQ,CAC9B,CAAC,EACMA,CACT,CAEA,YAAK,OAAO,MAAM,wDAAyD,CACzE,KAAM,CAAE,MAAAJ,CAAM,CAChB,CAAC,EACM,EACT,CAEA,MAAa,KACXK,EAC6B,CAC7B,KAAK,OAAO,MAAM,qCAAsC,CACtD,KAAM,CAAE,MAAOA,CAAuB,CACxC,CAAC,EACD,MAAMC,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AAA,eAAO,cAAY,0BAA0B,IAZrC9B",
6
- "names": ["LifiContextLoader_exports", "__export", "LifiContextLoader", "__toCommonJS", "import_inversify", "import_configTypes", "import_pkiTypes", "import_KeyId", "import_KeyUsage", "import_lifiTypes", "import_ClearSignContext", "SUPPORTED_TYPES", "LifiContextLoader", "dataSource", "config", "_certificateLoader", "loggerFactory", "input", "expectedTypes", "t", "templateId", "isValid", "solanaLifiContextInput", "result", "deviceModelId", "payload", "certificate", "error", "value", "lifiPayload", "response", "tokenData", "signatureKind", "output", "descriptors", "item", "key", "instructions", "meta", "ix", "m", "__decorateClass", "__decorateParam"]
4
+ "sourcesContent": ["import { LoggerPublisherService } from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleServiceConfig } from \"@/config/model/ContextModuleConfig\";\nimport { pkiTypes } from \"@/modules/multichain/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/modules/multichain/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/modules/multichain/pki/model/KeyId\";\nimport { KeyUsage } from \"@/modules/multichain/pki/model/KeyUsage\";\nimport { type PkiCertificate } from \"@/modules/multichain/pki/model/PkiCertificate\";\nimport {\n GetTransactionDescriptorsResponse,\n type LifiDataSource,\n} from \"@/modules/solana/lifi/data/LifiDataSource\";\nimport { lifiTypes } from \"@/modules/solana/lifi/di/lifiTypes\";\nimport {\n type SolanaContextError,\n type SolanaLifiContextSuccess,\n type SolanaTransactionDescriptorList,\n} from \"@/modules/solana/model/SolanaContextTypes\";\nimport {\n type SolanaLifiInstructionMeta,\n type SolanaLifiPayload,\n} from \"@/modules/solana/model/SolanaPayloads\";\nimport { type SolanaTransactionContext } from \"@/modules/solana/model/SolanaTransactionContext\";\nimport { type ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n type ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\n\nconst SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.SOLANA_LIFI,\n];\n\n@injectable()\nexport class LifiContextLoader\n implements ContextLoader<SolanaTransactionContext>\n{\n private logger: LoggerPublisherService;\n\n constructor(\n @inject(lifiTypes.LifiDataSource)\n private readonly dataSource: LifiDataSource,\n @inject(configTypes.Config)\n private readonly config: ContextModuleServiceConfig,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n @inject(configTypes.ContextModuleLoggerFactory)\n loggerFactory: (tag: string) => LoggerPublisherService,\n ) {\n this.logger = loggerFactory(\"LifiContextLoader\");\n }\n\n public canHandle(\n input: unknown,\n expectedTypes: ClearSignContextType[],\n ): input is SolanaTransactionContext {\n if (!SUPPORTED_TYPES.every((t) => expectedTypes.includes(t))) {\n this.logger.debug(\"[canHandle] Skipping, expected type does not match\", {\n data: { expectedTypes, required: ClearSignContextType.SOLANA_LIFI },\n });\n return false;\n }\n\n if (typeof input === \"object\" && input !== null && \"templateId\" in input) {\n const templateId = (input as { templateId: unknown }).templateId;\n const isValid = typeof templateId === \"string\" && templateId.length > 0;\n this.logger.debug(\"[canHandle] Field validation result\", {\n data: { templateId, isValid },\n });\n return isValid;\n }\n\n this.logger.debug(\"[canHandle] Field does not contain a valid templateId\", {\n data: { input },\n });\n return false;\n }\n\n public async load(\n solanaLifiContextInput: SolanaTransactionContext,\n ): Promise<ClearSignContext[]> {\n this.logger.debug(\"[load] Loading solana Lifi context\", {\n data: { input: solanaLifiContextInput },\n });\n const result = await this._loadInternal(solanaLifiContextInput);\n if (result.type === ClearSignContextType.ERROR) {\n return [{ type: ClearSignContextType.ERROR, error: result.error }];\n }\n const r = result as SolanaLifiContextSuccess;\n return [\n {\n type: ClearSignContextType.SOLANA_LIFI,\n payload: r.payload,\n certificate: r.certificate,\n },\n ];\n }\n\n private async _loadInternal(\n solanaLifiContextInput: SolanaTransactionContext,\n ): Promise<SolanaLifiContextSuccess | SolanaContextError> {\n this.logger.debug(\"[_loadInternal] Loading solana Lifi context\", {\n data: { input: solanaLifiContextInput },\n });\n const { templateId, deviceModelId } = solanaLifiContextInput;\n\n if (!templateId) {\n return {\n type: ClearSignContextType.ERROR,\n error: new Error(\n \"[ContextModule] LifiContextLoader: templateId is missing\",\n ),\n };\n }\n\n const payload = await this.dataSource.getTransactionDescriptorsPayload({\n templateId,\n });\n\n const certificate: PkiCertificate | undefined =\n await this._certificateLoader.loadCertificate({\n keyId: KeyId.SwapTemplateKey,\n keyUsage: KeyUsage.SwapTemplate,\n targetDevice: deviceModelId,\n });\n\n return payload.caseOf({\n Left: (error): SolanaLifiContextSuccess | SolanaContextError => {\n this.logger.error(\"[_loadInternal] Error loading solana Lifi context\", {\n data: { error },\n });\n\n return {\n type: ClearSignContextType.ERROR,\n error,\n };\n },\n Right: (value): SolanaLifiContextSuccess | SolanaContextError => {\n const lifiPayload = this.buildPayload(value);\n this.logger.debug(\n \"[_loadInternal] Successfully loaded solana Lifi context\",\n {\n data: {\n descriptors: lifiPayload.descriptors,\n instructionsCount: lifiPayload.instructions.length,\n certificate,\n },\n },\n );\n\n return {\n type: ClearSignContextType.SOLANA_LIFI,\n payload: lifiPayload,\n certificate,\n };\n },\n });\n }\n\n private buildPayload(\n response: GetTransactionDescriptorsResponse,\n ): SolanaLifiPayload {\n return {\n descriptors: this.pluckTransactionData(response),\n instructions: this.extractInstructionsMeta(response),\n };\n }\n\n private pluckTransactionData(\n tokenData: GetTransactionDescriptorsResponse,\n ): SolanaTransactionDescriptorList {\n const signatureKind = this.config.cal.mode || \"prod\";\n const output: SolanaTransactionDescriptorList = {};\n const descriptors = tokenData.descriptors ?? [];\n\n this.logger.debug(\"[pluckTransactionData] Processing descriptors\", {\n data: { descriptorsCount: descriptors.length, signatureKind },\n });\n\n for (const item of descriptors) {\n const key = `${item.program_id}:${item.discriminator_hex ?? \"\"}`;\n const descriptor = {\n data: item.descriptor.data,\n descriptorType: item.descriptor.descriptorType,\n descriptorVersion: item.descriptor.descriptorVersion,\n signature: item.descriptor.signatures[signatureKind] ?? \"\",\n ...(item.has_basis_point !== undefined && {\n has_basis_point: item.has_basis_point,\n }),\n };\n (output[key] ??= []).push(descriptor);\n this.logger.debug(\"[pluckTransactionData] Mapped program descriptor\", {\n data: {\n programId: item.program_id,\n discriminatorHex: item.discriminator_hex ?? \"\",\n key,\n },\n });\n }\n\n this.logger.debug(\"[pluckTransactionData] Completed processing\", {\n data: { outputKeys: Object.keys(output) },\n });\n\n return output;\n }\n\n private extractInstructionsMeta(\n response: GetTransactionDescriptorsResponse,\n ): SolanaLifiInstructionMeta[] {\n const instructions = response.instructions ?? [];\n\n this.logger.debug(\n \"[extractInstructionsMeta] Extracting instructions metadata\",\n {\n data: { instructionsCount: instructions.length },\n },\n );\n\n const meta = instructions.map((ix) => ({\n program_id: ix.program_id,\n ...(ix.discriminator_hex !== undefined && {\n discriminator_hex: ix.discriminator_hex,\n }),\n ...(ix.amount !== undefined && {\n has_basis_point: ix.amount.capped_bps !== undefined,\n }),\n }));\n\n this.logger.debug(\n \"[extractInstructionsMeta] Completed extracting instructions metadata\",\n {\n data: {\n meta: meta.map((m) => ({\n programId: m.program_id,\n discriminatorHex: m.discriminator_hex,\n })),\n },\n },\n );\n\n return meta;\n }\n}\n"],
5
+ "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,IAAA,eAAAC,EAAAH,GACA,IAAAI,EAAmC,qBAEnCC,EAA4B,mCAE5BC,EAAyB,gDAEzBC,EAAsB,gDACtBC,EAAyB,mDAMzBC,EAA0B,8CAY1BC,EAGO,2CAEP,MAAMC,EAA0C,CAC9C,uBAAqB,WACvB,EAGO,IAAMC,EAAN,KAEP,CAGE,YAEmBC,EAEAC,EAEAC,EAEjBC,EACA,CAPiB,gBAAAH,EAEA,YAAAC,EAEA,wBAAAC,EAIjB,KAAK,OAASC,EAAc,mBAAmB,CACjD,CAbQ,OAeD,UACLC,EACAC,EACmC,CACnC,GAAI,CAACP,EAAg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YAAK,OAAO,MAAM,8CAA+C,CAC/D,KAAM,CAAE,WAAY,OAAO,KAAKH,CAAM,CAAE,CAC1C,CAAC,EAEMA,CACT,CAEQ,wBACNH,EAC6B,CAC7B,MAAMQ,EAAeR,EAAS,cAAgB,CAAC,EAE/C,KAAK,OAAO,MACV,6DACA,CACE,KAAM,CAAE,kBAAmBQ,EAAa,MAAO,CACjD,CACF,EAEA,MAAMC,EAAOD,EAAa,IAAKE,IAAQ,CACrC,WAAYA,EAAG,WACf,GAAIA,EAAG,oBAAsB,QAAa,CACxC,kBAAmBA,EAAG,iBACxB,EACA,GAAIA,EAAG,SAAW,QAAa,CAC7B,gBAAiBA,EAAG,OAAO,aAAe,MAC5C,CACF,EAAE,EAEF,YAAK,OAAO,MACV,uEACA,CACE,KAAM,CACJ,KAAMD,EAAK,IAAKE,IAAO,CACrB,UAAWA,EAAE,WACb,iBAAkBA,EAAE,iBACtB,EAAE,CACJ,CACF,CACF,EAEOF,CACT,CACF,EAjNa5B,EAAN+B,EAAA,IADN,cAAW,EAOPC,EAAA,eAAO,YAAU,cAAc,GAE/BA,EAAA,eAAO,cAAY,MAAM,GAEzBA,EAAA,eAAO,WAAS,oBAAoB,GAEpCA,EAAA,eAAO,cAAY,0BAA0B,IAZrChC",
6
+ "names": ["LifiContextLoader_exports", "__export", "LifiContextLoader", "__toCommonJS", "import_inversify", "import_configTypes", "import_pkiTypes", "import_KeyId", "import_KeyUsage", "import_lifiTypes", "import_ClearSignContext", "SUPPORTED_TYPES", "LifiContextLoader", "dataSource", "config", "_certificateLoader", "loggerFactory", "input", "expectedTypes", "t", "templateId", "isValid", "solanaLifiContextInput", "result", "r", "deviceModelId", "payload", "certificate", "error", "value", "lifiPayload", "response", "tokenData", "signatureKind", "output", "descriptors", "item", "key", "descriptor", "instructions", "meta", "ix", "m", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var p=require("purify-ts"),e=require("vitest"),n=require("../../../../shared/model/ClearSignContext"),b=require("./LifiContextLoader");const k=()=>({debug:e.vi.fn(),info:e.vi.fn(),warn:e.vi.fn(),error:e.vi.fn(),subscribers:[]}),g={keyUsageNumber:13,payload:new Uint8Array([1,2])},f={cal:{url:"https://crypto-assets-service.api.ledger.com",mode:"test",branch:"main"}};(0,e.describe)("LifiContextLoader",()=>{let c,m;const i=(r,t="deadbeef")=>({data:r,descriptorType:"swap_template",descriptorVersion:"v1",signatures:{test:t,prod:`prod_${t}`}}),l=(r,t="deadbeef")=>({data:r,descriptorType:"swap_template",descriptorVersion:"v1",signature:t}),y=[{program_id:"SomeProgram",discriminator_hex:"1",descriptor:i("abc123")},{program_id:"AnotherProgram",descriptor:i("def456")}],u={"SomeProgram:1":l("abc123"),"AnotherProgram:":l("def456")},d={id:"tpl-1",chain_id:101,instructions:[{program_id:"SomeProgram",discriminator:1,discriminator_hex:"1"},{program_id:"AnotherProgram"}],descriptors:y};(0,e.beforeEach)(()=>{e.vi.restoreAllMocks(),c={getTransactionDescriptorsPayload:e.vi.fn()},m={loadCertificate:e.vi.fn().mockResolvedValue(g)}});const s=()=>new b.LifiContextLoader(c,f,m,k);(0,e.describe)("canHandle",()=>{(0,e.it)("returns true when templateId is provided and SOLANA_LIFI is in expectedTypes",()=>{const r=s();(0,e.expect)(r.canHandle({templateId:"tpl-123",deviceModelId:"nanoS"},[n.ClearSignContextType.SOLANA_LIFI])).toBe(!0)}),(0,e.it)("returns false when SOLANA_LIFI is not in expectedTypes",()=>{const r=s();(0,e.expect)(r.canHandle({templateId:"tpl-123"},[n.ClearSignContextType.SOLANA_TOKEN])).toBe(!1)}),(0,e.it)("returns false when templateId is missing or falsy",()=>{const r=s();(0,e.expect)(r.canHandle({templateId:""},[n.ClearSignContextType.SOLANA_LIFI])).toBe(!1),(0,e.expect)(r.canHandle({templateId:void 0},[n.ClearSignContextType.SOLANA_LIFI])).toBe(!1),(0,e.expect)(r.canHandle({},[n.ClearSignContextType.SOLANA_LIFI])).toBe(!1)})}),(0,e.describe)("load",()=>{(0,e.it)("returns an array with an error when datasource returns Left(error)",async()=>{const r=s(),t=new Error("boom");e.vi.spyOn(c,"getTransactionDescriptorsPayload").mockResolvedValue((0,p.Left)(t));const o={templateId:"tpl-err",deviceModelId:"nanoS"},a=await r.load(o);(0,e.expect)(c.getTransactionDescriptorsPayload).toHaveBeenCalledWith({templateId:"tpl-err"}),(0,e.expect)(a).toEqual([{type:n.ClearSignContextType.ERROR,error:t}])}),(0,e.it)("returns SOLANA_LIFI array with plucked descriptors and certificate when datasource returns Right(value)",async()=>{const r=s();e.vi.spyOn(c,"getTransactionDescriptorsPayload").mockResolvedValue((0,p.Right)(d));const t={templateId:"tpl-ok",deviceModelId:"nanoS"},o=await r.load(t);(0,e.expect)(c.getTransactionDescriptorsPayload).toHaveBeenCalledWith({templateId:"tpl-ok"}),(0,e.expect)(m.loadCertificate).toHaveBeenCalledWith({keyId:"swap_template_key",keyUsage:"swap_template",targetDevice:"nanoS"}),(0,e.expect)(o).toEqual([{type:n.ClearSignContextType.SOLANA_LIFI,payload:{descriptors:u,instructions:[{program_id:"SomeProgram",discriminator_hex:"1"},{program_id:"AnotherProgram"}]},certificate:g}])})}),(0,e.describe)("pluckTransactionData (private)",()=>{(0,e.it)("returns a map keyed by `${program_id}:${discriminator_hex ?? '0'}`",()=>{const r=s(),o=r.pluckTransactionData.bind(r)(d);(0,e.expect)(o).toEqual(u)})}),(0,e.describe)("extractInstructionsMeta (private)",()=>{(0,e.it)("returns instruction metadata from the API response",()=>{const r=s(),o=r.extractInstructionsMeta.bind(r)(d);(0,e.expect)(o).toEqual([{program_id:"SomeProgram",discriminator_hex:"1"},{program_id:"AnotherProgram"}])}),(0,e.it)("returns empty array when instructions are missing",()=>{const r=s(),o=r.extractInstructionsMeta.bind(r)({...d,instructions:void 0});(0,e.expect)(o).toEqual([])})}),(0,e.describe)("pluckTransactionData mode resolution (private)",()=>{(0,e.it)("resolves signature using config.cal.mode",()=>{const r=s(),o=r.pluckTransactionData.bind(r)(d);(0,e.expect)(o["SomeProgram:1"]?.signature).toBe("deadbeef")})}),(0,e.describe)("real CAL payload (LiFi template 4c694669)",()=>{const r={id:"4c694669",chain_id:101,instructions:[{program_id:"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",discriminator:1,discriminator_hex:"1"},{program_id:"11111111111111111111111111111111",discriminator:2,discriminator_hex:"2"},{program_id:"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4",discriminator:0x2aade37a97cb1800,discriminator_hex:"2aade37a97cb17e0"},{program_id:"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4",discriminator:9339575302786589e3,discriminator_hex:"819cd641339b2148"},{program_id:"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"},{program_id:"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",discriminator:1,discriminator_hex:"1"},{program_id:"3i5JeuZuUxeKtVysUnwQNGerJP2bSMX9fTFfS4Nxe3Br"},{program_id:"ComputeBudget111111111111111111111111111111",discriminator:2,discriminator_hex:"2"},{program_id:"ComputeBudget111111111111111111111111111111",discriminator:3,discriminator_hex:"3"},{program_id:"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",discriminator:3,discriminator_hex:"3"},{program_id:"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",discriminator:17,discriminator_hex:"11"},{program_id:"BrdgN2RPzEMWF96ZbnnJaUtQDQx7VRXYaHHbYCBvceWB"}],descriptors:[{program_id:"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",discriminator_hex:"1",descriptor:i("atoken_1","sig_atoken")},{program_id:"11111111111111111111111111111111",discriminator_hex:"2",descriptor:i("system_2","sig_system")},{program_id:"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4",discriminator_hex:"2aade37a97cb17e0",descriptor:i("jup_route","sig_jup_route")},{program_id:"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4",discriminator_hex:"819cd641339b2148",descriptor:i("jup_shared","sig_jup_shared")},{program_id:"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr",descriptor:i("memo","sig_memo")},{program_id:"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",discriminator_hex:"1",descriptor:i("atoken_1","sig_atoken")},{program_id:"3i5JeuZuUxeKtVysUnwQNGerJP2bSMX9fTFfS4Nxe3Br",descriptor:i("3i5jeu","sig_3i5jeu")},{program_id:"ComputeBudget111111111111111111111111111111",discriminator_hex:"2",descriptor:i("cb_2","sig_cb2")},{program_id:"ComputeBudget111111111111111111111111111111",discriminator_hex:"3",descriptor:i("cb_3","sig_cb3")},{program_id:"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",discriminator_hex:"3",descriptor:i("tokenkeg_3","sig_tk3")},{program_id:"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",discriminator_hex:"11",descriptor:i("tokenkeg_11","sig_tk11")},{program_id:"BrdgN2RPzEMWF96ZbnnJaUtQDQx7VRXYaHHbYCBvceWB",descriptor:i("brdg","sig_brdg")}]};(0,e.it)("produces 11 unique descriptor keys (ATokenGP:1 appears twice but deduplicates)",()=>{const t=s(),a=t.pluckTransactionData.bind(t)(r),_=Object.keys(a);(0,e.expect)(_).toHaveLength(11)}),(0,e.it)("creates distinct keys for same program_id with different discriminators",()=>{const t=s(),a=t.pluckTransactionData.bind(t)(r);(0,e.expect)(a["JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4:2aade37a97cb17e0"]?.data).toBe("jup_route"),(0,e.expect)(a["JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4:819cd641339b2148"]?.data).toBe("jup_shared"),(0,e.expect)(a["ComputeBudget111111111111111111111111111111:2"]?.data).toBe("cb_2"),(0,e.expect)(a["ComputeBudget111111111111111111111111111111:3"]?.data).toBe("cb_3"),(0,e.expect)(a["TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA:3"]?.data).toBe("tokenkeg_3"),(0,e.expect)(a["TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA:11"]?.data).toBe("tokenkeg_11")}),(0,e.it)("uses :0 suffix for programs without a discriminator",()=>{const t=s(),a=t.pluckTransactionData.bind(t)(r);(0,e.expect)(a["MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr:"]?.data).toBe("memo"),(0,e.expect)(a["3i5JeuZuUxeKtVysUnwQNGerJP2bSMX9fTFfS4Nxe3Br:"]?.data).toBe("3i5jeu"),(0,e.expect)(a["BrdgN2RPzEMWF96ZbnnJaUtQDQx7VRXYaHHbYCBvceWB:"]?.data).toBe("brdg")}),(0,e.it)("extracts 12 instruction metadata entries preserving order and discriminators",()=>{const t=s(),a=t.extractInstructionsMeta.bind(t)(r);(0,e.expect)(a).toHaveLength(12),(0,e.expect)(a[0]).toEqual({program_id:"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",discriminator_hex:"1"}),(0,e.expect)(a[2]).toEqual({program_id:"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4",discriminator_hex:"2aade37a97cb17e0"}),(0,e.expect)(a[3]).toEqual({program_id:"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4",discriminator_hex:"819cd641339b2148"}),(0,e.expect)(a[4]).toEqual({program_id:"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"}),(0,e.expect)(a[11]).toEqual({program_id:"BrdgN2RPzEMWF96ZbnnJaUtQDQx7VRXYaHHbYCBvceWB"})}),(0,e.it)("load returns full payload with descriptors and instructions from real API response",async()=>{const t=s();e.vi.spyOn(c,"getTransactionDescriptorsPayload").mockResolvedValue((0,p.Right)(r));const o={templateId:"4c694669",deviceModelId:"nanoS"},a=await t.load(o);(0,e.expect)(a).toHaveLength(1),(0,e.expect)(a[0]).toMatchObject({type:n.ClearSignContextType.SOLANA_LIFI,payload:{descriptors:e.expect.objectContaining({"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4:2aade37a97cb17e0":e.expect.objectContaining({data:"jup_route"}),"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4:819cd641339b2148":e.expect.objectContaining({data:"jup_shared"})}),instructions:e.expect.arrayContaining([e.expect.objectContaining({program_id:"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4",discriminator_hex:"2aade37a97cb17e0"}),e.expect.objectContaining({program_id:"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4",discriminator_hex:"819cd641339b2148"})])}}),(0,e.expect)(Object.keys(a[0].payload.descriptors)).toHaveLength(11),(0,e.expect)(a[0].payload.instructions).toHaveLength(12)})})});
1
+ "use strict";var p=require("purify-ts"),r=require("vitest"),n=require("../../../../shared/model/ClearSignContext"),_=require("./LifiContextLoader");const k=()=>({debug:r.vi.fn(),info:r.vi.fn(),warn:r.vi.fn(),error:r.vi.fn(),subscribers:[]}),g={keyUsageNumber:13,payload:new Uint8Array([1,2])},f={cal:{url:"https://global.api.prd.ledger.com/cal/v1",mode:"test",branch:"main"}};(0,r.describe)("LifiContextLoader",()=>{let c,m;const i=(e,t="deadbeef")=>({data:e,descriptorType:"swap_template",descriptorVersion:"v1",signatures:{test:t,prod:`prod_${t}`}}),l=(e,t="deadbeef")=>({data:e,descriptorType:"swap_template",descriptorVersion:"v1",signature:t}),b=[{program_id:"SomeProgram",discriminator_hex:"1",descriptor:i("abc123")},{program_id:"AnotherProgram",descriptor:i("def456")}],u={"SomeProgram:1":[l("abc123")],"AnotherProgram:":[l("def456")]},d={id:"tpl-1",chain_id:101,instructions:[{program_id:"SomeProgram",discriminator:1,discriminator_hex:"1"},{program_id:"AnotherProgram"}],descriptors:b};(0,r.beforeEach)(()=>{r.vi.restoreAllMocks(),c={getTransactionDescriptorsPayload:r.vi.fn()},m={loadCertificate:r.vi.fn().mockResolvedValue(g)}});const s=()=>new _.LifiContextLoader(c,f,m,k);(0,r.describe)("canHandle",()=>{(0,r.it)("returns true when templateId is provided and SOLANA_LIFI is in expectedTypes",()=>{const e=s();(0,r.expect)(e.canHandle({templateId:"tpl-123",deviceModelId:"nanoS"},[n.ClearSignContextType.SOLANA_LIFI])).toBe(!0)}),(0,r.it)("returns false when SOLANA_LIFI is not in expectedTypes",()=>{const e=s();(0,r.expect)(e.canHandle({templateId:"tpl-123"},[n.ClearSignContextType.SOLANA_TOKEN])).toBe(!1)}),(0,r.it)("returns false when templateId is missing or falsy",()=>{const e=s();(0,r.expect)(e.canHandle({templateId:""},[n.ClearSignContextType.SOLANA_LIFI])).toBe(!1),(0,r.expect)(e.canHandle({templateId:void 0},[n.ClearSignContextType.SOLANA_LIFI])).toBe(!1),(0,r.expect)(e.canHandle({},[n.ClearSignContextType.SOLANA_LIFI])).toBe(!1)})}),(0,r.describe)("load",()=>{(0,r.it)("returns an array with an error when datasource returns Left(error)",async()=>{const e=s(),t=new Error("boom");r.vi.spyOn(c,"getTransactionDescriptorsPayload").mockResolvedValue((0,p.Left)(t));const o={templateId:"tpl-err",deviceModelId:"nanoS"},a=await e.load(o);(0,r.expect)(c.getTransactionDescriptorsPayload).toHaveBeenCalledWith({templateId:"tpl-err"}),(0,r.expect)(a).toEqual([{type:n.ClearSignContextType.ERROR,error:t}])}),(0,r.it)("returns SOLANA_LIFI array with plucked descriptors and certificate when datasource returns Right(value)",async()=>{const e=s();r.vi.spyOn(c,"getTransactionDescriptorsPayload").mockResolvedValue((0,p.Right)(d));const t={templateId:"tpl-ok",deviceModelId:"nanoS"},o=await e.load(t);(0,r.expect)(c.getTransactionDescriptorsPayload).toHaveBeenCalledWith({templateId:"tpl-ok"}),(0,r.expect)(m.loadCertificate).toHaveBeenCalledWith({keyId:"swap_template_key",keyUsage:"swap_template",targetDevice:"nanoS"}),(0,r.expect)(o).toEqual([{type:n.ClearSignContextType.SOLANA_LIFI,payload:{descriptors:u,instructions:[{program_id:"SomeProgram",discriminator_hex:"1"},{program_id:"AnotherProgram"}]},certificate:g}])})}),(0,r.describe)("pluckTransactionData (private)",()=>{(0,r.it)("returns a map keyed by `${program_id}:${discriminator_hex ?? '0'}`",()=>{const e=s(),o=e.pluckTransactionData.bind(e)(d);(0,r.expect)(o).toEqual(u)})}),(0,r.describe)("extractInstructionsMeta (private)",()=>{(0,r.it)("returns instruction metadata from the API response",()=>{const e=s(),o=e.extractInstructionsMeta.bind(e)(d);(0,r.expect)(o).toEqual([{program_id:"SomeProgram",discriminator_hex:"1"},{program_id:"AnotherProgram"}])}),(0,r.it)("returns empty array when instructions are missing",()=>{const e=s(),o=e.extractInstructionsMeta.bind(e)({...d,instructions:void 0});(0,r.expect)(o).toEqual([])})}),(0,r.describe)("pluckTransactionData mode resolution (private)",()=>{(0,r.it)("resolves signature using config.cal.mode",()=>{const e=s(),o=e.pluckTransactionData.bind(e)(d);(0,r.expect)(o["SomeProgram:1"]?.[0]?.signature).toBe("deadbeef")})}),(0,r.describe)("duplicate discriminator handling (private)",()=>{(0,r.it)("collects both descriptors into an array when same (program_id, discriminator_hex) appears twice",()=>{const e=s(),t=e.pluckTransactionData.bind(e),o={id:"dup-test",chain_id:101,instructions:[{program_id:"11111111111111111111111111111111",discriminator:2,discriminator_hex:"02"},{program_id:"11111111111111111111111111111111",discriminator:2,discriminator_hex:"02"}],descriptors:[{program_id:"11111111111111111111111111111111",discriminator_hex:"02",has_basis_point:!1,descriptor:i("transfer_descriptor","sig_transfer")},{program_id:"11111111111111111111111111111111",discriminator_hex:"02",has_basis_point:!0,descriptor:i("fee_descriptor","sig_fee")}]},a=t(o);(0,r.expect)(Object.keys(a)).toHaveLength(1),(0,r.expect)(a["11111111111111111111111111111111:02"]).toHaveLength(2),(0,r.expect)(a["11111111111111111111111111111111:02"]?.[0]?.data).toBe("transfer_descriptor"),(0,r.expect)(a["11111111111111111111111111111111:02"]?.[0]?.has_basis_point).toBe(!1),(0,r.expect)(a["11111111111111111111111111111111:02"]?.[1]?.data).toBe("fee_descriptor"),(0,r.expect)(a["11111111111111111111111111111111:02"]?.[1]?.has_basis_point).toBe(!0)})}),(0,r.describe)("real CAL payload (LiFi template 4c694669)",()=>{const e={id:"4c694669",chain_id:101,instructions:[{program_id:"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",discriminator:1,discriminator_hex:"1"},{program_id:"11111111111111111111111111111111",discriminator:2,discriminator_hex:"2"},{program_id:"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4",discriminator:0x2aade37a97cb1800,discriminator_hex:"2aade37a97cb17e0"},{program_id:"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4",discriminator:9339575302786589e3,discriminator_hex:"819cd641339b2148"},{program_id:"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"},{program_id:"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",discriminator:1,discriminator_hex:"1"},{program_id:"3i5JeuZuUxeKtVysUnwQNGerJP2bSMX9fTFfS4Nxe3Br"},{program_id:"ComputeBudget111111111111111111111111111111",discriminator:2,discriminator_hex:"2"},{program_id:"ComputeBudget111111111111111111111111111111",discriminator:3,discriminator_hex:"3"},{program_id:"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",discriminator:3,discriminator_hex:"3"},{program_id:"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",discriminator:17,discriminator_hex:"11"},{program_id:"BrdgN2RPzEMWF96ZbnnJaUtQDQx7VRXYaHHbYCBvceWB"}],descriptors:[{program_id:"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",discriminator_hex:"1",descriptor:i("atoken_1","sig_atoken")},{program_id:"11111111111111111111111111111111",discriminator_hex:"2",descriptor:i("system_2","sig_system")},{program_id:"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4",discriminator_hex:"2aade37a97cb17e0",descriptor:i("jup_route","sig_jup_route")},{program_id:"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4",discriminator_hex:"819cd641339b2148",descriptor:i("jup_shared","sig_jup_shared")},{program_id:"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr",descriptor:i("memo","sig_memo")},{program_id:"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",discriminator_hex:"1",descriptor:i("atoken_1","sig_atoken")},{program_id:"3i5JeuZuUxeKtVysUnwQNGerJP2bSMX9fTFfS4Nxe3Br",descriptor:i("3i5jeu","sig_3i5jeu")},{program_id:"ComputeBudget111111111111111111111111111111",discriminator_hex:"2",descriptor:i("cb_2","sig_cb2")},{program_id:"ComputeBudget111111111111111111111111111111",discriminator_hex:"3",descriptor:i("cb_3","sig_cb3")},{program_id:"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",discriminator_hex:"3",descriptor:i("tokenkeg_3","sig_tk3")},{program_id:"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",discriminator_hex:"11",descriptor:i("tokenkeg_11","sig_tk11")},{program_id:"BrdgN2RPzEMWF96ZbnnJaUtQDQx7VRXYaHHbYCBvceWB",descriptor:i("brdg","sig_brdg")}]};(0,r.it)("produces 11 unique descriptor keys (ATokenGP:1 appears twice -> array of 2)",()=>{const t=s(),a=t.pluckTransactionData.bind(t)(e),y=Object.keys(a);(0,r.expect)(y).toHaveLength(11),(0,r.expect)(a["ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL:1"]).toHaveLength(2)}),(0,r.it)("creates distinct keys for same program_id with different discriminators",()=>{const t=s(),a=t.pluckTransactionData.bind(t)(e);(0,r.expect)(a["JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4:2aade37a97cb17e0"]?.[0]?.data).toBe("jup_route"),(0,r.expect)(a["JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4:819cd641339b2148"]?.[0]?.data).toBe("jup_shared"),(0,r.expect)(a["ComputeBudget111111111111111111111111111111:2"]?.[0]?.data).toBe("cb_2"),(0,r.expect)(a["ComputeBudget111111111111111111111111111111:3"]?.[0]?.data).toBe("cb_3"),(0,r.expect)(a["TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA:3"]?.[0]?.data).toBe("tokenkeg_3"),(0,r.expect)(a["TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA:11"]?.[0]?.data).toBe("tokenkeg_11")}),(0,r.it)("uses :0 suffix for programs without a discriminator",()=>{const t=s(),a=t.pluckTransactionData.bind(t)(e);(0,r.expect)(a["MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr:"]?.[0]?.data).toBe("memo"),(0,r.expect)(a["3i5JeuZuUxeKtVysUnwQNGerJP2bSMX9fTFfS4Nxe3Br:"]?.[0]?.data).toBe("3i5jeu"),(0,r.expect)(a["BrdgN2RPzEMWF96ZbnnJaUtQDQx7VRXYaHHbYCBvceWB:"]?.[0]?.data).toBe("brdg")}),(0,r.it)("extracts 12 instruction metadata entries preserving order and discriminators",()=>{const t=s(),a=t.extractInstructionsMeta.bind(t)(e);(0,r.expect)(a).toHaveLength(12),(0,r.expect)(a[0]).toEqual({program_id:"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",discriminator_hex:"1"}),(0,r.expect)(a[2]).toEqual({program_id:"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4",discriminator_hex:"2aade37a97cb17e0"}),(0,r.expect)(a[3]).toEqual({program_id:"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4",discriminator_hex:"819cd641339b2148"}),(0,r.expect)(a[4]).toEqual({program_id:"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"}),(0,r.expect)(a[11]).toEqual({program_id:"BrdgN2RPzEMWF96ZbnnJaUtQDQx7VRXYaHHbYCBvceWB"})}),(0,r.it)("load returns full payload with descriptors and instructions from real API response",async()=>{const t=s();r.vi.spyOn(c,"getTransactionDescriptorsPayload").mockResolvedValue((0,p.Right)(e));const o={templateId:"4c694669",deviceModelId:"nanoS"},a=await t.load(o);(0,r.expect)(a).toHaveLength(1),(0,r.expect)(a[0]).toMatchObject({type:n.ClearSignContextType.SOLANA_LIFI,payload:{descriptors:r.expect.objectContaining({"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4:2aade37a97cb17e0":r.expect.arrayContaining([r.expect.objectContaining({data:"jup_route"})]),"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4:819cd641339b2148":r.expect.arrayContaining([r.expect.objectContaining({data:"jup_shared"})])}),instructions:r.expect.arrayContaining([r.expect.objectContaining({program_id:"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4",discriminator_hex:"2aade37a97cb17e0"}),r.expect.objectContaining({program_id:"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4",discriminator_hex:"819cd641339b2148"})])}}),(0,r.expect)(Object.keys(a[0].payload.descriptors)).toHaveLength(11),(0,r.expect)(a[0].payload.instructions).toHaveLength(12)})})});
2
2
  //# sourceMappingURL=LifiContextLoader.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/modules/solana/lifi/domain/LifiContextLoader.test.ts"],
4
- "sourcesContent": ["/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { Left, Right } from \"purify-ts\";\nimport { beforeEach, describe, expect, it, vi } from \"vitest\";\n\nimport { type ContextModuleServiceConfig } from \"@/config/model/ContextModuleConfig\";\nimport { type PkiCertificateLoader } from \"@/modules/multichain/pki/domain/PkiCertificateLoader\";\nimport {\n type GetTransactionDescriptorsResponse,\n type LifiDataSource,\n} from \"@/modules/solana/lifi/data/LifiDataSource\";\nimport {\n type SolanaTransactionDescriptorList,\n type SolanaTransactionDescriptorRaw,\n} from \"@/modules/solana/model/SolanaContextTypes\";\nimport { type SolanaTransactionDescriptor } from \"@/modules/solana/model/SolanaPayloads\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\n\nimport { LifiContextLoader } from \"./LifiContextLoader\";\n\nconst mockLoggerFactory = () => ({\n debug: vi.fn(),\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n subscribers: [],\n});\n\nconst mockCertificate = {\n keyUsageNumber: 13,\n payload: new Uint8Array([0x01, 0x02]),\n};\n\nconst mockConfig = {\n cal: {\n url: \"https://crypto-assets-service.api.ledger.com\",\n mode: \"test\",\n branch: \"main\",\n },\n} as ContextModuleServiceConfig;\n\ndescribe(\"LifiContextLoader\", () => {\n let mockDataSource: LifiDataSource;\n let mockCertificateLoader: PkiCertificateLoader;\n\n const makeRawDescriptor = (\n data: string,\n sig = \"deadbeef\",\n ): SolanaTransactionDescriptorRaw => ({\n data,\n descriptorType: \"swap_template\",\n descriptorVersion: \"v1\",\n signatures: { test: sig, prod: `prod_${sig}` },\n });\n\n const makeResolvedDescriptor = (\n data: string,\n sig = \"deadbeef\",\n ): SolanaTransactionDescriptor => ({\n data,\n descriptorType: \"swap_template\",\n descriptorVersion: \"v1\",\n signature: sig,\n });\n\n const responseDescriptorsArray: GetTransactionDescriptorsResponse[\"descriptors\"] =\n [\n {\n program_id: \"SomeProgram\",\n discriminator_hex: \"1\",\n descriptor: makeRawDescriptor(\"abc123\"),\n },\n {\n program_id: \"AnotherProgram\",\n // discriminator_hex intentionally omitted -> defaults to \"\"\n descriptor: makeRawDescriptor(\"def456\"),\n },\n ];\n\n const expectedPlucked: SolanaTransactionDescriptorList = {\n \"SomeProgram:1\": makeResolvedDescriptor(\"abc123\"),\n \"AnotherProgram:\": makeResolvedDescriptor(\"def456\"),\n };\n\n const responseInstructionsArray: GetTransactionDescriptorsResponse[\"instructions\"] =\n [\n {\n program_id: \"SomeProgram\",\n discriminator: 1,\n discriminator_hex: \"1\",\n },\n {\n program_id: \"AnotherProgram\",\n // discriminator_hex intentionally omitted\n },\n ];\n\n const txDescriptorsResponse: GetTransactionDescriptorsResponse = {\n id: \"tpl-1\",\n chain_id: 101,\n instructions: responseInstructionsArray,\n descriptors: responseDescriptorsArray,\n };\n\n beforeEach(() => {\n vi.restoreAllMocks();\n mockDataSource = {\n getTransactionDescriptorsPayload: vi.fn(),\n } as unknown as LifiDataSource;\n mockCertificateLoader = {\n loadCertificate: vi.fn().mockResolvedValue(mockCertificate),\n } as unknown as PkiCertificateLoader;\n });\n\n const makeLoader = () =>\n new LifiContextLoader(\n mockDataSource,\n mockConfig,\n mockCertificateLoader,\n mockLoggerFactory,\n );\n\n describe(\"canHandle\", () => {\n it(\"returns true when templateId is provided and SOLANA_LIFI is in expectedTypes\", () => {\n const loader = makeLoader();\n\n expect(\n loader.canHandle(\n {\n templateId: \"tpl-123\",\n deviceModelId: \"nanoS\" as any,\n },\n [ClearSignContextType.SOLANA_LIFI],\n ),\n ).toBe(true);\n });\n\n it(\"returns false when SOLANA_LIFI is not in expectedTypes\", () => {\n const loader = makeLoader();\n\n expect(\n loader.canHandle({ templateId: \"tpl-123\" } as any, [\n ClearSignContextType.SOLANA_TOKEN,\n ]),\n ).toBe(false);\n });\n\n it(\"returns false when templateId is missing or falsy\", () => {\n const loader = makeLoader();\n\n expect(\n loader.canHandle({ templateId: \"\" } as any, [\n ClearSignContextType.SOLANA_LIFI,\n ]),\n ).toBe(false);\n expect(\n loader.canHandle({ templateId: undefined } as any, [\n ClearSignContextType.SOLANA_LIFI,\n ]),\n ).toBe(false);\n expect(\n loader.canHandle({} as any, [ClearSignContextType.SOLANA_LIFI]),\n ).toBe(false);\n });\n });\n\n describe(\"load\", () => {\n it(\"returns an array with an error when datasource returns Left(error)\", async () => {\n const loader = makeLoader();\n const error = new Error(\"boom\");\n\n vi.spyOn(\n mockDataSource,\n \"getTransactionDescriptorsPayload\",\n ).mockResolvedValue(Left(error));\n\n const input = { templateId: \"tpl-err\", deviceModelId: \"nanoS\" as any };\n const result = await loader.load(input);\n\n expect(\n mockDataSource.getTransactionDescriptorsPayload,\n ).toHaveBeenCalledWith({\n templateId: \"tpl-err\",\n });\n\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error,\n },\n ]);\n });\n\n it(\"returns SOLANA_LIFI array with plucked descriptors and certificate when datasource returns Right(value)\", async () => {\n const loader = makeLoader();\n\n vi.spyOn(\n mockDataSource,\n \"getTransactionDescriptorsPayload\",\n ).mockResolvedValue(Right(txDescriptorsResponse));\n\n const input = { templateId: \"tpl-ok\", deviceModelId: \"nanoS\" as any };\n const result = await loader.load(input);\n\n expect(\n mockDataSource.getTransactionDescriptorsPayload,\n ).toHaveBeenCalledWith({\n templateId: \"tpl-ok\",\n });\n\n expect(mockCertificateLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: \"swap_template_key\",\n keyUsage: \"swap_template\",\n targetDevice: \"nanoS\",\n });\n\n expect(result).toEqual([\n {\n type: ClearSignContextType.SOLANA_LIFI,\n payload: {\n descriptors: expectedPlucked,\n instructions: [\n { program_id: \"SomeProgram\", discriminator_hex: \"1\" },\n { program_id: \"AnotherProgram\" },\n ],\n },\n certificate: mockCertificate,\n },\n ]);\n });\n });\n\n describe(\"pluckTransactionData (private)\", () => {\n it(\"returns a map keyed by `${program_id}:${discriminator_hex ?? '0'}`\", () => {\n const loader = makeLoader();\n const pluck = (loader as any).pluckTransactionData.bind(loader);\n\n const result: SolanaTransactionDescriptorList = pluck(\n txDescriptorsResponse,\n );\n\n expect(result).toEqual(expectedPlucked);\n });\n });\n\n describe(\"extractInstructionsMeta (private)\", () => {\n it(\"returns instruction metadata from the API response\", () => {\n const loader = makeLoader();\n const extract = (loader as any).extractInstructionsMeta.bind(loader);\n\n const result = extract(txDescriptorsResponse);\n\n expect(result).toEqual([\n { program_id: \"SomeProgram\", discriminator_hex: \"1\" },\n { program_id: \"AnotherProgram\" },\n ]);\n });\n\n it(\"returns empty array when instructions are missing\", () => {\n const loader = makeLoader();\n const extract = (loader as any).extractInstructionsMeta.bind(loader);\n\n const result = extract({\n ...txDescriptorsResponse,\n instructions: undefined,\n });\n\n expect(result).toEqual([]);\n });\n });\n\n describe(\"pluckTransactionData mode resolution (private)\", () => {\n it(\"resolves signature using config.cal.mode\", () => {\n const loader = makeLoader();\n const pluck = (loader as any).pluckTransactionData.bind(loader);\n\n const result: SolanaTransactionDescriptorList = pluck(\n txDescriptorsResponse,\n );\n\n expect(result[\"SomeProgram:1\"]?.signature).toBe(\"deadbeef\");\n });\n });\n\n describe(\"real CAL payload (LiFi template 4c694669)\", () => {\n const realApiResponse: GetTransactionDescriptorsResponse = {\n id: \"4c694669\",\n chain_id: 101,\n instructions: [\n {\n program_id: \"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL\",\n discriminator: 1,\n discriminator_hex: \"1\",\n },\n {\n program_id: \"11111111111111111111111111111111\",\n discriminator: 2,\n discriminator_hex: \"2\",\n },\n {\n program_id: \"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4\",\n discriminator: 3.0753642362361016e18,\n discriminator_hex: \"2aade37a97cb17e0\",\n },\n {\n program_id: \"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4\",\n discriminator: 9.339575302786589e18,\n discriminator_hex: \"819cd641339b2148\",\n },\n { program_id: \"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr\" },\n {\n program_id: \"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL\",\n discriminator: 1,\n discriminator_hex: \"1\",\n },\n { program_id: \"3i5JeuZuUxeKtVysUnwQNGerJP2bSMX9fTFfS4Nxe3Br\" },\n {\n program_id: \"ComputeBudget111111111111111111111111111111\",\n discriminator: 2,\n discriminator_hex: \"2\",\n },\n {\n program_id: \"ComputeBudget111111111111111111111111111111\",\n discriminator: 3,\n discriminator_hex: \"3\",\n },\n {\n program_id: \"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\",\n discriminator: 3,\n discriminator_hex: \"3\",\n },\n {\n program_id: \"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\",\n discriminator: 17,\n discriminator_hex: \"11\",\n },\n { program_id: \"BrdgN2RPzEMWF96ZbnnJaUtQDQx7VRXYaHHbYCBvceWB\" },\n ],\n descriptors: [\n {\n program_id: \"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL\",\n discriminator_hex: \"1\",\n descriptor: makeRawDescriptor(\"atoken_1\", \"sig_atoken\"),\n },\n {\n program_id: \"11111111111111111111111111111111\",\n discriminator_hex: \"2\",\n descriptor: makeRawDescriptor(\"system_2\", \"sig_system\"),\n },\n {\n program_id: \"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4\",\n discriminator_hex: \"2aade37a97cb17e0\",\n descriptor: makeRawDescriptor(\"jup_route\", \"sig_jup_route\"),\n },\n {\n program_id: \"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4\",\n discriminator_hex: \"819cd641339b2148\",\n descriptor: makeRawDescriptor(\"jup_shared\", \"sig_jup_shared\"),\n },\n {\n program_id: \"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr\",\n descriptor: makeRawDescriptor(\"memo\", \"sig_memo\"),\n },\n {\n program_id: \"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL\",\n discriminator_hex: \"1\",\n descriptor: makeRawDescriptor(\"atoken_1\", \"sig_atoken\"),\n },\n {\n program_id: \"3i5JeuZuUxeKtVysUnwQNGerJP2bSMX9fTFfS4Nxe3Br\",\n descriptor: makeRawDescriptor(\"3i5jeu\", \"sig_3i5jeu\"),\n },\n {\n program_id: \"ComputeBudget111111111111111111111111111111\",\n discriminator_hex: \"2\",\n descriptor: makeRawDescriptor(\"cb_2\", \"sig_cb2\"),\n },\n {\n program_id: \"ComputeBudget111111111111111111111111111111\",\n discriminator_hex: \"3\",\n descriptor: makeRawDescriptor(\"cb_3\", \"sig_cb3\"),\n },\n {\n program_id: \"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\",\n discriminator_hex: \"3\",\n descriptor: makeRawDescriptor(\"tokenkeg_3\", \"sig_tk3\"),\n },\n {\n program_id: \"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\",\n discriminator_hex: \"11\",\n descriptor: makeRawDescriptor(\"tokenkeg_11\", \"sig_tk11\"),\n },\n {\n program_id: \"BrdgN2RPzEMWF96ZbnnJaUtQDQx7VRXYaHHbYCBvceWB\",\n descriptor: makeRawDescriptor(\"brdg\", \"sig_brdg\"),\n },\n ],\n };\n\n it(\"produces 11 unique descriptor keys (ATokenGP:1 appears twice but deduplicates)\", () => {\n const loader = makeLoader();\n const pluck = (loader as any).pluckTransactionData.bind(loader);\n\n const result: SolanaTransactionDescriptorList = pluck(realApiResponse);\n const keys = Object.keys(result);\n\n // 12 descriptors but ATokenGP:1 appears twice -> 11 unique keys\n expect(keys).toHaveLength(11);\n });\n\n it(\"creates distinct keys for same program_id with different discriminators\", () => {\n const loader = makeLoader();\n const pluck = (loader as any).pluckTransactionData.bind(loader);\n\n const result: SolanaTransactionDescriptorList = pluck(realApiResponse);\n\n // JUP6 has two different discriminators -> two distinct entries\n expect(\n result[\"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4:2aade37a97cb17e0\"]\n ?.data,\n ).toBe(\"jup_route\");\n expect(\n result[\"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4:819cd641339b2148\"]\n ?.data,\n ).toBe(\"jup_shared\");\n\n // ComputeBudget has discriminator 2 and 3\n expect(\n result[\"ComputeBudget111111111111111111111111111111:2\"]?.data,\n ).toBe(\"cb_2\");\n expect(\n result[\"ComputeBudget111111111111111111111111111111:3\"]?.data,\n ).toBe(\"cb_3\");\n\n // TokenkegQ has discriminator 3 and 11\n expect(\n result[\"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA:3\"]?.data,\n ).toBe(\"tokenkeg_3\");\n expect(\n result[\"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA:11\"]?.data,\n ).toBe(\"tokenkeg_11\");\n });\n\n it(\"uses :0 suffix for programs without a discriminator\", () => {\n const loader = makeLoader();\n const pluck = (loader as any).pluckTransactionData.bind(loader);\n\n const result: SolanaTransactionDescriptorList = pluck(realApiResponse);\n\n expect(result[\"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr:\"]?.data).toBe(\n \"memo\",\n );\n expect(\n result[\"3i5JeuZuUxeKtVysUnwQNGerJP2bSMX9fTFfS4Nxe3Br:\"]?.data,\n ).toBe(\"3i5jeu\");\n expect(\n result[\"BrdgN2RPzEMWF96ZbnnJaUtQDQx7VRXYaHHbYCBvceWB:\"]?.data,\n ).toBe(\"brdg\");\n });\n\n it(\"extracts 12 instruction metadata entries preserving order and discriminators\", () => {\n const loader = makeLoader();\n const extract = (loader as any).extractInstructionsMeta.bind(loader);\n\n const result = extract(realApiResponse);\n\n expect(result).toHaveLength(12);\n\n // First: ATokenGP with discriminator\n expect(result[0]).toEqual({\n program_id: \"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL\",\n discriminator_hex: \"1\",\n });\n // JUP6 route (8-byte discriminator)\n expect(result[2]).toEqual({\n program_id: \"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4\",\n discriminator_hex: \"2aade37a97cb17e0\",\n });\n // JUP6 shared (8-byte discriminator)\n expect(result[3]).toEqual({\n program_id: \"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4\",\n discriminator_hex: \"819cd641339b2148\",\n });\n // Memo: no discriminator\n expect(result[4]).toEqual({\n program_id: \"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr\",\n });\n // BrdgN2: no discriminator (last entry)\n expect(result[11]).toEqual({\n program_id: \"BrdgN2RPzEMWF96ZbnnJaUtQDQx7VRXYaHHbYCBvceWB\",\n });\n });\n\n it(\"load returns full payload with descriptors and instructions from real API response\", async () => {\n const loader = makeLoader();\n\n vi.spyOn(\n mockDataSource,\n \"getTransactionDescriptorsPayload\",\n ).mockResolvedValue(Right(realApiResponse));\n\n const input = { templateId: \"4c694669\", deviceModelId: \"nanoS\" as any };\n const result = await loader.load(input);\n\n expect(result).toHaveLength(1);\n expect(result[0]).toMatchObject({\n type: ClearSignContextType.SOLANA_LIFI,\n payload: {\n descriptors: expect.objectContaining({\n \"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4:2aade37a97cb17e0\":\n expect.objectContaining({ data: \"jup_route\" }),\n \"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4:819cd641339b2148\":\n expect.objectContaining({ data: \"jup_shared\" }),\n }),\n instructions: expect.arrayContaining([\n expect.objectContaining({\n program_id: \"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4\",\n discriminator_hex: \"2aade37a97cb17e0\",\n }),\n expect.objectContaining({\n program_id: \"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4\",\n discriminator_hex: \"819cd641339b2148\",\n }),\n ]),\n },\n });\n\n expect(Object.keys((result[0] as any).payload.descriptors)).toHaveLength(\n 11,\n );\n exp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B,CACtB,WAAY,8CACZ,kBAAmB,kBACrB,CAAC,CACH,CAAC,CACH,CACF,CAAC,KAED,UAAO,OAAO,KAAMA,EAAO,CAAC,EAAU,QAAQ,WAAW,CAAC,EAAE,aAC1D,EACF,KACA,UAAQA,EAAO,CAAC,EAAU,QAAQ,YAAY,EAAE,aAAa,EAAE,CACjE,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["import_purify_ts", "import_vitest", "import_ClearSignContext", "import_LifiContextLoader", "mockLoggerFactory", "mockCertificate", "mockConfig", "mockDataSource", "mockCertificateLoader", "makeRawDescriptor", "data", "sig", "makeResolvedDescriptor", "responseDescriptorsArray", "expectedPlucked", "txDescriptorsResponse", "makeLoader", "loader", "error", "input", "result", "realApiResponse", "keys"]
4
+ "sourcesContent": ["/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { Left, Right } from \"purify-ts\";\nimport { beforeEach, describe, expect, it, vi } from \"vitest\";\n\nimport { type ContextModuleServiceConfig } from \"@/config/model/ContextModuleConfig\";\nimport { type PkiCertificateLoader } from \"@/modules/multichain/pki/domain/PkiCertificateLoader\";\nimport {\n type GetTransactionDescriptorsResponse,\n type LifiDataSource,\n} from \"@/modules/solana/lifi/data/LifiDataSource\";\nimport {\n type SolanaTransactionDescriptorList,\n type SolanaTransactionDescriptorRaw,\n} from \"@/modules/solana/model/SolanaContextTypes\";\nimport { type SolanaTransactionDescriptor } from \"@/modules/solana/model/SolanaPayloads\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\n\nimport { LifiContextLoader } from \"./LifiContextLoader\";\n\nconst mockLoggerFactory = () => ({\n debug: vi.fn(),\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n subscribers: [],\n});\n\nconst mockCertificate = {\n keyUsageNumber: 13,\n payload: new Uint8Array([0x01, 0x02]),\n};\n\nconst mockConfig = {\n cal: {\n url: \"https://global.api.prd.ledger.com/cal/v1\",\n mode: \"test\",\n branch: \"main\",\n },\n} as ContextModuleServiceConfig;\n\ndescribe(\"LifiContextLoader\", () => {\n let mockDataSource: LifiDataSource;\n let mockCertificateLoader: PkiCertificateLoader;\n\n const makeRawDescriptor = (\n data: string,\n sig = \"deadbeef\",\n ): SolanaTransactionDescriptorRaw => ({\n data,\n descriptorType: \"swap_template\",\n descriptorVersion: \"v1\",\n signatures: { test: sig, prod: `prod_${sig}` },\n });\n\n const makeResolvedDescriptor = (\n data: string,\n sig = \"deadbeef\",\n ): SolanaTransactionDescriptor => ({\n data,\n descriptorType: \"swap_template\",\n descriptorVersion: \"v1\",\n signature: sig,\n });\n\n const responseDescriptorsArray: GetTransactionDescriptorsResponse[\"descriptors\"] =\n [\n {\n program_id: \"SomeProgram\",\n discriminator_hex: \"1\",\n descriptor: makeRawDescriptor(\"abc123\"),\n },\n {\n program_id: \"AnotherProgram\",\n // discriminator_hex intentionally omitted -> defaults to \"\"\n descriptor: makeRawDescriptor(\"def456\"),\n },\n ];\n\n const expectedPlucked: SolanaTransactionDescriptorList = {\n \"SomeProgram:1\": [makeResolvedDescriptor(\"abc123\")],\n \"AnotherProgram:\": [makeResolvedDescriptor(\"def456\")],\n };\n\n const responseInstructionsArray: GetTransactionDescriptorsResponse[\"instructions\"] =\n [\n {\n program_id: \"SomeProgram\",\n discriminator: 1,\n discriminator_hex: \"1\",\n },\n {\n program_id: \"AnotherProgram\",\n // discriminator_hex intentionally omitted\n },\n ];\n\n const txDescriptorsResponse: GetTransactionDescriptorsResponse = {\n id: \"tpl-1\",\n chain_id: 101,\n instructions: responseInstructionsArray,\n descriptors: responseDescriptorsArray,\n };\n\n beforeEach(() => {\n vi.restoreAllMocks();\n mockDataSource = {\n getTransactionDescriptorsPayload: vi.fn(),\n } as unknown as LifiDataSource;\n mockCertificateLoader = {\n loadCertificate: vi.fn().mockResolvedValue(mockCertificate),\n } as unknown as PkiCertificateLoader;\n });\n\n const makeLoader = () =>\n new LifiContextLoader(\n mockDataSource,\n mockConfig,\n mockCertificateLoader,\n mockLoggerFactory,\n );\n\n describe(\"canHandle\", () => {\n it(\"returns true when templateId is provided and SOLANA_LIFI is in expectedTypes\", () => {\n const loader = makeLoader();\n\n expect(\n loader.canHandle(\n {\n templateId: \"tpl-123\",\n deviceModelId: \"nanoS\" as any,\n },\n [ClearSignContextType.SOLANA_LIFI],\n ),\n ).toBe(true);\n });\n\n it(\"returns false when SOLANA_LIFI is not in expectedTypes\", () => {\n const loader = makeLoader();\n\n expect(\n loader.canHandle({ templateId: \"tpl-123\" } as any, [\n ClearSignContextType.SOLANA_TOKEN,\n ]),\n ).toBe(false);\n });\n\n it(\"returns false when templateId is missing or falsy\", () => {\n const loader = makeLoader();\n\n expect(\n loader.canHandle({ templateId: \"\" } as any, [\n ClearSignContextType.SOLANA_LIFI,\n ]),\n ).toBe(false);\n expect(\n loader.canHandle({ templateId: undefined } as any, [\n ClearSignContextType.SOLANA_LIFI,\n ]),\n ).toBe(false);\n expect(\n loader.canHandle({} as any, [ClearSignContextType.SOLANA_LIFI]),\n ).toBe(false);\n });\n });\n\n describe(\"load\", () => {\n it(\"returns an array with an error when datasource returns Left(error)\", async () => {\n const loader = makeLoader();\n const error = new Error(\"boom\");\n\n vi.spyOn(\n mockDataSource,\n \"getTransactionDescriptorsPayload\",\n ).mockResolvedValue(Left(error));\n\n const input = { templateId: \"tpl-err\", deviceModelId: \"nanoS\" as any };\n const result = await loader.load(input);\n\n expect(\n mockDataSource.getTransactionDescriptorsPayload,\n ).toHaveBeenCalledWith({\n templateId: \"tpl-err\",\n });\n\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error,\n },\n ]);\n });\n\n it(\"returns SOLANA_LIFI array with plucked descriptors and certificate when datasource returns Right(value)\", async () => {\n const loader = makeLoader();\n\n vi.spyOn(\n mockDataSource,\n \"getTransactionDescriptorsPayload\",\n ).mockResolvedValue(Right(txDescriptorsResponse));\n\n const input = { templateId: \"tpl-ok\", deviceModelId: \"nanoS\" as any };\n const result = await loader.load(input);\n\n expect(\n mockDataSource.getTransactionDescriptorsPayload,\n ).toHaveBeenCalledWith({\n templateId: \"tpl-ok\",\n });\n\n expect(mockCertificateLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: \"swap_template_key\",\n keyUsage: \"swap_template\",\n targetDevice: \"nanoS\",\n });\n\n expect(result).toEqual([\n {\n type: ClearSignContextType.SOLANA_LIFI,\n payload: {\n descriptors: expectedPlucked,\n instructions: [\n { program_id: \"SomeProgram\", discriminator_hex: \"1\" },\n { program_id: \"AnotherProgram\" },\n ],\n },\n certificate: mockCertificate,\n },\n ]);\n });\n });\n\n describe(\"pluckTransactionData (private)\", () => {\n it(\"returns a map keyed by `${program_id}:${discriminator_hex ?? '0'}`\", () => {\n const loader = makeLoader();\n const pluck = (loader as any).pluckTransactionData.bind(loader);\n\n const result: SolanaTransactionDescriptorList = pluck(\n txDescriptorsResponse,\n );\n\n expect(result).toEqual(expectedPlucked);\n });\n });\n\n describe(\"extractInstructionsMeta (private)\", () => {\n it(\"returns instruction metadata from the API response\", () => {\n const loader = makeLoader();\n const extract = (loader as any).extractInstructionsMeta.bind(loader);\n\n const result = extract(txDescriptorsResponse);\n\n expect(result).toEqual([\n { program_id: \"SomeProgram\", discriminator_hex: \"1\" },\n { program_id: \"AnotherProgram\" },\n ]);\n });\n\n it(\"returns empty array when instructions are missing\", () => {\n const loader = makeLoader();\n const extract = (loader as any).extractInstructionsMeta.bind(loader);\n\n const result = extract({\n ...txDescriptorsResponse,\n instructions: undefined,\n });\n\n expect(result).toEqual([]);\n });\n });\n\n describe(\"pluckTransactionData mode resolution (private)\", () => {\n it(\"resolves signature using config.cal.mode\", () => {\n const loader = makeLoader();\n const pluck = (loader as any).pluckTransactionData.bind(loader);\n\n const result: SolanaTransactionDescriptorList = pluck(\n txDescriptorsResponse,\n );\n\n expect(result[\"SomeProgram:1\"]?.[0]?.signature).toBe(\"deadbeef\");\n });\n });\n\n describe(\"duplicate discriminator handling (private)\", () => {\n it(\"collects both descriptors into an array when same (program_id, discriminator_hex) appears twice\", () => {\n // Models the LiFi CAL PR fix: System Program Transfer has two descriptors \u2014\n // one for the transfer amount and one for fees (distinguished by capped_bps).\n const loader = makeLoader();\n const pluck = (loader as any).pluckTransactionData.bind(loader);\n\n const response: GetTransactionDescriptorsResponse = {\n id: \"dup-test\",\n chain_id: 101,\n instructions: [\n {\n program_id: \"11111111111111111111111111111111\",\n discriminator: 2,\n discriminator_hex: \"02\",\n },\n {\n program_id: \"11111111111111111111111111111111\",\n discriminator: 2,\n discriminator_hex: \"02\",\n },\n ],\n descriptors: [\n {\n program_id: \"11111111111111111111111111111111\",\n discriminator_hex: \"02\",\n has_basis_point: false,\n descriptor: makeRawDescriptor(\n \"transfer_descriptor\",\n \"sig_transfer\",\n ),\n },\n {\n program_id: \"11111111111111111111111111111111\",\n discriminator_hex: \"02\",\n has_basis_point: true,\n descriptor: makeRawDescriptor(\"fee_descriptor\", \"sig_fee\"),\n },\n ],\n };\n\n const result: SolanaTransactionDescriptorList = pluck(response);\n\n expect(Object.keys(result)).toHaveLength(1);\n expect(result[\"11111111111111111111111111111111:02\"]).toHaveLength(2);\n expect(result[\"11111111111111111111111111111111:02\"]?.[0]?.data).toBe(\n \"transfer_descriptor\",\n );\n expect(\n result[\"11111111111111111111111111111111:02\"]?.[0]?.has_basis_point,\n ).toBe(false);\n expect(result[\"11111111111111111111111111111111:02\"]?.[1]?.data).toBe(\n \"fee_descriptor\",\n );\n expect(\n result[\"11111111111111111111111111111111:02\"]?.[1]?.has_basis_point,\n ).toBe(true);\n });\n });\n\n describe(\"real CAL payload (LiFi template 4c694669)\", () => {\n const realApiResponse: GetTransactionDescriptorsResponse = {\n id: \"4c694669\",\n chain_id: 101,\n instructions: [\n {\n program_id: \"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL\",\n discriminator: 1,\n discriminator_hex: \"1\",\n },\n {\n program_id: \"11111111111111111111111111111111\",\n discriminator: 2,\n discriminator_hex: \"2\",\n },\n {\n program_id: \"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4\",\n discriminator: 3.0753642362361016e18,\n discriminator_hex: \"2aade37a97cb17e0\",\n },\n {\n program_id: \"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4\",\n discriminator: 9.339575302786589e18,\n discriminator_hex: \"819cd641339b2148\",\n },\n { program_id: \"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr\" },\n {\n program_id: \"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL\",\n discriminator: 1,\n discriminator_hex: \"1\",\n },\n { program_id: \"3i5JeuZuUxeKtVysUnwQNGerJP2bSMX9fTFfS4Nxe3Br\" },\n {\n program_id: \"ComputeBudget111111111111111111111111111111\",\n discriminator: 2,\n discriminator_hex: \"2\",\n },\n {\n program_id: \"ComputeBudget111111111111111111111111111111\",\n discriminator: 3,\n discriminator_hex: \"3\",\n },\n {\n program_id: \"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\",\n discriminator: 3,\n discriminator_hex: \"3\",\n },\n {\n program_id: \"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\",\n discriminator: 17,\n discriminator_hex: \"11\",\n },\n { program_id: \"BrdgN2RPzEMWF96ZbnnJaUtQDQx7VRXYaHHbYCBvceWB\" },\n ],\n descriptors: [\n {\n program_id: \"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL\",\n discriminator_hex: \"1\",\n descriptor: makeRawDescriptor(\"atoken_1\", \"sig_atoken\"),\n },\n {\n program_id: \"11111111111111111111111111111111\",\n discriminator_hex: \"2\",\n descriptor: makeRawDescriptor(\"system_2\", \"sig_system\"),\n },\n {\n program_id: \"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4\",\n discriminator_hex: \"2aade37a97cb17e0\",\n descriptor: makeRawDescriptor(\"jup_route\", \"sig_jup_route\"),\n },\n {\n program_id: \"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4\",\n discriminator_hex: \"819cd641339b2148\",\n descriptor: makeRawDescriptor(\"jup_shared\", \"sig_jup_shared\"),\n },\n {\n program_id: \"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr\",\n descriptor: makeRawDescriptor(\"memo\", \"sig_memo\"),\n },\n {\n program_id: \"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL\",\n discriminator_hex: \"1\",\n descriptor: makeRawDescriptor(\"atoken_1\", \"sig_atoken\"),\n },\n {\n program_id: \"3i5JeuZuUxeKtVysUnwQNGerJP2bSMX9fTFfS4Nxe3Br\",\n descriptor: makeRawDescriptor(\"3i5jeu\", \"sig_3i5jeu\"),\n },\n {\n program_id: \"ComputeBudget111111111111111111111111111111\",\n discriminator_hex: \"2\",\n descriptor: makeRawDescriptor(\"cb_2\", \"sig_cb2\"),\n },\n {\n program_id: \"ComputeBudget111111111111111111111111111111\",\n discriminator_hex: \"3\",\n descriptor: makeRawDescriptor(\"cb_3\", \"sig_cb3\"),\n },\n {\n program_id: \"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\",\n discriminator_hex: \"3\",\n descriptor: makeRawDescriptor(\"tokenkeg_3\", \"sig_tk3\"),\n },\n {\n program_id: \"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\",\n discriminator_hex: \"11\",\n descriptor: makeRawDescriptor(\"tokenkeg_11\", \"sig_tk11\"),\n },\n {\n program_id: \"BrdgN2RPzEMWF96ZbnnJaUtQDQx7VRXYaHHbYCBvceWB\",\n descriptor: makeRawDescriptor(\"brdg\", \"sig_brdg\"),\n },\n ],\n };\n\n it(\"produces 11 unique descriptor keys (ATokenGP:1 appears twice -> array of 2)\", () => {\n const loader = makeLoader();\n const pluck = (loader as any).pluckTransactionData.bind(loader);\n\n const result: SolanaTransactionDescriptorList = pluck(realApiResponse);\n const keys = Object.keys(result);\n\n // 12 descriptors but ATokenGP:1 appears twice -> 11 unique keys, ATokenGP:1 has 2 entries\n expect(keys).toHaveLength(11);\n expect(\n result[\"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL:1\"],\n ).toHaveLength(2);\n });\n\n it(\"creates distinct keys for same program_id with different discriminators\", () => {\n const loader = makeLoader();\n const pluck = (loader as any).pluckTransactionData.bind(loader);\n\n const result: SolanaTransactionDescriptorList = pluck(realApiResponse);\n\n // JUP6 has two different discriminators -> two distinct entries\n expect(\n result[\n \"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4:2aade37a97cb17e0\"\n ]?.[0]?.data,\n ).toBe(\"jup_route\");\n expect(\n result[\n \"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4:819cd641339b2148\"\n ]?.[0]?.data,\n ).toBe(\"jup_shared\");\n\n // ComputeBudget has discriminator 2 and 3\n expect(\n result[\"ComputeBudget111111111111111111111111111111:2\"]?.[0]?.data,\n ).toBe(\"cb_2\");\n expect(\n result[\"ComputeBudget111111111111111111111111111111:3\"]?.[0]?.data,\n ).toBe(\"cb_3\");\n\n // TokenkegQ has discriminator 3 and 11\n expect(\n result[\"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA:3\"]?.[0]?.data,\n ).toBe(\"tokenkeg_3\");\n expect(\n result[\"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA:11\"]?.[0]?.data,\n ).toBe(\"tokenkeg_11\");\n });\n\n it(\"uses :0 suffix for programs without a discriminator\", () => {\n const loader = makeLoader();\n const pluck = (loader as any).pluckTransactionData.bind(loader);\n\n const result: SolanaTransactionDescriptorList = pluck(realApiResponse);\n\n expect(\n result[\"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr:\"]?.[0]?.data,\n ).toBe(\"memo\");\n expect(\n result[\"3i5JeuZuUxeKtVysUnwQNGerJP2bSMX9fTFfS4Nxe3Br:\"]?.[0]?.data,\n ).toBe(\"3i5jeu\");\n expect(\n result[\"BrdgN2RPzEMWF96ZbnnJaUtQDQx7VRXYaHHbYCBvceWB:\"]?.[0]?.data,\n ).toBe(\"brdg\");\n });\n\n it(\"extracts 12 instruction metadata entries preserving order and discriminators\", () => {\n const loader = makeLoader();\n const extract = (loader as any).extractInstructionsMeta.bind(loader);\n\n const result = extract(realApiResponse);\n\n expect(result).toHaveLength(12);\n\n // First: ATokenGP with discriminator\n expect(result[0]).toEqual({\n program_id: \"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL\",\n discriminator_hex: \"1\",\n });\n // JUP6 route (8-byte discriminator)\n expect(result[2]).toEqual({\n program_id: \"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4\",\n discriminator_hex: \"2aade37a97cb17e0\",\n });\n // JUP6 shared (8-byte discriminator)\n expect(result[3]).toEqual({\n program_id: \"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4\",\n discriminator_hex: \"819cd641339b2148\",\n });\n // Memo: no discriminator\n expect(result[4]).toEqual({\n program_id: \"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr\",\n });\n // BrdgN2: no discriminator (last entry)\n expect(result[11]).toEqual({\n program_id: \"BrdgN2RPzEMWF96ZbnnJaUtQDQx7VRXYaHHbYCBvceWB\",\n });\n });\n\n it(\"load returns full payload with descriptors and instructions from real API response\", async () => {\n const loader = makeLoader();\n\n vi.spyOn(\n mockDataSource,\n \"getTransactionDescriptorsPayload\",\n ).mockResolvedValue(Right(realApiResponse));\n\n const input = { templateId: \"4c694669\", deviceModelId: \"nanoS\" as any };\n const result = await loader.load(input);\n\n expect(result).toHaveLength(1);\n expect(result[0]).toMatchObject({\n type: ClearSignContextType.SOLANA_LIFI,\n payload: {\n descriptors: expect.objectContaining({\n \"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4:2aade37a97cb17e0\":\n expect.arrayContaining([\n expect.objectContaining({ data: \"jup_route\" }),\n ]),\n \"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4:819cd641339b2148\":\n expect.arrayContaining([\n expect.objectContaining({ data: \"jup_shared\" }),\n ]),\n }),\n instructions: expect.arrayContaining([\n expect.objectContaining({\n program_id: \"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4\",\n discriminator_hex: \"2aade37a97cb17e0\",\n }),\n expect.objectContaining({\n program_id: \"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4\",\n discriminator_hex: \"819cd641339b2148\",\n }),\n ]),\n },\n });\n\n expect(Object.keys((result[0] as any).payload.descriptors)).toHaveLength(\n 11,\n );\n expect((result[0] as any).payload.instructions).toHaveLength(12);\n });\n });\n});\n"],
5
+ "mappings": "aAIA,IAAAA,EAA4B,qBAC5BC,EAAqD,kBAarDC,EAAqC,2CAErCC,EAAkC,+BAElC,MAAMC,EAAoB,KAAO,CAC/B,MAAO,KAAG,GAAG,EACb,KAAM,KAAG,GAAG,EACZ,KAAM,KAAG,GAAG,EACZ,MAAO,KAAG,GAAG,EACb,YAAa,CAAC,CAChB,GAEMC,EAAkB,CACtB,eAAgB,GAChB,QAAS,IAAI,WAAW,CAAC,EAAM,CAAI,CAAC,CACtC,EAEMC,EAAa,CACjB,IAAK,CACH,IAAK,2CACL,KAAM,OACN,OAAQ,MACV,CACF,KAEA,YAAS,oBAAqB,IAAM,CAClC,IAAIC,EACAC,EAEJ,MAAMC,EAAoB,CACxBC,EACAC,EAAM,cAC8B,CACpC,KAAAD,EACA,eAAgB,gBAChB,kBAAmB,KACnB,WAAY,CAAE,KAAMC,EAAK,KAAM,QAAQA,CAAG,EAAG,CAC/C,GAE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C,EAE1C,MAAMJ,EAAQ,CAAE,WAAY,WAAY,cAAe,OAAe,EAChEC,EAAS,MAAMH,EAAO,KAAKE,CAAK,KAEtC,UAAOC,CAAM,EAAE,aAAa,CAAC,KAC7B,UAAOA,EAAO,CAAC,CAAC,EAAE,cAAc,CAC9B,KAAM,uBAAqB,YAC3B,QAAS,CACP,YAAa,SAAO,iBAAiB,CACnC,+DACE,SAAO,gBAAgB,CACrB,SAAO,iBAAiB,CAAE,KAAM,WAAY,CAAC,CAC/C,CAAC,EACH,+DACE,SAAO,gBAAgB,CACrB,SAAO,iBAAiB,CAAE,KAAM,YAAa,CAAC,CAChD,CAAC,CACL,CAAC,EACD,aAAc,SAAO,gBAAgB,CACnC,SAAO,iBAAiB,CACtB,WAAY,8CACZ,kBAAmB,kBACrB,CAAC,EACD,SAAO,iBAAiB,CACtB,WAAY,8CACZ,kBAAmB,kBACrB,CAAC,CACH,CAAC,CACH,CACF,CAAC,KAED,UAAO,OAAO,KAAMA,EAAO,CAAC,EAAU,QAAQ,WAAW,CAAC,EAAE,aAC1D,EACF,KACA,UAAQA,EAAO,CAAC,EAAU,QAAQ,YAAY,EAAE,aAAa,EAAE,CACjE,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["import_purify_ts", "import_vitest", "import_ClearSignContext", "import_LifiContextLoader", "mockLoggerFactory", "mockCertificate", "mockConfig", "mockDataSource", "mockCertificateLoader", "makeRawDescriptor", "data", "sig", "makeResolvedDescriptor", "responseDescriptorsArray", "expectedPlucked", "txDescriptorsResponse", "makeLoader", "loader", "error", "input", "result", "pluck", "response", "realApiResponse", "keys"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/modules/solana/model/SolanaContextTypes.ts"],
4
- "sourcesContent": ["import { type SolanaTransactionDescriptor } from \"@/modules/solana/model/SolanaPayloads\";\nimport {\n type ClearSignContextError,\n type ClearSignContextSuccess,\n type ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\n\nexport type SolanaTransactionDescriptorRaw = {\n data: string;\n descriptorType: string;\n descriptorVersion: string;\n signatures: {\n prod?: string;\n test?: string;\n };\n};\n\nexport type SolanaLifiDescriptorEntry = {\n program_id: string;\n discriminator_hex?: string;\n descriptor: SolanaTransactionDescriptorRaw;\n};\n\nexport type GetTransactionDescriptorsResponse = {\n id: string;\n chain_id: number;\n instructions: Array<{\n program_id: string;\n discriminator?: number;\n discriminator_hex?: string;\n }>;\n descriptors: SolanaLifiDescriptorEntry[];\n};\n\nexport type SolanaTransactionDescriptorList = Record<\n string,\n SolanaTransactionDescriptor\n>;\n\n// The signer registry (`provideContextRegistry.ts`) uses a required mapped\n// type over this union, so every member listed here MUST have a matching\n// provide handler in the signer. The generic clear-signing types below are\n// declared together with their handlers\nexport type SolanaContextSuccessType =\n | ClearSignContextType.SOLANA_TOKEN\n | ClearSignContextType.SOLANA_LIFI\n | ClearSignContextType.SOLANA_TRANSACTION_CHECK\n | ClearSignContextType.SOLANA_INSTRUCTION_INFO\n | ClearSignContextType.SOLANA_ENUM_VARIANT\n | ClearSignContextType.SOLANA_TOKEN_INFO\n | ClearSignContextType.SOLANA_TOKEN_ACCOUNT_STATE\n | ClearSignContextType.SOLANA_ALT_RESOLUTION\n | ClearSignContextType.SOLANA_TRUSTED_NAME\n | ClearSignContextType.SOLANA_BASIC_TRUSTED_NAME;\n\nexport type SolanaContextSuccess<\n T extends SolanaContextSuccessType = SolanaContextSuccessType,\n> = ClearSignContextSuccess<T>;\n\nexport type SolanaContextError = ClearSignContextError;\n\nexport type SolanaContext = SolanaContextSuccess | SolanaContextError;\n\nexport type SolanaTokenContextSuccess =\n ClearSignContextSuccess<ClearSignContextType.SOLANA_TOKEN>;\n\nexport type SolanaLifiContextSuccess =\n ClearSignContextSuccess<ClearSignContextType.SOLANA_LIFI>;\n\nexport type SolanaTransactionCheckContextSuccess =\n ClearSignContextSuccess<ClearSignContextType.SOLANA_TRANSACTION_CHECK>;\n\nexport type SolanaInstructionInfoContextSuccess =\n ClearSignContextSuccess<ClearSignContextType.SOLANA_INSTRUCTION_INFO>;\n\nexport type SolanaEnumVariantContextSuccess =\n ClearSignContextSuccess<ClearSignContextType.SOLANA_ENUM_VARIANT>;\n\nexport type SolanaTokenInfoContextSuccess =\n ClearSignContextSuccess<ClearSignContextType.SOLANA_TOKEN_INFO>;\n\nexport type SolanaTokenAccountStateContextSuccess =\n ClearSignContextSuccess<ClearSignContextType.SOLANA_TOKEN_ACCOUNT_STATE>;\n\nexport type SolanaAltResolutionContextSuccess =\n ClearSignContextSuccess<ClearSignContextType.SOLANA_ALT_RESOLUTION>;\n\nexport type SolanaTrustedNameContextSuccess =\n ClearSignContextSuccess<ClearSignContextType.SOLANA_TRUSTED_NAME>;\n\nexport type SolanaBasicTrustedNameContextSuccess =\n ClearSignContextSuccess<ClearSignContextType.SOLANA_BASIC_TRUSTED_NAME>;\n\nexport type SolanaTokenContextResult =\n | SolanaTokenContextSuccess\n | SolanaContextError;\n\nexport type SolanaLifiContextResult =\n | SolanaLifiContextSuccess\n | SolanaContextError;\n\nexport type SolanaTransactionCheckContextResult =\n | SolanaTransactionCheckContextSuccess\n | SolanaContextError;\n\nexport type LoaderResult =\n | SolanaTokenContextResult\n | SolanaLifiContextResult\n | SolanaTransactionCheckContextResult;\n"],
4
+ "sourcesContent": ["import { type SolanaTransactionDescriptor } from \"@/modules/solana/model/SolanaPayloads\";\nimport {\n type ClearSignContextError,\n type ClearSignContextSuccess,\n type ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\n\nexport type SolanaTransactionDescriptorRaw = {\n data: string;\n descriptorType: string;\n descriptorVersion: string;\n signatures: {\n prod?: string;\n test?: string;\n };\n};\n\nexport type SolanaLifiDescriptorEntry = {\n program_id: string;\n discriminator_hex?: string;\n has_basis_point?: boolean;\n descriptor: SolanaTransactionDescriptorRaw;\n};\n\nexport type GetTransactionDescriptorsResponse = {\n id: string;\n chain_id: number;\n instructions: Array<{\n program_id: string;\n discriminator?: number;\n discriminator_hex?: string;\n amount?: { capped_bps?: number };\n }>;\n descriptors: SolanaLifiDescriptorEntry[];\n};\n\nexport type SolanaTransactionDescriptorList = Record<\n string,\n SolanaTransactionDescriptor[]\n>;\n\n// The signer registry (`provideContextRegistry.ts`) uses a required mapped\n// type over this union, so every member listed here MUST have a matching\n// provide handler in the signer. The generic clear-signing types below are\n// declared together with their handlers\nexport type SolanaContextSuccessType =\n | ClearSignContextType.SOLANA_TOKEN\n | ClearSignContextType.SOLANA_LIFI\n | ClearSignContextType.SOLANA_TRANSACTION_CHECK\n | ClearSignContextType.SOLANA_INSTRUCTION_INFO\n | ClearSignContextType.SOLANA_ENUM_VARIANT\n | ClearSignContextType.SOLANA_TOKEN_INFO\n | ClearSignContextType.SOLANA_TOKEN_ACCOUNT_STATE\n | ClearSignContextType.SOLANA_ALT_RESOLUTION\n | ClearSignContextType.SOLANA_TRUSTED_NAME\n | ClearSignContextType.SOLANA_BASIC_TRUSTED_NAME;\n\nexport type SolanaContextSuccess<\n T extends SolanaContextSuccessType = SolanaContextSuccessType,\n> = ClearSignContextSuccess<T>;\n\nexport type SolanaContextError = ClearSignContextError;\n\nexport type SolanaContext = SolanaContextSuccess | SolanaContextError;\n\nexport type SolanaTokenContextSuccess =\n ClearSignContextSuccess<ClearSignContextType.SOLANA_TOKEN>;\n\nexport type SolanaLifiContextSuccess =\n ClearSignContextSuccess<ClearSignContextType.SOLANA_LIFI>;\n\nexport type SolanaTransactionCheckContextSuccess =\n ClearSignContextSuccess<ClearSignContextType.SOLANA_TRANSACTION_CHECK>;\n\nexport type SolanaInstructionInfoContextSuccess =\n ClearSignContextSuccess<ClearSignContextType.SOLANA_INSTRUCTION_INFO>;\n\nexport type SolanaEnumVariantContextSuccess =\n ClearSignContextSuccess<ClearSignContextType.SOLANA_ENUM_VARIANT>;\n\nexport type SolanaTokenInfoContextSuccess =\n ClearSignContextSuccess<ClearSignContextType.SOLANA_TOKEN_INFO>;\n\nexport type SolanaTokenAccountStateContextSuccess =\n ClearSignContextSuccess<ClearSignContextType.SOLANA_TOKEN_ACCOUNT_STATE>;\n\nexport type SolanaAltResolutionContextSuccess =\n ClearSignContextSuccess<ClearSignContextType.SOLANA_ALT_RESOLUTION>;\n\nexport type SolanaTrustedNameContextSuccess =\n ClearSignContextSuccess<ClearSignContextType.SOLANA_TRUSTED_NAME>;\n\nexport type SolanaBasicTrustedNameContextSuccess =\n ClearSignContextSuccess<ClearSignContextType.SOLANA_BASIC_TRUSTED_NAME>;\n\nexport type SolanaTokenContextResult =\n | SolanaTokenContextSuccess\n | SolanaContextError;\n\nexport type SolanaLifiContextResult =\n | SolanaLifiContextSuccess\n | SolanaContextError;\n\nexport type SolanaTransactionCheckContextResult =\n | SolanaTransactionCheckContextSuccess\n | SolanaContextError;\n\nexport type LoaderResult =\n | SolanaTokenContextResult\n | SolanaLifiContextResult\n | SolanaTransactionCheckContextResult;\n"],
5
5
  "mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
6
6
  "names": ["SolanaContextTypes_exports", "__toCommonJS"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/modules/solana/model/SolanaPayloads.ts"],
4
- "sourcesContent": ["// Solana payload types \u2014 used both by Solana loaders and (type-only)\n// referenced by the shared ClearSignContext union for typed-payload variants.\n\nexport type SolanaTokenData = {\n solanaTokenDescriptor: {\n data: string;\n signature: string;\n };\n};\n\nexport type SolanaTransactionDescriptor = {\n data: string;\n descriptorType: string;\n descriptorVersion: string;\n signature: string;\n};\n\nexport type SolanaLifiInstructionMeta = {\n program_id: string;\n discriminator_hex?: string;\n};\n\nexport type SolanaLifiPayload = {\n descriptors: Record<string, SolanaTransactionDescriptor>;\n instructions: SolanaLifiInstructionMeta[];\n};\n\nexport type SolanaTransactionCheckPayload = {\n descriptor: string;\n};\n\n// --- Generic clear-signing payloads ---\n\n// CAL static descriptor payloads. `data` is the signed TLV (hex string);\n// `signature` is the resolved signature for the configured CAL signature\n// kind (`prod` | `test`).\n\nexport type SolanaSignedDescriptor = {\n data: string;\n signature: string;\n};\n\n/**\n * One enum-variant descriptor bundled with an instruction descriptor by CAL.\n * The signed TLV (`descriptor.data`) feeds the host-side type-pool decode\n * cache, `enumId`/`variantIndex` identify which variant it describes (and let\n * the host stream the selected variant's signed descriptor to the device).\n */\nexport type SolanaInstructionEnumVariant = {\n enumId: string;\n variantIndex: number;\n descriptor: SolanaSignedDescriptor;\n};\n\n/**\n * Payload for ClearSignContextType.SOLANA_INSTRUCTION_INFO.\n *\n * `instructionInfo` + `substructures` are the signed TLVs streamed to the\n * device, and `enumVariants` are the signed enum-variant descriptors CAL\n * bundles for the program's enums (used to build the host decode cache). The\n * remaining fields are CAL's decoded JSON consumed host-side by the\n * requirement builder.\n */\nexport type SolanaInstructionInfoPayload = {\n programId: string;\n discriminator: string;\n instructionInfo: SolanaSignedDescriptor;\n substructures: SolanaInstructionSubstructure[];\n enumVariants: SolanaInstructionEnumVariant[];\n idlDescriptor: {\n typePool: SolanaCalTypePoolEntry[];\n rootType: number;\n };\n mintAssociations: SolanaCalMintAssociation[];\n valueFlowPorts: SolanaCalValueFlowPort[];\n accountResets: SolanaCalAccountReset[];\n displayFields: SolanaCalDisplayField[];\n};\n\nexport enum SolanaInstructionSubstructureKind {\n DISPLAY_FIELD = 0x00,\n VALUE_FLOW_PORT = 0x01,\n HIDE_RULE = 0x02,\n ACCOUNT_RESET = 0x03,\n}\n\nexport type SolanaInstructionSubstructure = {\n kind: SolanaInstructionSubstructureKind;\n // TLV payload (hex string) for the substructure.\n data: string;\n};\n\n// --- Decoded CAL JSON (snake_case mirrors the CAL response) ---\n\nexport type SolanaCalValue = {\n source: string;\n /** ACCOUNT_PATH: index into the instruction's accounts. */\n account_index?: number;\n /** CONSTANT: hex-encoded bytes. */\n data?: string;\n /** ARGUMENT_PATH: decoded steps. */\n path?: { steps: number[] };\n};\n\nexport type SolanaCalTokenValue = {\n kind: string;\n value?: SolanaCalValue;\n account_index?: number;\n};\n\nexport type SolanaCalValueFlowPort = {\n /** Ordered candidate list (spec form). */\n account_indices?: number[];\n /** Single-account form currently emitted by CAL; treated as a 1-element list. */\n account_index?: number;\n optional_account_strategy?: string;\n token_value?: SolanaCalTokenValue;\n};\n\nexport type SolanaCalAccountReset = {\n account_index: number;\n require_pre_balance_zero?: boolean;\n};\n\nexport type SolanaCalDisplayField = {\n name?: string;\n param: { type: string; value?: SolanaCalValue; token?: SolanaCalValue };\n};\n\nexport type SolanaCalTypePoolEntry = {\n index: number;\n kind: string;\n refs?: number[];\n size?: number;\n encoding?: number;\n len_kind?: string;\n flag_kind?: string;\n sentinel?: string;\n disc_kind?: string;\n total_variants?: number;\n enum_id?: string;\n};\n\nexport type SolanaCalMintAssociation = {\n account_index: number;\n mint_index: number;\n};\n\n/**\n * Payload for ClearSignContextType.SOLANA_ENUM_VARIANT: one signed\n * ENUM_VARIANT descriptor for a `(programId, enumId, variantIndex)` triple.\n */\nexport type SolanaEnumVariantPayload = {\n programId: string;\n enumId: string;\n variantIndex: number;\n descriptor: SolanaSignedDescriptor;\n};\n\n/**\n * Payload for ClearSignContextType.SOLANA_TOKEN_INFO, keyed by mint pubkey.\n * Distinct from the legacy SOLANA_TOKEN context.\n */\nexport type SolanaTokenInfoPayload = {\n mint: string;\n descriptor: SolanaSignedDescriptor;\n};\n\n// --- Dynamic descriptor payloads (challenge-bound) ---\n//\n// Each payload carries the raw signed TLV bytes decoded from the backend's\n// hex `signedDescriptor`.\n\nexport type SolanaTokenAccountStatePayload = {\n descriptor: Uint8Array;\n};\n\nexport type SolanaAltResolutionPayload = {\n descriptor: Uint8Array;\n};\n\n// SOLANA_TRUSTED_NAME (generic flow, with 2-byte length prefix) is emitted by\n// SolanaTrustedNameContextLoader. SOLANA_BASIC_TRUSTED_NAME (basic flow, raw\n// bytes) is emitted by OwnerInfoContextLoader. Both carry `payload: Uint8Array`.\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uCAAAE,IAAA,eAAAC,EAAAH,GA+EO,IAAKE,OACVA,IAAA,cAAgB,GAAhB,gBACAA,IAAA,gBAAkB,GAAlB,kBACAA,IAAA,UAAY,GAAZ,YACAA,IAAA,cAAgB,GAAhB,gBAJUA,OAAA",
4
+ "sourcesContent": ["// Solana payload types \u2014 used both by Solana loaders and (type-only)\n// referenced by the shared ClearSignContext union for typed-payload variants.\n\nexport type SolanaTokenData = {\n solanaTokenDescriptor: {\n data: string;\n signature: string;\n };\n};\n\nexport type SolanaTransactionDescriptor = {\n data: string;\n descriptorType: string;\n descriptorVersion: string;\n signature: string;\n has_basis_point?: boolean;\n};\n\nexport type SolanaLifiInstructionMeta = {\n program_id: string;\n discriminator_hex?: string;\n has_basis_point?: boolean;\n};\n\nexport type SolanaLifiPayload = {\n descriptors: Record<string, SolanaTransactionDescriptor[]>;\n instructions: SolanaLifiInstructionMeta[];\n};\n\nexport type SolanaTransactionCheckPayload = {\n descriptor: string;\n};\n\n// --- Generic clear-signing payloads ---\n\n// CAL static descriptor payloads. `data` is the signed TLV (hex string);\n// `signature` is the resolved signature for the configured CAL signature\n// kind (`prod` | `test`).\n\nexport type SolanaSignedDescriptor = {\n data: string;\n signature: string;\n};\n\n/**\n * One enum-variant descriptor bundled with an instruction descriptor by CAL.\n * The signed TLV (`descriptor.data`) feeds the host-side type-pool decode\n * cache, `enumId`/`variantIndex` identify which variant it describes (and let\n * the host stream the selected variant's signed descriptor to the device).\n */\nexport type SolanaInstructionEnumVariant = {\n enumId: string;\n variantIndex: number;\n descriptor: SolanaSignedDescriptor;\n};\n\n/**\n * Payload for ClearSignContextType.SOLANA_INSTRUCTION_INFO.\n *\n * `instructionInfo` + `substructures` are the signed TLVs streamed to the\n * device, and `enumVariants` are the signed enum-variant descriptors CAL\n * bundles for the program's enums (used to build the host decode cache). The\n * remaining fields are CAL's decoded JSON consumed host-side by the\n * requirement builder.\n */\nexport type SolanaInstructionInfoPayload = {\n programId: string;\n discriminator: string;\n instructionInfo: SolanaSignedDescriptor;\n substructures: SolanaInstructionSubstructure[];\n enumVariants: SolanaInstructionEnumVariant[];\n idlDescriptor: {\n typePool: SolanaCalTypePoolEntry[];\n rootType: number;\n };\n mintAssociations: SolanaCalMintAssociation[];\n valueFlowPorts: SolanaCalValueFlowPort[];\n accountResets: SolanaCalAccountReset[];\n displayFields: SolanaCalDisplayField[];\n};\n\nexport enum SolanaInstructionSubstructureKind {\n DISPLAY_FIELD = 0x00,\n VALUE_FLOW_PORT = 0x01,\n HIDE_RULE = 0x02,\n ACCOUNT_RESET = 0x03,\n}\n\nexport type SolanaInstructionSubstructure = {\n kind: SolanaInstructionSubstructureKind;\n // TLV payload (hex string) for the substructure.\n data: string;\n};\n\n// --- Decoded CAL JSON (snake_case mirrors the CAL response) ---\n\nexport type SolanaCalValue = {\n source: string;\n /** ACCOUNT_PATH: index into the instruction's accounts. */\n account_index?: number;\n /** CONSTANT: hex-encoded bytes. */\n data?: string;\n /** ARGUMENT_PATH: decoded steps. */\n path?: { steps: number[] };\n};\n\nexport type SolanaCalTokenValue = {\n kind: string;\n value?: SolanaCalValue;\n account_index?: number;\n};\n\nexport type SolanaCalValueFlowPort = {\n /** Ordered candidate list of account indices (length 1 for a single-account port). */\n account_indices: number[];\n optional_account_strategy?: string;\n token_value: SolanaCalTokenValue;\n};\n\nexport type SolanaCalAccountReset = {\n account_index: number;\n require_pre_balance_zero?: boolean;\n};\n\nexport type SolanaCalDisplayField = {\n name?: string;\n param: { type: string; value?: SolanaCalValue; token?: SolanaCalValue };\n};\n\nexport type SolanaCalTypePoolEntry = {\n index: number;\n kind: string;\n refs?: number[];\n size?: number;\n encoding?: number;\n len_kind?: string;\n flag_kind?: string;\n sentinel?: string;\n disc_kind?: string;\n total_variants?: number;\n enum_id?: string;\n};\n\nexport type SolanaCalMintAssociation = {\n account_index: number;\n mint_index: number;\n};\n\n/**\n * Payload for ClearSignContextType.SOLANA_ENUM_VARIANT: one signed\n * ENUM_VARIANT descriptor for a `(programId, enumId, variantIndex)` triple.\n */\nexport type SolanaEnumVariantPayload = {\n programId: string;\n enumId: string;\n variantIndex: number;\n descriptor: SolanaSignedDescriptor;\n};\n\n/**\n * Payload for ClearSignContextType.SOLANA_TOKEN_INFO, keyed by mint pubkey.\n * Distinct from the legacy SOLANA_TOKEN context.\n */\nexport type SolanaTokenInfoPayload = {\n mint: string;\n descriptor: SolanaSignedDescriptor;\n};\n\n// --- Dynamic descriptor payloads (challenge-bound) ---\n//\n// Each payload carries the raw signed TLV bytes decoded from the backend's\n// hex `signedDescriptor`.\n\nexport type SolanaTokenAccountStatePayload = {\n descriptor: Uint8Array;\n};\n\nexport type SolanaAltResolutionPayload = {\n descriptor: Uint8Array;\n};\n\n// SOLANA_TRUSTED_NAME (generic flow, with 2-byte length prefix) is emitted by\n// SolanaTrustedNameContextLoader. SOLANA_BASIC_TRUSTED_NAME (basic flow, raw\n// bytes) is emitted by OwnerInfoContextLoader. Both carry `payload: Uint8Array`.\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uCAAAE,IAAA,eAAAC,EAAAH,GAiFO,IAAKE,OACVA,IAAA,cAAgB,GAAhB,gBACAA,IAAA,gBAAkB,GAAlB,kBACAA,IAAA,UAAY,GAAZ,YACAA,IAAA,cAAgB,GAAhB,gBAJUA,OAAA",
6
6
  "names": ["SolanaPayloads_exports", "__export", "SolanaInstructionSubstructureKind", "__toCommonJS"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var f=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var I=Object.prototype.hasOwnProperty;var C=(o,e)=>{for(var r in e)f(o,r,{get:e[r],enumerable:!0})},O=(o,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of g(e))!I.call(o,t)&&t!==r&&f(o,t,{get:()=>e[t],enumerable:!(n=p(e,t))||n.enumerable});return o};var D=o=>O(f({},"__esModule",{value:!0}),o),w=(o,e,r,n)=>{for(var t=n>1?void 0:n?p(e,r):e,i=o.length-1,s;i>=0;i--)(s=o[i])&&(t=(n?s(e,r,t):s(t))||t);return n&&t&&f(e,r,t),t},l=(o,e)=>(r,n)=>e(r,n,o);var k={};C(k,{HttpOwnerInfoDataSource:()=>c});module.exports=D(k);var m=require("@ledgerhq/device-management-kit"),d=require("inversify"),a=require("purify-ts"),S=require("../../../../config/di/configTypes"),h=require("../../../../shared/network/di/networkTypes");let c=class{constructor(e,r){this.config=e;this.http=r;if(!this.config.originToken)throw new Error("[ContextModule] - HttpOwnerInfoDataSource: origin token is required")}isSolanaSPLOwnerInfo(e){return typeof e!="object"||e===null?!1:typeof e.tokenAccount=="string"&&typeof e.owner=="string"&&typeof e.contract=="string"&&typeof e.signedDescriptor=="string"}async fetchAddressMetadata(e,r){try{const n=await this.http.get(`${this.config.metadataServiceDomain.url}/v2/solana/owner/${e}`,{params:{challenge:r}});return this.isSolanaSPLOwnerInfo(n)?(0,a.Right)(n):(0,a.Left)(new Error("[ContextModule] - HttpOwnerInfoDataSource: invalid fetchAddressMetadata response shape"))}catch{return(0,a.Left)(new Error("[ContextModule] - HttpOwnerInfoDataSource: Failed to fetch address metadata"))}}async computeAddressMetadata(e,r,n){try{const t=await this.http.get(`${this.config.metadataServiceDomain.url}/v2/solana/computed-token-account/${e}/${r}`,{params:{challenge:n}});return this.isSolanaSPLOwnerInfo(t)?(0,a.Right)(t):(0,a.Left)(new Error("[ContextModule] - HttpOwnerInfoDataSource: invalid computeAddressMetadata response shape"))}catch{return(0,a.Left)(new Error("[ContextModule] - HttpOwnerInfoDataSource: Failed to compute address metadata"))}}async getOwnerInfo(e){const{tokenAddress:r,challenge:n,createATA:t}=e;if(!n)return(0,a.Left)(new Error("[ContextModule] - HttpOwnerInfoDataSource: challenge is required"));let i;if(r)i=await this.fetchAddressMetadata(r,n);else if(t?.address&&t?.mintAddress)i=await this.computeAddressMetadata(t.address,t.mintAddress,n);else return(0,a.Left)(new Error("[ContextModule] - HttpOwnerInfoDataSource: either tokenAddress or valid createATA must be provided"));return i.chain(s=>{const u=(0,m.hexaStringToBuffer)(s.signedDescriptor);return u?(0,a.Right)({tlvDescriptor:u}):(0,a.Left)(new Error("[ContextModule] - HttpOwnerInfoDataSource: invalid base64 tlvDescriptor received"))})}};c=w([(0,d.injectable)(),l(0,(0,d.inject)(S.configTypes.Config)),l(1,(0,d.inject)(h.networkTypes.NetworkClient))],c);0&&(module.exports={HttpOwnerInfoDataSource});
1
+ "use strict";var f=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var I=Object.prototype.hasOwnProperty;var C=(o,e)=>{for(var r in e)f(o,r,{get:e[r],enumerable:!0})},O=(o,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of g(e))!I.call(o,t)&&t!==r&&f(o,t,{get:()=>e[t],enumerable:!(n=p(e,t))||n.enumerable});return o};var v=o=>O(f({},"__esModule",{value:!0}),o),w=(o,e,r,n)=>{for(var t=n>1?void 0:n?p(e,r):e,i=o.length-1,s;i>=0;i--)(s=o[i])&&(t=(n?s(e,r,t):s(t))||t);return n&&t&&f(e,r,t),t},l=(o,e)=>(r,n)=>e(r,n,o);var y={};C(y,{HttpOwnerInfoDataSource:()=>c});module.exports=v(y);var m=require("@ledgerhq/device-management-kit"),d=require("inversify"),a=require("purify-ts"),S=require("../../../../config/di/configTypes"),h=require("../../../../shared/network/di/networkTypes");let c=class{constructor(e,r){this.config=e;this.http=r}isSolanaSPLOwnerInfo(e){return typeof e!="object"||e===null?!1:typeof e.tokenAccount=="string"&&typeof e.owner=="string"&&typeof e.contract=="string"&&typeof e.signedDescriptor=="string"}async fetchAddressMetadata(e,r){try{const n=await this.http.get(`${this.config.metadataServiceDomain.url}/v2/solana/owner/${e}`,{params:{challenge:r}});return this.isSolanaSPLOwnerInfo(n)?(0,a.Right)(n):(0,a.Left)(new Error("[ContextModule] - HttpOwnerInfoDataSource: invalid fetchAddressMetadata response shape"))}catch{return(0,a.Left)(new Error("[ContextModule] - HttpOwnerInfoDataSource: Failed to fetch address metadata"))}}async computeAddressMetadata(e,r,n){try{const t=await this.http.get(`${this.config.metadataServiceDomain.url}/v2/solana/computed-token-account/${e}/${r}`,{params:{challenge:n}});return this.isSolanaSPLOwnerInfo(t)?(0,a.Right)(t):(0,a.Left)(new Error("[ContextModule] - HttpOwnerInfoDataSource: invalid computeAddressMetadata response shape"))}catch{return(0,a.Left)(new Error("[ContextModule] - HttpOwnerInfoDataSource: Failed to compute address metadata"))}}async getOwnerInfo(e){const{tokenAddress:r,challenge:n,createATA:t}=e;if(!n)return(0,a.Left)(new Error("[ContextModule] - HttpOwnerInfoDataSource: challenge is required"));let i;if(r)i=await this.fetchAddressMetadata(r,n);else if(t?.address&&t?.mintAddress)i=await this.computeAddressMetadata(t.address,t.mintAddress,n);else return(0,a.Left)(new Error("[ContextModule] - HttpOwnerInfoDataSource: either tokenAddress or valid createATA must be provided"));return i.chain(s=>{const u=(0,m.hexaStringToBuffer)(s.signedDescriptor);return u?(0,a.Right)({tlvDescriptor:u}):(0,a.Left)(new Error("[ContextModule] - HttpOwnerInfoDataSource: invalid base64 tlvDescriptor received"))})}};c=w([(0,d.injectable)(),l(0,(0,d.inject)(S.configTypes.Config)),l(1,(0,d.inject)(h.networkTypes.NetworkClient))],c);0&&(module.exports={HttpOwnerInfoDataSource});
2
2
  //# sourceMappingURL=HttpOwnerInfoDataSource.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/modules/solana/owner-info/data/HttpOwnerInfoDataSource.ts"],
4
- "sourcesContent": ["import {\n DmkNetworkClient,\n hexaStringToBuffer,\n} from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport type { ContextModuleServiceConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n type SolanaSPLOwnerInfo,\n type SolanaTransactionContext,\n} from \"@/modules/solana/model/SolanaTransactionContext\";\nimport { networkTypes } from \"@/shared/network/di/networkTypes\";\n\nimport {\n HttpOwnerInfoDataSourceResult,\n OwnerInfoDataSource,\n} from \"./OwnerInfoDataSource\";\n\n@injectable()\nexport class HttpOwnerInfoDataSource implements OwnerInfoDataSource {\n constructor(\n @inject(configTypes.Config)\n private readonly config: ContextModuleServiceConfig,\n @inject(networkTypes.NetworkClient)\n private readonly http: DmkNetworkClient,\n ) {\n if (!this.config.originToken) {\n throw new Error(\n \"[ContextModule] - HttpOwnerInfoDataSource: origin token is required\",\n );\n }\n }\n\n private isSolanaSPLOwnerInfo(data: {\n tokenAccount?: unknown;\n owner?: unknown;\n contract?: unknown;\n signedDescriptor?: unknown;\n }): data is SolanaSPLOwnerInfo {\n if (typeof data !== \"object\" || data === null) return false;\n return (\n typeof data.tokenAccount === \"string\" &&\n typeof data.owner === \"string\" &&\n typeof data.contract === \"string\" &&\n typeof data.signedDescriptor === \"string\"\n );\n }\n\n async fetchAddressMetadata(\n tokenAddress: string,\n challenge: string,\n ): Promise<Either<Error, SolanaSPLOwnerInfo>> {\n try {\n const data = (await this.http.get(\n `${this.config.metadataServiceDomain.url}/v2/solana/owner/${tokenAddress}`,\n { params: { challenge } },\n )) as SolanaSPLOwnerInfo;\n if (!this.isSolanaSPLOwnerInfo(data))\n return Left(\n new Error(\n \"[ContextModule] - HttpOwnerInfoDataSource: invalid fetchAddressMetadata response shape\",\n ),\n );\n return Right(data);\n } catch {\n return Left(\n new Error(\n \"[ContextModule] - HttpOwnerInfoDataSource: Failed to fetch address metadata\",\n ),\n );\n }\n }\n\n async computeAddressMetadata(\n address: string,\n mintAddress: string,\n challenge: string,\n ): Promise<Either<Error, SolanaSPLOwnerInfo>> {\n try {\n const data = (await this.http.get(\n `${this.config.metadataServiceDomain.url}/v2/solana/computed-token-account/${address}/${mintAddress}`,\n { params: { challenge } },\n )) as SolanaSPLOwnerInfo;\n if (!this.isSolanaSPLOwnerInfo(data))\n return Left(\n new Error(\n \"[ContextModule] - HttpOwnerInfoDataSource: invalid computeAddressMetadata response shape\",\n ),\n );\n return Right(data);\n } catch {\n return Left(\n new Error(\n \"[ContextModule] - HttpOwnerInfoDataSource: Failed to compute address metadata\",\n ),\n );\n }\n }\n\n async getOwnerInfo(\n context: SolanaTransactionContext,\n ): Promise<Either<Error, HttpOwnerInfoDataSourceResult>> {\n const { tokenAddress, challenge, createATA } = context;\n\n if (!challenge) {\n return Left(\n new Error(\n \"[ContextModule] - HttpOwnerInfoDataSource: challenge is required\",\n ),\n );\n }\n\n let ownerInfoResult: Either<Error, SolanaSPLOwnerInfo>;\n\n if (tokenAddress) {\n ownerInfoResult = await this.fetchAddressMetadata(\n tokenAddress,\n challenge,\n );\n } else if (createATA?.address && createATA?.mintAddress) {\n ownerInfoResult = await this.computeAddressMetadata(\n createATA.address,\n createATA.mintAddress,\n challenge,\n );\n } else {\n return Left(\n new Error(\n \"[ContextModule] - HttpOwnerInfoDataSource: either tokenAddress or valid createATA must be provided\",\n ),\n );\n }\n\n return ownerInfoResult.chain((ownerInfo) => {\n const tlvDescriptor = hexaStringToBuffer(ownerInfo.signedDescriptor);\n if (!tlvDescriptor) {\n return Left(\n new Error(\n \"[ContextModule] - HttpOwnerInfoDataSource: invalid base64 tlvDescriptor received\",\n ),\n );\n }\n return Right({\n tlvDescriptor,\n });\n });\n }\n}\n"],
5
- "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,6BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAGO,2CACPC,EAAmC,qBACnCC,EAAoC,qBAEpCC,EAA4B,mCAM5BC,EAA6B,4CAQtB,IAAMC,EAAN,KAA6D,CAClE,YAEmBC,EAEAC,EACjB,CAHiB,YAAAD,EAEA,UAAAC,EAEjB,GAAI,CAAC,KAAK,OAAO,YACf,MAAM,IAAI,MACR,qEACF,CAEJ,CAEQ,qBAAqBC,E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GAAc,CAC1C,MAAMC,KAAgB,sBAAmBD,EAAU,gBAAgB,EACnE,OAAKC,KAOE,SAAM,CACX,cAAAA,CACF,CAAC,KARQ,QACL,IAAI,MACF,kFACF,CACF,CAKJ,CAAC,CACH,CACF,EAhIaZ,EAANa,EAAA,IADN,cAAW,EAGPC,EAAA,eAAO,cAAY,MAAM,GAEzBA,EAAA,eAAO,eAAa,aAAa,IAJzBd",
4
+ "sourcesContent": ["import {\n DmkNetworkClient,\n hexaStringToBuffer,\n} from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport type { ContextModuleServiceConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n type SolanaSPLOwnerInfo,\n type SolanaTransactionContext,\n} from \"@/modules/solana/model/SolanaTransactionContext\";\nimport { networkTypes } from \"@/shared/network/di/networkTypes\";\n\nimport {\n HttpOwnerInfoDataSourceResult,\n OwnerInfoDataSource,\n} from \"./OwnerInfoDataSource\";\n\n@injectable()\nexport class HttpOwnerInfoDataSource implements OwnerInfoDataSource {\n constructor(\n @inject(configTypes.Config)\n private readonly config: ContextModuleServiceConfig,\n @inject(networkTypes.NetworkClient)\n private readonly http: DmkNetworkClient,\n ) {}\n\n private isSolanaSPLOwnerInfo(data: {\n tokenAccount?: unknown;\n owner?: unknown;\n contract?: unknown;\n signedDescriptor?: unknown;\n }): data is SolanaSPLOwnerInfo {\n if (typeof data !== \"object\" || data === null) return false;\n return (\n typeof data.tokenAccount === \"string\" &&\n typeof data.owner === \"string\" &&\n typeof data.contract === \"string\" &&\n typeof data.signedDescriptor === \"string\"\n );\n }\n\n async fetchAddressMetadata(\n tokenAddress: string,\n challenge: string,\n ): Promise<Either<Error, SolanaSPLOwnerInfo>> {\n try {\n const data = (await this.http.get(\n `${this.config.metadataServiceDomain.url}/v2/solana/owner/${tokenAddress}`,\n { params: { challenge } },\n )) as SolanaSPLOwnerInfo;\n if (!this.isSolanaSPLOwnerInfo(data))\n return Left(\n new Error(\n \"[ContextModule] - HttpOwnerInfoDataSource: invalid fetchAddressMetadata response shape\",\n ),\n );\n return Right(data);\n } catch {\n return Left(\n new Error(\n \"[ContextModule] - HttpOwnerInfoDataSource: Failed to fetch address metadata\",\n ),\n );\n }\n }\n\n async computeAddressMetadata(\n address: string,\n mintAddress: string,\n challenge: string,\n ): Promise<Either<Error, SolanaSPLOwnerInfo>> {\n try {\n const data = (await this.http.get(\n `${this.config.metadataServiceDomain.url}/v2/solana/computed-token-account/${address}/${mintAddress}`,\n { params: { challenge } },\n )) as SolanaSPLOwnerInfo;\n if (!this.isSolanaSPLOwnerInfo(data))\n return Left(\n new Error(\n \"[ContextModule] - HttpOwnerInfoDataSource: invalid computeAddressMetadata response shape\",\n ),\n );\n return Right(data);\n } catch {\n return Left(\n new Error(\n \"[ContextModule] - HttpOwnerInfoDataSource: Failed to compute address metadata\",\n ),\n );\n }\n }\n\n async getOwnerInfo(\n context: SolanaTransactionContext,\n ): Promise<Either<Error, HttpOwnerInfoDataSourceResult>> {\n const { tokenAddress, challenge, createATA } = context;\n\n if (!challenge) {\n return Left(\n new Error(\n \"[ContextModule] - HttpOwnerInfoDataSource: challenge is required\",\n ),\n );\n }\n\n let ownerInfoResult: Either<Error, SolanaSPLOwnerInfo>;\n\n if (tokenAddress) {\n ownerInfoResult = await this.fetchAddressMetadata(\n tokenAddress,\n challenge,\n );\n } else if (createATA?.address && createATA?.mintAddress) {\n ownerInfoResult = await this.computeAddressMetadata(\n createATA.address,\n createATA.mintAddress,\n challenge,\n );\n } else {\n return Left(\n new Error(\n \"[ContextModule] - HttpOwnerInfoDataSource: either tokenAddress or valid createATA must be provided\",\n ),\n );\n }\n\n return ownerInfoResult.chain((ownerInfo) => {\n const tlvDescriptor = hexaStringToBuffer(ownerInfo.signedDescriptor);\n if (!tlvDescriptor) {\n return Left(\n new Error(\n \"[ContextModule] - HttpOwnerInfoDataSource: invalid base64 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E,aAAAJ,EAAc,UAAAC,EAAW,UAAAI,CAAU,EAAID,EAE/C,GAAI,CAACH,EACH,SAAO,QACL,IAAI,MACF,kEACF,CACF,EAGF,IAAIK,EAEJ,GAAIN,EACFM,EAAkB,MAAM,KAAK,qBAC3BN,EACAC,CACF,UACSI,GAAW,SAAWA,GAAW,YAC1CC,EAAkB,MAAM,KAAK,uBAC3BD,EAAU,QACVA,EAAU,YACVJ,CACF,MAEA,UAAO,QACL,IAAI,MACF,oGACF,CACF,EAGF,OAAOK,EAAgB,MAAOC,GAAc,CAC1C,MAAMC,KAAgB,sBAAmBD,EAAU,gBAAgB,EACnE,OAAKC,KAOE,SAAM,CACX,cAAAA,CACF,CAAC,KARQ,QACL,IAAI,MACF,kFACF,CACF,CAKJ,CAAC,CACH,CACF,EA1HaZ,EAANa,EAAA,IADN,cAAW,EAGPC,EAAA,eAAO,cAAY,MAAM,GAEzBA,EAAA,eAAO,eAAa,aAAa,IAJzBd",
6
6
  "names": ["HttpOwnerInfoDataSource_exports", "__export", "HttpOwnerInfoDataSource", "__toCommonJS", "import_device_management_kit", "import_inversify", "import_purify_ts", "import_configTypes", "import_networkTypes", "HttpOwnerInfoDataSource", "config", "http", "data", "tokenAddress", "challenge", "address", "mintAddress", "context", "createATA", "ownerInfoResult", "ownerInfo", "tlvDescriptor", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var a=require("@ledgerhq/device-management-kit"),s=require("purify-ts"),r=require("../../../../modules/solana/owner-info/data/HttpOwnerInfoDataSource");function l(o){const c=new TextEncoder().encode(o);return Array.from(c).map(e=>e.toString(16).padStart(2,"0")).join("")}describe("HttpOwnerInfoDataSource",()=>{const o={metadataServiceDomain:{url:"https://some.doma.in"},originToken:"mock-origin-token"},i=l("mock-descriptor"),c={tokenAccount:"token-account",owner:"owner-address",contract:"contract-address",signedDescriptor:i};let e;beforeEach(()=>{vi.resetAllMocks(),e={get:vi.fn()}}),it("should fetch address metadata via tokenAddress",async()=>{const n={deviceModelId:a.DeviceModelId.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0};e.get.mockResolvedValueOnce(c);const t=await new r.HttpOwnerInfoDataSource(o,e).getOwnerInfo(n);expect(e.get).toHaveBeenCalledWith(`${o.metadataServiceDomain.url}/v2/solana/owner/some-token`,{params:{challenge:"random"}}),expect(t.isRight()).toBe(!0),expect(t.extract()).toEqual({tlvDescriptor:(0,a.hexaStringToBuffer)(i)})}),it("should return an error if both tokenAddress and createATA are missing or invalid",async()=>{const n={deviceModelId:a.DeviceModelId.FLEX,tokenAddress:void 0,challenge:"random",createATA:void 0},t=await new r.HttpOwnerInfoDataSource(o,e).getOwnerInfo(n);expect(t).toEqual((0,s.Left)(new Error("[ContextModule] - HttpOwnerInfoDataSource: either tokenAddress or valid createATA must be provided")))}),it("should return an error if challenge is missing",async()=>{const n={deviceModelId:a.DeviceModelId.FLEX,tokenAddress:"some-token",challenge:void 0,createATA:void 0},t=await new r.HttpOwnerInfoDataSource(o,e).getOwnerInfo(n);expect(t).toEqual((0,s.Left)(new Error("[ContextModule] - HttpOwnerInfoDataSource: challenge is required")))}),it("should return an error if the descriptor is not valid base64",async()=>{e.get.mockResolvedValueOnce({...c,signedDescriptor:"!!!not-valid-base64!!!"});const n={deviceModelId:a.DeviceModelId.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},t=await new r.HttpOwnerInfoDataSource(o,e).getOwnerInfo(n);expect(t).toEqual((0,s.Left)(new Error("[ContextModule] - HttpOwnerInfoDataSource: invalid base64 tlvDescriptor received")))}),it("should return an error if the metadata request fails",async()=>{e.get.mockRejectedValueOnce(new Error("Network error"));const n={deviceModelId:a.DeviceModelId.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},t=await new r.HttpOwnerInfoDataSource(o,e).getOwnerInfo(n);expect(t).toEqual((0,s.Left)(new Error("[ContextModule] - HttpOwnerInfoDataSource: Failed to fetch address metadata")))}),it("should return an error if fetch request return wrong shape for fetchAddressMetadata",async()=>{e.get.mockResolvedValueOnce({wrong:"field"});const n={deviceModelId:a.DeviceModelId.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},t=await new r.HttpOwnerInfoDataSource(o,e).getOwnerInfo(n);expect(t).toEqual((0,s.Left)(new Error("[ContextModule] - HttpOwnerInfoDataSource: invalid fetchAddressMetadata response shape")))}),it("should return an error if fetch request return wrong shape for computeAddressMetadata",async()=>{e.get.mockResolvedValueOnce({wrong:"field"});const n={deviceModelId:a.DeviceModelId.FLEX,tokenAddress:void 0,challenge:"random",createATA:{address:"some-address",mintAddress:"some-mint"}},t=await new r.HttpOwnerInfoDataSource(o,e).getOwnerInfo(n);expect(e.get).toHaveBeenCalledWith(`${o.metadataServiceDomain.url}/v2/solana/computed-token-account/some-address/some-mint`,{params:{challenge:"random"}}),expect(t).toEqual((0,s.Left)(new Error("[ContextModule] - HttpOwnerInfoDataSource: invalid computeAddressMetadata response shape")))}),it("should throw if originToken is missing",()=>{expect(()=>{new r.HttpOwnerInfoDataSource({...o,originToken:void 0},e)}).toThrow("[ContextModule] - HttpOwnerInfoDataSource: origin token is required")})});
1
+ "use strict";var a=require("@ledgerhq/device-management-kit"),s=require("purify-ts"),r=require("../../../../modules/solana/owner-info/data/HttpOwnerInfoDataSource");function l(o){const c=new TextEncoder().encode(o);return Array.from(c).map(e=>e.toString(16).padStart(2,"0")).join("")}describe("HttpOwnerInfoDataSource",()=>{const o={metadataServiceDomain:{url:"https://some.doma.in"},originToken:"mock-origin-token"},i=l("mock-descriptor"),c={tokenAccount:"token-account",owner:"owner-address",contract:"contract-address",signedDescriptor:i};let e;beforeEach(()=>{vi.resetAllMocks(),e={get:vi.fn()}}),it("should fetch address metadata via tokenAddress",async()=>{const n={deviceModelId:a.DeviceModelId.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0};e.get.mockResolvedValueOnce(c);const t=await new r.HttpOwnerInfoDataSource(o,e).getOwnerInfo(n);expect(e.get).toHaveBeenCalledWith(`${o.metadataServiceDomain.url}/v2/solana/owner/some-token`,{params:{challenge:"random"}}),expect(t.isRight()).toBe(!0),expect(t.extract()).toEqual({tlvDescriptor:(0,a.hexaStringToBuffer)(i)})}),it("should return an error if both tokenAddress and createATA are missing or invalid",async()=>{const n={deviceModelId:a.DeviceModelId.FLEX,tokenAddress:void 0,challenge:"random",createATA:void 0},t=await new r.HttpOwnerInfoDataSource(o,e).getOwnerInfo(n);expect(t).toEqual((0,s.Left)(new Error("[ContextModule] - HttpOwnerInfoDataSource: either tokenAddress or valid createATA must be provided")))}),it("should return an error if challenge is missing",async()=>{const n={deviceModelId:a.DeviceModelId.FLEX,tokenAddress:"some-token",challenge:void 0,createATA:void 0},t=await new r.HttpOwnerInfoDataSource(o,e).getOwnerInfo(n);expect(t).toEqual((0,s.Left)(new Error("[ContextModule] - HttpOwnerInfoDataSource: challenge is required")))}),it("should return an error if the descriptor is not valid base64",async()=>{e.get.mockResolvedValueOnce({...c,signedDescriptor:"!!!not-valid-base64!!!"});const n={deviceModelId:a.DeviceModelId.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},t=await new r.HttpOwnerInfoDataSource(o,e).getOwnerInfo(n);expect(t).toEqual((0,s.Left)(new Error("[ContextModule] - HttpOwnerInfoDataSource: invalid base64 tlvDescriptor received")))}),it("should return an error if the metadata request fails",async()=>{e.get.mockRejectedValueOnce(new Error("Network error"));const n={deviceModelId:a.DeviceModelId.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},t=await new r.HttpOwnerInfoDataSource(o,e).getOwnerInfo(n);expect(t).toEqual((0,s.Left)(new Error("[ContextModule] - HttpOwnerInfoDataSource: Failed to fetch address metadata")))}),it("should return an error if fetch request return wrong shape for fetchAddressMetadata",async()=>{e.get.mockResolvedValueOnce({wrong:"field"});const n={deviceModelId:a.DeviceModelId.FLEX,tokenAddress:"some-token",challenge:"random",createATA:void 0},t=await new r.HttpOwnerInfoDataSource(o,e).getOwnerInfo(n);expect(t).toEqual((0,s.Left)(new Error("[ContextModule] - HttpOwnerInfoDataSource: invalid fetchAddressMetadata response shape")))}),it("should return an error if fetch request return wrong shape for computeAddressMetadata",async()=>{e.get.mockResolvedValueOnce({wrong:"field"});const n={deviceModelId:a.DeviceModelId.FLEX,tokenAddress:void 0,challenge:"random",createATA:{address:"some-address",mintAddress:"some-mint"}},t=await new r.HttpOwnerInfoDataSource(o,e).getOwnerInfo(n);expect(e.get).toHaveBeenCalledWith(`${o.metadataServiceDomain.url}/v2/solana/computed-token-account/some-address/some-mint`,{params:{challenge:"random"}}),expect(t).toEqual((0,s.Left)(new Error("[ContextModule] - HttpOwnerInfoDataSource: invalid computeAddressMetadata response shape")))})});
2
2
  //# sourceMappingURL=HttpOwnerInfoDataSource.test.js.map