@ledgerhq/device-signer-kit-ethereum 0.0.0-rn-ble-perf-20251009143619 → 0.0.0-rn-hid-issues-20251023075200
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/README.md +59 -1
- package/lib/cjs/api/SignerEth.js +1 -1
- package/lib/cjs/api/SignerEth.js.map +1 -1
- package/lib/cjs/api/SignerEthBuilder.test.js +1 -1
- package/lib/cjs/api/SignerEthBuilder.test.js.map +2 -2
- package/lib/cjs/api/app-binder/VerifySafeAddressDeviceActionTypes.js +2 -0
- package/lib/cjs/api/app-binder/VerifySafeAddressDeviceActionTypes.js.map +7 -0
- package/lib/cjs/api/model/SafeAddressOptions.js +2 -0
- package/lib/cjs/api/model/SafeAddressOptions.js.map +7 -0
- package/lib/cjs/internal/DefaultSignerEth.js +1 -1
- package/lib/cjs/internal/DefaultSignerEth.js.map +3 -3
- package/lib/cjs/internal/app-binder/EthAppBinder.js +1 -1
- package/lib/cjs/internal/app-binder/EthAppBinder.js.map +3 -3
- package/lib/cjs/internal/app-binder/command/ProvideSafeAccountCommand.js +2 -0
- package/lib/cjs/internal/app-binder/command/ProvideSafeAccountCommand.js.map +7 -0
- package/lib/cjs/internal/app-binder/command/ProvideSafeAccountCommand.test.js +2 -0
- package/lib/cjs/internal/app-binder/command/ProvideSafeAccountCommand.test.js.map +7 -0
- package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js +1 -1
- package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js.map +3 -3
- package/lib/cjs/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.js +2 -0
- package/lib/cjs/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.js.map +7 -0
- package/lib/cjs/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.test.js +2 -0
- package/lib/cjs/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.test.js.map +7 -0
- 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/BuildSafeAddressContextTask.js +2 -0
- package/lib/cjs/internal/app-binder/task/BuildSafeAddressContextTask.js.map +7 -0
- package/lib/cjs/internal/app-binder/task/BuildSafeAddressContextTask.test.js +2 -0
- package/lib/cjs/internal/app-binder/task/BuildSafeAddressContextTask.test.js.map +7 -0
- package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.js +1 -1
- package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.js.map +2 -2
- package/lib/cjs/internal/app-binder/task/ProvideContextTask.js +2 -0
- package/lib/cjs/internal/app-binder/task/ProvideContextTask.js.map +7 -0
- package/lib/cjs/internal/app-binder/task/ProvideContextTask.test.js +2 -0
- package/lib/cjs/internal/app-binder/task/ProvideContextTask.test.js.map +7 -0
- package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.js +1 -1
- package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.js.map +3 -3
- package/lib/cjs/internal/app-binder/task/ProvideTransactionContextsTask.js +2 -0
- package/lib/cjs/internal/app-binder/task/ProvideTransactionContextsTask.js.map +7 -0
- package/lib/cjs/internal/app-binder/task/ProvideTransactionContextsTask.test.js +2 -0
- package/lib/cjs/internal/app-binder/task/ProvideTransactionContextsTask.test.js.map +7 -0
- package/lib/cjs/internal/di.js +1 -1
- package/lib/cjs/internal/di.js.map +3 -3
- package/lib/cjs/internal/safe/di/safeModule.js +2 -0
- package/lib/cjs/internal/safe/di/safeModule.js.map +7 -0
- package/lib/cjs/internal/safe/di/safeModule.test.js +2 -0
- package/lib/cjs/internal/safe/di/safeModule.test.js.map +7 -0
- package/lib/cjs/internal/safe/di/safeTypes.js +2 -0
- package/lib/cjs/internal/safe/di/safeTypes.js.map +7 -0
- package/lib/cjs/internal/safe/use-case/VerifySafeAddressUseCase.js +2 -0
- package/lib/cjs/internal/safe/use-case/VerifySafeAddressUseCase.js.map +7 -0
- package/lib/cjs/internal/safe/use-case/VerifySafeAddressUseCase.test.js +2 -0
- package/lib/cjs/internal/safe/use-case/VerifySafeAddressUseCase.test.js.map +7 -0
- package/lib/esm/api/SignerEthBuilder.test.js +1 -1
- package/lib/esm/api/SignerEthBuilder.test.js.map +2 -2
- package/lib/esm/api/app-binder/VerifySafeAddressDeviceActionTypes.js +2 -0
- package/lib/esm/api/app-binder/VerifySafeAddressDeviceActionTypes.js.map +7 -0
- package/lib/esm/api/model/SafeAddressOptions.js +1 -0
- package/lib/esm/api/model/SafeAddressOptions.js.map +7 -0
- package/lib/esm/internal/DefaultSignerEth.js +1 -1
- package/lib/esm/internal/DefaultSignerEth.js.map +3 -3
- package/lib/esm/internal/app-binder/EthAppBinder.js +1 -1
- package/lib/esm/internal/app-binder/EthAppBinder.js.map +3 -3
- package/lib/esm/internal/app-binder/command/ProvideSafeAccountCommand.js +2 -0
- package/lib/esm/internal/app-binder/command/ProvideSafeAccountCommand.js.map +7 -0
- package/lib/esm/internal/app-binder/command/ProvideSafeAccountCommand.test.js +2 -0
- package/lib/esm/internal/app-binder/command/ProvideSafeAccountCommand.test.js.map +7 -0
- package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js +1 -1
- package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js.map +3 -3
- package/lib/esm/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.js +2 -0
- package/lib/esm/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.js.map +7 -0
- package/lib/esm/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.test.js +2 -0
- package/lib/esm/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.test.js.map +7 -0
- 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 +3 -3
- package/lib/esm/internal/app-binder/task/BuildSafeAddressContextTask.js +2 -0
- package/lib/esm/internal/app-binder/task/BuildSafeAddressContextTask.js.map +7 -0
- package/lib/esm/internal/app-binder/task/BuildSafeAddressContextTask.test.js +2 -0
- package/lib/esm/internal/app-binder/task/BuildSafeAddressContextTask.test.js.map +7 -0
- package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.js +1 -1
- package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.js.map +2 -2
- package/lib/esm/internal/app-binder/task/ProvideContextTask.js +2 -0
- package/lib/esm/internal/app-binder/task/ProvideContextTask.js.map +7 -0
- package/lib/esm/internal/app-binder/task/ProvideContextTask.test.js +2 -0
- package/lib/esm/internal/app-binder/task/ProvideContextTask.test.js.map +7 -0
- package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.js +1 -1
- package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.js.map +3 -3
- package/lib/esm/internal/app-binder/task/ProvideTransactionContextsTask.js +2 -0
- package/lib/esm/internal/app-binder/task/ProvideTransactionContextsTask.js.map +7 -0
- package/lib/esm/internal/app-binder/task/ProvideTransactionContextsTask.test.js +2 -0
- package/lib/esm/internal/app-binder/task/ProvideTransactionContextsTask.test.js.map +7 -0
- package/lib/esm/internal/di.js +1 -1
- package/lib/esm/internal/di.js.map +3 -3
- package/lib/esm/internal/safe/di/safeModule.js +2 -0
- package/lib/esm/internal/safe/di/safeModule.js.map +7 -0
- package/lib/esm/internal/safe/di/safeModule.test.js +2 -0
- package/lib/esm/internal/safe/di/safeModule.test.js.map +7 -0
- package/lib/esm/internal/safe/di/safeTypes.js +2 -0
- package/lib/esm/internal/safe/di/safeTypes.js.map +7 -0
- package/lib/esm/internal/safe/use-case/VerifySafeAddressUseCase.js +2 -0
- package/lib/esm/internal/safe/use-case/VerifySafeAddressUseCase.js.map +7 -0
- package/lib/esm/internal/safe/use-case/VerifySafeAddressUseCase.test.js +2 -0
- package/lib/esm/internal/safe/use-case/VerifySafeAddressUseCase.test.js.map +7 -0
- package/lib/types/api/SignerEth.d.ts +3 -0
- package/lib/types/api/SignerEth.d.ts.map +1 -1
- package/lib/types/api/app-binder/VerifySafeAddressDeviceActionTypes.d.ts +30 -0
- package/lib/types/api/app-binder/VerifySafeAddressDeviceActionTypes.d.ts.map +1 -0
- package/lib/types/api/model/SafeAddressOptions.d.ts +5 -0
- package/lib/types/api/model/SafeAddressOptions.d.ts.map +1 -0
- package/lib/types/internal/DefaultSignerEth.d.ts +3 -0
- package/lib/types/internal/DefaultSignerEth.d.ts.map +1 -1
- package/lib/types/internal/app-binder/EthAppBinder.d.ts +6 -0
- package/lib/types/internal/app-binder/EthAppBinder.d.ts.map +1 -1
- package/lib/types/internal/app-binder/command/ProvideSafeAccountCommand.d.ts +34 -0
- package/lib/types/internal/app-binder/command/ProvideSafeAccountCommand.d.ts.map +1 -0
- package/lib/types/internal/app-binder/command/ProvideSafeAccountCommand.test.d.ts +2 -0
- package/lib/types/internal/app-binder/command/ProvideSafeAccountCommand.test.d.ts.map +1 -0
- package/lib/types/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.d.ts +3 -3
- package/lib/types/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.d.ts.map +1 -1
- package/lib/types/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.d.ts +20 -0
- package/lib/types/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.d.ts.map +1 -0
- package/lib/types/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.test.d.ts +2 -0
- package/lib/types/internal/app-binder/device-action/VerifySafeAddress/VerifySafeAddress.test.d.ts.map +1 -0
- package/lib/types/internal/app-binder/task/BuildBaseContexts.d.ts +3 -1
- package/lib/types/internal/app-binder/task/BuildBaseContexts.d.ts.map +1 -1
- package/lib/types/internal/app-binder/task/BuildSafeAddressContextTask.d.ts +19 -0
- package/lib/types/internal/app-binder/task/BuildSafeAddressContextTask.d.ts.map +1 -0
- package/lib/types/internal/app-binder/task/BuildSafeAddressContextTask.test.d.ts +2 -0
- package/lib/types/internal/app-binder/task/BuildSafeAddressContextTask.test.d.ts.map +1 -0
- package/lib/types/internal/app-binder/task/BuildSubcontextsTask.d.ts.map +1 -1
- package/lib/types/internal/app-binder/task/ProvideContextTask.d.ts +22 -0
- package/lib/types/internal/app-binder/task/ProvideContextTask.d.ts.map +1 -0
- package/lib/types/internal/app-binder/task/ProvideContextTask.test.d.ts +2 -0
- package/lib/types/internal/app-binder/task/ProvideContextTask.test.d.ts.map +1 -0
- package/lib/types/internal/app-binder/task/ProvideEIP712ContextTask.d.ts +2 -2
- package/lib/types/internal/app-binder/task/ProvideEIP712ContextTask.d.ts.map +1 -1
- package/lib/types/internal/app-binder/task/ProvideTransactionContextsTask.d.ts +36 -0
- package/lib/types/internal/app-binder/task/ProvideTransactionContextsTask.d.ts.map +1 -0
- package/lib/types/internal/app-binder/task/ProvideTransactionContextsTask.test.d.ts +2 -0
- package/lib/types/internal/app-binder/task/ProvideTransactionContextsTask.test.d.ts.map +1 -0
- package/lib/types/internal/di.d.ts.map +1 -1
- package/lib/types/internal/safe/di/safeModule.d.ts +3 -0
- package/lib/types/internal/safe/di/safeModule.d.ts.map +1 -0
- package/lib/types/internal/safe/di/safeModule.test.d.ts +2 -0
- package/lib/types/internal/safe/di/safeModule.test.d.ts.map +1 -0
- package/lib/types/internal/safe/di/safeTypes.d.ts +4 -0
- package/lib/types/internal/safe/di/safeTypes.d.ts.map +1 -0
- package/lib/types/internal/safe/use-case/VerifySafeAddressUseCase.d.ts +9 -0
- package/lib/types/internal/safe/use-case/VerifySafeAddressUseCase.d.ts.map +1 -0
- package/lib/types/internal/safe/use-case/VerifySafeAddressUseCase.test.d.ts +2 -0
- package/lib/types/internal/safe/use-case/VerifySafeAddressUseCase.test.d.ts.map +1 -0
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +6 -6
- package/lib/cjs/internal/app-binder/task/ProvideContextsTask.js +0 -2
- package/lib/cjs/internal/app-binder/task/ProvideContextsTask.js.map +0 -7
- package/lib/cjs/internal/app-binder/task/ProvideContextsTask.test.js +0 -2
- package/lib/cjs/internal/app-binder/task/ProvideContextsTask.test.js.map +0 -7
- package/lib/esm/internal/app-binder/task/ProvideContextsTask.js +0 -2
- package/lib/esm/internal/app-binder/task/ProvideContextsTask.js.map +0 -7
- package/lib/esm/internal/app-binder/task/ProvideContextsTask.test.js +0 -2
- package/lib/esm/internal/app-binder/task/ProvideContextsTask.test.js.map +0 -7
- package/lib/types/internal/app-binder/task/ProvideContextsTask.d.ts +0 -44
- package/lib/types/internal/app-binder/task/ProvideContextsTask.d.ts.map +0 -1
- package/lib/types/internal/app-binder/task/ProvideContextsTask.test.d.ts +0 -2
- package/lib/types/internal/app-binder/task/ProvideContextsTask.test.d.ts.map +0 -1
|
@@ -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 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},void 0)}),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},void 0)}),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},void 0)}),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 x,DeviceModelId as l,DeviceSessionStateType as r,DeviceStatus as d,hexaStringToBuffer as O,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 N}from"../../app-binder/device-action/__test-utils__/makeInternalApi";import{BASE_CONTEXT_TYPES_FILTER as y,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()},E={domain:"domain-name.eth"},g=O(v.from({chainId:1n,nonce:0,data:"0x"}).unsignedSerialized),p={keyUsageNumber:1,payload:new Uint8Array([1,2,3])};let o;const n=N(),c=vi.fn();function S(e){return{blindSigningEnabled:!1,web3ChecksEnabled:e,web3ChecksOptIn:!1,version:"1.13.0"}}beforeEach(()=>{vi.resetAllMocks(),n.sendCommand.mockResolvedValue(x({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:g,options:E,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={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 h=await new s(n,{...o,appConfig:S(!0)},c).run();expect(h).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:g})}),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},y)}),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},y)}),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(x({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},y)}),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 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 {\n deviceModelId: DeviceModelId.FLEX,\n challenge: \"challenge\",\n domain: \"domain-name.eth\",\n ...defaultArgs.subset,\n },\n undefined,\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 {\n deviceModelId: DeviceModelId.NANO_S,\n domain: \"domain-name.eth\",\n ...defaultArgs.subset,\n },\n undefined,\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 {\n deviceModelId: DeviceModelId.FLEX,\n challenge: undefined,\n domain: \"domain-name.eth\",\n ...defaultArgs.subset,\n },\n undefined,\n );\n });\n\n it(\"should exclude error contexts from the result\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result on old apps\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"transaction_info\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"transaction_field\",\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"enum\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result if no transaction_info was found\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"transaction_field\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"enum\",\n id: 1,\n value: 2,\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.14.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude legacy contexts from the result for generic-parser transactions\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-5\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [clearSignContexts[4]],\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should exclude generic-parser contexts with a nano s device\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.14.0\" },\n deviceModelId: DeviceModelId.NANO_S,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts with an old app version\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts with a non ready device\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.NOT_CONNECTED,\n deviceModelId: DeviceModelId.FLEX,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should return no clear sign context if the transaction info certificate is missing\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.17.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should not return web3check if the transaction is undefined\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.17.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, transaction: undefined },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(getWeb3ChecksFactoryMock).not.toHaveBeenCalled();\n });\n});\n"],
|
|
5
|
-
"mappings": "AAAA,OAEE,wBAAAA,MAEK,2BACP,OACE,wBAAAC,EACA,iBAAAC,EACA,0BAAAC,EACA,gBAAAC,EACA,sBAAAC,EACA,8BAAAC,MACK,kCACP,OAAS,eAAAC,MAAmB,SAG5B,OAAS,oBAAAC,MAAwB,8BACjC,OAAS,mCAAAC,MAAuC,oEAEhD,OACE,qBAAAC,MAEK,sBACP,OAAS,oBAAAC,MAAwB,qBAEjC,SAAS,oBAAqB,IAAM,CAClC,MAAMC,EAAoB,CACxB,gBAAiB,GAAG,GAAG,EACvB,YAAa,GAAG,GAAG,EACnB,oBAAqB,GAAG,GAAG,EAC3B,cAAe,GAAG,GAAG,EACrB,iBAAkB,GAAG,GAAG,CAC1B,EACMC,EAAiB,CACrB,OAAQ,iBACV,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,GAA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AED,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
|
-
"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"]
|
|
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 BASE_CONTEXT_TYPES_FILTER,\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 {\n deviceModelId: DeviceModelId.FLEX,\n challenge: \"challenge\",\n domain: \"domain-name.eth\",\n ...defaultArgs.subset,\n },\n BASE_CONTEXT_TYPES_FILTER,\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 {\n deviceModelId: DeviceModelId.NANO_S,\n domain: \"domain-name.eth\",\n ...defaultArgs.subset,\n },\n BASE_CONTEXT_TYPES_FILTER,\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 {\n deviceModelId: DeviceModelId.FLEX,\n challenge: undefined,\n domain: \"domain-name.eth\",\n ...defaultArgs.subset,\n },\n BASE_CONTEXT_TYPES_FILTER,\n );\n });\n\n it(\"should exclude error contexts from the result\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result on old apps\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"transaction_info\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"transaction_field\",\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"enum\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result if no transaction_info was found\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"transaction_field\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"enum\",\n id: 1,\n value: 2,\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.14.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude legacy contexts from the result for generic-parser transactions\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-5\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n clearSignContextsOptional: [clearSignContexts[4]],\n clearSigningType: ClearSigningType.EIP7730,\n });\n });\n\n it(\"should exclude generic-parser contexts with a nano s device\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.14.0\" },\n deviceModelId: DeviceModelId.NANO_S,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts with an old app version\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should exclude generic-parser contexts with a non ready device\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.NOT_CONNECTED,\n deviceModelId: DeviceModelId.FLEX,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should return no clear sign context if the transaction info certificate is missing\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n },\n ];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.17.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildBaseContexts(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n });\n\n it(\"should not return web3check if the transaction is undefined\", async () => {\n // GIVEN\n const clearSignContexts: ClearSignContext[] = [];\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.17.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildBaseContexts(\n apiMock,\n { ...defaultArgs, transaction: undefined },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(getWeb3ChecksFactoryMock).not.toHaveBeenCalled();\n });\n});\n"],
|
|
5
|
+
"mappings": "AAAA,OAEE,wBAAAA,MAEK,2BACP,OACE,wBAAAC,EACA,iBAAAC,EACA,0BAAAC,EACA,gBAAAC,EACA,sBAAAC,EACA,8BAAAC,MACK,kCACP,OAAS,eAAAC,MAAmB,SAG5B,OAAS,oBAAAC,MAAwB,8BACjC,OAAS,mCAAAC,MAAuC,oEAEhD,OACE,6BAAAC,EACA,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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3B,cAAe,CAAC,EAChB,WAAY,CAAE,KAAM,WAAY,QAAS,QAAS,EAClD,cAAeF,EAAc,KAC7B,0BAA2B,EAC7B,CAAC,EAGD,MAAMuB,EAAS,MAAM,IAAId,EACvBO,EACAD,EACAE,CACF,EAAE,IAAI,EAGN,OAAOM,CAAM,EAAE,QAAQ,CACrB,kBAAmB,CAAC,EACpB,0BAA2B,CAAC,EAC5B,iBAAkBjB,EAAiB,KACrC,CAAC,CACH,CAAC,EAED,GAAG,8DAA+D,SAAY,CAE5E,MAAMe,EAAwC,CAAC,EAC/CV,EAAkB,YAAY,sBAAsBU,CAAiB,EACrEL,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkBf,EAAuB,0BACzC,aAAcC,EAAa,UAC3B,cAAe,CAAC,EAChB,WAAY,CAAE,KAAM,WAAY,QAAS,QAAS,EAClD,cAAeF,EAAc,KAC7B,0BAA2B,EAC7B,CAAC,EAGD,MAAM,IAAIS,EACRO,EACA,CAAE,GAAGD,EAAa,YAAa,MAAU,EACzCE,CACF,EAAE,IAAI,EAGN,OAAOA,CAAwB,EAAE,IAAI,iBAAiB,CACxD,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["ClearSignContextType", "CommandResultFactory", "DeviceModelId", "DeviceSessionStateType", "DeviceStatus", "hexaStringToBuffer", "UnknownDeviceExchangeError", "Transaction", "ClearSigningType", "makeDeviceActionInternalApiMock", "BASE_CONTEXT_TYPES_FILTER", "BuildBaseContexts", "GetWeb3CheckTask", "contextModuleMock", "defaultOptions", "defaultTransaction", "defaultCertificate", "defaultArgs", "apiMock", "getWeb3ChecksFactoryMock", "createAppConfig", "web3ChecksEnabled", "task", "clearSignContexts", "clearSignContextsOptional", "result", "expectedWeb3Check"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{ClearSignContextType as s}from"@ledgerhq/context-module";import{isSuccessCommandResult as r}from"@ledgerhq/device-management-kit";import{GetChallengeCommand as a}from"../../app-binder/command/GetChallengeCommand";class p{constructor(n,o){this._api=n;this._args=o}async run(){const n=await this._api.sendCommand(new a);if(!r(n))throw new Error("Failed to get challenge");const o=n.data.challenge,t=await this._args.contextModule.getContexts({safeContractAddress:this._args.safeContractAddress,chainId:this._args.options.chainId,deviceModelId:this._args.deviceModelId,challenge:o},[s.SAFE,s.SIGNER]);if(t.forEach(e=>{if(e.type===s.ERROR)throw new Error(e.error.message)}),t.length!==2||t.find(e=>e.type===s.SAFE)===void 0||t.find(e=>e.type===s.SIGNER)===void 0)throw new Error("Invalid safe address contexts");return{clearSignContexts:t}}}export{p as BuildSafeAddressContextTask};
|
|
2
|
+
//# sourceMappingURL=BuildSafeAddressContextTask.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/internal/app-binder/task/BuildSafeAddressContextTask.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n type ClearSignContextSuccess,\n ClearSignContextType,\n type ContextModule,\n} from \"@ledgerhq/context-module\";\nimport {\n type DeviceModelId,\n type InternalApi,\n isSuccessCommandResult,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { type SafeAddressOptions } from \"@api/model/SafeAddressOptions\";\nimport { GetChallengeCommand } from \"@internal/app-binder/command/GetChallengeCommand\";\n\nexport type BuildSafeAddressContextTaskArgs = {\n readonly contextModule: ContextModule;\n readonly safeContractAddress: string;\n readonly options: SafeAddressOptions;\n readonly deviceModelId: DeviceModelId;\n};\n\nexport type BuildSafeAddressContextTaskResult = {\n readonly clearSignContexts: ClearSignContextSuccess[];\n};\n\nexport class BuildSafeAddressContextTask {\n constructor(\n private readonly _api: InternalApi,\n private readonly _args: BuildSafeAddressContextTaskArgs,\n ) {}\n\n async run(): Promise<BuildSafeAddressContextTaskResult> {\n const challengeResponse = await this._api.sendCommand(\n new GetChallengeCommand(),\n );\n\n if (!isSuccessCommandResult(challengeResponse)) {\n throw new Error(\"Failed to get challenge\");\n }\n\n const challenge = challengeResponse.data.challenge;\n\n const contexts = await this._args.contextModule.getContexts(\n {\n safeContractAddress: this._args.safeContractAddress,\n chainId: this._args.options.chainId,\n deviceModelId: this._args.deviceModelId,\n challenge,\n },\n [ClearSignContextType.SAFE, ClearSignContextType.SIGNER],\n );\n\n contexts.forEach((context) => {\n if (context.type === ClearSignContextType.ERROR) {\n throw new Error(context.error.message);\n }\n });\n\n // should contain one SAFE and one SIGNER context\n if (\n contexts.length !== 2 ||\n contexts.find((context) => context.type === ClearSignContextType.SAFE) ===\n undefined ||\n contexts.find(\n (context) => context.type === ClearSignContextType.SIGNER,\n ) === undefined\n ) {\n throw new Error(\"Invalid safe address contexts\");\n }\n\n return {\n clearSignContexts: contexts as ClearSignContextSuccess[],\n };\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAEE,wBAAAA,MAEK,2BACP,OAGE,0BAAAC,MACK,kCAGP,OAAS,uBAAAC,MAA2B,mDAa7B,MAAMC,CAA4B,CACvC,YACmBC,EACAC,EACjB,CAFiB,UAAAD,EACA,WAAAC,CAChB,CAEH,MAAM,KAAkD,CACtD,MAAMC,EAAoB,MAAM,KAAK,KAAK,YACxC,IAAIJ,CACN,EAEA,GAAI,CAACD,EAAuBK,CAAiB,EAC3C,MAAM,IAAI,MAAM,yBAAyB,EAG3C,MAAMC,EAAYD,EAAkB,KAAK,UAEnCE,EAAW,MAAM,KAAK,MAAM,cAAc,YAC9C,CACE,oBAAqB,KAAK,MAAM,oBAChC,QAAS,KAAK,MAAM,QAAQ,QAC5B,cAAe,KAAK,MAAM,cAC1B,UAAAD,CACF,EACA,CAACP,EAAqB,KAAMA,EAAqB,MAAM,CACzD,EASA,GAPAQ,EAAS,QAASC,GAAY,CAC5B,GAAIA,EAAQ,OAAST,EAAqB,MACxC,MAAM,IAAI,MAAMS,EAAQ,MAAM,OAAO,CAEzC,CAAC,EAICD,EAAS,SAAW,GACpBA,EAAS,KAAMC,GAAYA,EAAQ,OAAST,EAAqB,IAAI,IACnE,QACFQ,EAAS,KACNC,GAAYA,EAAQ,OAAST,EAAqB,MACrD,IAAM,OAEN,MAAM,IAAI,MAAM,+BAA+B,EAGjD,MAAO,CACL,kBAAmBQ,CACrB,CACF,CACF",
|
|
6
|
+
"names": ["ClearSignContextType", "isSuccessCommandResult", "GetChallengeCommand", "BuildSafeAddressContextTask", "_api", "_args", "challengeResponse", "challenge", "contexts", "context"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{ClearSignContextType as a}from"@ledgerhq/context-module";import{CommandResultFactory as p,DeviceModelId as n}from"@ledgerhq/device-management-kit";import{makeDeviceActionInternalApiMock as v}from"../../app-binder/device-action/__test-utils__/makeInternalApi";import{BuildSafeAddressContextTask as l}from"./BuildSafeAddressContextTask";describe("BuildSafeAddressContextTask",()=>{const o=v(),e={getContexts:vi.fn(),getFieldContext:vi.fn(),getTypedDataFilters:vi.fn(),getWeb3Checks:vi.fn(),getSolanaContext:vi.fn()},S="0x12345678",d="0x1234567890123456789012345678901234567890",r=1,i=p({data:{challenge:S}}),h=p({data:void 0,error:{}}),C={type:a.SAFE,payload:"safe_payload"},x={type:a.SIGNER,payload:"signer_payload"};beforeEach(()=>{vi.resetAllMocks()}),describe("run",()=>{it("should successfully build safe address contexts with valid SAFE and SIGNER contexts",async()=>{const t={contextModule:e,safeContractAddress:d,options:{chainId:r},deviceModelId:n.FLEX};o.sendCommand.mockResolvedValue(i),e.getContexts=vi.fn().mockResolvedValue([C,x]);const c=await new l(o,t).run();expect(c).toEqual({clearSignContexts:[C,x]}),expect(o.sendCommand).toHaveBeenCalledTimes(1),expect(e.getContexts).toHaveBeenCalledWith({safeContractAddress:d,chainId:r,deviceModelId:n.FLEX,challenge:S},[a.SAFE,a.SIGNER])}),it("should include certificates when provided in contexts",async()=>{const t={type:a.SAFE,payload:"safe_payload",certificate:{keyUsageNumber:1,payload:new Uint8Array([1,2,3])}},s={type:a.SIGNER,payload:"signer_payload",certificate:{keyUsageNumber:2,payload:new Uint8Array([4,5,6])}},c={contextModule:e,safeContractAddress:d,options:{chainId:r},deviceModelId:n.FLEX};o.sendCommand.mockResolvedValue(i),e.getContexts=vi.fn().mockResolvedValue([t,s]);const g=await new l(o,c).run();expect(g).toEqual({clearSignContexts:[t,s]})})}),describe("error handling",()=>{it("should throw error when GetChallengeCommand fails",async()=>{const t={contextModule:e,safeContractAddress:d,options:{chainId:r},deviceModelId:n.FLEX};o.sendCommand.mockResolvedValue(h);const s=new l(o,t);await expect(s.run()).rejects.toThrow("Failed to get challenge")}),it("should throw error when context contains ERROR type",async()=>{const t={type:a.ERROR,error:new Error("Context error")},s={contextModule:e,safeContractAddress:d,options:{chainId:r},deviceModelId:n.FLEX};o.sendCommand.mockResolvedValue(i),e.getContexts=vi.fn().mockResolvedValue([t,x]);const c=new l(o,s);await expect(c.run()).rejects.toThrow("Context error")}),it("should throw error when only one context is returned",async()=>{const t={contextModule:e,safeContractAddress:d,options:{chainId:r},deviceModelId:n.FLEX};o.sendCommand.mockResolvedValue(i),e.getContexts=vi.fn().mockResolvedValue([C]);const s=new l(o,t);await expect(s.run()).rejects.toThrow("Invalid safe address contexts")}),it("should throw error when no contexts are returned",async()=>{const t={contextModule:e,safeContractAddress:d,options:{chainId:r},deviceModelId:n.FLEX};o.sendCommand.mockResolvedValue(i),e.getContexts=vi.fn().mockResolvedValue([]);const s=new l(o,t);await expect(s.run()).rejects.toThrow("Invalid safe address contexts")}),it("should throw error when more than two contexts are returned",async()=>{const t={type:a.TOKEN,payload:"extra_payload"},s={contextModule:e,safeContractAddress:d,options:{chainId:r},deviceModelId:n.FLEX};o.sendCommand.mockResolvedValue(i),e.getContexts=vi.fn().mockResolvedValue([C,x,t]);const c=new l(o,s);await expect(c.run()).rejects.toThrow("Invalid safe address contexts")}),it("should throw error when SAFE context is missing",async()=>{const t={contextModule:e,safeContractAddress:d,options:{chainId:r},deviceModelId:n.FLEX};o.sendCommand.mockResolvedValue(i),e.getContexts=vi.fn().mockResolvedValue([x,x]);const s=new l(o,t);await expect(s.run()).rejects.toThrow("Invalid safe address contexts")}),it("should throw error when SIGNER context is missing",async()=>{const t={contextModule:e,safeContractAddress:d,options:{chainId:r},deviceModelId:n.FLEX};o.sendCommand.mockResolvedValue(i),e.getContexts=vi.fn().mockResolvedValue([C,C]);const s=new l(o,t);await expect(s.run()).rejects.toThrow("Invalid safe address contexts")}),it("should throw error when contexts are of wrong types",async()=>{const t={type:a.TOKEN,payload:"token_payload"},s={type:a.NFT,payload:"nft_payload"},c={contextModule:e,safeContractAddress:d,options:{chainId:r},deviceModelId:n.FLEX};o.sendCommand.mockResolvedValue(i),e.getContexts=vi.fn().mockResolvedValue([t,s]);const u=new l(o,c);await expect(u.run()).rejects.toThrow("Invalid safe address contexts")}),it("should throw error with multiple ERROR contexts",async()=>{const t={type:a.ERROR,error:new Error("First error")},s={type:a.ERROR,error:new Error("Second error")},c={contextModule:e,safeContractAddress:d,options:{chainId:r},deviceModelId:n.FLEX};o.sendCommand.mockResolvedValue(i),e.getContexts=vi.fn().mockResolvedValue([t,s]);const u=new l(o,c);await expect(u.run()).rejects.toThrow("First error")})}),describe("device model variants",()=>{it.each([[n.NANO_S,"Nano S"],[n.NANO_SP,"Nano S Plus"],[n.NANO_X,"Nano X"],[n.FLEX,"Flex"],[n.STAX,"Stax"]])("should successfully build contexts for %s device",async(t,s)=>{const c={contextModule:e,safeContractAddress:d,options:{chainId:r},deviceModelId:t};o.sendCommand.mockResolvedValue(i),e.getContexts=vi.fn().mockResolvedValue([C,x]);const g=await new l(o,c).run();expect(g).toEqual({clearSignContexts:[C,x]}),expect(e.getContexts).toHaveBeenCalledWith(expect.objectContaining({deviceModelId:t}),[a.SAFE,a.SIGNER])})}),describe("challenge handling",()=>{it("should pass the correct challenge to contextModule",async()=>{const t="0xabcdef12",s={contextModule:e,safeContractAddress:d,options:{chainId:r},deviceModelId:n.FLEX};o.sendCommand.mockResolvedValue(p({data:{challenge:t}})),e.getContexts=vi.fn().mockResolvedValue([C,x]),await new l(o,s).run(),expect(e.getContexts).toHaveBeenCalledWith(expect.objectContaining({challenge:t}),[a.SAFE,a.SIGNER])})})});
|
|
2
|
+
//# sourceMappingURL=BuildSafeAddressContextTask.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/internal/app-binder/task/BuildSafeAddressContextTask.test.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n type ClearSignContext,\n type ClearSignContextSuccess,\n ClearSignContextType,\n type ContextModule,\n} from \"@ledgerhq/context-module\";\nimport {\n CommandResultFactory,\n DeviceModelId,\n type UnknownDeviceExchangeError,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\n\nimport {\n BuildSafeAddressContextTask,\n type BuildSafeAddressContextTaskArgs,\n} from \"./BuildSafeAddressContextTask\";\n\ndescribe(\"BuildSafeAddressContextTask\", () => {\n const apiMock = makeDeviceActionInternalApiMock();\n const contextModuleMock: ContextModule = {\n getContexts: vi.fn(),\n getFieldContext: vi.fn(),\n getTypedDataFilters: vi.fn(),\n getWeb3Checks: vi.fn(),\n getSolanaContext: vi.fn(),\n };\n\n const TEST_CHALLENGE = \"0x12345678\";\n const TEST_SAFE_ADDRESS = \"0x1234567890123456789012345678901234567890\";\n const TEST_CHAIN_ID = 1;\n\n const successChallengeResult = CommandResultFactory({\n data: { challenge: TEST_CHALLENGE },\n });\n\n const errorResult = CommandResultFactory({\n data: undefined,\n error: {} as UnknownDeviceExchangeError,\n });\n\n const validSafeContext: ClearSignContextSuccess<ClearSignContextType.SAFE> = {\n type: ClearSignContextType.SAFE,\n payload: \"safe_payload\",\n };\n\n const validSignerContext: ClearSignContextSuccess<ClearSignContextType.SIGNER> =\n {\n type: ClearSignContextType.SIGNER,\n payload: \"signer_payload\",\n };\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n describe(\"run\", () => {\n it(\"should successfully build safe address contexts with valid SAFE and SIGNER contexts\", async () => {\n // GIVEN\n const args: BuildSafeAddressContextTaskArgs = {\n contextModule: contextModuleMock,\n safeContractAddress: TEST_SAFE_ADDRESS,\n options: { chainId: TEST_CHAIN_ID },\n deviceModelId: DeviceModelId.FLEX,\n };\n apiMock.sendCommand.mockResolvedValue(successChallengeResult);\n contextModuleMock.getContexts = vi\n .fn()\n .mockResolvedValue([validSafeContext, validSignerContext]);\n\n // WHEN\n const task = new BuildSafeAddressContextTask(apiMock, args);\n const result = await task.run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [validSafeContext, validSignerContext],\n });\n expect(apiMock.sendCommand).toHaveBeenCalledTimes(1);\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith(\n {\n safeContractAddress: TEST_SAFE_ADDRESS,\n chainId: TEST_CHAIN_ID,\n deviceModelId: DeviceModelId.FLEX,\n challenge: TEST_CHALLENGE,\n },\n [ClearSignContextType.SAFE, ClearSignContextType.SIGNER],\n );\n });\n\n it(\"should include certificates when provided in contexts\", async () => {\n // GIVEN\n const safeContextWithCert: ClearSignContextSuccess<ClearSignContextType.SAFE> =\n {\n type: ClearSignContextType.SAFE,\n payload: \"safe_payload\",\n certificate: {\n keyUsageNumber: 1,\n payload: new Uint8Array([1, 2, 3]),\n },\n };\n const signerContextWithCert: ClearSignContextSuccess<ClearSignContextType.SIGNER> =\n {\n type: ClearSignContextType.SIGNER,\n payload: \"signer_payload\",\n certificate: {\n keyUsageNumber: 2,\n payload: new Uint8Array([4, 5, 6]),\n },\n };\n const args: BuildSafeAddressContextTaskArgs = {\n contextModule: contextModuleMock,\n safeContractAddress: TEST_SAFE_ADDRESS,\n options: { chainId: TEST_CHAIN_ID },\n deviceModelId: DeviceModelId.FLEX,\n };\n apiMock.sendCommand.mockResolvedValue(successChallengeResult);\n contextModuleMock.getContexts = vi\n .fn()\n .mockResolvedValue([safeContextWithCert, signerContextWithCert]);\n\n // WHEN\n const task = new BuildSafeAddressContextTask(apiMock, args);\n const result = await task.run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [safeContextWithCert, signerContextWithCert],\n });\n });\n });\n\n describe(\"error handling\", () => {\n it(\"should throw error when GetChallengeCommand fails\", async () => {\n // GIVEN\n const args: BuildSafeAddressContextTaskArgs = {\n contextModule: contextModuleMock,\n safeContractAddress: TEST_SAFE_ADDRESS,\n options: { chainId: TEST_CHAIN_ID },\n deviceModelId: DeviceModelId.FLEX,\n };\n apiMock.sendCommand.mockResolvedValue(errorResult);\n\n // WHEN\n const task = new BuildSafeAddressContextTask(apiMock, args);\n\n // THEN\n await expect(task.run()).rejects.toThrow(\"Failed to get challenge\");\n });\n\n it(\"should throw error when context contains ERROR type\", async () => {\n // GIVEN\n const errorContext: ClearSignContext = {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Context error\"),\n };\n const args: BuildSafeAddressContextTaskArgs = {\n contextModule: contextModuleMock,\n safeContractAddress: TEST_SAFE_ADDRESS,\n options: { chainId: TEST_CHAIN_ID },\n deviceModelId: DeviceModelId.FLEX,\n };\n apiMock.sendCommand.mockResolvedValue(successChallengeResult);\n contextModuleMock.getContexts = vi\n .fn()\n .mockResolvedValue([errorContext, validSignerContext]);\n\n // WHEN\n const task = new BuildSafeAddressContextTask(apiMock, args);\n\n // THEN\n await expect(task.run()).rejects.toThrow(\"Context error\");\n });\n\n it(\"should throw error when only one context is returned\", async () => {\n // GIVEN\n const args: BuildSafeAddressContextTaskArgs = {\n contextModule: contextModuleMock,\n safeContractAddress: TEST_SAFE_ADDRESS,\n options: { chainId: TEST_CHAIN_ID },\n deviceModelId: DeviceModelId.FLEX,\n };\n apiMock.sendCommand.mockResolvedValue(successChallengeResult);\n contextModuleMock.getContexts = vi\n .fn()\n .mockResolvedValue([validSafeContext]);\n\n // WHEN\n const task = new BuildSafeAddressContextTask(apiMock, args);\n\n // THEN\n await expect(task.run()).rejects.toThrow(\"Invalid safe address contexts\");\n });\n\n it(\"should throw error when no contexts are returned\", async () => {\n // GIVEN\n const args: BuildSafeAddressContextTaskArgs = {\n contextModule: contextModuleMock,\n safeContractAddress: TEST_SAFE_ADDRESS,\n options: { chainId: TEST_CHAIN_ID },\n deviceModelId: DeviceModelId.FLEX,\n };\n apiMock.sendCommand.mockResolvedValue(successChallengeResult);\n contextModuleMock.getContexts = vi.fn().mockResolvedValue([]);\n\n // WHEN\n const task = new BuildSafeAddressContextTask(apiMock, args);\n\n // THEN\n await expect(task.run()).rejects.toThrow(\"Invalid safe address contexts\");\n });\n\n it(\"should throw error when more than two contexts are returned\", async () => {\n // GIVEN\n const extraContext: ClearSignContextSuccess<ClearSignContextType.TOKEN> =\n {\n type: ClearSignContextType.TOKEN,\n payload: \"extra_payload\",\n };\n const args: BuildSafeAddressContextTaskArgs = {\n contextModule: contextModuleMock,\n safeContractAddress: TEST_SAFE_ADDRESS,\n options: { chainId: TEST_CHAIN_ID },\n deviceModelId: DeviceModelId.FLEX,\n };\n apiMock.sendCommand.mockResolvedValue(successChallengeResult);\n contextModuleMock.getContexts = vi\n .fn()\n .mockResolvedValue([\n validSafeContext,\n validSignerContext,\n extraContext,\n ]);\n\n // WHEN\n const task = new BuildSafeAddressContextTask(apiMock, args);\n\n // THEN\n await expect(task.run()).rejects.toThrow(\"Invalid safe address contexts\");\n });\n\n it(\"should throw error when SAFE context is missing\", async () => {\n // GIVEN\n const args: BuildSafeAddressContextTaskArgs = {\n contextModule: contextModuleMock,\n safeContractAddress: TEST_SAFE_ADDRESS,\n options: { chainId: TEST_CHAIN_ID },\n deviceModelId: DeviceModelId.FLEX,\n };\n apiMock.sendCommand.mockResolvedValue(successChallengeResult);\n contextModuleMock.getContexts = vi\n .fn()\n .mockResolvedValue([validSignerContext, validSignerContext]);\n\n // WHEN\n const task = new BuildSafeAddressContextTask(apiMock, args);\n\n // THEN\n await expect(task.run()).rejects.toThrow(\"Invalid safe address contexts\");\n });\n\n it(\"should throw error when SIGNER context is missing\", async () => {\n // GIVEN\n const args: BuildSafeAddressContextTaskArgs = {\n contextModule: contextModuleMock,\n safeContractAddress: TEST_SAFE_ADDRESS,\n options: { chainId: TEST_CHAIN_ID },\n deviceModelId: DeviceModelId.FLEX,\n };\n apiMock.sendCommand.mockResolvedValue(successChallengeResult);\n contextModuleMock.getContexts = vi\n .fn()\n .mockResolvedValue([validSafeContext, validSafeContext]);\n\n // WHEN\n const task = new BuildSafeAddressContextTask(apiMock, args);\n\n // THEN\n await expect(task.run()).rejects.toThrow(\"Invalid safe address contexts\");\n });\n\n it(\"should throw error when contexts are of wrong types\", async () => {\n // GIVEN\n const wrongContext1: ClearSignContextSuccess<ClearSignContextType.TOKEN> =\n {\n type: ClearSignContextType.TOKEN,\n payload: \"token_payload\",\n };\n const wrongContext2: ClearSignContextSuccess<ClearSignContextType.NFT> = {\n type: ClearSignContextType.NFT,\n payload: \"nft_payload\",\n };\n const args: BuildSafeAddressContextTaskArgs = {\n contextModule: contextModuleMock,\n safeContractAddress: TEST_SAFE_ADDRESS,\n options: { chainId: TEST_CHAIN_ID },\n deviceModelId: DeviceModelId.FLEX,\n };\n apiMock.sendCommand.mockResolvedValue(successChallengeResult);\n contextModuleMock.getContexts = vi\n .fn()\n .mockResolvedValue([wrongContext1, wrongContext2]);\n\n // WHEN\n const task = new BuildSafeAddressContextTask(apiMock, args);\n\n // THEN\n await expect(task.run()).rejects.toThrow(\"Invalid safe address contexts\");\n });\n\n it(\"should throw error with multiple ERROR contexts\", async () => {\n // GIVEN\n const errorContext1: ClearSignContext = {\n type: ClearSignContextType.ERROR,\n error: new Error(\"First error\"),\n };\n const errorContext2: ClearSignContext = {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Second error\"),\n };\n const args: BuildSafeAddressContextTaskArgs = {\n contextModule: contextModuleMock,\n safeContractAddress: TEST_SAFE_ADDRESS,\n options: { chainId: TEST_CHAIN_ID },\n deviceModelId: DeviceModelId.FLEX,\n };\n apiMock.sendCommand.mockResolvedValue(successChallengeResult);\n contextModuleMock.getContexts = vi\n .fn()\n .mockResolvedValue([errorContext1, errorContext2]);\n\n // WHEN\n const task = new BuildSafeAddressContextTask(apiMock, args);\n\n // THEN\n await expect(task.run()).rejects.toThrow(\"First error\");\n });\n });\n\n describe(\"device model variants\", () => {\n it.each([\n [DeviceModelId.NANO_S, \"Nano S\"],\n [DeviceModelId.NANO_SP, \"Nano S Plus\"],\n [DeviceModelId.NANO_X, \"Nano X\"],\n [DeviceModelId.FLEX, \"Flex\"],\n [DeviceModelId.STAX, \"Stax\"],\n ])(\n \"should successfully build contexts for %s device\",\n async (deviceModelId, _deviceName) => {\n // GIVEN\n const args: BuildSafeAddressContextTaskArgs = {\n contextModule: contextModuleMock,\n safeContractAddress: TEST_SAFE_ADDRESS,\n options: { chainId: TEST_CHAIN_ID },\n deviceModelId,\n };\n apiMock.sendCommand.mockResolvedValue(successChallengeResult);\n contextModuleMock.getContexts = vi\n .fn()\n .mockResolvedValue([validSafeContext, validSignerContext]);\n\n // WHEN\n const task = new BuildSafeAddressContextTask(apiMock, args);\n const result = await task.run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [validSafeContext, validSignerContext],\n });\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith(\n expect.objectContaining({\n deviceModelId,\n }),\n [ClearSignContextType.SAFE, ClearSignContextType.SIGNER],\n );\n },\n );\n });\n\n describe(\"challenge handling\", () => {\n it(\"should pass the correct challenge to contextModule\", async () => {\n // GIVEN\n const customChallenge = \"0xabcdef12\";\n const args: BuildSafeAddressContextTaskArgs = {\n contextModule: contextModuleMock,\n safeContractAddress: TEST_SAFE_ADDRESS,\n options: { chainId: TEST_CHAIN_ID },\n deviceModelId: DeviceModelId.FLEX,\n };\n apiMock.sendCommand.mockResolvedValue(\n CommandResultFactory({\n data: { challenge: customChallenge },\n }),\n );\n contextModuleMock.getContexts = vi\n .fn()\n .mockResolvedValue([validSafeContext, validSignerContext]);\n\n // WHEN\n const task = new BuildSafeAddressContextTask(apiMock, args);\n await task.run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith(\n expect.objectContaining({\n challenge: customChallenge,\n }),\n [ClearSignContextType.SAFE, ClearSignContextType.SIGNER],\n );\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "AAAA,OAGE,wBAAAA,MAEK,2BACP,OACE,wBAAAC,EACA,iBAAAC,MAEK,kCAEP,OAAS,mCAAAC,MAAuC,oEAEhD,OACE,+BAAAC,MAEK,gCAEP,SAAS,8BAA+B,IAAM,CAC5C,MAAMC,EAAUF,EAAgC,EAC1CG,EAAmC,CACvC,YAAa,GAAG,GAAG,EACnB,gBAAiB,GAAG,GAAG,EACvB,oBAAqB,GAAG,GAAG,EAC3B,cAAe,GAAG,GAAG,EACrB,iBAAkB,GAAG,GAAG,CAC1B,EAEMC,EAAiB,aACjBC,EAAoB,6CACpBC,EAAgB,EAEhBC,EAAyBT,EAAqB,CAClD,KAAM,CAAE,UAAWM,CAAe,CACpC,CAAC,EAEKI,EAAcV,EAAqB,CACvC,KAAM,OACN,MAAO,CAAC,CACV,CAAC,EAEKW,EAAuE,CAC3E,KAAMZ,EAAqB,KAC3B,QAAS,cACX,EAEMa,EACJ,CACE,KAAMb,EAAqB,OAC3B,QAAS,gBACX,EAEF,WAAW,IAAM,CACf,GAAG,cAAc,CACnB,CAAC,EAED,SAAS,MAAO,IAAM,CACpB,GAAG,sFAAuF,SAAY,CAEpG,MAAMc,EAAwC,CAC5C,cAAeR,EACf,oBAAqBE,EACrB,QAAS,CAAE,QAASC,CAAc,EAClC,cAAeP,EAAc,IAC/B,EACAG,EAAQ,YAAY,kBAAkBK,CAAsB,EAC5DJ,EAAkB,YAAc,GAC7B,GAAG,EACH,kBAAkB,CAACM,EAAkBC,CAAkB,CAAC,EAI3D,MAAME,EAAS,MADF,IAAIX,EAA4BC,EAASS,CAAI,EAChC,IAAI,EAG9B,OAAOC,CAAM,EAAE,QAAQ,CACrB,kBAAmB,CAACH,EAAkBC,CAAkB,CAC1D,CAA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AAsB,EAC5DJ,EAAkB,YAAc,GAC7B,GAAG,EACH,kBAAkB,CAACM,EAAkBC,CAAkB,CAAC,EAI3D,MAAME,EAAS,MADF,IAAIX,EAA4BC,EAASS,CAAI,EAChC,IAAI,EAG9B,OAAOC,CAAM,EAAE,QAAQ,CACrB,kBAAmB,CAACH,EAAkBC,CAAkB,CAC1D,CAAC,EACD,OAAOP,EAAkB,WAAW,EAAE,qBACpC,OAAO,iBAAiB,CACtB,cAAAmB,CACF,CAAC,EACD,CAACzB,EAAqB,KAAMA,EAAqB,MAAM,CACzD,CACF,CACF,CACF,CAAC,EAED,SAAS,qBAAsB,IAAM,CACnC,GAAG,qDAAsD,SAAY,CAEnE,MAAM2B,EAAkB,aAClBb,EAAwC,CAC5C,cAAeR,EACf,oBAAqBE,EACrB,QAAS,CAAE,QAASC,CAAc,EAClC,cAAeP,EAAc,IAC/B,EACAG,EAAQ,YAAY,kBAClBJ,EAAqB,CACnB,KAAM,CAAE,UAAW0B,CAAgB,CACrC,CAAC,CACH,EACArB,EAAkB,YAAc,GAC7B,GAAG,EACH,kBAAkB,CAACM,EAAkBC,CAAkB,CAAC,EAI3D,MADa,IAAIT,EAA4BC,EAASS,CAAI,EAC/C,IAAI,EAGf,OAAOR,EAAkB,WAAW,EAAE,qBACpC,OAAO,iBAAiB,CACtB,UAAWqB,CACb,CAAC,EACD,CAAC3B,EAAqB,KAAMA,EAAqB,MAAM,CACzD,CACF,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["ClearSignContextType", "CommandResultFactory", "DeviceModelId", "makeDeviceActionInternalApiMock", "BuildSafeAddressContextTask", "apiMock", "contextModuleMock", "TEST_CHALLENGE", "TEST_SAFE_ADDRESS", "TEST_CHAIN_ID", "successChallengeResult", "errorResult", "validSafeContext", "validSignerContext", "args", "result", "safeContextWithCert", "signerContextWithCert", "task", "errorContext", "extraContext", "wrongContext1", "wrongContext2", "errorContext1", "errorContext2", "deviceModelId", "_deviceName", "customChallenge"]
|
|
7
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
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,deviceModelId:this.args.deviceModelId},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};
|
|
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:case t.SAFE:case t.SIGNER: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,deviceModelId:this.args.deviceModelId},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 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 deviceModelId: this.args.deviceModelId,\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,
|
|
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 case ClearSignContextType.SAFE:\n case ClearSignContextType.SIGNER:\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 deviceModelId: this.args.deviceModelId,\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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kB,EAO3B,MAAM,KAAK,KAAK,cAAc,gBAC/C,CACE,QAAS,KAAK,KAAK,OAAO,QAC1B,QAAAL,EACA,UAAWK,EAAmB,KAAK,UACnC,MAAOb,EAAU,MACjB,QAASA,EAAU,QACnB,cAAe,KAAK,KAAK,aAC3B,EACAV,EAAqB,YACvB,EAhBS,CACL,KAAMA,EAAqB,MAC3B,MAAO,IAAI,MAAM,yBAAyB,CAC5C,CAgBJ,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
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
|
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{ClearSignContextType as t}from"@ledgerhq/context-module";import{CommandResultFactory as u,InvalidStatusWordError as c,LoadCertificateCommand as C}from"@ledgerhq/device-management-kit";import{ProvideEnumCommand as h}from"../../app-binder/command/ProvideEnumCommand";import{NetworkConfigurationType as i,ProvideNetworkConfigurationCommand as s}from"../../app-binder/command/ProvideNetworkConfigurationCommand";import{ProvideNFTInformationCommand as k}from"../../app-binder/command/ProvideNFTInformationCommand";import{ProvideProxyInfoCommand as p}from"../../app-binder/command/ProvideProxyInfoCommand";import{ProvideSafeAccountCommand as d,ProvideSafeAccountCommandType as m}from"../../app-binder/command/ProvideSafeAccountCommand";import{ProvideTokenInformationCommand as y}from"../../app-binder/command/ProvideTokenInformationCommand";import{ProvideTransactionFieldDescriptionCommand as F}from"../../app-binder/command/ProvideTransactionFieldDescriptionCommand";import{ProvideTransactionInformationCommand as T}from"../../app-binder/command/ProvideTransactionInformationCommand";import{ProvideTrustedNameCommand as I}from"../../app-binder/command/ProvideTrustedNameCommand";import{ProvideWeb3CheckCommand as P}from"../../app-binder/command/ProvideWeb3CheckCommand";import{SetExternalPluginCommand as _}from"../../app-binder/command/SetExternalPluginCommand";import{SetPluginCommand as l}from"../../app-binder/command/SetPluginCommand";import{SendPayloadInChunksTask as f}from"./SendPayloadInChunksTask";class M{constructor(r,n,o=(a,e)=>new f(a,e)){this._api=r;this._args=n;this._sendPayloadInChunksTaskFactory=o}async run(){const{type:r,payload:n,certificate:o}=this._args.context;switch(o&&await this._api.sendCommand(new C({keyUsage:o.keyUsageNumber,certificate:o.payload})),r){case t.PLUGIN:return await this._api.sendCommand(new l({payload:n}));case t.EXTERNAL_PLUGIN:return await this._api.sendCommand(new _({payload:n}));case t.NFT:return await this._api.sendCommand(new k({payload:n}));case t.TOKEN:return await this._api.sendCommand(new y({payload:n}));case t.TRANSACTION_INFO:return await this._sendPayloadInChunksTaskFactory(this._api,{payload:n,commandFactory:e=>new T({data:e.chunkedData,isFirstChunk:e.isFirstChunk})}).run();case t.TRUSTED_NAME:return this._sendPayloadInChunksTaskFactory(this._api,{payload:n,commandFactory:a=>new I({data:a.chunkedData,isFirstChunk:a.isFirstChunk})}).run();case t.ENUM:return this._sendPayloadInChunksTaskFactory(this._api,{payload:n,commandFactory:a=>new h({data:a.chunkedData,isFirstChunk:a.isFirstChunk})}).run();case t.TRANSACTION_FIELD_DESCRIPTION:return this._sendPayloadInChunksTaskFactory(this._api,{payload:n,commandFactory:a=>new F({data:a.chunkedData,isFirstChunk:a.isFirstChunk})}).run();case t.WEB3_CHECK:return this._sendPayloadInChunksTaskFactory(this._api,{payload:n,commandFactory:a=>new P({payload:a.chunkedData,isFirstChunk:a.isFirstChunk})}).run();case t.PROXY_INFO:return this._sendPayloadInChunksTaskFactory(this._api,{payload:n,commandFactory:a=>new p({data:a.chunkedData,isFirstChunk:a.isFirstChunk})}).run();case t.DYNAMIC_NETWORK:return this._sendPayloadInChunksTaskFactory(this._api,{payload:n,commandFactory:a=>new s({data:a.chunkedData,isFirstChunk:a.isFirstChunk,configurationType:i.CONFIGURATION})}).run();case t.DYNAMIC_NETWORK_ICON:return this._sendPayloadInChunksTaskFactory(this._api,{payload:n,commandFactory:a=>new s({data:a.chunkedData,isFirstChunk:a.isFirstChunk,configurationType:i.ICON}),withPayloadLength:!1}).run();case t.SAFE:return this._sendPayloadInChunksTaskFactory(this._api,{payload:n,commandFactory:a=>new d({data:a.chunkedData,isFirstChunk:a.isFirstChunk,type:m.SAFE_DESCRIPTOR})}).run();case t.SIGNER:return this._sendPayloadInChunksTaskFactory(this._api,{payload:n,commandFactory:a=>new d({data:a.chunkedData,isFirstChunk:a.isFirstChunk,type:m.SIGNER_DESCRIPTOR})}).run();default:{const a=r;return u({error:new c(`The context type [${a}] is not covered`)})}}}}export{M as ProvideContextTask};
|
|
2
|
+
//# sourceMappingURL=ProvideContextTask.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/internal/app-binder/task/ProvideContextTask.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n type ClearSignContextSuccess,\n ClearSignContextType,\n} from \"@ledgerhq/context-module\";\nimport {\n type CommandResult,\n CommandResultFactory,\n type InternalApi,\n InvalidStatusWordError,\n LoadCertificateCommand,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { ProvideEnumCommand } from \"@internal/app-binder/command/ProvideEnumCommand\";\nimport {\n NetworkConfigurationType,\n ProvideNetworkConfigurationCommand,\n} from \"@internal/app-binder/command/ProvideNetworkConfigurationCommand\";\nimport { ProvideNFTInformationCommand } from \"@internal/app-binder/command/ProvideNFTInformationCommand\";\nimport { ProvideProxyInfoCommand } from \"@internal/app-binder/command/ProvideProxyInfoCommand\";\nimport {\n ProvideSafeAccountCommand,\n ProvideSafeAccountCommandType,\n} from \"@internal/app-binder/command/ProvideSafeAccountCommand\";\nimport { ProvideTokenInformationCommand } from \"@internal/app-binder/command/ProvideTokenInformationCommand\";\nimport { ProvideTransactionFieldDescriptionCommand } from \"@internal/app-binder/command/ProvideTransactionFieldDescriptionCommand\";\nimport { ProvideTransactionInformationCommand } from \"@internal/app-binder/command/ProvideTransactionInformationCommand\";\nimport { ProvideTrustedNameCommand } from \"@internal/app-binder/command/ProvideTrustedNameCommand\";\nimport { ProvideWeb3CheckCommand } from \"@internal/app-binder/command/ProvideWeb3CheckCommand\";\nimport { SetExternalPluginCommand } from \"@internal/app-binder/command/SetExternalPluginCommand\";\nimport { SetPluginCommand } from \"@internal/app-binder/command/SetPluginCommand\";\nimport { type EthErrorCodes } from \"@internal/app-binder/command/utils/ethAppErrors\";\n\nimport {\n SendPayloadInChunksTask,\n type SendPayloadInChunksTaskArgs,\n} from \"./SendPayloadInChunksTask\";\n\nexport type ProvideContextTaskArgs = {\n /**\n * The clear sign context to provide.\n */\n context: ClearSignContextSuccess;\n};\n\nexport type ProvideContextTaskResult = CommandResult<unknown, EthErrorCodes>;\n\n/**\n * This task is responsible for providing a single context to the device.\n */\nexport class ProvideContextTask {\n constructor(\n private _api: InternalApi,\n private _args: ProvideContextTaskArgs,\n private _sendPayloadInChunksTaskFactory = (\n api: InternalApi,\n args: SendPayloadInChunksTaskArgs<unknown>,\n ) => new SendPayloadInChunksTask(api, args),\n ) {}\n\n async run(): Promise<ProvideContextTaskResult> {\n const { type, payload, certificate } = this._args.context;\n\n // if a certificate is provided, we load it before sending the command\n if (certificate) {\n await this._api.sendCommand(\n new LoadCertificateCommand({\n keyUsage: certificate.keyUsageNumber,\n certificate: certificate.payload,\n }),\n );\n }\n\n switch (type) {\n case ClearSignContextType.PLUGIN: {\n return await this._api.sendCommand(new SetPluginCommand({ payload }));\n }\n case ClearSignContextType.EXTERNAL_PLUGIN: {\n return await this._api.sendCommand(\n new SetExternalPluginCommand({ payload }),\n );\n }\n case ClearSignContextType.NFT: {\n return await this._api.sendCommand(\n new ProvideNFTInformationCommand({ payload }),\n );\n }\n case ClearSignContextType.TOKEN: {\n return await this._api.sendCommand(\n new ProvideTokenInformationCommand({ payload }),\n );\n }\n case ClearSignContextType.TRANSACTION_INFO: {\n const transactionInfoResult =\n await this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideTransactionInformationCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n\n return transactionInfoResult;\n }\n case ClearSignContextType.TRUSTED_NAME: {\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideTrustedNameCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n }\n case ClearSignContextType.ENUM:\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideEnumCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n case ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideTransactionFieldDescriptionCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n case ClearSignContextType.WEB3_CHECK:\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideWeb3CheckCommand({\n payload: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n case ClearSignContextType.PROXY_INFO:\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideProxyInfoCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n case ClearSignContextType.DYNAMIC_NETWORK:\n // Dynamic network configuration uses the existing ProvideNetworkConfiguration command\n // but is provided as part of the context flow\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideNetworkConfigurationCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n configurationType: NetworkConfigurationType.CONFIGURATION,\n }),\n }).run();\n case ClearSignContextType.DYNAMIC_NETWORK_ICON: {\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideNetworkConfigurationCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n configurationType: NetworkConfigurationType.ICON,\n }),\n withPayloadLength: false,\n }).run();\n }\n case ClearSignContextType.SAFE:\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideSafeAccountCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n type: ProvideSafeAccountCommandType.SAFE_DESCRIPTOR,\n }),\n }).run();\n case ClearSignContextType.SIGNER:\n return this._sendPayloadInChunksTaskFactory(this._api, {\n payload,\n commandFactory: (args) =>\n new ProvideSafeAccountCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n type: ProvideSafeAccountCommandType.SIGNER_DESCRIPTOR,\n }),\n }).run();\n default: {\n const uncoveredType: never = type;\n return CommandResultFactory({\n error: new InvalidStatusWordError(\n `The context type [${uncoveredType}] is not covered`,\n ),\n });\n }\n }\n }\n}\n"],
|
|
5
|
+
"m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f,IAAIlB,EAAmC,CACrC,KAAMkB,EAAK,YACX,aAAcA,EAAK,aACnB,kBAAmBnB,EAAyB,aAC9C,CAAC,CACL,CAAC,EAAE,IAAI,EACT,KAAKL,EAAqB,qBACxB,OAAO,KAAK,gCAAgC,KAAK,KAAM,CACrD,QAAA0B,EACA,eAAiBF,GACf,IAAIlB,EAAmC,CACrC,KAAMkB,EAAK,YACX,aAAcA,EAAK,aACnB,kBAAmBnB,EAAyB,IAC9C,CAAC,EACH,kBAAmB,EACrB,CAAC,EAAE,IAAI,EAET,KAAKL,EAAqB,KACxB,OAAO,KAAK,gCAAgC,KAAK,KAAM,CACrD,QAAA0B,EACA,eAAiBF,GACf,IAAIf,EAA0B,CAC5B,KAAMe,EAAK,YACX,aAAcA,EAAK,aACnB,KAAMd,EAA8B,eACtC,CAAC,CACL,CAAC,EAAE,IAAI,EACT,KAAKV,EAAqB,OACxB,OAAO,KAAK,gCAAgC,KAAK,KAAM,CACrD,QAAA0B,EACA,eAAiBF,GACf,IAAIf,EAA0B,CAC5B,KAAMe,EAAK,YACX,aAAcA,EAAK,aACnB,KAAMd,EAA8B,iBACtC,CAAC,CACL,CAAC,EAAE,IAAI,EACT,QAAS,CACP,MAAMkB,EAAuBH,EAC7B,OAAOxB,EAAqB,CAC1B,MAAO,IAAIC,EACT,qBAAqB0B,CAAa,kBACpC,CACF,CAAC,CACH,CACF,CACF,CACF",
|
|
6
|
+
"names": ["ClearSignContextType", "CommandResultFactory", "InvalidStatusWordError", "LoadCertificateCommand", "ProvideEnumCommand", "NetworkConfigurationType", "ProvideNetworkConfigurationCommand", "ProvideNFTInformationCommand", "ProvideProxyInfoCommand", "ProvideSafeAccountCommand", "ProvideSafeAccountCommandType", "ProvideTokenInformationCommand", "ProvideTransactionFieldDescriptionCommand", "ProvideTransactionInformationCommand", "ProvideTrustedNameCommand", "ProvideWeb3CheckCommand", "SetExternalPluginCommand", "SetPluginCommand", "SendPayloadInChunksTask", "ProvideContextTask", "_api", "_args", "_sendPayloadInChunksTaskFactory", "api", "args", "type", "payload", "certificate", "uncoveredType"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{ClearSignContextType as a}from"@ledgerhq/context-module";import{CommandResultFactory as u,InvalidStatusWordError as E,LoadCertificateCommand as k}from"@ledgerhq/device-management-kit";import{ProvideEnumCommand as A}from"../../app-binder/command/ProvideEnumCommand";import{NetworkConfigurationType as x,ProvideNetworkConfigurationCommand as T}from"../../app-binder/command/ProvideNetworkConfigurationCommand";import{ProvideNFTInformationCommand as I}from"../../app-binder/command/ProvideNFTInformationCommand";import{ProvideProxyInfoCommand as P}from"../../app-binder/command/ProvideProxyInfoCommand";import{ProvideSafeAccountCommand as h,ProvideSafeAccountCommandType as f}from"../../app-binder/command/ProvideSafeAccountCommand";import{ProvideTokenInformationCommand as C}from"../../app-binder/command/ProvideTokenInformationCommand";import{ProvideTransactionFieldDescriptionCommand as N}from"../../app-binder/command/ProvideTransactionFieldDescriptionCommand";import{ProvideTransactionInformationCommand as v}from"../../app-binder/command/ProvideTransactionInformationCommand";import{ProvideTrustedNameCommand as F}from"../../app-binder/command/ProvideTrustedNameCommand";import{ProvideWeb3CheckCommand as R}from"../../app-binder/command/ProvideWeb3CheckCommand";import{SetExternalPluginCommand as O}from"../../app-binder/command/SetExternalPluginCommand";import{SetPluginCommand as B}from"../../app-binder/command/SetPluginCommand";import{makeDeviceActionInternalApiMock as S}from"../../app-binder/device-action/__test-utils__/makeInternalApi";import{ProvideContextTask as l}from"./ProvideContextTask";import{SendPayloadInChunksTask as D}from"./SendPayloadInChunksTask";describe("ProvideContextTask",()=>{const e=S(),n=u({data:void 0}),y=u({data:void 0,error:{}});beforeEach(()=>{vi.resetAllMocks()}),describe("run",()=>{const r=vi.fn(),s=vi.fn();beforeEach(()=>{vi.clearAllMocks(),s.mockImplementation((t,c)=>({run:()=>r(t,c)}))}),describe("contexts with sendCommand",()=>{it.each([[a.PLUGIN,B],[a.EXTERNAL_PLUGIN,O],[a.NFT,I],[a.TOKEN,C]])("should provide context by calling sendCommand for a %s context",async(t,c)=>{const o={context:{type:t,payload:"payload"}};e.sendCommand.mockResolvedValue(n);const i=await new l(e,o,s).run();expect(i).toEqual(n),expect(e.sendCommand).toHaveBeenCalledTimes(1),expect(e.sendCommand).toHaveBeenCalledWith(expect.any(c))})}),describe("contexts with sendPayloadInChunksTask",()=>{it.each([[a.TRANSACTION_INFO,v],[a.TRUSTED_NAME,F],[a.ENUM,A],[a.TRANSACTION_FIELD_DESCRIPTION,N],[a.WEB3_CHECK,R],[a.PROXY_INFO,P]])("should provide context by calling sendPayloadInChunksTask for a %s context",async(t,c)=>{const o={context:{type:t,payload:"payload"}};r.mockResolvedValue(n);const i=await new l(e,o,s).run();expect(i).toEqual(n),expect(r).toHaveBeenCalledTimes(1),expect(r).toHaveBeenCalledWith(e,{payload:"payload",commandFactory:expect.any(Function)});const d=s.mock.calls[0][1].commandFactory,g={chunkedData:new Uint8Array([1,2,3]),isFirstChunk:!0},w=d(g);expect(w).toBeInstanceOf(c)}),it("should provide context for DYNAMIC_NETWORK with correct configuration type",async()=>{const t={context:{type:a.DYNAMIC_NETWORK,payload:"payload"}};r.mockResolvedValue(n);const o=await new l(e,t,s).run();expect(o).toEqual(n),expect(r).toHaveBeenCalledTimes(1);const i=s.mock.calls[0][1].commandFactory,m={chunkedData:new Uint8Array([1,2,3]),isFirstChunk:!0},d=i(m);expect(d).toBeInstanceOf(T),expect(d.args.configurationType).toBe(x.CONFIGURATION)}),it("should provide context for DYNAMIC_NETWORK_ICON with correct configuration type and withPayloadLength",async()=>{const t={context:{type:a.DYNAMIC_NETWORK_ICON,payload:"payload"}};r.mockResolvedValue(n);const o=await new l(e,t,s).run();expect(o).toEqual(n),expect(r).toHaveBeenCalledTimes(1),expect(r).toHaveBeenCalledWith(e,{payload:"payload",commandFactory:expect.any(Function),withPayloadLength:!1});const i=s.mock.calls[0][1].commandFactory,m={chunkedData:new Uint8Array([1,2,3]),isFirstChunk:!0},d=i(m);expect(d).toBeInstanceOf(T),expect(d.args.configurationType).toBe(x.ICON)}),it("should provide context for SAFE with correct type",async()=>{const t={context:{type:a.SAFE,payload:"payload"}};r.mockResolvedValue(n);const o=await new l(e,t,s).run();expect(o).toEqual(n),expect(r).toHaveBeenCalledTimes(1);const i=s.mock.calls[0][1].commandFactory,m={chunkedData:new Uint8Array([1,2,3]),isFirstChunk:!0},d=i(m);expect(d).toBeInstanceOf(h),expect(d.args.type).toBe(f.SAFE_DESCRIPTOR)}),it("should provide context for SIGNER with correct type",async()=>{const t={context:{type:a.SIGNER,payload:"payload"}};r.mockResolvedValue(n);const o=await new l(e,t,s).run();expect(o).toEqual(n),expect(r).toHaveBeenCalledTimes(1);const i=s.mock.calls[0][1].commandFactory,m={chunkedData:new Uint8Array([1,2,3]),isFirstChunk:!0},d=i(m);expect(d).toBeInstanceOf(h),expect(d.args.type).toBe(f.SIGNER_DESCRIPTOR)})}),describe("with certificate",()=>{it("should load certificate before providing context when certificate is present",async()=>{const t={context:{type:a.TOKEN,payload:"payload",certificate:{keyUsageNumber:1,payload:new Uint8Array([1,2,3])}}};e.sendCommand.mockResolvedValue(n);const o=await new l(e,t,s).run();expect(o).toEqual(n),expect(e.sendCommand).toHaveBeenCalledTimes(2),expect(e.sendCommand).toHaveBeenNthCalledWith(1,expect.any(k)),expect(e.sendCommand).toHaveBeenNthCalledWith(2,expect.any(C))}),it("should load certificate with sendPayloadInChunksTask context",async()=>{const t={context:{type:a.TRANSACTION_INFO,payload:"payload",certificate:{keyUsageNumber:2,payload:new Uint8Array([4,5,6])}}};e.sendCommand.mockResolvedValue(n),r.mockResolvedValue(n);const o=await new l(e,t,s).run();expect(o).toEqual(n),expect(e.sendCommand).toHaveBeenCalledTimes(1),expect(e.sendCommand).toHaveBeenCalledWith(expect.any(k)),expect(r).toHaveBeenCalledTimes(1)}),it("should not load certificate when not present",async()=>{const t={context:{type:a.TOKEN,payload:"payload"}};e.sendCommand.mockResolvedValue(n);const o=await new l(e,t,s).run();expect(o).toEqual(n),expect(e.sendCommand).toHaveBeenCalledTimes(1),expect(e.sendCommand).toHaveBeenCalledWith(expect.any(C))})}),describe("error handling",()=>{it("should return error when sendCommand fails",async()=>{const t={context:{type:a.NFT,payload:"payload"}};e.sendCommand.mockResolvedValue(y);const o=await new l(e,t,s).run();expect(o).toEqual(y)}),it("should return error when sendPayloadInChunksTask fails",async()=>{const t={context:{type:a.TRUSTED_NAME,payload:"payload"}};r.mockResolvedValue(y);const o=await new l(e,t,s).run();expect(o).toEqual(y)}),it("should return error for unsupported context type",async()=>{const t={context:{type:"unsupported",payload:"payload"}},o=await new l(e,t,s).run();expect(o).toEqual(u({error:new E("The context type [unsupported] is not covered")}))})}),describe("factory",()=>{it("should have a default sendPayloadInChunksTaskFactory",()=>{const t={context:{type:a.TOKEN,payload:"payload"}},c=new l(e,t);expect(c._sendPayloadInChunksTaskFactory).toBeDefined();const o=c._sendPayloadInChunksTaskFactory(e,{payload:"payload",commandFactory:()=>new v({data:new Uint8Array,isFirstChunk:!0})});expect(o).toBeInstanceOf(D)})})})});
|
|
2
|
+
//# sourceMappingURL=ProvideContextTask.test.js.map
|