@ledgerhq/context-module 2.3.0 → 2.4.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 (169) hide show
  1. package/lib/cjs/package.json +2 -2
  2. package/lib/cjs/src/modules/multichain/transaction-check/loaders/SolanaTransactionCheckLoader.js +1 -1
  3. package/lib/cjs/src/modules/multichain/transaction-check/loaders/SolanaTransactionCheckLoader.js.map +3 -3
  4. package/lib/cjs/src/modules/multichain/transaction-check/loaders/SolanaTransactionCheckLoader.test.js +1 -1
  5. package/lib/cjs/src/modules/multichain/transaction-check/loaders/SolanaTransactionCheckLoader.test.js.map +3 -3
  6. package/lib/cjs/src/modules/solana/alt-resolution/data/AltResolutionDataSource.js +1 -1
  7. package/lib/cjs/src/modules/solana/alt-resolution/data/AltResolutionDataSource.js.map +1 -1
  8. package/lib/cjs/src/modules/solana/alt-resolution/data/HttpAltResolutionDataSource.js +1 -1
  9. package/lib/cjs/src/modules/solana/alt-resolution/data/HttpAltResolutionDataSource.js.map +2 -2
  10. package/lib/cjs/src/modules/solana/alt-resolution/domain/AltResolutionContextLoader.js +1 -1
  11. package/lib/cjs/src/modules/solana/alt-resolution/domain/AltResolutionContextLoader.js.map +2 -2
  12. package/lib/cjs/src/modules/solana/instruction-info/data/HttpInstructionInfoDataSource.js +1 -1
  13. package/lib/cjs/src/modules/solana/instruction-info/data/HttpInstructionInfoDataSource.js.map +2 -2
  14. package/lib/cjs/src/modules/solana/instruction-info/data/HttpInstructionInfoDataSource.test.js +1 -1
  15. package/lib/cjs/src/modules/solana/instruction-info/data/HttpInstructionInfoDataSource.test.js.map +3 -3
  16. package/lib/cjs/src/modules/solana/instruction-info/data/InstructionInfoDto.js +1 -1
  17. package/lib/cjs/src/modules/solana/instruction-info/data/InstructionInfoDto.js.map +2 -2
  18. package/lib/cjs/src/modules/solana/lifi/domain/LifiContextLoader.js +1 -1
  19. package/lib/cjs/src/modules/solana/lifi/domain/LifiContextLoader.js.map +3 -3
  20. package/lib/cjs/src/modules/solana/lifi/domain/LifiContextLoader.test.js +1 -1
  21. package/lib/cjs/src/modules/solana/lifi/domain/LifiContextLoader.test.js.map +3 -3
  22. package/lib/cjs/src/modules/solana/model/SolanaContextTypes.js.map +1 -1
  23. package/lib/cjs/src/modules/solana/model/SolanaPayloads.js +1 -1
  24. package/lib/cjs/src/modules/solana/model/SolanaPayloads.js.map +2 -2
  25. package/lib/cjs/src/modules/solana/model/SolanaTransactionContext.js +1 -1
  26. package/lib/cjs/src/modules/solana/model/SolanaTransactionContext.js.map +1 -1
  27. package/lib/cjs/src/modules/solana/owner-info/data/HttpOwnerInfoDataSource.js +1 -1
  28. package/lib/cjs/src/modules/solana/owner-info/data/HttpOwnerInfoDataSource.js.map +2 -2
  29. package/lib/cjs/src/modules/solana/owner-info/data/HttpOwnerInfoDataSource.test.js +1 -1
  30. package/lib/cjs/src/modules/solana/owner-info/data/HttpOwnerInfoDataSource.test.js.map +2 -2
  31. package/lib/cjs/src/modules/solana/token/data/HttpMintToIdDataSource.js +2 -0
  32. package/lib/cjs/src/modules/solana/token/data/HttpMintToIdDataSource.js.map +7 -0
  33. package/lib/cjs/src/modules/solana/token/data/HttpMintToIdDataSource.test.js +2 -0
  34. package/lib/cjs/src/modules/solana/token/data/HttpMintToIdDataSource.test.js.map +7 -0
  35. package/lib/cjs/src/modules/solana/token/data/MintToIdDataSource.js +2 -0
  36. package/lib/cjs/src/modules/solana/token/data/MintToIdDataSource.js.map +7 -0
  37. package/lib/cjs/src/modules/solana/token/di/tokenModuleFactory.js +1 -1
  38. package/lib/cjs/src/modules/solana/token/di/tokenModuleFactory.js.map +3 -3
  39. package/lib/cjs/src/modules/solana/token/di/tokenTypes.js +1 -1
  40. package/lib/cjs/src/modules/solana/token/di/tokenTypes.js.map +2 -2
  41. package/lib/cjs/src/modules/solana/token/domain/TokenContextLoader.js +1 -1
  42. package/lib/cjs/src/modules/solana/token/domain/TokenContextLoader.js.map +3 -3
  43. package/lib/cjs/src/modules/solana/token/domain/TokenContextLoader.test.js +1 -1
  44. package/lib/cjs/src/modules/solana/token/domain/TokenContextLoader.test.js.map +3 -3
  45. package/lib/cjs/src/modules/solana/token-account-state/data/HttpTokenAccountStateDataSource.js +1 -1
  46. package/lib/cjs/src/modules/solana/token-account-state/data/HttpTokenAccountStateDataSource.js.map +2 -2
  47. package/lib/cjs/src/modules/solana/token-account-state/data/TokenAccountStateDataSource.js +1 -1
  48. package/lib/cjs/src/modules/solana/token-account-state/data/TokenAccountStateDataSource.js.map +1 -1
  49. package/lib/cjs/src/modules/solana/token-account-state/domain/TokenAccountStateContextLoader.js +1 -1
  50. package/lib/cjs/src/modules/solana/token-account-state/domain/TokenAccountStateContextLoader.js.map +2 -2
  51. package/lib/cjs/src/modules/solana/token-info/data/HttpTokenInfoDataSource.js +1 -1
  52. package/lib/cjs/src/modules/solana/token-info/data/HttpTokenInfoDataSource.js.map +3 -3
  53. package/lib/cjs/src/modules/solana/token-info/data/HttpTokenInfoDataSource.test.js +1 -1
  54. package/lib/cjs/src/modules/solana/token-info/data/HttpTokenInfoDataSource.test.js.map +2 -2
  55. package/lib/cjs/src/modules/solana/trusted-name/data/HttpTrustedNameDataSource.js +1 -1
  56. package/lib/cjs/src/modules/solana/trusted-name/data/HttpTrustedNameDataSource.js.map +3 -3
  57. package/lib/cjs/src/modules/solana/trusted-name/data/HttpTrustedNameDataSource.test.js +1 -1
  58. package/lib/cjs/src/modules/solana/trusted-name/data/HttpTrustedNameDataSource.test.js.map +2 -2
  59. package/lib/cjs/src/modules/solana/trusted-name/data/TrustedNameDataSource.js +1 -1
  60. package/lib/cjs/src/modules/solana/trusted-name/data/TrustedNameDataSource.js.map +1 -1
  61. package/lib/cjs/src/modules/solana/trusted-name/domain/TrustedNameContextLoader.js +1 -1
  62. package/lib/cjs/src/modules/solana/trusted-name/domain/TrustedNameContextLoader.js.map +2 -2
  63. package/lib/cjs/src/modules/solana/trusted-name/domain/TrustedNameContextLoader.test.js +1 -1
  64. package/lib/cjs/src/modules/solana/trusted-name/domain/TrustedNameContextLoader.test.js.map +2 -2
  65. package/lib/cjs/src/shared/utils/deviceModelIdCodec.js +1 -1
  66. package/lib/cjs/src/shared/utils/deviceModelIdCodec.js.map +2 -2
  67. package/lib/cjs/src/shared/utils/deviceModelIdCodec.test.js +1 -1
  68. package/lib/cjs/src/shared/utils/deviceModelIdCodec.test.js.map +2 -2
  69. package/lib/esm/package.json +2 -2
  70. package/lib/esm/src/modules/multichain/transaction-check/loaders/SolanaTransactionCheckLoader.js +1 -1
  71. package/lib/esm/src/modules/multichain/transaction-check/loaders/SolanaTransactionCheckLoader.js.map +3 -3
  72. package/lib/esm/src/modules/multichain/transaction-check/loaders/SolanaTransactionCheckLoader.test.js +1 -1
  73. package/lib/esm/src/modules/multichain/transaction-check/loaders/SolanaTransactionCheckLoader.test.js.map +3 -3
  74. package/lib/esm/src/modules/solana/alt-resolution/data/HttpAltResolutionDataSource.js +1 -1
  75. package/lib/esm/src/modules/solana/alt-resolution/data/HttpAltResolutionDataSource.js.map +2 -2
  76. package/lib/esm/src/modules/solana/alt-resolution/domain/AltResolutionContextLoader.js +1 -1
  77. package/lib/esm/src/modules/solana/alt-resolution/domain/AltResolutionContextLoader.js.map +2 -2
  78. package/lib/esm/src/modules/solana/instruction-info/data/HttpInstructionInfoDataSource.js +1 -1
  79. package/lib/esm/src/modules/solana/instruction-info/data/HttpInstructionInfoDataSource.js.map +2 -2
  80. package/lib/esm/src/modules/solana/instruction-info/data/HttpInstructionInfoDataSource.test.js +1 -1
  81. package/lib/esm/src/modules/solana/instruction-info/data/HttpInstructionInfoDataSource.test.js.map +3 -3
  82. package/lib/esm/src/modules/solana/instruction-info/data/InstructionInfoDto.js +1 -1
  83. package/lib/esm/src/modules/solana/instruction-info/data/InstructionInfoDto.js.map +2 -2
  84. package/lib/esm/src/modules/solana/lifi/domain/LifiContextLoader.js +1 -1
  85. package/lib/esm/src/modules/solana/lifi/domain/LifiContextLoader.js.map +3 -3
  86. package/lib/esm/src/modules/solana/lifi/domain/LifiContextLoader.test.js +1 -1
  87. package/lib/esm/src/modules/solana/lifi/domain/LifiContextLoader.test.js.map +3 -3
  88. package/lib/esm/src/modules/solana/model/SolanaPayloads.js.map +2 -2
  89. package/lib/esm/src/modules/solana/owner-info/data/HttpOwnerInfoDataSource.js +1 -1
  90. package/lib/esm/src/modules/solana/owner-info/data/HttpOwnerInfoDataSource.js.map +2 -2
  91. package/lib/esm/src/modules/solana/owner-info/data/HttpOwnerInfoDataSource.test.js +1 -1
  92. package/lib/esm/src/modules/solana/owner-info/data/HttpOwnerInfoDataSource.test.js.map +2 -2
  93. package/lib/esm/src/modules/solana/token/data/HttpMintToIdDataSource.js +2 -0
  94. package/lib/esm/src/modules/solana/token/data/HttpMintToIdDataSource.js.map +7 -0
  95. package/lib/esm/src/modules/solana/token/data/HttpMintToIdDataSource.test.js +2 -0
  96. package/lib/esm/src/modules/solana/token/data/HttpMintToIdDataSource.test.js.map +7 -0
  97. package/lib/esm/src/modules/solana/token/data/MintToIdDataSource.js +1 -0
  98. package/lib/esm/src/modules/solana/token/data/MintToIdDataSource.js.map +7 -0
  99. package/lib/esm/src/modules/solana/token/di/tokenModuleFactory.js +1 -1
  100. package/lib/esm/src/modules/solana/token/di/tokenModuleFactory.js.map +3 -3
  101. package/lib/esm/src/modules/solana/token/di/tokenTypes.js +1 -1
  102. package/lib/esm/src/modules/solana/token/di/tokenTypes.js.map +2 -2
  103. package/lib/esm/src/modules/solana/token/domain/TokenContextLoader.js +1 -1
  104. package/lib/esm/src/modules/solana/token/domain/TokenContextLoader.js.map +3 -3
  105. package/lib/esm/src/modules/solana/token/domain/TokenContextLoader.test.js +1 -1
  106. package/lib/esm/src/modules/solana/token/domain/TokenContextLoader.test.js.map +3 -3
  107. package/lib/esm/src/modules/solana/token-account-state/data/HttpTokenAccountStateDataSource.js +1 -1
  108. package/lib/esm/src/modules/solana/token-account-state/data/HttpTokenAccountStateDataSource.js.map +2 -2
  109. package/lib/esm/src/modules/solana/token-account-state/domain/TokenAccountStateContextLoader.js +1 -1
  110. package/lib/esm/src/modules/solana/token-account-state/domain/TokenAccountStateContextLoader.js.map +3 -3
  111. package/lib/esm/src/modules/solana/token-info/data/HttpTokenInfoDataSource.js +1 -1
  112. package/lib/esm/src/modules/solana/token-info/data/HttpTokenInfoDataSource.js.map +3 -3
  113. package/lib/esm/src/modules/solana/token-info/data/HttpTokenInfoDataSource.test.js +1 -1
  114. package/lib/esm/src/modules/solana/token-info/data/HttpTokenInfoDataSource.test.js.map +2 -2
  115. package/lib/esm/src/modules/solana/trusted-name/data/HttpTrustedNameDataSource.js +1 -1
  116. package/lib/esm/src/modules/solana/trusted-name/data/HttpTrustedNameDataSource.js.map +3 -3
  117. package/lib/esm/src/modules/solana/trusted-name/data/HttpTrustedNameDataSource.test.js +1 -1
  118. package/lib/esm/src/modules/solana/trusted-name/data/HttpTrustedNameDataSource.test.js.map +2 -2
  119. package/lib/esm/src/modules/solana/trusted-name/domain/TrustedNameContextLoader.js +1 -1
  120. package/lib/esm/src/modules/solana/trusted-name/domain/TrustedNameContextLoader.js.map +2 -2
  121. package/lib/esm/src/modules/solana/trusted-name/domain/TrustedNameContextLoader.test.js +1 -1
  122. package/lib/esm/src/modules/solana/trusted-name/domain/TrustedNameContextLoader.test.js.map +2 -2
  123. package/lib/esm/src/shared/utils/deviceModelIdCodec.js +1 -1
  124. package/lib/esm/src/shared/utils/deviceModelIdCodec.js.map +2 -2
  125. package/lib/esm/src/shared/utils/deviceModelIdCodec.test.js +1 -1
  126. package/lib/esm/src/shared/utils/deviceModelIdCodec.test.js.map +2 -2
  127. package/lib/types/src/modules/multichain/transaction-check/loaders/SolanaTransactionCheckLoader.d.ts +0 -12
  128. package/lib/types/src/modules/multichain/transaction-check/loaders/SolanaTransactionCheckLoader.d.ts.map +1 -1
  129. package/lib/types/src/modules/solana/alt-resolution/data/AltResolutionDataSource.d.ts +1 -0
  130. package/lib/types/src/modules/solana/alt-resolution/data/AltResolutionDataSource.d.ts.map +1 -1
  131. package/lib/types/src/modules/solana/alt-resolution/data/HttpAltResolutionDataSource.d.ts.map +1 -1
  132. package/lib/types/src/modules/solana/alt-resolution/domain/AltResolutionContextLoader.d.ts.map +1 -1
  133. package/lib/types/src/modules/solana/instruction-info/data/HttpInstructionInfoDataSource.d.ts.map +1 -1
  134. package/lib/types/src/modules/solana/instruction-info/data/InstructionInfoDto.d.ts +2 -2
  135. package/lib/types/src/modules/solana/instruction-info/data/InstructionInfoDto.d.ts.map +1 -1
  136. package/lib/types/src/modules/solana/lifi/domain/LifiContextLoader.d.ts.map +1 -1
  137. package/lib/types/src/modules/solana/model/SolanaContextTypes.d.ts +5 -1
  138. package/lib/types/src/modules/solana/model/SolanaContextTypes.d.ts.map +1 -1
  139. package/lib/types/src/modules/solana/model/SolanaPayloads.d.ts +5 -1
  140. package/lib/types/src/modules/solana/model/SolanaPayloads.d.ts.map +1 -1
  141. package/lib/types/src/modules/solana/model/SolanaTransactionContext.d.ts +1 -0
  142. package/lib/types/src/modules/solana/model/SolanaTransactionContext.d.ts.map +1 -1
  143. package/lib/types/src/modules/solana/owner-info/data/HttpOwnerInfoDataSource.d.ts.map +1 -1
  144. package/lib/types/src/modules/solana/token/data/HttpMintToIdDataSource.d.ts +11 -0
  145. package/lib/types/src/modules/solana/token/data/HttpMintToIdDataSource.d.ts.map +1 -0
  146. package/lib/types/src/modules/solana/token/data/HttpMintToIdDataSource.test.d.ts +2 -0
  147. package/lib/types/src/modules/solana/token/data/HttpMintToIdDataSource.test.d.ts.map +1 -0
  148. package/lib/types/src/modules/solana/token/data/MintToIdDataSource.d.ts +8 -0
  149. package/lib/types/src/modules/solana/token/data/MintToIdDataSource.d.ts.map +1 -0
  150. package/lib/types/src/modules/solana/token/di/tokenModuleFactory.d.ts.map +1 -1
  151. package/lib/types/src/modules/solana/token/di/tokenTypes.d.ts +1 -0
  152. package/lib/types/src/modules/solana/token/di/tokenTypes.d.ts.map +1 -1
  153. package/lib/types/src/modules/solana/token/domain/TokenContextLoader.d.ts +3 -1
  154. package/lib/types/src/modules/solana/token/domain/TokenContextLoader.d.ts.map +1 -1
  155. package/lib/types/src/modules/solana/token-account-state/data/HttpTokenAccountStateDataSource.d.ts.map +1 -1
  156. package/lib/types/src/modules/solana/token-account-state/data/TokenAccountStateDataSource.d.ts +1 -0
  157. package/lib/types/src/modules/solana/token-account-state/data/TokenAccountStateDataSource.d.ts.map +1 -1
  158. package/lib/types/src/modules/solana/token-account-state/domain/TokenAccountStateContextLoader.d.ts.map +1 -1
  159. package/lib/types/src/modules/solana/token-info/data/HttpTokenInfoDataSource.d.ts.map +1 -1
  160. package/lib/types/src/modules/solana/trusted-name/data/HttpTrustedNameDataSource.d.ts +1 -1
  161. package/lib/types/src/modules/solana/trusted-name/data/HttpTrustedNameDataSource.d.ts.map +1 -1
  162. package/lib/types/src/modules/solana/trusted-name/data/TrustedNameDataSource.d.ts +1 -0
  163. package/lib/types/src/modules/solana/trusted-name/data/TrustedNameDataSource.d.ts.map +1 -1
  164. package/lib/types/src/modules/solana/trusted-name/domain/TrustedNameContextLoader.d.ts +1 -0
  165. package/lib/types/src/modules/solana/trusted-name/domain/TrustedNameContextLoader.d.ts.map +1 -1
  166. package/lib/types/src/shared/utils/deviceModelIdCodec.d.ts +2 -2
  167. package/lib/types/src/shared/utils/deviceModelIdCodec.d.ts.map +1 -1
  168. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  169. package/package.json +4 -4
@@ -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.7.1"
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": "2.3.0"
61
+ "version": "2.4.0"
62
62
  }
