@ledgerhq/context-module 2.3.1 → 2.4.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 (131) hide show
  1. package/lib/cjs/package.json +2 -2
  2. package/lib/cjs/src/modules/multichain/transaction-check/loaders/SolanaTransactionCheckLoader.js +1 -1
  3. package/lib/cjs/src/modules/multichain/transaction-check/loaders/SolanaTransactionCheckLoader.js.map +3 -3
  4. package/lib/cjs/src/modules/multichain/transaction-check/loaders/SolanaTransactionCheckLoader.test.js +1 -1
  5. package/lib/cjs/src/modules/multichain/transaction-check/loaders/SolanaTransactionCheckLoader.test.js.map +3 -3
  6. package/lib/cjs/src/modules/solana/alt-resolution/data/AltResolutionDataSource.js +1 -1
  7. package/lib/cjs/src/modules/solana/alt-resolution/data/AltResolutionDataSource.js.map +1 -1
  8. package/lib/cjs/src/modules/solana/alt-resolution/data/HttpAltResolutionDataSource.js +1 -1
  9. package/lib/cjs/src/modules/solana/alt-resolution/data/HttpAltResolutionDataSource.js.map +2 -2
  10. package/lib/cjs/src/modules/solana/alt-resolution/domain/AltResolutionContextLoader.js +1 -1
  11. package/lib/cjs/src/modules/solana/alt-resolution/domain/AltResolutionContextLoader.js.map +2 -2
  12. package/lib/cjs/src/modules/solana/instruction-info/data/HttpInstructionInfoDataSource.js +1 -1
  13. package/lib/cjs/src/modules/solana/instruction-info/data/HttpInstructionInfoDataSource.js.map +2 -2
  14. package/lib/cjs/src/modules/solana/instruction-info/data/HttpInstructionInfoDataSource.test.js +1 -1
  15. package/lib/cjs/src/modules/solana/instruction-info/data/HttpInstructionInfoDataSource.test.js.map +3 -3
  16. package/lib/cjs/src/modules/solana/instruction-info/data/InstructionInfoDto.js +1 -1
  17. package/lib/cjs/src/modules/solana/instruction-info/data/InstructionInfoDto.js.map +2 -2
  18. package/lib/cjs/src/modules/solana/instruction-info/data/InstructionInfoMapper.js +1 -1
  19. package/lib/cjs/src/modules/solana/instruction-info/data/InstructionInfoMapper.js.map +2 -2
  20. package/lib/cjs/src/modules/solana/model/SolanaPayloads.js +1 -1
  21. package/lib/cjs/src/modules/solana/model/SolanaPayloads.js.map +2 -2
  22. package/lib/cjs/src/modules/solana/model/SolanaTransactionContext.js +1 -1
  23. package/lib/cjs/src/modules/solana/model/SolanaTransactionContext.js.map +1 -1
  24. package/lib/cjs/src/modules/solana/owner-info/data/HttpOwnerInfoDataSource.test.js.map +2 -2
  25. package/lib/cjs/src/modules/solana/token/data/HttpMintToIdDataSource.js +2 -0
  26. package/lib/cjs/src/modules/solana/token/data/HttpMintToIdDataSource.js.map +7 -0
  27. package/lib/cjs/src/modules/solana/token/data/HttpMintToIdDataSource.test.js +2 -0
  28. package/lib/cjs/src/modules/solana/token/data/HttpMintToIdDataSource.test.js.map +7 -0
  29. package/lib/cjs/src/modules/solana/token/data/MintToIdDataSource.js +2 -0
  30. package/lib/cjs/src/modules/solana/token/data/MintToIdDataSource.js.map +7 -0
  31. package/lib/cjs/src/modules/solana/token/di/tokenModuleFactory.js +1 -1
  32. package/lib/cjs/src/modules/solana/token/di/tokenModuleFactory.js.map +3 -3
  33. package/lib/cjs/src/modules/solana/token/di/tokenTypes.js +1 -1
  34. package/lib/cjs/src/modules/solana/token/di/tokenTypes.js.map +2 -2
  35. package/lib/cjs/src/modules/solana/token/domain/TokenContextLoader.js +1 -1
  36. package/lib/cjs/src/modules/solana/token/domain/TokenContextLoader.js.map +3 -3
  37. package/lib/cjs/src/modules/solana/token/domain/TokenContextLoader.test.js +1 -1
  38. package/lib/cjs/src/modules/solana/token/domain/TokenContextLoader.test.js.map +3 -3
  39. package/lib/cjs/src/modules/solana/token-account-state/data/HttpTokenAccountStateDataSource.js +1 -1
  40. package/lib/cjs/src/modules/solana/token-account-state/data/HttpTokenAccountStateDataSource.js.map +2 -2
  41. package/lib/cjs/src/modules/solana/token-account-state/data/TokenAccountStateDataSource.js +1 -1
  42. package/lib/cjs/src/modules/solana/token-account-state/data/TokenAccountStateDataSource.js.map +1 -1
  43. package/lib/cjs/src/modules/solana/token-account-state/domain/TokenAccountStateContextLoader.js +1 -1
  44. package/lib/cjs/src/modules/solana/token-account-state/domain/TokenAccountStateContextLoader.js.map +2 -2
  45. package/lib/cjs/src/modules/solana/token-info/data/HttpTokenInfoDataSource.js +1 -1
  46. package/lib/cjs/src/modules/solana/token-info/data/HttpTokenInfoDataSource.js.map +3 -3
  47. package/lib/cjs/src/modules/solana/token-info/data/HttpTokenInfoDataSource.test.js +1 -1
  48. package/lib/cjs/src/modules/solana/token-info/data/HttpTokenInfoDataSource.test.js.map +2 -2
  49. package/lib/cjs/src/shared/utils/deviceModelIdCodec.js +1 -1
  50. package/lib/cjs/src/shared/utils/deviceModelIdCodec.js.map +2 -2
  51. package/lib/cjs/src/shared/utils/deviceModelIdCodec.test.js +1 -1
  52. package/lib/cjs/src/shared/utils/deviceModelIdCodec.test.js.map +2 -2
  53. package/lib/esm/package.json +2 -2
  54. package/lib/esm/src/modules/multichain/transaction-check/loaders/SolanaTransactionCheckLoader.js +1 -1
  55. package/lib/esm/src/modules/multichain/transaction-check/loaders/SolanaTransactionCheckLoader.js.map +3 -3
  56. package/lib/esm/src/modules/multichain/transaction-check/loaders/SolanaTransactionCheckLoader.test.js +1 -1
  57. package/lib/esm/src/modules/multichain/transaction-check/loaders/SolanaTransactionCheckLoader.test.js.map +3 -3
  58. package/lib/esm/src/modules/solana/alt-resolution/data/HttpAltResolutionDataSource.js +1 -1
  59. package/lib/esm/src/modules/solana/alt-resolution/data/HttpAltResolutionDataSource.js.map +2 -2
  60. package/lib/esm/src/modules/solana/alt-resolution/domain/AltResolutionContextLoader.js +1 -1
  61. package/lib/esm/src/modules/solana/alt-resolution/domain/AltResolutionContextLoader.js.map +2 -2
  62. package/lib/esm/src/modules/solana/instruction-info/data/HttpInstructionInfoDataSource.js +1 -1
  63. package/lib/esm/src/modules/solana/instruction-info/data/HttpInstructionInfoDataSource.js.map +2 -2
  64. package/lib/esm/src/modules/solana/instruction-info/data/HttpInstructionInfoDataSource.test.js +1 -1
  65. package/lib/esm/src/modules/solana/instruction-info/data/HttpInstructionInfoDataSource.test.js.map +3 -3
  66. package/lib/esm/src/modules/solana/instruction-info/data/InstructionInfoDto.js +1 -1
  67. package/lib/esm/src/modules/solana/instruction-info/data/InstructionInfoDto.js.map +2 -2
  68. package/lib/esm/src/modules/solana/instruction-info/data/InstructionInfoMapper.js +1 -1
  69. package/lib/esm/src/modules/solana/instruction-info/data/InstructionInfoMapper.js.map +2 -2
  70. package/lib/esm/src/modules/solana/model/SolanaPayloads.js.map +2 -2
  71. package/lib/esm/src/modules/solana/owner-info/data/HttpOwnerInfoDataSource.test.js.map +2 -2
  72. package/lib/esm/src/modules/solana/token/data/HttpMintToIdDataSource.js +2 -0
  73. package/lib/esm/src/modules/solana/token/data/HttpMintToIdDataSource.js.map +7 -0
  74. package/lib/esm/src/modules/solana/token/data/HttpMintToIdDataSource.test.js +2 -0
  75. package/lib/esm/src/modules/solana/token/data/HttpMintToIdDataSource.test.js.map +7 -0
  76. package/lib/esm/src/modules/solana/token/data/MintToIdDataSource.js +1 -0
  77. package/lib/esm/src/modules/solana/token/data/MintToIdDataSource.js.map +7 -0
  78. package/lib/esm/src/modules/solana/token/di/tokenModuleFactory.js +1 -1
  79. package/lib/esm/src/modules/solana/token/di/tokenModuleFactory.js.map +3 -3
  80. package/lib/esm/src/modules/solana/token/di/tokenTypes.js +1 -1
  81. package/lib/esm/src/modules/solana/token/di/tokenTypes.js.map +2 -2
  82. package/lib/esm/src/modules/solana/token/domain/TokenContextLoader.js +1 -1
  83. package/lib/esm/src/modules/solana/token/domain/TokenContextLoader.js.map +3 -3
  84. package/lib/esm/src/modules/solana/token/domain/TokenContextLoader.test.js +1 -1
  85. package/lib/esm/src/modules/solana/token/domain/TokenContextLoader.test.js.map +3 -3
  86. package/lib/esm/src/modules/solana/token-account-state/data/HttpTokenAccountStateDataSource.js +1 -1
  87. package/lib/esm/src/modules/solana/token-account-state/data/HttpTokenAccountStateDataSource.js.map +2 -2
  88. package/lib/esm/src/modules/solana/token-account-state/domain/TokenAccountStateContextLoader.js +1 -1
  89. package/lib/esm/src/modules/solana/token-account-state/domain/TokenAccountStateContextLoader.js.map +3 -3
  90. package/lib/esm/src/modules/solana/token-info/data/HttpTokenInfoDataSource.js +1 -1
  91. package/lib/esm/src/modules/solana/token-info/data/HttpTokenInfoDataSource.js.map +3 -3
  92. package/lib/esm/src/modules/solana/token-info/data/HttpTokenInfoDataSource.test.js +1 -1
  93. package/lib/esm/src/modules/solana/token-info/data/HttpTokenInfoDataSource.test.js.map +2 -2
  94. package/lib/esm/src/shared/utils/deviceModelIdCodec.js +1 -1
  95. package/lib/esm/src/shared/utils/deviceModelIdCodec.js.map +2 -2
  96. package/lib/esm/src/shared/utils/deviceModelIdCodec.test.js +1 -1
  97. package/lib/esm/src/shared/utils/deviceModelIdCodec.test.js.map +2 -2
  98. package/lib/types/src/modules/multichain/transaction-check/loaders/SolanaTransactionCheckLoader.d.ts +0 -12
  99. package/lib/types/src/modules/multichain/transaction-check/loaders/SolanaTransactionCheckLoader.d.ts.map +1 -1
  100. package/lib/types/src/modules/solana/alt-resolution/data/AltResolutionDataSource.d.ts +1 -0
  101. package/lib/types/src/modules/solana/alt-resolution/data/AltResolutionDataSource.d.ts.map +1 -1
  102. package/lib/types/src/modules/solana/alt-resolution/data/HttpAltResolutionDataSource.d.ts.map +1 -1
  103. package/lib/types/src/modules/solana/alt-resolution/domain/AltResolutionContextLoader.d.ts.map +1 -1
  104. package/lib/types/src/modules/solana/instruction-info/data/HttpInstructionInfoDataSource.d.ts.map +1 -1
  105. package/lib/types/src/modules/solana/instruction-info/data/InstructionInfoDto.d.ts +2 -2
  106. package/lib/types/src/modules/solana/instruction-info/data/InstructionInfoDto.d.ts.map +1 -1
  107. package/lib/types/src/modules/solana/instruction-info/data/InstructionInfoMapper.d.ts.map +1 -1
  108. package/lib/types/src/modules/solana/model/SolanaPayloads.d.ts +3 -0
  109. package/lib/types/src/modules/solana/model/SolanaPayloads.d.ts.map +1 -1
  110. package/lib/types/src/modules/solana/model/SolanaTransactionContext.d.ts +1 -0
  111. package/lib/types/src/modules/solana/model/SolanaTransactionContext.d.ts.map +1 -1
  112. package/lib/types/src/modules/solana/token/data/HttpMintToIdDataSource.d.ts +11 -0
  113. package/lib/types/src/modules/solana/token/data/HttpMintToIdDataSource.d.ts.map +1 -0
  114. package/lib/types/src/modules/solana/token/data/HttpMintToIdDataSource.test.d.ts +2 -0
  115. package/lib/types/src/modules/solana/token/data/HttpMintToIdDataSource.test.d.ts.map +1 -0
  116. package/lib/types/src/modules/solana/token/data/MintToIdDataSource.d.ts +8 -0
  117. package/lib/types/src/modules/solana/token/data/MintToIdDataSource.d.ts.map +1 -0
  118. package/lib/types/src/modules/solana/token/di/tokenModuleFactory.d.ts.map +1 -1
  119. package/lib/types/src/modules/solana/token/di/tokenTypes.d.ts +1 -0
  120. package/lib/types/src/modules/solana/token/di/tokenTypes.d.ts.map +1 -1
  121. package/lib/types/src/modules/solana/token/domain/TokenContextLoader.d.ts +3 -1
  122. package/lib/types/src/modules/solana/token/domain/TokenContextLoader.d.ts.map +1 -1
  123. package/lib/types/src/modules/solana/token-account-state/data/HttpTokenAccountStateDataSource.d.ts.map +1 -1
  124. package/lib/types/src/modules/solana/token-account-state/data/TokenAccountStateDataSource.d.ts +1 -0
  125. package/lib/types/src/modules/solana/token-account-state/data/TokenAccountStateDataSource.d.ts.map +1 -1
  126. package/lib/types/src/modules/solana/token-account-state/domain/TokenAccountStateContextLoader.d.ts.map +1 -1
  127. package/lib/types/src/modules/solana/token-info/data/HttpTokenInfoDataSource.d.ts.map +1 -1
  128. package/lib/types/src/shared/utils/deviceModelIdCodec.d.ts +2 -2
  129. package/lib/types/src/shared/utils/deviceModelIdCodec.d.ts.map +1 -1
  130. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  131. package/package.json +5 -5
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/modules/solana/instruction-info/data/InstructionInfoMapper.ts"],
4
- "sourcesContent": ["// Maps the validated CAL instruction-descriptor DTOs into the core\n// `SolanaInstructionInfoPayload` model. Keeping this in the data layer means\n// the domain `InstructionInfoContextLoader` never has to know the CAL DTO\n// shapes \u2014 it consumes core models only.\n\nimport { type Either, Left, Right } from \"purify-ts\";\n\nimport {\n type SolanaCalAccountReset,\n type SolanaCalDisplayField,\n type SolanaCalValueFlowPort,\n type SolanaInstructionEnumVariant,\n type SolanaInstructionInfoPayload,\n type SolanaInstructionSubstructure,\n SolanaInstructionSubstructureKind,\n} from \"@/modules/solana/model/SolanaPayloads\";\nimport { u16Codec } from \"@/shared/utils/uIntCodec\";\n\nimport {\n type CalAccountResetDto,\n type CalDisplayFieldDto,\n type CalInstructionDescriptorDto,\n type CalSignatures,\n type CalValueFlowPortDto,\n} from \"./InstructionInfoDto\";\n\nexport type CalMode = \"prod\" | \"test\";\n\nfunction pickSignature(\n signatures: CalSignatures,\n mode: CalMode,\n): string | undefined {\n return signatures[mode];\n}\n\n// --- DTO \u2192 decoded-payload projections. Pick only the fields the host-side\n// requirement builder reads, dropping the signed-TLV `descriptor` carried by\n// the DTO. ---\n\nexport function toValueFlowPorts(\n dtos: CalValueFlowPortDto[] = [],\n): SolanaCalValueFlowPort[] {\n return dtos.map((port) => ({\n account_indices: port.account_indices,\n optional_account_strategy: port.optional_account_strategy,\n token_value: port.token_value,\n }));\n}\n\nexport function toAccountResets(\n dtos: CalAccountResetDto[] = [],\n): SolanaCalAccountReset[] {\n // Drop malformed resets (missing account_index) rather than defaulting to\n // slot 0, which would create an unintended TOKEN_ACCOUNT_STATE requirement.\n return dtos.flatMap((reset) =>\n reset.account_index === undefined\n ? []\n : [\n {\n account_index: reset.account_index,\n require_pre_balance_zero: reset.require_pre_balance_zero,\n },\n ],\n );\n}\n\nexport function toDisplayFields(\n dtos: CalDisplayFieldDto[] = [],\n): SolanaCalDisplayField[] {\n return dtos.map((field) => ({\n name: field.name,\n param: field.param ?? { type: \"\" },\n }));\n}\n\nfunction toSubstructures(\n dto: CalInstructionDescriptorDto,\n): SolanaInstructionSubstructure[] {\n return [\n ...(dto.display_fields ?? []).map((s) => ({\n kind: SolanaInstructionSubstructureKind.DISPLAY_FIELD,\n data: s.descriptor,\n })),\n ...(dto.value_flow_ports ?? []).map((s) => ({\n kind: SolanaInstructionSubstructureKind.VALUE_FLOW_PORT,\n data: s.descriptor,\n })),\n ...(dto.hide_rules ?? []).map((s) => ({\n kind: SolanaInstructionSubstructureKind.HIDE_RULE,\n data: s.descriptor,\n })),\n ...(dto.account_resets ?? []).map((s) => ({\n kind: SolanaInstructionSubstructureKind.ACCOUNT_RESET,\n data: s.descriptor,\n })),\n ];\n}\n\n/**\n * Flatten the CAL-bundled enum variants (keyed enumId \u2192 variantIndex). Keys\n * that don't validate as a u16 are skipped rather than leaking NaN/out-of-range\n * indices into the payload.\n */\nfunction toEnumVariants(\n dto: CalInstructionDescriptorDto,\n mode: CalMode,\n): SolanaInstructionEnumVariant[] {\n const enumVariants: SolanaInstructionEnumVariant[] = [];\n for (const [enumId, variants] of Object.entries(dto.enum_variants ?? {})) {\n for (const [variantIndex, variant] of Object.entries(variants)) {\n const index = Number(variantIndex);\n if (u16Codec.decode(index).isLeft()) {\n continue;\n }\n enumVariants.push({\n enumId,\n variantIndex: index,\n descriptor: {\n data: variant.descriptor.data,\n signature: pickSignature(variant.descriptor.signatures, mode) ?? \"\",\n },\n });\n }\n }\n return enumVariants;\n}\n\n/**\n * Flatten the enum variants of every descriptor in a program into a single\n * list. CAL nests `enum_variants` inside each instruction descriptor but\n * guarantees `(enumId, variantIndex)` is unique across a program, so the enum\n * loader resolves a selection against this program-level list \u2014 independently\n * of whether any individual instruction descriptor carried a usable signature.\n */\nexport function toProgramEnumVariants(\n descriptors: Record<string, CalInstructionDescriptorDto>,\n mode: CalMode,\n): SolanaInstructionEnumVariant[] {\n return Object.values(descriptors).flatMap((dto) => toEnumVariants(dto, mode));\n}\n\n/**\n * Transform one validated CAL descriptor DTO into the core\n * {@link SolanaInstructionInfoPayload}. Returns a `Left` when the descriptor is\n * unusable (no signature for the configured `mode`), so the caller can surface\n * a per-descriptor ERROR rather than emitting an empty signature.\n *\n * `programId` comes from the enclosing `solana_programs` envelope `id`;\n * `discriminator` from the instruction's `discriminator_hex`.\n */\nexport function toInstructionInfoPayload(\n programId: string,\n discriminator: string,\n dto: CalInstructionDescriptorDto,\n mode: CalMode,\n): Either<Error, SolanaInstructionInfoPayload> {\n const signature = pickSignature(dto.descriptor.signatures, mode);\n if (!signature) {\n return Left(\n new Error(\n `[ContextModule] InstructionInfoDataSource: missing '${mode}' signature for (${programId}, ${discriminator})`,\n ),\n );\n }\n\n return Right({\n programId,\n discriminator,\n instructionInfo: {\n data: dto.descriptor.data,\n signature,\n },\n substructures: toSubstructures(dto),\n enumVariants: toEnumVariants(dto, mode),\n idlDescriptor: {\n typePool: dto.idl_descriptor?.type_pool ?? [],\n rootType: dto.idl_descriptor?.root_type ?? 0,\n },\n mintAssociations: dto.mint_association ? [dto.mint_association] : [],\n valueFlowPorts: toValueFlowPorts(dto.value_flow_ports),\n accountResets: toAccountResets(dto.account_resets),\n displayFields: toDisplayFields(dto.display_fields),\n });\n}\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,oBAAAC,EAAA,6BAAAC,EAAA,0BAAAC,EAAA,qBAAAC,IAAA,eAAAC,EAAAP,GAKA,IAAAQ,EAAyC,qBAEzCC,EAQO,iDACPC,EAAyB,oCAYzB,SAASC,EACPC,EACAC,EACoB,CACpB,OAAOD,EAAWC,CAAI,CACxB,CAMO,SAASP,EACdQ,EAA8B,CAAC,EACL,CAC1B,OAAOA,EAAK,IAAKC,IAAU,CACzB,gBAAiBA,EAAK,gBACtB,0BAA2BA,EAAK,0BAChC,YAAaA,EAAK,WACpB,EAAE,CACJ,CAEO,SAASb,EACdY,EAA6B,CAAC,EAC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Oe,CAAW,EAAE,QAAST,GAAQE,EAAeF,EAAKN,CAAI,CAAC,CAC9E,CAWO,SAAST,EACdyB,EACAC,EACAX,EACAN,EAC6C,CAC7C,MAAMkB,EAAYpB,EAAcQ,EAAI,WAAW,WAAYN,CAAI,EAC/D,OAAKkB,KAQE,SAAM,CACX,UAAAF,EACA,cAAAC,EACA,gBAAiB,CACf,KAAMX,EAAI,WAAW,KACrB,UAAAY,CACF,EACA,cAAeb,EAAgBC,CAAG,EAClC,aAAcE,EAAeF,EAAKN,CAAI,EACtC,cAAe,CACb,SAAUM,EAAI,gBAAgB,WAAa,CAAC,EAC5C,SAAUA,EAAI,gBAAgB,WAAa,CAC7C,EACA,iBAAkBA,EAAI,iBAAmB,CAACA,EAAI,gBAAgB,EAAI,CAAC,EACnE,eAAgBb,EAAiBa,EAAI,gBAAgB,EACrD,cAAejB,EAAgBiB,EAAI,cAAc,EACjD,cAAehB,EAAgBgB,EAAI,cAAc,CACnD,CAAC,KAxBQ,QACL,IAAI,MACF,uDAAuDN,CAAI,oBAAoBgB,CAAS,KAAKC,CAAa,GAC5G,CACF,CAqBJ",
4
+ "sourcesContent": ["// Maps the validated CAL instruction-descriptor DTOs into the core\n// `SolanaInstructionInfoPayload` model. Keeping this in the data layer means\n// the domain `InstructionInfoContextLoader` never has to know the CAL DTO\n// shapes \u2014 it consumes core models only.\n\nimport { type Either, Left, Right } from \"purify-ts\";\n\nimport {\n type SolanaCalAccountReset,\n type SolanaCalDisplayField,\n type SolanaCalValueFlowPort,\n type SolanaInstructionEnumVariant,\n type SolanaInstructionInfoPayload,\n type SolanaInstructionSubstructure,\n SolanaInstructionSubstructureKind,\n} from \"@/modules/solana/model/SolanaPayloads\";\nimport { u16Codec } from \"@/shared/utils/uIntCodec\";\n\nimport {\n type CalAccountResetDto,\n type CalDisplayFieldDto,\n type CalInstructionDescriptorDto,\n type CalSignatures,\n type CalValueFlowPortDto,\n} from \"./InstructionInfoDto\";\n\nexport type CalMode = \"prod\" | \"test\";\n\nfunction pickSignature(\n signatures: CalSignatures,\n mode: CalMode,\n): string | undefined {\n return signatures[mode];\n}\n\n// --- DTO \u2192 decoded-payload projections. Pick only the fields the host-side\n// requirement builder reads, dropping the signed-TLV `descriptor` carried by\n// the DTO. ---\n\nexport function toValueFlowPorts(\n dtos: CalValueFlowPortDto[] = [],\n): SolanaCalValueFlowPort[] {\n return dtos.map((port) => ({\n account_indices: port.account_indices,\n optional_account_strategy: port.optional_account_strategy,\n token_value: port.token_value,\n }));\n}\n\nexport function toAccountResets(\n dtos: CalAccountResetDto[] = [],\n): SolanaCalAccountReset[] {\n // Drop malformed resets (missing account_index) rather than defaulting to\n // slot 0, which would create an unintended TOKEN_ACCOUNT_STATE requirement.\n return dtos.flatMap((reset) =>\n reset.account_index === undefined\n ? []\n : [\n {\n account_index: reset.account_index,\n require_pre_balance_zero: reset.require_pre_balance_zero,\n },\n ],\n );\n}\n\nexport function toDisplayFields(\n dtos: CalDisplayFieldDto[] = [],\n): SolanaCalDisplayField[] {\n return dtos.map((field) => ({\n name: field.name,\n param: field.param ?? { type: \"\" },\n }));\n}\n\nfunction toSubstructures(\n dto: CalInstructionDescriptorDto,\n): SolanaInstructionSubstructure[] {\n return [\n ...(dto.display_fields ?? []).map((s) => ({\n kind: SolanaInstructionSubstructureKind.DISPLAY_FIELD,\n data: s.descriptor,\n })),\n ...(dto.value_flow_ports ?? []).map((s) => ({\n kind: SolanaInstructionSubstructureKind.VALUE_FLOW_PORT,\n data: s.descriptor,\n })),\n ...(dto.hide_rules ?? []).map((s) => ({\n kind: SolanaInstructionSubstructureKind.HIDE_RULE,\n data: s.descriptor,\n })),\n ...(dto.account_resets ?? []).map((s) => ({\n kind: SolanaInstructionSubstructureKind.ACCOUNT_RESET,\n data: s.descriptor,\n })),\n ];\n}\n\n/**\n * Flatten the CAL-bundled enum variants (keyed enumId \u2192 variantIndex). Keys\n * that don't validate as a u16 are skipped rather than leaking NaN/out-of-range\n * indices into the payload.\n */\nfunction toEnumVariants(\n dto: CalInstructionDescriptorDto,\n mode: CalMode,\n): SolanaInstructionEnumVariant[] {\n const enumVariants: SolanaInstructionEnumVariant[] = [];\n for (const [enumId, variants] of Object.entries(dto.enum_variants ?? {})) {\n for (const [variantIndex, variant] of Object.entries(variants)) {\n const index = Number(variantIndex);\n if (u16Codec.decode(index).isLeft()) {\n continue;\n }\n enumVariants.push({\n enumId,\n variantIndex: index,\n descriptor: {\n data: variant.descriptor.data,\n signature: pickSignature(variant.descriptor.signatures, mode) ?? \"\",\n },\n });\n }\n }\n return enumVariants;\n}\n\n/**\n * Flatten the enum variants of every descriptor in a program into a single\n * list. CAL nests `enum_variants` inside each instruction descriptor but\n * guarantees `(enumId, variantIndex)` is unique across a program, so the enum\n * loader resolves a selection against this program-level list \u2014 independently\n * of whether any individual instruction descriptor carried a usable signature.\n */\nexport function toProgramEnumVariants(\n descriptors: Record<string, CalInstructionDescriptorDto>,\n mode: CalMode,\n): SolanaInstructionEnumVariant[] {\n return Object.values(descriptors).flatMap((dto) => toEnumVariants(dto, mode));\n}\n\n/**\n * Transform one validated CAL descriptor DTO into the core\n * {@link SolanaInstructionInfoPayload}. Returns a `Left` when the descriptor is\n * unusable (no signature for the configured `mode`), so the caller can surface\n * a per-descriptor ERROR rather than emitting an empty signature.\n *\n * `programId` comes from the enclosing `solana_programs` envelope `id`;\n * `discriminator` from the instruction's `discriminator_hex`.\n */\nexport function toInstructionInfoPayload(\n programId: string,\n discriminator: string,\n dto: CalInstructionDescriptorDto,\n mode: CalMode,\n): Either<Error, SolanaInstructionInfoPayload> {\n const signature = pickSignature(dto.descriptor.signatures, mode);\n if (!signature) {\n return Left(\n new Error(\n `[ContextModule] InstructionInfoDataSource: missing '${mode}' signature for (${programId}, ${discriminator})`,\n ),\n );\n }\n\n return Right({\n programId,\n discriminator,\n instructionName: dto.instruction_name,\n instructionInfo: {\n data: dto.descriptor.data,\n signature,\n },\n substructures: toSubstructures(dto),\n enumVariants: toEnumVariants(dto, mode),\n idlDescriptor: {\n typePool: dto.idl_descriptor?.type_pool ?? [],\n rootType: dto.idl_descriptor?.root_type ?? 0,\n },\n mintAssociations: dto.mint_association ? [dto.mint_association] : [],\n valueFlowPorts: toValueFlowPorts(dto.value_flow_ports),\n accountResets: toAccountResets(dto.account_resets),\n displayFields: toDisplayFields(dto.display_fields),\n });\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,oBAAAC,EAAA,6BAAAC,EAAA,0BAAAC,EAAA,qBAAAC,IAAA,eAAAC,EAAAP,GAKA,IAAAQ,EAAyC,qBAEzCC,EAQO,iDACPC,EAAyB,oCAYzB,SAASC,EACPC,EACAC,EACoB,CACpB,OAAOD,EAAWC,CAAI,CACxB,CAMO,SAASP,EACdQ,EAA8B,CAAC,EACL,CAC1B,OAAOA,EAAK,IAAKC,IAAU,CACzB,gBAAiBA,EAAK,gBACtB,0BAA2BA,EAAK,0BAChC,YAAaA,EAAK,WACpB,EAAE,CACJ,CAEO,SAASb,EACdY,EAA6B,CAAC,EACL,CAGzB,OAAOA,EAAK,QAASE,GACnBA,EAAM,gBAAkB,OACpB,CAAC,EACD,CACE,CACE,cAAeA,EAAM,cACrB,yBAA0BA,EAAM,wBAClC,CACF,CACN,CACF,CAEO,SAASb,EACdW,EAA6B,CAAC,EACL,CACzB,OAAOA,EAAK,IAAKG,IAAW,CAC1B,KAAMA,EAAM,KACZ,MAAOA,EAAM,OAAS,CAAE,KAAM,EAAG,CACnC,EAAE,CACJ,CAEA,SAASC,EACPC,EACiC,CACjC,MAAO,CACL,IAAIA,EAAI,gBAAkB,CAAC,GAAG,IAAKC,IAAO,CACxC,KAAM,oCAAkC,cACxC,KAAMA,EAAE,UACV,EAAE,EACF,IAAID,EAAI,kBAAoB,CAAC,GAAG,IAAKC,IAAO,CAC1C,KAAM,oCAAkC,gBACxC,KAAMA,EAAE,UACV,EAAE,EACF,IAAID,EAAI,YAAc,CAAC,GAAG,IAAKC,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,EAAI,cAAc,EACjD,cAAehB,EAAgBgB,EAAI,cAAc,CACnD,CAAC,KAzBQ,QACL,IAAI,MACF,uDAAuDN,CAAI,oBAAoBgB,CAAS,KAAKC,CAAa,GAC5G,CACF,CAsBJ",
6
6
  "names": ["InstructionInfoMapper_exports", "__export", "toAccountResets", "toDisplayFields", "toInstructionInfoPayload", "toProgramEnumVariants", "toValueFlowPorts", "__toCommonJS", "import_purify_ts", "import_SolanaPayloads", "import_uIntCodec", "pickSignature", "signatures", "mode", "dtos", "port", "reset", "field", "toSubstructures", "dto", "s", "toEnumVariants", "enumVariants", "enumId", "variants", "variantIndex", "variant", "index", "descriptors", "programId", "discriminator", "signature"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var o=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var c=(t,n)=>{for(var e in n)o(t,e,{get:n[e],enumerable:!0})},d=(t,n,e,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let a of l(n))!p.call(t,a)&&a!==e&&o(t,a,{get:()=>n[a],enumerable:!(r=s(n,a))||r.enumerable});return t};var g=t=>d(o({},"__esModule",{value:!0}),t);var u={};c(u,{SolanaInstructionSubstructureKind:()=>i});module.exports=g(u);var i=(a=>(a[a.DISPLAY_FIELD=0]="DISPLAY_FIELD",a[a.VALUE_FLOW_PORT=1]="VALUE_FLOW_PORT",a[a.HIDE_RULE=2]="HIDE_RULE",a[a.ACCOUNT_RESET=3]="ACCOUNT_RESET",a))(i||{});0&&(module.exports={SolanaInstructionSubstructureKind});
1
+ "use strict";var o=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var d=(t,n)=>{for(var e in n)o(t,e,{get:n[e],enumerable:!0})},c=(t,n,e,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let a of l(n))!p.call(t,a)&&a!==e&&o(t,a,{get:()=>n[a],enumerable:!(r=s(n,a))||r.enumerable});return t};var g=t=>c(o({},"__esModule",{value:!0}),t);var u={};d(u,{SolanaInstructionSubstructureKind:()=>i});module.exports=g(u);var i=(a=>(a[a.DISPLAY_FIELD=0]="DISPLAY_FIELD",a[a.VALUE_FLOW_PORT=1]="VALUE_FLOW_PORT",a[a.HIDE_RULE=2]="HIDE_RULE",a[a.ACCOUNT_RESET=3]="ACCOUNT_RESET",a))(i||{});0&&(module.exports={SolanaInstructionSubstructureKind});
2
2
  //# sourceMappingURL=SolanaPayloads.js.map
@@ -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 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",
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 instructionName?: 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 mint?: string;\n};\n\nexport type SolanaAltResolutionPayload = {\n descriptor: Uint8Array;\n resolvedAddress?: string;\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,GAkFO,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 o=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var a=Object.prototype.hasOwnProperty;var g=(t,e,s,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of d(e))!a.call(t,n)&&n!==s&&o(t,n,{get:()=>e[n],enumerable:!(r=i(e,n))||r.enumerable});return t};var c=t=>g(o({},"__esModule",{value:!0}),t);var l={};module.exports=c(l);
1
+ "use strict";var s=Object.defineProperty;var o=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var a=(t,e,i,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of d(e))!g.call(t,n)&&n!==i&&s(t,n,{get:()=>e[n],enumerable:!(r=o(e,n))||r.enumerable});return t};var c=t=>a(s({},"__esModule",{value:!0}),t);var l={};module.exports=c(l);
2
2
  //# sourceMappingURL=SolanaTransactionContext.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/modules/solana/model/SolanaTransactionContext.ts"],
