@ledgerhq/context-module 0.0.0-multisig-2-20250922093851 → 0.0.0-multisig-2-20250922095845
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.
- package/lib/cjs/src/calldata/data/HttpCalldataDescriptorDataSource.js +1 -1
- package/lib/cjs/src/calldata/data/HttpCalldataDescriptorDataSource.js.map +2 -2
- package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.js +1 -1
- package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.js.map +1 -1
- package/lib/esm/src/calldata/data/HttpCalldataDescriptorDataSource.js +1 -1
- package/lib/esm/src/calldata/data/HttpCalldataDescriptorDataSource.js.map +2 -2
- package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.js +1 -1
- package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.js.map +1 -1
- package/lib/types/src/calldata/data/HttpCalldataDescriptorDataSource.d.ts.map +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +3 -3
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var U=Object.create;var c=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var w=Object.getPrototypeOf,K=Object.prototype.hasOwnProperty;var $=(o,e)=>{for(var t in e)c(o,t,{get:e[t],enumerable:!0})},T=(o,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of j(e))!K.call(o,i)&&i!==t&&c(o,i,{get:()=>e[i],enumerable:!(r=V(e,i))||r.enumerable});return o};var g=(o,e,t)=>(t=o!=null?U(w(o)):{},T(e||!o||!o.__esModule?c(t,"default",{value:o,enumerable:!0}):t,o)),B=o=>T(c({},"__esModule",{value:!0}),o),A=(o,e,t,r)=>{for(var i=r>1?void 0:r?V(e,t):e,s=o.length-1,n;s>=0;s--)(n=o[s])&&(i=(r?n(e,t,i):n(i))||i);return r&&i&&c(e,t,i),i},
|
|
1
|
+
"use strict";var U=Object.create;var c=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var w=Object.getPrototypeOf,K=Object.prototype.hasOwnProperty;var $=(o,e)=>{for(var t in e)c(o,t,{get:e[t],enumerable:!0})},T=(o,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of j(e))!K.call(o,i)&&i!==t&&c(o,i,{get:()=>e[i],enumerable:!(r=V(e,i))||r.enumerable});return o};var g=(o,e,t)=>(t=o!=null?U(w(o)):{},T(e||!o||!o.__esModule?c(t,"default",{value:o,enumerable:!0}):t,o)),B=o=>T(c({},"__esModule",{value:!0}),o),A=(o,e,t,r)=>{for(var i=r>1?void 0:r?V(e,t):e,s=o.length-1,n;s>=0;s--)(n=o[s])&&(i=(r?n(e,t,i):n(i))||i);return r&&i&&c(e,t,i),i},d=(o,e)=>(t,r)=>e(t,r,o);var Y={};$(Y,{HttpCalldataDescriptorDataSource:()=>y});module.exports=B(Y);var _=g(require("axios")),u=require("inversify"),p=require("purify-ts"),v=require("../../config/di/configTypes"),b=require("../../pki/di/pkiTypes"),P=require("../../pki/model/KeyId"),N=require("../../pki/model/KeyUsage"),C=require("../../shared/constant/HttpHeaders"),a=require("../../shared/model/ClearSignContext"),h=require("../../shared/model/SignatureTags"),m=require("../../shared/utils/HexStringUtils"),I=g(require("../../../package.json"));let y=class{constructor(e,t,r){this.config=e;this._certificateLoader=t;this.endpoint=r}async getCalldataDescriptors({chainId:e,address:t,selector:r,deviceModelId:i}){let s;try{const n=this.endpoint==="dapps"?"https://crypto-assets-service.api.ledger.com/v1":"https://crypto-assets-service.api.ledger-test.com/v1";s=(await _.default.request({method:"GET",url:`${n}/${this.endpoint}`,params:{output:"descriptors_calldata",chain_id:e,contracts:t,contract_address:t,ref:"commit:c9227c39e225932796e87ef4c9eb84f647e16150"},headers:{[C.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${I.default.version}`,[C.LEDGER_ORIGIN_TOKEN_HEADER]:this.config.originToken}})).data}catch(n){return(0,p.Left)(new Error(`[ContextModule] HttpCalldataDescriptorDataSource: Failed to fetch calldata descriptors: ${n}`))}if(!Array.isArray(s))return(0,p.Left)(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Response is not an array"));if(s.length===0)return(0,p.Left)(new Error(`[ContextModule] HttpCalldataDescriptorDataSource: No data for contract ${t} and selector ${r}`));for(const n of s){t=t.toLowerCase(),r=`0x${r.slice(2).toLowerCase()}`;const l=n.descriptors_calldata?.[t]?.[r];if(!l||!this.isCalldataDescriptorV1(l,this.config.cal.mode))continue;const S=l.transaction_info.descriptor.data,M=l.transaction_info.descriptor.signatures[this.config.cal.mode],R={targetDevice:i,keyUsage:N.KeyUsage.Calldata,keyId:P.KeyId.CalCalldataKey},D=await this._certificateLoader.loadCertificate(R),L={type:a.ClearSignContextType.TRANSACTION_INFO,payload:m.HexStringUtils.appendSignatureToPayload(S,M,h.INFO_SIGNATURE_TAG),certificate:D},E=[];for(const[f,O]of Object.entries(l.enums))for(const[F,{data:G,signatures:k}]of Object.entries(O))E.push({type:a.ClearSignContextType.ENUM,id:Number(f),value:Number(F),payload:m.HexStringUtils.appendSignatureToPayload(G,k[this.config.cal.mode],h.INFO_SIGNATURE_TAG),certificate:D});const x=l.fields.map(f=>({type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:f.descriptor,reference:this.getReference(f.param)}));return(0,p.Right)([L,...E,...x])}return(0,p.Left)(new Error(`[ContextModule] HttpCalldataDescriptorDataSource: 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.ClearSignContextReferenceType.TOKEN,valuePath:this.toGenericPath(e.token.binary_path)};if(e.type==="TOKEN_AMOUNT"&&e.token!==void 0&&e.token.type==="constant")return{type:a.ClearSignContextReferenceType.TOKEN,value:e.token.value};if(e.type==="NFT"&&e.collection.type==="path")return{type:a.ClearSignContextReferenceType.NFT,valuePath:this.toGenericPath(e.collection.binary_path)};if(e.type==="NFT"&&e.collection.type==="constant")return{type:a.ClearSignContextReferenceType.NFT,value:e.collection.value};if(e.type==="TRUSTED_NAME"&&e.value.type==="path")return{type:a.ClearSignContextReferenceType.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.ClearSignContextReferenceType.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.ClearSignContextReferenceType.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(([s,n])=>typeof s=="string"&&typeof n=="object"&&typeof n.data=="string"&&n.signatures!==void 0&&this.isCalldataSignatures(n.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"))}};y=A([(0,u.injectable)(),d(0,(0,u.inject)(v.configTypes.Config)),d(1,(0,u.inject)(b.pkiTypes.PkiCertificateLoader))],y);0&&(module.exports={HttpCalldataDescriptorDataSource});
|
|
2
2
|
//# sourceMappingURL=HttpCalldataDescriptorDataSource.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/calldata/data/HttpCalldataDescriptorDataSource.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 CalldataDescriptorDataSource,\n GetCalldataDescriptorsParams,\n} from \"./CalldataDescriptorDataSource\";\n\n@injectable()\nexport class HttpCalldataDescriptorDataSource\n implements CalldataDescriptorDataSource\n{\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n private readonly endpoint: string,\n ) {}\n\n public async getCalldataDescriptors({\n chainId,\n address,\n selector,\n deviceModelId,\n }: GetCalldataDescriptorsParams): Promise<\n Either<Error, ClearSignContextSuccess[]>\n > {\n let dto: CalldataDto[] | undefined;\n try {\n const url =\n this.endpoint === \"dapps\"\n ? \"https://crypto-assets-service.api.ledger.com/v1\"\n : \"https://crypto-assets-service.api.ledger-test.com/v1\";\n const response = await axios.request<CalldataDto[]>({\n method: \"GET\",\n url: `${url}/${this.endpoint}`,\n params: {\n output: \"descriptors_calldata\",\n chain_id: chainId,\n contracts: address, // used for dapps\n contract_address: address, // used for tokens\n // TODO revert to branch\n ref:\n this.endpoint === \"dapps\"\n ? `commit:fbc6fc39e2c335545c726a972b9d366a69944ed0`\n : `branch:next`,\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] HttpCalldataDescriptorDataSource: Failed to fetch calldata descriptors: ${error}`,\n ),\n );\n }\n\n if (!Array.isArray(dto)) {\n return Left(\n new Error(\n `[ContextModule] HttpCalldataDescriptorDataSource: Response is not an array`,\n ),\n );\n }\n\n if (dto.length === 0) {\n return Left(\n new Error(\n `[ContextModule] HttpCalldataDescriptorDataSource: 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] HttpCalldataDescriptorDataSource: 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": "qtBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,sCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkB,oBAClBC,EAAmC,qBACnCC,EAAoC,qBAEpCC,EAA4B,mCAK5BC,EAAyB,6BAEzBC,EAAsB,6BACtBC,EAAyB,gCAGzBC,EAGO,yCACPC,EAKO,2CAEPC,EAAmC,wCACnCC,EAA+B,yCAC/BC,EAAoB,iCAyBb,IAAMC,EAAN,KAEP,CACE,YAC+CC,EAE5BC,EACAC,EACjB,CAJ6C,YAAAF,EAE5B,wBAAAC,EACA,cAAAC,CAChB,CAEH,MAAa,uBAAuB,CAClC,QAAAC,EACA,QAAAC,EACA,SAAAC,EACA,cAAAC,CACF,EAEE,CACA,IAAIC,EACJ,GAAI,CACF,MAAMC,EACJ,KAAK,WAAa,QACd,kDACA,
|
|
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 CalldataDescriptorDataSource,\n GetCalldataDescriptorsParams,\n} from \"./CalldataDescriptorDataSource\";\n\n@injectable()\nexport class HttpCalldataDescriptorDataSource\n implements CalldataDescriptorDataSource\n{\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n private readonly endpoint: string,\n ) {}\n\n public async getCalldataDescriptors({\n chainId,\n address,\n selector,\n deviceModelId,\n }: GetCalldataDescriptorsParams): Promise<\n Either<Error, ClearSignContextSuccess[]>\n > {\n let dto: CalldataDto[] | undefined;\n try {\n const url =\n this.endpoint === \"dapps\"\n ? \"https://crypto-assets-service.api.ledger.com/v1\"\n : \"https://crypto-assets-service.api.ledger-test.com/v1\";\n const response = await axios.request<CalldataDto[]>({\n method: \"GET\",\n url: `${url}/${this.endpoint}`,\n params: {\n output: \"descriptors_calldata\",\n chain_id: chainId,\n contracts: address, // used for dapps\n contract_address: address, // used for tokens\n // TODO revert to branch\n ref: `commit:c9227c39e225932796e87ef4c9eb84f647e16150`,\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] HttpCalldataDescriptorDataSource: Failed to fetch calldata descriptors: ${error}`,\n ),\n );\n }\n\n if (!Array.isArray(dto)) {\n return Left(\n new Error(\n `[ContextModule] HttpCalldataDescriptorDataSource: Response is not an array`,\n ),\n );\n }\n\n if (dto.length === 0) {\n return Left(\n new Error(\n `[ContextModule] HttpCalldataDescriptorDataSource: 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] HttpCalldataDescriptorDataSource: 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": "qtBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,sCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkB,oBAClBC,EAAmC,qBACnCC,EAAoC,qBAEpCC,EAA4B,mCAK5BC,EAAyB,6BAEzBC,EAAsB,6BACtBC,EAAyB,gCAGzBC,EAGO,yCACPC,EAKO,2CAEPC,EAAmC,wCACnCC,EAA+B,yCAC/BC,EAAoB,iCAyBb,IAAMC,EAAN,KAEP,CACE,YAC+CC,EAE5BC,EACAC,EACjB,CAJ6C,YAAAF,EAE5B,wBAAAC,EACA,cAAAC,CAChB,CAEH,MAA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,EAAK,YAAY,KAAK,GACtDA,EAAK,YAAY,OAAS,QACzB,MAAM,QAAQA,EAAK,YAAY,QAAQ,GACvCA,EAAK,YAAY,SAAS,MAAOa,GAAM,KAAK,gBAAgBA,CAAC,CAAC,EAEtE,CAEQ,gBAAgBb,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,EA1ZaxB,EAANsC,EAAA,IADN,cAAW,EAKPC,EAAA,eAAO,cAAY,MAAM,GACzBA,EAAA,eAAO,WAAS,oBAAoB,IAL5BvC",
|
|
6
6
|
"names": ["HttpCalldataDescriptorDataSource_exports", "__export", "HttpCalldataDescriptorDataSource", "__toCommonJS", "import_axios", "import_inversify", "import_purify_ts", "import_configTypes", "import_pkiTypes", "import_KeyId", "import_KeyUsage", "import_HttpHeaders", "import_ClearSignContext", "import_SignatureTags", "import_HexStringUtils", "import_package", "HttpCalldataDescriptorDataSource", "config", "_certificateLoader", "endpoint", "chainId", "address", "selector", "deviceModelId", "dto", "url", "axios", "PACKAGE", "error", "calldata", "calldataDescriptor", "infoData", "infoSignature", "certificateInfos", "certificate", "info", "enums", "id", "values", "value", "data", "signatures", "fields", "field", "param", "path", "element", "itemSize", "rest", "leafType", "mode", "f", "obj", "e", "__decorateClass", "__decorateParam"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var v=Object.create;var f=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,N=Object.prototype.hasOwnProperty;var S=(r,e)=>{for(var t in e)f(r,t,{get:e[t],enumerable:!0})},I=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of E(e))!N.call(r,o)&&o!==t&&f(r,o,{get:()=>e[o],enumerable:!(i=C(e,o))||i.enumerable});return r};var _=(r,e,t)=>(t=r!=null?v(V(r)):{},I(e||!r||!r.__esModule?f(t,"default",{value:r,enumerable:!0}):t,r)),j=r=>I(f({},"__esModule",{value:!0}),r),F=(r,e,t,i)=>{for(var o=i>1?void 0:i?C(e,t):e,s=r.length-1,a;s>=0;s--)(a=r[s])&&(o=(i?a(e,t,o):a(o))||o);return i&&o&&f(e,t,o),o},x=(r,e)=>(t,i)=>e(t,i,r);var P={};S(P,{HttpTypedDataDataSource:()=>d});module.exports=j(P);var M=_(require("axios")),D=_(require("crypto-js/sha224")),m=require("inversify"),l=require("purify-ts"),T=require("../../config/di/configTypes"),g=require("../../shared/constant/HttpHeaders"),y=require("../../shared/model/TypedDataClearSignContext"),b=_(require("../../../package.json"));let d=class{constructor(e){this.config=e}async getTypedDataFilters({chainId:e,address:t,schema:i,version:o}){let s;try{const a=await M.default.request({method:"GET",url:`${this.config.cal.url}/dapps`,params:{contracts:t,chain_id:e,output:"descriptors_eip712",descriptors_eip712_version:o,descriptors_eip712:"<set>",ref:"commit:
|
|
1
|
+
"use strict";var v=Object.create;var f=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,N=Object.prototype.hasOwnProperty;var S=(r,e)=>{for(var t in e)f(r,t,{get:e[t],enumerable:!0})},I=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of E(e))!N.call(r,o)&&o!==t&&f(r,o,{get:()=>e[o],enumerable:!(i=C(e,o))||i.enumerable});return r};var _=(r,e,t)=>(t=r!=null?v(V(r)):{},I(e||!r||!r.__esModule?f(t,"default",{value:r,enumerable:!0}):t,r)),j=r=>I(f({},"__esModule",{value:!0}),r),F=(r,e,t,i)=>{for(var o=i>1?void 0:i?C(e,t):e,s=r.length-1,a;s>=0;s--)(a=r[s])&&(o=(i?a(e,t,o):a(o))||o);return i&&o&&f(e,t,o),o},x=(r,e)=>(t,i)=>e(t,i,r);var P={};S(P,{HttpTypedDataDataSource:()=>d});module.exports=j(P);var M=_(require("axios")),D=_(require("crypto-js/sha224")),m=require("inversify"),l=require("purify-ts"),T=require("../../config/di/configTypes"),g=require("../../shared/constant/HttpHeaders"),y=require("../../shared/model/TypedDataClearSignContext"),b=_(require("../../../package.json"));let d=class{constructor(e){this.config=e}async getTypedDataFilters({chainId:e,address:t,schema:i,version:o}){let s;try{const a=await M.default.request({method:"GET",url:`${this.config.cal.url}/dapps`,params:{contracts:t,chain_id:e,output:"descriptors_eip712",descriptors_eip712_version:o,descriptors_eip712:"<set>",ref:"commit:c9227c39e225932796e87ef4c9eb84f647e16150"},headers:{[g.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${b.default.version}`,[g.LEDGER_ORIGIN_TOKEN_HEADER]:this.config.originToken}}),c=(0,D.default)(JSON.stringify(this.sortTypes(i)).replace(" ","")).toString();t=t.toLowerCase();const u=a.data?.[0]?.descriptors_eip712?.[t]?.[c];if(!u)return(0,l.Left)(new Error(`[ContextModule] HttpTypedDataDataSource: no typed data filters for address ${t} on chain ${e} for schema ${c}`));if(!u.schema||!Array.isArray(u.instructions))return(0,l.Left)(new Error(`[ContextModule] HttpTypedDataDataSource: no message info for address ${t} on chain ${e} for schema ${c}`));const p=[],h={};for(const n of u.instructions)if(this.isInstructionContractInfo(n,this.config.cal.mode))s={displayName:n.display_name,signature:n.signatures[this.config.cal.mode],filtersCount:n.field_mappers_count};else if(o==="v1"&&this.isInstructionFieldV1(n,this.config.cal.mode))p.push({type:"raw",displayName:n.display_name,path:n.field_path,signature:n.signatures[this.config.cal.mode]});else if(this.isInstructionFieldV2(n,this.config.cal.mode))p.push({type:n.format,displayName:n.display_name,path:n.field_path,signature:n.signatures[this.config.cal.mode]});else if(this.isInstructionFieldV2WithCoinRef(n,this.config.cal.mode))p.push({type:n.format,displayName:n.display_name,path:n.field_path,signature:n.signatures[this.config.cal.mode],tokenIndex:n.coin_ref});else if(this.isInstructionFieldV2WithName(n,this.config.cal.mode))p.push({type:n.format,displayName:n.display_name,path:n.field_path,signature:n.signatures[this.config.cal.mode],types:n.name_types,sources:n.name_sources,typesAndSourcesPayload:this.formatTrustedNameTypesAndSources(n)});else if(this.isInstructionCalldataInfo(n,this.config.cal.mode))h[n.calldata_index]={displayName:n.display_name,calldataIndex:n.calldata_index,valueFlag:n.value_filter_flag,calleeFlag:this.convertCalldataPresenceFlag(n.callee_filter_flag),amountFlag:n.amount_filter_flag,spenderFlag:this.convertCalldataPresenceFlag(n.spender_filter_flag),chainIdFlag:n.chain_id_filter_flag,selectorFlag:n.selector_filter_flag,signature:n.signatures[this.config.cal.mode]};else if(this.isInstructionFieldV2Calldata(n,this.config.cal.mode))p.push({type:n.format,displayName:n.display_name,path:n.field_path,signature:n.signatures[this.config.cal.mode],calldataIndex:n.calldata_index});else return(0,l.Left)(new Error(`[ContextModule] HttpTypedDataDataSource: invalid typed data field for address ${t} on chain ${e} for schema ${c}`));return s?(0,l.Right)({messageInfo:s,filters:p,calldatasInfos:h}):(0,l.Left)(new Error(`[ContextModule] HttpTypedDataDataSource: no message info for address ${t} on chain ${e} for schema ${c}`))}catch{return(0,l.Left)(new Error("[ContextModule] HttpTypedDataDataSource: Failed to fetch typed data informations"))}}convertCalldataPresenceFlag(e){switch(e){case"none":return y.TypedDataCalldataParamPresence.None;case"present":return y.TypedDataCalldataParamPresence.Present;case"verifying_contract":return y.TypedDataCalldataParamPresence.VerifyingContract;default:{const t=e;throw new Error(`Unhandled flag: ${t}`)}}}formatTrustedNameTypesAndSources(e){const t=e.name_types.length,i=e.name_sources.length,o=e.descriptor.slice((t+i)*2*-1,i*2*-1),s=e.descriptor.slice(i*2*-1),a=t.toString(16).padStart(2,"0"),c=i.toString(16).padStart(2,"0");return a+o+c+s}isInstructionFieldV1(e,t){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_path=="string"&&typeof e.signatures=="object"&&typeof e.signatures[t]=="string"}isInstructionFieldV2(e,t){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_path=="string"&&typeof e.signatures=="object"&&typeof e.signatures[t]=="string"&&typeof e.format=="string"&&["raw","datetime"].includes(e.format)&&e.coin_ref===void 0}isInstructionFieldV2WithCoinRef(e,t){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_path=="string"&&typeof e.signatures=="object"&&typeof e.signatures[t]=="string"&&typeof e.format=="string"&&["token","amount"].includes(e.format)&&typeof e.coin_ref=="number"}isInstructionFieldV2WithName(e,t){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_path=="string"&&typeof e.signatures=="object"&&typeof e.signatures[t]=="string"&&typeof e.format=="string"&&e.format==="trusted-name"&&e.coin_ref===void 0&&Array.isArray(e.name_types)&&Array.isArray(e.name_sources)&&e.name_types.every(i=>typeof i=="string")&&e.name_sources.every(i=>typeof i=="string")}isInstructionContractInfo(e,t){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_mappers_count=="number"&&typeof e.signatures=="object"&&typeof e.signatures[t]=="string"&&e.field_path===void 0}isInstructionCalldataInfo(e,t){return typeof e=="object"&&typeof e.type=="string"&&e.type==="calldata"&&typeof e.display_name=="string"&&typeof e.calldata_index=="number"&&typeof e.value_filter_flag=="boolean"&&typeof e.chain_id_filter_flag=="boolean"&&typeof e.selector_filter_flag=="boolean"&&typeof e.amount_filter_flag=="boolean"&&["none","present","verifying_contract"].includes(e.callee_filter_flag)&&["none","present","verifying_contract"].includes(e.spender_filter_flag)&&typeof e.signatures=="object"&&typeof e.signatures[t]=="string"}isInstructionFieldV2Calldata(e,t){return typeof e=="object"&&typeof e.display_name=="string"&&typeof e.field_path=="string"&&typeof e.signatures=="object"&&typeof e.signatures[t]=="string"&&typeof e.format=="string"&&["calldata-value","calldata-callee","calldata-chain-id","calldata-selector","calldata-amount","calldata-spender"].includes(e.format)&&typeof e.calldata_index=="number"}sortTypes(e){return Object.fromEntries(Object.entries(e).sort(([t],[i])=>t.localeCompare(i)).map(([t,i])=>[t,i.map(o=>({name:o.name,type:o.type}))]))}};d=F([(0,m.injectable)(),x(0,(0,m.inject)(T.configTypes.Config))],d);0&&(module.exports={HttpTypedDataDataSource});
|
|
2
2
|
//# sourceMappingURL=HttpTypedDataDataSource.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/typed-data/data/HttpTypedDataDataSource.ts"],
|
|
4
|
-
"sourcesContent": ["import axios from \"axios\";\nimport SHA224 from \"crypto-js/sha224\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport type {\n ContextModuleCalMode,\n ContextModuleConfig,\n} from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport type {\n TypedDataCalldataIndex,\n TypedDataFilter,\n TypedDataFilterCalldataInfo,\n TypedDataMessageInfo,\n} from \"@/shared/model/TypedDataClearSignContext\";\nimport { TypedDataCalldataParamPresence } from \"@/shared/model/TypedDataClearSignContext\";\nimport type { TypedDataSchema } from \"@/shared/model/TypedDataContext\";\nimport PACKAGE from \"@root/package.json\";\n\nimport type {\n FiltersDto,\n InstructionCalldataInfo,\n InstructionCalldataParamPresence,\n InstructionContractInfo,\n InstructionField,\n InstructionFieldV1,\n InstructionFieldV2,\n InstructionFieldV2Calldata,\n InstructionFieldV2WithCoinRef,\n InstructionFieldV2WithName,\n} from \"./FiltersDto\";\nimport {\n GetTypedDataFiltersParams,\n GetTypedDataFiltersResult,\n TypedDataDataSource,\n} from \"./TypedDataDataSource\";\n\n@injectable()\nexport class HttpTypedDataDataSource implements TypedDataDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n ) {}\n\n public async getTypedDataFilters({\n chainId,\n address,\n schema,\n version,\n }: GetTypedDataFiltersParams): Promise<\n Either<Error, GetTypedDataFiltersResult>\n > {\n let messageInfo: TypedDataMessageInfo | undefined = undefined;\n\n try {\n const response = await axios.request<FiltersDto[]>({\n method: \"GET\",\n url: `${this.config.cal.url}/dapps`,\n params: {\n contracts: address,\n chain_id: chainId,\n output: \"descriptors_eip712\",\n descriptors_eip712_version: version,\n descriptors_eip712: \"<set>\",\n // TODO revert to branch\n ref: `commit:fbc6fc39e2c335545c726a972b9d366a69944ed0`,\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"],
|
|
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:c9227c39e225932796e87ef4c9eb84f647e16150`,\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
5
|
"mappings": "qtBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,6BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkB,oBAClBC,EAAmB,+BACnBC,EAAmC,qBACnCC,EAAoC,qBAEpCC,EAA4B,mCAK5BC,EAGO,yCAOPC,EAA+C,oDAE/CC,EAAoB,iCAqBb,IAAMC,EAAN,KAA6D,CAClE,YAC+CC,EAC7C,CAD6C,YAAAA,CAC5C,CAEH,MAAa,oBAAoB,CAC/B,QAAAC,EACA,QAAAC,EACA,OAAAC,EACA,QAAAC,CACF,EAEE,CACA,IAAIC,EAEJ,GAAI,CACF,MAAMC,EAAW,MAAM,EAAAC,QAAM,QAAsB,CACjD,OAAQ,MACR,IAAK,GAAG,KAAK,OAAO,IAAI,GAAG,SAC3B,OAAQ,CACN,UAAWL,EACX,SAAUD,EACV,OAAQ,qBACR,2BAA4BG,EAC5B,mBAAoB,QAEpB,IAAK,iDACP,EACA,QAAS,CACP,CAAC,8BAA4B,EAAG,kBAAkB,EAAAI,QAAQ,OAAO,GACjE,CAAC,4BAA0B,EAAG,KAAK,OAAO,WAC5C,CACF,CAAC,EAGKC,KAAa,EAAAC,SACjB,KAAK,UAAU,KAAK,UAAUP,CAAM,CAAC,EAAE,QAAQ,IAAK,EAAE,CACxD,EAAE,SAAS,EACXD,EAAUA,EAAQ,YAAY,EAC9B,MAAMS,EACJL,EAAS,OAAO,CAAC,GAAG,qBAAqBJ,CAAO,IAA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ACjB,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,EAtWahC,EAANiC,EAAA,IADN,cAAW,EAGPC,EAAA,eAAO,cAAY,MAAM,IAFjBlC",
|
|
6
6
|
"names": ["HttpTypedDataDataSource_exports", "__export", "HttpTypedDataDataSource", "__toCommonJS", "import_axios", "import_sha224", "import_inversify", "import_purify_ts", "import_configTypes", "import_HttpHeaders", "import_TypedDataClearSignContext", "import_package", "HttpTypedDataDataSource", "config", "chainId", "address", "schema", "version", "messageInfo", "response", "axios", "PACKAGE", "schemaHash", "SHA224", "filtersJson", "filters", "calldatasInfos", "field", "flag", "uncoveredFlag", "typesCount", "sourcesCount", "types", "sources", "typesCountHex", "sourcesCountHex", "data", "mode", "t", "s", "aKey", "bKey", "key", "value", "v", "__decorateClass", "__decorateParam"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var I=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var h=(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},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
|
|
1
|
+
var I=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var h=(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},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 s,ClearSignContextType as f}from"../../shared/model/ClearSignContext";import{INFO_SIGNATURE_TAG as D}from"../../shared/model/SignatureTags";import{HexStringUtils as E}from"../../shared/utils/HexStringUtils";import j from"../../../package.json";let y=class{constructor(e,t,r){this.config=e;this._certificateLoader=t;this.endpoint=r}async getCalldataDescriptors({chainId:e,address:t,selector:r,deviceModelId:i}){let n;try{const o=this.endpoint==="dapps"?"https://crypto-assets-service.api.ledger.com/v1":"https://crypto-assets-service.api.ledger-test.com/v1";n=(await M.request({method:"GET",url:`${o}/${this.endpoint}`,params:{output:"descriptors_calldata",chain_id:e,contracts:t,contract_address:t,ref:"commit:c9227c39e225932796e87ef4c9eb84f647e16150"},headers:{[k]:`context-module/${j.version}`,[U]:this.config.originToken}})).data}catch(o){return c(new Error(`[ContextModule] HttpCalldataDescriptorDataSource: Failed to fetch calldata descriptors: ${o}`))}if(!Array.isArray(n))return c(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Response is not an array"));if(n.length===0)return c(new Error(`[ContextModule] HttpCalldataDescriptorDataSource: No data for contract ${t} and selector ${r}`));for(const o of n){t=t.toLowerCase(),r=`0x${r.slice(2).toLowerCase()}`;const a=o.descriptors_calldata?.[t]?.[r];if(!a||!this.isCalldataDescriptorV1(a,this.config.cal.mode))continue;const V=a.transaction_info.descriptor.data,T=a.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(V,T,D),certificate:C},d=[];for(const[p,v]of Object.entries(a.enums))for(const[b,{data:P,signatures:N}]of Object.entries(v))d.push({type:f.ENUM,id:Number(p),value:Number(b),payload:E.appendSignatureToPayload(P,N[this.config.cal.mode],D),certificate:C});const _=a.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] HttpCalldataDescriptorDataSource: 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:s.TOKEN,valuePath:this.toGenericPath(e.token.binary_path)};if(e.type==="TOKEN_AMOUNT"&&e.token!==void 0&&e.token.type==="constant")return{type:s.TOKEN,value:e.token.value};if(e.type==="NFT"&&e.collection.type==="path")return{type:s.NFT,valuePath:this.toGenericPath(e.collection.binary_path)};if(e.type==="NFT"&&e.collection.type==="constant")return{type:s.NFT,value:e.collection.value};if(e.type==="TRUSTED_NAME"&&e.value.type==="path")return{type:s.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:s.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:s.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"))}};y=h([R(),u(0,m(x.Config)),u(1,m(O.PkiCertificateLoader))],y);export{y as HttpCalldataDescriptorDataSource};
|
|
2
2
|
//# sourceMappingURL=HttpCalldataDescriptorDataSource.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/calldata/data/HttpCalldataDescriptorDataSource.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 CalldataDescriptorDataSource,\n GetCalldataDescriptorsParams,\n} from \"./CalldataDescriptorDataSource\";\n\n@injectable()\nexport class HttpCalldataDescriptorDataSource\n implements CalldataDescriptorDataSource\n{\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n private readonly endpoint: string,\n ) {}\n\n public async getCalldataDescriptors({\n chainId,\n address,\n selector,\n deviceModelId,\n }: GetCalldataDescriptorsParams): Promise<\n Either<Error, ClearSignContextSuccess[]>\n > {\n let dto: CalldataDto[] | undefined;\n try {\n const url =\n this.endpoint === \"dapps\"\n ? \"https://crypto-assets-service.api.ledger.com/v1\"\n : \"https://crypto-assets-service.api.ledger-test.com/v1\";\n const response = await axios.request<CalldataDto[]>({\n method: \"GET\",\n url: `${url}/${this.endpoint}`,\n params: {\n output: \"descriptors_calldata\",\n chain_id: chainId,\n contracts: address, // used for dapps\n contract_address: address, // used for tokens\n // TODO revert to branch\n ref:\n this.endpoint === \"dapps\"\n ? `commit:fbc6fc39e2c335545c726a972b9d366a69944ed0`\n : `branch:next`,\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] HttpCalldataDescriptorDataSource: Failed to fetch calldata descriptors: ${error}`,\n ),\n );\n }\n\n if (!Array.isArray(dto)) {\n return Left(\n new Error(\n `[ContextModule] HttpCalldataDescriptorDataSource: Response is not an array`,\n ),\n );\n }\n\n if (dto.length === 0) {\n return Left(\n new Error(\n `[ContextModule] HttpCalldataDescriptorDataSource: 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] HttpCalldataDescriptorDataSource: 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,KAEP,CACE,YAC+CC,EAE5BC,EACAC,EACjB,CAJ6C,YAAAF,EAE5B,wBAAAC,EACA,cAAAC,CAChB,CAEH,MAAa,uBAAuB,CAClC,QAAAC,EACA,QAAAC,EACA,SAAAC,EACA,cAAAC,CACF,EAEE,CACA,IAAIC,EACJ,GAAI,CACF,MAAMC,EACJ,KAAK,WAAa,QACd,kDACA,
|
|
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 CalldataDescriptorDataSource,\n GetCalldataDescriptorsParams,\n} from \"./CalldataDescriptorDataSource\";\n\n@injectable()\nexport class HttpCalldataDescriptorDataSource\n implements CalldataDescriptorDataSource\n{\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n private readonly endpoint: string,\n ) {}\n\n public async getCalldataDescriptors({\n chainId,\n address,\n selector,\n deviceModelId,\n }: GetCalldataDescriptorsParams): Promise<\n Either<Error, ClearSignContextSuccess[]>\n > {\n let dto: CalldataDto[] | undefined;\n try {\n const url =\n this.endpoint === \"dapps\"\n ? \"https://crypto-assets-service.api.ledger.com/v1\"\n : \"https://crypto-assets-service.api.ledger-test.com/v1\";\n const response = await axios.request<CalldataDto[]>({\n method: \"GET\",\n url: `${url}/${this.endpoint}`,\n params: {\n output: \"descriptors_calldata\",\n chain_id: chainId,\n contracts: address, // used for dapps\n contract_address: address, // used for tokens\n // TODO revert to branch\n ref: `commit:c9227c39e225932796e87ef4c9eb84f647e16150`,\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] HttpCalldataDescriptorDataSource: Failed to fetch calldata descriptors: ${error}`,\n ),\n );\n }\n\n if (!Array.isArray(dto)) {\n return Left(\n new Error(\n `[ContextModule] HttpCalldataDescriptorDataSource: Response is not an array`,\n ),\n );\n }\n\n if (dto.length === 0) {\n return Left(\n new Error(\n `[ContextModule] HttpCalldataDescriptorDataSource: 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] HttpCalldataDescriptorDataSource: 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,KAEP,CACE,YAC+CC,EAE5BC,EACAC,EACjB,CAJ6C,YAAAF,EAE5B,wBAAAC,EACA,cAAAC,CAChB,CAEH,MAAa,uBAAuB,CAClC,QAAAC,EACA,QAAAC,EACA,SAAAC,EACA,cAAAC,CACF,EAEE,CACA,IAAIC,EACJ,GAAI,CACF,MAAMC,EACJ,KAAK,WAAa,QACd,kDACA,uDAiBND,GAhBiB,MAAME,EAAM,QAAuB,CAClD,OAAQ,MACR,IAAK,GAAGD,CAAG,IAAI,KAAK,QAAQ,GAC5B,OAAQ,CACN,OAAQ,uBACR,SAAUL,EACV,UAAWC,EACX,iBAAkBA,EAElB,IAAK,iDACP,EACA,QAAS,CACP,CAACM,CAA4B,EAAG,kBAAkBC,EAAQ,OAAO,GACjE,CAACC,CAA0B,EAAG,KAAK,OAAO,WAC5C,CACF,CAAC,GACc,IACjB,OAASC,EAAO,CACd,OAAOC,EACL,IAAI,MACF,2FAA2FD,CAAK,EAClG,CACF,CACF,CAEA,GAAI,CAAC,MAAM,QAAQN,CAAG,EACpB,OAAOO,EACL,IAAI,MACF,4EACF,CACF,EAGF,GAAIP,EAAI,SAAW,EACjB,OAAOO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OA,EAAK,KAAQ,UAEhE,CACF,EA1ZahC,EAANgD,EAAA,CADNC,EAAW,EAKPC,EAAA,EAAAC,EAAOC,EAAY,MAAM,GACzBF,EAAA,EAAAC,EAAOE,EAAS,oBAAoB,IAL5BrD",
|
|
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", "HttpCalldataDescriptorDataSource", "config", "_certificateLoader", "endpoint", "chainId", "address", "selector", "deviceModelId", "dto", "url", "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 _=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:
|
|
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:c9227c39e225932796e87ef4c9eb84f647e16150"},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
|