@@ -1,2 +1,2 @@
1
- "use strict";var p=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var N=Object.prototype.hasOwnProperty;var O=(a,e)=>{for(var n in e)p(a,n,{get:e[n],enumerable:!0})},_=(a,e,n,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of L(e))!N.call(a,r)&&r!==n&&p(a,r,{get:()=>e[r],enumerable:!(t=m(e,r))||t.enumerable});return a};var v=a=>_(p({},"__esModule",{value:!0}),a),g=(a,e,n,t)=>{for(var r=t>1?void 0:t?m(e,n):e,o=a.length-1,u;o>=0;o--)(u=a[o])&&(r=(t?u(e,n,r):u(r))||r);return t&&r&&p(e,n,r),r},h=(a,e)=>(n,t)=>e(n,t,a);var V={};O(V,{SolanaTransactionCheckLoader:()=>d});module.exports=v(V);var s=require("inversify"),c=require("purify-ts"),y=require("../../../../config/di/configTypes"),T=require("../../../../modules/multichain/pki/di/pkiTypes"),A=require("../../../../modules/multichain/pki/model/KeyUsage"),k=require("../../../../modules/multichain/transaction-check/di/transactionCheckTypes"),x=require("../../../../modules/multichain/transaction-check/utils/constants"),l=require("../../../../shared/model/ClearSignContext"),E=require("../../../../shared/utils/bs58Encoder"),R=require("../../../../shared/utils/deviceModelIdCodec"),I=require("../../../../shared/utils/uint8ArrayCodec");const w=[l.ClearSignContextType.SOLANA_TRANSACTION_CHECK],b=64,f=64,M=128,P=128,U=127,D=7,B=c.Codec.interface({deviceModelId:R.deviceModelIdCodec,transactionCheck:c.Codec.interface({from:c.string,transactionBytes:I.uint8ArrayCodec,chain:c.number})});let d=class{constructor(e,n,t,r=E.DefaultBs58Encoder){this.transactionCheckDataSource=e;this.certificateLoader=n;this.bs58Encoder=r;this.logger=t("SolanaTransactionCheckLoader")}logger;canHandle(e,n){return w.every(t=>n.includes(t))?B.decode(e).caseOf({Left:()=>!1,Right:({transactionCheck:{from:t,transactionBytes:r}})=>t.length>0&&r.length>0}):!1}async load(e){const{from:n,transactionBytes:t,chain:r}=e.transactionCheck;let o;try{o=this.bs58Encoder.encode(this.wrapMessageAsTransaction(t))}catch(i){const C=[{type:l.ClearSignContextType.ERROR,error:i instanceof Error?i:new Error(String(i))}];return this.logger.debug("load result",{data:{result:C}}),C}const S=[await(await this.transactionCheckDataSource.check({path:x.TransactionCheckPaths.SOLANA_TRANSACTION,body:{tx:{from:n,raw:o},chain:r}})).caseOf({Left:i=>Promise.resolve({type:l.ClearSignContextType.ERROR,error:i}),Right:async i=>{const C=await this.certificateLoader.loadCertificate({keyId:i.publicKeyId,keyUsage:A.KeyUsage.TxSimulationSigner,targetDevice:e.deviceModelId});return{type:l.ClearSignContextType.SOLANA_TRANSACTION_CHECK,payload:{descriptor:i.descriptor},certificate:C}}})];return this.logger.debug("load result",{data:{result:S}}),S}wrapMessageAsTransaction(e){const n=this.readNumRequiredSignatures(e),t=this.encodeShortVec(n),r=n*b,o=new Uint8Array(t.length+r+e.length);return o.set(t,0),o.set(e,t.length+r),o}readNumRequiredSignatures(e){const n=e[0];if(n===void 0)throw new Error("[ContextModule] SolanaTransactionCheckLoader: empty transaction bytes");const r=(n&M)!==0?1:0,o=e[r];if(o===void 0)throw new Error("[ContextModule] SolanaTransactionCheckLoader: malformed message header");if(o>f)throw new Error(`[ContextModule] SolanaTransactionCheckLoader: numRequiredSignatures (${o}) exceeds SOLANA_MAX_SIGNATURES (${f})`);return o}encodeShortVec(e){const n=[];let t=e;for(;;){const r=t&U;if(t>>>=D,t===0){n.push(r);break}n.push(r|P)}return Uint8Array.from(n)}};d=g([(0,s.injectable)(),h(0,(0,s.inject)(k.transactionCheckTypes.TransactionCheckDataSource)),h(1,(0,s.inject)(T.pkiTypes.PkiCertificateLoader)),h(2,(0,s.inject)(y.configTypes.ContextModuleLoggerFactory))],d);0&&(module.exports={SolanaTransactionCheckLoader});
1
+ "use strict";var p=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var P=Object.prototype.hasOwnProperty;var b=(a,e)=>{for(var o in e)p(a,o,{get:e[o],enumerable:!0})},R=(a,e,o,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of L(e))!P.call(a,t)&&t!==o&&p(a,t,{get:()=>e[t],enumerable:!(r=f(e,t))||r.enumerable});return a};var D=a=>R(p({},"__esModule",{value:!0}),a),g=(a,e,o,r)=>{for(var t=r>1?void 0:r?f(e,o):e,c=a.length-1,C;c>=0;c--)(C=a[c])&&(t=(r?C(e,o,t):C(t))||t);return r&&t&&p(e,o,t),t},l=(a,e)=>(o,r)=>e(o,r,a);var N={};b(N,{SolanaTransactionCheckLoader:()=>s});module.exports=D(N);var i=require("inversify"),n=require("purify-ts"),y=require("../../../../config/di/configTypes"),u=require("../../../../modules/multichain/pki/di/pkiTypes"),k=require("../../../../modules/multichain/pki/model/KeyUsage"),S=require("../../../../modules/multichain/transaction-check/di/transactionCheckTypes"),T=require("../../../../modules/multichain/transaction-check/utils/constants"),m=require("../../../../shared/model/ClearSignContext"),x=require("../../../../shared/utils/bs58Encoder"),v=require("../../../../shared/utils/deviceModelIdCodec"),I=require("../../../../shared/utils/uint8ArrayCodec");const E=[m.ClearSignContextType.SOLANA_TRANSACTION_CHECK],O=n.Codec.interface({deviceModelId:v.deviceModelIdCodec,transactionCheck:n.Codec.interface({from:n.string,transactionBytes:I.uint8ArrayCodec,chain:n.number})});let s=class{constructor(e,o,r,t=x.DefaultBs58Encoder){this.transactionCheckDataSource=e;this.certificateLoader=o;this.bs58Encoder=t;this.logger=r("SolanaTransactionCheckLoader")}logger;canHandle(e,o){return E.every(r=>o.includes(r))?O.decode(e).caseOf({Left:()=>!1,Right:({transactionCheck:{from:r,transactionBytes:t}})=>r.length>0&&t.length>0}):!1}async load(e){const{from:o,transactionBytes:r,chain:t}=e.transactionCheck,c=this.bs58Encoder.encode(r),h=[await(await this.transactionCheckDataSource.check({path:T.TransactionCheckPaths.SOLANA_TRANSACTION,body:{tx:{from:o,raw:c},chain:t}})).caseOf({Left:d=>Promise.resolve({type:m.ClearSignContextType.ERROR,error:d}),Right:async d=>{const A=await this.certificateLoader.loadCertificate({keyId:d.publicKeyId,keyUsage:k.KeyUsage.TxSimulationSigner,targetDevice:e.deviceModelId});return{type:m.ClearSignContextType.SOLANA_TRANSACTION_CHECK,payload:{descriptor:d.descriptor},certificate:A}}})];return this.logger.debug("load result",{data:{result:h}}),h}};s=g([(0,i.injectable)(),l(0,(0,i.inject)(S.transactionCheckTypes.TransactionCheckDataSource)),l(1,(0,i.inject)(u.pkiTypes.PkiCertificateLoader)),l(2,(0,i.inject)(y.configTypes.ContextModuleLoggerFactory))],s);0&&(module.exports={SolanaTransactionCheckLoader});
2
2
  //# sourceMappingURL=SolanaTransactionCheckLoader.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/modules/multichain/transaction-check/loaders/SolanaTransactionCheckLoader.ts"],
4
- "sourcesContent": ["import {\n type DeviceModelId,\n LoggerPublisherService,\n} from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\nimport { Codec, number, string } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { pkiTypes } from \"@/modules/multichain/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/modules/multichain/pki/domain/PkiCertificateLoader\";\nimport { KeyUsage } from \"@/modules/multichain/pki/model/KeyUsage\";\nimport { type TransactionCheckDataSource } from \"@/modules/multichain/transaction-check/data/TransactionCheckDataSource\";\nimport { transactionCheckTypes } from \"@/modules/multichain/transaction-check/di/transactionCheckTypes\";\nimport { type TransactionCheckLoader } from \"@/modules/multichain/transaction-check/loaders/TransactionCheckLoader\";\nimport { TransactionCheckPaths } from \"@/modules/multichain/transaction-check/utils/constants\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport {\n type Bs58Encoder,\n DefaultBs58Encoder,\n} from \"@/shared/utils/bs58Encoder\";\nimport { deviceModelIdCodec } from \"@/shared/utils/deviceModelIdCodec\";\nimport { uint8ArrayCodec } from \"@/shared/utils/uint8ArrayCodec\";\n\nexport type SolanaTransactionCheckRequest = {\n from: string;\n transactionBytes: Uint8Array;\n chain: number;\n};\n\nexport type SolanaTransactionCheckContextInput = {\n deviceModelId: DeviceModelId;\n transactionCheck: SolanaTransactionCheckRequest;\n};\n\nconst SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.SOLANA_TRANSACTION_CHECK,\n];\n\nconst SOLANA_SIGNATURE_LENGTH = 64;\nconst SOLANA_MAX_SIGNATURES = 64;\nconst VERSIONED_MESSAGE_PREFIX_MASK = 0x80;\nconst SHORTVEC_CONTINUATION_BIT = 0x80;\nconst SHORTVEC_DATA_MASK = 0x7f;\nconst SHORTVEC_DATA_BITS = 7;\n\nconst solanaTransactionCheckInputCodec = Codec.interface({\n deviceModelId: deviceModelIdCodec,\n transactionCheck: Codec.interface({\n from: string,\n transactionBytes: uint8ArrayCodec,\n chain: number,\n }),\n});\n\n@injectable()\nexport class SolanaTransactionCheckLoader\n implements TransactionCheckLoader<SolanaTransactionCheckContextInput>\n{\n private readonly logger: LoggerPublisherService;\n\n constructor(\n @inject(transactionCheckTypes.TransactionCheckDataSource)\n private readonly transactionCheckDataSource: TransactionCheckDataSource,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly certificateLoader: PkiCertificateLoader,\n @inject(configTypes.ContextModuleLoggerFactory)\n loggerFactory: (tag: string) => LoggerPublisherService,\n private readonly bs58Encoder: Bs58Encoder = DefaultBs58Encoder,\n ) {\n this.logger = loggerFactory(\"SolanaTransactionCheckLoader\");\n }\n\n canHandle(\n input: unknown,\n expectedType: ClearSignContextType[],\n ): input is SolanaTransactionCheckContextInput {\n if (!SUPPORTED_TYPES.every((type) => expectedType.includes(type)))\n return false;\n return solanaTransactionCheckInputCodec.decode(input).caseOf({\n Left: () => false,\n Right: ({ transactionCheck: { from, transactionBytes } }) =>\n from.length > 0 && transactionBytes.length > 0,\n });\n }\n\n async load(\n ctx: SolanaTransactionCheckContextInput,\n ): Promise<ClearSignContext[]> {\n const { from, transactionBytes, chain } = ctx.transactionCheck;\n\n let rawTx: string;\n try {\n rawTx = this.bs58Encoder.encode(\n this.wrapMessageAsTransaction(transactionBytes),\n );\n } catch (error) {\n const result: ClearSignContext[] = [\n {\n type: ClearSignContextType.ERROR,\n error: error instanceof Error ? error : new Error(String(error)),\n },\n ];\n this.logger.debug(\"load result\", { data: { result } });\n return result;\n }\n\n const txCheck = await this.transactionCheckDataSource.check({\n path: TransactionCheckPaths.SOLANA_TRANSACTION,\n body: { tx: { from, raw: rawTx }, chain },\n });\n\n const context = await txCheck.caseOf<Promise<ClearSignContext>>({\n Left: (error) =>\n Promise.resolve({\n type: ClearSignContextType.ERROR,\n error,\n }),\n Right: async (data) => {\n const certificate = await this.certificateLoader.loadCertificate({\n keyId: data.publicKeyId,\n keyUsage: KeyUsage.TxSimulationSigner,\n targetDevice: ctx.deviceModelId,\n });\n\n return {\n type: ClearSignContextType.SOLANA_TRANSACTION_CHECK,\n payload: { descriptor: data.descriptor },\n certificate,\n };\n },\n });\n\n const result = [context];\n this.logger.debug(\"load result\", { data: { result } });\n return result;\n }\n\n /**\n * Wrap a serialized Solana Message into a serialized Transaction expected\n * by the web3checks endpoint, by prepending a compact-u16 signature count\n * and the matching number of zero-filled signature placeholders.\n *\n * Supports legacy and versioned messages: versioned messages start with a\n * version prefix byte (high bit set), shifting `numRequiredSignatures` by\n * one position.\n */\n private wrapMessageAsTransaction(message: Uint8Array): Uint8Array {\n const numRequiredSignatures = this.readNumRequiredSignatures(message);\n const sigCount = this.encodeShortVec(numRequiredSignatures);\n const placeholdersLength = numRequiredSignatures * SOLANA_SIGNATURE_LENGTH;\n\n const wrapped = new Uint8Array(\n sigCount.length + placeholdersLength + message.length,\n );\n wrapped.set(sigCount, 0);\n wrapped.set(message, sigCount.length + placeholdersLength);\n return wrapped;\n }\n\n private readNumRequiredSignatures(message: Uint8Array): number {\n const firstByte = message[0];\n if (firstByte === undefined) {\n throw new Error(\n \"[ContextModule] SolanaTransactionCheckLoader: empty transaction bytes\",\n );\n }\n const isVersioned = (firstByte & VERSIONED_MESSAGE_PREFIX_MASK) !== 0;\n const headerOffset = isVersioned ? 1 : 0;\n const numRequiredSignatures = message[headerOffset];\n if (numRequiredSignatures === undefined) {\n throw new Error(\n \"[ContextModule] SolanaTransactionCheckLoader: malformed message header\",\n );\n }\n if (numRequiredSignatures > SOLANA_MAX_SIGNATURES) {\n throw new Error(\n `[ContextModule] SolanaTransactionCheckLoader: numRequiredSignatures (${numRequiredSignatures}) exceeds SOLANA_MAX_SIGNATURES (${SOLANA_MAX_SIGNATURES})`,\n );\n }\n return numRequiredSignatures;\n }\n\n private encodeShortVec(value: number): Uint8Array {\n const bytes: number[] = [];\n let remaining = value;\n while (true) {\n const lowBits = remaining & SHORTVEC_DATA_MASK;\n remaining >>>= SHORTVEC_DATA_BITS;\n if (remaining === 0) {\n bytes.push(lowBits);\n break;\n }\n bytes.push(lowBits | SHORTVEC_CONTINUATION_BIT);\n }\n return Uint8Array.from(bytes);\n }\n}\n"],
5
- "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kCAAAE,IAAA,eAAAC,EAAAH,GAIA,IAAAI,EAAmC,qBACnCC,EAAsC,qBAEtCC,EAA4B,mCAC5BC,EAAyB,gDAEzBC,EAAyB,mDAEzBC,EAAsC,2EAEtCC,EAAsC,kEACtCC,EAGO,2CACPC,EAGO,sCACPC,EAAmC,6CACnCC,EAAgC,0CAahC,MAAMC,EAA0C,CAC9C,uBAAqB,wBACvB,EAEMC,EAA0B,GAC1BC,EAAwB,GACxBC,EAAgC,IAChCC,EAA4B,IAC5BC,EAAqB,IACrBC,EAAqB,EAErBC,EAAmC,QAAM,UAAU,CACvD,cAAe,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IazB,EAAN4B,EAAA,IADN,cAAW,EAOPC,EAAA,eAAO,wBAAsB,0BAA0B,GAEvDA,EAAA,eAAO,WAAS,oBAAoB,GAEpCA,EAAA,eAAO,cAAY,0BAA0B,IAVrC7B",
6
- "names": ["SolanaTransactionCheckLoader_exports", "__export", "SolanaTransactionCheckLoader", "__toCommonJS", "import_inversify", "import_purify_ts", "import_configTypes", "import_pkiTypes", "import_KeyUsage", "import_transactionCheckTypes", "import_constants", "import_ClearSignContext", "import_bs58Encoder", "import_deviceModelIdCodec", "import_uint8ArrayCodec", "SUPPORTED_TYPES", "SOLANA_SIGNATURE_LENGTH", "SOLANA_MAX_SIGNATURES", "VERSIONED_MESSAGE_PREFIX_MASK", "SHORTVEC_CONTINUATION_BIT", "SHORTVEC_DATA_MASK", "SHORTVEC_DATA_BITS", "solanaTransactionCheckInputCodec", "SolanaTransactionCheckLoader", "transactionCheckDataSource", "certificateLoader", "loggerFactory", "bs58Encoder", "input", "expectedType", "type", "from", "transactionBytes", "ctx", "chain", "rawTx", "error", "result", "data", "certificate", "message", "numRequiredSignatures", "sigCount", "placeholdersLength", "wrapped", "firstByte", "headerOffset", "value", "bytes", "remaining", "lowBits", "__decorateClass", "__decorateParam"]
4
+ "sourcesContent": ["import {\n type DeviceModelId,\n LoggerPublisherService,\n} from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\nimport { Codec, number, string } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { pkiTypes } from \"@/modules/multichain/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/modules/multichain/pki/domain/PkiCertificateLoader\";\nimport { KeyUsage } from \"@/modules/multichain/pki/model/KeyUsage\";\nimport { type TransactionCheckDataSource } from \"@/modules/multichain/transaction-check/data/TransactionCheckDataSource\";\nimport { transactionCheckTypes } from \"@/modules/multichain/transaction-check/di/transactionCheckTypes\";\nimport { type TransactionCheckLoader } from \"@/modules/multichain/transaction-check/loaders/TransactionCheckLoader\";\nimport { TransactionCheckPaths } from \"@/modules/multichain/transaction-check/utils/constants\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport {\n type Bs58Encoder,\n DefaultBs58Encoder,\n} from \"@/shared/utils/bs58Encoder\";\nimport { deviceModelIdCodec } from \"@/shared/utils/deviceModelIdCodec\";\nimport { uint8ArrayCodec } from \"@/shared/utils/uint8ArrayCodec\";\n\nexport type SolanaTransactionCheckRequest = {\n from: string;\n transactionBytes: Uint8Array;\n chain: number;\n};\n\nexport type SolanaTransactionCheckContextInput = {\n deviceModelId: DeviceModelId;\n transactionCheck: SolanaTransactionCheckRequest;\n};\n\nconst SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.SOLANA_TRANSACTION_CHECK,\n];\n\nconst solanaTransactionCheckInputCodec = Codec.interface({\n deviceModelId: deviceModelIdCodec,\n transactionCheck: Codec.interface({\n from: string,\n transactionBytes: uint8ArrayCodec,\n chain: number,\n }),\n});\n\n@injectable()\nexport class SolanaTransactionCheckLoader\n implements TransactionCheckLoader<SolanaTransactionCheckContextInput>\n{\n private readonly logger: LoggerPublisherService;\n\n constructor(\n @inject(transactionCheckTypes.TransactionCheckDataSource)\n private readonly transactionCheckDataSource: TransactionCheckDataSource,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly certificateLoader: PkiCertificateLoader,\n @inject(configTypes.ContextModuleLoggerFactory)\n loggerFactory: (tag: string) => LoggerPublisherService,\n private readonly bs58Encoder: Bs58Encoder = DefaultBs58Encoder,\n ) {\n this.logger = loggerFactory(\"SolanaTransactionCheckLoader\");\n }\n\n canHandle(\n input: unknown,\n expectedType: ClearSignContextType[],\n ): input is SolanaTransactionCheckContextInput {\n if (!SUPPORTED_TYPES.every((type) => expectedType.includes(type)))\n return false;\n return solanaTransactionCheckInputCodec.decode(input).caseOf({\n Left: () => false,\n Right: ({ transactionCheck: { from, transactionBytes } }) =>\n from.length > 0 && transactionBytes.length > 0,\n });\n }\n\n async load(\n ctx: SolanaTransactionCheckContextInput,\n ): Promise<ClearSignContext[]> {\n const { from, transactionBytes, chain } = ctx.transactionCheck;\n\n const rawTx = this.bs58Encoder.encode(transactionBytes);\n\n const txCheck = await this.transactionCheckDataSource.check({\n path: TransactionCheckPaths.SOLANA_TRANSACTION,\n body: { tx: { from, raw: rawTx }, chain },\n });\n\n const context = await txCheck.caseOf<Promise<ClearSignContext>>({\n Left: (error) =>\n Promise.resolve({\n type: ClearSignContextType.ERROR,\n error,\n }),\n Right: async (data) => {\n const certificate = await this.certificateLoader.loadCertificate({\n keyId: data.publicKeyId,\n keyUsage: KeyUsage.TxSimulationSigner,\n targetDevice: ctx.deviceModelId,\n });\n\n return {\n type: ClearSignContextType.SOLANA_TRANSACTION_CHECK,\n payload: { descriptor: data.descriptor },\n certificate,\n };\n },\n });\n\n const result = [context];\n this.logger.debug(\"load result\", { data: { result } });\n return result;\n }\n}\n"],
5
+ "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kCAAAE,IAAA,eAAAC,EAAAH,GAIA,IAAAI,EAAmC,qBACnCC,EAAsC,qBAEtCC,EAA4B,mCAC5BC,EAAyB,gDAEzBC,EAAyB,mDAEzBC,EAAsC,2EAEtCC,EAAsC,kEACtCC,EAGO,2CACPC,EAGO,sCACPC,EAAmC,6CACnCC,EAAgC,0CAahC,MAAMC,EAA0C,CAC9C,uBAAqB,wBACvB,EAEMC,EAAmC,QAAM,UAAU,CACvD,cAAe,qBACf,iBAAkB,QAAM,UAAU,CAChC,KAAM,SACN,iBAAkB,kBAClB,MAAO,QACT,CAAC,CACH,CAAC,EAGM,IAAMC,EAAN,KAEP,CAGE,YAEmBC,EAEAC,EAEjBC,EACiBC,EAA2B,qBAC5C,CANiB,gCAAAH,EAEA,uBAAAC,EAGA,iBAAAE,EAEjB,KAAK,OAASD,EAAc,8BAA8B,CAC5D,CAZiB,OAcjB,UACEE,EACAC,EAC6C,CAC7C,OAAKR,EAAgB,MAAOS,GAASD,EAAa,SAASC,CAAI,CAAC,EAEzDR,EAAiC,OAAOM,CAAK,EAAE,OAAO,CAC3D,KAAM,IAAM,GACZ,MAAO,CAAC,CAAE,iBAAkB,CAAE,KAAAG,EAAM,iBAAAC,CAAiB,CAAE,IACrDD,EAAK,OAAS,GAAKC,EAAiB,OAAS,CACjD,CAAC,EALQ,EAMX,CAEA,MAAM,KACJC,EAC6B,CAC7B,KAAM,CAAE,KAAAF,EAAM,iBAAAC,EAAkB,MAAAE,CAAM,EAAID,EAAI,iBAExCE,EAAQ,KAAK,YAAY,OAAOH,CAAgB,EA4BhDI,EAAS,CArBC,MALA,MAAM,KAAK,2BAA2B,MAAM,CAC1D,KAAM,wBAAsB,mBAC5B,KAAM,CAAE,GAAI,CAAE,KAAAL,EAAM,IAAKI,CAAM,EAAG,MAAAD,CAAM,CAC1C,CAAC,GAE6B,OAAkC,CAC9D,KAAOG,GACL,QAAQ,QAAQ,CACd,KAAM,uBAAqB,MAC3B,MAAAA,CACF,CAAC,EACH,MAAO,MAAOC,GAAS,CACrB,MAAMC,EAAc,MAAM,KAAK,kBAAkB,gBAAgB,CAC/D,MAAOD,EAAK,YACZ,SAAU,WAAS,mBACnB,aAAcL,EAAI,aACpB,CAAC,EAED,MAAO,CACL,KAAM,uBAAqB,yBAC3B,QAAS,CAAE,WAAYK,EAAK,UAAW,EACvC,YAAAC,CACF,CACF,CACF,CAAC,CAEsB,EACvB,YAAK,OAAO,MAAM,cAAe,CAAE,KAAM,CAAE,OAAAH,CAAO,CAAE,CAAC,EAC9CA,CACT,CACF,EAnEab,EAANiB,EAAA,IADN,cAAW,EAOPC,EAAA,eAAO,wBAAsB,0BAA0B,GAEvDA,EAAA,eAAO,WAAS,oBAAoB,GAEpCA,EAAA,eAAO,cAAY,0BAA0B,IAVrClB",
6
+ "names": ["SolanaTransactionCheckLoader_exports", "__export", "SolanaTransactionCheckLoader", "__toCommonJS", "import_inversify", "import_purify_ts", "import_configTypes", "import_pkiTypes", "import_KeyUsage", "import_transactionCheckTypes", "import_constants", "import_ClearSignContext", "import_bs58Encoder", "import_deviceModelIdCodec", "import_uint8ArrayCodec", "SUPPORTED_TYPES", "solanaTransactionCheckInputCodec", "SolanaTransactionCheckLoader", "transactionCheckDataSource", "certificateLoader", "loggerFactory", "bs58Encoder", "input", "expectedType", "type", "from", "transactionBytes", "ctx", "chain", "rawTx", "result", "error", "data", "certificate", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var h=Object.create;var f=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var u=(e,t,a,p)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of m(t))!k.call(e,s)&&s!==a&&f(e,s,{get:()=>t[s],enumerable:!(p=C(t,s))||p.enumerable});return e};var w=(e,t,a)=>(a=e!=null?h(x(e)):{},u(t||!e||!e.__esModule?f(a,"default",{value:e,enumerable:!0}):a,e));var c=require("@ledgerhq/device-management-kit"),l=w(require("bs58")),d=require("purify-ts"),N=require("../../../../modules/multichain/transaction-check/utils/constants"),i=require("../../../../modules/solana/model/SolanaTransactionScanChainId"),r=require("../../../../shared/model/ClearSignContext"),y=require("./SolanaTransactionCheckLoader");const S={debug:vi.fn(),info:vi.fn(),warn:vi.fn(),error:vi.fn(),subscribers:[]},T=()=>S,A={loadCertificate:vi.fn()};let o,n;beforeEach(()=>{vi.resetAllMocks(),o={check:vi.fn()},n=new y.SolanaTransactionCheckLoader(o,A,T)});describe("SolanaTransactionCheckLoader",()=>{describe("canHandle",()=>{const e={deviceModelId:c.DeviceModelId.NANO_X,transactionCheck:{from:"signer",transactionBytes:new Uint8Array([1,0,3,222]),chain:1}};it("returns true for a valid Solana transaction-check input",()=>{expect(n.canHandle(e,[r.ClearSignContextType.SOLANA_TRANSACTION_CHECK])).toBe(!0)}),it("returns false when expected types do not include SOLANA_TRANSACTION_CHECK",()=>{expect(n.canHandle(e,[r.ClearSignContextType.SOLANA_TOKEN])).toBe(!1)}),it("returns false when transactionBytes is not a Uint8Array",()=>{expect(n.canHandle({...e,transactionCheck:{...e.transactionCheck,transactionBytes:"0xdead"}},[r.ClearSignContextType.SOLANA_TRANSACTION_CHECK])).toBe(!1)}),it("returns false when transactionBytes is empty",()=>{expect(n.canHandle({...e,transactionCheck:{...e.transactionCheck,transactionBytes:new Uint8Array}},[r.ClearSignContextType.SOLANA_TRANSACTION_CHECK])).toBe(!1)}),it("returns false when from is empty",()=>{expect(n.canHandle({...e,transactionCheck:{...e.transactionCheck,from:""}},[r.ClearSignContextType.SOLANA_TRANSACTION_CHECK])).toBe(!1)}),it("returns false for unsupported device models (NANO_S)",()=>{expect(n.canHandle({...e,deviceModelId:c.DeviceModelId.NANO_S},[r.ClearSignContextType.SOLANA_TRANSACTION_CHECK])).toBe(!1)})}),describe("load \u2014 wire format",()=>{beforeEach(()=>{o.check.mockResolvedValue((0,d.Right)({publicKeyId:"pk",descriptor:"aabb"})),A.loadCertificate.mockResolvedValue({payload:new Uint8Array([204]),keyUsageNumber:14})}),it("wraps a legacy message with zero-filled signature placeholders before bs58-encoding",async()=>{const e=new Uint8Array([2,0,3,170,187,204]),t=new Uint8Array(1+2*64+e.length);t[0]=2,t.set(e,1+2*64),await n.load({deviceModelId:c.DeviceModelId.NANO_X,transactionCheck:{from:"signer",transactionBytes:e,chain:i.SolanaTransactionScanChainId.MAINNET}});const a=o.check.mock.calls[0][0];expect(a.path).toBe(N.TransactionCheckPaths.SOLANA_TRANSACTION),expect(a.body.tx.from).toBe("signer"),expect(a.body.chain).toBe(i.SolanaTransactionScanChainId.MAINNET),expect(Array.from(l.default.decode(a.body.tx.raw))).toEqual(Array.from(t)),expect(a.body.tx.raw).toBe(l.default.encode(t))}),it("wraps a versioned (v0) message with signature placeholders",async()=>{const e=new Uint8Array([128,1,0,3,222,173]),t=new Uint8Array(1+1*64+e.length);t[0]=1,t.set(e,1+1*64),await n.load({deviceModelId:c.DeviceModelId.NANO_X,transactionCheck:{from:"signer",transactionBytes:e,chain:i.SolanaTransactionScanChainId.MAINNET}});const a=o.check.mock.calls[0][0].body.tx.raw;expect(Array.from(l.default.decode(a))).toEqual(Array.from(t))})}),describe("load \u2014 result mapping",()=>{it("returns a SOLANA_TRANSACTION_CHECK context with descriptor and certificate on success",async()=>{o.check.mockResolvedValue((0,d.Right)({publicKeyId:"pk-1",descriptor:"deadbeef"}));const e={payload:new Uint8Array([153]),keyUsageNumber:14};A.loadCertificate.mockResolvedValue(e);const[t]=await n.load({deviceModelId:c.DeviceModelId.NANO_X,transactionCheck:{from:"signer",transactionBytes:new Uint8Array([1,0,3,170]),chain:i.SolanaTransactionScanChainId.MAINNET}});expect(t).toEqual({type:r.ClearSignContextType.SOLANA_TRANSACTION_CHECK,payload:{descriptor:"deadbeef"},certificate:e})}),it("returns an ERROR context when the data source returns Left",async()=>{const e=new Error("network fail");o.check.mockResolvedValue((0,d.Left)(e));const[t]=await n.load({deviceModelId:c.DeviceModelId.NANO_X,transactionCheck:{from:"signer",transactionBytes:new Uint8Array([1,0,3,170]),chain:i.SolanaTransactionScanChainId.MAINNET}});expect(t).toEqual({type:r.ClearSignContextType.ERROR,error:e}),expect(A.loadCertificate).not.toHaveBeenCalled()}),it("returns an ERROR context when numRequiredSignatures exceeds the 64-signature limit",async()=>{const e=new Uint8Array([65,0,3,170]),[t]=await n.load({deviceModelId:c.DeviceModelId.NANO_X,transactionCheck:{from:"signer",transactionBytes:e,chain:i.SolanaTransactionScanChainId.MAINNET}});expect(t).toMatchObject({type:r.ClearSignContextType.ERROR,error:expect.objectContaining({message:expect.stringContaining("exceeds SOLANA_MAX_SIGNATURES")})}),expect(o.check).not.toHaveBeenCalled()})})});
1
+ "use strict";var y=Object.create;var f=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty;var T=(e,a,r,A)=>{if(a&&typeof a=="object"||typeof a=="function")for(let i of k(a))!m.call(e,i)&&i!==r&&f(e,i,{get:()=>a[i],enumerable:!(A=h(a,i))||A.enumerable});return e};var x=(e,a,r)=>(r=e!=null?y(u(e)):{},T(a||!e||!e.__esModule?f(r,"default",{value:e,enumerable:!0}):r,e));var o=require("@ledgerhq/device-management-kit"),p=x(require("bs58")),d=require("purify-ts"),C=require("../../../../modules/multichain/transaction-check/utils/constants"),s=require("../../../../modules/solana/model/SolanaTransactionScanChainId"),n=require("../../../../shared/model/ClearSignContext"),N=require("./SolanaTransactionCheckLoader");const S={debug:vi.fn(),info:vi.fn(),warn:vi.fn(),error:vi.fn(),subscribers:[]},O=()=>S,l={loadCertificate:vi.fn()};let c,t;beforeEach(()=>{vi.resetAllMocks(),c={check:vi.fn()},t=new N.SolanaTransactionCheckLoader(c,l,O)});describe("SolanaTransactionCheckLoader",()=>{describe("canHandle",()=>{const e={deviceModelId:o.DeviceModelId.NANO_X,transactionCheck:{from:"signer",transactionBytes:new Uint8Array([1,0,3,222]),chain:1}};it("returns true for a valid Solana transaction-check input",()=>{expect(t.canHandle(e,[n.ClearSignContextType.SOLANA_TRANSACTION_CHECK])).toBe(!0)}),it("returns false when expected types do not include SOLANA_TRANSACTION_CHECK",()=>{expect(t.canHandle(e,[n.ClearSignContextType.SOLANA_TOKEN])).toBe(!1)}),it("returns false when transactionBytes is not a Uint8Array",()=>{expect(t.canHandle({...e,transactionCheck:{...e.transactionCheck,transactionBytes:"0xdead"}},[n.ClearSignContextType.SOLANA_TRANSACTION_CHECK])).toBe(!1)}),it("returns false when transactionBytes is empty",()=>{expect(t.canHandle({...e,transactionCheck:{...e.transactionCheck,transactionBytes:new Uint8Array}},[n.ClearSignContextType.SOLANA_TRANSACTION_CHECK])).toBe(!1)}),it("returns false when from is empty",()=>{expect(t.canHandle({...e,transactionCheck:{...e.transactionCheck,from:""}},[n.ClearSignContextType.SOLANA_TRANSACTION_CHECK])).toBe(!1)}),it("returns false for unsupported device models (NANO_S)",()=>{expect(t.canHandle({...e,deviceModelId:o.DeviceModelId.NANO_S},[n.ClearSignContextType.SOLANA_TRANSACTION_CHECK])).toBe(!1)})}),describe("load \u2014 wire format",()=>{beforeEach(()=>{c.check.mockResolvedValue((0,d.Right)({publicKeyId:"pk",descriptor:"aabb"})),l.loadCertificate.mockResolvedValue({payload:new Uint8Array([204]),keyUsageNumber:14})}),it("bs58-encodes transactionBytes and passes it to the data source",async()=>{const e=new Uint8Array([170,187,204,221]);await t.load({deviceModelId:o.DeviceModelId.NANO_X,transactionCheck:{from:"signer",transactionBytes:e,chain:s.SolanaTransactionScanChainId.MAINNET}});const a=c.check.mock.calls[0][0];expect(a.path).toBe(C.TransactionCheckPaths.SOLANA_TRANSACTION),expect(a.body.tx.from).toBe("signer"),expect(a.body.chain).toBe(s.SolanaTransactionScanChainId.MAINNET),expect(a.body.tx.raw).toBe(p.default.encode(e))})}),describe("load \u2014 result mapping",()=>{it("returns a SOLANA_TRANSACTION_CHECK context with descriptor and certificate on success",async()=>{c.check.mockResolvedValue((0,d.Right)({publicKeyId:"pk-1",descriptor:"deadbeef"}));const e={payload:new Uint8Array([153]),keyUsageNumber:14};l.loadCertificate.mockResolvedValue(e);const[a]=await t.load({deviceModelId:o.DeviceModelId.NANO_X,transactionCheck:{from:"signer",transactionBytes:new Uint8Array([1,0,3,170]),chain:s.SolanaTransactionScanChainId.MAINNET}});expect(a).toEqual({type:n.ClearSignContextType.SOLANA_TRANSACTION_CHECK,payload:{descriptor:"deadbeef"},certificate:e})}),it("returns an ERROR context when the data source returns Left",async()=>{const e=new Error("network fail");c.check.mockResolvedValue((0,d.Left)(e));const[a]=await t.load({deviceModelId:o.DeviceModelId.NANO_X,transactionCheck:{from:"signer",transactionBytes:new Uint8Array([1,0,3,170]),chain:s.SolanaTransactionScanChainId.MAINNET}});expect(a).toEqual({type:n.ClearSignContextType.ERROR,error:e}),expect(l.loadCertificate).not.toHaveBeenCalled()})})});
2
2
  //# sourceMappingURL=SolanaTransactionCheckLoader.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/modules/multichain/transaction-check/loaders/SolanaTransactionCheckLoader.test.ts"],
