@ledgerhq/device-signer-kit-ethereum 1.3.0 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -2
- package/lib/cjs/api/app-binder/SignTransactionDeviceActionTypes.js +1 -1
- package/lib/cjs/api/app-binder/SignTransactionDeviceActionTypes.js.map +3 -3
- package/lib/cjs/api/app-binder/SignTypedDataDeviceActionTypes.js +1 -1
- package/lib/cjs/api/app-binder/SignTypedDataDeviceActionTypes.js.map +3 -3
- package/lib/cjs/api/index.js +1 -1
- package/lib/cjs/api/index.js.map +3 -3
- package/lib/cjs/internal/app-binder/command/SendEIP712FilteringCommand.js +1 -1
- package/lib/cjs/internal/app-binder/command/SendEIP712FilteringCommand.js.map +2 -2
- package/lib/cjs/internal/app-binder/command/SendEIP712FilteringCommand.test.js +1 -1
- package/lib/cjs/internal/app-binder/command/SendEIP712FilteringCommand.test.js.map +3 -3
- package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js +1 -1
- package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js.map +3 -3
- package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js +1 -1
- package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js.map +3 -3
- package/lib/cjs/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.js +1 -1
- package/lib/cjs/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.js.map +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 +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 +3 -3
- package/lib/cjs/internal/app-binder/task/BuildTransactionContextTask.test.js +1 -1
- package/lib/cjs/internal/app-binder/task/BuildTransactionContextTask.test.js.map +3 -3
- package/lib/cjs/internal/app-binder/task/GetWeb3CheckTask.js +1 -1
- package/lib/cjs/internal/app-binder/task/GetWeb3CheckTask.js.map +3 -3
- package/lib/cjs/internal/app-binder/task/GetWeb3CheckTask.test.js +1 -1
- package/lib/cjs/internal/app-binder/task/GetWeb3CheckTask.test.js.map +3 -3
- package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.js +1 -1
- package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.js.map +3 -3
- package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.test.js +1 -1
- package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.test.js.map +3 -3
- package/lib/cjs/internal/shared/utils/ApplicationChecker.js +2 -0
- package/lib/cjs/internal/shared/utils/ApplicationChecker.js.map +7 -0
- package/lib/cjs/internal/shared/utils/ApplicationChecker.test.js +2 -0
- package/lib/cjs/internal/shared/utils/ApplicationChecker.test.js.map +7 -0
- package/lib/cjs/package.json +2 -2
- package/lib/esm/api/app-binder/SignTransactionDeviceActionTypes.js +1 -0
- package/lib/esm/api/app-binder/SignTransactionDeviceActionTypes.js.map +4 -4
- package/lib/esm/api/app-binder/SignTypedDataDeviceActionTypes.js +1 -0
- package/lib/esm/api/app-binder/SignTypedDataDeviceActionTypes.js.map +4 -4
- package/lib/esm/api/index.js +1 -1
- package/lib/esm/api/index.js.map +3 -3
- package/lib/esm/internal/app-binder/command/SendEIP712FilteringCommand.js +1 -1
- package/lib/esm/internal/app-binder/command/SendEIP712FilteringCommand.js.map +2 -2
- package/lib/esm/internal/app-binder/command/SendEIP712FilteringCommand.test.js +1 -1
- package/lib/esm/internal/app-binder/command/SendEIP712FilteringCommand.test.js.map +3 -3
- package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js +1 -1
- package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js.map +3 -3
- package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js +1 -1
- package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js.map +3 -3
- package/lib/esm/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.js +1 -1
- package/lib/esm/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.js.map +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 +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 +3 -3
- package/lib/esm/internal/app-binder/task/BuildTransactionContextTask.test.js +1 -1
- package/lib/esm/internal/app-binder/task/BuildTransactionContextTask.test.js.map +3 -3
- package/lib/esm/internal/app-binder/task/GetWeb3CheckTask.js +1 -1
- package/lib/esm/internal/app-binder/task/GetWeb3CheckTask.js.map +3 -3
- package/lib/esm/internal/app-binder/task/GetWeb3CheckTask.test.js +1 -1
- package/lib/esm/internal/app-binder/task/GetWeb3CheckTask.test.js.map +3 -3
- package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.js +1 -1
- package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.js.map +3 -3
- package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.test.js +1 -1
- package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.test.js.map +3 -3
- package/lib/esm/internal/shared/utils/ApplicationChecker.js +2 -0
- package/lib/esm/internal/shared/utils/ApplicationChecker.js.map +7 -0
- package/lib/esm/internal/shared/utils/ApplicationChecker.test.js +2 -0
- package/lib/esm/internal/shared/utils/ApplicationChecker.test.js.map +7 -0
- package/lib/esm/package.json +2 -2
- package/lib/types/api/app-binder/SignTransactionDeviceActionTypes.d.ts +13 -2
- package/lib/types/api/app-binder/SignTransactionDeviceActionTypes.d.ts.map +1 -1
- package/lib/types/api/app-binder/SignTypedDataDeviceActionTypes.d.ts +14 -1
- package/lib/types/api/app-binder/SignTypedDataDeviceActionTypes.d.ts.map +1 -1
- package/lib/types/api/index.d.ts +2 -2
- package/lib/types/api/index.d.ts.map +1 -1
- package/lib/types/internal/app-binder/command/SendEIP712FilteringCommand.d.ts +8 -1
- package/lib/types/internal/app-binder/command/SendEIP712FilteringCommand.d.ts.map +1 -1
- package/lib/types/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.d.ts +6 -13
- package/lib/types/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.d.ts.map +1 -1
- package/lib/types/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.d.ts +6 -0
- package/lib/types/internal/app-binder/device-action/SignTypedData/SignTypedDataDeviceAction.d.ts.map +1 -1
- package/lib/types/internal/app-binder/task/BuildEIP712ContextTask.d.ts +8 -7
- package/lib/types/internal/app-binder/task/BuildEIP712ContextTask.d.ts.map +1 -1
- package/lib/types/internal/app-binder/task/BuildTransactionContextTask.d.ts +7 -3
- package/lib/types/internal/app-binder/task/BuildTransactionContextTask.d.ts.map +1 -1
- package/lib/types/internal/app-binder/task/GetWeb3CheckTask.d.ts +0 -1
- package/lib/types/internal/app-binder/task/GetWeb3CheckTask.d.ts.map +1 -1
- package/lib/types/internal/app-binder/task/ProvideEIP712ContextTask.d.ts +6 -3
- package/lib/types/internal/app-binder/task/ProvideEIP712ContextTask.d.ts.map +1 -1
- package/lib/types/internal/shared/utils/ApplicationChecker.d.ts +12 -0
- package/lib/types/internal/shared/utils/ApplicationChecker.d.ts.map +1 -0
- package/lib/types/internal/shared/utils/ApplicationChecker.test.d.ts +2 -0
- package/lib/types/internal/shared/utils/ApplicationChecker.test.d.ts.map +1 -0
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +7 -7
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/app-binder/task/GetWeb3CheckTask.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { type ContextModule } from \"@ledgerhq/context-module\";\nimport {\n CommandResultFactory,\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n InvalidStatusWordError,\n} from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type TypedData } from \"@api/model/TypedData\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\nimport { GetWeb3CheckTask } from \"@internal/app-binder/task/GetWeb3CheckTask\";\nimport { type TransactionMapperService } from \"@internal/transaction/service/mapper/TransactionMapperService\";\n\ndescribe(\"GetWeb3CheckTask\", () => {\n const apiMock = makeDeviceActionInternalApiMock();\n const contextModuleMock = {\n getWeb3Checks: vi.fn(),\n };\n const mapperMock = {\n mapTransactionToSubset: vi.fn(),\n };\n const transaction = new Uint8Array([0x01, 0x02, 0x03, 0x04]);\n const derivationPath = \"44'/60'/0'/0/0\";\n\n describe(\"old apps\", () => {\n beforeEach(() => {\n vi.clearAllMocks();\n\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.15.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: true,\n });\n });\n\n it(\"should return null on old applications\", async () => {\n // GIVEN\n mapperMock.mapTransactionToSubset.mockReturnValue(\n Right({ subset: {}, serializedTransaction: new Uint8Array() }),\n );\n apiMock.sendCommand.mockResolvedValue(\n CommandResultFactory({\n data: { web3ChecksEnabled: true, web3ChecksOptIn: true },\n }),\n );\n contextModuleMock.getWeb3Checks.mockResolvedValue({\n type: \"web3Check\",\n id: 1,\n });\n\n // WHEN\n const result = await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n\n // THEN\n expect(result).toEqual({\n web3Check: null,\n });\n });\n });\n\n describe(\"run\", () => {\n beforeEach(() => {\n vi.clearAllMocks();\n\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.16.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: true,\n });\n });\n\n describe(\"errors\", () => {\n it(\"should throw an error if mapTransactionToSubset assert.fails\", async () => {\n // GIVEN\n const error = new Error(\"error\");\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({\n data: { web3ChecksEnabled: true, web3ChecksOptIn: true },\n }),\n );\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ data: { address: \"address\" } }),\n );\n mapperMock.mapTransactionToSubset.mockReturnValue(Left(error));\n\n // WHEN\n try {\n await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n assert.fail(\"should throw an error\");\n } catch (e) {\n // THEN\n expect(e).toEqual(error);\n }\n });\n\n it(\"should return a context error if GetAppConfiguration assert.fails\", async () => {\n // GIVEN\n mapperMock.mapTransactionToSubset.mockReturnValue(\n Right({ subset: {}, serializedTransaction: new Uint8Array() }),\n );\n apiMock.sendCommand.mockResolvedValue(\n CommandResultFactory({ error: new InvalidStatusWordError(\"error\") }),\n );\n\n // WHEN\n const result = await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n\n // THEN\n expect(result).toEqual({\n web3Check: null,\n error: new InvalidStatusWordError(\"error\"),\n });\n });\n\n it(\"should return a context error if Web3CheckOptInCommand assert.fails\", async () => {\n // GIVEN\n mapperMock.mapTransactionToSubset.mockReturnValue(\n Right({ subset: {}, serializedTransaction: new Uint8Array() }),\n );\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({\n data: { web3ChecksEnabled: false, web3ChecksOptIn: false },\n }),\n );\n apiMock.sendCommand.mockResolvedValue(\n CommandResultFactory({ error: new InvalidStatusWordError(\"error\") }),\n );\n\n // WHEN\n const result = await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n\n // THEN\n expect(result).toEqual({\n web3Check: null,\n error: new InvalidStatusWordError(\"error\"),\n });\n });\n\n it(\"should return a context error if GetAddressCommand assert.fails\", async () => {\n // GIVEN\n mapperMock.mapTransactionToSubset.mockReturnValue(\n Right({ subset: {}, serializedTransaction: new Uint8Array() }),\n );\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({\n data: { web3ChecksEnabled: true, web3ChecksOptIn: true },\n }),\n );\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ error: new InvalidStatusWordError(\"error\") }),\n );\n\n // WHEN\n const result = await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n\n // THEN\n expect(result).toEqual({\n web3Check: null,\n error: new InvalidStatusWordError(\"error\"),\n });\n });\n\n it(\"should return null if the type is not a ClearSignContextSuccess web3check\", async () => {\n // GIVEN\n mapperMock.mapTransactionToSubset.mockReturnValue(\n Right({ subset: {}, serializedTransaction: new Uint8Array() }),\n );\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({\n data: { web3ChecksEnabled: true, web3ChecksOptIn: true },\n }),\n );\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ data: { address: \"address\" } }),\n );\n contextModuleMock.getWeb3Checks.mockResolvedValue({\n type: \"invalid-type\",\n id: 1,\n });\n\n // WHEN\n const result = await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n\n // THEN\n expect(result).toEqual({\n web3Check: null,\n });\n });\n });\n\n describe(\"success\", () => {\n it(\"should return null if web3ChecksEnabled is false\", async () => {\n // GIVEN\n mapperMock.mapTransactionToSubset.mockReturnValue(\n Right({ subset: {}, serializedTransaction: new Uint8Array() }),\n );\n apiMock.sendCommand.mockResolvedValue(\n CommandResultFactory({\n data: { web3ChecksEnabled: false, web3ChecksOptIn: true },\n }),\n );\n\n // WHEN\n const result = await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n\n // THEN\n expect(result).toEqual({\n web3Check: null,\n });\n });\n\n it(\"should return null if the context module does not have a web3 check\", async () => {\n // GIVEN\n mapperMock.mapTransactionToSubset.mockReturnValue(\n Right({ subset: {}, serializedTransaction: new Uint8Array() }),\n );\n apiMock.sendCommand.mockResolvedValue(\n CommandResultFactory({\n data: { web3ChecksEnabled: true, web3ChecksOptIn: true },\n }),\n );\n contextModuleMock.getWeb3Checks.mockResolvedValue(null);\n\n // WHEN\n const result = await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n\n // THEN\n expect(result).toEqual({\n web3Check: null,\n });\n });\n\n it(\"should return a web3 check\", async () => {\n // GIVEN\n const web3Check = { type: \"web3Check\", id: 1 };\n mapperMock.mapTransactionToSubset.mockReturnValue(\n Right({ subset: {}, serializedTransaction: new Uint8Array() }),\n );\n apiMock.sendCommand.mockResolvedValue(\n CommandResultFactory({\n data: { web3ChecksEnabled: true, web3ChecksOptIn: true },\n }),\n );\n contextModuleMock.getWeb3Checks.mockResolvedValue(web3Check);\n\n // WHEN\n const result = await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n\n // THEN\n expect(result).toEqual({\n web3Check,\n });\n });\n\n it(\"should opt-in and then return the web3check\", async () => {\n // GIVEN\n const web3Check = { type: \"web3Check\", id: 1 };\n mapperMock.mapTransactionToSubset.mockReturnValue(\n Right({ subset: {}, serializedTransaction: new Uint8Array() }),\n );\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({\n data: { web3ChecksEnabled: false, web3ChecksOptIn: false },\n }),\n );\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ data: { enabled: true } }),\n );\n contextModuleMock.getWeb3Checks.mockResolvedValue(web3Check);\n\n // WHEN\n const result = await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n\n // THEN\n expect(result).toEqual({\n web3Check,\n });\n });\n\n it(\"should opt-in and then return a null if disabled\", async () => {\n // GIVEN\n const web3Check = { type: \"web3Check\", id: 1 };\n mapperMock.mapTransactionToSubset.mockReturnValue(\n Right({ subset: {}, serializedTransaction: new Uint8Array() }),\n );\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({\n data: { web3ChecksEnabled: false, web3ChecksOptIn: false },\n }),\n );\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ data: { enabled: false } }),\n );\n contextModuleMock.getWeb3Checks.mockResolvedValue(web3Check);\n\n // WHEN\n const result = await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n\n // THEN\n expect(result).toEqual({\n web3Check: null,\n });\n });\n\n it(\"should return a web3 check for typed data\", async () => {\n // GIVEN\n const web3Check = { type: \"web3Check\", id: 1 };\n apiMock.sendCommand.mockResolvedValue(\n CommandResultFactory({\n data: { web3ChecksEnabled: true, web3ChecksOptIn: true },\n }),\n );\n contextModuleMock.getWeb3Checks.mockResolvedValue(web3Check);\n\n // WHEN\n const result = await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n data: \"typed data\" as unknown as TypedData,\n derivationPath,\n }).run();\n\n // THEN\n expect(result).toEqual({\n web3Check,\n });\n });\n\n it(\"should call the context module with the right parameters\", async () => {\n // GIVEN\n mapperMock.mapTransactionToSubset.mockReturnValue(\n Right({\n subset: { chainId: 15, from: \"from\" },\n serializedTransaction: new Uint8Array([0x01, 0x02, 0x03]),\n }),\n );\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({\n data: { web3ChecksEnabled: true, web3ChecksOptIn: true },\n }),\n );\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ data: { address: \"address\" } }),\n );\n contextModuleMock.getWeb3Checks.mockResolvedValue(null);\n\n // WHEN\n await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n\n // THEN\n expect(contextModuleMock.getWeb3Checks).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.FLEX,\n from: \"address\",\n rawTx: \"0x010203\",\n chainId: 15,\n });\n });\n });\n });\n});\n"],
|
|
5
|
-
"mappings": "aACA,IAAAA,EAMO,2CACPC,EAA4B,qBAG5BC,EAAgD,6EAChDC,EAAiC,sDAGjC,SAAS,mBAAoB,IAAM,CACjC,MAAMC,KAAU,mCAAgC,EAC1CC,EAAoB,CACxB,cAAe,GAAG,GAAG,CACvB,EACMC,EAAa,CACjB,uBAAwB,GAAG,GAAG,CAChC,EACMC,EAAc,IAAI,WAAW,CAAC,EAAM,EAAM,EAAM,CAAI,CAAC,EACrDC,EAAiB,iBAEvB,SAAS,
|
|
6
|
-
"names": ["import_device_management_kit", "import_purify_ts", "import_makeInternalApi", "import_GetWeb3CheckTask", "apiMock", "contextModuleMock", "mapperMock", "transaction", "derivationPath", "
|
|
4
|
+
"sourcesContent": ["import { type ContextModule } from \"@ledgerhq/context-module\";\nimport {\n CommandResultFactory,\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n InvalidStatusWordError,\n} from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type TypedData } from \"@api/model/TypedData\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\nimport { GetWeb3CheckTask } from \"@internal/app-binder/task/GetWeb3CheckTask\";\nimport { type TransactionMapperService } from \"@internal/transaction/service/mapper/TransactionMapperService\";\n\ndescribe(\"GetWeb3CheckTask\", () => {\n const apiMock = makeDeviceActionInternalApiMock();\n const contextModuleMock = {\n getWeb3Checks: vi.fn(),\n };\n const mapperMock = {\n mapTransactionToSubset: vi.fn(),\n };\n const transaction = new Uint8Array([0x01, 0x02, 0x03, 0x04]);\n const derivationPath = \"44'/60'/0'/0/0\";\n\n describe(\"run\", () => {\n beforeEach(() => {\n vi.clearAllMocks();\n\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version: \"1.16.0\" },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: true,\n });\n });\n\n describe(\"errors\", () => {\n it(\"should throw an error if mapTransactionToSubset assert.fails\", async () => {\n // GIVEN\n const error = new Error(\"error\");\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ data: { address: \"address\" } }),\n );\n mapperMock.mapTransactionToSubset.mockReturnValue(Left(error));\n\n // WHEN\n try {\n await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n assert.fail(\"should throw an error\");\n } catch (e) {\n // THEN\n expect(e).toEqual(error);\n }\n });\n\n it(\"should return a context error if GetAddressCommand assert.fails\", async () => {\n // GIVEN\n mapperMock.mapTransactionToSubset.mockReturnValue(\n Right({ subset: {}, serializedTransaction: new Uint8Array() }),\n );\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ error: new InvalidStatusWordError(\"error\") }),\n );\n\n // WHEN\n const result = await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n\n // THEN\n expect(result).toEqual({\n web3Check: null,\n error: new InvalidStatusWordError(\"error\"),\n });\n });\n\n it(\"should return null if the type is not a ClearSignContextSuccess web3check\", async () => {\n // GIVEN\n mapperMock.mapTransactionToSubset.mockReturnValue(\n Right({ subset: {}, serializedTransaction: new Uint8Array() }),\n );\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ data: { address: \"address\" } }),\n );\n contextModuleMock.getWeb3Checks.mockResolvedValue({\n type: \"invalid-type\",\n id: 1,\n });\n\n // WHEN\n const result = await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n\n // THEN\n expect(result).toEqual({\n web3Check: null,\n });\n });\n });\n\n describe(\"success\", () => {\n it(\"should return null if the context module does not have a web3 check\", async () => {\n // GIVEN\n mapperMock.mapTransactionToSubset.mockReturnValue(\n Right({ subset: {}, serializedTransaction: new Uint8Array() }),\n );\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ data: { address: \"address\" } }),\n );\n contextModuleMock.getWeb3Checks.mockResolvedValue(null);\n\n // WHEN\n const result = await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n\n // THEN\n expect(result).toEqual({\n web3Check: null,\n });\n });\n\n it(\"should return a web3 check\", async () => {\n // GIVEN\n const web3Check = { type: \"web3Check\", id: 1 };\n mapperMock.mapTransactionToSubset.mockReturnValue(\n Right({ subset: {}, serializedTransaction: new Uint8Array() }),\n );\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ data: { address: \"address\" } }),\n );\n contextModuleMock.getWeb3Checks.mockResolvedValue(web3Check);\n\n // WHEN\n const result = await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n\n // THEN\n expect(result).toEqual({\n web3Check,\n });\n });\n\n it(\"should return a web3 check for typed data\", async () => {\n // GIVEN\n const web3Check = { type: \"web3Check\", id: 1 };\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ data: { address: \"address\" } }),\n );\n contextModuleMock.getWeb3Checks.mockResolvedValue(web3Check);\n\n // WHEN\n const result = await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n data: \"typed data\" as unknown as TypedData,\n derivationPath,\n }).run();\n\n // THEN\n expect(result).toEqual({\n web3Check,\n });\n });\n\n it(\"should call the context module with the right parameters\", async () => {\n // GIVEN\n mapperMock.mapTransactionToSubset.mockReturnValue(\n Right({\n subset: { chainId: 15, from: \"from\" },\n serializedTransaction: new Uint8Array([0x01, 0x02, 0x03]),\n }),\n );\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ data: { address: \"address\" } }),\n );\n contextModuleMock.getWeb3Checks.mockResolvedValue(null);\n\n // WHEN\n await new GetWeb3CheckTask(apiMock, {\n contextModule: contextModuleMock as unknown as ContextModule,\n mapper: mapperMock as unknown as TransactionMapperService,\n transaction,\n derivationPath,\n }).run();\n\n // THEN\n expect(contextModuleMock.getWeb3Checks).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.FLEX,\n from: \"address\",\n rawTx: \"0x010203\",\n chainId: 15,\n });\n });\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "aACA,IAAAA,EAMO,2CACPC,EAA4B,qBAG5BC,EAAgD,6EAChDC,EAAiC,sDAGjC,SAAS,mBAAoB,IAAM,CACjC,MAAMC,KAAU,mCAAgC,EAC1CC,EAAoB,CACxB,cAAe,GAAG,GAAG,CACvB,EACMC,EAAa,CACjB,uBAAwB,GAAG,GAAG,CAChC,EACMC,EAAc,IAAI,WAAW,CAAC,EAAM,EAAM,EAAM,CAAI,CAAC,EACrDC,EAAiB,iBAEvB,SAAS,MAAO,IAAM,CACpB,WAAW,IAAM,CACf,GAAG,cAAc,EAEjBJ,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,CACH,CAAC,EAED,SAAS,SAAU,IAAM,CACvB,GAAG,+DAAgE,SAAY,CAE7E,MAAMK,EAAQ,IAAI,MAAM,OAAO,EAC/BL,EAAQ,YAAY,yBAClB,wBAAqB,CAAE,KAAM,CAAE,QAAS,SAAU,CAAE,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AG,2DAA4D,SAAY,CAEzEN,EAAW,uBAAuB,mBAChC,SAAM,CACJ,OAAQ,CAAE,QAAS,GAAI,KAAM,MAAO,EACpC,sBAAuB,IAAI,WAAW,CAAC,EAAM,EAAM,CAAI,CAAC,CAC1D,CAAC,CACH,EACAF,EAAQ,YAAY,yBAClB,wBAAqB,CAAE,KAAM,CAAE,QAAS,SAAU,CAAE,CAAC,CACvD,EACAC,EAAkB,cAAc,kBAAkB,IAAI,EAGtD,MAAM,IAAI,mBAAiBD,EAAS,CAClC,cAAeC,EACf,OAAQC,EACR,YAAAC,EACA,eAAAC,CACF,CAAC,EAAE,IAAI,EAGP,OAAOH,EAAkB,aAAa,EAAE,qBAAqB,CAC3D,cAAe,gBAAc,KAC7B,KAAM,UACN,MAAO,WACP,QAAS,EACX,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["import_device_management_kit", "import_purify_ts", "import_makeInternalApi", "import_GetWeb3CheckTask", "apiMock", "contextModuleMock", "mapperMock", "transaction", "derivationPath", "error", "e", "result", "web3Check"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var g=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var M=(u,e)=>{for(var a in e)g(u,a,{get:e[a],enumerable:!0})},V=(u,e,a,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of P(e))!F.call(u,t)&&t!==a&&g(u,t,{get:()=>e[t],enumerable:!(n=b(e,t))||n.enumerable});return u};var J=u=>V(g({},"__esModule",{value:!0}),u);var O={};M(O,{ProvideEIP712ContextTask:()=>_});module.exports=J(O);var x=require("@ledgerhq/context-module"),T=require("@ledgerhq/context-module"),s=require("@ledgerhq/device-management-kit"),d=require("purify-ts"),E=require("../../app-binder/command/GetChallengeCommand"),v=require("../../app-binder/command/ProvideTokenInformationCommand"),N=require("../../app-binder/command/ProvideTrustedNameCommand"),R=require("../../app-binder/command/ProvideWeb3CheckCommand"),r=require("../../app-binder/command/SendEIP712FilteringCommand"),l=require("../../app-binder/command/SendEIP712StructDefinitionCommand"),h=require("../../app-binder/command/SendEIP712StructImplemCommand"),C=require("../../app-binder/task/SendEIP712StructImplemTask"),A=require("../../typed-data/model/Types"),f=require("../../typed-data/model/Types"),I=require("./SendPayloadInChunksTask");const w=5;class _{constructor(e,a,n){this.api=e;this.contextModule=a;this.args=n;for(const t of this.args.domain)if(t.path==="chainId"&&t.value instanceof A.TypedDataValueField){const i=BigInt((0,s.bufferToHexaString)(t.value.data));i<=Number.MAX_SAFE_INTEGER&&(this.chainId=(0,d.Just)(Number(i)));break}}chainId=d.Nothing;async run(){this.args.web3Check&&(this.args.web3Check.certificate&&await this.api.sendCommand(new s.LoadCertificateCommand({keyUsage:this.args.web3Check.certificate.keyUsageNumber,certificate:this.args.web3Check.certificate.payload})),await new I.SendPayloadInChunksTask(this.api,{payload:this.args.web3Check.payload,commandFactory:t=>new R.ProvideWeb3CheckCommand({payload:t.chunkedData,isFirstChunk:t.isFirstChunk})}).run());const e=(0,s.CommandResultFactory)({data:void 0}),a=Object.entries(this.args.types).sort(([t],[i])=>t.localeCompare(i));for(const[t,i]of a){const o=await this.api.sendCommand(new l.SendEIP712StructDefinitionCommand({command:l.StructDefinitionCommand.Name,name:t}));if(!(0,s.isSuccessCommandResult)(o))return o;for(const[m,c]of Object.entries(i)){const y=await this.api.sendCommand(new l.SendEIP712StructDefinitionCommand({command:l.StructDefinitionCommand.Field,name:m,type:c}));if(!(0,s.isSuccessCommandResult)(y))return y}}if(this.args.clearSignContext.isJust()){const t=await this.api.sendCommand(new r.SendEIP712FilteringCommand({type:r.Eip712FilterType.Activation}));if(!(0,s.isSuccessCommandResult)(t))return t}for(const t of this.args.domain){const o=await this.getImplementationTask(t).run();if(!(0,s.isSuccessCommandResult)(o))return o}if(this.args.clearSignContext.isJust()){const t=this.args.clearSignContext.extract(),i=await this.api.sendCommand(new r.SendEIP712FilteringCommand({type:r.Eip712FilterType.MessageInfo,displayName:t.messageInfo.displayName,filtersCount:t.messageInfo.filtersCount,signature:t.messageInfo.signature}));if(!(0,s.isSuccessCommandResult)(i))return i}const n={indexes:{},nextIndex:0};for(const t of this.args.message){const i=await this.provideTokenInformation(t,n);if(i.isJust())return i.extract();const o=await this.provideTrustedName(t);if(o.isJust())return o.extract();const m=await this.filterValue(t,n);if(m.isJust()&&!(0,s.isSuccessCommandResult)(m.extract()))return m.extract();const y=await this.getImplementationTask(t).run();if(!(0,s.isSuccessCommandResult)(y))return y;if(this.args.clearSignContext.isJust()&&t.value instanceof f.TypedDataValueArray&&t.value.length===0){const D=Object.entries(this.args.clearSignContext.extract().filters).filter(([p])=>p.startsWith(`${t.path}.[]`)).map(([,p])=>p);for(const p of D){const k=await this.api.sendCommand(new r.SendEIP712FilteringCommand({type:r.Eip712FilterType.DiscardedPath,path:p.path}));if(!(0,s.isSuccessCommandResult)(k))return k;const S=await this.provideFiltering(p,n,!0);if(!(0,s.isSuccessCommandResult)(S))return S}}}return e}getImplementationTask(e){return e.value instanceof f.TypedDataValueRoot?new C.SendEIP712StructImplemTask(this.api,{type:h.StructImplemType.ROOT,value:e.value.root}):e.value instanceof f.TypedDataValueArray?new C.SendEIP712StructImplemTask(this.api,{type:h.StructImplemType.ARRAY,value:e.value.length}):new C.SendEIP712StructImplemTask(this.api,{type:h.StructImplemType.FIELD,value:e.value.data})}async provideTokenInformation(e,a){if(this.args.clearSignContext.isJust()){const n=this.args.clearSignContext.extract().filters[e.path];if(n!==void 0&&(n.type==="amount"||n.type==="token")&&a.indexes[n.tokenIndex]===void 0){const t=n.tokenIndex,o=this.args.clearSignContext.extract().tokens[t];if(o===void 0)return d.Nothing;const m=await this.api.sendCommand(new v.ProvideTokenInformationCommand({payload:o}));if(!(0,s.isSuccessCommandResult)(m))return d.Maybe.of(m);let{tokenIndex:c}=m.data;a.nextIndex=(c+1)%w,Number(t)===x.VERIFYING_CONTRACT_TOKEN_INDEX&&(c=x.VERIFYING_CONTRACT_TOKEN_INDEX),a.indexes[Number(t)]=c}}return d.Nothing}async provideTrustedName(e){if(this.args.clearSignContext.isJust()&&this.chainId.isJust()){const a=this.args.clearSignContext.extract(),n=a.filters[e.path],t=a.trustedNamesAddresses[e.path];if(n!==void 0&&n.type==="trusted-name"&&t!==void 0){const i=await this.api.sendCommand(new E.GetChallengeCommand);if(!(0,s.isSuccessCommandResult)(i))return(0,d.Just)(i);const o=await this.contextModule.getContext({type:T.ClearSignContextType.TRUSTED_NAME,chainId:this.chainId.extract(),address:t,challenge:i.data.challenge,types:n.types,sources:n.sources});if(o.type===T.ClearSignContextType.TRUSTED_NAME){o.certificate&&await this.api.sendCommand(new s.LoadCertificateCommand({keyUsage:o.certificate.keyUsageNumber,certificate:o.certificate.payload}));const m=await new I.SendPayloadInChunksTask(this.api,{payload:o.payload,commandFactory:c=>new N.ProvideTrustedNameCommand({data:c.chunkedData,isFirstChunk:c.isFirstChunk})}).run();if(!(0,s.isSuccessCommandResult)(m))return(0,d.Just)(m)}}}return d.Nothing}async filterValue(e,a){if(this.args.clearSignContext.isJust()){const n=this.args.clearSignContext.extract().filters[e.path];if(n===void 0)return d.Nothing;const t=await this.provideFiltering(n,a,!1);return d.Maybe.of(t)}return d.Nothing}async provideFiltering(e,a,n){switch(e.type){case"trusted-name":return await this.api.sendCommand(new r.SendEIP712FilteringCommand({type:r.Eip712FilterType.TrustedName,discarded:n,displayName:e.displayName,typesAndSourcesPayload:e.typesAndSourcesPayload,signature:e.signature}));case"datetime":return await this.api.sendCommand(new r.SendEIP712FilteringCommand({type:r.Eip712FilterType.Datetime,discarded:n,displayName:e.displayName,signature:e.signature}));case"raw":return await this.api.sendCommand(new r.SendEIP712FilteringCommand({type:r.Eip712FilterType.Raw,discarded:n,displayName:e.displayName,signature:e.signature}));case"token":return this.sanitizeDeviceIndex(e.tokenIndex,a),await this.api.sendCommand(new r.SendEIP712FilteringCommand({type:r.Eip712FilterType.Token,discarded:n,tokenIndex:a.indexes[e.tokenIndex],signature:e.signature}));case"amount":return this.sanitizeDeviceIndex(e.tokenIndex,a),await this.api.sendCommand(new r.SendEIP712FilteringCommand({type:r.Eip712FilterType.Amount,discarded:n,displayName:e.displayName,tokenIndex:a.indexes[e.tokenIndex],signature:e.signature}));default:return(0,s.CommandResultFactory)({error:new s.InvalidStatusWordError("ProvideEIP712ContextTask/provideFiltering - Unhandled filter type")})}}sanitizeDeviceIndex(e,a){a.indexes[e]===void 0&&(a.indexes[e]=a.nextIndex,a.nextIndex=(a.nextIndex+1)%w)}}0&&(module.exports={ProvideEIP712ContextTask});
|
|
2
2
|
//# sourceMappingURL=ProvideEIP712ContextTask.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/app-binder/task/ProvideEIP712ContextTask.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n type TypedDataClearSignContextSuccess,\n type TypedDataFilter,\n type TypedDataTokenIndex,\n VERIFYING_CONTRACT_TOKEN_INDEX,\n} from \"@ledgerhq/context-module\";\nimport {\n type ClearSignContextSuccess,\n type ClearSignContextType,\n} from \"@ledgerhq/context-module\";\nimport type {\n CommandResult,\n InternalApi,\n} from \"@ledgerhq/device-management-kit\";\nimport {\n CommandResultFactory,\n InvalidStatusWordError,\n isSuccessCommandResult,\n LoadCertificateCommand,\n} from \"@ledgerhq/device-management-kit\";\nimport { Maybe, Nothing } from \"purify-ts\";\n\nimport { ProvideTokenInformationCommand } from \"@internal/app-binder/command/ProvideTokenInformationCommand\";\nimport { ProvideWeb3CheckCommand } from \"@internal/app-binder/command/ProvideWeb3CheckCommand\";\nimport {\n Eip712FilterType,\n SendEIP712FilteringCommand,\n} from \"@internal/app-binder/command/SendEIP712FilteringCommand\";\nimport {\n SendEIP712StructDefinitionCommand,\n StructDefinitionCommand,\n} from \"@internal/app-binder/command/SendEIP712StructDefinitionCommand\";\nimport { StructImplemType } from \"@internal/app-binder/command/SendEIP712StructImplemCommand\";\nimport { type EthErrorCodes } from \"@internal/app-binder/command/utils/ethAppErrors\";\nimport { SendEIP712StructImplemTask } from \"@internal/app-binder/task/SendEIP712StructImplemTask\";\nimport {\n type FieldName,\n type FieldType,\n type StructName,\n type TypedDataValue,\n TypedDataValueArray,\n TypedDataValueRoot,\n} from \"@internal/typed-data/model/Types\";\n\nimport { SendPayloadInChunksTask } from \"./SendPayloadInChunksTask\";\n\ntype AllSuccessTypes = void | { tokenIndex: number };\n\nexport type ProvideEIP712ContextTaskReturnType = Promise<\n CommandResult<AllSuccessTypes, EthErrorCodes>\n>;\n\nexport type ProvideEIP712ContextTaskArgs = {\n types: Record<StructName, Record<FieldName, FieldType>>;\n domain: Array<TypedDataValue>;\n message: Array<TypedDataValue>;\n clearSignContext: Maybe<TypedDataClearSignContextSuccess>;\n domainHash: string;\n messageHash: string;\n web3Check: ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK> | null;\n};\n\nconst DEVICE_ASSETS_MAX = 5;\n\ntype DeviceAssetIndexes = {\n indexes: Record<TypedDataTokenIndex, number>;\n nextIndex: number;\n};\n\nexport class ProvideEIP712ContextTask {\n constructor(\n private api: InternalApi,\n private args: ProvideEIP712ContextTaskArgs,\n ) {}\n\n async run(): ProvideEIP712ContextTaskReturnType {\n // Send message simulation first\n if (this.args.web3Check) {\n if (this.args.web3Check.certificate) {\n await this.api.sendCommand(\n new LoadCertificateCommand({\n keyUsage: this.args.web3Check.certificate.keyUsageNumber,\n certificate: this.args.web3Check.certificate.payload,\n }),\n );\n }\n await new SendPayloadInChunksTask(this.api, {\n payload: this.args.web3Check.payload,\n commandFactory: (args) =>\n new ProvideWeb3CheckCommand({\n payload: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n }\n\n const result: CommandResult<AllSuccessTypes, EthErrorCodes> =\n CommandResultFactory<AllSuccessTypes, EthErrorCodes>({ data: undefined });\n\n // Provide the structure definitions.\n // Should be sent before struct implementations, as described here:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#eip712-send-struct-definition\n // Note that those types are used to compute the schema hash, in the device and in ClearSignContexts, as described here:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#eip712-filtering\n // Therefore it should be normalized on both sides: sorted per keys\n const types = Object.entries(this.args.types).sort(([aKey], [bKey]) =>\n aKey.localeCompare(bKey),\n );\n for (const [structName, fields] of types) {\n const structNameResult = await this.api.sendCommand(\n new SendEIP712StructDefinitionCommand({\n command: StructDefinitionCommand.Name,\n name: structName,\n }),\n );\n if (!isSuccessCommandResult(structNameResult)) {\n return structNameResult;\n }\n\n for (const [fieldName, fieldType] of Object.entries(fields)) {\n const fieldResult = await this.api.sendCommand(\n new SendEIP712StructDefinitionCommand({\n command: StructDefinitionCommand.Field,\n name: fieldName,\n type: fieldType,\n }),\n );\n if (!isSuccessCommandResult(fieldResult)) {\n return fieldResult;\n }\n }\n }\n\n // possibly activate the filtering, before sending domain and message implementations, as described here:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#activation\n if (this.args.clearSignContext.isJust()) {\n const activationResult = await this.api.sendCommand(\n new SendEIP712FilteringCommand({ type: Eip712FilterType.Activation }),\n );\n if (!isSuccessCommandResult(activationResult)) {\n return activationResult;\n }\n }\n\n // send domain implementation values.\n for (const value of this.args.domain) {\n const domainImplTask = this.getImplementationTask(value);\n const domainImplResult = await domainImplTask.run();\n if (!isSuccessCommandResult(domainImplResult)) {\n return domainImplResult;\n }\n }\n\n // possibly send MessageInformation filter (between Domain and Message)\n // should be sent between Domain and Message implementations, as described here:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#message-info\n if (this.args.clearSignContext.isJust()) {\n const clearSignContext = this.args.clearSignContext.extract();\n const messageInfoFilterResult = await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.MessageInfo,\n displayName: clearSignContext.messageInfo.displayName,\n filtersCount: clearSignContext.messageInfo.filtersCount,\n signature: clearSignContext.messageInfo.signature,\n }),\n );\n if (!isSuccessCommandResult(messageInfoFilterResult)) {\n return messageInfoFilterResult;\n }\n }\n\n // send message implementation values\n const deviceIndexes: DeviceAssetIndexes = { indexes: {}, nextIndex: 0 };\n for (const value of this.args.message) {\n // 5.1 Provide token descriptors, if any\n // Keep a map of all device indexes for those provided tokens.\n const maybeError = await this.provideTokenInformation(\n value,\n deviceIndexes,\n );\n if (maybeError.isJust()) {\n return maybeError.extract();\n }\n\n // if there's a filter, send it\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#amount-join-token\n const maybeFilterResult = await this.filterValue(value, deviceIndexes);\n if (\n maybeFilterResult.isJust() &&\n !isSuccessCommandResult(maybeFilterResult.extract())\n ) {\n return maybeFilterResult.extract();\n }\n\n // provide message value implementation\n const messageImplTask = this.getImplementationTask(value);\n const messageImplResult = await messageImplTask.run();\n if (!isSuccessCommandResult(messageImplResult)) {\n return messageImplResult;\n }\n\n // if the value is an empty array, discard sub-filters since\n // there will be no according sub-values in the message\n if (\n this.args.clearSignContext.isJust() &&\n value.value instanceof TypedDataValueArray &&\n value.value.length === 0\n ) {\n const filters = Object.entries(\n this.args.clearSignContext.extract().filters,\n );\n const discardedFilters = filters\n .filter(([path]) => path.startsWith(`${value.path}.[]`))\n .map(([, filter]) => filter);\n for (const filter of discardedFilters) {\n const discardedPathResult = await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.DiscardedPath,\n path: filter.path,\n }),\n );\n if (!isSuccessCommandResult(discardedPathResult)) {\n return discardedPathResult;\n }\n\n const provideFilteringResult = await this.provideFiltering(\n filter,\n deviceIndexes,\n true,\n );\n if (!isSuccessCommandResult(provideFilteringResult)) {\n return provideFilteringResult;\n }\n }\n }\n }\n\n return result;\n }\n\n getImplementationTask(value: TypedDataValue): SendEIP712StructImplemTask {\n if (value.value instanceof TypedDataValueRoot) {\n return new SendEIP712StructImplemTask(this.api, {\n type: StructImplemType.ROOT,\n value: value.value.root,\n });\n } else if (value.value instanceof TypedDataValueArray) {\n return new SendEIP712StructImplemTask(this.api, {\n type: StructImplemType.ARRAY,\n value: value.value.length,\n });\n } else {\n return new SendEIP712StructImplemTask(this.api, {\n type: StructImplemType.FIELD,\n value: value.value.data,\n });\n }\n }\n\n async provideTokenInformation(\n value: TypedDataValue,\n deviceIndexes: DeviceAssetIndexes,\n ): Promise<Maybe<CommandResult<AllSuccessTypes, EthErrorCodes>>> {\n if (this.args.clearSignContext.isJust()) {\n const filter = this.args.clearSignContext.extract().filters[value.path];\n // tokens descriptors only needed when a tokenIndex is available in filter.\n // it should be sent to the device only 1 time so deviceIndexes has to be checked.\n if (\n filter !== undefined &&\n (filter.type === \"amount\" || filter.type === \"token\") &&\n deviceIndexes.indexes[filter.tokenIndex] === undefined\n ) {\n const descriptorIndex = filter.tokenIndex;\n const tokens = this.args.clearSignContext.extract().tokens;\n const token = tokens[descriptorIndex];\n if (token === undefined) {\n return Nothing;\n }\n\n const provideTokenInfoResult = await this.api.sendCommand(\n new ProvideTokenInformationCommand({ payload: token }),\n );\n if (!isSuccessCommandResult(provideTokenInfoResult)) {\n return Maybe.of(provideTokenInfoResult);\n }\n let { tokenIndex: deviceIndex } = provideTokenInfoResult.data;\n deviceIndexes.nextIndex = (deviceIndex + 1) % DEVICE_ASSETS_MAX;\n\n // the token corresponding to the Verifying Contract of message domain has a special index value, as described here:\n // https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.adoc#amount-join-value\n if (Number(descriptorIndex) === VERIFYING_CONTRACT_TOKEN_INDEX) {\n deviceIndex = VERIFYING_CONTRACT_TOKEN_INDEX;\n }\n\n deviceIndexes.indexes[Number(descriptorIndex)] = deviceIndex;\n }\n }\n return Nothing;\n }\n\n async filterValue(\n value: TypedDataValue,\n deviceIndexes: DeviceAssetIndexes,\n ): Promise<Maybe<CommandResult<AllSuccessTypes, EthErrorCodes>>> {\n if (this.args.clearSignContext.isJust()) {\n const filter = this.args.clearSignContext.extract().filters[value.path];\n if (filter === undefined) {\n return Nothing;\n }\n // provide the filter\n const filteringResult = await this.provideFiltering(\n filter,\n deviceIndexes,\n false,\n );\n return Maybe.of(filteringResult);\n }\n return Nothing;\n }\n\n async provideFiltering(\n filter: TypedDataFilter,\n deviceIndexes: DeviceAssetIndexes,\n discarded: boolean,\n ): Promise<CommandResult<AllSuccessTypes, EthErrorCodes>> {\n switch (filter.type) {\n case \"datetime\":\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.Datetime,\n discarded,\n displayName: filter.displayName,\n signature: filter.signature,\n }),\n );\n case \"raw\":\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.Raw,\n discarded,\n displayName: filter.displayName,\n signature: filter.signature,\n }),\n );\n case \"token\":\n this.sanitizeDeviceIndex(filter.tokenIndex, deviceIndexes);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.Token,\n discarded,\n tokenIndex: deviceIndexes.indexes[filter.tokenIndex]!,\n signature: filter.signature,\n }),\n );\n case \"amount\":\n this.sanitizeDeviceIndex(filter.tokenIndex, deviceIndexes);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.Amount,\n discarded,\n displayName: filter.displayName,\n tokenIndex: deviceIndexes.indexes[filter.tokenIndex]!,\n signature: filter.signature,\n }),\n );\n default:\n return CommandResultFactory<AllSuccessTypes, EthErrorCodes>({\n error: new InvalidStatusWordError(\n \"ProvideEIP712ContextTask/provideFiltering - Unhandled filter type\",\n ),\n });\n }\n }\n\n private sanitizeDeviceIndex(\n descriptorIndex: number,\n deviceIndexes: DeviceAssetIndexes,\n ) {\n // If a token is missing, the device will replace it with a placeholder and use the next available index\n if (deviceIndexes.indexes[descriptorIndex] === undefined) {\n deviceIndexes.indexes[descriptorIndex] = deviceIndexes.nextIndex;\n deviceIndexes.nextIndex =\n (deviceIndexes.nextIndex + 1) % DEVICE_ASSETS_MAX;\n }\n }\n}\n"],
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,8BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,
|
|
6
|
-
"names": ["ProvideEIP712ContextTask_exports", "__export", "ProvideEIP712ContextTask", "__toCommonJS", "import_context_module", "import_device_management_kit", "import_purify_ts", "import_ProvideTokenInformationCommand", "import_ProvideWeb3CheckCommand", "import_SendEIP712FilteringCommand", "import_SendEIP712StructDefinitionCommand", "import_SendEIP712StructImplemCommand", "import_SendEIP712StructImplemTask", "import_Types", "import_SendPayloadInChunksTask", "DEVICE_ASSETS_MAX", "api", "args", "result", "types", "aKey", "bKey", "structName", "fields", "structNameResult", "fieldName", "fieldType", "fieldResult", "activationResult", "value", "domainImplResult", "clearSignContext", "messageInfoFilterResult", "deviceIndexes", "
|
|
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,qCAkBxC,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,KAAK,KAAK,UAAU,YAAY,eAC1C,YAAa,KAAK,KAAK,UAAU,YAAY,OAC/C,CAAC,CACH,EAEF,MAAM,IAAI,0BA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QAAQU,CAAe,EAAIV,EAAc,UACvDA,EAAc,WACXA,EAAc,UAAY,GAAKrB,EAEtC,CACF",
|
|
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 v=require("@ledgerhq/context-module"),a=require("@ledgerhq/device-management-kit"),c=require("purify-ts"),C=require("../../app-binder/command/ProvideTokenInformationCommand"),w=require("../../app-binder/command/ProvideWeb3CheckCommand"),t=require("../../app-binder/command/SendEIP712FilteringCommand"),k=require("../../app-binder/command/SendEIP712StructDefinitionCommand"),u=require("../../app-binder/command/SendEIP712StructImplemCommand"),I=require("../../app-binder/device-action/__test-utils__/makeInternalApi"),n=require("../../typed-data/model/Types"),l=require("./ProvideEIP712ContextTask");describe("ProvideEIP712ContextTask",()=>{const e=(0,I.makeDeviceActionInternalApiMock)(),m={EIP712Domain:{name:new n.PrimitiveType("string","string",c.Nothing),chainId:new n.PrimitiveType("uint256","uint",(0,c.Just)(32)),verifyingContract:new n.PrimitiveType("address","address",c.Nothing)},PermitSingle:{details:new n.StructType("PermitDetails"),spender:new n.PrimitiveType("address","address",c.Nothing),sigDeadline:new n.PrimitiveType("uint256","uint",(0,c.Just)(32))},PermitDetails:{token:new n.PrimitiveType("address","address",c.Nothing),amount:new n.PrimitiveType("uint160","uint",(0,c.Just)(20)),expiration:new n.PrimitiveType("uint48","uint",(0,c.Just)(6)),nonce:new n.PrimitiveType("uint48","uint",(0,c.Just)(6))}},r=[{path:"",type:"",value:new n.TypedDataValueRoot("EIP712Domain")},{path:"name",type:"string",value:new n.TypedDataValueField(new TextEncoder().encode("Permit2"))},{path:"chainId",type:"uint256",value:new n.TypedDataValueField(Uint8Array.from([137]))},{path:"verifyingContract",type:"address",value:new n.TypedDataValueField((0,a.hexaStringToBuffer)("0x000000000022d473030f116ddee9f6b43ac78ba3"))}],x=[{path:"",type:"",value:new n.TypedDataValueRoot("PermitSingle")},{path:"details.token",type:"address",value:new n.TypedDataValueField((0,a.hexaStringToBuffer)("0x7ceb23fd6bc0add59e62ac25578270cff1b9f619"))},{path:"details.amount",type:"uint160",value:new n.TypedDataValueField(Uint8Array.from([18]))},{path:"details.expiration",type:"uint48",value:new n.TypedDataValueField(Uint8Array.from([18]))},{path:"details.nonce",type:"uint48",value:new n.TypedDataValueField(Uint8Array.from([0]))},{path:"spender",type:"address",value:new n.TypedDataValueField((0,a.hexaStringToBuffer)("0xec7be89e9d109e7e3fec59c222cf297125fefda2"))},{path:"sigDeadline",type:"uint256",value:new n.TypedDataValueField(Uint8Array.from([18]))}],f={type:"success",messageInfo:{displayName:"Permit2",filtersCount:4,signature:"3045022100e3c597d13d28a87a88b0239404c668373cf5063362f2a81d09eed4582941dfe802207669aabb504fd5b95b2734057f6b8bbf51f14a69a5f9bdf658a5952cefbf44d3"},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"}}},p=new n.PrimitiveType("address","address",c.Nothing),E=new n.PrimitiveType("string","string",c.Nothing),y=new n.PrimitiveType("uint256","uint",(0,c.Just)(32)),h=new n.PrimitiveType("uint160","uint",(0,c.Just)(20)),g=new n.PrimitiveType("uint48","uint",(0,c.Just)(6)),q=d=>new n.StructType(d),b=d=>new k.SendEIP712StructDefinitionCommand({command:k.StructDefinitionCommand.Name,name:d}),o=(d,i)=>new k.SendEIP712StructDefinitionCommand({command:k.StructDefinitionCommand.Field,name:d,type:i}),S=d=>new u.SendEIP712StructImplemCommand({type:u.StructImplemType.ROOT,value:d}),A=d=>new u.SendEIP712StructImplemCommand({type:u.StructImplemType.ARRAY,value:d}),s=d=>new u.SendEIP712StructImplemCommand({type:u.StructImplemType.FIELD,value:{data:d,isLastChunk:!0}});beforeEach(()=>{vi.resetAllMocks()}),it("Send context with no clear signing context",async()=>{const d={web3Check:null,types:m,domain:r,message:x,clearSignContext:c.Nothing,domainHash:"0x",messageHash:"0x"};e.sendCommand.mockResolvedValue((0,a.CommandResultFactory)({data:void 0})),await new l.ProvideEIP712ContextTask(e,d).run(),expect(e.sendCommand.mock.calls).toHaveLength(24),expect(e.sendCommand.mock.calls[0][0]).toStrictEqual(b("EIP712Domain")),expect(e.sendCommand.mock.calls[1][0]).toStrictEqual(o("name",E)),expect(e.sendCommand.mock.calls[2][0]).toStrictEqual(o("chainId",y)),expect(e.sendCommand.mock.calls[3][0]).toStrictEqual(o("verifyingContract",p)),expect(e.sendCommand.mock.calls[4][0]).toStrictEqual(b("PermitDetails")),expect(e.sendCommand.mock.calls[5][0]).toStrictEqual(o("token",p)),expect(e.sendCommand.mock.calls[6][0]).toStrictEqual(o("amount",h)),expect(e.sendCommand.mock.calls[7][0]).toStrictEqual(o("expiration",g)),expect(e.sendCommand.mock.calls[8][0]).toStrictEqual(o("nonce",g)),expect(e.sendCommand.mock.calls[9][0]).toStrictEqual(b("PermitSingle")),expect(e.sendCommand.mock.calls[10][0]).toStrictEqual(o("details",q("PermitDetails"))),expect(e.sendCommand.mock.calls[11][0]).toStrictEqual(o("spender",p)),expect(e.sendCommand.mock.calls[12][0]).toStrictEqual(o("sigDeadline",y)),expect(e.sendCommand.mock.calls[13][0]).toStrictEqual(S("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(S("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 d={web3Check:null,types:m,domain:r,message:x,clearSignContext:(0,c.Just)(f),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 l.ProvideEIP712ContextTask(e,d).run(),expect(e.sendCommand.mock.calls).toHaveLength(32),expect(e.sendCommand.mock.calls[0][0]).toStrictEqual(b("EIP712Domain")),expect(e.sendCommand.mock.calls[1][0]).toStrictEqual(o("name",E)),expect(e.sendCommand.mock.calls[2][0]).toStrictEqual(o("chainId",y)),expect(e.sendCommand.mock.calls[3][0]).toStrictEqual(o("verifyingContract",p)),expect(e.sendCommand.mock.calls[4][0]).toStrictEqual(b("PermitDetails")),expect(e.sendCommand.mock.calls[5][0]).toStrictEqual(o("token",p)),expect(e.sendCommand.mock.calls[6][0]).toStrictEqual(o("amount",h)),expect(e.sendCommand.mock.calls[7][0]).toStrictEqual(o("expiration",g)),expect(e.sendCommand.mock.calls[8][0]).toStrictEqual(o("nonce",g)),expect(e.sendCommand.mock.calls[9][0]).toStrictEqual(b("PermitSingle")),expect(e.sendCommand.mock.calls[10][0]).toStrictEqual(o("details",q("PermitDetails"))),expect(e.sendCommand.mock.calls[11][0]).toStrictEqual(o("spender",p)),expect(e.sendCommand.mock.calls[12][0]).toStrictEqual(o("sigDeadline",y)),expect(e.sendCommand.mock.calls[13][0]).toStrictEqual(new t.SendEIP712FilteringCommand({type:t.Eip712FilterType.Activation})),expect(e.sendCommand.mock.calls[14][0]).toStrictEqual(S("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(S("PermitSingle")),expect(e.sendCommand.mock.calls[20][0]).toStrictEqual(new C.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 C.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 d={web3Check:null,types:m,domain:r,message:x,clearSignContext:(0,c.Just)({type:"success",messageInfo:f.messageInfo,filters:f.filters,tokens:{}}),domainHash:"0x",messageHash:"0x"};e.sendCommand.mockResolvedValue((0,a.CommandResultFactory)({data:void 0})),await new l.ProvideEIP712ContextTask(e,d).run(),expect(e.sendCommand).not.toHaveBeenCalledWith(new C.ProvideTokenInformationCommand({payload:"payload-0x7ceb23fd6bc0add59e62ac25578270cff1b9f619"})),expect(e.sendCommand).not.toHaveBeenCalledWith(new C.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 d={web3Check:null,types:m,domain:r,message:x,clearSignContext:(0,c.Just)({type:"success",messageInfo:f.messageInfo,filters:f.filters,tokens:{255:"payload-0x000000000022d473030f116ddee9f6b43ac78ba3"}}),domainHash:"0x",messageHash:"0x"};e.sendCommand.mockResolvedValue((0,a.CommandResultFactory)({data:{tokenIndex:4}})),await new l.ProvideEIP712ContextTask(e,d).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 d={web3Check:null,types:m,domain:r,message:x,clearSignContext:(0,c.Just)({type:"success",messageInfo:f.messageInfo,filters:f.filters,tokens:{0:"payload-0x7ceb23fd6bc0add59e62ac25578270cff1b9f619"}}),domainHash:"0x",messageHash:"0x"};e.sendCommand.mockResolvedValue((0,a.CommandResultFactory)({data:{tokenIndex:4}})),await new l.ProvideEIP712ContextTask(e,d).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("Provide Web3Check",async()=>{const i={web3Check:{type:v.ClearSignContextType.WEB3_CHECK,payload:"0x010203"},types:m,domain:r,message:x,clearSignContext:c.Nothing,domainHash:"0x",messageHash:"0x"};e.sendCommand.mockResolvedValue((0,a.CommandResultFactory)({data:void 0})),await new l.ProvideEIP712ContextTask(e,i).run(),expect(e.sendCommand).toHaveBeenCalledWith(new w.ProvideWeb3CheckCommand({payload:(0,a.hexaStringToBuffer)("0x0003010203"),isFirstChunk:!0}))}),it("Provide Web3Check and certificate",async()=>{const d={type:v.ClearSignContextType.WEB3_CHECK,certificate:{keyUsageNumber:3,payload:new Uint8Array(3).fill(42)},payload:"0x010203"},i={web3Check:d,types:m,domain:r,message:x,clearSignContext:c.Nothing,domainHash:"0x",messageHash:"0x"};e.sendCommand.mockResolvedValue((0,a.CommandResultFactory)({data:void 0})),await new l.ProvideEIP712ContextTask(e,i).run(),expect(e.sendCommand).toHaveBeenCalledWith(new a.LoadCertificateCommand({keyUsage:3,certificate:d.certificate.payload})),expect(e.sendCommand).toHaveBeenCalledWith(new w.ProvideWeb3CheckCommand({payload:(0,a.hexaStringToBuffer)("0x0003010203"),isFirstChunk:!0}))}),it("Error when providing tokens",async()=>{const d={web3Check:null,types:m,domain:r,message:x,clearSignContext:(0,c.Just)(f),domainHash:"0x",messageHash:"0x"};e.sendCommand.mockResolvedValueOnce((0,a.CommandResultFactory)({error:new a.UnknownDeviceExchangeError("error")}));const i=new l.ProvideEIP712ContextTask(e,d).run();await expect(i).resolves.toStrictEqual((0,a.CommandResultFactory)({error:new a.UnknownDeviceExchangeError("error")}))}),it("Error when sending struct definitions",async()=>{const d={web3Check:null,types:m,domain:r,message:x,clearSignContext:(0,c.Just)(f),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 i=new l.ProvideEIP712ContextTask(e,d).run();await expect(i).resolves.toStrictEqual((0,a.CommandResultFactory)({error:new a.UnknownDeviceExchangeError("error")}))}),it("Error when sending struct implementations",async()=>{const d={web3Check:null,types:m,domain:r,message:x,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 i=new l.ProvideEIP712ContextTask(e,d).run();await expect(i).resolves.toStrictEqual((0,a.CommandResultFactory)({error:new a.UnknownDeviceExchangeError("error")}))}),it("Send struct array",async()=>{const d={web3Check:null,domainHash:"0x",messageHash:"0x",types:{},domain:[],message:[{path:"spenders",type:"address[]",value:new n.TypedDataValueArray(1)},{path:"spenders.[]",type:"address",value:new n.TypedDataValueField((0,a.hexaStringToBuffer)("0x7ceb23fd6bc0add59e62ac25578270cff1b9f619"))},{path:"beneficiaries",type:"address[]",value:new n.TypedDataValueArray(0)}],clearSignContext:(0,c.Just)({type:"success",messageInfo:{displayName:"Permit2",filtersCount:2,signature:"sig"},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 l.ProvideEIP712ContextTask(e,d).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(A(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(A(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"),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"}))})});
|
|
2
2
|
//# sourceMappingURL=ProvideEIP712ContextTask.test.js.map
|