@ledgerhq/device-signer-kit-ethereum 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/api/app-binder/GetConfigCommandTypes.js +2 -0
- package/lib/cjs/api/app-binder/GetConfigCommandTypes.js.map +7 -0
- package/lib/cjs/api/app-binder/SignTransactionDeviceActionTypes.js +1 -1
- package/lib/cjs/api/app-binder/SignTransactionDeviceActionTypes.js.map +1 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/internal/app-binder/EthAppBinder.test.js +1 -1
- package/lib/cjs/internal/app-binder/EthAppBinder.test.js.map +2 -2
- package/lib/cjs/internal/app-binder/command/GetAppConfigurationCommand.js +2 -0
- package/lib/cjs/internal/app-binder/command/GetAppConfigurationCommand.js.map +7 -0
- package/lib/cjs/internal/app-binder/command/GetAppConfigurationCommand.test.js +2 -0
- package/lib/cjs/internal/app-binder/command/GetAppConfigurationCommand.test.js.map +7 -0
- package/lib/cjs/internal/app-binder/command/ProvideWeb3CheckCommand.js +2 -0
- package/lib/cjs/internal/app-binder/command/ProvideWeb3CheckCommand.js.map +7 -0
- package/lib/cjs/internal/app-binder/command/ProvideWeb3CheckCommand.test.js +2 -0
- package/lib/cjs/internal/app-binder/command/ProvideWeb3CheckCommand.test.js.map +7 -0
- package/lib/cjs/internal/app-binder/command/Web3CheckOptInCommand.js +2 -0
- package/lib/cjs/internal/app-binder/command/Web3CheckOptInCommand.js.map +7 -0
- package/lib/cjs/internal/app-binder/command/Web3CheckOptInCommand.test.js +2 -0
- package/lib/cjs/internal/app-binder/command/Web3CheckOptInCommand.test.js.map +7 -0
- package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js +1 -1
- package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js.map +3 -3
- package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js +1 -1
- package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js.map +3 -3
- package/lib/cjs/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.js +1 -1
- package/lib/cjs/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.js.map +2 -2
- package/lib/cjs/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.test.js +1 -1
- package/lib/cjs/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.test.js.map +2 -2
- package/lib/cjs/internal/app-binder/device-action/__test-utils__/makeInternalApi.js +1 -1
- package/lib/cjs/internal/app-binder/device-action/__test-utils__/makeInternalApi.js.map +3 -3
- package/lib/cjs/internal/app-binder/task/BuildEIP712ContextTask.js +1 -1
- package/lib/cjs/internal/app-binder/task/BuildEIP712ContextTask.js.map +3 -3
- package/lib/cjs/internal/app-binder/task/BuildEIP712ContextTask.test.js +1 -1
- package/lib/cjs/internal/app-binder/task/BuildEIP712ContextTask.test.js.map +3 -3
- package/lib/cjs/internal/app-binder/task/BuildTransactionContextTask.test.js +1 -1
- package/lib/cjs/internal/app-binder/task/BuildTransactionContextTask.test.js.map +2 -2
- package/lib/cjs/internal/app-binder/task/GetWeb3CheckTask.js +2 -0
- package/lib/cjs/internal/app-binder/task/GetWeb3CheckTask.js.map +7 -0
- package/lib/cjs/internal/app-binder/task/GetWeb3CheckTask.test.js +2 -0
- package/lib/cjs/internal/app-binder/task/GetWeb3CheckTask.test.js.map +7 -0
- package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.js +1 -1
- package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.js.map +3 -3
- package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.test.js +1 -1
- package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.test.js.map +3 -3
- package/lib/cjs/internal/app-binder/task/ProvideTransactionContextTask.js +1 -1
- package/lib/cjs/internal/app-binder/task/ProvideTransactionContextTask.js.map +3 -3
- package/lib/cjs/internal/app-binder/task/ProvideTransactionContextTask.test.js +1 -1
- package/lib/cjs/internal/app-binder/task/ProvideTransactionContextTask.test.js.map +2 -2
- package/lib/cjs/internal/app-binder/task/ProvideTransactionFieldDescriptionTask.js +1 -1
- package/lib/cjs/internal/app-binder/task/ProvideTransactionFieldDescriptionTask.js.map +3 -3
- package/lib/cjs/internal/app-binder/task/ProvideTransactionGenericContextTask.js +1 -1
- package/lib/cjs/internal/app-binder/task/ProvideTransactionGenericContextTask.js.map +3 -3
- package/lib/cjs/internal/app-binder/task/ProvideTransactionGenericContextTask.test.js +1 -1
- package/lib/cjs/internal/app-binder/task/ProvideTransactionGenericContextTask.test.js.map +2 -2
- package/lib/cjs/package.json +3 -3
- package/lib/esm/api/app-binder/GetConfigCommandTypes.js +1 -0
- package/lib/esm/api/app-binder/GetConfigCommandTypes.js.map +7 -0
- package/lib/esm/internal/app-binder/EthAppBinder.test.js +1 -1
- package/lib/esm/internal/app-binder/EthAppBinder.test.js.map +2 -2
- package/lib/esm/internal/app-binder/command/GetAppConfigurationCommand.js +2 -0
- package/lib/esm/internal/app-binder/command/GetAppConfigurationCommand.js.map +7 -0
- package/lib/esm/internal/app-binder/command/GetAppConfigurationCommand.test.js +2 -0
- package/lib/esm/internal/app-binder/command/GetAppConfigurationCommand.test.js.map +7 -0
- package/lib/esm/internal/app-binder/command/ProvideWeb3CheckCommand.js +2 -0
- package/lib/esm/internal/app-binder/command/ProvideWeb3CheckCommand.js.map +7 -0
- package/lib/esm/internal/app-binder/command/ProvideWeb3CheckCommand.test.js +2 -0
- package/lib/esm/internal/app-binder/command/ProvideWeb3CheckCommand.test.js.map +7 -0
- package/lib/esm/internal/app-binder/command/Web3CheckOptInCommand.js +2 -0
- package/lib/esm/internal/app-binder/command/Web3CheckOptInCommand.js.map +7 -0
- package/lib/esm/internal/app-binder/command/Web3CheckOptInCommand.test.js +2 -0
- package/lib/esm/internal/app-binder/command/Web3CheckOptInCommand.test.js.map +7 -0
- package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js +1 -1
- package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js.map +3 -3
- package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js +1 -1
- package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js.map +3 -3
- package/lib/esm/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.js +1 -1
- package/lib/esm/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.js.map +2 -2
- package/lib/esm/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.test.js +1 -1
- package/lib/esm/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.test.js.map +2 -2
- package/lib/esm/internal/app-binder/device-action/__test-utils__/makeInternalApi.js +1 -1
- package/lib/esm/internal/app-binder/device-action/__test-utils__/makeInternalApi.js.map +3 -3
- package/lib/esm/internal/app-binder/task/BuildEIP712ContextTask.js +1 -1
- package/lib/esm/internal/app-binder/task/BuildEIP712ContextTask.js.map +3 -3
- package/lib/esm/internal/app-binder/task/BuildEIP712ContextTask.test.js +1 -1
- package/lib/esm/internal/app-binder/task/BuildEIP712ContextTask.test.js.map +3 -3
- package/lib/esm/internal/app-binder/task/BuildTransactionContextTask.test.js +1 -1
- package/lib/esm/internal/app-binder/task/BuildTransactionContextTask.test.js.map +2 -2
- package/lib/esm/internal/app-binder/task/GetWeb3CheckTask.js +2 -0
- package/lib/esm/internal/app-binder/task/GetWeb3CheckTask.js.map +7 -0
- package/lib/esm/internal/app-binder/task/GetWeb3CheckTask.test.js +2 -0
- package/lib/esm/internal/app-binder/task/GetWeb3CheckTask.test.js.map +7 -0
- package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.js +1 -1
- package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.js.map +3 -3
- package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.test.js +1 -1
- package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.test.js.map +3 -3
- package/lib/esm/internal/app-binder/task/ProvideTransactionContextTask.js +1 -1
- package/lib/esm/internal/app-binder/task/ProvideTransactionContextTask.js.map +3 -3
- package/lib/esm/internal/app-binder/task/ProvideTransactionContextTask.test.js +1 -1
- package/lib/esm/internal/app-binder/task/ProvideTransactionContextTask.test.js.map +2 -2
- package/lib/esm/internal/app-binder/task/ProvideTransactionFieldDescriptionTask.js +1 -1
- package/lib/esm/internal/app-binder/task/ProvideTransactionFieldDescriptionTask.js.map +3 -3
- package/lib/esm/internal/app-binder/task/ProvideTransactionGenericContextTask.js +1 -1
- package/lib/esm/internal/app-binder/task/ProvideTransactionGenericContextTask.js.map +3 -3
- package/lib/esm/internal/app-binder/task/ProvideTransactionGenericContextTask.test.js +1 -1
- package/lib/esm/internal/app-binder/task/ProvideTransactionGenericContextTask.test.js.map +2 -2
- package/lib/esm/package.json +3 -3
- package/lib/types/api/app-binder/GetConfigCommandTypes.d.ts +7 -0
- package/lib/types/api/app-binder/GetConfigCommandTypes.d.ts.map +1 -0
- package/lib/types/api/app-binder/SignTransactionDeviceActionTypes.d.ts +2 -1
- package/lib/types/api/app-binder/SignTransactionDeviceActionTypes.d.ts.map +1 -1
- package/lib/types/internal/app-binder/command/GetAppConfigurationCommand.d.ts +10 -0
- package/lib/types/internal/app-binder/command/GetAppConfigurationCommand.d.ts.map +1 -0
- package/lib/types/internal/app-binder/command/GetAppConfigurationCommand.test.d.ts +2 -0
- package/lib/types/internal/app-binder/command/GetAppConfigurationCommand.test.d.ts.map +1 -0
- package/lib/types/internal/app-binder/command/ProvideWeb3CheckCommand.d.ts +17 -0
- package/lib/types/internal/app-binder/command/ProvideWeb3CheckCommand.d.ts.map +1 -0
- package/lib/types/internal/app-binder/command/ProvideWeb3CheckCommand.test.d.ts +2 -0
- package/lib/types/internal/app-binder/command/ProvideWeb3CheckCommand.test.d.ts.map +1 -0
- package/lib/types/internal/app-binder/command/Web3CheckOptInCommand.d.ts +15 -0
- package/lib/types/internal/app-binder/command/Web3CheckOptInCommand.d.ts.map +1 -0
- package/lib/types/internal/app-binder/command/Web3CheckOptInCommand.test.d.ts +2 -0
- package/lib/types/internal/app-binder/command/Web3CheckOptInCommand.test.d.ts.map +1 -0
- package/lib/types/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.d.ts +13 -1
- package/lib/types/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.d.ts.map +1 -1
- package/lib/types/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.d.ts +1 -0
- package/lib/types/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.d.ts.map +1 -1
- package/lib/types/internal/app-binder/device-action/__test-utils__/makeInternalApi.d.ts.map +1 -1
- package/lib/types/internal/app-binder/task/BuildEIP712ContextTask.d.ts +4 -1
- package/lib/types/internal/app-binder/task/BuildEIP712ContextTask.d.ts.map +1 -1
- package/lib/types/internal/app-binder/task/GetWeb3CheckTask.d.ts +31 -0
- package/lib/types/internal/app-binder/task/GetWeb3CheckTask.d.ts.map +1 -0
- package/lib/types/internal/app-binder/task/GetWeb3CheckTask.test.d.ts +2 -0
- package/lib/types/internal/app-binder/task/GetWeb3CheckTask.test.d.ts.map +1 -0
- package/lib/types/internal/app-binder/task/ProvideEIP712ContextTask.d.ts +2 -0
- package/lib/types/internal/app-binder/task/ProvideEIP712ContextTask.d.ts.map +1 -1
- package/lib/types/internal/app-binder/task/ProvideTransactionContextTask.d.ts +3 -2
- package/lib/types/internal/app-binder/task/ProvideTransactionContextTask.d.ts.map +1 -1
- package/lib/types/internal/app-binder/task/ProvideTransactionFieldDescriptionTask.d.ts.map +1 -1
- package/lib/types/internal/app-binder/task/ProvideTransactionGenericContextTask.d.ts +1 -0
- package/lib/types/internal/app-binder/task/ProvideTransactionGenericContextTask.d.ts.map +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +10 -10
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var a=require("@ledgerhq/context-module"),e=require("@ledgerhq/device-management-kit"),T=require("ethers"),l=require("purify-ts"),S=require("../../app-binder/constant/plugins"),C=require("../../app-binder/device-action/__test-utils__/makeInternalApi"),u=require("./BuildTransactionContextTask");describe("BuildTransactionContextTask",()=>{const p={getContext:vi.fn(),getContexts:vi.fn(),getTypedDataFilters:vi.fn()},r={mapTransactionToSubset:vi.fn()},x={domain:"domain-name.eth"},y=(0,e.hexaStringToBuffer)(T.Transaction.from({chainId:1n,nonce:0,data:"0x"}).unsignedSerialized),c={keyUsageNumber:1,payload:new Uint8Array([1,2,3])};let d;const o=(0,C.makeDeviceActionInternalApiMock)();beforeEach(()=>{vi.resetAllMocks(),d={contextModule:p,mapper:r,transaction:y,options:x,challenge:"challenge"}}),it("should build the transaction context without clear sign contexts",async()=>{const n=new Uint8Array([1,2,3]),t=[],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:t,serializedTransaction:n,chainId:1,transactionType:0})}),it("should build the transaction context with clear sign contexts",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.NFT,payload:"payload-2"}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:t,serializedTransaction:n,chainId:1,transactionType:2})}),it("should build the transaction context with generic-parser context",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:a.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:e.DeviceModelId.FLEX});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:{transactionInfo:"payload-1",transactionInfoCertificate:c,transactionFields:[t[1],t[3]],transactionEnums:[t[2]]},serializedTransaction:n,chainId:1,transactionType:2})}),it("should build the transaction context with generic-parser context and a plugin instead of Ethereum app",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:a.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:S.ETHEREUM_PLUGINS[0],version:"1.15.0"},deviceModelId:e.DeviceModelId.FLEX});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:{transactionInfo:"payload-1",transactionInfoCertificate:c,transactionFields:[t[1],t[3]],transactionEnums:[t[2]]},serializedTransaction:n,chainId:1,transactionType:2})}),it("should call the mapper with the transaction",async()=>{const n=new Uint8Array([1,2,3]),t=[],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX}),await new u.BuildTransactionContextTask(o,d).run(),expect(r.mapTransactionToSubset).toHaveBeenCalledWith(y)}),it("should call the context module with the correct parameters",async()=>{const n=new Uint8Array([1,2,3]),t=[],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX}),await new u.BuildTransactionContextTask(o,d).run(),expect(p.getContexts).toHaveBeenCalledWith({deviceModelId:e.DeviceModelId.FLEX,challenge:"challenge",domain:"domain-name.eth",...s.subset})}),it("should throw an error if the mapper returns an error",async()=>{const n=new Error("error");r.mapTransactionToSubset.mockReturnValueOnce((0,l.Left)(n)),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX});const t=new u.BuildTransactionContextTask(o,d);await expect(t.run()).rejects.toThrow(n)}),it("should exclude error contexts from the result",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.ERROR,error:new Error("error")},{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.ERROR,error:new Error("error")},{type:a.ClearSignContextType.NFT,payload:"payload-2"}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:[t[1],t[3]],serializedTransaction:n,chainId:1,transactionType:0})}),it("should exclude generic-parser contexts from the result on old apps",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"transaction_info",certificate:c},{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:a.ClearSignContextType.NFT,payload:"payload-2"},{type:a.ClearSignContextType.ENUM,payload:"enum",id:1,value:2,certificate:c}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:[t[1],t[3]],serializedTransaction:n,chainId:1,transactionType:0})}),it("should exclude generic-parser contexts from the result if no transaction_info was found",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.ENUM,payload:"enum",id:1,value:2},{type:a.ClearSignContextType.NFT,payload:"payload-2"}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:e.DeviceModelId.FLEX});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:[t[1],t[3]],serializedTransaction:n,chainId:1,transactionType:0})}),it("should exclude legacy contexts from the result for generic-parser transactions",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:c},{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"payload-3"},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"},{type:a.ClearSignContextType.ENUM,payload:"payload-5",id:1,value:2,certificate:c}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:e.DeviceModelId.FLEX});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:{transactionInfo:"payload-2",transactionInfoCertificate:c,transactionFields:[t[3]],transactionEnums:[t[4]]},serializedTransaction:n,chainId:1,transactionType:2})}),it("should exclude generic-parser contexts with a nano s device",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:a.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:c}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:e.DeviceModelId.NANO_S});const i=await new u.BuildTransactionContextTask(o,{...d,challenge:null}).run();expect(i).toEqual({clearSignContexts:[t[0]],serializedTransaction:n,chainId:1,transactionType:2})}),it("should exclude generic-parser contexts with an old app version",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:a.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:c}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX});const i=await new u.BuildTransactionContextTask(o,{...d,challenge:null}).run();expect(i).toEqual({clearSignContexts:[t[0]],serializedTransaction:n,chainId:1,transactionType:2})}),it("should exclude generic-parser contexts with a non ready device",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:a.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:c}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.Connected,deviceStatus:e.DeviceStatus.NOT_CONNECTED,deviceModelId:e.DeviceModelId.FLEX});const i=await new u.BuildTransactionContextTask(o,{...d,challenge:null}).run();expect(i).toEqual({clearSignContexts:[t[0]],serializedTransaction:n,chainId:1,transactionType:2})}),it("should throw an error if the app is not ethereum compatible",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:a.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:c}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Not Ethereum Compatible",version:"1.14.0"},deviceModelId:e.DeviceModelId.FLEX});const i=new u.BuildTransactionContextTask(o,d);await expect(i.run()).rejects.toThrow("Unsupported app")}),it("should return an error if the transaction info certificate is missing",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:a.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:e.DeviceModelId.FLEX});const i=new u.BuildTransactionContextTask(o,d);await expect(i.run()).rejects.toThrow("Transaction info certificate is missing")})});
|
|
1
|
+
"use strict";var a=require("@ledgerhq/context-module"),e=require("@ledgerhq/device-management-kit"),T=require("ethers"),l=require("purify-ts"),S=require("../../app-binder/constant/plugins"),C=require("../../app-binder/device-action/__test-utils__/makeInternalApi"),u=require("./BuildTransactionContextTask");describe("BuildTransactionContextTask",()=>{const p={getContext:vi.fn(),getContexts:vi.fn(),getTypedDataFilters:vi.fn(),getWeb3Checks:vi.fn()},r={mapTransactionToSubset:vi.fn()},x={domain:"domain-name.eth"},y=(0,e.hexaStringToBuffer)(T.Transaction.from({chainId:1n,nonce:0,data:"0x"}).unsignedSerialized),c={keyUsageNumber:1,payload:new Uint8Array([1,2,3])};let d;const o=(0,C.makeDeviceActionInternalApiMock)();beforeEach(()=>{vi.resetAllMocks(),d={contextModule:p,mapper:r,transaction:y,options:x,challenge:"challenge"}}),it("should build the transaction context without clear sign contexts",async()=>{const n=new Uint8Array([1,2,3]),t=[],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:t,serializedTransaction:n,chainId:1,transactionType:0})}),it("should build the transaction context with clear sign contexts",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.NFT,payload:"payload-2"}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:t,serializedTransaction:n,chainId:1,transactionType:2})}),it("should build the transaction context with generic-parser context",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:a.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:{transactionInfo:"payload-1",transactionInfoCertificate:c,transactionFields:[t[1],t[3]],transactionEnums:[t[2]]},serializedTransaction:n,chainId:1,transactionType:2})}),it("should build the transaction context with generic-parser context and a plugin instead of Ethereum app",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:a.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:S.ETHEREUM_PLUGINS[0],version:"1.15.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:{transactionInfo:"payload-1",transactionInfoCertificate:c,transactionFields:[t[1],t[3]],transactionEnums:[t[2]]},serializedTransaction:n,chainId:1,transactionType:2})}),it("should call the mapper with the transaction",async()=>{const n=new Uint8Array([1,2,3]),t=[],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),await new u.BuildTransactionContextTask(o,d).run(),expect(r.mapTransactionToSubset).toHaveBeenCalledWith(y)}),it("should call the context module with the correct parameters",async()=>{const n=new Uint8Array([1,2,3]),t=[],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),await new u.BuildTransactionContextTask(o,d).run(),expect(p.getContexts).toHaveBeenCalledWith({deviceModelId:e.DeviceModelId.FLEX,challenge:"challenge",domain:"domain-name.eth",...s.subset})}),it("should throw an error if the mapper returns an error",async()=>{const n=new Error("error");r.mapTransactionToSubset.mockReturnValueOnce((0,l.Left)(n)),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const t=new u.BuildTransactionContextTask(o,d);await expect(t.run()).rejects.toThrow(n)}),it("should exclude error contexts from the result",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.ERROR,error:new Error("error")},{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.ERROR,error:new Error("error")},{type:a.ClearSignContextType.NFT,payload:"payload-2"}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:[t[1],t[3]],serializedTransaction:n,chainId:1,transactionType:0})}),it("should exclude generic-parser contexts from the result on old apps",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"transaction_info",certificate:c},{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:a.ClearSignContextType.NFT,payload:"payload-2"},{type:a.ClearSignContextType.ENUM,payload:"enum",id:1,value:2,certificate:c}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:[t[1],t[3]],serializedTransaction:n,chainId:1,transactionType:0})}),it("should exclude generic-parser contexts from the result if no transaction_info was found",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.ENUM,payload:"enum",id:1,value:2},{type:a.ClearSignContextType.NFT,payload:"payload-2"}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:0};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:[t[1],t[3]],serializedTransaction:n,chainId:1,transactionType:0})}),it("should exclude legacy contexts from the result for generic-parser transactions",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:c},{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"payload-3"},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"},{type:a.ClearSignContextType.ENUM,payload:"payload-5",id:1,value:2,certificate:c}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const i=await new u.BuildTransactionContextTask(o,d).run();expect(i).toEqual({clearSignContexts:{transactionInfo:"payload-2",transactionInfoCertificate:c,transactionFields:[t[3]],transactionEnums:[t[4]]},serializedTransaction:n,chainId:1,transactionType:2})}),it("should exclude generic-parser contexts with a nano s device",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:a.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:c}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:e.DeviceModelId.NANO_S,isSecureConnectionAllowed:!1});const i=await new u.BuildTransactionContextTask(o,{...d,challenge:null}).run();expect(i).toEqual({clearSignContexts:[t[0]],serializedTransaction:n,chainId:1,transactionType:2})}),it("should exclude generic-parser contexts with an old app version",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:a.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:c}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const i=await new u.BuildTransactionContextTask(o,{...d,challenge:null}).run();expect(i).toEqual({clearSignContexts:[t[0]],serializedTransaction:n,chainId:1,transactionType:2})}),it("should exclude generic-parser contexts with a non ready device",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TOKEN,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:a.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:c}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.Connected,deviceStatus:e.DeviceStatus.NOT_CONNECTED,deviceModelId:e.DeviceModelId.FLEX});const i=await new u.BuildTransactionContextTask(o,{...d,challenge:null}).run();expect(i).toEqual({clearSignContexts:[t[0]],serializedTransaction:n,chainId:1,transactionType:2})}),it("should throw an error if the app is not ethereum compatible",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:c},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:a.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:c}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Not Ethereum Compatible",version:"1.14.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const i=new u.BuildTransactionContextTask(o,d);await expect(i.run()).rejects.toThrow("Unsupported app")}),it("should return an error if the transaction info certificate is missing",async()=>{const n=new Uint8Array([1,2,3]),t=[{type:a.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1"},{type:a.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:a.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2}],s={subset:{chainId:1,to:void 0,data:"0x"},serializedTransaction:n,type:2};r.mapTransactionToSubset.mockReturnValueOnce((0,l.Right)(s)),p.getContexts.mockResolvedValueOnce(t),o.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const i=new u.BuildTransactionContextTask(o,d);await expect(i.run()).rejects.toThrow("Transaction info certificate is missing")})});
|
|
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 ClearSignContextType,\n type PkiCertificate,\n} from \"@ledgerhq/context-module\";\nimport {\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n hexaStringToBuffer,\n} from \"@ledgerhq/device-management-kit\";\nimport { Transaction } from \"ethers\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { ETHEREUM_PLUGINS } from \"@internal/app-binder/constant/plugins\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\nimport { type TransactionMapperResult } from \"@internal/transaction/service/mapper/model/TransactionMapperResult\";\nimport { type TransactionMapperService } from \"@internal/transaction/service/mapper/TransactionMapperService\";\n\nimport {\n BuildTransactionContextTask,\n type BuildTransactionContextTaskArgs,\n} from \"./BuildTransactionContextTask\";\n\ndescribe(\"BuildTransactionContextTask\", () => {\n const contextModuleMock = {\n getContext: vi.fn(),\n getContexts: vi.fn(),\n getTypedDataFilters: vi.fn(),\n };\n const mapperMock = {\n mapTransactionToSubset: 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\n beforeEach(() => {\n vi.resetAllMocks();\n\n defaultArgs = {\n contextModule: contextModuleMock,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction: defaultTransaction,\n options: defaultOptions,\n challenge: \"challenge\",\n };\n });\n\n it(\"should build the transaction context without clear sign contexts\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n serializedTransaction,\n chainId: 1,\n transactionType: 0,\n });\n });\n\n it(\"should build the transaction context with clear sign contexts\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n });\n });\n\n it(\"should build the transaction context with generic-parser context\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: {\n transactionInfo: \"payload-1\",\n transactionInfoCertificate: defaultCertificate,\n transactionFields: [clearSignContexts[1], clearSignContexts[3]],\n transactionEnums: [clearSignContexts[2]],\n },\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n });\n });\n\n it(\"should build the transaction context with generic-parser context and a plugin instead of Ethereum app\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: ETHEREUM_PLUGINS[0]!, version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: {\n transactionInfo: \"payload-1\",\n transactionInfoCertificate: defaultCertificate,\n transactionFields: [clearSignContexts[1], clearSignContexts[3]],\n transactionEnums: [clearSignContexts[2]],\n },\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n });\n });\n\n it(\"should call the mapper with the transaction\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 });\n\n // WHEN\n await new BuildTransactionContextTask(apiMock, defaultArgs).run();\n\n // THEN\n expect(mapperMock.mapTransactionToSubset).toHaveBeenCalledWith(\n defaultTransaction,\n );\n });\n\n it(\"should call the context module with the correct parameters\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 });\n\n // WHEN\n await new BuildTransactionContextTask(apiMock, defaultArgs).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.FLEX,\n challenge: \"challenge\",\n domain: \"domain-name.eth\",\n ...mapperResult.subset,\n });\n });\n\n it(\"should throw an error if the mapper returns an error\", async () => {\n // GIVEN\n const error = new Error(\"error\");\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Left(error));\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 });\n\n // WHEN\n const task = new BuildTransactionContextTask(apiMock, defaultArgs);\n\n // THEN\n await expect(task.run()).rejects.toThrow(error);\n });\n\n it(\"should exclude error contexts from the result\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n serializedTransaction,\n chainId: 1,\n transactionType: 0,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result on old apps\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n serializedTransaction,\n chainId: 1,\n transactionType: 0,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result if no transaction_info was found\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n serializedTransaction,\n chainId: 1,\n transactionType: 0,\n });\n });\n\n it(\"should exclude legacy contexts from the result for generic-parser transactions\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: {\n transactionInfo: \"payload-2\",\n transactionInfoCertificate: defaultCertificate,\n transactionFields: [clearSignContexts[3]],\n transactionEnums: [clearSignContexts[4]],\n },\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n });\n });\n\n it(\"should exclude generic-parser contexts with a nano s device\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 });\n\n // WHEN\n const result = await new BuildTransactionContextTask(apiMock, {\n ...defaultArgs,\n challenge: null,\n }).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n });\n });\n\n it(\"should exclude generic-parser contexts with an old app version\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 });\n\n // WHEN\n const result = await new BuildTransactionContextTask(apiMock, {\n ...defaultArgs,\n challenge: null,\n }).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n });\n });\n\n it(\"should exclude generic-parser contexts with a non ready device\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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(apiMock, {\n ...defaultArgs,\n challenge: null,\n }).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n });\n });\n\n it(\"should throw an error if the app is not ethereum compatible\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Not Ethereum Compatible\", version: \"1.14.0\" },\n deviceModelId: DeviceModelId.FLEX,\n });\n\n // WHEN\n const task = new BuildTransactionContextTask(apiMock, defaultArgs);\n\n // THEN\n await expect(task.run()).rejects.toThrow(\"Unsupported app\");\n });\n\n it(\"should return an error if the transaction info certificate is missing\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 });\n\n // WHEN\n const task = new BuildTransactionContextTask(apiMock, defaultArgs);\n\n // THEN\n await expect(task.run()).rejects.toThrow(\n \"Transaction info certificate is missing\",\n );\n });\n});\n"],
|
|
5
|
-
"mappings": "aAAA,IAAAA,EAIO,oCACPC,EAKO,2CACPC,EAA4B,kBAC5BC,EAA4B,qBAE5BC,EAAiC,iD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Certificate,\n} from \"@ledgerhq/context-module\";\nimport {\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n hexaStringToBuffer,\n} from \"@ledgerhq/device-management-kit\";\nimport { Transaction } from \"ethers\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { ETHEREUM_PLUGINS } from \"@internal/app-binder/constant/plugins\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\nimport { type TransactionMapperResult } from \"@internal/transaction/service/mapper/model/TransactionMapperResult\";\nimport { type TransactionMapperService } from \"@internal/transaction/service/mapper/TransactionMapperService\";\n\nimport {\n BuildTransactionContextTask,\n type BuildTransactionContextTaskArgs,\n} from \"./BuildTransactionContextTask\";\n\ndescribe(\"BuildTransactionContextTask\", () => {\n const contextModuleMock = {\n getContext: vi.fn(),\n getContexts: vi.fn(),\n getTypedDataFilters: vi.fn(),\n getWeb3Checks: vi.fn(),\n };\n const mapperMock = {\n mapTransactionToSubset: 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\n beforeEach(() => {\n vi.resetAllMocks();\n\n defaultArgs = {\n contextModule: contextModuleMock,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction: defaultTransaction,\n options: defaultOptions,\n challenge: \"challenge\",\n };\n });\n\n it(\"should build the transaction context without clear sign contexts\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n serializedTransaction,\n chainId: 1,\n transactionType: 0,\n });\n });\n\n it(\"should build the transaction context with clear sign contexts\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n });\n });\n\n it(\"should build the transaction context with generic-parser context\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: {\n transactionInfo: \"payload-1\",\n transactionInfoCertificate: defaultCertificate,\n transactionFields: [clearSignContexts[1], clearSignContexts[3]],\n transactionEnums: [clearSignContexts[2]],\n },\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n });\n });\n\n it(\"should build the transaction context with generic-parser context and a plugin instead of Ethereum app\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: ETHEREUM_PLUGINS[0]!, 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 ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: {\n transactionInfo: \"payload-1\",\n transactionInfoCertificate: defaultCertificate,\n transactionFields: [clearSignContexts[1], clearSignContexts[3]],\n transactionEnums: [clearSignContexts[2]],\n },\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n });\n });\n\n it(\"should call the mapper with the transaction\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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(apiMock, defaultArgs).run();\n\n // THEN\n expect(mapperMock.mapTransactionToSubset).toHaveBeenCalledWith(\n defaultTransaction,\n );\n });\n\n it(\"should call the context module with the correct parameters\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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(apiMock, defaultArgs).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.FLEX,\n challenge: \"challenge\",\n domain: \"domain-name.eth\",\n ...mapperResult.subset,\n });\n });\n\n it(\"should throw an error if the mapper returns an error\", async () => {\n // GIVEN\n const error = new Error(\"error\");\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Left(error));\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 task = new BuildTransactionContextTask(apiMock, defaultArgs);\n\n // THEN\n await expect(task.run()).rejects.toThrow(error);\n });\n\n it(\"should exclude error contexts from the result\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n serializedTransaction,\n chainId: 1,\n transactionType: 0,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result on old apps\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n serializedTransaction,\n chainId: 1,\n transactionType: 0,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result if no transaction_info was found\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n serializedTransaction,\n chainId: 1,\n transactionType: 0,\n });\n });\n\n it(\"should exclude legacy contexts from the result for generic-parser transactions\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: {\n transactionInfo: \"payload-2\",\n transactionInfoCertificate: defaultCertificate,\n transactionFields: [clearSignContexts[3]],\n transactionEnums: [clearSignContexts[4]],\n },\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n });\n });\n\n it(\"should exclude generic-parser contexts with a nano s device\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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(apiMock, {\n ...defaultArgs,\n challenge: null,\n }).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n });\n });\n\n it(\"should exclude generic-parser contexts with an old app version\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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(apiMock, {\n ...defaultArgs,\n challenge: null,\n }).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n });\n });\n\n it(\"should exclude generic-parser contexts with a non ready device\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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(apiMock, {\n ...defaultArgs,\n challenge: null,\n }).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n });\n });\n\n it(\"should throw an error if the app is not ethereum compatible\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Not Ethereum Compatible\", version: \"1.14.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const task = new BuildTransactionContextTask(apiMock, defaultArgs);\n\n // THEN\n await expect(task.run()).rejects.toThrow(\"Unsupported app\");\n });\n\n it(\"should return an error if the transaction info certificate is missing\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\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 const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\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 task = new BuildTransactionContextTask(apiMock, defaultArgs);\n\n // THEN\n await expect(task.run()).rejects.toThrow(\n \"Transaction info certificate is missing\",\n );\n });\n});\n"],
|
|
5
|
+
"mappings": "aAAA,IAAAA,EAIO,oCACPC,EAKO,2CACPC,EAA4B,kBAC5BC,EAA4B,qBAE5BC,EAAiC,iDACjCC,EAAgD,6EAIhDC,EAGO,yCAEP,SAAS,8BAA+B,IAAM,CAC5C,MAAMC,EAAoB,CACxB,WAAY,GAAG,GAAG,EAClB,YAAa,GAAG,GAAG,EACnB,oBAAqB,GAAG,GAAG,EAC3B,cAAe,GAAG,GAAG,CACvB,EACMC,EAAa,CACjB,uBAAwB,GAAG,GAAG,CAChC,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,EAEhD,WAAW,IAAM,CACf,GAAG,cAAc,EAEjBD,EAAc,CACZ,cAAeL,EACf,OAAQC,EACR,YAAaE,EACb,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N,EAASD,CAAW,EAGjE,MAAM,OAAOO,EAAK,IAAI,CAAC,EAAE,QAAQ,QAAQ,iBAAiB,CAC5D,CAAC,EAED,GAAG,wEAAyE,SAAY,CAEtF,MAAML,EAAwB,IAAI,WAAW,CAAC,EAAM,EAAM,CAAI,CAAC,EACzDC,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,EACMC,EAAwC,CAC5C,OAAQ,CAAE,QAAS,EAAG,GAAI,OAAW,KAAM,IAAK,EAChD,sBAAAF,EACA,KAAM,CACR,EACAN,EAAW,uBAAuB,uBAAoB,SAAMQ,CAAY,CAAC,EACzET,EAAkB,YAAY,sBAAsBQ,CAAiB,EACrEF,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,MAAMM,EAAO,IAAI,8BAA4BN,EAASD,CAAW,EAGjE,MAAM,OAAOO,EAAK,IAAI,CAAC,EAAE,QAAQ,QAC/B,yCACF,CACF,CAAC,CACH,CAAC",
|
|
6
6
|
"names": ["import_context_module", "import_device_management_kit", "import_ethers", "import_purify_ts", "import_plugins", "import_makeInternalApi", "import_BuildTransactionContextTask", "contextModuleMock", "mapperMock", "defaultOptions", "defaultTransaction", "defaultCertificate", "defaultArgs", "apiMock", "serializedTransaction", "clearSignContexts", "mapperResult", "result", "error", "task"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var c=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var f=(n,e)=>{for(var t in e)c(n,t,{get:e[t],enumerable:!0})},S=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of T(e))!x.call(n,r)&&r!==t&&c(n,r,{get:()=>e[r],enumerable:!(o=w(e,r))||o.enumerable});return n};var W=n=>S(c({},"__esModule",{value:!0}),n);var v={};f(v,{GetWeb3CheckTask:()=>A});module.exports=W(v);var d=require("@ledgerhq/context-module"),s=require("@ledgerhq/device-management-kit"),h=require("semver"),u=require("../../app-binder/command/GetAddressCommand"),k=require("../../app-binder/command/GetAppConfigurationCommand"),b=require("../../app-binder/command/Web3CheckOptInCommand");class A{constructor(e,t){this.api=e;this.args=t}async run(){const e=this.api.getDeviceSessionState();if(!this.isSupported(e))return{web3Check:null};const t=await this.api.sendCommand(new k.GetAppConfiguration);if(!(0,s.isSuccessCommandResult)(t))return{web3Check:null,error:t.error};let o=t.data.web3ChecksEnabled;if(!o&&!t.data.web3ChecksOptIn){const a=await this.api.sendCommand(new b.Web3CheckOptInCommand);if(!(0,s.isSuccessCommandResult)(a))return{web3Check:null,error:a.error};o=a.data.enabled}if(!o)return{web3Check:null};const r=await this.api.sendCommand(new u.GetAddressCommand({derivationPath:this.args.derivationPath,checkOnDevice:!1,returnChainCode:!1}));if(!(0,s.isSuccessCommandResult)(r))return{web3Check:null,error:r.error};const p=r.data.address,{deviceModelId:C}=e,{contextModule:l}=this.args;let i;if(this.isRawTx(this.args)){const a=this.args.mapper.mapTransactionToSubset(this.args.transaction);if(a.isRight()){const{subset:m,serializedTransaction:y}=a.extract(),g={deviceModelId:C,from:p,rawTx:(0,s.bufferToHexaString)(y),chainId:m.chainId};i=await l.getWeb3Checks(g)}else throw a.extract()}else{const a={deviceModelId:C,from:p,data:this.args.data};i=await l.getWeb3Checks(a)}return i===null||i?.type!==d.ClearSignContextType.WEB3_CHECK?{web3Check:null}:{web3Check:i}}isRawTx(e){return"transaction"in e}isSupported(e){return e.sessionStateType!==s.DeviceSessionStateType.Connected&&e.currentApp.name==="Ethereum"&&(0,h.gte)(e.currentApp.version,"1.16.0")}}0&&(module.exports={GetWeb3CheckTask});
|
|
2
|
+
//# sourceMappingURL=GetWeb3CheckTask.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/internal/app-binder/task/GetWeb3CheckTask.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n type ClearSignContext,\n type ClearSignContextSuccess,\n ClearSignContextType,\n type ContextModule,\n type Web3CheckContext,\n} from \"@ledgerhq/context-module\";\nimport {\n bufferToHexaString,\n type DeviceSessionState,\n DeviceSessionStateType,\n type DmkError,\n type InternalApi,\n isSuccessCommandResult,\n} from \"@ledgerhq/device-management-kit\";\nimport { gte } from \"semver\";\n\nimport { type TypedData } from \"@api/model/TypedData\";\nimport { GetAddressCommand } from \"@internal/app-binder/command/GetAddressCommand\";\nimport { GetAppConfiguration } from \"@internal/app-binder/command/GetAppConfigurationCommand\";\nimport { Web3CheckOptInCommand } from \"@internal/app-binder/command/Web3CheckOptInCommand\";\nimport { type TransactionMapperService } from \"@internal/transaction/service/mapper/TransactionMapperService\";\n\nexport type GetWeb3CheckTaskResult =\n | {\n readonly web3Check: ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK> | null;\n }\n | {\n readonly web3Check: null;\n error: DmkError;\n };\n\nexport type GetWeb3CheckTypedDataTaskArgs = {\n readonly contextModule: ContextModule;\n readonly derivationPath: string;\n readonly data: TypedData;\n};\nexport type GetWeb3CheckRawTxTaskArgs = {\n readonly contextModule: ContextModule;\n readonly derivationPath: string;\n readonly mapper: TransactionMapperService;\n readonly transaction: Uint8Array;\n};\nexport type GetWeb3CheckTaskArgs =\n | GetWeb3CheckTypedDataTaskArgs\n | GetWeb3CheckRawTxTaskArgs;\n\nexport class GetWeb3CheckTask {\n constructor(\n private readonly api: InternalApi,\n private readonly args: GetWeb3CheckTaskArgs,\n ) {}\n\n async run(): Promise<GetWeb3CheckTaskResult> {\n // Early return on old applications\n const sessionState = this.api.getDeviceSessionState();\n if (!this.isSupported(sessionState)) {\n return {\n web3Check: null,\n };\n }\n\n // Get app configuration\n const configResult = await this.api.sendCommand(new GetAppConfiguration());\n if (!isSuccessCommandResult(configResult)) {\n return {\n web3Check: null,\n error: configResult.error,\n };\n }\n let web3ChecksEnabled = configResult.data.web3ChecksEnabled;\n\n // If feature is disabled and opt-in was not done, trigger it on the device\n if (!web3ChecksEnabled && !configResult.data.web3ChecksOptIn) {\n const web3CheckStatus = await this.api.sendCommand(\n new Web3CheckOptInCommand(),\n );\n if (!isSuccessCommandResult(web3CheckStatus)) {\n return {\n web3Check: null,\n error: web3CheckStatus.error,\n };\n }\n web3ChecksEnabled = web3CheckStatus.data.enabled;\n }\n\n // Only do Web3 Check if it is activated\n if (!web3ChecksEnabled) {\n return {\n web3Check: null,\n };\n }\n\n // Get sender address\n const getAddressResult = await this.api.sendCommand(\n new GetAddressCommand({\n derivationPath: this.args.derivationPath,\n checkOnDevice: false,\n returnChainCode: false,\n }),\n );\n if (!isSuccessCommandResult(getAddressResult)) {\n return {\n web3Check: null,\n error: getAddressResult.error,\n };\n }\n\n const address = getAddressResult.data.address;\n const { deviceModelId } = sessionState;\n const { contextModule } = this.args;\n let web3CheckContext: ClearSignContext | null;\n\n if (this.isRawTx(this.args)) {\n // Transaction simulation\n const parsed = this.args.mapper.mapTransactionToSubset(\n this.args.transaction,\n );\n if (parsed.isRight()) {\n const { subset, serializedTransaction } = parsed.extract();\n const web3Params: Web3CheckContext = {\n deviceModelId,\n from: address,\n rawTx: bufferToHexaString(serializedTransaction),\n chainId: subset.chainId,\n };\n web3CheckContext = await contextModule.getWeb3Checks(web3Params);\n } else {\n throw parsed.extract();\n }\n } else {\n // Typed data simulation\n const web3Params: Web3CheckContext = {\n deviceModelId,\n from: address,\n data: this.args.data,\n };\n web3CheckContext = await contextModule.getWeb3Checks(web3Params);\n }\n\n if (\n web3CheckContext === null ||\n web3CheckContext?.type !== ClearSignContextType.WEB3_CHECK\n ) {\n return {\n web3Check: null,\n };\n }\n\n return {\n web3Check: web3CheckContext,\n };\n }\n\n private isRawTx(\n args: GetWeb3CheckTaskArgs,\n ): args is GetWeb3CheckRawTxTaskArgs {\n return \"transaction\" in args;\n }\n\n private isSupported(deviceState: DeviceSessionState): boolean {\n return (\n deviceState.sessionStateType !== DeviceSessionStateType.Connected &&\n deviceState.currentApp.name === \"Ethereum\" &&\n gte(deviceState.currentApp.version, \"1.16.0\")\n );\n }\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,sBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAMO,oCACPC,EAOO,2CACPC,EAAoB,kBAGpBC,EAAkC,0DAClCC,EAAoC,mEACpCC,EAAsC,8DA2B/B,MAAMP,CAAiB,CAC5B,YACmBQ,EACAC,EACjB,CAFiB,SAAAD,EACA,UAAAC,CAChB,CAEH,MAAM,KAAuC,CAE3C,MAAMC,EAAe,KAAK,IAAI,sBAAsB,EACpD,GAAI,CAAC,KAAK,YAAYA,CAAY,EAChC,MAAO,CACL,UAAW,IACb,EAIF,MAAMC,EAAe,MAAM,KAAK,IAAI,YAAY,IAAI,qBAAqB,EACzE,GAAI,IAAC,0BAAuBA,CAAY,EACtC,MAAO,CACL,UAAW,KACX,MAAOA,EAAa,KACtB,EAEF,IAAIC,EAAoBD,EAAa,KAAK,kBAG1C,GAAI,CAACC,GAAqB,CAACD,EAAa,KAAK,gBAAiB,CAC5D,MAAME,EAAkB,MAAM,KAAK,IAAI,YACrC,IAAI,uBACN,EACA,GAAI,IAAC,0BAAuBA,CAAe,EACzC,MAAO,CACL,UAAW,KACX,MAAOA,EAAgB,KACzB,EAEFD,EAAoBC,EAAgB,KAAK,OAC3C,CAGA,GAAI,CAACD,EACH,MAAO,CACL,UAAW,IACb,EAIF,MAAME,EAAmB,MAAM,KAAK,IAAI,YACtC,IAAI,oBAAkB,CACpB,eAAgB,KAAK,KAAK,eAC1B,cAAe,GACf,gBAAiB,EACnB,CAAC,CACH,EACA,GAAI,IAAC,0BAAuBA,CAAgB,EAC1C,MAAO,CACL,UAAW,KACX,MAAOA,EAAiB,KAC1B,EAGF,MAAMC,EAAUD,EAAiB,KAAK,QAChC,CAAE,cAAAE,CAAc,EAAIN,EACpB,CAAE,cAAAO,CAAc,EAAI,KAAK,KAC/B,IAAIC,EAEJ,GAAI,KAAK,QAAQ,KAAK,IAAI,EAAG,CAE3B,MAAMC,EAAS,KAAK,KAAK,OAAO,uBAC9B,KAAK,KAAK,WACZ,EACA,GAAIA,EAAO,QAAQ,EAAG,CACpB,KAAM,CAAE,OAAAC,EAAQ,sBAAAC,CAAsB,EAAIF,EAAO,QAAQ,EACnDG,EAA+B,CACnC,cAAAN,EACA,KAAMD,EACN,SAAO,sBAAmBM,CAAqB,EAC/C,QAASD,EAAO,OAClB,EACAF,EAAmB,MAAMD,EAAc,cAAcK,CAAU,CACjE,KACE,OAAMH,EAAO,QAAQ,CAEzB,KAAO,CAEL,MAAMG,EAA+B,CACnC,cAAAN,EACA,KAAMD,EACN,KAAM,KAAK,KAAK,IAClB,EACAG,EAAmB,MAAMD,EAAc,cAAcK,CAAU,CACjE,CAEA,OACEJ,IAAqB,MACrBA,GAAkB,OAAS,uBAAqB,WAEzC,CACL,UAAW,IACb,EAGK,CACL,UAAWA,CACb,CACF,CAEQ,QACNT,EACmC,CACnC,MAAO,gBAAiBA,CAC1B,CAEQ,YAAYc,EAA0C,CAC5D,OACEA,EAAY,mBAAqB,yBAAuB,WACxDA,EAAY,WAAW,OAAS,eAChC,OAAIA,EAAY,WAAW,QAAS,QAAQ,CAEhD,CACF",
|
|
6
|
+
"names": ["GetWeb3CheckTask_exports", "__export", "GetWeb3CheckTask", "__toCommonJS", "import_context_module", "import_device_management_kit", "import_semver", "import_GetAddressCommand", "import_GetAppConfigurationCommand", "import_Web3CheckOptInCommand", "api", "args", "sessionState", "configResult", "web3ChecksEnabled", "web3CheckStatus", "getAddressResult", "address", "deviceModelId", "contextModule", "web3CheckContext", "parsed", "subset", "serializedTransaction", "web3Params", "deviceState"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var e=require("@ledgerhq/device-management-kit"),r=require("purify-ts"),d=require("../../app-binder/device-action/__test-utils__/makeInternalApi"),s=require("../../app-binder/task/GetWeb3CheckTask");describe("GetWeb3CheckTask",()=>{const n=(0,d.makeDeviceActionInternalApiMock)(),o={getWeb3Checks:vi.fn()},t={mapTransactionToSubset:vi.fn()},u=new Uint8Array([1,2,3,4]),c="44'/60'/0'/0/0";describe("old apps",()=>{beforeEach(()=>{vi.clearAllMocks(),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!0})}),it("should return null on old applications",async()=>{t.mapTransactionToSubset.mockReturnValue((0,r.Right)({subset:{},serializedTransaction:new Uint8Array})),n.sendCommand.mockResolvedValue((0,e.CommandResultFactory)({data:{web3ChecksEnabled:!0,web3ChecksOptIn:!0}})),o.getWeb3Checks.mockResolvedValue({type:"web3Check",id:1});const a=await new s.GetWeb3CheckTask(n,{contextModule:o,mapper:t,transaction:u,derivationPath:c}).run();expect(a).toEqual({web3Check:null})})}),describe("run",()=>{beforeEach(()=>{vi.clearAllMocks(),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.16.0"},deviceModelId:e.DeviceModelId.FLEX,isSecureConnectionAllowed:!0})}),describe("errors",()=>{it("should throw an error if mapTransactionToSubset assert.fails",async()=>{const a=new Error("error");n.sendCommand.mockResolvedValueOnce((0,e.CommandResultFactory)({data:{web3ChecksEnabled:!0,web3ChecksOptIn:!0}})),n.sendCommand.mockResolvedValueOnce((0,e.CommandResultFactory)({data:{address:"address"}})),t.mapTransactionToSubset.mockReturnValue((0,r.Left)(a));try{await new s.GetWeb3CheckTask(n,{contextModule:o,mapper:t,transaction:u,derivationPath:c}).run(),assert.fail("should throw an error")}catch(l){expect(l).toEqual(a)}}),it("should return a context error if GetAppConfiguration assert.fails",async()=>{t.mapTransactionToSubset.mockReturnValue((0,r.Right)({subset:{},serializedTransaction:new Uint8Array})),n.sendCommand.mockResolvedValue((0,e.CommandResultFactory)({error:new e.InvalidStatusWordError("error")}));const a=await new s.GetWeb3CheckTask(n,{contextModule:o,mapper:t,transaction:u,derivationPath:c}).run();expect(a).toEqual({web3Check:null,error:new e.InvalidStatusWordError("error")})}),it("should return a context error if Web3CheckOptInCommand assert.fails",async()=>{t.mapTransactionToSubset.mockReturnValue((0,r.Right)({subset:{},serializedTransaction:new Uint8Array})),n.sendCommand.mockResolvedValueOnce((0,e.CommandResultFactory)({data:{web3ChecksEnabled:!1,web3ChecksOptIn:!1}})),n.sendCommand.mockResolvedValue((0,e.CommandResultFactory)({error:new e.InvalidStatusWordError("error")}));const a=await new s.GetWeb3CheckTask(n,{contextModule:o,mapper:t,transaction:u,derivationPath:c}).run();expect(a).toEqual({web3Check:null,error:new e.InvalidStatusWordError("error")})}),it("should return a context error if GetAddressCommand assert.fails",async()=>{t.mapTransactionToSubset.mockReturnValue((0,r.Right)({subset:{},serializedTransaction:new Uint8Array})),n.sendCommand.mockResolvedValueOnce((0,e.CommandResultFactory)({data:{web3ChecksEnabled:!0,web3ChecksOptIn:!0}})),n.sendCommand.mockResolvedValueOnce((0,e.CommandResultFactory)({error:new e.InvalidStatusWordError("error")}));const a=await new s.GetWeb3CheckTask(n,{contextModule:o,mapper:t,transaction:u,derivationPath:c}).run();expect(a).toEqual({web3Check:null,error:new e.InvalidStatusWordError("error")})}),it("should return null if the type is not a ClearSignContextSuccess web3check",async()=>{t.mapTransactionToSubset.mockReturnValue((0,r.Right)({subset:{},serializedTransaction:new Uint8Array})),n.sendCommand.mockResolvedValueOnce((0,e.CommandResultFactory)({data:{web3ChecksEnabled:!0,web3ChecksOptIn:!0}})),n.sendCommand.mockResolvedValueOnce((0,e.CommandResultFactory)({data:{address:"address"}})),o.getWeb3Checks.mockResolvedValue({type:"invalid-type",id:1});const a=await new s.GetWeb3CheckTask(n,{contextModule:o,mapper:t,transaction:u,derivationPath:c}).run();expect(a).toEqual({web3Check:null})})}),describe("success",()=>{it("should return null if web3ChecksEnabled is false",async()=>{t.mapTransactionToSubset.mockReturnValue((0,r.Right)({subset:{},serializedTransaction:new Uint8Array})),n.sendCommand.mockResolvedValue((0,e.CommandResultFactory)({data:{web3ChecksEnabled:!1,web3ChecksOptIn:!0}}));const a=await new s.GetWeb3CheckTask(n,{contextModule:o,mapper:t,transaction:u,derivationPath:c}).run();expect(a).toEqual({web3Check:null})}),it("should return null if the context module does not have a web3 check",async()=>{t.mapTransactionToSubset.mockReturnValue((0,r.Right)({subset:{},serializedTransaction:new Uint8Array})),n.sendCommand.mockResolvedValue((0,e.CommandResultFactory)({data:{web3ChecksEnabled:!0,web3ChecksOptIn:!0}})),o.getWeb3Checks.mockResolvedValue(null);const a=await new s.GetWeb3CheckTask(n,{contextModule:o,mapper:t,transaction:u,derivationPath:c}).run();expect(a).toEqual({web3Check:null})}),it("should return a web3 check",async()=>{const a={type:"web3Check",id:1};t.mapTransactionToSubset.mockReturnValue((0,r.Right)({subset:{},serializedTransaction:new Uint8Array})),n.sendCommand.mockResolvedValue((0,e.CommandResultFactory)({data:{web3ChecksEnabled:!0,web3ChecksOptIn:!0}})),o.getWeb3Checks.mockResolvedValue(a);const l=await new s.GetWeb3CheckTask(n,{contextModule:o,mapper:t,transaction:u,derivationPath:c}).run();expect(l).toEqual({web3Check:a})}),it("should opt-in and then return the web3check",async()=>{const a={type:"web3Check",id:1};t.mapTransactionToSubset.mockReturnValue((0,r.Right)({subset:{},serializedTransaction:new Uint8Array})),n.sendCommand.mockResolvedValueOnce((0,e.CommandResultFactory)({data:{web3ChecksEnabled:!1,web3ChecksOptIn:!1}})),n.sendCommand.mockResolvedValueOnce((0,e.CommandResultFactory)({data:{enabled:!0}})),o.getWeb3Checks.mockResolvedValue(a);const l=await new s.GetWeb3CheckTask(n,{contextModule:o,mapper:t,transaction:u,derivationPath:c}).run();expect(l).toEqual({web3Check:a})}),it("should opt-in and then return a null if disabled",async()=>{const a={type:"web3Check",id:1};t.mapTransactionToSubset.mockReturnValue((0,r.Right)({subset:{},serializedTransaction:new Uint8Array})),n.sendCommand.mockResolvedValueOnce((0,e.CommandResultFactory)({data:{web3ChecksEnabled:!1,web3ChecksOptIn:!1}})),n.sendCommand.mockResolvedValueOnce((0,e.CommandResultFactory)({data:{enabled:!1}})),o.getWeb3Checks.mockResolvedValue(a);const l=await new s.GetWeb3CheckTask(n,{contextModule:o,mapper:t,transaction:u,derivationPath:c}).run();expect(l).toEqual({web3Check:null})}),it("should return a web3 check for typed data",async()=>{const a={type:"web3Check",id:1};n.sendCommand.mockResolvedValue((0,e.CommandResultFactory)({data:{web3ChecksEnabled:!0,web3ChecksOptIn:!0}})),o.getWeb3Checks.mockResolvedValue(a);const l=await new s.GetWeb3CheckTask(n,{contextModule:o,data:"typed data",derivationPath:c}).run();expect(l).toEqual({web3Check:a})}),it("should call the context module with the right parameters",async()=>{t.mapTransactionToSubset.mockReturnValue((0,r.Right)({subset:{chainId:15,from:"from"},serializedTransaction:new Uint8Array([1,2,3])})),n.sendCommand.mockResolvedValueOnce((0,e.CommandResultFactory)({data:{web3ChecksEnabled:!0,web3ChecksOptIn:!0}})),n.sendCommand.mockResolvedValueOnce((0,e.CommandResultFactory)({data:{address:"address"}})),o.getWeb3Checks.mockResolvedValue(null),await new s.GetWeb3CheckTask(n,{contextModule:o,mapper:t,transaction:u,derivationPath:c}).run(),expect(o.getWeb3Checks).toHaveBeenCalledWith({deviceModelId:e.DeviceModelId.FLEX,from:"address",rawTx:"0x010203",chainId:15})})})})});
|
|
2
|
+
//# sourceMappingURL=GetWeb3CheckTask.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/internal/app-binder/task/GetWeb3CheckTask.test.ts"],
|
|
4
|
+
"sourcesContent": ["import { type ContextModule } from \"@ledgerhq/context-module\";\nimport {\n CommandResultFactory,\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n InvalidStatusWordError,\n} from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type TypedData } from \"@api/model/TypedData\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\nimport { GetWeb3CheckTask } from \"@internal/app-binder/task/GetWeb3CheckTask\";\nimport { type TransactionMapperService } from \"@internal/transaction/service/mapper/TransactionMapperService\";\n\ndescribe(\"GetWeb3CheckTask\", () => {\n const apiMock = makeDeviceActionInternalApiMock();\n const contextModuleMock = {\n getWeb3Checks: vi.fn(),\n };\n const mapperMock = {\n mapTransactionToSubset: vi.fn(),\n };\n const transaction = new Uint8Array([0x01, 0x02, 0x03, 0x04]);\n const derivationPath = \"44'/60'/0'/0/0\";\n\n describe(\"old apps\", () => {\n beforeEach(() => {\n vi.clearAllMocks();\n\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: true,\n });\n });\n\n it(\"should return null on old applications\", async () => {\n // GIVEN\n mapperMock.mapTransactionToSubset.mockReturnValue(\n Right({ subset: {}, serializedTransaction: new Uint8Array() }),\n );\n apiMock.sendCommand.mockResolvedValue(\n CommandResultFactory({\n data: { web3ChecksEnabled: true, web3ChecksOptIn: true },\n }),\n );\n contextModuleMock.getWeb3Checks.mockResolvedValue({\n type: \"web3Check\",\n id: 1,\n });\n\n // WHEN\n const result = await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n\n // THEN\n expect(result).toEqual({\n web3Check: null,\n });\n });\n });\n\n describe(\"run\", () => {\n beforeEach(() => {\n vi.clearAllMocks();\n\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.16.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: true,\n });\n });\n\n describe(\"errors\", () => {\n it(\"should throw an error if mapTransactionToSubset assert.fails\", async () => {\n // GIVEN\n const error = new Error(\"error\");\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({\n data: { web3ChecksEnabled: true, web3ChecksOptIn: true },\n }),\n );\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ data: { address: \"address\" } }),\n );\n mapperMock.mapTransactionToSubset.mockReturnValue(Left(error));\n\n // WHEN\n try {\n await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n assert.fail(\"should throw an error\");\n } catch (e) {\n // THEN\n expect(e).toEqual(error);\n }\n });\n\n it(\"should return a context error if GetAppConfiguration assert.fails\", async () => {\n // GIVEN\n mapperMock.mapTransactionToSubset.mockReturnValue(\n Right({ subset: {}, serializedTransaction: new Uint8Array() }),\n );\n apiMock.sendCommand.mockResolvedValue(\n CommandResultFactory({ error: new InvalidStatusWordError(\"error\") }),\n );\n\n // WHEN\n const result = await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n\n // THEN\n expect(result).toEqual({\n web3Check: null,\n error: new InvalidStatusWordError(\"error\"),\n });\n });\n\n it(\"should return a context error if Web3CheckOptInCommand assert.fails\", async () => {\n // GIVEN\n mapperMock.mapTransactionToSubset.mockReturnValue(\n Right({ subset: {}, serializedTransaction: new Uint8Array() }),\n );\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({\n data: { web3ChecksEnabled: false, web3ChecksOptIn: false },\n }),\n );\n apiMock.sendCommand.mockResolvedValue(\n CommandResultFactory({ error: new InvalidStatusWordError(\"error\") }),\n );\n\n // WHEN\n const result = await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n\n // THEN\n expect(result).toEqual({\n web3Check: null,\n error: new InvalidStatusWordError(\"error\"),\n });\n });\n\n it(\"should return a context error if GetAddressCommand assert.fails\", async () => {\n // GIVEN\n mapperMock.mapTransactionToSubset.mockReturnValue(\n Right({ subset: {}, serializedTransaction: new Uint8Array() }),\n );\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({\n data: { web3ChecksEnabled: true, web3ChecksOptIn: true },\n }),\n );\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ error: new InvalidStatusWordError(\"error\") }),\n );\n\n // WHEN\n const result = await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n\n // THEN\n expect(result).toEqual({\n web3Check: null,\n error: new InvalidStatusWordError(\"error\"),\n });\n });\n\n it(\"should return null if the type is not a ClearSignContextSuccess web3check\", async () => {\n // GIVEN\n mapperMock.mapTransactionToSubset.mockReturnValue(\n Right({ subset: {}, serializedTransaction: new Uint8Array() }),\n );\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({\n data: { web3ChecksEnabled: true, web3ChecksOptIn: true },\n }),\n );\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ data: { address: \"address\" } }),\n );\n contextModuleMock.getWeb3Checks.mockResolvedValue({\n type: \"invalid-type\",\n id: 1,\n });\n\n // WHEN\n const result = await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n\n // THEN\n expect(result).toEqual({\n web3Check: null,\n });\n });\n });\n\n describe(\"success\", () => {\n it(\"should return null if web3ChecksEnabled is false\", async () => {\n // GIVEN\n mapperMock.mapTransactionToSubset.mockReturnValue(\n Right({ subset: {}, serializedTransaction: new Uint8Array() }),\n );\n apiMock.sendCommand.mockResolvedValue(\n CommandResultFactory({\n data: { web3ChecksEnabled: false, web3ChecksOptIn: true },\n }),\n );\n\n // WHEN\n const result = await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n\n // THEN\n expect(result).toEqual({\n web3Check: null,\n });\n });\n\n it(\"should return null if the context module does not have a web3 check\", async () => {\n // GIVEN\n mapperMock.mapTransactionToSubset.mockReturnValue(\n Right({ subset: {}, serializedTransaction: new Uint8Array() }),\n );\n apiMock.sendCommand.mockResolvedValue(\n CommandResultFactory({\n data: { web3ChecksEnabled: true, web3ChecksOptIn: true },\n }),\n );\n contextModuleMock.getWeb3Checks.mockResolvedValue(null);\n\n // WHEN\n const result = await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n\n // THEN\n expect(result).toEqual({\n web3Check: null,\n });\n });\n\n it(\"should return a web3 check\", async () => {\n // GIVEN\n const web3Check = { type: \"web3Check\", id: 1 };\n mapperMock.mapTransactionToSubset.mockReturnValue(\n Right({ subset: {}, serializedTransaction: new Uint8Array() }),\n );\n apiMock.sendCommand.mockResolvedValue(\n CommandResultFactory({\n data: { web3ChecksEnabled: true, web3ChecksOptIn: true },\n }),\n );\n contextModuleMock.getWeb3Checks.mockResolvedValue(web3Check);\n\n // WHEN\n const result = await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n\n // THEN\n expect(result).toEqual({\n web3Check,\n });\n });\n\n it(\"should opt-in and then return the web3check\", async () => {\n // GIVEN\n const web3Check = { type: \"web3Check\", id: 1 };\n mapperMock.mapTransactionToSubset.mockReturnValue(\n Right({ subset: {}, serializedTransaction: new Uint8Array() }),\n );\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({\n data: { web3ChecksEnabled: false, web3ChecksOptIn: false },\n }),\n );\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ data: { enabled: true } }),\n );\n contextModuleMock.getWeb3Checks.mockResolvedValue(web3Check);\n\n // WHEN\n const result = await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n\n // THEN\n expect(result).toEqual({\n web3Check,\n });\n });\n\n it(\"should opt-in and then return a null if disabled\", async () => {\n // GIVEN\n const web3Check = { type: \"web3Check\", id: 1 };\n mapperMock.mapTransactionToSubset.mockReturnValue(\n Right({ subset: {}, serializedTransaction: new Uint8Array() }),\n );\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({\n data: { web3ChecksEnabled: false, web3ChecksOptIn: false },\n }),\n );\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ data: { enabled: false } }),\n );\n contextModuleMock.getWeb3Checks.mockResolvedValue(web3Check);\n\n // WHEN\n const result = await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n\n // THEN\n expect(result).toEqual({\n web3Check: null,\n });\n });\n\n it(\"should return a web3 check for typed data\", async () => {\n // GIVEN\n const web3Check = { type: \"web3Check\", id: 1 };\n apiMock.sendCommand.mockResolvedValue(\n CommandResultFactory({\n data: { web3ChecksEnabled: true, web3ChecksOptIn: true },\n }),\n );\n contextModuleMock.getWeb3Checks.mockResolvedValue(web3Check);\n\n // WHEN\n const result = await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n data: \"typed data\" as unknown as TypedData,\n derivationPath,\n }).run();\n\n // THEN\n expect(result).toEqual({\n web3Check,\n });\n });\n\n it(\"should call the context module with the right parameters\", async () => {\n // GIVEN\n mapperMock.mapTransactionToSubset.mockReturnValue(\n Right({\n subset: { chainId: 15, from: \"from\" },\n serializedTransaction: new Uint8Array([0x01, 0x02, 0x03]),\n }),\n );\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({\n data: { web3ChecksEnabled: true, web3ChecksOptIn: true },\n }),\n );\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ data: { address: \"address\" } }),\n );\n contextModuleMock.getWeb3Checks.mockResolvedValue(null);\n\n // WHEN\n await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n\n // THEN\n expect(contextModuleMock.getWeb3Checks).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.FLEX,\n from: \"address\",\n rawTx: \"0x010203\",\n chainId: 15,\n });\n });\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "aACA,IAAAA,EAMO,2CACPC,EAA4B,qBAG5BC,EAAgD,6EAChDC,EAAiC,sDAGjC,SAAS,mBAAoB,IAAM,CACjC,MAAMC,KAAU,mCAAgC,EAC1CC,EAAoB,CACxB,cAAe,GAAG,GAAG,CACvB,EAC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AW,IACb,CAAC,CACH,CAAC,EAED,GAAG,4CAA6C,SAAY,CAE1D,MAAMG,EAAY,CAAE,KAAM,YAAa,GAAI,CAAE,EAC7CR,EAAQ,YAAY,qBAClB,wBAAqB,CACnB,KAAM,CAAE,kBAAmB,GAAM,gBAAiB,EAAK,CACzD,CAAC,CACH,EACAC,EAAkB,cAAc,kBAAkBO,CAAS,EAG3D,MAAMH,EAAS,MAAM,IAAI,mBAAiBL,EAAS,CACjD,cAAeC,EACf,KAAM,aACN,eAAAG,CACF,CAAC,EAAE,IAAI,EAGP,OAAOC,CAAM,EAAE,QAAQ,CACrB,UAAAG,CACF,CAAC,CACH,CAAC,EAED,GAAG,2DAA4D,SAAY,CAEzEN,EAAW,uBAAuB,mBAChC,SAAM,CACJ,OAAQ,CAAE,QAAS,GAAI,KAAM,MAAO,EACpC,sBAAuB,IAAI,WAAW,CAAC,EAAM,EAAM,CAAI,CAAC,CAC1D,CAAC,CACH,EACAF,EAAQ,YAAY,yBAClB,wBAAqB,CACnB,KAAM,CAAE,kBAAmB,GAAM,gBAAiB,EAAK,CACzD,CAAC,CACH,EACAA,EAAQ,YAAY,yBAClB,wBAAqB,CAAE,KAAM,CAAE,QAAS,SAAU,CAAE,CAAC,CACvD,EACAC,EAAkB,cAAc,kBAAkB,IAAI,EAGtD,MAAM,IAAI,mBAAiBD,EAAS,CAClC,cAAeC,EACf,OAAQC,EACR,YAAAC,EACA,eAAAC,CACF,CAAC,EAAE,IAAI,EAGP,OAAOH,EAAkB,aAAa,EAAE,qBAAqB,CAC3D,cAAe,gBAAc,KAC7B,KAAM,UACN,MAAO,WACP,QAAS,EACX,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["import_device_management_kit", "import_purify_ts", "import_makeInternalApi", "import_GetWeb3CheckTask", "apiMock", "contextModuleMock", "mapperMock", "transaction", "derivationPath", "result", "error", "e", "web3Check"]
|
|
7
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var h=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var P=(m,e)=>{for(var a in e)h(m,a,{get:e[a],enumerable:!0})},b=(m,e,a,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of R(e))!A.call(m,t)&&t!==a&&h(m,t,{get:()=>e[t],enumerable:!(n=D(e,t))||n.enumerable});return m};var N=m=>b(h({},"__esModule",{value:!0}),m);var V={};P(V,{ProvideEIP712ContextTask:()=>F});module.exports=N(V);var x=require("@ledgerhq/context-module"),s=require("@ledgerhq/device-management-kit"),p=require("purify-ts"),S=require("../../app-binder/command/ProvideTokenInformationCommand"),w=require("../../app-binder/command/ProvideWeb3CheckCommand"),i=require("../../app-binder/command/SendEIP712FilteringCommand"),u=require("../../app-binder/command/SendEIP712StructDefinitionCommand"),f=require("../../app-binder/command/SendEIP712StructImplemCommand"),C=require("../../app-binder/task/SendEIP712StructImplemTask"),y=require("../../typed-data/model/Types"),E=require("./SendPayloadInChunksTask");const k=5;class F{constructor(e,a){this.api=e;this.args=a}async run(){this.args.web3Check&&(this.args.web3Check.certificate&&await this.api.sendCommand(new s.LoadCertificateCommand({keyUsage:this.args.web3Check.certificate.keyUsageNumber,certificate:this.args.web3Check.certificate.payload})),await new E.SendPayloadInChunksTask(this.api,{payload:this.args.web3Check.payload,commandFactory:t=>new w.ProvideWeb3CheckCommand({payload:t.chunkedData,isFirstChunk:t.isFirstChunk})}).run());const e=(0,s.CommandResultFactory)({data:void 0}),a=Object.entries(this.args.types).sort(([t],[o])=>t.localeCompare(o));for(const[t,o]of a){const r=await this.api.sendCommand(new u.SendEIP712StructDefinitionCommand({command:u.StructDefinitionCommand.Name,name:t}));if(!(0,s.isSuccessCommandResult)(r))return r;for(const[l,d]of Object.entries(o)){const g=await this.api.sendCommand(new u.SendEIP712StructDefinitionCommand({command:u.StructDefinitionCommand.Field,name:l,type:d}));if(!(0,s.isSuccessCommandResult)(g))return g}}if(this.args.clearSignContext.isJust()){const t=await this.api.sendCommand(new i.SendEIP712FilteringCommand({type:i.Eip712FilterType.Activation}));if(!(0,s.isSuccessCommandResult)(t))return t}for(const t of this.args.domain){const r=await this.getImplementationTask(t).run();if(!(0,s.isSuccessCommandResult)(r))return r}if(this.args.clearSignContext.isJust()){const t=this.args.clearSignContext.extract(),o=await this.api.sendCommand(new i.SendEIP712FilteringCommand({type:i.Eip712FilterType.MessageInfo,displayName:t.messageInfo.displayName,filtersCount:t.messageInfo.filtersCount,signature:t.messageInfo.signature}));if(!(0,s.isSuccessCommandResult)(o))return o}const n={indexes:{},nextIndex:0};for(const t of this.args.message){const o=await this.provideTokenInformation(t,n);if(o.isJust())return o.extract();const r=await this.filterValue(t,n);if(r.isJust()&&!(0,s.isSuccessCommandResult)(r.extract()))return r.extract();const d=await this.getImplementationTask(t).run();if(!(0,s.isSuccessCommandResult)(d))return d;if(this.args.clearSignContext.isJust()&&t.value instanceof y.TypedDataValueArray&&t.value.length===0){const v=Object.entries(this.args.clearSignContext.extract().filters).filter(([c])=>c.startsWith(`${t.path}.[]`)).map(([,c])=>c);for(const c of v){const I=await this.api.sendCommand(new i.SendEIP712FilteringCommand({type:i.Eip712FilterType.DiscardedPath,path:c.path}));if(!(0,s.isSuccessCommandResult)(I))return I;const T=await this.provideFiltering(c,n,!0);if(!(0,s.isSuccessCommandResult)(T))return T}}}return e}getImplementationTask(e){return e.value instanceof y.TypedDataValueRoot?new C.SendEIP712StructImplemTask(this.api,{type:f.StructImplemType.ROOT,value:e.value.root}):e.value instanceof y.TypedDataValueArray?new C.SendEIP712StructImplemTask(this.api,{type:f.StructImplemType.ARRAY,value:e.value.length}):new C.SendEIP712StructImplemTask(this.api,{type:f.StructImplemType.FIELD,value:e.value.data})}async provideTokenInformation(e,a){if(this.args.clearSignContext.isJust()){const n=this.args.clearSignContext.extract().filters[e.path];if(n!==void 0&&(n.type==="amount"||n.type==="token")&&a.indexes[n.tokenIndex]===void 0){const t=n.tokenIndex,r=this.args.clearSignContext.extract().tokens[t];if(r===void 0)return p.Nothing;const l=await this.api.sendCommand(new S.ProvideTokenInformationCommand({payload:r}));if(!(0,s.isSuccessCommandResult)(l))return p.Maybe.of(l);let{tokenIndex:d}=l.data;a.nextIndex=(d+1)%k,Number(t)===x.VERIFYING_CONTRACT_TOKEN_INDEX&&(d=x.VERIFYING_CONTRACT_TOKEN_INDEX),a.indexes[Number(t)]=d}}return p.Nothing}async filterValue(e,a){if(this.args.clearSignContext.isJust()){const n=this.args.clearSignContext.extract().filters[e.path];if(n===void 0)return p.Nothing;const t=await this.provideFiltering(n,a,!1);return p.Maybe.of(t)}return p.Nothing}async provideFiltering(e,a,n){switch(e.type){case"datetime":return await this.api.sendCommand(new i.SendEIP712FilteringCommand({type:i.Eip712FilterType.Datetime,discarded:n,displayName:e.displayName,signature:e.signature}));case"raw":return await this.api.sendCommand(new i.SendEIP712FilteringCommand({type:i.Eip712FilterType.Raw,discarded:n,displayName:e.displayName,signature:e.signature}));case"token":return this.sanitizeDeviceIndex(e.tokenIndex,a),await this.api.sendCommand(new i.SendEIP712FilteringCommand({type:i.Eip712FilterType.Token,discarded:n,tokenIndex:a.indexes[e.tokenIndex],signature:e.signature}));case"amount":return this.sanitizeDeviceIndex(e.tokenIndex,a),await this.api.sendCommand(new i.SendEIP712FilteringCommand({type:i.Eip712FilterType.Amount,discarded:n,displayName:e.displayName,tokenIndex:a.indexes[e.tokenIndex],signature:e.signature}));default:return(0,s.CommandResultFactory)({error:new s.InvalidStatusWordError("ProvideEIP712ContextTask/provideFiltering - Unhandled filter type")})}}sanitizeDeviceIndex(e,a){a.indexes[e]===void 0&&(a.indexes[e]=a.nextIndex,a.nextIndex=(a.nextIndex+1)%k)}}0&&(module.exports={ProvideEIP712ContextTask});
|
|
2
2
|
//# sourceMappingURL=ProvideEIP712ContextTask.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/app-binder/task/ProvideEIP712ContextTask.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n type TypedDataClearSignContextSuccess,\n type TypedDataFilter,\n type TypedDataTokenIndex,\n VERIFYING_CONTRACT_TOKEN_INDEX,\n} from \"@ledgerhq/context-module\";\nimport type {\n CommandResult,\n InternalApi,\n} from \"@ledgerhq/device-management-kit\";\nimport {\n CommandResultFactory,\n InvalidStatusWordError,\n isSuccessCommandResult,\n} from \"@ledgerhq/device-management-kit\";\nimport { Maybe, Nothing } from \"purify-ts\";\n\nimport { ProvideTokenInformationCommand } from \"@internal/app-binder/command/ProvideTokenInformationCommand\";\nimport {\n Eip712FilterType,\n SendEIP712FilteringCommand,\n} from \"@internal/app-binder/command/SendEIP712FilteringCommand\";\nimport {\n SendEIP712StructDefinitionCommand,\n StructDefinitionCommand,\n} from \"@internal/app-binder/command/SendEIP712StructDefinitionCommand\";\nimport { StructImplemType } from \"@internal/app-binder/command/SendEIP712StructImplemCommand\";\nimport { type EthErrorCodes } from \"@internal/app-binder/command/utils/ethAppErrors\";\nimport { SendEIP712StructImplemTask } from \"@internal/app-binder/task/SendEIP712StructImplemTask\";\nimport {\n type FieldName,\n type FieldType,\n type StructName,\n type TypedDataValue,\n TypedDataValueArray,\n TypedDataValueRoot,\n} from \"@internal/typed-data/model/Types\";\n\ntype AllSuccessTypes = void | { tokenIndex: number };\n\nexport type ProvideEIP712ContextTaskReturnType = Promise<\n CommandResult<AllSuccessTypes, EthErrorCodes>\n>;\n\nexport type ProvideEIP712ContextTaskArgs = {\n types: Record<StructName, Record<FieldName, FieldType>>;\n domain: Array<TypedDataValue>;\n message: Array<TypedDataValue>;\n clearSignContext: Maybe<TypedDataClearSignContextSuccess>;\n domainHash: string;\n messageHash: string;\n};\n\nconst DEVICE_ASSETS_MAX = 5;\n\ntype DeviceAssetIndexes = {\n indexes: Record<TypedDataTokenIndex, number>;\n nextIndex: number;\n};\n\nexport class ProvideEIP712ContextTask {\n constructor(\n private api: InternalApi,\n private args: ProvideEIP712ContextTaskArgs,\n ) {}\n\n async run(): ProvideEIP712ContextTaskReturnType {\n const result: CommandResult<AllSuccessTypes, EthErrorCodes> =\n CommandResultFactory<AllSuccessTypes, EthErrorCodes>({ data: undefined });\n\n // Provide the structure definitions.\n // Should be sent before struct implementations, as described here:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#eip712-send-struct-definition\n // Note that those types are used to compute the schema hash, in the device and in ClearSignContexts, as described here:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#eip712-filtering\n // Therefore it should be normalized on both sides: sorted per keys\n const types = Object.entries(this.args.types).sort(([aKey], [bKey]) =>\n aKey.localeCompare(bKey),\n );\n for (const [structName, fields] of types) {\n const structNameResult = await this.api.sendCommand(\n new SendEIP712StructDefinitionCommand({\n command: StructDefinitionCommand.Name,\n name: structName,\n }),\n );\n if (!isSuccessCommandResult(structNameResult)) {\n return structNameResult;\n }\n\n for (const [fieldName, fieldType] of Object.entries(fields)) {\n const fieldResult = await this.api.sendCommand(\n new SendEIP712StructDefinitionCommand({\n command: StructDefinitionCommand.Field,\n name: fieldName,\n type: fieldType,\n }),\n );\n if (!isSuccessCommandResult(fieldResult)) {\n return fieldResult;\n }\n }\n }\n\n // possibly activate the filtering, before sending domain and message implementations, as described here:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#activation\n if (this.args.clearSignContext.isJust()) {\n const activationResult = await this.api.sendCommand(\n new SendEIP712FilteringCommand({ type: Eip712FilterType.Activation }),\n );\n if (!isSuccessCommandResult(activationResult)) {\n return activationResult;\n }\n }\n\n // send domain implementation values.\n for (const value of this.args.domain) {\n const domainImplTask = this.getImplementationTask(value);\n const domainImplResult = await domainImplTask.run();\n if (!isSuccessCommandResult(domainImplResult)) {\n return domainImplResult;\n }\n }\n\n // possibly send MessageInformation filter (between Domain and Message)\n // should be sent between Domain and Message implementations, as described here:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#message-info\n if (this.args.clearSignContext.isJust()) {\n const clearSignContext = this.args.clearSignContext.extract();\n const messageInfoFilterResult = await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.MessageInfo,\n displayName: clearSignContext.messageInfo.displayName,\n filtersCount: clearSignContext.messageInfo.filtersCount,\n signature: clearSignContext.messageInfo.signature,\n }),\n );\n if (!isSuccessCommandResult(messageInfoFilterResult)) {\n return messageInfoFilterResult;\n }\n }\n\n // send message implementation values\n const deviceIndexes: DeviceAssetIndexes = { indexes: {}, nextIndex: 0 };\n for (const value of this.args.message) {\n // 5.1 Provide token descriptors, if any\n // Keep a map of all device indexes for those provided tokens.\n const maybeError = await this.provideTokenInformation(\n value,\n deviceIndexes,\n );\n if (maybeError.isJust()) {\n return maybeError.extract();\n }\n\n // if there's a filter, send it\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#amount-join-token\n const maybeFilterResult = await this.filterValue(value, deviceIndexes);\n if (\n maybeFilterResult.isJust() &&\n !isSuccessCommandResult(maybeFilterResult.extract())\n ) {\n return maybeFilterResult.extract();\n }\n\n // provide message value implementation\n const messageImplTask = this.getImplementationTask(value);\n const messageImplResult = await messageImplTask.run();\n if (!isSuccessCommandResult(messageImplResult)) {\n return messageImplResult;\n }\n\n // if the value is an empty array, discard sub-filters since\n // there will be no according sub-values in the message\n if (\n this.args.clearSignContext.isJust() &&\n value.value instanceof TypedDataValueArray &&\n value.value.length === 0\n ) {\n const filters = Object.entries(\n this.args.clearSignContext.extract().filters,\n );\n const discardedFilters = filters\n .filter(([path]) => path.startsWith(`${value.path}.[]`))\n .map(([, filter]) => filter);\n for (const filter of discardedFilters) {\n const discardedPathResult = await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.DiscardedPath,\n path: filter.path,\n }),\n );\n if (!isSuccessCommandResult(discardedPathResult)) {\n return discardedPathResult;\n }\n\n const provideFilteringResult = await this.provideFiltering(\n filter,\n deviceIndexes,\n true,\n );\n if (!isSuccessCommandResult(provideFilteringResult)) {\n return provideFilteringResult;\n }\n }\n }\n }\n\n return result;\n }\n\n getImplementationTask(value: TypedDataValue): SendEIP712StructImplemTask {\n if (value.value instanceof TypedDataValueRoot) {\n return new SendEIP712StructImplemTask(this.api, {\n type: StructImplemType.ROOT,\n value: value.value.root,\n });\n } else if (value.value instanceof TypedDataValueArray) {\n return new SendEIP712StructImplemTask(this.api, {\n type: StructImplemType.ARRAY,\n value: value.value.length,\n });\n } else {\n return new SendEIP712StructImplemTask(this.api, {\n type: StructImplemType.FIELD,\n value: value.value.data,\n });\n }\n }\n\n async provideTokenInformation(\n value: TypedDataValue,\n deviceIndexes: DeviceAssetIndexes,\n ): Promise<Maybe<CommandResult<AllSuccessTypes, EthErrorCodes>>> {\n if (this.args.clearSignContext.isJust()) {\n const filter = this.args.clearSignContext.extract().filters[value.path];\n // tokens descriptors only needed when a tokenIndex is available in filter.\n // it should be sent to the device only 1 time so deviceIndexes has to be checked.\n if (\n filter !== undefined &&\n (filter.type === \"amount\" || filter.type === \"token\") &&\n deviceIndexes.indexes[filter.tokenIndex] === undefined\n ) {\n const descriptorIndex = filter.tokenIndex;\n const tokens = this.args.clearSignContext.extract().tokens;\n const token = tokens[descriptorIndex];\n if (token === undefined) {\n return Nothing;\n }\n\n const provideTokenInfoResult = await this.api.sendCommand(\n new ProvideTokenInformationCommand({ payload: token }),\n );\n if (!isSuccessCommandResult(provideTokenInfoResult)) {\n return Maybe.of(provideTokenInfoResult);\n }\n let { tokenIndex: deviceIndex } = provideTokenInfoResult.data;\n deviceIndexes.nextIndex = (deviceIndex + 1) % DEVICE_ASSETS_MAX;\n\n // the token corresponding to the Verifying Contract of message domain has a special index value, as described here:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#amount-join-value\n if (Number(descriptorIndex) === VERIFYING_CONTRACT_TOKEN_INDEX) {\n deviceIndex = VERIFYING_CONTRACT_TOKEN_INDEX;\n }\n\n deviceIndexes.indexes[Number(descriptorIndex)] = deviceIndex;\n }\n }\n return Nothing;\n }\n\n async filterValue(\n value: TypedDataValue,\n deviceIndexes: DeviceAssetIndexes,\n ): Promise<Maybe<CommandResult<AllSuccessTypes, EthErrorCodes>>> {\n if (this.args.clearSignContext.isJust()) {\n const filter = this.args.clearSignContext.extract().filters[value.path];\n if (filter === undefined) {\n return Nothing;\n }\n // provide the filter\n const filteringResult = await this.provideFiltering(\n filter,\n deviceIndexes,\n false,\n );\n return Maybe.of(filteringResult);\n }\n return Nothing;\n }\n\n async provideFiltering(\n filter: TypedDataFilter,\n deviceIndexes: DeviceAssetIndexes,\n discarded: boolean,\n ): Promise<CommandResult<AllSuccessTypes, EthErrorCodes>> {\n switch (filter.type) {\n case \"datetime\":\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.Datetime,\n discarded,\n displayName: filter.displayName,\n signature: filter.signature,\n }),\n );\n case \"raw\":\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.Raw,\n discarded,\n displayName: filter.displayName,\n signature: filter.signature,\n }),\n );\n case \"token\":\n this.sanitizeDeviceIndex(filter.tokenIndex, deviceIndexes);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.Token,\n discarded,\n tokenIndex: deviceIndexes.indexes[filter.tokenIndex]!,\n signature: filter.signature,\n }),\n );\n case \"amount\":\n this.sanitizeDeviceIndex(filter.tokenIndex, deviceIndexes);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.Amount,\n discarded,\n displayName: filter.displayName,\n tokenIndex: deviceIndexes.indexes[filter.tokenIndex]!,\n signature: filter.signature,\n }),\n );\n default:\n return CommandResultFactory<AllSuccessTypes, EthErrorCodes>({\n error: new InvalidStatusWordError(\n \"ProvideEIP712ContextTask/provideFiltering - Unhandled filter type\",\n ),\n });\n }\n }\n\n private sanitizeDeviceIndex(\n descriptorIndex: number,\n deviceIndexes: DeviceAssetIndexes,\n ) {\n // If a token is missing, the device will replace it with a placeholder and use the next available index\n if (deviceIndexes.indexes[descriptorIndex] === undefined) {\n deviceIndexes.indexes[descriptorIndex] = deviceIndexes.nextIndex;\n deviceIndexes.nextIndex =\n (deviceIndexes.nextIndex + 1) % DEVICE_ASSETS_MAX;\n }\n }\n}\n"],
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,8BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAKO,
|
|
6
|
-
"names": ["ProvideEIP712ContextTask_exports", "__export", "ProvideEIP712ContextTask", "__toCommonJS", "import_context_module", "import_device_management_kit", "import_purify_ts", "import_ProvideTokenInformationCommand", "import_SendEIP712FilteringCommand", "import_SendEIP712StructDefinitionCommand", "import_SendEIP712StructImplemCommand", "import_SendEIP712StructImplemTask", "import_Types", "DEVICE_ASSETS_MAX", "api", "args", "result", "types", "aKey", "bKey", "structName", "fields", "structNameResult", "fieldName", "fieldType", "fieldResult", "activationResult", "value", "domainImplResult", "clearSignContext", "messageInfoFilterResult", "deviceIndexes", "maybeError", "maybeFilterResult", "messageImplResult", "discardedFilters", "path", "filter", "discardedPathResult", "provideFilteringResult", "descriptorIndex", "token", "provideTokenInfoResult", "deviceIndex", "filteringResult", "discarded"]
|
|
4
|
+
"sourcesContent": ["import {\n type TypedDataClearSignContextSuccess,\n type TypedDataFilter,\n type TypedDataTokenIndex,\n VERIFYING_CONTRACT_TOKEN_INDEX,\n} from \"@ledgerhq/context-module\";\nimport {\n type ClearSignContextSuccess,\n type ClearSignContextType,\n} from \"@ledgerhq/context-module\";\nimport type {\n CommandResult,\n InternalApi,\n} from \"@ledgerhq/device-management-kit\";\nimport {\n CommandResultFactory,\n InvalidStatusWordError,\n isSuccessCommandResult,\n LoadCertificateCommand,\n} from \"@ledgerhq/device-management-kit\";\nimport { Maybe, Nothing } from \"purify-ts\";\n\nimport { ProvideTokenInformationCommand } from \"@internal/app-binder/command/ProvideTokenInformationCommand\";\nimport { ProvideWeb3CheckCommand } from \"@internal/app-binder/command/ProvideWeb3CheckCommand\";\nimport {\n Eip712FilterType,\n SendEIP712FilteringCommand,\n} from \"@internal/app-binder/command/SendEIP712FilteringCommand\";\nimport {\n SendEIP712StructDefinitionCommand,\n StructDefinitionCommand,\n} from \"@internal/app-binder/command/SendEIP712StructDefinitionCommand\";\nimport { StructImplemType } from \"@internal/app-binder/command/SendEIP712StructImplemCommand\";\nimport { type EthErrorCodes } from \"@internal/app-binder/command/utils/ethAppErrors\";\nimport { SendEIP712StructImplemTask } from \"@internal/app-binder/task/SendEIP712StructImplemTask\";\nimport {\n type FieldName,\n type FieldType,\n type StructName,\n type TypedDataValue,\n TypedDataValueArray,\n TypedDataValueRoot,\n} from \"@internal/typed-data/model/Types\";\n\nimport { SendPayloadInChunksTask } from \"./SendPayloadInChunksTask\";\n\ntype AllSuccessTypes = void | { tokenIndex: number };\n\nexport type ProvideEIP712ContextTaskReturnType = Promise<\n CommandResult<AllSuccessTypes, EthErrorCodes>\n>;\n\nexport type ProvideEIP712ContextTaskArgs = {\n types: Record<StructName, Record<FieldName, FieldType>>;\n domain: Array<TypedDataValue>;\n message: Array<TypedDataValue>;\n clearSignContext: Maybe<TypedDataClearSignContextSuccess>;\n domainHash: string;\n messageHash: string;\n web3Check: ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK> | null;\n};\n\nconst DEVICE_ASSETS_MAX = 5;\n\ntype DeviceAssetIndexes = {\n indexes: Record<TypedDataTokenIndex, number>;\n nextIndex: number;\n};\n\nexport class ProvideEIP712ContextTask {\n constructor(\n private api: InternalApi,\n private args: ProvideEIP712ContextTaskArgs,\n ) {}\n\n async run(): ProvideEIP712ContextTaskReturnType {\n // Send message simulation first\n if (this.args.web3Check) {\n if (this.args.web3Check.certificate) {\n await this.api.sendCommand(\n new LoadCertificateCommand({\n keyUsage: this.args.web3Check.certificate.keyUsageNumber,\n certificate: this.args.web3Check.certificate.payload,\n }),\n );\n }\n await new SendPayloadInChunksTask(this.api, {\n payload: this.args.web3Check.payload,\n commandFactory: (args) =>\n new ProvideWeb3CheckCommand({\n payload: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n }\n\n const result: CommandResult<AllSuccessTypes, EthErrorCodes> =\n CommandResultFactory<AllSuccessTypes, EthErrorCodes>({ data: undefined });\n\n // Provide the structure definitions.\n // Should be sent before struct implementations, as described here:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#eip712-send-struct-definition\n // Note that those types are used to compute the schema hash, in the device and in ClearSignContexts, as described here:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#eip712-filtering\n // Therefore it should be normalized on both sides: sorted per keys\n const types = Object.entries(this.args.types).sort(([aKey], [bKey]) =>\n aKey.localeCompare(bKey),\n );\n for (const [structName, fields] of types) {\n const structNameResult = await this.api.sendCommand(\n new SendEIP712StructDefinitionCommand({\n command: StructDefinitionCommand.Name,\n name: structName,\n }),\n );\n if (!isSuccessCommandResult(structNameResult)) {\n return structNameResult;\n }\n\n for (const [fieldName, fieldType] of Object.entries(fields)) {\n const fieldResult = await this.api.sendCommand(\n new SendEIP712StructDefinitionCommand({\n command: StructDefinitionCommand.Field,\n name: fieldName,\n type: fieldType,\n }),\n );\n if (!isSuccessCommandResult(fieldResult)) {\n return fieldResult;\n }\n }\n }\n\n // possibly activate the filtering, before sending domain and message implementations, as described here:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#activation\n if (this.args.clearSignContext.isJust()) {\n const activationResult = await this.api.sendCommand(\n new SendEIP712FilteringCommand({ type: Eip712FilterType.Activation }),\n );\n if (!isSuccessCommandResult(activationResult)) {\n return activationResult;\n }\n }\n\n // send domain implementation values.\n for (const value of this.args.domain) {\n const domainImplTask = this.getImplementationTask(value);\n const domainImplResult = await domainImplTask.run();\n if (!isSuccessCommandResult(domainImplResult)) {\n return domainImplResult;\n }\n }\n\n // possibly send MessageInformation filter (between Domain and Message)\n // should be sent between Domain and Message implementations, as described here:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#message-info\n if (this.args.clearSignContext.isJust()) {\n const clearSignContext = this.args.clearSignContext.extract();\n const messageInfoFilterResult = await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.MessageInfo,\n displayName: clearSignContext.messageInfo.displayName,\n filtersCount: clearSignContext.messageInfo.filtersCount,\n signature: clearSignContext.messageInfo.signature,\n }),\n );\n if (!isSuccessCommandResult(messageInfoFilterResult)) {\n return messageInfoFilterResult;\n }\n }\n\n // send message implementation values\n const deviceIndexes: DeviceAssetIndexes = { indexes: {}, nextIndex: 0 };\n for (const value of this.args.message) {\n // 5.1 Provide token descriptors, if any\n // Keep a map of all device indexes for those provided tokens.\n const maybeError = await this.provideTokenInformation(\n value,\n deviceIndexes,\n );\n if (maybeError.isJust()) {\n return maybeError.extract();\n }\n\n // if there's a filter, send it\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#amount-join-token\n const maybeFilterResult = await this.filterValue(value, deviceIndexes);\n if (\n maybeFilterResult.isJust() &&\n !isSuccessCommandResult(maybeFilterResult.extract())\n ) {\n return maybeFilterResult.extract();\n }\n\n // provide message value implementation\n const messageImplTask = this.getImplementationTask(value);\n const messageImplResult = await messageImplTask.run();\n if (!isSuccessCommandResult(messageImplResult)) {\n return messageImplResult;\n }\n\n // if the value is an empty array, discard sub-filters since\n // there will be no according sub-values in the message\n if (\n this.args.clearSignContext.isJust() &&\n value.value instanceof TypedDataValueArray &&\n value.value.length === 0\n ) {\n const filters = Object.entries(\n this.args.clearSignContext.extract().filters,\n );\n const discardedFilters = filters\n .filter(([path]) => path.startsWith(`${value.path}.[]`))\n .map(([, filter]) => filter);\n for (const filter of discardedFilters) {\n const discardedPathResult = await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.DiscardedPath,\n path: filter.path,\n }),\n );\n if (!isSuccessCommandResult(discardedPathResult)) {\n return discardedPathResult;\n }\n\n const provideFilteringResult = await this.provideFiltering(\n filter,\n deviceIndexes,\n true,\n );\n if (!isSuccessCommandResult(provideFilteringResult)) {\n return provideFilteringResult;\n }\n }\n }\n }\n\n return result;\n }\n\n getImplementationTask(value: TypedDataValue): SendEIP712StructImplemTask {\n if (value.value instanceof TypedDataValueRoot) {\n return new SendEIP712StructImplemTask(this.api, {\n type: StructImplemType.ROOT,\n value: value.value.root,\n });\n } else if (value.value instanceof TypedDataValueArray) {\n return new SendEIP712StructImplemTask(this.api, {\n type: StructImplemType.ARRAY,\n value: value.value.length,\n });\n } else {\n return new SendEIP712StructImplemTask(this.api, {\n type: StructImplemType.FIELD,\n value: value.value.data,\n });\n }\n }\n\n async provideTokenInformation(\n value: TypedDataValue,\n deviceIndexes: DeviceAssetIndexes,\n ): Promise<Maybe<CommandResult<AllSuccessTypes, EthErrorCodes>>> {\n if (this.args.clearSignContext.isJust()) {\n const filter = this.args.clearSignContext.extract().filters[value.path];\n // tokens descriptors only needed when a tokenIndex is available in filter.\n // it should be sent to the device only 1 time so deviceIndexes has to be checked.\n if (\n filter !== undefined &&\n (filter.type === \"amount\" || filter.type === \"token\") &&\n deviceIndexes.indexes[filter.tokenIndex] === undefined\n ) {\n const descriptorIndex = filter.tokenIndex;\n const tokens = this.args.clearSignContext.extract().tokens;\n const token = tokens[descriptorIndex];\n if (token === undefined) {\n return Nothing;\n }\n\n const provideTokenInfoResult = await this.api.sendCommand(\n new ProvideTokenInformationCommand({ payload: token }),\n );\n if (!isSuccessCommandResult(provideTokenInfoResult)) {\n return Maybe.of(provideTokenInfoResult);\n }\n let { tokenIndex: deviceIndex } = provideTokenInfoResult.data;\n deviceIndexes.nextIndex = (deviceIndex + 1) % DEVICE_ASSETS_MAX;\n\n // the token corresponding to the Verifying Contract of message domain has a special index value, as described here:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#amount-join-value\n if (Number(descriptorIndex) === VERIFYING_CONTRACT_TOKEN_INDEX) {\n deviceIndex = VERIFYING_CONTRACT_TOKEN_INDEX;\n }\n\n deviceIndexes.indexes[Number(descriptorIndex)] = deviceIndex;\n }\n }\n return Nothing;\n }\n\n async filterValue(\n value: TypedDataValue,\n deviceIndexes: DeviceAssetIndexes,\n ): Promise<Maybe<CommandResult<AllSuccessTypes, EthErrorCodes>>> {\n if (this.args.clearSignContext.isJust()) {\n const filter = this.args.clearSignContext.extract().filters[value.path];\n if (filter === undefined) {\n return Nothing;\n }\n // provide the filter\n const filteringResult = await this.provideFiltering(\n filter,\n deviceIndexes,\n false,\n );\n return Maybe.of(filteringResult);\n }\n return Nothing;\n }\n\n async provideFiltering(\n filter: TypedDataFilter,\n deviceIndexes: DeviceAssetIndexes,\n discarded: boolean,\n ): Promise<CommandResult<AllSuccessTypes, EthErrorCodes>> {\n switch (filter.type) {\n case \"datetime\":\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.Datetime,\n discarded,\n displayName: filter.displayName,\n signature: filter.signature,\n }),\n );\n case \"raw\":\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.Raw,\n discarded,\n displayName: filter.displayName,\n signature: filter.signature,\n }),\n );\n case \"token\":\n this.sanitizeDeviceIndex(filter.tokenIndex, deviceIndexes);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.Token,\n discarded,\n tokenIndex: deviceIndexes.indexes[filter.tokenIndex]!,\n signature: filter.signature,\n }),\n );\n case \"amount\":\n this.sanitizeDeviceIndex(filter.tokenIndex, deviceIndexes);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.Amount,\n discarded,\n displayName: filter.displayName,\n tokenIndex: deviceIndexes.indexes[filter.tokenIndex]!,\n signature: filter.signature,\n }),\n );\n default:\n return CommandResultFactory<AllSuccessTypes, EthErrorCodes>({\n error: new InvalidStatusWordError(\n \"ProvideEIP712ContextTask/provideFiltering - Unhandled filter type\",\n ),\n });\n }\n }\n\n private sanitizeDeviceIndex(\n descriptorIndex: number,\n deviceIndexes: DeviceAssetIndexes,\n ) {\n // If a token is missing, the device will replace it with a placeholder and use the next available index\n if (deviceIndexes.indexes[descriptorIndex] === undefined) {\n deviceIndexes.indexes[descriptorIndex] = deviceIndexes.nextIndex;\n deviceIndexes.nextIndex =\n (deviceIndexes.nextIndex + 1) % DEVICE_ASSETS_MAX;\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,8BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAKO,oCASPC,EAKO,2CACPC,EAA+B,qBAE/BC,EAA+C,uEAC/CC,EAAwC,gEACxCC,EAGO,mEACPC,EAGO,0EACPC,EAAiC,sEAEjCC,EAA2C,gEAC3CC,EAOO,4CAEPC,EAAwC,qCAkBxC,MAAMC,EAAoB,EAOnB,MAAMb,CAAyB,CACpC,YACUc,EACAC,EACR,CAFQ,SAAAD,EACA,UAAAC,CACP,CAEH,MAAM,KAA0C,CAE1C,KAAK,KAAK,YACR,KAAK,KAAK,UAAU,aACtB,MAAM,KAAK,IAAI,YACb,IAAI,yBAAuB,CACzB,SAAU,KAAK,KAAK,UAAU,YAAY,eAC1C,YAAa,KAAK,KAAK,UAAU,YAAY,OAC/C,CAAC,CACH,EAEF,MAAM,IAAI,0BAAwB,KAAK,IAAK,CAC1C,QAAS,KAAK,KAAK,UAAU,QAC7B,eAAiBA,GACf,IAAI,0BAAwB,CAC1B,QAASA,EAAK,YACd,aAAcA,EAAK,YACrB,CAAC,CACL,CAAC,EAAE,IAAI,GAGT,MAAMC,KACJ,wBAAqD,CAAE,KAAM,MAAU,CAAC,EAQpEC,EAAQ,OAAO,QAAQ,KAAK,KAAK,KAAK,EAAE,KAAK,CAAC,CAACC,CAAI,EAA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AO,MAAM,KAAK,IAAI,YACpB,IAAI,6BAA2B,CAC7B,KAAM,mBAAiB,SACvB,UAAAQ,EACA,YAAaR,EAAO,YACpB,UAAWA,EAAO,SACpB,CAAC,CACH,EACF,IAAK,MACH,OAAO,MAAM,KAAK,IAAI,YACpB,IAAI,6BAA2B,CAC7B,KAAM,mBAAiB,IACvB,UAAAQ,EACA,YAAaR,EAAO,YACpB,UAAWA,EAAO,SACpB,CAAC,CACH,EACF,IAAK,QACH,YAAK,oBAAoBA,EAAO,WAAYN,CAAa,EAClD,MAAM,KAAK,IAAI,YACpB,IAAI,6BAA2B,CAC7B,KAAM,mBAAiB,MACvB,UAAAc,EACA,WAAYd,EAAc,QAAQM,EAAO,UAAU,EACnD,UAAWA,EAAO,SACpB,CAAC,CACH,EACF,IAAK,SACH,YAAK,oBAAoBA,EAAO,WAAYN,CAAa,EAClD,MAAM,KAAK,IAAI,YACpB,IAAI,6BAA2B,CAC7B,KAAM,mBAAiB,OACvB,UAAAc,EACA,YAAaR,EAAO,YACpB,WAAYN,EAAc,QAAQM,EAAO,UAAU,EACnD,UAAWA,EAAO,SACpB,CAAC,CACH,EACF,QACE,SAAO,wBAAqD,CAC1D,MAAO,IAAI,yBACT,mEACF,CACF,CAAC,CACL,CACF,CAEQ,oBACNG,EACAT,EACA,CAEIA,EAAc,QAAQS,CAAe,IAAM,SAC7CT,EAAc,QAAQS,CAAe,EAAIT,EAAc,UACvDA,EAAc,WACXA,EAAc,UAAY,GAAKlB,EAEtC,CACF",
|
|
6
|
+
"names": ["ProvideEIP712ContextTask_exports", "__export", "ProvideEIP712ContextTask", "__toCommonJS", "import_context_module", "import_device_management_kit", "import_purify_ts", "import_ProvideTokenInformationCommand", "import_ProvideWeb3CheckCommand", "import_SendEIP712FilteringCommand", "import_SendEIP712StructDefinitionCommand", "import_SendEIP712StructImplemCommand", "import_SendEIP712StructImplemTask", "import_Types", "import_SendPayloadInChunksTask", "DEVICE_ASSETS_MAX", "api", "args", "result", "types", "aKey", "bKey", "structName", "fields", "structNameResult", "fieldName", "fieldType", "fieldResult", "activationResult", "value", "domainImplResult", "clearSignContext", "messageInfoFilterResult", "deviceIndexes", "maybeError", "maybeFilterResult", "messageImplResult", "discardedFilters", "path", "filter", "discardedPathResult", "provideFilteringResult", "descriptorIndex", "token", "provideTokenInfoResult", "deviceIndex", "filteringResult", "discarded"]
|
|
7
7
|
}
|