4
- "sourcesContent": ["/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport bs58 from \"bs58\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type PkiCertificateLoader } from \"@/modules/multichain/pki/domain/PkiCertificateLoader\";\nimport { type TransactionCheckDataSource } from \"@/modules/multichain/transaction-check/data/TransactionCheckDataSource\";\nimport { TransactionCheckPaths } from \"@/modules/multichain/transaction-check/utils/constants\";\nimport { SolanaTransactionScanChainId } from \"@/modules/solana/model/SolanaTransactionScanChainId\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\n\nimport { SolanaTransactionCheckLoader } from \"./SolanaTransactionCheckLoader\";\n\nconst loggerMock = {\n debug: vi.fn(),\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n subscribers: [],\n};\nconst loggerFactory = () => loggerMock;\n\nconst certificateLoaderMock: PkiCertificateLoader = {\n loadCertificate: vi.fn(),\n};\n\nlet dataSourceMock: { check: ReturnType<typeof vi.fn> };\nlet loader: SolanaTransactionCheckLoader;\n\nbeforeEach(() => {\n vi.resetAllMocks();\n dataSourceMock = { check: vi.fn() };\n loader = new SolanaTransactionCheckLoader(\n dataSourceMock as unknown as TransactionCheckDataSource,\n certificateLoaderMock,\n loggerFactory,\n );\n});\n\ndescribe(\"SolanaTransactionCheckLoader\", () => {\n describe(\"canHandle\", () => {\n const validInput = {\n deviceModelId: DeviceModelId.NANO_X,\n transactionCheck: {\n from: \"signer\",\n transactionBytes: new Uint8Array([1, 0, 3, 0xde]),\n chain: 1,\n },\n };\n\n it(\"returns true for a valid Solana transaction-check input\", () => {\n expect(\n loader.canHandle(validInput, [\n ClearSignContextType.SOLANA_TRANSACTION_CHECK,\n ]),\n ).toBe(true);\n });\n\n it(\"returns false when expected types do not include SOLANA_TRANSACTION_CHECK\", () => {\n expect(\n loader.canHandle(validInput, [ClearSignContextType.SOLANA_TOKEN]),\n ).toBe(false);\n });\n\n it(\"returns false when transactionBytes is not a Uint8Array\", () => {\n expect(\n loader.canHandle(\n {\n ...validInput,\n transactionCheck: {\n ...validInput.transactionCheck,\n transactionBytes: \"0xdead\" as unknown as Uint8Array,\n },\n },\n [ClearSignContextType.SOLANA_TRANSACTION_CHECK],\n ),\n ).toBe(false);\n });\n\n it(\"returns false when transactionBytes is empty\", () => {\n expect(\n loader.canHandle(\n {\n ...validInput,\n transactionCheck: {\n ...validInput.transactionCheck,\n transactionBytes: new Uint8Array(),\n },\n },\n [ClearSignContextType.SOLANA_TRANSACTION_CHECK],\n ),\n ).toBe(false);\n });\n\n it(\"returns false when from is empty\", () => {\n expect(\n loader.canHandle(\n {\n ...validInput,\n transactionCheck: { ...validInput.transactionCheck, from: \"\" },\n },\n [ClearSignContextType.SOLANA_TRANSACTION_CHECK],\n ),\n ).toBe(false);\n });\n\n it(\"returns false for unsupported device models (NANO_S)\", () => {\n expect(\n loader.canHandle(\n { ...validInput, deviceModelId: DeviceModelId.NANO_S },\n [ClearSignContextType.SOLANA_TRANSACTION_CHECK],\n ),\n ).toBe(false);\n });\n });\n\n describe(\"load \u2014 wire format\", () => {\n beforeEach(() => {\n dataSourceMock.check.mockResolvedValue(\n Right({ publicKeyId: \"pk\", descriptor: \"aabb\" }),\n );\n (certificateLoaderMock.loadCertificate as any).mockResolvedValue({\n payload: new Uint8Array([0xcc]),\n keyUsageNumber: 14,\n });\n });\n\n it(\"wraps a legacy message with zero-filled signature placeholders before bs58-encoding\", async () => {\n // message[0] = 2 \u2192 numRequiredSignatures = 2 (legacy, high bit clear)\n const message = new Uint8Array([2, 0, 3, 0xaa, 0xbb, 0xcc]);\n // expected: compact-u16(2) + 2*64 zero bytes + message\n const expected = new Uint8Array(1 + 2 * 64 + message.length);\n expected[0] = 2; // compact-u16 encoding of 2\n expected.set(message, 1 + 2 * 64);\n\n await loader.load({\n deviceModelId: DeviceModelId.NANO_X,\n transactionCheck: {\n from: \"signer\",\n transactionBytes: message,\n chain: SolanaTransactionScanChainId.MAINNET,\n },\n });\n\n const sent = dataSourceMock.check.mock.calls[0]![0];\n\n expect(sent.path).toBe(TransactionCheckPaths.SOLANA_TRANSACTION);\n expect(sent.body.tx.from).toBe(\"signer\");\n expect(sent.body.chain).toBe(SolanaTransactionScanChainId.MAINNET);\n expect(Array.from(bs58.decode(sent.body.tx.raw))).toEqual(\n Array.from(expected),\n );\n expect(sent.body.tx.raw).toBe(bs58.encode(expected));\n });\n\n it(\"wraps a versioned (v0) message with signature placeholders\", async () => {\n // message[0] = 0x80 \u2192 versioned prefix; message[1] = 1 \u2192 numRequiredSignatures = 1\n const message = new Uint8Array([0x80, 1, 0, 3, 0xde, 0xad]);\n // expected: compact-u16(1) + 1*64 zero bytes + message\n const expected = new Uint8Array(1 + 1 * 64 + message.length);\n expected[0] = 1; // compact-u16 encoding of 1\n expected.set(message, 1 + 1 * 64);\n\n await loader.load({\n deviceModelId: DeviceModelId.NANO_X,\n transactionCheck: {\n from: \"signer\",\n transactionBytes: message,\n chain: SolanaTransactionScanChainId.MAINNET,\n },\n });\n\n const raw = dataSourceMock.check.mock.calls[0]![0].body.tx.raw;\n\n expect(Array.from(bs58.decode(raw))).toEqual(Array.from(expected));\n });\n });\n\n describe(\"load \u2014 result mapping\", () => {\n it(\"returns a SOLANA_TRANSACTION_CHECK context with descriptor and certificate on success\", async () => {\n dataSourceMock.check.mockResolvedValue(\n Right({ publicKeyId: \"pk-1\", descriptor: \"deadbeef\" }),\n );\n const cert = { payload: new Uint8Array([0x99]), keyUsageNumber: 14 };\n (certificateLoaderMock.loadCertificate as any).mockResolvedValue(cert);\n\n const [ctx] = await loader.load({\n deviceModelId: DeviceModelId.NANO_X,\n transactionCheck: {\n from: \"signer\",\n transactionBytes: new Uint8Array([1, 0, 3, 0xaa]),\n chain: SolanaTransactionScanChainId.MAINNET,\n },\n });\n\n expect(ctx).toEqual({\n type: ClearSignContextType.SOLANA_TRANSACTION_CHECK,\n payload: { descriptor: \"deadbeef\" },\n certificate: cert,\n });\n });\n\n it(\"returns an ERROR context when the data source returns Left\", async () => {\n const error = new Error(\"network fail\");\n dataSourceMock.check.mockResolvedValue(Left(error));\n\n const [ctx] = await loader.load({\n deviceModelId: DeviceModelId.NANO_X,\n transactionCheck: {\n from: \"signer\",\n transactionBytes: new Uint8Array([1, 0, 3, 0xaa]),\n chain: SolanaTransactionScanChainId.MAINNET,\n },\n });\n\n expect(ctx).toEqual({ type: ClearSignContextType.ERROR, error });\n expect(certificateLoaderMock.loadCertificate).not.toHaveBeenCalled();\n });\n\n it(\"returns an ERROR context when numRequiredSignatures exceeds the 64-signature limit\", async () => {\n // message[0] = 65 \u2192 numRequiredSignatures = 65 (legacy, high bit clear), which exceeds SOLANA_MAX_SIGNATURES\n const message = new Uint8Array([65, 0, 3, 0xaa]);\n\n const [ctx] = await loader.load({\n deviceModelId: DeviceModelId.NANO_X,\n transactionCheck: {\n from: \"signer\",\n transactionBytes: message,\n chain: SolanaTransactionScanChainId.MAINNET,\n },\n });\n\n expect(ctx).toMatchObject({\n type: ClearSignContextType.ERROR,\n error: expect.objectContaining({\n message: expect.stringContaining(\"exceeds SOLANA_MAX_SIGNATURES\"),\n }),\n });\n expect(dataSourceMock.check).not.toHaveBeenCalled();\n });\n });\n});\n"],
5
- "mappings": "wdAEA,IAAAA,EAA8B,2CAC9BC,EAAiB,mBACjBC,EAA4B,qBAI5BC,EAAsC,kEACtCC,EAA6C,+DAC7CC,EAAqC,2CAErCC,EAA6C,0CAE7C,MAAMC,EAAa,CACjB,MAAO,GAAG,GAAG,EACb,KAAM,GAAG,GAAG,EACZ,KAAM,GAAG,GAAG,EACZ,MAAO,GAAG,GAAG,EACb,YAAa,CAAC,CAChB,EACMC,E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CAC9B,cAAe,gBAAc,OAC7B,iBAAkB,CAChB,KAAM,SACN,iBAAkB,IAAI,WAAW,CAAC,EAAG,EAAG,EAAG,GAAI,CAAC,EAChD,MAAO,+BAA6B,OACtC,CACF,CAAC,EAED,OAAOQ,CAAG,EAAE,QAAQ,CAAE,KAAM,uBAAqB,MAAO,MAAAC,CAAM,CAAC,EAC/D,OAAOX,EAAsB,eAAe,EAAE,IAAI,iBAAiB,CACrE,CAAC,EAED,GAAG,qFAAsF,SAAY,CAEnG,MAAMI,EAAU,IAAI,WAAW,CAAC,GAAI,EAAG,EAAG,GAAI,CAAC,EAEzC,CAACM,CAAG,EAAI,MAAMR,EAAO,KAAK,CAC9B,cAAe,gBAAc,OAC7B,iBAAkB,CAChB,KAAM,SACN,iBAAkBE,EAClB,MAAO,+BAA6B,OACtC,CACF,CAAC,EAED,OAAOM,CAAG,EAAE,cAAc,CACxB,KAAM,uBAAqB,MAC3B,MAAO,OAAO,iBAAiB,CAC7B,QAAS,OAAO,iBAAiB,+BAA+B,CAClE,CAAC,CACH,CAAC,EACD,OAAOT,EAAe,KAAK,EAAE,IAAI,iBAAiB,CACpD,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["import_device_management_kit", "import_bs58", "import_purify_ts", "import_constants", "import_SolanaTransactionScanChainId", "import_ClearSignContext", "import_SolanaTransactionCheckLoader", "loggerMock", "loggerFactory", "certificateLoaderMock", "dataSourceMock", "loader", "validInput", "message", "expected", "sent", "bs58", "raw", "cert", "ctx", "error"]
4
+ "sourcesContent": ["/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport bs58 from \"bs58\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type PkiCertificateLoader } from \"@/modules/multichain/pki/domain/PkiCertificateLoader\";\nimport { type TransactionCheckDataSource } from \"@/modules/multichain/transaction-check/data/TransactionCheckDataSource\";\nimport { TransactionCheckPaths } from \"@/modules/multichain/transaction-check/utils/constants\";\nimport { SolanaTransactionScanChainId } from \"@/modules/solana/model/SolanaTransactionScanChainId\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\n\nimport { SolanaTransactionCheckLoader } from \"./SolanaTransactionCheckLoader\";\n\nconst loggerMock = {\n debug: vi.fn(),\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n subscribers: [],\n};\nconst loggerFactory = () => loggerMock;\n\nconst certificateLoaderMock: PkiCertificateLoader = {\n loadCertificate: vi.fn(),\n};\n\nlet dataSourceMock: { check: ReturnType<typeof vi.fn> };\nlet loader: SolanaTransactionCheckLoader;\n\nbeforeEach(() => {\n vi.resetAllMocks();\n dataSourceMock = { check: vi.fn() };\n loader = new SolanaTransactionCheckLoader(\n dataSourceMock as unknown as TransactionCheckDataSource,\n certificateLoaderMock,\n loggerFactory,\n );\n});\n\ndescribe(\"SolanaTransactionCheckLoader\", () => {\n describe(\"canHandle\", () => {\n const validInput = {\n deviceModelId: DeviceModelId.NANO_X,\n transactionCheck: {\n from: \"signer\",\n transactionBytes: new Uint8Array([1, 0, 3, 0xde]),\n chain: 1,\n },\n };\n\n it(\"returns true for a valid Solana transaction-check input\", () => {\n expect(\n loader.canHandle(validInput, [\n ClearSignContextType.SOLANA_TRANSACTION_CHECK,\n ]),\n ).toBe(true);\n });\n\n it(\"returns false when expected types do not include SOLANA_TRANSACTION_CHECK\", () => {\n expect(\n loader.canHandle(validInput, [ClearSignContextType.SOLANA_TOKEN]),\n ).toBe(false);\n });\n\n it(\"returns false when transactionBytes is not a Uint8Array\", () => {\n expect(\n loader.canHandle(\n {\n ...validInput,\n transactionCheck: {\n ...validInput.transactionCheck,\n transactionBytes: \"0xdead\" as unknown as Uint8Array,\n },\n },\n [ClearSignContextType.SOLANA_TRANSACTION_CHECK],\n ),\n ).toBe(false);\n });\n\n it(\"returns false when transactionBytes is empty\", () => {\n expect(\n loader.canHandle(\n {\n ...validInput,\n transactionCheck: {\n ...validInput.transactionCheck,\n transactionBytes: new Uint8Array(),\n },\n },\n [ClearSignContextType.SOLANA_TRANSACTION_CHECK],\n ),\n ).toBe(false);\n });\n\n it(\"returns false when from is empty\", () => {\n expect(\n loader.canHandle(\n {\n ...validInput,\n transactionCheck: { ...validInput.transactionCheck, from: \"\" },\n },\n [ClearSignContextType.SOLANA_TRANSACTION_CHECK],\n ),\n ).toBe(false);\n });\n\n it(\"returns false for unsupported device models (NANO_S)\", () => {\n expect(\n loader.canHandle(\n { ...validInput, deviceModelId: DeviceModelId.NANO_S },\n [ClearSignContextType.SOLANA_TRANSACTION_CHECK],\n ),\n ).toBe(false);\n });\n });\n\n describe(\"load \u2014 wire format\", () => {\n beforeEach(() => {\n dataSourceMock.check.mockResolvedValue(\n Right({ publicKeyId: \"pk\", descriptor: \"aabb\" }),\n );\n (certificateLoaderMock.loadCertificate as any).mockResolvedValue({\n payload: new Uint8Array([0xcc]),\n keyUsageNumber: 14,\n });\n });\n\n it(\"bs58-encodes transactionBytes and passes it to the data source\", async () => {\n const transactionBytes = new Uint8Array([0xaa, 0xbb, 0xcc, 0xdd]);\n\n await loader.load({\n deviceModelId: DeviceModelId.NANO_X,\n transactionCheck: {\n from: \"signer\",\n transactionBytes,\n chain: SolanaTransactionScanChainId.MAINNET,\n },\n });\n\n const sent = dataSourceMock.check.mock.calls[0]![0];\n expect(sent.path).toBe(TransactionCheckPaths.SOLANA_TRANSACTION);\n expect(sent.body.tx.from).toBe(\"signer\");\n expect(sent.body.chain).toBe(SolanaTransactionScanChainId.MAINNET);\n expect(sent.body.tx.raw).toBe(bs58.encode(transactionBytes));\n });\n });\n\n describe(\"load \u2014 result mapping\", () => {\n it(\"returns a SOLANA_TRANSACTION_CHECK context with descriptor and certificate on success\", async () => {\n dataSourceMock.check.mockResolvedValue(\n Right({ publicKeyId: \"pk-1\", descriptor: \"deadbeef\" }),\n );\n const cert = { payload: new Uint8Array([0x99]), keyUsageNumber: 14 };\n (certificateLoaderMock.loadCertificate as any).mockResolvedValue(cert);\n\n const [ctx] = await loader.load({\n deviceModelId: DeviceModelId.NANO_X,\n transactionCheck: {\n from: \"signer\",\n transactionBytes: new Uint8Array([1, 0, 3, 0xaa]),\n chain: SolanaTransactionScanChainId.MAINNET,\n },\n });\n\n expect(ctx).toEqual({\n type: ClearSignContextType.SOLANA_TRANSACTION_CHECK,\n payload: { descriptor: \"deadbeef\" },\n certificate: cert,\n });\n });\n\n it(\"returns an ERROR context when the data source returns Left\", async () => {\n const error = new Error(\"network fail\");\n dataSourceMock.check.mockResolvedValue(Left(error));\n\n const [ctx] = await loader.load({\n deviceModelId: DeviceModelId.NANO_X,\n transactionCheck: {\n from: \"signer\",\n transactionBytes: new Uint8Array([1, 0, 3, 0xaa]),\n chain: SolanaTransactionScanChainId.MAINNET,\n },\n });\n\n expect(ctx).toEqual({ type: ClearSignContextType.ERROR, error });\n expect(certificateLoaderMock.loadCertificate).not.toHaveBeenCalled();\n });\n });\n});\n"],
5
+ "mappings": "wdAGA,IAAAA,EAA8B,2CAC9BC,EAAiB,mBACjBC,EAA4B,qBAI5BC,EAAsC,kEACtCC,EAA6C,+DAC7CC,EAAqC,2CAErCC,EAA6C,0CAE7C,MAAMC,EAAa,CACjB,MAAO,GAAG,GAAG,EACb,KAAM,GAAG,GAAG,EACZ,KAAM,GAAG,GAAG,EACZ,MAAO,GAAG,GAAG,EACb,YAAa,CAAC,CAChB,EACMC,EAAgB,IAAMD,EAEtBE,EAA8C,CAClD,gBAAiB,GAAG,GAAG,CACzB,EAEA,IAAIC,EACAC,EAEJ,WAAW,IAAM,CACf,GAAG,cAAc,EACjBD,EAAiB,CAAE,MAAO,GAAG,GAAG,CAAE,EAClCC,EAAS,IAAI,+BACXD,EACAD,EACAD,CACF,CACF,CAAC,EAED,SAAS,+BAAgC,IAAM,CAC7C,SAAS,YAAa,IAAM,CAC1B,MAAMI,EAAa,CACjB,cAAe,gBAAc,OAC7B,iBAAkB,CAChB,KAAM,SACN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,MAAM,qBAAkB,QAAKQ,CAAK,CAAC,EAElD,KAAM,CAACD,CAAG,EAAI,MAAMN,EAAO,KAAK,CAC9B,cAAe,gBAAc,OAC7B,iBAAkB,CAChB,KAAM,SACN,iBAAkB,IAAI,WAAW,CAAC,EAAG,EAAG,EAAG,GAAI,CAAC,EAChD,MAAO,+BAA6B,OACtC,CACF,CAAC,EAED,OAAOM,CAAG,EAAE,QAAQ,CAAE,KAAM,uBAAqB,MAAO,MAAAC,CAAM,CAAC,EAC/D,OAAOT,EAAsB,eAAe,EAAE,IAAI,iBAAiB,CACrE,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["import_device_management_kit", "import_bs58", "import_purify_ts", "import_constants", "import_SolanaTransactionScanChainId", "import_ClearSignContext", "import_SolanaTransactionCheckLoader", "loggerMock", "loggerFactory", "certificateLoaderMock", "dataSourceMock", "loader", "validInput", "transactionBytes", "sent", "bs58", "cert", "ctx", "error"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var o=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var a=Object.prototype.hasOwnProperty;var u=(e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of l(t))!a.call(e,r)&&r!==n&&o(e,r,{get:()=>t[r],enumerable:!(s=i(t,r))||s.enumerable});return e};var p=e=>u(o({},"__esModule",{value:!0}),e);var A={};module.exports=p(A);
1
+ "use strict";var o=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var a=Object.prototype.hasOwnProperty;var d=(t,e,n,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of l(e))!a.call(t,r)&&r!==n&&o(t,r,{get:()=>e[r],enumerable:!(s=i(e,r))||s.enumerable});return t};var u=t=>d(o({},"__esModule",{value:!0}),t);var A={};module.exports=u(A);
2
2
  //# sourceMappingURL=AltResolutionDataSource.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/modules/solana/alt-resolution/data/AltResolutionDataSource.ts"],
