@ledgerhq/device-signer-kit-ethereum 0.0.0-multisig-20250918154034 → 0.0.0-multisig-2-20250922093851
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/internal/app-binder/task/BuildBaseContexts.js +1 -1
- package/lib/cjs/internal/app-binder/task/BuildBaseContexts.js.map +3 -3
- package/lib/cjs/internal/app-binder/task/BuildBaseContexts.test.js +1 -1
- package/lib/cjs/internal/app-binder/task/BuildBaseContexts.test.js.map +2 -2
- package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.js +1 -1
- package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.js.map +3 -3
- package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.test.js +1 -1
- package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.test.js.map +2 -2
- package/lib/cjs/internal/app-binder/task/ProvideContextsTask.js +1 -1
- package/lib/cjs/internal/app-binder/task/ProvideContextsTask.js.map +2 -2
- package/lib/cjs/internal/app-binder/task/ProvideContextsTask.test.js +1 -1
- package/lib/cjs/internal/app-binder/task/ProvideContextsTask.test.js.map +2 -2
- package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.js +1 -1
- package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.js.map +2 -2
- package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.test.js +1 -1
- package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.test.js.map +2 -2
- package/lib/esm/internal/app-binder/task/BuildBaseContexts.js +1 -1
- package/lib/esm/internal/app-binder/task/BuildBaseContexts.js.map +3 -3
- package/lib/esm/internal/app-binder/task/BuildBaseContexts.test.js +1 -1
- package/lib/esm/internal/app-binder/task/BuildBaseContexts.test.js.map +2 -2
- package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.js +1 -1
- package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.js.map +3 -3
- package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.test.js +1 -1
- package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.test.js.map +3 -3
- package/lib/esm/internal/app-binder/task/ProvideContextsTask.js +1 -1
- package/lib/esm/internal/app-binder/task/ProvideContextsTask.js.map +2 -2
- package/lib/esm/internal/app-binder/task/ProvideContextsTask.test.js +1 -1
- package/lib/esm/internal/app-binder/task/ProvideContextsTask.test.js.map +2 -2
- package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.js +1 -1
- package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.js.map +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 +2 -2
- package/lib/types/internal/app-binder/task/BuildBaseContexts.d.ts +14 -1
- package/lib/types/internal/app-binder/task/BuildBaseContexts.d.ts.map +1 -1
- package/lib/types/internal/app-binder/task/BuildSubcontextsTask.d.ts.map +1 -1
- package/lib/types/internal/app-binder/task/ProvideEIP712ContextTask.d.ts.map +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +5 -5
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{ClearSignContextType as t}from"@ledgerhq/context-module";import{CommandResultFactory as g,DeviceModelId as l,DeviceSessionStateType as r,DeviceStatus as d,hexaStringToBuffer as h,UnknownDeviceExchangeError as m}from"@ledgerhq/device-management-kit";import{Transaction as v}from"ethers";import{ClearSigningType as u}from"../../../api/model/ClearSigningType";import{makeDeviceActionInternalApiMock as O}from"../../app-binder/device-action/__test-utils__/makeInternalApi";import{BuildBaseContexts as s}from"./BuildBaseContexts";import{GetWeb3CheckTask as T}from"./GetWeb3CheckTask";describe("BuildBaseContexts",()=>{const i={getFieldContext:vi.fn(),getContexts:vi.fn(),getTypedDataFilters:vi.fn(),getWeb3Checks:vi.fn(),getSolanaContext:vi.fn()},x={domain:"domain-name.eth"},y=h(v.from({chainId:1n,nonce:0,data:"0x"}).unsignedSerialized),p={keyUsageNumber:1,payload:new Uint8Array([1,2,3])};let o;const n=O(),c=vi.fn();function S(e){return{blindSigningEnabled:!1,web3ChecksEnabled:e,web3ChecksOptIn:!1,version:"1.13.0"}}beforeEach(()=>{vi.resetAllMocks(),n.sendCommand.mockResolvedValue(g({data:{challenge:"challenge"}})),c.mockReturnValue({run:async()=>Promise.resolve({web3Check:null})}),o={contextModule:i,subset:{chainId:1,to:void 0,data:"0x",selector:"0x"},transaction:y,options:x,appConfig:S(!1),derivationPath:"44'/60'/0'/0/0"}}),it("should init with a default GetWeb3CheckTaskFactory",()=>{const e=new s(n,o);expect(e.getWeb3ChecksFactory).toBeDefined(),expect(e.getWeb3ChecksFactory(n,{contextModule:o.contextModule,derivationPath:o.derivationPath,subset:o.subset,transaction:o.transaction})).toBeInstanceOf(T)}),it("should build the transaction context without clear sign contexts",async()=>{const e=[],a=[];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const C=await new s(n,{...o,appConfig:S(!0)},c).run();expect(C).toEqual({clearSignContexts:e,clearSignContextsOptional:a,clearSigningType:u.BASIC})}),it("should build the transaction context with web3checks",async()=>{const e=[],a=[],C="web3Check";c.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:C})}),i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const E=await new s(n,{...o,appConfig:S(!0)},c).run();expect(E).toEqual({clearSignContexts:[C,...e],clearSignContextsOptional:a,clearSigningType:u.BASIC})}),it("should build the transaction context with web3checks and generic-parser clear sign contexts",async()=>{const e=[{type:t.TRANSACTION_INFO,payload:"payload-1",certificate:p},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:t.ENUM,payload:"payload-3",id:1,value:2,certificate:p},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}],a="web3Check";c.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:a})}),i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const C=await new s(n,{...o,appConfig:S(!0)},c).run();expect(C).toEqual({clearSignContexts:[e[0],e[1],e[3],a],clearSignContextsOptional:[e[2]],clearSigningType:u.EIP7730})}),it("should build the transaction context with web3checks and generic-parser clear sign contexts in the correct order",async()=>{const e=[{type:t.ENUM,payload:"payload-3",id:1,value:2,certificate:p},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:t.TRANSACTION_INFO,payload:"payload-1",certificate:p}],a="web3Check";c.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:a})}),i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const C=await new s(n,{...o,appConfig:S(!0)},c).run();expect(C).toEqual({clearSignContexts:[e[3],e[1],e[2],a],clearSignContextsOptional:[e[0]],clearSigningType:u.EIP7730})}),it("should build the transaction context with clear sign contexts",async()=>{const e=[{type:t.TOKEN,payload:"payload-1"},{type:t.NFT,payload:"payload-2"}],a="web3Check";c.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:a})}),i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const C=await new s(n,o,c).run();expect(C).toEqual({clearSignContexts:e,clearSignContextsOptional:[],clearSigningType:u.BASIC})}),it("should build the transaction context with generic-parser context",async()=>{const e=[{type:t.TRANSACTION_INFO,payload:"payload-1",certificate:p},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:t.ENUM,payload:"payload-3",id:1,value:2,certificate:p},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[e[0],e[1],e[3]],clearSignContextsOptional:[e[2]],clearSigningType:u.EIP7730})}),it("should build the transaction context with proxy delegate call context",async()=>{const e=[{type:t.TRANSACTION_INFO,payload:"payload-1",certificate:p},{type:t.PROXY_DELEGATE_CALL,payload:"payload-2"}],a=[];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const C=await new s(n,o,c).run();expect(C).toEqual({clearSignContexts:[e[1],e[0]],clearSignContextsOptional:a,clearSigningType:u.EIP7730})}),it("should call the web3checks factory with correct parameters",async()=>{const e=[];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1}),await new s(n,{...o,appConfig:S(!0)},c).run(),expect(c).toHaveBeenCalledWith(n,{contextModule:i,derivationPath:"44'/60'/0'/0/0",subset:o.subset,transaction:y})}),it("should call the context module with the correct parameters",async()=>{const e=[];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1}),await new s(n,o,c).run(),expect(i.getContexts).toHaveBeenCalledWith({deviceModelId:l.FLEX,challenge:"challenge",domain:"domain-name.eth",...o.subset})}),it("should call the context module without challenge for Nano S",async()=>{const e=[];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.NANO_S,isSecureConnectionAllowed:!1}),await new s(n,o,c).run(),expect(i.getContexts).toHaveBeenCalledWith({deviceModelId:l.NANO_S,domain:"domain-name.eth",...o.subset})}),it("should call the context module without context on error",async()=>{const e=[];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1}),n.sendCommand.mockResolvedValueOnce(g({error:new m})),await new s(n,o,c).run(),expect(i.getContexts).toHaveBeenCalledWith({deviceModelId:l.FLEX,challenge:void 0,domain:"domain-name.eth",...o.subset})}),it("should exclude error contexts from the result",async()=>{const e=[{type:t.ERROR,error:new Error("error")},{type:t.TOKEN,payload:"payload-1"},{type:t.ERROR,error:new Error("error")},{type:t.NFT,payload:"payload-2"}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:u.BASIC})}),it("should exclude generic-parser contexts from the result on old apps",async()=>{const e=[{type:t.TRANSACTION_INFO,payload:"transaction_info",certificate:p},{type:t.TOKEN,payload:"payload-1"},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:t.NFT,payload:"payload-2"},{type:t.ENUM,payload:"enum",id:1,value:2,certificate:p}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:u.BASIC})}),it("should exclude generic-parser contexts from the result if no transaction_info was found",async()=>{const e=[{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:t.TOKEN,payload:"payload-1"},{type:t.ENUM,payload:"enum",id:1,value:2},{type:t.NFT,payload:"payload-2"}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:u.BASIC})}),it("should exclude legacy contexts from the result for generic-parser transactions",async()=>{const e=[{type:t.TOKEN,payload:"payload-1"},{type:t.TRANSACTION_INFO,payload:"payload-2",certificate:p},{type:t.EXTERNAL_PLUGIN,payload:"payload-3"},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"},{type:t.ENUM,payload:"payload-5",id:1,value:2,certificate:p}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[e[4]],clearSigningType:u.EIP7730})}),it("should exclude generic-parser contexts with a nano s device",async()=>{const e=[{type:t.TOKEN,payload:"payload-1"},{type:t.TRANSACTION_INFO,payload:"payload-2",certificate:p},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:t.ENUM,payload:"payload-4",id:1,value:2,certificate:p}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:l.NANO_S,isSecureConnectionAllowed:!1});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:u.BASIC})}),it("should exclude generic-parser contexts with an old app version",async()=>{const e=[{type:t.TOKEN,payload:"payload-1"},{type:t.TRANSACTION_INFO,payload:"payload-2",certificate:p},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:t.ENUM,payload:"payload-4",id:1,value:2,certificate:p}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:u.BASIC})}),it("should exclude generic-parser contexts with a non ready device",async()=>{const e=[{type:t.TOKEN,payload:"payload-1"},{type:t.TRANSACTION_INFO,payload:"payload-2",certificate:p},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:t.ENUM,payload:"payload-4",id:1,value:2,certificate:p}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.Connected,deviceStatus:d.NOT_CONNECTED,deviceModelId:l.FLEX});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:u.BASIC})}),it("should return no clear sign context if the transaction info certificate is missing",async()=>{const e=[{type:t.TRANSACTION_INFO,payload:"payload-1"},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:t.ENUM,payload:"payload-3",id:1,value:2}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.17.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[],clearSignContextsOptional:[],clearSigningType:u.BASIC})}),it("should not return web3check if the transaction is undefined",async()=>{const e=[];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.17.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1}),await new s(n,{...o,transaction:void 0},c).run(),expect(c).not.toHaveBeenCalled()})});
|
|
1
|
+
import{ClearSignContextType as t}from"@ledgerhq/context-module";import{CommandResultFactory as g,DeviceModelId as l,DeviceSessionStateType as r,DeviceStatus as d,hexaStringToBuffer as h,UnknownDeviceExchangeError as m}from"@ledgerhq/device-management-kit";import{Transaction as O}from"ethers";import{ClearSigningType as u}from"../../../api/model/ClearSigningType";import{makeDeviceActionInternalApiMock as v}from"../../app-binder/device-action/__test-utils__/makeInternalApi";import{BuildBaseContexts as s}from"./BuildBaseContexts";import{GetWeb3CheckTask as N}from"./GetWeb3CheckTask";describe("BuildBaseContexts",()=>{const i={getFieldContext:vi.fn(),getContexts:vi.fn(),getTypedDataFilters:vi.fn(),getWeb3Checks:vi.fn(),getSolanaContext:vi.fn()},x={domain:"domain-name.eth"},y=h(O.from({chainId:1n,nonce:0,data:"0x"}).unsignedSerialized),p={keyUsageNumber:1,payload:new Uint8Array([1,2,3])};let o;const n=v(),c=vi.fn();function S(e){return{blindSigningEnabled:!1,web3ChecksEnabled:e,web3ChecksOptIn:!1,version:"1.13.0"}}beforeEach(()=>{vi.resetAllMocks(),n.sendCommand.mockResolvedValue(g({data:{challenge:"challenge"}})),c.mockReturnValue({run:async()=>Promise.resolve({web3Check:null})}),o={contextModule:i,subset:{chainId:1,to:void 0,data:"0x",selector:"0x"},transaction:y,options:x,appConfig:S(!1),derivationPath:"44'/60'/0'/0/0"}}),it("should init with a default GetWeb3CheckTaskFactory",()=>{const e=new s(n,o);expect(e.getWeb3ChecksFactory).toBeDefined(),expect(e.getWeb3ChecksFactory(n,{contextModule:o.contextModule,derivationPath:o.derivationPath,subset:o.subset,transaction:o.transaction})).toBeInstanceOf(N)}),it("should build the transaction context without clear sign contexts",async()=>{const e=[],a=[];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const C=await new s(n,{...o,appConfig:S(!0)},c).run();expect(C).toEqual({clearSignContexts:e,clearSignContextsOptional:a,clearSigningType:u.BASIC})}),it("should build the transaction context with web3checks",async()=>{const e=[],a=[],C={type:t.WEB3_CHECK,payload:"web3Check"};c.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:C})}),i.getContexts.mockResolvedValueOnce([...e]),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const E=await new s(n,{...o,appConfig:S(!0)},c).run();expect(E).toEqual({clearSignContexts:[C,...e],clearSignContextsOptional:a,clearSigningType:u.BASIC})}),it("should build the transaction context with web3checks and generic-parser clear sign contexts",async()=>{const e=[{type:t.TRANSACTION_INFO,payload:"payload-1",certificate:p},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:t.ENUM,payload:"payload-3",id:1,value:2,certificate:p},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}],a={type:t.WEB3_CHECK,payload:"web3Check"};c.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:a})}),i.getContexts.mockResolvedValueOnce([...e]),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const C=await new s(n,{...o,appConfig:S(!0)},c).run();expect(C).toEqual({clearSignContexts:[a,e[0],e[1],e[3]],clearSignContextsOptional:[e[2]],clearSigningType:u.EIP7730})}),it("should build the transaction context with web3checks and generic-parser clear sign contexts in the correct order",async()=>{const e=[{type:t.ENUM,payload:"payload-3",id:1,value:2,certificate:p},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:t.TRANSACTION_INFO,payload:"payload-1",certificate:p}],a={type:t.WEB3_CHECK,payload:"web3Check"};c.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:a})}),i.getContexts.mockResolvedValueOnce([...e]),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const C=await new s(n,{...o,appConfig:S(!0)},c).run();expect(C).toEqual({clearSignContexts:[a,e[3],e[1],e[2]],clearSignContextsOptional:[e[0]],clearSigningType:u.EIP7730})}),it("should build the transaction context with clear sign contexts",async()=>{const e=[{type:t.TOKEN,payload:"payload-1"},{type:t.NFT,payload:"payload-2"}],a={type:t.WEB3_CHECK,payload:"web3Check"};c.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:a})}),i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const C=await new s(n,o,c).run();expect(C).toEqual({clearSignContexts:e,clearSignContextsOptional:[],clearSigningType:u.BASIC})}),it("should build the transaction context with generic-parser context",async()=>{const e=[{type:t.TRANSACTION_INFO,payload:"payload-1",certificate:p},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:t.ENUM,payload:"payload-3",id:1,value:2,certificate:p},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[e[0],e[1],e[3]],clearSignContextsOptional:[e[2]],clearSigningType:u.EIP7730})}),it("should build the transaction context with proxy delegate call context",async()=>{const e=[{type:t.TRANSACTION_INFO,payload:"payload-1",certificate:p},{type:t.PROXY_INFO,payload:"payload-2"}],a=[];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const C=await new s(n,o,c).run();expect(C).toEqual({clearSignContexts:[e[1],e[0]],clearSignContextsOptional:a,clearSigningType:u.EIP7730})}),it("should call the web3checks factory with correct parameters",async()=>{const e=[];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1}),await new s(n,{...o,appConfig:S(!0)},c).run(),expect(c).toHaveBeenCalledWith(n,{contextModule:i,derivationPath:"44'/60'/0'/0/0",subset:o.subset,transaction:y})}),it("should call the context module with the correct parameters",async()=>{const e=[];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1}),await new s(n,o,c).run(),expect(i.getContexts).toHaveBeenCalledWith({deviceModelId:l.FLEX,challenge:"challenge",domain:"domain-name.eth",...o.subset})}),it("should call the context module without challenge for Nano S",async()=>{const e=[];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.NANO_S,isSecureConnectionAllowed:!1}),await new s(n,o,c).run(),expect(i.getContexts).toHaveBeenCalledWith({deviceModelId:l.NANO_S,domain:"domain-name.eth",...o.subset})}),it("should call the context module without context on error",async()=>{const e=[];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1}),n.sendCommand.mockResolvedValueOnce(g({error:new m})),await new s(n,o,c).run(),expect(i.getContexts).toHaveBeenCalledWith({deviceModelId:l.FLEX,challenge:void 0,domain:"domain-name.eth",...o.subset})}),it("should exclude error contexts from the result",async()=>{const e=[{type:t.ERROR,error:new Error("error")},{type:t.TOKEN,payload:"payload-1"},{type:t.ERROR,error:new Error("error")},{type:t.NFT,payload:"payload-2"}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:u.BASIC})}),it("should exclude generic-parser contexts from the result on old apps",async()=>{const e=[{type:t.TRANSACTION_INFO,payload:"transaction_info",certificate:p},{type:t.TOKEN,payload:"payload-1"},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:t.NFT,payload:"payload-2"},{type:t.ENUM,payload:"enum",id:1,value:2,certificate:p}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:u.BASIC})}),it("should exclude generic-parser contexts from the result if no transaction_info was found",async()=>{const e=[{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:t.TOKEN,payload:"payload-1"},{type:t.ENUM,payload:"enum",id:1,value:2},{type:t.NFT,payload:"payload-2"}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:u.BASIC})}),it("should exclude legacy contexts from the result for generic-parser transactions",async()=>{const e=[{type:t.TOKEN,payload:"payload-1"},{type:t.TRANSACTION_INFO,payload:"payload-2",certificate:p},{type:t.EXTERNAL_PLUGIN,payload:"payload-3"},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"},{type:t.ENUM,payload:"payload-5",id:1,value:2,certificate:p}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[e[4]],clearSigningType:u.EIP7730})}),it("should exclude generic-parser contexts with a nano s device",async()=>{const e=[{type:t.TOKEN,payload:"payload-1"},{type:t.TRANSACTION_INFO,payload:"payload-2",certificate:p},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:t.ENUM,payload:"payload-4",id:1,value:2,certificate:p}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:l.NANO_S,isSecureConnectionAllowed:!1});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:u.BASIC})}),it("should exclude generic-parser contexts with an old app version",async()=>{const e=[{type:t.TOKEN,payload:"payload-1"},{type:t.TRANSACTION_INFO,payload:"payload-2",certificate:p},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:t.ENUM,payload:"payload-4",id:1,value:2,certificate:p}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:u.BASIC})}),it("should exclude generic-parser contexts with a non ready device",async()=>{const e=[{type:t.TOKEN,payload:"payload-1"},{type:t.TRANSACTION_INFO,payload:"payload-2",certificate:p},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:t.ENUM,payload:"payload-4",id:1,value:2,certificate:p}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.Connected,deviceStatus:d.NOT_CONNECTED,deviceModelId:l.FLEX});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:u.BASIC})}),it("should return no clear sign context if the transaction info certificate is missing",async()=>{const e=[{type:t.TRANSACTION_INFO,payload:"payload-1"},{type:t.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:t.ENUM,payload:"payload-3",id:1,value:2}];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.17.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1});const a=await new s(n,o,c).run();expect(a).toEqual({clearSignContexts:[],clearSignContextsOptional:[],clearSigningType:u.BASIC})}),it("should not return web3check if the transaction is undefined",async()=>{const e=[];i.getContexts.mockResolvedValueOnce(e),n.getDeviceSessionState.mockReturnValueOnce({sessionStateType:r.ReadyWithoutSecureChannel,deviceStatus:d.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.17.0"},deviceModelId:l.FLEX,isSecureConnectionAllowed:!1}),await new s(n,{...o,transaction:void 0},c).run(),expect(c).not.toHaveBeenCalled()})});
|
|
2
2
|
//# sourceMappingURL=BuildBaseContexts.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/app-binder/task/BuildBaseContexts.test.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n type ClearSignContext,\n type ClearSignContextSuccess,\n ClearSignContextType,\n type PkiCertificate,\n} from \"@ledgerhq/context-module\";\nimport {\n CommandResultFactory,\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n hexaStringToBuffer,\n UnknownDeviceExchangeError,\n} from \"@ledgerhq/device-management-kit\";\nimport { Transaction } from \"ethers\";\n\nimport type { GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\nimport { ClearSigningType } from \"@api/model/ClearSigningType\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\n\nimport {\n BuildBaseContexts,\n type BuildBaseContextsArgs,\n} from \"./BuildBaseContexts\";\nimport { GetWeb3CheckTask } from \"./GetWeb3CheckTask\";\n\ndescribe(\"BuildBaseContexts\", () => {\n const contextModuleMock = {\n getFieldContext: vi.fn(),\n getContexts: vi.fn(),\n getTypedDataFilters: vi.fn(),\n getWeb3Checks: vi.fn(),\n getSolanaContext: vi.fn(),\n };\n const defaultOptions = {\n domain: \"domain-name.eth\",\n };\n const defaultTransaction: Uint8Array = hexaStringToBuffer(\n Transaction.from({\n chainId: 1n,\n nonce: 0,\n data: \"0x\",\n }).unsignedSerialized,\n )!;\n const defaultCertificate: PkiCertificate = {\n keyUsageNumber: 1,\n payload: new Uint8Array([0x01, 0x02, 0x03]),\n };\n\n let defaultArgs: BuildBaseContextsArgs;\n const apiMock = makeDeviceActionInternalApiMock();\n const getWeb3ChecksFactoryMock = vi.fn();\n\n function createAppConfig(\n web3ChecksEnabled: boolean,\n ): GetConfigCommandResponse {\n return {\n blindSigningEnabled: false,\n web3ChecksEnabled,\n web3ChecksOptIn: false,\n version: \"1.13.0\",\n };\n }\n\n beforeEach(() => {\n vi.resetAllMocks();\n apiMock.sendCommand.mockResolvedValue(\n CommandResultFactory({ data: { challenge: \"challenge\" } }),\n );\n getWeb3ChecksFactoryMock.mockReturnValue({\n run: async () => Promise.resolve({ web3Check: null }),\n });\n\n defaultArgs = {\n contextModule: contextModuleMock,\n subset: { chainId: 1, to: undefined, data: \"0x\", selector: \"0x\" },\n transaction: defaultTransaction,\n options: defaultOptions,\n appConfig: createAppConfig(false),\n derivationPath: \"44'/60'/0'/0/0\",\n };\n });\n\n it(\"should init with a default GetWeb3CheckTaskFactory\", () => {\n // GIVEN\n const task = new BuildBaseContexts(apiMock, defaultArgs);\n\n // THEN\n expect(task[\"getWeb3ChecksFactory\"]).toBeDefined();\n expect(\n task[\"getWeb3ChecksFactory\"](apiMock, {\n contextModule: defaultArgs.contextModule,\n derivationPath: defaultArgs.derivationPath,\n subset: defaultArgs.subset,\n transaction: defaultArgs.transaction!,\n }),\n ).toBeInstanceOf(GetWeb3CheckTask);\n });\n\n it(\"should build the transaction context without clear sign contexts\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n const clearSignContextsOptional: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n clearSignContextsOptional,\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should build the transaction context with web3checks\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n const clearSignContextsOptional: ClearSignContext[] = [];\n const expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [expectedWeb3Check, ...clearSignContexts],\n clearSignContextsOptional,\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should build the transaction context with web3checks and generic-parser clear sign contexts\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n ];\n const expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [\n clearSignContexts[0],\n clearSignContexts[1],\n clearSignContexts[3],\n expectedWeb3Check,\n ],\n clearSignContextsOptional: [clearSignContexts[2]],\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should build the transaction context with web3checks and generic-parser clear sign contexts in the correct order\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n ];\n const expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [\n clearSignContexts[3], // transaction info\n clearSignContexts[1], // transaction field description\n clearSignContexts[2], // transaction field description\n expectedWeb3Check, // web3 check\n ],\n clearSignContextsOptional: [clearSignContexts[0]], // enum\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should build the transaction context with clear sign contexts\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n const expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should build the transaction context with generic-parser context\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [\n clearSignContexts[0],\n clearSignContexts[1],\n clearSignContexts[3],\n ],\n clearSignContextsOptional: [clearSignContexts[2]],\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should build the transaction context with proxy delegate call context\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.PROXY_DELEGATE_CALL,\n payload: \"payload-2\",\n },\n ];\n const clearSignContextsOptional: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[0]],\n clearSignContextsOptional,\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should call the web3checks factory with correct parameters\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(getWeb3ChecksFactoryMock).toHaveBeenCalledWith(apiMock, {\n contextModule: contextModuleMock,\n derivationPath: \"44'/60'/0'/0/0\",\n subset: defaultArgs.subset,\n transaction: defaultTransaction,\n });\n });\n\n it(\"should call the context module with the correct parameters\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.FLEX,\n challenge: \"challenge\",\n domain: \"domain-name.eth\",\n ...defaultArgs.subset,\n });\n });\n\n it(\"should call the context module without challenge for Nano S\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.NANO_S,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.NANO_S,\n domain: \"domain-name.eth\",\n ...defaultArgs.subset,\n });\n });\n\n it(\"should call the context module without context on error\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ error: new UnknownDeviceExchangeError() }),\n );\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.FLEX,\n challenge: undefined,\n domain: \"domain-name.eth\",\n ...defaultArgs.subset,\n });\n });\n\n it(\"should exclude error contexts from the result\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result on old apps\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"transaction_info\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"transaction_field\",\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"enum\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result if no transaction_info was found\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"transaction_field\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"enum\",\n id: 1,\n value: 2,\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.14.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude legacy contexts from the result for generic-parser transactions\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-5\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [clearSignContexts[4]],\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should exclude generic-parser contexts with a nano s device\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.14.0\" },\n deviceModelId: DeviceModelId.NANO_S,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts with an old app version\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts with a non ready device\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.NOT_CONNECTED,\n deviceModelId: DeviceModelId.FLEX,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should return no clear sign context if the transaction info certificate is missing\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.17.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should not return web3check if the transaction is undefined\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.17.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, transaction: undefined },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(getWeb3ChecksFactoryMock).not.toHaveBeenCalled();\n });\n});\n"],
|
|
5
|
-
"mappings": "AAAA,OAGE,wBAAAA,MAEK,2BACP,OACE,wBAAAC,EACA,iBAAAC,EACA,0BAAAC,EACA,gBAAAC,EACA,sBAAAC,EACA,8BAAAC,MACK,kCACP,OAAS,eAAAC,MAAmB,SAG5B,OAAS,oBAAAC,MAAwB,8BACjC,OAAS,mCAAAC,MAAuC,oEAEhD,OACE,qBAAAC,MAEK,sBACP,OAAS,oBAAAC,MAAwB,qBAEjC,SAAS,oBAAqB,IAAM,CAClC,MAAMC,EAAoB,CACxB,gBAAiB,GAAG,GAAG,EACvB,YAAa,GAAG,GAAG,EACnB,oBAAqB,GAAG,GAAG,EAC3B,cAAe,GAAG,GAAG,EACrB,iBAAkB,GAAG,GAAG,CAC1B,EACMC,EAAiB,CACrB,OAAQ,iBACV,EACMC,EAAiCT,EACrCE,EAAY,KAAK,CACf,QAAS,GACT,MAAO,EACP,KAAM,IACR,CAAC,EAAE,kBACL,EACMQ,EAAqC,CACzC,eAAgB,EAChB,QAAS,IAAI,WAAW,CAAC,EAAM,EAAM,CAAI,CAAC,CAC5C,EAEA,IAAIC,EACJ,MAAMC,EAAUR,EAAgC,EAC1CS,EAA2B,GAAG,GAAG,EAEvC,SAASC,EACPC,EAC0B,CAC1B,MAAO,CACL,oBAAqB,GACrB,kBAAAA,EACA,gBAAiB,GACjB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D,EAAa,YAAa,MAAU,EACzCE,CACF,EAAE,IAAI,EAGN,OAAOA,CAAwB,EAAE,IAAI,iBAAiB,CACxD,CAAC,CACH,CAAC",
|
|
4
|
+
"sourcesContent": ["import {\n type ClearSignContext,\n ClearSignContextType,\n type PkiCertificate,\n} from \"@ledgerhq/context-module\";\nimport {\n CommandResultFactory,\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n hexaStringToBuffer,\n UnknownDeviceExchangeError,\n} from \"@ledgerhq/device-management-kit\";\nimport { Transaction } from \"ethers\";\n\nimport type { GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\nimport { ClearSigningType } from \"@api/model/ClearSigningType\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\n\nimport {\n BuildBaseContexts,\n type BuildBaseContextsArgs,\n} from \"./BuildBaseContexts\";\nimport { GetWeb3CheckTask } from \"./GetWeb3CheckTask\";\n\ndescribe(\"BuildBaseContexts\", () => {\n const contextModuleMock = {\n getFieldContext: vi.fn(),\n getContexts: vi.fn(),\n getTypedDataFilters: vi.fn(),\n getWeb3Checks: vi.fn(),\n getSolanaContext: vi.fn(),\n };\n const defaultOptions = {\n domain: \"domain-name.eth\",\n };\n const defaultTransaction: Uint8Array = hexaStringToBuffer(\n Transaction.from({\n chainId: 1n,\n nonce: 0,\n data: \"0x\",\n }).unsignedSerialized,\n )!;\n const defaultCertificate: PkiCertificate = {\n keyUsageNumber: 1,\n payload: new Uint8Array([0x01, 0x02, 0x03]),\n };\n\n let defaultArgs: BuildBaseContextsArgs;\n const apiMock = makeDeviceActionInternalApiMock();\n const getWeb3ChecksFactoryMock = vi.fn();\n\n function createAppConfig(\n web3ChecksEnabled: boolean,\n ): GetConfigCommandResponse {\n return {\n blindSigningEnabled: false,\n web3ChecksEnabled,\n web3ChecksOptIn: false,\n version: \"1.13.0\",\n };\n }\n\n beforeEach(() => {\n vi.resetAllMocks();\n apiMock.sendCommand.mockResolvedValue(\n CommandResultFactory({ data: { challenge: \"challenge\" } }),\n );\n getWeb3ChecksFactoryMock.mockReturnValue({\n run: async () => Promise.resolve({ web3Check: null }),\n });\n\n defaultArgs = {\n contextModule: contextModuleMock,\n subset: { chainId: 1, to: undefined, data: \"0x\", selector: \"0x\" },\n transaction: defaultTransaction,\n options: defaultOptions,\n appConfig: createAppConfig(false),\n derivationPath: \"44'/60'/0'/0/0\",\n };\n });\n\n it(\"should init with a default GetWeb3CheckTaskFactory\", () => {\n // GIVEN\n const task = new BuildBaseContexts(apiMock, defaultArgs);\n\n // THEN\n expect(task[\"getWeb3ChecksFactory\"]).toBeDefined();\n expect(\n task[\"getWeb3ChecksFactory\"](apiMock, {\n contextModule: defaultArgs.contextModule,\n derivationPath: defaultArgs.derivationPath,\n subset: defaultArgs.subset,\n transaction: defaultArgs.transaction!,\n }),\n ).toBeInstanceOf(GetWeb3CheckTask);\n });\n\n it(\"should build the transaction context without clear sign contexts\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n const clearSignContextsOptional: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n clearSignContextsOptional,\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should build the transaction context with web3checks\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n const clearSignContextsOptional: ClearSignContext[] = [];\n const expectedWeb3Check = {\n type: ClearSignContextType.WEB3_CHECK,\n payload: \"web3Check\",\n };\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\n contextModuleMock.getContexts.mockResolvedValueOnce([...clearSignContexts]);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [expectedWeb3Check, ...clearSignContexts],\n clearSignContextsOptional,\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should build the transaction context with web3checks and generic-parser clear sign contexts\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n ];\n const expectedWeb3Check = {\n type: ClearSignContextType.WEB3_CHECK,\n payload: \"web3Check\",\n };\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\n contextModuleMock.getContexts.mockResolvedValueOnce([...clearSignContexts]);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [\n expectedWeb3Check,\n clearSignContexts[0],\n clearSignContexts[1],\n clearSignContexts[3],\n ],\n clearSignContextsOptional: [clearSignContexts[2]],\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should build the transaction context with web3checks and generic-parser clear sign contexts in the correct order\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n ];\n const expectedWeb3Check = {\n type: ClearSignContextType.WEB3_CHECK,\n payload: \"web3Check\",\n };\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\n contextModuleMock.getContexts.mockResolvedValueOnce([...clearSignContexts]);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [\n expectedWeb3Check, // web3 check\n clearSignContexts[3], // transaction info\n clearSignContexts[1], // transaction field description\n clearSignContexts[2], // transaction field description\n ],\n clearSignContextsOptional: [clearSignContexts[0]], // enum\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should build the transaction context with clear sign contexts\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n const expectedWeb3Check = {\n type: ClearSignContextType.WEB3_CHECK,\n payload: \"web3Check\",\n };\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => Promise.resolve({ web3Check: expectedWeb3Check }),\n });\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should build the transaction context with generic-parser context\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [\n clearSignContexts[0],\n clearSignContexts[1],\n clearSignContexts[3],\n ],\n clearSignContextsOptional: [clearSignContexts[2]],\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should build the transaction context with proxy delegate call context\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.PROXY_INFO,\n payload: \"payload-2\",\n },\n ];\n const clearSignContextsOptional: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[0]],\n clearSignContextsOptional,\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should call the web3checks factory with correct parameters\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(getWeb3ChecksFactoryMock).toHaveBeenCalledWith(apiMock, {\n contextModule: contextModuleMock,\n derivationPath: \"44'/60'/0'/0/0\",\n subset: defaultArgs.subset,\n transaction: defaultTransaction,\n });\n });\n\n it(\"should call the context module with the correct parameters\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.FLEX,\n challenge: \"challenge\",\n domain: \"domain-name.eth\",\n ...defaultArgs.subset,\n });\n });\n\n it(\"should call the context module without challenge for Nano S\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.NANO_S,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.NANO_S,\n domain: \"domain-name.eth\",\n ...defaultArgs.subset,\n });\n });\n\n it(\"should call the context module without context on error\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ error: new UnknownDeviceExchangeError() }),\n );\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.FLEX,\n challenge: undefined,\n domain: \"domain-name.eth\",\n ...defaultArgs.subset,\n });\n });\n\n it(\"should exclude error contexts from the result\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result on old apps\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"transaction_info\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"transaction_field\",\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"enum\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result if no transaction_info was found\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"transaction_field\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"enum\",\n id: 1,\n value: 2,\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.14.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude legacy contexts from the result for generic-parser transactions\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-5\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [clearSignContexts[4]],\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should exclude generic-parser contexts with a nano s device\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.14.0\" },\n deviceModelId: DeviceModelId.NANO_S,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts with an old app version\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts with a non ready device\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.NOT_CONNECTED,\n deviceModelId: DeviceModelId.FLEX,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should return no clear sign context if the transaction info certificate is missing\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.17.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should not return web3check if the transaction is undefined\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.17.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, transaction: undefined },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(getWeb3ChecksFactoryMock).not.toHaveBeenCalled();\n });\n});\n"],
|
|
5
|
+
"mappings": "AAAA,OAEE,wBAAA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AAC,CAAC,EACxC,0BAA2B,CAAC,EAC5B,iBAAkBd,EAAiB,KACrC,CAAC,CACH,CAAC,EAED,GAAG,qFAAsF,SAAY,CAEnG,MAAMc,EAAwC,CAC5C,CACE,KAAMtB,EAAqB,iBAC3B,QAAS,WACX,EACA,CACE,KAAMA,EAAqB,8BAC3B,QAAS,WACX,EACA,CACE,KAAMA,EAAqB,KAC3B,QAAS,YACT,GAAI,EACJ,MAAO,CACT,CACF,EACAY,EAAkB,YAAY,sBAAsBU,CAAiB,EACrEL,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkBd,EAAuB,0BACzC,aAAcC,EAAa,UAC3B,cAAe,CAAC,EAChB,WAAY,CAAE,KAAM,WAAY,QAAS,QAAS,EAClD,cAAeF,EAAc,KAC7B,0BAA2B,EAC7B,CAAC,EAGD,MAAMsB,EAAS,MAAM,IAAId,EACvBO,EACAD,EACAE,CACF,EAAE,IAAI,EAGN,OAAOM,CAAM,EAAE,QAAQ,CACrB,kBAAmB,CAAC,EACpB,0BAA2B,CAAC,EAC5B,iBAAkBhB,EAAiB,KACrC,CAAC,CACH,CAAC,EAED,GAAG,8DAA+D,SAAY,CAE5E,MAAMc,EAAwC,CAAC,EAC/CV,EAAkB,YAAY,sBAAsBU,CAAiB,EACrEL,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkBd,EAAuB,0BACzC,aAAcC,EAAa,UAC3B,cAAe,CAAC,EAChB,WAAY,CAAE,KAAM,WAAY,QAAS,QAAS,EAClD,cAAeF,EAAc,KAC7B,0BAA2B,EAC7B,CAAC,EAGD,MAAM,IAAIQ,EACRO,EACA,CAAE,GAAGD,EAAa,YAAa,MAAU,EACzCE,CACF,EAAE,IAAI,EAGN,OAAOA,CAAwB,EAAE,IAAI,iBAAiB,CACxD,CAAC,CACH,CAAC",
|
|
6
6
|
"names": ["ClearSignContextType", "CommandResultFactory", "DeviceModelId", "DeviceSessionStateType", "DeviceStatus", "hexaStringToBuffer", "UnknownDeviceExchangeError", "Transaction", "ClearSigningType", "makeDeviceActionInternalApiMock", "BuildBaseContexts", "GetWeb3CheckTask", "contextModuleMock", "defaultOptions", "defaultTransaction", "defaultCertificate", "defaultArgs", "apiMock", "getWeb3ChecksFactoryMock", "createAppConfig", "web3ChecksEnabled", "task", "clearSignContexts", "clearSignContextsOptional", "result", "expectedWeb3Check"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{ClearSignContextReferenceType as r,ClearSignContextType as
|
|
1
|
+
import{ClearSignContextReferenceType as r,ClearSignContextType as t}from"@ledgerhq/context-module";import{bufferToHexaString as i,isSuccessCommandResult as d}from"@ledgerhq/device-management-kit";import{GetChallengeCommand as x}from"../../app-binder/command/GetChallengeCommand";class h{constructor(e,n){this.api=e;this.args=n}run(){const e=this.args.context,n=e.type;switch(n){case t.TRANSACTION_INFO:case t.WEB3_CHECK:case t.PLUGIN:case t.EXTERNAL_PLUGIN:case t.DYNAMIC_NETWORK:case t.DYNAMIC_NETWORK_ICON:case t.ENUM:case t.TRUSTED_NAME:case t.TOKEN:case t.NFT:return{subcontextCallbacks:[]};case t.TRANSACTION_FIELD_DESCRIPTION:return{subcontextCallbacks:e.reference?this._getSubcontextsFromReference(e.reference):[]};case t.PROXY_INFO:return{subcontextCallbacks:this._getSubcontextFromProxy(e)};default:{const a=n;throw new Error(`Uncovered type: ${a}`)}}}_getSubcontextsFromReference(e){const n=e.type;switch(n){case r.TOKEN:case r.NFT:return this._getSubcontextsFromTokenOrNftReference(e);case r.ENUM:return this._getSubcontextsFromEnumReference(e);case r.TRUSTED_NAME:return this._getSubcontextsFromTrustedNameReference(e);case r.CALLDATA:return[];default:{const a=n;throw new Error(`Uncovered reference type: ${a}`)}}}_getSubcontextsFromTokenOrNftReference(e){if(e.value!==void 0){const a={chainId:this.args.subset.chainId,address:e.value},s=e.type===r.TOKEN?t.TOKEN:t.NFT;return[()=>this.args.contextModule.getFieldContext(a,s)]}const n=[];if(e.valuePath!==void 0){const a=this.args.transactionParser.extractValue(this.args.subset,e.valuePath).orDefault([]);for(const s of a){const o=i(s.slice(Math.max(0,s.length-20))),c=e.type===r.TOKEN?t.TOKEN:t.NFT;n.push(()=>this.args.contextModule.getFieldContext({chainId:this.args.subset.chainId,address:o},c))}}return n}_getSubcontextsFromEnumReference(e){const n=[];if(!e.valuePath)return n;const a=this.args.transactionParser.extractValue(this.args.subset,e.valuePath).orDefault([]);for(const s of a){const o=s[s.length-1];if(o===void 0)continue;const u=this.args.contextOptional.filter(l=>l.type===t.ENUM).find(l=>l.value===o&&l.id===e.id);u&&n.push(()=>Promise.resolve(u))}return n}_getSubcontextsFromTrustedNameReference(e){const n=[];if(!e.valuePath)return n;const a=this.args.transactionParser.extractValue(this.args.subset,e.valuePath).orDefault([]);for(const s of a)n.push(async()=>{const o=i(s.slice(Math.max(0,s.length-20))),c=await this.api.sendCommand(new x);return d(c)?await this.args.contextModule.getFieldContext({chainId:this.args.subset.chainId,address:o,challenge:c.data.challenge,types:e.types,sources:e.sources},t.TRUSTED_NAME):{type:t.ERROR,error:new Error("Failed to get challenge")}});return n}_getSubcontextFromProxy(e){return[async()=>{const n=await this.api.sendCommand(new x);return d(n)?this.args.subset.to===void 0?{type:t.ERROR,error:new Error("Failed to get proxy address")}:await this.args.contextModule.getFieldContext({chainId:this.args.subset.chainId,proxyAddress:this.args.subset.to,calldata:this.args.subset.data,deviceModelId:this.args.deviceModelId,challenge:n.data.challenge},t.PROXY_INFO):{type:t.ERROR,error:new Error("Failed to get challenge")}}]}}export{h as BuildSubcontextsTask};
|
|
2
2
|
//# sourceMappingURL=BuildSubcontextsTask.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/app-binder/task/BuildSubcontextsTask.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n type ClearSignContext,\n type ClearSignContextReference,\n ClearSignContextReferenceType,\n type ClearSignContextSuccess,\n ClearSignContextType,\n
|
|
5
|
-
"mappings": "AAAA,OAGE,iCAAAA,EAEA,wBAAAC,
|
|
6
|
-
"names": ["ClearSignContextReferenceType", "ClearSignContextType", "
|
|
4
|
+
"sourcesContent": ["import {\n type ClearSignContext,\n type ClearSignContextReference,\n ClearSignContextReferenceType,\n type ClearSignContextSuccess,\n ClearSignContextType,\n type ContextModule,\n type TransactionSubset,\n} from \"@ledgerhq/context-module\";\nimport {\n bufferToHexaString,\n type DeviceModelId,\n type InternalApi,\n isSuccessCommandResult,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { GetChallengeCommand } from \"@internal/app-binder/command/GetChallengeCommand\";\nimport { type TransactionParserService } from \"@internal/transaction/service/parser/TransactionParserService\";\n\nexport type BuildSubcontextsTaskArgs = {\n readonly context: ClearSignContextSuccess;\n readonly contextOptional: ClearSignContextSuccess[];\n readonly transactionParser: TransactionParserService;\n readonly subset: TransactionSubset;\n readonly deviceModelId: DeviceModelId;\n readonly contextModule: ContextModule;\n};\n\ntype SubcontextCallback = () => Promise<ClearSignContext>;\n\nexport type BuildSubcontextsTaskResult = {\n subcontextCallbacks: SubcontextCallback[];\n};\n\nexport class BuildSubcontextsTask {\n constructor(\n private readonly api: InternalApi,\n private readonly args: BuildSubcontextsTaskArgs,\n ) {}\n\n run(): BuildSubcontextsTaskResult {\n const context = this.args.context;\n const type = context.type;\n\n switch (type) {\n case ClearSignContextType.TRANSACTION_INFO:\n case ClearSignContextType.WEB3_CHECK:\n case ClearSignContextType.PLUGIN:\n case ClearSignContextType.EXTERNAL_PLUGIN:\n case ClearSignContextType.DYNAMIC_NETWORK:\n case ClearSignContextType.DYNAMIC_NETWORK_ICON:\n case ClearSignContextType.ENUM:\n case ClearSignContextType.TRUSTED_NAME:\n case ClearSignContextType.TOKEN:\n case ClearSignContextType.NFT:\n return {\n subcontextCallbacks: [],\n };\n case ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:\n return {\n subcontextCallbacks: context.reference\n ? this._getSubcontextsFromReference(context.reference)\n : [],\n };\n case ClearSignContextType.PROXY_INFO:\n return {\n subcontextCallbacks: this._getSubcontextFromProxy(context),\n };\n default: {\n const uncoveredType: never = type;\n throw new Error(`Uncovered type: ${uncoveredType}`);\n }\n }\n }\n\n private _getSubcontextsFromReference(\n reference: ClearSignContextReference,\n ): SubcontextCallback[] {\n const referenceType = reference.type;\n\n switch (referenceType) {\n case ClearSignContextReferenceType.TOKEN:\n case ClearSignContextReferenceType.NFT:\n return this._getSubcontextsFromTokenOrNftReference(reference);\n case ClearSignContextReferenceType.ENUM:\n return this._getSubcontextsFromEnumReference(reference);\n case ClearSignContextReferenceType.TRUSTED_NAME:\n return this._getSubcontextsFromTrustedNameReference(reference);\n case ClearSignContextReferenceType.CALLDATA:\n // calldata reference is handled by the BuildFullContextsTask and ParseNestedTransactionTask\n return [];\n default: {\n const uncoveredReferenceType: never = referenceType;\n throw new Error(`Uncovered reference type: ${uncoveredReferenceType}`);\n }\n }\n }\n\n private _getSubcontextsFromTokenOrNftReference(\n reference: ClearSignContextReference<\n ClearSignContextReferenceType.TOKEN | ClearSignContextReferenceType.NFT\n >,\n ): SubcontextCallback[] {\n // if the reference is a string, it means it is a direct address\n // and we don't need to extract the value from the transaction\n // as it is already provided in the reference\n if (reference.value !== undefined) {\n const transactionFieldContext = {\n chainId: this.args.subset.chainId,\n address: reference.value,\n };\n\n const expectedType =\n reference.type === ClearSignContextReferenceType.TOKEN\n ? ClearSignContextType.TOKEN\n : ClearSignContextType.NFT;\n\n return [\n () =>\n this.args.contextModule.getFieldContext(\n transactionFieldContext,\n expectedType,\n ),\n ];\n }\n\n const subcontextCallbacks: SubcontextCallback[] = [];\n\n // if the reference is a path, it means we need to extract the value\n // from the transaction and provide it to the device\n if (reference.valuePath !== undefined) {\n const referenceValues = this.args.transactionParser\n .extractValue(this.args.subset, reference.valuePath)\n .orDefault([]);\n\n for (const value of referenceValues) {\n const address = bufferToHexaString(\n value.slice(Math.max(0, value.length - 20)),\n );\n\n const expectedType =\n reference.type === ClearSignContextReferenceType.TOKEN\n ? ClearSignContextType.TOKEN\n : ClearSignContextType.NFT;\n\n subcontextCallbacks.push(() =>\n this.args.contextModule.getFieldContext(\n {\n chainId: this.args.subset.chainId,\n address,\n },\n expectedType,\n ),\n );\n }\n }\n\n return subcontextCallbacks;\n }\n\n private _getSubcontextsFromEnumReference(\n reference: ClearSignContextReference<ClearSignContextReferenceType.ENUM>,\n ): SubcontextCallback[] {\n const subcontextCallbacks: SubcontextCallback[] = [];\n\n if (!reference.valuePath) {\n return subcontextCallbacks;\n }\n\n const referenceValues = this.args.transactionParser\n .extractValue(this.args.subset, reference.valuePath)\n .orDefault([]);\n\n for (const value of referenceValues) {\n const enumValue = value[value.length - 1];\n if (enumValue === undefined) {\n continue;\n }\n\n const enumsContext = this.args.contextOptional.filter(\n (c) => c.type === ClearSignContextType.ENUM,\n );\n\n const subcontext = enumsContext.find(\n (enumContext) =>\n enumContext.value === enumValue && enumContext.id === reference.id,\n );\n\n if (subcontext) {\n subcontextCallbacks.push(() => Promise.resolve(subcontext));\n }\n }\n return subcontextCallbacks;\n }\n\n private _getSubcontextsFromTrustedNameReference(\n reference: ClearSignContextReference<ClearSignContextReferenceType.TRUSTED_NAME>,\n ): SubcontextCallback[] {\n const subcontextCallbacks: SubcontextCallback[] = [];\n\n if (!reference.valuePath) {\n return subcontextCallbacks;\n }\n\n const referenceValues = this.args.transactionParser\n .extractValue(this.args.subset, reference.valuePath)\n .orDefault([]);\n\n for (const value of referenceValues) {\n {\n subcontextCallbacks.push(async () => {\n const address = bufferToHexaString(\n value.slice(Math.max(0, value.length - 20)),\n );\n\n const getChallengeResult = await this.api.sendCommand(\n new GetChallengeCommand(),\n );\n if (!isSuccessCommandResult(getChallengeResult)) {\n return {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Failed to get challenge\"),\n };\n }\n\n const subcontext = await this.args.contextModule.getFieldContext(\n {\n chainId: this.args.subset.chainId,\n address,\n challenge: getChallengeResult.data.challenge,\n types: reference.types,\n sources: reference.sources,\n },\n ClearSignContextType.TRUSTED_NAME,\n );\n\n return subcontext;\n });\n }\n }\n\n return subcontextCallbacks;\n }\n\n private _getSubcontextFromProxy(\n _context: ClearSignContextSuccess<ClearSignContextType.PROXY_INFO>,\n ): SubcontextCallback[] {\n return [\n async () => {\n const getChallengeResult = await this.api.sendCommand(\n new GetChallengeCommand(),\n );\n if (!isSuccessCommandResult(getChallengeResult)) {\n return {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Failed to get challenge\"),\n };\n }\n\n if (this.args.subset.to === undefined) {\n return {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Failed to get proxy address\"),\n };\n }\n\n const subcontext = await this.args.contextModule.getFieldContext(\n {\n chainId: this.args.subset.chainId,\n proxyAddress: this.args.subset.to,\n calldata: this.args.subset.data,\n deviceModelId: this.args.deviceModelId,\n challenge: getChallengeResult.data.challenge,\n },\n ClearSignContextType.PROXY_INFO,\n );\n\n return subcontext;\n },\n ];\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAGE,iCAAAA,EAEA,wBAAAC,MAGK,2BACP,OACE,sBAAAC,EAGA,0BAAAC,MACK,kCAEP,OAAS,uBAAAC,MAA2B,mDAkB7B,MAAMC,CAAqB,CAChC,YACmBC,EACAC,EACjB,CAFiB,SAAAD,EACA,UAAAC,CAChB,CAEH,KAAkC,CAChC,MAAMC,EAAU,KAAK,KAAK,QACpBC,EAAOD,EAAQ,KAErB,OAAQC,EAAM,CACZ,KAAKR,EAAqB,iBAC1B,KAAKA,EAAqB,WAC1B,KAAKA,EAAqB,OAC1B,KAAKA,EAAqB,gBAC1B,KAAKA,EAAqB,gBAC1B,KAAKA,EAAqB,qBAC1B,KAAKA,EAAqB,KAC1B,KAAKA,EAAqB,aAC1B,KAAKA,EAAqB,MAC1B,KAAKA,EAAqB,IACxB,MAAO,CACL,oBAAqB,CAAC,CACxB,EACF,KAAKA,EAAqB,8BACxB,MAAO,CACL,oBAAqBO,EAAQ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KAAMA,EAAqB,MAC3B,MAAO,IAAI,MAAM,yBAAyB,CAC5C,CAeJ,CAAC,EAIL,OAAOe,CACT,CAEQ,wBACNS,EACsB,CACtB,MAAO,CACL,SAAY,CACV,MAAMD,EAAqB,MAAM,KAAK,IAAI,YACxC,IAAIpB,CACN,EACA,OAAKD,EAAuBqB,CAAkB,EAO1C,KAAK,KAAK,OAAO,KAAO,OACnB,CACL,KAAMvB,EAAqB,MAC3B,MAAO,IAAI,MAAM,6BAA6B,CAChD,EAGiB,MAAM,KAAK,KAAK,cAAc,gBAC/C,CACE,QAAS,KAAK,KAAK,OAAO,QAC1B,aAAc,KAAK,KAAK,OAAO,GAC/B,SAAU,KAAK,KAAK,OAAO,KAC3B,cAAe,KAAK,KAAK,cACzB,UAAWuB,EAAmB,KAAK,SACrC,EACAvB,EAAqB,UACvB,EAtBS,CACL,KAAMA,EAAqB,MAC3B,MAAO,IAAI,MAAM,yBAAyB,CAC5C,CAsBJ,CACF,CACF,CACF",
|
|
6
|
+
"names": ["ClearSignContextReferenceType", "ClearSignContextType", "bufferToHexaString", "isSuccessCommandResult", "GetChallengeCommand", "BuildSubcontextsTask", "api", "args", "context", "type", "uncoveredType", "reference", "referenceType", "uncoveredReferenceType", "transactionFieldContext", "expectedType", "subcontextCallbacks", "referenceValues", "value", "address", "enumValue", "subcontext", "c", "enumContext", "getChallengeResult", "_context"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{ClearSignContextReferenceType as d,ClearSignContextType as e,ContextFieldLoaderKind as C}from"@ledgerhq/context-module";import{CommandResultFactory as E,DeviceModelId as h,UnknownDeviceExchangeError as k}from"@ledgerhq/device-management-kit";import{Left as R,Right as y}from"purify-ts";import{GetChallengeCommand as T}from"../../app-binder/command/GetChallengeCommand";import{makeDeviceActionInternalApiMock as f}from"../../app-binder/device-action/__test-utils__/makeInternalApi";import{BuildSubcontextsTask as r}from"./BuildSubcontextsTask";describe("BuildSubcontextsTask",()=>{const x={getFieldContext:vi.fn()},p={extractValue:vi.fn()},o=f();let l;beforeEach(()=>{vi.resetAllMocks(),l={context:{type:e.TRANSACTION_INFO,payload:"test payload"},contextOptional:[],transactionParser:p,subset:{chainId:1,data:"0x",selector:"0x",to:"0x",value:BigInt(0)},contextModule:x,deviceModelId:h.STAX}}),describe("when context type is a simple type",()=>{const n=[e.TRANSACTION_INFO,e.WEB3_CHECK,e.PLUGIN,e.EXTERNAL_PLUGIN,e.DYNAMIC_NETWORK,e.DYNAMIC_NETWORK_ICON,e.ENUM,e.TRUSTED_NAME,e.TOKEN,e.NFT];it.each(n)("should return context with empty subcontextCallbacks for %s",t=>{const c={...l,context:{type:t,payload:"test payload"}},s=new r(o,c).run();expect(s.subcontextCallbacks).toHaveLength(0)})}),describe("when context has a direct value reference",()=>{it("should create a callback to get context with the direct value",async()=>{const n={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.TOKEN,value:"0x1234567890123456789012345678901234567890"}},t={...l,context:n},a={kind:C.TOKEN,chainId:1,address:"0x1234567890123456789012345678901234567890"},c=new r(o,t).run();expect(c.subcontextCallbacks).toHaveLength(1);const s=c.subcontextCallbacks[0];await s(),expect(x.getFieldContext).toHaveBeenCalledWith(a)}),it("should handle undefined value in reference",()=>{const n={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:void 0},t={...l,context:n},a=new r(o,t).run();expect(a.subcontextCallbacks).toHaveLength(0)})}),describe("when context has a valuePath reference",()=>{beforeEach(()=>{o.sendCommand.mockResolvedValue(E({data:{challenge:"test-challenge"}}))}),describe("when extractValue returns Left (error)",()=>{it("should return context with empty subcontextCallbacks",()=>{const n={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.TOKEN,valuePath:[{type:"SLICE",start:0,end:20}]}},t={...l,context:n};p.extractValue.mockReturnValue(R(new Error("Extraction failed")));const a=new r(o,t).run();expect(a.subcontextCallbacks).toHaveLength(0)})}),describe("when extractValue returns Right with values",()=>{describe("for ENUM type",()=>{it("should create callbacks for matching enum contexts",async()=>{const n={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.ENUM,id:1,valuePath:[{type:"TUPLE",offset:0}]}},t={type:e.ENUM,id:1,value:1,payload:"enum context 1"},a={type:e.ENUM,id:1,value:2,payload:"enum context 2"},c={type:e.ENUM,id:2,value:2,payload:"enum context 3"},s={...l,context:n,contextOptional:[t,a,c]},u=[new Uint8Array([1,2])];p.extractValue.mockReturnValue(y(u));const i=new r(o,s).run();expect(i.subcontextCallbacks).toHaveLength(1);const b=i.subcontextCallbacks[0],g=await b();expect(g).toEqual(a)}),it("should create callbacks for matching enum contexts with two values",async()=>{const n={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.ENUM,id:1,valuePath:[{type:"TUPLE",offset:0}]}},t={type:e.ENUM,id:1,value:1,payload:"enum context 1"},a={type:e.ENUM,id:1,value:2,payload:"enum context 2"},c={type:e.ENUM,id:2,value:2,payload:"enum context 3"},s={...l,context:n,contextOptional:[t,a,c]},u=[new Uint8Array([1,2]),new Uint8Array([3,2,1])];p.extractValue.mockReturnValue(y(u));const i=new r(o,s).run();expect(i.subcontextCallbacks).toHaveLength(2);const b=i.subcontextCallbacks[0],g=i.subcontextCallbacks[1],N=await b(),S=await g();expect(N).toEqual(a),expect(S).toEqual(t)}),it("should skip when enum value is undefined",()=>{const n={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.ENUM,id:1,valuePath:[{type:"TUPLE",offset:0}]}},t={...l,context:n},a=[new Uint8Array([])];p.extractValue.mockReturnValue(y(a));const c=new r(o,t).run();expect(c.subcontextCallbacks).toHaveLength(0)}),it("should create callback with enum id 0",async()=>{const n={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.ENUM,id:0,valuePath:[{type:"TUPLE",offset:0}]}},t={type:e.ENUM,id:0,value:0,payload:"enum context 1"},a={type:e.ENUM,id:1,value:1,payload:"enum context 2"},c={...l,context:n,contextOptional:[t,a]},s=[new Uint8Array([1,0])];p.extractValue.mockReturnValue(y(s));const u=new r(o,c).run();expect(u.subcontextCallbacks).toHaveLength(1);const i=u.subcontextCallbacks[0],b=await i();expect(b).toEqual(t)}),it("should skip when no matching enum context found",()=>{const n={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.ENUM,id:1,valuePath:[{type:"TUPLE",offset:0}]}},t={type:e.ENUM,id:2,value:2,payload:"enum context"},a={...l,context:n,contextOptional:[t]},c=[new Uint8Array([1,2])];p.extractValue.mockReturnValue(y(c));const s=new r(o,a).run();expect(s.subcontextCallbacks).toHaveLength(0)})}),describe("for TOKEN type",()=>{it("should create callbacks to get token context",async()=>{const n={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.TOKEN,valuePath:[{type:"TUPLE",offset:0}]}},t={...l,context:n},a=[new Uint8Array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22])];p.extractValue.mockReturnValue(y(a)),x.getFieldContext.mockResolvedValue({type:e.TOKEN,payload:"token result"});const c=new r(o,t).run();expect(c.subcontextCallbacks).toHaveLength(1);const s=c.subcontextCallbacks[0],u=await s();expect(u).toEqual({type:e.TOKEN,payload:"token result"}),expect(x.getFieldContext).toHaveBeenCalledWith({kind:C.TOKEN,chainId:1,address:"0x030405060708090a0b0c0d0e0f10111213141516"})}),it("should create callbacks to get token as constant",async()=>{const n={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.TOKEN,value:"0x030405060708090a0b0c0d0e0f10111213141516"}},t={...l,context:n};x.getFieldContext.mockResolvedValue({type:e.TOKEN,payload:"token result"});const a=new r(o,t).run();expect(a.subcontextCallbacks).toHaveLength(1);const c=a.subcontextCallbacks[0],s=await c();expect(s).toEqual({type:e.TOKEN,payload:"token result"}),expect(x.getFieldContext).toHaveBeenCalledWith({kind:C.TOKEN,chainId:1,address:"0x030405060708090a0b0c0d0e0f10111213141516"})})}),describe("for NFT type",()=>{it("should create callbacks to get NFT context",async()=>{const n={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.NFT,valuePath:[{type:"TUPLE",offset:0}]}},t={...l,context:n},a=[new Uint8Array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22])];p.extractValue.mockReturnValue(y(a)),x.getFieldContext.mockResolvedValue({type:e.NFT,payload:"nft result"});const c=new r(o,t).run();expect(c.subcontextCallbacks).toHaveLength(1);const s=c.subcontextCallbacks[0],u=await s();expect(u).toEqual({type:e.NFT,payload:"nft result"}),expect(x.getFieldContext).toHaveBeenCalledWith({kind:C.NFT,chainId:1,address:"0x030405060708090a0b0c0d0e0f10111213141516"})}),it("should create callbacks to get NFT as constant",async()=>{const n={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.NFT,value:"0x030405060708090a0b0c0d0e0f10111213141516"}},t={...l,context:n};x.getFieldContext.mockResolvedValue({type:e.NFT,payload:"nft result"});const a=new r(o,t).run();expect(a.subcontextCallbacks).toHaveLength(1);const c=a.subcontextCallbacks[0],s=await c();expect(s).toEqual({type:e.NFT,payload:"nft result"}),expect(x.getFieldContext).toHaveBeenCalledWith({kind:C.NFT,chainId:1,address:"0x030405060708090a0b0c0d0e0f10111213141516"})})}),describe("for TRUSTED_NAME type",()=>{it("should create callbacks to get trusted name context with challenge",async()=>{const n={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.TRUSTED_NAME,valuePath:[{type:"TUPLE",offset:0}],types:["type1","type2"],sources:["source1","source2"]}},t={...l,context:n},a=[new Uint8Array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22])];p.extractValue.mockReturnValue(y(a)),x.getFieldContext.mockResolvedValue({type:e.TRUSTED_NAME,payload:"trusted name result"});const c=new r(o,t).run();expect(c.subcontextCallbacks).toHaveLength(1);const s=c.subcontextCallbacks[0],u=await s();expect(u).toEqual({type:e.TRUSTED_NAME,payload:"trusted name result"}),expect(o.sendCommand).toHaveBeenCalledWith(expect.any(T)),expect(x.getFieldContext).toHaveBeenCalledWith({kind:C.TRUSTED_NAME,chainId:1,address:"0x030405060708090a0b0c0d0e0f10111213141516",challenge:"test-challenge",types:["type1","type2"],sources:["source1","source2"]})}),it("should handle challenge command failure",async()=>{const n={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.TRUSTED_NAME,valuePath:[{type:"TUPLE",offset:0}],types:["type1"],sources:["source1"]}},t={...l,context:n},a=[new Uint8Array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22])];p.extractValue.mockReturnValue(y(a));const c=new k("Failed");o.sendCommand.mockResolvedValueOnce(E({error:c}));const s=new r(o,t).run();expect(s.subcontextCallbacks).toHaveLength(1);const u=s.subcontextCallbacks[0],i=await u();expect(i).toEqual({error:new Error("Failed to get challenge"),type:e.ERROR})})}),describe("for multiple values",()=>{it("should create callbacks for each extracted value",async()=>{const n={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.TOKEN,valuePath:[{type:"TUPLE",offset:0}]}},t={...l,context:n},a=[new Uint8Array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22]),new Uint8Array([33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54])];p.extractValue.mockReturnValue(y(a)),x.getFieldContext.mockResolvedValueOnce({type:e.TOKEN,payload:"token result 1"}),x.getFieldContext.mockResolvedValueOnce({type:e.TOKEN,payload:"token result 2"});const c=new r(o,t).run();expect(c.subcontextCallbacks).toHaveLength(2);const s=c.subcontextCallbacks[0],u=c.subcontextCallbacks[1],i=await s(),b=await u();expect(i).toEqual({type:e.TOKEN,payload:"token result 1"}),expect(b).toEqual({type:e.TOKEN,payload:"token result 2"}),expect(x.getFieldContext).toHaveBeenCalledTimes(2),expect(x.getFieldContext).toHaveBeenNthCalledWith(1,{kind:C.TOKEN,chainId:1,address:"0x030405060708090a0b0c0d0e0f10111213141516"}),expect(x.getFieldContext).toHaveBeenNthCalledWith(2,{kind:C.TOKEN,chainId:1,address:"0x232425262728292a2b2c2d2e2f30313233343536"})})})})}),describe("when context has no reference",()=>{it("should return context with empty subcontextCallbacks",()=>{const n={type:e.TOKEN,payload:"test payload"},t={...l,context:n},a=new r(o,t).run();expect(a.subcontextCallbacks).toHaveLength(0)})}),describe("when context has reference but no valuePath",()=>{it("should return context with empty subcontextCallbacks",()=>{const n={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.TOKEN,valuePath:void 0}},t={...l,context:n},a=new r(o,t).run();expect(a.subcontextCallbacks).toHaveLength(0)})}),describe("error handling",()=>{it("should throw error for uncovered context type",()=>{const t={...l,context:{type:"UNKNOWN_TYPE",payload:"test payload"}};expect(()=>new r(o,t).run()).toThrow("Uncovered type: UNKNOWN_TYPE")}),it("should throw error for uncovered reference type",()=>{const n={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:"UNKNOWN_REFERENCE_TYPE"}},t={...l,context:n};expect(()=>new r(o,t).run()).toThrow("Uncovered reference type: UNKNOWN_REFERENCE_TYPE")})}),describe("CALLDATA reference type",()=>{it("should return empty subcontextCallbacks for CALLDATA reference",()=>{const n={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.CALLDATA,callee:[{type:"TUPLE",offset:0}],valuePath:[{type:"TUPLE",offset:0}]}},t={...l,context:n},a=new r(o,t).run();expect(a.subcontextCallbacks).toHaveLength(0)})}),describe("references without valuePath",()=>{it("should return empty subcontextCallbacks for ENUM reference without valuePath",()=>{const n={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.ENUM,id:1,valuePath:void 0}},t={...l,context:n},a=new r(o,t).run();expect(a.subcontextCallbacks).toHaveLength(0)}),it("should return empty subcontextCallbacks for TRUSTED_NAME reference without valuePath",()=>{const n={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.TRUSTED_NAME,types:["type1"],sources:["source1"],valuePath:void 0}},t={...l,context:n},a=new r(o,t).run();expect(a.subcontextCallbacks).toHaveLength(0)})}),describe("PROXY_DELEGATE_CALL context type",()=>{beforeEach(()=>{o.sendCommand.mockResolvedValue(E({data:{challenge:"test-challenge"}}))}),it("should create callback to get proxy delegate call context",async()=>{const n={type:e.PROXY_DELEGATE_CALL,payload:"proxy payload"},t={...l,context:n,subset:{...l.subset,to:"0x1234567890123456789012345678901234567890",data:"0xabcdef"}};x.getFieldContext.mockResolvedValue({type:e.PROXY_DELEGATE_CALL,payload:"proxy result"});const a=new r(o,t).run();expect(a.subcontextCallbacks).toHaveLength(1);const c=a.subcontextCallbacks[0],s=await c();expect(s).toEqual({type:e.PROXY_DELEGATE_CALL,payload:"proxy result"}),expect(o.sendCommand).toHaveBeenCalledWith(expect.any(T)),expect(x.getFieldContext).toHaveBeenCalledWith({kind:C.PROXY_DELEGATE_CALL,chainId:1,proxyAddress:"0x1234567890123456789012345678901234567890",calldata:"0xabcdef",deviceModelId:h.STAX,challenge:"test-challenge"})}),it("should handle challenge command failure",async()=>{const n={type:e.PROXY_DELEGATE_CALL,payload:"proxy payload"},t={...l,context:n,subset:{...l.subset,to:"0x1234567890123456789012345678901234567890",data:"0xabcdef"}},a=new k("Failed");o.sendCommand.mockResolvedValueOnce(E({error:a}));const c=new r(o,t).run();expect(c.subcontextCallbacks).toHaveLength(1);const s=c.subcontextCallbacks[0],u=await s();expect(u).toEqual({error:new Error("Failed to get challenge"),type:e.ERROR}),expect(o.sendCommand).toHaveBeenCalledWith(expect.any(T)),expect(x.getFieldContext).not.toHaveBeenCalled()}),it("should handle missing proxy address",async()=>{const n={type:e.PROXY_DELEGATE_CALL,payload:"proxy payload"},t={...l,context:n,subset:{...l.subset,to:void 0,data:"0xabcdef"}},a=new r(o,t).run();expect(a.subcontextCallbacks).toHaveLength(1);const c=a.subcontextCallbacks[0],s=await c();expect(s).toEqual({error:new Error("Failed to get proxy address"),type:e.ERROR}),expect(o.sendCommand).toHaveBeenCalledWith(expect.any(T)),expect(x.getFieldContext).not.toHaveBeenCalled()}),it("should use correct device model id in context",async()=>{const n={type:e.PROXY_DELEGATE_CALL,payload:"proxy payload"},t={...l,context:n,deviceModelId:h.NANO_SP,subset:{...l.subset,to:"0x1234567890123456789012345678901234567890",data:"0xabcdef"}};x.getFieldContext.mockResolvedValue({type:e.PROXY_DELEGATE_CALL,payload:"proxy result"});const a=new r(o,t).run();expect(a.subcontextCallbacks).toHaveLength(1);const c=a.subcontextCallbacks[0];await c(),expect(x.getFieldContext).toHaveBeenCalledWith({kind:C.PROXY_DELEGATE_CALL,chainId:1,proxyAddress:"0x1234567890123456789012345678901234567890",calldata:"0xabcdef",deviceModelId:h.NANO_SP,challenge:"test-challenge"})})}),describe("edge cases",()=>{it("should handle value array shorter than 20 bytes for address extraction",async()=>{const n={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.TOKEN,valuePath:[{type:"TUPLE",offset:0}]}},t={...l,context:n},a=[new Uint8Array([1,2,3])];p.extractValue.mockReturnValue(y(a)),x.getFieldContext.mockResolvedValue({type:e.ERROR,message:"Invalid address"});const c=new r(o,t).run();expect(c.subcontextCallbacks).toHaveLength(1);const s=c.subcontextCallbacks[0],u=await s();expect(u).toEqual({type:e.ERROR,message:"Invalid address"}),expect(x.getFieldContext).toHaveBeenCalledWith({kind:C.TOKEN,chainId:1,address:"0x010203"})}),it("should handle empty value array",async()=>{const n={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.TOKEN,valuePath:[{type:"TUPLE",offset:0}]}},t={...l,context:n},a=[new Uint8Array([])];p.extractValue.mockReturnValue(y(a)),x.getFieldContext.mockResolvedValue({type:e.TOKEN,payload:"token result"});const c=new r(o,t).run();expect(c.subcontextCallbacks).toHaveLength(1);const s=c.subcontextCallbacks[0],u=await s();expect(u).toEqual({type:e.TOKEN,payload:"token result"}),expect(x.getFieldContext).toHaveBeenCalledWith({kind:C.TOKEN,chainId:1,address:"0x"})})})});
|
|
1
|
+
import{ClearSignContextReferenceType as d,ClearSignContextType as e}from"@ledgerhq/context-module";import{CommandResultFactory as b,DeviceModelId as h,UnknownDeviceExchangeError as E}from"@ledgerhq/device-management-kit";import{Left as S,Right as y}from"purify-ts";import{GetChallengeCommand as N}from"../../app-binder/command/GetChallengeCommand";import{makeDeviceActionInternalApiMock as R}from"../../app-binder/device-action/__test-utils__/makeInternalApi";import{BuildSubcontextsTask as r}from"./BuildSubcontextsTask";describe("BuildSubcontextsTask",()=>{const x={getFieldContext:vi.fn()},p={extractValue:vi.fn()},o=R();let l;beforeEach(()=>{vi.resetAllMocks(),l={context:{type:e.TRANSACTION_INFO,payload:"test payload"},contextOptional:[],transactionParser:p,subset:{chainId:1,data:"0x",selector:"0x",to:"0x",value:BigInt(0)},contextModule:x,deviceModelId:h.STAX}}),describe("when context type is a simple type",()=>{const c=[e.TRANSACTION_INFO,e.WEB3_CHECK,e.PLUGIN,e.EXTERNAL_PLUGIN,e.DYNAMIC_NETWORK,e.DYNAMIC_NETWORK_ICON,e.ENUM,e.TRUSTED_NAME,e.TOKEN,e.NFT];it.each(c)("should return context with empty subcontextCallbacks for %s",t=>{const n={...l,context:{type:t,payload:"test payload"}},s=new r(o,n).run();expect(s.subcontextCallbacks).toHaveLength(0)})}),describe("when context has a direct value reference",()=>{it("should create a callback to get context with the direct value",async()=>{const c={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.TOKEN,value:"0x1234567890123456789012345678901234567890"}},t={...l,context:c},a={chainId:1,address:"0x1234567890123456789012345678901234567890"},n=new r(o,t).run();expect(n.subcontextCallbacks).toHaveLength(1);const s=n.subcontextCallbacks[0];await s(),expect(x.getFieldContext).toHaveBeenCalledWith(a,e.TOKEN)}),it("should handle undefined value in reference",()=>{const c={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:void 0},t={...l,context:c},a=new r(o,t).run();expect(a.subcontextCallbacks).toHaveLength(0)})}),describe("when context has a valuePath reference",()=>{beforeEach(()=>{o.sendCommand.mockResolvedValue(b({data:{challenge:"test-challenge"}}))}),describe("when extractValue returns Left (error)",()=>{it("should return context with empty subcontextCallbacks",()=>{const c={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.TOKEN,valuePath:[{type:"SLICE",start:0,end:20}]}},t={...l,context:c};p.extractValue.mockReturnValue(S(new Error("Extraction failed")));const a=new r(o,t).run();expect(a.subcontextCallbacks).toHaveLength(0)})}),describe("when extractValue returns Right with values",()=>{describe("for ENUM type",()=>{it("should create callbacks for matching enum contexts",async()=>{const c={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.ENUM,id:1,valuePath:[{type:"TUPLE",offset:0}]}},t={type:e.ENUM,id:1,value:1,payload:"enum context 1"},a={type:e.ENUM,id:1,value:2,payload:"enum context 2"},n={type:e.ENUM,id:2,value:2,payload:"enum context 3"},s={...l,context:c,contextOptional:[t,a,n]},u=[new Uint8Array([1,2])];p.extractValue.mockReturnValue(y(u));const i=new r(o,s).run();expect(i.subcontextCallbacks).toHaveLength(1);const C=i.subcontextCallbacks[0],g=await C();expect(g).toEqual(a)}),it("should create callbacks for matching enum contexts with two values",async()=>{const c={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.ENUM,id:1,valuePath:[{type:"TUPLE",offset:0}]}},t={type:e.ENUM,id:1,value:1,payload:"enum context 1"},a={type:e.ENUM,id:1,value:2,payload:"enum context 2"},n={type:e.ENUM,id:2,value:2,payload:"enum context 3"},s={...l,context:c,contextOptional:[t,a,n]},u=[new Uint8Array([1,2]),new Uint8Array([3,2,1])];p.extractValue.mockReturnValue(y(u));const i=new r(o,s).run();expect(i.subcontextCallbacks).toHaveLength(2);const C=i.subcontextCallbacks[0],g=i.subcontextCallbacks[1],T=await C(),k=await g();expect(T).toEqual(a),expect(k).toEqual(t)}),it("should skip when enum value is undefined",()=>{const c={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.ENUM,id:1,valuePath:[{type:"TUPLE",offset:0}]}},t={...l,context:c},a=[new Uint8Array([])];p.extractValue.mockReturnValue(y(a));const n=new r(o,t).run();expect(n.subcontextCallbacks).toHaveLength(0)}),it("should create callback with enum id 0",async()=>{const c={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.ENUM,id:0,valuePath:[{type:"TUPLE",offset:0}]}},t={type:e.ENUM,id:0,value:0,payload:"enum context 1"},a={type:e.ENUM,id:1,value:1,payload:"enum context 2"},n={...l,context:c,contextOptional:[t,a]},s=[new Uint8Array([1,0])];p.extractValue.mockReturnValue(y(s));const u=new r(o,n).run();expect(u.subcontextCallbacks).toHaveLength(1);const i=u.subcontextCallbacks[0],C=await i();expect(C).toEqual(t)}),it("should skip when no matching enum context found",()=>{const c={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.ENUM,id:1,valuePath:[{type:"TUPLE",offset:0}]}},t={type:e.ENUM,id:2,value:2,payload:"enum context"},a={...l,context:c,contextOptional:[t]},n=[new Uint8Array([1,2])];p.extractValue.mockReturnValue(y(n));const s=new r(o,a).run();expect(s.subcontextCallbacks).toHaveLength(0)})}),describe("for TOKEN type",()=>{it("should create callbacks to get token context",async()=>{const c={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.TOKEN,valuePath:[{type:"TUPLE",offset:0}]}},t={...l,context:c},a=[new Uint8Array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22])];p.extractValue.mockReturnValue(y(a)),x.getFieldContext.mockResolvedValue({type:e.TOKEN,payload:"token result"});const n=new r(o,t).run();expect(n.subcontextCallbacks).toHaveLength(1);const s=n.subcontextCallbacks[0],u=await s();expect(u).toEqual({type:e.TOKEN,payload:"token result"}),expect(x.getFieldContext).toHaveBeenCalledWith({chainId:1,address:"0x030405060708090a0b0c0d0e0f10111213141516"},e.TOKEN)}),it("should create callbacks to get token as constant",async()=>{const c={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.TOKEN,value:"0x030405060708090a0b0c0d0e0f10111213141516"}},t={...l,context:c};x.getFieldContext.mockResolvedValue({type:e.TOKEN,payload:"token result"});const a=new r(o,t).run();expect(a.subcontextCallbacks).toHaveLength(1);const n=a.subcontextCallbacks[0],s=await n();expect(s).toEqual({type:e.TOKEN,payload:"token result"}),expect(x.getFieldContext).toHaveBeenCalledWith({chainId:1,address:"0x030405060708090a0b0c0d0e0f10111213141516"},e.TOKEN)})}),describe("for NFT type",()=>{it("should create callbacks to get NFT context",async()=>{const c={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.NFT,valuePath:[{type:"TUPLE",offset:0}]}},t={...l,context:c},a=[new Uint8Array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22])];p.extractValue.mockReturnValue(y(a)),x.getFieldContext.mockResolvedValue({type:e.NFT,payload:"nft result"});const n=new r(o,t).run();expect(n.subcontextCallbacks).toHaveLength(1);const s=n.subcontextCallbacks[0],u=await s();expect(u).toEqual({type:e.NFT,payload:"nft result"}),expect(x.getFieldContext).toHaveBeenCalledWith({chainId:1,address:"0x030405060708090a0b0c0d0e0f10111213141516"},e.NFT)}),it("should create callbacks to get NFT as constant",async()=>{const c={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.NFT,value:"0x030405060708090a0b0c0d0e0f10111213141516"}},t={...l,context:c};x.getFieldContext.mockResolvedValue({type:e.NFT,payload:"nft result"});const a=new r(o,t).run();expect(a.subcontextCallbacks).toHaveLength(1);const n=a.subcontextCallbacks[0],s=await n();expect(s).toEqual({type:e.NFT,payload:"nft result"}),expect(x.getFieldContext).toHaveBeenCalledWith({chainId:1,address:"0x030405060708090a0b0c0d0e0f10111213141516"},e.NFT)})}),describe("for TRUSTED_NAME type",()=>{it("should create callbacks to get trusted name context with challenge",async()=>{const c={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.TRUSTED_NAME,valuePath:[{type:"TUPLE",offset:0}],types:["type1","type2"],sources:["source1","source2"]}},t={...l,context:c},a=[new Uint8Array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22])];p.extractValue.mockReturnValue(y(a)),x.getFieldContext.mockResolvedValue({type:e.TRUSTED_NAME,payload:"trusted name result"});const n=new r(o,t).run();expect(n.subcontextCallbacks).toHaveLength(1);const s=n.subcontextCallbacks[0],u=await s();expect(u).toEqual({type:e.TRUSTED_NAME,payload:"trusted name result"}),expect(o.sendCommand).toHaveBeenCalledWith(expect.any(N)),expect(x.getFieldContext).toHaveBeenCalledWith({chainId:1,address:"0x030405060708090a0b0c0d0e0f10111213141516",challenge:"test-challenge",types:["type1","type2"],sources:["source1","source2"]},e.TRUSTED_NAME)}),it("should handle challenge command failure",async()=>{const c={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.TRUSTED_NAME,valuePath:[{type:"TUPLE",offset:0}],types:["type1"],sources:["source1"]}},t={...l,context:c},a=[new Uint8Array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22])];p.extractValue.mockReturnValue(y(a));const n=new E("Failed");o.sendCommand.mockResolvedValueOnce(b({error:n}));const s=new r(o,t).run();expect(s.subcontextCallbacks).toHaveLength(1);const u=s.subcontextCallbacks[0],i=await u();expect(i).toEqual({error:new Error("Failed to get challenge"),type:e.ERROR})})}),describe("for multiple values",()=>{it("should create callbacks for each extracted value",async()=>{const c={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.TOKEN,valuePath:[{type:"TUPLE",offset:0}]}},t={...l,context:c},a=[new Uint8Array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22]),new Uint8Array([33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54])];p.extractValue.mockReturnValue(y(a)),x.getFieldContext.mockResolvedValueOnce({type:e.TOKEN,payload:"token result 1"}),x.getFieldContext.mockResolvedValueOnce({type:e.TOKEN,payload:"token result 2"});const n=new r(o,t).run();expect(n.subcontextCallbacks).toHaveLength(2);const s=n.subcontextCallbacks[0],u=n.subcontextCallbacks[1],i=await s(),C=await u();expect(i).toEqual({type:e.TOKEN,payload:"token result 1"}),expect(C).toEqual({type:e.TOKEN,payload:"token result 2"}),expect(x.getFieldContext).toHaveBeenCalledTimes(2),expect(x.getFieldContext).toHaveBeenNthCalledWith(1,{chainId:1,address:"0x030405060708090a0b0c0d0e0f10111213141516"},e.TOKEN),expect(x.getFieldContext).toHaveBeenNthCalledWith(2,{chainId:1,address:"0x232425262728292a2b2c2d2e2f30313233343536"},e.TOKEN)})})})}),describe("when context has no reference",()=>{it("should return context with empty subcontextCallbacks",()=>{const c={type:e.TOKEN,payload:"test payload"},t={...l,context:c},a=new r(o,t).run();expect(a.subcontextCallbacks).toHaveLength(0)})}),describe("when context has reference but no valuePath",()=>{it("should return context with empty subcontextCallbacks",()=>{const c={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.TOKEN,valuePath:void 0}},t={...l,context:c},a=new r(o,t).run();expect(a.subcontextCallbacks).toHaveLength(0)})}),describe("error handling",()=>{it("should throw error for uncovered context type",()=>{const t={...l,context:{type:"UNKNOWN_TYPE",payload:"test payload"}};expect(()=>new r(o,t).run()).toThrow("Uncovered type: UNKNOWN_TYPE")}),it("should throw error for uncovered reference type",()=>{const c={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:"UNKNOWN_REFERENCE_TYPE"}},t={...l,context:c};expect(()=>new r(o,t).run()).toThrow("Uncovered reference type: UNKNOWN_REFERENCE_TYPE")})}),describe("CALLDATA reference type",()=>{it("should return empty subcontextCallbacks for CALLDATA reference",()=>{const c={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.CALLDATA,callee:[{type:"TUPLE",offset:0}],valuePath:[{type:"TUPLE",offset:0}]}},t={...l,context:c},a=new r(o,t).run();expect(a.subcontextCallbacks).toHaveLength(0)})}),describe("references without valuePath",()=>{it("should return empty subcontextCallbacks for ENUM reference without valuePath",()=>{const c={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.ENUM,id:1,valuePath:void 0}},t={...l,context:c},a=new r(o,t).run();expect(a.subcontextCallbacks).toHaveLength(0)}),it("should return empty subcontextCallbacks for TRUSTED_NAME reference without valuePath",()=>{const c={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.TRUSTED_NAME,types:["type1"],sources:["source1"],valuePath:void 0}},t={...l,context:c},a=new r(o,t).run();expect(a.subcontextCallbacks).toHaveLength(0)})}),describe("PROXY_INFO context type",()=>{beforeEach(()=>{o.sendCommand.mockResolvedValue(b({data:{challenge:"test-challenge"}}))}),it("should create callback to get proxy delegate call context",async()=>{const c={type:e.PROXY_INFO,payload:"proxy payload"},t={...l,context:c,subset:{...l.subset,to:"0x1234567890123456789012345678901234567890",data:"0xabcdef"}};x.getFieldContext.mockResolvedValue({type:e.PROXY_INFO,payload:"proxy result"});const a=new r(o,t).run();expect(a.subcontextCallbacks).toHaveLength(1);const n=a.subcontextCallbacks[0],s=await n();expect(s).toEqual({type:e.PROXY_INFO,payload:"proxy result"}),expect(o.sendCommand).toHaveBeenCalledWith(expect.any(N)),expect(x.getFieldContext).toHaveBeenCalledWith({chainId:1,proxyAddress:"0x1234567890123456789012345678901234567890",calldata:"0xabcdef",deviceModelId:h.STAX,challenge:"test-challenge"},e.PROXY_INFO)}),it("should handle challenge command failure",async()=>{const c={type:e.PROXY_INFO,payload:"proxy payload"},t={...l,context:c,subset:{...l.subset,to:"0x1234567890123456789012345678901234567890",data:"0xabcdef"}},a=new E("Failed");o.sendCommand.mockResolvedValueOnce(b({error:a}));const n=new r(o,t).run();expect(n.subcontextCallbacks).toHaveLength(1);const s=n.subcontextCallbacks[0],u=await s();expect(u).toEqual({error:new Error("Failed to get challenge"),type:e.ERROR}),expect(o.sendCommand).toHaveBeenCalledWith(expect.any(N)),expect(x.getFieldContext).not.toHaveBeenCalled()}),it("should handle missing proxy address",async()=>{const c={type:e.PROXY_INFO,payload:"proxy payload"},t={...l,context:c,subset:{...l.subset,to:void 0,data:"0xabcdef"}},a=new r(o,t).run();expect(a.subcontextCallbacks).toHaveLength(1);const n=a.subcontextCallbacks[0],s=await n();expect(s).toEqual({error:new Error("Failed to get proxy address"),type:e.ERROR}),expect(o.sendCommand).toHaveBeenCalledWith(expect.any(N)),expect(x.getFieldContext).not.toHaveBeenCalled()}),it("should use correct device model id in context",async()=>{const c={type:e.PROXY_INFO,payload:"proxy payload"},t={...l,context:c,deviceModelId:h.NANO_SP,subset:{...l.subset,to:"0x1234567890123456789012345678901234567890",data:"0xabcdef"}};x.getFieldContext.mockResolvedValue({type:e.PROXY_INFO,payload:"proxy result"});const a=new r(o,t).run();expect(a.subcontextCallbacks).toHaveLength(1);const n=a.subcontextCallbacks[0];await n(),expect(x.getFieldContext).toHaveBeenCalledWith({chainId:1,proxyAddress:"0x1234567890123456789012345678901234567890",calldata:"0xabcdef",deviceModelId:h.NANO_SP,challenge:"test-challenge"},e.PROXY_INFO)})}),describe("edge cases",()=>{it("should handle value array shorter than 20 bytes for address extraction",async()=>{const c={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.TOKEN,valuePath:[{type:"TUPLE",offset:0}]}},t={...l,context:c},a=[new Uint8Array([1,2,3])];p.extractValue.mockReturnValue(y(a)),x.getFieldContext.mockResolvedValue({type:e.ERROR,message:"Invalid address"});const n=new r(o,t).run();expect(n.subcontextCallbacks).toHaveLength(1);const s=n.subcontextCallbacks[0],u=await s();expect(u).toEqual({type:e.ERROR,message:"Invalid address"}),expect(x.getFieldContext).toHaveBeenCalledWith({chainId:1,address:"0x010203"},e.TOKEN)}),it("should handle empty value array",async()=>{const c={type:e.TRANSACTION_FIELD_DESCRIPTION,payload:"test payload",reference:{type:d.TOKEN,valuePath:[{type:"TUPLE",offset:0}]}},t={...l,context:c},a=[new Uint8Array([])];p.extractValue.mockReturnValue(y(a)),x.getFieldContext.mockResolvedValue({type:e.TOKEN,payload:"token result"});const n=new r(o,t).run();expect(n.subcontextCallbacks).toHaveLength(1);const s=n.subcontextCallbacks[0],u=await s();expect(u).toEqual({type:e.TOKEN,payload:"token result"}),expect(x.getFieldContext).toHaveBeenCalledWith({chainId:1,address:"0x"},e.TOKEN)})})});
|
|
2
2
|
//# sourceMappingURL=BuildSubcontextsTask.test.js.map
|