@ledgerhq/device-signer-kit-ethereum 0.0.0-ledger-button-20250808181454 → 0.0.0-ledger-button-20250821162931

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 (22) hide show
  1. package/lib/cjs/internal/app-binder/task/BuildTransactionContextTask.js +1 -1
  2. package/lib/cjs/internal/app-binder/task/BuildTransactionContextTask.js.map +2 -2
  3. package/lib/cjs/internal/app-binder/task/BuildTransactionContextTask.test.js +1 -1
  4. package/lib/cjs/internal/app-binder/task/BuildTransactionContextTask.test.js.map +2 -2
  5. package/lib/cjs/internal/app-binder/task/ProvideTransactionContextTask.js +1 -1
  6. package/lib/cjs/internal/app-binder/task/ProvideTransactionContextTask.js.map +3 -3
  7. package/lib/cjs/internal/app-binder/task/ProvideTransactionContextTask.test.js +1 -1
  8. package/lib/cjs/internal/app-binder/task/ProvideTransactionContextTask.test.js.map +3 -3
  9. package/lib/cjs/package.json +1 -1
  10. package/lib/esm/internal/app-binder/task/BuildTransactionContextTask.js +1 -1
  11. package/lib/esm/internal/app-binder/task/BuildTransactionContextTask.js.map +2 -2
  12. package/lib/esm/internal/app-binder/task/BuildTransactionContextTask.test.js +1 -1
  13. package/lib/esm/internal/app-binder/task/BuildTransactionContextTask.test.js.map +2 -2
  14. package/lib/esm/internal/app-binder/task/ProvideTransactionContextTask.js +1 -1
  15. package/lib/esm/internal/app-binder/task/ProvideTransactionContextTask.js.map +3 -3
  16. package/lib/esm/internal/app-binder/task/ProvideTransactionContextTask.test.js +1 -1
  17. package/lib/esm/internal/app-binder/task/ProvideTransactionContextTask.test.js.map +3 -3
  18. package/lib/esm/package.json +1 -1
  19. package/lib/types/internal/app-binder/task/BuildTransactionContextTask.d.ts.map +1 -1
  20. package/lib/types/internal/app-binder/task/ProvideTransactionContextTask.d.ts.map +1 -1
  21. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  22. package/package.json +8 -8
@@ -1,2 +1,2 @@
1
- "use strict";var g=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var R=(o,e)=>{for(var n in e)g(o,n,{get:e[n],enumerable:!0})},_=(o,e,n,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of E(e))!O.call(o,i)&&i!==n&&g(o,i,{get:()=>e[i],enumerable:!(s=v(e,i))||s.enumerable});return o};var b=o=>_(g({},"__esModule",{value:!0}),o);var w={};R(w,{BuildTransactionContextTask:()=>M});module.exports=b(w);var a=require("@ledgerhq/context-module"),c=require("@ledgerhq/device-management-kit"),y=require("../../../api/model/ClearSigningType"),h=require("../../app-binder/command/GetChallengeCommand"),I=require("../../app-binder/task/GetWeb3CheckTask"),A=require("../../shared/utils/ApplicationChecker");class M{constructor(e,n,s=(i,C)=>new I.GetWeb3CheckTask(i,C)){this._api=e;this._args=n;this.getWeb3ChecksFactory=s}async run(){const{contextModule:e,options:n,appConfig:s,derivationPath:i,transaction:C,subset:u}=this._args,p=this._api.getDeviceSessionState();let r=[],T=[],x=y.ClearSigningType.BASIC,l=null;s.web3ChecksEnabled&&(l=(await this.getWeb3ChecksFactory(this._api,{contextModule:e,derivationPath:i,subset:u,transaction:C}).run()).web3Check);let m;if(p.deviceModelId!==c.DeviceModelId.NANO_S){const t=await this._api.sendCommand(new h.GetChallengeCommand);(0,c.isSuccessCommandResult)(t)&&(m=t.data.challenge)}const f=await e.getContexts({challenge:m,domain:n.domain,deviceModelId:p.deviceModelId,...u}),d=f.filter(t=>t.type!==a.ClearSignContextType.ERROR&&t.type!==a.ClearSignContextType.ENUM),N=f.filter(t=>t.type===a.ClearSignContextType.ENUM),S=d.find(t=>t.type===a.ClearSignContextType.TRANSACTION_INFO);if(!this.supportsGenericParser(p,s)||S===void 0)r=d.filter(t=>t.type!==a.ClearSignContextType.TRANSACTION_INFO&&t.type!==a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION),l&&(r=[l,...r]);else if(S.certificate){const t=d.filter(k=>k.type===a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION);r=[S,...t,...l?[l]:[]],T=[...N],x=y.ClearSigningType.EIP7730}return{clearSignContexts:r,clearSignContextsOptional:T,clearSigningType:x}}supportsGenericParser(e,n){return new A.ApplicationChecker(e,n).withMinVersionExclusive("1.14.0").excludeDeviceModel(c.DeviceModelId.NANO_S).check()}}0&&(module.exports={BuildTransactionContextTask});
1
+ "use strict";var y=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var R=Object.prototype.hasOwnProperty;var _=(a,e)=>{for(var n in e)y(a,n,{get:e[n],enumerable:!0})},v=(a,e,n,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of O(e))!R.call(a,i)&&i!==n&&y(a,i,{get:()=>e[i],enumerable:!(s=k(e,i))||s.enumerable});return a};var b=a=>v(y({},"__esModule",{value:!0}),a);var w={};_(w,{BuildTransactionContextTask:()=>M});module.exports=b(w);var o=require("@ledgerhq/context-module"),c=require("@ledgerhq/device-management-kit"),u=require("../../../api/model/ClearSigningType"),A=require("../../app-binder/command/GetChallengeCommand"),I=require("../../app-binder/task/GetWeb3CheckTask"),N=require("../../shared/utils/ApplicationChecker");class M{constructor(e,n,s=(i,p)=>new I.GetWeb3CheckTask(i,p)){this._api=e;this._args=n;this.getWeb3ChecksFactory=s}async run(){const{contextModule:e,options:n,appConfig:s,derivationPath:i,transaction:p,subset:x}=this._args,d=this._api.getDeviceSessionState();let r=[],T=[],f=u.ClearSigningType.BASIC,l=null;s.web3ChecksEnabled&&(l=(await this.getWeb3ChecksFactory(this._api,{contextModule:e,derivationPath:i,subset:x,transaction:p}).run()).web3Check);let m;if(d.deviceModelId!==c.DeviceModelId.NANO_S){const t=await this._api.sendCommand(new A.GetChallengeCommand);(0,c.isSuccessCommandResult)(t)&&(m=t.data.challenge)}const h=await e.getContexts({challenge:m,domain:n.domain,deviceModelId:d.deviceModelId,...x}),C=h.filter(t=>t.type!==o.ClearSignContextType.ERROR&&t.type!==o.ClearSignContextType.ENUM),E=h.filter(t=>t.type===o.ClearSignContextType.ENUM),S=C.find(t=>t.type===o.ClearSignContextType.TRANSACTION_INFO);if(!this.supportsGenericParser(d,s)||S===void 0)r=C.filter(t=>t.type!==o.ClearSignContextType.TRANSACTION_INFO&&t.type!==o.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION),l&&(r=[l,...r]);else if(S.certificate){const t=C.filter(g=>g.type===o.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION);r=[...C.filter(g=>g.type===o.ClearSignContextType.PROXY_DELEGATE_CALL),S,...t,...l?[l]:[]],T=[...E],f=u.ClearSigningType.EIP7730}return{clearSignContexts:r,clearSignContextsOptional:T,clearSigningType:f}}supportsGenericParser(e,n){return new N.ApplicationChecker(e,n).withMinVersionExclusive("1.14.0").excludeDeviceModel(c.DeviceModelId.NANO_S).check()}}0&&(module.exports={BuildTransactionContextTask});
2
2
  //# sourceMappingURL=BuildTransactionContextTask.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/internal/app-binder/task/BuildTransactionContextTask.ts"],