4
- "sourcesContent": ["import { type Either } from \"purify-ts\";\n\nexport type GetAltResolutionParams = {\n altAddress: string;\n entryIndex: number;\n challenge: string;\n};\n\nexport type AltResolutionResult = {\n altAddress: string;\n entryIndex: number;\n // Raw signed TLV bytes decoded from the backend response.\n descriptor: Uint8Array;\n keyId: string;\n keyUsage: string;\n};\n\nexport interface AltResolutionDataSource {\n getAltResolution(\n params: GetAltResolutionParams,\n ): Promise<Either<Error, AltResolutionResult>>;\n}\n"],
4
+ "sourcesContent": ["import { type Either } from \"purify-ts\";\n\nexport type GetAltResolutionParams = {\n altAddress: string;\n entryIndex: number;\n challenge: string;\n};\n\nexport type AltResolutionResult = {\n altAddress: string;\n entryIndex: number;\n // Raw signed TLV bytes decoded from the backend response.\n descriptor: Uint8Array;\n resolvedAddress?: string;\n keyId: string;\n keyUsage: string;\n};\n\nexport interface AltResolutionDataSource {\n getAltResolution(\n params: GetAltResolutionParams,\n ): Promise<Either<Error, AltResolutionResult>>;\n}\n"],
5
5
  "mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
6
6
  "names": ["AltResolutionDataSource_exports", "__toCommonJS"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var c=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var $=(r,e)=>{for(var t in e)c(r,t,{get:e[t],enumerable:!0})},E=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of A(e))!k.call(r,o)&&o!==t&&c(r,o,{get:()=>e[o],enumerable:!(s=f(e,o))||s.enumerable});return r};var w=r=>E(c({},"__esModule",{value:!0}),r),g=(r,e,t,s)=>{for(var o=s>1?void 0:s?f(e,t):e,l=r.length-1,i;l>=0;l--)(i=r[l])&&(o=(s?i(e,t,o):i(o))||o);return s&&o&&c(e,t,o),o},m=(r,e)=>(t,s)=>e(t,s,r);var x={};$(x,{HttpAltResolutionDataSource:()=>a});module.exports=w(x);var u=require("inversify"),n=require("purify-ts"),d=require("../../../../config/di/configTypes"),R=require("../../../../shared/network/di/networkTypes"),y=require("../../../../shared/utils/HexStringUtils"),D=require("../../../../shared/utils/signedDescriptorDto"),h=require("../../../../shared/utils/uIntCodec");let a=class{constructor(e,t){this.config=e;this.http=t}async getAltResolution({altAddress:e,entryIndex:t,challenge:s}){const o=h.u8Codec.decode(t);if(o.isLeft())return(0,n.Left)(new Error(`[ContextModule] HttpAltResolutionDataSource: invalid entryIndex (got ${t}): ${o.leftOrDefault("")}`));let l;try{l=await this.http.get(`${this.config.metadataServiceDomain.url}/v2/solana/alt-resolution/${e}/${t}`,{params:{challenge:s}})}catch(i){const p=i instanceof Error?i.message:String(i);return(0,n.Left)(new Error(`[ContextModule] HttpAltResolutionDataSource: Failed to fetch ALT resolution: ${p}`))}return D.signedDescriptorDtoCodec.decode(l).caseOf({Left:i=>(0,n.Left)(new Error(`[ContextModule] HttpAltResolutionDataSource: malformed response for (${e}, ${t}): ${i}`)),Right:i=>{let p;try{p=y.HexStringUtils.hexToBytes(i.signedDescriptor)}catch(C){return(0,n.Left)(new Error(`[ContextModule] HttpAltResolutionDataSource: invalid hex in signedDescriptor for (${e}, ${t}): ${C.message}`))}return(0,n.Right)({altAddress:e,entryIndex:t,descriptor:p,keyId:i.keyId,keyUsage:i.keyUsage})}})}};a=g([(0,u.injectable)(),m(0,(0,u.inject)(d.configTypes.Config)),m(1,(0,u.inject)(R.networkTypes.NetworkClient))],a);0&&(module.exports={HttpAltResolutionDataSource});
1
+ "use strict";var c=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var $=(r,e)=>{for(var t in e)c(r,t,{get:e[t],enumerable:!0})},E=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of C(e))!k.call(r,o)&&o!==t&&c(r,o,{get:()=>e[o],enumerable:!(s=d(e,o))||s.enumerable});return r};var v=r=>E(c({},"__esModule",{value:!0}),r),f=(r,e,t,s)=>{for(var o=s>1?void 0:s?d(e,t):e,n=r.length-1,i;n>=0;n--)(i=r[n])&&(o=(s?i(e,t,o):i(o))||o);return s&&o&&c(e,t,o),o},m=(r,e)=>(t,s)=>e(t,s,r);var w={};$(w,{HttpAltResolutionDataSource:()=>a});module.exports=v(w);var u=require("inversify"),l=require("purify-ts"),g=require("../../../../config/di/configTypes"),R=require("../../../../shared/network/di/networkTypes"),y=require("../../../../shared/utils/HexStringUtils"),A=require("../../../../shared/utils/signedDescriptorDto"),D=require("../../../../shared/utils/uIntCodec");let a=class{constructor(e,t){this.config=e;this.http=t}async getAltResolution({altAddress:e,entryIndex:t,challenge:s}){const o=D.u8Codec.decode(t);if(o.isLeft())return(0,l.Left)(new Error(`[ContextModule] HttpAltResolutionDataSource: invalid entryIndex (got ${t}): ${o.leftOrDefault("")}`));let n;try{n=await this.http.get(`${this.config.metadataServiceDomain.url}/v2/solana/alt-resolution/${e}/${t}`,{params:{challenge:s}})}catch(i){const p=i instanceof Error?i.message:String(i);return(0,l.Left)(new Error(`[ContextModule] HttpAltResolutionDataSource: Failed to fetch ALT resolution: ${p}`))}return A.signedDescriptorDtoCodec.decode(n).caseOf({Left:i=>(0,l.Left)(new Error(`[ContextModule] HttpAltResolutionDataSource: malformed response for (${e}, ${t}): ${i}`)),Right:i=>{let p;try{p=y.HexStringUtils.hexToBytes(i.signedDescriptor)}catch(h){return(0,l.Left)(new Error(`[ContextModule] HttpAltResolutionDataSource: invalid hex in signedDescriptor for (${e}, ${t}): ${h.message}`))}return(0,l.Right)({altAddress:e,entryIndex:t,descriptor:p,resolvedAddress:n.resolvedAddress,keyId:i.keyId,keyUsage:i.keyUsage})}})}};a=f([(0,u.injectable)(),m(0,(0,u.inject)(g.configTypes.Config)),m(1,(0,u.inject)(R.networkTypes.NetworkClient))],a);0&&(module.exports={HttpAltResolutionDataSource});
2
2
  //# sourceMappingURL=HttpAltResolutionDataSource.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/modules/solana/alt-resolution/data/HttpAltResolutionDataSource.ts"],
4
- "sourcesContent": ["import { DmkNetworkClient } from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleServiceConfig } from \"@/config/model/ContextModuleConfig\";\nimport { networkTypes } from \"@/shared/network/di/networkTypes\";\nimport { HexStringUtils } from \"@/shared/utils/HexStringUtils\";\nimport { signedDescriptorDtoCodec } from \"@/shared/utils/signedDescriptorDto\";\nimport { u8Codec } from \"@/shared/utils/uIntCodec\";\n\nimport {\n type AltResolutionDataSource,\n type AltResolutionResult,\n type GetAltResolutionParams,\n} from \"./AltResolutionDataSource\";\n\ntype AltResolutionResponseDto = {\n descriptorType?: string;\n descriptorVersion?: number;\n altAddress?: string;\n entryIndex?: number;\n resolvedAddress?: string;\n signedDescriptor: string;\n keyId: string;\n keyUsage: string;\n};\n\n@injectable()\nexport class HttpAltResolutionDataSource implements AltResolutionDataSource {\n constructor(\n @inject(configTypes.Config)\n private readonly config: ContextModuleServiceConfig,\n @inject(networkTypes.NetworkClient)\n private readonly http: DmkNetworkClient,\n ) {}\n\n public async getAltResolution({\n altAddress,\n entryIndex,\n challenge,\n }: GetAltResolutionParams): Promise<Either<Error, AltResolutionResult>> {\n const entryIndexResult = u8Codec.decode(entryIndex);\n if (entryIndexResult.isLeft()) {\n return Left(\n new Error(\n `[ContextModule] HttpAltResolutionDataSource: invalid entryIndex (got ${entryIndex}): ${entryIndexResult.leftOrDefault(\"\")}`,\n ),\n );\n }\n\n let dto: AltResolutionResponseDto;\n try {\n dto = (await this.http.get(\n `${this.config.metadataServiceDomain.url}/v2/solana/alt-resolution/${altAddress}/${entryIndex}`,\n { params: { challenge } },\n )) as AltResolutionResponseDto;\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n return Left(\n new Error(\n `[ContextModule] HttpAltResolutionDataSource: Failed to fetch ALT resolution: ${reason}`,\n ),\n );\n }\n\n return signedDescriptorDtoCodec\n .decode(dto)\n .caseOf<Either<Error, AltResolutionResult>>({\n Left: (error) =>\n Left(\n new Error(\n `[ContextModule] HttpAltResolutionDataSource: malformed response for (${altAddress}, ${entryIndex}): ${error}`,\n ),\n ),\n Right: (validated) => {\n let descriptor: Uint8Array;\n try {\n descriptor = HexStringUtils.hexToBytes(validated.signedDescriptor);\n } catch (error) {\n return Left(\n new Error(\n `[ContextModule] HttpAltResolutionDataSource: invalid hex in signedDescriptor for (${altAddress}, ${entryIndex}): ${(error as Error).message}`,\n ),\n );\n }\n\n return Right({\n altAddress,\n entryIndex,\n descriptor,\n keyId: validated.keyId,\n keyUsage: validated.keyUsage,\n });\n },\n });\n }\n}\n"],
5
- "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iCAAAE,IAAA,eAAAC,EAAAH,GACA,IAAAI,EAAmC,qBACnCC,EAAoC,qBAEpCC,EAA4B,mCAE5BC,EAA6B,4CAC7BC,EAA+B,yCAC/BC,EAAyC,8CACzCC,EAAwB,oCAoBjB,IAAMC,EAAN,KAAqE,CAC1E,YAEmBC,EAEAC,EACjB,CAHiB,YAAAD,EAEA,UAAAC,CAChB,CAEH,MAAa,iBAAiB,CAC5B,WAAAC,EACA,WAAAC,EACA,UAAAC,CACF,EAAwE,CACtE,MAAMC,EAAmB,UAAQ,OAAOF,CAAU,EAClD,GAAIE,EAAiB,OAAO,EAC1B,SAAO,QACL,IAAI,MACF,wEAAwEF,CAAU,MAAME,EAAiB,cAAc,EAAE,CAAC,EAC5H,CACF,EAGF,IAAIC,EACJ,GAAI,CACFA,EAAO,MAAM,KAAK,KAAK,IACrB,GAAG,KAAK,OAAO,sBAAsB,GAAG,6BAA6BJ,CAAU,IAAIC,CAAU,GAC7F,CAAE,OAAQ,CAAE,UAAAC,CAAU,CAAE,CAC1B,CACF,OAASG,EAAO,CACd,MAAMC,EAASD,aAAiB,MAAQA,EAAM,QAAU,OAAOA,CAAK,EACpE,SAAO,QACL,IAAI,MACF,gFAAgFC,CAAM,EACxF,CACF,CACF,CAEA,OAAO,2BACJ,OAAOF,CAAG,EACV,OAA2C,CAC1C,KAAOC,MACL,QACE,IAAI,MACF,wEAAwEL,CAAU,KAAKC,CAAU,MAAMI,CAAK,EAC9G,CACF,EACF,MAAQE,GAAc,CACpB,IAAIC,EACJ,GAAI,CACFA,EAAa,iBAAe,WAAWD,EAAU,gBAAgB,CACnE,OAASF,EAAO,CACd,SAAO,QACL,IAAI,MACF,qFAAqFL,CAAU,KAAKC,CAAU,MAAOI,EAAgB,OAAO,EAC9I,CACF,CACF,CAEA,SAAO,SAAM,CACX,WAAAL,EACA,WAAAC,EACA,WAAAO,EACA,MAAOD,EAAU,MACjB,SAAUA,EAAU,QACtB,CAAC,CACH,CACF,CAAC,CACL,CACF,EApEaV,EAANY,EAAA,IADN,cAAW,EAGPC,EAAA,eAAO,cAAY,MAAM,GAEzBA,EAAA,eAAO,eAAa,aAAa,IAJzBb",
4
+ "sourcesContent": ["import { DmkNetworkClient } from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleServiceConfig } from \"@/config/model/ContextModuleConfig\";\nimport { networkTypes } from \"@/shared/network/di/networkTypes\";\nimport { HexStringUtils } from \"@/shared/utils/HexStringUtils\";\nimport { signedDescriptorDtoCodec } from \"@/shared/utils/signedDescriptorDto\";\nimport { u8Codec } from \"@/shared/utils/uIntCodec\";\n\nimport {\n type AltResolutionDataSource,\n type AltResolutionResult,\n type GetAltResolutionParams,\n} from \"./AltResolutionDataSource\";\n\ntype AltResolutionResponseDto = {\n descriptorType?: string;\n descriptorVersion?: number;\n altAddress?: string;\n entryIndex?: number;\n resolvedAddress?: string;\n signedDescriptor: string;\n keyId: string;\n keyUsage: string;\n};\n\n@injectable()\nexport class HttpAltResolutionDataSource implements AltResolutionDataSource {\n constructor(\n @inject(configTypes.Config)\n private readonly config: ContextModuleServiceConfig,\n @inject(networkTypes.NetworkClient)\n private readonly http: DmkNetworkClient,\n ) {}\n\n public async getAltResolution({\n altAddress,\n entryIndex,\n challenge,\n }: GetAltResolutionParams): Promise<Either<Error, AltResolutionResult>> {\n const entryIndexResult = u8Codec.decode(entryIndex);\n if (entryIndexResult.isLeft()) {\n return Left(\n new Error(\n `[ContextModule] HttpAltResolutionDataSource: invalid entryIndex (got ${entryIndex}): ${entryIndexResult.leftOrDefault(\"\")}`,\n ),\n );\n }\n\n let dto: AltResolutionResponseDto;\n try {\n dto = (await this.http.get(\n `${this.config.metadataServiceDomain.url}/v2/solana/alt-resolution/${altAddress}/${entryIndex}`,\n { params: { challenge } },\n )) as AltResolutionResponseDto;\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n return Left(\n new Error(\n `[ContextModule] HttpAltResolutionDataSource: Failed to fetch ALT resolution: ${reason}`,\n ),\n );\n }\n\n return signedDescriptorDtoCodec\n .decode(dto)\n .caseOf<Either<Error, AltResolutionResult>>({\n Left: (error) =>\n Left(\n new Error(\n `[ContextModule] HttpAltResolutionDataSource: malformed response for (${altAddress}, ${entryIndex}): ${error}`,\n ),\n ),\n Right: (validated) => {\n let descriptor: Uint8Array;\n try {\n descriptor = HexStringUtils.hexToBytes(validated.signedDescriptor);\n } catch (error) {\n return Left(\n new Error(\n `[ContextModule] HttpAltResolutionDataSource: invalid hex in signedDescriptor for (${altAddress}, ${entryIndex}): ${(error as Error).message}`,\n ),\n );\n }\n\n return Right({\n altAddress,\n entryIndex,\n descriptor,\n resolvedAddress: dto.resolvedAddress,\n keyId: validated.keyId,\n keyUsage: validated.keyUsage,\n });\n },\n });\n }\n}\n"],
5
+ "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,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CACH,CACF,CAAC,CACL,CACF,EArEaV,EAANY,EAAA,IADN,cAAW,EAGPC,EAAA,eAAO,cAAY,MAAM,GAEzBA,EAAA,eAAO,eAAa,aAAa,IAJzBb",
6
6
  "names": ["HttpAltResolutionDataSource_exports", "__export", "HttpAltResolutionDataSource", "__toCommonJS", "import_inversify", "import_purify_ts", "import_configTypes", "import_networkTypes", "import_HexStringUtils", "import_signedDescriptorDto", "import_uIntCodec", "HttpAltResolutionDataSource", "config", "http", "altAddress", "entryIndex", "challenge", "entryIndexResult", "dto", "error", "reason", "validated", "descriptor", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var s=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var I=Object.prototype.hasOwnProperty;var L=(l,e)=>{for(var t in e)s(l,t,{get:e[t],enumerable:!0})},h=(l,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of x(e))!I.call(l,r)&&r!==t&&s(l,r,{get:()=>e[r],enumerable:!(o=g(e,r))||o.enumerable});return l};var v=l=>h(s({},"__esModule",{value:!0}),l),m=(l,e,t,o)=>{for(var r=o>1?void 0:o?g(e,t):e,c=l.length-1,p;c>=0;c--)(p=l[c])&&(r=(o?p(e,t,r):p(r))||r);return o&&r&&s(e,t,r),r},d=(l,e)=>(t,o)=>e(t,o,l);var b={};L(b,{AltResolutionContextLoader:()=>a});module.exports=v(b);var i=require("inversify"),n=require("purify-ts"),y=require("../../../../config/di/configTypes"),f=require("../../../../modules/multichain/pki/di/pkiTypes"),S=require("../../../../modules/solana/alt-resolution/di/altResolutionTypes"),u=require("../../../../shared/model/ClearSignContext"),C=require("../../../../shared/utils/challengeBoundLoader"),A=require("../../../../shared/utils/deviceModelIdCodec"),R=require("../../../../shared/utils/uIntCodec");const T=[u.ClearSignContextType.SOLANA_ALT_RESOLUTION],P=n.Codec.interface({altAddress:n.string,entryIndex:R.u8Codec,challenge:n.string}),O=n.Codec.interface({deviceModelId:A.deviceModelIdCodec,requests:(0,n.array)(P)});let a=class{constructor(e,t,o){this.dataSource=e;this.certificateLoader=t;this.logger=o("AltResolutionContextLoader")}logger;canHandle(e,t){return T.every(o=>t.includes(o))?O.decode(e).caseOf({Left:()=>!1,Right:({requests:o})=>o.length>0&&o.every(r=>r.altAddress.length>0&&r.challenge.length>0)}):!1}async load(e){return(0,C.loadChallengeBoundContexts)({requests:e.requests,deviceModelId:e.deviceModelId,certificateLoader:this.certificateLoader,logger:this.logger,label:"ALT_RESOLUTION",fetch:t=>this.dataSource.getAltResolution(t),toContext:(t,o)=>{const r={descriptor:t.descriptor};return{type:u.ClearSignContextType.SOLANA_ALT_RESOLUTION,payload:r,certificate:o}},describe:t=>({altAddress:t.altAddress,entryIndex:t.entryIndex})})}};a=m([(0,i.injectable)(),d(0,(0,i.inject)(S.altResolutionTypes.AltResolutionDataSource)),d(1,(0,i.inject)(f.pkiTypes.PkiCertificateLoader)),d(2,(0,i.inject)(y.configTypes.ContextModuleLoggerFactory))],a);0&&(module.exports={AltResolutionContextLoader});