4
- "sourcesContent": ["import { type DeviceModelId } from \"@ledgerhq/device-management-kit\";\n\nexport type SolanaTransactionContext = {\n deviceModelId: DeviceModelId;\n challenge?: string;\n tokenAddress?: string;\n tokenInternalId?: string;\n templateId?: string;\n createATA?: {\n address: string;\n mintAddress: string;\n };\n};\n\nexport type SolanaSPLOwnerInfo = {\n tokenAccount: string;\n owner: string;\n contract: string;\n signedDescriptor: string;\n};\n"],
4
+ "sourcesContent": ["import { type DeviceModelId } from \"@ledgerhq/device-management-kit\";\n\nexport type SolanaTransactionContext = {\n deviceModelId: DeviceModelId;\n challenge?: string;\n tokenAddress?: string;\n tokenInternalId?: string;\n mintAddress?: string;\n templateId?: string;\n createATA?: {\n address: string;\n mintAddress: string;\n };\n};\n\nexport type SolanaSPLOwnerInfo = {\n tokenAccount: string;\n owner: string;\n contract: string;\n signedDescriptor: string;\n};\n"],
5
5
  "mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
6
6
  "names": ["SolanaTransactionContext_exports", "__toCommonJS"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/modules/solana/owner-info/data/HttpOwnerInfoDataSource.test.ts"],
4
- "sourcesContent": ["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n DeviceModelId,\n type DmkNetworkClient,\n hexaStringToBuffer,\n} from \"@ledgerhq/device-management-kit\";\nimport { Left } from \"purify-ts\";\n\nimport type { ContextModuleServiceConfig } from \"@/config/model/ContextModuleConfig\";\nimport { HttpOwnerInfoDataSource } from \"@/modules/solana/owner-info/data/HttpOwnerInfoDataSource\";\nimport type { SolanaTransactionContext } from \"@/modules/solana/owner-info/domain/solanaContextTypes\";\n\nfunction stringToHex(str: string): string {\n const encoder = new TextEncoder();\n const bytes = encoder.encode(str); // Uint8Array\n return Array.from(bytes)\n .map((byte) => byte.toString(16).padStart(2, \"0\"))\n .join(\"\");\n}\n\ndescribe(\"HttpOwnerInfoDataSource\", () => {\n const config = {\n metadataServiceDomain: { url: \"https://some.doma.in\" },\n originToken: \"mock-origin-token\",\n } as ContextModuleServiceConfig;\n\n const signedDescriptorHex = stringToHex(\"mock-descriptor\");\n const responseData = {\n tokenAccount: \"token-account\",\n owner: \"owner-address\",\n contract: \"contract-address\",\n signedDescriptor: signedDescriptorHex,\n };\n\n let httpMock: { get: ReturnType<typeof vi.fn> };\n\n beforeEach(() => {\n vi.resetAllMocks();\n httpMock = { get: vi.fn() };\n });\n\n it(\"should fetch address metadata via tokenAddress\", async () => {\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n httpMock.get.mockResolvedValueOnce(responseData);\n\n const dataSource = new HttpOwnerInfoDataSource(\n config,\n httpMock as unknown as DmkNetworkClient,\n );\n const result = await dataSource.getOwnerInfo(context);\n\n expect(httpMock.get).toHaveBeenCalledWith(\n `${config.metadataServiceDomain.url}/v2/solana/owner/some-token`,\n { params: { challenge: \"random\" } },\n );\n expect(result.isRight()).toBe(true);\n expect(result.extract()).toEqual({\n tlvDescriptor: hexaStringToBuffer(signedDescriptorHex),\n });\n });\n\n it(\"should return an error if both tokenAddress and createATA are missing or invalid\", async () => {\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: undefined,\n challenge: \"random\",\n createATA: undefined,\n };\n\n const dataSource = new HttpOwnerInfoDataSource(\n config,\n httpMock as unknown as DmkNetworkClient,\n );\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpOwnerInfoDataSource: either tokenAddress or valid createATA must be provided\",\n ),\n ),\n );\n });\n\n it(\"should return an error if challenge is missing\", async () => {\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: undefined,\n createATA: undefined,\n };\n\n const dataSource = new HttpOwnerInfoDataSource(\n config,\n httpMock as unknown as DmkNetworkClient,\n );\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpOwnerInfoDataSource: challenge is required\",\n ),\n ),\n );\n });\n\n it(\"should return an error if the descriptor is not valid base64\", async () => {\n httpMock.get.mockResolvedValueOnce({\n ...responseData,\n signedDescriptor: \"!!!not-valid-base64!!!\",\n });\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n\n const dataSource = new HttpOwnerInfoDataSource(\n config,\n httpMock as unknown as DmkNetworkClient,\n );\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpOwnerInfoDataSource: invalid base64 tlvDescriptor received\",\n ),\n ),\n );\n });\n\n it(\"should return an error if the metadata request fails\", async () => {\n httpMock.get.mockRejectedValueOnce(new Error(\"Network error\"));\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n\n const dataSource = new HttpOwnerInfoDataSource(\n config,\n httpMock as unknown as DmkNetworkClient,\n );\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpOwnerInfoDataSource: Failed to fetch address metadata\",\n ),\n ),\n );\n });\n\n it(\"should return an error if fetch request return wrong shape for fetchAddressMetadata\", async () => {\n httpMock.get.mockResolvedValueOnce({ wrong: \"field\" });\n\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n\n const dataSource = new HttpOwnerInfoDataSource(\n config,\n httpMock as unknown as DmkNetworkClient,\n );\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpOwnerInfoDataSource: invalid fetchAddressMetadata response shape\",\n ),\n ),\n );\n });\n\n it(\"should return an error if fetch request return wrong shape for computeAddressMetadata\", async () => {\n httpMock.get.mockResolvedValueOnce({ wrong: \"field\" });\n\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: undefined,\n challenge: \"random\",\n createATA: {\n address: \"some-address\",\n mintAddress: \"some-mint\",\n },\n };\n\n const dataSource = new HttpOwnerInfoDataSource(\n config,\n httpMock as unknown as DmkNetworkClient,\n );\n const result = await dataSource.getOwnerInfo(context);\n\n expect(httpMock.get).toHaveBeenCalledWith(\n `${config.metadataServiceDomain.url}/v2/solana/computed-token-account/some-address/some-mint`,\n { params: { challenge: \"random\" } },\n );\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpOwnerInfoDataSource: invalid computeAddressMetadata response shape\",\n ),\n ),\n );\n });\n});\n"],
5
- "mappings": "aACA,IAAAA,EAIO,2CACPC,EAAqB,qBAGrBC,EAAwC,oEAGxC,SAASC,EAAYC,EAAqB,CAExC,MAAMC,EADU,IAAI,YAAY,EACV,OAAOD,CAAG,EAChC,OAAO,MAAM,KAAKC,CAAK,EACpB,IAAKC,GAASA,EAAK,SAAS,EAAE,EAAE,SAAS,EAAG,GAAG,CAAC,EAChD,KAAK,EAAE,CACZ,CAEA,SAAS,0BAA2B,IAAM,CACxC,MAAMC,EAAS,CACb,sBAAuB,CAAE,IAAK,sBAAuB,EACrD,YAAa,mBACf,EAEMC,EAAsBL,EAAY,iBAAiB,EACnDM,EAAe,CACnB,aAAc,gBACd,MAAO,gBACP,SAAU,mBACV,iBAAkBD,CACpB,EAEA,IAAIE,EAEJ,WAAW,IAAM,CACf,GAAG,cAAc,EACjBA,EAAW,CAAE,IAAK,GAAG,GAAG,CAAE,CAC5B,CAAC,EAED,GAAG,iDAAkD,SAAY,CAC/D,MAAMC,EAAoC,C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G,uDAAwD,SAAY,CACrEF,EAAS,IAAI,sBAAsB,IAAI,MAAM,eAAe,CAAC,EAC7D,MAAMC,EAAoC,CACxC,cAAe,gBAAc,KAC7B,aAAc,aACd,UAAW,SACX,UAAW,MACb,EAMMC,EAAS,MAJI,IAAI,0BACrBL,EACAG,CACF,EACgC,aAAaC,CAAO,EAEpD,OAAOC,CAAM,EAAE,WACb,QACE,IAAI,MACF,6EACF,CACF,CACF,CACF,CAAC,EAED,GAAG,sFAAuF,SAAY,CACpGF,EAAS,IAAI,sBAAsB,CAAE,MAAO,OAAQ,CAAC,EAErD,MAAMC,EAAoC,CACxC,cAAe,gBAAc,KAC7B,aAAc,aACd,UAAW,SACX,UAAW,MACb,EAMMC,EAAS,MAJI,IAAI,0BACrBL,EACAG,CACF,EACgC,aAAaC,CAAO,EAEpD,OAAOC,CAAM,EAAE,WACb,QACE,IAAI,MACF,wFACF,CACF,CACF,CACF,CAAC,EAED,GAAG,wFAAyF,SAAY,CACtGF,EAAS,IAAI,sBAAsB,CAAE,MAAO,OAAQ,CAAC,EAErD,MAAMC,EAAoC,CACxC,cAAe,gBAAc,KAC7B,aAAc,OACd,UAAW,SACX,UAAW,CACT,QAAS,eACT,YAAa,WACf,CACF,EAMMC,EAAS,MAJI,IAAI,0BACrBL,EACAG,CACF,EACgC,aAAaC,CAAO,EAEpD,OAAOD,EAAS,GAAG,EAAE,qBACnB,GAAGH,EAAO,sBAAsB,GAAG,2DACnC,CAAE,OAAQ,CAAE,UAAW,QAAS,CAAE,CACpC,EACA,OAAOK,CAAM,EAAE,WACb,QACE,IAAI,MACF,0FACF,CACF,CACF,CACF,CAAC,CACH,CAAC",
4
+ "sourcesContent": ["import {\n DeviceModelId,\n type DmkNetworkClient,\n hexaStringToBuffer,\n} from \"@ledgerhq/device-management-kit\";\nimport { Left } from \"purify-ts\";\n\nimport type { ContextModuleServiceConfig } from \"@/config/model/ContextModuleConfig\";\nimport { HttpOwnerInfoDataSource } from \"@/modules/solana/owner-info/data/HttpOwnerInfoDataSource\";\nimport type { SolanaTransactionContext } from \"@/modules/solana/owner-info/domain/solanaContextTypes\";\n\nfunction stringToHex(str: string): string {\n const encoder = new TextEncoder();\n const bytes = encoder.encode(str); // Uint8Array\n return Array.from(bytes)\n .map((byte) => byte.toString(16).padStart(2, \"0\"))\n .join(\"\");\n}\n\ndescribe(\"HttpOwnerInfoDataSource\", () => {\n const config = {\n metadataServiceDomain: { url: \"https://some.doma.in\" },\n originToken: \"mock-origin-token\",\n } as ContextModuleServiceConfig;\n\n const signedDescriptorHex = stringToHex(\"mock-descriptor\");\n const responseData = {\n tokenAccount: \"token-account\",\n owner: \"owner-address\",\n contract: \"contract-address\",\n signedDescriptor: signedDescriptorHex,\n };\n\n let httpMock: { get: ReturnType<typeof vi.fn> };\n\n beforeEach(() => {\n vi.resetAllMocks();\n httpMock = { get: vi.fn() };\n });\n\n it(\"should fetch address metadata via tokenAddress\", async () => {\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n httpMock.get.mockResolvedValueOnce(responseData);\n\n const dataSource = new HttpOwnerInfoDataSource(\n config,\n httpMock as unknown as DmkNetworkClient,\n );\n const result = await dataSource.getOwnerInfo(context);\n\n expect(httpMock.get).toHaveBeenCalledWith(\n `${config.metadataServiceDomain.url}/v2/solana/owner/some-token`,\n { params: { challenge: \"random\" } },\n );\n expect(result.isRight()).toBe(true);\n expect(result.extract()).toEqual({\n tlvDescriptor: hexaStringToBuffer(signedDescriptorHex),\n });\n });\n\n it(\"should return an error if both tokenAddress and createATA are missing or invalid\", async () => {\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: undefined,\n challenge: \"random\",\n createATA: undefined,\n };\n\n const dataSource = new HttpOwnerInfoDataSource(\n config,\n httpMock as unknown as DmkNetworkClient,\n );\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpOwnerInfoDataSource: either tokenAddress or valid createATA must be provided\",\n ),\n ),\n );\n });\n\n it(\"should return an error if challenge is missing\", async () => {\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: undefined,\n createATA: undefined,\n };\n\n const dataSource = new HttpOwnerInfoDataSource(\n config,\n httpMock as unknown as DmkNetworkClient,\n );\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpOwnerInfoDataSource: challenge is required\",\n ),\n ),\n );\n });\n\n it(\"should return an error if the descriptor is not valid base64\", async () => {\n httpMock.get.mockResolvedValueOnce({\n ...responseData,\n signedDescriptor: \"!!!not-valid-base64!!!\",\n });\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n\n const dataSource = new HttpOwnerInfoDataSource(\n config,\n httpMock as unknown as DmkNetworkClient,\n );\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpOwnerInfoDataSource: invalid base64 tlvDescriptor received\",\n ),\n ),\n );\n });\n\n it(\"should return an error if the metadata request fails\", async () => {\n httpMock.get.mockRejectedValueOnce(new Error(\"Network error\"));\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n\n const dataSource = new HttpOwnerInfoDataSource(\n config,\n httpMock as unknown as DmkNetworkClient,\n );\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpOwnerInfoDataSource: Failed to fetch address metadata\",\n ),\n ),\n );\n });\n\n it(\"should return an error if fetch request return wrong shape for fetchAddressMetadata\", async () => {\n httpMock.get.mockResolvedValueOnce({ wrong: \"field\" });\n\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: \"some-token\",\n challenge: \"random\",\n createATA: undefined,\n };\n\n const dataSource = new HttpOwnerInfoDataSource(\n config,\n httpMock as unknown as DmkNetworkClient,\n );\n const result = await dataSource.getOwnerInfo(context);\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpOwnerInfoDataSource: invalid fetchAddressMetadata response shape\",\n ),\n ),\n );\n });\n\n it(\"should return an error if fetch request return wrong shape for computeAddressMetadata\", async () => {\n httpMock.get.mockResolvedValueOnce({ wrong: \"field\" });\n\n const context: SolanaTransactionContext = {\n deviceModelId: DeviceModelId.FLEX,\n tokenAddress: undefined,\n challenge: \"random\",\n createATA: {\n address: \"some-address\",\n mintAddress: \"some-mint\",\n },\n };\n\n const dataSource = new HttpOwnerInfoDataSource(\n config,\n httpMock as unknown as DmkNetworkClient,\n );\n const result = await dataSource.getOwnerInfo(context);\n\n expect(httpMock.get).toHaveBeenCalledWith(\n `${config.metadataServiceDomain.url}/v2/solana/computed-token-account/some-address/some-mint`,\n { params: { challenge: \"random\" } },\n );\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] - HttpOwnerInfoDataSource: invalid computeAddressMetadata response shape\",\n ),\n ),\n );\n });\n});\n"],
5
+ "mappings": "aAAA,IAAAA,EAIO,2CACPC,EAAqB,qBAGrBC,EAAwC,oEAGxC,SAASC,EAAYC,EAAqB,CAExC,MAAMC,EADU,IAAI,YAAY,EACV,OAAOD,CAAG,EAChC,OAAO,MAAM,KAAKC,CAAK,EACpB,IAAKC,GAASA,EAAK,SAAS,EAAE,EAAE,SAAS,EAAG,GAAG,CAAC,EAChD,KAAK,EAAE,CACZ,CAEA,SAAS,0BAA2B,IAAM,CACxC,MAAMC,EAAS,CACb,sBAAuB,CAAE,IAAK,sBAAuB,EACrD,YAAa,mBACf,EAEMC,EAAsBL,EAAY,iBAAiB,EACnDM,EAAe,CACnB,aAAc,gBACd,MAAO,gBACP,SAAU,mBACV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ACd,UAAW,SACX,UAAW,MACb,EAMMC,EAAS,MAJI,IAAI,0BACrBL,EACAG,CACF,EACgC,aAAaC,CAAO,EAEpD,OAAOC,CAAM,EAAE,WACb,QACE,IAAI,MACF,kFACF,CACF,CACF,CACF,CAAC,EAED,GAAG,uDAAwD,SAAY,CACrEF,EAAS,IAAI,sBAAsB,IAAI,MAAM,eAAe,CAAC,EAC7D,MAAMC,EAAoC,CACxC,cAAe,gBAAc,KAC7B,aAAc,aACd,UAAW,SACX,UAAW,MACb,EAMMC,EAAS,MAJI,IAAI,0BACrBL,EACAG,CACF,EACgC,aAAaC,CAAO,EAEpD,OAAOC,CAAM,EAAE,WACb,QACE,IAAI,MACF,6EACF,CACF,CACF,CACF,CAAC,EAED,GAAG,sFAAuF,SAAY,CACpGF,EAAS,IAAI,sBAAsB,CAAE,MAAO,OAAQ,CAAC,EAErD,MAAMC,EAAoC,CACxC,cAAe,gBAAc,KAC7B,aAAc,aACd,UAAW,SACX,UAAW,MACb,EAMMC,EAAS,MAJI,IAAI,0BACrBL,EACAG,CACF,EACgC,aAAaC,CAAO,EAEpD,OAAOC,CAAM,EAAE,WACb,QACE,IAAI,MACF,wFACF,CACF,CACF,CACF,CAAC,EAED,GAAG,wFAAyF,SAAY,CACtGF,EAAS,IAAI,sBAAsB,CAAE,MAAO,OAAQ,CAAC,EAErD,MAAMC,EAAoC,CACxC,cAAe,gBAAc,KAC7B,aAAc,OACd,UAAW,SACX,UAAW,CACT,QAAS,eACT,YAAa,WACf,CACF,EAMMC,EAAS,MAJI,IAAI,0BACrBL,EACAG,CACF,EACgC,aAAaC,CAAO,EAEpD,OAAOD,EAAS,GAAG,EAAE,qBACnB,GAAGH,EAAO,sBAAsB,GAAG,2DACnC,CAAE,OAAQ,CAAE,UAAW,QAAS,CAAE,CACpC,EACA,OAAOK,CAAM,EAAE,WACb,QACE,IAAI,MACF,0FACF,CACF,CACF,CACF,CAAC,CACH,CAAC",
6
6
  "names": ["import_device_management_kit", "import_purify_ts", "import_HttpOwnerInfoDataSource", "stringToHex", "str", "bytes", "byte", "config", "signedDescriptorHex", "responseData", "httpMock", "context", "result"]
7
7
  }
