@ledgerhq/context-module 1.14.1 → 1.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/lib/cjs/package.json +2 -2
  2. package/lib/cjs/src/DefaultContextModule.js +1 -1
  3. package/lib/cjs/src/DefaultContextModule.js.map +3 -3
  4. package/lib/cjs/src/di.js +1 -1
  5. package/lib/cjs/src/di.js.map +3 -3
  6. package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.js +1 -1
  7. package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.js.map +3 -3
  8. package/lib/cjs/src/gated-signing/data/GatedDescriptorDataSource.js +2 -0
  9. package/lib/cjs/src/gated-signing/data/GatedDescriptorDataSource.js.map +7 -0
  10. package/lib/cjs/src/gated-signing/data/HttpGatedDescriptorDataSource.js +2 -0
  11. package/lib/cjs/src/gated-signing/data/HttpGatedDescriptorDataSource.js.map +7 -0
  12. package/lib/cjs/src/gated-signing/data/HttpGatedDescriptorDataSource.test.js +2 -0
  13. package/lib/cjs/src/gated-signing/data/HttpGatedDescriptorDataSource.test.js.map +7 -0
  14. package/lib/cjs/src/gated-signing/data/dto/GatedDappsDto.js +2 -0
  15. package/lib/cjs/src/gated-signing/data/dto/GatedDappsDto.js.map +7 -0
  16. package/lib/cjs/src/gated-signing/di/gatedSigningModuleFactory.js +2 -0
  17. package/lib/cjs/src/gated-signing/di/gatedSigningModuleFactory.js.map +7 -0
  18. package/lib/cjs/src/gated-signing/di/gatedSigningTypes.js +2 -0
  19. package/lib/cjs/src/gated-signing/di/gatedSigningTypes.js.map +7 -0
  20. package/lib/cjs/src/gated-signing/domain/GatedSigningContextLoader.js +2 -0
  21. package/lib/cjs/src/gated-signing/domain/GatedSigningContextLoader.js.map +7 -0
  22. package/lib/cjs/src/gated-signing/domain/GatedSigningContextLoader.test.js +2 -0
  23. package/lib/cjs/src/gated-signing/domain/GatedSigningContextLoader.test.js.map +7 -0
  24. package/lib/cjs/src/gated-signing/domain/GatedSigningTypedDataContextLoader.js +2 -0
  25. package/lib/cjs/src/gated-signing/domain/GatedSigningTypedDataContextLoader.js.map +7 -0
  26. package/lib/cjs/src/gated-signing/domain/GatedSigningTypedDataContextLoader.test.js +2 -0
  27. package/lib/cjs/src/gated-signing/domain/GatedSigningTypedDataContextLoader.test.js.map +7 -0
  28. package/lib/cjs/src/index.js +1 -1
  29. package/lib/cjs/src/index.js.map +2 -2
  30. package/lib/cjs/src/pki/model/KeyId.js +1 -1
  31. package/lib/cjs/src/pki/model/KeyId.js.map +2 -2
  32. package/lib/cjs/src/pki/model/KeyUsage.js +1 -1
  33. package/lib/cjs/src/pki/model/KeyUsage.js.map +2 -2
  34. package/lib/cjs/src/shared/model/ClearSignContext.js +1 -1
  35. package/lib/cjs/src/shared/model/ClearSignContext.js.map +2 -2
  36. package/lib/cjs/src/shared/model/SolanaContextTypes.js +1 -1
  37. package/lib/cjs/src/shared/model/SolanaContextTypes.js.map +1 -1
  38. package/lib/cjs/src/shared/utils/KeyUsageMapper.js +1 -1
  39. package/lib/cjs/src/shared/utils/KeyUsageMapper.js.map +2 -2
  40. package/lib/cjs/src/shared/utils/KeyUsageMapper.test.js +1 -1
  41. package/lib/cjs/src/shared/utils/KeyUsageMapper.test.js.map +2 -2
  42. package/lib/cjs/src/solana/domain/DefaultSolanaContextLoader.js +1 -1
  43. package/lib/cjs/src/solana/domain/DefaultSolanaContextLoader.js.map +3 -3
  44. package/lib/cjs/src/solana/domain/solanaContextTypes.js.map +1 -1
  45. package/lib/cjs/src/solanaLifi/data/HttpSolanaLifiDataSource.js +1 -1
  46. package/lib/cjs/src/solanaLifi/data/HttpSolanaLifiDataSource.js.map +3 -3
  47. package/lib/cjs/src/solanaLifi/data/HttpSolanaLifiDataSource.test.js +1 -1
  48. package/lib/cjs/src/solanaLifi/data/HttpSolanaLifiDataSource.test.js.map +3 -3
  49. package/lib/cjs/src/solanaLifi/data/SolanaLifiDataSource.js +1 -1
  50. package/lib/cjs/src/solanaLifi/data/SolanaLifiDataSource.js.map +1 -1
  51. package/lib/cjs/src/solanaLifi/domain/SolanaLifiContextLoader.js +1 -1
  52. package/lib/cjs/src/solanaLifi/domain/SolanaLifiContextLoader.js.map +3 -3
  53. package/lib/cjs/src/solanaLifi/domain/SolanaLifiContextLoader.test.js +1 -1
  54. package/lib/cjs/src/solanaLifi/domain/SolanaLifiContextLoader.test.js.map +3 -3
  55. package/lib/cjs/src/solanaToken/domain/SolanaTokenContextLoader.js +1 -1
  56. package/lib/cjs/src/solanaToken/domain/SolanaTokenContextLoader.js.map +2 -2
  57. package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.js +1 -1
  58. package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.js.map +3 -3
  59. package/lib/cjs/src/typed-data/utils/getSchemaHash.js +2 -0
  60. package/lib/cjs/src/typed-data/utils/getSchemaHash.js.map +7 -0
  61. package/lib/cjs/src/typed-data/utils/getSchemaHash.test.js +2 -0
  62. package/lib/cjs/src/typed-data/utils/getSchemaHash.test.js.map +7 -0
  63. package/lib/esm/package.json +2 -2
  64. package/lib/esm/src/DefaultContextModule.js +1 -1
  65. package/lib/esm/src/DefaultContextModule.js.map +3 -3
  66. package/lib/esm/src/di.js +1 -1
  67. package/lib/esm/src/di.js.map +3 -3
  68. package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.js +1 -1
  69. package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.js.map +3 -3
  70. package/lib/esm/src/gated-signing/data/GatedDescriptorDataSource.js +1 -0
  71. package/lib/esm/src/gated-signing/data/GatedDescriptorDataSource.js.map +7 -0
  72. package/lib/esm/src/gated-signing/data/HttpGatedDescriptorDataSource.js +2 -0
  73. package/lib/esm/src/gated-signing/data/HttpGatedDescriptorDataSource.js.map +7 -0
  74. package/lib/esm/src/gated-signing/data/HttpGatedDescriptorDataSource.test.js +2 -0
  75. package/lib/esm/src/gated-signing/data/HttpGatedDescriptorDataSource.test.js.map +7 -0
  76. package/lib/esm/src/gated-signing/data/dto/GatedDappsDto.js +1 -0
  77. package/lib/esm/src/gated-signing/data/dto/GatedDappsDto.js.map +7 -0
  78. package/lib/esm/src/gated-signing/di/gatedSigningModuleFactory.js +2 -0
  79. package/lib/esm/src/gated-signing/di/gatedSigningModuleFactory.js.map +7 -0
  80. package/lib/esm/src/gated-signing/di/gatedSigningTypes.js +2 -0
  81. package/lib/esm/src/gated-signing/di/gatedSigningTypes.js.map +7 -0
  82. package/lib/esm/src/gated-signing/domain/GatedSigningContextLoader.js +2 -0
  83. package/lib/esm/src/gated-signing/domain/GatedSigningContextLoader.js.map +7 -0
  84. package/lib/esm/src/gated-signing/domain/GatedSigningContextLoader.test.js +2 -0
  85. package/lib/esm/src/gated-signing/domain/GatedSigningContextLoader.test.js.map +7 -0
  86. package/lib/esm/src/gated-signing/domain/GatedSigningTypedDataContextLoader.js +2 -0
  87. package/lib/esm/src/gated-signing/domain/GatedSigningTypedDataContextLoader.js.map +7 -0
  88. package/lib/esm/src/gated-signing/domain/GatedSigningTypedDataContextLoader.test.js +2 -0
  89. package/lib/esm/src/gated-signing/domain/GatedSigningTypedDataContextLoader.test.js.map +7 -0
  90. package/lib/esm/src/index.js +1 -1
  91. package/lib/esm/src/index.js.map +2 -2
  92. package/lib/esm/src/pki/model/KeyId.js +1 -1
  93. package/lib/esm/src/pki/model/KeyId.js.map +2 -2
  94. package/lib/esm/src/pki/model/KeyUsage.js +1 -1
  95. package/lib/esm/src/pki/model/KeyUsage.js.map +2 -2
  96. package/lib/esm/src/shared/model/ClearSignContext.js +1 -1
  97. package/lib/esm/src/shared/model/ClearSignContext.js.map +2 -2
  98. package/lib/esm/src/shared/model/SolanaContextTypes.js.map +1 -1
  99. package/lib/esm/src/shared/utils/KeyUsageMapper.js +1 -1
  100. package/lib/esm/src/shared/utils/KeyUsageMapper.js.map +2 -2
  101. package/lib/esm/src/shared/utils/KeyUsageMapper.test.js +1 -1
  102. package/lib/esm/src/shared/utils/KeyUsageMapper.test.js.map +2 -2
  103. package/lib/esm/src/solana/domain/DefaultSolanaContextLoader.js +1 -1
  104. package/lib/esm/src/solana/domain/DefaultSolanaContextLoader.js.map +3 -3
  105. package/lib/esm/src/solanaLifi/data/HttpSolanaLifiDataSource.js +1 -1
  106. package/lib/esm/src/solanaLifi/data/HttpSolanaLifiDataSource.js.map +3 -3
  107. package/lib/esm/src/solanaLifi/data/HttpSolanaLifiDataSource.test.js +1 -1
  108. package/lib/esm/src/solanaLifi/data/HttpSolanaLifiDataSource.test.js.map +3 -3
  109. package/lib/esm/src/solanaLifi/domain/SolanaLifiContextLoader.js +1 -1
  110. package/lib/esm/src/solanaLifi/domain/SolanaLifiContextLoader.js.map +3 -3
  111. package/lib/esm/src/solanaLifi/domain/SolanaLifiContextLoader.test.js +1 -1
  112. package/lib/esm/src/solanaLifi/domain/SolanaLifiContextLoader.test.js.map +3 -3
  113. package/lib/esm/src/solanaToken/domain/SolanaTokenContextLoader.js +1 -1
  114. package/lib/esm/src/solanaToken/domain/SolanaTokenContextLoader.js.map +2 -2
  115. package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.js +1 -1
  116. package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.js.map +3 -3
  117. package/lib/esm/src/typed-data/utils/getSchemaHash.js +2 -0
  118. package/lib/esm/src/typed-data/utils/getSchemaHash.js.map +7 -0
  119. package/lib/esm/src/typed-data/utils/getSchemaHash.test.js +2 -0
  120. package/lib/esm/src/typed-data/utils/getSchemaHash.test.js.map +7 -0
  121. package/lib/types/src/DefaultContextModule.d.ts.map +1 -1
  122. package/lib/types/src/di.d.ts.map +1 -1
  123. package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.d.ts +2 -0
  124. package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.d.ts.map +1 -1
  125. package/lib/types/src/gated-signing/data/GatedDescriptorDataSource.d.ts +20 -0
  126. package/lib/types/src/gated-signing/data/GatedDescriptorDataSource.d.ts.map +1 -0
  127. package/lib/types/src/gated-signing/data/HttpGatedDescriptorDataSource.d.ts +13 -0
  128. package/lib/types/src/gated-signing/data/HttpGatedDescriptorDataSource.d.ts.map +1 -0
  129. package/lib/types/src/gated-signing/data/HttpGatedDescriptorDataSource.test.d.ts +2 -0
  130. package/lib/types/src/gated-signing/data/HttpGatedDescriptorDataSource.test.d.ts.map +1 -0
  131. package/lib/types/src/gated-signing/data/dto/GatedDappsDto.d.ts +15 -0
  132. package/lib/types/src/gated-signing/data/dto/GatedDappsDto.d.ts.map +1 -0
  133. package/lib/types/src/gated-signing/di/gatedSigningModuleFactory.d.ts +3 -0
  134. package/lib/types/src/gated-signing/di/gatedSigningModuleFactory.d.ts.map +1 -0
  135. package/lib/types/src/gated-signing/di/gatedSigningTypes.d.ts +6 -0
  136. package/lib/types/src/gated-signing/di/gatedSigningTypes.d.ts.map +1 -0
  137. package/lib/types/src/gated-signing/domain/GatedSigningContextLoader.d.ts +22 -0
  138. package/lib/types/src/gated-signing/domain/GatedSigningContextLoader.d.ts.map +1 -0
  139. package/lib/types/src/gated-signing/domain/GatedSigningContextLoader.test.d.ts +2 -0
  140. package/lib/types/src/gated-signing/domain/GatedSigningContextLoader.test.d.ts.map +1 -0
  141. package/lib/types/src/gated-signing/domain/GatedSigningTypedDataContextLoader.d.ts +27 -0
  142. package/lib/types/src/gated-signing/domain/GatedSigningTypedDataContextLoader.d.ts.map +1 -0
  143. package/lib/types/src/gated-signing/domain/GatedSigningTypedDataContextLoader.test.d.ts +2 -0
  144. package/lib/types/src/gated-signing/domain/GatedSigningTypedDataContextLoader.test.d.ts.map +1 -0
  145. package/lib/types/src/index.d.ts +5 -0
  146. package/lib/types/src/index.d.ts.map +1 -1
  147. package/lib/types/src/pki/model/KeyId.d.ts +3 -1
  148. package/lib/types/src/pki/model/KeyId.d.ts.map +1 -1
  149. package/lib/types/src/pki/model/KeyUsage.d.ts +3 -1
  150. package/lib/types/src/pki/model/KeyUsage.d.ts.map +1 -1
  151. package/lib/types/src/shared/model/ClearSignContext.d.ts +2 -1
  152. package/lib/types/src/shared/model/ClearSignContext.d.ts.map +1 -1
  153. package/lib/types/src/shared/model/SolanaContextTypes.d.ts +33 -3
  154. package/lib/types/src/shared/model/SolanaContextTypes.d.ts.map +1 -1
  155. package/lib/types/src/shared/utils/KeyUsageMapper.d.ts.map +1 -1
  156. package/lib/types/src/solana/domain/DefaultSolanaContextLoader.d.ts +4 -1
  157. package/lib/types/src/solana/domain/DefaultSolanaContextLoader.d.ts.map +1 -1
  158. package/lib/types/src/solana/domain/solanaContextTypes.d.ts +2 -2
  159. package/lib/types/src/solana/domain/solanaContextTypes.d.ts.map +1 -1
  160. package/lib/types/src/solanaLifi/data/HttpSolanaLifiDataSource.d.ts +3 -1
  161. package/lib/types/src/solanaLifi/data/HttpSolanaLifiDataSource.d.ts.map +1 -1
  162. package/lib/types/src/solanaLifi/data/SolanaLifiDataSource.d.ts +2 -5
  163. package/lib/types/src/solanaLifi/data/SolanaLifiDataSource.d.ts.map +1 -1
  164. package/lib/types/src/solanaLifi/domain/SolanaLifiContextLoader.d.ts +10 -8
  165. package/lib/types/src/solanaLifi/domain/SolanaLifiContextLoader.d.ts.map +1 -1
  166. package/lib/types/src/solanaToken/domain/SolanaTokenContextLoader.d.ts +4 -9
  167. package/lib/types/src/solanaToken/domain/SolanaTokenContextLoader.d.ts.map +1 -1
  168. package/lib/types/src/typed-data/data/HttpTypedDataDataSource.d.ts +0 -1
  169. package/lib/types/src/typed-data/data/HttpTypedDataDataSource.d.ts.map +1 -1
  170. package/lib/types/src/typed-data/utils/getSchemaHash.d.ts +12 -0
  171. package/lib/types/src/typed-data/utils/getSchemaHash.d.ts.map +1 -0
  172. package/lib/types/src/typed-data/utils/getSchemaHash.test.d.ts +2 -0
  173. package/lib/types/src/typed-data/utils/getSchemaHash.test.d.ts.map +1 -0
  174. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  175. package/package.json +5 -5
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/solanaLifi/data/SolanaLifiDataSource.ts"],
4
- "sourcesContent": ["import { type Either } from \"purify-ts\";\n\nimport { type SolanaTransactionDescriptorList } from \"@/shared/model/SolanaContextTypes\";\n\nexport type GetTransactionDescriptorsParams = {\n templateId: string;\n};\n\nexport type GetTransactionDescriptorsResponse = {\n [key: string]: unknown;\n descriptors: SolanaTransactionDescriptorList;\n};\n\nexport interface SolanaLifiDataSource {\n getTransactionDescriptorsPayload(\n params: GetTransactionDescriptorsParams,\n ): Promise<Either<Error, GetTransactionDescriptorsResponse>>;\n}\n"],
4
+ "sourcesContent": ["import { type Either } from \"purify-ts\";\n\nimport type { GetTransactionDescriptorsResponse } from \"@/shared/model/SolanaContextTypes\";\n\nexport type GetTransactionDescriptorsParams = {\n templateId: string;\n};\n\nexport type { GetTransactionDescriptorsResponse };\n\nexport interface SolanaLifiDataSource {\n getTransactionDescriptorsPayload(\n params: GetTransactionDescriptorsParams,\n ): Promise<Either<Error, GetTransactionDescriptorsResponse>>;\n}\n"],
5
5
  "mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
6
6
  "names": ["SolanaLifiDataSource_exports", "__toCommonJS"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var l=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var y=(o,t)=>{for(var e in t)l(o,e,{get:t[e],enumerable:!0})},x=(o,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of m(t))!L.call(o,a)&&a!==e&&l(o,a,{get:()=>t[a],enumerable:!(i=u(t,a))||i.enumerable});return o};var T=o=>x(l({},"__esModule",{value:!0}),o),f=(o,t,e,i)=>{for(var a=i>1?void 0:i?u(t,e):t,p=o.length-1,c;p>=0;p--)(c=o[p])&&(a=(i?c(t,e,a):c(a))||a);return i&&a&&l(t,e,a),a},d=(o,t)=>(e,i)=>t(e,i,o);var F={};y(F,{SolanaLifiContextLoader:()=>n});module.exports=T(F);var r=require("inversify"),g=require("../../config/di/configTypes"),s=require("../../shared/model/SolanaContextTypes"),S=require("../../solanaLifi/di/solanaLifiTypes");let n=class{constructor(t,e){this.dataSource=t;this.logger=e("SolanaLifiContextLoader")}logger;canHandle(t,e){if(e!==s.SolanaContextTypes.SOLANA_LIFI)return!1;if(typeof t=="object"&&t!==null&&"templateId"in t){const i=t.templateId;return typeof i=="string"&&i.length>0}return!1}async loadField(t){this.logger.debug("[loadField] Loading solana Lifi context",{data:{input:t}});const{templateId:e}=t;return(await this.dataSource.getTransactionDescriptorsPayload({templateId:e})).caseOf({Left:a=>(this.logger.error("[loadField] Error loading solana Lifi context",{data:{error:a}}),{type:s.SolanaContextTypes.ERROR,error:a}),Right:a=>(this.logger.debug("[loadField] Successfully loaded solana Lifi context",{data:{payload:this.pluckTransactionData(a)}}),{type:s.SolanaContextTypes.SOLANA_LIFI,payload:this.pluckTransactionData(a)})})}pluckTransactionData(t){return{...t.descriptors}}};n=f([(0,r.injectable)(),d(0,(0,r.inject)(S.lifiTypes.SolanaLifiDataSource)),d(1,(0,r.inject)(g.configTypes.ContextModuleLoggerFactory))],n);0&&(module.exports={SolanaLifiContextLoader});
