@ledgerhq/device-signer-kit-ethereum 0.0.0-multisig-20250905101831 → 0.0.0-multisig-20250918154034

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 (119) 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/app-binder/SignTypedDataDeviceActionTypes.js +1 -1
  4. package/lib/cjs/api/app-binder/SignTypedDataDeviceActionTypes.js.map +2 -2
  5. package/lib/cjs/api/index.js +1 -1
  6. package/lib/cjs/api/index.js.map +3 -3
  7. package/lib/cjs/internal/app-binder/EthAppBinder.js +1 -1
  8. package/lib/cjs/internal/app-binder/EthAppBinder.js.map +2 -2
  9. package/lib/cjs/internal/app-binder/EthAppBinder.test.js +1 -1
  10. package/lib/cjs/internal/app-binder/EthAppBinder.test.js.map +2 -2
  11. package/lib/cjs/internal/app-binder/command/SendEIP712FilteringCommand.js +1 -1
  12. package/lib/cjs/internal/app-binder/command/SendEIP712FilteringCommand.js.map +3 -3
  13. package/lib/cjs/internal/app-binder/command/SendEIP712FilteringCommand.test.js +1 -1
  14. package/lib/cjs/internal/app-binder/command/SendEIP712FilteringCommand.test.js.map +3 -3
  15. package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js +1 -1
  16. package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js.map +3 -3
  17. package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js +1 -1
  18. package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js.map +3 -3
  19. package/lib/cjs/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.js +1 -1
  20. package/lib/cjs/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.js.map +2 -2
  21. package/lib/cjs/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.test.js +1 -1
  22. package/lib/cjs/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.test.js.map +3 -3
  23. package/lib/cjs/internal/app-binder/task/BuildBaseContexts.test.js +1 -1
  24. package/lib/cjs/internal/app-binder/task/BuildBaseContexts.test.js.map +2 -2
  25. package/lib/cjs/internal/app-binder/task/BuildEIP712ContextTask.js +1 -1
  26. package/lib/cjs/internal/app-binder/task/BuildEIP712ContextTask.js.map +3 -3
  27. package/lib/cjs/internal/app-binder/task/BuildEIP712ContextTask.test.js +1 -1
  28. package/lib/cjs/internal/app-binder/task/BuildEIP712ContextTask.test.js.map +3 -3
  29. package/lib/cjs/internal/app-binder/task/BuildFullContextsTask.js +1 -1
  30. package/lib/cjs/internal/app-binder/task/BuildFullContextsTask.js.map +2 -2
  31. package/lib/cjs/internal/app-binder/task/BuildFullContextsTask.test.js +1 -1
  32. package/lib/cjs/internal/app-binder/task/BuildFullContextsTask.test.js.map +2 -2
  33. package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.js +1 -1
  34. package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.js.map +3 -3
  35. package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.test.js +1 -1
  36. package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.test.js.map +3 -3
  37. package/lib/cjs/internal/app-binder/task/ParseTransactionTask.test.js +2 -0
  38. package/lib/cjs/internal/app-binder/task/ParseTransactionTask.test.js.map +7 -0
  39. package/lib/cjs/internal/app-binder/task/ProvideContextsTask.js +1 -1
  40. package/lib/cjs/internal/app-binder/task/ProvideContextsTask.js.map +2 -2
  41. package/lib/cjs/internal/app-binder/task/ProvideContextsTask.test.js +1 -1
  42. package/lib/cjs/internal/app-binder/task/ProvideContextsTask.test.js.map +2 -2
  43. package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.js +1 -1
  44. package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.js.map +3 -3
  45. package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.test.js +1 -1
  46. package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.test.js.map +3 -3
  47. package/lib/cjs/package.json +1 -1
  48. package/lib/esm/api/app-binder/SignTransactionDeviceActionTypes.js +1 -1
  49. package/lib/esm/api/app-binder/SignTransactionDeviceActionTypes.js.map +2 -2
  50. package/lib/esm/api/app-binder/SignTypedDataDeviceActionTypes.js +1 -1
  51. package/lib/esm/api/app-binder/SignTypedDataDeviceActionTypes.js.map +2 -2
  52. package/lib/esm/api/index.js +1 -1
  53. package/lib/esm/api/index.js.map +2 -2
  54. package/lib/esm/internal/app-binder/EthAppBinder.js +1 -1
  55. package/lib/esm/internal/app-binder/EthAppBinder.js.map +2 -2
  56. package/lib/esm/internal/app-binder/EthAppBinder.test.js +1 -1
  57. package/lib/esm/internal/app-binder/EthAppBinder.test.js.map +2 -2
  58. package/lib/esm/internal/app-binder/command/SendEIP712FilteringCommand.js +1 -1
  59. package/lib/esm/internal/app-binder/command/SendEIP712FilteringCommand.js.map +3 -3
  60. package/lib/esm/internal/app-binder/command/SendEIP712FilteringCommand.test.js +1 -1
  61. package/lib/esm/internal/app-binder/command/SendEIP712FilteringCommand.test.js.map +3 -3
  62. package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js +1 -1
  63. package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js.map +3 -3
  64. package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js +1 -1
  65. package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js.map +3 -3
  66. package/lib/esm/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.js +1 -1
  67. package/lib/esm/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.js.map +2 -2
  68. package/lib/esm/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.test.js +1 -1
  69. package/lib/esm/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.test.js.map +3 -3
  70. package/lib/esm/internal/app-binder/task/BuildBaseContexts.test.js +1 -1
  71. package/lib/esm/internal/app-binder/task/BuildBaseContexts.test.js.map +2 -2
  72. package/lib/esm/internal/app-binder/task/BuildEIP712ContextTask.js +1 -1
  73. package/lib/esm/internal/app-binder/task/BuildEIP712ContextTask.js.map +3 -3
  74. package/lib/esm/internal/app-binder/task/BuildEIP712ContextTask.test.js +1 -1
  75. package/lib/esm/internal/app-binder/task/BuildEIP712ContextTask.test.js.map +3 -3
  76. package/lib/esm/internal/app-binder/task/BuildFullContextsTask.js +1 -1
  77. package/lib/esm/internal/app-binder/task/BuildFullContextsTask.js.map +2 -2
  78. package/lib/esm/internal/app-binder/task/BuildFullContextsTask.test.js +1 -1
  79. package/lib/esm/internal/app-binder/task/BuildFullContextsTask.test.js.map +2 -2
  80. package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.js +1 -1
  81. package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.js.map +2 -2
  82. package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.test.js +1 -1
  83. package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.test.js.map +2 -2
  84. package/lib/esm/internal/app-binder/task/ParseTransactionTask.test.js +2 -0
  85. package/lib/esm/internal/app-binder/task/ParseTransactionTask.test.js.map +7 -0
  86. package/lib/esm/internal/app-binder/task/ProvideContextsTask.js +1 -1
  87. package/lib/esm/internal/app-binder/task/ProvideContextsTask.js.map +2 -2
  88. package/lib/esm/internal/app-binder/task/ProvideContextsTask.test.js +1 -1
  89. package/lib/esm/internal/app-binder/task/ProvideContextsTask.test.js.map +2 -2
  90. package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.js +1 -1
  91. package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.js.map +3 -3
  92. package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.test.js +1 -1
  93. package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.test.js.map +3 -3
  94. package/lib/esm/package.json +1 -1
  95. package/lib/types/api/app-binder/SignTransactionDeviceActionTypes.d.ts +2 -1
  96. package/lib/types/api/app-binder/SignTransactionDeviceActionTypes.d.ts.map +1 -1
  97. package/lib/types/api/app-binder/SignTypedDataDeviceActionTypes.d.ts +4 -0
  98. package/lib/types/api/app-binder/SignTypedDataDeviceActionTypes.d.ts.map +1 -1
  99. package/lib/types/api/index.d.ts +5 -9
  100. package/lib/types/api/index.d.ts.map +1 -1
  101. package/lib/types/internal/app-binder/EthAppBinder.d.ts.map +1 -1
  102. package/lib/types/internal/app-binder/command/SendEIP712FilteringCommand.d.ts +29 -1
  103. package/lib/types/internal/app-binder/command/SendEIP712FilteringCommand.d.ts.map +1 -1
  104. package/lib/types/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.d.ts +1 -1
  105. package/lib/types/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.d.ts.map +1 -1
  106. package/lib/types/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.d.ts +4 -0
  107. package/lib/types/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.d.ts.map +1 -1
  108. package/lib/types/internal/app-binder/task/BuildEIP712ContextTask.d.ts +8 -1
  109. package/lib/types/internal/app-binder/task/BuildEIP712ContextTask.d.ts.map +1 -1
  110. package/lib/types/internal/app-binder/task/BuildFullContextsTask.d.ts.map +1 -1
  111. package/lib/types/internal/app-binder/task/BuildSubcontextsTask.d.ts.map +1 -1
  112. package/lib/types/internal/app-binder/task/ParseTransactionTask.test.d.ts +2 -0
  113. package/lib/types/internal/app-binder/task/ParseTransactionTask.test.d.ts.map +1 -0
  114. package/lib/types/internal/app-binder/task/ProvideContextsTask.d.ts +3 -1
  115. package/lib/types/internal/app-binder/task/ProvideContextsTask.d.ts.map +1 -1
  116. package/lib/types/internal/app-binder/task/ProvideEIP712ContextTask.d.ts +12 -2
  117. package/lib/types/internal/app-binder/task/ProvideEIP712ContextTask.d.ts.map +1 -1
  118. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  119. package/package.json +8 -8