@@ -0,0 +1,2 @@
1
+ "use strict";var c=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var y=(o,t)=>{for(var r in t)c(o,r,{get:t[r],enumerable:!0})},C=(o,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of h(t))!k.call(o,e)&&e!==r&&c(o,e,{get:()=>t[e],enumerable:!(i=p(t,e))||i.enumerable});return o};var w=o=>C(c({},"__esModule",{value:!0}),o),l=(o,t,r,i)=>{for(var e=i>1?void 0:i?p(t,r):t,f=o.length-1,s;f>=0;f--)(s=o[f])&&(e=(i?s(t,r,e):s(e))||e);return i&&e&&c(t,r,e),e},d=(o,t)=>(r,i)=>t(r,i,o);var M={};y(M,{HttpMintToIdDataSource:()=>n});module.exports=w(M);var a=require("inversify"),m=require("purify-ts"),u=require("../../../../config/di/configTypes"),g=require("../../../../shared/network/di/networkTypes");let n=class{constructor(t,r){this.config=t;this.http=r}async getIdFromMint({mintAddress:t}){try{const r=await this.http.get(`${this.config.cal.url}/tokens`,{params:{contract_address:t,network:"solana",output:"id",ref:`branch:${this.config.cal.branch}`}});return!r||r.length===0||!r[0]?.id?(0,m.Left)(new Error(`[ContextModule] HttpMintToIdDataSource: no token id found for mint ${t}`)):(0,m.Right)(r[0].id)}catch{return(0,m.Left)(new Error("[ContextModule] HttpMintToIdDataSource: failed to fetch token id from mint address"))}}};n=l([(0,a.injectable)(),d(0,(0,a.inject)(u.configTypes.Config)),d(1,(0,a.inject)(g.networkTypes.NetworkClient))],n);0&&(module.exports={HttpMintToIdDataSource});
2
+ //# sourceMappingURL=HttpMintToIdDataSource.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../../src/modules/solana/token/data/HttpMintToIdDataSource.ts"],
4
+ "sourcesContent": ["import { DmkNetworkClient } 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 { networkTypes } from \"@/shared/network/di/networkTypes\";\n\nimport {\n type GetIdFromMintParams,\n type MintToIdDataSource,\n} from \"./MintToIdDataSource\";\n\n@injectable()\nexport class HttpMintToIdDataSource implements MintToIdDataSource {\n constructor(\n @inject(configTypes.Config)\n private readonly config: ContextModuleServiceConfig,\n @inject(networkTypes.NetworkClient)\n private readonly http: DmkNetworkClient,\n ) {}\n\n public async getIdFromMint({\n mintAddress,\n }: GetIdFromMintParams): Promise<Either<Error, string>> {\n try {\n const data = (await this.http.get(`${this.config.cal.url}/tokens`, {\n params: {\n contract_address: mintAddress,\n network: \"solana\",\n output: \"id\",\n ref: `branch:${this.config.cal.branch}`,\n },\n })) as Array<{ id?: string }>;\n\n if (!data || data.length === 0 || !data[0]?.id) {\n return Left(\n new Error(\n `[ContextModule] HttpMintToIdDataSource: no token id found for mint ${mintAddress}`,\n ),\n );\n }\n\n return Right(data[0].id);\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] HttpMintToIdDataSource: failed to fetch token id from mint address\",\n ),\n );\n }\n }\n}\n"],
5
+ "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,4BAAAE,IAAA,eAAAC,EAAAH,GACA,IAAAI,EAAmC,qBACnCC,EAAoC,qBAEpCC,EAA4B,mCAE5BC,EAA6B,4CAQtB,IAAMC,EAAN,KAA2D,CAChE,YAEmBC,EAEAC,EACjB,CAHiB,YAAAD,EAEA,UAAAC,CAChB,CAEH,MAAa,cAAc,CACzB,YAAAC,CACF,EAAwD,CACtD,GAAI,CACF,MAAMC,EAAQ,MAAM,KAAK,KAAK,IAAI,GAAG,KAAK,OAAO,IAAI,GAAG,UAAW,CACjE,OAAQ,CACN,iBAAkBD,EAClB,QAAS,SACT,OAAQ,KACR,IAAK,UAAU,KAAK,OAAO,IAAI,MAAM,EACvC,CACF,CAAC,EAED,MAAI,CAACC,GAAQA,EAAK,SAAW,GAAK,CAACA,EAAK,CAAC,GAAG,MACnC,QACL,IAAI,MACF,sEAAsED,CAAW,EACnF,CACF,KAGK,SAAMC,EAAK,CAAC,EAAE,EAAE,CACzB,MAAiB,CACf,SAAO,QACL,IAAI,MACF,oFACF,CACF,CACF,CACF,CACF,EAtCaJ,EAANK,EAAA,IADN,cAAW,EAGPC,EAAA,eAAO,cAAY,MAAM,GAEzBA,EAAA,eAAO,eAAa,aAAa,IAJzBN",
6
+ "names": ["HttpMintToIdDataSource_exports", "__export", "HttpMintToIdDataSource", "__toCommonJS", "import_inversify", "import_purify_ts", "import_configTypes", "import_networkTypes", "HttpMintToIdDataSource", "config", "http", "mintAddress", "data", "__decorateClass", "__decorateParam"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var t=require("vitest"),s=require("./HttpMintToIdDataSource");(0,t.describe)("HttpMintToIdDataSource",()=>{let n,o;const r="3iql8bfs2Ve7mwW4EHaqqHasbmrnCrPxiZWat2ZFyr9Y",a={cal:{url:"https://global.api.prd.ledger.com/cal/v1",branch:"main"}};(0,t.beforeEach)(()=>{t.vi.clearAllMocks(),o={get:t.vi.fn()},n=new s.HttpMintToIdDataSource(a,o)}),(0,t.it)("calls the correct endpoint with the right params",async()=>{o.get.mockResolvedValue([{id:"sol:usdc"}]),await n.getIdFromMint({mintAddress:r}),(0,t.expect)(o.get).toHaveBeenCalledWith(`${a.cal.url}/tokens`,{params:{contract_address:r,network:"solana",output:"id",ref:`branch:${a.cal.branch}`}})}),(0,t.it)("returns Right with id when response contains a token",async()=>{o.get.mockResolvedValue([{id:"sol:usdc"}]);const e=await n.getIdFromMint({mintAddress:r});(0,t.expect)(e.isRight()).toBe(!0),(0,t.expect)(e.extract()).toBe("sol:usdc")}),(0,t.it)("returns Left when response is an empty array",async()=>{o.get.mockResolvedValue([]);const e=await n.getIdFromMint({mintAddress:r});(0,t.expect)(e.isLeft()).toBe(!0),(0,t.expect)(e.extract().message).toContain(`no token id found for mint ${r}`)}),(0,t.it)("returns Left when response entry has no id field",async()=>{o.get.mockResolvedValue([{}]);const e=await n.getIdFromMint({mintAddress:r});(0,t.expect)(e.isLeft()).toBe(!0),(0,t.expect)(e.extract().message).toContain(`no token id found for mint ${r}`)}),(0,t.it)("returns Left when http.get throws",async()=>{o.get.mockRejectedValue(new Error("network error"));const e=await n.getIdFromMint({mintAddress:r});(0,t.expect)(e.isLeft()).toBe(!0),(0,t.expect)(e.extract().message).toContain("failed to fetch token id from mint address")})});
2
+ //# sourceMappingURL=HttpMintToIdDataSource.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../../src/modules/solana/token/data/HttpMintToIdDataSource.test.ts"],
4
+ "sourcesContent": ["import { type DmkNetworkClient } from \"@ledgerhq/device-management-kit\";\nimport { beforeEach, describe, expect, it, vi } from \"vitest\";\n\nimport { type ContextModuleServiceConfig } from \"@/config/model/ContextModuleConfig\";\n\nimport { HttpMintToIdDataSource } from \"./HttpMintToIdDataSource\";\n\ndescribe(\"HttpMintToIdDataSource\", () => {\n let datasource: HttpMintToIdDataSource;\n let httpMock: { get: ReturnType<typeof vi.fn> };\n\n const mintAddress = \"3iql8bfs2Ve7mwW4EHaqqHasbmrnCrPxiZWat2ZFyr9Y\";\n const config = {\n cal: {\n url: \"https://global.api.prd.ledger.com/cal/v1\",\n branch: \"main\",\n },\n } as ContextModuleServiceConfig;\n\n beforeEach(() => {\n vi.clearAllMocks();\n httpMock = { get: vi.fn() };\n datasource = new HttpMintToIdDataSource(\n config,\n httpMock as unknown as DmkNetworkClient,\n );\n });\n\n it(\"calls the correct endpoint with the right params\", async () => {\n httpMock.get.mockResolvedValue([{ id: \"sol:usdc\" }]);\n\n await datasource.getIdFromMint({ mintAddress });\n\n expect(httpMock.get).toHaveBeenCalledWith(`${config.cal.url}/tokens`, {\n params: {\n contract_address: mintAddress,\n network: \"solana\",\n output: \"id\",\n ref: `branch:${config.cal.branch}`,\n },\n });\n });\n\n it(\"returns Right with id when response contains a token\", async () => {\n httpMock.get.mockResolvedValue([{ id: \"sol:usdc\" }]);\n\n const result = await datasource.getIdFromMint({ mintAddress });\n\n expect(result.isRight()).toBe(true);\n expect(result.extract()).toBe(\"sol:usdc\");\n });\n\n it(\"returns Left when response is an empty array\", async () => {\n httpMock.get.mockResolvedValue([]);\n\n const result = await datasource.getIdFromMint({ mintAddress });\n\n expect(result.isLeft()).toBe(true);\n expect((result.extract() as Error).message).toContain(\n `no token id found for mint ${mintAddress}`,\n );\n });\n\n it(\"returns Left when response entry has no id field\", async () => {\n httpMock.get.mockResolvedValue([{}]);\n\n const result = await datasource.getIdFromMint({ mintAddress });\n\n expect(result.isLeft()).toBe(true);\n expect((result.extract() as Error).message).toContain(\n `no token id found for mint ${mintAddress}`,\n );\n });\n\n it(\"returns Left when http.get throws\", async () => {\n httpMock.get.mockRejectedValue(new Error(\"network error\"));\n\n const result = await datasource.getIdFromMint({ mintAddress });\n\n expect(result.isLeft()).toBe(true);\n expect((result.extract() as Error).message).toContain(\n \"failed to fetch token id from mint address\",\n );\n });\n});\n"],
5
+ "mappings": "aACA,IAAAA,EAAqD,kBAIrDC,EAAuC,uCAEvC,YAAS,yBAA0B,IAAM,CACvC,IAAIC,EACAC,EAEJ,MAAMC,EAAc,+CACdC,EAAS,CACb,IAAK,CACH,IAAK,2CACL,OAAQ,MACV,CACF,KAEA,cAAW,IAAM,CACf,KAAG,cAAc,EACjBF,EAAW,CAAE,IAAK,KAAG,GAAG,CAAE,EAC1BD,EAAa,IAAI,yBACfG,EACAF,CACF,CACF,CAAC,KAED,MAAG,mDAAoD,SAAY,CACjEA,EAAS,IAAI,kBAAkB,CAAC,CAAE,GAAI,UAAW,CAAC,CAAC,EAEnD,MAAMD,EAAW,cAAc,CAAE,Y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AO,QAAQ,EAAY,OAAO,EAAE,UAC1C,4CACF,CACF,CAAC,CACH,CAAC",
6
+ "names": ["import_vitest", "import_HttpMintToIdDataSource", "datasource", "httpMock", "mintAddress", "config", "result"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var o=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var n=Object.getOwnPropertyNames;var s=Object.prototype.hasOwnProperty;var d=(t,r,m,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let e of n(r))!s.call(t,e)&&e!==m&&o(t,e,{get:()=>r[e],enumerable:!(i=a(r,e))||i.enumerable});return t};var p=t=>d(o({},"__esModule",{value:!0}),t);var I={};module.exports=p(I);
2
+ //# sourceMappingURL=MintToIdDataSource.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../../src/modules/solana/token/data/MintToIdDataSource.ts"],
4
+ "sourcesContent": ["import { type Either } from \"purify-ts\";\n\nexport type GetIdFromMintParams = {\n mintAddress: string;\n};\n\nexport interface MintToIdDataSource {\n getIdFromMint(params: GetIdFromMintParams): Promise<Either<Error, string>>;\n}\n"],
5
+ "mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
6
+ "names": ["MintToIdDataSource_exports", "__toCommonJS"]
7
+ }
@@ -1,2 +1,2 @@
1
- "use strict";var n=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var i=Object.prototype.hasOwnProperty;var u=(o,t)=>{for(var r in t)n(o,r,{get:t[r],enumerable:!0})},d=(o,t,r,m)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of f(t))!i.call(o,e)&&e!==r&&n(o,e,{get:()=>t[e],enumerable:!(m=c(t,e))||m.enumerable});return o};var x=o=>d(n({},"__esModule",{value:!0}),o);var l={};u(l,{tokenModuleFactory:()=>C});module.exports=x(l);var p=require("inversify"),k=require("../../../../modules/solana/token/data/HttpTokenDataSource"),a=require("../../../../modules/solana/token/di/tokenTypes"),T=require("../../../../modules/solana/token/domain/TokenContextLoader");const C=()=>new p.ContainerModule(({bind:o})=>{o(a.tokenTypes.TokenDataSource).to(k.HttpTokenDataSource),o(a.tokenTypes.TokenContextLoader).to(T.TokenContextLoader)});0&&(module.exports={tokenModuleFactory});
1
+ "use strict";var n=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var d=(o,t)=>{for(var r in t)n(o,r,{get:t[r],enumerable:!0})},D=(o,t,r,m)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of u(t))!f.call(o,e)&&e!==r&&n(o,e,{get:()=>t[e],enumerable:!(m=k(t,e))||m.enumerable});return o};var M=o=>D(n({},"__esModule",{value:!0}),o);var x={};d(x,{tokenModuleFactory:()=>S});module.exports=M(x);var p=require("inversify"),T=require("../../../../modules/solana/token/data/HttpMintToIdDataSource"),c=require("../../../../modules/solana/token/data/HttpTokenDataSource"),a=require("../../../../modules/solana/token/di/tokenTypes"),i=require("../../../../modules/solana/token/domain/TokenContextLoader");const S=()=>new p.ContainerModule(({bind:o})=>{o(a.tokenTypes.TokenDataSource).to(c.HttpTokenDataSource),o(a.tokenTypes.MintToIdDataSource).to(T.HttpMintToIdDataSource),o(a.tokenTypes.TokenContextLoader).to(i.TokenContextLoader)});0&&(module.exports={tokenModuleFactory});
2
2
  //# sourceMappingURL=tokenModuleFactory.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/modules/solana/token/di/tokenModuleFactory.ts"],
