@ledgerhq/context-module 0.0.0-multisig-20250910160951 → 0.0.0-no-issue-rn-ble-reconnection-20250916150911

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 (39) hide show
  1. package/lib/cjs/package.json +1 -1
  2. package/lib/cjs/src/shared/model/TypedDataClearSignContext.js.map +1 -1
  3. package/lib/cjs/src/shared/model/TypedDataContext.js.map +1 -1
  4. package/lib/cjs/src/transaction/data/HttpTransactionDataSource.js +1 -1
  5. package/lib/cjs/src/transaction/data/HttpTransactionDataSource.js.map +2 -2
  6. package/lib/cjs/src/transaction/domain/TransactionContextLoader.js +1 -1
  7. package/lib/cjs/src/transaction/domain/TransactionContextLoader.js.map +3 -3
  8. package/lib/cjs/src/transaction/domain/TransactionContextLoader.test.js +1 -1
  9. package/lib/cjs/src/transaction/domain/TransactionContextLoader.test.js.map +3 -3
  10. package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.js +1 -1
  11. package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.js.map +2 -2
  12. package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.js +1 -1
  13. package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.js.map +3 -3
  14. package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.test.js +1 -1
  15. package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.test.js.map +2 -2
  16. package/lib/esm/package.json +1 -1
  17. package/lib/esm/src/shared/model/TypedDataClearSignContext.js.map +1 -1
  18. package/lib/esm/src/transaction/data/HttpTransactionDataSource.js +1 -1
  19. package/lib/esm/src/transaction/data/HttpTransactionDataSource.js.map +2 -2
  20. package/lib/esm/src/transaction/domain/TransactionContextLoader.js +1 -1
  21. package/lib/esm/src/transaction/domain/TransactionContextLoader.js.map +3 -3
  22. package/lib/esm/src/transaction/domain/TransactionContextLoader.test.js +1 -1
  23. package/lib/esm/src/transaction/domain/TransactionContextLoader.test.js.map +3 -3
  24. package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.js +1 -1
  25. package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.js.map +2 -2
  26. package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.js +1 -1
  27. package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.js.map +3 -3
  28. package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.test.js +1 -1
  29. package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.test.js.map +2 -2
  30. package/lib/types/src/shared/model/TypedDataClearSignContext.d.ts +1 -1
  31. package/lib/types/src/shared/model/TypedDataClearSignContext.d.ts.map +1 -1
  32. package/lib/types/src/shared/model/TypedDataContext.d.ts +1 -1
  33. package/lib/types/src/shared/model/TypedDataContext.d.ts.map +1 -1
  34. package/lib/types/src/transaction/data/HttpTransactionDataSource.d.ts.map +1 -1
  35. package/lib/types/src/transaction/domain/TransactionContextLoader.d.ts.map +1 -1
  36. package/lib/types/src/typed-data/data/HttpTypedDataDataSource.d.ts.map +1 -1
  37. package/lib/types/src/typed-data/domain/DefaultTypedDataContextLoader.d.ts.map +1 -1
  38. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  39. package/package.json +5 -5
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ledgerhq/context-module",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "private": false,
5
5
  "license": "Apache-2.0",
6
6
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/shared/model/TypedDataClearSignContext.ts"],
4
- "sourcesContent": ["import type { HexaString } from \"@ledgerhq/device-management-kit\";\n\nimport {\n type ClearSignContextSuccess,\n type ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { type TransactionSubset } from \"@/shared/model/TransactionSubset\";\n\n// The general informations for a typed message\nexport type TypedDataMessageInfo = {\n displayName: string;\n filtersCount: number;\n signature: string;\n};\n\n// Token index and descriptor. Needed for tokens that are referenced by a typed message\nexport type TypedDataTokenIndex = number;\nexport type TypedDataToken = string;\n// Calldata index. Needed for calldatas that are referenced by a typed message\nexport type TypedDataCalldataIndex = number;\n// Special token index value when the referenced token is the verifying contract\nexport const VERIFYING_CONTRACT_TOKEN_INDEX = 255;\n\n// Typed message filters, to select fields to display, and provide formatting informations\nexport type TypedDataFilterPath = string;\nexport type TypedDataFilterWithToken = {\n type: \"amount\" | \"token\";\n displayName: string;\n tokenIndex: TypedDataTokenIndex;\n path: TypedDataFilterPath;\n signature: string;\n};\nexport type TypedDataFilterWithTrustedName = {\n type: \"trusted-name\";\n displayName: string;\n types: string[];\n sources: string[];\n typesAndSourcesPayload: string;\n path: TypedDataFilterPath;\n signature: string;\n};\nexport type TypedDataFilterCalldata = {\n type:\n | \"calldata-value\"\n | \"calldata-callee\"\n | \"calldata-chain-id\"\n | \"calldata-selector\"\n | \"calldata-amount\"\n | \"calldata-spender\";\n displayName: string;\n calldataIndex: TypedDataCalldataIndex;\n path: TypedDataFilterPath;\n signature: string;\n};\nexport type TypedDataFilter =\n | {\n type: \"datetime\" | \"raw\";\n displayName: string;\n path: TypedDataFilterPath;\n signature: string;\n }\n | TypedDataFilterWithToken\n | TypedDataFilterWithTrustedName\n | TypedDataFilterCalldata;\n\n// Calldata info when referenced by a typed message\nexport enum TypedDataCalldataParamPresence {\n None = \"none\",\n Present = \"present\",\n VerifyingContract = \"verifying_contract\",\n}\nexport type TypedDataFilterCalldataInfo = {\n displayName: string;\n calldataIndex: TypedDataCalldataIndex;\n valueFlag: boolean;\n calleeFlag: TypedDataCalldataParamPresence;\n chainIdFlag: boolean;\n selectorFlag: boolean;\n amountFlag: boolean;\n spenderFlag: TypedDataCalldataParamPresence;\n signature: string;\n};\nexport type TypedDataCalldataInfo = {\n filter: TypedDataFilterCalldataInfo;\n subset: TransactionSubset;\n};\n\n// Clear signing context for a typed message\nexport type TypedDataClearSignContextSuccess = {\n type: \"success\";\n messageInfo: TypedDataMessageInfo;\n filters: Record<TypedDataFilterPath, TypedDataFilter>;\n trustedNamesAddresses: Record<TypedDataFilterPath, HexaString>;\n tokens: Record<TypedDataTokenIndex, TypedDataToken>;\n calldatas: Record<TypedDataCalldataIndex, TypedDataCalldataInfo>;\n proxy:\n | ClearSignContextSuccess<ClearSignContextType.PROXY_DELEGATE_CALL>\n | undefined;\n};\nexport type TypedDataClearSignContextError = {\n type: \"error\";\n error: Error;\n};\nexport type TypedDataClearSignContext =\n | TypedDataClearSignContextSuccess\n | TypedDataClearSignContextError;\n"],
4
+ "sourcesContent": ["import type { HexaString } from \"@ledgerhq/device-management-kit\";\n\nimport {\n type ClearSignContextSuccess,\n type ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { type TransactionSubset } from \"@/shared/model/TransactionSubset\";\n\n// The general informations for a typed message\nexport type TypedDataMessageInfo = {\n displayName: string;\n filtersCount: number;\n signature: string;\n};\n\n// Token index and descriptor. Needed for tokens that are referenced by a typed message\nexport type TypedDataTokenIndex = number;\nexport type TypedDataToken = string;\n// Calldata index. Needed for calldatas that are referenced by a typed message\nexport type TypedDataCalldataIndex = number;\n// Special token index value when the referenced token is the verifying contract\nexport const VERIFYING_CONTRACT_TOKEN_INDEX = 255;\n\n// Typed message filters, to select fields to display, and provide formatting informations\nexport type TypedDataFilterPath = string;\nexport type TypedDataFilterWithToken = {\n type: \"amount\" | \"token\";\n displayName: string;\n tokenIndex: TypedDataTokenIndex;\n path: TypedDataFilterPath;\n signature: string;\n};\nexport type TypedDataFilterWithTrustedName = {\n type: \"trusted-name\";\n displayName: string;\n types: string[];\n sources: string[];\n typesAndSourcesPayload: string;\n path: TypedDataFilterPath;\n signature: string;\n};\nexport type TypedDataFilterCalldata = {\n type:\n | \"calldata-value\"\n | \"calldata-callee\"\n | \"calldata-chain-id\"\n | \"calldata-selector\"\n | \"calldata-amount\"\n | \"calldata-spender\";\n displayName: string;\n calldataIndex: TypedDataCalldataIndex;\n path: TypedDataFilterPath;\n signature: string;\n};\nexport type TypedDataFilter =\n | {\n type: \"datetime\" | \"raw\";\n displayName: string;\n path: TypedDataFilterPath;\n signature: string;\n }\n | TypedDataFilterWithToken\n | TypedDataFilterWithTrustedName\n | TypedDataFilterCalldata;\n\n// Calldata info when referenced by a typed message\nexport enum TypedDataCalldataParamPresence {\n None = \"none\",\n Present = \"present\",\n VerifyingContract = \"verifying_contract\",\n}\nexport type TypedDataFilterCalldataInfo = {\n displayName: string;\n calldataIndex: TypedDataCalldataIndex;\n valueFlag: boolean;\n calleeFlag: TypedDataCalldataParamPresence;\n chainIdFlag: boolean;\n selectorFlag: boolean;\n amountFlag: boolean;\n spenderFlag: TypedDataCalldataParamPresence;\n signature: string;\n};\nexport type TypedDataCalldataInfo = {\n filter: TypedDataFilterCalldataInfo;\n subset: TransactionSubset;\n};\n\n// Clear signing context for a typed message\nexport type TypedDataClearSignContextSuccess = {\n type: \"success\";\n messageInfo: TypedDataMessageInfo;\n filters: Record<TypedDataFilterPath, TypedDataFilter>;\n trustedNamesAddresses: Record<TypedDataFilterPath, HexaString>;\n tokens: Record<TypedDataTokenIndex, TypedDataToken>;\n calldatas: Record<TypedDataCalldataIndex, TypedDataCalldataInfo>;\n proxy?: ClearSignContextSuccess<ClearSignContextType.PROXY_DELEGATE_CALL>;\n};\nexport type TypedDataClearSignContextError = {\n type: \"error\";\n error: Error;\n};\nexport type TypedDataClearSignContext =\n | TypedDataClearSignContextSuccess\n | TypedDataClearSignContextError;\n"],
5
5
  "mappings": "AAqBO,MAAMA,EAAiC,IA6CvC,IAAKC,OACVA,EAAA,KAAO,OACPA,EAAA,QAAU,UACVA,EAAA,kBAAoB,qBAHVA,OAAA",