1
+ "use strict";var s=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var I=Object.prototype.hasOwnProperty;var L=(l,e)=>{for(var t in e)s(l,t,{get:e[t],enumerable:!0})},h=(l,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of x(e))!I.call(l,r)&&r!==t&&s(l,r,{get:()=>e[r],enumerable:!(o=g(e,r))||o.enumerable});return l};var v=l=>h(s({},"__esModule",{value:!0}),l),m=(l,e,t,o)=>{for(var r=o>1?void 0:o?g(e,t):e,c=l.length-1,p;c>=0;c--)(p=l[c])&&(r=(o?p(e,t,r):p(r))||r);return o&&r&&s(e,t,r),r},d=(l,e)=>(t,o)=>e(t,o,l);var b={};L(b,{AltResolutionContextLoader:()=>a});module.exports=v(b);var i=require("inversify"),n=require("purify-ts"),y=require("../../../../config/di/configTypes"),f=require("../../../../modules/multichain/pki/di/pkiTypes"),S=require("../../../../modules/solana/alt-resolution/di/altResolutionTypes"),u=require("../../../../shared/model/ClearSignContext"),C=require("../../../../shared/utils/challengeBoundLoader"),A=require("../../../../shared/utils/deviceModelIdCodec"),R=require("../../../../shared/utils/uIntCodec");const T=[u.ClearSignContextType.SOLANA_ALT_RESOLUTION],P=n.Codec.interface({altAddress:n.string,entryIndex:R.u8Codec,challenge:n.string}),O=n.Codec.interface({deviceModelId:A.deviceModelIdCodec,requests:(0,n.array)(P)});let a=class{constructor(e,t,o){this.dataSource=e;this.certificateLoader=t;this.logger=o("AltResolutionContextLoader")}logger;canHandle(e,t){return T.every(o=>t.includes(o))?O.decode(e).caseOf({Left:()=>!1,Right:({requests:o})=>o.length>0&&o.every(r=>r.altAddress.length>0&&r.challenge.length>0)}):!1}async load(e){return(0,C.loadChallengeBoundContexts)({requests:e.requests,deviceModelId:e.deviceModelId,certificateLoader:this.certificateLoader,logger:this.logger,label:"ALT_RESOLUTION",fetch:t=>this.dataSource.getAltResolution(t),toContext:(t,o)=>{const r={descriptor:t.descriptor,resolvedAddress:t.resolvedAddress};return{type:u.ClearSignContextType.SOLANA_ALT_RESOLUTION,payload:r,certificate:o}},describe:t=>({altAddress:t.altAddress,entryIndex:t.entryIndex})})}};a=m([(0,i.injectable)(),d(0,(0,i.inject)(S.altResolutionTypes.AltResolutionDataSource)),d(1,(0,i.inject)(f.pkiTypes.PkiCertificateLoader)),d(2,(0,i.inject)(y.configTypes.ContextModuleLoggerFactory))],a);0&&(module.exports={AltResolutionContextLoader});
2
2
  //# sourceMappingURL=AltResolutionContextLoader.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/modules/solana/alt-resolution/domain/AltResolutionContextLoader.ts"],
4
- "sourcesContent": ["import {\n type DeviceModelId,\n type LoggerPublisherService,\n} from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\nimport { array, Codec, string } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { pkiTypes } from \"@/modules/multichain/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/modules/multichain/pki/domain/PkiCertificateLoader\";\nimport { type AltResolutionDataSource } from \"@/modules/solana/alt-resolution/data/AltResolutionDataSource\";\nimport { altResolutionTypes } from \"@/modules/solana/alt-resolution/di/altResolutionTypes\";\nimport { type SolanaAltResolutionPayload } from \"@/modules/solana/model/SolanaPayloads\";\nimport { type ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n type ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { loadChallengeBoundContexts } from \"@/shared/utils/challengeBoundLoader\";\nimport { deviceModelIdCodec } from \"@/shared/utils/deviceModelIdCodec\";\nimport { u8Codec } from \"@/shared/utils/uIntCodec\";\n\nconst SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.SOLANA_ALT_RESOLUTION,\n];\n\nexport type SolanaAltResolutionRequest = {\n altAddress: string;\n entryIndex: number;\n challenge: string;\n};\n\nexport type SolanaAltResolutionContextInput = {\n deviceModelId: DeviceModelId;\n requests: SolanaAltResolutionRequest[];\n};\n\nconst altResolutionRequestCodec = Codec.interface({\n altAddress: string,\n entryIndex: u8Codec,\n challenge: string,\n});\n\nconst solanaAltResolutionInputCodec = Codec.interface({\n deviceModelId: deviceModelIdCodec,\n requests: array(altResolutionRequestCodec),\n});\n\n@injectable()\nexport class AltResolutionContextLoader\n implements ContextLoader<SolanaAltResolutionContextInput>\n{\n private readonly logger: LoggerPublisherService;\n\n constructor(\n @inject(altResolutionTypes.AltResolutionDataSource)\n private readonly dataSource: AltResolutionDataSource,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly certificateLoader: PkiCertificateLoader,\n @inject(configTypes.ContextModuleLoggerFactory)\n loggerFactory: (tag: string) => LoggerPublisherService,\n ) {\n this.logger = loggerFactory(\"AltResolutionContextLoader\");\n }\n\n public canHandle(\n input: unknown,\n expectedTypes: ClearSignContextType[],\n ): input is SolanaAltResolutionContextInput {\n if (!SUPPORTED_TYPES.every((t) => expectedTypes.includes(t))) return false;\n return solanaAltResolutionInputCodec.decode(input).caseOf({\n Left: () => false,\n Right: ({ requests }) =>\n requests.length > 0 &&\n requests.every(\n (r) => r.altAddress.length > 0 && r.challenge.length > 0,\n ),\n });\n }\n\n public async load(\n input: SolanaAltResolutionContextInput,\n ): Promise<ClearSignContext[]> {\n return loadChallengeBoundContexts({\n requests: input.requests,\n deviceModelId: input.deviceModelId,\n certificateLoader: this.certificateLoader,\n logger: this.logger,\n label: \"ALT_RESOLUTION\",\n fetch: (request) => this.dataSource.getAltResolution(request),\n toContext: (value, certificate) => {\n const payload: SolanaAltResolutionPayload = {\n descriptor: value.descriptor,\n };\n return {\n type: ClearSignContextType.SOLANA_ALT_RESOLUTION,\n payload,\n certificate,\n };\n },\n describe: (request) => ({\n altAddress: request.altAddress,\n entryIndex: request.entryIndex,\n }),\n });\n }\n}\n"],
5
- "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gCAAAE,IAAA,eAAAC,EAAAH,GAIA,IAAAI,EAAmC,qBACnCC,EAAqC,qBAErCC,EAA4B,mCAC5BC,EAAyB,gDAGzBC,EAAmC,iEAGnCC,EAGO,2CACPC,EAA2C,+CAC3CC,EAAmC,6CACnCC,EAAwB,oCAExB,MAAMC,EAA0C,CAC9C,uBAAqB,qBACvB,EAaMC,EAA4B,QAAM,UAAU,CAChD,WAAY,SACZ,WAAY,UACZ,UAAW,QACb,CAAC,EAEKC,EAAgC,QAAM,UAAU,CACpD,cAAe,qBACf,YAAU,SAAMD,CAAyB,CAC3C,CAAC,EAGM,IAAME,EAAN,KAEP,CAGE,YAEmBC,EAEAC,EAEjBC,EACA,CALiB,gBAAAF,EAEA,uBAAAC,EAIjB,KAAK,OAASC,EAAc,4BAA4B,CAC1D,CAXiB,OAaV,UACLC,EACAC,EAC0C,CAC1C,OAAKR,EAAgB,MAAOS,GAAMD,EAAc,SAASC,CAAC,CAAC,EACpDP,EAA8B,OAAOK,CAAK,EAAE,OAAO,CACxD,KAAM,IAAM,GACZ,MAAO,CAAC,CAAE,SAAAG,CAAS,IACjBA,EAAS,OAAS,GAClBA,EAAS,MACN,GAAM,EAAE,WAAW,OAAS,GAAK,EAAE,UAAU,OAAS,CACzD,CACJ,CAAC,EARoE,EASvE,CAEA,MAAa,KACXH,EAC6B,CAC7B,SAAO,8BAA2B,CAChC,SAAUA,EAAM,SAChB,cAAeA,EAAM,cACrB,kBAAmB,KAAK,kBACxB,OAAQ,KAAK,OACb,MAAO,iBACP,MAAQI,GAAY,KAAK,WAAW,iBAAiBA,CAAO,EAC5D,UAAW,CAACC,EAAOC,IAAgB,CACjC,MAAMC,EAAsC,CAC1C,WAAYF,EAAM,UACpB,EACA,MAAO,CACL,KAAM,uBAAqB,sBAC3B,QAAAE,EACA,YAAAD,CACF,CACF,EACA,SAAWF,IAAa,CACtB,WAAYA,EAAQ,WACpB,WAAYA,EAAQ,UACtB,EACF,CAAC,CACH,CACF,EAzDaR,EAANY,EAAA,IADN,cAAW,EAOPC,EAAA,eAAO,qBAAmB,uBAAuB,GAEjDA,EAAA,eAAO,WAAS,oBAAoB,GAEpCA,EAAA,eAAO,cAAY,0BAA0B,IAVrCb",
4
+ "sourcesContent": ["import {\n type DeviceModelId,\n type LoggerPublisherService,\n} from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\nimport { array, Codec, string } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { pkiTypes } from \"@/modules/multichain/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/modules/multichain/pki/domain/PkiCertificateLoader\";\nimport { type AltResolutionDataSource } from \"@/modules/solana/alt-resolution/data/AltResolutionDataSource\";\nimport { altResolutionTypes } from \"@/modules/solana/alt-resolution/di/altResolutionTypes\";\nimport { type SolanaAltResolutionPayload } from \"@/modules/solana/model/SolanaPayloads\";\nimport { type ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n type ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { loadChallengeBoundContexts } from \"@/shared/utils/challengeBoundLoader\";\nimport { deviceModelIdCodec } from \"@/shared/utils/deviceModelIdCodec\";\nimport { u8Codec } from \"@/shared/utils/uIntCodec\";\n\nconst SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.SOLANA_ALT_RESOLUTION,\n];\n\nexport type SolanaAltResolutionRequest = {\n altAddress: string;\n entryIndex: number;\n challenge: string;\n};\n\nexport type SolanaAltResolutionContextInput = {\n deviceModelId: DeviceModelId;\n requests: SolanaAltResolutionRequest[];\n};\n\nconst altResolutionRequestCodec = Codec.interface({\n altAddress: string,\n entryIndex: u8Codec,\n challenge: string,\n});\n\nconst solanaAltResolutionInputCodec = Codec.interface({\n deviceModelId: deviceModelIdCodec,\n requests: array(altResolutionRequestCodec),\n});\n\n@injectable()\nexport class AltResolutionContextLoader\n implements ContextLoader<SolanaAltResolutionContextInput>\n{\n private readonly logger: LoggerPublisherService;\n\n constructor(\n @inject(altResolutionTypes.AltResolutionDataSource)\n private readonly dataSource: AltResolutionDataSource,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly certificateLoader: PkiCertificateLoader,\n @inject(configTypes.ContextModuleLoggerFactory)\n loggerFactory: (tag: string) => LoggerPublisherService,\n ) {\n this.logger = loggerFactory(\"AltResolutionContextLoader\");\n }\n\n public canHandle(\n input: unknown,\n expectedTypes: ClearSignContextType[],\n ): input is SolanaAltResolutionContextInput {\n if (!SUPPORTED_TYPES.every((t) => expectedTypes.includes(t))) return false;\n return solanaAltResolutionInputCodec.decode(input).caseOf({\n Left: () => false,\n Right: ({ requests }) =>\n requests.length > 0 &&\n requests.every(\n (r) => r.altAddress.length > 0 && r.challenge.length > 0,\n ),\n });\n }\n\n public async load(\n input: SolanaAltResolutionContextInput,\n ): Promise<ClearSignContext[]> {\n return loadChallengeBoundContexts({\n requests: input.requests,\n deviceModelId: input.deviceModelId,\n certificateLoader: this.certificateLoader,\n logger: this.logger,\n label: \"ALT_RESOLUTION\",\n fetch: (request) => this.dataSource.getAltResolution(request),\n toContext: (value, certificate) => {\n const payload: SolanaAltResolutionPayload = {\n descriptor: value.descriptor,\n resolvedAddress: value.resolvedAddress,\n };\n return {\n type: ClearSignContextType.SOLANA_ALT_RESOLUTION,\n payload,\n certificate,\n };\n },\n describe: (request) => ({\n altAddress: request.altAddress,\n entryIndex: request.entryIndex,\n }),\n });\n }\n}\n"],
5
+ "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gCAAAE,IAAA,eAAAC,EAAAH,GAIA,IAAAI,EAAmC,qBACnCC,EAAqC,qBAErCC,EAA4B,mCAC5BC,EAAyB,gDAGzBC,EAAmC,iEAGnCC,EAGO,2CACPC,EAA2C,+CAC3CC,EAAmC,6CACnCC,EAAwB,oCAExB,MAAMC,EAA0C,CAC9C,uBAAqB,qBACvB,EAaMC,EAA4B,QAAM,UAAU,CAChD,WAAY,SACZ,WAAY,UACZ,UAAW,QACb,CAAC,EAEKC,EAAgC,QAAM,UAAU,CACpD,cAAe,qBACf,YAAU,SAAMD,CAAyB,CAC3C,CAAC,EAGM,IAAME,EAAN,KAEP,CAGE,YAEmBC,EAEAC,EAEjBC,EACA,CALiB,gBAAAF,EAEA,uBAAAC,EAIjB,KAAK,OAASC,EAAc,4BAA4B,CAC1D,CAXiB,OAaV,UACLC,EACAC,EAC0C,CAC1C,OAAKR,EAAgB,MAAOS,GAAMD,EAAc,SAASC,CAAC,CAAC,EACpDP,EAA8B,OAAOK,CAAK,EAAE,OAAO,CACxD,KAAM,IAAM,GACZ,MAAO,CAAC,CAAE,SAAAG,CAAS,IACjBA,EAAS,OAAS,GAClBA,EAAS,MACN,GAAM,EAAE,WAAW,OAAS,GAAK,EAAE,UAAU,OAAS,CACzD,CACJ,CAAC,EARoE,EASvE,CAEA,MAAa,KACXH,EAC6B,CAC7B,SAAO,8BAA2B,CAChC,SAAUA,EAAM,SAChB,cAAeA,EAAM,cACrB,kBAAmB,KAAK,kBACxB,OAAQ,KAAK,OACb,MAAO,iBACP,MAAQI,GAAY,KAAK,WAAW,iBAAiBA,CAAO,EAC5D,UAAW,CAACC,EAAOC,IAAgB,CACjC,MAAMC,EAAsC,CAC1C,WAAYF,EAAM,WAClB,gBAAiBA,EAAM,eACzB,EACA,MAAO,CACL,KAAM,uBAAqB,sBAC3B,QAAAE,EACA,YAAAD,CACF,CACF,EACA,SAAWF,IAAa,CACtB,WAAYA,EAAQ,WACpB,WAAYA,EAAQ,UACtB,EACF,CAAC,CACH,CACF,EA1DaR,EAANY,EAAA,IADN,cAAW,EAOPC,EAAA,eAAO,qBAAmB,uBAAuB,GAEjDA,EAAA,eAAO,WAAS,oBAAoB,GAEpCA,EAAA,eAAO,cAAY,0BAA0B,IAVrCb",
6
6
  "names": ["AltResolutionContextLoader_exports", "__export", "AltResolutionContextLoader", "__toCommonJS", "import_inversify", "import_purify_ts", "import_configTypes", "import_pkiTypes", "import_altResolutionTypes", "import_ClearSignContext", "import_challengeBoundLoader", "import_deviceModelIdCodec", "import_uIntCodec", "SUPPORTED_TYPES", "altResolutionRequestCodec", "solanaAltResolutionInputCodec", "AltResolutionContextLoader", "dataSource", "certificateLoader", "loggerFactory", "input", "expectedTypes", "t", "requests", "request", "value", "certificate", "payload", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var l=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var M=(n,t)=>{for(var e in t)l(n,e,{get:t[e],enumerable:!0})},k=(n,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of S(t))!T.call(n,o)&&o!==e&&l(n,o,{get:()=>t[o],enumerable:!(i=C(t,o))||i.enumerable});return n};var b=n=>k(l({},"__esModule",{value:!0}),n),g=(n,t,e,i)=>{for(var o=i>1?void 0:i?C(t,e):t,s=n.length-1,r;s>=0;s--)(r=n[s])&&(o=(i?r(t,e,o):r(o))||o);return i&&o&&l(t,e,o),o},I=(n,t)=>(e,i)=>t(e,i,n);var P={};M(P,{HttpInstructionInfoDataSource:()=>u});module.exports=b(P);var f=require("inversify"),a=require("purify-ts"),E=require("../../../../config/di/configTypes"),m=require("../../../../modules/solana/model/SolanaTransactionScanChainId"),y=require("../../../../shared/network/di/networkTypes"),D=require("./InstructionInfoDto"),p=require("./InstructionInfoMapper");const x={"solana-mainnet":m.SolanaTransactionScanChainId.MAINNET,"solana-devnet":m.SolanaTransactionScanChainId.DEVNET,"solana-testnet":m.SolanaTransactionScanChainId.TESTNET};let u=class{constructor(t,e){this.config=t;this.http=e}async getInstructionInfo({programId:t,network:e}){const i=x[e]??m.SolanaTransactionScanChainId.MAINNET;let o;try{o=await this.http.get(`${this.config.cal.url}/solana_programs`,{params:{id:t,chain_id:i,output:"id,chain_id,instructions",ref:`branch:${this.config.cal.branch}`}})}catch(r){const d=r instanceof Error?r.message:String(r);return(0,a.Left)(new Error(`[ContextModule] HttpInstructionInfoDataSource: Failed to fetch instruction descriptors: ${d}`))}if(!Array.isArray(o)||o.length===0)return(0,a.Left)(new Error(`[ContextModule] HttpInstructionInfoDataSource: empty response for program ${t}`));const s=o.find(r=>r!=null&&typeof r=="object"&&r.id===t);return s===void 0?(0,a.Left)(new Error(`[ContextModule] HttpInstructionInfoDataSource: no descriptors for program ${t}`)):D.calInstructionProgramCodec.decode(s).caseOf({Left:r=>(0,a.Left)(new Error(`[ContextModule] HttpInstructionInfoDataSource: malformed descriptors for program ${t}: ${r}`)),Right:()=>{const r=this.config.cal.mode??"prod",d=s.instructions,h=Object.fromEntries(d.map(c=>[c.discriminator_hex,c])),w=Object.fromEntries(Object.entries(h).map(([c,N])=>[c,(0,p.toInstructionInfoPayload)(t,c,N,r)]));return(0,a.Right)({programId:t,descriptors:w,enumVariants:(0,p.toProgramEnumVariants)(h,r)})}})}};u=g([(0,f.injectable)(),I(0,(0,f.inject)(E.configTypes.Config)),I(1,(0,f.inject)(y.networkTypes.NetworkClient))],u);0&&(module.exports={HttpInstructionInfoDataSource});