@@ -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": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,2BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAOO,oCAYPC,EAGO,+BACPC,EAGO,kCACPC,EAGO,wCAwBA,MAAML,CAAsB,CACjC,YACmBM,EACAC,EACAC,EAA+B,CAC9CC,EACAC,IACG,IAAI,uBAAqBD,EAAKC,CAAI,EACtBC,EAAgC,CAC/CF,EACAC,IACG,IAAI,oBAAkBD,EAAKC,CAAI,EACnBE,EACfF,GACG,IAAI,6BAA2BA,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,OACd,uBAAqB,+BACvBA,EAAQ,QAAQ,WAAW,OACzB,gCAA8B,SAChC,CACA,KAAM,CAAE,QAAAG,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,IAAItB,EACR,KAAK,KACL,CACE,GAAG,KAAK,MACR,OAAAqB,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": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,2BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAOO,oCAYPC,EAGO,+BACPC,EAGO,kCACPC,EAGO,wCAwBA,MAAML,CAAsB,CACjC,YACmBM,EACAC,EACAC,EAA+B,CAC9CC,EACAC,IACG,IAAI,uBAAqBD,EAAKC,CAAI,EACtBC,EAAgC,CAC/CF,EACAC,IACG,IAAI,oBAAkBD,EAAKC,CAAI,EACnBE,EACfF,GACG,IAAI,6BAA2BA,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,OACd,uBAAqB,+BACvBA,EAAQ,QAAQ,WAAW,OACzB,gCAA8B,SAChC,CACA,KAAM,CAAE,QAAAG,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,IAAItB,EACR,KAAK,KACL,CACE,GAAG,KAAK,MACR,OAAAqB,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": ["BuildFullContextsTask_exports", "__export", "BuildFullContextsTask", "__toCommonJS", "import_context_module", "import_BuildBaseContexts", "import_BuildSubcontextsTask", "import_ParseNestedTransactionTask", "_api", "_args", "_buildSubcontextsTaskFactory", "api", "args", "_buildBaseContextsTaskFactory", "_preBuildNestedCallDataTaskFactory", "clearSignContexts", "clearSigningType", "clearSignContextsOptional", "contextsWithSubContexts", "context", "subcontextCallbacks", "contextWithNestedContexts", "subsets", "subset", "nestedContexts"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("@ledgerhq/context-module"),c=require("@ledgerhq/device-management-kit"),o=require("../../../api/model/ClearSigningType"),b=require("../../app-binder/device-action/__test-utils__/makeInternalApi"),A=require("./BuildBaseContexts"),l=require("./BuildFullContextsTask"),N=require("./BuildSubcontextsTask"),g=require("./ParseNestedTransactionTask");describe("BuildFullContextsTask",()=>{const n=(0,b.makeDeviceActionInternalApiMock)(),p={},i={},r={},d={blindSigningEnabled:!1,web3ChecksEnabled:!1,web3ChecksOptIn:!1,version:"1.0.0"},u={},y={chainId:1,data:"0x",selector:"0x"},x="44'/60'/0'/0/0",T=vi.fn(),C=(a,t)=>({run:T}),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 l.BuildFullContextsTask(n,{contextModule:p,mapper:i,parser:r,options:u,appConfig:d,derivationPath:x,subset:y,deviceModelId:c.DeviceModelId.STAX});expect(a).toBeDefined(),expect(a._buildSubcontextsTaskFactory(n,{})).toBeInstanceOf(N.BuildSubcontextsTask),expect(a._buildBaseContextsTaskFactory(n,{})).toBeInstanceOf(A.BuildBaseContexts),expect(a._preBuildNestedCallDataTaskFactory({})).toBeInstanceOf(g.ParseNestedTransactionTask)})}),describe("Happy path",()=>{beforeEach(()=>{vi.resetAllMocks()}),it("should build with no context",async()=>{s.mockReturnValue({clearSignContexts:[],clearSignContextsOptional:[],clearSigningType:o.ClearSigningType.BASIC});const t=await new l.BuildFullContextsTask(n,{contextModule:p,mapper:i,parser:r,options:u,appConfig:d,derivationPath:x,subset:y,deviceModelId:c.DeviceModelId.STAX},C,S,I).run();expect(t).toEqual({clearSignContexts:[],clearSigningType:o.ClearSigningType.BASIC})}),it("should build with multiple contexts and no subcontexts",async()=>{s.mockReturnValueOnce({clearSignContexts:[{type:e.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1"},{type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"}],clearSigningType:o.ClearSigningType.EIP7730}),T.mockReturnValue({subcontextCallbacks:[]});const t=await new l.BuildFullContextsTask(n,{contextModule:p,mapper:i,parser:r,options:u,appConfig:d,derivationPath:x,subset:y,deviceModelId:c.DeviceModelId.STAX},C,S,I).run();expect(t).toEqual({clearSignContexts:[{context:{type:e.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1"},subcontextCallbacks:[]},{context:{type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},subcontextCallbacks:[]},{context:{type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},subcontextCallbacks:[]}],clearSigningType:o.ClearSigningType.EIP7730})}),it("should build with multiple contexts and subcontexts",async()=>{s.mockReturnValueOnce({clearSignContexts:[{type:e.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1"},{type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"}],clearSignContextsOptional:[],clearSigningType:o.ClearSigningType.EIP7730}),T.mockReturnValueOnce({subcontextCallbacks:[]}),T.mockReturnValueOnce({subcontextCallbacks:[()=>Promise.resolve({type:e.ClearSignContextType.TOKEN,payload:"payload-3"}),()=>Promise.resolve({type:e.ClearSignContextType.TOKEN,payload:"payload-4"})]});const t=await new l.BuildFullContextsTask(n,{contextModule:p,mapper:i,parser:r,options:u,appConfig:d,derivationPath:x,subset:y,deviceModelId:c.DeviceModelId.STAX},C,S,I).run();expect(t.clearSignContexts[0]).toEqual({context:{type:e.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1"},subcontextCallbacks:[]}),expect(t.clearSignContexts[1]).toEqual({context:{type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},subcontextCallbacks:[expect.any(Function),expect.any(Function)]}),expect(t.clearSignContexts[1].subcontextCallbacks[0]()).resolves.toEqual({type:e.ClearSignContextType.TOKEN,payload:"payload-3"}),expect(t.clearSignContexts[1].subcontextCallbacks[1]()).resolves.toEqual({type:e.ClearSignContextType.TOKEN,payload:"payload-4"})}),it("should build with nested contexts",async()=>{s.mockReturnValueOnce({clearSignContexts:[{type:e.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1"},{type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2",reference:{type:e.ClearSignContextReferenceType.CALLDATA,subset:{chainId:1,data:"0x",selector:"0x"}}}],clearSigningType:o.ClearSigningType.EIP7730}),s.mockReturnValueOnce({clearSignContexts:[{type:e.ClearSignContextType.TRANSACTION_INFO,payload:"payload-3"},{type:e.ClearSignContextType.TOKEN,payload:"payload-4"}],clearSignContextsOptional:[],clearSigningType:o.ClearSigningType.EIP7730}),T.mockReturnValue({subcontextCallbacks:[]}),k.mockReturnValue({subsets:[{chainId:1,data:"0x",selector:"0x"}]});const t=await new l.BuildFullContextsTask(n,{contextModule:p,mapper:i,parser:r,options:u,appConfig:d,derivationPath:x,subset:y,deviceModelId:c.DeviceModelId.STAX},C,S,I).run();expect(t).toEqual({clearSignContexts:expect.any(Array),clearSigningType:o.ClearSigningType.EIP7730}),expect(t.clearSignContexts[0]).toEqual({context:{type:e.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1"},subcontextCallbacks:[]}),expect(t.clearSignContexts[1]).toEqual({context:{type:e.ClearSignContextType.TRANSACTION_INFO,payload:"payload-3"},subcontextCallbacks:[]}),expect(t.clearSignContexts[2]).toEqual({context:{type:e.ClearSignContextType.TOKEN,payload:"payload-4"},subcontextCallbacks:[]}),expect(t.clearSignContexts[3]).toEqual({context:{type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2",reference:{type:e.ClearSignContextReferenceType.CALLDATA,subset:{chainId:1,data:"0x",selector:"0x"}}},subcontextCallbacks:[]})})})});
1
+ "use strict";var e=require("@ledgerhq/context-module"),c=require("@ledgerhq/device-management-kit"),o=require("../../../api/model/ClearSigningType"),b=require("../../app-binder/device-action/__test-utils__/makeInternalApi"),A=require("./BuildBaseContexts"),l=require("./BuildFullContextsTask"),N=require("./BuildSubcontextsTask"),g=require("./ParseNestedTransactionTask");describe("BuildFullContextsTask",()=>{const n=(0,b.makeDeviceActionInternalApiMock)(),p={},i={},r={},d={blindSigningEnabled:!1,web3ChecksEnabled:!1,web3ChecksOptIn:!1,version:"1.0.0"},u={},y={chainId:1,data:"0x",selector:"0x"},x="44'/60'/0'/0/0",T=vi.fn(),C=(a,t)=>({run:T}),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 l.BuildFullContextsTask(n,{contextModule:p,mapper:i,parser:r,options:u,appConfig:d,derivationPath:x,subset:y,deviceModelId:c.DeviceModelId.STAX});expect(a).toBeDefined(),expect(a._buildSubcontextsTaskFactory(n,{})).toBeInstanceOf(N.BuildSubcontextsTask),expect(a._buildBaseContextsTaskFactory(n,{})).toBeInstanceOf(A.BuildBaseContexts),expect(a._preBuildNestedCallDataTaskFactory({})).toBeInstanceOf(g.ParseNestedTransactionTask)})}),describe("Happy path",()=>{beforeEach(()=>{vi.resetAllMocks()}),it("should build with no context",async()=>{s.mockReturnValue({clearSignContexts:[],clearSignContextsOptional:[],clearSigningType:o.ClearSigningType.BASIC});const t=await new l.BuildFullContextsTask(n,{contextModule:p,mapper:i,parser:r,options:u,appConfig:d,derivationPath:x,subset:y,deviceModelId:c.DeviceModelId.STAX},C,S,I).run();expect(t).toEqual({clearSignContexts:[],clearSigningType:o.ClearSigningType.BASIC})}),it("should build with multiple contexts and no subcontexts",async()=>{s.mockReturnValueOnce({clearSignContexts:[{type:e.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1"},{type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"}],clearSigningType:o.ClearSigningType.EIP7730}),T.mockReturnValue({subcontextCallbacks:[]});const t=await new l.BuildFullContextsTask(n,{contextModule:p,mapper:i,parser:r,options:u,appConfig:d,derivationPath:x,subset:y,deviceModelId:c.DeviceModelId.STAX},C,S,I).run();expect(t).toEqual({clearSignContexts:[{context:{type:e.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1"},subcontextCallbacks:[]},{context:{type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},subcontextCallbacks:[]},{context:{type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},subcontextCallbacks:[]}],clearSigningType:o.ClearSigningType.EIP7730})}),it("should build with multiple contexts and subcontexts",async()=>{s.mockReturnValueOnce({clearSignContexts:[{type:e.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1"},{type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"}],clearSignContextsOptional:[],clearSigningType:o.ClearSigningType.EIP7730}),T.mockReturnValueOnce({subcontextCallbacks:[]}),T.mockReturnValueOnce({subcontextCallbacks:[()=>Promise.resolve({type:e.ClearSignContextType.TOKEN,payload:"payload-3"}),()=>Promise.resolve({type:e.ClearSignContextType.TOKEN,payload:"payload-4"})]});const t=await new l.BuildFullContextsTask(n,{contextModule:p,mapper:i,parser:r,options:u,appConfig:d,derivationPath:x,subset:y,deviceModelId:c.DeviceModelId.STAX},C,S,I).run();expect(t.clearSignContexts[0]).toEqual({context:{type:e.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1"},subcontextCallbacks:[]}),expect(t.clearSignContexts[1]).toEqual({context:{type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},subcontextCallbacks:[expect.any(Function),expect.any(Function)]}),await expect(t.clearSignContexts[1].subcontextCallbacks[0]()).resolves.toEqual({type:e.ClearSignContextType.TOKEN,payload:"payload-3"}),await expect(t.clearSignContexts[1].subcontextCallbacks[1]()).resolves.toEqual({type:e.ClearSignContextType.TOKEN,payload:"payload-4"})}),it("should build with nested contexts",async()=>{s.mockReturnValueOnce({clearSignContexts:[{type:e.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1"},{type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2",reference:{type:e.ClearSignContextReferenceType.CALLDATA,subset:{chainId:1,data:"0x",selector:"0x"}}}],clearSigningType:o.ClearSigningType.EIP7730}),s.mockReturnValueOnce({clearSignContexts:[{type:e.ClearSignContextType.TRANSACTION_INFO,payload:"payload-3"},{type:e.ClearSignContextType.TOKEN,payload:"payload-4"}],clearSignContextsOptional:[],clearSigningType:o.ClearSigningType.EIP7730}),T.mockReturnValue({subcontextCallbacks:[]}),k.mockReturnValue({subsets:[{chainId:1,data:"0x",selector:"0x"}]});const t=await new l.BuildFullContextsTask(n,{contextModule:p,mapper:i,parser:r,options:u,appConfig:d,derivationPath:x,subset:y,deviceModelId:c.DeviceModelId.STAX},C,S,I).run();expect(t).toEqual({clearSignContexts:expect.any(Array),clearSigningType:o.ClearSigningType.EIP7730}),expect(t.clearSignContexts[0]).toEqual({context:{type:e.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1"},subcontextCallbacks:[]}),expect(t.clearSignContexts[1]).toEqual({context:{type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2",reference:{type:e.ClearSignContextReferenceType.CALLDATA,subset:{chainId:1,data:"0x",selector:"0x"}}},subcontextCallbacks:[]}),expect(t.clearSignContexts[2]).toEqual({context:{type:e.ClearSignContextType.TRANSACTION_INFO,payload:"payload-3"},subcontextCallbacks:[]}),expect(t.clearSignContexts[3]).toEqual({context:{type:e.ClearSignContextType.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 expect(\n result.clearSignContexts[1]!.subcontextCallbacks[0]!(),\n ).resolves.toEqual({\n type: ClearSignContextType.TOKEN,\n payload: \"payload-3\",\n });\n 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,IAAAA,EAKO,oCACPC,EAGO,2CAIPC,EAAiC,uCACjCC,EAAgD,6EAIhDC,EAGO,+BACPC,EAAsC,mCACtCC,EAGO,kCACPC,EAGO,wCAEP,SAAS,wBA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A8B,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,IAAAA,EAKO,oCACPC,EAGO,2CAIPC,EAAiC,uCACjCC,EAAgD,6EAIhDC,EAGO,+BACPC,EAAsC,mCACtCC,EAGO,kCACPC,EAGO,wCAEP,SAAS,wBAAyB,IAAM,CACtC,MAAMC,KAAU,mCAAgC,EAC1CC,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,EAC1CC,EACJJ,IAEC,CACC,IAAKG,CACP,GAEF,SAAS,OAAQ,IAAM,CACrB,GAAG,kCAAmC,IAAM,CAC1C,MAAME,EAAO,IAAI,wBAAsBhB,EAAS,CAC9C,cAAeC,EACf,OAAQC,EACR,OAAQC,EACR,QAASE,EACT,UAAWD,EACX,eAAgBG,EAChB,OAAQD,EACR,cAAe,gBAAc,IAC/B,CAAC,EAED,OAAOU,CAAI,EAAE,YAAY,EACzB,OACEA,EAAK,6BACHhB,EACA,CAAC,CACH,CACF,EAAE,eAAe,sBAAoB,EACrC,OACEgB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,iBAC3B,QAAS,WACX,EACA,oBAAqB,CAAC,CACxB,CAAC,EACD,OAAOA,EAAO,kBAAkB,CAAC,CAAC,EAAE,QAAQ,CAC1C,QAAS,CACP,KAAM,uBAAqB,8BAC3B,QAAS,YACT,UAAW,CACT,KAAM,gCAA8B,SACpC,OAAQ,CACN,QAAS,EACT,KAAM,KACN,SAAU,IACZ,CACF,CACF,EACA,oBAAqB,CAAC,CACxB,CAAC,EACD,OAAOA,EAAO,kBAAkB,CAAC,CAAC,EAAE,QAAQ,CAC1C,QAAS,CACP,KAAM,uBAAqB,iBAC3B,QAAS,WACX,EACA,oBAAqB,CAAC,CACxB,CAAC,EACD,OAAOA,EAAO,kBAAkB,CAAC,CAAC,EAAE,QAAQ,CAC1C,QAAS,CACP,KAAM,uBAAqB,MAC3B,QAAS,WACX,EACA,oBAAqB,CAAC,CACxB,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
6
  "names": ["import_context_module", "import_device_management_kit", "import_ClearSigningType", "import_makeInternalApi", "import_BuildBaseContexts", "import_BuildFullContextsTask", "import_BuildSubcontextsTask", "import_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
- "use strict";var d=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var S=(s,e)=>{for(var t in e)d(s,t,{get:e[t],enumerable:!0})},h=(s,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of b(e))!p.call(s,r)&&r!==t&&d(s,r,{get:()=>e[r],enumerable:!(a=g(e,r))||a.enumerable});return s};var T=s=>h(d({},"__esModule",{value:!0}),s);var f={};S(f,{BuildSubcontextsTask:()=>y});module.exports=T(f);var n=require("@ledgerhq/context-module"),c=require("@ledgerhq/context-module/src/shared/domain/ContextFieldLoader.js"),l=require("@ledgerhq/device-management-kit"),C=require("../../app-binder/command/GetChallengeCommand");class y{constructor(e,t){this.api=e;this.args=t}run(){const e=this.args.context,t=e.type;switch(t){case n.ClearSignContextType.TRANSACTION_INFO:case n.ClearSignContextType.WEB3_CHECK:case n.ClearSignContextType.PLUGIN:case n.ClearSignContextType.EXTERNAL_PLUGIN:case n.ClearSignContextType.DYNAMIC_NETWORK:case n.ClearSignContextType.DYNAMIC_NETWORK_ICON:case n.ClearSignContextType.ENUM:case n.ClearSignContextType.TRUSTED_NAME:case n.ClearSignContextType.TOKEN:case n.ClearSignContextType.NFT:return{subcontextCallbacks:[]};case n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:return{subcontextCallbacks:e.reference?this._getSubcontextsFromReference(e.reference):[]};case n.ClearSignContextType.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 n.ClearSignContextReferenceType.TOKEN:case n.ClearSignContextReferenceType.NFT:return this._getSubcontextsFromTokenOrNftReference(e);case n.ClearSignContextReferenceType.ENUM:return this._getSubcontextsFromEnumReference(e);case n.ClearSignContextReferenceType.TRUSTED_NAME:return this._getSubcontextsFromTrustedNameReference(e);case n.ClearSignContextReferenceType.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===n.ClearSignContextReferenceType.TOKEN?c.ContextFieldLoaderKind.TOKEN:c.ContextFieldLoaderKind.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 r of a){const o=(0,l.bufferToHexaString)(r.slice(Math.max(0,r.length-20)));t.push(()=>this.args.contextModule.getFieldContext({kind:e.type===n.ClearSignContextReferenceType.TOKEN?c.ContextFieldLoaderKind.TOKEN:c.ContextFieldLoaderKind.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 r of a){const o=r[r.length-1];if(o===void 0)continue;const x=this.args.contextOptional.filter(u=>u.type===n.ClearSignContextType.ENUM).find(u=>u.value===o&&u.id===e.id);x&&t.push(()=>Promise.resolve(x))}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 r of a)t.push(async()=>{const o=(0,l.bufferToHexaString)(r.slice(Math.max(0,r.length-20))),i=await this.api.sendCommand(new C.GetChallengeCommand);return(0,l.isSuccessCommandResult)(i)?await this.args.contextModule.getFieldContext({kind:c.ContextFieldLoaderKind.TRUSTED_NAME,chainId:this.args.subset.chainId,address:o,challenge:i.data.challenge,types:e.types,sources:e.sources}):{type:n.ClearSignContextType.ERROR,error:new Error("Failed to get challenge")}});return t}_getSubcontextFromProxy(e){return console.log("LAU: _getSubcontextsFromCallDataReference"),[async()=>{const t=await this.api.sendCommand(new C.GetChallengeCommand);if(console.log("LAU: getChallengeResult",t),!(0,l.isSuccessCommandResult)(t))return{type:n.ClearSignContextType.ERROR,error:new Error("Failed to get challenge")};const a=await this.args.contextModule.getProxyDelegateCall({...this.args.subset,deviceModelId:this.args.deviceModelId,challenge:t.data.challenge});return console.log("LAU: subcontext",a),a||{type:n.ClearSignContextType.ERROR,error:new Error("Failed to get proxy delegate call")}}]}}0&&(module.exports={BuildSubcontextsTask});
1
+ "use strict";var d=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var h=(r,e)=>{for(var n in e)d(r,n,{get:e[n],enumerable:!0})},p=(r,e,n,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of g(e))!b.call(r,s)&&s!==n&&d(r,s,{get:()=>e[s],enumerable:!(a=C(e,s))||a.enumerable});return r};var S=r=>p(d({},"__esModule",{value:!0}),r);var y={};h(y,{BuildSubcontextsTask:()=>T});module.exports=S(y);var t=require("@ledgerhq/context-module"),c=require("@ledgerhq/device-management-kit"),x=require("../../app-binder/command/GetChallengeCommand");class T{constructor(e,n){this.api=e;this.args=n}run(){const e=this.args.context,n=e.type;switch(n){case t.ClearSignContextType.TRANSACTION_INFO:case t.ClearSignContextType.WEB3_CHECK:case t.ClearSignContextType.PLUGIN:case t.ClearSignContextType.EXTERNAL_PLUGIN:case t.ClearSignContextType.DYNAMIC_NETWORK:case t.ClearSignContextType.DYNAMIC_NETWORK_ICON:case t.ClearSignContextType.ENUM:case t.ClearSignContextType.TRUSTED_NAME:case t.ClearSignContextType.TOKEN:case t.ClearSignContextType.NFT:return{subcontextCallbacks:[]};case t.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:return{subcontextCallbacks:e.reference?this._getSubcontextsFromReference(e.reference):[]};case t.ClearSignContextType.PROXY_DELEGATE_CALL:return{subcontextCallbacks:this._getSubcontextFromProxy(e)};default:{const a=n;throw new Error(`Uncovered type: ${a}`)}}}_getSubcontextsFromReference(e){const n=e.type;switch(n){case t.ClearSignContextReferenceType.TOKEN:case t.ClearSignContextReferenceType.NFT:return this._getSubcontextsFromTokenOrNftReference(e);case t.ClearSignContextReferenceType.ENUM:return this._getSubcontextsFromEnumReference(e);case t.ClearSignContextReferenceType.TRUSTED_NAME:return this._getSubcontextsFromTrustedNameReference(e);case t.ClearSignContextReferenceType.CALLDATA:return[];default:{const a=n;throw new Error(`Uncovered reference type: ${a}`)}}}_getSubcontextsFromTokenOrNftReference(e){if(e.value!==void 0){const a={kind:e.type===t.ClearSignContextReferenceType.TOKEN?t.ContextFieldLoaderKind.TOKEN:t.ContextFieldLoaderKind.NFT,chainId:this.args.subset.chainId,address:e.value};return[()=>this.args.contextModule.getFieldContext(a)]}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=(0,c.bufferToHexaString)(s.slice(Math.max(0,s.length-20)));n.push(()=>this.args.contextModule.getFieldContext({kind:e.type===t.ClearSignContextReferenceType.TOKEN?t.ContextFieldLoaderKind.TOKEN:t.ContextFieldLoaderKind.NFT,chainId:this.args.subset.chainId,address:o}))}}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.ClearSignContextType.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=(0,c.bufferToHexaString)(s.slice(Math.max(0,s.length-20))),i=await this.api.sendCommand(new x.GetChallengeCommand);return(0,c.isSuccessCommandResult)(i)?await this.args.contextModule.getFieldContext({kind:t.ContextFieldLoaderKind.TRUSTED_NAME,chainId:this.args.subset.chainId,address:o,challenge:i.data.challenge,types:e.types,sources:e.sources}):{type:t.ClearSignContextType.ERROR,error:new Error("Failed to get challenge")}});return n}_getSubcontextFromProxy(e){return[async()=>{const n=await this.api.sendCommand(new x.GetChallengeCommand);return(0,c.isSuccessCommandResult)(n)?this.args.subset.to===void 0?{type:t.ClearSignContextType.ERROR,error:new Error("Failed to get proxy address")}:await this.args.contextModule.getFieldContext({kind:t.ContextFieldLoaderKind.PROXY_DELEGATE_CALL,chainId:this.args.subset.chainId,proxyAddress:this.args.subset.to,calldata:this.args.subset.data,deviceModelId:this.args.deviceModelId,challenge:n.data.challenge}):{type:t.ClearSignContextType.ERROR,error:new Error("Failed to get challenge")}}]}}0&&(module.exports={BuildSubcontextsTask});
2
2
  //# sourceMappingURL=BuildSubcontextsTask.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/internal/app-binder/task/BuildSubcontextsTask.ts"],
4
- "sourcesContent": ["import {\n type ClearSignContext,\n type ClearSignContextReference,\n ClearSignContextReferenceType,\n type ClearSignContextSuccess,\n ClearSignContextType,\n type ContextModule,\n type TransactionFieldContext,\n type TransactionSubset,\n} from \"@ledgerhq/context-module\";\nimport { ContextFieldLoaderKind } from \"@ledgerhq/context-module/src/shared/domain/ContextFieldLoader.js\";\nimport {\n bufferToHexaString,\n type DeviceModelId,\n type InternalApi,\n isSuccessCommandResult,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { GetChallengeCommand } from \"@internal/app-binder/command/GetChallengeCommand\";\nimport { type TransactionParserService } from \"@internal/transaction/service/parser/TransactionParserService\";\n\nexport type BuildSubcontextsTaskArgs = {\n readonly context: ClearSignContextSuccess;\n readonly contextOptional: ClearSignContextSuccess[];\n readonly transactionParser: TransactionParserService;\n readonly subset: TransactionSubset;\n readonly deviceModelId: DeviceModelId;\n readonly contextModule: ContextModule;\n};\n\ntype SubcontextCallback = () => Promise<ClearSignContext>;\n\nexport type BuildSubcontextsTaskResult = {\n subcontextCallbacks: SubcontextCallback[];\n};\n\nexport class BuildSubcontextsTask {\n constructor(\n private readonly api: InternalApi,\n private readonly args: BuildSubcontextsTaskArgs,\n ) {}\n\n run(): BuildSubcontextsTaskResult {\n const context = this.args.context;\n const type = context.type;\n\n switch (type) {\n case ClearSignContextType.TRANSACTION_INFO:\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.ENUM:\n case ClearSignContextType.TRUSTED_NAME:\n case ClearSignContextType.TOKEN:\n case ClearSignContextType.NFT:\n return {\n subcontextCallbacks: [],\n };\n case ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:\n return {\n subcontextCallbacks: context.reference\n ? this._getSubcontextsFromReference(context.reference)\n : [],\n };\n case ClearSignContextType.PROXY_DELEGATE_CALL:\n return {\n subcontextCallbacks: this._getSubcontextFromProxy(context),\n };\n default: {\n const uncoveredType: never = type;\n throw new Error(`Uncovered type: ${uncoveredType}`);\n }\n }\n }\n\n private _getSubcontextsFromReference(\n reference: ClearSignContextReference,\n ): SubcontextCallback[] {\n const referenceType = reference.type;\n\n switch (referenceType) {\n case ClearSignContextReferenceType.TOKEN:\n case ClearSignContextReferenceType.NFT:\n return this._getSubcontextsFromTokenOrNftReference(reference);\n case ClearSignContextReferenceType.ENUM:\n return this._getSubcontextsFromEnumReference(reference);\n case ClearSignContextReferenceType.TRUSTED_NAME:\n return this._getSubcontextsFromTrustedNameReference(reference);\n case ClearSignContextReferenceType.CALLDATA:\n return [];\n default: {\n const uncoveredReferenceType: never = referenceType;\n throw new Error(`Uncovered reference type: ${uncoveredReferenceType}`);\n }\n }\n }\n\n private _getSubcontextsFromTokenOrNftReference(\n reference: ClearSignContextReference<\n ClearSignContextReferenceType.TOKEN | ClearSignContextReferenceType.NFT\n >,\n ): SubcontextCallback[] {\n // if the reference is a string, it means it is a direct address\n // and we don't need to extract the value from the transaction\n // as it is already provided in the reference\n if (reference.value !== undefined) {\n const transactionFieldContext: TransactionFieldContext = {\n kind:\n reference.type === ClearSignContextReferenceType.TOKEN\n ? ContextFieldLoaderKind.TOKEN\n : ContextFieldLoaderKind.NFT,\n chainId: this.args.subset.chainId,\n address: reference.value,\n };\n\n return [\n () => this.args.contextModule.getFieldContext(transactionFieldContext),\n ];\n }\n\n const subcontextCallbacks: SubcontextCallback[] = [];\n\n // if the reference is a path, it means we need to extract the value\n // from the transaction and provide it to the device\n if (reference.valuePath !== undefined) {\n const referenceValues = this.args.transactionParser\n .extractValue(this.args.subset, reference.valuePath)\n .orDefault([]);\n\n for (const value of referenceValues) {\n const address = bufferToHexaString(\n value.slice(Math.max(0, value.length - 20)),\n );\n\n subcontextCallbacks.push(() =>\n this.args.contextModule.getFieldContext({\n kind:\n reference.type === ClearSignContextReferenceType.TOKEN\n ? ContextFieldLoaderKind.TOKEN\n : ContextFieldLoaderKind.NFT,\n chainId: this.args.subset.chainId,\n address,\n }),\n );\n }\n }\n\n return subcontextCallbacks;\n }\n\n private _getSubcontextsFromEnumReference(\n reference: ClearSignContextReference<ClearSignContextReferenceType.ENUM>,\n ): SubcontextCallback[] {\n const subcontextCallbacks: SubcontextCallback[] = [];\n\n if (!reference.valuePath) {\n return subcontextCallbacks;\n }\n\n const referenceValues = this.args.transactionParser\n .extractValue(this.args.subset, reference.valuePath)\n .orDefault([]);\n\n for (const value of referenceValues) {\n const enumValue = value[value.length - 1];\n if (enumValue === undefined) {\n continue;\n }\n\n const enumsContext = this.args.contextOptional.filter(\n (c) => c.type === ClearSignContextType.ENUM,\n );\n\n const subcontext = enumsContext.find(\n (enumContext) =>\n enumContext.value === enumValue && enumContext.id === reference.id,\n );\n\n if (subcontext) {\n subcontextCallbacks.push(() => Promise.resolve(subcontext));\n }\n }\n return subcontextCallbacks;\n }\n\n private _getSubcontextsFromTrustedNameReference(\n reference: ClearSignContextReference<ClearSignContextReferenceType.TRUSTED_NAME>,\n ): SubcontextCallback[] {\n const subcontextCallbacks: SubcontextCallback[] = [];\n\n if (!reference.valuePath) {\n return subcontextCallbacks;\n }\n\n const referenceValues = this.args.transactionParser\n .extractValue(this.args.subset, reference.valuePath)\n .orDefault([]);\n\n for (const value of referenceValues) {\n {\n subcontextCallbacks.push(async () => {\n const address = bufferToHexaString(\n value.slice(Math.max(0, value.length - 20)),\n );\n\n const getChallengeResult = await this.api.sendCommand(\n new GetChallengeCommand(),\n );\n if (!isSuccessCommandResult(getChallengeResult)) {\n // TODO: we need to return an error here\n return {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Failed to get challenge\"),\n };\n }\n\n const subcontext = await this.args.contextModule.getFieldContext({\n kind: ContextFieldLoaderKind.TRUSTED_NAME,\n chainId: this.args.subset.chainId,\n address,\n challenge: getChallengeResult.data.challenge,\n types: reference.types,\n sources: reference.sources,\n });\n\n return subcontext;\n });\n }\n }\n\n return subcontextCallbacks;\n }\n\n private _getSubcontextFromProxy(\n _context: ClearSignContextSuccess<ClearSignContextType.PROXY_DELEGATE_CALL>,\n ): SubcontextCallback[] {\n console.log(\"LAU: _getSubcontextsFromCallDataReference\");\n return [\n async () => {\n const getChallengeResult = await this.api.sendCommand(\n new GetChallengeCommand(),\n );\n console.log(\"LAU: getChallengeResult\", getChallengeResult);\n if (!isSuccessCommandResult(getChallengeResult)) {\n return {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Failed to get challenge\"),\n };\n }\n\n const subcontext = await this.args.contextModule.getProxyDelegateCall({\n ...this.args.subset,\n deviceModelId: this.args.deviceModelId,\n challenge: getChallengeResult.data.challenge,\n });\n\n console.log(\"LAU: subcontext\", subcontext);\n\n if (!subcontext) {\n return {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Failed to get proxy delegate call\"),\n };\n }\n\n return subcontext;\n },\n ];\n }\n}\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EASO,oCACPC,EAAuC,4EACvCC,EAKO,2CAEPC,EAAoC,4DAkB7B,MAAML,CAAqB,CAChC,YACmBM,EACAC,EACjB,CAFiB,SAAAD,EACA,UAAAC,CAChB,CAEH,KAAkC,CAChC,MAAMC,EAAU,KAAK,KAAK,QACpBC,EAAOD,EAAQ,KAErB,OAAQC,EAAM,CACZ,KAAK,uBAAqB,iBAC1B,KAAK,uBAAqB,WAC1B,KAAK,uBAAqB,OAC1B,KAAK,uBAAqB,g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EACA,SAAK,0BAAuBA,CAAkB,EAQ3B,MAAM,KAAK,KAAK,cAAc,gBAAgB,CAC/D,KAAM,yBAAuB,aAC7B,QAAS,KAAK,KAAK,OAAO,QAC1B,QAAAL,EACA,UAAWK,EAAmB,KAAK,UACnC,MAAOZ,EAAU,MACjB,QAASA,EAAU,OACrB,CAAC,EAbQ,CACL,KAAM,uBAAqB,MAC3B,MAAO,IAAI,MAAM,yBAAyB,CAC5C,CAaJ,CAAC,EAIL,OAAOI,CACT,CAEQ,wBACNS,EACsB,CACtB,eAAQ,IAAI,2CAA2C,EAChD,CACL,SAAY,CACV,MAAMD,EAAqB,MAAM,KAAK,IAAI,YACxC,IAAI,qBACN,EAEA,GADA,QAAQ,IAAI,0BAA2BA,CAAkB,EACrD,IAAC,0BAAuBA,CAAkB,EAC5C,MAAO,CACL,KAAM,uBAAqB,MAC3B,MAAO,IAAI,MAAM,yBAAyB,CAC5C,EAGF,MAAMH,EAAa,MAAM,KAAK,KAAK,cAAc,qBAAqB,CACpE,GAAG,KAAK,KAAK,OACb,cAAe,KAAK,KAAK,cACzB,UAAWG,EAAmB,KAAK,SACrC,CAAC,EAID,OAFA,QAAQ,IAAI,kBAAmBH,CAAU,EAEpCA,GACI,CACL,KAAM,uBAAqB,MAC3B,MAAO,IAAI,MAAM,mCAAmC,CACtD,CAIJ,CACF,CACF,CACF",
6
- "names": ["BuildSubcontextsTask_exports", "__export", "BuildSubcontextsTask", "__toCommonJS", "import_context_module", "import_ContextFieldLoader", "import_device_management_kit", "import_GetChallengeCommand", "api", "args", "context", "type", "uncoveredType", "reference", "referenceType", "uncoveredReferenceType", "transactionFieldContext", "subcontextCallbacks", "referenceValues", "value", "address", "enumValue", "subcontext", "c", "enumContext", "getChallengeResult", "_context"]
4
+ "sourcesContent": ["import {\n type ClearSignContext,\n type ClearSignContextReference,\n ClearSignContextReferenceType,\n type ClearSignContextSuccess,\n ClearSignContextType,\n ContextFieldLoaderKind,\n type ContextModule,\n type TransactionSubset,\n} from \"@ledgerhq/context-module\";\nimport {\n bufferToHexaString,\n type DeviceModelId,\n type InternalApi,\n isSuccessCommandResult,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { GetChallengeCommand } from \"@internal/app-binder/command/GetChallengeCommand\";\nimport { type TransactionParserService } from \"@internal/transaction/service/parser/TransactionParserService\";\n\nexport type BuildSubcontextsTaskArgs = {\n readonly context: ClearSignContextSuccess;\n readonly contextOptional: ClearSignContextSuccess[];\n readonly transactionParser: TransactionParserService;\n readonly subset: TransactionSubset;\n readonly deviceModelId: DeviceModelId;\n readonly contextModule: ContextModule;\n};\n\ntype SubcontextCallback = () => Promise<ClearSignContext>;\n\nexport type BuildSubcontextsTaskResult = {\n subcontextCallbacks: SubcontextCallback[];\n};\n\nexport class BuildSubcontextsTask {\n constructor(\n private readonly api: InternalApi,\n private readonly args: BuildSubcontextsTaskArgs,\n ) {}\n\n run(): BuildSubcontextsTaskResult {\n const context = this.args.context;\n const type = context.type;\n\n switch (type) {\n case ClearSignContextType.TRANSACTION_INFO:\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.ENUM:\n case ClearSignContextType.TRUSTED_NAME:\n case ClearSignContextType.TOKEN:\n case ClearSignContextType.NFT:\n return {\n subcontextCallbacks: [],\n };\n case ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:\n return {\n subcontextCallbacks: context.reference\n ? this._getSubcontextsFromReference(context.reference)\n : [],\n };\n case ClearSignContextType.PROXY_DELEGATE_CALL:\n return {\n subcontextCallbacks: this._getSubcontextFromProxy(context),\n };\n default: {\n const uncoveredType: never = type;\n throw new Error(`Uncovered type: ${uncoveredType}`);\n }\n }\n }\n\n private _getSubcontextsFromReference(\n reference: ClearSignContextReference,\n ): SubcontextCallback[] {\n const referenceType = reference.type;\n\n switch (referenceType) {\n case ClearSignContextReferenceType.TOKEN:\n case ClearSignContextReferenceType.NFT:\n return this._getSubcontextsFromTokenOrNftReference(reference);\n case ClearSignContextReferenceType.ENUM:\n return this._getSubcontextsFromEnumReference(reference);\n case ClearSignContextReferenceType.TRUSTED_NAME:\n return this._getSubcontextsFromTrustedNameReference(reference);\n case ClearSignContextReferenceType.CALLDATA:\n // calldata reference is handled by the BuildFullContextsTask and ParseNestedTransactionTask\n return [];\n default: {\n const uncoveredReferenceType: never = referenceType;\n throw new Error(`Uncovered reference type: ${uncoveredReferenceType}`);\n }\n }\n }\n\n private _getSubcontextsFromTokenOrNftReference(\n reference: ClearSignContextReference<\n ClearSignContextReferenceType.TOKEN | ClearSignContextReferenceType.NFT\n >,\n ): SubcontextCallback[] {\n // if the reference is a string, it means it is a direct address\n // and we don't need to extract the value from the transaction\n // as it is already provided in the reference\n if (reference.value !== undefined) {\n const transactionFieldContext = {\n kind:\n reference.type === ClearSignContextReferenceType.TOKEN\n ? ContextFieldLoaderKind.TOKEN\n : ContextFieldLoaderKind.NFT,\n chainId: this.args.subset.chainId,\n address: reference.value,\n };\n\n return [\n () => this.args.contextModule.getFieldContext(transactionFieldContext),\n ];\n }\n\n const subcontextCallbacks: SubcontextCallback[] = [];\n\n // if the reference is a path, it means we need to extract the value\n // from the transaction and provide it to the device\n if (reference.valuePath !== undefined) {\n const referenceValues = this.args.transactionParser\n .extractValue(this.args.subset, reference.valuePath)\n .orDefault([]);\n\n for (const value of referenceValues) {\n const address = bufferToHexaString(\n value.slice(Math.max(0, value.length - 20)),\n );\n\n subcontextCallbacks.push(() =>\n this.args.contextModule.getFieldContext({\n kind:\n reference.type === ClearSignContextReferenceType.TOKEN\n ? ContextFieldLoaderKind.TOKEN\n : ContextFieldLoaderKind.NFT,\n chainId: this.args.subset.chainId,\n address,\n }),\n );\n }\n }\n\n return subcontextCallbacks;\n }\n\n private _getSubcontextsFromEnumReference(\n reference: ClearSignContextReference<ClearSignContextReferenceType.ENUM>,\n ): SubcontextCallback[] {\n const subcontextCallbacks: SubcontextCallback[] = [];\n\n if (!reference.valuePath) {\n return subcontextCallbacks;\n }\n\n const referenceValues = this.args.transactionParser\n .extractValue(this.args.subset, reference.valuePath)\n .orDefault([]);\n\n for (const value of referenceValues) {\n const enumValue = value[value.length - 1];\n if (enumValue === undefined) {\n continue;\n }\n\n const enumsContext = this.args.contextOptional.filter(\n (c) => c.type === ClearSignContextType.ENUM,\n );\n\n const subcontext = enumsContext.find(\n (enumContext) =>\n enumContext.value === enumValue && enumContext.id === reference.id,\n );\n\n if (subcontext) {\n subcontextCallbacks.push(() => Promise.resolve(subcontext));\n }\n }\n return subcontextCallbacks;\n }\n\n private _getSubcontextsFromTrustedNameReference(\n reference: ClearSignContextReference<ClearSignContextReferenceType.TRUSTED_NAME>,\n ): SubcontextCallback[] {\n const subcontextCallbacks: SubcontextCallback[] = [];\n\n if (!reference.valuePath) {\n return subcontextCallbacks;\n }\n\n const referenceValues = this.args.transactionParser\n .extractValue(this.args.subset, reference.valuePath)\n .orDefault([]);\n\n for (const value of referenceValues) {\n {\n subcontextCallbacks.push(async () => {\n const address = bufferToHexaString(\n value.slice(Math.max(0, value.length - 20)),\n );\n\n const getChallengeResult = await this.api.sendCommand(\n new GetChallengeCommand(),\n );\n if (!isSuccessCommandResult(getChallengeResult)) {\n return {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Failed to get challenge\"),\n };\n }\n\n const subcontext = await this.args.contextModule.getFieldContext({\n kind: ContextFieldLoaderKind.TRUSTED_NAME,\n chainId: this.args.subset.chainId,\n address,\n challenge: getChallengeResult.data.challenge,\n types: reference.types,\n sources: reference.sources,\n });\n\n return subcontext;\n });\n }\n }\n\n return subcontextCallbacks;\n }\n\n private _getSubcontextFromProxy(\n _context: ClearSignContextSuccess<ClearSignContextType.PROXY_DELEGATE_CALL>,\n ): SubcontextCallback[] {\n return [\n async () => {\n const getChallengeResult = await this.api.sendCommand(\n new GetChallengeCommand(),\n );\n if (!isSuccessCommandResult(getChallengeResult)) {\n return {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Failed to get challenge\"),\n };\n }\n\n if (this.args.subset.to === undefined) {\n return {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Failed to get proxy address\"),\n };\n }\n\n const subcontext = await this.args.contextModule.getFieldContext({\n kind: ContextFieldLoaderKind.PROXY_DELEGATE_CALL,\n chainId: this.args.subset.chainId,\n proxyAddress: this.args.subset.to,\n calldata: this.args.subset.data,\n deviceModelId: this.args.deviceModelId,\n challenge: getChallengeResult.data.challenge,\n });\n\n return subcontext;\n },\n ];\n }\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EASO,oCACPC,EAKO,2CAEPC,EAAoC,4DAkB7B,MAAMJ,CAAqB,CAChC,YACmBK,EACAC,EACjB,CAFiB,SAAAD,EACA,UAAAC,CAChB,CAEH,KAAkC,CAChC,MAAMC,EAAU,KAAK,KAAK,QACpBC,EAAOD,EAAQ,KAErB,OAAQC,EAAM,CACZ,KAAK,uBAAqB,iBAC1B,KAAK,uBAAqB,WAC1B,KAAK,uBAAqB,OAC1B,KAAK,uBAAqB,gBAC1B,KAAK,uBAAqB,gBAC1B,KAAK,uBAAqB,qBAC1B,KAAK,uBAAqB,KAC1B,KAAK,uBAAqB,aAC1B,KAAK,uBAAqB,MAC1B,KAAK,uBAAqB,IACxB,MAAO,CACL,oBAAqB,CAAC,CACxB,EACF,KAAK,uBAAqB,8BACxB,MAAO,CACL,oBAAqBD,EAAQ,UACzB,KAAK,6BAA6BA,EAAQ,SAAS,EACnD,CAAC,CACP,EACF,KAAK,uBAAqB,oBACxB,MAAO,CACL,oBAAqB,KAAK,wBAAwBA,CAAO,CAC3D,EACF,QAAS,CACP,MAAME,EAAuBD,EAC7B,MAAM,IAAI,MAAM,mBAAmBC,CAAa,EAAE,CACpD,CACF,CACF,CAEQ,6BACNC,EACs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O,KAAO,OACnB,CACL,KAAM,uBAAqB,MAC3B,MAAO,IAAI,MAAM,6BAA6B,CAChD,EAGiB,MAAM,KAAK,KAAK,cAAc,gBAAgB,CAC/D,KAAM,yBAAuB,oBAC7B,QAAS,KAAK,KAAK,OAAO,QAC1B,aAAc,KAAK,KAAK,OAAO,GAC/B,SAAU,KAAK,KAAK,OAAO,KAC3B,cAAe,KAAK,KAAK,cACzB,UAAWA,EAAmB,KAAK,SACrC,CAAC,EApBQ,CACL,KAAM,uBAAqB,MAC3B,MAAO,IAAI,MAAM,yBAAyB,CAC5C,CAoBJ,CACF,CACF,CACF",
6
+ "names": ["BuildSubcontextsTask_exports", "__export", "BuildSubcontextsTask", "__toCommonJS", "import_context_module", "import_device_management_kit", "import_GetChallengeCommand", "api", "args", "context", "type", "uncoveredType", "reference", "referenceType", "uncoveredReferenceType", "transactionFieldContext", "subcontextCallbacks", "referenceValues", "value", "address", "enumValue", "subcontext", "c", "enumContext", "getChallengeResult", "_context"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("@ledgerhq/context-module"),T=require("@ledgerhq/context-module/src/shared/domain/ContextFieldLoader.js"),C=require("@ledgerhq/device-management-kit"),d=require("purify-ts"),E=require("../../app-binder/command/GetChallengeCommand"),N=require("../../app-binder/device-action/__test-utils__/makeInternalApi"),r=require("./BuildSubcontextsTask");describe("BuildSubcontextsTask",()=>{const x={getFieldContext:vi.fn()},p={extractValue:vi.fn()},s=(0,N.makeDeviceActionInternalApiMock)();let l;beforeEach(()=>{vi.resetAllMocks(),l={context:{type:e.ClearSignContextType.TRANSACTION_INFO,payload:"test payload"},contextOptional:[],transactionParser:p,subset:{chainId:1,data:"0x",selector:"0x",to:"0x",value:BigInt(0)},contextModule:x,deviceModelId:C.DeviceModelId.STAX}}),describe("when context type is a simple type",()=>{const a=[e.ClearSignContextType.TRANSACTION_INFO,e.ClearSignContextType.WEB3_CHECK,e.ClearSignContextType.PLUGIN,e.ClearSignContextType.EXTERNAL_PLUGIN,e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION];it.each(a)("should return context with empty subcontextCallbacks for %s",t=>{const c={...l,context:{type:t,payload:"test payload"}},o=new r.BuildSubcontextsTask(s,c).run();expect(o.subcontextCallbacks).toHaveLength(0)})}),describe("when context has a direct value reference",()=>{it("should create a callback to get context with the direct value",async()=>{const a={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.TOKEN,value:"0x1234567890123456789012345678901234567890"}},t={...l,context:a},n={kind:T.ContextFieldLoaderKind.TOKEN,chainId:1,address:"0x1234567890123456789012345678901234567890"},c=new r.BuildSubcontextsTask(s,t).run();expect(c.subcontextCallbacks).toHaveLength(1);const o=c.subcontextCallbacks[0];await o(),expect(x.getFieldContext).toHaveBeenCalledWith(n)}),it("should handle undefined value in reference",()=>{const a={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:void 0},t={...l,context:a},n=new r.BuildSubcontextsTask(s,t).run();expect(n.subcontextCallbacks).toHaveLength(0)})}),describe("when context has a valuePath reference",()=>{beforeEach(()=>{s.sendCommand.mockResolvedValue((0,C.CommandResultFactory)({data:{challenge:"test-challenge"}}))}),describe("when extractValue returns Left (error)",()=>{it("should return context with empty subcontextCallbacks",()=>{const a={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.TOKEN,valuePath:[{type:"SLICE",start:0,end:20}]}},t={...l,context:a};p.extractValue.mockReturnValue((0,d.Left)(new Error("Extraction failed")));const n=new r.BuildSubcontextsTask(s,t).run();expect(n.subcontextCallbacks).toHaveLength(0)})}),describe("when extractValue returns Right with values",()=>{describe("for ENUM type",()=>{it("should create callbacks for matching enum contexts",async()=>{const a={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.ENUM,id:1,valuePath:[{type:"TUPLE",offset:0}]}},t={type:e.ClearSignContextType.ENUM,id:1,value:1,payload:"enum context 1"},n={type:e.ClearSignContextType.ENUM,id:1,value:2,payload:"enum context 2"},c={type:e.ClearSignContextType.ENUM,id:2,value:2,payload:"enum context 3"},o={...l,context:a,contextOptional:[t,n,c]},u=[new Uint8Array([1,2])];p.extractValue.mockReturnValue((0,d.Right)(u));const i=new r.BuildSubcontextsTask(s,o).run();expect(i.subcontextCallbacks).toHaveLength(1);const y=i.subcontextCallbacks[0],b=await y();expect(b).toEqual(n)}),it("should create callbacks for matching enum contexts with two values",async()=>{const a={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.ENUM,id:1,valuePath:[{type:"TUPLE",offset:0}]}},t={type:e.ClearSignContextType.ENUM,id:1,value:1,payload:"enum context 1"},n={type:e.ClearSignContextType.ENUM,id:1,value:2,payload:"enum context 2"},c={type:e.ClearSignContextType.ENUM,id:2,value:2,payload:"enum context 3"},o={...l,context:a,contextOptional:[t,n,c]},u=[new Uint8Array([1,2]),new Uint8Array([3,2,1])];p.extractValue.mockReturnValue((0,d.Right)(u));const i=new r.BuildSubcontextsTask(s,o).run();expect(i.subcontextCallbacks).toHaveLength(2);const y=i.subcontextCallbacks[0],b=i.subcontextCallbacks[1],h=await y(),S=await b();expect(h).toEqual(n),expect(S).toEqual(t)}),it("should skip when enum value is undefined",()=>{const a={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.ENUM,id:1,valuePath:[{type:"TUPLE",offset:0}]}},t={...l,context:a},n=[new Uint8Array([])];p.extractValue.mockReturnValue((0,d.Right)(n));const c=new r.BuildSubcontextsTask(s,t).run();expect(c.subcontextCallbacks).toHaveLength(0)}),it("should create callback with enum id 0",async()=>{const a={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.ENUM,id:0,valuePath:[{type:"TUPLE",offset:0}]}},t={type:e.ClearSignContextType.ENUM,id:0,value:0,payload:"enum context 1"},n={type:e.ClearSignContextType.ENUM,id:1,value:1,payload:"enum context 2"},c={...l,context:a,contextOptional:[t,n]},o=[new Uint8Array([1,0])];p.extractValue.mockReturnValue((0,d.Right)(o));const u=new r.BuildSubcontextsTask(s,c).run();expect(u.subcontextCallbacks).toHaveLength(1);const i=u.subcontextCallbacks[0],y=await i();expect(y).toEqual(t)}),it("should skip when no matching enum context found",()=>{const a={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.ENUM,id:1,valuePath:[{type:"TUPLE",offset:0}]}},t={type:e.ClearSignContextType.ENUM,id:2,value:2,payload:"enum context"},n={...l,context:a,contextOptional:[t]},c=[new Uint8Array([1,2])];p.extractValue.mockReturnValue((0,d.Right)(c));const o=new r.BuildSubcontextsTask(s,n).run();expect(o.subcontextCallbacks).toHaveLength(0)})}),describe("for TOKEN type",()=>{it("should create callbacks to get token context",async()=>{const a={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.TOKEN,valuePath:[{type:"TUPLE",offset:0}]}},t={...l,context:a},n=[new Uint8Array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22])];p.extractValue.mockReturnValue((0,d.Right)(n)),x.getFieldContext.mockResolvedValue({type:e.ClearSignContextType.TOKEN,payload:"token result"});const c=new r.BuildSubcontextsTask(s,t).run();expect(c.subcontextCallbacks).toHaveLength(1);const o=c.subcontextCallbacks[0],u=await o();expect(u).toEqual({type:e.ClearSignContextType.TOKEN,payload:"token result"}),expect(x.getFieldContext).toHaveBeenCalledWith({type:e.ClearSignContextType.TOKEN,chainId:1,address:"0x030405060708090a0b0c0d0e0f10111213141516"})}),it("should create callbacks to get token as constant",async()=>{const a={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.TOKEN,value:"0x030405060708090a0b0c0d0e0f10111213141516"}},t={...l,context:a};x.getFieldContext.mockResolvedValue({type:e.ClearSignContextType.TOKEN,payload:"token result"});const n=new r.BuildSubcontextsTask(s,t).run();expect(n.subcontextCallbacks).toHaveLength(1);const c=n.subcontextCallbacks[0],o=await c();expect(o).toEqual({type:e.ClearSignContextType.TOKEN,payload:"token result"}),expect(x.getFieldContext).toHaveBeenCalledWith({type:e.ClearSignContextType.TOKEN,chainId:1,address:"0x030405060708090a0b0c0d0e0f10111213141516"})})}),describe("for NFT type",()=>{it("should create callbacks to get NFT context",async()=>{const a={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.NFT,valuePath:[{type:"TUPLE",offset:0}]}},t={...l,context:a},n=[new Uint8Array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22])];p.extractValue.mockReturnValue((0,d.Right)(n)),x.getFieldContext.mockResolvedValue({type:e.ClearSignContextType.NFT,payload:"nft result"});const c=new r.BuildSubcontextsTask(s,t).run();expect(c.subcontextCallbacks).toHaveLength(1);const o=c.subcontextCallbacks[0],u=await o();expect(u).toEqual({type:e.ClearSignContextType.NFT,payload:"nft result"}),expect(x.getFieldContext).toHaveBeenCalledWith({type:e.ClearSignContextType.NFT,chainId:1,address:"0x030405060708090a0b0c0d0e0f10111213141516"})}),it("should create callbacks to get NFT as constant",async()=>{const a={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.NFT,value:"0x030405060708090a0b0c0d0e0f10111213141516"}},t={...l,context:a};x.getFieldContext.mockResolvedValue({type:e.ClearSignContextType.NFT,payload:"nft result"});const n=new r.BuildSubcontextsTask(s,t).run();expect(n.subcontextCallbacks).toHaveLength(1);const c=n.subcontextCallbacks[0],o=await c();expect(o).toEqual({type:e.ClearSignContextType.NFT,payload:"nft result"}),expect(x.getFieldContext).toHaveBeenCalledWith({type:e.ClearSignContextType.NFT,chainId:1,address:"0x030405060708090a0b0c0d0e0f10111213141516"})})}),describe("for TRUSTED_NAME type",()=>{it("should create callbacks to get trusted name context with challenge",async()=>{const a={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.TRUSTED_NAME,valuePath:[{type:"TUPLE",offset:0}],types:["type1","type2"],sources:["source1","source2"]}},t={...l,context:a},n=[new Uint8Array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22])];p.extractValue.mockReturnValue((0,d.Right)(n)),x.getFieldContext.mockResolvedValue({type:e.ClearSignContextType.TRUSTED_NAME,payload:"trusted name result"});const c=new r.BuildSubcontextsTask(s,t).run();expect(c.subcontextCallbacks).toHaveLength(1);const o=c.subcontextCallbacks[0],u=await o();expect(u).toEqual({type:e.ClearSignContextType.TRUSTED_NAME,payload:"trusted name result"}),expect(s.sendCommand).toHaveBeenCalledWith(expect.any(E.GetChallengeCommand)),expect(x.getFieldContext).toHaveBeenCalledWith({type:e.ClearSignContextType.TRUSTED_NAME,chainId:1,address:"0x030405060708090a0b0c0d0e0f10111213141516",challenge:"test-challenge",types:["type1","type2"],sources:["source1","source2"]})}),it("should handle challenge command failure",async()=>{const a={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.TRUSTED_NAME,valuePath:[{type:"TUPLE",offset:0}],types:["type1"],sources:["source1"]}},t={...l,context:a},n=[new Uint8Array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22])];p.extractValue.mockReturnValue((0,d.Right)(n));const c=new C.UnknownDeviceExchangeError("Failed");s.sendCommand.mockResolvedValueOnce((0,C.CommandResultFactory)({error:c}));const o=new r.BuildSubcontextsTask(s,t).run();expect(o.subcontextCallbacks).toHaveLength(1);const u=o.subcontextCallbacks[0],i=await u();expect(i).toEqual({error:new Error("Failed to get challenge"),type:e.ClearSignContextType.ERROR})})}),describe("for multiple values",()=>{it("should create callbacks for each extracted value",async()=>{const a={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.TOKEN,valuePath:[{type:"TUPLE",offset:0}]}},t={...l,context:a},n=[new Uint8Array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22]),new Uint8Array([33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54])];p.extractValue.mockReturnValue((0,d.Right)(n)),x.getFieldContext.mockResolvedValueOnce({type:e.ClearSignContextType.TOKEN,payload:"token result 1"}),x.getFieldContext.mockResolvedValueOnce({type:e.ClearSignContextType.TOKEN,payload:"token result 2"});const c=new r.BuildSubcontextsTask(s,t).run();expect(c.subcontextCallbacks).toHaveLength(2);const o=c.subcontextCallbacks[0],u=c.subcontextCallbacks[1],i=await o(),y=await u();expect(i).toEqual({type:e.ClearSignContextType.TOKEN,payload:"token result 1"}),expect(y).toEqual({type:e.ClearSignContextType.TOKEN,payload:"token result 2"}),expect(x.getFieldContext).toHaveBeenCalledTimes(2),expect(x.getFieldContext).toHaveBeenNthCalledWith(1,{type:e.ClearSignContextType.TOKEN,chainId:1,address:"0x030405060708090a0b0c0d0e0f10111213141516"}),expect(x.getFieldContext).toHaveBeenNthCalledWith(2,{type:e.ClearSignContextType.TOKEN,chainId:1,address:"0x232425262728292a2b2c2d2e2f30313233343536"})})})})}),describe("when context has no reference",()=>{it("should return context with empty subcontextCallbacks",()=>{const a={type:e.ClearSignContextType.TOKEN,payload:"test payload"},t={...l,context:a},n=new r.BuildSubcontextsTask(s,t).run();expect(n.subcontextCallbacks).toHaveLength(0)})}),describe("when context has reference but no valuePath",()=>{it("should return context with empty subcontextCallbacks",()=>{const a={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.TOKEN,valuePath:void 0}},t={...l,context:a},n=new r.BuildSubcontextsTask(s,t).run();expect(n.subcontextCallbacks).toHaveLength(0)})}),describe("error handling",()=>{it("should throw error for uncovered context type",()=>{const t={...l,context:{type:"UNKNOWN_TYPE",payload:"test payload"}};expect(()=>new r.BuildSubcontextsTask(s,t).run()).toThrow("Uncovered type: UNKNOWN_TYPE")}),it("should throw error for uncovered reference type",()=>{const a={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:"UNKNOWN_REFERENCE_TYPE"}},t={...l,context:a};expect(()=>new r.BuildSubcontextsTask(s,t).run()).toThrow("Uncovered reference type: UNKNOWN_REFERENCE_TYPE")})}),describe("CALLDATA reference type",()=>{it("should return empty subcontextCallbacks for CALLDATA reference",()=>{const a={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.CALLDATA,callee:[{type:"TUPLE",offset:0}],valuePath:[{type:"TUPLE",offset:0}]}},t={...l,context:a},n=new r.BuildSubcontextsTask(s,t).run();expect(n.subcontextCallbacks).toHaveLength(0)})}),describe("references without valuePath",()=>{it("should return empty subcontextCallbacks for ENUM reference without valuePath",()=>{const a={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.ENUM,id:1,valuePath:void 0}},t={...l,context:a},n=new r.BuildSubcontextsTask(s,t).run();expect(n.subcontextCallbacks).toHaveLength(0)}),it("should return empty subcontextCallbacks for TRUSTED_NAME reference without valuePath",()=>{const a={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.TRUSTED_NAME,types:["type1"],sources:["source1"],valuePath:void 0}},t={...l,context:a},n=new r.BuildSubcontextsTask(s,t).run();expect(n.subcontextCallbacks).toHaveLength(0)})}),describe("edge cases",()=>{it("should handle value array shorter than 20 bytes for address extraction",async()=>{const a={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.TOKEN,valuePath:[{type:"TUPLE",offset:0}]}},t={...l,context:a},n=[new Uint8Array([1,2,3])];p.extractValue.mockReturnValue((0,d.Right)(n)),x.getFieldContext.mockResolvedValue({type:e.ClearSignContextType.ERROR,message:"Invalid address"});const c=new r.BuildSubcontextsTask(s,t).run();expect(c.subcontextCallbacks).toHaveLength(1);const o=c.subcontextCallbacks[0],u=await o();expect(u).toEqual({type:e.ClearSignContextType.ERROR,message:"Invalid address"}),expect(x.getFieldContext).toHaveBeenCalledWith({type:e.ClearSignContextType.TOKEN,chainId:1,address:"0x010203"})}),it("should handle empty value array",async()=>{const a={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.TOKEN,valuePath:[{type:"TUPLE",offset:0}]}},t={...l,context:a},n=[new Uint8Array([])];p.extractValue.mockReturnValue((0,d.Right)(n)),x.getFieldContext.mockResolvedValue({type:e.ClearSignContextType.TOKEN,payload:"token result"});const c=new r.BuildSubcontextsTask(s,t).run();expect(c.subcontextCallbacks).toHaveLength(1);const o=c.subcontextCallbacks[0],u=await o();expect(u).toEqual({type:e.ClearSignContextType.TOKEN,payload:"token result"}),expect(x.getFieldContext).toHaveBeenCalledWith({type:e.ClearSignContextType.TOKEN,chainId:1,address:"0x"})})})});
1
+ "use strict";var e=require("@ledgerhq/context-module"),i=require("@ledgerhq/device-management-kit"),d=require("purify-ts"),b=require("../../app-binder/command/GetChallengeCommand"),h=require("../../app-binder/device-action/__test-utils__/makeInternalApi"),r=require("./BuildSubcontextsTask");describe("BuildSubcontextsTask",()=>{const x={getFieldContext:vi.fn()},p={extractValue:vi.fn()},o=(0,h.makeDeviceActionInternalApiMock)();let l;beforeEach(()=>{vi.resetAllMocks(),l={context:{type:e.ClearSignContextType.TRANSACTION_INFO,payload:"test payload"},contextOptional:[],transactionParser:p,subset:{chainId:1,data:"0x",selector:"0x",to:"0x",value:BigInt(0)},contextModule:x,deviceModelId:i.DeviceModelId.STAX}}),describe("when context type is a simple type",()=>{const n=[e.ClearSignContextType.TRANSACTION_INFO,e.ClearSignContextType.WEB3_CHECK,e.ClearSignContextType.PLUGIN,e.ClearSignContextType.EXTERNAL_PLUGIN,e.ClearSignContextType.DYNAMIC_NETWORK,e.ClearSignContextType.DYNAMIC_NETWORK_ICON,e.ClearSignContextType.ENUM,e.ClearSignContextType.TRUSTED_NAME,e.ClearSignContextType.TOKEN,e.ClearSignContextType.NFT];it.each(n)("should return context with empty subcontextCallbacks for %s",t=>{const c={...l,context:{type:t,payload:"test payload"}},s=new r.BuildSubcontextsTask(o,c).run();expect(s.subcontextCallbacks).toHaveLength(0)})}),describe("when context has a direct value reference",()=>{it("should create a callback to get context with the direct value",async()=>{const n={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.TOKEN,value:"0x1234567890123456789012345678901234567890"}},t={...l,context:n},a={kind:e.ContextFieldLoaderKind.TOKEN,chainId:1,address:"0x1234567890123456789012345678901234567890"},c=new r.BuildSubcontextsTask(o,t).run();expect(c.subcontextCallbacks).toHaveLength(1);const s=c.subcontextCallbacks[0];await s(),expect(x.getFieldContext).toHaveBeenCalledWith(a)}),it("should handle undefined value in reference",()=>{const n={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:void 0},t={...l,context:n},a=new r.BuildSubcontextsTask(o,t).run();expect(a.subcontextCallbacks).toHaveLength(0)})}),describe("when context has a valuePath reference",()=>{beforeEach(()=>{o.sendCommand.mockResolvedValue((0,i.CommandResultFactory)({data:{challenge:"test-challenge"}}))}),describe("when extractValue returns Left (error)",()=>{it("should return context with empty subcontextCallbacks",()=>{const n={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.TOKEN,valuePath:[{type:"SLICE",start:0,end:20}]}},t={...l,context:n};p.extractValue.mockReturnValue((0,d.Left)(new Error("Extraction failed")));const a=new r.BuildSubcontextsTask(o,t).run();expect(a.subcontextCallbacks).toHaveLength(0)})}),describe("when extractValue returns Right with values",()=>{describe("for ENUM type",()=>{it("should create callbacks for matching enum contexts",async()=>{const n={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.ENUM,id:1,valuePath:[{type:"TUPLE",offset:0}]}},t={type:e.ClearSignContextType.ENUM,id:1,value:1,payload:"enum context 1"},a={type:e.ClearSignContextType.ENUM,id:1,value:2,payload:"enum context 2"},c={type:e.ClearSignContextType.ENUM,id:2,value:2,payload:"enum context 3"},s={...l,context:n,contextOptional:[t,a,c]},u=[new Uint8Array([1,2])];p.extractValue.mockReturnValue((0,d.Right)(u));const C=new r.BuildSubcontextsTask(o,s).run();expect(C.subcontextCallbacks).toHaveLength(1);const y=C.subcontextCallbacks[0],E=await y();expect(E).toEqual(a)}),it("should create callbacks for matching enum contexts with two values",async()=>{const n={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.ENUM,id:1,valuePath:[{type:"TUPLE",offset:0}]}},t={type:e.ClearSignContextType.ENUM,id:1,value:1,payload:"enum context 1"},a={type:e.ClearSignContextType.ENUM,id:1,value:2,payload:"enum context 2"},c={type:e.ClearSignContextType.ENUM,id:2,value:2,payload:"enum context 3"},s={...l,context:n,contextOptional:[t,a,c]},u=[new Uint8Array([1,2]),new Uint8Array([3,2,1])];p.extractValue.mockReturnValue((0,d.Right)(u));const C=new r.BuildSubcontextsTask(o,s).run();expect(C.subcontextCallbacks).toHaveLength(2);const y=C.subcontextCallbacks[0],E=C.subcontextCallbacks[1],T=await y(),g=await E();expect(T).toEqual(a),expect(g).toEqual(t)}),it("should skip when enum value is undefined",()=>{const n={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.ENUM,id:1,valuePath:[{type:"TUPLE",offset:0}]}},t={...l,context:n},a=[new Uint8Array([])];p.extractValue.mockReturnValue((0,d.Right)(a));const c=new r.BuildSubcontextsTask(o,t).run();expect(c.subcontextCallbacks).toHaveLength(0)}),it("should create callback with enum id 0",async()=>{const n={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.ENUM,id:0,valuePath:[{type:"TUPLE",offset:0}]}},t={type:e.ClearSignContextType.ENUM,id:0,value:0,payload:"enum context 1"},a={type:e.ClearSignContextType.ENUM,id:1,value:1,payload:"enum context 2"},c={...l,context:n,contextOptional:[t,a]},s=[new Uint8Array([1,0])];p.extractValue.mockReturnValue((0,d.Right)(s));const u=new r.BuildSubcontextsTask(o,c).run();expect(u.subcontextCallbacks).toHaveLength(1);const C=u.subcontextCallbacks[0],y=await C();expect(y).toEqual(t)}),it("should skip when no matching enum context found",()=>{const n={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.ENUM,id:1,valuePath:[{type:"TUPLE",offset:0}]}},t={type:e.ClearSignContextType.ENUM,id:2,value:2,payload:"enum context"},a={...l,context:n,contextOptional:[t]},c=[new Uint8Array([1,2])];p.extractValue.mockReturnValue((0,d.Right)(c));const s=new r.BuildSubcontextsTask(o,a).run();expect(s.subcontextCallbacks).toHaveLength(0)})}),describe("for TOKEN type",()=>{it("should create callbacks to get token context",async()=>{const n={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.TOKEN,valuePath:[{type:"TUPLE",offset:0}]}},t={...l,context:n},a=[new Uint8Array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22])];p.extractValue.mockReturnValue((0,d.Right)(a)),x.getFieldContext.mockResolvedValue({type:e.ClearSignContextType.TOKEN,payload:"token result"});const c=new r.BuildSubcontextsTask(o,t).run();expect(c.subcontextCallbacks).toHaveLength(1);const s=c.subcontextCallbacks[0],u=await s();expect(u).toEqual({type:e.ClearSignContextType.TOKEN,payload:"token result"}),expect(x.getFieldContext).toHaveBeenCalledWith({kind:e.ContextFieldLoaderKind.TOKEN,chainId:1,address:"0x030405060708090a0b0c0d0e0f10111213141516"})}),it("should create callbacks to get token as constant",async()=>{const n={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.TOKEN,value:"0x030405060708090a0b0c0d0e0f10111213141516"}},t={...l,context:n};x.getFieldContext.mockResolvedValue({type:e.ClearSignContextType.TOKEN,payload:"token result"});const a=new r.BuildSubcontextsTask(o,t).run();expect(a.subcontextCallbacks).toHaveLength(1);const c=a.subcontextCallbacks[0],s=await c();expect(s).toEqual({type:e.ClearSignContextType.TOKEN,payload:"token result"}),expect(x.getFieldContext).toHaveBeenCalledWith({kind:e.ContextFieldLoaderKind.TOKEN,chainId:1,address:"0x030405060708090a0b0c0d0e0f10111213141516"})})}),describe("for NFT type",()=>{it("should create callbacks to get NFT context",async()=>{const n={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.NFT,valuePath:[{type:"TUPLE",offset:0}]}},t={...l,context:n},a=[new Uint8Array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22])];p.extractValue.mockReturnValue((0,d.Right)(a)),x.getFieldContext.mockResolvedValue({type:e.ClearSignContextType.NFT,payload:"nft result"});const c=new r.BuildSubcontextsTask(o,t).run();expect(c.subcontextCallbacks).toHaveLength(1);const s=c.subcontextCallbacks[0],u=await s();expect(u).toEqual({type:e.ClearSignContextType.NFT,payload:"nft result"}),expect(x.getFieldContext).toHaveBeenCalledWith({kind:e.ContextFieldLoaderKind.NFT,chainId:1,address:"0x030405060708090a0b0c0d0e0f10111213141516"})}),it("should create callbacks to get NFT as constant",async()=>{const n={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.NFT,value:"0x030405060708090a0b0c0d0e0f10111213141516"}},t={...l,context:n};x.getFieldContext.mockResolvedValue({type:e.ClearSignContextType.NFT,payload:"nft result"});const a=new r.BuildSubcontextsTask(o,t).run();expect(a.subcontextCallbacks).toHaveLength(1);const c=a.subcontextCallbacks[0],s=await c();expect(s).toEqual({type:e.ClearSignContextType.NFT,payload:"nft result"}),expect(x.getFieldContext).toHaveBeenCalledWith({kind:e.ContextFieldLoaderKind.NFT,chainId:1,address:"0x030405060708090a0b0c0d0e0f10111213141516"})})}),describe("for TRUSTED_NAME type",()=>{it("should create callbacks to get trusted name context with challenge",async()=>{const n={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.TRUSTED_NAME,valuePath:[{type:"TUPLE",offset:0}],types:["type1","type2"],sources:["source1","source2"]}},t={...l,context:n},a=[new Uint8Array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22])];p.extractValue.mockReturnValue((0,d.Right)(a)),x.getFieldContext.mockResolvedValue({type:e.ClearSignContextType.TRUSTED_NAME,payload:"trusted name result"});const c=new r.BuildSubcontextsTask(o,t).run();expect(c.subcontextCallbacks).toHaveLength(1);const s=c.subcontextCallbacks[0],u=await s();expect(u).toEqual({type:e.ClearSignContextType.TRUSTED_NAME,payload:"trusted name result"}),expect(o.sendCommand).toHaveBeenCalledWith(expect.any(b.GetChallengeCommand)),expect(x.getFieldContext).toHaveBeenCalledWith({kind:e.ContextFieldLoaderKind.TRUSTED_NAME,chainId:1,address:"0x030405060708090a0b0c0d0e0f10111213141516",challenge:"test-challenge",types:["type1","type2"],sources:["source1","source2"]})}),it("should handle challenge command failure",async()=>{const n={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.TRUSTED_NAME,valuePath:[{type:"TUPLE",offset:0}],types:["type1"],sources:["source1"]}},t={...l,context:n},a=[new Uint8Array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22])];p.extractValue.mockReturnValue((0,d.Right)(a));const c=new i.UnknownDeviceExchangeError("Failed");o.sendCommand.mockResolvedValueOnce((0,i.CommandResultFactory)({error:c}));const s=new r.BuildSubcontextsTask(o,t).run();expect(s.subcontextCallbacks).toHaveLength(1);const u=s.subcontextCallbacks[0],C=await u();expect(C).toEqual({error:new Error("Failed to get challenge"),type:e.ClearSignContextType.ERROR})})}),describe("for multiple values",()=>{it("should create callbacks for each extracted value",async()=>{const n={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.TOKEN,valuePath:[{type:"TUPLE",offset:0}]}},t={...l,context:n},a=[new Uint8Array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22]),new Uint8Array([33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54])];p.extractValue.mockReturnValue((0,d.Right)(a)),x.getFieldContext.mockResolvedValueOnce({type:e.ClearSignContextType.TOKEN,payload:"token result 1"}),x.getFieldContext.mockResolvedValueOnce({type:e.ClearSignContextType.TOKEN,payload:"token result 2"});const c=new r.BuildSubcontextsTask(o,t).run();expect(c.subcontextCallbacks).toHaveLength(2);const s=c.subcontextCallbacks[0],u=c.subcontextCallbacks[1],C=await s(),y=await u();expect(C).toEqual({type:e.ClearSignContextType.TOKEN,payload:"token result 1"}),expect(y).toEqual({type:e.ClearSignContextType.TOKEN,payload:"token result 2"}),expect(x.getFieldContext).toHaveBeenCalledTimes(2),expect(x.getFieldContext).toHaveBeenNthCalledWith(1,{kind:e.ContextFieldLoaderKind.TOKEN,chainId:1,address:"0x030405060708090a0b0c0d0e0f10111213141516"}),expect(x.getFieldContext).toHaveBeenNthCalledWith(2,{kind:e.ContextFieldLoaderKind.TOKEN,chainId:1,address:"0x232425262728292a2b2c2d2e2f30313233343536"})})})})}),describe("when context has no reference",()=>{it("should return context with empty subcontextCallbacks",()=>{const n={type:e.ClearSignContextType.TOKEN,payload:"test payload"},t={...l,context:n},a=new r.BuildSubcontextsTask(o,t).run();expect(a.subcontextCallbacks).toHaveLength(0)})}),describe("when context has reference but no valuePath",()=>{it("should return context with empty subcontextCallbacks",()=>{const n={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.TOKEN,valuePath:void 0}},t={...l,context:n},a=new r.BuildSubcontextsTask(o,t).run();expect(a.subcontextCallbacks).toHaveLength(0)})}),describe("error handling",()=>{it("should throw error for uncovered context type",()=>{const t={...l,context:{type:"UNKNOWN_TYPE",payload:"test payload"}};expect(()=>new r.BuildSubcontextsTask(o,t).run()).toThrow("Uncovered type: UNKNOWN_TYPE")}),it("should throw error for uncovered reference type",()=>{const n={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:"UNKNOWN_REFERENCE_TYPE"}},t={...l,context:n};expect(()=>new r.BuildSubcontextsTask(o,t).run()).toThrow("Uncovered reference type: UNKNOWN_REFERENCE_TYPE")})}),describe("CALLDATA reference type",()=>{it("should return empty subcontextCallbacks for CALLDATA reference",()=>{const n={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.CALLDATA,callee:[{type:"TUPLE",offset:0}],valuePath:[{type:"TUPLE",offset:0}]}},t={...l,context:n},a=new r.BuildSubcontextsTask(o,t).run();expect(a.subcontextCallbacks).toHaveLength(0)})}),describe("references without valuePath",()=>{it("should return empty subcontextCallbacks for ENUM reference without valuePath",()=>{const n={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.ENUM,id:1,valuePath:void 0}},t={...l,context:n},a=new r.BuildSubcontextsTask(o,t).run();expect(a.subcontextCallbacks).toHaveLength(0)}),it("should return empty subcontextCallbacks for TRUSTED_NAME reference without valuePath",()=>{const n={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.TRUSTED_NAME,types:["type1"],sources:["source1"],valuePath:void 0}},t={...l,context:n},a=new r.BuildSubcontextsTask(o,t).run();expect(a.subcontextCallbacks).toHaveLength(0)})}),describe("PROXY_DELEGATE_CALL context type",()=>{beforeEach(()=>{o.sendCommand.mockResolvedValue((0,i.CommandResultFactory)({data:{challenge:"test-challenge"}}))}),it("should create callback to get proxy delegate call context",async()=>{const n={type:e.ClearSignContextType.PROXY_DELEGATE_CALL,payload:"proxy payload"},t={...l,context:n,subset:{...l.subset,to:"0x1234567890123456789012345678901234567890",data:"0xabcdef"}};x.getFieldContext.mockResolvedValue({type:e.ClearSignContextType.PROXY_DELEGATE_CALL,payload:"proxy result"});const a=new r.BuildSubcontextsTask(o,t).run();expect(a.subcontextCallbacks).toHaveLength(1);const c=a.subcontextCallbacks[0],s=await c();expect(s).toEqual({type:e.ClearSignContextType.PROXY_DELEGATE_CALL,payload:"proxy result"}),expect(o.sendCommand).toHaveBeenCalledWith(expect.any(b.GetChallengeCommand)),expect(x.getFieldContext).toHaveBeenCalledWith({kind:e.ContextFieldLoaderKind.PROXY_DELEGATE_CALL,chainId:1,proxyAddress:"0x1234567890123456789012345678901234567890",calldata:"0xabcdef",deviceModelId:i.DeviceModelId.STAX,challenge:"test-challenge"})}),it("should handle challenge command failure",async()=>{const n={type:e.ClearSignContextType.PROXY_DELEGATE_CALL,payload:"proxy payload"},t={...l,context:n,subset:{...l.subset,to:"0x1234567890123456789012345678901234567890",data:"0xabcdef"}},a=new i.UnknownDeviceExchangeError("Failed");o.sendCommand.mockResolvedValueOnce((0,i.CommandResultFactory)({error:a}));const c=new r.BuildSubcontextsTask(o,t).run();expect(c.subcontextCallbacks).toHaveLength(1);const s=c.subcontextCallbacks[0],u=await s();expect(u).toEqual({error:new Error("Failed to get challenge"),type:e.ClearSignContextType.ERROR}),expect(o.sendCommand).toHaveBeenCalledWith(expect.any(b.GetChallengeCommand)),expect(x.getFieldContext).not.toHaveBeenCalled()}),it("should handle missing proxy address",async()=>{const n={type:e.ClearSignContextType.PROXY_DELEGATE_CALL,payload:"proxy payload"},t={...l,context:n,subset:{...l.subset,to:void 0,data:"0xabcdef"}},a=new r.BuildSubcontextsTask(o,t).run();expect(a.subcontextCallbacks).toHaveLength(1);const c=a.subcontextCallbacks[0],s=await c();expect(s).toEqual({error:new Error("Failed to get proxy address"),type:e.ClearSignContextType.ERROR}),expect(o.sendCommand).toHaveBeenCalledWith(expect.any(b.GetChallengeCommand)),expect(x.getFieldContext).not.toHaveBeenCalled()}),it("should use correct device model id in context",async()=>{const n={type:e.ClearSignContextType.PROXY_DELEGATE_CALL,payload:"proxy payload"},t={...l,context:n,deviceModelId:i.DeviceModelId.NANO_SP,subset:{...l.subset,to:"0x1234567890123456789012345678901234567890",data:"0xabcdef"}};x.getFieldContext.mockResolvedValue({type:e.ClearSignContextType.PROXY_DELEGATE_CALL,payload:"proxy result"});const a=new r.BuildSubcontextsTask(o,t).run();expect(a.subcontextCallbacks).toHaveLength(1);const c=a.subcontextCallbacks[0];await c(),expect(x.getFieldContext).toHaveBeenCalledWith({kind:e.ContextFieldLoaderKind.PROXY_DELEGATE_CALL,chainId:1,proxyAddress:"0x1234567890123456789012345678901234567890",calldata:"0xabcdef",deviceModelId:i.DeviceModelId.NANO_SP,challenge:"test-challenge"})})}),describe("edge cases",()=>{it("should handle value array shorter than 20 bytes for address extraction",async()=>{const n={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.TOKEN,valuePath:[{type:"TUPLE",offset:0}]}},t={...l,context:n},a=[new Uint8Array([1,2,3])];p.extractValue.mockReturnValue((0,d.Right)(a)),x.getFieldContext.mockResolvedValue({type:e.ClearSignContextType.ERROR,message:"Invalid address"});const c=new r.BuildSubcontextsTask(o,t).run();expect(c.subcontextCallbacks).toHaveLength(1);const s=c.subcontextCallbacks[0],u=await s();expect(u).toEqual({type:e.ClearSignContextType.ERROR,message:"Invalid address"}),expect(x.getFieldContext).toHaveBeenCalledWith({kind:e.ContextFieldLoaderKind.TOKEN,chainId:1,address:"0x010203"})}),it("should handle empty value array",async()=>{const n={type:e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:e.ClearSignContextReferenceType.TOKEN,valuePath:[{type:"TUPLE",offset:0}]}},t={...l,context:n},a=[new Uint8Array([])];p.extractValue.mockReturnValue((0,d.Right)(a)),x.getFieldContext.mockResolvedValue({type:e.ClearSignContextType.TOKEN,payload:"token result"});const c=new r.BuildSubcontextsTask(o,t).run();expect(c.subcontextCallbacks).toHaveLength(1);const s=c.subcontextCallbacks[0],u=await s();expect(u).toEqual({type:e.ClearSignContextType.TOKEN,payload:"token result"}),expect(x.getFieldContext).toHaveBeenCalledWith({kind:e.ContextFieldLoaderKind.TOKEN,chainId:1,address:"0x"})})})});
2
2
  //# sourceMappingURL=BuildSubcontextsTask.test.js.map