@ledgerhq/device-signer-kit-ethereum 0.0.0-develop-20260415002255 → 0.0.0-develop-20260417002136
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/internal/app-binder/task/BuildBaseContexts.js +1 -1
- package/lib/cjs/internal/app-binder/task/BuildBaseContexts.js.map +2 -2
- package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.js +1 -1
- package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.js.map +2 -2
- package/lib/cjs/internal/app-binder/task/ProvideContextTask.js +1 -1
- package/lib/cjs/internal/app-binder/task/ProvideContextTask.js.map +2 -2
- package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.js +1 -1
- package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.js.map +2 -2
- package/lib/cjs/package.json +1 -1
- package/lib/esm/internal/app-binder/task/BuildBaseContexts.js +1 -1
- package/lib/esm/internal/app-binder/task/BuildBaseContexts.js.map +2 -2
- package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.js +1 -1
- package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.js.map +2 -2
- package/lib/esm/internal/app-binder/task/ProvideContextTask.js +1 -1
- package/lib/esm/internal/app-binder/task/ProvideContextTask.js.map +2 -2
- package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.js +1 -1
- package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.js.map +2 -2
- package/lib/esm/package.json +1 -1
- package/lib/types/internal/app-binder/task/BuildBaseContexts.d.ts.map +1 -1
- package/lib/types/internal/app-binder/task/BuildSubcontextsTask.d.ts.map +1 -1
- package/lib/types/internal/app-binder/task/ProvideContextTask.d.ts.map +1 -1
- package/lib/types/internal/app-binder/task/ProvideEIP712ContextTask.d.ts.map +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +9 -9
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var T=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var D=(a,t)=>{for(var n in t)T(a,n,{get:t[n],enumerable:!0})},G=(a,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of x(t))!y.call(a,s)&&s!==n&&T(a,s,{get:()=>t[s],enumerable:!(i=O(t,s))||i.enumerable});return a};var f=a=>G(T({},"__esModule",{value:!0}),a);var
|
|
1
|
+
"use strict";var T=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var D=(a,t)=>{for(var n in t)T(a,n,{get:t[n],enumerable:!0})},G=(a,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of x(t))!y.call(a,s)&&s!==n&&T(a,s,{get:()=>t[s],enumerable:!(i=O(t,s))||i.enumerable});return a};var f=a=>G(T({},"__esModule",{value:!0}),a);var P={};D(P,{BASE_CONTEXT_TYPES_FILTER:()=>R,BuildBaseContexts:()=>h,NESTED_CALLDATA_CONTEXT_TYPES_FILTER:()=>A});module.exports=f(P);var e=require("@ledgerhq/context-module"),o=require("@ledgerhq/device-management-kit"),_=require("../../../api/model/ClearSigningType"),p=require("../../app-binder/command/GetChallengeCommand"),I=require("../../app-binder/EthereumApplicationResolver"),N=require("../../shared/EthAppVersions");const A=[e.ClearSignContextType.TRUSTED_NAME,e.ClearSignContextType.TRANSACTION_INFO,e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,e.ClearSignContextType.ENUM,e.ClearSignContextType.PROXY_INFO],R=[e.ClearSignContextType.TRANSACTION_INFO,e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,e.ClearSignContextType.PROXY_INFO,e.ClearSignContextType.TRANSACTION_CHECK,e.ClearSignContextType.DYNAMIC_NETWORK,e.ClearSignContextType.DYNAMIC_NETWORK_ICON,e.ClearSignContextType.ENUM,e.ClearSignContextType.TRUSTED_NAME,e.ClearSignContextType.TOKEN,e.ClearSignContextType.NFT,e.ClearSignContextType.PLUGIN,e.ClearSignContextType.EXTERNAL_PLUGIN,e.ClearSignContextType.GATED_SIGNING];class h{constructor(t,n){this._api=t;this._args=n}async run(){const{contextModule:t,appConfig:n,transaction:i,subset:s}=this._args,r=i===void 0,l=!r&&n.web3ChecksEnabled,C=this._api.getDeviceSessionState();let E;if(C.deviceModelId!==o.DeviceModelId.NANO_S){const c=await this._api.sendCommand(new p.GetChallengeCommand);(0,o.isSuccessCommandResult)(c)&&(E=c.data.challenge)}const d=await t.getContexts({challenge:E,deviceModelId:C.deviceModelId,transaction:l?i:void 0,...s},r?A:R),u=d.filter(c=>c.type===e.ClearSignContextType.ERROR).length,g=d.filter(c=>c.type!==e.ClearSignContextType.ERROR),S=new o.ApplicationChecker(C,n,new I.EthereumApplicationResolver).withMinVersionInclusive(N.MIN_ETH_APP_VERSION_FOR_GATED_SIGNING).excludeDeviceModel(o.DeviceModelId.NANO_S).check()?g:g.filter(c=>c.type!==e.ClearSignContextType.GATED_SIGNING);return this._supportsGenericParser(C,n)&&this._hasValidTransactionInfo(S)?this._getERC7730Contexts(S,u):this._getBasicContexts(S,u)}_getERC7730Contexts(t,n){const i=t.filter(r=>this._isContextNeededForERC7730ClearSigning(r)).sort((r,l)=>this._getContextPriority(r)-this._getContextPriority(l)),s=t.filter(r=>r.type===e.ClearSignContextType.ENUM);return{clearSignContexts:i,clearSignContextsOptional:s,clearSigningType:_.ClearSigningType.EIP7730,contextErrorCount:n}}_getBasicContexts(t,n){return{clearSignContexts:t.filter(s=>this._isContextNeededForBasicClearSigning(s)).sort((s,r)=>this._getContextPriority(s)-this._getContextPriority(r)),clearSignContextsOptional:[],clearSigningType:_.ClearSigningType.BASIC,contextErrorCount:n}}_isContextNeededForBasicClearSigning({type:t}){switch(t){case e.ClearSignContextType.TRANSACTION_CHECK:case e.ClearSignContextType.PLUGIN:case e.ClearSignContextType.EXTERNAL_PLUGIN:case e.ClearSignContextType.DYNAMIC_NETWORK:case e.ClearSignContextType.DYNAMIC_NETWORK_ICON:case e.ClearSignContextType.TRUSTED_NAME:case e.ClearSignContextType.TOKEN:case e.ClearSignContextType.NFT:case e.ClearSignContextType.GATED_SIGNING:case e.ClearSignContextType.PROXY_INFO:return!0;case e.ClearSignContextType.TRANSACTION_INFO:case e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:case e.ClearSignContextType.ENUM:case e.ClearSignContextType.SAFE:case e.ClearSignContextType.SIGNER:case e.ClearSignContextType.ACCOUNT_OWNERSHIP:return!1;default:{const n=t;throw new Error(`Unhandled context type ${String(n)}`)}}}_isContextNeededForERC7730ClearSigning({type:t}){switch(t){case e.ClearSignContextType.TRANSACTION_INFO:case e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:case e.ClearSignContextType.PROXY_INFO:case e.ClearSignContextType.DYNAMIC_NETWORK:case e.ClearSignContextType.DYNAMIC_NETWORK_ICON:case e.ClearSignContextType.TRANSACTION_CHECK:case e.ClearSignContextType.GATED_SIGNING:return!0;case e.ClearSignContextType.ENUM:case e.ClearSignContextType.TRUSTED_NAME:case e.ClearSignContextType.TOKEN:case e.ClearSignContextType.NFT:case e.ClearSignContextType.PLUGIN:case e.ClearSignContextType.EXTERNAL_PLUGIN:case e.ClearSignContextType.SAFE:case e.ClearSignContextType.SIGNER:case e.ClearSignContextType.ACCOUNT_OWNERSHIP:return!1;default:{const n=t;throw new Error(`Unhandled context type ${String(n)}`)}}}_hasValidTransactionInfo(t){return t.find(n=>n.type===e.ClearSignContextType.TRANSACTION_INFO)?.certificate!==void 0}_supportsGenericParser(t,n){return new o.ApplicationChecker(t,n,new I.EthereumApplicationResolver).withMinVersionExclusive(N.MIN_ETH_APP_VERSION_FOR_GENERIC_PARSER).excludeDeviceModel(o.DeviceModelId.NANO_S).check()}_getContextPriority({type:t}){switch(t){case e.ClearSignContextType.PROXY_INFO:return 5;case e.ClearSignContextType.TRANSACTION_CHECK:case e.ClearSignContextType.GATED_SIGNING:return 10;case e.ClearSignContextType.DYNAMIC_NETWORK:case e.ClearSignContextType.DYNAMIC_NETWORK_ICON:return 30;case e.ClearSignContextType.TRANSACTION_INFO:return 50;case e.ClearSignContextType.PLUGIN:case e.ClearSignContextType.EXTERNAL_PLUGIN:case e.ClearSignContextType.TOKEN:case e.ClearSignContextType.NFT:case e.ClearSignContextType.TRUSTED_NAME:case e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:case e.ClearSignContextType.ENUM:return 70;case e.ClearSignContextType.SAFE:case e.ClearSignContextType.SIGNER:case e.ClearSignContextType.ACCOUNT_OWNERSHIP:return 90;default:{const n=t;throw new Error(`Unhandled context type for priority: ${String(n)}`)}}}}0&&(module.exports={BASE_CONTEXT_TYPES_FILTER,BuildBaseContexts,NESTED_CALLDATA_CONTEXT_TYPES_FILTER});
|
|
2
2
|
//# sourceMappingURL=BuildBaseContexts.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/app-binder/task/BuildBaseContexts.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n type ClearSignContext,\n type ClearSignContextSuccess,\n ClearSignContextType,\n type ContextModule,\n type TransactionSubset,\n} from \"@ledgerhq/context-module\";\nimport {\n ApplicationChecker,\n DeviceModelId,\n type DeviceSessionState,\n type InternalApi,\n isSuccessCommandResult,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { type GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\nimport { ClearSigningType } from \"@api/model/ClearSigningType\";\nimport { type TransactionOptions } from \"@api/model/TransactionOptions\";\nimport { GetChallengeCommand } from \"@internal/app-binder/command/GetChallengeCommand\";\nimport { EthereumApplicationResolver } from \"@internal/app-binder/EthereumApplicationResolver\";\nimport {\n MIN_ETH_APP_VERSION_FOR_GATED_SIGNING,\n MIN_ETH_APP_VERSION_FOR_GENERIC_PARSER,\n} from \"@internal/shared/EthAppVersions\";\n\nexport const NESTED_CALLDATA_CONTEXT_TYPES_FILTER: ClearSignContextType[] = [\n ClearSignContextType.TRUSTED_NAME,\n ClearSignContextType.TRANSACTION_INFO,\n ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n ClearSignContextType.ENUM,\n ClearSignContextType.PROXY_INFO,\n];\n\nexport const BASE_CONTEXT_TYPES_FILTER: ClearSignContextType[] = [\n ClearSignContextType.TRANSACTION_INFO,\n ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n ClearSignContextType.PROXY_INFO,\n ClearSignContextType.TRANSACTION_CHECK,\n ClearSignContextType.DYNAMIC_NETWORK,\n ClearSignContextType.DYNAMIC_NETWORK_ICON,\n ClearSignContextType.ENUM,\n ClearSignContextType.TRUSTED_NAME,\n ClearSignContextType.TOKEN,\n ClearSignContextType.NFT,\n ClearSignContextType.PLUGIN,\n ClearSignContextType.EXTERNAL_PLUGIN,\n ClearSignContextType.GATED_SIGNING,\n];\n\nexport type BuildBaseContextsResult = {\n readonly clearSignContexts: ClearSignContextSuccess[];\n readonly clearSignContextsOptional: ClearSignContextSuccess[];\n readonly clearSigningType: ClearSigningType;\n readonly contextErrorCount: number;\n};\n\nexport type BuildBaseContextsArgs = {\n readonly contextModule: ContextModule;\n readonly options: TransactionOptions;\n readonly appConfig: GetConfigCommandResponse;\n readonly subset: TransactionSubset;\n readonly transaction?: Uint8Array;\n};\n\n/**\n * Builds the base contexts for a transaction\n * @param api - The internal API\n * @param args - The arguments for the build\n *\n * returns the base contexts for a transaction, without subcontexts or nested call data contexts\n */\nexport class BuildBaseContexts {\n constructor(\n private readonly _api: InternalApi,\n private readonly _args: BuildBaseContextsArgs,\n ) {}\n\n async run(): Promise<BuildBaseContextsResult> {\n const { contextModule, appConfig, transaction, subset } = this._args;\n const isNestedCallData = transaction === undefined;\n // As only transaction checks needs the transaction, we don't need to send it if it's not needed\n const needTransaction = !isNestedCallData && appConfig.web3ChecksEnabled;\n\n const deviceState = this._api.getDeviceSessionState();\n\n // Get challenge (not supported on Nano S)\n let challenge: string | undefined = undefined;\n if (deviceState.deviceModelId !== DeviceModelId.NANO_S) {\n const challengeRes = await this._api.sendCommand(\n new GetChallengeCommand(),\n );\n if (isSuccessCommandResult(challengeRes)) {\n challenge = challengeRes.data.challenge;\n }\n }\n\n // Get the clear sign contexts\n const clearSignContexts: ClearSignContext[] =\n await contextModule.getContexts(\n {\n challenge: challenge,\n deviceModelId: deviceState.deviceModelId,\n transaction: needTransaction ? transaction : undefined,\n ...subset,\n },\n isNestedCallData\n ? NESTED_CALLDATA_CONTEXT_TYPES_FILTER\n : BASE_CONTEXT_TYPES_FILTER,\n );\n\n // filter out the error contexts\n const contextErrorCount = clearSignContexts.filter(\n (context) => context.type === ClearSignContextType.ERROR,\n ).length;\n const contextsSuccess: ClearSignContextSuccess[] = clearSignContexts.filter(\n (context) => context.type !== ClearSignContextType.ERROR,\n );\n\n // Remove gating contexts when app does not support them\n const supportsGatedSigning = new ApplicationChecker(\n deviceState,\n appConfig,\n new EthereumApplicationResolver(),\n )\n .withMinVersionInclusive(MIN_ETH_APP_VERSION_FOR_GATED_SIGNING)\n .excludeDeviceModel(DeviceModelId.NANO_S)\n .check();\n const contextsForSigning = supportsGatedSigning\n ? contextsSuccess\n : contextsSuccess.filter(\n (context) => context.type !== ClearSignContextType.GATED_SIGNING,\n );\n\n if (\n this._supportsGenericParser(deviceState, appConfig) &&\n this._hasValidTransactionInfo(contextsForSigning)\n ) {\n return this._getERC7730Contexts(contextsForSigning, contextErrorCount);\n } else {\n return this._getBasicContexts(contextsForSigning, contextErrorCount);\n }\n }\n\n private _getERC7730Contexts(\n contexts: ClearSignContextSuccess[],\n contextErrorCount: number,\n ): BuildBaseContextsResult {\n const clearSignContexts: ClearSignContextSuccess[] = contexts\n .filter((context) => this._isContextNeededForERC7730ClearSigning(context))\n .sort(\n (a, b) => this._getContextPriority(a) - this._getContextPriority(b),\n );\n\n const clearSignContextsOptional: ClearSignContextSuccess[] =\n contexts.filter((context) => context.type === ClearSignContextType.ENUM);\n\n return {\n clearSignContexts,\n clearSignContextsOptional,\n clearSigningType: ClearSigningType.EIP7730,\n contextErrorCount,\n };\n }\n\n private _getBasicContexts(\n contexts: ClearSignContextSuccess[],\n contextErrorCount: number,\n ): BuildBaseContextsResult {\n const clearSignContexts: ClearSignContextSuccess[] = contexts\n .filter((context) => this._isContextNeededForBasicClearSigning(context))\n .sort(\n (a, b) => this._getContextPriority(a) - this._getContextPriority(b),\n );\n\n return {\n clearSignContexts,\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n contextErrorCount,\n };\n }\n\n private _isContextNeededForBasicClearSigning({\n type,\n }: ClearSignContextSuccess): boolean {\n switch (type) {\n case ClearSignContextType.TRANSACTION_CHECK:\n case ClearSignContextType.PLUGIN:\n case ClearSignContextType.EXTERNAL_PLUGIN:\n case ClearSignContextType.DYNAMIC_NETWORK:\n case ClearSignContextType.DYNAMIC_NETWORK_ICON:\n case ClearSignContextType.TRUSTED_NAME:\n case ClearSignContextType.TOKEN:\n case ClearSignContextType.NFT:\n case ClearSignContextType.GATED_SIGNING:\n case ClearSignContextType.PROXY_INFO:\n return true;\n case ClearSignContextType.TRANSACTION_INFO:\n case ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:\n case ClearSignContextType.ENUM:\n case ClearSignContextType.SAFE:\n case ClearSignContextType.SIGNER:\n return false;\n default: {\n const uncoveredType: never = type;\n throw new Error(`Unhandled context type ${String(uncoveredType)}`);\n }\n }\n }\n\n private _isContextNeededForERC7730ClearSigning({\n type,\n }: ClearSignContextSuccess): boolean {\n switch (type) {\n case ClearSignContextType.TRANSACTION_INFO:\n case ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:\n case ClearSignContextType.PROXY_INFO:\n case ClearSignContextType.DYNAMIC_NETWORK:\n case ClearSignContextType.DYNAMIC_NETWORK_ICON:\n case ClearSignContextType.TRANSACTION_CHECK:\n case ClearSignContextType.GATED_SIGNING:\n return true;\n case ClearSignContextType.ENUM: // enum is needed but as optional\n case ClearSignContextType.TRUSTED_NAME:\n case ClearSignContextType.TOKEN:\n case ClearSignContextType.NFT:\n case ClearSignContextType.PLUGIN:\n case ClearSignContextType.EXTERNAL_PLUGIN:\n case ClearSignContextType.SAFE:\n case ClearSignContextType.SIGNER:\n return false;\n default: {\n const uncoveredType: never = type;\n throw new Error(`Unhandled context type ${String(uncoveredType)}`);\n }\n }\n }\n\n private _hasValidTransactionInfo(\n contexts: ClearSignContextSuccess[],\n ): boolean {\n return (\n contexts.find(\n (context) => context.type === ClearSignContextType.TRANSACTION_INFO,\n )?.certificate !== undefined\n );\n }\n\n private _supportsGenericParser(\n deviceState: DeviceSessionState,\n appConfig: GetConfigCommandResponse,\n ): boolean {\n return new ApplicationChecker(\n deviceState,\n appConfig,\n new EthereumApplicationResolver(),\n )\n .withMinVersionExclusive(MIN_ETH_APP_VERSION_FOR_GENERIC_PARSER)\n .excludeDeviceModel(DeviceModelId.NANO_S)\n .check();\n }\n\n /**\n * Determines the processing priority of a clear sign context.\n * Lower numbers indicate higher priority (processed first).\n *\n * @param context The clear sign context to get priority for\n * @returns Priority number (lower = higher priority)\n */\n private _getContextPriority({ type }: ClearSignContextSuccess): number {\n switch (type) {\n case ClearSignContextType.PROXY_INFO:\n return 5;\n case ClearSignContextType.TRANSACTION_CHECK:\n case ClearSignContextType.GATED_SIGNING:\n return 10;\n case ClearSignContextType.DYNAMIC_NETWORK:\n case ClearSignContextType.DYNAMIC_NETWORK_ICON:\n return 30;\n case ClearSignContextType.TRANSACTION_INFO:\n return 50;\n case ClearSignContextType.PLUGIN:\n case ClearSignContextType.EXTERNAL_PLUGIN:\n case ClearSignContextType.TOKEN:\n case ClearSignContextType.NFT:\n case ClearSignContextType.TRUSTED_NAME:\n case ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:\n case ClearSignContextType.ENUM:\n return 70;\n\n /* not used here */\n case ClearSignContextType.SAFE:\n case ClearSignContextType.SIGNER:\n return 90;\n\n default: {\n const uncoveredType: never = type;\n throw new Error(\n `Unhandled context type for priority: ${String(uncoveredType)}`,\n );\n }\n }\n }\n}\n"],
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,+BAAAE,EAAA,sBAAAC,EAAA,yCAAAC,IAAA,eAAAC,EAAAL,GAAA,IAAAM,EAMO,oCACPC,EAMO,2CAGPC,EAAiC,uCAEjCC,EAAoC,4DACpCC,EAA4C,4DAC5CC,EAGO,2CAEA,MAAMP,EAA+D,CAC1E,uBAAqB,aACrB,uBAAqB,iBACrB,uBAAqB,8BACrB,uBAAqB,KACrB,uBAAqB,UACvB,EAEaF,EAAoD,CAC/D,uBAAqB,iBACrB,uBAAqB,8BACrB,uBAAqB,WACrB,uBAAqB,kBACrB,uBAAqB,gBACrB,uBAAqB,qBACrB,uBAAqB,KACrB,uBAAqB,aACrB,uBAAqB,MACrB,uBAAqB,IACrB,uBAAqB,OACrB,uBAAqB,gBACrB,uBAAqB,aACvB,EAwBO,MAAMC,CAAkB,CAC7B,YACmBS,EACAC,EACjB,CAFiB,UAAAD,EACA,WAAAC,CAChB,CAEH,MAAM,KAAwC,CAC5C,KAAM,CAAE,cAAAC,EAAe,UAAAC,EAAW,YAAAC,EAAa,OAAAC,CAAO,EAAI,KAAK,MACzDC,EAAmBF,IAAgB,OAEnCG,EAAkB,CAACD,GAAoBH,EAAU,kBAEjDK,EAAc,KAAK,KAAK,sBAAsB,EAGpD,IAAIC,EACJ,GAAID,EAAY,gBAAkB,gBAAc,OAAQ,CACtD,MAAME,EAAe,MAAM,KAAK,KAAK,YACnC,IAAI,qBACN,KACI,0BAAuBA,CAAY,IACrCD,EAAYC,EAAa,KAAK,UAElC,CAGA,MAAMC,EACJ,MAAMT,EAAc,YAClB,CACE,UAAWO,EACX,cAAeD,EAAY,cAC3B,YAAaD,EAAkBH,EAAc,OAC7C,GAAGC,CACL,EACAC,EACId,EACAF,CACN,EAGIsB,EAAoBD,EAAkB,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K,uBAAqB,MAC1B,KAAK,uBAAqB,IAC1B,KAAK,uBAAqB,cAC1B,KAAK,uBAAqB,WACxB,MAAO,GACT,KAAK,uBAAqB,iBAC1B,KAAK,uBAAqB,8BAC1B,KAAK,uBAAqB,KAC1B,KAAK,uBAAqB,KAC1B,KAAK,uBAAqB,
|
|
4
|
+
"sourcesContent": ["import {\n type ClearSignContext,\n type ClearSignContextSuccess,\n ClearSignContextType,\n type ContextModule,\n type TransactionSubset,\n} from \"@ledgerhq/context-module\";\nimport {\n ApplicationChecker,\n DeviceModelId,\n type DeviceSessionState,\n type InternalApi,\n isSuccessCommandResult,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { type GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\nimport { ClearSigningType } from \"@api/model/ClearSigningType\";\nimport { type TransactionOptions } from \"@api/model/TransactionOptions\";\nimport { GetChallengeCommand } from \"@internal/app-binder/command/GetChallengeCommand\";\nimport { EthereumApplicationResolver } from \"@internal/app-binder/EthereumApplicationResolver\";\nimport {\n MIN_ETH_APP_VERSION_FOR_GATED_SIGNING,\n MIN_ETH_APP_VERSION_FOR_GENERIC_PARSER,\n} from \"@internal/shared/EthAppVersions\";\n\nexport const NESTED_CALLDATA_CONTEXT_TYPES_FILTER: ClearSignContextType[] = [\n ClearSignContextType.TRUSTED_NAME,\n ClearSignContextType.TRANSACTION_INFO,\n ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n ClearSignContextType.ENUM,\n ClearSignContextType.PROXY_INFO,\n];\n\nexport const BASE_CONTEXT_TYPES_FILTER: ClearSignContextType[] = [\n ClearSignContextType.TRANSACTION_INFO,\n ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n ClearSignContextType.PROXY_INFO,\n ClearSignContextType.TRANSACTION_CHECK,\n ClearSignContextType.DYNAMIC_NETWORK,\n ClearSignContextType.DYNAMIC_NETWORK_ICON,\n ClearSignContextType.ENUM,\n ClearSignContextType.TRUSTED_NAME,\n ClearSignContextType.TOKEN,\n ClearSignContextType.NFT,\n ClearSignContextType.PLUGIN,\n ClearSignContextType.EXTERNAL_PLUGIN,\n ClearSignContextType.GATED_SIGNING,\n];\n\nexport type BuildBaseContextsResult = {\n readonly clearSignContexts: ClearSignContextSuccess[];\n readonly clearSignContextsOptional: ClearSignContextSuccess[];\n readonly clearSigningType: ClearSigningType;\n readonly contextErrorCount: number;\n};\n\nexport type BuildBaseContextsArgs = {\n readonly contextModule: ContextModule;\n readonly options: TransactionOptions;\n readonly appConfig: GetConfigCommandResponse;\n readonly subset: TransactionSubset;\n readonly transaction?: Uint8Array;\n};\n\n/**\n * Builds the base contexts for a transaction\n * @param api - The internal API\n * @param args - The arguments for the build\n *\n * returns the base contexts for a transaction, without subcontexts or nested call data contexts\n */\nexport class BuildBaseContexts {\n constructor(\n private readonly _api: InternalApi,\n private readonly _args: BuildBaseContextsArgs,\n ) {}\n\n async run(): Promise<BuildBaseContextsResult> {\n const { contextModule, appConfig, transaction, subset } = this._args;\n const isNestedCallData = transaction === undefined;\n // As only transaction checks needs the transaction, we don't need to send it if it's not needed\n const needTransaction = !isNestedCallData && appConfig.web3ChecksEnabled;\n\n const deviceState = this._api.getDeviceSessionState();\n\n // Get challenge (not supported on Nano S)\n let challenge: string | undefined = undefined;\n if (deviceState.deviceModelId !== DeviceModelId.NANO_S) {\n const challengeRes = await this._api.sendCommand(\n new GetChallengeCommand(),\n );\n if (isSuccessCommandResult(challengeRes)) {\n challenge = challengeRes.data.challenge;\n }\n }\n\n // Get the clear sign contexts\n const clearSignContexts: ClearSignContext[] =\n await contextModule.getContexts(\n {\n challenge: challenge,\n deviceModelId: deviceState.deviceModelId,\n transaction: needTransaction ? transaction : undefined,\n ...subset,\n },\n isNestedCallData\n ? NESTED_CALLDATA_CONTEXT_TYPES_FILTER\n : BASE_CONTEXT_TYPES_FILTER,\n );\n\n // filter out the error contexts\n const contextErrorCount = clearSignContexts.filter(\n (context) => context.type === ClearSignContextType.ERROR,\n ).length;\n const contextsSuccess: ClearSignContextSuccess[] = clearSignContexts.filter(\n (context) => context.type !== ClearSignContextType.ERROR,\n );\n\n // Remove gating contexts when app does not support them\n const supportsGatedSigning = new ApplicationChecker(\n deviceState,\n appConfig,\n new EthereumApplicationResolver(),\n )\n .withMinVersionInclusive(MIN_ETH_APP_VERSION_FOR_GATED_SIGNING)\n .excludeDeviceModel(DeviceModelId.NANO_S)\n .check();\n const contextsForSigning = supportsGatedSigning\n ? contextsSuccess\n : contextsSuccess.filter(\n (context) => context.type !== ClearSignContextType.GATED_SIGNING,\n );\n\n if (\n this._supportsGenericParser(deviceState, appConfig) &&\n this._hasValidTransactionInfo(contextsForSigning)\n ) {\n return this._getERC7730Contexts(contextsForSigning, contextErrorCount);\n } else {\n return this._getBasicContexts(contextsForSigning, contextErrorCount);\n }\n }\n\n private _getERC7730Contexts(\n contexts: ClearSignContextSuccess[],\n contextErrorCount: number,\n ): BuildBaseContextsResult {\n const clearSignContexts: ClearSignContextSuccess[] = contexts\n .filter((context) => this._isContextNeededForERC7730ClearSigning(context))\n .sort(\n (a, b) => this._getContextPriority(a) - this._getContextPriority(b),\n );\n\n const clearSignContextsOptional: ClearSignContextSuccess[] =\n contexts.filter((context) => context.type === ClearSignContextType.ENUM);\n\n return {\n clearSignContexts,\n clearSignContextsOptional,\n clearSigningType: ClearSigningType.EIP7730,\n contextErrorCount,\n };\n }\n\n private _getBasicContexts(\n contexts: ClearSignContextSuccess[],\n contextErrorCount: number,\n ): BuildBaseContextsResult {\n const clearSignContexts: ClearSignContextSuccess[] = contexts\n .filter((context) => this._isContextNeededForBasicClearSigning(context))\n .sort(\n (a, b) => this._getContextPriority(a) - this._getContextPriority(b),\n );\n\n return {\n clearSignContexts,\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n contextErrorCount,\n };\n }\n\n private _isContextNeededForBasicClearSigning({\n type,\n }: ClearSignContextSuccess): boolean {\n switch (type) {\n case ClearSignContextType.TRANSACTION_CHECK:\n case ClearSignContextType.PLUGIN:\n case ClearSignContextType.EXTERNAL_PLUGIN:\n case ClearSignContextType.DYNAMIC_NETWORK:\n case ClearSignContextType.DYNAMIC_NETWORK_ICON:\n case ClearSignContextType.TRUSTED_NAME:\n case ClearSignContextType.TOKEN:\n case ClearSignContextType.NFT:\n case ClearSignContextType.GATED_SIGNING:\n case ClearSignContextType.PROXY_INFO:\n return true;\n case ClearSignContextType.TRANSACTION_INFO:\n case ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:\n case ClearSignContextType.ENUM:\n case ClearSignContextType.SAFE:\n case ClearSignContextType.SIGNER:\n case ClearSignContextType.ACCOUNT_OWNERSHIP:\n return false;\n default: {\n const uncoveredType: never = type;\n throw new Error(`Unhandled context type ${String(uncoveredType)}`);\n }\n }\n }\n\n private _isContextNeededForERC7730ClearSigning({\n type,\n }: ClearSignContextSuccess): boolean {\n switch (type) {\n case ClearSignContextType.TRANSACTION_INFO:\n case ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:\n case ClearSignContextType.PROXY_INFO:\n case ClearSignContextType.DYNAMIC_NETWORK:\n case ClearSignContextType.DYNAMIC_NETWORK_ICON:\n case ClearSignContextType.TRANSACTION_CHECK:\n case ClearSignContextType.GATED_SIGNING:\n return true;\n case ClearSignContextType.ENUM: // enum is needed but as optional\n case ClearSignContextType.TRUSTED_NAME:\n case ClearSignContextType.TOKEN:\n case ClearSignContextType.NFT:\n case ClearSignContextType.PLUGIN:\n case ClearSignContextType.EXTERNAL_PLUGIN:\n case ClearSignContextType.SAFE:\n case ClearSignContextType.SIGNER:\n case ClearSignContextType.ACCOUNT_OWNERSHIP:\n return false;\n default: {\n const uncoveredType: never = type;\n throw new Error(`Unhandled context type ${String(uncoveredType)}`);\n }\n }\n }\n\n private _hasValidTransactionInfo(\n contexts: ClearSignContextSuccess[],\n ): boolean {\n return (\n contexts.find(\n (context) => context.type === ClearSignContextType.TRANSACTION_INFO,\n )?.certificate !== undefined\n );\n }\n\n private _supportsGenericParser(\n deviceState: DeviceSessionState,\n appConfig: GetConfigCommandResponse,\n ): boolean {\n return new ApplicationChecker(\n deviceState,\n appConfig,\n new EthereumApplicationResolver(),\n )\n .withMinVersionExclusive(MIN_ETH_APP_VERSION_FOR_GENERIC_PARSER)\n .excludeDeviceModel(DeviceModelId.NANO_S)\n .check();\n }\n\n /**\n * Determines the processing priority of a clear sign context.\n * Lower numbers indicate higher priority (processed first).\n *\n * @param context The clear sign context to get priority for\n * @returns Priority number (lower = higher priority)\n */\n private _getContextPriority({ type }: ClearSignContextSuccess): number {\n switch (type) {\n case ClearSignContextType.PROXY_INFO:\n return 5;\n case ClearSignContextType.TRANSACTION_CHECK:\n case ClearSignContextType.GATED_SIGNING:\n return 10;\n case ClearSignContextType.DYNAMIC_NETWORK:\n case ClearSignContextType.DYNAMIC_NETWORK_ICON:\n return 30;\n case ClearSignContextType.TRANSACTION_INFO:\n return 50;\n case ClearSignContextType.PLUGIN:\n case ClearSignContextType.EXTERNAL_PLUGIN:\n case ClearSignContextType.TOKEN:\n case ClearSignContextType.NFT:\n case ClearSignContextType.TRUSTED_NAME:\n case ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:\n case ClearSignContextType.ENUM:\n return 70;\n\n /* not used here */\n case ClearSignContextType.SAFE:\n case ClearSignContextType.SIGNER:\n case ClearSignContextType.ACCOUNT_OWNERSHIP:\n return 90;\n\n default: {\n const uncoveredType: never = type;\n throw new Error(\n `Unhandled context type for priority: ${String(uncoveredType)}`,\n );\n }\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,+BAAAE,EAAA,sBAAAC,EAAA,yCAAAC,IAAA,eAAAC,EAAAL,GAAA,IAAAM,EAMO,oCACPC,EAMO,2CAGPC,EAAiC,uCAEjCC,EAAoC,4DACpCC,EAA4C,4DAC5CC,EAGO,2CAEA,MAAMP,EAA+D,CAC1E,uBAAqB,aACrB,uBAAqB,iBACrB,uBAAqB,8BACr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AMC,EAAuBD,EAC7B,MAAM,IAAI,MACR,wCAAwC,OAAOC,CAAa,CAAC,EAC/D,CACF,CACF,CACF,CACF",
|
|
6
6
|
"names": ["BuildBaseContexts_exports", "__export", "BASE_CONTEXT_TYPES_FILTER", "BuildBaseContexts", "NESTED_CALLDATA_CONTEXT_TYPES_FILTER", "__toCommonJS", "import_context_module", "import_device_management_kit", "import_ClearSigningType", "import_GetChallengeCommand", "import_EthereumApplicationResolver", "import_EthAppVersions", "_api", "_args", "contextModule", "appConfig", "transaction", "subset", "isNestedCallData", "needTransaction", "deviceState", "challenge", "challengeRes", "clearSignContexts", "contextErrorCount", "context", "contextsSuccess", "contextsForSigning", "contexts", "a", "b", "clearSignContextsOptional", "type", "uncoveredType"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var x=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var h=(r,e)=>{for(var n in e)x(r,n,{get:e[n],enumerable:!0})},S=(r,e,n,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of C(e))!b.call(r,a)&&a!==n&&x(r,a,{get:()=>e[a],enumerable:!(s=g(e,a))||s.enumerable});return r};var p=r=>S(x({},"__esModule",{value:!0}),r);var
|
|
1
|
+
"use strict";var x=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var h=(r,e)=>{for(var n in e)x(r,n,{get:e[n],enumerable:!0})},S=(r,e,n,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of C(e))!b.call(r,a)&&a!==n&&x(r,a,{get:()=>e[a],enumerable:!(s=g(e,a))||s.enumerable});return r};var p=r=>S(x({},"__esModule",{value:!0}),r);var R={};h(R,{BuildSubcontextsTask:()=>T});module.exports=p(R);var t=require("@ledgerhq/context-module"),o=require("@ledgerhq/device-management-kit"),u=require("../../app-binder/command/GetChallengeCommand");class T{constructor(e,n){this.api=e;this.args=n}run(){const e=this.args.context,n=e.type;switch(n){case t.ClearSignContextType.TRANSACTION_CHECK:case t.ClearSignContextType.TRANSACTION_INFO:case t.ClearSignContextType.PLUGIN:case t.ClearSignContextType.EXTERNAL_PLUGIN:case t.ClearSignContextType.DYNAMIC_NETWORK:case t.ClearSignContextType.DYNAMIC_NETWORK_ICON:case t.ClearSignContextType.ENUM:case t.ClearSignContextType.TOKEN:case t.ClearSignContextType.NFT:case t.ClearSignContextType.SAFE:case t.ClearSignContextType.SIGNER:case t.ClearSignContextType.GATED_SIGNING:case t.ClearSignContextType.ACCOUNT_OWNERSHIP:return{subcontextCallbacks:[]};case t.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:return{subcontextCallbacks:e.reference?this._getSubcontextsFromReference(e.reference):[]};case t.ClearSignContextType.PROXY_INFO:return{subcontextCallbacks:this._getSubcontextFromProxy(e)};case t.ClearSignContextType.TRUSTED_NAME:return{subcontextCallbacks:this._getSubcontextFromTrustedName(e)};default:{const s=n;throw new Error(`Uncovered type: ${s}`)}}}_getSubcontextsFromReference(e){const n=e.type;switch(n){case t.ClearSignContextReferenceType.TOKEN:case t.ClearSignContextReferenceType.NFT:return this._getSubcontextsFromTokenOrNftReference(e);case t.ClearSignContextReferenceType.ENUM:return this._getSubcontextsFromEnumReference(e);case t.ClearSignContextReferenceType.TRUSTED_NAME:return this._getSubcontextsFromTrustedNameReference(e);case t.ClearSignContextReferenceType.CALLDATA:return[];default:{const s=n;throw new Error(`Uncovered reference type: ${s}`)}}}_getSubcontextsFromTokenOrNftReference(e){if(e.value!==void 0){const s={chainId:this.args.subset.chainId,address:e.value,deviceModelId:this.args.deviceModelId},a=e.type===t.ClearSignContextReferenceType.TOKEN?t.ClearSignContextType.TOKEN:t.ClearSignContextType.NFT;return[()=>this.args.contextModule.getFieldContext(s,a)]}const n=[];if(e.valuePath!==void 0){const s=this.args.transactionParser.extractValue(this.args.subset,e.valuePath).orDefault([]);for(const a of s){const c=(0,o.bufferToHexaString)(a.slice(Math.max(0,a.length-20))),l=e.type===t.ClearSignContextReferenceType.TOKEN?t.ClearSignContextType.TOKEN:t.ClearSignContextType.NFT;n.push(()=>this.args.contextModule.getFieldContext({chainId:this.args.subset.chainId,address:c,deviceModelId:this.args.deviceModelId},l))}}return n}_getSubcontextsFromEnumReference(e){const n=[];if(!e.valuePath)return n;const s=this.args.transactionParser.extractValue(this.args.subset,e.valuePath).orDefault([]);for(const a of s){const c=a[a.length-1];if(c===void 0)continue;const d=this.args.contextOptional.filter(i=>i.type===t.ClearSignContextType.ENUM).find(i=>i.value===c&&i.id===e.id);d&&n.push(()=>Promise.resolve(d))}return n}_getSubcontextsFromTrustedNameReference(e){const n=[];if(!e.valuePath)return n;const s=this.args.transactionParser.extractValue(this.args.subset,e.valuePath).orDefault([]);for(const a of s)n.push(async()=>{const c=(0,o.bufferToHexaString)(a.slice(Math.max(0,a.length-20))),l=await this.api.sendCommand(new u.GetChallengeCommand);return(0,o.isSuccessCommandResult)(l)?await this.args.contextModule.getFieldContext({chainId:this.args.subset.chainId,address:c,challenge:l.data.challenge,types:e.types,sources:e.sources,deviceModelId:this.args.deviceModelId},t.ClearSignContextType.TRUSTED_NAME):{type:t.ClearSignContextType.ERROR,error:new Error("Failed to get challenge")}});return n}_getSubcontextFromTrustedName(e){return[async()=>{const n=await this.api.sendCommand(new u.GetChallengeCommand);return(0,o.isSuccessCommandResult)(n)?await this.args.contextModule.getFieldContext({chainId:this.args.subset.chainId,address:this.args.subset.to,challenge:n.data.challenge,types:["eoa"],sources:["ens"],deviceModelId:this.args.deviceModelId},t.ClearSignContextType.TRUSTED_NAME):{type:t.ClearSignContextType.ERROR,error:new Error("Failed to get challenge")}}]}_getSubcontextFromProxy(e){return[async()=>{const n=await this.api.sendCommand(new u.GetChallengeCommand);return(0,o.isSuccessCommandResult)(n)?this.args.subset.to===void 0?{type:t.ClearSignContextType.ERROR,error:new Error("Failed to get proxy address")}:await this.args.contextModule.getFieldContext({chainId:this.args.subset.chainId,proxyAddress:this.args.subset.to,calldata:this.args.subset.data,deviceModelId:this.args.deviceModelId,challenge:n.data.challenge},t.ClearSignContextType.PROXY_INFO):{type:t.ClearSignContextType.ERROR,error:new Error("Failed to get challenge")}}]}}0&&(module.exports={BuildSubcontextsTask});
|
|
2
2
|
//# sourceMappingURL=BuildSubcontextsTask.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/app-binder/task/BuildSubcontextsTask.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n type ClearSignContext,\n type ClearSignContextReference,\n ClearSignContextReferenceType,\n type ClearSignContextSuccess,\n ClearSignContextType,\n type ContextModule,\n type TransactionSubset,\n} from \"@ledgerhq/context-module\";\nimport {\n bufferToHexaString,\n type DeviceModelId,\n type InternalApi,\n isSuccessCommandResult,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { GetChallengeCommand } from \"@internal/app-binder/command/GetChallengeCommand\";\nimport { type TransactionParserService } from \"@internal/transaction/service/parser/TransactionParserService\";\n\nexport type BuildSubcontextsTaskArgs = {\n readonly context: ClearSignContextSuccess;\n readonly contextOptional: ClearSignContextSuccess[];\n readonly transactionParser: TransactionParserService;\n readonly subset: TransactionSubset;\n readonly deviceModelId: DeviceModelId;\n readonly contextModule: ContextModule;\n};\n\ntype SubcontextCallback = () => Promise<ClearSignContext>;\n\nexport type BuildSubcontextsTaskResult = {\n subcontextCallbacks: SubcontextCallback[];\n};\n\nexport class BuildSubcontextsTask {\n constructor(\n private readonly api: InternalApi,\n private readonly args: BuildSubcontextsTaskArgs,\n ) {}\n\n run(): BuildSubcontextsTaskResult {\n const context = this.args.context;\n const type = context.type;\n\n switch (type) {\n case ClearSignContextType.TRANSACTION_CHECK:\n case ClearSignContextType.TRANSACTION_INFO:\n case ClearSignContextType.PLUGIN:\n case ClearSignContextType.EXTERNAL_PLUGIN:\n case ClearSignContextType.DYNAMIC_NETWORK:\n case ClearSignContextType.DYNAMIC_NETWORK_ICON:\n case ClearSignContextType.ENUM:\n case ClearSignContextType.TOKEN:\n case ClearSignContextType.NFT:\n case ClearSignContextType.SAFE:\n case ClearSignContextType.SIGNER:\n case ClearSignContextType.GATED_SIGNING:\n return {\n subcontextCallbacks: [],\n };\n case ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:\n return {\n subcontextCallbacks: context.reference\n ? this._getSubcontextsFromReference(context.reference)\n : [],\n };\n case ClearSignContextType.PROXY_INFO:\n return {\n subcontextCallbacks: this._getSubcontextFromProxy(context),\n };\n case ClearSignContextType.TRUSTED_NAME:\n return {\n subcontextCallbacks: this._getSubcontextFromTrustedName(context),\n };\n default: {\n const uncoveredType: never = type;\n throw new Error(`Uncovered type: ${uncoveredType}`);\n }\n }\n }\n\n private _getSubcontextsFromReference(\n reference: ClearSignContextReference,\n ): SubcontextCallback[] {\n const referenceType = reference.type;\n\n switch (referenceType) {\n case ClearSignContextReferenceType.TOKEN:\n case ClearSignContextReferenceType.NFT:\n return this._getSubcontextsFromTokenOrNftReference(reference);\n case ClearSignContextReferenceType.ENUM:\n return this._getSubcontextsFromEnumReference(reference);\n case ClearSignContextReferenceType.TRUSTED_NAME:\n return this._getSubcontextsFromTrustedNameReference(reference);\n case ClearSignContextReferenceType.CALLDATA:\n // calldata reference is handled by the BuildFullContextsTask and ParseNestedTransactionTask\n return [];\n default: {\n const uncoveredReferenceType: never = referenceType;\n throw new Error(`Uncovered reference type: ${uncoveredReferenceType}`);\n }\n }\n }\n\n private _getSubcontextsFromTokenOrNftReference(\n reference: ClearSignContextReference<\n ClearSignContextReferenceType.TOKEN | ClearSignContextReferenceType.NFT\n >,\n ): SubcontextCallback[] {\n // if the reference is a string, it means it is a direct address\n // and we don't need to extract the value from the transaction\n // as it is already provided in the reference\n if (reference.value !== undefined) {\n const transactionFieldContext = {\n chainId: this.args.subset.chainId,\n address: reference.value,\n deviceModelId: this.args.deviceModelId,\n };\n\n const expectedType =\n reference.type === ClearSignContextReferenceType.TOKEN\n ? ClearSignContextType.TOKEN\n : ClearSignContextType.NFT;\n\n return [\n () =>\n this.args.contextModule.getFieldContext(\n transactionFieldContext,\n expectedType,\n ),\n ];\n }\n\n const subcontextCallbacks: SubcontextCallback[] = [];\n\n // if the reference is a path, it means we need to extract the value\n // from the transaction and provide it to the device\n if (reference.valuePath !== undefined) {\n const referenceValues = this.args.transactionParser\n .extractValue(this.args.subset, reference.valuePath)\n .orDefault([]);\n\n for (const value of referenceValues) {\n const address = bufferToHexaString(\n value.slice(Math.max(0, value.length - 20)),\n );\n\n const expectedType =\n reference.type === ClearSignContextReferenceType.TOKEN\n ? ClearSignContextType.TOKEN\n : ClearSignContextType.NFT;\n\n subcontextCallbacks.push(() =>\n this.args.contextModule.getFieldContext(\n {\n chainId: this.args.subset.chainId,\n address,\n deviceModelId: this.args.deviceModelId,\n },\n expectedType,\n ),\n );\n }\n }\n\n return subcontextCallbacks;\n }\n\n private _getSubcontextsFromEnumReference(\n reference: ClearSignContextReference<ClearSignContextReferenceType.ENUM>,\n ): SubcontextCallback[] {\n const subcontextCallbacks: SubcontextCallback[] = [];\n\n if (!reference.valuePath) {\n return subcontextCallbacks;\n }\n\n const referenceValues = this.args.transactionParser\n .extractValue(this.args.subset, reference.valuePath)\n .orDefault([]);\n\n for (const value of referenceValues) {\n const enumValue = value[value.length - 1];\n if (enumValue === undefined) {\n continue;\n }\n\n const enumsContext = this.args.contextOptional.filter(\n (c) => c.type === ClearSignContextType.ENUM,\n );\n\n const subcontext = enumsContext.find(\n (enumContext) =>\n enumContext.value === enumValue && enumContext.id === reference.id,\n );\n\n if (subcontext) {\n subcontextCallbacks.push(() => Promise.resolve(subcontext));\n }\n }\n return subcontextCallbacks;\n }\n\n private _getSubcontextsFromTrustedNameReference(\n reference: ClearSignContextReference<ClearSignContextReferenceType.TRUSTED_NAME>,\n ): SubcontextCallback[] {\n const subcontextCallbacks: SubcontextCallback[] = [];\n\n if (!reference.valuePath) {\n return subcontextCallbacks;\n }\n\n const referenceValues = this.args.transactionParser\n .extractValue(this.args.subset, reference.valuePath)\n .orDefault([]);\n\n for (const value of referenceValues) {\n {\n subcontextCallbacks.push(async () => {\n const address = bufferToHexaString(\n value.slice(Math.max(0, value.length - 20)),\n );\n\n const getChallengeResult = await this.api.sendCommand(\n new GetChallengeCommand(),\n );\n if (!isSuccessCommandResult(getChallengeResult)) {\n return {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Failed to get challenge\"),\n };\n }\n\n const subcontext = await this.args.contextModule.getFieldContext(\n {\n chainId: this.args.subset.chainId,\n address,\n challenge: getChallengeResult.data.challenge,\n types: reference.types,\n sources: reference.sources,\n deviceModelId: this.args.deviceModelId,\n },\n ClearSignContextType.TRUSTED_NAME,\n );\n\n return subcontext;\n });\n }\n }\n\n return subcontextCallbacks;\n }\n\n private _getSubcontextFromTrustedName(\n _context: ClearSignContextSuccess<ClearSignContextType.TRUSTED_NAME>,\n ): SubcontextCallback[] {\n return [\n async () => {\n const getChallengeResult = await this.api.sendCommand(\n new GetChallengeCommand(),\n );\n if (!isSuccessCommandResult(getChallengeResult)) {\n return {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Failed to get challenge\"),\n };\n }\n\n const subcontext = await this.args.contextModule.getFieldContext(\n {\n chainId: this.args.subset.chainId,\n address: this.args.subset.to,\n challenge: getChallengeResult.data.challenge,\n types: [\"eoa\"],\n sources: [\"ens\"],\n deviceModelId: this.args.deviceModelId,\n },\n ClearSignContextType.TRUSTED_NAME,\n );\n\n return subcontext;\n },\n ];\n }\n\n private _getSubcontextFromProxy(\n _context: ClearSignContextSuccess<ClearSignContextType.PROXY_INFO>,\n ): SubcontextCallback[] {\n return [\n async () => {\n const getChallengeResult = await this.api.sendCommand(\n new GetChallengeCommand(),\n );\n if (!isSuccessCommandResult(getChallengeResult)) {\n return {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Failed to get challenge\"),\n };\n }\n\n if (this.args.subset.to === undefined) {\n return {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Failed to get proxy address\"),\n };\n }\n\n const subcontext = await this.args.contextModule.getFieldContext(\n {\n chainId: this.args.subset.chainId,\n proxyAddress: this.args.subset.to,\n calldata: this.args.subset.data,\n deviceModelId: this.args.deviceModelId,\n challenge: getChallengeResult.data.challenge,\n },\n ClearSignContextType.PROXY_INFO,\n );\n\n return subcontext;\n },\n ];\n }\n}\n"],
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAQO,oCACPC,EAKO,2CAEPC,EAAoC,4DAkB7B,MAAMJ,CAAqB,CAChC,YACmBK,EACAC,EACjB,CAFiB,SAAAD,EACA,UAAAC,CAChB,CAEH,KAAkC,CAChC,MAAMC,EAAU,KAAK,KAAK,QACpBC,EAAOD,EAAQ,KAErB,OAAQC,EAAM,CACZ,KAAK,uBAAqB,kBAC1B,KAAK,uBAAqB,iBAC1B,KAAK,uBAAqB,OAC1B,KAAK,uBAAqB,gBAC1B,KAAK,uBAAqB,gBAC1B,KAAK,uBAAqB,qBAC1B,KAAK,uBAAqB,KAC1B,KAAK,uBAAqB,MAC1B,KAAK,uBAAqB,IAC1B,KAAK,uBAAqB,KAC1B,KAAK,uBAAqB,OAC1B,KAAK,uBAAqB,
|
|
4
|
+
"sourcesContent": ["import {\n type ClearSignContext,\n type ClearSignContextReference,\n ClearSignContextReferenceType,\n type ClearSignContextSuccess,\n ClearSignContextType,\n type ContextModule,\n type TransactionSubset,\n} from \"@ledgerhq/context-module\";\nimport {\n bufferToHexaString,\n type DeviceModelId,\n type InternalApi,\n isSuccessCommandResult,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { GetChallengeCommand } from \"@internal/app-binder/command/GetChallengeCommand\";\nimport { type TransactionParserService } from \"@internal/transaction/service/parser/TransactionParserService\";\n\nexport type BuildSubcontextsTaskArgs = {\n readonly context: ClearSignContextSuccess;\n readonly contextOptional: ClearSignContextSuccess[];\n readonly transactionParser: TransactionParserService;\n readonly subset: TransactionSubset;\n readonly deviceModelId: DeviceModelId;\n readonly contextModule: ContextModule;\n};\n\ntype SubcontextCallback = () => Promise<ClearSignContext>;\n\nexport type BuildSubcontextsTaskResult = {\n subcontextCallbacks: SubcontextCallback[];\n};\n\nexport class BuildSubcontextsTask {\n constructor(\n private readonly api: InternalApi,\n private readonly args: BuildSubcontextsTaskArgs,\n ) {}\n\n run(): BuildSubcontextsTaskResult {\n const context = this.args.context;\n const type = context.type;\n\n switch (type) {\n case ClearSignContextType.TRANSACTION_CHECK:\n case ClearSignContextType.TRANSACTION_INFO:\n case ClearSignContextType.PLUGIN:\n case ClearSignContextType.EXTERNAL_PLUGIN:\n case ClearSignContextType.DYNAMIC_NETWORK:\n case ClearSignContextType.DYNAMIC_NETWORK_ICON:\n case ClearSignContextType.ENUM:\n case ClearSignContextType.TOKEN:\n case ClearSignContextType.NFT:\n case ClearSignContextType.SAFE:\n case ClearSignContextType.SIGNER:\n case ClearSignContextType.GATED_SIGNING:\n case ClearSignContextType.ACCOUNT_OWNERSHIP:\n return {\n subcontextCallbacks: [],\n };\n case ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:\n return {\n subcontextCallbacks: context.reference\n ? this._getSubcontextsFromReference(context.reference)\n : [],\n };\n case ClearSignContextType.PROXY_INFO:\n return {\n subcontextCallbacks: this._getSubcontextFromProxy(context),\n };\n case ClearSignContextType.TRUSTED_NAME:\n return {\n subcontextCallbacks: this._getSubcontextFromTrustedName(context),\n };\n default: {\n const uncoveredType: never = type;\n throw new Error(`Uncovered type: ${uncoveredType}`);\n }\n }\n }\n\n private _getSubcontextsFromReference(\n reference: ClearSignContextReference,\n ): SubcontextCallback[] {\n const referenceType = reference.type;\n\n switch (referenceType) {\n case ClearSignContextReferenceType.TOKEN:\n case ClearSignContextReferenceType.NFT:\n return this._getSubcontextsFromTokenOrNftReference(reference);\n case ClearSignContextReferenceType.ENUM:\n return this._getSubcontextsFromEnumReference(reference);\n case ClearSignContextReferenceType.TRUSTED_NAME:\n return this._getSubcontextsFromTrustedNameReference(reference);\n case ClearSignContextReferenceType.CALLDATA:\n // calldata reference is handled by the BuildFullContextsTask and ParseNestedTransactionTask\n return [];\n default: {\n const uncoveredReferenceType: never = referenceType;\n throw new Error(`Uncovered reference type: ${uncoveredReferenceType}`);\n }\n }\n }\n\n private _getSubcontextsFromTokenOrNftReference(\n reference: ClearSignContextReference<\n ClearSignContextReferenceType.TOKEN | ClearSignContextReferenceType.NFT\n >,\n ): SubcontextCallback[] {\n // if the reference is a string, it means it is a direct address\n // and we don't need to extract the value from the transaction\n // as it is already provided in the reference\n if (reference.value !== undefined) {\n const transactionFieldContext = {\n chainId: this.args.subset.chainId,\n address: reference.value,\n deviceModelId: this.args.deviceModelId,\n };\n\n const expectedType =\n reference.type === ClearSignContextReferenceType.TOKEN\n ? ClearSignContextType.TOKEN\n : ClearSignContextType.NFT;\n\n return [\n () =>\n this.args.contextModule.getFieldContext(\n transactionFieldContext,\n expectedType,\n ),\n ];\n }\n\n const subcontextCallbacks: SubcontextCallback[] = [];\n\n // if the reference is a path, it means we need to extract the value\n // from the transaction and provide it to the device\n if (reference.valuePath !== undefined) {\n const referenceValues = this.args.transactionParser\n .extractValue(this.args.subset, reference.valuePath)\n .orDefault([]);\n\n for (const value of referenceValues) {\n const address = bufferToHexaString(\n value.slice(Math.max(0, value.length - 20)),\n );\n\n const expectedType =\n reference.type === ClearSignContextReferenceType.TOKEN\n ? ClearSignContextType.TOKEN\n : ClearSignContextType.NFT;\n\n subcontextCallbacks.push(() =>\n this.args.contextModule.getFieldContext(\n {\n chainId: this.args.subset.chainId,\n address,\n deviceModelId: this.args.deviceModelId,\n },\n expectedType,\n ),\n );\n }\n }\n\n return subcontextCallbacks;\n }\n\n private _getSubcontextsFromEnumReference(\n reference: ClearSignContextReference<ClearSignContextReferenceType.ENUM>,\n ): SubcontextCallback[] {\n const subcontextCallbacks: SubcontextCallback[] = [];\n\n if (!reference.valuePath) {\n return subcontextCallbacks;\n }\n\n const referenceValues = this.args.transactionParser\n .extractValue(this.args.subset, reference.valuePath)\n .orDefault([]);\n\n for (const value of referenceValues) {\n const enumValue = value[value.length - 1];\n if (enumValue === undefined) {\n continue;\n }\n\n const enumsContext = this.args.contextOptional.filter(\n (c) => c.type === ClearSignContextType.ENUM,\n );\n\n const subcontext = enumsContext.find(\n (enumContext) =>\n enumContext.value === enumValue && enumContext.id === reference.id,\n );\n\n if (subcontext) {\n subcontextCallbacks.push(() => Promise.resolve(subcontext));\n }\n }\n return subcontextCallbacks;\n }\n\n private _getSubcontextsFromTrustedNameReference(\n reference: ClearSignContextReference<ClearSignContextReferenceType.TRUSTED_NAME>,\n ): SubcontextCallback[] {\n const subcontextCallbacks: SubcontextCallback[] = [];\n\n if (!reference.valuePath) {\n return subcontextCallbacks;\n }\n\n const referenceValues = this.args.transactionParser\n .extractValue(this.args.subset, reference.valuePath)\n .orDefault([]);\n\n for (const value of referenceValues) {\n {\n subcontextCallbacks.push(async () => {\n const address = bufferToHexaString(\n value.slice(Math.max(0, value.length - 20)),\n );\n\n const getChallengeResult = await this.api.sendCommand(\n new GetChallengeCommand(),\n );\n if (!isSuccessCommandResult(getChallengeResult)) {\n return {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Failed to get challenge\"),\n };\n }\n\n const subcontext = await this.args.contextModule.getFieldContext(\n {\n chainId: this.args.subset.chainId,\n address,\n challenge: getChallengeResult.data.challenge,\n types: reference.types,\n sources: reference.sources,\n deviceModelId: this.args.deviceModelId,\n },\n ClearSignContextType.TRUSTED_NAME,\n );\n\n return subcontext;\n });\n }\n }\n\n return subcontextCallbacks;\n }\n\n private _getSubcontextFromTrustedName(\n _context: ClearSignContextSuccess<ClearSignContextType.TRUSTED_NAME>,\n ): SubcontextCallback[] {\n return [\n async () => {\n const getChallengeResult = await this.api.sendCommand(\n new GetChallengeCommand(),\n );\n if (!isSuccessCommandResult(getChallengeResult)) {\n return {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Failed to get challenge\"),\n };\n }\n\n const subcontext = await this.args.contextModule.getFieldContext(\n {\n chainId: this.args.subset.chainId,\n address: this.args.subset.to,\n challenge: getChallengeResult.data.challenge,\n types: [\"eoa\"],\n sources: [\"ens\"],\n deviceModelId: this.args.deviceModelId,\n },\n ClearSignContextType.TRUSTED_NAME,\n );\n\n return subcontext;\n },\n ];\n }\n\n private _getSubcontextFromProxy(\n _context: ClearSignContextSuccess<ClearSignContextType.PROXY_INFO>,\n ): SubcontextCallback[] {\n return [\n async () => {\n const getChallengeResult = await this.api.sendCommand(\n new GetChallengeCommand(),\n );\n if (!isSuccessCommandResult(getChallengeResult)) {\n return {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Failed to get challenge\"),\n };\n }\n\n if (this.args.subset.to === undefined) {\n return {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Failed to get proxy address\"),\n };\n }\n\n const subcontext = await this.args.contextModule.getFieldContext(\n {\n chainId: this.args.subset.chainId,\n proxyAddress: this.args.subset.to,\n calldata: this.args.subset.data,\n deviceModelId: this.args.deviceModelId,\n challenge: getChallengeResult.data.challenge,\n },\n ClearSignContextType.PROXY_INFO,\n );\n\n return subcontext;\n },\n ];\n }\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAQO,oCACPC,EAKO,2CAEPC,EAAoC,4DAkB7B,MAAMJ,CAAqB,CAChC,YACmBK,EACAC,EACjB,CAFiB,SAAAD,EACA,UAAAC,CAChB,CAEH,KAAkC,CAChC,MAAMC,EAAU,KAAK,KAAK,QACpBC,EAAOD,EAAQ,KAErB,OAAQC,EAAM,CACZ,KAAK,uBAAqB,kBAC1B,KAAK,uBAAqB,iBAC1B,KAAK,uBAAqB,OAC1B,KAAK,uBAAqB,gBAC1B,KAAK,uBAAqB,gBAC1B,KAA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AK,OAAO,GAC/B,SAAU,KAAK,KAAK,OAAO,KAC3B,cAAe,KAAK,KAAK,cACzB,UAAWA,EAAmB,KAAK,SACrC,EACA,uBAAqB,UACvB,EAtBS,CACL,KAAM,uBAAqB,MAC3B,MAAO,IAAI,MAAM,yBAAyB,CAC5C,CAsBJ,CACF,CACF,CACF",
|
|
6
6
|
"names": ["BuildSubcontextsTask_exports", "__export", "BuildSubcontextsTask", "__toCommonJS", "import_context_module", "import_device_management_kit", "import_GetChallengeCommand", "api", "args", "context", "type", "uncoveredType", "reference", "referenceType", "uncoveredReferenceType", "transactionFieldContext", "expectedType", "subcontextCallbacks", "referenceValues", "value", "address", "enumValue", "subcontext", "c", "enumContext", "getChallengeResult", "_context"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var u=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var
|
|
1
|
+
"use strict";var u=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var w=(r,e)=>{for(var n in e)u(r,n,{get:e[n],enumerable:!0})},v=(r,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of N(e))!g.call(r,t)&&t!==n&&u(r,t,{get:()=>e[t],enumerable:!(o=f(e,t))||o.enumerable});return r};var S=r=>v(u({},"__esModule",{value:!0}),r);var A={};w(A,{ProvideContextTask:()=>E});module.exports=S(A);var a=require("@ledgerhq/context-module"),i=require("@ledgerhq/device-management-kit"),c=require("../../app-binder/command/ProvideEnumCommand"),h=require("../../app-binder/command/ProvideGatedSigningCommand"),s=require("../../app-binder/command/ProvideNetworkConfigurationCommand"),C=require("../../app-binder/command/ProvideNFTInformationCommand"),k=require("../../app-binder/command/ProvideProxyInfoCommand"),d=require("../../app-binder/command/ProvideSafeAccountCommand"),y=require("../../app-binder/command/ProvideTokenInformationCommand"),p=require("../../app-binder/command/ProvideTransactionFieldDescriptionCommand"),F=require("../../app-binder/command/ProvideTransactionInformationCommand"),T=require("../../app-binder/command/ProvideTrustedNameCommand"),l=require("../../app-binder/command/ProvideWeb3CheckCommand"),P=require("../../app-binder/command/SetExternalPluginCommand"),I=require("../../app-binder/command/SetPluginCommand"),_=require("./SendPayloadInChunksTask");class E{constructor(e,n,o=(t,m)=>new _.SendPayloadInChunksTask(t,m)){this._api=e;this._args=n;this._sendPayloadInChunksTaskFactory=o;this._logger=n.loggerFactory("ProvideContextTask")}_logger;async run(){const{type:e,payload:n,certificate:o}=this._args.context;switch(this._logger.debug("[run] Providing context",{data:{type:e,payloadLength:n.length,hasCertificate:!!o}}),o&&await this._api.sendCommand(new i.LoadCertificateCommand({keyUsage:o.keyUsageNumber,certificate:o.payload})),e){case a.ClearSignContextType.PLUGIN:return await this._api.sendCommand(new I.SetPluginCommand({payload:n}));case a.ClearSignContextType.EXTERNAL_PLUGIN:return await this._api.sendCommand(new P.SetExternalPluginCommand({payload:n}));case a.ClearSignContextType.NFT:return await this._api.sendCommand(new C.ProvideNFTInformationCommand({payload:n}));case a.ClearSignContextType.TOKEN:return await this._api.sendCommand(new y.ProvideTokenInformationCommand({payload:n}));case a.ClearSignContextType.TRANSACTION_INFO:return await this._sendPayloadInChunksTaskFactory(this._api,{payload:n,commandFactory:m=>new F.ProvideTransactionInformationCommand({data:m.chunkedData,isFirstChunk:m.isFirstChunk})}).run();case a.ClearSignContextType.TRUSTED_NAME:return this._sendPayloadInChunksTaskFactory(this._api,{payload:n,commandFactory:t=>new T.ProvideTrustedNameCommand({data:t.chunkedData,isFirstChunk:t.isFirstChunk})}).run();case a.ClearSignContextType.ENUM:return this._sendPayloadInChunksTaskFactory(this._api,{payload:n,commandFactory:t=>new c.ProvideEnumCommand({data:t.chunkedData,isFirstChunk:t.isFirstChunk})}).run();case a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:return this._sendPayloadInChunksTaskFactory(this._api,{payload:n,commandFactory:t=>new p.ProvideTransactionFieldDescriptionCommand({data:t.chunkedData,isFirstChunk:t.isFirstChunk})}).run();case a.ClearSignContextType.TRANSACTION_CHECK:return this._sendPayloadInChunksTaskFactory(this._api,{payload:n,commandFactory:t=>new l.ProvideWeb3CheckCommand({payload:t.chunkedData,isFirstChunk:t.isFirstChunk})}).run();case a.ClearSignContextType.PROXY_INFO:return this._sendPayloadInChunksTaskFactory(this._api,{payload:n,commandFactory:t=>new k.ProvideProxyInfoCommand({data:t.chunkedData,isFirstChunk:t.isFirstChunk})}).run();case a.ClearSignContextType.DYNAMIC_NETWORK:return this._sendPayloadInChunksTaskFactory(this._api,{payload:n,commandFactory:t=>new s.ProvideNetworkConfigurationCommand({data:t.chunkedData,isFirstChunk:t.isFirstChunk,configurationType:s.NetworkConfigurationType.CONFIGURATION})}).run();case a.ClearSignContextType.DYNAMIC_NETWORK_ICON:return this._sendPayloadInChunksTaskFactory(this._api,{payload:n,commandFactory:t=>new s.ProvideNetworkConfigurationCommand({data:t.chunkedData,isFirstChunk:t.isFirstChunk,configurationType:s.NetworkConfigurationType.ICON}),withPayloadLength:!1}).run();case a.ClearSignContextType.SAFE:return this._sendPayloadInChunksTaskFactory(this._api,{payload:n,commandFactory:t=>new d.ProvideSafeAccountCommand({data:t.chunkedData,isFirstChunk:t.isFirstChunk,type:d.ProvideSafeAccountCommandType.SAFE_DESCRIPTOR})}).run();case a.ClearSignContextType.SIGNER:return this._sendPayloadInChunksTaskFactory(this._api,{payload:n,commandFactory:t=>new d.ProvideSafeAccountCommand({data:t.chunkedData,isFirstChunk:t.isFirstChunk,type:d.ProvideSafeAccountCommandType.SIGNER_DESCRIPTOR})}).run();case a.ClearSignContextType.GATED_SIGNING:return this._sendPayloadInChunksTaskFactory(this._api,{payload:n,commandFactory:t=>new h.ProvideGatedSigningCommand({data:t.chunkedData,isFirstChunk:t.isFirstChunk})}).run();case a.ClearSignContextType.ACCOUNT_OWNERSHIP:return(0,i.CommandResultFactory)({error:new i.InvalidStatusWordError(`The context type [${e}] is not supported by the Ethereum signer`)});default:{const t=e;return(0,i.CommandResultFactory)({error:new i.InvalidStatusWordError(`The context type [${t}] is not covered`)})}}}}0&&(module.exports={ProvideContextTask});
|
|
2
2
|
//# sourceMappingURL=ProvideContextTask.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/app-binder/task/ProvideContextTask.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n type ClearSignContextSuccess,\n ClearSignContextType,\n} from \"@ledgerhq/context-module\";\nimport {\n type CommandResult,\n CommandResultFactory,\n type InternalApi,\n InvalidStatusWordError,\n LoadCertificateCommand,\n type LoggerPublisherService,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { ProvideEnumCommand } from \"@internal/app-binder/command/ProvideEnumCommand\";\nimport { ProvideGatedSigningCommand } from \"@internal/app-binder/command/ProvideGatedSigningCommand\";\nimport {\n NetworkConfigurationType,\n ProvideNetworkConfigurationCommand,\n} from \"@internal/app-binder/command/ProvideNetworkConfigurationCommand\";\nimport { ProvideNFTInformationCommand } from \"@internal/app-binder/command/ProvideNFTInformationCommand\";\nimport { ProvideProxyInfoCommand } from \"@internal/app-binder/command/ProvideProxyInfoCommand\";\nimport {\n ProvideSafeAccountCommand,\n ProvideSafeAccountCommandType,\n} from \"@internal/app-binder/command/ProvideSafeAccountCommand\";\nimport { ProvideTokenInformationCommand } from \"@internal/app-binder/command/ProvideTokenInformationCommand\";\nimport { ProvideTransactionFieldDescriptionCommand } from \"@internal/app-binder/command/ProvideTransactionFieldDescriptionCommand\";\nimport { ProvideTransactionInformationCommand } from \"@internal/app-binder/command/ProvideTransactionInformationCommand\";\nimport { ProvideTrustedNameCommand } from \"@internal/app-binder/command/ProvideTrustedNameCommand\";\nimport { ProvideWeb3CheckCommand } from \"@internal/app-binder/command/ProvideWeb3CheckCommand\";\nimport { SetExternalPluginCommand } from \"@internal/app-binder/command/SetExternalPluginCommand\";\nimport { SetPluginCommand } from \"@internal/app-binder/command/SetPluginCommand\";\nimport { type EthErrorCodes } from \"@internal/app-binder/command/utils/ethAppErrors\";\n\nimport {\n SendPayloadInChunksTask,\n type SendPayloadInChunksTaskArgs,\n} from \"./SendPayloadInChunksTask\";\n\nexport type ProvideContextTaskArgs = {\n /**\n * The clear sign context to provide.\n */\n context: ClearSignContextSuccess;\n /**\n * Logger factory for creating loggers with custom tags.\n */\n loggerFactory: (tag: string) => LoggerPublisherService;\n};\n\nexport type ProvideContextTaskResult = CommandResult<unknown, EthErrorCodes>;\n\n/**\n * This task is responsible for providing a single context to the device.\n */\nexport class ProvideContextTask {\n private readonly _logger: LoggerPublisherService;\n\n constructor(\n private _api: InternalApi,\n private _args: ProvideContextTaskArgs,\n private _sendPayloadInChunksTaskFactory = (\n api: InternalApi,\n args: SendPayloadInChunksTaskArgs<unknown>,\n ) => new SendPayloadInChunksTask(api, args),\n ) {\n this._logger = _args.loggerFactory(\"ProvideContextTask\");\n }\n\n async run(): Promise<ProvideContextTaskResult> {\n const { type, payload, certificate } = this._args.context;\n this._logger.debug(\"[run] Providing context\", {\n data: {\n type,\n payloadLength: payload.length,\n hasCertificate: !!certificate,\n },\n });\n\n // if a certificate is provided, we load it before sending the command\n if (certificate) {\n await this._api.sendCommand(\n new LoadCertificateCommand({\n keyUsage: certificate.keyUsageNumber,\n certificate: certificate.payload,\n }),\n );\n }\n\n switch (type) {\n case ClearSignContextType.PLUGIN: {\n return await this._api.sendCommand(new SetPluginCommand({ payload }));\n }\n case ClearSignContextType.EXTERNAL_PLUGIN: {\n return await this._api.sendCommand(\n new SetExternalPluginCommand({ payload }),\n );\n }\n case ClearSignContextType.NFT: {\n return await this._api.sendCommand(\n new ProvideNFTInformationCommand({ payload }),\n );\n }\n case ClearSignContextType.TOKEN: {\n return await this._api.sendCommand(\n new ProvideTokenInformationCommand({ payload }),\n );\n }\n case ClearSignContextType.TRANSACTION_INFO: {\n const transactionInfoResult =\n await this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideTransactionInformationCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n\n return transactionInfoResult;\n }\n case ClearSignContextType.TRUSTED_NAME: {\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideTrustedNameCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n }\n case ClearSignContextType.ENUM:\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideEnumCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n case ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideTransactionFieldDescriptionCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n case ClearSignContextType.TRANSACTION_CHECK:\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideWeb3CheckCommand({\n payload: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n case ClearSignContextType.PROXY_INFO:\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideProxyInfoCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n case ClearSignContextType.DYNAMIC_NETWORK:\n // Dynamic network configuration uses the existing ProvideNetworkConfiguration command\n // but is provided as part of the context flow\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideNetworkConfigurationCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n configurationType: NetworkConfigurationType.CONFIGURATION,\n }),\n }).run();\n case ClearSignContextType.DYNAMIC_NETWORK_ICON: {\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideNetworkConfigurationCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n configurationType: NetworkConfigurationType.ICON,\n }),\n withPayloadLength: false,\n }).run();\n }\n case ClearSignContextType.SAFE:\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideSafeAccountCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n type: ProvideSafeAccountCommandType.SAFE_DESCRIPTOR,\n }),\n }).run();\n case ClearSignContextType.SIGNER:\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideSafeAccountCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n type: ProvideSafeAccountCommandType.SIGNER_DESCRIPTOR,\n }),\n }).run();\n case ClearSignContextType.GATED_SIGNING:\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideGatedSigningCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n default: {\n const uncoveredType: never = type;\n return CommandResultFactory({\n error: new InvalidStatusWordError(\n `The context type [${uncoveredType}] is not covered`,\n ),\n });\n }\n }\n }\n}\n"],
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,wBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAGO,oCACPC,EAOO,2CAEPC,EAAmC,2DACnCC,EAA2C,mEAC3CC,EAGO,2EACPC,EAA6C,qEAC7CC,EAAwC,gEACxCC,EAGO,kEACPC,EAA+C,uEAC/CC,EAA0D,kFAC1DC,EAAqD,6EACrDC,EAA0C,kEAC1CC,EAAwC,gEACxCC,EAAyC,iEACzCC,EAAiC,yDAGjCC,EAGO,qCAkBA,MAAMjB,CAAmB,CAG9B,YACUkB,EACAC,EACAC,EAAkC,CACxCC,EACAC,IACG,IAAI,0BAAwBD,EAAKC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AC5B,KAAMA,EAAK,YACX,aAAcA,EAAK,aACnB,KAAM,gCAA8B,eACtC,CAAC,CACL,CAAC,EAAE,IAAI,EACT,KAAK,uBAAqB,OACxB,OAAO,KAAK,gCAAgC,KAAK,KAAM,CACrD,QAAAE,EACA,eAAiBF,GACf,IAAI,4BAA0B,CAC5B,KAAMA,EAAK,YACX,aAAcA,EAAK,aACnB,KAAM,gCAA8B,iBACtC,CAAC,CACL,CAAC,EAAE,IAAI,EACT,KAAK,uBAAqB,cACxB,OAAO,KAAK,gCAAgC,KAAK,KAAM,CACrD,QAAAE,EACA,eAAiBF,GACf,IAAI,6BAA2B,CAC7B,KAAMA,EAAK,YACX,aAAcA,EAAK,YACrB,CAAC,CACL,CAAC,EAAE,IAAI,EACT,QAAS,CACP,
|
|
4
|
+
"sourcesContent": ["import {\n type ClearSignContextSuccess,\n ClearSignContextType,\n} from \"@ledgerhq/context-module\";\nimport {\n type CommandResult,\n CommandResultFactory,\n type InternalApi,\n InvalidStatusWordError,\n LoadCertificateCommand,\n type LoggerPublisherService,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { ProvideEnumCommand } from \"@internal/app-binder/command/ProvideEnumCommand\";\nimport { ProvideGatedSigningCommand } from \"@internal/app-binder/command/ProvideGatedSigningCommand\";\nimport {\n NetworkConfigurationType,\n ProvideNetworkConfigurationCommand,\n} from \"@internal/app-binder/command/ProvideNetworkConfigurationCommand\";\nimport { ProvideNFTInformationCommand } from \"@internal/app-binder/command/ProvideNFTInformationCommand\";\nimport { ProvideProxyInfoCommand } from \"@internal/app-binder/command/ProvideProxyInfoCommand\";\nimport {\n ProvideSafeAccountCommand,\n ProvideSafeAccountCommandType,\n} from \"@internal/app-binder/command/ProvideSafeAccountCommand\";\nimport { ProvideTokenInformationCommand } from \"@internal/app-binder/command/ProvideTokenInformationCommand\";\nimport { ProvideTransactionFieldDescriptionCommand } from \"@internal/app-binder/command/ProvideTransactionFieldDescriptionCommand\";\nimport { ProvideTransactionInformationCommand } from \"@internal/app-binder/command/ProvideTransactionInformationCommand\";\nimport { ProvideTrustedNameCommand } from \"@internal/app-binder/command/ProvideTrustedNameCommand\";\nimport { ProvideWeb3CheckCommand } from \"@internal/app-binder/command/ProvideWeb3CheckCommand\";\nimport { SetExternalPluginCommand } from \"@internal/app-binder/command/SetExternalPluginCommand\";\nimport { SetPluginCommand } from \"@internal/app-binder/command/SetPluginCommand\";\nimport { type EthErrorCodes } from \"@internal/app-binder/command/utils/ethAppErrors\";\n\nimport {\n SendPayloadInChunksTask,\n type SendPayloadInChunksTaskArgs,\n} from \"./SendPayloadInChunksTask\";\n\nexport type ProvideContextTaskArgs = {\n /**\n * The clear sign context to provide.\n */\n context: ClearSignContextSuccess;\n /**\n * Logger factory for creating loggers with custom tags.\n */\n loggerFactory: (tag: string) => LoggerPublisherService;\n};\n\nexport type ProvideContextTaskResult = CommandResult<unknown, EthErrorCodes>;\n\n/**\n * This task is responsible for providing a single context to the device.\n */\nexport class ProvideContextTask {\n private readonly _logger: LoggerPublisherService;\n\n constructor(\n private _api: InternalApi,\n private _args: ProvideContextTaskArgs,\n private _sendPayloadInChunksTaskFactory = (\n api: InternalApi,\n args: SendPayloadInChunksTaskArgs<unknown>,\n ) => new SendPayloadInChunksTask(api, args),\n ) {\n this._logger = _args.loggerFactory(\"ProvideContextTask\");\n }\n\n async run(): Promise<ProvideContextTaskResult> {\n const { type, payload, certificate } = this._args.context;\n this._logger.debug(\"[run] Providing context\", {\n data: {\n type,\n payloadLength: payload.length,\n hasCertificate: !!certificate,\n },\n });\n\n // if a certificate is provided, we load it before sending the command\n if (certificate) {\n await this._api.sendCommand(\n new LoadCertificateCommand({\n keyUsage: certificate.keyUsageNumber,\n certificate: certificate.payload,\n }),\n );\n }\n\n switch (type) {\n case ClearSignContextType.PLUGIN: {\n return await this._api.sendCommand(new SetPluginCommand({ payload }));\n }\n case ClearSignContextType.EXTERNAL_PLUGIN: {\n return await this._api.sendCommand(\n new SetExternalPluginCommand({ payload }),\n );\n }\n case ClearSignContextType.NFT: {\n return await this._api.sendCommand(\n new ProvideNFTInformationCommand({ payload }),\n );\n }\n case ClearSignContextType.TOKEN: {\n return await this._api.sendCommand(\n new ProvideTokenInformationCommand({ payload }),\n );\n }\n case ClearSignContextType.TRANSACTION_INFO: {\n const transactionInfoResult =\n await this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideTransactionInformationCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n\n return transactionInfoResult;\n }\n case ClearSignContextType.TRUSTED_NAME: {\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideTrustedNameCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n }\n case ClearSignContextType.ENUM:\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideEnumCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n case ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideTransactionFieldDescriptionCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n case ClearSignContextType.TRANSACTION_CHECK:\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideWeb3CheckCommand({\n payload: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n case ClearSignContextType.PROXY_INFO:\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideProxyInfoCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n case ClearSignContextType.DYNAMIC_NETWORK:\n // Dynamic network configuration uses the existing ProvideNetworkConfiguration command\n // but is provided as part of the context flow\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideNetworkConfigurationCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n configurationType: NetworkConfigurationType.CONFIGURATION,\n }),\n }).run();\n case ClearSignContextType.DYNAMIC_NETWORK_ICON: {\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideNetworkConfigurationCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n configurationType: NetworkConfigurationType.ICON,\n }),\n withPayloadLength: false,\n }).run();\n }\n case ClearSignContextType.SAFE:\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideSafeAccountCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n type: ProvideSafeAccountCommandType.SAFE_DESCRIPTOR,\n }),\n }).run();\n case ClearSignContextType.SIGNER:\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideSafeAccountCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n type: ProvideSafeAccountCommandType.SIGNER_DESCRIPTOR,\n }),\n }).run();\n case ClearSignContextType.GATED_SIGNING:\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideGatedSigningCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n case ClearSignContextType.ACCOUNT_OWNERSHIP:\n return CommandResultFactory({\n error: new InvalidStatusWordError(\n `The context type [${type}] is not supported by the Ethereum signer`,\n ),\n });\n default: {\n const uncoveredType: never = type;\n return CommandResultFactory({\n error: new InvalidStatusWordError(\n `The context type [${uncoveredType}] is not covered`,\n ),\n });\n }\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,wBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAGO,oCACPC,EAOO,2CAEPC,EAAmC,2DAC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ACxB,OAAO,KAAK,gCAAgC,KAAK,KAAM,CACrD,QAAAE,EACA,eAAiBF,GACf,IAAI,qCAAmC,CACrC,KAAMA,EAAK,YACX,aAAcA,EAAK,aACnB,kBAAmB,2BAAyB,IAC9C,CAAC,EACH,kBAAmB,EACrB,CAAC,EAAE,IAAI,EAET,KAAK,uBAAqB,KACxB,OAAO,KAAK,gCAAgC,KAAK,KAAM,CACrD,QAAAE,EACA,eAAiBF,GACf,IAAI,4BAA0B,CAC5B,KAAMA,EAAK,YACX,aAAcA,EAAK,aACnB,KAAM,gCAA8B,eACtC,CAAC,CACL,CAAC,EAAE,IAAI,EACT,KAAK,uBAAqB,OACxB,OAAO,KAAK,gCAAgC,KAAK,KAAM,CACrD,QAAAE,EACA,eAAiBF,GACf,IAAI,4BAA0B,CAC5B,KAAMA,EAAK,YACX,aAAcA,EAAK,aACnB,KAAM,gCAA8B,iBACtC,CAAC,CACL,CAAC,EAAE,IAAI,EACT,KAAK,uBAAqB,cACxB,OAAO,KAAK,gCAAgC,KAAK,KAAM,CACrD,QAAAE,EACA,eAAiBF,GACf,IAAI,6BAA2B,CAC7B,KAAMA,EAAK,YACX,aAAcA,EAAK,YACrB,CAAC,CACL,CAAC,EAAE,IAAI,EACT,KAAK,uBAAqB,kBACxB,SAAO,wBAAqB,CAC1B,MAAO,IAAI,yBACT,qBAAqBC,CAAI,2CAC3B,CACF,CAAC,EACH,QAAS,CACP,MAAMG,EAAuBH,EAC7B,SAAO,wBAAqB,CAC1B,MAAO,IAAI,yBACT,qBAAqBG,CAAa,kBACpC,CACF,CAAC,CACH,CACF,CACF,CACF",
|
|
6
6
|
"names": ["ProvideContextTask_exports", "__export", "ProvideContextTask", "__toCommonJS", "import_context_module", "import_device_management_kit", "import_ProvideEnumCommand", "import_ProvideGatedSigningCommand", "import_ProvideNetworkConfigurationCommand", "import_ProvideNFTInformationCommand", "import_ProvideProxyInfoCommand", "import_ProvideSafeAccountCommand", "import_ProvideTokenInformationCommand", "import_ProvideTransactionFieldDescriptionCommand", "import_ProvideTransactionInformationCommand", "import_ProvideTrustedNameCommand", "import_ProvideWeb3CheckCommand", "import_SetExternalPluginCommand", "import_SetPluginCommand", "import_SendPayloadInChunksTask", "_api", "_args", "_sendPayloadInChunksTaskFactory", "api", "args", "type", "payload", "certificate", "uncoveredType"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var F=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var G=Object.prototype.hasOwnProperty;var L=(p,e)=>{for(var t in e)F(p,t,{get:e[t],enumerable:!0})},W=(p,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of J(e))!G.call(p,n)&&n!==t&&F(p,n,{get:()=>e[n],enumerable:!(a=U(e,n))||a.enumerable});return p};var X=p=>W(F({},"__esModule",{value:!0}),p);var K={};L(K,{ProvideEIP712ContextTask:()=>Y});module.exports=X(K);var u=require("@ledgerhq/context-module"),o=require("@ledgerhq/context-module"),r=require("@ledgerhq/device-management-kit"),d=require("purify-ts"),E=require("../../app-binder/command/GetChallengeCommand"),D=require("../../app-binder/command/ProvideGatedSigningCommand"),y=require("../../app-binder/command/ProvideNetworkConfigurationCommand"),R=require("../../app-binder/command/ProvideProxyInfoCommand"),A=require("../../app-binder/command/ProvideTokenInformationCommand"),b=require("../../app-binder/command/ProvideTrustedNameCommand"),M=require("../../app-binder/command/ProvideWeb3CheckCommand"),s=require("../../app-binder/command/SendEIP712FilteringCommand"),x=require("../../app-binder/command/SendEIP712StructDefinitionCommand"),w=require("../../app-binder/command/SendEIP712StructImplemCommand"),v=require("../../app-binder/task/SendEIP712StructImplemTask"),O=require("../../typed-data/model/Types"),T=require("../../typed-data/model/Types"),_=require("./ProvideTransactionContextsTask"),h=require("./SendPayloadInChunksTask");const N=5;class Y{constructor(e,t,a,n=m=>new _.ProvideTransactionContextsTask(this.api,m)){this.api=e;this.contextModule=t;this.args=a;this.provideContextFactory=n;for(const m of this.args.domain)if(m.path==="chainId"&&m.value instanceof O.TypedDataValueField){const l=BigInt((0,r.bufferToHexaString)(m.value.data));l<=Number.MAX_SAFE_INTEGER&&(this.chainId=(0,d.Just)(Number(l)));break}}chainId=d.Nothing;calldataMetadatas={};async run(){for(const i of this.args.additionalContexts)await this.provideContext(i);const e=this.args.additionalContexts.some(i=>i.type===o.ClearSignContextType.PROXY_INFO),t=this.args.clearSignContext.extract()?.proxy;t!==void 0&&!e&&await this.provideContext(t);const a=this.args.clearSignContext.extract()?.certificate;a!==void 0&&await this.api.sendCommand(new r.LoadCertificateCommand({keyUsage:a.keyUsageNumber,certificate:a.payload}));const n=(0,r.CommandResultFactory)({data:void 0}),m=Object.entries(this.args.types).sort(([i],[c])=>i.localeCompare(c));for(const[i,c]of m){const C=await this.api.sendCommand(new x.SendEIP712StructDefinitionCommand({command:x.StructDefinitionCommand.Name,name:i}));if(!(0,r.isSuccessCommandResult)(C))return C;for(const[f,k]of Object.entries(c)){const I=await this.api.sendCommand(new x.SendEIP712StructDefinitionCommand({command:x.StructDefinitionCommand.Field,name:f,type:k}));if(!(0,r.isSuccessCommandResult)(I))return I}}if(this.args.clearSignContext.isJust()){const i=await this.api.sendCommand(new s.SendEIP712FilteringCommand({type:s.Eip712FilterType.Activation}));if(!(0,r.isSuccessCommandResult)(i))return i}for(const i of this.args.domain){const C=await this.getImplementationTask(i).run();if(!(0,r.isSuccessCommandResult)(C))return C}if(this.args.clearSignContext.isJust()){const i=this.args.clearSignContext.extract(),c=await this.api.sendCommand(new s.SendEIP712FilteringCommand({type:s.Eip712FilterType.MessageInfo,displayName:i.messageInfo.displayName,filtersCount:i.messageInfo.filtersCount,signature:i.messageInfo.signature}));if(!(0,r.isSuccessCommandResult)(c))return c}const l={indexes:{},nextIndex:0};for(const i of this.args.message){const c=await this.provideTokenInformation(i,l);if(c.isJust())return c.extract();const C=await this.provideTrustedName(i);if(C.isJust())return C.extract();const f=await this.filterValue(i,l);if(f.isJust()&&!(0,r.isSuccessCommandResult)(f.extract()))return f.extract();const I=await this.getImplementationTask(i).run();if(!(0,r.isSuccessCommandResult)(I))return I;if(await this.tryProvideTransactionContext(),this.args.clearSignContext.isJust()&&i.value instanceof T.TypedDataValueArray&&i.value.length===0){const V=Object.entries(this.args.clearSignContext.extract().filters).filter(([g])=>g.startsWith(`${i.path}.[]`)).map(([,g])=>g);for(const g of V){const P=await this.api.sendCommand(new s.SendEIP712FilteringCommand({type:s.Eip712FilterType.DiscardedPath,path:g.path}));if(!(0,r.isSuccessCommandResult)(P))return P;const S=await this.provideFiltering(g,l,!0);if(!(0,r.isSuccessCommandResult)(S))return S}}}return n}async provideContext({type:e,payload:t,certificate:a}){switch(a&&await this.api.sendCommand(new r.LoadCertificateCommand({keyUsage:a.keyUsageNumber,certificate:a.payload})),e){case o.ClearSignContextType.TRANSACTION_CHECK:await new h.SendPayloadInChunksTask(this.api,{payload:t,commandFactory:n=>new M.ProvideWeb3CheckCommand({payload:n.chunkedData,isFirstChunk:n.isFirstChunk})}).run();break;case o.ClearSignContextType.DYNAMIC_NETWORK:await new h.SendPayloadInChunksTask(this.api,{payload:t,commandFactory:n=>new y.ProvideNetworkConfigurationCommand({data:n.chunkedData,isFirstChunk:n.isFirstChunk,configurationType:y.NetworkConfigurationType.CONFIGURATION})}).run();break;case o.ClearSignContextType.DYNAMIC_NETWORK_ICON:await new h.SendPayloadInChunksTask(this.api,{payload:t,commandFactory:n=>new y.ProvideNetworkConfigurationCommand({data:n.chunkedData,isFirstChunk:n.isFirstChunk,configurationType:y.NetworkConfigurationType.ICON}),withPayloadLength:!1}).run();break;case o.ClearSignContextType.PROXY_INFO:await new h.SendPayloadInChunksTask(this.api,{payload:t,commandFactory:n=>new R.ProvideProxyInfoCommand({data:n.chunkedData,isFirstChunk:n.isFirstChunk})}).run();break;case o.ClearSignContextType.GATED_SIGNING:await new h.SendPayloadInChunksTask(this.api,{payload:t,commandFactory:n=>new D.ProvideGatedSigningCommand({data:n.chunkedData,isFirstChunk:n.isFirstChunk})}).run();break;case o.ClearSignContextType.TOKEN:case o.ClearSignContextType.NFT:case o.ClearSignContextType.TRUSTED_NAME:case o.ClearSignContextType.PLUGIN:case o.ClearSignContextType.EXTERNAL_PLUGIN:case o.ClearSignContextType.ENUM:case o.ClearSignContextType.TRANSACTION_INFO:case o.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:case o.ClearSignContextType.SAFE:case o.ClearSignContextType.SIGNER:throw new Error(`Context type ${e} not supported in EIP712 messages`);default:{const n=e;throw new Error(`Unhandled context type ${n}`)}}}getImplementationTask(e){return e.value instanceof T.TypedDataValueRoot?new v.SendEIP712StructImplemTask(this.api,{type:w.StructImplemType.ROOT,value:e.value.root}):e.value instanceof T.TypedDataValueArray?new v.SendEIP712StructImplemTask(this.api,{type:w.StructImplemType.ARRAY,value:e.value.length}):new v.SendEIP712StructImplemTask(this.api,{type:w.StructImplemType.FIELD,value:e.value.data})}async provideTokenInformation(e,t){if(this.args.clearSignContext.isJust()){const a=this.args.clearSignContext.extract().filters[e.path];if(a!==void 0&&(a.type==="amount"||a.type==="token")&&t.indexes[a.tokenIndex]===void 0){const n=a.tokenIndex,l=this.args.clearSignContext.extract().tokens[n];if(l===void 0)return d.Nothing;const i=await this.api.sendCommand(new A.ProvideTokenInformationCommand({payload:l}));if(!(0,r.isSuccessCommandResult)(i))return d.Maybe.of(i);let{tokenIndex:c}=i.data;t.nextIndex=(c+1)%N,Number(n)===u.VERIFYING_CONTRACT_TOKEN_INDEX&&(c=u.VERIFYING_CONTRACT_TOKEN_INDEX),t.indexes[Number(n)]=c}}return d.Nothing}async provideTrustedName(e){if(this.args.clearSignContext.isJust()&&this.chainId.isJust()){const t=this.args.clearSignContext.extract(),a=t.filters[e.path],n=t.trustedNamesAddresses[e.path];if(a!==void 0&&a.type==="trusted-name"&&n!==void 0){const m=await this.api.sendCommand(new E.GetChallengeCommand);if(!(0,r.isSuccessCommandResult)(m))return(0,d.Just)(m);const l=await this.contextModule.getFieldContext({chainId:this.chainId.extract(),address:n,challenge:m.data.challenge,types:a.types,sources:a.sources,deviceModelId:this.args.deviceModelId},o.ClearSignContextType.TRUSTED_NAME);if(l.type===o.ClearSignContextType.TRUSTED_NAME){l.certificate&&await this.api.sendCommand(new r.LoadCertificateCommand({keyUsage:l.certificate.keyUsageNumber,certificate:l.certificate.payload}));const i=await new h.SendPayloadInChunksTask(this.api,{payload:l.payload,commandFactory:c=>new b.ProvideTrustedNameCommand({data:c.chunkedData,isFirstChunk:c.isFirstChunk})}).run();if(!(0,r.isSuccessCommandResult)(i))return(0,d.Just)(i)}}}return d.Nothing}async filterValue(e,t){if(this.args.clearSignContext.isJust()){const a=this.args.clearSignContext.extract().filters[e.path];if(a===void 0)return d.Nothing;const n=await this.provideFiltering(a,t,!1);return d.Maybe.of(n)}return d.Nothing}async provideFiltering(e,t,a){switch(e.type){case"trusted-name":return await this.api.sendCommand(new s.SendEIP712FilteringCommand({type:s.Eip712FilterType.TrustedName,discarded:a,displayName:e.displayName,typesAndSourcesPayload:e.typesAndSourcesPayload,signature:e.signature}));case"datetime":return await this.api.sendCommand(new s.SendEIP712FilteringCommand({type:s.Eip712FilterType.Datetime,discarded:a,displayName:e.displayName,signature:e.signature}));case"raw":return await this.api.sendCommand(new s.SendEIP712FilteringCommand({type:s.Eip712FilterType.Raw,discarded:a,displayName:e.displayName,signature:e.signature}));case"token":return this.sanitizeDeviceIndex(e.tokenIndex,t),await this.api.sendCommand(new s.SendEIP712FilteringCommand({type:s.Eip712FilterType.Token,discarded:a,tokenIndex:t.indexes[e.tokenIndex],signature:e.signature}));case"amount":return this.sanitizeDeviceIndex(e.tokenIndex,t),await this.api.sendCommand(new s.SendEIP712FilteringCommand({type:s.Eip712FilterType.Amount,discarded:a,displayName:e.displayName,tokenIndex:t.indexes[e.tokenIndex],signature:e.signature}));case"calldata-value":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new s.SendEIP712FilteringCommand({type:s.Eip712FilterType.CalldataValue,discarded:a,calldataIndex:e.calldataIndex,signature:e.signature}));case"calldata-callee":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new s.SendEIP712FilteringCommand({type:s.Eip712FilterType.CalldataCallee,discarded:a,calldataIndex:e.calldataIndex,signature:e.signature}));case"calldata-spender":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new s.SendEIP712FilteringCommand({type:s.Eip712FilterType.CalldataSpender,discarded:a,calldataIndex:e.calldataIndex,signature:e.signature}));case"calldata-chain-id":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new s.SendEIP712FilteringCommand({type:s.Eip712FilterType.CalldataChainId,discarded:a,calldataIndex:e.calldataIndex,signature:e.signature}));case"calldata-selector":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new s.SendEIP712FilteringCommand({type:s.Eip712FilterType.CalldataSelector,discarded:a,calldataIndex:e.calldataIndex,signature:e.signature}));case"calldata-amount":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new s.SendEIP712FilteringCommand({type:s.Eip712FilterType.CalldataAmount,discarded:a,calldataIndex:e.calldataIndex,signature:e.signature}));default:{const n=e;throw new Error(`ProvideEIP712ContextTask/provideFiltering - Unhandled filter ${n}`)}}}async provideCalldataInfos(e){if(this.args.clearSignContext.isJust()){if(this.calldataMetadatas[e]!==void 0)return this.calldataMetadatas[e].remainingFilters--,d.Nothing;const t=this.args.clearSignContext.extract().calldatas[e];if(t===void 0)return d.Nothing;const n=[t.filter.valueFlag,t.filter.calleeFlag===u.TypedDataCalldataParamPresence.Present,t.filter.chainIdFlag,t.filter.selectorFlag,t.filter.amountFlag,t.filter.spenderFlag===u.TypedDataCalldataParamPresence.Present].filter(l=>l).length,m=this.args.calldatasPreContexts[e];return m?.length&&await this.provideContextFactory({contexts:m,derivationPath:this.args.derivationPath,loggerFactory:this.args.loggerFactory}).run(),this.calldataMetadatas[e]={remainingFilters:n-1,postContexts:this.args.calldatasPostContexts[e]},d.Maybe.of(await this.api.sendCommand(new s.SendEIP712FilteringCommand({type:s.Eip712FilterType.CalldataInfo,discarded:!1,calldataIndex:e,valueFlag:t.filter.valueFlag,calleeFlag:this.mapCalldataPresence(t.filter.calleeFlag),chainIdFlag:t.filter.chainIdFlag,selectorFlag:t.filter.selectorFlag,amountFlag:t.filter.amountFlag,spenderFlag:this.mapCalldataPresence(t.filter.spenderFlag),signature:t.filter.signature})))}return d.Nothing}async tryProvideTransactionContext(){for(const e in this.calldataMetadatas){const t=this.calldataMetadatas[e];t.remainingFilters===0&&(t.postContexts?.length&&await this.provideContextFactory({contexts:t.postContexts,derivationPath:this.args.derivationPath,loggerFactory:this.args.loggerFactory}).run(),delete this.calldataMetadatas[e])}}mapCalldataPresence(e){switch(e){case u.TypedDataCalldataParamPresence.None:return s.CalldataParamPresence.None;case u.TypedDataCalldataParamPresence.Present:return s.CalldataParamPresence.Present;case u.TypedDataCalldataParamPresence.VerifyingContract:return s.CalldataParamPresence.VerifyingContract;default:{const t=e;throw new Error(`Unhandled presence ${t}`)}}}sanitizeDeviceIndex(e,t){t.indexes[e]===void 0&&(t.indexes[e]=t.nextIndex,t.nextIndex=(t.nextIndex+1)%N)}}0&&(module.exports={ProvideEIP712ContextTask});
|
|
1
|
+
"use strict";var F=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var G=Object.prototype.hasOwnProperty;var L=(p,e)=>{for(var t in e)F(p,t,{get:e[t],enumerable:!0})},W=(p,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of J(e))!G.call(p,n)&&n!==t&&F(p,n,{get:()=>e[n],enumerable:!(a=U(e,n))||a.enumerable});return p};var X=p=>W(F({},"__esModule",{value:!0}),p);var K={};L(K,{ProvideEIP712ContextTask:()=>Y});module.exports=X(K);var u=require("@ledgerhq/context-module"),o=require("@ledgerhq/context-module"),r=require("@ledgerhq/device-management-kit"),d=require("purify-ts"),E=require("../../app-binder/command/GetChallengeCommand"),R=require("../../app-binder/command/ProvideGatedSigningCommand"),y=require("../../app-binder/command/ProvideNetworkConfigurationCommand"),D=require("../../app-binder/command/ProvideProxyInfoCommand"),A=require("../../app-binder/command/ProvideTokenInformationCommand"),b=require("../../app-binder/command/ProvideTrustedNameCommand"),M=require("../../app-binder/command/ProvideWeb3CheckCommand"),s=require("../../app-binder/command/SendEIP712FilteringCommand"),x=require("../../app-binder/command/SendEIP712StructDefinitionCommand"),w=require("../../app-binder/command/SendEIP712StructImplemCommand"),v=require("../../app-binder/task/SendEIP712StructImplemTask"),O=require("../../typed-data/model/Types"),T=require("../../typed-data/model/Types"),_=require("./ProvideTransactionContextsTask"),h=require("./SendPayloadInChunksTask");const N=5;class Y{constructor(e,t,a,n=m=>new _.ProvideTransactionContextsTask(this.api,m)){this.api=e;this.contextModule=t;this.args=a;this.provideContextFactory=n;for(const m of this.args.domain)if(m.path==="chainId"&&m.value instanceof O.TypedDataValueField){const l=BigInt((0,r.bufferToHexaString)(m.value.data));l<=Number.MAX_SAFE_INTEGER&&(this.chainId=(0,d.Just)(Number(l)));break}}chainId=d.Nothing;calldataMetadatas={};async run(){for(const i of this.args.additionalContexts)await this.provideContext(i);const e=this.args.additionalContexts.some(i=>i.type===o.ClearSignContextType.PROXY_INFO),t=this.args.clearSignContext.extract()?.proxy;t!==void 0&&!e&&await this.provideContext(t);const a=this.args.clearSignContext.extract()?.certificate;a!==void 0&&await this.api.sendCommand(new r.LoadCertificateCommand({keyUsage:a.keyUsageNumber,certificate:a.payload}));const n=(0,r.CommandResultFactory)({data:void 0}),m=Object.entries(this.args.types).sort(([i],[c])=>i.localeCompare(c));for(const[i,c]of m){const C=await this.api.sendCommand(new x.SendEIP712StructDefinitionCommand({command:x.StructDefinitionCommand.Name,name:i}));if(!(0,r.isSuccessCommandResult)(C))return C;for(const[f,P]of Object.entries(c)){const I=await this.api.sendCommand(new x.SendEIP712StructDefinitionCommand({command:x.StructDefinitionCommand.Field,name:f,type:P}));if(!(0,r.isSuccessCommandResult)(I))return I}}if(this.args.clearSignContext.isJust()){const i=await this.api.sendCommand(new s.SendEIP712FilteringCommand({type:s.Eip712FilterType.Activation}));if(!(0,r.isSuccessCommandResult)(i))return i}for(const i of this.args.domain){const C=await this.getImplementationTask(i).run();if(!(0,r.isSuccessCommandResult)(C))return C}if(this.args.clearSignContext.isJust()){const i=this.args.clearSignContext.extract(),c=await this.api.sendCommand(new s.SendEIP712FilteringCommand({type:s.Eip712FilterType.MessageInfo,displayName:i.messageInfo.displayName,filtersCount:i.messageInfo.filtersCount,signature:i.messageInfo.signature}));if(!(0,r.isSuccessCommandResult)(c))return c}const l={indexes:{},nextIndex:0};for(const i of this.args.message){const c=await this.provideTokenInformation(i,l);if(c.isJust())return c.extract();const C=await this.provideTrustedName(i);if(C.isJust())return C.extract();const f=await this.filterValue(i,l);if(f.isJust()&&!(0,r.isSuccessCommandResult)(f.extract()))return f.extract();const I=await this.getImplementationTask(i).run();if(!(0,r.isSuccessCommandResult)(I))return I;if(await this.tryProvideTransactionContext(),this.args.clearSignContext.isJust()&&i.value instanceof T.TypedDataValueArray&&i.value.length===0){const V=Object.entries(this.args.clearSignContext.extract().filters).filter(([g])=>g.startsWith(`${i.path}.[]`)).map(([,g])=>g);for(const g of V){const S=await this.api.sendCommand(new s.SendEIP712FilteringCommand({type:s.Eip712FilterType.DiscardedPath,path:g.path}));if(!(0,r.isSuccessCommandResult)(S))return S;const k=await this.provideFiltering(g,l,!0);if(!(0,r.isSuccessCommandResult)(k))return k}}}return n}async provideContext({type:e,payload:t,certificate:a}){switch(a&&await this.api.sendCommand(new r.LoadCertificateCommand({keyUsage:a.keyUsageNumber,certificate:a.payload})),e){case o.ClearSignContextType.TRANSACTION_CHECK:await new h.SendPayloadInChunksTask(this.api,{payload:t,commandFactory:n=>new M.ProvideWeb3CheckCommand({payload:n.chunkedData,isFirstChunk:n.isFirstChunk})}).run();break;case o.ClearSignContextType.DYNAMIC_NETWORK:await new h.SendPayloadInChunksTask(this.api,{payload:t,commandFactory:n=>new y.ProvideNetworkConfigurationCommand({data:n.chunkedData,isFirstChunk:n.isFirstChunk,configurationType:y.NetworkConfigurationType.CONFIGURATION})}).run();break;case o.ClearSignContextType.DYNAMIC_NETWORK_ICON:await new h.SendPayloadInChunksTask(this.api,{payload:t,commandFactory:n=>new y.ProvideNetworkConfigurationCommand({data:n.chunkedData,isFirstChunk:n.isFirstChunk,configurationType:y.NetworkConfigurationType.ICON}),withPayloadLength:!1}).run();break;case o.ClearSignContextType.PROXY_INFO:await new h.SendPayloadInChunksTask(this.api,{payload:t,commandFactory:n=>new D.ProvideProxyInfoCommand({data:n.chunkedData,isFirstChunk:n.isFirstChunk})}).run();break;case o.ClearSignContextType.GATED_SIGNING:await new h.SendPayloadInChunksTask(this.api,{payload:t,commandFactory:n=>new R.ProvideGatedSigningCommand({data:n.chunkedData,isFirstChunk:n.isFirstChunk})}).run();break;case o.ClearSignContextType.TOKEN:case o.ClearSignContextType.NFT:case o.ClearSignContextType.TRUSTED_NAME:case o.ClearSignContextType.PLUGIN:case o.ClearSignContextType.EXTERNAL_PLUGIN:case o.ClearSignContextType.ENUM:case o.ClearSignContextType.TRANSACTION_INFO:case o.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:case o.ClearSignContextType.SAFE:case o.ClearSignContextType.SIGNER:case o.ClearSignContextType.ACCOUNT_OWNERSHIP:throw new Error(`Context type ${e} not supported in EIP712 messages`);default:{const n=e;throw new Error(`Unhandled context type ${n}`)}}}getImplementationTask(e){return e.value instanceof T.TypedDataValueRoot?new v.SendEIP712StructImplemTask(this.api,{type:w.StructImplemType.ROOT,value:e.value.root}):e.value instanceof T.TypedDataValueArray?new v.SendEIP712StructImplemTask(this.api,{type:w.StructImplemType.ARRAY,value:e.value.length}):new v.SendEIP712StructImplemTask(this.api,{type:w.StructImplemType.FIELD,value:e.value.data})}async provideTokenInformation(e,t){if(this.args.clearSignContext.isJust()){const a=this.args.clearSignContext.extract().filters[e.path];if(a!==void 0&&(a.type==="amount"||a.type==="token")&&t.indexes[a.tokenIndex]===void 0){const n=a.tokenIndex,l=this.args.clearSignContext.extract().tokens[n];if(l===void 0)return d.Nothing;const i=await this.api.sendCommand(new A.ProvideTokenInformationCommand({payload:l}));if(!(0,r.isSuccessCommandResult)(i))return d.Maybe.of(i);let{tokenIndex:c}=i.data;t.nextIndex=(c+1)%N,Number(n)===u.VERIFYING_CONTRACT_TOKEN_INDEX&&(c=u.VERIFYING_CONTRACT_TOKEN_INDEX),t.indexes[Number(n)]=c}}return d.Nothing}async provideTrustedName(e){if(this.args.clearSignContext.isJust()&&this.chainId.isJust()){const t=this.args.clearSignContext.extract(),a=t.filters[e.path],n=t.trustedNamesAddresses[e.path];if(a!==void 0&&a.type==="trusted-name"&&n!==void 0){const m=await this.api.sendCommand(new E.GetChallengeCommand);if(!(0,r.isSuccessCommandResult)(m))return(0,d.Just)(m);const l=await this.contextModule.getFieldContext({chainId:this.chainId.extract(),address:n,challenge:m.data.challenge,types:a.types,sources:a.sources,deviceModelId:this.args.deviceModelId},o.ClearSignContextType.TRUSTED_NAME);if(l.type===o.ClearSignContextType.TRUSTED_NAME){l.certificate&&await this.api.sendCommand(new r.LoadCertificateCommand({keyUsage:l.certificate.keyUsageNumber,certificate:l.certificate.payload}));const i=await new h.SendPayloadInChunksTask(this.api,{payload:l.payload,commandFactory:c=>new b.ProvideTrustedNameCommand({data:c.chunkedData,isFirstChunk:c.isFirstChunk})}).run();if(!(0,r.isSuccessCommandResult)(i))return(0,d.Just)(i)}}}return d.Nothing}async filterValue(e,t){if(this.args.clearSignContext.isJust()){const a=this.args.clearSignContext.extract().filters[e.path];if(a===void 0)return d.Nothing;const n=await this.provideFiltering(a,t,!1);return d.Maybe.of(n)}return d.Nothing}async provideFiltering(e,t,a){switch(e.type){case"trusted-name":return await this.api.sendCommand(new s.SendEIP712FilteringCommand({type:s.Eip712FilterType.TrustedName,discarded:a,displayName:e.displayName,typesAndSourcesPayload:e.typesAndSourcesPayload,signature:e.signature}));case"datetime":return await this.api.sendCommand(new s.SendEIP712FilteringCommand({type:s.Eip712FilterType.Datetime,discarded:a,displayName:e.displayName,signature:e.signature}));case"raw":return await this.api.sendCommand(new s.SendEIP712FilteringCommand({type:s.Eip712FilterType.Raw,discarded:a,displayName:e.displayName,signature:e.signature}));case"token":return this.sanitizeDeviceIndex(e.tokenIndex,t),await this.api.sendCommand(new s.SendEIP712FilteringCommand({type:s.Eip712FilterType.Token,discarded:a,tokenIndex:t.indexes[e.tokenIndex],signature:e.signature}));case"amount":return this.sanitizeDeviceIndex(e.tokenIndex,t),await this.api.sendCommand(new s.SendEIP712FilteringCommand({type:s.Eip712FilterType.Amount,discarded:a,displayName:e.displayName,tokenIndex:t.indexes[e.tokenIndex],signature:e.signature}));case"calldata-value":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new s.SendEIP712FilteringCommand({type:s.Eip712FilterType.CalldataValue,discarded:a,calldataIndex:e.calldataIndex,signature:e.signature}));case"calldata-callee":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new s.SendEIP712FilteringCommand({type:s.Eip712FilterType.CalldataCallee,discarded:a,calldataIndex:e.calldataIndex,signature:e.signature}));case"calldata-spender":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new s.SendEIP712FilteringCommand({type:s.Eip712FilterType.CalldataSpender,discarded:a,calldataIndex:e.calldataIndex,signature:e.signature}));case"calldata-chain-id":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new s.SendEIP712FilteringCommand({type:s.Eip712FilterType.CalldataChainId,discarded:a,calldataIndex:e.calldataIndex,signature:e.signature}));case"calldata-selector":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new s.SendEIP712FilteringCommand({type:s.Eip712FilterType.CalldataSelector,discarded:a,calldataIndex:e.calldataIndex,signature:e.signature}));case"calldata-amount":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new s.SendEIP712FilteringCommand({type:s.Eip712FilterType.CalldataAmount,discarded:a,calldataIndex:e.calldataIndex,signature:e.signature}));default:{const n=e;throw new Error(`ProvideEIP712ContextTask/provideFiltering - Unhandled filter ${n}`)}}}async provideCalldataInfos(e){if(this.args.clearSignContext.isJust()){if(this.calldataMetadatas[e]!==void 0)return this.calldataMetadatas[e].remainingFilters--,d.Nothing;const t=this.args.clearSignContext.extract().calldatas[e];if(t===void 0)return d.Nothing;const n=[t.filter.valueFlag,t.filter.calleeFlag===u.TypedDataCalldataParamPresence.Present,t.filter.chainIdFlag,t.filter.selectorFlag,t.filter.amountFlag,t.filter.spenderFlag===u.TypedDataCalldataParamPresence.Present].filter(l=>l).length,m=this.args.calldatasPreContexts[e];return m?.length&&await this.provideContextFactory({contexts:m,derivationPath:this.args.derivationPath,loggerFactory:this.args.loggerFactory}).run(),this.calldataMetadatas[e]={remainingFilters:n-1,postContexts:this.args.calldatasPostContexts[e]},d.Maybe.of(await this.api.sendCommand(new s.SendEIP712FilteringCommand({type:s.Eip712FilterType.CalldataInfo,discarded:!1,calldataIndex:e,valueFlag:t.filter.valueFlag,calleeFlag:this.mapCalldataPresence(t.filter.calleeFlag),chainIdFlag:t.filter.chainIdFlag,selectorFlag:t.filter.selectorFlag,amountFlag:t.filter.amountFlag,spenderFlag:this.mapCalldataPresence(t.filter.spenderFlag),signature:t.filter.signature})))}return d.Nothing}async tryProvideTransactionContext(){for(const e in this.calldataMetadatas){const t=this.calldataMetadatas[e];t.remainingFilters===0&&(t.postContexts?.length&&await this.provideContextFactory({contexts:t.postContexts,derivationPath:this.args.derivationPath,loggerFactory:this.args.loggerFactory}).run(),delete this.calldataMetadatas[e])}}mapCalldataPresence(e){switch(e){case u.TypedDataCalldataParamPresence.None:return s.CalldataParamPresence.None;case u.TypedDataCalldataParamPresence.Present:return s.CalldataParamPresence.Present;case u.TypedDataCalldataParamPresence.VerifyingContract:return s.CalldataParamPresence.VerifyingContract;default:{const t=e;throw new Error(`Unhandled presence ${t}`)}}}sanitizeDeviceIndex(e,t){t.indexes[e]===void 0&&(t.indexes[e]=t.nextIndex,t.nextIndex=(t.nextIndex+1)%N)}}0&&(module.exports={ProvideEIP712ContextTask});
|
|
2
2
|
//# sourceMappingURL=ProvideEIP712ContextTask.js.map
|