1
+ "use strict";var l=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var M=(n,t)=>{for(var e in t)l(n,e,{get:t[e],enumerable:!0})},k=(n,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of S(t))!T.call(n,o)&&o!==e&&l(n,o,{get:()=>t[o],enumerable:!(i=C(t,o))||i.enumerable});return n};var b=n=>k(l({},"__esModule",{value:!0}),n),g=(n,t,e,i)=>{for(var o=i>1?void 0:i?C(t,e):t,s=n.length-1,r;s>=0;s--)(r=n[s])&&(o=(i?r(t,e,o):r(o))||o);return i&&o&&l(t,e,o),o},I=(n,t)=>(e,i)=>t(e,i,n);var P={};M(P,{HttpInstructionInfoDataSource:()=>u});module.exports=b(P);var f=require("inversify"),a=require("purify-ts"),E=require("../../../../config/di/configTypes"),m=require("../../../../modules/solana/model/SolanaTransactionScanChainId"),y=require("../../../../shared/network/di/networkTypes"),D=require("./InstructionInfoDto"),p=require("./InstructionInfoMapper");const x={"solana-mainnet":m.SolanaTransactionScanChainId.MAINNET,"solana-devnet":m.SolanaTransactionScanChainId.DEVNET,"solana-testnet":m.SolanaTransactionScanChainId.TESTNET};let u=class{constructor(t,e){this.config=t;this.http=e}async getInstructionInfo({programId:t,network:e}){const i=x[e]??m.SolanaTransactionScanChainId.MAINNET;let o;try{o=await this.http.get(`${this.config.cal.url}/solana_programs`,{params:{id:t,chain_id:i,output:"id,chain_id,instructions",ref:`branch:${this.config.cal.branch}`}})}catch(r){const d=r instanceof Error?r.message:String(r);return(0,a.Left)(new Error(`[ContextModule] HttpInstructionInfoDataSource: Failed to fetch instruction descriptors: ${d}`))}if(!Array.isArray(o)||o.length===0)return(0,a.Left)(new Error(`[ContextModule] HttpInstructionInfoDataSource: empty response for program ${t}`));const s=o.find(r=>r!=null&&typeof r=="object"&&r.id===t);return s===void 0?(0,a.Left)(new Error(`[ContextModule] HttpInstructionInfoDataSource: no descriptors for program ${t}`)):D.calInstructionProgramCodec.decode(s).caseOf({Left:r=>(0,a.Left)(new Error(`[ContextModule] HttpInstructionInfoDataSource: malformed descriptors for program ${t}: ${r}`)),Right:()=>{const r=this.config.cal.mode??"prod",d=s.instructions,h=Object.fromEntries(d.map(c=>[c.discriminator_hex??"",c])),w=Object.fromEntries(Object.entries(h).map(([c,N])=>[c,(0,p.toInstructionInfoPayload)(t,c,N,r)]));return(0,a.Right)({programId:t,descriptors:w,enumVariants:(0,p.toProgramEnumVariants)(h,r)})}})}};u=g([(0,f.injectable)(),I(0,(0,f.inject)(E.configTypes.Config)),I(1,(0,f.inject)(y.networkTypes.NetworkClient))],u);0&&(module.exports={HttpInstructionInfoDataSource});
2
2
  //# sourceMappingURL=HttpInstructionInfoDataSource.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/modules/solana/instruction-info/data/HttpInstructionInfoDataSource.ts"],
