@ledgerhq/device-signer-kit-ethereum 0.0.0-multisig-20250910160951 → 0.0.0-multisig-2-20250922093851

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/lib/cjs/api/app-binder/SignTransactionDeviceActionTypes.js +1 -1
  2. package/lib/cjs/api/app-binder/SignTransactionDeviceActionTypes.js.map +2 -2
  3. package/lib/cjs/api/index.js +1 -1
  4. package/lib/cjs/api/index.js.map +3 -3
  5. package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js +1 -1
  6. package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js.map +3 -3
  7. package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js +1 -1
  8. package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js.map +3 -3
  9. package/lib/cjs/internal/app-binder/task/BuildBaseContexts.js +1 -1
  10. package/lib/cjs/internal/app-binder/task/BuildBaseContexts.js.map +3 -3
  11. package/lib/cjs/internal/app-binder/task/BuildBaseContexts.test.js +1 -1
  12. package/lib/cjs/internal/app-binder/task/BuildBaseContexts.test.js.map +2 -2
  13. package/lib/cjs/internal/app-binder/task/BuildFullContextsTask.js +1 -1
  14. package/lib/cjs/internal/app-binder/task/BuildFullContextsTask.js.map +2 -2
  15. package/lib/cjs/internal/app-binder/task/BuildFullContextsTask.test.js +1 -1
  16. package/lib/cjs/internal/app-binder/task/BuildFullContextsTask.test.js.map +2 -2
  17. package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.js +1 -1
  18. package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.js.map +3 -3
  19. package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.test.js +1 -1
  20. package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.test.js.map +3 -3
  21. package/lib/cjs/internal/app-binder/task/ProvideContextsTask.js +1 -1
  22. package/lib/cjs/internal/app-binder/task/ProvideContextsTask.js.map +2 -2
  23. package/lib/cjs/internal/app-binder/task/ProvideContextsTask.test.js +1 -1
  24. package/lib/cjs/internal/app-binder/task/ProvideContextsTask.test.js.map +2 -2
  25. package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.js +1 -1
  26. package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.js.map +3 -3
  27. package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.test.js +1 -1
  28. package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.test.js.map +2 -2
  29. package/lib/cjs/package.json +1 -1
  30. package/lib/esm/api/app-binder/SignTransactionDeviceActionTypes.js +1 -1
  31. package/lib/esm/api/app-binder/SignTransactionDeviceActionTypes.js.map +2 -2
  32. package/lib/esm/api/index.js +1 -1
  33. package/lib/esm/api/index.js.map +2 -2
  34. package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js +1 -1
  35. package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js.map +3 -3
  36. package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js +1 -1
  37. package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js.map +3 -3
  38. package/lib/esm/internal/app-binder/task/BuildBaseContexts.js +1 -1
  39. package/lib/esm/internal/app-binder/task/BuildBaseContexts.js.map +3 -3
  40. package/lib/esm/internal/app-binder/task/BuildBaseContexts.test.js +1 -1
  41. package/lib/esm/internal/app-binder/task/BuildBaseContexts.test.js.map +2 -2
  42. package/lib/esm/internal/app-binder/task/BuildFullContextsTask.js +1 -1
  43. package/lib/esm/internal/app-binder/task/BuildFullContextsTask.js.map +2 -2
  44. package/lib/esm/internal/app-binder/task/BuildFullContextsTask.test.js +1 -1
  45. package/lib/esm/internal/app-binder/task/BuildFullContextsTask.test.js.map +2 -2
  46. package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.js +1 -1
  47. package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.js.map +3 -3
  48. package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.test.js +1 -1
  49. package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.test.js.map +3 -3
  50. package/lib/esm/internal/app-binder/task/ProvideContextsTask.js +1 -1
  51. package/lib/esm/internal/app-binder/task/ProvideContextsTask.js.map +2 -2
  52. package/lib/esm/internal/app-binder/task/ProvideContextsTask.test.js +1 -1
  53. package/lib/esm/internal/app-binder/task/ProvideContextsTask.test.js.map +2 -2
  54. package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.js +1 -1
  55. package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.js.map +3 -3
  56. package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.test.js +1 -1
  57. package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.test.js.map +2 -2
  58. package/lib/esm/package.json +1 -1
  59. package/lib/types/api/app-binder/SignTransactionDeviceActionTypes.d.ts +2 -1
  60. package/lib/types/api/app-binder/SignTransactionDeviceActionTypes.d.ts.map +1 -1
  61. package/lib/types/api/index.d.ts +5 -9
  62. package/lib/types/api/index.d.ts.map +1 -1
  63. package/lib/types/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.d.ts +1 -1
  64. package/lib/types/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.d.ts.map +1 -1
  65. package/lib/types/internal/app-binder/task/BuildBaseContexts.d.ts +14 -1
  66. package/lib/types/internal/app-binder/task/BuildBaseContexts.d.ts.map +1 -1
  67. package/lib/types/internal/app-binder/task/BuildFullContextsTask.d.ts.map +1 -1
  68. package/lib/types/internal/app-binder/task/BuildSubcontextsTask.d.ts.map +1 -1
  69. package/lib/types/internal/app-binder/task/ProvideContextsTask.d.ts +3 -1
  70. package/lib/types/internal/app-binder/task/ProvideContextsTask.d.ts.map +1 -1
  71. package/lib/types/internal/app-binder/task/ProvideEIP712ContextTask.d.ts +1 -1
  72. package/lib/types/internal/app-binder/task/ProvideEIP712ContextTask.d.ts.map +1 -1
  73. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  74. package/package.json +6 -6