4
- "sourcesContent": ["import { ContainerModule } from \"inversify\";\n\nimport { HttpTokenDataSource } from \"@/modules/solana/token/data/HttpTokenDataSource\";\nimport { tokenTypes } from \"@/modules/solana/token/di/tokenTypes\";\nimport { TokenContextLoader } from \"@/modules/solana/token/domain/TokenContextLoader\";\n\nexport const tokenModuleFactory = () =>\n new ContainerModule(({ bind }) => {\n bind(tokenTypes.TokenDataSource).to(HttpTokenDataSource);\n bind(tokenTypes.TokenContextLoader).to(TokenContextLoader);\n });\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,wBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAgC,qBAEhCC,EAAoC,2DACpCC,EAA2B,gDAC3BC,EAAmC,4DAE5B,MAAML,EAAqB,IAChC,IAAI,kBAAgB,CAAC,CAAE,KAAAM,CAAK,IAAM,CAChCA,EAAK,aAAW,eAAe,EAAE,GAAG,qBAAmB,EACvDA,EAAK,aAAW,kBAAkB,EAAE,GAAG,oBAAkB,CAC3D,CAAC",
6
- "names": ["tokenModuleFactory_exports", "__export", "tokenModuleFactory", "__toCommonJS", "import_inversify", "import_HttpTokenDataSource", "import_tokenTypes", "import_TokenContextLoader", "bind"]
4
+ "sourcesContent": ["import { ContainerModule } from \"inversify\";\n\nimport { HttpMintToIdDataSource } from \"@/modules/solana/token/data/HttpMintToIdDataSource\";\nimport { HttpTokenDataSource } from \"@/modules/solana/token/data/HttpTokenDataSource\";\nimport { tokenTypes } from \"@/modules/solana/token/di/tokenTypes\";\nimport { TokenContextLoader } from \"@/modules/solana/token/domain/TokenContextLoader\";\n\nexport const tokenModuleFactory = () =>\n new ContainerModule(({ bind }) => {\n bind(tokenTypes.TokenDataSource).to(HttpTokenDataSource);\n bind(tokenTypes.MintToIdDataSource).to(HttpMintToIdDataSource);\n bind(tokenTypes.TokenContextLoader).to(TokenContextLoader);\n });\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,wBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAgC,qBAEhCC,EAAuC,8DACvCC,EAAoC,2DACpCC,EAA2B,gDAC3BC,EAAmC,4DAE5B,MAAMN,EAAqB,IAChC,IAAI,kBAAgB,CAAC,CAAE,KAAAO,CAAK,IAAM,CAChCA,EAAK,aAAW,eAAe,EAAE,GAAG,qBAAmB,EACvDA,EAAK,aAAW,kBAAkB,EAAE,GAAG,wBAAsB,EAC7DA,EAAK,aAAW,kBAAkB,EAAE,GAAG,oBAAkB,CAC3D,CAAC",
6
+ "names": ["tokenModuleFactory_exports", "__export", "tokenModuleFactory", "__toCommonJS", "import_inversify", "import_HttpMintToIdDataSource", "import_HttpTokenDataSource", "import_tokenTypes", "import_TokenContextLoader", "bind"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var r=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var c=(e,o)=>{for(var n in o)r(e,n,{get:o[n],enumerable:!0})},x=(e,o,n,a)=>{if(o&&typeof o=="object"||typeof o=="function")for(let t of T(o))!S.call(e,t)&&t!==n&&r(e,t,{get:()=>o[t],enumerable:!(a=k(o,t))||a.enumerable});return e};var y=e=>x(r({},"__esModule",{value:!0}),e);var d={};c(d,{tokenTypes:()=>b});module.exports=y(d);const b={TokenDataSource:Symbol.for("TokenDataSource"),TokenContextLoader:Symbol.for("TokenContextLoader")};0&&(module.exports={tokenTypes});
1
+ "use strict";var n=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var k=(e,o)=>{for(var a in o)n(e,a,{get:o[a],enumerable:!0})},d=(e,o,a,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let t of T(o))!c.call(e,t)&&t!==a&&n(e,t,{get:()=>o[t],enumerable:!(r=S(o,t))||r.enumerable});return e};var u=e=>d(n({},"__esModule",{value:!0}),e);var D={};k(D,{tokenTypes:()=>y});module.exports=u(D);const y={TokenDataSource:Symbol.for("TokenDataSource"),MintToIdDataSource:Symbol.for("MintToIdDataSource"),TokenContextLoader:Symbol.for("TokenContextLoader")};0&&(module.exports={tokenTypes});
2
2
  //# sourceMappingURL=tokenTypes.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/modules/solana/token/di/tokenTypes.ts"],
4
- "sourcesContent": ["export const tokenTypes = {\n TokenDataSource: Symbol.for(\"TokenDataSource\"),\n TokenContextLoader: Symbol.for(\"TokenContextLoader\"),\n};\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gBAAAE,IAAA,eAAAC,EAAAH,GAAO,MAAME,EAAa,CACxB,gBAAiB,OAAO,IAAI,iBAAiB,EAC7C,mBAAoB,OAAO,IAAI,oBAAoB,CACrD",
4
+ "sourcesContent": ["export const tokenTypes = {\n TokenDataSource: Symbol.for(\"TokenDataSource\"),\n MintToIdDataSource: Symbol.for(\"MintToIdDataSource\"),\n TokenContextLoader: Symbol.for(\"TokenContextLoader\"),\n};\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gBAAAE,IAAA,eAAAC,EAAAH,GAAO,MAAME,EAAa,CACxB,gBAAiB,OAAO,IAAI,iBAAiB,EAC7C,mBAAoB,OAAO,IAAI,oBAAoB,EACnD,mBAAoB,OAAO,IAAI,oBAAoB,CACrD",
6
6
  "names": ["tokenTypes_exports", "__export", "tokenTypes", "__toCommonJS"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var d=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var x=(a,e)=>{for(var t in e)d(a,t,{get:e[t],enumerable:!0})},I=(a,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of m(e))!T.call(a,o)&&o!==t&&d(a,o,{get:()=>e[o],enumerable:!(r=g(e,o))||r.enumerable});return a};var R=a=>I(d({},"__esModule",{value:!0}),a),u=(a,e,t,r)=>{for(var o=r>1?void 0:r?g(e,t):e,l=a.length-1,n;l>=0;l--)(n=a[l])&&(o=(r?n(e,t,o):n(o))||o);return r&&o&&d(e,t,o),o},c=(a,e)=>(t,r)=>e(t,r,a);var L={};x(L,{TokenContextLoader:()=>p});module.exports=R(L);var s=require("inversify"),f=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"),k=require("../../../../modules/solana/token/di/tokenTypes"),i=require("../../../../shared/model/ClearSignContext");const E=[i.ClearSignContextType.SOLANA_TOKEN];let p=class{constructor(e,t,r,o){this.dataSource=e;this.config=t;this._certificateLoader=r;this.logger=o("TokenContextLoader")}logger;canHandle(e,t){if(!E.every(o=>t.includes(o))||typeof e!="object"||e===null||!("tokenInternalId"in e))return!1;const r=e.tokenInternalId;return typeof r=="string"&&r.length>0}async load(e){this.logger.debug("[load] Loading solana token context",{data:{input:e}});const t=await this._loadInternal(e);if(t.type===i.ClearSignContextType.ERROR)return[{type:i.ClearSignContextType.ERROR,error:t.error}];const r=t;return[{type:i.ClearSignContextType.SOLANA_TOKEN,payload:r.payload,certificate:r.certificate}]}async _loadInternal(e){const{tokenInternalId:t,deviceModelId:r}=e;if(!t)return{type:i.ClearSignContextType.ERROR,error:new Error("[ContextModule] TokenContextLoader: tokenInternalId is missing")};const o=await this.dataSource.getTokenInfosPayload({tokenInternalId:t}),l=await this._certificateLoader.loadCertificate({keyId:S.KeyId.TokenMetadataKey,keyUsage:C.KeyUsage.CoinMeta,targetDevice:r});return l?o.caseOf({Left:n=>(this.logger.error("[_loadInternal] Error loading solana token context",{data:{error:n}}),{type:i.ClearSignContextType.ERROR,error:n}),Right:n=>(this.logger.debug("[_loadInternal] Successfully loaded solana token context",{data:{payload:this.pluckTokenData(n),certificate:l}}),{type:i.ClearSignContextType.SOLANA_TOKEN,payload:this.pluckTokenData(n),certificate:l})}):{type:i.ClearSignContextType.ERROR,error:new Error("[ContextModule] TokenContextLoader: tokenMetadataCertificate is missing")}}pluckTokenData(e){const t=this.config.cal.mode||"prod";return{solanaTokenDescriptor:{data:e.descriptor.data,signature:e.descriptor.signatures[t]}}}};p=u([(0,s.injectable)(),c(0,(0,s.inject)(k.tokenTypes.TokenDataSource)),c(1,(0,s.inject)(f.configTypes.Config)),c(2,(0,s.inject)(y.pkiTypes.PkiCertificateLoader)),c(3,(0,s.inject)(f.configTypes.ContextModuleLoggerFactory))],p);0&&(module.exports={TokenContextLoader});
1
+ "use strict";var g=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var I=(a,e)=>{for(var o in e)g(a,o,{get:e[o],enumerable:!0})},R=(a,e,o,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of T(e))!x.call(a,r)&&r!==o&&g(a,r,{get:()=>e[r],enumerable:!(t=m(e,r))||t.enumerable});return a};var h=a=>R(g({},"__esModule",{value:!0}),a),y=(a,e,o,t)=>{for(var r=t>1?void 0:t?m(e,o):e,i=a.length-1,s;i>=0;i--)(s=a[i])&&(r=(t?s(e,o,r):s(r))||r);return t&&r&&g(e,o,r),r},d=(a,e)=>(o,t)=>e(o,t,a);var D={};I(D,{TokenContextLoader:()=>p});module.exports=h(D);var c=require("inversify"),f=require("../../../../config/di/configTypes"),S=require("../../../../modules/multichain/pki/di/pkiTypes"),k=require("../../../../modules/multichain/pki/model/KeyId"),C=require("../../../../modules/multichain/pki/model/KeyUsage"),u=require("../../../../modules/solana/token/di/tokenTypes"),n=require("../../../../shared/model/ClearSignContext");const E=[n.ClearSignContextType.SOLANA_TOKEN];let p=class{constructor(e,o,t,r,i){this.dataSource=e;this.mintToIdDataSource=o;this.config=t;this._certificateLoader=r;this.logger=i("TokenContextLoader")}logger;canHandle(e,o){if(!E.every(s=>o.includes(s))||typeof e!="object"||e===null)return!1;const t=e,r=typeof t.tokenInternalId=="string"&&t.tokenInternalId.length>0,i=typeof t.mintAddress=="string"&&t.mintAddress.length>0;return r||i}async load(e){this.logger.debug("[load] Loading solana token context",{data:{input:e}});const o=await this._loadInternal(e);if(o.type===n.ClearSignContextType.ERROR)return[{type:n.ClearSignContextType.ERROR,error:o.error}];const t=o;return[{type:n.ClearSignContextType.SOLANA_TOKEN,payload:t.payload,certificate:t.certificate}]}async _loadInternal(e){const{deviceModelId:o,mintAddress:t}=e;let{tokenInternalId:r}=e;if(!r){if(!t)return{type:n.ClearSignContextType.ERROR,error:new Error("[ContextModule] TokenContextLoader: tokenInternalId and mintAddress are missing")};this.logger.debug("[_loadInternal] Resolving tokenInternalId from mintAddress",{data:{mintAddress:t}});const l=await this.mintToIdDataSource.getIdFromMint({mintAddress:t});if(l.isLeft())return{type:n.ClearSignContextType.ERROR,error:l.extract()};r=l.extract()}const i=await this.dataSource.getTokenInfosPayload({tokenInternalId:r}),s=await this._certificateLoader.loadCertificate({keyId:k.KeyId.TokenMetadataKey,keyUsage:C.KeyUsage.CoinMeta,targetDevice:o});return s?i.caseOf({Left:l=>(this.logger.error("[_loadInternal] Error loading solana token context",{data:{error:l}}),{type:n.ClearSignContextType.ERROR,error:l}),Right:l=>(this.logger.debug("[_loadInternal] Successfully loaded solana token context",{data:{payload:this.pluckTokenData(l),certificate:s}}),{type:n.ClearSignContextType.SOLANA_TOKEN,payload:this.pluckTokenData(l),certificate:s})}):{type:n.ClearSignContextType.ERROR,error:new Error("[ContextModule] TokenContextLoader: tokenMetadataCertificate is missing")}}pluckTokenData(e){const o=this.config.cal.mode||"prod";return{solanaTokenDescriptor:{data:e.descriptor.data,signature:e.descriptor.signatures[o]}}}};p=y([(0,c.injectable)(),d(0,(0,c.inject)(u.tokenTypes.TokenDataSource)),d(1,(0,c.inject)(u.tokenTypes.MintToIdDataSource)),d(2,(0,c.inject)(f.configTypes.Config)),d(3,(0,c.inject)(S.pkiTypes.PkiCertificateLoader)),d(4,(0,c.inject)(f.configTypes.ContextModuleLoggerFactory))],p);0&&(module.exports={TokenContextLoader});
2
2
  //# sourceMappingURL=TokenContextLoader.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/modules/solana/token/domain/TokenContextLoader.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 { PkiCertificate } from \"@/modules/multichain/pki/model/PkiCertificate\";\nimport {\n type SolanaContextError,\n type SolanaTokenContextSuccess,\n} from \"@/modules/solana/model/SolanaContextTypes\";\nimport { type SolanaTokenData } from \"@/modules/solana/model/SolanaPayloads\";\nimport { type SolanaTransactionContext } from \"@/modules/solana/model/SolanaTransactionContext\";\nimport {\n type TokenDataResponse,\n type TokenDataSource,\n} from \"@/modules/solana/token/data/TokenDataSource\";\nimport { tokenTypes } from \"@/modules/solana/token/di/tokenTypes\";\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_TOKEN,\n];\n\n@injectable()\nexport class TokenContextLoader\n implements ContextLoader<SolanaTransactionContext>\n{\n private logger: LoggerPublisherService;\n\n constructor(\n @inject(tokenTypes.TokenDataSource)\n private readonly dataSource: TokenDataSource,\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(\"TokenContextLoader\");\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 return false;\n }\n\n if (\n typeof input !== \"object\" ||\n input === null ||\n !(\"tokenInternalId\" in input)\n ) {\n return false;\n }\n\n const tokenInternalId = (input as { tokenInternalId: unknown })\n .tokenInternalId;\n\n return typeof tokenInternalId === \"string\" && tokenInternalId.length > 0;\n }\n\n public async load(\n solanaTokenContextInput: SolanaTransactionContext,\n ): Promise<ClearSignContext[]> {\n this.logger.debug(\"[load] Loading solana token context\", {\n data: { input: solanaTokenContextInput },\n });\n const result = await this._loadInternal(solanaTokenContextInput);\n if (result.type === ClearSignContextType.ERROR) {\n return [{ type: ClearSignContextType.ERROR, error: result.error }];\n }\n const r = result as SolanaTokenContextSuccess;\n return [\n {\n type: ClearSignContextType.SOLANA_TOKEN,\n payload: r.payload,\n certificate: r.certificate,\n },\n ];\n }\n\n private async _loadInternal(\n solanaTokenContextInput: SolanaTransactionContext,\n ): Promise<SolanaTokenContextSuccess | SolanaContextError> {\n const { tokenInternalId, deviceModelId } = solanaTokenContextInput;\n\n if (!tokenInternalId) {\n return {\n type: ClearSignContextType.ERROR,\n error: new Error(\n \"[ContextModule] TokenContextLoader: tokenInternalId is missing\",\n ),\n };\n }\n\n const payload = await this.dataSource.getTokenInfosPayload({\n tokenInternalId,\n });\n\n const certificate: PkiCertificate | undefined =\n await this._certificateLoader.loadCertificate({\n keyId: KeyId.TokenMetadataKey,\n keyUsage: KeyUsage.CoinMeta,\n targetDevice: deviceModelId,\n });\n\n if (!certificate) {\n return {\n type: ClearSignContextType.ERROR,\n error: new Error(\n \"[ContextModule] TokenContextLoader: tokenMetadataCertificate is missing\",\n ),\n };\n }\n\n return payload.caseOf({\n Left: (error): SolanaTokenContextSuccess | SolanaContextError => {\n this.logger.error(\n \"[_loadInternal] Error loading solana token context\",\n {\n data: { error },\n },\n );\n\n return {\n type: ClearSignContextType.ERROR,\n error,\n };\n },\n Right: (value): SolanaTokenContextSuccess | SolanaContextError => {\n this.logger.debug(\n \"[_loadInternal] Successfully loaded solana token context\",\n {\n data: { payload: this.pluckTokenData(value), certificate },\n },\n );\n\n return {\n type: ClearSignContextType.SOLANA_TOKEN,\n payload: this.pluckTokenData(value),\n certificate,\n };\n },\n });\n }\n\n private pluckTokenData(tokenData: TokenDataResponse): SolanaTokenData {\n const signatureKind = this.config.cal.mode || \"prod\";\n return {\n solanaTokenDescriptor: {\n data: tokenData.descriptor.data,\n signature: tokenData.descriptor.signatures[signatureKind],\n },\n };\n }\n}\n"],
5
- "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,wBAAAE,IAAA,eAAAC,EAAAH,GACA,IAAAI,EAAmC,qBAEnCC,EAA4B,mCAE5BC,EAAyB,gDAEzBC,EAAsB,gDACtBC,EAAyB,mDAYzBC,EAA2B,gDAE3BC,EAGO,2CAEP,MAAMC,EAA0C,CAC9C,uBAAqB,YACvB,EAGO,IAAMC,EAAN,KAEP,CAGE,YAEmBC,EAEAC,EAEAC,EAEjBC,EACA,CAPiB,gBAAAH,EAEA,YAAAC,EAEA,wBAAAC,EAIjB,KAAK,OAASC,EAAc,oBAAoB,CAClD,CAbQ,OAeD,UACLC,EACAC,EACmC,CAKnC,GAJI,CAACP,EAAgB,MAAOQ,GAAMD,EAAc,SAASC,CAAC,CAAC,GAKzD,OAAOF,GAAU,UACjBA,IAAU,MACV,EAAE,oBAAqBA,GAEvB,MAAO,GAGT,MAAMG,EAAmBH,EACtB,gBAEH,OAAO,OAAOG,GAAoB,UAAYA,EAAgB,OAAS,CACzE,CAEA,MAAa,KACXC,EAC6B,CAC7B,KAAK,OAAO,MAAM,sCAAuC,CACvD,KAAM,CAAE,MAAOA,CAAwB,CACzC,CAAC,EACD,MAAMC,EAAS,MAAM,KAAK,cAAcD,CAAuB,EAC/D,GAAIC,EAAO,OAAS,uBAAqB,MACvC,MAAO,CAAC,CAAE,KAAM,uBAAqB,MAAO,MAAOA,EAAO,KAAM,CAAC,EAEnE,MAAM,EAAIA,EACV,MAAO,CACL,CACE,KAAM,uB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onJS", "import_inversify", "import_configTypes", "import_pkiTypes", "import_KeyId", "import_KeyUsage", "import_tokenTypes", "import_ClearSignContext", "SUPPORTED_TYPES", "TokenContextLoader", "dataSource", "config", "_certificateLoader", "loggerFactory", "input", "expectedTypes", "t", "tokenInternalId", "solanaTokenContextInput", "result", "deviceModelId", "payload", "certificate", "error", "value", "tokenData", "signatureKind", "__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 { PkiCertificate } from \"@/modules/multichain/pki/model/PkiCertificate\";\nimport {\n type SolanaContextError,\n type SolanaTokenContextSuccess,\n} from \"@/modules/solana/model/SolanaContextTypes\";\nimport { type SolanaTokenData } from \"@/modules/solana/model/SolanaPayloads\";\nimport { type SolanaTransactionContext } from \"@/modules/solana/model/SolanaTransactionContext\";\nimport { type MintToIdDataSource } from \"@/modules/solana/token/data/MintToIdDataSource\";\nimport {\n type TokenDataResponse,\n type TokenDataSource,\n} from \"@/modules/solana/token/data/TokenDataSource\";\nimport { tokenTypes } from \"@/modules/solana/token/di/tokenTypes\";\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_TOKEN,\n];\n\n@injectable()\nexport class TokenContextLoader\n implements ContextLoader<SolanaTransactionContext>\n{\n private logger: LoggerPublisherService;\n\n constructor(\n @inject(tokenTypes.TokenDataSource)\n private readonly dataSource: TokenDataSource,\n @inject(tokenTypes.MintToIdDataSource)\n private readonly mintToIdDataSource: MintToIdDataSource,\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(\"TokenContextLoader\");\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 return false;\n }\n\n if (typeof input !== \"object\" || input === null) {\n return false;\n }\n\n const obj = input as { tokenInternalId?: unknown; mintAddress?: unknown };\n\n const hasTokenInternalId =\n typeof obj.tokenInternalId === \"string\" && obj.tokenInternalId.length > 0;\n const hasMintAddress =\n typeof obj.mintAddress === \"string\" && obj.mintAddress.length > 0;\n\n return hasTokenInternalId || hasMintAddress;\n }\n\n public async load(\n solanaTokenContextInput: SolanaTransactionContext,\n ): Promise<ClearSignContext[]> {\n this.logger.debug(\"[load] Loading solana token context\", {\n data: { input: solanaTokenContextInput },\n });\n const result = await this._loadInternal(solanaTokenContextInput);\n if (result.type === ClearSignContextType.ERROR) {\n return [{ type: ClearSignContextType.ERROR, error: result.error }];\n }\n const r = result as SolanaTokenContextSuccess;\n return [\n {\n type: ClearSignContextType.SOLANA_TOKEN,\n payload: r.payload,\n certificate: r.certificate,\n },\n ];\n }\n\n private async _loadInternal(\n solanaTokenContextInput: SolanaTransactionContext,\n ): Promise<SolanaTokenContextSuccess | SolanaContextError> {\n const { deviceModelId, mintAddress } = solanaTokenContextInput;\n let { tokenInternalId } = solanaTokenContextInput;\n\n if (!tokenInternalId) {\n if (!mintAddress) {\n return {\n type: ClearSignContextType.ERROR,\n error: new Error(\n \"[ContextModule] TokenContextLoader: tokenInternalId and mintAddress are missing\",\n ),\n };\n }\n\n this.logger.debug(\n \"[_loadInternal] Resolving tokenInternalId from mintAddress\",\n { data: { mintAddress } },\n );\n\n const idResult = await this.mintToIdDataSource.getIdFromMint({\n mintAddress,\n });\n\n if (idResult.isLeft()) {\n return {\n type: ClearSignContextType.ERROR,\n error: idResult.extract() as Error,\n };\n }\n\n tokenInternalId = idResult.extract() as string;\n }\n\n const payload = await this.dataSource.getTokenInfosPayload({\n tokenInternalId,\n });\n\n const certificate: PkiCertificate | undefined =\n await this._certificateLoader.loadCertificate({\n keyId: KeyId.TokenMetadataKey,\n keyUsage: KeyUsage.CoinMeta,\n targetDevice: deviceModelId,\n });\n\n if (!certificate) {\n return {\n type: ClearSignContextType.ERROR,\n error: new Error(\n \"[ContextModule] TokenContextLoader: tokenMetadataCertificate is missing\",\n ),\n };\n }\n\n return payload.caseOf({\n Left: (error): SolanaTokenContextSuccess | SolanaContextError => {\n this.logger.error(\n \"[_loadInternal] Error loading solana token context\",\n {\n data: { error },\n },\n );\n\n return {\n type: ClearSignContextType.ERROR,\n error,\n };\n },\n Right: (value): SolanaTokenContextSuccess | SolanaContextError => {\n this.logger.debug(\n \"[_loadInternal] Successfully loaded solana token context\",\n {\n data: { payload: this.pluckTokenData(value), certificate },\n },\n );\n\n return {\n type: ClearSignContextType.SOLANA_TOKEN,\n payload: this.pluckTokenData(value),\n certificate,\n };\n },\n });\n }\n\n private pluckTokenData(tokenData: TokenDataResponse): SolanaTokenData {\n const signatureKind = this.config.cal.mode || \"prod\";\n return {\n solanaTokenDescriptor: {\n data: tokenData.descriptor.data,\n signature: tokenData.descriptor.signatures[signatureKind],\n },\n };\n }\n}\n"],
5
+ "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,wBAAAE,IAAA,eAAAC,EAAAH,GACA,IAAAI,EAAmC,qBAEnCC,EAA4B,mCAE5BC,EAAyB,gDAEzBC,EAAsB,gDACtBC,EAAyB,mDAazBC,EAA2B,gDAE3BC,EAGO,2CAEP,MAAMC,EA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CACF,CAAC,EAED,GAAIE,EAAS,OAAO,EAClB,MAAO,CACL,KAAM,uBAAqB,MAC3B,MAAOA,EAAS,QAAQ,CAC1B,EAGFD,EAAkBC,EAAS,QAAQ,CACrC,CAEA,MAAMC,EAAU,MAAM,KAAK,WAAW,qBAAqB,CACzD,gBAAAF,CACF,CAAC,EAEKG,EACJ,MAAM,KAAK,mBAAmB,gBAAgB,CAC5C,MAAO,QAAM,iBACb,SAAU,WAAS,SACnB,aAAcL,CAChB,CAAC,EAEH,OAAKK,EASED,EAAQ,OAAO,CACpB,KAAOE,IACL,KAAK,OAAO,MACV,qDACA,CACE,KAAM,CAAE,MAAAA,CAAM,CAChB,CACF,EAEO,CACL,KAAM,uBAAqB,MAC3B,MAAAA,CACF,GAEF,MAAQC,IACN,KAAK,OAAO,MACV,2DACA,CACE,KAAM,CAAE,QAAS,KAAK,eAAeA,CAAK,EAAG,YAAAF,CAAY,CAC3D,CACF,EAEO,CACL,KAAM,uBAAqB,aAC3B,QAAS,KAAK,eAAeE,CAAK,EAClC,YAAAF,CACF,EAEJ,CAAC,EApCQ,CACL,KAAM,uBAAqB,MAC3B,MAAO,IAAI,MACT,yEACF,CACF,CAgCJ,CAEQ,eAAeG,EAA+C,CACpE,MAAMC,EAAgB,KAAK,OAAO,IAAI,MAAQ,OAC9C,MAAO,CACL,sBAAuB,CACrB,KAAMD,EAAU,WAAW,KAC3B,UAAWA,EAAU,WAAW,WAAWC,CAAa,CAC1D,CACF,CACF,CACF,EA7JaxB,EAANyB,EAAA,IADN,cAAW,EAOPC,EAAA,eAAO,aAAW,eAAe,GAEjCA,EAAA,eAAO,aAAW,kBAAkB,GAEpCA,EAAA,eAAO,cAAY,MAAM,GAEzBA,EAAA,eAAO,WAAS,oBAAoB,GAEpCA,EAAA,eAAO,cAAY,0BAA0B,IAdrC1B",
6
+ "names": ["TokenContextLoader_exports", "__export", "TokenContextLoader", "__toCommonJS", "import_inversify", "import_configTypes", "import_pkiTypes", "import_KeyId", "import_KeyUsage", "import_tokenTypes", "import_ClearSignContext", "SUPPORTED_TYPES", "TokenContextLoader", "dataSource", "mintToIdDataSource", "config", "_certificateLoader", "loggerFactory", "input", "expectedTypes", "t", "obj", "hasTokenInternalId", "hasMintAddress", "solanaTokenContextInput", "result", "r", "deviceModelId", "mintAddress", "tokenInternalId", "idResult", "payload", "certificate", "error", "value", "tokenData", "signatureKind", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var u=require("@ledgerhq/device-management-kit"),i=require("purify-ts"),e=require("vitest"),p=require("../../../../modules/multichain/pki/model/KeyUsage"),t=require("../../../../shared/model/ClearSignContext"),f=require("./TokenContextLoader");const y=()=>({debug:e.vi.fn(),info:e.vi.fn(),warn:e.vi.fn(),error:e.vi.fn(),subscribers:[]});(0,e.describe)("TokenContextLoader",()=>{let s,d;const l=new Uint8Array([240,202,204,26]),n={descriptor:{data:{symbol:"SOL",name:"Solana",decimals:9},signatures:{prod:"prod-sig",test:"test-sig"}}},c={tokenInternalId:"token-1",deviceModelId:u.DeviceModelId.FLEX};(0,e.beforeEach)(()=>{e.vi.restoreAllMocks(),s={getTokenInfosPayload:e.vi.fn()},d={loadCertificate:e.vi.fn()}});const r=a=>{const o={cal:{mode:a}};return new f.TokenContextLoader(s,o,d,y)};(0,e.describe)("canHandle",()=>{(0,e.it)("returns true when tokenInternalId is provided and SOLANA_TOKEN is in expectedTypes",()=>{const a=r("prod");(0,e.expect)(a.canHandle({tokenInternalId:"abc123"},[t.ClearSignContextType.SOLANA_TOKEN])).toBe(!0)}),(0,e.it)("returns false when SOLANA_TOKEN is not in expectedTypes",()=>{const a=r("prod");(0,e.expect)(a.canHandle({tokenInternalId:"abc123"},[t.ClearSignContextType.SOLANA_LIFI])).toBe(!1)}),(0,e.it)("returns false when tokenInternalId is missing or falsy",()=>{const a=r("prod");(0,e.expect)(a.canHandle({tokenInternalId:""},[t.ClearSignContextType.SOLANA_TOKEN])).toBe(!1),(0,e.expect)(a.canHandle({tokenInternalId:void 0},[t.ClearSignContextType.SOLANA_TOKEN])).toBe(!1),(0,e.expect)(a.canHandle({},[t.ClearSignContextType.SOLANA_TOKEN])).toBe(!1)})}),(0,e.describe)("load",()=>{(0,e.it)("returns an array with an error when datasource returns Left(error) (certificate still retrieved)",async()=>{const a=r("prod"),o=new Error("datasource failed");e.vi.spyOn(s,"getTokenInfosPayload").mockResolvedValue((0,i.Left)(o)),e.vi.spyOn(d,"loadCertificate").mockResolvedValue({keyUsageNumber:0,payload:l});const k=await a.load(c);(0,e.expect)(s.getTokenInfosPayload).toHaveBeenCalledWith({tokenInternalId:"token-1"}),(0,e.expect)(d.loadCertificate).toHaveBeenCalledWith({keyId:"token_metadata_key",keyUsage:p.KeyUsage.CoinMeta,targetDevice:c.deviceModelId}),(0,e.expect)(k).toEqual([{type:t.ClearSignContextType.ERROR,error:o}])}),(0,e.it)("returns SOLANA_TOKEN array with prod signature by default (falsy mode) and includes certificate",async()=>{const a=r("");e.vi.spyOn(s,"getTokenInfosPayload").mockResolvedValue((0,i.Right)(n)),e.vi.spyOn(d,"loadCertificate").mockResolvedValue({keyUsageNumber:0,payload:l});const o=await a.load({...c,tokenInternalId:"token-2"});(0,e.expect)(o).toEqual([{type:t.ClearSignContextType.SOLANA_TOKEN,payload:{solanaTokenDescriptor:{data:n.descriptor.data,signature:"prod-sig"}},certificate:{keyUsageNumber:0,payload:l}}])}),(0,e.it)("returns SOLANA_TOKEN array with signature matching config.cal.mode",async()=>{const a=r("test");e.vi.spyOn(s,"getTokenInfosPayload").mockResolvedValue((0,i.Right)(n)),e.vi.spyOn(d,"loadCertificate").mockResolvedValue({keyUsageNumber:1,payload:l});const o=await a.load({...c,tokenInternalId:"token-3"});(0,e.expect)(o).toEqual([{type:t.ClearSignContextType.SOLANA_TOKEN,payload:{solanaTokenDescriptor:{data:n.descriptor.data,signature:"test-sig"}},certificate:{keyUsageNumber:1,payload:l}}])}),(0,e.it)("returns ERROR when certificate loader returns undefined",async()=>{const a=r("prod");e.vi.spyOn(s,"getTokenInfosPayload").mockResolvedValue((0,i.Right)(n)),e.vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const o=await a.load(c);(0,e.expect)(o).toEqual([{type:t.ClearSignContextType.ERROR,error:new Error("[ContextModule] TokenContextLoader: tokenMetadataCertificate is missing")}])})}),(0,e.describe)("pluckTokenData (private)",()=>{(0,e.it)("picks the signature for the configured mode",()=>{const a=r("test"),k=a.pluckTokenData.bind(a)(n);(0,e.expect)(k).toEqual({solanaTokenDescriptor:{data:n.descriptor.data,signature:"test-sig"}})}),(0,e.it)("falls back to 'prod' when config.cal.mode is falsy",()=>{const o=r(void 0).pluckTokenData(n);(0,e.expect)(o).toEqual({solanaTokenDescriptor:{data:n.descriptor.data,signature:"prod-sig"}})})})});
1
+ "use strict";var y=require("@ledgerhq/device-management-kit"),d=require("purify-ts"),e=require("vitest"),p=require("../../../../modules/multichain/pki/model/KeyUsage"),n=require("../../../../shared/model/ClearSignContext"),m=require("./TokenContextLoader");const I=()=>({debug:e.vi.fn(),info:e.vi.fn(),warn:e.vi.fn(),error:e.vi.fn(),subscribers:[]});(0,e.describe)("TokenContextLoader",()=>{let r,c,l;const i=new Uint8Array([240,202,204,26]),s={descriptor:{data:{symbol:"SOL",name:"Solana",decimals:9},signatures:{prod:"prod-sig",test:"test-sig"}}},k={tokenInternalId:"token-1",deviceModelId:y.DeviceModelId.FLEX};(0,e.beforeEach)(()=>{e.vi.restoreAllMocks(),r={getTokenInfosPayload:e.vi.fn()},c={getIdFromMint:e.vi.fn()},l={loadCertificate:e.vi.fn()}});const t=a=>{const o={cal:{mode:a}};return new m.TokenContextLoader(r,c,o,l,I)};(0,e.describe)("canHandle",()=>{(0,e.it)("returns true when tokenInternalId is provided and SOLANA_TOKEN is in expectedTypes",()=>{const a=t("prod");(0,e.expect)(a.canHandle({tokenInternalId:"abc123"},[n.ClearSignContextType.SOLANA_TOKEN])).toBe(!0)}),(0,e.it)("returns false when SOLANA_TOKEN is not in expectedTypes",()=>{const a=t("prod");(0,e.expect)(a.canHandle({tokenInternalId:"abc123"},[n.ClearSignContextType.SOLANA_LIFI])).toBe(!1)}),(0,e.it)("returns false when tokenInternalId is missing or falsy",()=>{const a=t("prod");(0,e.expect)(a.canHandle({tokenInternalId:""},[n.ClearSignContextType.SOLANA_TOKEN])).toBe(!1),(0,e.expect)(a.canHandle({tokenInternalId:void 0},[n.ClearSignContextType.SOLANA_TOKEN])).toBe(!1),(0,e.expect)(a.canHandle({},[n.ClearSignContextType.SOLANA_TOKEN])).toBe(!1)}),(0,e.it)("returns true when only mintAddress is provided (no tokenInternalId)",()=>{const a=t("prod");(0,e.expect)(a.canHandle({mintAddress:"3iql8bfs2Ve7mwW4EHaqqHasbmrnCrPxiZWat2ZFyr9Y"},[n.ClearSignContextType.SOLANA_TOKEN])).toBe(!0)}),(0,e.it)("returns false when both tokenInternalId and mintAddress are absent or empty",()=>{const a=t("prod");(0,e.expect)(a.canHandle({mintAddress:""},[n.ClearSignContextType.SOLANA_TOKEN])).toBe(!1)})}),(0,e.describe)("load",()=>{(0,e.it)("returns an array with an error when datasource returns Left(error) (certificate still retrieved)",async()=>{const a=t("prod"),o=new Error("datasource failed");e.vi.spyOn(r,"getTokenInfosPayload").mockResolvedValue((0,d.Left)(o)),e.vi.spyOn(l,"loadCertificate").mockResolvedValue({keyUsageNumber:0,payload:i});const u=await a.load(k);(0,e.expect)(r.getTokenInfosPayload).toHaveBeenCalledWith({tokenInternalId:"token-1"}),(0,e.expect)(l.loadCertificate).toHaveBeenCalledWith({keyId:"token_metadata_key",keyUsage:p.KeyUsage.CoinMeta,targetDevice:k.deviceModelId}),(0,e.expect)(u).toEqual([{type:n.ClearSignContextType.ERROR,error:o}])}),(0,e.it)("returns SOLANA_TOKEN array with prod signature by default (falsy mode) and includes certificate",async()=>{const a=t("");e.vi.spyOn(r,"getTokenInfosPayload").mockResolvedValue((0,d.Right)(s)),e.vi.spyOn(l,"loadCertificate").mockResolvedValue({keyUsageNumber:0,payload:i});const o=await a.load({...k,tokenInternalId:"token-2"});(0,e.expect)(o).toEqual([{type:n.ClearSignContextType.SOLANA_TOKEN,payload:{solanaTokenDescriptor:{data:s.descriptor.data,signature:"prod-sig"}},certificate:{keyUsageNumber:0,payload:i}}])}),(0,e.it)("returns SOLANA_TOKEN array with signature matching config.cal.mode",async()=>{const a=t("test");e.vi.spyOn(r,"getTokenInfosPayload").mockResolvedValue((0,d.Right)(s)),e.vi.spyOn(l,"loadCertificate").mockResolvedValue({keyUsageNumber:1,payload:i});const o=await a.load({...k,tokenInternalId:"token-3"});(0,e.expect)(o).toEqual([{type:n.ClearSignContextType.SOLANA_TOKEN,payload:{solanaTokenDescriptor:{data:s.descriptor.data,signature:"test-sig"}},certificate:{keyUsageNumber:1,payload:i}}])}),(0,e.it)("returns ERROR when certificate loader returns undefined",async()=>{const a=t("prod");e.vi.spyOn(r,"getTokenInfosPayload").mockResolvedValue((0,d.Right)(s)),e.vi.spyOn(l,"loadCertificate").mockResolvedValue(void 0);const o=await a.load(k);(0,e.expect)(o).toEqual([{type:n.ClearSignContextType.ERROR,error:new Error("[ContextModule] TokenContextLoader: tokenMetadataCertificate is missing")}])}),(0,e.describe)("mintAddress resolution",()=>{const a={mintAddress:"3iql8bfs2Ve7mwW4EHaqqHasbmrnCrPxiZWat2ZFyr9Y",deviceModelId:y.DeviceModelId.FLEX};(0,e.it)("resolves tokenInternalId from mintAddress when tokenInternalId is absent",async()=>{const o=t("prod");e.vi.spyOn(c,"getIdFromMint").mockResolvedValue((0,d.Right)("sol:usdc")),e.vi.spyOn(r,"getTokenInfosPayload").mockResolvedValue((0,d.Right)(s)),e.vi.spyOn(l,"loadCertificate").mockResolvedValue({keyUsageNumber:0,payload:i}),await o.load(a),(0,e.expect)(c.getIdFromMint).toHaveBeenCalledWith({mintAddress:a.mintAddress}),(0,e.expect)(r.getTokenInfosPayload).toHaveBeenCalledWith({tokenInternalId:"sol:usdc"})}),(0,e.it)("skips mintAddress resolution when tokenInternalId is already provided",async()=>{const o=t("prod");e.vi.spyOn(r,"getTokenInfosPayload").mockResolvedValue((0,d.Right)(s)),e.vi.spyOn(l,"loadCertificate").mockResolvedValue({keyUsageNumber:0,payload:i}),await o.load({...a,tokenInternalId:"sol:usdc-direct"}),(0,e.expect)(c.getIdFromMint).not.toHaveBeenCalled(),(0,e.expect)(r.getTokenInfosPayload).toHaveBeenCalledWith({tokenInternalId:"sol:usdc-direct"})}),(0,e.it)("returns ERROR when mintToIdDataSource returns Left",async()=>{const o=t("prod"),u=new Error("mint resolution failed");e.vi.spyOn(c,"getIdFromMint").mockResolvedValue((0,d.Left)(u));const f=await o.load(a);(0,e.expect)(f).toEqual([{type:n.ClearSignContextType.ERROR,error:u}]),(0,e.expect)(r.getTokenInfosPayload).not.toHaveBeenCalled()})})}),(0,e.describe)("pluckTokenData (private)",()=>{(0,e.it)("picks the signature for the configured mode",()=>{const a=t("test"),u=a.pluckTokenData.bind(a)(s);(0,e.expect)(u).toEqual({solanaTokenDescriptor:{data:s.descriptor.data,signature:"test-sig"}})}),(0,e.it)("falls back to 'prod' when config.cal.mode is falsy",()=>{const o=t(void 0).pluckTokenData(s);(0,e.expect)(o).toEqual({solanaTokenDescriptor:{data:s.descriptor.data,signature:"prod-sig"}})})})});
2
2
  //# sourceMappingURL=TokenContextLoader.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/modules/solana/token/domain/TokenContextLoader.test.ts"],
4
- "sourcesContent": ["/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\nimport { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\nimport { beforeEach, describe, expect, it, vi } from \"vitest\";\n\nimport { type ContextModuleServiceConfig } from \"@/config/model/ContextModuleConfig\";\nimport type { PkiCertificateLoader } from \"@/modules/multichain/pki/domain/PkiCertificateLoader\";\nimport { KeyUsage } from \"@/modules/multichain/pki/model/KeyUsage\";\nimport type { SolanaTransactionContext } from \"@/modules/solana/owner-info/domain/solanaContextTypes\";\nimport {\n type TokenDataResponse,\n type TokenDataSource,\n} from \"@/modules/solana/token/data/TokenDataSource\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\n\nimport { TokenContextLoader } from \"./TokenContextLoader\";\n\nconst mockLoggerFactory = () => ({\n debug: vi.fn(),\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n subscribers: [],\n});\n\ndescribe(\"TokenContextLoader\", () => {\n let mockDataSource: TokenDataSource;\n let mockCertLoader: PkiCertificateLoader;\n\n const bytes = new Uint8Array([0xf0, 0xca, 0xcc, 0x1a]);\n\n const tokenDataResponse: TokenDataResponse = {\n descriptor: {\n // The loader just forwards this; exact shape isn't important for the test\n data: { symbol: \"SOL\", name: \"Solana\", decimals: 9 } as any,\n signatures: {\n prod: \"prod-sig\",\n test: \"test-sig\",\n } as any,\n },\n } as any;\n\n const baseCtx = {\n tokenInternalId: \"token-1\",\n deviceModelId: DeviceModelId.FLEX,\n };\n\n beforeEach(() => {\n vi.restoreAllMocks();\n\n mockDataSource = {\n getTokenInfosPayload: vi.fn(),\n } as unknown as TokenDataSource;\n\n mockCertLoader = {\n loadCertificate: vi.fn(),\n } as unknown as PkiCertificateLoader;\n });\n\n const makeLoader = (mode?: string) => {\n const config = { cal: { mode } } as unknown as ContextModuleServiceConfig;\n return new TokenContextLoader(\n mockDataSource,\n config,\n mockCertLoader,\n mockLoggerFactory,\n );\n };\n\n describe(\"canHandle\", () => {\n it(\"returns true when tokenInternalId is provided and SOLANA_TOKEN is in expectedTypes\", () => {\n const loader = makeLoader(\"prod\");\n\n expect(\n loader.canHandle(\n {\n tokenInternalId: \"abc123\",\n } as SolanaTransactionContext,\n [ClearSignContextType.SOLANA_TOKEN],\n ),\n ).toBe(true);\n });\n\n it(\"returns false when SOLANA_TOKEN is not in expectedTypes\", () => {\n const loader = makeLoader(\"prod\");\n\n expect(\n loader.canHandle(\n { tokenInternalId: \"abc123\" } as SolanaTransactionContext,\n [ClearSignContextType.SOLANA_LIFI],\n ),\n ).toBe(false);\n });\n\n it(\"returns false when tokenInternalId is missing or falsy\", () => {\n const loader = makeLoader(\"prod\");\n\n expect(\n loader.canHandle({ tokenInternalId: \"\" } as any, [\n ClearSignContextType.SOLANA_TOKEN,\n ]),\n ).toBe(false);\n expect(\n loader.canHandle({ tokenInternalId: undefined } as any, [\n ClearSignContextType.SOLANA_TOKEN,\n ]),\n ).toBe(false);\n expect(\n loader.canHandle({} as any, [ClearSignContextType.SOLANA_TOKEN]),\n ).toBe(false);\n });\n });\n\n describe(\"load\", () => {\n it(\"returns an array with an error when datasource returns Left(error) (certificate still retrieved)\", async () => {\n const loader = makeLoader(\"prod\");\n const error = new Error(\"datasource failed\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(error),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 0,\n payload: bytes,\n });\n\n const result = await loader.load(baseCtx);\n\n expect(mockDataSource.getTokenInfosPayload).toHaveBeenCalledWith({\n tokenInternalId: \"token-1\",\n });\n expect(mockCertLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: \"token_metadata_key\",\n keyUsage: KeyUsage.CoinMeta,\n targetDevice: baseCtx.deviceModelId,\n });\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error,\n },\n ]);\n });\n\n it(\"returns SOLANA_TOKEN array with prod signature by default (falsy mode) and includes certificate\", async () => {\n const loader = makeLoader(\"\"); // falsy -> default 'prod'\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 0,\n payload: bytes,\n });\n\n const result = await loader.load({\n ...baseCtx,\n tokenInternalId: \"token-2\",\n });\n\n expect(result).toEqual([\n {\n type: ClearSignContextType.SOLANA_TOKEN,\n payload: {\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"prod-sig\",\n },\n },\n certificate: { keyUsageNumber: 0, payload: bytes },\n },\n ]);\n });\n\n it(\"returns SOLANA_TOKEN array with signature matching config.cal.mode\", async () => {\n const loader = makeLoader(\"test\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 1,\n payload: bytes,\n });\n\n const result = await loader.load({\n ...baseCtx,\n tokenInternalId: \"token-3\",\n });\n\n expect(result).toEqual([\n {\n type: ClearSignContextType.SOLANA_TOKEN,\n payload: {\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"test-sig\",\n },\n },\n certificate: { keyUsageNumber: 1, payload: bytes },\n },\n ]);\n });\n\n it(\"returns ERROR when certificate loader returns undefined\", async () => {\n const loader = makeLoader(\"prod\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue(undefined);\n\n const result = await loader.load(baseCtx);\n\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\n \"[ContextModule] TokenContextLoader: tokenMetadataCertificate is missing\",\n ),\n },\n ]);\n });\n });\n\n describe(\"pluckTokenData (private)\", () => {\n it(\"picks the signature for the configured mode\", () => {\n const loader = makeLoader(\"test\");\n const pluck = (loader as any).pluckTokenData.bind(loader);\n\n const result = pluck(tokenDataResponse);\n\n expect(result).toEqual({\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"test-sig\",\n },\n });\n });\n\n it(\"falls back to 'prod' when config.cal.mode is falsy\", () => {\n const loader = makeLoader(undefined as any);\n const result = (loader as any).pluckTokenData(tokenDataResponse);\n\n expect(result).toEqual({\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"prod-sig\",\n },\n });\n });\n });\n});\n"],
5
- "mappings": "aAIA,IAAAA,EAA8B,2CAC9BC,EAA4B,qBAC5BC,EAAqD,kBAIrDC,EAAyB,mDAMzBC,EAAqC,2CAErCC,EAAmC,gCAEnC,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,EAEJ,MAAMC,EAAQ,IAAI,WAAW,CAAC,IAAM,IAAM,IAAM,EAAI,CAAC,EAE/CC,EAAuC,CAC3C,WAAY,CAEV,KAAM,CAAE,OAAQ,MAAO,KAAM,SAAU,SAAU,CAAE,EACnD,WAAY,CACV,KAAM,WACN,KAAM,UACR,CACF,CACF,EAEMC,EAAU,CACd,gBAAiB,UACjB,cAAe,gBAAc,IAC/B,KAEA,cAAW,IAAM,CACf,KAAG,gBAAgB,EAEnBJ,EAAiB,CACf,qBAAsB,KAAG,GAAG,CAC9B,EAEAC,EAAiB,CACf,gBAAiB,KAAG,GAAG,CACzB,CACF,CAAC,EAED,MAAMI,EAAcC,GAAkB,CACpC,MAAMC,EAAS,CAAE,IAAK,CAAE,KAAAD,CAAK,CAAE,EAC/B,OAAO,IAAI,qBACTN,EACAO,EACAN,EACAF,CACF,CACF,KAEA,YAAS,YAAa,IAAM,IAC1B,MAAG,qFAAsF,IAAM,CAC7F,MAAMS,EAASH,EAAW,MAAM,KAEhC,UACEG,EAAO,UACL,CACE,gBAAiB,QACnB,EACA,CAAC,uBAAqB,YAAY,CACpC,CACF,EAAE,KAAK,EAAI,CACb,CAAC,KAED,MAAG,0DAA2D,IAAM,CAClE,MAA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G,8CAA+C,IAAM,CACtD,MAAMF,EAASH,EAAW,MAAM,EAG1BK,EAFSF,EAAe,eAAe,KAAKA,CAAM,EAEnCL,CAAiB,KAEtC,UAAOO,CAAM,EAAE,QAAQ,CACrB,sBAAuB,CACrB,KAAMP,EAAkB,WAAW,KACnC,UAAW,UACb,CACF,CAAC,CACH,CAAC,KAED,MAAG,qDAAsD,IAAM,CAE7D,MAAMO,EADSL,EAAW,MAAgB,EACX,eAAeF,CAAiB,KAE/D,UAAOO,CAAM,EAAE,QAAQ,CACrB,sBAAuB,CACrB,KAAMP,EAAkB,WAAW,KACnC,UAAW,UACb,CACF,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["import_device_management_kit", "import_purify_ts", "import_vitest", "import_KeyUsage", "import_ClearSignContext", "import_TokenContextLoader", "mockLoggerFactory", "mockDataSource", "mockCertLoader", "bytes", "tokenDataResponse", "baseCtx", "makeLoader", "mode", "config", "loader", "error", "result"]
4
+ "sourcesContent": ["/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\nimport { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\nimport { beforeEach, describe, expect, it, vi } from \"vitest\";\n\nimport { type ContextModuleServiceConfig } from \"@/config/model/ContextModuleConfig\";\nimport type { PkiCertificateLoader } from \"@/modules/multichain/pki/domain/PkiCertificateLoader\";\nimport { KeyUsage } from \"@/modules/multichain/pki/model/KeyUsage\";\nimport type { SolanaTransactionContext } from \"@/modules/solana/owner-info/domain/solanaContextTypes\";\nimport { type MintToIdDataSource } from \"@/modules/solana/token/data/MintToIdDataSource\";\nimport {\n type TokenDataResponse,\n type TokenDataSource,\n} from \"@/modules/solana/token/data/TokenDataSource\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\n\nimport { TokenContextLoader } from \"./TokenContextLoader\";\n\nconst mockLoggerFactory = () => ({\n debug: vi.fn(),\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n subscribers: [],\n});\n\ndescribe(\"TokenContextLoader\", () => {\n let mockDataSource: TokenDataSource;\n let mockMintToIdDataSource: MintToIdDataSource;\n let mockCertLoader: PkiCertificateLoader;\n\n const bytes = new Uint8Array([0xf0, 0xca, 0xcc, 0x1a]);\n\n const tokenDataResponse: TokenDataResponse = {\n descriptor: {\n // The loader just forwards this; exact shape isn't important for the test\n data: { symbol: \"SOL\", name: \"Solana\", decimals: 9 } as any,\n signatures: {\n prod: \"prod-sig\",\n test: \"test-sig\",\n } as any,\n },\n } as any;\n\n const baseCtx = {\n tokenInternalId: \"token-1\",\n deviceModelId: DeviceModelId.FLEX,\n };\n\n beforeEach(() => {\n vi.restoreAllMocks();\n\n mockDataSource = {\n getTokenInfosPayload: vi.fn(),\n } as unknown as TokenDataSource;\n\n mockMintToIdDataSource = {\n getIdFromMint: vi.fn(),\n } as unknown as MintToIdDataSource;\n\n mockCertLoader = {\n loadCertificate: vi.fn(),\n } as unknown as PkiCertificateLoader;\n });\n\n const makeLoader = (mode?: string) => {\n const config = { cal: { mode } } as unknown as ContextModuleServiceConfig;\n return new TokenContextLoader(\n mockDataSource,\n mockMintToIdDataSource,\n config,\n mockCertLoader,\n mockLoggerFactory,\n );\n };\n\n describe(\"canHandle\", () => {\n it(\"returns true when tokenInternalId is provided and SOLANA_TOKEN is in expectedTypes\", () => {\n const loader = makeLoader(\"prod\");\n\n expect(\n loader.canHandle(\n {\n tokenInternalId: \"abc123\",\n } as SolanaTransactionContext,\n [ClearSignContextType.SOLANA_TOKEN],\n ),\n ).toBe(true);\n });\n\n it(\"returns false when SOLANA_TOKEN is not in expectedTypes\", () => {\n const loader = makeLoader(\"prod\");\n\n expect(\n loader.canHandle(\n { tokenInternalId: \"abc123\" } as SolanaTransactionContext,\n [ClearSignContextType.SOLANA_LIFI],\n ),\n ).toBe(false);\n });\n\n it(\"returns false when tokenInternalId is missing or falsy\", () => {\n const loader = makeLoader(\"prod\");\n\n expect(\n loader.canHandle({ tokenInternalId: \"\" } as any, [\n ClearSignContextType.SOLANA_TOKEN,\n ]),\n ).toBe(false);\n expect(\n loader.canHandle({ tokenInternalId: undefined } as any, [\n ClearSignContextType.SOLANA_TOKEN,\n ]),\n ).toBe(false);\n expect(\n loader.canHandle({} as any, [ClearSignContextType.SOLANA_TOKEN]),\n ).toBe(false);\n });\n\n it(\"returns true when only mintAddress is provided (no tokenInternalId)\", () => {\n const loader = makeLoader(\"prod\");\n\n expect(\n loader.canHandle(\n {\n mintAddress: \"3iql8bfs2Ve7mwW4EHaqqHasbmrnCrPxiZWat2ZFyr9Y\",\n } as any,\n [ClearSignContextType.SOLANA_TOKEN],\n ),\n ).toBe(true);\n });\n\n it(\"returns false when both tokenInternalId and mintAddress are absent or empty\", () => {\n const loader = makeLoader(\"prod\");\n\n expect(\n loader.canHandle({ mintAddress: \"\" } as any, [\n ClearSignContextType.SOLANA_TOKEN,\n ]),\n ).toBe(false);\n });\n });\n\n describe(\"load\", () => {\n it(\"returns an array with an error when datasource returns Left(error) (certificate still retrieved)\", async () => {\n const loader = makeLoader(\"prod\");\n const error = new Error(\"datasource failed\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(error),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 0,\n payload: bytes,\n });\n\n const result = await loader.load(baseCtx);\n\n expect(mockDataSource.getTokenInfosPayload).toHaveBeenCalledWith({\n tokenInternalId: \"token-1\",\n });\n expect(mockCertLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: \"token_metadata_key\",\n keyUsage: KeyUsage.CoinMeta,\n targetDevice: baseCtx.deviceModelId,\n });\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error,\n },\n ]);\n });\n\n it(\"returns SOLANA_TOKEN array with prod signature by default (falsy mode) and includes certificate\", async () => {\n const loader = makeLoader(\"\"); // falsy -> default 'prod'\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 0,\n payload: bytes,\n });\n\n const result = await loader.load({\n ...baseCtx,\n tokenInternalId: \"token-2\",\n });\n\n expect(result).toEqual([\n {\n type: ClearSignContextType.SOLANA_TOKEN,\n payload: {\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"prod-sig\",\n },\n },\n certificate: { keyUsageNumber: 0, payload: bytes },\n },\n ]);\n });\n\n it(\"returns SOLANA_TOKEN array with signature matching config.cal.mode\", async () => {\n const loader = makeLoader(\"test\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 1,\n payload: bytes,\n });\n\n const result = await loader.load({\n ...baseCtx,\n tokenInternalId: \"token-3\",\n });\n\n expect(result).toEqual([\n {\n type: ClearSignContextType.SOLANA_TOKEN,\n payload: {\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"test-sig\",\n },\n },\n certificate: { keyUsageNumber: 1, payload: bytes },\n },\n ]);\n });\n\n it(\"returns ERROR when certificate loader returns undefined\", async () => {\n const loader = makeLoader(\"prod\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue(undefined);\n\n const result = await loader.load(baseCtx);\n\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\n \"[ContextModule] TokenContextLoader: tokenMetadataCertificate is missing\",\n ),\n },\n ]);\n });\n\n describe(\"mintAddress resolution\", () => {\n const mintCtx = {\n mintAddress: \"3iql8bfs2Ve7mwW4EHaqqHasbmrnCrPxiZWat2ZFyr9Y\",\n deviceModelId: DeviceModelId.FLEX,\n };\n\n it(\"resolves tokenInternalId from mintAddress when tokenInternalId is absent\", async () => {\n const loader = makeLoader(\"prod\");\n\n vi.spyOn(mockMintToIdDataSource, \"getIdFromMint\").mockResolvedValue(\n Right(\"sol:usdc\"),\n );\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 0,\n payload: bytes,\n });\n\n await loader.load(mintCtx as any);\n\n expect(mockMintToIdDataSource.getIdFromMint).toHaveBeenCalledWith({\n mintAddress: mintCtx.mintAddress,\n });\n expect(mockDataSource.getTokenInfosPayload).toHaveBeenCalledWith({\n tokenInternalId: \"sol:usdc\",\n });\n });\n\n it(\"skips mintAddress resolution when tokenInternalId is already provided\", async () => {\n const loader = makeLoader(\"prod\");\n\n vi.spyOn(mockDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Right(tokenDataResponse),\n );\n vi.spyOn(mockCertLoader, \"loadCertificate\").mockResolvedValue({\n keyUsageNumber: 0,\n payload: bytes,\n });\n\n await loader.load({\n ...mintCtx,\n tokenInternalId: \"sol:usdc-direct\",\n } as any);\n\n expect(mockMintToIdDataSource.getIdFromMint).not.toHaveBeenCalled();\n expect(mockDataSource.getTokenInfosPayload).toHaveBeenCalledWith({\n tokenInternalId: \"sol:usdc-direct\",\n });\n });\n\n it(\"returns ERROR when mintToIdDataSource returns Left\", async () => {\n const loader = makeLoader(\"prod\");\n const error = new Error(\"mint resolution failed\");\n\n vi.spyOn(mockMintToIdDataSource, \"getIdFromMint\").mockResolvedValue(\n Left(error),\n );\n\n const result = await loader.load(mintCtx as any);\n\n expect(result).toEqual([{ type: ClearSignContextType.ERROR, error }]);\n expect(mockDataSource.getTokenInfosPayload).not.toHaveBeenCalled();\n });\n });\n });\n\n describe(\"pluckTokenData (private)\", () => {\n it(\"picks the signature for the configured mode\", () => {\n const loader = makeLoader(\"test\");\n const pluck = (loader as any).pluckTokenData.bind(loader);\n\n const result = pluck(tokenDataResponse);\n\n expect(result).toEqual({\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"test-sig\",\n },\n });\n });\n\n it(\"falls back to 'prod' when config.cal.mode is falsy\", () => {\n const loader = makeLoader(undefined as any);\n const result = (loader as any).pluckTokenData(tokenDataResponse);\n\n expect(result).toEqual({\n solanaTokenDescriptor: {\n data: tokenDataResponse.descriptor.data,\n signature: \"prod-sig\",\n },\n });\n });\n });\n});\n"],
5
+ "mappings": "aAIA,IAAAA,EAA8B,2CAC9BC,EAA4B,qBAC5BC,EAAqD,kBAIrDC,EAAyB,mDAOzBC,EAAqC,2CAErCC,EAAmC,gCAEnC,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,EACAC,EAEJ,MAAMC,EAAQ,IAAI,WAAW,CAAC,IAAM,IAAM,IAAM,EAAI,CAAC,EAE/CC,EAAuC,CAC3C,WAAY,CAEV,KAAM,CAAE,OAAQ,MAAO,KAAM,SAAU,SAAU,CAAE,EACnD,WAAY,CACV,KAAM,WACN,KAAM,UACR,CACF,CACF,EAEMC,EAAU,CACd,gBAAiB,UACjB,cAAe,gBAAc,IAC/B,KAEA,cAAW,IAAM,CACf,KAAG,gBAAgB,EAEnBL,EAAiB,CACf,qBAAsB,KAAG,GAAG,CAC9B,EAEAC,EAAyB,CACvB,cAAe,KAAG,GAAG,CACvB,EAEAC,EAAiB,CACf,gBAAiB,KAAG,GAAG,CACzB,CACF,CAAC,EAED,MAAMI,EAAcC,GAAkB,CACpC,MAAMC,EAAS,CAAE,IAAK,CAAE,KAAAD,CAAK,CAAE,E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CAAiB,CACzB,EACA,KAAG,MAAMF,EAAgB,iBAAiB,EAAE,kBAAkB,CAC5D,eAAgB,EAChB,QAASC,CACX,CAAC,EAED,MAAMM,EAAO,KAAK,CAChB,GAAGG,EACH,gBAAiB,iBACnB,CAAQ,KAER,UAAOX,EAAuB,aAAa,EAAE,IAAI,iBAAiB,KAClE,UAAOD,EAAe,oBAAoB,EAAE,qBAAqB,CAC/D,gBAAiB,iBACnB,CAAC,CACH,CAAC,KAED,MAAG,qDAAsD,SAAY,CACnE,MAAMS,EAASH,EAAW,MAAM,EAC1BI,EAAQ,IAAI,MAAM,wBAAwB,EAEhD,KAAG,MAAMT,EAAwB,eAAe,EAAE,qBAChD,QAAKS,CAAK,CACZ,EAEA,MAAMC,EAAS,MAAMF,EAAO,KAAKG,CAAc,KAE/C,UAAOD,CAAM,EAAE,QAAQ,CAAC,CAAE,KAAM,uBAAqB,MAAO,MAAAD,CAAM,CAAC,CAAC,KACpE,UAAOV,EAAe,oBAAoB,EAAE,IAAI,iBAAiB,CACnE,CAAC,CACH,CAAC,CACH,CAAC,KAED,YAAS,2BAA4B,IAAM,IACzC,MAAG,8CAA+C,IAAM,CACtD,MAAMS,EAASH,EAAW,MAAM,EAG1BK,EAFSF,EAAe,eAAe,KAAKA,CAAM,EAEnCL,CAAiB,KAEtC,UAAOO,CAAM,EAAE,QAAQ,CACrB,sBAAuB,CACrB,KAAMP,EAAkB,WAAW,KACnC,UAAW,UACb,CACF,CAAC,CACH,CAAC,KAED,MAAG,qDAAsD,IAAM,CAE7D,MAAMO,EADSL,EAAW,MAAgB,EACX,eAAeF,CAAiB,KAE/D,UAAOO,CAAM,EAAE,QAAQ,CACrB,sBAAuB,CACrB,KAAMP,EAAkB,WAAW,KACnC,UAAW,UACb,CACF,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["import_device_management_kit", "import_purify_ts", "import_vitest", "import_KeyUsage", "import_ClearSignContext", "import_TokenContextLoader", "mockLoggerFactory", "mockDataSource", "mockMintToIdDataSource", "mockCertLoader", "bytes", "tokenDataResponse", "baseCtx", "makeLoader", "mode", "config", "loader", "error", "result", "mintCtx"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var m=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var h=(r,t)=>{for(var o in t)m(r,o,{get:t[o],enumerable:!0})},D=(r,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of S(t))!T.call(r,e)&&e!==o&&m(r,e,{get:()=>t[e],enumerable:!(n=g(t,e))||n.enumerable});return r};var C=r=>D(m({},"__esModule",{value:!0}),r),l=(r,t,o,n)=>{for(var e=n>1?void 0:n?g(t,o):t,i=r.length-1,c;i>=0;i--)(c=r[i])&&(e=(n?c(t,o,e):c(e))||e);return n&&e&&m(t,o,e),e},u=(r,t)=>(o,n)=>t(o,n,r);var A={};h(A,{HttpTokenAccountStateDataSource:()=>a});module.exports=C(A);var p=require("inversify"),s=require("purify-ts"),f=require("../../../../config/di/configTypes"),k=require("../../../../shared/network/di/networkTypes"),d=require("../../../../shared/utils/HexStringUtils"),y=require("../../../../shared/utils/signedDescriptorDto");let a=class{constructor(t,o){this.config=t;this.http=o}async getTokenAccountState({tokenAccount:t,challenge:o}){let n;try{n=await this.http.get(`${this.config.metadataServiceDomain.url}/v2/solana/token-account-state/${t}`,{params:{challenge:o}})}catch(e){const i=e instanceof Error?e.message:String(e);return(0,s.Left)(new Error(`[ContextModule] HttpTokenAccountStateDataSource: Failed to fetch token account state: ${i}`))}return y.signedDescriptorDtoCodec.decode(n).caseOf({Left:e=>(0,s.Left)(new Error(`[ContextModule] HttpTokenAccountStateDataSource: malformed response for ${t}: ${e}`)),Right:e=>{let i;try{i=d.HexStringUtils.hexToBytes(e.signedDescriptor)}catch(c){return(0,s.Left)(new Error(`[ContextModule] HttpTokenAccountStateDataSource: invalid hex in signedDescriptor for ${t}: ${c.message}`))}return(0,s.Right)({tokenAccount:t,descriptor:i,keyId:e.keyId,keyUsage:e.keyUsage})}})}};a=l([(0,p.injectable)(),u(0,(0,p.inject)(f.configTypes.Config)),u(1,(0,p.inject)(k.networkTypes.NetworkClient))],a);0&&(module.exports={HttpTokenAccountStateDataSource});
1
+ "use strict";var p=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var h=(r,t)=>{for(var o in t)p(r,o,{get:t[o],enumerable:!0})},D=(r,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of S(t))!T.call(r,e)&&e!==o&&p(r,e,{get:()=>t[e],enumerable:!(n=g(t,e))||n.enumerable});return r};var C=r=>D(p({},"__esModule",{value:!0}),r),l=(r,t,o,n)=>{for(var e=n>1?void 0:n?g(t,o):t,i=r.length-1,c;i>=0;i--)(c=r[i])&&(e=(n?c(t,o,e):c(e))||e);return n&&e&&p(t,o,e),e},u=(r,t)=>(o,n)=>t(o,n,r);var A={};h(A,{HttpTokenAccountStateDataSource:()=>a});module.exports=C(A);var m=require("inversify"),s=require("purify-ts"),f=require("../../../../config/di/configTypes"),k=require("../../../../shared/network/di/networkTypes"),d=require("../../../../shared/utils/HexStringUtils"),y=require("../../../../shared/utils/signedDescriptorDto");let a=class{constructor(t,o){this.config=t;this.http=o}async getTokenAccountState({tokenAccount:t,challenge:o}){let n;try{n=await this.http.get(`${this.config.metadataServiceDomain.url}/v2/solana/token-account-state/${t}`,{params:{challenge:o}})}catch(e){const i=e instanceof Error?e.message:String(e);return(0,s.Left)(new Error(`[ContextModule] HttpTokenAccountStateDataSource: Failed to fetch token account state: ${i}`))}return y.signedDescriptorDtoCodec.decode(n).caseOf({Left:e=>(0,s.Left)(new Error(`[ContextModule] HttpTokenAccountStateDataSource: malformed response for ${t}: ${e}`)),Right:e=>{let i;try{i=d.HexStringUtils.hexToBytes(e.signedDescriptor)}catch(c){return(0,s.Left)(new Error(`[ContextModule] HttpTokenAccountStateDataSource: invalid hex in signedDescriptor for ${t}: ${c.message}`))}return(0,s.Right)({tokenAccount:t,descriptor:i,mint:n.mint,keyId:e.keyId,keyUsage:e.keyUsage})}})}};a=l([(0,m.injectable)(),u(0,(0,m.inject)(f.configTypes.Config)),u(1,(0,m.inject)(k.networkTypes.NetworkClient))],a);0&&(module.exports={HttpTokenAccountStateDataSource});
2
2
  //# sourceMappingURL=HttpTokenAccountStateDataSource.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/modules/solana/token-account-state/data/HttpTokenAccountStateDataSource.ts"],
4
- "sourcesContent": ["import { DmkNetworkClient } 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 { networkTypes } from \"@/shared/network/di/networkTypes\";\nimport { HexStringUtils } from \"@/shared/utils/HexStringUtils\";\nimport { signedDescriptorDtoCodec } from \"@/shared/utils/signedDescriptorDto\";\n\nimport {\n type GetTokenAccountStateParams,\n type TokenAccountStateDataSource,\n type TokenAccountStateResult,\n} from \"./TokenAccountStateDataSource\";\n\ntype TokenAccountStateResponseDto = {\n descriptorType?: string;\n descriptorVersion?: number;\n tokenAccount?: string;\n mint?: string;\n owner?: string;\n preBalance?: number;\n signedDescriptor: string;\n keyId: string;\n keyUsage: string;\n};\n\n@injectable()\nexport class HttpTokenAccountStateDataSource\n implements TokenAccountStateDataSource\n{\n constructor(\n @inject(configTypes.Config)\n private readonly config: ContextModuleServiceConfig,\n @inject(networkTypes.NetworkClient)\n private readonly http: DmkNetworkClient,\n ) {}\n\n public async getTokenAccountState({\n tokenAccount,\n challenge,\n }: GetTokenAccountStateParams): Promise<\n Either<Error, TokenAccountStateResult>\n > {\n let dto: TokenAccountStateResponseDto;\n try {\n dto = (await this.http.get(\n `${this.config.metadataServiceDomain.url}/v2/solana/token-account-state/${tokenAccount}`,\n { params: { challenge } },\n )) as TokenAccountStateResponseDto;\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n return Left(\n new Error(\n `[ContextModule] HttpTokenAccountStateDataSource: Failed to fetch token account state: ${reason}`,\n ),\n );\n }\n\n return signedDescriptorDtoCodec\n .decode(dto)\n .caseOf<Either<Error, TokenAccountStateResult>>({\n Left: (error) =>\n Left(\n new Error(\n `[ContextModule] HttpTokenAccountStateDataSource: malformed response for ${tokenAccount}: ${error}`,\n ),\n ),\n Right: (validated) => {\n let descriptor: Uint8Array;\n try {\n descriptor = HexStringUtils.hexToBytes(validated.signedDescriptor);\n } catch (error) {\n return Left(\n new Error(\n `[ContextModule] HttpTokenAccountStateDataSource: invalid hex in signedDescriptor for ${tokenAccount}: ${(error as Error).message}`,\n ),\n );\n }\n\n return Right({\n tokenAccount,\n descriptor,\n keyId: validated.keyId,\n keyUsage: validated.keyUsage,\n });\n },\n });\n }\n}\n"],
5
- "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qCAAAE,IAAA,eAAAC,EAAAH,GACA,IAAAI,EAAmC,qBACnCC,EAAoC,qBAEpCC,EAA4B,mCAE5BC,EAA6B,4CAC7BC,EAA+B,yCAC/BC,EAAyC,8CAqBlC,IAAMC,EAAN,KAEP,CACE,YAEmBC,EAEAC,EACjB,CAHiB,YAAAD,EAEA,UAAAC,CAChB,CAEH,MAAa,qBAAqB,CAChC,aAAAC,EACA,UAAAC,CACF,EAEE,CACA,IAAIC,EACJ,GAAI,CACFA,EAAO,MAAM,KAAK,KAAK,IACrB,GAAG,KAAK,OAAO,sBAAsB,GAAG,kCAAkCF,CAAY,GACtF,CAAE,OAAQ,CAAE,UAAAC,CAAU,CAAE,CAC1B,CACF,OAASE,EAAO,CACd,MAAMC,EAASD,aAAiB,MAAQA,EAAM,QAAU,OAAOA,CAAK,EACpE,SAAO,QACL,IAAI,MACF,yFAAyFC,CAAM,EACjG,CACF,CACF,CAEA,OAAO,2BACJ,OAAOF,CAAG,EACV,OAA+C,CAC9C,KAAOC,MACL,QACE,IAAI,MACF,2EAA2EH,CAAY,KAAKG,CAAK,EACnG,CACF,EACF,MAAQE,GAAc,CACpB,IAAIC,EACJ,GAAI,CACFA,EAAa,iBAAe,WAAWD,EAAU,gBAAgB,CACnE,OAASF,EAAO,CACd,SAAO,QACL,IAAI,MACF,wFAAwFH,CAAY,KAAMG,EAAgB,OAAO,EACnI,CACF,CACF,CAEA,SAAO,SAAM,CACX,aAAAH,EACA,WAAAM,EACA,MAAOD,EAAU,MACjB,SAAUA,EAAU,QACtB,CAAC,CACH,CACF,CAAC,CACL,CACF,EA7DaR,EAANU,EAAA,IADN,cAAW,EAKPC,EAAA,eAAO,cAAY,MAAM,GAEzBA,EAAA,eAAO,eAAa,aAAa,IANzBX",
4
+ "sourcesContent": ["import { DmkNetworkClient } 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 { networkTypes } from \"@/shared/network/di/networkTypes\";\nimport { HexStringUtils } from \"@/shared/utils/HexStringUtils\";\nimport { signedDescriptorDtoCodec } from \"@/shared/utils/signedDescriptorDto\";\n\nimport {\n type GetTokenAccountStateParams,\n type TokenAccountStateDataSource,\n type TokenAccountStateResult,\n} from \"./TokenAccountStateDataSource\";\n\ntype TokenAccountStateResponseDto = {\n descriptorType?: string;\n descriptorVersion?: number;\n tokenAccount?: string;\n mint?: string;\n owner?: string;\n preBalance?: number;\n signedDescriptor: string;\n keyId: string;\n keyUsage: string;\n};\n\n@injectable()\nexport class HttpTokenAccountStateDataSource\n implements TokenAccountStateDataSource\n{\n constructor(\n @inject(configTypes.Config)\n private readonly config: ContextModuleServiceConfig,\n @inject(networkTypes.NetworkClient)\n private readonly http: DmkNetworkClient,\n ) {}\n\n public async getTokenAccountState({\n tokenAccount,\n challenge,\n }: GetTokenAccountStateParams): Promise<\n Either<Error, TokenAccountStateResult>\n > {\n let dto: TokenAccountStateResponseDto;\n try {\n dto = (await this.http.get(\n `${this.config.metadataServiceDomain.url}/v2/solana/token-account-state/${tokenAccount}`,\n { params: { challenge } },\n )) as TokenAccountStateResponseDto;\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n return Left(\n new Error(\n `[ContextModule] HttpTokenAccountStateDataSource: Failed to fetch token account state: ${reason}`,\n ),\n );\n }\n\n return signedDescriptorDtoCodec\n .decode(dto)\n .caseOf<Either<Error, TokenAccountStateResult>>({\n Left: (error) =>\n Left(\n new Error(\n `[ContextModule] HttpTokenAccountStateDataSource: malformed response for ${tokenAccount}: ${error}`,\n ),\n ),\n Right: (validated) => {\n let descriptor: Uint8Array;\n try {\n descriptor = HexStringUtils.hexToBytes(validated.signedDescriptor);\n } catch (error) {\n return Left(\n new Error(\n `[ContextModule] HttpTokenAccountStateDataSource: invalid hex in signedDescriptor for ${tokenAccount}: ${(error as Error).message}`,\n ),\n );\n }\n\n return Right({\n tokenAccount,\n descriptor,\n mint: dto.mint,\n keyId: validated.keyId,\n keyUsage: validated.keyUsage,\n });\n },\n });\n }\n}\n"],
5
+ "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qCAAAE,IAAA,eAAAC,EAAAH,GACA,IAAAI,EAAmC,qBACnCC,EAAoC,qBAEpCC,EAA4B,mCAE5BC,EAA6B,4CAC7BC,EAA+B,yCAC/BC,EAAyC,8CAqBlC,IAAMC,EAAN,KAEP,CACE,YAEmBC,EAEAC,EACjB,CAHiB,YAAAD,EAEA,UAAAC,CAChB,CAEH,MAAa,qBAAqB,CAChC,aAAAC,EACA,UAAAC,CACF,EAEE,CACA,IAAIC,EACJ,GAAI,CACFA,EAAO,MAAM,KAAK,KAAK,IACrB,GAAG,KAAK,OAAO,sBAAsB,GAAG,kCAAkCF,CAAY,GACtF,CAAE,OAAQ,CAAE,UAAAC,CAAU,CAAE,CAC1B,CACF,OAASE,EAAO,CACd,MAAMC,EAASD,aAAiB,MAAQA,EAAM,QAAU,OAAOA,CAAK,EACpE,SAAO,QACL,IAAI,MACF,yFAAyFC,CAAM,EACjG,CACF,CACF,CAEA,OAAO,2BACJ,OAAOF,CAAG,EACV,OAA+C,CAC9C,KAAOC,MACL,QACE,IAAI,MACF,2EAA2EH,CAAY,KAAKG,CAAK,EACnG,CACF,EACF,MAAQE,GAAc,CACpB,IAAIC,EACJ,GAAI,CACFA,EAAa,iBAAe,WAAWD,EAAU,gBAAgB,CACnE,OAASF,EAAO,CACd,SAAO,QACL,IAAI,MACF,wFAAwFH,CAAY,KAAMG,EAAgB,OAAO,EACnI,CACF,CACF,CAEA,SAAO,SAAM,CACX,aAAAH,EACA,WAAAM,EACA,KAAMJ,EAAI,KACV,MAAOG,EAAU,MACjB,SAAUA,EAAU,QACtB,CAAC,CACH,CACF,CAAC,CACL,CACF,EA9DaR,EAANU,EAAA,IADN,cAAW,EAKPC,EAAA,eAAO,cAAY,MAAM,GAEzBA,EAAA,eAAO,eAAa,aAAa,IANzBX",
6
6
  "names": ["HttpTokenAccountStateDataSource_exports", "__export", "HttpTokenAccountStateDataSource", "__toCommonJS", "import_inversify", "import_purify_ts", "import_configTypes", "import_networkTypes", "import_HexStringUtils", "import_signedDescriptorDto", "HttpTokenAccountStateDataSource", "config", "http", "tokenAccount", "challenge", "dto", "error", "reason", "validated", "descriptor", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var n=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var i=Object.prototype.hasOwnProperty;var u=(e,t,c,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of s(t))!i.call(e,o)&&o!==c&&n(e,o,{get:()=>t[o],enumerable:!(r=a(t,o))||r.enumerable});return e};var k=e=>u(n({},"__esModule",{value:!0}),e);var p={};module.exports=k(p);
1
+ "use strict";var o=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var s=Object.prototype.hasOwnProperty;var u=(e,t,c,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of i(t))!s.call(e,n)&&n!==c&&o(e,n,{get:()=>t[n],enumerable:!(r=a(t,n))||r.enumerable});return e};var k=e=>u(o({},"__esModule",{value:!0}),e);var g={};module.exports=k(g);
2
2
  //# sourceMappingURL=TokenAccountStateDataSource.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/modules/solana/token-account-state/data/TokenAccountStateDataSource.ts"],
4
- "sourcesContent": ["import { type Either } from \"purify-ts\";\n\nexport type GetTokenAccountStateParams = {\n tokenAccount: string;\n challenge: string;\n};\n\nexport type TokenAccountStateResult = {\n tokenAccount: string;\n // Raw signed TLV bytes decoded from the backend response.\n descriptor: Uint8Array;\n keyId: string;\n keyUsage: string;\n};\n\nexport interface TokenAccountStateDataSource {\n getTokenAccountState(\n params: GetTokenAccountStateParams,\n ): Promise<Either<Error, TokenAccountStateResult>>;\n}\n"],
4
+ "sourcesContent": ["import { type Either } from \"purify-ts\";\n\nexport type GetTokenAccountStateParams = {\n tokenAccount: string;\n challenge: string;\n};\n\nexport type TokenAccountStateResult = {\n tokenAccount: string;\n // Raw signed TLV bytes decoded from the backend response.\n descriptor: Uint8Array;\n mint?: string;\n keyId: string;\n keyUsage: string;\n};\n\nexport interface TokenAccountStateDataSource {\n getTokenAccountState(\n params: GetTokenAccountStateParams,\n ): Promise<Either<Error, TokenAccountStateResult>>;\n}\n"],
5
5
  "mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
6
6
  "names": ["TokenAccountStateDataSource_exports", "__toCommonJS"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var l=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var h=(r,e)=>{for(var t in e)l(r,t,{get:e[t],enumerable:!0})},v=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of y(e))!k.call(r,n)&&n!==t&&l(r,n,{get:()=>e[n],enumerable:!(o=S(e,n))||o.enumerable});return r};var x=r=>v(l({},"__esModule",{value:!0}),r),g=(r,e,t,o)=>{for(var n=o>1?void 0:o?S(e,t):e,u=r.length-1,p;u>=0;u--)(p=r[u])&&(n=(o?p(e,t,n):p(n))||n);return o&&n&&l(e,t,n),n},d=(r,e)=>(t,o)=>e(t,o,r);var O={};h(O,{TokenAccountStateContextLoader:()=>i});module.exports=x(O);var c=require("inversify"),a=require("purify-ts"),C=require("../../../../config/di/configTypes"),T=require("../../../../modules/multichain/pki/di/pkiTypes"),m=require("../../../../modules/solana/token-account-state/di/tokenAccountStateTypes"),s=require("../../../../shared/model/ClearSignContext"),f=require("../../../../shared/utils/challengeBoundLoader"),A=require("../../../../shared/utils/deviceModelIdCodec");const L=[s.ClearSignContextType.SOLANA_TOKEN_ACCOUNT_STATE],I=a.Codec.interface({tokenAccount:a.string,challenge:a.string}),P=a.Codec.interface({deviceModelId:A.deviceModelIdCodec,requests:(0,a.array)(I)});let i=class{constructor(e,t,o){this.dataSource=e;this.certificateLoader=t;this.logger=o("TokenAccountStateContextLoader")}logger;canHandle(e,t){return L.every(o=>t.includes(o))?P.decode(e).caseOf({Left:()=>!1,Right:({requests:o})=>o.length>0&&o.every(n=>n.tokenAccount.length>0&&n.challenge.length>0)}):!1}async load(e){return(0,f.loadChallengeBoundContexts)({requests:e.requests,deviceModelId:e.deviceModelId,certificateLoader:this.certificateLoader,logger:this.logger,label:"TOKEN_ACCOUNT_STATE",fetch:t=>this.dataSource.getTokenAccountState(t),toContext:(t,o)=>{const n={descriptor:t.descriptor};return{type:s.ClearSignContextType.SOLANA_TOKEN_ACCOUNT_STATE,payload:n,certificate:o}},describe:t=>({tokenAccount:t.tokenAccount})})}};i=g([(0,c.injectable)(),d(0,(0,c.inject)(m.tokenAccountStateTypes.TokenAccountStateDataSource)),d(1,(0,c.inject)(T.pkiTypes.PkiCertificateLoader)),d(2,(0,c.inject)(C.configTypes.ContextModuleLoggerFactory))],i);0&&(module.exports={TokenAccountStateContextLoader});