4
- "sourcesContent": ["import { DmkNetworkClient } from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleServiceConfig } from \"@/config/model/ContextModuleConfig\";\nimport { SolanaTransactionScanChainId } from \"@/modules/solana/model/SolanaTransactionScanChainId\";\nimport { networkTypes } from \"@/shared/network/di/networkTypes\";\n\nimport {\n GetInstructionInfoParams,\n InstructionInfoDataSource,\n InstructionInfoResult,\n} from \"./InstructionInfoDataSource\";\nimport {\n type CalInstructionDescriptorDto,\n calInstructionProgramCodec,\n type CalInstructionProgramDto,\n} from \"./InstructionInfoDto\";\nimport {\n type CalMode,\n toInstructionInfoPayload,\n toProgramEnumVariants,\n} from \"./InstructionInfoMapper\";\n\n// Maps the DMK network label to the numeric CAL `chain_id` (the extended\n// Solana network ids 900/901/902). Unknown labels fall back to mainnet.\nconst CHAIN_ID_BY_NETWORK: Record<string, SolanaTransactionScanChainId> = {\n \"solana-mainnet\": SolanaTransactionScanChainId.MAINNET,\n \"solana-devnet\": SolanaTransactionScanChainId.DEVNET,\n \"solana-testnet\": SolanaTransactionScanChainId.TESTNET,\n};\n\n@injectable()\nexport class HttpInstructionInfoDataSource\n implements InstructionInfoDataSource\n{\n constructor(\n @inject(configTypes.Config)\n private readonly config: ContextModuleServiceConfig,\n @inject(networkTypes.NetworkClient)\n private readonly http: DmkNetworkClient,\n ) {}\n\n public async getInstructionInfo({\n programId,\n network,\n }: GetInstructionInfoParams): Promise<Either<Error, InstructionInfoResult>> {\n const chainId =\n CHAIN_ID_BY_NETWORK[network] ?? SolanaTransactionScanChainId.MAINNET;\n let data: unknown;\n try {\n data = await this.http.get(`${this.config.cal.url}/solana_programs`, {\n params: {\n id: programId,\n chain_id: chainId,\n output: \"id,chain_id,instructions\",\n ref: `branch:${this.config.cal.branch}`,\n },\n });\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n return Left(\n new Error(\n `[ContextModule] HttpInstructionInfoDataSource: Failed to fetch instruction descriptors: ${reason}`,\n ),\n );\n }\n\n if (!Array.isArray(data) || data.length === 0) {\n return Left(\n new Error(\n `[ContextModule] HttpInstructionInfoDataSource: empty response for program ${programId}`,\n ),\n );\n }\n\n // Select the program object whose `id` matches the requested `programId`\n // (the response is an array, one object per requested id).\n const program = data.find(\n (entry): entry is { id: unknown } =>\n entry != null &&\n typeof entry === \"object\" &&\n (entry as { id?: unknown }).id === programId,\n );\n if (program === undefined) {\n return Left(\n new Error(\n `[ContextModule] HttpInstructionInfoDataSource: no descriptors for program ${programId}`,\n ),\n );\n }\n\n // Validate the program shape so the mapper can dereference `descriptor` /\n // `enum_variants` without runtime-throwing on a malformed CAL payload. A\n // malformed program degrades to a per-program ERROR rather than rejecting\n // the batch. On success we transform each validated DTO into the core\n // payload so the loader never sees the CAL DTO shapes.\n return calInstructionProgramCodec\n .decode(program)\n .caseOf<Either<Error, InstructionInfoResult>>({\n Left: (error) =>\n Left(\n new Error(\n `[ContextModule] HttpInstructionInfoDataSource: malformed descriptors for program ${programId}: ${error}`,\n ),\n ),\n Right: () => {\n const mode: CalMode = this.config.cal.mode ?? \"prod\";\n // The codec strips undeclared fields, so we key the original\n // (full) instruction objects by `discriminator_hex` \u2014 the cast is\n // justified now that the shape has been validated.\n const instructions = (program as CalInstructionProgramDto)\n .instructions;\n const descriptorsByDiscriminator: Record<\n string,\n CalInstructionDescriptorDto\n > = Object.fromEntries(\n instructions.map((dto) => [dto.discriminator_hex, dto]),\n );\n const mapped = Object.fromEntries(\n Object.entries(descriptorsByDiscriminator).map(\n ([discriminator, dto]) => [\n discriminator,\n toInstructionInfoPayload(programId, discriminator, dto, mode),\n ],\n ),\n );\n return Right({\n programId,\n descriptors: mapped,\n enumVariants: toProgramEnumVariants(\n descriptorsByDiscriminator,\n mode,\n ),\n });\n },\n });\n }\n}\n"],
5
- "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mCAAAE,IAAA,eAAAC,EAAAH,GACA,IAAAI,EAAmC,qBACnCC,EAAoC,qBAEpCC,EAA4B,mCAE5BC,EAA6C,+DAC7CC,EAA6B,4CAO7BC,EAIO,gCACPC,EAIO,mCAIP,MAAMC,EAAoE,CACxE,iBAAkB,+BAA6B,QAC/C,gBAAiB,+BAA6B,OAC9C,iBAAkB,+BAA6B,OACjD,EAGO,IAAMC,EAAN,KAEP,CACE,YAEmBC,EAEAC,EACjB,CAHiB,YAAAD,EAEA,UAAAC,CAChB,CAEH,MAAa,mBAAmB,CAC9B,UAAAC,EACA,QAAAC,CACF,EAA4E,CAC1E,MAAMC,EACJN,EAAoBK,CAAO,GAAK,+BAA6B,QAC/D,IAAIE,EACJ,GAAI,CACFA,EAAO,MAAM,KAAK,KAAK,IAAI,GAAG,KAAK,OAAO,IAAI,GAAG,mBAAoB,CACnE,OAAQ,CACN,GAAIH,EACJ,SAAUE,EACV,OAAQ,2BACR,IAAK,UAAU,KAAK,OAAO,IAAI,MAAM,EACvC,CACF,CAAC,CACH,OAASE,EAAO,CACd,MAAMC,EAASD,aAAiB,MAAQA,EAAM,QAAU,OAAOA,CAAK,EACpE,SAAO,QACL,IAAI,MACF,2FAA2FC,CAAM,EACnG,CACF,CACF,CAEA,GAAI,CAAC,MAAM,QAAQF,CAAI,GAAKA,EAAK,SAAW,EAC1C,SAAO,QACL,IAAI,MACF,6EAA6EH,CAAS,EACxF,CACF,EAKF,MAAMM,EAAUH,EAAK,KAClBI,GACCA,GAAS,MACT,OAAOA,GAAU,UAChBA,EAA2B,KAAOP,CACvC,EACA,OAAIM,IAAY,UACP,QACL,IAAI,MACF,6EAA6EN,CAAS,EACxF,CACF,EAQK,6BACJ,OAAOM,CAAO,EACd,OAA6C,CAC5C,KAAOF,MACL,QACE,IAAI,MACF,oFAAoFJ,CAAS,KAAKI,CAAK,EACzG,CACF,EACF,MAAO,IAAM,CACX,MAAMI,EAAgB,KAAK,OAAO,IAAI,MAAQ,OAIxCC,EAAgBH,EACnB,aACGI,EAGF,OAAO,YACTD,EAAa,IAAKE,GAAQ,CAACA,EAAI,kBAAmBA,CAAG,CAAC,CACxD,EACMC,EAAS,OAAO,YACpB,OAAO,QAAQF,CAA0B,EAAE,IACzC,CAAC,CAACG,EAAeF,CAAG,IAAM,CACxBE,KACA,4BAAyBb,EAAWa,EAAeF,EAAKH,CAAI,CAC9D,CACF,CACF,EACA,SAAO,SAAM,CACX,UAAAR,EACA,YAAaY,EACb,gBAAc,yBACZF,EACAF,CACF,CACF,CAAC,CACH,CACF,CAAC,CACL,CACF,EAzGaX,EAANiB,EAAA,IADN,cAAW,EAKPC,EAAA,eAAO,cAAY,MAAM,GAEzBA,EAAA,eAAO,eAAa,aAAa,IANzBlB",
4
+ "sourcesContent": ["import { DmkNetworkClient } from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleServiceConfig } from \"@/config/model/ContextModuleConfig\";\nimport { SolanaTransactionScanChainId } from \"@/modules/solana/model/SolanaTransactionScanChainId\";\nimport { networkTypes } from \"@/shared/network/di/networkTypes\";\n\nimport {\n GetInstructionInfoParams,\n InstructionInfoDataSource,\n InstructionInfoResult,\n} from \"./InstructionInfoDataSource\";\nimport {\n type CalInstructionDescriptorDto,\n calInstructionProgramCodec,\n type CalInstructionProgramDto,\n} from \"./InstructionInfoDto\";\nimport {\n type CalMode,\n toInstructionInfoPayload,\n toProgramEnumVariants,\n} from \"./InstructionInfoMapper\";\n\n// Maps the DMK network label to the numeric CAL `chain_id` (the extended\n// Solana network ids 900/901/902). Unknown labels fall back to mainnet.\nconst CHAIN_ID_BY_NETWORK: Record<string, SolanaTransactionScanChainId> = {\n \"solana-mainnet\": SolanaTransactionScanChainId.MAINNET,\n \"solana-devnet\": SolanaTransactionScanChainId.DEVNET,\n \"solana-testnet\": SolanaTransactionScanChainId.TESTNET,\n};\n\n@injectable()\nexport class HttpInstructionInfoDataSource\n implements InstructionInfoDataSource\n{\n constructor(\n @inject(configTypes.Config)\n private readonly config: ContextModuleServiceConfig,\n @inject(networkTypes.NetworkClient)\n private readonly http: DmkNetworkClient,\n ) {}\n\n public async getInstructionInfo({\n programId,\n network,\n }: GetInstructionInfoParams): Promise<Either<Error, InstructionInfoResult>> {\n const chainId =\n CHAIN_ID_BY_NETWORK[network] ?? SolanaTransactionScanChainId.MAINNET;\n let data: unknown;\n try {\n data = await this.http.get(`${this.config.cal.url}/solana_programs`, {\n params: {\n id: programId,\n chain_id: chainId,\n output: \"id,chain_id,instructions\",\n ref: `branch:${this.config.cal.branch}`,\n },\n });\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n return Left(\n new Error(\n `[ContextModule] HttpInstructionInfoDataSource: Failed to fetch instruction descriptors: ${reason}`,\n ),\n );\n }\n\n if (!Array.isArray(data) || data.length === 0) {\n return Left(\n new Error(\n `[ContextModule] HttpInstructionInfoDataSource: empty response for program ${programId}`,\n ),\n );\n }\n\n // Select the program object whose `id` matches the requested `programId`\n // (the response is an array, one object per requested id).\n const program = data.find(\n (entry): entry is { id: unknown } =>\n entry != null &&\n typeof entry === \"object\" &&\n (entry as { id?: unknown }).id === programId,\n );\n if (program === undefined) {\n return Left(\n new Error(\n `[ContextModule] HttpInstructionInfoDataSource: no descriptors for program ${programId}`,\n ),\n );\n }\n\n // Validate the program shape so the mapper can dereference `descriptor` /\n // `enum_variants` without runtime-throwing on a malformed CAL payload. A\n // malformed program degrades to a per-program ERROR rather than rejecting\n // the batch. On success we transform each validated DTO into the core\n // payload so the loader never sees the CAL DTO shapes.\n return calInstructionProgramCodec\n .decode(program)\n .caseOf<Either<Error, InstructionInfoResult>>({\n Left: (error) =>\n Left(\n new Error(\n `[ContextModule] HttpInstructionInfoDataSource: malformed descriptors for program ${programId}: ${error}`,\n ),\n ),\n Right: () => {\n const mode: CalMode = this.config.cal.mode ?? \"prod\";\n // The codec strips undeclared fields, so we key the original\n // (full) instruction objects by `discriminator_hex` \u2014 the cast is\n // justified now that the shape has been validated. A descriptor\n // without a discriminator (single-instruction programs such as SPL\n // Memo) is keyed under the empty string.\n const instructions = (program as CalInstructionProgramDto)\n .instructions;\n const descriptorsByDiscriminator: Record<\n string,\n CalInstructionDescriptorDto\n > = Object.fromEntries(\n instructions.map((dto) => [dto.discriminator_hex ?? \"\", dto]),\n );\n const mapped = Object.fromEntries(\n Object.entries(descriptorsByDiscriminator).map(\n ([discriminator, dto]) => [\n discriminator,\n toInstructionInfoPayload(programId, discriminator, dto, mode),\n ],\n ),\n );\n return Right({\n programId,\n descriptors: mapped,\n enumVariants: toProgramEnumVariants(\n descriptorsByDiscriminator,\n mode,\n ),\n });\n },\n });\n }\n}\n"],
5
+ "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EA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,OAMxCC,EAAgBH,EACnB,aACGI,EAGF,OAAO,YACTD,EAAa,IAAKE,GAAQ,CAACA,EAAI,mBAAqB,GAAIA,CAAG,CAAC,CAC9D,EACMC,EAAS,OAAO,YACpB,OAAO,QAAQF,CAA0B,EAAE,IACzC,CAAC,CAACG,EAAeF,CAAG,IAAM,CACxBE,KACA,4BAAyBb,EAAWa,EAAeF,EAAKH,CAAI,CAC9D,CACF,CACF,EACA,SAAO,SAAM,CACX,UAAAR,EACA,YAAaY,EACb,gBAAc,yBACZF,EACAF,CACF,CACF,CAAC,CACH,CACF,CAAC,CACL,CACF,EA3GaX,EAANiB,EAAA,IADN,cAAW,EAKPC,EAAA,eAAO,cAAY,MAAM,GAEzBA,EAAA,eAAO,eAAa,aAAa,IANzBlB",
6
6
  "names": ["HttpInstructionInfoDataSource_exports", "__export", "HttpInstructionInfoDataSource", "__toCommonJS", "import_inversify", "import_purify_ts", "import_configTypes", "import_SolanaTransactionScanChainId", "import_networkTypes", "import_InstructionInfoDto", "import_InstructionInfoMapper", "CHAIN_ID_BY_NETWORK", "HttpInstructionInfoDataSource", "config", "http", "programId", "network", "chainId", "data", "error", "reason", "program", "entry", "mode", "instructions", "descriptorsByDiscriminator", "dto", "mapped", "discriminator", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var a=require("purify-ts"),t=require("vitest"),i=require("../../../../modules/solana/model/SolanaTransactionScanChainId"),u=require("./HttpInstructionInfoDataSource");(0,t.describe)("HttpInstructionInfoDataSource",()=>{let r,o;const e="11111111111111111111111111111111",s="solana-mainnet",l={cal:{url:"https://global.api.prd.ledger.com/cal/v1",mode:"prod",branch:"main"}},c=[{id:e,chain_id:i.SolanaTransactionScanChainId.MAINNET,instructions:[{discriminator_hex:"00000000",instruction_name:"createAccount",descriptor:{data:"00010101",signatures:{prod:"prodsig",test:"testsig"}},display_fields:[],value_flow_ports:[],hide_rules:[],account_resets:[]}]}];(0,t.beforeEach)(()=>{t.vi.clearAllMocks(),o={get:t.vi.fn()},r=new u.HttpInstructionInfoDataSource(l,o)}),(0,t.it)("calls CAL /solana_programs with id, chain_id and output params",async()=>{o.get.mockResolvedValue(c),await r.getInstructionInfo({programId:e,network:s}),(0,t.expect)(o.get).toHaveBeenCalledTimes(1),(0,t.expect)(o.get).toHaveBeenCalledWith("https://global.api.prd.ledger.com/cal/v1/solana_programs",{params:{id:e,chain_id:i.SolanaTransactionScanChainId.MAINNET,output:"id,chain_id,instructions",ref:"branch:main"}})}),(0,t.it)("maps devnet/testnet networks to their numeric chain ids",async()=>{o.get.mockResolvedValue(c),await r.getInstructionInfo({programId:e,network:"solana-devnet"}),(0,t.expect)(o.get).toHaveBeenCalledWith("https://global.api.prd.ledger.com/cal/v1/solana_programs",t.expect.objectContaining({params:t.expect.objectContaining({chain_id:901})}))}),(0,t.it)("returns Right with each descriptor transformed into the core payload on success",async()=>{o.get.mockResolvedValue(c);const n=await r.getInstructionInfo({programId:e,network:s});(0,t.expect)(n).toEqual((0,a.Right)({programId:e,descriptors:{"00000000":(0,a.Right)({programId:e,discriminator:"00000000",instructionInfo:{data:"00010101",signature:"prodsig"},substructures:[],enumVariants:[],idlDescriptor:{typePool:[],rootType:0},mintAssociations:[],valueFlowPorts:[],accountResets:[],displayFields:[]})},enumVariants:[]}))}),(0,t.it)("returns Left when the response array is empty",async()=>{o.get.mockResolvedValue([]);const n=await r.getInstructionInfo({programId:e,network:s});(0,t.expect)(n).toEqual((0,a.Left)(new Error(`[ContextModule] HttpInstructionInfoDataSource: empty response for program ${e}`)))}),(0,t.it)("returns Left when no program object matches the requested programId",async()=>{o.get.mockResolvedValue([{id:"OtherProgram",chain_id:i.SolanaTransactionScanChainId.MAINNET,instructions:[]}]);const n=await r.getInstructionInfo({programId:e,network:s});(0,t.expect)(n).toEqual((0,a.Left)(new Error(`[ContextModule] HttpInstructionInfoDataSource: no descriptors for program ${e}`)))}),(0,t.it)("returns Left (not a throw) when an instruction descriptor is malformed",async()=>{o.get.mockResolvedValue([{id:e,chain_id:i.SolanaTransactionScanChainId.MAINNET,instructions:[{discriminator_hex:"00000000"}]}]);const n=await r.getInstructionInfo({programId:e,network:s});(0,t.expect)(n.isLeft()).toBe(!0),(0,t.expect)(n.extract().message).toMatch(new RegExp(String.raw`\[ContextModule\] HttpInstructionInfoDataSource: malformed descriptors for program ${e}:`))}),(0,t.it)("returns Left when the HTTP client throws",async()=>{o.get.mockRejectedValue(new Error("network"));const n=await r.getInstructionInfo({programId:e,network:s});(0,t.expect)(n).toEqual((0,a.Left)(new Error("[ContextModule] HttpInstructionInfoDataSource: Failed to fetch instruction descriptors: network")))})});
1
+ "use strict";var a=require("purify-ts"),t=require("vitest"),i=require("../../../../modules/solana/model/SolanaTransactionScanChainId"),d=require("./HttpInstructionInfoDataSource");(0,t.describe)("HttpInstructionInfoDataSource",()=>{let r,o;const e="11111111111111111111111111111111",s="solana-mainnet",l={cal:{url:"https://global.api.prd.ledger.com/cal/v1",mode:"prod",branch:"main"}},c=[{id:e,chain_id:i.SolanaTransactionScanChainId.MAINNET,instructions:[{discriminator_hex:"00000000",instruction_name:"createAccount",descriptor:{data:"00010101",signatures:{prod:"prodsig",test:"testsig"}},display_fields:[],value_flow_ports:[],hide_rules:[],account_resets:[]}]}];(0,t.beforeEach)(()=>{t.vi.clearAllMocks(),o={get:t.vi.fn()},r=new d.HttpInstructionInfoDataSource(l,o)}),(0,t.it)("calls CAL /solana_programs with id, chain_id and output params",async()=>{o.get.mockResolvedValue(c),await r.getInstructionInfo({programId:e,network:s}),(0,t.expect)(o.get).toHaveBeenCalledTimes(1),(0,t.expect)(o.get).toHaveBeenCalledWith("https://global.api.prd.ledger.com/cal/v1/solana_programs",{params:{id:e,chain_id:i.SolanaTransactionScanChainId.MAINNET,output:"id,chain_id,instructions",ref:"branch:main"}})}),(0,t.it)("maps devnet/testnet networks to their numeric chain ids",async()=>{o.get.mockResolvedValue(c),await r.getInstructionInfo({programId:e,network:"solana-devnet"}),(0,t.expect)(o.get).toHaveBeenCalledWith("https://global.api.prd.ledger.com/cal/v1/solana_programs",t.expect.objectContaining({params:t.expect.objectContaining({chain_id:901})}))}),(0,t.it)("returns Right with each descriptor transformed into the core payload on success",async()=>{o.get.mockResolvedValue(c);const n=await r.getInstructionInfo({programId:e,network:s});(0,t.expect)(n).toEqual((0,a.Right)({programId:e,descriptors:{"00000000":(0,a.Right)({programId:e,discriminator:"00000000",instructionInfo:{data:"00010101",signature:"prodsig"},substructures:[],enumVariants:[],idlDescriptor:{typePool:[],rootType:0},mintAssociations:[],valueFlowPorts:[],accountResets:[],displayFields:[]})},enumVariants:[]}))}),(0,t.it)("keys a descriptor without `discriminator_hex` under the empty string",async()=>{o.get.mockResolvedValue([{id:e,chain_id:i.SolanaTransactionScanChainId.MAINNET,instructions:[{instruction_name:"addMemo",descriptor:{data:"00010101",signatures:{prod:"prodsig",test:"testsig"}}}]}]);const n=await r.getInstructionInfo({programId:e,network:s});(0,t.expect)(n.isRight()).toBe(!0);const{descriptors:u}=n.unsafeCoerce();(0,t.expect)(Object.keys(u)).toEqual([""]),(0,t.expect)(u[""].unsafeCoerce()).toEqual(t.expect.objectContaining({programId:e,discriminator:"",instructionInfo:{data:"00010101",signature:"prodsig"}}))}),(0,t.it)("returns Left when the response array is empty",async()=>{o.get.mockResolvedValue([]);const n=await r.getInstructionInfo({programId:e,network:s});(0,t.expect)(n).toEqual((0,a.Left)(new Error(`[ContextModule] HttpInstructionInfoDataSource: empty response for program ${e}`)))}),(0,t.it)("returns Left when no program object matches the requested programId",async()=>{o.get.mockResolvedValue([{id:"OtherProgram",chain_id:i.SolanaTransactionScanChainId.MAINNET,instructions:[]}]);const n=await r.getInstructionInfo({programId:e,network:s});(0,t.expect)(n).toEqual((0,a.Left)(new Error(`[ContextModule] HttpInstructionInfoDataSource: no descriptors for program ${e}`)))}),(0,t.it)("returns Left (not a throw) when an instruction descriptor is malformed",async()=>{o.get.mockResolvedValue([{id:e,chain_id:i.SolanaTransactionScanChainId.MAINNET,instructions:[{discriminator_hex:"00000000"}]}]);const n=await r.getInstructionInfo({programId:e,network:s});(0,t.expect)(n.isLeft()).toBe(!0),(0,t.expect)(n.extract().message).toMatch(new RegExp(String.raw`\[ContextModule\] HttpInstructionInfoDataSource: malformed descriptors for program ${e}:`))}),(0,t.it)("returns Left when the HTTP client throws",async()=>{o.get.mockRejectedValue(new Error("network"));const n=await r.getInstructionInfo({programId:e,network:s});(0,t.expect)(n).toEqual((0,a.Left)(new Error("[ContextModule] HttpInstructionInfoDataSource: Failed to fetch instruction descriptors: network")))})});
2
2
  //# sourceMappingURL=HttpInstructionInfoDataSource.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/modules/solana/instruction-info/data/HttpInstructionInfoDataSource.test.ts"],
4
- "sourcesContent": ["import { type DmkNetworkClient } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\nimport { beforeEach, describe, expect, it, vi } from \"vitest\";\n\nimport { type ContextModuleServiceConfig } from \"@/config/model/ContextModuleConfig\";\nimport { SolanaTransactionScanChainId } from \"@/modules/solana/model/SolanaTransactionScanChainId\";\n\nimport { HttpInstructionInfoDataSource } from \"./HttpInstructionInfoDataSource\";\nimport { type InstructionInfoDataSource } from \"./InstructionInfoDataSource\";\nimport { type CalInstructionInfoResponseDto } from \"./InstructionInfoDto\";\n\ndescribe(\"HttpInstructionInfoDataSource\", () => {\n let datasource: InstructionInfoDataSource;\n let httpMock: { get: ReturnType<typeof vi.fn> };\n const programId = \"11111111111111111111111111111111\";\n const network = \"solana-mainnet\";\n const config: ContextModuleServiceConfig = {\n cal: {\n url: \"https://global.api.prd.ledger.com/cal/v1\",\n mode: \"prod\",\n branch: \"main\",\n },\n } as ContextModuleServiceConfig;\n\n const successResponse: CalInstructionInfoResponseDto = [\n {\n id: programId,\n chain_id: SolanaTransactionScanChainId.MAINNET,\n instructions: [\n {\n discriminator_hex: \"00000000\",\n instruction_name: \"createAccount\",\n descriptor: {\n data: \"00010101\",\n signatures: { prod: \"prodsig\", test: \"testsig\" },\n },\n display_fields: [],\n value_flow_ports: [],\n hide_rules: [],\n account_resets: [],\n },\n ],\n },\n ];\n\n beforeEach(() => {\n vi.clearAllMocks();\n httpMock = { get: vi.fn() };\n datasource = new HttpInstructionInfoDataSource(\n config,\n httpMock as unknown as DmkNetworkClient,\n );\n });\n\n it(\"calls CAL /solana_programs with id, chain_id and output params\", async () => {\n httpMock.get.mockResolvedValue(successResponse);\n\n await datasource.getInstructionInfo({ programId, network });\n\n expect(httpMock.get).toHaveBeenCalledTimes(1);\n expect(httpMock.get).toHaveBeenCalledWith(\n \"https://global.api.prd.ledger.com/cal/v1/solana_programs\",\n {\n params: {\n id: programId,\n chain_id: SolanaTransactionScanChainId.MAINNET,\n output: \"id,chain_id,instructions\",\n ref: \"branch:main\",\n },\n },\n );\n });\n\n it(\"maps devnet/testnet networks to their numeric chain ids\", async () => {\n httpMock.get.mockResolvedValue(successResponse);\n\n await datasource.getInstructionInfo({\n programId,\n network: \"solana-devnet\",\n });\n\n expect(httpMock.get).toHaveBeenCalledWith(\n \"https://global.api.prd.ledger.com/cal/v1/solana_programs\",\n expect.objectContaining({\n params: expect.objectContaining({ chain_id: 901 }),\n }),\n );\n });\n\n it(\"returns Right with each descriptor transformed into the core payload on success\", async () => {\n httpMock.get.mockResolvedValue(successResponse);\n\n const result = await datasource.getInstructionInfo({ programId, network });\n\n expect(result).toEqual(\n Right({\n programId,\n descriptors: {\n \"00000000\": Right({\n programId,\n discriminator: \"00000000\",\n instructionInfo: { data: \"00010101\", signature: \"prodsig\" },\n substructures: [],\n enumVariants: [],\n idlDescriptor: { typePool: [], rootType: 0 },\n mintAssociations: [],\n valueFlowPorts: [],\n accountResets: [],\n displayFields: [],\n }),\n },\n enumVariants: [],\n }),\n );\n });\n\n it(\"returns Left when the response array is empty\", async () => {\n httpMock.get.mockResolvedValue([]);\n\n const result = await datasource.getInstructionInfo({ programId, network });\n\n expect(result).toEqual(\n Left(\n new Error(\n `[ContextModule] HttpInstructionInfoDataSource: empty response for program ${programId}`,\n ),\n ),\n );\n });\n\n it(\"returns Left when no program object matches the requested programId\", async () => {\n httpMock.get.mockResolvedValue([\n {\n id: \"OtherProgram\",\n chain_id: SolanaTransactionScanChainId.MAINNET,\n instructions: [],\n },\n ]);\n\n const result = await datasource.getInstructionInfo({ programId, network });\n\n expect(result).toEqual(\n Left(\n new Error(\n `[ContextModule] HttpInstructionInfoDataSource: no descriptors for program ${programId}`,\n ),\n ),\n );\n });\n\n it(\"returns Left (not a throw) when an instruction descriptor is malformed\", async () => {\n // `descriptor` missing on the instruction \u2014 would crash the loader if the\n // datasource handed it through unvalidated.\n httpMock.get.mockResolvedValue([\n {\n id: programId,\n chain_id: SolanaTransactionScanChainId.MAINNET,\n instructions: [{ discriminator_hex: \"00000000\" }],\n },\n ]);\n\n const result = await datasource.getInstructionInfo({ programId, network });\n\n expect(result.isLeft()).toBe(true);\n expect((result.extract() as Error).message).toMatch(\n new RegExp(\n String.raw`\\[ContextModule\\] HttpInstructionInfoDataSource: malformed descriptors for program ${programId}:`,\n ),\n );\n });\n\n it(\"returns Left when the HTTP client throws\", async () => {\n httpMock.get.mockRejectedValue(new Error(\"network\"));\n\n const result = await datasource.getInstructionInfo({ programId, network });\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpInstructionInfoDataSource: Failed to fetch instruction descriptors: network\",\n ),\n ),\n );\n });\n});\n"],
5
- "mappings": "aACA,IAAAA,EAA4B,qBAC5BC,EAAqD,kBAGrDC,EAA6C,+DAE7CC,EAA8C,8CAI9C,YAAS,gCAAiC,IAAM,CAC9C,IAAIC,EACAC,EACJ,MAAMC,EAAY,mCACZC,EAAU,iBACVC,EAAqC,CACzC,IAAK,CACH,IAAK,2CACL,KAAM,OACN,OAAQ,MACV,CACF,EAEMC,EAAiD,CACrD,CACE,GAAIH,EACJ,SAAU,+BAA6B,QACvC,aAAc,CACZ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AAE,EAAW,QAAAC,CAAQ,CAAC,KAEzE,UAAOG,CAAM,EAAE,WACb,QACE,IAAI,MACF,iGACF,CACF,CACF,CACF,CAAC,CACH,CAAC",
6
- "names": ["import_purify_ts", "import_vitest", "import_SolanaTransactionScanChainId", "import_HttpInstructionInfoDataSource", "datasource", "httpMock", "programId", "network", "config", "successResponse", "result"]
4
+ "sourcesContent": ["import { type DmkNetworkClient } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\nimport { beforeEach, describe, expect, it, vi } from \"vitest\";\n\nimport { type ContextModuleServiceConfig } from \"@/config/model/ContextModuleConfig\";\nimport { SolanaTransactionScanChainId } from \"@/modules/solana/model/SolanaTransactionScanChainId\";\n\nimport { HttpInstructionInfoDataSource } from \"./HttpInstructionInfoDataSource\";\nimport { type InstructionInfoDataSource } from \"./InstructionInfoDataSource\";\nimport { type CalInstructionInfoResponseDto } from \"./InstructionInfoDto\";\n\ndescribe(\"HttpInstructionInfoDataSource\", () => {\n let datasource: InstructionInfoDataSource;\n let httpMock: { get: ReturnType<typeof vi.fn> };\n const programId = \"11111111111111111111111111111111\";\n const network = \"solana-mainnet\";\n const config: ContextModuleServiceConfig = {\n cal: {\n url: \"https://global.api.prd.ledger.com/cal/v1\",\n mode: \"prod\",\n branch: \"main\",\n },\n } as ContextModuleServiceConfig;\n\n const successResponse: CalInstructionInfoResponseDto = [\n {\n id: programId,\n chain_id: SolanaTransactionScanChainId.MAINNET,\n instructions: [\n {\n discriminator_hex: \"00000000\",\n instruction_name: \"createAccount\",\n descriptor: {\n data: \"00010101\",\n signatures: { prod: \"prodsig\", test: \"testsig\" },\n },\n display_fields: [],\n value_flow_ports: [],\n hide_rules: [],\n account_resets: [],\n },\n ],\n },\n ];\n\n beforeEach(() => {\n vi.clearAllMocks();\n httpMock = { get: vi.fn() };\n datasource = new HttpInstructionInfoDataSource(\n config,\n httpMock as unknown as DmkNetworkClient,\n );\n });\n\n it(\"calls CAL /solana_programs with id, chain_id and output params\", async () => {\n httpMock.get.mockResolvedValue(successResponse);\n\n await datasource.getInstructionInfo({ programId, network });\n\n expect(httpMock.get).toHaveBeenCalledTimes(1);\n expect(httpMock.get).toHaveBeenCalledWith(\n \"https://global.api.prd.ledger.com/cal/v1/solana_programs\",\n {\n params: {\n id: programId,\n chain_id: SolanaTransactionScanChainId.MAINNET,\n output: \"id,chain_id,instructions\",\n ref: \"branch:main\",\n },\n },\n );\n });\n\n it(\"maps devnet/testnet networks to their numeric chain ids\", async () => {\n httpMock.get.mockResolvedValue(successResponse);\n\n await datasource.getInstructionInfo({\n programId,\n network: \"solana-devnet\",\n });\n\n expect(httpMock.get).toHaveBeenCalledWith(\n \"https://global.api.prd.ledger.com/cal/v1/solana_programs\",\n expect.objectContaining({\n params: expect.objectContaining({ chain_id: 901 }),\n }),\n );\n });\n\n it(\"returns Right with each descriptor transformed into the core payload on success\", async () => {\n httpMock.get.mockResolvedValue(successResponse);\n\n const result = await datasource.getInstructionInfo({ programId, network });\n\n expect(result).toEqual(\n Right({\n programId,\n descriptors: {\n \"00000000\": Right({\n programId,\n discriminator: \"00000000\",\n instructionInfo: { data: \"00010101\", signature: \"prodsig\" },\n substructures: [],\n enumVariants: [],\n idlDescriptor: { typePool: [], rootType: 0 },\n mintAssociations: [],\n valueFlowPorts: [],\n accountResets: [],\n displayFields: [],\n }),\n },\n enumVariants: [],\n }),\n );\n });\n\n it(\"keys a descriptor without `discriminator_hex` under the empty string\", async () => {\n // Single-instruction programs (e.g. SPL Memo `addMemo`) genuinely have no\n // discriminator, so CAL omits the field.\n httpMock.get.mockResolvedValue([\n {\n id: programId,\n chain_id: SolanaTransactionScanChainId.MAINNET,\n instructions: [\n {\n instruction_name: \"addMemo\",\n descriptor: {\n data: \"00010101\",\n signatures: { prod: \"prodsig\", test: \"testsig\" },\n },\n },\n ],\n },\n ]);\n\n const result = await datasource.getInstructionInfo({ programId, network });\n\n expect(result.isRight()).toBe(true);\n const { descriptors } = result.unsafeCoerce();\n expect(Object.keys(descriptors)).toEqual([\"\"]);\n expect(descriptors[\"\"]!.unsafeCoerce()).toEqual(\n expect.objectContaining({\n programId,\n discriminator: \"\",\n instructionInfo: { data: \"00010101\", signature: \"prodsig\" },\n }),\n );\n });\n\n it(\"returns Left when the response array is empty\", async () => {\n httpMock.get.mockResolvedValue([]);\n\n const result = await datasource.getInstructionInfo({ programId, network });\n\n expect(result).toEqual(\n Left(\n new Error(\n `[ContextModule] HttpInstructionInfoDataSource: empty response for program ${programId}`,\n ),\n ),\n );\n });\n\n it(\"returns Left when no program object matches the requested programId\", async () => {\n httpMock.get.mockResolvedValue([\n {\n id: \"OtherProgram\",\n chain_id: SolanaTransactionScanChainId.MAINNET,\n instructions: [],\n },\n ]);\n\n const result = await datasource.getInstructionInfo({ programId, network });\n\n expect(result).toEqual(\n Left(\n new Error(\n `[ContextModule] HttpInstructionInfoDataSource: no descriptors for program ${programId}`,\n ),\n ),\n );\n });\n\n it(\"returns Left (not a throw) when an instruction descriptor is malformed\", async () => {\n // `descriptor` missing on the instruction \u2014 would crash the loader if the\n // datasource handed it through unvalidated.\n httpMock.get.mockResolvedValue([\n {\n id: programId,\n chain_id: SolanaTransactionScanChainId.MAINNET,\n instructions: [{ discriminator_hex: \"00000000\" }],\n },\n ]);\n\n const result = await datasource.getInstructionInfo({ programId, network });\n\n expect(result.isLeft()).toBe(true);\n expect((result.extract() as Error).message).toMatch(\n new RegExp(\n String.raw`\\[ContextModule\\] HttpInstructionInfoDataSource: malformed descriptors for program ${programId}:`,\n ),\n );\n });\n\n it(\"returns Left when the HTTP client throws\", async () => {\n httpMock.get.mockRejectedValue(new Error(\"network\"));\n\n const result = await datasource.getInstructionInfo({ programId, network });\n\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpInstructionInfoDataSource: Failed to fetch instruction descriptors: network\",\n ),\n ),\n );\n });\n});\n"],
5
+ "mappings": "aACA,IAAAA,EAA4B,qBAC5BC,EAAqD,kBAGrDC,EAA6C,+DAE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,IAAI,MACF,6EAA6EJ,CAAS,EACxF,CACF,CACF,CACF,CAAC,KAED,MAAG,sEAAuE,SAAY,CACpFD,EAAS,IAAI,kBAAkB,CAC7B,CACE,GAAI,eACJ,SAAU,+BAA6B,QACvC,aAAc,CAAC,CACjB,CACF,CAAC,EAED,MAAMK,EAAS,MAAMN,EAAW,mBAAmB,CAAE,UAAAE,EAAW,QAAAC,CAAQ,CAAC,KAEzE,UAAOG,CAAM,EAAE,WACb,QACE,IAAI,MACF,6EAA6EJ,CAAS,EACxF,CACF,CACF,CACF,CAAC,KAED,MAAG,yEAA0E,SAAY,CAGvFD,EAAS,IAAI,kBAAkB,CAC7B,CACE,GAAIC,EACJ,SAAU,+BAA6B,QACvC,aAAc,CAAC,CAAE,kBAAmB,UAAW,CAAC,CAClD,CACF,CAAC,EAED,MAAMI,EAAS,MAAMN,EAAW,mBAAmB,CAAE,UAAAE,EAAW,QAAAC,CAAQ,CAAC,KAEzE,UAAOG,EAAO,OAAO,CAAC,EAAE,KAAK,EAAI,KACjC,UAAQA,EAAO,QAAQ,EAAY,OAAO,EAAE,QAC1C,IAAI,OACF,OAAO,yFAAyFJ,CAAS,GAC3G,CACF,CACF,CAAC,KAED,MAAG,2CAA4C,SAAY,CACzDD,EAAS,IAAI,kBAAkB,IAAI,MAAM,SAAS,CAAC,EAEnD,MAAMK,EAAS,MAAMN,EAAW,mBAAmB,CAAE,UAAAE,EAAW,QAAAC,CAAQ,CAAC,KAEzE,UAAOG,CAAM,EAAE,WACb,QACE,IAAI,MACF,iGACF,CACF,CACF,CACF,CAAC,CACH,CAAC",
6
+ "names": ["import_purify_ts", "import_vitest", "import_SolanaTransactionScanChainId", "import_HttpInstructionInfoDataSource", "datasource", "httpMock", "programId", "network", "config", "successResponse", "result", "descriptors"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var a=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var d=(r,e)=>{for(var o in e)a(r,o,{get:e[o],enumerable:!0})},_=(r,e,o,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of l(e))!p.call(r,n)&&n!==o&&a(r,n,{get:()=>e[n],enumerable:!(s=u(e,n))||s.enumerable});return r};var C=r=>_(a({},"__esModule",{value:!0}),r);var b={};d(b,{calInstructionProgramCodec:()=>y});module.exports=C(b);var t=require("purify-ts");const D=t.Codec.interface({prod:(0,t.optional)(t.string),test:(0,t.optional)(t.string)}),c=t.Codec.interface({data:t.string,signatures:D}),g=t.Codec.interface({descriptor:c}),i=t.Codec.interface({descriptor:t.string}),m=t.Codec.interface({discriminator_hex:t.string,descriptor:c,enum_variants:(0,t.optional)((0,t.record)(t.string,(0,t.record)(t.string,g))),display_fields:(0,t.optional)((0,t.array)(i)),value_flow_ports:(0,t.optional)((0,t.array)(i)),hide_rules:(0,t.optional)((0,t.array)(i)),account_resets:(0,t.optional)((0,t.array)(i))}),y=t.Codec.interface({id:t.string,chain_id:t.number,instructions:(0,t.array)(m)});0&&(module.exports={calInstructionProgramCodec});
1
+ "use strict";var a=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var d=(r,e)=>{for(var o in e)a(r,o,{get:e[o],enumerable:!0})},_=(r,e,o,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of l(e))!p.call(r,n)&&n!==o&&a(r,n,{get:()=>e[n],enumerable:!(s=u(e,n))||s.enumerable});return r};var C=r=>_(a({},"__esModule",{value:!0}),r);var b={};d(b,{calInstructionProgramCodec:()=>y});module.exports=C(b);var t=require("purify-ts");const D=t.Codec.interface({prod:(0,t.optional)(t.string),test:(0,t.optional)(t.string)}),c=t.Codec.interface({data:t.string,signatures:D}),g=t.Codec.interface({descriptor:c}),i=t.Codec.interface({descriptor:t.string}),m=t.Codec.interface({discriminator_hex:(0,t.optional)(t.string),descriptor:c,enum_variants:(0,t.optional)((0,t.record)(t.string,(0,t.record)(t.string,g))),display_fields:(0,t.optional)((0,t.array)(i)),value_flow_ports:(0,t.optional)((0,t.array)(i)),hide_rules:(0,t.optional)((0,t.array)(i)),account_resets:(0,t.optional)((0,t.array)(i))}),y=t.Codec.interface({id:t.string,chain_id:t.number,instructions:(0,t.array)(m)});0&&(module.exports={calInstructionProgramCodec});
2
2
  //# sourceMappingURL=InstructionInfoDto.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/modules/solana/instruction-info/data/InstructionInfoDto.ts"],
