@ledgerhq/device-signer-kit-ethereum 0.0.0-fix-rn-ble-20250502084951 → 0.0.0-hid-candidate-2-20250526084932
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/api/app-binder/SignTransactionDeviceActionTypes.js +1 -1
- package/lib/cjs/api/app-binder/SignTransactionDeviceActionTypes.js.map +2 -2
- package/lib/cjs/api/app-binder/SignTypedDataDeviceActionTypes.js +1 -1
- package/lib/cjs/api/app-binder/SignTypedDataDeviceActionTypes.js.map +2 -2
- package/lib/cjs/internal/address/di/addressModule.js +1 -1
- package/lib/cjs/internal/address/di/addressModule.js.map +3 -3
- package/lib/cjs/internal/address/di/addressModule.test.js +1 -1
- package/lib/cjs/internal/address/di/addressModule.test.js.map +2 -2
- package/lib/cjs/internal/address/use-case/GetAddressUseCase.js +1 -1
- package/lib/cjs/internal/address/use-case/GetAddressUseCase.js.map +2 -2
- package/lib/cjs/internal/address/use-case/GetAddressUseCase.test.js +1 -1
- package/lib/cjs/internal/address/use-case/GetAddressUseCase.test.js.map +2 -2
- package/lib/cjs/internal/app-binder/EthAppBinder.js.map +1 -1
- package/lib/cjs/internal/app-binder/EthAppBinder.test.js +1 -1
- package/lib/cjs/internal/app-binder/EthAppBinder.test.js.map +2 -2
- package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js +1 -1
- package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js.map +2 -2
- package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js +1 -1
- package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js.map +2 -2
- package/lib/cjs/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.js +1 -1
- package/lib/cjs/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.js.map +3 -3
- package/lib/cjs/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.test.js +1 -1
- package/lib/cjs/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.test.js.map +2 -2
- package/lib/cjs/internal/app-binder/device-action/__test-utils__/makeInternalApi.js +1 -1
- package/lib/cjs/internal/app-binder/device-action/__test-utils__/makeInternalApi.js.map +3 -3
- package/lib/cjs/internal/app-binder/di/appBinderModule.js +1 -1
- package/lib/cjs/internal/app-binder/di/appBinderModule.js.map +3 -3
- package/lib/cjs/internal/app-binder/task/BuildEIP712ContextTask.js +1 -1
- package/lib/cjs/internal/app-binder/task/BuildEIP712ContextTask.js.map +3 -3
- package/lib/cjs/internal/app-binder/task/BuildEIP712ContextTask.test.js +1 -1
- package/lib/cjs/internal/app-binder/task/BuildEIP712ContextTask.test.js.map +2 -2
- package/lib/cjs/internal/app-binder/task/BuildTransactionContextTask.js +1 -1
- package/lib/cjs/internal/app-binder/task/BuildTransactionContextTask.js.map +2 -2
- package/lib/cjs/internal/app-binder/task/BuildTransactionContextTask.test.js +1 -1
- package/lib/cjs/internal/app-binder/task/BuildTransactionContextTask.test.js.map +2 -2
- package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.js.map +2 -2
- package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.test.js +1 -1
- package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.test.js.map +2 -2
- package/lib/cjs/internal/app-binder/task/SignTypedDataLegacyTask.js +2 -0
- package/lib/cjs/internal/app-binder/task/SignTypedDataLegacyTask.js.map +7 -0
- package/lib/cjs/internal/app-binder/task/SignTypedDataLegacyTask.test.js +2 -0
- package/lib/cjs/internal/app-binder/task/SignTypedDataLegacyTask.test.js.map +7 -0
- package/lib/cjs/internal/di.js +1 -1
- package/lib/cjs/internal/di.js.map +2 -2
- package/lib/cjs/internal/message/di/messageModule.js +1 -1
- package/lib/cjs/internal/message/di/messageModule.js.map +3 -3
- package/lib/cjs/internal/message/di/messageModule.test.js +1 -1
- package/lib/cjs/internal/message/di/messageModule.test.js.map +2 -2
- package/lib/cjs/internal/message/use-case/SignMessageUseCase.js +1 -1
- package/lib/cjs/internal/message/use-case/SignMessageUseCase.js.map +2 -2
- package/lib/cjs/internal/message/use-case/SignMessageUseCase.test.js +1 -1
- package/lib/cjs/internal/message/use-case/SignMessageUseCase.test.js.map +2 -2
- package/lib/cjs/internal/transaction/di/transactionModule.js +1 -1
- package/lib/cjs/internal/transaction/di/transactionModule.js.map +3 -3
- package/lib/cjs/internal/transaction/di/transactionModule.test.js +1 -1
- package/lib/cjs/internal/transaction/di/transactionModule.test.js.map +2 -2
- package/lib/cjs/internal/typed-data/di/typedDataModule.js +1 -1
- package/lib/cjs/internal/typed-data/di/typedDataModule.js.map +3 -3
- package/lib/cjs/internal/typed-data/di/typedDataModule.test.js +1 -1
- package/lib/cjs/internal/typed-data/di/typedDataModule.test.js.map +2 -2
- package/lib/cjs/internal/typed-data/service/DefaultTypedDataParserService.js +1 -1
- package/lib/cjs/internal/typed-data/service/DefaultTypedDataParserService.js.map +2 -2
- package/lib/cjs/internal/typed-data/service/TypedDataParser.js +1 -1
- package/lib/cjs/internal/typed-data/service/TypedDataParser.js.map +3 -3
- package/lib/cjs/internal/typed-data/service/TypedDataParser.test.js +1 -1
- package/lib/cjs/internal/typed-data/service/TypedDataParser.test.js.map +2 -2
- package/lib/cjs/internal/typed-data/use-case/SignTypedDataUseCase.js +1 -1
- package/lib/cjs/internal/typed-data/use-case/SignTypedDataUseCase.js.map +2 -2
- package/lib/cjs/internal/typed-data/use-case/SignTypedDataUseCase.test.js +1 -1
- package/lib/cjs/internal/typed-data/use-case/SignTypedDataUseCase.test.js.map +2 -2
- package/lib/cjs/package.json +13 -14
- package/lib/esm/api/app-binder/SignTransactionDeviceActionTypes.js +1 -1
- package/lib/esm/api/app-binder/SignTransactionDeviceActionTypes.js.map +2 -2
- package/lib/esm/api/app-binder/SignTypedDataDeviceActionTypes.js +1 -1
- package/lib/esm/api/app-binder/SignTypedDataDeviceActionTypes.js.map +2 -2
- package/lib/esm/internal/address/di/addressModule.js +1 -1
- package/lib/esm/internal/address/di/addressModule.js.map +3 -3
- package/lib/esm/internal/address/di/addressModule.test.js +1 -1
- package/lib/esm/internal/address/di/addressModule.test.js.map +2 -2
- package/lib/esm/internal/address/use-case/GetAddressUseCase.js +1 -1
- package/lib/esm/internal/address/use-case/GetAddressUseCase.js.map +2 -2
- package/lib/esm/internal/address/use-case/GetAddressUseCase.test.js +1 -1
- package/lib/esm/internal/address/use-case/GetAddressUseCase.test.js.map +2 -2
- package/lib/esm/internal/app-binder/EthAppBinder.js.map +1 -1
- package/lib/esm/internal/app-binder/EthAppBinder.test.js +1 -1
- package/lib/esm/internal/app-binder/EthAppBinder.test.js.map +2 -2
- package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js +1 -1
- package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js.map +2 -2
- package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js +1 -1
- package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js.map +2 -2
- package/lib/esm/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.js +1 -1
- package/lib/esm/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.js.map +3 -3
- package/lib/esm/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.test.js +1 -1
- package/lib/esm/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.test.js.map +2 -2
- package/lib/esm/internal/app-binder/device-action/__test-utils__/makeInternalApi.js +1 -1
- package/lib/esm/internal/app-binder/device-action/__test-utils__/makeInternalApi.js.map +3 -3
- package/lib/esm/internal/app-binder/di/appBinderModule.js +1 -1
- package/lib/esm/internal/app-binder/di/appBinderModule.js.map +3 -3
- package/lib/esm/internal/app-binder/task/BuildEIP712ContextTask.js +1 -1
- package/lib/esm/internal/app-binder/task/BuildEIP712ContextTask.js.map +3 -3
- package/lib/esm/internal/app-binder/task/BuildEIP712ContextTask.test.js +1 -1
- package/lib/esm/internal/app-binder/task/BuildEIP712ContextTask.test.js.map +2 -2
- package/lib/esm/internal/app-binder/task/BuildTransactionContextTask.js +1 -1
- package/lib/esm/internal/app-binder/task/BuildTransactionContextTask.js.map +2 -2
- package/lib/esm/internal/app-binder/task/BuildTransactionContextTask.test.js +1 -1
- package/lib/esm/internal/app-binder/task/BuildTransactionContextTask.test.js.map +2 -2
- package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.js.map +2 -2
- package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.test.js +1 -1
- package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.test.js.map +2 -2
- package/lib/esm/internal/app-binder/task/SignTypedDataLegacyTask.js +2 -0
- package/lib/esm/internal/app-binder/task/SignTypedDataLegacyTask.js.map +7 -0
- package/lib/esm/internal/app-binder/task/SignTypedDataLegacyTask.test.js +2 -0
- package/lib/esm/internal/app-binder/task/SignTypedDataLegacyTask.test.js.map +7 -0
- package/lib/esm/internal/di.js +1 -1
- package/lib/esm/internal/di.js.map +2 -2
- package/lib/esm/internal/message/di/messageModule.js +1 -1
- package/lib/esm/internal/message/di/messageModule.js.map +3 -3
- package/lib/esm/internal/message/di/messageModule.test.js +1 -1
- package/lib/esm/internal/message/di/messageModule.test.js.map +2 -2
- package/lib/esm/internal/message/use-case/SignMessageUseCase.js +1 -1
- package/lib/esm/internal/message/use-case/SignMessageUseCase.js.map +2 -2
- package/lib/esm/internal/message/use-case/SignMessageUseCase.test.js +1 -1
- package/lib/esm/internal/message/use-case/SignMessageUseCase.test.js.map +2 -2
- package/lib/esm/internal/transaction/di/transactionModule.js +1 -1
- package/lib/esm/internal/transaction/di/transactionModule.js.map +3 -3
- package/lib/esm/internal/transaction/di/transactionModule.test.js +1 -1
- package/lib/esm/internal/transaction/di/transactionModule.test.js.map +2 -2
- package/lib/esm/internal/typed-data/di/typedDataModule.js +1 -1
- package/lib/esm/internal/typed-data/di/typedDataModule.js.map +3 -3
- package/lib/esm/internal/typed-data/di/typedDataModule.test.js +1 -1
- package/lib/esm/internal/typed-data/di/typedDataModule.test.js.map +2 -2
- package/lib/esm/internal/typed-data/service/DefaultTypedDataParserService.js +1 -1
- package/lib/esm/internal/typed-data/service/DefaultTypedDataParserService.js.map +2 -2
- package/lib/esm/internal/typed-data/service/TypedDataParser.js +1 -1
- package/lib/esm/internal/typed-data/service/TypedDataParser.js.map +3 -3
- package/lib/esm/internal/typed-data/service/TypedDataParser.test.js +1 -1
- package/lib/esm/internal/typed-data/service/TypedDataParser.test.js.map +2 -2
- package/lib/esm/internal/typed-data/use-case/SignTypedDataUseCase.js +1 -1
- package/lib/esm/internal/typed-data/use-case/SignTypedDataUseCase.js.map +2 -2
- package/lib/esm/internal/typed-data/use-case/SignTypedDataUseCase.test.js +1 -1
- package/lib/esm/internal/typed-data/use-case/SignTypedDataUseCase.test.js.map +2 -2
- package/lib/esm/package.json +13 -14
- package/lib/types/api/app-binder/SignTransactionDeviceActionTypes.d.ts +6 -1
- package/lib/types/api/app-binder/SignTransactionDeviceActionTypes.d.ts.map +1 -1
- package/lib/types/api/app-binder/SignTypedDataDeviceActionTypes.d.ts +7 -2
- package/lib/types/api/app-binder/SignTypedDataDeviceActionTypes.d.ts.map +1 -1
- package/lib/types/internal/address/di/addressModule.d.ts.map +1 -1
- package/lib/types/internal/app-binder/EthAppBinder.d.ts +5 -5
- package/lib/types/internal/app-binder/EthAppBinder.d.ts.map +1 -1
- package/lib/types/internal/app-binder/command/utils/ethAppErrors.d.ts.map +1 -1
- package/lib/types/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.d.ts +1 -2
- package/lib/types/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.d.ts.map +1 -1
- package/lib/types/internal/app-binder/device-action/__test-utils__/makeInternalApi.d.ts.map +1 -1
- package/lib/types/internal/app-binder/device-action/__test-utils__/setupOpenAppDAMock.d.ts.map +1 -1
- package/lib/types/internal/app-binder/di/appBinderModule.d.ts.map +1 -1
- package/lib/types/internal/app-binder/task/BuildEIP712ContextTask.d.ts.map +1 -1
- package/lib/types/internal/app-binder/task/BuildTransactionContextTask.d.ts.map +1 -1
- package/lib/types/internal/app-binder/task/ProvideEIP712ContextTask.d.ts +0 -2
- package/lib/types/internal/app-binder/task/ProvideEIP712ContextTask.d.ts.map +1 -1
- package/lib/types/internal/app-binder/task/SignTypedDataLegacyTask.d.ts +12 -0
- package/lib/types/internal/app-binder/task/SignTypedDataLegacyTask.d.ts.map +1 -0
- package/lib/types/internal/app-binder/task/SignTypedDataLegacyTask.test.d.ts +2 -0
- package/lib/types/internal/app-binder/task/SignTypedDataLegacyTask.test.d.ts.map +1 -0
- package/lib/types/internal/di.d.ts.map +1 -1
- package/lib/types/internal/message/di/messageModule.d.ts.map +1 -1
- package/lib/types/internal/transaction/di/transactionModule.d.ts.map +1 -1
- package/lib/types/internal/typed-data/di/typedDataModule.d.ts.map +1 -1
- package/lib/types/internal/typed-data/service/TypedDataParser.d.ts +4 -2
- package/lib/types/internal/typed-data/service/TypedDataParser.d.ts.map +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +19 -20
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/app-binder/task/BuildTransactionContextTask.test.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n type ClearSignContext,\n type ClearSignContextSuccess,\n ClearSignContextType,\n type PkiCertificate,\n} from \"@ledgerhq/context-module\";\nimport {\n CommandResultFactory,\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n hexaStringToBuffer,\n UnknownDeviceExchangeError,\n} from \"@ledgerhq/device-management-kit\";\nimport { Transaction } from \"ethers\";\nimport { Left, Right } from \"purify-ts\";\n\nimport type { GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\nimport { type TransactionMapperResult } from \"@internal/transaction/service/mapper/model/TransactionMapperResult\";\nimport { type TransactionMapperService } from \"@internal/transaction/service/mapper/TransactionMapperService\";\n\nimport {\n BuildTransactionContextTask,\n type BuildTransactionContextTaskArgs,\n} from \"./BuildTransactionContextTask\";\n\ndescribe(\"BuildTransactionContextTask\", () => {\n const contextModuleMock = {\n getContext: vi.fn(),\n getContexts: vi.fn(),\n getTypedDataFilters: vi.fn(),\n getWeb3Checks: vi.fn(),\n };\n const mapperMock = {\n mapTransactionToSubset: vi.fn(),\n };\n const defaultOptions = {\n domain: \"domain-name.eth\",\n };\n const defaultTransaction: Uint8Array = hexaStringToBuffer(\n Transaction.from({\n chainId: 1n,\n nonce: 0,\n data: \"0x\",\n }).unsignedSerialized,\n )!;\n const defaultCertificate: PkiCertificate = {\n keyUsageNumber: 1,\n payload: new Uint8Array([0x01, 0x02, 0x03]),\n };\n\n let defaultArgs: BuildTransactionContextTaskArgs;\n const apiMock = makeDeviceActionInternalApiMock();\n 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 () => ({ web3Check: null }),\n });\n\n defaultArgs = {\n contextModule: contextModuleMock,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction: defaultTransaction,\n options: defaultOptions,\n appConfig: createAppConfig(false),\n derivationPath: \"44'/60'/0'/0/0\",\n };\n });\n\n it(\"should build the transaction context without clear sign contexts\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n serializedTransaction,\n chainId: 1,\n transactionType: 0,\n web3Check: null,\n });\n });\n\n it(\"should build the transaction context with web3checks\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n const expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => ({ web3Check: expectedWeb3Check }),\n });\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n serializedTransaction,\n chainId: 1,\n transactionType: 0,\n web3Check: expectedWeb3Check,\n });\n });\n\n it(\"should build the transaction context with clear sign contexts\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n const expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => ({ web3Check: expectedWeb3Check }),\n });\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n web3Check: null,\n });\n });\n\n it(\"should build the transaction context with generic-parser context\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: {\n transactionInfo: \"payload-1\",\n transactionInfoCertificate: defaultCertificate,\n transactionFields: [clearSignContexts[1], clearSignContexts[3]],\n transactionEnums: [clearSignContexts[2]],\n },\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n web3Check: null,\n });\n });\n\n it(\"should call the mapper with the transaction\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(mapperMock.mapTransactionToSubset).toHaveBeenCalledWith(\n defaultTransaction,\n );\n });\n\n it(\"should call the web3checks factory with correct parameters\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildTransactionContextTask(\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 mapper: mapperMock,\n transaction: defaultTransaction,\n });\n });\n\n it(\"should call the context module with the correct parameters\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.FLEX,\n challenge: \"challenge\",\n domain: \"domain-name.eth\",\n ...mapperResult.subset,\n });\n });\n\n it(\"should call the context module without context on error\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ error: new UnknownDeviceExchangeError() }),\n );\n\n // WHEN\n await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.FLEX,\n challenge: undefined,\n domain: \"domain-name.eth\",\n ...mapperResult.subset,\n });\n });\n\n it(\"should throw an error if the mapper returns an error\", async () => {\n // GIVEN\n const error = new Error(\"error\");\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Left(error));\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const task = new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n );\n\n // THEN\n await expect(task.run()).rejects.toThrow(error);\n });\n\n it(\"should exclude error contexts from the result\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n serializedTransaction,\n chainId: 1,\n transactionType: 0,\n web3Check: null,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result on old apps\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"transaction_info\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"transaction_field\",\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"enum\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n serializedTransaction,\n chainId: 1,\n transactionType: 0,\n web3Check: null,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result if no transaction_info was found\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"transaction_field\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"enum\",\n id: 1,\n value: 2,\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.14.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n serializedTransaction,\n chainId: 1,\n transactionType: 0,\n web3Check: null,\n });\n });\n\n it(\"should exclude legacy contexts from the result for generic-parser transactions\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-5\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: {\n transactionInfo: \"payload-2\",\n transactionInfoCertificate: defaultCertificate,\n transactionFields: [clearSignContexts[3]],\n transactionEnums: [clearSignContexts[4]],\n },\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n web3Check: null,\n });\n });\n\n it(\"should exclude generic-parser contexts with a nano s device\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.14.0\" },\n deviceModelId: DeviceModelId.NANO_S,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n web3Check: null,\n });\n });\n\n it(\"should exclude generic-parser contexts with an old app version\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n web3Check: null,\n });\n });\n\n it(\"should exclude generic-parser contexts with a non ready device\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.NOT_CONNECTED,\n deviceModelId: DeviceModelId.FLEX,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n web3Check: null,\n });\n });\n\n it(\"should return no clear sign context if the transaction info certificate is missing\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.17.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [],\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n web3Check: null,\n });\n });\n});\n"],
|
|
5
|
-
"mappings": "aAAA,IAAAA,EAKO,oCACPC,EAOO,2CACPC,EAA4B,kBAC5BC,EAA4B,qBAG5BC,EAAgD,6EAIhDC,EAGO,yCAEP,SAAS,8BAA+B,IAAM,CAC5C,MAAMC,EAAoB,CACxB,WAAY,GAAG,GAAG,EAClB,YAAa,GAAG,GAAG,EACnB,oBAAqB,GAAG,GAAG,EAC3B,cAAe,GAAG,GAAG,CACvB,EACMC,EAAa,CACjB,uBAAwB,GAAG,GAAG,CAChC,EACMC,EAAiB,CACrB,OAAQ,iBACV,EACMC,KAAiC,sBACrC,cAAY,KAAK,CACf,QAAS,GACT,MAAO,EACP,KAAM,IACR,CAAC,EAAE,kBACL,EACMC,EAAqC,CACzC,eAAgB,EAChB,QAAS,IAAI,WAAW,CAAC,EAAM,EAAM,CAAI,CAAC,CAC5C,EAEA,IAAIC,EACJ,MAAMC,KAAU,mCAAgC,EAC1CC,EAA2B,GAAG,GAAG,EAEvC,SAASC,EACPC,EAC0B,CAC1B,MAAO,CACL,oBAAqB,GACrB,kBAAAA,EACA,gBAAiB,GACjB,QAAS,QACX,CACF,CAEA,WAAW,IAAM,CACf,GAAG,cAAc,EACjBH,EAAQ,YAAY,qBAClB,wBA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AAM,IAAK,EAChD,sBAAAF,EACA,KAAM,CACR,EACAT,EAAW,uBAAuB,uBAAoB,SAAMW,CAAY,CAAC,EACzEZ,EAAkB,YAAY,sBAAsBW,CAAiB,EACrEL,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkB,yBAAuB,0BACzC,aAAc,eAAa,UAC3B,cAAe,CAAC,EAChB,WAAY,CAAE,KAAM,WAAY,QAAS,QAAS,EAClD,cAAe,gBAAc,KAC7B,0BAA2B,EAC7B,CAAC,EAGD,MAAMO,EAAS,MAAM,IAAI,8BACvBP,EACAD,EACAE,CACF,EAAE,IAAI,EAGN,OAAOM,CAAM,EAAE,QAAQ,CACrB,kBAAmB,CAAC,EACpB,sBAAAH,EACA,QAAS,EACT,gBAAiB,EACjB,UAAW,IACb,CAAC,CACH,CAAC,CACH,CAAC",
|
|
4
|
+
"sourcesContent": ["import {\n type ClearSignContext,\n type ClearSignContextSuccess,\n ClearSignContextType,\n type PkiCertificate,\n} from \"@ledgerhq/context-module\";\nimport {\n CommandResultFactory,\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n hexaStringToBuffer,\n UnknownDeviceExchangeError,\n} from \"@ledgerhq/device-management-kit\";\nimport { Transaction } from \"ethers\";\nimport { Left, Right } from \"purify-ts\";\n\nimport type { GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\nimport { type TransactionMapperResult } from \"@internal/transaction/service/mapper/model/TransactionMapperResult\";\nimport { type TransactionMapperService } from \"@internal/transaction/service/mapper/TransactionMapperService\";\n\nimport {\n BuildTransactionContextTask,\n type BuildTransactionContextTaskArgs,\n} from \"./BuildTransactionContextTask\";\n\ndescribe(\"BuildTransactionContextTask\", () => {\n const contextModuleMock = {\n getContext: vi.fn(),\n getContexts: vi.fn(),\n getTypedDataFilters: vi.fn(),\n getWeb3Checks: vi.fn(),\n };\n const mapperMock = {\n mapTransactionToSubset: vi.fn(),\n };\n const defaultOptions = {\n domain: \"domain-name.eth\",\n };\n const defaultTransaction: Uint8Array = hexaStringToBuffer(\n Transaction.from({\n chainId: 1n,\n nonce: 0,\n data: \"0x\",\n }).unsignedSerialized,\n )!;\n const defaultCertificate: PkiCertificate = {\n keyUsageNumber: 1,\n payload: new Uint8Array([0x01, 0x02, 0x03]),\n };\n\n let defaultArgs: BuildTransactionContextTaskArgs;\n const apiMock = makeDeviceActionInternalApiMock();\n 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 () => ({ web3Check: null }),\n });\n\n defaultArgs = {\n contextModule: contextModuleMock,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction: defaultTransaction,\n options: defaultOptions,\n appConfig: createAppConfig(false),\n derivationPath: \"44'/60'/0'/0/0\",\n };\n });\n\n it(\"should build the transaction context without clear sign contexts\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n serializedTransaction,\n chainId: 1,\n transactionType: 0,\n web3Check: null,\n });\n });\n\n it(\"should build the transaction context with web3checks\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n const expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => ({ web3Check: expectedWeb3Check }),\n });\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n { ...defaultArgs, appConfig: createAppConfig(true) },\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n serializedTransaction,\n chainId: 1,\n transactionType: 0,\n web3Check: expectedWeb3Check,\n });\n });\n\n it(\"should build the transaction context with clear sign contexts\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n const expectedWeb3Check =\n \"web3Check\" as unknown as ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK>;\n getWeb3ChecksFactoryMock.mockReturnValueOnce({\n run: async () => ({ web3Check: expectedWeb3Check }),\n });\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts,\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n web3Check: null,\n });\n });\n\n it(\"should build the transaction context with generic-parser context\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: {\n transactionInfo: \"payload-1\",\n transactionInfoCertificate: defaultCertificate,\n transactionFields: [clearSignContexts[1], clearSignContexts[3]],\n transactionEnums: [clearSignContexts[2]],\n },\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n web3Check: null,\n });\n });\n\n it(\"should call the mapper with the transaction\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(mapperMock.mapTransactionToSubset).toHaveBeenCalledWith(\n defaultTransaction,\n );\n });\n\n it(\"should call the web3checks factory with correct parameters\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildTransactionContextTask(\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 mapper: mapperMock,\n transaction: defaultTransaction,\n });\n });\n\n it(\"should call the context module with the correct parameters\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.FLEX,\n challenge: \"challenge\",\n domain: \"domain-name.eth\",\n ...mapperResult.subset,\n });\n });\n\n it(\"should call the context module without challenge for Nano S\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.NANO_S,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.NANO_S,\n domain: \"domain-name.eth\",\n ...mapperResult.subset,\n });\n });\n\n it(\"should call the context module without context on error\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ error: new UnknownDeviceExchangeError() }),\n );\n\n // WHEN\n await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(contextModuleMock.getContexts).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.FLEX,\n challenge: undefined,\n domain: \"domain-name.eth\",\n ...mapperResult.subset,\n });\n });\n\n it(\"should throw an error if the mapper returns an error\", async () => {\n // GIVEN\n const error = new Error(\"error\");\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Left(error));\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const task = new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n );\n\n // THEN\n await expect(task.run()).rejects.toThrow(error);\n });\n\n it(\"should exclude error contexts from the result\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n serializedTransaction,\n chainId: 1,\n transactionType: 0,\n web3Check: null,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result on old apps\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"transaction_info\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"transaction_field\",\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"enum\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n serializedTransaction,\n chainId: 1,\n transactionType: 0,\n web3Check: null,\n });\n });\n\n it(\"should exclude generic-parser contexts from the result if no transaction_info was found\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"transaction_field\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"enum\",\n id: 1,\n value: 2,\n },\n {\n type: ClearSignContextType.NFT,\n payload: \"payload-2\",\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 0,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.14.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[1], clearSignContexts[3]],\n serializedTransaction,\n chainId: 1,\n transactionType: 0,\n web3Check: null,\n });\n });\n\n it(\"should exclude legacy contexts from the result for generic-parser transactions\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-4\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-5\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: {\n transactionInfo: \"payload-2\",\n transactionInfoCertificate: defaultCertificate,\n transactionFields: [clearSignContexts[3]],\n transactionEnums: [clearSignContexts[4]],\n },\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n web3Check: null,\n });\n });\n\n it(\"should exclude generic-parser contexts with a nano s device\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.14.0\" },\n deviceModelId: DeviceModelId.NANO_S,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n web3Check: null,\n });\n });\n\n it(\"should exclude generic-parser contexts with an old app version\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.12.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n web3Check: null,\n });\n });\n\n it(\"should exclude generic-parser contexts with a non ready device\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-2\",\n certificate: defaultCertificate,\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-3\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-4\",\n id: 1,\n value: 2,\n certificate: defaultCertificate,\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.NOT_CONNECTED,\n deviceModelId: DeviceModelId.FLEX,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [clearSignContexts[0]],\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n web3Check: null,\n });\n });\n\n it(\"should return no clear sign context if the transaction info certificate is missing\", async () => {\n // GIVEN\n const serializedTransaction = new Uint8Array([0x01, 0x02, 0x03]);\n const clearSignContexts: ClearSignContext[] = [\n {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n },\n {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n {\n type: ClearSignContextType.ENUM,\n payload: \"payload-3\",\n id: 1,\n value: 2,\n },\n ];\n const mapperResult: TransactionMapperResult = {\n subset: { chainId: 1, to: undefined, data: \"0x\" },\n serializedTransaction,\n type: 2,\n };\n mapperMock.mapTransactionToSubset.mockReturnValueOnce(Right(mapperResult));\n contextModuleMock.getContexts.mockResolvedValueOnce(clearSignContexts);\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.17.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n\n // WHEN\n const result = await new BuildTransactionContextTask(\n apiMock,\n defaultArgs,\n getWeb3ChecksFactoryMock,\n ).run();\n\n // THEN\n expect(result).toEqual({\n clearSignContexts: [],\n serializedTransaction,\n chainId: 1,\n transactionType: 2,\n web3Check: null,\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "aAAA,IAAAA,EAKO,oCACPC,EAOO,2CACPC,EAA4B,kBAC5BC,EAA4B,qBAG5BC,EAAgD,6EAIhDC,EAGO,yCAEP,SAAS,8BAA+B,IAAM,CAC5C,MAAMC,EAAoB,CACxB,WAAY,GAAG,GAAG,EAClB,YAAa,GAAG,GAAG,EACnB,oBAAqB,GAAG,GAAG,EAC3B,cAAe,GAAG,GAAG,CACvB,EACMC,EAAa,CACjB,uBAAwB,GAAG,GAAG,CAChC,EACMC,EAAiB,CACrB,OAAQ,iBACV,EACMC,KAAiC,sBACrC,cAAY,KAAK,CACf,QAAS,GACT,MAAO,EACP,KAAM,IACR,CAAC,EAAE,kB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AS,QAAS,EAClD,cAAe,gBAAc,KAC7B,0BAA2B,EAC7B,CAAC,EAGD,MAAMO,EAAS,MAAM,IAAI,8BACvBP,EACAD,EACAE,CACF,EAAE,IAAI,EAGN,OAAOM,CAAM,EAAE,QAAQ,CACrB,kBAAmB,CAAC,EACpB,sBAAAH,EACA,QAAS,EACT,gBAAiB,EACjB,UAAW,IACb,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
6
|
"names": ["import_context_module", "import_device_management_kit", "import_ethers", "import_purify_ts", "import_makeInternalApi", "import_BuildTransactionContextTask", "contextModuleMock", "mapperMock", "defaultOptions", "defaultTransaction", "defaultCertificate", "defaultArgs", "apiMock", "getWeb3ChecksFactoryMock", "createAppConfig", "web3ChecksEnabled", "serializedTransaction", "clearSignContexts", "mapperResult", "result", "expectedWeb3Check", "error", "task"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/app-binder/task/ProvideEIP712ContextTask.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n type ContextModule,\n type TypedDataClearSignContextSuccess,\n type TypedDataFilter,\n type TypedDataTokenIndex,\n VERIFYING_CONTRACT_TOKEN_INDEX,\n} from \"@ledgerhq/context-module\";\nimport {\n type ClearSignContextSuccess,\n ClearSignContextType,\n} from \"@ledgerhq/context-module\";\nimport type {\n CommandResult,\n InternalApi,\n} from \"@ledgerhq/device-management-kit\";\nimport {\n bufferToHexaString,\n CommandResultFactory,\n InvalidStatusWordError,\n isSuccessCommandResult,\n LoadCertificateCommand,\n} from \"@ledgerhq/device-management-kit\";\nimport { Just, Maybe, Nothing } from \"purify-ts\";\n\nimport { GetChallengeCommand } from \"@internal/app-binder/command/GetChallengeCommand\";\nimport { ProvideTokenInformationCommand } from \"@internal/app-binder/command/ProvideTokenInformationCommand\";\nimport { ProvideTrustedNameCommand } from \"@internal/app-binder/command/ProvideTrustedNameCommand\";\nimport { ProvideWeb3CheckCommand } from \"@internal/app-binder/command/ProvideWeb3CheckCommand\";\nimport {\n Eip712FilterType,\n SendEIP712FilteringCommand,\n} from \"@internal/app-binder/command/SendEIP712FilteringCommand\";\nimport {\n SendEIP712StructDefinitionCommand,\n StructDefinitionCommand,\n} from \"@internal/app-binder/command/SendEIP712StructDefinitionCommand\";\nimport { StructImplemType } from \"@internal/app-binder/command/SendEIP712StructImplemCommand\";\nimport { type EthErrorCodes } from \"@internal/app-binder/command/utils/ethAppErrors\";\nimport { SendEIP712StructImplemTask } from \"@internal/app-binder/task/SendEIP712StructImplemTask\";\nimport { TypedDataValueField } from \"@internal/typed-data/model/Types\";\nimport {\n type FieldName,\n type FieldType,\n type StructName,\n type TypedDataValue,\n TypedDataValueArray,\n TypedDataValueRoot,\n} from \"@internal/typed-data/model/Types\";\n\nimport { SendPayloadInChunksTask } from \"./SendPayloadInChunksTask\";\n\ntype AllSuccessTypes = void | { tokenIndex: number };\n\nexport type ProvideEIP712ContextTaskReturnType = Promise<\n CommandResult<AllSuccessTypes, EthErrorCodes>\n>;\n\nexport type ProvideEIP712ContextTaskArgs = {\n types: Record<StructName, Record<FieldName, FieldType>>;\n domain: Array<TypedDataValue>;\n message: Array<TypedDataValue>;\n clearSignContext: Maybe<TypedDataClearSignContextSuccess>;\n domainHash: string;\n messageHash: string;\n web3Check: ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK> | null;\n};\n\nconst DEVICE_ASSETS_MAX = 5;\n\ntype DeviceAssetIndexes = {\n indexes: Record<TypedDataTokenIndex, number>;\n nextIndex: number;\n};\n\nexport class ProvideEIP712ContextTask {\n private chainId: Maybe<number> = Nothing;\n\n constructor(\n private api: InternalApi,\n private contextModule: ContextModule,\n private args: ProvideEIP712ContextTaskArgs,\n ) {\n for (const domainValue of this.args.domain) {\n if (\n domainValue.path === \"chainId\" &&\n domainValue.value instanceof TypedDataValueField\n ) {\n const val = BigInt(bufferToHexaString(domainValue.value.data));\n if (val <= Number.MAX_SAFE_INTEGER) {\n this.chainId = Just(Number(val));\n }\n break;\n }\n }\n }\n\n async run(): ProvideEIP712ContextTaskReturnType {\n // Send message simulation first\n if (this.args.web3Check) {\n if (this.args.web3Check.certificate) {\n await this.api.sendCommand(\n new LoadCertificateCommand({\n keyUsage: this.args.web3Check.certificate.keyUsageNumber,\n certificate: this.args.web3Check.certificate.payload,\n }),\n );\n }\n await new SendPayloadInChunksTask(this.api, {\n payload: this.args.web3Check.payload,\n commandFactory: (args) =>\n new ProvideWeb3CheckCommand({\n payload: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n }\n\n const result: CommandResult<AllSuccessTypes, EthErrorCodes> =\n CommandResultFactory<AllSuccessTypes, EthErrorCodes>({ data: undefined });\n\n // Provide the structure definitions.\n // Should be sent before struct implementations, as described here:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#eip712-send-struct-definition\n // Note that those types are used to compute the schema hash, in the device and in ClearSignContexts, as described here:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#eip712-filtering\n // Therefore it should be normalized on both sides: sorted per keys\n const types = Object.entries(this.args.types).sort(([aKey], [bKey]) =>\n aKey.localeCompare(bKey),\n );\n for (const [structName, fields] of types) {\n const structNameResult = await this.api.sendCommand(\n new SendEIP712StructDefinitionCommand({\n command: StructDefinitionCommand.Name,\n name: structName,\n }),\n );\n if (!isSuccessCommandResult(structNameResult)) {\n return structNameResult;\n }\n\n for (const [fieldName, fieldType] of Object.entries(fields)) {\n const fieldResult = await this.api.sendCommand(\n new SendEIP712StructDefinitionCommand({\n command: StructDefinitionCommand.Field,\n name: fieldName,\n type: fieldType,\n }),\n );\n if (!isSuccessCommandResult(fieldResult)) {\n return fieldResult;\n }\n }\n }\n\n // possibly activate the filtering, before sending domain and message implementations, as described here:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#activation\n if (this.args.clearSignContext.isJust()) {\n const activationResult = await this.api.sendCommand(\n new SendEIP712FilteringCommand({ type: Eip712FilterType.Activation }),\n );\n if (!isSuccessCommandResult(activationResult)) {\n return activationResult;\n }\n }\n\n // send domain implementation values.\n for (const value of this.args.domain) {\n const domainImplTask = this.getImplementationTask(value);\n const domainImplResult = await domainImplTask.run();\n if (!isSuccessCommandResult(domainImplResult)) {\n return domainImplResult;\n }\n }\n\n // possibly send MessageInformation filter (between Domain and Message)\n // should be sent between Domain and Message implementations, as described here:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#message-info\n if (this.args.clearSignContext.isJust()) {\n const clearSignContext = this.args.clearSignContext.extract();\n const messageInfoFilterResult = await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.MessageInfo,\n displayName: clearSignContext.messageInfo.displayName,\n filtersCount: clearSignContext.messageInfo.filtersCount,\n signature: clearSignContext.messageInfo.signature,\n }),\n );\n if (!isSuccessCommandResult(messageInfoFilterResult)) {\n return messageInfoFilterResult;\n }\n }\n\n // send message implementation values\n const deviceIndexes: DeviceAssetIndexes = { indexes: {}, nextIndex: 0 };\n for (const value of this.args.message) {\n // 5.1 Provide token descriptors, if any\n // Keep a map of all device indexes for those provided tokens.\n const maybeTokenError = await this.provideTokenInformation(\n value,\n deviceIndexes,\n );\n if (maybeTokenError.isJust()) {\n return maybeTokenError.extract();\n }\n\n // Provide trusted name descriptors, if any\n const maybeNameError = await this.provideTrustedName(value);\n if (maybeNameError.isJust()) {\n return maybeNameError.extract();\n }\n\n // if there's a filter, send it\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#amount-join-token\n const maybeFilterResult = await this.filterValue(value, deviceIndexes);\n if (\n maybeFilterResult.isJust() &&\n !isSuccessCommandResult(maybeFilterResult.extract())\n ) {\n return maybeFilterResult.extract();\n }\n\n // provide message value implementation\n const messageImplTask = this.getImplementationTask(value);\n const messageImplResult = await messageImplTask.run();\n if (!isSuccessCommandResult(messageImplResult)) {\n return messageImplResult;\n }\n\n // if the value is an empty array, discard sub-filters since\n // there will be no according sub-values in the message\n if (\n this.args.clearSignContext.isJust() &&\n value.value instanceof TypedDataValueArray &&\n value.value.length === 0\n ) {\n const filters = Object.entries(\n this.args.clearSignContext.extract().filters,\n );\n const discardedFilters = filters\n .filter(([path]) => path.startsWith(`${value.path}.[]`))\n .map(([, filter]) => filter);\n for (const filter of discardedFilters) {\n const discardedPathResult = await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.DiscardedPath,\n path: filter.path,\n }),\n );\n if (!isSuccessCommandResult(discardedPathResult)) {\n return discardedPathResult;\n }\n\n const provideFilteringResult = await this.provideFiltering(\n filter,\n deviceIndexes,\n true,\n );\n if (!isSuccessCommandResult(provideFilteringResult)) {\n return provideFilteringResult;\n }\n }\n }\n }\n\n return result;\n }\n\n getImplementationTask(value: TypedDataValue): SendEIP712StructImplemTask {\n if (value.value instanceof TypedDataValueRoot) {\n return new SendEIP712StructImplemTask(this.api, {\n type: StructImplemType.ROOT,\n value: value.value.root,\n });\n } else if (value.value instanceof TypedDataValueArray) {\n return new SendEIP712StructImplemTask(this.api, {\n type: StructImplemType.ARRAY,\n value: value.value.length,\n });\n } else {\n return new SendEIP712StructImplemTask(this.api, {\n type: StructImplemType.FIELD,\n value: value.value.data,\n });\n }\n }\n\n async provideTokenInformation(\n value: TypedDataValue,\n deviceIndexes: DeviceAssetIndexes,\n ): Promise<Maybe<CommandResult<AllSuccessTypes, EthErrorCodes>>> {\n if (this.args.clearSignContext.isJust()) {\n const filter = this.args.clearSignContext.extract().filters[value.path];\n // tokens descriptors only needed when a tokenIndex is available in filter.\n // it should be sent to the device only 1 time so deviceIndexes has to be checked.\n if (\n filter !== undefined &&\n (filter.type === \"amount\" || filter.type === \"token\") &&\n deviceIndexes.indexes[filter.tokenIndex] === undefined\n ) {\n const descriptorIndex = filter.tokenIndex;\n const tokens = this.args.clearSignContext.extract().tokens;\n const token = tokens[descriptorIndex];\n if (token === undefined) {\n return Nothing;\n }\n\n const provideTokenInfoResult = await this.api.sendCommand(\n new ProvideTokenInformationCommand({ payload: token }),\n );\n if (!isSuccessCommandResult(provideTokenInfoResult)) {\n return Maybe.of(provideTokenInfoResult);\n }\n let { tokenIndex: deviceIndex } = provideTokenInfoResult.data;\n deviceIndexes.nextIndex = (deviceIndex + 1) % DEVICE_ASSETS_MAX;\n\n // the token corresponding to the Verifying Contract of message domain has a special index value, as described here:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#amount-join-value\n if (Number(descriptorIndex) === VERIFYING_CONTRACT_TOKEN_INDEX) {\n deviceIndex = VERIFYING_CONTRACT_TOKEN_INDEX;\n }\n\n deviceIndexes.indexes[Number(descriptorIndex)] = deviceIndex;\n }\n }\n return Nothing;\n }\n\n private async provideTrustedName(\n value: TypedDataValue,\n ): Promise<Maybe<CommandResult<AllSuccessTypes, EthErrorCodes>>> {\n if (this.args.clearSignContext.isJust() && this.chainId.isJust()) {\n const context = this.args.clearSignContext.extract();\n const filter = context.filters[value.path];\n const address = context.trustedNamesAddresses[value.path];\n if (\n filter !== undefined &&\n filter.type === \"trusted-name\" &&\n address !== undefined\n ) {\n const getChallengeResult = await this.api.sendCommand(\n new GetChallengeCommand(),\n );\n if (!isSuccessCommandResult(getChallengeResult)) {\n return Just(getChallengeResult);\n }\n\n const context = await this.contextModule.getContext({\n type: ClearSignContextType.TRUSTED_NAME,\n chainId: this.chainId.extract(),\n address,\n challenge: getChallengeResult.data.challenge,\n types: filter.types,\n sources: filter.sources,\n });\n if (context.type === ClearSignContextType.TRUSTED_NAME) {\n if (context.certificate) {\n await this.api.sendCommand(\n new LoadCertificateCommand({\n keyUsage: context.certificate.keyUsageNumber,\n certificate: context.certificate.payload,\n }),\n );\n }\n const provideNameResult = await new SendPayloadInChunksTask(\n this.api,\n {\n payload: context.payload,\n commandFactory: (args) =>\n new ProvideTrustedNameCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n },\n ).run();\n if (!isSuccessCommandResult(provideNameResult)) {\n return Just(provideNameResult);\n }\n }\n }\n }\n return Nothing;\n }\n\n async filterValue(\n value: TypedDataValue,\n deviceIndexes: DeviceAssetIndexes,\n ): Promise<Maybe<CommandResult<AllSuccessTypes, EthErrorCodes>>> {\n if (this.args.clearSignContext.isJust()) {\n const filter = this.args.clearSignContext.extract().filters[value.path];\n if (filter === undefined) {\n return Nothing;\n }\n // provide the filter\n const filteringResult = await this.provideFiltering(\n filter,\n deviceIndexes,\n false,\n );\n return Maybe.of(filteringResult);\n }\n return Nothing;\n }\n\n async provideFiltering(\n filter: TypedDataFilter,\n deviceIndexes: DeviceAssetIndexes,\n discarded: boolean,\n ): Promise<CommandResult<AllSuccessTypes, EthErrorCodes>> {\n switch (filter.type) {\n case \"trusted-name\":\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.TrustedName,\n discarded,\n displayName: filter.displayName,\n typesAndSourcesPayload: filter.typesAndSourcesPayload,\n signature: filter.signature,\n }),\n );\n case \"datetime\":\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.Datetime,\n discarded,\n displayName: filter.displayName,\n signature: filter.signature,\n }),\n );\n case \"raw\":\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.Raw,\n discarded,\n displayName: filter.displayName,\n signature: filter.signature,\n }),\n );\n case \"token\":\n this.sanitizeDeviceIndex(filter.tokenIndex, deviceIndexes);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.Token,\n discarded,\n tokenIndex: deviceIndexes.indexes[filter.tokenIndex]!,\n signature: filter.signature,\n }),\n );\n case \"amount\":\n this.sanitizeDeviceIndex(filter.tokenIndex, deviceIndexes);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.Amount,\n discarded,\n displayName: filter.displayName,\n tokenIndex: deviceIndexes.indexes[filter.tokenIndex]!,\n signature: filter.signature,\n }),\n );\n default:\n return CommandResultFactory<AllSuccessTypes, EthErrorCodes>({\n error: new InvalidStatusWordError(\n \"ProvideEIP712ContextTask/provideFiltering - Unhandled filter type\",\n ),\n });\n }\n }\n\n private sanitizeDeviceIndex(\n descriptorIndex: number,\n deviceIndexes: DeviceAssetIndexes,\n ) {\n // If a token is missing, the device will replace it with a placeholder and use the next available index\n if (deviceIndexes.indexes[descriptorIndex] === undefined) {\n deviceIndexes.indexes[descriptorIndex] = deviceIndexes.nextIndex;\n deviceIndexes.nextIndex =\n (deviceIndexes.nextIndex + 1) % DEVICE_ASSETS_MAX;\n }\n }\n}\n"],
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,8BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAMO,oCACPA,EAGO,oCAKPC,EAMO,2CACPC,EAAqC,qBAErCC,EAAoC,4DACpCC,EAA+C,uEAC/CC,EAA0C,kEAC1CC,EAAwC,gEACxCC,EAGO,mEACPC,EAGO,0EACPC,EAAiC,sEAEjCC,EAA2C,gEAC3CC,EAAoC,4CACpCA,EAOO,4CAEPC,EAAwC,
|
|
4
|
+
"sourcesContent": ["import {\n type ContextModule,\n type TypedDataClearSignContextSuccess,\n type TypedDataFilter,\n type TypedDataTokenIndex,\n VERIFYING_CONTRACT_TOKEN_INDEX,\n} from \"@ledgerhq/context-module\";\nimport {\n type ClearSignContextSuccess,\n ClearSignContextType,\n} from \"@ledgerhq/context-module\";\nimport type {\n CommandResult,\n InternalApi,\n} from \"@ledgerhq/device-management-kit\";\nimport {\n bufferToHexaString,\n CommandResultFactory,\n InvalidStatusWordError,\n isSuccessCommandResult,\n LoadCertificateCommand,\n} from \"@ledgerhq/device-management-kit\";\nimport { Just, Maybe, Nothing } from \"purify-ts\";\n\nimport { GetChallengeCommand } from \"@internal/app-binder/command/GetChallengeCommand\";\nimport { ProvideTokenInformationCommand } from \"@internal/app-binder/command/ProvideTokenInformationCommand\";\nimport { ProvideTrustedNameCommand } from \"@internal/app-binder/command/ProvideTrustedNameCommand\";\nimport { ProvideWeb3CheckCommand } from \"@internal/app-binder/command/ProvideWeb3CheckCommand\";\nimport {\n Eip712FilterType,\n SendEIP712FilteringCommand,\n} from \"@internal/app-binder/command/SendEIP712FilteringCommand\";\nimport {\n SendEIP712StructDefinitionCommand,\n StructDefinitionCommand,\n} from \"@internal/app-binder/command/SendEIP712StructDefinitionCommand\";\nimport { StructImplemType } from \"@internal/app-binder/command/SendEIP712StructImplemCommand\";\nimport { type EthErrorCodes } from \"@internal/app-binder/command/utils/ethAppErrors\";\nimport { SendEIP712StructImplemTask } from \"@internal/app-binder/task/SendEIP712StructImplemTask\";\nimport { TypedDataValueField } from \"@internal/typed-data/model/Types\";\nimport {\n type FieldName,\n type FieldType,\n type StructName,\n type TypedDataValue,\n TypedDataValueArray,\n TypedDataValueRoot,\n} from \"@internal/typed-data/model/Types\";\n\nimport { SendPayloadInChunksTask } from \"./SendPayloadInChunksTask\";\n\ntype AllSuccessTypes = void | { tokenIndex: number };\n\nexport type ProvideEIP712ContextTaskReturnType = Promise<\n CommandResult<AllSuccessTypes, EthErrorCodes>\n>;\n\nexport type ProvideEIP712ContextTaskArgs = {\n types: Record<StructName, Record<FieldName, FieldType>>;\n domain: Array<TypedDataValue>;\n message: Array<TypedDataValue>;\n clearSignContext: Maybe<TypedDataClearSignContextSuccess>;\n web3Check: ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK> | null;\n};\n\nconst DEVICE_ASSETS_MAX = 5;\n\ntype DeviceAssetIndexes = {\n indexes: Record<TypedDataTokenIndex, number>;\n nextIndex: number;\n};\n\nexport class ProvideEIP712ContextTask {\n private chainId: Maybe<number> = Nothing;\n\n constructor(\n private api: InternalApi,\n private contextModule: ContextModule,\n private args: ProvideEIP712ContextTaskArgs,\n ) {\n for (const domainValue of this.args.domain) {\n if (\n domainValue.path === \"chainId\" &&\n domainValue.value instanceof TypedDataValueField\n ) {\n const val = BigInt(bufferToHexaString(domainValue.value.data));\n if (val <= Number.MAX_SAFE_INTEGER) {\n this.chainId = Just(Number(val));\n }\n break;\n }\n }\n }\n\n async run(): ProvideEIP712ContextTaskReturnType {\n // Send message simulation first\n if (this.args.web3Check) {\n if (this.args.web3Check.certificate) {\n await this.api.sendCommand(\n new LoadCertificateCommand({\n keyUsage: this.args.web3Check.certificate.keyUsageNumber,\n certificate: this.args.web3Check.certificate.payload,\n }),\n );\n }\n await new SendPayloadInChunksTask(this.api, {\n payload: this.args.web3Check.payload,\n commandFactory: (args) =>\n new ProvideWeb3CheckCommand({\n payload: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n }\n\n const result: CommandResult<AllSuccessTypes, EthErrorCodes> =\n CommandResultFactory<AllSuccessTypes, EthErrorCodes>({ data: undefined });\n\n // Provide the structure definitions.\n // Should be sent before struct implementations, as described here:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#eip712-send-struct-definition\n // Note that those types are used to compute the schema hash, in the device and in ClearSignContexts, as described here:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#eip712-filtering\n // Therefore it should be normalized on both sides: sorted per keys\n const types = Object.entries(this.args.types).sort(([aKey], [bKey]) =>\n aKey.localeCompare(bKey),\n );\n for (const [structName, fields] of types) {\n const structNameResult = await this.api.sendCommand(\n new SendEIP712StructDefinitionCommand({\n command: StructDefinitionCommand.Name,\n name: structName,\n }),\n );\n if (!isSuccessCommandResult(structNameResult)) {\n return structNameResult;\n }\n\n for (const [fieldName, fieldType] of Object.entries(fields)) {\n const fieldResult = await this.api.sendCommand(\n new SendEIP712StructDefinitionCommand({\n command: StructDefinitionCommand.Field,\n name: fieldName,\n type: fieldType,\n }),\n );\n if (!isSuccessCommandResult(fieldResult)) {\n return fieldResult;\n }\n }\n }\n\n // possibly activate the filtering, before sending domain and message implementations, as described here:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#activation\n if (this.args.clearSignContext.isJust()) {\n const activationResult = await this.api.sendCommand(\n new SendEIP712FilteringCommand({ type: Eip712FilterType.Activation }),\n );\n if (!isSuccessCommandResult(activationResult)) {\n return activationResult;\n }\n }\n\n // send domain implementation values.\n for (const value of this.args.domain) {\n const domainImplTask = this.getImplementationTask(value);\n const domainImplResult = await domainImplTask.run();\n if (!isSuccessCommandResult(domainImplResult)) {\n return domainImplResult;\n }\n }\n\n // possibly send MessageInformation filter (between Domain and Message)\n // should be sent between Domain and Message implementations, as described here:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#message-info\n if (this.args.clearSignContext.isJust()) {\n const clearSignContext = this.args.clearSignContext.extract();\n const messageInfoFilterResult = await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.MessageInfo,\n displayName: clearSignContext.messageInfo.displayName,\n filtersCount: clearSignContext.messageInfo.filtersCount,\n signature: clearSignContext.messageInfo.signature,\n }),\n );\n if (!isSuccessCommandResult(messageInfoFilterResult)) {\n return messageInfoFilterResult;\n }\n }\n\n // send message implementation values\n const deviceIndexes: DeviceAssetIndexes = { indexes: {}, nextIndex: 0 };\n for (const value of this.args.message) {\n // 5.1 Provide token descriptors, if any\n // Keep a map of all device indexes for those provided tokens.\n const maybeTokenError = await this.provideTokenInformation(\n value,\n deviceIndexes,\n );\n if (maybeTokenError.isJust()) {\n return maybeTokenError.extract();\n }\n\n // Provide trusted name descriptors, if any\n const maybeNameError = await this.provideTrustedName(value);\n if (maybeNameError.isJust()) {\n return maybeNameError.extract();\n }\n\n // if there's a filter, send it\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#amount-join-token\n const maybeFilterResult = await this.filterValue(value, deviceIndexes);\n if (\n maybeFilterResult.isJust() &&\n !isSuccessCommandResult(maybeFilterResult.extract())\n ) {\n return maybeFilterResult.extract();\n }\n\n // provide message value implementation\n const messageImplTask = this.getImplementationTask(value);\n const messageImplResult = await messageImplTask.run();\n if (!isSuccessCommandResult(messageImplResult)) {\n return messageImplResult;\n }\n\n // if the value is an empty array, discard sub-filters since\n // there will be no according sub-values in the message\n if (\n this.args.clearSignContext.isJust() &&\n value.value instanceof TypedDataValueArray &&\n value.value.length === 0\n ) {\n const filters = Object.entries(\n this.args.clearSignContext.extract().filters,\n );\n const discardedFilters = filters\n .filter(([path]) => path.startsWith(`${value.path}.[]`))\n .map(([, filter]) => filter);\n for (const filter of discardedFilters) {\n const discardedPathResult = await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.DiscardedPath,\n path: filter.path,\n }),\n );\n if (!isSuccessCommandResult(discardedPathResult)) {\n return discardedPathResult;\n }\n\n const provideFilteringResult = await this.provideFiltering(\n filter,\n deviceIndexes,\n true,\n );\n if (!isSuccessCommandResult(provideFilteringResult)) {\n return provideFilteringResult;\n }\n }\n }\n }\n\n return result;\n }\n\n getImplementationTask(value: TypedDataValue): SendEIP712StructImplemTask {\n if (value.value instanceof TypedDataValueRoot) {\n return new SendEIP712StructImplemTask(this.api, {\n type: StructImplemType.ROOT,\n value: value.value.root,\n });\n } else if (value.value instanceof TypedDataValueArray) {\n return new SendEIP712StructImplemTask(this.api, {\n type: StructImplemType.ARRAY,\n value: value.value.length,\n });\n } else {\n return new SendEIP712StructImplemTask(this.api, {\n type: StructImplemType.FIELD,\n value: value.value.data,\n });\n }\n }\n\n async provideTokenInformation(\n value: TypedDataValue,\n deviceIndexes: DeviceAssetIndexes,\n ): Promise<Maybe<CommandResult<AllSuccessTypes, EthErrorCodes>>> {\n if (this.args.clearSignContext.isJust()) {\n const filter = this.args.clearSignContext.extract().filters[value.path];\n // tokens descriptors only needed when a tokenIndex is available in filter.\n // it should be sent to the device only 1 time so deviceIndexes has to be checked.\n if (\n filter !== undefined &&\n (filter.type === \"amount\" || filter.type === \"token\") &&\n deviceIndexes.indexes[filter.tokenIndex] === undefined\n ) {\n const descriptorIndex = filter.tokenIndex;\n const tokens = this.args.clearSignContext.extract().tokens;\n const token = tokens[descriptorIndex];\n if (token === undefined) {\n return Nothing;\n }\n\n const provideTokenInfoResult = await this.api.sendCommand(\n new ProvideTokenInformationCommand({ payload: token }),\n );\n if (!isSuccessCommandResult(provideTokenInfoResult)) {\n return Maybe.of(provideTokenInfoResult);\n }\n let { tokenIndex: deviceIndex } = provideTokenInfoResult.data;\n deviceIndexes.nextIndex = (deviceIndex + 1) % DEVICE_ASSETS_MAX;\n\n // the token corresponding to the Verifying Contract of message domain has a special index value, as described here:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#amount-join-value\n if (Number(descriptorIndex) === VERIFYING_CONTRACT_TOKEN_INDEX) {\n deviceIndex = VERIFYING_CONTRACT_TOKEN_INDEX;\n }\n\n deviceIndexes.indexes[Number(descriptorIndex)] = deviceIndex;\n }\n }\n return Nothing;\n }\n\n private async provideTrustedName(\n value: TypedDataValue,\n ): Promise<Maybe<CommandResult<AllSuccessTypes, EthErrorCodes>>> {\n if (this.args.clearSignContext.isJust() && this.chainId.isJust()) {\n const context = this.args.clearSignContext.extract();\n const filter = context.filters[value.path];\n const address = context.trustedNamesAddresses[value.path];\n if (\n filter !== undefined &&\n filter.type === \"trusted-name\" &&\n address !== undefined\n ) {\n const getChallengeResult = await this.api.sendCommand(\n new GetChallengeCommand(),\n );\n if (!isSuccessCommandResult(getChallengeResult)) {\n return Just(getChallengeResult);\n }\n\n const context = await this.contextModule.getContext({\n type: ClearSignContextType.TRUSTED_NAME,\n chainId: this.chainId.extract(),\n address,\n challenge: getChallengeResult.data.challenge,\n types: filter.types,\n sources: filter.sources,\n });\n if (context.type === ClearSignContextType.TRUSTED_NAME) {\n if (context.certificate) {\n await this.api.sendCommand(\n new LoadCertificateCommand({\n keyUsage: context.certificate.keyUsageNumber,\n certificate: context.certificate.payload,\n }),\n );\n }\n const provideNameResult = await new SendPayloadInChunksTask(\n this.api,\n {\n payload: context.payload,\n commandFactory: (args) =>\n new ProvideTrustedNameCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n },\n ).run();\n if (!isSuccessCommandResult(provideNameResult)) {\n return Just(provideNameResult);\n }\n }\n }\n }\n return Nothing;\n }\n\n async filterValue(\n value: TypedDataValue,\n deviceIndexes: DeviceAssetIndexes,\n ): Promise<Maybe<CommandResult<AllSuccessTypes, EthErrorCodes>>> {\n if (this.args.clearSignContext.isJust()) {\n const filter = this.args.clearSignContext.extract().filters[value.path];\n if (filter === undefined) {\n return Nothing;\n }\n // provide the filter\n const filteringResult = await this.provideFiltering(\n filter,\n deviceIndexes,\n false,\n );\n return Maybe.of(filteringResult);\n }\n return Nothing;\n }\n\n async provideFiltering(\n filter: TypedDataFilter,\n deviceIndexes: DeviceAssetIndexes,\n discarded: boolean,\n ): Promise<CommandResult<AllSuccessTypes, EthErrorCodes>> {\n switch (filter.type) {\n case \"trusted-name\":\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.TrustedName,\n discarded,\n displayName: filter.displayName,\n typesAndSourcesPayload: filter.typesAndSourcesPayload,\n signature: filter.signature,\n }),\n );\n case \"datetime\":\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.Datetime,\n discarded,\n displayName: filter.displayName,\n signature: filter.signature,\n }),\n );\n case \"raw\":\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.Raw,\n discarded,\n displayName: filter.displayName,\n signature: filter.signature,\n }),\n );\n case \"token\":\n this.sanitizeDeviceIndex(filter.tokenIndex, deviceIndexes);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.Token,\n discarded,\n tokenIndex: deviceIndexes.indexes[filter.tokenIndex]!,\n signature: filter.signature,\n }),\n );\n case \"amount\":\n this.sanitizeDeviceIndex(filter.tokenIndex, deviceIndexes);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.Amount,\n discarded,\n displayName: filter.displayName,\n tokenIndex: deviceIndexes.indexes[filter.tokenIndex]!,\n signature: filter.signature,\n }),\n );\n default:\n return CommandResultFactory<AllSuccessTypes, EthErrorCodes>({\n error: new InvalidStatusWordError(\n \"ProvideEIP712ContextTask/provideFiltering - Unhandled filter type\",\n ),\n });\n }\n }\n\n private sanitizeDeviceIndex(\n descriptorIndex: number,\n deviceIndexes: DeviceAssetIndexes,\n ) {\n // If a token is missing, the device will replace it with a placeholder and use the next available index\n if (deviceIndexes.indexes[descriptorIndex] === undefined) {\n deviceIndexes.indexes[descriptorIndex] = deviceIndexes.nextIndex;\n deviceIndexes.nextIndex =\n (deviceIndexes.nextIndex + 1) % DEVICE_ASSETS_MAX;\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,8BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAMO,oCACPA,EAGO,oCAKPC,EAMO,2CACPC,EAAqC,qBAErCC,EAAoC,4DACpCC,EAA+C,uEAC/CC,EAA0C,kEAC1CC,EAAwC,gEACxCC,EAGO,mEACPC,EAGO,0EACPC,EAAiC,sEAEjCC,EAA2C,gEAC3CC,EAAoC,4CACpCA,EAOO,4CAEPC,EAAwC,qCAgBxC,MAAMC,EAAoB,EAOnB,MAAMf,CAAyB,CAGpC,YACUgB,EACAC,EACAC,EACR,CAHQ,SAAAF,EACA,mBAAAC,EACA,UAAAC,EAER,UAAWC,KAAe,KAAK,KAAK,OAClC,GACEA,EAAY,OAAS,WACrBA,EAAY,iBAAiB,sBAC7B,CACA,MAAMC,EAAM,UAAO,sBAAmBD,EAAY,MAAM,IAAI,CAAC,EACzDC,GAAO,OAAO,mBAChB,KAAK,WAAU,QAAK,OAAOA,CAAG,CAAC,GAEjC,KACF,CAEJ,CAnBQ,QAAyB,UAqBjC,MAAM,KAA0C,CAE1C,KAAK,KAAK,YACR,KAAK,KAAK,UAAU,aACtB,MAAM,KAAK,IAAI,YACb,IAAI,yBAAuB,CACzB,SAAU,KA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mEACF,CACF,CAAC,CACL,CACF,CAEQ,oBACNG,EACAV,EACA,CAEIA,EAAc,QAAQU,CAAe,IAAM,SAC7CV,EAAc,QAAQU,CAAe,EAAIV,EAAc,UACvDA,EAAc,WACXA,EAAc,UAAY,GAAKrB,EAEtC,CACF",
|
|
6
6
|
"names": ["ProvideEIP712ContextTask_exports", "__export", "ProvideEIP712ContextTask", "__toCommonJS", "import_context_module", "import_device_management_kit", "import_purify_ts", "import_GetChallengeCommand", "import_ProvideTokenInformationCommand", "import_ProvideTrustedNameCommand", "import_ProvideWeb3CheckCommand", "import_SendEIP712FilteringCommand", "import_SendEIP712StructDefinitionCommand", "import_SendEIP712StructImplemCommand", "import_SendEIP712StructImplemTask", "import_Types", "import_SendPayloadInChunksTask", "DEVICE_ASSETS_MAX", "api", "contextModule", "args", "domainValue", "val", "result", "types", "aKey", "bKey", "structName", "fields", "structNameResult", "fieldName", "fieldType", "fieldResult", "activationResult", "value", "domainImplResult", "clearSignContext", "messageInfoFilterResult", "deviceIndexes", "maybeTokenError", "maybeNameError", "maybeFilterResult", "messageImplResult", "discardedFilters", "path", "filter", "discardedPathResult", "provideFilteringResult", "descriptorIndex", "token", "provideTokenInfoResult", "deviceIndex", "context", "address", "getChallengeResult", "provideNameResult", "filteringResult", "discarded"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var b=require("@ledgerhq/context-module"),a=require("@ledgerhq/device-management-kit"),c=require("purify-ts"),E=require("../../app-binder/command/GetChallengeCommand"),g=require("../../app-binder/command/ProvideTokenInformationCommand"),h=require("../../app-binder/command/ProvideWeb3CheckCommand"),t=require("../../app-binder/command/SendEIP712FilteringCommand"),y=require("../../app-binder/command/SendEIP712StructDefinitionCommand"),p=require("../../app-binder/command/SendEIP712StructImplemCommand"),q=require("../../app-binder/device-action/__test-utils__/makeInternalApi"),d=require("../../typed-data/model/Types"),i=require("./ProvideEIP712ContextTask");describe("ProvideEIP712ContextTask",()=>{const e=(0,q.makeDeviceActionInternalApiMock)(),l={getContext:vi.fn(),getContexts:vi.fn(),getTypedDataFilters:vi.fn(),getWeb3Checks:vi.fn()},m={EIP712Domain:{name:new d.PrimitiveType("string","string",c.Nothing),chainId:new d.PrimitiveType("uint256","uint",(0,c.Just)(32)),verifyingContract:new d.PrimitiveType("address","address",c.Nothing)},PermitSingle:{details:new d.StructType("PermitDetails"),spender:new d.PrimitiveType("address","address",c.Nothing),sigDeadline:new d.PrimitiveType("uint256","uint",(0,c.Just)(32))},PermitDetails:{token:new d.PrimitiveType("address","address",c.Nothing),amount:new d.PrimitiveType("uint160","uint",(0,c.Just)(20)),expiration:new d.PrimitiveType("uint48","uint",(0,c.Just)(6)),nonce:new d.PrimitiveType("uint48","uint",(0,c.Just)(6))}},r=[{path:"",type:"",value:new d.TypedDataValueRoot("EIP712Domain")},{path:"name",type:"string",value:new d.TypedDataValueField(new TextEncoder().encode("Permit2"))},{path:"chainId",type:"uint256",value:new d.TypedDataValueField(Uint8Array.from([137]))},{path:"verifyingContract",type:"address",value:new d.TypedDataValueField((0,a.hexaStringToBuffer)("0x000000000022d473030f116ddee9f6b43ac78ba3"))}],f=[{path:"",type:"",value:new d.TypedDataValueRoot("PermitSingle")},{path:"details.token",type:"address",value:new d.TypedDataValueField((0,a.hexaStringToBuffer)("0x7ceb23fd6bc0add59e62ac25578270cff1b9f619"))},{path:"details.amount",type:"uint160",value:new d.TypedDataValueField(Uint8Array.from([18]))},{path:"details.expiration",type:"uint48",value:new d.TypedDataValueField(Uint8Array.from([18]))},{path:"details.nonce",type:"uint48",value:new d.TypedDataValueField(Uint8Array.from([0]))},{path:"spender",type:"address",value:new d.TypedDataValueField((0,a.hexaStringToBuffer)("0xec7be89e9d109e7e3fec59c222cf297125fefda2"))},{path:"sigDeadline",type:"uint256",value:new d.TypedDataValueField(Uint8Array.from([18]))}],x={type:"success",messageInfo:{displayName:"Permit2",filtersCount:4,signature:"3045022100e3c597d13d28a87a88b0239404c668373cf5063362f2a81d09eed4582941dfe802207669aabb504fd5b95b2734057f6b8bbf51f14a69a5f9bdf658a5952cefbf44d3"},trustedNamesAddresses:{},tokens:{0:"payload-0x7ceb23fd6bc0add59e62ac25578270cff1b9f619",255:"payload-0x000000000022d473030f116ddee9f6b43ac78ba3"},filters:{"details.amount":{displayName:"Amount allowance",path:"details.amount",signature:"304402201a46e6b4ef89eaf9fcf4945d053bfc5616a826400fd758312fbbe976bafc07ec022025a9b408722baf983ee053f90179c75b0c55bb0668f437d55493e36069bbd5a3",tokenIndex:255,type:"amount"},"details.expiration":{displayName:"Approval expire",path:"details.expiration",signature:"3044022056b3381e4540629ad73bc434ec49d80523234b82f62340fbb77157fb0eb21a680220459fe9cf6ca309f9c7dfc6d4711fea1848dba661563c57f77b3c2dc480b3a63b",type:"datetime"},"details.token":{displayName:"Amount allowance",path:"details.token",signature:"3044022075103b38995e031d1ebbfe38ac6603bec32854b5146a664e49b4cc4f460c1da6022029f4b0fd1f3b7995ffff1627d4b57f27888a2dcc9b3a4e85c37c67571092c733",tokenIndex:0,type:"token"},spender:{displayName:"Approve to spender",path:"spender",signature:"3044022033e5713d9cb9bc375b56a9fb53b736c81ea3c4ac5cfb2d3ca7f8b8f0558fe2430220543ca4fef6d6f725f29e343f167fe9dd582aa856ecb5797259050eb990a1befb",type:"raw"}}},C=new d.PrimitiveType("address","address",c.Nothing),A=new d.PrimitiveType("string","string",c.Nothing),S=new d.PrimitiveType("uint256","uint",(0,c.Just)(32)),I=new d.PrimitiveType("uint160","uint",(0,c.Just)(20)),w=new d.PrimitiveType("uint48","uint",(0,c.Just)(6)),R=n=>new d.StructType(n),k=n=>new y.SendEIP712StructDefinitionCommand({command:y.StructDefinitionCommand.Name,name:n}),o=(n,u)=>new y.SendEIP712StructDefinitionCommand({command:y.StructDefinitionCommand.Field,name:n,type:u}),v=n=>new p.SendEIP712StructImplemCommand({type:p.StructImplemType.ROOT,value:n}),P=n=>new p.SendEIP712StructImplemCommand({type:p.StructImplemType.ARRAY,value:n}),s=n=>new p.SendEIP712StructImplemCommand({type:p.StructImplemType.FIELD,value:{data:n,isLastChunk:!0}});beforeEach(()=>{vi.resetAllMocks()}),it("Send context with no clear signing context",async()=>{const n={web3Check:null,types:m,domain:r,message:f,clearSignContext:c.Nothing,domainHash:"0x",messageHash:"0x"};e.sendCommand.mockResolvedValue((0,a.CommandResultFactory)({data:void 0})),await new i.ProvideEIP712ContextTask(e,l,n).run(),expect(e.sendCommand.mock.calls).toHaveLength(24),expect(e.sendCommand.mock.calls[0][0]).toStrictEqual(k("EIP712Domain")),expect(e.sendCommand.mock.calls[1][0]).toStrictEqual(o("name",A)),expect(e.sendCommand.mock.calls[2][0]).toStrictEqual(o("chainId",S)),expect(e.sendCommand.mock.calls[3][0]).toStrictEqual(o("verifyingContract",C)),expect(e.sendCommand.mock.calls[4][0]).toStrictEqual(k("PermitDetails")),expect(e.sendCommand.mock.calls[5][0]).toStrictEqual(o("token",C)),expect(e.sendCommand.mock.calls[6][0]).toStrictEqual(o("amount",I)),expect(e.sendCommand.mock.calls[7][0]).toStrictEqual(o("expiration",w)),expect(e.sendCommand.mock.calls[8][0]).toStrictEqual(o("nonce",w)),expect(e.sendCommand.mock.calls[9][0]).toStrictEqual(k("PermitSingle")),expect(e.sendCommand.mock.calls[10][0]).toStrictEqual(o("details",R("PermitDetails"))),expect(e.sendCommand.mock.calls[11][0]).toStrictEqual(o("spender",C)),expect(e.sendCommand.mock.calls[12][0]).toStrictEqual(o("sigDeadline",S)),expect(e.sendCommand.mock.calls[13][0]).toStrictEqual(v("EIP712Domain")),expect(e.sendCommand.mock.calls[14][0]).toStrictEqual(s(Uint8Array.from([0,7,80,101,114,109,105,116,50]))),expect(e.sendCommand.mock.calls[15][0]).toStrictEqual(s(Uint8Array.from([0,1,137]))),expect(e.sendCommand.mock.calls[16][0]).toStrictEqual(s(Uint8Array.from([0,20,0,0,0,0,0,34,212,115,3,15,17,109,222,233,246,180,58,199,139,163]))),expect(e.sendCommand.mock.calls[17][0]).toStrictEqual(v("PermitSingle")),expect(e.sendCommand.mock.calls[18][0]).toStrictEqual(s(Uint8Array.from([0,20,124,235,35,253,107,192,173,213,158,98,172,37,87,130,112,207,241,185,246,25]))),expect(e.sendCommand.mock.calls[19][0]).toStrictEqual(s(Uint8Array.from([0,1,18]))),expect(e.sendCommand.mock.calls[20][0]).toStrictEqual(s(Uint8Array.from([0,1,18]))),expect(e.sendCommand.mock.calls[21][0]).toStrictEqual(s(Uint8Array.from([0,1,0]))),expect(e.sendCommand.mock.calls[22][0]).toStrictEqual(s(Uint8Array.from([0,20,236,123,232,158,157,16,158,126,63,236,89,194,34,207,41,113,37,254,253,162]))),expect(e.sendCommand.mock.calls[23][0]).toStrictEqual(s(Uint8Array.from([0,1,18])))}),it("Send context with clear signing",async()=>{const n={web3Check:null,types:m,domain:r,message:f,clearSignContext:(0,c.Just)(x),domainHash:"0x",messageHash:"0x"};e.sendCommand.mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:{tokenIndex:4}})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:{tokenIndex:5}})),e.sendCommand.mockResolvedValue((0,a.CommandResultFactory)({data:void 0})),await new i.ProvideEIP712ContextTask(e,l,n).run(),expect(e.sendCommand.mock.calls).toHaveLength(32),expect(e.sendCommand.mock.calls[0][0]).toStrictEqual(k("EIP712Domain")),expect(e.sendCommand.mock.calls[1][0]).toStrictEqual(o("name",A)),expect(e.sendCommand.mock.calls[2][0]).toStrictEqual(o("chainId",S)),expect(e.sendCommand.mock.calls[3][0]).toStrictEqual(o("verifyingContract",C)),expect(e.sendCommand.mock.calls[4][0]).toStrictEqual(k("PermitDetails")),expect(e.sendCommand.mock.calls[5][0]).toStrictEqual(o("token",C)),expect(e.sendCommand.mock.calls[6][0]).toStrictEqual(o("amount",I)),expect(e.sendCommand.mock.calls[7][0]).toStrictEqual(o("expiration",w)),expect(e.sendCommand.mock.calls[8][0]).toStrictEqual(o("nonce",w)),expect(e.sendCommand.mock.calls[9][0]).toStrictEqual(k("PermitSingle")),expect(e.sendCommand.mock.calls[10][0]).toStrictEqual(o("details",R("PermitDetails"))),expect(e.sendCommand.mock.calls[11][0]).toStrictEqual(o("spender",C)),expect(e.sendCommand.mock.calls[12][0]).toStrictEqual(o("sigDeadline",S)),expect(e.sendCommand.mock.calls[13][0]).toStrictEqual(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.Activation})),expect(e.sendCommand.mock.calls[14][0]).toStrictEqual(v("EIP712Domain")),expect(e.sendCommand.mock.calls[15][0]).toStrictEqual(s(Uint8Array.from([0,7,80,101,114,109,105,116,50]))),expect(e.sendCommand.mock.calls[16][0]).toStrictEqual(s(Uint8Array.from([0,1,137]))),expect(e.sendCommand.mock.calls[17][0]).toStrictEqual(s(Uint8Array.from([0,20,0,0,0,0,0,34,212,115,3,15,17,109,222,233,246,180,58,199,139,163]))),expect(e.sendCommand.mock.calls[18][0]).toStrictEqual(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.MessageInfo,displayName:"Permit2",filtersCount:4,signature:"3045022100e3c597d13d28a87a88b0239404c668373cf5063362f2a81d09eed4582941dfe802207669aabb504fd5b95b2734057f6b8bbf51f14a69a5f9bdf658a5952cefbf44d3"})),expect(e.sendCommand.mock.calls[19][0]).toStrictEqual(v("PermitSingle")),expect(e.sendCommand.mock.calls[20][0]).toStrictEqual(new g.ProvideTokenInformationCommand({payload:"payload-0x7ceb23fd6bc0add59e62ac25578270cff1b9f619"})),expect(e.sendCommand.mock.calls[21][0]).toStrictEqual(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.Token,discarded:!1,tokenIndex:4,signature:"3044022075103b38995e031d1ebbfe38ac6603bec32854b5146a664e49b4cc4f460c1da6022029f4b0fd1f3b7995ffff1627d4b57f27888a2dcc9b3a4e85c37c67571092c733"})),expect(e.sendCommand.mock.calls[22][0]).toStrictEqual(s(Uint8Array.from([0,20,124,235,35,253,107,192,173,213,158,98,172,37,87,130,112,207,241,185,246,25]))),expect(e.sendCommand.mock.calls[23][0]).toStrictEqual(new g.ProvideTokenInformationCommand({payload:"payload-0x000000000022d473030f116ddee9f6b43ac78ba3"})),expect(e.sendCommand.mock.calls[24][0]).toStrictEqual(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.Amount,discarded:!1,displayName:"Amount allowance",tokenIndex:255,signature:"304402201a46e6b4ef89eaf9fcf4945d053bfc5616a826400fd758312fbbe976bafc07ec022025a9b408722baf983ee053f90179c75b0c55bb0668f437d55493e36069bbd5a3"})),expect(e.sendCommand.mock.calls[25][0]).toStrictEqual(s(Uint8Array.from([0,1,18]))),expect(e.sendCommand.mock.calls[26][0]).toStrictEqual(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.Datetime,discarded:!1,displayName:"Approval expire",signature:"3044022056b3381e4540629ad73bc434ec49d80523234b82f62340fbb77157fb0eb21a680220459fe9cf6ca309f9c7dfc6d4711fea1848dba661563c57f77b3c2dc480b3a63b"})),expect(e.sendCommand.mock.calls[27][0]).toStrictEqual(s(Uint8Array.from([0,1,18]))),expect(e.sendCommand.mock.calls[28][0]).toStrictEqual(s(Uint8Array.from([0,1,0]))),expect(e.sendCommand.mock.calls[29][0]).toStrictEqual(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.Raw,discarded:!1,displayName:"Approve to spender",signature:"3044022033e5713d9cb9bc375b56a9fb53b736c81ea3c4ac5cfb2d3ca7f8b8f0558fe2430220543ca4fef6d6f725f29e343f167fe9dd582aa856ecb5797259050eb990a1befb"})),expect(e.sendCommand.mock.calls[30][0]).toStrictEqual(s(Uint8Array.from([0,20,236,123,232,158,157,16,158,126,63,236,89,194,34,207,41,113,37,254,253,162]))),expect(e.sendCommand.mock.calls[31][0]).toStrictEqual(s(Uint8Array.from([0,1,18])))}),it("Both tokens unavailable",async()=>{const n={web3Check:null,types:m,domain:r,message:f,clearSignContext:(0,c.Just)({type:"success",messageInfo:x.messageInfo,filters:x.filters,trustedNamesAddresses:{},tokens:{}}),domainHash:"0x",messageHash:"0x"};e.sendCommand.mockResolvedValue((0,a.CommandResultFactory)({data:void 0})),await new i.ProvideEIP712ContextTask(e,l,n).run(),expect(e.sendCommand).not.toHaveBeenCalledWith(new g.ProvideTokenInformationCommand({payload:"payload-0x7ceb23fd6bc0add59e62ac25578270cff1b9f619"})),expect(e.sendCommand).not.toHaveBeenCalledWith(new g.ProvideTokenInformationCommand({payload:"payload-0x000000000022d473030f116ddee9f6b43ac78ba3"})),expect(e.sendCommand).toHaveBeenCalledWith(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.Token,discarded:!1,tokenIndex:0,signature:"3044022075103b38995e031d1ebbfe38ac6603bec32854b5146a664e49b4cc4f460c1da6022029f4b0fd1f3b7995ffff1627d4b57f27888a2dcc9b3a4e85c37c67571092c733"})),expect(e.sendCommand).toHaveBeenCalledWith(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.Amount,discarded:!1,displayName:"Amount allowance",tokenIndex:1,signature:"304402201a46e6b4ef89eaf9fcf4945d053bfc5616a826400fd758312fbbe976bafc07ec022025a9b408722baf983ee053f90179c75b0c55bb0668f437d55493e36069bbd5a3"}))}),it("First token unavailable",async()=>{const n={web3Check:null,types:m,domain:r,message:f,clearSignContext:(0,c.Just)({type:"success",messageInfo:x.messageInfo,filters:x.filters,trustedNamesAddresses:{},tokens:{255:"payload-0x000000000022d473030f116ddee9f6b43ac78ba3"}}),domainHash:"0x",messageHash:"0x"};e.sendCommand.mockResolvedValue((0,a.CommandResultFactory)({data:{tokenIndex:4}})),await new i.ProvideEIP712ContextTask(e,l,n).run(),expect(e.sendCommand).toHaveBeenCalledWith(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.Token,discarded:!1,tokenIndex:0,signature:"3044022075103b38995e031d1ebbfe38ac6603bec32854b5146a664e49b4cc4f460c1da6022029f4b0fd1f3b7995ffff1627d4b57f27888a2dcc9b3a4e85c37c67571092c733"})),expect(e.sendCommand).toHaveBeenCalledWith(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.Amount,discarded:!1,displayName:"Amount allowance",tokenIndex:255,signature:"304402201a46e6b4ef89eaf9fcf4945d053bfc5616a826400fd758312fbbe976bafc07ec022025a9b408722baf983ee053f90179c75b0c55bb0668f437d55493e36069bbd5a3"}))}),it("Second token unavailable",async()=>{const n={web3Check:null,types:m,domain:r,message:f,clearSignContext:(0,c.Just)({type:"success",messageInfo:x.messageInfo,filters:x.filters,trustedNamesAddresses:{},tokens:{0:"payload-0x7ceb23fd6bc0add59e62ac25578270cff1b9f619"}}),domainHash:"0x",messageHash:"0x"};e.sendCommand.mockResolvedValue((0,a.CommandResultFactory)({data:{tokenIndex:4}})),await new i.ProvideEIP712ContextTask(e,l,n).run(),expect(e.sendCommand).toHaveBeenCalledWith(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.Token,discarded:!1,tokenIndex:4,signature:"3044022075103b38995e031d1ebbfe38ac6603bec32854b5146a664e49b4cc4f460c1da6022029f4b0fd1f3b7995ffff1627d4b57f27888a2dcc9b3a4e85c37c67571092c733"})),expect(e.sendCommand).toHaveBeenCalledWith(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.Amount,discarded:!1,displayName:"Amount allowance",tokenIndex:0,signature:"304402201a46e6b4ef89eaf9fcf4945d053bfc5616a826400fd758312fbbe976bafc07ec022025a9b408722baf983ee053f90179c75b0c55bb0668f437d55493e36069bbd5a3"}))}),it("Filter with trusted name",async()=>{const n={web3Check:null,types:m,domain:r,message:f,clearSignContext:(0,c.Just)({type:"success",messageInfo:x.messageInfo,filters:{"details.token":{displayName:"Amount allowance",path:"details.token",signature:"3044022075103b38995e031d1ebbfe38ac6603bec32854b5146a664e49b4cc4f460c1da6022029f4b0fd1f3b7995ffff1627d4b57f27888a2dcc9b3a4e85c37c67571092c733",types:["contract"],sources:["local","ens"],typesAndSourcesPayload:"010203010002",type:"trusted-name"}},trustedNamesAddresses:{"details.token":"0x7ceb23fd6bc0add59e62ac25578270cff1b9f619"},tokens:{}}),domainHash:"0x",messageHash:"0x"};e.sendCommand.mockResolvedValue((0,a.CommandResultFactory)({data:{challenge:"0x42"}})),l.getContext.mockResolvedValue({type:b.ClearSignContextType.TRUSTED_NAME,payload:"0x01020304"}),await new i.ProvideEIP712ContextTask(e,l,n).run(),expect(e.sendCommand).toHaveBeenCalledWith(new E.GetChallengeCommand),expect(l.getContext).toHaveBeenCalledWith({type:b.ClearSignContextType.TRUSTED_NAME,chainId:137,address:"0x7ceb23fd6bc0add59e62ac25578270cff1b9f619",types:["contract"],sources:["local","ens"],challenge:"0x42"}),expect(e.sendCommand).toHaveBeenCalledWith(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.TrustedName,discarded:!1,displayName:"Amount allowance",typesAndSourcesPayload:"010203010002",signature:"3044022075103b38995e031d1ebbfe38ac6603bec32854b5146a664e49b4cc4f460c1da6022029f4b0fd1f3b7995ffff1627d4b57f27888a2dcc9b3a4e85c37c67571092c733"}))}),it("Filter with trusted name and certificate",async()=>{const n={web3Check:null,types:m,domain:r,message:f,clearSignContext:(0,c.Just)({type:"success",messageInfo:x.messageInfo,filters:{"details.token":{displayName:"Amount allowance",path:"details.token",signature:"3044022075103b38995e031d1ebbfe38ac6603bec32854b5146a664e49b4cc4f460c1da6022029f4b0fd1f3b7995ffff1627d4b57f27888a2dcc9b3a4e85c37c67571092c733",types:["contract"],sources:["local","ens"],typesAndSourcesPayload:"010203010002",type:"trusted-name"}},trustedNamesAddresses:{"details.token":"0x7ceb23fd6bc0add59e62ac25578270cff1b9f619"},tokens:{}}),domainHash:"0x",messageHash:"0x"};e.sendCommand.mockResolvedValue((0,a.CommandResultFactory)({data:{challenge:"0x42"}})),l.getContext.mockResolvedValue({type:b.ClearSignContextType.TRUSTED_NAME,certificate:{keyUsageNumber:7,payload:new Uint8Array(3).fill(42)},payload:"0x01020304"}),await new i.ProvideEIP712ContextTask(e,l,n).run(),expect(e.sendCommand).toHaveBeenCalledWith(new E.GetChallengeCommand),expect(l.getContext).toHaveBeenCalledWith({type:b.ClearSignContextType.TRUSTED_NAME,chainId:137,address:"0x7ceb23fd6bc0add59e62ac25578270cff1b9f619",types:["contract"],sources:["local","ens"],challenge:"0x42"}),expect(e.sendCommand).toHaveBeenCalledWith(new a.LoadCertificateCommand({keyUsage:7,certificate:new Uint8Array(3).fill(42)})),expect(e.sendCommand).toHaveBeenCalledWith(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.TrustedName,discarded:!1,displayName:"Amount allowance",typesAndSourcesPayload:"010203010002",signature:"3044022075103b38995e031d1ebbfe38ac6603bec32854b5146a664e49b4cc4f460c1da6022029f4b0fd1f3b7995ffff1627d4b57f27888a2dcc9b3a4e85c37c67571092c733"}))}),it("Provide Web3Check",async()=>{const u={web3Check:{type:b.ClearSignContextType.WEB3_CHECK,payload:"0x010203"},types:m,domain:r,message:f,clearSignContext:c.Nothing,domainHash:"0x",messageHash:"0x"};e.sendCommand.mockResolvedValue((0,a.CommandResultFactory)({data:void 0})),await new i.ProvideEIP712ContextTask(e,l,u).run(),expect(e.sendCommand).toHaveBeenCalledWith(new h.ProvideWeb3CheckCommand({payload:(0,a.hexaStringToBuffer)("0x0003010203"),isFirstChunk:!0}))}),it("Provide Web3Check and certificate",async()=>{const n={type:b.ClearSignContextType.WEB3_CHECK,certificate:{keyUsageNumber:3,payload:new Uint8Array(3).fill(42)},payload:"0x010203"},u={web3Check:n,types:m,domain:r,message:f,clearSignContext:c.Nothing,domainHash:"0x",messageHash:"0x"};e.sendCommand.mockResolvedValue((0,a.CommandResultFactory)({data:void 0})),await new i.ProvideEIP712ContextTask(e,l,u).run(),expect(e.sendCommand).toHaveBeenCalledWith(new a.LoadCertificateCommand({keyUsage:3,certificate:n.certificate.payload})),expect(e.sendCommand).toHaveBeenCalledWith(new h.ProvideWeb3CheckCommand({payload:(0,a.hexaStringToBuffer)("0x0003010203"),isFirstChunk:!0}))}),it("Error when providing tokens",async()=>{const n={web3Check:null,types:m,domain:r,message:f,clearSignContext:(0,c.Just)(x),domainHash:"0x",messageHash:"0x"};e.sendCommand.mockResolvedValueOnce((0,a.CommandResultFactory)({error:new a.UnknownDeviceExchangeError("error")}));const u=new i.ProvideEIP712ContextTask(e,l,n).run();await expect(u).resolves.toStrictEqual((0,a.CommandResultFactory)({error:new a.UnknownDeviceExchangeError("error")}))}),it("Error when sending struct definitions",async()=>{const n={web3Check:null,types:m,domain:r,message:f,clearSignContext:(0,c.Just)(x),domainHash:"0x",messageHash:"0x"};e.sendCommand.mockResolvedValueOnce((0,a.CommandResultFactory)({data:{tokenIndex:4}})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:{tokenIndex:5}})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({error:new a.UnknownDeviceExchangeError("error")}));const u=new i.ProvideEIP712ContextTask(e,l,n).run();await expect(u).resolves.toStrictEqual((0,a.CommandResultFactory)({error:new a.UnknownDeviceExchangeError("error")}))}),it("Error when sending struct implementations",async()=>{const n={web3Check:null,types:m,domain:r,message:f,clearSignContext:c.Nothing,domainHash:"0x",messageHash:"0x"};e.sendCommand.mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({error:new a.UnknownDeviceExchangeError("error")})).mockResolvedValue((0,a.CommandResultFactory)({data:void 0}));const u=new i.ProvideEIP712ContextTask(e,l,n).run();await expect(u).resolves.toStrictEqual((0,a.CommandResultFactory)({error:new a.UnknownDeviceExchangeError("error")}))}),it("Send struct array",async()=>{const n={web3Check:null,domainHash:"0x",messageHash:"0x",types:{},domain:[],message:[{path:"spenders",type:"address[]",value:new d.TypedDataValueArray(1)},{path:"spenders.[]",type:"address",value:new d.TypedDataValueField((0,a.hexaStringToBuffer)("0x7ceb23fd6bc0add59e62ac25578270cff1b9f619"))},{path:"beneficiaries",type:"address[]",value:new d.TypedDataValueArray(0)}],clearSignContext:(0,c.Just)({type:"success",messageInfo:{displayName:"Permit2",filtersCount:2,signature:"sig"},trustedNamesAddresses:{},tokens:{},filters:{"spenders.[]":{displayName:"Spender",path:"spenders.[]",signature:"sig",type:"raw"},"beneficiaries.[]":{displayName:"Beneficiary",path:"beneficiaries.[]",signature:"sig",type:"raw"}}})};e.sendCommand.mockResolvedValue((0,a.CommandResultFactory)({data:void 0})),await new i.ProvideEIP712ContextTask(e,l,n).run(),expect(e.sendCommand.mock.calls[0][0]).toStrictEqual(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.Activation})),expect(e.sendCommand.mock.calls[1][0]).toStrictEqual(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.MessageInfo,displayName:"Permit2",filtersCount:2,signature:"sig"})),expect(e.sendCommand.mock.calls[2][0]).toStrictEqual(P(1)),expect(e.sendCommand.mock.calls[3][0]).toStrictEqual(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.Raw,discarded:!1,displayName:"Spender",signature:"sig"})),expect(e.sendCommand.mock.calls[4][0]).toStrictEqual(s(Uint8Array.from([0,20,124,235,35,253,107,192,173,213,158,98,172,37,87,130,112,207,241,185,246,25]))),expect(e.sendCommand.mock.calls[5][0]).toStrictEqual(P(0)),expect(e.sendCommand.mock.calls[6][0]).toStrictEqual(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.DiscardedPath,path:"beneficiaries.[]"})),expect(e.sendCommand.mock.calls[7][0]).toStrictEqual(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.Raw,discarded:!0,displayName:"Beneficiary",signature:"sig"}))})});
|
|
1
|
+
"use strict";var b=require("@ledgerhq/context-module"),a=require("@ledgerhq/device-management-kit"),c=require("purify-ts"),E=require("../../app-binder/command/GetChallengeCommand"),g=require("../../app-binder/command/ProvideTokenInformationCommand"),A=require("../../app-binder/command/ProvideWeb3CheckCommand"),t=require("../../app-binder/command/SendEIP712FilteringCommand"),y=require("../../app-binder/command/SendEIP712StructDefinitionCommand"),p=require("../../app-binder/command/SendEIP712StructImplemCommand"),q=require("../../app-binder/device-action/__test-utils__/makeInternalApi"),d=require("../../typed-data/model/Types"),i=require("./ProvideEIP712ContextTask");describe("ProvideEIP712ContextTask",()=>{const e=(0,q.makeDeviceActionInternalApiMock)(),l={getContext:vi.fn(),getContexts:vi.fn(),getTypedDataFilters:vi.fn(),getWeb3Checks:vi.fn()},r={EIP712Domain:{name:new d.PrimitiveType("string","string",c.Nothing),chainId:new d.PrimitiveType("uint256","uint",(0,c.Just)(32)),verifyingContract:new d.PrimitiveType("address","address",c.Nothing)},PermitSingle:{details:new d.StructType("PermitDetails"),spender:new d.PrimitiveType("address","address",c.Nothing),sigDeadline:new d.PrimitiveType("uint256","uint",(0,c.Just)(32))},PermitDetails:{token:new d.PrimitiveType("address","address",c.Nothing),amount:new d.PrimitiveType("uint160","uint",(0,c.Just)(20)),expiration:new d.PrimitiveType("uint48","uint",(0,c.Just)(6)),nonce:new d.PrimitiveType("uint48","uint",(0,c.Just)(6))}},m=[{path:"",type:"",value:new d.TypedDataValueRoot("EIP712Domain")},{path:"name",type:"string",value:new d.TypedDataValueField(new TextEncoder().encode("Permit2"))},{path:"chainId",type:"uint256",value:new d.TypedDataValueField(Uint8Array.from([137]))},{path:"verifyingContract",type:"address",value:new d.TypedDataValueField((0,a.hexaStringToBuffer)("0x000000000022d473030f116ddee9f6b43ac78ba3"))}],f=[{path:"",type:"",value:new d.TypedDataValueRoot("PermitSingle")},{path:"details.token",type:"address",value:new d.TypedDataValueField((0,a.hexaStringToBuffer)("0x7ceb23fd6bc0add59e62ac25578270cff1b9f619"))},{path:"details.amount",type:"uint160",value:new d.TypedDataValueField(Uint8Array.from([18]))},{path:"details.expiration",type:"uint48",value:new d.TypedDataValueField(Uint8Array.from([18]))},{path:"details.nonce",type:"uint48",value:new d.TypedDataValueField(Uint8Array.from([0]))},{path:"spender",type:"address",value:new d.TypedDataValueField((0,a.hexaStringToBuffer)("0xec7be89e9d109e7e3fec59c222cf297125fefda2"))},{path:"sigDeadline",type:"uint256",value:new d.TypedDataValueField(Uint8Array.from([18]))}],x={type:"success",messageInfo:{displayName:"Permit2",filtersCount:4,signature:"3045022100e3c597d13d28a87a88b0239404c668373cf5063362f2a81d09eed4582941dfe802207669aabb504fd5b95b2734057f6b8bbf51f14a69a5f9bdf658a5952cefbf44d3"},trustedNamesAddresses:{},tokens:{0:"payload-0x7ceb23fd6bc0add59e62ac25578270cff1b9f619",255:"payload-0x000000000022d473030f116ddee9f6b43ac78ba3"},filters:{"details.amount":{displayName:"Amount allowance",path:"details.amount",signature:"304402201a46e6b4ef89eaf9fcf4945d053bfc5616a826400fd758312fbbe976bafc07ec022025a9b408722baf983ee053f90179c75b0c55bb0668f437d55493e36069bbd5a3",tokenIndex:255,type:"amount"},"details.expiration":{displayName:"Approval expire",path:"details.expiration",signature:"3044022056b3381e4540629ad73bc434ec49d80523234b82f62340fbb77157fb0eb21a680220459fe9cf6ca309f9c7dfc6d4711fea1848dba661563c57f77b3c2dc480b3a63b",type:"datetime"},"details.token":{displayName:"Amount allowance",path:"details.token",signature:"3044022075103b38995e031d1ebbfe38ac6603bec32854b5146a664e49b4cc4f460c1da6022029f4b0fd1f3b7995ffff1627d4b57f27888a2dcc9b3a4e85c37c67571092c733",tokenIndex:0,type:"token"},spender:{displayName:"Approve to spender",path:"spender",signature:"3044022033e5713d9cb9bc375b56a9fb53b736c81ea3c4ac5cfb2d3ca7f8b8f0558fe2430220543ca4fef6d6f725f29e343f167fe9dd582aa856ecb5797259050eb990a1befb",type:"raw"}}},C=new d.PrimitiveType("address","address",c.Nothing),h=new d.PrimitiveType("string","string",c.Nothing),S=new d.PrimitiveType("uint256","uint",(0,c.Just)(32)),I=new d.PrimitiveType("uint160","uint",(0,c.Just)(20)),w=new d.PrimitiveType("uint48","uint",(0,c.Just)(6)),R=n=>new d.StructType(n),k=n=>new y.SendEIP712StructDefinitionCommand({command:y.StructDefinitionCommand.Name,name:n}),o=(n,u)=>new y.SendEIP712StructDefinitionCommand({command:y.StructDefinitionCommand.Field,name:n,type:u}),v=n=>new p.SendEIP712StructImplemCommand({type:p.StructImplemType.ROOT,value:n}),P=n=>new p.SendEIP712StructImplemCommand({type:p.StructImplemType.ARRAY,value:n}),s=n=>new p.SendEIP712StructImplemCommand({type:p.StructImplemType.FIELD,value:{data:n,isLastChunk:!0}});beforeEach(()=>{vi.resetAllMocks()}),it("Send context with no clear signing context",async()=>{const n={web3Check:null,types:r,domain:m,message:f,clearSignContext:c.Nothing};e.sendCommand.mockResolvedValue((0,a.CommandResultFactory)({data:void 0})),await new i.ProvideEIP712ContextTask(e,l,n).run(),expect(e.sendCommand.mock.calls).toHaveLength(24),expect(e.sendCommand.mock.calls[0][0]).toStrictEqual(k("EIP712Domain")),expect(e.sendCommand.mock.calls[1][0]).toStrictEqual(o("name",h)),expect(e.sendCommand.mock.calls[2][0]).toStrictEqual(o("chainId",S)),expect(e.sendCommand.mock.calls[3][0]).toStrictEqual(o("verifyingContract",C)),expect(e.sendCommand.mock.calls[4][0]).toStrictEqual(k("PermitDetails")),expect(e.sendCommand.mock.calls[5][0]).toStrictEqual(o("token",C)),expect(e.sendCommand.mock.calls[6][0]).toStrictEqual(o("amount",I)),expect(e.sendCommand.mock.calls[7][0]).toStrictEqual(o("expiration",w)),expect(e.sendCommand.mock.calls[8][0]).toStrictEqual(o("nonce",w)),expect(e.sendCommand.mock.calls[9][0]).toStrictEqual(k("PermitSingle")),expect(e.sendCommand.mock.calls[10][0]).toStrictEqual(o("details",R("PermitDetails"))),expect(e.sendCommand.mock.calls[11][0]).toStrictEqual(o("spender",C)),expect(e.sendCommand.mock.calls[12][0]).toStrictEqual(o("sigDeadline",S)),expect(e.sendCommand.mock.calls[13][0]).toStrictEqual(v("EIP712Domain")),expect(e.sendCommand.mock.calls[14][0]).toStrictEqual(s(Uint8Array.from([0,7,80,101,114,109,105,116,50]))),expect(e.sendCommand.mock.calls[15][0]).toStrictEqual(s(Uint8Array.from([0,1,137]))),expect(e.sendCommand.mock.calls[16][0]).toStrictEqual(s(Uint8Array.from([0,20,0,0,0,0,0,34,212,115,3,15,17,109,222,233,246,180,58,199,139,163]))),expect(e.sendCommand.mock.calls[17][0]).toStrictEqual(v("PermitSingle")),expect(e.sendCommand.mock.calls[18][0]).toStrictEqual(s(Uint8Array.from([0,20,124,235,35,253,107,192,173,213,158,98,172,37,87,130,112,207,241,185,246,25]))),expect(e.sendCommand.mock.calls[19][0]).toStrictEqual(s(Uint8Array.from([0,1,18]))),expect(e.sendCommand.mock.calls[20][0]).toStrictEqual(s(Uint8Array.from([0,1,18]))),expect(e.sendCommand.mock.calls[21][0]).toStrictEqual(s(Uint8Array.from([0,1,0]))),expect(e.sendCommand.mock.calls[22][0]).toStrictEqual(s(Uint8Array.from([0,20,236,123,232,158,157,16,158,126,63,236,89,194,34,207,41,113,37,254,253,162]))),expect(e.sendCommand.mock.calls[23][0]).toStrictEqual(s(Uint8Array.from([0,1,18])))}),it("Send context with clear signing",async()=>{const n={web3Check:null,types:r,domain:m,message:f,clearSignContext:(0,c.Just)(x)};e.sendCommand.mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:{tokenIndex:4}})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:{tokenIndex:5}})),e.sendCommand.mockResolvedValue((0,a.CommandResultFactory)({data:void 0})),await new i.ProvideEIP712ContextTask(e,l,n).run(),expect(e.sendCommand.mock.calls).toHaveLength(32),expect(e.sendCommand.mock.calls[0][0]).toStrictEqual(k("EIP712Domain")),expect(e.sendCommand.mock.calls[1][0]).toStrictEqual(o("name",h)),expect(e.sendCommand.mock.calls[2][0]).toStrictEqual(o("chainId",S)),expect(e.sendCommand.mock.calls[3][0]).toStrictEqual(o("verifyingContract",C)),expect(e.sendCommand.mock.calls[4][0]).toStrictEqual(k("PermitDetails")),expect(e.sendCommand.mock.calls[5][0]).toStrictEqual(o("token",C)),expect(e.sendCommand.mock.calls[6][0]).toStrictEqual(o("amount",I)),expect(e.sendCommand.mock.calls[7][0]).toStrictEqual(o("expiration",w)),expect(e.sendCommand.mock.calls[8][0]).toStrictEqual(o("nonce",w)),expect(e.sendCommand.mock.calls[9][0]).toStrictEqual(k("PermitSingle")),expect(e.sendCommand.mock.calls[10][0]).toStrictEqual(o("details",R("PermitDetails"))),expect(e.sendCommand.mock.calls[11][0]).toStrictEqual(o("spender",C)),expect(e.sendCommand.mock.calls[12][0]).toStrictEqual(o("sigDeadline",S)),expect(e.sendCommand.mock.calls[13][0]).toStrictEqual(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.Activation})),expect(e.sendCommand.mock.calls[14][0]).toStrictEqual(v("EIP712Domain")),expect(e.sendCommand.mock.calls[15][0]).toStrictEqual(s(Uint8Array.from([0,7,80,101,114,109,105,116,50]))),expect(e.sendCommand.mock.calls[16][0]).toStrictEqual(s(Uint8Array.from([0,1,137]))),expect(e.sendCommand.mock.calls[17][0]).toStrictEqual(s(Uint8Array.from([0,20,0,0,0,0,0,34,212,115,3,15,17,109,222,233,246,180,58,199,139,163]))),expect(e.sendCommand.mock.calls[18][0]).toStrictEqual(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.MessageInfo,displayName:"Permit2",filtersCount:4,signature:"3045022100e3c597d13d28a87a88b0239404c668373cf5063362f2a81d09eed4582941dfe802207669aabb504fd5b95b2734057f6b8bbf51f14a69a5f9bdf658a5952cefbf44d3"})),expect(e.sendCommand.mock.calls[19][0]).toStrictEqual(v("PermitSingle")),expect(e.sendCommand.mock.calls[20][0]).toStrictEqual(new g.ProvideTokenInformationCommand({payload:"payload-0x7ceb23fd6bc0add59e62ac25578270cff1b9f619"})),expect(e.sendCommand.mock.calls[21][0]).toStrictEqual(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.Token,discarded:!1,tokenIndex:4,signature:"3044022075103b38995e031d1ebbfe38ac6603bec32854b5146a664e49b4cc4f460c1da6022029f4b0fd1f3b7995ffff1627d4b57f27888a2dcc9b3a4e85c37c67571092c733"})),expect(e.sendCommand.mock.calls[22][0]).toStrictEqual(s(Uint8Array.from([0,20,124,235,35,253,107,192,173,213,158,98,172,37,87,130,112,207,241,185,246,25]))),expect(e.sendCommand.mock.calls[23][0]).toStrictEqual(new g.ProvideTokenInformationCommand({payload:"payload-0x000000000022d473030f116ddee9f6b43ac78ba3"})),expect(e.sendCommand.mock.calls[24][0]).toStrictEqual(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.Amount,discarded:!1,displayName:"Amount allowance",tokenIndex:255,signature:"304402201a46e6b4ef89eaf9fcf4945d053bfc5616a826400fd758312fbbe976bafc07ec022025a9b408722baf983ee053f90179c75b0c55bb0668f437d55493e36069bbd5a3"})),expect(e.sendCommand.mock.calls[25][0]).toStrictEqual(s(Uint8Array.from([0,1,18]))),expect(e.sendCommand.mock.calls[26][0]).toStrictEqual(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.Datetime,discarded:!1,displayName:"Approval expire",signature:"3044022056b3381e4540629ad73bc434ec49d80523234b82f62340fbb77157fb0eb21a680220459fe9cf6ca309f9c7dfc6d4711fea1848dba661563c57f77b3c2dc480b3a63b"})),expect(e.sendCommand.mock.calls[27][0]).toStrictEqual(s(Uint8Array.from([0,1,18]))),expect(e.sendCommand.mock.calls[28][0]).toStrictEqual(s(Uint8Array.from([0,1,0]))),expect(e.sendCommand.mock.calls[29][0]).toStrictEqual(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.Raw,discarded:!1,displayName:"Approve to spender",signature:"3044022033e5713d9cb9bc375b56a9fb53b736c81ea3c4ac5cfb2d3ca7f8b8f0558fe2430220543ca4fef6d6f725f29e343f167fe9dd582aa856ecb5797259050eb990a1befb"})),expect(e.sendCommand.mock.calls[30][0]).toStrictEqual(s(Uint8Array.from([0,20,236,123,232,158,157,16,158,126,63,236,89,194,34,207,41,113,37,254,253,162]))),expect(e.sendCommand.mock.calls[31][0]).toStrictEqual(s(Uint8Array.from([0,1,18])))}),it("Both tokens unavailable",async()=>{const n={web3Check:null,types:r,domain:m,message:f,clearSignContext:(0,c.Just)({type:"success",messageInfo:x.messageInfo,filters:x.filters,trustedNamesAddresses:{},tokens:{}})};e.sendCommand.mockResolvedValue((0,a.CommandResultFactory)({data:void 0})),await new i.ProvideEIP712ContextTask(e,l,n).run(),expect(e.sendCommand).not.toHaveBeenCalledWith(new g.ProvideTokenInformationCommand({payload:"payload-0x7ceb23fd6bc0add59e62ac25578270cff1b9f619"})),expect(e.sendCommand).not.toHaveBeenCalledWith(new g.ProvideTokenInformationCommand({payload:"payload-0x000000000022d473030f116ddee9f6b43ac78ba3"})),expect(e.sendCommand).toHaveBeenCalledWith(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.Token,discarded:!1,tokenIndex:0,signature:"3044022075103b38995e031d1ebbfe38ac6603bec32854b5146a664e49b4cc4f460c1da6022029f4b0fd1f3b7995ffff1627d4b57f27888a2dcc9b3a4e85c37c67571092c733"})),expect(e.sendCommand).toHaveBeenCalledWith(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.Amount,discarded:!1,displayName:"Amount allowance",tokenIndex:1,signature:"304402201a46e6b4ef89eaf9fcf4945d053bfc5616a826400fd758312fbbe976bafc07ec022025a9b408722baf983ee053f90179c75b0c55bb0668f437d55493e36069bbd5a3"}))}),it("First token unavailable",async()=>{const n={web3Check:null,types:r,domain:m,message:f,clearSignContext:(0,c.Just)({type:"success",messageInfo:x.messageInfo,filters:x.filters,trustedNamesAddresses:{},tokens:{255:"payload-0x000000000022d473030f116ddee9f6b43ac78ba3"}})};e.sendCommand.mockResolvedValue((0,a.CommandResultFactory)({data:{tokenIndex:4}})),await new i.ProvideEIP712ContextTask(e,l,n).run(),expect(e.sendCommand).toHaveBeenCalledWith(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.Token,discarded:!1,tokenIndex:0,signature:"3044022075103b38995e031d1ebbfe38ac6603bec32854b5146a664e49b4cc4f460c1da6022029f4b0fd1f3b7995ffff1627d4b57f27888a2dcc9b3a4e85c37c67571092c733"})),expect(e.sendCommand).toHaveBeenCalledWith(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.Amount,discarded:!1,displayName:"Amount allowance",tokenIndex:255,signature:"304402201a46e6b4ef89eaf9fcf4945d053bfc5616a826400fd758312fbbe976bafc07ec022025a9b408722baf983ee053f90179c75b0c55bb0668f437d55493e36069bbd5a3"}))}),it("Second token unavailable",async()=>{const n={web3Check:null,types:r,domain:m,message:f,clearSignContext:(0,c.Just)({type:"success",messageInfo:x.messageInfo,filters:x.filters,trustedNamesAddresses:{},tokens:{0:"payload-0x7ceb23fd6bc0add59e62ac25578270cff1b9f619"}})};e.sendCommand.mockResolvedValue((0,a.CommandResultFactory)({data:{tokenIndex:4}})),await new i.ProvideEIP712ContextTask(e,l,n).run(),expect(e.sendCommand).toHaveBeenCalledWith(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.Token,discarded:!1,tokenIndex:4,signature:"3044022075103b38995e031d1ebbfe38ac6603bec32854b5146a664e49b4cc4f460c1da6022029f4b0fd1f3b7995ffff1627d4b57f27888a2dcc9b3a4e85c37c67571092c733"})),expect(e.sendCommand).toHaveBeenCalledWith(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.Amount,discarded:!1,displayName:"Amount allowance",tokenIndex:0,signature:"304402201a46e6b4ef89eaf9fcf4945d053bfc5616a826400fd758312fbbe976bafc07ec022025a9b408722baf983ee053f90179c75b0c55bb0668f437d55493e36069bbd5a3"}))}),it("Filter with trusted name",async()=>{const n={web3Check:null,types:r,domain:m,message:f,clearSignContext:(0,c.Just)({type:"success",messageInfo:x.messageInfo,filters:{"details.token":{displayName:"Amount allowance",path:"details.token",signature:"3044022075103b38995e031d1ebbfe38ac6603bec32854b5146a664e49b4cc4f460c1da6022029f4b0fd1f3b7995ffff1627d4b57f27888a2dcc9b3a4e85c37c67571092c733",types:["contract"],sources:["local","ens"],typesAndSourcesPayload:"010203010002",type:"trusted-name"}},trustedNamesAddresses:{"details.token":"0x7ceb23fd6bc0add59e62ac25578270cff1b9f619"},tokens:{}})};e.sendCommand.mockResolvedValue((0,a.CommandResultFactory)({data:{challenge:"0x42"}})),l.getContext.mockResolvedValue({type:b.ClearSignContextType.TRUSTED_NAME,payload:"0x01020304"}),await new i.ProvideEIP712ContextTask(e,l,n).run(),expect(e.sendCommand).toHaveBeenCalledWith(new E.GetChallengeCommand),expect(l.getContext).toHaveBeenCalledWith({type:b.ClearSignContextType.TRUSTED_NAME,chainId:137,address:"0x7ceb23fd6bc0add59e62ac25578270cff1b9f619",types:["contract"],sources:["local","ens"],challenge:"0x42"}),expect(e.sendCommand).toHaveBeenCalledWith(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.TrustedName,discarded:!1,displayName:"Amount allowance",typesAndSourcesPayload:"010203010002",signature:"3044022075103b38995e031d1ebbfe38ac6603bec32854b5146a664e49b4cc4f460c1da6022029f4b0fd1f3b7995ffff1627d4b57f27888a2dcc9b3a4e85c37c67571092c733"}))}),it("Filter with trusted name and certificate",async()=>{const n={web3Check:null,types:r,domain:m,message:f,clearSignContext:(0,c.Just)({type:"success",messageInfo:x.messageInfo,filters:{"details.token":{displayName:"Amount allowance",path:"details.token",signature:"3044022075103b38995e031d1ebbfe38ac6603bec32854b5146a664e49b4cc4f460c1da6022029f4b0fd1f3b7995ffff1627d4b57f27888a2dcc9b3a4e85c37c67571092c733",types:["contract"],sources:["local","ens"],typesAndSourcesPayload:"010203010002",type:"trusted-name"}},trustedNamesAddresses:{"details.token":"0x7ceb23fd6bc0add59e62ac25578270cff1b9f619"},tokens:{}})};e.sendCommand.mockResolvedValue((0,a.CommandResultFactory)({data:{challenge:"0x42"}})),l.getContext.mockResolvedValue({type:b.ClearSignContextType.TRUSTED_NAME,certificate:{keyUsageNumber:7,payload:new Uint8Array(3).fill(42)},payload:"0x01020304"}),await new i.ProvideEIP712ContextTask(e,l,n).run(),expect(e.sendCommand).toHaveBeenCalledWith(new E.GetChallengeCommand),expect(l.getContext).toHaveBeenCalledWith({type:b.ClearSignContextType.TRUSTED_NAME,chainId:137,address:"0x7ceb23fd6bc0add59e62ac25578270cff1b9f619",types:["contract"],sources:["local","ens"],challenge:"0x42"}),expect(e.sendCommand).toHaveBeenCalledWith(new a.LoadCertificateCommand({keyUsage:7,certificate:new Uint8Array(3).fill(42)})),expect(e.sendCommand).toHaveBeenCalledWith(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.TrustedName,discarded:!1,displayName:"Amount allowance",typesAndSourcesPayload:"010203010002",signature:"3044022075103b38995e031d1ebbfe38ac6603bec32854b5146a664e49b4cc4f460c1da6022029f4b0fd1f3b7995ffff1627d4b57f27888a2dcc9b3a4e85c37c67571092c733"}))}),it("Provide Web3Check",async()=>{const u={web3Check:{type:b.ClearSignContextType.WEB3_CHECK,payload:"0x010203"},types:r,domain:m,message:f,clearSignContext:c.Nothing};e.sendCommand.mockResolvedValue((0,a.CommandResultFactory)({data:void 0})),await new i.ProvideEIP712ContextTask(e,l,u).run(),expect(e.sendCommand).toHaveBeenCalledWith(new A.ProvideWeb3CheckCommand({payload:(0,a.hexaStringToBuffer)("0x0003010203"),isFirstChunk:!0}))}),it("Provide Web3Check and certificate",async()=>{const n={type:b.ClearSignContextType.WEB3_CHECK,certificate:{keyUsageNumber:3,payload:new Uint8Array(3).fill(42)},payload:"0x010203"},u={web3Check:n,types:r,domain:m,message:f,clearSignContext:c.Nothing};e.sendCommand.mockResolvedValue((0,a.CommandResultFactory)({data:void 0})),await new i.ProvideEIP712ContextTask(e,l,u).run(),expect(e.sendCommand).toHaveBeenCalledWith(new a.LoadCertificateCommand({keyUsage:3,certificate:n.certificate.payload})),expect(e.sendCommand).toHaveBeenCalledWith(new A.ProvideWeb3CheckCommand({payload:(0,a.hexaStringToBuffer)("0x0003010203"),isFirstChunk:!0}))}),it("Error when providing tokens",async()=>{const n={web3Check:null,types:r,domain:m,message:f,clearSignContext:(0,c.Just)(x)};e.sendCommand.mockResolvedValueOnce((0,a.CommandResultFactory)({error:new a.UnknownDeviceExchangeError("error")}));const u=new i.ProvideEIP712ContextTask(e,l,n).run();await expect(u).resolves.toStrictEqual((0,a.CommandResultFactory)({error:new a.UnknownDeviceExchangeError("error")}))}),it("Error when sending struct definitions",async()=>{const n={web3Check:null,types:r,domain:m,message:f,clearSignContext:(0,c.Just)(x)};e.sendCommand.mockResolvedValueOnce((0,a.CommandResultFactory)({data:{tokenIndex:4}})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:{tokenIndex:5}})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({error:new a.UnknownDeviceExchangeError("error")}));const u=new i.ProvideEIP712ContextTask(e,l,n).run();await expect(u).resolves.toStrictEqual((0,a.CommandResultFactory)({error:new a.UnknownDeviceExchangeError("error")}))}),it("Error when sending struct implementations",async()=>{const n={web3Check:null,types:r,domain:m,message:f,clearSignContext:c.Nothing};e.sendCommand.mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({data:void 0})).mockResolvedValueOnce((0,a.CommandResultFactory)({error:new a.UnknownDeviceExchangeError("error")})).mockResolvedValue((0,a.CommandResultFactory)({data:void 0}));const u=new i.ProvideEIP712ContextTask(e,l,n).run();await expect(u).resolves.toStrictEqual((0,a.CommandResultFactory)({error:new a.UnknownDeviceExchangeError("error")}))}),it("Send struct array",async()=>{const n={web3Check:null,types:{},domain:[],message:[{path:"spenders",type:"address[]",value:new d.TypedDataValueArray(1)},{path:"spenders.[]",type:"address",value:new d.TypedDataValueField((0,a.hexaStringToBuffer)("0x7ceb23fd6bc0add59e62ac25578270cff1b9f619"))},{path:"beneficiaries",type:"address[]",value:new d.TypedDataValueArray(0)}],clearSignContext:(0,c.Just)({type:"success",messageInfo:{displayName:"Permit2",filtersCount:2,signature:"sig"},trustedNamesAddresses:{},tokens:{},filters:{"spenders.[]":{displayName:"Spender",path:"spenders.[]",signature:"sig",type:"raw"},"beneficiaries.[]":{displayName:"Beneficiary",path:"beneficiaries.[]",signature:"sig",type:"raw"}}})};e.sendCommand.mockResolvedValue((0,a.CommandResultFactory)({data:void 0})),await new i.ProvideEIP712ContextTask(e,l,n).run(),expect(e.sendCommand.mock.calls[0][0]).toStrictEqual(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.Activation})),expect(e.sendCommand.mock.calls[1][0]).toStrictEqual(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.MessageInfo,displayName:"Permit2",filtersCount:2,signature:"sig"})),expect(e.sendCommand.mock.calls[2][0]).toStrictEqual(P(1)),expect(e.sendCommand.mock.calls[3][0]).toStrictEqual(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.Raw,discarded:!1,displayName:"Spender",signature:"sig"})),expect(e.sendCommand.mock.calls[4][0]).toStrictEqual(s(Uint8Array.from([0,20,124,235,35,253,107,192,173,213,158,98,172,37,87,130,112,207,241,185,246,25]))),expect(e.sendCommand.mock.calls[5][0]).toStrictEqual(P(0)),expect(e.sendCommand.mock.calls[6][0]).toStrictEqual(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.DiscardedPath,path:"beneficiaries.[]"})),expect(e.sendCommand.mock.calls[7][0]).toStrictEqual(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.Raw,discarded:!0,displayName:"Beneficiary",signature:"sig"}))})});
|
|
2
2
|
//# sourceMappingURL=ProvideEIP712ContextTask.test.js.map
|