1
+ "use strict";var l=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var h=(r,e)=>{for(var t in e)l(r,t,{get:e[t],enumerable:!0})},x=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of y(e))!k.call(r,n)&&n!==t&&l(r,n,{get:()=>e[n],enumerable:!(o=S(e,n))||o.enumerable});return r};var v=r=>x(l({},"__esModule",{value:!0}),r),g=(r,e,t,o)=>{for(var n=o>1?void 0:o?S(e,t):e,p=r.length-1,u;p>=0;p--)(u=r[p])&&(n=(o?u(e,t,n):u(n))||n);return o&&n&&l(e,t,n),n},d=(r,e)=>(t,o)=>e(t,o,r);var O={};h(O,{TokenAccountStateContextLoader:()=>i});module.exports=v(O);var a=require("inversify"),c=require("purify-ts"),m=require("../../../../config/di/configTypes"),C=require("../../../../modules/multichain/pki/di/pkiTypes"),T=require("../../../../modules/solana/token-account-state/di/tokenAccountStateTypes"),s=require("../../../../shared/model/ClearSignContext"),f=require("../../../../shared/utils/challengeBoundLoader"),A=require("../../../../shared/utils/deviceModelIdCodec");const L=[s.ClearSignContextType.SOLANA_TOKEN_ACCOUNT_STATE],I=c.Codec.interface({tokenAccount:c.string,challenge:c.string}),P=c.Codec.interface({deviceModelId:A.deviceModelIdCodec,requests:(0,c.array)(I)});let i=class{constructor(e,t,o){this.dataSource=e;this.certificateLoader=t;this.logger=o("TokenAccountStateContextLoader")}logger;canHandle(e,t){return L.every(o=>t.includes(o))?P.decode(e).caseOf({Left:()=>!1,Right:({requests:o})=>o.length>0&&o.every(n=>n.tokenAccount.length>0&&n.challenge.length>0)}):!1}async load(e){return(0,f.loadChallengeBoundContexts)({requests:e.requests,deviceModelId:e.deviceModelId,certificateLoader:this.certificateLoader,logger:this.logger,label:"TOKEN_ACCOUNT_STATE",fetch:t=>this.dataSource.getTokenAccountState(t),toContext:(t,o)=>{const n={descriptor:t.descriptor,mint:t.mint};return{type:s.ClearSignContextType.SOLANA_TOKEN_ACCOUNT_STATE,payload:n,certificate:o}},describe:t=>({tokenAccount:t.tokenAccount})})}};i=g([(0,a.injectable)(),d(0,(0,a.inject)(T.tokenAccountStateTypes.TokenAccountStateDataSource)),d(1,(0,a.inject)(C.pkiTypes.PkiCertificateLoader)),d(2,(0,a.inject)(m.configTypes.ContextModuleLoggerFactory))],i);0&&(module.exports={TokenAccountStateContextLoader});
2
2
  //# sourceMappingURL=TokenAccountStateContextLoader.js.map