@@ -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 type ClearSignContextSuccessType,\n ClearSignContextType,\n type ContextModule,\n type TransactionSubset,\n} from \"@ledgerhq/context-module\";\nimport {\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 {\n GetWeb3CheckTask,\n type GetWeb3CheckTaskArgs,\n} from \"@internal/app-binder/task/GetWeb3CheckTask\";\nimport { ApplicationChecker } from \"@internal/shared/utils/ApplicationChecker\";\n\nexport type BuildBaseContextsResult = {\n readonly clearSignContexts: ClearSignContextSuccess[];\n readonly clearSignContextsOptional: ClearSignContextSuccess[];\n readonly clearSigningType: ClearSigningType;\n};\n\nexport type BuildBaseContextsArgs = {\n readonly contextModule: ContextModule;\n readonly options: TransactionOptions;\n readonly appConfig: GetConfigCommandResponse;\n readonly derivationPath: string;\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 * @param getWeb3ChecksFactory - The factory for the web3 checks\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 private readonly getWeb3ChecksFactory = (\n api: InternalApi,\n args: GetWeb3CheckTaskArgs,\n ) => new GetWeb3CheckTask(api, args),\n ) {}\n\n async run(): Promise<BuildBaseContextsResult> {\n const {\n contextModule,\n options,\n appConfig,\n derivationPath,\n transaction,\n subset,\n } = this._args;\n const deviceState = this._api.getDeviceSessionState();\n let filteredContexts: ClearSignContextSuccess[] = [];\n let filteredContextOptional: ClearSignContextSuccess[] = [];\n let clearSigningType: ClearSigningType = ClearSigningType.BASIC;\n let web3Check: ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK> | null =\n null;\n\n // Run the web3checks if needed\n if (transaction) {\n if (appConfig.web3ChecksEnabled) {\n web3Check = (\n await this.getWeb3ChecksFactory(this._api, {\n contextModule,\n derivationPath,\n subset,\n transaction,\n }).run()\n ).web3Check;\n }\n }\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 challenge: challenge,\n domain: options.domain,\n deviceModelId: deviceState.deviceModelId,\n ...subset,\n });\n\n // NOTE: we need to filter out the ENUM and ERROR types\n // ENUM are handled differently\n // ERROR are not handled at all for now\n const clearSignContextsSuccess: ClearSignContextSuccess<\n Exclude<ClearSignContextSuccessType, ClearSignContextType.ENUM>\n >[] = clearSignContexts.filter(\n (context) =>\n context.type !== ClearSignContextType.ERROR &&\n context.type !== ClearSignContextType.ENUM,\n );\n\n // Retrieve all ENUM contexts\n const transactionEnums: ClearSignContextSuccess<ClearSignContextType.ENUM>[] =\n clearSignContexts.filter(\n (context) => context.type === ClearSignContextType.ENUM,\n );\n\n const transactionInfo = clearSignContextsSuccess.find(\n (ctx) => ctx.type === ClearSignContextType.TRANSACTION_INFO,\n );\n\n // If the device does not support the generic parser,\n // we need to filter out the transaction info and transaction field description\n // as they are not supported by the device\n if (\n !this.supportsGenericParser(deviceState, appConfig) ||\n transactionInfo === undefined\n ) {\n filteredContexts = clearSignContextsSuccess.filter(\n (ctx) =>\n ctx.type !== ClearSignContextType.TRANSACTION_INFO &&\n ctx.type !== ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n );\n\n // If the device supports the web3 check, we need to add it to the list of contexts\n if (web3Check) {\n filteredContexts = [web3Check, ...filteredContexts];\n }\n } else if (transactionInfo.certificate) {\n const transactionFields = clearSignContextsSuccess.filter(\n (ctx) =>\n ctx.type === ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n );\n const proxyContexts = clearSignContextsSuccess.filter(\n (ctx) => ctx.type === ClearSignContextType.PROXY_DELEGATE_CALL,\n );\n const dynamicNetworkContexts = clearSignContextsSuccess.filter(\n (ctx) =>\n ctx.type === ClearSignContextType.DYNAMIC_NETWORK ||\n ctx.type === ClearSignContextType.DYNAMIC_NETWORK_ICON,\n );\n\n filteredContexts = [\n ...dynamicNetworkContexts,\n ...proxyContexts,\n transactionInfo,\n ...transactionFields,\n ...(web3Check ? [web3Check] : []),\n ];\n filteredContextOptional = [...transactionEnums];\n clearSigningType = ClearSigningType.EIP7730;\n }\n\n return {\n clearSignContexts: filteredContexts,\n clearSignContextsOptional: filteredContextOptional,\n clearSigningType,\n };\n }\n\n private supportsGenericParser(\n deviceState: DeviceSessionState,\n appConfig: GetConfigCommandResponse,\n ): boolean {\n return new ApplicationChecker(deviceState, appConfig)\n .withMinVersionExclusive(\"1.14.0\")\n .excludeDeviceModel(DeviceModelId.NANO_S)\n .check();\n }\n}\n"],
5
- "mappings": "AAAA,OAIE,wBAAAA,MAGK,2BACP,OACE,iBAAAC,EAGA,0BAAAC,MACK,kCAGP,OAAS,oBAAAC,MAAwB,8BAEjC,OAAS,uBAAAC,MAA2B,mDACpC,OACE,oBAAAC,MAEK,6CACP,OAAS,sBAAAC,MAA0B,4CAyB5B,MAAMC,CAAkB,CAC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gB,WAE3CU,EAAgB,YAAa,CACtC,MAAME,EAAoBL,EAAyB,OAChDI,GACCA,EAAI,OAAS/B,EAAqB,6BACtC,EACMiC,EAAgBN,EAAyB,OAC5CI,GAAQA,EAAI,OAAS/B,EAAqB,mBAC7C,EAOAoB,EAAmB,CACjB,GAP6BO,EAAyB,OACrDI,GACCA,EAAI,OAAS/B,EAAqB,iBAClC+B,EAAI,OAAS/B,EAAqB,oBACtC,EAIE,GAAGiC,EACHH,EACA,GAAGE,EACH,GAAIT,EAAY,CAACA,CAAS,EAAI,CAAC,CACjC,EACAF,EAA0B,CAAC,GAAGQ,CAAgB,EAC9CP,EAAmBnB,EAAiB,OACtC,CAEA,MAAO,CACL,kBAAmBiB,EACnB,0BAA2BC,EAC3B,iBAAAC,CACF,CACF,CAEQ,sBACNH,EACAJ,EACS,CACT,OAAO,IAAIT,EAAmBa,EAAaJ,CAAS,EACjD,wBAAwB,QAAQ,EAChC,mBAAmBd,EAAc,MAAM,EACvC,MAAM,CACX,CACF",
6
- "names": ["ClearSignContextType", "DeviceModelId", "isSuccessCommandResult", "ClearSigningType", "GetChallengeCommand", "GetWeb3CheckTask", "ApplicationChecker", "BuildBaseContexts", "_api", "_args", "getWeb3ChecksFactory", "api", "args", "contextModule", "options", "appConfig", "derivationPath", "transaction", "subset", "deviceState", "filteredContexts", "filteredContextOptional", "clearSigningType", "web3Check", "challenge", "challengeRes", "clearSignContexts", "clearSignContextsSuccess", "context", "transactionEnums", "transactionInfo", "ctx", "transactionFields", "proxyContexts"]
4
+ "sourcesContent": ["import {\n type ClearSignContext,\n type ClearSignContextSuccess,\n ClearSignContextType,\n type ContextModule,\n type TransactionSubset,\n} from \"@ledgerhq/context-module\";\nimport {\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 {\n GetWeb3CheckTask,\n type GetWeb3CheckTaskArgs,\n} from \"@internal/app-binder/task/GetWeb3CheckTask\";\nimport { ApplicationChecker } from \"@internal/shared/utils/ApplicationChecker\";\n\nexport type BuildBaseContextsResult = {\n readonly clearSignContexts: ClearSignContextSuccess[];\n readonly clearSignContextsOptional: ClearSignContextSuccess[];\n readonly clearSigningType: ClearSigningType;\n};\n\nexport type BuildBaseContextsArgs = {\n readonly contextModule: ContextModule;\n readonly options: TransactionOptions;\n readonly appConfig: GetConfigCommandResponse;\n readonly derivationPath: string;\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 * @param getWeb3ChecksFactory - The factory for the web3 checks\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 private readonly getWeb3ChecksFactory = (\n api: InternalApi,\n args: GetWeb3CheckTaskArgs,\n ) => new GetWeb3CheckTask(api, args),\n ) {}\n\n async run(): Promise<BuildBaseContextsResult> {\n const {\n contextModule,\n options,\n appConfig,\n derivationPath,\n transaction,\n subset,\n } = this._args;\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 challenge: challenge,\n domain: options.domain,\n deviceModelId: deviceState.deviceModelId,\n ...subset,\n });\n\n // Run the web3checks if needed\n if (transaction && appConfig.web3ChecksEnabled) {\n const web3CheckContext = (\n await this.getWeb3ChecksFactory(this._api, {\n contextModule,\n derivationPath,\n subset,\n transaction,\n }).run()\n ).web3Check;\n if (web3CheckContext) {\n clearSignContexts.unshift(web3CheckContext);\n }\n }\n\n // filter out the error contexts\n const contextsSuccess: ClearSignContextSuccess[] = clearSignContexts.filter(\n (context) => context.type !== ClearSignContextType.ERROR,\n );\n\n if (\n this._supportsGenericParser(deviceState, appConfig) &&\n this._hasValidTransactionInfo(contextsSuccess)\n ) {\n return this._getERC7730Contexts(contextsSuccess);\n } else {\n return this._getBasicContexts(contextsSuccess);\n }\n }\n\n private _getERC7730Contexts(\n contexts: ClearSignContextSuccess[],\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 };\n }\n\n private _getBasicContexts(\n contexts: ClearSignContextSuccess[],\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 };\n }\n\n private _isContextNeededForBasicClearSigning({\n type,\n }: ClearSignContextSuccess): boolean {\n switch (type) {\n case ClearSignContextType.WEB3_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 return true;\n case ClearSignContextType.TRANSACTION_INFO:\n case ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:\n case ClearSignContextType.ENUM:\n case ClearSignContextType.PROXY_INFO:\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.WEB3_CHECK:\n case ClearSignContextType.DYNAMIC_NETWORK:\n case ClearSignContextType.DYNAMIC_NETWORK_ICON:\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 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(deviceState, appConfig)\n .withMinVersionExclusive(\"1.14.0\")\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.WEB3_CHECK:\n return 10;\n case ClearSignContextType.DYNAMIC_NETWORK:\n case ClearSignContextType.DYNAMIC_NETWORK_ICON:\n case ClearSignContextType.PROXY_INFO:\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 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": "AAAA,OAGE,wBAAAA,MAGK,2BACP,OACE,iBAAAC,EAGA,0BAAAC,MACK,kCAGP,OAAS,oBAAAC,MAAwB,8BAEjC,OAAS,uBAAAC,MAA2B,mDACpC,OACE,oBAAAC,MAEK,6CACP,OAAS,sBAAAC,MAA0B,4CAyB5B,MAAMC,CAAkB,CAC7B,YACmBC,EACAC,EACAC,EAAuB,CACtCC,EACAC,IACG,IAAIP,EAAiBM,EAAKC,CAAI,EACnC,CANiB,UAAAJ,EACA,WAAAC,EACA,0BAAAC,CAIhB,CAEH,MAAM,KAAwC,CAC5C,KAAM,CACJ,cAAAG,EACA,QAAAC,EACA,UAAAC,EACA,eAAAC,EACA,YAAAC,EACA,OAAAC,CACF,EAAI,KAAK,MACHC,EAAc,KAAK,KAAK,sBAAsB,EAGpD,IAAIC,EACJ,GAAID,EAAY,gBAAkBlB,EAAc,OAAQ,CACtD,MAAMoB,EAAe,MAAM,KAAK,KAAK,YACnC,IAAIjB,CACN,EACIF,EAAuBmB,CAAY,IACrCD,EAAYC,EAAa,KAAK,UAElC,CAGA,MAAMC,EACJ,MAAMT,EAAc,YAAY,CAC9B,UAAWO,EACX,OAAQN,EAAQ,OAChB,cAAeK,EAAY,cAC3B,GAAGD,CACL,CAAC,EAGH,GAAID,GAAeF,EAAU,kBAAmB,CAC9C,MAAMQ,GACJ,MAAM,KAAK,qBAAqB,KAAK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CAAa,CAAC,EAC/D,CACF,CACF,CACF,CACF",
6
+ "names": ["ClearSignContextType", "DeviceModelId", "isSuccessCommandResult", "ClearSigningType", "GetChallengeCommand", "GetWeb3CheckTask", "ApplicationChecker", "BuildBaseContexts", "_api", "_args", "getWeb3ChecksFactory", "api", "args", "contextModule", "options", "appConfig", "derivationPath", "transaction", "subset", "deviceState", "challenge", "challengeRes", "clearSignContexts", "web3CheckContext", "contextsSuccess", "context", "contexts", "a", "b", "clearSignContextsOptional", "type", "uncoveredType"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{ClearSignContextType as t}from"@ledgerhq/context-module";import{CommandResultFactory as g,DeviceModelId as l,DeviceSessionStateType as r,DeviceStatus as d,hexaStringToBuffer as h,UnknownDeviceExchangeError as m}from"@ledgerhq/device-management-kit";import{Transaction as v}from"ethers";import{ClearSigningType as u}from"../../../api/model/ClearSigningType";import{makeDeviceActionInternalApiMock as O}from"../../app-binder/device-action/__test-utils__/makeInternalApi";import{BuildBaseContexts as s}from"./BuildBaseContexts";import{GetWeb3CheckTask as T}from"./GetWeb3CheckTask";describe("BuildBaseContexts",()=>{const i={getFieldContext:vi.fn(),getContexts:vi.fn(),getTypedDataFilters:vi.fn(),getWeb3Checks:vi.fn(),getSolanaContext:vi.fn()},x={domain:"domain-name.eth"},y=h(v.from({chainId:1n,nonce:0,data:"0x"}).unsignedSerialized),p={keyUsageNumber:1,payload:new Uint8Array([1,2,3])};let o;const n=O(),c=vi.fn();function S(e){return{blindSigningEnabled:!1,web3ChecksEnabled:e,web3ChecksOptIn:!1,version:"1.13.0"}}beforeEach(()=>{vi.resetAllMocks(),n.sendCommand.mockResolvedValue(g({data:{challenge:"challenge"}})),c.mockReturnValue({run:async()=>Promise.resolve({web3Check:null})}),o={contextModule:i,subset:{chainId:1,to:void 0,data:"0x",selector:"0x"},transaction:y,options:x,appConfig:S(!1),derivationPath:"44'/60'/0'/0/0"}}),it("should init with a default GetWeb3CheckTaskFactory",()=>{const e=new s(n,o);expect(e.getWeb3ChecksFactory).toBeDefined(),expect(e.getWeb3ChecksFactory(n,{contextModule:o.contextModule,derivationPath:o.derivationPath,subset:o.subset,transaction:o.transaction})).toBeInstanceOf(T)}),it("should build the transaction context without clear sign contexts",async()=>{const e=[],a=[];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const C=await new s(n,{...o,appConfig:S(!0)},c).run();expect(C).toEqual({clearSignContexts:e,clearSignContextsOptional:a,clearSigningType:u.BASIC})}),it("should build the transaction context with web3checks",async()=>{const e=[],a=[],C="web3Check";c.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:C})}),i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const E=await new s(n,{...o,appConfig:S(!0)},c).run();expect(E).toEqual({clearSignContexts:[C,...e],clearSignContextsOptional:a,clearSigningType:u.BASIC})}),it("should build the transaction context with web3checks and generic-parser clear sign contexts",async()=>{const e=[{type:t.TRANSACTION_INFO,payload:"payload-1",certificate:p},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:t.ENUM,payload:"payload-3",id:1,value:2,certificate:p},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}],a="web3Check";c.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:a})}),i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const C=await new s(n,{...o,appConfig:S(!0)},c).run();expect(C).toEqual({clearSignContexts:[e[0],e[1],e[3],a],clearSignContextsOptional:[e[2]],clearSigningType:u.EIP7730})}),it("should build the transaction context with web3checks and generic-parser clear sign contexts in the correct order",async()=>{const e=[{type:t.ENUM,payload:"payload-3",id:1,value:2,certificate:p},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:t.TRANSACTION_INFO,payload:"payload-1",certificate:p}],a="web3Check";c.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:a})}),i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const C=await new s(n,{...o,appConfig:S(!0)},c).run();expect(C).toEqual({clearSignContexts:[e[3],e[1],e[2],a],clearSignContextsOptional:[e[0]],clearSigningType:u.EIP7730})}),it("should build the transaction context with clear sign contexts",async()=>{const e=[{type:t.TOKEN,payload:"payload-1"},{type:t.NFT,payload:"payload-2"}],a="web3Check";c.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:a})}),i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const C=await new s(n,o,c).run();expect(C).toEqual({clearSignContexts:e,clearSignContextsOptional:[],clearSigningType:u.BASIC})}),it("should build the transaction context with generic-parser context",async()=>{const e=[{type:t.TRANSACTION_INFO,payload:"payload-1",certificate:p},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:t.ENUM,payload:"payload-3",id:1,value:2,certificate:p},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[e[0],e[1],e[3]],clearSignContextsOptional:[e[2]],clearSigningType:u.EIP7730})}),it("should build the transaction context with proxy delegate call context",async()=>{const e=[{type:t.TRANSACTION_INFO,payload:"payload-1",certificate:p},{type:t.PROXY_DELEGATE_CALL,payload:"payload-2"}],a=[];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const C=await new s(n,o,c).run();expect(C).toEqual({clearSignContexts:[e[1],e[0]],clearSignContextsOptional:a,clearSigningType:u.EIP7730})}),it("should call the web3checks factory with correct parameters",async()=>{const e=[];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1}),await new s(n,{...o,appConfig:S(!0)},c).run(),expect(c).toHaveBeenCalledWith(n,{contextModule:i,derivationPath:"44'/60'/0'/0/0",subset:o.subset,transaction:y})}),it("should call the context module with the correct parameters",async()=>{const e=[];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1}),await new s(n,o,c).run(),expect(i.getContexts).toHaveBeenCalledWith({deviceModelId:l.FLEX,challenge:"challenge",domain:"domain-name.eth",...o.subset})}),it("should call the context module without challenge for Nano S",async()=>{const e=[];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.NANO_S,isSecureConnectionAllowed:!1}),await new s(n,o,c).run(),expect(i.getContexts).toHaveBeenCalledWith({deviceModelId:l.NANO_S,domain:"domain-name.eth",...o.subset})}),it("should call the context module without context on error",async()=>{const e=[];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1}),n.sendCommand.mockResolvedValueOnce(g({error:new m})),await new s(n,o,c).run(),expect(i.getContexts).toHaveBeenCalledWith({deviceModelId:l.FLEX,challenge:void 0,domain:"domain-name.eth",...o.subset})}),it("should exclude error contexts from the result",async()=>{const e=[{type:t.ERROR,error:new Error("error")},{type:t.TOKEN,payload:"payload-1"},{type:t.ERROR,error:new Error("error")},{type:t.NFT,payload:"payload-2"}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:u.BASIC})}),it("should exclude generic-parser contexts from the result on old apps",async()=>{const e=[{type:t.TRANSACTION_INFO,payload:"transaction_info",certificate:p},{type:t.TOKEN,payload:"payload-1"},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:t.NFT,payload:"payload-2"},{type:t.ENUM,payload:"enum",id:1,value:2,certificate:p}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:u.BASIC})}),it("should exclude generic-parser contexts from the result if no transaction_info was found",async()=>{const e=[{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:t.TOKEN,payload:"payload-1"},{type:t.ENUM,payload:"enum",id:1,value:2},{type:t.NFT,payload:"payload-2"}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:u.BASIC})}),it("should exclude legacy contexts from the result for generic-parser transactions",async()=>{const e=[{type:t.TOKEN,payload:"payload-1"},{type:t.TRANSACTION_INFO,payload:"payload-2",certificate:p},{type:t.EXTERNAL_PLUGIN,payload:"payload-3"},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"},{type:t.ENUM,payload:"payload-5",id:1,value:2,certificate:p}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[e[4]],clearSigningType:u.EIP7730})}),it("should exclude generic-parser contexts with a nano s device",async()=>{const e=[{type:t.TOKEN,payload:"payload-1"},{type:t.TRANSACTION_INFO,payload:"payload-2",certificate:p},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:t.ENUM,payload:"payload-4",id:1,value:2,certificate:p}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:l.NANO_S,isSecureConnectionAllowed:!1});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:u.BASIC})}),it("should exclude generic-parser contexts with an old app version",async()=>{const e=[{type:t.TOKEN,payload:"payload-1"},{type:t.TRANSACTION_INFO,payload:"payload-2",certificate:p},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:t.ENUM,payload:"payload-4",id:1,value:2,certificate:p}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:u.BASIC})}),it("should exclude generic-parser contexts with a non ready device",async()=>{const e=[{type:t.TOKEN,payload:"payload-1"},{type:t.TRANSACTION_INFO,payload:"payload-2",certificate:p},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:t.ENUM,payload:"payload-4",id:1,value:2,certificate:p}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.Connected,deviceStatus:d.NOT_CONNECTED,deviceModelId:l.FLEX});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:u.BASIC})}),it("should return no clear sign context if the transaction info certificate is missing",async()=>{const e=[{type:t.TRANSACTION_INFO,payload:"payload-1"},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:t.ENUM,payload:"payload-3",id:1,value:2}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.17.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[],clearSignContextsOptional:[],clearSigningType:u.BASIC})}),it("should not return web3check if the transaction is undefined",async()=>{const e=[];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.17.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1}),await new s(n,{...o,transaction:void 0},c).run(),expect(c).not.toHaveBeenCalled()})});
1
+ import{ClearSignContextType as t}from"@ledgerhq/context-module";import{CommandResultFactory as g,DeviceModelId as l,DeviceSessionStateType as r,DeviceStatus as d,hexaStringToBuffer as h,UnknownDeviceExchangeError as m}from"@ledgerhq/device-management-kit";import{Transaction as O}from"ethers";import{ClearSigningType as u}from"../../../api/model/ClearSigningType";import{makeDeviceActionInternalApiMock as v}from"../../app-binder/device-action/__test-utils__/makeInternalApi";import{BuildBaseContexts as s}from"./BuildBaseContexts";import{GetWeb3CheckTask as N}from"./GetWeb3CheckTask";describe("BuildBaseContexts",()=>{const i={getFieldContext:vi.fn(),getContexts:vi.fn(),getTypedDataFilters:vi.fn(),getWeb3Checks:vi.fn(),getSolanaContext:vi.fn()},x={domain:"domain-name.eth"},y=h(O.from({chainId:1n,nonce:0,data:"0x"}).unsignedSerialized),p={keyUsageNumber:1,payload:new Uint8Array([1,2,3])};let o;const n=v(),c=vi.fn();function S(e){return{blindSigningEnabled:!1,web3ChecksEnabled:e,web3ChecksOptIn:!1,version:"1.13.0"}}beforeEach(()=>{vi.resetAllMocks(),n.sendCommand.mockResolvedValue(g({data:{challenge:"challenge"}})),c.mockReturnValue({run:async()=>Promise.resolve({web3Check:null})}),o={contextModule:i,subset:{chainId:1,to:void 0,data:"0x",selector:"0x"},transaction:y,options:x,appConfig:S(!1),derivationPath:"44'/60'/0'/0/0"}}),it("should init with a default GetWeb3CheckTaskFactory",()=>{const e=new s(n,o);expect(e.getWeb3ChecksFactory).toBeDefined(),expect(e.getWeb3ChecksFactory(n,{contextModule:o.contextModule,derivationPath:o.derivationPath,subset:o.subset,transaction:o.transaction})).toBeInstanceOf(N)}),it("should build the transaction context without clear sign contexts",async()=>{const e=[],a=[];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const C=await new s(n,{...o,appConfig:S(!0)},c).run();expect(C).toEqual({clearSignContexts:e,clearSignContextsOptional:a,clearSigningType:u.BASIC})}),it("should build the transaction context with web3checks",async()=>{const e=[],a=[],C={type:t.WEB3_CHECK,payload:"web3Check"};c.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:C})}),i.getContexts.mockResolvedValueOnce([...e]),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const E=await new s(n,{...o,appConfig:S(!0)},c).run();expect(E).toEqual({clearSignContexts:[C,...e],clearSignContextsOptional:a,clearSigningType:u.BASIC})}),it("should build the transaction context with web3checks and generic-parser clear sign contexts",async()=>{const e=[{type:t.TRANSACTION_INFO,payload:"payload-1",certificate:p},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:t.ENUM,payload:"payload-3",id:1,value:2,certificate:p},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}],a={type:t.WEB3_CHECK,payload:"web3Check"};c.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:a})}),i.getContexts.mockResolvedValueOnce([...e]),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const C=await new s(n,{...o,appConfig:S(!0)},c).run();expect(C).toEqual({clearSignContexts:[a,e[0],e[1],e[3]],clearSignContextsOptional:[e[2]],clearSigningType:u.EIP7730})}),it("should build the transaction context with web3checks and generic-parser clear sign contexts in the correct order",async()=>{const e=[{type:t.ENUM,payload:"payload-3",id:1,value:2,certificate:p},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:t.TRANSACTION_INFO,payload:"payload-1",certificate:p}],a={type:t.WEB3_CHECK,payload:"web3Check"};c.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:a})}),i.getContexts.mockResolvedValueOnce([...e]),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const C=await new s(n,{...o,appConfig:S(!0)},c).run();expect(C).toEqual({clearSignContexts:[a,e[3],e[1],e[2]],clearSignContextsOptional:[e[0]],clearSigningType:u.EIP7730})}),it("should build the transaction context with clear sign contexts",async()=>{const e=[{type:t.TOKEN,payload:"payload-1"},{type:t.NFT,payload:"payload-2"}],a={type:t.WEB3_CHECK,payload:"web3Check"};c.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:a})}),i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const C=await new s(n,o,c).run();expect(C).toEqual({clearSignContexts:e,clearSignContextsOptional:[],clearSigningType:u.BASIC})}),it("should build the transaction context with generic-parser context",async()=>{const e=[{type:t.TRANSACTION_INFO,payload:"payload-1",certificate:p},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:t.ENUM,payload:"payload-3",id:1,value:2,certificate:p},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[e[0],e[1],e[3]],clearSignContextsOptional:[e[2]],clearSigningType:u.EIP7730})}),it("should build the transaction context with proxy delegate call context",async()=>{const e=[{type:t.TRANSACTION_INFO,payload:"payload-1",certificate:p},{type:t.PROXY_INFO,payload:"payload-2"}],a=[];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const C=await new s(n,o,c).run();expect(C).toEqual({clearSignContexts:[e[1],e[0]],clearSignContextsOptional:a,clearSigningType:u.EIP7730})}),it("should call the web3checks factory with correct parameters",async()=>{const e=[];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1}),await new s(n,{...o,appConfig:S(!0)},c).run(),expect(c).toHaveBeenCalledWith(n,{contextModule:i,derivationPath:"44'/60'/0'/0/0",subset:o.subset,transaction:y})}),it("should call the context module with the correct parameters",async()=>{const e=[];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1}),await new s(n,o,c).run(),expect(i.getContexts).toHaveBeenCalledWith({deviceModelId:l.FLEX,challenge:"challenge",domain:"domain-name.eth",...o.subset})}),it("should call the context module without challenge for Nano S",async()=>{const e=[];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.NANO_S,isSecureConnectionAllowed:!1}),await new s(n,o,c).run(),expect(i.getContexts).toHaveBeenCalledWith({deviceModelId:l.NANO_S,domain:"domain-name.eth",...o.subset})}),it("should call the context module without context on error",async()=>{const e=[];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1}),n.sendCommand.mockResolvedValueOnce(g({error:new m})),await new s(n,o,c).run(),expect(i.getContexts).toHaveBeenCalledWith({deviceModelId:l.FLEX,challenge:void 0,domain:"domain-name.eth",...o.subset})}),it("should exclude error contexts from the result",async()=>{const e=[{type:t.ERROR,error:new Error("error")},{type:t.TOKEN,payload:"payload-1"},{type:t.ERROR,error:new Error("error")},{type:t.NFT,payload:"payload-2"}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:u.BASIC})}),it("should exclude generic-parser contexts from the result on old apps",async()=>{const e=[{type:t.TRANSACTION_INFO,payload:"transaction_info",certificate:p},{type:t.TOKEN,payload:"payload-1"},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:t.NFT,payload:"payload-2"},{type:t.ENUM,payload:"enum",id:1,value:2,certificate:p}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:u.BASIC})}),it("should exclude generic-parser contexts from the result if no transaction_info was found",async()=>{const e=[{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:t.TOKEN,payload:"payload-1"},{type:t.ENUM,payload:"enum",id:1,value:2},{type:t.NFT,payload:"payload-2"}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:u.BASIC})}),it("should exclude legacy contexts from the result for generic-parser transactions",async()=>{const e=[{type:t.TOKEN,payload:"payload-1"},{type:t.TRANSACTION_INFO,payload:"payload-2",certificate:p},{type:t.EXTERNAL_PLUGIN,payload:"payload-3"},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"},{type:t.ENUM,payload:"payload-5",id:1,value:2,certificate:p}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[e[4]],clearSigningType:u.EIP7730})}),it("should exclude generic-parser contexts with a nano s device",async()=>{const e=[{type:t.TOKEN,payload:"payload-1"},{type:t.TRANSACTION_INFO,payload:"payload-2",certificate:p},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:t.ENUM,payload:"payload-4",id:1,value:2,certificate:p}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:l.NANO_S,isSecureConnectionAllowed:!1});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:u.BASIC})}),it("should exclude generic-parser contexts with an old app version",async()=>{const e=[{type:t.TOKEN,payload:"payload-1"},{type:t.TRANSACTION_INFO,payload:"payload-2",certificate:p},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:t.ENUM,payload:"payload-4",id:1,value:2,certificate:p}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:u.BASIC})}),it("should exclude generic-parser contexts with a non ready device",async()=>{const e=[{type:t.TOKEN,payload:"payload-1"},{type:t.TRANSACTION_INFO,payload:"payload-2",certificate:p},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:t.ENUM,payload:"payload-4",id:1,value:2,certificate:p}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.Connected,deviceStatus:d.NOT_CONNECTED,deviceModelId:l.FLEX});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:u.BASIC})}),it("should return no clear sign context if the transaction info certificate is missing",async()=>{const e=[{type:t.TRANSACTION_INFO,payload:"payload-1"},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:t.ENUM,payload:"payload-3",id:1,value:2}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.17.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[],clearSignContextsOptional:[],clearSigningType:u.BASIC})}),it("should not return web3check if the transaction is undefined",async()=>{const e=[];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.17.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1}),await new s(n,{...o,transaction:void 0},c).run(),expect(c).not.toHaveBeenCalled()})});
2
2
  //# sourceMappingURL=BuildBaseContexts.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/internal/app-binder/task/BuildBaseContexts.test.ts"],
4
- "sourcesContent": ["import {\n type ClearSignContext,\n type ClearSignContextSuccess,\n ClearSignContextType,\n type PkiCertificate,\n} from \"@ledgerhq/context-module\";\nimport {\n CommandResultFactory,\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n hexaStringToBuffer,\n UnknownDeviceExchangeError,\n} from \"@ledgerhq/device-management-kit\";\nimport { Transaction } from \"ethers\";\n\nimport type { GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\nimport { ClearSigningType } from \"@api/model/ClearSigningType\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\n\nimport {\n BuildBaseContexts,\n type BuildBaseContextsArgs,\n} from \"./BuildBaseContexts\";\nimport { GetWeb3CheckTask } from \"./GetWeb3CheckTask\";\n\ndescribe(\"BuildBaseContexts\", () => {\n const contextModuleMock = {\n getFieldContext: vi.fn(),\n getContexts: vi.fn(),\n getTypedDataFilters: vi.fn(),\n getWeb3Checks: vi.fn(),\n getSolanaContext: vi.fn(),\n };\n const defaultOptions = {\n domain: \"domain-name.eth\",\n };\n const defaultTransaction: Uint8Array = hexaStringToBuffer(\n Transaction.from({\n chainId: 1n,\n nonce: 0,\n data: \"0x\",\n }).unsignedSerialized,\n )!;\n const defaultCertificate: PkiCertificate = {\n keyUsageNumber: 1,\n payload: new Uint8Array([0x01, 0x02, 0x03]),\n };\n\n let defaultArgs: BuildBaseContextsArgs;\n const apiMock = makeDeviceActionInternalApiMock();\n const getWeb3ChecksFactoryMock = vi.fn();\n\n function createAppConfig(\n web3ChecksEnabled: boolean,\n ): GetConfigCommandResponse {\n return {\n blindSigningEnabled: false,\n web3ChecksEnabled,\n web3ChecksOptIn: false,\n version: \"1.13.0\",\n };\n }\n\n beforeEach(() => {\n vi.resetAllMocks();\n apiMock.sendCommand.mockResolvedValue(\n CommandResultFactory({ data: { challenge: \"challenge\" } }),\n );\n getWeb3ChecksFactoryMock.mockReturnValue({\n run: async () => Promise.resolve({ web3Check: null }),\n });\n\n defaultArgs = {\n contextModule: contextModuleMock,\n subset: { chainId: 1, to: undefined, data: \"0x\", selector: \"0x\" },\n transaction: defaultTransaction,\n options: defaultOptions,\n appConfig: createAppConfig(false),\n derivationPath: \"44'/60'/0'/0/0\",\n };\n });\n\n it(\"should init with a default GetWeb3CheckTaskFactory\", () => {\n // GIVEN\n const task = new BuildBaseContexts(apiMock, defaultArgs);\n\n // THEN\n expect(task[\"getWeb3ChecksFactory\"]).toBeDefined();\n expect(\n task[\"getWeb3ChecksFactory\"](apiMock, {\n contextModule: defaultArgs.contextModule,\n derivationPath: defaultArgs.derivationPath,\n subset: defaultArgs.subset,\n transaction: defaultArgs.transaction!,\n }),\n ).toBeInstanceOf(GetWeb3CheckTask);\n });\n\n it(\"should build the transaction context without clear sign contexts\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n const clearSignContextsOptional: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n clearSignContextsOptional,\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should build the transaction context with web3checks\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n const clearSignContextsOptional: ClearSignContext[] = [];\n const expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [expectedWeb3Check, ...clearSignContexts],\n clearSignContextsOptional,\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should build the transaction context with web3checks and generic-parser clear sign contexts\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n ];\n const expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [\n clearSignContexts[0],\n clearSignContexts[1],\n clearSignContexts[3],\n expectedWeb3Check,\n ],\n clearSignContextsOptional: [clearSignContexts[2]],\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should build the transaction context with web3checks and generic-parser clear sign contexts in the correct order\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n ];\n const expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [\n clearSignContexts[3], // transaction info\n clearSignContexts[1], // transaction field description\n clearSignContexts[2], // transaction field description\n expectedWeb3Check, // web3 check\n ],\n clearSignContextsOptional: [clearSignContexts[0]], // enum\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should build the transaction context with clear sign contexts\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n const expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should build the transaction context with generic-parser context\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [\n clearSignContexts[0],\n clearSignContexts[1],\n clearSignContexts[3],\n ],\n clearSignContextsOptional: [clearSignContexts[2]],\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should build the transaction context with proxy delegate call context\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.PROXY_DELEGATE_CALL,\n payload: \"payload-2\",\n },\n ];\n const clearSignContextsOptional: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[0]],\n clearSignContextsOptional,\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should call the web3checks factory with correct parameters\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(getWeb3ChecksFactoryMock).toHaveBeenCalledWith(apiMock, {\n contextModule: contextModuleMock,\n derivationPath: \"44'/60'/0'/0/0\",\n subset: defaultArgs.subset,\n transaction: defaultTransaction,\n });\n });\n\n it(\"should call the context module with the correct parameters\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.FLEX,\n challenge: \"challenge\",\n domain: \"domain-name.eth\",\n ...defaultArgs.subset,\n });\n });\n\n it(\"should call the context module without challenge for Nano S\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.NANO_S,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.NANO_S,\n domain: \"domain-name.eth\",\n ...defaultArgs.subset,\n });\n });\n\n it(\"should call the context module without context on error\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ error: new UnknownDeviceExchangeError() }),\n );\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.FLEX,\n challenge: undefined,\n domain: \"domain-name.eth\",\n ...defaultArgs.subset,\n });\n });\n\n it(\"should exclude error contexts from the result\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result on old apps\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"transaction_info\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"transaction_field\",\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"enum\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result if no transaction_info was found\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"transaction_field\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"enum\",\n id: 1,\n value: 2,\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.14.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude legacy contexts from the result for generic-parser transactions\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-5\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [clearSignContexts[4]],\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should exclude generic-parser contexts with a nano s device\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.14.0\" },\n deviceModelId: DeviceModelId.NANO_S,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts with an old app version\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts with a non ready device\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.NOT_CONNECTED,\n deviceModelId: DeviceModelId.FLEX,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should return no clear sign context if the transaction info certificate is missing\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.17.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should not return web3check if the transaction is undefined\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.17.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, transaction: undefined },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(getWeb3ChecksFactoryMock).not.toHaveBeenCalled();\n });\n});\n"],
5
- "mappings": "AAAA,OAGE,wBAAAA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AAMA,EAAqB,KAC3B,QAAS,YACT,GAAI,EACJ,MAAO,CACT,CACF,EACAY,EAAkB,YAAY,sBAAsBU,CAAiB,EACrEL,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkBd,EAAuB,0BACzC,aAAcC,EAAa,UAC3B,cAAe,CAAC,EAChB,WAAY,CAAE,KAAM,WAAY,QAAS,QAAS,EAClD,cAAeF,EAAc,KAC7B,0BAA2B,EAC7B,CAAC,EAGD,MAAMsB,EAAS,MAAM,IAAId,EACvBO,EACAD,EACAE,CACF,EAAE,IAAI,EAGN,OAAOM,CAAM,EAAE,QAAQ,CACrB,kBAAmB,CAAC,EACpB,0BAA2B,CAAC,EAC5B,iBAAkBhB,EAAiB,KACrC,CAAC,CACH,CAAC,EAED,GAAG,8DAA+D,SAAY,CAE5E,MAAMc,EAAwC,CAAC,EAC/CV,EAAkB,YAAY,sBAAsBU,CAAiB,EACrEL,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkBd,EAAuB,0BACzC,aAAcC,EAAa,UAC3B,cAAe,CAAC,EAChB,WAAY,CAAE,KAAM,WAAY,QAAS,QAAS,EAClD,cAAeF,EAAc,KAC7B,0BAA2B,EAC7B,CAAC,EAGD,MAAM,IAAIQ,EACRO,EACA,CAAE,GAAGD,EAAa,YAAa,MAAU,EACzCE,CACF,EAAE,IAAI,EAGN,OAAOA,CAAwB,EAAE,IAAI,iBAAiB,CACxD,CAAC,CACH,CAAC",
4
+ "sourcesContent": ["import {\n type ClearSignContext,\n ClearSignContextType,\n type PkiCertificate,\n} from \"@ledgerhq/context-module\";\nimport {\n CommandResultFactory,\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n hexaStringToBuffer,\n UnknownDeviceExchangeError,\n} from \"@ledgerhq/device-management-kit\";\nimport { Transaction } from \"ethers\";\n\nimport type { GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\nimport { ClearSigningType } from \"@api/model/ClearSigningType\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\n\nimport {\n BuildBaseContexts,\n type BuildBaseContextsArgs,\n} from \"./BuildBaseContexts\";\nimport { GetWeb3CheckTask } from \"./GetWeb3CheckTask\";\n\ndescribe(\"BuildBaseContexts\", () => {\n const contextModuleMock = {\n getFieldContext: vi.fn(),\n getContexts: vi.fn(),\n getTypedDataFilters: vi.fn(),\n getWeb3Checks: vi.fn(),\n getSolanaContext: vi.fn(),\n };\n const defaultOptions = {\n domain: \"domain-name.eth\",\n };\n const defaultTransaction: Uint8Array = hexaStringToBuffer(\n Transaction.from({\n chainId: 1n,\n nonce: 0,\n data: \"0x\",\n }).unsignedSerialized,\n )!;\n const defaultCertificate: PkiCertificate = {\n keyUsageNumber: 1,\n payload: new Uint8Array([0x01, 0x02, 0x03]),\n };\n\n let defaultArgs: BuildBaseContextsArgs;\n const apiMock = makeDeviceActionInternalApiMock();\n const getWeb3ChecksFactoryMock = vi.fn();\n\n function createAppConfig(\n web3ChecksEnabled: boolean,\n ): GetConfigCommandResponse {\n return {\n blindSigningEnabled: false,\n web3ChecksEnabled,\n web3ChecksOptIn: false,\n version: \"1.13.0\",\n };\n }\n\n beforeEach(() => {\n vi.resetAllMocks();\n apiMock.sendCommand.mockResolvedValue(\n CommandResultFactory({ data: { challenge: \"challenge\" } }),\n );\n getWeb3ChecksFactoryMock.mockReturnValue({\n run: async () => Promise.resolve({ web3Check: null }),\n });\n\n defaultArgs = {\n contextModule: contextModuleMock,\n subset: { chainId: 1, to: undefined, data: \"0x\", selector: \"0x\" },\n transaction: defaultTransaction,\n options: defaultOptions,\n appConfig: createAppConfig(false),\n derivationPath: \"44'/60'/0'/0/0\",\n };\n });\n\n it(\"should init with a default GetWeb3CheckTaskFactory\", () => {\n // GIVEN\n const task = new BuildBaseContexts(apiMock, defaultArgs);\n\n // THEN\n expect(task[\"getWeb3ChecksFactory\"]).toBeDefined();\n expect(\n task[\"getWeb3ChecksFactory\"](apiMock, {\n contextModule: defaultArgs.contextModule,\n derivationPath: defaultArgs.derivationPath,\n subset: defaultArgs.subset,\n transaction: defaultArgs.transaction!,\n }),\n ).toBeInstanceOf(GetWeb3CheckTask);\n });\n\n it(\"should build the transaction context without clear sign contexts\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n const clearSignContextsOptional: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n clearSignContextsOptional,\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should build the transaction context with web3checks\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n const clearSignContextsOptional: ClearSignContext[] = [];\n const expectedWeb3Check = {\n type: ClearSignContextType.WEB3_CHECK,\n payload: \"web3Check\",\n };\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\n contextModuleMock.getContexts.mockResolvedValueOnce([...clearSignContexts]);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [expectedWeb3Check, ...clearSignContexts],\n clearSignContextsOptional,\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should build the transaction context with web3checks and generic-parser clear sign contexts\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n ];\n const expectedWeb3Check = {\n type: ClearSignContextType.WEB3_CHECK,\n payload: \"web3Check\",\n };\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\n contextModuleMock.getContexts.mockResolvedValueOnce([...clearSignContexts]);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [\n expectedWeb3Check,\n clearSignContexts[0],\n clearSignContexts[1],\n clearSignContexts[3],\n ],\n clearSignContextsOptional: [clearSignContexts[2]],\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should build the transaction context with web3checks and generic-parser clear sign contexts in the correct order\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n ];\n const expectedWeb3Check = {\n type: ClearSignContextType.WEB3_CHECK,\n payload: \"web3Check\",\n };\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\n contextModuleMock.getContexts.mockResolvedValueOnce([...clearSignContexts]);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [\n expectedWeb3Check, // web3 check\n clearSignContexts[3], // transaction info\n clearSignContexts[1], // transaction field description\n clearSignContexts[2], // transaction field description\n ],\n clearSignContextsOptional: [clearSignContexts[0]], // enum\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should build the transaction context with clear sign contexts\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n const expectedWeb3Check = {\n type: ClearSignContextType.WEB3_CHECK,\n payload: \"web3Check\",\n };\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should build the transaction context with generic-parser context\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [\n clearSignContexts[0],\n clearSignContexts[1],\n clearSignContexts[3],\n ],\n clearSignContextsOptional: [clearSignContexts[2]],\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should build the transaction context with proxy delegate call context\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.PROXY_INFO,\n payload: \"payload-2\",\n },\n ];\n const clearSignContextsOptional: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[0]],\n clearSignContextsOptional,\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should call the web3checks factory with correct parameters\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(getWeb3ChecksFactoryMock).toHaveBeenCalledWith(apiMock, {\n contextModule: contextModuleMock,\n derivationPath: \"44'/60'/0'/0/0\",\n subset: defaultArgs.subset,\n transaction: defaultTransaction,\n });\n });\n\n it(\"should call the context module with the correct parameters\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.FLEX,\n challenge: \"challenge\",\n domain: \"domain-name.eth\",\n ...defaultArgs.subset,\n });\n });\n\n it(\"should call the context module without challenge for Nano S\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.NANO_S,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.NANO_S,\n domain: \"domain-name.eth\",\n ...defaultArgs.subset,\n });\n });\n\n it(\"should call the context module without context on error\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ error: new UnknownDeviceExchangeError() }),\n );\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.FLEX,\n challenge: undefined,\n domain: \"domain-name.eth\",\n ...defaultArgs.subset,\n });\n });\n\n it(\"should exclude error contexts from the result\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result on old apps\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"transaction_info\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"transaction_field\",\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"enum\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result if no transaction_info was found\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"transaction_field\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"enum\",\n id: 1,\n value: 2,\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.14.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude legacy contexts from the result for generic-parser transactions\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-5\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [clearSignContexts[4]],\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should exclude generic-parser contexts with a nano s device\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.14.0\" },\n deviceModelId: DeviceModelId.NANO_S,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts with an old app version\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts with a non ready device\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.NOT_CONNECTED,\n deviceModelId: DeviceModelId.FLEX,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should return no clear sign context if the transaction info certificate is missing\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.17.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should not return web3check if the transaction is undefined\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.17.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, transaction: undefined },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(getWeb3ChecksFactoryMock).not.toHaveBeenCalled();\n });\n});\n"],
5
+ "mappings": "AAAA,OAEE,wBAAAA,MAEK,2BACP,OACE,wBAAAC,EACA,iBAAAC,EACA,0BAAAC,EACA,gBAAAC,EACA,sBAAAC,EACA,8BAAAC,MACK,kCACP,OAAS,eAAAC,MAAmB,SAG5B,OAAS,oBAAAC,MAAwB,8BACjC,OAAS,mCAAAC,MAAuC,oEAEhD,OACE,qBAAAC,MAEK,sBACP,OAAS,oBAAAC,MAAwB,qBAEjC,SAAS,oBAAqB,IAAM,CAClC,MAAMC,EAAoB,CACxB,gBAAiB,GAAG,GAAG,EACvB,YAAa,GAAG,GAAG,EACnB,oBAAqB,GAAG,GAAG,EAC3B,cAAe,GAAG,GAAG,EACrB,iBAAkB,GAAG,GAAG,CAC1B,EACMC,EAAiB,CACrB,OAAQ,iBACV,EACM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ClD,cAAeF,EAAc,KAC7B,0BAA2B,EAC7B,CAAC,EAGD,MAAMsB,EAAS,MAAM,IAAId,EACvBO,EACAD,EACAE,CACF,EAAE,IAAI,EAGN,OAAOM,CAAM,EAAE,QAAQ,CACrB,kBAAmB,CAAC,EACpB,0BAA2B,CAAC,EAC5B,iBAAkBhB,EAAiB,KACrC,CAAC,CACH,CAAC,EAED,GAAG,8DAA+D,SAAY,CAE5E,MAAMc,EAAwC,CAAC,EAC/CV,EAAkB,YAAY,sBAAsBU,CAAiB,EACrEL,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkBd,EAAuB,0BACzC,aAAcC,EAAa,UAC3B,cAAe,CAAC,EAChB,WAAY,CAAE,KAAM,WAAY,QAAS,QAAS,EAClD,cAAeF,EAAc,KAC7B,0BAA2B,EAC7B,CAAC,EAGD,MAAM,IAAIQ,EACRO,EACA,CAAE,GAAGD,EAAa,YAAa,MAAU,EACzCE,CACF,EAAE,IAAI,EAGN,OAAOA,CAAwB,EAAE,IAAI,iBAAiB,CACxD,CAAC,CACH,CAAC",
6
6
  "names": ["ClearSignContextType", "CommandResultFactory", "DeviceModelId", "DeviceSessionStateType", "DeviceStatus", "hexaStringToBuffer", "UnknownDeviceExchangeError", "Transaction", "ClearSigningType", "makeDeviceActionInternalApiMock", "BuildBaseContexts", "GetWeb3CheckTask", "contextModuleMock", "defaultOptions", "defaultTransaction", "defaultCertificate", "defaultArgs", "apiMock", "getWeb3ChecksFactoryMock", "createAppConfig", "web3ChecksEnabled", "task", "clearSignContexts", "clearSignContextsOptional", "result", "expectedWeb3Check"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{ClearSignContextReferenceType as p,ClearSignContextType as d}from"@ledgerhq/context-module";import{BuildBaseContexts as u}from"./BuildBaseContexts";import{BuildSubcontextsTask as x}from"./BuildSubcontextsTask";import{ParseNestedTransactionTask as C}from"./ParseNestedTransactionTask";class i{constructor(n,a,o=(t,e)=>new x(t,e),r=(t,e)=>new u(t,e),s=t=>new C(t)){this._api=n;this._args=a;this._buildSubcontextsTaskFactory=o;this._buildBaseContextsTaskFactory=r;this._preBuildNestedCallDataTaskFactory=s}async run(){const{clearSignContexts:n,clearSigningType:a,clearSignContextsOptional:o}=await this._buildBaseContextsTaskFactory(this._api,this._args).run(),r=n.map(t=>{const{subcontextCallbacks:e}=this._buildSubcontextsTaskFactory(this._api,{context:t,contextOptional:o,contextModule:this._args.contextModule,subset:this._args.subset,transactionParser:this._args.parser,deviceModelId:this._args.deviceModelId}).run();return{context:t,subcontextCallbacks:e}});let s=[];for(const t of r)if(t.context.type===d.TRANSACTION_FIELD_DESCRIPTION&&t.context.reference?.type===p.CALLDATA){const{subsets:e}=this._preBuildNestedCallDataTaskFactory({parser:this._args.parser,subset:this._args.subset,context:t.context}).run();for(const l of e){const{clearSignContexts:c}=await new i(this._api,{...this._args,subset:l},this._buildSubcontextsTaskFactory,this._buildBaseContextsTaskFactory,this._preBuildNestedCallDataTaskFactory).run();s=[...s,...c,t]}}else s.push(t);return{clearSignContexts:s,clearSigningType:a}}}export{i as BuildFullContextsTask};
1
+ import{ClearSignContextReferenceType as p,ClearSignContextType as u}from"@ledgerhq/context-module";import{BuildBaseContexts as d}from"./BuildBaseContexts";import{BuildSubcontextsTask as x}from"./BuildSubcontextsTask";import{ParseNestedTransactionTask as C}from"./ParseNestedTransactionTask";class i{constructor(n,o,a=(t,e)=>new x(t,e),r=(t,e)=>new d(t,e),s=t=>new C(t)){this._api=n;this._args=o;this._buildSubcontextsTaskFactory=a;this._buildBaseContextsTaskFactory=r;this._preBuildNestedCallDataTaskFactory=s}async run(){const{clearSignContexts:n,clearSigningType:o,clearSignContextsOptional:a}=await this._buildBaseContextsTaskFactory(this._api,this._args).run(),r=n.map(t=>{const{subcontextCallbacks:e}=this._buildSubcontextsTaskFactory(this._api,{context:t,contextOptional:a,contextModule:this._args.contextModule,subset:this._args.subset,transactionParser:this._args.parser,deviceModelId:this._args.deviceModelId}).run();return{context:t,subcontextCallbacks:e}}),s=[];for(const t of r)if(s.push(t),t.context.type===u.TRANSACTION_FIELD_DESCRIPTION&&t.context.reference?.type===p.CALLDATA){const{subsets:e}=this._preBuildNestedCallDataTaskFactory({parser:this._args.parser,subset:this._args.subset,context:t.context}).run();for(const l of e){const{clearSignContexts:c}=await new i(this._api,{...this._args,subset:l},this._buildSubcontextsTaskFactory,this._buildBaseContextsTaskFactory,this._preBuildNestedCallDataTaskFactory).run();s.push(...c)}}return{clearSignContexts:s,clearSigningType:o}}}export{i as BuildFullContextsTask};
2
2
  //# sourceMappingURL=BuildFullContextsTask.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/internal/app-binder/task/BuildFullContextsTask.ts"],
4
- "sourcesContent": ["import {\n type ClearSignContext,\n ClearSignContextReferenceType,\n type ClearSignContextSuccess,\n ClearSignContextType,\n type ContextModule,\n type TransactionSubset,\n} from \"@ledgerhq/context-module\";\nimport {\n type DeviceModelId,\n type InternalApi,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { type GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\nimport { type ClearSigningType } from \"@api/model/ClearSigningType\";\nimport { type TransactionOptions } from \"@api/model/TransactionOptions\";\nimport { type TransactionMapperService } from \"@internal/transaction/service/mapper/TransactionMapperService\";\nimport { type TransactionParserService } from \"@internal/transaction/service/parser/TransactionParserService\";\n\nimport {\n BuildBaseContexts,\n type BuildBaseContextsArgs,\n} from \"./BuildBaseContexts\";\nimport {\n BuildSubcontextsTask,\n type BuildSubcontextsTaskArgs,\n} from \"./BuildSubcontextsTask\";\nimport {\n ParseNestedTransactionTask,\n type ParseNestedTransactionTaskArgs,\n} from \"./ParseNestedTransactionTask\";\n\nexport type BuildFullContextsTaskResult = {\n readonly clearSignContexts: ContextWithSubContexts[];\n readonly clearSigningType: ClearSigningType;\n};\n\nexport type BuildFullContextsTaskArgs = {\n readonly contextModule: ContextModule;\n readonly mapper: TransactionMapperService;\n readonly parser: TransactionParserService;\n readonly options: TransactionOptions;\n readonly appConfig: GetConfigCommandResponse;\n readonly derivationPath: string;\n readonly subset: TransactionSubset;\n readonly deviceModelId: DeviceModelId;\n readonly transaction?: Uint8Array;\n};\n\nexport type ContextWithSubContexts = {\n context: ClearSignContextSuccess;\n subcontextCallbacks: (() => Promise<ClearSignContext>)[];\n};\n\nexport class BuildFullContextsTask {\n constructor(\n private readonly _api: InternalApi,\n private readonly _args: BuildFullContextsTaskArgs,\n private readonly _buildSubcontextsTaskFactory = (\n api: InternalApi,\n args: BuildSubcontextsTaskArgs,\n ) => new BuildSubcontextsTask(api, args),\n private readonly _buildBaseContextsTaskFactory = (\n api: InternalApi,\n args: BuildBaseContextsArgs,\n ) => new BuildBaseContexts(api, args),\n private readonly _preBuildNestedCallDataTaskFactory = (\n args: ParseNestedTransactionTaskArgs,\n ) => new ParseNestedTransactionTask(args),\n ) {}\n\n async run(): Promise<BuildFullContextsTaskResult> {\n // get the base contexts\n const { clearSignContexts, clearSigningType, clearSignContextsOptional } =\n await this._buildBaseContextsTaskFactory(this._api, this._args).run();\n\n // for each context, build the subcontexts\n const contextsWithSubContexts: ContextWithSubContexts[] =\n clearSignContexts.map((context: ClearSignContextSuccess) => {\n const { subcontextCallbacks } = this._buildSubcontextsTaskFactory(\n this._api,\n {\n context,\n contextOptional: clearSignContextsOptional,\n contextModule: this._args.contextModule,\n subset: this._args.subset,\n transactionParser: this._args.parser,\n deviceModelId: this._args.deviceModelId,\n },\n ).run();\n\n return {\n context,\n subcontextCallbacks,\n };\n });\n\n // recursively build the nested contexts\n let contextWithNestedContexts: ContextWithSubContexts[] = [];\n for (const context of contextsWithSubContexts) {\n if (\n context.context.type ===\n ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION &&\n context.context.reference?.type ===\n ClearSignContextReferenceType.CALLDATA\n ) {\n const { subsets } = this._preBuildNestedCallDataTaskFactory({\n parser: this._args.parser,\n subset: this._args.subset,\n context: context.context,\n }).run();\n\n for (const subset of subsets) {\n const { clearSignContexts: nestedContexts } =\n await new BuildFullContextsTask(\n this._api,\n {\n ...this._args,\n subset,\n },\n // inject the factories for testing\n this._buildSubcontextsTaskFactory,\n this._buildBaseContextsTaskFactory,\n this._preBuildNestedCallDataTaskFactory,\n ).run();\n\n // TODO: this order will change with app optimizations\n // currently the order is:\n // previous contexts, nested transaction info and nested fields, calldata field from the parent,\n // futurre order:\n // previous contexts, nested transaction info, calldata field from the parent, then nested fields\n contextWithNestedContexts = [\n ...contextWithNestedContexts, // previous contexts\n ...nestedContexts, // nested transaction info and nested fields\n context, // calldatafield from the parent,\n ];\n }\n } else {\n contextWithNestedContexts.push(context);\n }\n }\n\n return {\n clearSignContexts: contextWithNestedContexts,\n clearSigningType,\n };\n }\n}\n"],
5
- "mappings": "AAAA,OAEE,iCAAAA,EAEA,wBAAAC,MAGK,2BAYP,OACE,qBAAAC,MAEK,sBACP,OACE,wBAAAC,MAEK,yBACP,OACE,8BAAAC,MAEK,+BAwBA,MAAMC,CAAsB,CACjC,YACmBC,EACAC,EACAC,EAA+B,CAC9CC,EACAC,IACG,IAAIP,EAAqBM,EAAKC,CAAI,EACtBC,EAAgC,CAC/CF,EACAC,IACG,IAAIR,EAAkBO,EAAKC,CAAI,EACnBE,EACfF,GACG,IAAIN,EAA2BM,CAAI,EACxC,CAbiB,UAAAJ,EACA,WAAAC,EACA,kCAAAC,EAIA,mCAAAG,EAIA,wCAAAC,CAGhB,CAEH,MAAM,KAA4C,CAEhD,KAAM,CAAE,kBAAAC,EAAmB,iBAAAC,EAAkB,0BAAAC,CAA0B,EACrE,MAAM,KAAK,8BAA8B,KAAK,KAAM,KAAK,KAAK,EAAE,IAAI,EAGhEC,EACJH,EAAkB,IAAKI,GAAqC,CAC1D,KAAM,CAAE,oBAAAC,CAAoB,EAAI,KAAK,6BACnC,KAAK,KACL,CACE,QAAAD,EACA,gBAAiBF,EACjB,cAAe,KAAK,MAAM,cAC1B,OAAQ,KAAK,MAAM,OACnB,kBAAmB,KAAK,MAAM,OAC9B,cAAe,KAAK,MAAM,aAC5B,CACF,EAAE,IAAI,EAEN,MAAO,CACL,QAAAE,EACA,oBAAAC,CACF,CACF,CAAC,EAGH,IAAIC,EAAsD,CAAC,EAC3D,UAAWF,KAAWD,EACpB,GACEC,EAAQ,QAAQ,OACdhB,EAAqB,+BACvBgB,EAAQ,QAAQ,WAAW,OACzBjB,EAA8B,SAChC,CACA,KAAM,CAAE,QAAAoB,CAAQ,EAAI,KAAK,mCAAmC,CAC1D,OAAQ,KAAK,MAAM,OACnB,OAAQ,KAAK,MAAM,OACnB,QAASH,EAAQ,OACnB,CAAC,EAAE,IAAI,EAEP,UAAWI,KAAUD,EAAS,CAC5B,KAAM,CAAE,kBAAmBE,CAAe,EACxC,MAAM,IAAIjB,EACR,KAAK,KACL,CACE,GAAG,KAAK,MACR,OAAAgB,CACF,EAEA,KAAK,6BACL,KAAK,8BACL,KAAK,kCACP,EAAE,IAAI,EAORF,EAA4B,CAC1B,GAAGA,EACH,GAAGG,EACHL,CACF,CACF,CACF,MACEE,EAA0B,KAAKF,CAAO,EAI1C,MAAO,CACL,kBAAmBE,EACnB,iBAAAL,CACF,CACF,CACF",
4
+ "sourcesContent": ["import {\n type ClearSignContext,\n ClearSignContextReferenceType,\n type ClearSignContextSuccess,\n ClearSignContextType,\n type ContextModule,\n type TransactionSubset,\n} from \"@ledgerhq/context-module\";\nimport {\n type DeviceModelId,\n type InternalApi,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { type GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\nimport { type ClearSigningType } from \"@api/model/ClearSigningType\";\nimport { type TransactionOptions } from \"@api/model/TransactionOptions\";\nimport { type TransactionMapperService } from \"@internal/transaction/service/mapper/TransactionMapperService\";\nimport { type TransactionParserService } from \"@internal/transaction/service/parser/TransactionParserService\";\n\nimport {\n BuildBaseContexts,\n type BuildBaseContextsArgs,\n} from \"./BuildBaseContexts\";\nimport {\n BuildSubcontextsTask,\n type BuildSubcontextsTaskArgs,\n} from \"./BuildSubcontextsTask\";\nimport {\n ParseNestedTransactionTask,\n type ParseNestedTransactionTaskArgs,\n} from \"./ParseNestedTransactionTask\";\n\nexport type BuildFullContextsTaskResult = {\n readonly clearSignContexts: ContextWithSubContexts[];\n readonly clearSigningType: ClearSigningType;\n};\n\nexport type BuildFullContextsTaskArgs = {\n readonly contextModule: ContextModule;\n readonly mapper: TransactionMapperService;\n readonly parser: TransactionParserService;\n readonly options: TransactionOptions;\n readonly appConfig: GetConfigCommandResponse;\n readonly derivationPath: string;\n readonly subset: TransactionSubset;\n readonly deviceModelId: DeviceModelId;\n readonly transaction?: Uint8Array;\n};\n\nexport type ContextWithSubContexts = {\n context: ClearSignContextSuccess;\n subcontextCallbacks: (() => Promise<ClearSignContext>)[];\n};\n\nexport class BuildFullContextsTask {\n constructor(\n private readonly _api: InternalApi,\n private readonly _args: BuildFullContextsTaskArgs,\n private readonly _buildSubcontextsTaskFactory = (\n api: InternalApi,\n args: BuildSubcontextsTaskArgs,\n ) => new BuildSubcontextsTask(api, args),\n private readonly _buildBaseContextsTaskFactory = (\n api: InternalApi,\n args: BuildBaseContextsArgs,\n ) => new BuildBaseContexts(api, args),\n private readonly _preBuildNestedCallDataTaskFactory = (\n args: ParseNestedTransactionTaskArgs,\n ) => new ParseNestedTransactionTask(args),\n ) {}\n\n async run(): Promise<BuildFullContextsTaskResult> {\n // get the base contexts\n const { clearSignContexts, clearSigningType, clearSignContextsOptional } =\n await this._buildBaseContextsTaskFactory(this._api, this._args).run();\n\n // for each context, build the subcontexts\n const contextsWithSubContexts: ContextWithSubContexts[] =\n clearSignContexts.map((context: ClearSignContextSuccess) => {\n const { subcontextCallbacks } = this._buildSubcontextsTaskFactory(\n this._api,\n {\n context,\n contextOptional: clearSignContextsOptional,\n contextModule: this._args.contextModule,\n subset: this._args.subset,\n transactionParser: this._args.parser,\n deviceModelId: this._args.deviceModelId,\n },\n ).run();\n\n return {\n context,\n subcontextCallbacks,\n };\n });\n\n // recursively build the nested contexts\n const contextWithNestedContexts: ContextWithSubContexts[] = [];\n for (const context of contextsWithSubContexts) {\n contextWithNestedContexts.push(context);\n\n if (\n context.context.type ===\n ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION &&\n context.context.reference?.type ===\n ClearSignContextReferenceType.CALLDATA\n ) {\n const { subsets } = this._preBuildNestedCallDataTaskFactory({\n parser: this._args.parser,\n subset: this._args.subset,\n context: context.context,\n }).run();\n\n for (const subset of subsets) {\n const { clearSignContexts: nestedContexts } =\n await new BuildFullContextsTask(\n this._api,\n {\n ...this._args,\n subset,\n },\n // inject the factories for testing\n this._buildSubcontextsTaskFactory,\n this._buildBaseContextsTaskFactory,\n this._preBuildNestedCallDataTaskFactory,\n ).run();\n\n // Contexts order as expected by the Ethereum application:\n // * previous contexts\n // * calldata field from the parent\n // * list of nested transactions infos and nested fields\n contextWithNestedContexts.push(...nestedContexts);\n }\n }\n }\n\n return {\n clearSignContexts: contextWithNestedContexts,\n clearSigningType,\n };\n }\n}\n"],
5
+ "mappings": "AAAA,OAEE,iCAAAA,EAEA,wBAAAC,MAGK,2BAYP,OACE,qBAAAC,MAEK,sBACP,OACE,wBAAAC,MAEK,yBACP,OACE,8BAAAC,MAEK,+BAwBA,MAAMC,CAAsB,CACjC,YACmBC,EACAC,EACAC,EAA+B,CAC9CC,EACAC,IACG,IAAIP,EAAqBM,EAAKC,CAAI,EACtBC,EAAgC,CAC/CF,EACAC,IACG,IAAIR,EAAkBO,EAAKC,CAAI,EACnBE,EACfF,GACG,IAAIN,EAA2BM,CAAI,EACxC,CAbiB,UAAAJ,EACA,WAAAC,EACA,kCAAAC,EAIA,mCAAAG,EAIA,wCAAAC,CAGhB,CAEH,MAAM,KAA4C,CAEhD,KAAM,CAAE,kBAAAC,EAAmB,iBAAAC,EAAkB,0BAAAC,CAA0B,EACrE,MAAM,KAAK,8BAA8B,KAAK,KAAM,KAAK,KAAK,EAAE,IAAI,EAGhEC,EACJH,EAAkB,IAAKI,GAAqC,CAC1D,KAAM,CAAE,oBAAAC,CAAoB,EAAI,KAAK,6BACnC,KAAK,KACL,CACE,QAAAD,EACA,gBAAiBF,EACjB,cAAe,KAAK,MAAM,cAC1B,OAAQ,KAAK,MAAM,OACnB,kBAAmB,KAAK,MAAM,OAC9B,cAAe,KAAK,MAAM,aAC5B,CACF,EAAE,IAAI,EAEN,MAAO,CACL,QAAAE,EACA,oBAAAC,CACF,CACF,CAAC,EAGGC,EAAsD,CAAC,EAC7D,UAAWF,KAAWD,EAGpB,GAFAG,EAA0B,KAAKF,CAAO,EAGpCA,EAAQ,QAAQ,OACdhB,EAAqB,+BACvBgB,EAAQ,QAAQ,WAAW,OACzBjB,EAA8B,SAChC,CACA,KAAM,CAAE,QAAAoB,CAAQ,EAAI,KAAK,mCAAmC,CAC1D,OAAQ,KAAK,MAAM,OACnB,OAAQ,KAAK,MAAM,OACnB,QAASH,EAAQ,OACnB,CAAC,EAAE,IAAI,EAEP,UAAWI,KAAUD,EAAS,CAC5B,KAAM,CAAE,kBAAmBE,CAAe,EACxC,MAAM,IAAIjB,EACR,KAAK,KACL,CACE,GAAG,KAAK,MACR,OAAAgB,CACF,EAEA,KAAK,6BACL,KAAK,8BACL,KAAK,kCACP,EAAE,IAAI,EAMRF,EAA0B,KAAK,GAAGG,CAAc,CAClD,CACF,CAGF,MAAO,CACL,kBAAmBH,EACnB,iBAAAL,CACF,CACF,CACF",
6
6
  "names": ["ClearSignContextReferenceType", "ClearSignContextType", "BuildBaseContexts", "BuildSubcontextsTask", "ParseNestedTransactionTask", "BuildFullContextsTask", "_api", "_args", "_buildSubcontextsTaskFactory", "api", "args", "_buildBaseContextsTaskFactory", "_preBuildNestedCallDataTaskFactory", "clearSignContexts", "clearSigningType", "clearSignContextsOptional", "contextsWithSubContexts", "context", "subcontextCallbacks", "contextWithNestedContexts", "subsets", "subset", "nestedContexts"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{ClearSignContextReferenceType as b,ClearSignContextType as e}from"@ledgerhq/context-module";import{DeviceModelId as x}from"@ledgerhq/device-management-kit";import{ClearSigningType as o}from"../../../api/model/ClearSigningType";import{makeDeviceActionInternalApiMock as A}from"../../app-binder/device-action/__test-utils__/makeInternalApi";import{BuildBaseContexts as N}from"./BuildBaseContexts";import{BuildFullContextsTask as T}from"./BuildFullContextsTask";import{BuildSubcontextsTask as g}from"./BuildSubcontextsTask";import{ParseNestedTransactionTask as O}from"./ParseNestedTransactionTask";describe("BuildFullContextsTask",()=>{const n=A(),c={},l={},p={},i={blindSigningEnabled:!1,web3ChecksEnabled:!1,web3ChecksOptIn:!1,version:"1.0.0"},r={},d={chainId:1,data:"0x",selector:"0x"},u="44'/60'/0'/0/0",y=vi.fn(),C=(a,t)=>({run:y}),s=vi.fn(),S=(a,t)=>({run:s}),k=vi.fn(),I=a=>({run:k});describe("Init",()=>{it("should init with defaults tasks",()=>{const a=new T(n,{contextModule:c,mapper:l,parser:p,options:r,appConfig:i,derivationPath:u,subset:d,deviceModelId:x.STAX});expect(a).toBeDefined(),expect(a._buildSubcontextsTaskFactory(n,{})).toBeInstanceOf(g),expect(a._buildBaseContextsTaskFactory(n,{})).toBeInstanceOf(N),expect(a._preBuildNestedCallDataTaskFactory({})).toBeInstanceOf(O)})}),describe("Happy path",()=>{beforeEach(()=>{vi.resetAllMocks()}),it("should build with no context",async()=>{s.mockReturnValue({clearSignContexts:[],clearSignContextsOptional:[],clearSigningType:o.BASIC});const t=await new T(n,{contextModule:c,mapper:l,parser:p,options:r,appConfig:i,derivationPath:u,subset:d,deviceModelId:x.STAX},C,S,I).run();expect(t).toEqual({clearSignContexts:[],clearSigningType:o.BASIC})}),it("should build with multiple contexts and no subcontexts",async()=>{s.mockReturnValueOnce({clearSignContexts:[{type:e.TRANSACTION_INFO,payload:"payload-1"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"}],clearSigningType:o.EIP7730}),y.mockReturnValue({subcontextCallbacks:[]});const t=await new T(n,{contextModule:c,mapper:l,parser:p,options:r,appConfig:i,derivationPath:u,subset:d,deviceModelId:x.STAX},C,S,I).run();expect(t).toEqual({clearSignContexts:[{context:{type:e.TRANSACTION_INFO,payload:"payload-1"},subcontextCallbacks:[]},{context:{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},subcontextCallbacks:[]},{context:{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},subcontextCallbacks:[]}],clearSigningType:o.EIP7730})}),it("should build with multiple contexts and subcontexts",async()=>{s.mockReturnValueOnce({clearSignContexts:[{type:e.TRANSACTION_INFO,payload:"payload-1"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"}],clearSignContextsOptional:[],clearSigningType:o.EIP7730}),y.mockReturnValueOnce({subcontextCallbacks:[]}),y.mockReturnValueOnce({subcontextCallbacks:[()=>Promise.resolve({type:e.TOKEN,payload:"payload-3"}),()=>Promise.resolve({type:e.TOKEN,payload:"payload-4"})]});const t=await new T(n,{contextModule:c,mapper:l,parser:p,options:r,appConfig:i,derivationPath:u,subset:d,deviceModelId:x.STAX},C,S,I).run();expect(t.clearSignContexts[0]).toEqual({context:{type:e.TRANSACTION_INFO,payload:"payload-1"},subcontextCallbacks:[]}),expect(t.clearSignContexts[1]).toEqual({context:{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},subcontextCallbacks:[expect.any(Function),expect.any(Function)]}),await expect(t.clearSignContexts[1].subcontextCallbacks[0]()).resolves.toEqual({type:e.TOKEN,payload:"payload-3"}),await expect(t.clearSignContexts[1].subcontextCallbacks[1]()).resolves.toEqual({type:e.TOKEN,payload:"payload-4"})}),it("should build with nested contexts",async()=>{s.mockReturnValueOnce({clearSignContexts:[{type:e.TRANSACTION_INFO,payload:"payload-1"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2",reference:{type:b.CALLDATA,subset:{chainId:1,data:"0x",selector:"0x"}}}],clearSigningType:o.EIP7730}),s.mockReturnValueOnce({clearSignContexts:[{type:e.TRANSACTION_INFO,payload:"payload-3"},{type:e.TOKEN,payload:"payload-4"}],clearSignContextsOptional:[],clearSigningType:o.EIP7730}),y.mockReturnValue({subcontextCallbacks:[]}),k.mockReturnValue({subsets:[{chainId:1,data:"0x",selector:"0x"}]});const t=await new T(n,{contextModule:c,mapper:l,parser:p,options:r,appConfig:i,derivationPath:u,subset:d,deviceModelId:x.STAX},C,S,I).run();expect(t).toEqual({clearSignContexts:expect.any(Array),clearSigningType:o.EIP7730}),expect(t.clearSignContexts[0]).toEqual({context:{type:e.TRANSACTION_INFO,payload:"payload-1"},subcontextCallbacks:[]}),expect(t.clearSignContexts[1]).toEqual({context:{type:e.TRANSACTION_INFO,payload:"payload-3"},subcontextCallbacks:[]}),expect(t.clearSignContexts[2]).toEqual({context:{type:e.TOKEN,payload:"payload-4"},subcontextCallbacks:[]}),expect(t.clearSignContexts[3]).toEqual({context:{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2",reference:{type:b.CALLDATA,subset:{chainId:1,data:"0x",selector:"0x"}}},subcontextCallbacks:[]})})})});
1
+ import{ClearSignContextReferenceType as b,ClearSignContextType as e}from"@ledgerhq/context-module";import{DeviceModelId as x}from"@ledgerhq/device-management-kit";import{ClearSigningType as o}from"../../../api/model/ClearSigningType";import{makeDeviceActionInternalApiMock as A}from"../../app-binder/device-action/__test-utils__/makeInternalApi";import{BuildBaseContexts as N}from"./BuildBaseContexts";import{BuildFullContextsTask as T}from"./BuildFullContextsTask";import{BuildSubcontextsTask as g}from"./BuildSubcontextsTask";import{ParseNestedTransactionTask as O}from"./ParseNestedTransactionTask";describe("BuildFullContextsTask",()=>{const n=A(),c={},l={},p={},i={blindSigningEnabled:!1,web3ChecksEnabled:!1,web3ChecksOptIn:!1,version:"1.0.0"},r={},d={chainId:1,data:"0x",selector:"0x"},u="44'/60'/0'/0/0",y=vi.fn(),C=(a,t)=>({run:y}),s=vi.fn(),S=(a,t)=>({run:s}),k=vi.fn(),I=a=>({run:k});describe("Init",()=>{it("should init with defaults tasks",()=>{const a=new T(n,{contextModule:c,mapper:l,parser:p,options:r,appConfig:i,derivationPath:u,subset:d,deviceModelId:x.STAX});expect(a).toBeDefined(),expect(a._buildSubcontextsTaskFactory(n,{})).toBeInstanceOf(g),expect(a._buildBaseContextsTaskFactory(n,{})).toBeInstanceOf(N),expect(a._preBuildNestedCallDataTaskFactory({})).toBeInstanceOf(O)})}),describe("Happy path",()=>{beforeEach(()=>{vi.resetAllMocks()}),it("should build with no context",async()=>{s.mockReturnValue({clearSignContexts:[],clearSignContextsOptional:[],clearSigningType:o.BASIC});const t=await new T(n,{contextModule:c,mapper:l,parser:p,options:r,appConfig:i,derivationPath:u,subset:d,deviceModelId:x.STAX},C,S,I).run();expect(t).toEqual({clearSignContexts:[],clearSigningType:o.BASIC})}),it("should build with multiple contexts and no subcontexts",async()=>{s.mockReturnValueOnce({clearSignContexts:[{type:e.TRANSACTION_INFO,payload:"payload-1"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"}],clearSigningType:o.EIP7730}),y.mockReturnValue({subcontextCallbacks:[]});const t=await new T(n,{contextModule:c,mapper:l,parser:p,options:r,appConfig:i,derivationPath:u,subset:d,deviceModelId:x.STAX},C,S,I).run();expect(t).toEqual({clearSignContexts:[{context:{type:e.TRANSACTION_INFO,payload:"payload-1"},subcontextCallbacks:[]},{context:{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},subcontextCallbacks:[]},{context:{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},subcontextCallbacks:[]}],clearSigningType:o.EIP7730})}),it("should build with multiple contexts and subcontexts",async()=>{s.mockReturnValueOnce({clearSignContexts:[{type:e.TRANSACTION_INFO,payload:"payload-1"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"}],clearSignContextsOptional:[],clearSigningType:o.EIP7730}),y.mockReturnValueOnce({subcontextCallbacks:[]}),y.mockReturnValueOnce({subcontextCallbacks:[()=>Promise.resolve({type:e.TOKEN,payload:"payload-3"}),()=>Promise.resolve({type:e.TOKEN,payload:"payload-4"})]});const t=await new T(n,{contextModule:c,mapper:l,parser:p,options:r,appConfig:i,derivationPath:u,subset:d,deviceModelId:x.STAX},C,S,I).run();expect(t.clearSignContexts[0]).toEqual({context:{type:e.TRANSACTION_INFO,payload:"payload-1"},subcontextCallbacks:[]}),expect(t.clearSignContexts[1]).toEqual({context:{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},subcontextCallbacks:[expect.any(Function),expect.any(Function)]}),await expect(t.clearSignContexts[1].subcontextCallbacks[0]()).resolves.toEqual({type:e.TOKEN,payload:"payload-3"}),await expect(t.clearSignContexts[1].subcontextCallbacks[1]()).resolves.toEqual({type:e.TOKEN,payload:"payload-4"})}),it("should build with nested contexts",async()=>{s.mockReturnValueOnce({clearSignContexts:[{type:e.TRANSACTION_INFO,payload:"payload-1"},{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2",reference:{type:b.CALLDATA,subset:{chainId:1,data:"0x",selector:"0x"}}}],clearSigningType:o.EIP7730}),s.mockReturnValueOnce({clearSignContexts:[{type:e.TRANSACTION_INFO,payload:"payload-3"},{type:e.TOKEN,payload:"payload-4"}],clearSignContextsOptional:[],clearSigningType:o.EIP7730}),y.mockReturnValue({subcontextCallbacks:[]}),k.mockReturnValue({subsets:[{chainId:1,data:"0x",selector:"0x"}]});const t=await new T(n,{contextModule:c,mapper:l,parser:p,options:r,appConfig:i,derivationPath:u,subset:d,deviceModelId:x.STAX},C,S,I).run();expect(t).toEqual({clearSignContexts:expect.any(Array),clearSigningType:o.EIP7730}),expect(t.clearSignContexts[0]).toEqual({context:{type:e.TRANSACTION_INFO,payload:"payload-1"},subcontextCallbacks:[]}),expect(t.clearSignContexts[1]).toEqual({context:{type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2",reference:{type:b.CALLDATA,subset:{chainId:1,data:"0x",selector:"0x"}}},subcontextCallbacks:[]}),expect(t.clearSignContexts[2]).toEqual({context:{type:e.TRANSACTION_INFO,payload:"payload-3"},subcontextCallbacks:[]}),expect(t.clearSignContexts[3]).toEqual({context:{type:e.TOKEN,payload:"payload-4"},subcontextCallbacks:[]})})})});
2
2
  //# sourceMappingURL=BuildFullContextsTask.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/internal/app-binder/task/BuildFullContextsTask.test.ts"],
4
- "sourcesContent": ["import {\n ClearSignContextReferenceType,\n ClearSignContextType,\n type ContextModule,\n type TransactionSubset,\n} from \"@ledgerhq/context-module\";\nimport {\n DeviceModelId,\n type InternalApi,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { type GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\nimport { type TransactionOptions } from \"@api/index\";\nimport { ClearSigningType } from \"@api/model/ClearSigningType\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\nimport { type TransactionMapperService } from \"@internal/transaction/service/mapper/TransactionMapperService\";\nimport { type TransactionParserService } from \"@internal/transaction/service/parser/TransactionParserService\";\n\nimport {\n BuildBaseContexts,\n type BuildBaseContextsArgs,\n} from \"./BuildBaseContexts\";\nimport { BuildFullContextsTask } from \"./BuildFullContextsTask\";\nimport {\n BuildSubcontextsTask,\n type BuildSubcontextsTaskArgs,\n} from \"./BuildSubcontextsTask\";\nimport {\n ParseNestedTransactionTask,\n type ParseNestedTransactionTaskArgs,\n} from \"./ParseNestedTransactionTask\";\n\ndescribe(\"BuildFullContextsTask\", () => {\n const apiMock = makeDeviceActionInternalApiMock();\n const contextModuleMock = {} as ContextModule;\n const mapperMock = {} as TransactionMapperService;\n const parserMock = {} as TransactionParserService;\n\n const defaultAppConfig: GetConfigCommandResponse = {\n blindSigningEnabled: false,\n web3ChecksEnabled: false,\n web3ChecksOptIn: false,\n version: \"1.0.0\",\n };\n const defaultOptions: TransactionOptions = {};\n const defaultSubset: TransactionSubset = {\n chainId: 1,\n data: \"0x\",\n selector: \"0x\",\n };\n const defaultDerivationPath = \"44'/60'/0'/0/0\";\n\n const buildSubContextTaskRunMock = vi.fn();\n const buildSubcontextsTaskFactory = (\n _api: InternalApi,\n _args: BuildSubcontextsTaskArgs,\n ) =>\n ({\n run: buildSubContextTaskRunMock,\n }) as unknown as BuildSubcontextsTask;\n\n const buildBaseContextsTaskRunMock = vi.fn();\n const buildBaseContextsTaskFactory = (\n _api: InternalApi,\n _args: BuildBaseContextsArgs,\n ) =>\n ({\n run: buildBaseContextsTaskRunMock,\n }) as unknown as BuildBaseContexts;\n\n const parseNestedTransactionTaskRunMock = vi.fn();\n const parseNestedTransactionTaskFactory = (\n _args: ParseNestedTransactionTaskArgs,\n ) =>\n ({\n run: parseNestedTransactionTaskRunMock,\n }) as unknown as ParseNestedTransactionTask;\n\n describe(\"Init\", () => {\n it(\"should init with defaults tasks\", () => {\n const task = new BuildFullContextsTask(apiMock, {\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n options: defaultOptions,\n appConfig: defaultAppConfig,\n derivationPath: defaultDerivationPath,\n subset: defaultSubset,\n deviceModelId: DeviceModelId.STAX,\n });\n\n expect(task).toBeDefined();\n expect(\n task[\"_buildSubcontextsTaskFactory\"](\n apiMock,\n {} as BuildSubcontextsTaskArgs,\n ),\n ).toBeInstanceOf(BuildSubcontextsTask);\n expect(\n task[\"_buildBaseContextsTaskFactory\"](\n apiMock,\n {} as BuildBaseContextsArgs,\n ),\n ).toBeInstanceOf(BuildBaseContexts);\n expect(\n task[\"_preBuildNestedCallDataTaskFactory\"](\n {} as ParseNestedTransactionTaskArgs,\n ),\n ).toBeInstanceOf(ParseNestedTransactionTask);\n });\n });\n\n describe(\"Happy path\", () => {\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n it(\"should build with no context\", async () => {\n // GIVEN\n buildBaseContextsTaskRunMock.mockReturnValue({\n clearSignContexts: [],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n\n const task = new BuildFullContextsTask(\n apiMock,\n {\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n options: defaultOptions,\n appConfig: defaultAppConfig,\n derivationPath: defaultDerivationPath,\n subset: defaultSubset,\n deviceModelId: DeviceModelId.STAX,\n },\n buildSubcontextsTaskFactory,\n buildBaseContextsTaskFactory,\n parseNestedTransactionTaskFactory,\n );\n\n // WHEN\n const result = await task.run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should build with multiple contexts and no subcontexts\", async () => {\n // GIVEN\n buildBaseContextsTaskRunMock.mockReturnValueOnce({\n clearSignContexts: [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n ],\n clearSigningType: ClearSigningType.EIP7730,\n });\n buildSubContextTaskRunMock.mockReturnValue({\n subcontextCallbacks: [],\n });\n\n const task = new BuildFullContextsTask(\n apiMock,\n {\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n options: defaultOptions,\n appConfig: defaultAppConfig,\n derivationPath: defaultDerivationPath,\n subset: defaultSubset,\n deviceModelId: DeviceModelId.STAX,\n },\n buildSubcontextsTaskFactory,\n buildBaseContextsTaskFactory,\n parseNestedTransactionTaskFactory,\n );\n\n // WHEN\n const result = await task.run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [\n {\n context: {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n },\n subcontextCallbacks: [],\n },\n {\n context: {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n subcontextCallbacks: [],\n },\n {\n context: {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n subcontextCallbacks: [],\n },\n ],\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should build with multiple contexts and subcontexts\", async () => {\n // GIVEN\n buildBaseContextsTaskRunMock.mockReturnValueOnce({\n clearSignContexts: [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n ],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.EIP7730,\n });\n buildSubContextTaskRunMock.mockReturnValueOnce({\n subcontextCallbacks: [],\n });\n buildSubContextTaskRunMock.mockReturnValueOnce({\n subcontextCallbacks: [\n () =>\n Promise.resolve({\n type: ClearSignContextType.TOKEN,\n payload: \"payload-3\",\n }),\n () =>\n Promise.resolve({\n type: ClearSignContextType.TOKEN,\n payload: \"payload-4\",\n }),\n ],\n });\n\n const task = new BuildFullContextsTask(\n apiMock,\n {\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n options: defaultOptions,\n appConfig: defaultAppConfig,\n derivationPath: defaultDerivationPath,\n subset: defaultSubset,\n deviceModelId: DeviceModelId.STAX,\n },\n buildSubcontextsTaskFactory,\n buildBaseContextsTaskFactory,\n parseNestedTransactionTaskFactory,\n );\n\n // WHEN\n const result = await task.run();\n\n // THEN\n expect(result.clearSignContexts[0]).toEqual({\n context: {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n },\n subcontextCallbacks: [],\n });\n expect(result.clearSignContexts[1]).toEqual({\n context: {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n subcontextCallbacks: [expect.any(Function), expect.any(Function)],\n });\n await expect(\n result.clearSignContexts[1]!.subcontextCallbacks[0]!(),\n ).resolves.toEqual({\n type: ClearSignContextType.TOKEN,\n payload: \"payload-3\",\n });\n await expect(\n result.clearSignContexts[1]!.subcontextCallbacks[1]!(),\n ).resolves.toEqual({\n type: ClearSignContextType.TOKEN,\n payload: \"payload-4\",\n });\n });\n\n it(\"should build with nested contexts\", async () => {\n // GIVEN\n buildBaseContextsTaskRunMock.mockReturnValueOnce({\n clearSignContexts: [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n reference: {\n type: ClearSignContextReferenceType.CALLDATA,\n subset: {\n chainId: 1,\n data: \"0x\",\n selector: \"0x\",\n },\n },\n },\n ],\n clearSigningType: ClearSigningType.EIP7730,\n });\n // nested context\n buildBaseContextsTaskRunMock.mockReturnValueOnce({\n clearSignContexts: [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-4\",\n },\n ],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.EIP7730,\n });\n buildSubContextTaskRunMock.mockReturnValue({\n subcontextCallbacks: [],\n });\n parseNestedTransactionTaskRunMock.mockReturnValue({\n subsets: [\n {\n chainId: 1,\n data: \"0x\",\n selector: \"0x\",\n },\n ],\n });\n\n const task = new BuildFullContextsTask(\n apiMock,\n {\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n options: defaultOptions,\n appConfig: defaultAppConfig,\n derivationPath: defaultDerivationPath,\n subset: defaultSubset,\n deviceModelId: DeviceModelId.STAX,\n },\n buildSubcontextsTaskFactory,\n buildBaseContextsTaskFactory,\n parseNestedTransactionTaskFactory,\n );\n\n // WHEN\n const result = await task.run();\n\n // THEN\n expect(result).toEqual({\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n clearSignContexts: expect.any(Array),\n clearSigningType: ClearSigningType.EIP7730,\n });\n expect(result.clearSignContexts[0]).toEqual({\n context: {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n },\n subcontextCallbacks: [],\n });\n expect(result.clearSignContexts[1]).toEqual({\n context: {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-3\",\n },\n subcontextCallbacks: [],\n });\n expect(result.clearSignContexts[2]).toEqual({\n context: {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-4\",\n },\n subcontextCallbacks: [],\n });\n expect(result.clearSignContexts[3]).toEqual({\n context: {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n reference: {\n type: ClearSignContextReferenceType.CALLDATA,\n subset: {\n chainId: 1,\n data: \"0x\",\n selector: \"0x\",\n },\n },\n },\n subcontextCallbacks: [],\n });\n });\n });\n});\n"],
5
- "mappings": "AAAA,OACE,iCAAAA,EACA,wBAAAC,MAGK,2BACP,OACE,iBAAAC,MAEK,kCAIP,OAAS,oBAAAC,MAAwB,8BACjC,OAAS,mCAAAC,MAAuC,oEAIhD,OACE,qBAAAC,MAEK,sBACP,OAAS,yBAAAC,MAA6B,0BACtC,OACE,wBAAAC,MAEK,yBACP,OACE,8BAAAC,MAEK,+BAEP,SAAS,wBAAyB,IAAM,CACtC,MAAMC,EAAUL,EAAgC,EAC1CM,EAAoB,CAAC,EACrBC,EAAa,CAAC,EACdC,EAAa,CAAC,EAEdC,EAA6C,CACjD,oBAAqB,GACrB,kBAAmB,GACnB,gBAAiB,GACjB,QAAS,OACX,EACMC,EAAqC,CAAC,EACtCC,EAAmC,CACvC,QAAS,EACT,KAAM,KACN,SAAU,IACZ,EACMC,EAAwB,iBAExBC,EAA6B,GAAG,GAAG,EACnCC,EAA8B,CAClCC,EACAC,KAEC,CACC,IAAKH,CACP,GAEII,EAA+B,GAAG,GAAG,EACrCC,EAA+B,CACnCH,EACAC,KAEC,CACC,IAAKC,CACP,GAEIE,EAAoC,GAAG,GAAG,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ACF,CAAC,EAoBD,MAAMG,EAAS,MAlBF,IAAIpB,EACfG,EACA,CACE,cAAeC,EACf,OAAQC,EACR,OAAQC,EACR,QAASE,EACT,UAAWD,EACX,eAAgBG,EAChB,OAAQD,EACR,cAAeb,EAAc,IAC/B,EACAgB,EACAI,EACAE,CACF,EAG0B,IAAI,EAG9B,OAAOE,CAAM,EAAE,QAAQ,CAErB,kBAAmB,OAAO,IAAI,KAAK,EACnC,iBAAkBvB,EAAiB,OACrC,CAAC,EACD,OAAOuB,EAAO,kBAAkB,CAAC,CAAC,EAAE,QAAQ,CAC1C,QAAS,CACP,KAAMzB,EAAqB,iBAC3B,QAAS,WACX,EACA,oBAAqB,CAAC,CACxB,CAAC,EACD,OAAOyB,EAAO,kBAAkB,CAAC,CAAC,EAAE,QAAQ,CAC1C,QAAS,CACP,KAAMzB,EAAqB,iBAC3B,QAAS,WACX,EACA,oBAAqB,CAAC,CACxB,CAAC,EACD,OAAOyB,EAAO,kBAAkB,CAAC,CAAC,EAAE,QAAQ,CAC1C,QAAS,CACP,KAAMzB,EAAqB,MAC3B,QAAS,WACX,EACA,oBAAqB,CAAC,CACxB,CAAC,EACD,OAAOyB,EAAO,kBAAkB,CAAC,CAAC,EAAE,QAAQ,CAC1C,QAAS,CACP,KAAMzB,EAAqB,8BAC3B,QAAS,YACT,UAAW,CACT,KAAMD,EAA8B,SACpC,OAAQ,CACN,QAAS,EACT,KAAM,KACN,SAAU,IACZ,CACF,CACF,EACA,oBAAqB,CAAC,CACxB,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
4
+ "sourcesContent": ["import {\n ClearSignContextReferenceType,\n ClearSignContextType,\n type ContextModule,\n type TransactionSubset,\n} from \"@ledgerhq/context-module\";\nimport {\n DeviceModelId,\n type InternalApi,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { type GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\nimport { type TransactionOptions } from \"@api/index\";\nimport { ClearSigningType } from \"@api/model/ClearSigningType\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\nimport { type TransactionMapperService } from \"@internal/transaction/service/mapper/TransactionMapperService\";\nimport { type TransactionParserService } from \"@internal/transaction/service/parser/TransactionParserService\";\n\nimport {\n BuildBaseContexts,\n type BuildBaseContextsArgs,\n} from \"./BuildBaseContexts\";\nimport { BuildFullContextsTask } from \"./BuildFullContextsTask\";\nimport {\n BuildSubcontextsTask,\n type BuildSubcontextsTaskArgs,\n} from \"./BuildSubcontextsTask\";\nimport {\n ParseNestedTransactionTask,\n type ParseNestedTransactionTaskArgs,\n} from \"./ParseNestedTransactionTask\";\n\ndescribe(\"BuildFullContextsTask\", () => {\n const apiMock = makeDeviceActionInternalApiMock();\n const contextModuleMock = {} as ContextModule;\n const mapperMock = {} as TransactionMapperService;\n const parserMock = {} as TransactionParserService;\n\n const defaultAppConfig: GetConfigCommandResponse = {\n blindSigningEnabled: false,\n web3ChecksEnabled: false,\n web3ChecksOptIn: false,\n version: \"1.0.0\",\n };\n const defaultOptions: TransactionOptions = {};\n const defaultSubset: TransactionSubset = {\n chainId: 1,\n data: \"0x\",\n selector: \"0x\",\n };\n const defaultDerivationPath = \"44'/60'/0'/0/0\";\n\n const buildSubContextTaskRunMock = vi.fn();\n const buildSubcontextsTaskFactory = (\n _api: InternalApi,\n _args: BuildSubcontextsTaskArgs,\n ) =>\n ({\n run: buildSubContextTaskRunMock,\n }) as unknown as BuildSubcontextsTask;\n\n const buildBaseContextsTaskRunMock = vi.fn();\n const buildBaseContextsTaskFactory = (\n _api: InternalApi,\n _args: BuildBaseContextsArgs,\n ) =>\n ({\n run: buildBaseContextsTaskRunMock,\n }) as unknown as BuildBaseContexts;\n\n const parseNestedTransactionTaskRunMock = vi.fn();\n const parseNestedTransactionTaskFactory = (\n _args: ParseNestedTransactionTaskArgs,\n ) =>\n ({\n run: parseNestedTransactionTaskRunMock,\n }) as unknown as ParseNestedTransactionTask;\n\n describe(\"Init\", () => {\n it(\"should init with defaults tasks\", () => {\n const task = new BuildFullContextsTask(apiMock, {\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n options: defaultOptions,\n appConfig: defaultAppConfig,\n derivationPath: defaultDerivationPath,\n subset: defaultSubset,\n deviceModelId: DeviceModelId.STAX,\n });\n\n expect(task).toBeDefined();\n expect(\n task[\"_buildSubcontextsTaskFactory\"](\n apiMock,\n {} as BuildSubcontextsTaskArgs,\n ),\n ).toBeInstanceOf(BuildSubcontextsTask);\n expect(\n task[\"_buildBaseContextsTaskFactory\"](\n apiMock,\n {} as BuildBaseContextsArgs,\n ),\n ).toBeInstanceOf(BuildBaseContexts);\n expect(\n task[\"_preBuildNestedCallDataTaskFactory\"](\n {} as ParseNestedTransactionTaskArgs,\n ),\n ).toBeInstanceOf(ParseNestedTransactionTask);\n });\n });\n\n describe(\"Happy path\", () => {\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n it(\"should build with no context\", async () => {\n // GIVEN\n buildBaseContextsTaskRunMock.mockReturnValue({\n clearSignContexts: [],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n\n const task = new BuildFullContextsTask(\n apiMock,\n {\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n options: defaultOptions,\n appConfig: defaultAppConfig,\n derivationPath: defaultDerivationPath,\n subset: defaultSubset,\n deviceModelId: DeviceModelId.STAX,\n },\n buildSubcontextsTaskFactory,\n buildBaseContextsTaskFactory,\n parseNestedTransactionTaskFactory,\n );\n\n // WHEN\n const result = await task.run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should build with multiple contexts and no subcontexts\", async () => {\n // GIVEN\n buildBaseContextsTaskRunMock.mockReturnValueOnce({\n clearSignContexts: [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n ],\n clearSigningType: ClearSigningType.EIP7730,\n });\n buildSubContextTaskRunMock.mockReturnValue({\n subcontextCallbacks: [],\n });\n\n const task = new BuildFullContextsTask(\n apiMock,\n {\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n options: defaultOptions,\n appConfig: defaultAppConfig,\n derivationPath: defaultDerivationPath,\n subset: defaultSubset,\n deviceModelId: DeviceModelId.STAX,\n },\n buildSubcontextsTaskFactory,\n buildBaseContextsTaskFactory,\n parseNestedTransactionTaskFactory,\n );\n\n // WHEN\n const result = await task.run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [\n {\n context: {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n },\n subcontextCallbacks: [],\n },\n {\n context: {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n subcontextCallbacks: [],\n },\n {\n context: {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n subcontextCallbacks: [],\n },\n ],\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should build with multiple contexts and subcontexts\", async () => {\n // GIVEN\n buildBaseContextsTaskRunMock.mockReturnValueOnce({\n clearSignContexts: [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n ],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.EIP7730,\n });\n buildSubContextTaskRunMock.mockReturnValueOnce({\n subcontextCallbacks: [],\n });\n buildSubContextTaskRunMock.mockReturnValueOnce({\n subcontextCallbacks: [\n () =>\n Promise.resolve({\n type: ClearSignContextType.TOKEN,\n payload: \"payload-3\",\n }),\n () =>\n Promise.resolve({\n type: ClearSignContextType.TOKEN,\n payload: \"payload-4\",\n }),\n ],\n });\n\n const task = new BuildFullContextsTask(\n apiMock,\n {\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n options: defaultOptions,\n appConfig: defaultAppConfig,\n derivationPath: defaultDerivationPath,\n subset: defaultSubset,\n deviceModelId: DeviceModelId.STAX,\n },\n buildSubcontextsTaskFactory,\n buildBaseContextsTaskFactory,\n parseNestedTransactionTaskFactory,\n );\n\n // WHEN\n const result = await task.run();\n\n // THEN\n expect(result.clearSignContexts[0]).toEqual({\n context: {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n },\n subcontextCallbacks: [],\n });\n expect(result.clearSignContexts[1]).toEqual({\n context: {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n subcontextCallbacks: [expect.any(Function), expect.any(Function)],\n });\n await expect(\n result.clearSignContexts[1]!.subcontextCallbacks[0]!(),\n ).resolves.toEqual({\n type: ClearSignContextType.TOKEN,\n payload: \"payload-3\",\n });\n await expect(\n result.clearSignContexts[1]!.subcontextCallbacks[1]!(),\n ).resolves.toEqual({\n type: ClearSignContextType.TOKEN,\n payload: \"payload-4\",\n });\n });\n\n it(\"should build with nested contexts\", async () => {\n // GIVEN\n buildBaseContextsTaskRunMock.mockReturnValueOnce({\n clearSignContexts: [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n reference: {\n type: ClearSignContextReferenceType.CALLDATA,\n subset: {\n chainId: 1,\n data: \"0x\",\n selector: \"0x\",\n },\n },\n },\n ],\n clearSigningType: ClearSigningType.EIP7730,\n });\n // nested context\n buildBaseContextsTaskRunMock.mockReturnValueOnce({\n clearSignContexts: [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-4\",\n },\n ],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.EIP7730,\n });\n buildSubContextTaskRunMock.mockReturnValue({\n subcontextCallbacks: [],\n });\n parseNestedTransactionTaskRunMock.mockReturnValue({\n subsets: [\n {\n chainId: 1,\n data: \"0x\",\n selector: \"0x\",\n },\n ],\n });\n\n const task = new BuildFullContextsTask(\n apiMock,\n {\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n options: defaultOptions,\n appConfig: defaultAppConfig,\n derivationPath: defaultDerivationPath,\n subset: defaultSubset,\n deviceModelId: DeviceModelId.STAX,\n },\n buildSubcontextsTaskFactory,\n buildBaseContextsTaskFactory,\n parseNestedTransactionTaskFactory,\n );\n\n // WHEN\n const result = await task.run();\n\n // THEN\n expect(result).toEqual({\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n clearSignContexts: expect.any(Array),\n clearSigningType: ClearSigningType.EIP7730,\n });\n expect(result.clearSignContexts[0]).toEqual({\n context: {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n },\n subcontextCallbacks: [],\n });\n expect(result.clearSignContexts[1]).toEqual({\n context: {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n reference: {\n type: ClearSignContextReferenceType.CALLDATA,\n subset: {\n chainId: 1,\n data: \"0x\",\n selector: \"0x\",\n },\n },\n },\n subcontextCallbacks: [],\n });\n expect(result.clearSignContexts[2]).toEqual({\n context: {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-3\",\n },\n subcontextCallbacks: [],\n });\n expect(result.clearSignContexts[3]).toEqual({\n context: {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-4\",\n },\n subcontextCallbacks: [],\n });\n });\n });\n});\n"],
5
+ "mappings": "AAAA,OACE,iCAAAA,EACA,wBAAAC,MAGK,2BACP,OACE,iBAAAC,MAEK,kCAIP,OAAS,oBAAAC,MAAwB,8B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BAAqB,CAAC,CACxB,CAAC,EACD,OAAO0B,EAAO,kBAAkB,CAAC,CAAC,EAAE,QAAQ,CAC1C,QAAS,CACP,KAAMzB,EAAqB,iBAC3B,QAAS,WACX,EACA,oBAAqB,CAAC,CACxB,CAAC,EACD,OAAOyB,EAAO,kBAAkB,CAAC,CAAC,EAAE,QAAQ,CAC1C,QAAS,CACP,KAAMzB,EAAqB,MAC3B,QAAS,WACX,EACA,oBAAqB,CAAC,CACxB,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
6
  "names": ["ClearSignContextReferenceType", "ClearSignContextType", "DeviceModelId", "ClearSigningType", "makeDeviceActionInternalApiMock", "BuildBaseContexts", "BuildFullContextsTask", "BuildSubcontextsTask", "ParseNestedTransactionTask", "apiMock", "contextModuleMock", "mapperMock", "parserMock", "defaultAppConfig", "defaultOptions", "defaultSubset", "defaultDerivationPath", "buildSubContextTaskRunMock", "buildSubcontextsTaskFactory", "_api", "_args", "buildBaseContextsTaskRunMock", "buildBaseContextsTaskFactory", "parseNestedTransactionTaskRunMock", "parseNestedTransactionTaskFactory", "task", "result"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{ClearSignContextReferenceType as r,ClearSignContextType as n}from"@ledgerhq/context-module";import{ContextFieldLoaderKind as c}from"@ledgerhq/context-module/src/shared/domain/ContextFieldLoader.js";import{bufferToHexaString as d,isSuccessCommandResult as x}from"@ledgerhq/device-management-kit";import{GetChallengeCommand as C}from"../../app-binder/command/GetChallengeCommand";class T{constructor(e,t){this.api=e;this.args=t}run(){const e=this.args.context,t=e.type;switch(t){case n.TRANSACTION_INFO:case n.WEB3_CHECK:case n.PLUGIN:case n.EXTERNAL_PLUGIN:case n.DYNAMIC_NETWORK:case n.DYNAMIC_NETWORK_ICON:case n.ENUM:case n.TRUSTED_NAME:case n.TOKEN:case n.NFT:return{subcontextCallbacks:[]};case n.TRANSACTION_FIELD_DESCRIPTION:return{subcontextCallbacks:e.reference?this._getSubcontextsFromReference(e.reference):[]};case n.PROXY_DELEGATE_CALL:return{subcontextCallbacks:this._getSubcontextFromProxy(e)};default:{const a=t;throw new Error(`Uncovered type: ${a}`)}}}_getSubcontextsFromReference(e){const t=e.type;switch(t){case r.TOKEN:case r.NFT:return this._getSubcontextsFromTokenOrNftReference(e);case r.ENUM:return this._getSubcontextsFromEnumReference(e);case r.TRUSTED_NAME:return this._getSubcontextsFromTrustedNameReference(e);case r.CALLDATA:return[];default:{const a=t;throw new Error(`Uncovered reference type: ${a}`)}}}_getSubcontextsFromTokenOrNftReference(e){if(e.value!==void 0){const a={kind:e.type===r.TOKEN?c.TOKEN:c.NFT,chainId:this.args.subset.chainId,address:e.value};return[()=>this.args.contextModule.getFieldContext(a)]}const t=[];if(e.valuePath!==void 0){const a=this.args.transactionParser.extractValue(this.args.subset,e.valuePath).orDefault([]);for(const s of a){const o=d(s.slice(Math.max(0,s.length-20)));t.push(()=>this.args.contextModule.getFieldContext({kind:e.type===r.TOKEN?c.TOKEN:c.NFT,chainId:this.args.subset.chainId,address:o}))}}return t}_getSubcontextsFromEnumReference(e){const t=[];if(!e.valuePath)return t;const a=this.args.transactionParser.extractValue(this.args.subset,e.valuePath).orDefault([]);for(const s of a){const o=s[s.length-1];if(o===void 0)continue;const u=this.args.contextOptional.filter(l=>l.type===n.ENUM).find(l=>l.value===o&&l.id===e.id);u&&t.push(()=>Promise.resolve(u))}return t}_getSubcontextsFromTrustedNameReference(e){const t=[];if(!e.valuePath)return t;const a=this.args.transactionParser.extractValue(this.args.subset,e.valuePath).orDefault([]);for(const s of a)t.push(async()=>{const o=d(s.slice(Math.max(0,s.length-20))),i=await this.api.sendCommand(new C);return x(i)?await this.args.contextModule.getFieldContext({kind:c.TRUSTED_NAME,chainId:this.args.subset.chainId,address:o,challenge:i.data.challenge,types:e.types,sources:e.sources}):{type:n.ERROR,error:new Error("Failed to get challenge")}});return t}_getSubcontextFromProxy(e){return[async()=>{const t=await this.api.sendCommand(new C);return x(t)?this.args.subset.to===void 0?{type:n.ERROR,error:new Error("Failed to get proxy address")}:await this.args.contextModule.getFieldContext({kind:c.PROXY_DELEGATE_CALL,chainId:this.args.subset.chainId,proxyAddress:this.args.subset.to,calldata:this.args.subset.data,deviceModelId:this.args.deviceModelId,challenge:t.data.challenge}):{type:n.ERROR,error:new Error("Failed to get challenge")}}]}}export{T as BuildSubcontextsTask};
1
+ import{ClearSignContextReferenceType as r,ClearSignContextType as t}from"@ledgerhq/context-module";import{bufferToHexaString as i,isSuccessCommandResult as d}from"@ledgerhq/device-management-kit";import{GetChallengeCommand as x}from"../../app-binder/command/GetChallengeCommand";class h{constructor(e,n){this.api=e;this.args=n}run(){const e=this.args.context,n=e.type;switch(n){case t.TRANSACTION_INFO:case t.WEB3_CHECK:case t.PLUGIN:case t.EXTERNAL_PLUGIN:case t.DYNAMIC_NETWORK:case t.DYNAMIC_NETWORK_ICON:case t.ENUM:case t.TRUSTED_NAME:case t.TOKEN:case t.NFT:return{subcontextCallbacks:[]};case t.TRANSACTION_FIELD_DESCRIPTION:return{subcontextCallbacks:e.reference?this._getSubcontextsFromReference(e.reference):[]};case t.PROXY_INFO:return{subcontextCallbacks:this._getSubcontextFromProxy(e)};default:{const a=n;throw new Error(`Uncovered type: ${a}`)}}}_getSubcontextsFromReference(e){const n=e.type;switch(n){case r.TOKEN:case r.NFT:return this._getSubcontextsFromTokenOrNftReference(e);case r.ENUM:return this._getSubcontextsFromEnumReference(e);case r.TRUSTED_NAME:return this._getSubcontextsFromTrustedNameReference(e);case r.CALLDATA:return[];default:{const a=n;throw new Error(`Uncovered reference type: ${a}`)}}}_getSubcontextsFromTokenOrNftReference(e){if(e.value!==void 0){const a={chainId:this.args.subset.chainId,address:e.value},s=e.type===r.TOKEN?t.TOKEN:t.NFT;return[()=>this.args.contextModule.getFieldContext(a,s)]}const n=[];if(e.valuePath!==void 0){const a=this.args.transactionParser.extractValue(this.args.subset,e.valuePath).orDefault([]);for(const s of a){const o=i(s.slice(Math.max(0,s.length-20))),c=e.type===r.TOKEN?t.TOKEN:t.NFT;n.push(()=>this.args.contextModule.getFieldContext({chainId:this.args.subset.chainId,address:o},c))}}return n}_getSubcontextsFromEnumReference(e){const n=[];if(!e.valuePath)return n;const a=this.args.transactionParser.extractValue(this.args.subset,e.valuePath).orDefault([]);for(const s of a){const o=s[s.length-1];if(o===void 0)continue;const u=this.args.contextOptional.filter(l=>l.type===t.ENUM).find(l=>l.value===o&&l.id===e.id);u&&n.push(()=>Promise.resolve(u))}return n}_getSubcontextsFromTrustedNameReference(e){const n=[];if(!e.valuePath)return n;const a=this.args.transactionParser.extractValue(this.args.subset,e.valuePath).orDefault([]);for(const s of a)n.push(async()=>{const o=i(s.slice(Math.max(0,s.length-20))),c=await this.api.sendCommand(new x);return d(c)?await this.args.contextModule.getFieldContext({chainId:this.args.subset.chainId,address:o,challenge:c.data.challenge,types:e.types,sources:e.sources},t.TRUSTED_NAME):{type:t.ERROR,error:new Error("Failed to get challenge")}});return n}_getSubcontextFromProxy(e){return[async()=>{const n=await this.api.sendCommand(new x);return d(n)?this.args.subset.to===void 0?{type:t.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.PROXY_INFO):{type:t.ERROR,error:new Error("Failed to get challenge")}}]}}export{h as BuildSubcontextsTask};
2
2
  //# sourceMappingURL=BuildSubcontextsTask.js.map