6
6
  "names": ["VERIFYING_CONTRACT_TOKEN_INDEX", "TypedDataCalldataParamPresence"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var S=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var h=(l,e,t,r)=>{for(var i=r>1?void 0:r?I(e,t):e,n=l.length-1,o;n>=0;n--)(o=l[n])&&(i=(r?o(e,t,i):o(i))||i);return r&&i&&S(e,t,i),i},u=(l,e)=>(t,r)=>e(t,r,l);import M from"axios";import{inject as m,injectable as R}from"inversify";import{Left as c,Right as L}from"purify-ts";import{configTypes as x}from"../../config/di/configTypes";import{pkiTypes as O}from"../../pki/di/pkiTypes";import{KeyId as F}from"../../pki/model/KeyId";import{KeyUsage as G}from"../../pki/model/KeyUsage";import{LEDGER_CLIENT_VERSION_HEADER as k,LEDGER_ORIGIN_TOKEN_HEADER as U}from"../../shared/constant/HttpHeaders";import{ClearSignContextReferenceType as a,ClearSignContextType as f}from"../../shared/model/ClearSignContext";import{INFO_SIGNATURE_TAG as T}from"../../shared/model/SignatureTags";import{HexStringUtils as E}from"../../shared/utils/HexStringUtils";import j from"../../../package.json";let y=class{constructor(e,t){this.config=e;this._certificateLoader=t}async getTransactionDescriptors({chainId:e,address:t,selector:r,deviceModelId:i}){let n;try{n=(await M.request({method:"GET",url:`${this.config.cal.url}/dapps`,params:{output:"descriptors_calldata",chain_id:e,contracts:t,ref:"commit:ff75b9427f79c04c09d0b4378d6e01e2e6113e28"},headers:{[k]:`context-module/${j.version}`,[U]:this.config.originToken}})).data}catch(o){return c(new Error(`[ContextModule] HttpTransactionDataSource: Failed to fetch transaction informations: ${o}`))}if(!Array.isArray(n))return c(new Error("[ContextModule] HttpTransactionDataSource: Response is not an array"));if(n.length===0)return c(new Error(`[ContextModule] HttpTransactionDataSource: No data for contract ${t} and selector ${r}`));for(const o of n){t=t.toLowerCase(),r=`0x${r.slice(2).toLowerCase()}`;const s=o.descriptors_calldata?.[t]?.[r];if(!s||!this.isCalldataDescriptorV1(s,this.config.cal.mode))continue;const D=s.transaction_info.descriptor.data,V=s.transaction_info.descriptor.signatures[this.config.cal.mode],g={targetDevice:i,keyUsage:G.Calldata,keyId:F.CalCalldataKey},C=await this._certificateLoader.loadCertificate(g),A={type:f.TRANSACTION_INFO,payload:E.appendSignatureToPayload(D,V,T),certificate:C},d=[];for(const[p,b]of Object.entries(s.enums))for(const[P,{data:v,signatures:N}]of Object.entries(b))d.push({type:f.ENUM,id:Number(p),value:Number(P),payload:E.appendSignatureToPayload(v,N[this.config.cal.mode],T),certificate:C});const _=s.fields.map(p=>({type:f.TRANSACTION_FIELD_DESCRIPTION,payload:p.descriptor,reference:this.getReference(p.param)}));return L([A,...d,..._])}return c(new Error(`[ContextModule] HttpTransactionDataSource: Invalid response for contract ${t} and selector ${r}`))}getReference(e){if(e.type==="TOKEN_AMOUNT"&&e.token!==void 0&&e.token.type==="path")return{type:a.TOKEN,valuePath:this.toGenericPath(e.token.binary_path)};if(e.type==="TOKEN_AMOUNT"&&e.token!==void 0&&e.token.type==="constant")return{type:a.TOKEN,value:e.token.value};if(e.type==="NFT"&&e.collection.type==="path")return{type:a.NFT,valuePath:this.toGenericPath(e.collection.binary_path)};if(e.type==="NFT"&&e.collection.type==="constant")return{type:a.NFT,value:e.collection.value};if(e.type==="TRUSTED_NAME"&&e.value.type==="path")return{type:a.TRUSTED_NAME,valuePath:this.toGenericPath(e.value.binary_path),types:e.types,sources:e.sources};if(e.type==="ENUM"&&e.value.type==="path")return{type:a.ENUM,valuePath:this.toGenericPath(e.value.binary_path),id:e.id};if(e.type==="CALLDATA"&&e.value.type==="path"&&e.callee.type==="path")return{type:a.CALLDATA,valuePath:this.toGenericPath(e.value.binary_path),callee:this.toGenericPath(e.callee.binary_path),selector:e.selector?.type==="path"?this.toGenericPath(e.selector.binary_path):void 0,amount:e.amount?.type==="path"?this.toGenericPath(e.amount.binary_path):void 0,spender:e.spender?.type==="path"?this.toGenericPath(e.spender.binary_path):void 0,chainId:e.chainId?.type==="path"?this.toGenericPath(e.chainId.binary_path):void 0}}toGenericPath(e){return e.type==="CONTAINER"?e.value:e.elements.map(t=>{if(t.type==="ARRAY"){const{weight:r,...i}=t;return{itemSize:r,...i}}else if(t.type==="LEAF"){const{leaf_type:r,...i}=t;return{leafType:r,...i}}return t})}isCalldataDescriptorV1(e,t){return typeof e=="object"&&e.type==="calldata"&&e.version==="v1"&&this.isTransactionInfoV1(e.transaction_info,t)&&this.isEnumV1(e.enums,t)&&Array.isArray(e.fields)&&e.fields.every(r=>this.isFieldV1(r))}isTransactionInfoV1(e,t){return typeof e=="object"&&typeof e.descriptor=="object"&&typeof e.descriptor.data=="string"&&typeof e.descriptor.signatures=="object"&&typeof e.descriptor.signatures[t]=="string"}isEnumV1(e,t){return typeof e=="object"&&Object.entries(e).every(([r,i])=>typeof r=="string"&&typeof i=="object"&&Object.entries(i).every(([n,o])=>typeof n=="string"&&typeof o=="object"&&typeof o.data=="string"&&o.signatures!==void 0&&this.isCalldataSignatures(o.signatures,t)))}isCalldataSignatures(e,t){return typeof e=="object"&&typeof e[t]=="string"}isFieldV1(e){return typeof e=="object"&&typeof e.descriptor=="string"&&typeof e.param=="object"&&typeof e.param.value=="object"&&this.isDescriptorValueV1(e.param.value)&&(e.param.type==="RAW"||e.param.type==="AMOUNT"||e.param.type==="DATETIME"||e.param.type==="DURATION"||e.param.type==="UNIT"||e.param.type==="ENUM"||e.param.type==="NFT"&&this.isDescriptorValueV1(e.param.collection)||e.param.type==="TOKEN_AMOUNT"&&(e.param.token===void 0||this.isDescriptorValueV1(e.param.token))||e.param.type==="TRUSTED_NAME"&&Array.isArray(e.param.types)&&Array.isArray(e.param.sources)&&e.param.types.every(t=>typeof t=="string")&&e.param.sources.every(t=>typeof t=="string")||e.param.type==="CALLDATA"&&this.isDescriptorValueV1(e.param.value)&&this.isDescriptorValueV1(e.param.callee)&&(e.param.selector===void 0||this.isDescriptorValueV1(e.param.selector))&&(e.param.amount===void 0||this.isDescriptorValueV1(e.param.amount)))}isDescriptorValueV1(e){return typeof e=="object"&&typeof e.type_family=="string"&&["UINT","INT","UFIXED","FIXED","ADDRESS","BOOL","BYTES","STRING"].includes(e.type_family)&&(typeof e.type_size>"u"||typeof e.type_size=="number")&&(e.type==="path"&&this.isCalldataDescriptorValueBinaryPathV1(e)||e.type==="constant"&&this.isCalldataDescriptorValueConstantV1(e))}isCalldataDescriptorValueConstantV1(e){return typeof e=="object"&&e.type==="constant"&&typeof e.value=="string"}isCalldataDescriptorValueBinaryPathV1(e){return typeof e=="object"&&(e.type==="path"&&e.binary_path.type==="CONTAINER"&&["FROM","TO","VALUE"].includes(e.binary_path.value)||e.binary_path.type==="DATA"&&Array.isArray(e.binary_path.elements)&&e.binary_path.elements.every(t=>this.isPathElementV1(t)))}isPathElementV1(e){return typeof e=="object"&&(e.type==="REF"||e.type==="TUPLE"&&typeof e.offset=="number"||e.type==="ARRAY"&&typeof e.weight=="number"&&(typeof e.start>"u"||typeof e.start=="number")&&(typeof e.end>"u"||typeof e.end=="number")||e.type==="LEAF"&&typeof e.leaf_type=="string"&&["ARRAY_LEAF","TUPLE_LEAF","STATIC_LEAF","DYNAMIC_LEAF"].includes(e.leaf_type)||e.type==="SLICE"&&(typeof e.start>"u"||typeof e.start=="number")&&(typeof e.end>"u"||typeof e.end=="number"))}};y=h([R(),u(0,m(x.Config)),u(1,m(O.PkiCertificateLoader))],y);export{y as HttpTransactionDataSource};
1
+ var I=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var d=(l,e,t,r)=>{for(var i=r>1?void 0:r?S(e,t):e,n=l.length-1,o;n>=0;n--)(o=l[n])&&(i=(r?o(e,t,i):o(i))||i);return r&&i&&I(e,t,i),i},y=(l,e)=>(t,r)=>e(t,r,l);import M from"axios";import{inject as m,injectable as R}from"inversify";import{Left as c,Right as L}from"purify-ts";import{configTypes as x}from"../../config/di/configTypes";import{pkiTypes as O}from"../../pki/di/pkiTypes";import{KeyId as F}from"../../pki/model/KeyId";import{KeyUsage as G}from"../../pki/model/KeyUsage";import{LEDGER_CLIENT_VERSION_HEADER as k,LEDGER_ORIGIN_TOKEN_HEADER as U}from"../../shared/constant/HttpHeaders";import{ClearSignContextReferenceType as a,ClearSignContextType as f}from"../../shared/model/ClearSignContext";import{INFO_SIGNATURE_TAG as T}from"../../shared/model/SignatureTags";import{HexStringUtils as D}from"../../shared/utils/HexStringUtils";import j from"../../../package.json";let u=class{constructor(e,t){this.config=e;this._certificateLoader=t}async getTransactionDescriptors({chainId:e,address:t,selector:r,deviceModelId:i}){let n;try{n=(await M.request({method:"GET",url:`${this.config.cal.url}/dapps`,params:{output:"descriptors_calldata",chain_id:e,contracts:t,ref:`branch:${this.config.cal.branch}`},headers:{[k]:`context-module/${j.version}`,[U]:this.config.originToken}})).data}catch(o){return c(new Error(`[ContextModule] HttpTransactionDataSource: Failed to fetch transaction informations: ${o}`))}if(!Array.isArray(n))return c(new Error("[ContextModule] HttpTransactionDataSource: Response is not an array"));if(n.length===0)return c(new Error(`[ContextModule] HttpTransactionDataSource: No data for contract ${t} and selector ${r}`));for(const o of n){t=t.toLowerCase(),r=`0x${r.slice(2).toLowerCase()}`;const s=o.descriptors_calldata?.[t]?.[r];if(!s||!this.isCalldataDescriptorV1(s,this.config.cal.mode))continue;const E=s.transaction_info.descriptor.data,V=s.transaction_info.descriptor.signatures[this.config.cal.mode],g={targetDevice:i,keyUsage:G.Calldata,keyId:F.CalCalldataKey},C=await this._certificateLoader.loadCertificate(g),A={type:f.TRANSACTION_INFO,payload:D.appendSignatureToPayload(E,V,T),certificate:C},h=[];for(const[p,b]of Object.entries(s.enums))for(const[P,{data:v,signatures:N}]of Object.entries(b))h.push({type:f.ENUM,id:Number(p),value:Number(P),payload:D.appendSignatureToPayload(v,N[this.config.cal.mode],T),certificate:C});const _=s.fields.map(p=>({type:f.TRANSACTION_FIELD_DESCRIPTION,payload:p.descriptor,reference:this.getReference(p.param)}));return L([A,...h,..._])}return c(new Error(`[ContextModule] HttpTransactionDataSource: Invalid response for contract ${t} and selector ${r}`))}getReference(e){if(e.type==="TOKEN_AMOUNT"&&e.token!==void 0&&e.token.type==="path")return{type:a.TOKEN,valuePath:this.toGenericPath(e.token.binary_path)};if(e.type==="TOKEN_AMOUNT"&&e.token!==void 0&&e.token.type==="constant")return{type:a.TOKEN,value:e.token.value};if(e.type==="NFT"&&e.collection.type==="path")return{type:a.NFT,valuePath:this.toGenericPath(e.collection.binary_path)};if(e.type==="NFT"&&e.collection.type==="constant")return{type:a.NFT,value:e.collection.value};if(e.type==="TRUSTED_NAME"&&e.value.type==="path")return{type:a.TRUSTED_NAME,valuePath:this.toGenericPath(e.value.binary_path),types:e.types,sources:e.sources};if(e.type==="ENUM"&&e.value.type==="path")return{type:a.ENUM,valuePath:this.toGenericPath(e.value.binary_path),id:e.id};if(e.type==="CALLDATA"&&e.value.type==="path"&&e.callee.type==="path")return{type:a.CALLDATA,valuePath:this.toGenericPath(e.value.binary_path),callee:this.toGenericPath(e.callee.binary_path),selector:e.selector?.type==="path"?this.toGenericPath(e.selector.binary_path):void 0,amount:e.amount?.type==="path"?this.toGenericPath(e.amount.binary_path):void 0,spender:e.spender?.type==="path"?this.toGenericPath(e.spender.binary_path):void 0,chainId:e.chainId?.type==="path"?this.toGenericPath(e.chainId.binary_path):void 0}}toGenericPath(e){return e.type==="CONTAINER"?e.value:e.elements.map(t=>{if(t.type==="ARRAY"){const{weight:r,...i}=t;return{itemSize:r,...i}}else if(t.type==="LEAF"){const{leaf_type:r,...i}=t;return{leafType:r,...i}}return t})}isCalldataDescriptorV1(e,t){return typeof e=="object"&&e.type==="calldata"&&e.version==="v1"&&this.isTransactionInfoV1(e.transaction_info,t)&&this.isEnumV1(e.enums,t)&&Array.isArray(e.fields)&&e.fields.every(r=>this.isFieldV1(r))}isTransactionInfoV1(e,t){return typeof e=="object"&&typeof e.descriptor=="object"&&typeof e.descriptor.data=="string"&&typeof e.descriptor.signatures=="object"&&typeof e.descriptor.signatures[t]=="string"}isEnumV1(e,t){return typeof e=="object"&&Object.entries(e).every(([r,i])=>typeof r=="string"&&typeof i=="object"&&Object.entries(i).every(([n,o])=>typeof n=="string"&&typeof o=="object"&&typeof o.data=="string"&&o.signatures!==void 0&&this.isCalldataSignatures(o.signatures,t)))}isCalldataSignatures(e,t){return typeof e=="object"&&typeof e[t]=="string"}isFieldV1(e){return typeof e=="object"&&typeof e.descriptor=="string"&&typeof e.param=="object"&&typeof e.param.value=="object"&&this.isDescriptorValueV1(e.param.value)&&(e.param.type==="RAW"||e.param.type==="AMOUNT"||e.param.type==="DATETIME"||e.param.type==="DURATION"||e.param.type==="UNIT"||e.param.type==="ENUM"||e.param.type==="NFT"&&this.isDescriptorValueV1(e.param.collection)||e.param.type==="TOKEN_AMOUNT"&&(e.param.token===void 0||this.isDescriptorValueV1(e.param.token))||e.param.type==="TRUSTED_NAME"&&Array.isArray(e.param.types)&&Array.isArray(e.param.sources)&&e.param.types.every(t=>typeof t=="string")&&e.param.sources.every(t=>typeof t=="string")||e.param.type==="CALLDATA"&&this.isDescriptorValueV1(e.param.value)&&this.isDescriptorValueV1(e.param.callee)&&(e.param.selector===void 0||this.isDescriptorValueV1(e.param.selector))&&(e.param.amount===void 0||this.isDescriptorValueV1(e.param.amount))&&(e.param.spender===void 0||this.isDescriptorValueV1(e.param.spender))&&(e.param.chainId===void 0||this.isDescriptorValueV1(e.param.chainId)))}isDescriptorValueV1(e){return typeof e=="object"&&typeof e.type_family=="string"&&["UINT","INT","UFIXED","FIXED","ADDRESS","BOOL","BYTES","STRING"].includes(e.type_family)&&(typeof e.type_size>"u"||typeof e.type_size=="number")&&(e.type==="path"&&this.isCalldataDescriptorValueBinaryPathV1(e)||e.type==="constant"&&this.isCalldataDescriptorValueConstantV1(e))}isCalldataDescriptorValueConstantV1(e){return typeof e=="object"&&e.type==="constant"&&typeof e.value=="string"}isCalldataDescriptorValueBinaryPathV1(e){return typeof e=="object"&&(e.type==="path"&&e.binary_path.type==="CONTAINER"&&["FROM","TO","VALUE"].includes(e.binary_path.value)||e.binary_path.type==="DATA"&&Array.isArray(e.binary_path.elements)&&e.binary_path.elements.every(t=>this.isPathElementV1(t)))}isPathElementV1(e){return typeof e=="object"&&(e.type==="REF"||e.type==="TUPLE"&&typeof e.offset=="number"||e.type==="ARRAY"&&typeof e.weight=="number"&&(typeof e.start>"u"||typeof e.start=="number")&&(typeof e.end>"u"||typeof e.end=="number")||e.type==="LEAF"&&typeof e.leaf_type=="string"&&["ARRAY_LEAF","TUPLE_LEAF","STATIC_LEAF","DYNAMIC_LEAF"].includes(e.leaf_type)||e.type==="SLICE"&&(typeof e.start>"u"||typeof e.start=="number")&&(typeof e.end>"u"||typeof e.end=="number"))}};u=d([R(),y(0,m(x.Config)),y(1,m(O.PkiCertificateLoader))],u);export{u as HttpTransactionDataSource};
2
2
  //# sourceMappingURL=HttpTransactionDataSource.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/transaction/data/HttpTransactionDataSource.ts"],
4
- "sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport {\n type ContextModuleCalMode,\n type ContextModuleConfig,\n} from \"@/config/model/ContextModuleConfig\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { PkiCertificateInfo } from \"@/pki/model/PkiCertificateInfo\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport {\n ClearSignContextReference,\n ClearSignContextReferenceType,\n ClearSignContextSuccess,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { GenericPath } from \"@/shared/model/GenericPath\";\nimport { INFO_SIGNATURE_TAG } from \"@/shared/model/SignatureTags\";\nimport { HexStringUtils } from \"@/shared/utils/HexStringUtils\";\nimport PACKAGE from \"@root/package.json\";\n\nimport {\n CalldataDescriptor,\n CalldataDescriptorContainerPathV1,\n CalldataDescriptorParam,\n CalldataDescriptorPathElementsV1,\n CalldataDescriptorPathElementV1,\n CalldataDescriptorV1,\n CalldataDescriptorValueBinaryPathV1,\n CalldataDescriptorValueConstantV1,\n CalldataDescriptorValueV1,\n CalldataDto,\n CalldataEnumV1,\n CalldataFieldV1,\n CalldataSignatures,\n CalldataTransactionDescriptor,\n CalldataTransactionInfoV1,\n} from \"./dto/CalldataDto\";\nimport {\n GetTransactionDescriptorsParams,\n TransactionDataSource,\n} from \"./TransactionDataSource\";\n\n@injectable()\nexport class HttpTransactionDataSource implements TransactionDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n ) {}\n\n public async getTransactionDescriptors({\n chainId,\n address,\n selector,\n deviceModelId,\n }: GetTransactionDescriptorsParams): Promise<\n Either<Error, ClearSignContextSuccess[]>\n > {\n let dto: CalldataDto[] | undefined;\n try {\n const response = await axios.request<CalldataDto[]>({\n method: \"GET\",\n url: `${this.config.cal.url}/dapps`,\n params: {\n output: \"descriptors_calldata\",\n chain_id: chainId,\n contracts: address,\n // TODO revert to branch\n ref: `commit:ff75b9427f79c04c09d0b4378d6e01e2e6113e28`,\n },\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n dto = response.data;\n } catch (error) {\n return Left(\n new Error(\n `[ContextModule] HttpTransactionDataSource: Failed to fetch transaction informations: ${error}`,\n ),\n );\n }\n\n if (!Array.isArray(dto)) {\n return Left(\n new Error(\n `[ContextModule] HttpTransactionDataSource: Response is not an array`,\n ),\n );\n }\n\n if (dto.length === 0) {\n return Left(\n new Error(\n `[ContextModule] HttpTransactionDataSource: No data for contract ${address} and selector ${selector}`,\n ),\n );\n }\n\n for (const calldata of dto) {\n // Normalize the address and selector\n address = address.toLowerCase();\n selector = `0x${selector.slice(2).toLowerCase()}`;\n const calldataDescriptor =\n calldata.descriptors_calldata?.[address]?.[selector];\n\n if (\n !calldataDescriptor ||\n !this.isCalldataDescriptorV1(calldataDescriptor, this.config.cal.mode)\n ) {\n continue;\n }\n\n const infoData = calldataDescriptor.transaction_info.descriptor.data;\n const infoSignature =\n calldataDescriptor.transaction_info.descriptor.signatures[\n this.config.cal.mode\n ];\n\n const certificateInfos: PkiCertificateInfo = {\n targetDevice: deviceModelId,\n keyUsage: KeyUsage.Calldata,\n keyId: KeyId.CalCalldataKey,\n };\n const certificate: PkiCertificate | undefined =\n await this._certificateLoader.loadCertificate(certificateInfos);\n\n const info: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: HexStringUtils.appendSignatureToPayload(\n infoData,\n infoSignature,\n INFO_SIGNATURE_TAG,\n ),\n certificate,\n };\n\n const enums: ClearSignContextSuccess[] = [];\n for (const [id, values] of Object.entries(calldataDescriptor.enums)) {\n for (const [\n value,\n { data, signatures },\n ] of Object.entries<CalldataTransactionDescriptor>(values)) {\n enums.push({\n type: ClearSignContextType.ENUM,\n id: Number(id),\n value: Number(value),\n payload: HexStringUtils.appendSignatureToPayload(\n data,\n signatures[this.config.cal.mode]!,\n INFO_SIGNATURE_TAG,\n ),\n certificate,\n });\n }\n }\n\n const fields: ClearSignContextSuccess[] = calldataDescriptor.fields.map(\n (field) => ({\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: field.descriptor,\n reference: this.getReference(field.param),\n }),\n );\n return Right([info, ...enums, ...fields]);\n }\n\n return Left(\n new Error(\n `[ContextModule] HttpTransactionDataSource: Invalid response for contract ${address} and selector ${selector}`,\n ),\n );\n }\n\n private getReference(\n param: CalldataDescriptorParam,\n ): ClearSignContextReference | undefined {\n if (\n param.type === \"TOKEN_AMOUNT\" &&\n param.token !== undefined &&\n param.token.type === \"path\"\n ) {\n return {\n type: ClearSignContextReferenceType.TOKEN,\n valuePath: this.toGenericPath(param.token.binary_path),\n };\n } else if (\n param.type === \"TOKEN_AMOUNT\" &&\n param.token !== undefined &&\n param.token.type === \"constant\"\n ) {\n return {\n type: ClearSignContextReferenceType.TOKEN,\n value: param.token.value,\n };\n } else if (param.type === \"NFT\" && param.collection.type === \"path\") {\n return {\n type: ClearSignContextReferenceType.NFT,\n valuePath: this.toGenericPath(param.collection.binary_path),\n };\n } else if (param.type === \"NFT\" && param.collection.type === \"constant\") {\n return {\n type: ClearSignContextReferenceType.NFT,\n value: param.collection.value,\n };\n } else if (param.type === \"TRUSTED_NAME\" && param.value.type === \"path\") {\n return {\n type: ClearSignContextReferenceType.TRUSTED_NAME,\n valuePath: this.toGenericPath(param.value.binary_path),\n types: param.types,\n sources: param.sources,\n };\n } else if (param.type === \"ENUM\" && param.value.type === \"path\") {\n return {\n type: ClearSignContextReferenceType.ENUM,\n valuePath: this.toGenericPath(param.value.binary_path),\n id: param.id,\n };\n } else if (\n param.type === \"CALLDATA\" &&\n param.value.type === \"path\" &&\n param.callee.type === \"path\"\n ) {\n return {\n type: ClearSignContextReferenceType.CALLDATA,\n valuePath: this.toGenericPath(param.value.binary_path),\n callee: this.toGenericPath(param.callee.binary_path),\n selector:\n param.selector?.type === \"path\"\n ? this.toGenericPath(param.selector.binary_path)\n : undefined,\n amount:\n param.amount?.type === \"path\"\n ? this.toGenericPath(param.amount.binary_path)\n : undefined,\n spender:\n param.spender?.type === \"path\"\n ? this.toGenericPath(param.spender.binary_path)\n : undefined,\n chainId:\n param.chainId?.type === \"path\"\n ? this.toGenericPath(param.chainId.binary_path)\n : undefined,\n };\n }\n return undefined;\n }\n\n private toGenericPath(\n path: CalldataDescriptorContainerPathV1 | CalldataDescriptorPathElementsV1,\n ): GenericPath {\n if (path.type === \"CONTAINER\") {\n return path.value;\n }\n return path.elements.map((element) => {\n if (element.type === \"ARRAY\") {\n const { weight: itemSize, ...rest } = element;\n return {\n itemSize,\n ...rest,\n };\n } else if (element.type === \"LEAF\") {\n const { leaf_type: leafType, ...rest } = element;\n return {\n leafType,\n ...rest,\n };\n }\n return element;\n });\n }\n\n private isCalldataDescriptorV1(\n data: CalldataDescriptor,\n mode: ContextModuleCalMode,\n ): data is CalldataDescriptorV1 & {\n transaction_info: {\n descriptor: {\n signatures: { [_key in ContextModuleCalMode]: string };\n };\n };\n } {\n return (\n typeof data === \"object\" &&\n data.type === \"calldata\" &&\n data.version === \"v1\" &&\n this.isTransactionInfoV1(data.transaction_info, mode) &&\n this.isEnumV1(data.enums, mode) &&\n Array.isArray(data.fields) &&\n data.fields.every((f) => this.isFieldV1(f))\n );\n }\n\n private isTransactionInfoV1(\n data: CalldataTransactionInfoV1,\n mode: ContextModuleCalMode,\n ): data is CalldataTransactionInfoV1 & {\n descriptor: {\n signatures: { [_key in ContextModuleCalMode]: string };\n };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.descriptor === \"object\" &&\n typeof data.descriptor.data === \"string\" &&\n typeof data.descriptor.signatures === \"object\" &&\n typeof data.descriptor.signatures[mode] === \"string\"\n );\n }\n\n private isEnumV1(\n calldata: CalldataEnumV1,\n mode: ContextModuleCalMode,\n ): calldata is CalldataEnumV1 {\n return (\n typeof calldata === \"object\" &&\n Object.entries(calldata).every(\n ([id, values]) =>\n typeof id === \"string\" &&\n typeof values === \"object\" &&\n Object.entries<CalldataTransactionDescriptor>(values).every(\n ([value, obj]) =>\n typeof value === \"string\" &&\n typeof obj === \"object\" &&\n typeof obj.data === \"string\" &&\n obj.signatures !== undefined &&\n this.isCalldataSignatures(obj.signatures, mode),\n ),\n )\n );\n }\n\n private isCalldataSignatures(\n data: CalldataSignatures,\n mode: ContextModuleCalMode,\n ): data is CalldataSignatures & { [_key in ContextModuleCalMode]: string } {\n return typeof data === \"object\" && typeof data[mode] === \"string\";\n }\n\n private isFieldV1(data: CalldataFieldV1): boolean {\n return (\n typeof data === \"object\" &&\n typeof data.descriptor === \"string\" &&\n typeof data.param === \"object\" &&\n typeof data.param.value === \"object\" &&\n this.isDescriptorValueV1(data.param.value) &&\n (data.param.type === \"RAW\" ||\n data.param.type === \"AMOUNT\" ||\n data.param.type === \"DATETIME\" ||\n data.param.type === \"DURATION\" ||\n data.param.type === \"UNIT\" ||\n data.param.type === \"ENUM\" ||\n (data.param.type === \"NFT\" &&\n this.isDescriptorValueV1(data.param.collection)) ||\n (data.param.type === \"TOKEN_AMOUNT\" &&\n (data.param.token === undefined ||\n this.isDescriptorValueV1(data.param.token))) ||\n (data.param.type === \"TRUSTED_NAME\" &&\n Array.isArray(data.param.types) &&\n Array.isArray(data.param.sources) &&\n data.param.types.every((t) => typeof t === \"string\") &&\n data.param.sources.every((t) => typeof t === \"string\")) ||\n (data.param.type === \"CALLDATA\" &&\n this.isDescriptorValueV1(data.param.value) &&\n this.isDescriptorValueV1(data.param.callee) &&\n (data.param.selector === undefined ||\n this.isDescriptorValueV1(data.param.selector)) &&\n (data.param.amount === undefined ||\n this.isDescriptorValueV1(data.param.amount))))\n );\n }\n\n private isDescriptorValueV1(data: CalldataDescriptorValueV1): boolean {\n return (\n typeof data === \"object\" &&\n typeof data.type_family === \"string\" &&\n [\n \"UINT\",\n \"INT\",\n \"UFIXED\",\n \"FIXED\",\n \"ADDRESS\",\n \"BOOL\",\n \"BYTES\",\n \"STRING\",\n ].includes(data.type_family) &&\n (typeof data.type_size === \"undefined\" ||\n typeof data.type_size === \"number\") &&\n ((data.type === \"path\" &&\n this.isCalldataDescriptorValueBinaryPathV1(data)) ||\n (data.type === \"constant\" &&\n this.isCalldataDescriptorValueConstantV1(data)))\n );\n }\n\n private isCalldataDescriptorValueConstantV1(\n data: CalldataDescriptorValueConstantV1,\n ): boolean {\n return (\n typeof data === \"object\" &&\n data.type === \"constant\" &&\n typeof data.value === \"string\"\n );\n }\n\n private isCalldataDescriptorValueBinaryPathV1(\n data: CalldataDescriptorValueBinaryPathV1,\n ): boolean {\n return (\n typeof data === \"object\" &&\n ((data.type === \"path\" &&\n data.binary_path.type === \"CONTAINER\" &&\n [\"FROM\", \"TO\", \"VALUE\"].includes(data.binary_path.value)) ||\n (data.binary_path.type === \"DATA\" &&\n Array.isArray(data.binary_path.elements) &&\n data.binary_path.elements.every((e) => this.isPathElementV1(e))))\n );\n }\n\n private isPathElementV1(data: CalldataDescriptorPathElementV1): boolean {\n return (\n typeof data === \"object\" &&\n (data.type === \"REF\" ||\n (data.type === \"TUPLE\" && typeof data.offset === \"number\") ||\n (data.type === \"ARRAY\" &&\n typeof data.weight === \"number\" &&\n (typeof data.start === \"undefined\" ||\n typeof data.start === \"number\") &&\n (typeof data.end === \"undefined\" || typeof data.end === \"number\")) ||\n (data.type === \"LEAF\" &&\n typeof data.leaf_type === \"string\" &&\n [\"ARRAY_LEAF\", \"TUPLE_LEAF\", \"STATIC_LEAF\", \"DYNAMIC_LEAF\"].includes(\n data.leaf_type,\n )) ||\n (data.type === \"SLICE\" &&\n (typeof data.start === \"undefined\" ||\n typeof data.start === \"number\") &&\n (typeof data.end === \"undefined\" || typeof data.end === \"number\")))\n );\n }\n}\n"],
5
- "mappings": "iOAAA,OAAOA,MAAW,QAClB,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YACnC,OAAiB,QAAAC,EAAM,SAAAC,MAAa,YAEpC,OAAS,eAAAC,MAAmB,0BAK5B,OAAS,YAAAC,MAAgB,oBAEzB,OAAS,SAAAC,MAAa,oBACtB,OAAS,YAAAC,MAAgB,uBAGzB,OACE,gCAAAC,EACA,8BAAAC,MACK,gCACP,OAEE,iCAAAC,EAEA,wBAAAC,MACK,kCAEP,OAAS,sBAAAC,MAA0B,+BACnC,OAAS,kBAAAC,MAAsB,gCAC/B,OAAOC,MAAa,qBAyBb,IAAMC,EAAN,KAAiE,CACtE,YAC+CC,EAE5BC,EACjB,CAH6C,YAAAD,EAE5B,wBAAAC,CAChB,CAEH,MAAa,0BAA0B,CACrC,QAAAC,EACA,QAAAC,EACA,SAAAC,EACA,cAAAC,CACF,EAEE,CACA,IAAIC,EACJ,GAAI,CAgBFA,GAfiB,MAAMC,EAAM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tB,OAAOA,EAAK,MAAU,KACrB,OAAOA,EAAK,OAAU,YACvB,OAAOA,EAAK,IAAQ,KAAe,OAAOA,EAAK,KAAQ,WACzDA,EAAK,OAAS,QACb,OAAOA,EAAK,WAAc,UAC1B,CAAC,aAAc,aAAc,cAAe,cAAc,EAAE,SAC1DA,EAAK,SACP,GACDA,EAAK,OAAS,UACZ,OAAOA,EAAK,MAAU,KACrB,OAAOA,EAAK,OAAU,YACvB,OAAOA,EAAK,IAAQ,KAAe,OAAOA,EAAK,KAAQ,UAEhE,CACF,EA9Ya9B,EAAN8C,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAY,MAAM,GACzBF,EAAA,EAAAC,EAAOE,EAAS,oBAAoB,IAH5BnD",
4
+ "sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport {\n type ContextModuleCalMode,\n type ContextModuleConfig,\n} from \"@/config/model/ContextModuleConfig\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { PkiCertificateInfo } from \"@/pki/model/PkiCertificateInfo\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport {\n ClearSignContextReference,\n ClearSignContextReferenceType,\n ClearSignContextSuccess,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { GenericPath } from \"@/shared/model/GenericPath\";\nimport { INFO_SIGNATURE_TAG } from \"@/shared/model/SignatureTags\";\nimport { HexStringUtils } from \"@/shared/utils/HexStringUtils\";\nimport PACKAGE from \"@root/package.json\";\n\nimport {\n CalldataDescriptor,\n CalldataDescriptorContainerPathV1,\n CalldataDescriptorParam,\n CalldataDescriptorPathElementsV1,\n CalldataDescriptorPathElementV1,\n CalldataDescriptorV1,\n CalldataDescriptorValueBinaryPathV1,\n CalldataDescriptorValueConstantV1,\n CalldataDescriptorValueV1,\n CalldataDto,\n CalldataEnumV1,\n CalldataFieldV1,\n CalldataSignatures,\n CalldataTransactionDescriptor,\n CalldataTransactionInfoV1,\n} from \"./dto/CalldataDto\";\nimport {\n GetTransactionDescriptorsParams,\n TransactionDataSource,\n} from \"./TransactionDataSource\";\n\n@injectable()\nexport class HttpTransactionDataSource implements TransactionDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n ) {}\n\n public async getTransactionDescriptors({\n chainId,\n address,\n selector,\n deviceModelId,\n }: GetTransactionDescriptorsParams): Promise<\n Either<Error, ClearSignContextSuccess[]>\n > {\n let dto: CalldataDto[] | undefined;\n try {\n const response = await axios.request<CalldataDto[]>({\n method: \"GET\",\n url: `${this.config.cal.url}/dapps`,\n params: {\n output: \"descriptors_calldata\",\n chain_id: chainId,\n contracts: address,\n ref: `branch:${this.config.cal.branch}`,\n },\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n dto = response.data;\n } catch (error) {\n return Left(\n new Error(\n `[ContextModule] HttpTransactionDataSource: Failed to fetch transaction informations: ${error}`,\n ),\n );\n }\n\n if (!Array.isArray(dto)) {\n return Left(\n new Error(\n `[ContextModule] HttpTransactionDataSource: Response is not an array`,\n ),\n );\n }\n\n if (dto.length === 0) {\n return Left(\n new Error(\n `[ContextModule] HttpTransactionDataSource: No data for contract ${address} and selector ${selector}`,\n ),\n );\n }\n\n for (const calldata of dto) {\n // Normalize the address and selector\n address = address.toLowerCase();\n selector = `0x${selector.slice(2).toLowerCase()}`;\n const calldataDescriptor =\n calldata.descriptors_calldata?.[address]?.[selector];\n\n if (\n !calldataDescriptor ||\n !this.isCalldataDescriptorV1(calldataDescriptor, this.config.cal.mode)\n ) {\n continue;\n }\n\n const infoData = calldataDescriptor.transaction_info.descriptor.data;\n const infoSignature =\n calldataDescriptor.transaction_info.descriptor.signatures[\n this.config.cal.mode\n ];\n\n const certificateInfos: PkiCertificateInfo = {\n targetDevice: deviceModelId,\n keyUsage: KeyUsage.Calldata,\n keyId: KeyId.CalCalldataKey,\n };\n const certificate: PkiCertificate | undefined =\n await this._certificateLoader.loadCertificate(certificateInfos);\n\n const info: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: HexStringUtils.appendSignatureToPayload(\n infoData,\n infoSignature,\n INFO_SIGNATURE_TAG,\n ),\n certificate,\n };\n\n const enums: ClearSignContextSuccess[] = [];\n for (const [id, values] of Object.entries(calldataDescriptor.enums)) {\n for (const [\n value,\n { data, signatures },\n ] of Object.entries<CalldataTransactionDescriptor>(values)) {\n enums.push({\n type: ClearSignContextType.ENUM,\n id: Number(id),\n value: Number(value),\n payload: HexStringUtils.appendSignatureToPayload(\n data,\n signatures[this.config.cal.mode]!,\n INFO_SIGNATURE_TAG,\n ),\n certificate,\n });\n }\n }\n\n const fields: ClearSignContextSuccess[] = calldataDescriptor.fields.map(\n (field) => ({\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: field.descriptor,\n reference: this.getReference(field.param),\n }),\n );\n return Right([info, ...enums, ...fields]);\n }\n\n return Left(\n new Error(\n `[ContextModule] HttpTransactionDataSource: Invalid response for contract ${address} and selector ${selector}`,\n ),\n );\n }\n\n private getReference(\n param: CalldataDescriptorParam,\n ): ClearSignContextReference | undefined {\n if (\n param.type === \"TOKEN_AMOUNT\" &&\n param.token !== undefined &&\n param.token.type === \"path\"\n ) {\n return {\n type: ClearSignContextReferenceType.TOKEN,\n valuePath: this.toGenericPath(param.token.binary_path),\n };\n } else if (\n param.type === \"TOKEN_AMOUNT\" &&\n param.token !== undefined &&\n param.token.type === \"constant\"\n ) {\n return {\n type: ClearSignContextReferenceType.TOKEN,\n value: param.token.value,\n };\n } else if (param.type === \"NFT\" && param.collection.type === \"path\") {\n return {\n type: ClearSignContextReferenceType.NFT,\n valuePath: this.toGenericPath(param.collection.binary_path),\n };\n } else if (param.type === \"NFT\" && param.collection.type === \"constant\") {\n return {\n type: ClearSignContextReferenceType.NFT,\n value: param.collection.value,\n };\n } else if (param.type === \"TRUSTED_NAME\" && param.value.type === \"path\") {\n return {\n type: ClearSignContextReferenceType.TRUSTED_NAME,\n valuePath: this.toGenericPath(param.value.binary_path),\n types: param.types,\n sources: param.sources,\n };\n } else if (param.type === \"ENUM\" && param.value.type === \"path\") {\n return {\n type: ClearSignContextReferenceType.ENUM,\n valuePath: this.toGenericPath(param.value.binary_path),\n id: param.id,\n };\n } else if (\n param.type === \"CALLDATA\" &&\n param.value.type === \"path\" &&\n param.callee.type === \"path\"\n ) {\n return {\n type: ClearSignContextReferenceType.CALLDATA,\n valuePath: this.toGenericPath(param.value.binary_path),\n callee: this.toGenericPath(param.callee.binary_path),\n selector:\n param.selector?.type === \"path\"\n ? this.toGenericPath(param.selector.binary_path)\n : undefined,\n amount:\n param.amount?.type === \"path\"\n ? this.toGenericPath(param.amount.binary_path)\n : undefined,\n spender:\n param.spender?.type === \"path\"\n ? this.toGenericPath(param.spender.binary_path)\n : undefined,\n chainId:\n param.chainId?.type === \"path\"\n ? this.toGenericPath(param.chainId.binary_path)\n : undefined,\n };\n }\n return undefined;\n }\n\n private toGenericPath(\n path: CalldataDescriptorContainerPathV1 | CalldataDescriptorPathElementsV1,\n ): GenericPath {\n if (path.type === \"CONTAINER\") {\n return path.value;\n }\n return path.elements.map((element) => {\n if (element.type === \"ARRAY\") {\n const { weight: itemSize, ...rest } = element;\n return {\n itemSize,\n ...rest,\n };\n } else if (element.type === \"LEAF\") {\n const { leaf_type: leafType, ...rest } = element;\n return {\n leafType,\n ...rest,\n };\n }\n return element;\n });\n }\n\n private isCalldataDescriptorV1(\n data: CalldataDescriptor,\n mode: ContextModuleCalMode,\n ): data is CalldataDescriptorV1 & {\n transaction_info: {\n descriptor: {\n signatures: { [_key in ContextModuleCalMode]: string };\n };\n };\n } {\n return (\n typeof data === \"object\" &&\n data.type === \"calldata\" &&\n data.version === \"v1\" &&\n this.isTransactionInfoV1(data.transaction_info, mode) &&\n this.isEnumV1(data.enums, mode) &&\n Array.isArray(data.fields) &&\n data.fields.every((f) => this.isFieldV1(f))\n );\n }\n\n private isTransactionInfoV1(\n data: CalldataTransactionInfoV1,\n mode: ContextModuleCalMode,\n ): data is CalldataTransactionInfoV1 & {\n descriptor: {\n signatures: { [_key in ContextModuleCalMode]: string };\n };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.descriptor === \"object\" &&\n typeof data.descriptor.data === \"string\" &&\n typeof data.descriptor.signatures === \"object\" &&\n typeof data.descriptor.signatures[mode] === \"string\"\n );\n }\n\n private isEnumV1(\n calldata: CalldataEnumV1,\n mode: ContextModuleCalMode,\n ): calldata is CalldataEnumV1 {\n return (\n typeof calldata === \"object\" &&\n Object.entries(calldata).every(\n ([id, values]) =>\n typeof id === \"string\" &&\n typeof values === \"object\" &&\n Object.entries<CalldataTransactionDescriptor>(values).every(\n ([value, obj]) =>\n typeof value === \"string\" &&\n typeof obj === \"object\" &&\n typeof obj.data === \"string\" &&\n obj.signatures !== undefined &&\n this.isCalldataSignatures(obj.signatures, mode),\n ),\n )\n );\n }\n\n private isCalldataSignatures(\n data: CalldataSignatures,\n mode: ContextModuleCalMode,\n ): data is CalldataSignatures & { [_key in ContextModuleCalMode]: string } {\n return typeof data === \"object\" && typeof data[mode] === \"string\";\n }\n\n private isFieldV1(data: CalldataFieldV1): boolean {\n return (\n typeof data === \"object\" &&\n typeof data.descriptor === \"string\" &&\n typeof data.param === \"object\" &&\n typeof data.param.value === \"object\" &&\n this.isDescriptorValueV1(data.param.value) &&\n (data.param.type === \"RAW\" ||\n data.param.type === \"AMOUNT\" ||\n data.param.type === \"DATETIME\" ||\n data.param.type === \"DURATION\" ||\n data.param.type === \"UNIT\" ||\n data.param.type === \"ENUM\" ||\n (data.param.type === \"NFT\" &&\n this.isDescriptorValueV1(data.param.collection)) ||\n (data.param.type === \"TOKEN_AMOUNT\" &&\n (data.param.token === undefined ||\n this.isDescriptorValueV1(data.param.token))) ||\n (data.param.type === \"TRUSTED_NAME\" &&\n Array.isArray(data.param.types) &&\n Array.isArray(data.param.sources) &&\n data.param.types.every((t) => typeof t === \"string\") &&\n data.param.sources.every((t) => typeof t === \"string\")) ||\n (data.param.type === \"CALLDATA\" &&\n this.isDescriptorValueV1(data.param.value) &&\n this.isDescriptorValueV1(data.param.callee) &&\n (data.param.selector === undefined ||\n this.isDescriptorValueV1(data.param.selector)) &&\n (data.param.amount === undefined ||\n this.isDescriptorValueV1(data.param.amount)) &&\n (data.param.spender === undefined ||\n this.isDescriptorValueV1(data.param.spender)) &&\n (data.param.chainId === undefined ||\n this.isDescriptorValueV1(data.param.chainId))))\n );\n }\n\n private isDescriptorValueV1(data: CalldataDescriptorValueV1): boolean {\n return (\n typeof data === \"object\" &&\n typeof data.type_family === \"string\" &&\n [\n \"UINT\",\n \"INT\",\n \"UFIXED\",\n \"FIXED\",\n \"ADDRESS\",\n \"BOOL\",\n \"BYTES\",\n \"STRING\",\n ].includes(data.type_family) &&\n (typeof data.type_size === \"undefined\" ||\n typeof data.type_size === \"number\") &&\n ((data.type === \"path\" &&\n this.isCalldataDescriptorValueBinaryPathV1(data)) ||\n (data.type === \"constant\" &&\n this.isCalldataDescriptorValueConstantV1(data)))\n );\n }\n\n private isCalldataDescriptorValueConstantV1(\n data: CalldataDescriptorValueConstantV1,\n ): boolean {\n return (\n typeof data === \"object\" &&\n data.type === \"constant\" &&\n typeof data.value === \"string\"\n );\n }\n\n private isCalldataDescriptorValueBinaryPathV1(\n data: CalldataDescriptorValueBinaryPathV1,\n ): boolean {\n return (\n typeof data === \"object\" &&\n ((data.type === \"path\" &&\n data.binary_path.type === \"CONTAINER\" &&\n [\"FROM\", \"TO\", \"VALUE\"].includes(data.binary_path.value)) ||\n (data.binary_path.type === \"DATA\" &&\n Array.isArray(data.binary_path.elements) &&\n data.binary_path.elements.every((e) => this.isPathElementV1(e))))\n );\n }\n\n private isPathElementV1(data: CalldataDescriptorPathElementV1): boolean {\n return (\n typeof data === \"object\" &&\n (data.type === \"REF\" ||\n (data.type === \"TUPLE\" && typeof data.offset === \"number\") ||\n (data.type === \"ARRAY\" &&\n typeof data.weight === \"number\" &&\n (typeof data.start === \"undefined\" ||\n typeof data.start === \"number\") &&\n (typeof data.end === \"undefined\" || typeof data.end === \"number\")) ||\n (data.type === \"LEAF\" &&\n typeof data.leaf_type === \"string\" &&\n [\"ARRAY_LEAF\", \"TUPLE_LEAF\", \"STATIC_LEAF\", \"DYNAMIC_LEAF\"].includes(\n data.leaf_type,\n )) ||\n (data.type === \"SLICE\" &&\n (typeof data.start === \"undefined\" ||\n typeof data.start === \"number\") &&\n (typeof data.end === \"undefined\" || typeof data.end === \"number\")))\n );\n }\n}\n"],
5
+ "mappings": "iOAAA,OAAOA,MAAW,QAClB,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YACnC,OAAiB,QAAAC,EAAM,SAAAC,MAAa,YAEpC,OAAS,eAAAC,MAAmB,0BAK5B,OAAS,YAAAC,MAAgB,oBAEzB,OAAS,SAAAC,MAAa,oBACtB,OAAS,YAAAC,MAAgB,uBAGzB,OACE,gCAAAC,EACA,8BAAAC,MACK,gCACP,OAEE,iCAAAC,EAEA,wBAAAC,MACK,kCAEP,OAAS,sBAAAC,MAA0B,+BACnC,OAAS,kBAAAC,MAAsB,gCAC/B,OAAOC,MAAa,qBAyBb,IAAMC,EAAN,KAAiE,CACtE,YAC+CC,EAE5BC,EACjB,CAH6C,YAAAD,EAE5B,wBAAAC,CAChB,CAEH,MAAa,0BAA0B,CACrC,QAAA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AAM,QAAQA,EAAK,YAAY,QAAQ,GACvCA,EAAK,YAAY,SAAS,MAAOe,GAAM,KAAK,gBAAgBA,CAAC,CAAC,EAEtE,CAEQ,gBAAgBf,EAAgD,CACtE,OACE,OAAOA,GAAS,WACfA,EAAK,OAAS,OACZA,EAAK,OAAS,SAAW,OAAOA,EAAK,QAAW,UAChDA,EAAK,OAAS,SACb,OAAOA,EAAK,QAAW,WACtB,OAAOA,EAAK,MAAU,KACrB,OAAOA,EAAK,OAAU,YACvB,OAAOA,EAAK,IAAQ,KAAe,OAAOA,EAAK,KAAQ,WACzDA,EAAK,OAAS,QACb,OAAOA,EAAK,WAAc,UAC1B,CAAC,aAAc,aAAc,cAAe,cAAc,EAAE,SAC1DA,EAAK,SACP,GACDA,EAAK,OAAS,UACZ,OAAOA,EAAK,MAAU,KACrB,OAAOA,EAAK,OAAU,YACvB,OAAOA,EAAK,IAAQ,KAAe,OAAOA,EAAK,KAAQ,UAEhE,CACF,EAjZa9B,EAAN8C,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAY,MAAM,GACzBF,EAAA,EAAAC,EAAOE,EAAS,oBAAoB,IAH5BnD",
6
6
  "names": ["axios", "inject", "injectable", "Left", "Right", "configTypes", "pkiTypes", "KeyId", "KeyUsage", "LEDGER_CLIENT_VERSION_HEADER", "LEDGER_ORIGIN_TOKEN_HEADER", "ClearSignContextReferenceType", "ClearSignContextType", "INFO_SIGNATURE_TAG", "HexStringUtils", "PACKAGE", "HttpTransactionDataSource", "config", "_certificateLoader", "chainId", "address", "selector", "deviceModelId", "dto", "axios", "LEDGER_CLIENT_VERSION_HEADER", "PACKAGE", "LEDGER_ORIGIN_TOKEN_HEADER", "error", "Left", "calldata", "calldataDescriptor", "infoData", "infoSignature", "certificateInfos", "KeyUsage", "KeyId", "certificate", "info", "ClearSignContextType", "HexStringUtils", "INFO_SIGNATURE_TAG", "enums", "id", "values", "value", "data", "signatures", "fields", "field", "Right", "param", "ClearSignContextReferenceType", "path", "element", "itemSize", "rest", "leafType", "mode", "f", "obj", "e", "__decorateClass", "injectable", "__decorateParam", "inject", "configTypes", "pkiTypes"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var D=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var p=(i,t,e,a)=>{for(var r=a>1?void 0:a?S(t,e):t,n=i.length-1,s;n>=0;n--)(s=i[n])&&(r=(a?s(t,e,r):s(r))||r);return a&&r&&D(t,e,r),r},l=(i,t)=>(e,a)=>t(e,a,i);import{DeviceModelId as P,isHexaString as R}from"@ledgerhq/device-management-kit";import{inject as g,injectable as T}from"inversify";import{proxyTypes as v}from"../../proxy/di/proxyTypes";import{ClearSignContextType as d}from"../../shared/model/ClearSignContext";import{transactionTypes as A}from"../../transaction/di/transactionTypes";let c=class{constructor(t,e){this.transactionDataSource=t;this.proxyDataSource=e}async load(t){if(t.deviceModelId===P.NANO_S)return[];const{to:e,data:a,selector:r,chainId:n,deviceModelId:s}=t;if(e===void 0)return[];if(!R(r))return[{type:d.ERROR,error:new Error("Invalid selector")}];const x=await this.proxyDataSource.getProxyDelegateCall({calldata:a,proxyAddress:e,chainId:n,challenge:""}),[m,y]=x.caseOf({Left:()=>[e,void 0],Right:o=>[o.delegateAddresses.find(C=>C===e)||o.delegateAddresses[0],o.signedDescriptor]}),f=y?[{type:d.PROXY_DELEGATE_CALL,payload:"0x"}]:[],u=(await this.transactionDataSource.getTransactionDescriptors({deviceModelId:s,address:m,chainId:n,selector:r})).caseOf({Left:o=>[{type:d.ERROR,error:o}],Right:o=>o});return[...f,...u]}};c=p([T(),l(0,g(A.TransactionDataSource)),l(1,g(v.ProxyDataSource))],c);export{c as TransactionContextLoader};
1
+ var f=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var u=(i,e,t,o)=>{for(var r=o>1?void 0:o?C(e,t):e,a=i.length-1,n;a>=0;a--)(n=i[a])&&(r=(o?n(e,t,r):n(r))||r);return o&&r&&f(e,t,r),r},p=(i,e)=>(t,o)=>e(t,o,i);import{DeviceModelId as g,isHexaString as D}from"@ledgerhq/device-management-kit";import{inject as m,injectable as S}from"inversify";import{proxyTypes as R}from"../../proxy/di/proxyTypes";import{ClearSignContextType as s}from"../../shared/model/ClearSignContext";import{transactionTypes as h}from"../../transaction/di/transactionTypes";let c=class{constructor(e,t){this.transactionDataSource=e;this.proxyDataSource=t}async load(e){if(e.deviceModelId===g.NANO_S)return[];const{to:t,data:o,selector:r,chainId:a,deviceModelId:n}=e;if(t===void 0)return[];if(!D(r))return[{type:s.ERROR,error:new Error("Invalid selector")}];const l=await this.transactionDataSource.getTransactionDescriptors({deviceModelId:n,address:t,chainId:a,selector:r});return l.isRight()&&l.extract().length>0?l.extract():(await this.proxyDataSource.getProxyDelegateCall({calldata:o,proxyAddress:t,chainId:a,challenge:""})).caseOf({Right:async({delegateAddresses:y})=>{const d=y[0];if(!d)return[{type:s.ERROR,error:new Error(`[ContextModule] TransactionContextLoader: No delegate address found for proxy ${t}`)}];const x=await this.transactionDataSource.getTransactionDescriptors({deviceModelId:n,address:d,chainId:a,selector:r});return x.isRight()&&x.extract().length>0?[{type:s.PROXY_DELEGATE_CALL,payload:"0x"},...x.extract()]:[{type:s.ERROR,error:new Error(`[ContextModule] TransactionContextLoader: Unable to fetch contexts from contract address using proxy delegate call ${d}`)}]},Left:y=>Promise.resolve([{type:s.ERROR,error:new Error(`[ContextModule] TransactionContextLoader: Unable to fetch contexts from contract address ${t}`)}])})}};c=u([S(),p(0,m(h.TransactionDataSource)),p(1,m(R.ProxyDataSource))],c);export{c as TransactionContextLoader};
2
2
  //# sourceMappingURL=TransactionContextLoader.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/transaction/domain/TransactionContextLoader.ts"],
4
- "sourcesContent": ["import { DeviceModelId, isHexaString } from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport type { ProxyDataSource } from \"@/proxy/data/HttpProxyDataSource\";\nimport { proxyTypes } from \"@/proxy/di/proxyTypes\";\nimport { ProxyDelegateCall } from \"@/proxy/model/ProxyDelegateCall\";\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { TransactionContext } from \"@/shared/model/TransactionContext\";\nimport type { TransactionDataSource } from \"@/transaction/data/TransactionDataSource\";\nimport { transactionTypes } from \"@/transaction/di/transactionTypes\";\n\n@injectable()\nexport class TransactionContextLoader implements ContextLoader {\n constructor(\n @inject(transactionTypes.TransactionDataSource)\n private transactionDataSource: TransactionDataSource,\n @inject(proxyTypes.ProxyDataSource)\n private proxyDataSource: ProxyDataSource,\n ) {}\n\n async load(ctx: TransactionContext): Promise<ClearSignContext[]> {\n if (ctx.deviceModelId === DeviceModelId.NANO_S) {\n return [];\n }\n\n const { to, data, selector, chainId, deviceModelId } = ctx;\n if (to === undefined) {\n return [];\n }\n\n if (!isHexaString(selector)) {\n return [\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Invalid selector\"),\n },\n ];\n }\n\n const proxyDelegateCall = await this.proxyDataSource.getProxyDelegateCall({\n calldata: data,\n proxyAddress: to,\n chainId,\n challenge: \"\",\n });\n\n // get the resolved address from the list of delegate addresses\n // if the transaction.to is not in the list of delegate addresses,\n // return the first element as the resolved address,\n // and undefined as the proxy delegate call descriptor\n // if the transaction.to is in the list of delegate addresses,\n // return the transaction.to as the resolved address,\n // and the proxy delegate call descriptor\n const [resolvedAddress, proxyDelegateCallDescriptor]: [\n string,\n string | undefined,\n ] = proxyDelegateCall.caseOf({\n Left: () => [to!, undefined],\n Right: (proxyData: ProxyDelegateCall): [string, string | undefined] => {\n return [\n proxyData.delegateAddresses.find((address) => address === to) ||\n proxyData.delegateAddresses[0]!,\n proxyData.signedDescriptor,\n ];\n },\n });\n\n const proxyDelegateCallContext: ClearSignContext[] =\n proxyDelegateCallDescriptor\n ? [\n {\n type: ClearSignContextType.PROXY_DELEGATE_CALL,\n // This payload is not used as the clear sign context is not used, only the subcontext that will be\n // fetched during the provide, with a correct challenge\n payload: \"0x\",\n },\n ]\n : [];\n\n const transactionContexts = (\n await this.transactionDataSource.getTransactionDescriptors({\n deviceModelId,\n address: resolvedAddress,\n chainId,\n selector,\n })\n ).caseOf({\n Left: (error): ClearSignContext[] => [\n {\n type: ClearSignContextType.ERROR,\n error,\n },\n ],\n Right: (contexts): ClearSignContext[] => contexts,\n });\n\n return [...proxyDelegateCallContext, ...transactionContexts];\n }\n}\n"],
5
- "mappings": "iOAAA,OAAS,iBAAAA,EAAe,gBAAAC,MAAoB,kCAC5C,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YAGnC,OAAS,cAAAC,MAAkB,wBAG3B,OAEE,wBAAAC,MACK,kCAGP,OAAS,oBAAAC,MAAwB,oCAG1B,IAAMC,EAAN,KAAwD,CAC7D,YAEUC,EAEAC,EACR,CAHQ,2BAAAD,EAEA,qBAAAC,CACP,CAEH,MAAM,KAAKC,EAAsD,CAC/D,GAAIA,EAAI,gBAAkBC,EAAc,OACtC,MAAO,CAAC,EAGV,KAAM,CAAE,GAAAC,EAAI,KAAAC,EAAM,SAAAC,EAAU,QAAAC,EAAS,cAAAC,CAAc,EAAIN,EACvD,GAAIE,IAAO,OACT,MAAO,CAAC,EAGV,GAAI,CAACK,EAAaH,CAAQ,EACxB,MAAO,CACL,CACE,KAAMI,EAAqB,MAC3B,MAAO,IAAI,MAAM,kBAAkB,CACrC,CACF,EAGF,MAAMC,EAAoB,MAAM,KAAK,gBAAgB,qBAAqB,CACxE,SAAUN,EACV,aAAcD,EACd,QAAAG,EACA,UAAW,EACb,CAAC,EASK,CAACK,EAAiBC,CAA2B,EAG/CF,EAAkB,OAAO,CAC3B,KAAM,IAAM,CAACP,EAAK,MAAS,EAC3B,MAAQU,GACC,CACLA,EAAU,kBAAkB,KAAMC,GAAYA,IAAYX,CAAE,GAC1DU,EAAU,kBAAkB,CAAC,EAC/BA,EAAU,gBACZ,CAEJ,CAAC,EAEKE,EACJH,EACI,CACE,CACE,KAAMH,EAAqB,oBAG3B,QAAS,IACX,CACF,EACA,CAAC,EAEDO,GACJ,MAAM,KAAK,sBAAsB,0BAA0B,CACzD,cAAAT,EACA,QAASI,EACT,QAAAL,EACA,SAAAD,CACF,CAAC,GACD,OAAO,CACP,KAAOY,GAA8B,CACnC,CACE,KAAMR,EAAqB,MAC3B,MAAAQ,CACF,CACF,EACA,MAAQC,GAAiCA,CAC3C,CAAC,EAED,MAAO,CAAC,GAAGH,EAA0B,GAAGC,CAAmB,CAC7D,CACF,EAtFalB,EAANqB,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAiB,qBAAqB,GAE7CF,EAAA,EAAAC,EAAOE,EAAW,eAAe,IAJzB1B",
6
- "names": ["DeviceModelId", "isHexaString", "inject", "injectable", "proxyTypes", "ClearSignContextType", "transactionTypes", "TransactionContextLoader", "transactionDataSource", "proxyDataSource", "ctx", "DeviceModelId", "to", "data", "selector", "chainId", "deviceModelId", "isHexaString", "ClearSignContextType", "proxyDelegateCall", "resolvedAddress", "proxyDelegateCallDescriptor", "proxyData", "address", "proxyDelegateCallContext", "transactionContexts", "error", "contexts", "__decorateClass", "injectable", "__decorateParam", "inject", "transactionTypes", "proxyTypes"]
4
+ "sourcesContent": ["import { DeviceModelId, isHexaString } from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport type { ProxyDataSource } from \"@/proxy/data/HttpProxyDataSource\";\nimport { proxyTypes } from \"@/proxy/di/proxyTypes\";\nimport { ProxyDelegateCall } from \"@/proxy/model/ProxyDelegateCall\";\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { TransactionContext } from \"@/shared/model/TransactionContext\";\nimport type { TransactionDataSource } from \"@/transaction/data/TransactionDataSource\";\nimport { transactionTypes } from \"@/transaction/di/transactionTypes\";\n\n@injectable()\nexport class TransactionContextLoader implements ContextLoader {\n constructor(\n @inject(transactionTypes.TransactionDataSource)\n private transactionDataSource: TransactionDataSource,\n @inject(proxyTypes.ProxyDataSource)\n private proxyDataSource: ProxyDataSource,\n ) {}\n\n async load(ctx: TransactionContext): Promise<ClearSignContext[]> {\n if (ctx.deviceModelId === DeviceModelId.NANO_S) {\n return [];\n }\n\n const { to, data, selector, chainId, deviceModelId } = ctx;\n if (to === undefined) {\n return [];\n }\n\n if (!isHexaString(selector)) {\n return [\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Invalid selector\"),\n },\n ];\n }\n\n // try to fetch the transaction descriptors from the transaction data source\n // using the smart contract address to\n const transactionContexts =\n await this.transactionDataSource.getTransactionDescriptors({\n deviceModelId,\n address: to,\n chainId,\n selector,\n });\n\n if (\n transactionContexts.isRight() &&\n transactionContexts.extract().length > 0\n ) {\n return transactionContexts.extract();\n }\n\n // if the transaction descriptors are not found, try to fetch the proxy delegate call\n // and return the proxy delegate call context\n const proxyDelegateCall = await this.proxyDataSource.getProxyDelegateCall({\n calldata: data,\n proxyAddress: to,\n chainId,\n challenge: \"\",\n });\n\n return proxyDelegateCall.caseOf<Promise<ClearSignContext[]>>({\n Right: async ({ delegateAddresses }: ProxyDelegateCall) => {\n const resolvedAddress = delegateAddresses[0];\n\n if (!resolvedAddress) {\n return [\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\n `[ContextModule] TransactionContextLoader: No delegate address found for proxy ${to}`,\n ),\n },\n ];\n }\n\n const transactionProxyContexts =\n await this.transactionDataSource.getTransactionDescriptors({\n deviceModelId,\n address: resolvedAddress,\n chainId,\n selector,\n });\n\n if (\n transactionProxyContexts.isRight() &&\n transactionProxyContexts.extract().length > 0\n ) {\n return [\n // This payload is not used as the clear sign context is not used, only the subcontext that will be\n // fetched during the provide, with a correct challenge\n {\n type: ClearSignContextType.PROXY_DELEGATE_CALL,\n payload: \"0x\",\n },\n ...transactionProxyContexts.extract(),\n ];\n }\n\n return [\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\n `[ContextModule] TransactionContextLoader: Unable to fetch contexts from contract address using proxy delegate call ${resolvedAddress}`,\n ),\n },\n ];\n },\n Left: (_) => {\n return Promise.resolve([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\n `[ContextModule] TransactionContextLoader: Unable to fetch contexts from contract address ${to}`,\n ),\n },\n ]);\n },\n });\n }\n}\n"],
5
+ "mappings": "iOAAA,OAAS,iBAAAA,EAAe,gBAAAC,MAAoB,kCAC5C,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YAGnC,OAAS,cAAAC,MAAkB,wBAG3B,OAEE,wBAAAC,MACK,kCAGP,OAAS,oBAAAC,MAAwB,oCAG1B,IAAMC,EAAN,KAAwD,CAC7D,YAEUC,EAEAC,EACR,CAHQ,2BAAAD,EAEA,qBAAAC,CACP,CAEH,MAAM,KAAKC,EAAsD,CAC/D,GAAIA,EAAI,gBAAkBC,EAAc,OACtC,MAAO,CAAC,EAGV,KAAM,CAAE,GAAAC,EAAI,KAAAC,EAAM,SAAAC,EAAU,QAAAC,EAAS,cAAAC,CAAc,EAAIN,EACvD,GAAIE,IAAO,OACT,MAAO,CAAC,EAGV,GAAI,CAACK,EAAaH,CAAQ,EACxB,MAAO,CACL,CACE,KAAMI,EAAqB,MAC3B,MAAO,IAAI,MAAM,kBAAkB,CACrC,CACF,EAKF,MAAMC,EACJ,MAAM,KAAK,sBAAsB,0BAA0B,CACzD,cAAAH,EACA,QAASJ,EACT,QAAAG,EACA,SAAAD,CACF,CAAC,EAEH,OACEK,EAAoB,QAAQ,GAC5BA,EAAoB,QAAQ,EAAE,OAAS,EAEhCA,EAAoB,QAAQ,GAKX,MAAM,KAAK,gBAAgB,qBAAqB,CACxE,SAAUN,EACV,aAAcD,EACd,QAAAG,EACA,UAAW,EACb,CAAC,GAEwB,OAAoC,CAC3D,MAAO,MAAO,CAAE,kBAAAK,CAAkB,IAAyB,CACzD,MAAMC,EAAkBD,EAAkB,CAAC,EAE3C,GAAI,CAACC,EACH,MAAO,CACL,CACE,KAAMH,EAAqB,MAC3B,MAAO,IAAI,MACT,iFAAiFN,CAAE,EACrF,CACF,CACF,EAGF,MAAMU,EACJ,MAAM,KAAK,sBAAsB,0BAA0B,CACzD,cAAAN,EACA,QAASK,EACT,QAAAN,EACA,SAAAD,CACF,CAAC,EAEH,OACEQ,EAAyB,QAAQ,GACjCA,EAAyB,QAAQ,EAAE,OAAS,EAErC,CAGL,CACE,KAAMJ,EAAqB,oBAC3B,QAAS,IACX,EACA,GAAGI,EAAyB,QAAQ,CACtC,EAGK,CACL,CACE,KAAMJ,EAAqB,MAC3B,MAAO,IAAI,MACT,sHAAsHG,CAAe,EACvI,CACF,CACF,CACF,EACA,KAAOE,GACE,QAAQ,QAAQ,CACrB,CACE,KAAML,EAAqB,MAC3B,MAAO,IAAI,MACT,4FAA4FN,CAAE,EAChG,CACF,CACF,CAAC,CAEL,CAAC,CACH,CACF,EAhHaL,EAANiB,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAiB,qBAAqB,GAE7CF,EAAA,EAAAC,EAAOE,EAAW,eAAe,IAJzBtB",
6
+ "names": ["DeviceModelId", "isHexaString", "inject", "injectable", "proxyTypes", "ClearSignContextType", "transactionTypes", "TransactionContextLoader", "transactionDataSource", "proxyDataSource", "ctx", "DeviceModelId", "to", "data", "selector", "chainId", "deviceModelId", "isHexaString", "ClearSignContextType", "transactionContexts", "delegateAddresses", "resolvedAddress", "transactionProxyContexts", "_", "__decorateClass", "injectable", "__decorateParam", "inject", "transactionTypes", "proxyTypes"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{Left as c,Right as n}from"purify-ts";import{ClearSignContextType as e}from"../../shared/model/ClearSignContext";import{TransactionContextLoader as i}from"../../transaction/domain/TransactionContextLoader";describe("TransactionContextLoader",()=>{const r=vi.fn(),s=vi.fn(),d={getTransactionDescriptors:r},l={getProxyDelegateCall:s,getProxyImplementationAddress:vi.fn()},o=new i(d,l);beforeEach(()=>{vi.resetAllMocks()}),it("should return an empty array if no destination address is provided",async()=>{const a={},t=await o.load(a);expect(t).toEqual([])}),it("should return an empty array if 'to' is undefined",async()=>{const a={to:void 0,data:"0x"},t=await o.load(a);expect(t).toEqual([])}),it("should return an error if selector is invalid",async()=>{const a={to:"0x7",chainId:3,data:"0xzf68b302000000000000000000000000000000000000000000000000000000000002"},t=await o.load(a);expect(t).toEqual([{type:e.ERROR,error:new Error("Invalid selector")}])}),it("should return an error if data source fails",async()=>{s.mockResolvedValue(c(new Error("data source error"))),r.mockResolvedValue(c(new Error("data source error")));const a={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await o.load(a);expect(r).toHaveBeenCalledWith({address:"0x7",chainId:3,selector:"0xaf68b302"}),expect(t).toEqual([{type:e.ERROR,error:new Error("data source error")}])}),it("should return the contexts on success",async()=>{r.mockResolvedValue(n([{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),s.mockResolvedValue(c(new Error("data source error")));const a={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await o.load(a);expect(t).toEqual([{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])}),it("should return the proxy delegate call context on success",async()=>{r.mockResolvedValue(n([{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),s.mockResolvedValue(n({delegateAddresses:["0x7"],signedDescriptor:"0x1234567890abcdef"}));const a={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await o.load(a);expect(t).toEqual([{type:e.PROXY_DELEGATE_CALL,payload:"0x"},{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])}),it("should return the proxy delegate call context if the transaction.to is in the delegate addresses and the transaction.to is not the first element",async()=>{r.mockResolvedValue(n([{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),s.mockResolvedValue(n({delegateAddresses:["0x7","0x8"],signedDescriptor:"0x1234567890abcdef"}));const a={to:"0x8",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await o.load(a);expect(t).toEqual([{type:e.PROXY_DELEGATE_CALL,payload:"0x"},{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])}),it("should return the proxy delegate call context if the transaction.to is not in the delegate addresses",async()=>{r.mockResolvedValue(n([{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),s.mockResolvedValue(n({delegateAddresses:["0x8"],signedDescriptor:"0x1234567890abcdef"}));const a={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await o.load(a);expect(t).toEqual([{type:e.PROXY_DELEGATE_CALL,payload:"0x"},{type:e.TRANSACTION_INFO,payload:"1234567890"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])})});
1
+ import{DeviceModelId as i}from"@ledgerhq/device-management-kit";import{Left as c,Right as n}from"purify-ts";import{ClearSignContextType as a}from"../../shared/model/ClearSignContext";import{TransactionContextLoader as x}from"../../transaction/domain/TransactionContextLoader";describe("TransactionContextLoader",()=>{const o=vi.fn(),s=vi.fn(),d={getTransactionDescriptors:o},l={getProxyDelegateCall:s,getProxyImplementationAddress:vi.fn()},r=new x(d,l);beforeEach(()=>{vi.resetAllMocks()}),it("should return an empty array if no destination address is provided",async()=>{const e={},t=await r.load(e);expect(t).toEqual([])}),it("should return an empty array if 'to' is undefined",async()=>{const e={to:void 0,data:"0x"},t=await r.load(e);expect(t).toEqual([])}),it("should return an error if selector is invalid",async()=>{const e={to:"0x7",chainId:3,data:"0xzf68b302000000000000000000000000000000000000000000000000000000000002"},t=await r.load(e);expect(t).toEqual([{type:a.ERROR,error:new Error("Invalid selector")}])}),it("should return an error if data source fails",async()=>{s.mockResolvedValue(c(new Error("data source error"))),o.mockResolvedValue(c(new Error("data source error")));const e={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await r.load(e);expect(o).toHaveBeenCalledWith({address:"0x7",chainId:3,selector:"0xaf68b302"}),expect(t).toEqual([{type:a.ERROR,error:new Error("[ContextModule] TransactionContextLoader: Unable to fetch contexts from contract address 0x7")}])}),it("should return the contexts on success",async()=>{o.mockResolvedValue(n([{type:a.TRANSACTION_INFO,payload:"1234567890"},{type:a.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),s.mockResolvedValue(c(new Error("data source error")));const e={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await r.load(e);expect(t).toEqual([{type:a.TRANSACTION_INFO,payload:"1234567890"},{type:a.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])}),it("should return the proxy delegate call context on success",async()=>{o.mockResolvedValueOnce(n([])),o.mockResolvedValue(n([{type:a.TRANSACTION_INFO,payload:"1234567890"},{type:a.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),s.mockResolvedValue(n({delegateAddresses:["0x7"],signedDescriptor:"0x1234567890abcdef"}));const e={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await r.load(e);expect(t).toEqual([{type:a.PROXY_DELEGATE_CALL,payload:"0x"},{type:a.TRANSACTION_INFO,payload:"1234567890"},{type:a.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])}),it("should return an empty array if device model is NANO_S",async()=>{const e={deviceModelId:i.NANO_S,to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await r.load(e);expect(t).toEqual([]),expect(o).not.toHaveBeenCalled(),expect(s).not.toHaveBeenCalled()}),it("should return an error when proxy delegate call succeeds but no delegate addresses are found",async()=>{o.mockResolvedValueOnce(n([])),s.mockResolvedValue(n({delegateAddresses:[],signedDescriptor:"0x1234567890abcdef"}));const e={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await r.load(e);expect(t).toEqual([{type:a.ERROR,error:new Error("[ContextModule] TransactionContextLoader: No delegate address found for proxy 0x7")}])}),it("should return an error when proxy delegate call succeeds but transaction descriptors for resolved address fail",async()=>{o.mockResolvedValueOnce(n([])),o.mockResolvedValueOnce(c(new Error("data source error"))),s.mockResolvedValue(n({delegateAddresses:["0xResolvedAddress"],signedDescriptor:"0x1234567890abcdef"}));const e={to:"0x7",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302"},t=await r.load(e);expect(o).toHaveBeenCalledTimes(2),expect(o).toHaveBeenNthCalledWith(2,{address:"0xResolvedAddress",chainId:3,selector:"0xaf68b302"}),expect(t).toEqual([{type:a.ERROR,error:new Error("[ContextModule] TransactionContextLoader: Unable to fetch contexts from contract address using proxy delegate call 0xResolvedAddress")}])})});
2
2
  //# sourceMappingURL=TransactionContextLoader.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/transaction/domain/TransactionContextLoader.test.ts"],
4
- "sourcesContent": ["import { Left, Right } from \"purify-ts\";\n\nimport type { ProxyDataSource } from \"@/proxy/data/HttpProxyDataSource\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport type { TransactionContext } from \"@/shared/model/TransactionContext\";\nimport type { TransactionDataSource } from \"@/transaction/data/TransactionDataSource\";\nimport { TransactionContextLoader } from \"@/transaction/domain/TransactionContextLoader\";\n\ndescribe(\"TransactionContextLoader\", () => {\n const getTransactionDescriptorsMock = vi.fn();\n const getProxyDelegateCallMock = vi.fn();\n const mockTransactionDataSource: TransactionDataSource = {\n getTransactionDescriptors: getTransactionDescriptorsMock,\n };\n const mockProxyDatasource: ProxyDataSource = {\n getProxyDelegateCall: getProxyDelegateCallMock,\n getProxyImplementationAddress: vi.fn(),\n };\n const loader = new TransactionContextLoader(\n mockTransactionDataSource,\n mockProxyDatasource,\n );\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n it(\"should return an empty array if no destination address is provided\", async () => {\n // GIVEN\n const transaction = {} as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if 'to' is undefined\", async () => {\n // GIVEN\n const transaction = { to: undefined, data: \"0x\" } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an error if selector is invalid\", async () => {\n // GIVEN\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xzf68b302000000000000000000000000000000000000000000000000000000000002\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Invalid selector\"),\n },\n ]);\n });\n\n it(\"should return an error if data source fails\", async () => {\n // GIVEN\n getProxyDelegateCallMock.mockResolvedValue(\n Left(new Error(\"data source error\")),\n );\n getTransactionDescriptorsMock.mockResolvedValue(\n Left(new Error(\"data source error\")),\n );\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(getTransactionDescriptorsMock).toHaveBeenCalledWith({\n address: \"0x7\",\n chainId: 3,\n selector: \"0xaf68b302\",\n });\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"data source error\"),\n },\n ]);\n });\n\n it(\"should return the contexts on success\", async () => {\n // GIVEN\n getTransactionDescriptorsMock.mockResolvedValue(\n Right([\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]),\n );\n getProxyDelegateCallMock.mockResolvedValue(\n Left(new Error(\"data source error\")),\n );\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]);\n });\n\n it(\"should return the proxy delegate call context on success\", async () => {\n // GIVEN\n getTransactionDescriptorsMock.mockResolvedValue(\n Right([\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]),\n );\n getProxyDelegateCallMock.mockResolvedValue(\n Right({\n delegateAddresses: [\"0x7\"],\n signedDescriptor: \"0x1234567890abcdef\",\n }),\n );\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.PROXY_DELEGATE_CALL,\n payload: \"0x\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]);\n });\n\n it(\"should return the proxy delegate call context if the transaction.to is in the delegate addresses and the transaction.to is not the first element\", async () => {\n // GIVEN\n getTransactionDescriptorsMock.mockResolvedValue(\n Right([\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]),\n );\n getProxyDelegateCallMock.mockResolvedValue(\n Right({\n delegateAddresses: [\"0x7\", \"0x8\"],\n signedDescriptor: \"0x1234567890abcdef\",\n }),\n );\n const transaction = {\n to: \"0x8\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.PROXY_DELEGATE_CALL,\n payload: \"0x\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]);\n });\n\n it(\"should return the proxy delegate call context if the transaction.to is not in the delegate addresses\", async () => {\n // GIVEN\n getTransactionDescriptorsMock.mockResolvedValue(\n Right([\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]),\n );\n getProxyDelegateCallMock.mockResolvedValue(\n Right({\n delegateAddresses: [\"0x8\"],\n signedDescriptor: \"0x1234567890abcdef\",\n }),\n );\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.PROXY_DELEGATE_CALL,\n payload: \"0x\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]);\n });\n});\n"],
5
- "mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAG5B,OAAS,wBAAAC,MAA4B,kCAGrC,OAAS,4BAAAC,MAAgC,gDAEzC,SAAS,2BAA4B,IAAM,CACzC,MAAMC,EAAgC,GAAG,GAAG,EACtCC,EAA2B,GAAG,GAAG,EACjCC,EAAmD,CACvD,0BAA2BF,CAC7B,EACMG,EAAuC,CAC3C,qBAAsBF,EACtB,8BAA+B,GAAG,GAAG,CACvC,EACMG,EAAS,IAAIL,EACjBG,EACAC,CACF,EAEA,WAAW,IAAM,CACf,GAAG,cAAc,CACnB,CAAC,EAED,GAAG,qEAAsE,SAAY,CAEnF,MAAME,EAAc,CAAC,EAGfC,EAAS,MAAMF,EAAO,KAAKC,CAAW,EAG5C,OAAOC,CAAM,EAAE,QAAQ,CAAC,CAAC,CAC3B,CAAC,EAED,GAAG,oDAAqD,SAAY,CAElE,MAAMD,EAAc,CAAE,GAAI,OAAW,KAAM,IAAK,EAG1CC,EAAS,MAAMF,EAAO,KAAKC,CAAW,EAG5C,OAAOC,CAAM,EAAE,QAAQ,CAAC,CAAC,CAC3B,CAAC,EAED,GAAG,gDAAiD,SAAY,CAE9D,MAAMD,EAAc,CAClB,GAAI,MACJ,QAAS,EACT,KAAM,wEACR,EAGMC,EAAS,MAAMF,EAAO,KAAKC,CAAW,EAG5C,OAAOC,CAAM,EAAE,QAAQ,CACrB,CACE,KAAMR,EAAqB,MAC3B,MAAO,IAAI,MAAM,kBAAkB,CACrC,CACF,CAAC,CACH,CAAC,EAED,GAAG,8CAA+C,SAAY,CAE5DG,EAAyB,kBACvBL,EAAK,IAAI,MAAM,mBAAmB,CAAC,CACr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AS,UACX,CACF,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["Left", "Right", "ClearSignContextType", "TransactionContextLoader", "getTransactionDescriptorsMock", "getProxyDelegateCallMock", "mockTransactionDataSource", "mockProxyDatasource", "loader", "transaction", "result"]
4
+ "sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport type { ProxyDataSource } from \"@/proxy/data/HttpProxyDataSource\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport type { TransactionContext } from \"@/shared/model/TransactionContext\";\nimport type { TransactionDataSource } from \"@/transaction/data/TransactionDataSource\";\nimport { TransactionContextLoader } from \"@/transaction/domain/TransactionContextLoader\";\n\ndescribe(\"TransactionContextLoader\", () => {\n const getTransactionDescriptorsMock = vi.fn();\n const getProxyDelegateCallMock = vi.fn();\n const mockTransactionDataSource: TransactionDataSource = {\n getTransactionDescriptors: getTransactionDescriptorsMock,\n };\n const mockProxyDatasource: ProxyDataSource = {\n getProxyDelegateCall: getProxyDelegateCallMock,\n getProxyImplementationAddress: vi.fn(),\n };\n const loader = new TransactionContextLoader(\n mockTransactionDataSource,\n mockProxyDatasource,\n );\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n it(\"should return an empty array if no destination address is provided\", async () => {\n // GIVEN\n const transaction = {} as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if 'to' is undefined\", async () => {\n // GIVEN\n const transaction = { to: undefined, data: \"0x\" } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an error if selector is invalid\", async () => {\n // GIVEN\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xzf68b302000000000000000000000000000000000000000000000000000000000002\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Invalid selector\"),\n },\n ]);\n });\n\n it(\"should return an error if data source fails\", async () => {\n // GIVEN\n getProxyDelegateCallMock.mockResolvedValue(\n Left(new Error(\"data source error\")),\n );\n getTransactionDescriptorsMock.mockResolvedValue(\n Left(new Error(\"data source error\")),\n );\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(getTransactionDescriptorsMock).toHaveBeenCalledWith({\n address: \"0x7\",\n chainId: 3,\n selector: \"0xaf68b302\",\n });\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\n \"[ContextModule] TransactionContextLoader: Unable to fetch contexts from contract address 0x7\",\n ),\n },\n ]);\n });\n\n it(\"should return the contexts on success\", async () => {\n // GIVEN\n getTransactionDescriptorsMock.mockResolvedValue(\n Right([\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]),\n );\n getProxyDelegateCallMock.mockResolvedValue(\n Left(new Error(\"data source error\")),\n );\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]);\n });\n\n it(\"should return the proxy delegate call context on success\", async () => {\n // GIVEN\n getTransactionDescriptorsMock.mockResolvedValueOnce(Right([])); // No transaction descriptors found for the first call\n getTransactionDescriptorsMock.mockResolvedValue(\n Right([\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]),\n );\n getProxyDelegateCallMock.mockResolvedValue(\n Right({\n delegateAddresses: [\"0x7\"],\n signedDescriptor: \"0x1234567890abcdef\",\n }),\n );\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.PROXY_DELEGATE_CALL,\n payload: \"0x\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"deadbeef\",\n },\n ]);\n });\n\n it(\"should return an empty array if device model is NANO_S\", async () => {\n // GIVEN\n const transaction = {\n deviceModelId: DeviceModelId.NANO_S,\n to: \"0x7\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n expect(getTransactionDescriptorsMock).not.toHaveBeenCalled();\n expect(getProxyDelegateCallMock).not.toHaveBeenCalled();\n });\n\n it(\"should return an error when proxy delegate call succeeds but no delegate addresses are found\", async () => {\n // GIVEN\n getTransactionDescriptorsMock.mockResolvedValueOnce(Right([])); // No transaction descriptors found for the first call\n getProxyDelegateCallMock.mockResolvedValue(\n Right({\n delegateAddresses: [], // Empty delegate addresses array\n signedDescriptor: \"0x1234567890abcdef\",\n }),\n );\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\n \"[ContextModule] TransactionContextLoader: No delegate address found for proxy 0x7\",\n ),\n },\n ]);\n });\n\n it(\"should return an error when proxy delegate call succeeds but transaction descriptors for resolved address fail\", async () => {\n // GIVEN\n getTransactionDescriptorsMock.mockResolvedValueOnce(Right([])); // No transaction descriptors found for the first call\n getTransactionDescriptorsMock.mockResolvedValueOnce(\n Left(new Error(\"data source error\")),\n ); // Second call fails\n getProxyDelegateCallMock.mockResolvedValue(\n Right({\n delegateAddresses: [\"0xResolvedAddress\"],\n signedDescriptor: \"0x1234567890abcdef\",\n }),\n );\n const transaction = {\n to: \"0x7\",\n chainId: 3,\n data: \"0xaf68b302000000000000000000000000000000000000000000000000000000000002\",\n selector: \"0xaf68b302\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(getTransactionDescriptorsMock).toHaveBeenCalledTimes(2);\n expect(getTransactionDescriptorsMock).toHaveBeenNthCalledWith(2, {\n address: \"0xResolvedAddress\",\n chainId: 3,\n selector: \"0xaf68b302\",\n });\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\n \"[ContextModule] TransactionContextLoader: Unable to fetch contexts from contract address using proxy delegate call 0xResolvedAddress\",\n ),\n },\n ]);\n });\n});\n"],
5
+ "mappings": "AAAA,OAAS,iBAAAA,MAAqB,kCAC9B,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAG5B,OAAS,wBAAAC,MAA4B,kCAGrC,OAAS,4BAAAC,MAAgC,gDAEzC,SAAS,2BAA4B,IAAM,CACzC,MAAMC,EAAgC,GAAG,GAAG,EACtCC,EAA2B,GAAG,GAAG,EACjCC,EAAmD,CACvD,0BAA2BF,CAC7B,EACMG,EAAuC,CAC3C,qBAAsBF,EACtB,8BAA+B,GAAG,GAAG,CACvC,EACMG,EAAS,IAAIL,EACjBG,EACAC,CACF,EAEA,WAAW,IAAM,CACf,GAA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,EAAM,CAAC,CAAC,CAAC,EAC7DI,EAAyB,kBACvBJ,EAAM,CACJ,kBAAmB,CAAC,EACpB,iBAAkB,oBACpB,CAAC,CACH,EACA,MAAMQ,EAAc,CAClB,GAAI,MACJ,QAAS,EACT,KAAM,yEACN,SAAU,YACZ,EAGMC,EAAS,MAAMF,EAAO,KAAKC,CAAW,EAG5C,OAAOC,CAAM,EAAE,QAAQ,CACrB,CACE,KAAMR,EAAqB,MAC3B,MAAO,IAAI,MACT,mFACF,CACF,CACF,CAAC,CACH,CAAC,EAED,GAAG,iHAAkH,SAAY,CAE/HE,EAA8B,sBAAsBH,EAAM,CAAC,CAAC,CAAC,EAC7DG,EAA8B,sBAC5BJ,EAAK,IAAI,MAAM,mBAAmB,CAAC,CACrC,EACAK,EAAyB,kBACvBJ,EAAM,CACJ,kBAAmB,CAAC,mBAAmB,EACvC,iBAAkB,oBACpB,CAAC,CACH,EACA,MAAMQ,EAAc,CAClB,GAAI,MACJ,QAAS,EACT,KAAM,yEACN,SAAU,YACZ,EAGMC,EAAS,MAAMF,EAAO,KAAKC,CAAW,EAG5C,OAAOL,CAA6B,EAAE,sBAAsB,CAAC,EAC7D,OAAOA,CAA6B,EAAE,wBAAwB,EAAG,CAC/D,QAAS,oBACT,QAAS,EACT,SAAU,YACZ,CAAC,EACD,OAAOM,CAAM,EAAE,QAAQ,CACrB,CACE,KAAMR,EAAqB,MAC3B,MAAO,IAAI,MACT,sIACF,CACF,CACF,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["DeviceModelId", "Left", "Right", "ClearSignContextType", "TransactionContextLoader", "getTransactionDescriptorsMock", "getProxyDelegateCallMock", "mockTransactionDataSource", "mockProxyDatasource", "loader", "transaction", "result"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var _=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var m=(c,e,n,i)=>{for(var o=i>1?void 0:i?h(e,n):e,r=c.length-1,s;r>=0;r--)(s=c[r])&&(o=(i?s(e,n,o):s(o))||o);return i&&o&&_(e,n,o),o},g=(c,e)=>(n,i)=>e(n,i,c);import C from"axios";import I from"crypto-js/sha224";import{inject as F,injectable as x}from"inversify";import{Left as p,Right as M}from"purify-ts";import{configTypes as D}from"../../config/di/configTypes";import{LEDGER_CLIENT_VERSION_HEADER as T,LEDGER_ORIGIN_TOKEN_HEADER as b}from"../../shared/constant/HttpHeaders";import{TypedDataCalldataParamPresence as u}from"../../shared/model/TypedDataClearSignContext";import v from"../../../package.json";let d=class{constructor(e){this.config=e}async getTypedDataFilters({chainId:e,address:n,schema:i,version:o}){let r;try{const s=await C.request({method:"GET",url:`${this.config.cal.url}/dapps`,params:{contracts:n,chain_id:e,output:"descriptors_eip712",descriptors_eip712_version:o,descriptors_eip712:"<set>",ref:"commit:ff75b9427f79c04c09d0b4378d6e01e2e6113e28"},headers:{[T]:`context-module/${v.version}`,[b]:this.config.originToken}}),a=I(JSON.stringify(this.sortTypes(i)).replace(" ","")).toString();n=n.toLowerCase();const f=s.data?.[0]?.descriptors_eip712?.[n]?.[a];if(!f)return p(new Error(`[ContextModule] HttpTypedDataDataSource: no typed data filters for address ${n} on chain ${e} for schema ${a}`));if(!f.schema||!Array.isArray(f.instructions))return p(new Error(`[ContextModule] HttpTypedDataDataSource: no message info for address ${n} on chain ${e} for schema ${a}`));const l=[],y={};for(const t of f.instructions)if(this.isInstructionContractInfo(t,this.config.cal.mode))r={displayName:t.display_name,signature:t.signatures[this.config.cal.mode],filtersCount:t.field_mappers_count};else if(o==="v1"&&this.isInstructionFieldV1(t,this.config.cal.mode))l.push({type:"raw",displayName:t.display_name,path:t.field_path,signature:t.signatures[this.config.cal.mode]});else if(this.isInstructionFieldV2(t,this.config.cal.mode))l.push({type:t.format,displayName:t.display_name,path:t.field_path,signature:t.signatures[this.config.cal.mode]});else if(this.isInstructionFieldV2WithCoinRef(t,this.config.cal.mode))l.push({type:t.format,displayName:t.display_name,path:t.field_path,signature:t.signatures[this.config.cal.mode],tokenIndex:t.coin_ref});else if(this.isInstructionFieldV2WithName(t,this.config.cal.mode))l.push({type:t.format,displayName:t.display_name,path:t.field_path,signature:t.signatures[this.config.cal.mode],types:t.name_types,sources:t.name_sources,typesAndSourcesPayload:this.formatTrustedNameTypesAndSources(t)});else if(this.isInstructionCalldataInfo(t,this.config.cal.mode))y[t.calldata_index]={displayName:t.display_name,calldataIndex:t.calldata_index,valueFlag:t.value_filter_flag,calleeFlag:this.convertCalldataPresenceFlag(t.callee_filter_flag),amountFlag:t.amount_filter_flag,spenderFlag:this.convertCalldataPresenceFlag(t.spender_filter_flag),chainIdFlag:t.chain_id_filter_flag,selectorFlag:t.selector_filter_flag,signature:t.signatures[this.config.cal.mode]};else if(this.isInstructionFieldV2Calldata(t,this.config.cal.mode))l.push({type:t.format,displayName:t.display_name,path:t.field_path,signature:t.signatures[this.config.cal.mode],calldataIndex:t.calldata_index});else return p(new Error(`[ContextModule] HttpTypedDataDataSource: invalid typed data field for address ${n} on chain ${e} for schema ${a}`));return r?M({messageInfo:r,filters:l,calldatasInfos:y}):p(new Error(`[ContextModule] HttpTypedDataDataSource: no message info for address ${n} on chain ${e} for schema ${a}`))}catch{return p(new Error("[ContextModule] HttpTypedDataDataSource: Failed to fetch typed data informations"))}}convertCalldataPresenceFlag(e){switch(e){case"none":return u.None;case"present":return u.Present;case"verifying_contract":return u.VerifyingContract;default:{const n=e;throw new Error(`Unhandled flag: ${n}`)}}}formatTrustedNameTypesAndSources(e){const n=e.name_types.length,i=e.name_sources.length,o=e.descriptor.slice((n+i)*2*-1,i*2*-1),r=e.descriptor.slice(i*2*-1),s=n.toString(16).padStart(2,"0"),a=i.toString(16).padStart(2,"0");return s+o+a+r}isInstructionFieldV1(e,n){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_path=="string"&&typeof e.signatures=="object"&&typeof e.signatures[n]=="string"}isInstructionFieldV2(e,n){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_path=="string"&&typeof e.signatures=="object"&&typeof e.signatures[n]=="string"&&typeof e.format=="string"&&["raw","datetime"].includes(e.format)&&e.coin_ref===void 0}isInstructionFieldV2WithCoinRef(e,n){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_path=="string"&&typeof e.signatures=="object"&&typeof e.signatures[n]=="string"&&typeof e.format=="string"&&["token","amount"].includes(e.format)&&typeof e.coin_ref=="number"}isInstructionFieldV2WithName(e,n){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_path=="string"&&typeof e.signatures=="object"&&typeof e.signatures[n]=="string"&&typeof e.format=="string"&&e.format==="trusted-name"&&e.coin_ref===void 0&&Array.isArray(e.name_types)&&Array.isArray(e.name_sources)&&e.name_types.every(i=>typeof i=="string")&&e.name_sources.every(i=>typeof i=="string")}isInstructionContractInfo(e,n){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_mappers_count=="number"&&typeof e.signatures=="object"&&typeof e.signatures[n]=="string"&&e.field_path===void 0}isInstructionCalldataInfo(e,n){return typeof e=="object"&&typeof e.type=="string"&&e.type==="calldata"&&typeof e.display_name=="string"&&typeof e.calldata_index=="number"&&typeof e.value_filter_flag=="boolean"&&typeof e.chain_id_filter_flag=="boolean"&&typeof e.selector_filter_flag=="boolean"&&typeof e.amount_filter_flag=="boolean"&&["none","present","verifying_contract"].includes(e.callee_filter_flag)&&["none","present","verifying_contract"].includes(e.spender_filter_flag)&&typeof e.signatures=="object"&&typeof e.signatures[n]=="string"}isInstructionFieldV2Calldata(e,n){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_path=="string"&&typeof e.signatures=="object"&&typeof e.signatures[n]=="string"&&typeof e.format=="string"&&["calldata-value","calldata-callee","calldata-chain-id","calldata-selector","calldata-amount","calldata-spender"].includes(e.format)&&typeof e.calldata_index=="number"}sortTypes(e){return Object.fromEntries(Object.entries(e).sort(([n],[i])=>n.localeCompare(i)).map(([n,i])=>[n,i.map(o=>({name:o.name,type:o.type}))]))}};d=m([x(),g(0,F(D.Config))],d);export{d as HttpTypedDataDataSource};
1
+ var _=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var m=(c,e,n,i)=>{for(var o=i>1?void 0:i?h(e,n):e,r=c.length-1,s;r>=0;r--)(s=c[r])&&(o=(i?s(e,n,o):s(o))||o);return i&&o&&_(e,n,o),o},g=(c,e)=>(n,i)=>e(n,i,c);import C from"axios";import I from"crypto-js/sha224";import{inject as F,injectable as x}from"inversify";import{Left as p,Right as M}from"purify-ts";import{configTypes as D}from"../../config/di/configTypes";import{LEDGER_CLIENT_VERSION_HEADER as T,LEDGER_ORIGIN_TOKEN_HEADER as b}from"../../shared/constant/HttpHeaders";import{TypedDataCalldataParamPresence as u}from"../../shared/model/TypedDataClearSignContext";import v from"../../../package.json";let d=class{constructor(e){this.config=e}async getTypedDataFilters({chainId:e,address:n,schema:i,version:o}){let r;try{const s=await C.request({method:"GET",url:`${this.config.cal.url}/dapps`,params:{contracts:n,chain_id:e,output:"descriptors_eip712",descriptors_eip712_version:o,descriptors_eip712:"<set>",ref:`branch:${this.config.cal.branch}`},headers:{[T]:`context-module/${v.version}`,[b]:this.config.originToken}}),a=I(JSON.stringify(this.sortTypes(i)).replace(" ","")).toString();n=n.toLowerCase();const f=s.data?.[0]?.descriptors_eip712?.[n]?.[a];if(!f)return p(new Error(`[ContextModule] HttpTypedDataDataSource: no typed data filters for address ${n} on chain ${e} for schema ${a}`));if(!f.schema||!Array.isArray(f.instructions))return p(new Error(`[ContextModule] HttpTypedDataDataSource: no message info for address ${n} on chain ${e} for schema ${a}`));const l=[],y={};for(const t of f.instructions)if(this.isInstructionContractInfo(t,this.config.cal.mode))r={displayName:t.display_name,signature:t.signatures[this.config.cal.mode],filtersCount:t.field_mappers_count};else if(o==="v1"&&this.isInstructionFieldV1(t,this.config.cal.mode))l.push({type:"raw",displayName:t.display_name,path:t.field_path,signature:t.signatures[this.config.cal.mode]});else if(this.isInstructionFieldV2(t,this.config.cal.mode))l.push({type:t.format,displayName:t.display_name,path:t.field_path,signature:t.signatures[this.config.cal.mode]});else if(this.isInstructionFieldV2WithCoinRef(t,this.config.cal.mode))l.push({type:t.format,displayName:t.display_name,path:t.field_path,signature:t.signatures[this.config.cal.mode],tokenIndex:t.coin_ref});else if(this.isInstructionFieldV2WithName(t,this.config.cal.mode))l.push({type:t.format,displayName:t.display_name,path:t.field_path,signature:t.signatures[this.config.cal.mode],types:t.name_types,sources:t.name_sources,typesAndSourcesPayload:this.formatTrustedNameTypesAndSources(t)});else if(this.isInstructionCalldataInfo(t,this.config.cal.mode))y[t.calldata_index]={displayName:t.display_name,calldataIndex:t.calldata_index,valueFlag:t.value_filter_flag,calleeFlag:this.convertCalldataPresenceFlag(t.callee_filter_flag),amountFlag:t.amount_filter_flag,spenderFlag:this.convertCalldataPresenceFlag(t.spender_filter_flag),chainIdFlag:t.chain_id_filter_flag,selectorFlag:t.selector_filter_flag,signature:t.signatures[this.config.cal.mode]};else if(this.isInstructionFieldV2Calldata(t,this.config.cal.mode))l.push({type:t.format,displayName:t.display_name,path:t.field_path,signature:t.signatures[this.config.cal.mode],calldataIndex:t.calldata_index});else return p(new Error(`[ContextModule] HttpTypedDataDataSource: invalid typed data field for address ${n} on chain ${e} for schema ${a}`));return r?M({messageInfo:r,filters:l,calldatasInfos:y}):p(new Error(`[ContextModule] HttpTypedDataDataSource: no message info for address ${n} on chain ${e} for schema ${a}`))}catch{return p(new Error("[ContextModule] HttpTypedDataDataSource: Failed to fetch typed data informations"))}}convertCalldataPresenceFlag(e){switch(e){case"none":return u.None;case"present":return u.Present;case"verifying_contract":return u.VerifyingContract;default:{const n=e;throw new Error(`Unhandled flag: ${n}`)}}}formatTrustedNameTypesAndSources(e){const n=e.name_types.length,i=e.name_sources.length,o=e.descriptor.slice((n+i)*2*-1,i*2*-1),r=e.descriptor.slice(i*2*-1),s=n.toString(16).padStart(2,"0"),a=i.toString(16).padStart(2,"0");return s+o+a+r}isInstructionFieldV1(e,n){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_path=="string"&&typeof e.signatures=="object"&&typeof e.signatures[n]=="string"}isInstructionFieldV2(e,n){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_path=="string"&&typeof e.signatures=="object"&&typeof e.signatures[n]=="string"&&typeof e.format=="string"&&["raw","datetime"].includes(e.format)&&e.coin_ref===void 0}isInstructionFieldV2WithCoinRef(e,n){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_path=="string"&&typeof e.signatures=="object"&&typeof e.signatures[n]=="string"&&typeof e.format=="string"&&["token","amount"].includes(e.format)&&typeof e.coin_ref=="number"}isInstructionFieldV2WithName(e,n){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_path=="string"&&typeof e.signatures=="object"&&typeof e.signatures[n]=="string"&&typeof e.format=="string"&&e.format==="trusted-name"&&e.coin_ref===void 0&&Array.isArray(e.name_types)&&Array.isArray(e.name_sources)&&e.name_types.every(i=>typeof i=="string")&&e.name_sources.every(i=>typeof i=="string")}isInstructionContractInfo(e,n){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_mappers_count=="number"&&typeof e.signatures=="object"&&typeof e.signatures[n]=="string"&&e.field_path===void 0}isInstructionCalldataInfo(e,n){return typeof e=="object"&&typeof e.type=="string"&&e.type==="calldata"&&typeof e.display_name=="string"&&typeof e.calldata_index=="number"&&typeof e.value_filter_flag=="boolean"&&typeof e.chain_id_filter_flag=="boolean"&&typeof e.selector_filter_flag=="boolean"&&typeof e.amount_filter_flag=="boolean"&&["none","present","verifying_contract"].includes(e.callee_filter_flag)&&["none","present","verifying_contract"].includes(e.spender_filter_flag)&&typeof e.signatures=="object"&&typeof e.signatures[n]=="string"}isInstructionFieldV2Calldata(e,n){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_path=="string"&&typeof e.signatures=="object"&&typeof e.signatures[n]=="string"&&typeof e.format=="string"&&["calldata-value","calldata-callee","calldata-chain-id","calldata-selector","calldata-amount","calldata-spender"].includes(e.format)&&typeof e.calldata_index=="number"}sortTypes(e){return Object.fromEntries(Object.entries(e).sort(([n],[i])=>n.localeCompare(i)).map(([n,i])=>[n,i.map(o=>({name:o.name,type:o.type}))]))}};d=m([x(),g(0,F(D.Config))],d);export{d as HttpTypedDataDataSource};
2
2
  //# sourceMappingURL=HttpTypedDataDataSource.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/typed-data/data/HttpTypedDataDataSource.ts"],
4
- "sourcesContent": ["import axios from \"axios\";\nimport SHA224 from \"crypto-js/sha224\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport type {\n ContextModuleCalMode,\n ContextModuleConfig,\n} from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport type {\n TypedDataCalldataIndex,\n TypedDataFilter,\n TypedDataFilterCalldataInfo,\n TypedDataMessageInfo,\n} from \"@/shared/model/TypedDataClearSignContext\";\nimport { TypedDataCalldataParamPresence } from \"@/shared/model/TypedDataClearSignContext\";\nimport type { TypedDataSchema } from \"@/shared/model/TypedDataContext\";\nimport PACKAGE from \"@root/package.json\";\n\nimport type {\n FiltersDto,\n InstructionCalldataInfo,\n InstructionCalldataParamPresence,\n InstructionContractInfo,\n InstructionField,\n InstructionFieldV1,\n InstructionFieldV2,\n InstructionFieldV2Calldata,\n InstructionFieldV2WithCoinRef,\n InstructionFieldV2WithName,\n} from \"./FiltersDto\";\nimport {\n GetTypedDataFiltersParams,\n GetTypedDataFiltersResult,\n TypedDataDataSource,\n} from \"./TypedDataDataSource\";\n\n@injectable()\nexport class HttpTypedDataDataSource implements TypedDataDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n ) {}\n\n public async getTypedDataFilters({\n chainId,\n address,\n schema,\n version,\n }: GetTypedDataFiltersParams): Promise<\n Either<Error, GetTypedDataFiltersResult>\n > {\n let messageInfo: TypedDataMessageInfo | undefined = undefined;\n\n try {\n const response = await axios.request<FiltersDto[]>({\n method: \"GET\",\n url: `${this.config.cal.url}/dapps`,\n params: {\n contracts: address,\n chain_id: chainId,\n output: \"descriptors_eip712\",\n descriptors_eip712_version: version,\n descriptors_eip712: \"<set>\",\n // TODO revert to branch\n ref: `commit:ff75b9427f79c04c09d0b4378d6e01e2e6113e28`,\n },\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n\n // Try to get the filters JSON descriptor, from address and schema hash\n const schemaHash = SHA224(\n JSON.stringify(this.sortTypes(schema)).replace(\" \", \"\"),\n ).toString();\n address = address.toLowerCase();\n const filtersJson =\n response.data?.[0]?.descriptors_eip712?.[address]?.[schemaHash];\n if (!filtersJson) {\n return Left(\n new Error(\n `[ContextModule] HttpTypedDataDataSource: no typed data filters for address ${address} on chain ${chainId} for schema ${schemaHash}`,\n ),\n );\n }\n\n // Parse the message type, if available\n if (!filtersJson.schema || !Array.isArray(filtersJson.instructions)) {\n return Left(\n new Error(\n `[ContextModule] HttpTypedDataDataSource: no message info for address ${address} on chain ${chainId} for schema ${schemaHash}`,\n ),\n );\n }\n\n // Parse all the filters\n const filters: TypedDataFilter[] = [];\n const calldatasInfos: Record<\n TypedDataCalldataIndex,\n TypedDataFilterCalldataInfo\n > = {};\n for (const field of filtersJson.instructions) {\n if (this.isInstructionContractInfo(field, this.config.cal.mode)) {\n messageInfo = {\n displayName: field.display_name,\n signature: field.signatures[this.config.cal.mode],\n filtersCount: field.field_mappers_count,\n };\n } else if (\n version === \"v1\" &&\n this.isInstructionFieldV1(field, this.config.cal.mode)\n ) {\n filters.push({\n type: \"raw\",\n displayName: field.display_name,\n path: field.field_path,\n signature: field.signatures[this.config.cal.mode],\n });\n } else if (this.isInstructionFieldV2(field, this.config.cal.mode)) {\n filters.push({\n type: field.format,\n displayName: field.display_name,\n path: field.field_path,\n signature: field.signatures[this.config.cal.mode],\n });\n } else if (\n this.isInstructionFieldV2WithCoinRef(field, this.config.cal.mode)\n ) {\n filters.push({\n type: field.format,\n displayName: field.display_name,\n path: field.field_path,\n signature: field.signatures[this.config.cal.mode],\n tokenIndex: field.coin_ref,\n });\n } else if (\n this.isInstructionFieldV2WithName(field, this.config.cal.mode)\n ) {\n filters.push({\n type: field.format,\n displayName: field.display_name,\n path: field.field_path,\n signature: field.signatures[this.config.cal.mode],\n types: field.name_types,\n sources: field.name_sources,\n typesAndSourcesPayload:\n this.formatTrustedNameTypesAndSources(field),\n });\n } else if (\n this.isInstructionCalldataInfo(field, this.config.cal.mode)\n ) {\n calldatasInfos[field.calldata_index] = {\n displayName: field.display_name,\n calldataIndex: field.calldata_index,\n valueFlag: field.value_filter_flag,\n calleeFlag: this.convertCalldataPresenceFlag(\n field.callee_filter_flag,\n ),\n amountFlag: field.amount_filter_flag,\n spenderFlag: this.convertCalldataPresenceFlag(\n field.spender_filter_flag,\n ),\n chainIdFlag: field.chain_id_filter_flag,\n selectorFlag: field.selector_filter_flag,\n signature: field.signatures[this.config.cal.mode],\n };\n } else if (\n this.isInstructionFieldV2Calldata(field, this.config.cal.mode)\n ) {\n filters.push({\n type: field.format,\n displayName: field.display_name,\n path: field.field_path,\n signature: field.signatures[this.config.cal.mode],\n calldataIndex: field.calldata_index,\n });\n } else {\n return Left(\n new Error(\n `[ContextModule] HttpTypedDataDataSource: invalid typed data field for address ${address} on chain ${chainId} for schema ${schemaHash}`,\n ),\n );\n }\n }\n\n if (!messageInfo) {\n return Left(\n new Error(\n `[ContextModule] HttpTypedDataDataSource: no message info for address ${address} on chain ${chainId} for schema ${schemaHash}`,\n ),\n );\n }\n\n return Right({ messageInfo, filters, calldatasInfos });\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] HttpTypedDataDataSource: Failed to fetch typed data informations\",\n ),\n );\n }\n }\n\n private convertCalldataPresenceFlag(\n flag: InstructionCalldataParamPresence,\n ): TypedDataCalldataParamPresence {\n switch (flag) {\n case \"none\":\n return TypedDataCalldataParamPresence.None;\n case \"present\":\n return TypedDataCalldataParamPresence.Present;\n case \"verifying_contract\":\n return TypedDataCalldataParamPresence.VerifyingContract;\n default: {\n const uncoveredFlag: never = flag;\n throw new Error(`Unhandled flag: ${uncoveredFlag}`);\n }\n }\n }\n\n private formatTrustedNameTypesAndSources(\n field: InstructionFieldV2WithName,\n ): string {\n // Get number of types and sources\n const typesCount = field.name_types.length;\n const sourcesCount = field.name_sources.length;\n\n // Extract types and sources from the descriptor\n const types = field.descriptor.slice(\n (typesCount + sourcesCount) * 2 * -1,\n sourcesCount * 2 * -1,\n );\n const sources = field.descriptor.slice(sourcesCount * 2 * -1);\n\n // Convert counts into hex strings\n const typesCountHex = typesCount.toString(16).padStart(2, \"0\");\n const sourcesCountHex = sourcesCount.toString(16).padStart(2, \"0\");\n\n // Return the payload\n return typesCountHex + types + sourcesCountHex + sources;\n }\n\n private isInstructionFieldV1(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionFieldV1 & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n // NOTE: Currently the backend return the same structure for V1 and V2,\n // so we can't distinguish them here, but we can still check the required fields\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_path === \"string\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\"\n );\n }\n\n private isInstructionFieldV2(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionFieldV2 & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_path === \"string\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\" &&\n typeof data.format === \"string\" &&\n [\"raw\", \"datetime\"].includes(data.format) &&\n data.coin_ref === undefined\n );\n }\n\n private isInstructionFieldV2WithCoinRef(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionFieldV2WithCoinRef & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_path === \"string\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\" &&\n typeof data.format === \"string\" &&\n [\"token\", \"amount\"].includes(data.format) &&\n typeof data.coin_ref === \"number\"\n );\n }\n\n private isInstructionFieldV2WithName(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionFieldV2WithName & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_path === \"string\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\" &&\n typeof data.format === \"string\" &&\n data.format === \"trusted-name\" &&\n data.coin_ref === undefined &&\n Array.isArray(data.name_types) &&\n Array.isArray(data.name_sources) &&\n data.name_types.every((t) => typeof t === \"string\") &&\n data.name_sources.every((s) => typeof s === \"string\")\n );\n }\n\n private isInstructionContractInfo(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionContractInfo & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_mappers_count === \"number\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\" &&\n data.field_path === undefined\n );\n }\n\n private isInstructionCalldataInfo(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionCalldataInfo & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.type === \"string\" &&\n data.type === \"calldata\" &&\n typeof data.display_name === \"string\" &&\n typeof data.calldata_index === \"number\" &&\n typeof data.value_filter_flag === \"boolean\" &&\n typeof data.chain_id_filter_flag === \"boolean\" &&\n typeof data.selector_filter_flag === \"boolean\" &&\n typeof data.amount_filter_flag === \"boolean\" &&\n [\"none\", \"present\", \"verifying_contract\"].includes(\n data.callee_filter_flag,\n ) &&\n [\"none\", \"present\", \"verifying_contract\"].includes(\n data.spender_filter_flag,\n ) &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\"\n );\n }\n\n private isInstructionFieldV2Calldata(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionFieldV2Calldata & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_path === \"string\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\" &&\n typeof data.format === \"string\" &&\n [\n \"calldata-value\",\n \"calldata-callee\",\n \"calldata-chain-id\",\n \"calldata-selector\",\n \"calldata-amount\",\n \"calldata-spender\",\n ].includes(data.format) &&\n typeof data.calldata_index === \"number\"\n );\n }\n\n private sortTypes(types: TypedDataSchema): TypedDataSchema {\n return Object.fromEntries(\n Object.entries(types)\n .sort(([aKey], [bKey]) => aKey.localeCompare(bKey))\n .map(([key, value]) => [\n key,\n value.map((v) => ({ name: v.name, type: v.type })),\n ]),\n );\n }\n}\n"],
5
- "mappings": "iOAAA,OAAOA,MAAW,QAClB,OAAOC,MAAY,mBACnB,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YACnC,OAAiB,QAAAC,EAAM,SAAAC,MAAa,YAEpC,OAAS,eAAAC,MAAmB,0BAK5B,OACE,gCAAAC,EACA,8BAAAC,MACK,gCAOP,OAAS,kCAAAC,MAAsC,2CAE/C,OAAOC,MAAa,qBAqBb,IAAMC,EAAN,KAA6D,CAClE,YAC+CC,EAC7C,CAD6C,YAAAA,CAC5C,CAEH,MAAa,oBAAoB,CAC/B,QAAAC,EACA,QAAAC,EACA,OAAAC,EACA,QAAAC,CACF,EAEE,CACA,IAAIC,EAEJ,GAAI,CACF,MAAMC,EAAW,MAAMC,EAAM,QAAsB,CACjD,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B,EAAE,SACxCA,EAAK,mBACP,GACA,OAAOA,EAAK,YAAe,UAC3B,OAAOA,EAAK,WAAWC,CAAI,GAAM,QAErC,CAEQ,6BACND,EACAC,EAGA,CACA,OACE,OAAOD,GAAS,UAChB,OAAOA,EAAK,cAAiB,UAC7B,OAAOA,EAAK,YAAe,UAC3B,OAAOA,EAAK,YAAe,UAC3B,OAAOA,EAAK,WAAWC,CAAI,GAAM,UACjC,OAAOD,EAAK,QAAW,UACvB,CACE,iBACA,kBACA,oBACA,oBACA,kBACA,kBACF,EAAE,SAASA,EAAK,MAAM,GACtB,OAAOA,EAAK,gBAAmB,QAEnC,CAEQ,UAAUJ,EAAyC,CACzD,OAAO,OAAO,YACZ,OAAO,QAAQA,CAAK,EACjB,KAAK,CAAC,CAACQ,CAAI,EAAG,CAACC,CAAI,IAAMD,EAAK,cAAcC,CAAI,CAAC,EACjD,IAAI,CAAC,CAACC,EAAKC,CAAK,IAAM,CACrBD,EACAC,EAAM,IAAKC,IAAO,CAAE,KAAMA,EAAE,KAAM,KAAMA,EAAE,IAAK,EAAE,CACnD,CAAC,CACL,CACF,CACF,EAtWarC,EAANsC,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAY,MAAM,IAFjB1C",
4
+ "sourcesContent": ["import axios from \"axios\";\nimport SHA224 from \"crypto-js/sha224\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport type {\n ContextModuleCalMode,\n ContextModuleConfig,\n} from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport type {\n TypedDataCalldataIndex,\n TypedDataFilter,\n TypedDataFilterCalldataInfo,\n TypedDataMessageInfo,\n} from \"@/shared/model/TypedDataClearSignContext\";\nimport { TypedDataCalldataParamPresence } from \"@/shared/model/TypedDataClearSignContext\";\nimport type { TypedDataSchema } from \"@/shared/model/TypedDataContext\";\nimport PACKAGE from \"@root/package.json\";\n\nimport type {\n FiltersDto,\n InstructionCalldataInfo,\n InstructionCalldataParamPresence,\n InstructionContractInfo,\n InstructionField,\n InstructionFieldV1,\n InstructionFieldV2,\n InstructionFieldV2Calldata,\n InstructionFieldV2WithCoinRef,\n InstructionFieldV2WithName,\n} from \"./FiltersDto\";\nimport {\n GetTypedDataFiltersParams,\n GetTypedDataFiltersResult,\n TypedDataDataSource,\n} from \"./TypedDataDataSource\";\n\n@injectable()\nexport class HttpTypedDataDataSource implements TypedDataDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n ) {}\n\n public async getTypedDataFilters({\n chainId,\n address,\n schema,\n version,\n }: GetTypedDataFiltersParams): Promise<\n Either<Error, GetTypedDataFiltersResult>\n > {\n let messageInfo: TypedDataMessageInfo | undefined = undefined;\n\n try {\n const response = await axios.request<FiltersDto[]>({\n method: \"GET\",\n url: `${this.config.cal.url}/dapps`,\n params: {\n contracts: address,\n chain_id: chainId,\n output: \"descriptors_eip712\",\n descriptors_eip712_version: version,\n descriptors_eip712: \"<set>\",\n ref: `branch:${this.config.cal.branch}`,\n },\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n\n // Try to get the filters JSON descriptor, from address and schema hash\n const schemaHash = SHA224(\n JSON.stringify(this.sortTypes(schema)).replace(\" \", \"\"),\n ).toString();\n address = address.toLowerCase();\n const filtersJson =\n response.data?.[0]?.descriptors_eip712?.[address]?.[schemaHash];\n if (!filtersJson) {\n return Left(\n new Error(\n `[ContextModule] HttpTypedDataDataSource: no typed data filters for address ${address} on chain ${chainId} for schema ${schemaHash}`,\n ),\n );\n }\n\n // Parse the message type, if available\n if (!filtersJson.schema || !Array.isArray(filtersJson.instructions)) {\n return Left(\n new Error(\n `[ContextModule] HttpTypedDataDataSource: no message info for address ${address} on chain ${chainId} for schema ${schemaHash}`,\n ),\n );\n }\n\n // Parse all the filters\n const filters: TypedDataFilter[] = [];\n const calldatasInfos: Record<\n TypedDataCalldataIndex,\n TypedDataFilterCalldataInfo\n > = {};\n for (const field of filtersJson.instructions) {\n if (this.isInstructionContractInfo(field, this.config.cal.mode)) {\n messageInfo = {\n displayName: field.display_name,\n signature: field.signatures[this.config.cal.mode],\n filtersCount: field.field_mappers_count,\n };\n } else if (\n version === \"v1\" &&\n this.isInstructionFieldV1(field, this.config.cal.mode)\n ) {\n filters.push({\n type: \"raw\",\n displayName: field.display_name,\n path: field.field_path,\n signature: field.signatures[this.config.cal.mode],\n });\n } else if (this.isInstructionFieldV2(field, this.config.cal.mode)) {\n filters.push({\n type: field.format,\n displayName: field.display_name,\n path: field.field_path,\n signature: field.signatures[this.config.cal.mode],\n });\n } else if (\n this.isInstructionFieldV2WithCoinRef(field, this.config.cal.mode)\n ) {\n filters.push({\n type: field.format,\n displayName: field.display_name,\n path: field.field_path,\n signature: field.signatures[this.config.cal.mode],\n tokenIndex: field.coin_ref,\n });\n } else if (\n this.isInstructionFieldV2WithName(field, this.config.cal.mode)\n ) {\n filters.push({\n type: field.format,\n displayName: field.display_name,\n path: field.field_path,\n signature: field.signatures[this.config.cal.mode],\n types: field.name_types,\n sources: field.name_sources,\n typesAndSourcesPayload:\n this.formatTrustedNameTypesAndSources(field),\n });\n } else if (\n this.isInstructionCalldataInfo(field, this.config.cal.mode)\n ) {\n calldatasInfos[field.calldata_index] = {\n displayName: field.display_name,\n calldataIndex: field.calldata_index,\n valueFlag: field.value_filter_flag,\n calleeFlag: this.convertCalldataPresenceFlag(\n field.callee_filter_flag,\n ),\n amountFlag: field.amount_filter_flag,\n spenderFlag: this.convertCalldataPresenceFlag(\n field.spender_filter_flag,\n ),\n chainIdFlag: field.chain_id_filter_flag,\n selectorFlag: field.selector_filter_flag,\n signature: field.signatures[this.config.cal.mode],\n };\n } else if (\n this.isInstructionFieldV2Calldata(field, this.config.cal.mode)\n ) {\n filters.push({\n type: field.format,\n displayName: field.display_name,\n path: field.field_path,\n signature: field.signatures[this.config.cal.mode],\n calldataIndex: field.calldata_index,\n });\n } else {\n return Left(\n new Error(\n `[ContextModule] HttpTypedDataDataSource: invalid typed data field for address ${address} on chain ${chainId} for schema ${schemaHash}`,\n ),\n );\n }\n }\n\n if (!messageInfo) {\n return Left(\n new Error(\n `[ContextModule] HttpTypedDataDataSource: no message info for address ${address} on chain ${chainId} for schema ${schemaHash}`,\n ),\n );\n }\n\n return Right({ messageInfo, filters, calldatasInfos });\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] HttpTypedDataDataSource: Failed to fetch typed data informations\",\n ),\n );\n }\n }\n\n private convertCalldataPresenceFlag(\n flag: InstructionCalldataParamPresence,\n ): TypedDataCalldataParamPresence {\n switch (flag) {\n case \"none\":\n return TypedDataCalldataParamPresence.None;\n case \"present\":\n return TypedDataCalldataParamPresence.Present;\n case \"verifying_contract\":\n return TypedDataCalldataParamPresence.VerifyingContract;\n default: {\n const uncoveredFlag: never = flag;\n throw new Error(`Unhandled flag: ${uncoveredFlag}`);\n }\n }\n }\n\n private formatTrustedNameTypesAndSources(\n field: InstructionFieldV2WithName,\n ): string {\n // Get number of types and sources\n const typesCount = field.name_types.length;\n const sourcesCount = field.name_sources.length;\n\n // Extract types and sources from the descriptor\n const types = field.descriptor.slice(\n (typesCount + sourcesCount) * 2 * -1,\n sourcesCount * 2 * -1,\n );\n const sources = field.descriptor.slice(sourcesCount * 2 * -1);\n\n // Convert counts into hex strings\n const typesCountHex = typesCount.toString(16).padStart(2, \"0\");\n const sourcesCountHex = sourcesCount.toString(16).padStart(2, \"0\");\n\n // Return the payload\n return typesCountHex + types + sourcesCountHex + sources;\n }\n\n private isInstructionFieldV1(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionFieldV1 & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n // NOTE: Currently the backend return the same structure for V1 and V2,\n // so we can't distinguish them here, but we can still check the required fields\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_path === \"string\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\"\n );\n }\n\n private isInstructionFieldV2(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionFieldV2 & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_path === \"string\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\" &&\n typeof data.format === \"string\" &&\n [\"raw\", \"datetime\"].includes(data.format) &&\n data.coin_ref === undefined\n );\n }\n\n private isInstructionFieldV2WithCoinRef(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionFieldV2WithCoinRef & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_path === \"string\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\" &&\n typeof data.format === \"string\" &&\n [\"token\", \"amount\"].includes(data.format) &&\n typeof data.coin_ref === \"number\"\n );\n }\n\n private isInstructionFieldV2WithName(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionFieldV2WithName & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_path === \"string\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\" &&\n typeof data.format === \"string\" &&\n data.format === \"trusted-name\" &&\n data.coin_ref === undefined &&\n Array.isArray(data.name_types) &&\n Array.isArray(data.name_sources) &&\n data.name_types.every((t) => typeof t === \"string\") &&\n data.name_sources.every((s) => typeof s === \"string\")\n );\n }\n\n private isInstructionContractInfo(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionContractInfo & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_mappers_count === \"number\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\" &&\n data.field_path === undefined\n );\n }\n\n private isInstructionCalldataInfo(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionCalldataInfo & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.type === \"string\" &&\n data.type === \"calldata\" &&\n typeof data.display_name === \"string\" &&\n typeof data.calldata_index === \"number\" &&\n typeof data.value_filter_flag === \"boolean\" &&\n typeof data.chain_id_filter_flag === \"boolean\" &&\n typeof data.selector_filter_flag === \"boolean\" &&\n typeof data.amount_filter_flag === \"boolean\" &&\n [\"none\", \"present\", \"verifying_contract\"].includes(\n data.callee_filter_flag,\n ) &&\n [\"none\", \"present\", \"verifying_contract\"].includes(\n data.spender_filter_flag,\n ) &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\"\n );\n }\n\n private isInstructionFieldV2Calldata(\n data: InstructionField,\n mode: ContextModuleCalMode,\n ): data is InstructionFieldV2Calldata & {\n signatures: { [_key in ContextModuleCalMode]: string };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.display_name === \"string\" &&\n typeof data.field_path === \"string\" &&\n typeof data.signatures === \"object\" &&\n typeof data.signatures[mode] === \"string\" &&\n typeof data.format === \"string\" &&\n [\n \"calldata-value\",\n \"calldata-callee\",\n \"calldata-chain-id\",\n \"calldata-selector\",\n \"calldata-amount\",\n \"calldata-spender\",\n ].includes(data.format) &&\n typeof data.calldata_index === \"number\"\n );\n }\n\n private sortTypes(types: TypedDataSchema): TypedDataSchema {\n return Object.fromEntries(\n Object.entries(types)\n .sort(([aKey], [bKey]) => aKey.localeCompare(bKey))\n .map(([key, value]) => [\n key,\n value.map((v) => ({ name: v.name, type: v.type })),\n ]),\n );\n }\n}\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EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAY,MAAM,IAFjB1C",
6
6
  "names": ["axios", "SHA224", "inject", "injectable", "Left", "Right", "configTypes", "LEDGER_CLIENT_VERSION_HEADER", "LEDGER_ORIGIN_TOKEN_HEADER", "TypedDataCalldataParamPresence", "PACKAGE", "HttpTypedDataDataSource", "config", "chainId", "address", "schema", "version", "messageInfo", "response", "axios", "LEDGER_CLIENT_VERSION_HEADER", "PACKAGE", "LEDGER_ORIGIN_TOKEN_HEADER", "schemaHash", "SHA224", "filtersJson", "Left", "filters", "calldatasInfos", "field", "Right", "flag", "TypedDataCalldataParamPresence", "uncoveredFlag", "typesCount", "sourcesCount", "types", "sources", "typesCountHex", "sourcesCountHex", "data", "mode", "t", "s", "aKey", "bKey", "key", "value", "v", "__decorateClass", "injectable", "__decorateParam", "inject", "configTypes"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var D=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var m=(c,e,r,a)=>{for(var t=a>1?void 0:a?S(e,r):e,d=c.length-1,n;d>=0;d--)(n=c[d])&&(t=(a?n(e,r,t):n(t))||t);return a&&t&&D(e,r,t),t},y=(c,e)=>(r,a)=>e(r,a,c);import{bufferToHexaString as g}from"@ledgerhq/device-management-kit";import{inject as u,injectable as I}from"inversify";import{pkiTypes as k}from"../../pki/di/pkiTypes";import{KeyId as P}from"../../pki/model/KeyId";import{KeyUsage as A}from"../../pki/model/KeyUsage";import{proxyTypes as F}from"../../proxy/di/proxyTypes";import{ClearSignContextType as R}from"../../shared/model/ClearSignContext";import{TypedDataCalldataParamPresence as H,VERIFYING_CONTRACT_TOKEN_INDEX as L}from"../../shared/model/TypedDataClearSignContext";import{tokenTypes as E}from"../../token/di/tokenTypes";import{typedDataTypes as _}from"../../typed-data/di/typedDataTypes";let f=class{constructor(e,r,a,t){this.dataSource=e;this.tokenDataSource=r;this.proxyDataSource=a;this._certificateLoader=t}async load(e){const{resolvedAddress:r,proxy:a}=await this.resolveProxy(e),t=await this.dataSource.getTypedDataFilters({address:r,chainId:e.chainId,version:e.version,schema:e.schema});if(t.isLeft())return{type:"error",error:t.extract()};const{messageInfo:d,filters:n,calldatasInfos:o}=t.unsafeCoerce(),i=n.reduce((s,p)=>(s[p.path]=p,s),{});return{type:"success",messageInfo:d,filters:i,trustedNamesAddresses:this.extractTrustedNames(n,e),tokens:await this.extractTokens(n,e),calldatas:this.extractCalldatas(n,o,e),proxy:a}}async resolveProxy(e){const r=await this.proxyDataSource.getProxyDelegateCall({calldata:"0x",proxyAddress:e.verifyingContract,chainId:e.chainId,challenge:e.challenge??""});if(r.isLeft())return{resolvedAddress:e.verifyingContract,proxy:void 0};const a=await this._certificateLoader.loadCertificate({keyId:P.CalCalldataKey,keyUsage:A.Calldata,targetDevice:e.deviceModelId}),t=r.unsafeCoerce();return{resolvedAddress:t.delegateAddresses.find(d=>d===e.verifyingContract)||t.delegateAddresses[0],proxy:{type:R.PROXY_DELEGATE_CALL,payload:t.signedDescriptor,certificate:a}}}extractTrustedNames(e,r){return e.filter(a=>a.type==="trusted-name").reduce((a,t)=>{const d=r.fieldsValues.filter(n=>n.path===t.path);if(d.length!==0){const n=d[0],o=this.convertAddressToHexaString(n.value);a[t.path]=o}return a},{})}async extractTokens(e,r){const a={};for(const t of e){if(t.type!=="token"&&t.type!=="amount")continue;const d=t.tokenIndex;if(a[d]===void 0){if(t.type==="token"){const n=r.fieldsValues.filter(s=>s.path===t.path);if(n.length===0)continue;const o=n[0],i=this.convertAddressToHexaString(o.value);if(n.every(s=>this.convertAddressToHexaString(s.value)===i)){const s=r.chainId;(await this.tokenDataSource.getTokenInfosPayload({address:i,chainId:s})).ifRight(T=>{a[d]=T})}}else if(t.type==="amount"&&d===L){const n=r.verifyingContract,o=r.chainId;(await this.tokenDataSource.getTokenInfosPayload({address:n,chainId:o})).ifRight(s=>{a[d]=s})}}}return a}extractCalldatas(e,r,a){const t=e.reduce((n,o)=>{if(o.type==="calldata-value"||o.type==="calldata-callee"||o.type==="calldata-chain-id"||o.type==="calldata-selector"||o.type==="calldata-amount"||o.type==="calldata-spender"){const i=n[o.calldataIndex];i===void 0?n[o.calldataIndex]=[o]:i.push(o)}return n},{}),d={};for(const n in r){const o=r[n],i=t[n];if(!i)continue;const s=this.extractHexaString(i.find(l=>l.type==="calldata-value"),a,"0x"),p=this.extractHexaString(i.find(l=>l.type==="calldata-selector"),a,s.slice(0,10)),T=this.extractAddress(i.find(l=>l.type==="calldata-callee"),a,o.calleeFlag),h=this.extractAddress(i.find(l=>l.type==="calldata-spender"),a,o.spenderFlag),C=this.extractBigint(i.find(l=>l.type==="calldata-amount"),a,void 0),x=this.extractBigint(i.find(l=>l.type==="calldata-chain-id"),a,void 0),v=x!==void 0&&x<Number.MAX_SAFE_INTEGER?Number(x):a.chainId;d[n]={filter:o,subset:{chainId:v,data:s,selector:p,to:T,value:C,from:h}}}return d}extractHexaString(e,r,a){if(e!==void 0){const t=r.fieldsValues.filter(d=>d.path===e.path);if(t.length!==0)return g(t[0].value)}return a}extractAddress(e,r,a,t){if(a===H.VerifyingContract)return r.verifyingContract;if(e!==void 0){const d=r.fieldsValues.filter(n=>n.path===e.path);if(d.length!==0)return this.convertAddressToHexaString(d[0].value)}return t}extractBigint(e,r,a){if(e!==void 0){const t=r.fieldsValues.filter(d=>d.path===e.path);if(t.length!==0)return BigInt(g(t[0].value))}return a}convertAddressToHexaString(e){return`0x${Array.from(e,r=>r.toString(16).padStart(2,"0")).join("").padStart(40,"0")}`}};f=m([I(),y(0,u(_.TypedDataDataSource)),y(1,u(E.TokenDataSource)),y(2,u(F.ProxyDataSource)),y(3,u(k.PkiCertificateLoader))],f);export{f as DefaultTypedDataContextLoader};
1
+ var D=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var g=(c,e,r,t)=>{for(var a=t>1?void 0:t?S(e,r):e,n=c.length-1,d;n>=0;n--)(d=c[n])&&(a=(t?d(e,r,a):d(a))||a);return t&&a&&D(e,r,a),a},p=(c,e)=>(r,t)=>e(r,t,c);import{bufferToHexaString as h}from"@ledgerhq/device-management-kit";import{inject as y,injectable as I}from"inversify";import{pkiTypes as k}from"../../pki/di/pkiTypes";import{KeyId as P}from"../../pki/model/KeyId";import{KeyUsage as A}from"../../pki/model/KeyUsage";import{proxyTypes as F}from"../../proxy/di/proxyTypes";import{ClearSignContextType as R}from"../../shared/model/ClearSignContext";import{TypedDataCalldataParamPresence as L,VERIFYING_CONTRACT_TOKEN_INDEX as E}from"../../shared/model/TypedDataClearSignContext";import{tokenTypes as H}from"../../token/di/tokenTypes";import{typedDataTypes as _}from"../../typed-data/di/typedDataTypes";let u=class{constructor(e,r,t,a){this.dataSource=e;this.tokenDataSource=r;this.proxyDataSource=t;this._certificateLoader=a}async load(e){let r,t=await this.dataSource.getTypedDataFilters({address:e.verifyingContract,chainId:e.chainId,version:e.version,schema:e.schema});if(t.isLeft()){const{resolvedAddress:i,context:s}=await this.resolveProxy(e);if(s!==void 0&&(r=s,t=await this.dataSource.getTypedDataFilters({address:i,chainId:e.chainId,version:e.version,schema:e.schema})),t.isLeft())return{type:"error",error:t.extract()}}const{messageInfo:a,filters:n,calldatasInfos:d}=t.unsafeCoerce(),o=n.reduce((i,s)=>(i[s.path]=s,i),{});return{type:"success",messageInfo:a,filters:o,trustedNamesAddresses:this.extractTrustedNames(n,e),tokens:await this.extractTokens(n,e),calldatas:this.extractCalldatas(n,d,e),proxy:r}}async resolveProxy(e){const r=await this.proxyDataSource.getProxyDelegateCall({calldata:"0x",proxyAddress:e.verifyingContract,chainId:e.chainId,challenge:e.challenge??""});if(r.isLeft())return{resolvedAddress:e.verifyingContract,context:void 0};const t=await this._certificateLoader.loadCertificate({keyId:P.CalCalldataKey,keyUsage:A.Calldata,targetDevice:e.deviceModelId}),a=r.unsafeCoerce();return{resolvedAddress:a.delegateAddresses.find(n=>n===e.verifyingContract)||a.delegateAddresses[0],context:{type:R.PROXY_DELEGATE_CALL,payload:a.signedDescriptor,certificate:t}}}extractTrustedNames(e,r){return e.filter(t=>t.type==="trusted-name").reduce((t,a)=>{const n=r.fieldsValues.filter(d=>d.path===a.path);if(n.length!==0){const d=n[0],o=this.convertAddressToHexaString(d.value);t[a.path]=o}return t},{})}async extractTokens(e,r){const t={};for(const a of e){if(a.type!=="token"&&a.type!=="amount")continue;const n=a.tokenIndex;if(t[n]===void 0){if(a.type==="token"){const d=r.fieldsValues.filter(s=>s.path===a.path);if(d.length===0)continue;const o=d[0],i=this.convertAddressToHexaString(o.value);if(d.every(s=>this.convertAddressToHexaString(s.value)===i)){const s=r.chainId;(await this.tokenDataSource.getTokenInfosPayload({address:i,chainId:s})).ifRight(f=>{t[n]=f})}}else if(a.type==="amount"&&n===E){const d=r.verifyingContract,o=r.chainId;(await this.tokenDataSource.getTokenInfosPayload({address:d,chainId:o})).ifRight(s=>{t[n]=s})}}}return t}extractCalldatas(e,r,t){const a=e.reduce((d,o)=>{if(o.type==="calldata-value"||o.type==="calldata-callee"||o.type==="calldata-chain-id"||o.type==="calldata-selector"||o.type==="calldata-amount"||o.type==="calldata-spender"){const i=d[o.calldataIndex];i===void 0?d[o.calldataIndex]=[o]:i.push(o)}return d},{}),n={};for(const d in r){const o=r[d],i=a[d];if(!i)continue;const s=this.extractHexaString(i.find(l=>l.type==="calldata-value"),t,"0x"),x=this.extractHexaString(i.find(l=>l.type==="calldata-selector"),t,s.slice(0,10)),f=this.extractAddress(i.find(l=>l.type==="calldata-callee"),t,o.calleeFlag),m=this.extractAddress(i.find(l=>l.type==="calldata-spender"),t,o.spenderFlag),C=this.extractBigint(i.find(l=>l.type==="calldata-amount"),t,void 0),T=this.extractBigint(i.find(l=>l.type==="calldata-chain-id"),t,void 0),v=T!==void 0&&T<Number.MAX_SAFE_INTEGER?Number(T):t.chainId;n[d]={filter:o,subset:{chainId:v,data:s,selector:x,to:f,value:C,from:m}}}return n}extractHexaString(e,r,t){if(e!==void 0){const a=r.fieldsValues.filter(n=>n.path===e.path);if(a.length!==0)return h(a[0].value)}return t}extractAddress(e,r,t,a){if(t===L.VerifyingContract)return r.verifyingContract;if(e!==void 0){const n=r.fieldsValues.filter(d=>d.path===e.path);if(n.length!==0)return this.convertAddressToHexaString(n[0].value)}return a}extractBigint(e,r,t){if(e!==void 0){const a=r.fieldsValues.filter(n=>n.path===e.path);if(a.length!==0)return BigInt(h(a[0].value))}return t}convertAddressToHexaString(e){return`0x${Array.from(e,r=>r.toString(16).padStart(2,"0")).join("").padStart(40,"0")}`}};u=g([I(),p(0,y(_.TypedDataDataSource)),p(1,y(H.TokenDataSource)),p(2,y(F.ProxyDataSource)),p(3,y(k.PkiCertificateLoader))],u);export{u as DefaultTypedDataContextLoader};
2
2
  //# sourceMappingURL=DefaultTypedDataContextLoader.js.map