4
- "sourcesContent": ["import {\n type ClearSignContextSuccess,\n type ClearSignContextSuccessType,\n ClearSignContextType,\n type ContextModule,\n type TransactionSubset,\n} from \"@ledgerhq/context-module\";\nimport {\n DeviceModelId,\n type DeviceSessionState,\n type InternalApi,\n isSuccessCommandResult,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { type GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\nimport { ClearSigningType } from \"@api/model/ClearSigningType\";\nimport { type TransactionOptions } from \"@api/model/TransactionOptions\";\nimport { GetChallengeCommand } from \"@internal/app-binder/command/GetChallengeCommand\";\nimport {\n GetWeb3CheckTask,\n type GetWeb3CheckTaskArgs,\n} from \"@internal/app-binder/task/GetWeb3CheckTask\";\nimport { ApplicationChecker } from \"@internal/shared/utils/ApplicationChecker\";\n\nexport type BuildTransactionTaskResult = {\n readonly clearSignContexts: ClearSignContextSuccess[];\n readonly clearSignContextsOptional: ClearSignContextSuccess[];\n readonly clearSigningType: ClearSigningType;\n};\n\nexport type BuildTransactionContextTaskArgs = {\n readonly contextModule: ContextModule;\n readonly options: TransactionOptions;\n readonly appConfig: GetConfigCommandResponse;\n readonly derivationPath: string;\n readonly transaction: Uint8Array;\n readonly subset: TransactionSubset;\n};\n\nexport class BuildTransactionContextTask {\n constructor(\n private readonly _api: InternalApi,\n private readonly _args: BuildTransactionContextTaskArgs,\n private readonly getWeb3ChecksFactory = (\n api: InternalApi,\n args: GetWeb3CheckTaskArgs,\n ) => new GetWeb3CheckTask(api, args),\n ) {}\n\n async run(): Promise<BuildTransactionTaskResult> {\n const {\n contextModule,\n options,\n appConfig,\n derivationPath,\n transaction,\n subset,\n } = this._args;\n const deviceState = this._api.getDeviceSessionState();\n let filteredContexts: ClearSignContextSuccess[] = [];\n let filteredContextOptional: ClearSignContextSuccess[] = [];\n let clearSigningType: ClearSigningType = ClearSigningType.BASIC;\n\n // Run the web3checks if needed\n let web3Check: ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK> | null =\n null;\n if (appConfig.web3ChecksEnabled) {\n web3Check = (\n await this.getWeb3ChecksFactory(this._api, {\n contextModule,\n derivationPath,\n subset,\n transaction,\n }).run()\n ).web3Check;\n }\n\n // Get challenge (not supported on Nano S)\n let challenge: string | undefined = undefined;\n if (deviceState.deviceModelId !== DeviceModelId.NANO_S) {\n const challengeRes = await this._api.sendCommand(\n new GetChallengeCommand(),\n );\n if (isSuccessCommandResult(challengeRes)) {\n challenge = challengeRes.data.challenge;\n }\n }\n\n // Get the clear sign contexts\n const clearSignContexts = await contextModule.getContexts({\n challenge: challenge,\n domain: options.domain,\n deviceModelId: deviceState.deviceModelId,\n ...subset,\n });\n\n // NOTE: we need to filter out the ENUM and ERROR types\n // ENUM are handled differently\n // ERROR are not handled at all for now\n const clearSignContextsSuccess: ClearSignContextSuccess<\n Exclude<ClearSignContextSuccessType, ClearSignContextType.ENUM>\n >[] = clearSignContexts.filter(\n (context) =>\n context.type !== ClearSignContextType.ERROR &&\n context.type !== ClearSignContextType.ENUM,\n );\n\n // Retrieve all ENUM contexts\n const transactionEnums: ClearSignContextSuccess<ClearSignContextType.ENUM>[] =\n clearSignContexts.filter(\n (context) => context.type === ClearSignContextType.ENUM,\n );\n\n const transactionInfo = clearSignContextsSuccess.find(\n (ctx) => ctx.type === ClearSignContextType.TRANSACTION_INFO,\n );\n\n // If the device does not support the generic parser,\n // we need to filter out the transaction info and transaction field description\n // as they are not supported by the device\n if (\n !this.supportsGenericParser(deviceState, appConfig) ||\n transactionInfo === undefined\n ) {\n filteredContexts = clearSignContextsSuccess.filter(\n (ctx) =>\n ctx.type !== ClearSignContextType.TRANSACTION_INFO &&\n ctx.type !== ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n );\n\n // If the device supports the web3 check, we need to add it to the list of contexts\n if (web3Check) {\n filteredContexts = [web3Check, ...filteredContexts];\n }\n } else if (transactionInfo.certificate) {\n const transactionFields = clearSignContextsSuccess.filter(\n (ctx) =>\n ctx.type === ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n );\n\n filteredContexts = [\n transactionInfo,\n ...transactionFields,\n ...(web3Check ? [web3Check] : []),\n ];\n filteredContextOptional = [...transactionEnums];\n clearSigningType = ClearSigningType.EIP7730;\n }\n\n return {\n clearSignContexts: filteredContexts,\n clearSignContextsOptional: filteredContextOptional,\n clearSigningType,\n };\n }\n\n private supportsGenericParser(\n deviceState: DeviceSessionState,\n appConfig: GetConfigCommandResponse,\n ): boolean {\n return new ApplicationChecker(deviceState, appConfig)\n .withMinVersionExclusive(\"1.14.0\")\n .excludeDeviceModel(DeviceModelId.NANO_S)\n .check();\n }\n}\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAMO,oCACPC,EAKO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AAS,uBAAqB,6BACtC,EAGIR,IACFH,EAAmB,CAACG,EAAW,GAAGH,CAAgB,WAE3CU,EAAgB,YAAa,CACtC,MAAME,EAAoBL,EAAyB,OAChDI,GACCA,EAAI,OAAS,uBAAqB,6BACtC,EAEAX,EAAmB,CACjBU,EACA,GAAGE,EACH,GAAIT,EAAY,CAACA,CAAS,EAAI,CAAC,CACjC,EACAF,EAA0B,CAAC,GAAGQ,CAAgB,EAC9CP,EAAmB,mBAAiB,OACtC,CAEA,MAAO,CACL,kBAAmBF,EACnB,0BAA2BC,EAC3B,iBAAAC,CACF,CACF,CAEQ,sBACNH,EACAJ,EACS,CACT,OAAO,IAAI,qBAAmBI,EAAaJ,CAAS,EACjD,wBAAwB,QAAQ,EAChC,mBAAmB,gBAAc,MAAM,EACvC,MAAM,CACX,CACF",
4
+ "sourcesContent": ["import {\n type ClearSignContext,\n type ClearSignContextSuccess,\n type ClearSignContextSuccessType,\n ClearSignContextType,\n type ContextModule,\n type TransactionSubset,\n} from \"@ledgerhq/context-module\";\nimport {\n DeviceModelId,\n type DeviceSessionState,\n type InternalApi,\n isSuccessCommandResult,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { type GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\nimport { ClearSigningType } from \"@api/model/ClearSigningType\";\nimport { type TransactionOptions } from \"@api/model/TransactionOptions\";\nimport { GetChallengeCommand } from \"@internal/app-binder/command/GetChallengeCommand\";\nimport {\n GetWeb3CheckTask,\n type GetWeb3CheckTaskArgs,\n} from \"@internal/app-binder/task/GetWeb3CheckTask\";\nimport { ApplicationChecker } from \"@internal/shared/utils/ApplicationChecker\";\n\nexport type BuildTransactionTaskResult = {\n readonly clearSignContexts: ClearSignContextSuccess[];\n readonly clearSignContextsOptional: ClearSignContextSuccess[];\n readonly clearSigningType: ClearSigningType;\n};\n\nexport type BuildTransactionContextTaskArgs = {\n readonly contextModule: ContextModule;\n readonly options: TransactionOptions;\n readonly appConfig: GetConfigCommandResponse;\n readonly derivationPath: string;\n readonly transaction: Uint8Array;\n readonly subset: TransactionSubset;\n};\n\nexport class BuildTransactionContextTask {\n constructor(\n private readonly _api: InternalApi,\n private readonly _args: BuildTransactionContextTaskArgs,\n private readonly getWeb3ChecksFactory = (\n api: InternalApi,\n args: GetWeb3CheckTaskArgs,\n ) => new GetWeb3CheckTask(api, args),\n ) {}\n\n async run(): Promise<BuildTransactionTaskResult> {\n const {\n contextModule,\n options,\n appConfig,\n derivationPath,\n transaction,\n subset,\n } = this._args;\n const deviceState = this._api.getDeviceSessionState();\n let filteredContexts: ClearSignContextSuccess[] = [];\n let filteredContextOptional: ClearSignContextSuccess[] = [];\n let clearSigningType: ClearSigningType = ClearSigningType.BASIC;\n\n // Run the web3checks if needed\n let web3Check: ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK> | null =\n null;\n if (appConfig.web3ChecksEnabled) {\n web3Check = (\n await this.getWeb3ChecksFactory(this._api, {\n contextModule,\n derivationPath,\n subset,\n transaction,\n }).run()\n ).web3Check;\n }\n\n // Get challenge (not supported on Nano S)\n let challenge: string | undefined = undefined;\n if (deviceState.deviceModelId !== DeviceModelId.NANO_S) {\n const challengeRes = await this._api.sendCommand(\n new GetChallengeCommand(),\n );\n if (isSuccessCommandResult(challengeRes)) {\n challenge = challengeRes.data.challenge;\n }\n }\n\n // Get the clear sign contexts\n const clearSignContexts: ClearSignContext[] =\n await contextModule.getContexts({\n challenge: challenge,\n domain: options.domain,\n deviceModelId: deviceState.deviceModelId,\n ...subset,\n });\n\n // NOTE: we need to filter out the ENUM and ERROR types\n // ENUM are handled differently\n // ERROR are not handled at all for now\n const clearSignContextsSuccess: ClearSignContextSuccess<\n Exclude<ClearSignContextSuccessType, ClearSignContextType.ENUM>\n >[] = clearSignContexts.filter(\n (context) =>\n context.type !== ClearSignContextType.ERROR &&\n context.type !== ClearSignContextType.ENUM,\n );\n\n // Retrieve all ENUM contexts\n const transactionEnums: ClearSignContextSuccess<ClearSignContextType.ENUM>[] =\n clearSignContexts.filter(\n (context) => context.type === ClearSignContextType.ENUM,\n );\n\n const transactionInfo = clearSignContextsSuccess.find(\n (ctx) => ctx.type === ClearSignContextType.TRANSACTION_INFO,\n );\n\n // If the device does not support the generic parser,\n // we need to filter out the transaction info and transaction field description\n // as they are not supported by the device\n if (\n !this.supportsGenericParser(deviceState, appConfig) ||\n transactionInfo === undefined\n ) {\n filteredContexts = clearSignContextsSuccess.filter(\n (ctx) =>\n ctx.type !== ClearSignContextType.TRANSACTION_INFO &&\n ctx.type !== ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n );\n\n // If the device supports the web3 check, we need to add it to the list of contexts\n if (web3Check) {\n filteredContexts = [web3Check, ...filteredContexts];\n }\n } else if (transactionInfo.certificate) {\n const transactionFields = clearSignContextsSuccess.filter(\n (ctx) =>\n ctx.type === ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n );\n const proxyContexts = clearSignContextsSuccess.filter(\n (ctx) => ctx.type === ClearSignContextType.PROXY_DELEGATE_CALL,\n );\n\n filteredContexts = [\n ...proxyContexts,\n transactionInfo,\n ...transactionFields,\n ...(web3Check ? [web3Check] : []),\n ];\n filteredContextOptional = [...transactionEnums];\n clearSigningType = ClearSigningType.EIP7730;\n }\n\n return {\n clearSignContexts: filteredContexts,\n clearSignContextsOptional: filteredContextOptional,\n clearSigningType,\n };\n }\n\n private supportsGenericParser(\n deviceState: DeviceSessionState,\n appConfig: GetConfigCommandResponse,\n ): boolean {\n return new ApplicationChecker(deviceState, appConfig)\n .withMinVersionExclusive(\"1.14.0\")\n .excludeDeviceModel(DeviceModelId.NANO_S)\n .check();\n }\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAOO,oCACPC,EAKO,2CAGPC,EAAiC,uCAEjCC,EAAoC,4DACpCC,EAGO,sDACPC,EAAmC,qDAiB5B,MAAMP,CAA4B,C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,CACtC,MAAME,EAAoBL,EAAyB,OAChDI,GACCA,EAAI,OAAS,uBAAqB,6BACtC,EAKAX,EAAmB,CACjB,GALoBO,EAAyB,OAC5CI,GAAQA,EAAI,OAAS,uBAAqB,mBAC7C,EAIED,EACA,GAAGE,EACH,GAAIT,EAAY,CAACA,CAAS,EAAI,CAAC,CACjC,EACAF,EAA0B,CAAC,GAAGQ,CAAgB,EAC9CP,EAAmB,mBAAiB,OACtC,CAEA,MAAO,CACL,kBAAmBF,EACnB,0BAA2BC,EAC3B,iBAAAC,CACF,CACF,CAEQ,sBACNH,EACAJ,EACS,CACT,OAAO,IAAI,qBAAmBI,EAAaJ,CAAS,EACjD,wBAAwB,QAAQ,EAChC,mBAAmB,gBAAc,MAAM,EACvC,MAAM,CACX,CACF",
6
6
  "names": ["BuildTransactionContextTask_exports", "__export", "BuildTransactionContextTask", "__toCommonJS", "import_context_module", "import_device_management_kit", "import_ClearSigningType", "import_GetChallengeCommand", "import_GetWeb3CheckTask", "import_ApplicationChecker", "_api", "_args", "getWeb3ChecksFactory", "api", "args", "contextModule", "options", "appConfig", "derivationPath", "transaction", "subset", "deviceState", "filteredContexts", "filteredContextOptional", "clearSigningType", "web3Check", "challenge", "challengeRes", "clearSignContexts", "clearSignContextsSuccess", "context", "transactionEnums", "transactionInfo", "ctx", "transactionFields"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var n=require("@ledgerhq/context-module"),t=require("@ledgerhq/device-management-kit"),S=require("ethers"),d=require("../../../api/model/ClearSigningType"),y=require("../../app-binder/device-action/__test-utils__/makeInternalApi"),l=require("./BuildTransactionContextTask"),g=require("./GetWeb3CheckTask");describe("BuildTransactionContextTask",()=>{const s={getContext:vi.fn(),getContexts:vi.fn(),getTypedDataFilters:vi.fn(),getWeb3Checks:vi.fn(),getSolanaContext:vi.fn()},x={domain:"domain-name.eth"},C=(0,t.hexaStringToBuffer)(S.Transaction.from({chainId:1n,nonce:0,data:"0x"}).unsignedSerialized),r={keyUsageNumber:1,payload:new Uint8Array([1,2,3])};let c;const a=(0,y.makeDeviceActionInternalApiMock)(),i=vi.fn();function u(e){return{blindSigningEnabled:!1,web3ChecksEnabled:e,web3ChecksOptIn:!1,version:"1.13.0"}}beforeEach(()=>{vi.resetAllMocks(),a.sendCommand.mockResolvedValue((0,t.CommandResultFactory)({data:{challenge:"challenge"}})),i.mockReturnValue({run:async()=>Promise.resolve({web3Check:null})}),c={contextModule:s,subset:{chainId:1,to:void 0,data:"0x",selector:"0x"},transaction:C,options:x,appConfig:u(!1),derivationPath:"44'/60'/0'/0/0"}}),it("should init with a default GetWeb3CheckTaskFactory",()=>{const e=new l.BuildTransactionContextTask(a,c);expect(e.getWeb3ChecksFactory).toBeDefined(),expect(e.getWeb3ChecksFactory(a,{contextModule:c.contextModule,derivationPath:c.derivationPath,subset:c.subset,transaction:c.transaction})).toBeInstanceOf(g.GetWeb3CheckTask)}),it("should build the transaction context without clear sign contexts",async()=>{const e=[],o=[];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new l.BuildTransactionContextTask(a,{...c,appConfig:u(!0)},i).run();expect(p).toEqual({clearSignContexts:e,clearSignContextsOptional:o,clearSigningType:d.ClearSigningType.BASIC})}),it("should build the transaction context with web3checks",async()=>{const e=[],o=[],p="web3Check";i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:p})}),s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const E=await new l.BuildTransactionContextTask(a,{...c,appConfig:u(!0)},i).run();expect(E).toEqual({clearSignContexts:[p,...e],clearSignContextsOptional:o,clearSigningType:d.ClearSigningType.BASIC})}),it("should build the transaction context with web3checks and generic-parser clear sign contexts",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}],o="web3Check";i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:o})}),s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new l.BuildTransactionContextTask(a,{...c,appConfig:u(!0)},i).run();expect(p).toEqual({clearSignContexts:[e[0],e[1],e[3],o],clearSignContextsOptional:[e[2]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should build the transaction context with web3checks and generic-parser clear sign contexts in the correct order",async()=>{const e=[{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:r}],o="web3Check";i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:o})}),s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new l.BuildTransactionContextTask(a,{...c,appConfig:u(!0)},i).run();expect(p).toEqual({clearSignContexts:[e[3],e[1],e[2],o],clearSignContextsOptional:[e[0]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should build the transaction context with clear sign contexts",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.NFT,payload:"payload-2"}],o="web3Check";i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:o})}),s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new l.BuildTransactionContextTask(a,c,i).run();expect(p).toEqual({clearSignContexts:e,clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should build the transaction context with generic-parser context",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new l.BuildTransactionContextTask(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0],e[1],e[3]],clearSignContextsOptional:[e[2]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should call the web3checks factory with correct parameters",async()=>{const e=[];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),await new l.BuildTransactionContextTask(a,{...c,appConfig:u(!0)},i).run(),expect(i).toHaveBeenCalledWith(a,{contextModule:s,derivationPath:"44'/60'/0'/0/0",subset:c.subset,transaction:C})}),it("should call the context module with the correct parameters",async()=>{const e=[];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),await new l.BuildTransactionContextTask(a,c,i).run(),expect(s.getContexts).toHaveBeenCalledWith({deviceModelId:t.DeviceModelId.FLEX,challenge:"challenge",domain:"domain-name.eth",...c.subset})}),it("should call the context module without challenge for Nano S",async()=>{const e=[];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.NANO_S,isSecureConnectionAllowed:!1}),await new l.BuildTransactionContextTask(a,c,i).run(),expect(s.getContexts).toHaveBeenCalledWith({deviceModelId:t.DeviceModelId.NANO_S,domain:"domain-name.eth",...c.subset})}),it("should call the context module without context on error",async()=>{const e=[];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),a.sendCommand.mockResolvedValueOnce((0,t.CommandResultFactory)({error:new t.UnknownDeviceExchangeError})),await new l.BuildTransactionContextTask(a,c,i).run(),expect(s.getContexts).toHaveBeenCalledWith({deviceModelId:t.DeviceModelId.FLEX,challenge:void 0,domain:"domain-name.eth",...c.subset})}),it("should exclude error contexts from the result",async()=>{const e=[{type:n.ClearSignContextType.ERROR,error:new Error("error")},{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.ERROR,error:new Error("error")},{type:n.ClearSignContextType.NFT,payload:"payload-2"}];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new l.BuildTransactionContextTask(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts from the result on old apps",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"transaction_info",certificate:r},{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:n.ClearSignContextType.NFT,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"enum",id:1,value:2,certificate:r}];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new l.BuildTransactionContextTask(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts from the result if no transaction_info was found",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.ENUM,payload:"enum",id:1,value:2},{type:n.ClearSignContextType.NFT,payload:"payload-2"}];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new l.BuildTransactionContextTask(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude legacy contexts from the result for generic-parser transactions",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.EXTERNAL_PLUGIN,payload:"payload-3"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"},{type:n.ClearSignContextType.ENUM,payload:"payload-5",id:1,value:2,certificate:r}];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new l.BuildTransactionContextTask(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[e[4]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should exclude generic-parser contexts with a nano s device",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:n.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:r}];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:t.DeviceModelId.NANO_S,isSecureConnectionAllowed:!1});const o=await new l.BuildTransactionContextTask(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts with an old app version",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:n.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:r}];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new l.BuildTransactionContextTask(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts with a non ready device",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:n.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:r}];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.Connected,deviceStatus:t.DeviceStatus.NOT_CONNECTED,deviceModelId:t.DeviceModelId.FLEX});const o=await new l.BuildTransactionContextTask(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should return no clear sign context if the transaction info certificate is missing",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2}];s.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.17.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new l.BuildTransactionContextTask(a,c,i).run();expect(o).toEqual({clearSignContexts:[],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})})});