1
+ "use strict";var p=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var T=(r,t)=>{for(var a in t)p(r,a,{get:t[a],enumerable:!0})},I=(r,t,a,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of x(t))!C.call(r,e)&&e!==a&&p(r,e,{get:()=>t[e],enumerable:!(i=m(t,e))||i.enumerable});return r};var b=r=>I(p({},"__esModule",{value:!0}),r),f=(r,t,a,i)=>{for(var e=i>1?void 0:i?m(t,a):t,o=r.length-1,n;o>=0;o--)(n=r[o])&&(e=(i?n(t,a,e):n(e))||e);return i&&e&&p(t,a,e),e},d=(r,t)=>(a,i)=>t(a,i,r);var k={};T(k,{SolanaLifiContextLoader:()=>l});module.exports=b(k);var s=require("inversify"),u=require("../../config/di/configTypes"),y=require("../../pki/di/pkiTypes"),S=require("../../pki/model/KeyId"),L=require("../../pki/model/KeyUsage"),c=require("../../shared/model/SolanaContextTypes"),h=require("../../solanaLifi/di/solanaLifiTypes");let l=class{constructor(t,a,i,e){this.dataSource=t;this.config=a;this._certificateLoader=i;this.logger=e("SolanaLifiContextLoader")}logger;canHandle(t,a){if(a!==c.SolanaContextTypes.SOLANA_LIFI)return this.logger.debug("[canHandle] Skipping, expected type does not match",{data:{expectedType:a,required:c.SolanaContextTypes.SOLANA_LIFI}}),!1;if(typeof t=="object"&&t!==null&&"templateId"in t){const i=t.templateId,e=typeof i=="string"&&i.length>0;return this.logger.debug("[canHandle] Field validation result",{data:{templateId:i,isValid:e}}),e}return this.logger.debug("[canHandle] Field does not contain a valid templateId",{data:{field:t}}),!1}async loadField(t){this.logger.debug("[loadField] Loading solana Lifi context",{data:{input:t}});const{templateId:a,deviceModelId:i}=t;if(!a)return{type:c.SolanaContextTypes.ERROR,error:new Error("[ContextModule] SolanaLifiContextLoader: templateId is missing")};const e=await this.dataSource.getTransactionDescriptorsPayload({templateId:a}),o=await this._certificateLoader.loadCertificate({keyId:S.KeyId.SwapTemplateKey,keyUsage:L.KeyUsage.SwapTemplate,targetDevice:i});return e.caseOf({Left:n=>(this.logger.error("[loadField] Error loading solana Lifi context",{data:{error:n}}),{type:c.SolanaContextTypes.ERROR,error:n}),Right:n=>{const g=this.buildPayload(n);return this.logger.debug("[loadField] Successfully loaded solana Lifi context",{data:{descriptors:g.descriptors,instructionsCount:g.instructions.length,certificate:o}}),{type:c.SolanaContextTypes.SOLANA_LIFI,payload:g,certificate:o}}})}buildPayload(t){return{descriptors:this.pluckTransactionData(t),instructions:this.extractInstructionsMeta(t)}}pluckTransactionData(t){const a=this.config.cal.mode||"prod",i={},e=t.descriptors??[];this.logger.debug("[pluckTransactionData] Processing descriptors",{data:{descriptorsCount:e.length,signatureKind:a}});for(const o of e){const n=`${o.program_id}:${o.discriminator_hex??""}`;i[n]={data:o.descriptor.data,descriptorType:o.descriptor.descriptorType,descriptorVersion:o.descriptor.descriptorVersion,signature:o.descriptor.signatures[a]??""},this.logger.debug("[pluckTransactionData] Mapped program descriptor",{data:{programId:o.program_id,discriminatorHex:o.discriminator_hex??"",key:n}})}return this.logger.debug("[pluckTransactionData] Completed processing",{data:{outputKeys:Object.keys(i)}}),i}extractInstructionsMeta(t){const a=t.instructions??[];this.logger.debug("[extractInstructionsMeta] Extracting instructions metadata",{data:{instructionsCount:a.length}});const i=a.map(e=>({program_id:e.program_id,...e.discriminator_hex!==void 0&&{discriminator_hex:e.discriminator_hex}}));return this.logger.debug("[extractInstructionsMeta] Completed extracting instructions metadata",{data:{meta:i.map(e=>({programId:e.program_id,discriminatorHex:e.discriminator_hex}))}}),i}};l=f([(0,s.injectable)(),d(0,(0,s.inject)(h.lifiTypes.SolanaLifiDataSource)),d(1,(0,s.inject)(u.configTypes.Config)),d(2,(0,s.inject)(y.pkiTypes.PkiCertificateLoader)),d(3,(0,s.inject)(u.configTypes.ContextModuleLoggerFactory))],l);0&&(module.exports={SolanaLifiContextLoader});
2
2
  //# sourceMappingURL=SolanaLifiContextLoader.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/solanaLifi/domain/SolanaLifiContextLoader.ts"],