4
- "sourcesContent": ["// DTO + codecs for the CAL instruction-descriptors response (one object per\n// `programId`, wrapped in a JSON array).\n//\n// The hand-written types describe the consumed shape (with genuinely optional\n// `?:` fields); the codecs below validate that shape at runtime so\n// `HttpInstructionInfoDataSource` can hand the loaders a payload they can\n// dereference without runtime-throwing on a malformed descriptor.\n\nimport { array, Codec, number, optional, record, string } from \"purify-ts\";\n\nexport type CalSignatures = {\n prod?: string;\n test?: string;\n};\n\nexport type CalSignedDescriptorDto = {\n data: string;\n signatures: CalSignatures;\n};\n\n// Decoded CAL JSON shapes (snake_case mirrors the CAL response) that drive\n// host-side requirement building.\n\nexport type CalValueDto = {\n source: string;\n account_index?: number;\n data?: string;\n path?: { steps: number[] };\n};\n\nexport type CalTokenValueDto = {\n kind: string;\n value?: CalValueDto;\n account_index?: number;\n};\n\nexport type CalMintAssociationDto = {\n account_index: number;\n mint_index: number;\n};\n\nexport type CalTypePoolEntryDto = {\n index: number;\n kind: string;\n refs?: number[];\n size?: number;\n encoding?: number;\n len_kind?: string;\n flag_kind?: string;\n sentinel?: string;\n disc_kind?: string;\n total_variants?: number;\n enum_id?: string;\n};\n\nexport type CalEnumVariantDto = {\n variant_name: string;\n payload_kind?: string;\n descriptor: CalSignedDescriptorDto;\n};\n\n/** A substructure CAL serves only as opaque TLV (e.g. HIDE_RULE). */\nexport type CalSubstructureDto = {\n descriptor: string;\n};\n\nexport type CalValueFlowPortDto = CalSubstructureDto & {\n account_indices: number[];\n optional_account_strategy?: string;\n token_value: CalTokenValueDto;\n};\n\nexport type CalAccountResetDto = CalSubstructureDto & {\n account_index?: number;\n require_pre_balance_zero?: boolean;\n};\n\nexport type CalDisplayFieldDto = CalSubstructureDto & {\n name?: string;\n param?: { type: string; value?: CalValueDto; token?: CalValueDto };\n};\n\nexport type CalInstructionDescriptorDto = {\n discriminator_hex: string;\n instruction_name?: string;\n descriptor: CalSignedDescriptorDto;\n idl_descriptor?: {\n type_pool?: CalTypePoolEntryDto[];\n root_type?: number;\n };\n mint_association?: CalMintAssociationDto;\n owner_association?: unknown;\n enum_variants?: Record<string, Record<string, CalEnumVariantDto>>;\n display_fields?: CalDisplayFieldDto[];\n value_flow_ports?: CalValueFlowPortDto[];\n hide_rules?: CalSubstructureDto[];\n account_resets?: CalAccountResetDto[];\n};\n\n// One program object of the `solana_programs` response: the program `id`, its\n// `chain_id`, and the flat `instructions` array (keyed downstream by\n// `discriminator_hex`).\nexport type CalInstructionProgramDto = {\n id: string;\n chain_id: number;\n instructions: CalInstructionDescriptorDto[];\n};\n\n// Outer shape: array of program objects (one per requested `id`).\nexport type CalInstructionInfoResponseDto = CalInstructionProgramDto[];\n\n// --- Validation codecs (runtime). Validate only the fields the loaders read;\n// `Codec.interface` ignores unknown extras so CAL can add fields freely. ---\n\nconst calSignaturesCodec = Codec.interface({\n prod: optional(string),\n test: optional(string),\n});\n\nconst calSignedDescriptorCodec = Codec.interface({\n data: string,\n signatures: calSignaturesCodec,\n});\n\nconst calEnumVariantCodec = Codec.interface({\n descriptor: calSignedDescriptorCodec,\n});\n\nconst calSubstructureCodec = Codec.interface({\n descriptor: string,\n});\n\nconst calInstructionDescriptorCodec = Codec.interface({\n discriminator_hex: string,\n descriptor: calSignedDescriptorCodec,\n enum_variants: optional(record(string, record(string, calEnumVariantCodec))),\n display_fields: optional(array(calSubstructureCodec)),\n value_flow_ports: optional(array(calSubstructureCodec)),\n hide_rules: optional(array(calSubstructureCodec)),\n account_resets: optional(array(calSubstructureCodec)),\n});\n\n/**\n * Codec for one program object of the `solana_programs` response. Used by the\n * datasource to validate the CAL payload before handing it to the loaders.\n * Only loader-consumed fields are validated; unrelated CAL fields\n * (`idl_descriptor`, `mint_association`, \u2026) are ignored.\n */\nexport const calInstructionProgramCodec = Codec.interface({\n id: string,\n chain_id: number,\n instructions: array(calInstructionDescriptorCodec),\n});\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gCAAAE,IAAA,eAAAC,EAAAH,GAQA,IAAAI,EAA+D,qBA0G/D,MAAMC,EAAqB,QAAM,UAAU,CACzC,QAAM,YAAS,QAAM,EACrB,QAAM,YAAS,QAAM,CACvB,CAAC,EAEKC,EAA2B,QAAM,UAAU,CAC/C,KAAM,SACN,WAAYD,CACd,CAAC,EAEKE,EAAsB,QAAM,UAAU,CAC1C,WAAYD,CACd,CAAC,EAEKE,EAAuB,QAAM,UAAU,CAC3C,WAAY,QACd,CAAC,EAEKC,EAAgC,QAAM,UAAU,CACpD,kBAAmB,SACnB,WAAYH,EACZ,iBAAe,eAAS,UAAO,YAAQ,UAAO,SAAQC,CAAmB,CAAC,CAAC,EAC3E,kBAAgB,eAAS,SAAMC,CAAoB,CAAC,EACpD,oBAAkB,eAAS,SAAMA,CAAoB,CAAC,EACtD,cAAY,eAAS,SAAMA,CAAoB,CAAC,EAChD,kBAAgB,eAAS,SAAMA,CAAoB,CAAC,CACtD,CAAC,EAQYN,EAA6B,QAAM,UAAU,CACxD,GAAI,SACJ,SAAU,SACV,gBAAc,SAAMO,CAA6B,CACnD,CAAC",
4
+ "sourcesContent": ["// DTO + codecs for the CAL instruction-descriptors response (one object per\n// `programId`, wrapped in a JSON array).\n//\n// The hand-written types describe the consumed shape (with genuinely optional\n// `?:` fields); the codecs below validate that shape at runtime so\n// `HttpInstructionInfoDataSource` can hand the loaders a payload they can\n// dereference without runtime-throwing on a malformed descriptor.\n\nimport { array, Codec, number, optional, record, string } from \"purify-ts\";\n\nexport type CalSignatures = {\n prod?: string;\n test?: string;\n};\n\nexport type CalSignedDescriptorDto = {\n data: string;\n signatures: CalSignatures;\n};\n\n// Decoded CAL JSON shapes (snake_case mirrors the CAL response) that drive\n// host-side requirement building.\n\nexport type CalValueDto = {\n source: string;\n account_index?: number;\n data?: string;\n path?: { steps: number[] };\n};\n\nexport type CalTokenValueDto = {\n kind: string;\n value?: CalValueDto;\n account_index?: number;\n};\n\nexport type CalMintAssociationDto = {\n account_index: number;\n mint_index: number;\n};\n\nexport type CalTypePoolEntryDto = {\n index: number;\n kind: string;\n refs?: number[];\n size?: number;\n encoding?: number;\n len_kind?: string;\n flag_kind?: string;\n sentinel?: string;\n disc_kind?: string;\n total_variants?: number;\n enum_id?: string;\n};\n\nexport type CalEnumVariantDto = {\n variant_name: string;\n payload_kind?: string;\n descriptor: CalSignedDescriptorDto;\n};\n\n/** A substructure CAL serves only as opaque TLV (e.g. HIDE_RULE). */\nexport type CalSubstructureDto = {\n descriptor: string;\n};\n\nexport type CalValueFlowPortDto = CalSubstructureDto & {\n account_indices: number[];\n optional_account_strategy?: string;\n token_value: CalTokenValueDto;\n};\n\nexport type CalAccountResetDto = CalSubstructureDto & {\n account_index?: number;\n require_pre_balance_zero?: boolean;\n};\n\nexport type CalDisplayFieldDto = CalSubstructureDto & {\n name?: string;\n param?: { type: string; value?: CalValueDto; token?: CalValueDto };\n};\n\nexport type CalInstructionDescriptorDto = {\n discriminator_hex?: string;\n instruction_name?: string;\n descriptor: CalSignedDescriptorDto;\n idl_descriptor?: {\n type_pool?: CalTypePoolEntryDto[];\n root_type?: number;\n };\n mint_association?: CalMintAssociationDto;\n owner_association?: unknown;\n enum_variants?: Record<string, Record<string, CalEnumVariantDto>>;\n display_fields?: CalDisplayFieldDto[];\n value_flow_ports?: CalValueFlowPortDto[];\n hide_rules?: CalSubstructureDto[];\n account_resets?: CalAccountResetDto[];\n};\n\n// One program object of the `solana_programs` response: the program `id`, its\n// `chain_id`, and the flat `instructions` array (keyed downstream by\n// `discriminator_hex`).\nexport type CalInstructionProgramDto = {\n id: string;\n chain_id: number;\n instructions: CalInstructionDescriptorDto[];\n};\n\n// Outer shape: array of program objects (one per requested `id`).\nexport type CalInstructionInfoResponseDto = CalInstructionProgramDto[];\n\n// --- Validation codecs (runtime). Validate only the fields the loaders read;\n// `Codec.interface` ignores unknown extras so CAL can add fields freely. ---\n\nconst calSignaturesCodec = Codec.interface({\n prod: optional(string),\n test: optional(string),\n});\n\nconst calSignedDescriptorCodec = Codec.interface({\n data: string,\n signatures: calSignaturesCodec,\n});\n\nconst calEnumVariantCodec = Codec.interface({\n descriptor: calSignedDescriptorCodec,\n});\n\nconst calSubstructureCodec = Codec.interface({\n descriptor: string,\n});\n\nconst calInstructionDescriptorCodec = Codec.interface({\n discriminator_hex: optional(string),\n descriptor: calSignedDescriptorCodec,\n enum_variants: optional(record(string, record(string, calEnumVariantCodec))),\n display_fields: optional(array(calSubstructureCodec)),\n value_flow_ports: optional(array(calSubstructureCodec)),\n hide_rules: optional(array(calSubstructureCodec)),\n account_resets: optional(array(calSubstructureCodec)),\n});\n\n/**\n * Codec for one program object of the `solana_programs` response. Used by the\n * datasource to validate the CAL payload before handing it to the loaders.\n * Only loader-consumed fields are validated; unrelated CAL fields\n * (`idl_descriptor`, `mint_association`, \u2026) are ignored.\n */\nexport const calInstructionProgramCodec = Codec.interface({\n id: string,\n chain_id: number,\n instructions: array(calInstructionDescriptorCodec),\n});\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gCAAAE,IAAA,eAAAC,EAAAH,GAQA,IAAAI,EAA+D,qBA0G/D,MAAMC,EAAqB,QAAM,UAAU,CACzC,QAAM,YAAS,QAAM,EACrB,QAAM,YAAS,QAAM,CACvB,CAAC,EAEKC,EAA2B,QAAM,UAAU,CAC/C,KAAM,SACN,WAAYD,CACd,CAAC,EAEKE,EAAsB,QAAM,UAAU,CAC1C,WAAYD,CACd,CAAC,EAEKE,EAAuB,QAAM,UAAU,CAC3C,WAAY,QACd,CAAC,EAEKC,EAAgC,QAAM,UAAU,CACpD,qBAAmB,YAAS,QAAM,EAClC,WAAYH,EACZ,iBAAe,eAAS,UAAO,YAAQ,UAAO,SAAQC,CAAmB,CAAC,CAAC,EAC3E,kBAAgB,eAAS,SAAMC,CAAoB,CAAC,EACpD,oBAAkB,eAAS,SAAMA,CAAoB,CAAC,EACtD,cAAY,eAAS,SAAMA,CAAoB,CAAC,EAChD,kBAAgB,eAAS,SAAMA,CAAoB,CAAC,CACtD,CAAC,EAQYN,EAA6B,QAAM,UAAU,CACxD,GAAI,SACJ,SAAU,SACV,gBAAc,SAAMO,CAA6B,CACnD,CAAC",
6
6
  "names": ["InstructionInfoDto_exports", "__export", "calInstructionProgramCodec", "__toCommonJS", "import_purify_ts", "calSignaturesCodec", "calSignedDescriptorCodec", "calEnumVariantCodec", "calSubstructureCodec", "calInstructionDescriptorCodec"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var p=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var I=(i,t)=>{for(var a in t)p(i,a,{get:t[a],enumerable:!0})},T=(i,t,a,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of L(t))!h.call(i,e)&&e!==a&&p(i,e,{get:()=>t[e],enumerable:!(r=m(t,e))||r.enumerable});return i};var _=i=>T(p({},"__esModule",{value:!0}),i),f=(i,t,a,r)=>{for(var e=r>1?void 0:r?m(t,a):t,o=i.length-1,n;o>=0;o--)(n=i[o])&&(e=(r?n(t,a,e):n(e))||e);return r&&e&&p(t,a,e),e},d=(i,t)=>(a,r)=>t(a,r,i);var P={};I(P,{LifiContextLoader:()=>l});module.exports=_(P);var c=require("inversify"),u=require("../../../../config/di/configTypes"),y=require("../../../../modules/multichain/pki/di/pkiTypes"),S=require("../../../../modules/multichain/pki/model/KeyId"),C=require("../../../../modules/multichain/pki/model/KeyUsage"),x=require("../../../../modules/solana/lifi/di/lifiTypes"),s=require("../../../../shared/model/ClearSignContext");const b=[s.ClearSignContextType.SOLANA_LIFI];let l=class{constructor(t,a,r,e){this.dataSource=t;this.config=a;this._certificateLoader=r;this.logger=e("LifiContextLoader")}logger;canHandle(t,a){if(!b.every(r=>a.includes(r)))return this.logger.debug("[canHandle] Skipping, expected type does not match",{data:{expectedTypes:a,required:s.ClearSignContextType.SOLANA_LIFI}}),!1;if(typeof t=="object"&&t!==null&&"templateId"in t){const r=t.templateId,e=typeof r=="string"&&r.length>0;return this.logger.debug("[canHandle] Field validation result",{data:{templateId:r,isValid:e}}),e}return this.logger.debug("[canHandle] Field does not contain a valid templateId",{data:{input:t}}),!1}async load(t){this.logger.debug("[load] Loading solana Lifi context",{data:{input:t}});const a=await this._loadInternal(t);if(a.type===s.ClearSignContextType.ERROR)return[{type:s.ClearSignContextType.ERROR,error:a.error}];const r=a;return[{type:s.ClearSignContextType.SOLANA_LIFI,payload:r.payload,certificate:r.certificate}]}async _loadInternal(t){this.logger.debug("[_loadInternal] Loading solana Lifi context",{data:{input:t}});const{templateId:a,deviceModelId:r}=t;if(!a)return{type:s.ClearSignContextType.ERROR,error:new Error("[ContextModule] LifiContextLoader: templateId is missing")};const e=await this.dataSource.getTransactionDescriptorsPayload({templateId:a}),o=await this._certificateLoader.loadCertificate({keyId:S.KeyId.SwapTemplateKey,keyUsage:C.KeyUsage.SwapTemplate,targetDevice:r});return e.caseOf({Left:n=>(this.logger.error("[_loadInternal] Error loading solana Lifi context",{data:{error:n}}),{type:s.ClearSignContextType.ERROR,error:n}),Right:n=>{const g=this.buildPayload(n);return this.logger.debug("[_loadInternal] Successfully loaded solana Lifi context",{data:{descriptors:g.descriptors,instructionsCount:g.instructions.length,certificate:o}}),{type:s.ClearSignContextType.SOLANA_LIFI,payload:g,certificate:o}}})}buildPayload(t){return{descriptors:this.pluckTransactionData(t),instructions:this.extractInstructionsMeta(t)}}pluckTransactionData(t){const a=this.config.cal.mode||"prod",r={},e=t.descriptors??[];this.logger.debug("[pluckTransactionData] Processing descriptors",{data:{descriptorsCount:e.length,signatureKind:a}});for(const o of e){const n=`${o.program_id}:${o.discriminator_hex??""}`;r[n]={data:o.descriptor.data,descriptorType:o.descriptor.descriptorType,descriptorVersion:o.descriptor.descriptorVersion,signature:o.descriptor.signatures[a]??""},this.logger.debug("[pluckTransactionData] Mapped program descriptor",{data:{programId:o.program_id,discriminatorHex:o.discriminator_hex??"",key:n}})}return this.logger.debug("[pluckTransactionData] Completed processing",{data:{outputKeys:Object.keys(r)}}),r}extractInstructionsMeta(t){const a=t.instructions??[];this.logger.debug("[extractInstructionsMeta] Extracting instructions metadata",{data:{instructionsCount:a.length}});const r=a.map(e=>({program_id:e.program_id,...e.discriminator_hex!==void 0&&{discriminator_hex:e.discriminator_hex}}));return this.logger.debug("[extractInstructionsMeta] Completed extracting instructions metadata",{data:{meta:r.map(e=>({programId:e.program_id,discriminatorHex:e.discriminator_hex}))}}),r}};l=f([(0,c.injectable)(),d(0,(0,c.inject)(x.lifiTypes.LifiDataSource)),d(1,(0,c.inject)(u.configTypes.Config)),d(2,(0,c.inject)(y.pkiTypes.PkiCertificateLoader)),d(3,(0,c.inject)(u.configTypes.ContextModuleLoggerFactory))],l);0&&(module.exports={LifiContextLoader});
1
+ "use strict";var g=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var _=(i,t)=>{for(var r in t)g(i,r,{get:t[r],enumerable:!0})},I=(i,t,r,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of x(t))!L.call(i,e)&&e!==r&&g(i,e,{get:()=>t[e],enumerable:!(a=m(t,e))||a.enumerable});return i};var T=i=>I(g({},"__esModule",{value:!0}),i),f=(i,t,r,a)=>{for(var e=a>1?void 0:a?m(t,r):t,o=i.length-1,n;o>=0;o--)(n=i[o])&&(e=(a?n(t,r,e):n(e))||e);return a&&e&&g(t,r,e),e},p=(i,t)=>(r,a)=>t(r,a,i);var P={};_(P,{LifiContextLoader:()=>l});module.exports=T(P);var c=require("inversify"),u=require("../../../../config/di/configTypes"),y=require("../../../../modules/multichain/pki/di/pkiTypes"),S=require("../../../../modules/multichain/pki/model/KeyId"),C=require("../../../../modules/multichain/pki/model/KeyUsage"),h=require("../../../../modules/solana/lifi/di/lifiTypes"),s=require("../../../../shared/model/ClearSignContext");const b=[s.ClearSignContextType.SOLANA_LIFI];let l=class{constructor(t,r,a,e){this.dataSource=t;this.config=r;this._certificateLoader=a;this.logger=e("LifiContextLoader")}logger;canHandle(t,r){if(!b.every(a=>r.includes(a)))return this.logger.debug("[canHandle] Skipping, expected type does not match",{data:{expectedTypes:r,required:s.ClearSignContextType.SOLANA_LIFI}}),!1;if(typeof t=="object"&&t!==null&&"templateId"in t){const a=t.templateId,e=typeof a=="string"&&a.length>0;return this.logger.debug("[canHandle] Field validation result",{data:{templateId:a,isValid:e}}),e}return this.logger.debug("[canHandle] Field does not contain a valid templateId",{data:{input:t}}),!1}async load(t){this.logger.debug("[load] Loading solana Lifi context",{data:{input:t}});const r=await this._loadInternal(t);if(r.type===s.ClearSignContextType.ERROR)return[{type:s.ClearSignContextType.ERROR,error:r.error}];const a=r;return[{type:s.ClearSignContextType.SOLANA_LIFI,payload:a.payload,certificate:a.certificate}]}async _loadInternal(t){this.logger.debug("[_loadInternal] Loading solana Lifi context",{data:{input:t}});const{templateId:r,deviceModelId:a}=t;if(!r)return{type:s.ClearSignContextType.ERROR,error:new Error("[ContextModule] LifiContextLoader: templateId is missing")};const e=await this.dataSource.getTransactionDescriptorsPayload({templateId:r}),o=await this._certificateLoader.loadCertificate({keyId:S.KeyId.SwapTemplateKey,keyUsage:C.KeyUsage.SwapTemplate,targetDevice:a});return e.caseOf({Left:n=>(this.logger.error("[_loadInternal] Error loading solana Lifi context",{data:{error:n}}),{type:s.ClearSignContextType.ERROR,error:n}),Right:n=>{const d=this.buildPayload(n);return this.logger.debug("[_loadInternal] Successfully loaded solana Lifi context",{data:{descriptors:d.descriptors,instructionsCount:d.instructions.length,certificate:o}}),{type:s.ClearSignContextType.SOLANA_LIFI,payload:d,certificate:o}}})}buildPayload(t){return{descriptors:this.pluckTransactionData(t),instructions:this.extractInstructionsMeta(t)}}pluckTransactionData(t){const r=this.config.cal.mode||"prod",a={},e=t.descriptors??[];this.logger.debug("[pluckTransactionData] Processing descriptors",{data:{descriptorsCount:e.length,signatureKind:r}});for(const o of e){const n=`${o.program_id}:${o.discriminator_hex??""}`,d={data:o.descriptor.data,descriptorType:o.descriptor.descriptorType,descriptorVersion:o.descriptor.descriptorVersion,signature:o.descriptor.signatures[r]??"",...o.has_basis_point!==void 0&&{has_basis_point:o.has_basis_point}};(a[n]??=[]).push(d),this.logger.debug("[pluckTransactionData] Mapped program descriptor",{data:{programId:o.program_id,discriminatorHex:o.discriminator_hex??"",key:n}})}return this.logger.debug("[pluckTransactionData] Completed processing",{data:{outputKeys:Object.keys(a)}}),a}extractInstructionsMeta(t){const r=t.instructions??[];this.logger.debug("[extractInstructionsMeta] Extracting instructions metadata",{data:{instructionsCount:r.length}});const a=r.map(e=>({program_id:e.program_id,...e.discriminator_hex!==void 0&&{discriminator_hex:e.discriminator_hex},...e.amount!==void 0&&{has_basis_point:e.amount.capped_bps!==void 0}}));return this.logger.debug("[extractInstructionsMeta] Completed extracting instructions metadata",{data:{meta:a.map(e=>({programId:e.program_id,discriminatorHex:e.discriminator_hex}))}}),a}};l=f([(0,c.injectable)(),p(0,(0,c.inject)(h.lifiTypes.LifiDataSource)),p(1,(0,c.inject)(u.configTypes.Config)),p(2,(0,c.inject)(y.pkiTypes.PkiCertificateLoader)),p(3,(0,c.inject)(u.configTypes.ContextModuleLoggerFactory))],l);0&&(module.exports={LifiContextLoader});
2
2
  //# sourceMappingURL=LifiContextLoader.js.map