1
+ "use strict";var n=require("@ledgerhq/context-module"),t=require("@ledgerhq/device-management-kit"),S=require("ethers"),d=require("../../../api/model/ClearSigningType"),y=require("../../app-binder/device-action/__test-utils__/makeInternalApi"),s=require("./BuildTransactionContextTask"),g=require("./GetWeb3CheckTask");describe("BuildTransactionContextTask",()=>{const l={getContext:vi.fn(),getContexts:vi.fn(),getTypedDataFilters:vi.fn(),getWeb3Checks:vi.fn(),getSolanaContext:vi.fn()},x={domain:"domain-name.eth"},C=(0,t.hexaStringToBuffer)(S.Transaction.from({chainId:1n,nonce:0,data:"0x"}).unsignedSerialized),r={keyUsageNumber:1,payload:new Uint8Array([1,2,3])};let c;const a=(0,y.makeDeviceActionInternalApiMock)(),i=vi.fn();function u(e){return{blindSigningEnabled:!1,web3ChecksEnabled:e,web3ChecksOptIn:!1,version:"1.13.0"}}beforeEach(()=>{vi.resetAllMocks(),a.sendCommand.mockResolvedValue((0,t.CommandResultFactory)({data:{challenge:"challenge"}})),i.mockReturnValue({run:async()=>Promise.resolve({web3Check:null})}),c={contextModule:l,subset:{chainId:1,to:void 0,data:"0x",selector:"0x"},transaction:C,options:x,appConfig:u(!1),derivationPath:"44'/60'/0'/0/0"}}),it("should init with a default GetWeb3CheckTaskFactory",()=>{const e=new s.BuildTransactionContextTask(a,c);expect(e.getWeb3ChecksFactory).toBeDefined(),expect(e.getWeb3ChecksFactory(a,{contextModule:c.contextModule,derivationPath:c.derivationPath,subset:c.subset,transaction:c.transaction})).toBeInstanceOf(g.GetWeb3CheckTask)}),it("should build the transaction context without clear sign contexts",async()=>{const e=[],o=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new s.BuildTransactionContextTask(a,{...c,appConfig:u(!0)},i).run();expect(p).toEqual({clearSignContexts:e,clearSignContextsOptional:o,clearSigningType:d.ClearSigningType.BASIC})}),it("should build the transaction context with web3checks",async()=>{const e=[],o=[],p="web3Check";i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:p})}),l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const E=await new s.BuildTransactionContextTask(a,{...c,appConfig:u(!0)},i).run();expect(E).toEqual({clearSignContexts:[p,...e],clearSignContextsOptional:o,clearSigningType:d.ClearSigningType.BASIC})}),it("should build the transaction context with web3checks and generic-parser clear sign contexts",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}],o="web3Check";i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:o})}),l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new s.BuildTransactionContextTask(a,{...c,appConfig:u(!0)},i).run();expect(p).toEqual({clearSignContexts:[e[0],e[1],e[3],o],clearSignContextsOptional:[e[2]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should build the transaction context with web3checks and generic-parser clear sign contexts in the correct order",async()=>{const e=[{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:r}],o="web3Check";i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:o})}),l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new s.BuildTransactionContextTask(a,{...c,appConfig:u(!0)},i).run();expect(p).toEqual({clearSignContexts:[e[3],e[1],e[2],o],clearSignContextsOptional:[e[0]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should build the transaction context with clear sign contexts",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.NFT,payload:"payload-2"}],o="web3Check";i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:o})}),l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new s.BuildTransactionContextTask(a,c,i).run();expect(p).toEqual({clearSignContexts:e,clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should build the transaction context with generic-parser context",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildTransactionContextTask(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0],e[1],e[3]],clearSignContextsOptional:[e[2]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should build the transaction context with proxy delegate call context",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:r},{type:n.ClearSignContextType.PROXY_DELEGATE_CALL,payload:"payload-2"}],o=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new s.BuildTransactionContextTask(a,c,i).run();expect(p).toEqual({clearSignContexts:[e[1],e[0]],clearSignContextsOptional:o,clearSigningType:d.ClearSigningType.EIP7730})}),it("should call the web3checks factory with correct parameters",async()=>{const e=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),await new s.BuildTransactionContextTask(a,{...c,appConfig:u(!0)},i).run(),expect(i).toHaveBeenCalledWith(a,{contextModule:l,derivationPath:"44'/60'/0'/0/0",subset:c.subset,transaction:C})}),it("should call the context module with the correct parameters",async()=>{const e=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),await new s.BuildTransactionContextTask(a,c,i).run(),expect(l.getContexts).toHaveBeenCalledWith({deviceModelId:t.DeviceModelId.FLEX,challenge:"challenge",domain:"domain-name.eth",...c.subset})}),it("should call the context module without challenge for Nano S",async()=>{const e=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.NANO_S,isSecureConnectionAllowed:!1}),await new s.BuildTransactionContextTask(a,c,i).run(),expect(l.getContexts).toHaveBeenCalledWith({deviceModelId:t.DeviceModelId.NANO_S,domain:"domain-name.eth",...c.subset})}),it("should call the context module without context on error",async()=>{const e=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),a.sendCommand.mockResolvedValueOnce((0,t.CommandResultFactory)({error:new t.UnknownDeviceExchangeError})),await new s.BuildTransactionContextTask(a,c,i).run(),expect(l.getContexts).toHaveBeenCalledWith({deviceModelId:t.DeviceModelId.FLEX,challenge:void 0,domain:"domain-name.eth",...c.subset})}),it("should exclude error contexts from the result",async()=>{const e=[{type:n.ClearSignContextType.ERROR,error:new Error("error")},{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.ERROR,error:new Error("error")},{type:n.ClearSignContextType.NFT,payload:"payload-2"}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildTransactionContextTask(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts from the result on old apps",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"transaction_info",certificate:r},{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:n.ClearSignContextType.NFT,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"enum",id:1,value:2,certificate:r}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildTransactionContextTask(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts from the result if no transaction_info was found",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.ENUM,payload:"enum",id:1,value:2},{type:n.ClearSignContextType.NFT,payload:"payload-2"}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildTransactionContextTask(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude legacy contexts from the result for generic-parser transactions",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.EXTERNAL_PLUGIN,payload:"payload-3"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"},{type:n.ClearSignContextType.ENUM,payload:"payload-5",id:1,value:2,certificate:r}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildTransactionContextTask(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[e[4]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should exclude generic-parser contexts with a nano s device",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:n.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:r}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:t.DeviceModelId.NANO_S,isSecureConnectionAllowed:!1});const o=await new s.BuildTransactionContextTask(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts with an old app version",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:n.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:r}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildTransactionContextTask(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts with a non ready device",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:n.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:r}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.Connected,deviceStatus:t.DeviceStatus.NOT_CONNECTED,deviceModelId:t.DeviceModelId.FLEX});const o=await new s.BuildTransactionContextTask(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should return no clear sign context if the transaction info certificate is missing",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.17.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildTransactionContextTask(a,c,i).run();expect(o).toEqual({clearSignContexts:[],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})})});
2
2
  //# sourceMappingURL=BuildTransactionContextTask.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/internal/app-binder/task/BuildTransactionContextTask.test.ts"],
4
- "sourcesContent": ["import {\n type ClearSignContext,\n type ClearSignContextSuccess,\n ClearSignContextType,\n type PkiCertificate,\n} from \"@ledgerhq/context-module\";\nimport {\n CommandResultFactory,\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n hexaStringToBuffer,\n UnknownDeviceExchangeError,\n} from \"@ledgerhq/device-management-kit\";\nimport { Transaction } from \"ethers\";\n\nimport type { GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\nimport { ClearSigningType } from \"@api/model/ClearSigningType\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\n\nimport {\n BuildTransactionContextTask,\n type BuildTransactionContextTaskArgs,\n} from \"./BuildTransactionContextTask\";\nimport { GetWeb3CheckTask } from \"./GetWeb3CheckTask\";\n\ndescribe(\"BuildTransactionContextTask\", () => {\n const contextModuleMock = {\n getContext: vi.fn(),\n getContexts: vi.fn(),\n getTypedDataFilters: vi.fn(),\n getWeb3Checks: vi.fn(),\n getSolanaContext: vi.fn(),\n };\n const defaultOptions = {\n domain: \"domain-name.eth\",\n };\n const defaultTransaction: Uint8Array = hexaStringToBuffer(\n Transaction.from({\n chainId: 1n,\n nonce: 0,\n data: \"0x\",\n }).unsignedSerialized,\n )!;\n const defaultCertificate: PkiCertificate = {\n keyUsageNumber: 1,\n payload: new Uint8Array([0x01, 0x02, 0x03]),\n };\n\n let defaultArgs: BuildTransactionContextTaskArgs;\n const apiMock = makeDeviceActionInternalApiMock();\n const getWeb3ChecksFactoryMock = vi.fn();\n\n function createAppConfig(\n web3ChecksEnabled: boolean,\n ): GetConfigCommandResponse {\n return {\n blindSigningEnabled: false,\n web3ChecksEnabled,\n web3ChecksOptIn: false,\n version: \"1.13.0\",\n };\n }\n\n beforeEach(() => {\n vi.resetAllMocks();\n apiMock.sendCommand.mockResolvedValue(\n CommandResultFactory({ data: { challenge: \"challenge\" } }),\n );\n getWeb3ChecksFactoryMock.mockReturnValue({\n run: async () => Promise.resolve({ web3Check: null }),\n });\n\n defaultArgs = {\n contextModule: contextModuleMock,\n subset: { chainId: 1, to: undefined, data: \"0x\", selector: \"0x\" },\n transaction: defaultTransaction,\n options: defaultOptions,\n appConfig: createAppConfig(false),\n derivationPath: \"44'/60'/0'/0/0\",\n };\n });\n\n it(\"should init with a default GetWeb3CheckTaskFactory\", () => {\n // GIVEN\n const task = new BuildTransactionContextTask(apiMock, defaultArgs);\n\n // THEN\n expect(task[\"getWeb3ChecksFactory\"]).toBeDefined();\n expect(\n task[\"getWeb3ChecksFactory\"](apiMock, {\n contextModule: defaultArgs.contextModule,\n derivationPath: defaultArgs.derivationPath,\n subset: defaultArgs.subset,\n transaction: defaultArgs.transaction,\n }),\n ).toBeInstanceOf(GetWeb3CheckTask);\n });\n\n it(\"should build the transaction context without clear sign contexts\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n const clearSignContextsOptional: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n clearSignContextsOptional,\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should build the transaction context with web3checks\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n const clearSignContextsOptional: ClearSignContext[] = [];\n const expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [expectedWeb3Check, ...clearSignContexts],\n clearSignContextsOptional,\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should build the transaction context with web3checks and generic-parser clear sign contexts\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n ];\n const expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [\n clearSignContexts[0],\n clearSignContexts[1],\n clearSignContexts[3],\n expectedWeb3Check,\n ],\n clearSignContextsOptional: [clearSignContexts[2]],\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should build the transaction context with web3checks and generic-parser clear sign contexts in the correct order\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n ];\n const expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [\n clearSignContexts[3], // transaction info\n clearSignContexts[1], // transaction field description\n clearSignContexts[2], // transaction field description\n expectedWeb3Check, // web3 check\n ],\n clearSignContextsOptional: [clearSignContexts[0]], // enum\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should build the transaction context with clear sign contexts\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n const expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should build the transaction context with generic-parser context\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [\n clearSignContexts[0],\n clearSignContexts[1],\n clearSignContexts[3],\n ],\n clearSignContextsOptional: [clearSignContexts[2]],\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should call the web3checks factory with correct parameters\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildTransactionContextTask(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(getWeb3ChecksFactoryMock).toHaveBeenCalledWith(apiMock, {\n contextModule: contextModuleMock,\n derivationPath: \"44'/60'/0'/0/0\",\n subset: defaultArgs.subset,\n transaction: defaultTransaction,\n });\n });\n\n it(\"should call the context module with the correct parameters\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.FLEX,\n challenge: \"challenge\",\n domain: \"domain-name.eth\",\n ...defaultArgs.subset,\n });\n });\n\n it(\"should call the context module without challenge for Nano S\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.NANO_S,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.NANO_S,\n domain: \"domain-name.eth\",\n ...defaultArgs.subset,\n });\n });\n\n it(\"should call the context module without context on error\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ error: new UnknownDeviceExchangeError() }),\n );\n\n // WHEN\n await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.FLEX,\n challenge: undefined,\n domain: \"domain-name.eth\",\n ...defaultArgs.subset,\n });\n });\n\n it(\"should exclude error contexts from the result\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result on old apps\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"transaction_info\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"transaction_field\",\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"enum\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result if no transaction_info was found\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"transaction_field\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"enum\",\n id: 1,\n value: 2,\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.14.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude legacy contexts from the result for generic-parser transactions\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-5\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [clearSignContexts[4]],\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should exclude generic-parser contexts with a nano s device\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.14.0\" },\n deviceModelId: DeviceModelId.NANO_S,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts with an old app version\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts with a non ready device\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.NOT_CONNECTED,\n deviceModelId: DeviceModelId.FLEX,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should return no clear sign context if the transaction info certificate is missing\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.17.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n});\n"],
5
- "mappings": "aAAA,IAAAA,EAKO,oCACPC,EAOO,2CACPC,EAA4B,kBAG5BC,EAAiC,uCACjCC,EAAgD,6EAEhDC,EAGO,yCACPC,EAAiC,8BAEjC,SAAS,8BAA+B,IAAM,CAC5C,MAAMC,EAAoB,CACxB,WAAY,GAAG,GAAG,EAClB,YAAa,GAAG,GAAG,EACnB,oBAAqB,GAAG,GAAG,EAC3B,cAAe,GAAG,GAAG,EACrB,iBAAkB,GAAG,GAAG,CAC1B,EACMC,EAAiB,CACrB,OAAQ,iBACV,EACMC,KAAiC,sBACrC,cAAY,KAAK,CACf,QAAS,GACT,MAAO,EACP,KAAM,IACR,CAAC,EAAE,kBACL,EACMC,EAAqC,CACzC,eAAgB,EAChB,QAAS,IAAI,WAAW,CAAC,EAAM,EAAM,CAAI,CAAC,CAC5C,EAEA,IAAIC,EACJ,MAAMC,KAAU,mCAAgC,EAC1CC,EAA2B,GAAG,GAAG,EAEvC,SAASC,EACPC,EAC0B,CAC1B,MAAO,CACL,oBAAqB,GACrB,kBAAAA,EACA,gBAAiB,GACjB,QAAS,QACX,CACF,CAEA,WAAW,IAAM,CACf,GAAG,cAAc,EACjBH,EAAQ,YAAY,qBAClB,wBAAqB,CAAE,KAAM,CAAE,UAAW,WAAY,CAAE,CAAC,CAC3D,EACAC,EAAyB,gBAAgB,CACvC,IAAK,SAAY,QAAQ,QAAQ,CAAE,UAAW,IAAK,CAAC,CACtD,CAAC,EAEDF,EAAc,CACZ,cAAeJ,EACf,OAAQ,CAAE,QAAS,EAAG,GAAI,OAAW,KAAM,KAAM,SAAU,IAAK,EAChE,YAAaE,EACb,QAASD,EACT,UAA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S,WACX,EACA,CACE,KAAM,uBAAqB,iBAC3B,QAAS,YACT,YAAaP,CACf,EACA,CACE,KAAM,uBAAqB,8BAC3B,QAAS,WACX,EACA,CACE,KAAM,uBAAqB,KAC3B,QAAS,YACT,GAAI,EACJ,MAAO,EACP,YAAaA,CACf,CACF,EACAH,EAAkB,YAAY,sBAAsBU,CAAiB,EACrEL,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkB,yBAAuB,UACzC,aAAc,eAAa,cAC3B,cAAe,gBAAc,IAC/B,CAAC,EAGD,MAAMO,EAAS,MAAM,IAAI,8BACvBP,EACAD,EACAE,CACF,EAAE,IAAI,EAGN,OAAOM,CAAM,EAAE,QAAQ,CACrB,kBAAmB,CAACF,EAAkB,CAAC,CAAC,EACxC,0BAA2B,CAAC,EAC5B,iBAAkB,mBAAiB,KACrC,CAAC,CACH,CAAC,EAED,GAAG,qFAAsF,SAAY,CAEnG,MAAMA,EAAwC,CAC5C,CACE,KAAM,uBAAqB,iBAC3B,QAAS,WACX,EACA,CACE,KAAM,uBAAqB,8BAC3B,QAAS,WACX,EACA,CACE,KAAM,uBAAqB,KAC3B,QAAS,YACT,GAAI,EACJ,MAAO,CACT,CACF,EACAV,EAAkB,YAAY,sBAAsBU,CAAiB,EACrEL,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkB,yBAAuB,0BACzC,aAAc,eAAa,UAC3B,cAAe,CAAC,EAChB,WAAY,CAAE,KAAM,WAAY,QAAS,QAAS,EAClD,cAAe,gBAAc,KAC7B,0BAA2B,EAC7B,CAAC,EAGD,MAAMO,EAAS,MAAM,IAAI,8BACvBP,EACAD,EACAE,CACF,EAAE,IAAI,EAGN,OAAOM,CAAM,EAAE,QAAQ,CACrB,kBAAmB,CAAC,EACpB,0BAA2B,CAAC,EAC5B,iBAAkB,mBAAiB,KACrC,CAAC,CACH,CAAC,CACH,CAAC",
4
+ "sourcesContent": ["import {\n type ClearSignContext,\n type ClearSignContextSuccess,\n ClearSignContextType,\n type PkiCertificate,\n} from \"@ledgerhq/context-module\";\nimport {\n CommandResultFactory,\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n hexaStringToBuffer,\n UnknownDeviceExchangeError,\n} from \"@ledgerhq/device-management-kit\";\nimport { Transaction } from \"ethers\";\n\nimport type { GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\nimport { ClearSigningType } from \"@api/model/ClearSigningType\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\n\nimport {\n BuildTransactionContextTask,\n type BuildTransactionContextTaskArgs,\n} from \"./BuildTransactionContextTask\";\nimport { GetWeb3CheckTask } from \"./GetWeb3CheckTask\";\n\ndescribe(\"BuildTransactionContextTask\", () => {\n const contextModuleMock = {\n getContext: vi.fn(),\n getContexts: vi.fn(),\n getTypedDataFilters: vi.fn(),\n getWeb3Checks: vi.fn(),\n getSolanaContext: vi.fn(),\n };\n const defaultOptions = {\n domain: \"domain-name.eth\",\n };\n const defaultTransaction: Uint8Array = hexaStringToBuffer(\n Transaction.from({\n chainId: 1n,\n nonce: 0,\n data: \"0x\",\n }).unsignedSerialized,\n )!;\n const defaultCertificate: PkiCertificate = {\n keyUsageNumber: 1,\n payload: new Uint8Array([0x01, 0x02, 0x03]),\n };\n\n let defaultArgs: BuildTransactionContextTaskArgs;\n const apiMock = makeDeviceActionInternalApiMock();\n const getWeb3ChecksFactoryMock = vi.fn();\n\n function createAppConfig(\n web3ChecksEnabled: boolean,\n ): GetConfigCommandResponse {\n return {\n blindSigningEnabled: false,\n web3ChecksEnabled,\n web3ChecksOptIn: false,\n version: \"1.13.0\",\n };\n }\n\n beforeEach(() => {\n vi.resetAllMocks();\n apiMock.sendCommand.mockResolvedValue(\n CommandResultFactory({ data: { challenge: \"challenge\" } }),\n );\n getWeb3ChecksFactoryMock.mockReturnValue({\n run: async () => Promise.resolve({ web3Check: null }),\n });\n\n defaultArgs = {\n contextModule: contextModuleMock,\n subset: { chainId: 1, to: undefined, data: \"0x\", selector: \"0x\" },\n transaction: defaultTransaction,\n options: defaultOptions,\n appConfig: createAppConfig(false),\n derivationPath: \"44'/60'/0'/0/0\",\n };\n });\n\n it(\"should init with a default GetWeb3CheckTaskFactory\", () => {\n // GIVEN\n const task = new BuildTransactionContextTask(apiMock, defaultArgs);\n\n // THEN\n expect(task[\"getWeb3ChecksFactory\"]).toBeDefined();\n expect(\n task[\"getWeb3ChecksFactory\"](apiMock, {\n contextModule: defaultArgs.contextModule,\n derivationPath: defaultArgs.derivationPath,\n subset: defaultArgs.subset,\n transaction: defaultArgs.transaction,\n }),\n ).toBeInstanceOf(GetWeb3CheckTask);\n });\n\n it(\"should build the transaction context without clear sign contexts\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n const clearSignContextsOptional: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n clearSignContextsOptional,\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should build the transaction context with web3checks\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n const clearSignContextsOptional: ClearSignContext[] = [];\n const expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [expectedWeb3Check, ...clearSignContexts],\n clearSignContextsOptional,\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should build the transaction context with web3checks and generic-parser clear sign contexts\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n ];\n const expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [\n clearSignContexts[0],\n clearSignContexts[1],\n clearSignContexts[3],\n expectedWeb3Check,\n ],\n clearSignContextsOptional: [clearSignContexts[2]],\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should build the transaction context with web3checks and generic-parser clear sign contexts in the correct order\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n ];\n const expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [\n clearSignContexts[3], // transaction info\n clearSignContexts[1], // transaction field description\n clearSignContexts[2], // transaction field description\n expectedWeb3Check, // web3 check\n ],\n clearSignContextsOptional: [clearSignContexts[0]], // enum\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should build the transaction context with clear sign contexts\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n const expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should build the transaction context with generic-parser context\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [\n clearSignContexts[0],\n clearSignContexts[1],\n clearSignContexts[3],\n ],\n clearSignContextsOptional: [clearSignContexts[2]],\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should build the transaction context with proxy delegate call context\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.PROXY_DELEGATE_CALL,\n payload: \"payload-2\",\n },\n ];\n const clearSignContextsOptional: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[0]],\n clearSignContextsOptional,\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should call the web3checks factory with correct parameters\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildTransactionContextTask(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(getWeb3ChecksFactoryMock).toHaveBeenCalledWith(apiMock, {\n contextModule: contextModuleMock,\n derivationPath: \"44'/60'/0'/0/0\",\n subset: defaultArgs.subset,\n transaction: defaultTransaction,\n });\n });\n\n it(\"should call the context module with the correct parameters\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.FLEX,\n challenge: \"challenge\",\n domain: \"domain-name.eth\",\n ...defaultArgs.subset,\n });\n });\n\n it(\"should call the context module without challenge for Nano S\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.NANO_S,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.NANO_S,\n domain: \"domain-name.eth\",\n ...defaultArgs.subset,\n });\n });\n\n it(\"should call the context module without context on error\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ error: new UnknownDeviceExchangeError() }),\n );\n\n // WHEN\n await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.FLEX,\n challenge: undefined,\n domain: \"domain-name.eth\",\n ...defaultArgs.subset,\n });\n });\n\n it(\"should exclude error contexts from the result\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result on old apps\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"transaction_info\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"transaction_field\",\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"enum\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result if no transaction_info was found\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"transaction_field\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"enum\",\n id: 1,\n value: 2,\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.14.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude legacy contexts from the result for generic-parser transactions\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-5\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [clearSignContexts[4]],\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should exclude generic-parser contexts with a nano s device\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.14.0\" },\n deviceModelId: DeviceModelId.NANO_S,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts with an old app version\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts with a non ready device\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.NOT_CONNECTED,\n deviceModelId: DeviceModelId.FLEX,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should return no clear sign context if the transaction info certificate is missing\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.17.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n});\n"],
5
+ "mappings": "aAAA,IAAAA,EAKO,oCACPC,EAOO,2CACPC,EAA4B,kBAG5BC,EAAiC,uCACjCC,EAAgD,6EAEhDC,EAGO,yCACPC,EAAiC,8BAEjC,SAAS,8BAA+B,IAAM,CAC5C,MAAMC,EAAoB,CACxB,WAAY,GAAG,GAAG,EAClB,YAAa,GAAG,GAAG,EACnB,oBAAqB,GAAG,GAAG,EAC3B,cAAe,GAAG,GAAG,EACrB,iBAAkB,GAAG,GAAG,CAC1B,EACMC,EAAiB,CACrB,OAAQ,iBACV,EACMC,KAAiC,sBACrC,cAAY,KAAK,CACf,QAAS,GACT,MAAO,EACP,KAAM,IACR,CAAC,EAAE,kBACL,EACMC,EAAqC,CACzC,eAAgB,EAChB,QAAS,IAAI,WAAW,CAAC,EAAM,EAAM,CAAI,CAAC,CAC5C,EAEA,IAAIC,EACJ,MAAMC,KAAU,mCAAgC,EAC1CC,EAA2B,GA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P,YAAaA,CACf,CACF,EACAH,EAAkB,YAAY,sBAAsBU,CAAiB,EACrEL,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkB,yBAAuB,UACzC,aAAc,eAAa,cAC3B,cAAe,gBAAc,IAC/B,CAAC,EAGD,MAAMO,EAAS,MAAM,IAAI,8BACvBP,EACAD,EACAE,CACF,EAAE,IAAI,EAGN,OAAOM,CAAM,EAAE,QAAQ,CACrB,kBAAmB,CAACF,EAAkB,CAAC,CAAC,EACxC,0BAA2B,CAAC,EAC5B,iBAAkB,mBAAiB,KACrC,CAAC,CACH,CAAC,EAED,GAAG,qFAAsF,SAAY,CAEnG,MAAMA,EAAwC,CAC5C,CACE,KAAM,uBAAqB,iBAC3B,QAAS,WACX,EACA,CACE,KAAM,uBAAqB,8BAC3B,QAAS,WACX,EACA,CACE,KAAM,uBAAqB,KAC3B,QAAS,YACT,GAAI,EACJ,MAAO,CACT,CACF,EACAV,EAAkB,YAAY,sBAAsBU,CAAiB,EACrEL,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkB,yBAAuB,0BACzC,aAAc,eAAa,UAC3B,cAAe,CAAC,EAChB,WAAY,CAAE,KAAM,WAAY,QAAS,QAAS,EAClD,cAAe,gBAAc,KAC7B,0BAA2B,EAC7B,CAAC,EAGD,MAAMO,EAAS,MAAM,IAAI,8BACvBP,EACAD,EACAE,CACF,EAAE,IAAI,EAGN,OAAOM,CAAM,EAAE,QAAQ,CACrB,kBAAmB,CAAC,EACpB,0BAA2B,CAAC,EAC5B,iBAAkB,mBAAiB,KACrC,CAAC,CACH,CAAC,CACH,CAAC",
6
6
  "names": ["import_context_module", "import_device_management_kit", "import_ethers", "import_ClearSigningType", "import_makeInternalApi", "import_BuildTransactionContextTask", "import_GetWeb3CheckTask", "contextModuleMock", "defaultOptions", "defaultTransaction", "defaultCertificate", "defaultArgs", "apiMock", "getWeb3ChecksFactoryMock", "createAppConfig", "web3ChecksEnabled", "task", "clearSignContexts", "clearSignContextsOptional", "result", "expectedWeb3Check"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var u=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var x=(s,t)=>{for(var a in t)u(s,a,{get:t[a],enumerable:!0})},g=(s,t,a,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of E(t))!S.call(s,n)&&n!==a&&u(s,n,{get:()=>t[n],enumerable:!(e=v(t,n))||e.enumerable});return s};var A=s=>g(u({},"__esModule",{value:!0}),s);var N={};x(N,{ProvideTransactionContextTask:()=>R});module.exports=A(N);var r=require("@ledgerhq/context-module"),o=require("@ledgerhq/device-management-kit"),C=require("@ledgerhq/signer-utils"),m=require("purify-ts"),h=require("../../app-binder/command/ProvideEnumCommand"),k=require("../../app-binder/command/ProvideNFTInformationCommand"),p=require("../../app-binder/command/ProvideTokenInformationCommand"),l=require("../../app-binder/command/ProvideTransactionFieldDescriptionCommand"),T=require("../../app-binder/command/ProvideTransactionInformationCommand"),y=require("../../app-binder/command/ProvideTrustedNameCommand"),I=require("../../app-binder/command/ProvideWeb3CheckCommand"),f=require("../../app-binder/command/SetExternalPluginCommand"),F=require("../../app-binder/command/SetPluginCommand"),_=require("../../app-binder/command/StoreTransactionCommand"),P=require("./SendCommandInChunksTask"),w=require("./SendPayloadInChunksTask");class R{constructor(t,a,e=(i,c)=>new w.SendPayloadInChunksTask(i,c),n=(i,c)=>new P.SendCommandInChunksTask(i,c)){this._api=t;this._args=a;this._sendPayloadInChunksTaskFactory=e;this._sendCommandInChunksTaskFactory=n}async run(){for(const a of this._args.subcontextsCallbacks){const e=await a();if(e.type===r.ClearSignContextType.ERROR)continue;const n=await this.provideContext(e);if(!(0,o.isSuccessCommandResult)(n))return(0,m.Left)(n)}const t=await this.provideContext(this._args.context);return(0,o.isSuccessCommandResult)(t)?(0,m.Right)(void 0):(0,m.Left)(t)}async provideContext({type:t,payload:a,certificate:e}){switch(e&&await this._api.sendCommand(new o.LoadCertificateCommand({keyUsage:e.keyUsageNumber,certificate:e.payload})),t){case r.ClearSignContextType.PLUGIN:return await this._api.sendCommand(new F.SetPluginCommand({payload:a}));case r.ClearSignContextType.EXTERNAL_PLUGIN:return await this._api.sendCommand(new f.SetExternalPluginCommand({payload:a}));case r.ClearSignContextType.NFT:return await this._api.sendCommand(new k.ProvideNFTInformationCommand({payload:a}));case r.ClearSignContextType.TOKEN:return await this._api.sendCommand(new p.ProvideTokenInformationCommand({payload:a}));case r.ClearSignContextType.TRANSACTION_INFO:{const n=C.DerivationPathUtils.splitPath(this._args.derivationPath),i=new o.ByteArrayBuilder;return i.add8BitUIntToData(n.length),n.forEach(d=>{i.add32BitUIntToData(d)}),i.addBufferToData(this._args.serializedTransaction),await this._sendCommandInChunksTaskFactory(this._api,{data:i.build(),commandFactory:d=>new _.StoreTransactionCommand({serializedTransaction:d.chunkedData,isFirstChunk:d.isFirstChunk})}).run(),await this._sendPayloadInChunksTaskFactory(this._api,{payload:this._args.context.payload,commandFactory:d=>new T.ProvideTransactionInformationCommand({data:d.chunkedData,isFirstChunk:d.isFirstChunk})}).run()}case r.ClearSignContextType.TRUSTED_NAME:return this._sendPayloadInChunksTaskFactory(this._api,{payload:a,commandFactory:n=>new y.ProvideTrustedNameCommand({data:n.chunkedData,isFirstChunk:n.isFirstChunk})}).run();case r.ClearSignContextType.ENUM:return this._sendPayloadInChunksTaskFactory(this._api,{payload:a,commandFactory:n=>new h.ProvideEnumCommand({data:n.chunkedData,isFirstChunk:n.isFirstChunk})}).run();case r.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:return this._sendPayloadInChunksTaskFactory(this._api,{payload:a,commandFactory:n=>new l.ProvideTransactionFieldDescriptionCommand({data:n.chunkedData,isFirstChunk:n.isFirstChunk})}).run();case r.ClearSignContextType.WEB3_CHECK:return this._sendPayloadInChunksTaskFactory(this._api,{payload:a,commandFactory:n=>new I.ProvideWeb3CheckCommand({payload:n.chunkedData,isFirstChunk:n.isFirstChunk})}).run();default:{const n=t;return(0,o.CommandResultFactory)({error:new o.InvalidStatusWordError(`The context type [${n}] is not covered`)})}}}}0&&(module.exports={ProvideTransactionContextTask});
1
+ "use strict";var u=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var A=(s,a)=>{for(var t in a)u(s,t,{get:a[t],enumerable:!0})},g=(s,a,t,e)=>{if(a&&typeof a=="object"||typeof a=="function")for(let n of S(a))!x.call(s,n)&&n!==t&&u(s,n,{get:()=>a[n],enumerable:!(e=v(a,n))||e.enumerable});return s};var R=s=>g(u({},"__esModule",{value:!0}),s);var N={};A(N,{ProvideTransactionContextTask:()=>D});module.exports=R(N);var r=require("@ledgerhq/context-module"),o=require("@ledgerhq/device-management-kit"),C=require("@ledgerhq/signer-utils"),m=require("purify-ts"),h=require("../../app-binder/command/ProvideEnumCommand"),k=require("../../app-binder/command/ProvideNFTInformationCommand"),p=require("../../app-binder/command/ProvideProxyInfoCommand"),T=require("../../app-binder/command/ProvideTokenInformationCommand"),l=require("../../app-binder/command/ProvideTransactionFieldDescriptionCommand"),y=require("../../app-binder/command/ProvideTransactionInformationCommand"),F=require("../../app-binder/command/ProvideTrustedNameCommand"),I=require("../../app-binder/command/ProvideWeb3CheckCommand"),_=require("../../app-binder/command/SetExternalPluginCommand"),f=require("../../app-binder/command/SetPluginCommand"),P=require("../../app-binder/command/StoreTransactionCommand"),w=require("./SendCommandInChunksTask"),E=require("./SendPayloadInChunksTask");class D{constructor(a,t,e=(i,c)=>new E.SendPayloadInChunksTask(i,c),n=(i,c)=>new w.SendCommandInChunksTask(i,c)){this._api=a;this._args=t;this._sendPayloadInChunksTaskFactory=e;this._sendCommandInChunksTaskFactory=n}async run(){for(const t of this._args.subcontextsCallbacks){const e=await t();if(e.type===r.ClearSignContextType.ERROR)continue;const n=await this.provideContext(e);if(!(0,o.isSuccessCommandResult)(n))return(0,m.Left)(n)}const a=await this.provideContext(this._args.context);return(0,o.isSuccessCommandResult)(a)?(0,m.Right)(void 0):(0,m.Left)(a)}async provideContext({type:a,payload:t,certificate:e}){switch(e&&await this._api.sendCommand(new o.LoadCertificateCommand({keyUsage:e.keyUsageNumber,certificate:e.payload})),a){case r.ClearSignContextType.PLUGIN:return await this._api.sendCommand(new f.SetPluginCommand({payload:t}));case r.ClearSignContextType.EXTERNAL_PLUGIN:return await this._api.sendCommand(new _.SetExternalPluginCommand({payload:t}));case r.ClearSignContextType.NFT:return await this._api.sendCommand(new k.ProvideNFTInformationCommand({payload:t}));case r.ClearSignContextType.TOKEN:return await this._api.sendCommand(new T.ProvideTokenInformationCommand({payload:t}));case r.ClearSignContextType.TRANSACTION_INFO:{const n=C.DerivationPathUtils.splitPath(this._args.derivationPath),i=new o.ByteArrayBuilder;return i.add8BitUIntToData(n.length),n.forEach(d=>{i.add32BitUIntToData(d)}),i.addBufferToData(this._args.serializedTransaction),await this._sendCommandInChunksTaskFactory(this._api,{data:i.build(),commandFactory:d=>new P.StoreTransactionCommand({serializedTransaction:d.chunkedData,isFirstChunk:d.isFirstChunk})}).run(),await this._sendPayloadInChunksTaskFactory(this._api,{payload:this._args.context.payload,commandFactory:d=>new y.ProvideTransactionInformationCommand({data:d.chunkedData,isFirstChunk:d.isFirstChunk})}).run()}case r.ClearSignContextType.TRUSTED_NAME:return this._sendPayloadInChunksTaskFactory(this._api,{payload:t,commandFactory:n=>new F.ProvideTrustedNameCommand({data:n.chunkedData,isFirstChunk:n.isFirstChunk})}).run();case r.ClearSignContextType.ENUM:return this._sendPayloadInChunksTaskFactory(this._api,{payload:t,commandFactory:n=>new h.ProvideEnumCommand({data:n.chunkedData,isFirstChunk:n.isFirstChunk})}).run();case r.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:return this._sendPayloadInChunksTaskFactory(this._api,{payload:t,commandFactory:n=>new l.ProvideTransactionFieldDescriptionCommand({data:n.chunkedData,isFirstChunk:n.isFirstChunk})}).run();case r.ClearSignContextType.WEB3_CHECK:return this._sendPayloadInChunksTaskFactory(this._api,{payload:t,commandFactory:n=>new I.ProvideWeb3CheckCommand({payload:n.chunkedData,isFirstChunk:n.isFirstChunk})}).run();case r.ClearSignContextType.PROXY_DELEGATE_CALL:return this._sendPayloadInChunksTaskFactory(this._api,{payload:t,commandFactory:n=>new p.ProvideProxyInfoCommand({data:n.chunkedData,isFirstChunk:n.isFirstChunk})}).run();default:{const n=a;return(0,o.CommandResultFactory)({error:new o.InvalidStatusWordError(`The context type [${n}] is not covered`)})}}}}0&&(module.exports={ProvideTransactionContextTask});
2
2
  //# sourceMappingURL=ProvideTransactionContextTask.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/internal/app-binder/task/ProvideTransactionContextTask.ts"],
4
- "sourcesContent": ["import {\n type ClearSignContext,\n type ClearSignContextSuccess,\n ClearSignContextType,\n} from \"@ledgerhq/context-module\";\nimport {\n ByteArrayBuilder,\n type CommandErrorResult,\n type CommandResult,\n CommandResultFactory,\n type InternalApi,\n InvalidStatusWordError,\n isSuccessCommandResult,\n LoadCertificateCommand,\n} from \"@ledgerhq/device-management-kit\";\nimport { DerivationPathUtils } from \"@ledgerhq/signer-utils\";\nimport { type Either, Left, Right } from \"purify-ts\";\n\nimport { ProvideEnumCommand } from \"@internal/app-binder/command/ProvideEnumCommand\";\nimport { ProvideNFTInformationCommand } from \"@internal/app-binder/command/ProvideNFTInformationCommand\";\nimport { ProvideTokenInformationCommand } from \"@internal/app-binder/command/ProvideTokenInformationCommand\";\nimport { ProvideTransactionFieldDescriptionCommand } from \"@internal/app-binder/command/ProvideTransactionFieldDescriptionCommand\";\nimport { ProvideTransactionInformationCommand } from \"@internal/app-binder/command/ProvideTransactionInformationCommand\";\nimport { ProvideTrustedNameCommand } from \"@internal/app-binder/command/ProvideTrustedNameCommand\";\nimport { ProvideWeb3CheckCommand } from \"@internal/app-binder/command/ProvideWeb3CheckCommand\";\nimport { SetExternalPluginCommand } from \"@internal/app-binder/command/SetExternalPluginCommand\";\nimport { SetPluginCommand } from \"@internal/app-binder/command/SetPluginCommand\";\nimport { StoreTransactionCommand } from \"@internal/app-binder/command/StoreTransactionCommand\";\nimport { type EthErrorCodes } from \"@internal/app-binder/command/utils/ethAppErrors\";\n\nimport {\n SendCommandInChunksTask,\n type SendCommandInChunksTaskArgs,\n} from \"./SendCommandInChunksTask\";\nimport {\n SendPayloadInChunksTask,\n type SendPayloadInChunksTaskArgs,\n} from \"./SendPayloadInChunksTask\";\n\nexport type ProvideTransactionContextTaskArgs = {\n /**\n * The clear sign context to provide.\n */\n context: ClearSignContextSuccess;\n /**\n * The subcontexts callbacks to provide.\n */\n subcontextsCallbacks: (() => Promise<ClearSignContext>)[];\n /**\n * The serialized transaction to provide.\n */\n serializedTransaction: Uint8Array;\n /**\n * The derivation path to provide.\n */\n derivationPath: string;\n};\n\n/**\n * This task is responsible for providing the transaction context to the device.\n * It will send the subcontexts callbacks in order and finish with the context.\n */\nexport class ProvideTransactionContextTask {\n constructor(\n private _api: InternalApi,\n private _args: ProvideTransactionContextTaskArgs,\n private _sendPayloadInChunksTaskFactory = (\n api: InternalApi,\n args: SendPayloadInChunksTaskArgs<unknown>,\n ) => new SendPayloadInChunksTask(api, args),\n private _sendCommandInChunksTaskFactory = (\n api: InternalApi,\n args: SendCommandInChunksTaskArgs<unknown>,\n ) => new SendCommandInChunksTask(api, args),\n ) {}\n\n async run(): Promise<Either<CommandErrorResult<EthErrorCodes>, void>> {\n for (const callback of this._args.subcontextsCallbacks) {\n const subcontext = await callback();\n\n if (subcontext.type === ClearSignContextType.ERROR) {\n // silently ignore error subcontexts\n continue;\n }\n\n const res = await this.provideContext(subcontext);\n if (!isSuccessCommandResult(res)) {\n return Left(res);\n }\n }\n\n const res = await this.provideContext(this._args.context);\n if (!isSuccessCommandResult(res)) {\n return Left(res);\n }\n\n return Right(void 0);\n }\n\n /**\n * This method will send the context to the device.\n *\n * @param context The clear sign context to provide.\n * @returns A promise that resolves when the command is sent.\n */\n async provideContext({\n type,\n payload,\n certificate,\n }: ClearSignContextSuccess): Promise<CommandResult<unknown, EthErrorCodes>> {\n // if a certificate is provided, we load it before sending the command\n if (certificate) {\n await this._api.sendCommand(\n new LoadCertificateCommand({\n keyUsage: certificate.keyUsageNumber,\n certificate: certificate.payload,\n }),\n );\n }\n\n switch (type) {\n case ClearSignContextType.PLUGIN: {\n return await this._api.sendCommand(new SetPluginCommand({ payload }));\n }\n case ClearSignContextType.EXTERNAL_PLUGIN: {\n return await this._api.sendCommand(\n new SetExternalPluginCommand({ payload }),\n );\n }\n case ClearSignContextType.NFT: {\n return await this._api.sendCommand(\n new ProvideNFTInformationCommand({ payload }),\n );\n }\n case ClearSignContextType.TOKEN: {\n return await this._api.sendCommand(\n new ProvideTokenInformationCommand({ payload }),\n );\n }\n case ClearSignContextType.TRANSACTION_INFO: {\n const paths = DerivationPathUtils.splitPath(this._args.derivationPath);\n const builder = new ByteArrayBuilder();\n builder.add8BitUIntToData(paths.length);\n paths.forEach((path) => {\n builder.add32BitUIntToData(path);\n });\n builder.addBufferToData(this._args.serializedTransaction);\n await this._sendCommandInChunksTaskFactory(this._api, {\n data: builder.build(),\n commandFactory: (args) =>\n new StoreTransactionCommand({\n serializedTransaction: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n\n const transactionInfoResult =\n await this._sendPayloadInChunksTaskFactory(this._api, {\n payload: this._args.context.payload,\n commandFactory: (args) =>\n new ProvideTransactionInformationCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n\n return transactionInfoResult;\n }\n case ClearSignContextType.TRUSTED_NAME: {\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideTrustedNameCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n }\n case ClearSignContextType.ENUM:\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideEnumCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n case ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideTransactionFieldDescriptionCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n case ClearSignContextType.WEB3_CHECK:\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideWeb3CheckCommand({\n payload: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n default: {\n const uncoveredType: never = type;\n return CommandResultFactory({\n error: new InvalidStatusWordError(\n `The context type [${uncoveredType}] is not covered`,\n ),\n });\n }\n }\n }\n}\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAIO,oCACPC,EASO,2CACPC,EAAoC,kCACpCC,EAAyC,qBAEzCC,EAAmC,2DACnCC,EAA6C,qEAC7CC,EAA+C,uEAC/CC,EAA0D,kFAC1DC,EAAqD,6EACrDC,EAA0C,kEAC1CC,EAAwC,gEACxCC,EAAyC,iEACzCC,EAAiC,yDACjCC,EAAwC,gEAGxCC,EAGO,qCACPC,EAGO,qCAyBA,MAAMjB,CAA8B,CACzC,YACUkB,EACAC,EACAC,EAAkC,CACxCC,EACAC,IACG,IAAI,0BAAwBD,EAAKC,CAAI,EAClCC,EAAkC,CACxCF,EACAC,IACG,IAAI,0BAAwBD,EAAKC,CAAI,EAC1C,CAVQ,UAAAJ,EACA,WAAAC,EACA,qCAAAC,EAIA,qCAAAG,CAIP,CAEH,MAAM,KAAgE,CACpE,UAAWC,KAAY,KAAK,MAAM,qBAAsB,CACtD,MAAMC,EAAa,MAAMD,EAAS,EAElC,GAAIC,EAAW,OAAS,uBAAqB,MAE3C,SAGF,MAAMC,EAAM,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B,CAAC,CACL,CAAC,EAAE,IAAI,EAGL,MAAM,KAAK,gCAAgC,KAAK,KAAM,CACpD,QAAS,KAAK,MAAM,QAAQ,QAC5B,eAAiBA,GACf,IAAI,uCAAqC,CACvC,KAAMA,EAAK,YACX,aAAcA,EAAK,YACrB,CAAC,CACL,CAAC,EAAE,IAAI,CAGX,CACA,KAAK,uBAAqB,aACxB,OAAO,KAAK,gCAAgC,KAAK,KAAM,CACrD,QAAAM,EACA,eAAiBN,GACf,IAAI,4BAA0B,CAC5B,KAAMA,EAAK,YACX,aAAcA,EAAK,YACrB,CAAC,CACL,CAAC,EAAE,IAAI,EAET,KAAK,uBAAqB,KACxB,OAAO,KAAK,gCAAgC,KAAK,KAAM,CACrD,QAAAM,EACA,eAAiBN,GACf,IAAI,qBAAmB,CACrB,KAAMA,EAAK,YACX,aAAcA,EAAK,YACrB,CAAC,CACL,CAAC,EAAE,IAAI,EACT,KAAK,uBAAqB,8BACxB,OAAO,KAAK,gCAAgC,KAAK,KAAM,CACrD,QAAAM,EACA,eAAiBN,GACf,IAAI,4CAA0C,CAC5C,KAAMA,EAAK,YACX,aAAcA,EAAK,YACrB,CAAC,CACL,CAAC,EAAE,IAAI,EACT,KAAK,uBAAqB,WACxB,OAAO,KAAK,gCAAgC,KAAK,KAAM,CACrD,QAAAM,EACA,eAAiBN,GACf,IAAI,0BAAwB,CAC1B,QAASA,EAAK,YACd,aAAcA,EAAK,YACrB,CAAC,CACL,CAAC,EAAE,IAAI,EACT,QAAS,CACP,MAAMW,EAAuBN,EAC7B,SAAO,wBAAqB,CAC1B,MAAO,IAAI,yBACT,qBAAqBM,CAAa,kBACpC,CACF,CAAC,CACH,CACF,CACF,CACF",
6
- "names": ["ProvideTransactionContextTask_exports", "__export", "ProvideTransactionContextTask", "__toCommonJS", "import_context_module", "import_device_management_kit", "import_signer_utils", "import_purify_ts", "import_ProvideEnumCommand", "import_ProvideNFTInformationCommand", "import_ProvideTokenInformationCommand", "import_ProvideTransactionFieldDescriptionCommand", "import_ProvideTransactionInformationCommand", "import_ProvideTrustedNameCommand", "import_ProvideWeb3CheckCommand", "import_SetExternalPluginCommand", "import_SetPluginCommand", "import_StoreTransactionCommand", "import_SendCommandInChunksTask", "import_SendPayloadInChunksTask", "_api", "_args", "_sendPayloadInChunksTaskFactory", "api", "args", "_sendCommandInChunksTaskFactory", "callback", "subcontext", "res", "type", "payload", "certificate", "paths", "builder", "path", "uncoveredType"]
4
+ "sourcesContent": ["import {\n type ClearSignContext,\n type ClearSignContextSuccess,\n ClearSignContextType,\n} from \"@ledgerhq/context-module\";\nimport {\n ByteArrayBuilder,\n type CommandErrorResult,\n type CommandResult,\n CommandResultFactory,\n type InternalApi,\n InvalidStatusWordError,\n isSuccessCommandResult,\n LoadCertificateCommand,\n} from \"@ledgerhq/device-management-kit\";\nimport { DerivationPathUtils } from \"@ledgerhq/signer-utils\";\nimport { type Either, Left, Right } from \"purify-ts\";\n\nimport { ProvideEnumCommand } from \"@internal/app-binder/command/ProvideEnumCommand\";\nimport { ProvideNFTInformationCommand } from \"@internal/app-binder/command/ProvideNFTInformationCommand\";\nimport { ProvideProxyInfoCommand } from \"@internal/app-binder/command/ProvideProxyInfoCommand\";\nimport { ProvideTokenInformationCommand } from \"@internal/app-binder/command/ProvideTokenInformationCommand\";\nimport { ProvideTransactionFieldDescriptionCommand } from \"@internal/app-binder/command/ProvideTransactionFieldDescriptionCommand\";\nimport { ProvideTransactionInformationCommand } from \"@internal/app-binder/command/ProvideTransactionInformationCommand\";\nimport { ProvideTrustedNameCommand } from \"@internal/app-binder/command/ProvideTrustedNameCommand\";\nimport { ProvideWeb3CheckCommand } from \"@internal/app-binder/command/ProvideWeb3CheckCommand\";\nimport { SetExternalPluginCommand } from \"@internal/app-binder/command/SetExternalPluginCommand\";\nimport { SetPluginCommand } from \"@internal/app-binder/command/SetPluginCommand\";\nimport { StoreTransactionCommand } from \"@internal/app-binder/command/StoreTransactionCommand\";\nimport { type EthErrorCodes } from \"@internal/app-binder/command/utils/ethAppErrors\";\n\nimport {\n SendCommandInChunksTask,\n type SendCommandInChunksTaskArgs,\n} from \"./SendCommandInChunksTask\";\nimport {\n SendPayloadInChunksTask,\n type SendPayloadInChunksTaskArgs,\n} from \"./SendPayloadInChunksTask\";\n\nexport type ProvideTransactionContextTaskArgs = {\n /**\n * The clear sign context to provide.\n */\n context: ClearSignContextSuccess;\n /**\n * The subcontexts callbacks to provide.\n */\n subcontextsCallbacks: (() => Promise<ClearSignContext>)[];\n /**\n * The serialized transaction to provide.\n */\n serializedTransaction: Uint8Array;\n /**\n * The derivation path to provide.\n */\n derivationPath: string;\n};\n\n/**\n * This task is responsible for providing the transaction context to the device.\n * It will send the subcontexts callbacks in order and finish with the context.\n */\nexport class ProvideTransactionContextTask {\n constructor(\n private _api: InternalApi,\n private _args: ProvideTransactionContextTaskArgs,\n private _sendPayloadInChunksTaskFactory = (\n api: InternalApi,\n args: SendPayloadInChunksTaskArgs<unknown>,\n ) => new SendPayloadInChunksTask(api, args),\n private _sendCommandInChunksTaskFactory = (\n api: InternalApi,\n args: SendCommandInChunksTaskArgs<unknown>,\n ) => new SendCommandInChunksTask(api, args),\n ) {}\n\n async run(): Promise<Either<CommandErrorResult<EthErrorCodes>, void>> {\n for (const callback of this._args.subcontextsCallbacks) {\n const subcontext = await callback();\n\n if (subcontext.type === ClearSignContextType.ERROR) {\n // silently ignore error subcontexts\n continue;\n }\n\n const res = await this.provideContext(subcontext);\n if (!isSuccessCommandResult(res)) {\n return Left(res);\n }\n }\n\n const res = await this.provideContext(this._args.context);\n if (!isSuccessCommandResult(res)) {\n return Left(res);\n }\n\n return Right(void 0);\n }\n\n /**\n * This method will send the context to the device.\n *\n * @param context The clear sign context to provide.\n * @returns A promise that resolves when the command is sent.\n */\n async provideContext({\n type,\n payload,\n certificate,\n }: ClearSignContextSuccess): Promise<CommandResult<unknown, EthErrorCodes>> {\n // if a certificate is provided, we load it before sending the command\n if (certificate) {\n await this._api.sendCommand(\n new LoadCertificateCommand({\n keyUsage: certificate.keyUsageNumber,\n certificate: certificate.payload,\n }),\n );\n }\n\n switch (type) {\n case ClearSignContextType.PLUGIN: {\n return await this._api.sendCommand(new SetPluginCommand({ payload }));\n }\n case ClearSignContextType.EXTERNAL_PLUGIN: {\n return await this._api.sendCommand(\n new SetExternalPluginCommand({ payload }),\n );\n }\n case ClearSignContextType.NFT: {\n return await this._api.sendCommand(\n new ProvideNFTInformationCommand({ payload }),\n );\n }\n case ClearSignContextType.TOKEN: {\n return await this._api.sendCommand(\n new ProvideTokenInformationCommand({ payload }),\n );\n }\n case ClearSignContextType.TRANSACTION_INFO: {\n const paths = DerivationPathUtils.splitPath(this._args.derivationPath);\n const builder = new ByteArrayBuilder();\n builder.add8BitUIntToData(paths.length);\n paths.forEach((path) => {\n builder.add32BitUIntToData(path);\n });\n builder.addBufferToData(this._args.serializedTransaction);\n await this._sendCommandInChunksTaskFactory(this._api, {\n data: builder.build(),\n commandFactory: (args) =>\n new StoreTransactionCommand({\n serializedTransaction: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n\n const transactionInfoResult =\n await this._sendPayloadInChunksTaskFactory(this._api, {\n payload: this._args.context.payload,\n commandFactory: (args) =>\n new ProvideTransactionInformationCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n\n return transactionInfoResult;\n }\n case ClearSignContextType.TRUSTED_NAME: {\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideTrustedNameCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n }\n case ClearSignContextType.ENUM:\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideEnumCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n case ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideTransactionFieldDescriptionCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n case ClearSignContextType.WEB3_CHECK:\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideWeb3CheckCommand({\n payload: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n case ClearSignContextType.PROXY_DELEGATE_CALL:\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideProxyInfoCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n default: {\n const uncoveredType: never = type;\n return CommandResultFactory({\n error: new InvalidStatusWordError(\n `The context type [${uncoveredType}] is not covered`,\n ),\n });\n }\n }\n }\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAIO,oCACPC,EASO,2CACPC,EAAoC,kCACpCC,EAAyC,qBAEzCC,EAAmC,2DACnCC,EAA6C,qEAC7CC,EAAwC,gEACxCC,EAA+C,uEAC/CC,EAA0D,kFAC1DC,EAAqD,6EACrDC,EAA0C,kEAC1CC,EAAwC,gEACxCC,EAAyC,iEACzCC,EAAiC,yDACjCC,EAAwC,gEAGxCC,EAGO,qCACPC,EAGO,qCAyBA,MAAMlB,CAA8B,CACzC,YACUmB,EACAC,EACAC,EAAkC,CACxCC,EACAC,IACG,IAAI,0BAAwBD,EAAKC,CAAI,EAClCC,EAAkC,CACxCF,EACAC,IACG,IAAI,0BAAwBD,EAAKC,CAAI,EAC1C,CAVQ,UAAAJ,EACA,WAAAC,EACA,qCAAAC,EAIA,qCAAAG,CAIP,CAEH,MAAM,KAAgE,CACpE,UAAWC,KAAY,KAAK,MAAM,qBAAsB,CACtD,MAAMC,EAAa,MAAMD,EAAS,EAElC,GAAIC,EAAW,OAAS,uBAAqB,MAE3C,S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,CACF,CACF,CACF",
6
+ "names": ["ProvideTransactionContextTask_exports", "__export", "ProvideTransactionContextTask", "__toCommonJS", "import_context_module", "import_device_management_kit", "import_signer_utils", "import_purify_ts", "import_ProvideEnumCommand", "import_ProvideNFTInformationCommand", "import_ProvideProxyInfoCommand", "import_ProvideTokenInformationCommand", "import_ProvideTransactionFieldDescriptionCommand", "import_ProvideTransactionInformationCommand", "import_ProvideTrustedNameCommand", "import_ProvideWeb3CheckCommand", "import_SetExternalPluginCommand", "import_SetPluginCommand", "import_StoreTransactionCommand", "import_SendCommandInChunksTask", "import_SendPayloadInChunksTask", "_api", "_args", "_sendPayloadInChunksTaskFactory", "api", "args", "_sendCommandInChunksTaskFactory", "callback", "subcontext", "res", "type", "payload", "certificate", "paths", "builder", "path", "uncoveredType"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var t=require("@ledgerhq/context-module"),y=require("@ledgerhq/device-management-kit"),l=require("purify-ts"),P=require("../../app-binder/command/ProvideEnumCommand"),h=require("../../app-binder/command/ProvideNFTInformationCommand"),T=require("../../app-binder/command/ProvideTokenInformationCommand"),f=require("../../app-binder/command/ProvideTransactionFieldDescriptionCommand"),E=require("../../app-binder/command/ProvideTransactionInformationCommand"),F=require("../../app-binder/command/ProvideTrustedNameCommand"),N=require("../../app-binder/command/ProvideWeb3CheckCommand"),b=require("../../app-binder/command/SetExternalPluginCommand"),g=require("../../app-binder/command/SetPluginCommand"),A=require("../../app-binder/command/StoreTransactionCommand"),B=require("../../app-binder/device-action/__test-utils__/makeInternalApi"),i=require("./ProvideTransactionContextTask"),R=require("./SendCommandInChunksTask"),U=require("./SendPayloadInChunksTask");describe("ProvideTransactionContextTask",()=>{const e=(0,B.makeDeviceActionInternalApiMock)(),c=(0,y.CommandResultFactory)({data:void 0}),v=(0,y.CommandResultFactory)({data:void 0,error:{}});beforeEach(()=>{vi.resetAllMocks()}),describe("run",()=>{const n=vi.fn(),C=vi.fn(),r=vi.fn(),d=vi.fn();beforeEach(()=>{vi.clearAllMocks(),r.mockImplementation((a,o)=>({run:()=>C(a,o)})),d.mockImplementation((a,o)=>({run:()=>n(a,o)}))}),describe("with no subcontexts",()=>{it("should provide the transaction context for a TRANSACTION_INFO context",async()=>{const a={context:{type:t.ClearSignContextType.TRANSACTION_INFO,payload:"0x00",certificate:{keyUsageNumber:1,payload:new Uint8Array([1,2,3])}},subcontextsCallbacks:[],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"};C.mockResolvedValue(c),n.mockResolvedValue(c),e.sendCommand.mockResolvedValue(c);const s=await new i.ProvideTransactionContextTask(e,a,d,r).run();expect(s).toEqual((0,l.Right)(void 0)),expect(C).toHaveBeenCalledTimes(1),expect(r).toHaveBeenCalledWith(e,{data:new Uint8Array([5,128,0,0,44,128,0,0,60,128,0,0,0,0,0,0,0,0,0,0,0]),commandFactory:expect.any(Function)});const m=r.mock.calls[0][1].commandFactory,p={chunkedData:new Uint8Array([1,2,3,4]),isFirstChunk:!0},x=m(p);expect(x).toBeInstanceOf(A.StoreTransactionCommand),expect(e.sendCommand).toHaveBeenCalledTimes(1),expect(e.sendCommand).toHaveBeenCalledWith(expect.any(y.LoadCertificateCommand)),expect(n).toHaveBeenCalledTimes(1),expect(n).toHaveBeenCalledWith(e,{payload:"0x00",commandFactory:expect.any(Function)});const k=n.mock.calls[0][1].commandFactory,I=k(p);expect(I).toBeInstanceOf(E.ProvideTransactionInformationCommand)}),it("should provide the transaction context for a TRANSACTION_INFO context without certificate",async()=>{const a={context:{type:t.ClearSignContextType.TRANSACTION_INFO,payload:"0x00"},subcontextsCallbacks:[],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"};C.mockResolvedValue(c),n.mockResolvedValue(c),e.sendCommand.mockResolvedValue(c);const s=await new i.ProvideTransactionContextTask(e,a,d,r).run();expect(s).toEqual((0,l.Right)(void 0)),expect(C).toHaveBeenCalledTimes(1),expect(r).toHaveBeenCalledWith(e,{data:new Uint8Array([5,128,0,0,44,128,0,0,60,128,0,0,0,0,0,0,0,0,0,0,0]),commandFactory:expect.any(Function)});const m=r.mock.calls[0][1].commandFactory,p={chunkedData:new Uint8Array([1,2,3,4]),isFirstChunk:!0},x=m(p);expect(x).toBeInstanceOf(A.StoreTransactionCommand),expect(e.sendCommand).toHaveBeenCalledTimes(0),expect(n).toHaveBeenCalledTimes(1),expect(n).toHaveBeenCalledWith(e,{payload:"0x00",commandFactory:expect.any(Function)});const k=n.mock.calls[0][1].commandFactory,I=k(p);expect(I).toBeInstanceOf(E.ProvideTransactionInformationCommand)}),it.each([[t.ClearSignContextType.PLUGIN,g.SetPluginCommand],[t.ClearSignContextType.EXTERNAL_PLUGIN,b.SetExternalPluginCommand],[t.ClearSignContextType.NFT,h.ProvideNFTInformationCommand],[t.ClearSignContextType.TOKEN,T.ProvideTokenInformationCommand]])("should provide the transaction context by calling sendCommand for a %s context",async(a,o)=>{const s={context:{type:a,payload:"payload"},subcontextsCallbacks:[],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"};e.sendCommand.mockResolvedValue(c);const m=await new i.ProvideTransactionContextTask(e,s,d,r).run();expect(m).toEqual((0,l.Right)(void 0)),expect(e.sendCommand).toHaveBeenCalledTimes(1),expect(e.sendCommand).toHaveBeenCalledWith(expect.any(o))}),it.each([[t.ClearSignContextType.ENUM,P.ProvideEnumCommand],[t.ClearSignContextType.TRUSTED_NAME,F.ProvideTrustedNameCommand],[t.ClearSignContextType.WEB3_CHECK,N.ProvideWeb3CheckCommand],[t.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,f.ProvideTransactionFieldDescriptionCommand]])("should provide the transaction context by calling sendPayloadInChunksTask for a %s context",async(a,o)=>{const s={context:{type:a,payload:"payload"},subcontextsCallbacks:[],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"};n.mockResolvedValue(c);const m=await new i.ProvideTransactionContextTask(e,s,d,r).run();expect(m).toEqual((0,l.Right)(void 0)),expect(n).toHaveBeenCalledTimes(1),expect(n).toHaveBeenCalledWith(e,{payload:"payload",commandFactory:expect.any(Function)});const x=d.mock.calls[0][1].commandFactory,w={chunkedData:new Uint8Array([1,2,3]),isFirstChunk:!0},k=x(w);expect(k).toBeInstanceOf(o)}),it("should skip the subcontexts if the context is an error",async()=>{const a={context:{type:t.ClearSignContextType.TOKEN,payload:"payload",certificate:{keyUsageNumber:1,payload:new Uint8Array([1,2,3])}},subcontextsCallbacks:[()=>Promise.resolve({type:t.ClearSignContextType.ERROR,error:new Error("error")})],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"};n.mockResolvedValue(c),e.sendCommand.mockResolvedValue(c);const s=await new i.ProvideTransactionContextTask(e,a,d,r).run();expect(s).toEqual((0,l.Right)(void 0)),expect(n).toHaveBeenCalledTimes(0),expect(C).toHaveBeenCalledTimes(0),expect(e.sendCommand).toHaveBeenCalledTimes(2),expect(e.sendCommand).toHaveBeenNthCalledWith(1,expect.any(y.LoadCertificateCommand)),expect(e.sendCommand).toHaveBeenNthCalledWith(2,expect.any(T.ProvideTokenInformationCommand))})}),describe("with subcontexts",()=>{it("should provide the transaction context and subcontext for a TRANSACTION_FIELD_DESCRIPTION context",async()=>{const a={context:{type:t.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload"},subcontextsCallbacks:[()=>Promise.resolve({type:t.ClearSignContextType.TOKEN,payload:"payload"})],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"};n.mockResolvedValue(c),e.sendCommand.mockResolvedValue(c);const s=await new i.ProvideTransactionContextTask(e,a,d,r).run();expect(s).toEqual((0,l.Right)(void 0)),expect(n).toHaveBeenCalledTimes(1),expect(n).toHaveBeenCalledWith(e,{payload:"payload",commandFactory:expect.any(Function)});const m=d.mock.calls[0][1].commandFactory,p={chunkedData:new Uint8Array([1,2,3]),isFirstChunk:!0},x=m(p);expect(x).toBeInstanceOf(f.ProvideTransactionFieldDescriptionCommand),expect(e.sendCommand).toHaveBeenCalledTimes(1),expect(e.sendCommand).toHaveBeenCalledWith(expect.any(T.ProvideTokenInformationCommand))}),it("should provide the transaction context and subcontexts for a TRUSTED_NAME context",async()=>{const a={context:{type:t.ClearSignContextType.TRUSTED_NAME,payload:"payload"},subcontextsCallbacks:[()=>Promise.resolve({type:t.ClearSignContextType.NFT,payload:"payload1"}),()=>Promise.resolve({type:t.ClearSignContextType.TOKEN,payload:"payload2"})],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"};n.mockResolvedValue(c),e.sendCommand.mockResolvedValue(c);const s=await new i.ProvideTransactionContextTask(e,a,d,r).run();expect(s).toEqual((0,l.Right)(void 0)),expect(n).toHaveBeenCalledTimes(1),expect(n).toHaveBeenCalledWith(e,{payload:"payload",commandFactory:expect.any(Function)});const m=d.mock.calls[0][1].commandFactory,p={chunkedData:new Uint8Array([1,2,3]),isFirstChunk:!0},x=m(p);expect(x).toBeInstanceOf(F.ProvideTrustedNameCommand),expect(e.sendCommand).toHaveBeenCalledTimes(2),expect(e.sendCommand).toHaveBeenNthCalledWith(1,expect.any(h.ProvideNFTInformationCommand)),expect(e.sendCommand).toHaveBeenNthCalledWith(2,expect.any(T.ProvideTokenInformationCommand))})}),describe("with subcontexts and certificate",()=>{it("should provide the transaction context and subcontexts for a TRUSTED_NAME context",async()=>{const a={context:{type:t.ClearSignContextType.TRUSTED_NAME,payload:"payload",certificate:{keyUsageNumber:1,payload:new Uint8Array([1,2,3])}},subcontextsCallbacks:[()=>Promise.resolve({type:t.ClearSignContextType.NFT,payload:"payload1",certificate:{keyUsageNumber:2,payload:new Uint8Array([4,5,6])}})],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"};n.mockResolvedValue(c),e.sendCommand.mockResolvedValue(c),await new i.ProvideTransactionContextTask(e,a,d,r).run(),expect(e.sendCommand).toHaveBeenCalledTimes(3),expect(e.sendCommand).toHaveBeenNthCalledWith(1,expect.any(y.LoadCertificateCommand)),expect(e.sendCommand).toHaveBeenNthCalledWith(2,expect.any(h.ProvideNFTInformationCommand)),expect(e.sendCommand).toHaveBeenNthCalledWith(3,expect.any(y.LoadCertificateCommand))})}),describe("with error",()=>{it("should return an error if the provideContext fails",async()=>{const a={context:{type:t.ClearSignContextType.TOKEN,payload:"payload"},subcontextsCallbacks:[],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"};e.sendCommand.mockResolvedValue(v);const s=await new i.ProvideTransactionContextTask(e,a,d,r).run();expect(s).toEqual((0,l.Left)(v))}),it("should return an error if the provide subcontext fails",async()=>{const a={context:{type:t.ClearSignContextType.TOKEN,payload:"payload"},subcontextsCallbacks:[()=>Promise.resolve({type:t.ClearSignContextType.TOKEN,payload:"payload"})],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"};e.sendCommand.mockResolvedValue(v);const s=await new i.ProvideTransactionContextTask(e,a,d,r).run();expect(s).toEqual((0,l.Left)(v))}),it("should return an error if the type is not supported",async()=>{const a={context:{type:"unsupported",payload:"payload"},subcontextsCallbacks:[],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"},s=await new i.ProvideTransactionContextTask(e,a,d,r).run();expect(s).toEqual((0,l.Left)((0,y.CommandResultFactory)({error:new y.InvalidStatusWordError("The context type [unsupported] is not covered")})))})}),describe("factory types",()=>{it("should have a sendPayloadInChunksTaskFactory by default",()=>{const a=new i.ProvideTransactionContextTask(e,{context:{type:t.ClearSignContextType.TOKEN,payload:"payload"},subcontextsCallbacks:[],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"});expect(a._sendPayloadInChunksTaskFactory).toBeDefined();const o=a._sendPayloadInChunksTaskFactory(e,{payload:"payload",commandFactory:()=>new f.ProvideTransactionFieldDescriptionCommand({data:new Uint8Array,isFirstChunk:!0})});expect(o).toBeInstanceOf(U.SendPayloadInChunksTask)}),it("should have a sendCommandInChunksTaskFactory by default",()=>{const a=new i.ProvideTransactionContextTask(e,{context:{type:t.ClearSignContextType.TOKEN,payload:"payload"},subcontextsCallbacks:[],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"});expect(a._sendCommandInChunksTaskFactory).toBeDefined();const o=a._sendCommandInChunksTaskFactory(e,{data:new Uint8Array,commandFactory:()=>new A.StoreTransactionCommand({serializedTransaction:new Uint8Array,isFirstChunk:!0})});expect(o).toBeInstanceOf(R.SendCommandInChunksTask)})})})});
1
+ "use strict";var t=require("@ledgerhq/context-module"),y=require("@ledgerhq/device-management-kit"),l=require("purify-ts"),F=require("../../app-binder/command/ProvideEnumCommand"),h=require("../../app-binder/command/ProvideNFTInformationCommand"),N=require("../../app-binder/command/ProvideProxyInfoCommand"),T=require("../../app-binder/command/ProvideTokenInformationCommand"),f=require("../../app-binder/command/ProvideTransactionFieldDescriptionCommand"),E=require("../../app-binder/command/ProvideTransactionInformationCommand"),P=require("../../app-binder/command/ProvideTrustedNameCommand"),b=require("../../app-binder/command/ProvideWeb3CheckCommand"),g=require("../../app-binder/command/SetExternalPluginCommand"),B=require("../../app-binder/command/SetPluginCommand"),A=require("../../app-binder/command/StoreTransactionCommand"),R=require("../../app-binder/device-action/__test-utils__/makeInternalApi"),i=require("./ProvideTransactionContextTask"),U=require("./SendCommandInChunksTask"),O=require("./SendPayloadInChunksTask");describe("ProvideTransactionContextTask",()=>{const e=(0,R.makeDeviceActionInternalApiMock)(),c=(0,y.CommandResultFactory)({data:void 0}),v=(0,y.CommandResultFactory)({data:void 0,error:{}});beforeEach(()=>{vi.resetAllMocks()}),describe("run",()=>{const n=vi.fn(),C=vi.fn(),r=vi.fn(),d=vi.fn();beforeEach(()=>{vi.clearAllMocks(),r.mockImplementation((a,o)=>({run:()=>C(a,o)})),d.mockImplementation((a,o)=>({run:()=>n(a,o)}))}),describe("with no subcontexts",()=>{it("should provide the transaction context for a TRANSACTION_INFO context",async()=>{const a={context:{type:t.ClearSignContextType.TRANSACTION_INFO,payload:"0x00",certificate:{keyUsageNumber:1,payload:new Uint8Array([1,2,3])}},subcontextsCallbacks:[],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"};C.mockResolvedValue(c),n.mockResolvedValue(c),e.sendCommand.mockResolvedValue(c);const s=await new i.ProvideTransactionContextTask(e,a,d,r).run();expect(s).toEqual((0,l.Right)(void 0)),expect(C).toHaveBeenCalledTimes(1),expect(r).toHaveBeenCalledWith(e,{data:new Uint8Array([5,128,0,0,44,128,0,0,60,128,0,0,0,0,0,0,0,0,0,0,0]),commandFactory:expect.any(Function)});const m=r.mock.calls[0][1].commandFactory,p={chunkedData:new Uint8Array([1,2,3,4]),isFirstChunk:!0},x=m(p);expect(x).toBeInstanceOf(A.StoreTransactionCommand),expect(e.sendCommand).toHaveBeenCalledTimes(1),expect(e.sendCommand).toHaveBeenCalledWith(expect.any(y.LoadCertificateCommand)),expect(n).toHaveBeenCalledTimes(1),expect(n).toHaveBeenCalledWith(e,{payload:"0x00",commandFactory:expect.any(Function)});const k=n.mock.calls[0][1].commandFactory,I=k(p);expect(I).toBeInstanceOf(E.ProvideTransactionInformationCommand)}),it("should provide the transaction context for a TRANSACTION_INFO context without certificate",async()=>{const a={context:{type:t.ClearSignContextType.TRANSACTION_INFO,payload:"0x00"},subcontextsCallbacks:[],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"};C.mockResolvedValue(c),n.mockResolvedValue(c),e.sendCommand.mockResolvedValue(c);const s=await new i.ProvideTransactionContextTask(e,a,d,r).run();expect(s).toEqual((0,l.Right)(void 0)),expect(C).toHaveBeenCalledTimes(1),expect(r).toHaveBeenCalledWith(e,{data:new Uint8Array([5,128,0,0,44,128,0,0,60,128,0,0,0,0,0,0,0,0,0,0,0]),commandFactory:expect.any(Function)});const m=r.mock.calls[0][1].commandFactory,p={chunkedData:new Uint8Array([1,2,3,4]),isFirstChunk:!0},x=m(p);expect(x).toBeInstanceOf(A.StoreTransactionCommand),expect(e.sendCommand).toHaveBeenCalledTimes(0),expect(n).toHaveBeenCalledTimes(1),expect(n).toHaveBeenCalledWith(e,{payload:"0x00",commandFactory:expect.any(Function)});const k=n.mock.calls[0][1].commandFactory,I=k(p);expect(I).toBeInstanceOf(E.ProvideTransactionInformationCommand)}),it.each([[t.ClearSignContextType.PLUGIN,B.SetPluginCommand],[t.ClearSignContextType.EXTERNAL_PLUGIN,g.SetExternalPluginCommand],[t.ClearSignContextType.NFT,h.ProvideNFTInformationCommand],[t.ClearSignContextType.TOKEN,T.ProvideTokenInformationCommand]])("should provide the transaction context by calling sendCommand for a %s context",async(a,o)=>{const s={context:{type:a,payload:"payload"},subcontextsCallbacks:[],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"};e.sendCommand.mockResolvedValue(c);const m=await new i.ProvideTransactionContextTask(e,s,d,r).run();expect(m).toEqual((0,l.Right)(void 0)),expect(e.sendCommand).toHaveBeenCalledTimes(1),expect(e.sendCommand).toHaveBeenCalledWith(expect.any(o))}),it.each([[t.ClearSignContextType.ENUM,F.ProvideEnumCommand],[t.ClearSignContextType.TRUSTED_NAME,P.ProvideTrustedNameCommand],[t.ClearSignContextType.WEB3_CHECK,b.ProvideWeb3CheckCommand],[t.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,f.ProvideTransactionFieldDescriptionCommand],[t.ClearSignContextType.PROXY_DELEGATE_CALL,N.ProvideProxyInfoCommand]])("should provide the transaction context by calling sendPayloadInChunksTask for a %s context",async(a,o)=>{const s={context:{type:a,payload:"payload"},subcontextsCallbacks:[],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"};n.mockResolvedValue(c);const m=await new i.ProvideTransactionContextTask(e,s,d,r).run();expect(m).toEqual((0,l.Right)(void 0)),expect(n).toHaveBeenCalledTimes(1),expect(n).toHaveBeenCalledWith(e,{payload:"payload",commandFactory:expect.any(Function)});const x=d.mock.calls[0][1].commandFactory,w={chunkedData:new Uint8Array([1,2,3]),isFirstChunk:!0},k=x(w);expect(k).toBeInstanceOf(o)}),it("should skip the subcontexts if the context is an error",async()=>{const a={context:{type:t.ClearSignContextType.TOKEN,payload:"payload",certificate:{keyUsageNumber:1,payload:new Uint8Array([1,2,3])}},subcontextsCallbacks:[()=>Promise.resolve({type:t.ClearSignContextType.ERROR,error:new Error("error")})],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"};n.mockResolvedValue(c),e.sendCommand.mockResolvedValue(c);const s=await new i.ProvideTransactionContextTask(e,a,d,r).run();expect(s).toEqual((0,l.Right)(void 0)),expect(n).toHaveBeenCalledTimes(0),expect(C).toHaveBeenCalledTimes(0),expect(e.sendCommand).toHaveBeenCalledTimes(2),expect(e.sendCommand).toHaveBeenNthCalledWith(1,expect.any(y.LoadCertificateCommand)),expect(e.sendCommand).toHaveBeenNthCalledWith(2,expect.any(T.ProvideTokenInformationCommand))})}),describe("with subcontexts",()=>{it("should provide the transaction context and subcontext for a TRANSACTION_FIELD_DESCRIPTION context",async()=>{const a={context:{type:t.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload"},subcontextsCallbacks:[()=>Promise.resolve({type:t.ClearSignContextType.TOKEN,payload:"payload"})],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"};n.mockResolvedValue(c),e.sendCommand.mockResolvedValue(c);const s=await new i.ProvideTransactionContextTask(e,a,d,r).run();expect(s).toEqual((0,l.Right)(void 0)),expect(n).toHaveBeenCalledTimes(1),expect(n).toHaveBeenCalledWith(e,{payload:"payload",commandFactory:expect.any(Function)});const m=d.mock.calls[0][1].commandFactory,p={chunkedData:new Uint8Array([1,2,3]),isFirstChunk:!0},x=m(p);expect(x).toBeInstanceOf(f.ProvideTransactionFieldDescriptionCommand),expect(e.sendCommand).toHaveBeenCalledTimes(1),expect(e.sendCommand).toHaveBeenCalledWith(expect.any(T.ProvideTokenInformationCommand))}),it("should provide the transaction context and subcontexts for a TRUSTED_NAME context",async()=>{const a={context:{type:t.ClearSignContextType.TRUSTED_NAME,payload:"payload"},subcontextsCallbacks:[()=>Promise.resolve({type:t.ClearSignContextType.NFT,payload:"payload1"}),()=>Promise.resolve({type:t.ClearSignContextType.TOKEN,payload:"payload2"})],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"};n.mockResolvedValue(c),e.sendCommand.mockResolvedValue(c);const s=await new i.ProvideTransactionContextTask(e,a,d,r).run();expect(s).toEqual((0,l.Right)(void 0)),expect(n).toHaveBeenCalledTimes(1),expect(n).toHaveBeenCalledWith(e,{payload:"payload",commandFactory:expect.any(Function)});const m=d.mock.calls[0][1].commandFactory,p={chunkedData:new Uint8Array([1,2,3]),isFirstChunk:!0},x=m(p);expect(x).toBeInstanceOf(P.ProvideTrustedNameCommand),expect(e.sendCommand).toHaveBeenCalledTimes(2),expect(e.sendCommand).toHaveBeenNthCalledWith(1,expect.any(h.ProvideNFTInformationCommand)),expect(e.sendCommand).toHaveBeenNthCalledWith(2,expect.any(T.ProvideTokenInformationCommand))})}),describe("with subcontexts and certificate",()=>{it("should provide the transaction context and subcontexts for a TRUSTED_NAME context",async()=>{const a={context:{type:t.ClearSignContextType.TRUSTED_NAME,payload:"payload",certificate:{keyUsageNumber:1,payload:new Uint8Array([1,2,3])}},subcontextsCallbacks:[()=>Promise.resolve({type:t.ClearSignContextType.NFT,payload:"payload1",certificate:{keyUsageNumber:2,payload:new Uint8Array([4,5,6])}})],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"};n.mockResolvedValue(c),e.sendCommand.mockResolvedValue(c),await new i.ProvideTransactionContextTask(e,a,d,r).run(),expect(e.sendCommand).toHaveBeenCalledTimes(3),expect(e.sendCommand).toHaveBeenNthCalledWith(1,expect.any(y.LoadCertificateCommand)),expect(e.sendCommand).toHaveBeenNthCalledWith(2,expect.any(h.ProvideNFTInformationCommand)),expect(e.sendCommand).toHaveBeenNthCalledWith(3,expect.any(y.LoadCertificateCommand))})}),describe("with error",()=>{it("should return an error if the provideContext fails",async()=>{const a={context:{type:t.ClearSignContextType.TOKEN,payload:"payload"},subcontextsCallbacks:[],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"};e.sendCommand.mockResolvedValue(v);const s=await new i.ProvideTransactionContextTask(e,a,d,r).run();expect(s).toEqual((0,l.Left)(v))}),it("should return an error if the provide subcontext fails",async()=>{const a={context:{type:t.ClearSignContextType.TOKEN,payload:"payload"},subcontextsCallbacks:[()=>Promise.resolve({type:t.ClearSignContextType.TOKEN,payload:"payload"})],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"};e.sendCommand.mockResolvedValue(v);const s=await new i.ProvideTransactionContextTask(e,a,d,r).run();expect(s).toEqual((0,l.Left)(v))}),it("should return an error if the type is not supported",async()=>{const a={context:{type:"unsupported",payload:"payload"},subcontextsCallbacks:[],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"},s=await new i.ProvideTransactionContextTask(e,a,d,r).run();expect(s).toEqual((0,l.Left)((0,y.CommandResultFactory)({error:new y.InvalidStatusWordError("The context type [unsupported] is not covered")})))})}),describe("factory types",()=>{it("should have a sendPayloadInChunksTaskFactory by default",()=>{const a=new i.ProvideTransactionContextTask(e,{context:{type:t.ClearSignContextType.TOKEN,payload:"payload"},subcontextsCallbacks:[],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"});expect(a._sendPayloadInChunksTaskFactory).toBeDefined();const o=a._sendPayloadInChunksTaskFactory(e,{payload:"payload",commandFactory:()=>new f.ProvideTransactionFieldDescriptionCommand({data:new Uint8Array,isFirstChunk:!0})});expect(o).toBeInstanceOf(O.SendPayloadInChunksTask)}),it("should have a sendCommandInChunksTaskFactory by default",()=>{const a=new i.ProvideTransactionContextTask(e,{context:{type:t.ClearSignContextType.TOKEN,payload:"payload"},subcontextsCallbacks:[],serializedTransaction:new Uint8Array,derivationPath:"44'/60'/0'/0/0"});expect(a._sendCommandInChunksTaskFactory).toBeDefined();const o=a._sendCommandInChunksTaskFactory(e,{data:new Uint8Array,commandFactory:()=>new A.StoreTransactionCommand({serializedTransaction:new Uint8Array,isFirstChunk:!0})});expect(o).toBeInstanceOf(U.SendCommandInChunksTask)})})})});
2
2
  //# sourceMappingURL=ProvideTransactionContextTask.test.js.map