4
- "sourcesContent": ["import { LoggerPublisherService } from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { ContextFieldLoader } from \"@/shared/domain/ContextFieldLoader\";\nimport {\n SolanaContextTypes,\n SolanaLifiContextResult,\n SolanaTransactionDescriptorList,\n} from \"@/shared/model/SolanaContextTypes\";\nimport { SolanaTransactionContext } from \"@/solana/domain/solanaContextTypes\";\nimport {\n GetTransactionDescriptorsResponse,\n type SolanaLifiDataSource,\n} from \"@/solanaLifi/data/SolanaLifiDataSource\";\nimport { lifiTypes } from \"@/solanaLifi/di/solanaLifiTypes\";\n\ntype SolanaLifiFieldInput = SolanaTransactionContext & {\n templateId: string;\n};\n\n@injectable()\nexport class SolanaLifiContextLoader\n implements\n ContextFieldLoader<\n SolanaLifiFieldInput,\n SolanaContextTypes,\n SolanaLifiContextResult\n >\n{\n private logger: LoggerPublisherService;\n\n constructor(\n @inject(lifiTypes.SolanaLifiDataSource)\n private readonly dataSource: SolanaLifiDataSource,\n @inject(configTypes.ContextModuleLoggerFactory)\n loggerFactory: (tag: string) => LoggerPublisherService,\n ) {\n this.logger = loggerFactory(\"SolanaLifiContextLoader\");\n }\n\n public canHandle(\n field: unknown,\n expectedType: SolanaContextTypes,\n ): field is SolanaLifiFieldInput {\n if (expectedType !== SolanaContextTypes.SOLANA_LIFI) return false;\n\n if (typeof field === \"object\" && field !== null && \"templateId\" in field) {\n const templateId = (field as { templateId: unknown }).templateId;\n return typeof templateId === \"string\" && templateId.length > 0;\n }\n\n return false;\n }\n\n public async loadField(\n solanaTokenContextInput: SolanaLifiFieldInput,\n ): Promise<SolanaLifiContextResult> {\n this.logger.debug(\"[loadField] Loading solana Lifi context\", {\n data: { input: solanaTokenContextInput },\n });\n const { templateId } = solanaTokenContextInput;\n\n const payload = await this.dataSource.getTransactionDescriptorsPayload({\n templateId,\n });\n\n return payload.caseOf({\n Left: (error): SolanaLifiContextResult => {\n this.logger.error(\"[loadField] Error loading solana Lifi context\", {\n data: { error },\n });\n\n return {\n type: SolanaContextTypes.ERROR,\n error,\n };\n },\n Right: (value): SolanaLifiContextResult => {\n this.logger.debug(\n \"[loadField] Successfully loaded solana Lifi context\",\n {\n data: { payload: this.pluckTransactionData(value) },\n },\n );\n\n return {\n type: SolanaContextTypes.SOLANA_LIFI,\n payload: this.pluckTransactionData(value),\n };\n },\n });\n }\n\n private pluckTransactionData(\n tokenData: GetTransactionDescriptorsResponse,\n ): SolanaTransactionDescriptorList {\n return {\n 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": ["SolanaLifiContextLoader_exports", "__export", "SolanaLifiContextLoader", "__toCommonJS", "import_inversify", "import_configTypes", "import_SolanaContextTypes", "import_solanaLifiTypes", "SolanaLifiContextLoader", "dataSource", "loggerFactory", "field", "expectedType", "templateId", "solanaTokenContextInput", "error", "value", "tokenData", "__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 ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { type PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { ContextFieldLoader } from \"@/shared/domain/ContextFieldLoader\";\nimport {\n SolanaContextTypes,\n SolanaLifiContextResult,\n type SolanaLifiInstructionMeta,\n type SolanaLifiPayload,\n SolanaTransactionDescriptorList,\n} from \"@/shared/model/SolanaContextTypes\";\nimport { SolanaTransactionContext } from \"@/solana/domain/solanaContextTypes\";\nimport {\n GetTransactionDescriptorsResponse,\n type SolanaLifiDataSource,\n} from \"@/solanaLifi/data/SolanaLifiDataSource\";\nimport { lifiTypes } from \"@/solanaLifi/di/solanaLifiTypes\";\n\n@injectable()\nexport class SolanaLifiContextLoader\n implements\n ContextFieldLoader<\n SolanaTransactionContext,\n SolanaContextTypes,\n SolanaLifiContextResult\n >\n{\n private logger: LoggerPublisherService;\n\n constructor(\n @inject(lifiTypes.SolanaLifiDataSource)\n private readonly dataSource: SolanaLifiDataSource,\n @inject(configTypes.Config)\n private readonly config: ContextModuleConfig,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n @inject(configTypes.ContextModuleLoggerFactory)\n loggerFactory: (tag: string) => LoggerPublisherService,\n ) {\n this.logger = loggerFactory(\"SolanaLifiContextLoader\");\n }\n\n public canHandle(\n field: unknown,\n expectedType: SolanaContextTypes,\n ): field is SolanaTransactionContext {\n if (expectedType !== SolanaContextTypes.SOLANA_LIFI) {\n this.logger.debug(\"[canHandle] Skipping, expected type does not match\", {\n data: { expectedType, required: SolanaContextTypes.SOLANA_LIFI },\n });\n return false;\n }\n\n if (typeof field === \"object\" && field !== null && \"templateId\" in field) {\n const templateId = (field as { templateId: unknown }).templateId;\n const isValid = typeof templateId === \"string\" && templateId.length > 0;\n this.logger.debug(\"[canHandle] Field validation result\", {\n data: { templateId, isValid },\n });\n return isValid;\n }\n\n this.logger.debug(\"[canHandle] Field does not contain a valid templateId\", {\n data: { field },\n });\n return false;\n }\n\n public async loadField(\n solanaLifiContextInput: SolanaTransactionContext,\n ): Promise<SolanaLifiContextResult> {\n this.logger.debug(\"[loadField] Loading solana Lifi context\", {\n data: { input: solanaLifiContextInput },\n });\n const { templateId, deviceModelId } = solanaLifiContextInput;\n\n if (!templateId) {\n return {\n type: SolanaContextTypes.ERROR,\n error: new Error(\n \"[ContextModule] SolanaLifiContextLoader: templateId is missing\",\n ),\n };\n }\n\n const payload = await this.dataSource.getTransactionDescriptorsPayload({\n templateId,\n });\n\n const certificate: PkiCertificate | undefined =\n await this._certificateLoader.loadCertificate({\n keyId: KeyId.SwapTemplateKey,\n keyUsage: KeyUsage.SwapTemplate,\n targetDevice: deviceModelId,\n });\n\n return payload.caseOf({\n Left: (error): SolanaLifiContextResult => {\n this.logger.error(\"[loadField] Error loading solana Lifi context\", {\n data: { error },\n });\n\n return {\n type: SolanaContextTypes.ERROR,\n error,\n };\n },\n Right: (value): SolanaLifiContextResult => {\n const lifiPayload = this.buildPayload(value);\n this.logger.debug(\n \"[loadField] Successfully loaded solana Lifi context\",\n {\n data: {\n descriptors: lifiPayload.descriptors,\n instructionsCount: lifiPayload.instructions.length,\n certificate,\n },\n },\n );\n\n return {\n type: SolanaContextTypes.SOLANA_LIFI,\n payload: lifiPayload,\n certificate,\n };\n },\n });\n }\n\n private buildPayload(\n response: GetTransactionDescriptorsResponse,\n ): SolanaLifiPayload {\n return {\n descriptors: this.pluckTransactionData(response),\n instructions: this.extractInstructionsMeta(response),\n };\n }\n\n private pluckTransactionData(\n tokenData: GetTransactionDescriptorsResponse,\n ): SolanaTransactionDescriptorList {\n const signatureKind = this.config.cal.mode || \"prod\";\n const output: SolanaTransactionDescriptorList = {};\n const descriptors = tokenData.descriptors ?? [];\n\n this.logger.debug(\"[pluckTransactionData] Processing descriptors\", {\n data: { descriptorsCount: descriptors.length, signatureKind },\n });\n\n for (const item of descriptors) {\n const key = `${item.program_id}:${item.discriminator_hex ?? \"\"}`;\n output[key] = {\n data: item.descriptor.data,\n descriptorType: item.descriptor.descriptorType,\n descriptorVersion: item.descriptor.descriptorVersion,\n signature: item.descriptor.signatures[signatureKind] ?? \"\",\n };\n this.logger.debug(\"[pluckTransactionData] Mapped program descriptor\", {\n data: {\n programId: item.program_id,\n discriminatorHex: item.discriminator_hex ?? \"\",\n key,\n },\n });\n }\n\n this.logger.debug(\"[pluckTransactionData] Completed processing\", {\n data: { outputKeys: Object.keys(output) },\n });\n\n return output;\n }\n\n private extractInstructionsMeta(\n response: GetTransactionDescriptorsResponse,\n ): SolanaLifiInstructionMeta[] {\n const instructions = response.instructions ?? [];\n\n this.logger.debug(\n \"[extractInstructionsMeta] Extracting instructions metadata\",\n {\n data: { instructionsCount: instructions.length },\n },\n );\n\n const meta = instructions.map((ix) => ({\n program_id: ix.program_id,\n ...(ix.discriminator_hex !== undefined && {\n discriminator_hex: ix.discriminator_hex,\n }),\n }));\n\n this.logger.debug(\n \"[extractInstructionsMeta] Completed extracting instructions metadata\",\n {\n data: {\n meta: meta.map((m) => ({\n programId: m.program_id,\n discriminatorHex: m.discriminator_hex,\n })),\n },\n },\n );\n\n return meta;\n }\n}\n"],
5
+ "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAA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EAAS,cAAgB,CAAC,EAE/C,KAAK,OAAO,MACV,6DACA,CACE,KAAM,CAAE,kBAAmBO,EAAa,MAAO,CACjD,CACF,EAEA,MAAMC,EAAOD,EAAa,IAAKE,IAAQ,CACrC,WAAYA,EAAG,WACf,GAAIA,EAAG,oBAAsB,QAAa,CACxC,kBAAmBA,EAAG,iBACxB,CACF,EAAE,EAEF,YAAK,OAAO,MACV,uEACA,CACE,KAAM,CACJ,KAAMD,EAAK,IAAKE,IAAO,CACrB,UAAWA,EAAE,WACb,iBAAkBA,EAAE,iBACtB,EAAE,CACJ,CACF,CACF,EAEOF,CACT,CACF,EA3LaxB,EAAN2B,EAAA,IADN,cAAW,EAYPC,EAAA,eAAO,YAAU,oBAAoB,GAErCA,EAAA,eAAO,cAAY,MAAM,GAEzBA,EAAA,eAAO,WAAS,oBAAoB,GAEpCA,EAAA,eAAO,cAAY,0BAA0B,IAjBrC5B",
6
+ "names": ["SolanaLifiContextLoader_exports", "__export", "SolanaLifiContextLoader", "__toCommonJS", "import_inversify", "import_configTypes", "import_pkiTypes", "import_KeyId", "import_KeyUsage", "import_SolanaContextTypes", "import_solanaLifiTypes", "SolanaLifiContextLoader", "dataSource", "config", "_certificateLoader", "loggerFactory", "field", "expectedType", "templateId", "isValid", "solanaLifiContextInput", "deviceModelId", "payload", "certificate", "error", "value", "lifiPayload", "response", "tokenData", "signatureKind", "output", "descriptors", "item", "key", "instructions", "meta", "ix", "m", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var c=require("purify-ts"),a=require("vitest"),t=require("../../shared/model/SolanaContextTypes"),d=require("./SolanaLifiContextLoader");const u=()=>({debug:a.vi.fn(),info:a.vi.fn(),warn:a.vi.fn(),error:a.vi.fn(),subscribers:[]});(0,a.describe)("SolanaLifiContextLoader",()=>{let o;const l={swap:{programId:"SomeProgram",accounts:[],data:"abc123"},bridge:{programId:"AnotherProgram",accounts:[],data:"def456"}},i={descriptors:l};(0,a.beforeEach)(()=>{a.vi.restoreAllMocks(),o={getTransactionDescriptorsPayload:a.vi.fn()}});const r=()=>new d.SolanaLifiContextLoader(o,u);(0,a.describe)("canHandle",()=>{(0,a.it)("returns true when templateId is provided",()=>{const e=r();(0,a.expect)(e.canHandle({templateId:"tpl-123",deviceModelId:"nanoS"},t.SolanaContextTypes.SOLANA_LIFI)).toBe(!0)}),(0,a.it)("returns false when templateId is missing or falsy",()=>{const e=r();(0,a.expect)(e.canHandle({templateId:""},t.SolanaContextTypes.SOLANA_LIFI)).toBe(!1),(0,a.expect)(e.canHandle({templateId:void 0},t.SolanaContextTypes.SOLANA_LIFI)).toBe(!1),(0,a.expect)(e.canHandle({},t.SolanaContextTypes.SOLANA_LIFI)).toBe(!1)})}),(0,a.describe)("loadField",()=>{(0,a.it)("returns an error when datasource returns Left(error)",async()=>{const e=r(),n=new Error("boom");a.vi.spyOn(o,"getTransactionDescriptorsPayload").mockResolvedValue((0,c.Left)(n));const s={templateId:"tpl-err",deviceModelId:"nanoS"},p=await e.loadField(s);(0,a.expect)(o.getTransactionDescriptorsPayload).toHaveBeenCalledWith({templateId:"tpl-err"}),(0,a.expect)(p).toEqual({type:t.SolanaContextTypes.ERROR,error:n})}),(0,a.it)("returns SOLANA_LIFI with plucked descriptors when datasource returns Right(value)",async()=>{const e=r();a.vi.spyOn(o,"getTransactionDescriptorsPayload").mockResolvedValue((0,c.Right)(i));const n={templateId:"tpl-ok",deviceModelId:"nanoS"},s=await e.loadField(n);(0,a.expect)(o.getTransactionDescriptorsPayload).toHaveBeenCalledWith({templateId:"tpl-ok"}),(0,a.expect)(s).toEqual({type:t.SolanaContextTypes.SOLANA_LIFI,payload:l})})}),(0,a.describe)("pluckTransactionData (private)",()=>{(0,a.it)("simply returns the descriptors object from the response",()=>{const e=r(),s=e.pluckTransactionData.bind(e)(i);(0,a.expect)(s).toEqual(l)})})});
1
+ "use strict";var p=require("purify-ts"),e=require("vitest"),n=require("../../shared/model/SolanaContextTypes"),b=require("./SolanaLifiContextLoader");const k=()=>({debug:e.vi.fn(),info:e.vi.fn(),warn:e.vi.fn(),error:e.vi.fn(),subscribers:[]}),g={keyUsageNumber:13,payload:new Uint8Array([1,2])},f={cal:{url:"https://crypto-assets-service.api.ledger.com",mode:"test",branch:"main"}};(0,e.describe)("SolanaLifiContextLoader",()=>{let c,m;const i=(r,a="deadbeef")=>({data:r,descriptorType:"swap_template",descriptorVersion:"v1",signatures:{test:a,prod:`prod_${a}`}}),l=(r,a="deadbeef")=>({data:r,descriptorType:"swap_template",descriptorVersion:"v1",signature:a}),_=[{program_id:"SomeProgram",discriminator_hex:"1",descriptor:i("abc123")},{program_id:"AnotherProgram",descriptor:i("def456")}],u={"SomeProgram:1":l("abc123"),"AnotherProgram:":l("def456")},d={id:"tpl-1",chain_id:101,instructions:[{program_id:"SomeProgram",discriminator:1,discriminator_hex:"1"},{program_id:"AnotherProgram"}],descriptors:_};(0,e.beforeEach)(()=>{e.vi.restoreAllMocks(),c={getTransactionDescriptorsPayload:e.vi.fn()},m={loadCertificate:e.vi.fn().mockResolvedValue(g)}});const s=()=>new b.SolanaLifiContextLoader(c,f,m,k);(0,e.describe)("canHandle",()=>{(0,e.it)("returns true when templateId is provided",()=>{const r=s();(0,e.expect)(r.canHandle({templateId:"tpl-123",deviceModelId:"nanoS"},n.SolanaContextTypes.SOLANA_LIFI)).toBe(!0)}),(0,e.it)("returns false when templateId is missing or falsy",()=>{const r=s();(0,e.expect)(r.canHandle({templateId:""},n.SolanaContextTypes.SOLANA_LIFI)).toBe(!1),(0,e.expect)(r.canHandle({templateId:void 0},n.SolanaContextTypes.SOLANA_LIFI)).toBe(!1),(0,e.expect)(r.canHandle({},n.SolanaContextTypes.SOLANA_LIFI)).toBe(!1)})}),(0,e.describe)("loadField",()=>{(0,e.it)("returns an error when datasource returns Left(error)",async()=>{const r=s(),a=new Error("boom");e.vi.spyOn(c,"getTransactionDescriptorsPayload").mockResolvedValue((0,p.Left)(a));const o={templateId:"tpl-err",deviceModelId:"nanoS"},t=await r.loadField(o);(0,e.expect)(c.getTransactionDescriptorsPayload).toHaveBeenCalledWith({templateId:"tpl-err"}),(0,e.expect)(t).toEqual({type:n.SolanaContextTypes.ERROR,error:a})}),(0,e.it)("returns SOLANA_LIFI with plucked descriptors and certificate when datasource returns Right(value)",async()=>{const r=s();e.vi.spyOn(c,"getTransactionDescriptorsPayload").mockResolvedValue((0,p.Right)(d));const a={templateId:"tpl-ok",deviceModelId:"nanoS"},o=await r.loadField(a);(0,e.expect)(c.getTransactionDescriptorsPayload).toHaveBeenCalledWith({templateId:"tpl-ok"}),(0,e.expect)(m.loadCertificate).toHaveBeenCalledWith({keyId:"swap_template_key",keyUsage:"swap_template",targetDevice:"nanoS"}),(0,e.expect)(o).toEqual({type:n.SolanaContextTypes.SOLANA_LIFI,payload:{descriptors:u,instructions:[{program_id:"SomeProgram",discriminator_hex:"1"},{program_id:"AnotherProgram"}]},certificate:g})})}),(0,e.describe)("pluckTransactionData (private)",()=>{(0,e.it)("returns a map keyed by `${program_id}:${discriminator_hex ?? '0'}`",()=>{const r=s(),o=r.pluckTransactionData.bind(r)(d);(0,e.expect)(o).toEqual(u)})}),(0,e.describe)("extractInstructionsMeta (private)",()=>{(0,e.it)("returns instruction metadata from the API response",()=>{const r=s(),o=r.extractInstructionsMeta.bind(r)(d);(0,e.expect)(o).toEqual([{program_id:"SomeProgram",discriminator_hex:"1"},{program_id:"AnotherProgram"}])}),(0,e.it)("returns empty array when instructions are missing",()=>{const r=s(),o=r.extractInstructionsMeta.bind(r)({...d,instructions:void 0});(0,e.expect)(o).toEqual([])})}),(0,e.describe)("pluckTransactionData mode resolution (private)",()=>{(0,e.it)("resolves signature using config.cal.mode",()=>{const r=s(),o=r.pluckTransactionData.bind(r)(d);(0,e.expect)(o["SomeProgram:1"]?.signature).toBe("deadbeef")})}),(0,e.describe)("real CAL payload (LiFi template 4c694669)",()=>{const r={id:"4c694669",chain_id:101,instructions:[{program_id:"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",discriminator:1,discriminator_hex:"1"},{program_id:"11111111111111111111111111111111",discriminator:2,discriminator_hex:"2"},{program_id:"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4",discriminator:0x2aade37a97cb1800,discriminator_hex:"2aade37a97cb17e0"},{program_id:"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4",discriminator:9339575302786589e3,discriminator_hex:"819cd641339b2148"},{program_id:"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"},{program_id:"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",discriminator:1,discriminator_hex:"1"},{program_id:"3i5JeuZuUxeKtVysUnwQNGerJP2bSMX9fTFfS4Nxe3Br"},{program_id:"ComputeBudget111111111111111111111111111111",discriminator:2,discriminator_hex:"2"},{program_id:"ComputeBudget111111111111111111111111111111",discriminator:3,discriminator_hex:"3"},{program_id:"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",discriminator:3,discriminator_hex:"3"},{program_id:"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",discriminator:17,discriminator_hex:"11"},{program_id:"BrdgN2RPzEMWF96ZbnnJaUtQDQx7VRXYaHHbYCBvceWB"}],descriptors:[{program_id:"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",discriminator_hex:"1",descriptor:i("atoken_1","sig_atoken")},{program_id:"11111111111111111111111111111111",discriminator_hex:"2",descriptor:i("system_2","sig_system")},{program_id:"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4",discriminator_hex:"2aade37a97cb17e0",descriptor:i("jup_route","sig_jup_route")},{program_id:"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4",discriminator_hex:"819cd641339b2148",descriptor:i("jup_shared","sig_jup_shared")},{program_id:"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr",descriptor:i("memo","sig_memo")},{program_id:"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",discriminator_hex:"1",descriptor:i("atoken_1","sig_atoken")},{program_id:"3i5JeuZuUxeKtVysUnwQNGerJP2bSMX9fTFfS4Nxe3Br",descriptor:i("3i5jeu","sig_3i5jeu")},{program_id:"ComputeBudget111111111111111111111111111111",discriminator_hex:"2",descriptor:i("cb_2","sig_cb2")},{program_id:"ComputeBudget111111111111111111111111111111",discriminator_hex:"3",descriptor:i("cb_3","sig_cb3")},{program_id:"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",discriminator_hex:"3",descriptor:i("tokenkeg_3","sig_tk3")},{program_id:"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",discriminator_hex:"11",descriptor:i("tokenkeg_11","sig_tk11")},{program_id:"BrdgN2RPzEMWF96ZbnnJaUtQDQx7VRXYaHHbYCBvceWB",descriptor:i("brdg","sig_brdg")}]};(0,e.it)("produces 11 unique descriptor keys (ATokenGP:1 appears twice but deduplicates)",()=>{const a=s(),t=a.pluckTransactionData.bind(a)(r),y=Object.keys(t);(0,e.expect)(y).toHaveLength(11)}),(0,e.it)("creates distinct keys for same program_id with different discriminators",()=>{const a=s(),t=a.pluckTransactionData.bind(a)(r);(0,e.expect)(t["JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4:2aade37a97cb17e0"]?.data).toBe("jup_route"),(0,e.expect)(t["JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4:819cd641339b2148"]?.data).toBe("jup_shared"),(0,e.expect)(t["ComputeBudget111111111111111111111111111111:2"]?.data).toBe("cb_2"),(0,e.expect)(t["ComputeBudget111111111111111111111111111111:3"]?.data).toBe("cb_3"),(0,e.expect)(t["TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA:3"]?.data).toBe("tokenkeg_3"),(0,e.expect)(t["TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA:11"]?.data).toBe("tokenkeg_11")}),(0,e.it)("uses :0 suffix for programs without a discriminator",()=>{const a=s(),t=a.pluckTransactionData.bind(a)(r);(0,e.expect)(t["MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr:"]?.data).toBe("memo"),(0,e.expect)(t["3i5JeuZuUxeKtVysUnwQNGerJP2bSMX9fTFfS4Nxe3Br:"]?.data).toBe("3i5jeu"),(0,e.expect)(t["BrdgN2RPzEMWF96ZbnnJaUtQDQx7VRXYaHHbYCBvceWB:"]?.data).toBe("brdg")}),(0,e.it)("extracts 12 instruction metadata entries preserving order and discriminators",()=>{const a=s(),t=a.extractInstructionsMeta.bind(a)(r);(0,e.expect)(t).toHaveLength(12),(0,e.expect)(t[0]).toEqual({program_id:"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",discriminator_hex:"1"}),(0,e.expect)(t[2]).toEqual({program_id:"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4",discriminator_hex:"2aade37a97cb17e0"}),(0,e.expect)(t[3]).toEqual({program_id:"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4",discriminator_hex:"819cd641339b2148"}),(0,e.expect)(t[4]).toEqual({program_id:"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"}),(0,e.expect)(t[11]).toEqual({program_id:"BrdgN2RPzEMWF96ZbnnJaUtQDQx7VRXYaHHbYCBvceWB"})}),(0,e.it)("loadField returns full payload with descriptors and instructions from real API response",async()=>{const a=s();e.vi.spyOn(c,"getTransactionDescriptorsPayload").mockResolvedValue((0,p.Right)(r));const o={templateId:"4c694669",deviceModelId:"nanoS"},t=await a.loadField(o);(0,e.expect)(t).toMatchObject({type:n.SolanaContextTypes.SOLANA_LIFI,payload:{descriptors:e.expect.objectContaining({"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4:2aade37a97cb17e0":e.expect.objectContaining({data:"jup_route"}),"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4:819cd641339b2148":e.expect.objectContaining({data:"jup_shared"})}),instructions:e.expect.arrayContaining([e.expect.objectContaining({program_id:"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4",discriminator_hex:"2aade37a97cb17e0"}),e.expect.objectContaining({program_id:"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4",discriminator_hex:"819cd641339b2148"})])}}),(0,e.expect)(Object.keys(t.payload.descriptors)).toHaveLength(11),(0,e.expect)(t.payload.instructions).toHaveLength(12)})})});
2
2
  //# sourceMappingURL=SolanaLifiContextLoader.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/solanaLifi/domain/SolanaLifiContextLoader.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 { Left, Right } from \"purify-ts\";\nimport { beforeEach, describe, expect, it, vi } from \"vitest\";\n\nimport {\n SolanaContextTypes,\n type SolanaTransactionDescriptorList,\n} from \"@/shared/model/SolanaContextTypes\";\nimport {\n type GetTransactionDescriptorsResponse,\n type SolanaLifiDataSource,\n} from \"@/solanaLifi/data/SolanaLifiDataSource\";\n\nimport { SolanaLifiContextLoader } from \"./SolanaLifiContextLoader\";\n\nconst mockLoggerFactory = () => ({\n debug: vi.fn(),\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n subscribers: [],\n});\n\ndescribe(\"SolanaLifiContextLoader\", () => {\n let mockDataSource: SolanaLifiDataSource;\n\n const descriptors: SolanaTransactionDescriptorList = {\n // Shape not important for the loader: it's plucked verbatim\n swap: { programId: \"SomeProgram\", accounts: [], data: \"abc123\" } as any,\n bridge: {\n programId: \"AnotherProgram\",\n accounts: [],\n data: \"def456\",\n } as any,\n };\n\n const txDescriptorsResponse: GetTransactionDescriptorsResponse = {\n descriptors,\n } as any;\n\n beforeEach(() => {\n vi.restoreAllMocks();\n mockDataSource = {\n getTransactionDescriptorsPayload: vi.fn(),\n } as unknown as SolanaLifiDataSource;\n });\n\n const makeLoader = () =>\n new SolanaLifiContextLoader(mockDataSource, mockLoggerFactory);\n\n describe(\"canHandle\", () => {\n it(\"returns true when templateId is provided\", () => {\n const loader = makeLoader();\n\n expect(\n loader.canHandle(\n {\n templateId: \"tpl-123\",\n deviceModelId: \"nanoS\" as any,\n },\n SolanaContextTypes.SOLANA_LIFI,\n ),\n ).toBe(true);\n });\n\n it(\"returns false when templateId is missing or falsy\", () => {\n const loader = makeLoader();\n\n expect(\n loader.canHandle(\n { templateId: \"\" } as any,\n SolanaContextTypes.SOLANA_LIFI,\n ),\n ).toBe(false);\n expect(\n loader.canHandle(\n { templateId: undefined } as any,\n SolanaContextTypes.SOLANA_LIFI,\n ),\n ).toBe(false);\n expect(loader.canHandle({} as any, SolanaContextTypes.SOLANA_LIFI)).toBe(\n false,\n );\n });\n });\n\n describe(\"loadField\", () => {\n it(\"returns an error when datasource returns Left(error)\", async () => {\n const loader = makeLoader();\n const error = new Error(\"boom\");\n vi.spyOn(\n mockDataSource,\n \"getTransactionDescriptorsPayload\",\n ).mockResolvedValue(Left(error));\n const input = { templateId: \"tpl-err\", deviceModelId: \"nanoS\" as any };\n const result = await loader.loadField(input);\n\n expect(\n mockDataSource.getTransactionDescriptorsPayload,\n ).toHaveBeenCalledWith({\n templateId: \"tpl-err\",\n });\n expect(result).toEqual({\n type: SolanaContextTypes.ERROR,\n error,\n });\n });\n\n it(\"returns SOLANA_LIFI with plucked descriptors when datasource returns Right(value)\", async () => {\n const loader = makeLoader();\n vi.spyOn(\n mockDataSource,\n \"getTransactionDescriptorsPayload\",\n ).mockResolvedValue(Right(txDescriptorsResponse));\n const input = { templateId: \"tpl-ok\", deviceModelId: \"nanoS\" as any };\n const result = await loader.loadField(input);\n\n expect(\n mockDataSource.getTransactionDescriptorsPayload,\n ).toHaveBeenCalledWith({\n templateId: \"tpl-ok\",\n });\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_LIFI,\n payload: descriptors,\n });\n });\n });\n\n describe(\"pluckTransactionData (private)\", () => {\n it(\"simply returns the descriptors object from the response\", () => {\n const loader = makeLoader();\n const pluck = (loader as any).pluckTransactionData.bind(loader);\n\n const result = pluck(txDescriptorsResponse);\n\n expect(result).toEqual(descriptors);\n });\n });\n});\n"],
5
- "mappings": "aAIA,IAAAA,EAA4B,qBAC5BC,EAAqD,kBAErDC,EAGO,6CAMPC,EAAwC,qCAExC,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,0BAA2B,IAAM,CACxC,IAAIC,EAEJ,MAAMC,EAA+C,CAEnD,KAAM,CAAE,UAAW,cAAe,SAAU,CAAC,EAAG,KAAM,QAAS,EAC/D,OAAQ,CACN,UAAW,iBACX,SAAU,CAAC,EACX,KAAM,QACR,CACF,EAEMC,EAA2D,CAC/D,YAAAD,CACF,KAEA,cAAW,IAAM,CACf,KAAG,gBAAgB,EACnBD,EAAiB,CACf,iCAAkC,KAAG,GAAG,CAC1C,CACF,CAAC,EAED,MAAMG,EAAa,IACjB,IAAI,0BAAwBH,EAAgBD,CAAiB,KAE/D,YAAS,YAAa,IAAM,IAC1B,MAAG,2CAA4C,IAAM,CACnD,MAAMK,EAASD,EAAW,KAE1B,UACEC,EAAO,UACL,CACE,WAAY,UACZ,cAAe,OACjB,EACA,qBAAmB,WACrB,CACF,EAAE,KAAK,EAAI,CACb,CAAC,KAED,MAAG,oDAAqD,IAAM,CAC5D,MAAMA,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AW,CACpC,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["import_purify_ts", "import_vitest", "import_SolanaContextTypes", "import_SolanaLifiContextLoader", "mockLoggerFactory", "mockDataSource", "descriptors", "txDescriptorsResponse", "makeLoader", "loader", "error", "input", "result"]
4
+ "sourcesContent": ["/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { Left, Right } from \"purify-ts\";\nimport { beforeEach, describe, expect, it, vi } from \"vitest\";\n\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport {\n SolanaContextTypes,\n type SolanaTransactionDescriptor,\n type SolanaTransactionDescriptorList,\n type SolanaTransactionDescriptorRaw,\n} from \"@/shared/model/SolanaContextTypes\";\nimport {\n type GetTransactionDescriptorsResponse,\n type SolanaLifiDataSource,\n} from \"@/solanaLifi/data/SolanaLifiDataSource\";\n\nimport { SolanaLifiContextLoader } from \"./SolanaLifiContextLoader\";\n\nconst mockLoggerFactory = () => ({\n debug: vi.fn(),\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n subscribers: [],\n});\n\nconst mockCertificate = {\n keyUsageNumber: 13,\n payload: new Uint8Array([0x01, 0x02]),\n};\n\nconst mockConfig = {\n cal: {\n url: \"https://crypto-assets-service.api.ledger.com\",\n mode: \"test\",\n branch: \"main\",\n },\n} as ContextModuleConfig;\n\ndescribe(\"SolanaLifiContextLoader\", () => {\n let mockDataSource: SolanaLifiDataSource;\n let mockCertificateLoader: PkiCertificateLoader;\n\n const makeRawDescriptor = (\n data: string,\n sig = \"deadbeef\",\n ): SolanaTransactionDescriptorRaw => ({\n data,\n descriptorType: \"swap_template\",\n descriptorVersion: \"v1\",\n signatures: { test: sig, prod: `prod_${sig}` },\n });\n\n const makeResolvedDescriptor = (\n data: string,\n sig = \"deadbeef\",\n ): SolanaTransactionDescriptor => ({\n data,\n descriptorType: \"swap_template\",\n descriptorVersion: \"v1\",\n signature: sig,\n });\n\n const responseDescriptorsArray: GetTransactionDescriptorsResponse[\"descriptors\"] =\n [\n {\n program_id: \"SomeProgram\",\n discriminator_hex: \"1\",\n descriptor: makeRawDescriptor(\"abc123\"),\n },\n {\n program_id: \"AnotherProgram\",\n // discriminator_hex intentionally omitted -> defaults to \"\"\n descriptor: makeRawDescriptor(\"def456\"),\n },\n ];\n\n const expectedPlucked: SolanaTransactionDescriptorList = {\n \"SomeProgram:1\": makeResolvedDescriptor(\"abc123\"),\n \"AnotherProgram:\": makeResolvedDescriptor(\"def456\"),\n };\n\n const responseInstructionsArray: GetTransactionDescriptorsResponse[\"instructions\"] =\n [\n {\n program_id: \"SomeProgram\",\n discriminator: 1,\n discriminator_hex: \"1\",\n },\n {\n program_id: \"AnotherProgram\",\n // discriminator_hex intentionally omitted\n },\n ];\n\n const txDescriptorsResponse: GetTransactionDescriptorsResponse = {\n id: \"tpl-1\",\n chain_id: 101,\n instructions: responseInstructionsArray,\n descriptors: responseDescriptorsArray,\n };\n\n beforeEach(() => {\n vi.restoreAllMocks();\n mockDataSource = {\n getTransactionDescriptorsPayload: vi.fn(),\n } as unknown as SolanaLifiDataSource;\n mockCertificateLoader = {\n loadCertificate: vi.fn().mockResolvedValue(mockCertificate),\n } as unknown as PkiCertificateLoader;\n });\n\n const makeLoader = () =>\n new SolanaLifiContextLoader(\n mockDataSource,\n mockConfig,\n mockCertificateLoader,\n mockLoggerFactory,\n );\n\n describe(\"canHandle\", () => {\n it(\"returns true when templateId is provided\", () => {\n const loader = makeLoader();\n\n expect(\n loader.canHandle(\n {\n templateId: \"tpl-123\",\n deviceModelId: \"nanoS\" as any,\n },\n SolanaContextTypes.SOLANA_LIFI,\n ),\n ).toBe(true);\n });\n\n it(\"returns false when templateId is missing or falsy\", () => {\n const loader = makeLoader();\n\n expect(\n loader.canHandle(\n { templateId: \"\" } as any,\n SolanaContextTypes.SOLANA_LIFI,\n ),\n ).toBe(false);\n expect(\n loader.canHandle(\n { templateId: undefined } as any,\n SolanaContextTypes.SOLANA_LIFI,\n ),\n ).toBe(false);\n expect(loader.canHandle({} as any, SolanaContextTypes.SOLANA_LIFI)).toBe(\n false,\n );\n });\n });\n\n describe(\"loadField\", () => {\n it(\"returns an error when datasource returns Left(error)\", async () => {\n const loader = makeLoader();\n const error = new Error(\"boom\");\n\n vi.spyOn(\n mockDataSource,\n \"getTransactionDescriptorsPayload\",\n ).mockResolvedValue(Left(error));\n\n const input = { templateId: \"tpl-err\", deviceModelId: \"nanoS\" as any };\n const result = await loader.loadField(input);\n\n expect(\n mockDataSource.getTransactionDescriptorsPayload,\n ).toHaveBeenCalledWith({\n templateId: \"tpl-err\",\n });\n\n expect(result).toEqual({\n type: SolanaContextTypes.ERROR,\n error,\n });\n });\n\n it(\"returns SOLANA_LIFI with plucked descriptors and certificate when datasource returns Right(value)\", async () => {\n const loader = makeLoader();\n\n vi.spyOn(\n mockDataSource,\n \"getTransactionDescriptorsPayload\",\n ).mockResolvedValue(Right(txDescriptorsResponse));\n\n const input = { templateId: \"tpl-ok\", deviceModelId: \"nanoS\" as any };\n const result = await loader.loadField(input);\n\n expect(\n mockDataSource.getTransactionDescriptorsPayload,\n ).toHaveBeenCalledWith({\n templateId: \"tpl-ok\",\n });\n\n expect(mockCertificateLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: \"swap_template_key\",\n keyUsage: \"swap_template\",\n targetDevice: \"nanoS\",\n });\n\n expect(result).toEqual({\n type: SolanaContextTypes.SOLANA_LIFI,\n payload: {\n descriptors: expectedPlucked,\n instructions: [\n { program_id: \"SomeProgram\", discriminator_hex: \"1\" },\n { program_id: \"AnotherProgram\" },\n ],\n },\n certificate: mockCertificate,\n });\n });\n });\n\n describe(\"pluckTransactionData (private)\", () => {\n it(\"returns a map keyed by `${program_id}:${discriminator_hex ?? '0'}`\", () => {\n const loader = makeLoader();\n const pluck = (loader as any).pluckTransactionData.bind(loader);\n\n const result: SolanaTransactionDescriptorList = pluck(\n txDescriptorsResponse,\n );\n\n expect(result).toEqual(expectedPlucked);\n });\n });\n\n describe(\"extractInstructionsMeta (private)\", () => {\n it(\"returns instruction metadata from the API response\", () => {\n const loader = makeLoader();\n const extract = (loader as any).extractInstructionsMeta.bind(loader);\n\n const result = extract(txDescriptorsResponse);\n\n expect(result).toEqual([\n { program_id: \"SomeProgram\", discriminator_hex: \"1\" },\n { program_id: \"AnotherProgram\" },\n ]);\n });\n\n it(\"returns empty array when instructions are missing\", () => {\n const loader = makeLoader();\n const extract = (loader as any).extractInstructionsMeta.bind(loader);\n\n const result = extract({\n ...txDescriptorsResponse,\n instructions: undefined,\n });\n\n expect(result).toEqual([]);\n });\n });\n\n describe(\"pluckTransactionData mode resolution (private)\", () => {\n it(\"resolves signature using config.cal.mode\", () => {\n const loader = makeLoader();\n const pluck = (loader as any).pluckTransactionData.bind(loader);\n\n const result: SolanaTransactionDescriptorList = pluck(\n txDescriptorsResponse,\n );\n\n expect(result[\"SomeProgram:1\"]?.signature).toBe(\"deadbeef\");\n });\n });\n\n describe(\"real CAL payload (LiFi template 4c694669)\", () => {\n const realApiResponse: GetTransactionDescriptorsResponse = {\n id: \"4c694669\",\n chain_id: 101,\n instructions: [\n {\n program_id: \"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL\",\n discriminator: 1,\n discriminator_hex: \"1\",\n },\n {\n program_id: \"11111111111111111111111111111111\",\n discriminator: 2,\n discriminator_hex: \"2\",\n },\n {\n program_id: \"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4\",\n discriminator: 3.0753642362361016e18,\n discriminator_hex: \"2aade37a97cb17e0\",\n },\n {\n program_id: \"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4\",\n discriminator: 9.339575302786589e18,\n discriminator_hex: \"819cd641339b2148\",\n },\n { program_id: \"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr\" },\n {\n program_id: \"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL\",\n discriminator: 1,\n discriminator_hex: \"1\",\n },\n { program_id: \"3i5JeuZuUxeKtVysUnwQNGerJP2bSMX9fTFfS4Nxe3Br\" },\n {\n program_id: \"ComputeBudget111111111111111111111111111111\",\n discriminator: 2,\n discriminator_hex: \"2\",\n },\n {\n program_id: \"ComputeBudget111111111111111111111111111111\",\n discriminator: 3,\n discriminator_hex: \"3\",\n },\n {\n program_id: \"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\",\n discriminator: 3,\n discriminator_hex: \"3\",\n },\n {\n program_id: \"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\",\n discriminator: 17,\n discriminator_hex: \"11\",\n },\n { program_id: \"BrdgN2RPzEMWF96ZbnnJaUtQDQx7VRXYaHHbYCBvceWB\" },\n ],\n descriptors: [\n {\n program_id: \"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL\",\n discriminator_hex: \"1\",\n descriptor: makeRawDescriptor(\"atoken_1\", \"sig_atoken\"),\n },\n {\n program_id: \"11111111111111111111111111111111\",\n discriminator_hex: \"2\",\n descriptor: makeRawDescriptor(\"system_2\", \"sig_system\"),\n },\n {\n program_id: \"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4\",\n discriminator_hex: \"2aade37a97cb17e0\",\n descriptor: makeRawDescriptor(\"jup_route\", \"sig_jup_route\"),\n },\n {\n program_id: \"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4\",\n discriminator_hex: \"819cd641339b2148\",\n descriptor: makeRawDescriptor(\"jup_shared\", \"sig_jup_shared\"),\n },\n {\n program_id: \"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr\",\n descriptor: makeRawDescriptor(\"memo\", \"sig_memo\"),\n },\n {\n program_id: \"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL\",\n discriminator_hex: \"1\",\n descriptor: makeRawDescriptor(\"atoken_1\", \"sig_atoken\"),\n },\n {\n program_id: \"3i5JeuZuUxeKtVysUnwQNGerJP2bSMX9fTFfS4Nxe3Br\",\n descriptor: makeRawDescriptor(\"3i5jeu\", \"sig_3i5jeu\"),\n },\n {\n program_id: \"ComputeBudget111111111111111111111111111111\",\n discriminator_hex: \"2\",\n descriptor: makeRawDescriptor(\"cb_2\", \"sig_cb2\"),\n },\n {\n program_id: \"ComputeBudget111111111111111111111111111111\",\n discriminator_hex: \"3\",\n descriptor: makeRawDescriptor(\"cb_3\", \"sig_cb3\"),\n },\n {\n program_id: \"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\",\n discriminator_hex: \"3\",\n descriptor: makeRawDescriptor(\"tokenkeg_3\", \"sig_tk3\"),\n },\n {\n program_id: \"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\",\n discriminator_hex: \"11\",\n descriptor: makeRawDescriptor(\"tokenkeg_11\", \"sig_tk11\"),\n },\n {\n program_id: \"BrdgN2RPzEMWF96ZbnnJaUtQDQx7VRXYaHHbYCBvceWB\",\n descriptor: makeRawDescriptor(\"brdg\", \"sig_brdg\"),\n },\n ],\n };\n\n it(\"produces 11 unique descriptor keys (ATokenGP:1 appears twice but deduplicates)\", () => {\n const loader = makeLoader();\n const pluck = (loader as any).pluckTransactionData.bind(loader);\n\n const result: SolanaTransactionDescriptorList = pluck(realApiResponse);\n const keys = Object.keys(result);\n\n // 12 descriptors but ATokenGP:1 appears twice -> 11 unique keys\n expect(keys).toHaveLength(11);\n });\n\n it(\"creates distinct keys for same program_id with different discriminators\", () => {\n const loader = makeLoader();\n const pluck = (loader as any).pluckTransactionData.bind(loader);\n\n const result: SolanaTransactionDescriptorList = pluck(realApiResponse);\n\n // JUP6 has two different discriminators -> two distinct entries\n expect(\n result[\"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4:2aade37a97cb17e0\"]\n ?.data,\n ).toBe(\"jup_route\");\n expect(\n result[\"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4:819cd641339b2148\"]\n ?.data,\n ).toBe(\"jup_shared\");\n\n // ComputeBudget has discriminator 2 and 3\n expect(\n result[\"ComputeBudget111111111111111111111111111111:2\"]?.data,\n ).toBe(\"cb_2\");\n expect(\n result[\"ComputeBudget111111111111111111111111111111:3\"]?.data,\n ).toBe(\"cb_3\");\n\n // TokenkegQ has discriminator 3 and 11\n expect(\n result[\"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA:3\"]?.data,\n ).toBe(\"tokenkeg_3\");\n expect(\n result[\"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA:11\"]?.data,\n ).toBe(\"tokenkeg_11\");\n });\n\n it(\"uses :0 suffix for programs without a discriminator\", () => {\n const loader = makeLoader();\n const pluck = (loader as any).pluckTransactionData.bind(loader);\n\n const result: SolanaTransactionDescriptorList = pluck(realApiResponse);\n\n expect(result[\"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr:\"]?.data).toBe(\n \"memo\",\n );\n expect(\n result[\"3i5JeuZuUxeKtVysUnwQNGerJP2bSMX9fTFfS4Nxe3Br:\"]?.data,\n ).toBe(\"3i5jeu\");\n expect(\n result[\"BrdgN2RPzEMWF96ZbnnJaUtQDQx7VRXYaHHbYCBvceWB:\"]?.data,\n ).toBe(\"brdg\");\n });\n\n it(\"extracts 12 instruction metadata entries preserving order and discriminators\", () => {\n const loader = makeLoader();\n const extract = (loader as any).extractInstructionsMeta.bind(loader);\n\n const result = extract(realApiResponse);\n\n expect(result).toHaveLength(12);\n\n // First: ATokenGP with discriminator\n expect(result[0]).toEqual({\n program_id: \"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL\",\n discriminator_hex: \"1\",\n });\n // JUP6 route (8-byte discriminator)\n expect(result[2]).toEqual({\n program_id: \"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4\",\n discriminator_hex: \"2aade37a97cb17e0\",\n });\n // JUP6 shared (8-byte discriminator)\n expect(result[3]).toEqual({\n program_id: \"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4\",\n discriminator_hex: \"819cd641339b2148\",\n });\n // Memo: no discriminator\n expect(result[4]).toEqual({\n program_id: \"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr\",\n });\n // BrdgN2: no discriminator (last entry)\n expect(result[11]).toEqual({\n program_id: \"BrdgN2RPzEMWF96ZbnnJaUtQDQx7VRXYaHHbYCBvceWB\",\n });\n });\n\n it(\"loadField returns full payload with descriptors and instructions from real API response\", async () => {\n const loader = makeLoader();\n\n vi.spyOn(\n mockDataSource,\n \"getTransactionDescriptorsPayload\",\n ).mockResolvedValue(Right(realApiResponse));\n\n const input = { templateId: \"4c694669\", deviceModelId: \"nanoS\" as any };\n const result = await loader.loadField(input);\n\n expect(result).toMatchObject({\n type: SolanaContextTypes.SOLANA_LIFI,\n payload: {\n descriptors: expect.objectContaining({\n \"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4:2aade37a97cb17e0\":\n expect.objectContaining({ data: \"jup_route\" }),\n \"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4:819cd641339b2148\":\n expect.objectContaining({ data: \"jup_shared\" }),\n }),\n instructions: expect.arrayContaining([\n expect.objectContaining({\n program_id: \"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4\",\n discriminator_hex: \"2aade37a97cb17e0\",\n }),\n expect.objectContaining({\n program_id: \"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4\",\n discriminator_hex: \"819cd641339b2148\",\n }),\n ]),\n },\n });\n\n expect(Object.keys((result as any).payload.descriptors)).toHaveLength(11);\n expect((result as any).payload.instructions).toHaveLength(12);\n });\n });\n});\n"],
5
+ "mappings": "aAIA,IAAAA,EAA4B,qBAC5BC,EAAqD,kBAIrDC,EAKO,6CAMPC,EAAwC,qCAExC,MAAMC,EAAoB,KAAO,CAC/B,MAAO,KAAG,GAAG,EACb,KAAM,KAAG,GAAG,EACZ,KAAM,KAAG,GAAG,EACZ,MAAO,KAAG,GAAG,EACb,YAAa,CAAC,CAChB,GAEMC,EAAkB,CACtB,eAAgB,GAChB,QAAS,IAAI,WAAW,CAAC,EAAM,CAAI,CAAC,CACtC,EAEMC,EAAa,CACjB,IAAK,CACH,IAAK,+CACL,KAAM,OACN,OAAQ,MACV,CACF,KAEA,YAAS,0BAA2B,IAAM,CACxC,IAAIC,EACAC,EAEJ,MAAMC,EAAoB,CACxBC,EACAC,EAAM,cAC8B,CACpC,KAAAD,EACA,eAAgB,gBAChB,kBAAmB,KACnB,WAAY,CAAE,KAAMC,EAAK,KAAM,QAAQA,CAAG,EAAG,CAC/C,GAEMC,EAAyB,CAC7BF,EACAC,EAAM,cAC2B,CACjC,KAAAD,EACA,eAAgB,gBAChB,kBAAmB,KACnB,UAAWC,CACb,GAEME,EACJ,CACE,CACE,WAAY,cACZ,kBAAmB,IACnB,WAAYJ,EAAkB,QAAQ,CACxC,EACA,CACE,WAAY,iBAEZ,WAAYA,EAAkB,QAAQ,CACxC,CACF,EAEIK,EAAmD,CACvD,gBAAiBF,EAAuB,QAAQ,EAChD,kBAAmBA,EAAuB,QAAQ,CACpD,EAeMG,EAA2D,CAC/D,GAAI,QACJ,SAAU,IACV,aAfA,CACE,CACE,WAAY,cACZ,cAAe,EACf,kBAAmB,GACrB,EACA,CACE,WAAY,gBAEd,CACF,EAMA,YAAaF,CACf,KAEA,cAAW,IAAM,CACf,KAAG,gBAAgB,EACnBN,EAAiB,CACf,iCAAkC,KAAG,GAAG,CAC1C,EACAC,EAAwB,C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["import_purify_ts", "import_vitest", "import_SolanaContextTypes", "import_SolanaLifiContextLoader", "mockLoggerFactory", "mockCertificate", "mockConfig", "mockDataSource", "mockCertificateLoader", "makeRawDescriptor", "data", "sig", "makeResolvedDescriptor", "responseDescriptorsArray", "expectedPlucked", "txDescriptorsResponse", "makeLoader", "loader", "error", "input", "result", "realApiResponse", "keys"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var c=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var C=(n,e)=>{for(var t in e)c(n,t,{get:e[t],enumerable:!0})},I=(n,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of T(e))!S.call(n,o)&&o!==t&&c(n,o,{get:()=>e[o],enumerable:!(a=k(e,o))||a.enumerable});return n};var x=n=>I(c({},"__esModule",{value:!0}),n),g=(n,e,t,a)=>{for(var o=a>1?void 0:a?k(e,t):e,l=n.length-1,r;l>=0;l--)(r=n[l])&&(o=(a?r(e,t,o):r(o))||o);return a&&o&&c(e,t,o),o},d=(n,e)=>(t,a)=>e(t,a,n);var h={};C(h,{SolanaTokenContextLoader:()=>s});module.exports=x(h);var i=require("inversify"),u=require("../../config/di/configTypes"),f=require("../../pki/di/pkiTypes"),m=require("../../pki/model/KeyUsage"),p=require("../../shared/model/SolanaContextTypes"),y=require("../../solanaToken/di/solanaTokenTypes");let s=class{constructor(e,t,a,o){this.dataSource=e;this.config=t;this._certificateLoader=a;this.logger=o("SolanaTokenContextLoader")}logger;canHandle(e,t){if(t!==p.SolanaContextTypes.SOLANA_TOKEN||typeof e!="object"||e===null||!("tokenInternalId"in e))return!1;const a=e.tokenInternalId;return typeof a=="string"&&a.length>0}async loadField(e){this.logger.debug("[loadField] Loading solana token context",{data:{input:e}});const{tokenInternalId:t,deviceModelId:a}=e,o=await this.dataSource.getTokenInfosPayload({tokenInternalId:t}),l=await this._certificateLoader.loadCertificate({keyId:"token_metadata_key",keyUsage:m.KeyUsage.CoinMeta,targetDevice:a});return o.caseOf({Left:r=>(this.logger.error("[loadField] Error loading solana token context",{data:{error:r}}),{type:p.SolanaContextTypes.ERROR,error:r}),Right:r=>(this.logger.debug("[loadField] Successfully loaded solana token context",{data:{payload:this.pluckTokenData(r),certificate:l}}),{type:p.SolanaContextTypes.SOLANA_TOKEN,payload:this.pluckTokenData(r),certificate:l})})}pluckTokenData(e){const t=this.config.cal.mode||"prod";return{solanaTokenDescriptor:{data:e.descriptor.data,signature:e.descriptor.signatures[t]}}}};s=g([(0,i.injectable)(),d(0,(0,i.inject)(y.solanaTokenTypes.SolanaTokenDataSource)),d(1,(0,i.inject)(u.configTypes.Config)),d(2,(0,i.inject)(f.pkiTypes.PkiCertificateLoader)),d(3,(0,i.inject)(u.configTypes.ContextModuleLoggerFactory))],s);0&&(module.exports={SolanaTokenContextLoader});
1
+ "use strict";var p=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var C=(n,e)=>{for(var t in e)p(n,t,{get:e[t],enumerable:!0})},x=(n,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of T(e))!S.call(n,o)&&o!==t&&p(n,o,{get:()=>e[o],enumerable:!(a=u(e,o))||a.enumerable});return n};var h=n=>x(p({},"__esModule",{value:!0}),n),k=(n,e,t,a)=>{for(var o=a>1?void 0:a?u(e,t):e,l=n.length-1,r;l>=0;l--)(r=n[l])&&(o=(a?r(e,t,o):r(o))||o);return a&&o&&p(e,t,o),o},s=(n,e)=>(t,a)=>e(t,a,n);var I={};C(I,{SolanaTokenContextLoader:()=>d});module.exports=h(I);var i=require("inversify"),g=require("../../config/di/configTypes"),f=require("../../pki/di/pkiTypes"),m=require("../../pki/model/KeyUsage"),c=require("../../shared/model/SolanaContextTypes"),y=require("../../solanaToken/di/solanaTokenTypes");let d=class{constructor(e,t,a,o){this.dataSource=e;this.config=t;this._certificateLoader=a;this.logger=o("SolanaTokenContextLoader")}logger;canHandle(e,t){if(t!==c.SolanaContextTypes.SOLANA_TOKEN||typeof e!="object"||e===null||!("tokenInternalId"in e))return!1;const a=e.tokenInternalId;return typeof a=="string"&&a.length>0}async loadField(e){this.logger.debug("[loadField] Loading solana token context",{data:{input:e}});const{tokenInternalId:t,deviceModelId:a}=e;if(!t)return{type:c.SolanaContextTypes.ERROR,error:new Error("[ContextModule] SolanaTokenContextLoader: tokenInternalId is missing")};const o=await this.dataSource.getTokenInfosPayload({tokenInternalId:t}),l=await this._certificateLoader.loadCertificate({keyId:"token_metadata_key",keyUsage:m.KeyUsage.CoinMeta,targetDevice:a});return o.caseOf({Left:r=>(this.logger.error("[loadField] Error loading solana token context",{data:{error:r}}),{type:c.SolanaContextTypes.ERROR,error:r}),Right:r=>(this.logger.debug("[loadField] Successfully loaded solana token context",{data:{payload:this.pluckTokenData(r),certificate:l}}),{type:c.SolanaContextTypes.SOLANA_TOKEN,payload:this.pluckTokenData(r),certificate:l})})}pluckTokenData(e){const t=this.config.cal.mode||"prod";return{solanaTokenDescriptor:{data:e.descriptor.data,signature:e.descriptor.signatures[t]}}}};d=k([(0,i.injectable)(),s(0,(0,i.inject)(y.solanaTokenTypes.SolanaTokenDataSource)),s(1,(0,i.inject)(g.configTypes.Config)),s(2,(0,i.inject)(f.pkiTypes.PkiCertificateLoader)),s(3,(0,i.inject)(g.configTypes.ContextModuleLoggerFactory))],d);0&&(module.exports={SolanaTokenContextLoader});
2
2
  //# sourceMappingURL=SolanaTokenContextLoader.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/solanaToken/domain/SolanaTokenContextLoader.ts"],
4
- "sourcesContent": ["import {\n DeviceModelId,\n LoggerPublisherService,\n} from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { ContextFieldLoader } from \"@/shared/domain/ContextFieldLoader\";\nimport {\n SolanaContextTypes,\n SolanaTokenContextResult,\n SolanaTokenData,\n} from \"@/shared/model/SolanaContextTypes\";\nimport { SolanaTransactionContext } from \"@/solana/domain/solanaContextTypes\";\nimport {\n type SolanaTokenDataSource,\n type TokenDataResponse,\n} from \"@/solanaToken/data/SolanaTokenDataSource\";\nimport { solanaTokenTypes } from \"@/solanaToken/di/solanaTokenTypes\";\n\ntype SolanaTokenFieldInput = SolanaTransactionContext & {\n deviceModelId: DeviceModelId;\n tokenInternalId: string;\n};\n\n@injectable()\nexport class SolanaTokenContextLoader\n implements\n ContextFieldLoader<\n SolanaTokenFieldInput,\n SolanaContextTypes,\n SolanaTokenContextResult\n >\n{\n private logger: LoggerPublisherService;\n\n constructor(\n @inject(solanaTokenTypes.SolanaTokenDataSource)\n private readonly dataSource: SolanaTokenDataSource,\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n @inject(configTypes.ContextModuleLoggerFactory)\n loggerFactory: (tag: string) => LoggerPublisherService,\n ) {\n this.logger = loggerFactory(\"SolanaTokenContextLoader\");\n }\n\n public canHandle(\n field: unknown,\n expectedType: SolanaContextTypes,\n ): field is SolanaTokenFieldInput {\n if (expectedType !== SolanaContextTypes.SOLANA_TOKEN) {\n return false;\n }\n\n if (\n typeof field !== \"object\" ||\n field === null ||\n !(\"tokenInternalId\" in field)\n ) {\n return false;\n }\n\n const tokenInternalId = (field as { tokenInternalId: unknown })\n .tokenInternalId;\n\n return typeof tokenInternalId === \"string\" && tokenInternalId.length > 0;\n }\n\n public async loadField(\n solanaTokenContextInput: SolanaTokenFieldInput,\n ): Promise<SolanaTokenContextResult> {\n this.logger.debug(\"[loadField] Loading solana token context\", {\n data: { input: solanaTokenContextInput },\n });\n const { tokenInternalId, deviceModelId } = solanaTokenContextInput;\n\n const payload = await this.dataSource.getTokenInfosPayload({\n tokenInternalId,\n });\n\n const certificate: PkiCertificate | undefined =\n await this._certificateLoader.loadCertificate({\n keyId: \"token_metadata_key\",\n keyUsage: KeyUsage.CoinMeta,\n targetDevice: deviceModelId,\n });\n\n return payload.caseOf({\n Left: (error): SolanaTokenContextResult => {\n this.logger.error(\"[loadField] Error loading solana token context\", {\n data: { error },\n });\n\n return {\n type: SolanaContextTypes.ERROR,\n error,\n };\n },\n Right: (value): SolanaTokenContextResult => {\n this.logger.debug(\n \"[loadField] Successfully loaded solana token context\",\n {\n data: { payload: this.pluckTokenData(value), certificate },\n },\n );\n\n return {\n type: SolanaContextTypes.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,8BAAAE,IAAA,eAAAC,EAAAH,GAIA,IAAAI,EAAmC,qBAEnCC,EAA4B,mCAE5BC,EAAyB,6BAEzBC,EAAyB,gCAGzBC,EAIO,6CAMPC,EAAiC,6CAQ1B,IAAMC,EAAN,KAOP,CAGE,YAEmBC,EAC4BC,EAE5BC,EAEjBC,EACA,CANiB,gBAAAH,EAC4B,YAAAC,EAE5B,wBAAAC,EAIjB,KAAK,OAASC,EAAc,0BAA0B,CACxD,CAZQ,OAcD,UACLC,EACAC,EACgC,CAKhC,GAJIA,IAAiB,qBAAmB,cAKtC,OAAOD,GAAU,UACjBA,IAAU,MACV,EAAE,oBAAqBA,GAEvB,MAAO,GAGT,MAAME,EAAmBF,EACtB,gBAEH,OAAO,OAAOE,GAAoB,UAAYA,EAAgB,OAAS,CACzE,CAEA,MAAa,UACXC,EACmC,CACnC,KAAK,OAAO,MAAM,2CAA4C,CAC5D,KAAM,CAAE,MAAOA,CAAwB,CACzC,CAAC,EACD,KAAM,CAAE,gBAAAD,EAAiB,cAAAE,CAAc,EAAID,EAErCE,EAAU,MAAM,KAAK,WAAW,qBAAqB,CACzD,gBAAAH,CACF,CAAC,EAEKI,EACJ,MAAM,KAAK,mBAAmB,gBAAgB,CAC5C,MAAO,qBACP,SAAU,WAAS,SACnB,aAAcF,CAChB,CAAC,EAEH,OAAOC,EAAQ,OAAO,CACpB,KAAOE,IACL,KAAK,OAAO,MAAM,iDAAkD,CAClE,KAAM,CAAE,MAAAA,CAAM,CAChB,CAAC,EAEM,CACL,KAAM,qBAAmB,MACzB,MAAAA,CACF,GAEF,MAAQC,IACN,KAAK,OAAO,MACV,uDACA,CACE,KAAM,CAAE,QAAS,KAAK,eAAeA,CAAK,EAAG,YAAAF,CAAY,CAC3D,CACF,EAEO,CACL,KAAM,qBAAmB,aACzB,QAAS,KAAK,eAAeE,CAAK,EAClC,YAAAF,CACF,EAEJ,CAAC,CACH,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,EApGaf,EAANgB,EAAA,IADN,cAAW,EAYPC,EAAA,eAAO,mBAAiB,qBAAqB,GAE7CA,EAAA,eAAO,cAAY,MAAM,GACzBA,EAAA,eAAO,WAAS,oBAAoB,GAEpCA,EAAA,eAAO,cAAY,0BAA0B,IAhBrCjB",
4
+ "sourcesContent": ["import { LoggerPublisherService } from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { ContextFieldLoader } from \"@/shared/domain/ContextFieldLoader\";\nimport {\n SolanaContextTypes,\n SolanaTokenContextResult,\n SolanaTokenData,\n} from \"@/shared/model/SolanaContextTypes\";\nimport { SolanaTransactionContext } from \"@/solana/domain/solanaContextTypes\";\nimport {\n type SolanaTokenDataSource,\n type TokenDataResponse,\n} from \"@/solanaToken/data/SolanaTokenDataSource\";\nimport { solanaTokenTypes } from \"@/solanaToken/di/solanaTokenTypes\";\n\n@injectable()\nexport class SolanaTokenContextLoader\n implements\n ContextFieldLoader<\n SolanaTransactionContext,\n SolanaContextTypes,\n SolanaTokenContextResult\n >\n{\n private logger: LoggerPublisherService;\n\n constructor(\n @inject(solanaTokenTypes.SolanaTokenDataSource)\n private readonly dataSource: SolanaTokenDataSource,\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n @inject(configTypes.ContextModuleLoggerFactory)\n loggerFactory: (tag: string) => LoggerPublisherService,\n ) {\n this.logger = loggerFactory(\"SolanaTokenContextLoader\");\n }\n\n public canHandle(\n field: unknown,\n expectedType: SolanaContextTypes,\n ): field is SolanaTransactionContext {\n if (expectedType !== SolanaContextTypes.SOLANA_TOKEN) {\n return false;\n }\n\n if (\n typeof field !== \"object\" ||\n field === null ||\n !(\"tokenInternalId\" in field)\n ) {\n return false;\n }\n\n const tokenInternalId = (field as { tokenInternalId: unknown })\n .tokenInternalId;\n\n return typeof tokenInternalId === \"string\" && tokenInternalId.length > 0;\n }\n\n public async loadField(\n solanaTokenContextInput: SolanaTransactionContext,\n ): Promise<SolanaTokenContextResult> {\n this.logger.debug(\"[loadField] Loading solana token context\", {\n data: { input: solanaTokenContextInput },\n });\n const { tokenInternalId, deviceModelId } = solanaTokenContextInput;\n\n if (!tokenInternalId) {\n return {\n type: SolanaContextTypes.ERROR,\n error: new Error(\n \"[ContextModule] SolanaTokenContextLoader: 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: \"token_metadata_key\",\n keyUsage: KeyUsage.CoinMeta,\n targetDevice: deviceModelId,\n });\n\n return payload.caseOf({\n Left: (error): SolanaTokenContextResult => {\n this.logger.error(\"[loadField] Error loading solana token context\", {\n data: { error },\n });\n\n return {\n type: SolanaContextTypes.ERROR,\n error,\n };\n },\n Right: (value): SolanaTokenContextResult => {\n this.logger.debug(\n \"[loadField] Successfully loaded solana token context\",\n {\n data: { payload: this.pluckTokenData(value), certificate },\n },\n );\n\n return {\n type: SolanaContextTypes.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,8BAAAE,IAAA,eAAAC,EAAAH,GACA,IAAAI,EAAmC,qBAEnCC,EAA4B,mCAE5BC,EAAyB,6BAEzBC,EAAyB,gCAGzBC,EAIO,6CAMPC,EAAiC,6CAG1B,IAAMC,EAAN,KAOP,CAGE,YAEmBC,EAC4BC,EAE5BC,EAEjBC,EACA,CANiB,gBAAAH,EAC4B,YAAAC,EAE5B,wBAAAC,EAIjB,KAAK,OAASC,EAAc,0BAA0B,CACxD,CAZQ,OAcD,UACLC,EACAC,EACmC,CAKnC,GAJIA,IAAi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WAAS,oBAAoB,GAEpCA,EAAA,eAAO,cAAY,0BAA0B,IAhBrCjB",
6
6
  "names": ["SolanaTokenContextLoader_exports", "__export", "SolanaTokenContextLoader", "__toCommonJS", "import_inversify", "import_configTypes", "import_pkiTypes", "import_KeyUsage", "import_SolanaContextTypes", "import_solanaTokenTypes", "SolanaTokenContextLoader", "dataSource", "config", "_certificateLoader", "loggerFactory", "field", "expectedType", "tokenInternalId", "solanaTokenContextInput", "deviceModelId", "payload", "certificate", "error", "value", "tokenData", "signatureKind", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var v=Object.create;var f=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,N=Object.prototype.hasOwnProperty;var S=(r,e)=>{for(var t in e)f(r,t,{get:e[t],enumerable:!0})},I=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of E(e))!N.call(r,o)&&o!==t&&f(r,o,{get:()=>e[o],enumerable:!(i=C(e,o))||i.enumerable});return r};var _=(r,e,t)=>(t=r!=null?v(V(r)):{},I(e||!r||!r.__esModule?f(t,"default",{value:r,enumerable:!0}):t,r)),j=r=>I(f({},"__esModule",{value:!0}),r),F=(r,e,t,i)=>{for(var o=i>1?void 0:i?C(e,t):e,a=r.length-1,s;a>=0;a--)(s=r[a])&&(o=(i?s(e,t,o):s(o))||o);return i&&o&&f(e,t,o),o},x=(r,e)=>(t,i)=>e(t,i,r);var P={};S(P,{HttpTypedDataDataSource:()=>d});module.exports=j(P);var M=_(require("axios")),D=_(require("crypto-js/sha224")),y=require("inversify"),l=require("purify-ts"),T=require("../../config/di/configTypes"),m=require("../../shared/constant/HttpHeaders"),u=require("../../shared/model/TypedDataClearSignContext"),b=_(require("../../../package.json"));let d=class{constructor(e){this.config=e}async getTypedDataFilters({chainId:e,address:t,schema:i,version:o}){let a;try{const s=await M.default.request({method:"GET",url:`${this.config.cal.url}/dapps`,params:{contracts:t,chain_id:e,output:"descriptors_eip712",descriptors_eip712_version:o,descriptors_eip712:"<set>",ref:`branch:${this.config.cal.branch}`},headers:{[m.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${b.default.version}`,[m.LEDGER_ORIGIN_TOKEN_HEADER]:this.config.originToken}}),c=(0,D.default)(JSON.stringify(this.sortTypes(i)).replace(" ","")).toString();t=t.toLowerCase();const g=(s.data??[]).map(n=>n?.descriptors_eip712?.[t]?.[c]).find(Boolean);if(!g)return(0,l.Left)(new Error(`[ContextModule] HttpTypedDataDataSource: no typed data filters for address ${t} on chain ${e} for schema ${c}`));if(!Array.isArray(g.instructions))return(0,l.Left)(new Error(`[ContextModule] HttpTypedDataDataSource: no message info for address ${t} on chain ${e} for schema ${c}`));const p=[],h={};for(const n of g.instructions)if(this.isInstructionContractInfo(n,this.config.cal.mode))a={displayName:n.display_name,signature:n.signatures[this.config.cal.mode],filtersCount:n.field_mappers_count};else if(o==="v1"&&this.isInstructionFieldV1(n,this.config.cal.mode))p.push({type:"raw",displayName:n.display_name,path:n.field_path,signature:n.signatures[this.config.cal.mode]});else if(this.isInstructionFieldV2(n,this.config.cal.mode))p.push({type:n.format,displayName:n.display_name,path:n.field_path,signature:n.signatures[this.config.cal.mode]});else if(this.isInstructionFieldV2WithCoinRef(n,this.config.cal.mode))p.push({type:n.format,displayName:n.display_name,path:n.field_path,signature:n.signatures[this.config.cal.mode],tokenIndex:n.coin_ref});else if(this.isInstructionFieldV2WithName(n,this.config.cal.mode))p.push({type:n.format,displayName:n.display_name,path:n.field_path,signature:n.signatures[this.config.cal.mode],types:n.name_types,sources:n.name_sources,typesAndSourcesPayload:this.formatTrustedNameTypesAndSources(n)});else if(this.isInstructionCalldataInfo(n,this.config.cal.mode))h[n.calldata_index]={displayName:n.display_name,calldataIndex:n.calldata_index,valueFlag:n.value_filter_flag,calleeFlag:this.convertCalldataPresenceFlag(n.callee_filter_flag),amountFlag:n.amount_filter_flag,spenderFlag:this.convertCalldataPresenceFlag(n.spender_filter_flag),chainIdFlag:n.chain_id_filter_flag,selectorFlag:n.selector_filter_flag,signature:n.signatures[this.config.cal.mode]};else if(this.isInstructionFieldV2Calldata(n,this.config.cal.mode))p.push({type:n.format,displayName:n.display_name,path:n.field_path,signature:n.signatures[this.config.cal.mode],calldataIndex:n.calldata_index});else return(0,l.Left)(new Error(`[ContextModule] HttpTypedDataDataSource: invalid typed data field for address ${t} on chain ${e} for schema ${c}`));return a?(0,l.Right)({messageInfo:a,filters:p,calldatasInfos:h}):(0,l.Left)(new Error(`[ContextModule] HttpTypedDataDataSource: no message info for address ${t} on chain ${e} for schema ${c}`))}catch{return(0,l.Left)(new Error("[ContextModule] HttpTypedDataDataSource: Failed to fetch typed data informations"))}}convertCalldataPresenceFlag(e){switch(e){case"none":return u.TypedDataCalldataParamPresence.None;case"present":return u.TypedDataCalldataParamPresence.Present;case"verifying_contract":return u.TypedDataCalldataParamPresence.VerifyingContract;default:{const t=e;throw new Error(`Unhandled flag: ${t}`)}}}formatTrustedNameTypesAndSources(e){const t=e.name_types.length,i=e.name_sources.length,o=e.descriptor.slice((t+i)*2*-1,i*2*-1),a=e.descriptor.slice(i*2*-1),s=t.toString(16).padStart(2,"0"),c=i.toString(16).padStart(2,"0");return s+o+c+a}isInstructionFieldV1(e,t){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_path=="string"&&typeof e.signatures=="object"&&typeof e.signatures[t]=="string"}isInstructionFieldV2(e,t){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_path=="string"&&typeof e.signatures=="object"&&typeof e.signatures[t]=="string"&&typeof e.format=="string"&&["raw","datetime"].includes(e.format)&&e.coin_ref===void 0}isInstructionFieldV2WithCoinRef(e,t){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_path=="string"&&typeof e.signatures=="object"&&typeof e.signatures[t]=="string"&&typeof e.format=="string"&&["token","amount"].includes(e.format)&&typeof e.coin_ref=="number"}isInstructionFieldV2WithName(e,t){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_path=="string"&&typeof e.signatures=="object"&&typeof e.signatures[t]=="string"&&typeof e.format=="string"&&e.format==="trusted-name"&&e.coin_ref===void 0&&Array.isArray(e.name_types)&&Array.isArray(e.name_sources)&&e.name_types.every(i=>typeof i=="string")&&e.name_sources.every(i=>typeof i=="string")}isInstructionContractInfo(e,t){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_mappers_count=="number"&&typeof e.signatures=="object"&&typeof e.signatures[t]=="string"&&e.field_path===void 0}isInstructionCalldataInfo(e,t){return typeof e=="object"&&typeof e.type=="string"&&e.type==="calldata"&&typeof e.display_name=="string"&&typeof e.calldata_index=="number"&&typeof e.value_filter_flag=="boolean"&&typeof e.chain_id_filter_flag=="boolean"&&typeof e.selector_filter_flag=="boolean"&&typeof e.amount_filter_flag=="boolean"&&["none","present","verifying_contract"].includes(e.callee_filter_flag)&&["none","present","verifying_contract"].includes(e.spender_filter_flag)&&typeof e.signatures=="object"&&typeof e.signatures[t]=="string"}isInstructionFieldV2Calldata(e,t){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_path=="string"&&typeof e.signatures=="object"&&typeof e.signatures[t]=="string"&&typeof e.format=="string"&&["calldata-value","calldata-callee","calldata-chain-id","calldata-selector","calldata-amount","calldata-spender"].includes(e.format)&&typeof e.calldata_index=="number"}sortTypes(e){return Object.fromEntries(Object.entries(e).sort(([t],[i])=>t.localeCompare(i)).map(([t,i])=>[t,i.map(o=>({name:o.name,type:o.type}))]))}};d=F([(0,y.injectable)(),x(0,(0,y.inject)(T.configTypes.Config))],d);0&&(module.exports={HttpTypedDataDataSource});
1
+ "use strict";var b=Object.create;var p=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var E=Object.getPrototypeOf,N=Object.prototype.hasOwnProperty;var P=(i,e)=>{for(var n in e)p(i,n,{get:e[n],enumerable:!0})},C=(i,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of V(e))!N.call(i,r)&&r!==n&&p(i,r,{get:()=>e[r],enumerable:!(o=h(e,r))||o.enumerable});return i};var I=(i,e,n)=>(n=i!=null?b(E(i)):{},C(e||!i||!i.__esModule?p(n,"default",{value:i,enumerable:!0}):n,i)),j=i=>C(p({},"__esModule",{value:!0}),i),F=(i,e,n,o)=>{for(var r=o>1?void 0:o?h(e,n):e,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(o?a(e,n,r):a(r))||r);return o&&r&&p(e,n,r),r},M=(i,e)=>(n,o)=>e(n,o,i);var $={};P($,{HttpTypedDataDataSource:()=>d});module.exports=j($);var x=I(require("axios")),y=require("inversify"),l=require("purify-ts"),D=require("../../config/di/configTypes"),g=require("../../shared/constant/HttpHeaders"),u=require("../../shared/model/TypedDataClearSignContext"),T=require("../../typed-data/utils/getSchemaHash"),v=I(require("../../../package.json"));let d=class{constructor(e){this.config=e}async getTypedDataFilters({chainId:e,address:n,schema:o,version:r}){let s;try{const a=await x.default.request({method:"GET",url:`${this.config.cal.url}/dapps`,params:{contracts:n,chain_id:e,output:"descriptors_eip712",descriptors_eip712_version:r,descriptors_eip712:"<set>",ref:`branch:${this.config.cal.branch}`},headers:{[g.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${v.default.version}`,[g.LEDGER_ORIGIN_TOKEN_HEADER]:this.config.originToken}}),c=(0,T.getSchemaHash)(o);n=n.toLowerCase();const m=(a.data??[]).map(t=>t?.descriptors_eip712?.[n]?.[c]).find(Boolean);if(!m)return(0,l.Left)(new Error(`[ContextModule] HttpTypedDataDataSource: no typed data filters for address ${n} on chain ${e} for schema ${c}`));if(!Array.isArray(m.instructions))return(0,l.Left)(new Error(`[ContextModule] HttpTypedDataDataSource: no message info for address ${n} on chain ${e} for schema ${c}`));const f=[],_={};for(const t of m.instructions)if(this.isInstructionContractInfo(t,this.config.cal.mode))s={displayName:t.display_name,signature:t.signatures[this.config.cal.mode],filtersCount:t.field_mappers_count};else if(r==="v1"&&this.isInstructionFieldV1(t,this.config.cal.mode))f.push({type:"raw",displayName:t.display_name,path:t.field_path,signature:t.signatures[this.config.cal.mode]});else if(this.isInstructionFieldV2(t,this.config.cal.mode))f.push({type:t.format,displayName:t.display_name,path:t.field_path,signature:t.signatures[this.config.cal.mode]});else if(this.isInstructionFieldV2WithCoinRef(t,this.config.cal.mode))f.push({type:t.format,displayName:t.display_name,path:t.field_path,signature:t.signatures[this.config.cal.mode],tokenIndex:t.coin_ref});else if(this.isInstructionFieldV2WithName(t,this.config.cal.mode))f.push({type:t.format,displayName:t.display_name,path:t.field_path,signature:t.signatures[this.config.cal.mode],types:t.name_types,sources:t.name_sources,typesAndSourcesPayload:this.formatTrustedNameTypesAndSources(t)});else if(this.isInstructionCalldataInfo(t,this.config.cal.mode))_[t.calldata_index]={displayName:t.display_name,calldataIndex:t.calldata_index,valueFlag:t.value_filter_flag,calleeFlag:this.convertCalldataPresenceFlag(t.callee_filter_flag),amountFlag:t.amount_filter_flag,spenderFlag:this.convertCalldataPresenceFlag(t.spender_filter_flag),chainIdFlag:t.chain_id_filter_flag,selectorFlag:t.selector_filter_flag,signature:t.signatures[this.config.cal.mode]};else if(this.isInstructionFieldV2Calldata(t,this.config.cal.mode))f.push({type:t.format,displayName:t.display_name,path:t.field_path,signature:t.signatures[this.config.cal.mode],calldataIndex:t.calldata_index});else return(0,l.Left)(new Error(`[ContextModule] HttpTypedDataDataSource: invalid typed data field for address ${n} on chain ${e} for schema ${c}`));return s?(0,l.Right)({messageInfo:s,filters:f,calldatasInfos:_}):(0,l.Left)(new Error(`[ContextModule] HttpTypedDataDataSource: no message info for address ${n} on chain ${e} for schema ${c}`))}catch{return(0,l.Left)(new Error("[ContextModule] HttpTypedDataDataSource: Failed to fetch typed data informations"))}}convertCalldataPresenceFlag(e){switch(e){case"none":return u.TypedDataCalldataParamPresence.None;case"present":return u.TypedDataCalldataParamPresence.Present;case"verifying_contract":return u.TypedDataCalldataParamPresence.VerifyingContract;default:{const n=e;throw new Error(`Unhandled flag: ${n}`)}}}formatTrustedNameTypesAndSources(e){const n=e.name_types.length,o=e.name_sources.length,r=e.descriptor.slice((n+o)*2*-1,o*2*-1),s=e.descriptor.slice(o*2*-1),a=n.toString(16).padStart(2,"0"),c=o.toString(16).padStart(2,"0");return a+r+c+s}isInstructionFieldV1(e,n){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_path=="string"&&typeof e.signatures=="object"&&typeof e.signatures[n]=="string"}isInstructionFieldV2(e,n){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_path=="string"&&typeof e.signatures=="object"&&typeof e.signatures[n]=="string"&&typeof e.format=="string"&&["raw","datetime"].includes(e.format)&&e.coin_ref===void 0}isInstructionFieldV2WithCoinRef(e,n){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_path=="string"&&typeof e.signatures=="object"&&typeof e.signatures[n]=="string"&&typeof e.format=="string"&&["token","amount"].includes(e.format)&&typeof e.coin_ref=="number"}isInstructionFieldV2WithName(e,n){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_path=="string"&&typeof e.signatures=="object"&&typeof e.signatures[n]=="string"&&typeof e.format=="string"&&e.format==="trusted-name"&&e.coin_ref===void 0&&Array.isArray(e.name_types)&&Array.isArray(e.name_sources)&&e.name_types.every(o=>typeof o=="string")&&e.name_sources.every(o=>typeof o=="string")}isInstructionContractInfo(e,n){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_mappers_count=="number"&&typeof e.signatures=="object"&&typeof e.signatures[n]=="string"&&e.field_path===void 0}isInstructionCalldataInfo(e,n){return typeof e=="object"&&typeof e.type=="string"&&e.type==="calldata"&&typeof e.display_name=="string"&&typeof e.calldata_index=="number"&&typeof e.value_filter_flag=="boolean"&&typeof e.chain_id_filter_flag=="boolean"&&typeof e.selector_filter_flag=="boolean"&&typeof e.amount_filter_flag=="boolean"&&["none","present","verifying_contract"].includes(e.callee_filter_flag)&&["none","present","verifying_contract"].includes(e.spender_filter_flag)&&typeof e.signatures=="object"&&typeof e.signatures[n]=="string"}isInstructionFieldV2Calldata(e,n){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_path=="string"&&typeof e.signatures=="object"&&typeof e.signatures[n]=="string"&&typeof e.format=="string"&&["calldata-value","calldata-callee","calldata-chain-id","calldata-selector","calldata-amount","calldata-spender"].includes(e.format)&&typeof e.calldata_index=="number"}};d=F([(0,y.injectable)(),M(0,(0,y.inject)(D.configTypes.Config))],d);0&&(module.exports={HttpTypedDataDataSource});
2
2
  //# sourceMappingURL=HttpTypedDataDataSource.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/typed-data/data/HttpTypedDataDataSource.ts"],
4
- "sourcesContent": ["import axios from \"axios\";\nimport SHA224 from \"crypto-js/sha224\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport type {\n ContextModuleCalMode,\n ContextModuleConfig,\n} from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport type {\n TypedDataCalldataIndex,\n TypedDataFilter,\n TypedDataFilterCalldataInfo,\n TypedDataMessageInfo,\n} from \"@/shared/model/TypedDataClearSignContext\";\nimport { TypedDataCalldataParamPresence } from \"@/shared/model/TypedDataClearSignContext\";\nimport type { TypedDataSchema } from \"@/shared/model/TypedDataContext\";\nimport PACKAGE from \"@root/package.json\";\n\nimport type {\n FiltersDto,\n InstructionCalldataInfo,\n InstructionCalldataParamPresence,\n InstructionContractInfo,\n InstructionField,\n InstructionFieldV1,\n InstructionFieldV2,\n InstructionFieldV2Calldata,\n InstructionFieldV2WithCoinRef,\n InstructionFieldV2WithName,\n} from \"./FiltersDto\";\nimport {\n GetTypedDataFiltersParams,\n GetTypedDataFiltersResult,\n TypedDataDataSource,\n} from \"./TypedDataDataSource\";\n\n@injectable()\nexport class HttpTypedDataDataSource implements TypedDataDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n ) {}\n\n public async getTypedDataFilters({\n chainId,\n address,\n schema,\n version,\n }: GetTypedDataFiltersParams): Promise<\n Either<Error, GetTypedDataFiltersResult>\n > {\n let messageInfo: TypedDataMessageInfo | undefined = undefined;\n\n try {\n const response = await axios.request<FiltersDto[]>({\n method: \"GET\",\n url: `${this.config.cal.url}/dapps`,\n params: {\n contracts: address,\n chain_id: chainId,\n output: \"descriptors_eip712\",\n descriptors_eip712_version: version,\n descriptors_eip712: \"<set>\",\n ref: `branch:${this.config.cal.branch}`,\n },\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n\n // Try to get the filters JSON descriptor, from address and schema hash\n const schemaHash = SHA224(\n JSON.stringify(this.sortTypes(schema)).replace(\" \", \"\"),\n ).toString();\n address = address.toLowerCase();\n const dataArray = response.data ?? [];\n const filtersJson = dataArray\n .map((item) => item?.descriptors_eip712?.[address]?.[schemaHash])\n .find(Boolean);\n\n if (!filtersJson) {\n return Left(\n new Error(\n `[ContextModule] HttpTypedDataDataSource: no typed data filters for address ${address} on chain ${chainId} for schema ${schemaHash}`,\n ),\n );\n }\n\n // Parse the message type, if available\n if (!Array.isArray(filtersJson.instructions)) {\n return Left(\n new Error(\n `[ContextModule] HttpTypedDataDataSource: no message info for address ${address} on chain ${chainId} for schema ${schemaHash}`,\n ),\n );\n }\n\n // Parse all the filters\n const filters: TypedDataFilter[] = [];\n const calldatasInfos: Record<\n TypedDataCalldataIndex,\n TypedDataFilterCalldataInfo\n > = {};\n for (const field of filtersJson.instructions) {\n if (this.isInstructionContractInfo(field, this.config.cal.mode)) {\n messageInfo = {\n displayName: field.display_name,\n signature: field.signatures[this.config.cal.mode],\n filtersCount: field.field_mappers_count,\n };\n } else if (\n version === \"v1\" &&\n this.isInstructionFieldV1(field, this.config.cal.mode)\n ) {\n filters.push({\n type: \"raw\",\n displayName: field.display_name,\n path: field.field_path,\n signature: field.signatures[this.config.cal.mode],\n });\n } else if (this.isInstructionFieldV2(field, this.config.cal.mode)) {\n filters.push({\n type: field.format,\n displayName: field.display_name,\n path: field.field_path,\n signature: field.signatures[this.config.cal.mode],\n });\n } else if (\n this.isInstructionFieldV2WithCoinRef(field, this.config.cal.mode)\n ) {\n filters.push({\n type: field.format,\n displayName: field.display_name,\n path: field.field_path,\n signature: field.signatures[this.config.cal.mode],\n tokenIndex: field.coin_ref,\n });\n } else if (\n this.isInstructionFieldV2WithName(field, this.config.cal.mode)\n ) {\n filters.push({\n type: field.format,\n displayName: field.display_name,\n path: field.field_path,\n signature: field.signatures[this.config.cal.mode],\n types: field.name_types,\n sources: field.name_sources,\n typesAndSourcesPayload:\n this.formatTrustedNameTypesAndSources(field),\n });\n } else if (\n this.isInstructionCalldataInfo(field, this.config.cal.mode)\n ) {\n calldatasInfos[field.calldata_index] = {\n displayName: field.display_name,\n calldataIndex: field.calldata_index,\n valueFlag: field.value_filter_flag,\n calleeFlag: this.convertCalldataPresenceFlag(\n field.callee_filter_flag,\n ),\n amountFlag: field.amount_filter_flag,\n spenderFlag: this.convertCalldataPresenceFlag(\n field.spender_filter_flag,\n ),\n chainIdFlag: field.chain_id_filter_flag,\n selectorFlag: field.selector_filter_flag,\n signature: field.signatures[this.config.cal.mode],\n };\n } else if (\n this.isInstructionFieldV2Calldata(field, this.config.cal.mode)\n ) {\n filters.push({\n type: field.format,\n displayName: field.display_name,\n path: field.field_path,\n signature: field.signatures[this.config.cal.mode],\n calldataIndex: field.calldata_index,\n });\n } else {\n return Left(\n new Error(\n `[ContextModule] HttpTypedDataDataSource: invalid typed data field for address ${address} on chain ${chainId} for schema ${schemaHash}`,\n ),\n );\n }\n }\n\n if (!messageInfo) {\n return Left(\n new Error(\n `[ContextModule] HttpTypedDataDataSource: no message info for address ${address} on chain ${chainId} for schema ${schemaHash}`,\n ),\n );\n }\n\n return Right({ messageInfo, filters, calldatasInfos });\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] HttpTypedDataDataSource: Failed to fetch typed data informations\",\n ),\n );\n }\n }\n\n private convertCalldataPresenceFlag(\n flag: InstructionCalldataParamPresence,\n ): TypedDataCalldataParamPresence {\n switch (flag) {\n case \"none\":\n return TypedDataCalldataParamPresence.None;\n case \"present\":\n return TypedDataCalldataParamPresence.Present;\n case \"verifying_contract\":\n return TypedDataCalldataParamPresence.VerifyingContract;\n default: {\n const uncoveredFlag: never = flag;\n throw new Error(`Unhandled flag: ${uncoveredFlag}`);\n }\n }\n }\n\n private formatTrustedNameTypesAndSources(\n field: InstructionFieldV2WithName,\n ): string {\n // Get number of types and sources\n const typesCount = field.name_types.length;\n const sourcesCount = field.name_sources.length;\n\n // Extract types and sources from the descriptor\n const types = field.descriptor.slice(\n (typesCount + sourcesCount) * 2 * -1,\n sourcesCount * 2 * -1,\n );\n const sources = field.descriptor.slice(sourcesCount * 2 * -1);\n\n // Convert counts into hex strings\n const typesCountHex = typesCount.toString(16).padStart(2, \"0\");\n const sourcesCountHex = sourcesCount.toString(16).padStart(2, \"0\");\n\n // Return the payload\n return typesCountHex + types + sourcesCountHex + sources;\n }\n\n private isInstructionFieldV1(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionFieldV1 & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n // NOTE: Currently the backend return the same structure for V1 and V2,\n // so we can't distinguish them here, but we can still check the required fields\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_path === \"string\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\"\n );\n }\n\n private isInstructionFieldV2(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionFieldV2 & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_path === \"string\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\" &&\n typeof data.format === \"string\" &&\n [\"raw\", \"datetime\"].includes(data.format) &&\n data.coin_ref === undefined\n );\n }\n\n private isInstructionFieldV2WithCoinRef(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionFieldV2WithCoinRef & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_path === \"string\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\" &&\n typeof data.format === \"string\" &&\n [\"token\", \"amount\"].includes(data.format) &&\n typeof data.coin_ref === \"number\"\n );\n }\n\n private isInstructionFieldV2WithName(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionFieldV2WithName & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_path === \"string\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\" &&\n typeof data.format === \"string\" &&\n data.format === \"trusted-name\" &&\n data.coin_ref === undefined &&\n Array.isArray(data.name_types) &&\n Array.isArray(data.name_sources) &&\n data.name_types.every((t) => typeof t === \"string\") &&\n data.name_sources.every((s) => typeof s === \"string\")\n );\n }\n\n private isInstructionContractInfo(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionContractInfo & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_mappers_count === \"number\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\" &&\n data.field_path === undefined\n );\n }\n\n private isInstructionCalldataInfo(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionCalldataInfo & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.type === \"string\" &&\n data.type === \"calldata\" &&\n typeof data.display_name === \"string\" &&\n typeof data.calldata_index === \"number\" &&\n typeof data.value_filter_flag === \"boolean\" &&\n typeof data.chain_id_filter_flag === \"boolean\" &&\n typeof data.selector_filter_flag === \"boolean\" &&\n typeof data.amount_filter_flag === \"boolean\" &&\n [\"none\", \"present\", \"verifying_contract\"].includes(\n data.callee_filter_flag,\n ) &&\n [\"none\", \"present\", \"verifying_contract\"].includes(\n data.spender_filter_flag,\n ) &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\"\n );\n }\n\n private isInstructionFieldV2Calldata(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionFieldV2Calldata & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_path === \"string\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\" &&\n typeof data.format === \"string\" &&\n [\n \"calldata-value\",\n \"calldata-callee\",\n \"calldata-chain-id\",\n \"calldata-selector\",\n \"calldata-amount\",\n \"calldata-spender\",\n ].includes(data.format) &&\n typeof data.calldata_index === \"number\"\n );\n }\n\n private sortTypes(types: TypedDataSchema): TypedDataSchema {\n return Object.fromEntries(\n Object.entries(types)\n .sort(([aKey], [bKey]) => aKey.localeCompare(bKey))\n .map(([key, value]) => [\n key,\n value.map((v) => ({ name: v.name, type: v.type })),\n ]),\n );\n }\n}\n"],
5
- "mappings": "qtBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,6BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkB,oBAClBC,EAAmB,+BACnBC,EAAmC,qBACnCC,EAAoC,qBAEpCC,EAA4B,mCAK5BC,EAGO,yCAOPC,EAA+C,oDAE/CC,EAAoB,iCAqBb,IAAMC,EAAN,KAA6D,CAClE,YAC+CC,EAC7C,CAD6C,YAAAA,CAC5C,CAEH,MAAa,oBAAoB,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,UAC/B,OAAOA,EAAK,mBAAsB,WAClC,OAAOA,EAAK,sBAAyB,WACrC,OAAOA,EAAK,sBAAyB,WACrC,OAAOA,EAAK,oBAAuB,WACnC,CAAC,OAAQ,UAAW,oBAAoB,EAAE,SACxCA,EAAK,kBACP,GACA,CAAC,OAAQ,UAAW,oBAAoB,EAAE,SACxCA,EAAK,mBACP,GACA,OAAOA,EAAK,YAAe,UAC3B,OAAOA,EAAK,WAAWC,CAAI,GAAM,QAErC,CAEQ,6BACND,EACAC,EAGA,CACA,OACE,OAAOD,GAAS,UAChB,OAAOA,EAAK,cAAiB,UAC7B,OAAOA,EAAK,YAAe,UAC3B,OAAOA,EAAK,YAAe,UAC3B,OAAOA,EAAK,WAAWC,CAAI,GAAM,UACjC,OAAOD,EAAK,QAAW,UACvB,CACE,iBACA,kBACA,oBACA,oBACA,kBACA,kBACF,EAAE,SAASA,EAAK,MAAM,GACtB,OAAOA,EAAK,gBAAmB,QAEnC,CAEQ,UAAUJ,EAAyC,CACzD,OAAO,OAAO,YACZ,OAAO,QAAQA,CAAK,EACjB,KAAK,CAAC,CAACQ,CAAI,EAAG,CAACC,CAAI,IAAMD,EAAK,cAAcC,CAAI,CAAC,EACjD,IAAI,CAAC,CAACC,EAAKC,CAAK,IAAM,CACrBD,EACAC,EAAM,IAAKC,IAAO,CAAE,KAAMA,EAAE,KAAM,KAAMA,EAAE,IAAK,EAAE,CACnD,CAAC,CACL,CACF,CACF,EAxWajC,EAANkC,EAAA,IADN,cAAW,EAGPC,EAAA,eAAO,cAAY,MAAM,IAFjBnC",
6
- "names": ["HttpTypedDataDataSource_exports", "__export", "HttpTypedDataDataSource", "__toCommonJS", "import_axios", "import_sha224", "import_inversify", "import_purify_ts", "import_configTypes", "import_HttpHeaders", "import_TypedDataClearSignContext", "import_package", "HttpTypedDataDataSource", "config", "chainId", "address", "schema", "version", "messageInfo", "response", "axios", "PACKAGE", "schemaHash", "SHA224", "filtersJson", "item", "filters", "calldatasInfos", "field", "flag", "uncoveredFlag", "typesCount", "sourcesCount", "types", "sources", "typesCountHex", "sourcesCountHex", "data", "mode", "t", "s", "aKey", "bKey", "key", "value", "v", "__decorateClass", "__decorateParam"]
4
+ "sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport type {\n ContextModuleCalMode,\n ContextModuleConfig,\n} from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport type {\n TypedDataCalldataIndex,\n TypedDataFilter,\n TypedDataFilterCalldataInfo,\n TypedDataMessageInfo,\n} from \"@/shared/model/TypedDataClearSignContext\";\nimport { TypedDataCalldataParamPresence } from \"@/shared/model/TypedDataClearSignContext\";\nimport { getSchemaHash } from \"@/typed-data/utils/getSchemaHash\";\nimport PACKAGE from \"@root/package.json\";\n\nimport type {\n FiltersDto,\n InstructionCalldataInfo,\n InstructionCalldataParamPresence,\n InstructionContractInfo,\n InstructionField,\n InstructionFieldV1,\n InstructionFieldV2,\n InstructionFieldV2Calldata,\n InstructionFieldV2WithCoinRef,\n InstructionFieldV2WithName,\n} from \"./FiltersDto\";\nimport {\n GetTypedDataFiltersParams,\n GetTypedDataFiltersResult,\n TypedDataDataSource,\n} from \"./TypedDataDataSource\";\n\n@injectable()\nexport class HttpTypedDataDataSource implements TypedDataDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n ) {}\n\n public async getTypedDataFilters({\n chainId,\n address,\n schema,\n version,\n }: GetTypedDataFiltersParams): Promise<\n Either<Error, GetTypedDataFiltersResult>\n > {\n let messageInfo: TypedDataMessageInfo | undefined = undefined;\n\n try {\n const response = await axios.request<FiltersDto[]>({\n method: \"GET\",\n url: `${this.config.cal.url}/dapps`,\n params: {\n contracts: address,\n chain_id: chainId,\n output: \"descriptors_eip712\",\n descriptors_eip712_version: version,\n descriptors_eip712: \"<set>\",\n ref: `branch:${this.config.cal.branch}`,\n },\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n\n // Try to get the filters JSON descriptor, from address and schema hash\n const schemaHash = getSchemaHash(schema);\n address = address.toLowerCase();\n const dataArray = response.data ?? [];\n const filtersJson = dataArray\n .map((item) => item?.descriptors_eip712?.[address]?.[schemaHash])\n .find(Boolean);\n\n if (!filtersJson) {\n return Left(\n new Error(\n `[ContextModule] HttpTypedDataDataSource: no typed data filters for address ${address} on chain ${chainId} for schema ${schemaHash}`,\n ),\n );\n }\n\n // Parse the message type, if available\n if (!Array.isArray(filtersJson.instructions)) {\n return Left(\n new Error(\n `[ContextModule] HttpTypedDataDataSource: no message info for address ${address} on chain ${chainId} for schema ${schemaHash}`,\n ),\n );\n }\n\n // Parse all the filters\n const filters: TypedDataFilter[] = [];\n const calldatasInfos: Record<\n TypedDataCalldataIndex,\n TypedDataFilterCalldataInfo\n > = {};\n for (const field of filtersJson.instructions) {\n if (this.isInstructionContractInfo(field, this.config.cal.mode)) {\n messageInfo = {\n displayName: field.display_name,\n signature: field.signatures[this.config.cal.mode],\n filtersCount: field.field_mappers_count,\n };\n } else if (\n version === \"v1\" &&\n this.isInstructionFieldV1(field, this.config.cal.mode)\n ) {\n filters.push({\n type: \"raw\",\n displayName: field.display_name,\n path: field.field_path,\n signature: field.signatures[this.config.cal.mode],\n });\n } else if (this.isInstructionFieldV2(field, this.config.cal.mode)) {\n filters.push({\n type: field.format,\n displayName: field.display_name,\n path: field.field_path,\n signature: field.signatures[this.config.cal.mode],\n });\n } else if (\n this.isInstructionFieldV2WithCoinRef(field, this.config.cal.mode)\n ) {\n filters.push({\n type: field.format,\n displayName: field.display_name,\n path: field.field_path,\n signature: field.signatures[this.config.cal.mode],\n tokenIndex: field.coin_ref,\n });\n } else if (\n this.isInstructionFieldV2WithName(field, this.config.cal.mode)\n ) {\n filters.push({\n type: field.format,\n displayName: field.display_name,\n path: field.field_path,\n signature: field.signatures[this.config.cal.mode],\n types: field.name_types,\n sources: field.name_sources,\n typesAndSourcesPayload:\n this.formatTrustedNameTypesAndSources(field),\n });\n } else if (\n this.isInstructionCalldataInfo(field, this.config.cal.mode)\n ) {\n calldatasInfos[field.calldata_index] = {\n displayName: field.display_name,\n calldataIndex: field.calldata_index,\n valueFlag: field.value_filter_flag,\n calleeFlag: this.convertCalldataPresenceFlag(\n field.callee_filter_flag,\n ),\n amountFlag: field.amount_filter_flag,\n spenderFlag: this.convertCalldataPresenceFlag(\n field.spender_filter_flag,\n ),\n chainIdFlag: field.chain_id_filter_flag,\n selectorFlag: field.selector_filter_flag,\n signature: field.signatures[this.config.cal.mode],\n };\n } else if (\n this.isInstructionFieldV2Calldata(field, this.config.cal.mode)\n ) {\n filters.push({\n type: field.format,\n displayName: field.display_name,\n path: field.field_path,\n signature: field.signatures[this.config.cal.mode],\n calldataIndex: field.calldata_index,\n });\n } else {\n return Left(\n new Error(\n `[ContextModule] HttpTypedDataDataSource: invalid typed data field for address ${address} on chain ${chainId} for schema ${schemaHash}`,\n ),\n );\n }\n }\n\n if (!messageInfo) {\n return Left(\n new Error(\n `[ContextModule] HttpTypedDataDataSource: no message info for address ${address} on chain ${chainId} for schema ${schemaHash}`,\n ),\n );\n }\n\n return Right({ messageInfo, filters, calldatasInfos });\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] HttpTypedDataDataSource: Failed to fetch typed data informations\",\n ),\n );\n }\n }\n\n private convertCalldataPresenceFlag(\n flag: InstructionCalldataParamPresence,\n ): TypedDataCalldataParamPresence {\n switch (flag) {\n case \"none\":\n return TypedDataCalldataParamPresence.None;\n case \"present\":\n return TypedDataCalldataParamPresence.Present;\n case \"verifying_contract\":\n return TypedDataCalldataParamPresence.VerifyingContract;\n default: {\n const uncoveredFlag: never = flag;\n throw new Error(`Unhandled flag: ${uncoveredFlag}`);\n }\n }\n }\n\n private formatTrustedNameTypesAndSources(\n field: InstructionFieldV2WithName,\n ): string {\n // Get number of types and sources\n const typesCount = field.name_types.length;\n const sourcesCount = field.name_sources.length;\n\n // Extract types and sources from the descriptor\n const types = field.descriptor.slice(\n (typesCount + sourcesCount) * 2 * -1,\n sourcesCount * 2 * -1,\n );\n const sources = field.descriptor.slice(sourcesCount * 2 * -1);\n\n // Convert counts into hex strings\n const typesCountHex = typesCount.toString(16).padStart(2, \"0\");\n const sourcesCountHex = sourcesCount.toString(16).padStart(2, \"0\");\n\n // Return the payload\n return typesCountHex + types + sourcesCountHex + sources;\n }\n\n private isInstructionFieldV1(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionFieldV1 & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n // NOTE: Currently the backend return the same structure for V1 and V2,\n // so we can't distinguish them here, but we can still check the required fields\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_path === \"string\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\"\n );\n }\n\n private isInstructionFieldV2(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionFieldV2 & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_path === \"string\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\" &&\n typeof data.format === \"string\" &&\n [\"raw\", \"datetime\"].includes(data.format) &&\n data.coin_ref === undefined\n );\n }\n\n private isInstructionFieldV2WithCoinRef(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionFieldV2WithCoinRef & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_path === \"string\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\" &&\n typeof data.format === \"string\" &&\n [\"token\", \"amount\"].includes(data.format) &&\n typeof data.coin_ref === \"number\"\n );\n }\n\n private isInstructionFieldV2WithName(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionFieldV2WithName & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_path === \"string\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\" &&\n typeof data.format === \"string\" &&\n data.format === \"trusted-name\" &&\n data.coin_ref === undefined &&\n Array.isArray(data.name_types) &&\n Array.isArray(data.name_sources) &&\n data.name_types.every((t) => typeof t === \"string\") &&\n data.name_sources.every((s) => typeof s === \"string\")\n );\n }\n\n private isInstructionContractInfo(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionContractInfo & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_mappers_count === \"number\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\" &&\n data.field_path === undefined\n );\n }\n\n private isInstructionCalldataInfo(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionCalldataInfo & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.type === \"string\" &&\n data.type === \"calldata\" &&\n typeof data.display_name === \"string\" &&\n typeof data.calldata_index === \"number\" &&\n typeof data.value_filter_flag === \"boolean\" &&\n typeof data.chain_id_filter_flag === \"boolean\" &&\n typeof data.selector_filter_flag === \"boolean\" &&\n typeof data.amount_filter_flag === \"boolean\" &&\n [\"none\", \"present\", \"verifying_contract\"].includes(\n data.callee_filter_flag,\n ) &&\n [\"none\", \"present\", \"verifying_contract\"].includes(\n data.spender_filter_flag,\n ) &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\"\n );\n }\n\n private isInstructionFieldV2Calldata(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionFieldV2Calldata & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_path === \"string\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\" &&\n typeof data.format === \"string\" &&\n [\n \"calldata-value\",\n \"calldata-callee\",\n \"calldata-chain-id\",\n \"calldata-selector\",\n \"calldata-amount\",\n \"calldata-spender\",\n ].includes(data.format) &&\n typeof data.calldata_index === \"number\"\n );\n }\n}\n"],
5
+ "mappings": "qtBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,6BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkB,oBAClBC,EAAmC,qBACnCC,EAAoC,qBAEpCC,EAA4B,mCAK5BC,EAGO,yCAOPC,EAA+C,oDAC/CC,EAA8B,4CAC9BC,EAAoB,iCAqBb,IAAMC,EAAN,KAA6D,CAClE,YAC+CC,EAC7C,CAD6C,YAAAA,CAC5C,CAEH,MAAa,oBAAoB,CAC/B,QAAAC,EACA,QAAAC,EACA,OAAAC,EACA,QAAAC,CACF,EAEE,CACA,IAAIC,EAEJ,GAAI,CACF,MAAMC,EAAW,MAAM,EAAAC,QAAM,QAAsB,CACjD,OAAQ,MACR,IAAK,GAAG,KAAK,OAAO,IAAI,GAAG,SAC3B,OAAQ,CACN,UAAWL,EACX,SAAUD,EACV,OAAQ,qBACR,2BAA4BG,EAC5B,mBAAoB,QACpB,IAAK,UAAU,KAAK,OAAO,IAAI,MAAM,EACvC,EACA,QAAS,CACP,CAAC,8BAA4B,EAAG,kBAAkB,EAAAI,QAAQ,OAAO,GACjE,CAAC,4BAA0B,EAAG,KAAK,OAAO,WAC5C,CACF,CAAC,EAGKC,KAAa,iBAAcN,CAAM,EACvCD,EAAUA,EAAQ,YAAY,EAE9B,MAAMQ,GADYJ,EAAS,MAAQ,CAAC,GAEjC,IAAKK,GAASA,G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AAW,EAGPC,EAAA,eAAO,cAAY,MAAM,IAFjB7B",
6
+ "names": ["HttpTypedDataDataSource_exports", "__export", "HttpTypedDataDataSource", "__toCommonJS", "import_axios", "import_inversify", "import_purify_ts", "import_configTypes", "import_HttpHeaders", "import_TypedDataClearSignContext", "import_getSchemaHash", "import_package", "HttpTypedDataDataSource", "config", "chainId", "address", "schema", "version", "messageInfo", "response", "axios", "PACKAGE", "schemaHash", "filtersJson", "item", "filters", "calldatasInfos", "field", "flag", "uncoveredFlag", "typesCount", "sourcesCount", "types", "sources", "typesCountHex", "sourcesCountHex", "data", "mode", "t", "s", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -0,0 +1,2 @@
1
+ "use strict";var p=Object.create;var o=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,i=Object.prototype.hasOwnProperty;var y=(e,t)=>{for(var a in t)o(e,a,{get:t[a],enumerable:!0})},c=(e,t,a,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let m of s(t))!i.call(e,m)&&m!==a&&o(e,m,{get:()=>t[m],enumerable:!(r=h(t,m))||r.enumerable});return e};var d=(e,t,a)=>(a=e!=null?p(S(e)):{},c(t||!e||!e.__esModule?o(a,"default",{value:e,enumerable:!0}):a,e)),f=e=>c(o({},"__esModule",{value:!0}),e);var g={};y(g,{getSchemaHash:()=>T});module.exports=f(g);var n=d(require("crypto-js/sha224"));function D(e){return Object.fromEntries(Object.entries(e).sort(([t],[a])=>t.localeCompare(a)).map(([t,a])=>[t,a.map(r=>({name:r.name,type:r.type}))]))}function T(e){const t=D(e),a=JSON.stringify(t);return(0,n.default)(a).toString()}0&&(module.exports={getSchemaHash});
2
+ //# sourceMappingURL=getSchemaHash.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/typed-data/utils/getSchemaHash.ts"],
4
+ "sourcesContent": ["import SHA224 from \"crypto-js/sha224\";\n\nimport type { TypedDataSchema } from \"@/shared/model/TypedDataContext\";\n\n/**\n * Schema hash is the SHA-224 hex digest of the compact JSON UTF-8 representation\n * of the EIP-712 schema (types object), with keys sorted for deterministic output.\n */\nexport type SchemaHash = string;\n\n/**\n * Sorts the schema by type name and normalizes each type's fields to { name, type }\n * for deterministic JSON serialization.\n */\nfunction sortSchema(schema: TypedDataSchema): TypedDataSchema {\n return Object.fromEntries(\n Object.entries(schema)\n .sort(([aKey], [bKey]) => aKey.localeCompare(bKey))\n .map(([key, value]) => [\n key,\n value.map((v) => ({ name: v.name, type: v.type })),\n ]),\n );\n}\n\n/**\n * Computes the schema hash of an EIP-712 schema.\n * Schema hash is SHA-224 of the compact JSON UTF-8 encoded representation of the schema.\n */\nexport function getSchemaHash(schema: TypedDataSchema): SchemaHash {\n const sortedSchema = sortSchema(schema);\n const schemaStr = JSON.stringify(sortedSchema);\n return SHA224(schemaStr).toString();\n}\n"],
5
+ "mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAmB,+BAcnB,SAASC,EAAWC,EAA0C,CAC5D,OAAO,OAAO,YACZ,OAAO,QAAQA,CAAM,EAClB,KAAK,CAAC,CAACC,CAAI,EAAG,CAACC,CAAI,IAAMD,EAAK,cAAcC,CAAI,CAAC,EACjD,IAAI,CAAC,CAACC,EAAKC,CAAK,IAAM,CACrBD,EACAC,EAAM,IAAKC,IAAO,CAAE,KAAMA,EAAE,KAAM,KAAMA,EAAE,IAAK,EAAE,CACnD,CAAC,CACL,CACF,CAMO,SAAST,EAAcI,EAAqC,CACjE,MAAMM,EAAeP,EAAWC,CAAM,EAChCO,EAAY,KAAK,UAAUD,CAAY,EAC7C,SAAO,EAAAE,SAAOD,CAAS,EAAE,SAAS,CACpC",
6
+ "names": ["getSchemaHash_exports", "__export", "getSchemaHash", "__toCommonJS", "import_sha224", "sortSchema", "schema", "aKey", "bKey", "key", "value", "v", "sortedSchema", "schemaStr", "SHA224"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var e=require("vitest"),a=require("./getSchemaHash");(0,e.describe)("getSchemaHash",()=>{(0,e.it)("returns SHA-224 hex digest of compact sorted JSON",()=>{const n=(0,a.getSchemaHash)({Mail:[{name:"from",type:"Person"},{name:"to",type:"Person"},{name:"contents",type:"string"}],Person:[{name:"name",type:"string"},{name:"wallet",type:"address"}]});(0,e.expect)(n).toMatch(/^[a-f0-9]{56}$/),(0,e.expect)(typeof n).toBe("string")}),(0,e.it)("is deterministic: same schema yields same hash",()=>{const t={EIP712Domain:[{name:"name",type:"string"},{name:"chainId",type:"uint256"}],Mail:[{name:"subject",type:"string"}]};(0,e.expect)((0,a.getSchemaHash)(t)).toBe((0,a.getSchemaHash)(t))}),(0,e.it)("sorts schema by type name for canonical representation",()=>{const t={Mail:[{name:"x",type:"string"}],EIP712Domain:[{name:"y",type:"uint256"}]},n={EIP712Domain:[{name:"y",type:"uint256"}],Mail:[{name:"x",type:"string"}]};(0,e.expect)((0,a.getSchemaHash)(t)).toBe((0,a.getSchemaHash)(n))})});
2
+ //# sourceMappingURL=getSchemaHash.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/typed-data/utils/getSchemaHash.test.ts"],
4
+ "sourcesContent": ["import { describe, expect, it } from \"vitest\";\n\nimport type { TypedDataSchema } from \"@/shared/model/TypedDataContext\";\n\nimport { getSchemaHash } from \"./getSchemaHash\";\n\ndescribe(\"getSchemaHash\", () => {\n it(\"returns SHA-224 hex digest of compact sorted JSON\", () => {\n const schema: TypedDataSchema = {\n Mail: [\n { name: \"from\", type: \"Person\" },\n { name: \"to\", type: \"Person\" },\n { name: \"contents\", type: \"string\" },\n ],\n Person: [\n { name: \"name\", type: \"string\" },\n { name: \"wallet\", type: \"address\" },\n ],\n };\n const hash = getSchemaHash(schema);\n expect(hash).toMatch(/^[a-f0-9]{56}$/);\n expect(typeof hash).toBe(\"string\");\n });\n\n it(\"is deterministic: same schema yields same hash\", () => {\n const schema: TypedDataSchema = {\n EIP712Domain: [\n { name: \"name\", type: \"string\" },\n { name: \"chainId\", type: \"uint256\" },\n ],\n Mail: [{ name: \"subject\", type: \"string\" }],\n };\n expect(getSchemaHash(schema)).toBe(getSchemaHash(schema));\n });\n\n it(\"sorts schema by type name for canonical representation\", () => {\n const schemaA: TypedDataSchema = {\n Mail: [{ name: \"x\", type: \"string\" }],\n EIP712Domain: [{ name: \"y\", type: \"uint256\" }],\n };\n const schemaB: TypedDataSchema = {\n EIP712Domain: [{ name: \"y\", type: \"uint256\" }],\n Mail: [{ name: \"x\", type: \"string\" }],\n };\n expect(getSchemaHash(schemaA)).toBe(getSchemaHash(schemaB));\n });\n});\n"],
5
+ "mappings": "aAAA,IAAAA,EAAqC,kBAIrCC,EAA8B,8BAE9B,YAAS,gBAAiB,IAAM,IAC9B,MAAG,oDAAqD,IAAM,CAY5D,MAAMC,KAAO,iBAXmB,CAC9B,KAAM,CACJ,CAAE,KAAM,OAAQ,KAAM,QAAS,EAC/B,CAAE,KAAM,KAAM,KAAM,QAAS,EAC7B,CAAE,KAAM,WAAY,KAAM,QAAS,CACrC,EACA,OAAQ,CACN,CAAE,KAAM,OAAQ,KAAM,QAAS,EAC/B,CAAE,KAAM,SAAU,KAAM,SAAU,CACpC,CACF,CACiC,KACjC,UAAOA,CAAI,EAAE,QAAQ,gBAAgB,KACrC,UAAO,OAAOA,CAAI,EAAE,KAAK,QAAQ,CACnC,CAAC,KAED,MAAG,iDAAkD,IAAM,CACzD,MAAMC,EAA0B,CAC9B,aAAc,CACZ,CAAE,KAAM,OAAQ,KAAM,QAAS,EAC/B,CAAE,KAAM,UAAW,KAAM,SAAU,CACrC,EACA,KAAM,CAAC,CAAE,KAAM,UAAW,KAAM,QAAS,CAAC,CAC5C,KACA,aAAO,iBAAcA,CAAM,CAAC,EAAE,QAAK,iBAAcA,CAAM,CAAC,CAC1D,CAAC,KAED,MAAG,yDAA0D,IAAM,CACjE,MAAMC,EAA2B,CAC/B,KAAM,CAAC,CAAE,KAAM,IAAK,KAAM,QAAS,CAAC,EACpC,aAAc,CAAC,CAAE,KAAM,IAAK,KAAM,SAAU,CAAC,CAC/C,EACMC,EAA2B,CAC/B,aAAc,CAAC,CAAE,KAAM,IAAK,KAAM,SAAU,CAAC,EAC7C,KAAM,CAAC,CAAE,KAAM,IAAK,KAAM,QAAS,CAAC,CACtC,KACA,aAAO,iBAAcD,CAAO,CAAC,EAAE,QAAK,iBAAcC,CAAO,CAAC,CAC5D,CAAC,CACH,CAAC",
6
+ "names": ["import_vitest", "import_getSchemaHash", "hash", "schema", "schemaA", "schemaB"]
7
+ }
@@ -35,7 +35,7 @@
35
35
  "license": "Apache-2.0",
36
36
  "name": "@ledgerhq/context-module",
37
37
  "peerDependencies": {
38
- "@ledgerhq/device-management-kit": "^1.1.0"
38
+ "@ledgerhq/device-management-kit": "workspace:^"
39
39
  },
40
40
  "private": false,
41
41
  "repository": {
@@ -58,5 +58,5 @@
58
58
  "watch:builds": "pnpm ldmk-tool watch --entryPoints index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
59
59
  "watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\""
60
60
  },
61
- "version": "1.14.1"
61
+ "version": "1.15.0"
62
62
  }
@@ -1,2 +1,2 @@
1
- import{Left as C}from"purify-ts";import{calldataTypes as x}from"./calldata/di/calldataTypes";import{dynamicNetworkTypes as m}from"./dynamic-network/di/dynamicNetworkTypes";import{trustedNameTypes as i}from"./trusted-name/di/trustedNameTypes";import{externalPluginTypes as L}from"./external-plugin/di/externalPluginTypes";import{nftTypes as s}from"./nft/di/nftTypes";import{proxyTypes as y}from"./proxy/di/proxyTypes";import{safeTypes as c}from"./safe/di/safeTypes";import{ClearSignContextType as n}from"./shared/model/ClearSignContext";import{solanaContextTypes as f}from"./solana/di/solanaContextTypes";import{tokenTypes as l}from"./token/di/tokenTypes";import{transactionCheckTypes as p}from"./transaction-check/di/transactionCheckTypes";import{typedDataTypes as u}from"./typed-data/di/typedDataTypes";import{makeContainer as T}from"./di";class ${_container;_loaders;_typedDataLoader;_solanaLoader;_fieldLoaders;constructor(t){this._container=T({config:t}),this._loaders=t.defaultLoaders?this._getDefaultLoaders():[],this._loaders.push(...t.customLoaders),this._fieldLoaders=t.defaultFieldLoaders?this._getDefaultFieldLoaders():[],this._fieldLoaders.push(...t.customFieldLoaders),this._typedDataLoader=t.customTypedDataLoader??this._getDefaultTypedDataLoader(),this._solanaLoader=t.customSolanaLoader??this._getSolanaLoader()}_getDefaultFieldLoaders(){return[this._container.get(s.NftContextFieldLoader),this._container.get(l.TokenContextFieldLoader),this._container.get(i.TrustedNameContextFieldLoader),this._container.get(y.ProxyContextFieldLoader)]}_getDefaultLoaders(){return[this._container.get(L.ExternalPluginContextLoader),this._container.get(i.TrustedNameContextLoader),this._container.get(s.NftContextLoader),this._container.get(l.TokenContextLoader),this._container.get(x.CalldataContextLoader),this._container.get(m.DynamicNetworkContextLoader),this._container.get(c.SafeAddressLoader),this._container.get(p.TransactionCheckContextLoader),this._container.get(p.TypedDataCheckContextLoader)]}_getDefaultTypedDataLoader(){return this._container.get(u.TypedDataContextLoader)}_getSolanaLoader(){try{return this._container.get(f.SolanaContextLoader)}catch{return{load:async t=>C(new Error("[ContextModule] - DefaultContextModule: no SolanaContextLoader bound"))}}}async getContexts(t,e){const o=Object.values(n),r=this._loaders.filter(d=>d.canHandle(t,e??o)).map(d=>d.load(t));return(await Promise.all(r)).flat()}async getFieldContext(t,e){const o=this._fieldLoaders.filter(a=>a.canHandle(t,e));if(o.length===0)return Promise.resolve({type:n.ERROR,error:new Error(`Loader not found for field: ${t} and expected type: ${e}`)});for(const a of o){const r=await a.loadField(t);if(r.type!==n.ERROR)return r}return{type:n.ERROR,error:new Error(`Loader not found for field: ${t} and expected type: ${e}`)}}async getTypedDataFilters(t){return this._typedDataLoader.load(t)}async getSolanaContext(t){return await this._solanaLoader.load(t)}}export{$ as DefaultContextModule};
1
+ import{Left as x}from"purify-ts";import{calldataTypes as m}from"./calldata/di/calldataTypes";import{dynamicNetworkTypes as L}from"./dynamic-network/di/dynamicNetworkTypes";import{trustedNameTypes as i}from"./trusted-name/di/trustedNameTypes";import{externalPluginTypes as y}from"./external-plugin/di/externalPluginTypes";import{gatedSigningTypes as s}from"./gated-signing/di/gatedSigningTypes";import{nftTypes as l}from"./nft/di/nftTypes";import{proxyTypes as c}from"./proxy/di/proxyTypes";import{safeTypes as f}from"./safe/di/safeTypes";import{ClearSignContextType as n}from"./shared/model/ClearSignContext";import{solanaContextTypes as u}from"./solana/di/solanaContextTypes";import{tokenTypes as p}from"./token/di/tokenTypes";import{transactionCheckTypes as C}from"./transaction-check/di/transactionCheckTypes";import{typedDataTypes as g}from"./typed-data/di/typedDataTypes";import{makeContainer as T}from"./di";class H{_container;_loaders;_typedDataLoader;_solanaLoader;_fieldLoaders;constructor(t){this._container=T({config:t}),this._loaders=t.defaultLoaders?this._getDefaultLoaders():[],this._loaders.push(...t.customLoaders),this._fieldLoaders=t.defaultFieldLoaders?this._getDefaultFieldLoaders():[],this._fieldLoaders.push(...t.customFieldLoaders),this._typedDataLoader=t.customTypedDataLoader??this._getDefaultTypedDataLoader(),this._solanaLoader=t.customSolanaLoader??this._getSolanaLoader()}_getDefaultFieldLoaders(){return[this._container.get(l.NftContextFieldLoader),this._container.get(p.TokenContextFieldLoader),this._container.get(i.TrustedNameContextFieldLoader),this._container.get(c.ProxyContextFieldLoader)]}_getDefaultLoaders(){return[this._container.get(y.ExternalPluginContextLoader),this._container.get(i.TrustedNameContextLoader),this._container.get(l.NftContextLoader),this._container.get(p.TokenContextLoader),this._container.get(m.CalldataContextLoader),this._container.get(L.DynamicNetworkContextLoader),this._container.get(f.SafeAddressLoader),this._container.get(s.GatedSigningContextLoader),this._container.get(s.GatedSigningTypedDataContextLoader),this._container.get(C.TransactionCheckContextLoader),this._container.get(C.TypedDataCheckContextLoader)]}_getDefaultTypedDataLoader(){return this._container.get(g.TypedDataContextLoader)}_getSolanaLoader(){try{return this._container.get(u.SolanaContextLoader)}catch{return{load:async t=>x(new Error("[ContextModule] - DefaultContextModule: no SolanaContextLoader bound"))}}}async getContexts(t,e){const o=Object.values(n),r=this._loaders.filter(d=>d.canHandle(t,e??o)).map(d=>d.load(t));return(await Promise.all(r)).flat()}async getFieldContext(t,e){const o=this._fieldLoaders.filter(a=>a.canHandle(t,e));if(o.length===0)return Promise.resolve({type:n.ERROR,error:new Error(`Loader not found for field: ${t} and expected type: ${e}`)});for(const a of o){const r=await a.loadField(t);if(r.type!==n.ERROR)return r}return{type:n.ERROR,error:new Error(`Loader not found for field: ${t} and expected type: ${e}`)}}async getTypedDataFilters(t){return this._typedDataLoader.load(t)}async getSolanaContext(t){return await this._solanaLoader.load(t)}}export{H as DefaultContextModule};
2
2
  //# sourceMappingURL=DefaultContextModule.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/DefaultContextModule.ts"],
4
- "sourcesContent": ["import { type Container } from \"inversify\";\nimport { Left } from \"purify-ts\";\n\nimport { calldataTypes } from \"@/calldata/di/calldataTypes\";\nimport { dynamicNetworkTypes } from \"@/dynamic-network/di/dynamicNetworkTypes\";\nimport type { TypedDataClearSignContext } from \"@/shared/model/TypedDataClearSignContext\";\nimport type { TypedDataContext } from \"@/shared/model/TypedDataContext\";\nimport { trustedNameTypes } from \"@/trusted-name/di/trustedNameTypes\";\n\nimport { type ContextModuleConfig } from \"./config/model/ContextModuleConfig\";\nimport { externalPluginTypes } from \"./external-plugin/di/externalPluginTypes\";\nimport { nftTypes } from \"./nft/di/nftTypes\";\nimport { proxyTypes } from \"./proxy/di/proxyTypes\";\nimport { safeTypes } from \"./safe/di/safeTypes\";\nimport { type ContextFieldLoader } from \"./shared/domain/ContextFieldLoader\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport {\n type ClearSignContext,\n ClearSignContextType,\n} from \"./shared/model/ClearSignContext\";\nimport { type SolanaTransactionContext } from \"./shared/model/SolanaTransactionContext\";\nimport { solanaContextTypes } from \"./solana/di/solanaContextTypes\";\nimport { type SolanaContextLoader } from \"./solana/domain/SolanaContextLoader\";\nimport { type SolanaTransactionContextResult } from \"./solana/domain/solanaContextTypes\";\nimport { tokenTypes } from \"./token/di/tokenTypes\";\nimport { transactionCheckTypes } from \"./transaction-check/di/transactionCheckTypes\";\nimport { typedDataTypes } from \"./typed-data/di/typedDataTypes\";\nimport type { TypedDataContextLoader } from \"./typed-data/domain/TypedDataContextLoader\";\nimport { type ContextModule } from \"./ContextModule\";\nimport { makeContainer } from \"./di\";\n\nexport class DefaultContextModule implements ContextModule {\n private _container: Container;\n private _loaders: ContextLoader<unknown>[];\n private _typedDataLoader: TypedDataContextLoader;\n private _solanaLoader: SolanaContextLoader;\n private _fieldLoaders: ContextFieldLoader<unknown>[];\n\n constructor(args: ContextModuleConfig) {\n this._container = makeContainer({ config: args });\n\n this._loaders = args.defaultLoaders ? this._getDefaultLoaders() : [];\n this._loaders.push(...args.customLoaders);\n\n this._fieldLoaders = args.defaultFieldLoaders\n ? this._getDefaultFieldLoaders()\n : [];\n this._fieldLoaders.push(...args.customFieldLoaders);\n\n this._typedDataLoader =\n args.customTypedDataLoader ?? this._getDefaultTypedDataLoader();\n this._solanaLoader = args.customSolanaLoader ?? this._getSolanaLoader();\n }\n\n private _getDefaultFieldLoaders(): ContextFieldLoader[] {\n return [\n this._container.get<ContextFieldLoader>(nftTypes.NftContextFieldLoader),\n this._container.get<ContextFieldLoader>(\n tokenTypes.TokenContextFieldLoader,\n ),\n this._container.get<ContextFieldLoader>(\n trustedNameTypes.TrustedNameContextFieldLoader,\n ),\n this._container.get<ContextFieldLoader>(\n proxyTypes.ProxyContextFieldLoader,\n ),\n ];\n }\n\n private _getDefaultLoaders(): ContextLoader<unknown>[] {\n return [\n this._container.get<ContextLoader>(\n externalPluginTypes.ExternalPluginContextLoader,\n ),\n this._container.get<ContextLoader>(\n trustedNameTypes.TrustedNameContextLoader,\n ),\n this._container.get<ContextLoader>(nftTypes.NftContextLoader),\n this._container.get<ContextLoader>(tokenTypes.TokenContextLoader),\n this._container.get<ContextLoader>(calldataTypes.CalldataContextLoader),\n this._container.get<ContextLoader>(\n dynamicNetworkTypes.DynamicNetworkContextLoader,\n ),\n this._container.get<ContextLoader>(safeTypes.SafeAddressLoader),\n this._container.get<ContextLoader>(\n transactionCheckTypes.TransactionCheckContextLoader,\n ),\n this._container.get<ContextLoader>(\n transactionCheckTypes.TypedDataCheckContextLoader,\n ),\n ];\n }\n\n private _getDefaultTypedDataLoader(): TypedDataContextLoader {\n return this._container.get<TypedDataContextLoader>(\n typedDataTypes.TypedDataContextLoader,\n );\n }\n\n private _getSolanaLoader(): SolanaContextLoader {\n try {\n return this._container.get<SolanaContextLoader>(\n solanaContextTypes.SolanaContextLoader,\n );\n } catch {\n return {\n load: async (_ctx) =>\n Left(\n new Error(\n \"[ContextModule] - DefaultContextModule: no SolanaContextLoader bound\",\n ),\n ),\n };\n }\n }\n\n public async getContexts(\n input: unknown,\n expectedTypes?: ClearSignContextType[],\n ): Promise<ClearSignContext[]> {\n const allContextTypes = Object.values(ClearSignContextType);\n const loaders = this._loaders.filter((l) =>\n l.canHandle(input, expectedTypes ?? allContextTypes),\n );\n const promises = loaders.map((fetcher) => fetcher.load(input));\n const responses = await Promise.all(promises);\n return responses.flat();\n }\n\n public async getFieldContext<TInput>(\n field: TInput,\n expectedType: ClearSignContextType,\n ): Promise<ClearSignContext> {\n const loaders = this._fieldLoaders.filter((l) =>\n l.canHandle(field, expectedType),\n );\n if (loaders.length === 0) {\n return Promise.resolve({\n type: ClearSignContextType.ERROR,\n error: new Error(\n `Loader not found for field: ${field} and expected type: ${expectedType}`,\n ),\n });\n }\n\n for (const loader of loaders) {\n const context = await loader.loadField(field);\n if (context.type !== ClearSignContextType.ERROR) {\n return context;\n }\n }\n\n return {\n type: ClearSignContextType.ERROR,\n error: new Error(\n `Loader not found for field: ${field} and expected type: ${expectedType}`,\n ),\n };\n }\n\n public async getTypedDataFilters(\n typedData: TypedDataContext,\n ): Promise<TypedDataClearSignContext> {\n return this._typedDataLoader.load(typedData);\n }\n\n public async getSolanaContext(\n transactionContext: SolanaTransactionContext,\n ): Promise<SolanaTransactionContextResult> {\n return await this._solanaLoader.load(transactionContext);\n }\n}\n"],
5
- "mappings": "AACA,OAAS,QAAAA,MAAY,YAErB,OAAS,iBAAAC,MAAqB,8BAC9B,OAAS,uBAAAC,MAA2B,2CAGpC,OAAS,oBAAAC,MAAwB,qCAGjC,OAAS,uBAAAC,MAA2B,2CACpC,OAAS,YAAAC,MAAgB,oBACzB,OAAS,cAAAC,MAAkB,wBAC3B,OAAS,aAAAC,MAAiB,sBAG1B,OAEE,wBAAAC,MACK,kCAEP,OAAS,sBAAAC,MAA0B,iCAGnC,OAAS,cAAAC,MAAkB,wBAC3B,OAAS,yBAAAC,MAA6B,+CACtC,OAAS,kBAAAC,MAAsB,iCAG/B,OAAS,iBAAAC,MAAqB,OAEvB,MAAMC,CAA8C,CACjD,WACA,SACA,iBACA,cACA,cAER,YAAYC,EAA2B,CACrC,KAAK,WAAaF,EAAc,CAAE,OAAQE,CAAK,CAAC,EAEhD,KAAK,SAAWA,EAAK,eAAiB,KAAK,mBAAmB,EAAI,CAAC,EACnE,KAAK,SAAS,KAAK,GAAGA,EAAK,aAAa,EAExC,KAAK,cAAgBA,EAAK,oBACtB,KAAK,wBAAwB,EAC7B,CAAC,EACL,KAAK,cAAc,KAAK,GAAGA,EAAK,kBAAkB,EAElD,KAAK,iBACHA,EAAK,uBAAyB,KAAK,2BAA2B,EAChE,KAAK,cAAgBA,EAAK,oBAAsB,KAAK,iBAAiB,CACxE,CAEQ,yBAAgD,CACtD,MAAO,CACL,KAAK,WAAW,IAAwBV,EAAS,qBAAqB,EACtE,KAAK,WAAW,IACdK,EAAW,uBACb,EACA,KAAK,WAAW,IACdP,EAAiB,6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,EAAU,MAAMD,EAAO,UAAUH,CAAK,EAC5C,GAAII,EAAQ,OAASnB,EAAqB,MACxC,OAAOmB,CAEX,CAEA,MAAO,CACL,KAAMnB,EAAqB,MAC3B,MAAO,IAAI,MACT,+BAA+Be,CAAK,uBAAuBC,CAAY,EACzE,CACF,CACF,CAEA,MAAa,oBACXI,EACoC,CACpC,OAAO,KAAK,iBAAiB,KAAKA,CAAS,CAC7C,CAEA,MAAa,iBACXC,EACyC,CACzC,OAAO,MAAM,KAAK,cAAc,KAAKA,CAAkB,CACzD,CACF",
6
- "names": ["Left", "calldataTypes", "dynamicNetworkTypes", "trustedNameTypes", "externalPluginTypes", "nftTypes", "proxyTypes", "safeTypes", "ClearSignContextType", "solanaContextTypes", "tokenTypes", "transactionCheckTypes", "typedDataTypes", "makeContainer", "DefaultContextModule", "args", "_ctx", "input", "expectedTypes", "allContextTypes", "promises", "l", "fetcher", "field", "expectedType", "loaders", "loader", "context", "typedData", "transactionContext"]
4
+ "sourcesContent": ["import { type Container } from \"inversify\";\nimport { Left } from \"purify-ts\";\n\nimport { calldataTypes } from \"@/calldata/di/calldataTypes\";\nimport { dynamicNetworkTypes } from \"@/dynamic-network/di/dynamicNetworkTypes\";\nimport type { TypedDataClearSignContext } from \"@/shared/model/TypedDataClearSignContext\";\nimport type { TypedDataContext } from \"@/shared/model/TypedDataContext\";\nimport { trustedNameTypes } from \"@/trusted-name/di/trustedNameTypes\";\n\nimport { type ContextModuleConfig } from \"./config/model/ContextModuleConfig\";\nimport { externalPluginTypes } from \"./external-plugin/di/externalPluginTypes\";\nimport { gatedSigningTypes } from \"./gated-signing/di/gatedSigningTypes\";\nimport { nftTypes } from \"./nft/di/nftTypes\";\nimport { proxyTypes } from \"./proxy/di/proxyTypes\";\nimport { safeTypes } from \"./safe/di/safeTypes\";\nimport { type ContextFieldLoader } from \"./shared/domain/ContextFieldLoader\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport {\n type ClearSignContext,\n ClearSignContextType,\n} from \"./shared/model/ClearSignContext\";\nimport { type SolanaTransactionContext } from \"./shared/model/SolanaTransactionContext\";\nimport { solanaContextTypes } from \"./solana/di/solanaContextTypes\";\nimport { type SolanaContextLoader } from \"./solana/domain/SolanaContextLoader\";\nimport { type SolanaTransactionContextResult } from \"./solana/domain/solanaContextTypes\";\nimport { tokenTypes } from \"./token/di/tokenTypes\";\nimport { transactionCheckTypes } from \"./transaction-check/di/transactionCheckTypes\";\nimport { typedDataTypes } from \"./typed-data/di/typedDataTypes\";\nimport type { TypedDataContextLoader } from \"./typed-data/domain/TypedDataContextLoader\";\nimport { type ContextModule } from \"./ContextModule\";\nimport { makeContainer } from \"./di\";\n\nexport class DefaultContextModule implements ContextModule {\n private _container: Container;\n private _loaders: ContextLoader<unknown>[];\n private _typedDataLoader: TypedDataContextLoader;\n private _solanaLoader: SolanaContextLoader;\n private _fieldLoaders: ContextFieldLoader<unknown>[];\n\n constructor(args: ContextModuleConfig) {\n this._container = makeContainer({ config: args });\n\n this._loaders = args.defaultLoaders ? this._getDefaultLoaders() : [];\n this._loaders.push(...args.customLoaders);\n\n this._fieldLoaders = args.defaultFieldLoaders\n ? this._getDefaultFieldLoaders()\n : [];\n this._fieldLoaders.push(...args.customFieldLoaders);\n\n this._typedDataLoader =\n args.customTypedDataLoader ?? this._getDefaultTypedDataLoader();\n this._solanaLoader = args.customSolanaLoader ?? this._getSolanaLoader();\n }\n\n private _getDefaultFieldLoaders(): ContextFieldLoader[] {\n return [\n this._container.get<ContextFieldLoader>(nftTypes.NftContextFieldLoader),\n this._container.get<ContextFieldLoader>(\n tokenTypes.TokenContextFieldLoader,\n ),\n this._container.get<ContextFieldLoader>(\n trustedNameTypes.TrustedNameContextFieldLoader,\n ),\n this._container.get<ContextFieldLoader>(\n proxyTypes.ProxyContextFieldLoader,\n ),\n ];\n }\n\n private _getDefaultLoaders(): ContextLoader<unknown>[] {\n return [\n this._container.get<ContextLoader>(\n externalPluginTypes.ExternalPluginContextLoader,\n ),\n this._container.get<ContextLoader>(\n trustedNameTypes.TrustedNameContextLoader,\n ),\n this._container.get<ContextLoader>(nftTypes.NftContextLoader),\n this._container.get<ContextLoader>(tokenTypes.TokenContextLoader),\n this._container.get<ContextLoader>(calldataTypes.CalldataContextLoader),\n this._container.get<ContextLoader>(\n dynamicNetworkTypes.DynamicNetworkContextLoader,\n ),\n this._container.get<ContextLoader>(safeTypes.SafeAddressLoader),\n this._container.get<ContextLoader>(\n gatedSigningTypes.GatedSigningContextLoader,\n ),\n this._container.get<ContextLoader>(\n gatedSigningTypes.GatedSigningTypedDataContextLoader,\n ),\n this._container.get<ContextLoader>(\n transactionCheckTypes.TransactionCheckContextLoader,\n ),\n this._container.get<ContextLoader>(\n transactionCheckTypes.TypedDataCheckContextLoader,\n ),\n ];\n }\n\n private _getDefaultTypedDataLoader(): TypedDataContextLoader {\n return this._container.get<TypedDataContextLoader>(\n typedDataTypes.TypedDataContextLoader,\n );\n }\n\n private _getSolanaLoader(): SolanaContextLoader {\n try {\n return this._container.get<SolanaContextLoader>(\n solanaContextTypes.SolanaContextLoader,\n );\n } catch {\n return {\n load: async (_ctx) =>\n Left(\n new Error(\n \"[ContextModule] - DefaultContextModule: no SolanaContextLoader bound\",\n ),\n ),\n };\n }\n }\n\n public async getContexts(\n input: unknown,\n expectedTypes?: ClearSignContextType[],\n ): Promise<ClearSignContext[]> {\n const allContextTypes = Object.values(ClearSignContextType);\n const loaders = this._loaders.filter((l) =>\n l.canHandle(input, expectedTypes ?? allContextTypes),\n );\n const promises = loaders.map((fetcher) => fetcher.load(input));\n const responses = await Promise.all(promises);\n return responses.flat();\n }\n\n public async getFieldContext<TInput>(\n field: TInput,\n expectedType: ClearSignContextType,\n ): Promise<ClearSignContext> {\n const loaders = this._fieldLoaders.filter((l) =>\n l.canHandle(field, expectedType),\n );\n if (loaders.length === 0) {\n return Promise.resolve({\n type: ClearSignContextType.ERROR,\n error: new Error(\n `Loader not found for field: ${field} and expected type: ${expectedType}`,\n ),\n });\n }\n\n for (const loader of loaders) {\n const context = await loader.loadField(field);\n if (context.type !== ClearSignContextType.ERROR) {\n return context;\n }\n }\n\n return {\n type: ClearSignContextType.ERROR,\n error: new Error(\n `Loader not found for field: ${field} and expected type: ${expectedType}`,\n ),\n };\n }\n\n public async getTypedDataFilters(\n typedData: TypedDataContext,\n ): Promise<TypedDataClearSignContext> {\n return this._typedDataLoader.load(typedData);\n }\n\n public async getSolanaContext(\n transactionContext: SolanaTransactionContext,\n ): Promise<SolanaTransactionContextResult> {\n return await this._solanaLoader.load(transactionContext);\n }\n}\n"],
5
+ "mappings": "AACA,OAAS,QAAAA,MAAY,YAErB,OAAS,iBAAAC,MAAqB,8BAC9B,OAAS,uBAAAC,MAA2B,2CAGpC,OAAS,oBAAAC,MAAwB,qCAGjC,OAAS,uBAAAC,MAA2B,2CACpC,OAAS,qBAAAC,MAAyB,uCAClC,OAAS,YAAAC,MAAgB,oBACzB,OAAS,cAAAC,MAAkB,wBAC3B,OAAS,aAAAC,MAAiB,sBAG1B,OAEE,wBAAAC,MACK,kCAEP,OAAS,sBAAAC,MAA0B,iCAGnC,OAAS,cAAAC,MAAkB,wBAC3B,OAAS,yBAAAC,MAA6B,+CACtC,OAAS,kBAAAC,MAAsB,iCAG/B,OAAS,iBAAAC,MAAqB,OAEvB,MAAMC,CAA8C,CACjD,WACA,SACA,iBACA,cACA,cAER,YAAYC,EAA2B,CACrC,KAAK,WAAaF,EAAc,CAAE,OAAQE,CAAK,CAAC,EAEhD,KAAK,SAAWA,EAAK,eAAiB,KAAK,mBAAmB,EAAI,CAAC,EACnE,KAAK,SAAS,KAAK,GAAGA,EAAK,aAAa,EAExC,KAAK,cAAgBA,EAAK,oBACtB,KAAK,wBAAwB,EAC7B,CAAC,EACL,KAAK,cAAc,KAAK,GAAGA,EAAK,kBAAkB,EAElD,KAAK,iBACHA,EAAK,uBAAyB,KAAK,2BAA2B,EAChE,KAAK,cAAgBA,EAAK,oBAAsB,KAAK,iBAAiB,CAC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E,UAAUE,EAAOC,CAAY,CACjC,EACA,GAAIC,EAAQ,SAAW,EACrB,OAAO,QAAQ,QAAQ,CACrB,KAAMjB,EAAqB,MAC3B,MAAO,IAAI,MACT,+BAA+Be,CAAK,uBAAuBC,CAAY,EACzE,CACF,CAAC,EAGH,UAAWE,KAAUD,EAAS,CAC5B,MAAME,EAAU,MAAMD,EAAO,UAAUH,CAAK,EAC5C,GAAII,EAAQ,OAASnB,EAAqB,MACxC,OAAOmB,CAEX,CAEA,MAAO,CACL,KAAMnB,EAAqB,MAC3B,MAAO,IAAI,MACT,+BAA+Be,CAAK,uBAAuBC,CAAY,EACzE,CACF,CACF,CAEA,MAAa,oBACXI,EACoC,CACpC,OAAO,KAAK,iBAAiB,KAAKA,CAAS,CAC7C,CAEA,MAAa,iBACXC,EACyC,CACzC,OAAO,MAAM,KAAK,cAAc,KAAKA,CAAkB,CACzD,CACF",
6
+ "names": ["Left", "calldataTypes", "dynamicNetworkTypes", "trustedNameTypes", "externalPluginTypes", "gatedSigningTypes", "nftTypes", "proxyTypes", "safeTypes", "ClearSignContextType", "solanaContextTypes", "tokenTypes", "transactionCheckTypes", "typedDataTypes", "makeContainer", "DefaultContextModule", "args", "_ctx", "input", "expectedTypes", "allContextTypes", "promises", "l", "fetcher", "field", "expectedType", "loaders", "loader", "context", "typedData", "transactionContext"]
7
7
  }